home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2296 / readtbl.icn < prev    next >
Encoding:
Text File  |  1990-12-28  |  1.9 KB  |  79 lines

  1. ############################################################################
  2. #
  3. #    Name:     readtbl.icn
  4. #
  5. #    Title:     Read user-created stripsgml table
  6. #
  7. #    Author:     Richard L. Goerwitz
  8. #
  9. #    Version: 1.1
  10. #
  11. ############################################################################
  12. #  
  13. #  This file is part of the stripsgml package.  It does the job of read-
  14. #  ing option user-created mapping information from a file.  The purpose
  15. #  of this file is to specify how each code in a given input text should
  16. #  be translated.  Each line has the form:
  17. #
  18. #      SGML-designator    start_code    end_code
  19. #
  20. #  where the SGML designator is something like "quote" (without the quota-
  21. #  tion marks), and the start and end codes are the way in which you want
  22. #  the beginning and end of a <quote>...<\quote> sequence to be transla-
  23. #  ted.  Presumably, in this instance, your codes would indicate some set
  24. #  level of indentation, and perhaps a font change.  If you don't have an
  25. #  end code for a particular SGML designator, just leave it blank.
  26. #
  27. ############################################################################
  28. #
  29. #  Links: stripsgml.icn
  30. #
  31. ############################################################################
  32.  
  33.  
  34. procedure readtbl(f)
  35.  
  36.     local t, line, k, on_sequence, off_sequence
  37.  
  38.     /f & stop("readtbl:  Arg must be a valid open file.")
  39.  
  40.     t := table()
  41.  
  42.     every line := trim(!f,'\t ') do {
  43.     line ? {
  44.         k := tabslashupto('\t:') &
  45.         tab(many('\t:')) &
  46.         on_sequence := tabslashupto('\t:') | tab(0)
  47.         tab(many('\t:'))
  48.         off_sequence := tab(0)
  49.     } | stop("readtbl:  Bad map file format.")
  50.     insert(t, k, outstr(on_sequence, off_sequence))
  51.     }
  52.  
  53.     return t
  54.  
  55. end
  56.  
  57.  
  58.  
  59. procedure tabslashupto(c,s)
  60.  
  61.     POS := &pos
  62.  
  63.     while tab(upto('\\' ++ c)) do {
  64.     if ="\\" then {
  65.         move(1)
  66.         next
  67.     }
  68.     else {
  69.         if any(c) then {
  70.         suspend &subject[POS:.&pos]
  71.         }
  72.     }
  73.     }
  74.  
  75.     &pos := POS
  76.     fail
  77.  
  78. end
  79.