From 33c2d047571cd4ebce2eb630515fc33aa3f05b98 Mon Sep 17 00:00:00 2001 From: Roland Mainz Date: Mon, 11 Apr 2005 01:06:15 +0000 Subject: xc/programs/Xserver/Xprint/attributes.c xc/programs/glxgears/glxgears.c xc/programs/xdbedizzy/xdbedizzy.c xc/programs/xedit/Imakefile xc/programs/xedit/Xedit-xprint.ad xc/programs/xedit/util.c xc/programs/xedit/xedit.h xc/programs/xlogo/print.c xc/programs/xlogo/xlogo.c xc/programs/xlogo/xlogo.h xc/programs/xman/Imakefile xc/programs/xman/print.h xc/programs/xmore/Imakefile xc/programs/xmore/print.c xc/programs/xmore/print.h xc/programs/xmore/printdialog.c xc/programs/xphelloworld/xpawhelloworld/xpawhelloworld.c xc/programs/xphelloworld/xphelloworld/xphelloworld.c xc/programs/xphelloworld/xpsimplehelloworld/xpsimplehelloworld.c xc/programs/xphelloworld/xpxmhelloworld/xpxmhelloworld.c //bugs.freedesktop.org/show_bug.cgi?id=790) attachment #2379 (https://bugs.freedesktop.org/attachment.cgi?id=2379) Implement support client+Xserver support for passing output (stdout+stderr) of the spooler command started by the Xprint server back to the application using the "xp-spooler-command-results" XPJobAttr attribute (applications can fetch the attribute value after the XPEndJobNotify event was received; more details can be found in http://xprint.mozdev.org/docs/dtprint_fspec.ps). --- Xedit-xprint.ad | 5 +++-- print.c | 39 +++++++++++++++++++++++++++++++++------ print.h | 8 ++++++++ printdialog.c | 8 +++++--- util.c | 34 ++++++++++++++++++++++++++++++++-- xedit.h | 4 +++- 6 files changed, 84 insertions(+), 14 deletions(-) diff --git a/Xedit-xprint.ad b/Xedit-xprint.ad index 8c1d398..cb8445f 100644 --- a/Xedit-xprint.ad +++ b/Xedit-xprint.ad @@ -71,7 +71,7 @@ Use Control-G to interrupt the lisp subprocess *buttons*showGrip: False *buttons.min: 18 -*messageWindow.height: 50 +*messageWindow.height: 70 *messageWindow.min: 18 *Paned*Text*allowResize: True @@ -153,12 +153,14 @@ mI: no-op(r) *baseTranslations: #override \ X,C:quit()\n\ X,S:save-file()\n\ +X,P:print-file()\n\ X,F:find-file()\n\ Escape: line-edit() *messageWindow.Translations: #override \ X,C:quit()\n\ X,S:save-file()\n\ +X,P:print-file()\n\ X,F:find-file()\n\ : no-op()\n\ : no-op()\n\ @@ -246,7 +248,6 @@ cR: no-op(r)\n\ mI: no-op(r)\n\ cG: cancel-find-file()\n\ Return: load-file()\n\ -P: print-file()\n\ Tab: file-completion(h)\n\ Escape: cancel-find-file()\n\ : no-op()\n\ diff --git a/print.c b/print.c index dad23e5..fbb260b 100644 --- a/print.c +++ b/print.c @@ -32,6 +32,9 @@ in this Software without prior written authorization from The Open Group. #define Assertion(expr, msg) { if (!(expr)) { Error msg } } #define Log(x) { if(True) printf x; } +#ifdef XEDIT +#include "xedit.h" +#endif /* XEDIT */ #include "print.h" #include #include @@ -181,13 +184,36 @@ PageSetupCB(Widget widget, XtPointer client_data, XtPointer call_data) static void FinishPrinting(AppPrintData *p) { + char *scr; + if (p->printtofile_handle) { if (XpuWaitForPrintFileChild(p->printtofile_handle) != XPGetDocFinished) { - fprintf(stderr, "%s: Error while printing to file.\n", apd->programname); + PrintMsg(("Error while printing to file.\n")); } p->printtofile_handle = NULL; - } + } + + /* Job completed, check if there are any messages from the spooler command */ + scr = XpGetOneAttribute(p->pdpy, p->pcontext, XPJobAttr, "xp-spooler-command-results"); + if( scr ) + { + if( strlen(scr) > 0 ) + { + const char *msg = XpuCompoundTextToXmb(p->pdpy, scr); + if( msg ) + { + PrintMsg(("Spooler command returned:\n%s", msg)); + XpuFreeXmbString(msg); + } + else + { + PrintMsg(("Spooler command returned (unconverted):\n%s", scr)); + } + } + XFree((void *)scr); + } + if (p->printshell) { XtDestroyWidget(p->printshell); p->printshell = NULL; @@ -288,7 +314,7 @@ void DoPrintTextSource(const char *programname, apd->pdpyDestroyCallback = pdpyDestroyCB; if (apd->isPrinting) { - fprintf(stderr, "%s: Already busy with printing.\n", apd->programname); + PrintMsg(("Already busy with printing.\n")); return; } @@ -303,7 +329,7 @@ void DoPrintTextSource(const char *programname, /* Get default printer resolution */ if (XpuGetResolution(pdpy, pcontext, &dpi_x, &dpi_y) != 1) { - fprintf(stderr, "%s: No default resolution for printer.\n", apd->programname); + PrintMsg(("No default resolution for printer.\n")); XpuClosePrinterDisplay(pdpy, pcontext); return; } @@ -390,17 +416,18 @@ void DoPrintTextSource(const char *programname, apd->isPrinting = True; if (toFile) { - printf("%s: Printing to file '%s'...\n", apd->programname, toFile); + PrintMsg(("Printing to file '%s'...\n", toFile)); apd->printtofile_handle = XpuStartJobToFile(pdpy, pcontext, toFile); if (!apd->printtofile_handle) { perror("XpuStartJobToFile failure"); + PrintMsg(("Printing failed: XpuStartJobToFile\n")); apd->isPrinting = False; return; } } else { - printf("%s: Printing to printer...\n", apd->programname); + PrintMsg(("Printing to printer...\n")); XpuStartJobToSpooler(pdpy); } } diff --git a/print.h b/print.h index d1ecbf6..a87779c 100644 --- a/print.h +++ b/print.h @@ -35,6 +35,14 @@ in this Software without prior written authorization from The Open Group. #include #include +#if defined(XMORE) +#define PrintMsg(x) { printf("xmore: "); printf x ; } +#elif defined(XEDIT) +#define PrintMsg(x) { XeditPrintf x ; } +#else +#error unknown application +#endif + /* Prototypes */ void DoPrintTextSource(const char *programname, Widget textsource, diff --git a/printdialog.c b/printdialog.c index 3642c07..50d2a88 100644 --- a/printdialog.c +++ b/printdialog.c @@ -44,6 +44,9 @@ in this Software without prior written authorization from The Open Group. #include #endif /* XKB */ +#ifdef XEDIT +#include "xedit.h" +#endif /* XEDIT */ #include "printdialog.h" #include "printdialogprivates.h" #include "print.h" @@ -1024,9 +1027,8 @@ createprintdialogchildren(Widget w) } else { - XtAppWarning(XtWidgetToApplicationContext(w), - "No Xprint servers could be found. " - "Check whether the XPSERVERLIST environment variable contains any valid Xprint server(s)."); + PrintMsg(("No Xprint servers could be found.\n" + "Check whether the XPSERVERLIST environment variable contains any valid Xprint server(s).\n")); } n = 0; diff --git a/util.c b/util.c index 6e8c1d4..008792c 100644 --- a/util.c +++ b/util.c @@ -57,13 +57,41 @@ extern Widget scratch; extern Widget vpanes[2], labels[3], texts[3], forms[3]; extern XawTextWrapMode wrapmodes[3]; +#ifndef va_copy +# ifdef __va_copy +# define va_copy __va_copy +# else +# error "no working va_copy was found" +# endif +#endif + /* * Implementation */ void -XeditPrintf(char *str) +XeditPrintf(const char *format, ...) { - XawTextBlock text; + char *str; + size_t size; + va_list va, + va2; + XawTextBlock text; + + va_start(va, format); + + va_copy(va2, va); + size = vsnprintf(NULL, 0, format, va2); + va_end(va2); + + str = (char *)malloc(size + 1); + if (str == NULL) + return; + + vsnprintf(str, size + 1, format, va); + str[size] = 0; + + va_end(va); + XawTextPosition pos = XawTextSourceScan(XawTextGetSource(messwidget), 0, XawstAll, XawsdRight, 1, True); @@ -75,6 +103,8 @@ XeditPrintf(char *str) XawTextReplace(messwidget, pos, pos, &text); XawTextSetInsertionPoint(messwidget, pos + text.length); + + free(str); } Widget diff --git a/xedit.h b/xedit.h index c7a786d..7e95075 100644 --- a/xedit.h +++ b/xedit.h @@ -28,6 +28,8 @@ */ /* $XFree86: xc/programs/xedit/xedit.h,v 1.17 2002/10/06 17:11:39 paulo Exp $ */ +#include +#include #include #include #include @@ -106,7 +108,7 @@ extern Boolean line_edit; void Feep(void); /* externals in util.c */ -void XeditPrintf(char*); +void XeditPrintf(const char *format, ...); Widget MakeCommandButton(Widget, char*, XtCallbackProc); Widget MakeStringBox(Widget, String, String); String GetString(Widget); -- cgit v1.2.3