source: trunk/gui/shared/PrintUtl.VRS@ 22

Last change on this file since 22 was 22, checked in by Alex Taylor, 13 years ago

Fixed return code handling in a couple of shared functions.

File size: 22.3 KB
Line 
1/*:VRX GetDriverSource
2*/
3/* Figure out where to look for the PrinterPak driver files used as the install
4 * source. Preference is given to the local repository (PDR_DIR); if it's not
5 * there, we look in a couple of other places where it might have ended up.
6 * Note that we don't look for the actual installed driver files under \OS2\DLL;
7 * if the application wants to fall back to those in some way, then it will have
8 * to take care of that logic itself.
9 *
10 * Various global values are assumed to be set already:
11 * - globals.!prdrv: filespec of \OS2\INSTALL\PRDRV.LST
12 * - globals.!repository: value indicated by PM_INSTALL->PDR_DIR in OS2.INI
13 *
14 * Returns the path, or '' if not found. Also, 'pmdx' will be 0-9 if the
15 * driver is in the repository (indicating the repository subdirectory), or
16 * '' if the driver is not in the repository.
17 */
18GetDriverSource: PROCEDURE EXPOSE globals. pmdx
19 ARG driver
20 IF driver == '' THEN RETURN ''
21
22 drv_file = ''
23 IF globals.!repository <> '' THEN DO
24
25 /* See if the driver is defined in the local repository. (This is the
26 * directory where installable printer drivers are kept. OS/2 gets them
27 * from here when you select 'Printer driver included with OS/2'.)
28 */
29 pmdx = GetDriverPMDD( driver, globals.!prdrv )
30 IF pmdx == '' THEN DO
31 /* Hmm, the driver isn't listed in PRDRV.LST. Let's check to see if
32 * it's in the default repository location anyway.
33 */
34 IF WORDPOS( driver, 'ECUPS ECUPS-HP PSPRINT PSPRINT2') > 0 THEN
35 pmdx = '9'
36 ELSE
37 pmdx = '0'
38 drv_file = STREAM( globals.!repository'\PMDD_'pmdx'\'driver'.DRV', 'C', 'QUERY EXISTS')
39 IF drv_file <> '' THEN DO
40 /* We found the driver in the repository, even though it isn't
41 * defined as such. So let's add the proper definition to
42 * PRDRV.LST now.
43 */
44 CALL LINEOUT globals.!prdrv, LEFT( driver'.DRV', 14 ) pmdx ||,
45 ' (added automatically)'
46 CALL LINEOUT globals.!prdrv
47 END
48 ELSE
49 pmdx = ''
50 END
51 ELSE DO
52 /* The driver is listed; now make sure it's actually there.
53 */
54 drv_file = STREAM( globals.!repository'\PMDD_'pmdx'\'driver'.DRV', 'C', 'QUERY EXISTS')
55 END
56 END
57
58 IF drv_file == '' THEN DO
59 CALL LINEOUT globals.!log1, 'Driver' driver 'is not in the local repository.'
60 /* If the driver really isn't in the repository, there are a couple of
61 * other places that various install utilities might have put it...
62 */
63 PARSE VALUE VRGetIni('PM_INSTALL', driver'_DIR', 'USER') WITH drvr_dir '00'x .
64 IF drvr_dir == '' THEN
65 PARSE VALUE VRGetIni('InstPDR', 'PATH_TO_'driver, 'USER') WITH drvr_dir '00'x .
66 IF drvr_dir <> '' THEN DO
67 drv_file = drvr_dir'\'driver'.DRV'
68 CALL LINEOUT globals.!log1, 'Found driver in' drvr_dir'.'
69 END
70 END
71
72RETURN drv_file
73
74
75/*:VRX GetDriverPMDD
76*/
77/* Check to see which repository directory the specified driver resides in.
78 * Returns the number suffix of the PMDD_* subdirectory name, or '' if either
79 * the driver or the index file could not be located.
80 */
81GetDriverPMDD: PROCEDURE
82 PARSE ARG driver, prdrv_lst
83
84 IF prdrv_lst <> '' THEN DO
85 CALL LINEIN prdrv_lst, 1, 0
86 DO WHILE LINES( prdrv_lst ) > 0
87 PARSE VALUE LINEIN( prdrv_lst ) WITH (driver)'.DRV' pmdx .
88 IF pmdx <> '' THEN LEAVE
89 END
90 CALL STREAM prdrv_lst, 'C', 'CLOSE'
91 END
92 ELSE pmdx = ''
93
94RETURN pmdx
95
96
97/*:VRX VerifyDriverEAs
98*/
99/* Make sure the driver has its extended attributes. If not, look for an
100 * accompanying .EA or .EA_ file, and join it to the driver.
101 */
102VerifyDriverEAs: PROCEDURE EXPOSE globals.
103 PARSE ARG driver
104 eas.0 = 0
105 CALL SysQueryEAList driver, 'eas.'
106 IF eas.0 == 0 THEN DO
107 ea_file = SUBSTR( driver, 1, LASTPOS('.', driver )) || 'EA'
108 IF STREAM( ea_file, 'C', 'QUERY EXISTS') == '' THEN
109 ea_file = ea_file || '_'
110 IF STREAM( ea_file, 'C', 'QUERY EXISTS') == '' THEN
111 RETURN 0
112
113 ADDRESS CMD '@UNLOCK' driver '2>NUL 1>NUL'
114 ADDRESS CMD '@EAUTIL' driver ea_file '/j /p 2>NUL 1>NUL'
115 END
116RETURN 1
117
118
119/*:VRX CopyDriverToSource
120*/
121/* Copies a printerpak driver and all its files from one directory to another.
122 * Usually the target is the source (repository) directory used for
123 * installation, hence the function name. However, this routine can be used
124 * in other contexts as well.
125 *
126 * driver - The fully-qualified filename of the printerpak driver
127 * newdrvdir - The directory where the files will be copied; must exist
128 */
129CopyDriverToSource: PROCEDURE EXPOSE globals.
130 PARSE ARG driver, newdrvdir
131
132 drv_dir = VRParseFilePath( driver, 'DP')
133 IF drv_dir == '' THEN RETURN 0
134
135 IF VerifyDriverEAs( driver ) == 0 THEN RETURN 0
136
137 CALL LINEOUT globals.!log1, 'Copying driver files from' drv_dir 'to' newdrvdir'...'
138
139 /* Read the list of required driver files from the EAs, and copy them
140 * all to the target directory.
141 */
142 IF SysGetEA( driver, 'REQUIREDDRIVERFILES', 'reqfiles') == 0 THEN DO
143 PARSE VAR reqfiles 5 filelist
144 filelist = TRANSLATE( filelist, ' ', ',')
145 DO i = 1 TO WORDS( filelist )
146 copyfile = drv_dir'\' || WORD( filelist, i )
147 ok = VRCopyFile( copyfile, newdrvdir'\' || WORD( filelist, i ))
148 CALL LINEOUT globals.!log1, ' -' copyfile '(REQUIRED):' ok
149 END
150 DROP copyfile
151 DROP filelist
152 END
153 ELSE RETURN 0
154
155 /* If there are optional files defined as well, try to copy those also.
156 */
157 IF SysGetEA( driver, 'OPTIONALDRIVERFILES', 'reqfiles') == 0 THEN DO
158 PARSE VAR reqfiles 5 filelist
159 filelist = TRANSLATE( filelist, ' ', ',')
160 DO i = 1 TO WORDS( filelist )
161 copyfile = drv_dir'\' || WORD( filelist, i )
162 IF STREAM( copyfile, 'C', 'QUERY EXISTS') == '' THEN ITERATE
163 ok = VRCopyFile( copyfile, newdrvdir'\' || WORD( filelist, i ))
164 CALL LINEOUT globals.!log1, ' -' copyfile '(OPTIONAL):' ok
165 END
166 DROP copyfile
167 DROP filelist
168 END
169
170RETURN 1
171
172
173/*:VRX PrinterExistsInDRV
174*/
175/* Determine if the specified PrinterPak driver already contains support
176 * for the specified printer model.
177 */
178PrinterExistsInDRV: PROCEDURE EXPOSE globals.
179 PARSE UPPER ARG driver_name, printer_name
180 printer_name = TRANSLATE( printer_name, '_', '.')
181
182 printer_drv = globals.!bootdrv'\OS2\DLL\'driver_name'\'driver_name'.DRV'
183 /* ?? TODO: install driver_name if not found (prompt first) ?? */
184
185 IF SysGetEA( printer_drv, '.EXPAND', 'exist_ea') <> 0 THEN RETURN 0
186 PARSE VAR exist_ea 1 _eatype 3 .
187 IF C2X( _eatype ) <> 'FDFF' THEN RETURN 0
188
189 PARSE VAR exist_ea 3 _ealen 5 exist_models
190 total_len = C2D( REVERSE( _ealen ))
191
192 /* The variable exist_models now contains a null-separated list of printer
193 * models supported by the driver (including those from previously-imported
194 * PPD files). Next we check each one against our requested printer name.
195 */
196 start = 1
197 found = 0
198 DO WHILE ( found == 0 ) & ( start < total_len )
199 _strend = POS('0'x, exist_models, start )
200 IF _strend == 0 THEN LEAVE
201 _model = TRANSLATE( SUBSTR( exist_models, start, _strend - start ))
202 IF _model == printer_name THEN
203 found = 1
204 ELSE
205 start = _strend + 1
206 END
207
208RETURN found
209
210
211/*:VRX CreateDriverList
212*/
213/* Generate a driver listfile from the .EXPAND EA
214 */
215CreateDriverList: PROCEDURE EXPOSE globals.
216 ARG driver, listfile
217
218 IF STREAM( listfile, 'C', 'QUERY EXISTS') <> '' THEN
219 CALL SysFileDelete listfile
220
221 drv_name = FILESPEC('NAME', driver )
222 IF SysGetEA( driver, '.EXPAND', 'eaval') == 0 THEN DO
223 PARSE VAR eaval 3 ealen 5 models
224 offs = 1
225 datalen = C2D( REVERSE( ealen ))
226 DO WHILE offs <= datalen
227 start = SUBSTR( models, offs )
228 inc = POS('00'x, start )
229 IF inc > 1 THEN DO
230 current_name = STRIP( SUBSTR( start, 1, inc-1 ))
231 CALL LINEOUT listfile, current_name':' current_name '('drv_name')'
232 END
233 offs = offs + inc
234 END
235 CALL LINEOUT listfile
236 CALL LINEOUT globals.!log1, 'Created driver list' listfile 'for' driver'.'
237 END
238 ELSE
239 CALL LINEOUT globals.!log1, 'No drivers found in' driver '(missing .EXPAND extended attribute?)'
240
241RETURN 1
242
243
244/*:VRX AddPort_CUPS
245*/
246/* Adds a new CUPS port. Returns 0 on full success, 1 if the port was created
247 * but could not be configured, and an OS/2 or PM error code otherwise.
248 */
249AddPort_CUPS: PROCEDURE EXPOSE globals.
250 PARSE ARG portname, hostname, queuename
251 CALL LINEOUT globals.!log1, 'Creating new port' portname
252 ADDRESS CMD '@cupsport' portname hostname queuename '>>' globals.!log2
253 IF rc == 1 THEN DO
254 CALL VRSetIni 'PM_'portname, 'INITIALIZATION', hostname'#'queuename||'00'x, 'SYSTEM', 'NoClose'
255 CALL VRSetIni 'PM_'portname, 'DESCRIPTION', hostname':'queuename||'00'x, 'SYSTEM'
256 END
257RETURN rc
258
259
260/*:VRX DeletePort
261*/
262/* Deletes a printer port (any type).
263 */
264DeletePort: PROCEDURE EXPOSE globals.
265 PARSE ARG portname
266 CALL SysIni 'SYSTEM', 'PM_'portname, 'DELETE:'
267 CALL SysIni 'SYSTEM', 'PM_SPOOLER_PORT', portname, 'DELETE:'
268RETURN 1
269
270
271/*:VRX GetNextPortName
272*/
273/* Get the next unique (non-existing) port name for the specified port driver.
274 */
275GetNextPortName: PROCEDURE
276 ARG portdrv
277
278 maxports = 64 /* should be smarter about this if possible */
279 exists = 1
280 x = 0
281 DO WHILE ( x < maxports ) & ( exists == 1 )
282 x = x + 1
283 portname = portdrv || x
284 nextport = SysIni('SYSTEM', 'PM_SPOOLER_PORT', portname )
285 IF LEFT( nextport, 6 ) == 'ERROR:' THEN exists = 0
286 END
287 IF exists == 1 THEN
288 portname = ''
289
290RETURN portname
291
292
293/*:VRX GetQueueName
294*/
295/* Generate a unique queue name from the specified printer name.
296 */
297GetQueueName: PROCEDURE
298 ARG queuename
299
300 DO UNTIL badchar = 0
301 badchar = VERIFY( queuename, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-_0123456789 ')
302 IF badchar > 0 THEN
303 queuename = OVERLAY(' ', queuename, badchar, 1 )
304 END
305 queuename = LEFT( SPACE( queuename, 0 ), 8 )
306
307 tail = 0
308 PARSE VALUE VRGetIni('PM_SPOOLER', 'DIR', 'SYSTEM') WITH spldir ';' .
309 DO WHILE VRFileExists( spldir'\'queuename ) == 1
310 tail = tail + 1
311 queuename = STRIP( LEFT( queuename, 8 - LENGTH( tail ))) || tail
312 END
313
314RETURN queuename
315
316
317/*:VRX InstallPrintDriver
318*/
319/* 'Installs' (that is to say, registers with the spooler) an OS printer
320 * device driver/model. Installs the corresponding printerpak driver if
321 * necessary.
322 *
323 * driver - The name of the printerpak driver (without path or extension)
324 * driverfull - The fully-qualified filename of the printerpak driver
325 * model - The printer make/model name used by the driver
326 */
327InstallPrintDriver: PROCEDURE EXPOSE globals.
328 PARSE ARG driver, driverfull, model
329
330 ok = 0
331 targetdir = globals.!os2dir'\DLL\'driver
332 IF ( VRFileExists( targetdir'\'driver'.DRV') == 0 ) THEN DO
333 CALL VRMkDir targetdir
334 ok = CopyDriverToSource( driverfull, targetdir )
335 END
336 IF VRGetIni('PM_DEVICE_DRIVERS', driver, 'USER', 'NoClose') <> driverfull THEN
337 CALL VRSetIni 'PM_DEVICE_DRIVERS', driver, driverfull||'00'x, 'USER'
338 CALL VRSetIni 'PM_SPOOLER_DD', driver'.'model, driver'.DRV;;;'||'00'x, 'SYSTEM'
339RETURN ok
340
341
342/*:VRX CreatePrinterObject
343*/
344/* Create the specified printer using SysCreateObject (this should create the
345 * queue automatically).
346 */
347CreatePrinterObject: PROCEDURE
348 PARSE ARG driver, model, portname, queuename, printername
349
350 oid = '<WPPO_'queuename'>'
351 setup = 'PORTNAME='portname';PRINTDRIVER='driver'.'model';QUEUENAME='queuename';TAKEDEFAULTS=YES'
352
353 ok = SysCreateObject('WPPrinter', printername, '<WP_DESKTOP>', setup';OBJECTID='oid';', 'F')
354 IF ok == 1 THEN
355 CALL SysMoveObject oid, '<WP_PRINTERSFOLDER>'
356 ELSE
357 ok = SysCreateObject('WPPrinter', printername, '<WP_DESKTOP>', setup';', 'F')
358
359RETURN ok
360
361
362/*:VRX RSPCreatePort
363*/
364/* Create/update a RINSTPRN response file to create the specified port.
365 */
366RSPCreatePort: PROCEDURE
367 PARSE ARG rsp, portdriver, portname, hostname, printername
368
369 CALL LINEOUT rsp, '* Creates a new printer port.'
370 CALL LINEOUT rsp, '*'
371 CALL LINEOUT rsp, 'ADDPORT'
372 CALL LINEOUT rsp, ' NAME =' portname
373 CALL LINEOUT rsp, ' PORTDRIVER =' portdriver
374 CALL LINEOUT rsp, ' DESCRIPTION =' hostname':'printername
375 CALL LINEOUT rsp, ' INITIALIZATION =' hostname'#'printername
376 CALL LINEOUT rsp, ' TERMINATION = ;'
377 CALL LINEOUT rsp, ' TIMEOUT = 45;'
378 CALL LINEOUT rsp, 'ENDPORT'
379 CALL LINEOUT rsp, ''
380 CALL LINEOUT rsp
381RETURN 1
382
383
384/*:VRX RSPCreatePrinter
385*/
386/* Create a RINSTPRN response file to create the specified printer.
387 */
388RSPCreatePrinter: PROCEDURE
389 PARSE ARG rsp, driver, model, portname, queuename, printername
390
391 IF STREAM( rsp, 'C', 'QUERY EXISTS') <> '' THEN
392 CALL SysFileDelete rsp
393
394 /* This is temporary until we can implement proper options configuration */
395 PARSE UPPER VALUE VALUE('LANG',,'OS2ENVIRONMENT') WITH 1 . 4 _ctry 6 .
396 IF ( WORDPOS( _ctry, 'US CA MX BO CO VE PH CL') > 0 ) THEN
397 page = 'Letter'
398 ELSE
399 page = 'A4'
400 o9n = 'PORTRAIT'
401
402 CALL LINEOUT rsp, '* Creates both a printer queue and a desktop object for this printer.'
403 CALL LINEOUT rsp, '*'
404 CALL LINEOUT rsp, 'ADDQUEUE'
405 CALL LINEOUT rsp, ' NAME =' queuename
406 CALL LINEOUT rsp, ' COMMENT =' printername
407 CALL LINEOUT rsp, ' DRIVERNAME =' driver'.'model
408 CALL LINEOUT rsp, ' PORT =' portname
409 CALL LINEOUT rsp, ' DEFINEQUEUEPROPS'
410 CALL LINEOUT rsp, ' FORMNAME =' page
411 CALL LINEOUT rsp, ' ORIENTATION =' o9n
412 CALL LINEOUT rsp, ' ENDQUEUEPROPS'
413 CALL LINEOUT rsp, 'ENDQUEUE'
414 CALL LINEOUT rsp, ''
415 CALL LINEOUT rsp
416RETURN 1
417
418
419/*:VRX RSPInstallDriver
420*/
421/* Create/update a RINSTPRN response file to install the specified printer
422 * driver. (This doesn't always seem to work so we don't use it except as
423 * a fallback.)
424 */
425RSPInstallDriver: PROCEDURE
426 PARSE ARG rsp, driver, model
427
428 CALL LINEOUT rsp, '* Installs the' driver 'PrinterPak driver.'
429 CALL LINEOUT rsp, '*'
430 CALL LINEOUT rsp, 'ADDPRINTDRIVER'
431 CALL LINEOUT rsp, ' NAME =' driver
432 CALL LINEOUT rsp, 'ENDPRINTDRIVER'
433 CALL LINEOUT rsp, ''
434 CALL LINEOUT rsp, '* Installs support for the' model 'device.'
435 CALL LINEOUT rsp, '*'
436 CALL LINEOUT rsp, 'ADDPRINTDEVICE'
437 CALL LINEOUT rsp, ' NAME =' model
438 CALL LINEOUT rsp, ' DRIVER =' driver
439 CALL LINEOUT rsp, 'ENDPRINTDEVICE'
440 CALL LINEOUT rsp, ''
441 CALL LINEOUT rsp
442RETURN 1
443
444
445/*:VRX GetNameFromPPD
446*/
447GetNameFromPPD: PROCEDURE
448 ARG ppd_file
449
450 IF STREAM( ppd_file, 'C', 'QUERY EXISTS') == '' THEN RETURN ''
451 nickname = ''
452 IF VRParseFilePath( ppd_file, 'E') == 'GZ' THEN DO
453 nq = RXQUEUE('CREATE')
454 oq = RXQUEUE('SET', nq )
455 ADDRESS CMD '@gzip -c -d' ppd_file '| RXQUEUE' nq
456 DO QUEUED()
457 PARSE PULL line
458 line = STRIP( line )
459 IF LEFT( line, 15 ) == '*ShortNickName:' THEN DO
460 PARSE VAR line . ':' _nick '0D'x .
461 nickname = STRIP( _nick )
462 nickname = STRIP( nickname, 'B', '"')
463 LEAVE
464 END
465 END
466 CALL RXQUEUE 'SET', oq
467 CALL RXQUEUE 'DELETE', nq
468 END
469 ELSE DO
470 CALL LINEIN ppd_file, 1, 0
471 DO WHILE LINES( ppd_file ) <> 0
472 line = STRIP( LINEIN( ppd_file ))
473 IF LEFT( line, 15 ) == '*ShortNickName:' THEN DO
474 PARSE VAR line . ':' _nick '0D'x .
475 nickname = STRIP( _nick )
476 nickname = STRIP( nickname, 'B', '"')
477 LEAVE
478 END
479 END
480 CALL STREAM ppd_file, 'C', 'CLOSE'
481 END
482
483RETURN nickname
484
485/*:VRX CleanPPD
486*/
487/* Clean out lines from Gutenprint and Foomatic PPD files that are known to
488 * cause problems when importing with PIN. (Partially based on work by Paul
489 * Smedley and Peter Brown).
490 */
491CleanPPD: PROCEDURE
492 PARSE ARG in_ppd, logfile
493 IF logfile <> '' THEN
494 logfile = STREAM( logfile, 'C', 'QUERY EXISTS')
495
496 out_ppd = VRParseFilePath( in_ppd, 'DPN') || '.TMP'
497 IF STREAM( out_ppd, 'C', 'QUERY EXISTS') \= '' THEN
498 CALL SysFileDelete out_ppd
499
500 IF logfile <> '' THEN
501 CALL CHAROUT logfile, 'Doing cleanup on' in_ppd '...'
502
503 skip_next = 0
504 DO WHILE LINES( in_ppd ) \= 0
505 line = LINEIN( in_ppd )
506 SELECT
507 WHEN skip_next == 1 THEN DO
508 line = STRIP( TRANSLATE( line ))
509 IF line == '*END' THEN skip_next = 0
510 END
511 WHEN LEFT( line, 11 ) == '*StpDefault' THEN NOP
512 WHEN LEFT( line, 7 ) == '*StpStp' THEN NOP
513 WHEN LEFT( line, 18 ) == '*StpResolutionMap:' THEN NOP
514 WHEN LEFT( line, 14 ) == '*OPOptionHints' THEN NOP
515 WHEN LEFT( line, 9 ) == '*Foomatic' THEN DO
516 line = STRIP( line )
517 IF RIGHT( line, 2 ) == '&&' THEN skip_next = 1
518 END
519 OTHERWISE DO
520 CALL LINEOUT out_ppd, line
521 skip_next = 0
522 END
523 END
524 END
525 CALL STREAM in_ppd, 'C', 'CLOSE'
526 CALL STREAM out_ppd, 'C', 'CLOSE'
527
528 ok = VRCopyFile( out_ppd, in_ppd )
529 IF logfile <> '' THEN DO
530 IF ok == 1 THEN
531 CALL LINEOUT logfile, 'OK'
532 ELSE DO
533 CALL LINEOUT logfile, 'Failed!'
534 CALL LINEOUT logfile, ' ->' VRError()
535 END
536 CALL LINEOUT logfile, ''
537 END
538 CALL SysFileDelete out_ppd
539
540RETURN
541
542/*:VRX MatchPrinterModel
543*/
544/* Find a set of printers supported by the OS/2 driver which mostly closely
545 * match the given name.
546 */
547MatchPrinterModel: PROCEDURE EXPOSE globals. models.
548 PARSE UPPER ARG driver_name, printer_name
549 printer_name = TRANSLATE( printer_name, '_', '.')
550 printer_drv = globals.!bootdrv'\OS2\DLL\'driver_name'\'driver_name'.DRV'
551 models.0 = 0
552
553 IF SysGetEA( printer_drv, '.EXPAND', 'exist_ea') <> 0 THEN RETURN 0
554 PARSE VAR exist_ea 1 _eatype 3 .
555 IF C2X( _eatype ) <> 'FDFF' THEN RETURN 0
556
557 PARSE VAR exist_ea 3 _ealen 5 exist_models
558 total_len = C2D( REVERSE( _ealen ))
559
560 /* The variable exist_models now contains a null-separated list of printer
561 * models supported by the driver (including those from previously-imported
562 * PPD files). Next we check each one against our requested printer name.
563 */
564 start = 1
565 count = 0
566 best = 0
567 DO WHILE start < total_len
568 _strend = POS('0'x, exist_models, start )
569 IF _strend == 0 THEN LEAVE
570 _model = TRANSLATE( SUBSTR( exist_models, start, _strend - start ))
571 _model = TRANSLATE( _model, ' ', '-')
572 _comp = COMPARE( _model, printer_name )
573 IF WORD( _model, 1 ) == WORD( printer_name, 1 ) THEN DO
574 count = count + 1
575 IF _comp == 0 THEN DO
576 _comp = 9999
577 best = count
578 END
579 ELSE IF ( best == 0 ) & ( _comp > LENGTH( printer_name )) THEN
580 best = count
581/*
582 models.count = RIGHT( _comp, 4, '0') SUBSTR( exist_models, start, _strend - start )
583*/
584 models.count = SUBSTR( exist_models, start, _strend - start )
585 END
586 start = _strend + 1
587 END
588 models.0 = count
589
590/*
591 CALL SysStemSort 'models.', 'D', 'I',,, 1, 4
592 DO i = 1 TO count
593 models.i = SUBWORD( models.i, 2 )
594 END
595*/
596RETURN best
597
598/*:VRX QueryAvailableDrivers
599*/
600/* Determine which of our supported PrinterPak drivers are currently available.
601 */
602QueryAvailableDrivers: PROCEDURE EXPOSE globals. drv_list.
603 drv_list.0 = 0
604
605 test_drivers = 'ECUPS ECUPS-HP PSPRINT'
606 DO i = 1 TO WORDS( test_drivers )
607 driver = WORD( test_drivers, i )
608 ok = GetDriverSource( driver )
609 IF ok == '' THEN
610 ok = VRGetIni('PM_DEVICE_DRIVERS', driver, 'USER')
611 IF ok <> '' THEN
612 CALL SysStemInsert 'drv_list.', drv_list.0+1, driver
613 END
614
615RETURN drv_list.0
616
617/*:VRX NLSGetMessage
618*/
619/*
620 * Gets the message text associated with the given message number from the
621 * current language file.
622 */
623NLSGetMessage: PROCEDURE EXPOSE globals.
624 PARSE ARG msgnum, .
625 args = ARG()
626
627 msgfile = globals.!messages
628 IF msgnum == '' THEN RETURN ''
629
630 sub_parms = ''
631 DO i = 2 TO args
632 sub_parms = sub_parms', "'ARG( i )'"'
633 END
634
635 INTERPRET 'msgfromfile = SysGetMessage( msgnum, msgfile' sub_parms ')'
636
637 PARSE VAR msgfromfile message '0D'x .
638 IF SUBSTR( message, 1, 4 ) == 'SYS0' THEN message = ''
639
640RETURN message
641
642/*:VRX NLSSetText
643*/
644/*
645 * Sets the specified property of the specified control to the specified
646 * message text.
647 */
648NLSSetText: PROCEDURE EXPOSE globals.
649 PARSE ARG control, property, message, substitution
650 args = ARG()
651
652 success = 1
653 IF args < 4 THEN
654 text = NLSGetMessage( message )
655 ELSE DO
656 sub_parms = ''
657 DO i = 4 TO args
658 sub_parms = sub_parms '"'|| ARG( i ) ||'",'
659 END
660 sub_parms = STRIP( sub_parms, 'T', ',')
661 INTERPRET 'text = NLSGetMessage( message, 'sub_parms')'
662 END
663
664 IF text == '' THEN success = 0
665 ELSE CALL VRSet control, property, text
666
667RETURN success
668
Note: See TracBrowser for help on using the repository browser.