Ignore:
Timestamp:
Dec 14, 2001, 11:41:33 PM (24 years ago)
Author:
umoeller
Message:

Lots of changes for icons and refresh.

File:
1 edited

Legend:

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

    r122 r123  
    127127    ULONG           ulAction;
    128128
    129     arc = DosOpen("KBD$", &hfKbd, &ulAction, 0,
    130                   FILE_NORMAL, FILE_OPEN,
    131                   OPEN_ACCESS_READONLY | OPEN_SHARE_DENYWRITE,
    132                   (PEAOP2)NULL);
    133     if (arc == NO_ERROR)
     129    if (!(arc = DosOpen("KBD$", &hfKbd, &ulAction, 0,
     130                        FILE_NORMAL,
     131                        FILE_OPEN,
     132                        OPEN_ACCESS_READONLY | OPEN_SHARE_DENYWRITE,
     133                        (PEAOP2)NULL)))
    134134    {
    135135        SHIFTSTATE      ShiftState;
    136136        ULONG           cbDataLen = sizeof(ShiftState);
    137137
    138         arc = DosDevIOCtl(hfKbd, IOCTL_KEYBOARD, KBD_GETSHIFTSTATE,
    139                           NULL, 0, NULL,      // no parameters
    140                           &ShiftState, cbDataLen, &cbDataLen);
    141         if (arc == NO_ERROR)
     138        if (!(arc = DosDevIOCtl(hfKbd, IOCTL_KEYBOARD, KBD_GETSHIFTSTATE,
     139                                NULL, 0, NULL,      // no parameters
     140                                &ShiftState, cbDataLen, &cbDataLen)))
    142141            brc = ((ShiftState.fsState & 3) != 0);
    143142
     
    308307
    309308    return (pv);
     309}
     310
     311/*
     312 *@@ doshAllocArray:
     313 *      allocates c * cbArrayItem bytes.
     314 *      Similar to calloc(), but returns
     315 *      error codes:
     316 *
     317 *      --  NO_ERROR: *ppv and *pcbAllocated were set.
     318 *
     319 *      --  ERROR_NO_DATA: either c or cbArrayItem are
     320 *          zero.
     321 *
     322 *      --  ERROR_NOT_ENOUGH_MEMORY: malloc() failed.
     323 *
     324 *@@added V0.9.16 (2001-12-08) [umoeller]
     325 */
     326
     327APIRET doshAllocArray(ULONG c,              // in: array item count
     328                      ULONG cbArrayItem,    // in: size of one array item
     329                      PBYTE *ppv,           // out: memory ptr if NO_ERROR is returned
     330                      PULONG pcbAllocated)  // out: # of bytes allocated
     331{
     332    if (!c || !cbArrayItem)
     333        return ERROR_NO_DATA;
     334
     335    *pcbAllocated = c * cbArrayItem;
     336    if (!(*ppv = malloc(*pcbAllocated)))
     337        return ERROR_NOT_ENOUGH_MEMORY;
     338
     339    return NO_ERROR;
    310340}
    311341
     
    13331363 *      has no dot in it).
    13341364 *
     1365 *      In the pathological case of a dot in the path
     1366 *      but not in the filename itself, this correctly
     1367 *      returns NULL.
     1368 *
    13351369 *@@added V0.9.6 (2000-10-16) [umoeller]
    13361370 *@@changed V0.9.7 (2000-12-10) [umoeller]: fixed "F:filename.ext" case
     
    13441378    {
    13451379        // find filename
    1346         PCSZ    p2 = strrchr(pcszFilename + 2, '\\'),
    1347                             // works on "C:\blah" or "\\unc\blah"
     1380        PCSZ    p2,
    13481381                pStartOfName = NULL,
    13491382                pExtension = NULL;
    13501383
    1351         if (p2)
     1384        if (p2 = strrchr(pcszFilename + 2, '\\'))
     1385                            // works on "C:\blah" or "\\unc\blah"
    13521386            pStartOfName = p2 + 1;
    13531387        else
     
    13651399
    13661400        // find last dot in filename
    1367         pExtension = strrchr(pStartOfName, '.');
    1368         if (pExtension)
     1401        if (pExtension = strrchr(pStartOfName, '.'))
    13691402            pReturn = (PSZ)pExtension + 1;
    13701403    }
     
    14181451        // Each data field following fsqBuffer.szName begins
    14191452        // immediately after the previous item.
    1420         if (strncmp((PSZ)&(pfsqBuffer->szName) + pfsqBuffer->cbName + 1,
    1421                     "FAT",
    1422                     3)
    1423                == 0)
     1453        if (!strncmp((PSZ)&(pfsqBuffer->szName) + pfsqBuffer->cbName + 1,
     1454                     "FAT",
     1455                     3))
    14241456            brc = TRUE;
    14251457    }
     
    14381470 */
    14391471
    1440 APIRET doshQueryFileSize(HFILE hFile,
    1441                          PULONG pulSize)
     1472APIRET doshQueryFileSize(HFILE hFile,       // in: file handle
     1473                         PULONG pulSize)    // out: file size (ptr can be NULL)
    14421474{
    14431475    APIRET arc;
    14441476    FILESTATUS3 fs3;
    14451477    if (!(arc = DosQueryFileInfo(hFile, FIL_STANDARD, &fs3, sizeof(fs3))))
    1446         *pulSize = fs3.cbFile;
     1478        if (pulSize)
     1479            *pulSize = fs3.cbFile;
    14471480    return (arc);
    14481481}
     
    14531486 *      or 0 if the file could not be
    14541487 *      found.
     1488 *
    14551489 *      Use doshQueryFileSize instead to query the
    14561490 *      size if you have a HFILE.
    14571491 *
     1492 *      Otherwise this returns:
     1493 *
     1494 *      --  ERROR_FILE_NOT_FOUND
     1495 *      --  ERROR_PATH_NOT_FOUND
     1496 *      --  ERROR_SHARING_VIOLATION
     1497 *      --  ERROR_FILENAME_EXCED_RANGE
     1498 *      --  ERROR_INVALID_PARAMETER
     1499 *
    14581500 *@@changed V0.9.16 (2001-10-19) [umoeller]: now returning APIRET
    14591501 */
    14601502
    1461 APIRET doshQueryPathSize(PCSZ pcszFile,
    1462                          PULONG pulSize)
     1503APIRET doshQueryPathSize(PCSZ pcszFile,         // in: filename
     1504                         PULONG pulSize)        // out: file size (ptr can be NULL)
    14631505{
    14641506    APIRET arc;
    1465     FILESTATUS3 fs3;
    1466     if (!(arc = DosQueryPathInfo((PSZ)pcszFile, FIL_STANDARD, &fs3, sizeof(fs3))))
    1467         *pulSize = fs3.cbFile;
     1507
     1508    if (pcszFile)      // V0.9.16 (2001-12-08) [umoeller]
     1509    {
     1510        FILESTATUS3 fs3;
     1511        if (!(arc = DosQueryPathInfo((PSZ)pcszFile, FIL_STANDARD, &fs3, sizeof(fs3))))
     1512            if (pulSize)
     1513                *pulSize = fs3.cbFile;
     1514    }
     1515    else
     1516        arc = ERROR_INVALID_PARAMETER;
     1517
    14681518    return (arc);
    14691519}
     
    14881538 *      returned.
    14891539 *
     1540 *      Otherwise this returns:
     1541 *
     1542 *      --  ERROR_FILE_NOT_FOUND
     1543 *      --  ERROR_PATH_NOT_FOUND
     1544 *      --  ERROR_SHARING_VIOLATION
     1545 *      --  ERROR_FILENAME_EXCED_RANGE
     1546 *
    14901547 *@@added V0.9.0 [umoeller]
    14911548 */
    14921549
    14931550APIRET doshQueryPathAttr(const char* pcszFile,      // in: file or directory name
    1494                          PULONG pulAttr)            // out: attributes
     1551                         PULONG pulAttr)            // out: attributes (ptr can be NULL)
    14951552{
    14961553    FILESTATUS3 fs3;
    1497     APIRET arc = DosQueryPathInfo((PSZ)pcszFile,
     1554    APIRET arc;
     1555
     1556    if (!(arc = DosQueryPathInfo((PSZ)pcszFile,
    14981557                                  FIL_STANDARD,
    14991558                                  &fs3,
    1500                                   sizeof(fs3));
    1501     if (arc == NO_ERROR)
     1559                                  sizeof(fs3))))
    15021560    {
    15031561        if (pulAttr)
     
    15321590                       ULONG ulAttr)            // in: new attributes
    15331591{
    1534     FILESTATUS3 fs3;
    1535     APIRET rc = DosQueryPathInfo((PSZ)pcszFile,
     1592    APIRET arc;
     1593
     1594    if (pcszFile)
     1595    {
     1596        FILESTATUS3 fs3;
     1597        if (!(arc = DosQueryPathInfo((PSZ)pcszFile,
     1598                                      FIL_STANDARD,
     1599                                      &fs3,
     1600                                      sizeof(fs3))))
     1601        {
     1602            fs3.attrFile = ulAttr;
     1603            arc = DosSetPathInfo((PSZ)pcszFile,
    15361604                                 FIL_STANDARD,
    15371605                                 &fs3,
    1538                                  sizeof(fs3));
    1539 
    1540     if (rc == NO_ERROR)
    1541     {
    1542         fs3.attrFile = ulAttr;
    1543         rc = DosSetPathInfo((PSZ)pcszFile,
    1544                             FIL_STANDARD,
    1545                             &fs3,
    1546                             sizeof(fs3),
    1547                             DSPI_WRTTHRU);
    1548     }
    1549     return (rc);
     1606                                 sizeof(fs3),
     1607                                 DSPI_WRTTHRU);
     1608        }
     1609    }
     1610    else
     1611        arc = ERROR_INVALID_PARAMETER;
     1612
     1613    return (arc);
    15501614}
    15511615
     
    16401704                  LONG lOffset,    // in: offset to write at (depends on ulMethod)
    16411705                  ULONG ulMethod,  // in: one of FILE_BEGIN, FILE_CURRENT, FILE_END
    1642                   ULONG cb,        // in: bytes to write
     1706                  PULONG pcb,      // in: bytes to read, out: bytes read
    16431707                  PBYTE pbData)    // out: read buffer (must be cb bytes)
    16441708{
    16451709    APIRET arc;
     1710    ULONG cb = *pcb;
    16461711    ULONG ulDummy;
     1712
     1713    *pcb = 0;
     1714
    16471715    if (!(arc = DosSetFilePtr(hf,
    16481716                              lOffset,
    16491717                              ulMethod,
    16501718                              &ulDummy)))
    1651         arc = DosRead(hf,
    1652                       pbData,
    1653                       cb,
    1654                       &ulDummy);
     1719    {
     1720        if (!(arc = DosRead(hf,
     1721                            pbData,
     1722                            cb,
     1723                            &ulDummy)))
     1724            *pcb = ulDummy;     // bytes read
     1725    }
    16551726
    16561727    return (arc);
     
    16631734 *
    16641735 *      ulOpenMode determines the mode to open the
    1665  *      file in:
    1666  *
    1667  +      +-------------------------+------+-----------+-----------+
    1668  +      |                         |      |           |           |
    1669  +      |  ulOpenMode             | mode | if exists | if new    |
    1670  +      +-------------------------+------+-----------+-----------+
    1671  +      |  XOPEN_READ_EXISTING    | read | opens     | fails     |
    1672  +      +-------------------------+------+-----------+-----------+
    1673  +      |  XOPEN_READWRITE_APPEND | r/w  | opens,    | creates   |
    1674  +      |                         |      | appends   |           |
    1675  +      +-------------------------+------+-----------+-----------+
    1676  +      |  XOPEN_READWRITE_NEW    | r/w  | replaces  | creates   |
    1677  +      +-------------------------+------+-----------+-----------+
    1678  *
    1679  *      In addition, you can specify the XOPEN_BINARY flag:
     1736 *      file in (fptr specifies the position after
     1737 *      the open):
     1738 *
     1739 +      +-------------------------+------+------------+-----------+
     1740 +      |  ulOpenMode             | mode | if exists  | if new    |
     1741 +      +-------------------------+------+------------+-----------+
     1742 +      |  XOPEN_READ_EXISTING    | read | opens      | fails     |
     1743 +      |                         |      | fptr = 0   |           |
     1744 +      +-------------------------+------+------------+-----------+
     1745 +      |  XOPEN_READWRITE_APPEND | r/w  | opens,     | creates   |
     1746 +      |                         |      | appends    |           |
     1747 +      |                         |      | fptr = end | fptr = 0  |
     1748 +      +-------------------------+------+------------+-----------+
     1749 +      |  XOPEN_READWRITE_NEW    | r/w  | replaces   | creates   |
     1750 +      |                         |      | fptr = 0   | fptr = 0  |
     1751 +      +-------------------------+------+------------+-----------+
     1752 *
     1753 *      In addition, you can OR one of the above values with
     1754 *      the XOPEN_BINARY flag:
    16801755 *
    16811756 *      --  If XOPEN_BINARY is set, no conversion is performed
     
    16871762 *      *ppFile receives a new XFILE structure describing
    16881763 *      the open file, if NO_ERROR is returned.
     1764 *
     1765 *      The file pointer is then set to the beginning of the
     1766 *      file _unless_ XOPEN_READWRITE_APPEND was specified;
     1767 *      in that case only, the file pointer is set to the
     1768 *      end of the file so data can be appended (see above).
     1769 *
     1770 *      Otherwise this returns:
     1771 *
     1772 *      --  ERROR_FILE_NOT_FOUND
     1773 *      --  ERROR_PATH_NOT_FOUND
     1774 *      --  ERROR_SHARING_VIOLATION
     1775 *      --  ERROR_FILENAME_EXCED_RANGE
     1776 *
     1777 *      --  ERROR_NOT_ENOUGH_MEMORY
     1778 *      --  ERROR_INVALID_PARAMETER
    16891779 *
    16901780 *@@added V0.9.16 (2001-10-19) [umoeller]
     
    16991789    APIRET arc = NO_ERROR;
    17001790
    1701     ULONG   fsOpenFlags = 0,
    1702             fsOpenMode =    OPEN_FLAGS_FAIL_ON_ERROR
    1703                           | OPEN_FLAGS_NO_LOCALITY
    1704                           | OPEN_FLAGS_NOINHERIT;
    1705 
    1706     switch (flOpenMode & XOPEN_ACCESS_MASK)
    1707     {
    1708         case XOPEN_READ_EXISTING:
    1709             fsOpenFlags =   OPEN_ACTION_FAIL_IF_NEW
    1710                           | OPEN_ACTION_OPEN_IF_EXISTS;
    1711             fsOpenMode |=   OPEN_SHARE_DENYWRITE
    1712                           | OPEN_ACCESS_READONLY;
    1713             // _Pmpf((__FUNCTION__ ": opening XOPEN_READ_EXISTING"));
    1714         break;
    1715 
    1716         case XOPEN_READWRITE_APPEND:
    1717             fsOpenFlags =   OPEN_ACTION_CREATE_IF_NEW
    1718                           | OPEN_ACTION_OPEN_IF_EXISTS;
    1719             fsOpenMode |=   OPEN_SHARE_DENYREADWRITE
    1720                           | OPEN_ACCESS_READWRITE;
    1721             // _Pmpf((__FUNCTION__ ": opening XOPEN_READWRITE_APPEND"));
    1722         break;
    1723 
    1724         case XOPEN_READWRITE_NEW:
    1725             fsOpenFlags =   OPEN_ACTION_CREATE_IF_NEW
    1726                           | OPEN_ACTION_REPLACE_IF_EXISTS;
    1727             fsOpenMode |=   OPEN_SHARE_DENYREADWRITE
    1728                           | OPEN_ACCESS_READWRITE;
    1729             // _Pmpf((__FUNCTION__ ": opening XOPEN_READWRITE_NEW"));
    1730         break;
    1731 
    1732         default:
    1733             arc = ERROR_INVALID_PARAMETER;
    1734     }
    1735 
    1736     if ((!arc) && pcszFilename && fsOpenFlags && pcbFile && ppFile)
    1737     {
    1738         PXFILE pFile;
    1739         if (pFile = NEW(XFILE))
     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)
    17401804        {
    1741             ULONG ulAction;
    1742 
    1743             ZERO(pFile);
    1744 
    1745             // copy open flags
    1746             pFile->flOpenMode = flOpenMode;
    1747 
    1748             if (!(arc = DosOpen((PSZ)pcszFilename,
    1749                                 &pFile->hf,
    1750                                 &ulAction,
    1751                                 *pcbFile,
    1752                                 FILE_ARCHIVED,
    1753                                 fsOpenFlags,
    1754                                 fsOpenMode,
    1755                                 NULL)))       // EAs
     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))
    17561834            {
    1757                 // alright, got the file:
    1758 
    1759                 if (    (ulAction == FILE_EXISTED)
    1760                      && ((flOpenMode & XOPEN_ACCESS_MASK) == XOPEN_READWRITE_APPEND)
    1761                    )
    1762                     // get its size and set ptr to end for append
    1763                     arc = DosSetFilePtr(pFile->hf,
    1764                                         0,
    1765                                         FILE_END,
    1766                                         pcbFile);
     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,
     1860                                            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);
    17671874                else
    1768                     arc = doshQueryFileSize(pFile->hf,
    1769                                             pcbFile);
    1770                     // file ptr is at beginning
    1771 
    1772                 // store file size
    1773                 pFile->cbInitial
    1774                 = pFile->cbCurrent
    1775                 = *pcbFile;
     1875                    *ppFile = pFile;
    17761876            }
    1777 
    1778             if (arc)
    1779                 doshClose(&pFile);
    17801877            else
    1781                 *ppFile = pFile;
     1878                arc = ERROR_NOT_ENOUGH_MEMORY;
    17821879        }
    17831880        else
    1784             arc = ERROR_NOT_ENOUGH_MEMORY;
    1785     }
    1786     else
    1787         arc = ERROR_INVALID_PARAMETER;
     1881            arc = ERROR_INVALID_PARAMETER;
     1882    }
    17881883
    17891884    return (arc);
     
    21992294        if (!pcszTemp)
    22002295        {
    2201             pcszTemp = getenv("TEMP");
    2202             if (!pcszTemp)
     2296            if (!(pcszTemp = getenv("TEMP")))
    22032297                pcszTemp = getenv("TMP");
    22042298        }
     
    23852479 *@@ doshQueryDirExist:
    23862480 *      returns TRUE if the given directory
    2387  *      exists.
     2481 *      exists and really is a directory.
    23882482 */
    23892483
     
    23912485{
    23922486    FILESTATUS3 fs3;
    2393     APIRET arc = DosQueryPathInfo((PSZ)pcszDir,
    2394                                   FIL_STANDARD,
    2395                                   &fs3,
    2396                                   sizeof(fs3));
    2397     if (arc == NO_ERROR)
     2487    APIRET arc;
     2488
     2489    if (!(arc = DosQueryPathInfo((PSZ)pcszDir,
     2490                                 FIL_STANDARD,
     2491                                 &fs3,
     2492                                 sizeof(fs3))))
    23982493        // file found:
    23992494        return ((fs3.attrFile & FILE_DIRECTORY) != 0);
     
    26412736{
    26422737    CHAR    szName[CCHMAXPATH];
    2643     APIRET arc = DosLoadModule(szName,
    2644                                sizeof(szName),
    2645                                pszModuleName,
    2646                                phmod);
    2647     if (arc == NO_ERROR)
     2738    APIRET  arc;
     2739
     2740    if (!(arc = DosLoadModule(szName,
     2741                              sizeof(szName),
     2742                              pszModuleName,
     2743                              phmod)))
    26482744    {
    26492745        ULONG  ul;
     
    26522748             ul++)
    26532749        {
    2654             arc = DosQueryProcAddr(*phmod,
    2655                                    0,               // ordinal, ignored
    2656                                    (PSZ)paResolves[ul].pcszFunctionName,
    2657                                    paResolves[ul].ppFuncAddress);
    2658 
    2659             /* _Pmpf(("Resolved %s to 0x%lX, rc: %d",
    2660                     paResolves[ul].pcszFunctionName,
    2661                     *paResolves[ul].ppFuncAddress,
    2662                     arc)); */
    2663             if (arc != NO_ERROR)
     2750            if (arc = DosQueryProcAddr(*phmod,
     2751                                       0,               // ordinal, ignored
     2752                                       (PSZ)paResolves[ul].pcszFunctionName,
     2753                                       paResolves[ul].ppFuncAddress))
     2754                // error:
    26642755                break;
    26652756        }
     2757
     2758        if (arc)
     2759            // V0.9.16 (2001-12-08) [umoeller]
     2760            DosFreeModule(*phmod);
    26662761    }
    26672762
Note: See TracChangeset for help on using the changeset viewer.