Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
- #define L1LEFT "[# .]\n"
- #define L1RIGHT "[. #]\n"
- #define L1NONE "[. .]\n"
- char *l1res_str[6] = {
- L1LEFT L1NONE L1NONE,
- L1RIGHT L1NONE L1NONE,
- L1NONE L1LEFT L1NONE,
- L1NONE L1RIGHT L1NONE,
- L1NONE L1NONE L1LEFT,
- L1NONE L1NONE L1RIGHT
- };
- int
- streq(char *s1, char *s2)
- {
- size_t l1 = strlen(s1);
- size_t l2 = strlen(s2);
- if(l1 != l2)
- return 0;
- for(size_t i = 0; i < l1; i++)
- if(tolower(s1[i]) != tolower(s2[i]))
- return 0;
- return 1;
- }
- int
- lookup_1(char *word)
- {
- char *table[6][10] = {
- {"ur", NULL},
- {"first", "okay", "c", NULL},
- {"yes", "nothing", "led", "they are", NULL},
- {"blank", "read", "red", "you", "your", "you're", "their", NULL},
- {"", "reed", "leed", "they're", NULL},
- {"display", "says", "no", "lead", "hold on", "you are", "there", "see", "cee", NULL}
- };
- for(size_t i = 0; i < 6; i++)
- for(char **selrow = table[i]; *selrow != NULL; selrow++)
- if(streq(word, *selrow))
- return i;
- return -1;
- }
- void
- s2_get_input(char *out)
- {
- int ch;
- for(size_t i = 0; i < 7; i++){
- ch = getchar();
- if(isspace(ch) && ch != ' ')
- break;
- *out++ = ch;
- }
- *out = '\0';
- }
- void
- s2_print_row(char **row)
- {
- puts("Input the first word that matches your six face buttons\n");
- for(size_t i = 0; i < 14; i++)
- printf(" %s\n", row[i]);
- }
- void
- step_2(void)
- {
- char response[8] = "";
- char *table[28][15] = {
- { "ready", "yes", "okay", "what", "middle", "left", "press", "right", "blank", "ready", "no", "first", "uhhh", "nothing", "wait" },
- { "first", "left", "okay", "yes", "middle", "no", "right", "nothing", "uhhh", "wait", "ready", "blank", "what", "press", "first" },
- { "no", "blank", "uhhh", "wait", "first", "what", "ready", "right", "yes", "nothing", "left", "press", "okay", "no", "middle" },
- { "blank", "wait", "right", "okay", "middle", "blank", "press", "ready", "nothing", "no", "what", "left", "uhhh", "yes", "first" },
- { "nothing", "uhhh", "right", "okay", "middle", "yes", "blank", "no", "press", "left", "what", "wait", "first", "nothing", "ready" },
- { "yes", "okay", "right", "uhhh", "middle", "first", "what", "press", "ready", "nothing", "yes", "left", "blank", "no", "wait" },
- { "what", "uhhh", "what", "left", "nothing", "ready", "blank", "middle", "no", "okay", "first", "wait", "yes", "press", "right" },
- { "uhhh", "ready", "nothing", "left", "what", "okay", "yes", "right", "no", "press", "blank", "uhhh", "middle", "wait", "first" },
- { "left", "right", "left", "first", "no", "middle", "yes", "blank", "what", "uhhh", "wait", "press", "ready", "okay", "nothing" },
- { "right", "yes", "nothing", "ready", "press", "no", "wait", "what", "right", "middle", "left", "uhhh", "blank", "okay", "first" },
- { "middle", "blank", "ready", "okay", "what", "nothing", "press", "no", "wait", "left", "middle", "right", "first", "uhhh", "yes" },
- { "okay", "middle", "no", "first", "yes", "uhhh", "nothing", "wait", "okay", "left", "ready", "blank", "press", "what", "right" },
- { "wait", "uhhh", "no", "blank", "okay", "yes", "left", "first", "press", "what", "wait", "nothing", "ready", "right", "middle" },
- { "press", "right", "middle", "yes", "ready", "press", "okay", "nothing", "uhhh", "blank", "left", "first", "what", "no", "wait" },
- { "you", "sure", "you are", "your", "you're", "next", "uh huh", "ur", "hold", "what?", "you", "uh uh", "like", "done", "u" },
- { "you are", "your", "next", "like", "uh huh", "what?", "done", "uh uh", "hold", "you", "u", "you're", "sure", "ur", "you are" },
- { "your", "uh uh", "you are", "uh huh", "your", "next", "ur", "sure", "u", "you're", "you", "what?", "hold", "like", "done" },
- { "you're", "you", "you're", "ur", "next", "uh uh", "you are", "u", "your", "what?", "uh huh", "sure", "done", "like", "hold" },
- { "ur", "done", "u", "ur", "uh huh", "what?", "sure", "your", "hold", "you're", "like", "next", "uh uh", "you are", "you" },
- { "u", "uh huh", "sure", "next", "what?", "you're", "ur", "uh uh", "done", "u", "you", "like", "hold", "you are", "your" },
- { "uh huh", "uh huh", "your", "you are", "you", "done", "hold", "uh uh", "next", "sure", "like", "you're", "ur", "u", "what?" },
- { "uh uh", "ur", "u", "you are", "you're", "next", "uh uh", "done", "you", "uh huh", "like", "your", "sure", "hold", "what?" },
- { "what?", "you", "hold", "you're", "your", "u", "done", "uh uh", "like", "you are", "uh huh", "ur", "next", "what?", "sure" },
- { "done", "sure", "uh huh", "next", "what?", "your", "ur", "you're", "hold", "like", "you", "u", "you are", "uh uh", "done" },
- { "next", "what?", "uh huh", "uh uh", "your", "hold", "sure", "next", "like", "done", "you are", "ur", "you're", "u", "you" },
- { "hold", "you are", "u", "done", "uh uh", "you", "ur", "sure", "what?", "you're", "next", "hold", "uh huh", "your", "like" },
- { "sure", "you are", "done", "like", "you're", "you", "hold", "uh huh", "ur", "sure", "u", "what?", "next", "your", "uh uh" },
- { "like", "you're", "next", "u", "ur", "hold", "done", "uh uh", "what?", "uh huh", "you", "like", "sure", "you are", "your" }
- };
- printf("Response? >");
- s2_get_input(response);
- for(size_t i = 0; i < 28; i++)
- if(streq(response, table[i][0])){
- s2_print_row(table[i] + 1);
- return;
- }
- printf("No matches for '%s'. Are you sure you typed it correctly?\n", response);
- }
- void
- usage(void)
- {
- puts("Usage: whosonfirst <word on display>");
- puts("Follow the prompts");
- exit(1);
- }
- int
- main(int argc, char **argv)
- {
- int response;
- if(argv[1] == NULL)
- usage();
- response = lookup_1(argv[1]);
- if(response == -1){
- printf("Nothing for '%s'. Did you misspell it?\n", argv[1]);
- return 1;
- }
- printf("\"%s\" : %i\n%s", argv[1], response, l1res_str[response]);
- step_2();
- return 0;
- }
Add Comment
Please, Sign In to add comment