static void cdata(B *b, unsigned char *dat, int siz) { if (b->vt) { /* ANSI terminal emulator */ MACRO *m; do { cready(b, b->vt->vtcur->byte); m = vt_data(b->vt, &dat, &siz); cfollow(b, b->vt, b->vt->vtcur->byte); undomark(); if (m) { /* only do this if cursor is on window */ if ((maint->curwin->watom->what & TYPETW) && ((BW *)maint->curwin->object)->b == b) { exmacro(m, 1); edupd(1); } rmmacro(m); } } while (m); } else { /* Dumb terminal */ P *q = pdup(b->eof, USTR "cdata"); P *r = pdup(b->eof, USTR "cdata"); off_t byte = q->byte; unsigned char bf[1024]; int x, y; cready(b, byte); for (x = y = 0; x != siz; ++x) { if (dat[x] == 13 || dat[x] == 0) { ; } else if (dat[x] == 8 || dat[x] == 127) { if (y) { --y; } else { pset(q, r); prgetc(q); bdel(q, r); --byte; } } else if (dat[x] == 7) { ttputc(7); } else { bf[y++] = dat[x]; } } if (y) { binsm(r, bf, y); } prm(r); prm(q); cfollow(b, NULL, b->eof->byte); undomark(); } }
int edloop(int flg) { int term = 0; int ret = 0; if (flg) { if (maint->curwin->watom->what == TYPETW) return 0; else maint->curwin->notify = &term; } while (!leave && (!flg || !term)) { MACRO *m; int c; if (exmsg && !flg) { vsrm(exmsg); exmsg = NULL; } edupd(1); if (!ahead && !have) ahead = 1; if (ungot) { if (ungot == 2) { c = ungotc2; ungot = 1; } else { c = ungotc; ungot = 0; } } else c = ttgetc(); if (!ahead && c == 10) c = 13; m = dokey(maint->curwin->kbd, c); if (maint->curwin->main && maint->curwin->main != maint->curwin) { int x = maint->curwin->kbd->x; maint->curwin->main->kbd->x = x; if (x) maint->curwin->main->kbd->seq[x - 1] = maint->curwin->kbd->seq[x - 1]; } if (m) ret = exemac(m); } if (term == -1) return -1; else return ret; }
int ttgetc(void) { int stat; long new_time; int flg; tickon(); loop: flg = 0; /* Status line clock */ new_time = time(NULL); if (new_time != last_time) { last_time = new_time; dostaupd = 1; ticked = 1; } /* Autoscroller */ if (auto_scroll && mnow() >= auto_trig_time) { do_auto_scroll(); ticked = 1; flg = 1; } ttflsh(); while (winched) { winched = 0; edupd(1); ttflsh(); } if (ticked) { edupd(flg); ttflsh(); tickon(); } if (ackkbd != -1) { if (!have) { /* Wait for input */ stat = read(mpxfd, &pack, sizeof(struct packet) - 1024); if (pack.size && stat > 0) { joe_read(mpxfd, pack.data, pack.size); } else if (stat < 1) { if (winched || ticked) goto loop; else ttsig(0); } acceptch = pack.ch; } have = 0; if (pack.who) { /* Got bknd input */ if (acceptch != NO_MORE_DATA) { if (pack.who->func) { pack.who->func(pack.who->object, pack.data, pack.size); edupd(1); } } else mpxdied(pack.who); goto loop; } else { if (acceptch != NO_MORE_DATA) { tickoff(); return acceptch; } else { tickoff(); ttsig(0); return 0; } } } if (have) { have = 0; } else { if (read(fileno(termin), &havec, 1) < 1) { if (winched || ticked) goto loop; else ttsig(0); } } tickoff(); return havec; }
int edloop(int flg) { int term = 0; int ret = 0; if (flg) { if (maint->curwin->watom->what == TYPETW) return 0; else maint->curwin->notify = &term; } while (!leave && (!flg || !term)) { W *w; MACRO *m; BW *bw; int c; int auto_off = 0; int word_off = 0; if (exmsg && !flg) { vsrm(exmsg); exmsg = NULL; } edupd(1); if (!ahead && !have) ahead = 1; if (ungot) { c = ungotc; ungot = 0; } else c = ttgetc(); /* Clear temporary messages */ w = maint->curwin; do { if (w->y != -1) { msgclr(w); } w = (W *) (w->link.next); } while (w != maint->curwin); if (!ahead && c == 10) c = 13; more_no_auto: /* Use special kbd if we're handing data to a shell window */ bw = (BW *)maint->curwin->object; if (shell_kbd && (maint->curwin->watom->what & TYPETW) && bw->b->pid && !bw->b->vt && piseof(bw->cursor)) m = dokey(shell_kbd, c); else if ((maint->curwin->watom->what & TYPETW) && bw->b->pid && bw->b->vt && bw->cursor->byte == bw->b->vt->vtcur->byte) m = dokey(bw->b->vt->kbd, c); else m = dokey(maint->curwin->kbd, c); /* leading part of backtick hack... */ /* should only do this if backtick is uquote, but you're not likely to get quick typeahead with ESC ' as uquote */ if (m && m->cmd && m->cmd->func == uquote && ttcheck()) { m = type_backtick; } /* disable autoindent if it looks like a mouse paste... */ if (m && m->cmd && (m->cmd->func == utype || m->cmd->func == urtn) && (maint->curwin->watom->what & TYPETW) && (bw->o.autoindent || bw->o.wordwrap) && ttcheck()) { auto_off = bw->o.autoindent; bw->o.autoindent = 0; word_off = bw->o.wordwrap; bw->o.wordwrap = 0; } if (maint->curwin->main && maint->curwin->main != maint->curwin) { int x = maint->curwin->kbd->x; maint->curwin->main->kbd->x = x; if (x) maint->curwin->main->kbd->seq[x - 1] = maint->curwin->kbd->seq[x - 1]; } if (!m) m = timer_play(); if (m) ret = exemac(m); /* trailing part of backtick hack... */ /* for case where ` is very last character of pasted block */ while (!leave && (!flg || !term) && m && (m == type_backtick || (m->cmd && (m->cmd->func == utype || m->cmd->func == urtn))) && ttcheck() && havec == '`') { ttgetc(); ret = exemac(type_backtick); } /* trailing part of disabled autoindent */ if (!leave && (!flg || !term) && m && (m == type_backtick || (m->cmd && (m->cmd->func == utype || m->cmd->func == urtn))) && ttcheck()) { if (ungot) { c = ungotc; ungot = 0; } else c = ttgetc(); goto more_no_auto; } if (auto_off) { auto_off = 0; bw->o.autoindent = 1; } if (word_off) { word_off = 0; bw->o.wordwrap = 1; } } if (term == -1) return -1; else return ret; }