home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROCS.LZH / GETKEYS.ICN < prev    next >
Text File  |  1991-09-05  |  2KB  |  75 lines

  1. ############################################################################
  2. #
  3. #    Name:     getkeys.icn
  4. #
  5. #    Title:     get keys for a gettext file
  6. #
  7. #    Author:     Richard L. Goerwitz
  8. #
  9. #    Version: 1.1
  10. #
  11. #    Date:     June 1, 1991
  12. #
  13. ############################################################################
  14. #
  15. #  getkeys(FNAME) generates all keys in FNAME in order of occurrence.
  16. #  See gettext.icn for a description of the requisite file structure
  17. #  for FNAME.
  18. #
  19. ############################################################################
  20. #
  21. #  Links: adjuncts.icn
  22. #
  23. #  Requires: UNIX (may work under MS-DOS; untested there)
  24. #
  25. #  See also gettext.icn
  26. #
  27. ############################################################################
  28.  
  29. link adjuncts
  30.  
  31. # declared in adjuncts.icn
  32. # global _slash, _baselen
  33.  
  34. procedure getkeys(FNAME)
  35.  
  36.     local line, intext, start_unindexed_part
  37.     initial {
  38.     if /_slash then {
  39.         if find("UNIX", &features) then {
  40.         _slash := "/"
  41.         _baselen := 10
  42.         }
  43.         else if find("MS-DOS", &features) then {
  44.         _slash := "\\"
  45.         _baselen := 8
  46.         }
  47.         else stop("getkeys:  OS not supported")
  48.     }
  49.     }
  50.  
  51.     /FNAME & stop("error (getkeys):  null argument")
  52.  
  53.     # Try to open index file (there may not be one).
  54.     if intext := open(Pathname(FNAME) || getidxname(FNAME)) then {
  55.     # If there's an index file, then just suspend all the keys in
  56.     # it (i.e. suspend every line except the first, upto the tab).
  57.     # The first line tells how many bytes in FNAME were indexed.
  58.     # save it, and use it to seek to unindexed portions later on.
  59.     start_unindexed_part := integer(read(intext))
  60.     while line := read(intext) do
  61.         line ? suspend tab(find("\t")) \ 1
  62.     close(intext)
  63.     }
  64.  
  65.     intext := open(FNAME) | stop("getkeys:  ",FNAME," not found")
  66.     seek(intext, \start_unindexed_part | 1)
  67.     while line := read(intext) do
  68.     line ? { suspend (="::", tab(0)) \ 1 }
  69.  
  70.     # Nothing left to suspend, so fail.
  71.     fail
  72.  
  73. end
  74.  
  75.