3 # converts from Unix (LF only) text files to
4 # DOS (CRLF) text files
6 # works on both unix and dos
7 # if used on unix change COPY and DEL in BEGIN section
9 # mawk -f add_cr.awk [files]
11 # with no files reads stdin writes stdout
12 # otherwise the original is overwritten
14 # If a file of the form `@file', then arguments are read from
15 # `file', one per line
18 # To add cr's to the whole distribution
20 # mawk -f doslist.awk packing.lis | mawk "{print $2}" > list
21 # mawk -f add_cr.awk @list
25 # read arguments for @file into ARGV[]
26 function reset_argv(T, i, j, flag, file) #all args local
28 for( i = 1 ; i < ARGC ; i++ )
31 if ( T[i] ~ /^@/ ) flag = 1
36 # need to read from a @file into ARGV
38 for( i = 1 ; i < ARGC ; i++ )
40 if ( T[i] !~ /^@/ ) ARGV[j++] = T[i]
44 # read arguments from T[i]
45 while ( (getline file < T[i]) > 0 ) ARGV[j++] = file
53 COPY = "copy" # unix: "cp"
54 DEL = "del" # unix: "rm"
56 tmpfile = ENVIRON["MAWKTMPDIR"] "MAWK.TMP"
63 # just write to stdout
68 FILENAME != filename {
73 syscmd = sprintf( "%s %s %s", COPY, tmpfile, filename )
80 { printf "%s\r\n" , $0 > tmpfile }
87 syscmd = sprintf( "%s %s %s", COPY, tmpfile, filename )
89 system(DEL " " tmpfile)