X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=utils%2Fgenargs%2Fgenargs.pl;fp=utils%2Fgenargs%2Fgenargs.pl;h=2ef2dfa3e6224ddd39d31015eb2b5062774edfb4;hb=0065d5ab628975892cea1ec7303f968c3338cbe1;hp=0000000000000000000000000000000000000000;hpb=28a464a75e14cece5db40f2765a29348273ff2d2;p=ghc-hetmet.git diff --git a/utils/genargs/genargs.pl b/utils/genargs/genargs.pl new file mode 100644 index 0000000..2ef2dfa --- /dev/null +++ b/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 + } + } +}