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 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; int scrollkey, upkey; scrollkey = 0; upkey = 0; if(res == RKeyboard) { scrollkey = qpeekc()==SCROLLKEY; /* ICK */ upkey = qpeekc() == UPKEY; } if(lock || t->lock){ kbdblock(); return; } a = l->p0; if(a!=l->p1 && !scrollkey && !upkey){ flushtyping(1); cut(t, t->front, 1, 1); return; /* it may now be locked */ } backspacing = 0; while((c = kbdchar())>0){ if(res == RKeyboard){ if(c == UPKEY || c==SCROLLKEY || c==ESC) break; /* backspace, ctrl-u, ctrl-w, del, ctrl-x */ if(c=='\b' || c==0x15 || c==0x17 || c==0x7F || c==0x18){ backspacing = 1; break; } } *p++ = c; if(c == '\n' || p >= buf+sizeof(buf)/sizeof(buf[0])) 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){ flushtyping(0); center(l, l->origin+l->f.nchars+1); } else if (c == UPKEY) { flushtyping(0); outTsll(Torigin, t->tag, l->origin, l->f.maxlines+1); /* backspacing immediately after outcmd(): sorry */ }else if(backspacing && !lock){ if(l->f.p0>0 && a>0){ switch(c){ case '\b': case 0x7F: /* del */ l->p0 = a-1; break; case 0x18: /* ctrl-x */ case 0x15: /* ctrl-u */ 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); } for(l=t->l; l<&t->l[NL]; l++) if(l->textfn) flsetselect(l, l->p0, l->p1); } }
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; int32_t 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){ backspacing = 1; break; } } *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+sizeof(buf)/sizeof(buf[0])) 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); /* backspacing immediately after outcmd(): sorry */ }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 */ l->p0 = a-1; break; case 0x15: /* ctrl-u */ 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); } for(l=t->l; l<&t->l[NL]; l++) if(l->textfn) flsetselect(l, l->p0, l->p1); } }
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 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; } } }
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(); } } }