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
133 char buf1[128];133 char buf1[128];
134 CFsys *fs;134 CFsys *fs;
135 char *dump;135 char *dump;
136 char *xargv[2];
136 137
137 dump = onestring(argc, argv);138 dump = onestring(argc, argv);
138 139
@@ -159,6 +160,15 @@ threadmain(int argc, char **argv) · 20 unmodified lines
159 }160 }
160 }161 }
161 162
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
162 /*172 /*
163 * notedisable("sys: write on closed pipe");173 * notedisable("sys: write on closed pipe");
164 * not okay to disable the note, because that174 * not okay to disable the note, because that
@@ -343,6 +353,39 @@ nrunes(char *s, int nb) · 178 unmodified lines
343 return n;353 return n;
344}354}
345 355
356void
357bodyinsert(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
379void
380bodydelete(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
346void389void
347stdinproc(void *v)390stdinproc(void *v)
348{391{
@@ -352,7 +395,6 @@ stdinproc(void *v) · 3 unmodified lines
352 CFid *afd = addrfd;395 CFid *afd = addrfd;
353 int fd0 = rcfd;396 int fd0 = rcfd;
354 Event e, e2, e3, e4;397 Event e, e2, e3, e4;
355 int n;
356 398
357 USED(v);399 USED(v);
358 400
@@ -369,17 +411,17 @@ stdinproc(void *v) · 10 unmodified lines
369 print("unknown message %c%c\n", e.c1, e.c2);411 print("unknown message %c%c\n", e.c1, e.c2);
370 break;412 break;
371 413
372 case 'E': /* write to body or tag; can't affect us */414 case 'E':
373 switch(e.c2){415 switch(e.c2){
374 case 'I':416 case 'I':
375 case 'D': /* body */417 bodyinsert(&e);
376 if(debug)
377 fprint(2, "shift typing %d... ", e.q1-e.q0);
378 q.p += e.q1-e.q0;
379 break;418 break;
380 419 case 'D':
381 case 'i':420 bodydelete(&e);
382 case 'd': /* tag */421 break;
422
423 case 'i': /* write to tag; can't affect us */
424 case 'd':
383 break;425 break;
384 426
385 default:427 default:
@@ -394,33 +436,11 @@ stdinproc(void *v) · 8 unmodified lines
394 case 'M':436 case 'M':
395 switch(e.c2){437 switch(e.c2){
396 case 'I':438 case 'I':
397 if(e.nr == 1 && e.r[0] == 0x7F) {439 bodyinsert(&e);
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 }
415 break;440 break;
416
417 case 'D':441 case 'D':
418 n = delete(&e);442 bodydelete(&e);
419 q.p -= n;
420 if(israw(fd0) && e.q1 >= q.p+n)
421 sendbs(fd0, n);
422 break;443 break;
423
424 case 'x':444 case 'x':
425 case 'X':445 case 'X':
426 if(e.flag & 2)446 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