/* Read a line, processing commands (lines that start with a backslash * (that isn't the start of a special character)), and write the * first non-command to s. * Return true if timed-out. */ static bool ui_read_line(char *s, char *prompt, bool show_cursor, int timeout, enum input_type type, zchar *continued_line_chars) { unix_set_global_timeout(timeout); if (prompt) iphone_puts(prompt); zgetline(s); translate_special_chars(s); if (*s == ZC_AUTOSAVE) return FALSE; if (*s == ZC_TIME_OUT) return TRUE; return FALSE; }
/* Read a line, processing commands (lines that start with a backslash * (that isn't the start of a special character)), and write the * first non-command to s. * Return true if timed-out. */ static bool dumb_read_line(char *s, char *prompt, bool show_cursor, int timeout, enum input_type type, zchar *continued_line_chars) { time_t start_time; if (timeout) { if (time_ahead >= timeout) { time_ahead -= timeout; return TRUE; } timeout -= time_ahead; start_time = time(0); } time_ahead = 0; dumb_show_screen(show_cursor); for (;;) { char *command; if (prompt) fputs(prompt, stdout); else dumb_show_prompt(show_cursor, (timeout ? "tTD" : ")>}")[type]); getline_(s); if ((s[0] != '\\') || ((s[1] != '\0') && !islower(s[1]))) { /* Is not a command line. */ translate_special_chars(s); if (timeout) { int elapsed = (time(0) - start_time) * 10 * speed; if (elapsed > timeout) { time_ahead = elapsed - timeout; return TRUE; } } return FALSE; } /* Commands. */ /* Remove the \ and the terminating newline. */ command = s + 1; command[strlen(command) - 1] = '\0'; if (!strcmp(command, "t")) { if (timeout) { time_ahead = 0; s[0] = '\0'; return TRUE; } } else if (*command == 'w') { if (timeout) { int elapsed = atoi(&command[1]); time_t now = time(0); if (elapsed == 0) elapsed = (now - start_time) * 10 * speed; if (elapsed >= timeout) { time_ahead = elapsed - timeout; s[0] = '\0'; return TRUE; } timeout -= elapsed; start_time = now; } } else if (!strcmp(command, "d")) { if (type != INPUT_LINE_CONTINUED) fprintf(stderr, "DUMB-FROTZ: No input to discard\n"); else { dumb_discard_old_input(strlen((char *) continued_line_chars)); continued_line_chars[0] = '\0'; type = INPUT_LINE; } } else if (!strcmp(command, "help")) { if (!do_more_prompts) fputs(runtime_usage, stdout); else { char *current_page, *next_page; current_page = next_page = runtime_usage; for (;;) { int i; for (i = 0; (i < h_screen_rows - 2) && *next_page; i++) next_page = strchr(next_page, '\n') + 1; printf("%.*s", (int) (next_page - current_page), current_page); current_page = next_page; if (!*current_page) break; printf("HELP: Type <return> for more, or q <return> to stop: "); getline_(s); if (!strcmp(s, "q\n")) break; } } } else if (!strcmp(command, "s")) { dumb_dump_screen(); } else if (!dumb_handle_setting(command, show_cursor, FALSE)) { fprintf(stderr, "DUMB-FROTZ: unknown command: %s\n", s); fprintf(stderr, "Enter \\help to see the list of commands\n"); } } }