|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T p
Length: 3913 (0xf49) Types: TextFile Names: »picture.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦35176feda⟧ »EurOpenD22/isode/isode-6.tar.Z« └─⟦de7628f85⟧ └─⟦this⟧ »isode-6.0/dsap/common/picture.c«
/* picture.c - exec printing of external attributes */ #ifndef lint static char *rcsid = "$Header: /f/osi/dsap/common/RCS/picture.c,v 7.0 89/11/23 21:44:21 mrose Rel $"; #endif /* * $Header: /f/osi/dsap/common/RCS/picture.c,v 7.0 89/11/23 21:44:21 mrose Rel $ * * * $Log: picture.c,v $ * Revision 7.0 89/11/23 21:44:21 mrose * Release 6.0 * */ /* * NOTICE * * Acquisition, use, and distribution of this module and related * materials are subject to the restrictions of a license agreement. * Consult the Preface in the User's Manual for the full terms of * this agreement. * */ /* LINTLIBRARY */ #include <signal.h> #include "quipu/util.h" #include "quipu/photo.h" #include "quipu/attr.h" #include "psap.h" #include <errno.h> #ifdef BSD42 #include <sys/wait.h> #endif static int childpid = 0; char * show_picture (picture,picture_process,len) char *picture; char *picture_process; int len; { int ret; int pd[2]; int pd2[2]; char *decode_t4(); static char buffer [BUFLEN]; char * cp; char * argv[NVEC]; hide_picture (); if (*picture == '\0') return ("(No data to pass !)"); if (picture_process == NULLCP) return ("(No external process defined !)"); (void) sstr2arg (picture_process, NVEC, argv, " \t"); /* get next two file descriptors used for data xfer */ ret = pipe(pd); if (ret == -1) return ("ERROR: could not create pipe"); ret = pipe(pd2); if (ret == -1) { (void) close (pd[1]); (void) close (pd[0]); return ("ERROR: could not create 2nd pipe"); } /* generate one parent and one child process */ if ((childpid = fork()) == -1) { (void) close (pd[1]); (void) close (pd[0]); (void) close (pd2[1]); (void) close (pd2[0]); return ("ERROR: could not fork"); } if (childpid != 0) { /* in parent process */ (void) close (pd[0]); (void) close (pd2[1]); if (write (pd[1], picture, len) != len) { (void) close (pd[1]); (void) close (pd2[0]); return("ERROR: length error"); } (void) close (pd[1]); for (cp = buffer, len = BUFLEN - 1; len > 0;) { if ((ret = read (pd2[0], cp, len)) <= 0) break; cp += ret; len -= ret; } if (cp > buffer) { if (*--cp != '\n') cp++; *cp = NULL; } else (void) sprintf (buffer, "%s invoked", argv[0]); (void) close (pd2[0]); if ( ret < 0 ) return ("ERROR: read error"); return (buffer); } /* you're in child process */ if (dup2(pd[0], 0) == -1) _exit (-1); (void) close (pd[0]); (void) close (pd[1]); if (dup2(pd2[1], 1) == -1) _exit (-1); (void) close (pd2[0]); (void) close (pd2[1]); execv (argv[0],argv); while (read (0, buffer, sizeof buffer) > 0) continue; (void) printf ("ERROR: can't execute '%s'",argv[0]); (void) fflush (stdout); /* safety catch */ _exit (-1); /* NOTREACHED */ } exec_print (ps,av,proc) PS ps; AttributeValue av; char * proc; { char * ptr; PS sps; PE pe, grab_pe(); (void) ps_flush (ps); if ((sps = ps_alloc (str_open)) == NULLPS) return; if (str_setup (sps,NULLCP,LINESIZE,0) == NOTOK) { ps_free (sps); return; } pe = grab_pe (av); (void) pe2ps (sps,pe); ptr = show_picture (sps->ps_base,proc,pe->pe_len); ps_print (ps,ptr); pe_free (pe); ps_free (sps); } hide_picture () { int pid; #ifndef BSD42 int status; #else union wait status; #endif if (childpid > 0) { (void) kill (childpid, SIGTERM); while ((pid = wait (&status)) != NOTOK && childpid != pid) continue; childpid = 0; } } picture_print (ps,pe,format) PS ps; PE pe; int format; { if (format != READOUT) pe_print (ps,pe,format); else ps_print (ps,"(No display process defined)"); } quipu_pe_cmp(); photo_syntax () { (void) add_attribute_syntax ("photo", (IFP)pe_cpy, NULLIFP, NULLIFP, picture_print, (IFP)pe_cpy, quipu_pe_cmp, pe_free, NULLCP, NULLIFP, TRUE ); }