home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume20
/
bibleref
/
part01
next >
Wrap
Text File
|
1991-07-18
|
36KB
|
1,169 lines
Newsgroups: comp.sources.misc
From: Richard Goerwitz <goer@midway.uchicago.edu>
Subject: v20i099: bibleref - Word and passage retrievals from King James Bible, Part01/07
Message-ID: <csm-v20i099=bibleref.215242@sparky.imd.sterling.com>
X-Md4-Signature: ead405db03944642c762da100f918f03
Date: Thu, 18 Jul 1991 03:00:17 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: Richard Goerwitz <goer@midway.uchicago.edu>
Posting-number: Volume 20, Issue 99
Archive-name: bibleref/part01
Environment: ICON, UNIX
Program: Bibleref
Language: Icon
Purpose: Perform word and passage-based retrievals on the King James Bible
Overview:
This package, Bibleref, offers simple tools for word and
passage-based access to the King James Bible on UNIX platforms.
Bibleref is fast, and easy to install (assuming you possess a suitable
King James Bible text and a sufficiently powerful machine). It will
also run with stock terminals - even nasty old ones that leave magic
cookies on your screen. Bibleref will, however, put a significant
dent in your mass storage resources. Along with the 4-5 megabytes of
King James Bible text, you'll need to house some 2 megabytes of
indices, and also the 150k icode file (more if you compile, rather
than interpret). In-core requirements start at about 800k, and go up
from there (if your searches are complex enough, you could easily eat
up two or three megabytes). In brief: Bibleref has a large appetite
for memory. Once set up, though, it can operate with fairly minimal
impact on the CPU.
With Bibleref, you can perform most of the more basic,
low-level functions commercial Bible browsing packages offer (and
perhaps a few not found in some of the commercial packages). You can,
for example,
- retrieve any passage in the Bible instantaneously
- move forward or backward relative to the retrieved passage
- search the entire Bible for words and/or word-patterns
- search for word co-occurrences (or the absence thereof)
- save passages and/or passage-lists for use with an editor
Although this program is hardly the product of any major research
effort :-), it should prove sophisticated enough for quick lookup of
passages whose precise location you have forgotten, for research on
sermons and Bible study classes, and for general topical perusal of
the biblical text.
To install Bibleref, you'll need to get a hold of the King
James Bible text as packaged in the PC-SIG disk set (19 disks), which
is available from wsmr-simtel20.army.mil. I happen to have gotten my
texts (very similar to the PC-SIG version) from helens.stanford.edu
(36.0.2.99; kjv.tar.Z). These ones work as well. There are a number
of KJV texts floating around which are derivative of the PC-SIG disk
set. Only ones which have not been edited too severely will work,
unmodified, with the stock Bibleref installation program.
Additional Notes:
As mentioned above, this package is really just a wrapper
around a more general set of indexing and retrieval utilities I'm
using for personal research. Despite the way they are used here,
these utilities are *not* geared solely for the KJV. In fact, they
are set up so that they can be used with just about any text broken up
into hierarchically arranged divisions. If, for instance, you don't
like Renaissance English, and have a more modern Bible translation
online, you can certainly use that instead. All you'll need to do is
copy the kjv2rtv.icn file to, say, kjv2rsv.icn, edit it to reflect the
text you are using, run it on your text, and then index it as you
would have done for the King James text. You can tell Bibleref to use
this text instead of the King James text either by modifying
bibleref.icn to point to the new file, or by giving it a filename
argument, a la "bibleref -f your.indexed.bible.text."
-Richard L. Goerwitz goer%sophist@uchicago.bitnet
goer@sophist.uchicago.edu rutgers!oddjob!gide!sophist!goer
---- Cut Here and feed the following to sh ----
#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 07/14/1991 19:06 UTC by richard@zenu
# Source directory /u/richard/Bibleref/src
#
# existing files will NOT be overwritten unless -c is specified
# This format requires very little intelligence at unshar time.
# "if test", "cat", "rm", "echo", "true", and "sed" may be needed.
#
# This is part 1 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 6521 -rw-r--r-- bibleref.src
# 3103 -r--r--r-- ref2bmap.icn
# 2991 -r--r--r-- name2num.icn
# 2716 -r--r--r-- convertb.icn
# 13413 -r--r--r-- listutil.icn
# 7191 -r--r--r-- passutil.icn
# 2816 -r--r--r-- readfile.icn
# 6117 -r--r--r-- srchutil.icn
# 456 -r--r--r-- version.icn
# 5988 -r--r--r-- complete.icn
# 744 -r--r--r-- ipause.icn
# 4314 -r--r--r-- rewrap.icn
# 1855 -r--r--r-- binsrch.icn
# 4974 -r--r--r-- bmp2text.icn
# 3059 -r--r--r-- initfile.icn
# 7107 -r--r--r-- retrieve.icn
# 7264 -r--r--r-- indexutl.icn
# 6797 -r--r--r-- retrops.icn
# 6601 -r--r--r-- whatnext.icn
# 18055 -r--r--r-- iolib.icn
# 6945 -r--r--r-- iscreen.icn
# 20980 -r--r--r-- findre.icn
# 2176 -r--r--r-- kjv2rtv.icn
# 1328 -r--r--r-- convertr.icn
# 16283 -r--r--r-- makeind.icn
# 2423 -r--r--r-- gettokens.icn
# 4827 -r--r--r-- Makefile.dist
# 15535 -rw-r--r-- README
# 15504 -rw-r--r-- README.rtv
#
if test -r _shar_seq_.tmp; then
echo 'Must unpack archives in sequence!'
echo Please unpack part `cat _shar_seq_.tmp` next
exit 1
fi
# ============= bibleref.src ==============
if test -f 'bibleref.src' -a X"$1" != X"-c"; then
echo 'x - skipping bibleref.src (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting bibleref.src (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'bibleref.src' &&
X############################################################################
X#
X# Name: bibleref.icn
X#
X# Title: Bible Reference Finder
X#
X# Author: Richard L. Goerwitz
X#
X# Version: 1.18
X#
X############################################################################
X#
X# This program helps the user locate and browse passages from the
X# King James Bible, as distributed in the 19-disk PC-SIG set.
X# Startup syntax is
X#
X# bibleref [-f filename] [-v]
X#
X# where filename is the name of the indexed Bible text you wish to
X# peruse. Because the KJV filename is hard-coded into the program,
X# you need not supply the -f argument. It is available, though,
X# just in case you have indexed another biblical file, and wish to
X# use that instead.
X#
X# If bibleref is called with a -v argument, it prints the version
X# number and patchlevel, then exits.
X#
X# This particular file contains only the basic command loop, some
X# initialization routines, and some basic clearing/prompting/reading
X# utilities. The other integral file is listutil.icn, which contains
X# all of the basic list and passage display routines.
X#
X############################################################################
X#
X# Requires: UNIX, fully updated & installed Icon Program Library
X#
X############################################################################
X#
X# Links: ./ref2bmap.icn ./name2num.icn ./convertb.icn ./complete.icn
X# ./binsrch.icn ./bmp2text.icn ./initfile.icn ./retrieve.icn
X# ./indexutl.icn ./retrops.icn ./whatnext.icn ./iolib.icn
X# ./iscreen.icn ./listutil.icn ./rewrap.icn ./passutil.icn
X# ./srchutil.icn ./readfile (and probably others I've forgotten)
X#
X# Until incorporated into Icon, also link: ./ipause.icn
X#
X# See also: kjv2rtv.icn, makeind.icn, retrieve.icn, iolib.icn
X#
X############################################################################
X
Xglobal kjv_filename, lists
Xrecord lst(l,pos,old_n,s)
X
X
Xprocedure main(a)
X
X local option_table, filename, prompt, intext, first, result
X # global lists
X initial {
X lists := []
X checkout_features()
X option_table := getopts(a, "f:v")
X if \option_table["v"] then abort("Bibleref", _version(), 0)
X kjv_filename := \option_table["f"] | "/usr/local/lib/bibleref/kjv.rtv"
X initialize_screen()
X message("Initializing offset file...")
X initfile(kjv_filename) |
X quit("main","can't locate "||kjv_filename,1)
X }
X
X # Setup initial prompt.
X prompt := "Enter passage, or f to find a word (q to quit): "
X
X # Read user input.
X while intext := snarf_input(prompt) do {
X
X trim(intext,'\t ') ? {
X
X # See if the user has just input a passage reference.
X # If so, then display it...
X if display_passage(intext) then
X result := "yes"
X
X # ...otherwise, see if his/her input matches any of the
X # following commands:
X else {
X first := move(1) | "c"
X case first of {
X "!" : push_shell() & initialize_screen()
X "c" : initialize_screen() # c = clear
X "d" : display_list() # d = display (a list)
X "f" : { # f = find a word
X if search_database() # insert new list into "lists"
X then display_list() # stores it as a record (lst)
X }
X "l" : show_lists() # l = list all lists
X "q" : { # q = quit program
X if pos(0) & "y" == snarf_input("Really quit? (y/n) ")
X then break
X }
X "r" : readfile() & display_list()# r = read file from disk
X default : { # input error
X err_message("Unrecognized passage or command.")
X next
X }
X }
X }
X # If we have any tangible search results, or else have viewed
X # a passage, then alter the prompt to reflect the full range
X # of options.
X \result | *\lists > 0 &
X prompt := "Enter passage, or !/c/d/f/l/q/r: "
X }
X }
X
X # Clear, say goodbye, and exit with zero status.
X initialize_screen()
X message("Thanks for using Bibleref.")
X write(); exit(0)
X
Xend
X
X
Xprocedure initialize_screen()
X
X #
X # Initialize screen
X #
X local msg, short_message
X
X pos(0) | {
X err_message("Garbage characters after \"c\" command.")
X fail
X }
X
X msg := "\"Bibleref\" - a King James Bible browser _
X by Richard Goerwitz"
X short_message := "\"Bibleref,\" by Richard Goerwitz"
X
X clear()
X status_line(msg, short_message, "c") &
X return
X
Xend
X
X
Xprocedure snarf_input(prompt)
X
X #
X # Read user input after displaying a prompt.
X #
X local command
X # global commands
X
X /prompt := "Please input: "
X message(prompt)
X return read()
X
Xend
X
X
Xprocedure err_message(msg)
X
X #
X # Display error message for 1 second; erase.
X #
X /msg := "Error."
X message(msg)
X ipause(700) # until Icon gets a sleep function
X message("")
X return
X
Xend
X
X
Xprocedure status_message(msg)
X
X #
X # Display some status message on the highlighted status line.
X #
X status_line(msg) &
X return
X
Xend
X
X
Xprocedure checkout_features()
X
X #
X # Check to see if we have the necessary terminal & OS features.
X #
X local capname
X
X every capname := ("li","co","ce","so") do {
X getval(capname) | {
X quit("check_features",
X "terminal lacks "||capname||" capability", 2)
X }
X }
X find("UNIX",&features) |
X quit("check_features", "OS unsupported", 1)
X return
X
Xend
X
X
Xprocedure quit(s1, s2, i)
X
X #
X # Move cursor to bottom screen line & abort, sending the message
X # s1: s2 to the user, and exiting with status i.
X #
X iputs(igoto(getval("cm"), 1, getval("li")))
X iputs(getval("ce"))
X abort(s1, s2, i)
X
Xend
X
X
Xprocedure getopts(arg,optstring)
X
X #
X # Get opts. Based on Bob Alexander & Gregg Townsend's IPL
X # options procedure.
X #
X local x,i,c,otab,flist,o,p
X
X /optstring := string(&letters)
X otab := table()
X flist := []
X while x := get(arg) do {
X x ? {
X if ="-" & not pos(0) then {
X if ="-" & pos(0) then break
X while c := move(1) do
X if i := find(c,optstring) + 1 then
X otab[c] :=
X if any(':+.',o := optstring[i]) then {
X p := "" ~== tab(0) | get(arg) |
X quit("getopts", "No parameter following -"||c, 1)
X case o of {
X ":": p
X "+": integer(p) |
X quit("getopts", "-"||c||" needs numeric", 1)
X ".": real(p) |
X quit("getopts", "-"||c||" needs numeric", 1)
X }
X }
X else 1
X else quit("getopts","Unrecognized option: -"||c, 1)
X }
X else put(flist,x)
X }
X }
X while push(arg,pull(flist))
X return otab
X
Xend
SHAR_EOF
true || echo 'restore of bibleref.src failed'
rm -f _shar_wnt_.tmp
fi
# ============= ref2bmap.icn ==============
if test -f 'ref2bmap.icn' -a X"$1" != X"-c"; then
echo 'x - skipping ref2bmap.icn (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting ref2bmap.icn (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ref2bmap.icn' &&
X############################################################################
X#
X# Name: ref2bmap.icn
X#
X# Title: convert English reference to a bitmap
X#
X# Author: Richard L. Goerwitz
X#
X# Version: 1.6
X#
X############################################################################
X#
X# Converts an English reference (e.g. "Ex 4:21" to a bitmap suitable
X# for retrieval via bitmap_2_text(bitmap, filename)). Syntax:
X#
X# ref_2_bitmap(english_ref, filename)
X#
X# fails if the requested conversion can't be performed on account of
X# a misspelling. Aborts if the file whose name is given as arg 2
X# does not have a transparently book:chapter:verse organization (i.e.
X# IS.no must = 3).
X#
X############################################################################
X#
X# Links: complete.icn, ./initfile.icn ./name2num.icn
X#
X############################################################################
X
X# Declared in indexutl.icn.
X# record is(FS, s_len, len, no, is_case_sensitive)
X# global IS
X
X# Declared in initfile.icn.
X# global filestats
X# record Fs(ind_filename,bmp_filename,lim_filename, IS, ofs_table,all_bitmaps)
X
X
Xprocedure ref_2_bitmap(s, filename)
X
X local bitmap, bookname, book_numeric, field, no
X
X # Check for sloppy programming.
X /filename & abort("ref_2_bitmap","you called me without a filename",54)
X
X # If necessary, initialize stats for the current file.
X #
X if /filestats | /filestats[filename]
X then initfile(filename) # see initfile.icn
X IS := filestats[filename].IS
X IS.no ~= 3 & abort("ref_2_bitmap","can't yet handle IS.no ~= 3",51)
X
X # IS.len = the number of bits needed to hold an integer
X # representation of a single field in filename
X # IS.no = number of fields in bitmaps for filename
X # s = English Bible reference (e.g. Gen 8:10)
X # no = number of fields minus one
X
X no := IS.no - 1
X bookname := ""
X bitmap := 0
X
X s ? {
X
X # Find book name, convert it to an integer.
X bookname ||:= tab(any('1234')); tab(many(' '))
X bookname ||:= tab(many(&letters)) | fail
X # Fail if the user gives us just a single letter...
X *bookname > 1 | fail
X # ...otherwise, convert book name into the correct value for
X # for this file, and fit it into a proper-length bit field.
X book_numeric := name2num(bookname) | fail
X bitmap := ior(bitmap, ishift(book_numeric, no * IS.len)) | fail
X
X # Get book and verse fields. Add them, shifted appropriately,
X # to bitmap.
X while tab(upto(&digits)) do {
X no -:= 1
X # If no goes below 0 then we have too many fields for the
X # file named in arg 2.
X no >= 0 | fail
X # If you prefer to abort with an error, uncomment this.
X # no >= 0 | abort("ref_2_bitmap", "impossible reference",52)
X bitmap := ior(bitmap, ishift(tab(many(&digits)), no * IS.len))
X }
X }
X
X # If the current no is not 0, then we have either too
X # many or too few fields. This check can be disabled,
X # to allow for dummy specifications (e.g. Exod, which would
X # imply all of the book of Exodus).
X no = 0 | fail
X
X return bitmap
X
Xend
SHAR_EOF
true || echo 'restore of ref2bmap.icn failed'
rm -f _shar_wnt_.tmp
fi
# ============= name2num.icn ==============
if test -f 'name2num.icn' -a X"$1" != X"-c"; then
echo 'x - skipping name2num.icn (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting name2num.icn (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'name2num.icn' &&
X############################################################################
X#
X# Name: name2num.icn
X#
X# Title: convert English book name to an integer
X#
X# Author: Richard L. Goerwitz
X#
X# Version: 1.3
X#
X############################################################################
X#
X# Used by ref_2_bitmap(), convertr(), etc.
X#
X############################################################################
X
X
Xprocedure name2num(s)
X
X # Map English book names or abbreviations to numeric values.
X
X local n, b_name, tmp_names, i, nameset
X static names, abbrevtbl
X initial {
X
X names := ["genesis", "exodus", "leviticus", "numbers",
X "deuteronomy", "joshua", "judges", "ruth",
X "1samuel", "2samuel", "1kings", "2kings",
X "1chronicles", "2chronicles", "ezra",
X "nehemiah", "esther", "job", "psalms",
X "proverbs", "ecclesiastes", "canticles",
X "isaiah", "jeremiah", "lamentations", "ezekiel",
X "daniel", "hosea", "joel", "amos", "obadiah",
X "jonah", "micah", "nahum", "habakkuk",
X "zephaniah", "haggai", "zechariah", "malachi",
X "matthew", "mark", "luke", "john", "acts",
X "romans", "1corinthians", "2corinthians",
X "galations", "ephesians", "philippians",
X "colossians", "1thessalonians",
X "2thessalonians", "1timothy", "2timothy",
X "titus", "philemon", "hebrews", "james",
X "1peter", "2peter", "1john", "2john", "3john",
X "jude", "revelation", "tobit", "judith", "wisdom",
X "sirach", "baruch", "1maccabees", "2maccabees",
X
X "gen", "exod", "lev", "num", "deut", "josh",
X "judg", "ruth", "1sam", "2sam", "1kgs", "2kgs",
X "1chr", "2chr", "ezra", "neh", "esth", "job",
X "pss", "prov", "qoh", "cant", "isa", "jer",
X "lam", "ezek", "dan", "hos", "joel", "amos",
X "obad", "jonah", "mic", "nahum", "hab", "zeph",
X "hag", "zech", "mal", "mat", "mark", "luke",
X "john", "acts", "rom", "1cor", "2cor", "gal",
X "eph", "phil", "col", "1thess", "2thess",
X "1tim", "2tim", "titus", "phlm", "heb", "jas",
X "1pet", "2pet", "1john", "2john", "3john",
X "jude", "rev", "tob", "jdt", "wis", "sir",
X "bar", "1macc", "2macc",
X
X "dt", "jdg", "jg", "rth", "sa1", "sa2", "ki1",
X "ki2", "ch1", "ch2", "jl", "mt", "mk", "lk",
X "jn", "co1", "co2", "th1", "th2", "ti1", "ti2",
X "phm", "pe1", "pe2", "jo1", "jo2", "jo3", "1jn",
X "2jn", "3jn",
X
X "son", "solomon", "ecclesiasticus", "ecclus"]
X
X abbrevtbl := table()
X tmp_names := copy(names)
X every i := (1 to 73) | (1 to 73) |
X 5|7|7|8|9|10|11|12|13|14|29|40|41|42|43|46|
X 47|52|53|54|55|57|60|61|62|63|64|62|63|64|
X 22|22|70|70
X do {
X insert(abbrevtbl, get(tmp_names), i)
X }
X }
X
X nameset := set()
X every insert(nameset, complete(map(s), names))
X case *nameset of {
X 0 : fail
X 1 : return abbrevtbl[!nameset]
X default : suspend abbrevtbl[!sort(nameset)]
X }
X
Xend
SHAR_EOF
true || echo 'restore of name2num.icn failed'
rm -f _shar_wnt_.tmp
fi
# ============= convertb.icn ==============
if test -f 'convertb.icn' -a X"$1" != X"-c"; then
echo 'x - skipping convertb.icn (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting convertb.icn (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'convertb.icn' &&
X############################################################################
X#
X# Name: convertb.icn
X#
X# Title: convert 3-field book,chap,verse bitmap into a human-
X# readable book chapter:verse reference
X#
X# Author: Richard L. Goerwitz
X#
X# Version: 1.3
X#
X############################################################################
X#
X# Links: complete.icn ./initfile.icn
X#
X############################################################################
X
X# Declared in indexutl.icn.
X# record is(FS, s_len, len, no, is_case_sensitive)
X# global IS
X
X# Declared in initfile.icn.
X# global filestats
X# record Fs(ind_filename,bmp_filename,lim_filename, IS, ofs_table,all_bitmaps)
X
Xprocedure convertb(bitmap, filename)
X
X local no, reference, field_mask
X
X # Check for sloppy programming.
X /filename & abort("convertb","you called me without a filename",70)
X
X # If necessary, initialize stats for the current file.
X #
X if /filestats | /filestats[filename]
X then initfile(filename) # see initfile.icn
X IS := filestats[filename].IS
X IS.no ~= 3 & abort("convertb", "can't yet handle IS.no ~= 3", 71)
X
X # IS.len = the number of bits needed to hold an integer
X # representation of a single field in filename
X # IS.no = number of fields in bitmaps for filename
X
X no := IS.no-1
X field_mask := 2^(IS.len)-1
X
X # No need for mask here; add it just in case.
X reference := Num2Name(
X iand(field_mask, ishift(bitmap, -(no*IS.len))), "kjv.rtv") |
X abort("convertb", "can't convert first field", 52)
X
X no -:= 1
X reference ||:= " " || iand(field_mask, ishift(bitmap, -(no*IS.len)))
X no -:= 1
X reference ||:= ":" || iand(field_mask, ishift(bitmap, -(no*IS.len)))
X
X return reference
X
Xend
X
X
X
Xprocedure Num2Name(i)
X
X # Map English book names or abbreviations to numeric values.
X
X local names, n
X static num_table
X initial {
X names := ["Gen", "Exod", "Lev", "Num", "Deut", "Josh",
X "Judg", "Ruth", "1Sam", "2Sam", "1Kgs", "2Kgs",
X "1Chr", "2Chr", "Ezra", "Neh", "Esth", "Job",
X "Pss", "Prov", "Qoh", "Cant", "Isa", "Jer",
X "Lam", "Ezek", "Dan", "Hos", "Joel", "Amos",
X "Obad", "Jonah", "Mic", "Nahum", "Hab", "Zeph",
X "Hag", "Zech", "Mal", "Mat", "Mark", "Luke",
X "John", "Acts", "Rom", "1Cor", "2Cor", "Gal",
X "Eph", "Phil", "Col", "1Thess", "2Thess",
X "1Tim", "2Tim", "Titus", "Phlm", "Heb", "Jas",
X "1Pet", "2Pet", "1John", "2John", "3John",
X "Jude", "Rev", "Tob", "Jdt", "Wis", "Sir",
X "Bar", "1Macc", "2Macc"]
X num_table := table()
X every n := 1 to 73 do
X insert(num_table, n, get(names))
X }
X
X return num_table[i]
X
Xend
SHAR_EOF
true || echo 'restore of convertb.icn failed'
rm -f _shar_wnt_.tmp
fi
# ============= listutil.icn ==============
if test -f 'listutil.icn' -a X"$1" != X"-c"; then
echo 'x - skipping listutil.icn (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting listutil.icn (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'listutil.icn' &&
X############################################################################
X#
X# Name: 1.20
X#
X# Title: bibleref list display utilities
X#
X# Author: Richard L. Goerwitz
X#
X# Version: listutil.icn
X#
X############################################################################
X#
X# Contains:
X#
X# display_list(), which displays all passages in a given bitmap
X# list by calling listlist(), which converts the bitmaps to
X# human-readable format, and writes them to the screen
X#
X# listlist(), on which see above,
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. l is the list itself, pos is the viewer's
X# last position in the list. old_n is the last passage in the list that
X# was viewed. s is a brief indication of the search string used to gen-
X# erate the list.
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 :=
X listlist(
X lists[subscr],
X "length = "||*lists[subscr].l||"; "||
X "search string = "||lists[subscr].s,
X getval("co")-10
X ) | 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 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-1 & (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 "" : lst_rec.pos := (*l > (lst_rec.pos+1))
X "!" : push_shell()
X "/" : lst_rec.pos := search_list(lst_rec,rsp,lines)
X "?" : lst_rec.pos := search_list(lst_rec,rsp,lines)
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 rsp2 == "" & rsp2 := lst_rec.old_n
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 rsp ? {
X lst_rec.pos :=
X search_list(lst_rec,tab(any('?/')),lines)
X }
X then next
X else {
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 # ...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 "/" : lst_rec.pos := search_list(lst_rec,rsp,lines)
X "?" : lst_rec.pos := search_list(lst_rec,rsp,lines)
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 rsp2 == "" & rsp2 := lst_rec.old_n
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 rsp ? {
X lst_rec.pos :=
X search_list(lst_rec,tab(any('?/')),lines)
X }
X then next
X else {
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 }
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, firstchar
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 fname ? {
X firstchar := move(1) | ""
X case firstchar of {
X "" : fail
X "!" : push_shell() & initialize_screen()
X "q" : pos(0) & 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("Can't write to "|| fname ||".")
X default : quit("write_passage","internal error",80)
X }
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, prompt, rsp, rsp2
X static lines, last_viewed
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 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-1 & (offset+i) ~= (*l+1) then {
X rsp := snarf_input("Press !/b/c/m/v (q = quit viewing): ")
X case map(rsp) of {
X "" : offset := (*l > (offset+1))
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 rsp2 == "" & rsp2 := \last_viewed
X if last_viewed := integer(rsp2) then {
X if 0 < last_viewed <= *l
X then return last_viewed
X else err_message("Out of range.")
X }
X else err_message("Invalid list 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
SHAR_EOF
true || echo 'restore of listutil.icn failed'
fi
echo 'End of part 1'
echo 'File listutil.icn is continued in part 2'
echo 2 > _shar_seq_.tmp
exit 0
exit 0 # Just in case...
--
Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
Sterling Software, IMD UUCP: uunet!sparky!kent
Phone: (402) 291-8300 FAX: (402) 291-4362
Please send comp.sources.misc-related mail to kent@uunet.uu.net.