1.1 --- a/cline.c Fri May 27 15:10:23 2011 +0200 1.2 +++ b/cline.c Mon May 30 08:45:08 2011 +0200 1.3 @@ -72,6 +72,12 @@ 1.4 printf(helpText, prgName, prgName, prgName, prgName); 1.5 } 1.6 1.7 +int exit_with_help(char* prgName, settings_t* settings, int code) { 1.8 + printHelpText(prgName); 1.9 + destroy_settings_t(settings); 1.10 + return code; 1.11 +} 1.12 + 1.13 int main(int argc, char** argv) { 1.14 1.15 // Settings 1.16 @@ -94,7 +100,7 @@ 1.17 char* directory = "./"; 1.18 char* suffix = " "; 1.19 bool showHelp = false; 1.20 - char checked = 0; 1.21 + int checked = 0; 1.22 1.23 for (int t = 1 ; t < argc ; t++) { 1.24 1.25 @@ -102,84 +108,61 @@ 1.26 1.27 // s 1.28 if ((argflags & 2) > 0) { 1.29 - if ((checked & 1) > 0) { 1.30 - printHelpText(prgName); 1.31 - destroy_settings_t(settings); 1.32 - return 1; 1.33 + if (registerArgument(&checked, 6)) { 1.34 + return exit_with_help(prgName, settings, 1); 1.35 } 1.36 settings->includeSuffixes = true; 1.37 t++; 1.38 if (t >= argc) { 1.39 - printHelpText(prgName); 1.40 - destroy_settings_t(settings); 1.41 - return 1; 1.42 + return exit_with_help(prgName, settings, 1); 1.43 } 1.44 suffix = argv[t]; 1.45 - checked |= 1; 1.46 } 1.47 // S 1.48 if ((argflags & 4) > 0) { 1.49 - if ((checked & 1) > 0) { 1.50 - printHelpText(prgName); 1.51 - destroy_settings_t(settings); 1.52 - return 1; 1.53 + if (registerArgument(&checked, 6)) { 1.54 + return exit_with_help(prgName, settings, 1); 1.55 } 1.56 settings->includeSuffixes = false; 1.57 t++; 1.58 if (t >= argc) { 1.59 - printHelpText(prgName); 1.60 - destroy_settings_t(settings); 1.61 - return 1; 1.62 + return exit_with_help(prgName, settings, 1); 1.63 } 1.64 suffix = argv[t]; 1.65 - checked |= 1; 1.66 } 1.67 // h 1.68 if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { 1.69 - if ((checked & 2) > 0) { 1.70 - printHelpText(prgName); 1.71 - destroy_settings_t(settings); 1.72 - return 1; 1.73 + if (registerArgument(&checked, 1)) { 1.74 + return exit_with_help(prgName, settings, 1); 1.75 } 1.76 - checked |= 2; 1.77 showHelp = true; 1.78 } 1.79 // r, R 1.80 if ((argflags & 24) > 0) { 1.81 - if ((checked & 4) > 0) { 1.82 - printHelpText(prgName); 1.83 - destroy_settings_t(settings); 1.84 - return 1; 1.85 + if (registerArgument(&checked, 24)) { 1.86 + return exit_with_help(prgName, settings, 1); 1.87 } 1.88 - checked |= 4; 1.89 settings->recursive = true; 1.90 } 1.91 + // m 1.92 if ((argflags & 32) > 0) { 1.93 - if ((checked & 32) > 0) { 1.94 - printHelpText(prgName); 1.95 - destroy_settings_t(settings); 1.96 - return 1; 1.97 + if (registerArgument(&checked, 32)) { 1.98 + return exit_with_help(prgName, settings, 1); 1.99 } 1.100 - checked |= 32; 1.101 settings->matchesOnly = true; 1.102 } 1.103 // Path 1.104 if (argflags == 0) { 1.105 - if ((checked & 8) > 0) { 1.106 - printHelpText(prgName); 1.107 - destroy_settings_t(settings); 1.108 - return 1; 1.109 + if (registerArgument(&checked, 1024)) { 1.110 + return exit_with_help(prgName, settings, 1); 1.111 } 1.112 - checked |= 8; 1.113 directory = argv[t]; 1.114 } 1.115 } 1.116 1.117 // Show help and quit 1.118 if (showHelp) { 1.119 - printHelpText(prgName); 1.120 - destroy_settings_t(settings); 1.121 - return 0; 1.122 + return exit_with_help(prgName, settings, 0); 1.123 } 1.124 1.125 // Find tokens