msvcp90: Use macro to define RTTI data.
[wine] / programs / cmd / wcmd.h
1 /*
2  * CMD - Wine-compatible command line interface.
3  *
4  * Copyright (C) 1999 D A Pickles
5  * Copyright (C) 2007 J Edmeades
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #define IDI_ICON1       1
23 #include <windows.h>
24 #include <windef.h>
25 #ifndef RC_INVOKED
26 #include <string.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <ctype.h>
31 #include <wine/unicode.h>
32
33 /* msdn specified max for Win XP */
34 #define MAXSTRING 8192
35
36 /* Data structure to hold commands delimitors/separators */
37
38 typedef enum _CMDdelimiters {
39   CMD_NONE,        /* End of line or single & */
40   CMD_ONFAILURE,   /* ||                      */
41   CMD_ONSUCCESS,   /* &&                      */
42   CMD_PIPE         /* Single |                */
43 } CMD_DELIMITERS;
44
45 /* Data structure to hold commands to be processed */
46
47 typedef struct _CMD_LIST {
48   WCHAR              *command;     /* Command string to execute                */
49   WCHAR              *redirects;   /* Redirects in place                       */
50   struct _CMD_LIST   *nextcommand; /* Next command string to execute           */
51   CMD_DELIMITERS      prevDelim;   /* Previous delimiter                       */
52   int                 bracketDepth;/* How deep bracketing have we got to       */
53   WCHAR               pipeFile[MAX_PATH]; /* Where to get input from for pipes */
54 } CMD_LIST;
55
56 void WCMD_assoc (const WCHAR *, BOOL);
57 void WCMD_batch (WCHAR *, WCHAR *, int, WCHAR *, HANDLE);
58 void WCMD_call (WCHAR *command);
59 void WCMD_change_tty (void);
60 void WCMD_choice (const WCHAR *);
61 void WCMD_clear_screen (void);
62 void WCMD_color (void);
63 void WCMD_copy (void);
64 void WCMD_create_dir (WCHAR *);
65 BOOL WCMD_delete (WCHAR *);
66 void WCMD_directory (WCHAR *);
67 void WCMD_echo (const WCHAR *);
68 void WCMD_endlocal (void);
69 void WCMD_enter_paged_mode(const WCHAR *);
70 void WCMD_exit (CMD_LIST **cmdList);
71 void WCMD_for (WCHAR *, CMD_LIST **cmdList);
72 void WCMD_give_help (const WCHAR *command);
73 void WCMD_goto (CMD_LIST **cmdList);
74 void WCMD_if (WCHAR *, CMD_LIST **cmdList);
75 void WCMD_leave_paged_mode(void);
76 void WCMD_more (WCHAR *);
77 void WCMD_move (void);
78 WCHAR* CDECL WCMD_format_string (const WCHAR *format, ...);
79 void CDECL WCMD_output (const WCHAR *format, ...);
80 void CDECL WCMD_output_stderr (const WCHAR *format, ...);
81 void WCMD_output_asis (const WCHAR *message);
82 void WCMD_output_asis_stderr (const WCHAR *message);
83 void WCMD_pause (void);
84 void WCMD_popd (void);
85 void WCMD_print_error (void);
86 void WCMD_pushd (const WCHAR *command);
87 void WCMD_remove_dir (WCHAR *command);
88 void WCMD_rename (void);
89 void WCMD_run_program (WCHAR *command, int called);
90 void WCMD_setlocal (const WCHAR *command);
91 void WCMD_setshow_date (void);
92 void WCMD_setshow_default (const WCHAR *command);
93 void WCMD_setshow_env (WCHAR *command);
94 void WCMD_setshow_path (const WCHAR *command);
95 void WCMD_setshow_prompt (void);
96 void WCMD_setshow_time (void);
97 void WCMD_shift (const WCHAR *command);
98 void WCMD_title (const WCHAR *);
99 void WCMD_type (WCHAR *);
100 void WCMD_verify (const WCHAR *command);
101 void WCMD_version (void);
102 int  WCMD_volume (BOOL set_label, const WCHAR *command);
103
104 static inline BOOL WCMD_is_console_handle(HANDLE h)
105 {
106     return (((DWORD_PTR)h) & 3) == 3;
107 }
108 WCHAR *WCMD_fgets (WCHAR *buf, DWORD n, HANDLE stream);
109 WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **start, WCHAR **end);
110 WCHAR *WCMD_skip_leading_spaces (WCHAR *string);
111 BOOL WCMD_keyword_ws_found(const WCHAR *keyword, int len, const WCHAR *ptr);
112 void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable, const WCHAR *forValue, BOOL justFors);
113
114 void WCMD_splitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext);
115 void WCMD_strip_quotes(WCHAR *cmd);
116 WCHAR *WCMD_LoadMessage(UINT id);
117 WCHAR *WCMD_strdupW(const WCHAR *input);
118 void WCMD_strsubstW(WCHAR *start, const WCHAR* next, const WCHAR* insert, int len);
119 BOOL WCMD_ReadFile(const HANDLE hIn, WCHAR *intoBuf, const DWORD maxChars, LPDWORD charsRead);
120
121 WCHAR    *WCMD_ReadAndParseLine(const WCHAR *initialcmd, CMD_LIST **output, HANDLE readFrom);
122 CMD_LIST *WCMD_process_commands(CMD_LIST *thisCmd, BOOL oneBracket,
123                                 const WCHAR *var, const WCHAR *val);
124 void      WCMD_free_commands(CMD_LIST *cmds);
125 void      WCMD_execute (const WCHAR *orig_command, const WCHAR *redirects,
126                         const WCHAR *parameter, const WCHAR *substitution,
127                         CMD_LIST **cmdList);
128
129 /* Data structure to hold context when executing batch files */
130
131 typedef struct _BATCH_CONTEXT {
132   WCHAR *command;       /* The command which invoked the batch file */
133   HANDLE h;             /* Handle to the open batch file */
134   WCHAR *batchfileW;    /* Name of same */
135   int shift_count[10];  /* Offset in terms of shifts for %0 - %9 */
136   struct _BATCH_CONTEXT *prev_context; /* Pointer to the previous context block */
137   BOOL  skip_rest;      /* Skip the rest of the batch program and exit */
138   CMD_LIST *toExecute;  /* Commands left to be executed */
139 } BATCH_CONTEXT;
140
141 /* Data structure to handle building lists during recursive calls */
142
143 struct env_stack
144 {
145   struct env_stack *next;
146   union {
147     int    stackdepth;       /* Only used for pushd and popd */
148     WCHAR   cwd;              /* Only used for set/endlocal   */
149   } u;
150   WCHAR *strings;
151 };
152
153 /* Data structure to save setlocal and pushd information */
154
155 typedef struct _DIRECTORY_STACK
156 {
157   struct _DIRECTORY_STACK *next;
158   WCHAR  *dirName;
159   WCHAR  *fileName;
160 } DIRECTORY_STACK;
161
162 /*
163  * Global variables quals, param1, param2 contain the current qualifiers
164  * (uppercased and concatenated) and parameters entered, with environment
165  * variables and batch parameters substitution already done.
166  */
167 extern WCHAR quals[MAX_PATH], param1[MAXSTRING], param2[MAXSTRING];
168 extern DWORD errorlevel;
169 extern BATCH_CONTEXT *context;
170
171 #endif /* !RC_INVOKED */
172
173 /*
174  *      Serial nos of builtin commands. These constants must be in step with
175  *      the list of strings defined in wcmd.rc, and WCMD_EXIT *must* always be
176  *      the last one.
177  *
178  *      Yes it *would* be nice to use an enumeration here, but the Resource
179  *      Compiler won't accept resource IDs from enumerations :-(
180  */
181
182 #define WCMD_CALL      0
183 #define WCMD_CD        1
184 #define WCMD_CHDIR     2
185 #define WCMD_CLS       3
186 #define WCMD_COPY      4
187 #define WCMD_CTTY      5
188 #define WCMD_DATE      6
189 #define WCMD_DEL       7
190 #define WCMD_DIR       8
191 #define WCMD_ECHO      9
192 #define WCMD_ERASE    10
193 #define WCMD_FOR      11
194 #define WCMD_GOTO     12
195 #define WCMD_HELP     13
196 #define WCMD_IF       14
197 #define WCMD_LABEL    15
198 #define WCMD_MD       16
199 #define WCMD_MKDIR    17
200 #define WCMD_MOVE     18
201 #define WCMD_PATH     19
202 #define WCMD_PAUSE    20
203 #define WCMD_PROMPT   21
204 #define WCMD_REM      22
205 #define WCMD_REN      23
206 #define WCMD_RENAME   24
207 #define WCMD_RD       25
208 #define WCMD_RMDIR    26
209 #define WCMD_SET      27
210 #define WCMD_SHIFT    28
211 #define WCMD_TIME     29
212 #define WCMD_TITLE    30
213 #define WCMD_TYPE     31
214 #define WCMD_VERIFY   32
215 #define WCMD_VER      33
216 #define WCMD_VOL      34
217
218 #define WCMD_ENDLOCAL 35
219 #define WCMD_SETLOCAL 36
220 #define WCMD_PUSHD    37
221 #define WCMD_POPD     38
222 #define WCMD_ASSOC    39
223 #define WCMD_COLOR    40
224 #define WCMD_FTYPE    41
225 #define WCMD_MORE     42
226 #define WCMD_CHOICE   43
227
228 /* Must be last in list */
229 #define WCMD_EXIT     44
230
231 /* Some standard messages */
232 extern const WCHAR newline[];
233 extern const WCHAR space[];
234 extern const WCHAR nullW[];
235 extern const WCHAR dotW[];
236 extern const WCHAR dotdotW[];
237 extern const WCHAR starW[];
238 extern const WCHAR slashW[];
239 extern const WCHAR equalW[];
240 extern WCHAR anykey[];
241 extern WCHAR version_string[];
242
243 /* Translated messages */
244 #define WCMD_ALLHELP          1000
245 #define WCMD_CONFIRM          1001
246 #define WCMD_YES              1002
247 #define WCMD_NO               1003
248 #define WCMD_NOASSOC          1004
249 #define WCMD_NOFTYPE          1005
250 #define WCMD_OVERWRITE        1006
251 #define WCMD_MORESTR          1007
252 #define WCMD_TRUNCATEDLINE    1008
253 #define WCMD_NYI              1009
254 #define WCMD_NOARG            1010
255 #define WCMD_SYNTAXERR        1011
256 #define WCMD_FILENOTFOUND     1012
257 #define WCMD_NOCMDHELP        1013
258 #define WCMD_NOTARGET         1014
259 #define WCMD_CURRENTDATE      1015
260 #define WCMD_CURRENTTIME      1016
261 #define WCMD_NEWDATE          1017
262 #define WCMD_NEWTIME          1018
263 #define WCMD_MISSINGENV       1019
264 #define WCMD_READFAIL         1020
265 #define WCMD_CALLINSCRIPT     1021
266 #define WCMD_ALL              1022
267 #define WCMD_DELPROMPT        1023
268 #define WCMD_ECHOPROMPT       1024
269 #define WCMD_VERIFYPROMPT     1025
270 #define WCMD_VERIFYERR        1026
271 #define WCMD_ARGERR           1027
272 #define WCMD_VOLUMESERIALNO   1028
273 #define WCMD_VOLUMEPROMPT     1029
274 #define WCMD_NOPATH           1030
275 #define WCMD_ANYKEY           1031
276 #define WCMD_CONSTITLE        1032
277 #define WCMD_VERSION          1033
278 #define WCMD_MOREPROMPT       1034
279 #define WCMD_LINETOOLONG      1035
280 #define WCMD_VOLUMELABEL      1036
281 #define WCMD_VOLUMENOLABEL    1037