File: tlaunch2.c

package info (click to toggle)
funtools 1.4.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,004 kB
  • sloc: ansic: 89,502; sh: 10,714; lex: 4,613; asm: 3,281; ada: 1,681; makefile: 1,468; pascal: 1,089; cpp: 1,001; cs: 879; perl: 161; python: 119; yacc: 64; sed: 38; csh: 10; tcl: 9
file content (59 lines) | stat: -rw-r--r-- 1,105 bytes parent folder | download | duplicates (7)
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
/*
 *
 * tlaunch2 -- test launch routine (child routines)
 *
 */

#define HAVE_CONFIG_H 1

#if HAVE_CONFIG_H
#include <conf.h>
#endif
#include <stdio.h>
#include <ctype.h>
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef ANSI_FUNC
int main (int argc, char **argv)
#else
int main(argc, argv)
     int argc;
     char **argv;
#endif
{
  int i;
  char c;
  char *s, *t, *u;
  int pipes[4];
  if( (s=getenv("LAUNCH_PIPES")) ){
    t = (char *)strdup(s);
    for(i=0, u=(char *)strtok(t, ","); i<4 && u; 
	i++, u=(char *)strtok(NULL,",")){
      pipes[i] = atoi(u);
      fprintf(stderr, "child pipe #%d: %d\n", i, pipes[i]);
    }
    if( t ) free(t);
    if( i < 4 ) return(1);
    close(pipes[0]);
    close(pipes[3]);
    dup2(pipes[2], 0);  close(pipes[2]);
    dup2(pipes[1], 1);  close(pipes[1]);
  }
  else{
    fprintf(stderr, "No LAUNCH_PIPE environment variable\n");
  }
  while( read(0, &c, 1) ){
    if( islower((int)c) ) c = toupper((int)c);
    write(3, &c, 1);
    write(1, &c, 1);
  }
  return 0;
}