| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 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 |
|
| 30 |
int main(int argc, char *argv[]) |
| 31 |
{ |
| 32 |
|
| 33 |
if (argc == 2) { |
| 34 |
if ((strcmp(argv[1], "-h") == 0) |
| 35 |
|| (strcmp(argv[1], "--help") == 0)) |
| 36 |
argc = 1; |
| 37 |
} |
| 38 |
|
| 39 |
if (argc == 1) { |
| 40 |
version_show_info(argv[0]); |
| 41 |
return EXIT_SUCCESS; |
| 42 |
} |
| 43 |
|
| 44 |
if (argc != 4) { |
| 45 |
fputs("Wrong number of arguments.\n", stderr); |
| 46 |
return EXIT_FAILURE; |
| 47 |
} |
| 48 |
|
| 49 |
if (version_parse_id(argv[1])) { |
| 50 |
fputs("Unknown format id.\n", stderr); |
| 51 |
return EXIT_FAILURE; |
| 52 |
} |
| 53 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 71 |
version_main(); |
| 72 |
|
| 73 |
fclose(global_output_stream); |
| 74 |
PLATFORM_SETFILETYPE_TEXT(argv[3]); |
| 75 |
fclose(global_input_stream); |
| 76 |
return EXIT_SUCCESS; |
| 77 |
} |