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

  1. ############################################################################
  2. #
  3. #    Name:     convertb.icn
  4. #
  5. #    Title:     convert 3-field book,chap,verse bitmap into a human-
  6. #                readable book chapter:verse reference
  7. #
  8. #    Author:     Richard L. Goerwitz
  9. #
  10. #    Version: 1.2
  11. #
  12. ############################################################################
  13. #
  14. #  Links: complete.icn ./initfile.icn
  15. #
  16. ############################################################################
  17.  
  18. # Declared in indexutl.icn.
  19. # record is(FS, s_len, len, no, is_case_sensitive)
  20. # global IS
  21.  
  22. # Declared in initfile.icn.
  23. # global filestats
  24. # record Fs(ind_filename, bmp_filename, lim_filename, IS, ofs_table)
  25.  
  26. procedure convertb(bitmap, filename)
  27.  
  28.     local no, reference, field_mask
  29.  
  30.     # Check for sloppy programming.
  31.     /filename & abort("convertb","you called me without a filename",70)
  32.  
  33.     # If necessary, initialize stats for the current file.
  34.     #
  35.     if /filestats | /filestats[filename]
  36.     then initfile(filename)           # see initfile.icn
  37.     IS := filestats[filename].IS
  38.     IS.no ~= 3 & abort("convertb", "can't yet handle IS.no ~= 3", 71)
  39.  
  40.     # IS.len   = the number of bits needed to hold an integer
  41.     #            representation of a single field in filename
  42.     # IS.no    = number of fields in bitmaps for filename
  43.  
  44.     no := IS.no-1
  45.     field_mask := 2^(IS.len)-1
  46.  
  47.     # No need for mask here; add it just in case.
  48.     reference  := Num2Name(
  49.     iand(field_mask, ishift(bitmap, -(no*IS.len))), "kjv.rtv") |
  50.     abort("convertb", "can't convert first field", 52)
  51.  
  52.     no -:= 1
  53.     reference ||:= " " || iand(field_mask, ishift(bitmap, -(no*IS.len)))
  54.     no -:= 1
  55.     reference ||:= ":" || iand(field_mask, ishift(bitmap, -(no*IS.len)))
  56.  
  57.     return reference
  58.  
  59. end
  60.  
  61.  
  62.  
  63. procedure Num2Name(i)
  64.  
  65.     # Map English book names or abbreviations to numeric values.
  66.  
  67.     local names, n
  68.     static num_table
  69.     initial {
  70.     names     := ["Gen", "Exod", "Lev", "Num", "Deut", "Josh",
  71.               "Judg", "Ruth", "1Sam", "2Sam", "1Kgs", "2Kgs",
  72.               "1Chr", "2Chr", "Ezra", "Neh", "Esth", "Job",
  73.               "Pss", "Prov", "Qoh", "Cant", "Isa", "Jer",
  74.               "Lam", "Ezek", "Dan", "Hos", "Joel", "Amos",
  75.               "Obad", "Jonah", "Mic", "Nahum", "Hab", "Zeph",
  76.               "Hag", "Zech", "Mal", "Mat", "Mark", "Luke",
  77.               "John", "Acts", "Rom", "1Cor", "2Cor", "Gal",
  78.               "Eph", "Phil", "Col", "1Thess", "2Thess",
  79.               "1Tim", "2Tim", "Titus", "Phlm", "Heb", "Jas",
  80.               "1Pet", "2Pet", "1John", "2John", "3John",
  81.               "Jude", "Rev", "Tob", "Jdt", "Wis", "Sir",
  82.               "Bar", "1Macc", "2Macc"]
  83.         num_table :=  table()
  84.     every n := 1 to 73 do
  85.         insert(num_table, n, get(names))
  86.     }
  87.  
  88.     return num_table[i]
  89.  
  90. end
  91.