From: Arnaud L. <leg...@us...> - 2006-03-21 16:51:25
|
Update of /cvsroot/flexml/flexml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31690 Modified Files: flexml.pl Log Message: Added a few dirty hacks to rename states and transitions in the lex file and variable, functions and types in the .h. This enable to have in the same C code many xml parser with potentially identical keywords. Index: flexml.pl =================================================================== RCS file: /cvsroot/flexml/flexml/flexml.pl,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- flexml.pl 21 Mar 2006 08:24:12 -0000 1.46 +++ flexml.pl 21 Mar 2006 11:12:57 -0000 1.47 @@ -213,8 +213,8 @@ my ($pre,$post) = @_; print "/* XML application entry points. */\n" if @tags; for (@tags) { - print $pre . "void STag_$ctag{$_}(void)$post\n" unless $startok{$_}; - print $pre . "void ETag_$ctag{$_}(void)$post\n" unless $endok{$_}; + print $pre . "void STag_${tagprefix}$ctag{$_}(void)$post\n" unless $startok{$_}; + print $pre . "void ETag_${tagprefix}$ctag{$_}(void)$post\n" unless $endok{$_}; } } @@ -224,8 +224,8 @@ for (keys %atttype) { if (m.($Nmtoken)[/]($Nmtoken).xo) { my ($tag,$attribute) = ($1,$2); - print "typedef $typeof{$_} AT_$ctag{$tag}_$catt{$attribute};\n"; - print "#define AU_$ctag{$tag}_$catt{$attribute} NULL\n" + print "typedef $typeof{$_} AT_${tagprefix}$ctag{$tag}_$catt{$attribute};\n"; + print "#define AU_${tagprefix}$ctag{$tag}_$catt{$attribute} NULL\n" if not $enumtype{$_}; } } @@ -238,7 +238,7 @@ print $pre . "const char* pcdata;\n"; for (keys %atttype) { if (m.($Nmtoken)[/]($Nmtoken).xo) { - print $pre . "AT_$ctag{$1}_$catt{$2} A_$ctag{$1}_$catt{$2};\n"; + print $pre . "AT_${tagprefix}$ctag{$1}_$catt{$2} A_${tagprefix}$ctag{$1}_$catt{$2};\n"; } } } @@ -686,7 +686,7 @@ # All elements should be followed by nothing when at the root. # IF there is a list of roottags ($0 -r ..,..), then only add # the exittrans if it is in the list - $exittrans{$tag} .= ($exittrans{$tag}?',':'') . "ROOT_$c=>EPILOG" + $exittrans{$tag} .= ($exittrans{$tag}?',':'') . "ROOT_${tagprefix}$c=>EPILOG" if not %roottags or $roottags{$tag}; # Handle element declaration. @@ -796,13 +796,13 @@ s/\s+//go; s/\|/,/go; $enumtype{"$tag/$attribute"} = "$_"; - s/$Nmtoken/ "A_$ctag{$tag}_$catt{$attribute}_" . variablify($&) /xge; - my $undefined = "AU_$ctag{$tag}_$catt{$attribute}"; + s/$Nmtoken/ "A_${tagprefix}$ctag{$tag}_$catt{$attribute}_" . variablify($&) /xge; + my $undefined = "AU_${tagprefix}$ctag{$tag}_$catt{$attribute}"; s/^/enum \{ $undefined, /o; s/$/ \}/o; $typeof{"$tag/$attribute"} = "$_"; if ($default) { - $initof{"$tag/$attribute"} = "A_$ctag{$tag}_$catt{$attribute}_" + $initof{"$tag/$attribute"} = "A_${tagprefix}$ctag{$tag}_$catt{$attribute}_" . variablify($default); } else { @@ -975,6 +975,23 @@ for (@tags) { $roottags{$_} = 'true'; } } +# Handling prefix +if($opt{P}) { + my($h,$k); + my(@hashlist) = (\%states,\%emptytrans,\%instates,\%startstate, + \%endstates,\%exittrans); + + foreach $h (@hashlist) { + foreach $k (keys (%$h)) { + $$h{$k} =~ s/^E_/E_${tagprefix}/g; + $$h{$k} =~ s/,E_/,E_${tagprefix}/g; + $$h{$k} =~ s/>E_/>E_${tagprefix}/g; + $$h{$k} =~ s/^S_/S_${tagprefix}/g; + $$h{$k} =~ s/,S_/,S_${tagprefix}/g; + $$h{$k} =~ s/>S_/>S_${tagprefix}/g; + } + } +} # Debugging: show DTD representation. @@ -988,10 +1005,9 @@ my ($k,$v); my $out = ''; - while ( ($k, $v) = each(%$name) ) - { - $out .= "\n $k => " . ($v || "undef"); - } + while ( ($k, $v) = each(%$name) ) { + $out .= "\n $k => '" . ($v || "undef")."'"; + } return $out; } @@ -1045,7 +1061,6 @@ # WRITE API HEADER (if requested). - if ($opt{H}) { print STDOUT "Generating XML processor header in `$HEADER'.\n" if $verbose; @@ -1166,8 +1181,8 @@ for (@tags) { my $c = $ctag{$_}; print "%x" - . ($roottags{$_} ? " ROOT_$c" : "") - . " AL_$c " . join(' ',split(',',$states{$_})) . "\n"; + . ($roottags{$_} ? " ROOT_${tagprefix}$c" : "") + . " AL_${tagprefix}$c " . join(' ',split(',',$states{$_})) . "\n"; } } @@ -1191,8 +1206,8 @@ } for my $tag (@tags) { my $c = $ctag{$tag}; - print " ${tagprefix}statenames[ROOT_$c] = NULL;\n" if $roottags{$tag}; - print " ${tagprefix}statenames[AL_$c] = NULL;\n"; + print " ${tagprefix}statenames[ROOT_${tagprefix}$c] = NULL;\n" if $roottags{$tag}; + print " ${tagprefix}statenames[AL_${tagprefix}$c] = NULL;\n"; for (split ',',$states{$tag}) { print " ${tagprefix}statenames[$_] = \"$tag\";\n"; } @@ -1207,11 +1222,11 @@ for (keys %roottags) { my $c = $ctag{$_}; print " \"<!DOCTYPE\"{S}\"$_\"{S}" - . "SYSTEM{S}" . $sysid . "{s}\">\" SET(ROOT_$c);\n"; + . "SYSTEM{S}" . $sysid . "{s}\">\" SET(ROOT_${tagprefix}$c);\n"; if ($pubid) { print " \"<!DOCTYPE\"{S}\"$_\"{S}" . "PUBLIC{S}(\"'$pubid'\"|\"\\\"$pubid\\\"\"){S}" - . $sysid . "{s}\">\" SET(ROOT_$c);\n"; + . $sysid . "{s}\">\" SET(ROOT_${tagprefix}$c);\n"; } } @@ -1258,7 +1273,7 @@ # Start or empty tag: initialise attribute list. print "\n"; if ($roottags{$tag}) { - print "<ROOT_$myctag" . ($instates{$tag} ? ",$instates{$tag}" : ""); + print "<ROOT_${tagprefix}$myctag" . ($instates{$tag} ? ",$instates{$tag}" : ""); } else { print "<$instates{$tag}"; @@ -1269,9 +1284,9 @@ print ">\"<$tag\"{s} {\n"; for my $attribute (@myattributes) { - print " A_${myctag}_$catt{$attribute} = " . $initof{"$tag/$attribute"} . ";\n"; + print " A_${tagprefix}${myctag}_$catt{$attribute} = " . $initof{"$tag/$attribute"} . ";\n"; } - print " ENTER(AL_$myctag);\n"; + print " ENTER(AL_${tagprefix}$myctag);\n"; print " }\n"; # print " . FAIL(\"Unexpected character `%c': `<$tag' expected.\",yytext[0]);\n"; @@ -1281,7 +1296,7 @@ # Attribute list (of start or empty tag): print "\n"; - print "<AL_$myctag>{\n"; + print "<AL_${tagprefix}$myctag>{\n"; for my $attribute (@myattributes) { my $type; # set by conditions @@ -1293,7 +1308,7 @@ print " \"$attribute\"{Eq}\"'" . $attdef{"$tag/$attribute"} . "'\"" . " |\n" . " \"$attribute\"{Eq}\"\\\"" . $attdef{"$tag/$attribute"} . "\\\"\"" - . " A_${myctag}_$catt{$attribute}" + . " A_${tagprefix}${myctag}_$catt{$attribute}" . " = " . $initof{"$tag/$attribute"} . ";\n"; } else { @@ -1302,8 +1317,8 @@ print " \"$attribute\"{Eq}\"'$alternative'\"" . " |\n" . " \"$attribute\"{Eq}\"\\\"$alternative\\\"\"" - . " A_${myctag}_$catt{$attribute}" - . " = A_${myctag}_$catt{$attribute}_" . variablify($alternative) . ";\n"; + . " A_${tagprefix}${myctag}_$catt{$attribute}" + . " = A_${tagprefix}${myctag}_$catt{$attribute}_" . variablify($alternative) . ";\n"; } } } @@ -1314,23 +1329,23 @@ print " \"$attribute\"{Eq}\"'" . $attdef{"$tag/$attribute"} . "'\"" . " |\n" . " \"$attribute\"{Eq}\"\\\"" . $attdef{"$tag/$attribute"} . "\\\"\"" - . " A_${myctag}_$catt{$attribute}" + . " A_${tagprefix}${myctag}_$catt{$attribute}" . " = " . $initof{"$tag/$attribute"} . ";\n"; } elsif ($type = $literaltype{"$tag/$attribute"}) { # - (non-fixed) literal-type attribute: scan literal string directly, or - print " \"$attribute\"{Eq}\'$type\' BUFFERLITERAL('\\\'',A_${myctag}_$catt{$attribute});\n"; + print " \"$attribute\"{Eq}\'$type\' BUFFERLITERAL('\\\'',A_${tagprefix}${myctag}_$catt{$attribute});\n"; - print " \"$attribute\"{Eq}\\\"$type\\\" BUFFERLITERAL('\"',A_${myctag}_$catt{$attribute});\n"; + print " \"$attribute\"{Eq}\\\"$type\\\" BUFFERLITERAL('\"',A_${tagprefix}${myctag}_$catt{$attribute});\n"; } else { # - (non-fixed non-literal) attribute: scan string with entity expansion. - print " \"$attribute\"{Eq}\\' ENTER(VALUE1); BUFFERSET(A_${myctag}_$catt{$attribute});\n"; - print " \"$attribute\"{Eq}\\\" ENTER(VALUE2); BUFFERSET(A_${myctag}_$catt{$attribute});\n"; + print " \"$attribute\"{Eq}\\' ENTER(VALUE1); BUFFERSET(A_${tagprefix}${myctag}_$catt{$attribute});\n"; + print " \"$attribute\"{Eq}\\\" ENTER(VALUE2); BUFFERSET(A_${tagprefix}${myctag}_$catt{$attribute});\n"; } print "\n"; @@ -1341,11 +1356,11 @@ print " \">\" {\n"; for my $attribute (@myattributes) { if ($required{"$tag/$attribute"}) { - print " if (!A_$ctag{$tag}_" . variablify($attribute) . ")" + print " if (!A_${tagprefix}$ctag{$tag}_" . variablify($attribute) . ")" . " FAIL(\"Required attribute `$attribute' not set for `$tag' element.\");\n"; } } - print " LEAVE; STag_$myctag();" + print " LEAVE; STag_${tagprefix}$myctag();" . (%inmixed ? ' pushbuffer(pcdata);' : '') . ($mixed{$tag} ? 'BUFFERSET(pcdata)' : 'pcdata = NULL'). ";" . " ENTER($startstate{$tag});\n"; @@ -1356,14 +1371,14 @@ print " \"/>\" {\n"; for my $attribute (@myattributes) { if ($required{"$tag/$attribute"}) { - print " if (!A_$ctag{$tag}_" . variablify($attribute) . ")" + print " if (!A_${tagprefix}$ctag{$tag}_" . variablify($attribute) . ")" . " FAIL(\"Required attribute `$attribute' not set for `$tag' element.\");\n"; } } - print " LEAVE; STag_$myctag();" + print " LEAVE; STag_${tagprefix}$myctag();" . (%inmixed ? ' pushbuffer(pcdata);' : '') . ' pcdata = ' . ($mixed{$tag} ? '""' : 'NULL') . ';' - . " ETag_$myctag();" + . " ETag_${tagprefix}$myctag();" . (%inmixed ? ' pcdata = popbuffer();' : '') . "\n"; # @@ -1388,7 +1403,7 @@ print " \"</$tag\"{s}\">\" {\n"; print " LEAVE;\n"; print " BUFFERDONE;\n" if $mixed{$tag}; - print " ETag_$myctag();\n"; + print " ETag_${tagprefix}$myctag();\n"; print " pcdata = popbuffer();\n" if %inmixed; print $exitswitch; print " }\n"; @@ -1404,7 +1419,7 @@ # Errors when expecting root tag. if ($roottags{$tag} and $nofail) { print "\n"; - print "<ROOT_$myctag>{\n"; + print "<ROOT_${tagprefix}$myctag>{\n"; print " . FAIL(\"Unexpected character `%c': `$tag' element expected.\",yytext[0]);\n"; print " <<EOF>> FAIL(\"EOF in prolog.\");\n"; print "}\n"; @@ -1426,8 +1441,8 @@ my $sep = $`; for (@tags) { - print $sep . ($roottags{$_} ? "ROOT_$ctag{$_}," : "") - . "AL_$ctag{$_}"; + print $sep . ($roottags{$_} ? "ROOT_${tagprefix}$ctag{$_}," : "") + . "AL_${tagprefix}$ctag{$_}"; print ",$states{$_}" if $properempty{$_} or $children{$_}; $sep = ','; } @@ -1437,8 +1452,8 @@ elsif ( /FLEXML_COMMENTS([,>])/ ) { print "$`" - . join(',', map(($roottags{$_} ? "ROOT_$ctag{$_}," : "") - . "AL_$ctag{$_},$states{$_}", @tags)) + . join(',', map(($roottags{$_} ? "ROOT_${tagprefix}$ctag{$_}," : "") + . "AL_${tagprefix}$ctag{$_},$states{$_}", @tags)) . "$1$'"; } @@ -1545,19 +1560,19 @@ if ( m/^\#line ([0-9]+)/ ) { $lineno = $1; } - elsif ( m/^void\s+STag_($Name)\(void\)$/xo ) { + elsif ( m/^void\s+STag_${tagprefix}($Name)\(void\)$/xo ) { $tag = $1; die "\"$ACTIONS\", line $lineno: Unknown element `$tag'.\n" unless $ctag{$tag}; $startok{$tag} = 'true'; @myattributes = (exists $withattr{$tag} ? split /,/,"$withattr{$tag}" : ()); $isstart = 'true'; } - elsif ( m|^\}\s+\/\*\s+STag_($Name)\s+\*\/$|xo ) { + elsif ( m|^\}\s+\/\*\s+STag_${tagprefix}($Name)\s+\*\/$|xo ) { $tag = undef; @myattributes = (); $isstart = 'true'; } - elsif ( m/^void\s+ETag_($Name)\(void\)$/xo ) { + elsif ( m/^void\s+ETag_${tagprefix}($Name)\(void\)$/xo ) { $tag = $1; $endok{$1} = 'true'; $isstart = undef; @@ -1569,14 +1584,14 @@ # Replace special annotations with C equivalents. if ($tag) { - while ( s/\{($Name)\}/A_$ctag{$tag}_$catt{$1}/x ) { + while ( s/\{($Name)\}/A_${tagprefix}$ctag{$tag}_$catt{$1}/x ) { die "\"$ACTIONS\", line $lineno: Attributes only allowed in start tag.\n" if not $isstart; die "\"$ACTIONS\", line $lineno: Unknown attribute `$1' for <$tag>.\n" if not $atttype{"$tag/$1"}; } - while ( s/\{[!]($Name)\}/AU_$ctag{$tag}_$catt{$1}/x ) { + while ( s/\{[!]($Name)\}/AU_${tagprefix}$ctag{$tag}_$catt{$1}/x ) { die "\"$ACTIONS\", line $lineno: Attributes only allowed in start tag.\n" if not $isstart; die "\"$ACTIONS\", line $lineno: Unknown attribute `$1' for <$tag>.\n" @@ -1584,7 +1599,7 @@ } while ( s|\{($Name)=($Name)\}| - "A_$ctag{$tag}_$catt{$1}_" . variablify($2); |xe ) { + "A_${tagprefix}$ctag{$tag}_$catt{$1}_" . variablify($2); |xe ) { die "\"$ACTIONS\", line $lineno: Attributes only allowed in start tag.\n" if not $isstart; my ($att,$elt) = ($1,$2); @@ -1623,7 +1638,6 @@ close SCANNER || die "$0: Cannot close $SCANNER: $!\n"; } - =pod |