Commits

Anonymous committed d667320 Draft

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

  • Participants
  • Parent commits b16dba0

Comments (0)

Files changed (1)

 	char buf1[128];
 	CFsys *fs;
 	char *dump;
+	char *xargv[2];
 	
 	dump = onestring(argc, argv);
 
 		}
 	}
 
+	if(argc == 0){
+		argc = 1;
+		argv = xargv;
+		argv[0] = getenv("FORTH");
+		if(argv[0] == nil)
+			argv[0] = "gforth";
+		argv[1] = 0;
+	}
+
 	/*
 	 * notedisable("sys: write on closed pipe");
 	 * not okay to disable the note, because that
 }
 
 void
+bodyinsert(Event *e)
+{
+	if(e->nr == 1 && e->r[0] == 0x7F) {
+		char buf[1];
+		fsprint(addrfd, "#%ud,#%ud", e->q0, e->q1);
+		fswrite(datafd, "", 0);
+		buf[0] = 0x7F;
+		write(rcfd, buf, 1);
+		return;
+	}
+	if(e->q0 < q.p){
+		if(debug)
+			fprint(2, "shift typing %d... ", e->q1-e->q0);
+		q.p += e->q1-e->q0;
+	}
+	else if(e->q0 <= q.p+ntyper){
+		if(debug)
+			fprint(2, "type->.. ");
+		type(e, rcfd, addrfd, datafd);
+	}
+}
+
+void
+bodydelete(Event *e)
+{
+	int n;
+	n = delete(e);
+	q.p -= n;
+	if(israw(rcfd) && e->q1 >= q.p+n)
+		sendbs(rcfd, n);
+}
+
+void
 stdinproc(void *v)
 {
 	CFid *cfd = ctlfd;
 	CFid *afd = addrfd;
 	int fd0 = rcfd;
 	Event e, e2, e3, e4;
-	int n;
 
 	USED(v);
 
 			print("unknown message %c%c\n", e.c1, e.c2);
 			break;
 
-		case 'E':	/* write to body or tag; can't affect us */
+		case 'E':
 			switch(e.c2){
 			case 'I':
-			case 'D':		/* body */
-				if(debug)
-					fprint(2, "shift typing %d... ", e.q1-e.q0);
-				q.p += e.q1-e.q0;
+				bodyinsert(&e);
 				break;
-			
-			case 'i':
-			case 'd':		/* tag */
+			case 'D':
+				bodydelete(&e);
+				break;
+		
+			case 'i':	/* write to tag; can't affect us */
+			case 'd':
 				break;
 			
 			default:
 		case 'M':
 			switch(e.c2){
 			case 'I':
-				if(e.nr == 1 && e.r[0] == 0x7F) {
-					char buf[1];
-					fsprint(addrfd, "#%ud,#%ud", e.q0, e.q1);
-					fswrite(datafd, "", 0);
-					buf[0] = 0x7F;
-					write(fd0, buf, 1);
-					break;
-				}
-				if(e.q0 < q.p){
-					if(debug)
-						fprint(2, "shift typing %d... ", e.q1-e.q0);
-					q.p += e.q1-e.q0;
-				}
-				else if(e.q0 <= q.p+ntyper){
-					if(debug)
-						fprint(2, "type... ");
-					type(&e, fd0, afd, dfd);
-				}
+				bodyinsert(&e);
 				break;
-
 			case 'D':
-				n = delete(&e);
-				q.p -= n;
-				if(israw(fd0) && e.q1 >= q.p+n)
-					sendbs(fd0, n);
+				bodydelete(&e);
 				break;
-
 			case 'x':
 			case 'X':
 				if(e.flag & 2)