Changeset 103 for trunk/dll/valid.c


Ignore:
Timestamp:
Jun 17, 2004, 6:40:41 AM (21 years ago)
Author:
root
Message:

Implement Jim Read's removable logic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/valid.c

    r70 r103  
    66  File name manipulation routines
    77
    8   Copyright (c) 1993-98 M. Kimes
    9   Copyright (c) 2002 Steven H.Levine
     8  Copyright (c) 1993, 1998 M. Kimes
     9  Copyright (c) 2002, 2004 Steven H.Levine
    1010
    1111  Revisions     23 Nov 02 SHL - RootName: rework for sanity
    12                 27 Nov 02 SHL - MakeFullName: correct typo
     12                27 Nov 02 SHL - MakeFullName: correct typo
    1313                11 Jun 03 SHL - Add JFS and FAT32 support
     14                15 Jun 04 SHL - Implement Jim Read's removable logic
    1415
    1516***********************************************************************/
     
    1718#define INCL_DOS
    1819#define INCL_WIN
     20#define INCL_DOSDEVICES         // DosDevIOCtl
     21#define INCL_DOSDEVIOCTL        // DosDevIOCtl
    1922
    2023#include <os2.h>
     
    2326#include <string.h>
    2427#include <ctype.h>
     28
    2529#include "fm3dll.h"
    2630
     
    3438
    3539
    36 APIRET MakeFullName (char *filename) {
    37 
    38   /* filename must be CCHMAXPATH long minimum! */
    39 
    40   char   fullname[CCHMAXPATH];
     40APIRET MakeFullName (char *pszFileName)
     41{
     42  /* pszFileName must be CCHMAXPATH long minimum! */
     43
     44  char   szPathName[CCHMAXPATH];
    4145  APIRET rc;
    4246
    4347  DosError(FERR_DISABLEHARDERR);
    44   rc = DosQueryPathInfo(filename,
    45                         FIL_QUERYFULLNAME,
    46                         fullname,
    47                         sizeof(fullname));
     48  rc = DosQueryPathInfo(pszFileName,
     49                        FIL_QUERYFULLNAME,
     50                        szPathName,
     51                        sizeof(szPathName));
    4852  if(!rc)
    49     strcpy(filename, fullname);         // Use actual name
     53    strcpy(pszFileName, szPathName);    // Pass back actual name
    5054  return rc;
    5155}
    5256
    5357
    54 char *RootName (char *filename) {
    55 
     58char *RootName (char *filename)
     59{
    5660  char *p = NULL,*pp;
    5761
     
    6367    pp = strrchr(filename,'/');
    6468    p = (p) ?
    65         (pp) ?
    66           (p > pp) ?
    67            p :
    68            pp :
    69           p :
    70         pp;
     69        (pp) ?
     70          (p > pp) ?
     71           p :
     72           pp :
     73          p :
     74        pp;
    7175  }
    7276  if(!p)                  /* name is itself a root */
     
    7882
    7983
    80 int TestDates (char *file1,char *file2) {
    81 
     84int TestDates (char *file1,char *file2)
     85{
    8286  /*
    8387   * return 1 (file2 newer than file1),
     
    9195  DosError(FERR_DISABLEHARDERR);
    9296  if(!DosQueryPathInfo(file1,
    93                        FIL_STANDARD,
    94                        &fs3o,
    95                        sizeof(fs3o))) {
     97                       FIL_STANDARD,
     98                       &fs3o,
     99                       sizeof(fs3o))) {
    96100    DosError(FERR_DISABLEHARDERR);
    97101    if(!DosQueryPathInfo(file2,
    98                         FIL_STANDARD,
    99                         &fs3n,
    100                         sizeof(fs3n))) {
     102                        FIL_STANDARD,
     103                        &fs3n,
     104                        sizeof(fs3n))) {
    101105      comp = (fs3n.fdateLastWrite.year >
    102               fs3o.fdateLastWrite.year) ? 1 :
    103              (fs3n.fdateLastWrite.year <
    104               fs3o.fdateLastWrite.year) ? -1 :
    105              (fs3n.fdateLastWrite.month >
    106               fs3o.fdateLastWrite.month) ? 1 :
    107              (fs3n.fdateLastWrite.month <
    108               fs3o.fdateLastWrite.month) ? -1 :
    109              (fs3n.fdateLastWrite.day >
    110               fs3o.fdateLastWrite.day) ? 1 :
    111              (fs3n.fdateLastWrite.day <
    112               fs3o.fdateLastWrite.day) ? -1 :
    113              (fs3n.ftimeLastWrite.hours >
    114               fs3o.ftimeLastWrite.hours) ? 1 :
    115              (fs3n.ftimeLastWrite.hours <
    116               fs3o.ftimeLastWrite.hours) ? -1 :
    117              (fs3n.ftimeLastWrite.minutes >
    118               fs3o.ftimeLastWrite.minutes) ? 1 :
    119              (fs3n.ftimeLastWrite.minutes <
    120               fs3o.ftimeLastWrite.minutes) ? -1 :
    121              (fs3n.ftimeLastWrite.twosecs >
    122               fs3o.ftimeLastWrite.twosecs) ? 1 :
    123              (fs3n.ftimeLastWrite.twosecs <
    124               fs3o.ftimeLastWrite.twosecs) ? -1 :
    125              0;
     106              fs3o.fdateLastWrite.year) ? 1 :
     107             (fs3n.fdateLastWrite.year <
     108              fs3o.fdateLastWrite.year) ? -1 :
     109             (fs3n.fdateLastWrite.month >
     110              fs3o.fdateLastWrite.month) ? 1 :
     111             (fs3n.fdateLastWrite.month <
     112              fs3o.fdateLastWrite.month) ? -1 :
     113             (fs3n.fdateLastWrite.day >
     114              fs3o.fdateLastWrite.day) ? 1 :
     115             (fs3n.fdateLastWrite.day <
     116              fs3o.fdateLastWrite.day) ? -1 :
     117             (fs3n.ftimeLastWrite.hours >
     118              fs3o.ftimeLastWrite.hours) ? 1 :
     119             (fs3n.ftimeLastWrite.hours <
     120              fs3o.ftimeLastWrite.hours) ? -1 :
     121             (fs3n.ftimeLastWrite.minutes >
     122              fs3o.ftimeLastWrite.minutes) ? 1 :
     123             (fs3n.ftimeLastWrite.minutes <
     124              fs3o.ftimeLastWrite.minutes) ? -1 :
     125             (fs3n.ftimeLastWrite.twosecs >
     126              fs3o.ftimeLastWrite.twosecs) ? 1 :
     127             (fs3n.ftimeLastWrite.twosecs <
     128              fs3o.ftimeLastWrite.twosecs) ? -1 :
     129             0;
    126130    }
    127131  }
     
    130134
    131135
    132 BOOL IsNewer (char *file1,char *file2) {
    133 
     136BOOL IsNewer (char *file1,char *file2)
     137{
    134138  /* return TRUE if file2 is newer than file1 */
    135139
     
    138142
    139143
    140 BOOL IsDesktop (HAB hab,HWND hwnd) {
    141 
     144BOOL IsDesktop (HAB hab,HWND hwnd)
     145{
    142146  HWND hwndDesktop;
    143147
     
    150154}
    151155
    152 BOOL ParentIsDesktop (HWND hwnd,HWND hwndParent) {
    153 
     156BOOL ParentIsDesktop (HWND hwnd,HWND hwndParent)
     157{
    154158  HWND hwndDesktop;
    155159  BOOL ret = FALSE;
     
    170174INT CheckDrive (CHAR chDrive, CHAR *pszFileSystem, ULONG *pulType)
    171175{
    172   CHAR        Path[3],*Buffer = NULL,*pfsn = NULL,*pfsd = NULL;
    173   ULONG       Size,Status,action,LengthIn,LengthOut;
    174   HFILE       Handle;
    175   BYTE        Command = 0,NonRemovable;
     176  CHAR          szPath[3];
     177  VOID          *pvBuffer = NULL;
     178  CHAR          *pfsn;
     179  CHAR          *pfsd;
     180  ULONG         clBufferSize;
     181  APIRET        ulrc;
     182  ULONG         ulAction;
     183  ULONG         clParmBytes;
     184  ULONG         clDataBytes;
     185  HFILE         hDev;
     186# pragma pack(1)
     187  struct {
     188    BYTE        Cmd;
     189    BYTE        Unit;
     190  } parmPkt = {0, 0};
     191# define BPB_REMOVABLE_MEDIA    0x08    // 3 - Media is removable
     192  struct
     193  {
     194    BIOSPARAMETERBLOCK bpb;
     195    USHORT cCylinders;                  // Documented but not implemented
     196    BYTE bDeviceType;                   // Documented but not implemented
     197    USHORT fsDeviceAttr;                // Documented but not implemented
     198  } dataPkt;
     199# pragma pack()
     200  BYTE          NonRemovable;
    176201  PFSQBUFFER2 pfsq;
    177202
     
    181206    *pulType = 0;
    182207
    183   if(DosAllocMem((PVOID)&Buffer,4096,
    184                  PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE)) {
     208# define BUFFER_BYTES   4096
     209  if(DosAllocMem(&pvBuffer,BUFFER_BYTES,
     210                 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE)) {
    185211    DosBeep(50,50);
    186212    return -1;                          // Say failed
    187213  }
    188214
    189   Path[0] = chDrive;
    190   Path[1] = ':';
    191   Path[2] = 0;
    192   Size = 4096;
     215  szPath[0] = chDrive;
     216  szPath[1] = ':';
     217  szPath[2] = 0;
     218  clBufferSize = BUFFER_BYTES;
    193219  DosError(FERR_DISABLEHARDERR);
    194   Status = DosQueryFSAttach(Path, 0, FSAIL_QUERYNAME,
    195                             (PFSQBUFFER2)Buffer, &Size);
    196   if (Status)
     220  ulrc = DosQueryFSAttach(szPath, 0, FSAIL_QUERYNAME,
     221                          (PFSQBUFFER2)pvBuffer, &clBufferSize);
     222  if (ulrc)
    197223  {
    198224    /* can't get any info at all */
    199     DosFreeMem(Buffer);
     225    DosFreeMem(pvBuffer);
    200226    DosError(FERR_DISABLEHARDERR);
    201227    return -1;                          // Say failed
    202228  }
    203229
    204   pfsq = (PFSQBUFFER2)Buffer;
     230  pfsq = (PFSQBUFFER2)pvBuffer;
    205231  pfsn = pfsq->szName + pfsq->cbName + 1;
    206232  pfsd = pfsn + pfsq->cbFSDName + 1;
     
    215241    *pulType |= DRIVE_NOTWRITEABLE | DRIVE_CDROM | DRIVE_REMOVABLE;
    216242
    217   if (((PFSQBUFFER2)Buffer)->iType == FSAT_REMOTEDRV)
     243  if (((PFSQBUFFER2)pvBuffer)->iType == FSAT_REMOTEDRV)
    218244  {
    219245    if (pulType)
     
    226252      if (pfsq->cbFSAData)
    227253      {
    228         ULONG FType;
    229 
    230         if (CheckDrive(*pfsd,NULL,&FType) != -1)
     254        ULONG FType;
     255
     256        if (CheckDrive(*pfsd,NULL,&FType) != -1)
    231257        {
    232           if (FType & DRIVE_REMOVABLE)
    233             *pulType |= DRIVE_REMOVABLE;
    234           if (~FType & DRIVE_NOLONGNAMES)
    235             *pulType &= ~DRIVE_NOLONGNAMES;
    236         }
     258          if (FType & DRIVE_REMOVABLE)
     259            *pulType |= DRIVE_REMOVABLE;
     260          if (~FType & DRIVE_NOLONGNAMES)
     261            *pulType &= ~DRIVE_NOLONGNAMES;
     262        }
    237263      }
    238264    }
    239265    if (pulType &&
    240         (!strcmp(pfsn,HPFS) ||
    241         !strcmp(pfsn,JFS) ||
    242         !strcmp(pfsn,FAT32) ||
    243         !strcmp(pfsn,HPFS386)))
     266        (!strcmp(pfsn,HPFS) ||
     267        !strcmp(pfsn,JFS) ||
     268        !strcmp(pfsn,FAT32) ||
     269        !strcmp(pfsn,HPFS386)))
    244270    {
    245271      *pulType &= ~DRIVE_NOLONGNAMES;
    246272    }
    247     DosFreeMem(Buffer);
    248     return 0;                           // Say non-removable
     273    DosFreeMem(pvBuffer);
     274    return 0;                           // Remotes are non-removable
    249275  }
    250276
     
    257283  {
    258284    if(pulType)
    259       (*pulType) |= DRIVE_NOLONGNAMES;
     285      (*pulType) |= DRIVE_NOLONGNAMES;  // Others can not have long names
    260286  }
    261287
    262288  DosError(FERR_DISABLEHARDERR);
    263   Status = DosOpen(Path, &Handle, &action, 0, 0, FILE_OPEN,
    264                   OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE |
    265                   OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR, 0);
    266   if(Status)
     289  ulrc = DosOpen(szPath, &hDev, &ulAction, 0, 0, FILE_OPEN,
     290                OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE |
     291                OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR, 0);
     292  if(ulrc)
    267293  {
    268294    DosError(FERR_DISABLEHARDERR);
    269295    if (pulType)
    270296      *pulType |= DRIVE_REMOVABLE;      // Assume removable if can not access
    271     DosFreeMem(Buffer);
     297    DosFreeMem(pvBuffer);
    272298    return 1;                           // Say removable
    273299  }
    274   LengthIn = sizeof(Command);
    275   LengthOut = sizeof(NonRemovable);
    276   NonRemovable = 1;
     300
     301  clParmBytes = sizeof(parmPkt.Cmd);
     302  clDataBytes = sizeof(NonRemovable);
     303  NonRemovable = 1;                     // Preset as non removable
    277304  DosError(FERR_DISABLEHARDERR);
    278   DosDevIOCtl(Handle, 8, 0x20,&Command, sizeof(Command), &LengthIn,
    279               &NonRemovable, sizeof(NonRemovable), &LengthOut);
    280   DosClose(Handle);
     305  ulrc = DosDevIOCtl(hDev, IOCTL_DISK, DSK_BLOCKREMOVABLE,
     306                     &parmPkt.Cmd,              /*  Address of the command-specific argument list. */
     307                     sizeof(parmPkt.Cmd),       /*  Length, in bytes, of pParams. */
     308                     &clParmBytes,              /*  Pointer to the length of parameters. */
     309                     &NonRemovable,             /*  Address of the data area. */
     310                     sizeof(NonRemovable),      /*  Length, in bytes, of pData. */
     311                     &clDataBytes);             /*  Pointer to the length of data. */
     312
     313  if (!ulrc && NonRemovable) {
     314    // Could be USB so check BPB flags
     315    clParmBytes = sizeof(parmPkt.Cmd);
     316    clDataBytes = sizeof(dataPkt);
     317    memset(&dataPkt, 0xff, sizeof(dataPkt));
     318    DosError(FERR_DISABLEHARDERR);
     319    ulrc = DosDevIOCtl(hDev, IOCTL_DISK, DSK_GETDEVICEPARAMS,
     320                       &parmPkt.Cmd,            /*  Address of the command-specific argument list. */
     321                       sizeof(parmPkt.Cmd),     /*  Length, in bytes, of pParams. */
     322                       &clParmBytes,            /*  Pointer to the length of parameters. */
     323                       &dataPkt,                /*  Address of the data area. */
     324                       sizeof(dataPkt),         /*  Length, in bytes, of pData. */
     325                       &clDataBytes);           /*  Pointer to the length of data. */
     326
     327    if (!ulrc && (dataPkt.bpb.fsDeviceAttr & BPB_REMOVABLE_MEDIA))
     328      NonRemovable = 0;
     329  }
     330
     331  DosClose(hDev);
     332
    281333  if (!NonRemovable && pulType)
    282334    *pulType |= DRIVE_REMOVABLE;
    283   DosFreeMem(Buffer);
     335
     336  DosFreeMem(pvBuffer);
     337
    284338  return NonRemovable ? 0 : 1;
    285339}
    286340
    287341
    288 BOOL IsFileSame (CHAR *filename1,CHAR *filename2) {
    289 
     342BOOL IsFileSame (CHAR *filename1,CHAR *filename2)
     343{
    290344  /* returns:  -1 (error), 0 (is a directory), or 1 (is a file) */
    291345
     
    296350    DosError(FERR_DISABLEHARDERR);
    297351    ret = DosQueryPathInfo(filename1,FIL_STANDARD,&fsa1,
    298                         (ULONG)sizeof(fsa1));
     352                        (ULONG)sizeof(fsa1));
    299353    if(!ret) {
    300354      DosError(FERR_DISABLEHARDERR);
    301355      ret = DosQueryPathInfo(filename2,FIL_STANDARD,&fsa2,
    302                              (ULONG)sizeof(fsa2));
     356                             (ULONG)sizeof(fsa2));
    303357      if(!ret) {
    304         if(fsa1.cbFile == fsa2.cbFile &&
    305            (fsa1.attrFile & (~FILE_ARCHIVED)) ==
    306            (fsa2.attrFile & (~FILE_ARCHIVED)))
    307           return TRUE;
     358        if(fsa1.cbFile == fsa2.cbFile &&
     359           (fsa1.attrFile & (~FILE_ARCHIVED)) ==
     360           (fsa2.attrFile & (~FILE_ARCHIVED)))
     361          return TRUE;
    308362      }
    309363    }
     
    313367
    314368
    315 INT IsFile (CHAR *filename) {
    316 
     369INT IsFile (CHAR *filename)
     370{
    317371  /* returns:  -1 (error), 0 (is a directory), or 1 (is a file) */
    318372
     
    323377    DosError(FERR_DISABLEHARDERR);
    324378    ret = DosQueryPathInfo(filename,
    325                            FIL_STANDARD,
    326                            &fsa,
    327                            (ULONG)sizeof(fsa));
     379                           FIL_STANDARD,
     380                           &fsa,
     381                           (ULONG)sizeof(fsa));
    328382    if(!ret)
    329383      return ((fsa.attrFile & FILE_DIRECTORY) == 0);
     
    335389
    336390
    337 BOOL IsFullName (CHAR *filename) {
    338 
     391BOOL IsFullName (CHAR *filename)
     392{
    339393  return (filename) ?
    340           (isalpha(*filename) && filename[1] == ':' && filename[2] == '\\') :
    341           0;
    342 }
    343 
    344 
    345 BOOL IsRoot (CHAR *filename) {
    346 
     394          (isalpha(*filename) && filename[1] == ':' && filename[2] == '\\') :
     395          0;
     396}
     397
     398
     399BOOL IsRoot (CHAR *filename)
     400{
    347401  return (filename && isalpha(*filename) && filename[1] == ':' &&
    348           filename[2] == '\\' && !filename[3]);
    349 }
    350 
    351 
    352 BOOL IsValidDir (CHAR *path) {
    353 
     402          filename[2] == '\\' && !filename[3]);
     403}
     404
     405
     406BOOL IsValidDir (CHAR *path)
     407{
    354408  CHAR        fullname[CCHMAXPATH];
    355409  FILESTATUS3 fs;
     
    358412    DosError(FERR_DISABLEHARDERR);
    359413    if(!DosQueryPathInfo(path,
    360                         FIL_QUERYFULLNAME,
    361                         fullname,
    362                         sizeof(fullname))) {
     414                        FIL_QUERYFULLNAME,
     415                        fullname,
     416                        sizeof(fullname))) {
    363417      if(IsValidDrive(*fullname)) {
    364         if(!IsRoot(fullname)) {
    365           DosError(FERR_DISABLEHARDERR);
    366           if(!DosQueryPathInfo(fullname,
    367                                FIL_STANDARD,
    368                                &fs,
    369                                sizeof(fs)) &&
    370              (fs.attrFile & FILE_DIRECTORY))
    371             return TRUE;
    372         }
    373         else
    374           return TRUE;
     418        if(!IsRoot(fullname)) {
     419          DosError(FERR_DISABLEHARDERR);
     420          if(!DosQueryPathInfo(fullname,
     421                               FIL_STANDARD,
     422                               &fs,
     423                               sizeof(fs)) &&
     424             (fs.attrFile & FILE_DIRECTORY))
     425            return TRUE;
     426        }
     427        else
     428          return TRUE;
    375429      }
    376430    }
     
    380434
    381435
    382 BOOL IsValidDrive (CHAR drive) {
    383 
     436BOOL IsValidDrive (CHAR drive)
     437{
    384438  CHAR   Path[] = " :",Buffer[256];
    385439  APIRET Status;
     
    399453    DosError(FERR_DISABLEHARDERR);
    400454    Status = DosQueryFSAttach(Path,
    401                               0,
    402                               FSAIL_QUERYNAME,
    403                               (PFSQBUFFER2)Buffer,
    404                               &Size);
     455                              0,
     456                              FSAIL_QUERYNAME,
     457                              (PFSQBUFFER2)Buffer,
     458                              &Size);
    405459  }
    406460  return (Status == 0);
     
    408462
    409463
    410 CHAR * MakeValidDir (CHAR *path) {
    411 
     464CHAR * MakeValidDir (CHAR *path)
     465{
    412466  CHAR           fullname[CCHMAXPATH],drive;
    413467  register CHAR *p;
     
    418472    if(IsValidDrive(*path)) {
    419473      for(;;) {
    420         if(IsRoot(path))
    421           return path;
    422         DosError(FERR_DISABLEHARDERR);
    423         status = DosQueryPathInfo(path,
    424                                   FIL_STANDARD,
    425                                   &fs,
    426                                   sizeof(fs));
    427         if(!status &&
    428            (fs.attrFile & FILE_DIRECTORY) != 0)
    429           return path;
    430         p = strrchr(path,'\\');
    431         if(p) {
    432           if(p < path + 3)
    433             p++;
    434           *p = 0;
    435         }
    436         else
    437           break;
     474        if(IsRoot(path))
     475          return path;
     476        DosError(FERR_DISABLEHARDERR);
     477        status = DosQueryPathInfo(path,
     478                                  FIL_STANDARD,
     479                                  &fs,
     480                                  sizeof(fs));
     481        if(!status &&
     482           (fs.attrFile & FILE_DIRECTORY) != 0)
     483          return path;
     484        p = strrchr(path,'\\');
     485        if(p) {
     486          if(p < path + 3)
     487            p++;
     488          *p = 0;
     489        }
     490        else
     491          break;
    438492      }
    439493    }
     
    441495  DosError(FERR_DISABLEHARDERR);
    442496  if(!DosQuerySysInfo(QSV_BOOT_DRIVE,
    443                       QSV_BOOT_DRIVE,
    444                       &drive,
    445                       1L)) {
     497                      QSV_BOOT_DRIVE,
     498                      &drive,
     499                      1L)) {
    446500    drive += '@';
    447501    if(drive < 'C')
     
    456510
    457511
    458 BOOL IsExecutable (CHAR *filename) {
    459 
     512BOOL IsExecutable (CHAR *filename)
     513{
    460514  register CHAR *p;
    461515  APIRET         ret;
     
    467521    if(p)
    468522      ret = DosQAppType(filename,
    469                         &apptype);
     523                        &apptype);
    470524    else {
    471525
     
    475529      strcat(fname,".");
    476530      ret = DosQAppType(fname,
    477                         &apptype);
     531                        &apptype);
    478532    }
    479533    if((!ret && (!apptype ||
    480                 (apptype &
    481                   (FAPPTYP_NOTWINDOWCOMPAT |
    482                    FAPPTYP_WINDOWCOMPAT |
    483                    FAPPTYP_WINDOWAPI |
    484                    FAPPTYP_BOUND |
    485                    FAPPTYP_DOS |
    486                    FAPPTYP_WINDOWSREAL |
    487                    FAPPTYP_WINDOWSPROT |
    488                    FAPPTYP_32BIT |
    489                    0x1000)))) ||
     534                (apptype &
     535                  (FAPPTYP_NOTWINDOWCOMPAT |
     536                   FAPPTYP_WINDOWCOMPAT |
     537                   FAPPTYP_WINDOWAPI |
     538                   FAPPTYP_BOUND |
     539                   FAPPTYP_DOS |
     540                   FAPPTYP_WINDOWSREAL |
     541                   FAPPTYP_WINDOWSPROT |
     542                   FAPPTYP_32BIT |
     543                   0x1000)))) ||
    490544       (p &&
    491         (!stricmp(p,".CMD") ||
    492         !stricmp(p,".BAT"))))
     545        (!stricmp(p,".CMD") ||
     546        !stricmp(p,".BAT"))))
    493547      return TRUE;
    494548  }
     
    497551
    498552
    499 VOID ArgDriveFlags (INT argc,CHAR **argv) {
    500 
     553VOID ArgDriveFlags (INT argc,CHAR **argv)
     554{
    501555  INT x;
    502556
     
    507561
    508562      while(isalpha(*p)) {
    509         driveflags[toupper(*p) - 'A'] |= DRIVE_IGNORE;
    510         p++;
     563        driveflags[toupper(*p) - 'A'] |= DRIVE_IGNORE;
     564        p++;
    511565      }
    512566    }
     
    516570
    517571      while(isalpha(*p)) {
    518         driveflags[toupper(*p) - 'A'] |= DRIVE_NOPRESCAN;
    519         p++;
     572        driveflags[toupper(*p) - 'A'] |= DRIVE_NOPRESCAN;
     573        p++;
    520574      }
    521575    }
     
    525579
    526580      while(isalpha(*p)) {
    527         driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADICONS;
    528         p++;
     581        driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADICONS;
     582        p++;
    529583      }
    530584    }
     
    534588
    535589      while(isalpha(*p)) {
    536         driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADSUBJS;
    537         p++;
     590        driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADSUBJS;
     591        p++;
    538592      }
    539593    }
     
    543597
    544598      while(isalpha(*p)) {
    545         driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADLONGS;
    546         p++;
     599        driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADLONGS;
     600        p++;
    547601      }
    548602    }
     
    563617  driveserial[x] = -1;
    564618  driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
    565                     DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
    566                     DRIVE_INCLUDEFILES | DRIVE_SLOW);
     619                    DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
     620                    DRIVE_INCLUDEFILES | DRIVE_SLOW);
    567621  if(removable != -1)
    568622  {
     
    583637    driveflags[x] |= DRIVE_INVALID;
    584638  driveflags[x] |= ((removable == -1 || removable == 1) ?
    585                                         DRIVE_REMOVABLE : 0);
     639                                        DRIVE_REMOVABLE : 0);
    586640  if(drvtype & DRIVE_REMOTE)
    587641    driveflags[x] |= DRIVE_REMOTE;
     
    597651    removable = 1;
    598652    driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOTWRITEABLE |
    599                       DRIVE_CDROM);
     653                      DRIVE_CDROM);
    600654  }
    601655  else if(!stricmp(FileSystem,CBSIFS)) {
     
    610664
    611665
    612 VOID FillInDriveFlags (VOID *dummy) {
    613 
     666VOID FillInDriveFlags (VOID *dummy)
     667{
    614668  ULONG        ulDriveNum,ulDriveMap;
    615669  register INT x;
     
    617671  for(x = 0;x < 26;x++)
    618672    driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
    619                       DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
    620                       DRIVE_INCLUDEFILES | DRIVE_SLOW);
     673                      DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
     674                      DRIVE_INCLUDEFILES | DRIVE_SLOW);
    621675  memset(driveserial,-1,sizeof(driveserial));
    622676  DosError(FERR_DISABLEHARDERR);
     
    625679    if(ulDriveMap & (1L << x) && !(driveflags[x] & DRIVE_IGNORE)) {
    626680      {
    627         CHAR  s[80];
    628         ULONG flags = 0,size = sizeof(ULONG);
    629 
    630         sprintf(s,"%c.DriveFlags",(CHAR)(x + 'A'));
    631         if(PrfQueryProfileData(fmprof,appname,s,&flags,&size) &&
    632            size == sizeof(ULONG))
    633           driveflags[x] |= flags;
     681        CHAR  s[80];
     682        ULONG flags = 0,size = sizeof(ULONG);
     683
     684        sprintf(s,"%c.DriveFlags",(CHAR)(x + 'A'));
     685        if(PrfQueryProfileData(fmprof,appname,s,&flags,&size) &&
     686           size == sizeof(ULONG))
     687          driveflags[x] |= flags;
    634688      }
    635689
    636690      if(x > 1) {
    637         if(!(driveflags[x] & DRIVE_NOPRESCAN))
    638           DriveFlagsOne(x);
    639         else
    640           driveserial[x] = -1;
     691        if(!(driveflags[x] & DRIVE_NOPRESCAN))
     692          DriveFlagsOne(x);
     693        else
     694          driveserial[x] = -1;
    641695      }
    642696      else {
    643         driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOLONGNAMES);
    644         driveserial[x] = -1;
     697        driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOLONGNAMES);
     698        driveserial[x] = -1;
    645699      }
    646700    }
     
    653707    DosError(FERR_DISABLEHARDERR);
    654708    DosQuerySysInfo(QSV_BOOT_DRIVE,QSV_BOOT_DRIVE,
    655                     (PVOID)&startdrive,(ULONG)sizeof(ULONG));
     709                    (PVOID)&startdrive,(ULONG)sizeof(ULONG));
    656710    if(startdrive)
    657711      driveflags[startdrive - 1] |= DRIVE_BOOT;
     
    660714
    661715
    662 CHAR * assign_ignores (CHAR *s) {
    663 
     716CHAR * assign_ignores (CHAR *s)
     717{
    664718  register INT   x;
    665719  register CHAR *p,*pp;
     
    671725    for(x = 0;x < 26;x++) {
    672726      if((driveflags[x] & DRIVE_IGNORE) != 0) {
    673         *p = (CHAR)x + 'A';
    674         p++;
    675         *p = 0;
     727        *p = (CHAR)x + 'A';
     728        p++;
     729        *p = 0;
    676730      }
    677731    }
     
    692746    for(x = 0;x < 26;x++) {
    693747      if((driveflags[x] & DRIVE_NOPRESCAN) != 0) {
    694         *p = (CHAR)x + 'A';
    695         p++;
    696         *p = 0;
     748        *p = (CHAR)x + 'A';
     749        p++;
     750        *p = 0;
    697751      }
    698752    }
     
    709763    for(x = 0;x < 26;x++) {
    710764      if((driveflags[x] & DRIVE_NOLOADICONS) != 0) {
    711         *p = (CHAR)x + 'A';
    712         p++;
    713         *p = 0;
     765        *p = (CHAR)x + 'A';
     766        p++;
     767        *p = 0;
    714768      }
    715769    }
     
    726780    for(x = 0;x < 26;x++) {
    727781      if((driveflags[x] & DRIVE_NOLOADSUBJS) != 0) {
    728         *p = (CHAR)x + 'A';
    729         p++;
    730         *p = 0;
     782        *p = (CHAR)x + 'A';
     783        p++;
     784        *p = 0;
    731785      }
    732786    }
     
    743797    for(x = 0;x < 26;x++) {
    744798      if((driveflags[x] & DRIVE_NOLOADLONGS) != 0) {
    745         *p = (CHAR)x + 'A';
    746         p++;
    747         *p = 0;
     799        *p = (CHAR)x + 'A';
     800        p++;
     801        *p = 0;
    748802      }
    749803    }
     
    756810
    757811
    758 BOOL needs_quoting (register CHAR *f) {
    759 
     812BOOL needs_quoting (register CHAR *f)
     813{
    760814  register CHAR *p = " &|<>";
    761815
     
    769823
    770824
    771 BOOL IsBinary (register CHAR *str,ULONG len) {
    772 
     825BOOL IsBinary (register CHAR *str,ULONG len)
     826{
    773827  register ULONG x = 0L;
    774828
     
    776830    while(x < len) {
    777831      if(str[x] < ' ' && str[x] != '\r' && str[x] != '\n' && str[x] != '\t' &&
    778         str[x] != '\x1b' && str[x] != '\x1a' && str[x] != '\07' &&
    779         str[x] != '\x0c')
    780         return TRUE;
     832        str[x] != '\x1b' && str[x] != '\x1a' && str[x] != '\07' &&
     833        str[x] != '\x0c')
     834        return TRUE;
    781835      x++;
    782836    }
     
    786840
    787841
    788 BOOL TestBinary (CHAR *filename) {
    789 
     842BOOL TestBinary (CHAR *filename)
     843{
    790844  HFILE   handle;
    791   ULONG   action,len;
    792   APIRET  rc;
     845  ULONG   ulAction;
     846  ULONG   len;
     847  APIRET  ulrc;
    793848  CHAR    buff[512];
    794849
    795850  if(filename) {
    796     if(!DosOpen(filename,&handle,&action,0L,0L,
    797                 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
    798                 OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT |
    799                 OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYNONE |
    800                 OPEN_ACCESS_READONLY,0L)) {
     851    if(!DosOpen(filename,&handle,&ulAction,0L,0L,
     852                OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
     853                OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT |
     854                OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYNONE |
     855                OPEN_ACCESS_READONLY,0L)) {
    801856      len = 512;
    802       rc = DosRead(handle,buff,len,&len);
     857      ulrc = DosRead(handle,buff,len,&len);
    803858      DosClose(handle);
    804       if(!rc && len)
    805         return IsBinary(buff,len);
     859      if(!ulrc && len)
     860        return IsBinary(buff,len);
    806861    }
    807862  }
     
    810865
    811866
    812 char *IsVowel (char a) {
    813 
     867char *IsVowel (char a)
     868{
    814869  return (strchr("aeiouAEIOU",a) != NULL) ? "n" : NullStr;
    815870}
    816871
    817872
    818 VOID GetDesktopName (CHAR *objectpath,ULONG size) {
    819 
     873VOID GetDesktopName (CHAR *objectpath,ULONG size)
     874{
    820875  PFN     WQDPath;
    821876  HMODULE hmod = 0;
    822   APIRET  rc;
     877  APIRET  ulrc;
    823878  ULONG   startdrive = 3L;
    824879  CHAR    objerr[CCHMAXPATH];
     
    832887     * this way...
    833888     */
    834     rc = DosLoadModule(objerr,
    835                       sizeof(objerr),
    836                       "PMWP",
    837                       &hmod);
    838     if(!rc) {
    839       rc = DosQueryProcAddr(hmod,
    840                             262,
    841                             NULL,
    842                             &WQDPath);
    843       if(!rc)
    844         WQDPath(objectpath,size);
     889    ulrc = DosLoadModule(objerr,
     890                        sizeof(objerr),
     891                        "PMWP",
     892                        &hmod);
     893    if(!ulrc) {
     894      ulrc = DosQueryProcAddr(hmod,
     895                              262,
     896                              NULL,
     897                              &WQDPath);
     898      if(!ulrc)
     899        WQDPath(objectpath,size);
    845900      DosFreeModule(hmod);
    846901    }
     
    848903  if(!*objectpath) {
    849904    if(!PrfQueryProfileString(HINI_SYSTEMPROFILE,
    850                               "FolderWorkareaRunningObjects",
    851                               NULL,
    852                               "\0",
    853                               (PVOID)objectpath,
    854                               sizeof(objectpath)))
     905                              "FolderWorkareaRunningObjects",
     906                              NULL,
     907                              "\0",
     908                              (PVOID)objectpath,
     909                              sizeof(objectpath)))
    855910      *objectpath = 0;
    856911    if(!*objectpath || IsFile(objectpath)) {
     
    858913      DosError(FERR_DISABLEHARDERR);
    859914      DosQuerySysInfo(QSV_BOOT_DRIVE,QSV_BOOT_DRIVE,
    860                       (PVOID)&startdrive,(ULONG)sizeof(ULONG));
     915                      (PVOID)&startdrive,(ULONG)sizeof(ULONG));
    861916      sprintf(objectpath,
    862               "%c:\\DESKTOP",
    863               ((CHAR)startdrive) + '@');
    864     }
    865   }
    866 }
     917              "%c:\\DESKTOP",
     918              ((CHAR)startdrive) + '@');
     919    }
     920  }
     921}
Note: See TracChangeset for help on using the changeset viewer.