]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/INC/ERRTST.C

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / INC / ERRTST.C
1 /* \ f\e0 */
2 #include "comsub.h"
3 #include "dpb.h"
4 #include <dos.h>
5 #include "jointype.h"
6
7 extern unsigned char *com_substr() ; /* ;AN000; DBCS enabled */
8 extern char getdrv() ;
9
10 union REGS inregs, outregs; /* ;AN000; Regs for Int21 */
11 struct SREGS segregs; /* ;AN000; Segment regs for Int21 */
12
13 #define GET_DBCS_VEC 0x6300 /* ;AN000; Int21 Get DBCS Vector */
14 #define DBLNULL "00" /* ;AN000; */
15 #define NULL 0 /* ;AN000; */
16
17 #define KANJI TRUE
18
19 /* return FALSE if drive is valid AND the path is not a prefix of a non-root
20 * current directory.
21 */
22 char fPathErr(p)
23 char *p ;
24 {
25 char buf[MAXARG] ;
26 int d ;
27 #ifdef KANJI
28 char *p1;
29 #endif
30
31 if (p[1] == ':')
32 d = *p-'A'+1 ;
33 else
34 d = 0 ;
35
36 if (curdir(buf, d) == -1) /* drive is invalid => error */
37 return(TRUE) ;
38
39 if (strlen(buf) == 3) /* current directory is root => OK */
40 return(FALSE) ;
41
42 if (strpre(p, buf)) {
43 #ifdef KANJI
44 p1 = p;
45 while (*p1 != NULL) {
46 if(testkanj(*p1 & 0xFF))
47 p1 += 2 ;
48 else
49 if((*p1++ == '\\') && (*p1 == NULL))
50 return(TRUE) ;
51 }
52 #else
53 if (p[strlen(p)-1] == '\\') /* prefix matched, prefix had...*/
54 return(TRUE) ; /* ...trailing / => valid ... */
55 /* ...prefix => ERROR */
56 #endif
57 d = buf[strlen(p)] ;
58 if (d == 0 || d == '\\') /* prefix matched,... */
59 return(TRUE) ; /* ...prefix had no trailing /, */
60 /* ...next char was / => ... */
61 /* ...valid prefix => ERROR */
62 } ;
63
64 return(FALSE) ; /* drive letter good and not valid prefix => OK */
65 }
66
67
68 strpre(pre, tot)
69 char *pre;
70 char *tot;
71 {
72 return(!strncmp(pre, tot, strlen(pre)));
73 }
74
75
76
77 Fatal(p)
78 char *p ;
79 {
80 printf("%s\n", p) ;
81 exit(1) ;
82 }
83
84
85
86
87 ffirst(pb, attr, pfbuf)
88 char *pb ;
89 int attr ;
90 struct findType *pfbuf ;
91 {
92 union REGS regs ;
93
94 /* set DMA to point to buffer */
95
96 regs.h.ah = 0x1A ;
97 regs.x.dx = (unsigned) pfbuf ;
98 intdos (&regs, &regs) ;
99
100 /* perform system call */
101
102 regs.h.ah = 0x4E ;
103 regs.x.cx = attr ;
104 regs.x.dx = (unsigned) pb ;
105 intdos (&regs, &regs) ;
106
107 return (regs.x.cflag ? -1 : 0) ;
108 }
109
110 fnext (pfbuf)
111 struct findType *pfbuf;
112 {
113 union REGS regs;
114
115 /* set DMA to point to buffer */
116 regs.h.ah = 0x1A;
117 regs.x.dx = (unsigned) pfbuf;
118 intdos (&regs, &regs);
119 /* perform system call */
120 regs.h.ah = 0x4F;
121 intdos (&regs, &regs);
122 return (regs.x.cflag ? -1 : 0) ;
123 }
124
125
126 char *strbscan(str, class)
127 char *str ;
128 char *class ;
129 {
130 char *p ;
131
132 p = com_substr(str, class) ; /* :AN000; DBCS function */
133 return((p == NULL) ? (str + strlen(str)) : p) ;
134 }
135
136
137
138
139
140 /* curdir.c - return text of current directory for a particular drive */
141
142
143 curdir (dst, drive)
144 char *dst ;
145 int drive ;
146 {
147 union REGS regs ;
148
149 *dst++ = PathChr ;
150 regs.h.ah = 0x47 ;
151 regs.h.dl = drive ;
152 regs.x.si = (unsigned) dst ;
153 intdos (&regs, &regs) ;
154 return(regs.x.cflag ? -1 : 0) ;
155 }
156
157
158
159
160 /*
161 rootpath
162 */
163
164 /*** rootpath -- convert a pathname argument to root based cannonical form
165 *
166 * rootpath determines the current directory, appends the path argument (which
167 * may affect which disk the current directory is relative to), and qualifies
168 * "." and ".." references. The result is a complete, simple, path name with
169 * drive specifier.
170 *
171 * If the relative path the user specifies does not include a drive spec., the
172 * default drive will be used as the base. (The default drive will never be
173 * changed.)
174 *
175 * entry: relpath -- pointer to the pathname to be expanded
176 * fullpath -- must point to a working buffer, see warning
177 * exit: fullpath -- the full path which results
178 * return: true if an error occurs, false otherwise
179 *
180 * calls: curdir, getdrv
181 *
182 * warning: fullpath must point to a working buffer large enough to hold the
183 * longest possible relative path argument plus the longest possible
184 * current directory path.
185 *
186 */
187 int rootpath(relpath, fullpath)
188 char *relpath ;
189 char *fullpath ;
190 {
191 int drivenum ;
192 char tempchar;
193 register char *lead, *follow ;
194 char *p1, *p2;
195
196
197 /* extract drive spec */
198 drivenum = getdrv() ;
199 if ((*relpath != NULL) && (relpath[1] == COLON)) {
200 drivenum = relpath[0] - 'A' ;
201 relpath += 2 ;
202 }
203 fullpath[0] = (char) ('A' + drivenum) ;
204 fullpath[1] = COLON ;
205
206 /* append relpath to fullpath/base */
207 if (*relpath == PathChr) {
208 /* relpath starts at base */
209 strcpy(fullpath+2, relpath) ;
210 }
211 else {
212 /* must get base path first */
213 if (curdir(fullpath+2, drivenum+1))
214 return(TRUE) ; /* terrible error */
215 if ((*relpath != ASCNULL) && (strlen(fullpath) > 3))
216 strcat(fullpath, "\\") ;
217 strcat(fullpath, relpath) ;
218 }
219
220
221 /* convert path to cannonical form */
222 lead = fullpath ;
223 while(*lead != ASCNULL) {
224 /* mark next path segment */
225 follow = lead ;
226 lead = (char *) com_substr(follow+1, "\\") ; /* ;AC000; */
227 if (lead == NULL)
228 lead = fullpath + strlen(fullpath) ;
229 tempchar = *lead ;
230 if (tempchar == PathChr)
231 tempchar = BACKSLASH ; /* make breaks uniform */
232 *lead = ASCNULL ;
233
234 /* "." segment? */
235 if (strcmp(follow+1, ".") == 0) {
236 *lead = tempchar ;
237 strcpy(follow, lead) ; /* remove "." segment */
238 lead = follow ;
239 }
240
241 /* ".." segment? */
242 else if (strcmp(follow+1, "..") == 0) {
243 *lead = tempchar ;
244 tempchar = *follow ;
245 *follow = NULL ;
246 p2 = fullpath - 1 ;
247 while(*(p2=strbscan(p1=p2+1,"\\")) != NULL) ;
248 /* p1 now points to the start of the previous element */
249 *follow = tempchar ;
250 if(p1 == fullpath)
251 return(TRUE) ; /* tried to .. the root */
252 follow = p1 - 1 ; /* follow points to path sep */
253 strcpy(follow, lead) ; /* remove ".." segment */
254 lead = follow ;
255 }
256
257 /* normal segment */
258 else
259 *lead = tempchar ;
260 }
261 if (strlen(fullpath) == 2) /* 'D:' or some such */
262 strcat(fullpath, "\\") ;
263
264 return(FALSE) ;
265 }
266
267
268 /* getdrv - return current drive as a character */
269
270
271 char getdrv()
272 {
273 union REGS regs ;
274
275 regs.h.ah = CURDISK ; /* Function 0x19 */
276 intdos (&regs, &regs) ;
277 return(regs.h.al) ;
278 }
279
280 testkanj(c)
281 unsigned char c;
282 {
283 char fix_es_reg[1]; /* ;AN000; Fixes es reg after "far" */
284 char far * fptr; /* ;AN000; Pts to DBCS vector */
285 unsigned * ptr; /* ;AN000; Input to fptr */
286 unsigned int got_dbcs; /* ;AN000; Flag */
287
288 inregs.x.ax = GET_DBCS_VEC; /* ;AN000; 0x6300 */
289 intdosx(&inregs,&outregs,&segregs); /* ;AN000; Int21 */
290
291 got_dbcs = FALSE; /* ;AN000; Initialize */
292
293 ptr = (unsigned *)&fptr; /* ;AN000; Int21 returns DS:SI */
294 *ptr = outregs.x.si; /* ;AN000; as ptr to DBCS */
295 ptr++; /* ;AN000; vector, now fill */
296 *ptr = segregs.ds; /* ;AN000; in our pointer */
297
298 for (fptr; *(unsigned far *)fptr != (unsigned)DBLNULL; fptr += 2) /* ;AN000; */
299 { /* ;AN000; */
300 if ( (c >= (char)*fptr) && (c <= (char)*(fptr+1)) ) /* ;AN000; Is char */
301 { /* ;AN000; within the range? */
302 got_dbcs = TRUE; /* ;AN000; Char is DBCS */
303 break; /* ;AN000; */
304 } /* ;AN000; */
305 } /* ;AN000; */
306
307 strcpy(fix_es_reg,NULL); /* ;AN000; Repair ES reg */
308 return(got_dbcs); /* ;AN000; */
309 }
310 \1a