int viquotedinsert(char **args) { #ifndef HAS_TIO struct sgttyb sob; #endif spaceinline(1); zleline[zlecs] = '^'; zrefresh(); #ifndef HAS_TIO sob = shttyinfo.sgttyb; sob.sg_flags = (sob.sg_flags | RAW) & ~ECHO; ioctl(SHTTY, TIOCSETN, &sob); #endif getfullchar(0); #ifndef HAS_TIO zsetterm(); #endif foredel(1, 0); if(LASTFULLCHAR == ZLEEOF) return 1; else return selfinsert(args); }
int quotedinsert(char **args) { #ifndef HAS_TIO struct sgttyb sob; sob = shttyinfo.sgttyb; sob.sg_flags = (sob.sg_flags | RAW) & ~ECHO; ioctl(SHTTY, TIOCSETN, &sob); #endif getfullchar(0); #ifndef HAS_TIO zsetterm(); #endif if (LASTFULLCHAR == ZLEEOF) return 1; else return selfinsert(args); }
mod_export int getbyte(long do_keytmout, int *timeout) { char cc; unsigned int ret; int die = 0, r, icnt = 0; int old_errno = errno, obreaks = breaks; if (timeout) *timeout = 0; #ifdef MULTIBYTE_SUPPORT /* * Reading a single byte always invalidates the status * of lastchar_wide. We may fix this up in getrestchar * if this is the last byte of a wide character. */ lastchar_wide_valid = 0; #endif if (kungetct) ret = STOUC(kungetbuf[--kungetct]); else { #ifdef FIONREAD if (delayzsetterm) { int val; ioctl(SHTTY, FIONREAD, (char *)&val); if (!val) zsetterm(); } #endif for (;;) { int q = queue_signal_level(); dont_queue_signals(); r = raw_getbyte(do_keytmout, &cc); restore_queue_signals(q); if (r == -2) { /* timeout */ if (timeout) *timeout = 1; return lastchar = EOF; } if (r == 1) break; if (r == 0) { /* The test for IGNOREEOF was added to make zsh ignore ^Ds that were typed while commands are running. Unfortuantely this caused trouble under at least one system (SunOS 4.1). Here shells that lost their xterm (e.g. if it was killed with -9) didn't fail to read from the terminal but instead happily continued to read EOFs, so that the above read returned with 0, and, with IGNOREEOF set, this caused an infinite loop. The simple way around this was to add the counter (icnt) so that this happens 20 times and than the shell gives up (yes, this is a bit dirty...). */ if ((zlereadflags & ZLRF_IGNOREEOF) && icnt++ < 20) continue; stopmsg = 1; zexit(1, 0); } icnt = 0; if (errno == EINTR) { die = 0; if (!errflag && !retflag && !breaks) continue; errflag = 0; breaks = obreaks; errno = old_errno; return lastchar = EOF; } else if (errno == EWOULDBLOCK) { fcntl(0, F_SETFL, 0); } else if (errno == EIO && !die) { ret = opts[MONITOR]; opts[MONITOR] = 1; attachtty(mypgrp); zrefresh(); /* kludge! */ opts[MONITOR] = ret; die = 1; } else if (errno != 0) { zerr("error on TTY read: %e", errno); stopmsg = 1; zexit(1, 0); } } if (cc == '\r') /* undo the exchange of \n and \r determined by */ cc = '\n'; /* zsetterm() */ else if (cc == '\n') cc = '\r'; ret = STOUC(cc); } /* * vichgbuf is raw bytes, not wide characters, so is dealt * with here. */ if (vichgflag) { if (vichgbufptr == vichgbufsz) vichgbuf = realloc(vichgbuf, vichgbufsz *= 2); vichgbuf[vichgbufptr++] = ret; } errno = old_errno; return lastchar = ret; }