### /u/sy/beebe/tex/bib/check-page-range.awk, Tue Mar 19 15:16:40 1996 ### Edit by Nelson H. F. Beebe ### ==================================================================== ### Check a BibTeX bibliography file for inconsistent page ranges. ### Although bibclean can do this more generally, this program is a ### fast alternative. ### ### Usage: ### nawk -f check-page-range.awk ### ### [09-Nov-2000] -- add check_range() function, and augment code in ### check_pages() to handle lists of numbers and ranges ### [08-Apr-1996] -- add some more patterns to avoid flagging certain ### acceptable page ranges. ### [19-Mar-1996] -- original version ### ==================================================================== BEGIN {} /^ *pages *= */ { check_pages() } END { print nchecks " checks made" } ### ==================================================================== function check_pages( this,k,last,n,parts,s) { s = substr($0,index($0,"\"")) sub(/^\"/,"",s) sub(/\",/,"",s) if (match(s,/^[0-9]+--[0-9]+$/)) { split(s,parts,"--") if (parts[2] < parts[1]) warning("Inconsistent page range: [" s "]") nchecks++ } else if (match(s,/^[0-9]+--[?]+$/)) { split(s,parts,"--") if (parts[2] < parts[1]) warning("Inconsistent page range: [" s "]") nchecks++ } else if (match(s,/^[- ,0-9]+$/)) { n = split(s,parts," *, *") last = 0 for (k = 1; k <= n; ++k) { ## print "DEBUG: parts[" k "] = [" parts[k] "]" if (parts[k] ~ "^[0-9]+-+[0-9]+$") this = 0 + check_range(parts[k]) else this = 0 + parts[k] if (last >= this) warning("out-of-order page numbers (" last "," this "): " s ) last = this } nchecks++ } else if (match(s,/^[0-9]+$/)) { nchecks++ } else if (match(s,/^various$/)) { } else if (match(s,/^[?]*$/)) { } else if (match(s,/^[?]+--[?]+$/)) { } else if (match(s,/^([0-9]+(--[0-9]+)?, *)+[0-9]+(--[0-9]+)?$/)) { } else if (match(s,/^[icdlmvx]+ *[+]+ *[0-9]+$/)) { } else warning("Unrecognized page number field: [" s "]") } function check_range(s, parts) { ## Check a page range of the form "mmm--nnn" , and return the ## first of the pair. if (split(s,parts,"--") != 2) { warning("expected page range, but found " s) return (-1) } else if ((0 + parts[1]) >= (0 + parts[2])) { warning("out-of-order page range: " s) return (parts[1]) } else return (parts[1]) } function warning(message) { print FILENAME ":" FNR ":%%" message >"/dev/stderr" }