home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Mops 2.7 / Mops source / More classes / MW documents / WordBatch < prev   
Encoding:
Text File  |  1991-12-05  |  1.9 KB  |  87 lines  |  [TEXT/MSET]

  1. \ WordBatch - read text from a batch of Microsoft Word documents.
  2. \ Revised May 87 for compatibility with Neon 2.0 and new MW docs code.
  3.  
  4. need    MWdocs
  5.  
  6.     int    VOL#
  7.     file+    WDFILE
  8.     string+    FNAMES
  9.  
  10. forward MYST        \ Executed when MYSTERY? is set true.  The appl can't
  11.             \ check properly because it doesn't know when we
  12.             \ switch to a new input file.
  13.  
  14. :f MYST  ;f        \ Default: do nothing
  15.  
  16. :class  WORDBATCH  super( object )
  17.  
  18. \    int    VOL#
  19.  
  20. :m NEXT?:    \ ( -- f )
  21.     nextline?: fnames  drop  len: fnames  0>
  22.     dup ( save in stk for return )
  23.     IF
  24.         clear: wdfile  get: fnames  name: wdfile
  25.         get: vol#  setVRef: wdfile
  26.         open: wdfile  OK?  print: wdfile  cr
  27.         wdfile  bring: theDoc
  28.         close: wdfile  drop
  29.         true  fixup: theDoc  drop
  30.         mystery?  IF  myst  THEN
  31.         begin: text
  32.     THEN  ;m
  33.  
  34. :m OPEN:    \ ( -- f )
  35.     true -> text_only?
  36.     pushnew: loadfile
  37.     'type TEXT 1 stdget: topfile
  38.     NIF  drop: loadfile  false  EXIT  THEN
  39.     cls  open: topfile  OK?
  40.     topfile  $ 16 +  w@  put: vol#
  41.     new: fnames
  42.     new: text  new: fmt_run  new: para_run  new: style_names
  43.     readtop: fnames  0 >lim: fnames
  44.     next?: self  ;m
  45.  
  46. :m CLOSE:
  47.     close: wdfile drop  release: fnames
  48.     release: text  release: fmt_run  release: para_run
  49.     release: style_names  ;m
  50.  
  51.  
  52. \ GETLINE: is designed to work in the same way as in class File+,
  53. \ so that the caller doesn't have to worry about whether his input is coming
  54. \ from a single file or a batch of files.
  55. \ It reads the next line into the given string and returns TRUE, or, if end
  56. \ file has been reached, sets the length of the string to zero and returns
  57. \ FALSE.
  58.  
  59. :m GETLINE?:  { str -- b }
  60.     nextline?: text  ?dup
  61.     NIF   next?: self  line>: text   THEN
  62.     text ->: str  ;m
  63.  
  64. :m GETALL:  { str -- }
  65.     clear: str
  66.     BEGIN
  67.         reset: text  text addstr: str
  68.         next?: self
  69.     NUNTIL
  70.     reset: str  close: self  ;m
  71.  
  72. ;class
  73.  
  74. wordbatch  BATCH
  75.  
  76. EndLoad
  77.  
  78. \ testing
  79.  
  80. \ string+ S
  81. \ : TEST
  82. \    new: s  open: batch  0EXIT
  83. \    ( s getall: batch )   ;
  84.  
  85. \ : ZZ
  86. \    release: s  release: text   ;
  87.