| 1 |  | 
|---|
| 2 | /*********************************************************************** | 
|---|
| 3 |  | 
|---|
| 4 | $Id: valid.c 328 2006-07-25 18:37:24Z root $ | 
|---|
| 5 |  | 
|---|
| 6 | File name manipulation routines | 
|---|
| 7 |  | 
|---|
| 8 | Copyright (c) 1993, 1998 M. Kimes | 
|---|
| 9 | Copyright (c) 2002, 2006 Steven H.Levine | 
|---|
| 10 |  | 
|---|
| 11 | 23 Nov 02 SHL RootName: rework for sanity | 
|---|
| 12 | 27 Nov 02 SHL MakeFullName: correct typo | 
|---|
| 13 | 11 Jun 03 SHL Add JFS and FAT32 support | 
|---|
| 14 | 15 Jun 04 SHL Implement Jim Read's removable logic | 
|---|
| 15 | 31 Jul 04 SHL Comments | 
|---|
| 16 | 01 Aug 04 SHL Rework lstrip/rstrip usage | 
|---|
| 17 | 03 Jun 05 SHL Drop CD_DEBUG logic | 
|---|
| 18 | 28 Nov 05 SHL MakeValidDir: correct DosQuerySysInfo args | 
|---|
| 19 | 22 Jul 06 SHL Use Runtime_Error | 
|---|
| 20 |  | 
|---|
| 21 | ***********************************************************************/ | 
|---|
| 22 |  | 
|---|
| 23 | #define INCL_DOS | 
|---|
| 24 | #define INCL_WIN | 
|---|
| 25 | #define INCL_DOSDEVICES         // DosDevIOCtl | 
|---|
| 26 | #define INCL_DOSDEVIOCTL        // DosDevIOCtl | 
|---|
| 27 | #include <os2.h> | 
|---|
| 28 |  | 
|---|
| 29 | #include <stdlib.h> | 
|---|
| 30 | #include <stdio.h> | 
|---|
| 31 | #include <string.h> | 
|---|
| 32 | #include <ctype.h> | 
|---|
| 33 |  | 
|---|
| 34 | #include "fm3dll.h" | 
|---|
| 35 | #include "fm3str.h" | 
|---|
| 36 |  | 
|---|
| 37 | static PSZ pszSrcFile = __FILE__; | 
|---|
| 38 |  | 
|---|
| 39 | #pragma alloc_text(VALID,CheckDrive,IsRoot,IsFile,IsFullName,needsquoting) | 
|---|
| 40 | #pragma alloc_text(VALID,IsValidDir,IsValidDrive,MakeValidDir,IsVowel) | 
|---|
| 41 | #pragma alloc_text(VALID,IsFileSame,IsNewer,TestDates,RootName,MakeFullName) | 
|---|
| 42 | #pragma alloc_text(VALID,IsExecutable,IsBinary,IsDesktop,ParentIsDesktop) | 
|---|
| 43 | #pragma alloc_text(FILLFLAGS,FillInDriveFlags,assign_ignores) | 
|---|
| 44 | #pragma alloc_text(FILLFLAGS,ArgDriveFlags,DriveFlagsOne) | 
|---|
| 45 | #pragma alloc_text(FINDDESK,GetDesktopName) | 
|---|
| 46 |  | 
|---|
| 47 |  | 
|---|
| 48 | APIRET MakeFullName (char *pszFileName) | 
|---|
| 49 | { | 
|---|
| 50 | /* pszFileName must be CCHMAXPATH long minimum! */ | 
|---|
| 51 |  | 
|---|
| 52 | char   szPathName[CCHMAXPATH]; | 
|---|
| 53 | APIRET rc; | 
|---|
| 54 |  | 
|---|
| 55 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 56 | rc = DosQueryPathInfo(pszFileName, | 
|---|
| 57 | FIL_QUERYFULLNAME, | 
|---|
| 58 | szPathName, | 
|---|
| 59 | sizeof(szPathName)); | 
|---|
| 60 | if(!rc) | 
|---|
| 61 | strcpy(pszFileName, szPathName);    // Pass back actual name | 
|---|
| 62 | return rc; | 
|---|
| 63 | } | 
|---|
| 64 |  | 
|---|
| 65 |  | 
|---|
| 66 | char *RootName (char *filename) | 
|---|
| 67 | { | 
|---|
| 68 | char *p = NULL,*pp; | 
|---|
| 69 |  | 
|---|
| 70 | // Return filename, strip path parts | 
|---|
| 71 | // Return empty string when filename ends with \ | 
|---|
| 72 |  | 
|---|
| 73 | if(filename) { | 
|---|
| 74 | p = strrchr(filename,'\\'); | 
|---|
| 75 | pp = strrchr(filename,'/'); | 
|---|
| 76 | p = (p) ? | 
|---|
| 77 | (pp) ? | 
|---|
| 78 | (p > pp) ? | 
|---|
| 79 | p : | 
|---|
| 80 | pp : | 
|---|
| 81 | p : | 
|---|
| 82 | pp; | 
|---|
| 83 | } | 
|---|
| 84 | if(!p)                  /* name is itself a root */ | 
|---|
| 85 | p = filename; | 
|---|
| 86 | else                    /* skip past backslash */ | 
|---|
| 87 | p++; | 
|---|
| 88 | return p; | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 |  | 
|---|
| 92 | int TestDates (char *file1,char *file2) | 
|---|
| 93 | { | 
|---|
| 94 | /* | 
|---|
| 95 | * return 1 (file2 newer than file1), | 
|---|
| 96 | * 0 (files same) | 
|---|
| 97 | * or -1 (file1 newer than file2) | 
|---|
| 98 | */ | 
|---|
| 99 |  | 
|---|
| 100 | int         comp = 0; | 
|---|
| 101 | FILESTATUS3 fs3o,fs3n; | 
|---|
| 102 |  | 
|---|
| 103 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 104 | if(!DosQueryPathInfo(file1, | 
|---|
| 105 | FIL_STANDARD, | 
|---|
| 106 | &fs3o, | 
|---|
| 107 | sizeof(fs3o))) { | 
|---|
| 108 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 109 | if(!DosQueryPathInfo(file2, | 
|---|
| 110 | FIL_STANDARD, | 
|---|
| 111 | &fs3n, | 
|---|
| 112 | sizeof(fs3n))) { | 
|---|
| 113 | comp = (fs3n.fdateLastWrite.year > | 
|---|
| 114 | fs3o.fdateLastWrite.year) ? 1 : | 
|---|
| 115 | (fs3n.fdateLastWrite.year < | 
|---|
| 116 | fs3o.fdateLastWrite.year) ? -1 : | 
|---|
| 117 | (fs3n.fdateLastWrite.month > | 
|---|
| 118 | fs3o.fdateLastWrite.month) ? 1 : | 
|---|
| 119 | (fs3n.fdateLastWrite.month < | 
|---|
| 120 | fs3o.fdateLastWrite.month) ? -1 : | 
|---|
| 121 | (fs3n.fdateLastWrite.day > | 
|---|
| 122 | fs3o.fdateLastWrite.day) ? 1 : | 
|---|
| 123 | (fs3n.fdateLastWrite.day < | 
|---|
| 124 | fs3o.fdateLastWrite.day) ? -1 : | 
|---|
| 125 | (fs3n.ftimeLastWrite.hours > | 
|---|
| 126 | fs3o.ftimeLastWrite.hours) ? 1 : | 
|---|
| 127 | (fs3n.ftimeLastWrite.hours < | 
|---|
| 128 | fs3o.ftimeLastWrite.hours) ? -1 : | 
|---|
| 129 | (fs3n.ftimeLastWrite.minutes > | 
|---|
| 130 | fs3o.ftimeLastWrite.minutes) ? 1 : | 
|---|
| 131 | (fs3n.ftimeLastWrite.minutes < | 
|---|
| 132 | fs3o.ftimeLastWrite.minutes) ? -1 : | 
|---|
| 133 | (fs3n.ftimeLastWrite.twosecs > | 
|---|
| 134 | fs3o.ftimeLastWrite.twosecs) ? 1 : | 
|---|
| 135 | (fs3n.ftimeLastWrite.twosecs < | 
|---|
| 136 | fs3o.ftimeLastWrite.twosecs) ? -1 : | 
|---|
| 137 | 0; | 
|---|
| 138 | } | 
|---|
| 139 | } | 
|---|
| 140 | return comp; | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 |  | 
|---|
| 144 | BOOL IsNewer (char *file1,char *file2) | 
|---|
| 145 | { | 
|---|
| 146 | /* return TRUE if file2 is newer than file1 */ | 
|---|
| 147 |  | 
|---|
| 148 | return (TestDates(file1,file2) > 0); | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 |  | 
|---|
| 152 | BOOL IsDesktop (HAB hab,HWND hwnd) | 
|---|
| 153 | { | 
|---|
| 154 | HWND hwndDesktop; | 
|---|
| 155 |  | 
|---|
| 156 | if(hwnd == HWND_DESKTOP) | 
|---|
| 157 | return TRUE; | 
|---|
| 158 | hwndDesktop = WinQueryDesktopWindow(hab,NULLHANDLE); | 
|---|
| 159 | if(hwnd == hwndDesktop) | 
|---|
| 160 | return TRUE; | 
|---|
| 161 | return FALSE; | 
|---|
| 162 | } | 
|---|
| 163 |  | 
|---|
| 164 | BOOL ParentIsDesktop (HWND hwnd,HWND hwndParent) | 
|---|
| 165 | { | 
|---|
| 166 | HWND hwndDesktop; | 
|---|
| 167 | BOOL ret = FALSE; | 
|---|
| 168 |  | 
|---|
| 169 | if(!hwndParent) | 
|---|
| 170 | hwndParent = WinQueryWindow(hwnd,QW_PARENT); | 
|---|
| 171 | if(hwndParent == HWND_DESKTOP) | 
|---|
| 172 | ret = TRUE; | 
|---|
| 173 | else { | 
|---|
| 174 | hwndDesktop = WinQueryDesktopWindow(WinQueryAnchorBlock(hwnd),(HWND)0); | 
|---|
| 175 | if(hwndDesktop == hwndParent) | 
|---|
| 176 | ret = TRUE; | 
|---|
| 177 | } | 
|---|
| 178 | return ret; | 
|---|
| 179 | } | 
|---|
| 180 |  | 
|---|
| 181 | /* CheckDrive | 
|---|
| 182 | * @param chDrive drive letter | 
|---|
| 183 | * @param pszFileSystem pointer to buffer to return file system type or NULL | 
|---|
| 184 | * @param pulType pointer to long word to return drive flags or NULL | 
|---|
| 185 | * @returns removability flag, 1 = removable, 0 = not removable, -1 = error | 
|---|
| 186 | */ | 
|---|
| 187 |  | 
|---|
| 188 | INT CheckDrive (CHAR chDrive, CHAR *pszFileSystem, ULONG *pulType) | 
|---|
| 189 | { | 
|---|
| 190 | CHAR          szPath[3]; | 
|---|
| 191 | VOID          *pvBuffer = NULL; | 
|---|
| 192 | CHAR          *pfsn; | 
|---|
| 193 | CHAR          *pfsd; | 
|---|
| 194 | ULONG         clBufferSize; | 
|---|
| 195 | APIRET        rc; | 
|---|
| 196 | ULONG         ulAction; | 
|---|
| 197 | ULONG         clParmBytes; | 
|---|
| 198 | ULONG         clDataBytes; | 
|---|
| 199 | HFILE         hDev; | 
|---|
| 200 | # pragma pack(1) | 
|---|
| 201 | struct { | 
|---|
| 202 | BYTE        Cmd; | 
|---|
| 203 | BYTE        Unit; | 
|---|
| 204 | } parmPkt = {0, 0}; | 
|---|
| 205 | # define BPB_REMOVABLE_MEDIA    0x08    // 3 - Media is removable | 
|---|
| 206 | struct | 
|---|
| 207 | { | 
|---|
| 208 | BIOSPARAMETERBLOCK bpb; | 
|---|
| 209 | USHORT cCylinders;                  // Documented but not implemented | 
|---|
| 210 | BYTE bDeviceType;                   // Documented but not implemented | 
|---|
| 211 | USHORT fsDeviceAttr;                // Documented but not implemented | 
|---|
| 212 | } dataPkt; | 
|---|
| 213 | # pragma pack() | 
|---|
| 214 | BYTE          NonRemovable; | 
|---|
| 215 | PFSQBUFFER2 pfsq; | 
|---|
| 216 |  | 
|---|
| 217 | if (pszFileSystem) | 
|---|
| 218 | *pszFileSystem = 0; | 
|---|
| 219 | if (pulType) | 
|---|
| 220 | *pulType = 0; | 
|---|
| 221 |  | 
|---|
| 222 | # define BUFFER_BYTES   4096 | 
|---|
| 223 | rc = DosAllocMem(&pvBuffer,BUFFER_BYTES,PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); | 
|---|
| 224 | if (rc) { | 
|---|
| 225 | Dos_Error(MB_CANCEL,rc,HWND_DESKTOP,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY)); | 
|---|
| 226 | return -1;                          // Say failed | 
|---|
| 227 | } | 
|---|
| 228 |  | 
|---|
| 229 | szPath[0] = chDrive; | 
|---|
| 230 | szPath[1] = ':'; | 
|---|
| 231 | szPath[2] = 0; | 
|---|
| 232 | clBufferSize = BUFFER_BYTES; | 
|---|
| 233 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 234 | rc = DosQueryFSAttach(szPath, 0, FSAIL_QUERYNAME, | 
|---|
| 235 | (PFSQBUFFER2)pvBuffer, &clBufferSize); | 
|---|
| 236 | if (rc) | 
|---|
| 237 | { | 
|---|
| 238 | /* can't get any info at all */ | 
|---|
| 239 | DosFreeMem(pvBuffer); | 
|---|
| 240 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 241 | return -1;                          // Say failed | 
|---|
| 242 | } | 
|---|
| 243 |  | 
|---|
| 244 | pfsq = (PFSQBUFFER2)pvBuffer; | 
|---|
| 245 | pfsn = pfsq->szName + pfsq->cbName + 1; | 
|---|
| 246 | pfsd = pfsn + pfsq->cbFSDName + 1; | 
|---|
| 247 |  | 
|---|
| 248 | if (pszFileSystem) | 
|---|
| 249 | { | 
|---|
| 250 | strncpy(pszFileSystem, pfsn, CCHMAXPATH); | 
|---|
| 251 | pszFileSystem[CCHMAXPATH - 1] = 0; | 
|---|
| 252 | } | 
|---|
| 253 |  | 
|---|
| 254 | if (pulType && !strcmp(pfsn,CDFS)) | 
|---|
| 255 | *pulType |= DRIVE_NOTWRITEABLE | DRIVE_CDROM | DRIVE_REMOVABLE; | 
|---|
| 256 |  | 
|---|
| 257 | if (((PFSQBUFFER2)pvBuffer)->iType == FSAT_REMOTEDRV) | 
|---|
| 258 | { | 
|---|
| 259 | if (pulType) | 
|---|
| 260 | *pulType |= DRIVE_REMOTE; | 
|---|
| 261 | if (pulType && !strcmp(pfsn,CBSIFS)) | 
|---|
| 262 | { | 
|---|
| 263 | *pulType |= DRIVE_ZIPSTREAM; | 
|---|
| 264 | *pulType &= ~DRIVE_REMOTE; | 
|---|
| 265 | *pulType |= DRIVE_NOLONGNAMES; | 
|---|
| 266 | if (pfsq->cbFSAData) | 
|---|
| 267 | { | 
|---|
| 268 | ULONG FType; | 
|---|
| 269 |  | 
|---|
| 270 | if (CheckDrive(*pfsd,NULL,&FType) != -1) | 
|---|
| 271 | { | 
|---|
| 272 | if (FType & DRIVE_REMOVABLE) | 
|---|
| 273 | *pulType |= DRIVE_REMOVABLE; | 
|---|
| 274 | if (~FType & DRIVE_NOLONGNAMES) | 
|---|
| 275 | *pulType &= ~DRIVE_NOLONGNAMES; | 
|---|
| 276 | } | 
|---|
| 277 | } | 
|---|
| 278 | } | 
|---|
| 279 | if (pulType && | 
|---|
| 280 | (!strcmp(pfsn,HPFS) || | 
|---|
| 281 | !strcmp(pfsn,JFS) || | 
|---|
| 282 | !strcmp(pfsn,FAT32) || | 
|---|
| 283 | !strcmp(pfsn,HPFS386))) | 
|---|
| 284 | { | 
|---|
| 285 | *pulType &= ~DRIVE_NOLONGNAMES; | 
|---|
| 286 | } | 
|---|
| 287 | DosFreeMem(pvBuffer); | 
|---|
| 288 | return 0;                           // Remotes are non-removable | 
|---|
| 289 | } | 
|---|
| 290 |  | 
|---|
| 291 | // Local drive | 
|---|
| 292 | if (strcmp(pfsn,HPFS) && | 
|---|
| 293 | strcmp(pfsn,JFS) && | 
|---|
| 294 | strcmp(pfsn,CDFS) && | 
|---|
| 295 | strcmp(pfsn,FAT32) && | 
|---|
| 296 | strcmp(pfsn,HPFS386)) | 
|---|
| 297 | { | 
|---|
| 298 | if(pulType) | 
|---|
| 299 | (*pulType) |= DRIVE_NOLONGNAMES;  // Others can not have long names | 
|---|
| 300 | } | 
|---|
| 301 |  | 
|---|
| 302 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 303 | rc = DosOpen(szPath, &hDev, &ulAction, 0, 0, FILE_OPEN, | 
|---|
| 304 | OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE | | 
|---|
| 305 | OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR, 0); | 
|---|
| 306 | if(rc) | 
|---|
| 307 | { | 
|---|
| 308 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 309 | if (pulType) | 
|---|
| 310 | *pulType |= DRIVE_REMOVABLE;      // Assume removable if can not access | 
|---|
| 311 | DosFreeMem(pvBuffer); | 
|---|
| 312 | return 1;                           // Say removable | 
|---|
| 313 | } | 
|---|
| 314 |  | 
|---|
| 315 | clParmBytes = sizeof(parmPkt.Cmd); | 
|---|
| 316 | clDataBytes = sizeof(NonRemovable); | 
|---|
| 317 | NonRemovable = 1;                     // Preset as non removable | 
|---|
| 318 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 319 | rc = DosDevIOCtl(hDev, IOCTL_DISK, DSK_BLOCKREMOVABLE, | 
|---|
| 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 | &NonRemovable,             /*  Address of the data area. */ | 
|---|
| 324 | sizeof(NonRemovable),      /*  Length, in bytes, of pData. */ | 
|---|
| 325 | &clDataBytes);             /*  Pointer to the length of data. */ | 
|---|
| 326 |  | 
|---|
| 327 | if (!rc && NonRemovable) { | 
|---|
| 328 | // Could be USB so check BPB flags | 
|---|
| 329 | clParmBytes = sizeof(parmPkt.Cmd); | 
|---|
| 330 | clDataBytes = sizeof(dataPkt); | 
|---|
| 331 | memset(&dataPkt, 0xff, sizeof(dataPkt)); | 
|---|
| 332 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 333 | rc = DosDevIOCtl(hDev, IOCTL_DISK, DSK_GETDEVICEPARAMS, | 
|---|
| 334 | &parmPkt.Cmd,            /*  Address of the command-specific argument list. */ | 
|---|
| 335 | sizeof(parmPkt.Cmd),     /*  Length, in bytes, of pParams. */ | 
|---|
| 336 | &clParmBytes,            /*  Pointer to the length of parameters. */ | 
|---|
| 337 | &dataPkt,                /*  Address of the data area. */ | 
|---|
| 338 | sizeof(dataPkt),         /*  Length, in bytes, of pData. */ | 
|---|
| 339 | &clDataBytes);           /*  Pointer to the length of data. */ | 
|---|
| 340 |  | 
|---|
| 341 | if (!rc && (dataPkt.bpb.fsDeviceAttr & BPB_REMOVABLE_MEDIA)) | 
|---|
| 342 | NonRemovable = 0; | 
|---|
| 343 | } | 
|---|
| 344 |  | 
|---|
| 345 | DosClose(hDev); | 
|---|
| 346 |  | 
|---|
| 347 | if (!NonRemovable && pulType) | 
|---|
| 348 | *pulType |= DRIVE_REMOVABLE; | 
|---|
| 349 |  | 
|---|
| 350 | DosFreeMem(pvBuffer); | 
|---|
| 351 |  | 
|---|
| 352 | return NonRemovable ? 0 : 1; | 
|---|
| 353 | } | 
|---|
| 354 |  | 
|---|
| 355 |  | 
|---|
| 356 | BOOL IsFileSame (CHAR *filename1,CHAR *filename2) | 
|---|
| 357 | { | 
|---|
| 358 | /* returns:  -1 (error), 0 (is a directory), or 1 (is a file) */ | 
|---|
| 359 |  | 
|---|
| 360 | FILESTATUS3 fsa1,fsa2; | 
|---|
| 361 | APIRET      ret; | 
|---|
| 362 |  | 
|---|
| 363 | if(filename1 && filename2) { | 
|---|
| 364 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 365 | ret = DosQueryPathInfo(filename1,FIL_STANDARD,&fsa1, | 
|---|
| 366 | (ULONG)sizeof(fsa1)); | 
|---|
| 367 | if(!ret) { | 
|---|
| 368 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 369 | ret = DosQueryPathInfo(filename2,FIL_STANDARD,&fsa2, | 
|---|
| 370 | (ULONG)sizeof(fsa2)); | 
|---|
| 371 | if(!ret) { | 
|---|
| 372 | if(fsa1.cbFile == fsa2.cbFile && | 
|---|
| 373 | (fsa1.attrFile & (~FILE_ARCHIVED)) == | 
|---|
| 374 | (fsa2.attrFile & (~FILE_ARCHIVED))) | 
|---|
| 375 | return TRUE; | 
|---|
| 376 | } | 
|---|
| 377 | } | 
|---|
| 378 | } | 
|---|
| 379 | return FALSE; | 
|---|
| 380 | } | 
|---|
| 381 |  | 
|---|
| 382 |  | 
|---|
| 383 | INT IsFile (CHAR *filename) | 
|---|
| 384 | { | 
|---|
| 385 | /* returns:  -1 (error), 0 (is a directory), or 1 (is a file) */ | 
|---|
| 386 |  | 
|---|
| 387 | FILESTATUS3 fsa; | 
|---|
| 388 | APIRET      ret; | 
|---|
| 389 |  | 
|---|
| 390 | if(filename && *filename) { | 
|---|
| 391 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 392 | ret = DosQueryPathInfo(filename, | 
|---|
| 393 | FIL_STANDARD, | 
|---|
| 394 | &fsa, | 
|---|
| 395 | (ULONG)sizeof(fsa)); | 
|---|
| 396 | if(!ret) | 
|---|
| 397 | return ((fsa.attrFile & FILE_DIRECTORY) == 0); | 
|---|
| 398 | else if(IsValidDrive(*filename) && IsRoot(filename)) | 
|---|
| 399 | return 0; | 
|---|
| 400 | } | 
|---|
| 401 | return -1;  /* error; doesn't exist or can't read or null filename */ | 
|---|
| 402 | } | 
|---|
| 403 |  | 
|---|
| 404 |  | 
|---|
| 405 | BOOL IsFullName (CHAR *filename) | 
|---|
| 406 | { | 
|---|
| 407 | return (filename) ? | 
|---|
| 408 | (isalpha(*filename) && filename[1] == ':' && filename[2] == '\\') : | 
|---|
| 409 | 0; | 
|---|
| 410 | } | 
|---|
| 411 |  | 
|---|
| 412 |  | 
|---|
| 413 | BOOL IsRoot (CHAR *filename) | 
|---|
| 414 | { | 
|---|
| 415 | return (filename && isalpha(*filename) && filename[1] == ':' && | 
|---|
| 416 | filename[2] == '\\' && !filename[3]); | 
|---|
| 417 | } | 
|---|
| 418 |  | 
|---|
| 419 |  | 
|---|
| 420 | BOOL IsValidDir (CHAR *path) | 
|---|
| 421 | { | 
|---|
| 422 | CHAR        fullname[CCHMAXPATH]; | 
|---|
| 423 | FILESTATUS3 fs; | 
|---|
| 424 |  | 
|---|
| 425 | if(path) { | 
|---|
| 426 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 427 | if(!DosQueryPathInfo(path, | 
|---|
| 428 | FIL_QUERYFULLNAME, | 
|---|
| 429 | fullname, | 
|---|
| 430 | sizeof(fullname))) { | 
|---|
| 431 | if(IsValidDrive(*fullname)) { | 
|---|
| 432 | if(!IsRoot(fullname)) { | 
|---|
| 433 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 434 | if(!DosQueryPathInfo(fullname, | 
|---|
| 435 | FIL_STANDARD, | 
|---|
| 436 | &fs, | 
|---|
| 437 | sizeof(fs)) && | 
|---|
| 438 | (fs.attrFile & FILE_DIRECTORY)) | 
|---|
| 439 | return TRUE; | 
|---|
| 440 | } | 
|---|
| 441 | else | 
|---|
| 442 | return TRUE; | 
|---|
| 443 | } | 
|---|
| 444 | } | 
|---|
| 445 | } | 
|---|
| 446 | return FALSE; | 
|---|
| 447 | } | 
|---|
| 448 |  | 
|---|
| 449 |  | 
|---|
| 450 | BOOL IsValidDrive (CHAR drive) | 
|---|
| 451 | { | 
|---|
| 452 | CHAR   Path[] = " :",Buffer[256]; | 
|---|
| 453 | APIRET Status; | 
|---|
| 454 | ULONG  Size; | 
|---|
| 455 | ULONG  ulDriveNum,ulDriveMap; | 
|---|
| 456 |  | 
|---|
| 457 | if(!isalpha(drive) || | 
|---|
| 458 | (driveflags[toupper(drive) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID))) | 
|---|
| 459 | return FALSE; | 
|---|
| 460 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 461 | Status = DosQCurDisk(&ulDriveNum,&ulDriveMap); | 
|---|
| 462 | if(!Status) { | 
|---|
| 463 | if(!(ulDriveMap & (1L << (ULONG)(toupper(drive) - 'A')))) | 
|---|
| 464 | return FALSE; | 
|---|
| 465 | Path[0] = toupper(drive); | 
|---|
| 466 | Size = sizeof(Buffer); | 
|---|
| 467 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 468 | Status = DosQueryFSAttach(Path, | 
|---|
| 469 | 0, | 
|---|
| 470 | FSAIL_QUERYNAME, | 
|---|
| 471 | (PFSQBUFFER2)Buffer, | 
|---|
| 472 | &Size); | 
|---|
| 473 | } | 
|---|
| 474 | return (Status == 0); | 
|---|
| 475 | } | 
|---|
| 476 |  | 
|---|
| 477 | //=== MakeValidDir() build valid directory name === | 
|---|
| 478 |  | 
|---|
| 479 | CHAR *MakeValidDir(CHAR *path) | 
|---|
| 480 | { | 
|---|
| 481 | ULONG         ulDrv; | 
|---|
| 482 | CHAR          *p; | 
|---|
| 483 | FILESTATUS3   fs; | 
|---|
| 484 | APIRET        rc; | 
|---|
| 485 |  | 
|---|
| 486 | if (!MakeFullName(path)) { | 
|---|
| 487 | if (IsValidDrive(*path)) { | 
|---|
| 488 | // Passed name is valid - trim to directory | 
|---|
| 489 | for (;;) { | 
|---|
| 490 | if (IsRoot(path)) | 
|---|
| 491 | return path; | 
|---|
| 492 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 493 | rc = DosQueryPathInfo(path, | 
|---|
| 494 | FIL_STANDARD, | 
|---|
| 495 | &fs, | 
|---|
| 496 | sizeof(fs)); | 
|---|
| 497 | if (!rc && (fs.attrFile & FILE_DIRECTORY)) | 
|---|
| 498 | return path; | 
|---|
| 499 | p = strrchr(path,'\\'); | 
|---|
| 500 | if (p) { | 
|---|
| 501 | if (p < path + 3) | 
|---|
| 502 | p++; | 
|---|
| 503 | *p = 0; | 
|---|
| 504 | } | 
|---|
| 505 | else | 
|---|
| 506 | break; | 
|---|
| 507 | } | 
|---|
| 508 | } | 
|---|
| 509 | } | 
|---|
| 510 | // Fall back to boot drive | 
|---|
| 511 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 512 | if (!DosQuerySysInfo(QSV_BOOT_DRIVE, | 
|---|
| 513 | QSV_BOOT_DRIVE, | 
|---|
| 514 | &ulDrv, | 
|---|
| 515 | sizeof(ulDrv))) { | 
|---|
| 516 | ulDrv += '@'; | 
|---|
| 517 | if (ulDrv < 'C') | 
|---|
| 518 | ulDrv = 'C'; | 
|---|
| 519 | strcpy(path," :\\"); | 
|---|
| 520 | *path = (CHAR)ulDrv; | 
|---|
| 521 | } | 
|---|
| 522 | else | 
|---|
| 523 | save_dir2(path);    // Fall back to fm3.ini drive or current dir - should never occur | 
|---|
| 524 | return path; | 
|---|
| 525 | } | 
|---|
| 526 |  | 
|---|
| 527 |  | 
|---|
| 528 | BOOL IsExecutable (CHAR *filename) | 
|---|
| 529 | { | 
|---|
| 530 | register CHAR *p; | 
|---|
| 531 | APIRET         ret; | 
|---|
| 532 | ULONG          apptype; | 
|---|
| 533 |  | 
|---|
| 534 | if(filename) { | 
|---|
| 535 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 536 | p = strrchr(filename,'.'); | 
|---|
| 537 | if(p) | 
|---|
| 538 | ret = DosQAppType(filename, | 
|---|
| 539 | &apptype); | 
|---|
| 540 | else { | 
|---|
| 541 |  | 
|---|
| 542 | char fname[CCHMAXPATH + 2]; | 
|---|
| 543 |  | 
|---|
| 544 | strcpy(fname,filename); | 
|---|
| 545 | strcat(fname,"."); | 
|---|
| 546 | ret = DosQAppType(fname, | 
|---|
| 547 | &apptype); | 
|---|
| 548 | } | 
|---|
| 549 | if((!ret && (!apptype || | 
|---|
| 550 | (apptype & | 
|---|
| 551 | (FAPPTYP_NOTWINDOWCOMPAT | | 
|---|
| 552 | FAPPTYP_WINDOWCOMPAT | | 
|---|
| 553 | FAPPTYP_WINDOWAPI | | 
|---|
| 554 | FAPPTYP_BOUND | | 
|---|
| 555 | FAPPTYP_DOS | | 
|---|
| 556 | FAPPTYP_WINDOWSREAL | | 
|---|
| 557 | FAPPTYP_WINDOWSPROT | | 
|---|
| 558 | FAPPTYP_32BIT | | 
|---|
| 559 | 0x1000)))) || | 
|---|
| 560 | (p && | 
|---|
| 561 | (!stricmp(p,".CMD") || | 
|---|
| 562 | !stricmp(p,".BAT")))) | 
|---|
| 563 | return TRUE; | 
|---|
| 564 | } | 
|---|
| 565 | return FALSE; | 
|---|
| 566 | } | 
|---|
| 567 |  | 
|---|
| 568 |  | 
|---|
| 569 | VOID ArgDriveFlags (INT argc,CHAR **argv) | 
|---|
| 570 | { | 
|---|
| 571 | INT x; | 
|---|
| 572 |  | 
|---|
| 573 | for(x = 1;x < argc;x++) { | 
|---|
| 574 | if(*argv[x] == '/' && isalpha(argv[x][1])) { | 
|---|
| 575 |  | 
|---|
| 576 | CHAR *p = &argv[x][1]; | 
|---|
| 577 |  | 
|---|
| 578 | while(isalpha(*p)) { | 
|---|
| 579 | driveflags[toupper(*p) - 'A'] |= DRIVE_IGNORE; | 
|---|
| 580 | p++; | 
|---|
| 581 | } | 
|---|
| 582 | } | 
|---|
| 583 | else if(*argv[x] == ';' && isalpha(argv[x][1])) { | 
|---|
| 584 |  | 
|---|
| 585 | CHAR *p = &argv[x][1]; | 
|---|
| 586 |  | 
|---|
| 587 | while(isalpha(*p)) { | 
|---|
| 588 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOPRESCAN; | 
|---|
| 589 | p++; | 
|---|
| 590 | } | 
|---|
| 591 | } | 
|---|
| 592 | else if(*argv[x] == ',' && isalpha(argv[x][1])) { | 
|---|
| 593 |  | 
|---|
| 594 | CHAR *p = &argv[x][1]; | 
|---|
| 595 |  | 
|---|
| 596 | while(isalpha(*p)) { | 
|---|
| 597 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADICONS; | 
|---|
| 598 | p++; | 
|---|
| 599 | } | 
|---|
| 600 | } | 
|---|
| 601 | else if(*argv[x] == '`' && isalpha(argv[x][1])) { | 
|---|
| 602 |  | 
|---|
| 603 | CHAR *p = &argv[x][1]; | 
|---|
| 604 |  | 
|---|
| 605 | while(isalpha(*p)) { | 
|---|
| 606 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADSUBJS; | 
|---|
| 607 | p++; | 
|---|
| 608 | } | 
|---|
| 609 | } | 
|---|
| 610 | else if(*argv[x] == '\'' && isalpha(argv[x][1])) { | 
|---|
| 611 |  | 
|---|
| 612 | CHAR *p = &argv[x][1]; | 
|---|
| 613 |  | 
|---|
| 614 | while(isalpha(*p)) { | 
|---|
| 615 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADLONGS; | 
|---|
| 616 | p++; | 
|---|
| 617 | } | 
|---|
| 618 | } | 
|---|
| 619 | } | 
|---|
| 620 | } | 
|---|
| 621 |  | 
|---|
| 622 |  | 
|---|
| 623 | VOID DriveFlagsOne (INT x) | 
|---|
| 624 | { | 
|---|
| 625 | INT         removable; | 
|---|
| 626 | CHAR        szDrive[] = " :\\",FileSystem[CCHMAXPATH]; | 
|---|
| 627 | ULONG       drvtype; | 
|---|
| 628 |  | 
|---|
| 629 | *szDrive = (CHAR)(x + 'A'); | 
|---|
| 630 | *FileSystem = 0; | 
|---|
| 631 | drvtype = 0; | 
|---|
| 632 | removable = CheckDrive(*szDrive,FileSystem,&drvtype); | 
|---|
| 633 | driveserial[x] = -1; | 
|---|
| 634 | driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS | | 
|---|
| 635 | DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS | | 
|---|
| 636 | DRIVE_INCLUDEFILES | DRIVE_SLOW); | 
|---|
| 637 | if(removable != -1) | 
|---|
| 638 | { | 
|---|
| 639 | struct | 
|---|
| 640 | { | 
|---|
| 641 | ULONG serial; | 
|---|
| 642 | CHAR  volumelength; | 
|---|
| 643 | CHAR  volumelabel[CCHMAXPATH]; | 
|---|
| 644 | }      volser; | 
|---|
| 645 |  | 
|---|
| 646 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 647 | if(!DosQueryFSInfo((ULONG)x + 1,FSIL_VOLSER,&volser,sizeof(volser))) | 
|---|
| 648 | driveserial[x] = volser.serial; | 
|---|
| 649 | else | 
|---|
| 650 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 651 | } | 
|---|
| 652 | else | 
|---|
| 653 | driveflags[x] |= DRIVE_INVALID; | 
|---|
| 654 | driveflags[x] |= ((removable == -1 || removable == 1) ? | 
|---|
| 655 | DRIVE_REMOVABLE : 0); | 
|---|
| 656 | if(drvtype & DRIVE_REMOTE) | 
|---|
| 657 | driveflags[x] |= DRIVE_REMOTE; | 
|---|
| 658 | if (strcmp(FileSystem,HPFS) && | 
|---|
| 659 | strcmp(FileSystem,JFS) && | 
|---|
| 660 | strcmp(FileSystem,CDFS) && | 
|---|
| 661 | strcmp(FileSystem,FAT32) && | 
|---|
| 662 | strcmp(FileSystem,HPFS386)) | 
|---|
| 663 | { | 
|---|
| 664 | driveflags[x] |= DRIVE_NOLONGNAMES; | 
|---|
| 665 | } | 
|---|
| 666 | if(!strcmp(FileSystem,CDFS)) { | 
|---|
| 667 | removable = 1; | 
|---|
| 668 | driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOTWRITEABLE | | 
|---|
| 669 | DRIVE_CDROM); | 
|---|
| 670 | } | 
|---|
| 671 | else if(!stricmp(FileSystem,CBSIFS)) { | 
|---|
| 672 | driveflags[x] |= DRIVE_ZIPSTREAM; | 
|---|
| 673 | driveflags[x] &= (~DRIVE_REMOTE); | 
|---|
| 674 | if(drvtype & DRIVE_REMOVABLE) | 
|---|
| 675 | driveflags[x] |= DRIVE_REMOVABLE; | 
|---|
| 676 | if(!(drvtype & DRIVE_NOLONGNAMES)) | 
|---|
| 677 | driveflags[x] &= (~DRIVE_NOLONGNAMES); | 
|---|
| 678 | } | 
|---|
| 679 | } | 
|---|
| 680 |  | 
|---|
| 681 |  | 
|---|
| 682 | VOID FillInDriveFlags (VOID *dummy) | 
|---|
| 683 | { | 
|---|
| 684 | ULONG        ulDriveNum,ulDriveMap; | 
|---|
| 685 | register INT x; | 
|---|
| 686 |  | 
|---|
| 687 | for(x = 0;x < 26;x++) | 
|---|
| 688 | driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS | | 
|---|
| 689 | DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS | | 
|---|
| 690 | DRIVE_INCLUDEFILES | DRIVE_SLOW); | 
|---|
| 691 | memset(driveserial,-1,sizeof(driveserial)); | 
|---|
| 692 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 693 | DosQCurDisk(&ulDriveNum,&ulDriveMap); | 
|---|
| 694 | for(x = 0;x < 26;x++) { | 
|---|
| 695 | if(ulDriveMap & (1L << x) && !(driveflags[x] & DRIVE_IGNORE)) { | 
|---|
| 696 | { | 
|---|
| 697 | CHAR  s[80]; | 
|---|
| 698 | ULONG flags = 0,size = sizeof(ULONG); | 
|---|
| 699 |  | 
|---|
| 700 | sprintf(s,"%c.DriveFlags",(CHAR)(x + 'A')); | 
|---|
| 701 | if(PrfQueryProfileData(fmprof,appname,s,&flags,&size) && | 
|---|
| 702 | size == sizeof(ULONG)) | 
|---|
| 703 | driveflags[x] |= flags; | 
|---|
| 704 | } | 
|---|
| 705 |  | 
|---|
| 706 | if(x > 1) { | 
|---|
| 707 | if(!(driveflags[x] & DRIVE_NOPRESCAN)) | 
|---|
| 708 | DriveFlagsOne(x); | 
|---|
| 709 | else | 
|---|
| 710 | driveserial[x] = -1; | 
|---|
| 711 | } | 
|---|
| 712 | else { | 
|---|
| 713 | driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOLONGNAMES); | 
|---|
| 714 | driveserial[x] = -1; | 
|---|
| 715 | } | 
|---|
| 716 | } | 
|---|
| 717 | else if(!(ulDriveMap & (1L << x))) | 
|---|
| 718 | driveflags[x] |= DRIVE_INVALID; | 
|---|
| 719 | } | 
|---|
| 720 | { | 
|---|
| 721 | ULONG  startdrive = 3L; | 
|---|
| 722 |  | 
|---|
| 723 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 724 | DosQuerySysInfo(QSV_BOOT_DRIVE,QSV_BOOT_DRIVE, | 
|---|
| 725 | (PVOID)&startdrive,(ULONG)sizeof(ULONG)); | 
|---|
| 726 | if(startdrive) | 
|---|
| 727 | driveflags[startdrive - 1] |= DRIVE_BOOT; | 
|---|
| 728 | } | 
|---|
| 729 | } | 
|---|
| 730 |  | 
|---|
| 731 |  | 
|---|
| 732 | CHAR * assign_ignores (CHAR *s) | 
|---|
| 733 | { | 
|---|
| 734 | register INT   x; | 
|---|
| 735 | register CHAR *p,*pp; | 
|---|
| 736 |  | 
|---|
| 737 | *s = '/'; | 
|---|
| 738 | s[1] = 0; | 
|---|
| 739 | p = s + 1; | 
|---|
| 740 | if(s) { | 
|---|
| 741 | for(x = 0;x < 26;x++) { | 
|---|
| 742 | if((driveflags[x] & DRIVE_IGNORE) != 0) { | 
|---|
| 743 | *p = (CHAR)x + 'A'; | 
|---|
| 744 | p++; | 
|---|
| 745 | *p = 0; | 
|---|
| 746 | } | 
|---|
| 747 | } | 
|---|
| 748 | } | 
|---|
| 749 | if(!s[1]) { | 
|---|
| 750 | *s = 0; | 
|---|
| 751 | pp = s; | 
|---|
| 752 | } | 
|---|
| 753 | else { | 
|---|
| 754 | pp = &s[strlen(s)]; | 
|---|
| 755 | *pp = ' '; | 
|---|
| 756 | pp++; | 
|---|
| 757 | } | 
|---|
| 758 | *pp = ';'; | 
|---|
| 759 | pp[1] = 0; | 
|---|
| 760 | p = pp + 1; | 
|---|
| 761 | if(pp) { | 
|---|
| 762 | for(x = 0;x < 26;x++) { | 
|---|
| 763 | if((driveflags[x] & DRIVE_NOPRESCAN) != 0) { | 
|---|
| 764 | *p = (CHAR)x + 'A'; | 
|---|
| 765 | p++; | 
|---|
| 766 | *p = 0; | 
|---|
| 767 | } | 
|---|
| 768 | } | 
|---|
| 769 | } | 
|---|
| 770 | if(!pp[1]) | 
|---|
| 771 | *pp = 0; | 
|---|
| 772 | pp = &s[strlen(s)]; | 
|---|
| 773 | *pp = ' '; | 
|---|
| 774 | pp++; | 
|---|
| 775 | *pp = ','; | 
|---|
| 776 | pp[1] = 0; | 
|---|
| 777 | p = pp + 1; | 
|---|
| 778 | if(pp) { | 
|---|
| 779 | for(x = 0;x < 26;x++) { | 
|---|
| 780 | if((driveflags[x] & DRIVE_NOLOADICONS) != 0) { | 
|---|
| 781 | *p = (CHAR)x + 'A'; | 
|---|
| 782 | p++; | 
|---|
| 783 | *p = 0; | 
|---|
| 784 | } | 
|---|
| 785 | } | 
|---|
| 786 | } | 
|---|
| 787 | if(!pp[1]) | 
|---|
| 788 | *pp = 0; | 
|---|
| 789 | pp = &s[strlen(s)]; | 
|---|
| 790 | *pp = ' '; | 
|---|
| 791 | pp++; | 
|---|
| 792 | *pp = '`'; | 
|---|
| 793 | pp[1] = 0; | 
|---|
| 794 | p = pp + 1; | 
|---|
| 795 | if(pp) { | 
|---|
| 796 | for(x = 0;x < 26;x++) { | 
|---|
| 797 | if((driveflags[x] & DRIVE_NOLOADSUBJS) != 0) { | 
|---|
| 798 | *p = (CHAR)x + 'A'; | 
|---|
| 799 | p++; | 
|---|
| 800 | *p = 0; | 
|---|
| 801 | } | 
|---|
| 802 | } | 
|---|
| 803 | } | 
|---|
| 804 | if(!pp[1]) | 
|---|
| 805 | *pp = 0; | 
|---|
| 806 | pp = &s[strlen(s)]; | 
|---|
| 807 | *pp = ' '; | 
|---|
| 808 | pp++; | 
|---|
| 809 | *pp = '\''; | 
|---|
| 810 | pp[1] = 0; | 
|---|
| 811 | p = pp + 1; | 
|---|
| 812 | if(pp) { | 
|---|
| 813 | for(x = 0;x < 26;x++) { | 
|---|
| 814 | if((driveflags[x] & DRIVE_NOLOADLONGS) != 0) { | 
|---|
| 815 | *p = (CHAR)x + 'A'; | 
|---|
| 816 | p++; | 
|---|
| 817 | *p = 0; | 
|---|
| 818 | } | 
|---|
| 819 | } | 
|---|
| 820 | } | 
|---|
| 821 | if(!pp[1]) | 
|---|
| 822 | *pp = 0; | 
|---|
| 823 | bstrip(s); | 
|---|
| 824 | return s; | 
|---|
| 825 | } | 
|---|
| 826 |  | 
|---|
| 827 |  | 
|---|
| 828 | BOOL needs_quoting (register CHAR *f) | 
|---|
| 829 | { | 
|---|
| 830 | register CHAR *p = " &|<>"; | 
|---|
| 831 |  | 
|---|
| 832 | while(*p) { | 
|---|
| 833 | if(strchr(f,*p)) | 
|---|
| 834 | return TRUE; | 
|---|
| 835 | p++; | 
|---|
| 836 | } | 
|---|
| 837 | return FALSE; | 
|---|
| 838 | } | 
|---|
| 839 |  | 
|---|
| 840 |  | 
|---|
| 841 | BOOL IsBinary (register CHAR *str,ULONG len) | 
|---|
| 842 | { | 
|---|
| 843 | register ULONG x = 0L; | 
|---|
| 844 |  | 
|---|
| 845 | if(str) { | 
|---|
| 846 | while(x < len) { | 
|---|
| 847 | if(str[x] < ' ' && str[x] != '\r' && str[x] != '\n' && str[x] != '\t' && | 
|---|
| 848 | str[x] != '\x1b' && str[x] != '\x1a' && str[x] != '\07' && | 
|---|
| 849 | str[x] != '\x0c') | 
|---|
| 850 | return TRUE; | 
|---|
| 851 | x++; | 
|---|
| 852 | } | 
|---|
| 853 | } | 
|---|
| 854 | return FALSE; | 
|---|
| 855 | } | 
|---|
| 856 |  | 
|---|
| 857 |  | 
|---|
| 858 | BOOL TestBinary (CHAR *filename) | 
|---|
| 859 | { | 
|---|
| 860 | HFILE   handle; | 
|---|
| 861 | ULONG   ulAction; | 
|---|
| 862 | ULONG   len; | 
|---|
| 863 | APIRET  rc; | 
|---|
| 864 | CHAR    buff[512]; | 
|---|
| 865 |  | 
|---|
| 866 | if(filename) { | 
|---|
| 867 | if(!DosOpen(filename,&handle,&ulAction,0L,0L, | 
|---|
| 868 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, | 
|---|
| 869 | OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT | | 
|---|
| 870 | OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYNONE | | 
|---|
| 871 | OPEN_ACCESS_READONLY,0L)) { | 
|---|
| 872 | len = 512; | 
|---|
| 873 | rc = DosRead(handle,buff,len,&len); | 
|---|
| 874 | DosClose(handle); | 
|---|
| 875 | if(!rc && len) | 
|---|
| 876 | return IsBinary(buff,len); | 
|---|
| 877 | } | 
|---|
| 878 | } | 
|---|
| 879 | return FALSE; | 
|---|
| 880 | } | 
|---|
| 881 |  | 
|---|
| 882 |  | 
|---|
| 883 | char *IsVowel (char a) | 
|---|
| 884 | { | 
|---|
| 885 | return (strchr("aeiouAEIOU",a) != NULL) ? "n" : NullStr; | 
|---|
| 886 | } | 
|---|
| 887 |  | 
|---|
| 888 |  | 
|---|
| 889 | VOID GetDesktopName (CHAR *objectpath,ULONG size) | 
|---|
| 890 | { | 
|---|
| 891 | PFN     WQDPath; | 
|---|
| 892 | HMODULE hmod = 0; | 
|---|
| 893 | APIRET  rc; | 
|---|
| 894 | ULONG   startdrive = 3L; | 
|---|
| 895 | CHAR    objerr[CCHMAXPATH]; | 
|---|
| 896 |  | 
|---|
| 897 | if (!objectpath) { | 
|---|
| 898 | Runtime_Error(pszSrcFile, __LINE__, "null pointer"); | 
|---|
| 899 | return; | 
|---|
| 900 | } | 
|---|
| 901 | *objectpath = 0; | 
|---|
| 902 | if (OS2ver[0] > 20 || (OS2ver[0] == 20 && OS2ver[1] >= 30)) { | 
|---|
| 903 | /* | 
|---|
| 904 | * if running under warp, we can get the desktop name | 
|---|
| 905 | * this way... | 
|---|
| 906 | */ | 
|---|
| 907 | rc = DosLoadModule(objerr, | 
|---|
| 908 | sizeof(objerr), | 
|---|
| 909 | "PMWP", | 
|---|
| 910 | &hmod); | 
|---|
| 911 | if(!rc) { | 
|---|
| 912 | rc = DosQueryProcAddr(hmod, | 
|---|
| 913 | 262, | 
|---|
| 914 | NULL, | 
|---|
| 915 | &WQDPath); | 
|---|
| 916 | if(!rc) | 
|---|
| 917 | WQDPath(objectpath,size); | 
|---|
| 918 | DosFreeModule(hmod); | 
|---|
| 919 | } | 
|---|
| 920 | } | 
|---|
| 921 | if (!*objectpath) { | 
|---|
| 922 | // Fall back to INI content | 
|---|
| 923 | if (!PrfQueryProfileString(HINI_SYSTEMPROFILE, | 
|---|
| 924 | "FolderWorkareaRunningObjects", | 
|---|
| 925 | NULL, | 
|---|
| 926 | "\0", | 
|---|
| 927 | (PVOID)objectpath, | 
|---|
| 928 | sizeof(objectpath))) { | 
|---|
| 929 | Win_Error(HWND_DESKTOP,HWND_DESKTOP,pszSrcFile,__LINE__,"PrfQueryProfileString"); | 
|---|
| 930 | *objectpath = 0; | 
|---|
| 931 | } | 
|---|
| 932 | else if (!*objectpath || IsFile(objectpath)) { | 
|---|
| 933 | Runtime_Error(pszSrcFile, __LINE__, "bad FolderWorkareaRunningObjects"); | 
|---|
| 934 | *objectpath = 0; | 
|---|
| 935 | } | 
|---|
| 936 | if (!*objectpath) { | 
|---|
| 937 | // Fall back - fixme to work for NLS | 
|---|
| 938 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 939 | DosQuerySysInfo(QSV_BOOT_DRIVE,QSV_BOOT_DRIVE, | 
|---|
| 940 | (PVOID)&startdrive,(ULONG)sizeof(ULONG)); | 
|---|
| 941 | sprintf(objectpath, | 
|---|
| 942 | "%c:\\DESKTOP", | 
|---|
| 943 | ((CHAR)startdrive) + '@'); | 
|---|
| 944 | } | 
|---|
| 945 | } | 
|---|
| 946 | } | 
|---|