int getCommands() { printf("Welcome to the Keyboard Layout Optimizer. If you have questions or comments, contact Michael Dickens by email ([email protected]) or leave a comment at http://mathematicalmulticore.wordpress.com/category/keyboards/.\n"); printf("Type \"help\" for a listing of commands.\n\n"); int length = 5000; char cmd[length]; do { printf(">>> "); fgets(cmd, length, stdin); cmd[strlen(cmd)-1] = '\0'; // Remove the newline. if (streq(cmd, "help")) { printf("algorithm: Run the keyboard optimization algorithm.\n"); printf("best swap <filename>: For the first layout in <filename>, print the single swap that would improve the layout the most.\n"); printf("compare <filename>: Print information about the keyboards in <filename>. The keyboards must be in the proper format.\n"); printf("damaging <filename>: Find the most damaging digraphs for the keyboard layouts in <filename>.\n"); printf("game: Play a keyboard layout game.\n"); printf("get <variable>: Get the value of the specified variable.\n"); printf("improve <filename>: Try to improve the first keyboard in <filename>. The keyboard must be in the proper format.\n"); printf("make typing data: Use the files in freq_types to customize character and digraph frequency.\n"); printf("set <variable> <value>: Set the specified variable to the given value.\n"); printf("setksize <fk_setting>: Set the keyboard type. Type \"setksize help\" for more information.\n"); printf("test fitness: Test that the fitness functions are working properly.\n"); printf("use <keys>: Use <keys> in the keyboard layout instead of the default.\n"); printf("worst <filename>: Find the worst digraphs for the keyboard layouts in <filename>.\n"); printf("variables: Print all variables that can be modified.\n"); printf("quit: Quit the keyboard optimization program.\n"); printf("\n"); } else if (streq(cmd, "algorithm")) { printf("Running the keyboard optimization algorithm. Press ctrl-C to abort.\n\n"); runCJAlgorithm(kbdFilename); } else if (streqn(cmd, "best swap ", strlen("best swap "))) { char *filename = cmd + strlen("best swap "); FILE *fp = fopen(filename, "r"); Keyboard k; if (layoutFromFile(fp, &k) != -1) { layoutFromFile(fp, &k); bestSwap(&k); } fclose(fp); } else if (streqn(cmd, "compare ", 8)) { compare(cmd + 8); } else if (streqn(cmd, "damaging ", 9)) { char *filename = cmd + 9; worstDigraphsFromFile(filename, TRUE); } else if (streq(cmd, "game")) { game(); } else if (streqn(cmd, "get ", 4)) { getValue(cmd + 4); } else if (streqn(cmd, "improve ", strlen("improve "))) { improveFromFile(cmd + 8); } else if (streq(cmd, "make typing data")) { makeTypingData(); } else if (streqn(cmd, "set ", strlen("set "))) { setValue(cmd + 4); } else if (streqn(cmd, "setksize ", strlen("setksize "))) { size_t str_len = strlen("setksize "); if (streq(cmd + str_len, "no")) { setksize(FK_NO); printf("Keyboard set to non-full. All user-defined values have been reset.\n\n"); } else if (streq(cmd + str_len, "standard")) { setksize(FK_STANDARD); printf("Keyboard set to full standard. All user-defined values have been reset.\n\n"); } else if (streq(cmd + str_len, "kinesis")) { setksize(FK_KINESIS); printf("Keyboard set to full Kinesis. All user-defined values have been reset.\n\n"); } else if (streq(cmd + str_len, "iphone")) { setksize(FK_IPHONE); printf("Keyboard set to iPhone. All user-defined values have been reset.\n\n"); } else if (streq(cmd+6, "bs4822")) { setksize(FK_BS4822); printf("Keyboard set to British Standard BS 4822. All user-defined values have been reset.\n\n"); } else { printf("Undefined input. Valid inputs: \"setksize no\" (do not use full keyboard), \"setksize standard\" (use standard full keyboard), \"setksize kinesis\" (use Kinesis full keyboard), \"setksize bs4822\" (use BS 4822 full keyboard).\n\n"); } } else if (streq(cmd, "test fitness")) { testFitness(); } else if (streqn(cmd, "use ", 4)) { strcpy(keysToInclude, cmd + 4); initTypingData(); printf("Now using keys: %s\n\n", cmd + 4); } else if (streq(cmd, "variables")) { printf("Boolean variables should be set to 0 for false and 1 for true. Variables not specified as booleans are integers.\n"); printf("\t(bool) detailedOutput : provide additional information while running the algorithm\n"); printf("\t(bool) keepZXCV : keep keys Z, X, C, and V in place\n"); printf("\t(bool) keepQWERTY : try to keep keys in their QWERTY positions\n"); printf("\t(bool) keepNumbers : keep numbers in place\n"); printf("\t(bool) keepBrackets : keep brackets symmetrical\n"); printf("\t(bool) keepShiftPairs : shifted/unshifted pairs of special characters stay together\n"); printf("\t(bool) keepTab : keep Tab in place\n"); printf("\t(bool) keepNumbersShifted: numbers do not move between shifted and unshifted\n"); printf("\nThese variables determine the costs for particular key combinations. Higher cost is worse.\n"); printf("\tdistance\n"); printf("\tinRoll\n"); printf("\toutRoll\n"); printf("\tsameHand\n"); printf("\tsameFingerP\n"); printf("\tsameFingerR\n"); printf("\tsameFingerM\n"); printf("\tsameFingerI\n"); printf("\trowChangeUp\n"); printf("\trowChangeDown\n"); printf("\thandWarp\n"); printf("\thandSmooth\n"); printf("\thomeJump\n"); printf("\thomeJumpIndex\n"); printf("\tdoubleJump\n"); printf("\ttoCenter\n"); printf("\ttoOutside\n"); } else if (streqn(cmd, "worst ", 6)) { char *filename = cmd + 6; worstDigraphsFromFile(filename, FALSE); } else if (streq(cmd, "quit")) { printf("Goodbye!\n"); break; } else { printf("Unknown command. Type \"help\" for a listing of commands.\n\n"); } } while (strcmp(cmd, "exit") != 0); return 0; }
int getCommands() { printf("Welcome to the Keyboard Layout Optimizer. If you have questions or comments, contact Michael Dickens by email ([email protected]) or leave a comment at http://mathematicalmulticore.wordpress.com/category/keyboards/.\n"); printf("Type \"help\" for a listing of commands.\n\n"); int length = 5000; char cmd[length]; do { printf(">>> "); fgets(cmd, length, stdin); cmd[strlen(cmd)-1] = '\0'; // Remove the newline. if (streq(cmd, "help")) { printf("algorithm: Run the keyboard optimization algorithm.\n"); printf("best swap <filename>: For the first layout in <filename>, print the single swap that would improve the layout the most.\n"); printf("compare <filename>: Print information about the keyboards in <filename>. The keyboards must be in the proper format.\n"); printf("damaging <filename>: Find the most damaging digraphs for the keyboard layouts in <filename>.\n"); printf("game: Play a keyboard layout game.\n"); printf("get <variable>: Get the value of the specified variable.\n"); printf("improve <filename>: Try to improve the first keyboard in <filename>. The keyboard must be in the proper format.\n"); printf("make typing data: Use the files in freq_types to customize character and digraph frequency.\n"); printf("run: See 'algorithm'.\n"); printf("set <variable> <value>: Set the specified variable to the given value.\n"); printf("setksize <K_setting>: Set the keyboard type. Type \"setksize help\" for more information.\n"); printf("test fitness: Test that the fitness functions are working properly.\n"); printf("use <keys>: Use <keys> in the keyboard layout instead of the default.\n"); printf("worst <filename>: Find the worst digraphs for the keyboard layouts in <filename>.\n"); printf("variables: Print all variables that can be modified.\n"); printf("quit: Quit the keyboard optimization program.\n"); printf("\n"); } else if (streq(cmd, "algorithm") || streq(cmd, "run")) { printf("Running the keyboard optimization algorithm. Press ctrl-C to quit.\n\n"); runAlgorithm(); } else if (streqn(cmd, "best swap ", strlen("best swap "))) { const char *const filename = cmd + strlen("best swap "); FILE *file = fopen(filename, "r"); CHECK_FILE_FOR_NULL(file, filename); Keyboard k; if (layoutFromFile(file, &k) != -1) { bestSwap(&k); } fclose(file); } else if (streqn(cmd, "compare ", 8)) { compare(cmd + 8); } else if (streqn(cmd, "damaging ", 9)) { const char *const filename = cmd + 9; worstDigraphsFromFile(filename, TRUE); } else if (streq(cmd, "game")) { game(); } else if (streqn(cmd, "get ", 4)) { getValue(cmd + 4); } else if (streqn(cmd, "improve ", strlen("improve "))) { improveFromFile(cmd + 8); } else if (streq(cmd, "make typing data")) { makeTypingData(); } else if (streqn(cmd, "set ", strlen("set "))) { setValue(cmd + 4); } else if (streqn(cmd, "setksize ", strlen("setksize "))) { size_t str_len = strlen("setksize "); if (streq(cmd + str_len, "no")) { setksize(K_NO); printf("Keyboard set to non-full. All user-defined values have been reset.\n\n"); } else if (streq(cmd + str_len, "standard")) { setksize(K_STANDARD); printf("Keyboard set to full standard. All user-defined values have been reset.\n\n"); } else if (streq(cmd + str_len, "kinesis")) { setksize(K_KINESIS); printf("Keyboard set to full Kinesis. All user-defined values have been reset.\n\n"); } else if (streq(cmd + str_len, "iphone")) { setksize(K_IPHONE); printf("Keyboard set to iPhone. All user-defined values have been reset.\n\n"); } else { printf("Undefined input. Valid inputs: \"setksize no\" (do not use full keyboard), \"setksize standard\" (use standard full keyboard), \"setksize kinesis\" (use Kinesis full keyboard).\n\n"); } } else if (streq(cmd, "test fitness")) { testFitness(); } else if (streqn(cmd, "use ", 4)) { strcpy(keysToInclude, cmd + 4); initTypingData(); printf("Now using keys: %s\n\n", cmd + 4); } else if (streq(cmd, "variables")) { printf("Boolean variables should be set to 0 for false and 1 for true. Variables not specified as booleans are integers.\n"); int i; for (i = 0; i < variablesLength; ++i) { printf("\t%s", variables[i].name); if (variables[i].description) printf(": %s", variables[i].description); printf("\n"); } printf("\n"); } else if (streqn(cmd, "worst ", 6)) { const char *const filename = cmd + 6; worstDigraphsFromFile(filename, FALSE); } else if (streq(cmd, "quit")) { printf("Goodbye!\n"); break; } else { printf("Unknown command. Type \"help\" for a listing of commands.\n\n"); } } while (strcmp(cmd, "exit") != 0); return 0; }