r3742 - in trunk/src/host/devirginator: . tests
werner at sita.openmoko.org
werner at sita.openmoko.org
Thu Dec 27 17:17:17 CET 2007
Author: werner
Date: 2007-12-27 17:17:12 +0100 (Thu, 27 Dec 2007)
New Revision: 3742
Modified:
trunk/src/host/devirginator/envedit.pl
trunk/src/host/devirginator/tests/macro
Log:
- devirginator/envedit.pl, devirginator/tests/macro: macro expansion yielded
incorrect results if there were multiple macros in the same line
- devirginator/envedit.pl, devirginator/tests/define: added #define directive
Modified: trunk/src/host/devirginator/envedit.pl
===================================================================
--- trunk/src/host/devirginator/envedit.pl 2007-12-27 05:55:24 UTC (rev 3741)
+++ trunk/src/host/devirginator/envedit.pl 2007-12-27 16:17:12 UTC (rev 3742)
@@ -33,6 +33,7 @@
#
# Macro expansion:
#
+# #define MACRO TEXT ...
# MACRO
# MACRO##TOKEN
#
@@ -245,14 +246,33 @@
}
next if $false;
+ if (/^\s*#define\s+(\S+)(\s*(.*?))?\s*$/) {
+ if (defined $def{$1} && $def{$1} ne $3) {
+ print STDERR "$file:$.: redefinition of macro \"$1\"\n";
+ exit(1);
+ }
+ $def{$1} = $3;
+ }
+
$tmp = "";
- for $def (keys %def) {
- while (/(##)?\b$def\b(##)?/) {
- $tmp = $`.$def{$def};
- $_ = $';
+ while (length $_) {
+ $pre = $_;
+ $exp = "";
+ $post = "";
+ for $def (keys %def) {
+ if (/(##)?\b$def\b(##)?/) {
+ if (length $` < length $pre) {
+ $pre = $`;
+ $exp = $def{$def};
+ $post = $';
+ }
+ }
}
+ $tmp .= $pre.$exp;
+ $_ = $post;
}
- $_ = $tmp.$_;
+ $_ = $tmp;
+
s/#.*//;
s/\s*$//;
next if /^\s*$/;
Modified: trunk/src/host/devirginator/tests/macro
===================================================================
--- trunk/src/host/devirginator/tests/macro 2007-12-27 05:55:24 UTC (rev 3741)
+++ trunk/src/host/devirginator/tests/macro 2007-12-27 16:17:12 UTC (rev 3742)
@@ -112,3 +112,16 @@
b=2
c=3
EOF
+
+# -----------------------------------------------------------------------------
+
+setup "expand multiple macros" <<EOF
+EOF
+
+edit -D foo=bar -D x=y -p <<EOF
+foo=x
+EOF
+
+expect <<EOF
+bar=y
+EOF
More information about the commitlog
mailing list