void hiccough(char *s) { if(rescuing) exit(EXIT_FAILURE); if(s) dprint(L"%s\n", s); resetcmd(); resetxec(); resetsys(); if(io > 0) close(io); if(undobuf->nrunes) Bdelete(undobuf, (Posn)0, undobuf->nrunes); update(); if (curfile) { if (curfile->state==Unread) curfile->state = Clean; else if (downloaded) outTs(Hcurrent, curfile->tag); } longjmp(mainloop, 1); }
void cmdloop(void) { Cmd *cmdp; File *ocurfile; int loaded; for(;;){ if(!downloaded && curfile && curfile->unread) load(curfile); if((cmdp = parsecmd(0))==0){ if(downloaded){ rescue(); exits("eof"); } break; } ocurfile = curfile; loaded = curfile && !curfile->unread; if(cmdexec(curfile, cmdp) == 0) break; freecmd(); cmdupdate(); update(); if(downloaded && curfile && (ocurfile!=curfile || (!loaded && !curfile->unread))) outTs(Hcurrent, curfile->tag); /* don't allow type ahead on files that aren't bound */ if(downloaded && curfile && curfile->rasp == 0) terminp = termoutp; } }
void state(File *f, int cleandirty) { if(f == cmd) return; f->unread = FALSE; if(downloaded && whichmenu(f)>=0){ /* else flist or menu */ if(f->mod && cleandirty!=Dirty) outTs(Hclean, f->tag); else if(!f->mod && cleandirty==Dirty) outTs(Hdirty, f->tag); } if(cleandirty == Clean) f->mod = FALSE; else f->mod = TRUE; }
void startup(char *machine, int Rflag, char **argv, char **files) { if(machine) connectto(machine, files); if(!Rflag) bootterm(machine, argv); downloaded = 1; outTs(Hversion, VERSION); }
void delfile(File *f) { int w = whichmenu(f); if(w < 0) /* e.g. x/./D */ return; if(downloaded) outTs(Hdelname, f->tag); dellist(&file, w); fileclose(f); }
File * newfile(void) { File *f; f = fileopen(); inslist(&file, 0, f); f->tag = tag++; if(downloaded) outTs(Hnewname, f->tag); /* already sorted; file name is "" */ return f; }
void hiccough(char *s) { File *f; int i; if(rescuing) exits("rescue"); if(s) dprint("%s\n", s); resetcmd(); resetxec(); resetsys(); if(io > 0) close(io); /* * back out any logged changes & restore old sequences */ for(i=0; i<file.nused; i++) { f = file.filepptr[i]; if(f==cmd) continue; if(f->seq==seq) { bufdelete(&f->epsilon, 0, f->epsilon.nc); f->seq = f->prevseq; f->dot.r = f->prevdot; f->mark = f->prevmark; state(f, f->prevmod ? Dirty: Clean); } } update(); if (curfile) { if (curfile->unread) curfile->unread = FALSE; else if (downloaded) outTs(Hcurrent, curfile->tag); } longjmp(mainloop, 1); }
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; }
void menu3hit(void) { Rectangle r; Flayer *l; int m, i; Text *t; mw = -1; switch(m = menuhit(3, &mouse, &menu3)){ case -1: break; case New: if(!lock) sweeptext(1, 0); break; case Xerox: case Reshape: if(!lock){ cursorswitch(&bullseye); buttons(Down); if((mouse.buttons&4) && (l = flwhich(mouse.xy)) && getr(&r)) duplicate(l, r, l->f.font, m==Reshape); else cursorswitch(cursor); buttons(Up); } break; case Close: if(!lock){ cursorswitch(&bullseye); buttons(Down); if((mouse.buttons&4) && (l = flwhich(mouse.xy)) && !lock){ t=(Text *)l->user1; if (t->nwin>1) closeup(l); else if(t!=&cmd) { outTs(Tclose, t->tag); setlock(); } } cursorswitch(cursor); buttons(Up); } break; case Write: if(!lock){ cursorswitch(&bullseye); buttons(Down); if((mouse.buttons&4) && (l = flwhich(mouse.xy))){ outTs(Twrite, ((Text *)l->user1)->tag); setlock(); }else cursorswitch(cursor); buttons(Up); } break; default: if(t = text[m-NMENU3]){ i = t->front; if(t->nwin==0 || t->l[i].textfn==0) return; /* not ready yet; try again later */ if(t->nwin>1 && which==&t->l[i]) do if(++i==NL) i = 0; while(i!=t->front && t->l[i].textfn==0); current(&t->l[i]); }else if(!lock) sweeptext(0, tag[m-NMENU3]); break; } }
void main(int argc, char *argv[]) { int i, got, scr; Text *t; Rectangle r; Flayer *nwhich; int fwdbut; if (argc >= 3 && strcmp(argv[1], "-r") == 0) { machine = argv[2]; } getscreen(argc, argv); fwdbut = scrollfwdbut(); iconinit(); initio(); scratch = alloc(100*RUNESIZE); nscralloc = 100; r = screen.r; r.max.y = r.min.y+Dy(r)/5; flstart(screen.clipr); rinit(&cmd.rasp); flnew(&cmd.l[0], stgettext, 1, &cmd); flinit(&cmd.l[0], r, font); cmd.nwin = 1; which = &cmd.l[0]; cmd.tag = Untagged; outTs(Tversion, VERSION); startnewfile(Tstartcmdfile, &cmd); got = 0; for(;;got = waitforio()){ if(hasunlocked && RESHAPED()) reshape(); if(got&RHost) rcv(); if(got&RExtern){ for(i=0; cmd.l[i].textfn==0; i++) ; current(&cmd.l[i]); flsetselect(which, cmd.rasp.nrunes, cmd.rasp.nrunes); type(which, RExtern); } if(got&RKeyboard) if(which) type(which, RKeyboard); else kbdblock(); if(got&RMouse){ if(lock==2 || !ptinrect(mouse.xy, screen.r)){ mouseunblock(); continue; } nwhich = flwhich(mouse.xy); scr = which && ptinrect(mouse.xy, which->scroll); if(mouse.buttons) flushtyping(1); if (chord == 1 && !mouse.buttons) chord = 0; if (chord) chord |= mouse.buttons; else if(mouse.buttons&1){ if(nwhich){ if(nwhich!=which) current(nwhich); else if(scr) scroll(which, 1, fwdbut == 3 ? 1 : 3); else{ t=(Text *)which->user1; if(flselect(which)){ outTsl(Tdclick, t->tag, which->p0); t->lock++; }else if(t!=&cmd) outcmd(); if(mouse.buttons&1) chord = mouse.buttons; } } }else if((mouse.buttons&2) && which){ if(scr) scroll(which, 2, 2); else menu2hit(); }else if((mouse.buttons&4)){ if(scr) scroll(which, 3, fwdbut == 3 ? 3 : 1); else menu3hit(); }else if((mouse.buttons&8)){ scrollone(which, 1); }else if((mouse.buttons&16)){ scrollone(which, 3); } mouseunblock(); } if(chord) { t = (Text *)which->user1; if(!t->lock){ int w = which-t->l; if(chord&2){ cut(t, w, 1, 1); chord &= ~2; } if(chord&4){ paste(t, w); chord &= ~4; } } } } }
void LteBtslogParserDlg::onParseBtnClicked() { if(btslogList.size() == 0) { return; } QApplication::setOverrideCursor(Qt::WaitCursor); ueidDec = ueidEdit->text().trimmed(); ueidHex = QString::number(ueidDec.toInt(), 16); crntiDec = crntiEdit->text().trimmed(); crntiHex = QString::number(crntiDec.toInt(), 16); QDir(".").mkpath("./output"); QString outFileName = tr("./output/btslog_ueid=%1_crnti=%2.txt").arg(ueidDec).arg(crntiDec); QFile outFile(outFileName); if(!outFile.open(QIODevice::WriteOnly)) { logWidget->append(tr("%1:%2 Fail to open file: %3").arg(__FILE__).arg(__LINE__).arg(QFileInfo(outFile).fileName())); QApplication::restoreOverrideCursor(); return; } QTextStream outTs(&outFile); for(int i = 0; i < btslogList.size(); ++i) { QFile inFile(btslogList.at(i)); if(!inFile.open(QIODevice::ReadOnly)) { logWidget->append(tr("%1:%2 Fail to open file: %3").arg(__FILE__).arg(__LINE__).arg(QFileInfo(inFile).fileName())); outFile.close(); QApplication::restoreOverrideCursor(); return; } if(enableDebug) { logWidget->append(tr("parsing %1...").arg(btslogList.at(i))); } QRegularExpression reCrntiDec(tr("\\bcrnti(\\s?)[:=](\\s?)%1\\b").arg(crntiDec)); QRegularExpression reCrntiHex(tr("\\bcrnti(\\s?)[:=](\\s?)0x%1\\b").arg(crntiHex)); QRegularExpression reUeidDec(tr("\\b(ueContextId|instanceId|ueId|UeId)(\\s?)[:=](\\s?)%1\\b").arg(ueidDec)); QRegularExpression reUeidHex(tr("\\bueId(\\s?)[:=](\\s?)0x%1\\b").arg(ueidHex)); if(enableDebug) { outTs << "reCrntiDec: " << reCrntiDec.pattern() << "\n"; outTs << "reCrntiHex: " << reCrntiHex.pattern() << "\n"; outTs << "reUeidDec: " << reUeidDec.pattern() << "\n"; outTs << "reUeidHex: " << reUeidHex.pattern() << "\n"; } QTextStream inTs(&inFile); while(!inTs.atEnd()) { QString line = inTs.readLine(); if(line.isEmpty()) { continue; } // if((line.contains("/LTE MAC/", Qt::CaseSensitive) || line.contains("/UEC/", Qt::CaseSensitive) || line.contains("/CELLC/", Qt::CaseSensitive) || line.contains("/L2TupuUl", Qt::CaseSensitive)) && // (line.contains("crnti=" + crntiDec) || line.contains("crnti:" + crntiDec) || line.contains("crnti = " + crntiDec) || // line.contains("crnti=0x" + crntiHex, Qt::CaseInsensitive) || line.contains("crnti: 0x" + crntiHex, Qt::CaseInsensitive) || line.contains("crnti = 0x" + crntiHex, Qt::CaseInsensitive) || // line.contains("ueContextId:" + ueidDec) || line.contains("instanceId:" + ueidDec) || line.contains("ueId:" + ueidDec) || line.contains("ueId: " + ueidDec) || line.contains("ueId=" + ueidDec) || line.contains("UeId = " + ueidDec) || // line.contains("ueId=0x" + ueidHex, Qt::CaseInsensitive) || line.contains("ueId: 0x" + ueidHex, Qt::CaseInsensitive) || line.contains("ueId = 0x" + ueidHex, Qt::CaseInsensitive))) // { // outTs << line << "\n"; // } if(line.contains("/LTE MAC/", Qt::CaseSensitive) || line.contains("/UEC/", Qt::CaseSensitive) || line.contains("/CELLC/", Qt::CaseSensitive) || line.contains("/L2TupuUl", Qt::CaseSensitive)) { if(reCrntiDec.match(line).hasMatch() || reCrntiHex.match(line).hasMatch() || reUeidDec.match(line).hasMatch() || reUeidHex.match(line).hasMatch()) { outTs << line << "\n"; } } } inFile.close(); } outFile.close(); QApplication::restoreOverrideCursor(); }
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 threadmain(int argc, char *argv[]) { int i, got, scr; Text *t; Rectangle r; Flayer *nwhich; getscreen(argc, argv); iconinit(); initio(); scratch = alloc(100*RUNESIZE); nscralloc = 100; r = screen->r; r.max.y = r.min.y+Dy(r)/5; flstart(screen->clipr); rinit(&cmd.rasp); flnew(&cmd.l[0], gettext, 1, &cmd); flinit(&cmd.l[0], r, font, cmdcols); cmd.nwin = 1; which = &cmd.l[0]; cmd.tag = Untagged; outTs(Tversion, VERSION); startnewfile(Tstartcmdfile, &cmd); got = 0; for(;;got = waitforio()){ if(hasunlocked && RESIZED()) resize(); if(got&(1<<RHost)) rcv(); if(got&(1<<RPlumb)){ for(i=0; cmd.l[i].textfn==0; i++) ; current(&cmd.l[i]); flsetselect(which, cmd.rasp.nrunes, cmd.rasp.nrunes); type(which, RPlumb); } if(got&(1<<RKeyboard)) if(which) type(which, RKeyboard); else kbdblock(); if(got&(1<<RMouse)){ if(hostlock==2 || !ptinrect(mousep->xy, screen->r)){ mouseunblock(); continue; } nwhich = flwhich(mousep->xy); scr = which && ptinrect(mousep->xy, which->scroll); if(mousep->buttons) flushtyping(1); if(mousep->buttons&1){ if(nwhich){ if(nwhich!=which) current(nwhich); else if(scr) scroll(which, 1); else{ t=(Text *)which->user1; if(flselect(which)){ outTsl(Tdclick, t->tag, which->p0); t->lock++; }else if(t!=&cmd) outcmd(); } } }else if((mousep->buttons&2) && which){ if(scr) scroll(which, 2); else menu2hit(); }else if((mousep->buttons&4)){ if(scr) scroll(which, 3); else menu3hit(); } mouseunblock(); } } }
void threadmain(int argc, char *argv[]) { int i, got, scr, chord; Text *t; Rectangle r; Flayer *nwhich; /* * sam is talking to us on fd 0 and 1. * move these elsewhere so that if we accidentally * use 0 and 1 in other code, nothing bad happens. */ dup(0, 3); dup(1, 4); hostfd[0] = 3; hostfd[1] = 4; close(0); close(1); open("/dev/null", OREAD); if(open("/dev/tty", OWRITE) < 0) open("/dev/null", OWRITE); notify(notifyf); if(protodebug) print("getscreen\n"); getscreen(argc, argv); if(protodebug) print("iconinit\n"); iconinit(); if(protodebug) print("initio\n"); initio(); if(protodebug) print("scratch\n"); scratch = alloc(100*RUNESIZE); nscralloc = 100; r = screen->r; r.max.y = r.min.y+Dy(r)/5; if(protodebug) print("flstart\n"); flstart(screen->clipr); rinit(&cmd.rasp); flnew(&cmd.l[0], gettext, 1, &cmd); flinit(&cmd.l[0], r, font, cmdcols); cmd.nwin = 1; which = &cmd.l[0]; cmd.tag = Untagged; outTs(Tversion, VERSION); startnewfile(Tstartcmdfile, &cmd); got = 0; chord = 0; if(protodebug) print("loop\n"); for(;;got = waitforio()){ if(hasunlocked && RESIZED()) resize(); if(got&(1<<RHost)) rcv(); if(got&(1<<RPlumb)){ for(i=0; cmd.l[i].textfn==0; i++) ; current(&cmd.l[i]); flsetselect(which, cmd.rasp.nrunes, cmd.rasp.nrunes); type(which, RPlumb); } if(got&(1<<RKeyboard)) if(which) type(which, RKeyboard); else kbdblock(); if(got&(1<<RMouse)){ if(hostlock==2 || !ptinrect(mousep->xy, screen->r)){ mouseunblock(); continue; } nwhich = flwhich(mousep->xy); //scr = which && ptinrect(mousep->xy, which->scroll); scr = which && (ptinrect(mousep->xy, which->scroll) || mousep->buttons&(8|16)); if(mousep->buttons) flushtyping(1); //if(chording && chord==1 && !mousep->buttons) if((mousep->buttons&1)==0) chord = 0; //if(chording && chord) //chord |= mousep->buttons; //else if(mousep->buttons&1){ if(chord && which && which==nwhich){ chord |= mousep->buttons; t = (Text *)which->user1; if(!t->lock){ int w = which-t->l; if(chord&2){ cut(t, w, 1, 1); chord &= ~2; } if(chord&4){ paste(t, w); chord &= ~4; } } }else if(mousep->buttons&(1|8)){ //}else if(mousep->buttons&1){ if(nwhich){ if(nwhich!=which) current(nwhich); else if(scr) //scroll(which, 1); scroll(which, (mousep->buttons&8) ? 4 : 1); else{ t=(Text *)which->user1; if(flselect(which)){ outTsl(Tdclick, t->tag, which->p0); t->lock++; }else if(t!=&cmd) outcmd(); if(mousep->buttons&1) chord = mousep->buttons; } } }else if((mousep->buttons&2) && which){ if(scr) scroll(which, 2); else menu2hit(); }else if(mousep->buttons&(4|16)){ //}else if(mousep->buttons&4){ if(nwhich!=which) current(nwhich); else if(scr) //if(scr) //scroll(which, 3); scroll(which, (mousep->buttons&16) ? 5 : 3); else menu3hit(); } mouseunblock(); } } }