Skip to content

Commit

Permalink
vis-menu: reduce indentation level of switch statements
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed May 29, 2016
1 parent 8bd8422 commit 2ac0721
Showing 1 changed file with 78 additions and 74 deletions.
152 changes: 78 additions & 74 deletions vis-menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,85 +369,89 @@ run(void) {
xread(0, &c, 1);
esc_switch_top:
switch(c) {
case CONTROL('['): /* ESC, need to press twice due to console limitations */
c = CONTROL('C');
case CONTROL('['): /* ESC, need to press twice due to console limitations */
c = CONTROL('C');
goto switch_top;
case '[':
xread(0, &c, 1);
switch(c) {
case '1': /* Home */
case '7':
case 'H':
if (c != 'H') xread(0, &c, 1); /* Remove trailing '~' from stdin */
c = CONTROL('A');
goto switch_top;
case '[':
xread(0, &c, 1);
switch(c) {
case '1': /* Home */
case '7':
case 'H':
if (c != 'H') xread(0, &c, 1); /* Remove trailing '~' from stdin */
c = CONTROL('A');
goto switch_top;
case '3': /* Delete */
xread(0, &c, 1); /* Remove trailing '~' from stdin */
c = CONTROL('D');
goto switch_top;
case '4': /* End */
case '8':
case 'F':
if (c != 'F') xread(0, &c, 1); /* Remove trailing '~' from stdin */
c = CONTROL('E');
goto switch_top;
case '5': /* PageUp */
xread(0, &c, 1); /* Remove trailing '~' from stdin */
c = CONTROL('V');
goto switch_top;
case '6': /* PageDown */
xread(0, &c, 1); /* Remove trailing '~' from stdin */
c = 'v';
goto esc_switch_top;
case 'A': /* Up arrow */
c = CONTROL('P');
goto switch_top;
case 'B': /* Down arrow */
c = CONTROL('N');
goto switch_top;
case 'C': /* Right arrow */
c = CONTROL('F');
goto switch_top;
case 'D': /* Left arrow */
c = CONTROL('B');
goto switch_top;
}
break;
case 'b':
while (cursor > 0 && text[nextrune(-1)] == ' ')
cursor = nextrune(-1);
while (cursor > 0 && text[nextrune(-1)] != ' ')
cursor = nextrune(-1);
break;
case 'f':
while (text[cursor] != '\0' && text[nextrune(+1)] == ' ')
case '2': /* Insert */
xread(0, &c, 1); /* Remove trailing '~' from stdin */
c = CONTROL('Y');
goto switch_top;
case '3': /* Delete */
xread(0, &c, 1); /* Remove trailing '~' from stdin */
c = CONTROL('D');
goto switch_top;
case '4': /* End */
case '8':
case 'F':
if (c != 'F') xread(0, &c, 1); /* Remove trailing '~' from stdin */
c = CONTROL('E');
goto switch_top;
case '5': /* PageUp */
xread(0, &c, 1); /* Remove trailing '~' from stdin */
c = CONTROL('V');
goto switch_top;
case '6': /* PageDown */
xread(0, &c, 1); /* Remove trailing '~' from stdin */
c = 'v';
goto esc_switch_top;
case 'A': /* Up arrow */
c = CONTROL('P');
goto switch_top;
case 'B': /* Down arrow */
c = CONTROL('N');
goto switch_top;
case 'C': /* Right arrow */
c = CONTROL('F');
goto switch_top;
case 'D': /* Left arrow */
c = CONTROL('B');
goto switch_top;
}
break;
case 'b':
while (cursor > 0 && text[nextrune(-1)] == ' ')
cursor = nextrune(-1);
while (cursor > 0 && text[nextrune(-1)] != ' ')
cursor = nextrune(-1);
break;
case 'f':
while (text[cursor] != '\0' && text[nextrune(+1)] == ' ')
cursor = nextrune(+1);
if (text[cursor] != '\0') {
do {
cursor = nextrune(+1);
if (text[cursor] != '\0') {
do {
cursor = nextrune(+1);
} while (text[cursor] != '\0' && text[cursor] != ' ');
}
break;
case 'd':
while (text[cursor] != '\0' && text[nextrune(+1)] == ' ') {
} while (text[cursor] != '\0' && text[cursor] != ' ');
}
break;
case 'd':
while (text[cursor] != '\0' && text[nextrune(+1)] == ' ') {
cursor = nextrune(+1);
insert(NULL, nextrune(-1) - cursor);
}
if (text[cursor] != '\0') {
do {
cursor = nextrune(+1);
insert(NULL, nextrune(-1) - cursor);
}
if (text[cursor] != '\0') {
do {
cursor = nextrune(+1);
insert(NULL, nextrune(-1) - cursor);
} while (text[cursor] != '\0' && text[cursor] != ' ');
}
break;
case 'v':
if (!next)
break;
sel = curr = next;
calcoffsets();
break;
default:
} while (text[cursor] != '\0' && text[cursor] != ' ');
}
break;
case 'v':
if (!next)
break;
sel = curr = next;
calcoffsets();
break;
default:
break;
}
break;
case CONTROL('C'):
Expand Down

0 comments on commit 2ac0721

Please sign in to comment.