(view source code of dblcr2cr.rex as plain text)
/* DouBLe CR/lf 2 CR/lf, Version 2.00 */
/* Replace double CR/LF pairs with a single CR/LF pair */
/* Written by Rob van der Woude */
/* http://www.robvanderwoude.com */
/* Initialize RexxUtil */
Call RxFuncAdd "sysloadfuncs", "RexxUtil", "sysloadfuncs"
Call sysloadfuncs
/* Command line parsing */
Parse Arg file dummy
If dummy <> "" Then Call Syntax
If file = "" Then Call Syntax
/* Check if specified file exists */
Call SysFileTree file, "file.", "F", , "**---"
If file.0 = 0 Then Call Syntax "File not found: "||file
If file.0 > 1 Then Call Syntax "Wildcards not allowed!"
/* Parse target file name and check if it exists */
Parse Value FileSpec( "N", file ) With target".".
target = target||".bak"
Call SysFileTree target, "target.", "F", , "**---"
If target.0 > 0 Then Call Syntax "Target file already exists!"
/* Read the specified file and store it in a single variable */
Parse Value file.1 With . . size . file
file = Strip( file )
filestr = CharIn( file, 1, size )
Call LineOut file
/* Replace all substrings "0D0A"X (CR/LF/CR/LF) with "0D0A"X (CR/LF) */
dblpos = 0
Do Forever
start = dblpos + 2
dblpos = Pos( "0D0A0D0A"X, filestr, start )
If dblpos = 0 Then Leave
filestr = SubStr( filestr, 1, dblpos - 1 )||,
SubStr( filestr, dblpos + 2 )
end
/* Write the result to target file and close the file */
Call CharOut target, filestr
Call LineOut target
/* Normal program end */
Exit 0
Syntax:
msg = arg( 1 )
If msg <> "" Then Do
msg = msg||"0D0A"X
say msg
End
Say
Say "DblCR2CR, Version 2.00"
Say "Replaces double CR/LF pairs with a single CR/LF pair"
Say
Say "Usage: DBLCR2CR <filename>"
Say
Say 'Result: File with name of target and extension ".BAK"'
Say
Say "Written by Rob van der Woude"
Say "http://www.robvanderwoude.com"
Exit 1
Return
page last modified: 2024-04-16; loaded in 0.0082 seconds