Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for crlf2lf.rex

(view source code of crlf2lf.rex as plain text)

  1. /* CrLf2Lf,  Version 2.00                 */
  2. /* Convert CR/LF to LF only               */
  3. /* Written by Rob van der Woude           */
  4. /* Original version:  September 9, 1998   */
  5. /* Latest update:     December 30, 2002   */
  6.  
  7. /* Initialize RexxUtil library */
  8. Call RxFuncAdd "sysloadfuncs", "RexxUtil", "sysloadfuncs"
  9. Call sysloadfuncs
  10.  
  11. /* Check and interpret command line parameters */
  12. Parse Upper Arg commandline
  13. Parse Value commandline With source target dummy
  14. If dummy <> "" Then Call ErrorMsg "Too many parameters: "||commandline
  15. If source = "" Then Call ErrorMsg
  16. If target = "" Then Call ErrorMsg "Please specify target"
  17.  
  18. /* Check source and target files */
  19. Call SysFileTree source, "source.", "F"
  20. If source.0 <> 1 Then Call ErrorMsg "Source file "||source||" not found."
  21. Call SysFileTree target, "target.", "F"
  22. If target.0  = 1 Then Call ErrorMsg "Target file "||target||" already exists."
  23.  
  24. /* Read source file as one single string */
  25. Parse Value source.1 With . . size .
  26. filestring = CharIn( source, 1, size )
  27. newstring  = filestring
  28.  
  29. /* Search source file for CR/LF combinations and remove the CR */
  30. start = 1
  31. Do Forever
  32. 	newline = Pos( "0D0A"X, newstring )
  33. 	If newline = 0 Then Leave
  34. 	newstring = SubStr( newstring, 1, ( newline - 1 ) )||,
  35. 	            SubStr( newstring, ( newline + 1 ) )
  36. End
  37.  
  38. /* Write result to target file and close it */
  39. Call CharOut target, newstring
  40. Call LineOut target
  41. Exit 0
  42.  
  43.  
  44. ErrorMsg: Procedure
  45. 	msg = Strip( arg( 1 ) )
  46. 	Call Beep 220, 240
  47. 	Say
  48. 	If msg <> "" Then Say "Error: "||msg||"0D0A"X
  49. 	Say "CRLF2LF,  Version 1.01"
  50. 	Say "Convert CR/LF to LF only"
  51. 	Say
  52. 	Say "Usage:  CRLF2LF  <source_file>  <target_file>"
  53. 	Say
  54. 	Say "Written by Rob van der Woude"
  55. 	Say "http://www.robvanderwoude.com"
  56. 	Exit 1
  57. Return
  58.  

page last uploaded: 2017-04-06, 13:33