---
 flexml.pl                            |   54 +++++++++++++++++------------------
 testbed/missing-att.stderr.expected  |    2 -
 testbed/multiple-att.stderr.expected |    2 -
 3 files changed, 29 insertions(+), 29 deletions(-)

Index: b/flexml.pl
===================================================================
--- a/flexml.pl
+++ b/flexml.pl
@@ -236,7 +236,7 @@ sub api_functions { # Print XML applicat
 
 sub api_types { # Print XML application interface types.
   print "/* XML application data. */\n" if %atttype;
-  for (keys %atttype) {
+  for (sort keys %atttype) {
     if (m.($Nmtoken)[/]($Nmtoken).xo) {
       my ($tag,$attribute) = ($1,$2);
       print "typedef $typeof{$_} AT_${tagprefix}$ctag{$tag}_$catt{$attribute};\n";
@@ -254,7 +254,7 @@ sub api_data { # Print XML application i
   print "extern char *${tagprefix}bufferstack;\n";
   print "#define ${tagprefix}pcdata (${tagprefix}bufferstack + ${tagprefix}pcdata_ix)\n";
 
-  for (keys %atttype) {
+  for (sort keys %atttype) {
     if (m.($Nmtoken)[/]($Nmtoken).xo) {
       print $pre . "AT_${tagprefix}$ctag{$1}_$catt{$2} AX_${tagprefix}$ctag{$1}_$catt{$2};\n";
       print "#define A_${tagprefix}$ctag{$1}_$catt{$2} ";
@@ -1004,7 +1004,7 @@ print STDOUT "Post-processing DTD.\n" if
 }
 
 # Complete all states with their `empty' equivalents.
-for my $tag (@tags) {
+for my $tag (sort @tags) {
 
   # Complete and prune instates and endstates...
   my %ins = ();
@@ -1035,13 +1035,13 @@ for my $tag (@tags) {
   }
 
   # Completion done...now store'em right back.
-  $instates{$tag} = join ',', keys %ins if %ins;
-  $endstates{$tag} = join ',', keys %ens if %ens;
-  $exittrans{$tag} = join ',', map "$_=>$exits{$_}", keys %exits if %exits;
+  $instates{$tag} = join ',', sort keys %ins if %ins;
+  $endstates{$tag} = join ',', sort keys %ens if %ens;
+  $exittrans{$tag} = join ',', map "$_=>$exits{$_}", sort keys %exits if %exits;
 }
 
 if (not %roottags) {
-  for (@tags) { $roottags{$_} = 'true'; }
+  for (sort @tags) { $roottags{$_} = 'true'; }
 }
 
 # Handling prefix
@@ -1118,7 +1118,7 @@ if ($debug) {
   print '%source = (' . printhash(\%source) . ")\n";
   print "\n";
 
-  print '@tags = (' . join(',',@tags) . ")\n";
+  print '@tags = (' . join(',',sort @tags) . ")\n";
   print '%ctag = (' . printhash(\%ctag) . ")\n";
 
   print '%states = (' . printhash(\%states) . ")\n";
@@ -1288,7 +1288,7 @@ if ($scanner or $standalone) {
     }
     elsif ( /^FLEXML_START_CONDITIONS$/ ) {
 
-      for (@tags) {
+      for (sort @tags) {
 	my $c = $ctag{$_};
 	print "%x"
             . ($roottags{$_} ? " ROOT_${tagprefix}$c" : "")
@@ -1317,7 +1317,7 @@ if ($scanner or $standalone) {
       for ('PROLOG','DOCTYPE','EPILOG','INCOMMENT','INPI','VALUE1','VALUE2','CDATA') {
 	print "  ${tagprefix}statenames[$_] = NULL;\n";
       }
-      for my $tag (@tags) {
+      for my $tag (sort @tags) {
 	my $c = $ctag{$tag};
 	print "  ${tagprefix}statenames[ROOT_${tagprefix}$c] = NULL;\n" if $roottags{$tag};
 	print "  ${tagprefix}statenames[AL_${tagprefix}$c] = NULL;\n";
@@ -1333,7 +1333,7 @@ if ($scanner or $standalone) {
 	              : ( $uri ? "(\"'$uri'\"|\"\\\"$uri\\\"\")"
 			       : "(\"'$dtd'\"|\"\\\"$dtd\\\"\")" );
 
-      for (keys %roottags) {
+      for (sort keys %roottags) {
 	my $c = $ctag{$_};
 	print " \"<!DOCTYPE\"{S}\"$_\"{S}"
 	    . "SYSTEM{S}" . $sysid . "{s}\">\" SET(ROOT_${tagprefix}$c);\n";
@@ -1348,10 +1348,10 @@ if ($scanner or $standalone) {
     elsif ( /^FLEXML_RULES$/ ) {
 
       # Dump all parameter entity declarations.
-      for (keys %parameter) { printsource($_); }
+      for (sort keys %parameter) { printsource($_); }
 
       # Dump all start and empty tag recognition rules.
-      for my $tag (@tags) {
+      for my $tag (sort @tags) {
 
 	my $myctag = $ctag{$tag};
 	my @myattributes = (exists $attlist{$tag} ? split /,/,"$attlist{$tag}" : ());
@@ -1359,7 +1359,7 @@ if ($scanner or $standalone) {
 
 	# Tag's source element and attribute declarations.
 	printsource($tag);
-	for my $attribute (@myattributes) {
+	for my $attribute (sort @myattributes) {
 	  printsource("$tag/$attribute");
 	}
 
@@ -1368,12 +1368,12 @@ if ($scanner or $standalone) {
 	if (exists $exittrans{$tag}) {
 	  $exitswitch .= "  switch (YY_START) {\n";
 	  my %casesto = ();
-	  for (split /,/,$exittrans{$tag}) {
+	  for (sort split /,/,$exittrans{$tag}) {
 	    if (m/^($Name)=>($Name)$/o) {
 	      $casesto{$2} .= "case $1: ";
 	    }
 	  }
-	  for (keys %casesto) {
+	  for (sort keys %casesto) {
 	    $exitswitch .= "   $casesto{$_}SET($_); break;\n" 
 	  }
 	  $exitswitch .= "  }\n";
@@ -1389,7 +1389,7 @@ if ($scanner or $standalone) {
 	    if (exists $instates{$tag}) {
 		for (split /,/,$instates{$tag}) { $ins{$_} = 'true'; }
 	    }
-	    my $str = '<' . join(',', grep {$ins{$_} eq 'false'} keys %ins);	    
+	    my $str = '<' . join(',', grep {$ins{$_} eq 'false'} sort keys %ins);
 	    if ($str ne '<') {
 		print "$str>\"<$tag\"{s} FAIL(\"Starting tag <$tag> is not allowed here.\");\n";
 	    }
@@ -1409,7 +1409,7 @@ if ($scanner or $standalone) {
 #              "\"<$tag\"{s} {\n";
 	print ">\"<$tag\"{s} {\n";
 
-	for my $attribute (@myattributes) {
+	for my $attribute (sort @myattributes) {
 	  print "  AX_${tagprefix}${myctag}_$catt{$attribute} = " . $initof{"$tag/$attribute"} . ";\n";
 	  print "  ${tagprefix}${myctag}_$catt{$attribute}_isset = 0;\n";
 	}
@@ -1425,7 +1425,7 @@ if ($scanner or $standalone) {
 	print "\n";
 	print "<AL_${tagprefix}$myctag>{\n";
 
-	for my $attribute (@myattributes) {
+	for my $attribute (sort @myattributes) {
 	  my $type; # set by conditions
 	  
 	  if ($type = $enumtype{"$tag/$attribute"}) {
@@ -1481,7 +1481,7 @@ if ($scanner or $standalone) {
 	# - the end of a start tag means to enter the contents after
 	#   checking that all required attributes were set.
 	print " \">\" {\n";
-	for my $attribute (@myattributes) {
+	for my $attribute (sort @myattributes) {
 	  if ($required{"$tag/$attribute"}) {
 	    print "  if (!AX_${tagprefix}$ctag{$tag}_" . variablify($attribute) . ")"
 	        . " FAIL(\"Required attribute `$attribute' not set for `$tag' element.\");\n";
@@ -1496,7 +1496,7 @@ if ($scanner or $standalone) {
 	# - accept and handle empty tags straight away,
 	if ($empty{$tag}) {
 	  print " \"/>\" {\n";
-	  for my $attribute (@myattributes) {
+	  for my $attribute (sort @myattributes) {
 	    if ($required{"$tag/$attribute"}) {
 	      print "  if (!AX_${tagprefix}$ctag{$tag}_" . variablify($attribute) . ")"
 		  . " FAIL(\"Required attribute `$attribute' not set for `$tag' element.\");\n";
@@ -1559,7 +1559,7 @@ if ($scanner or $standalone) {
     elsif ( /FLEXML_MIXED([,>])/ ) {
 
       if (%mixed) {
-	print  "$`" . join(',', map("IN_$ctag{$_}", keys %mixed)) . "$1$'";
+	print  "$`" . join(',', map("IN_$ctag{$_}", sort keys %mixed)) . "$1$'";
       }
       else {
 	print "$`IMPOSSIBLE$1$'";
@@ -1569,7 +1569,7 @@ if ($scanner or $standalone) {
     elsif ( /FLEXML_NON_MIXED([,>])/ ) {
 
       my $sep = $`;
-      for (@tags) {
+      for (sort @tags) {
 	print $sep . ($roottags{$_} ? "ROOT_${tagprefix}$ctag{$_}," : "")
             . "AL_${tagprefix}$ctag{$_}";
 	print ",$states{$_}" if $properempty{$_} or $children{$_};
@@ -1582,14 +1582,14 @@ if ($scanner or $standalone) {
 
       print "$`"
 	  . join(',', map(($roottags{$_} ? "ROOT_${tagprefix}$ctag{$_}," : "")
-			  . "AL_${tagprefix}$ctag{$_},$states{$_}", @tags))
+			  . "AL_${tagprefix}$ctag{$_},$states{$_}", sort @tags))
 	  . "$1$'";
 
     }
     elsif ( /^FLEXML_ENTITIES$/ ) {
 
       # Process general entities.
-      for my $ent (keys %entity) {
+      for my $ent (sort keys %entity) {
 	printsource("%$ent;");
 	print " \"&$ent;\" ENTITYTEXT(\"" . $entity{$ent} . "\");\n";
       }
@@ -1605,8 +1605,8 @@ if ($scanner or $standalone) {
     elsif ( /^FLEXML_FINAL$/ and not $nofail ) {
 
       # Catch-all error cases.
-      for my $tag (@tags) {
-	 for (split ',',$states{$tag}) {
+      for my $tag (sort @tags) {
+	 for (sort split ',',$states{$tag}) {
 	   print "<$_>{\n";
 	   print " .    FAIL(\"Unrecognized `%c' in $_.\",yytext[0]);\n";
 	   print " [\\n] FAIL(\"Unrecognized newline in $_.\");\n";
Index: b/testbed/missing-att.stderr.expected
===================================================================
--- a/testbed/missing-att.stderr.expected
+++ b/testbed/missing-att.stderr.expected
@@ -1 +1 @@
-Invalid XML (state 13): Required attribute `batt' not set for `bar' element.
+Invalid XML (state 10): Required attribute `batt' not set for `bar' element.
Index: b/testbed/multiple-att.stderr.expected
===================================================================
--- a/testbed/multiple-att.stderr.expected
+++ b/testbed/multiple-att.stderr.expected
@@ -1 +1 @@
-Invalid XML (state 13): Multiple definition of attribute batt in <bar>
+Invalid XML (state 10): Multiple definition of attribute batt in <bar>
