I've been trying to replace my current VICE-based read_input() function (which is weird and not cross-platform) with a much simpler one. The goal of the function (called once every 2048 nodes searched) is to read the current buffer, and if the user/GUI entered anything, respond appropriately. This is what I have so far:
Code: Select all
void read_input() {
char input[256];
if (!fgets(input, 256, stdin)) return;
// replace first newline with terminating character:
char* endc = strchr(input, '\n');
if (endc) *endc = 0;
// if nothing was entered, return:
if (!strlen(input)) return;
// if the user entered something, stop the search:
stop_search = true;
// if the user typed 'quit' or 'stop', quit the program:
if (!strncmp(input, "quit", 4) || !strncmp(input, "stop", 4)) {
quit_flag = true;
}
}
- Ori
