3 ###############################################################################
6 # Author : Chris Koeritz #
7 # Rights : Copyright (C) 1996-$now by Author #
11 # Turns Unix format text files into DOS format text files. #
13 ###############################################################################
14 # This program is free software; you can redistribute it and/or modify it #
15 # under the terms of the GNU General Public License as published by the Free #
16 # Software Foundation; either version 2 of the License, or (at your option) #
17 # any later version. See: "http://www.gruntose.com/Info/GNU/GPL.html" for a #
18 # version of the License. Please send any updates to "fred@gruntose.com". #
19 ###############################################################################
21 require "filename_helper.pl";
25 $new_version = `mktemp "$TMP/zz_add_cr_tmp.XXXXXX"`;
28 foreach $filename (&glob_list(@ARGV)) {
29 # go through each file on the command line.
31 open(IN_FILE, "<$filename");
33 # open our temporary file for appending.
34 open(NEW_FILE, ">$new_version");
37 local($changed_file) = 0; # records whether the file was modified.
39 # go through each line in the current file...
40 while ($to_add_cr = <IN_FILE>) {
42 for ($i = 0; $i < length($to_add_cr); $i++) {
43 $curr_char = substr($to_add_cr, $i, 1);
44 if ($curr_char =~ /[\r\n]/) {
45 if ($curr_char =~ /\n/) {
46 # if LF comes first, we are fixing a unix style file.
51 $new_line .= $curr_char;
55 # add on dos EOL, a carriage return and a line feed.
58 print NEW_FILE "$new_line"; # write out the current line.
65 print "filename is $filename\n";
66 open(NEW, "<$new_version");
67 open(CURR, ">$filename");
68 while (<NEW>) { print CURR; }
73 # clean up our temporaries.
74 unlink("$new_version");