home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3577 / ref2bmap.icn < prev   
Encoding:
Text File  |  1991-07-03  |  3.0 KB  |  96 lines

  1. ############################################################################
  2. #
  3. #    Name:     ref2bmap.icn
  4. #
  5. #    Title:     convert English reference to a bitmap
  6. #
  7. #    Author:     Richard L. Goerwitz
  8. #
  9. #    Version: 1.6
  10. #
  11. ############################################################################
  12. #
  13. #  Converts an English reference (e.g. "Ex 4:21" to a bitmap suitable
  14. #  for retrieval via bitmap_2_text(bitmap, filename)).  Syntax:
  15. #
  16. #      ref_2_bitmap(english_ref, filename)
  17. #
  18. #  fails if the requested conversion can't be performed on account of
  19. #  a misspelling.  Aborts if the file whose name is given as arg 2
  20. #  does not have a transparently book:chapter:verse organization (i.e.
  21. #  IS.no must = 3).
  22. #
  23. ############################################################################
  24. #
  25. #  Links: complete.icn, ./initfile.icn ./name2num.icn
  26. #
  27. ############################################################################
  28.  
  29. # Declared in indexutl.icn.
  30. # record is(FS, s_len, len, no, is_case_sensitive)
  31. # global IS
  32.  
  33. # Declared in initfile.icn.
  34. # global filestats
  35. # record Fs(ind_filename, bmp_filename, lim_filename, IS, ofs_table)
  36.  
  37.  
  38. procedure ref_2_bitmap(s, filename)
  39.  
  40.     local bitmap, bookname, book_numeric, field, no
  41.  
  42.     # Check for sloppy programming.
  43.     /filename & abort("ref_2_bitmap","you called me without a filename",54)
  44.  
  45.     # If necessary, initialize stats for the current file.
  46.     #
  47.     if /filestats | /filestats[filename]
  48.     then initfile(filename)           # see initfile.icn
  49.     IS := filestats[filename].IS
  50.     IS.no ~= 3 & abort("ref_2_bitmap","can't yet handle IS.no ~= 3",51)
  51.  
  52.     # IS.len   = the number of bits needed to hold an integer
  53.     #            representation of a single field in filename
  54.     # IS.no    = number of fields in bitmaps for filename
  55.     # s        = English Bible reference (e.g. Gen 8:10)
  56.     # no       = number of fields minus one
  57.  
  58.     no       := IS.no - 1
  59.     bookname := ""
  60.     bitmap   := 0
  61.  
  62.     s ? {
  63.  
  64.     # Find book name, convert it to an integer.
  65.     bookname ||:= tab(any('1234'));    tab(many(' '))
  66.     bookname ||:= tab(many(&letters)) | fail
  67.     # Fail if the user gives us just a single letter...
  68.     *bookname > 1 | fail
  69.     # ...otherwise, convert book name into the correct value for
  70.     # for this file, and fit it into a proper-length bit field.
  71.     book_numeric :=  name2num(bookname) | fail
  72.     bitmap := ior(bitmap, ishift(book_numeric, no * IS.len)) | fail
  73.     
  74.     # Get book and verse fields.  Add them, shifted appropriately,
  75.     # to bitmap.
  76.     while tab(upto(&digits)) do {
  77.         no -:= 1
  78.         # If no goes below 0 then we have too many fields for the
  79.         # file named in arg 2.
  80.         no >= 0 | fail
  81.         # If you prefer to abort with an error, uncomment this.
  82.         # no >= 0 | abort("ref_2_bitmap", "impossible reference",52)
  83.         bitmap := ior(bitmap, ishift(tab(many(&digits)), no * IS.len))
  84.     }
  85.     }
  86.  
  87.     # If the current no is not 0, then we have either too
  88.     # many or too few fields.  This check can be disabled,
  89.     # to allow for dummy specifications (e.g. Exod, which would
  90.     # imply all of the book of Exodus).
  91.     no = 0 | fail
  92.  
  93.     return bitmap
  94.  
  95. end
  96.