[793] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: dirs.c 841 2007-09-23 16:27:51Z 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 |
|
---|
[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;
|
---|
[841] | 71 | FILESTATUS3L fsa;
|
---|
[551] | 72 | CHAR path[CCHMAXPATH + 1], *p;
|
---|
[2] | 73 |
|
---|
[551] | 74 | strcpy(path, s);
|
---|
| 75 | while (*path) {
|
---|
[841] | 76 | ret = DosQueryPathInfo(path, FIL_STANDARDL, &fsa,
|
---|
| 77 | (ULONG) sizeof(FILESTATUS3L));
|
---|
[551] | 78 | if (ret || !(fsa.attrFile & FILE_DIRECTORY)) {
|
---|
| 79 | p = strrchr(path, '\\');
|
---|
| 80 | if (p)
|
---|
| 81 | *p = 0;
|
---|
[2] | 82 | else {
|
---|
[551] | 83 | strcpy(path, s);
|
---|
| 84 | break;
|
---|
[2] | 85 | }
|
---|
| 86 | }
|
---|
| 87 | else
|
---|
| 88 | break;
|
---|
| 89 | }
|
---|
[551] | 90 | if (isalpha(*path) && path[1] == ':') {
|
---|
[2] | 91 |
|
---|
[551] | 92 | ULONG curdrive, drivemap;
|
---|
[2] | 93 |
|
---|
[551] | 94 | if (!DosQCurDisk(&curdrive, &drivemap)) {
|
---|
| 95 | if ((CHAR) ((CHAR) curdrive + '@') != (CHAR) toupper(*HomePath) &&
|
---|
| 96 | (CHAR) ((CHAR) curdrive + '@') != (CHAR) toupper(*path))
|
---|
| 97 | DosChDir("\\");
|
---|
[2] | 98 | }
|
---|
| 99 | ret = DosSelectDisk(toupper(*path) - '@');
|
---|
| 100 | return (ret) ? ret : DosChDir(path);
|
---|
| 101 | }
|
---|
| 102 | return DosChDir(path);
|
---|
| 103 | }
|
---|
[793] | 104 |
|
---|
| 105 | #pragma alloc_text(MISC9,save_dir,save_dir2,switch_to)
|
---|