Changeset 126


Ignore:
Timestamp:
Dec 22, 2001, 12:10:30 PM (24 years ago)
Author:
umoeller
Message:

Misc fixes.

Location:
trunk/src/helpers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/dosh.c

    r123 r126  
    334334
    335335    *pcbAllocated = c * cbArrayItem;
    336     if (!(*ppv = malloc(*pcbAllocated)))
     336    if (!(*ppv = (PBYTE)malloc(*pcbAllocated)))
    337337        return ERROR_NOT_ENOUGH_MEMORY;
    338338
     
    17791779 *
    17801780 *@@added V0.9.16 (2001-10-19) [umoeller]
     1781 *@@changed V0.9.16 (2001-12-18) [umoeller]: fixed error codes
    17811782 */
    17821783
     
    17891790    APIRET arc = NO_ERROR;
    17901791
    1791     // run this first, because if the file doesn't
    1792     // exists, DosOpen only returns ERROR_OPEN_FAILED,
    1793     // which isn't that meaningful
    1794     // V0.9.16 (2001-12-08) [umoeller]
    1795     if (!(arc = doshQueryPathSize(pcszFilename,
    1796                                   pcbFile)))
    1797     {
    1798         ULONG   fsOpenFlags = 0,
    1799                 fsOpenMode =    OPEN_FLAGS_FAIL_ON_ERROR
    1800                               | OPEN_FLAGS_NO_LOCALITY
    1801                               | OPEN_FLAGS_NOINHERIT;
    1802 
    1803         switch (flOpenMode & XOPEN_ACCESS_MASK)
     1792    ULONG   fsOpenFlags = 0,
     1793            fsOpenMode =    OPEN_FLAGS_FAIL_ON_ERROR
     1794                          | OPEN_FLAGS_NO_LOCALITY
     1795                          | OPEN_FLAGS_NOINHERIT;
     1796
     1797    switch (flOpenMode & XOPEN_ACCESS_MASK)
     1798    {
     1799        case XOPEN_READ_EXISTING:
     1800            fsOpenFlags =   OPEN_ACTION_FAIL_IF_NEW
     1801                          | OPEN_ACTION_OPEN_IF_EXISTS;
     1802            fsOpenMode |=   OPEN_SHARE_DENYWRITE
     1803                          | OPEN_ACCESS_READONLY;
     1804            // _Pmpf((__FUNCTION__ ": opening XOPEN_READ_EXISTING"));
     1805
     1806            // run this first, because if the file doesn't
     1807            // exists, DosOpen only returns ERROR_OPEN_FAILED,
     1808            // which isn't that meaningful
     1809            // V0.9.16 (2001-12-08) [umoeller]
     1810            arc = doshQueryPathSize(pcszFilename,
     1811                                    pcbFile);
     1812        break;
     1813
     1814        case XOPEN_READWRITE_APPEND:
     1815            fsOpenFlags =   OPEN_ACTION_CREATE_IF_NEW
     1816                          | OPEN_ACTION_OPEN_IF_EXISTS;
     1817            fsOpenMode |=   OPEN_SHARE_DENYREADWRITE
     1818                          | OPEN_ACCESS_READWRITE;
     1819            // _Pmpf((__FUNCTION__ ": opening XOPEN_READWRITE_APPEND"));
     1820        break;
     1821
     1822        case XOPEN_READWRITE_NEW:
     1823            fsOpenFlags =   OPEN_ACTION_CREATE_IF_NEW
     1824                          | OPEN_ACTION_REPLACE_IF_EXISTS;
     1825            fsOpenMode |=   OPEN_SHARE_DENYREADWRITE
     1826                          | OPEN_ACCESS_READWRITE;
     1827            // _Pmpf((__FUNCTION__ ": opening XOPEN_READWRITE_NEW"));
     1828        break;
     1829    }
     1830
     1831    if ((!arc) && fsOpenFlags && pcbFile && ppFile)
     1832    {
     1833        PXFILE pFile;
     1834        if (pFile = NEW(XFILE))
    18041835        {
    1805             case XOPEN_READ_EXISTING:
    1806                 fsOpenFlags =   OPEN_ACTION_FAIL_IF_NEW
    1807                               | OPEN_ACTION_OPEN_IF_EXISTS;
    1808                 fsOpenMode |=   OPEN_SHARE_DENYWRITE
    1809                               | OPEN_ACCESS_READONLY;
    1810                 // _Pmpf((__FUNCTION__ ": opening XOPEN_READ_EXISTING"));
    1811             break;
    1812 
    1813             case XOPEN_READWRITE_APPEND:
    1814                 fsOpenFlags =   OPEN_ACTION_CREATE_IF_NEW
    1815                               | OPEN_ACTION_OPEN_IF_EXISTS;
    1816                 fsOpenMode |=   OPEN_SHARE_DENYREADWRITE
    1817                               | OPEN_ACCESS_READWRITE;
    1818                 // _Pmpf((__FUNCTION__ ": opening XOPEN_READWRITE_APPEND"));
    1819             break;
    1820 
    1821             case XOPEN_READWRITE_NEW:
    1822                 fsOpenFlags =   OPEN_ACTION_CREATE_IF_NEW
    1823                               | OPEN_ACTION_REPLACE_IF_EXISTS;
    1824                 fsOpenMode |=   OPEN_SHARE_DENYREADWRITE
    1825                               | OPEN_ACCESS_READWRITE;
    1826                 // _Pmpf((__FUNCTION__ ": opening XOPEN_READWRITE_NEW"));
    1827             break;
    1828         }
    1829 
    1830         if ((!arc) && fsOpenFlags && pcbFile && ppFile)
    1831         {
    1832             PXFILE pFile;
    1833             if (pFile = NEW(XFILE))
     1836            ULONG ulAction;
     1837
     1838            ZERO(pFile);
     1839
     1840            // copy open flags
     1841            pFile->flOpenMode = flOpenMode;
     1842
     1843            if (!(arc = DosOpen((PSZ)pcszFilename,
     1844                                &pFile->hf,
     1845                                &ulAction,
     1846                                *pcbFile,
     1847                                FILE_ARCHIVED,
     1848                                fsOpenFlags,
     1849                                fsOpenMode,
     1850                                NULL)))       // EAs
    18341851            {
    1835                 ULONG ulAction;
    1836 
    1837                 ZERO(pFile);
    1838 
    1839                 // copy open flags
    1840                 pFile->flOpenMode = flOpenMode;
    1841 
    1842                 if (!(arc = DosOpen((PSZ)pcszFilename,
    1843                                     &pFile->hf,
    1844                                     &ulAction,
    1845                                     *pcbFile,
    1846                                     FILE_ARCHIVED,
    1847                                     fsOpenFlags,
    1848                                     fsOpenMode,
    1849                                     NULL)))       // EAs
    1850                 {
    1851                     // alright, got the file:
    1852 
    1853                     if (    (ulAction == FILE_EXISTED)
    1854                          && ((flOpenMode & XOPEN_ACCESS_MASK) == XOPEN_READWRITE_APPEND)
    1855                        )
    1856                         // get its size and set ptr to end for append
    1857                         arc = DosSetFilePtr(pFile->hf,
    1858                                             0,
    1859                                             FILE_END,
     1852                // alright, got the file:
     1853
     1854                if (    (ulAction == FILE_EXISTED)
     1855                     && ((flOpenMode & XOPEN_ACCESS_MASK) == XOPEN_READWRITE_APPEND)
     1856                   )
     1857                    // get its size and set ptr to end for append
     1858                    arc = DosSetFilePtr(pFile->hf,
     1859                                        0,
     1860                                        FILE_END,
     1861                                        pcbFile);
     1862                else
     1863                    arc = doshQueryFileSize(pFile->hf,
    18601864                                            pcbFile);
    1861                     else
    1862                         arc = doshQueryFileSize(pFile->hf,
    1863                                                 pcbFile);
    1864                         // file ptr is at beginning
    1865 
    1866                     // store file size
    1867                     pFile->cbInitial
    1868                     = pFile->cbCurrent
    1869                     = *pcbFile;
    1870                 }
    1871 
    1872                 if (arc)
    1873                     doshClose(&pFile);
    1874                 else
    1875                     *ppFile = pFile;
     1865                    // file ptr is at beginning
     1866
     1867                 if (arc)
     1868                    _Pmpf((__FUNCTION__ ": DosSetFilePtr/queryfilesize returned %d for %s",
     1869                                arc, pcszFilename));
     1870
     1871                // store file size
     1872                pFile->cbInitial
     1873                = pFile->cbCurrent
     1874                = *pcbFile;
    18761875            }
    18771876            else
    1878                 arc = ERROR_NOT_ENOUGH_MEMORY;
     1877                 _Pmpf((__FUNCTION__ ": DosOpen returned %d for %s",
     1878                             arc, pcszFilename));
     1879
     1880            if (arc)
     1881                doshClose(&pFile);
     1882            else
     1883                *ppFile = pFile;
    18791884        }
    18801885        else
    1881             arc = ERROR_INVALID_PARAMETER;
    1882     }
     1886            arc = ERROR_NOT_ENOUGH_MEMORY;
     1887    }
     1888    else
     1889        arc = ERROR_INVALID_PARAMETER;
    18831890
    18841891    return (arc);
  • trunk/src/helpers/dosh2.c

    r124 r126  
    552552                        cbRead = sizeof(PEHEADER);
    553553
    554                     if (!(pbHeader = malloc(cbRead)))
     554                    if (!(pbHeader = (PBYTE)malloc(cbRead)))
    555555                        arc = ERROR_NOT_ENOUGH_MEMORY;
    556556                    else if (!(arc = doshReadAt(hFile,
  • trunk/src/helpers/gpih.c

    r111 r126  
    6262// array for querying device capabilities (gpihQueryDisplayCaps)
    6363LONG            DisplayCaps[CAPS_DEVICE_POLYSET_POINTS] = {0};
    64 BOOL            fCapsQueried = FALSE;
     64BOOL            G_fCapsQueried = FALSE;
    6565
    6666/*
     
    171171 *      This function will load all the device capabilities
    172172 *      only once into a global array and re-use them afterwards.
     173 *
     174 *@@changed V0.9.16 (2001-12-18) [umoeller]: fixed multiple loads
    173175 */
    174176
    175177ULONG gpihQueryDisplayCaps(ULONG ulIndex)
    176178{
    177     if (!fCapsQueried)
     179    if (!G_fCapsQueried)
    178180    {
    179181        HPS hps = WinGetScreenPS(HWND_DESKTOP);
    180182        HDC hdc = GpiQueryDevice(hps);
    181183        DevQueryCaps(hdc, 0, CAPS_DEVICE_POLYSET_POINTS, &DisplayCaps[0]);
     184        G_fCapsQueried = TRUE;      // was missing V0.9.16 (2001-12-18) [umoeller]
    182185    }
    183186
     
    14591462/*
    14601463 *@@ gpihCreateBitmap:
     1464 *      calls gpihCreateBitmap2 with cPlanes and cBitCount == 0
     1465 *      for compatibility with exports. Widgets might
     1466 *      have used this func.
     1467 *
     1468 *@@changed V0.9.0 [umoeller]: function prototype changed to cx and cy
     1469 *@@changed V0.9.16 (2001-12-18) [umoeller]: now using optimized gpihCreateBitmap2
     1470 */
     1471
     1472HBITMAP gpihCreateBitmap(HPS hpsMem,        // in: memory DC
     1473                         ULONG cx,          // in: width of new bitmap
     1474                         ULONG cy)          // in: height of new bitmap
     1475{
     1476    return (gpihCreateBitmap2(hpsMem,
     1477                              cx,
     1478                              cy,
     1479                              0,
     1480                              0));            // current screen bit count
     1481}
     1482
     1483/*
     1484 *@@ gpihCreateBitmap2:
    14611485 *      creates a new bitmap for a given memory PS.
    14621486 *      This bitmap will have the cPlanes and bitcount
     
    14721496 *      Returns the bitmap handle or NULLHANDLE upon errors.
    14731497 *
    1474  *@@changed V0.9.0 [umoeller]: function prototype changed to cx and cy
    1475  */
    1476 
    1477 HBITMAP gpihCreateBitmap(HPS hpsMem,        // in: memory DC
    1478                          ULONG cx,          // in: width of new bitmap
    1479                          ULONG cy)          // in: height of new bitmap
     1498 *@@added V0.9.16 (2001-12-18) [umoeller]
     1499 */
     1500
     1501HBITMAP gpihCreateBitmap2(HPS hpsMem,        // in: memory DC
     1502                          ULONG cx,          // in: width of new bitmap
     1503                          ULONG cy,          // in: height of new bitmap
     1504                          ULONG cPlanes,     // in: color planes (usually 1); if 0, current screen is used
     1505                          ULONG cBitCount)   // in: either 1, 4, or 24; if 0, current screen value
    14801506{
    14811507    HBITMAP hbm = NULLHANDLE;
    14821508    LONG alData[2];
    14831509    BITMAPINFOHEADER2 bih2;
    1484     PBITMAPINFO2 pbmi = NULL;
     1510    // PBITMAPINFO2 pbmi = NULL;
    14851511
    14861512    // determine the device's plane/bit-count format;
     
    14931519        bih2.cx = cx; // (prcl->xRight - prcl->xLeft);       changed V0.9.0
    14941520        bih2.cy = cy; // (prcl->yTop - prcl->yBottom);       changed V0.9.0
    1495         bih2.cPlanes = alData[0];
    1496         bih2.cBitCount = alData[1];
     1521        bih2.cPlanes = (cPlanes) ? cPlanes : alData[0];
     1522        bih2.cBitCount = (cBitCount) ? cBitCount : alData[1];
     1523            _Pmpf((__FUNCTION__ ": cPlanes %d, cBitCount %d",
     1524                        bih2.cPlanes, bih2.cBitCount));
    14971525        bih2.ulCompression = BCA_UNCOMP;
    14981526        bih2.cbImage = (    (   (bih2.cx
     
    15151543        bih2.ulIdentifier = 0;              // application-specific data
    15161544
    1517         // allocate memory for info header
    1518         if (DosAllocMem((PPVOID)&pbmi,
    1519                         sizeof(BITMAPINFO2) +
    1520                             (sizeof(RGB2)
    1521                                 * (1 << bih2.cPlanes)
    1522                                 * (1 << bih2.cBitCount)
    1523                             ),
    1524                         PAG_COMMIT | PAG_READ | PAG_WRITE)
    1525             == NO_ERROR)
    1526         {
    1527             pbmi->cbFix = bih2.cbFix;
    1528             pbmi->cx = bih2.cx;
    1529             pbmi->cy = bih2.cy;
    1530             pbmi->cPlanes = bih2.cPlanes;
    1531             pbmi->cBitCount = bih2.cBitCount;
    1532             pbmi->ulCompression = BCA_UNCOMP;
    1533             pbmi->cbImage = ((bih2.cx+31)/32) * bih2.cy;
    1534             pbmi->cxResolution = 70;
    1535             pbmi->cyResolution = 70;
    1536             pbmi->cclrUsed = 2;
    1537             pbmi->cclrImportant = 0;
    1538             pbmi->usUnits = BRU_METRIC;
    1539             pbmi->usReserved = 0;
    1540             pbmi->usRecording = BRA_BOTTOMUP;
    1541             pbmi->usRendering = BRH_NOTHALFTONED;
    1542             pbmi->cSize1 = 0;
    1543             pbmi->cSize2 = 0;
    1544             pbmi->ulColorEncoding = BCE_RGB;
    1545             pbmi->ulIdentifier = 0;
    1546 
    1547             // create a bit map that is compatible with the display
    1548             hbm = GpiCreateBitmap(hpsMem,
    1549                                   &bih2,
    1550                                   FALSE,
    1551                                   NULL,
    1552                                   pbmi);
    1553 
    1554             // free the memory we allocated previously; GPI has
    1555             // allocated all the resources it needs itself, so
    1556             // we can release this
    1557             DosFreeMem(pbmi);
    1558         }
     1545        // create a bit map that is compatible with the display
     1546        hbm = GpiCreateBitmap(hpsMem,
     1547                              &bih2,
     1548                              0,            // do not initialize
     1549                              NULL,
     1550                              NULL);
    15591551    }
    15601552
     
    20862078/*
    20872079 *@@ gpihCreateXBitmap:
     2080 *      calls gpihCreateXBitmap2 with cPlanes and cBitCount == 0
     2081 *      for compatibility with exports. Widgets might
     2082 *      have used this func.
     2083 *
     2084 *@@added V0.9.12 (2001-05-20) [umoeller]
     2085 *@@changed V0.9.16 (2001-12-18) [umoeller]: now using optimized gpihCreateXBitmap2
     2086 */
     2087
     2088PXBITMAP gpihCreateXBitmap(HAB hab,         // in: anchor block
     2089                           LONG cx,         // in: bitmap width
     2090                           LONG cy)         // in: bitmap height
     2091{
     2092    return (gpihCreateXBitmap2(hab,
     2093                               cx,
     2094                               cy,
     2095                               0,
     2096                               0));
     2097}
     2098
     2099/*
     2100 *@@ gpihCreateXBitmap:
    20882101 *      creates an XBitmap, which is returned in an
    20892102 *      _XBITMAP structure.
     
    21242137 *      to more than 100 lines.
    21252138 *
    2126  *@@added V0.9.12 (2001-05-20) [umoeller]
    2127  */
    2128 
    2129 PXBITMAP gpihCreateXBitmap(HAB hab,         // in: anchor block
    2130                            LONG cx,         // in: bitmap width
    2131                            LONG cy)         // in: bitmap height
     2139 *@@added V0.9.16 (2001-12-18) [umoeller]
     2140 */
     2141
     2142PXBITMAP gpihCreateXBitmap2(HAB hab,         // in: anchor block
     2143                            LONG cx,         // in: bitmap width
     2144                            LONG cy,         // in: bitmap height
     2145                            ULONG cPlanes,     // in: color planes (usually 1); if 0, current screen is used
     2146                            ULONG cBitCount)   // in: either 1, 4, or 24; if 0, current screen value
    21322147{
    21332148    BOOL fOK = FALSE;
     
    21452160                            &pbmp->hpsMem))
    21462161        {
    2147             gpihSwitchToRGB(pbmp->hpsMem);
    2148             if (pbmp->hbm = gpihCreateBitmap(pbmp->hpsMem,
    2149                                              cx,
    2150                                              cy))
     2162            if (cBitCount != 1)
     2163                // not monochrome bitmap:
     2164                gpihSwitchToRGB(pbmp->hpsMem);
     2165
     2166            if (pbmp->hbm = gpihCreateBitmap2(pbmp->hpsMem,
     2167                                              cx,
     2168                                              cy,
     2169                                              cPlanes,
     2170                                              cBitCount))
    21512171            {
    21522172                if (GpiSetBitmap(pbmp->hpsMem,
     
    21622182
    21632183    return (pbmp);
     2184}
     2185
     2186/*
     2187 *@@ gpihDetachBitmap:
     2188 *      "detaches" the bitmap from the given XBITMAP.
     2189 *      This will deselect the bitmap from the internal
     2190 *      memory PS so it can be used with many OS/2 APIs
     2191 *      that require that the bitmap not be selected
     2192 *      into any memory PS.
     2193 *
     2194 *      Note that it then becomes the responsibility
     2195 *      of the caller to explicitly call GpiDeleteBitmap
     2196 *      because it will not be deleted by gpihDestroyXBitmap.
     2197 *
     2198 *@@added V0.9.16 (2001-12-18) [umoeller]
     2199 */
     2200
     2201HBITMAP gpihDetachBitmap(PXBITMAP pbmp)
     2202{
     2203    HBITMAP hbm = pbmp->hbm;
     2204    pbmp->hbm = NULLHANDLE;
     2205    GpiSetBitmap(pbmp->hpsMem, NULLHANDLE);
     2206
     2207    return (hbm);
    21642208}
    21652209
Note: See TracChangeset for help on using the changeset viewer.