diff -r 1b55f3fa52c9 -r 28319b20968c cline.c --- a/cline.c Fri May 27 15:10:23 2011 +0200 +++ b/cline.c Mon May 30 08:45:08 2011 +0200 @@ -72,6 +72,12 @@ printf(helpText, prgName, prgName, prgName, prgName); } +int exit_with_help(char* prgName, settings_t* settings, int code) { + printHelpText(prgName); + destroy_settings_t(settings); + return code; +} + int main(int argc, char** argv) { // Settings @@ -94,7 +100,7 @@ char* directory = "./"; char* suffix = " "; bool showHelp = false; - char checked = 0; + int checked = 0; for (int t = 1 ; t < argc ; t++) { @@ -102,84 +108,61 @@ // s if ((argflags & 2) > 0) { - if ((checked & 1) > 0) { - printHelpText(prgName); - destroy_settings_t(settings); - return 1; + if (registerArgument(&checked, 6)) { + return exit_with_help(prgName, settings, 1); } settings->includeSuffixes = true; t++; if (t >= argc) { - printHelpText(prgName); - destroy_settings_t(settings); - return 1; + return exit_with_help(prgName, settings, 1); } suffix = argv[t]; - checked |= 1; } // S if ((argflags & 4) > 0) { - if ((checked & 1) > 0) { - printHelpText(prgName); - destroy_settings_t(settings); - return 1; + if (registerArgument(&checked, 6)) { + return exit_with_help(prgName, settings, 1); } settings->includeSuffixes = false; t++; if (t >= argc) { - printHelpText(prgName); - destroy_settings_t(settings); - return 1; + return exit_with_help(prgName, settings, 1); } suffix = argv[t]; - checked |= 1; } // h if ((argflags & 1) > 0 || strcmp(argv[t], "--help") == 0) { - if ((checked & 2) > 0) { - printHelpText(prgName); - destroy_settings_t(settings); - return 1; + if (registerArgument(&checked, 1)) { + return exit_with_help(prgName, settings, 1); } - checked |= 2; showHelp = true; } // r, R if ((argflags & 24) > 0) { - if ((checked & 4) > 0) { - printHelpText(prgName); - destroy_settings_t(settings); - return 1; + if (registerArgument(&checked, 24)) { + return exit_with_help(prgName, settings, 1); } - checked |= 4; settings->recursive = true; } + // m if ((argflags & 32) > 0) { - if ((checked & 32) > 0) { - printHelpText(prgName); - destroy_settings_t(settings); - return 1; + if (registerArgument(&checked, 32)) { + return exit_with_help(prgName, settings, 1); } - checked |= 32; settings->matchesOnly = true; } // Path if (argflags == 0) { - if ((checked & 8) > 0) { - printHelpText(prgName); - destroy_settings_t(settings); - return 1; + if (registerArgument(&checked, 1024)) { + return exit_with_help(prgName, settings, 1); } - checked |= 8; directory = argv[t]; } } // Show help and quit if (showHelp) { - printHelpText(prgName); - destroy_settings_t(settings); - return 0; + return exit_with_help(prgName, settings, 0); } // Find tokens