Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for dblcr2cr.rex

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

  1. /* DouBLe CR/lf 2 CR/lf, Version 2.00                   */
  2. /* Replace double CR/LF pairs with a single CR/LF pair  */
  3. /* Written by Rob van der Woude                         */
  4. /* http://www.robvanderwoude.com                        */
  5.  
  6. /* Initialize RexxUtil */
  7. Call RxFuncAdd "sysloadfuncs", "RexxUtil", "sysloadfuncs"
  8. Call sysloadfuncs
  9.  
  10. /* Command line parsing */
  11. Parse Arg file dummy
  12. If dummy <> "" Then Call Syntax
  13. If file   = "" Then Call Syntax
  14.  
  15. /* Check if specified file exists */
  16. Call SysFileTree file, "file.", "F", , "**---"
  17. If file.0 = 0 Then Call Syntax "File not found: "||file
  18. If file.0 > 1 Then Call Syntax "Wildcards not allowed!"
  19.  
  20. /* Parse target file name and check if it exists */
  21. Parse Value FileSpec( "N", file ) With target".".
  22. target = target||".bak"
  23. Call SysFileTree target, "target.", "F", , "**---"
  24. If target.0 > 0 Then Call Syntax "Target file already exists!"
  25.  
  26. /* Read the specified file and store it in a single variable */
  27. Parse Value file.1 With . . size . file
  28. file    = Strip( file )
  29. filestr = CharIn( file, 1, size )
  30. Call LineOut file
  31.  
  32. /* Replace all substrings "0D0A"X (CR/LF/CR/LF) with "0D0A"X (CR/LF) */
  33. dblpos = 0
  34. Do Forever
  35. 	start = dblpos + 2
  36. 	dblpos = Pos( "0D0A0D0A"X, filestr, start )
  37. 	If dblpos = 0 Then Leave
  38. 	filestr = SubStr( filestr, 1, dblpos - 1 )||,
  39. 	          SubStr( filestr, dblpos + 2 )
  40. end
  41.  
  42. /* Write the result to target file and close the file */
  43. Call CharOut target, filestr
  44. Call LineOut target
  45.  
  46. /* Normal program end */
  47. Exit 0
  48.  
  49.  
  50. Syntax:
  51. 	msg = arg( 1 )
  52. 	If msg <> "" Then Do
  53. 		msg = msg||"0D0A"X
  54. 		say msg
  55. 	End
  56. 	Say
  57. 	Say "DblCR2CR,  Version 2.00"
  58. 	Say "Replaces double CR/LF pairs with a single CR/LF pair"
  59. 	Say
  60. 	Say "Usage:   DBLCR2CR  <filename>"
  61. 	Say
  62. 	Say 'Result:  File with name of target and extension ".BAK"'
  63. 	Say
  64. 	Say "Written by Rob van der Woude"
  65. 	Say "http://www.robvanderwoude.com"
  66. 	Exit 1
  67. Return
  68.  

page last modified: 2024-02-26; loaded in 0.0260 seconds