Index: trunk/ippToPsps/scripts/pspsSchema2xml.pl
===================================================================
--- trunk/ippToPsps/scripts/pspsSchema2xml.pl	(revision 27364)
+++ trunk/ippToPsps/scripts/pspsSchema2xml.pl	(revision 27431)
@@ -23,5 +23,5 @@
         -msg => "\n   Required options:\n\n".
         "--schema <path to PSPS schema>\n".
-        "--type <IN|DT|OB>\n".
+        "--type <init|det|diff|stack>\n".
         -exitval => 3
         ) unless
@@ -29,9 +29,15 @@
 defined $type;
 
-if ($type ne "DT" && $type ne "IN" && $type ne "OB" && $type ne "ST") {
+if ($type ne "init" && $type ne "det" && $type ne "diff" && $type ne "stack") {
 
     print "Don't understand type '$type'\n"; 
     die;
 }
+
+my $enumsHeader = "ippToPsps".ucfirst($type)."Enums";
+open(OUT, ">".$enumsHeader.".h") or die("Error");
+
+print OUT "#ifndef ".uc($enumsHeader)."_H\n";
+print OUT "#define ".uc($enumsHeader)."_H\n\n";
 
 
@@ -42,8 +48,8 @@
 $writer->startTag('tableDescriptions', "type" => "$type");
 
-if ($type eq "IN") {createInit();}
-elsif ($type eq "DT") {createDetections();}
-elsif ($type eq "OB") {createDiffs();}
-elsif ($type eq "ST") {createStacks();}
+if ($type eq "init") {createInit();}
+elsif ($type eq "det") {createDetections();}
+elsif ($type eq "diff") {createDiffs();}
+elsif ($type eq "stack") {createStacks();}
 
 # finish up XML
@@ -51,8 +57,13 @@
 $writer->end();
 
-
-######################################################################################3
-
-# finds the schema file containing this table description
+print OUT "\n#endif";
+close OUT;
+
+
+#######################################################################################
+#
+# Finds the schema file containing the table name passed in
+#
+#######################################################################################
 sub findSchemaFile {
     my ($tableName) = @_;
@@ -86,5 +97,9 @@
 }
 
-# creates detections tables
+#######################################################################################
+#
+# Creates detection batch tables
+#
+#######################################################################################
 sub createInit {
 
@@ -101,5 +116,9 @@
 }
 
-# creates init batch tables
+#######################################################################################
+#
+# Creates initialisation batch tables
+#
+#######################################################################################
 sub createDetections {
 
@@ -111,5 +130,9 @@
 }
 
-# creates diff batch tables
+#######################################################################################
+#
+# Creates difference batch tables
+#
+#######################################################################################
 sub createDiffs {
 
@@ -118,7 +141,12 @@
     parseTable("StackLowSigDelta");
     parseTable("StackHighSigDelta");
-}
-
-# creates stack batch tables
+    parseTable("ObjectCalColor");
+}
+
+#######################################################################################
+#
+# Creates stack batch tables
+#
+#######################################################################################
 sub createStacks {
 
@@ -130,6 +158,9 @@
 }
 
-
-# parses out a table
+#######################################################################################
+#
+# Parses a particular table from the SQL file and converts it to an XML description 
+#
+#######################################################################################
 sub parseTable {
     my ($tableName, $newName) = @_;
@@ -144,4 +175,5 @@
     else {$tableNameOut = $tableName}
 
+    print OUT "\ntypedef enum {\n";
     $writer->startTag('table', "name" => $tableNameOut);
 
@@ -150,4 +182,5 @@
     my $reading = 0;
     my $found = 0;
+    my $colNum = 0;
     my $table;
 
@@ -163,4 +196,5 @@
                 $reading = 1;
                 $found = 1;
+                $colNum = 0;
                 next;
             }
@@ -180,5 +214,5 @@
         if ($line =~ m/\*\//) {next;}
 
-        processLine($line, $tableName);
+        $colNum = processLine($line, $tableName, $colNum);
 
     }
@@ -186,11 +220,16 @@
     if (!$found) {print "Could not find table '$tableName'\n";}
     $writer->endTag();
+    print OUT "} ".$tableNameOut.";\n";
 
     close SCHEMA;
 }
 
-# process line
+#######################################################################################
+#
+# Processes a line from the PSPS schema table description and converts to XML
+#
+#######################################################################################
 sub processLine {
-    my ($line, $tableName) = @_;
+    my ($line, $tableName, $colNum) = @_;
 
     my $name;
@@ -223,5 +262,5 @@
 
         print "In '$tableName', can't process: '$line'\n";
-        return 0
+        return $colNum
     }
 
@@ -263,4 +302,8 @@
     if ($type eq "TSTRING" && $default eq "") {$default = " ";}
 
+    $colNum++;
+
+    print OUT "  ".uc($tableName)."_".uc($name)." = ".$colNum.",\n";
+
     $writer->startTag('column',
             "name" => $name,
@@ -270,10 +313,5 @@
 
     $writer->endTag();
-}
-
-
-
-
-
-
-
+
+    return $colNum;
+}
