Getting rid of that ugly switch statement

modified:   src/nms.c
This commit is contained in:
Brian Barto 2016-04-07 14:27:27 -04:00
parent 72bf59301a
commit 420987a544

View File

@ -29,43 +29,32 @@ int main(void) {
int c, x = 1, y = 1; int c, x = 1, y = 1;
bool first = true; bool first = true;
while ((c = getchar()) != EOF) { while ((c = getchar()) != EOF) {
switch (c) { if (c == NEWLINE) {
case '\n': ++y;
++y; x = 1;
x = 1; } else if (isspace(c)) {
break; ++x;
case ' ': } else if (first) {
case '\t': start.source = c;
case '\f': start.row = y;
case '\r': start.col = x;
case '\v': start.next = (struct winpos *) 0;
++x; first = false;
break; ++x;
default: } else {
if (first) { // Allocate space for the new struct in our linked list
start.source = c; // and point *next to it.
start.row = y; list_pointer->next = malloc(sizeof(struct winpos));
start.col = x;
start.next = (struct winpos *) 0;
first = false;
++x;
} else {
// Allocate space for the new struct in our linked list
// and point *next to it.
list_pointer->next = malloc(sizeof(struct winpos));
// Now let's point list_pointer to the next structure // Now let's point list_pointer to the next structure
// and populate it. // and populate it.
list_pointer = list_pointer->next; list_pointer = list_pointer->next;
list_pointer->source = c; list_pointer->source = c;
list_pointer->row = y; list_pointer->row = y;
list_pointer->col = x; list_pointer->col = x;
list_pointer->next = (struct winpos *) 0; list_pointer->next = (struct winpos *) 0;
++x;
}
break;
++x;
} }
} }