From c349189b2c4978f3f045e7cf80e15e1553418c5e Mon Sep 17 00:00:00 2001 From: William Kendrick Date: Sun, 7 Dec 2008 09:03:40 +0000 Subject: [PATCH] On systems that use postscript_print (Linux and other Unix-likes), errors when attempting to issue a print command (e.g., trying to use "lpr", but that command is not available) should appear in Tux Paint. (SourceForge bug #2205528) --- docs/CHANGES.txt | 7 +++++- src/postscript_print.c | 57 +++++++++++++++++++++++++++++++++++++++--- src/postscript_print.h | 7 +++--- src/tuxpaint.c | 10 ++++++-- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 6475bd4d4..81a773b6a 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -8,7 +8,7 @@ http://www.tuxpaint.org/ $Id$ -2008.December.3 (0.9.21) +2008.December.7 (0.9.21) * New Starters: ------------- * Silver Frame @@ -79,6 +79,11 @@ $Id$ NOTE: 'printcommand' and 'altprintcommand' options not currently parsed for env. vars. + * On systems that use postscript_print (Linux and other Unix-likes), + errors when attempting to issue a print command (e.g., trying to use + "lpr", but that command is not available) should appear in Tux Paint. + (SourceForge bug #2205528) + * Build System Improvements: -------------------------- * Adhering to Debian & FreeDesktop.org standards regarding .desktop file. diff --git a/src/postscript_print.c b/src/postscript_print.c index 03afb63fa..549ad2ef8 100644 --- a/src/postscript_print.c +++ b/src/postscript_print.c @@ -36,7 +36,7 @@ implied warranty. - June 24, 2007 - August 28, 2008 + June 24, 2007 - December 7, 2008 $Id$ */ @@ -50,6 +50,7 @@ #include #include #include +#include #ifndef PAPER_H #error "---------------------------------------------------" @@ -81,7 +82,8 @@ int do_ps_save(FILE * fi, // const char *restrict const fname, const char * fname, SDL_Surface * surf, - char * pprsize) + char * pprsize, + int is_pipe) { const struct paper * ppr; int img_w = surf->w; @@ -300,8 +302,55 @@ int do_ps_save(FILE * fi, fprintf(fi, "%%%%Trailer\n"); fprintf(fi, "%%%%EOF\n"); - fclose(fi); - return 1; + if (!is_pipe) + { + fclose(fi); + return 1; + } + else + { + pid_t child_pid, w; + int status; + + child_pid = pclose(fi); + +/* debug */ +/* + printf("pclose returned %d\n", child_pid); fflush(stdout); + printf("errno = %d\n", errno); fflush(stdout); +*/ + + if (child_pid < 0 || (errno != 0 && errno != EAGAIN)) { /* FIXME: This right? */ + return 0; + } else if (child_pid == 0) { + return 1; + } + + do + { + w = waitpid(child_pid, &status, 0); + +/* debug */ +/* + if (w == -1) { perror("waitpid"); exit(EXIT_FAILURE); } + if (WIFEXITED(status)) { + printf("exited, status=%d\n", WEXITSTATUS(status)); + } else if (WIFSIGNALED(status)) { + printf("killed by signal %d\n", WTERMSIG(status)); + } else if (WIFSTOPPED(status)) { + printf("stopped by signal %d\n", WSTOPSIG(status)); + } else if (WIFCONTINUED(status)) { + printf("continued\n"); + } +*/ + } + while (w != -1 && !WIFEXITED(status) && !WIFSIGNALED(status)); + + if (WIFEXITED(status) && WEXITSTATUS(status) != 0) /* Not happy exit */ + return 0; + + return 1; + } } #endif diff --git a/src/postscript_print.h b/src/postscript_print.h index bfc0bd0cf..2f8b68b91 100644 --- a/src/postscript_print.h +++ b/src/postscript_print.h @@ -7,7 +7,7 @@ (for non-Windows, non-Mac OS X, non-BeOS platforms, e.g. Linux) (moved from tuxpaint.c in 0.9.17) - Copyright (c) 2007 by Bill Kendrick and others + Copyright (c) 2008 by Bill Kendrick and others bill@newbreedsoftware.com http://www.tuxpaint.org/ @@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - June 24, 2007 - June 25, 2007 + June 24, 2007 - December 7, 2008 $Id$ */ @@ -80,7 +80,8 @@ int do_ps_save(FILE * fi, // const char *restrict const fname, const char *fname, SDL_Surface * surf, - char * pprsize); + char * pprsize, + int is_pipe); #endif diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 7cb81bf30..9998e3644 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (See COPYING.txt) - June 14, 2002 - December 1, 2008 + June 14, 2002 - December 7, 2008 $Id$ */ @@ -1891,6 +1891,9 @@ int main(int argc, char *argv[]) #define PROMPT_PRINT_TXT gettext_noop("Your picture has been printed!") #define PROMPT_PRINT_YES gettext_noop("OK") +/* We got an error printing */ +#define PROMPT_PRINT_FAILED_TXT gettext_noop("Sorry! Your picture could not be printed!") + /* Notification that it's too soon to print again (--printdelay option is in effect) */ #define PROMPT_PRINT_TOO_SOON_TXT gettext_noop("You can’t print yet!") #define PROMPT_PRINT_TOO_SOON_YES gettext_noop("OK") @@ -15420,9 +15423,12 @@ void do_print(void) #elif defined(PRINTMETHOD_PNM_PS) /* nothing here */ #elif defined(PRINTMETHOD_PS) - if (do_ps_save(pi, pcmd, canvas, papersize)) + if (do_ps_save(pi, pcmd, canvas, papersize, 1)) do_prompt_snd(PROMPT_PRINT_TXT, PROMPT_PRINT_YES, "", SND_TUXOK, screen->w / 2, screen->h / 2); + else + do_prompt_snd(PROMPT_PRINT_FAILED_TXT, PROMPT_PRINT_YES, "", SND_YOUCANNOT, + screen->w / 2, screen->h / 2); #else #error No print method defined! #endif