static void echoserialoq(char *buf, int n) { char *e, *p; char ebuf[128]; int x; p = ebuf; e = ebuf + sizeof(ebuf) - 4; while (n-- > 0) { if (p >= e) { qiwrite(serialoq, ebuf, p - ebuf); p = ebuf; } x = *buf++; if (x == '\n') { *p++ = '\r'; *p++ = '\n'; } else if (x == 0x15) { *p++ = '^'; *p++ = 'U'; *p++ = '\n'; } else *p++ = x; } if (p != ebuf) qiwrite(serialoq, ebuf, p - ebuf); }
/* * Print a string on the console. Convert \n to \r\n for serial * line consoles. Locking of the queues is left up to the screen * or uart code. Multi-line messages to serial consoles may get * interspersed with other messages. */ static void putstrn0(char *str, int n, int usewrite) { if(!islo()) usewrite = 0; /* * how many different output devices do we need? */ kmesgputs(str, n); /* * if someone is reading /dev/kprint, * put the message there. * if not and there's an attached bit mapped display, * put the message there. * * if there's a serial line being used as a console, * put the message there. */ if(kprintoq != nil && !qisclosed(kprintoq)){ if(usewrite) qwrite(kprintoq, str, n); else qiwrite(kprintoq, str, n); }else if(screenputs != nil) screenputs(str, n); uartputs(str, n); #if 0 // Plan 9 VX if(serialoq == nil){ uartputs(str, n); return; } while(n > 0) { t = memchr(str, '\n', n); if(t && !kbd.raw) { m = t-str; if(usewrite){ qwrite(serialoq, str, m); qwrite(serialoq, "\r\n", 2); } else { qiwrite(serialoq, str, m); qiwrite(serialoq, "\r\n", 2); } n -= m+1; str = t+1; } else { if(usewrite) qwrite(serialoq, str, n); else qiwrite(serialoq, str, n); break; } } #endif }
int iprint(char *fmt, ...) { Mpl pl; int i, n, locked; va_list arg; char buf[PRINTSIZE]; pl = splhi(); va_start(arg, fmt); n = vseprint(buf, buf+sizeof(buf), fmt, arg) - buf; va_end(arg); locked = iprintcanlock(&iprintlock); for(i = 0; i < nconsdevs; i++) if((consdevs[i].flags&Ciprint) != 0){ if(consdevs[i].q != nil) qiwrite(consdevs[i].q, buf, n); else consdevs[i].fn(buf, n); } if(locked) unlock(&iprintlock); splx(pl); return n; }
void echo(Rune r, char *buf, int n) { if (kbd.raw) return; if (r == '\n') { if (printq) qiwrite(printq, "\r", 1); } else if (r == 0x15) { buf = "^U\n"; n = 3; } if (consoleprint && screenputs != NULL) screenputs(buf, n); if (printq) qiwrite(printq, buf, n); }
/* total hack. */ void kbdputsc(int data, int _) { static char line[512]; static int len; putchar(data); line[len++] = data; if (keybq && (data == '\n')) { qiwrite(keybq, line, len); len = 0; } }
/* * Print a string on the console. Convert \n to \r\n for serial * line consoles. Locking of the queues is left up to the screen * or uart code. Multi-line messages to serial consoles may get * interspersed with other messages. */ static void putstrn0(char *str, int n, int usewrite) { int m; char *t; char buf[PRINTSIZE + 2]; ERRSTACK(1); /* * if kprint is open, put the message there, otherwise * if there's an attached bit mapped display, * put the message there. */ m = consoleprint; if (canrlock(&(&kprintq)->rwlock)) { if (kprintq.q != NULL) { if (waserror()) { runlock(&(&kprintq)->rwlock); nexterror(); } if (usewrite) qwrite(kprintq.q, str, n); else qiwrite(kprintq.q, str, n); poperror(); m = 0; } runlock(&(&kprintq)->rwlock); } if (m && screenputs != NULL) screenputs(str, n); /* * if there's a serial line being used as a console, * put the message there. */ if (serwrite != NULL) { serwrite(str, n); return; } if (printq == 0) return; while (n > 0) { t = memchr(str, '\n', n); if (t && !kbd.raw) { m = t - str; if (m > sizeof(buf) - 2) m = sizeof(buf) - 2; memmove(buf, str, m); buf[m] = '\r'; buf[m + 1] = '\n'; if (usewrite) qwrite(printq, buf, m + 2); else qiwrite(printq, buf, m + 2); str = t + 1; n -= m + 1; } else { if (usewrite) qwrite(printq, str, n); else qiwrite(printq, str, n); break; } } }
long consread(Chan *c, void *va, long count, vlong offset) { int i, n, ch, eol; Pointer m; char *p, buf[64]; if(c->qid.type & QTDIR) return devdirread(c, va, count, contab, nelem(contab), devgen); switch((ulong)c->qid.path) { default: error(Egreg); case Qsysctl: return readstr(offset, va, count, VERSION); case Qsysname: if(ossysname == nil) return 0; return readstr(offset, va, count, ossysname); case Qrandom: return randomread(va, count); case Qnotquiterandom: pseudoRandomBytes(va, count); return count; case Qpin: p = "pin set"; if(up->env->pgrp->pin == Nopin) p = "no pin"; return readstr(offset, va, count, p); case Qhostowner: return readstr(offset, va, count, eve); case Qhoststdin: return read(0, va, count); /* should be pread */ case Quser: return readstr(offset, va, count, up->env->user); case Qjit: snprint(buf, sizeof(buf), "%d", cflag); return readstr(offset, va, count, buf); case Qtime: snprint(buf, sizeof(buf), "%.lld", timeoffset + osusectime()); return readstr(offset, va, count, buf); case Qdrivers: p = malloc(READSTR); if(p == nil) error(Enomem); n = 0; for(i = 0; devtab[i] != nil; i++) n += snprint(p+n, READSTR-n, "#%C %s\n", devtab[i]->dc, devtab[i]->name); n = readstr(offset, va, count, p); free(p); return n; case Qmemory: return poolread(va, count, offset); case Qnull: return 0; case Qmsec: return readnum(offset, va, count, osmillisec(), NUMSIZE); case Qcons: qlock(&kbd.q); if(waserror()){ qunlock(&kbd.q); nexterror(); } if(dflag) error(Enonexist); while(!qcanread(lineq)) { qread(kbdq, &kbd.line[kbd.x], 1); ch = kbd.line[kbd.x]; if(kbd.raw){ qiwrite(lineq, &kbd.line[kbd.x], 1); continue; } eol = 0; switch(ch) { case '\b': if(kbd.x) kbd.x--; break; case 0x15: kbd.x = 0; break; case '\n': case 0x04: eol = 1; default: kbd.line[kbd.x++] = ch; break; } if(kbd.x == sizeof(kbd.line) || eol){ if(ch == 0x04) kbd.x--; qwrite(lineq, kbd.line, kbd.x); kbd.x = 0; } } n = qread(lineq, va, count); qunlock(&kbd.q); poperror(); return n; case Qscancode: if(offset == 0) return readstr(0, va, count, gkscanid); else return qread(gkscanq, va, count); case Qkeyboard: return qread(gkbdq, va, count); case Qpointer: m = mouseconsume(); n = sprint(buf, "m%11d %11d %11d %11lud ", m.x, m.y, m.b, m.msec); if (count < n) n = count; memmove(va, buf, n); return n; case Qkprint: rlock(&kprintq.l); if(waserror()){ runlock(&kprintq.l); nexterror(); } n = qread(kprintq.q, va, count); poperror(); runlock(&kprintq.l); return n; case Qsnarf: if(offset == 0) { free(c->aux); c->aux = clipread(); } if(c->aux == nil) return 0; return readstr(offset, va, count, c->aux); } }