| 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 | */
|
|---|
| 18 | GetDriverSource: 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 |
|
|---|
| 72 | RETURN 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 | */
|
|---|
| 81 | GetDriverPMDD: 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 |
|
|---|
| 94 | RETURN 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 | */
|
|---|
| 102 | VerifyDriverEAs: 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
|
|---|
| 116 | RETURN 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 | *
|
|---|
| 129 | * Returns: 1 on success, 0 on failure
|
|---|
| 130 | */
|
|---|
| 131 | CopyDriverToSource: PROCEDURE EXPOSE globals.
|
|---|
| 132 | PARSE ARG driver, newdrvdir
|
|---|
| 133 |
|
|---|
| 134 | drv_dir = VRParseFilePath( driver, 'DP')
|
|---|
| 135 | IF drv_dir == '' THEN RETURN 0
|
|---|
| 136 |
|
|---|
| 137 | IF VerifyDriverEAs( driver ) == 0 THEN RETURN 0
|
|---|
| 138 |
|
|---|
| 139 | CALL LINEOUT globals.!log1, 'Copying driver files from' drv_dir 'to' newdrvdir'...'
|
|---|
| 140 |
|
|---|
| 141 | /* Read the list of required driver files from the EAs, and copy them
|
|---|
| 142 | * all to the target directory.
|
|---|
| 143 | */
|
|---|
| 144 | IF SysGetEA( driver, 'REQUIREDDRIVERFILES', 'reqfiles') == 0 THEN DO
|
|---|
| 145 | PARSE VAR reqfiles 5 filelist
|
|---|
| 146 | filelist = TRANSLATE( filelist, ' ', ',')
|
|---|
| 147 | DO i = 1 TO WORDS( filelist )
|
|---|
| 148 | copyfile = drv_dir'\' || WORD( filelist, i )
|
|---|
| 149 | ok = VRCopyFile( copyfile, newdrvdir'\' || WORD( filelist, i ))
|
|---|
| 150 | CALL LINEOUT globals.!log1, ' -' copyfile '(REQUIRED):' ok
|
|---|
| 151 | END
|
|---|
| 152 | DROP copyfile
|
|---|
| 153 | DROP filelist
|
|---|
| 154 | END
|
|---|
| 155 | ELSE RETURN 0
|
|---|
| 156 |
|
|---|
| 157 | /* If there are optional files defined as well, try to copy those also.
|
|---|
| 158 | */
|
|---|
| 159 | IF SysGetEA( driver, 'OPTIONALDRIVERFILES', 'reqfiles') == 0 THEN DO
|
|---|
| 160 | PARSE VAR reqfiles 5 filelist
|
|---|
| 161 | filelist = TRANSLATE( filelist, ' ', ',')
|
|---|
| 162 | DO i = 1 TO WORDS( filelist )
|
|---|
| 163 | copyfile = drv_dir'\' || WORD( filelist, i )
|
|---|
| 164 | IF STREAM( copyfile, 'C', 'QUERY EXISTS') == '' THEN ITERATE
|
|---|
| 165 | ok = VRCopyFile( copyfile, newdrvdir'\' || WORD( filelist, i ))
|
|---|
| 166 | CALL LINEOUT globals.!log1, ' -' copyfile '(OPTIONAL):' ok
|
|---|
| 167 | END
|
|---|
| 168 | DROP copyfile
|
|---|
| 169 | DROP filelist
|
|---|
| 170 | END
|
|---|
| 171 |
|
|---|
| 172 | RETURN 1
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 | /*:VRX PrinterExistsInDRV
|
|---|
| 176 | */
|
|---|
| 177 | /* Determine if the specified PrinterPak driver already contains support
|
|---|
| 178 | * for the specified printer model.
|
|---|
| 179 | *
|
|---|
| 180 | * If so, return the name of the model as found in the driver (necessary in
|
|---|
| 181 | * order to make sure the correct case is retained, which may be different
|
|---|
| 182 | * from what was requested). Otherwise return ''.
|
|---|
| 183 | */
|
|---|
| 184 | PrinterExistsInDRV: PROCEDURE EXPOSE globals.
|
|---|
| 185 | PARSE UPPER ARG driver_name, printer_name
|
|---|
| 186 | printer_name = TRANSLATE( printer_name, '_', '.')
|
|---|
| 187 |
|
|---|
| 188 | printer_drv = globals.!os2dir'\DLL\'driver_name'\'driver_name'.DRV'
|
|---|
| 189 | /* ?? TODO: install driver_name if not found (prompt first) ?? */
|
|---|
| 190 |
|
|---|
| 191 | IF SysGetEA( printer_drv, '.EXPAND', 'exist_ea') <> 0 THEN RETURN ''
|
|---|
| 192 | PARSE VAR exist_ea 1 _eatype 3 .
|
|---|
| 193 | IF C2X( _eatype ) <> 'FDFF' THEN RETURN ''
|
|---|
| 194 |
|
|---|
| 195 | PARSE VAR exist_ea 3 _ealen 5 exist_models
|
|---|
| 196 | total_len = C2D( REVERSE( _ealen ))
|
|---|
| 197 |
|
|---|
| 198 | /* The variable exist_models now contains a null-separated list of printer
|
|---|
| 199 | * models supported by the driver (including those from previously-imported
|
|---|
| 200 | * PPD files). Next we check each one against our requested printer name.
|
|---|
| 201 | */
|
|---|
| 202 | start = 1
|
|---|
| 203 | found = ''
|
|---|
| 204 | DO WHILE ( found == 0 ) & ( start < total_len )
|
|---|
| 205 | _strend = POS('0'x, exist_models, start )
|
|---|
| 206 | IF _strend == 0 THEN LEAVE
|
|---|
| 207 | _model = SUBSTR( exist_models, start, _strend - start )
|
|---|
| 208 | IF TRANSLATE( _model ) == printer_name THEN
|
|---|
| 209 | found = _model
|
|---|
| 210 | ELSE
|
|---|
| 211 | start = _strend + 1
|
|---|
| 212 | END
|
|---|
| 213 |
|
|---|
| 214 | RETURN found
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 | /*:VRX CreateDriverList
|
|---|
| 218 | */
|
|---|
| 219 | /* Generate a driver listfile from the .EXPAND EA
|
|---|
| 220 | */
|
|---|
| 221 | CreateDriverList: PROCEDURE EXPOSE globals.
|
|---|
| 222 | ARG driver, listfile
|
|---|
| 223 |
|
|---|
| 224 | IF STREAM( listfile, 'C', 'QUERY EXISTS') <> '' THEN
|
|---|
| 225 | CALL SysFileDelete listfile
|
|---|
| 226 |
|
|---|
| 227 | drv_name = FILESPEC('NAME', driver )
|
|---|
| 228 | IF SysGetEA( driver, '.EXPAND', 'eaval') == 0 THEN DO
|
|---|
| 229 | PARSE VAR eaval 3 ealen 5 models
|
|---|
| 230 | offs = 1
|
|---|
| 231 | datalen = C2D( REVERSE( ealen ))
|
|---|
| 232 | DO WHILE offs <= datalen
|
|---|
| 233 | start = SUBSTR( models, offs )
|
|---|
| 234 | inc = POS('00'x, start )
|
|---|
| 235 | IF inc > 1 THEN DO
|
|---|
| 236 | current_name = STRIP( SUBSTR( start, 1, inc-1 ))
|
|---|
| 237 | CALL LINEOUT listfile, current_name':' current_name '('drv_name')'
|
|---|
| 238 | END
|
|---|
| 239 | offs = offs + inc
|
|---|
| 240 | END
|
|---|
| 241 | CALL LINEOUT listfile
|
|---|
| 242 | CALL LINEOUT globals.!log1, 'Created driver list' listfile 'for' driver'.'
|
|---|
| 243 | END
|
|---|
| 244 | ELSE
|
|---|
| 245 | CALL LINEOUT globals.!log1, 'No drivers found in' driver '(missing .EXPAND extended attribute?)'
|
|---|
| 246 |
|
|---|
| 247 | RETURN 1
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 | /*:VRX AddPort_CUPS
|
|---|
| 251 | */
|
|---|
| 252 | /* Adds a new CUPS port. Returns 0 on full success, 1 if the port was created
|
|---|
| 253 | * but could not be configured, and an OS/2 or PM error code otherwise.
|
|---|
| 254 | */
|
|---|
| 255 | AddPort_CUPS: PROCEDURE EXPOSE globals.
|
|---|
| 256 | PARSE ARG portname, hostname, queuename
|
|---|
| 257 | CALL LINEOUT globals.!log1, 'Creating new port' portname
|
|---|
| 258 | ADDRESS CMD '@cupsport' portname hostname queuename '>>' globals.!log2
|
|---|
| 259 | IF rc == 1 THEN DO
|
|---|
| 260 | CALL VRSetIni 'PM_'portname, 'INITIALIZATION', hostname'#'queuename||'00'x, 'SYSTEM', 'NoClose'
|
|---|
| 261 | CALL VRSetIni 'PM_'portname, 'DESCRIPTION', hostname':'queuename||'00'x, 'SYSTEM'
|
|---|
| 262 | END
|
|---|
| 263 | RETURN rc
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 | /*:VRX DeletePort
|
|---|
| 267 | */
|
|---|
| 268 | /* Deletes a printer port (any type).
|
|---|
| 269 | */
|
|---|
| 270 | DeletePort: PROCEDURE EXPOSE globals.
|
|---|
| 271 | PARSE ARG portname
|
|---|
| 272 | CALL SysIni 'SYSTEM', 'PM_'portname, 'DELETE:'
|
|---|
| 273 | CALL SysIni 'SYSTEM', 'PM_SPOOLER_PORT', portname, 'DELETE:'
|
|---|
| 274 | RETURN 1
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 | /*:VRX GetNextPortName
|
|---|
| 278 | */
|
|---|
| 279 | /* Get the next unique (non-existing) port name for the specified port driver.
|
|---|
| 280 | */
|
|---|
| 281 | GetNextPortName: PROCEDURE
|
|---|
| 282 | ARG portdrv
|
|---|
| 283 |
|
|---|
| 284 | maxports = 64 /* should be smarter about this if possible */
|
|---|
| 285 | exists = 1
|
|---|
| 286 | x = 0
|
|---|
| 287 | DO WHILE ( x < maxports ) & ( exists == 1 )
|
|---|
| 288 | x = x + 1
|
|---|
| 289 | portname = portdrv || x
|
|---|
| 290 | nextport = SysIni('SYSTEM', 'PM_SPOOLER_PORT', portname )
|
|---|
| 291 | IF LEFT( nextport, 6 ) == 'ERROR:' THEN exists = 0
|
|---|
| 292 | END
|
|---|
| 293 | IF exists == 1 THEN
|
|---|
| 294 | portname = ''
|
|---|
| 295 |
|
|---|
| 296 | RETURN portname
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 | /*:VRX GetQueueName
|
|---|
| 300 | */
|
|---|
| 301 | /* Generate a unique queue name from the specified printer name.
|
|---|
| 302 | */
|
|---|
| 303 | GetQueueName: PROCEDURE
|
|---|
| 304 | ARG queuename
|
|---|
| 305 |
|
|---|
| 306 | DO UNTIL badchar = 0
|
|---|
| 307 | badchar = VERIFY( queuename, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-_0123456789 ')
|
|---|
| 308 | IF badchar > 0 THEN
|
|---|
| 309 | queuename = OVERLAY(' ', queuename, badchar, 1 )
|
|---|
| 310 | END
|
|---|
| 311 | queuename = LEFT( SPACE( queuename, 0 ), 8 )
|
|---|
| 312 |
|
|---|
| 313 | tail = 0
|
|---|
| 314 | PARSE VALUE VRGetIni('PM_SPOOLER', 'DIR', 'SYSTEM') WITH spldir ';' .
|
|---|
| 315 | DO WHILE VRFileExists( spldir'\'queuename ) == 1
|
|---|
| 316 | tail = tail + 1
|
|---|
| 317 | queuename = STRIP( LEFT( queuename, 8 - LENGTH( tail ))) || tail
|
|---|
| 318 | END
|
|---|
| 319 |
|
|---|
| 320 | RETURN queuename
|
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 | /*:VRX InstallPrintDriver
|
|---|
| 324 | */
|
|---|
| 325 | /* 'Installs' (that is to say, registers with the spooler) an OS printer
|
|---|
| 326 | * device driver/model. Installs the corresponding printerpak driver if
|
|---|
| 327 | * necessary.
|
|---|
| 328 | *
|
|---|
| 329 | * driver - The name of the printerpak driver (without path or extension)
|
|---|
| 330 | * driverfull - The fully-qualified filename of the printerpak driver
|
|---|
| 331 | * model - The printer make/model name used by the driver
|
|---|
| 332 | *
|
|---|
| 333 | * Returns: 0 on success, 1 on error
|
|---|
| 334 | */
|
|---|
| 335 | InstallPrintDriver: PROCEDURE EXPOSE globals.
|
|---|
| 336 | PARSE ARG driver, driverfull, model
|
|---|
| 337 |
|
|---|
| 338 | ok = 0
|
|---|
| 339 | targetdir = globals.!os2dir'\DLL\'driver
|
|---|
| 340 | targetdrv = targetdir'\'driver'.DRV'
|
|---|
| 341 | IF ( VRFileExists( targetdrv ) == 0 ) THEN DO
|
|---|
| 342 | CALL VRMkDir targetdir
|
|---|
| 343 | r = CopyDriverToSource( driverfull, targetdir )
|
|---|
| 344 | IF r <> 1 THEN ok = 1
|
|---|
| 345 | END
|
|---|
| 346 | IF ok == 0 THEN DO
|
|---|
| 347 | IF VRGetIni('PM_DEVICE_DRIVERS', driver, 'USER') <> targetdrv THEN
|
|---|
| 348 | CALL VRSetIni 'PM_DEVICE_DRIVERS', driver, targetdrv||'00'x, 'USER'
|
|---|
| 349 | CALL VRSetIni 'PM_SPOOLER_DD', driver'.'model, driver'.DRV;;;'||'00'x, 'SYSTEM'
|
|---|
| 350 | END
|
|---|
| 351 | RETURN ok
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 | /*:VRX CreatePrinterObject
|
|---|
| 355 | */
|
|---|
| 356 | /* Create the specified printer using SysCreateObject (this should create the
|
|---|
| 357 | * queue automatically).
|
|---|
| 358 | *
|
|---|
| 359 | * Returns: 0 on success or non-zero return code on error.
|
|---|
| 360 | */
|
|---|
| 361 | CreatePrinterObject: PROCEDURE EXPOSE globals.
|
|---|
| 362 | PARSE ARG driver, model, portname, queuename, printername
|
|---|
| 363 |
|
|---|
| 364 | CALL LINEOUT globals.!log1, 'Creating new printer:' printername '('queuename')'
|
|---|
| 365 | ADDRESS CMD '@prntobj' queuename portname '"'driver'.'model'" "'printername'" >>' globals.!log2
|
|---|
| 366 | /*
|
|---|
| 367 | oid = '<WPPO_'queuename'>'
|
|---|
| 368 | setup = 'PORTNAME='portname';PRINTDRIVER='driver'.'model';QUEUENAME='queuename';TAKEDEFAULTS=YES'
|
|---|
| 369 | CALL LINEOUT globals.!log1, 'Creating printer object "'printername'" with setup string "'setup';OBJECTID='oid';"'
|
|---|
| 370 | ok = SysCreateObject('WPPrinter', printername, '<WP_DESKTOP>', setup';OBJECTID='oid';', 'F')
|
|---|
| 371 | IF ok == 1 THEN
|
|---|
| 372 | CALL SysMoveObject oid, '<WP_PRINTERSFOLDER>'
|
|---|
| 373 | ELSE DO
|
|---|
| 374 | CALL LINEOUT globals.!log1, ' - creation failed, trying again without object-ID ...'
|
|---|
| 375 | ok = SysCreateObject('WPPrinter', printername, '<WP_DESKTOP>', setup';', 'F')
|
|---|
| 376 | END
|
|---|
| 377 | IF ok == 1 THEN ok = 0
|
|---|
| 378 | ELSE DO
|
|---|
| 379 | CALL LINEOUT globals.!log1, ' - unable to create object!'
|
|---|
| 380 | ok = 1
|
|---|
| 381 | END
|
|---|
| 382 | CALL LINEOUT globals.!log1
|
|---|
| 383 | */
|
|---|
| 384 |
|
|---|
| 385 | RETURN rc
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 | /*:VRX RSPCreatePort
|
|---|
| 389 | */
|
|---|
| 390 | /* Create/update a RINSTPRN response file to create the specified port.
|
|---|
| 391 | */
|
|---|
| 392 | RSPCreatePort: PROCEDURE
|
|---|
| 393 | PARSE ARG rsp, portdriver, portname, hostname, printername
|
|---|
| 394 |
|
|---|
| 395 | CALL LINEOUT rsp, '* Creates a new printer port.'
|
|---|
| 396 | CALL LINEOUT rsp, '*'
|
|---|
| 397 | CALL LINEOUT rsp, 'ADDPORT'
|
|---|
| 398 | CALL LINEOUT rsp, ' NAME =' portname
|
|---|
| 399 | CALL LINEOUT rsp, ' PORTDRIVER =' portdriver
|
|---|
| 400 | CALL LINEOUT rsp, ' DESCRIPTION =' hostname':'printername
|
|---|
| 401 | CALL LINEOUT rsp, ' INITIALIZATION =' hostname'#'printername
|
|---|
| 402 | CALL LINEOUT rsp, ' TERMINATION = ;'
|
|---|
| 403 | CALL LINEOUT rsp, ' TIMEOUT = 45;'
|
|---|
| 404 | CALL LINEOUT rsp, 'ENDPORT'
|
|---|
| 405 | CALL LINEOUT rsp, ''
|
|---|
| 406 | CALL LINEOUT rsp
|
|---|
| 407 | RETURN 1
|
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 | /*:VRX RSPCreatePrinter
|
|---|
| 411 | */
|
|---|
| 412 | /* Create a RINSTPRN response file to create the specified printer.
|
|---|
| 413 | */
|
|---|
| 414 | RSPCreatePrinter: PROCEDURE
|
|---|
| 415 | PARSE ARG rsp, driver, model, portname, queuename, printername
|
|---|
| 416 |
|
|---|
| 417 | IF STREAM( rsp, 'C', 'QUERY EXISTS') <> '' THEN
|
|---|
| 418 | CALL SysFileDelete rsp
|
|---|
| 419 |
|
|---|
| 420 | /* This is temporary until we can implement proper options configuration */
|
|---|
| 421 | PARSE UPPER VALUE VALUE('LANG',,'OS2ENVIRONMENT') WITH 1 . 4 _ctry 6 .
|
|---|
| 422 | IF ( WORDPOS( _ctry, 'US CA MX BO CO VE PH CL') > 0 ) THEN
|
|---|
| 423 | page = 'Letter'
|
|---|
| 424 | ELSE
|
|---|
| 425 | page = 'A4'
|
|---|
| 426 | o9n = 'PORTRAIT'
|
|---|
| 427 |
|
|---|
| 428 | CALL LINEOUT rsp, '* Creates both a printer queue and a desktop object for this printer.'
|
|---|
| 429 | CALL LINEOUT rsp, '*'
|
|---|
| 430 | CALL LINEOUT rsp, 'ADDQUEUE'
|
|---|
| 431 | CALL LINEOUT rsp, ' NAME =' queuename
|
|---|
| 432 | CALL LINEOUT rsp, ' COMMENT =' printername
|
|---|
| 433 | CALL LINEOUT rsp, ' DRIVERNAME =' driver'.'model
|
|---|
| 434 | CALL LINEOUT rsp, ' PORT =' portname
|
|---|
| 435 | CALL LINEOUT rsp, ' DEFINEQUEUEPROPS'
|
|---|
| 436 | CALL LINEOUT rsp, ' FORMNAME =' page
|
|---|
| 437 | CALL LINEOUT rsp, ' ORIENTATION =' o9n
|
|---|
| 438 | CALL LINEOUT rsp, ' ENDQUEUEPROPS'
|
|---|
| 439 | CALL LINEOUT rsp, 'ENDQUEUE'
|
|---|
| 440 | CALL LINEOUT rsp, ''
|
|---|
| 441 | CALL LINEOUT rsp
|
|---|
| 442 | RETURN 1
|
|---|
| 443 |
|
|---|
| 444 |
|
|---|
| 445 | /*:VRX RSPInstallDriver
|
|---|
| 446 | */
|
|---|
| 447 | /* Create/update a RINSTPRN response file to install the specified printer
|
|---|
| 448 | * driver. (This doesn't always seem to work so we don't use it except as
|
|---|
| 449 | * a fallback.)
|
|---|
| 450 | */
|
|---|
| 451 | RSPInstallDriver: PROCEDURE
|
|---|
| 452 | PARSE ARG rsp, driver, model
|
|---|
| 453 |
|
|---|
| 454 | CALL LINEOUT rsp, '* Installs the' driver 'PrinterPak driver.'
|
|---|
| 455 | CALL LINEOUT rsp, '*'
|
|---|
| 456 | CALL LINEOUT rsp, 'ADDPRINTDRIVER'
|
|---|
| 457 | CALL LINEOUT rsp, ' NAME =' driver
|
|---|
| 458 | CALL LINEOUT rsp, 'ENDPRINTDRIVER'
|
|---|
| 459 | CALL LINEOUT rsp, ''
|
|---|
| 460 | CALL LINEOUT rsp, '* Installs support for the' model 'device.'
|
|---|
| 461 | CALL LINEOUT rsp, '*'
|
|---|
| 462 | CALL LINEOUT rsp, 'ADDPRINTDEVICE'
|
|---|
| 463 | CALL LINEOUT rsp, ' NAME =' model
|
|---|
| 464 | CALL LINEOUT rsp, ' DRIVER =' driver
|
|---|
| 465 | CALL LINEOUT rsp, 'ENDPRINTDEVICE'
|
|---|
| 466 | CALL LINEOUT rsp, ''
|
|---|
| 467 | CALL LINEOUT rsp
|
|---|
| 468 | RETURN 1
|
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 | /*:VRX GetNameFromPPD
|
|---|
| 472 | */
|
|---|
| 473 | GetNameFromPPD: PROCEDURE
|
|---|
| 474 | ARG ppd_file
|
|---|
| 475 |
|
|---|
| 476 | IF STREAM( ppd_file, 'C', 'QUERY EXISTS') == '' THEN RETURN ''
|
|---|
| 477 | nickname = ''
|
|---|
| 478 | IF VRParseFilePath( ppd_file, 'E') == 'GZ' THEN DO
|
|---|
| 479 | nq = RXQUEUE('CREATE')
|
|---|
| 480 | oq = RXQUEUE('SET', nq )
|
|---|
| 481 | ADDRESS CMD '@gzip -c -d' ppd_file '| RXQUEUE' nq
|
|---|
| 482 | DO QUEUED()
|
|---|
| 483 | PARSE PULL line
|
|---|
| 484 | line = STRIP( line )
|
|---|
| 485 | IF LEFT( line, 15 ) == '*ShortNickName:' THEN DO
|
|---|
| 486 | PARSE VAR line . ':' _nick '0D'x .
|
|---|
| 487 | nickname = STRIP( _nick )
|
|---|
| 488 | nickname = STRIP( nickname, 'B', '09'x )
|
|---|
| 489 | nickname = STRIP( nickname, 'B', '"')
|
|---|
| 490 | LEAVE
|
|---|
| 491 | END
|
|---|
| 492 | END
|
|---|
| 493 | CALL RXQUEUE 'SET', oq
|
|---|
| 494 | CALL RXQUEUE 'DELETE', nq
|
|---|
| 495 | END
|
|---|
| 496 | ELSE DO
|
|---|
| 497 | CALL LINEIN ppd_file, 1, 0
|
|---|
| 498 | DO WHILE LINES( ppd_file ) <> 0
|
|---|
| 499 | line = STRIP( LINEIN( ppd_file ))
|
|---|
| 500 | IF LEFT( line, 15 ) == '*ShortNickName:' THEN DO
|
|---|
| 501 | PARSE VAR line . ':' _nick '0D'x .
|
|---|
| 502 | nickname = STRIP( _nick )
|
|---|
| 503 | nickname = STRIP( nickname, 'B', '09'x )
|
|---|
| 504 | nickname = STRIP( nickname, 'B', '"')
|
|---|
| 505 | LEAVE
|
|---|
| 506 | END
|
|---|
| 507 | END
|
|---|
| 508 | CALL STREAM ppd_file, 'C', 'CLOSE'
|
|---|
| 509 | END
|
|---|
| 510 | nickname = TRANSLATE( nickname, ' ', '"')
|
|---|
| 511 | nickname = TRANSLATE( nickname, ' ', "'")
|
|---|
| 512 |
|
|---|
| 513 | RETURN nickname
|
|---|
| 514 |
|
|---|
| 515 | /*:VRX CleanPPD
|
|---|
| 516 | */
|
|---|
| 517 | /* Clean out lines from Gutenprint and Foomatic PPD files that are known to
|
|---|
| 518 | * cause problems when importing with PIN. (Partially based on work by Paul
|
|---|
| 519 | * Smedley and Peter Brown).
|
|---|
| 520 | */
|
|---|
| 521 | CleanPPD: PROCEDURE
|
|---|
| 522 | PARSE ARG in_ppd, logfile
|
|---|
| 523 | IF logfile <> '' THEN
|
|---|
| 524 | logfile = STREAM( logfile, 'C', 'QUERY EXISTS')
|
|---|
| 525 |
|
|---|
| 526 | out_ppd = VRParseFilePath( in_ppd, 'DPN') || '.TMP'
|
|---|
| 527 | IF STREAM( out_ppd, 'C', 'QUERY EXISTS') \= '' THEN
|
|---|
| 528 | CALL SysFileDelete out_ppd
|
|---|
| 529 |
|
|---|
| 530 | IF logfile <> '' THEN
|
|---|
| 531 | CALL CHAROUT logfile, 'Doing cleanup on' in_ppd '...'
|
|---|
| 532 |
|
|---|
| 533 | skip_next = 0
|
|---|
| 534 | DO WHILE LINES( in_ppd ) \= 0
|
|---|
| 535 | line = LINEIN( in_ppd )
|
|---|
| 536 | SELECT
|
|---|
| 537 | WHEN skip_next == 1 THEN DO
|
|---|
| 538 | line = STRIP( TRANSLATE( line ))
|
|---|
| 539 | IF line == '*END' THEN skip_next = 0
|
|---|
| 540 | END
|
|---|
| 541 | WHEN LEFT( line, 11 ) == '*StpDefault' THEN NOP
|
|---|
| 542 | WHEN LEFT( line, 7 ) == '*StpStp' THEN NOP
|
|---|
| 543 | WHEN LEFT( line, 18 ) == '*StpResolutionMap:' THEN NOP
|
|---|
| 544 | WHEN LEFT( line, 14 ) == '*OPOptionHints' THEN NOP
|
|---|
| 545 | WHEN LEFT( line, 4 ) == '*da.' THEN NOP
|
|---|
| 546 | WHEN LEFT( line, 4 ) == '*de.' THEN NOP
|
|---|
| 547 | WHEN LEFT( line, 4 ) == '*es.' THEN NOP
|
|---|
| 548 | WHEN LEFT( line, 4 ) == '*fi.' THEN NOP
|
|---|
| 549 | WHEN LEFT( line, 4 ) == '*fr.' THEN NOP
|
|---|
| 550 | WHEN LEFT( line, 4 ) == '*it.' THEN NOP
|
|---|
| 551 | WHEN LEFT( line, 4 ) == '*ja.' THEN NOP
|
|---|
| 552 | WHEN LEFT( line, 4 ) == '*ko.' THEN NOP
|
|---|
| 553 | WHEN LEFT( line, 4 ) == '*nb.' THEN NOP
|
|---|
| 554 | WHEN LEFT( line, 4 ) == '*nl.' THEN NOP
|
|---|
| 555 | WHEN LEFT( line, 4 ) == '*pt.' THEN NOP
|
|---|
| 556 | WHEN LEFT( line, 4 ) == '*sv.' THEN NOP
|
|---|
| 557 | WHEN LEFT( line, 7 ) == '*zh_CN.' THEN NOP
|
|---|
| 558 | WHEN LEFT( line, 7 ) == '*zh_TW.' THEN NOP
|
|---|
| 559 | WHEN LEFT( line, 9 ) == '*Foomatic' THEN DO
|
|---|
| 560 | line = STRIP( line )
|
|---|
| 561 | IF RIGHT( line, 2 ) == '&&' THEN skip_next = 1
|
|---|
| 562 | END
|
|---|
| 563 | OTHERWISE DO
|
|---|
| 564 | CALL LINEOUT out_ppd, line
|
|---|
| 565 | skip_next = 0
|
|---|
| 566 | END
|
|---|
| 567 | END
|
|---|
| 568 | END
|
|---|
| 569 | CALL STREAM in_ppd, 'C', 'CLOSE'
|
|---|
| 570 | CALL STREAM out_ppd, 'C', 'CLOSE'
|
|---|
| 571 |
|
|---|
| 572 | ok = VRCopyFile( out_ppd, in_ppd )
|
|---|
| 573 | IF logfile <> '' THEN DO
|
|---|
| 574 | IF ok == 1 THEN
|
|---|
| 575 | CALL LINEOUT logfile, 'OK'
|
|---|
| 576 | ELSE DO
|
|---|
| 577 | CALL LINEOUT logfile, 'Failed!'
|
|---|
| 578 | CALL LINEOUT logfile, ' ->' VRError()
|
|---|
| 579 | END
|
|---|
| 580 | CALL LINEOUT logfile, ''
|
|---|
| 581 | END
|
|---|
| 582 | CALL SysFileDelete out_ppd
|
|---|
| 583 |
|
|---|
| 584 | RETURN
|
|---|
| 585 |
|
|---|
| 586 | /*:VRX MatchPrinterModel
|
|---|
| 587 | */
|
|---|
| 588 | /* Find a set of printers supported by the OS/2 driver which mostly closely
|
|---|
| 589 | * match the given name.
|
|---|
| 590 | */
|
|---|
| 591 | MatchPrinterModel: PROCEDURE EXPOSE globals. models.
|
|---|
| 592 | PARSE UPPER ARG driver_name, printer_name
|
|---|
| 593 | printer_name = TRANSLATE( printer_name, '_', '.')
|
|---|
| 594 | printer_drv = globals.!os2dir'\DLL\'driver_name'\'driver_name'.DRV'
|
|---|
| 595 | models.0 = 0
|
|---|
| 596 |
|
|---|
| 597 | IF SysGetEA( printer_drv, '.EXPAND', 'exist_ea') <> 0 THEN RETURN 0
|
|---|
| 598 | PARSE VAR exist_ea 1 _eatype 3 .
|
|---|
| 599 | IF C2X( _eatype ) <> 'FDFF' THEN RETURN 0
|
|---|
| 600 |
|
|---|
| 601 | PARSE VAR exist_ea 3 _ealen 5 exist_models
|
|---|
| 602 | total_len = C2D( REVERSE( _ealen ))
|
|---|
| 603 |
|
|---|
| 604 | /* The variable exist_models now contains a null-separated list of printer
|
|---|
| 605 | * models supported by the driver (including those from previously-imported
|
|---|
| 606 | * PPD files). Next we check each one against our requested printer name.
|
|---|
| 607 | */
|
|---|
| 608 | start = 1
|
|---|
| 609 | count = 0
|
|---|
| 610 | best = 0
|
|---|
| 611 | DO WHILE start < total_len
|
|---|
| 612 | _strend = POS('0'x, exist_models, start )
|
|---|
| 613 | IF _strend == 0 THEN LEAVE
|
|---|
| 614 | _model = TRANSLATE( SUBSTR( exist_models, start, _strend - start ))
|
|---|
| 615 | _model = TRANSLATE( _model, ' ', '-')
|
|---|
| 616 | _comp = COMPARE( _model, printer_name )
|
|---|
| 617 | IF WORD( _model, 1 ) == WORD( printer_name, 1 ) THEN DO
|
|---|
| 618 | count = count + 1
|
|---|
| 619 | IF _comp == 0 THEN DO
|
|---|
| 620 | _comp = 9999
|
|---|
| 621 | best = count
|
|---|
| 622 | END
|
|---|
| 623 | ELSE IF ( best == 0 ) & ( _comp > LENGTH( printer_name )) THEN
|
|---|
| 624 | best = count
|
|---|
| 625 | /*
|
|---|
| 626 | models.count = RIGHT( _comp, 4, '0') SUBSTR( exist_models, start, _strend - start )
|
|---|
| 627 | */
|
|---|
| 628 | models.count = SUBSTR( exist_models, start, _strend - start )
|
|---|
| 629 | END
|
|---|
| 630 | start = _strend + 1
|
|---|
| 631 | END
|
|---|
| 632 | models.0 = count
|
|---|
| 633 |
|
|---|
| 634 | /*
|
|---|
| 635 | CALL SysStemSort 'models.', 'D', 'I',,, 1, 4
|
|---|
| 636 | DO i = 1 TO count
|
|---|
| 637 | models.i = SUBWORD( models.i, 2 )
|
|---|
| 638 | END
|
|---|
| 639 | */
|
|---|
| 640 | RETURN best
|
|---|
| 641 |
|
|---|
| 642 | /*:VRX QueryAvailableDrivers
|
|---|
| 643 | */
|
|---|
| 644 | /* Determine which of our supported PrinterPak drivers are currently available.
|
|---|
| 645 | */
|
|---|
| 646 | QueryAvailableDrivers: PROCEDURE EXPOSE globals. drv_list.
|
|---|
| 647 | drv_list.0 = 0
|
|---|
| 648 |
|
|---|
| 649 | test_drivers = 'ECUPS ECUPS-HP PSPRINT'
|
|---|
| 650 | DO i = 1 TO WORDS( test_drivers )
|
|---|
| 651 | driver = WORD( test_drivers, i )
|
|---|
| 652 | ok = GetDriverSource( driver )
|
|---|
| 653 | IF ok == '' THEN
|
|---|
| 654 | ok = VRGetIni('PM_DEVICE_DRIVERS', driver, 'USER')
|
|---|
| 655 | IF ok <> '' THEN
|
|---|
| 656 | CALL SysStemInsert 'drv_list.', drv_list.0+1, driver
|
|---|
| 657 | END
|
|---|
| 658 |
|
|---|
| 659 | RETURN drv_list.0
|
|---|
| 660 |
|
|---|
| 661 | /*:VRX NLSGetMessage
|
|---|
| 662 | */
|
|---|
| 663 | /*
|
|---|
| 664 | * Gets the message text associated with the given message number from the
|
|---|
| 665 | * current language file.
|
|---|
| 666 | */
|
|---|
| 667 | NLSGetMessage: PROCEDURE EXPOSE globals.
|
|---|
| 668 | PARSE ARG msgnum, .
|
|---|
| 669 | args = ARG()
|
|---|
| 670 |
|
|---|
| 671 | msgfile = globals.!messages
|
|---|
| 672 | IF msgnum == '' THEN RETURN ''
|
|---|
| 673 |
|
|---|
| 674 | sub_parms = ''
|
|---|
| 675 | DO i = 2 TO args
|
|---|
| 676 | sub_parms = sub_parms', "'ARG( i )'"'
|
|---|
| 677 | END
|
|---|
| 678 |
|
|---|
| 679 | INTERPRET 'msgfromfile = SysGetMessage( msgnum, msgfile' sub_parms ')'
|
|---|
| 680 |
|
|---|
| 681 | PARSE VAR msgfromfile message '0D'x .
|
|---|
| 682 | IF SUBSTR( message, 1, 4 ) == 'SYS0' THEN message = ''
|
|---|
| 683 |
|
|---|
| 684 | RETURN message
|
|---|
| 685 |
|
|---|
| 686 | /*:VRX NLSSetText
|
|---|
| 687 | */
|
|---|
| 688 | /*
|
|---|
| 689 | * Sets the specified property of the specified control to the specified
|
|---|
| 690 | * message text.
|
|---|
| 691 | */
|
|---|
| 692 | NLSSetText: PROCEDURE EXPOSE globals.
|
|---|
| 693 | PARSE ARG control, property, message, substitution
|
|---|
| 694 | args = ARG()
|
|---|
| 695 |
|
|---|
| 696 | success = 1
|
|---|
| 697 | IF args < 4 THEN
|
|---|
| 698 | text = NLSGetMessage( message )
|
|---|
| 699 | ELSE DO
|
|---|
| 700 | sub_parms = ''
|
|---|
| 701 | DO i = 4 TO args
|
|---|
| 702 | sub_parms = sub_parms '"'|| ARG( i ) ||'",'
|
|---|
| 703 | END
|
|---|
| 704 | sub_parms = STRIP( sub_parms, 'T', ',')
|
|---|
| 705 | INTERPRET 'text = NLSGetMessage( message, 'sub_parms')'
|
|---|
| 706 | END
|
|---|
| 707 |
|
|---|
| 708 | IF text == '' THEN success = 0
|
|---|
| 709 | ELSE CALL VRSet control, property, text
|
|---|
| 710 |
|
|---|
| 711 | RETURN success
|
|---|
| 712 |
|
|---|