cmd: Add an output parameter to WCMD_parameter to point to the end of the extracted...
[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 /* Data structure to hold commands delimitors/separators */
34
35 typedef enum _CMDdelimiters {
36   CMD_NONE,        /* End of line or single & */
37   CMD_ONFAILURE,   /* ||                      */
38   CMD_ONSUCCESS,   /* &&                      */
39   CMD_PIPE         /* Single |                */
40 } CMD_DELIMITERS;
41
42 /* Data structure to hold commands to be processed */
43
44 typedef struct _CMD_LIST {
45   WCHAR              *command;     /* Command string to execute                */
46   WCHAR              *redirects;   /* Redirects in place                       */
47   struct _CMD_LIST   *nextcommand; /* Next command string to execute           */
48   CMD_DELIMITERS      prevDelim;   /* Previous delimiter                       */
49   int                 bracketDepth;/* How deep bracketing have we got to       */
50   WCHAR               pipeFile[MAX_PATH]; /* Where to get input from for pipes */
51 } CMD_LIST;
52
53 void WCMD_assoc (const WCHAR *, BOOL);
54 void WCMD_batch (WCHAR *, WCHAR *, int, WCHAR *, HANDLE);
55 void WCMD_call (WCHAR *command);
56 void WCMD_change_tty (void);
57 void WCMD_choice (const WCHAR *);
58 void WCMD_clear_screen (void);
59 void WCMD_color (void);
60 void WCMD_copy (void);
61 void WCMD_create_dir (WCHAR *);
62 BOOL WCMD_delete (WCHAR *);
63 void WCMD_directory (WCHAR *);
64 void WCMD_echo (const WCHAR *);
65 void WCMD_endlocal (void);
66 void WCMD_enter_paged_mode(const WCHAR *);
67 void WCMD_exit (CMD_LIST **cmdList);
68 void WCMD_for (WCHAR *, CMD_LIST **cmdList);
69 void WCMD_give_help (const WCHAR *command);
70 void WCMD_goto (CMD_LIST **cmdList);
71 void WCMD_if (WCHAR *, CMD_LIST **cmdList);
72 void WCMD_leave_paged_mode(void);
73 void WCMD_more (WCHAR *);
74 void WCMD_move (void);
75 void WCMD_output (const WCHAR *format, ...);
76 void WCMD_output_asis (const WCHAR *message);
77 void WCMD_output_asis_stderr (const WCHAR *message);
78 void WCMD_pause (void);
79 void WCMD_popd (void);
80 void WCMD_print_error (void);
81 void WCMD_pushd (WCHAR *);
82 void WCMD_remove_dir (WCHAR *command);
83 void WCMD_rename (void);
84 void WCMD_run_program (WCHAR *command, int called);
85 void WCMD_setlocal (const WCHAR *command);
86 void WCMD_setshow_date (void);
87 void WCMD_setshow_default (const WCHAR *command);
88 void WCMD_setshow_env (WCHAR *command);
89 void WCMD_setshow_path (const WCHAR *command);
90 void WCMD_setshow_prompt (void);
91 void WCMD_setshow_time (void);
92 void WCMD_shift (const WCHAR *command);
93 void WCMD_title (const WCHAR *);
94 void WCMD_type (WCHAR *);
95 void WCMD_verify (const WCHAR *command);
96 void WCMD_version (void);
97 int  WCMD_volume (int mode, const WCHAR *command);
98
99 WCHAR *WCMD_fgets (WCHAR *s, int n, HANDLE stream);
100 WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where, WCHAR **end);
101 WCHAR *WCMD_skip_leading_spaces (WCHAR *string);
102 BOOL WCMD_keyword_ws_found(const WCHAR *keyword, int len, const WCHAR *ptr);
103 void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable, const WCHAR *forValue, BOOL justFors);
104
105 void WCMD_splitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext);
106 void WCMD_opt_s_strip_quotes(WCHAR *cmd);
107 WCHAR *WCMD_LoadMessage(UINT id);
108 WCHAR *WCMD_strdupW(const WCHAR *input);
109 void WCMD_strsubstW(WCHAR *start, const WCHAR* next, const WCHAR* insert, int len);
110 BOOL WCMD_ReadFile(const HANDLE hIn, WCHAR *intoBuf, const DWORD maxChars,
111                    LPDWORD charsRead, const LPOVERLAPPED unused);
112
113 WCHAR    *WCMD_ReadAndParseLine(const WCHAR *initialcmd, CMD_LIST **output, HANDLE readFrom);
114 CMD_LIST *WCMD_process_commands(CMD_LIST *thisCmd, BOOL oneBracket,
115                                 const WCHAR *var, const WCHAR *val);
116 void      WCMD_free_commands(CMD_LIST *cmds);
117 void      WCMD_execute (const WCHAR *orig_command, const WCHAR *redirects,
118                         const WCHAR *parameter, const WCHAR *substitution,
119                         CMD_LIST **cmdList);
120
121 /* Data structure to hold context when executing batch files */
122
123 typedef struct {
124   WCHAR *command;       /* The command which invoked the batch file */
125   HANDLE h;             /* Handle to the open batch file */
126   WCHAR *batchfileW;    /* Name of same */
127   int shift_count[10];  /* Offset in terms of shifts for %0 - %9 */
128   void *prev_context;   /* Pointer to the previous context block */
129   BOOL  skip_rest;      /* Skip the rest of the batch program and exit */
130   CMD_LIST *toExecute;  /* Commands left to be executed */
131 } BATCH_CONTEXT;
132
133 /* Data structure to handle building lists during recursive calls */
134
135 struct env_stack
136 {
137   struct env_stack *next;
138   union {
139     int    stackdepth;       /* Only used for pushd and popd */
140     WCHAR   cwd;              /* Only used for set/endlocal   */
141   } u;
142   WCHAR *strings;
143 };
144
145 /* Data structure to save setlocal and pushd information */
146
147 typedef struct _DIRECTORY_STACK
148 {
149   struct _DIRECTORY_STACK *next;
150   WCHAR  *dirName;
151   WCHAR  *fileName;
152 } DIRECTORY_STACK;
153
154 #endif /* !RC_INVOKED */
155
156 /*
157  *      Serial nos of builtin commands. These constants must be in step with
158  *      the list of strings defined in wcmd.rc, and WCMD_EXIT *must* always be
159  *      the last one.
160  *
161  *      Yes it *would* be nice to use an enumeration here, but the Resource
162  *      Compiler won't accept resource IDs from enumerations :-(
163  */
164
165 #define WCMD_CALL      0
166 #define WCMD_CD        1
167 #define WCMD_CHDIR     2
168 #define WCMD_CLS       3
169 #define WCMD_COPY      4
170 #define WCMD_CTTY      5
171 #define WCMD_DATE      6
172 #define WCMD_DEL       7
173 #define WCMD_DIR       8
174 #define WCMD_ECHO      9
175 #define WCMD_ERASE    10
176 #define WCMD_FOR      11
177 #define WCMD_GOTO     12
178 #define WCMD_HELP     13
179 #define WCMD_IF       14
180 #define WCMD_LABEL    15
181 #define WCMD_MD       16
182 #define WCMD_MKDIR    17
183 #define WCMD_MOVE     18
184 #define WCMD_PATH     19
185 #define WCMD_PAUSE    20
186 #define WCMD_PROMPT   21
187 #define WCMD_REM      22
188 #define WCMD_REN      23
189 #define WCMD_RENAME   24
190 #define WCMD_RD       25
191 #define WCMD_RMDIR    26
192 #define WCMD_SET      27
193 #define WCMD_SHIFT    28
194 #define WCMD_TIME     29
195 #define WCMD_TITLE    30
196 #define WCMD_TYPE     31
197 #define WCMD_VERIFY   32
198 #define WCMD_VER      33
199 #define WCMD_VOL      34
200
201 #define WCMD_ENDLOCAL 35
202 #define WCMD_SETLOCAL 36
203 #define WCMD_PUSHD    37
204 #define WCMD_POPD     38
205 #define WCMD_ASSOC    39
206 #define WCMD_COLOR    40
207 #define WCMD_FTYPE    41
208 #define WCMD_MORE     42
209 #define WCMD_CHOICE   43
210
211 /* Must be last in list */
212 #define WCMD_EXIT     44
213
214 /* Some standard messages */
215 extern const WCHAR newline[];
216 extern WCHAR anykey[];
217 extern WCHAR version_string[];
218
219 /* Translated messages */
220 #define WCMD_ALLHELP          1000
221 #define WCMD_CONFIRM          1001
222 #define WCMD_YES              1002
223 #define WCMD_NO               1003
224 #define WCMD_NOASSOC          1004
225 #define WCMD_NOFTYPE          1005
226 #define WCMD_OVERWRITE        1006
227 #define WCMD_MORESTR          1007
228 #define WCMD_TRUNCATEDLINE    1008
229 #define WCMD_NYI              1009
230 #define WCMD_NOARG            1010
231 #define WCMD_SYNTAXERR        1011
232 #define WCMD_FILENOTFOUND     1012
233 #define WCMD_NOCMDHELP        1013
234 #define WCMD_NOTARGET         1014
235 #define WCMD_CURRENTDATE      1015
236 #define WCMD_CURRENTTIME      1016
237 #define WCMD_NEWDATE          1017
238 #define WCMD_NEWTIME          1018
239 #define WCMD_MISSINGENV       1019
240 #define WCMD_READFAIL         1020
241 #define WCMD_CALLINSCRIPT     1021
242 #define WCMD_ALL              1022
243 #define WCMD_DELPROMPT        1023
244 #define WCMD_ECHOPROMPT       1024
245 #define WCMD_VERIFYPROMPT     1025
246 #define WCMD_VERIFYERR        1026
247 #define WCMD_ARGERR           1027
248 #define WCMD_VOLUMEDETAIL     1028
249 #define WCMD_VOLUMEPROMPT     1029
250 #define WCMD_NOPATH           1030
251 #define WCMD_ANYKEY           1031
252 #define WCMD_CONSTITLE        1032
253 #define WCMD_VERSION          1033
254 #define WCMD_MOREPROMPT       1034
255 #define WCMD_LINETOOLONG      1035
256
257 /* msdn specified max for Win XP */
258 #define MAXSTRING 8192