xref: /openbsd-src/gnu/usr.bin/cvs/vms/pc.c (revision 50bf276cd1c7e20f1eda64a5e63e0fae39e12a95)
1*50bf276cStholo #include <stdio.h>
2*50bf276cStholo #include <unixio.h>
3*50bf276cStholo #include <stdlib.h>
4*50bf276cStholo #include <string.h>
5*50bf276cStholo 
6*50bf276cStholo int trace = 1;
7*50bf276cStholo 
8*50bf276cStholo extern int piped_child();
9*50bf276cStholo extern int piped_child_shutdown();
10*50bf276cStholo 
main(argc,argv)11*50bf276cStholo main (argc, argv)
12*50bf276cStholo   int argc;
13*50bf276cStholo   char ** argv;
14*50bf276cStholo {
15*50bf276cStholo   static char line[512];
16*50bf276cStholo   char *linep[] = {line, NULL};
17*50bf276cStholo   int pid;
18*50bf276cStholo   int tofd, fromfd;
19*50bf276cStholo   FILE *in, *out;
20*50bf276cStholo 
21*50bf276cStholo   while (1)
22*50bf276cStholo     {
23*50bf276cStholo     printf("\nEnter a command to run: ");
24*50bf276cStholo     line[0] = '\0';
25*50bf276cStholo     fgets(line, 511, stdin);
26*50bf276cStholo     if (!strlen(line))
27*50bf276cStholo        exit(2);
28*50bf276cStholo 
29*50bf276cStholo     line[strlen(line)-1] = '\0';
30*50bf276cStholo     pid = piped_child(linep, &tofd, &fromfd);
31*50bf276cStholo 
32*50bf276cStholo     in = fdopen(fromfd, "r");
33*50bf276cStholo     out = fdopen(tofd, "w");
34*50bf276cStholo 
35*50bf276cStholo #if 0
36*50bf276cStholo     out = fdopen(tofd, "w");
37*50bf276cStholo     fclose(out);
38*50bf276cStholo #endif
39*50bf276cStholo 
40*50bf276cStholo     do
41*50bf276cStholo        {
42*50bf276cStholo        if(!feof(stdin))
43*50bf276cStholo          {
44*50bf276cStholo          fprintf(stdout, "> ");
45*50bf276cStholo          fgets(line, 511, stdin);
46*50bf276cStholo          fputs(line, out);
47*50bf276cStholo          }
48*50bf276cStholo        else
49*50bf276cStholo          {
50*50bf276cStholo          fclose(out);
51*50bf276cStholo          close(tofd);
52*50bf276cStholo          }
53*50bf276cStholo 
54*50bf276cStholo        fgets(line, 511, in);
55*50bf276cStholo        fputs(line, stdout);
56*50bf276cStholo        line[0] = '\0';
57*50bf276cStholo        } while (!feof(in));
58*50bf276cStholo 
59*50bf276cStholo     fprintf(stderr, "waiting for child to stop\n");
60*50bf276cStholo     piped_child_shutdown(pid);
61*50bf276cStholo     }
62*50bf276cStholo }
63