/* * Read character */ getchar() { char c; if(!standalone) { return(unix_read_char(0, &c, 1)) ; } else { while (!char_ready) thread_switch(MACH_PORT_NULL, SWITCH_OPTION_DEPRESS, 0); char_ready = FALSE; return(cur_char); } }
/* Read one line, including the newline, into s. Safely avoids buffer * overruns (but that's kind of pointless because there are several * other places where I'm not so careful). */ static void zgetline(char *s) { int c = 0; char *p = s; iphone_enable_input(); while (p < s + INPUT_BUFFER_SIZE - 1) // if ((c = iphone_getchar(timeout_to_ms())) != '\n') if ((c = unix_read_char(0)) != '\n' && c != ZC_RETURN) { if (c == -1) { c = ZC_TIME_OUT; break; } if (c == ZC_AUTOSAVE) { do_autosave = 1; break; } if (c == ZC_BACKSPACE && p > s) p--; else if (c == ZC_ESCAPE) { *p = 0; if (p > s) { if (*--p == ' ' || ispunct(*p)) *p = 0; } while (p > s && *p != ' ' && !ispunct(*p)) p--; if (p != s) p++; } else *p++ = c; } else break; if (c == ZC_AUTOSAVE) *p++ = c; else *p++ = '\n'; *p++ = '\0'; iphone_disable_input(); if (c == ZC_TIME_OUT || p < s + INPUT_BUFFER_SIZE - 1) return; while (iphone_getchar(-1) != '\n') ; printf("Line too long, truncated to %s\n", s - INPUT_BUFFER_SIZE); }
zchar os_read_key (int timeout, int cursor) { zchar c; // if (!cursor) curs_set(0); //xxx iphone_enable_single_key_input(); unix_set_global_timeout(timeout); c = (zchar) unix_read_char(0); if (cwin == 1 && c == ZC_BACKSPACE) { iphone_backspace(); iphone_putchar(c); } iphone_disable_input(); // if (!cursor) curs_set(1); //xxx return c; }/* os_read_key */