Formatting change to switch indentation style
This commit is contained in:
parent
303b6bad08
commit
5559171fe4
86
bb.c
86
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) {
|
for (char *sort = bb->sort + 1; *sort; sort += 2) {
|
||||||
sign = sort[-1] == '-' ? -1 : 1;
|
sign = sort[-1] == '-' ? -1 : 1;
|
||||||
switch (*sort) {
|
switch (*sort) {
|
||||||
case COL_SELECTED: COMPARE(IS_SELECTED(e1), IS_SELECTED(e2)); break;
|
case COL_SELECTED: COMPARE(IS_SELECTED(e1), IS_SELECTED(e2)); break;
|
||||||
case COL_NAME: {
|
case COL_NAME: {
|
||||||
// This sorting method is not identical to strverscmp(). Notably, bb's sort
|
// 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
|
// 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
|
// 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
|
// 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
|
// will be grouped together, and files with the same padding will be sorted
|
||||||
// ordinally. This version also does case-insensitivity by lowercasing words,
|
// ordinally. This version also does case-insensitivity by lowercasing words,
|
||||||
// so the following characters come before all letters: [\]^_`
|
// so the following characters come before all letters: [\]^_`
|
||||||
const char *n1 = e1->name, *n2 = e2->name;
|
const char *n1 = e1->name, *n2 = e2->name;
|
||||||
while (*n1 && *n2) {
|
while (*n1 && *n2) {
|
||||||
char c1 = tolower(*n1), c2 = tolower(*n2);
|
char c1 = tolower(*n1), c2 = tolower(*n2);
|
||||||
if ('0' <= c1 && c1 <= '9' && '0' <= c2 && c2 <= '9') {
|
if ('0' <= c1 && c1 <= '9' && '0' <= c2 && c2 <= '9') {
|
||||||
long i1 = strtol(n1, (char**)&n1, 10);
|
long i1 = strtol(n1, (char**)&n1, 10);
|
||||||
long i2 = strtol(n2, (char**)&n2, 10);
|
long i2 = strtol(n2, (char**)&n2, 10);
|
||||||
// Shorter numbers always go before longer. In practice, I assume
|
// Shorter numbers always go before longer. In practice, I assume
|
||||||
// filenames padded to the same number of digits should be grouped
|
// filenames padded to the same number of digits should be grouped
|
||||||
// together, instead of
|
// together, instead of
|
||||||
// [1.png, 0001.png, 2.png, 0002.png, 3.png], it makes more sense to have:
|
// [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]
|
// [1.png, 2.png, 3.png, 0001.png, 0002.png]
|
||||||
COMPARE((n2 - e2->name), (n1 - e1->name));
|
COMPARE((n2 - e2->name), (n1 - e1->name));
|
||||||
COMPARE(i2, i1);
|
COMPARE(i2, i1);
|
||||||
} else {
|
} else {
|
||||||
COMPARE(c2, c1);
|
COMPARE(c2, c1);
|
||||||
++n1; ++n2;
|
++n1; ++n2;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
COMPARE(tolower(*n2), tolower(*n1));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case COL_PERM: COMPARE((e1->info.st_mode & 0x3FF), (e2->info.st_mode & 0x3FF)); break;
|
COMPARE(tolower(*n2), tolower(*n1));
|
||||||
case COL_SIZE: COMPARE(e1->info.st_size, e2->info.st_size); break;
|
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_PERM: COMPARE((e1->info.st_mode & 0x3FF), (e2->info.st_mode & 0x3FF)); break;
|
||||||
case COL_ATIME: COMPARE_TIME(atime(e1->info), atime(e2->info)); break;
|
case COL_SIZE: COMPARE(e1->info.st_size, e2->info.st_size); break;
|
||||||
case COL_RANDOM: COMPARE(e2->shufflepos, e1->shufflepos); break;
|
case COL_MTIME: COMPARE_TIME(mtime(e1->info), mtime(e2->info)); break;
|
||||||
default: 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;
|
return 0;
|
||||||
@ -1114,13 +1114,13 @@ int main(int argc, char *argv[])
|
|||||||
} else if (argv[i][0] == '-' && argv[i][1] != '-') {
|
} else if (argv[i][0] == '-' && argv[i][1] != '-') {
|
||||||
for (char *c = &argv[i][1]; *c; c++) {
|
for (char *c = &argv[i][1]; *c; c++) {
|
||||||
switch (*c) {
|
switch (*c) {
|
||||||
case 'h': goto help;
|
case 'h': goto help;
|
||||||
case 'v': goto version;
|
case 'v': goto version;
|
||||||
case 'd': print_dir = 1; break;
|
case 'd': print_dir = 1; break;
|
||||||
case '0': sep = '\0'; break;
|
case '0': sep = '\0'; break;
|
||||||
case 's': print_selection = 1; break;
|
case 's': print_selection = 1; break;
|
||||||
default: printf("Unknown command line argument: -%c\n%s", *c, usage_str);
|
default: printf("Unknown command line argument: -%c\n%s", *c, usage_str);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (i < argc-1) {
|
} else if (i < argc-1) {
|
||||||
@ -1238,4 +1238,4 @@ int main(int argc, char *argv[])
|
|||||||
return 0;
|
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
|
||||||
|
2
draw.c
2
draw.c
@ -405,4 +405,4 @@ void render(FILE *out, bb_t *bb)
|
|||||||
fflush(out);
|
fflush(out);
|
||||||
bb->dirty = 0;
|
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
|
||||||
|
2
draw.h
2
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);
|
void col_name(entry_t *entry, const char *color, char *buf, int width);
|
||||||
|
|
||||||
#endif
|
#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
|
||||||
|
204
terminal.c
204
terminal.c
@ -95,11 +95,11 @@ int bgetkey(FILE *in, int *mouse_x, int *mouse_y)
|
|||||||
return KEY_ESC;
|
return KEY_ESC;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '\x1b': return KEY_ESC;
|
case '\x1b': return KEY_ESC;
|
||||||
case '[': c = nextchar(fd); goto CSI_start;
|
case '[': c = nextchar(fd); goto CSI_start;
|
||||||
case 'P': goto DCS;
|
case 'P': goto DCS;
|
||||||
case 'O': goto SS3;
|
case 'O': goto SS3;
|
||||||
default: return MOD_ALT | c;
|
default: return MOD_ALT | c;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSI_start:
|
CSI_start:
|
||||||
@ -107,104 +107,104 @@ int bgetkey(FILE *in, int *mouse_x, int *mouse_y)
|
|||||||
return MOD_ALT | '[';
|
return MOD_ALT | '[';
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'A': return modifiers | KEY_ARROW_UP;
|
case 'A': return modifiers | KEY_ARROW_UP;
|
||||||
case 'B': return modifiers | KEY_ARROW_DOWN;
|
case 'B': return modifiers | KEY_ARROW_DOWN;
|
||||||
case 'C': return modifiers | KEY_ARROW_RIGHT;
|
case 'C': return modifiers | KEY_ARROW_RIGHT;
|
||||||
case 'D': return modifiers | KEY_ARROW_LEFT;
|
case 'D': return modifiers | KEY_ARROW_LEFT;
|
||||||
case 'F': return modifiers | KEY_END;
|
case 'F': return modifiers | KEY_END;
|
||||||
case 'H': return modifiers | KEY_HOME;
|
case 'H': return modifiers | KEY_HOME;
|
||||||
case 'J': return numcode == 2 ? (MOD_SHIFT | KEY_HOME) : -1;
|
case 'J': return numcode == 2 ? (MOD_SHIFT | KEY_HOME) : -1;
|
||||||
case 'K': return MOD_SHIFT | KEY_END;
|
case 'K': return MOD_SHIFT | KEY_END;
|
||||||
case 'M': return MOD_CTRL | KEY_DELETE;
|
case 'M': return MOD_CTRL | KEY_DELETE;
|
||||||
case 'P': return modifiers | (numcode == 1 ? KEY_F1 : KEY_DELETE);
|
case 'P': return modifiers | (numcode == 1 ? KEY_F1 : KEY_DELETE);
|
||||||
case 'Q': return numcode == 1 ? (modifiers | KEY_F2) : -1;
|
case 'Q': return numcode == 1 ? (modifiers | KEY_F2) : -1;
|
||||||
case 'R': return numcode == 1 ? (modifiers | KEY_F3) : -1;
|
case 'R': return numcode == 1 ? (modifiers | KEY_F3) : -1;
|
||||||
case 'S': return numcode == 1 ? (modifiers | KEY_F4) : -1;
|
case 'S': return numcode == 1 ? (modifiers | KEY_F4) : -1;
|
||||||
case '~':
|
case '~':
|
||||||
switch (numcode) {
|
switch (numcode) {
|
||||||
case 1: return modifiers | KEY_HOME;
|
case 1: return modifiers | KEY_HOME;
|
||||||
case 2: return modifiers | KEY_INSERT;
|
case 2: return modifiers | KEY_INSERT;
|
||||||
case 3: return modifiers | KEY_DELETE;
|
case 3: return modifiers | KEY_DELETE;
|
||||||
case 4: return modifiers | KEY_END;
|
case 4: return modifiers | KEY_END;
|
||||||
case 5: return modifiers | KEY_PGUP;
|
case 5: return modifiers | KEY_PGUP;
|
||||||
case 6: return modifiers | KEY_PGDN;
|
case 6: return modifiers | KEY_PGDN;
|
||||||
case 7: return modifiers | KEY_HOME;
|
case 7: return modifiers | KEY_HOME;
|
||||||
case 8: return modifiers | KEY_END;
|
case 8: return modifiers | KEY_END;
|
||||||
case 10: return modifiers | KEY_F0;
|
case 10: return modifiers | KEY_F0;
|
||||||
case 11: return modifiers | KEY_F1;
|
case 11: return modifiers | KEY_F1;
|
||||||
case 12: return modifiers | KEY_F2;
|
case 12: return modifiers | KEY_F2;
|
||||||
case 13: return modifiers | KEY_F3;
|
case 13: return modifiers | KEY_F3;
|
||||||
case 14: return modifiers | KEY_F4;
|
case 14: return modifiers | KEY_F4;
|
||||||
case 15: return modifiers | KEY_F5;
|
case 15: return modifiers | KEY_F5;
|
||||||
case 17: return modifiers | KEY_F6;
|
case 17: return modifiers | KEY_F6;
|
||||||
case 18: return modifiers | KEY_F7;
|
case 18: return modifiers | KEY_F7;
|
||||||
case 19: return modifiers | KEY_F8;
|
case 19: return modifiers | KEY_F8;
|
||||||
case 20: return modifiers | KEY_F9;
|
case 20: return modifiers | KEY_F9;
|
||||||
case 21: return modifiers | KEY_F10;
|
case 21: return modifiers | KEY_F10;
|
||||||
case 23: return modifiers | KEY_F11;
|
case 23: return modifiers | KEY_F11;
|
||||||
case 24: return modifiers | KEY_F12;
|
case 24: return modifiers | KEY_F12;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
case '<': { // Mouse clicks
|
case '<': { // Mouse clicks
|
||||||
int buttons = 0, x = 0, y = 0;
|
int buttons = 0, x = 0, y = 0;
|
||||||
c = nextnum(fd, nextchar(fd), &buttons);
|
c = nextnum(fd, nextchar(fd), &buttons);
|
||||||
if (c != ';') return -1;
|
if (c != ';') return -1;
|
||||||
c = nextnum(fd, nextchar(fd), &x);
|
c = nextnum(fd, nextchar(fd), &x);
|
||||||
if (c != ';') return -1;
|
if (c != ';') return -1;
|
||||||
c = nextnum(fd, nextchar(fd), &y);
|
c = nextnum(fd, nextchar(fd), &y);
|
||||||
if (c != 'm' && c != 'M') return -1;
|
if (c != 'm' && c != 'M') return -1;
|
||||||
|
|
||||||
if (mouse_x) *mouse_x = x - 1;
|
if (mouse_x) *mouse_x = x - 1;
|
||||||
if (mouse_y) *mouse_y = y - 1;
|
if (mouse_y) *mouse_y = y - 1;
|
||||||
|
|
||||||
if (buttons & 4) modifiers |= MOD_SHIFT;
|
if (buttons & 4) modifiers |= MOD_SHIFT;
|
||||||
if (buttons & 8) modifiers |= MOD_META;
|
if (buttons & 8) modifiers |= MOD_META;
|
||||||
if (buttons & 16) modifiers |= MOD_CTRL;
|
if (buttons & 16) modifiers |= MOD_CTRL;
|
||||||
int key = -1;
|
int key = -1;
|
||||||
switch (buttons & ~(4|8|16)) {
|
switch (buttons & ~(4|8|16)) {
|
||||||
case 0: key = c == 'm' ? MOUSE_LEFT_RELEASE : MOUSE_LEFT_PRESS; break;
|
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 1: key = c == 'm' ? MOUSE_MIDDLE_RELEASE : MOUSE_MIDDLE_PRESS; break;
|
||||||
case 2: key = c == 'm' ? MOUSE_RIGHT_RELEASE : MOUSE_RIGHT_PRESS; break;
|
case 2: key = c == 'm' ? MOUSE_RIGHT_RELEASE : MOUSE_RIGHT_PRESS; break;
|
||||||
case 32: key = MOUSE_LEFT_DRAG; break;
|
case 32: key = MOUSE_LEFT_DRAG; break;
|
||||||
case 33: key = MOUSE_MIDDLE_DRAG; break;
|
case 33: key = MOUSE_MIDDLE_DRAG; break;
|
||||||
case 34: key = MOUSE_RIGHT_DRAG; break;
|
case 34: key = MOUSE_RIGHT_DRAG; break;
|
||||||
case 64: key = MOUSE_WHEEL_RELEASE; break;
|
case 64: key = MOUSE_WHEEL_RELEASE; break;
|
||||||
case 65: key = MOUSE_WHEEL_PRESS; break;
|
case 65: key = MOUSE_WHEEL_PRESS; break;
|
||||||
default: return -1;
|
default: return -1;
|
||||||
}
|
}
|
||||||
if (key == MOUSE_LEFT_RELEASE || key == MOUSE_RIGHT_RELEASE || key == MOUSE_MIDDLE_RELEASE) {
|
if (key == MOUSE_LEFT_RELEASE || key == MOUSE_RIGHT_RELEASE || key == MOUSE_MIDDLE_RELEASE) {
|
||||||
static int lastclick = -1;
|
static int lastclick = -1;
|
||||||
static struct timespec lastclicktime = {0, 0};
|
static struct timespec lastclicktime = {0, 0};
|
||||||
struct timespec clicktime;
|
struct timespec clicktime;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &clicktime);
|
clock_gettime(CLOCK_MONOTONIC, &clicktime);
|
||||||
if (key == lastclick) {
|
if (key == lastclick) {
|
||||||
double dt_ms = 1e3*(double)(clicktime.tv_sec - lastclicktime.tv_sec)
|
double dt_ms = 1e3*(double)(clicktime.tv_sec - lastclicktime.tv_sec)
|
||||||
+ 1e-6*(double)(clicktime.tv_nsec - lastclicktime.tv_nsec);
|
+ 1e-6*(double)(clicktime.tv_nsec - lastclicktime.tv_nsec);
|
||||||
if (dt_ms < DOUBLECLICK_THRESHOLD) {
|
if (dt_ms < DOUBLECLICK_THRESHOLD) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case MOUSE_LEFT_RELEASE: key = MOUSE_LEFT_DOUBLE; break;
|
case MOUSE_LEFT_RELEASE: key = MOUSE_LEFT_DOUBLE; break;
|
||||||
case MOUSE_RIGHT_RELEASE: key = MOUSE_RIGHT_DOUBLE; break;
|
case MOUSE_RIGHT_RELEASE: key = MOUSE_RIGHT_DOUBLE; break;
|
||||||
case MOUSE_MIDDLE_RELEASE: key = MOUSE_MIDDLE_DOUBLE; break;
|
case MOUSE_MIDDLE_RELEASE: key = MOUSE_MIDDLE_DOUBLE; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastclicktime = clicktime;
|
|
||||||
lastclick = key;
|
|
||||||
}
|
}
|
||||||
return modifiers | key;
|
lastclicktime = clicktime;
|
||||||
|
lastclick = key;
|
||||||
}
|
}
|
||||||
default:
|
return modifiers | key;
|
||||||
if ('0' <= c && c <= '9') {
|
}
|
||||||
// Ps prefix
|
default:
|
||||||
c = nextnum(fd, c, &numcode);
|
if ('0' <= c && c <= '9') {
|
||||||
if (c == ';') {
|
// Ps prefix
|
||||||
c = nextnum(fd, nextchar(fd), &modifiers);
|
c = nextnum(fd, c, &numcode);
|
||||||
modifiers = (modifiers >> 1) << MOD_BITSHIFT;
|
if (c == ';') {
|
||||||
}
|
c = nextnum(fd, nextchar(fd), &modifiers);
|
||||||
goto CSI_start;
|
modifiers = (modifiers >> 1) << MOD_BITSHIFT;
|
||||||
}
|
}
|
||||||
|
goto CSI_start;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -213,11 +213,11 @@ int bgetkey(FILE *in, int *mouse_x, int *mouse_y)
|
|||||||
|
|
||||||
SS3:
|
SS3:
|
||||||
switch (nextchar(fd)) {
|
switch (nextchar(fd)) {
|
||||||
case 'P': return KEY_F1;
|
case 'P': return KEY_F1;
|
||||||
case 'Q': return KEY_F2;
|
case 'Q': return KEY_F2;
|
||||||
case 'R': return KEY_F3;
|
case 'R': return KEY_F3;
|
||||||
case 'S': return KEY_F4;
|
case 'S': return KEY_F4;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -267,4 +267,4 @@ int bkeywithname(const char *name)
|
|||||||
}
|
}
|
||||||
return strlen(name) == 1 ? name[0] : -1;
|
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
|
||||||
|
@ -83,4 +83,4 @@ char *bkeyname(int key, char *buf);
|
|||||||
int bkeywithname(const char *name);
|
int bkeywithname(const char *name);
|
||||||
|
|
||||||
#endif
|
#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
|
||||||
|
2
types.h
2
types.h
@ -86,4 +86,4 @@ typedef struct {
|
|||||||
} binding_t;
|
} binding_t;
|
||||||
|
|
||||||
#endif
|
#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
|
||||||
|
2
utils.c
2
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
|
||||||
|
Loading…
Reference in New Issue
Block a user