Changeset 15


Ignore:
Timestamp:
Sep 18, 2013, 1:36:17 AM (12 years ago)
Author:
Alex Taylor
Message:

Added new RPUDeviceDelete function.
Replaced malloc() with DosAllocMem() in attempt to avoid occasional errors sometimes seen with repeated calls to RPUEnumModels.

Location:
rxprtutl/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • rxprtutl/trunk/rxprtutl.c

    r14 r15  
    6060#define SZ_LIBRARY_NAME         "RXPRTUTL"  // Name of this library
    6161#define SZ_ERROR_NAME           "RPUERROR"  // REXX variable used to store error codes
    62 #define SZ_VERSION              "0.2.2"     // Current version of this library
     62#define SZ_VERSION              "0.2.4"     // Current version of this library
    6363
    6464#define APPNAME_LEAD_STR        "PM_"
     
    123123static PSZ RxFunctionTbl[] = {
    124124    "RPUDropFuncs",
     125    "RPUDeviceDelete",
    125126    "RPUEnumModels",
    126127    "RPUEnumDrivers",
     
    149150RexxFunctionHandler RPUDropFuncs;
    150151RexxFunctionHandler RPUVersion;
     152RexxFunctionHandler RPUDeviceDelete;
    151153RexxFunctionHandler RPUEnumModels;
    152154RexxFunctionHandler RPUEnumDrivers;
     
    260262
    261263/* ------------------------------------------------------------------------- *
     264 * RPUDeviceDelete                                                           *
     265 *                                                                           *
     266 * Deletes a local print device which lacks a printer queue.  Can be useful  *
     267 * for cleaning up bad or corrupted printer definitions.                     *
     268 *                                                                           *
     269 * REXX ARGUMENTS:                                                           *
     270 *   1. The name of the print device to be deleted.               (REQUIRED) *
     271 *                                                                           *
     272 * REXX RETURN VALUE:                                                        *
     273 *   1 on success, or 0 if an error occurred.                                *
     274 * ------------------------------------------------------------------------- */
     275ULONG APIENTRY RPUDeviceDelete( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult )
     276{
     277    PSZ    pszDeviceName = NULL;
     278    SPLERR rc;
     279
     280
     281    // Reset the error indicator
     282    WriteErrorCode( 0, NULL );
     283
     284    // Validate the REXX arguments
     285    if (( argc != 1 ) || ( ! RXVALIDSTRING( argv[0] )))
     286        return ( 40 );
     287
     288    pszDeviceName = argv[0].strptr;
     289
     290    rc = SplDeleteDevice( NULL, pszDeviceName );
     291    if ( rc != NO_ERROR ) {
     292        WriteErrorCode( rc, "SplDeleteDevice");
     293        MAKERXSTRING( *prsResult, "0", 1 );
     294        return 0;
     295    }
     296
     297    MAKERXSTRING( *prsResult, "1", 1 );
     298    return ( 0 );
     299}
     300
     301
     302/* ------------------------------------------------------------------------- *
    262303 * RPUEnumModels                                                             *
    263304 *                                                                           *
     
    285326           pldt = 0L,                   // number of data types
    286327           i;
    287 
     328    APIRET rc = 0;
    288329
    289330    // Reset the error indicator
     
    318359
    319360    // Now get the actual data
     361#if 1
     362    rc = DosAllocMem( (PVOID) &aDeviceName, (ULONG) pldn * sizeof( STR32 ), PAG_WRITE | PAG_COMMIT );
     363    if ( rc != NO_ERROR ) {
     364        WriteErrorCode( rc, "DosAllocMem");
     365        MAKERXSTRING( *prsResult, "0", 1 );
     366        goto cleanup;
     367    }
     368    rc = DosAllocMem( (PVOID) &aDeviceDesc, (ULONG) pldn * sizeof( STR64 ), PAG_WRITE | PAG_COMMIT );
     369    if ( rc != NO_ERROR ) {
     370        WriteErrorCode( rc, "DosAllocMem");
     371        MAKERXSTRING( *prsResult, "0", 1 );
     372        DosFreeMem( aDeviceName );
     373        goto cleanup;
     374    }
     375    rc = DosAllocMem( (PVOID) &aDataType, (ULONG) pldt * sizeof( STR16 ), PAG_WRITE | PAG_COMMIT );
     376    if ( rc != NO_ERROR ) {
     377        WriteErrorCode( rc, "DosAllocMem");
     378        MAKERXSTRING( *prsResult, "0", 1 );
     379        DosFreeMem( aDeviceName );
     380        DosFreeMem( aDeviceDesc );
     381        goto cleanup;
     382    }
     383#else
    320384    aDeviceName = malloc( pldn * sizeof( STR32 ));
     385    if ( !aDeviceName ) {
     386        WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "malloc");
     387        MAKERXSTRING( *prsResult, "0", 1 );
     388        goto cleanup;
     389    }
    321390    aDeviceDesc = malloc( pldn * sizeof( STR64 ));
    322     aDataType   = malloc( pldt * sizeof( STR16 ));
    323     if ( !aDeviceName || !aDeviceDesc || ! aDataType ) {
     391    if ( !aDeviceDesc ) {
    324392        WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "malloc");
    325393        MAKERXSTRING( *prsResult, "0", 1 );
     394        free( aDeviceName );
    326395        goto cleanup;
    327396    }
     397    aDataType = malloc( pldt * sizeof( STR16 ));
     398    if ( !aDataType ) {
     399        WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "malloc");
     400        MAKERXSTRING( *prsResult, "0", 1 );
     401        free( aDeviceName );
     402        free( aDeviceDesc );
     403        goto cleanup;
     404    }
     405#endif
    328406    fSuccess = DevQueryDeviceNames( hab, pszDriver, &pldn, aDeviceName,
    329407                                    aDeviceDesc, &pldt, aDataType );
     
    337415    MAKERXSTRING( *prsResult, "1", 1 );
    338416
     417#if 1
     418    DosFreeMem( aDeviceName );
     419    DosFreeMem( aDeviceDesc );
     420    DosFreeMem( aDataType );
     421#else
    339422    free( aDeviceName );
    340423    free( aDeviceDesc );
    341424    free( aDataType );
     425#endif
    342426
    343427cleanup:
     
    785869 *      (stem).!driver     The name of the port driver                       *
    786870 *      (stem).!converter  The name of the protocol converter used           *
     871 *   TODO                                                                    *
     872 *      (stem).!printer    The device name of the printer(s) using this      *
     873 *                         port, if any ('' if not in use)                   *
    787874 *                                                                           *
    788875 * REXX RETURN VALUE:                                                        *
     
    14661553 * Gets information about the specified printer device.                      *
    14671554 *                                                                           *
    1468  *   (stem).i.!description  Printer description (name of WPS object)         *
    1469  *   (stem).i.!port         Name of the port the printer is using            *
    1470  *   (stem).i.!driver       List of the drivers used by this printer         *
    1471  *   (stem).i.!jobflags     Zero or more of the following flags (any order): *
     1555 *   (stem).!description  Printer description (name of WPS object)           *
     1556 *   (stem).!port         Name of the port the printer is using              *
     1557 *   (stem).!driver2      List of the drivers used by this printer           *
     1558 *   (stem).!jobflags     Zero or more of the following flags (any order):  *
    14721559 *                            E  A printer error has occurred                *
    14731560 *                            H  Printer destination is paused (held)        *
  • rxprtutl/trunk/rxprtutl.def

    r14 r15  
    11LIBRARY     RXPRTUTL INITINSTANCE TERMINSTANCE
    22DATA        MULTIPLE NONSHARED
    3 DESCRIPTION '@#Alex Taylor:0.2.2#@##1## 3 May 2013 12:46:17      REINFORCE::::::@@REXX Printer Management Utilities'
     3DESCRIPTION '@#Alex Taylor:0.2.4#@##1## 8 Sep 2013 20:30:22      REINFORCE::::::@@REXX Printer Management Utilities'
    44
    55EXPORTS     RPULoadFuncs
    66RPUDropFuncs
    77RPUVersion
     8RPUDeviceDelete
    89RPUEnumModels
    910RPUEnumDrivers
  • rxprtutl/trunk/testlib.cmd

    r13 r15  
    7474*/
    7575
     76
     77rc = RPUEnumModels(test_driver_file, 'models.')
     78IF rc == 0 THEN SAY RPUERROR
     79ELSE DO
     80    SAY models.0 'models found in driver' test_driver_file
     81DROP models.
     82
    7683CALL RPUDropFuncs
    7784RETURN 0
Note: See TracChangeset for help on using the changeset viewer.