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