############################################################################ # # Name: ref2bmap.icn # # Title: convert English reference to a bitmap # # Author: Richard L. Goerwitz # # Version: 1.15 # ############################################################################ # # Converts an English reference (e.g. "Ex 4:2" for the Bible; "4:2" # for the Quran) to a bitmap suitable for retrieval via # bitmap_2_text(bitmap, filename). Syntax: # # ref_2_bitmap(english_ref, filename) # # fails if the requested conversion can't be performed on account of # a misspelling. Aborts if the file whose name is given as arg 2 # does not have a transparently [book:]chapter:verse organization # (i.e. IS.no must = 2 or 3). # ############################################################################ # # Links: complete.icn, ./initfile.icn ./name2num.icn # ############################################################################ # Declared in indexutl.icn. # record is(FS, s_len, len, no, is_case_sensitive) # global IS # Declared in initfile.icn. # global filestats # record Fs(ind_filename,bmp_filename,lim_filename, IS, ofs_table,all_bitmaps) procedure ref_2_bitmap(s, filename) local bitmap, bookname, book_numeric, field, no # Check for sloppy programming. /filename & abort("ref_2_bitmap","you called me without a filename",54) # If necessary, initialize stats for the current file. # if /filestats | /filestats[filename] then initfile(filename) # see initfile.icn IS := filestats[filename].IS 1 < IS.no < 4 | abort("ref_2_bitmap","oops; IS.no is not = (2|3)",51) # IS.len = the number of bits needed to hold an integer # representation of a single field in filename # IS.no = number of fields in bitmaps for filename # s = English Bible reference (e.g. Gen 8:10) # no = number of fields minus one no := IS.no bookname := "" bitmap := 0 s ? { if IS.no = 3 then { no -:= 1 # Find book name, convert it to an integer. bookname ||:= tab(any('1234')) | { (="first", "1") | (="second", "2") | (="third", "3") | (="fourth", "4") } tab(many(' ')) bookname ||:= trim(tab(many(&letters ++ ' '))) | fail # Fail if the user gives us just a single letter... *bookname > 1 | fail # ...otherwise, convert book name into the correct value for # for this file, and fit it into a proper-length bit field. book_numeric := name2num(bookname) | fail bitmap := ior(bitmap, ishift(book_numeric, no * IS.len)) | fail } # Get book and verse fields. Add them, shifted appropriately, # to bitmap. while tab(upto(&digits)) do { no -:= 1 # If no goes below 0 then we have too many fields for the # file named in arg 2. no >= 0 | fail # If you prefer to abort with an error, uncomment this. # no >= 0 | abort("ref_2_bitmap", "impossible reference",52) bitmap := ior(bitmap, ishift(tab(many(&digits)), no * IS.len)) } } # If the current no is not 0, then we have either too many or too # few fields. This check can be disabled, to allow for dummy # specifications (e.g. in a biblicat test, Exod would imply all of # the book of Exodus). no = 0 | fail return bitmap end