| [793] | 1 | 
 | 
|---|
 | 2 | /***********************************************************************
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 |   $Id: dirs.c 1673 2012-12-30 18:51:01Z gyoung $
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 |   Copyright (c) 1993-98 M. Kimes
 | 
|---|
| [1498] | 7 |   Copyright (c) 2003, 2010 Steven H.Levine
 | 
|---|
| [793] | 8 | 
 | 
|---|
 | 9 |   Directory manipulation
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 |   20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
 | 
|---|
| [1498] | 12 |   17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
 | 
|---|
| [793] | 13 | 
 | 
|---|
 | 14 | ***********************************************************************/
 | 
|---|
 | 15 | 
 | 
|---|
| [2] | 16 | #include <stdlib.h>
 | 
|---|
 | 17 | #include <string.h>
 | 
|---|
 | 18 | #include <ctype.h>
 | 
|---|
| [907] | 19 | 
 | 
|---|
| [1159] | 20 | #define INCL_LONGLONG                   // dircnrs.h
 | 
|---|
| [907] | 21 | 
 | 
|---|
| [2] | 22 | #include "fm3dll.h"
 | 
|---|
| [1206] | 23 | #include "init.h"                       // Data declaration(s)
 | 
|---|
| [1159] | 24 | #include "dirs.h"
 | 
|---|
 | 25 | #include "valid.h"                      // IsValidDir
 | 
|---|
| [2] | 26 | 
 | 
|---|
| [551] | 27 | APIRET save_dir2(CHAR * curdir)
 | 
|---|
 | 28 | {
 | 
|---|
| [1607] | 29 |   CHAR *env = getenv(PCSZ_FM3INI);
 | 
|---|
| [2] | 30 | 
 | 
|---|
| [551] | 31 |   if (env && *env) {
 | 
|---|
 | 32 |     strncpy(curdir, env, CCHMAXPATH);
 | 
|---|
| [2] | 33 |     curdir[CCHMAXPATH - 1] = 0;
 | 
|---|
| [551] | 34 |     if (IsValidDir(curdir))
 | 
|---|
| [2] | 35 |       return 0;
 | 
|---|
 | 36 |     else {
 | 
|---|
| [551] | 37 |       env = strrchr(curdir, '\\');
 | 
|---|
 | 38 |       if (env) {
 | 
|---|
| [1159] | 39 |         *env = 0;
 | 
|---|
 | 40 |         if (IsValidDir(curdir))
 | 
|---|
 | 41 |           return 0;
 | 
|---|
| [2] | 42 |       }
 | 
|---|
 | 43 |     }
 | 
|---|
 | 44 |   }
 | 
|---|
 | 45 |   return save_dir(curdir);
 | 
|---|
 | 46 | }
 | 
|---|
 | 47 | 
 | 
|---|
| [551] | 48 | APIRET save_dir(CHAR * curdir)
 | 
|---|
 | 49 | {
 | 
|---|
 | 50 |   APIRET ret;
 | 
|---|
 | 51 |   ULONG curdirlen, curdrive, drivemap;
 | 
|---|
| [2] | 52 | 
 | 
|---|
 | 53 |   *curdir = 0;
 | 
|---|
| [551] | 54 |   ret = DosQCurDisk(&curdrive, &drivemap);
 | 
|---|
| [1673] | 55 |   curdirlen = CCHMAXPATH - 4;           // NOTE!!!!!!!!!
 | 
|---|
| [1321] | 56 |   ret += DosQCurDir(curdrive, (PBYTE)&curdir[3], &curdirlen);
 | 
|---|
| [551] | 57 |   *curdir = (CHAR) ('@' + (INT) curdrive);
 | 
|---|
| [2] | 58 |   curdir[1] = ':';
 | 
|---|
 | 59 |   curdir[2] = '\\';
 | 
|---|
 | 60 |   return ret;
 | 
|---|
 | 61 | }
 | 
|---|
 | 62 | 
 | 
|---|
| [551] | 63 | APIRET switch_to(CHAR * s)
 | 
|---|
 | 64 | {
 | 
|---|
| [2] | 65 | 
 | 
|---|
| [551] | 66 |   APIRET ret;
 | 
|---|
| [843] | 67 |   FILESTATUS3 fsa;
 | 
|---|
| [551] | 68 |   CHAR path[CCHMAXPATH + 1], *p;
 | 
|---|
| [2] | 69 | 
 | 
|---|
| [551] | 70 |   strcpy(path, s);
 | 
|---|
 | 71 |   while (*path) {
 | 
|---|
| [843] | 72 |     ret = DosQueryPathInfo(path, FIL_STANDARD, &fsa, sizeof(fsa));
 | 
|---|
| [551] | 73 |     if (ret || !(fsa.attrFile & FILE_DIRECTORY)) {
 | 
|---|
 | 74 |       p = strrchr(path, '\\');
 | 
|---|
 | 75 |       if (p)
 | 
|---|
| [1159] | 76 |         *p = 0;
 | 
|---|
| [2] | 77 |       else {
 | 
|---|
| [1159] | 78 |         strcpy(path, s);
 | 
|---|
 | 79 |         break;
 | 
|---|
| [2] | 80 |       }
 | 
|---|
 | 81 |     }
 | 
|---|
 | 82 |     else
 | 
|---|
 | 83 |       break;
 | 
|---|
 | 84 |   }
 | 
|---|
| [551] | 85 |   if (isalpha(*path) && path[1] == ':') {
 | 
|---|
| [2] | 86 | 
 | 
|---|
| [551] | 87 |     ULONG curdrive, drivemap;
 | 
|---|
| [2] | 88 | 
 | 
|---|
| [551] | 89 |     if (!DosQCurDisk(&curdrive, &drivemap)) {
 | 
|---|
 | 90 |       if ((CHAR) ((CHAR) curdrive + '@') != (CHAR) toupper(*HomePath) &&
 | 
|---|
| [1159] | 91 |           (CHAR) ((CHAR) curdrive + '@') != (CHAR) toupper(*path))
 | 
|---|
| [1498] | 92 |         DosChDir((CHAR *) PCSZ_BACKSLASH);
 | 
|---|
| [2] | 93 |     }
 | 
|---|
 | 94 |     ret = DosSelectDisk(toupper(*path) - '@');
 | 
|---|
 | 95 |     return (ret) ? ret : DosChDir(path);
 | 
|---|
 | 96 |   }
 | 
|---|
 | 97 |   return DosChDir(path);
 | 
|---|
 | 98 | }
 | 
|---|
| [793] | 99 | 
 | 
|---|
 | 100 | #pragma alloc_text(MISC9,save_dir,save_dir2,switch_to)
 | 
|---|