Annotation of 43BSDReno/contrib/isode-beta/dsap/common/picture.c, revision 1.1

1.1     ! root        1: /* picture.c - exec printing of external attributes */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/dsap/common/RCS/picture.c,v 7.0 89/11/23 21:44:21 mrose Rel $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/dsap/common/RCS/picture.c,v 7.0 89/11/23 21:44:21 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       picture.c,v $
        !            12:  * Revision 7.0  89/11/23  21:44:21  mrose
        !            13:  * Release 6.0
        !            14:  * 
        !            15:  */
        !            16: 
        !            17: /*
        !            18:  *                               NOTICE
        !            19:  *
        !            20:  *    Acquisition, use, and distribution of this module and related
        !            21:  *    materials are subject to the restrictions of a license agreement.
        !            22:  *    Consult the Preface in the User's Manual for the full terms of
        !            23:  *    this agreement.
        !            24:  *
        !            25:  */
        !            26: 
        !            27: 
        !            28: /* LINTLIBRARY */
        !            29: 
        !            30: #include <signal.h>
        !            31: #include "quipu/util.h"
        !            32: #include "quipu/photo.h"
        !            33: #include "quipu/attr.h"
        !            34: #include "psap.h"
        !            35: #include <errno.h>
        !            36: #ifdef BSD42
        !            37: #include <sys/wait.h>
        !            38: #endif
        !            39: 
        !            40: static int     childpid = 0;
        !            41: 
        !            42: char * show_picture (picture,picture_process,len)
        !            43: char    *picture;
        !            44: char    *picture_process;
        !            45: int    len;
        !            46: {
        !            47: int     ret;
        !            48: int     pd[2];
        !            49: int     pd2[2];
        !            50: char    *decode_t4();
        !            51: static char    buffer [BUFLEN];
        !            52: char    * cp;
        !            53: char   * argv[NVEC];
        !            54: 
        !            55:        hide_picture ();
        !            56: 
        !            57:        if (*picture == '\0')
        !            58:                return ("(No data to pass !)");
        !            59:        if (picture_process == NULLCP) 
        !            60:                return ("(No external process defined !)");
        !            61: 
        !            62:        (void) sstr2arg (picture_process, NVEC, argv, " \t");
        !            63: 
        !            64:        /* get next two file descriptors  used for data xfer */
        !            65:        ret = pipe(pd);
        !            66:        if (ret == -1)
        !            67:                return ("ERROR: could not create pipe");
        !            68: 
        !            69:        ret = pipe(pd2);
        !            70:        if (ret == -1) {
        !            71:                (void) close (pd[1]);
        !            72:                (void) close (pd[0]);
        !            73:                return ("ERROR: could not create 2nd pipe");
        !            74:        }
        !            75: 
        !            76: 
        !            77:        /* generate one parent and one child process */
        !            78:        if ((childpid = fork()) == -1) {
        !            79:                (void) close (pd[1]);
        !            80:                (void) close (pd[0]);
        !            81:                (void) close (pd2[1]);
        !            82:                (void) close (pd2[0]);
        !            83:                return ("ERROR: could not fork");
        !            84:        }
        !            85: 
        !            86:        if (childpid != 0) {
        !            87: 
        !            88:                /* in parent process */
        !            89:                (void) close (pd[0]);
        !            90:                (void) close (pd2[1]);
        !            91: 
        !            92:                if (write (pd[1], picture, len) != len) {
        !            93:                        (void) close (pd[1]);
        !            94:                        (void) close (pd2[0]);
        !            95:                        return("ERROR: length error");
        !            96:                }
        !            97: 
        !            98:                (void) close (pd[1]);
        !            99: 
        !           100:                for (cp = buffer, len = BUFLEN - 1; len > 0;) {
        !           101:                        if ((ret = read (pd2[0], cp, len)) <= 0)
        !           102:                                break;
        !           103:                        cp += ret;
        !           104:                        len -= ret;
        !           105:                }
        !           106:                if (cp > buffer) {
        !           107:                    if (*--cp != '\n')
        !           108:                        cp++;
        !           109:                    *cp = NULL;
        !           110:                }
        !           111:                else
        !           112:                    (void) sprintf (buffer, "%s invoked", argv[0]);
        !           113:                
        !           114:                (void) close (pd2[0]);
        !           115:                if ( ret < 0 )
        !           116:                        return ("ERROR: read error");
        !           117: 
        !           118:                return (buffer);
        !           119: 
        !           120:        } 
        !           121: 
        !           122:                /* you're in child process */
        !           123:                if (dup2(pd[0], 0) == -1)
        !           124:                        _exit (-1);
        !           125:                (void) close (pd[0]);
        !           126:                (void) close (pd[1]);
        !           127: 
        !           128:                if (dup2(pd2[1], 1) == -1)
        !           129:                        _exit (-1);
        !           130:                (void) close (pd2[0]);
        !           131:                (void) close (pd2[1]);
        !           132: 
        !           133:                execv (argv[0],argv);
        !           134: 
        !           135:                while (read (0, buffer, sizeof buffer) > 0)
        !           136:                    continue;
        !           137:                (void) printf ("ERROR: can't execute '%s'",argv[0]);
        !           138: 
        !           139:                (void) fflush (stdout);
        !           140:                /* safety catch */
        !           141:                _exit (-1);
        !           142:                /* NOTREACHED */
        !           143: }
        !           144: 
        !           145: 
        !           146: exec_print (ps,av,proc)
        !           147: PS ps;
        !           148: AttributeValue av;
        !           149: char * proc;
        !           150: {
        !           151: char * ptr;
        !           152: PS sps;
        !           153: PE pe, grab_pe();
        !           154: 
        !           155:        (void) ps_flush (ps);
        !           156: 
        !           157:        if ((sps = ps_alloc (str_open)) == NULLPS)
        !           158:                return;
        !           159:        if (str_setup (sps,NULLCP,LINESIZE,0) == NOTOK) {
        !           160:                ps_free (sps);
        !           161:                return;
        !           162:        }
        !           163: 
        !           164:        pe = grab_pe (av);
        !           165:        (void) pe2ps (sps,pe);
        !           166: 
        !           167:        ptr = show_picture (sps->ps_base,proc,pe->pe_len);
        !           168:        ps_print (ps,ptr);
        !           169:        
        !           170:        pe_free (pe);
        !           171:        ps_free (sps);
        !           172: 
        !           173: }
        !           174: 
        !           175: 
        !           176: hide_picture ()
        !           177: {
        !           178:     int            pid;
        !           179: #ifndef        BSD42
        !           180:     int        status;
        !           181: #else
        !           182:     union wait status;
        !           183: #endif
        !           184: 
        !           185:        if (childpid > 0) {
        !           186:            (void) kill (childpid, SIGTERM);
        !           187:            while ((pid = wait (&status)) != NOTOK && childpid != pid)
        !           188:                continue;
        !           189: 
        !           190:            childpid = 0;
        !           191:        }
        !           192: }
        !           193: 
        !           194: picture_print (ps,pe,format)
        !           195: PS ps;
        !           196: PE pe;
        !           197: int format;
        !           198: {
        !           199:        if (format != READOUT)
        !           200:                pe_print (ps,pe,format);
        !           201:        else
        !           202:                ps_print (ps,"(No display process defined)");
        !           203: }
        !           204: 
        !           205: quipu_pe_cmp();
        !           206: 
        !           207: photo_syntax ()
        !           208: {
        !           209:        (void) add_attribute_syntax ("photo",
        !           210:                (IFP)pe_cpy,    NULLIFP,
        !           211:                NULLIFP,        picture_print,
        !           212:                (IFP)pe_cpy,    quipu_pe_cmp,
        !           213:                pe_free,        NULLCP,
        !           214:                NULLIFP,        TRUE );
        !           215: 
        !           216: }

unix.superglobalmegacorp.com

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