/* Get the next character from the terminal - performs table lookup on the character to do the desired translation */ static unsigned int input_char() { unsigned c; if ((c=t_gnc()) <= 599) { /* IBM generates codes up to 260 */ c = do_smap(c); } else if (c > 1000) { /* stuffed function */ c -= 1000; /* convert back to function code */ } if (c <= 0) { t_honk_horn(); } /* if we got a screen size escape sequence, read height, width */ if (c == F_SCRSIZ) { t_gnc(); /* - 0x20 = y */ t_gnc(); /* - 0x20 = x */ c = input_char(); } return c; }
void alert_box(char *s) /* alert the user to an error */ { char *b; int x, y, w; w = strlen(s) + 20; b = prepare_popup("Error", &x, &y, &w); hide_c(); mywrite(s); clear_keybuf(); while (m_b) poll_mouse(); while ((!input_waiting()) && (!m_b)) poll_mouse(); if (input_waiting()) input_char(); else while (m_b) poll_mouse(); show_c(); end_popup(b, &x, &y, &w); }
char gets( char *key){ char temp; char i=0; while( ( temp=input_char())!=0x0d ){ if( temp == '\b'){ // delete a word unsigned short int now_pos = get_pointer_pos(); if( (now_pos&0x00ff) < flag_len){ //dont delete flag continue; } printToscn('\b'); printToscn(' '); printToscn('\b'); i--; continue; } key[i] = temp; if(i<63)i++; printToscn( temp); } key[i] = '\0'; return i; }
int input_line(char *string, int length) { char curline[2000]; /* edit buffer */ int noline; unsigned c; int more; int i; if (first) { poolinit(); /* build line pool */ first = 0; } noline = 1; /* no line fetched yet */ for (cl=cp=0; cl<length && cl<(int)sizeof(curline); ) { if (usrbrk()) { clrbrk(); break; } switch (c=input_char()) { case F_RETURN: /* CR */ t_sendl("\r\n", 2); /* yes, print it and */ goto done; /* get out */ case F_CLRSCRN: /* clear screen */ asclrs(); t_sendl(curline, cl); ascurs(0, cp); break; case F_CSRUP: if (noline) { /* no line fetched yet */ getnext(); /* getnext so getprev gets current */ noline = 0; /* we now have line */ } bstrncpy(curline, getprev(), sizeof(curline)); prtcur(curline); break; case F_CSRDWN: noline = 0; /* mark line fetched */ bstrncpy(curline, getnext(), sizeof(curline)); prtcur(curline); break; case F_INSCHR: insert_space(curline, sizeof(curline)); break; case F_DELCHR: delchr(1, curline, sizeof(curline)); /* delete one character */ break; case F_CSRLFT: /* Backspace */ backup(curline); break; case F_CSRRGT: forward(curline, sizeof(curline)); break; case F_ERSCHR: /* Rubout */ backup(curline); delchr(1, curline, sizeof(curline)); if (cp == 0) { t_char(' '); t_char(0x8); } break; case F_DELEOL: t_clrline(0, t_width); if (cl > cp) cl = cp; break; case F_NXTWRD: i = next_word(curline); while (i--) { forward(curline, sizeof(curline)); } break; case F_PRVWRD: i = prev_word(curline); while (i--) { backup(curline); } break; case F_DELWRD: delchr(next_word(curline), curline, sizeof(curline)); /* delete word */ break; case F_NXTMCH: /* Ctl-X */ if (cl==0) { *string = EOS; /* terminate string */ return(c); /* give it to him */ } /* Note fall through */ case F_DELLIN: case F_ERSLIN: while (cp > 0) { backup(curline); /* backup to beginning of line */ } t_clrline(0, t_width); /* erase line */ cp = 0; cl = 0; /* reset cursor counter */ t_char(' '); t_char(0x8); break; case F_SOL: while (cp > 0) { backup(curline); } break; case F_EOL: while (cp < cl) { forward(curline, sizeof(curline)); } while (cp > cl) { backup(curline); } break; case F_TINS: /* toggle insert mode */ mode_insert = !mode_insert; /* flip bit */ break; default: if (c > 255) { /* function key hit */ if (cl==0) { /* if first character then */ *string = EOS; /* terminate string */ return c; /* return it */ } t_honk_horn(); /* complain */ } else { if ((c & 0xC0) == 0xC0) { if ((c & 0xFC) == 0xFC) { more = 5; } else if ((c & 0xF8) == 0xF8) { more = 4; } else if ((c & 0xF0) == 0xF0) { more = 3; } else if ((c & 0xE0) == 0xE0) { more = 2; } else { more = 1; } } else { more = 0; } if (mode_insert) { insert_space(curline, sizeof(curline)); } curline[cp++] = c; /* store character in line being built */ t_char(c); /* echo character to terminal */ while (more--) { c= input_char(); insert_hole(curline, sizeof(curline)); curline[cp++] = c; /* store character in line being built */ t_char(c); /* echo character to terminal */ } if (cp > cl) { cl = cp; /* keep current length */ curline[cp] = 0; } } break; } /* end switch */ } /* If we fall through here rather than goto done, the line is too long simply return what we have now. */ done: curline[cl++] = EOS; /* terminate */ bstrncpy(string,curline,length); /* return line to caller */ /* Save non-blank lines. Note, put line zaps curline */ if (curline[0] != EOS) { putline(curline,cl); /* save line for posterity */ } return 0; /* give it to him/her */ }
static locale_module *parse_locale_file(z_ucs *module_name, char* locale_dir_name, char* module_name_utf8) { char *filename; z_file *in; z_ucs *locale_data; locale_module *result; char in_char; long nof_zucs_chars; z_ucs input; z_ucs *linestart; list *lines; TRACE_LOG("locale_dir_name: \"%s\".\n", locale_dir_name); TRACE_LOG("module_name_utf8: \"%s\".\n", module_name_utf8); // open-resource: if ((filename = malloc(strlen(locale_dir_name) + strlen(module_name_utf8) + 2)) == NULL) { // exit-point: TRACE_LOG("malloc() returned NULL.\n"); return NULL; } TRACE_LOG("locale_dir_name: \"%s\".\n", locale_dir_name); TRACE_LOG("module_name_utf8: \"%s\".\n", module_name_utf8); strcpy(filename, locale_dir_name); strcat(filename, "/"); strcat(filename, module_name_utf8); TRACE_LOG("Parsing locale file \"%s\".\n", filename); // open-resource: if ((in = fsi->openfile(filename, FILETYPE_DATA, FILEACCESS_READ)) == NULL) { // exit-point: TRACE_LOG("openfile(\"%s\") returned NULL.\n", filename); free(filename); return NULL; } nof_zucs_chars = 0; while ((parse_utf8_char_from_file(in)) != UEOF) nof_zucs_chars++; nof_zucs_chars++; // Add space for terminating zero (yes, really required). if (fsi->setfilepos(in, 0, SEEK_SET) == -1) { // exit-point: TRACE_LOG("setfilepos() returned -1.\n"); fsi->closefile(in); free(filename); return NULL; } TRACE_LOG("Allocating space for %ld z_ucs chars.\n", nof_zucs_chars); // open-resource: if ((locale_data = malloc(nof_zucs_chars * sizeof(z_ucs))) == NULL) { // exit-point: TRACE_LOG("malloc(%ld) returned NULL.\n", nof_zucs_chars * sizeof(z_ucs)); fsi->closefile(in); free(filename); return NULL; } TRACE_LOG("Locale data at %p, ends at %p.\n", locale_data, locale_data+nof_zucs_chars); // open-resource: if ((result = malloc(sizeof(locale_module))) == NULL) { // exit-point: free(locale_data); fsi->closefile(in); free(filename); return NULL; } TRACE_LOG("New module at %p.\n", result); result->locale_data = locale_data; TRACE_LOG("Locale data starts at %p.\n", locale_data); /* --- */ // open-resource: lines = create_list(); //printf("new list created: %p\n", lines); in_char = fsi->getchar(in); while (in_char != EOF) { linestart = locale_data; // Found a new line. fsi->ungetchar(in_char, in); for (;;) { input = input_char(in); if (input == Z_UCS_BACKSLASH) { //*locale_data++ = input; input = input_char(in); if (input == Z_UCS_BACKSLASH) { *locale_data++ = Z_UCS_BACKSLASH; } else if (input == 'n') { *locale_data++ = Z_UCS_NEWLINE; } else if (input == '{') { *locale_data++ = Z_UCS_BACKSLASH; *locale_data++ = (z_ucs)'{'; input = input_char(in); if ((input < 0x30) && (input > 0x39)) { fprintf(stderr, "Variable number expected.\n"); exit(EXIT_FAILURE); } *locale_data++ = input; input = input_char(in); if ( (input != (z_ucs)'s') && (input != (z_ucs)'d') && (input != (z_ucs)'x') && (input != (z_ucs)'z') ) { fprintf(stderr, "Invalid parameter type.\n"); exit(EXIT_FAILURE); } *locale_data++ = input; input = input_char(in); if (input != (z_ucs)'}') { fprintf(stderr, "Expected '}'.\n"); exit(EXIT_FAILURE); } *locale_data++ = (z_ucs)'}'; } else { fprintf(stderr, "Undefined control sequence \\%c.\n",(char)input); exit(EXIT_FAILURE); } } else if (input == Z_UCS_NEWLINE) { *locale_data++ = 0; TRACE_LOG("New line at %p.\n", linestart); add_list_element(lines, (void*)linestart); //TRACE_LOG_Z_UCS(linestart); break; } else { // Here we've found some "normal" output. *locale_data++ = (z_ucs)input; } } //messages_processed++; in_char = fsi->getchar(in); } *locale_data = 0; TRACE_LOG("Wirte last byte at %p.\n", locale_data); /* --- */ TRACE_LOG("Read %d lines.\n", get_list_size(lines)); // close-resource(l), open-resource(result->messages): result->nof_messages = get_list_size(lines); result->messages = (z_ucs**)delete_list_and_get_ptrs(lines); TRACE_LOG("Messages at %p.\n", result->messages); TRACE_LOG("First msg at %p.\n", result->messages[0]); if ((result->module_name = malloc(sizeof(z_ucs) * (z_ucs_len(module_name)+1))) == NULL) { // exit-point: free(result->messages); free(result); free(locale_data); fsi->closefile(in); free(filename); return NULL; } z_ucs_cpy(result->module_name, module_name); // close-resource: fsi->closefile(in); // close-resource: free(filename); TRACE_LOG("Returning new module at %p.\n", result); return result; }
int do_input_text(char *buf, int size, int width, int (*valid)(char), int (*proc)(int, char *, int *, int *), int mouse_flag, int (*mouse_proc)(int x, int y, char *buf, int *oldlen)) { KEYPRESS k; int key; int askey; int ret; int x, y, len, cpos; int oldlen, c; int gap; int sel = TRUE; x = x_pos; y = y_pos; len = oldlen = cpos = strlen(buf); n_vid(); do { goto1(x, y); if ((width > 0) && (len > width)) { gap = len - width; pch('.'); pch('.'); pch('.'); pch(' '); mywrite(buf+gap+4); } else { gap = 0; mywrite(buf); } hi_vid(); for (c=len-gap; c < ((width > 0) ? width : oldlen); c++) pch(' '); oldlen = len; if (cpos-gap > 0) goto2(x+cpos-gap, y); else goto2(x, y); show_c(); if (mouse_flag) { display_mouse(); while (m_b) poll_mouse(); while (TRUE) { if (input_waiting()) { k = input_char(); key = k.key; if ((ascii(key) == CR) && (k.flags & KF_CTRL)) key = LF; if (key) break; } poll_mouse(); if ((m_b) && (mouse_proc)) { hide_c(); key = (*mouse_proc)(x, y, buf, &oldlen); len = cpos = strlen(buf); sel = FALSE; show_c(); if (key > 0) break; } } hide_mouse(); } else { while (m_b) poll_mouse(); while ((!input_waiting()) && (!m_b)) poll_mouse(); if (m_b) { if (m_b & 2) key = ESC; else key = CR; } else { k = input_char(); key = k.key; if ((ascii(key) == CR) && (k.flags & KF_CTRL)) key = LF; } } if ((!proc) || (!(*proc)(key, buf, &len, &cpos))) { if ((key==CTRL_G) || (key==CTRL_C)) askey=ESC; else askey=ascii((char)key); if ((askey==ESC) || (askey==CR) || (askey==LF)) { ret = askey; break; } if (key==LEFT_ARROW) { if (cpos > 0) cpos--; } else if (key==RIGHT_ARROW) { if (cpos < len) cpos++; } else if (key==K_HOME) { cpos = 0; } else if (key==K_END) { cpos = MAX(len, 0); } else { if ((sel) && ((key==K_DELETE) || (askey==BACKSPACE) || ((*valid)(askey)))) { len = cpos = 0; buf[0] = 0; } if (key==K_DELETE) { if (cpos < len) { for (c=cpos; c<len; c++) buf[c] = buf[c+1]; len--; } } else if (askey==BACKSPACE) { if (cpos > 0) { cpos--; for (c=cpos; c<len; c++) buf[c] = buf[c+1]; len--; } } else { if ((len<size) && ((*valid)(askey))) { len++; for (c=len; c>cpos; c--) buf[c] = buf[c-1]; buf[cpos++]=askey; } } } if (proc) (*proc)(-1, buf, &len, &cpos); } sel = FALSE; } while (TRUE); n_vid(); return ret; }
void wait_key(){ puts("\r\n\r\n press any key to exit..."); char a=input_char(); }
int do_listbox(LISTBOX *l, int *oklist, int *cancellist, int init_key, int instant_mouse) { int key; int *pos; int done; int ret; int c; char *b = save_screen(l->x, l->y, l->w, l->h); int is_key; hide_c(); draw_listbox(l); l->key = init_key; l->key2 = -1; display_mouse(); while (m_b) { poll_mouse(); if ((instant_mouse) && ((m_b & 2) || (mouse_inside_list(l)) || ((mouse_inside_parent(l)) && (get_mouse_item(l->parent) != l->parent->current)))) break; } do { if (l->key == -1) { while (!input_waiting()) { poll_mouse(); if (m_b) break; } if (input_waiting()) { key = input_char().key; is_key = TRUE; } else { int ox, oy, ob; int sel_item; int first = TRUE; key = 0; is_key = FALSE; while (m_b) { if ((m_b & 2) && (!(l->flags & LISTBOX_USE_RMB))) { key = ESC; is_key = TRUE; break; } sel_item = -1; if (mouse_inside_list(l)) { l->current = get_mouse_item(l); if (l->current >= l->count) l->current = l->count-1; else sel_item = l->current; } hide_mouse(); draw_contents(l); display_mouse(); if (first) { if (sel_item >= 0) { if (l->flags & LISTBOX_MOUSE_OK) { key = CR; is_key = TRUE; break; } if (!(l->flags & LISTBOX_MOUSE_OK2)) { if (!mouse_dclick(FALSE)) { if (mouse_dclick(TRUE)) { key = CR; is_key = TRUE; break; } } } } else if (mouse_outside_list(l)) { if (l->flags & LISTBOX_MOUSE_CANCEL) { key = ESC; is_key = TRUE; break; } } first = FALSE; } if (mouse_inside_parent(l)) { if (l->flags & LISTBOX_MOUSE_CANCEL) { key = ESC; is_key = TRUE; break; } } if (l->flags & LISTBOX_SCROLL) { int changed = FALSE; if ((m_y < l->y + l->yoff) && (l->scroll > 0)) { l->scroll--; l->current = l->scroll; m_y = -1; changed = TRUE; } else if ((m_y >= l->y + l->yoff + l->height) && (l->scroll < l->count - l->height)) { l->scroll++; l->current = l->scroll + l->height - 1; if (l->current >= l->count) l->current = l->count-1; m_y = -1; changed = TRUE; } if (changed) { hide_mouse(); draw_contents(l); display_mouse(); delay(20); } } do { ox = m_x; oy = m_y; ob = m_b; poll_mouse(); } while ((m_x == ox) && (m_y == oy) && (m_b == ob) && (m_b) && (!input_waiting())); if ((!m_b) && (sel_item >= 0) && (l->flags & LISTBOX_MOUSE_OK2)) { key = CR; is_key = TRUE; break; } } } } else { key = l->key; l->key = l->key2; l->key2 = -1; is_key = TRUE; } done = FALSE; if (is_key) { pos = oklist; while (*pos) { if ((*pos == key) || (ascii(key)==CR) || (ascii(key)==LF)) { if ((l->current >= 0) && (l->current < l->count)) { hide_mouse(); if (l->data[l->current].click_proc) ret = (l->data[l->current].click_proc) (l, l->data+l->current); else ret = l->data[l->current].data; if (ret >= 0) { l->key = key; restore_screen(l->x, l->y, l->w, l->h, b); show_c(); return ret; } else { hide_c(); display_mouse(); } } done = TRUE; break; } pos++; } if (!done) { pos = cancellist; while (*pos) { if ((*pos == key) || (ascii(key)==ESC)) { hide_mouse(); l->key = key; restore_screen(l->x, l->y, l->w, l->h, b); show_c(); return -1; } pos++; } } if (!done) { if (key==LEFT_ARROW) l->current--; else if (key==UP_ARROW) l->current -= l->width; else if (key==RIGHT_ARROW) l->current++; else if (key==DOWN_ARROW) l->current += l->width; else if (key==PAGE_UP) l->current -= l->width * l->height - 1; else if (key==PAGE_DOWN) l->current += l->width * l->height - 1; else if (key==K_HOME) l->current = 0; else if (key==K_END) l->current = l->count-1; else if (l->process_proc) if ((*l->process_proc)(l, key)) goto skip; for (c=0; c<l->count; c++) if (tolower(l->data[c].text[0]) == tolower(ascii(key))) { l->current = c; if (l->flags & LISTBOX_FASTKEY) l->key = oklist[0]; break; } skip: if (l->current < 0) { if (l->flags & LISTBOX_WRAP) l->current = MAX(0, l->count-1); else l->current = 0; } else if (l->current >= l->count) { if (l->flags & LISTBOX_WRAP) l->current = 0; else l->current = MAX(0, l->count-1); } while (l->current < l->scroll) l->scroll -= l->width; while (l->current >= l->scroll+l->width*l->height) l->scroll += l->width; } } hide_mouse(); draw_contents(l); display_mouse(); } while (TRUE); }