[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

redirection & fork



If there's work being done on redirection, here's another request.
I think I know how far I'll get with this one, but anyway:

This causes a fork:
	echo ouch >[1=2]

As it does in rc, but modern Bourne shells manage this one without forking.
That makes for a pretty substantial performance boost.  I was just looking
at an es-based application, checking the number of processes created, and
this echo thing is about half of it.  I just want to write to a particular
unit, so something like "echo -u2" would be excellent, actually easier to
use since that way "2" can be a variable without needing to "eval" everything.
And of course when "read" comes along it could use the same syntax.

Sample patch demonstrating "echo -u" follows.

	Donn Cave, University Computing Services, University of Washington
	donn@cac.washington.edu
-------------------------------
*** prim-etc.c.dist	Thu Oct  1 00:25:38 1992
--- prim-etc.c	Fri Oct 16 17:59:51 1992
***************
*** 21,36 ****
  
  PRIM(echo) {
  	const char *eol = "\n";
  	if (list != NULL) {
  		const char *opt;
  		assert(list->term != NULL);
  		opt = list->term->str;
! 		if (opt != NULL && opt[0] == '-' && opt[2] == '\0') {
  			switch (opt[1]) {
  			case 'n':
  				eol = "";
  				list = list->next;
  				break;
  			case '-':
  				list = list->next;
  				break;
--- 21,54 ----
  
  PRIM(echo) {
  	const char *eol = "\n";
+ 	int unit = 1;
  	if (list != NULL) {
  		const char *opt;
  		assert(list->term != NULL);
  		opt = list->term->str;
! 		if (opt != NULL && opt[0] == '-' /*&& opt[2] == '\0'*/) {
  			switch (opt[1]) {
  			case 'n':
  				eol = "";
  				list = list->next;
  				break;
+ 			case 'u':
+ 				unit = atoi (&opt[2]);
+ 				if (unit == 0) {
+ 					int i;
+ 					for (i=2; opt[i]; ++i)
+ 						if (opt[i] != '0') break;
+ 					if ((i == 2) || opt[i]) {
+ 						/*eprint("invalid descriptor \"%s\"\n", &opt[2]);
+ 						return false;*/
+ 						unit = 1;
+ 					}
+ 					else {
+ 						list = list->next;
+ 					}
+ 				}
+ 				else list = list->next;
+ 				break;
  			case '-':
  				list = list->next;
  				break;
***************
*** 39,45 ****
  			}
  		}
  	}
! 	print("%L%s", list, " ", eol);
  	return true;
  }
  
--- 57,63 ----
  			}
  		}
  	}
! 	fprint(unit, "%L%s", list, " ", eol);
  	return true;
  }