home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: alt.sources
- From: goer@ellis.uchicago.edu (Richard L. Goerwitz)
- Subject: kjv browser, part 2 of 11
- Message-ID: <1991Jul3.064929.27914@midway.uchicago.edu>
- Date: Wed, 3 Jul 1991 06:49:29 GMT
-
- ---- Cut Here and feed the following to sh ----
- #!/bin/sh
- # this is bibleref.02 (part 2 of a multipart archive)
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file listutil.icn continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 2; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping listutil.icn'
- else
- echo 'x - continuing file listutil.icn'
- sed 's/^X//' << 'SHAR_EOF' >> 'listutil.icn' &&
- X#
- X# writelist(), which writes a bitmap list in human readable form
- X# to a file.
- X#
- X############################################################################
- X#
- X# Links: ./rewrap.icn (also uses push_shell(), which is in ./passutil.icn)
- X#
- X############################################################################
- X
- X# Declared in bibleref.icn.
- X# record lst(l,pos,old_n,s)
- X
- X
- Xprocedure display_list()
- X
- X #
- X # Display a retrieved "hit list."
- X #
- X local passage, subscr
- X
- X #
- X # We're in the midst of a scanning expression in the main
- X # command loop. If the "d" command was given with no arguments,
- X # then default to the last list retrieved.
- X #
- X if pos(0) then {
- X subscr := (0 ~= *lists) | {
- X err_message("No lists have been created yet.")
- X fail
- X }
- X }
- X #
- X # If we are not at pos(0) then we are to go to a specific list
- X # in the list history.
- X #
- X else {
- X if not {
- X tab(upto('-+' ++ &digits)) &
- X subscr := integer(tab(many('-+' ++ &digits))) &
- X pos(0)
- X }
- X # If we don't have an integer, then the user has screwed
- X # up somehow.
- X then {
- X err_message("Garbage characters after \"d\" command.")
- X fail
- X }
- X # Check to be sure the subscript give is in range.
- X lists[subscr] | {
- X err_message("There is no list number "||subscr||".")
- X fail
- X }
- X }
- X
- X #
- X # While listlist gives us a valid passage reference, display it.
- X # When it returns &null or fails, quit.
- X #
- X repeat {
- X
- X # Display the list (defaults above to the last list in the list
- X # history). Use listlist(). Arg 1 is the lst record, which
- X # contains a list and a position to start viewing that list at.
- X # The second arg to listlist tells the user the length of the
- X # list. The last arg specifies how many display columns we can
- X # eat up before truncating.
- X passage := listlist(lists[subscr],
- X "list length = "||*lists[subscr].l,
- X getval("co")-10) | fail
- X if /passage then return
- X else display_passage(passage)
- X }
- X
- Xend
- X
- X
- X
- Xprocedure listlist(lst_rec, msg, width)
- X
- X local l, i, ss, j, n, prompt, rsp, rsp2
- X static lines
- X initial lines := getval("li")-3
- X
- X # "l" is a record of type lst, containing the list to print
- X # "msg" is the message to put on the status line
- X # "width" gives the length to which lines in l are truncated
- X # "offset" gives the starting offset in l at which to begin
- X # printing (default 0).
- X
- X l := lst_rec.l
- X
- X repeat {
- X i := 0
- X while *l >= (ss := lst_rec.pos + (lines > (i +:= 1))) do {
- X iputs(igoto(getval("cm"), 1, i))
- X normal(); iputs(getval("ce"))
- X writes(" ", left(ss||".",7))
- X if ss = \lst_rec.old_n then {
- X # Boldface last viewed passage from this list.
- X boldface(); writes(convertb(l[ss], kjv_filename)[1:\width|0])
- X normal()
- X } else writes(convertb(l[ss], kjv_filename)[1:\width|0])
- X }
- X
- X # If we haven't reached the end of the displayable screen,
- X # then clear lines until we reach it...
- X if i-1 ~= lines+1 then {
- X every j := i to lines+1 do {
- X iputs(igoto(getval("cm"), 1, j))
- X normal(); iputs(getval("ce"))
- X }
- X }
- X # Display message on status line.
- X status_line("-- " || \msg || " --" | "", "", "c")
- X
- X # If we're to the end of the screen, and there's still more to
- X # display, then...
- X if *l > lines & (lst_rec.pos+i) ~= (*l+1) then {
- X rsp :=
- X snarf_input("Press !/a/b/c/m/n/p/s/v/w (q = quit viewing): ")
- X case map(rsp) of {
- X "!" : push_shell()
- X "a" : write_list(l, "append")
- X "b" : lst_rec.pos := (0 < lst_rec.pos-lines+1) | 0
- X "c" : next
- X "m"|"" : (lst_rec.pos := (*l > (lst_rec.pos+i-1)))
- X "n" : {
- X n := \lst_rec.old_n+1 | {
- X err_message("Type \"v\" to set the current passage.")
- X next
- X }
- X if 0 < n <= *l then {
- X if not (lst_rec.pos < n < lst_rec.pos+lines)
- X then lst_rec.pos := (0 < n-2) | n-1
- X lst_rec.old_n := n & (return l[n])
- X } else err_message("Out of range.")
- X }
- X "p" : {
- X n := \lst_rec.old_n-1 | {
- X err_message("Type \"v\" to set the current passage.")
- X next
- X }
- X if 0 < n <= *l then {
- X if not (lst_rec.pos < n < lst_rec.pos+lines)
- X then lst_rec.pos := (0 < n-2) | n-1
- X lst_rec.old_n := n & (return l[n])
- X } else err_message("Out of range.")
- X }
- X "q" : break
- X "s" : {
- X l := (lst_rec.l := sort(lst_rec.l))
- X lst_rec.old_n := &null
- X }
- X "v" : {
- X rsp2 := snarf_input("View which passage: ")
- X rsp2 == (""|"q") & next
- X if n := integer(rsp2) then {
- X if 0 < n <= *l then {
- X if not (lst_rec.pos < n < lst_rec.pos+lines)
- X then lst_rec.pos := (0 < n-2) | n-1
- X lst_rec.old_n := n
- X return l[n]
- X } else err_message("Out of range.")
- X } else err_message("Invalid passage number.")
- X }
- X "w" : write_list(l)
- X default : {
- X if n := integer(rsp)-1 then {
- X if 0 <= n < *l
- X then lst_rec.pos := n
- X else err_message("Out of range.")
- X } else err_message("Invalid command.")
- X }
- X }
- X }
- X # ...otherwise, we've displayed everything.
- X else {
- X prompt := "c/n/p/s/v/w (q to go to previous menu): "
- X if *l <= lines
- X then rsp:= snarf_input("Press !/a/" || prompt) | next
- X else rsp := snarf_input("Press !/a/b/" || prompt) | next
- X case map(rsp) of {
- X "!" : push_shell()
- X "a" : write_list(l,"append")
- X "b" : lst_rec.pos := (0 < lst_rec.pos-lines+1) | 0
- X "c"|"" : next
- X "m" : next # no more to display; just stay were we are
- X "n" : {
- X n := \lst_rec.old_n+1 | {
- X err_message("No passage viewed yet from this list.")
- X next
- X }
- X if 0 < n <= *l then {
- X lst_rec.old_n := n & (return l[n])
- X if not (lst_rec.pos < n < lst_rec.pos+lines)
- X then lst_rec.pos := (0 < n-2) | n-1
- X } else err_message("Out of range.")
- X }
- X "p" : {
- X n := \lst_rec.old_n-1 | {
- X err_message("No passage viewed yet from this list.")
- X next
- X }
- X if 0 < n <= *l then {
- X lst_rec.old_n := n & (return l[n])
- X if not (lst_rec.pos < n < lst_rec.pos+lines)
- X then lst_rec.pos := (0 < n-2) | n-1
- X } else err_message("Out of range.")
- X }
- X "q" : break
- X "s" : {
- X l := (lst_rec.l := sort(lst_rec.l))
- X lst_rec.old_n := &null
- X }
- X "v" : {
- X rsp2 := snarf_input("View which passage: ")
- X rsp2 == (""|"q") & next
- X if n := integer(rsp2) then {
- X if 0 < n <= *l then {
- X if not (lst_rec.pos < n < lst_rec.pos+lines)
- X then lst_rec.pos := (0 < n-2) | n-1
- X lst_rec.old_n := n
- X return l[n]
- X } else err_message("Out of range.")
- X } else err_message("Invalid passage number.")
- X }
- X "w" : write_list(l)
- X default : {
- X if n := integer(rsp)-1 then {
- X if 0 <= n < *l
- X then lst_rec.pos := n
- X else err_message("Out of range.")
- X } else {
- X err_message("Invalid command.")
- X }
- X }
- X }
- X }
- X }
- X return
- X
- Xend
- X
- X
- X
- Xprocedure write_list(l, switch)
- X
- X #
- X # Used for writing the contents of a displayed list to a file.
- X #
- X local fname, outtext, i
- X
- X # Get straight whether we are appending or clobbering.
- X (/switch := "a") | (switch := "w")
- X
- X until \outtext do {
- X fname := snarf_input("Enter filename (! for shell; q to quit): ")
- X case fname of {
- X "" : fail
- X "!" : push_shell() & initialize_screen()
- X "q" : fail
- X default : {
- X outtext := open(fname, switch) | {
- X case switch of {
- X "a" : err_message("Can't append to " || fname || ".")
- X "w" : err_message("Cannot write to " || fname || ".")
- X default : quit("write_passage", "internal error", 80)
- X }
- X }
- X }
- X }
- X }
- X message("Writing.")
- X every i := 1 to *l do
- X write(outtext, " ", left(i||".",7), convertb(l[i], kjv_filename))
- X close(outtext)
- X message("Done.")
- X return
- X
- Xend
- X
- X
- X
- Xprocedure show_lists()
- X
- X #
- X # Display stats for all generated lists. So far the only routine
- X # that can generate lists is search_database(). Every time it
- X # generates a list, it inserts that list into the global list,
- X # lists (declared and initialized in bibleref.icn).
- X #
- X local expanded_list, i, result
- X
- X #
- X # We're in the midst of a scanning expression in the main
- X # command loop. If the "l" command was given with no arguments,
- X # then default to the last list retrieved.
- X #
- X if not pos(0) then {
- X err_message("Garbage characters after \"l\" command.")
- X fail
- X }
- X *lists = 0 & {
- X err_message("No lists in memory.")
- X fail
- X }
- X
- X repeat {
- X result :=
- X listlistS(lists, "list of viewable lists", getval("co")-10) | fail
- X if /result
- X then return
- X else result ? display_list()
- X }
- X
- Xend
- X
- X
- X
- Xprocedure listlistS(all_lists, msg, width)
- X
- X local l, offset, i, ss, j, n, prompt, rsp, rsp2
- X static lines
- X initial lines := getval("li")-3
- X
- X # "all_lists" is a list of records of type lst
- X # "msg" is the message to put on the status line
- X # "width" gives the length to which lines in l are truncated
- X
- X l := all_lists
- X
- X offset := 0
- X repeat {
- X i := 0
- X while *l >= (ss := offset + (lines > (i +:= 1))) do {
- X iputs(igoto(getval("cm"), 1, i))
- X normal(); iputs(getval("ce"))
- X writes(" ", left(ss||".",5))
- X writes("length = " || *l[i].l || ", search pattern = " || l[i].s)
- X }
- X
- X # If we haven't reached the end of the displayable screen,
- X # then clear lines until we reach it...
- X if i-1 ~= lines+1 then {
- X every j := i to lines+1 do {
- X iputs(igoto(getval("cm"), 1, j))
- X normal(); iputs(getval("ce"))
- X }
- X }
- X # Display message on status line.
- X status_line("-- " || \msg || " --" | "", "", "c")
- X
- X # If we're to the end of the screen, and there's still more to
- X # display, then...
- X if *l > lines & (offset+i) ~= (*l+1) then {
- X rsp := snarf_input("Press !/b/c/m/v (q = quit viewing): ")
- X case map(rsp) of {
- X "!" : push_shell()
- X "b" : offset := (0 < offset-lines+1) | 0
- X "c" : next
- X "m"|"" : (offset := (*l > (offset+i-1)))
- X "q" : break
- X "v" : {
- X rsp2 := snarf_input("View which list: ")
- X rsp2 == (""|"q") & next
- X if n := integer(rsp2) then {
- X if 0 < n <= *l
- X then return n
- X else err_message("Out of range.")
- X }
- X else err_message("Invalid passage number.")
- X }
- X default : {
- X err_message("Command invalid in this context.")
- X }
- X }
- X }
- X # ...otherwise, we've displayed everything.
- X else {
- X prompt := "c/v (q to go to previous menu): "
- X if *l <= lines
- X then rsp:= snarf_input("Press !/" || prompt) | next
- X else rsp := snarf_input("Press !/b/" || prompt) | next
- X case map(rsp) of {
- X "!" : push_shell()
- X "b" : offset := (0 < offset-lines+1) | 0
- X "c"|"" : next
- X "m" : next # no more to display; just stay were we are
- X "q" : break
- X "v" : {
- X rsp2 := snarf_input("View which list: ")
- X rsp2 == (""|"q") & next
- X if n := integer(rsp2) then {
- X if 0 < n <= *l
- X then return n
- X else err_message("Out of range.")
- X }
- X else err_message("Invalid passage number.")
- X }
- X default : {
- X err_message("Command invalid in this context.")
- X }
- X }
- X }
- X }
- X return
- X
- Xend
- X
- SHAR_EOF
- echo 'File listutil.icn is complete' &&
- true || echo 'restore of listutil.icn failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= passutil.icn ==============
- if test -f 'passutil.icn' -a X"$1" != X"-c"; then
- echo 'x - skipping passutil.icn (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting passutil.icn (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'passutil.icn' &&
- X############################################################################
- X#
- X# Name: 1.9
- X#
- X# Title: utilities for displaying passages
- X#
- X# Author: Richard L. Goerwitz
- X#
- X# Version: passutil.icn
- X#
- X############################################################################
- X#
- X# Contains:
- X#
- X# display_passage(ref), which displays ref, but fails if ref
- X# either can't be converted to a bitmap or else can, but
- X# doesn't correspond to any text in the main file
- X#
- X# listpassage(l, msg, width), which displays the lines contained
- X# in list l, truncating them to width, and displaying msg
- X# both near the top of the screen and on the status line
- X#
- X# writepassage(l, msg, switch), which writes list l to a file
- X# (the name of which it prompts the user to enter); if switch
- X# is nonnull, then it appends l to the file the user enters,
- X# rather then overwriting it
- X#
- X# get_{next,prev}_passage(), which generates the bitmap for the
- X# next/previous reference in the KJV file
- X#
- X# push_shell(), which suspends bibleref, and starts up either
- X# /bin/sh, or the program named in the SHELL environment
- X# variable.
- X#
- X############################################################################
- X#
- X# Links: ./rewrap.icn
- X#
- X# See also: ./bibleref.icn
- X#
- X############################################################################
- X
- X
- Xprocedure display_passage(passage_ref)
- X
- X local msg, d_list, bitmap, text
- X static width
- X # global kjv_filename
- X initial {
- X # decide how long to make lines. The display procedures
- X # listpassage leaves a margin on the left (8 spaces). On
- X # a typical display, it looks nice to leave about nine
- X # spaces on the other side. This leaves getval("co")-17
- X # spaces left for text in between. The space left for
- X # text here is stored in the static variable "width."
- X width := (18 < getval("co")-17) |
- X quit("display_passage","your terminal is too narrow",98)
- X }
- X
- X # Try to convert passage_ref to a retrieve-format bitmap.
- X if type(passage_ref) == "string" then {
- X *passage_ref > 0 | fail
- X bitmap := ref_2_bitmap(passage_ref, kjv_filename) | fail
- X }
- X # If the passage_ref is not a string, the it's probably already
- X # been converted; try to use it as-is.
- X else bitmap := passage_ref
- X
- X repeat {
- X
- X message("Locating text in main file...")
- X # Now check to see if the passage is present in the indexed text.
- X text := bitmap_2_text(bitmap, kjv_filename) | fail
- X
- X # Rewrap passage to width characters per line; put them into a list.
- X d_list := []
- X every put(d_list, rewrap(text, width))
- X put(d_list, rewrap(&null, width))
- X
- X # Get the name of the current passage, using standard abbrevs.
- X msg := convertb(bitmap, kjv_filename)
- X
- X # Display passage.
- X bitmap := listpassage(bitmap, d_list, msg, width) | fail
- X # If bitmap ends up null, then return.
- X if /bitmap then return
- X
- X }
- X
- Xend
- X
- X
- X
- Xprocedure listpassage(bitmap, l, msg, width)
- X
- X local offset, ss, done, i, j, n, rsp, prompt
- X static lines, top_margin
- X initial {
- X (lines := getval("li")-4) > 6 |
- X quit("listpassage", "your terminal isn't tall enough", 96)
- X top_margin := 3
- X }
- X
- X # "l" is a list of lines to print
- X # "msg" is the message to put on the status line
- X # "width" gives the length to which lines in l are truncated
- X
- X offset := 0
- X repeat {
- X
- X # Set up top margin.
- X every j := 1 to top_margin do {
- X iputs(igoto(getval("cm"), 1, j))
- X if j = 2 then {
- X writes(repl(" ",3))
- X underline()
- X writes(msg)
- X }
- X normal(); iputs(getval("ce"))
- X }
- X
- X i := 0
- X while *l >= (ss := offset + (lines > (i +:= 1))) do {
- X iputs(igoto(getval("cm"), 1, i+top_margin))
- X normal(); iputs(getval("ce"))
- X writes(repl(" ", 8), l[ss][1:\width|0])
- X }
- X
- X # If we haven't reached the end of the displayable screen,
- X # then clear lines until we reach it...
- X if i-1 ~= lines then {
- X every j := (i+top_margin) to lines+1 do {
- X iputs(igoto(getval("cm"), 1, j))
- X normal(); iputs(getval("ce"))
- X }
- X }
- X status_line("** " || \msg || " **" | "", "", "c")
- X
- X # If there's more to do, but we're at the end of the display,
- X # then...
- X if *l > lines & (offset+i) ~= (*l+1) then {
- X rsp := snarf_input("Press !/a/b/c/m/w/+/- (q to quit viewing): ")
- X case map(rsp) of {
- X "!" : push_shell()
- X "a" : write_passage(l, msg, "append")
- X "b" : offset := (0 < offset-lines+1) | 0
- X "c" : next
- X "m"|"" : (offset := (*l > (offset+i-1)))
- X "+" : return get_next_bitmap(bitmap)
- X "-" : return get_prev_bitmap(bitmap)
- X "q" : return
- X "w" : write_passage(l, msg)
- X default : err_message("Command is invalid in this context.")
- X }
- X }
- X # ...otherwise, we've displayed everything.
- X else {
- X prompt := "c/w/+/- (q to go to previous menu): "
- X if *l <= lines
- X then rsp:= snarf_input("Press !/a/" || prompt) | next
- X else rsp := snarf_input("Press !/a/b/" || prompt) | next
- X case map(rsp) of {
- X "!" : push_shell()
- X "a" : write_passage(l, msg, "append")
- X "b" : offset := (0 < offset-lines+1) | 0
- X "c"|"" : next
- X "m" : next
- X "+" : return get_next_bitmap(bitmap)
- X "-" : return get_prev_bitmap(bitmap)
- X "q" : return
- X "w" : write_passage(l, msg)
- X default : err_message("Command is invalid in this context.")
- X }
- X }
- X }
- X
- Xend
- X
- X
- X
- Xprocedure write_passage(passage_list, msg, switch)
- X
- X local fname, outtext
- X
- X # Get straight whether we are appending or clobbering.
- X (/switch := "w") | (switch := "a")
- X
- X until \outtext do {
- X fname := snarf_input("Enter filename (! for shell; q to quit): ")
- X case fname of {
- X "" : fail
- X "!" : push_shell() & initialize_screen()
- X "q" : fail
- X default : {
- X outtext := open(fname, switch) | {
- X case switch of {
- X "a" : err_message("Can't append to " || fname || ".")
- X "w" : err_message("Cannot write to " || fname || ".")
- X default : quit("write_passage", "internal error", 80)
- X }
- X }
- X }
- X }
- X }
- X message("Writing.")
- X write(\outtext, msg)
- X every write(outtext,!passage_list)
- X close(outtext)
- X message("Done.")
- X return
- X
- Xend
- X
- X
- X
- Xprocedure get_next_bitmap(lastone)
- X
- X local next_bitmap
- X initial message("Reading limits file...")
- X
- X next_bitmap := NextBitmap(lastone, kjv_filename) | {
- X err_message(convertb(lastone, kjv_filename) || " has no successor.")
- X fail
- X }
- X return next_bitmap
- X
- Xend
- X
- X
- X
- Xprocedure get_prev_bitmap(lastone)
- X
- X local prev_bitmap
- X initial message("Reading limits file...")
- X
- X prev_bitmap := PrevBitmap(lastone, kjv_filename) | {
- X err_message(convertb(lastone, kjv_filename) || " has no predecessor.")
- X fail
- X }
- X return prev_bitmap
- X
- Xend
- X
- X
- X
- Xprocedure push_shell()
- X
- X local status
- X static shell
- X initial shell := getenv("SHELL") | "/bin/sh"
- X
- X clear()
- X status := system(shell)
- X clear()
- X
- X return status
- X
- Xend
- SHAR_EOF
- true || echo 'restore of passutil.icn failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= srchutil.icn ==============
- if test -f 'srchutil.icn' -a X"$1" != X"-c"; then
- echo 'x - skipping srchutil.icn (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting srchutil.icn (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'srchutil.icn' &&
- X############################################################################
- SHAR_EOF
- true || echo 'restore of srchutil.icn failed'
- fi
- echo 'End of part 2'
- echo 'File srchutil.icn is continued in part 3'
- echo 3 > _shar_seq_.tmp
- exit 0
- --
-
- -Richard L. Goerwitz goer%sophist@uchicago.bitnet
- goer@sophist.uchicago.edu rutgers!oddjob!gide!sophist!goer
-