unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] guile-snarf: allow multiple init actions on one line
@ 2011-02-22 19:14 BT Templeton
  2011-02-22 19:26 ` Andy Wingo
  2011-03-04 10:34 ` Andy Wingo
  0 siblings, 2 replies; 8+ messages in thread
From: BT Templeton @ 2011-02-22 19:14 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 258 bytes --]

Guile-SDL contains some cpp macros that define multiple subrs. To allow
that, this patch modifies guile-snarf to recognize more than one
initialization action per line, which is necessary because GNU's C
preprocessor removes newlines from macro expansions.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 1085 bytes --]

From e14436798deb8c9bb59273844d194c1bc4af6682 Mon Sep 17 00:00:00 2001
From: BT Templeton <bpt@hcoop.net>
Date: Tue, 22 Feb 2011 13:15:31 -0500
Subject: [PATCH] guile-snarf: allow multiple init actions on one line

* libguile/guile-snarf.in (modern_snarf): Allow programs to specify
  multiple initialization actions on a single line. This makes it
  possible for C programs to define multiple subrs with a single macro
  invocation.
---
 libguile/guile-snarf.in |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libguile/guile-snarf.in b/libguile/guile-snarf.in
index 043b3ed..a1aeba5 100644
--- a/libguile/guile-snarf.in
+++ b/libguile/guile-snarf.in
@@ -51,7 +51,7 @@ modern_snarf ()                         # writes stdout
     ## empty file.
     echo "/* cpp arguments: $@ */" ;
     ${cpp} -DSCM_MAGIC_SNARF_INITS -DSCM_MAGIC_SNARFER "$@" > ${temp} && cpp_ok_p=true
-    grep "^ *\^ *\^" ${temp} | sed -e "s/ *\^ *\^//g" -e "s/\^ *: *\^/;/g"
+    sed -ne "s/ *\^ *: *\^/\n/;s/[^\n]*\^ *\^ *\([^\n]*\)/\1;/;tx;d;:x;P;D" ${temp}
 }
 
 ## main
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] guile-snarf: allow multiple init actions on one line
  2011-02-22 19:14 [PATCH] guile-snarf: allow multiple init actions on one line BT Templeton
@ 2011-02-22 19:26 ` Andy Wingo
  2011-02-22 23:09   ` BT Templeton
  2011-03-04 10:34 ` Andy Wingo
  1 sibling, 1 reply; 8+ messages in thread
From: Andy Wingo @ 2011-02-22 19:26 UTC (permalink / raw)
  To: BT Templeton; +Cc: guile-devel

On Tue 22 Feb 2011 20:14, BT Templeton <bpt@hcoop.net> writes:

> Guile-SDL contains some cpp macros that define multiple subrs. To allow
> that, this patch modifies guile-snarf to recognize more than one
> initialization action per line, which is necessary because GNU's C
> preprocessor removes newlines from macro expansions.

Thanks for the patch.  I don't understand the sed; can some sedi master
check this one to make sure it's compatible with guile-snarf as it is?

Ideally some tests would be nice, as well...

Thanks :)

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] guile-snarf: allow multiple init actions on one line
  2011-02-22 19:26 ` Andy Wingo
@ 2011-02-22 23:09   ` BT Templeton
  2011-02-24 19:31     ` Ludovic Courtès
  0 siblings, 1 reply; 8+ messages in thread
From: BT Templeton @ 2011-02-22 23:09 UTC (permalink / raw)
  To: guile-devel; +Cc: Andy Wingo

