void show_vtw_stats(void) { vtw_stats_t stats; void *p; if (!Vflag) return; if ((p = lookup("vtw_stats")) == NULL) return; snarf(p, &stats, sizeof(stats)); printf("\t\t%" PRIu64 " inserts\n", stats.ins); printf("\t\t%" PRIu64 " deletes\n", stats.del); printf("\t\t%" PRIu64 " assassinations\n", stats.kill); printf("\tvestigial time-wait lookup_connect\n"); printf("\t\t%" PRIu64 " look\n", stats.look[0]); printf("\t\t%" PRIu64 " hit\n", stats.hit[0]); printf("\t\t%" PRIu64 " miss\n", stats.miss[0]); printf("\t\t%" PRIu64 " probe\n", stats.probe[0]); printf("\t\t%" PRIu64 " losing\n", stats.losing[0]); printf("\t\t%" PRIu64 " max_chain\n", stats.max_chain[0]); printf("\t\t%" PRIu64 " max_probe\n", stats.max_probe[0]); printf("\t\t%" PRIu64 " max_loss\n", stats.max_loss[0]); printf("\tvestigial time-wait lookup_port\n"); printf("\t\t%" PRIu64 " look\n", stats.look[1]); printf("\t\t%" PRIu64 " hit\n", stats.hit[1]); printf("\t\t%" PRIu64 " miss\n", stats.miss[1]); printf("\t\t%" PRIu64 " probe\n", stats.probe[1]); printf("\t\t%" PRIu64 " losing\n", stats.losing[1]); printf("\t\t%" PRIu64 " max_chain\n", stats.max_chain[1]); printf("\t\t%" PRIu64 " max_probe\n", stats.max_probe[1]); printf("\t\t%" PRIu64 " max_loss\n", stats.max_loss[1]); }
static struct mailbox_sync_context * snarf_sync_init(struct mailbox *box, enum mailbox_sync_flags flags) { struct snarf_mailbox *sbox = SNARF_CONTEXT(box); (void)snarf(sbox->snarf_box, box); return sbox->module_ctx.super.sync_init(box, flags); }
void menu2hit(void) { Text *t=(Text *)which->user1; int w = which-t->l; int m; m = menuhit(2, &mouse, t==&cmd? &menu2c : &menu2); if(lock || t->lock) return; switch(m){ case Cut: cut(t, w, true, true); break; case Paste: paste(t, w); break; case Snarf: snarf(t, w); break; case Exch: snarf(t, w); outT0(Tstartsnarf); setlock(); break; case Look: outTsll(Tlook, t->tag, which->p0, which->p1); setlock(); break; case Search: outcmd(); if(t==&cmd) outTsll(Tsend, 0 /*ignored*/, which->p0, which->p1); else outT0(Tsearch); setlock(); break; } }
static struct mailbox_sync_context * snarf_sync_init(struct mailbox *box, enum mailbox_sync_flags flags) { struct snarf_mailbox *sbox = SNARF_CONTEXT(box); (void)snarf(sbox->snarf_box, box); /* close the mailbox so that we don't have to keep it locked */ (void)mailbox_close(sbox->snarf_box); return sbox->module_ctx.super.sync_init(box, flags); }
void timebase(struct timeval *tv) { void *p; struct bintime timebasebin; p = lookup("timebasebin"); if (!p) return; snarf(p, &timebasebin, sizeof(timebasebin)); bintime2timeval(&timebasebin, tv); }
/* * Save/copy the indicated messages at the end of the passed file name. * If mark is true, mark the message "saved." */ int save1(char str[], int mark, const char *cmd, struct ignoretab *ignore) { struct message *mp; char *file; const char *disp; int f, *msgvec, *ip; FILE *obuf; msgvec = (int *)salloc((msgCount + 2) * sizeof(*msgvec)); if ((file = snarf(str, &f)) == NULL) return (1); if (!f) { *msgvec = first(0, MMNORM); if (*msgvec == 0) { printf("No messages to %s.\n", cmd); return (1); } msgvec[1] = 0; } if (f && getmsglist(str, msgvec, 0) < 0) return (1); if ((file = expand(file)) == NULL) return (1); printf("\"%s\" ", file); (void)fflush(stdout); if (access(file, 0) >= 0) disp = "[Appended]"; else disp = "[New file]"; if ((obuf = Fopen(file, "a")) == NULL) { warn((char *)NULL); return (1); } for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) { mp = &message[*ip - 1]; touch(mp); if (sendmessage(mp, obuf, ignore, NULL) < 0) { warnx("%s", file); (void)Fclose(obuf); return (1); } if (mark) mp->m_flag |= MSAVED; } (void)fflush(obuf); if (ferror(obuf)) warn("%s", file); (void)Fclose(obuf); printf("%s\n", disp); return (0); }
void main(int argc, char **argv) { int i, errs; Fontchar *fc; Bitmap *b; int nc, ht, as; Subfont *f; binit(0, 0, "font merge"); if(argc < 1) usage(); nf = argc-1; for(i = 0; i < nf; i++) snarf(argv[i+1], i); nc = ft[0].sf->n; ht = ft[0].sf->height; as = ft[0].sf->ascent; errs = 0; for(i = 0; i < nf; i++){ if(nc < ft[i].sf->n) nc = ft[i].sf->n; if(ht != ft[1].sf->height){ fprint(2, "%s: %s.height=%d (!= %s.height=%d)\n", argv[0], ft[i].name, ft[i].sf->height, ft[0].name, ht); errs = 1; } if(as != ft[1].sf->ascent){ fprint(2, "%s: %s.ascent=%d (!= %s.ascent=%d)\n", argv[0], ft[i].name, ft[i].sf->ascent, ft[0].name, ht); errs = 1; } } if(errs) exits("param mismatch"); fc = (Fontchar *)malloc(nc*sizeof(Fontchar)); b = balloc(Rect(0, 0, nc*64, ht), ft[0].bm->ldepth); if(b == 0 || fc == 0){ fprint(2, "%s: couldn't malloc %d chars\n", argv0, nc); exits("out of memory"); } bitblt(b, b->r.min, b, b->r, Zero); choose(fc, b, nc, ht, as); wrbitmapfile(1, b); bitblt(&screen, screen.r.min, b, b->r, S); bflush();sleep(5000); f = subfalloc(nc, ht, as, fc, b, ~0, ~0); wrsubfontfile(1, f); exits(0); }
void cut(Text *t, int w, int save, int check) { long p0, p1; Flayer *l; l = &t->l[w]; p0 = l->p0; p1 = l->p1; if(p0 == p1) return; if(p0 < 0) panic("cut"); if(save) snarf(t, w); outTsll(Tcut, t->tag, p0, p1); flsetselect(l, p0, p0); t->lock++; hcut(t->tag, p0, p1-p0); if(check) hcheck(t->tag); }
int inmesg(Tmesg type) { Rune buf[1025]; char cbuf[64]; int i, m; short s; long l, l1; vlong v; File *f; Posn p0, p1, p; Range r; String *str; char *c, *wdir; Rune *rp; Plumbmsg *pm; if(type > TMAX) panic("inmesg"); journal(0, tname[type]); inp = indata; switch(type){ case -1: panic("rcv error"); default: fprint(2, "unknown type %d\n", type); panic("rcv unknown"); case Tversion: tversion = inshort(); journaln(0, tversion); break; case Tstartcmdfile: v = invlong(); /* for 64-bit pointers */ journaln(0, v); Strdupl(&genstr, samname); cmd = newfile(); cmd->unread = 0; outTsv(Hbindname, cmd->tag, v); outTs(Hcurrent, cmd->tag); logsetname(cmd, &genstr); cmd->rasp = listalloc('P'); cmd->mod = 0; if(cmdstr.n){ loginsert(cmd, 0L, cmdstr.s, cmdstr.n); Strdelete(&cmdstr, 0L, (Posn)cmdstr.n); } fileupdate(cmd, FALSE, TRUE); outT0(Hunlock); break; case Tcheck: /* go through whichfile to check the tag */ outTs(Hcheck, whichfile(inshort())->tag); break; case Trequest: f = whichfile(inshort()); p0 = inlong(); p1 = p0+inshort(); journaln(0, p0); journaln(0, p1-p0); if(f->unread) panic("Trequest: unread"); if(p1>f->b.nc) p1 = f->b.nc; if(p0>f->b.nc) /* can happen e.g. scrolling during command */ p0 = f->b.nc; if(p0 == p1){ i = 0; r.p1 = r.p2 = p0; }else{ r = rdata(f->rasp, p0, p1-p0); i = r.p2-r.p1; bufread(&f->b, r.p1, buf, i); } buf[i]=0; outTslS(Hdata, f->tag, r.p1, tmprstr(buf, i+1)); break; case Torigin: s = inshort(); l = inlong(); l1 = inlong(); journaln(0, l1); lookorigin(whichfile(s), l, l1); break; case Tstartfile: termlocked++; f = whichfile(inshort()); if(!f->rasp) /* this might be a duplicate message */ f->rasp = listalloc('P'); current(f); outTsv(Hbindname, f->tag, invlong()); /* for 64-bit pointers */ outTs(Hcurrent, f->tag); journaln(0, f->tag); if(f->unread) load(f); else{ if(f->b.nc>0){ rgrow(f->rasp, 0L, f->b.nc); outTsll(Hgrow, f->tag, 0L, f->b.nc); } outTs(Hcheck0, f->tag); moveto(f, f->dot.r); } break; case Tworkfile: i = inshort(); f = whichfile(i); current(f); f->dot.r.p1 = inlong(); f->dot.r.p2 = inlong(); f->tdot = f->dot.r; journaln(0, i); journaln(0, f->dot.r.p1); journaln(0, f->dot.r.p2); break; case Ttype: f = whichfile(inshort()); p0 = inlong(); journaln(0, p0); journal(0, (char*)inp); str = tmpcstr((char*)inp); i = str->n; loginsert(f, p0, str->s, str->n); if(fileupdate(f, FALSE, FALSE)) seq++; if(f==cmd && p0==f->b.nc-i && i>0 && str->s[i-1]=='\n'){ freetmpstr(str); termlocked++; termcommand(); }else freetmpstr(str); f->dot.r.p1 = f->dot.r.p2 = p0+i; /* terminal knows this already */ f->tdot = f->dot.r; break; case Tcut: f = whichfile(inshort()); p0 = inlong(); p1 = inlong(); journaln(0, p0); journaln(0, p1); logdelete(f, p0, p1); if(fileupdate(f, FALSE, FALSE)) seq++; f->dot.r.p1 = f->dot.r.p2 = p0; f->tdot = f->dot.r; /* terminal knows the value of dot already */ break; case Tpaste: f = whichfile(inshort()); p0 = inlong(); journaln(0, p0); for(l=0; l<snarfbuf.nc; l+=m){ m = snarfbuf.nc-l; if(m>BLOCKSIZE) m = BLOCKSIZE; bufread(&snarfbuf, l, genbuf, m); loginsert(f, p0, tmprstr(genbuf, m)->s, m); } if(fileupdate(f, FALSE, TRUE)) seq++; f->dot.r.p1 = p0; f->dot.r.p2 = p0+snarfbuf.nc; f->tdot.p1 = -1; /* force telldot to tell (arguably a BUG) */ telldot(f); outTs(Hunlockfile, f->tag); break; case Tsnarf: i = inshort(); p0 = inlong(); p1 = inlong(); snarf(whichfile(i), p0, p1, &snarfbuf, 0); break; case Tstartnewfile: v = invlong(); Strdupl(&genstr, empty); f = newfile(); f->rasp = listalloc('P'); outTsv(Hbindname, f->tag, v); logsetname(f, &genstr); outTs(Hcurrent, f->tag); current(f); load(f); break; case Twrite: termlocked++; i = inshort(); journaln(0, i); f = whichfile(i); addr.r.p1 = 0; addr.r.p2 = f->b.nc; if(f->name.s[0] == 0) error(Enoname); Strduplstr(&genstr, &f->name); writef(f); break; case Tclose: termlocked++; i = inshort(); journaln(0, i); f = whichfile(i); current(f); trytoclose(f); /* if trytoclose fails, will error out */ delete(f); break; case Tlook: f = whichfile(inshort()); termlocked++; p0 = inlong(); p1 = inlong(); journaln(0, p0); journaln(0, p1); setgenstr(f, p0, p1); for(l = 0; l<genstr.n; l++){ i = genstr.s[l]; if(utfrune(".*+?(|)\\[]^$", i)){ str = tmpcstr("\\"); Strinsert(&genstr, str, l++); freetmpstr(str); } } Straddc(&genstr, '\0'); nextmatch(f, &genstr, p1, 1); moveto(f, sel.p[0]); break; case Tsearch: termlocked++; if(curfile == 0) error(Enofile); if(lastpat.s[0] == 0) panic("Tsearch"); nextmatch(curfile, &lastpat, curfile->dot.r.p2, 1); moveto(curfile, sel.p[0]); break; case Tsend: termlocked++; inshort(); /* ignored */ p0 = inlong(); p1 = inlong(); setgenstr(cmd, p0, p1); bufreset(&snarfbuf); bufinsert(&snarfbuf, (Posn)0, genstr.s, genstr.n); outTl(Hsnarflen, genstr.n); if(genstr.s[genstr.n-1] != '\n') Straddc(&genstr, '\n'); loginsert(cmd, cmd->b.nc, genstr.s, genstr.n); fileupdate(cmd, FALSE, TRUE); cmd->dot.r.p1 = cmd->dot.r.p2 = cmd->b.nc; telldot(cmd); termcommand(); break; case Tdclick: f = whichfile(inshort()); p1 = inlong(); doubleclick(f, p1); f->tdot.p1 = f->tdot.p2 = p1; telldot(f); outTs(Hunlockfile, f->tag); break; case Tstartsnarf: if (snarfbuf.nc <= 0) { /* nothing to export */ outTs(Hsetsnarf, 0); break; } c = 0; i = 0; m = snarfbuf.nc; if(m > SNARFSIZE) { m = SNARFSIZE; dprint("?warning: snarf buffer truncated\n"); } rp = malloc(m*sizeof(Rune)); if(rp){ bufread(&snarfbuf, 0, rp, m); c = Strtoc(tmprstr(rp, m)); free(rp); i = strlen(c); } outTs(Hsetsnarf, i); if(c){ Write(1, c, i); free(c); } else dprint("snarf buffer too long\n"); break; case Tsetsnarf: m = inshort(); if(m > SNARFSIZE) error(Etoolong); c = malloc(m+1); if(c){ for(i=0; i<m; i++) c[i] = rcvchar(); c[m] = 0; str = tmpcstr(c); free(c); bufreset(&snarfbuf); bufinsert(&snarfbuf, (Posn)0, str->s, str->n); freetmpstr(str); outT0(Hunlock); } break; case Tack: waitack = 0; break; case Tplumb: f = whichfile(inshort()); p0 = inlong(); p1 = inlong(); pm = emalloc(sizeof(Plumbmsg)); pm->src = strdup("sam"); pm->dst = 0; /* construct current directory */ c = Strtoc(&f->name); if(c[0] == '/') pm->wdir = c; else{ wdir = emalloc(1024); getwd(wdir, 1024); pm->wdir = emalloc(1024); snprint(pm->wdir, 1024, "%s/%s", wdir, c); cleanname(pm->wdir); free(wdir); free(c); } c = strrchr(pm->wdir, '/'); if(c) *c = '\0'; pm->type = strdup("text"); if(p1 > p0) pm->attr = nil; else{ p = p0; while(p0>0 && (i=filereadc(f, p0 - 1))!=' ' && i!='\t' && i!='\n') p0--; while(p1<f->b.nc && (i=filereadc(f, p1))!=' ' && i!='\t' && i!='\n') p1++; sprint(cbuf, "click=%ld", p-p0); pm->attr = plumbunpackattr(cbuf); } if(p0==p1 || p1-p0>=BLOCKSIZE){ plumbfree(pm); break; } setgenstr(f, p0, p1); pm->data = Strtoc(&genstr); pm->ndata = strlen(pm->data); c = plumbpack(pm, &i); if(c != 0){ outTs(Hplumb, i); Write(1, c, i); free(c); } plumbfree(pm); break; case Texit: exits(0); } return TRUE; }
int plan9(File *f, int type, String *s, int nest) { long l; int m; int volatile pid; int fd; int retcode; int pipe1[2], pipe2[2]; if(s->s[0]==0 && plan9cmd.s[0]==0) error(Enocmd); else if(s->s[0]) Strduplstr(&plan9cmd, s); if(downloaded){ samerr(errfile); remove(errfile); } if(type!='!' && pipe(pipe1)==-1) error(Epipe); if(type=='|') snarf(f, addr.r.p1, addr.r.p2, &plan9buf, 1); if((pid=fork()) == 0){ setname(f); if(downloaded){ /* also put nasty fd's into errfile */ fd = create(errfile, 1, 0666L); if(fd < 0) fd = create("/dev/null", 1, 0666L); dup(fd, 2); close(fd); /* 2 now points at err file */ if(type == '>') dup(2, 1); else if(type=='!'){ dup(2, 1); fd = open("/dev/null", 0); dup(fd, 0); close(fd); } } if(type != '!') { if(type=='<' || type=='|') dup(pipe1[1], 1); else if(type == '>') dup(pipe1[0], 0); close(pipe1[0]); close(pipe1[1]); } if(type == '|'){ if(pipe(pipe2) == -1) exits("pipe"); if((pid = fork())==0){ /* * It's ok if we get SIGPIPE here */ close(pipe2[0]); io = pipe2[1]; if(retcode=!setjmp(mainloop)){ /* assignment = */ char *c; for(l = 0; l<plan9buf.nc; l+=m){ m = plan9buf.nc-l; if(m>BLOCKSIZE-1) m = BLOCKSIZE-1; bufread(&plan9buf, l, genbuf, m); genbuf[m] = 0; c = Strtoc(tmprstr(genbuf, m+1)); Write(pipe2[1], c, strlen(c)); free(c); } } exits(retcode? "error" : 0); } if(pid==-1){ fprint(2, "Can't fork?!\n"); exits("fork"); } dup(pipe2[0], 0); close(pipe2[0]); close(pipe2[1]); } if(type=='<'){ close(0); /* so it won't read from terminal */ open("/dev/null", 0); } execl(SHPATH, SH, "-c", Strtoc(&plan9cmd), (char *)0); exits("exec"); } if(pid == -1) error(Efork); if(type=='<' || type=='|'){ int nulls; if(downloaded && addr.r.p1 != addr.r.p2) outTl(Hsnarflen, addr.r.p2-addr.r.p1); snarf(f, addr.r.p1, addr.r.p2, &snarfbuf, 0); logdelete(f, addr.r.p1, addr.r.p2); close(pipe1[1]); io = pipe1[0]; f->tdot.p1 = -1; f->ndot.r.p2 = addr.r.p2+readio(f, &nulls, 0, FALSE); f->ndot.r.p1 = addr.r.p2; closeio((Posn)-1); }else if(type=='>'){ close(pipe1[0]); io = pipe1[1]; bpipeok = 1; writeio(f); bpipeok = 0; closeio((Posn)-1); } retcode = waitfor(pid); if(type=='|' || type=='<') if(retcode!=0) warn(Wbadstatus); if(downloaded) checkerrs(); if(!nest) dprint("!\n"); return retcode; }
void show_vtw_v6(void (*print)(const vtw_t *)) { fatp_t *base, *lim; fatp_t **hash, **port; size_t n; fatp_ctl_t fat_tcpv6; vtw_ctl_t vtw_tcpv6[VTW_NCLASS]; int i; int mem = 0; void *p; if ((p = lookup("fat_tcpv6")) == NULL) return; snarf(p, &fat_tcpv6, sizeof(fat_tcpv6)); if ((p = lookup("vtw_tcpv6")) == NULL) return; snarf(p, &vtw_tcpv6[0], sizeof(vtw_tcpv6)); mem += sizeof(fat_tcpv6); mem += sizeof(vtw_tcpv6); for (i = 0; i < VTW_NCLASS; ++i) { vtw_v6_t *kbase, *klim; vtw_v6_t *ubase; ptrdiff_t delta; kbase = vtw_tcpv6[i].base.v6; klim = vtw_tcpv6[i].lim.v6; if (!kbase || !klim) continue; n = (klim - kbase + 1); if (!i) { if ((ubase = malloc(n * sizeof(*kbase))) == NULL) err(EXIT_FAILURE, NULL); snarf(kbase, ubase, n * sizeof(*ubase)); mem += n * sizeof(*ubase); } else { ubase = vtw_tcpv6[0].base.v6; } delta = ubase - kbase; vtw_tcpv6[i].base.v6 += delta; vtw_tcpv6[i].lim.v6 += delta; vtw_tcpv6[i].alloc.v6 += delta; vtw_tcpv6[i].fat = &fat_tcpv6; if (vtw_tcpv6[i].oldest.v6) vtw_tcpv6[i].oldest.v6 += delta; } base = fat_tcpv6.base; lim = fat_tcpv6.lim; if (!base || !lim) goto end; mem += (lim - base + 1) * sizeof(*base); fat_tcpv6.base = malloc((lim - base + 1) * sizeof(*base)); if (fat_tcpv6.base == NULL) err(EXIT_FAILURE, NULL); fat_tcpv6.lim = fat_tcpv6.base + (lim - base); snarf(base, fat_tcpv6.base, sizeof(*base) * (lim - base + 1)); fat_tcpv6.vtw = &vtw_tcpv6[0]; fat_tcpv6.free = fat_tcpv6.base + (fat_tcpv6.free - base); n = fat_tcpv6.mask + 1; hash = fat_tcpv6.hash; port = fat_tcpv6.port; fat_tcpv6.hash = malloc(n * sizeof(*hash)); fat_tcpv6.port = malloc(n * sizeof(*port)); if (fat_tcpv6.hash == NULL || fat_tcpv6.port == NULL) err(EXIT_FAILURE, NULL); snarf(hash, fat_tcpv6.hash, n * sizeof(*hash)); snarf(port, fat_tcpv6.port, n * sizeof(*port)); end: process_vtw(&vtw_tcpv6[0], print); #if 0 if (Vflag && vflag) { printf("total memory for VTW in current config: %d bytes %f MB\n" ,mem ,mem / (1024.0 * 1024)); } #endif }
int inmesg(Tmesg type) { Rune buf[1025]; int i, m; short s; long l, l1; File *f; Posn p0, p1; Range r; String *str; char *c; Rune *rp; if(type > TMAX) panic("inmesg"); journal(0, tname[type]); inp = indata; switch(type) { case -1: panic("rcv error"); default: fprint(2, "unknown type %d\n", type); panic("rcv unknown"); case Tversion: tversion = inshort(); journaln(0, tversion); break; case Tstartcmdfile: l = invlong(); /* for 64-bit pointers */ journaln(0, l); Strdupl(&genstr, samname); cmd = newfile(); outTsv(Hbindname, cmd->tag, l); outTs(Hcurrent, cmd->tag); Fsetname(cmd, &genstr); cmd->rasp = emalloc(sizeof(List)); cmd->state = Clean; if(cmdstr.n) { Finsert(cmd, &cmdstr, 0L); Strdelete(&cmdstr, 0L, (Posn)cmdstr.n); } Fupdate(cmd, FALSE, TRUE); outT0(Hunlock); break; case Tcheck: /* go through whichfile to check the tag */ outTs(Hcheck, whichfile(inshort())->tag); break; case Trequest: f = whichfile(inshort()); p0 = inlong(); p1 = p0+inshort(); journaln(0, p0); journaln(0, p1-p0); if(f->state == Unread) panic("Trequest: unread"); if(p1>f->nrunes) p1 = f->nrunes; if(p0>f->nrunes) /* can happen e.g. scrolling during command */ p0 = f->nrunes; if(p0 == p1) { i = 0; r.p1 = r.p2 = p0; } else { r = rdata(f->rasp, p0, p1-p0); i = r.p2-r.p1; if(Fchars(f, buf, r.p1, r.p2)!=i) panic("Trequest 2"); } buf[i]=0; outTslS(Hdata, f->tag, r.p1, tmprstr(buf, i+1)); break; case Torigin: s = inshort(); l = inlong(); l1 = inlong(); journaln(0, l1); lookorigin(whichfile(s), l, l1); break; case Tstartfile: termlocked++; f = whichfile(inshort()); if(!f->rasp) /* this might be a duplicate message */ f->rasp = emalloc(sizeof(List)); current(f); outTsv(Hbindname, f->tag, invlong()); /* for 64-bit pointers */ outTs(Hcurrent, f->tag); journaln(0, f->tag); if(f->state == Unread) load(f); else { if(f->nrunes>0) { rgrow(f->rasp, 0L, f->nrunes); outTsll(Hgrow, f->tag, 0L, f->nrunes); } outTs(Hcheck0, f->tag); moveto(f, f->dot.r); } break; case Tworkfile: i = inshort(); f = whichfile(i); current(f); f->dot.r.p1 = inlong(); f->dot.r.p2 = inlong(); f->tdot = f->dot.r; journaln(0, i); journaln(0, f->dot.r.p1); journaln(0, f->dot.r.p2); break; case Ttype: f = whichfile(inshort()); p0 = inlong(); journaln(0, p0); journal(0, (char*)inp); str = tmpcstr((char*)inp); i = str->n; Finsert(f, str, p0); if(Fupdate(f, FALSE, FALSE)) modnum++; if(f==cmd && p0==f->nrunes-i && i>0 && str->s[i-1]=='\n') { freetmpstr(str); termlocked++; termcommand(); } else freetmpstr(str); f->dot.r.p1 = f->dot.r.p2 = p0+i; /* terminal knows this already */ f->tdot = f->dot.r; break; case Tcut: f = whichfile(inshort()); p0 = inlong(); p1 = inlong(); journaln(0, p0); journaln(0, p1); Fdelete(f, p0, p1); if(Fupdate(f, FALSE, FALSE)) modnum++; f->dot.r.p1 = f->dot.r.p2 = p0; f->tdot = f->dot.r; /* terminal knows the value of dot already */ break; case Tpaste: f = whichfile(inshort()); p0 = inlong(); journaln(0, p0); for(l=0; l<snarfbuf->nrunes; l+=m) { m = snarfbuf->nrunes-l; if(m>BLOCKSIZE) m = BLOCKSIZE; Bread(snarfbuf, genbuf, m, l); Finsert(f, tmprstr(genbuf, m), p0); } if(Fupdate(f, FALSE, TRUE)) modnum++; f->dot.r.p1 = p0; f->dot.r.p2 = p0+snarfbuf->nrunes; f->tdot.p1 = -1; /* force telldot to tell (arguably a BUG) */ telldot(f); outTs(Hunlockfile, f->tag); break; case Tsnarf: i = inshort(); p0 = inlong(); p1 = inlong(); snarf(whichfile(i), p0, p1, snarfbuf, 0); break; case Tstartnewfile: l = invlong(); Strdupl(&genstr, empty); f = newfile(); f->rasp = emalloc(sizeof(List)); outTsv(Hbindname, f->tag, l); Fsetname(f, &genstr); outTs(Hcurrent, f->tag); current(f); load(f); break; case Twrite: termlocked++; i = inshort(); journaln(0, i); f = whichfile(i); addr.r.p1 = 0; addr.r.p2 = f->nrunes; if(f->name.s[0] == 0) error(Enoname); Strduplstr(&genstr, &f->name); writef(f); break; case Tclose: termlocked++; i = inshort(); journaln(0, i); f = whichfile(i); current(f); trytoclose(f); /* if trytoclose fails, will error out */ delete(f); break; case Tlook: f = whichfile(inshort()); termlocked++; p0 = inlong(); p1 = inlong(); journaln(0, p0); journaln(0, p1); setgenstr(f, p0, p1); for(l = 0; l<genstr.n; l++) { i = genstr.s[l]; if(utfrune(".*+?(|)\\[]^$", i)) Strinsert(&genstr, tmpcstr("\\"), l++); } Straddc(&genstr, '\0'); nextmatch(f, &genstr, p1, 1); moveto(f, sel.p[0]); break; case Tsearch: termlocked++; if(curfile == 0) error(Enofile); if(lastpat.s[0] == 0) panic("Tsearch"); nextmatch(curfile, &lastpat, curfile->dot.r.p2, 1); moveto(curfile, sel.p[0]); break; case Tsend: termlocked++; inshort(); /* ignored */ p0 = inlong(); p1 = inlong(); setgenstr(cmd, p0, p1); Bdelete(snarfbuf, (Posn)0, snarfbuf->nrunes); Binsert(snarfbuf, &genstr, (Posn)0); outTl(Hsnarflen, genstr.n); if(genstr.s[genstr.n-1] != '\n') Straddc(&genstr, '\n'); Finsert(cmd, &genstr, cmd->nrunes); Fupdate(cmd, FALSE, TRUE); cmd->dot.r.p1 = cmd->dot.r.p2 = cmd->nrunes; telldot(cmd); termcommand(); break; case Tdclick: f = whichfile(inshort()); p1 = inlong(); doubleclick(f, p1); f->tdot.p1 = f->tdot.p2 = p1; telldot(f); outTs(Hunlockfile, f->tag); break; case Tstartsnarf: if (snarfbuf->nrunes <= 0) { /* nothing to export */ outTs(Hsetsnarf, 0); break; } c = 0; i = 0; m = snarfbuf->nrunes; if(m > 32000) { /* tmprstr stores len in a short */ m = 32000; dprint("?warning: snarf buffer truncated\n"); } rp = malloc(m*sizeof(Rune)); if(rp) { Bread(snarfbuf, rp, m, 0); c = Strtoc(tmprstr(rp, m)); free(rp); i = strlen(c); } outTs(Hsetsnarf, i); if(c) { Write(1, c, i); free(c); } else dprint("snarf buffer too long\n"); break; case Tsetsnarf: m = inshort(); if(m > SNARFSIZE) error(Etoolong); c = malloc(m+1); if(c) { for(i=0; i<m; i++) c[i] = rcvchar(); c[m] = 0; str = tmpcstr(c); free(c); Bdelete(snarfbuf, (Posn)0, snarfbuf->nrunes); Binsert(snarfbuf, str, (Posn)0); freetmpstr(str); outT0(Hunlock); } break; case Tack: waitack = 0; break; case Texit: exits(0); } return TRUE; }
void initialize_data () { const char data_root[] = "../../vhti/bindings/perl/examples/"; valid_svb = snarf (data_root, "voter-Joe_Voter_#0/svb.xml"); valid_svbs = snarf (data_root, "svbs.xml"); valid_bb = snarf (data_root, "bb.xml"); valid_rbb = snarf (data_root, "rbb.xml"); valid_rbb_before = snarf (data_root, "rbb.xml"); valid_rbb_after = snarf (data_root, "shuffled-rbb-#0.xml"); valid_auth_pd = snarf (data_root, "auth0/partial-decrypt.xml"); valid_auth_pds = snarf (data_root, "auth-partial-decrypts.xml"); valid_auth_pds_4vc = snarf (data_root, "partial-decrypts-4vc.xml"); valid_pd_ballot_box = snarf (data_root, "partially-decrypted-bb.xml"); valid_sbb = snarf (data_root, "sbb.xml"); valid_prvkey = snarf (data_root, "pollsite-private-key.xml"); valid_pubkey = snarf (data_root, "pollsite-pubkey.xml"); valid_committed_authority = snarf (data_root, "committed-auth-0.xml"); valid_sv_proof = snarf (data_root, "shuffle-validity-proof-#0.xml"); valid_pvc_boxes = snarf (data_root, "pre-vc-boxes.xml"); valid_vr = snarf (data_root, "voter-roll.xml"); valid_authority = snarf (data_root, "auth0.xml"); valid_trustee_dict_comm = snarf (data_root, "trustee-0-dict_comm.xml"); valid_trustee_dict_secrets = snarf (data_root, "trustee-0-revealed_dict_secrets.xml"); valid_trustee_dict_secrets_box = snarf (data_root, "trustee_revealed_dict_secrets_box.xml"); valid_trustee_pubkey = snarf (data_root, "trustee-0-pubkey.xml"); }
void type(Flayer *l, int res) /* what a bloody mess this is */ { Text *t = (Text *)l->user1; Rune buf[100]; Rune *p = buf; int c, backspacing; // long a, a0, a2, ao; long a, a0; int scrollkey; scrollkey = 0; if(res == RKeyboard) scrollkey = nontypingkey(qpeekc()); /* ICK */ if(hostlock || t->lock){ kbdblock(); return; } a = l->p0; if(a!=l->p1 && !scrollkey){ flushtyping(1); cut(t, t->front, 1, 1); return; /* it may now be locked */ } backspacing = 0; while((c = kbdchar())>0){ if(res == RKeyboard){ if(nontypingkey(c) || c==ESC) break; /* backspace, ctrl-u, ctrl-w, del */ //if(c=='\b' || c==0x15 || c==0x17 || c==0x7F){ if(c=='\b' || c==0x06 || c==0x17 || c==0x7F || c==0x11){ backspacing = 1; break; } } //*p++ = c; if(spacesindent && c == '\t'){ int i, col, n; col = getcol(&t->rasp, a); n = maxtab - col % maxtab; for(i = 0; i < n && p < buf+nelem(buf); i++) *p++ = ' '; } else *p++ = c; if(autoindent) if(c == '\n'){ /* autoindent */ int cursor, ch; cursor = ctlu(&t->rasp, 0, a+(p-buf)-1); while(p < buf+nelem(buf)){ ch = raspc(&t->rasp, cursor++); if(ch == ' ' || ch == '\t') *p++ = ch; else break; } } if(c == '\n' || p >= buf+nelem(buf)) break; } if(p > buf){ if(typestart < 0) typestart = a; if(typeesc < 0) typeesc = a; hgrow(t->tag, a, p-buf, 0); t->lock++; /* pretend we Trequest'ed for hdatarune*/ hdatarune(t->tag, a, buf, p-buf); a += p-buf; l->p0 = a; l->p1 = a; typeend = a; if(c=='\n' || typeend-typestart>100) flushtyping(0); onethird(l, a); } if(c==SCROLLKEY || c==PAGEDOWN){ flushtyping(0); center(l, l->origin+l->f.nchars+1); }else if(c==BACKSCROLLKEY || c==PAGEUP){ flushtyping(0); a0 = l->origin-l->f.nchars; if(a0 < 0) a0 = 0; center(l, a0); }else if(c == RIGHTARROW){ flushtyping(0); a0 = l->p0; if(a0 < t->rasp.nrunes) a0++; flsetselect(l, a0, a0); center(l, a0); }else if(c == LEFTARROW){ flushtyping(0); a0 = l->p0; if(a0 > 0) a0--; flsetselect(l, a0, a0); center(l, a0); }else if(c == HOMEKEY){ flushtyping(0); center(l, 0); }else if(c == ENDKEY){ flushtyping(0); center(l, t->rasp.nrunes); }else if(c == LINESTART || c == LINEEND){ flushtyping(1); if(c == LINESTART) while(a > 0 && raspc(&t->rasp, a-1)!='\n') a--; else while(a < t->rasp.nrunes && raspc(&t->rasp, a)!='\n') a++; l->p0 = l->p1 = a; for(l=t->l; l<&t->l[NL]; l++) if(l->textfn) flsetselect(l, l->p0, l->p1); }else if(backspacing && !hostlock){ /* backspacing immediately after outcmd(): sorry */ if(l->f.p0>0 && a>0){ switch(c){ case '\b': case 0x7F: /* del */ //case 0x11: /* del */ //l->p0 = a-1; l->p0 = del(&t->rasp, l->origin, a); break; case 0x15: /* ctrl-u */ //case 0x06: /* ctrl-f */ l->p0 = ctlu(&t->rasp, l->origin, a); break; case 0x17: /* ctrl-w */ l->p0 = ctlw(&t->rasp, l->origin, a); break; } l->p1 = a; if(l->p1 != l->p0){ /* cut locally if possible */ if(typestart<=l->p0 && l->p1<=typeend){ t->lock++; /* to call hcut */ hcut(t->tag, l->p0, l->p1-l->p0); /* hcheck is local because we know rasp is contiguous */ hcheck(t->tag); }else{ flushtyping(0); cut(t, t->front, 0, 1); } } if(typeesc >= l->p0) typeesc = l->p0; if(typestart >= 0){ if(typestart >= l->p0) typestart = l->p0; typeend = l->p0; if(typestart == typeend){ typestart = -1; typeend = -1; modified = 0; } } } }else{ if(c==ESC && typeesc>=0){ l->p0 = typeesc; l->p1 = a; flushtyping(1); } // if(c==MID){ // flushtyping(1); // a2 = a; // while(a2 > 0 && raspc(&t->rasp, a2-1)!='\n') // a2--; // if(a2!=t->rasp.nrunes){ // a2--; // } // flushtyping(0); // flsetselect(l, a, a); // outTsll(Torigin, t->tag, a2, 1L); // } // if(c==CWIN){ // if (inCMD==0) { // tp = t; // t = &cmd; // for(l=t->l; l->textfn==0; l++) // ; // current(l); // flushtyping(0); // a = t->rasp.nrunes; // flsetselect(l, a, a); // center(l, a); // inCMD = 1; // } else { // for(l=tp->l; l->textfn==0; l++) // ; // current(l); // flushtyping(0); // inCMD = 0; // } // } // if(c==GFO) // sendcmd("<gfo", 4, t); // if(c==GFU) // sendcmd("<gfu", 4, t); // if(c==GI) // sendcmd("<gi", 3, t); // if(c==GIE) // sendcmd("<gie", 4, t); // if(c==GIEI) // sendcmd("<giei", 5, t); // if(c==GP) // sendcmd("<gp", 3, t); // if(c==MK) // sendcmd("!mk", 3, t); // if(c==MCO) // sendcmd("|mco", 4, t); // if(c==MLI) // sendcmd(",|mli", 5, t); // if(c==MFU) // sendcmd("<mfu", 4, t); // if(c==UNDO) // sendcmd("u", 1, t); // if(c==REDO) // sendcmd("u-1", 3, t); // if(c==ALL) // sendcmd(",", 1, t); // if(c==MARK) // sendcmd("k", 1, t); // if(c==GO) // sendcmd("'", 1, t); // if(c==SEL) // sendcmd("',.", 3, t); // if(c==SAVE){ // for(l=t->l; l->textfn==0; l++) // ; // current(l); // flushtyping(0); // ao = l->p0; // a = t->rasp.nrunes; // flsetselect(l, a, a); // if(raspc(&t->rasp, a-1)!='\n'){ // *p++ = '\n'; // if(typestart < 0) // typestart = a; // if(typeesc < 0) // typeesc = a; // hgrow(t->tag, a, p-buf, 0); // t->lock++; /* pretend we Trequest'ed for hdatarune*/ // hdatarune(t->tag, a, buf, p-buf); // a += p-buf; // } // l->p0 = ao; // l->p1 = ao; // typeend = ao; // flushtyping(0); // flsetselect(l, ao, ao); // center(l, ao); // sendcmd("w", 1, t); // } // if(c==FMT) // sendcmd("|par", 4, t); // if(c==FFMT) // sendcmd(",|par", 5, t); // if(c==WC) // sendcmd(">wc", 3, t); // if(c==MI) // sendcmd("|a+", 3, t); // if(c==LI) // sendcmd("|a-", 3, t); // if(c==RIOEXCH){ // snarf(t, t->front); // outT0(Tstartsnarf); // setlock(); // } // if(c==PLUMB){ // if(hversion > 0) // outTsll(Tplumb, t->tag, which->p0, which->p1); // } // if(c==LOOK){ // outTsll(Tlook, t->tag, which->p0, which->p1); // setlock(); // } // if(c==NEW){ // sweeptext(1, 0); // } // if(c==CLOSE){ // t=(Text *)l->user1; // if (t->nwin>1) // closeup(l); // else if(t!=&cmd) { // outTs(Tclose, t->tag); // setlock(); // } // } for(l=t->l; l<&t->l[NL]; l++) if(l->textfn) flsetselect(l, l->p0, l->p1); switch(c) { case CUT: flushtyping(0); cut(t, t->front, 1, 1); break; case COPY: flushtyping(0); snarf(t, t->front); break; case PASTE: flushtyping(0); paste(t, t->front); break; } } }