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