home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3577 / bibleref.src < prev    next >
Encoding:
Text File  |  1991-07-03  |  6.2 KB  |  255 lines

  1. ############################################################################
  2. #
  3. #    Name:     bibleref.icn
  4. #
  5. #    Title:     Bible Reference Finder
  6. #
  7. #    Author:     Richard L. Goerwitz
  8. #
  9. #    Version: 1.10
  10. #
  11. ############################################################################
  12. #
  13. #  This program helps the user locate and browse passages from the
  14. #  King James Bible, as distributed in the 19-disk PC-SIG set.
  15. #  Startup syntax is
  16. #
  17. #      bibleref [-f filename]
  18. #
  19. #  where filename is the name of the indexed Bible text you wish to
  20. #  peruse.  Because the KJV filename is hard-coded into the program,
  21. #  you need not supply the -f argument.  It is available, though,
  22. #  just in case you have indexed another biblical file, and wish to
  23. #  use that instead.
  24. #
  25. #  This particular file contains only the basic command loop, some
  26. #  initialization routines, and some basic clearing/prompting/reading
  27. #  utilities.  The other integral file is listutil.icn, which contains
  28. #  all of the basic list and passage display routines.
  29. #
  30. ############################################################################
  31. #
  32. #  Requires: UNIX, fully updated & installed Icon Program Library
  33. #
  34. ############################################################################
  35. #
  36. #  Links: ./ref2bmap.icn ./name2num.icn ./convertb.icn ./complete.icn
  37. #         ./binsrch.icn ./bmp2text.icn ./initfile.icn ./retrieve.icn
  38. #         ./indexutl.icn ./retrops.icn ./whatnext.icn ./iolib.icn
  39. #         ./iscreen.icn ./listutil.icn ./rewrap.icn ./passutil.icn
  40. #         ./srchutil.icn (and probably others I've forgotten; see the
  41. #         Makefile for details about what depends on what).
  42. #
  43. #  Until incorporated into Icon, also link:  ./ipause.icn
  44. #
  45. #  See also: kjv2rtv.icn, makeind.icn, retrieve.icn, iolib.icn
  46. #
  47. ############################################################################
  48.  
  49. global kjv_filename, lists
  50. record lst(l,pos,old_n,s)
  51.  
  52.  
  53. procedure main(a)
  54.  
  55.     local option_table, filename, prompt, intext, first, result
  56.     # global lists
  57.     initial {
  58.     lists := []
  59.     checkout_features()
  60.     option_table := getopts(a, "f:")
  61.     kjv_filename := \option_table["f"] | "/usr/local/lib/bibleref/kjv.rtv"
  62.     initialize_screen()
  63.     message("Initializing offset file...")
  64.     initfile(kjv_filename) |
  65.         quit("main","can't locate "||kjv_filename,1)
  66.     }
  67.  
  68.     # Setup initial prompt.
  69.     prompt := "Enter passage, or f to find a word (q to quit):  "
  70.  
  71.     # Read user input.
  72.     while intext := snarf_input(prompt) do {
  73.  
  74.     trim(intext,'\t ') ? {
  75.  
  76.         # See if the user has just input a passage reference.
  77.         # If so, then display it...
  78.         if display_passage(intext) then
  79.         result := "yes"
  80.  
  81.         # ...otherwise, see if his/her input matches any of the
  82.         # following commands:
  83.         else {
  84.         first := move(1) | "c"
  85.         case first of {
  86.             "!" : push_shell() & initialize_screen()
  87.             "c" : initialize_screen()        # c = clear
  88.             "d" : display_list()             # d = display (a list)
  89.             "l" : show_lists()             # l = list all lists
  90.             "q" : {                 # q = quit program
  91.             if pos(0) & "y" == snarf_input("Really quit? (y/n)  ")
  92.             then break
  93.             }
  94.             "f" : {                 # f = find a word
  95.             if search_database() # insert new list into "lists"
  96.             then display_list()  # stores it as a record (lst)
  97.             }
  98.             default : {                 # input error
  99.             err_message("Unrecognized passage or command.")
  100.             next
  101.             }
  102.         }
  103.         }
  104.         # If we have any tangible search results, or else have viewed
  105.         # a passage, then alter the prompt to reflect the full range
  106.         # of options.
  107.         \result | *\lists > 0 &
  108.         prompt := "Enter passage, or !/c/d/l/q/f:  "
  109.     }
  110.     }
  111.  
  112.     # Clear, say goodbye, and exit with zero status.
  113.     initialize_screen()
  114.     message("Thank you for using Bibleref.")
  115.     write(); exit(0)
  116.  
  117. end
  118.  
  119.  
  120. procedure initialize_screen()
  121.  
  122.     #
  123.     # Initialize screen
  124.     #
  125.     local msg, short_message
  126.  
  127.     pos(0) | {
  128.     err_message("Garbage characters after \"c\" command.")
  129.     fail
  130.     }
  131.  
  132.     msg := "\"Bibleref\" - a King James Bible browser _
  133.            by Richard Goerwitz"
  134.     short_message := "\"Bibleref,\" by Richard Goerwitz"
  135.  
  136.     clear()
  137.     status_line(msg, short_message, "c") &
  138.     return
  139.  
  140. end
  141.  
  142.  
  143. procedure snarf_input(prompt)
  144.  
  145.     #
  146.     # Read user input after displaying a prompt.
  147.     #
  148.     local command
  149.     # global commands
  150.  
  151.     /prompt := "Please input:  "
  152.     message(prompt)
  153.     return read()
  154.  
  155. end
  156.  
  157.  
  158. procedure err_message(msg)
  159.  
  160.     #
  161.     #  Display error message for 1 second; erase.
  162.     #
  163.     /msg := "Error."
  164.     message(msg)
  165.     ipause(700)        # until Icon gets a sleep function
  166.     message("")
  167.     return
  168.  
  169. end
  170.     
  171.  
  172. procedure status_message(msg)
  173.  
  174.     #
  175.     #  Display some status message on the highlighted status line.
  176.     #
  177.     status_line(msg) &
  178.     return
  179.  
  180. end
  181.     
  182.  
  183. procedure checkout_features()
  184.  
  185.     #
  186.     # Check to see if we have the necessary terminal & OS features.
  187.     #
  188.     local capname
  189.  
  190.     every capname := ("li","co","ce","so") do {
  191.     getval(capname) | {
  192.         quit("check_features",
  193.          "terminal lacks "||capname||" capability", 2)
  194.     }
  195.     }
  196.     find("UNIX",&features) |
  197.     quit("check_features", "OS unsupported", 1)
  198.     return
  199.  
  200. end
  201.  
  202.  
  203. procedure quit(s1, s2, i)
  204.     
  205.     #
  206.     # Move cursor to bottom screen line & abort, sending the message
  207.     # s1: s2 to the user, and exiting with status i.
  208.     #
  209.     iputs(igoto(getval("cm"), 1, getval("li")))
  210.     iputs(getval("ce"))
  211.     abort(s1, s2, i)
  212.  
  213. end
  214.  
  215.  
  216. procedure getopts(arg,optstring)
  217.  
  218.     #
  219.     # Get opts.  Based on Bob Alexander & Gregg Townsend's IPL
  220.     # options procedure.
  221.     #
  222.     local x,i,c,otab,flist,o,p
  223.  
  224.     /optstring := string(&letters)
  225.     otab := table()
  226.     flist := []
  227.     while x := get(arg) do {
  228.     x ? {
  229.         if ="-" & not pos(0) then {
  230.         if ="-" & pos(0) then break
  231.         while c := move(1) do
  232.             if i := find(c,optstring) + 1 then
  233.             otab[c] :=
  234.             if any(':+.',o := optstring[i]) then {
  235.                         p := "" ~== tab(0) | get(arg) |
  236.                 quit("getopts", "No parameter following -"||c, 1)
  237.                         case o of {
  238.                 ":": p
  239.                 "+": integer(p) |
  240.                 quit("getopts", "-"||c||" needs numeric", 1)
  241.                 ".": real(p) |
  242.                 quit("getopts", "-"||c||" needs numeric", 1)
  243.             }
  244.             }
  245.             else 1
  246.             else quit("getopts","Unrecognized option: -"||c, 1)
  247.         }
  248.         else put(flist,x)
  249.     }
  250.     }
  251.     while push(arg,pull(flist))
  252.     return otab
  253.  
  254. end
  255.