Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 69 lines (58 sloc) 1.928 kb
176e6d0 Add install of examples for Windows.
steve authored
1 /*
52fbb3f @caryr Fix memory leak, unneeded argument.
caryr authored
2 * Copyright (c) 2001-2009 Stephen Williams (steve@icarus.com)
176e6d0 Add install of examples for Windows.
steve authored
3 *
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 */
19
20 /*
21 * This is a simple program to make a dosified copy of the
22 * original. That is, it converts unix style line ends to DOS
23 * style. This is useful for installing text files.
24 *
25 * The exact substitution is to replace \n with \r\n. If the line
26 * already ends with \r\n then it is not changed to \r\r\n.
27 */
28
29 # include <stdio.h>
30
31 int main(int argc, char*argv[])
32 {
33 FILE*ifile;
34 FILE*ofile;
35 int ch, pr;
36
37 if (argc != 3) {
38 fprintf(stderr, "Usage: %s <input> <output>\n", argv[0]);
39 return 1;
40 }
41
42 ifile = fopen(argv[1], "rb");
43 if (ifile == 0) {
44 fprintf(stderr, "Unable to open %s for input.\n", argv[1]);
45 return 2;
46 }
47
48 ofile = fopen(argv[2], "wb");
49 if (ofile == 0) {
50 fprintf(stderr, "Unable to open %s for output.\n", argv[2]);
52fbb3f @caryr Fix memory leak, unneeded argument.
caryr authored
51 fclose(ifile);
176e6d0 Add install of examples for Windows.
steve authored
52 return 2;
53 }
54
55 pr = 0;
56 while ((ch = fgetc(ifile)) != EOF) {
57
58 if ((ch == '\n') && (pr != '\r'))
59 fputc('\r', ofile);
60
61 fputc(ch, ofile);
62 pr = ch;
63 }
64
52fbb3f @caryr Fix memory leak, unneeded argument.
caryr authored
65 fclose(ifile);
66 fclose(ofile);
176e6d0 Add install of examples for Windows.
steve authored
67 return 0;
68 }
Something went wrong with that request. Please try again.