diff options
| -rw-r--r-- | appl/cmd/m4.b | 25 | ||||
| -rw-r--r-- | dis/m4.dis | bin | 11662 -> 11974 bytes | |||
| -rw-r--r-- | man/1/m4 | 13 |
3 files changed, 33 insertions, 5 deletions
diff --git a/appl/cmd/m4.b b/appl/cmd/m4.b index 6d5d9864..9315bf55 100644 --- a/appl/cmd/m4.b +++ b/appl/cmd/m4.b @@ -9,6 +9,8 @@ include "bufio.m"; bufio: Bufio; Iobuf: import bufio; +include "sh.m"; + include "arg.m"; M4: module @@ -50,6 +52,7 @@ rquote := '\''; initcom := "#"; endcom := "\n"; bout: ref Iobuf; +sh: Sh; init(nil: ref Draw->Context, args: list of string) { @@ -78,6 +81,7 @@ init(nil: ref Draw->Context, args: list of string) builtin("maketemp", domaketemp); builtin("sinclude", dosinclude); builtin("substr", dosubstr); + builtin("syscmd", dosyscmd); builtin("translit", dotranslit); builtin("undefine", doundefine); builtin("undivert", doundivert); @@ -670,6 +674,23 @@ domaketemp(args: array of string) pushs(mktemp(args[1])); } +dosyscmd(args: array of string) +{ + if(len args > 1){ + { + if(sh == nil){ + sh = load Sh Sh->PATH; + if(sh == nil) + raise sys->sprint("load: can't load %s: %r", Sh->PATH); + } + sh->system(nil, args[1]); + }exception e{ + "load:*" => + error(e); + } + } +} + sysname: string; mktemp(s: string): string @@ -685,7 +706,9 @@ mktemp(s: string): string break; } # add system name, process ID and 'a' - s += sys->sprint(".%s.%.10uda", sysname, sys->pctl(0, nil)); + if(s != nil) + s += "."; + s += sys->sprint("%s.%.10uda", sysname, sys->pctl(0, nil)); while(sys->stat(s).t0 >= 0){ if(s[len s-1] == 'z') error("out of temp files: "+s); Binary files differ@@ -199,10 +199,15 @@ number selecting the first character; the third argument indicates the length of the substring. A missing third argument is taken to be large enough to extend to the end of the first string. -\" .TP -\" syscmd -\" executes the shell command given in the first argument. -\" No value is returned. +.TP +syscmd +Runs the first argument as an +.IR sh (1) +command. +No value is returned. +Note that the output of a command can be redirected to a temporary file named by +.BR maketemp , +included, and then removed. .TP translit Transliterates the characters in its first argument |
