source: trunk/gui/util/prntobj/prntobj.c@ 25

Last change on this file since 25 was 25, checked in by Alex Taylor, 12 years ago

PRNTOBJ.EXE tool to create printer objects.

File size: 3.1 KB
Line 
1/* PRNTOBJ
2 *
3 * Simple program to create a new printer object
4 *
5 * Syntax: prntobj <queuename> <portname> <driver> <title>
6 */
7
8#define INCL_DOSERRORS
9#define INCL_SPL
10#define INCL_SPLDOSPRINT
11#define INCL_SPLERRORS
12#include <os2.h>
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16
17
18#define MAX_DEVICE_NAME 9
19
20
21int main( int argc, char *argv[] )
22{
23 PRDINFO3 devinfo = {0};
24 PRQINFO3 qinfo = {0};
25 ULONG cbBuf = 0;
26 PSZ pszQueueName = NULL,
27 pszPortName = NULL,
28 pszModel = NULL,
29 pszTitle = NULL;
30 CHAR szDeviceName[ 9 ] = {0};
31 USHORT i, len;
32 SPLERR rc;
33
34 if ( argc != 5 ) {
35 printf("PRNTOBJ - Create a new spooled (local) printer object.\n");
36 printf("Syntax: prntobj <queuename> <port> <driver.model> <title>\n");
37 printf(" <queuename> Physical name of the spooler queue to create (max. 8 chars)\n");
38 printf(" <port> The output port to use, e.g. \"LPT2\" (must exist)\n");
39 printf(" <driver.model> The printer driver/model, e.g. \"PSCRIPT.HP Laserjet 4L\"\n");
40 printf(" <title> Descriptive name to use as the object title\n");
41 printf("\nExample:\n prntobj GENERICP SLPR2 \"PSCRIPT.Generic Postscript Printer\" \"My Printer\"\n");
42 return 1;
43 }
44 pszQueueName = argv[ 1 ];
45 pszPortName = strupr( argv[ 2 ] );
46 pszModel = argv[ 3 ];
47 pszTitle = argv[ 4 ];
48
49 // Generate a suitable internal device name
50 strncpy( szDeviceName, pszQueueName, MAX_DEVICE_NAME-1 );
51 i = 1;
52 len = strlen( szDeviceName );
53 rc = SplQueryDevice( NULL, szDeviceName, 0, NULL, 0, &cbBuf );
54 while (( rc != NERR_DestNotFound) && ( i < 10 )) {
55 szDeviceName[len-1] = '0' + i;
56 rc = SplQueryDevice( NULL, szDeviceName, 0, NULL, 0, &cbBuf );
57 }
58 if ( rc == NERR_DestNotFound ) {
59 devinfo.pszPrinterName = szDeviceName;
60 devinfo.pszUserName = NULL;
61 devinfo.pszLogAddr = pszPortName;
62 devinfo.pszComment = pszTitle;
63 devinfo.pszDrivers = pszModel;
64 devinfo.usTimeOut = 45;
65 rc = SplCreateDevice( NULL, 3, &devinfo, sizeof( devinfo ));
66 if ( rc != NO_ERROR ) {
67 printf("Failed to create device: SplCreateDevice() returned %u\n", rc);
68 return ( rc );
69 }
70 }
71 else {
72 printf("Failed to get unique device name: SplQueryDevice() returned %u\n", rc);
73 return ( rc );
74 }
75
76 // Create the queue
77 qinfo.pszName = pszQueueName;
78 qinfo.uPriority = PRQ_DEF_PRIORITY;
79 qinfo.fsType = PRQ3_TYPE_RAW;
80 qinfo.pszPrProc = "PMPRINT";
81 qinfo.pszComment = pszTitle;
82 qinfo.pszPrinters = szDeviceName;
83 qinfo.pszDriverName = pszModel;
84 rc = SplCreateQueue( NULL, 3, &qinfo, sizeof( qinfo ));
85 if ( rc != NO_ERROR ) {
86 printf("Failed to create printer: SplCreateQueue() returned %u", rc);
87 SplDeleteDevice( NULL, szDeviceName );
88 return ( rc );
89 }
90
91 return 0;
92}
93
94
Note: See TracBrowser for help on using the repository browser.