Leaked source code of windows server 2003
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.

1283 lines
50 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. #define AEV_ADDPROG 0 /* Flag to AddEnvVar, add a program name */
  259. #define AEV_NORMAL 1 /* Flag to AddEnvVar, add a normal variable */
  260. /* Definitions used by or passed to the functions in CCLOCK.C */
  261. #define PD_DIR 0 /* Flag to PrintDate, use Dir command date format */
  262. #define PD_DATE 1 /* Flag to PrintDate, use Date command date format */
  263. #define PD_PTDATE 2 /* Flag to PrintDate, prompt & use Date command format */
  264. #define PD_DIR2000 3 // Dir date format, four digit years
  265. #define PT_DIR 0 /* Flag to PrintTime, use Dir command time format */
  266. #define PT_TIME 1 /* Flag to PrintTime, use Time command time format */
  267. #define EDATE 0 /* Flag for eDate */
  268. #define ETIME -1 /* Flag for eTime */
  269. /* Definitions used by or passed to the functions in COTHER.C */
  270. #define GSVM_GET 2 /* Flag to GetSetVerMode(), just get current mode */
  271. #define GSVM_OFF 0 /* Flag to GetSetVerMode(), turn off */
  272. #define GSVM_ON 1 /* Flag to GetSetVerMode(), turn on */
  273. /* Definitions used by CSTART.C @WM2 */
  274. #define FOREGRND 0 /* Start session in foreground */
  275. #define BACKGRND 1 /* Start session in background */
  276. #define ST_UNDEF -1 /* Parameter isn't defined yet */
  277. #define INDEPENDANT 0 /* New session will be independant */
  278. #define ST_KSWITCH 1 /* Start parameter /K */
  279. #define ST_CSWITCH 2 /* Start parameter /C */
  280. #define ST_NSWITCH 3 /* Start parameter /N */
  281. #define ST_FSSWITCH PROG_FULLSCREEN /* Start session in full screen mode */
  282. #define ST_WINSWITCH PROG_WINDOWABLEVIO /* Start session in winthorn mode */
  283. #define ST_PMSWITCH PROG_PM /* Start session in presentation manager mode */
  284. #define ST_DOSFSSWITCH PROG_VDM /* Start session in a VDM */
  285. #define ST_DOSWINSWITCH PROG_WINDOWEDVDM /* Start session in windowed VDM */
  286. #define NONWINSTARTLEN 30 /* Length of Data Structure when not using WIN */
  287. /* Definitions used by or passed to the functions in CTOOLS.C */
  288. #define GD_DEFAULT 0 /* Flag to GetDir(), get dir for default drive */
  289. #define LTA_NOFLAGS 0 /* Flag to LoopThroughArgs() */
  290. #define LTA_EXPAND 1 /* Flag to LoopThroughArgs(), expand wildcards */
  291. #define LTA_NULLOK 2 /* Flag to LoopThroughArgs(), null args ok */
  292. #define LTA_NOMATCH 4 /* Flag to LoopThroughArgs(), no match on wildcard ok */
  293. #define LTA_CONT 8 /* Flag to LoopThroughArgs(), continue process @@4 */
  294. #define OOC_OFF 0 /* OnOffCheck() retcode, found "OFF" */
  295. #define OOC_ON 1 /* OnOffCheck() retcode, found "ON" */
  296. #define OOC_EMPTY 2 /* OnOffCheck() retcode, found empty string */
  297. #define OOC_OTHER 3 /* OnOffCheck() retcode, found some other string */
  298. #define OOC_NOERROR 0 /* Flag to OnOffCheck(), OCC_OTHER is not an error */
  299. #define OOC_ERROR 1 /* Flag to OnOffCheck(), OCC_OTHER is an error */
  300. #define TS_NOFLAGS 0 /* Flag to TokStr(), */
  301. #define TS_WSPACE 1 /* Flag to TokStr(), whitespace aren't delimiters */
  302. #define TS_SDTOKENS 2 /* Flag to TokStr(), special delimiters are tokens */
  303. #define TS_NWSPACE 4 /* Flag to TokStr(), spec delims are not white sp @@*/
  304. #define RAW 4 /* Bit pattern for setting KBD RAW mode (M032) */
  305. #define COOKED 8 /* Bit pattern for setting KBD COOKED mode (M032) */
  306. /* Defines used to define and manage file handle from the C runtime */
  307. typedef int CRTHANDLE;
  308. #define BADHANDLE (CRTHANDLE)-1 // bad handle from different opens
  309. #define CRTTONT(fh) (HANDLE)_get_osfhandle(fh)
  310. /*** Definitions and structures used by COP.C */
  311. /* Added structure to hold temporary pipe file information. It is used
  312. * to communicate with SetRedir() when redirecting input during execution
  313. * of piped commands and by SigHand() and BreakPipes() when necessary
  314. * to terminate a piped operation.
  315. * M027 - Modified structure for real pipes.
  316. */
  317. struct pipedata {
  318. CRTHANDLE rh; /* Pipe read handle */
  319. CRTHANDLE wh; /* Pipe write handle */
  320. CRTHANDLE shr; /* Handles where the normal... */
  321. CRTHANDLE shw; /* ...STDIN/OUT handles are saved */
  322. HANDLE lPID ; /* Pipe lh side PID */
  323. HANDLE rPID ; /* Pipe rh side PID */
  324. unsigned lstart ; /* Start Information of lh side D64*/
  325. unsigned rstart ; /* Start Information of rh side D64*/
  326. struct pipedata *prvpds ; /* Ptr to next pipedata struct */
  327. struct pipedata *nxtpds ; /* Ptr to next pipedata struct */
  328. } ;
  329. #define FH_INHERIT 0x0080 /* M027 Bits used by the api... */
  330. #define FH_WRTTHRU 0x4000 /* ...DOSQ/SETFHANDSTATE */
  331. #define FH_FAILERR 0x2000
  332. /* Miscellaneous defines used in the code for enhanced readability. */
  333. #define MAX_DRIVES (TEXT('Z') - TEXT('A') + 1)
  334. #define BSLASH TEXT('\\')
  335. #define SWITCHAR TEXT('/')
  336. #define COLON TEXT(':')
  337. #define COMMA TEXT(',')
  338. #define DEFENVSIZE 0xA0 /* Default environment size */
  339. #define DOLLAR TEXT('$')
  340. #define WINLOW 0x00000004 // Lowest acceptable version of Win32
  341. #define WINHIGH 0xFFFF0004 // Highest acceptable version of Win32
  342. #define DOT TEXT('.')
  343. #define FAILURE 1 /* Command/function failed. */
  344. #define MINSTACKNEED 2200 /* MIN stack needed to parse commands @WM1 */
  345. #define NLN TEXT('\n') /* Newline character */
  346. #define CR TEXT('\r') /* M004 - Added def for carriage return */
  347. #define NULLC TEXT('\0') /* Null character */
  348. #define ONEQSTR TEXT("=")
  349. #define PERCENT TEXT('%')
  350. #define PLUS TEXT('+')
  351. #define MINUS TEXT('-') /* M038 - Added def for CTRY code */
  352. #define QMARK TEXT('?')
  353. #define QUOTE TEXT('"')
  354. #define STAR TEXT('*')
  355. #define CTRLZ 0x1A /* M004 - Def for ^Z for lexer */
  356. #define CTRLC 0x03 /* M035 - Def for ^C for ePause */
  357. #define SPACE TEXT(' ') /* M014 - Def for space character */
  358. #define SUCCESS 0 /* Command/function succeeded */
  359. #define MAXTOWRITE 160 /* maximum number of chars to write - for ctrl-s */
  360. //
  361. // type for return code on dir and related functions, can be migrated
  362. // into rest of cmd later.
  363. typedef ULONG STATUS;
  364. #define CHECKSTATUS( p1 ) {STATUS rc; if ((rc = p1) != SUCCESS) return( rc ); }
  365. // #define CHECKSTATUS( rc ) if (rc != SUCCESS) { return( rc ); }
  366. /* CWAIT ACTION CODES */
  367. #define CW_A_SNGL 0x00 /* Wait only on indicated process */
  368. #define CW_A_ALL 0x01 /* Wait on all grandchildren too */
  369. /* CWAIT OPTION CODES */
  370. #define CW_W_YES 0x00 /* Wait if no child ends (or no children) */
  371. #define CW_W_NO 0x01 /* Don't wait if no child ends */
  372. /* CWAIT PID VALUE */
  373. #define CW_PID_ANY 0x00 /* PID val for wait on any child */
  374. /* DOSKILLPROCESS flag */
  375. #define SS_SUBTREE 0x00
  376. #define f_RET_DIR -1 /* from f_how_many() when directory */
  377. /* This structure is used by the FOR loop processor to save parse tree node
  378. * strings in.
  379. *
  380. * M022 - This structure was extended to enable it to store the 10 possible
  381. * redirection strings and the cmdline and argptr strings of a command node.
  382. * This added eight pointers to the structure.
  383. */
  384. struct savtype {
  385. TCHAR *saveptrs[12] ;
  386. } ;
  387. //
  388. // Global handles for DLL's
  389. //
  390. extern HMODULE hKernel32;
  391. //
  392. // Types used in dir command
  393. //
  394. #define MAXSORTDESC 6
  395. typedef struct PATDSC {
  396. PTCHAR pszPattern;
  397. PTCHAR pszDir;
  398. BOOLEAN fIsFat;
  399. struct PATDSC * ppatdscNext;
  400. } PATDSC, *PPATDSC;
  401. //
  402. // Dir command parameters in conan form (post parsing)
  403. //
  404. //
  405. // A sort descriptor is used to define a type of sorting on the
  406. // files in a directory. Currently these are
  407. // Name, Extension, Date/Time, Size and group directories first
  408. // Each can be sort either by Assending or descending order.
  409. //
  410. typedef struct { // srtdsc
  411. USHORT Order;
  412. USHORT Type;
  413. int(__cdecl * fctCmp) (const void * elem1, const void * elem2);
  414. } SORTDESC, *PSORTDESC;
  415. typedef struct {
  416. //
  417. // Switches for enumeration
  418. //
  419. ULONG rgfSwitches;
  420. //
  421. // Attributes that are of interest for this enumeration
  422. //
  423. ULONG rgfAttribs;
  424. //
  425. // Attributes (subject to rgfAttribs mask) that must be on or off
  426. // for files that match this enumeration
  427. //
  428. ULONG rgfAttribsOnOff;
  429. //
  430. // Number of sort descriptions
  431. //
  432. ULONG csrtdsc;
  433. //
  434. // Individual sort descriptors
  435. //
  436. SORTDESC rgsrtdsc[MAXSORTDESC];
  437. //
  438. // Count of patterns that are later converted to FS's
  439. //
  440. ULONG cpatdsc;
  441. //
  442. // Pointer to first pattern
  443. //
  444. PATDSC patdscFirst;
  445. //
  446. // Form of timestamp to display
  447. //
  448. ULONG dwTimeType;
  449. //
  450. // Count of files and directories seen and total bytes
  451. //
  452. ULONG FileCount;
  453. ULONG DirectoryCount;
  454. LARGE_INTEGER TotalBytes;
  455. } DRP;
  456. typedef DRP *PDRP;
  457. //
  458. // The following number is also in makefile.inc as a parameter to MC.EXE
  459. // to prevent it from generating a message that is bigger than we can handle.
  460. //
  461. #define MAXCBMSGBUFFER LBUFLEN
  462. TCHAR MsgBuf[MAXCBMSGBUFFER] ;
  463. //
  464. // The buffers holding WIN32_FIND_DATA for dir use a USHORT size field
  465. // for each WIN32_FIND_DATA entry and place the each data entry one after the
  466. // other, plus DWORD align each entry. This is to avoid allocating MAX_PATH
  467. // for each file name or maintaining a seperate filename buffer.
  468. // The size of the entry is maintained so that we can quickly run over
  469. // all of the data entries generating a seperate array of pointers to each
  470. // entry that is used in sorting.
  471. //
  472. // obAlternative is the offset from the cFileName field to the alternative
  473. // file name field if any. A 0 indication no alternative file name.
  474. //
  475. typedef struct {
  476. USHORT cb;
  477. USHORT obAlternate;
  478. WIN32_FIND_DATA data;
  479. } FF, *PFF, **PPFF;
  480. typedef struct FS {
  481. //
  482. // Link to next directory to be enumerated
  483. //
  484. struct FS * pfsNext;
  485. //
  486. // Text of directory to be enumerated
  487. //
  488. PTCHAR pszDir;
  489. //
  490. // Count of patterns in directory
  491. //
  492. ULONG cpatdsc;
  493. //
  494. // Linked list of patterns within directory to be enumerated
  495. //
  496. PPATDSC ppatdsc;
  497. //
  498. // Various state flags
  499. //
  500. BOOLEAN fIsFat;
  501. BOOLEAN fDelPrompted;
  502. //
  503. // Total count of entries stored in pff
  504. //
  505. ULONG cff;
  506. //
  507. // Pointer to packed FF's
  508. //
  509. PFF pff;
  510. //
  511. // Array of pointers into packed FF's. Used for sorting.
  512. //
  513. PPFF prgpff;
  514. //
  515. // Number of files/directories in FF's
  516. //
  517. ULONG FileCount;
  518. ULONG DirectoryCount;
  519. //
  520. // Total disk usage by all files satisfying this enumeration
  521. //
  522. LARGE_INTEGER cbFileTotal;
  523. } FS, *PFS;
  524. //
  525. // used in dir to control display of screen.
  526. //
  527. typedef struct { // scr
  528. HANDLE hndScreen; // Screen handle (NULL if not a device)
  529. ULONG crow; // row position on current screen
  530. ULONG ccol; // column position in current row
  531. ULONG cbMaxBuffer;// size of allocated buffer
  532. PTCHAR pbBuffer; // bytes in buffer
  533. ULONG ccolTab; // column position for each tab
  534. ULONG ccolTabMax; // max. cols to allow tabing into.
  535. ULONG crowMax; // no. of rows on screen
  536. ULONG ccolMax; // no. of cols on screen
  537. ULONG crowPause; // no. of rows to pause on.
  538. ULONG cb; // no. of characters in row - different than
  539. // ccol, since Kanjii characters are half-width
  540. } SCREEN, *PSCREEN;
  541. /* Parse tree node structure declarations. The basic structure type is called
  542. * node and is used for all operators. All of the rest are based on it. There
  543. * are several types of structures because some commands need special fields.
  544. * Functions that manipulate a parse tree node will either not care what type
  545. * of node it is getting or will know in advance what to expect. All of the
  546. * nodes are the same size to make their manipulation easier.
  547. *
  548. * M022 - The structures for node and cmdnode have been changed so that
  549. * their redirection information is now a single pointer to a linked list
  550. * of 'relem' structures rather than two simple byte pointers for STDIN and
  551. * STDOUT and a single append flag.
  552. */
  553. struct node { /* Used for operators */
  554. int type ; /* Type of operator */
  555. struct savtype save ; /* FOR processor saves orig strings here */
  556. struct relem *rio ; /* M022 - Linked redirection list */
  557. struct node *lhs ; /* Ptr to left hand side of the operator */
  558. struct node *rhs ; /* Ptr to right hand side of the operator */
  559. INT_PTR extra[ 4 ] ; /* M022 - Padding now needed */
  560. } ;
  561. struct cmdnode { /* Used for all commands except ones below */
  562. int type ; /* Type of command */
  563. struct savtype save ; /* FOR processor saves orig strings here */
  564. struct relem *rio ; /* M022 - Linked redirection list */
  565. PTCHAR cmdline ; /* Ptr to command line */
  566. PTCHAR argptr ; /* Ptr to type of command */
  567. int flag ; /* M022 - Valid for cond and goto types */
  568. int cmdarg ; /* M022 - Argument to STRTYP routine */
  569. } ;
  570. #define CMDNODE_FLAG_GOTO 0x0001
  571. #define CMDNODE_FLAG_IF_IGNCASE 0x0002
  572. #define CMDNODE_ARG_IF_EQU 1
  573. #define CMDNODE_ARG_IF_NEQ 2
  574. #define CMDNODE_ARG_IF_LSS 3
  575. #define CMDNODE_ARG_IF_LEQ 4
  576. #define CMDNODE_ARG_IF_GTR 5
  577. #define CMDNODE_ARG_IF_GEQ 6
  578. struct fornode { /* Used for FOR commands */
  579. int type ; /* FOR command type */
  580. struct savtype save ; /* FOR processor saves orig strings here */
  581. struct relem *rio ; /* M022 - Linked redirection list */
  582. PTCHAR cmdline ; /* Ptr to command line */
  583. PTCHAR arglist ; /* Ptr to the FOR argument list */
  584. struct node *body ; /* Ptr to the body of the FOR */
  585. unsigned forvar ; /* FOR variable - MUST BE UNSIGNED */
  586. int flag ; /* Flag */
  587. union {
  588. PTCHAR recurseDir ;
  589. PTCHAR parseOpts ;
  590. } ;
  591. } ;
  592. #define FOR_LOOP 0x0001
  593. #define FOR_MATCH_DIRONLY 0x0002
  594. #define FOR_MATCH_RECURSE 0x0004
  595. #define FOR_MATCH_PARSE 0x0008
  596. struct ifnode { /* Used for IF commands */
  597. int type ; /* IF command type */
  598. struct savtype save ; /* FOR processor saves orig strings here */
  599. struct relem *rio ; /* M022 - Linked redirection list */
  600. PTCHAR cmdline ; /* Ptr to command line */
  601. struct cmdnode *cond ; /* Ptr to the IF condition */
  602. struct node *ifbody ; /* Ptr to the body of the IF */
  603. PTCHAR elseline ; /* Ptr to ELSE command line */
  604. struct node *elsebody ; /* Ptr to the body of the ELSE */
  605. } ;
  606. /* Operator and Command type values. These definitions are the values
  607. * assigned to the type fields in the parse tree nodes and can be used as
  608. * indexes into the Operator and command jump table. Because of this last
  609. * point these values ***>MUST<*** be kept in sync with the jump table.
  610. */
  611. #define CMDTYP 0
  612. #define CMDLOW 0 /* Lowest type number for an internal command */
  613. #define DIRTYP 0 /* DIR */
  614. #define DELTYP 1 /* DEL, ERASE */
  615. #define TYTYP 3 /* TYPE */
  616. #define CPYTYP 4 /* COPY */
  617. #define CDTYP 5 /* CD, CHDIR */
  618. #define RENTYP 7 /* REN, RENAME */
  619. #define ECHTYP 9 /* ECHO */
  620. #define SETTYP 10 /* SET */
  621. #define PAUTYP 11 /* PAUSE */
  622. #define DATTYP 12 /* DATE */
  623. #define TIMTYP 13 /* TIME */
  624. #define PROTYP 14 /* PROMPT */
  625. #define MDTYP 16 /* MD, MKDIR */
  626. #define RDTYP 18 /* RD, RMDIR */
  627. #define PATTYP 19 /* PATH */
  628. #define GOTYP 20 /* GOTO */
  629. #define SHFTYP 21 /* SHIFT */
  630. #define CLSTYP 22 /* CLS */
  631. #define CALTYP 23 /* M007 - New CALL command */
  632. #define VRITYP 24 /* VERIFY */
  633. #define VERTYP 25 /* VER */
  634. #define VOLTYP 26 /* VOL */
  635. #define EXITYP 27 /* EXIT */
  636. #define SLTYP 28 /* M006 - Definition for SETLOCAL command */
  637. #define ELTYP 29 /* M006 - Definition for ENDLOCAL command */
  638. #define CHPTYP 30 /* CHCP @@*/
  639. #define STRTTYP 31 /* START @@*/
  640. #define APPDTYP 32 /* APPEND @@ */
  641. #define KEYSTYP 33 /* KEYS @@5 */
  642. #define MOVETYP 34 /* MOVE @@5 */
  643. #define PUSHTYP 35 /* PushD */
  644. #define POPTYP 36 /* PopD */
  645. #define BRKTYP 37 /* M012 - Added new command type @@*/
  646. #define ASSOCTYP 38 /* M012 - Added new command type @@*/
  647. #define FTYPETYP 39 /* M012 - Added new command type @@*/
  648. #define COLORTYP 40 /* COLOR */
  649. #define CMDHIGH 40 /* Cmds higher than this are unique parse types @@*/
  650. #define FORTYP 41 /* FOR */
  651. #define IFTYP 42 /* IF */
  652. #define REMTYP 43 /* REM */
  653. #define CMDMAX 43 /* Values higher are not commands */
  654. #define LFTYP 44 /* Command separator (NL) */
  655. #define CSTYP 45 /* Command separator (&) */
  656. #define ORTYP 46 /* Or operator */
  657. #define ANDTYP 47 /* And operator */
  658. #define PIPTYP 48 /* Pipe operator */
  659. #define PARTYP 49 /* Parenthesis */
  660. #define CMDVERTYP 50 /* CMDEXTVERSION (used by if) */
  661. #define ERRTYP 51 /* ERRORLEVEL (used by if) */
  662. #define DEFTYP 52 /* DEFINED (used by if) */
  663. #define EXSTYP 53 /* EXIST (used by if) */
  664. #define NOTTYP 54 /* NOT (used by if) */
  665. #define STRTYP 55 /* String comparison (used by if) */
  666. #define CMPTYP 56 /* General comparison (used by if) */
  667. #define SILTYP 57 /* M024 - "SILENT" unary operator */
  668. #define HELPTYP 58 /* Help for FOR, IF and REM */
  669. #define TBLMAX 58 /* M012 - Highest numbered table entry */
  670. /* The following macros are for my debugging statements. DEBUG expands to
  671. * a call to my debug statement printer if the DBGugging variable is
  672. * defined. Otherwise, it expands to NULL.
  673. */
  674. #if DBG
  675. #define CMD_DEBUG_ENABLE 1
  676. #define DEBUG(a) Deb a
  677. /* The following are definitions of the debugging group and level bits
  678. * for the code in cbatch.c
  679. */
  680. #define BPGRP 0x0100 /* Batch processor group */
  681. #define BPLVL 0x0001 /* Batch processor level */
  682. #define FOLVL 0x0002 /* FOR processor level */
  683. #define IFLVL 0x0004 /* IF processor level */
  684. #define OTLVL 0x0008 /* Other batch commands level */
  685. /* The following are definitions of the debugging group and level bits
  686. * for the code in cclock.c
  687. */
  688. #define CLGRP 0x4000 /* Other commands group */
  689. #define DALVL 0x0001 /* Date command level */
  690. #define TILVL 0x0002 /* Time command level */
  691. /* The following are definitions of the DEBUGging group and level bits
  692. * for the code in cfile.c, cpparse.c, cpwork.c
  693. */
  694. #define FCGRP 0x0020 // File commands group
  695. #define COLVL 0x0001 // Copy level
  696. #define DELVL 0x0002 // Delete level
  697. #define RELVL 0x0004 // Rename level
  698. /* The following are definitions of the debugging group and level bits
  699. * for the code in cinfo.c and display.c
  700. */
  701. #define ICGRP 0x0040 /* Informational commands group */
  702. #define DILVL 0x0001 /* Directory level */
  703. #define TYLVL 0x0002 /* Type level */
  704. #define VOLVL 0x0008 /* Volume level */
  705. #define DISLVL 0x0040 /* Directory level */
  706. /* The following are definitions of the debugging group and level bits
  707. * for the code in cinit.c
  708. */
  709. #define INGRP 0x0002 /* Command Initialization group */
  710. #define ACLVL 0x0001 /* Argument checking level */
  711. #define EILVL 0x0002 /* Environment initialization level */
  712. #define RSLVL 0x0004 /* Rest of initialization level */
  713. /* The following are definitions of the debugging group and level bits
  714. * for the code in clex.c, cparse.c
  715. */
  716. #define PAGRP 0x0004 /* Parser */
  717. #define PALVL 0x0001 /* Parsing */
  718. #define LXLVL 0x0002 /* Lexing */
  719. #define LFLVL 0x0004 /* Input routine */
  720. #define DPLVL 0x0008 /* Dump parse tree */
  721. #define BYLVL 0x0010 /* Byte input routines */
  722. //
  723. // The following are definitions of the debugging group and level bits
  724. // for the code in cmd.c
  725. //
  726. #define MNGRP 0x0001 // Main command loop code group
  727. #define MNLVL 0x0001 // Main function level
  728. #define DFLVL 0x0002 // Dispatch function level
  729. #define RIOLVL 0x0004 // Redirection function level
  730. /* The following are definitions of the debugging group and level bits
  731. * for the code in cmem.c
  732. */
  733. #define MMGRP 0x1000 /* Memory Manager */
  734. #define MALVL 0x0001 /* Memory allocators */
  735. #define LMLVL 0x0002 /* List managers */
  736. #define SMLVL 0x0004 /* Segment manipulators */
  737. /* The following are definitions of the debugging group and level bits
  738. * for the code in cop.c
  739. */
  740. #define OPGRP 0x0008 /* Operators group */
  741. #define PILVL 0x0001 /* Pipe level */
  742. #define PNLVL 0x0002 /* Paren operator level */
  743. /* The following are definitions of the debugging group and level bits
  744. * for the code in cother.c
  745. */
  746. #define OCGRP 0x0400 /* Other commands group */
  747. #define BRLVL 0x0001 /* Break command level */
  748. #define CLLVL 0x0002 /* Cls command level */
  749. #define CTLVL 0x0004 /* Ctty command level */
  750. #define EXLVL 0x0008 /* Exit command level */
  751. #define VELVL 0x0010 /* Verify command level */
  752. /* The following are definitions of the debugging group and level bits
  753. * for the code in cpath.c
  754. */
  755. #define PCGRP 0x0010 /* Path commands group */
  756. #define MDLVL 0x0001 /* Mkdir level */
  757. #define CDLVL 0x0002 /* Chdir level */
  758. #define RDLVL 0x0004 /* Rmdir level */
  759. /* The following are definitions of the debugging group and level bits
  760. * for the code in csig.c
  761. */
  762. #define SHGRP 0x0800 /* Signal handler group */
  763. #define MSLVL 0x0001 /* Main Signal handler level */
  764. #define ISLVL 0x0002 /* Init Signal handler level */
  765. /* The following are definitions of the debugging group and level bits
  766. * for the code in ctools1.c, ctools2.c, ctools3.c and ffirst.c
  767. */
  768. #define CTGRP 0x2000 /* Common tools group */
  769. #define CTMLVL 0x0400 /* Common tools misc. level */
  770. #define BFLVL 0x0800 /* BuildFSpec() level */
  771. #define SFLVL 0x1000 /* ScanFSpec() level */
  772. #define SSLVL 0x2000 /* SetAndSaveDir() level */
  773. #define TSLVL 0x4000 /* TokStr() level */
  774. #define FPLVL 0x8000 /* FullPath level */
  775. #else
  776. #define CMD_DEBUG_ENABLE 0
  777. #define DEBUG(a)
  778. #endif
  779. /* File attributes */
  780. #define FILE_ATTRIBUTE_READONLY 0x00000001
  781. #define FILE_ATTRIBUTE_HIDDEN 0x00000002
  782. #define FILE_ATTRIBUTE_SYSTEM 0x00000004
  783. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
  784. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
  785. #define FILE_ATTRIBUTE_NORMAL 0x00000080
  786. #define IsDirectory(a) ((a) & FILE_ATTRIBUTE_DIRECTORY)
  787. #define IsReparse(a) ((a) & FILE_ATTRIBUTE_REPARSE_POINT)
  788. //#define A_AEV 0x37
  789. #define A_ALL (FILE_ATTRIBUTE_READONLY | \
  790. FILE_ATTRIBUTE_HIDDEN | \
  791. FILE_ATTRIBUTE_SYSTEM | \
  792. FILE_ATTRIBUTE_DIRECTORY | \
  793. FILE_ATTRIBUTE_ARCHIVE )
  794. //#define A_AEDV 0x27 /* all attributes except dir & vol */
  795. #define A_AEDV (A_ALL & ~FILE_ATTRIBUTE_DIRECTORY)
  796. //#define A_AEDVH 0x25 /* all except dir/vol/hidden (M040) */
  797. #define A_AEDVH (FILE_ATTRIBUTE_READONLY | \
  798. FILE_ATTRIBUTE_SYSTEM | \
  799. FILE_ATTRIBUTE_ARCHIVE )
  800. //#define A_AEVH 0x35 /* all except vol/hidden */
  801. #define A_AEVH (A_ALL & ~FILE_ATTRIBUTE_HIDDEN)
  802. /* Batdata is the structure which contains all of the information needed to
  803. * start/continue executing a batch job. The fields are:
  804. * filespec - full file specification of the batch file
  805. * dircpy - ptr to copy of current drive and directory (used by the
  806. * setlocal/endlocal commands.
  807. * filepos - the current position in the file
  808. * stackmin - M037 - the number of elements on the data stack comprising
  809. * only the batch data structure itself. Used when chaining to free
  810. * memory prior to reconstructing the data structure.
  811. * stacksize - the number of elements on the data stack before the
  812. * execution of the batch job begins. This number is past to
  813. * FreeStack() via Parser() to make sure that only that data which
  814. * is used to execute batch file statements is freed.
  815. * hRestrictedToken - Handle to the restricted token with which the batch file
  816. * should be run.
  817. * envcpy - ptr to structure containing info on environment copy
  818. * orgargs - pointer to original argument string
  819. * args - tokenized string containing the the unused batch job arguments
  820. * aptrs - pointers into args to individual arguments, NULL if no arg for
  821. * that number
  822. * alens - the lengths of individual args, 0 if no arg
  823. * backptr - the structures are stacked using this pointer. Through it,
  824. * nestable batch jobs are achieved.
  825. */
  826. #define CMD_MAX_SAVED_ENV 32
  827. struct batsaveddata {
  828. TCHAR *dircpy ;
  829. struct envdata * envcpy;
  830. BOOLEAN fEnableExtensions;
  831. BOOLEAN fDelayedExpansion;
  832. } ;
  833. struct batdata {
  834. TCHAR *filespec ;
  835. long filepos ;
  836. int stackmin ;
  837. int stacksize ;
  838. int SavedEnvironmentCount;
  839. HANDLE hRestrictedToken;
  840. TCHAR *orgargs ;
  841. TCHAR *args ;
  842. TCHAR *aptrs[10] ;
  843. int alens[10] ;
  844. TCHAR *orgaptr0 ;
  845. struct batsaveddata *saveddata[CMD_MAX_SAVED_ENV] ;
  846. struct batdata *backptr ;
  847. } ;
  848. //
  849. // The following variables are used to detect the current batch state
  850. //
  851. //
  852. // Set for /K on command line
  853. //
  854. extern BOOL SingleBatchInvocation; // fSingleBatchLine
  855. //
  856. // Set of /c switch on command line set.
  857. //
  858. extern BOOL SingleCommandInvocation; // fSingleCmdLine
  859. //
  860. // Data for start and executing a batch file. Used in calls
  861. //
  862. extern struct batdata *CurrentBatchFile; // CurBat
  863. //
  864. // Set during the execution of a GOTO command. All sequential dispatch
  865. // routines muse examine this and return success when set in order
  866. // to let the top-level batch file execution continue at the next
  867. // point
  868. //
  869. extern BOOLEAN GotoFlag;
  870. /* M022 - This structure has been changed. It is still used in a linked
  871. * list, but now stores no actual redirection information. Instead the
  872. * node pointer is used to access this data which is in another linked
  873. * list of relem structures whose head element is pointed to by n->rio in
  874. * the node. The riodata list is reverse linked and its tail element is
  875. * still pointed to by CurRIO (global).
  876. */
  877. struct rio {
  878. int type ; /* Type of redir'ing process */
  879. CRTHANDLE stdio ; /* Highest handle for this node */
  880. struct node *rnod ; /* Associated parse node ptr */
  881. struct rio *back ; /* Pointer to prior list element */
  882. } ;
  883. // relem is used in a linked list, the head element of which is pointed to by
  884. // n->rio in a 'node' or 'cmdnode'. It contains the following parse information;
  885. // the handle to be redirected, a pointer to the filename (or "&n" for handle
  886. // substitution), the handle where the original is saved (by duping it), the
  887. // operator, ('>' or '<'), specifying the redirection type, a flag to indicate
  888. // whether this is to be appended and a pointer to the next list element.
  889. struct relem {
  890. CRTHANDLE rdhndl ; // handle to be redirected
  891. TCHAR *fname ; // filename (or &n)
  892. CRTHANDLE svhndl ; // where orig handle is saved
  893. int flag ; // Append flag
  894. TCHAR rdop ; // Type ('>' | '<')
  895. struct relem *nxt ; // Next structure
  896. };
  897. /* Used to hold information on Copy sources and destinations. */
  898. struct cpyinfo {
  899. TCHAR *fspec ; /* Source/destination filespec */
  900. TCHAR *curfspec ; /* Current filespec being used */
  901. TCHAR *pathend ; /* Ptr to end of pathname in fspec */
  902. TCHAR *fnptr ; /* Ptr to filename in fspec */
  903. TCHAR *extptr ; /* Ptr to file extension in fspec */
  904. PWIN32_FIND_DATA buf ; /* Buffer used for findfirst/next */
  905. int flags ; /* Wildcards, device, etc */
  906. struct cpyinfo *next ; /* Next ptr, used with sources only */
  907. } ;
  908. /* Following is true if user specifically enable the potentially incompatible */
  909. /* extensions to CMD.EXE. */
  910. extern BOOLEAN fEnableExtensions;
  911. extern BOOLEAN fDelayedExpansion;
  912. //
  913. // Suppress/allow delay load errors
  914. //
  915. extern BOOLEAN ReportDelayLoadErrors;
  916. /* Message Retriever definitions */
  917. #define NOARGS 0
  918. #define ONEARG 1
  919. #define TWOARGS 2
  920. #define THREEARGS 3
  921. /* length of double byte character set (DBCS) buffer */
  922. #define DBCS_BUF_LEN 10
  923. /* DBCS_SPACE is the code for the second byte of a dbcs space character
  924. * DBCS_SPACE is not a space unless it immediatly follows a bdcs lead
  925. * character */
  926. /* I don't know what value the double byte space is, so I made a guess.
  927. * I know this guess is wrong, but, you've gotta suffer if you're going
  928. * to sing the blues!
  929. * (Correct the value for BDCS_SPACE and everything should work fine)
  930. */
  931. #define DBCS_SPACE 64 /* @@ */
  932. #define LEAD_DBCS_SPACE 129 /* @@ */
  933. /*
  934. * is_dbcsleadchar(c) returns TRUE if c is a valid first character of a double
  935. * character code, FALSE otherwise.
  936. *
  937. */
  938. extern BOOLEAN DbcsLeadCharTable[ ];
  939. //
  940. // AnyDbcsLeadChars can be tested to determine if there are any TRUE values
  941. // in DbcsLeadCharTable i.e. do we have to do any look-ups.
  942. //
  943. extern BOOLEAN AnyDbcsLeadChars;
  944. #define is_dbcsleadchar( c ) DbcsLeadCharTable[((UCHAR)(c))]
  945. //
  946. // Line terminator
  947. //
  948. extern TCHAR CrLf[] ;
  949. //
  950. // The following macros are copies of the C Runtime versions that test
  951. // for NULL string pointer arguments and return NULL instead of generating
  952. // an access violation dereferencing a null pointer.
  953. //
  954. #define mystrlen( str ) \
  955. ( (str) ? _tcslen( str ) : ( 0 ))
  956. #define mystrcpy( s1, s2 ) \
  957. ( ((s1) && (s2)) ? _tcscpy( s1, s2 ) : ( NULL ))
  958. #define mystrcat( s1, s2 ) \
  959. ( ((s1) && (s2)) ? _tcscat( s1, s2 ) : ( NULL ))
  960. extern TCHAR DbcsFlags[];
  961. #define W_ON 1 /* Whinthorn.DLL exists */
  962. #define W_OFF 0 /* Whinthorn.DLL exists */
  963. #define FIFO 0 /* FIFO Queue */
  964. #define FULLSCRN 0 /* Full Screen Mode */
  965. #define VIOWIN 1 /* VIO Windowable Mode */
  966. #define DETACHED 2 /* Detached Mode */
  967. #define NONEPGM 0 /* Program is not started */
  968. #define EXECPGM 1 /* Program is started by DosExecPgm */
  969. #define STARTSESSION 2 /* Program is started by DosStartSession */
  970. #define WAIT 0 /* WAIT for DosReadQueue */
  971. #define NOWAIT 1 /* NOWAIT for DosReadQueue */
  972. #define READ_TERMQ 0 /* Read TermQ */
  973. #define ALL_STOP 0 /* Terminate All Sessions */
  974. #define SPEC_STOP 1 /* Terminate Specified Session */
  975. // to handle OS/2 vs DOS behavior (e.g. errorlevel) in a script files
  976. #define NO_TYPE 0
  977. #define BAT_TYPE 1
  978. #define CMD_TYPE 2
  979. #include "cmdproto.h"
  980. #include "console.h"
  981. #include "dir.h"
  982. #include <vdmapi.h>
  983. #include <conapi.h>
  984. #if defined(RICHARDW)
  985. extern TCHAR Buffer27[ TMPBUFLEN ];
  986. __inline VOID
  987. Mirror( BOOL Result, PTCHAR Buf, ULONG CharCount )
  988. {
  989. HANDLE File;
  990. if (!Result) {
  991. return;
  992. }
  993. File = CreateFile( Buffer27,
  994. GENERIC_WRITE,
  995. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
  996. NULL,
  997. OPEN_ALWAYS,
  998. FILE_ATTRIBUTE_NORMAL,
  999. NULL );
  1000. if (File == INVALID_HANDLE_VALUE) {
  1001. return;
  1002. }
  1003. SetFilePointer( File, 0, NULL, FILE_END );
  1004. WriteFile( File,
  1005. Buf,
  1006. CharCount * sizeof( TCHAR ),
  1007. &CharCount,
  1008. NULL );
  1009. CloseHandle( File );
  1010. }
  1011. #endif