From 5559171fe41784993f789fc3d7d30e365706ee97 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 29 Sep 2021 14:40:03 -0700 Subject: [PATCH] Formatting change to switch indentation style --- bb.c | 86 +++++++++++----------- draw.c | 2 +- draw.h | 2 +- terminal.c | 204 ++++++++++++++++++++++++++--------------------------- terminal.h | 2 +- types.h | 2 +- utils.c | 2 +- utils.h | 2 +- 8 files changed, 151 insertions(+), 151 deletions(-) diff --git a/bb.c b/bb.c index ee5cf73..911697e 100644 --- a/bb.c +++ b/bb.c @@ -247,43 +247,43 @@ static int compare_files(const void *v1, const void *v2) for (char *sort = bb->sort + 1; *sort; sort += 2) { sign = sort[-1] == '-' ? -1 : 1; switch (*sort) { - case COL_SELECTED: COMPARE(IS_SELECTED(e1), IS_SELECTED(e2)); break; - case COL_NAME: { - // This sorting method is not identical to strverscmp(). Notably, bb's sort - // will order: [0, 1, 9, 00, 01, 09, 10, 000, 010] instead of strverscmp()'s - // order: [000, 00, 01, 010, 09, 0, 1, 9, 10]. I believe bb's sort is consistent - // with how people want their files grouped: all files padded to n digits - // will be grouped together, and files with the same padding will be sorted - // ordinally. This version also does case-insensitivity by lowercasing words, - // so the following characters come before all letters: [\]^_` - const char *n1 = e1->name, *n2 = e2->name; - while (*n1 && *n2) { - char c1 = tolower(*n1), c2 = tolower(*n2); - if ('0' <= c1 && c1 <= '9' && '0' <= c2 && c2 <= '9') { - long i1 = strtol(n1, (char**)&n1, 10); - long i2 = strtol(n2, (char**)&n2, 10); - // Shorter numbers always go before longer. In practice, I assume - // filenames padded to the same number of digits should be grouped - // together, instead of - // [1.png, 0001.png, 2.png, 0002.png, 3.png], it makes more sense to have: - // [1.png, 2.png, 3.png, 0001.png, 0002.png] - COMPARE((n2 - e2->name), (n1 - e1->name)); - COMPARE(i2, i1); - } else { - COMPARE(c2, c1); - ++n1; ++n2; - } + case COL_SELECTED: COMPARE(IS_SELECTED(e1), IS_SELECTED(e2)); break; + case COL_NAME: { + // This sorting method is not identical to strverscmp(). Notably, bb's sort + // will order: [0, 1, 9, 00, 01, 09, 10, 000, 010] instead of strverscmp()'s + // order: [000, 00, 01, 010, 09, 0, 1, 9, 10]. I believe bb's sort is consistent + // with how people want their files grouped: all files padded to n digits + // will be grouped together, and files with the same padding will be sorted + // ordinally. This version also does case-insensitivity by lowercasing words, + // so the following characters come before all letters: [\]^_` + const char *n1 = e1->name, *n2 = e2->name; + while (*n1 && *n2) { + char c1 = tolower(*n1), c2 = tolower(*n2); + if ('0' <= c1 && c1 <= '9' && '0' <= c2 && c2 <= '9') { + long i1 = strtol(n1, (char**)&n1, 10); + long i2 = strtol(n2, (char**)&n2, 10); + // Shorter numbers always go before longer. In practice, I assume + // filenames padded to the same number of digits should be grouped + // together, instead of + // [1.png, 0001.png, 2.png, 0002.png, 3.png], it makes more sense to have: + // [1.png, 2.png, 3.png, 0001.png, 0002.png] + COMPARE((n2 - e2->name), (n1 - e1->name)); + COMPARE(i2, i1); + } else { + COMPARE(c2, c1); + ++n1; ++n2; } - COMPARE(tolower(*n2), tolower(*n1)); - break; } - case COL_PERM: COMPARE((e1->info.st_mode & 0x3FF), (e2->info.st_mode & 0x3FF)); break; - case COL_SIZE: COMPARE(e1->info.st_size, e2->info.st_size); break; - case COL_MTIME: COMPARE_TIME(mtime(e1->info), mtime(e2->info)); break; - case COL_CTIME: COMPARE_TIME(ctime(e1->info), ctime(e2->info)); break; - case COL_ATIME: COMPARE_TIME(atime(e1->info), atime(e2->info)); break; - case COL_RANDOM: COMPARE(e2->shufflepos, e1->shufflepos); break; - default: break; + COMPARE(tolower(*n2), tolower(*n1)); + break; + } + case COL_PERM: COMPARE((e1->info.st_mode & 0x3FF), (e2->info.st_mode & 0x3FF)); break; + case COL_SIZE: COMPARE(e1->info.st_size, e2->info.st_size); break; + case COL_MTIME: COMPARE_TIME(mtime(e1->info), mtime(e2->info)); break; + case COL_CTIME: COMPARE_TIME(ctime(e1->info), ctime(e2->info)); break; + case COL_ATIME: COMPARE_TIME(atime(e1->info), atime(e2->info)); break; + case COL_RANDOM: COMPARE(e2->shufflepos, e1->shufflepos); break; + default: break; } } return 0; @@ -1114,13 +1114,13 @@ int main(int argc, char *argv[]) } else if (argv[i][0] == '-' && argv[i][1] != '-') { for (char *c = &argv[i][1]; *c; c++) { switch (*c) { - case 'h': goto help; - case 'v': goto version; - case 'd': print_dir = 1; break; - case '0': sep = '\0'; break; - case 's': print_selection = 1; break; - default: printf("Unknown command line argument: -%c\n%s", *c, usage_str); - return 1; + case 'h': goto help; + case 'v': goto version; + case 'd': print_dir = 1; break; + case '0': sep = '\0'; break; + case 's': print_selection = 1; break; + default: printf("Unknown command line argument: -%c\n%s", *c, usage_str); + return 1; } } } else if (i < argc-1) { @@ -1238,4 +1238,4 @@ int main(int argc, char *argv[]) return 0; } -// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1 +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/draw.c b/draw.c index c8d7737..806198d 100644 --- a/draw.c +++ b/draw.c @@ -405,4 +405,4 @@ void render(FILE *out, bb_t *bb) fflush(out); bb->dirty = 0; } -// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1 +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/draw.h b/draw.h index ef683e9..692a601 100644 --- a/draw.h +++ b/draw.h @@ -65,4 +65,4 @@ void col_size(entry_t *entry, const char *color, char *buf, int width); void col_name(entry_t *entry, const char *color, char *buf, int width); #endif -// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1 +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/terminal.c b/terminal.c index ae9fe66..8f5e72f 100644 --- a/terminal.c +++ b/terminal.c @@ -95,11 +95,11 @@ int bgetkey(FILE *in, int *mouse_x, int *mouse_y) return KEY_ESC; switch (c) { - case '\x1b': return KEY_ESC; - case '[': c = nextchar(fd); goto CSI_start; - case 'P': goto DCS; - case 'O': goto SS3; - default: return MOD_ALT | c; + case '\x1b': return KEY_ESC; + case '[': c = nextchar(fd); goto CSI_start; + case 'P': goto DCS; + case 'O': goto SS3; + default: return MOD_ALT | c; } CSI_start: @@ -107,104 +107,104 @@ int bgetkey(FILE *in, int *mouse_x, int *mouse_y) return MOD_ALT | '['; switch (c) { - case 'A': return modifiers | KEY_ARROW_UP; - case 'B': return modifiers | KEY_ARROW_DOWN; - case 'C': return modifiers | KEY_ARROW_RIGHT; - case 'D': return modifiers | KEY_ARROW_LEFT; - case 'F': return modifiers | KEY_END; - case 'H': return modifiers | KEY_HOME; - case 'J': return numcode == 2 ? (MOD_SHIFT | KEY_HOME) : -1; - case 'K': return MOD_SHIFT | KEY_END; - case 'M': return MOD_CTRL | KEY_DELETE; - case 'P': return modifiers | (numcode == 1 ? KEY_F1 : KEY_DELETE); - case 'Q': return numcode == 1 ? (modifiers | KEY_F2) : -1; - case 'R': return numcode == 1 ? (modifiers | KEY_F3) : -1; - case 'S': return numcode == 1 ? (modifiers | KEY_F4) : -1; - case '~': - switch (numcode) { - case 1: return modifiers | KEY_HOME; - case 2: return modifiers | KEY_INSERT; - case 3: return modifiers | KEY_DELETE; - case 4: return modifiers | KEY_END; - case 5: return modifiers | KEY_PGUP; - case 6: return modifiers | KEY_PGDN; - case 7: return modifiers | KEY_HOME; - case 8: return modifiers | KEY_END; - case 10: return modifiers | KEY_F0; - case 11: return modifiers | KEY_F1; - case 12: return modifiers | KEY_F2; - case 13: return modifiers | KEY_F3; - case 14: return modifiers | KEY_F4; - case 15: return modifiers | KEY_F5; - case 17: return modifiers | KEY_F6; - case 18: return modifiers | KEY_F7; - case 19: return modifiers | KEY_F8; - case 20: return modifiers | KEY_F9; - case 21: return modifiers | KEY_F10; - case 23: return modifiers | KEY_F11; - case 24: return modifiers | KEY_F12; - default: break; - } - return -1; - case '<': { // Mouse clicks - int buttons = 0, x = 0, y = 0; - c = nextnum(fd, nextchar(fd), &buttons); - if (c != ';') return -1; - c = nextnum(fd, nextchar(fd), &x); - if (c != ';') return -1; - c = nextnum(fd, nextchar(fd), &y); - if (c != 'm' && c != 'M') return -1; + case 'A': return modifiers | KEY_ARROW_UP; + case 'B': return modifiers | KEY_ARROW_DOWN; + case 'C': return modifiers | KEY_ARROW_RIGHT; + case 'D': return modifiers | KEY_ARROW_LEFT; + case 'F': return modifiers | KEY_END; + case 'H': return modifiers | KEY_HOME; + case 'J': return numcode == 2 ? (MOD_SHIFT | KEY_HOME) : -1; + case 'K': return MOD_SHIFT | KEY_END; + case 'M': return MOD_CTRL | KEY_DELETE; + case 'P': return modifiers | (numcode == 1 ? KEY_F1 : KEY_DELETE); + case 'Q': return numcode == 1 ? (modifiers | KEY_F2) : -1; + case 'R': return numcode == 1 ? (modifiers | KEY_F3) : -1; + case 'S': return numcode == 1 ? (modifiers | KEY_F4) : -1; + case '~': + switch (numcode) { + case 1: return modifiers | KEY_HOME; + case 2: return modifiers | KEY_INSERT; + case 3: return modifiers | KEY_DELETE; + case 4: return modifiers | KEY_END; + case 5: return modifiers | KEY_PGUP; + case 6: return modifiers | KEY_PGDN; + case 7: return modifiers | KEY_HOME; + case 8: return modifiers | KEY_END; + case 10: return modifiers | KEY_F0; + case 11: return modifiers | KEY_F1; + case 12: return modifiers | KEY_F2; + case 13: return modifiers | KEY_F3; + case 14: return modifiers | KEY_F4; + case 15: return modifiers | KEY_F5; + case 17: return modifiers | KEY_F6; + case 18: return modifiers | KEY_F7; + case 19: return modifiers | KEY_F8; + case 20: return modifiers | KEY_F9; + case 21: return modifiers | KEY_F10; + case 23: return modifiers | KEY_F11; + case 24: return modifiers | KEY_F12; + default: break; + } + return -1; + case '<': { // Mouse clicks + int buttons = 0, x = 0, y = 0; + c = nextnum(fd, nextchar(fd), &buttons); + if (c != ';') return -1; + c = nextnum(fd, nextchar(fd), &x); + if (c != ';') return -1; + c = nextnum(fd, nextchar(fd), &y); + if (c != 'm' && c != 'M') return -1; - if (mouse_x) *mouse_x = x - 1; - if (mouse_y) *mouse_y = y - 1; + if (mouse_x) *mouse_x = x - 1; + if (mouse_y) *mouse_y = y - 1; - if (buttons & 4) modifiers |= MOD_SHIFT; - if (buttons & 8) modifiers |= MOD_META; - if (buttons & 16) modifiers |= MOD_CTRL; - int key = -1; - switch (buttons & ~(4|8|16)) { - case 0: key = c == 'm' ? MOUSE_LEFT_RELEASE : MOUSE_LEFT_PRESS; break; - case 1: key = c == 'm' ? MOUSE_MIDDLE_RELEASE : MOUSE_MIDDLE_PRESS; break; - case 2: key = c == 'm' ? MOUSE_RIGHT_RELEASE : MOUSE_RIGHT_PRESS; break; - case 32: key = MOUSE_LEFT_DRAG; break; - case 33: key = MOUSE_MIDDLE_DRAG; break; - case 34: key = MOUSE_RIGHT_DRAG; break; - case 64: key = MOUSE_WHEEL_RELEASE; break; - case 65: key = MOUSE_WHEEL_PRESS; break; - default: return -1; - } - if (key == MOUSE_LEFT_RELEASE || key == MOUSE_RIGHT_RELEASE || key == MOUSE_MIDDLE_RELEASE) { - static int lastclick = -1; - static struct timespec lastclicktime = {0, 0}; - struct timespec clicktime; - clock_gettime(CLOCK_MONOTONIC, &clicktime); - if (key == lastclick) { - double dt_ms = 1e3*(double)(clicktime.tv_sec - lastclicktime.tv_sec) - + 1e-6*(double)(clicktime.tv_nsec - lastclicktime.tv_nsec); - if (dt_ms < DOUBLECLICK_THRESHOLD) { - switch (key) { - case MOUSE_LEFT_RELEASE: key = MOUSE_LEFT_DOUBLE; break; - case MOUSE_RIGHT_RELEASE: key = MOUSE_RIGHT_DOUBLE; break; - case MOUSE_MIDDLE_RELEASE: key = MOUSE_MIDDLE_DOUBLE; break; - default: break; - } + if (buttons & 4) modifiers |= MOD_SHIFT; + if (buttons & 8) modifiers |= MOD_META; + if (buttons & 16) modifiers |= MOD_CTRL; + int key = -1; + switch (buttons & ~(4|8|16)) { + case 0: key = c == 'm' ? MOUSE_LEFT_RELEASE : MOUSE_LEFT_PRESS; break; + case 1: key = c == 'm' ? MOUSE_MIDDLE_RELEASE : MOUSE_MIDDLE_PRESS; break; + case 2: key = c == 'm' ? MOUSE_RIGHT_RELEASE : MOUSE_RIGHT_PRESS; break; + case 32: key = MOUSE_LEFT_DRAG; break; + case 33: key = MOUSE_MIDDLE_DRAG; break; + case 34: key = MOUSE_RIGHT_DRAG; break; + case 64: key = MOUSE_WHEEL_RELEASE; break; + case 65: key = MOUSE_WHEEL_PRESS; break; + default: return -1; + } + if (key == MOUSE_LEFT_RELEASE || key == MOUSE_RIGHT_RELEASE || key == MOUSE_MIDDLE_RELEASE) { + static int lastclick = -1; + static struct timespec lastclicktime = {0, 0}; + struct timespec clicktime; + clock_gettime(CLOCK_MONOTONIC, &clicktime); + if (key == lastclick) { + double dt_ms = 1e3*(double)(clicktime.tv_sec - lastclicktime.tv_sec) + + 1e-6*(double)(clicktime.tv_nsec - lastclicktime.tv_nsec); + if (dt_ms < DOUBLECLICK_THRESHOLD) { + switch (key) { + case MOUSE_LEFT_RELEASE: key = MOUSE_LEFT_DOUBLE; break; + case MOUSE_RIGHT_RELEASE: key = MOUSE_RIGHT_DOUBLE; break; + case MOUSE_MIDDLE_RELEASE: key = MOUSE_MIDDLE_DOUBLE; break; + default: break; } } - lastclicktime = clicktime; - lastclick = key; } - return modifiers | key; + lastclicktime = clicktime; + lastclick = key; } - default: - if ('0' <= c && c <= '9') { - // Ps prefix - c = nextnum(fd, c, &numcode); - if (c == ';') { - c = nextnum(fd, nextchar(fd), &modifiers); - modifiers = (modifiers >> 1) << MOD_BITSHIFT; - } - goto CSI_start; + return modifiers | key; + } + default: + if ('0' <= c && c <= '9') { + // Ps prefix + c = nextnum(fd, c, &numcode); + if (c == ';') { + c = nextnum(fd, nextchar(fd), &modifiers); + modifiers = (modifiers >> 1) << MOD_BITSHIFT; } + goto CSI_start; + } } return -1; @@ -213,11 +213,11 @@ int bgetkey(FILE *in, int *mouse_x, int *mouse_y) SS3: switch (nextchar(fd)) { - case 'P': return KEY_F1; - case 'Q': return KEY_F2; - case 'R': return KEY_F3; - case 'S': return KEY_F4; - default: break; + case 'P': return KEY_F1; + case 'Q': return KEY_F2; + case 'R': return KEY_F3; + case 'S': return KEY_F4; + default: break; } return -1; } @@ -267,4 +267,4 @@ int bkeywithname(const char *name) } return strlen(name) == 1 ? name[0] : -1; } -// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1 +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/terminal.h b/terminal.h index 2189f35..199fe30 100644 --- a/terminal.h +++ b/terminal.h @@ -83,4 +83,4 @@ char *bkeyname(int key, char *buf); int bkeywithname(const char *name); #endif -// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1 +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/types.h b/types.h index b211788..d80e83d 100644 --- a/types.h +++ b/types.h @@ -86,4 +86,4 @@ typedef struct { } binding_t; #endif -// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1 +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/utils.c b/utils.c index 1444894..e94658c 100644 --- a/utils.c +++ b/utils.c @@ -54,4 +54,4 @@ void delete(void *p) } } -// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1 +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/utils.h b/utils.h index ae98d75..1cb4744 100644 --- a/utils.h +++ b/utils.h @@ -76,4 +76,4 @@ __attribute__((nonnull)) void delete(void *p); #endif -// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1 +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0