1 #!/usr/athena/bin/perl -i.bak
4 # 1. Schema must have "create table tablename" all on one line
5 # 2. Fields (columns) must be declared "NOT NULL WITH DEFAULT"
6 # 3. C variables corresponding to database fields must use the
7 # database field name with "t_" prefixed.
8 # 4. Field names, table names, and C "t_" variable names are of the same case
9 # 5. Only references within CURSOR loops are corrected.
12 # Step 1. Read the schema, so we know the proper field lengths
13 open(SCHEMA,"../db/schema") || die "Could not open schema, stopped\n";
16 if(/create\s+table\s+/) {
17 ($table,$ignore) = split(' ',$');
20 if(/\s+(\w+)\s+(VAR)?CHAR\((\d+)\)\s+NOT NULL WITH DEFAULT/) {
21 $fields{$table . "." . $1} = $3;
26 # Step 2. Read the code to be cleaned up
28 # Pass through most lines.
29 # Note the opening and closing of cursors.
30 # Play with IIcsGetio. Change 4th argument if it's wrong.
33 if(/IIwritio\(.*"select.*from\s+(\w+)"\);/) {
37 if(/IIcsGetio\((.*,.*,.*,(\d+),&?t_(\w+))\);/) {
41 $tablefield = $table . "." . $field;
42 $shouldbe = $fields{$tablefield};
44 if( $shouldbe && $shouldbe != $width ) {
45 s/(\(.*,.*,.*,)(\d+),/\1$shouldbe,/;