gvwprn.c

Go to the documentation of this file.
00001 
00002 /* Copyright (C) 1993-1996, Russell Lang.  All rights reserved.
00003 
00004    This file is part of GSview.
00005    This program is distributed with NO WARRANTY OF ANY KIND.  No author
00006    or distributor accepts any responsibility for the consequences of using it,
00007    or for whether it serves any particular purpose or works at all, unless he
00008    or she says so in writing.  Refer to the GSview Free Public Licence 
00009    (the "Licence") for full details.
00010    Every copy of GSview must include a copy of the Licence, normally in a 
00011    plain ASCII text file named LICENCE.  The Licence grants you the right 
00012    to copy, modify and redistribute GSview, but only under certain conditions 
00013    described in the Licence.  Among other things, the Licence requires that 
00014    the copyright notice and this notice be preserved on all copies.
00015 
00016    1997 : modified for Scilab
00017    Jean-Philippe Chancelier 
00018    See gp_printfile : choose a printer and send a file to printer 
00019    2005 : Allan CORNET INRIA
00020  */
00021 /*-----------------------------------------------------------------------------------*/
00022 #include "wresource.h"
00023 #include "wcommon.h"
00024 #include "Messages.h"
00025 #include "Warnings.h"
00026 #include "Errors.h"
00027 #include "win_mem_alloc.h" /* MALLOC */
00028 /*-----------------------------------------------------------------------------------*/
00029 #define MAXSTR 256     /* maximum file name length and general string length */
00030 /* documented in Device Driver Adaptation Guide */
00031 #define PORT_BUF_SIZE 4096
00032 /*-----------------------------------------------------------------------------------*/
00033 char printer_port[32];
00034 #define PRINT_BUF_SIZE 16384u
00035 /*-----------------------------------------------------------------------------------*/
00036 extern char* GetPrinterName(void);
00037 /*-----------------------------------------------------------------------------------*/
00038 BOOL get_queuename (HINSTANCE hInstance, HWND hwnd, char *portname, char *queue)
00039 {
00040         char *PrinterName=NULL;
00041 
00042         PrinterName=GetPrinterName();
00043         if (strcmp(PrinterName,"EMPTY")==0) return FALSE;
00044         wsprintf(portname, "\\\\spool\\%s",PrinterName);
00045         if (PrinterName) { FREE(PrinterName); PrinterName=NULL;}
00046 
00047         return TRUE;
00048 }
00049 /*-----------------------------------------------------------------------------------*/
00050 /******************************************************************
00051  * Print File to port or queue 
00052  * port==NULL means prompt for port or queue with dialog box 
00053  ******************************************************************/
00054 int gp_printfile (HINSTANCE hInstance, HWND hwnd, char *filename, char *port)
00055 {
00056   DWORD count;
00057   char *buffer;
00058   char portname[MAXSTR];
00059   FILE *f;
00060   HANDLE printer;
00061   DOC_INFO_1 di;
00062   DWORD written;
00063 
00064   if (!get_queuename (hInstance, hwnd, portname, port))    return FALSE;
00065   port = portname + 8;          /* skip over \\spool\ */
00066 
00067   if ((buffer = MALLOC (PRINT_BUF_SIZE)) == (char *) NULL) return FALSE;
00068   if (filename != (char *) 0)
00069     {
00070       if ((f = fopen (filename, "rb")) == (FILE *) NULL)
00071         {
00072           FREE (buffer);
00073           return FALSE;
00074         }
00075     }
00076   else
00077     f = stdin;
00078 
00079   /* open a printer */
00080   if (!OpenPrinter (port, &printer, NULL))
00081     {
00082       sciprint (MSG_ERROR71, port, GetLastError ());
00083       FREE (buffer);
00084       return FALSE;
00085     }
00086   /* from here until ClosePrinter, should AbortPrinter on error */
00087 
00088   di.pDocName = filename;
00089   di.pOutputFile = NULL;
00090   di.pDatatype = "RAW";         /* for available types see EnumPrintProcessorDatatypes */
00091   if (!StartDocPrinter (printer, 1, (LPBYTE) & di))
00092     {
00093       sciprint (MSG_ERROR72, GetLastError ());
00094       AbortPrinter (printer);
00095       FREE (buffer);
00096       return FALSE;
00097     }
00098 
00099   while ((count = fread (buffer, 1, PRINT_BUF_SIZE, f)) != 0)
00100     {
00101       if (!WritePrinter (printer, (LPVOID) buffer, count, &written))
00102         {
00103           FREE (buffer);
00104           fclose (f);
00105           AbortPrinter (printer);
00106           return FALSE;
00107         }
00108     }
00109   fclose (f);
00110   FREE (buffer);
00111 
00112   if (!EndDocPrinter (printer))
00113     {
00114       sciprint (MSG_ERROR73, GetLastError ());
00115       AbortPrinter (printer);
00116       return FALSE;
00117     }
00118 
00119   if (!ClosePrinter (printer))
00120     {
00121       sciprint (MSG_ERROR74, GetLastError ());
00122       return FALSE;
00123     }
00124   return TRUE;
00125 }
00126 /*-----------------------------------------------------------------------------------*/

Generated on Sun Mar 4 15:03:54 2007 for Scilab [trunk] by  doxygen 1.5.1