Ignore:
Timestamp:
Nov 1, 2001, 6:43:18 PM (24 years ago)
Author:
umoeller
Message:

More updates.

File:
1 edited

Legend:

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

    r113 r116  
    6464#include <stdio.h>
    6565#include <stdarg.h>
     66#include <ctype.h>
    6667
    6768#include "setup.h"                      // code generation and debugging options
     
    357358 */
    358359
    359 PVOID doshRequestSharedMem(const char *pcszName)
     360PVOID doshRequestSharedMem(PCSZ pcszName)
    360361{
    361362    PVOID pvrc = NULL;
     
    682683
    683684VOID doshEnumDrives(PSZ pszBuffer,      // out: drive letters
    684                     const char *pcszFileSystem,  // in: FS's to match or NULL
     685                    PCSZ pcszFileSystem,  // in: FS's to match or NULL
    685686                    BOOL fSkipRemoveables) // in: if TRUE, only non-removeable disks will be returned
    686687{
     
    11911192
    11921193/*
    1193  *@@category: Helpers\Control program helpers\File management
     1194 *@@category: Helpers\Control program helpers\File name parsing
    11941195 */
    11951196
    11961197/* ******************************************************************
    11971198 *
    1198  *   File helpers
     1199 *   File name parsing
    11991200 *
    12001201 ********************************************************************/
     1202
     1203/*
     1204 *@@ doshGetDriveSpec:
     1205 *      returns the drive specification in pcszFullFile,
     1206 *      if any is present. This is useful for UNC support.
     1207 *
     1208 *      This returns:
     1209 *
     1210 *      --  NO_ERROR: drive spec was given, and the output
     1211 *          fields have been set.
     1212 *
     1213 *      --  ERROR_INVALID_NAME: incorrect UNC syntax.
     1214 *
     1215 *      --  ERROR_INVALID_DRIVE: second char is ':', but
     1216 *          drive letter is not in the range [A-Z].
     1217 *
     1218 *      --  ERROR_INVALID_PARAMETER: no drive spec given
     1219 *          at all; apparently pcszFullFile is not fully
     1220 *          qualified in the first place, or it is NULL,
     1221 *          or its length is <= 2.
     1222 *
     1223 *@@added V0.9.16 (2001-10-25) [umoeller]
     1224 */
     1225
     1226APIRET doshGetDriveSpec(PCSZ pcszFullFile,      // in: fully q'fied file spec
     1227                        PSZ pszDrive,           // out: drive spec ("C:" or "\\SERVER\RESOURCE"; ptr can be NULL)
     1228                        PULONG pulDriveLen,     // out: length of drive spec (2 if local drive; ptr can be NULL)
     1229                        PBOOL pfIsUNC)          // out: set to TRUE if UNC name, FALSE otherwise (ptr can be NULL)
     1230{
     1231    APIRET  arc = NO_ERROR;
     1232    ULONG   ulFileSpecLength;
     1233
     1234    if (    (pcszFullFile)
     1235         && (ulFileSpecLength = strlen(pcszFullFile))
     1236         && (ulFileSpecLength >= 2)
     1237       )
     1238    {
     1239        // upper-case the drive letter
     1240        if (pcszFullFile[1] == ':')
     1241        {
     1242            CHAR cDrive = toupper(*pcszFullFile);
     1243            // local drive specified:
     1244            if (    (cDrive >= 'A')
     1245                 && (cDrive <= 'Z')
     1246               )
     1247            {
     1248                if (pszDrive)
     1249                {
     1250                    pszDrive[0] = cDrive;
     1251                    pszDrive[1] = ':';
     1252                    pszDrive[2] = '\0';
     1253                }
     1254
     1255                if (pulDriveLen)
     1256                    *pulDriveLen = 2;
     1257                if (pfIsUNC)
     1258                    *pfIsUNC = FALSE;
     1259            }
     1260            else
     1261                // this is not a valid drive:
     1262                arc = ERROR_INVALID_DRIVE;
     1263        }
     1264        else if (    (pcszFullFile[0] == '\\')
     1265                  && (pcszFullFile[1] == '\\')
     1266                )
     1267        {
     1268            // UNC drive specified:
     1269            // this better be a full \\SERVER\RESOURCE string
     1270            PCSZ pResource;
     1271            if (pResource = strchr(pcszFullFile + 3, '\\'))
     1272            {
     1273                // we got at least \\SERVER\:
     1274                ULONG ulLength;
     1275                PCSZ p;
     1276
     1277                // check if more stuff is coming
     1278                if (p = strchr(pResource + 1, '\\'))
     1279                {
     1280                    // yes: copy server and resource excluding that backslash
     1281                    if (p == pResource + 1)
     1282                        // "\\SERVER\\" is invalid
     1283                        arc = ERROR_INVALID_NAME;
     1284                    else
     1285                        // we got "\\SERVER\something\":
     1286                        // drop the last backslash
     1287                        ulLength = p - pcszFullFile;
     1288                }
     1289                else
     1290                    // "\\SERVER\something" only:
     1291                    ulLength = ulFileSpecLength;
     1292
     1293                if (!arc)
     1294                {
     1295                    if (pszDrive)
     1296                    {
     1297                        memcpy(pszDrive,
     1298                               pcszFullFile,
     1299                               ulLength);
     1300                        pszDrive[ulLength] = '\0';
     1301                    }
     1302
     1303                    if (pulDriveLen)
     1304                        *pulDriveLen = ulLength;
     1305                    if (pfIsUNC)
     1306                        *pfIsUNC = TRUE;
     1307                }
     1308            }
     1309            else
     1310                // invalid UNC name:
     1311                arc = ERROR_INVALID_NAME;
     1312        }
     1313        else
     1314            // neither local, nor UNC:
     1315            arc = ERROR_INVALID_PARAMETER;
     1316    }
     1317    else
     1318        arc = ERROR_INVALID_PARAMETER;
     1319
     1320    return (arc);
     1321}
    12011322
    12021323/*
     
    12161337 */
    12171338
    1218 PSZ doshGetExtension(const char *pcszFilename)
     1339PSZ doshGetExtension(PCSZ pcszFilename)
    12191340{
    12201341    PSZ pReturn = NULL;
     
    12231344    {
    12241345        // find filename
    1225         const char *p2 = strrchr(pcszFilename + 2, '\\'),
     1346        PCSZ    p2 = strrchr(pcszFilename + 2, '\\'),
    12261347                            // works on "C:\blah" or "\\unc\blah"
    1227                    *pStartOfName = NULL,
    1228                    *pExtension = NULL;
     1348                pStartOfName = NULL,
     1349                pExtension = NULL;
    12291350
    12301351        if (p2)
     
    12341355            // no backslash found:
    12351356            // maybe only a drive letter was specified:
    1236             if (*(pcszFilename + 1) == ':')
     1357            if (pcszFilename[1] == ':')
    12371358                // yes:
    12381359                pStartOfName = pcszFilename + 2;
     
    12511372    return (pReturn);
    12521373}
     1374
     1375/*
     1376 *@@category: Helpers\Control program helpers\File management
     1377 */
     1378
     1379/* ******************************************************************
     1380 *
     1381 *   File helpers
     1382 *
     1383 ********************************************************************/
    12531384
    12541385/*
     
    14451576 */
    14461577
    1447 APIRET doshOpenExisting(const char *pcszFilename,   // in: file name
     1578APIRET doshOpenExisting(PCSZ pcszFilename,   // in: file name
    14481579                        ULONG ulOpenFlags,          // in: open flags
    14491580                        HFILE *phf)                 // out: OS/2 file handle
     
    15521683 */
    15531684
    1554 APIRET doshOpen(const char *pcszFilename,   // in: filename to open
     1685APIRET doshOpen(PCSZ pcszFilename,   // in: filename to open
    15551686                ULONG ulOpenMode,       // in: XOPEN_* mode
    15561687                PULONG pcbFile,         // in: new file size (if new file is created)
     
    17561887
    17571888            arc = doshWrite(pFile,
    1758                             (PVOID)szTemp,
     1889                            (PCSZ)szTemp,
    17591890                            ulLength);
    17601891        }
     
    18231954 */
    18241955
    1825 APIRET doshLoadTextFile(const char *pcszFile,  // in: file name to read
     1956APIRET doshLoadTextFile(PCSZ pcszFile,  // in: file name to read
    18261957                        PSZ* ppszContent)      // out: newly allocated buffer with file's content
    18271958{
     
    19602091
    19612092APIRET doshCreateTempFileName(PSZ pszTempFileName,        // out: fully q'fied temp file name
    1962                               const char *pcszDir,        // in: dir or NULL for %TEMP%
    1963                               const char *pcszPrefix,     // in: prefix for temp file or NULL
    1964                               const char *pcszExt)        // in: extension (without dot) or NULL
     2093                              PCSZ pcszDir,        // in: dir or NULL for %TEMP%
     2094                              PCSZ pcszPrefix,     // in: prefix for temp file or NULL
     2095                              PCSZ pcszExt)        // in: extension (without dot) or NULL
    19652096{
    19662097    APIRET      arc = NO_ERROR;
     
    21722303 */
    21732304
    2174 BOOL doshQueryDirExist(const char *pcszDir)
     2305BOOL doshQueryDirExist(PCSZ pcszDir)
    21752306{
    21762307    FILESTATUS3 fs3;
     
    21952326 */
    21962327
    2197 APIRET doshCreatePath(const char *pcszPath,
     2328APIRET doshCreatePath(PCSZ pcszPath,
    21982329                      BOOL fHidden) // in: if TRUE, the new directories will get FILE_HIDDEN
    21992330{
     
    23042435 */
    23052436
    2306 APIRET doshDeleteDir(const char *pcszDir,
     2437APIRET doshDeleteDir(PCSZ pcszDir,
    23072438                     ULONG flFlags,
    23082439                     PULONG pulDirs,        // out: directories found
     
    28442975 */
    28452976
    2846 APIRET doshExecVIO(const char *pcszExecWithArgs,
     2977APIRET doshExecVIO(PCSZ pcszExecWithArgs,
    28472978                   PLONG plExitCode)            // out: exit code (ptr can be NULL)
    28482979{
     
    29263057 */
    29273058
    2928 APIRET doshQuickStartSession(const char *pcszPath,       // in: program to start
    2929                              const char *pcszParams,     // in: parameters for program
     3059APIRET doshQuickStartSession(PCSZ pcszPath,       // in: program to start
     3060                             PCSZ pcszParams,     // in: parameters for program
    29303061                             BOOL fForeground,  // in: if TRUE, session will be in foreground
    29313062                             USHORT usPgmCtl,   // in: STARTDATA.PgmControl
Note: See TracChangeset for help on using the changeset viewer.