Annotation of researchv10no/cmd/cfront/demangle/errfilt.c, revision 1.1.1.1

1.1       root        1: /*ident        "@(#)ctrans:demangler/errfilt.c 1.1"*/
                      2: /*
                      3:  * C++ Demangler Source Code
                      4:  * @(#)master  1.5
                      5:  * 7/27/88 13:54:37
                      6:  */
                      7: /* If the filter is applied using the standard
                      8:  * shell's pipes, then to use c++filt one must
                      9:  * say:
                     10:  *
                     11:  *     cc options 2>&1 | c++filt >&2
                     12:  *
                     13:  * But when this is done, the return code from
                     14:  * the cc command is lost.  Furthermore, the
                     15:  * stdout becomes the stderr.
                     16:  * This program is a kludge to alleviate these
                     17:  * problems.  It is invoked as follows:
                     18:  *
                     19:  *     errfilt "cc $OPTS" c++filt
                     20:  *
                     21:  * Only the stderr is redirected to the pipe
                     22:  * for c++filt.  Furthermore, the return code
                     23:  * is what it should be for the cc command.
                     24:  */
                     25: #include <stdio.h>
                     26: 
                     27: main(argc, argv) int argc; char **argv; {
                     28:        int pfd[2],f = -1;
                     29:        int f2;
                     30:        int rc,rc2;
                     31:        int pid;
                     32: 
                     33:        if(argc != 3) {
                     34:                fprintf(stderr, "usage: %s string1 string2\n", argv[0]);
                     35:                return 0;
                     36:        }
                     37:        pipe(pfd);
                     38:        f = fork();
                     39: 
                     40:        /* filter program */
                     41:        if(f == 0) {
                     42:                close(0);
                     43:                dup(pfd[0]);
                     44:                close(1);
                     45:                dup(2);
                     46: 
                     47:                close(pfd[0]); close(pfd[1]);
                     48:                execl("/bin/sh","sh","-c",argv[2],0);
                     49:                exit(255);
                     50:        }
                     51:        f2 = fork();
                     52:        /* base program */
                     53:        if(f2 == 0) {
                     54:                close(2);
                     55:                dup(pfd[1]);
                     56: 
                     57:                close(pfd[1]); close(pfd[0]);
                     58:                execl("/bin/sh","sh","-c",argv[1],0);
                     59:                exit(255);
                     60:        }
                     61:        close(pfd[1]); close(pfd[0]);
                     62: 
                     63:        while((pid = wait(&rc)) != -1) {
                     64:                if(pid == f) {
                     65:                        f = 0;
                     66:                }
                     67:                if(pid == f2) {
                     68:                        f2 = 0;
                     69:                        rc2 = rc;
                     70:                }
                     71:        }
                     72:        return rc2/0xff;
                     73: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.