int main(int argc, char** argv) { modulname = argv[0]; char* outFileName = NULL; int c; opterr = 0; bool fOption = false; bool hOption = false; while ((c = getopt (argc, argv, "fho:")) != -1) switch (c) { case 'f': fOption = true; break; case 'h': hOption = true; break; case 'o': outFileName = optarg; break; case '?': EXIT_ERR() default: assert(0); } // check if either find OR hide option is set if (fOption == hOption) { EXIT_ERR() } char* input = getInputLine(); if (input == NULL) { (void)fprintf(stderr, "Failed to reserve space for input"); return 2; } out = stdout; if (outFileName != NULL) { out = fopen(outFileName, "w"); } if (fOption) find(input, out); else hide(input, out); free(input); (void)fclose(out); return 0; }
void interactive_shell(void) { #define MAX_LINE_LEN 100 #define MAX_CMD_LEN 10 trie_t trieObj; trie_t *trie = &trieObj; char cmd[MAX_CMD_LEN] = {0}, arg[MAX_LINE_LEN] = {0}; trie_init(trie); while (1) { show_prompt("*Trie"); if (getInputLine(cmd, arg, MAX_LINE_LEN) == EOF) break; if (process_cmds(trie, cmd, arg)) { /** Done processing at 'quit' command */ break; } } }