summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/cvs/vms/pc.c
blob: 5868a7f8494556d5fd6497c69de98fc6091f5e05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <unixio.h>
#include <stdlib.h>
#include <string.h>

int trace = 1;

extern int piped_child();
extern int piped_child_shutdown();

main (argc, argv)
  int argc;
  char ** argv;
{
  static char line[512];
  char *linep[] = {line, NULL};
  int pid;
  int tofd, fromfd;
  FILE *in, *out;
  
  while (1)
    {
    printf("\nEnter a command to run: ");
    line[0] = '\0';
    fgets(line, 511, stdin);
    if (!strlen(line))
       exit(2);

    line[strlen(line)-1] = '\0';
    pid = piped_child(linep, &tofd, &fromfd);

    in = fdopen(fromfd, "r");
    out = fdopen(tofd, "w");

#if 0
    out = fdopen(tofd, "w");
    fclose(out);
#endif

    do
       {
       if(!feof(stdin))
         {
         fprintf(stdout, "> ");
         fgets(line, 511, stdin);
         fputs(line, out);
         }
       else 
         {
         fclose(out);
         close(tofd);
         }

       fgets(line, 511, in);
       fputs(line, stdout);
       line[0] = '\0';
       } while (!feof(in));

    fprintf(stderr, "waiting for child to stop\n");
    piped_child_shutdown(pid);
    }
}