source: trunk/dll/dirs.c@ 1498

Last change on this file since 1498 was 1498, checked in by Gregg Young, 16 years ago

Changes to get FM2 to compile with the latest watcom 1.9 beta (mostly type casts of CHAR CONSTANT * to CHAR *). Changes to get the environment settings working everywhere again (broken by the change that moved commands to the INI); Added an environment size variable (set to 2048 which was the largest I found hard coded). Still need to find everywhere the environment size is set and use this variable.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1
2/***********************************************************************
3
4 $Id: dirs.c 1498 2010-01-18 00:57:01Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2003, 2010 Steven H.Levine
8
9 Directory manipulation
10
11 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
12 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
13
14***********************************************************************/
15
16#include <stdlib.h>
17#include <string.h>
18#include <ctype.h>
19
20#define INCL_LONGLONG // dircnrs.h
21
22#include "fm3dll.h"
23#include "init.h" // Data declaration(s)
24#include "dirs.h"
25#include "valid.h" // IsValidDir
26
27APIRET save_dir2(CHAR * curdir)
28{
29 CHAR *env = getenv("FM3INI");
30
31 if (env && *env) {
32 strncpy(curdir, env, CCHMAXPATH);
33 curdir[CCHMAXPATH - 1] = 0;
34 if (IsValidDir(curdir))
35 return 0;
36 else {
37 env = strrchr(curdir, '\\');
38 if (env) {
39 *env = 0;
40 if (IsValidDir(curdir))
41 return 0;
42 }
43 }
44 }
45 return save_dir(curdir);
46}
47
48APIRET save_dir(CHAR * curdir)
49{
50 APIRET ret;
51 ULONG curdirlen, curdrive, drivemap;
52
53 *curdir = 0;
54 ret = DosQCurDisk(&curdrive, &drivemap);
55 curdirlen = CCHMAXPATH - 4; /* NOTE!!!!!!!!! */
56 ret += DosQCurDir(curdrive, (PBYTE)&curdir[3], &curdirlen);
57 *curdir = (CHAR) ('@' + (INT) curdrive);
58 curdir[1] = ':';
59 curdir[2] = '\\';
60 return ret;
61}
62
63APIRET switch_to(CHAR * s)
64{
65
66 APIRET ret;
67 FILESTATUS3 fsa;
68 CHAR path[CCHMAXPATH + 1], *p;
69
70 strcpy(path, s);
71 while (*path) {
72 ret = DosQueryPathInfo(path, FIL_STANDARD, &fsa, sizeof(fsa));
73 if (ret || !(fsa.attrFile & FILE_DIRECTORY)) {
74 p = strrchr(path, '\\');
75 if (p)
76 *p = 0;
77 else {
78 strcpy(path, s);
79 break;
80 }
81 }
82 else
83 break;
84 }
85 if (isalpha(*path) && path[1] == ':') {
86
87 ULONG curdrive, drivemap;
88
89 if (!DosQCurDisk(&curdrive, &drivemap)) {
90 if ((CHAR) ((CHAR) curdrive + '@') != (CHAR) toupper(*HomePath) &&
91 (CHAR) ((CHAR) curdrive + '@') != (CHAR) toupper(*path))
92 DosChDir((CHAR *) PCSZ_BACKSLASH);
93 }
94 ret = DosSelectDisk(toupper(*path) - '@');
95 return (ret) ? ret : DosChDir(path);
96 }
97 return DosChDir(path);
98}
99
100#pragma alloc_text(MISC9,save_dir,save_dir2,switch_to)
Note: See TracBrowser for help on using the repository browser.