source: trunk/dll/dirs.c@ 1321

Last change on this file since 1321 was 1321, checked in by Steven Levine, 17 years ago

Rework casts variable types for OpenWatcom 1.8 compatibility
Add more FORTIFY support

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 KB
Line 
1
2/***********************************************************************
3
4 $Id: dirs.c 1321 2008-12-07 01:48:06Z 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#include "init.h" // Data declaration(s)
23#include "dirs.h"
24#include "valid.h" // IsValidDir
25
26APIRET save_dir2(CHAR * curdir)
27{
28 CHAR *env = getenv("FM3INI");
29
30 if (env && *env) {
31 strncpy(curdir, env, CCHMAXPATH);
32 curdir[CCHMAXPATH - 1] = 0;
33 if (IsValidDir(curdir))
34 return 0;
35 else {
36 env = strrchr(curdir, '\\');
37 if (env) {
38 *env = 0;
39 if (IsValidDir(curdir))
40 return 0;
41 }
42 }
43 }
44 return save_dir(curdir);
45}
46
47APIRET save_dir(CHAR * curdir)
48{
49 APIRET ret;
50 ULONG curdirlen, curdrive, drivemap;
51
52 *curdir = 0;
53 ret = DosQCurDisk(&curdrive, &drivemap);
54 curdirlen = CCHMAXPATH - 4; /* NOTE!!!!!!!!! */
55 ret += DosQCurDir(curdrive, (PBYTE)&curdir[3], &curdirlen);
56 *curdir = (CHAR) ('@' + (INT) curdrive);
57 curdir[1] = ':';
58 curdir[2] = '\\';
59 return ret;
60}
61
62APIRET switch_to(CHAR * s)
63{
64
65 APIRET ret;
66 FILESTATUS3 fsa;
67 CHAR path[CCHMAXPATH + 1], *p;
68
69 strcpy(path, s);
70 while (*path) {
71 ret = DosQueryPathInfo(path, FIL_STANDARD, &fsa, sizeof(fsa));
72 if (ret || !(fsa.attrFile & FILE_DIRECTORY)) {
73 p = strrchr(path, '\\');
74 if (p)
75 *p = 0;
76 else {
77 strcpy(path, s);
78 break;
79 }
80 }
81 else
82 break;
83 }
84 if (isalpha(*path) && path[1] == ':') {
85
86 ULONG curdrive, drivemap;
87
88 if (!DosQCurDisk(&curdrive, &drivemap)) {
89 if ((CHAR) ((CHAR) curdrive + '@') != (CHAR) toupper(*HomePath) &&
90 (CHAR) ((CHAR) curdrive + '@') != (CHAR) toupper(*path))
91 DosChDir("\\");
92 }
93 ret = DosSelectDisk(toupper(*path) - '@');
94 return (ret) ? ret : DosChDir(path);
95 }
96 return DosChDir(path);
97}
98
99#pragma alloc_text(MISC9,save_dir,save_dir2,switch_to)
Note: See TracBrowser for help on using the repository browser.