diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2023-06-28 17:29:32 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2023-06-28 17:29:32 +0000 |
commit | 23ce26f64c34e30951ad9ade2151552ed77e7357 (patch) | |
tree | d73b31a0c2f7c7be4a69f8a8e84e00dd39c432b5 /converter/other/pstopnm.c | |
parent | 1b6e51a266008348ad93ed8b6ac9ec91b5024fea (diff) | |
download | netpbm-mirror-23ce26f64c34e30951ad9ade2151552ed77e7357.tar.gz netpbm-mirror-23ce26f64c34e30951ad9ade2151552ed77e7357.tar.xz netpbm-mirror-23ce26f64c34e30951ad9ade2151552ed77e7357.zip |
promote Advanced to Stable
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@4558 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/pstopnm.c')
-rw-r--r-- | converter/other/pstopnm.c | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/converter/other/pstopnm.c b/converter/other/pstopnm.c index f5342655..25f2c429 100644 --- a/converter/other/pstopnm.c +++ b/converter/other/pstopnm.c @@ -442,7 +442,7 @@ languageDeclaration(char const inputFileName[]) { /*---------------------------------------------------------------------------- Return the Postscript language in which the file declares it is written. (Except that if the file is on Standard Input or doesn't validly declare - a languages, just say it is Common Postscript). + a language, just say it is Common Postscript). -----------------------------------------------------------------------------*/ enum PostscriptLanguage language; @@ -909,6 +909,27 @@ execGhostscript(int const inputPipeFd, static void +copyFileStream(FILE * const ifP, + FILE * const ofP) { + + bool eof; + + for (eof = false; !eof; ) { + char buffer[4096]; + size_t readCt; + + readCt = fread(buffer, 1, sizeof(buffer), ifP); + + if (readCt == 0) + eof = true; + else + fwrite(buffer, 1, readCt, ofP); + } +} + + + +static void feedPsToGhostScript(const char * const inputFileName, struct Box const borderedBox, struct Dimensions const imageDim, @@ -927,7 +948,6 @@ feedPsToGhostScript(const char * const inputFileName, -----------------------------------------------------------------------------*/ FILE * pipeToGsP; /* Pipe to Ghostscript's standard input */ FILE * ifP; - bool eof; /* End of file on input */ pipeToGsP = fdopen(pipeToGhostscriptFd, "w"); if (pipeToGsP == NULL) @@ -947,8 +967,14 @@ feedPsToGhostScript(const char * const inputFileName, The example given is a much fancier solution than we need here, I think, so I boiled it down a bit. JM */ - if (language == ENCAPSULATED_POSTSCRIPT) - fprintf(pipeToGsP, "\n/b4_Inc_state save def /showpage { } def\n"); + if (language == ENCAPSULATED_POSTSCRIPT) { + const char * const defShowpageCmd = + "/b4_Inc_state save def /showpage { } def"; + if (verbose) + pm_message("Defining showpage with '%s'", defShowpageCmd); + + fprintf(pipeToGsP, "\n%s\n", defShowpageCmd); + } writePstrans(borderedBox, imageDim, orientation, pipeToGsP); @@ -958,22 +984,19 @@ feedPsToGhostScript(const char * const inputFileName, */ signal(SIGPIPE, SIG_IGN); - eof = FALSE; - while (!eof) { - char buffer[4096]; - size_t readCt; + copyFileStream(ifP, pipeToGsP); - readCt = fread(buffer, 1, sizeof(buffer), ifP); - if (readCt == 0) - eof = TRUE; - else - fwrite(buffer, 1, readCt, pipeToGsP); - } pm_close(ifP); - if (language == ENCAPSULATED_POSTSCRIPT) - fprintf(pipeToGsP, "\nb4_Inc_state restore showpage\n"); + if (language == ENCAPSULATED_POSTSCRIPT) { + const char * const restoreShowpageCmd = + "b4_Inc_state restore showpage"; + + if (verbose) + pm_message("Restoring showpage with '%s'", restoreShowpageCmd); + fprintf(pipeToGsP, "\n%s\n", restoreShowpageCmd); + } fclose(pipeToGsP); } |