IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 24, 2010, 11:15:44 AM (16 years ago)
Author:
rhenders
Message:

pspsSchema2xml now generates C header files with enums detailing table columns

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/scripts/pspsSchema2xml.pl

    r27364 r27431  
    2323        -msg => "\n   Required options:\n\n".
    2424        "--schema <path to PSPS schema>\n".
    25         "--type <IN|DT|OB>\n".
     25        "--type <init|det|diff|stack>\n".
    2626        -exitval => 3
    2727        ) unless
     
    2929defined $type;
    3030
    31 if ($type ne "DT" && $type ne "IN" && $type ne "OB" && $type ne "ST") {
     31if ($type ne "init" && $type ne "det" && $type ne "diff" && $type ne "stack") {
    3232
    3333    print "Don't understand type '$type'\n";
    3434    die;
    3535}
     36
     37my $enumsHeader = "ippToPsps".ucfirst($type)."Enums";
     38open(OUT, ">".$enumsHeader.".h") or die("Error");
     39
     40print OUT "#ifndef ".uc($enumsHeader)."_H\n";
     41print OUT "#define ".uc($enumsHeader)."_H\n\n";
    3642
    3743
     
    4248$writer->startTag('tableDescriptions', "type" => "$type");
    4349
    44 if ($type eq "IN") {createInit();}
    45 elsif ($type eq "DT") {createDetections();}
    46 elsif ($type eq "OB") {createDiffs();}
    47 elsif ($type eq "ST") {createStacks();}
     50if ($type eq "init") {createInit();}
     51elsif ($type eq "det") {createDetections();}
     52elsif ($type eq "diff") {createDiffs();}
     53elsif ($type eq "stack") {createStacks();}
    4854
    4955# finish up XML
     
    5157$writer->end();
    5258
    53 
    54 ######################################################################################3
    55 
    56 # finds the schema file containing this table description
     59print OUT "\n#endif";
     60close OUT;
     61
     62
     63#######################################################################################
     64#
     65# Finds the schema file containing the table name passed in
     66#
     67#######################################################################################
    5768sub findSchemaFile {
    5869    my ($tableName) = @_;
     
    8697}
    8798
    88 # creates detections tables
     99#######################################################################################
     100#
     101# Creates detection batch tables
     102#
     103#######################################################################################
    89104sub createInit {
    90105
     
    101116}
    102117
    103 # creates init batch tables
     118#######################################################################################
     119#
     120# Creates initialisation batch tables
     121#
     122#######################################################################################
    104123sub createDetections {
    105124
     
    111130}
    112131
    113 # creates diff batch tables
     132#######################################################################################
     133#
     134# Creates difference batch tables
     135#
     136#######################################################################################
    114137sub createDiffs {
    115138
     
    118141    parseTable("StackLowSigDelta");
    119142    parseTable("StackHighSigDelta");
    120 }
    121 
    122 # creates stack batch tables
     143    parseTable("ObjectCalColor");
     144}
     145
     146#######################################################################################
     147#
     148# Creates stack batch tables
     149#
     150#######################################################################################
    123151sub createStacks {
    124152
     
    130158}
    131159
    132 
    133 # parses out a table
     160#######################################################################################
     161#
     162# Parses a particular table from the SQL file and converts it to an XML description
     163#
     164#######################################################################################
    134165sub parseTable {
    135166    my ($tableName, $newName) = @_;
     
    144175    else {$tableNameOut = $tableName}
    145176
     177    print OUT "\ntypedef enum {\n";
    146178    $writer->startTag('table', "name" => $tableNameOut);
    147179
     
    150182    my $reading = 0;
    151183    my $found = 0;
     184    my $colNum = 0;
    152185    my $table;
    153186
     
    163196                $reading = 1;
    164197                $found = 1;
     198                $colNum = 0;
    165199                next;
    166200            }
     
    180214        if ($line =~ m/\*\//) {next;}
    181215
    182         processLine($line, $tableName);
     216        $colNum = processLine($line, $tableName, $colNum);
    183217
    184218    }
     
    186220    if (!$found) {print "Could not find table '$tableName'\n";}
    187221    $writer->endTag();
     222    print OUT "} ".$tableNameOut.";\n";
    188223
    189224    close SCHEMA;
    190225}
    191226
    192 # process line
     227#######################################################################################
     228#
     229# Processes a line from the PSPS schema table description and converts to XML
     230#
     231#######################################################################################
    193232sub processLine {
    194     my ($line, $tableName) = @_;
     233    my ($line, $tableName, $colNum) = @_;
    195234
    196235    my $name;
     
    223262
    224263        print "In '$tableName', can't process: '$line'\n";
    225         return 0
     264        return $colNum
    226265    }
    227266
     
    263302    if ($type eq "TSTRING" && $default eq "") {$default = " ";}
    264303
     304    $colNum++;
     305
     306    print OUT "  ".uc($tableName)."_".uc($name)." = ".$colNum.",\n";
     307
    265308    $writer->startTag('column',
    266309            "name" => $name,
     
    270313
    271314    $writer->endTag();
    272 }
    273 
    274 
    275 
    276 
    277 
    278 
    279 
     315
     316    return $colNum;
     317}
Note: See TracChangeset for help on using the changeset viewer.