replace_cr {
; Replace all stray occurrences of CR with spaces in the file (doesn't affect CRLFs)
var %file = $qt($1-)
bread %file 0 $file(%file) &cr
var %i = 1, %pos
while $bfind(&cr, %i, 13) {
%pos = $v1
%i = %pos + 1
; Ignore if it's part of a CRLF
if ($bvar(&cr, %i) != 10) bset &cr %pos 32
}
bwrite %file 0 -1 &cr
}
strip_cr {
; Remove all stray occurrences of CR from the file (doesn't affect CRLFs)
var %file = $qt($1-)
bread %file 0 $file(%file) &cr
var %i = 1, %pos
while $bfind(&cr, %i, 13) {
%pos = $v1
%i = %pos + 1
; Ignore if it's part of a CRLF
if ($bvar(&cr, %i) != 10) {
bcopy -c &cr %pos &cr %i -1
%i = %pos
}
}
write -c %file
bwrite %file 0 -1 &cr
}