#! /bin/gawk -f # Last edited on 2003-01-31 00:02:28 by stolfi BEGIN{ usage = ( ARGV[0] " < INFILE > OUTFILE" ); abort = -1; # Takes a file with raw data on the background grid dimensions, and # outputs a cleaned version, suitable for `source'ing into a script. # The input file may contain lines with the format # # NX NY BATCHDIR IMAGE # # where NX and NY are the grid dimensions in centimeters, # BATCHDIR is a image batch subdirectory (e.g. {misc/001}) # and IMAGE is the name of the image where the grid occurs, # minus the "-s.jpg" and ".jpg" extensions. # # The IMAGE may also be "batch" meaning that the data applies # to all images in the directory BATCHDIR. # # The output is a file with commands # # echo "NX NY" > BATCHDIR/IMAGE.grsz # printf "# Created mechanically by cleanup-gridsizes\n"; printf "\n"; } (abort >= 0){ exit abort; } /^ *([#]|$)/{ next; } /^ *[0-9]+ +[0-9]+ +[-A-Za-z0-9/._]+ +[-A-Za-z0-9/_]+ *($|[#])/{ sub(/ *[#].*$/, "", $0); if (NF != 4) { data_error(("bad line \"" $0 "\"")); } printf "echo \"%03d %03d\" > %s/%s.grsz\n", $1, $2, $3, $4; next; } //{ data_error(("unrecognized line \"" $0 "\"")); } function data_error(msg) { printf "line %d: ** %s\n", FNR, msg > "/dev/stderr"; abort = 1; exit abort; } function data_warning(msg) { printf "line %d: ** warning: %s\n", FNR, msg > "/dev/stderr"; }