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

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

Add NLS support 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 targetdir = globals.!os2dir'\DLL\'driver
331 IF ( VRFileExists( targetdir'\'driver'.DRV') == 0 ) THEN DO
332 CALL VRMkDir targetdir
333 rc = CopyDriverToSource( driverfull, targetdir )
334 END
335 IF VRGetIni('PM_DEVICE_DRIVERS', driver, 'USER', 'NoClose') <> driverfull THEN
336 CALL VRSetIni 'PM_DEVICE_DRIVERS', driver, driverfull||'00'x, 'USER'
337 CALL VRSetIni 'PM_SPOOLER_DD', driver'.'model, driver'.DRV;;;'||'00'x, 'SYSTEM'
338RETURN rc
339
340
341/*:VRX CreatePrinterObject
342*/
343/* Create the specified printer using SysCreateObject (this should create the
344 * queue automatically).
345 */
346CreatePrinterObject: PROCEDURE
347 PARSE ARG driver, model, portname, queuename, printername
348
349 oid = '<WPPO_'queuename'>'
350 setup = 'PORTNAME='portname';PRINTDRIVER='driver'.'model';QUEUENAME='queuename';TAKEDEFAULTS=YES'
351
352 rc = SysCreateObject('WPPrinter', printername, '<WP_DESKTOP>', setup';OBJECTID='oid';', 'F')
353 IF rc == 1 THEN
354 CALL SysMoveObject oid, '<WP_PRINTERSFOLDER>'
355 ELSE
356 rc = SysCreateObject('WPPrinter', printername, '<WP_DESKTOP>', setup';', 'F')
357
358RETURN rc
359
360
361/*:VRX RSPCreatePort
362*/
363/* Create/update a RINSTPRN response file to create the specified port.
364 */
365RSPCreatePort: PROCEDURE
366 PARSE ARG rsp, portdriver, portname, hostname, printername
367
368 CALL LINEOUT rsp, '* Creates a new printer port.'
369 CALL LINEOUT rsp, '*'
370 CALL LINEOUT rsp, 'ADDPORT'
371 CALL LINEOUT rsp, ' NAME =' portname
372 CALL LINEOUT rsp, ' PORTDRIVER =' portdriver
373 CALL LINEOUT rsp, ' DESCRIPTION =' hostname':'printername
374 CALL LINEOUT rsp, ' INITIALIZATION =' hostname'#'printername
375 CALL LINEOUT rsp, ' TERMINATION = ;'
376 CALL LINEOUT rsp, ' TIMEOUT = 45;'
377 CALL LINEOUT rsp, 'ENDPORT'
378 CALL LINEOUT rsp, ''
379 CALL LINEOUT rsp
380RETURN 1
381
382
383/*:VRX RSPCreatePrinter
384*/
385/* Create a RINSTPRN response file to create the specified printer.
386 */
387RSPCreatePrinter: PROCEDURE
388 PARSE ARG rsp, driver, model, portname, queuename, printername
389
390 IF STREAM( rsp, 'C', 'QUERY EXISTS') <> '' THEN
391 CALL SysFileDelete rsp
392
393 /* This is temporary until we can implement proper options configuration */
394 PARSE UPPER VALUE VALUE('LANG',,'OS2ENVIRONMENT') WITH 1 . 4 _ctry 6 .
395 IF ( WORDPOS( _ctry, 'US CA MX BO CO VE PH CL') > 0 ) THEN
396 page = 'Letter'
397 ELSE
398 page = 'A4'
399 o9n = 'PORTRAIT'
400
401 CALL LINEOUT rsp, '* Creates both a printer queue and a desktop object for this printer.'
402 CALL LINEOUT rsp, '*'
403 CALL LINEOUT rsp, 'ADDQUEUE'
404 CALL LINEOUT rsp, ' NAME =' queuename
405 CALL LINEOUT rsp, ' COMMENT =' printername
406 CALL LINEOUT rsp, ' DRIVERNAME =' driver'.'model
407 CALL LINEOUT rsp, ' PORT =' portname
408 CALL LINEOUT rsp, ' DEFINEQUEUEPROPS'
409 CALL LINEOUT rsp, ' FORMNAME =' page
410 CALL LINEOUT rsp, ' ORIENTATION =' o9n
411 CALL LINEOUT rsp, ' ENDQUEUEPROPS'
412 CALL LINEOUT rsp, 'ENDQUEUE'
413 CALL LINEOUT rsp, ''
414 CALL LINEOUT rsp
415RETURN 1
416
417
418/*:VRX RSPInstallDriver
419*/
420/* Create/update a RINSTPRN response file to install the specified printer
421 * driver. (This doesn't always seem to work so we don't use it except as
422 * a fallback.)
423 */
424RSPInstallDriver: PROCEDURE
425 PARSE ARG rsp, driver, model
426
427 CALL LINEOUT rsp, '* Installs the' driver 'PrinterPak driver.'
428 CALL LINEOUT rsp, '*'
429 CALL LINEOUT rsp, 'ADDPRINTDRIVER'
430 CALL LINEOUT rsp, ' NAME =' driver
431 CALL LINEOUT rsp, 'ENDPRINTDRIVER'
432 CALL LINEOUT rsp, ''
433 CALL LINEOUT rsp, '* Installs support for the' model 'device.'
434 CALL LINEOUT rsp, '*'
435 CALL LINEOUT rsp, 'ADDPRINTDEVICE'
436 CALL LINEOUT rsp, ' NAME =' model
437 CALL LINEOUT rsp, ' DRIVER =' driver
438 CALL LINEOUT rsp, 'ENDPRINTDEVICE'
439 CALL LINEOUT rsp, ''
440 CALL LINEOUT rsp
441RETURN 1
442
443
444/*:VRX GetNameFromPPD
445*/
446GetNameFromPPD: PROCEDURE
447 ARG ppd_file
448
449 IF STREAM( ppd_file, 'C', 'QUERY EXISTS') == '' THEN RETURN ''
450 nickname = ''
451 IF VRParseFilePath( ppd_file, 'E') == 'GZ' THEN DO
452 nq = RXQUEUE('CREATE')
453 oq = RXQUEUE('SET', nq )
454 ADDRESS CMD '@gzip -c -d' ppd_file '| RXQUEUE' nq
455 DO QUEUED()
456 PARSE PULL line
457 line = STRIP( line )
458 IF LEFT( line, 15 ) == '*ShortNickName:' THEN DO
459 PARSE VAR line . ':' _nick '0D'x .
460 nickname = STRIP( _nick )
461 nickname = STRIP( nickname, 'B', '"')
462 LEAVE
463 END
464 END
465 CALL RXQUEUE 'SET', oq
466 CALL RXQUEUE 'DELETE', nq
467 END
468 ELSE DO
469 CALL LINEIN ppd_file, 1, 0
470 DO WHILE LINES( ppd_file ) <> 0
471 line = STRIP( LINEIN( ppd_file ))
472 IF LEFT( line, 15 ) == '*ShortNickName:' THEN DO
473 PARSE VAR line . ':' _nick '0D'x .
474 nickname = STRIP( _nick )
475 nickname = STRIP( nickname, 'B', '"')
476 LEAVE
477 END
478 END
479 CALL STREAM ppd_file, 'C', 'CLOSE'
480 END
481
482RETURN nickname
483
484/*:VRX CleanPPD
485*/
486/* Clean out lines from Gutenprint and Foomatic PPD files that are known to
487 * cause problems when importing with PIN. (Partially based on work by Paul
488 * Smedley and Peter Brown).
489 */
490CleanPPD: PROCEDURE
491 PARSE ARG in_ppd, logfile
492 IF logfile <> '' THEN
493 logfile = STREAM( logfile, 'C', 'QUERY EXISTS')
494
495 out_ppd = VRParseFilePath( in_ppd, 'DPN') || '.TMP'
496 IF STREAM( out_ppd, 'C', 'QUERY EXISTS') \= '' THEN
497 CALL SysFileDelete out_ppd
498
499 IF logfile <> '' THEN
500 CALL CHAROUT logfile, 'Doing cleanup on' in_ppd '...'
501
502 skip_next = 0
503 DO WHILE LINES( in_ppd ) \= 0
504 line = LINEIN( in_ppd )
505 SELECT
506 WHEN skip_next == 1 THEN DO
507 line = STRIP( TRANSLATE( line ))
508 IF line == '*END' THEN skip_next = 0
509 END
510 WHEN LEFT( line, 11 ) == '*StpDefault' THEN NOP
511 WHEN LEFT( line, 7 ) == '*StpStp' THEN NOP
512 WHEN LEFT( line, 18 ) == '*StpResolutionMap:' THEN NOP
513 WHEN LEFT( line, 14 ) == '*OPOptionHints' THEN NOP
514 WHEN LEFT( line, 9 ) == '*Foomatic' THEN DO
515 line = STRIP( line )
516 IF RIGHT( line, 2 ) == '&&' THEN skip_next = 1
517 END
518 OTHERWISE DO
519 CALL LINEOUT out_ppd, line
520 skip_next = 0
521 END
522 END
523 END
524 CALL STREAM in_ppd, 'C', 'CLOSE'
525 CALL STREAM out_ppd, 'C', 'CLOSE'
526
527 ok = VRCopyFile( out_ppd, in_ppd )
528 IF logfile <> '' THEN DO
529 IF ok == 1 THEN
530 CALL LINEOUT logfile, 'OK'
531 ELSE DO
532 CALL LINEOUT logfile, 'Failed!'
533 CALL LINEOUT logfile, ' ->' VRError()
534 END
535 CALL LINEOUT logfile, ''
536 END
537 CALL SysFileDelete out_ppd
538
539RETURN
540
541/*:VRX MatchPrinterModel
542*/
543/* Find a set of printers supported by the OS/2 driver which mostly closely
544 * match the given name.
545 */
546MatchPrinterModel: PROCEDURE EXPOSE globals. models.
547 PARSE UPPER ARG driver_name, printer_name
548 printer_name = TRANSLATE( printer_name, '_', '.')
549 printer_drv = globals.!bootdrv'\OS2\DLL\'driver_name'\'driver_name'.DRV'
550 models.0 = 0
551
552 IF SysGetEA( printer_drv, '.EXPAND', 'exist_ea') <> 0 THEN RETURN 0
553 PARSE VAR exist_ea 1 _eatype 3 .
554 IF C2X( _eatype ) <> 'FDFF' THEN RETURN 0
555
556 PARSE VAR exist_ea 3 _ealen 5 exist_models
557 total_len = C2D( REVERSE( _ealen ))
558
559 /* The variable exist_models now contains a null-separated list of printer
560 * models supported by the driver (including those from previously-imported
561 * PPD files). Next we check each one against our requested printer name.
562 */
563 start = 1
564 count = 0
565 best = 0
566 DO WHILE start < total_len
567 _strend = POS('0'x, exist_models, start )
568 IF _strend == 0 THEN LEAVE
569 _model = TRANSLATE( SUBSTR( exist_models, start, _strend - start ))
570 _model = TRANSLATE( _model, ' ', '-')
571 _comp = COMPARE( _model, printer_name )
572 IF WORD( _model, 1 ) == WORD( printer_name, 1 ) THEN DO
573 count = count + 1
574 IF _comp == 0 THEN DO
575 _comp = 9999
576 best = count
577 END
578 ELSE IF ( best == 0 ) & ( _comp > LENGTH( printer_name )) THEN
579 best = count
580/*
581 models.count = RIGHT( _comp, 4, '0') SUBSTR( exist_models, start, _strend - start )
582*/
583 models.count = SUBSTR( exist_models, start, _strend - start )
584 END
585 start = _strend + 1
586 END
587 models.0 = count
588
589/*
590 CALL SysStemSort 'models.', 'D', 'I',,, 1, 4
591 DO i = 1 TO count
592 models.i = SUBWORD( models.i, 2 )
593 END
594*/
595RETURN best
596
597/*:VRX QueryAvailableDrivers
598*/
599/* Determine which of our supported PrinterPak drivers are currently available.
600 */
601QueryAvailableDrivers: PROCEDURE EXPOSE globals. drv_list.
602 drv_list.0 = 0
603
604 test_drivers = 'ECUPS ECUPS-HP PSPRINT'
605 DO i = 1 TO WORDS( test_drivers )
606 driver = WORD( test_drivers, i )
607 ok = GetDriverSource( driver )
608 IF ok == '' THEN
609 ok = VRGetIni('PM_DEVICE_DRIVERS', driver, 'USER')
610 IF ok <> '' THEN
611 CALL SysStemInsert 'drv_list.', drv_list.0+1, driver
612 END
613
614RETURN drv_list.0
615
616/*:VRX NLSGetMessage
617*/
618/*
619 * Gets the message text associated with the given message number from the
620 * current language file.
621 */
622NLSGetMessage: PROCEDURE EXPOSE globals.
623 PARSE ARG msgnum, .
624 args = ARG()
625
626 msgfile = globals.!messages
627 IF msgnum == '' THEN RETURN ''
628
629 sub_parms = ''
630 DO i = 2 TO args
631 sub_parms = sub_parms', "'ARG( i )'"'
632 END
633
634 INTERPRET 'msgfromfile = SysGetMessage( msgnum, msgfile' sub_parms ')'
635
636 PARSE VAR msgfromfile message '0D'x .
637 IF SUBSTR( message, 1, 4 ) == 'SYS0' THEN message = ''
638
639RETURN message
640
641/*:VRX NLSSetText
642*/
643/*
644 * Sets the specified property of the specified control to the specified
645 * message text.
646 */
647NLSSetText: PROCEDURE EXPOSE globals.
648 PARSE ARG control, property, message, substitution
649 args = ARG()
650
651 success = 1
652 IF args < 4 THEN
653 text = NLSGetMessage( message )
654 ELSE DO
655 sub_parms = ''
656 DO i = 4 TO args
657 sub_parms = sub_parms '"'|| ARG( i ) ||'",'
658 END
659 sub_parms = STRIP( sub_parms, 'T', ',')
660 INTERPRET 'text = NLSGetMessage( message, 'sub_parms')'
661 END
662
663 IF text == '' THEN success = 0
664 ELSE CALL VRSet control, property, text
665
666RETURN success
667
Note: See TracBrowser for help on using the repository browser.