summaryrefslogtreecommitdiff
path: root/glafp-utils
diff options
context:
space:
mode:
authorstolz <unknown>2003-06-27 16:21:11 +0000
committerstolz <unknown>2003-06-27 16:21:11 +0000
commit7f155a377bed8d1258cddd36d3dbecab1e6ecdaf (patch)
tree933c2b7bf253dc5475736326ec51f2ac5ae9acc5 /glafp-utils
parent536e2a029dcc11c33c9448146b34513c682f17ad (diff)
downloadhaskell-7f155a377bed8d1258cddd36d3dbecab1e6ecdaf.tar.gz
[project @ 2003-06-27 16:21:10 by stolz]
From genargs.pl: # This program generates a partial Haskell list of Strings from # words passed via stdin suitable for use in package.conf, e.g.: # # foo bar --> "foo", "bar" # "foo bar" --> "foo bar" # foo\"bar --> "foo\"bar" # # Invoking genargs.pl with -comma will print an initial comma if # there's anything to print at all. # # Sample application in a Makefile: # HSIFIED_EXTRA_LD_OPTS= `echo "$(EXTRA_LD_OPTS)" | $(PERL) genargs.pl` # PACKAGE_CPP_OPTS += -DHSIFIED_EXTRA_LD_OPTS="$(HSIFIED_EXTRA_LD_OPTS)"
Diffstat (limited to 'glafp-utils')
-rw-r--r--glafp-utils/README4
-rw-r--r--glafp-utils/genargs/Makefile8
-rw-r--r--glafp-utils/genargs/genargs.pl62
3 files changed, 74 insertions, 0 deletions
diff --git a/glafp-utils/README b/glafp-utils/README
index 4661b46867..8967522e5a 100644
--- a/glafp-utils/README
+++ b/glafp-utils/README
@@ -25,3 +25,7 @@ project-specific bits, try <project>/utils/<blah>.)
docbook scripts to process DocBook files stolen from Cygnus DocBook
tools.
+
+ genargs converts whitespace separated strings into partial
+ Haskell lists.
+
diff --git a/glafp-utils/genargs/Makefile b/glafp-utils/genargs/Makefile
new file mode 100644
index 0000000000..3c31e6a39f
--- /dev/null
+++ b/glafp-utils/genargs/Makefile
@@ -0,0 +1,8 @@
+comma = ,
+BAR= "-L\"foo bar\""
+FOO= $(patsubst %,$(comma)"%",$(BAR))
+
+test:
+ @echo "$(FOO)"
+ @echo "$(BAR)" | $(PERL) genargs.pl -comma
+ @echo
diff --git a/glafp-utils/genargs/genargs.pl b/glafp-utils/genargs/genargs.pl
new file mode 100644
index 0000000000..2ef2dfa3e6
--- /dev/null
+++ b/glafp-utils/genargs/genargs.pl
@@ -0,0 +1,62 @@
+#!/usr/bin/perl
+my $quote_open = 0;
+my $quote_char = '';
+my $accum = "";
+my $once = 1;
+my $c;
+
+# This program generates a partial Haskell list of Strings from
+# words passed via stdin suitable for use in package.conf, e.g.:
+#
+# foo bar --> "foo", "bar"
+# "foo bar" --> "foo bar"
+# foo\"bar --> "foo\"bar"
+#
+# Invoking genargs.pl with -comma will print an initial comma if
+# there's anything to print at all.
+#
+# Sample application in a Makefile:
+# HSIFIED_EXTRA_LD_OPTS= `echo "$(EXTRA_LD_OPTS)" | $(PERL) genargs.pl`
+# PACKAGE_CPP_OPTS += -DHSIFIED_EXTRA_LD_OPTS="$(HSIFIED_EXTRA_LD_OPTS)"
+
+sub printaccum {
+ if ($once) {
+ if ($ARGV[0] eq "-comma") {
+ print ", ";
+ }
+ } else {
+ print ", ";
+ }
+ $once=0;
+ print '"';
+ print $accum;
+ print '"';
+}
+
+while ($c = getc) {
+ if ($quote_open) {
+ if ($c eq $quote_char) {
+ $quote_open = 0;
+ } elsif ($c eq '"') {
+ $accum .= '\"';
+ } else {
+ $accum .= $c;
+ }
+ } else {
+ if (($c eq ' ') || ($c eq "\n")) {
+ if (!($accum eq "")) {
+ printaccum;
+ $accum = "";
+ }
+ } elsif ($c eq "\\") {
+ $accum .= $c;
+ $c = getc;
+ $accum .= $c;
+ } elsif (($c eq '"') || ($c eq "\'")) {
+ $quote_open = 1;
+ $quote_char = $c;
+ } else {
+ $accum .= $c
+ }
+ }
+}