4 * 19. Input/output file switching.
7 /* .so - push new source file */
9 r_so(int argc, Rune **argv)
12 pushinputfile(erunesmprint("%s", unsharp(esmprint("%S", argv[1]))));
15 /* .nx - end this file, switch to arg */
17 r_nx(int argc, Rune **argv)
26 warn("too many arguments for .nx");
27 while((n=popinput()) && n != 2)
29 pushinputfile(argv[1]);
33 /* .sy - system: run string */
38 warn(".sy not implemented");
41 /* .pi - pipe output to string */
46 warn(".pi not implemented");
49 /* .cf - copy contents of filename to output */
51 r_cf(int argc, Rune **argv)
58 p = esmprint("%S", argv[1]);
59 if((b = Bopen(p, OREAD)) == nil){
60 fprint(2, "%L: open %s: %r\n", p);
66 while((c = Bgetrune(b)) >= 0)
72 r_inputpipe(Rune *name)
74 Rune *cmd, *stop, *line;
75 int n, pid, p[2], len;
84 cmd = readline(CopyMode);
93 execl(unsharp("#9/bin/rc"), "rc", "-c", esmprint("%S", cmd), nil);
94 warn("%Cdp %S: %r", dot, cmd);
100 len = runestrlen(stop);
101 fprint(p[1], ".ps %d\n", getnr(L(".s")));
102 fprint(p[1], ".vs %du\n", getnr(L(".v")));
103 fprint(p[1], ".ft %d\n", getnr(L(".f")));
104 fprint(p[1], ".ll 8i\n");
105 fprint(p[1], ".pl 30i\n");
106 while((line = readline(~0)) != nil){
107 if(runestrncmp(line, stop, len) == 0
108 && (line[len]==' ' || line[len]==0 || line[len]=='\t'
109 || (line[len]=='\\' && line[len+1]=='}')))
111 n = runestrlen(line);
113 fprint(p[1], "%.*S", n+1, line);
124 sysfatal("%C%S %S: %s", dot, name, cmd, w->msg);
133 addreq(L("so"), r_so, 1);
134 addreq(L("nx"), r_nx, -1);
135 addraw(L("sy"), r_sy);
136 addraw(L("inputpipe"), r_inputpipe);
137 addraw(L("pi"), r_pi);
138 addreq(L("cf"), r_cf, 1);
140 nr(L("$$"), getpid());