NODE *reader(FILE *strm, char *prompt) { int c = 0, dribbling, vbar = 0, paren = 0; int bracket = 0, brace = 0, p_pos, contin=1, insemi=0, raw=0; char *phys_line, *lookfor = ender; NODETYPES this_type = STRING; NODE *ret; char *old_stringptr = print_stringptr; int old_stringlen = print_stringlen; fix_turtle_shownness(); //readingInstruction = !strcmp(prompt, "? "); readingInstruction = (strm == stdin); #ifdef HAVE_WX wx_refresh(); if(readingInstruction) { wx_enable_scrolling(); } #endif print_stringptr = ender; print_stringlen = 99; ndprintf(NULL, "\n%p\n", theName(Name_end)); *print_stringptr = '\0'; print_stringptr = old_stringptr; print_stringlen = old_stringlen; if (!strcmp(prompt, "RW")) { /* called by readword */ prompt = ""; contin = 0; } if (!strcmp(prompt, "RAW")) { /* called by readrawline */ prompt = ""; contin = 0; raw = 1; } charmode_off(); #ifdef WIN32 dribbling = 0; #else dribbling = (dribblestream != NULL && strm == stdin); #endif if (p_line == 0) { p_line = malloc(MAX_PHYS_LINE); if (p_line == NULL) { err_logo(OUT_OF_MEM, NIL); return UNBOUND; } p_end = &p_line[MAX_PHYS_LINE-1]; } phys_line = p_line; if (strm == stdin && *prompt) { if (interactive) { rd_print_prompt(prompt); #ifdef WIN32 win32_update_text(); #endif } } if (strm == stdin) { input_blocking++; erract_errtype = FATAL; } #ifndef TIOCSTI if (!setjmp(iblk_buf)) { #endif c = rd_getc(strm); /* if ((c=='\b' || c=='\127') && strm==stdin && interactive) { silent_load(LogoLogo, logolib); c = rd_getc(strm); } */ /* 6.0 */ #ifdef mac if (c == '\r') c = '\n'; /* seen in raw mode by keyp, never read */ #endif while (c != EOF && (vbar || paren || bracket || brace || c != '\n') && NOT_THROWING) { if (dribbling) rd_putc(c, dribblestream); if (!raw && c == '\\' && (c = rd_getc(strm)) != EOF) { if (dribbling) rd_putc(c, dribblestream); c = setparity(c); this_type = BACKSLASH_STRING; if (c == setparity('\n') && strm == stdin) { if (interactive) zrd_print_prompt("\\ "); } } if (c != EOF) into_line(c); if (raw) { c = rd_getc(strm); continue; } if (*prompt && (c&0137) == ((*lookfor)&0137)) { lookfor++; if (*lookfor == 0) { if (deepend_proc_name != NIL) err_logo(DEEPEND, deepend_proc_name); else err_logo(DEEPEND_NONAME, NIL); break; } } else lookfor = ender; if (c == '|' && !insemi) { vbar = !vbar; this_type = VBAR_STRING; } else if (contin && !vbar && !insemi) { if (c == '(') paren++; else if (paren && c == ')') paren--; else if (c == '[') bracket++; else if (bracket && c == ']') bracket--; else if (c == '{') brace++; else if (brace && c == '}') brace--; else if (c == ';') insemi++; } if (this_type == STRING && strchr(special_chars, c)) this_type = VBAR_STRING; if (/* (vbar || paren ...) && */ c == '\n') { insemi = 0; if (strm == stdin) { if (interactive) zrd_print_prompt(vbar ? "| " : "~ "); } } while (!vbar && c == '~' && (c = rd_getc(strm)) != EOF) { int gotspc = 0; while (c == ' ' || c == '\t') { gotspc = 1; c = rd_getc(strm); } if (dribbling) rd_putc(c, dribblestream); if (c != '\n' && gotspc) into_line(' '); into_line(c); if (c == '\n') { insemi = 0; if (interactive && strm == stdin) zrd_print_prompt("~ "); } else if (c == '(') paren++; else if (paren && c == ')') paren--; else if (c == '[') bracket++; else if (bracket && c == ']') bracket--; else if (c == '{') brace++; else if (brace && c == '}') brace--; else if (c == ';') insemi++; } if (c != EOF) c = rd_getc(strm); } #ifndef TIOCSTI } #endif *phys_line = '\0'; input_blocking = 0; #if defined(__RZTC__) && !defined(WIN32) /* sowings */ fix_cursor(); if (interactive && strm == stdin) newline_bugfix(); #endif if (dribbling) rd_putc('\n', dribblestream); if (c == EOF && strm == stdin) { if (interactive) clearerr(stdin); rd_print_prompt("\n"); } if (phys_line == p_line) return(Null_Word); /* so emptyp works */ ret = make_strnode(p_line, (struct string_block *)NULL, (int)strlen(p_line), this_type, strnzcpy); #if 0 if (strm == stdin && !strcmp(prompt, "? ")){ char *histline = malloc(1+strlen(p_line)); strcpy(histline, p_line); *hist_inptr++ = histline; if (hist_inptr >= &cmdHistory[HIST_MAX]) { hist_inptr = cmdHistory; } if (*hist_inptr) { free(*hist_inptr); *hist_inptr = 0; } hist_outptr = hist_inptr; } #endif //added (evan) readingInstruction = 0; return(ret); }
int rd_getc(FILE *strm) { int c; #ifdef WIN32 MSG msg; #endif #ifndef WIN32 /* skip this section ... */ #ifdef __RZTC__ if (strm == stdin) zflush(); c = ztc_getc(strm); #else c = getc(strm); #endif if (strm == stdin && c != EOF) update_coords(c); #ifndef mac if (c == '\r') return rd_getc(strm); #endif #ifdef ibm if (c == 17 && interactive && strm==stdin) { /* control-q */ to_pending = 0; err_logo(STOP_ERROR,NIL); if (input_blocking) { #ifdef SIG_TAKES_ARG logo_stop(0); #else logo_stop(); #endif } } if (c == 23 && interactive && strm==stdin) { /* control-w */ #ifndef __RZTC__ getc(strm); /* eat up the return */ #endif #ifdef SIG_TAKES_ARG logo_pause(0); #else logo_pause(); #endif return(rd_getc(strm)); } #endif #else /* WIN32 */ if (strm == stdin) { if (winPasteText && !line_avail) winDoPaste(); if (!line_avail) { win32_text_cursor(); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); if (line_avail) break; } } c = read_line[read_index++]; if (c == 17 && interactive && strm==stdin) { /* control-q */ to_pending = 0; err_logo(STOP_ERROR,NIL); line_avail = 0; free(read_line); if (input_blocking) logo_stop(0); return('\n'); } if (c == 23 && interactive && strm==stdin) { /* control-w */ line_avail = 0; free(read_line); logo_pause(0); return(rd_getc(strm)); } if (c == '\n') { line_avail = 0; free(read_line); } } else /* reading from a file */ c = getc(strm); #endif /* WIN32 */ #ifdef ecma return((c == EOF) ? c : ecma_clear(c)); #else return(c); #endif }
void parse(Reader *rd) { for(;;) { wr_putc(&wr, rd_getc(rd)); } }