[2] | 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 |
|
---|
[551] | 16 | APIRET save_dir2(CHAR * curdir)
|
---|
| 17 | {
|
---|
[2] | 18 |
|
---|
| 19 | CHAR *env = getenv("FM3INI");
|
---|
| 20 |
|
---|
[551] | 21 | if (env && *env) {
|
---|
| 22 | strncpy(curdir, env, CCHMAXPATH);
|
---|
[2] | 23 | curdir[CCHMAXPATH - 1] = 0;
|
---|
[551] | 24 | if (IsValidDir(curdir))
|
---|
[2] | 25 | return 0;
|
---|
| 26 | else {
|
---|
[551] | 27 | env = strrchr(curdir, '\\');
|
---|
| 28 | if (env) {
|
---|
| 29 | *env = 0;
|
---|
| 30 | if (IsValidDir(curdir))
|
---|
| 31 | return 0;
|
---|
[2] | 32 | }
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 | return save_dir(curdir);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[551] | 38 | APIRET save_dir(CHAR * curdir)
|
---|
| 39 | {
|
---|
[2] | 40 |
|
---|
[551] | 41 | APIRET ret;
|
---|
| 42 | ULONG curdirlen, curdrive, drivemap;
|
---|
[2] | 43 |
|
---|
| 44 | *curdir = 0;
|
---|
[551] | 45 | ret = DosQCurDisk(&curdrive, &drivemap);
|
---|
| 46 | curdirlen = CCHMAXPATH - 4; /* NOTE!!!!!!!!! */
|
---|
| 47 | ret += DosQCurDir(curdrive, &curdir[3], &curdirlen);
|
---|
| 48 | *curdir = (CHAR) ('@' + (INT) curdrive);
|
---|
[2] | 49 | curdir[1] = ':';
|
---|
| 50 | curdir[2] = '\\';
|
---|
| 51 | return ret;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[551] | 54 | APIRET switch_to(CHAR * s)
|
---|
| 55 | {
|
---|
[2] | 56 |
|
---|
[551] | 57 | APIRET ret;
|
---|
[2] | 58 | FILESTATUS3 fsa;
|
---|
[551] | 59 | CHAR path[CCHMAXPATH + 1], *p;
|
---|
[2] | 60 |
|
---|
[551] | 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;
|
---|
[2] | 69 | else {
|
---|
[551] | 70 | strcpy(path, s);
|
---|
| 71 | break;
|
---|
[2] | 72 | }
|
---|
| 73 | }
|
---|
| 74 | else
|
---|
| 75 | break;
|
---|
| 76 | }
|
---|
[551] | 77 | if (isalpha(*path) && path[1] == ':') {
|
---|
[2] | 78 |
|
---|
[551] | 79 | ULONG curdrive, drivemap;
|
---|
[2] | 80 |
|
---|
[551] | 81 | if (!DosQCurDisk(&curdrive, &drivemap)) {
|
---|
| 82 | if ((CHAR) ((CHAR) curdrive + '@') != (CHAR) toupper(*HomePath) &&
|
---|
| 83 | (CHAR) ((CHAR) curdrive + '@') != (CHAR) toupper(*path))
|
---|
| 84 | DosChDir("\\");
|
---|
[2] | 85 | }
|
---|
| 86 | ret = DosSelectDisk(toupper(*path) - '@');
|
---|
| 87 | return (ret) ? ret : DosChDir(path);
|
---|
| 88 | }
|
---|
| 89 | return DosChDir(path);
|
---|
| 90 | }
|
---|