#!/net/u/1/f/fdc/kermit/wermit + #!/p/kd/fdc/bin.linux/wermit + # # pwa.ksc - convert PWA project table into a searchable, sortable table, # and also into a TSV (tab-separated-value) file. # # Script requires C-Kermit 9.0: # http://www.kermitproject.org/ckdaily.html # Top line of this file must show full path of C-Kermit executable. # # And sortability: requires Stuart Langridge's sorttable Javascript package: # https://kryogenix.org/code/browser/sorttable/ # # To be added: validation of each field to catch transcriptions errors. # # Usage: cd to desired directory, run this script with the name of # of the card-image file as an argument. # # Frank da Cruz, 8 June 2017 # Updated 14 June 2017 to add custom sort keys for docket numbers. # if not def \%1 { # Default input file on my own computer if \findex(panix.com,\v(host)) { cd ~/newdeal/virginia/ if fail exit 1 .\%1 := pwa-virginia.dat } else exit 1 "Usage: \%0 name-of-card-image-file" } .\%8 = style="text-align:left" .\%9 = style="text-align:right" dcl \&f[5] = 1:8 9:15 24:13 37:9 50:10 # card field definitions dcl \&a[5] = \%9 \%8 \%8 \%9 \%8 # table cell alignments dcl \&v[5] # table cell values fopen /read \%c \%1 # Open card-image file for input if fail exit 1 .tsvfile := \fstripx(\%1).tsv # Open TSV file for output fopen /write \%t \m(tsvfile) if fail exit 1 .htmlfile := \fstripx(\%1).tbl # Open html table file for output fopen /write \%o \m(htmlfile) if fail exit 1 def getfields { # Macro to extract fields from card image for i 1 5 1 { .\&v[i] := \fsqueeze(\s(line[\&f[i]])) } } fwrite /line \%o # Start the table .\%n = 0 while 1 { # Loop to read cards fread /line \%c line # Read a card if fail break # End of deck incr \%n # Count card getfields # Get its fields into array &v[] .tsvline := \fjoin(&v,TSV) # Make TSV record fwrite /line \%t \m(tsvline) # Write out TSV record fwrite /line \%o # Start table row .\%7 = td # Choose # End table row } fwrite /line \%o
or if ( == \%n 1 && > \fcode(\m(line)) 32 ) .\%7 = th .\%6 = # Make numeric sort key for docket no. if equ "\fleft(\&v[1],1)" "W" { # W prefix becomes 2 .\%6 := { sorttable_customkey="2\:(\&v[1][2])"} } else if equ "\fleft(\&v[1],1)" "X" { # X prefix becomes 3 .\%6 := { sorttable_customkey="3\:(\&v[1][2])"} } fwrite /line \%o "<\%7\%6 \&a[1]>\&v[1] " for i 2 5 1 { # Write table cells for this row fwrite /line \%o "<\%7 \&a[i]>\&v[i] " } fwrite /line \%o
# End table fclose \%t # Close files fclose \%c fclose \%o chmod 664 \m(htmlfile) # Make result files accessible chmod 664 \m(tsvfile) echo Cards: \%n # Print results xecho "HTML file: " dir \m(htmlfile) xecho "TSV file: " dir \m(tsvfile) exit ; Local Variables: ; comment-column:40 ; comment-start:"# " ; End: