polish arg

This commit is contained in:
kuoi 2023-02-28 16:02:03 +08:00
parent fa83172efb
commit cb67fc49ed

View file

@ -18,41 +18,35 @@ void show_help (int help_num){
if (help_num == 0) { if (help_num == 0) {
cout << "~|~|\\ |~|~ ~) | |o._ |~| _ _| _ " << endl; cout << "~|~|\\ |~|~ ~) | |o._ |~| _ _| _ " << endl;
cout << " | | \\| | /_ \\/\\/ || ||_|(_|(_|(_|" << endl; cout << " | | \\| | /_ \\/\\/ || ||_|(_|(_|(_|" << endl;
cout << "TNT2WinClada MIT\nplease use -h to see more help" << endl; cout << "TNT2WinClada\nMIT, Guoyi Zhang, 2023\nplease use -h to see more options" << endl;
} else { } else {
cout << "~|~|\\ |~|~ ~) | |o._ |~| _ _| _ " << endl; cout << "~|~|\\ |~|~ ~) | |o._ |~| _ _| _ " << endl;
cout << " | | \\| | /_ \\/\\/ || ||_|(_|(_|(_|" << endl; cout << " | | \\| | /_ \\/\\/ || ||_|(_|(_|(_|" << endl;
cout << "-h help;\n-i input: -i ${input_file};\n-o output: -o ${output_file}" << endl; cout << "Usage: tnt2winclada -i ${input_file} -o ${output_file}\n-h help;\n-i input: -i ${input_file};\n-o output: -o ${output_file}" << endl;
} }
} }
void argument(int argc, char **argv) { void argument(int argc, char **argv) {
// -i -h -o option // -i -h -o option
int x=0, y = 0, z=0;
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
if (argc == 2 && string(argv[1]) == "-h") { if (argc == 2 && string(argv[1]) == "-h") {
show_help(1); show_help(1);
x++; exit(0);
return;
} }
if (argc != 5 || string(argv[1]) != "-i" || string(argv[3]) != "-o") { if (argc != 5 || string(argv[1]) != "-i" || string(argv[3]) != "-o") {
cout << "input or output can't be empty." << endl;
show_help(0); show_help(0);
return; exit(0);
} }
if (string(argv[i]) == "-i") { if (string(argv[i]) == "-i") {
i++; i++;
inputFileName = argv[i]; inputFileName = argv[i];
y++;
} }
if (string(argv[i]) == "-o") { if (string(argv[i]) == "-o") {
i++; i++;
outputFileName = argv[i]; outputFileName = argv[i];
z++;
} }
} }
if (x==0 && (y==0 || z==0)) {
cout << "input or output can't be empty." << endl;
}
} }
int read_tnt() { int read_tnt() {