home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0925.lha / DonsGenies / DonsGenies.lha / Don'sGenies / ASCIIFileProcessor.pprx < prev    next >
Text File  |  1993-05-22  |  5KB  |  136 lines

  1. /*
  2. This genie pre-processes Doc files and other ASCII files. It breaks up long lines of ==== etc., converts double quotes, replaces formfeeds with the Pro Page "next box" code, and deals with PC and Mac line endings. 
  3. Written by Don Cox, April '93. Not Public Domain. All rights reserved.
  4. */
  5.  
  6. trace n
  7.  
  8. if ~show("l", "rexxsupport.library") then
  9.     if ~addlib("rexxsupport.library", 0, -30,0) then
  10.     do
  11.         call ppm_Inform(1,"Please install the rexxsupport.library in your libs: directory before running this Genie.")
  12.     end
  13.  
  14. call SafeEndEdit.rexx()
  15. call ppm_AutoUpdate(0)
  16. address command
  17.  
  18.  
  19. filename = ppm_GetFileName("Open Text File:", "", "")
  20. if filename = '' then call exit_msg("No File Selected")
  21. if ~open("input",filename,"R") then call exit_msg("Could not open input file")
  22. filelength = word(statef(filename),2)
  23. fileblocks = (filelength % 10000)+1
  24. filename2 = filename||".proc"
  25.  
  26. if ~open("output",filename2,"W") then call exit_msg("Could not open output file")
  27.  
  28. blocknumber = 1
  29. do until eof("input")
  30.     text = readch("input",10000)
  31.     call ppm_ShowStatus("  Processing block "blocknumber" of "fileblocks)
  32.     blocknumber = blocknumber +1
  33.     position = 0 /* replace formfeeds with "next box" command */
  34.     do forever
  35.         position = pos("0c"x, text,position+1)
  36.         if position = 0 then break
  37.         text = delstr(text,position,1)
  38.         text = insert("\!",text,position-1)
  39.         end
  40.     position = 0 /* replace CR-LF with LF, for MSDOS files */
  41.     do forever
  42.         position = pos("0d0a"x, text,position+1)
  43.         if position = 0 then break
  44.         text = delstr(text,position,1)
  45.         end
  46.     position = 0 /* now we can replace CR with LF, for Mac files */
  47.     do forever
  48.         position = pos("0d"x, text,position+1)
  49.         if position = 0 then break
  50.         text = delstr(text,position,1)
  51.         text = insert("0a"x,text,position-1)
  52.         end
  53.     position = 0 /* now replace tabs with Mspace-tab, so that runs of tabs can be broken. */
  54.     do forever
  55.         position = pos("09"x, text,position+1)
  56.         if position = 0 then break
  57.         text = delstr(text,position,1)
  58.         text = insert("\127\s",text,position-1)
  59.         end
  60.     position = 0 /* now replace left double quotes after spaces */
  61.     do forever
  62.         position = pos(" "||"22"x, text,position+1)
  63.         if position = 0 then break
  64.         text = delstr(text,position,2)
  65.         text = insert(" "||"b9"x,text,position-1)
  66.         end
  67.     position = 0 /* now replace left double quotes after linefeeds */
  68.     do forever
  69.         position = pos("0a22"x, text,position+1)
  70.         if position = 0 then break
  71.         text = delstr(text,position,2)
  72.         text = insert("0ab9"x,text,position-1)
  73.         end
  74.     position = 0 /* now replace right double quotes */
  75.     do forever
  76.         position = pos("22"x, text,position+1)
  77.         if position = 0 then break
  78.         text = delstr(text,position,1)
  79.         text = insert("b2"x,text,position-1)
  80.         end
  81.     position = 0 /* replace sets of 4 spaces with tabs */
  82.     do forever
  83.         position = pos("    ", text,position+1)
  84.         if position = 0 then break
  85.         text = delstr(text,position,4)
  86.         text = insert("\127\s",text,position-1) /* the \127 allows long strings of tabs to be broken */
  87.         end        
  88.     position = -3 /* break up rows of ===== */
  89.     do forever
  90.         position = pos("====", text,position+4)
  91.         if position = 0 then break
  92.         text = delstr(text,position,4)
  93.         text = insert("== =",text,position-1)
  94.         end        
  95.     position = -3 /* break up rows of ++++ */
  96.     do forever
  97.         position = pos("++++", text,position+4)
  98.         if position = 0 then break
  99.         text = delstr(text,position,4)
  100.         text = insert("++ +",text,position-1)
  101.         end        
  102.     position = -3 /* break up rows of **** */
  103.     do forever
  104.         position = pos("****", text,position+4)
  105.         if position = 0 then break
  106.         text = delstr(text,position,4)
  107.         text = insert("** *",text,position-1)
  108.         end        
  109.     position = -3 /* break up rows of ~~~~ */
  110.     do forever
  111.         position = pos("~~~~", text,position+4)
  112.         if position = 0 then break
  113.         text = delstr(text,position,4)
  114.         text = insert("~~ ~",text,position-1)
  115.         end            
  116.     call writech("output",text)
  117.     end
  118.  
  119.  
  120. call exit_msg("Done")
  121.  
  122.  
  123.  
  124. /*
  125.  *  Exit Msg Procedure
  126.  */
  127. exit_msg: procedure 
  128. do
  129.     parse arg message
  130.     if message ~= '' then call ppm_Inform(1, message,)
  131.     call ppm_AutoUpdate(1)
  132.     call ppm_ClearStatus()
  133.     exit
  134. end
  135.  
  136.