2 * CMD - Wine-compatible command line interface.
4 * Copyright (C) 1999 D A Pickles
5 * Copyright (C) 2007 J Edmeades
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.
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.
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
30 #include <wine/unicode.h>
32 /* Data structure to hold commands to be processed */
34 typedef struct _CMD_LIST
{
35 WCHAR
*command
; /* Command string to execute */
36 WCHAR
*redirects
; /* Redirects in place */
37 struct _CMD_LIST
*nextcommand
; /* Next command string to execute */
38 BOOL isAmphersand
;/* Whether follows && */
39 int bracketDepth
;/* How deep bracketing have we got to */
42 void WCMD_assoc (WCHAR
*, BOOL
);
43 void WCMD_batch (WCHAR
*, WCHAR
*, int, WCHAR
*, HANDLE
);
44 void WCMD_call (WCHAR
*command
);
45 void WCMD_change_tty (void);
46 void WCMD_clear_screen (void);
47 void WCMD_color (void);
48 void WCMD_copy (void);
49 void WCMD_create_dir (void);
50 BOOL
WCMD_delete (WCHAR
*, BOOL
);
51 void WCMD_directory (WCHAR
*);
52 void WCMD_echo (const WCHAR
*);
53 void WCMD_endlocal (void);
54 void WCMD_enter_paged_mode(const WCHAR
*);
55 void WCMD_exit (CMD_LIST
**cmdList
);
56 void WCMD_for (WCHAR
*, CMD_LIST
**cmdList
);
57 void WCMD_give_help (WCHAR
*command
);
58 void WCMD_goto (CMD_LIST
**cmdList
);
59 void WCMD_if (WCHAR
*, CMD_LIST
**cmdList
);
60 void WCMD_leave_paged_mode(void);
61 void WCMD_more (WCHAR
*);
62 void WCMD_move (void);
63 void WCMD_output (const WCHAR
*format
, ...);
64 void WCMD_output_asis (const WCHAR
*message
);
65 void WCMD_parse (WCHAR
*s
, WCHAR
*q
, WCHAR
*p1
, WCHAR
*p2
);
66 void WCMD_pause (void);
67 void WCMD_pipe (CMD_LIST
**command
, WCHAR
*var
, WCHAR
*val
);
68 void WCMD_popd (void);
69 void WCMD_print_error (void);
70 void WCMD_pushd (WCHAR
*);
71 int WCMD_read_console (WCHAR
*string
, int str_len
);
72 void WCMD_remove_dir (WCHAR
*command
);
73 void WCMD_rename (void);
74 void WCMD_run_program (WCHAR
*command
, int called
);
75 void WCMD_setlocal (const WCHAR
*command
);
76 void WCMD_setshow_attrib (void);
77 void WCMD_setshow_date (void);
78 void WCMD_setshow_default (WCHAR
*command
);
79 void WCMD_setshow_env (WCHAR
*command
);
80 void WCMD_setshow_path (WCHAR
*command
);
81 void WCMD_setshow_prompt (void);
82 void WCMD_setshow_time (void);
83 void WCMD_shift (WCHAR
*command
);
84 void WCMD_show_prompt (void);
85 void WCMD_title (WCHAR
*);
86 void WCMD_type (WCHAR
*);
87 void WCMD_verify (WCHAR
*command
);
88 void WCMD_version (void);
89 int WCMD_volume (int mode
, WCHAR
*command
);
91 WCHAR
*WCMD_fgets (WCHAR
*s
, int n
, HANDLE stream
);
92 WCHAR
*WCMD_parameter (WCHAR
*s
, int n
, WCHAR
**where
);
93 WCHAR
*WCMD_strtrim_leading_spaces (WCHAR
*string
);
94 void WCMD_strtrim_trailing_spaces (WCHAR
*string
);
95 void WCMD_opt_s_strip_quotes(WCHAR
*cmd
);
96 void WCMD_HandleTildaModifiers(WCHAR
**start
, WCHAR
*forVariable
, WCHAR
*forValue
, BOOL justFors
);
97 BOOL
WCMD_ask_confirm (WCHAR
*message
, BOOL showSureText
, BOOL
*optionAll
);
99 void WCMD_splitpath(const WCHAR
* path
, WCHAR
* drv
, WCHAR
* dir
, WCHAR
* name
, WCHAR
* ext
);
100 WCHAR
*WCMD_LoadMessage(UINT id
);
101 WCHAR
*WCMD_strdupW(WCHAR
*input
);
102 BOOL
WCMD_ReadFile(const HANDLE hIn
, WCHAR
*intoBuf
, const DWORD maxChars
,
103 LPDWORD charsRead
, const LPOVERLAPPED unused
);
105 WCHAR
*WCMD_ReadAndParseLine(WCHAR
*initialcmd
, CMD_LIST
**output
, HANDLE readFrom
);
106 CMD_LIST
*WCMD_process_commands(CMD_LIST
*thisCmd
, BOOL oneBracket
, WCHAR
*var
, WCHAR
*val
);
107 void WCMD_free_commands(CMD_LIST
*cmds
);
108 void WCMD_execute (WCHAR
*orig_command
, WCHAR
*redirects
, WCHAR
*parameter
,
109 WCHAR
*substitution
, CMD_LIST
**cmdList
);
111 /* Data structure to hold context when executing batch files */
114 WCHAR
*command
; /* The command which invoked the batch file */
115 HANDLE h
; /* Handle to the open batch file */
116 int shift_count
[10]; /* Offset in terms of shifts for %0 - %9 */
117 void *prev_context
; /* Pointer to the previous context block */
118 BOOL skip_rest
; /* Skip the rest of the batch program and exit */
119 CMD_LIST
*toExecute
; /* Commands left to be executed */
122 /* Data structure to save setlocal and pushd information */
126 struct env_stack
*next
;
128 int stackdepth
; /* Only used for pushd and popd */
129 WCHAR cwd
; /* Only used for set/endlocal */
134 /* Data structure to handle building lists during recursive calls */
136 typedef struct _DIRECTORY_STACK
138 struct _DIRECTORY_STACK
*next
;
143 #endif /* !RC_INVOKED */
146 * Serial nos of builtin commands. These constants must be in step with
147 * the list of strings defined in WCMD.C, and WCMD_EXIT *must* always be
150 * Yes it *would* be nice to use an enumeration here, but the Resource
151 * Compiler won't accept resource IDs from enumerations :-(
154 #define WCMD_ATTRIB 0
165 #define WCMD_ERASE 11
170 #define WCMD_LABEL 16
172 #define WCMD_MKDIR 18
175 #define WCMD_PAUSE 21
176 #define WCMD_PROMPT 22
179 #define WCMD_RENAME 25
181 #define WCMD_RMDIR 27
183 #define WCMD_SHIFT 29
185 #define WCMD_TITLE 31
187 #define WCMD_VERIFY 33
191 #define WCMD_ENDLOCAL 36
192 #define WCMD_SETLOCAL 37
193 #define WCMD_PUSHD 38
195 #define WCMD_ASSOC 40
196 #define WCMD_COLOR 41
197 #define WCMD_FTYPE 42
200 /* Must be last in list */
203 /* Some standard messages */
204 extern const WCHAR newline
[];
205 extern WCHAR anykey
[];
206 extern WCHAR version_string
[];
208 /* Translated messages */
209 #define WCMD_ALLHELP 1000
210 #define WCMD_CONFIRM 1001
211 #define WCMD_YES 1002
213 #define WCMD_NOASSOC 1004
214 #define WCMD_NOFTYPE 1005
215 #define WCMD_OVERWRITE 1006
216 #define WCMD_MORESTR 1007
217 #define WCMD_TRUNCATEDLINE 1008
218 #define WCMD_NYI 1009
219 #define WCMD_NOARG 1010
220 #define WCMD_SYNTAXERR 1011
221 #define WCMD_FILENOTFOUND 1012
222 #define WCMD_NOCMDHELP 1013
223 #define WCMD_NOTARGET 1014
224 #define WCMD_CURRENTDATE 1015
225 #define WCMD_CURRENTTIME 1016
226 #define WCMD_NEWDATE 1017
227 #define WCMD_NEWTIME 1018
228 #define WCMD_MISSINGENV 1019
229 #define WCMD_READFAIL 1020
230 #define WCMD_CALLINSCRIPT 1021
231 #define WCMD_ALL 1022
232 #define WCMD_DELPROMPT 1023
233 #define WCMD_ECHOPROMPT 1024
234 #define WCMD_VERIFYPROMPT 1025
235 #define WCMD_VERIFYERR 1026
236 #define WCMD_ARGERR 1027
237 #define WCMD_VOLUMEDETAIL 1028
238 #define WCMD_VOLUMEPROMPT 1029
239 #define WCMD_NOPATH 1030
240 #define WCMD_ANYKEY 1031
241 #define WCMD_CONSTITLE 1032
242 #define WCMD_VERSION 1033
243 #define WCMD_MOREPROMPT 1034
245 /* msdn specified max for Win XP */
246 #define MAXSTRING 8192