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