1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
/*************************************************************************
*
* PARSPATH.C
*
* NetWare parsing routines, ported from DOS
*
* Copyright (c) 1995 Microsoft Corporation
*
* $Log: N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\PARSPATH.C $
*
* Rev 1.3 22 Jan 1996 16:48:38 terryt
* Add automatic attach query during map
*
* Rev 1.2 22 Dec 1995 14:26:16 terryt
* Add Microsoft headers
*
* Rev 1.1 22 Dec 1995 11:08:50 terryt
* Fixes
*
* Rev 1.0 15 Nov 1995 18:07:48 terryt
* Initial revision.
*
* Rev 1.1 25 Aug 1995 16:23:34 terryt
* Capture support
*
* Rev 1.0 15 May 1995 19:11:00 terryt
* Initial revision.
*
*************************************************************************/
/*++
Copyright (c) 1994 Micro Computer Systems, Inc.
Module Name:
nwlibs\parspath.c
Abstract:
Directory APIs.
Author:
Shawn Walker (v-swalk) 10-10-1994
Revision History:
--*/
#include "common.h"
#include <ctype.h>
#include <direct.h>
#include "inc\nwlibs.h"
/*++
*******************************************************************
ParsePath
Routine Description:
Parse the path string.
Arguments:
pPath = The pointer to the path to parse.
pServerName = The pointer to return the server name.
pVolumeName = The pointer to return the volume name.
pDirPath = The pointer to return the directory path.
Return Value:
0x0000 SUCCESSFUL
0x000F INVALID_DRIVE
0x8800 Unknown error
*******************************************************************
--*/
unsigned int
ParsePath(
unsigned char *pPath,
unsigned char *pServerName, //OPTIONAL
unsigned char *pVolumeName, //OPTIONAL
unsigned char *pDirPath //OPTIONAL
)
{
unsigned char *p, *p2;
unsigned int Result;
unsigned int Remote;
unsigned int NcpError = 0;
unsigned char DriveNumber = (unsigned char)-1;
unsigned char CurrentPath[64];
unsigned char RootPath[NCP_MAX_PATH_LENGTH];
unsigned char ServerName[NCP_MAX_PATH_LENGTH];
unsigned char *pRootDir;
unsigned char NetWarePath[NCP_MAX_PATH_LENGTH];
unsigned char VolumeName[NCP_VOLUME_LENGTH];
unsigned int LocalDriveForce = FALSE;
RootPath[0] = 0;
VolumeName[0] = 0;
ServerName[0] = 0;
if ( pServerName )
*pServerName = '\0';
/** See if there is a volume on the path **/
p = pPath;
while (*p != ':' && *p) {
p++;
}
if (*p == ':') {
*p = 0;
/**
Check to see if this is a drive letter. The volume must
be 2 characters or more.
**/
if ((p - pPath) == 1) {
/** Make sure it is a valid alpha char **/
if (!isalpha((int) *pPath)) {
return 0x000F;
}
*pPath = (unsigned char) toupper((int) *pPath);
/** Make it a drive number **/
DriveNumber = (unsigned char) (*pPath - 'A');
GetDriveStatus ((unsigned short)(DriveNumber+1),
NETWARE_FORMAT_SERVER_VOLUME,
NULL,
NULL,
RootPath,
NULL,
NULL);
pRootDir = strchr (RootPath, ':');
if (pRootDir)
{
/*
* Setup the pServerName here
*/
pRootDir[0] = '\0';
p2 = RootPath;
while (*p2)
{
if (*p2 == '\\' || *p2 == '/')
{
*p2++ = 0;
strcpy(ServerName, RootPath);
if (pServerName) {
strcpy(pServerName, RootPath);
}
break;
}
p2++;
}
strcpy (RootPath, pRootDir+1);
}
else
RootPath[0] = 0;
}
else {
DriveNumber = 0;
LocalDriveForce = TRUE;
/**
If there is a server name, save the server name
and set the error code to 0x880F but still parse
the path. This just means that there is no connection
for this server. Even if we do have one.
**/
p2 = pPath;
while (*p2) {
if (*p2 == '\\' || *p2 == '/') {
*p2++ = 0;
strcpy(ServerName, pPath);
if (pServerName) {
strcpy(pServerName, pPath);
}
pPath = p2;
NcpError = 0x880F;
break;
}
p2++;
}
if (NcpError == 0x880F) {
/**
Do any attach processing.
**/
NcpError = DoAttachProcessing( ServerName );
}
strcpy(VolumeName, pPath);
}
/** Get the directory **/
p++;
pPath = p;
}
/**
If we did not get the drive letter of volume name
from above, then get the current drive we are on.
**/
if (DriveNumber == (unsigned char) -1) {
DriveNumber = _getdrive();
}
/*
* Use the PREFERRED_SERVER for 3X logins if no server name
* was specified.
*/
if (pServerName && !fNDS && !pServerName[0] ) {
strcpy( pServerName, PREFERRED_SERVER );
}
if (pVolumeName) {
/**
Check if the drive is remote, if so, then go get the path
from the server.
**/
if ( LocalDriveForce ) {
Result = 0;
Remote = 0;
}
else {
Result = IsDriveRemote(DriveNumber, &Remote);
}
if (NcpError != 0x880F && !VolumeName[0] && (Result || !Remote)) {
pVolumeName[0] = (unsigned char) (DriveNumber + 'A');
pVolumeName[1] = 0;
}
else {
if (VolumeName[0]) {
strcpy(pVolumeName, VolumeName);
}
else {
Result = NTGetNWDrivePath( DriveNumber, NULL, NetWarePath );
if (Result) {
return Result;
}
p = NetWarePath;
while (*p != ':' && *p) {
p++;
}
if (*p == ':') {
*p = 0;
}
strcpy(pVolumeName, NetWarePath);
}
}
}
if (pDirPath) {
memset(CurrentPath, 0, sizeof(CurrentPath));
if (VolumeName[0]) {
strcpy(pDirPath, pPath);
}
else {
Result = NTGetCurrentDirectory(DriveNumber, CurrentPath);
if (Result) {
CurrentPath[0] = 0;
}
else {
/*
* Skip the drive letter
*/
if ( CurrentPath[0] ) {
int i;
for ( i = 0; ;i++ ) {
CurrentPath[i] = CurrentPath[i+3];
if ( !CurrentPath[i] )
break;
}
}
}
if (CurrentPath[0] == 0) {
if ( (*pPath == '\\') || ( *pPath == '/' ) ) {
sprintf(pDirPath, "%s%s", RootPath, pPath);
}
else if ( !(*pPath) ) {
sprintf(pDirPath, "%s", RootPath);
}
else {
sprintf(pDirPath, "%s\\%s", RootPath, pPath);
}
}
else {
if (*pPath) {
if ( (*pPath == '\\') || ( *pPath == '/' ) ) {
strcpy (pDirPath, RootPath);
if (pPath[1]) {
strcat(pDirPath, pPath);
}
}
else {
sprintf(pDirPath, "%s\\%s\\%s", RootPath, CurrentPath, pPath);
}
}
else {
sprintf(pDirPath, "%s\\%s", RootPath, CurrentPath);
}
}
}
/** Convert the / in the path to \ **/
for (p = pDirPath; ( p && ( *p != 0 ) ) ; p++)
{
if (*p == '/')
*p = '\\';
}
}
return NcpError;
}
|