[-- Attachment #1: Type: text/plain, Size: 1000 bytes --]

Andy Wingo <wingo@pobox.com> writes:

> On Tue 22 Feb 2011 20:14, BT Templeton <bpt@hcoop.net> writes:
>
>> Guile-SDL contains some cpp macros that define multiple subrs. To allow
>> that, this patch modifies guile-snarf to recognize more than one
>> initialization action per line, which is necessary because GNU's C
>> preprocessor removes newlines from macro expansions.
>
> Thanks for the patch.  I don't understand the sed; can some sedi master
> check this one to make sure it's compatible with guile-snarf as it is?

There is one significant difference: currently guile-snarf outputs any
lines containing "^^" markers but with "^^"/"^:^" deleted, whereas my
version outputs only text *between* "^^" … "^:^". This shouldn't affect
programs using the snarfing macros as intended, but a line like
"a;SCM_SNARF_INIT(b);" would result in the output "a;b;" with the
current version and "b;" with this patch applied.

> Ideally some tests would be nice, as well...

How's the attached patch look?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 1682 bytes --]

From 4f7f85f0f8b62e471ee67d68a73d390b31f1d4b6 Mon Sep 17 00:00:00 2001
From: BT Templeton <bpt@hcoop.net>
Date: Tue, 22 Feb 2011 15:15:33 -0500
Subject: [PATCH] add guile-snarf tests

* test-suite/standalone/test-guile-snarf: New file.
* test-suite/standalone/Makefile.am: Add `test-guile-snarf'.
---
 test-suite/standalone/Makefile.am      |    3 +++
 test-suite/standalone/test-guile-snarf |   21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)
 create mode 100755 test-suite/standalone/test-guile-snarf

diff --git a/test-suite/standalone/Makefile.am b/test-suite/standalone/Makefile.am
index 861e668..0e9eaf7 100644
--- a/test-suite/standalone/Makefile.am
+++ b/test-suite/standalone/Makefile.am
@@ -66,6 +66,9 @@ TESTS += test-bad-identifiers
 check_SCRIPTS += test-require-extension
 TESTS += test-require-extension
 
+check_SCRIPTS += test-guile-snarf
+TESTS += test-guile-snarf
+
 # test-num2integral
 test_num2integral_SOURCES = test-num2integral.c
 test_num2integral_CFLAGS = ${test_cflags}
diff --git a/test-suite/standalone/test-guile-snarf b/test-suite/standalone/test-guile-snarf
new file mode 100755
index 0000000..032bfaa
--- /dev/null
+++ b/test-suite/standalone/test-guile-snarf
@@ -0,0 +1,21 @@
+#!/bin/sh
+snarf ()
+{
+    echo "$1" | guile-snarf - | tail -n +2 | tr -d ' \t\n'
+}
+
+snarf_test ()
+{
+    local x
+    x=$(snarf "$1")
+    if [ x"$x" != x"$2" ]; then
+        echo "Incorrect output: expected \"$2\", but got \"$x\""
+        exit 1
+    fi
+}
+
+snarf_test "^^a^:^" "a;"
+snarf_test "  ^  ^  b  ^  :  ^  " "b;"
+snarf_test "c\n^^d^:^\ne" "d;"
+snarf_test "f^^g^:^h" "g;"
+snarf_test "^^i^:^j^^k^:^" "i;k;"
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] guile-snarf: allow multiple init actions on one line
  2011-02-22 23:09   ` BT Templeton
@ 2011-02-24 19:31     ` Ludovic Courtès
  2011-02-24 20:42       ` Andreas Rottmann
  0 siblings, 1 reply; 8+ messages in thread
From: Ludovic Courtès @ 2011-02-24 19:31 UTC (permalink / raw)
  To: guile-devel

Hi Brian,

Thanks for the patches!

I haven’t look at the other patch yet, but about this one:

BT Templeton <bpt@hcoop.net> writes:

> +#!/bin/sh

Can you add a copyright/license header here?

> +snarf_test ()
> +{
> +    local x
> +    x=$(snarf "$1")
> +    if [ x"$x" != x"$2" ]; then

‘local’ and ‘$(...)’ are Bash extensions.  Can you remove ‘local’ and
use backquotes instead of $(...)?

> +snarf_test "^^a^:^" "a;"
> +snarf_test "  ^  ^  b  ^  :  ^  " "b;"
> +snarf_test "c\n^^d^:^\ne" "d;"
> +snarf_test "f^^g^:^h" "g;"
> +snarf_test "^^i^:^j^^k^:^" "i;k;"

Which of these should work with the current guile-snarf, and which
should work only with yours?

Thanks!

Ludo’.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] guile-snarf: allow multiple init actions on one line
  2011-02-24 19:31     ` Ludovic Courtès
@ 2011-02-24 20:42       ` Andreas Rottmann
  2011-02-24 21:49         ` Ludovic Courtès
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Rottmann @ 2011-02-24 20:42 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

ludo@gnu.org (Ludovic Courtès) writes:

> Hi Brian,
>
> Thanks for the patches!
>
> I haven’t look at the other patch yet, but about this one:
>
> BT Templeton <bpt@hcoop.net> writes:
>
>> +#!/bin/sh
>
> Can you add a copyright/license header here?
>
>> +snarf_test ()
>> +{
>> +    local x
>> +    x=$(snarf "$1")
>> +    if [ x"$x" != x"$2" ]; then
>
> ‘local’ and ‘$(...)’ are Bash extensions.
>
That's not true for '$(...)', see SUSv3, Section 2.6.3. 

'local' is strictly speaking a non-POSIX extension, but is very widely
implemented (for instance, it is one of the few extensions allowed by
Debian's policy[0], and seems also supported by FreeBSD's /bin/sh
[1]). If the script would be significanly more burdensome if expressed
without 'local', it would IMHO make sense to at least contemplate the
issue.

[0] http://www.debian.org/doc/debian-policy/ch-files.html#s-scripts
[1] http://www.freebsd.org/cgi/man.cgi?query=sh&format=html

Regards, Rotty
-- 
Andreas Rottmann -- <http://rotty.yi.org/>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] guile-snarf: allow multiple init actions on one line
  2011-02-24 20:42       ` Andreas Rottmann
@ 2011-02-24 21:49         ` Ludovic Courtès
  2011-02-25 11:01           ` Andy Wingo
  0 siblings, 1 reply; 8+ messages in thread
From: Ludovic Courtès @ 2011-02-24 21:49 UTC (permalink / raw)
  To: Andreas Rottmann; +Cc: guile-devel

Hi,

Andreas Rottmann <a.rottmann@gmx.at> writes:

> That's not true for '$(...)', see SUSv3, Section 2.6.3. 

Solaris 5.10 /bin/sh:

--8<---------------cut here---------------start------------->8---
> echo $(echo foo)
syntax error: `(' unexpected
--8<---------------cut here---------------end--------------->8---

If Bruno is around, I’m sure he’ll come up with other examples.  ;-)

I think it’s best to avoid these constructs since it has no downsides
anyway.

Thanks,
Ludo’.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] guile-snarf: allow multiple init actions on one line
  2011-02-24 21:49         ` Ludovic Courtès
@ 2011-02-25 11:01           ` Andy Wingo
  0 siblings, 0 replies; 8+ messages in thread
From: Andy Wingo @ 2011-02-25 11:01 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

On Thu 24 Feb 2011 22:49, ludo@gnu.org (Ludovic Courtès) writes:

> Andreas Rottmann <a.rottmann@gmx.at> writes:
>
>> That's not true for '$(...)', see SUSv3, Section 2.6.3. 
>
> Solaris 5.10 /bin/sh:
>
>> echo $(echo foo)
> syntax error: `(' unexpected

Gross :)

Perhaps it's an argument for preferring Guile over shell for scripting
and testing, once Guile is built anyway.  Not that I want to burden this
particular contribution with this can of worms.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] guile-snarf: allow multiple init actions on one line
  2011-02-22 19:14 [PATCH] guile-snarf: allow multiple init actions on one line BT Templeton
  2011-02-22 19:26 ` Andy Wingo
@ 2011-03-04 10:34 ` Andy Wingo
  1 sibling, 0 replies; 8+ messages in thread
From: Andy Wingo @ 2011-03-04 10:34 UTC (permalink / raw)
  To: BT Templeton; +Cc: guile-devel

On Tue 22 Feb 2011 20:14, BT Templeton <bpt@hcoop.net> writes:

> Guile-SDL contains some cpp macros that define multiple subrs. To allow
> that, this patch modifies guile-snarf to recognize more than one
> initialization action per line, which is necessary because GNU's C
> preprocessor removes newlines from macro expansions.

Applied, with your tests, and some shell portability foo.  Thanks!

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-03-04 10:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-22 19:14 [PATCH] guile-snarf: allow multiple init actions on one line BT Templeton
2011-02-22 19:26 ` Andy Wingo
2011-02-22 23:09   ` BT Templeton
2011-02-24 19:31     ` Ludovic Courtès
2011-02-24 20:42       ` Andreas Rottmann
2011-02-24 21:49         ` Ludovic Courtès
2011-02-25 11:01           ` Andy Wingo
2011-03-04 10:34 ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).