f02bb3ce9489bb2c922188ebf94f52a0e80dd757 braney Mon Jul 5 10:45:34 2021 -0700 change system() calls to pipeline() calls. diff --git src/lib/psGfx.c src/lib/psGfx.c index 73606f6..79e2c2d 100644 --- src/lib/psGfx.c +++ src/lib/psGfx.c @@ -1,28 +1,29 @@ /* PostScript graphics - * This provides a bit of a shell around writing graphics to * a postScript file. Perhaps the most important thing it * does is convert 0,0 from being at the bottom left to * being at the top left. */ /* Copyright (C) 2011 The Regents of the University of California * See README in this or parent directory for licensing information. */ #include "common.h" #include "psPoly.h" #include "psGfx.h" #include "linefile.h" +#include "pipeline.h" static void psFloatOut(FILE *f, double x) /* Write out a floating point number, but not in too much * precision. */ { int i = round(x); if (i == x) fprintf(f, "%d ", i); else fprintf(f, "%0.4f ", x); } void psClipRect(struct psGfx *ps, double x, double y, double width, double height) @@ -432,50 +433,52 @@ void psSetDash(struct psGfx *ps, boolean on) /* Set dashed line mode on or off. If set on, show two points marked, with one point of space */ { FILE *f = ps->f; if (on) fprintf(f, "[2 1] 0 setdash\n"); else fprintf(f, "[] 0 setdash\n"); } char * convertEpsToPdf(char *epsFile) /* Convert EPS to PDF and return filename, or NULL if failure. */ { char *pdfTmpName = NULL, *pdfName=NULL; -char cmdBuffer[2048]; int sysVal = 0; struct lineFile *lf = NULL; char *line; int lineSize=0; float width=0, height=0; pdfTmpName = cloneString(epsFile); /* Get the dimensions of bounding box. */ lf = lineFileOpen(epsFile, TRUE); while(lineFileNext(lf, &line, &lineSize)) { if(strstr( line, "BoundingBox:")) { char *words[5]; chopLine(line, words); width = atof(words[3]); height = atof(words[4]); break; } } lineFileClose(&lf); /* Do conversion. */ chopSuffix(pdfTmpName); pdfName = addSuffix(pdfTmpName, ".pdf"); -safef(cmdBuffer, sizeof(cmdBuffer), "ps2pdf -dDEVICEWIDTHPOINTS=%d -dDEVICEHEIGHTPOINTS=%d %s %s", - round(width), round(height), epsFile, pdfName); -sysVal = system(cmdBuffer); +char widthBuff[1024], heightBuff[1024]; +safef(widthBuff, sizeof widthBuff, "-dDEVICEWIDTHPOINTS=%d", round(width)); +safef(heightBuff, sizeof heightBuff, "-dDEVICEHEIGHTPOINTS=%d", round(height)); +char *pipeCmd[] = { "ps2pdf", widthBuff, heightBuff, epsFile, pdfName, NULL } ; +struct pipeline *pl = pipelineOpen1(pipeCmd, pipelineWrite, "/dev/null", NULL); +sysVal = pipelineWait(pl); if(sysVal != 0) freez(&pdfName); freez(&pdfTmpName); return pdfName; }