source: trunk/gui/shared/PrManUtl.VRS@ 38

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

Printer Manager: various fixes & updates.

File size: 28.2 KB
Line 
1/*:VRX DriverIsInstalled
2*/
3/* Checks if a given print driver (without extension) is installed, and if so
4 * returns the path to the active files. Returns '' if the driver is not
5 * installed.
6 */
7DriverIsInstalled: PROCEDURE
8 ARG driver
9 PARSE VALUE VRGetIni('PM_DEVICE_DRIVERS', driver, 'USER') WITH drv_path '00'x .
10 IF ( drv_path <> '') THEN
11 drv_path = STREAM( drv_path, 'C', 'QUERY EXISTS')
12RETURN drv_path
13
14
15/*:VRX GetDriverSource
16*/
17/* Figure out where to look for the PrinterPak driver files used as the install
18 * source. Preference is given to the local repository (PDR_DIR); if it's not
19 * there, we look in a couple of other places where it might have ended up.
20 * Note that we don't look for the actual installed driver files under \OS2\DLL;
21 * that logic is handled in LocateDriverFiles(), which calls this routine.
22 *
23 * Various global values are assumed to be set already:
24 * - globals.!prdrv: filespec of \OS2\INSTALL\PRDRV.LST
25 * - globals.!repository: value indicated by PM_INSTALL->PDR_DIR in OS2.INI
26 *
27 * Returns the path, or '' if not found. Also, 'pmdx' will be 0-9 if the
28 * driver is in the repository (indicating the repository subdirectory), or
29 * '' if the driver is not in the repository.
30 */
31GetDriverSource: PROCEDURE EXPOSE globals. pmdx
32 ARG driver
33 IF driver == '' THEN RETURN ''
34
35 drv_file = ''
36 IF globals.!repository <> '' THEN DO
37
38 /* See if the driver is defined in the local repository. (This is the
39 * directory where installable printer drivers are kept. OS/2 gets them
40 * from here when you select 'Printer driver included with OS/2'.)
41 */
42 pmdx = GetDriverPMDD( driver, globals.!prdrv )
43 IF pmdx == '' THEN DO
44 /* Hmm, the driver isn't listed in PRDRV.LST. Let's check to see if
45 * it's in the default repository location anyway.
46 */
47 IF WORDPOS( driver, 'ECUPS ECUPS-HP PSPRINT PSPRINT2') > 0 THEN
48 pmdx = '9'
49 ELSE
50 pmdx = '0'
51 drv_file = STREAM( globals.!repository'\PMDD_'pmdx'\'driver'.DRV', 'C', 'QUERY EXISTS')
52 IF drv_file <> '' THEN DO
53 /* We found the driver in the repository, even though it isn't
54 * defined as such. So let's add the proper definition to
55 * PRDRV.LST now.
56 */
57 CALL LINEOUT globals.!prdrv, LEFT( driver'.DRV', 14 ) pmdx ||,
58 ' (added automatically)'
59 CALL LINEOUT globals.!prdrv
60 END
61 ELSE
62 pmdx = ''
63 END
64 ELSE DO
65 /* The driver is listed; now make sure it's actually there.
66 */
67 drv_file = STREAM( globals.!repository'\PMDD_'pmdx'\'driver'.DRV', 'C', 'QUERY EXISTS')
68 END
69 END
70
71 IF drv_file == '' THEN DO
72 CALL LINEOUT globals.!log1, 'Driver' driver 'is not in the local repository.'
73 /* If the driver really isn't in the repository, there are a couple of
74 * other places that various install utilities might have put it...
75 */
76 PARSE VALUE VRGetIni('PM_INSTALL', driver'_DIR', 'USER') WITH drvr_dir '00'x .
77 IF drvr_dir == '' THEN
78 PARSE VALUE VRGetIni('InstPDR', 'PATH_TO_'driver, 'USER') WITH drvr_dir '00'x .
79 IF drvr_dir <> '' THEN DO
80 drv_file = drvr_dir'\'driver'.DRV'
81 CALL LINEOUT globals.!log1, 'Found driver in' drvr_dir'.'
82 END
83 END
84
85RETURN drv_file
86
87
88/*:VRX GetDriverPMDD
89*/
90/* Check to see which repository directory the specified driver resides in.
91 * Returns the number suffix of the PMDD_* subdirectory name, or '' if either
92 * the driver or the index file could not be located.
93 */
94GetDriverPMDD: PROCEDURE
95 PARSE ARG driver, prdrv_lst
96
97 IF prdrv_lst <> '' THEN DO
98 CALL LINEIN prdrv_lst, 1, 0
99 DO WHILE LINES( prdrv_lst ) > 0
100 PARSE VALUE LINEIN( prdrv_lst ) WITH (driver)'.DRV' pmdx .
101 IF pmdx <> '' THEN LEAVE
102 END
103 CALL STREAM prdrv_lst, 'C', 'CLOSE'
104 END
105 ELSE pmdx = ''
106
107RETURN pmdx
108
109
110/*:VRX LocateDriverFiles
111*/
112/* Returns:
113 * 0 - Driver files not found.
114 * 1 - Driver files found, path saved in 'driver_path'; 'driver_repo' will be 1
115 * if the driver is 'shipped' (i.e. defined in PRDRV.LST) or 0 otherwise.
116 * 2 - Only found installed driver files in (\OS2\DLL\xxx, saved in 'driver_path');
117 * will need to copy them somewhere for future installs.
118 */
119LocateDriverFiles: PROCEDURE EXPOSE globals. driver_path driver_repo
120 ARG driver
121 IF driver == '' THEN driver = 'PSCRIPT'
122
123 CALL LINEOUT globals.!log1, 'Looking for' driver 'files'
124
125 mustcopy = 0
126 driver_path = GetDriverSource( driver )
127
128 IF driver_path == '' THEN DO
129 /* No source found. We'll have to try copying the actual installed
130 * driver files from under \OS2\DLL.
131 */
132 CALL LINEOUT globals.!log1, 'Driver source not found. Trying installed driver.'
133 PARSE VALUE VRGetIni('PM_DEVICE_DRIVERS', driver, 'USER') WITH drv_used '00'x .
134 IF ( drv_used <> '') & VRFileExists( drv_used ) THEN
135 driver_path = drv_used
136 END
137 IF driver_path <> '' THEN DO
138 srcdir = VRParseFilePath( driver_path, 'DP')
139 pin = STREAM( srcdir'\PIN.EXE', 'C', 'QUERY EXISTS')
140 ppdenc = STREAM( srcdir'\PPDENC.EXE', 'C', 'QUERY EXISTS')
141 /* TODO should we check for all the REQUIREDDRIVER FILES as well? */
142 END
143
144 IF pmdx == '' THEN
145 driver_repo = 0
146 ELSE
147 driver_repo = 1
148
149 /* Driver (or one of its required files) was not found.
150 */
151 IF ( driver_path == '') | ( pin == '') | ( ppdenc == '') | ,
152 ( VerifyDriverEAs( driver_path ) == 0 ) THEN
153 DO
154 CALL LINEOUT globals.!log1, ' - Missing required driver files.'
155 RETURN 0
156 END
157
158 IF mustcopy THEN RETURN 2
159RETURN 1
160
161
162/*:VRX VerifyDriverEAs
163*/
164/* Make sure the driver has its extended attributes. If not, look for an
165 * accompanying .EA or .EA_ file, and join it to the driver.
166 */
167VerifyDriverEAs: PROCEDURE EXPOSE globals.
168 PARSE ARG driver
169 eas.0 = 0
170 CALL SysQueryEAList driver, 'eas.'
171 IF eas.0 == 0 THEN DO
172 ea_file = SUBSTR( driver, 1, LASTPOS('.', driver )) || 'EA'
173 IF STREAM( ea_file, 'C', 'QUERY EXISTS') == '' THEN
174 ea_file = ea_file || '_'
175 IF STREAM( ea_file, 'C', 'QUERY EXISTS') == '' THEN
176 RETURN 0
177
178 ADDRESS CMD '@UNLOCK' driver '2>NUL 1>NUL'
179 ADDRESS CMD '@EAUTIL' driver ea_file '/j /p 2>NUL 1>NUL'
180 END
181RETURN 1
182
183
184/*:VRX BldLevelVersion
185*/
186/* Parse the revision (version) number from a BLDLEVEL string
187 */
188BldLevelVersion: PROCEDURE EXPOSE globals.
189 ARG module
190 revision = ''
191
192 _nq = RXQUEUE('CREATE')
193 _oq = RXQUEUE('SET', _nq )
194
195 ADDRESS CMD '@bldlevel' module '2>&1 | RXQUEUE' _nq
196 DO QUEUED()
197 PARSE PULL _blline
198 IF LEFT( _blline, 9 ) == 'Revision:' THEN DO
199 PARSE VAR _blline 'Revision:' revision .
200 LEAVE
201 END
202 END
203
204 CALL RXQUEUE 'SET', _oq
205 CALL RXQUEUE 'DELETE', _nq
206
207 IF revision == '' THEN revision = '-'
208
209RETURN revision
210
211
212/*:VRX CopyPrinterPak
213*/
214/* Copies a printerpak driver and all its dependent files from one directory
215 * to another.
216 *
217 * driver - The fully-qualified filename of the printerpak .DRV
218 * newdrvdir - The directory where the files will be copied; must exist
219 *
220 * Returns: 1 on success, 0 on failure
221 */
222CopyPrinterPak: PROCEDURE EXPOSE globals.
223 PARSE ARG driver, newdrvdir
224
225 drv_dir = VRParseFilePath( driver, 'DP')
226 IF drv_dir == '' THEN RETURN 0
227
228 IF VerifyDriverEAs( driver ) == 0 THEN RETURN 0
229
230 CALL LINEOUT globals.!log1, 'Copying driver files from' drv_dir 'to' newdrvdir'...'
231
232 /* Read the list of required driver files from the EAs, and copy them
233 * all to the target directory.
234 */
235 IF SysGetEA( driver, 'REQUIREDDRIVERFILES', 'reqfiles') == 0 THEN DO
236 PARSE VAR reqfiles 5 filelist
237 filelist = TRANSLATE( filelist, ' ', ',')
238 DO i = 1 TO WORDS( filelist )
239 copyfile = drv_dir'\' || WORD( filelist, i )
240 ok = VRCopyFile( copyfile, newdrvdir'\' || WORD( filelist, i ))
241 CALL LINEOUT globals.!log1, ' -' copyfile '(REQUIRED):' ok
242 END
243 DROP copyfile
244 DROP filelist
245 END
246 ELSE RETURN 0
247
248 /* If there are optional files defined as well, try to copy those also.
249 */
250 IF SysGetEA( driver, 'OPTIONALDRIVERFILES', 'reqfiles') == 0 THEN DO
251 PARSE VAR reqfiles 5 filelist
252 filelist = TRANSLATE( filelist, ' ', ',')
253 DO i = 1 TO WORDS( filelist )
254 copyfile = drv_dir'\' || WORD( filelist, i )
255 IF STREAM( copyfile, 'C', 'QUERY EXISTS') == '' THEN ITERATE
256 ok = VRCopyFile( copyfile, newdrvdir'\' || WORD( filelist, i ))
257 CALL LINEOUT globals.!log1, ' -' copyfile '(OPTIONAL):' ok
258 END
259 DROP copyfile
260 DROP filelist
261 END
262
263RETURN 1
264
265
266/*:VRX PrinterExistsInDRV
267*/
268/* Determine if the specified PrinterPak driver already contains support
269 * for the specified printer model.
270 */
271PrinterExistsInDRV: PROCEDURE EXPOSE globals.
272 PARSE UPPER ARG driver_name, printer_name
273 printer_name = TRANSLATE( printer_name, '_', '.')
274
275 printer_drv = globals.!os2dir'\DLL\'driver_name'\'driver_name'.DRV'
276 /* ?? TODO: install driver_name if not found (prompt first) ?? */
277
278 IF SysGetEA( printer_drv, '.EXPAND', 'exist_ea') <> 0 THEN RETURN 0
279 PARSE VAR exist_ea 1 _eatype 3 .
280 IF C2X( _eatype ) <> 'FDFF' THEN RETURN 0
281
282 PARSE VAR exist_ea 3 _ealen 5 exist_models
283 total_len = C2D( REVERSE( _ealen ))
284
285 /* The variable exist_models now contains a null-separated list of printer
286 * models supported by the driver (including those from previously-imported
287 * PPD files). Next we check each one against our requested printer name.
288 */
289 start = 1
290 found = 0
291 DO WHILE ( found == 0 ) & ( start < total_len )
292 _strend = POS('0'x, exist_models, start )
293 IF _strend == 0 THEN LEAVE
294 _model = TRANSLATE( SUBSTR( exist_models, start, _strend - start ))
295 IF _model == printer_name THEN
296 found = 1
297 ELSE
298 start = _strend + 1
299 END
300
301RETURN found
302
303
304/*:VRX CreateDriverList
305*/
306/* Generate a driver listfile from the .EXPAND EA
307 */
308CreateDriverList: PROCEDURE EXPOSE globals.
309 ARG driver, listfile
310
311 IF STREAM( listfile, 'C', 'QUERY EXISTS') <> '' THEN
312 CALL SysFileDelete listfile
313
314 drv_name = FILESPEC('NAME', driver )
315 IF SysGetEA( driver, '.EXPAND', 'eaval') == 0 THEN DO
316 PARSE VAR eaval 3 ealen 5 models
317 offs = 1
318 datalen = C2D( REVERSE( ealen ))
319 DO WHILE offs <= datalen
320 start = SUBSTR( models, offs )
321 inc = POS('00'x, start )
322 IF inc > 1 THEN DO
323 current_name = STRIP( SUBSTR( start, 1, inc-1 ))
324 CALL LINEOUT listfile, current_name':' current_name '('drv_name')'
325 END
326 offs = offs + inc
327 END
328 CALL LINEOUT listfile
329 CALL LINEOUT globals.!log1, 'Created driver list' listfile 'for' driver'.'
330 END
331 ELSE
332 CALL LINEOUT globals.!log1, 'No drivers found in' driver '(missing .EXPAND extended attribute?)'
333
334RETURN 1
335
336
337/*:VRX AddPort_CUPS
338*/
339/* Adds a new CUPS port. Returns 0 on full success, 1 if the port was created
340 * but could not be configured, and an OS/2 or PM error code otherwise.
341 */
342AddPort_CUPS: PROCEDURE EXPOSE globals.
343 PARSE ARG portname, hostname, queuename
344 CALL LINEOUT globals.!log1, 'Creating new port' portname
345 ADDRESS CMD '@cupsport' portname hostname queuename '>>' globals.!log2
346 IF rc == 1 THEN DO
347 CALL VRSetIni 'PM_'portname, 'INITIALIZATION', hostname'#'queuename||'00'x, 'SYSTEM', 'NoClose'
348 CALL VRSetIni 'PM_'portname, 'DESCRIPTION', hostname':'queuename||'00'x, 'SYSTEM'
349 END
350RETURN rc
351
352
353/*:VRX DeletePort
354*/
355/* Deletes a printer port (any type).
356 */
357DeletePort: PROCEDURE EXPOSE globals.
358 PARSE ARG portname
359 CALL SysIni 'SYSTEM', 'PM_'portname, 'DELETE:'
360 CALL SysIni 'SYSTEM', 'PM_SPOOLER_PORT', portname, 'DELETE:'
361RETURN 1
362
363
364/*:VRX GetNextPortName
365*/
366/* Get the next unique (non-existing) port name for the specified port driver.
367 */
368GetNextPortName: PROCEDURE
369 ARG portdrv
370
371 maxports = 64 /* should be smarter about this if possible */
372 exists = 1
373 x = 0
374 DO WHILE ( x < maxports ) & ( exists == 1 )
375 x = x + 1
376 portname = portdrv || x
377 nextport = SysIni('SYSTEM', 'PM_SPOOLER_PORT', portname )
378 IF LEFT( nextport, 6 ) == 'ERROR:' THEN exists = 0
379 END
380 IF exists == 1 THEN
381 portname = ''
382
383RETURN portname
384
385
386/*:VRX GetPortDrivers
387*/
388/* Get the list of currently-installed port drivers. NOTE: we exclude LPRPDRVR
389 * from this list, because it has to be managed via the TCP/IP configuration
390 * program.
391 */
392GetPortDrivers: PROCEDURE EXPOSE portdrivers.
393 ok = SysIni('SYSTEM', 'PM_PORT_DRIVER', 'ALL:', 'installed.')
394 IF LEFT( ok, 6 ) == 'ERROR:' THEN RETURN 0
395 count = 0
396 DO i = 1 TO installed.0
397 IF installed.i = 'LPRPDRVR' THEN ITERATE
398 fullpath = STRIP( SysIni('SYSTEM', 'PM_PORT_DRIVER', installed.i ), 'T', '00'x )
399 IF LEFT( fullpath, 6 ) == 'ERROR:' THEN fullpath = ''
400 fullpath = STREAM( fullpath , 'C', 'QUERY EXISTS')
401 count = count + 1
402 portdrivers.count = installed.i || ' ' || fullpath
403 END
404 portdrivers.0 = count
405RETURN portdrivers.0
406
407
408/*:VRX GetQueueName
409*/
410/* Generate a unique queue name from the specified printer name.
411 */
412GetQueueName: PROCEDURE
413 ARG queuename
414
415 DO UNTIL badchar = 0
416 badchar = VERIFY( queuename, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-_0123456789 ')
417 IF badchar > 0 THEN
418 queuename = OVERLAY(' ', queuename, badchar, 1 )
419 END
420 queuename = LEFT( SPACE( queuename, 0 ), 8 )
421
422 tail = 0
423 PARSE VALUE VRGetIni('PM_SPOOLER', 'DIR', 'SYSTEM') WITH spldir ';' .
424 DO WHILE VRFileExists( spldir'\'queuename ) == 1
425 tail = tail + 1
426 queuename = STRIP( LEFT( queuename, 8 - LENGTH( tail ))) || tail
427 END
428
429RETURN queuename
430
431
432/*:VRX InstallPortDriver
433*/
434/* Installs a new port driver.
435 *
436 * Returns: 0 on success, 1 on error
437 */
438InstallPortDriver: PROCEDURE EXPOSE globals.
439 ARG new_pdr
440 filename = VRParseFileName( new_pdr, 'NE')
441 IF filename == '' THEN RETURN
442 installed_pdr = TRANSLATE( globals.!os2dir'\DLL\'filename )
443 IF installed_pdr <> new_pdr THEN DO
444 ok = VRCopyFile( new_pdr, installed_pdr )
445 IF ok == 0 THEN RETURN 1
446 /* Try to copy any optional files as well */
447 IF SysGetEA( new_pdr, 'OPTIONALDRIVERFILES', 'reqfiles') == 0 THEN DO
448 drv_dir = VRParseFilePath( new_pdr, 'DP')
449 PARSE VAR reqfiles 5 filelist
450 filelist = TRANSLATE( filelist, ' ', ',')
451 DO i = 1 TO WORDS( filelist )
452 copyfile = drv_dir'\' || WORD( filelist, i )
453 IF STREAM( copyfile, 'C', 'QUERY EXISTS') == '' THEN ITERATE
454 ok = VRCopyFile( copyfile, newdrvdir'\' || WORD( filelist, i ))
455 /*CALL LINEOUT globals.!log1, ' -' copyfile '(OPTIONAL):' ok*/
456 END
457 END
458 END
459
460 key = VRParseFileName( installed_pdr, 'N')
461 CALL VRSetIni 'PM_PORT_DRIVER', key, installed_pdr||'00'x, 'SYSTEM'
462RETURN 0
463
464
465/*:VRX InstallPrintDriver
466*/
467/* 'Installs' (that is to say, registers with the spooler) an OS printer
468 * device driver/model. Installs the corresponding printerpak driver if
469 * necessary.
470 *
471 * driver - The name of the printerpak driver (without path or extension)
472 * driverfull - The fully-qualified filename of the printerpak driver
473 * model - The printer make/model name used by the driver
474 *
475 * Returns: 0 on success, 1 on error
476 */
477InstallPrintDriver: PROCEDURE EXPOSE globals.
478 PARSE ARG driver, driverfull, model
479
480 ok = 0
481 targetdir = globals.!os2dir'\DLL\'driver
482 targetdrv = targetdir'\'driver'.DRV'
483 IF ( VRFileExists( targetdrv ) == 0 ) THEN DO
484 CALL VRMkDir targetdir
485 r = CopyDriverToSource( driverfull, targetdir )
486 IF r <> 1 THEN ok = 1
487 END
488 IF ok == 0 THEN DO
489 IF VRGetIni('PM_DEVICE_DRIVERS', driver, 'USER') <> targetdrv THEN
490 CALL VRSetIni 'PM_DEVICE_DRIVERS', driver, targetdrv||'00'x, 'USER'
491 CALL VRSetIni 'PM_SPOOLER_DD', driver'.'model, driver'.DRV;;;'||'00'x, 'SYSTEM'
492 END
493RETURN ok
494
495/*:VRX DeletePrintDriver
496*/
497/* Removes (that is to say, de-registers with the spooler) a PM printer
498 * device driver/model.
499 *
500 * driver - The name of the printerpak driver (without path or extension)
501 * model - The printer make/model name used by the driver
502 *
503 * Returns: 0 on success, 1 on error
504 */
505DeletePrintDriver: PROCEDURE EXPOSE globals.
506 PARSE ARG driver, model
507
508 ok = VRDelIni('PM_SPOOLER_DD', driver'.'model, 'SYSTEM')
509RETURN ok
510
511/*:VRX CreatePrinterObject
512*/
513/* Create the specified printer using SysCreateObject (this should create the
514 * queue automatically).
515 *
516 * Returns: 0 on success or non-zero return code on error.
517 */
518CreatePrinterObject: PROCEDURE EXPOSE globals.
519 PARSE ARG driver, model, portname, queuename, printername
520
521 CALL LINEOUT globals.!log1, 'Creating new printer:' printername '('queuename')'
522 ok = RPUPrinterCreate( printername, queuename, portname, driver'.'model )
523RETURN ok
524
525/*:VRX GetNameFromPPD
526*/
527GetNameFromPPD: PROCEDURE
528 ARG ppd_file
529
530 IF STREAM( ppd_file, 'C', 'QUERY EXISTS') == '' THEN RETURN ''
531 nickname = ''
532 IF VRParseFilePath( ppd_file, 'E') == 'GZ' THEN DO
533 nq = RXQUEUE('CREATE')
534 oq = RXQUEUE('SET', nq )
535 ADDRESS CMD '@gzip -c -d' ppd_file '| RXQUEUE' nq
536 DO QUEUED()
537 PARSE PULL line
538 line = STRIP( line )
539 IF LEFT( line, 15 ) == '*ShortNickName:' THEN DO
540 PARSE VAR line . ':' _nick '0D'x .
541 nickname = STRIP( _nick )
542 nickname = STRIP( nickname, 'B', '"')
543 LEAVE
544 END
545 END
546 CALL RXQUEUE 'SET', oq
547 CALL RXQUEUE 'DELETE', nq
548 END
549 ELSE DO
550 CALL LINEIN ppd_file, 1, 0
551 DO WHILE LINES( ppd_file ) <> 0
552 line = STRIP( LINEIN( ppd_file ))
553 IF LEFT( line, 15 ) == '*ShortNickName:' THEN DO
554 PARSE VAR line . ':' _nick '0D'x .
555 nickname = STRIP( _nick )
556 nickname = STRIP( nickname, 'B', '"')
557 LEAVE
558 END
559 END
560 CALL STREAM ppd_file, 'C', 'CLOSE'
561 END
562
563RETURN nickname
564
565/*:VRX CleanPPD
566*/
567/* Clean out lines from Gutenprint and Foomatic PPD files that are known to
568 * cause problems when importing with PIN. (Partially based on work by Paul
569 * Smedley and Peter Brown).
570 */
571CleanPPD: PROCEDURE
572 PARSE ARG in_ppd, logfile
573 IF logfile <> '' THEN
574 logfile = STREAM( logfile, 'C', 'QUERY EXISTS')
575
576 out_ppd = VRParseFilePath( in_ppd, 'DPN') || '.TMP'
577 IF STREAM( out_ppd, 'C', 'QUERY EXISTS') \= '' THEN
578 CALL SysFileDelete out_ppd
579
580 IF logfile <> '' THEN
581 CALL CHAROUT logfile, 'Doing cleanup on' in_ppd '...'
582
583 skip_next = 0
584 DO WHILE LINES( in_ppd ) \= 0
585 line = LINEIN( in_ppd )
586 SELECT
587 WHEN skip_next == 1 THEN DO
588 line = STRIP( TRANSLATE( line ))
589 IF line == '*END' THEN skip_next = 0
590 END
591 WHEN LEFT( line, 11 ) == '*StpDefault' THEN NOP
592 WHEN LEFT( line, 7 ) == '*StpStp' THEN NOP
593 WHEN LEFT( line, 18 ) == '*StpResolutionMap:' THEN NOP
594 WHEN LEFT( line, 14 ) == '*OPOptionHints' THEN NOP
595 WHEN LEFT( line, 4 ) == '*da.' THEN NOP
596 WHEN LEFT( line, 4 ) == '*de.' THEN NOP
597 WHEN LEFT( line, 4 ) == '*es.' THEN NOP
598 WHEN LEFT( line, 4 ) == '*fi.' THEN NOP
599 WHEN LEFT( line, 4 ) == '*fr.' THEN NOP
600 WHEN LEFT( line, 4 ) == '*it.' THEN NOP
601 WHEN LEFT( line, 4 ) == '*ja.' THEN NOP
602 WHEN LEFT( line, 4 ) == '*ko.' THEN NOP
603 WHEN LEFT( line, 4 ) == '*nb.' THEN NOP
604 WHEN LEFT( line, 4 ) == '*nl.' THEN NOP
605 WHEN LEFT( line, 4 ) == '*pt.' THEN NOP
606 WHEN LEFT( line, 4 ) == '*sv.' THEN NOP
607 WHEN LEFT( line, 7 ) == '*zh_CN.' THEN NOP
608 WHEN LEFT( line, 7 ) == '*zh_TW.' THEN NOP
609 WHEN LEFT( line, 9 ) == '*Foomatic' THEN DO
610 line = STRIP( line )
611 IF RIGHT( line, 2 ) == '&&' THEN skip_next = 1
612 END
613 OTHERWISE DO
614 CALL LINEOUT out_ppd, line
615 skip_next = 0
616 END
617 END
618 END
619 CALL STREAM in_ppd, 'C', 'CLOSE'
620 CALL STREAM out_ppd, 'C', 'CLOSE'
621
622 ok = VRCopyFile( out_ppd, in_ppd )
623 IF logfile <> '' THEN DO
624 IF ok == 1 THEN
625 CALL LINEOUT logfile, 'OK'
626 ELSE DO
627 CALL LINEOUT logfile, 'Failed!'
628 CALL LINEOUT logfile, ' ->' VRError()
629 END
630 CALL LINEOUT logfile, ''
631 END
632 CALL SysFileDelete out_ppd
633
634RETURN
635
636/*:VRX MatchPrinterModel
637*/
638/* Find a set of printers supported by the OS/2 driver which mostly closely
639 * match the given name.
640 */
641MatchPrinterModel: PROCEDURE EXPOSE globals. models.
642 PARSE UPPER ARG driver_name, printer_name
643 printer_name = TRANSLATE( printer_name, '_', '.')
644 printer_drv = globals.!os2dir'\DLL\'driver_name'\'driver_name'.DRV'
645 models.0 = 0
646
647 IF SysGetEA( printer_drv, '.EXPAND', 'exist_ea') <> 0 THEN RETURN 0
648 PARSE VAR exist_ea 1 _eatype 3 .
649 IF C2X( _eatype ) <> 'FDFF' THEN RETURN 0
650
651 PARSE VAR exist_ea 3 _ealen 5 exist_models
652 total_len = C2D( REVERSE( _ealen ))
653
654 /* The variable exist_models now contains a null-separated list of printer
655 * models supported by the driver (including those from previously-imported
656 * PPD files). Next we check each one against our requested printer name.
657 */
658 start = 1
659 count = 0
660 best = 0
661 DO WHILE start < total_len
662 _strend = POS('0'x, exist_models, start )
663 IF _strend == 0 THEN LEAVE
664 _model = TRANSLATE( SUBSTR( exist_models, start, _strend - start ))
665 _model = TRANSLATE( _model, ' ', '-')
666 _comp = COMPARE( _model, printer_name )
667 IF WORD( _model, 1 ) == WORD( printer_name, 1 ) THEN DO
668 count = count + 1
669 IF _comp == 0 THEN DO
670 _comp = 9999
671 best = count
672 END
673 ELSE IF ( best == 0 ) & ( _comp > LENGTH( printer_name )) THEN
674 best = count
675/*
676 models.count = RIGHT( _comp, 4, '0') SUBSTR( exist_models, start, _strend - start )
677*/
678 models.count = SUBSTR( exist_models, start, _strend - start )
679 END
680 start = _strend + 1
681 END
682 models.0 = count
683
684/*
685 CALL SysStemSort 'models.', 'D', 'I',,, 1, 4
686 DO i = 1 TO count
687 models.i = SUBWORD( models.i, 2 )
688 END
689*/
690RETURN best
691
692
693/*:VRX CheckWritablePath
694*/
695CheckWritablePath: PROCEDURE EXPOSE globals.
696 ARG path
697
698 /* Make sure path exists & is a directory */
699 IF \VRIsDir( path ) THEN RETURN 1
700
701 /* Make sure the drive is accessible */
702 di = SysDriveInfo( VRParseFilePath( path, 'DP'))
703 IF di == '' THEN RETURN 2
704
705 /* Make sure the drive has a supported filesystem */
706 fs = SysFileSystemType( prdrv )
707 IF WORDPOS( fs, 'HPFS JFS FAT FAT32') == 0 THEN RETURN 3
708
709RETURN 0
710
711
712/*:VRX QueryAvailableDrivers
713*/
714/* Determine which of our supported PrinterPak drivers are currently available.
715 */
716QueryAvailableDrivers: PROCEDURE EXPOSE globals. drv_list.
717 drv_list.0 = 0
718
719 test_drivers = 'ECUPS ECUPS-HP PSPRINT'
720 DO i = 1 TO WORDS( test_drivers )
721 driver = WORD( test_drivers, i )
722 ok = GetDriverSource( driver )
723 IF ok == '' THEN
724 ok = VRGetIni('PM_DEVICE_DRIVERS', driver, 'USER')
725 IF ok <> '' THEN
726 CALL SysStemInsert 'drv_list.', drv_list.0+1, driver
727 END
728
729RETURN drv_list.0
730
731
732/*:VRX UpdatePrDesc
733*/
734UpdatePrDesc: PROCEDURE EXPOSE globals.
735 ARG driver, fqn
736
737 IF globals.!prdesc == '' THEN RETURN 1
738
739 ok = RPUEnumModels( fqn, 'newdevs.')
740 IF ok == 0 THEN RETURN 2
741
742 _count = 0
743 CALL LINEIN globals.!prdesc, 1, 0
744 DO WHILE LINES( globals.!prdesc )
745 _next = LINEIN( globals.!prdesc )
746 PARSE UPPER VAR _next WITH . ':' . '('_prdrv')' .
747 IF _prdrv == driver THEN ITERATE
748 _count = _count + 1
749 prdefs.count = _next
750 END
751 CALL STREAM globals.!prdesc, 'C', 'CLOSE'
752
753 DO i = 1 TO devs.0
754 _count = _count + 1
755 prdefs._count = newdevs.i':' newdevs.i '('driver')'
756 END
757 prdefs.0 = count
758
759 CALL VRSortStem 'prdefs.'
760
761 _prdir = VRParseFileName( globals.!prdesc, 'DP')
762 CALL VRCopyFile globals.!prdesc, _prdir'\PRDESC.BAK'
763 CALL VRDeleteFile globals.!prdesc
764 DO i = 1 TO prdefs.0
765 CALL LINEOUT globals.!prdesc, prdefs.i
766 END
767 CALL LINEOUT globals.!prdesc
768
769RETURN 0
770
771
772/*:VRX NLSGetMessage
773*/
774/*
775 * Gets the message text associated with the given message number from the
776 * current language file.
777 */
778NLSGetMessage: PROCEDURE EXPOSE globals.
779 PARSE ARG msgnum, .
780 args = ARG()
781
782 msgfile = globals.!messages
783 IF msgnum == '' THEN RETURN ''
784
785 sub_parms = ''
786 DO i = 2 TO args
787 sub_parms = sub_parms', "'ARG( i )'"'
788 END
789
790 INTERPRET 'msgfromfile = SysGetMessage( msgnum, msgfile' sub_parms ')'
791
792 PARSE VAR msgfromfile message '0D'x .
793 IF SUBSTR( message, 1, 4 ) == 'SYS0' THEN message = ''
794
795RETURN message
796
797
798/*:VRX NLSSetText
799*/
800/*
801 * Sets the specified property of the specified control to the specified
802 * message text.
803 */
804NLSSetText: PROCEDURE EXPOSE globals.
805 PARSE ARG control, property, message, substitution
806 args = ARG()
807
808 success = 1
809 IF args < 4 THEN
810 text = NLSGetMessage( message )
811 ELSE DO
812 sub_parms = ''
813 DO i = 4 TO args
814 sub_parms = sub_parms '"'|| ARG( i ) ||'",'
815 END
816 sub_parms = STRIP( sub_parms, 'T', ',')
817 INTERPRET 'text = NLSGetMessage( message, 'sub_parms')'
818 END
819
820 IF text == '' THEN success = 0
821 ELSE CALL VRSet control, property, text
822
823RETURN success
824
825/*:VRX StringTokenize
826*/
827StringTokenize:
828 PARSE ARG string, separator, __stem
829 CALL __StringTokenize string, separator, __stem
830 DROP __stem
831RETURN
832
833/*:VRX __StringTokenize
834*/
835__StringTokenize: PROCEDURE EXPOSE (__stem)
836 PARSE ARG string, separator, tokens
837
838 /* Note: this differs slightly from my usual implementation in that
839 * each token is STRIPped of leading and trailing spaces.
840 */
841
842 IF ( string = '') THEN RETURN string
843 IF ( separator = '') THEN separator = ' '
844
845 i = 0
846 CALL VALUE tokens || '0', i
847 DO WHILE LENGTH( string ) > 0
848 x = 1
849 y = POS( separator, string, x )
850 IF y > 0 THEN DO
851 current = SUBSTR( string, 1, y-1 )
852 x = y + 1
853 i = i + 1
854 CALL VALUE tokens || 'i', STRIP( current )
855 END
856 ELSE DO
857 current = STRIP( string, 'B', separator )
858 i = i + 1
859 CALL VALUE tokens || 'i', STRIP( current )
860 x = LENGTH( string ) + 1
861 END
862 string = SUBSTR( string, x )
863 END
864 CALL VALUE tokens || '0', i
865
866RETURN
867
Note: See TracBrowser for help on using the repository browser.