Merge branch 'master' into verilog-ams
[sverilog.git] / dosify.c
blob7a3245bde35037c6bfa962515a51f4e5a2a78414
1 /*
2 * Copyright (c) 2001 Stephen Williams (steve@icarus.com)
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.
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.
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
19 #ifdef HAVE_CVS_IDENT
20 #ident "$Id: dosify.c,v 1.5 2003/07/15 16:17:47 steve Exp $"
21 #endif
24 * This is a simple program to make a dosified copy of the
25 * original. That is, it converts unix style line ends to DOS
26 * style. This is useful for installing text files.
28 * The exact substitution is to replace \n with \r\n. If the line
29 * already ends with \r\n then it is not changed to \r\r\n.
32 # include <stdio.h>
34 int main(int argc, char*argv[])
36 FILE*ifile;
37 FILE*ofile;
38 int ch, pr;
40 if (argc != 3) {
41 fprintf(stderr, "Usage: %s <input> <output>\n", argv[0]);
42 return 1;
45 ifile = fopen(argv[1], "rb");
46 if (ifile == 0) {
47 fprintf(stderr, "Unable to open %s for input.\n", argv[1]);
48 return 2;
51 ofile = fopen(argv[2], "wb");
52 if (ofile == 0) {
53 fprintf(stderr, "Unable to open %s for output.\n", argv[2]);
54 return 2;
57 pr = 0;
58 while ((ch = fgetc(ifile)) != EOF) {
60 if ((ch == '\n') && (pr != '\r'))
61 fputc('\r', ofile);
63 fputc(ch, ofile);
64 pr = ch;
67 return 0;
71 * $Log: dosify.c,v $
72 * Revision 1.5 2003/07/15 16:17:47 steve
73 * Fix spelling of ifdef.
75 * Revision 1.4 2003/07/15 03:49:22 steve
76 * Spelling fixes.
78 * Revision 1.3 2002/08/12 01:34:58 steve
79 * conditional ident string using autoconfig.
81 * Revision 1.2 2002/08/11 23:47:04 steve
82 * Add missing Log and Ident strings.
84 * Revision 1.1 2001/08/03 17:06:47 steve
85 * Add install of examples for Windows.