Changeset 43


Ignore:
Timestamp:
Mar 7, 2001, 10:41:07 PM (24 years ago)
Author:
umoeller
Message:

Misc. changes.

Location:
trunk
Files:
5 edited

Legend:

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

    r41 r43  
    330330     *
    331331     ********************************************************************/
     332
     333    APIRET doshFindExecutable(const char *pcszCommand,
     334                              PSZ pszExecutable,
     335                              ULONG cbExecutable,
     336                              const char **papcszExtensions,
     337                              ULONG cExtensions);
    332338
    333339    APIRET doshExecVIO(const char *pcszExecWithArgs,
  • trunk/include/helpers/winh.h

    r41 r43  
    591591
    592592    #ifdef INCL_WINPROGRAMLIST
     593        // additional PROG_* flags for winhQueryAppType
     594        #define PROG_XWP_DLL            998      // dynamic link library
     595
     596        APIRET winhQueryAppType(const char *pcszExecutable,
     597                                PULONG pulDosAppType,
     598                                PULONG pulWinAppType);
     599
    593600        HAPP XWPENTRY winhStartApp(HWND hwndNotify, const PROGDETAILS *pcProgDetails);
    594601    #endif
  • trunk/src/helpers/dosh.c

    r40 r43  
    18741874
    18751875/*
     1876 *@@ doshFindExecutable:
     1877 *      this searches the PATH for the specified pcszCommand
     1878 *      by calling DosSearchPath.
     1879 *
     1880 *      papcszExtensions determines if additional searches are to be
     1881 *      performed if DosSearchPath returns ERROR_FILE_NOT_FOUND.
     1882 *      This must point to an array of strings specifying the extra
     1883 *      extensions to search for.
     1884 *
     1885 *      If both papcszExtensions and cExtensions are null, no
     1886 *      extra searches are performed.
     1887 *
     1888 *      If this returns NO_ERROR, pszExecutable receives
     1889 *      the full path of the executable found by DosSearchPath.
     1890 *      Otherwise ERROR_FILE_NOT_FOUND is returned.
     1891 *
     1892 *      Example:
     1893 *
     1894 +      const char *aExtensions[] = {  "EXE",
     1895 +                                     "COM",
     1896 +                                     "CMD"
     1897 +                                  };
     1898 +      CHAR szExecutable[CCHMAXPATH];
     1899 +      APIRET arc = doshFindExecutable("lvm",
     1900 +                                      szExecutable,
     1901 +                                      sizeof(szExecutable),
     1902 +                                      aExtensions,
     1903 +                                      3);
     1904 *
     1905 *@@added V0.9.9 (2001-03-07) [umoeller]
     1906 */
     1907
     1908APIRET doshFindExecutable(const char *pcszCommand,      // in: command (e.g. "lvm")
     1909                          PSZ pszExecutable,            // out: full path (e.g. "F:\os2\lvm.exe")
     1910                          ULONG cbExecutable,           // in: sizeof (*pszExecutable)
     1911                          const char **papcszExtensions, // in: array of extensions (without dots)
     1912                          ULONG cExtensions)            // in: array item count
     1913{
     1914    APIRET arc = DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT | SEARCH_CUR_DIRECTORY,
     1915                               "PATH",
     1916                               (PSZ)pcszCommand,
     1917                               pszExecutable,
     1918                               cbExecutable);
     1919    if (    (arc == ERROR_FILE_NOT_FOUND)           // not found?
     1920         && (cExtensions)                    // any extra searches wanted?
     1921       )
     1922    {
     1923        // try additional things then
     1924        PSZ psz2 = malloc(strlen(pcszCommand) + 20);
     1925        if (psz2)
     1926        {
     1927            ULONG   ul;
     1928            for (ul = 0;
     1929                 ul < cExtensions;
     1930                 ul++)
     1931            {
     1932                const char *pcszExtThis = papcszExtensions[ul];
     1933                sprintf(psz2, "%s.%s", pcszCommand, pcszExtThis);
     1934                arc = DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT | SEARCH_CUR_DIRECTORY,
     1935                                    "PATH",
     1936                                    psz2,
     1937                                    pszExecutable,
     1938                                    cbExecutable);
     1939                if (arc != ERROR_FILE_NOT_FOUND)
     1940                    break;
     1941            }
     1942
     1943            free(psz2);
     1944        }
     1945        else
     1946            arc = ERROR_NOT_ENOUGH_MEMORY;
     1947    }
     1948
     1949    return (arc);
     1950}
     1951
     1952/*
    18761953 *@@ doshExecVIO:
    18771954 *      executes cmd.exe with the /c parameter
  • trunk/src/helpers/winh.c

    r35 r43  
    4141#define INCL_DOSDEVICES
    4242#define INCL_DOSDEVIOCTL
     43#define INCL_DOSSESMGR
    4344#define INCL_DOSERRORS
    4445
     
    25572558
    25582559/*
     2560 *@@ winhQueryAppType:
     2561 *      returns the Control Program (Dos) and
     2562 *      Win* PROG_* application types for the
     2563 *      specified executable. Essentially, this
     2564 *      is a wrapper around DosQueryAppType.
     2565 *
     2566 *      pcszExecutable must be fully qualified.
     2567 *      You can use doshFindExecutable to qualify
     2568 *      it.
     2569 *
     2570 *      This returns the APIRET of DosQueryAppType.
     2571 *      If this is NO_ERROR; *pulDosAppType receives
     2572 *      the app type of DosQueryAppType. In addition,
     2573 *      *pulWinAppType is set to one of the following:
     2574 *
     2575 *      --  PROG_FULLSCREEN
     2576 *
     2577 *      --  PROG_PDD
     2578 *
     2579 *      --  PROG_VDD
     2580 *
     2581 *      --  PROG_XWP_DLL: new apptype defined in winh.h for
     2582 *          dynamic link libraries.
     2583 *
     2584 *      --  PROG_WINDOWEDVDM
     2585 *
     2586 *      --  PROG_PM
     2587 *
     2588 *      --  PROG_31_ENH
     2589 *
     2590 *      --  PROG_WINDOWABLEVIO
     2591 *
     2592 *@@added V0.9.9 (2001-03-07) [umoeller]
     2593 */
     2594
     2595APIRET winhQueryAppType(const char *pcszExecutable,
     2596                        PULONG pulDosAppType,
     2597                        PULONG pulWinAppType)
     2598{
     2599    APIRET arc = DosQueryAppType((PSZ)pcszExecutable, pulDosAppType);
     2600    if (arc == NO_ERROR)
     2601    {
     2602        ULONG _ulDosAppType = *pulDosAppType;
     2603
     2604        if (_ulDosAppType == 0)
     2605            *pulWinAppType = PROG_FULLSCREEN;
     2606        else if (_ulDosAppType & 0x40)
     2607            *pulWinAppType = PROG_PDD;
     2608        else if (_ulDosAppType & 0x80)
     2609            *pulWinAppType = PROG_VDD;
     2610        else if ((_ulDosAppType & 0xF0) == 0x10)
     2611            // DLL bit set
     2612            *pulWinAppType = PROG_XWP_DLL;
     2613        else if (_ulDosAppType & 0x20)
     2614            // DOS bit set?
     2615            *pulWinAppType = PROG_WINDOWEDVDM;
     2616        else if ((_ulDosAppType & 0x0003) == 0x0003) // "Window-API" == PM
     2617            *pulWinAppType = PROG_PM;
     2618        else if (   ((_ulDosAppType & 0xFFFF) == 0x1000) // windows program (?!?)
     2619                 || ((_ulDosAppType & 0xFFFF) == 0x0400) // windows program (?!?)
     2620                )
     2621            *pulWinAppType = PROG_31_ENH;
     2622        else if ((_ulDosAppType & 0x03) == 0x02)
     2623            *pulWinAppType = PROG_WINDOWABLEVIO;
     2624        else if ((_ulDosAppType & 0x03) == 0x01)
     2625            *pulWinAppType = PROG_FULLSCREEN;
     2626    }
     2627
     2628    return (arc);
     2629}
     2630
     2631/*
    25592632 *@@ winhStartApp:
    25602633 *      wrapper around WinStartApp which fixes the
     
    25692642 *      -- starting ".CMD" and ".BAT" files as
    25702643 *         PROGDETAILS.pszExecutable.
     2644 *
     2645 *      Unless it is "*", PROGDETAILS.pszExecutable must
     2646 *      be a proper file name. The full path may be omitted
     2647 *      if it is on the PATH, but the extension (.EXE etc.)
     2648 *      must be given. You can use doshFindExecutable to
     2649 *      find executables if you don't know the extension.
    25712650 *
    25722651 *      This also handles and merges special and default
     
    28022881            }
    28032882        }
    2804 
    2805         // _Pmpf((__FUNCTION__ ": calling WinStartApp"));
    2806         // _Pmpf(("    exec: %s",
    2807         //             (ProgDetails.pszExecutable)
    2808                         // ? ProgDetails.pszExecutable
    2809                     // : "NULL"));
    2810         // _Pmpf(("    startupDir: %s",
    2811            //      (ProgDetails.pszStartupDir)
    2812               //       ? ProgDetails.pszStartupDir
    2813                  //    : "NULL"));
    2814         // _Pmpf(("    params: %s",
    2815            //      (pszParamsPatched)
    2816               //       ? pszParamsPatched
    2817                  //    : "NULL"));
    2818         // _Pmpf(("    new progc: 0x%lX", ProgDetails.progt.progc));
    28192883
    28202884        ProgDetails.pszParameters = strParamsPatched.psz;
     
    32823346                         ULONG flFrameCreateFlags,  // in: FCF_* flags
    32833347                         ULONG ulFrameStyle,        // in: WS_* flags (e.g. WS_VISIBLE, WS_ANIMATE)
    3284                          const char *pcszFrameTitle,
     3348                         const char *pcszFrameTitle, // in: frame title (title bar)
    32853349                         ULONG ulResourcesID,       // in: according to FCF_* flags
    3286                          const char *pcszClassClient,
    3287                          ULONG flStyleClient,
     3350                         const char *pcszClassClient, // in: client class name
     3351                         ULONG flStyleClient,       // in: client style
    32883352                         ULONG ulID,                // in: frame window ID
    32893353                         PVOID pClientCtlData,      // in: pCtlData structure pointer for client
  • trunk/src/helpers/xstring.c

    r42 r43  
    10831083}
    10841084
     1085// static encoding table for xstrEncode
     1086static PSZ apszEncoding[] =
     1087{
     1088    "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
     1089    "%08", "%09", "%0A", "%0B", "%0C", "%0D", "%0E", "%0F",
     1090    "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",
     1091    "%18", "%19", "%1A", "%1B", "%1C", "%1D", "%1E", "%1F",
     1092    "%20", "%21", "%22", "%23", "%24", "%25", "%26", "%27",
     1093    "%28", "%29", "%2A", "%2B", "%2C", "%2D", "%2E", "%2F",
     1094    "%30", "%31", "%32", "%33", "%34", "%35", "%36", "%37",
     1095    "%38", "%39", "%3A", "%3B", "%3C", "%3D", "%3E", "%3F",
     1096    "%40", "%41", "%42", "%43", "%44", "%45", "%46", "%47",
     1097    "%48", "%49", "%4A", "%4B", "%4C", "%4D", "%4E", "%4F",
     1098    "%50", "%51", "%52", "%53", "%54", "%55", "%56", "%57",
     1099    "%58", "%59", "%5A", "%5B", "%5C", "%5D", "%5E", "%5F",
     1100    "%60", "%61", "%62", "%63", "%64", "%65", "%66", "%67",
     1101    "%68", "%69", "%6A", "%6B", "%6C", "%6D", "%6E", "%6F",
     1102    "%70", "%71", "%72", "%73", "%74", "%75", "%76", "%77",
     1103    "%78", "%79", "%7A", "%7B", "%7C", "%7D", "%7E", "%7F",
     1104    "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",
     1105    "%88", "%89", "%8A", "%8B", "%8C", "%8D", "%8E", "%8F",
     1106    "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",
     1107    "%98", "%99", "%9A", "%9B", "%9C", "%9D", "%9E", "%9F",
     1108    "%A0", "%A1", "%A2", "%A3", "%A4", "%A5", "%A6", "%A7",
     1109    "%A8", "%A9", "%AA", "%AB", "%AC", "%AD", "%AE", "%AF",
     1110    "%B0", "%B1", "%B2", "%B3", "%B4", "%B5", "%B6", "%B7",
     1111    "%B8", "%B9", "%BA", "%BB", "%BC", "%BD", "%BE", "%BF",
     1112    "%C0", "%C1", "%C2", "%C3", "%C4", "%C5", "%C6", "%C7",
     1113    "%C8", "%C9", "%CA", "%CB", "%CC", "%CD", "%CE", "%CF",
     1114    "%D0", "%D1", "%D2", "%D3", "%D4", "%D5", "%D6", "%D7",
     1115    "%D8", "%D9", "%DA", "%DB", "%DC", "%DD", "%DE", "%DF",
     1116    "%E0", "%E1", "%E2", "%E3", "%E4", "%E5", "%E6", "%E7",
     1117    "%E8", "%E9", "%EA", "%EB", "%EC", "%ED", "%EE", "%EF",
     1118    "%F0", "%F1", "%F2", "%F3", "%F4", "%F5", "%F6", "%F7",
     1119    "%F8", "%F9", "%FA", "%FB", "%FC", "%FD", "%FE", "%FF"
     1120};
     1121
    10851122/*
    10861123 *@@ xstrEncode:
     
    11161153 +          S%61mple %63hara%63ters.
    11171154 *
    1118  *      Memory cost: None, except for that of xstrFindReplace.
     1155 *      Memory cost: None, except for that of xstrcpy.
    11191156 *
    11201157 *@@added V0.9.9 (2001-02-28) [umoeller]
     1158 *@@changed V0.9.9 (2001-03-06) [lafaix]: rewritten.
    11211159 */
    11221160
     
    11251163{
    11261164    ULONG ulrc = 0,
    1127           ul;
    1128 
    1129     // now encode the widget setup string...
    1130     for (ul = 0;
    1131          ul < strlen(pcszEncode);
    1132          ul++)
    1133     {
    1134         CHAR        szFind[3] = "?",
    1135                     szReplace[10] = "%xx";
    1136         XSTRING     strFind,
    1137                     strReplace;
    1138         size_t      ShiftTable[256];
    1139         BOOL        fRepeat = FALSE;
    1140         ULONG       ulOfs = 0;
    1141 
    1142         // search string:
    1143         szFind[0] = pcszEncode[ul];
    1144         xstrInitSet(&strFind, szFind);
    1145 
    1146         // replace string: ASCII encoding
    1147         sprintf(szReplace, "%%%lX", pcszEncode[ul]);
    1148         xstrInitSet(&strReplace, szReplace);
    1149 
    1150         // replace all occurences
    1151         while (xstrFindReplace(pxstr,
    1152                                &ulOfs,
    1153                                &strFind,
    1154                                &strReplace,
    1155                                ShiftTable,
    1156                                &fRepeat))
    1157                 ulrc++;
    1158 
    1159     } // for ul; next encoding
     1165          ul,
     1166          ulEncodeLength;
     1167
     1168    if (    (pxstr)
     1169         && (pxstr->ulLength)
     1170         && (pcszEncode)
     1171         && (ulEncodeLength = strlen(pcszEncode)))
     1172    {
     1173        PSZ pszDest = (PSZ)malloc(pxstr->ulLength * 3
     1174                                  + 1),
     1175            pszDestCurr = pszDest;
     1176
     1177        if (pszDest)
     1178        {
     1179            for (ul = 0;
     1180                 ul < pxstr->ulLength;
     1181                 ul++)
     1182            {
     1183                ULONG ulEncode;
     1184
     1185                for (ulEncode = 0;
     1186                     ulEncode < ulEncodeLength;
     1187                     ulEncode++)
     1188                {
     1189                    if (pxstr->psz[ul] == pcszEncode[ulEncode])
     1190                    {
     1191                        // use the static encoding table for speed
     1192                        memcpy(pszDestCurr,
     1193                               apszEncoding[(unsigned char)pcszEncode[ulEncode]],
     1194                               3);
     1195                        pszDestCurr += 3;
     1196                        ulrc++;
     1197                        goto iterate;
     1198                    }
     1199                }
     1200
     1201                *pszDestCurr++ = pxstr->psz[ul];
     1202
     1203                iterate:
     1204                    ;
     1205            }
     1206        }
     1207
     1208        // something was encoded; update pxstr
     1209        if (ulrc)
     1210        {
     1211            *pszDestCurr = 0;
     1212
     1213            xstrcpy(pxstr, pszDest, pszDestCurr-pszDest);
     1214        }
     1215
     1216        free(pszDest);
     1217    }
    11601218
    11611219    return (ulrc);
     
    11741232 *      Returns the no. of encodings replaced.
    11751233 *
    1176  *      Memory cost: Creates a temporary buffer with the
    1177  *      length of pxstr and replaces pxstr with it, if any
    1178  *      encodings were found. In other words, this is
    1179  *      expensive for very large strings.
     1234 *      Memory cost: None.
    11801235 *
    11811236 *@@added V0.9.9 (2001-02-28) [umoeller]
     1237 *@@changed V0.9.9 (2001-03-06) [lafaix]: removed memory allocation
    11821238 */
    11831239
     
    11901246       )
    11911247    {
    1192         ULONG   cbAllocated = pxstr->ulLength + 1;
    1193             // decoded string cannot be longer than source
    1194         PSZ     pszDest = (PSZ)malloc(cbAllocated);
    1195 
    1196         if (pszDest)
     1248        const char  *pSource = pxstr->psz;
     1249        PSZ         pszDest  = (PSZ)pSource,
     1250                    pDest    = (PSZ)pSource;
     1251        CHAR        c;
     1252
     1253        while ((c = *pSource++))
    11971254        {
    1198             const char  *pSource = pxstr->psz;
    1199             PSZ         pDest = pszDest;
    1200 
    1201             CHAR    c;
    1202 
    1203             while ((c = *pSource++))
     1255            // pSource points to next char now
     1256
     1257            if (c == '%')
    12041258            {
    1205                 // pSource points to next char now
    1206 
    1207                 if (c == '%')
     1259                static char ach[] = "0123456789ABCDEF";
     1260
     1261                // convert two chars after '%'
     1262                CHAR        c2,         // first char after '%'     --> hi-nibble
     1263                            c3;         // second char after '%'    --> lo-nibble
     1264                const char  *p2,        // for first char: points into ach or is NULL
     1265                            *p3;        // for second char: points into ach or is NULL
     1266                if (    (c2 = *pSource)
     1267                     && (p2 = strchr(ach, c2))
     1268                     && (c3 = *(pSource + 1))
     1269                     && (p3 = strchr(ach, c3))
     1270                   )
    12081271                {
    1209                     static char ach[] = "0123456789ABCDEF";
    1210 
    1211                     // convert two chars after '%'
    1212                     CHAR        c2,         // first char after '%'     --> hi-nibble
    1213                                 c3;         // second char after '%'    --> lo-nibble
    1214                     const char  *p2,        // for first char: points into ach or is NULL
    1215                                 *p3;        // for second char: points into ach or is NULL
    1216                     if (    (c2 = *pSource)
    1217                          && (p2 = strchr(ach, c2))
    1218                          && (c3 = *(pSource + 1))
    1219                          && (p3 = strchr(ach, c3))
    1220                        )
    1221                     {
    1222                         // both chars after '%' were valid:
    1223                         *pDest++ =    // lo-nibble:
    1224                                       (p3 - ach) // 0 for '0', 10 for 'A', ...
    1225                                       // hi-nibble:
    1226                                     + ((p2 - ach) << 4);
    1227                         // go on after that
    1228                         pSource += 2;
    1229                         // raise return count
    1230                         ulrc++;
    1231                         // next in loop
    1232                         continue;
    1233                     }
     1272                    // both chars after '%' were valid:
     1273                    *pDest++ =    // lo-nibble:
     1274                                  (p3 - ach) // 0 for '0', 10 for 'A', ...
     1275                                  // hi-nibble:
     1276                                + ((p2 - ach) << 4);
     1277                    // go on after that
     1278                    pSource += 2;
     1279                    // raise return count
     1280                    ulrc++;
     1281                    // next in loop
     1282                    continue;
    12341283                }
    1235 
    1236                 // not encoding, or null after '%', or invalid encoding:
    1237                 // just copy this
    1238                 *pDest++ = c;
    1239             } // while ((ch = *pSource++))
    1240 
    1241             if (ulrc)
    1242             {
    1243                 // any encodings found:
    1244                 // terminate target
    1245                 *pDest = 0;
    1246 
    1247                 // replace source with target
    1248                 free(pxstr->psz);
    1249                 pxstr->psz = pszDest;
    1250                 pxstr->cbAllocated = cbAllocated;
    1251                 pxstr->ulLength = (pDest - pszDest);
    12521284            }
    1253             else
    1254                 // no encodings found:
    1255                 free(pszDest);
     1285
     1286            // not encoding, or null after '%', or invalid encoding:
     1287            // just copy this
     1288            *pDest++ = c;
     1289        } // while ((ch = *pSource++))
     1290
     1291        if (ulrc)
     1292        {
     1293            *pDest = 0;
     1294            pxstr->ulLength = (pDest - pszDest);
    12561295        }
    12571296    }
Note: See TracChangeset for help on using the changeset viewer.