17 * These functions get called as:
19 * fn(et, t, argt, flag1, flag1, flag2, s, n);
21 * Where the arguments are:
23 * et: the Text* in which the executing event (click) occurred
24 * t: the Text* containing the current selection (Edit, Cut, Snarf, Paste)
25 * argt: the Text* containing the argument for a 2-1 click.
26 * e->flag1: from Exectab entry
27 * e->flag2: from Exectab entry
28 * s: the command line remainder (e.g., "x" if executing "Dump x")
29 * n: length of s (s is *not* NUL-terminated)
32 void del(Text*, Text*, Text*, int, int, Rune*, int);
33 void delcol(Text*, Text*, Text*, int, int, Rune*, int);
34 void dump(Text*, Text*, Text*, int, int, Rune*, int);
35 void edit(Text*, Text*, Text*, int, int, Rune*, int);
36 void exit(Text*, Text*, Text*, int, int, Rune*, int);
37 void fontx(Text*, Text*, Text*, int, int, Rune*, int);
38 void get(Text*, Text*, Text*, int, int, Rune*, int);
39 void id(Text*, Text*, Text*, int, int, Rune*, int);
40 void incl(Text*, Text*, Text*, int, int, Rune*, int);
41 void indent(Text*, Text*, Text*, int, int, Rune*, int);
42 void kill(Text*, Text*, Text*, int, int, Rune*, int);
43 void local(Text*, Text*, Text*, int, int, Rune*, int);
44 void look(Text*, Text*, Text*, int, int, Rune*, int);
45 void newcol(Text*, Text*, Text*, int, int, Rune*, int);
46 void paste(Text*, Text*, Text*, int, int, Rune*, int);
47 void put(Text*, Text*, Text*, int, int, Rune*, int);
48 void putall(Text*, Text*, Text*, int, int, Rune*, int);
49 void sendx(Text*, Text*, Text*, int, int, Rune*, int);
50 void sort(Text*, Text*, Text*, int, int, Rune*, int);
51 void tab(Text*, Text*, Text*, int, int, Rune*, int);
52 void zeroxx(Text*, Text*, Text*, int, int, Rune*, int);
54 typedef struct Exectab Exectab;
58 void (*fn)(Text*, Text*, Text*, int, int, Rune*, int);
65 { L"Cut", cut, TRUE, TRUE, TRUE },
66 { L"Del", del, FALSE, FALSE, XXX },
67 { L"Delcol", delcol, FALSE, XXX, XXX },
68 { L"Delete", del, FALSE, TRUE, XXX },
69 { L"Dump", dump, FALSE, TRUE, XXX },
70 { L"Edit", edit, FALSE, XXX, XXX },
71 { L"Exit", exit, FALSE, XXX, XXX },
72 { L"Font", fontx, FALSE, XXX, XXX },
73 { L"Get", get, FALSE, TRUE, XXX },
74 { L"ID", id, FALSE, XXX, XXX },
75 { L"Incl", incl, FALSE, XXX, XXX },
76 { L"Indent", indent, FALSE, AUTOINDENT, XXX },
77 { L"Kill", kill, FALSE, XXX, XXX },
78 { L"Load", dump, FALSE, FALSE, XXX },
79 { L"Local", local, FALSE, XXX, XXX },
80 { L"Look", look, FALSE, XXX, XXX },
81 { L"New", new, FALSE, XXX, XXX },
82 { L"Newcol", newcol, FALSE, XXX, XXX },
83 { L"Paste", paste, TRUE, TRUE, XXX },
84 { L"Put", put, FALSE, XXX, XXX },
85 { L"Putall", putall, FALSE, XXX, XXX },
86 { L"Redo", undo, FALSE, FALSE, XXX },
87 { L"Send", sendx, TRUE, XXX, XXX },
88 { L"Snarf", cut, FALSE, TRUE, FALSE },
89 { L"Sort", sort, FALSE, XXX, XXX },
90 { L"Spaces", indent, FALSE, SPACESINDENT, XXX },
91 { L"Tab", tab, FALSE, XXX, XXX },
92 { L"Undo", undo, FALSE, TRUE, XXX },
93 { L"Zerox", zeroxx, FALSE, XXX, XXX },
94 { nil, nil, 0, 0, 0 },
98 lookup(Rune *r, int n)
103 r = skipbl(r, n, &n);
108 for(e=exectab; e->name; e++)
109 if(runeeq(r, nr, e->name, runestrlen(e->name)) == TRUE)
119 return c=='<' || c=='|' || c=='>';
123 execute(Text *t, uint aq0, uint aq1, int external, Text *argt)
134 if(q1 == q0){ /* expand to find word (actually file name) */
135 /* if in selection, choose selection */
136 if(t->q1>t->q0 && t->q0<=q0 && q0<=t->q1){
140 while(q1<t->file->nc && isexecc(c=textreadc(t, q1)) && c!=':')
142 while(q0>0 && isexecc(c=textreadc(t, q0-1)) && c!=':')
148 r = runemalloc(q1-q0);
149 bufread(t->file, q0, r, q1-q0);
151 delcmd = runesmprint("%.*S", q1-q0, r);
152 e = lookup(r, q1-q0);
153 if(!external && t->w!=nil && t->w->nopen[QWevent]>0){
157 if(q0!=aq0 || q1!=aq1){
158 bufread(t->file, aq0, r, aq1-aq0);
161 aa = getbytearg(argt, TRUE, TRUE, &a);
163 if(strlen(a) > EVENTSIZE){ /* too big; too bad */
167 warning(nil, "`argument string too long\n");
177 winevent(t->w, "%c%d %d %d %d %.*S\n", c, aq0, aq1, f, n, n, r);
179 winevent(t->w, "%c%d %d %d 0 \n", c, aq0, aq1, f, n);
180 if(q0!=aq0 || q1!=aq1){
182 bufread(t->file, q0, r, n);
184 winevent(t->w, "%c%d %d 0 %d %.*S\n", c, q0, q1, n, n, r);
186 winevent(t->w, "%c%d %d 0 0 \n", c, q0, q1, n);
189 winevent(t->w, "%c0 0 0 %d %s\n", c, utflen(a), a);
191 winevent(t->w, "%c0 0 0 %d %s\n", c, utflen(aa), aa);
193 winevent(t->w, "%c0 0 0 0 \n", c);
201 if(e->mark && seltext!=nil)
202 if(seltext->what == Body){
204 filemark(seltext->w->body.file);
206 s = skipbl(r, q1-q0, &n);
207 s = findbl(s, n, &n);
208 s = skipbl(s, n, &n);
209 (*e->fn)(t, seltext, argt, e->flag1, e->flag2, s, n);
214 b = runetobyte(r, q1-q0);
216 dir = dirname(t, nil, 0);
217 if(dir.nr==1 && dir.r[0]=='.'){ /* sigh */
222 aa = getbytearg(argt, TRUE, TRUE, &a);
225 run(t->w, b, dir.r, dir.nr, TRUE, aa, a, FALSE);
229 printarg(Text *argt, uint q0, uint q1)
233 if(argt->what!=Body || argt->file->name==nil)
235 buf = emalloc(argt->file->nname+32);
237 sprint(buf, "%.*S:#%d", argt->file->nname, argt->file->name, q0);
239 sprint(buf, "%.*S:#%d,#%d", argt->file->nname, argt->file->name, q0, q1);
244 getarg(Text *argt, int doaddr, int dofile, Rune **rp, int *nrp)
255 textcommit(argt, TRUE);
256 if(expand(argt, argt->q0, argt->q1, &e)){
258 if(e.nname && dofile){
259 e.name = runerealloc(e.name, e.nname+1);
261 a = printarg(argt, e.q0, e.q1);
272 *rp = runemalloc(n+1);
273 bufread(argt->file, e.q0, *rp, n);
275 a = printarg(argt, e.q0, e.q1);
281 getbytearg(Text *argt, int doaddr, int dofile, char **bp)
288 aa = getarg(argt, doaddr, dofile, &r, &n);
291 *bp = runetobyte(r, n);
297 newcol(Text *et, Text*, Text*, int, int, Rune*, int)
301 c = rowadd(et->row, nil, -1);
303 winsettag(coladd(c, nil, nil, -1));
307 delcol(Text *et, Text*, Text*, int, int, Rune*, int)
314 if(c==nil || colclean(c)==0)
316 for(i=0; i<c->nw; i++){
318 if(w->nopen[QWevent]+w->nopen[QWaddr]+w->nopen[QWdata]+w->nopen[QWxdata] > 0){
319 warning(nil, "can't delete column; %.*S is running an external command\n", w->body.file->nname, w->body.file->name);
323 rowclose(et->col->row, et->col, TRUE);
327 del(Text *et, Text*, Text *argt, int flag1, int, Rune *arg, int narg)
333 if(et->col==nil || et->w == nil)
335 if(flag1 || et->w->body.file->ntext>1 || winclean(et->w, FALSE)){
337 name = getname(&w->body, argt, arg, narg, TRUE);
338 if(name && plumbsendfd >= 0){
339 pm = emalloc(sizeof(Plumbmsg));
340 pm->src = estrdup("acme");
341 pm->dst = estrdup("close");
342 pm->wdir = estrdup(name);
343 if(p = strrchr(pm->wdir, '/'))
345 pm->type = estrdup("text");
347 pm->data = estrdup(name);
348 pm->ndata = strlen(pm->data);
349 if(pm->ndata < messagesize-1024)
350 plumbsend(plumbsendfd, pm);
354 colclose(et->col, et->w, TRUE);
359 sort(Text *et, Text*, Text*, int, int, Rune*, int)
366 seqof(Window *w, int isundo)
368 /* if it's undo, see who changed with us */
370 return w->body.file->seq;
371 /* if it's redo, see who we'll be sync'ed up with */
372 return fileredoseq(w->body.file);
376 undo(Text *et, Text*, Text*, int flag1, int, Rune*, int)
383 if(et==nil || et->w== nil)
385 seq = seqof(et->w, flag1);
387 /* nothing to undo */
391 * Undo the executing window first. Its display will update. other windows
392 * in the same file will not call show() and jump to a different location in the file.
393 * Simultaneous changes to other files will be chaotic, however.
395 winundo(et->w, flag1);
396 for(i=0; i<row.ncol; i++){
398 for(j=0; j<c->nw; j++){
402 if(seqof(w, flag1) == seq)
409 getname(Text *t, Text *argt, Rune *arg, int narg, int isput)
416 getarg(argt, FALSE, TRUE, &r, &n);
421 /* if are doing a Put, want to synthesize name even for non-existent file */
422 /* best guess is that file name doesn't contain a slash */
438 s = runetobyte(t->file->name, t->file->nname);
441 /* prefix with directory name if necessary */
444 if(n>0 && arg[0]!='/'){
445 dir = dirname(t, nil, 0);
446 if(dir.nr==1 && dir.r[0]=='.'){ /* sigh */
453 r = runemalloc(dir.nr+n+1);
454 runemove(r, dir.r, dir.nr);
456 if(dir.nr>0 && r[dir.nr]!='/' && n>0 && arg[0]!='/')
458 runemove(r+dir.nr, arg, n);
465 s = runetobyte(r, n);
475 zeroxx(Text *et, Text *t, Text*, int, int, Rune*, int)
481 if(t!=nil && t->w!=nil && t->w!=et->w){
490 if(t==nil || t->w==nil)
494 warning(nil, "%.*S is a directory; Zerox illegal\n", t->file->nname, t->file->name);
496 nw = coladd(t->w->col, nil, t->w, -1);
497 /* ugly: fix locks so w->unlock works */
498 winlock1(nw, t->w->owner);
505 get(Text *et, Text *t, Text *argt, int flag1, int, Rune *arg, int narg)
509 int i, n, dirty, samename, isdir;
515 if(et==nil || et->w==nil)
517 if(!et->w->isdir && (et->w->body.file->nc>0 && !winclean(et->w, TRUE)))
521 name = getname(t, argt, arg, narg, FALSE);
523 warning(nil, "no file name\n");
526 if(t->file->ntext>1){
528 isdir = (d!=nil && (d->qid.type & QTDIR));
531 warning(nil, "%s is a directory; can't read with multiple windows on it\n", name);
535 r = bytetorune(name, &n);
536 for(i=0; i<t->file->ntext; i++){
537 u = t->file->text[i];
538 /* second and subsequent calls with zero an already empty buffer, but OK */
542 samename = runeeq(r, n, t->file->name, t->file->nname);
543 textload(t, 0, name, samename);
545 t->file->mod = FALSE;
551 for(i=0; i<t->file->ntext; i++)
552 t->file->text[i]->w->dirty = dirty;
556 t->file->unread = FALSE;
557 for(i=0; i<t->file->ntext; i++){
558 u = t->file->text[i];
559 textsetselect(&u->w->tag, u->w->tag.file->nc, u->w->tag.file->nc);
565 putfile(File *f, int q0, int q1, Rune *namer, int nname)
577 name = runetobyte(namer, nname);
579 if(d!=nil && runeeq(namer, nname, f->name, f->nname)){
580 /* f->mtime+1 because when talking over NFS it's often off by a second */
581 if(f->dev!=d->dev || f->qidpath!=d->qid.path || f->mtime+1<d->mtime){
583 f->qidpath = d->qid.path;
586 warning(nil, "%s not written; file already exists\n", name);
588 warning(nil, "%s modified%s%s since last read\n", name, d->muid[0]?" by ":"", d->muid);
592 fd = create(name, OWRITE, 0666);
594 warning(nil, "can't create file %s: %r\n", name);
601 isapp = (d!=nil && d->length>0 && (d->qid.type&QTAPPEND));
603 warning(nil, "%s not written; file is append only\n", name);
607 for(q=q0; q<q1; q+=n){
609 if(n > (BUFSIZE-1)/UTFmax)
610 n = (BUFSIZE-1)/UTFmax;
612 m = snprint(s, BUFSIZE, "%.*S", n, r);
613 if(write(fd, s, m) != m){
614 warning(nil, "can't write file %s: %r\n", name);
618 if(runeeq(namer, nname, f->name, f->nname)){
619 if(q0!=0 || q1!=f->nc){
629 f->qidpath = d->qid.path;
636 for(i=0; i<f->ntext; i++){
637 f->text[i]->w->putseq = f->seq;
638 f->text[i]->w->dirty = w->dirty;
641 if(plumbsendfd >= 0){
642 pm = emalloc(sizeof(Plumbmsg));
643 pm->src = estrdup("acme");
644 pm->dst = estrdup("put");
645 pm->wdir = estrdup(name);
646 if(p = strrchr(pm->wdir, '/'))
648 pm->type = estrdup("text");
650 pm->data = estrdup(name);
651 pm->ndata = strlen(pm->data);
652 if(pm->ndata < messagesize-1024)
653 plumbsend(plumbsendfd, pm);
679 put(Text *et, Text*, Text *argt, int, int, Rune *arg, int narg)
687 if(et==nil || et->w==nil || et->w->isdir)
691 name = getname(&w->body, argt, arg, narg, TRUE);
693 warning(nil, "no file name\n");
696 namer = bytetorune(name, &nname);
697 putfile(f, 0, f->nc, namer, nname);
702 dump(Text *, Text *, Text *argt, int isdump, int, Rune *arg, int narg)
707 name = runetobyte(arg, narg);
709 getbytearg(argt, FALSE, TRUE, &name);
713 rowload(&row, name, FALSE);
718 cut(Text *et, Text *t, Text*, int dosnarf, int docut, Rune*, int)
720 uint q0, q1, n, locked, c;
724 * if not executing a mouse chord (et != t) and snarfing (dosnarf)
725 * and executed Cut or Snarf in window tag (et->w != nil),
726 * then use the window body selection or the tag selection
727 * or do nothing at all.
729 if(et!=t && dosnarf && et->w!=nil){
730 if(et->w->body.q1>et->w->body.q0){
733 filemark(t->file); /* seq has been incremented by execute */
734 }else if(et->w->tag.q1>et->w->tag.q0)
739 if(t == nil) /* no selection */
743 if(t->w!=nil && et->w!=t->w){
758 bufdelete(&snarfbuf, 0, snarfbuf.nc);
764 bufread(t->file, q0, r, n);
765 bufinsert(&snarfbuf, snarfbuf.nc, r, n);
772 textdelete(t, t->q0, t->q1, TRUE);
773 textsetselect(t, t->q0, t->q0);
778 }else if(dosnarf) /* Snarf command */
785 paste(Text *et, Text *t, Text*, int selectall, int tobody, Rune*, int)
791 /* if(tobody), use body of executing window (Paste or Send command) */
792 if(tobody && et!=nil && et->w!=nil){
794 filemark(t->file); /* seq has been incremented by execute */
800 if(t==nil || snarfbuf.nc==0)
802 if(t->w!=nil && et->w!=t->w){
808 cut(t, t, nil, FALSE, TRUE, nil, 0);
811 q1 = t->q0+snarfbuf.nc;
819 bufread(&snarfbuf, q, r, n);
820 textinsert(t, q0, r, n, TRUE);
826 textsetselect(t, t->q0, q1);
828 textsetselect(t, q1, q1);
833 if(t->w!=nil && et->w!=t->w)
838 look(Text *et, Text *t, Text *argt, int, int, Rune *arg, int narg)
846 search(t, arg, narg);
849 getarg(argt, FALSE, FALSE, &r, &n);
853 bufread(t->file, t->q0, r, n);
861 sendx(Text *et, Text *t, Text*, int, int, Rune*, int)
867 cut(t, t, nil, TRUE, FALSE, nil, 0);
868 textsetselect(t, t->file->nc, t->file->nc);
869 paste(t, t, nil, TRUE, TRUE, nil, 0);
870 if(textreadc(t, t->file->nc-1) != '\n'){
871 textinsert(t, t->file->nc, L"\n", 1, TRUE);
872 textsetselect(t, t->file->nc, t->file->nc);
877 edit(Text *et, Text*, Text *argt, int, int, Rune *arg, int narg)
884 getarg(argt, FALSE, TRUE, &r, &len);
890 editcmd(et, arg, narg);
894 exit(Text*, Text*, Text*, int, int, Rune*, int)
903 putall(Text*, Text*, Text*, int, int, Rune*, int)
910 for(i=0; i<row.ncol; i++){
912 for(j=0; j<c->nw; j++){
914 if(w->isscratch || w->isdir || w->body.file->nname==0)
916 if(w->nopen[QWevent] > 0)
918 a = runetobyte(w->body.file->name, w->body.file->nname);
920 if(w->body.file->mod || w->body.ncache)
922 warning(nil, "no auto-Put of %s: %r\n", a);
924 wincommit(w, &w->body);
925 put(&w->body, nil, nil, XXX, XXX, nil, 0);
934 id(Text *et, Text*, Text*, int, int, Rune*, int)
937 warning(nil, "/mnt/acme/%d/\n", et->w->id);
941 local(Text *et, Text*, Text *argt, int, int, Rune *arg, int narg)
946 aa = getbytearg(argt, TRUE, TRUE, &a);
948 dir = dirname(et, nil, 0);
949 if(dir.nr==1 && dir.r[0]=='.'){ /* sigh */
954 run(nil, runetobyte(arg, narg), dir.r, dir.nr, FALSE, aa, a, FALSE);
958 kill(Text*, Text*, Text *argt, int, int, Rune *arg, int narg)
963 getarg(argt, FALSE, FALSE, &r, &na);
965 kill(nil, nil, nil, 0, 0, r, na);
966 /* loop condition: *arg is not a blank */
968 a = findbl(arg, narg, &na);
971 cmd = runemalloc(narg-na+1);
972 runemove(cmd, arg, narg-na);
974 arg = skipbl(a, na, &narg);
979 fontx(Text *et, Text *t, Text *argt, int, int, Rune *arg, int narg)
981 Rune *a, *r, *flag, *file;
988 if(et==nil || et->w==nil)
993 /* loop condition: *arg is not a blank */
996 a = findbl(arg, narg, &na);
999 r = runemalloc(narg-na+1);
1000 runemove(r, arg, narg-na);
1001 if(runeeq(r, narg-na, L"fix", 3) || runeeq(r, narg-na, L"var", 3)){
1009 arg = skipbl(a, na, &narg);
1011 getarg(argt, FALSE, TRUE, &r, &na);
1013 if(runeeq(r, na, L"fix", 3) || runeeq(r, na, L"var", 3)){
1023 fix = runeeq(flag, runestrlen(flag), L"fix", 3);
1024 else if(file == nil){
1025 newfont = rfget(FALSE, FALSE, FALSE, nil);
1027 fix = strcmp(newfont->f->name, t->font->name)==0;
1030 aa = runetobyte(file, nf);
1031 newfont = rfget(fix, flag!=nil, FALSE, aa);
1034 newfont = rfget(fix, FALSE, FALSE, nil);
1036 draw(screen, t->w->r, textcols[BACK], nil, ZP);
1037 rfclose(t->reffont);
1038 t->reffont = newfont;
1039 t->font = newfont->f;
1042 t->all.min.x++; /* force recolumnation; disgusting! */
1043 for(i=0; i<t->w->ndl; i++){
1045 aa = runetobyte(dp->r, dp->nr);
1046 dp->wid = stringwidth(newfont->f, aa);
1050 /* avoid shrinking of window due to quantization */
1051 colgrow(t->w->col, t->w, -1);
1058 incl(Text *et, Text*, Text *argt, int, int, Rune *arg, int narg)
1064 if(et==nil || et->w==nil)
1068 getarg(argt, FALSE, TRUE, &r, &len);
1071 winaddincl(w, r, len);
1073 /* loop condition: *arg is not a blank */
1075 a = findbl(arg, narg, &na);
1078 r = runemalloc(narg-na+1);
1079 runemove(r, arg, narg-na);
1081 winaddincl(w, r, narg-na);
1082 arg = skipbl(a, na, &narg);
1084 if(n==0 && w->nincl){
1085 for(n=w->nincl; --n>=0; )
1086 warning(nil, "%S ", w->incl[n]);
1097 indentval(Rune *s, int n, int type)
1099 static char *strs[] = {
1100 [SPACESINDENT] "Spaces",
1101 [AUTOINDENT] "Indent",
1106 if(runestrncmp(s, L"ON", n) == 0){
1107 globalindent[type] = TRUE;
1108 warning(nil, "%s ON\n", strs[type]);
1111 if(runestrncmp(s, L"OFF", n) == 0){
1112 globalindent[type] = FALSE;
1113 warning(nil, "%s OFF\n", strs[type]);
1116 if(runestrncmp(s, L"on", n) == 0)
1118 if(runestrncmp(s, L"off", n) == 0)
1124 fixindent(Window *w, void *v)
1127 w->indent[t] = globalindent[t];
1131 indent(Text *et, Text*, Text *argt, int type, int, Rune *arg, int narg)
1138 if(et!=nil && et->w!=nil)
1141 getarg(argt, FALSE, TRUE, &r, &len);
1143 ival = indentval(r, len, type);
1145 a = findbl(arg, narg, &na);
1147 ival = indentval(arg, narg-na, type);
1150 allwindows(fixindent, &type);
1151 else if(w != nil && ival >= 0)
1152 w->indent[type] = ival;
1156 tab(Text *et, Text*, Text *argt, int, int, Rune *arg, int narg)
1163 if(et==nil || et->w==nil)
1166 getarg(argt, FALSE, TRUE, &r, &len);
1168 if(r!=nil && len>0){
1169 p = runetobyte(r, len);
1170 if('0'<=p[0] && p[0]<='9')
1174 a = findbl(arg, narg, &na);
1176 p = runetobyte(arg, narg-na);
1177 if('0'<=p[0] && p[0]<='9')
1183 if(w->body.tabstop != tab){
1184 w->body.tabstop = tab;
1185 winresize(w, w->r, 1);
1188 warning(nil, "%.*S: Tab %d\n", w->body.file->nname, w->body.file->name, w->body.tabstop);
1192 runproc(void *argvp)
1206 char *e, *t, *name, *filename, *dir, **av, *news;
1208 int ac, w, inarg, i, n, fd, nincl, winid;
1217 ndir = (uintptr)argv[3];
1218 newns = (uintptr)argv[4];
1223 iseditcmd = (uintptr)argv[9];
1227 while(*t==' ' || *t=='\n' || *t=='\t')
1230 if(*e==' ' || *e=='\n' || *e=='\t' )
1232 name = emalloc((e-t)+2);
1233 memmove(name, t, e-t);
1235 e = utfrrune(name, '/');
1237 memmove(name, e+1, strlen(e+1)+1); /* strcpy but overlaps */
1238 strcat(name, " "); /* add blank here for ease in waittask */
1239 c->name = bytetorune(name, &c->nname);
1242 if(*t=='<' || *t=='|' || *t=='>')
1244 c->iseditcmd = iseditcmd;
1247 dir = runetobyte(rdir, ndir);
1248 chdir(dir); /* ignore error: probably app. window */
1255 filename = smprint("%.*S", win->body.file->nname, win->body.file->name);
1258 incl = emalloc(nincl*sizeof(Rune*));
1259 for(i=0; i<nincl; i++){
1260 n = runestrlen(win->incl[i]);
1261 incl[i] = runemalloc(n+1);
1262 runemove(incl[i], win->incl[i], n);
1270 winid = activewin->id;
1272 rfork(RFNAMEG|RFENVG|RFFDG|RFNOTEG);
1273 sprint(buf, "%d", winid);
1274 putenv("winid", buf);
1277 putenv("%", filename);
1280 c->md = fsysmount(rdir, ndir, incl, nincl);
1282 fprint(2, "child: can't mount /dev/cons: %r\n");
1283 threadexits("mount");
1286 if(winid>0 && (pipechar=='|' || pipechar=='>')){
1287 sprint(buf, "/mnt/acme/%d/rdsel", winid);
1290 open("/dev/null", OREAD);
1292 if((winid>0 || iseditcmd) && (pipechar=='|' || pipechar=='<')){
1295 sprint(buf, "/mnt/acme/%d/editout", winid);
1297 sprint(buf, "/mnt/acme/editout");
1299 sprint(buf, "/mnt/acme/%d/wrsel", winid);
1302 open("/dev/cons", OWRITE);
1304 open("/dev/cons", OWRITE);
1308 rfork(RFFDG|RFNOTEG);
1311 open("/dev/null", OREAD);
1313 open(acmeerrorfile, OWRITE);
1321 putenv("acmeaddr", argaddr);
1322 if(strlen(t) > sizeof buf-10) /* may need to print into stack */
1326 w = chartorune(&r, e);
1327 if(r==' ' || r=='\t')
1331 if(utfrune("#;&|^$=`'{}()<>[]*?^~`", r))
1342 w = chartorune(&r, e);
1343 if(r==' ' || r=='\t'){
1350 av = realloc(av, (ac+1)*sizeof(char**));
1354 av = realloc(av, (ac+2)*sizeof(char**));
1358 procexec(cpid, av[0], av);
1360 if(e[0]=='/' || (e[0]=='.' && e[1]=='/'))
1363 sprint(buf, "%s/%s", cputype, av[0]);
1364 procexec(cpid, buf, av);
1366 sprint(buf, "/bin/%s", av[0]);
1367 procexec(cpid, buf, av);
1373 * ugly: set path = (. $cputype /bin)
1374 * should honor $path if unusual.
1378 memmove(buf+n, ".", 2);
1380 i = strlen(cputype)+1;
1381 memmove(buf+n, cputype, i);
1383 memmove(buf+n, "/bin", 5);
1385 fd = create("/env/path", OWRITE, 0666);
1391 news = emalloc(strlen(t) + 1 + 1 + strlen(arg) + 1 + 1);
1393 sprint(news, "%s '%s'", t, arg); /* BUG: what if quote in arg? */
1399 procexecl(cpid, "/bin/rc", "rc", "-c", t, nil);
1402 /* procexec hasn't happened, so send a zero */
1408 runwaittask(void *v)
1414 threadsetname("runwaittask");
1420 c->pid = recvul(cpid);
1421 while(c->pid == ~0);
1423 if(c->pid != 0) /* successful exec */
1436 run(Window *win, char *s, Rune *rdir, int ndir, int newns, char *argaddr, char *xarg, int iseditcmd)
1445 arg = emalloc(10*sizeof(void*));
1446 c = emalloc(sizeof *c);
1447 cpid = chancreate(sizeof(ulong), 0);
1451 arg[3] = (void*)ndir;
1452 arg[4] = (void*)newns;
1457 arg[9] = (void*)iseditcmd;
1458 proccreate(runproc, arg, STACK);
1459 /* mustn't block here because must be ready to answer mount() call in run() */
1460 arg = emalloc(2*sizeof(void*));
1463 threadcreate(runwaittask, arg, STACK);