home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / findtext.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  86 lines

  1. ############################################################################
  2. #
  3. #    File:     findtext.icn
  4. #
  5. #    Subject:  Program to retrieve data from files indexed by idxtext
  6. #
  7. #    Author:   Phillip Lee Thomas
  8. #
  9. #    Date:     November 21, 1996
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  History:  Tested with DOS, DOS-386, OS/2, ProIcon, UNIX
  18. #
  19. ############################################################################
  20. #
  21. #  Version:  1.2 (August 5, 1995)
  22. #
  23. ############################################################################
  24. #
  25. #  See documentation with idxtext.icn, gettext.icn, adjuncts.icn
  26. #
  27. # History:
  28. #   (1.1) Tested with DOS, DOS-386, OS/2, ProIcon, UNIX
  29. #   (1.2) Use preprocessor include statement instead of link.
  30. #
  31. ############################################################################
  32. #
  33. #  Links:  gettext
  34. #
  35. #  Program findtext retrieves multiline text from database indexed by
  36. #     idxtext. Each stretch of text follows a line declaring the index
  37. #     terms:
  38. #
  39. #  ::be ::to ::by ::retrieved
  40. #  Text to be retrieved
  41. #  by findtext.
  42. #  ::index ::line
  43. #  Each index line begins with "::".
  44. #
  45. ############################################################################
  46.  
  47. link gettext
  48.  
  49. procedure main(args)
  50.  
  51.    local count, file, out_line, s
  52.   
  53.    Set_OS()
  54.  
  55.    s    := \args[1] | ""
  56.    file := \args[2] | ""
  57.  
  58.    if *args ~= 2 then {
  59.       while *s = 0 do {                # force entry of search string
  60.          writes("Search string: ")
  61.          s := read()
  62.          }
  63.  
  64.       while *file = 0 do {             # force entry of datafile name
  65.          writes("Search file:   ")
  66.          file := read()
  67.          }
  68.       }
  69.  
  70.    # Find text associated with index s in file 'file'.
  71.  
  72.    count := 0
  73.    every out_line := gettext(s, file) do {
  74.       count +:= 1
  75.       write(count, ": ", out_line)
  76.       }
  77.  
  78.    if count = 0 then {
  79.       write("String '", s, "' not found in indexed file '", file, "'")
  80.       write("Format: [iconx] findtext string filename")
  81.       exit(1)
  82.       }
  83.  
  84.    exit(0)
  85. end
  86.