Ignore:
Timestamp:
Jan 5, 2002, 8:11:10 PM (24 years ago)
Author:
umoeller
Message:

Tons of updates for turbo folders and replacement icons.

File:
1 edited

Legend:

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

    r126 r127  
    6565#include "helpers\dosh.h"
    6666#include "helpers\ensure.h"
     67#include "helpers\nls.h"
    6768#include "helpers\standards.h"
    6869#include "helpers\stringh.h"
     
    441442 *@@changed V0.9.16 (2001-12-08) [umoeller]: fLibrary was never set, works for LX and NE now
    442443 *@@changed V0.9.16 (2001-12-08) [umoeller]: some speed optimizations, changed some return codes
     444 *@@changed V0.9.16 (2002-01-04) [umoeller]: added fixes for COM, BAT, CMD extensions
    443445 */
    444446
     
    446448                    PEXECUTABLE* ppExec)
    447449{
    448     APIRET  arc = NO_ERROR;
    449 
    450     ULONG   ulAction = 0;
    451     HFILE   hFile;
     450    APIRET      arc = NO_ERROR;
     451
    452452    PEXECUTABLE pExec = NULL;
     453
     454    PXFILE      pFile = NULL;
     455    ULONG       cbFile = 0;
     456    PCSZ        pExt;
     457    BOOL        fOpenFile = FALSE;
    453458
    454459    if (!ppExec)
     
    460465    memset(pExec, 0, sizeof(EXECUTABLE));
    461466
    462     if (!(arc = DosOpen((PSZ)pcszExecutable,
    463                         &hFile,
    464                         &ulAction,                      // out: action taken
    465                         0,                              // in: new file (ignored for read-mode)
    466                         0,                              // in: new file attribs (ignored)
    467                         // open-flags
    468                         OPEN_ACTION_FAIL_IF_NEW
    469                            | OPEN_ACTION_OPEN_IF_EXISTS,
    470                         // open-mode
    471                         OPEN_FLAGS_FAIL_ON_ERROR        // report errors to caller
    472                            | OPEN_FLAGS_SEQUENTIAL
    473                            | OPEN_FLAGS_NOINHERIT
    474                            // | OPEN_SHARE_DENYNONE
    475                            | OPEN_SHARE_DENYWRITE       // changed V0.9.16 (2001-12-08) [umoeller]
    476                            | OPEN_ACCESS_READONLY,      // read-only mode
    477                         NULL)))                         // no EAs
     467    // check some of the default extensions
     468    // V0.9.16 (2002-01-04) [umoeller]
     469    if (pExt = doshGetExtension(pcszExecutable))
     470    {
     471        if (!stricmp(pExt, "COM"))
     472        {
     473            // I am not willing to find out more about the
     474            // .COM executable format, so for this one case,
     475            // let OS/2 determine what we have here
     476            ULONG ulDosAppType = 0;
     477            if (!(arc = DosQueryAppType((PSZ)pcszExecutable, &ulDosAppType)))
     478            {
     479                if (ulDosAppType & FAPPTYP_DOS)           // 0x20
     480                    pExec->ulOS = EXEOS_DOS3;
     481                else
     482                    pExec->ulOS = EXEOS_OS2;
     483
     484                pExec->ulExeFormat = EXEFORMAT_COM;
     485            }
     486        }
     487        else if (!stricmp(pExt, "BAT"))
     488        {
     489            pExec->ulOS = EXEOS_DOS3;
     490            pExec->ulExeFormat = EXEFORMAT_TEXT_BATCH;
     491        }
     492        else if (!stricmp(pExt, "CMD"))
     493        {
     494            pExec->ulOS = EXEOS_OS2;
     495            pExec->ulExeFormat = EXEFORMAT_TEXT_CMD;
     496        }
     497        else
     498            fOpenFile = TRUE;
     499    }
     500
     501    if (    (fOpenFile)
     502         && (!(arc = doshOpen((PSZ)pcszExecutable,
     503                              XOPEN_READ_EXISTING,
     504                              &cbFile,
     505                              &pFile)))
     506       )
    478507    {
    479508        // file opened successfully:
     509        pExec->pFile = pFile;
    480510
    481511        // read old DOS EXE header
     
    485515        {
    486516            pExec->cbDosExeHeader = sizeof(DOSEXEHEADER);
    487             if (!(arc = doshReadAt(hFile,
     517            if (!(arc = doshReadAt(pFile,
    488518                                   0,
    489                                    FILE_BEGIN,
    490519                                   &pExec->cbDosExeHeader,      // in/out
    491520                                   (PBYTE)pExec->pDosExeHeader)))
     
    554583                    if (!(pbHeader = (PBYTE)malloc(cbRead)))
    555584                        arc = ERROR_NOT_ENOUGH_MEMORY;
    556                     else if (!(arc = doshReadAt(hFile,
     585                    else if (!(arc = doshReadAt(pFile,
    557586                                                ulNewHeaderOfs,
    558                                                 FILE_BEGIN,
    559587                                                &cbRead,
    560588                                                pbHeader)))
     
    626654                                // plus an extended header, so check what
    627655                                // we've got
    628                                 ULONG cbPE =   24
    629                                              + ((PPEHEADER)pbHeader)->usHeaderSize;
     656                                ULONG cbPE =   sizeof(PEHEADER); // 24
     657                                   //           + ((PPEHEADER)pbHeader)->usHeaderSize;
    630658                                pExec->pPEHeader = (PPEHEADER)realloc(pbHeader,
    631659                                                                      cbPE);
     
    635663                                pExec->f32Bits = TRUE;
    636664
     665                                /*
    637666                                // we have the first 24 bytes already, so
    638                                 // go for the next chunk
    639                                 if (cbRead = pExec->pPEHeader->usHeaderSize)
     667                                // go for the next chunk, if this is more
     668                                // than we have in PEHEADER
     669                                if (    (cbRead < cbPE)
     670                                     && (cbRead = pExec->pPEHeader->usHeaderSize)
     671                                   )
    640672                                {
     673                                    _Pmpf(("  usHdrSize %d, sizeof(PEHEADER) %d, cbRead %d, cbPE %d --> reading extended header",
     674                                           pExec->pPEHeader->usHeaderSize,
     675                                           sizeof(PEHEADER),
     676                                           cbRead,
     677                                           cbPE));
    641678                                    if (!(arc = doshReadAt(hFile,
    642679                                                           ulNewHeaderOfs + 24,
     
    647684                                    }
    648685                                    else
     686                                    {
    649687                                        arc = ERROR_BAD_EXE_FORMAT;
     688                                        FREE(pExec->pPEHeader);
     689                                    }
    650690                                }
     691                                else
     692                                    _Pmpf(("  already got extended header"));
     693                                */
    651694                            }
    652695                        }
    653696                        else
     697                        {
    654698                            // strange type:
    655699                            arc = ERROR_INVALID_EXE_SIGNATURE;
    656 
    657                         if (pbCheckOS)
     700                            FREE(pbHeader);
     701                        }
     702
     703                        if ((!arc) && (pbCheckOS))
    658704                        {
    659705                            // BYTE to check for operating system
     
    681727                            }
    682728                        }
    683                     }
    684                 }
    685             } // end if (!(arc = DosSetFilePtr(hFile,
    686         } // end if pExec->pDosExeHeader = (PDOSEXEHEADER)malloc(sizeof(DOSEXEHEADER));
    687 
    688         // store exec's HFILE
    689         pExec->hfExe = hFile;
     729                    } // end if (!(arc = doshReadAt(hFile,
     730                } // end if (fLoadNewHeader)
     731            } // end if (!(arc = doshReadAt(hFile,
     732        } // end else if (!(pExec->pDosExeHeader = (PDOSEXEHEADER)malloc(sizeof(DOSEXEHEADER))))
     733
    690734    } // end if (!(arc = DosOpen((PSZ)pcszExecutable,
    691735
     
    941985    else
    942986    {
     987        PXFILE      pFile = pExec->pFile;
     988
    943989        ULONG       ulNRNTOfs = 0;
    944990
     
    9781024            // move EXE file pointer to offset of non-resident name table
    9791025            // (from LX header)
    980             if (!(arc = DosSetFilePtr(pExec->hfExe,     // file is still open
     1026            if (!(arc = DosSetFilePtr(pFile->hf,     // file is still open
    9811027                                      ulNRNTOfs,      // ofs determined above
    9821028                                      FILE_BEGIN,
     
    9901036                else
    9911037                {
    992                     if (!(arc = DosRead(pExec->hfExe,
     1038                    if (!(arc = DosRead(pFile->hf,
    9931039                                        pszNameTable,
    9941040                                        2000,
     
    10691115        PFSYSMODULE paModules = NULL;
    10701116        int i;
     1117        HFILE hfExe = pExec->pFile->hf;
    10711118
    10721119        ULONG ulNewHeaderOfs = 0;       // V0.9.12 (2001-05-03) [umoeller]
     
    10921139                memset(paModules, 0, cb);   // V0.9.9 (2001-04-03) [umoeller]
    10931140
    1094                 ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     1141                ENSURE_SAFE(DosSetFilePtr(hfExe,
    10951142                                          pExec->pLXHeader->ulImportModTblOfs
    10961143                                            + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller]
     
    11031150
    11041151                    // reading the length of the module name
    1105                     ENSURE_SAFE(DosRead(pExec->hfExe, &bLen, 1, &ulDummy));
     1152                    ENSURE_SAFE(DosRead(hfExe, &bLen, 1, &ulDummy));
    11061153
    11071154                    // reading the module name
    1108                     ENSURE_SAFE(DosRead(pExec->hfExe,
     1155                    ENSURE_SAFE(DosRead(hfExe,
    11091156                                        paModules[i].achModuleName,
    11101157                                        bLen,
     
    11431190                    // then we read the name in the import table
    11441191
    1145                     ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     1192                    ENSURE_SAFE(DosSetFilePtr(hfExe,
    11461193                                              pExec->pNEHeader->usModRefTblOfs
    11471194                                                + ulNewHeaderOfs // V0.9.12 (2001-05-03) [umoeller]
     
    11501197                                              &ulDummy));
    11511198
    1152                     ENSURE_SAFE(DosRead(pExec->hfExe, &usOfs, 2, &ulDummy));
    1153 
    1154                     ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     1199                    ENSURE_SAFE(DosRead(hfExe, &usOfs, 2, &ulDummy));
     1200
     1201                    ENSURE_SAFE(DosSetFilePtr(hfExe,
    11551202                                              pExec->pNEHeader->usImportTblOfs
    11561203                                                + ulNewHeaderOfs // V0.9.12 (2001-05-03) [umoeller]
     
    11591206                                              &ulDummy));
    11601207
    1161                     ENSURE_SAFE(DosRead(pExec->hfExe, &bLen, 1, &ulDummy));
    1162 
    1163                     ENSURE_SAFE(DosRead(pExec->hfExe,
     1208                    ENSURE_SAFE(DosRead(hfExe, &bLen, 1, &ulDummy));
     1209
     1210                    ENSURE_SAFE(DosRead(hfExe,
    11641211                                        paModules[i].achModuleName,
    11651212                                        bLen,
     
    12241271
    12251272    ULONG ulNewHeaderOfs = 0; // V0.9.12 (2001-05-03) [umoeller]
     1273    HFILE hfExe = pExec->pFile->hf;
    12261274
    12271275    if (pExec->pDosExeHeader)
     
    12291277        ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs;
    12301278
    1231     ENSURE(DosSetFilePtr(pExec->hfExe,
     1279    ENSURE(DosSetFilePtr(hfExe,
    12321280                         pExec->pLXHeader->ulEntryTblOfs
    12331281                           + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller]
     
    12411289               bFlag;
    12421290
    1243         ENSURE(DosRead(pExec->hfExe, &bCnt, 1, &ulDummy));
     1291        ENSURE(DosRead(hfExe, &bCnt, 1, &ulDummy));
    12441292
    12451293        if (bCnt == 0)
     
    12471295            break;
    12481296
    1249         ENSURE(DosRead(pExec->hfExe, &bType, 1, &ulDummy));
     1297        ENSURE(DosRead(hfExe, &bType, 1, &ulDummy));
    12501298
    12511299        switch (bType & 0x7F)
     
    12691317
    12701318            case 1:
    1271                 ENSURE(DosSetFilePtr(pExec->hfExe,
     1319                ENSURE(DosSetFilePtr(hfExe,
    12721320                                     sizeof(USHORT),
    12731321                                     FILE_CURRENT,
     
    12761324                for (i = 0; i < bCnt; i ++)
    12771325                {
    1278                     ENSURE(DosRead(pExec->hfExe, &bFlag, 1, &ulDummy));
     1326                    ENSURE(DosRead(hfExe, &bFlag, 1, &ulDummy));
    12791327
    12801328                    if (bFlag & 0x01)
     
    12911339                    usOrdinal++;
    12921340
    1293                     ENSURE(DosSetFilePtr(pExec->hfExe,
     1341                    ENSURE(DosSetFilePtr(hfExe,
    12941342                                         sizeof(USHORT),
    12951343                                         FILE_CURRENT,
     
    13081356
    13091357            case 2:
    1310                 ENSURE(DosSetFilePtr(pExec->hfExe,
     1358                ENSURE(DosSetFilePtr(hfExe,
    13111359                                     sizeof(USHORT),
    13121360                                     FILE_CURRENT,
     
    13151363                for (i = 0; i < bCnt; i ++)
    13161364                {
    1317                     ENSURE(DosRead(pExec->hfExe, &bFlag, 1, &ulDummy));
     1365                    ENSURE(DosRead(hfExe, &bFlag, 1, &ulDummy));
    13181366
    13191367                    if (bFlag & 0x01)
     
    13301378                    usOrdinal++;
    13311379
    1332                     ENSURE(DosSetFilePtr(pExec->hfExe,
     1380                    ENSURE(DosSetFilePtr(hfExe,
    13331381                                         sizeof(USHORT) + sizeof(USHORT),
    13341382                                         FILE_CURRENT,
     
    13471395
    13481396            case 3:
    1349                 ENSURE(DosSetFilePtr(pExec->hfExe,
     1397                ENSURE(DosSetFilePtr(hfExe,
    13501398                                     sizeof(USHORT),
    13511399                                     FILE_CURRENT,
     
    13541402                for (i = 0; i < bCnt; i ++)
    13551403                {
    1356                     ENSURE(DosRead(pExec->hfExe, &bFlag, 1, &ulDummy));
     1404                    ENSURE(DosRead(hfExe, &bFlag, 1, &ulDummy));
    13571405
    13581406                    if (bFlag & 0x01)
     
    13691417                    usOrdinal++;
    13701418
    1371                     ENSURE(DosSetFilePtr(pExec->hfExe,
     1419                    ENSURE(DosSetFilePtr(hfExe,
    13721420                                         sizeof(ULONG),
    13731421                                         FILE_CURRENT,
     
    13851433
    13861434            case 4:
    1387                 ENSURE(DosSetFilePtr(pExec->hfExe,
     1435                ENSURE(DosSetFilePtr(hfExe,
    13881436                                     sizeof(USHORT),
    13891437                                     FILE_CURRENT,
     
    13921440                for (i = 0; i < bCnt; i ++)
    13931441                {
    1394                     ENSURE(DosSetFilePtr(pExec->hfExe,
     1442                    ENSURE(DosSetFilePtr(hfExe,
    13951443                                         sizeof(BYTE) + sizeof(USHORT) + sizeof(ULONG),
    13961444                                         FILE_CURRENT,
     
    14641512
    14651513    ULONG ulNewHeaderOfs = 0;
     1514    HFILE hfExe = pExec->pFile->hf;
    14661515
    14671516    if (pExec->pDosExeHeader)
     
    14691518        ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs;
    14701519
    1471     ENSURE(DosSetFilePtr(pExec->hfExe,
     1520    ENSURE(DosSetFilePtr(hfExe,
    14721521                         pExec->pNEHeader->usEntryTblOfs
    14731522                           + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller]
     
    14811530             bFlag;
    14821531
    1483         ENSURE(DosRead(pExec->hfExe, &bCnt, 1, &ulDummy));
     1532        ENSURE(DosRead(hfExe, &bCnt, 1, &ulDummy));
    14841533
    14851534        if (bCnt == 0)
     
    14871536            break;
    14881537
    1489         ENSURE(DosRead(pExec->hfExe, &bType, 1, &ulDummy));
     1538        ENSURE(DosRead(hfExe, &bType, 1, &ulDummy));
    14901539
    14911540        if (bType)
     
    14931542            for (i = 0; i < bCnt; i++)
    14941543            {
    1495                 ENSURE(DosRead(pExec->hfExe,
     1544                ENSURE(DosRead(hfExe,
    14961545                               &bFlag,
    14971546                               1,
     
    15141563                {
    15151564                    // moveable segment
    1516                     ENSURE(DosSetFilePtr(pExec->hfExe,
     1565                    ENSURE(DosSetFilePtr(hfExe,
    15171566                                         5,
    15181567                                         FILE_CURRENT,
     
    15221571                {
    15231572                    // fixed segment or constant (0xFE)
    1524                     ENSURE(DosSetFilePtr(pExec->hfExe,
     1573                    ENSURE(DosSetFilePtr(hfExe,
    15251574                                         2,
    15261575                                         FILE_CURRENT,
     
    15851634    USHORT        usOrdinal;
    15861635    PFSYSFUNCTION pFunction;
     1636    HFILE hfExe = pExec->pFile->hf;
    15871637
    15881638    while (TRUE)
     
    15921642        // int    i;
    15931643
    1594         ENSURE(DosRead(pExec->hfExe, &bLen, 1, &ulDummy));
     1644        ENSURE(DosRead(hfExe, &bLen, 1, &ulDummy));
    15951645
    15961646        if (bLen == 0)
     
    15981648            break;
    15991649
    1600         ENSURE(DosRead(pExec->hfExe, &achName, bLen, &ulDummy));
     1650        ENSURE(DosRead(hfExe, &achName, bLen, &ulDummy));
    16011651        achName[bLen] = 0;
    16021652
    1603         ENSURE(DosRead(pExec->hfExe, &usOrdinal, sizeof(USHORT), &ulDummy));
     1653        ENSURE(DosRead(hfExe, &usOrdinal, sizeof(USHORT), &ulDummy));
    16041654
    16051655        if ((pFunction = (PFSYSFUNCTION)bsearch(&usOrdinal,
     
    16681718        ULONG ulDummy;
    16691719
     1720        HFILE hfExe = pExec->pFile->hf;
    16701721        ULONG ulNewHeaderOfs = 0; // V0.9.12 (2001-05-03) [umoeller]
    16711722
     
    17021753                // we now scan the resident name table entries
    17031754
    1704                 ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     1755                ENSURE_SAFE(DosSetFilePtr(hfExe,
    17051756                                          pExec->pLXHeader->ulResdNameTblOfs
    17061757                                            + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller]
     
    17131764                // whose offset is _from the begining of the file_
    17141765
    1715                 ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     1766                ENSURE_SAFE(DosSetFilePtr(hfExe,
    17161767                                          pExec->pLXHeader->ulNonResdNameTblOfs,
    17171768                                          FILE_BEGIN,
     
    17501801                // we now scan the resident name table entries
    17511802
    1752                 ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     1803                ENSURE_SAFE(DosSetFilePtr(hfExe,
    17531804                                          pExec->pNEHeader->usResdNameTblOfs
    17541805                                            + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller]
     
    17611812                // whose offset is _from the begining of the file_
    17621813
    1763                 ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     1814                ENSURE_SAFE(DosSetFilePtr(hfExe,
    17641815                                          pExec->pNEHeader->ulNonResdTblOfs,
    17651816                                          FILE_BEGIN,
     
    18421893        PFSYSRESOURCE   paResources = NULL;
    18431894
     1895        HFILE hfExe = pExec->pFile->hf;
    18441896        ULONG           ulNewHeaderOfs = 0; // V0.9.12 (2001-05-03) [umoeller]
    18451897
     
    18861938                memset(paResources, 0, cb); // V0.9.9 (2001-04-03) [umoeller]
    18871939
    1888                 ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     1940                ENSURE_SAFE(DosSetFilePtr(hfExe,
    18891941                                          pLXHeader->ulResTblOfs
    18901942                                            + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller]
     
    18941946                for (i = 0; i < cResources; i++)
    18951947                {
    1896                     ENSURE_SAFE(DosRead(pExec->hfExe, &rs, 14, &ulDummy));
     1948                    ENSURE_SAFE(DosRead(hfExe, &rs, 14, &ulDummy));
    18971949
    18981950                    paResources[i].ulID = rs.name;
     
    19121964                                          * (paResources[i].ulFlag - 1));
    19131965
    1914                     ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     1966                    ENSURE_SAFE(DosSetFilePtr(hfExe,
    19151967                                              ulOfsThis,
    19161968                                              FILE_BEGIN,
    19171969                                              &ulDummy));
    19181970
    1919                     ENSURE_SAFE(DosRead(pExec->hfExe, &ot, sizeof(ot), &ulDummy));
     1971                    ENSURE_SAFE(DosRead(hfExe, &ot, sizeof(ot), &ulDummy));
    19201972
    19211973                    paResources[i].ulFlag  = ((ot.o32_flags & OBJWRITE)
     
    19682020                    // we first read the resources IDs and types
    19692021
    1970                     ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     2022                    ENSURE_SAFE(DosSetFilePtr(hfExe,
    19712023                                              pNEHeader->usResTblOfs
    19722024                                                + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller]
     
    19762028                    for (i = 0; i < cResources; i++)
    19772029                    {
    1978                         ENSURE_SAFE(DosRead(pExec->hfExe, &rti, sizeof(rti), &ulDummy));
     2030                        ENSURE_SAFE(DosRead(hfExe, &rti, sizeof(rti), &ulDummy));
    19792031
    19802032                        paResources[i].ulID = rti.name;
     
    19862038                    for (i = 0; i < cResources; i++)
    19872039                    {
    1988                         ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     2040                        ENSURE_SAFE(DosSetFilePtr(hfExe,
    19892041                                                  ulNewHeaderOfs // V0.9.12 (2001-05-03) [umoeller]
    19902042                                                    + pNEHeader->usSegTblOfs
     
    19962048                                                    &ulDummy));
    19972049
    1998                         ENSURE_SAFE(DosRead(pExec->hfExe, &ns, sizeof(ns), &ulDummy));
     2050                        ENSURE_SAFE(DosRead(hfExe, &ns, sizeof(ns), &ulDummy));
    19992051
    20002052                        paResources[i].ulSize = ns.ns_cbseg;
     
    20132065                ULONG  ulDummy;
    20142066
    2015                 ENSURE(DosSetFilePtr(pExec->hfExe,
     2067                ENSURE(DosSetFilePtr(hfExe,
    20162068                                     pNEHeader->usResTblOfs
    20172069                                       + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller]
     
    20192071                                     &ulDummy));
    20202072
    2021                 ENSURE(DosRead(pExec->hfExe,
     2073                ENSURE(DosRead(hfExe,
    20222074                               &usAlignShift,
    20232075                               sizeof(usAlignShift),
     
    20292081                    USHORT usCount;
    20302082
    2031                     ENSURE(DosRead(pExec->hfExe,
     2083                    ENSURE(DosRead(hfExe,
    20322084                                   &usTypeID,
    20332085                                   sizeof(usTypeID),
     
    20372089                        break;
    20382090
    2039                     ENSURE(DosRead(pExec->hfExe,
     2091                    ENSURE(DosRead(hfExe,
    20402092                                   &usCount,
    20412093                                   sizeof(usCount),
    20422094                                   &ulDummy));
    20432095
    2044                     ENSURE(DosSetFilePtr(pExec->hfExe,
     2096                    ENSURE(DosSetFilePtr(hfExe,
    20452097                                         sizeof(ULONG),
    20462098                                         FILE_CURRENT,
     
    20502102
    20512103                    // first pass, skip NAMEINFO table
    2052                     ENSURE(DosSetFilePtr(pExec->hfExe,
     2104                    ENSURE(DosSetFilePtr(hfExe,
    20532105                                         usCount*6*sizeof(USHORT),
    20542106                                         FILE_CURRENT,
     
    20672119                    memset(paResources, 0, cb);
    20682120
    2069                     ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     2121                    ENSURE_SAFE(DosSetFilePtr(hfExe,
    20702122                                              pNEHeader->usResTblOfs
    20712123                                                + ulNewHeaderOfs,
     
    20732125                                              &ulDummy));
    20742126
    2075                     ENSURE_SAFE(DosRead(pExec->hfExe,
     2127                    ENSURE_SAFE(DosRead(hfExe,
    20762128                                        &usAlignShift,
    20772129                                        sizeof(usAlignShift),
     
    20842136                        int i;
    20852137
    2086                         ENSURE_SAFE(DosRead(pExec->hfExe,
     2138                        ENSURE_SAFE(DosRead(hfExe,
    20872139                                            &usTypeID,
    20882140                                            sizeof(usTypeID),
     
    20922144                            break;
    20932145
    2094                         ENSURE_SAFE(DosRead(pExec->hfExe,
     2146                        ENSURE_SAFE(DosRead(hfExe,
    20952147                                            &usCount,
    20962148                                            sizeof(usCount),
    20972149                                            &ulDummy));
    20982150
    2099                         ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     2151                        ENSURE_SAFE(DosSetFilePtr(hfExe,
    21002152                                                  sizeof(ULONG),
    21012153                                                  FILE_CURRENT,
     
    21092161                                   usID;
    21102162
    2111                             ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     2163                            ENSURE_SAFE(DosSetFilePtr(hfExe,
    21122164                                                      sizeof(USHORT),
    21132165                                                      FILE_CURRENT,
    21142166                                                      &ulDummy));
    21152167
    2116                             ENSURE_SAFE(DosRead(pExec->hfExe,
     2168                            ENSURE_SAFE(DosRead(hfExe,
    21172169                                                &usLength,
    21182170                                                sizeof(USHORT),
    21192171                                                &ulDummy));
    2120                             ENSURE_SAFE(DosRead(pExec->hfExe,
     2172                            ENSURE_SAFE(DosRead(hfExe,
    21212173                                                &usFlags,
    21222174                                                sizeof(USHORT),
    21232175                                                &ulDummy));
    2124                             ENSURE_SAFE(DosRead(pExec->hfExe,
     2176                            ENSURE_SAFE(DosRead(hfExe,
    21252177                                                &usID,
    21262178                                                sizeof(USHORT),
    21272179                                                &ulDummy));
    21282180
    2129                             ENSURE_SAFE(DosSetFilePtr(pExec->hfExe,
     2181                            ENSURE_SAFE(DosSetFilePtr(hfExe,
    21302182                                                      2*sizeof(USHORT),
    21312183                                                      FILE_CURRENT,
     
    22342286    else
    22352287    {
     2288        PXFILE pFile = pExec->pFile;
    22362289        ULONG ulNewHeaderOfs = 0;
    22372290        ULONG cb;
     
    22462299                                        (PBYTE*)&pExec->pRsTbl,
    22472300                                        &cb)))
    2248              && (!(arc = doshReadAt(pExec->hfExe,
     2301             && (!(arc = doshReadAt(pFile,
    22492302                                    pLXHeader->ulResTblOfs
    22502303                                      + ulNewHeaderOfs,
    2251                                     FILE_BEGIN,
    22522304                                    &cb,
    22532305                                    (PBYTE)pExec->pRsTbl)))
     
    22592311                                            (PBYTE*)&pExec->pObjTbl,
    22602312                                            &cb)))
    2261                  && (!(arc = doshReadAt(pExec->hfExe,
     2313                 && (!(arc = doshReadAt(pFile,
    22622314                                        pLXHeader->ulObjTblOfs
    22632315                                          + ulNewHeaderOfs,
    2264                                         FILE_BEGIN,
    22652316                                        &cb,
    22662317                                        (PBYTE)pExec->pObjTbl)))
     
    22722323                                                (PBYTE*)&pExec->pObjPageTbl,
    22732324                                                &cb)))
    2274                      && (!(arc = doshReadAt(pExec->hfExe,
     2325                     && (!(arc = doshReadAt(pFile,
    22752326                                            pLXHeader->ulObjPageTblOfs
    22762327                                              + ulNewHeaderOfs,
    2277                                             FILE_BEGIN,
    22782328                                            &cb,
    22792329                                            (PBYTE)pExec->pObjPageTbl)))
     
    23412391    else
    23422392    {
     2393        PXFILE pFile = pExec->pFile;
    23432394        ULONG ulNewHeaderOfs = 0;
    23442395        ULONG cb;
     
    23532404                                        (PBYTE*)&pExec->paOS2NEResTblEntry,
    23542405                                        &cb)))
    2355              && (!(arc = doshReadAt(pExec->hfExe,
     2406             && (!(arc = doshReadAt(pFile,
    23562407                                    pNEHeader->usResTblOfs
    23572408                                      + ulNewHeaderOfs,
    2358                                     FILE_BEGIN,
    23592409                                    &cb,
    23602410                                    (PBYTE)pExec->paOS2NEResTblEntry)))
     
    23662416                                            (PBYTE*)&pExec->paOS2NESegments,
    23672417                                            &cb)))
    2368                  && (!(arc = doshReadAt(pExec->hfExe,
     2418                 && (!(arc = doshReadAt(pFile,
    23692419                                        pNEHeader->usResTblOfs
    23702420                                          + ulNewHeaderOfs
    23712421                                          - cb, // pNEHeader->usResSegmCount * sizeof(struct new_seg)
    2372                                         FILE_BEGIN,
    23732422                                        &cb,
    23742423                                        (PBYTE)pExec->paOS2NESegments)))
     
    24612510        }
    24622511
    2463         if (pExec->hfExe)
    2464             arc = DosClose(pExec->hfExe);
     2512        doshClose(&pExec->pFile);
    24652513
    24662514        free(pExec);
     
    41134161    }
    41144162}
     4163
     4164/*
     4165 *@@category: Helpers\Control program helpers\Wildcard matching
     4166 *      See doshMatch.
     4167 */
     4168
     4169/* ******************************************************************
     4170 *
     4171 *   Wildcard matching
     4172 *
     4173 ********************************************************************/
     4174
     4175/*
     4176 * PerformMatch:
     4177 *      compares a single path component. The input strings must
     4178 *      not have slashes or backslashes in them.
     4179 *
     4180 *      fHasDot must be true if pName contains at least one dot.
     4181 *
     4182 *      Note that this function is recursive.
     4183 */
     4184
     4185BOOL PerformMatch(PCSZ pMask,
     4186                  PCSZ pName,
     4187                  int fHasDot)
     4188{
     4189    while (TRUE)
     4190    {
     4191        // go thru the pMask char by char
     4192        switch (*pMask)
     4193        {
     4194            case 0:
     4195                // if we've reached the end of the mask,
     4196                // we better have the end of the name too
     4197                if (*pName == 0)
     4198                    return TRUE;
     4199                return FALSE;
     4200
     4201            case '?':
     4202                // a question mark matches one single character;
     4203                // it does _not_ match a dot;
     4204                // at the end of the component, it also matches
     4205                // no characters
     4206                if (    (*pName != '.')
     4207                     && (*pName != 0)
     4208                   )
     4209                    ++pName;
     4210                ++pMask;
     4211            break;
     4212
     4213            case '*':
     4214                // asterisk matches zero or more characters
     4215
     4216                // skip extra asterisks
     4217                do
     4218                {
     4219                    ++pMask;
     4220                } while (*pMask == '*');
     4221
     4222                // pMask points to after '*';
     4223                // pName is unchanged... so for each pName
     4224                // that follows, check if it matches
     4225                while (TRUE)
     4226                {
     4227                    if (PerformMatch(pMask, pName, fHasDot))
     4228                        // the remainder matched:
     4229                        // then everything matches
     4230                        return TRUE;
     4231
     4232                    if (*pName == 0)
     4233                        return FALSE;
     4234
     4235                    // didn't match: try next pName
     4236                    ++pName;
     4237                }
     4238
     4239            case '.':
     4240                // a dot matches a dot only, even if the name doesn't
     4241                // have one at the end
     4242                ++pMask;
     4243                if (*pName == '.')
     4244                    ++pName;
     4245                else if (    (fHasDot)
     4246                          || (*pName != 0)
     4247                        )
     4248                    return FALSE;
     4249            break;
     4250
     4251            default:
     4252                if (*pMask++ != *pName++)
     4253                    return FALSE;
     4254            break;
     4255        }
     4256    }
     4257}
     4258
     4259/*
     4260 *@@ doshMatch:
     4261 *      this matches '*' and '?' wildcards, similar to what
     4262 *      DosEditName does. It returns TRUE if the given name
     4263 *      matches the given mask.
     4264 *
     4265 *      However, this does not require a file to be present, but
     4266 *      works on strings only.
     4267 *
     4268 *      This accepts both short and fully qualified masks and
     4269 *      names, but the following rules apply:
     4270 *
     4271 *      --  Either both the mask and the name must be fully
     4272 *          qualified, or both must not. Otherwise the match fails.
     4273 *
     4274 *      --  If fully qualified, only the last component may contain
     4275 *          wildcards.
     4276 *
     4277 *      --  This compares without respect to case always.
     4278 *
     4279 *      --  As opposed to the WPS, this handles multiple dots in
     4280 *          filenames correctly. For example, the WPS will not
     4281 *          match "*.ZIP" against "whatever-0.9.3.zip", but this
     4282 *          one will.
     4283 *
     4284 *      This replaces strhMatchOS2 which has been removed with
     4285 *      V0.9.16 and is a lot faster than the old code, which has
     4286 *      been completely rewritten.
     4287 *
     4288 *@@added V0.9.16 (2002-01-01) [umoeller]
     4289 */
     4290
     4291BOOL doshMatch(const char *pcszMask,     // in: mask (e.g. "*.txt")
     4292               const char *pcszName)     // in: string to check (e.g. "test.txt")
     4293{
     4294    BOOL    brc = FALSE;
     4295
     4296    int     iMaskDrive = -1,
     4297            iNameDrive = -1;
     4298
     4299    ULONG   cbMask = strlen(pcszMask),
     4300            cbName = strlen(pcszName);
     4301    PSZ     pszMask = (PSZ)_alloca(cbMask + 1),
     4302            pszName = (PSZ)_alloca(cbName + 1);
     4303
     4304    PCSZ    pLastMaskComponent,
     4305            pLastNameComponent;
     4306
     4307    ULONG   cbMaskPath = 0,
     4308            cbNamePath = 0;
     4309
     4310    CHAR    c;
     4311
     4312    memcpy(pszMask, pcszMask, cbMask + 1);
     4313    nlsUpper(pszMask, cbMask);
     4314    memcpy(pszName, pcszName, cbName + 1);
     4315    nlsUpper(pszName, cbName);
     4316
     4317    if (pLastMaskComponent = strrchr(pszMask, '\\'))
     4318    {
     4319        // length of path component
     4320        cbMaskPath = pLastMaskComponent - pszMask;
     4321        pLastMaskComponent++;
     4322    }
     4323    else
     4324        pLastMaskComponent = pszMask;
     4325
     4326    if (pLastNameComponent = strrchr(pszName, '\\'))
     4327    {
     4328        // length of path component
     4329        cbNamePath = pLastNameComponent - pszName;
     4330        pLastNameComponent++;
     4331    }
     4332    else
     4333        pLastNameComponent = pszName;
     4334
     4335    // compare paths; if the lengths are different
     4336    // or memcmp fails, we can't match
     4337    if (    (cbMaskPath == cbNamePath)      // can both be null
     4338         && (    (cbMaskPath == 0)
     4339              || (!memcmp(pszMask, pszName, cbMaskPath))
     4340            )
     4341       )
     4342    {
     4343        // alright, paths match:
     4344        brc = PerformMatch(pLastMaskComponent,
     4345                           pLastNameComponent,
     4346                           // has dot?
     4347                           (strchr(pLastNameComponent, '.') != NULL));
     4348
     4349    }
     4350
     4351    return brc;
     4352}
     4353
     4354
Note: See TracChangeset for help on using the changeset viewer.