Changeset 141


Ignore:
Timestamp:
Feb 14, 2002, 7:55:57 AM (24 years ago)
Author:
umoeller
Message:

Buncha fixes, plus Paul's screen wrap feature.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/helpers/linklist.h

    r113 r141  
    166166    typedef LSTCLEAR *PLSTCLEAR;
    167167
    168     long XWPENTRY lstCountItems(PLINKLIST pList);
    169     typedef long XWPENTRY LSTCOUNTITEMS(PLINKLIST pList);
     168    long XWPENTRY lstCountItems(const LINKLIST *pList);
     169    typedef long XWPENTRY LSTCOUNTITEMS(const LINKLIST *pList);
    170170    typedef LSTCOUNTITEMS *PLSTCOUNTITEMS;
    171171
    172     PLISTNODE XWPENTRY lstQueryFirstNode(PLINKLIST pList);
     172    PLISTNODE XWPENTRY lstQueryFirstNode(const LINKLIST *pList);
    173173    typedef PLISTNODE XWPENTRY LSTQUERYFIRSTNODE(PLINKLIST pList);
    174174    typedef LSTQUERYFIRSTNODE *PLSTQUERYFIRSTNODE;
    175175
    176     PLISTNODE XWPENTRY lstQueryLastNode(PLINKLIST pList);
     176    PLISTNODE XWPENTRY lstQueryLastNode(const LINKLIST *pList);
    177177    typedef PLISTNODE XWPENTRY LSTQUERYLASTNODE(PLINKLIST pList);
    178178    typedef LSTQUERYLASTNODE *PLSTQUERYLASTNODE;
  • trunk/src/helpers/apps.c

    r140 r141  
    829829
    830830/*
     831 *@@ strhSize:
     832 *      returns the size of the given string, which
     833 *      is the memory required to allocate a copy,
     834 *      including the null terminator.
     835 *
     836 *      Returns 0 if pcsz is NULL or points to a
     837 *      null character.
     838 *
     839 *@@added V0.9.18 (2002-02-13) [umoeller]
     840 */
     841
     842ULONG strhSize(PCSZ pcsz)
     843{
     844    if (pcsz && *pcsz)
     845        return (strlen(pcsz) + 1);
     846
     847    return (0);
     848}
     849
     850/*
    831851 *@@ appQueryDefaultWin31Environment:
    832852 *      returns the default Win-OS/2 3.1 environment
     
    873893
    874894    return (pszReturn);
     895}
     896
     897/*
     898 *@@ CallWinStartApp:
     899 *      wrapper around WinStartApp which copies all the
     900 *      parameters into a contiguous block of tiled memory.
     901 *      This might fix some of the problems with truncated
     902 *      environments we were having.
     903 *
     904 *@@added V0.9.18 (2002-02-13) [umoeller]
     905 */
     906
     907APIRET CallWinStartApp(HAPP *phapp,            // out: application handle if NO_ERROR is returned
     908                       HWND hwndNotify,        // in: notify window or NULLHANDLE
     909                       const PROGDETAILS *pcProgDetails, // in: program spec (req.)
     910                       PCSZ pcszParamsPatched)
     911{
     912    ULONG   cb,
     913            cbTitle,
     914            cbExecutable,
     915            cbParameters,
     916            cbStartupDir,
     917            cbIcon,
     918            cbEnvironment;
     919
     920    APIRET  arc = NO_ERROR;
     921
     922    /*
     923    if (WinMessageBox(HWND_DESKTOP,
     924                      NULLHANDLE,
     925                      (ProgDetails.pszExecutable) ? ProgDetails.pszExecutable : "NULL",
     926                      "Start?",
     927                      0,
     928                      MB_YESNO | MB_MOVEABLE)
     929              != MBID_YES)
     930        return (ERROR_INTERRUPT);
     931    */
     932
     933    // allocate a chunk of tiled memory from OS/2 to make sure
     934    // this is aligned on a 64K memory... otherwise we keep getting
     935    // hangs if this is memory that was allocated by some other thread
     936    cb = sizeof(PROGDETAILS);
     937    if (cbTitle = strhSize(pcProgDetails->pszTitle))
     938        cb += cbTitle;
     939    if (cbExecutable = strhSize(pcProgDetails->pszExecutable))
     940        cb += cbExecutable;
     941    if (cbParameters = strhSize(pcProgDetails->pszParameters))
     942        cb += cbParameters;
     943    if (cbStartupDir = strhSize(pcProgDetails->pszStartupDir))
     944        cb += cbStartupDir;
     945    if (cbIcon = strhSize(pcProgDetails->pszIcon))
     946        cb += cbIcon;
     947    if (cbEnvironment = appQueryEnvironmentLen(pcProgDetails->pszEnvironment))
     948        cb += cbEnvironment;
     949
     950    if (cb > 60000)     // to be on the safe side
     951        arc = ERROR_BAD_ENVIRONMENT; // 10;
     952    else
     953    {
     954        PPROGDETAILS pNewProgDetails;
     955        if (!(arc = DosAllocMem((PVOID*)&pNewProgDetails,
     956                                cb,
     957                                PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE)))
     958        {
     959            // alright, copy stuff
     960            PBYTE pThis;
     961
     962            memset(pNewProgDetails, 0, sizeof(PROGDETAILS));
     963
     964            pNewProgDetails->Length = sizeof(PROGDETAILS);
     965            pNewProgDetails->progt.progc = pcProgDetails->progt.progc;
     966            pNewProgDetails->progt.fbVisible = pcProgDetails->progt.fbVisible;
     967            memcpy(&pNewProgDetails->swpInitial, &pcProgDetails->swpInitial, sizeof(SWP));
     968
     969            pThis = (PBYTE)(pNewProgDetails + 1);
     970
     971            if (cbTitle)
     972            {
     973                memcpy(pThis, pcProgDetails->pszTitle, cbTitle);
     974                pNewProgDetails->pszTitle = pThis;
     975                pThis += cbTitle;
     976            }
     977
     978            if (cbExecutable)
     979            {
     980                memcpy(pThis, pcProgDetails->pszExecutable, cbExecutable);
     981                pNewProgDetails->pszExecutable = pThis;
     982                pThis += cbExecutable;
     983            }
     984
     985            if (cbParameters)
     986            {
     987                memcpy(pThis, pcProgDetails->pszParameters, cbParameters);
     988                pNewProgDetails->pszParameters = pThis;
     989                pThis += cbParameters;
     990            }
     991
     992            if (cbStartupDir)
     993            {
     994                memcpy(pThis, pcProgDetails->pszStartupDir, cbStartupDir);
     995                pNewProgDetails->pszStartupDir = pThis;
     996                pThis += cbStartupDir;
     997            }
     998
     999            if (cbIcon)
     1000            {
     1001                memcpy(pThis, pcProgDetails->pszIcon, cbIcon);
     1002                pNewProgDetails->pszIcon = pThis;
     1003                pThis += cbIcon;
     1004            }
     1005
     1006            if (cbEnvironment)
     1007            {
     1008                memcpy(pThis, pcProgDetails->pszEnvironment, cbEnvironment);
     1009                pNewProgDetails->pszEnvironment = pThis;
     1010                pThis += cbEnvironment;
     1011            }
     1012
     1013            _Pmpf((__FUNCTION__ ": progt.progc: %d", pNewProgDetails->progt.progc));
     1014            _Pmpf(("    progt.fbVisible: 0x%lX", pNewProgDetails->progt.fbVisible));
     1015            _Pmpf(("    progt.pszTitle: \"%s\"", (pNewProgDetails->pszTitle) ? pNewProgDetails->pszTitle : "NULL"));
     1016            _Pmpf(("    exec: \"%s\"", (pNewProgDetails->pszExecutable) ? pNewProgDetails->pszExecutable : "NULL"));
     1017            _Pmpf(("    params: \"%s\"", (pNewProgDetails->pszParameters) ? pNewProgDetails->pszParameters : "NULL"));
     1018            _Pmpf(("    startup: \"%s\"", (pNewProgDetails->pszStartupDir) ? pNewProgDetails->pszStartupDir : "NULL"));
     1019            _Pmpf(("    pszIcon: \"%s\"", (pNewProgDetails->pszIcon) ? pNewProgDetails->pszIcon : "NULL"));
     1020            _Pmpf(("    environment: "));
     1021            {
     1022                PSZ pszThis = pNewProgDetails->pszEnvironment;
     1023                while (pszThis && *pszThis)
     1024                {
     1025                    _Pmpf(("      \"%s\"", pszThis));
     1026                    pszThis += strlen(pszThis) + 1;
     1027                }
     1028            }
     1029
     1030            _Pmpf(("    swpInitial.fl = 0x%lX, x = %d, y = %d, cx = %d, cy = %d:",
     1031                        pNewProgDetails->swpInitial.fl,
     1032                        pNewProgDetails->swpInitial.x,
     1033                        pNewProgDetails->swpInitial.y,
     1034                        pNewProgDetails->swpInitial.cx,
     1035                        pNewProgDetails->swpInitial.cy));
     1036            _Pmpf(("    behind = %d, hwnd = %d, res1 = %d, res2 = %d",
     1037                        pNewProgDetails->swpInitial.hwndInsertBehind,
     1038                        pNewProgDetails->swpInitial.hwnd,
     1039                        pNewProgDetails->swpInitial.ulReserved1,
     1040                        pNewProgDetails->swpInitial.ulReserved2));
     1041
     1042            if (!(*phapp = WinStartApp(hwndNotify,
     1043                                                // receives WM_APPTERMINATENOTIFY
     1044                                       pNewProgDetails,
     1045                                       pNewProgDetails->pszParameters,
     1046                                       NULL,            // "reserved", PMREF says...
     1047                                       SAF_INSTALLEDCMDLINE)))
     1048                                            // we MUST use SAF_INSTALLEDCMDLINE
     1049                                            // or no Win-OS/2 session will start...
     1050                                            // whatever is going on here... Warp 4 FP11
     1051
     1052                                            // do not use SAF_STARTCHILDAPP, or the
     1053                                            // app will be terminated automatically
     1054                                            // when the WPS terminates!
     1055            {
     1056                // cannot start app:
     1057                // _Pmpf((__FUNCTION__ ": WinStartApp failed"));
     1058                arc = ERROR_FILE_NOT_FOUND;
     1059                // unfortunately WinStartApp doesn't
     1060                // return meaningful codes like DosStartSession, so
     1061                // try to see what happened
     1062                /*
     1063                switch (ERRORIDERROR(WinGetLastError(0)))
     1064                {
     1065                    case PMERR_DOS_ERROR: //  (0x1200)
     1066                    {
     1067                        arc = ERROR_FILE_NOT_FOUND;
     1068
     1069                        // this is probably the case where the module
     1070                        // couldn't be loaded, so try DosStartSession
     1071                        // to get a meaningful return code... note that
     1072                        // this cannot handle hwndNotify then
     1073                        RESULTCODES result;
     1074                        arc = DosExecPgm(pszFailingName,
     1075                                         cbFailingName,
     1076                                         EXEC_ASYNC,
     1077                                         NULL, // ProgDetails.pszParameters,
     1078                                         NULL, // ProgDetails.pszEnvironment,
     1079                                         &result,
     1080                                         ProgDetails.pszExecutable);
     1081                        ULONG sid, pid;
     1082                        STARTDATA   SData;
     1083                        SData.Length  = sizeof(STARTDATA);
     1084                        SData.Related = SSF_RELATED_CHILD; //INDEPENDENT;
     1085                        SData.FgBg    = SSF_FGBG_FORE;
     1086                        SData.TraceOpt = SSF_TRACEOPT_NONE;
     1087
     1088                        SData.PgmTitle = ProgDetails.pszTitle;
     1089                        SData.PgmName = ProgDetails.pszExecutable;
     1090                        SData.PgmInputs = ProgDetails.pszParameters;
     1091
     1092                        SData.TermQ = NULL;
     1093                        SData.Environment = ProgDetails.pszEnvironment;
     1094                        SData.InheritOpt = SSF_INHERTOPT_PARENT;    // ignored
     1095                        SData.SessionType = SSF_TYPE_DEFAULT;
     1096                        SData.IconFile = 0;
     1097                        SData.PgmHandle = 0;
     1098
     1099                        SData.PgmControl = SSF_CONTROL_VISIBLE;
     1100
     1101                        SData.InitXPos  = 30;
     1102                        SData.InitYPos  = 40;
     1103                        SData.InitXSize = 200;
     1104                        SData.InitYSize = 140;
     1105                        SData.Reserved = 0;
     1106                        SData.ObjectBuffer  = pszFailingName;
     1107                        SData.ObjectBuffLen = cbFailingName;
     1108
     1109                        arc = DosStartSession(&SData, &sid, &pid);
     1110                    }
     1111                    break;
     1112
     1113                    case PMERR_INVALID_APPL: //  (0x1530)
     1114                            // Attempted to start an application whose type is not
     1115                            // recognized by OS/2.
     1116                        arc = ERROR_INVALID_EXE_SIGNATURE;
     1117                    break;
     1118
     1119                    case PMERR_INVALID_PARAMETERS: //  (0x1208)
     1120                            // An application parameter value is invalid for
     1121                            // its converted PM type. For  example: a 4-byte
     1122                            // value outside the range -32 768 to +32 767 cannot be
     1123                            // converted to a SHORT, and a negative number cannot
     1124                            // be converted to a ULONG or USHORT.
     1125                        arc = ERROR_INVALID_DATA;
     1126                    break;
     1127
     1128                    case PMERR_STARTED_IN_BACKGROUND: //  (0x1532)
     1129                            // The application started a new session in the
     1130                            // background.
     1131                        arc = ERROR_SMG_START_IN_BACKGROUND;
     1132                    break;
     1133
     1134                    case PMERR_INVALID_WINDOW: // (0x1206)
     1135                            // The window specified with a Window List call
     1136                            // is not a valid frame window.
     1137
     1138                    default:
     1139                        arc = ERROR_BAD_FORMAT;
     1140                    break;
     1141                }
     1142                */
     1143            }
     1144
     1145            DosFreeMem(pNewProgDetails);
     1146        }
     1147    }
     1148
     1149    return (arc);
    8751150}
    8761151
     
    9771252 *@@changed V0.9.16 (2002-01-04) [umoeller]: removed error report if startup directory was drive letter only
    9781253 *@@changed V0.9.16 (2002-01-04) [umoeller]: added more detailed error reports and *FailingName params
     1254 *@@changed V0.9.18 (2002-02-13) [umoeller]: added CallWinStartApp to fix possible memory problems
    9791255 */
    9801256
     
    12501526                ProgDetails.pszParameters = strParamsPatched.psz;
    12511527
    1252                 /* _Pmpf((__FUNCTION__ ": progt.progc: %d", ProgDetails.progt.progc));
    1253                 _Pmpf(("    progt.fbVisible: 0x%lX", ProgDetails.progt.fbVisible));
    1254                 _Pmpf(("    progt.pszTitle: \"%s\"", (ProgDetails.pszTitle) ? ProgDetails.pszTitle : "NULL"));
    1255                 _Pmpf(("    exec: \"%s\"", (ProgDetails.pszExecutable) ? ProgDetails.pszExecutable : "NULL"));
    1256                 _Pmpf(("    params: \"%s\"", (ProgDetails.pszParameters) ? ProgDetails.pszParameters : "NULL"));
    1257                 _Pmpf(("    startup: \"%s\"", (ProgDetails.pszStartupDir) ? ProgDetails.pszStartupDir : "NULL"));
    1258                 _Pmpf(("    pszIcon: \"%s\"", (ProgDetails.pszIcon) ? ProgDetails.pszIcon : "NULL"));
    1259                 _Pmpf(("    environment: "));
    1260                 {
    1261                     PSZ pszThis = ProgDetails.pszEnvironment;
    1262                     while (pszThis && *pszThis)
    1263                     {
    1264                         _Pmpf(("      \"%s\"", pszThis));
    1265                         pszThis += strlen(pszThis) + 1;
    1266                     }
    1267                 }
    1268                    */
    1269 
    1270                 /* _Pmpf(("    swpInitial.fl = 0x%lX, x = %d, y = %d, cx = %d, cy = %d:",
    1271                             ProgDetails.swpInitial.fl,
    1272                             ProgDetails.swpInitial.x,
    1273                             ProgDetails.swpInitial.y,
    1274                             ProgDetails.swpInitial.cx,
    1275                             ProgDetails.swpInitial.cy));
    1276                 _Pmpf(("    behind = %d, hwnd = %d, res1 = %d, res2 = %d",
    1277                             ProgDetails.swpInitial.hwndInsertBehind,
    1278                             ProgDetails.swpInitial.hwnd,
    1279                             ProgDetails.swpInitial.ulReserved1,
    1280                             ProgDetails.swpInitial.ulReserved2));
    1281                    */
    1282 
    12831528                if (pszFailingName)
    12841529                    strhncpy0(pszFailingName, ProgDetails.pszExecutable, cbFailingName);
    12851530
    1286                 /* if (WinMessageBox(HWND_DESKTOP,
    1287                                   NULLHANDLE,
    1288                                   (ProgDetails.pszExecutable) ? ProgDetails.pszExecutable : "NULL",
    1289                                   "Start?",
    1290                                   0,
    1291                                   MB_YESNO | MB_MOVEABLE)
    1292                           != MBID_YES)
    1293                     arc = ERROR_INTERRUPT;
    1294                 else */
    1295                 {
    1296                     if (!(*phapp = WinStartApp(hwndNotify,
    1297                                                         // receives WM_APPTERMINATENOTIFY
    1298                                                &ProgDetails,
    1299                                                strParamsPatched.psz,
    1300                                                NULL,            // "reserved", PMREF says...
    1301                                                SAF_INSTALLEDCMDLINE)))
    1302                                                     // we MUST use SAF_INSTALLEDCMDLINE
    1303                                                     // or no Win-OS/2 session will start...
    1304                                                     // whatever is going on here... Warp 4 FP11
    1305 
    1306                                                     // do not use SAF_STARTCHILDAPP, or the
    1307                                                     // app will be terminated automatically
    1308                                                     // when the WPS terminates!
    1309                     {
    1310                         // cannot start app:
    1311                         // _Pmpf((__FUNCTION__ ": WinStartApp failed"));
    1312                         arc = ERROR_FILE_NOT_FOUND;
    1313                         // unfortunately WinStartApp doesn't
    1314                         // return meaningful codes like DosStartSession, so
    1315                         // try to see what happened
    1316                         /*
    1317                         switch (ERRORIDERROR(WinGetLastError(0)))
    1318                         {
    1319                             case PMERR_DOS_ERROR: //  (0x1200)
    1320                             {
    1321                                 arc = ERROR_FILE_NOT_FOUND;
    1322 
    1323                                 // this is probably the case where the module
    1324                                 // couldn't be loaded, so try DosStartSession
    1325                                 // to get a meaningful return code... note that
    1326                                 // this cannot handle hwndNotify then
    1327                                 /* RESULTCODES result;
    1328                                 arc = DosExecPgm(pszFailingName,
    1329                                                  cbFailingName,
    1330                                                  EXEC_ASYNC,
    1331                                                  NULL, // ProgDetails.pszParameters,
    1332                                                  NULL, // ProgDetails.pszEnvironment,
    1333                                                  &result,
    1334                                                  ProgDetails.pszExecutable);
    1335                                    */
    1336                                 /* ULONG sid, pid;
    1337                                 STARTDATA   SData;
    1338                                 SData.Length  = sizeof(STARTDATA);
    1339                                 SData.Related = SSF_RELATED_CHILD; //INDEPENDENT;
    1340                                 SData.FgBg    = SSF_FGBG_FORE;
    1341                                 SData.TraceOpt = SSF_TRACEOPT_NONE;
    1342 
    1343                                 SData.PgmTitle = ProgDetails.pszTitle;
    1344                                 SData.PgmName = ProgDetails.pszExecutable;
    1345                                 SData.PgmInputs = ProgDetails.pszParameters;
    1346 
    1347                                 SData.TermQ = NULL;
    1348                                 SData.Environment = ProgDetails.pszEnvironment;
    1349                                 SData.InheritOpt = SSF_INHERTOPT_PARENT;    // ignored
    1350                                 SData.SessionType = SSF_TYPE_DEFAULT;
    1351                                 SData.IconFile = 0;
    1352                                 SData.PgmHandle = 0;
    1353 
    1354                                 SData.PgmControl = SSF_CONTROL_VISIBLE;
    1355 
    1356                                 SData.InitXPos  = 30;
    1357                                 SData.InitYPos  = 40;
    1358                                 SData.InitXSize = 200;
    1359                                 SData.InitYSize = 140;
    1360                                 SData.Reserved = 0;
    1361                                 SData.ObjectBuffer  = pszFailingName;
    1362                                 SData.ObjectBuffLen = cbFailingName;
    1363 
    1364                                 arc = DosStartSession(&SData, &sid, &pid);
    1365                             }
    1366                             break;
    1367 
    1368                             case PMERR_INVALID_APPL: //  (0x1530)
    1369                                     // Attempted to start an application whose type is not
    1370                                     // recognized by OS/2.
    1371                                 arc = ERROR_INVALID_EXE_SIGNATURE;
    1372                             break;
    1373 
    1374                             case PMERR_INVALID_PARAMETERS: //  (0x1208)
    1375                                     // An application parameter value is invalid for
    1376                                     // its converted PM type. For  example: a 4-byte
    1377                                     // value outside the range -32 768 to +32 767 cannot be
    1378                                     // converted to a SHORT, and a negative number cannot
    1379                                     // be converted to a ULONG or USHORT.
    1380                                 arc = ERROR_INVALID_DATA;
    1381                             break;
    1382 
    1383                             case PMERR_STARTED_IN_BACKGROUND: //  (0x1532)
    1384                                     // The application started a new session in the
    1385                                     // background.
    1386                                 arc = ERROR_SMG_START_IN_BACKGROUND;
    1387                             break;
    1388 
    1389                             case PMERR_INVALID_WINDOW: // (0x1206)
    1390                                     // The window specified with a Window List call
    1391                                     // is not a valid frame window.
    1392 
    1393                             default:
    1394                                 arc = ERROR_BAD_FORMAT;
    1395                             break;
    1396                         }
    1397                         */
    1398                     }
    1399                 }
     1531                arc = CallWinStartApp(phapp,
     1532                                      hwndNotify,
     1533                                      &ProgDetails,
     1534                                      strParamsPatched.psz);
    14001535            }
    14011536        }
  • trunk/src/helpers/linklist.c

    r136 r141  
    358358 */
    359359
    360 long lstCountItems(PLINKLIST pList)
     360long lstCountItems(const LINKLIST *pList)
    361361{
    362362    long lCount = -1;
     
    398398 */
    399399
    400 PLISTNODE lstQueryFirstNode(PLINKLIST pList)
     400PLISTNODE lstQueryFirstNode(const LINKLIST *pList)
    401401{
    402402    if (    (pList)
     
    416416 */
    417417
    418 PLISTNODE lstQueryLastNode(PLINKLIST pList)
     418PLISTNODE lstQueryLastNode(const LINKLIST *pList)
    419419{
    420420    if (    (pList)
  • trunk/src/helpers/xstring.c

    r137 r141  
    899899              ULONG ulFirstReplOfs,             // in: ofs of first char to replace
    900900              ULONG cReplLen,                   // in: no. of chars to replace
    901               PCSZ pcszReplaceWith,      // in: string to replace chars with
     901              PCSZ pcszReplaceWith,             // in: string to replace chars with
    902902              ULONG cReplaceWithLen)            // in: length of replacement string
    903903                                                // (this MUST be specified; if 0, chars are removed only)
Note: See TracChangeset for help on using the changeset viewer.