IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 564


Ignore:
Timestamp:
May 3, 2004, 2:59:18 PM (22 years ago)
Author:
rhl
Message:

1/ Handle prefixes other than "ps" correctly
2/ Generate psErrorRegister() functions
3/ Commas in input files are now optional

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/pslib/bin/makeErrorCodes

    r321 r564  
    44#
    55$cfile = $hfile = undef;        # Output filenames (.{c,h})
    6 $indent = 4;                    # number of spaces to indent
    7 $prefix = "PS_ERR";             # Prefix for enums
     6$prefix = "ps";                 # Prefix for enums
    87$verbose = 0;                   # be chatty?
    98#
     
    3635   shift(@ARGV);
    3736}
     37
     38$prefix = lc("$prefix");        # e.g. ps
     39$PREFIX = uc("$prefix");        #      PS
     40
    3841
    3942if (!defined($cfile) && !defined($hfile)) {
     
    7073      #print "$_\n";
    7174
    72       ($name, undef, $val, $descrip) = /^\s*([^ \t]+)\s*(=\s*(\d+))?\s*,\s*(.*)/;
     75      ($name, undef, $val, $descrip) = /^\s*([^ \t]+)\s*(=\s*(\d+))?\s*,?\s*(.*)/;
    7376
    7477      push(@names,$name);
     
    7881}
    7982
    80 close(FD);
    81 #
    82 # And an entry for the total number of error codes
    83 #
    84 $name = "N_ERR_CLASSES";
    85 $values{$name} = undef;
    86 $descrips{$name} = undef;
    87 
    88 push(@names, $name);
     83close(FD)
    8984#
    9085# Generate .c file
     
    9893 * please do not modify it
    9994 */
     95#include "psError.h"
     96#include "${prefix}ErrorCodes.h"
    10097
    101 static struct {
    102     psErrorCode code;
    103     char *descrip;
    104 } errorStrings[] = {
     98void ${prefix}ErrorRegister(void)
     99{
     100    static psErrorDescription errors[] = {
    105101EOT
    106102
    107    foreach $name (@names) {
    108       printf FD "%*s{ ${prefix}_%s, ", $indent, "", $name;
    109       if (defined($descrips{$name})) {
    110          printf FD "\"%s\"", $descrips{$name};
    111       } else {
    112          printf FD "NULL";
    113       }
    114       printf FD "},\n";
     103    foreach $name (@names) {
     104       printf FD "        { ${PREFIX}_ERR_%s, ", $name;
     105       if (defined($descrips{$name})) {
     106          printf FD "\"%s\"", $descrips{$name};
     107       } else {
     108          printf FD "NULL";
     109       }
     110       printf FD " },\n";
    115111   }
    116112
     113
     114$names = @names;
    117115print FD <<"EOT";
    118 };
     116    };
     117    static int nerror = $names;         // number of values in enum
     118
     119    p_psErrorRegister(errors, nerror);
     120    nerror = 0;                                 // don't register more than once
     121}
    119122EOT
    120123}
     
    126129   
    127130   print FD <<"EOT";
    128 #if !defined(PS_ERROR_CODES_H)
    129 #define PS_ERROR_CODES_H
     131#if !defined(${PREFIX}_ERROR_CODES_H)
     132#define ${PREFIX}_ERROR_CODES_H
    130133/*
    131134 * This file was machine generated from $input_files;
     
    136139
    137140   foreach $name (@names) {
    138       printf FD "%*s${prefix}_%s", $indent, "", $name;
     141      printf FD "    ${PREFIX}_ERR_%s", $name;
    139142      if (defined($values{$name})) {
    140143         printf FD " = %d", $values{$name};
     
    144147         
    145148   print FD <<"EOT";
    146 } psErrorCode;
     149} ${prefix}ErrorCode;
     150
     151void ${prefix}ErrorRegister(void);
    147152
    148153#endif
     
    167172        -c file.c       Generate file.c
    168173        -h file.h       Generate file.h
    169         -p prefix       Change enum prefix from PS_ERR to \"prefix\"
     174        -p prefix       Change enum prefix from ps/PS to \"prefix/PREFIX\"
    170175        -v              Be chatty (repeat for even more output)
    171176";
Note: See TracChangeset for help on using the changeset viewer.