int getch(void) { if(eof) return -1; if(*linep==0 && inputline()<0){ eof = TRUE; return -1; } return *linep++; }
/* Set window title */ static int test_window_name(MENU_ARGS) { char temp[BUFSIZ]; vt_move(1,1); println("Please enter the new window name. Newer xterms may beep when setting the title."); inputline(temp); do_osc("0;%s%c", temp, BEL); return MENU_NOHOLD; }
int main(int argc, char **argv) { extern char *optarg; extern int optind; int iflag = 0; int nflag = 0; int ch; while ((ch = getopt(argc, argv, "c:il:n")) != -1) { switch (ch) { case 'i': iflag = 1; break; case 'c': cdelay = atoi(optarg) * 1000; break; case 'l': ldelay = atoi(optarg) * 1000; break; case 'n': nflag = 1; break; case '?': default: fprintf(stderr, "usage: wopr [opt] arg [arg2 ...]\n"); fprintf(stderr, "opt: -c msec Delay per character\n"); fprintf(stderr, " -i Read and (cleanup telnet) input line\n"); fprintf(stderr, " -l msec Delay per line\n"); fprintf(stderr, " -n No new line\n"); exit(EXIT_FAILURE); } } argc -= optind; argv += optind; if (iflag) { exit(inputline()); } if (!*argv && ! nflag) wopr('\n'); while (*argv) { char *ptr; for (ptr = *argv ; *ptr ; ++ptr) wopr(*ptr); if (! nflag) wopr('\n'); ++argv; } exit(EXIT_SUCCESS); }
int main() { char* linexmpl = malloc(5*sizeof(char)); char* cpdline = malloc(5*sizeof(char)); char* subline = malloc(5*sizeof(char)); int pos = 0; inputline(linexmpl); ASSERT(linexmpl > 0); printf("\nLength of line '%s':%d\n\n", linexmpl, strlength(linexmpl)); linecpy(linexmpl, cpdline); printf("Result of copying:%s\n\n", cpdline); printf("Searching substring in '%s':", linexmpl); inputline(subline); ASSERT(subline > 0); "\n"; if (pos = findsub(subline, linexmpl)) printf("\nSubstring is found on position:%d\n", pos); else printf("\nSubstring is no found\n"); free(linexmpl); free(cpdline); free(subline); return 0; }
int ingetc(void) { int lastc = ' '; if (lexstop) return ' '; for (;;) { if (inbufleft) { inbufleft--; inbufct--; if (itok(lastc = STOUC(*inbufptr++))) continue; if (((inbufflags & INP_LINENO) || !strin) && lastc == '\n') lineno++; break; } /* * See if we have reached the end of input * (due to an error, or to reading from a single string). * Check the remaining characters left, since if there aren't * any we don't want to pop the stack---it'll mark any aliases * as not in use before we've finished processing. */ if (!inbufct && (strin || errflag)) { lexstop = 1; break; } /* If the next element down the input stack is a continuation of * this, use it. */ if (inbufflags & INP_CONT) { inpoptop(); continue; } /* As a last resort, get some more input */ if (inputline()) break; } if (!lexstop) zshlex_raw_add(lastc); return lastc; }
int menu2(MENU *table, int top) { int i, tablesize, choice; char c; char storage[BUFSIZ]; int pagesize = max_lines - 7 - TITLE_LINE; int pagetop = 1; int redraw = FALSE; tablesize = 0; for (i = 0; !end_of_menu(table, i); i++) { tablesize++; } tablesize--; for (;;) { vt_move(top, 1); vt_clear(0); println(""); show_entry(table, 0); for (i = 0; i < pagesize; i++) { int j = pagetop + i; if (end_of_menu(table, j)) break; show_entry(table, pagetop + i); } printf("\n Enter choice number (0 - %d): ", tablesize); for (;;) { char *s = storage; inputline(s); choice = 0; redraw = FALSE; while ((c = *s++) != '\0') { if (c == '*') { choice = -1; break; } else if (c == '?') { redraw = TRUE; break; } else if (tablesize > pagesize && c == 'n') { pagetop = next_menu(table, pagetop, pagesize); redraw = TRUE; break; } else if (tablesize > pagesize && c == 'p') { pagetop = prev_menu(pagetop, pagesize); redraw = TRUE; break; } else if (c >= '0' && c <= '9') { choice = 10 * choice + c - '0'; } else { choice = tablesize + 1; break; } } if (redraw) break; if (choice < 0) { for (choice = 0; choice <= tablesize; choice++) { vt_clear(2); if (table[choice].dispatch != 0) { const char *save = push_menu(choice); const char *name = table[choice].description; if (LOG_ENABLED) fprintf(log_fp, "Menu %s: %s\n", current_menu, name); if ((*table[choice].dispatch) (name) == MENU_HOLD) holdit(); pop_menu(save); } } return 1; } else if (choice <= tablesize) { vt_clear(2); if (table[choice].dispatch != 0) { const char *save = push_menu(choice); const char *name = table[choice].description; if (LOG_ENABLED) fprintf(log_fp, "Menu %s: %s\n", current_menu, name); if ((*table[choice].dispatch) (name) != MENU_NOHOLD) holdit(); pop_menu(save); } return (table[choice].dispatch != 0); } printf(" Bad choice, try again: "); } } }