! translate_nulls.sqr ! ! This is a simple SQR program that reads through the input file ! and copies it to the output file, replacing any ASCII NULL (0) ! characters with the selected replacement character (or just ! stripping the NULL characters from the file). ! ! (This program operates byte-by-byte on the input file, and thus assumes the ! input file is using a single-byte character set.) ! ! ! Usage: sqr translate_nulls / -xl ! ! add "-debugs" to strip the null characters out of the file rather ! than replace them with {REPLACEMENT_CHAR} ! ! ! Written 2007-Sep-19 by Nathan Stratton Treadway. ! #DEFINE REPLACEMENT_CHAR '@' #DEFINE INFILE 1 #DEFINE OUTFILE 2 #DEFINE TRUE 1 begin-report input $infile 'Input file name' input $outfile 'Output file name' let #replacement_char = ascii({REPLACEMENT_CHAR}) open $infile as {INFILE} for-reading record=1:fixed_nolf open $outfile as {OUTFILE} for-writing record=1:fixed_nolf while {TRUE} read {INFILE} into #char:1 if #end-file break end-if #debugt show #char edit 9999 if #char = 0 ! If -debugs is specified, just skip the character completely (i.e. ! don't write anything here). Otherwise, write the replacement character ! instead of the NULL. #ifndef debugs write {OUTFILE} from #replacement_char:1 #endif else write {OUTFILE} from #char:1 end-if end-while close {INFILE} close {OUTFILE} end-report