source: trunk/gui/shared/PrintUtl.VRS

Last change on this file was 97, checked in by Alex Taylor, 3 years ago

Various updates and refactoring of font scaling logic; documentation and WIS updates.

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