[793] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: dirs.c 1904 2024-06-01 19:03:22Z stevenhl $
|
---|
| 5 |
|
---|
| 6 | Copyright (c) 1993-98 M. Kimes
|
---|
[1498] | 7 | Copyright (c) 2003, 2010 Steven H.Levine
|
---|
[793] | 8 |
|
---|
| 9 | Directory manipulation
|
---|
| 10 |
|
---|
| 11 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
[1498] | 12 | 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
|
---|
[793] | 13 |
|
---|
| 14 | ***********************************************************************/
|
---|
| 15 |
|
---|
[2] | 16 | #include <stdlib.h>
|
---|
| 17 | #include <string.h>
|
---|
| 18 | #include <ctype.h>
|
---|
[907] | 19 |
|
---|
[1159] | 20 | #define INCL_LONGLONG // dircnrs.h
|
---|
[907] | 21 |
|
---|
[2] | 22 | #include "fm3dll.h"
|
---|
[1206] | 23 | #include "init.h" // Data declaration(s)
|
---|
[1159] | 24 | #include "dirs.h"
|
---|
| 25 | #include "valid.h" // IsValidDir
|
---|
[2] | 26 |
|
---|
[551] | 27 | APIRET save_dir2(CHAR * curdir)
|
---|
| 28 | {
|
---|
[1607] | 29 | CHAR *env = getenv(PCSZ_FM3INI);
|
---|
[2] | 30 |
|
---|
[551] | 31 | if (env && *env) {
|
---|
| 32 | strncpy(curdir, env, CCHMAXPATH);
|
---|
[2] | 33 | curdir[CCHMAXPATH - 1] = 0;
|
---|
[551] | 34 | if (IsValidDir(curdir))
|
---|
[2] | 35 | return 0;
|
---|
| 36 | else {
|
---|
[551] | 37 | env = strrchr(curdir, '\\');
|
---|
| 38 | if (env) {
|
---|
[1159] | 39 | *env = 0;
|
---|
| 40 | if (IsValidDir(curdir))
|
---|
| 41 | return 0;
|
---|
[2] | 42 | }
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 | return save_dir(curdir);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[1904] | 48 | /**
|
---|
| 49 | * Return fully qualified path to current directory
|
---|
| 50 | */
|
---|
| 51 |
|
---|
[551] | 52 | APIRET save_dir(CHAR * curdir)
|
---|
| 53 | {
|
---|
| 54 | APIRET ret;
|
---|
| 55 | ULONG curdirlen, curdrive, drivemap;
|
---|
[2] | 56 |
|
---|
| 57 | *curdir = 0;
|
---|
[551] | 58 | ret = DosQCurDisk(&curdrive, &drivemap);
|
---|
[1673] | 59 | curdirlen = CCHMAXPATH - 4; // NOTE!!!!!!!!!
|
---|
[1321] | 60 | ret += DosQCurDir(curdrive, (PBYTE)&curdir[3], &curdirlen);
|
---|
[551] | 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)
|
---|
[1159] | 80 | *p = 0;
|
---|
[2] | 81 | else {
|
---|
[1159] | 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) &&
|
---|
[1159] | 95 | (CHAR) ((CHAR) curdrive + '@') != (CHAR) toupper(*path))
|
---|
[1498] | 96 | DosChDir((CHAR *) PCSZ_BACKSLASH);
|
---|
[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)
|
---|