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