b2dcfd9c21d71419904930dffd738c5940fb0fbb
[oweals/busybox.git] / coreutils / dos2unix.c
1 /*
2  * dos2unix for BusyBox
3  *
4  * dos2unix '\n' convertor 0.5.0
5  *   based on Unix2Dos 0.9.0 by Peter Hanecak (made 19.2.1997)
6  * Copyright 1997,.. by Peter Hanecak <hanecak@megaloman.sk>.
7  * All rights reserved.
8  *
9  * dos2unix filters reading input from stdin and writing output to stdout.
10  * Without arguments it reverts the format (e.i. if source is in UNIX format,
11  * output is in DOS format and vice versa).
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  *
27  * See the COPYING file for license information.
28  */
29
30 #include <getopt.h>
31 #include "busybox.h"
32
33 int dos2unix_main(int argc, char *argv[]) {
34         int ConvType = CT_AUTO;
35         int o;
36
37         // process parameters
38         while ((o = getopt(argc, argv, "du")) != EOF) {
39                 switch (o) {
40                 case 'd':
41                         ConvType = CT_UNIX2DOS;
42                         break;
43                 case 'u':
44                         ConvType = CT_DOS2UNIX;
45                         break;
46                 default:
47                         show_usage();
48                 }
49         }
50
51         if (optind < argc) {
52                 while(optind < argc)
53                         if ((o = convert(argv[optind++], ConvType)) < 0)
54                                 break;
55         }
56         else
57                 o = convert(NULL, ConvType);
58
59         return o;
60 }
61