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

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

Fixed some minor errors in updating presentation drivers (printerpaks).

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