| 227 |
dpurdie |
1 |
/*
|
|
|
2 |
* MS-DOS SHELL - Header File
|
|
|
3 |
*
|
|
|
4 |
* MS-DOS SHELL - Copyright (c) 1990,4 Data Logic Limited and Charles Forsyth
|
|
|
5 |
*
|
|
|
6 |
* This code is based on (in part) the shell program written by Charles
|
|
|
7 |
* Forsyth and the subsequence modifications made by Simon J. Gerraty (for
|
|
|
8 |
* his Public Domain Korn Shell) and is subject to the following copyright
|
|
|
9 |
* restrictions:
|
|
|
10 |
*
|
|
|
11 |
* 1. Redistribution and use in source and binary forms are permitted
|
|
|
12 |
* provided that the above copyright notice is duplicated in the
|
|
|
13 |
* source form and the copyright notice in file sh6.c is displayed
|
|
|
14 |
* on entry to the program.
|
|
|
15 |
*
|
|
|
16 |
* 2. The sources (or parts thereof) or objects generated from the sources
|
|
|
17 |
* (or parts of sources) cannot be sold under any circumstances.
|
|
|
18 |
*
|
|
|
19 |
* $Header: /cvsroot/device/DEVL/UTILS/SH/SH.H,v 1.3 2004/11/04 02:47:59 ayoung Exp $
|
|
|
20 |
*
|
|
|
21 |
* $Log: SH.H,v $
|
|
|
22 |
* Revision 1.3 2004/11/04 02:47:59 ayoung
|
|
|
23 |
* handle upto 8 PATH definitions
|
|
|
24 |
*
|
|
|
25 |
* Revision 1.2 2004/05/10 09:30:06 ayoung
|
|
|
26 |
* improved Path/PATH handling
|
|
|
27 |
* Quote CreateProcess arg0 if embedded spaces are encountered
|
|
|
28 |
* Native NT exec dont need to check command line length
|
|
|
29 |
* Warning when '@' within redirect list
|
|
|
30 |
* DEBUG_EXEC option, split from PRINT_EXEC option and improved
|
|
|
31 |
*
|
|
|
32 |
* Revision 1.1 2002/08/02 06:49:32 adamy
|
|
|
33 |
* imported (reference only)
|
|
|
34 |
*
|
|
|
35 |
* Revision 1.2 2002/07/02 04:40:49 mhunt
|
|
|
36 |
* CMD_LINE_MAX increase
|
|
|
37 |
*
|
|
|
38 |
* Revision 1.1 2001/07/20 05:55:42 ayoung
|
|
|
39 |
* WIN32 support
|
|
|
40 |
*
|
|
|
41 |
* Revision 1.2 2000/09/27 08:33:35 adamy
|
|
|
42 |
* Added EXTENDED_LINE cache and use __systeml_mode during DOS builds.
|
|
|
43 |
*
|
|
|
44 |
* Revision 1.1.1.1 1999/12/02 01:11:12 gordonh
|
|
|
45 |
* UTIL
|
|
|
46 |
*
|
|
|
47 |
* Revision 2.16 1994/08/25 20:58:47 istewart
|
|
|
48 |
* MS Shell 2.3 Release
|
|
|
49 |
*
|
|
|
50 |
* Revision 2.15 1994/02/23 09:23:38 istewart
|
|
|
51 |
* Beta 233 updates
|
|
|
52 |
*
|
|
|
53 |
* Revision 2.14 1994/02/01 10:25:20 istewart
|
|
|
54 |
* Release 2.3 Beta 2, including first NT port
|
|
|
55 |
*
|
|
|
56 |
* Revision 2.13 1994/01/11 17:55:25 istewart
|
|
|
57 |
* Release 2.3 Beta 0 patches
|
|
|
58 |
*
|
|
|
59 |
* Revision 2.12 1993/11/09 10:39:49 istewart
|
|
|
60 |
* Beta 226 checking
|
|
|
61 |
*
|
|
|
62 |
* Revision 2.11 1993/08/25 16:03:57 istewart
|
|
|
63 |
* Beta 225 - see Notes file
|
|
|
64 |
*
|
|
|
65 |
* Revision 2.10 1993/07/02 10:25:53 istewart
|
|
|
66 |
* 224 Beta fixes
|
|
|
67 |
*
|
|
|
68 |
* Revision 2.9 1993/06/14 11:00:54 istewart
|
|
|
69 |
* More changes for 223 beta
|
|
|
70 |
*
|
|
|
71 |
* Revision 2.8 1993/06/02 09:58:12 istewart
|
|
|
72 |
* Shell 223 Beta Release - see Notes file
|
|
|
73 |
*
|
|
|
74 |
* Revision 2.7 1993/02/16 16:04:22 istewart
|
|
|
75 |
* Beta 2.22 Release
|
|
|
76 |
*
|
|
|
77 |
* Revision 2.6 1993/01/26 18:35:09 istewart
|
|
|
78 |
* Release 2.2 beta 0
|
|
|
79 |
*
|
|
|
80 |
* Revision 2.5 1992/12/14 10:54:56 istewart
|
|
|
81 |
* BETA 215 Fixes and 2.1 Release
|
|
|
82 |
*
|
|
|
83 |
* Revision 2.4 1992/11/06 10:03:44 istewart
|
|
|
84 |
* 214 Beta test updates
|
|
|
85 |
*
|
|
|
86 |
* Revision 2.3 1992/09/03 18:54:45 istewart
|
|
|
87 |
* Beta 213 Updates
|
|
|
88 |
*
|
|
|
89 |
* Revision 2.2 1992/07/16 14:33:34 istewart
|
|
|
90 |
* Beta 212 Baseline
|
|
|
91 |
*
|
|
|
92 |
* Revision 2.1 1992/07/14 08:58:59 istewart
|
|
|
93 |
* 211 Beta updates
|
|
|
94 |
*
|
|
|
95 |
* Revision 2.0 1992/04/13 17:39:40 Ian_Stewartson
|
|
|
96 |
* MS-Shell 2.0 Baseline release
|
|
|
97 |
*
|
|
|
98 |
*/
|
|
|
99 |
|
|
|
100 |
/*
|
|
|
101 |
* Operating System Definitions
|
|
|
102 |
*/
|
|
|
103 |
|
|
|
104 |
#define OS_DOS 1 /* MSDOS */
|
|
|
105 |
#define OS_OS2 2 /* OS/2 */
|
|
|
106 |
#define OS_NT 3 /* Windows NT */
|
|
|
107 |
#define OS_UNIX 4 /* A UNIX system */
|
|
|
108 |
|
|
|
109 |
#define OS_16 1 /* 16-bit O/S */
|
|
|
110 |
#define OS_32 2 /* 32-bit O/S */
|
|
|
111 |
|
|
|
112 |
#if defined (__OS2__)
|
|
|
113 |
# define OS_TYPE OS_OS2
|
|
|
114 |
# define OS_SIZE OS_32
|
|
|
115 |
#elif defined (__32BIT__) && defined (__EMX__)
|
|
|
116 |
# if defined (EMX_DOS)
|
|
|
117 |
# define OS_TYPE OS_DOS
|
|
|
118 |
# else
|
|
|
119 |
# define OS_TYPE OS_OS2
|
|
|
120 |
# endif
|
|
|
121 |
# define OS_SIZE OS_32
|
|
|
122 |
#elif defined (OS2)
|
|
|
123 |
# define OS_TYPE OS_OS2
|
|
|
124 |
# define OS_SIZE OS_16
|
|
|
125 |
#elif defined (WIN32)
|
|
|
126 |
# define OS_TYPE OS_NT
|
|
|
127 |
# define OS_SIZE OS_32
|
|
|
128 |
#elif defined (__386__)
|
|
|
129 |
# define OS_TYPE OS_DOS
|
|
|
130 |
# define OS_SIZE OS_32
|
|
|
131 |
#elif defined (unix)
|
|
|
132 |
# define OS_TYPE OS_UNIX
|
|
|
133 |
# define OS_SIZE OS_32
|
|
|
134 |
#else
|
|
|
135 |
# define OS_TYPE OS_DOS
|
|
|
136 |
# define OS_SIZE OS_16
|
|
|
137 |
# define OS_SWAPPING 1
|
|
|
138 |
#endif
|
|
|
139 |
|
|
|
140 |
#if (OS_SIZE == OS_32)
|
|
|
141 |
# define F_LOCAL
|
|
|
142 |
#else
|
|
|
143 |
# define F_LOCAL near
|
|
|
144 |
#endif
|
|
|
145 |
|
|
|
146 |
/*
|
|
|
147 |
* Get the system include files
|
|
|
148 |
*/
|
|
|
149 |
|
|
|
150 |
#if (OS_TYPE == OS_OS2)
|
|
|
151 |
|
|
|
152 |
/*
|
|
|
153 |
* OS/2 Stuff. Define the following so we get the right defs.
|
|
|
154 |
*/
|
|
|
155 |
|
|
|
156 |
# define INCL_DOSDEVICES
|
|
|
157 |
# define INCL_DOSERRORS
|
|
|
158 |
# define INCL_DOSEXCEPTIONS
|
|
|
159 |
# define INCL_DOSFILEMGR
|
|
|
160 |
# define INCL_DOSMEMMGR
|
|
|
161 |
# define INCL_DOSMISC
|
|
|
162 |
# define INCL_DOSMODULEMGR
|
|
|
163 |
# define INCL_DOSPROCESS
|
|
|
164 |
# define INCL_DOSQUEUES
|
|
|
165 |
# define INCL_DOSSEMAPHORES
|
|
|
166 |
# define INCL_DOSSESMGR
|
|
|
167 |
# define INCL_DOSSIGNALS
|
|
|
168 |
# define INCL_KBD
|
|
|
169 |
# define INCL_VIO
|
|
|
170 |
# define INCL_WINSWITCHLIST
|
|
|
171 |
|
|
|
172 |
# include <os2.h>
|
|
|
173 |
# include <bseerr.h>
|
|
|
174 |
|
|
|
175 |
# if (OS_SIZE == OS_32)
|
|
|
176 |
# include <bsedev.h>
|
|
|
177 |
|
|
|
178 |
/* Some compilers miss the 1.x to 2.x conversion macros */
|
|
|
179 |
|
|
|
180 |
# ifndef DosCwait
|
|
|
181 |
# define DosCwait DosWaitChild
|
|
|
182 |
# endif
|
|
|
183 |
|
|
|
184 |
# ifndef DosQCurDisk
|
|
|
185 |
# define DosQCurDisk DosQueryCurrentDisk
|
|
|
186 |
# endif
|
|
|
187 |
|
|
|
188 |
# ifndef DosQFSAttach
|
|
|
189 |
# define DosQFSAttach DosQueryFSAttach
|
|
|
190 |
# endif
|
|
|
191 |
|
|
|
192 |
# ifndef DosQFSInfo
|
|
|
193 |
# define DosQFSInfo DosQueryFSInfo
|
|
|
194 |
# endif
|
|
|
195 |
|
|
|
196 |
# ifndef DosQHandType
|
|
|
197 |
# define DosQHandType DosQueryHType
|
|
|
198 |
# endif
|
|
|
199 |
|
|
|
200 |
# ifndef DosQVerify
|
|
|
201 |
# define DosQVerify DosQueryVerify
|
|
|
202 |
# endif
|
|
|
203 |
|
|
|
204 |
# ifndef DosSelectDisk
|
|
|
205 |
# define DosSelectDisk DosSetDefaultDisk
|
|
|
206 |
# endif
|
|
|
207 |
|
|
|
208 |
# ifndef DosSetFHandState
|
|
|
209 |
# define DosSetFHandState DosSetFHState
|
|
|
210 |
# endif
|
|
|
211 |
|
|
|
212 |
# ifndef DosQFileInfo
|
|
|
213 |
# define DosQFileInfo DosQueryFileInfo
|
|
|
214 |
# endif
|
|
|
215 |
|
|
|
216 |
# endif
|
|
|
217 |
|
|
|
218 |
#elif (OS_TYPE == OS_NT)
|
|
|
219 |
|
|
|
220 |
/*
|
|
|
221 |
* Windows NT Stuff. Define the following so we don't get tons of extra stuff
|
|
|
222 |
* when we include windows.h
|
|
|
223 |
*/
|
|
|
224 |
|
|
|
225 |
# define NOGDICAPMASKS
|
|
|
226 |
# define NOVIRTUALKEYCODES
|
|
|
227 |
# define NOWINMESSAGES
|
|
|
228 |
# define NOWINSTYLES
|
|
|
229 |
# define NOSYSMETRICS
|
|
|
230 |
# define NOMENUS
|
|
|
231 |
# define NOICONS
|
|
|
232 |
# define NOKEYSTATES
|
|
|
233 |
# define NOSYSCOMMANDS
|
|
|
234 |
# define NORASTEROPS
|
|
|
235 |
# define NOSHOWWINDOW
|
|
|
236 |
# define OEMRESOURCE
|
|
|
237 |
# define NOATOM
|
|
|
238 |
# define NOCLIPBOARD
|
|
|
239 |
# define NOCOLOR
|
|
|
240 |
# define NOCTLMGR
|
|
|
241 |
# define NODRAWTEXT
|
|
|
242 |
# define NOGDI
|
|
|
243 |
/* # define NOKERNEL */
|
|
|
244 |
/* # define NOUSER */
|
|
|
245 |
# define NONLS
|
|
|
246 |
# define NOMB
|
|
|
247 |
# define NOMEMMGR
|
|
|
248 |
# define NOMETAFILE
|
|
|
249 |
# define NOMINMAX
|
|
|
250 |
# define NOMSG
|
|
|
251 |
# define NOOPENFILE
|
|
|
252 |
# define NOSCROLL
|
|
|
253 |
# define NOSERVICE
|
|
|
254 |
# define NOSOUND
|
|
|
255 |
# define NOTEXTMETRIC
|
|
|
256 |
# define NOWH
|
|
|
257 |
# define NOWINOFFSETS
|
|
|
258 |
# define NOCOMM
|
|
|
259 |
# define NOKANJI
|
|
|
260 |
# define NOHELP
|
|
|
261 |
# define NOPROFILER
|
|
|
262 |
# define NODEFERWINDOWPOS
|
|
|
263 |
|
|
|
264 |
/*
|
|
|
265 |
* We're not using Microsoft's "extensions" to C for Structured Exception
|
|
|
266 |
* Handling (SEH).
|
|
|
267 |
*/
|
|
|
268 |
|
|
|
269 |
# undef try
|
|
|
270 |
# undef except
|
|
|
271 |
# undef finally
|
|
|
272 |
# undef leave
|
|
|
273 |
|
|
|
274 |
# define WIN32_LEAN_AND_MEAN
|
|
|
275 |
# include <windows.h>
|
|
|
276 |
# include <sys/types.h>
|
|
|
277 |
|
|
|
278 |
typedef int pid_t;
|
|
|
279 |
|
|
|
280 |
#elif (OS_TYPE == OS_DOS)
|
|
|
281 |
|
|
|
282 |
/* Finally the DOS stuff */
|
|
|
283 |
|
|
|
284 |
# include <dos.h>
|
|
|
285 |
# if defined (__32BIT__) && defined (__EMX__)
|
|
|
286 |
|
|
|
287 |
# else
|
|
|
288 |
# include <bios.h>
|
|
|
289 |
# endif
|
|
|
290 |
|
|
|
291 |
/* Add bool definitions and others for UNIX */
|
|
|
292 |
|
|
|
293 |
#elif (OS_TYPE == OS_UNIX)
|
|
|
294 |
typedef pid_t PID;
|
|
|
295 |
#endif
|
|
|
296 |
|
|
|
297 |
#if defined (__EMX__) && (OS_TYPE == OS_OS2)
|
|
|
298 |
typedef PID pid_t;
|
|
|
299 |
#endif
|
|
|
300 |
|
|
|
301 |
#ifndef _BOOL_T_DEFINED
|
|
|
302 |
typedef unsigned char bool;
|
|
|
303 |
# define _BOOL_T_DEFINED
|
|
|
304 |
#endif
|
|
|
305 |
|
|
|
306 |
#ifndef TRUE
|
|
|
307 |
# define TRUE ((bool)1)
|
|
|
308 |
#endif
|
|
|
309 |
|
|
|
310 |
#ifndef FALSE
|
|
|
311 |
# define FALSE ((bool)0)
|
|
|
312 |
#endif
|
|
|
313 |
|
|
|
314 |
|
|
|
315 |
/*
|
|
|
316 |
* Define number of signals
|
|
|
317 |
*/
|
|
|
318 |
|
|
|
319 |
#ifndef NSIG
|
|
|
320 |
# define NSIG 10
|
|
|
321 |
#endif
|
|
|
322 |
|
|
|
323 |
/*
|
|
|
324 |
* Flags to DosFlagProcess are missing on IBM C Set/2
|
|
|
325 |
*/
|
|
|
326 |
|
|
|
327 |
#ifndef PFLG_A
|
|
|
328 |
# define PFLG_A 0 /* Process Flag A */
|
|
|
329 |
#endif
|
|
|
330 |
|
|
|
331 |
#ifndef PFLG_B
|
|
|
332 |
# define PFLG_B 1 /* Process Flag B */
|
|
|
333 |
#endif
|
|
|
334 |
|
|
|
335 |
#ifndef PFLG_C
|
|
|
336 |
# define PFLG_C 2 /* Process Flag C */
|
|
|
337 |
#endif
|
|
|
338 |
|
|
|
339 |
/*
|
|
|
340 |
* DosFlagProcess codes
|
|
|
341 |
*/
|
|
|
342 |
|
|
|
343 |
#ifndef FLGP_SUBTREE
|
|
|
344 |
# define FLGP_SUBTREE 0 /* All sub-tree processes */
|
|
|
345 |
#endif
|
|
|
346 |
|
|
|
347 |
#ifndef FLGP_PID
|
|
|
348 |
# define FLGP_PID 1 /* only the process */
|
|
|
349 |
#endif
|
|
|
350 |
|
|
|
351 |
/*
|
|
|
352 |
* Spawn Types
|
|
|
353 |
*/
|
|
|
354 |
|
|
|
355 |
#ifndef P_WAIT
|
|
|
356 |
# define P_WAIT 0
|
|
|
357 |
#endif
|
|
|
358 |
|
|
|
359 |
#ifndef P_NOWAIT
|
|
|
360 |
# define P_NOWAIT 1
|
|
|
361 |
#endif
|
|
|
362 |
|
|
|
363 |
#ifndef P_OVERLAY
|
|
|
364 |
# define P_OVERLAY 2
|
|
|
365 |
#endif
|
|
|
366 |
|
|
|
367 |
#ifndef OLD_P_OVERLAY
|
|
|
368 |
# define OLD_P_OVERLAY 2
|
|
|
369 |
#endif
|
|
|
370 |
|
|
|
371 |
#ifndef P_NOWAITO
|
|
|
372 |
# define P_NOWAITO 3
|
|
|
373 |
#endif
|
|
|
374 |
|
|
|
375 |
#ifndef P_DETACH
|
|
|
376 |
# define P_DETACH 4
|
|
|
377 |
#endif
|
|
|
378 |
|
|
|
379 |
/* Wait values */
|
|
|
380 |
|
|
|
381 |
#ifndef WAIT_CHILD
|
|
|
382 |
# define WAIT_CHILD 0
|
|
|
383 |
#endif
|
|
|
384 |
|
|
|
385 |
#ifndef WAIT_GRANDCHILD
|
|
|
386 |
# define WAIT_GRANDCHILD 1
|
|
|
387 |
#endif
|
|
|
388 |
/*
|
|
|
389 |
* Missing errno values
|
|
|
390 |
*/
|
|
|
391 |
|
|
|
392 |
#ifndef EIO
|
|
|
393 |
# define EIO 105 /* I/O error */
|
|
|
394 |
#endif
|
|
|
395 |
|
|
|
396 |
#ifndef E2BIG
|
|
|
397 |
# define E2BIG 107 /* Arg list too long */
|
|
|
398 |
#endif
|
|
|
399 |
|
|
|
400 |
#ifndef ENOTDIR
|
|
|
401 |
# define ENOTDIR 120 /* Not a directory */
|
|
|
402 |
#endif
|
|
|
403 |
|
|
|
404 |
/*
|
|
|
405 |
* Missing stat definitions
|
|
|
406 |
*/
|
|
|
407 |
|
|
|
408 |
#ifndef S_IFMT
|
|
|
409 |
# define S_IFMT 0xf000 /* type of file */
|
|
|
410 |
#endif
|
|
|
411 |
|
|
|
412 |
#ifndef S_IFBLK
|
|
|
413 |
# define S_IFBLK 0x6000 /* block special */
|
|
|
414 |
#endif
|
|
|
415 |
|
|
|
416 |
#ifndef S_ISDIR
|
|
|
417 |
# define S_ISDIR(m) ((((m) & S_IFMT) == S_IFDIR))
|
|
|
418 |
#endif
|
|
|
419 |
|
|
|
420 |
#ifndef S_ISCHR
|
|
|
421 |
# define S_ISCHR(m) ((((m) & S_IFMT) == S_IFCHR))
|
|
|
422 |
#endif
|
|
|
423 |
|
|
|
424 |
#ifndef S_ISREG
|
|
|
425 |
# define S_ISREG(m) ((((m) & S_IFMT) == S_IFREG))
|
|
|
426 |
#endif
|
|
|
427 |
|
|
|
428 |
#ifndef S_ISBLK
|
|
|
429 |
# define S_ISBLK(m) ((((m) & S_IFMT) == S_IFBLK))
|
|
|
430 |
#endif
|
|
|
431 |
|
|
|
432 |
/* GCC has these missing */
|
|
|
433 |
|
|
|
434 |
#ifndef min
|
|
|
435 |
# define min(a,b) (((a) < (b)) ? (a) : (b))
|
|
|
436 |
#endif
|
|
|
437 |
|
|
|
438 |
#ifndef O_TEXT
|
|
|
439 |
# define O_TEXT 0
|
|
|
440 |
#endif
|
|
|
441 |
|
|
|
442 |
#ifndef O_BINARY
|
|
|
443 |
# define O_BINARY 0
|
|
|
444 |
#endif
|
|
|
445 |
|
|
|
446 |
#ifndef O_NOINHERIT
|
|
|
447 |
# define O_NOINHERIT 0x8000
|
|
|
448 |
#endif
|
|
|
449 |
|
|
|
450 |
#ifndef CLOCKS_PER_SEC
|
|
|
451 |
# define CLOCKS_PER_SEC 1000
|
|
|
452 |
#endif
|
|
|
453 |
|
|
|
454 |
#ifndef max
|
|
|
455 |
# define max(a,b) (((a) > (b)) ? (a) : (b))
|
|
|
456 |
#endif
|
|
|
457 |
|
|
|
458 |
/*
|
|
|
459 |
* File Attributes
|
|
|
460 |
*/
|
|
|
461 |
|
|
|
462 |
#if defined (__TURBOC__)
|
|
|
463 |
# define OS_FILE_DIRECTORY FA_DIREC
|
|
|
464 |
# define OS_FILE_HIDDEN FA_HIDDEN
|
|
|
465 |
# define OS_FILE_SYSTEM FA_SYSTEM
|
|
|
466 |
# define OS_FILE_NORMAL 0
|
|
|
467 |
# define OS_FILE_READONLY FA_RDONLY
|
|
|
468 |
# define OS_FILE_ARCHIVED FA_ARCH
|
|
|
469 |
|
|
|
470 |
/* TurboC puts this in io.h, which we don't include */
|
|
|
471 |
|
|
|
472 |
extern int _Cdecl _chmod (const char *, int, ...);
|
|
|
473 |
# define OS_GetFileAttributes(a,b) (*b = _chmod ((a), 0))
|
|
|
474 |
|
|
|
475 |
#elif (OS_TYPE == OS_DOS)
|
|
|
476 |
|
|
|
477 |
# define OS_FILE_DIRECTORY _A_SUBDIR
|
|
|
478 |
# define OS_FILE_HIDDEN _A_HIDDEN
|
|
|
479 |
# define OS_FILE_SYSTEM _A_SYSTEM
|
|
|
480 |
# define OS_FILE_NORMAL _A_NORMAL
|
|
|
481 |
# define OS_FILE_READONLY _A_RDONLY
|
|
|
482 |
# define OS_FILE_ARCHIVED _A_ARCH
|
|
|
483 |
|
|
|
484 |
# ifndef _A_NORMAL
|
|
|
485 |
# define _A_NORMAL 0x00 /* No attributes */
|
|
|
486 |
# endif
|
|
|
487 |
# ifndef _A_RDONLY
|
|
|
488 |
# define _A_RDONLY 0x01 /* Read-only */
|
|
|
489 |
# endif
|
|
|
490 |
# ifndef _A_HIDDEN
|
|
|
491 |
# define _A_HIDDEN 0x02 /* Hidden */
|
|
|
492 |
# endif
|
|
|
493 |
# ifndef _A_SYSTEM
|
|
|
494 |
# define _A_SYSTEM 0x04 /* System */
|
|
|
495 |
# endif
|
|
|
496 |
# ifndef _A_VOLID
|
|
|
497 |
# define _A_VOLID 0x08 /* Volume label */
|
|
|
498 |
# endif
|
|
|
499 |
# ifndef _A_SUBDIR
|
|
|
500 |
# define _A_SUBDIR 0x10 /* Directory */
|
|
|
501 |
# endif
|
|
|
502 |
# ifndef _A_ARCH
|
|
|
503 |
# define _A_ARCH 0x20 /* Archive */
|
|
|
504 |
# endif
|
|
|
505 |
# ifndef _A_DEVICE
|
|
|
506 |
# define _A_DEVICE 0x40 /* Device */
|
|
|
507 |
# endif
|
|
|
508 |
|
|
|
509 |
# define OS_GetFileAttributes(a,b) _dos_getfileattr ((a), (b))
|
|
|
510 |
|
|
|
511 |
#elif (OS_TYPE == OS_OS2)
|
|
|
512 |
|
|
|
513 |
# define OS_FILE_DIRECTORY FILE_DIRECTORY
|
|
|
514 |
# define OS_FILE_HIDDEN FILE_HIDDEN
|
|
|
515 |
# define OS_FILE_SYSTEM FILE_SYSTEM
|
|
|
516 |
# define OS_FILE_NORMAL FILE_NORMAL
|
|
|
517 |
# define OS_FILE_READONLY FILE_READONLY
|
|
|
518 |
# define OS_FILE_ARCHIVED FILE_ARCHIVED
|
|
|
519 |
|
|
|
520 |
# if (OS_SIZE == OS_16)
|
|
|
521 |
# define OS_GetFileAttributes(a,b) DosQFileMode ((a), (b), 0L)
|
|
|
522 |
# else
|
|
|
523 |
# define OS_GetFileAttributes(a,b) DosQFileMode ((a), (b))
|
|
|
524 |
# endif
|
|
|
525 |
|
|
|
526 |
#elif (OS_TYPE == OS_NT)
|
|
|
527 |
|
|
|
528 |
# define OS_FILE_DIRECTORY FILE_ATTRIBUTE_DIRECTORY
|
|
|
529 |
# define OS_FILE_HIDDEN FILE_ATTRIBUTE_HIDDEN
|
|
|
530 |
# define OS_FILE_SYSTEM FILE_ATTRIBUTE_SYSTEM
|
|
|
531 |
# define OS_FILE_NORMAL 0
|
|
|
532 |
# define OS_FILE_READONLY FILE_ATTRIBUTE_READONLY
|
|
|
533 |
# define OS_FILE_ARCHIVED FILE_ATTRIBUTE_ARCHIVE
|
|
|
534 |
|
|
|
535 |
# define OS_GetFileAttributes(a,b) DosQFileMode ((a), (b))
|
|
|
536 |
#endif
|
|
|
537 |
|
|
|
538 |
#define OS_FILE_ATTRIBUTES (OS_FILE_DIRECTORY | OS_FILE_HIDDEN | \
|
|
|
539 |
OS_FILE_SYSTEM | OS_FILE_NORMAL | \
|
|
|
540 |
OS_FILE_READONLY | OS_FILE_ARCHIVED)
|
|
|
541 |
|
|
|
542 |
/*
|
|
|
543 |
* Get major version number
|
|
|
544 |
*/
|
|
|
545 |
#if (OS_TYPE == OS_OS2)
|
|
|
546 |
# define OS_VERS_N (_osmajor / 10)
|
|
|
547 |
# define IS_VERS_M _osminor
|
|
|
548 |
#elif (OS_TYPE == OS_NT)
|
|
|
549 |
# define OS_VERS_N _winmajor
|
|
|
550 |
# define OS_VERS_M _winminor
|
|
|
551 |
#else
|
|
|
552 |
# define OS_VERS_N _osmajor
|
|
|
553 |
# define OS_VERS_M _osminor
|
|
|
554 |
#endif
|
|
|
555 |
|
|
|
556 |
extern int BaseOS; /* Underlying OS */
|
|
|
557 |
|
|
|
558 |
#define BASE_OS_DOS 0 /* DOS */
|
|
|
559 |
#define BASE_OS_WIN 1 /* Windows */
|
|
|
560 |
#define BASE_OS_OS2 2 /* OS2 */
|
|
|
561 |
#define BASE_OS_NT 3 /* Windows NT */
|
|
|
562 |
#define BASE_OS_UNIX 4 /* UNIX */
|
|
|
563 |
|
|
|
564 |
/*
|
|
|
565 |
* Watcom does something funny in 386 mode with registers and int86
|
|
|
566 |
*/
|
|
|
567 |
|
|
|
568 |
#if (OS_TYPE == OS_DOS)
|
|
|
569 |
# if defined (__WATCOMC__) && defined(__386__) && !defined(__WINDOWS_386__)
|
|
|
570 |
# define REG_AX eax
|
|
|
571 |
# define REG_BX ebx
|
|
|
572 |
# define REG_CX ecx
|
|
|
573 |
# define REG_DX edx
|
|
|
574 |
# define REG_SI esi
|
|
|
575 |
# define REG_DI edi
|
|
|
576 |
# define REG_CFLAGS cflag
|
|
|
577 |
# define SystemInterrupt(a,b,c) int386 (a, b, c)
|
|
|
578 |
# define SystemExtendedInterrupt(a,b,c,d) int386x (a, b, c, d)
|
|
|
579 |
# define DosInterrupt(a,b) intdos (a, b)
|
|
|
580 |
# define DosExtendedInterrupt(a,b,c) intdosx (a, b, c)
|
|
|
581 |
# elif defined (__EMX__)
|
|
|
582 |
# define REG_AX ax
|
|
|
583 |
# define REG_BX bx
|
|
|
584 |
# define REG_CX cx
|
|
|
585 |
# define REG_DX dx
|
|
|
586 |
# define REG_SI si
|
|
|
587 |
# define REG_DI di
|
|
|
588 |
# define REG_CFLAGS flags
|
|
|
589 |
# define SystemInterrupt(a,b,c) _int86 (a, b, c)
|
|
|
590 |
# define SystemExtendedInterrupt(a,b,c,d) not available
|
|
|
591 |
# define DosInterrupt(a,b) _int86 (0x21, a, b)
|
|
|
592 |
# define DosExtendedInterrupt(a,b,c) intdosx (a, b, c)
|
|
|
593 |
# else
|
|
|
594 |
# define REG_AX ax
|
|
|
595 |
# define REG_BX bx
|
|
|
596 |
# define REG_CX cx
|
|
|
597 |
# define REG_DX dx
|
|
|
598 |
# define REG_SI si
|
|
|
599 |
# define REG_DI di
|
|
|
600 |
# define REG_CFLAGS cflag
|
|
|
601 |
# define SystemInterrupt(a,b,c) int86 (a, b, c)
|
|
|
602 |
# define SystemExtendedInterrupt(a,b,c,d) int86x (a, b, c, d)
|
|
|
603 |
# define DosInterrupt(a,b) intdos (a, b)
|
|
|
604 |
# define DosExtendedInterrupt(a,b,c) intdosx (a, b, c)
|
|
|
605 |
# endif
|
|
|
606 |
#endif
|
|
|
607 |
|
|
|
608 |
/*
|
|
|
609 |
* Missing OS/2 1.x definitions. Map OS/2 2.x definitions as appropriate
|
|
|
610 |
*/
|
|
|
611 |
|
|
|
612 |
#if (OS_TYPE == OS_OS2) && (OS_SIZE == OS_16)
|
|
|
613 |
# define SSF_RELATED_INDEPENDENT 0 /* New session is an */
|
|
|
614 |
/* independent */
|
|
|
615 |
/* session (not related) */
|
|
|
616 |
# define SSF_RELATED_CHILD 1 /* New session is a child */
|
|
|
617 |
/* session (related) */
|
|
|
618 |
# define SSF_FGBG_FORE 0 /* Start session in foreground */
|
|
|
619 |
# define SSF_FGBG_BACK 1 /* Start session in background */
|
|
|
620 |
# define SSF_TRACEOPT_NONE 0 /* No trace */
|
|
|
621 |
# define SSF_TRACEOPT_TRACE 1 /* Trace with no notification */
|
|
|
622 |
/* of descendants */
|
|
|
623 |
# define SSF_TRACEOPT_TRACEALL 2 /* Trace all descendant sessions */
|
|
|
624 |
# define SSF_INHERTOPT_SHELL 0 /* Inherit the Shell's environment.*/
|
|
|
625 |
# define SSF_INHERTOPT_PARENT 1 /* Inherit the environment of the*/
|
|
|
626 |
/* program issuing the */
|
|
|
627 |
/* DosStartSession call. */
|
|
|
628 |
# define SSF_TYPE_DEFAULT 0 /* Use the PgmHandle data, or */
|
|
|
629 |
/* allow the Shell to establish */
|
|
|
630 |
/* the session type. */
|
|
|
631 |
# define SSF_TYPE_FULLSCREEN 1 /* Start the program in a */
|
|
|
632 |
/* full-screen session. */
|
|
|
633 |
# define SSF_TYPE_WINDOWABLEVIO 2 /* Start the program */
|
|
|
634 |
/* in a windowed session for */
|
|
|
635 |
/* programs using the Base Video*/
|
|
|
636 |
/* Subsystem */
|
|
|
637 |
# define SSF_TYPE_PM 3 /* Start the program in a */
|
|
|
638 |
/* windowed session for programs*/
|
|
|
639 |
/* using the Presentation Manager*/
|
|
|
640 |
/* services */
|
|
|
641 |
# define SSF_TYPE_VDM 4 /* Start the program in a */
|
|
|
642 |
/* full-screen DOS session. */
|
|
|
643 |
# define SSF_TYPE_WINDOWEDVDM 7 /* Start the program in a */
|
|
|
644 |
/* windowed DOS session. */
|
|
|
645 |
# define SSF_CONTROL_VISIBLE 0x0000 /* Visible */
|
|
|
646 |
# define SSF_CONTROL_INVISIBLE 0x0001 /* Invisible */
|
|
|
647 |
# define SSF_CONTROL_MAXIMIZE 0x0002 /* Maximize */
|
|
|
648 |
# define SSF_CONTROL_MINIMIZE 0x0004 /* Minimize */
|
|
|
649 |
# define SSF_CONTROL_NOAUTOCLOSE 0x0008 /* No Auto Close */
|
|
|
650 |
# define SSF_CONTROL_SETPOS 0x8000 /* Use specified size and position */
|
|
|
651 |
#endif
|
|
|
652 |
|
|
|
653 |
/*
|
|
|
654 |
* Define common OS2 APIs declaractions
|
|
|
655 |
*/
|
|
|
656 |
|
|
|
657 |
#if (OS_TYPE == OS_OS2)
|
|
|
658 |
# if (OS_SIZE == OS_16)
|
|
|
659 |
# define OSCALL_RET USHORT
|
|
|
660 |
# define OSCALL_PARAM USHORT
|
|
|
661 |
# else
|
|
|
662 |
# define OSCALL_RET APIRET
|
|
|
663 |
# define OSCALL_PARAM ULONG
|
|
|
664 |
# endif
|
|
|
665 |
#elif (OS_TYPE == OS_DOS)
|
|
|
666 |
# define OSCALL_RET unsigned int
|
|
|
667 |
# define OSCALL_PARAM unsigned int
|
|
|
668 |
#elif (OS_TYPE == OS_NT)
|
|
|
669 |
# define OSCALL_RET DWORD
|
|
|
670 |
# define OSCALL_PARAM DWORD
|
|
|
671 |
#elif (OS_TYPE == OS_UNIX)
|
|
|
672 |
# define OSCALL_RET int
|
|
|
673 |
# define OSCALL_PARAM int
|
|
|
674 |
#endif
|
|
|
675 |
|
|
|
676 |
/*
|
|
|
677 |
* Borland TurboC has this in a file we don't include
|
|
|
678 |
*/
|
|
|
679 |
|
|
|
680 |
#ifdef __TURBOC__
|
|
|
681 |
# define getpid() (_psp)
|
|
|
682 |
#endif
|
|
|
683 |
|
|
|
684 |
/*
|
|
|
685 |
* UNIX doesn't have these functions
|
|
|
686 |
*/
|
|
|
687 |
|
|
|
688 |
#if (OS_TYPE == OS_UNIX)
|
|
|
689 |
extern char *strlwr (char *);
|
|
|
690 |
extern char *strupr (char *);
|
|
|
691 |
extern int stricmp (char *, char *);
|
|
|
692 |
# define fputchar(c) putchar (c)
|
|
|
693 |
#endif
|
|
|
694 |
|
|
|
695 |
/*
|
|
|
696 |
* Ignore case compare. UNIX cares about case!
|
|
|
697 |
*/
|
|
|
698 |
|
|
|
699 |
#if (OS_TYPE == OS_UNIX)
|
|
|
700 |
# define NOCASE_COMPARE(a,b) strcmp (a,b)
|
|
|
701 |
#else
|
|
|
702 |
# define NOCASE_COMPARE(a,b) stricmp (a,b)
|
|
|
703 |
#endif
|
|
|
704 |
|
|
|
705 |
/*
|
|
|
706 |
* Executable Head Information structures
|
|
|
707 |
*
|
|
|
708 |
* Variable signatures
|
|
|
709 |
*/
|
|
|
710 |
|
|
|
711 |
#define SIG_DOS 0x5a4d /* Dos Magic number */
|
|
|
712 |
#define SIG_OS2_16 0x454e /* OS/2 16 Magic number */
|
|
|
713 |
#define SIG_OS2_16LE 0x454c /* OS/2 16 Magic number */
|
|
|
714 |
#define SIG_OS2_32 0x584c /* OS/2 32 Magic number */
|
|
|
715 |
#define SIG_NT 0x00004550 /* NT Magic number */
|
|
|
716 |
|
|
|
717 |
/*
|
|
|
718 |
* Standard DOS header
|
|
|
719 |
*/
|
|
|
720 |
|
|
|
721 |
#pragma pack (1)
|
|
|
722 |
|
|
|
723 |
struct ExecDosHeader {
|
|
|
724 |
unsigned short e_magic; /* Magic number */
|
|
|
725 |
unsigned short e_cblp; /* Bytes on last page of file */
|
|
|
726 |
unsigned short e_cp; /* Pages in file */
|
|
|
727 |
unsigned short e_crlc; /* Relocations */
|
|
|
728 |
unsigned short e_cparhdr; /* Size of header in paragraphs */
|
|
|
729 |
unsigned short e_minalloc; /* Minimum extra paras needed */
|
|
|
730 |
unsigned short e_maxalloc; /* Maximum extra paras needed */
|
|
|
731 |
unsigned short e_ss; /* Initial (relative) SS value */
|
|
|
732 |
unsigned short e_sp; /* Initial SP value */
|
|
|
733 |
unsigned short e_csum; /* Checksum */
|
|
|
734 |
unsigned short e_ip; /* Initial IP value */
|
|
|
735 |
unsigned short e_cs; /* Initial (relative) CS value */
|
|
|
736 |
unsigned short e_lfarlc; /* File addr. of reloc. table */
|
|
|
737 |
unsigned short e_ovno; /* Overlay number */
|
|
|
738 |
unsigned short e_res[4]; /* Reserved words */
|
|
|
739 |
unsigned short e_oemid; /* OEM identifier */
|
|
|
740 |
unsigned short e_oeminfo; /* OEM information */
|
|
|
741 |
unsigned short e_res2[10]; /* Reserved words */
|
|
|
742 |
long e_lfanew; /* File addr of new exe header */
|
|
|
743 |
};
|
|
|
744 |
|
|
|
745 |
/*
|
|
|
746 |
* OS/2 and Windows 16 Bit header
|
|
|
747 |
*/
|
|
|
748 |
|
|
|
749 |
struct ExecOS2_16Header {
|
|
|
750 |
unsigned short ne_magic; /* Magic number */
|
|
|
751 |
unsigned char ne_ver; /* Version number */
|
|
|
752 |
unsigned char ne_rev; /* Revision number */
|
|
|
753 |
unsigned short ne_enttab; /* Offset of Entry Table */
|
|
|
754 |
unsigned short ne_cbenttab; /* Size of Entry Table */
|
|
|
755 |
long ne_crc; /* Checksum of whole file */
|
|
|
756 |
unsigned short ne_flags; /* Flag word */
|
|
|
757 |
unsigned short ne_autodata; /* Automatic data segment number*/
|
|
|
758 |
unsigned short ne_heap; /* Initial heap allocation */
|
|
|
759 |
unsigned short ne_stack; /* Initial stack allocation */
|
|
|
760 |
long ne_csip; /* Initial CS:IP setting */
|
|
|
761 |
long ne_sssp; /* Initial SS:SP setting */
|
|
|
762 |
unsigned short ne_cseg; /* Count of file segments */
|
|
|
763 |
unsigned short ne_cmod; /* Entries in Module Ref. Table */
|
|
|
764 |
unsigned short ne_cbnrestab; /* Size non-resident name table */
|
|
|
765 |
unsigned short ne_segtab; /* Off. Segment Table */
|
|
|
766 |
unsigned short ne_rsrctab; /* Off. Resource Table */
|
|
|
767 |
unsigned short ne_restab; /* Off. resident name table */
|
|
|
768 |
unsigned short ne_modtab; /* Off. Module Reference Table */
|
|
|
769 |
unsigned short ne_imptab; /* Off. Imported Names Table */
|
|
|
770 |
long ne_nrestab; /* Off. Non-resident Names Table*/
|
|
|
771 |
unsigned short ne_cmovent; /* Count of movable entries */
|
|
|
772 |
unsigned short ne_align; /* Segment alignment shift count*/
|
|
|
773 |
unsigned short ne_cres; /* Count of resource segments */
|
|
|
774 |
unsigned char ne_exetyp; /* Target Operating system */
|
|
|
775 |
unsigned char ne_flagsothers; /* Other .EXE flags */
|
|
|
776 |
unsigned short ne_pretthunks; /* offset to return thunks */
|
|
|
777 |
unsigned short ne_psegrefbytes;/* offset to segment ref. bytes */
|
|
|
778 |
unsigned short ne_swaparea; /* Minimum code swap area size */
|
|
|
779 |
unsigned short ne_expver; /* Expected Windows version number */
|
|
|
780 |
};
|
|
|
781 |
|
|
|
782 |
/*
|
|
|
783 |
* Selected ne_flags values
|
|
|
784 |
*/
|
|
|
785 |
|
|
|
786 |
#define OS2_16_NOTP 0x8000 /* Not a process */
|
|
|
787 |
#define OS2_16_IERR 0x2000 /* Errors in image */
|
|
|
788 |
#define OS2_16_BOUND 0x0800 /* Bound Family/API */
|
|
|
789 |
#define OS2_16_APPTYP 0x0700 /* Application type mask */
|
|
|
790 |
#define OS2_16_NOTWINCOMPAT 0x0100 /* Not compatible with P.M. Windowing */
|
|
|
791 |
#define OS2_16_WINCOMPAT 0x0200 /* Compatible with P.M. Windowing */
|
|
|
792 |
#define OS2_16_WINAPI 0x0300 /* Uses P.M. Windowing API */
|
|
|
793 |
|
|
|
794 |
/*
|
|
|
795 |
* ne_exetyp values
|
|
|
796 |
*/
|
|
|
797 |
|
|
|
798 |
#define OS2_16_UNKNOWN 0 /* Unknown (any "new-format" OS) */
|
|
|
799 |
#define OS2_16_OS2 1 /* OS/2 (default) */
|
|
|
800 |
#define OS2_16_WINDOWS 2 /* Windows */
|
|
|
801 |
#define OS2_16_DOS4 3 /* DOS 4.x */
|
|
|
802 |
#define OS2_16_DEV386 4 /* Windows 386 */
|
|
|
803 |
|
|
|
804 |
/*
|
|
|
805 |
* OS2 32bit header
|
|
|
806 |
*/
|
|
|
807 |
|
|
|
808 |
struct ExecOS2_32header {
|
|
|
809 |
unsigned short e32_magic; /* Magic number OS2__MAGIC */
|
|
|
810 |
unsigned char e32_border; /* Byte ordering for the .EXE */
|
|
|
811 |
unsigned char e32_worder; /* Word ordering for the .EXE */
|
|
|
812 |
unsigned long e32_level; /* EXE format level for now = 0 */
|
|
|
813 |
unsigned short e32_cpu; /* CPU type */
|
|
|
814 |
unsigned short e32_os; /* OS type */
|
|
|
815 |
unsigned long e32_ver; /* Module version */
|
|
|
816 |
unsigned long e32_mflags; /* Module flags */
|
|
|
817 |
unsigned long e32_mpages; /* Module # pages */
|
|
|
818 |
unsigned long e32_startobj; /* Object # for IP */
|
|
|
819 |
unsigned long e32_eip; /* Extended IP */
|
|
|
820 |
unsigned long e32_stackobj; /* Object # for SS */
|
|
|
821 |
unsigned long e32_esp; /* Extended SS */
|
|
|
822 |
unsigned long e32_pagesize; /* .EXE page size */
|
|
|
823 |
unsigned long e32_pageshift; /* Page alignment shift in .EXE */
|
|
|
824 |
unsigned long e32_fixupsize; /* Fixup section size */
|
|
|
825 |
unsigned long e32_fixupsum; /* Fixup section checksum */
|
|
|
826 |
unsigned long e32_ldrsize; /* Loader section size */
|
|
|
827 |
unsigned long e32_ldrsum; /* Loader section checksum */
|
|
|
828 |
unsigned long e32_objtab; /* Object table off. */
|
|
|
829 |
unsigned long e32_objcnt; /* Number of objects in module */
|
|
|
830 |
unsigned long e32_objmap; /* Object page map off. */
|
|
|
831 |
unsigned long e32_itermap; /* Object iterated data map off. */
|
|
|
832 |
unsigned long e32_rsrctab; /* Off. Resource Table */
|
|
|
833 |
unsigned long e32_rsrccnt; /* Number of resource entries */
|
|
|
834 |
unsigned long e32_restab; /* Off. resident name table */
|
|
|
835 |
unsigned long e32_enttab; /* Off. Entry Table */
|
|
|
836 |
unsigned long e32_dirtab; /* Off. Module Directive Table */
|
|
|
837 |
unsigned long e32_dircnt; /* Number of module directives */
|
|
|
838 |
unsigned long e32_fpagetab; /* Off. Fixup Page Table */
|
|
|
839 |
unsigned long e32_frectab; /* Off. Fixup Record Table */
|
|
|
840 |
unsigned long e32_impmod; /* Off. Import Module Name Table */
|
|
|
841 |
unsigned long e32_impmodcnt; /* # entries in IM Name Table */
|
|
|
842 |
unsigned long e32_impproc; /* Off. IProcedure Name Table */
|
|
|
843 |
unsigned long e32_pagesum; /* Off. Per-Page Checksum Table */
|
|
|
844 |
unsigned long e32_datapage; /* Off. Enumerated Data Pages */
|
|
|
845 |
unsigned long e32_preload; /* Number of preload pages */
|
|
|
846 |
unsigned long e32_nrestab; /* Off. Non-resident Names Table */
|
|
|
847 |
unsigned long e32_cbnrestab; /* Size of Non-resident Name Table */
|
|
|
848 |
unsigned long e32_nressum; /* Non-resident Name Table Checksum */
|
|
|
849 |
unsigned long e32_autodata; /* Object # for automatic data object */
|
|
|
850 |
unsigned long e32_debuginfo; /* Off. the debugging information */
|
|
|
851 |
unsigned long e32_debuglen; /* Length of debugging info. */
|
|
|
852 |
unsigned long e32_instpreload;/* # instance pages in preload */
|
|
|
853 |
/* section of .EXE file */
|
|
|
854 |
unsigned long e32_instdemand; /* # instance pages in demand */
|
|
|
855 |
/* load section of .EXE file */
|
|
|
856 |
unsigned long e32_heapsize; /* Size of heap - for 16-bit apps */
|
|
|
857 |
/* Padding ignored */
|
|
|
858 |
};
|
|
|
859 |
|
|
|
860 |
/*
|
|
|
861 |
* Format of e32_mflags
|
|
|
862 |
*/
|
|
|
863 |
|
|
|
864 |
#define OS2_NOTP 0x00008000L /* Library Module - used as NENOTP */
|
|
|
865 |
#define OS2_NOLOAD 0x00002000L /* Module not Loadable */
|
|
|
866 |
#define OS2_PMAPI 0x00000300L /* Uses PM Windowing API */
|
|
|
867 |
#define OS2_PMW 0x00000200L /* Compatible with PM Windowing */
|
|
|
868 |
#define OS2_NOPMW 0x00000100L /* Incompatible with PM Windowing */
|
|
|
869 |
#define OS2_APPMASK 0x00000700L /* Application Type Mask */
|
|
|
870 |
#define OS2_PROTDLL 0x00010000L /* Protected memory library module */
|
|
|
871 |
#define OS2_DEVICE 0x00020000L /* Device driver */
|
|
|
872 |
#define OS2_MODEXE 0x00000000L /* .EXE module */
|
|
|
873 |
#define OS2_MODDLL 0x00008000L /* .DLL module */
|
|
|
874 |
#define OS2_MODPROTDLL 0x00018000L /* Protected memory library module */
|
|
|
875 |
#define OS2_MODPDEV 0x00020000L /* Physical device driver */
|
|
|
876 |
#define OS2_MODVDEV 0x00028000L /* Virtual device driver */
|
|
|
877 |
#define OS2_MODMASK 0x00038000L /* Module type mask */
|
|
|
878 |
|
|
|
879 |
/*
|
|
|
880 |
* NT Exec Header
|
|
|
881 |
*/
|
|
|
882 |
|
|
|
883 |
struct ExecNTHeader {
|
|
|
884 |
unsigned long Signature;
|
|
|
885 |
|
|
|
886 |
struct NTFileHeader {
|
|
|
887 |
unsigned short Machine;
|
|
|
888 |
unsigned short NumberOfSections;
|
|
|
889 |
unsigned long TimeDateStamp;
|
|
|
890 |
unsigned long PointerToSymbolTable;
|
|
|
891 |
unsigned long NumberOfSymbols;
|
|
|
892 |
unsigned short SizeOfOptionalHeader;
|
|
|
893 |
unsigned short Characteristics;
|
|
|
894 |
} FileHeader;
|
|
|
895 |
|
|
|
896 |
struct NTOptionalHeader {
|
|
|
897 |
unsigned short Magic;
|
|
|
898 |
unsigned char MajorLinkerVersion;
|
|
|
899 |
unsigned char MinorLinkerVersion;
|
|
|
900 |
unsigned long SizeOfCode;
|
|
|
901 |
unsigned long SizeOfInitializedData;
|
|
|
902 |
unsigned long SizeOfUninitializedData;
|
|
|
903 |
unsigned long AddressOfEntryPoint;
|
|
|
904 |
unsigned long BaseOfCode;
|
|
|
905 |
unsigned long BaseOfData;
|
|
|
906 |
unsigned long ImageBase;
|
|
|
907 |
unsigned long SectionAlignment;
|
|
|
908 |
unsigned long FileAlignment;
|
|
|
909 |
unsigned short MajorOperatingSystemVersion;
|
|
|
910 |
unsigned short MinorOperatingSystemVersion;
|
|
|
911 |
unsigned short MajorImageVersion;
|
|
|
912 |
unsigned short MinorImageVersion;
|
|
|
913 |
unsigned short MajorSubsystemVersion;
|
|
|
914 |
unsigned short MinorSubsystemVersion;
|
|
|
915 |
unsigned long Reserved1;
|
|
|
916 |
unsigned long SizeOfImage;
|
|
|
917 |
unsigned long SizeOfHeaders;
|
|
|
918 |
unsigned long CheckSum;
|
|
|
919 |
unsigned short Subsystem;
|
|
|
920 |
unsigned short DllCharacteristics;
|
|
|
921 |
unsigned long SizeOfStackReserve;
|
|
|
922 |
unsigned long SizeOfStackCommit;
|
|
|
923 |
unsigned long SizeOfHeapReserve;
|
|
|
924 |
unsigned long SizeOfHeapCommit;
|
|
|
925 |
unsigned long LoaderFlags;
|
|
|
926 |
unsigned long NumberOfRvaAndSizes;
|
|
|
927 |
/* All entries after this left out */
|
|
|
928 |
} OptionalHeader;
|
|
|
929 |
};
|
|
|
930 |
|
|
|
931 |
#pragma pack ()
|
|
|
932 |
|
|
|
933 |
/*
|
|
|
934 |
* NT header definitions
|
|
|
935 |
*/
|
|
|
936 |
|
|
|
937 |
#define NT_STD_HEADER 28 /* Size of Standard header */
|
|
|
938 |
#define NT_OPTIONAL_HEADER 224 /* Size of Optional header */
|
|
|
939 |
|
|
|
940 |
#define NT_FILE_DLL 0x2000 /* File is a DLL. */
|
|
|
941 |
#define NT_FILE_MACHINE_I386 0x14c /* Intel 386. */
|
|
|
942 |
|
|
|
943 |
/* Subsystem Values */
|
|
|
944 |
|
|
|
945 |
#define NT_SS_NATIVE 1 /* doesn't require a subsystem. */
|
|
|
946 |
#define NT_SS_WINDOWS_GUI 2 /* Windows GUI subsystem. */
|
|
|
947 |
#define NT_SS_WINDOWS_CUI 3 /* Windows character subsystem. */
|
|
|
948 |
#define NT_SS_OS2_CUI 5 /* OS/2 character subsystem. */
|
|
|
949 |
#define NT_SS_POSIX_CUI 7 /* Posix character subsystem. */
|
|
|
950 |
|
|
|
951 |
/*
|
|
|
952 |
* Find the application type
|
|
|
953 |
*/
|
|
|
954 |
|
|
|
955 |
extern unsigned long QueryApplicationType (const char *);
|
|
|
956 |
|
|
|
957 |
/* Result from above */
|
|
|
958 |
|
|
|
959 |
#define EXETYPE_ERROR 0x00000f /* Error on program */
|
|
|
960 |
#define EXETYPE_DOS 0x0000f0 /* Dos program */
|
|
|
961 |
#define EXETYPE_OS2 0x000f00 /* OS/2 16 program */
|
|
|
962 |
#define EXETYPE_OS2_TYPE 0x000700 /* OS/2 Type program */
|
|
|
963 |
#define EXETYPE_OS2_32 0x000800 /* OS/2 32 program */
|
|
|
964 |
#define EXETYPE_NT 0x00f000 /* Win NT program */
|
|
|
965 |
#define EXETYPE_UNIX 0x0f0000 /* UNIX program */
|
|
|
966 |
|
|
|
967 |
#define EXETYPE_UNKNOWN 0x000001 /* Not known */
|
|
|
968 |
#define EXETYPE_BAD_IMAGE 0x000002 /* Bad image */
|
|
|
969 |
#define EXETYPE_NOT_EXE 0x000003 /* Not exe - OS/2 */
|
|
|
970 |
#define EXETYPE_BAD_FILE 0x000004 /* File not found */
|
|
|
971 |
|
|
|
972 |
#define EXETYPE_DOS_CUI 0x000010 /* Dos non windows */
|
|
|
973 |
#define EXETYPE_DOS_GUI 0x000020 /* Windows */
|
|
|
974 |
#define EXETYPE_DOS_32 0x000030 /* Watcom 32 bit */
|
|
|
975 |
#define EXETYPE_DOS_BOUND 0x000040 /* OS/2 Bound */
|
|
|
976 |
|
|
|
977 |
#define EXETYPE_OS2_CUI 0x000100 /* Not windows compat */
|
|
|
978 |
#define EXETYPE_OS2_CGUI 0x000200 /* Windows compatible */
|
|
|
979 |
#define EXETYPE_OS2_GUI 0x000300 /* Uses PM */
|
|
|
980 |
|
|
|
981 |
#define EXETYPE_NT_NATIVE 0x001000 /* NT native */
|
|
|
982 |
#define EXETYPE_NT_WINDOWS_GUI 0x002000 /* NT Windows GUI ss */
|
|
|
983 |
#define EXETYPE_NT_WINDOWS_CUI 0x003000 /* NT Windows CUI ss */
|
|
|
984 |
#define EXETYPE_NT_OS2 0x004000 /* NT OS2 subsystem */
|
|
|
985 |
#define EXETYPE_NT_POSIX 0x005000 /* NT POSIX subsystem */
|
|
|
986 |
|
|
|
987 |
#define EXETYPE_UNIX_NATIVE 0x010000 /* UNIX program */
|
|
|
988 |
|
|
|
989 |
/*
|
|
|
990 |
* Shell Definitions
|
|
|
991 |
*/
|
|
|
992 |
|
|
|
993 |
#define PATCHLEVEL 4
|
|
|
994 |
#define LINE_MAX 1000 /* Command line length */
|
|
|
995 |
#define HISTORY_MAX 100 /* History array length */
|
|
|
996 |
/* Space for full file name */
|
|
|
997 |
#define FFNAME_MAX (PATH_MAX + NAME_MAX + 4)
|
|
|
998 |
#define DOS_CMD_LINE_MAX 127 /* Max command line length */
|
|
|
999 |
#define ARRAY_SIZE(a) ((sizeof (a)) / sizeof (a[0]))
|
|
|
1000 |
|
|
|
1001 |
#if (OS_TYPE == OS_DOS)
|
|
|
1002 |
# define CMD_LINE_MAX DOS_CMD_LINE_MAX
|
|
|
1003 |
#elif (OS_TYPE == OS_OS2)
|
|
|
1004 |
# define CMD_LINE_MAX 32000 /* Max command line length */
|
|
|
1005 |
#elif (OS_TYPE == OS_NT)
|
|
|
1006 |
# define CMD_LINE_MAX 32000 /* Max command line length */
|
|
|
1007 |
#endif
|
|
|
1008 |
|
|
|
1009 |
|
|
|
1010 |
#define SSAVE_IO_SIZE 4 /* Save IO array malloc inc */
|
|
|
1011 |
#define LEN_DEVICE_NAME_HEADER 5 /* /dev/ string length */
|
|
|
1012 |
|
|
|
1013 |
extern int MaxNumberofFDs; /* Max no of file descriptors */
|
|
|
1014 |
#define NUFILE 10 /* # of user-accessible files */
|
|
|
1015 |
#define FDBASE 10 /* First file usable by Shell */
|
|
|
1016 |
|
|
|
1017 |
/*
|
|
|
1018 |
* Some characters
|
|
|
1019 |
*/
|
|
|
1020 |
|
|
|
1021 |
#define CHAR_UNIX_DIRECTORY '/'
|
|
|
1022 |
#define CHAR_NEW_LINE '\n'
|
|
|
1023 |
#define CHAR_SINGLE_QUOTE '\''
|
|
|
1024 |
#define CHAR_DOUBLE_QUOTE '"'
|
|
|
1025 |
#define CHAR_BACKQUOTE '`'
|
|
|
1026 |
#define CHAR_RETURN '\r'
|
|
|
1027 |
#define CHAR_SPACE ' '
|
|
|
1028 |
#define CHAR_NOT '^'
|
|
|
1029 |
#define CHAR_TAB '\t'
|
|
|
1030 |
#define CHAR_BACKSPACE '\b'
|
|
|
1031 |
#define CHAR_ESCAPE 0x1b
|
|
|
1032 |
#define CHAR_XOR '^'
|
|
|
1033 |
#define CHAR_BEGIN_LINE '^'
|
|
|
1034 |
#define CHAR_OPEN_PARATHENSIS '('
|
|
|
1035 |
#define CHAR_CLOSE_PARATHENSIS ')'
|
|
|
1036 |
#define CHAR_OPEN_BRACES '{'
|
|
|
1037 |
#define CHAR_CLOSE_BRACES '}'
|
|
|
1038 |
#define CHAR_OPEN_BRACKETS '['
|
|
|
1039 |
#define CHAR_CLOSE_BRACKETS ']'
|
|
|
1040 |
#define CHAR_TILDE '~'
|
|
|
1041 |
#define CHAR_PIPE '|'
|
|
|
1042 |
#define CHAR_HISTORY '!'
|
|
|
1043 |
#define CHAR_COMMENT '#'
|
|
|
1044 |
#define CHAR_MATCH_START '#'
|
|
|
1045 |
#define CHAR_VARIABLE '$'
|
|
|
1046 |
#define CHAR_END_LINE '$'
|
|
|
1047 |
#define CHAR_FORMAT '%'
|
|
|
1048 |
#define CHAR_JOBID '%'
|
|
|
1049 |
#define CHAR_MATCH_END '%'
|
|
|
1050 |
#define CHAR_ASYNC '&'
|
|
|
1051 |
#define CHAR_MATCH_ALL '*'
|
|
|
1052 |
#define CHAR_PLUS '+'
|
|
|
1053 |
#define CHAR_HYPHEN '-'
|
|
|
1054 |
#define CHAR_MATCH_RANGE '-'
|
|
|
1055 |
#define CHAR_CLOSE_FD '-'
|
|
|
1056 |
#define CHAR_SWITCH '-'
|
|
|
1057 |
#define CHAR_PERIOD '.'
|
|
|
1058 |
#define CHAR_COLON ':'
|
|
|
1059 |
#define CHAR_DRIVE ':'
|
|
|
1060 |
#define CHAR_SEPARATOR ';'
|
|
|
1061 |
|
|
|
1062 |
#if (OS_TYPE == OS_UNIX)
|
|
|
1063 |
# define CHAR_PATH_SEPARATOR ':'
|
|
|
1064 |
#else
|
|
|
1065 |
# define CHAR_PATH_SEPARATOR ';'
|
|
|
1066 |
#endif
|
|
|
1067 |
|
|
|
1068 |
#define CHAR_INPUT '<'
|
|
|
1069 |
#define CHAR_ASSIGN '='
|
|
|
1070 |
#define CHAR_OUTPUT '>'
|
|
|
1071 |
#define CHAR_MATCH_ANY '?'
|
|
|
1072 |
#define CHAR_INDIRECT '@'
|
|
|
1073 |
#define CHAR_META '\\'
|
|
|
1074 |
#define CHAR_DOS_PATH '\\'
|
|
|
1075 |
#define CHAR_MAGIC 0x80
|
|
|
1076 |
|
|
|
1077 |
/*
|
|
|
1078 |
* fast character classes
|
|
|
1079 |
*/
|
|
|
1080 |
|
|
|
1081 |
#define C_ALPHA 0x001 /* a-z_A-Z */
|
|
|
1082 |
#define C_DIGIT 0x002 /* 0-9 */
|
|
|
1083 |
#define C_LEX1 0x004 /* \0 \t\n|&;<>() */
|
|
|
1084 |
#define C_VAR1 0x008 /* *@#!$-? */
|
|
|
1085 |
#define C_SUBOP 0x010 /* "=-+?#%" */
|
|
|
1086 |
#define C_IFS 0x020 /* $IFS */
|
|
|
1087 |
#define C_WILD 0x040 /* Wildcards */
|
|
|
1088 |
#define C_SEMICOLON 0x080 /* Semi-colon (;) */
|
|
|
1089 |
|
|
|
1090 |
extern void InitialiseCharacterTypes (void);
|
|
|
1091 |
extern void SetCharacterTypes (char *, int);
|
|
|
1092 |
extern unsigned char CharTypes [UCHAR_MAX + 1];
|
|
|
1093 |
|
|
|
1094 |
/*
|
|
|
1095 |
* Check for variable characters
|
|
|
1096 |
*/
|
|
|
1097 |
|
|
|
1098 |
#define IS_VariableFC(c) (CharTypes[(c)] & C_ALPHA)
|
|
|
1099 |
#define IS_VariableSC(c) (CharTypes[(c)] & (C_ALPHA | C_DIGIT))
|
|
|
1100 |
|
|
|
1101 |
#define IS_Numeric(c) (CharTypes[(c)] & C_DIGIT)
|
|
|
1102 |
#define IS_AlphaNumeric(c) (CharTypes[(c)] & (C_ALPHA | C_DIGIT))
|
|
|
1103 |
#define IS_IFS(c) (CharTypes[(c)] & C_IFS)
|
|
|
1104 |
#define IS_Lexical(c) (CharTypes[(c)] & C_LEX1)
|
|
|
1105 |
#define IS_VarNumeric(c) (CharTypes[(c)] & (C_DIGIT | C_VAR1))
|
|
|
1106 |
#define IS_VarOp(c) (CharTypes[(c)] & C_SUBOP)
|
|
|
1107 |
#define IS_WildCard(c) (CharTypes[(c)] & C_WILD)
|
|
|
1108 |
|
|
|
1109 |
extern char *SkipToWhiteSpace (char *);
|
|
|
1110 |
|
|
|
1111 |
/*
|
|
|
1112 |
* File open modes
|
|
|
1113 |
*/
|
|
|
1114 |
/* Open in create mode */
|
|
|
1115 |
#define O_CMASK (O_WRONLY | O_CREAT | O_TRUNC | O_BINARY)
|
|
|
1116 |
/* Open in create mode for a pipe */
|
|
|
1117 |
#define O_PMASK (O_RDWR | O_CREAT | O_TRUNC | O_TEXT)
|
|
|
1118 |
/* Open in create mode for swap file */
|
|
|
1119 |
#define O_SMASK (O_RDWR | O_CREAT | O_TRUNC | O_BINARY)
|
|
|
1120 |
#define O_SaMASK (O_RDWR | O_BINARY)
|
|
|
1121 |
#define O_RMASK (O_RDONLY | O_NOINHERIT | O_TEXT)
|
|
|
1122 |
|
|
|
1123 |
/*
|
|
|
1124 |
* Path format conversion
|
|
|
1125 |
*/
|
|
|
1126 |
|
|
|
1127 |
#define PATH_TO_UNIX(x) ConvertPathToFormat ((x), CHAR_DOS_PATH, \
|
|
|
1128 |
CHAR_UNIX_DIRECTORY)
|
|
|
1129 |
#define PATH_TO_DOS(x) ConvertPathToFormat ((x), CHAR_UNIX_DIRECTORY, \
|
|
|
1130 |
CHAR_DOS_PATH)
|
|
|
1131 |
|
|
|
1132 |
#if (OS_TYPE == OS_UNIX)
|
|
|
1133 |
# define PATH_TO_UPPER_CASE(a)
|
|
|
1134 |
# define PATH_TO_LOWER_CASE(a)
|
|
|
1135 |
# define IsHPFSFileSystem(a) TRUE
|
|
|
1136 |
#elif (OS_TYPE != OS_DOS)
|
|
|
1137 |
# define PATH_TO_UPPER_CASE(a) {if (!IsHPFSFileSystem (a)) strupr (a); }
|
|
|
1138 |
# define PATH_TO_LOWER_CASE(a) {if (!IsHPFSFileSystem (a)) strlwr (a); }
|
|
|
1139 |
#else
|
|
|
1140 |
# define PATH_TO_UPPER_CASE(a) { strupr (a); }
|
|
|
1141 |
# define PATH_TO_LOWER_CASE(a) { strlwr (a); }
|
|
|
1142 |
# define IsHPFSFileSystem(a) FALSE
|
|
|
1143 |
#endif
|
|
|
1144 |
|
|
|
1145 |
/*
|
|
|
1146 |
* Drive support
|
|
|
1147 |
*/
|
|
|
1148 |
|
|
|
1149 |
#if (OS_TYPE == OS_UNIX)
|
|
|
1150 |
# define IsDriveCharacter(a) FALSE
|
|
|
1151 |
#else
|
|
|
1152 |
# define IsDriveCharacter(a) C2bool ((a) == CHAR_DRIVE)
|
|
|
1153 |
#endif
|
|
|
1154 |
|
|
|
1155 |
#define IsPathCharacter(a) C2bool ((a) == CHAR_UNIX_DIRECTORY)
|
|
|
1156 |
#define FindLastPathCharacter(a) strrchr (a, CHAR_UNIX_DIRECTORY)
|
|
|
1157 |
#define FindPathCharacter(a) strchr (a, CHAR_UNIX_DIRECTORY)
|
|
|
1158 |
|
|
|
1159 |
/*
|
|
|
1160 |
* shell components
|
|
|
1161 |
*/
|
|
|
1162 |
|
|
|
1163 |
#define NOBLOCK ((C_Op *)NULL)
|
|
|
1164 |
#define NOWORD ((char *)NULL)
|
|
|
1165 |
#define NOWORDS ((char **)NULL)
|
|
|
1166 |
#define NOPIPE (-1)
|
|
|
1167 |
|
|
|
1168 |
/*
|
|
|
1169 |
* Ignore Variables flags
|
|
|
1170 |
*/
|
|
|
1171 |
|
|
|
1172 |
#define DISABLE_MAILCHECK 0x0001
|
|
|
1173 |
#define DISABLE_OPTARG 0x0002
|
|
|
1174 |
#define DISABLE_OPTIND 0x0004
|
|
|
1175 |
#define DISABLE_SECONDS 0x0008
|
|
|
1176 |
#define DISABLE_RANDOM 0x0010
|
|
|
1177 |
#define DISABLE_LASTWORD 0x0020
|
|
|
1178 |
#define DISABLE_LINECOUNT 0x0040
|
|
|
1179 |
#define DISABLE_WINTITLE 0x0080
|
|
|
1180 |
|
|
|
1181 |
extern int DisabledVariables;
|
|
|
1182 |
|
|
|
1183 |
/*
|
|
|
1184 |
* File Descriptor Types and Macros
|
|
|
1185 |
*/
|
|
|
1186 |
|
|
|
1187 |
#define DESCRIPTOR_UNKNOWN 0x0000 /* Error - not known */
|
|
|
1188 |
#define DESCRIPTOR_PIPE 0x0001 /* Pipe */
|
|
|
1189 |
#define DESCRIPTOR_FILE 0x0002 /* File */
|
|
|
1190 |
#define DESCRIPTOR_DEVICE 0x0004 /* Device - tty */
|
|
|
1191 |
#define DESCRIPTOR_CONSOLE 0x0008 /* Console device */
|
|
|
1192 |
|
|
|
1193 |
#define IS_Pipe(a) (GetDescriptorType (a) & DESCRIPTOR_PIPE)
|
|
|
1194 |
#define IS_File(a) (GetDescriptorType (a) & DESCRIPTOR_FILE)
|
|
|
1195 |
#define IS_TTY(a) (GetDescriptorType (a) & \
|
|
|
1196 |
(DESCRIPTOR_DEVICE | DESCRIPTOR_CONSOLE))
|
|
|
1197 |
#define IS_Console(a) (GetDescriptorType (a) & DESCRIPTOR_CONSOLE)
|
|
|
1198 |
|
|
|
1199 |
/*
|
|
|
1200 |
* Result from FindLocationOfExecutable
|
|
|
1201 |
*/
|
|
|
1202 |
|
|
|
1203 |
#define EXTENSION_NOT_FOUND 0 /* Cannot find file */
|
|
|
1204 |
#define EXTENSION_EXECUTABLE 1 /* OS/2 or DOS .exe or .com */
|
|
|
1205 |
#define EXTENSION_BATCH 2 /* OS/2 or DOS .cmd or .bat */
|
|
|
1206 |
#define EXTENSION_SHELL_SCRIPT 3 /* Shell script */
|
|
|
1207 |
#define EXTENSION_OTHER 4 /* Other */
|
|
|
1208 |
|
|
|
1209 |
/*
|
|
|
1210 |
* XString - Expandable strings
|
|
|
1211 |
*
|
|
|
1212 |
* XString functions:
|
|
|
1213 |
*
|
|
|
1214 |
* XFree - Release the string
|
|
|
1215 |
* XStart - Get start of string
|
|
|
1216 |
* XClose - close a string
|
|
|
1217 |
* XCreate - Create a string
|
|
|
1218 |
* XCheck - Check for overflow
|
|
|
1219 |
*/
|
|
|
1220 |
|
|
|
1221 |
typedef struct XString {
|
|
|
1222 |
unsigned char *SStart; /* End of string */
|
|
|
1223 |
unsigned char *SEnd; /* Beginning of string */
|
|
|
1224 |
size_t SLength; /* length */
|
|
|
1225 |
} XString;
|
|
|
1226 |
|
|
|
1227 |
#define XFree(xs) ReleaseMemoryCell ((void*)(xs).SStart)
|
|
|
1228 |
#define XStart(xs) ((xs).SStart)
|
|
|
1229 |
#define XCurrentOffset(xs, xp) (xp - (xs).SStart)
|
|
|
1230 |
#define XResetOffset(xs, n) ((xs).SStart + (n))
|
|
|
1231 |
|
|
|
1232 |
extern void XCheck (XString *, unsigned char **);
|
|
|
1233 |
extern char *XClose (XString *, unsigned char *);
|
|
|
1234 |
extern char *XCreate (XString *, size_t);
|
|
|
1235 |
|
|
|
1236 |
/*
|
|
|
1237 |
* Description of a command or an operation on commands.
|
|
|
1238 |
* Might eventually use a union.
|
|
|
1239 |
*/
|
|
|
1240 |
|
|
|
1241 |
typedef struct op {
|
|
|
1242 |
int type; /* operation type, see below */
|
|
|
1243 |
char **args; /* arguments to a command */
|
|
|
1244 |
char **vars; /* variable assignments */
|
|
|
1245 |
struct ioword **ioact; /* IO actions (eg, < > >>) */
|
|
|
1246 |
struct op *left;
|
|
|
1247 |
struct op *right;
|
|
|
1248 |
char *str; /* identifier for case and for */
|
|
|
1249 |
} C_Op;
|
|
|
1250 |
|
|
|
1251 |
/*
|
|
|
1252 |
* C_Op.type values
|
|
|
1253 |
*/
|
|
|
1254 |
|
|
|
1255 |
#define TEOF 0
|
|
|
1256 |
#define TCOM 1 /* command */
|
|
|
1257 |
#define TPAREN 2 /* (c-list) */
|
|
|
1258 |
#define TPIPE 3 /* a | b */
|
|
|
1259 |
#define TLIST 4 /* a [&;] b */
|
|
|
1260 |
#define TOR 5 /* || */
|
|
|
1261 |
#define TAND 6 /* && */
|
|
|
1262 |
#define TFOR 7 /* FOR */
|
|
|
1263 |
#define TCOPROCESS 8 /* coprocess */
|
|
|
1264 |
#define TCASE 9 /* CASE */
|
|
|
1265 |
#define TIF 10 /* IF */
|
|
|
1266 |
#define TWHILE 11 /* WHILE */
|
|
|
1267 |
#define TUNTIL 12 /* UNTIL */
|
|
|
1268 |
#define TELIF 13 /* ELSE IF */
|
|
|
1269 |
#define TPAT 14 /* pattern in case */
|
|
|
1270 |
#define TBRACE 15 /* {c-list} */
|
|
|
1271 |
#define TASYNC 16 /* c & */
|
|
|
1272 |
#define TFUNC 17 /* c () {c-list} */
|
|
|
1273 |
#define TSELECT 18 /* SELECT */
|
|
|
1274 |
#define TTIME 19 /* time pipeline */
|
|
|
1275 |
|
|
|
1276 |
/*
|
|
|
1277 |
* Prefix codes for words in command tree
|
|
|
1278 |
*/
|
|
|
1279 |
|
|
|
1280 |
#define WORD_EOS 0 /* end of string */
|
|
|
1281 |
#define WORD_CHAR 1 /* unquoted character */
|
|
|
1282 |
#define WORD_QCHAR 2 /* quoted character */
|
|
|
1283 |
#define WORD_QTCHAR 3 /* temporary quoted character */
|
|
|
1284 |
#define WORD_COMSUB 4 /* $() substitution (0 terminated) */
|
|
|
1285 |
#define WORD_OQUOTE 5 /* opening ' */
|
|
|
1286 |
#define WORD_CQUOTE 6 /* closing ' */
|
|
|
1287 |
#define WORD_ODQUOTE 7 /* opening " */
|
|
|
1288 |
#define WORD_CDQUOTE 8 /* closing " */
|
|
|
1289 |
#define WORD_OSUBST 9 /* opening ${ substitution */
|
|
|
1290 |
#define WORD_CSUBST 10 /* closing } of above */
|
|
|
1291 |
#define WORD_OMATHS 11 /* opening $(()) substitution (0 term) */
|
|
|
1292 |
#define WORD_OARRAY 12 /* opening ${name[ of array */
|
|
|
1293 |
#define WORD_CARRAY 13 /* closing ] for above */
|
|
|
1294 |
|
|
|
1295 |
/*
|
|
|
1296 |
* Syntax and Lexical Analysis
|
|
|
1297 |
*
|
|
|
1298 |
* Lexical tokens
|
|
|
1299 |
*/
|
|
|
1300 |
|
|
|
1301 |
#define PARSE_WORD 256
|
|
|
1302 |
#define PARSE_LOGICAL_AND 257 /* && */
|
|
|
1303 |
#define PARSE_LOGICAL_OR 258 /* || */
|
|
|
1304 |
#define PARSE_BREAK 259
|
|
|
1305 |
#define PARSE_IF 260
|
|
|
1306 |
#define PARSE_THEN 261
|
|
|
1307 |
#define PARSE_ELSE 262
|
|
|
1308 |
#define PARSE_ELIF 263
|
|
|
1309 |
#define PARSE_FI 264
|
|
|
1310 |
#define PARSE_CASE 265
|
|
|
1311 |
#define PARSE_ESAC 266
|
|
|
1312 |
#define PARSE_FOR 267
|
|
|
1313 |
#define PARSE_WHILE 268
|
|
|
1314 |
#define PARSE_UNTIL 269
|
|
|
1315 |
#define PARSE_DO 270
|
|
|
1316 |
#define PARSE_DONE 271
|
|
|
1317 |
#define PARSE_IN 272
|
|
|
1318 |
#define PARSE_SELECT 273
|
|
|
1319 |
#define PARSE_FUNCTION 274
|
|
|
1320 |
#define PARSE_TIME 275
|
|
|
1321 |
#define PARSE_REDIR 276 /* >, <, etc */
|
|
|
1322 |
#define PARSE_MPAREN 277 /* () */
|
|
|
1323 |
#define PARSE_MDPAREN 278 /* (( )) */
|
|
|
1324 |
#define PARSE_TEST 279 /* [[ ]] */
|
|
|
1325 |
#define PARSE_COPROCESS 280 /* |& */
|
|
|
1326 |
#define YYERRCODE 300
|
|
|
1327 |
|
|
|
1328 |
/*
|
|
|
1329 |
* Lexical token value
|
|
|
1330 |
*/
|
|
|
1331 |
|
|
|
1332 |
typedef union {
|
|
|
1333 |
int i; /* Integer */
|
|
|
1334 |
char *cp; /* String */
|
|
|
1335 |
char **wp; /* List */
|
|
|
1336 |
struct op *o; /* Command tree */
|
|
|
1337 |
struct ioword *iop; /* IO action */
|
|
|
1338 |
} YYSTYPE;
|
|
|
1339 |
|
|
|
1340 |
/*
|
|
|
1341 |
* flags to ScanNextToken
|
|
|
1342 |
*/
|
|
|
1343 |
|
|
|
1344 |
#define ALLOW_CONTINUATION 0x0001 /* skip new lines to complete */
|
|
|
1345 |
/* command */
|
|
|
1346 |
#define ONEWORD 0x0002 /* single word for substitute() */
|
|
|
1347 |
#define ALLOW_ALIAS 0x0004 /* recognize alias */
|
|
|
1348 |
#define ALLOW_KEYWORD 0x0008 /* recognize keywords */
|
|
|
1349 |
#define MATHS_EXPRESSION 0x0010 /* get expression inside (( )) */
|
|
|
1350 |
#define TEST_EXPRESSION 0x0020 /* get expression inside [[ ]] */
|
|
|
1351 |
|
|
|
1352 |
|
|
|
1353 |
#define IDENT 64 /* Max size of an Identifier */
|
|
|
1354 |
extern char CurrentLexIdentifier [IDENT+1];
|
|
|
1355 |
|
|
|
1356 |
/*
|
|
|
1357 |
* Input descriptor for yylex
|
|
|
1358 |
*/
|
|
|
1359 |
|
|
|
1360 |
typedef struct source {
|
|
|
1361 |
char *str; /* input pointe */
|
|
|
1362 |
int type; /* input type */
|
|
|
1363 |
union {
|
|
|
1364 |
char **strv; /* string [] */
|
|
|
1365 |
FILE *file; /* file */
|
|
|
1366 |
struct AliasList *Calias; /* alias */
|
|
|
1367 |
} u;
|
|
|
1368 |
|
|
|
1369 |
int line; /* line number */
|
|
|
1370 |
char *file; /* input file name */
|
|
|
1371 |
bool echo; /* echo input to shlout */
|
|
|
1372 |
struct source *next; /* stacked source */
|
|
|
1373 |
} Source;
|
|
|
1374 |
|
|
|
1375 |
/* Source.type values */
|
|
|
1376 |
|
|
|
1377 |
#define SEOF 0 /* input EOF */
|
|
|
1378 |
#define STTY 1 /* terminal input */
|
|
|
1379 |
#define SFILE 2 /* file input */
|
|
|
1380 |
#define SWSTR 3 /* string without \n */
|
|
|
1381 |
#define SSTRING 4 /* string */
|
|
|
1382 |
#define SWORDS 5 /* string[] */
|
|
|
1383 |
#define SALIAS 6 /* alias expansion */
|
|
|
1384 |
#define SWORDSEP 8 /* string[] seperator */
|
|
|
1385 |
|
|
|
1386 |
extern Source *pushs (int); /* push Source */
|
|
|
1387 |
extern C_Op *compile (Source *s); /* compile tree */
|
|
|
1388 |
|
|
|
1389 |
|
|
|
1390 |
extern Source *source; /* yyparse/yylex source */
|
|
|
1391 |
extern YYSTYPE yylval; /* result from yylex */
|
|
|
1392 |
extern int yynerrs;
|
|
|
1393 |
|
|
|
1394 |
/* Built in Command list */
|
|
|
1395 |
|
|
|
1396 |
struct builtin {
|
|
|
1397 |
char *command;
|
|
|
1398 |
int (*fn)(int, char **);
|
|
|
1399 |
int mode;
|
|
|
1400 |
};
|
|
|
1401 |
|
|
|
1402 |
extern int doexec (C_Op *); /* Exec function a cheat */
|
|
|
1403 |
|
|
|
1404 |
/*
|
|
|
1405 |
* Valid values of mode
|
|
|
1406 |
*/
|
|
|
1407 |
|
|
|
1408 |
#define BLT_ALWAYS 0x0001 /* Always use builtin version */
|
|
|
1409 |
#define BLT_CURRENT 0x0002 /* Currently use builtin version */
|
|
|
1410 |
#define BLT_NOGLOB 0x0004 /* No globbing for this internal */
|
|
|
1411 |
#define BLT_CENVIRON 0x0008 /* Don't create a new environment */
|
|
|
1412 |
#define BLT_NOWORDS 0x0010 /* Don't split words for this internal */
|
|
|
1413 |
#define BLT_SKIPGLOB (BLT_CURRENT | BLT_NOGLOB)
|
|
|
1414 |
#define BLT_SKIPENVIR (BLT_CURRENT | BLT_CENVIRON)
|
|
|
1415 |
|
|
|
1416 |
/*
|
|
|
1417 |
* actions determining the environment of a process
|
|
|
1418 |
*/
|
|
|
1419 |
|
|
|
1420 |
#define EXEC_WITHOUT_FORK 0x0001 /* execute without forking */
|
|
|
1421 |
#define EXEC_FUNCTION 0x0002 /* execute a function */
|
|
|
1422 |
|
|
|
1423 |
#if (OS_TYPE != OS_DOS)
|
|
|
1424 |
# define EXEC_SPAWN_NOWAIT 0x0004 /* execute a non-wait */
|
|
|
1425 |
# define EXEC_SPAWN_DETACH 0x0008 /* execute a detach */
|
|
|
1426 |
# define EXEC_SPAWN_IGNOREWAIT 0x0010 /* Pipe processing */
|
|
|
1427 |
#endif
|
|
|
1428 |
|
|
|
1429 |
#define EXEC_PIPE_IN 0x0020 /* On pipe */
|
|
|
1430 |
#define EXEC_PIPE_SUBS 0x0040 /* Second command */
|
|
|
1431 |
#define EXEC_WINDOWS 0x0080 /* Start Windows app */
|
|
|
1432 |
|
|
|
1433 |
extern unsigned int SW_intr; /* interrupt pending */
|
|
|
1434 |
extern bool IgnoreInterrupts;/* Ignore interrupts flag */
|
|
|
1435 |
|
|
|
1436 |
extern int LastNumberBase; /* Last base entered */
|
|
|
1437 |
|
|
|
1438 |
#ifdef OS_SWAPPING
|
|
|
1439 |
extern unsigned int far SW_Mode; /* Type of swapping to do */
|
|
|
1440 |
/* 1 - disk */
|
|
|
1441 |
/* 2 - Extended memory */
|
|
|
1442 |
/* 3 - EMS Driver */
|
|
|
1443 |
/* 4 - XMS Driver */
|
|
|
1444 |
extern int Swap_Mode; /* Swapping mode */
|
|
|
1445 |
|
|
|
1446 |
/* If you change these values, change sh7, swap_device as well */
|
|
|
1447 |
|
|
|
1448 |
# define SWAP_OFF 0x0000 /* No swapping */
|
|
|
1449 |
# define SWAP_DISK 0x0001 /* Disk only */
|
|
|
1450 |
# define SWAP_EXTEND 0x0002 /* Extended memory */
|
|
|
1451 |
# define SWAP_EXPAND 0x0004 /* Expanded memory */
|
|
|
1452 |
#endif
|
|
|
1453 |
|
|
|
1454 |
/*
|
|
|
1455 |
* Convert to bool
|
|
|
1456 |
*/
|
|
|
1457 |
|
|
|
1458 |
#define C2bool(c) (bool)((c) ? TRUE : FALSE)
|
|
|
1459 |
|
|
|
1460 |
/*
|
|
|
1461 |
* flags to control evaluation of words
|
|
|
1462 |
*/
|
|
|
1463 |
|
|
|
1464 |
#define EXPAND_SPLITIFS 0x01 /* Perform blank interpretation */
|
|
|
1465 |
#define EXPAND_GLOBBING 0x02 /* Do globbing on name */
|
|
|
1466 |
#define EXPAND_PATTERN 0x04 /* quote *?[ */
|
|
|
1467 |
#define EXPAND_TILDE 0x10 /* expand ~ */
|
|
|
1468 |
#define EXPAND_CONVERT 0x20 /* Convert - and / to DOS format */
|
|
|
1469 |
#define EXPAND_NOALTS 0x40 /* No alternations */
|
|
|
1470 |
|
|
|
1471 |
/*
|
|
|
1472 |
* Hard error handler
|
|
|
1473 |
*/
|
|
|
1474 |
|
|
|
1475 |
#if (OS_TYPE == OS_OS2)
|
|
|
1476 |
# if (OS_SIZE == OS_32)
|
|
|
1477 |
# define DISABLE_HARD_ERRORS DosError (FERR_DISABLEHARDERR)
|
|
|
1478 |
# define ENABLE_HARD_ERRORS DosError (FERR_ENABLEHARDERR)
|
|
|
1479 |
# else
|
|
|
1480 |
# define DISABLE_HARD_ERRORS DosError (HARDERROR_DISABLE)
|
|
|
1481 |
# define ENABLE_HARD_ERRORS DosError (HARDERROR_ENABLE)
|
|
|
1482 |
# endif
|
|
|
1483 |
|
|
|
1484 |
#elif (OS_TYPE == OS_NT)
|
|
|
1485 |
# define DISABLE_HARD_ERRORS SetErrorMode (SEM_FAILCRITICALERRORS | \
|
|
|
1486 |
SEM_NOOPENFILEERRORBOX)
|
|
|
1487 |
# define ENABLE_HARD_ERRORS SetErrorMode (0)
|
|
|
1488 |
|
|
|
1489 |
#elif (OS_TYPE == OS_DOS)
|
|
|
1490 |
# if (OS_SIZE == OS_32)
|
|
|
1491 |
extern bool IgnoreHardErrors;
|
|
|
1492 |
# define DISABLE_HARD_ERRORS IgnoreHardErrors = TRUE;
|
|
|
1493 |
# define ENABLE_HARD_ERRORS IgnoreHardErrors = FALSE;
|
|
|
1494 |
# else
|
|
|
1495 |
# define DISABLE_HARD_ERRORS
|
|
|
1496 |
# define ENABLE_HARD_ERRORS
|
|
|
1497 |
# endif
|
|
|
1498 |
|
|
|
1499 |
#elif (OS_TYPE == OS_UNIX)
|
|
|
1500 |
# define DISABLE_HARD_ERRORS
|
|
|
1501 |
# define ENABLE_HARD_ERRORS
|
|
|
1502 |
#endif
|
|
|
1503 |
|
|
|
1504 |
/*
|
|
|
1505 |
* General variables
|
|
|
1506 |
*/
|
|
|
1507 |
|
|
|
1508 |
extern char **ParameterArray;/* $<numeric> values */
|
|
|
1509 |
extern int ParameterCount; /* $<numeric> count */
|
|
|
1510 |
extern int ExitStatus;
|
|
|
1511 |
extern bool ExpansionErrorDetected;
|
|
|
1512 |
extern bool InteractiveFlag;/* interactive */
|
|
|
1513 |
extern bool ProcessingEXECCommand;
|
|
|
1514 |
extern int AllowMultipleLines; /* Allow continuation */
|
|
|
1515 |
extern int Current_Event; /* Current history event */
|
|
|
1516 |
extern bool ChangeInitLoad; /* Change load .ini point. */
|
|
|
1517 |
|
|
|
1518 |
/*
|
|
|
1519 |
* Break/Continue (in for and while), Return and Exit handler
|
|
|
1520 |
*/
|
|
|
1521 |
|
|
|
1522 |
typedef struct brkcon {
|
|
|
1523 |
jmp_buf CurrentReturnPoint;
|
|
|
1524 |
struct brkcon *NextExitLevel;
|
|
|
1525 |
} Break_C;
|
|
|
1526 |
/* Values returned by longjmp */
|
|
|
1527 |
#define BC_LOAD 0 /* Load condition */
|
|
|
1528 |
#define BC_BREAK 1 /* Break condition */
|
|
|
1529 |
#define BC_CONTINUE 2 /* Continue condition */
|
|
|
1530 |
|
|
|
1531 |
extern Break_C *Break_List; /* Break list for FOR/WHILE */
|
|
|
1532 |
extern Break_C *Return_List; /* Return list for RETURN */
|
|
|
1533 |
extern Break_C *SShell_List; /* SubShell list for EXIT */
|
|
|
1534 |
extern bool RestrictedShellFlag; /* Read only shell */
|
|
|
1535 |
extern bool HistoryEnabled;
|
|
|
1536 |
|
|
|
1537 |
/*
|
|
|
1538 |
* Word List structure
|
|
|
1539 |
*/
|
|
|
1540 |
|
|
|
1541 |
typedef struct wdblock {
|
|
|
1542 |
short w_bsize;
|
|
|
1543 |
short w_nword;
|
|
|
1544 |
char *w_words[1];
|
|
|
1545 |
} Word_B;
|
|
|
1546 |
|
|
|
1547 |
/*
|
|
|
1548 |
* Save Standard Input/Output/Error structure
|
|
|
1549 |
*/
|
|
|
1550 |
|
|
|
1551 |
typedef struct save_io {
|
|
|
1552 |
int depth; /* Execute recursive depth */
|
|
|
1553 |
int fp[STDERR_FILENO + 1]; /* File handlers */
|
|
|
1554 |
} Save_IO;
|
|
|
1555 |
|
|
|
1556 |
extern Save_IO *SSave_IO; /* Save IO array */
|
|
|
1557 |
extern int NSave_IO_E; /* Number of entries */
|
|
|
1558 |
extern int MSave_IO_E; /* Max Number of entries */
|
|
|
1559 |
|
|
|
1560 |
/*
|
|
|
1561 |
* Function tree processing
|
|
|
1562 |
*/
|
|
|
1563 |
|
|
|
1564 |
typedef struct FunctionList {
|
|
|
1565 |
C_Op *tree; /* The tree itself */
|
|
|
1566 |
bool Traced; /* Traced flag */
|
|
|
1567 |
} FunctionList;
|
|
|
1568 |
|
|
|
1569 |
extern void *FunctionTree; /* Function Tree root */
|
|
|
1570 |
extern FunctionList *CurrentFunction;
|
|
|
1571 |
|
|
|
1572 |
/*
|
|
|
1573 |
* Alias processing
|
|
|
1574 |
*/
|
|
|
1575 |
|
|
|
1576 |
typedef struct AliasList {
|
|
|
1577 |
char *name; /* The alias name */
|
|
|
1578 |
char *value; /* The alias */
|
|
|
1579 |
int AFlags; /* Alias flags */
|
|
|
1580 |
} AliasList;
|
|
|
1581 |
|
|
|
1582 |
extern void *AliasTree; /* Alias Tree root */
|
|
|
1583 |
|
|
|
1584 |
#define ALIAS_TRACKED 0x0001 /* Tracked alias */
|
|
|
1585 |
#define ALIAS_EXPANDING 0x0002 /* Alias being expanded */
|
|
|
1586 |
#define MAX_RECURSIVEALIASES 20 /* Max depth of recursive alias */
|
|
|
1587 |
|
|
|
1588 |
/*
|
|
|
1589 |
* Job Processing
|
|
|
1590 |
*/
|
|
|
1591 |
|
|
|
1592 |
#if (OS_TYPE != OS_DOS)
|
|
|
1593 |
|
|
|
1594 |
# if (OS_TYPE == OS_NT)
|
|
|
1595 |
typedef DWORD PID; /* Set up PID definition for NT */
|
|
|
1596 |
# endif
|
|
|
1597 |
|
|
|
1598 |
typedef struct JobList {
|
|
|
1599 |
int Number; /* Current number */
|
|
|
1600 |
PID pid; /* Process ID */
|
|
|
1601 |
unsigned short SessionId; /* Session ID */
|
|
|
1602 |
char *Command; /* Program */
|
|
|
1603 |
} JobList;
|
|
|
1604 |
|
|
|
1605 |
extern void *JobTree; /* Job Tree root */
|
|
|
1606 |
extern bool ExitWithJobsActive; /* Exit flag */
|
|
|
1607 |
extern int CurrentJob; /* No current */
|
|
|
1608 |
extern int PreviousJob; /* Previous Job */
|
|
|
1609 |
|
|
|
1610 |
/*
|
|
|
1611 |
* Session Info
|
|
|
1612 |
*/
|
|
|
1613 |
|
|
|
1614 |
extern char *SessionEndQName; /* Queue name */
|
|
|
1615 |
|
|
|
1616 |
/*
|
|
|
1617 |
* Special flag for EMX parameters
|
|
|
1618 |
*/
|
|
|
1619 |
|
|
|
1620 |
extern bool EMXStyleParameters;
|
|
|
1621 |
#endif
|
|
|
1622 |
|
|
|
1623 |
/*
|
|
|
1624 |
* redirection
|
|
|
1625 |
*/
|
|
|
1626 |
|
|
|
1627 |
typedef struct ioword {
|
|
|
1628 |
short io_unit; /* unit affected */
|
|
|
1629 |
short io_flag; /* action (below) */
|
|
|
1630 |
char *io_name; /* file name */
|
|
|
1631 |
} IO_Actions;
|
|
|
1632 |
|
|
|
1633 |
#define IOTYPE 0x000f /* type: bits 0:3 */
|
|
|
1634 |
#define IOREAD 0x0001 /* < */
|
|
|
1635 |
#define IOWRITE 0x0002 /* > */
|
|
|
1636 |
#define IORDWR 0x0003 /* <> */
|
|
|
1637 |
#define IOHERE 0x0004 /* << (here file) */
|
|
|
1638 |
#define IOCAT 0x0005 /* >> */
|
|
|
1639 |
#define IODUP 0x0006 /* >&digit */
|
|
|
1640 |
#define IOCLOSE 0x0007 /* >&- */
|
|
|
1641 |
#define IOEVAL 0x0010 /* Expand in << */
|
|
|
1642 |
#define IOSKIP 0x0020 /* <<- (here file */
|
|
|
1643 |
#define IOCLOBBER 0x0040 /* >| overwrite noclobber */
|
|
|
1644 |
#define IOFUNCTION 0x0080 /* The Here document name is inside a */
|
|
|
1645 |
/* function - don't delete it */
|
|
|
1646 |
|
|
|
1647 |
/*
|
|
|
1648 |
* parsing & execution environment
|
|
|
1649 |
*
|
|
|
1650 |
* For some reason, MSC (and IBM C Set/2), don't like taking addresses
|
|
|
1651 |
* of jmp_buf's, so this macro set removes the errors
|
|
|
1652 |
*/
|
|
|
1653 |
|
|
|
1654 |
#if defined (__TURBOC__) || defined (__WATCOMC__) || defined(_MSC_VER)
|
|
|
1655 |
# define ErrorPoint jmp_buf *
|
|
|
1656 |
# define SetErrorPoint(a) setjmp (*(e.ErrorReturnPoint = &(a)))
|
|
|
1657 |
# define ExitErrorPoint(a) longjmp (*(e.ErrorReturnPoint), a)
|
|
|
1658 |
#else
|
|
|
1659 |
# define ErrorPoint int *
|
|
|
1660 |
# define SetErrorPoint(a) setjmp (e.ErrorReturnPoint = a)
|
|
|
1661 |
# define ExitErrorPoint(a) longjmp (e.ErrorReturnPoint, a)
|
|
|
1662 |
#endif
|
|
|
1663 |
|
|
|
1664 |
#define TERMINATE_POINT_SET 0 /* Error point set */
|
|
|
1665 |
#define TERMINATE_COMMAND 1 /* Exit Error point for command */
|
|
|
1666 |
#define TERMINATE_SHELL 2 /* Exit Error point for shell */
|
|
|
1667 |
|
|
|
1668 |
|
|
|
1669 |
/* The environment structure itself */
|
|
|
1670 |
|
|
|
1671 |
typedef struct env {
|
|
|
1672 |
ErrorPoint ErrorReturnPoint;
|
|
|
1673 |
unsigned long IOMap; /* File Descriptors open in */
|
|
|
1674 |
/* this environment */
|
|
|
1675 |
char *line; /* Current input line */
|
|
|
1676 |
/* Previous environment */
|
|
|
1677 |
struct env *PreviousEnvironment;
|
|
|
1678 |
Word_B *OpenStreams;
|
|
|
1679 |
} ShellFileEnvironment;
|
|
|
1680 |
|
|
|
1681 |
extern ShellFileEnvironment e;
|
|
|
1682 |
|
|
|
1683 |
/*
|
|
|
1684 |
* Switches/flags
|
|
|
1685 |
*/
|
|
|
1686 |
|
|
|
1687 |
#define FL_TEST(x) (flags & (1L << ((x) - 'a')))
|
|
|
1688 |
#define FL_SET(x) flags |= (1L << ((x) - 'a'))
|
|
|
1689 |
#define FL_CLEAR(x) flags &= (~(1L << ((x) - 'a')))
|
|
|
1690 |
|
|
|
1691 |
extern long flags;
|
|
|
1692 |
|
|
|
1693 |
/*
|
|
|
1694 |
* Switch values
|
|
|
1695 |
*/
|
|
|
1696 |
|
|
|
1697 |
#define FLAG_ALL_EXPORT 'a' /* Set all env vars to exported */
|
|
|
1698 |
#define FLAG_EXECUTE_STRING 'c' /* Command from string */
|
|
|
1699 |
#define FLAG_EXIT_ON_ERROR 'e' /* Quit on error */
|
|
|
1700 |
#define FLAG_DISABLE_GLOB 'f' /* Disable file name expansion */
|
|
|
1701 |
#define FLAG_TRACK_ALL 'h' /* Track all aliases */
|
|
|
1702 |
#define FLAG_INTERACTIVE 'i' /* Interactive shell */
|
|
|
1703 |
#define FLAG_ALL_KEYWORDS 'k' /* Look for name=value everywhere */
|
|
|
1704 |
#define FLAG_SEPARATE_GROUP 'm' /* Separate process group */
|
|
|
1705 |
#define FLAG_NO_EXECUTE 'n' /* No execution */
|
|
|
1706 |
#define FLAG_READONLY_SHELL 'r' /* Read only shell */
|
|
|
1707 |
#define FLAG_POSITION 's' /* Read from standard input */
|
|
|
1708 |
#define FLAG_ONE_COMMAND 't' /* exit after exec'ing 1 cmd */
|
|
|
1709 |
#define FLAG_UNSET_ERROR 'u' /* Abort if env var not set */
|
|
|
1710 |
#define FLAG_ECHO_INPUT 'v' /* Echo as read */
|
|
|
1711 |
#define FLAG_WARNING 'w' /* No Warning messages */
|
|
|
1712 |
#define FLAG_PRINT_EXECUTE 'x' /* Trace */
|
|
|
1713 |
#define FLAG_DEBUG_EXECUTE 'd' /* Debug exec */
|
|
|
1714 |
|
|
|
1715 |
/*
|
|
|
1716 |
* Global flags set by set -o which do not have single letter equivalents
|
|
|
1717 |
*/
|
|
|
1718 |
|
|
|
1719 |
extern unsigned int ShellGlobalFlags;
|
|
|
1720 |
|
|
|
1721 |
#define FLAGS_NONE 0x0000
|
|
|
1722 |
#define FLAGS_IGNOREEOF 0x0001 /* Ignore EOF */
|
|
|
1723 |
#define FLAGS_MARKDIRECTORY 0x0002 /* Mark directories with / */
|
|
|
1724 |
#define FLAGS_NOCLOBER 0x0004 /* No delete on existing files */
|
|
|
1725 |
#define FLAGS_FUNCTION 0x0008 /* Special value used in */
|
|
|
1726 |
/* CreateGlobalVariableList. */
|
|
|
1727 |
/* Indicates a function caused */
|
|
|
1728 |
/* CGVL to be called. Not used */
|
|
|
1729 |
/* otherwise */
|
|
|
1730 |
#define FLAGS_REALPIPES 0x0010 /* Use Real pipes under OS/2 */
|
|
|
1731 |
#define FLAGS_ALTERNATION 0x0020 /* Allow alternations */
|
|
|
1732 |
|
|
|
1733 |
#define FLAGS_EDITORS 0x01c0 /* Any of Emacs, Gmacs, or Vi */
|
|
|
1734 |
#define FLAGS_NOCASE 0x0200 /* Ignore case */
|
|
|
1735 |
#define FLAGS_MSDOS_FORMAT 0x0400 /* MSDOS format environment */
|
|
|
1736 |
#define FLAGS_VERIFY_SWITCH 0x0800 /* Change verify status */
|
|
|
1737 |
|
|
|
1738 |
#if (OS_TYPE == OS_DOS)
|
|
|
1739 |
#define FLAGS_BREAK_SWITCH 0x1000 /* Change break status */
|
|
|
1740 |
#define FLAGS_SET_OS2 0x2000 /* Set OS to OS2 */
|
|
|
1741 |
#define FLAGS_SET_NT 0x4000 /* Set OS to NT */
|
|
|
1742 |
#endif
|
|
|
1743 |
|
|
|
1744 |
#define FLAGS_VI 0x0040 /* Vi mode */
|
|
|
1745 |
#define FLAGS_EMACS 0x0080 /* Emacs mode */
|
|
|
1746 |
#define FLAGS_GMACS 0x0100 /* Gmacs mode */
|
|
|
1747 |
|
|
|
1748 |
extern char null[]; /* null value for variable */
|
|
|
1749 |
extern int InterruptTrapPending; /* trap pending */
|
|
|
1750 |
extern int Execute_stack_depth; /* execute function recursion */
|
|
|
1751 |
/* depth */
|
|
|
1752 |
|
|
|
1753 |
/*
|
|
|
1754 |
* Mode values for new GeneralPatternMatch
|
|
|
1755 |
*/
|
|
|
1756 |
|
|
|
1757 |
#define GM_ALL 0 /* Match full string */
|
|
|
1758 |
#define GM_SHORTEST 1 /* Shortest prefix/suffix */
|
|
|
1759 |
#define GM_LONGEST 2 /* Longest prefix/suffix */
|
|
|
1760 |
|
|
|
1761 |
/*
|
|
|
1762 |
* Variable list
|
|
|
1763 |
*/
|
|
|
1764 |
|
|
|
1765 |
typedef struct var {
|
|
|
1766 |
char *name; /* Name */
|
|
|
1767 |
char *value; /* Value */
|
|
|
1768 |
int index; /* Array index */
|
|
|
1769 |
unsigned long nvalue; /* Numeric value */
|
|
|
1770 |
unsigned int base; /* Numeric base */
|
|
|
1771 |
unsigned int width; /* Field width */
|
|
|
1772 |
unsigned int status; /* Type, see below */
|
|
|
1773 |
} VariableList;
|
|
|
1774 |
|
|
|
1775 |
#define STATUS_READONLY 0x0001 /* variable is read-only */
|
|
|
1776 |
#define STATUS_EXPORT 0x0002 /* variable is to be exported */
|
|
|
1777 |
#define STATUS_CANNOT_UNSET 0x0008 /* PATH Value - no unset */
|
|
|
1778 |
#define STATUS_CONVERT_MSDOS 0x0010 /* Convert to MSDOS format */
|
|
|
1779 |
#define STATUS_LEFT_JUSTIFY 0x0020 /* Left Justify */
|
|
|
1780 |
#define STATUS_RIGHT_JUSTIFY 0x0040 /* Right Justify */
|
|
|
1781 |
#define STATUS_ZERO_FILL 0x0080 /* Zero fill */
|
|
|
1782 |
#define STATUS_LOWER_CASE 0x0100 /* Convert to lower case */
|
|
|
1783 |
#define STATUS_UPPER_CASE 0x0200 /* Convert to upper case */
|
|
|
1784 |
#define STATUS_INTEGER 0x0400 /* Contains integer value */
|
|
|
1785 |
#define STATUS_TAGGED 0x0800 /* User tagged */
|
|
|
1786 |
#define STATUS_LOCAL 0x1000 /* Local variable in function */
|
|
|
1787 |
#define STATUS_GLOBAL 0x2000 /* Global variable */
|
|
|
1788 |
#define STATUS_NOEXISTANT 0x8000 /* Does not exist */
|
|
|
1789 |
|
|
|
1790 |
extern void *VariableTree; /* Variable dictionary */
|
|
|
1791 |
extern VariableList *CurrentDirectory; /* Current directory */
|
|
|
1792 |
extern char PS1[]; /* Prompt 1 */
|
|
|
1793 |
extern char PS2[]; /* Prompt 2 */
|
|
|
1794 |
extern char PS3[]; /* Prompt 3 */
|
|
|
1795 |
extern char PS4[]; /* Prompt 4 */
|
|
|
1796 |
extern char IFS[]; /* Interfield separators */
|
|
|
1797 |
extern char *LastUserPrompt; /* Last prompt output */
|
|
|
1798 |
extern char *LastUserPrompt1; /* Alternate prompt output */
|
|
|
1799 |
extern char PathLiteral[]; /* PATH Variable */
|
|
|
1800 |
extern char UserLiteral[]; /* USER Variable */
|
|
|
1801 |
extern char CDPathLiteral[]; /* CDPATH Variable */
|
|
|
1802 |
extern char CurrentDirLiteral[]; /* Current Directory */
|
|
|
1803 |
extern char ParentDirLiteral[]; /* Parent Directory */
|
|
|
1804 |
extern char PathExtsLiteral[]; /* PATHEXTS Variable */
|
|
|
1805 |
extern char HomeVariableName[]; /* Home Variable */
|
|
|
1806 |
extern char ShellVariableName[]; /* Shell Variable */
|
|
|
1807 |
extern char *ParameterCountVariable;/* Parameter Count Variable (#) */
|
|
|
1808 |
extern char *ShellOptionsVariable; /* Shell Options Variable (-) */
|
|
|
1809 |
extern char StatusVariable[]; /* Status variable (?) */
|
|
|
1810 |
extern char *ComspecVariable; /* COMSPEC string */
|
|
|
1811 |
extern char SecondsVariable[]; /* Seconds string */
|
|
|
1812 |
extern char RandomVariable[]; /* Random string */
|
|
|
1813 |
extern char LineCountVariable[]; /* LINENO string */
|
|
|
1814 |
extern char *RootDirectory; /* Root directory */
|
|
|
1815 |
|
|
|
1816 |
|
|
|
1817 |
#if (OS_TYPE != OS_DOS)
|
|
|
1818 |
extern char WinTitleVariable[]; /* WINTITLE string */
|
|
|
1819 |
#endif
|
|
|
1820 |
|
|
|
1821 |
extern char *OldPWDVariable; /* OLDPWD string */
|
|
|
1822 |
extern char *PWDVariable; /* PWD string */
|
|
|
1823 |
extern char *ENVVariable; /* ENV string */
|
|
|
1824 |
extern char BATExtension[]; /* .bat string */
|
|
|
1825 |
extern char SHELLExtension[]; /* .sh string */
|
|
|
1826 |
extern char KSHELLExtension[]; /* .ksh string */
|
|
|
1827 |
extern char EXEExtension[]; /* .exe string */
|
|
|
1828 |
extern char COMExtension[]; /* .com string */
|
|
|
1829 |
extern char HistoryFileVariable[]; /* HISTFILE string */
|
|
|
1830 |
extern char HistorySizeVariable[]; /* HISTSIZE string */
|
|
|
1831 |
extern bool UseConsoleBuffer; /* Flag from dofc to */
|
|
|
1832 |
/* GetConsoleInput */
|
|
|
1833 |
extern char *NotFound; /* Not found message */
|
|
|
1834 |
extern char *BasicErrorMessage; /* Basic error message */
|
|
|
1835 |
extern char *DirectorySeparator; /* Directory separator */
|
|
|
1836 |
extern char *DeviceNameHeader; /* /dev/ */
|
|
|
1837 |
extern char LastWordVariable[]; /* Last word of command variable*/
|
|
|
1838 |
extern char OptArgVariable[]; /* OPTARG */
|
|
|
1839 |
extern char OptIndVariable[]; /* OPTIND */
|
|
|
1840 |
extern char MailCheckVariable[]; /* MAILCHECK */
|
|
|
1841 |
extern char FCEditVariable[]; /* FCEDIT */
|
|
|
1842 |
extern char EditorVariable[]; /* EDITOR */
|
|
|
1843 |
extern char VisualVariable[]; /* VISUAL */
|
|
|
1844 |
extern char Trap_DEBUG[]; /* DEBUG trap variable */
|
|
|
1845 |
extern char Trap_ERR[]; /* ERR trap variable */
|
|
|
1846 |
extern char ConsoleLineBuffer[]; /* Console line buffer */
|
|
|
1847 |
extern char LIT_dos[]; /* dos Literal */
|
|
|
1848 |
extern char *LIT_NewLine; /* NewLine Literal */
|
|
|
1849 |
extern char *LIT_BadID; /* Bad Identifier literal */
|
|
|
1850 |
extern char *LIT_OSname; /* OS name */
|
|
|
1851 |
extern char LIT_export[]; /* export literal */
|
|
|
1852 |
extern char LIT_history[]; /* history literal */
|
|
|
1853 |
extern char LIT_REPLY[]; /* Reply literal */
|
|
|
1854 |
extern char LIT_exit[]; /* Exit literal */
|
|
|
1855 |
extern char LIT_exec[]; /* Exec literal */
|
|
|
1856 |
extern char LIT_done[]; /* done literal */
|
|
|
1857 |
extern char LIT_LINES[]; /* LINES literal */
|
|
|
1858 |
extern char LIT_COLUMNS[]; /* COLUMNS literal */
|
|
|
1859 |
extern char *LIT_2Strings; /* 2 String concat */
|
|
|
1860 |
extern char *LIT_3Strings; /* 3 string concat */
|
|
|
1861 |
extern char *ListVarFormat; /* List variable format */
|
|
|
1862 |
extern char *Outofmemory1; /* Out of memory string */
|
|
|
1863 |
extern char *LIT_Emsg; /* Error message format */
|
|
|
1864 |
extern char *LIT_SyntaxError; /* Syntax error */
|
|
|
1865 |
extern char *LIT_BadArray; /* Bad Array value */
|
|
|
1866 |
extern char *LIT_ArrayRange; /* subscript out of range */
|
|
|
1867 |
extern char *LIT_BNumber; /* [%d] */
|
|
|
1868 |
extern char *LIT_Invalidfunction; /* Invalid function name */
|
|
|
1869 |
extern char *LIT_AllowTTY; /* Allow Psuedo TTYs */
|
|
|
1870 |
extern char *LIT_IsReadonly; /* is readonly */
|
|
|
1871 |
extern char LIT_Test[]; /* Test function */
|
|
|
1872 |
extern char *sOpenReadMode; /* Open file in read mode */
|
|
|
1873 |
extern char *sOpenWriteMode; /* Open file in write mode */
|
|
|
1874 |
extern char *sOpenAppendMode; /* Open file in append mode */
|
|
|
1875 |
extern char *sOpenWriteBinaryMode; /* Open file in append mode */
|
|
|
1876 |
extern int MaximumColumns; /* Max columns */
|
|
|
1877 |
extern int MaximumLines; /* Max Lines */
|
|
|
1878 |
extern int StartCursorPosition; /* Start cursor position */
|
|
|
1879 |
|
|
|
1880 |
#if (OS_TYPE == OS_OS2) || (OS_TYPE == OS_NT)
|
|
|
1881 |
extern void SetWindowName (char *); /* Set the Window Name */
|
|
|
1882 |
#else
|
|
|
1883 |
# define SetWindowName(a)
|
|
|
1884 |
#endif
|
|
|
1885 |
|
|
|
1886 |
/*
|
|
|
1887 |
* Note the the following global structure is used to pass session
|
|
|
1888 |
* information around. If the value of the Environment field is
|
|
|
1889 |
* (char *)NULL, then the parent environment is used. If the value is
|
|
|
1890 |
* (char *)1, then the environment is built from the current exported
|
|
|
1891 |
* environment. Otherwise the value of Environment is used as the
|
|
|
1892 |
* environment
|
|
|
1893 |
*/
|
|
|
1894 |
|
|
|
1895 |
#if (OS_TYPE == OS_OS2)
|
|
|
1896 |
extern STARTDATA *SessionControlBlock; /* Start a session info */
|
|
|
1897 |
extern STARTDATA PM_SessionControlBlock; /* PM session defaults */
|
|
|
1898 |
extern STARTDATA DOS_SessionControlBlock; /* DOS session defaults */
|
|
|
1899 |
#endif
|
|
|
1900 |
|
|
|
1901 |
/*
|
|
|
1902 |
* SubShell Save Structure
|
|
|
1903 |
*/
|
|
|
1904 |
|
|
|
1905 |
typedef struct subshell {
|
|
|
1906 |
int depth; /* Sub_Shell Depth */
|
|
|
1907 |
unsigned int GFlags; /* Global flags */
|
|
|
1908 |
long Eflags; /* single letter flags */
|
|
|
1909 |
void *OldVariableTree; /* Header start */
|
|
|
1910 |
} S_SubShell;
|
|
|
1911 |
|
|
|
1912 |
extern S_SubShell *SubShells; /* Save Vars array */
|
|
|
1913 |
extern int NSubShells; /* Number of entries */
|
|
|
1914 |
extern int MSubShells; /* Max Number of entries */
|
|
|
1915 |
|
|
|
1916 |
|
|
|
1917 |
/*
|
|
|
1918 |
* Extract field from a line
|
|
|
1919 |
*/
|
|
|
1920 |
|
|
|
1921 |
typedef struct Fields {
|
|
|
1922 |
FILE *FP; /* File handler */
|
|
|
1923 |
char *Line; /* Line buffer */
|
|
|
1924 |
int LineLength; /* Line Length */
|
|
|
1925 |
Word_B *Fields; /* ptr to the start of fields */
|
|
|
1926 |
} LineFields;
|
|
|
1927 |
|
|
|
1928 |
extern int ExtractFieldsFromLine (LineFields *);
|
|
|
1929 |
extern Word_B *SplitString (char *, Word_B *);
|
|
|
1930 |
|
|
|
1931 |
/*
|
|
|
1932 |
* Type of processing required by executable program.
|
|
|
1933 |
*/
|
|
|
1934 |
|
|
|
1935 |
typedef struct ExecutableMode {
|
|
|
1936 |
char *Name;
|
|
|
1937 |
unsigned int Flags;
|
|
|
1938 |
unsigned char FieldSep;
|
|
|
1939 |
} ExeMode;
|
|
|
1940 |
|
|
|
1941 |
#define EP_NONE 0x0000 /* Use PSP command line */
|
|
|
1942 |
#define EP_DOSMODE 0x0001 /* Use DOS mode extended line */
|
|
|
1943 |
#define EP_UNIXMODE 0x0002 /* Use UNIX mode extended line */
|
|
|
1944 |
#define EP_NOEXPAND 0x0004 /* Use -f for this command */
|
|
|
1945 |
#define EP_ENVIRON 0x0008 /* Use environ for variable */
|
|
|
1946 |
#define EP_NOSWAP 0x0010 /* Do not swap for this command */
|
|
|
1947 |
#define EP_QUOTEWILD 0x0020 /* Quote wildcards */
|
|
|
1948 |
#define EP_EXPORT 0x0040 /* Use -m for this command */
|
|
|
1949 |
#define EP_CONVERT 0x0080 /* Use conversion */
|
|
|
1950 |
#define EP_NOWORDS 0x0100 /* Do word expansion */
|
|
|
1951 |
#define EP_NOQUOTE 0x0200 /* No quote protection */
|
|
|
1952 |
#define EP_IGNTYPE 0x0400 /* Ignore exe type (DOS only) */
|
|
|
1953 |
#define EP_PSEUDOTTY 0x0800 /* Child shells allow psuedo tty */
|
|
|
1954 |
#define EP_DOSEXT 0x1000 /* DOS extender application */
|
|
|
1955 |
#define EP_CACHED (EP_UNIXMODE|EP_DOSMODE|EP_ENVIRON|\
|
|
|
1956 |
EP_CONVERT|EP_EXPORT|EP_NOSWAP|EP_NOEXPAND|\
|
|
|
1957 |
EP_NOQUOTE|EP_IGNTYPE|EP_PSEUDOTTY|EP_QUOTEWILD|\
|
|
|
1958 |
EP_DOSEXT)
|
|
|
1959 |
|
|
|
1960 |
extern void CheckProgramMode (char *, ExeMode *);
|
|
|
1961 |
extern ExeMode ExecProcessingMode; /* Current executable mode */
|
|
|
1962 |
|
|
|
1963 |
|
|
|
1964 |
/*
|
|
|
1965 |
* storage allocation
|
|
|
1966 |
*/
|
|
|
1967 |
|
|
|
1968 |
extern int MemoryAreaLevel; /* current allocation area */
|
|
|
1969 |
|
|
|
1970 |
/* Functions */
|
|
|
1971 |
|
|
|
1972 |
extern void ShellErrorMessage (char *, ...);
|
|
|
1973 |
extern void PrintErrorMessage (char *, ...);
|
|
|
1974 |
extern int PrintWarningMessage (char *, ...);
|
|
|
1975 |
extern void CompilingError (void);
|
|
|
1976 |
|
|
|
1977 |
extern void ExitTheShell (bool);
|
|
|
1978 |
extern void FinalExitCleanUp (int);
|
|
|
1979 |
|
|
|
1980 |
extern void TerminateCurrentEnvironment (int);
|
|
|
1981 |
extern void CreateNewEnvironment (void);
|
|
|
1982 |
extern void QuitCurrentEnvironment (void);
|
|
|
1983 |
|
|
|
1984 |
#if (OS_TYPE == OS_NT) && defined(_MSC_VER)
|
|
|
1985 |
#define _SIGDECL __cdecl
|
|
|
1986 |
#define _CDECL __cdecl
|
|
|
1987 |
#else
|
|
|
1988 |
#define _SIGDECL
|
|
|
1989 |
#define _CDECL
|
|
|
1990 |
#endif
|
|
|
1991 |
|
|
|
1992 |
extern void _SIGDECL InterruptSignalled (int);
|
|
|
1993 |
extern void _SIGDECL TerminateSignalled (int);
|
|
|
1994 |
extern void RunTrapCommand (int);
|
|
|
1995 |
|
|
|
1996 |
extern void SetShellSwitches (void);
|
|
|
1997 |
extern Word_B *AddWordToBlock (char *, Word_B *);
|
|
|
1998 |
extern char **GetWordList (Word_B *);
|
|
|
1999 |
extern int WordBlockSize (Word_B *);
|
|
|
2000 |
extern char *IntegerToString (int);
|
|
|
2001 |
extern char *GenerateTemporaryFileName (void);
|
|
|
2002 |
extern int (*IsCommandBuiltIn (char *, int *))(int, char **);
|
|
|
2003 |
extern char *BuildNextFullPathName (char *, char *, char *);
|
|
|
2004 |
extern int LookUpSymbol (char *);
|
|
|
2005 |
extern int GetNumericValue (char *);
|
|
|
2006 |
extern bool ConvertNumericValue (char *, long *, int);
|
|
|
2007 |
extern char *BuildFileName (char *);
|
|
|
2008 |
extern int CreateGlobalVariableList (unsigned int);
|
|
|
2009 |
extern void DeleteGlobalVariableList (void);
|
|
|
2010 |
extern Word_B *AddParameter (char *, Word_B *, char *);
|
|
|
2011 |
extern char *BuildOS2String (char **, char);
|
|
|
2012 |
extern char *GenerateFullExecutablePath (char *);
|
|
|
2013 |
|
|
|
2014 |
#if (OS_TYPE != OS_DOS)
|
|
|
2015 |
extern char *GetOSSystemErrorMessage (OSCALL_RET);
|
|
|
2016 |
#endif
|
|
|
2017 |
|
|
|
2018 |
extern int RestoreStandardIO (int, bool);
|
|
|
2019 |
extern void RestoreCurrentDirectory (char *);
|
|
|
2020 |
extern bool GotoDirectory (char *, unsigned int);
|
|
|
2021 |
extern void RestoreEnvironment (int, int);
|
|
|
2022 |
extern bool CheckForRestrictedShell (char *);
|
|
|
2023 |
extern void OutputUserPrompt (char *);
|
|
|
2024 |
extern void DisplayLineWithControl (char *);
|
|
|
2025 |
extern void GetCurrentDirectoryPath (void);
|
|
|
2026 |
extern int OpenForExecution (char *, char **, int *);
|
|
|
2027 |
extern int ProcessOutputMetaCharacters (char **);
|
|
|
2028 |
extern char *ConvertPathToFormat (char *, char, char);
|
|
|
2029 |
extern int CheckForScriptFile (char *, char **, int *);
|
|
|
2030 |
extern void PrintVersionNumber (FILE *);
|
|
|
2031 |
|
|
|
2032 |
/*
|
|
|
2033 |
* Smaller version of fputs & fputc
|
|
|
2034 |
*/
|
|
|
2035 |
|
|
|
2036 |
extern int feputs (const char *);
|
|
|
2037 |
extern int foputs (const char *);
|
|
|
2038 |
extern int feputc (int);
|
|
|
2039 |
|
|
|
2040 |
#if (OS_TYPE == OS_OS2) && (OS_SIZE == OS_32)
|
|
|
2041 |
extern int PrintTimes (void);
|
|
|
2042 |
#endif
|
|
|
2043 |
|
|
|
2044 |
#if (OS_TYPE == OS_NT)
|
|
|
2045 |
extern int PrintTimes (void);
|
|
|
2046 |
#endif
|
|
|
2047 |
|
|
|
2048 |
#ifdef OS_SWAPPING
|
|
|
2049 |
extern void ClearSwapFile (void);
|
|
|
2050 |
#else
|
|
|
2051 |
# define ClearSwapFile()
|
|
|
2052 |
#endif
|
|
|
2053 |
|
|
|
2054 |
extern void ClearExtendedLineFile (void);
|
|
|
2055 |
|
|
|
2056 |
extern bool GeneralPatternMatch (char *, unsigned char *, bool, char **,
|
|
|
2057 |
int);
|
|
|
2058 |
extern bool SuffixPatternMatch (char *, char *, char **, int);
|
|
|
2059 |
extern int CountNumberArguments (char **);
|
|
|
2060 |
extern int _CDECL SortCompare (const void *, const void *);
|
|
|
2061 |
|
|
|
2062 |
extern long EvaluateMathsExpression (char *);
|
|
|
2063 |
extern bool ValidMathsExpression (char *, long *);
|
|
|
2064 |
|
|
|
2065 |
/*
|
|
|
2066 |
* Compiling and executing parse tree
|
|
|
2067 |
*/
|
|
|
2068 |
|
|
|
2069 |
extern C_Op *BuildParseTree (Source *);
|
|
|
2070 |
extern int ExecuteParseTree (C_Op *, int, int, int);
|
|
|
2071 |
extern int ScanNextToken (int);
|
|
|
2072 |
|
|
|
2073 |
#ifdef OS_SWAPPING
|
|
|
2074 |
extern int SA_spawn (char **);
|
|
|
2075 |
#endif
|
|
|
2076 |
|
|
|
2077 |
extern int ExecuteACommand (char **, int);
|
|
|
2078 |
extern int RunACommand (Source *, char **);
|
|
|
2079 |
extern int FindLocationOfExecutable (char *, char *);
|
|
|
2080 |
|
|
|
2081 |
extern int ReMapIOHandler (int);
|
|
|
2082 |
|
|
|
2083 |
extern char **ExpandWordList (char **, int, ExeMode *);
|
|
|
2084 |
extern char *ExpandAString (char *, int);
|
|
|
2085 |
extern char *substitute (char *, int);
|
|
|
2086 |
extern char *ExpandOneStringFirstComponent (char *, int);
|
|
|
2087 |
extern char **BuildCompletionList (char *, size_t, int *, bool);
|
|
|
2088 |
extern size_t GetCommonPartOfFileList (char **);
|
|
|
2089 |
|
|
|
2090 |
extern bool ChangeInitialisationValue (char *, int);
|
|
|
2091 |
extern void Configure_Keys (void);
|
|
|
2092 |
|
|
|
2093 |
/*
|
|
|
2094 |
* Keyboard Input
|
|
|
2095 |
*/
|
|
|
2096 |
|
|
|
2097 |
extern bool RingWarningBell (void);
|
|
|
2098 |
#if (OS_TYPE == OS_DOS)
|
|
|
2099 |
extern unsigned char Poll_Keyboard (void);
|
|
|
2100 |
#else
|
|
|
2101 |
# define Poll_Keyboard()
|
|
|
2102 |
#endif
|
|
|
2103 |
|
|
|
2104 |
extern void PositionCursorInColumnZero (void);
|
|
|
2105 |
extern int GetConsoleInput (void);
|
|
|
2106 |
extern int GetDescriptorType (int);
|
|
|
2107 |
extern bool IsDirectory (const char *);
|
|
|
2108 |
extern int GetEOFKey (void);
|
|
|
2109 |
extern int LookUpKeyBoardFunction (unsigned char, unsigned char);
|
|
|
2110 |
extern int ReadCursorPosition (void);
|
|
|
2111 |
extern void SetCursorPosition (int);
|
|
|
2112 |
extern bool ClearScreen (void);
|
|
|
2113 |
extern void PrintAList (int, char **);
|
|
|
2114 |
extern void GetScreenParameters (void);
|
|
|
2115 |
extern void SetCursorShape (bool);
|
|
|
2116 |
extern void EMACS_Initialisation (void);
|
|
|
2117 |
|
|
|
2118 |
/* read the keyboard */
|
|
|
2119 |
|
|
|
2120 |
extern unsigned char ReadKeyBoard (unsigned char *);
|
|
|
2121 |
|
|
|
2122 |
#define KT_FUNCTION 0 /* Functionkey */
|
|
|
2123 |
#define KT_ALTFUNCTION 0xff /* ALT key pressed */
|
|
|
2124 |
#define KT_RESIZE 0xfe /* Window re-sized */
|
|
|
2125 |
|
|
|
2126 |
#if defined (FLAGS_EMACS) || defined (FLAGS_VI) || defined (FLAGS_GMACS)
|
|
|
2127 |
extern int EditorInput (void);
|
|
|
2128 |
#endif
|
|
|
2129 |
|
|
|
2130 |
#if defined (FLAGS_EMACS) || defined (FLAGS_GMACS)
|
|
|
2131 |
extern int BindKeyStroke (char *, char *, bool);
|
|
|
2132 |
extern unsigned char GetFunctionKeyMap (int, unsigned char *);
|
|
|
2133 |
#endif
|
|
|
2134 |
|
|
|
2135 |
/*
|
|
|
2136 |
* Keyboard functions
|
|
|
2137 |
*/
|
|
|
2138 |
|
|
|
2139 |
#define KF_SCANBACKWARD 0x00 /* Scan backwards in history */
|
|
|
2140 |
#define KF_SCANFOREWARD 0x01 /* Scan forewards in history */
|
|
|
2141 |
#define KF_PREVIOUS 0x02 /* Previous command */
|
|
|
2142 |
#define KF_NEXT 0x03 /* Next command */
|
|
|
2143 |
#define KF_LEFT 0x04 /* Left one character */
|
|
|
2144 |
#define KF_RIGHT 0x05 /* Right one character */
|
|
|
2145 |
#define KF_WORDRIGHT 0x06 /* Right one word */
|
|
|
2146 |
#define KF_WORDLEFT 0x07 /* Left one word */
|
|
|
2147 |
#define KF_START 0x08 /* Move to start of line */
|
|
|
2148 |
#define KF_CLEAR 0x09 /* Clear input line */
|
|
|
2149 |
#define KF_FLUSH 0x0a /* Flush to end of line */
|
|
|
2150 |
#define KF_END 0x0b /* End of line */
|
|
|
2151 |
#define KF_INSERT 0x0c /* Insert mode switch */
|
|
|
2152 |
#define KF_DELETERIGHT 0x0d /* Delete right character */
|
|
|
2153 |
#define KF_DELETELEFT 0x0e /* Delete left character */
|
|
|
2154 |
#define KF_COMPLETE 0x0f /* Complete file name */
|
|
|
2155 |
#define KF_DIRECTORY 0x10 /* Complete directory function */
|
|
|
2156 |
#define KF_CLEARSCREEN 0x11 /* Clear screen */
|
|
|
2157 |
#define KF_JOBS 0x12 /* Print Job tree */
|
|
|
2158 |
#define KF_TRANSPOSE 0x13 /* Transpose characters */
|
|
|
2159 |
#define KF_QUOTE 0x14 /* Quote character */
|
|
|
2160 |
#define KF_END_FKEYS 0x15 /* End of function keys */
|
|
|
2161 |
|
|
|
2162 |
/*
|
|
|
2163 |
* Other init file codes
|
|
|
2164 |
*/
|
|
|
2165 |
|
|
|
2166 |
#define KF_RINGBELL 0x15 /* Ring bell */
|
|
|
2167 |
#define KF_HALFHEIGTH 0x16 /* Half height cursor */
|
|
|
2168 |
#define KF_INSERTMODE 0x17 /* Overstrike or Insert */
|
|
|
2169 |
#define KF_INSERTCURSOR 0x18 /* Enable insert cursor */
|
|
|
2170 |
#define KF_ROOTDRIVE 0x19 /* Root drive */
|
|
|
2171 |
#define KF_EOFKEY 0x1a /* EOF value */
|
|
|
2172 |
|
|
|
2173 |
/*
|
|
|
2174 |
* Variable Name functions
|
|
|
2175 |
*/
|
|
|
2176 |
|
|
|
2177 |
extern void UnSetVariable (char *, int, bool);
|
|
|
2178 |
extern void SetVariableStatus (char *, int);
|
|
|
2179 |
extern void SetVariableArrayStatus (char *, int, int);
|
|
|
2180 |
extern void ClearVariableStatus (char *, int);
|
|
|
2181 |
extern char *GetVariableAsString (char *, bool);
|
|
|
2182 |
extern char *GetVariableArrayAsString (char *, int, bool);
|
|
|
2183 |
extern long GetVariableAsNumeric (char *);
|
|
|
2184 |
extern long GetVariableArrayAsNumeric (char *, int);
|
|
|
2185 |
extern int CountVariableArraySize (char *);
|
|
|
2186 |
extern void SetVariableFromString (char *, char *);
|
|
|
2187 |
extern void SetVariableArrayFromString (char *, int, char *);
|
|
|
2188 |
extern void SetVariableFromNumeric (char *, long);
|
|
|
2189 |
extern void SetVariableArrayFromNumeric (char *, int, long);
|
|
|
2190 |
extern void HandleSECONDandRANDOM (void);
|
|
|
2191 |
extern bool AssignVariableFromString (char *, int *);
|
|
|
2192 |
extern bool GetVariableName (char *, long *, char **, bool *);
|
|
|
2193 |
extern char IsValidVariableName (char *);
|
|
|
2194 |
extern VariableList *LookUpVariable (char *, int, bool);
|
|
|
2195 |
extern int SearchVariable (const void *, const void *);
|
|
|
2196 |
extern void BuildExtensionLists (void);
|
|
|
2197 |
|
|
|
2198 |
/*
|
|
|
2199 |
* Some missing EMX functions
|
|
|
2200 |
*/
|
|
|
2201 |
|
|
|
2202 |
#if defined (__EMX__)
|
|
|
2203 |
extern char *ltoa (long, char *, int);
|
|
|
2204 |
extern int cwait (int *, int, int);
|
|
|
2205 |
#endif
|
|
|
2206 |
|
|
|
2207 |
/*
|
|
|
2208 |
* Memory management
|
|
|
2209 |
*/
|
|
|
2210 |
|
|
|
2211 |
extern char *AllocateMemoryCell (size_t);
|
|
|
2212 |
extern void ReleaseMemoryCell (void *);
|
|
|
2213 |
extern void ReleaseAList (char **);
|
|
|
2214 |
extern void ReleaseMemoryArea (int);
|
|
|
2215 |
extern void SetMemoryAreaNumber (void *, int);
|
|
|
2216 |
extern int GetMemoryAreaNumber (void *);
|
|
|
2217 |
extern void *DuplicateMemoryCell (void *);
|
|
|
2218 |
extern void *GetAllocatedSpace (size_t);
|
|
|
2219 |
extern void *ReAllocateSpace (void *, size_t);
|
|
|
2220 |
extern char *StringSave (char *);
|
|
|
2221 |
extern char *StringCopy (char *);
|
|
|
2222 |
extern size_t GetMemoryCellSize (void *);
|
|
|
2223 |
|
|
|
2224 |
#ifdef DEBUG_MEMORY
|
|
|
2225 |
extern void DumpMemoryCells (int);
|
|
|
2226 |
#define exit(x) DumpMemoryCells (x)
|
|
|
2227 |
#endif
|
|
|
2228 |
|
|
|
2229 |
/*
|
|
|
2230 |
* UNIX File I/O function emulation
|
|
|
2231 |
*/
|
|
|
2232 |
|
|
|
2233 |
extern int S_open (bool, const char *, int);
|
|
|
2234 |
extern int S_close (int, bool);
|
|
|
2235 |
extern void S_fclose (FILE *, bool);
|
|
|
2236 |
extern bool S_stat (const char *, struct stat *);
|
|
|
2237 |
extern int S_dup (int);
|
|
|
2238 |
extern int S_dup2 (int, int);
|
|
|
2239 |
extern bool S_access (const char *, int);
|
|
|
2240 |
extern bool S_chdir (const char *);
|
|
|
2241 |
extern bool S_getcwd (char *, int);
|
|
|
2242 |
extern int S_Remap (int, int);
|
|
|
2243 |
extern int OpenAPipe (void);
|
|
|
2244 |
extern void CloseThePipe (int);
|
|
|
2245 |
extern void CloseAllHandlers (void);
|
|
|
2246 |
|
|
|
2247 |
#if (OS_TYPE == OS_UNIX)
|
|
|
2248 |
# define CheckDOSFileName(a) (a)
|
|
|
2249 |
# define GetCurrentDrive() 0
|
|
|
2250 |
# define SetCurrentDrive(a) -1
|
|
|
2251 |
# define GetDriveLetter(a) 0
|
|
|
2252 |
# define GetDriveNumber(a) 0
|
|
|
2253 |
# define GetRootDiskDrive() 0
|
|
|
2254 |
#else
|
|
|
2255 |
extern const char *CheckDOSFileName (const char *, char *buf);
|
|
|
2256 |
extern unsigned int GetCurrentDrive (void);
|
|
|
2257 |
extern int SetCurrentDrive (unsigned int);
|
|
|
2258 |
extern char GetDriveLetter (unsigned int);
|
|
|
2259 |
extern unsigned int GetDriveNumber (char);
|
|
|
2260 |
extern int GetRootDiskDrive (void);
|
|
|
2261 |
#endif
|
|
|
2262 |
|
|
|
2263 |
extern int CloseFile (FILE *);
|
|
|
2264 |
extern FILE *FOpenFile (const char *, const char *);
|
|
|
2265 |
extern FILE *ReOpenFile (int, const char *);
|
|
|
2266 |
extern void FlushStreams (void);
|
|
|
2267 |
extern void ChangeFileDescriptorStatus (int, bool);
|
|
|
2268 |
|
|
|
2269 |
/*
|
|
|
2270 |
* Shell Functions
|
|
|
2271 |
*/
|
|
|
2272 |
|
|
|
2273 |
#define PF_MODE_NORMAL 0 /* Normal command */
|
|
|
2274 |
#define PF_MODE_ASYNC 1 /* Async command */
|
|
|
2275 |
#define PF_MODE_COPROC 2 /* Co-process command */
|
|
|
2276 |
#define PF_MODE_NO 3 /* No mode */
|
|
|
2277 |
|
|
|
2278 |
extern FunctionList *LookUpFunction (char *, bool);
|
|
|
2279 |
extern bool SaveFunction (C_Op *);
|
|
|
2280 |
extern void DeleteFunction (C_Op *);
|
|
|
2281 |
extern void PrintFunction (C_Op *, int);
|
|
|
2282 |
extern C_Op *CopyFunction (C_Op *);
|
|
|
2283 |
extern int PrintAllFunctions (void);
|
|
|
2284 |
extern void DeleteAllFunctions (void);
|
|
|
2285 |
|
|
|
2286 |
/*
|
|
|
2287 |
* Alias processing
|
|
|
2288 |
*/
|
|
|
2289 |
|
|
|
2290 |
extern AliasList *LookUpAlias (char *, bool);
|
|
|
2291 |
extern void DeleteAlias (char *);
|
|
|
2292 |
extern bool SaveAlias (char *, char *, bool);
|
|
|
2293 |
extern void PrintAlias (char *);
|
|
|
2294 |
extern bool IsValidAliasName (char *, bool);
|
|
|
2295 |
extern void UnTrackAllAliases (void);
|
|
|
2296 |
extern int PrintAllAlias (bool);
|
|
|
2297 |
|
|
|
2298 |
/*
|
|
|
2299 |
* Here document processing
|
|
|
2300 |
*/
|
|
|
2301 |
|
|
|
2302 |
extern void ScrapHereList (void);
|
|
|
2303 |
extern void FreeAllHereDocuments (int);
|
|
|
2304 |
extern void SaveHereDocumentInfo (IO_Actions *);
|
|
|
2305 |
extern int OpenHereFile (char *, bool);
|
|
|
2306 |
|
|
|
2307 |
/*
|
|
|
2308 |
* Job Processing
|
|
|
2309 |
*/
|
|
|
2310 |
|
|
|
2311 |
#if (OS_TYPE != OS_DOS)
|
|
|
2312 |
extern int AddNewJob (PID, unsigned short, char *);
|
|
|
2313 |
extern void DeleteJob (PID);
|
|
|
2314 |
extern void DeleteJobBySession (unsigned short);
|
|
|
2315 |
extern int PrintJobs (bool);
|
|
|
2316 |
extern int NumberOfActiveJobs (void);
|
|
|
2317 |
extern JobList *LookUpJob (int);
|
|
|
2318 |
extern JobList *SearchForJob (char *);
|
|
|
2319 |
extern int PrintProcessTree (pid_t);
|
|
|
2320 |
#endif
|
|
|
2321 |
|
|
|
2322 |
/*
|
|
|
2323 |
* History Processing
|
|
|
2324 |
*/
|
|
|
2325 |
|
|
|
2326 |
extern void AddHistory (bool);
|
|
|
2327 |
extern void LoadHistory (void);
|
|
|
2328 |
extern void DumpHistory (void);
|
|
|
2329 |
extern void ClearHistory (void);
|
|
|
2330 |
extern void PrintHistory (bool, bool, int, int, FILE *);
|
|
|
2331 |
extern int GetLastHistoryEvent (void);
|
|
|
2332 |
extern int GetFirstHistoryEvent (void);
|
|
|
2333 |
extern char *GetHistoryRecord (int);
|
|
|
2334 |
|
|
|
2335 |
#if (OS_TYPE != OS_DOS)
|
|
|
2336 |
extern char *GetLastHistoryString (void);
|
|
|
2337 |
#endif
|
|
|
2338 |
|
|
|
2339 |
extern int SearchHistory (char *);
|
|
|
2340 |
extern void FlushHistoryBuffer (void);
|
|
|
2341 |
extern void DeleteLastHistory (void);
|
|
|
2342 |
extern char CleanUpBuffer (int, char *, int);
|
|
|
2343 |
|
|
|
2344 |
/*
|
|
|
2345 |
* Interrupt handling
|
|
|
2346 |
*/
|
|
|
2347 |
|
|
|
2348 |
#if (OS_TYPE == OS_DOS)
|
|
|
2349 |
# if (OS_SIZE == OS_16)
|
|
|
2350 |
extern void interrupt far SW_Int24 (void); /* Int 24 New address */
|
|
|
2351 |
extern void interrupt far SW_Int23 (void); /* Int 23 New address */
|
|
|
2352 |
extern void interrupt far SW_Int00 (void); /* Int 00 New address */
|
|
|
2353 |
extern bool far SW_I23_InShell; /* In the shell */
|
|
|
2354 |
# elif !defined (__EMX__)
|
|
|
2355 |
extern int __far HardErrorHandler (unsigned int, unsigned int,
|
|
|
2356 |
unsigned int *);
|
|
|
2357 |
# endif
|
|
|
2358 |
#endif
|
|
|
2359 |
|
|
|
2360 |
#if (OS_TYPE == OS_DOS)
|
|
|
2361 |
# if defined (__TURBOC__)
|
|
|
2362 |
# define GetInterruptVector(x) (void (interrupt far *)())getvect ((x))
|
|
|
2363 |
# define SetInterruptVector(x,y) setvect ((x), (y))
|
|
|
2364 |
# else
|
|
|
2365 |
# define GetInterruptVector(x) _dos_getvect ((x))
|
|
|
2366 |
# define SetInterruptVector(x,y) _dos_setvect ((x), (y))
|
|
|
2367 |
# endif
|
|
|
2368 |
#endif
|
|
|
2369 |
|
|
|
2370 |
|
|
|
2371 |
/*
|
|
|
2372 |
* Modified getopt for shell
|
|
|
2373 |
*/
|
|
|
2374 |
|
|
|
2375 |
extern int OptionIndex; /* optind */
|
|
|
2376 |
extern int OptionStart; /* start character */
|
|
|
2377 |
extern char *OptionArgument; /* optarg */
|
|
|
2378 |
|
|
|
2379 |
extern int GetOptions (int, char **, char *, int);
|
|
|
2380 |
extern void ResetGetOptions (void);
|
|
|
2381 |
|
|
|
2382 |
/*
|
|
|
2383 |
* Save structure for getopts command
|
|
|
2384 |
*/
|
|
|
2385 |
|
|
|
2386 |
typedef struct GetoptsIndex {
|
|
|
2387 |
int Index;
|
|
|
2388 |
int SubIndex;
|
|
|
2389 |
} GetoptsIndex;
|
|
|
2390 |
|
|
|
2391 |
extern void ResetGetoptsValues (bool);
|
|
|
2392 |
extern void GetGetoptsValues (GetoptsIndex *);
|
|
|
2393 |
extern void SaveGetoptsValues (int, int);
|
|
|
2394 |
|
|
|
2395 |
/*
|
|
|
2396 |
* General Functions
|
|
|
2397 |
*/
|
|
|
2398 |
|
|
|
2399 |
|
|
|
2400 |
/*
|
|
|
2401 |
* Flag values
|
|
|
2402 |
*/
|
|
|
2403 |
|
|
|
2404 |
#define GETOPT_PLUS 0x01 /* Allow plus sign */
|
|
|
2405 |
#define GETOPT_MESSAGE 0x02 /* Print error message */
|
|
|
2406 |
#define GETOPT_PRINT 0x04 /* doecho special */
|
|
|
2407 |
#define GETOPT_AMISSING 0x08 /* doset special */
|
|
|
2408 |
|
|
|
2409 |
/*
|
|
|
2410 |
* TSEARCH Functions
|
|
|
2411 |
*/
|
|
|
2412 |
|
|
|
2413 |
typedef enum { preorder, postorder, endorder, leaf } VISIT;
|
|
|
2414 |
|
|
|
2415 |
/*
|
|
|
2416 |
* Tree functions
|
|
|
2417 |
*/
|
|
|
2418 |
|
|
|
2419 |
extern void *tsearch (void *, void **, int (*)(const void *, const void *));
|
|
|
2420 |
extern void *tfind (void *, void **, int (*)(const void *, const void *));
|
|
|
2421 |
extern void *tdelete (void *, void **, int (*)(const void *, const void *));
|
|
|
2422 |
extern void twalk (const void *, void (*)(const void *, VISIT, int));
|
|
|
2423 |
|
|
|
2424 |
/*
|
|
|
2425 |
* DEBUG
|
|
|
2426 |
*/
|
|
|
2427 |
|
|
|
2428 |
#ifdef DEBUG_ON
|
|
|
2429 |
# define DPRINT(a,b) db_printf b
|
|
|
2430 |
extern void db_printf (char *, ...);
|
|
|
2431 |
#else
|
|
|
2432 |
# define DPRINT(a,b)
|
|
|
2433 |
#endif
|
|
|
2434 |
|
|
|
2435 |
extern void WhenceTypeDebug (unsigned long type);
|
|
|
2436 |
|
| 255 |
dpurdie |
2437 |
/*
|
|
|
2438 |
** Debug level
|
|
|
2439 |
** Set up debugging flags
|
|
|
2440 |
*/
|
|
|
2441 |
extern int debug_level;
|
|
|
2442 |
#define DEBUG_MULTIPATH 1 /* Path debugging */
|
|
|
2443 |
#define DEBUG_EXEC_ALL 2 /* EXEC debugging (All) */
|
|
|
2444 |
#define DEBUG_CREATE_PROCESS 4 /* Show process creation */
|
|
|
2445 |
#define DEBUG_SHOW_ARGS 8 /* Show Arguments */
|
|
|
2446 |
|
| 227 |
dpurdie |
2447 |
/**/
|
|
|
2448 |
|
|
|
2449 |
|