# Filename: endnote.awk # Author: Eric Pement - pemente [=at=] northpark.edu # Version: 1.1 # Date: March 25, 2002 # Purpose: To convert in-text notes and references to endnotes # Requires: GNU awk; blank lines between paragraphs of input file # Usage: awk [-v start=N] -f endnote.awk yourfile.txt [>output.txt] # To start numbering with 12, use "-v start=12" (no brackets) # Output: Plain ASCII text. # See also: ENDNOTE.TXT, which further explains usage and application. # To do: check for mismatched "[[" and "]]" braces. # # Credits: The idea for this endnote system was borrowed from "wsNOTE" # by Eric Meyer, a 1988 MS-DOS utility for managing footnotes # in WordStar files. His program offered many extra features. BEGIN { if ( start != start + 0 ) { print "\aError!\nVariable ``start'' was set as ``" start "''. It", "must be a numeric value!" exit } a=b= (start=="" ? 0 : start - 1); str = ""; # Initialize some variables } /^\[\[ *$/,/^]] *$/ { # If between [[ and ]] markers .. if ( /^\[\[ *$/) next # .. skip the [[ marker, sub( /^]] *$/, "") # .. change the ]] marker to a blank line, sub(/\#\#\./, ++a ".") # .. increment each "##." to next variable 'a.', str = str $0 "\n" # .. append the line to 'str' string variable next # .. get next input line (works like ELSE) } { # If not between the [[ and ]] markers .. while ( /\[\#\#]/ ) { sub(/\[\#\#]/, "[" ++b "]") # .. increment each "##" for 'b' } print # .. and print that line. } END { # Error checking. if (start != start+0) exit if ( a != b ) { # Do nums match? "\a\a" beeps the console print "\a\a\n\n\n", "================\n WARNING!\n ================\n", "Body text numbers and Endnote numbers don't match!\n You have", a-1, "notes in the Body text and", b-1, "notes in the Endnote", "section.\n The Endnote section will not be printed.\n\n\n", "\n" >> "/dev/stderr" } else { print "\n-----------\nENDNOTES:\n" print str, "[end of file]" } } #---end of script---