Ignore:
Timestamp:
Jan 19, 2003, 8:42:16 PM (23 years ago)
Author:
umoeller
Message:

First attempt at new container contol.

File:
1 edited

Legend:

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

    r240 r242  
    4545#define INCL_DOSDEVIOCTL
    4646#define INCL_DOSERRORS
     47
     48#define INCL_WINPROGRAMLIST
    4749#include <os2.h>
    4850
     
    835837{
    836838    APIRET      arc = NO_ERROR;
     839    PXFILE      pFile;
     840    ULONG       ulNRNTOfs = 0;
    837841
    838842    if (!pExec)
    839         arc = ERROR_INVALID_PARAMETER;
     843        return ERROR_INVALID_PARAMETER;
     844
     845    pFile = pExec->pFile;
     846    if (pExec->ulExeFormat == EXEFORMAT_LX)
     847    {
     848        // OK, LX format:
     849        // check if we have a non-resident name table
     850        if (pExec->pLXHeader == NULL)
     851            arc = ERROR_INVALID_DATA;
     852        else if (pExec->pLXHeader->ulNonResdNameTblOfs == 0)
     853            arc = ERROR_INVALID_DATA;
     854        else
     855            ulNRNTOfs = pExec->pLXHeader->ulNonResdNameTblOfs;
     856    }
     857    else if (pExec->ulExeFormat == EXEFORMAT_NE)
     858    {
     859        // OK, NE format:
     860        // check if we have a non-resident name table
     861        if (pExec->pNEHeader == NULL)
     862            arc = ERROR_INVALID_DATA;
     863        else if (pExec->pNEHeader->ulNonResdTblOfs == 0)
     864            arc = ERROR_INVALID_DATA;
     865        else
     866            ulNRNTOfs = pExec->pNEHeader->ulNonResdTblOfs;
     867    }
    840868    else
     869        // neither LX nor NE: stop
     870        arc = ERROR_INVALID_EXE_SIGNATURE;
     871
     872    if (    (!arc)
     873         && (ulNRNTOfs)
     874       )
    841875    {
    842         PXFILE      pFile = pExec->pFile;
    843 
    844         ULONG       ulNRNTOfs = 0;
    845 
    846         if (pExec->ulExeFormat == EXEFORMAT_LX)
     876        ULONG       cb = 2000;
     877
     878        PSZ         pszNameTable;
     879
     880        if (!(pszNameTable = (PSZ)malloc(2001)))
     881            arc = ERROR_NOT_ENOUGH_MEMORY;
     882        else
    847883        {
    848             // OK, LX format:
    849             // check if we have a non-resident name table
    850             if (pExec->pLXHeader == NULL)
    851                 arc = ERROR_INVALID_DATA;
    852             else if (pExec->pLXHeader->ulNonResdNameTblOfs == 0)
    853                 arc = ERROR_INVALID_DATA;
    854             else
    855                 ulNRNTOfs = pExec->pLXHeader->ulNonResdNameTblOfs;
    856         }
    857         else if (pExec->ulExeFormat == EXEFORMAT_NE)
    858         {
    859             // OK, NE format:
    860             // check if we have a non-resident name table
    861             if (pExec->pNEHeader == NULL)
    862                 arc = ERROR_INVALID_DATA;
    863             else if (pExec->pNEHeader->ulNonResdTblOfs == 0)
    864                 arc = ERROR_INVALID_DATA;
    865             else
    866                 ulNRNTOfs = pExec->pNEHeader->ulNonResdTblOfs;
    867         }
    868         else
    869             // neither LX nor NE: stop
    870             arc = ERROR_INVALID_EXE_SIGNATURE;
    871 
    872         if (    (!arc)
    873              && (ulNRNTOfs)
    874            )
    875         {
    876             ULONG       cb = 2000;
    877 
    878             PSZ         pszNameTable;
    879 
    880             if (!(pszNameTable = (PSZ)malloc(2001)))
    881                 arc = ERROR_NOT_ENOUGH_MEMORY;
    882             else
     884            // V0.9.16 (2002-01-05) [umoeller]: rewrote the following
     885
     886            // read from offset of non-resident name table
     887            if (!(arc = doshReadAt(pFile,           // file is still open
     888                                   ulNRNTOfs,       // ofs determined above
     889                                   &cb,             // 2000
     890                                   pszNameTable,
     891                                   0)))
    883892            {
    884                 // V0.9.16 (2002-01-05) [umoeller]: rewrote the following
    885 
    886                 // read from offset of non-resident name table
    887                 if (!(arc = doshReadAt(pFile,           // file is still open
    888                                        ulNRNTOfs,       // ofs determined above
    889                                        &cb,             // 2000
    890                                        pszNameTable,
    891                                        0)))
    892                 {
    893                     // the string is in Pascal format, so the
    894                     // first byte has the length
    895                     BYTE bLen;
    896                     if (!(bLen = *pszNameTable))
    897                         // length byte is null:
    898                         arc = ERROR_INVALID_DATA;
     893                // the string is in Pascal format, so the
     894                // first byte has the length
     895                BYTE bLen;
     896                if (!(bLen = *pszNameTable))
     897                    // length byte is null:
     898                    arc = ERROR_INVALID_DATA;
     899                else
     900                {
     901                    // now copy the string
     902                    if (!(pExec->pszDescription = (PSZ)malloc(bLen + 1)))
     903                        arc = ERROR_NOT_ENOUGH_MEMORY;
    899904                    else
    900905                    {
    901                         // now copy the string
    902                         if (!(pExec->pszDescription = (PSZ)malloc(bLen + 1)))
    903                             arc = ERROR_NOT_ENOUGH_MEMORY;
    904                         else
    905                         {
    906                             memcpy(pExec->pszDescription,
    907                                    pszNameTable + 1,    // skip length byte
    908                                    bLen);               // length byte
    909                             // terminate string
    910                             pExec->pszDescription[bLen] = 0;
    911 
    912                             ParseBldLevel(pExec);
    913                         }
     906                        memcpy(pExec->pszDescription,
     907                               pszNameTable + 1,    // skip length byte
     908                               bLen);               // length byte
     909                        // terminate string
     910                        pExec->pszDescription[bLen] = 0;
     911
     912                        ParseBldLevel(pExec);
    914913                    }
    915914                }
    916 
    917                 free(pszNameTable);
    918915            }
     916
     917            free(pszNameTable);
    919918        }
    920     } // end if (!pExec)
     919    }
    921920
    922921    return arc;
     922}
     923
     924/*
     925 *@@ exehQueryProgType:
     926 *      attempts to sets *pulProgType to a PROGTYPE constant.
     927 *
     928 *      Returns:
     929 *
     930 *      --  NO_ERROR
     931 *
     932 *      --  ERROR_INVALID_PARAMETER;
     933 *
     934 *@@added V1.0.1 (2003-01-17) [umoeller]
     935 *@@changed V1.0.1 (2003-01-17) [umoeller]: now correctly returning PROG_PDD/VDD for NE and LX @@fixes 343
     936 */
     937
     938APIRET exehQueryProgType(const EXECUTABLE *pExec,
     939                         PROGCATEGORY *pulProgType)
     940{
     941    APIRET      arc = NO_ERROR;
     942
     943    if (!pExec)
     944        return ERROR_INVALID_PARAMETER;
     945
     946    // now we have the PEXECUTABLE:
     947    // check what we found
     948    switch (pExec->ulOS)
     949    {
     950        case EXEOS_DOS3:
     951        case EXEOS_DOS4:
     952            *pulProgType = PROG_WINDOWEDVDM;
     953        break;
     954
     955        case EXEOS_OS2:
     956            switch (pExec->ulExeFormat)
     957            {
     958                case EXEFORMAT_LX:
     959                    switch (pExec->pLXHeader->ulFlags & E32MODMASK)
     960                    {
     961                        case E32MODPDEV:
     962                            *pulProgType = PROG_PDD;
     963                        break;
     964
     965                        case E32MODVDEV:
     966                            *pulProgType = PROG_VDD;
     967                        break;
     968
     969                        case E32MODDLL:
     970                        case E32MODPROTDLL:
     971                            *pulProgType = PROG_DLL;
     972                        break;
     973
     974                        default:
     975                            // all bits clear: --> real executable
     976                            switch (pExec->pLXHeader->ulFlags & E32APPMASK)
     977                            {
     978                                case E32PMAPI:
     979                                    // _Pmpf(("  LX OS2 PM"));
     980                                    *pulProgType = PROG_PM;
     981                                break;
     982
     983                                case E32PMW:
     984                                    // _Pmpf(("  LX OS2 VIO"));
     985                                    *pulProgType = PROG_WINDOWABLEVIO;
     986                                break;
     987
     988                                case E32NOPMW:
     989                                    // _Pmpf(("  LX OS2 FULLSCREEN"));
     990                                    *pulProgType = PROG_FULLSCREEN;
     991                                break;
     992
     993                                default:
     994                                    // _Pmpf(("  LX OS2 FULLSCREEN"));
     995                                    *pulProgType = PROG_FULLSCREEN;
     996                                break;
     997                            }
     998                        break;      // executable
     999                    }
     1000                break;
     1001
     1002                case EXEFORMAT_NE:
     1003                    if (pExec->fLibrary)
     1004                    {
     1005                        // there is no flag in the NE header for whether
     1006                        // this is a device driver, so rely on extension
     1007                        // V1.0.1 (2003-01-17) [umoeller]
     1008                        PSZ p;
     1009                        if (    (p = doshGetExtension(pExec->pFile->pszFilename))
     1010                             && (    (!stricmp(p, "ADD"))
     1011                                  || (!stricmp(p, "DMD"))
     1012                                  || (!stricmp(p, "FLT"))
     1013                                  || (!stricmp(p, "IFS"))
     1014                                  || (!stricmp(p, "SNP"))
     1015                                  || (!stricmp(p, "SYS"))
     1016                                )
     1017                           )
     1018                            *pulProgType = PROG_PDD;
     1019                                    // there can be no 16-bit VDDs, so this must be a PDD
     1020                        else
     1021                            *pulProgType = PROG_DLL;
     1022                    }
     1023                    else switch (pExec->pNEHeader->usFlags & NEAPPTYP)
     1024                    {
     1025                        case NEWINCOMPAT:
     1026                            // _Pmpf(("  NE OS2 VIO"));
     1027                            *pulProgType = PROG_WINDOWABLEVIO;
     1028                        break;
     1029
     1030                        case NEWINAPI:
     1031                            // _Pmpf(("  NE OS2 PM"));
     1032                            *pulProgType = PROG_PM;
     1033                        break;
     1034
     1035                        case NENOTWINCOMPAT:
     1036                        default:
     1037                            // _Pmpf(("  NE OS2 FULLSCREEN"));
     1038                            *pulProgType = PROG_FULLSCREEN;
     1039                        break;
     1040                    }
     1041                break;
     1042
     1043                case EXEFORMAT_COM:
     1044                    *pulProgType = PROG_WINDOWABLEVIO;
     1045                break;
     1046
     1047                default:
     1048                    arc = ERROR_INVALID_EXE_SIGNATURE;
     1049            }
     1050        break;
     1051
     1052        case EXEOS_WIN16:
     1053        case EXEOS_WIN386:
     1054            // _Pmpf(("  WIN16"));
     1055            *pulProgType = PROG_31_ENHSEAMLESSCOMMON;
     1056        break;
     1057
     1058        case EXEOS_WIN32_GUI:
     1059        case EXEOS_WIN32_CLI:
     1060            // _Pmpf(("  WIN32"));
     1061            *pulProgType = PROG_WIN32;
     1062        break;
     1063
     1064        default:
     1065            arc = ERROR_INVALID_EXE_SIGNATURE;
     1066    }
     1067
     1068    return arc;
     1069}
     1070
     1071/*
     1072 *@@ PROGTYPESTRING:
     1073 *
     1074 *@@added V0.9.16 (2002-01-13) [umoeller]
     1075 */
     1076
     1077typedef struct _PROGTYPESTRING
     1078{
     1079    PROGCATEGORY    progc;
     1080    PCSZ            pcsz;
     1081} PROGTYPESTRING, *PPROGTYPESTRING;
     1082
     1083PROGTYPESTRING G_aProgTypes[] =
     1084    {
     1085        PROG_DEFAULT, "PROG_DEFAULT",
     1086        PROG_FULLSCREEN, "PROG_FULLSCREEN",
     1087        PROG_WINDOWABLEVIO, "PROG_WINDOWABLEVIO",
     1088        PROG_PM, "PROG_PM",
     1089        PROG_GROUP, "PROG_GROUP",
     1090        PROG_VDM, "PROG_VDM",
     1091            // same as PROG_REAL, "PROG_REAL",
     1092        PROG_WINDOWEDVDM, "PROG_WINDOWEDVDM",
     1093        PROG_DLL, "PROG_DLL",
     1094        PROG_PDD, "PROG_PDD",
     1095        PROG_VDD, "PROG_VDD",
     1096        PROG_WINDOW_REAL, "PROG_WINDOW_REAL",
     1097        PROG_30_STD, "PROG_30_STD",
     1098            // same as PROG_WINDOW_PROT, "PROG_WINDOW_PROT",
     1099        PROG_WINDOW_AUTO, "PROG_WINDOW_AUTO",
     1100        PROG_30_STDSEAMLESSVDM, "PROG_30_STDSEAMLESSVDM",
     1101            // same as PROG_SEAMLESSVDM, "PROG_SEAMLESSVDM",
     1102        PROG_30_STDSEAMLESSCOMMON, "PROG_30_STDSEAMLESSCOMMON",
     1103            // same as PROG_SEAMLESSCOMMON, "PROG_SEAMLESSCOMMON",
     1104        PROG_31_STDSEAMLESSVDM, "PROG_31_STDSEAMLESSVDM",
     1105        PROG_31_STDSEAMLESSCOMMON, "PROG_31_STDSEAMLESSCOMMON",
     1106        PROG_31_ENHSEAMLESSVDM, "PROG_31_ENHSEAMLESSVDM",
     1107        PROG_31_ENHSEAMLESSCOMMON, "PROG_31_ENHSEAMLESSCOMMON",
     1108        PROG_31_ENH, "PROG_31_ENH",
     1109        PROG_31_STD, "PROG_31_STD",
     1110
     1111// Warp 4 toolkit defines, whatever these were designed for...
     1112#ifndef PROG_DOS_GAME
     1113    #define PROG_DOS_GAME            (PROGCATEGORY)21
     1114#endif
     1115#ifndef PROG_WIN_GAME
     1116    #define PROG_WIN_GAME            (PROGCATEGORY)22
     1117#endif
     1118#ifndef PROG_DOS_MODE
     1119    #define PROG_DOS_MODE            (PROGCATEGORY)23
     1120#endif
     1121
     1122        PROG_DOS_GAME, "PROG_DOS_GAME",
     1123        PROG_WIN_GAME, "PROG_WIN_GAME",
     1124        PROG_DOS_MODE, "PROG_DOS_MODE",
     1125
     1126        // added this V0.9.16 (2001-12-08) [umoeller]
     1127        PROG_WIN32, "PROG_WIN32"
     1128    };
     1129
     1130/*
     1131 *@@ exehDescribeProgType:
     1132 *      returns a "PROG_*" string for the given
     1133 *      program type. Useful for WPProgram setup
     1134 *      strings and such.
     1135 *
     1136 *@@added V0.9.16 (2001-10-06)
     1137 *@@changed V1.0.1 (2003-01-17) [umoeller]: moved this here from apps.c
     1138 */
     1139
     1140PCSZ exehDescribeProgType(PROGCATEGORY progc)        // in: from PROGDETAILS.progc
     1141{
     1142    ULONG ul;
     1143    for (ul = 0;
     1144         ul < ARRAYITEMCOUNT(G_aProgTypes);
     1145         ul++)
     1146    {
     1147        if (G_aProgTypes[ul].progc == progc)
     1148            return G_aProgTypes[ul].pcsz;
     1149    }
     1150
     1151    return NULL;
    9231152}
    9241153
Note: See TracChangeset for help on using the changeset viewer.