IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 10, 2010, 7:19:23 PM (16 years ago)
Author:
eugene
Message:

updates from eam_branches/20091201

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippMonitor/scripts/generate

    r26456 r26888  
    3737
    3838    foreach $line (@list) {
    39         chop $line;
    40         ($key, $value) = split (" ", $line, 2);
    41        
    42         # strip leading and trailing white space from the following
    43         if ($key eq "TABLE") { ($value) = $value =~ m|^\s*(.+)\s*$|; }
    44         if ($key eq "TYPE")  { ($value) = $value =~ m|^\s*(.+)\s*$|; }
    45 
    46         &set_keypair ($key, $value);
    47 
    48         # list of the table fields
    49         if ($key eq "FIELD") {
    50             ($field, $width, $format, $name, $show, $link, $extras) = split (/,\s+/, $value, 7);
    51             if (! $name) { die "table $ARGV[0] missing required elements\n"; }
    52             if ($field =~ m|\S+\s+as\s+\S+|) {
    53                 ($fieldreal) = $field =~ m|\S+\s+as\s+(\S+)|;
    54             } else {
    55                 $fieldreal = $field;
    56             }
    57            
    58             if ($VERBOSE) { printf "%-20s %-20s %-20s %-20s %-20s %-20s\n", $field, $name, $format, $show, $link, $extras; }
    59 
    60             if ($show eq "") {$show = "value";}
    61             push @field,     $field;
    62             push @fieldreal, $fieldreal;
    63             push @width,     $width;
    64             push @format,    $format;
    65             push @name,      $name;
    66             push @show,      $show;
    67             push @link,      $link;
    68             push @extras,    $extras;
    69         }
    70 
    71         if ($key eq "FILE") {
    72             $myFile = $value;
    73         }
    74 
    75         # list of the table fields
    76         if ($key eq "HEAD") {
    77             push @headcode, $value;
    78         }
    79 
    80         # the IMAGE commands sets up a reference name
    81         if ($key eq "IMAGE") {
    82             push @imagedefs, $value;
    83         }
    84 
    85         # the GROUP entries are used in summary tables as arguments to the GROUP BY sql statement
    86         if ($key eq "GROUP") {
    87             push @group, $value;
    88         }
    89 
    90         # the ARGS commands define arguments to FIELDS commands
    91         if ($key eq "ARGS") {
    92             push @linkargs, $value;
    93         }
    94 
    95         # the OP commands define field operations
    96         if ($key eq "OP") {
    97             push @opwords, $value;
    98         }
    99 
    100         # the TD_CLASS command sets up an alternate TD class
    101         if ($key eq "TD_CLASS") {
    102             push @tdClasses, $value;
    103             # print STDERR "found TD_CLASS\n";
    104         }
    105 
    106         # list of the table fields
    107         if ($key eq "TAIL") {
    108             push @tailcode, $value;
    109         }
    110 
    111         # list of the table restrictions
    112         # replace this with a flexible where statement?
    113         if ($key eq "WHERE") {
    114             ($field) = split (/,\s+/, $value, 1);
    115             if ($VERBOSE) { printf "%-20s\n", $field; }
    116             push @where,   $field;
    117         }
     39        chop $line;
     40        ($key, $value) = split (" ", $line, 2);
     41
     42        # strip leading and trailing white space from the following
     43        if ($key eq "TABLE") { ($value) = $value =~ m|^\s*(.+)\s*$|; }
     44        if ($key eq "TYPE")  { ($value) = $value =~ m|^\s*(.+)\s*$|; }
     45
     46        &set_keypair ($key, $value);
     47
     48        # list of the table fields
     49        if ($key eq "FIELD") {
     50            ($field, $width, $format, $name, $show, $link, $extras) = split (/,\s+/, $value, 7);
     51            if (! $name) { die "table $ARGV[0] missing required elements\n"; }
     52            if ($field =~ m|\S+\s+as\s+\S+|) {
     53                ($fieldreal) = $field =~ m|\S+\s+as\s+(\S+)|;
     54            } else {
     55                $fieldreal = $field;
     56            }
     57
     58            if ($VERBOSE) { printf "%-20s %-20s %-20s %-20s %-20s %-20s\n", $field, $name, $format, $show, $link, $extras; }
     59
     60            if ($show eq "") {$show = "value";}
     61            push @field,     $field;
     62            push @fieldreal, $fieldreal;
     63            push @width,     $width;
     64            push @format,    $format;
     65            push @name,      $name;
     66            push @show,      $show;
     67            push @link,      $link;
     68            push @extras,    $extras;
     69        }
     70
     71        if ($key eq "FILE") {
     72            $myFile = $value;
     73        }
     74
     75        # list of the table fields
     76        if ($key eq "HEAD") {
     77            push @headcode, $value;
     78        }
     79
     80        # the IMAGE commands sets up a reference name
     81        if ($key eq "IMAGE") {
     82            push @imagedefs, $value;
     83        }
     84
     85        # the GROUP entries are used in summary tables as arguments to the GROUP BY sql statement
     86        if ($key eq "GROUP") {
     87            push @group, $value;
     88        }
     89
     90        # the ARGS commands define arguments to FIELDS commands
     91        if ($key eq "ARGS") {
     92            push @linkargs, $value;
     93        }
     94
     95        # the OP commands define field operations
     96        if ($key eq "OP") {
     97            push @opwords, $value;
     98        }
     99
     100        # the TD_CLASS command sets up an alternate TD class
     101        if ($key eq "TD_CLASS") {
     102            push @tdClasses, $value;
     103            # print STDERR "found TD_CLASS\n";
     104        }
     105
     106        # list of the table fields
     107        if ($key eq "TAIL") {
     108            push @tailcode, $value;
     109        }
     110
     111        # list of the table restrictions
     112        # replace this with a flexible where statement?
     113        if ($key eq "WHERE") {
     114            ($field) = split (/,\s+/, $value, 1);
     115            if ($VERBOSE) { printf "%-20s\n", $field; }
     116            push @where,   $field;
     117        }
    118118    }
    119119
     
    126126    &check_key ("TITLE", "");
    127127    &check_key ("FILE", "");
    128    
     128
    129129    # these are used internally (not just a replacement)
    130130    for ($i = 0; $i < @key; $i++) {
    131         if ($key[$i] eq "MENU") { $MENU = $value[$i]; }
    132         if ($key[$i] eq "MODE") {
    133             if ($value[$i] eq "summary") {
    134                 if (@group == 0) {
    135                     print STDERR "a summary table must have at least one group\n";
    136                     exit 1;
    137                 }
    138                 &define_groups_string (@group);
    139             }
    140         }
     131        if ($key[$i] eq "MENU") { $MENU = $value[$i]; }
     132        if ($key[$i] eq "MODE") {
     133            if ($value[$i] eq "summary") {
     134                if (@group == 0) {
     135                    print STDERR "a summary table must have at least one group\n";
     136                    exit 1;
     137                }
     138                &define_groups_string (@group);
     139            }
     140        }
    141141    }
    142142
     
    149149
    150150    foreach $linkarg (@linkargs) {
    151         &parse_linkarg ($linkarg);
     151        # print STDERR "linkarg: $linkarg\n";
     152        &parse_linkarg ($linkarg);
    152153    }
    153154
    154155    foreach $imagedef (@imagedefs) {
    155         &parse_imagedef ($imagedef);
     156        &parse_imagedef ($imagedef);
    156157    }
    157158
    158159    foreach $opword (@opwords) {
    159         &parse_opwords ($opword);
    160     }
    161 
    162     if (0) {
    163         print STDERR "show: $show[0]\n";
    164         ($a, $b, $c) = &parse_label ($show[0]);
    165         print STDERR "a: $a, b: $b, c: $c\n";
    166 
    167         print STDERR "extras: $extras[0]\n";
    168         ($a, $b, $c) = &parse_label ($extras[0]);
    169         print STDERR "a: $a, b: $b, c: $c\n";
    170 
    171         print STDERR "show: $show[1]\n";
    172         ($a, $b, $c) = &parse_label ($show[1]);
    173         print STDERR "a: $a, b: $b, c: $c\n";
    174 
    175         print STDERR "extras: $extras[1]\n";
    176         ($a, $b, $c) = &parse_label ($extras[1]);
    177         print STDERR "a: $a, b: $b, c: $c\n";
    178         exit 0;
     160        &parse_opwords ($opword);
     161    }
     162
     163    if ($VERBOSE) {
     164        print STDERR "show: $show[0]\n";
     165        ($a, $b, $c) = &parse_label ($show[0]);
     166        print STDERR "a: $a, b: $b, c: $c\n";
     167
     168        print STDERR "extras: $extras[0]\n";
     169        ($a, $b, $c) = &parse_label ($extras[0]);
     170        print STDERR "a: $a, b: $b, c: $c\n";
     171
     172        print STDERR "show: $show[1]\n";
     173        ($a, $b, $c) = &parse_label ($show[1]);
     174        print STDERR "a: $a, b: $b, c: $c\n";
     175
     176        print STDERR "extras: $extras[1]\n";
     177        ($a, $b, $c) = &parse_label ($extras[1]);
     178        print STDERR "a: $a, b: $b, c: $c\n";
    179179    }
    180180}
     
    188188
    189189    foreach $line (@list) {
    190        
    191         &check_keypairs;
    192 
    193         print FILE $line;
    194 
    195         # fill in table header
    196         if ($line =~ m|// \*\* TABLE HEADER \*\*|) {
    197             &write_table_header;
    198         }
    199 
    200         # fill in TD_CLASS test
    201         if ($line =~ m|// \*\* TD CLASS \*\*|) {
    202             &write_td_class;
    203         }
    204 
    205         # fill in table data
    206         if ($line =~ m|// \*\* TABLE DATA \*\*|) {
    207             &write_table_data;
    208         }
    209 
    210         # fill in table query
    211         if ($line =~ m|// \*\* TABLE QUERY \*\*|) {
    212             &write_table_query;
    213         }
    214 
    215         # fill in table restricts
    216         if ($line =~ m|// \*\* TABLE RESTRICTIONS \*\*|) {
    217             &write_table_restrict;
    218         }
    219 
    220         # fill in table restricts
    221         if ($line =~ m|// \*\* BUTTON RESTRICTIONS \*\*|) {
    222             &write_button_restrict;
    223         }
    224 
    225         # fill in head HTML or PHP code
    226         if ($line =~ m|// \*\* HEAD CODE \*\*|) {
    227             &write_inline_code (@headcode);
    228         }
    229 
    230         # fill in tail HTML or PHP code
    231         if ($line =~ m|// \*\* TAIL CODE \*\*|) {
    232             &write_inline_code (@tailcode);
    233         }
     190
     191        &check_keypairs;
     192
     193        print FILE $line;
     194
     195        # fill in table header
     196        if ($line =~ m|// \*\* TABLE HEADER \*\*|) {
     197            &write_table_header;
     198        }
     199
     200        # fill in TD_CLASS test
     201        if ($line =~ m|// \*\* TD CLASS \*\*|) {
     202            &write_td_class;
     203        }
     204
     205        # fill in table data
     206        if ($line =~ m|// \*\* TABLE DATA \*\*|) {
     207            &write_table_data;
     208        }
     209
     210        # fill in table query
     211        if ($line =~ m|// \*\* TABLE QUERY \*\*|) {
     212            &write_table_query;
     213        }
     214
     215        # fill in table restricts
     216        if ($line =~ m|// \*\* TABLE RESTRICTIONS \*\*|) {
     217            &write_table_restrict;
     218        }
     219
     220        # fill in table restricts
     221        if ($line =~ m|// \*\* BUTTON RESTRICTIONS \*\*|) {
     222            &write_button_restrict;
     223        }
     224
     225        # fill in head HTML or PHP code
     226        if ($line =~ m|// \*\* HEAD CODE \*\*|) {
     227            &write_inline_code (@headcode);
     228        }
     229
     230        # fill in tail HTML or PHP code
     231        if ($line =~ m|// \*\* TAIL CODE \*\*|) {
     232            &write_inline_code (@tailcode);
     233        }
    234234    }
    235235    close (FILE);
     
    239239    my (@code) = @_;
    240240    my ($i, $code, $type);
    241    
     241
    242242    for ($i = 0; $i < @code; $i++) {
    243         ($type, $line) = split (" ", $code[$i], 2);
    244         if ($type eq "PHP") {
    245             print FILE "$line\n";
    246         }
    247         if ($type eq "HTML") {
    248             print FILE "?> $line <?\n";
    249         }
     243        ($type, $line) = split (" ", $code[$i], 2);
     244        if ($type eq "PHP") {
     245            print FILE "$line\n";
     246        }
     247        if ($type eq "HTML") {
     248            print FILE "?> $line <?\n";
     249        }
    250250    }
    251251}
     
    255255
    256256    # print the table header (field labels)
    257     print FILE "echo \"<tr><td></td>\\n\";\n"; 
    258     for ($i = 0; $i < @field; $i++) {
    259         ($label, $value, $string) = &parse_label ($show[$i]);
    260         if ($show[$i] eq "none")  { next; }
    261         print FILE "write_header_cell (\"list\", \"$name[$i]\");\n";
     257    print FILE "echo \"<tr><td></td>\\n\";\n";
     258    for ($i = 0; $i < @field; $i++) {
     259        ($label, $value, $string) = &parse_label ($show[$i]);
     260        if ($show[$i] eq "none")  { next; }
     261        print FILE "write_header_cell (\"list\", \"$name[$i]\");\n";
    262262    }
    263263    print FILE "echo \"</tr>\\n\";\n";
    264264
    265265    # print the column sort cells
    266     print FILE "echo \"<tr><td></td>\\n\";\n"; 
    267     for ($i = 0; $i < @field; $i++) {
    268         ($label, $value, $string) = &parse_label ($show[$i]);
    269         if ($show[$i] eq "none")  { next; }
    270         if ($field[$i] eq "*") { print FILE "echo \"<td></td>\\n\";\n"; next; } # empty cell (no sort for such fields)
    271         if ($label eq "op") {
    272             print FILE "write_sort_cell (\"list\", \"$opf{$value}\", \$buttonLink, \$ID, '$myFile');\n";
    273         } else {
    274             print FILE "write_sort_cell (\"list\", \"$fieldreal[$i]\", \$buttonLink, \$ID, '$myFile');\n";
    275         }
     266    print FILE "echo \"<tr><td></td>\\n\";\n";
     267    for ($i = 0; $i < @field; $i++) {
     268        ($label, $value, $string) = &parse_label ($show[$i]);
     269        if ($show[$i] eq "none")  { next; }
     270        if ($field[$i] eq "*") { print FILE "echo \"<td></td>\\n\";\n"; next; } # empty cell (no sort for such fields)
     271        if ($label eq "op") {
     272            print FILE "write_sort_cell (\"list\", \"$opf{$value}\", \$buttonLink, \$ID, '$myFile');\n";
     273        } else {
     274            print FILE "write_sort_cell (\"list\", \"$fieldreal[$i]\", \$buttonLink, \$ID, '$myFile');\n";
     275        }
    276276    }
    277277    print FILE "echo \"</tr>\\n\";\n";
     
    284284    foreach $tdClass (@tdClasses) {
    285285
    286         # TD_CLASS class field expression
    287         ($class, $testline) = split (" ", $tdClass, 2);
    288 
    289         $testlineFixed = "";
    290         @testlineBits = split (" ", $testline);
    291         foreach my $bit (@testlineBits) {
    292             $newbit = &parse_fieldname ($bit);
    293             $testlineFixed = "$testlineFixed $newbit";
    294         }
    295 
    296         print FILE "  if ($testlineFixed) {\n";
    297         print FILE "    \$class = \"$class\";\n";
    298         print FILE "  }\n";
     286        # TD_CLASS class field expression
     287        ($class, $testline) = split (" ", $tdClass, 2);
     288
     289        $testlineFixed = "";
     290        @testlineBits = split (" ", $testline);
     291        foreach my $bit (@testlineBits) {
     292            $newbit = &parse_fieldname ($bit);
     293            $testlineFixed = "$testlineFixed $newbit";
     294        }
     295
     296        print FILE "  if ($testlineFixed) {\n";
     297        print FILE "    \$class = \"$class\";\n";
     298        print FILE "  }\n";
    299299    }
    300300}
     
    304304
    305305    if ($WHERE) {
    306         print FILE "\$WHERE = \"WHERE $WHERE\";\n";
    307     }   
    308     for ($i = 0; $i < @field; $i++) {
    309         $value = $fieldreal[$i];
    310         if ($value eq "*") { next; }
    311         if ($format[$i] eq "%s") {
    312             print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'string', 1.0);\n";
    313             next;
    314         }
    315         if ($format[$i] eq "%C") {
    316             # convert the RA & DEC limits to radians for comparison
    317             print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'min', 0.017453);\n";
    318             print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'max', 0.017453);\n";
    319             next;
    320         }
    321         print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'string', 1.0);\n";
    322         print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'min', 1.0);\n";
    323         print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'max', 1.0);\n";
     306        print FILE "\$WHERE = \"WHERE $WHERE\";\n";
     307    }
     308    for ($i = 0; $i < @field; $i++) {
     309        $value = $fieldreal[$i];
     310        if ($value eq "*") { next; }
     311        if ($format[$i] eq "%s") {
     312            print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'string', 1.0);\n";
     313            next;
     314        }
     315        if ($format[$i] eq "%C") {
     316            # convert the RA & DEC limits to radians for comparison
     317            print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'min', 0.017453);\n";
     318            print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'max', 0.017453);\n";
     319            next;
     320        }
     321        print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'string', 1.0);\n";
     322        print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'min', 1.0);\n";
     323        print FILE "\$WHERE = check_restrict ('$value', \$WHERE, 'max', 1.0);\n";
    324324    }
    325325    print FILE "\$WHERE = check_ordering ('$GROUPS', \$WHERE);\n";
     
    330330
    331331    for ($i = 0; $i < @field; $i++) {
    332         $value = $fieldreal[$i];
    333         if ($value eq "*") { next; }
    334         if ($format[$i] eq "%s") {
    335             print FILE "\$buttonLink = button_restrict_string ('$value', \$buttonLink);\n";
    336         } else {
    337             print FILE "\$buttonLink = button_restrict_string ('$value', \$buttonLink);\n";
    338             print FILE "\$buttonLink = button_restrict_min ('$value', \$buttonLink);\n";
    339             print FILE "\$buttonLink = button_restrict_max ('$value', \$buttonLink);\n";
    340         }
     332        $value = $fieldreal[$i];
     333        if ($value eq "*") { next; }
     334        if ($format[$i] eq "%s") {
     335            print FILE "\$buttonLink = button_restrict_string ('$value', \$buttonLink);\n";
     336        } else {
     337            print FILE "\$buttonLink = button_restrict_string ('$value', \$buttonLink);\n";
     338            print FILE "\$buttonLink = button_restrict_min ('$value', \$buttonLink);\n";
     339            print FILE "\$buttonLink = button_restrict_max ('$value', \$buttonLink);\n";
     340        }
    341341    }
    342342}
     
    349349    print FILE "echo \"<tr><td>&ge;</td>\\n\";\n";
    350350    for ($i = 0; $i < @field; $i++) {
    351         if ($show[$i] eq "none")  { next; }
    352         if ($field[$i] eq "*")  {
    353             # * fields create an empty cell
    354             print FILE "echo \"<td> &nbsp; </td>\\n\";\n";
    355         } else {
    356             if ($format[$i] eq "%s") {
    357                 print FILE "write_query_row ('$fieldreal[$i]', $width[$i], 'string');\n";
    358             } else {
    359                 print FILE "write_query_row ('$fieldreal[$i]', $width[$i], 'min');\n";
    360             }
    361         }
     351        if ($show[$i] eq "none")  { next; }
     352        if ($field[$i] eq "*")  {
     353            # * fields create an empty cell
     354            print FILE "echo \"<td> &nbsp; </td>\\n\";\n";
     355        } else {
     356            if ($format[$i] eq "%s") {
     357                print FILE "write_query_row ('$fieldreal[$i]', $width[$i], 'string');\n";
     358            } else {
     359                print FILE "write_query_row ('$fieldreal[$i]', $width[$i], 'min');\n";
     360            }
     361        }
    362362    }
    363363    print FILE "echo \"</tr><tr><td>&le;</td>\\n\";\n";
    364364    for ($i = 0; $i < @field; $i++) {
    365         if ($show[$i] eq "none")  { next; }
    366         if (($field[$i] eq "*") || ($format[$i] eq "%s")) {
    367             # * fields create an empty cell
    368             print FILE "echo \"<td> &nbsp; </td>\\n\";\n";
    369         } else {
    370             print FILE "write_query_row ('$fieldreal[$i]', $width[$i], 'max');\n";
    371         }
     365        if ($show[$i] eq "none")  { next; }
     366        if (($field[$i] eq "*") || ($format[$i] eq "%s")) {
     367            # * fields create an empty cell
     368            print FILE "echo \"<td> &nbsp; </td>\\n\";\n";
     369        } else {
     370            print FILE "write_query_row ('$fieldreal[$i]', $width[$i], 'max');\n";
     371        }
    372372    }
    373373    print FILE "echo \"</tr>\\n\";\n";
     
    379379
    380380    for ($i = 0; $i < @field; $i++) {
    381         ($label, $value, $string) = &parse_label ($show[$i]);
    382         $Nrow = $count[$i];
    383 
    384         # create the link variable if this entry should be linked
    385         if ($label eq "none")  { next; }
    386 
    387         if ($label eq "value") {
    388             # create the basic link variable
    389             if ($link[$i]) {
    390                 print FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
    391                 # add extra GET data to target
    392                 if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); }
    393                 $myLink = "\$link";
    394             } else {
    395                 $myLink = "\"\"";
    396             }
    397             # print the actual table cell line with the link...
    398             if (! $value && ($field[$i] ne "*")) { $value = "\$row[$Nrow]"; }
    399 
    400             # add special format elements
    401             # $realFormat = $format[$i];
    402             # if ($format[$i] eq '%T') {
    403             #   $realFormat = '%s';
    404             # }
    405             print FILE "  write_table_cell (\$class, '$format[$i]', $myLink, $value);\n";
    406             next;
    407         }
    408 
    409         if ($label eq "op") {
    410             # create the basic link variable
    411             if ($link[$i]) {
    412                 print FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
    413                 # add extra GET data to target
    414                 if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); }
    415                 $myLink = "\$link";
    416             } else {
    417                 $myLink = "\"\"";
    418             }
    419             print FILE "  write_table_cell (\$class, '$format[$i]', $myLink, $ops{$value});\n";
    420             next;
    421         }
    422 
    423         if (($label eq "image") && !$link[$i]) {
    424             # print the actual table cell line with the image...
    425             print FILE "  echo \"<td class=\\\"\$class\\\">\n";
    426             print FILE "  echo \"              <img src=\\\"$image{$value}\\\"></td>\\n\";\n";
    427             next;
    428         }
    429 
    430         if (($label eq "image") && $link[$i]) {
    431             # create the basic link
    432             print FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
    433             # add extra php data to target
    434             if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); }
    435             # print the actual table cell line with the link...
    436             print FILE "  echo \"<td class=\\\"\$class\\\"><a href=\\\"\$link\\\"> <img src=\\\"$image{$value}\\\"> </a></td>\\n\";\n";
    437             next;
    438         }
     381        ($label, $value, $string) = &parse_label ($show[$i]);
     382        $Nrow = $count[$i];
     383
     384        # create the link variable if this entry should be linked
     385        if ($label eq "none")  { next; }
     386
     387        if ($label eq "value") {
     388            # create the basic link variable
     389            # print STDERR "value: $link[$i]\n";
     390            if ($link[$i]) {
     391                print FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
     392                # add extra GET data to target
     393                if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); }
     394                $myLink = "\$link";
     395            } else {
     396                $myLink = "\"\"";
     397            }
     398            # print the actual table cell line with the link...
     399            if (! $value && ($field[$i] ne "*")) { $value = "\$row[$Nrow]"; }
     400
     401            # add special format elements
     402            # $realFormat = $format[$i];
     403            # if ($format[$i] eq '%T') {
     404            #   $realFormat = '%s';
     405            # }
     406            print FILE "  write_table_cell (\$class, '$format[$i]', $myLink, $value);\n";
     407            next;
     408        }
     409
     410        if ($label eq "op") {
     411            # create the basic link variable
     412            if ($link[$i]) {
     413                print FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
     414                # add extra GET data to target
     415                if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); }
     416                $myLink = "\$link";
     417            } else {
     418                $myLink = "\"\"";
     419            }
     420            print FILE "  write_table_cell (\$class, '$format[$i]', $myLink, $ops{$value});\n";
     421            next;
     422        }
     423
     424        if (($label eq "image") && !$link[$i]) {
     425            # print the actual table cell line with the image...
     426            print FILE "  echo \"<td class=\\\"\$class\\\">\n";
     427            print FILE "  echo \"              <img src=\\\"$image{$value}\\\"></td>\\n\";\n";
     428            next;
     429        }
     430
     431        if (($label eq "image") && $link[$i]) {
     432            # create the basic link
     433            print FILE "  \$link = \"$link[$i]\" . \"?menu=$MENU&\" . \$ID['link'];\n";
     434            # add extra php data to target
     435            if ($extras[$i]) { &parse_extras ($linkarg{$extras[$i]}); }
     436            # print the actual table cell line with the link...
     437            print FILE "  echo \"<td class=\\\"\$class\\\"><a href=\\\"\$link\\\"> <img src=\\\"$image{$value}\\\"> </a></td>\\n\";\n";
     438            next;
     439        }
    439440    }
    440441}
     
    446447    $FIELDS = "$array[0]";
    447448    for ($i = 1; $i < @array; $i++) {
    448         # skip * fields (not a valid query element
    449         if ($array[$i] eq "*") { next; }
    450         $FIELDS = "$FIELDS,$array[$i]";
     449        # skip * fields (not a valid query element
     450        if ($array[$i] eq "*") { next; }
     451        $FIELDS = "$FIELDS,$array[$i]";
    451452    }
    452453    set_keypair ("FIELDS", $FIELDS);
     
    459460    $GROUPS = "$array[0]";
    460461    for ($i = 1; $i < @array; $i++) {
    461         # skip * fields (not a valid query element
    462         if ($array[$i] eq "*") { next; }
    463         $GROUPS = "$GROUPS,$array[$i]";
     462        # skip * fields (not a valid query element
     463        if ($array[$i] eq "*") { next; }
     464        $GROUPS = "$GROUPS,$array[$i]";
    464465    }
    465466    set_keypair ("GROUPS", $GROUPS);
     
    473474    $Nrow = 0;
    474475    for ($i = 0; $i < @field; $i++) {
    475         # skip * fields (not a valid query element
    476         if ($field[$i] eq "*") {
    477             $count[$i] = -1;
    478         } else {
    479             $count[$i] = $Nrow;
    480             $Nrow ++;
    481         }
     476        # skip * fields (not a valid query element
     477        if ($field[$i] eq "*") {
     478            $count[$i] = -1;
     479        } else {
     480            $count[$i] = $Nrow;
     481            $Nrow ++;
     482        }
    482483    }
    483484}
     
    491492    $WHERE = "$array[0]";
    492493    for ($i = 1; $i < @array; $i++) {
    493         $WHERE = "$WHERE AND $array[$i]";
    494     }
    495    
     494        $WHERE = "$WHERE AND $array[$i]";
     495    }
     496
    496497    set_keypair ("WHERE", $WHERE);
    497498}
     
    504505
    505506    # examine the extras and parse the embedded fields (comma-separated)
     507
    506508    @extfields = split (/,/, $extras);
    507509    for ($i = 0; $i < @extfields; $i++) {
    508         ($label, $value, $outline) = &parse_label ($extfields[$i]);
    509         print FILE "  \$link = \$link . \"&$outline\";\n";
     510        ($label, $value, $outline) = &parse_label ($extfields[$i]);
     511        print FILE "  \$link = \$link . \"&$outline\";\n";
    510512    }
    511513}
     
    519521    ($word, $value) = split (" ", $_[0]);
    520522
     523    # print STDERR "0: $_[0], $word, $value\n";
     524
    521525    if ($linkarg{$word}) {
    522         $linkarg{$word} = "$linkarg{$word},$value";
     526        $linkarg{$word} = "$linkarg{$word},$value";
    523527    } else {
    524         $linkarg{$word} = $value;
    525     }   
     528        $linkarg{$word} = $value;
     529    }
     530    # print STDERR "linkarg($word) : $linkarg{$word}\n";
    526531}
    527532
    528533# parse strings of the form label=value
    529 # if 'value' is of the form $field, try to match with 
     534# if 'value' is of the form $field, try to match with
    530535# a supplied DB field, and replace with $row[$n] if found
    531536sub parse_label {
     
    542547    if ($VERBOSE) { print STDERR "string: $string\n"; }
    543548    if ($string =~ m|\S+=\S+|) {
    544         ($label, $value) = $string =~ m|(\S+)=(\S+)|;
    545         if ($value =~ m|^\$|) {
    546           MATCH_LABEL:
    547             for ($i = 0; $i < @field; $i++) {
    548                 if ($field[$i] eq "*") { next; }
    549                 if ($value =~ m|^\$$fieldreal[$i]|) {
    550                     # print "field: $fieldreal[$i]\n";
    551                     ($name, $extra) = $value =~ m|^\$($fieldreal[$i])\@(\S+)|;
    552                     # print "name: $name\n";
    553                     # print "extra: $extra\n";
    554                     # print "value: $value\n";
    555 
    556                     $Nrow = $count[$i];
    557                     if ($extra) {
    558                         $value = "\$row[$Nrow]\@$extra";
    559                     } else {
    560                         $value = "\$row[$Nrow]";
    561                     }
    562                     # print "outval: $value\n";
    563                     last MATCH_LABEL;
    564                 }
    565             }
    566             $outline = "$label=$value";
    567         }
     549        ($label, $value) = $string =~ m|(\S+)=(\S+)|;
     550        if ($value =~ m|^\$|) {
     551          MATCH_LABEL:
     552            for ($i = 0; $i < @field; $i++) {
     553                if ($field[$i] eq "*") { next; }
     554                while ($value =~ m|\$$fieldreal[$i]|) {
     555                    # print "field: $fieldreal[$i]\n";
     556                    # ($part1, $name, $part2) = $value =~ m|\$($fieldreal[$i])\@(\S+)|;
     557                    ($part1, $name, $part2) = $value =~ m|(\S*)\$($fieldreal[$i])(\S*)|;
     558                    # print "name: $name\n";
     559                    # print "part1: $part1\n";
     560                    # print "part2: $part2\n";
     561                    # print "value: $value\n";
     562
     563                    $Nrow = $count[$i];
     564                    $value = $part1 . "\$row[$Nrow]" . $part2;
     565
     566                    # if ($part1 || $part2) {
     567                    # } else {
     568                    #     $value = "\$row[$Nrow]";
     569                    # }
     570                    # print "outval: $value\n";
     571                    # last MATCH_LABEL;
     572                }
     573            }
     574            $outline = "$label=$value";
     575        }
    568576    }
    569577    return ($label, $value, $outline);
     
    576584    my ($variable) = $_[0];
    577585    my ($i);
    578    
     586
    579587    # print STDERR "variable: $variable\n";
    580588
    581589    unless ($variable =~ m|^\$|) {
    582         return $variable;
     590        return $variable;
    583591    }
    584592
     
    588596
    589597    for ($i = 0; $i < @field; $i++) {
    590         # print STDERR "$i: $fieldreal[$i] : $fieldname\n";
    591 
    592         if ($field[$i] eq "*") { next; }
    593         if ($fieldname ne $fieldreal[$i]) { next; }
    594 
    595 
    596         $Nrow = $count[$i];
    597 
    598         $value = "\$row[$Nrow]";
    599 
    600         # print STDERR "found : $i : $count[$i] : $Nrow : $value\n";
    601         return $value;
     598        # print STDERR "$i: $fieldreal[$i] : $fieldname\n";
     599
     600        if ($field[$i] eq "*") { next; }
     601        if ($fieldname ne $fieldreal[$i]) { next; }
     602
     603
     604        $Nrow = $count[$i];
     605
     606        $value = "\$row[$Nrow]";
     607
     608        # print STDERR "found : $i : $count[$i] : $Nrow : $value\n";
     609        return $value;
    602610    }
    603611    return $variable;
     
    625633    @outfields = ();
    626634    foreach $word (@words) {
    627         $fword = &parse_fieldname ($word);
    628         # print "field: $word -> $fword\n";
    629         push @outwords, $fword;
    630         if ($word =~ m|^\$|) {
    631             $word = substr ($word, 1);
    632         }
    633         push @outfields, $word;
     635        $fword = &parse_fieldname ($word);
     636        # print "field: $word -> $fword\n";
     637        push @outwords, $fword;
     638        if ($word =~ m|^\$|) {
     639            $word = substr ($word, 1);
     640        }
     641        push @outfields, $word;
    634642    }
    635643    $outline = join (" ", @outwords);
     
    657665
    658666    for ($i = 0; $i < @key; $i++) {
    659         if ($key eq $key[$i]) {
    660             if ($value[$i] ne "") { die "key is multiply defined\n"; }
    661             $value[$i] = $value;
    662             if ($VERBOSE) { print STDERR "setting $key = $value\n"; }
    663             return;
    664         }
     667        if ($key eq $key[$i]) {
     668            if ($value[$i] ne "") { die "key is multiply defined\n"; }
     669            $value[$i] = $value;
     670            if ($VERBOSE) { print STDERR "setting $key = $value\n"; }
     671            return;
     672        }
    665673    }
    666674}
     
    672680
    673681    for ($i = 0; $i < @key; $i++) {
    674         if ($key eq $key[$i]) {
    675             if ($VERBOSE) { print "found $key: $key[$i]  -- $value[$i] (def: $default)\n"; }
    676             if (($default eq "") && ($value[$i] eq "")) { die "missing value for required key $key[$i]\n"; }
    677             if ($value[$i] eq "") { $value[$i] = $default; }
    678             return;
    679         }
     682        if ($key eq $key[$i]) {
     683            if ($VERBOSE) { print "found $key: $key[$i]  -- $value[$i] (def: $default)\n"; }
     684            if (($default eq "") && ($value[$i] eq "")) { die "missing value for required key $key[$i]\n"; }
     685            if ($value[$i] eq "") { $value[$i] = $default; }
     686            return;
     687        }
    680688    }
    681689    die "unknown key $key\n";
     
    685693    my ($i);
    686694    for ($i = 0; $i < @key; $i++) {
    687         if ($VERBOSE) { print "$key[$i]  -- $value[$i]\n"; }
    688         if ($line =~ m|\$$key[$i]|) {
    689             if ($value[$i] eq "") { die "missing value for required key $key[$i]\n"; }
    690             $line =~ s|\$$key[$i]|$value[$i]|g;
    691         }
    692     }
    693 }
    694 
    695 # we need to find the structure size, including padding 
    696 # i'm not sure I know the answer to this: it is probably 
    697 # the total number of bytes rounded up to the largest 
     695        if ($VERBOSE) { print "$key[$i]  -- $value[$i]\n"; }
     696        if ($line =~ m|\$$key[$i]|) {
     697            if ($value[$i] eq "") { die "missing value for required key $key[$i]\n"; }
     698            $line =~ s|\$$key[$i]|$value[$i]|g;
     699        }
     700    }
     701}
     702
     703# we need to find the structure size, including padding
     704# i'm not sure I know the answer to this: it is probably
     705# the total number of bytes rounded up to the largest
    698706# data item in the structure (ie, 8 for a double, etc)
    699707# if we have the size, then we can double check the structure
    700708# against the expectation at runtime.  for the moment,
    701 # calculate by hand and add to def.d file 
    702 
     709# calculate by hand and add to def.d file
     710
Note: See TracChangeset for help on using the changeset viewer.