| [793] | 1 |  | 
|---|
|  | 2 | /*********************************************************************** | 
|---|
|  | 3 |  | 
|---|
|  | 4 | $Id: dirs.c 907 2008-01-06 07:26:17Z stevenhl $ | 
|---|
|  | 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 |  | 
|---|
|  | 19 | #define INCL_LONGLONG                   // dircnrs.h | 
|---|
|  | 20 |  | 
|---|
| [2] | 21 | #include "fm3dll.h" | 
|---|
|  | 22 |  | 
|---|
| [551] | 23 | APIRET save_dir2(CHAR * curdir) | 
|---|
|  | 24 | { | 
|---|
| [2] | 25 | CHAR *env = getenv("FM3INI"); | 
|---|
|  | 26 |  | 
|---|
| [551] | 27 | if (env && *env) { | 
|---|
|  | 28 | strncpy(curdir, env, CCHMAXPATH); | 
|---|
| [2] | 29 | curdir[CCHMAXPATH - 1] = 0; | 
|---|
| [551] | 30 | if (IsValidDir(curdir)) | 
|---|
| [2] | 31 | return 0; | 
|---|
|  | 32 | else { | 
|---|
| [551] | 33 | env = strrchr(curdir, '\\'); | 
|---|
|  | 34 | if (env) { | 
|---|
|  | 35 | *env = 0; | 
|---|
|  | 36 | if (IsValidDir(curdir)) | 
|---|
|  | 37 | return 0; | 
|---|
| [2] | 38 | } | 
|---|
|  | 39 | } | 
|---|
|  | 40 | } | 
|---|
|  | 41 | return save_dir(curdir); | 
|---|
|  | 42 | } | 
|---|
|  | 43 |  | 
|---|
| [551] | 44 | APIRET save_dir(CHAR * curdir) | 
|---|
|  | 45 | { | 
|---|
| [2] | 46 |  | 
|---|
| [551] | 47 | APIRET ret; | 
|---|
|  | 48 | ULONG curdirlen, curdrive, drivemap; | 
|---|
| [2] | 49 |  | 
|---|
|  | 50 | *curdir = 0; | 
|---|
| [551] | 51 | ret = DosQCurDisk(&curdrive, &drivemap); | 
|---|
|  | 52 | curdirlen = CCHMAXPATH - 4;           /* NOTE!!!!!!!!! */ | 
|---|
|  | 53 | ret += DosQCurDir(curdrive, &curdir[3], &curdirlen); | 
|---|
|  | 54 | *curdir = (CHAR) ('@' + (INT) curdrive); | 
|---|
| [2] | 55 | curdir[1] = ':'; | 
|---|
|  | 56 | curdir[2] = '\\'; | 
|---|
|  | 57 | return ret; | 
|---|
|  | 58 | } | 
|---|
|  | 59 |  | 
|---|
| [551] | 60 | APIRET switch_to(CHAR * s) | 
|---|
|  | 61 | { | 
|---|
| [2] | 62 |  | 
|---|
| [551] | 63 | APIRET ret; | 
|---|
| [843] | 64 | FILESTATUS3 fsa; | 
|---|
| [551] | 65 | CHAR path[CCHMAXPATH + 1], *p; | 
|---|
| [2] | 66 |  | 
|---|
| [551] | 67 | strcpy(path, s); | 
|---|
|  | 68 | while (*path) { | 
|---|
| [843] | 69 | ret = DosQueryPathInfo(path, FIL_STANDARD, &fsa, sizeof(fsa)); | 
|---|
| [551] | 70 | if (ret || !(fsa.attrFile & FILE_DIRECTORY)) { | 
|---|
|  | 71 | p = strrchr(path, '\\'); | 
|---|
|  | 72 | if (p) | 
|---|
|  | 73 | *p = 0; | 
|---|
| [2] | 74 | else { | 
|---|
| [551] | 75 | strcpy(path, s); | 
|---|
|  | 76 | break; | 
|---|
| [2] | 77 | } | 
|---|
|  | 78 | } | 
|---|
|  | 79 | else | 
|---|
|  | 80 | break; | 
|---|
|  | 81 | } | 
|---|
| [551] | 82 | if (isalpha(*path) && path[1] == ':') { | 
|---|
| [2] | 83 |  | 
|---|
| [551] | 84 | ULONG curdrive, drivemap; | 
|---|
| [2] | 85 |  | 
|---|
| [551] | 86 | if (!DosQCurDisk(&curdrive, &drivemap)) { | 
|---|
|  | 87 | if ((CHAR) ((CHAR) curdrive + '@') != (CHAR) toupper(*HomePath) && | 
|---|
|  | 88 | (CHAR) ((CHAR) curdrive + '@') != (CHAR) toupper(*path)) | 
|---|
|  | 89 | DosChDir("\\"); | 
|---|
| [2] | 90 | } | 
|---|
|  | 91 | ret = DosSelectDisk(toupper(*path) - '@'); | 
|---|
|  | 92 | return (ret) ? ret : DosChDir(path); | 
|---|
|  | 93 | } | 
|---|
|  | 94 | return DosChDir(path); | 
|---|
|  | 95 | } | 
|---|
| [793] | 96 |  | 
|---|
|  | 97 | #pragma alloc_text(MISC9,save_dir,save_dir2,switch_to) | 
|---|