Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1253 lines
48 KiB

  1. /*++
  2. Copyright (c) 1988-1999 Microsoft Corporation
  3. Module Name:
  4. cmd.h
  5. Abstract:
  6. Global types and definitions
  7. --*/
  8. #define _WIN32_
  9. #include <ctype.h>
  10. /* use real function to avoid side effects */
  11. #undef iswalpha
  12. #undef iswdigit
  13. #undef iswspace
  14. #undef iswxdigit
  15. #include <stdio.h>
  16. #define inpw _inpw /* To keep the compiler happy */
  17. #define outpw _outpw /* To keep the compiler happy */
  18. #include <conio.h>
  19. #include <fcntl.h>
  20. #include <share.h>
  21. #include <search.h>
  22. #include <setjmp.h>
  23. #include <sys\types.h> /* M001 - this file must... */
  24. #include <sys\stat.h> /* ...precede this one */
  25. #include <io.h>
  26. #include <time.h>
  27. #include <locale.h>
  28. #include <memory.h>
  29. #include <process.h>
  30. #include <string.h>
  31. #include <stdlib.h>
  32. #include <stdarg.h>
  33. #include <limits.h>
  34. #include <errno.h>
  35. #include <nt.h>
  36. #include <ntrtl.h>
  37. #include <nturtl.h>
  38. #include <windows.h>
  39. #include <winbasep.h>
  40. #include <winnlsp.h>
  41. #include <shellapi.h>
  42. #include <shlobj.h>
  43. #include <shlapip.h>
  44. #include <winconp.h>
  45. #include <tchar.h>
  46. #include <aclapi.h>
  47. #include <aclapip.h>
  48. #include <winsafer.h>
  49. #include <delayimp.h>
  50. #ifndef UNICODE
  51. #ifndef WIN95_CMD
  52. #error Unicode must be defined!!!!
  53. #endif // WIN95_CMD
  54. #endif
  55. #define BYTE_ORDER_MARK 0xFEFF
  56. //
  57. // No dynamic stack checking in CBATCH.C and CPARSE.C
  58. //
  59. #undef USE_STACKAVAIL
  60. //
  61. // CMDEXTVERSION is a number that is incremented whenever the Command
  62. // Extensions enabled by CMD /X undergo a significant revision. Allow
  63. // batch scripts to use new features conditionally via the following
  64. // syntax:
  65. //
  66. // IF CMDEXTVERSION 1 statement
  67. //
  68. #define CMDEXTVERSION 2
  69. /* M000 - These are definitions for specific file classification and
  70. * permission variables used in redirection
  71. */
  72. #define OP_APPEN (O_RDWR|O_APPEND|O_CREAT) /* Append redir file */
  73. #define OP_TRUNC (O_WRONLY|O_CREAT|O_TRUNC) /* Truncate redir file */
  74. #define OP_PERM (S_IREAD|S_IWRITE|S_IEXEC) /* R/W/X permission 0700 */
  75. //
  76. // These 3 file handles are valid only for the Lowio routines exported
  77. // by the C Runtimes IO.H
  78. //
  79. #define STDIN 0
  80. #define STDOUT 1
  81. #define STDERR 2
  82. #include "cmdmsg.h"
  83. /* Definitions used by or passed to functions in CMD.C
  84. *
  85. * M000 - Args to Dispatch (ultimately Set/ResetRedir)
  86. * M037 - Added REPROCESS for rewalking redirection list.
  87. *
  88. */
  89. #define RIO_OTHER 0 /* Means call by misc. function */
  90. #define RIO_MAIN 0 /* Means call by main() */
  91. #define RIO_PIPE 1 /* Means call by ePipe() */
  92. #define RIO_BATLOOP 2 /* Means call by BatLoop() */
  93. #define RIO_REPROCESS 3 /* Means reprocessing redir by AddRedir */
  94. #define APP_FLG 1 /* Flag bit indicates append when redir stdout */
  95. /* M000 ends */
  96. /* M016 begin */
  97. #define NOFLAGS 0 /* No flag bits set */
  98. #define CHECKDRIVES 1 /* Check the drives of the args to this command */
  99. #define NOSWITCHES 2 /* No switches are allowed for this command */
  100. #define EXTENSCMD 4 /* Only allowed if fEnableExtensions is TRUE */
  101. /* M016 ends */
  102. //
  103. // Exit code used to abort processing (see ExitAbort and cmd.c)
  104. //
  105. // Exit due to eof on redirected stdin
  106. //
  107. #define EXIT_EOF 2
  108. #define EOF (-1)
  109. /* The following defines are used by CPARSE.C and CLEX.C */
  110. #define READSTRING 1 /* Flags which tell the parser */
  111. #define READSTDIN 2 /* where and how to get its input */
  112. #define READFILE 3
  113. #define FIRSTIME 3
  114. #define NOTFIRSTIME 0x8000
  115. #define ANDSTR TEXT("&&") /* And operator string */
  116. #define ANDOP TEXT('&') /* And operator character */
  117. #define CSOP TEXT('&') /* Command separator character */
  118. #define CSSTR TEXT("&") /* Command separator string */
  119. #define EQ TEXT('=') /* Equals character */
  120. #define EQSTR TEXT("==") /* Equals string */
  121. #define EQI TEXT('~') /* Equals character (case insensitive) */
  122. #define EQISTR TEXT("=~") /* Equals string (case insensitive) */
  123. #define INOP TEXT('<') /* Input redirection character */
  124. #define INSTR TEXT("<") /* M008 - Input redirection string */
  125. #define IAPSTR TEXT("<<") /* M022 - Will be used in future (<<foo) */
  126. #define LPOP TEXT('(') /* Left parenthesis character */
  127. #define LEFTPSTR TEXT("(") /* Left parenthesis string */
  128. #define ORSTR TEXT("||") /* Or operator string */
  129. #define OUTOP TEXT('>') /* Output redirection character */
  130. #define OUTSTR TEXT(">") /* M008 - Output redirection string */
  131. #define APPSTR TEXT(">>") /* M008 - Output w/append redir string */
  132. #define PIPOP TEXT('|') /* Pipe operator character */
  133. #define PIPSTR TEXT("|") /* Pipe operator string */
  134. #define RPOP TEXT(')') /* Right parenthesis character */
  135. #define RPSTR TEXT(")") /* Right parenthesis string */
  136. #define ESCHAR TEXT('^') /* M003/M013/M020 - Esc, next byte literal */
  137. #define SPCSTR TEXT(" ") /* M022 - New string used in CMD.C */
  138. #define SILSTR TEXT("@") /* M024 - Suppress echo string */
  139. #define SILOP TEXT('@') /* M024 - Silent operator */
  140. #define EOS 0 /* End of input stream */
  141. #define DISPERROR 1 /* Dispatch error code */
  142. #define DOPOS 22 /* Position in fornode->cmdline of do string */
  143. #define FORLINLEN 30 /* Length of for node command line */
  144. #define GT_NORMAL 0 /* Flag to GeToken(), get a normal token */
  145. #define GT_ARGSTR 1 /* Flag to GeToken(), get an argstring */
  146. #define GT_QUOTE 2 /* M007 - Term not used, reserves value */
  147. #define GT_EQOK 4 /* Flag to GeToken(), get equals not delimiter */
  148. #define GT_LPOP 8 /* M002 - Ok to parse '(' & '@' as oper's */
  149. #define GT_RPOP 16 /* M002 - Ok to parse ')' as operator */
  150. #define GT_REM 32 /* M007 - Parsing REM arg token */
  151. #define LEXERROR -1 /* Lexer error code */
  152. #define LX_UNGET 0 /* M020 - Lexer flag, Unget last token */
  153. #define LX_ARG 1 /* Lexer flag(), get an argstring */
  154. #define LX_QUOTE 2 /* Lexer flag(), getting a quoted string */
  155. #define LX_EQOK 4 /* Lexer flag(), equalsign not delimiter */
  156. #define LX_LPOP 8 /* M007 - Term not used, reserves value */
  157. #define LX_RPOP 16 /* M007 - Term not used, reserves value */
  158. #define LX_REM 32 /* M007 - Lexing REM arg token */
  159. #define LX_DBLOK 64 /* - ok for lexer to return second half
  160. of a double byte code */
  161. #define LX_DELOP 0x0100 /* Returned by TExtCheck, found delimeter/operator*/
  162. #define MAINERROR 1 /* Main error code */
  163. #define PC_NOTS 0 /* Flag to ParseCond(), "NOT"s are allowed */
  164. #define PC_NONOTS 1 /* Flag to ParseCond(), "NOT"s are not allowed */
  165. #define PIO_DO 1 /* Flag to ParseInOut(), do read token first */
  166. #define PIO_DONT 0 /* Flag to ParseInOut(), don't read token first */
  167. #define PARSERROR 1 /* Parser error code */
  168. #define TEXTOKEN 0x4000 /* Text token found flag */
  169. #define LBUFLEN 8192
  170. #define MAXTOKLEN 8192
  171. #define TMPBUFLEN 8192
  172. /* Definitions used by or passed to functions in CMEM.C */
  173. #define FS_FREEALL 0 /* Tells FreeStack to free entire stack */
  174. /* Definitions used by or passed to functions in CEXT.C */
  175. #define T_OFF 0 /* Execute with no trace active */
  176. #define T_ON 1 /* Execute with trace active */
  177. #define AI_SYNC 0 /* Async indicator - Exec synchronous */
  178. #define AI_DSCD 4 /* Async indicator - Exec async/discard @@ */
  179. #define AI_KEEP 2 /* Async indicator - Exec async/save retcd */
  180. #define SFE_NOTFND 0 /* Ret'd by SearchForExecutable, not found */
  181. #define SFE_ISEXECOM 1 /* Ret'd by SearchForExecutable, exe/com found */
  182. #define SFE_ISBAT 2 /* Ret'd by SearchForExecutable, bat found */
  183. #define SFE_FAIL 3 /* Ret'd by SearchForExecutable, out of memory */
  184. #define SFE_BADPATH 4 /* Ret'd by SearchForExecutable, specified
  185. path is bad */
  186. #define SFE_ISDIR 5 /* Ret'd by SearchForExecutable, directory */
  187. /* Definitions used by or passed to the functions in CBATCH.C */
  188. #define BT_CHN 0 /* M011 - Arg to BatProc() Chain this batch job */
  189. #define BT_CALL 1 /* M011 - Arg to BatProc() Nest this batch job */
  190. #define E_OFF 0 /* Echo mode off */
  191. #define E_ON 1 /* Echo mode on */
  192. #define FORERROR 1 /* For processor error */
  193. #define MS_BAT 0 /* Flag to MakeSubstitutions(), doing batch job subs*/
  194. #define MS_FOR 1 /* Flag to MakeSubstitutions(), doing FOR loop subs */
  195. #define DSP_SCN 0 /* M024 - DisplayStatement called for scrn output */
  196. #define DSP_PIP 1 /* M024 - DisplayStatement called for pipe output */
  197. #define DSP_SIL 0 /* M024 - DisplayStatement uses "silent" mode */
  198. #define DSP_VER 1 /* M024 - DisplayStatement uses "verbose" mode */
  199. #define QUIETCH TEXT('Q') /* M024 - "QUIET" switch for batch files */
  200. /* Definitions used by or passed to functions in CDIR.C */
  201. #define DAMASK 0x1F /* All of these are used to isolated the */
  202. #define HRSHIFT 11 /* different parts of a file's last */
  203. #define HRMASK 0x1F /* modification date and time. This info */
  204. #define LOYR 1980 /* is packed into 2 words in the following */
  205. #define MOSHIFT 5 /* format: */
  206. #define MOMASK 0x0F /* */
  207. #define MNSHIFT 5 /* Date word: bits 0-4 date, bits 5-8 */
  208. #define MNMASK 0x3F /* month, bits 9-15 year-1980. */
  209. #define SCMASK 0x1F /* */
  210. #define YRSHIFT 9 /* Time: bits 0-4 seconds/2, bits 5-10 */
  211. #define YRMASK 0x7F /* minutes, bits 11-15 month. */
  212. #define FFIRST_FAIL 2 /* Flag to show ffirst failed */
  213. /* Definitions used by or passed to the functions in CPWORK.C and CPPARSE.C */
  214. /* M010 - This entire block added to facilitate rewritten copy files
  215. */
  216. /* different states for the parser */
  217. #define SEEN_NO_FILES 1
  218. #define JUST_SEEN_SOURCE_FILE 2
  219. #define SEEN_PLUS_EXPECTING_SOURCE_FILE 3
  220. #define SEEN_COMMA_EXPECTING_SECOND 4
  221. #define SEEN_TWO_COMMAS 5
  222. #define SEEN_DEST 6
  223. /* types of copy */
  224. #define COPY 1
  225. #define TOUCH 2
  226. #define CONCAT 3
  227. #define COMBINE 4
  228. /* Definitions used by or passed to the functions in CFILE.C */
  229. /* Values for the flags field of the copy information structure. */
  230. #define CI_BINARY 0x0001 /* File to be copied in binary mode */
  231. #define CI_ASCII 0x0002 /* File to be copied in ascii mode */
  232. #define CI_NOTSET 0x0004 /* Above mode given to file by default */
  233. #define CI_NAMEWILD 0x0008 /* Filename contains wildcards */
  234. #define CI_ALLOWDECRYPT 0x0010 /* Allow destination of copy to be decrypted */
  235. #define CI_DONE 0x0020 /* No more files match this filespec */
  236. #define CI_FIRSTTIME 0x0040 /* First time file searched for */
  237. #define CI_ISDEVICE 0x0080 /* File is a device */
  238. #define CI_FIRSTSRC 0x0100 /* First source in source list */
  239. #define CI_SHORTNAME 0x0200 /* if copying to FAT from NTFS, use short name */
  240. #define CI_RESTARTABLE 0x0400 /* if the copy is restartable */
  241. #define CI_PROMPTUSER 0x2000 /* prompt if overwriting destination */
  242. //
  243. // These flags are filled in when we find out what the file type is
  244. //
  245. #define CI_UNICODE 0x4000 /* Buffer contains unicode chars */
  246. #define CI_NOT_UNICODE 0x8000 /* Buffer contains non-unicode chars */
  247. /* Flags passed to BuildFSpec() */
  248. #define BF_SRC 1 /* Called from OpenSrc() */
  249. #define BF_DEST 2 /* Called from OpenDest() */
  250. #define BF_DRVPATH 4 /* Add drive and path */
  251. /* Flags passed to CopyError() */
  252. #define CE_PCOUNT 1 /* Print the copied files count */
  253. #define CE_NOPCOUNT 0 /* Don't print the copied files count */
  254. /* Flags passed to CSearchError() */
  255. #define CSE_OPENSRC 0 /* Called from OpenSrc() */
  256. #define CSE_OPENDEST 1 /* Called from OpenDest() */
  257. /* Definitions/structures used by or passed to the functions in CENV.C */
  258. struct envdata {
  259. TCHAR *handle ; /* Environment pointer */
  260. unsigned cursize ; /* # of bytes used in the segment */
  261. unsigned maxsize ; /* # of bytes in the entire segment */
  262. } ;
  263. #define AEV_ADDPROG 0 /* Flag to AddEnvVar, add a program name */
  264. #define AEV_NORMAL 1 /* Flag to AddEnvVar, add a normal variable */
  265. /* Definitions used by or passed to the functions in CCLOCK.C */
  266. #define PD_DIR 0 /* Flag to PrintDate, use Dir command date format */
  267. #define PD_DATE 1 /* Flag to PrintDate, use Date command date format */
  268. #define PD_PTDATE 2 /* Flag to PrintDate, prompt & use Date command format */
  269. #define PD_DIR2000 3 // Dir date format, four digit years
  270. #define PT_DIR 0 /* Flag to PrintTime, use Dir command time format */
  271. #define PT_TIME 1 /* Flag to PrintTime, use Time command time format */
  272. #define EDATE 0 /* Flag for eDate */
  273. #define ETIME -1 /* Flag for eTime */
  274. /* Definitions used by or passed to the functions in COTHER.C */
  275. #define GSVM_GET 2 /* Flag to GetSetVerMode(), just get current mode */
  276. #define GSVM_OFF 0 /* Flag to GetSetVerMode(), turn off */
  277. #define GSVM_ON 1 /* Flag to GetSetVerMode(), turn on */
  278. /* Definitions used by CSTART.C @WM2 */
  279. #define FOREGRND 0 /* Start session in foreground */
  280. #define BACKGRND 1 /* Start session in background */
  281. #define ST_UNDEF -1 /* Parameter isn't defined yet */
  282. #define INDEPENDANT 0 /* New session will be independant */
  283. #define ST_KSWITCH 1 /* Start parameter /K */
  284. #define ST_CSWITCH 2 /* Start parameter /C */
  285. #define ST_NSWITCH 3 /* Start parameter /N */
  286. #define ST_FSSWITCH PROG_FULLSCREEN /* Start session in full screen mode */
  287. #define ST_WINSWITCH PROG_WINDOWABLEVIO /* Start session in winthorn mode */
  288. #define ST_PMSWITCH PROG_PM /* Start session in presentation manager mode */
  289. #define ST_DOSFSSWITCH PROG_VDM /* Start session in a VDM */
  290. #define ST_DOSWINSWITCH PROG_WINDOWEDVDM /* Start session in windowed VDM */
  291. #define NONWINSTARTLEN 30 /* Length of Data Structure when not using WIN */
  292. /* Definitions used by or passed to the functions in CTOOLS.C */
  293. #define GD_DEFAULT 0 /* Flag to GetDir(), get dir for default drive */
  294. #define LTA_NOFLAGS 0 /* Flag to LoopThroughArgs() */
  295. #define LTA_EXPAND 1 /* Flag to LoopThroughArgs(), expand wildcards */
  296. #define LTA_NULLOK 2 /* Flag to LoopThroughArgs(), null args ok */
  297. #define LTA_NOMATCH 4 /* Flag to LoopThroughArgs(), no match on wildcard ok */
  298. #define LTA_CONT 8 /* Flag to LoopThroughArgs(), continue process @@4 */
  299. #define OOC_OFF 0 /* OnOffCheck() retcode, found "OFF" */
  300. #define OOC_ON 1 /* OnOffCheck() retcode, found "ON" */
  301. #define OOC_EMPTY 2 /* OnOffCheck() retcode, found empty string */
  302. #define OOC_OTHER 3 /* OnOffCheck() retcode, found some other string */
  303. #define OOC_NOERROR 0 /* Flag to OnOffCheck(), OCC_OTHER is not an error */
  304. #define OOC_ERROR 1 /* Flag to OnOffCheck(), OCC_OTHER is an error */
  305. #define TS_NOFLAGS 0 /* Flag to TokStr(), */
  306. #define TS_WSPACE 1 /* Flag to TokStr(), whitespace aren't delimiters */
  307. #define TS_SDTOKENS 2 /* Flag to TokStr(), special delimiters are tokens */
  308. #define TS_NWSPACE 4 /* Flag to TokStr(), spec delims are not white sp @@*/
  309. #define RAW 4 /* Bit pattern for setting KBD RAW mode (M032) */
  310. #define COOKED 8 /* Bit pattern for setting KBD COOKED mode (M032) */
  311. /* Defines used to define and manage file handle from the C runtime */
  312. typedef int CRTHANDLE;
  313. #define BADHANDLE (CRTHANDLE)-1 // bad handle from different opens
  314. #define CRTTONT(fh) (HANDLE)_get_osfhandle(fh)
  315. /*** Definitions and structures used by COP.C */
  316. /* Added structure to hold temporary pipe file information. It is used
  317. * to communicate with SetRedir() when redirecting input during execution
  318. * of piped commands and by SigHand() and BreakPipes() when necessary
  319. * to terminate a piped operation.
  320. * M027 - Modified structure for real pipes.
  321. */
  322. struct pipedata {
  323. CRTHANDLE rh; /* Pipe read handle */
  324. CRTHANDLE wh; /* Pipe write handle */
  325. CRTHANDLE shr; /* Handles where the normal... */
  326. CRTHANDLE shw; /* ...STDIN/OUT handles are saved */
  327. HANDLE lPID ; /* Pipe lh side PID */
  328. HANDLE rPID ; /* Pipe rh side PID */
  329. unsigned lstart ; /* Start Information of lh side D64*/
  330. unsigned rstart ; /* Start Information of rh side D64*/
  331. struct pipedata *prvpds ; /* Ptr to next pipedata struct */
  332. struct pipedata *nxtpds ; /* Ptr to next pipedata struct */
  333. } ;
  334. #define FH_INHERIT 0x0080 /* M027 Bits used by the api... */
  335. #define FH_WRTTHRU 0x4000 /* ...DOSQ/SETFHANDSTATE */
  336. #define FH_FAILERR 0x2000
  337. /* Miscellaneous defines used in the code for enhanced readability. */
  338. #define MAX_DRIVES (TEXT('Z') - TEXT('A') + 1)
  339. #define BSLASH TEXT('\\')
  340. #define SWITCHAR TEXT('/')
  341. #define COLON TEXT(':')
  342. #define COMMA TEXT(',')
  343. #define DEFENVSIZE 0xA0 /* Default environment size */
  344. #define DOLLAR TEXT('$')
  345. #define WINLOW 0x00000004 // Lowest acceptable version of Win32
  346. #define WINHIGH 0xFFFF0004 // Highest acceptable version of Win32
  347. #define DOT TEXT('.')
  348. #define FAILURE 1 /* Command/function failed. */
  349. #define MINSTACKNEED 2200 /* MIN stack needed to parse commands @WM1 */
  350. #define NLN TEXT('\n') /* Newline character */
  351. #define CR TEXT('\r') /* M004 - Added def for carriage return */
  352. #define NULLC TEXT('\0') /* Null character */
  353. #define ONEQSTR TEXT("=")
  354. #define PERCENT TEXT('%')
  355. #define PLUS TEXT('+')
  356. #define MINUS TEXT('-') /* M038 - Added def for CTRY code */
  357. #define QMARK TEXT('?')
  358. #define QUOTE TEXT('"')
  359. #define STAR TEXT('*')
  360. #define CTRLZ 0x1A /* M004 - Def for ^Z for lexer */
  361. #define CTRLC 0x03 /* M035 - Def for ^C for ePause */
  362. #define SPACE TEXT(' ') /* M014 - Def for space character */
  363. #define SUCCESS 0 /* Command/function succeeded */
  364. #define MAXTOWRITE 160 /* maximum number of chars to write - for ctrl-s */
  365. //
  366. // type for return code on dir and related functions, can be migrated
  367. // into rest of cmd later.
  368. typedef ULONG STATUS;
  369. #define CHECKSTATUS( p1 ) {STATUS rc; if ((rc = p1) != SUCCESS) return( rc ); }
  370. // #define CHECKSTATUS( rc ) if (rc != SUCCESS) { return( rc ); }
  371. /* CWAIT ACTION CODES */
  372. #define CW_A_SNGL 0x00 /* Wait only on indicated process */
  373. #define CW_A_ALL 0x01 /* Wait on all grandchildren too */
  374. /* CWAIT OPTION CODES */
  375. #define CW_W_YES 0x00 /* Wait if no child ends (or no children) */
  376. #define CW_W_NO 0x01 /* Don't wait if no child ends */
  377. /* CWAIT PID VALUE */
  378. #define CW_PID_ANY 0x00 /* PID val for wait on any child */
  379. /* DOSKILLPROCESS flag */
  380. #define SS_SUBTREE 0x00
  381. #define f_RET_DIR -1 /* from f_how_many() when directory */
  382. /* This structure is used by the FOR loop processor to save parse tree node
  383. * strings in.
  384. *
  385. * M022 - This structure was extended to enable it to store the 10 possible
  386. * redirection strings and the cmdline and argptr strings of a command node.
  387. * This added eight pointers to the structure.
  388. */
  389. struct savtype {
  390. TCHAR *saveptrs[12] ;
  391. } ;
  392. //
  393. // Global handles for DLL's
  394. //
  395. extern HMODULE hKernel32;
  396. //
  397. // Types used in dir command
  398. //
  399. #define MAXSORTDESC 6
  400. typedef struct PATDSC {
  401. PTCHAR pszPattern;
  402. PTCHAR pszDir;
  403. BOOLEAN fIsFat;
  404. struct PATDSC * ppatdscNext;
  405. } PATDSC, *PPATDSC;
  406. //
  407. // Dir command parameters in conan form (post parsing)
  408. //
  409. //
  410. // A sort descriptor is used to define a type of sorting on the
  411. // files in a directory. Currently these are
  412. // Name, Extension, Date/Time, Size and group directories first
  413. // Each can be sort either by Assending or descending order.
  414. //
  415. typedef struct { // srtdsc
  416. USHORT Order;
  417. USHORT Type;
  418. int(__cdecl * fctCmp) (const void * elem1, const void * elem2);
  419. } SORTDESC, *PSORTDESC;
  420. typedef struct {
  421. //
  422. // Switches for enumeration
  423. //
  424. ULONG rgfSwitches;
  425. //
  426. // Attributes that are of interest for this enumeration
  427. //
  428. ULONG rgfAttribs;
  429. //
  430. // Attributes (subject to rgfAttribs mask) that must be on or off
  431. // for files that match this enumeration
  432. //
  433. ULONG rgfAttribsOnOff;
  434. //
  435. // Number of sort descriptions
  436. //
  437. ULONG csrtdsc;
  438. //
  439. // Individual sort descriptors
  440. //
  441. SORTDESC rgsrtdsc[MAXSORTDESC];
  442. //
  443. // Count of patterns that are later converted to FS's
  444. //
  445. ULONG cpatdsc;
  446. //
  447. // Pointer to first pattern
  448. //
  449. PATDSC patdscFirst;
  450. //
  451. // Form of timestamp to display
  452. //
  453. ULONG dwTimeType;
  454. //
  455. // Count of files and directories seen and total bytes
  456. //
  457. ULONG FileCount;
  458. ULONG DirectoryCount;
  459. LARGE_INTEGER TotalBytes;
  460. } DRP;
  461. typedef DRP *PDRP;
  462. //
  463. // The following number is also in makefile.inc as a parameter to MC.EXE
  464. // to prevent it from generating a message that is bigger than we can handle.
  465. //
  466. #define MAXCBMSGBUFFER LBUFLEN
  467. TCHAR MsgBuf[MAXCBMSGBUFFER] ;
  468. //
  469. // The buffers holding WIN32_FIND_DATA for dir use a USHORT size field
  470. // for each WIN32_FIND_DATA entry and place the each data entry one after the
  471. // other, plus DWORD align each entry. This is to avoid allocating MAX_PATH
  472. // for each file name or maintaining a seperate filename buffer.
  473. // The size of the entry is maintained so that we can quickly run over
  474. // all of the data entries generating a seperate array of pointers to each
  475. // entry that is used in sorting.
  476. //
  477. // obAlternative is the offset from the cFileName field to the alternative
  478. // file name field if any. A 0 indication no alternative file name.
  479. //
  480. typedef struct {
  481. USHORT cb;
  482. USHORT obAlternate;
  483. WIN32_FIND_DATA data;
  484. } FF, *PFF, **PPFF;
  485. typedef struct FS {
  486. //
  487. // Link to next directory to be enumerated
  488. //
  489. struct FS * pfsNext;
  490. //
  491. // Text of directory to be enumerated
  492. //
  493. PTCHAR pszDir;
  494. //
  495. // Count of patterns in directory
  496. //
  497. ULONG cpatdsc;
  498. //
  499. // Linked list of patterns within directory to be enumerated
  500. //
  501. PPATDSC ppatdsc;
  502. //
  503. // Various state flags
  504. //
  505. BOOLEAN fIsFat;
  506. BOOLEAN fDelPrompted;
  507. //
  508. // Total count of entries stored in pff
  509. //
  510. ULONG cff;
  511. //
  512. // Pointer to packed FF's
  513. //
  514. PFF pff;
  515. //
  516. // Array of pointers into packed FF's. Used for sorting.
  517. //
  518. PPFF prgpff;
  519. //
  520. // Number of files/directories in FF's
  521. //
  522. ULONG FileCount;
  523. ULONG DirectoryCount;
  524. //
  525. // Total disk usage by all files satisfying this enumeration
  526. //
  527. LARGE_INTEGER cbFileTotal;
  528. } FS, *PFS;
  529. //
  530. // used in dir to control display of screen.
  531. //
  532. typedef struct { // scr
  533. HANDLE hndScreen; // Screen handle (NULL if not a device)
  534. ULONG crow; // row position on current screen
  535. ULONG ccol; // column position in current row
  536. ULONG cbMaxBuffer;// size of allocated buffer
  537. PTCHAR pbBuffer; // bytes in buffer
  538. ULONG ccolTab; // column position for each tab
  539. ULONG ccolTabMax; // max. cols to allow tabing into.
  540. ULONG crowMax; // no. of rows on screen
  541. ULONG ccolMax; // no. of cols on screen
  542. ULONG crowPause; // no. of rows to pause on.
  543. ULONG cb; // no. of characters in row - different than
  544. // ccol, since Kanjii characters are half-width
  545. } SCREEN, *PSCREEN;
  546. /* Parse tree node structure declarations. The basic structure type is called
  547. * node and is used for all operators. All of the rest are based on it. There
  548. * are several types of structures because some commands need special fields.
  549. * Functions that manipulate a parse tree node will either not care what type
  550. * of node it is getting or will know in advance what to expect. All of the
  551. * nodes are the same size to make their manipulation easier.
  552. *
  553. * M022 - The structures for node and cmdnode have been changed so that
  554. * their redirection information is now a single pointer to a linked list
  555. * of 'relem' structures rather than two simple byte pointers for STDIN and
  556. * STDOUT and a single append flag.
  557. */
  558. struct node { /* Used for operators */
  559. int type ; /* Type of operator */
  560. struct savtype save ; /* FOR processor saves orig strings here */
  561. struct relem *rio ; /* M022 - Linked redirection list */
  562. struct node *lhs ; /* Ptr to left hand side of the operator */
  563. struct node *rhs ; /* Ptr to right hand side of the operator */
  564. INT_PTR extra[ 4 ] ; /* M022 - Padding now needed */
  565. } ;
  566. struct cmdnode { /* Used for all commands except ones below */
  567. int type ; /* Type of command */
  568. struct savtype save ; /* FOR processor saves orig strings here */
  569. struct relem *rio ; /* M022 - Linked redirection list */
  570. PTCHAR cmdline ; /* Ptr to command line */
  571. PTCHAR argptr ; /* Ptr to type of command */
  572. int flag ; /* M022 - Valid for cond and goto types */
  573. int cmdarg ; /* M022 - Argument to STRTYP routine */
  574. } ;
  575. #define CMDNODE_FLAG_GOTO 0x0001
  576. #define CMDNODE_FLAG_IF_IGNCASE 0x0002
  577. #define CMDNODE_ARG_IF_EQU 1
  578. #define CMDNODE_ARG_IF_NEQ 2
  579. #define CMDNODE_ARG_IF_LSS 3
  580. #define CMDNODE_ARG_IF_LEQ 4
  581. #define CMDNODE_ARG_IF_GTR 5
  582. #define CMDNODE_ARG_IF_GEQ 6
  583. struct fornode { /* Used for FOR commands */
  584. int type ; /* FOR command type */
  585. struct savtype save ; /* FOR processor saves orig strings here */
  586. struct relem *rio ; /* M022 - Linked redirection list */
  587. PTCHAR cmdline ; /* Ptr to command line */
  588. PTCHAR arglist ; /* Ptr to the FOR argument list */
  589. struct node *body ; /* Ptr to the body of the FOR */
  590. unsigned forvar ; /* FOR variable - MUST BE UNSIGNED */
  591. int flag ; /* Flag */
  592. union {
  593. PTCHAR recurseDir ;
  594. PTCHAR parseOpts ;
  595. } ;
  596. } ;
  597. #define FOR_LOOP 0x0001
  598. #define FOR_MATCH_DIRONLY 0x0002
  599. #define FOR_MATCH_RECURSE 0x0004
  600. #define FOR_MATCH_PARSE 0x0008
  601. struct ifnode { /* Used for IF commands */
  602. int type ; /* IF command type */
  603. struct savtype save ; /* FOR processor saves orig strings here */
  604. struct relem *rio ; /* M022 - Linked redirection list */
  605. PTCHAR cmdline ; /* Ptr to command line */
  606. struct cmdnode *cond ; /* Ptr to the IF condition */
  607. struct node *ifbody ; /* Ptr to the body of the IF */
  608. PTCHAR elseline ; /* Ptr to ELSE command line */
  609. struct node *elsebody ; /* Ptr to the body of the ELSE */
  610. } ;
  611. /* Operator and Command type values. These definitions are the values
  612. * assigned to the type fields in the parse tree nodes and can be used as
  613. * indexes into the Operator and command jump table. Because of this last
  614. * point these values ***>MUST<*** be kept in sync with the jump table.
  615. */
  616. #define CMDTYP 0
  617. #define CMDLOW 0 /* Lowest type number for an internal command */
  618. #define DIRTYP 0 /* DIR */
  619. #define DELTYP 1 /* DEL, ERASE */
  620. #define TYTYP 3 /* TYPE */
  621. #define CPYTYP 4 /* COPY */
  622. #define CDTYP 5 /* CD, CHDIR */
  623. #define RENTYP 7 /* REN, RENAME */
  624. #define ECHTYP 9 /* ECHO */
  625. #define SETTYP 10 /* SET */
  626. #define PAUTYP 11 /* PAUSE */
  627. #define DATTYP 12 /* DATE */
  628. #define TIMTYP 13 /* TIME */
  629. #define PROTYP 14 /* PROMPT */
  630. #define MDTYP 16 /* MD, MKDIR */
  631. #define RDTYP 18 /* RD, RMDIR */
  632. #define PATTYP 19 /* PATH */
  633. #define GOTYP 20 /* GOTO */
  634. #define SHFTYP 21 /* SHIFT */
  635. #define CLSTYP 22 /* CLS */
  636. #define CALTYP 23 /* M007 - New CALL command */
  637. #define VRITYP 24 /* VERIFY */
  638. #define VERTYP 25 /* VER */
  639. #define VOLTYP 26 /* VOL */
  640. #define EXITYP 27 /* EXIT */
  641. #define SLTYP 28 /* M006 - Definition for SETLOCAL command */
  642. #define ELTYP 29 /* M006 - Definition for ENDLOCAL command */
  643. #define CHPTYP 30 /* CHCP @@*/
  644. #define STRTTYP 31 /* START @@*/
  645. #define APPDTYP 32 /* APPEND @@ */
  646. #define KEYSTYP 33 /* KEYS @@5 */
  647. #define MOVETYP 34 /* MOVE @@5 */
  648. #define PUSHTYP 35 /* PushD */
  649. #define POPTYP 36 /* PopD */
  650. #define BRKTYP 37 /* M012 - Added new command type @@*/
  651. #define ASSOCTYP 38 /* M012 - Added new command type @@*/
  652. #define FTYPETYP 39 /* M012 - Added new command type @@*/
  653. #define COLORTYP 40 /* COLOR */
  654. #define CMDHIGH 40 /* Cmds higher than this are unique parse types @@*/
  655. #define FORTYP 41 /* FOR */
  656. #define IFTYP 42 /* IF */
  657. #define REMTYP 43 /* REM */
  658. #define CMDMAX 43 /* Values higher are not commands */
  659. #define LFTYP 44 /* Command separator (NL) */
  660. #define CSTYP 45 /* Command separator (&) */
  661. #define ORTYP 46 /* Or operator */
  662. #define ANDTYP 47 /* And operator */
  663. #define PIPTYP 48 /* Pipe operator */
  664. #define PARTYP 49 /* Parenthesis */
  665. #define CMDVERTYP 50 /* CMDEXTVERSION (used by if) */
  666. #define ERRTYP 51 /* ERRORLEVEL (used by if) */
  667. #define DEFTYP 52 /* DEFINED (used by if) */
  668. #define EXSTYP 53 /* EXIST (used by if) */
  669. #define NOTTYP 54 /* NOT (used by if) */
  670. #define STRTYP 55 /* String comparison (used by if) */
  671. #define CMPTYP 56 /* General comparison (used by if) */
  672. #define SILTYP 57 /* M024 - "SILENT" unary operator */
  673. #define HELPTYP 58 /* Help for FOR, IF and REM */
  674. #define TBLMAX 58 /* M012 - Highest numbered table entry */
  675. /* The following macros are for my debugging statements. DEBUG expands to
  676. * a call to my debug statement printer if the DBGugging variable is
  677. * defined. Otherwise, it expands to NULL.
  678. */
  679. #if DBG
  680. #define CMD_DEBUG_ENABLE 1
  681. #define DEBUG(a) Deb a
  682. /* The following are definitions of the debugging group and level bits
  683. * for the code in cbatch.c
  684. */
  685. #define BPGRP 0x0100 /* Batch processor group */
  686. #define BPLVL 0x0001 /* Batch processor level */
  687. #define FOLVL 0x0002 /* FOR processor level */
  688. #define IFLVL 0x0004 /* IF processor level */
  689. #define OTLVL 0x0008 /* Other batch commands level */
  690. /* The following are definitions of the debugging group and level bits
  691. * for the code in cclock.c
  692. */
  693. #define CLGRP 0x4000 /* Other commands group */
  694. #define DALVL 0x0001 /* Date command level */
  695. #define TILVL 0x0002 /* Time command level */
  696. /* The following are definitions of the DEBUGging group and level bits
  697. * for the code in cfile.c, cpparse.c, cpwork.c
  698. */
  699. #define FCGRP 0x0020 // File commands group
  700. #define COLVL 0x0001 // Copy level
  701. #define DELVL 0x0002 // Delete level
  702. #define RELVL 0x0004 // Rename level
  703. /* The following are definitions of the debugging group and level bits
  704. * for the code in cinfo.c and display.c
  705. */
  706. #define ICGRP 0x0040 /* Informational commands group */
  707. #define DILVL 0x0001 /* Directory level */
  708. #define TYLVL 0x0002 /* Type level */
  709. #define VOLVL 0x0008 /* Volume level */
  710. #define DISLVL 0x0040 /* Directory level */
  711. /* The following are definitions of the debugging group and level bits
  712. * for the code in cinit.c
  713. */
  714. #define INGRP 0x0002 /* Command Initialization group */
  715. #define ACLVL 0x0001 /* Argument checking level */
  716. #define EILVL 0x0002 /* Environment initialization level */
  717. #define RSLVL 0x0004 /* Rest of initialization level */
  718. /* The following are definitions of the debugging group and level bits
  719. * for the code in clex.c, cparse.c
  720. */
  721. #define PAGRP 0x0004 /* Parser */
  722. #define PALVL 0x0001 /* Parsing */
  723. #define LXLVL 0x0002 /* Lexing */
  724. #define LFLVL 0x0004 /* Input routine */
  725. #define DPLVL 0x0008 /* Dump parse tree */
  726. #define BYLVL 0x0010 /* Byte input routines */
  727. //
  728. // The following are definitions of the debugging group and level bits
  729. // for the code in cmd.c
  730. //
  731. #define MNGRP 0x0001 // Main command loop code group
  732. #define MNLVL 0x0001 // Main function level
  733. #define DFLVL 0x0002 // Dispatch function level
  734. #define RIOLVL 0x0004 // Redirection function level
  735. /* The following are definitions of the debugging group and level bits
  736. * for the code in cmem.c
  737. */
  738. #define MMGRP 0x1000 /* Memory Manager */
  739. #define MALVL 0x0001 /* Memory allocators */
  740. #define LMLVL 0x0002 /* List managers */
  741. #define SMLVL 0x0004 /* Segment manipulators */
  742. /* The following are definitions of the debugging group and level bits
  743. * for the code in cop.c
  744. */
  745. #define OPGRP 0x0008 /* Operators group */
  746. #define PILVL 0x0001 /* Pipe level */
  747. #define PNLVL 0x0002 /* Paren operator level */
  748. /* The following are definitions of the debugging group and level bits
  749. * for the code in cother.c
  750. */
  751. #define OCGRP 0x0400 /* Other commands group */
  752. #define BRLVL 0x0001 /* Break command level */
  753. #define CLLVL 0x0002 /* Cls command level */
  754. #define CTLVL 0x0004 /* Ctty command level */
  755. #define EXLVL 0x0008 /* Exit command level */
  756. #define VELVL 0x0010 /* Verify command level */
  757. /* The following are definitions of the debugging group and level bits
  758. * for the code in cpath.c
  759. */
  760. #define PCGRP 0x0010 /* Path commands group */
  761. #define MDLVL 0x0001 /* Mkdir level */
  762. #define CDLVL 0x0002 /* Chdir level */
  763. #define RDLVL 0x0004 /* Rmdir level */
  764. /* The following are definitions of the debugging group and level bits
  765. * for the code in csig.c
  766. */
  767. #define SHGRP 0x0800 /* Signal handler group */
  768. #define MSLVL 0x0001 /* Main Signal handler level */
  769. #define ISLVL 0x0002 /* Init Signal handler level */
  770. /* The following are definitions of the debugging group and level bits
  771. * for the code in ctools1.c, ctools2.c, ctools3.c and ffirst.c
  772. */
  773. #define CTGRP 0x2000 /* Common tools group */
  774. #define CTMLVL 0x0400 /* Common tools misc. level */
  775. #define BFLVL 0x0800 /* BuildFSpec() level */
  776. #define SFLVL 0x1000 /* ScanFSpec() level */
  777. #define SSLVL 0x2000 /* SetAndSaveDir() level */
  778. #define TSLVL 0x4000 /* TokStr() level */
  779. #define FPLVL 0x8000 /* FullPath level */
  780. #else
  781. #define CMD_DEBUG_ENABLE 0
  782. #define DEBUG(a)
  783. #endif
  784. /* File attributes */
  785. #define FILE_ATTRIBUTE_READONLY 0x00000001
  786. #define FILE_ATTRIBUTE_HIDDEN 0x00000002
  787. #define FILE_ATTRIBUTE_SYSTEM 0x00000004
  788. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
  789. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
  790. #define FILE_ATTRIBUTE_NORMAL 0x00000080
  791. #define IsDirectory(a) ((a) & FILE_ATTRIBUTE_DIRECTORY)
  792. #define IsReparse(a) ((a) & FILE_ATTRIBUTE_REPARSE_POINT)
  793. //#define A_AEV 0x37
  794. #define A_ALL (FILE_ATTRIBUTE_READONLY | \
  795. FILE_ATTRIBUTE_HIDDEN | \
  796. FILE_ATTRIBUTE_SYSTEM | \
  797. FILE_ATTRIBUTE_DIRECTORY | \
  798. FILE_ATTRIBUTE_ARCHIVE )
  799. //#define A_AEDV 0x27 /* all attributes except dir & vol */
  800. #define A_AEDV (A_ALL & ~FILE_ATTRIBUTE_DIRECTORY)
  801. //#define A_AEDVH 0x25 /* all except dir/vol/hidden (M040) */
  802. #define A_AEDVH (FILE_ATTRIBUTE_READONLY | \
  803. FILE_ATTRIBUTE_SYSTEM | \
  804. FILE_ATTRIBUTE_ARCHIVE )
  805. //#define A_AEVH 0x35 /* all except vol/hidden */
  806. #define A_AEVH (A_ALL & ~FILE_ATTRIBUTE_HIDDEN)
  807. /* Batdata is the structure which contains all of the information needed to
  808. * start/continue executing a batch job. The fields are:
  809. * filespec - full file specification of the batch file
  810. * dircpy - ptr to copy of current drive and directory (used by the
  811. * setlocal/endlocal commands.
  812. * filepos - the current position in the file
  813. * stackmin - M037 - the number of elements on the data stack comprising
  814. * only the batch data structure itself. Used when chaining to free
  815. * memory prior to reconstructing the data structure.
  816. * stacksize - the number of elements on the data stack before the
  817. * execution of the batch job begins. This number is past to
  818. * FreeStack() via Parser() to make sure that only that data which
  819. * is used to execute batch file statements is freed.
  820. * hRestrictedToken - Handle to the restricted token with which the batch file
  821. * should be run.
  822. * envcpy - ptr to structure containing info on environment copy
  823. * orgargs - pointer to original argument string
  824. * args - tokenized string containing the the unused batch job arguments
  825. * aptrs - pointers into args to individual arguments, NULL if no arg for
  826. * that number
  827. * alens - the lengths of individual args, 0 if no arg
  828. * backptr - the structures are stacked using this pointer. Through it,
  829. * nestable batch jobs are achieved.
  830. */
  831. #define CMD_MAX_SAVED_ENV 32
  832. struct batsaveddata {
  833. TCHAR *dircpy ;
  834. struct envdata * envcpy;
  835. BOOLEAN fEnableExtensions;
  836. BOOLEAN fDelayedExpansion;
  837. } ;
  838. struct batdata {
  839. TCHAR *filespec ;
  840. long filepos ;
  841. int stackmin ;
  842. int stacksize ;
  843. int SavedEnvironmentCount;
  844. HANDLE hRestrictedToken;
  845. TCHAR *orgargs ;
  846. TCHAR *args ;
  847. TCHAR *aptrs[10] ;
  848. int alens[10] ;
  849. TCHAR *orgaptr0 ;
  850. struct batsaveddata *saveddata[CMD_MAX_SAVED_ENV] ;
  851. struct batdata *backptr ;
  852. } ;
  853. //
  854. // The following variables are used to detect the current batch state
  855. //
  856. //
  857. // Set for /K on command line
  858. //
  859. extern BOOL SingleBatchInvocation; // fSingleBatchLine
  860. //
  861. // Set of /c switch on command line set.
  862. //
  863. extern BOOL SingleCommandInvocation; // fSingleCmdLine
  864. //
  865. // Data for start and executing a batch file. Used in calls
  866. //
  867. extern struct batdata *CurrentBatchFile; // CurBat
  868. //
  869. // Set during the execution of a GOTO command. All sequential dispatch
  870. // routines muse examine this and return success when set in order
  871. // to let the top-level batch file execution continue at the next
  872. // point
  873. //
  874. extern BOOLEAN GotoFlag;
  875. /* M022 - This structure has been changed. It is still used in a linked
  876. * list, but now stores no actual redirection information. Instead the
  877. * node pointer is used to access this data which is in another linked
  878. * list of relem structures whose head element is pointed to by n->rio in
  879. * the node. The riodata list is reverse linked and its tail element is
  880. * still pointed to by CurRIO (global).
  881. */
  882. struct rio {
  883. int type ; /* Type of redir'ing process */
  884. CRTHANDLE stdio ; /* Highest handle for this node */
  885. struct node *rnod ; /* Associated parse node ptr */
  886. struct rio *back ; /* Pointer to prior list element */
  887. } ;
  888. // relem is used in a linked list, the head element of which is pointed to by
  889. // n->rio in a 'node' or 'cmdnode'. It contains the following parse information;
  890. // the handle to be redirected, a pointer to the filename (or "&n" for handle
  891. // substitution), the handle where the original is saved (by duping it), the
  892. // operator, ('>' or '<'), specifying the redirection type, a flag to indicate
  893. // whether this is to be appended and a pointer to the next list element.
  894. struct relem {
  895. CRTHANDLE rdhndl ; // handle to be redirected
  896. TCHAR *fname ; // filename (or &n)
  897. CRTHANDLE svhndl ; // where orig handle is saved
  898. int flag ; // Append flag
  899. TCHAR rdop ; // Type ('>' | '<')
  900. struct relem *nxt ; // Next structure
  901. };
  902. /* Used to hold information on Copy sources and destinations. */
  903. struct cpyinfo {
  904. TCHAR *fspec ; /* Source/destination filespec */
  905. TCHAR *curfspec ; /* Current filespec being used */
  906. TCHAR *pathend ; /* Ptr to end of pathname in fspec */
  907. TCHAR *fnptr ; /* Ptr to filename in fspec */
  908. TCHAR *extptr ; /* Ptr to file extension in fspec */
  909. PWIN32_FIND_DATA buf ; /* Buffer used for findfirst/next */
  910. int flags ; /* Wildcards, device, etc */
  911. struct cpyinfo *next ; /* Next ptr, used with sources only */
  912. } ;
  913. /* Following is true if user specifically enable the potentially incompatible */
  914. /* extensions to CMD.EXE. */
  915. extern BOOLEAN fEnableExtensions;
  916. extern BOOLEAN fDelayedExpansion;
  917. //
  918. // Suppress/allow delay load errors
  919. //
  920. extern BOOLEAN ReportDelayLoadErrors;
  921. /* Message Retriever definitions */
  922. #define NOARGS 0
  923. #define ONEARG 1
  924. #define TWOARGS 2
  925. #define THREEARGS 3
  926. /* length of double byte character set (DBCS) buffer */
  927. #define DBCS_BUF_LEN 10
  928. /* DBCS_SPACE is the code for the second byte of a dbcs space character
  929. * DBCS_SPACE is not a space unless it immediatly follows a bdcs lead
  930. * character */
  931. /* I don't know what value the double byte space is, so I made a guess.
  932. * I know this guess is wrong, but, you've gotta suffer if you're going
  933. * to sing the blues!
  934. * (Correct the value for BDCS_SPACE and everything should work fine)
  935. */
  936. #define DBCS_SPACE 64 /* @@ */
  937. #define LEAD_DBCS_SPACE 129 /* @@ */
  938. /*
  939. * is_dbcsleadchar(c) returns TRUE if c is a valid first character of a double
  940. * character code, FALSE otherwise.
  941. *
  942. */
  943. extern BOOLEAN DbcsLeadCharTable[ ];
  944. //
  945. // AnyDbcsLeadChars can be tested to determine if there are any TRUE values
  946. // in DbcsLeadCharTable i.e. do we have to do any look-ups.
  947. //
  948. extern BOOLEAN AnyDbcsLeadChars;
  949. #define is_dbcsleadchar( c ) DbcsLeadCharTable[((UCHAR)(c))]
  950. //
  951. // Line terminator
  952. //
  953. extern TCHAR CrLf[] ;
  954. //
  955. // The following macros are copies of the C Runtime versions that test
  956. // for NULL string pointer arguments and return NULL instead of generating
  957. // an access violation dereferencing a null pointer.
  958. //
  959. #define mystrlen( str ) \
  960. ( (str) ? _tcslen( str ) : ( 0 ))
  961. #define mystrcpy( s1, s2 ) \
  962. ( ((s1) && (s2)) ? _tcscpy( s1, s2 ) : ( NULL ))
  963. #define mystrcat( s1, s2 ) \
  964. ( ((s1) && (s2)) ? _tcscat( s1, s2 ) : ( NULL ))
  965. extern TCHAR DbcsFlags[];
  966. #define W_ON 1 /* Whinthorn.DLL exists */
  967. #define W_OFF 0 /* Whinthorn.DLL exists */
  968. #define FIFO 0 /* FIFO Queue */
  969. #define FULLSCRN 0 /* Full Screen Mode */
  970. #define VIOWIN 1 /* VIO Windowable Mode */
  971. #define DETACHED 2 /* Detached Mode */
  972. #define NONEPGM 0 /* Program is not started */
  973. #define EXECPGM 1 /* Program is started by DosExecPgm */
  974. #define STARTSESSION 2 /* Program is started by DosStartSession */
  975. #define WAIT 0 /* WAIT for DosReadQueue */
  976. #define NOWAIT 1 /* NOWAIT for DosReadQueue */
  977. #define READ_TERMQ 0 /* Read TermQ */
  978. #define ALL_STOP 0 /* Terminate All Sessions */
  979. #define SPEC_STOP 1 /* Terminate Specified Session */
  980. // to handle OS/2 vs DOS behavior (e.g. errorlevel) in a script files
  981. #define NO_TYPE 0
  982. #define BAT_TYPE 1
  983. #define CMD_TYPE 2
  984. #include "cmdproto.h"
  985. #include "console.h"
  986. #include "dir.h"
  987. #include <vdmapi.h>
  988. #include <conapi.h>