History

Write to body should be passed to the executing program, as in Plan 9. Execute $FORTH or gforth if argc == 0.

iru committed 13 years ago

Commit b24bde81 parent 3bd87821 file · +53 −33Browse files

Unified · Split

fth.c+53−33
@@ -133,6 +133,7 @@ threadmain(int argc, char **argv) · 132 unmodified lines
133133 char buf1[128];
134134 CFsys *fs;
135135 char *dump;
136+ char *xargv[2];
136137
137138 dump = onestring(argc, argv);
138139
@@ -159,6 +160,15 @@ threadmain(int argc, char **argv) · 20 unmodified lines
159160 }
160161 }
161162
163+ if(argc == 0){
164+ argc = 1;
165+ argv = xargv;
166+ argv[0] = getenv("FORTH");
167+ if(argv[0] == nil)
168+ argv[0] = "gforth";
169+ argv[1] = 0;
170+ }
171+
162172 /*
163173 * notedisable("sys: write on closed pipe");
164174 * not okay to disable the note, because that
@@ -343,6 +353,39 @@ nrunes(char *s, int nb) · 178 unmodified lines
343353 return n;
344354 }
345355
356+void
357+bodyinsert(Event *e)
358+{
359+ if(e->nr == 1 && e->r[0] == 0x7F) {
360+ char buf[1];
361+ fsprint(addrfd, "#%ud,#%ud", e->q0, e->q1);
362+ fswrite(datafd, "", 0);
363+ buf[0] = 0x7F;
364+ write(rcfd, buf, 1);
365+ return;
366+ }
367+ if(e->q0 < q.p){
368+ if(debug)
369+ fprint(2, "shift typing %d... ", e->q1-e->q0);
370+ q.p += e->q1-e->q0;
371+ }
372+ else if(e->q0 <= q.p+ntyper){
373+ if(debug)
374+ fprint(2, "type->.. ");
375+ type(e, rcfd, addrfd, datafd);
376+ }
377+}
378+
379+void
380+bodydelete(Event *e)
381+{
382+ int n;
383+ n = delete(e);
384+ q.p -= n;
385+ if(israw(rcfd) && e->q1 >= q.p+n)
386+ sendbs(rcfd, n);
387+}
388+
346389 void
347390 stdinproc(void *v)
348391 {
@@ -352,7 +395,6 @@ stdinproc(void *v) · 3 unmodified lines
352395 CFid *afd = addrfd;
353396 int fd0 = rcfd;
354397 Event e, e2, e3, e4;
355− int n;
356398
357399 USED(v);
358400
@@ -369,17 +411,17 @@ stdinproc(void *v) · 10 unmodified lines
369411 print("unknown message %c%c\n", e.c1, e.c2);
370412 break;
371413
372− case 'E': /* write to body or tag; can't affect us */
414+ case 'E':
373415 switch(e.c2){
374416 case 'I':
375− case 'D': /* body */
376− if(debug)
377− fprint(2, "shift typing %d... ", e.q1-e.q0);
378− q.p += e.q1-e.q0;
417+ bodyinsert(&e);
379418 break;
380−
381− case 'i':
382− case 'd': /* tag */
419+ case 'D':
420+ bodydelete(&e);
421+ break;
422+
423+ case 'i': /* write to tag; can't affect us */
424+ case 'd':
383425 break;
384426
385427 default:
@@ -394,33 +436,11 @@ stdinproc(void *v) · 8 unmodified lines
394436 case 'M':
395437 switch(e.c2){
396438 case 'I':
397− if(e.nr == 1 && e.r[0] == 0x7F) {
398− char buf[1];
399− fsprint(addrfd, "#%ud,#%ud", e.q0, e.q1);
400− fswrite(datafd, "", 0);
401− buf[0] = 0x7F;
402− write(fd0, buf, 1);
403− break;
404− }
405− if(e.q0 < q.p){
406− if(debug)
407− fprint(2, "shift typing %d... ", e.q1-e.q0);
408− q.p += e.q1-e.q0;
409− }
410− else if(e.q0 <= q.p+ntyper){
411− if(debug)
412− fprint(2, "type... ");
413− type(&e, fd0, afd, dfd);
414− }
439+ bodyinsert(&e);
415440 break;
416−
417441 case 'D':
418− n = delete(&e);
419− q.p -= n;
420− if(israw(fd0) && e.q1 >= q.p+n)
421− sendbs(fd0, n);
442+ bodydelete(&e);
422443 break;
423−
424444 case 'x':
425445 case 'X':
426446 if(e.flag & 2)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t