19 void del(Text*, Text*, Text*, int, int, Rune*, int);
20 void delcol(Text*, Text*, Text*, int, int, Rune*, int);
21 void dotfiles(Text*, Text*, Text*, int, int, Rune*, int);
22 void dump(Text*, Text*, Text*, int, int, Rune*, int);
23 void edit(Text*, Text*, Text*, int, int, Rune*, int);
24 void xexit(Text*, Text*, Text*, int, int, Rune*, int);
25 void fontx(Text*, Text*, Text*, int, int, Rune*, int);
26 void get(Text*, Text*, Text*, int, int, Rune*, int);
27 void id(Text*, Text*, Text*, int, int, Rune*, int);
28 void incl(Text*, Text*, Text*, int, int, Rune*, int);
29 void indent(Text*, Text*, Text*, int, int, Rune*, int);
30 void xkill(Text*, Text*, Text*, int, int, Rune*, int);
31 void local(Text*, Text*, Text*, int, int, Rune*, int);
32 void look(Text*, Text*, Text*, int, int, Rune*, int);
33 void newcol(Text*, Text*, Text*, int, int, Rune*, int);
34 void paste(Text*, Text*, Text*, int, int, Rune*, int);
35 void put(Text*, Text*, Text*, int, int, Rune*, int);
36 void putall(Text*, Text*, Text*, int, int, Rune*, int);
37 void sendx(Text*, Text*, Text*, int, int, Rune*, int);
38 void sort(Text*, Text*, Text*, int, int, Rune*, int);
39 void tab(Text*, Text*, Text*, int, int, Rune*, int);
40 void zeroxx(Text*, Text*, Text*, int, int, Rune*, int);
42 typedef struct Exectab Exectab;
46 void (*fn)(Text*, Text*, Text*, int, int, Rune*, int);
52 static Rune LCut[] = { 'C', 'u', 't', 0 };
53 static Rune LDel[] = { 'D', 'e', 'l', 0 };
54 static Rune LDelcol[] = { 'D', 'e', 'l', 'c', 'o', 'l', 0 };
55 static Rune LDelete[] = { 'D', 'e', 'l', 'e', 't', 'e', 0 };
56 static Rune LDotfiles[] = { 'D', 'o', 't', 'f', 'i', 'l', 'e', 's', 0 };
57 static Rune LDump[] = { 'D', 'u', 'm', 'p', 0 };
58 static Rune LEdit[] = { 'E', 'd', 'i', 't', 0 };
59 static Rune LExit[] = { 'E', 'x', 'i', 't', 0 };
60 static Rune LFont[] = { 'F', 'o', 'n', 't', 0 };
61 static Rune LGet[] = { 'G', 'e', 't', 0 };
62 static Rune LID[] = { 'I', 'D', 0 };
63 static Rune LIncl[] = { 'I', 'n', 'c', 'l', 0 };
64 static Rune LIndent[] = { 'I', 'n', 'd', 'e', 'n', 't', 0 };
65 static Rune LKill[] = { 'K', 'i', 'l', 'l', 0 };
66 static Rune LLoad[] = { 'L', 'o', 'a', 'd', 0 };
67 static Rune LLocal[] = { 'L', 'o', 'c', 'a', 'l', 0 };
68 static Rune LLook[] = { 'L', 'o', 'o', 'k', 0 };
69 static Rune LNew[] = { 'N', 'e', 'w', 0 };
70 static Rune LNewcol[] = { 'N', 'e', 'w', 'c', 'o', 'l', 0 };
71 static Rune LPaste[] = { 'P', 'a', 's', 't', 'e', 0 };
72 static Rune LPut[] = { 'P', 'u', 't', 0 };
73 static Rune LPutall[] = { 'P', 'u', 't', 'a', 'l', 'l', 0 };
74 static Rune LRedo[] = { 'R', 'e', 'd', 'o', 0 };
75 static Rune LSend[] = { 'S', 'e', 'n', 'd', 0 };
76 static Rune LSnarf[] = { 'S', 'n', 'a', 'r', 'f', 0 };
77 static Rune LSort[] = { 'S', 'o', 'r', 't', 0 };
78 static Rune LTab[] = { 'T', 'a', 'b', 0 };
79 static Rune LUndo[] = { 'U', 'n', 'd', 'o', 0 };
80 static Rune LZerox[] = { 'Z', 'e', 'r', 'o', 'x', 0 };
83 { LCut, cut, TRUE, TRUE, TRUE },
84 { LDel, del, FALSE, FALSE, XXX },
85 { LDelcol, delcol, FALSE, XXX, XXX },
86 { LDelete, del, FALSE, TRUE, XXX },
87 { LDotfiles, dotfiles, FALSE, XXX, XXX },
88 { LDump, dump, FALSE, TRUE, XXX },
89 { LEdit, edit, FALSE, XXX, XXX },
90 { LExit, xexit, FALSE, XXX, XXX },
91 { LFont, fontx, FALSE, XXX, XXX },
92 { LGet, get, FALSE, TRUE, XXX },
93 { LID, id, FALSE, XXX, XXX },
94 { LIncl, incl, FALSE, XXX, XXX },
95 { LIndent, indent, FALSE, XXX, XXX },
96 { LKill, xkill, FALSE, XXX, XXX },
97 { LLoad, dump, FALSE, FALSE, XXX },
98 { LLocal, local, FALSE, XXX, XXX },
99 { LLook, look, FALSE, XXX, XXX },
100 { LNew, new, FALSE, XXX, XXX },
101 { LNewcol, newcol, FALSE, XXX, XXX },
102 { LPaste, paste, TRUE, TRUE, XXX },
103 { LPut, put, FALSE, XXX, XXX },
104 { LPutall, putall, FALSE, XXX, XXX },
105 { LRedo, undo, FALSE, FALSE, XXX },
106 { LSend, sendx, TRUE, XXX, XXX },
107 { LSnarf, cut, FALSE, TRUE, FALSE },
108 { LSort, sort, FALSE, XXX, XXX },
109 { LTab, tab, FALSE, XXX, XXX },
110 { LUndo, undo, FALSE, TRUE, XXX },
111 { LZerox, zeroxx, FALSE, XXX, XXX },
116 lookup(Rune *r, int n)
121 r = skipbl(r, n, &n);
126 for(e=exectab; e->name; e++)
127 if(runeeq(r, nr, e->name, runestrlen(e->name)) == TRUE)
137 return c=='<' || c=='|' || c=='>';
141 execute(Text *t, uint aq0, uint aq1, int external, Text *argt)
152 if(q1 == q0){ /* expand to find word (actually file name) */
153 /* if in selection, choose selection */
154 if(t->q1>t->q0 && t->q0<=q0 && q0<=t->q1){
158 while(q1<t->file->b.nc && isexecc(c=textreadc(t, q1)) && c!=':')
160 while(q0>0 && isexecc(c=textreadc(t, q0-1)) && c!=':')
166 r = runemalloc(q1-q0);
167 bufread(&t->file->b, q0, r, q1-q0);
168 e = lookup(r, q1-q0);
169 if(!external && t->w!=nil && t->w->nopen[QWevent]>0){
173 if(q0!=aq0 || q1!=aq1){
174 bufread(&t->file->b, aq0, r, aq1-aq0);
177 aa = getbytearg(argt, TRUE, TRUE, &a);
179 if(strlen(a) > EVENTSIZE){ /* too big; too bad */
182 warning(nil, "`argument string too long\n");
192 winevent(t->w, "%c%d %d %d %d %.*S\n", c, aq0, aq1, f, n, n, r);
194 winevent(t->w, "%c%d %d %d 0 \n", c, aq0, aq1, f, n);
195 if(q0!=aq0 || q1!=aq1){
197 bufread(&t->file->b, q0, r, n);
199 winevent(t->w, "%c%d %d 0 %d %.*S\n", c, q0, q1, n, n, r);
201 winevent(t->w, "%c%d %d 0 0 \n", c, q0, q1, n);
204 winevent(t->w, "%c0 0 0 %d %s\n", c, utflen(a), a);
206 winevent(t->w, "%c0 0 0 %d %s\n", c, utflen(aa), aa);
208 winevent(t->w, "%c0 0 0 0 \n", c);
216 if(e->mark && seltext!=nil)
217 if(seltext->what == Body){
219 filemark(seltext->w->body.file);
221 s = skipbl(r, q1-q0, &n);
222 s = findbl(s, n, &n);
223 s = skipbl(s, n, &n);
224 (*e->fn)(t, seltext, argt, e->flag1, e->flag2, s, n);
229 b = runetobyte(r, q1-q0);
231 dir = dirname(t, nil, 0);
232 if(dir.nr==1 && dir.r[0]=='.'){ /* sigh */
237 aa = getbytearg(argt, TRUE, TRUE, &a);
240 run(t->w, b, dir.r, dir.nr, TRUE, aa, a, FALSE);
244 printarg(Text *argt, uint q0, uint q1)
248 if(argt->what!=Body || argt->file->name==nil)
250 buf = emalloc(argt->file->nname+32);
252 sprint(buf, "%.*S:#%d", argt->file->nname, argt->file->name, q0);
254 sprint(buf, "%.*S:#%d,#%d", argt->file->nname, argt->file->name, q0, q1);
259 getarg(Text *argt, int doaddr, int dofile, Rune **rp, int *nrp)
270 textcommit(argt, TRUE);
271 if(expand(argt, argt->q0, argt->q1, &e)){
273 if(e.nname && dofile){
274 e.name = runerealloc(e.name, e.nname+1);
276 a = printarg(argt, e.q0, e.q1);
287 *rp = runemalloc(n+1);
288 bufread(&argt->file->b, e.q0, *rp, n);
290 a = printarg(argt, e.q0, e.q1);
296 getbytearg(Text *argt, int doaddr, int dofile, char **bp)
303 aa = getarg(argt, doaddr, dofile, &r, &n);
306 *bp = runetobyte(r, n);
312 newcol(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
323 c = rowadd(et->row, nil, -1);
325 winsettag(coladd(c, nil, nil, -1));
329 delcol(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
343 if(c==nil || colclean(c)==0)
345 for(i=0; i<c->nw; i++){
347 if(w->nopen[QWevent]+w->nopen[QWaddr]+w->nopen[QWdata] > 0){
348 warning(nil, "can't delete column; %.*S is running an external command\n", w->body.file->nname, w->body.file->name);
352 rowclose(et->col->row, et->col, TRUE);
356 del(Text *et, Text *_0, Text *_1, int flag1, int _2, Rune *_3, int _4)
364 if(et->col==nil || et->w == nil)
366 if(flag1 || et->w->body.file->ntext>1 || winclean(et->w, FALSE))
367 colclose(et->col, et->w, TRUE);
371 dotfiles(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
381 nodotfiles = !nodotfiles;
382 warning(nil, "%s dot files\n", nodotfiles ? "omitting" : "showing");
386 sort(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
400 seqof(Window *w, int isundo)
402 /* if it's undo, see who changed with us */
404 return w->body.file->seq;
405 /* if it's redo, see who we'll be sync'ed up with */
406 return fileredoseq(w->body.file);
410 undo(Text *et, Text *_0, Text *_1, int flag1, int _2, Rune *_3, int _4)
423 if(et==nil || et->w== nil)
425 seq = seqof(et->w, flag1);
427 /* nothing to undo */
431 * Undo the executing window first. Its display will update. other windows
432 * in the same file will not call show() and jump to a different location in the file.
433 * Simultaneous changes to other files will be chaotic, however.
435 winundo(et->w, flag1);
436 for(i=0; i<row.ncol; i++){
438 for(j=0; j<c->nw; j++){
442 if(seqof(w, flag1) == seq)
449 getname(Text *t, Text *argt, Rune *arg, int narg, int isput)
456 getarg(argt, FALSE, TRUE, &r, &n);
461 /* if are doing a Put, want to synthesize name even for non-existent file */
462 /* best guess is that file name doesn't contain a slash */
478 s = runetobyte(t->file->name, t->file->nname);
481 /* prefix with directory name if necessary */
484 if(n>0 && arg[0]!='/'){
485 dir = dirname(t, nil, 0);
486 if(dir.nr==1 && dir.r[0]=='.'){ /* sigh */
493 r = runemalloc(dir.nr+n+1);
494 runemove(r, dir.r, dir.nr);
496 runemove(r+dir.nr, arg, n);
503 s = runetobyte(r, n);
513 zeroxx(Text *et, Text *t, Text *_1, int _2, int _3, Rune *_4, int _5)
525 if(t!=nil && t->w!=nil && t->w!=et->w){
534 if(t==nil || t->w==nil)
538 warning(nil, "%.*S is a directory; Zerox illegal\n", t->file->nname, t->file->name);
540 nw = coladd(t->w->col, nil, t->w, -1);
541 /* ugly: fix locks so w->unlock works */
542 winlock1(nw, t->w->owner);
549 get(Text *et, Text *t, Text *argt, int flag1, int _0, Rune *arg, int narg)
553 int i, n, dirty, samename, isdir;
561 if(et==nil || et->w==nil)
563 if(!et->w->isdir && (et->w->body.file->b.nc>0 && !winclean(et->w, TRUE)))
567 name = getname(t, argt, arg, narg, FALSE);
569 warning(nil, "no file name\n");
572 if(t->file->ntext>1){
574 isdir = (d!=nil && (d->qid.type & QTDIR));
577 warning(nil, "%s is a directory; can't read with multiple windows on it\n", name);
580 r = bytetorune(name, &n);
581 for(i=0; i<t->file->ntext; i++){
582 u = t->file->text[i];
583 /* second and subsequent calls with zero an already empty buffer, but OK */
587 samename = runeeq(r, n, t->file->name, t->file->nname);
588 textload(t, 0, name, samename);
590 t->file->mod = FALSE;
596 for(i=0; i<t->file->ntext; i++)
597 t->file->text[i]->w->dirty = dirty;
601 t->file->unread = FALSE;
602 for(i=0; i<t->file->ntext; i++){
603 u = t->file->text[i];
604 textsetselect(&u->w->tag, u->w->tag.file->b.nc, u->w->tag.file->b.nc);
610 putfile(File *f, int q0, int q1, Rune *namer, int nname)
621 name = runetobyte(namer, nname);
623 if(d!=nil && runeeq(namer, nname, f->name, f->nname)){
624 /* f->mtime+1 because when talking over NFS it's often off by a second */
625 if(f->dev!=d->dev || f->qidpath!=d->qid.path || f->mtime+1<d->mtime){
627 f->qidpath = d->qid.path;
630 warning(nil, "%s not written; file already exists\n", name);
632 warning(nil, "%s modified%s%s since last read\n", name, d->muid[0]?" by ":"", d->muid);
636 fd = create(name, OWRITE, 0666);
638 warning(nil, "can't create file %s: %r\n", name);
645 isapp = (d!=nil && d->length>0 && (d->qid.type&QTAPPEND));
647 warning(nil, "%s not written; file is append only\n", name);
651 for(q=q0; q<q1; q+=n){
653 if(n > BUFSIZE/UTFmax)
655 bufread(&f->b, q, r, n);
656 m = snprint(s, BUFSIZE+1, "%.*S", n, r);
657 if(write(fd, s, m) != m){
658 warning(nil, "can't write file %s: %r\n", name);
662 if(runeeq(namer, nname, f->name, f->nname)){
663 if(q0!=0 || q1!=f->b.nc){
673 f->qidpath = d->qid.path;
680 for(i=0; i<f->ntext; i++){
681 f->text[i]->w->putseq = f->seq;
682 f->text[i]->w->dirty = w->dirty;
707 put(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
719 if(et==nil || et->w==nil || et->w->isdir)
723 name = getname(&w->body, argt, arg, narg, TRUE);
725 warning(nil, "no file name\n");
728 namer = bytetorune(name, &nname);
729 putfile(f, 0, f->b.nc, namer, nname);
734 dump(Text *_0, Text *_1, Text *argt, int isdump, int _2, Rune *arg, int narg)
743 name = runetobyte(arg, narg);
745 getbytearg(argt, FALSE, TRUE, &name);
749 rowload(&row, name, FALSE);
754 cut(Text *et, Text *t, Text *_0, int dosnarf, int docut, Rune *_2, int _3)
756 uint q0, q1, n, locked, c;
763 /* use current window if snarfing and its selection is non-null */
764 if(et!=t && dosnarf && et->w!=nil){
765 if(et->w->body.q1>et->w->body.q0){
768 filemark(t->file); /* seq has been incremented by execute */
769 }else if(et->w->tag.q1>et->w->tag.q0)
773 /* can only happen if seltext == nil */
777 if(t->w!=nil && et->w!=t->w){
792 bufdelete(&snarfbuf, 0, snarfbuf.nc);
798 bufread(&t->file->b, q0, r, n);
799 bufinsert(&snarfbuf, snarfbuf.nc, r, n);
806 textdelete(t, t->q0, t->q1, TRUE);
807 textsetselect(t, t->q0, t->q0);
812 }else if(dosnarf) /* Snarf command */
819 paste(Text *et, Text *t, Text *_0, int selectall, int tobody, Rune *_1, int _2)
829 /* if(tobody), use body of executing window (Paste or Send command) */
830 if(tobody && et!=nil && et->w!=nil){
832 filemark(t->file); /* seq has been incremented by execute */
838 if(t==nil || snarfbuf.nc==0)
840 if(t->w!=nil && et->w!=t->w){
846 cut(t, t, nil, FALSE, TRUE, nil, 0);
849 q1 = t->q0+snarfbuf.nc;
857 bufread(&snarfbuf, q, r, n);
858 textinsert(t, q0, r, n, TRUE);
864 textsetselect(t, t->q0, q1);
866 textsetselect(t, q1, q1);
871 if(t->w!=nil && et->w!=t->w)
876 look(Text *et, Text *t, Text *argt, int _0, int _1, Rune *arg, int narg)
887 search(t, arg, narg);
890 getarg(argt, FALSE, FALSE, &r, &n);
894 bufread(&t->file->b, t->q0, r, n);
901 static Rune Lnl[] = { '\n', 0 };
904 sendx(Text *et, Text *t, Text *_0, int _1, int _2, Rune *_3, int _4)
916 cut(t, t, nil, TRUE, FALSE, nil, 0);
917 textsetselect(t, t->file->b.nc, t->file->b.nc);
918 paste(t, t, nil, TRUE, TRUE, nil, 0);
919 if(textreadc(t, t->file->b.nc-1) != '\n'){
920 textinsert(t, t->file->b.nc, Lnl, 1, TRUE);
921 textsetselect(t, t->file->b.nc, t->file->b.nc);
926 edit(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
937 getarg(argt, FALSE, TRUE, &r, &len);
943 editcmd(et, arg, narg);
947 xexit(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
964 putall(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
979 for(i=0; i<row.ncol; i++){
981 for(j=0; j<c->nw; j++){
983 if(w->isscratch || w->isdir || w->body.file->nname==0)
985 if(w->nopen[QWevent] > 0)
987 a = runetobyte(w->body.file->name, w->body.file->nname);
989 if(w->body.file->mod || w->body.ncache)
991 warning(nil, "no auto-Put of %s: %r\n", a);
993 wincommit(w, &w->body);
994 put(&w->body, nil, nil, XXX, XXX, nil, 0);
1003 id(Text *et, Text *_0, Text *_1, int _2, int _3, Rune *_4, int _5)
1014 warning(nil, "/mnt/acme/%d/\n", et->w->id);
1018 local(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
1027 aa = getbytearg(argt, TRUE, TRUE, &a);
1029 dir = dirname(et, nil, 0);
1030 if(dir.nr==1 && dir.r[0]=='.'){ /* sigh */
1035 run(nil, runetobyte(arg, narg), dir.r, dir.nr, FALSE, aa, a, FALSE);
1039 xkill(Text *_0, Text *_1, Text *argt, int _2, int _3, Rune *arg, int narg)
1049 getarg(argt, FALSE, FALSE, &r, &na);
1051 xkill(nil, nil, nil, 0, 0, r, na);
1052 /* loop condition: *arg is not a blank */
1054 a = findbl(arg, narg, &na);
1057 cmd = runemalloc(narg-na+1);
1058 runemove(cmd, arg, narg-na);
1060 arg = skipbl(a, na, &narg);
1064 static Rune Lfix[] = { 'f', 'i', 'x', 0 };
1065 static Rune Lvar[] = { 'v', 'a', 'r', 0 };
1068 fontx(Text *et, Text *t, Text *argt, int _0, int _1, Rune *arg, int narg)
1070 Rune *a, *r, *flag, *file;
1080 if(et==nil || et->w==nil)
1085 /* loop condition: *arg is not a blank */
1088 a = findbl(arg, narg, &na);
1091 r = runemalloc(narg-na+1);
1092 runemove(r, arg, narg-na);
1093 if(runeeq(r, narg-na, Lfix, 3) || runeeq(r, narg-na, Lvar, 3)){
1101 arg = skipbl(a, na, &narg);
1103 getarg(argt, FALSE, TRUE, &r, &na);
1105 if(runeeq(r, na, Lfix, 3) || runeeq(r, na, Lvar, 3)){
1115 fix = runeeq(flag, runestrlen(flag), Lfix, 3);
1116 else if(file == nil){
1117 newfont = rfget(FALSE, FALSE, FALSE, nil);
1119 fix = strcmp(newfont->f->name, t->fr.font->name)==0;
1122 aa = runetobyte(file, nf);
1123 newfont = rfget(fix, flag!=nil, FALSE, aa);
1126 newfont = rfget(fix, FALSE, FALSE, nil);
1128 draw(screen, t->w->r, textcols[BACK], nil, ZP);
1129 rfclose(t->reffont);
1130 t->reffont = newfont;
1131 t->fr.font = newfont->f;
1134 t->all.min.x++; /* force recolumnation; disgusting! */
1135 for(i=0; i<t->w->ndl; i++){
1137 aa = runetobyte(dp->r, dp->nr);
1138 dp->wid = stringwidth(newfont->f, aa);
1142 /* avoid shrinking of window due to quantization */
1143 colgrow(t->w->col, t->w, -1);
1150 incl(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
1160 if(et==nil || et->w==nil)
1164 getarg(argt, FALSE, TRUE, &r, &len);
1167 winaddincl(w, r, len);
1169 /* loop condition: *arg is not a blank */
1171 a = findbl(arg, narg, &na);
1174 r = runemalloc(narg-na+1);
1175 runemove(r, arg, narg-na);
1177 winaddincl(w, r, narg-na);
1178 arg = skipbl(a, na, &narg);
1180 if(n==0 && w->nincl){
1181 for(n=w->nincl; --n>=0; )
1182 warning(nil, "%S ", w->incl[n]);
1187 static Rune LON[] = { 'O', 'N', 0 };
1188 static Rune LOFF[] = { 'O', 'F', 'F', 0 };
1189 static Rune Lon[] = { 'o', 'n', 0 };
1192 indentval(Rune *s, int n)
1196 if(runestrncmp(s, LON, n) == 0){
1197 globalautoindent = TRUE;
1198 warning(nil, "Indent ON\n");
1201 if(runestrncmp(s, LOFF, n) == 0){
1202 globalautoindent = FALSE;
1203 warning(nil, "Indent OFF\n");
1206 return runestrncmp(s, Lon, n) == 0;
1210 indent(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
1214 int na, len, autoindent;
1220 if(et==nil || et->w==nil)
1224 getarg(argt, FALSE, TRUE, &r, &len);
1226 autoindent = indentval(r, len);
1228 a = findbl(arg, narg, &na);
1230 autoindent = indentval(arg, narg-na);
1233 w->autoindent = autoindent;
1235 warning(nil, "%.*S: Indent %s\n", w->body.file->nname, w->body.file->name,
1236 w->autoindent ? "on" : "off");
1240 tab(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
1251 if(et==nil || et->w==nil)
1254 getarg(argt, FALSE, TRUE, &r, &len);
1256 if(r!=nil && len>0){
1257 p = runetobyte(r, len);
1258 if('0'<=p[0] && p[0]<='9')
1262 a = findbl(arg, narg, &na);
1264 p = runetobyte(arg, narg-na);
1265 if('0'<=p[0] && p[0]<='9')
1271 if(w->body.tabstop != tab){
1272 w->body.tabstop = tab;
1273 winresize(w, w->r, 1);
1276 warning(nil, "%.*S: Tab %d\n", w->body.file->nname, w->body.file->name, w->body.tabstop);
1280 runproc(void *argvp)
1294 char *e, *t, *name, *filename, *dir, **av, *news;
1296 int ac, w, inarg, i, n, fd, nincl, winid;
1300 //static void *parg[2];
1308 ndir = (int)argv[3];
1309 newns = (int)argv[4];
1314 iseditcmd = (int)argv[9];
1318 while(*t==' ' || *t=='\n' || *t=='\t')
1321 if(*e==' ' || *e=='\n' || *e=='\t' )
1323 name = emalloc((e-t)+2);
1324 memmove(name, t, e-t);
1326 e = utfrrune(name, '/');
1329 strcat(name, " "); /* add blank here for ease in waittask */
1330 c->name = bytetorune(name, &c->nname);
1333 if(*t=='<' || *t=='|' || *t=='>')
1335 c->iseditcmd = iseditcmd;
1338 dir = runetobyte(rdir, ndir);
1339 chdir(dir); /* ignore error: probably app. window */
1346 filename = smprint("%.*S", win->body.file->nname, win->body.file->name);
1349 incl = emalloc(nincl*sizeof(Rune*));
1350 for(i=0; i<nincl; i++){
1351 n = runestrlen(win->incl[i]);
1352 incl[i] = runemalloc(n+1);
1353 runemove(incl[i], win->incl[i], n);
1361 winid = activewin->id;
1363 rfork(RFNAMEG|RFENVG|RFFDG|RFNOTEG);
1364 sprint(buf, "%d", winid);
1365 putenv("winid", buf);
1368 putenv("%", filename);
1371 c->md = fsysmount(rdir, ndir, incl, nincl);
1373 fprint(2, "child: can't allocate mntdir: %r\n");
1374 threadexits("fsysmount");
1376 sprint(buf, "%d", c->md->id);
1377 if((fs = nsmount("acme", buf)) == nil){
1378 fprint(2, "child: can't mount acme: %r\n");
1381 threadexits("nsmount");
1383 if(winid>0 && (pipechar=='|' || pipechar=='>')){
1384 sprint(buf, "%d/rdsel", winid);
1385 sfd[0] = fsopenfd(fs, buf, OREAD);
1387 sfd[0] = open("/dev/null", OREAD);
1388 if((winid>0 || iseditcmd) && (pipechar=='|' || pipechar=='<')){
1391 sprint(buf, "%d/editout", winid);
1393 sprint(buf, "editout");
1395 sprint(buf, "%d/wrsel", winid);
1396 sfd[1] = fsopenfd(fs, buf, OWRITE);
1397 sfd[2] = fsopenfd(fs, "cons", OWRITE);
1399 sfd[1] = fsopenfd(fs, "cons", OWRITE);
1404 rfork(RFFDG|RFNOTEG);
1406 sfd[0] = open("/dev/null", OREAD);
1407 sfd[1] = open("/dev/null", OWRITE);
1408 sfd[2] = dup(erroutfd, -1);
1414 putenv("acmeaddr", argaddr);
1415 if(strlen(t) > sizeof buf-10) /* may need to print into stack */
1419 w = chartorune(&r, e);
1420 if(r==' ' || r=='\t')
1424 if(utfrune("#;&|^$=`'{}()<>[]*?^~`", r))
1435 w = chartorune(&r, e);
1436 if(r==' ' || r=='\t'){
1443 av = realloc(av, (ac+1)*sizeof(char**));
1447 av = realloc(av, (ac+2)*sizeof(char**));
1451 threadexec(cpid, sfd, av[0], av);
1452 /* libthread uses execvp so no need to do this */
1455 if(e[0]=='/' || (e[0]=='.' && e[1]=='/'))
1458 sprint(buf, "%s/%s", cputype, av[0]);
1459 procexec(cpid, sfd, buf, av);
1461 sprint(buf, "/bin/%s", av[0]);
1462 procexec(cpid, sfd, buf, av);
1468 * ugly: set path = (. $cputype /bin)
1469 * should honor $path if unusual.
1473 memmove(buf+n, ".", 2);
1475 i = strlen(cputype)+1;
1476 memmove(buf+n, cputype, i);
1478 memmove(buf+n, "/bin", 5);
1480 fd = create("/env/path", OWRITE, 0666);
1486 news = emalloc(strlen(t) + 1 + 1 + strlen(arg) + 1 + 1);
1488 sprint(news, "%s '%s'", t, arg); /* BUG: what if quote in arg? */
1494 threadexecl(cpid, sfd, "rc", "rc", "-c", t, nil);
1495 warning(nil, "exec rc: %r\n");
1498 /* threadexec hasn't happened, so send a zero */
1501 if(sfd[2] != sfd[1])
1508 runwaittask(void *v)
1514 threadsetname("runwaittask");
1520 c->pid = recvul(cpid);
1521 while(c->pid == ~0);
1523 if(c->pid != 0) /* successful exec */
1536 run(Window *win, char *s, Rune *rdir, int ndir, int newns, char *argaddr, char *xarg, int iseditcmd)
1545 arg = emalloc(10*sizeof(void*));
1546 c = emalloc(sizeof *c);
1547 cpid = chancreate(sizeof(ulong), 0);
1551 arg[3] = (void*)ndir;
1552 arg[4] = (void*)newns;
1557 arg[9] = (void*)iseditcmd;
1558 threadcreate(runproc, arg, STACK);
1559 /* mustn't block here because must be ready to answer mount() call in run() */
1560 arg = emalloc(2*sizeof(void*));
1563 threadcreate(runwaittask, arg, STACK);