Debian Codegraph @

contrib/toacme/src/main.c

raw symbols SCIP
1 // ToACME - converts other source codes to ACME format.
2 // Copyright (C) 1999-2015 Marco Baye
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21
22 #include "config.h"
23 #include "acme.h"
24 #include "io.h"
25 #include "platform.h"
26 #include "version.h"
27
28
29 // guess what
30 int main(int argc, char *argv[])
31 {
32 // handle "toacme -h" and "toacme --help" just like "toacme"
33 if (argc == 2) {
34 if ((strcmp(argv[1], "-h") == 0)
35 || (strcmp(argv[1], "--help") == 0))
36 argc = 1;
37 }
38 // "toacme" without any switches gives info and exits successfully
39 if (argc == 1) {
40 version_show_info(argv[0]);
41 return EXIT_SUCCESS;
42 }
43 // check argument count
44 if (argc != 4) {
45 fputs("Wrong number of arguments.\n", stderr);
46 return EXIT_FAILURE;
47 }
48 // check format id
49 if (version_parse_id(argv[1])) {
50 fputs("Unknown format id.\n", stderr);
51 return EXIT_FAILURE;
52 }
53 // be nice and ensure input and output are different
54 if (strcmp(argv[2], argv[3]) == 0) {
55 fputs("Input and output files must be different.\n", stderr);
56 return EXIT_FAILURE;
57 }
58 // try to open input file
59 global_input_stream = fopen(argv[2], "rb");
60 if (global_input_stream == NULL) {
61 fputs("Cannot open input file.\n", stderr);
62 return EXIT_FAILURE;
63 }
64 // try to open output file
65 global_output_stream = fopen(argv[3], "w");
66 if (global_output_stream == NULL) {
67 fputs("Cannot open output file.\n", stderr);
68 return EXIT_FAILURE;
69 }
70 // do the actual work
71 version_main();
72 // and then tidy up and exit
73 fclose(global_output_stream);
74 PLATFORM_SETFILETYPE_TEXT(argv[3]);
75 fclose(global_input_stream);
76 return EXIT_SUCCESS;
77 }