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

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

Fix bug in return code processing when creating OS/2 printer.

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