Full Listing of spellcheck.awk
# spellcheck.awk -- interactive spell checker # # AUTHOR: Dale Dougherty # # Usage: nawk -f spellcheck.awk [+dict] file # (Use spellcheck as name of shell program) # SPELLDICT = "dict" # SPELLFILE = "file" # BEGIN actions perform the following tasks: # 1) process command line arguments # 2) create temporary filenames # 3) execute spell program to create wordlist file # 4) display list of user responses BEGIN { # Process command line arguments # Must be at least two args -- nawk and filename if (ARGC > 1) { # if more than two args, second arg is dict if (ARGC > 2) { # test to see if dict is specified with "+" # and assign ARGV[1] to SPELLDICT if (ARGV[1] ~ /^\+.*/) SPELLDICT = ARGV[1] else SPELLDICT = "+" ARGV[1] # assign file ARGV[2] to SPELLFILE SPELLFILE = ARGV[2] # delete args so awk does not open them as files delete ARGV[1] delete ARGV[2] } # not more than two args else { # assign file ARGV[1] to SPELLFILE SPELLFILE = ARGV[1] # test to see if local dict file exists if (! system ("test -r dict")) { # if it does, ask if we should use it printf ("Use local dict file? (y/n)") getline reply < "-" # if reply is yes, use "dict" if (reply ~ /[yY](es)?/){ SPELLDICT = "+dict" } } } } # end of processing args > 1 # if args not > 1, then print shell-command usage else { print "Usage: spellcheck [+dict] file" exit 1 } # end of processing command line arguments # create temporary file names, each begin with sp_ wordlist = "sp_wordlist" spellsource = "sp_input" ...
Get sed & awk, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.