home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d952 / machv.lha / MachV / GuideToText.rexx < prev    next >
OS/2 REXX Batch file  |  1993-12-31  |  2KB  |  96 lines

  1. /* This ARexx program strips a filenamme.guide file of @Node, @EndNode
  2.  * @Next, @Prev and @Toc tokens. It also takes a line in the form
  3.  *
  4.  *   @{"gadget text" Link GadgetInfo}
  5.  *
  6.  * and changes it to:
  7.  *
  8.  *   gadget text.
  9.  *
  10.  * A formfeed is inserted every 60 lines. This can be changed on the command
  11.  * line.
  12.  *
  13.  * This program is REAL slow, but you can modify it easily to do more or 
  14.  * less.
  15.  *
  16.  *
  17.  * Usage is: GuideToText file.guide
  18.  *
  19.  * The resulting file will be named file.guide.txt.
  20.  *
  21. */
  22.  
  23.  
  24. parse arg filename lines_per_page
  25. signal on ioerr
  26.  
  27.  
  28.   if filename = '?' then do
  29.     Say 'Usage: GuideToText file.guide [lines per page]'
  30.     Return 0
  31.   end
  32.  
  33.   outfile = filename || '.txt'
  34.  
  35.   if (lines_per_page == "") then
  36.     lines_per_page = 60
  37.  
  38.   if Open(if,filename,'R') then do
  39.     if Open(of,outfile,'W') then do
  40.       Call stripit()
  41.       Call Close(of)
  42.     end; else
  43.       Say 'Cannot open ' outfile .
  44.     Call Close(if)
  45.   end; else
  46.     Say 'Cannot open ' || filename .
  47.   Return 0
  48.  
  49. stripit:
  50.  
  51.   say "processing...   (be patient, this is ARexx!)"
  52.   say "Press Ctrl-C to Abort!"
  53.  
  54.   linecnt = 0
  55.   page_num = 1
  56.   /*lf = bitclr('4c'x,6)  */
  57.   lf = '0c'x
  58.   do until eof(if)
  59.     l = ReadLN(if)
  60.     p = Pos('@',l)                /* amigaguide token? */
  61.     skip_line = 0
  62.     if p ~= 0 then do
  63.       p = Pos('@{"',l)            /* gadget? */
  64.       if p ~= 0 then do
  65.         l=DelStr(l,p,3)           /* delete @{" */
  66.         p1 = Pos('" Link',l)      /* find Link keyword */
  67.         if p1 ~= 0 then do
  68.           p2 = Pos('}',l,p1)      /* find position of } */
  69.           if p2 ~= 0 then do
  70.             l = DelStr(l,p1,(p2-p1)+1)  /* delete Link function} */
  71.           end
  72.         end
  73.       end; else do
  74.         p = Pos('@Node',l) | Pos('@EndNode',l) | Pos('@Next',l) | Pos('@Prev',l) | Pos('@Toc',l)
  75.         if p ~= 0 then
  76.           skip_line = 1     /* don't write this line */
  77.       end
  78.     end
  79.     if ~skip_line then do
  80.       Call WriteLN(of,l)
  81.       linecnt = linecnt + 1
  82.       if (linecnt > lines_per_page) then do
  83.         Call WriteLN(of,lf)
  84.         linecnt = 0;
  85.         say Page page_num
  86.         page_num = page_num + 1
  87.       end
  88.     end
  89.   end
  90.  
  91.   Return 0
  92.  
  93. ioerr:
  94.  
  95.   say IO Error
  96.   exit