commit 449f27a680701cbde84c1d8761e066700b0d411a from: Omar Polo date: Fri Jul 06 19:05:09 2018 UTC fixed switch indentation commit - 78a0e67f6fd44afc490886e1199117ad31291ee7 commit + 449f27a680701cbde84c1d8761e066700b0d411a blob - d952eec9e8d4409adf36c3a852924410a8f75003 blob + d77c0c9257ad6cadec4ff874046cb74b78fb673b --- mymenu.c +++ mymenu.c @@ -828,18 +828,18 @@ int main(int argc, char **argv) { int ch; while ((ch = getopt(argc, argv, "ahv")) != -1) { switch (ch) { - case 'a': - first_selected = true; - break; - case 'h': - usage(*argv); - return 0; - case 'v': - fprintf(stderr, "%s version: %s\n", *argv, VERSION); - return 0; - default: - usage(*argv); - return EX_USAGE; + case 'a': + first_selected = true; + break; + case 'h': + usage(*argv); + return 0; + case 'v': + fprintf(stderr, "%s version: %s\n", *argv, VERSION); + return 0; + default: + usage(*argv); + return EX_USAGE; } } @@ -1041,12 +1041,6 @@ int main(int argc, char **argv) { } // load the font - /* XFontStruct *font = XLoadQueryFont(d, fontname); */ - /* if (font == nil) { */ - /* fprintf(stderr, "Unable to load %s font\n", fontname); */ - /* font = XLoadQueryFont(d, "fixed"); */ - /* } */ - // load the font #ifdef USE_XFT XftFont *font = XftFontOpenName(d, DefaultScreen(d), fontname); #else @@ -1195,104 +1189,102 @@ int main(int argc, char **argv) { continue; switch (e.type) { - case KeymapNotify: - XRefreshKeyboardMapping(&e.xmapping); - break; - - case KeyPress: { - XKeyPressedEvent *ev = (XKeyPressedEvent*)&e; - - char *input; - switch (parse_event(d, ev, xic, &input)) { - case EXIT: - status = ERR; + case KeymapNotify: + XRefreshKeyboardMapping(&e.xmapping); break; - case CONFIRM: - status = OK; + case KeyPress: { + XKeyPressedEvent *ev = (XKeyPressedEvent*)&e; - // if first_selected is active and the first completion is - // active be sure to 'expand' the text to match the selection - if (first_selected && cs && cs->selected) { - free(text); - text = strdup(cs->completion); - if (text == nil) { - fprintf(stderr, "Memory allocation error"); + char *input; + switch (parse_event(d, ev, xic, &input)) { + case EXIT: status = ERR; - } - textlen = strlen(text); - } - break; + break; - case PREV_COMPL: { - complete(cs, first_selected, true, &text, &textlen, &status); - break; - } + case CONFIRM: + status = OK; - case NEXT_COMPL: { - complete(cs, first_selected, false, &text, &textlen, &status); - break; - } + // if first_selected is active and the first completion is + // active be sure to 'expand' the text to match the selection + if (first_selected && cs && cs->selected) { + free(text); + text = strdup(cs->completion); + if (text == nil) { + fprintf(stderr, "Memory allocation error"); + status = ERR; + } + textlen = strlen(text); + } + break; - case DEL_CHAR: - popc(text, textlen); - cs = update_completions(cs, text, lines, first_selected); - break; - - case DEL_WORD: { - // `textlen` is the lenght of the allocated string, not the - // lenght of the ACTUAL string - int p = strlen(text) -1; - if (p > 0) { // delete the current char - text[p] = 0; - p--; - } + case PREV_COMPL: { + complete(cs, first_selected, true, &text, &textlen, &status); + break; + } - // erase the alphanumeric char - while (p >= 0 && isalnum(text[p])) { - text[p] = 0; - p--; - } + case NEXT_COMPL: { + complete(cs, first_selected, false, &text, &textlen, &status); + break; + } - // erase also trailing white spaces - while (p >= 0 && isspace(text[p])) { - text[p] = 0; - p--; - } - cs = update_completions(cs, text, lines, first_selected); - break; - } + case DEL_CHAR: + popc(text, textlen); + cs = update_completions(cs, text, lines, first_selected); + break; - case DEL_LINE: { - for (int i = 0; i < textlen; ++i) - text[i] = 0; - cs = update_completions(cs, text, lines, first_selected); - break; - } + case DEL_WORD: { + // `textlen` is the lenght of the allocated string, not the + // lenght of the ACTUAL string + int p = strlen(text) -1; + if (p > 0) { // delete the current char + text[p] = 0; + p--; + } - case ADD_CHAR: { - int str_len = strlen(input); - for (int i = 0; i < str_len; ++i) { - textlen = pushc(&text, textlen, input[i]); - if (textlen == -1) { - fprintf(stderr, "Memory allocation error\n"); - status = ERR; + // erase the alphanumeric char + while (p >= 0 && isalnum(text[p])) { + text[p] = 0; + p--; + } + + // erase also trailing white spaces + while (p >= 0 && isspace(text[p])) { + text[p] = 0; + p--; + } + cs = update_completions(cs, text, lines, first_selected); break; } - cs = update_completions(cs, text, lines, first_selected); - free(input); + + case DEL_LINE: { + for (int i = 0; i < textlen; ++i) + text[i] = 0; + cs = update_completions(cs, text, lines, first_selected); + break; + } + + case ADD_CHAR: { + int str_len = strlen(input); + for (int i = 0; i < str_len; ++i) { + textlen = pushc(&text, textlen, input[i]); + if (textlen == -1) { + fprintf(stderr, "Memory allocation error\n"); + status = ERR; + break; + } + cs = update_completions(cs, text, lines, first_selected); + free(input); + } + break; + } } } - break; - } - + default: + fprintf(stderr, "Unknown event %d\n", e.type); } - default: - fprintf(stderr, "Unknown event %d\n", e.type); - } - draw(&r, text, cs); }