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