1999-06-06 17:24:04 +02:00
|
|
|
/*
|
2006-09-04 06:13:08 +02:00
|
|
|
* CMD - Wine-compatible command line interface.
|
1999-06-06 17:24:04 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* Copyright (C) 1999 D A Pickles
|
2007-09-11 22:43:08 +02:00
|
|
|
* Copyright (C) 2007 J Edmeades
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-06-06 17:24:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define IDI_ICON1 1
|
|
|
|
#include <windows.h>
|
2009-07-02 00:28:36 +02:00
|
|
|
#include <windef.h>
|
1999-06-06 17:24:04 +02:00
|
|
|
#ifndef RC_INVOKED
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
2007-06-03 23:07:41 +02:00
|
|
|
#include <wine/unicode.h>
|
1999-06-06 17:24:04 +02:00
|
|
|
|
2011-11-29 23:30:51 +01:00
|
|
|
/* msdn specified max for Win XP */
|
|
|
|
#define MAXSTRING 8192
|
|
|
|
|
2011-09-05 17:57:54 +02:00
|
|
|
/* Data structure to hold commands delimitors/separators */
|
2007-06-15 21:59:20 +02:00
|
|
|
|
2008-03-04 00:14:29 +01:00
|
|
|
typedef enum _CMDdelimiters {
|
|
|
|
CMD_NONE, /* End of line or single & */
|
|
|
|
CMD_ONFAILURE, /* || */
|
|
|
|
CMD_ONSUCCESS, /* && */
|
2011-07-21 15:28:27 +02:00
|
|
|
CMD_PIPE /* Single | */
|
2008-03-04 00:14:29 +01:00
|
|
|
} CMD_DELIMITERS;
|
|
|
|
|
2011-09-05 17:57:54 +02:00
|
|
|
/* Data structure to hold commands to be processed */
|
|
|
|
|
2007-06-15 21:59:20 +02:00
|
|
|
typedef struct _CMD_LIST {
|
|
|
|
WCHAR *command; /* Command string to execute */
|
2007-09-11 22:43:08 +02:00
|
|
|
WCHAR *redirects; /* Redirects in place */
|
2007-06-15 21:59:20 +02:00
|
|
|
struct _CMD_LIST *nextcommand; /* Next command string to execute */
|
2008-03-04 00:14:29 +01:00
|
|
|
CMD_DELIMITERS prevDelim; /* Previous delimiter */
|
2007-06-15 21:59:20 +02:00
|
|
|
int bracketDepth;/* How deep bracketing have we got to */
|
2008-03-04 00:14:29 +01:00
|
|
|
WCHAR pipeFile[MAX_PATH]; /* Where to get input from for pipes */
|
2007-06-15 21:59:20 +02:00
|
|
|
} CMD_LIST;
|
|
|
|
|
2011-08-20 01:58:59 +02:00
|
|
|
void WCMD_assoc (const WCHAR *, BOOL);
|
2012-03-29 18:05:59 +02:00
|
|
|
void WCMD_batch (WCHAR *, WCHAR *, BOOL, WCHAR *, HANDLE);
|
2007-06-03 23:07:42 +02:00
|
|
|
void WCMD_call (WCHAR *command);
|
1999-06-06 17:24:04 +02:00
|
|
|
void WCMD_change_tty (void);
|
2011-08-20 01:58:59 +02:00
|
|
|
void WCMD_choice (const WCHAR *);
|
1999-06-06 17:24:04 +02:00
|
|
|
void WCMD_clear_screen (void);
|
2007-03-08 01:37:44 +01:00
|
|
|
void WCMD_color (void);
|
2012-10-08 22:25:58 +02:00
|
|
|
void WCMD_copy (WCHAR *);
|
2011-08-02 22:02:19 +02:00
|
|
|
void WCMD_create_dir (WCHAR *);
|
2011-06-02 04:12:56 +02:00
|
|
|
BOOL WCMD_delete (WCHAR *);
|
2007-06-03 23:07:42 +02:00
|
|
|
void WCMD_directory (WCHAR *);
|
|
|
|
void WCMD_echo (const WCHAR *);
|
2004-03-22 23:56:58 +01:00
|
|
|
void WCMD_endlocal (void);
|
2007-06-03 23:07:42 +02:00
|
|
|
void WCMD_enter_paged_mode(const WCHAR *);
|
2007-06-15 21:59:24 +02:00
|
|
|
void WCMD_exit (CMD_LIST **cmdList);
|
2007-06-15 21:59:21 +02:00
|
|
|
void WCMD_for (WCHAR *, CMD_LIST **cmdList);
|
2012-10-17 00:41:58 +02:00
|
|
|
void WCMD_give_help (const WCHAR *args);
|
2007-06-15 21:59:22 +02:00
|
|
|
void WCMD_goto (CMD_LIST **cmdList);
|
2007-06-15 21:59:21 +02:00
|
|
|
void WCMD_if (WCHAR *, CMD_LIST **cmdList);
|
2003-02-25 04:58:42 +01:00
|
|
|
void WCMD_leave_paged_mode(void);
|
2007-06-03 23:07:42 +02:00
|
|
|
void WCMD_more (WCHAR *);
|
1999-06-06 17:24:04 +02:00
|
|
|
void WCMD_move (void);
|
2011-12-06 17:40:42 +01:00
|
|
|
WCHAR* CDECL WCMD_format_string (const WCHAR *format, ...);
|
|
|
|
void CDECL WCMD_output (const WCHAR *format, ...);
|
|
|
|
void CDECL WCMD_output_stderr (const WCHAR *format, ...);
|
2007-06-03 23:07:42 +02:00
|
|
|
void WCMD_output_asis (const WCHAR *message);
|
2011-08-29 21:45:14 +02:00
|
|
|
void WCMD_output_asis_stderr (const WCHAR *message);
|
1999-06-06 17:24:04 +02:00
|
|
|
void WCMD_pause (void);
|
2007-02-23 23:17:28 +01:00
|
|
|
void WCMD_popd (void);
|
1999-06-06 17:24:04 +02:00
|
|
|
void WCMD_print_error (void);
|
2012-10-17 00:41:58 +02:00
|
|
|
void WCMD_pushd (const WCHAR *args);
|
2007-06-03 23:07:42 +02:00
|
|
|
void WCMD_remove_dir (WCHAR *command);
|
1999-06-06 17:24:04 +02:00
|
|
|
void WCMD_rename (void);
|
2012-03-29 18:05:59 +02:00
|
|
|
void WCMD_run_program (WCHAR *command, BOOL called);
|
2012-10-17 00:41:58 +02:00
|
|
|
void WCMD_setlocal (const WCHAR *args);
|
1999-06-06 17:24:04 +02:00
|
|
|
void WCMD_setshow_date (void);
|
2012-10-17 00:41:58 +02:00
|
|
|
void WCMD_setshow_default (const WCHAR *args);
|
2007-06-03 23:07:42 +02:00
|
|
|
void WCMD_setshow_env (WCHAR *command);
|
2012-10-17 00:41:58 +02:00
|
|
|
void WCMD_setshow_path (const WCHAR *args);
|
1999-06-06 17:24:04 +02:00
|
|
|
void WCMD_setshow_prompt (void);
|
|
|
|
void WCMD_setshow_time (void);
|
2012-10-17 00:41:58 +02:00
|
|
|
void WCMD_shift (const WCHAR *args);
|
|
|
|
void WCMD_start (const WCHAR *args);
|
2011-08-20 01:58:59 +02:00
|
|
|
void WCMD_title (const WCHAR *);
|
2007-06-03 23:07:42 +02:00
|
|
|
void WCMD_type (WCHAR *);
|
2012-10-17 00:41:58 +02:00
|
|
|
void WCMD_verify (const WCHAR *args);
|
1999-06-06 17:24:04 +02:00
|
|
|
void WCMD_version (void);
|
2012-10-17 00:41:58 +02:00
|
|
|
int WCMD_volume (BOOL set_label, const WCHAR *args);
|
2007-06-03 23:07:42 +02:00
|
|
|
|
2011-10-06 18:50:31 +02:00
|
|
|
static inline BOOL WCMD_is_console_handle(HANDLE h)
|
|
|
|
{
|
|
|
|
return (((DWORD_PTR)h) & 3) == 3;
|
|
|
|
}
|
2011-11-07 10:52:22 +01:00
|
|
|
WCHAR *WCMD_fgets (WCHAR *buf, DWORD n, HANDLE stream);
|
2012-10-17 00:35:33 +02:00
|
|
|
WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **start, WCHAR **end, BOOL raw, BOOL wholecmdline);
|
2011-08-20 01:58:58 +02:00
|
|
|
WCHAR *WCMD_skip_leading_spaces (WCHAR *string);
|
2011-08-25 00:48:18 +02:00
|
|
|
BOOL WCMD_keyword_ws_found(const WCHAR *keyword, int len, const WCHAR *ptr);
|
2011-08-20 01:58:59 +02:00
|
|
|
void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable, const WCHAR *forValue, BOOL justFors);
|
2007-06-03 23:07:42 +02:00
|
|
|
|
|
|
|
void WCMD_splitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext);
|
2011-10-19 09:47:58 +02:00
|
|
|
void WCMD_strip_quotes(WCHAR *cmd);
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR *WCMD_LoadMessage(UINT id);
|
2011-08-20 01:58:59 +02:00
|
|
|
WCHAR *WCMD_strdupW(const WCHAR *input);
|
|
|
|
void WCMD_strsubstW(WCHAR *start, const WCHAR* next, const WCHAR* insert, int len);
|
2011-09-28 14:41:22 +02:00
|
|
|
BOOL WCMD_ReadFile(const HANDLE hIn, WCHAR *intoBuf, const DWORD maxChars, LPDWORD charsRead);
|
1999-06-26 12:24:08 +02:00
|
|
|
|
2011-10-06 18:50:31 +02:00
|
|
|
WCHAR *WCMD_ReadAndParseLine(const WCHAR *initialcmd, CMD_LIST **output, HANDLE readFrom);
|
2011-08-20 01:58:59 +02:00
|
|
|
CMD_LIST *WCMD_process_commands(CMD_LIST *thisCmd, BOOL oneBracket,
|
2012-10-14 01:38:53 +02:00
|
|
|
const WCHAR *var, const WCHAR *val, BOOL retrycall);
|
2007-06-15 21:59:28 +02:00
|
|
|
void WCMD_free_commands(CMD_LIST *cmds);
|
2011-08-20 01:58:59 +02:00
|
|
|
void WCMD_execute (const WCHAR *orig_command, const WCHAR *redirects,
|
|
|
|
const WCHAR *parameter, const WCHAR *substitution,
|
2012-10-14 01:38:53 +02:00
|
|
|
CMD_LIST **cmdList, BOOL retrycall);
|
2007-06-15 21:59:19 +02:00
|
|
|
|
2011-09-05 17:57:54 +02:00
|
|
|
/* Data structure to hold context when executing batch files */
|
1999-06-26 12:24:08 +02:00
|
|
|
|
2011-09-07 11:00:53 +02:00
|
|
|
typedef struct _BATCH_CONTEXT {
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR *command; /* The command which invoked the batch file */
|
1999-06-26 12:24:08 +02:00
|
|
|
HANDLE h; /* Handle to the open batch file */
|
2010-02-03 01:56:38 +01:00
|
|
|
WCHAR *batchfileW; /* Name of same */
|
2007-03-08 01:50:37 +01:00
|
|
|
int shift_count[10]; /* Offset in terms of shifts for %0 - %9 */
|
2011-09-07 11:00:53 +02:00
|
|
|
struct _BATCH_CONTEXT *prev_context; /* Pointer to the previous context block */
|
2007-02-20 18:49:08 +01:00
|
|
|
BOOL skip_rest; /* Skip the rest of the batch program and exit */
|
2007-06-15 21:59:19 +02:00
|
|
|
CMD_LIST *toExecute; /* Commands left to be executed */
|
1999-06-26 12:24:08 +02:00
|
|
|
} BATCH_CONTEXT;
|
|
|
|
|
2011-09-05 17:57:54 +02:00
|
|
|
/* Data structure to handle building lists during recursive calls */
|
2007-03-04 23:34:20 +01:00
|
|
|
|
|
|
|
struct env_stack
|
|
|
|
{
|
|
|
|
struct env_stack *next;
|
2007-03-08 01:48:49 +01:00
|
|
|
union {
|
|
|
|
int stackdepth; /* Only used for pushd and popd */
|
2012-10-01 00:07:01 +02:00
|
|
|
WCHAR cwd; /* Only used for set/endlocal */
|
2007-03-12 10:35:13 +01:00
|
|
|
} u;
|
2007-03-04 23:34:20 +01:00
|
|
|
WCHAR *strings;
|
2012-10-01 00:07:01 +02:00
|
|
|
HANDLE batchhandle; /* Used to ensure set/endlocals stay in scope */
|
2007-03-04 23:34:20 +01:00
|
|
|
};
|
|
|
|
|
2011-09-05 17:57:54 +02:00
|
|
|
/* Data structure to save setlocal and pushd information */
|
2007-04-24 00:24:38 +02:00
|
|
|
|
|
|
|
typedef struct _DIRECTORY_STACK
|
|
|
|
{
|
|
|
|
struct _DIRECTORY_STACK *next;
|
2007-06-03 23:07:42 +02:00
|
|
|
WCHAR *dirName;
|
|
|
|
WCHAR *fileName;
|
2007-04-24 00:24:38 +02:00
|
|
|
} DIRECTORY_STACK;
|
|
|
|
|
2011-11-29 23:30:51 +01:00
|
|
|
/*
|
|
|
|
* Global variables quals, param1, param2 contain the current qualifiers
|
|
|
|
* (uppercased and concatenated) and parameters entered, with environment
|
|
|
|
* variables and batch parameters substitution already done.
|
|
|
|
*/
|
|
|
|
extern WCHAR quals[MAX_PATH], param1[MAXSTRING], param2[MAXSTRING];
|
|
|
|
extern DWORD errorlevel;
|
|
|
|
extern BATCH_CONTEXT *context;
|
|
|
|
|
1999-06-06 17:24:04 +02:00
|
|
|
#endif /* !RC_INVOKED */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Serial nos of builtin commands. These constants must be in step with
|
2011-07-27 02:21:01 +02:00
|
|
|
* the list of strings defined in wcmd.rc, and WCMD_EXIT *must* always be
|
1999-06-06 17:24:04 +02:00
|
|
|
* the last one.
|
|
|
|
*
|
|
|
|
* Yes it *would* be nice to use an enumeration here, but the Resource
|
|
|
|
* Compiler won't accept resource IDs from enumerations :-(
|
|
|
|
*/
|
|
|
|
|
2011-09-07 09:09:59 +02:00
|
|
|
#define WCMD_CALL 0
|
|
|
|
#define WCMD_CD 1
|
|
|
|
#define WCMD_CHDIR 2
|
|
|
|
#define WCMD_CLS 3
|
|
|
|
#define WCMD_COPY 4
|
|
|
|
#define WCMD_CTTY 5
|
|
|
|
#define WCMD_DATE 6
|
|
|
|
#define WCMD_DEL 7
|
|
|
|
#define WCMD_DIR 8
|
|
|
|
#define WCMD_ECHO 9
|
|
|
|
#define WCMD_ERASE 10
|
|
|
|
#define WCMD_FOR 11
|
|
|
|
#define WCMD_GOTO 12
|
|
|
|
#define WCMD_HELP 13
|
|
|
|
#define WCMD_IF 14
|
|
|
|
#define WCMD_LABEL 15
|
|
|
|
#define WCMD_MD 16
|
|
|
|
#define WCMD_MKDIR 17
|
|
|
|
#define WCMD_MOVE 18
|
|
|
|
#define WCMD_PATH 19
|
|
|
|
#define WCMD_PAUSE 20
|
|
|
|
#define WCMD_PROMPT 21
|
|
|
|
#define WCMD_REM 22
|
|
|
|
#define WCMD_REN 23
|
|
|
|
#define WCMD_RENAME 24
|
|
|
|
#define WCMD_RD 25
|
|
|
|
#define WCMD_RMDIR 26
|
|
|
|
#define WCMD_SET 27
|
|
|
|
#define WCMD_SHIFT 28
|
2012-02-11 16:05:59 +01:00
|
|
|
#define WCMD_START 29
|
|
|
|
#define WCMD_TIME 30
|
|
|
|
#define WCMD_TITLE 31
|
|
|
|
#define WCMD_TYPE 32
|
|
|
|
#define WCMD_VERIFY 33
|
|
|
|
#define WCMD_VER 34
|
|
|
|
#define WCMD_VOL 35
|
|
|
|
|
|
|
|
#define WCMD_ENDLOCAL 36
|
|
|
|
#define WCMD_SETLOCAL 37
|
|
|
|
#define WCMD_PUSHD 38
|
|
|
|
#define WCMD_POPD 39
|
|
|
|
#define WCMD_ASSOC 40
|
|
|
|
#define WCMD_COLOR 41
|
|
|
|
#define WCMD_FTYPE 42
|
|
|
|
#define WCMD_MORE 43
|
|
|
|
#define WCMD_CHOICE 44
|
2004-03-22 23:56:58 +01:00
|
|
|
|
2002-05-04 20:29:31 +02:00
|
|
|
/* Must be last in list */
|
2012-02-11 16:05:59 +01:00
|
|
|
#define WCMD_EXIT 45
|
2004-05-04 06:13:05 +02:00
|
|
|
|
|
|
|
/* Some standard messages */
|
2012-02-11 18:24:56 +01:00
|
|
|
extern const WCHAR newlineW[];
|
|
|
|
extern const WCHAR spaceW[];
|
2011-11-12 13:58:01 +01:00
|
|
|
extern const WCHAR nullW[];
|
|
|
|
extern const WCHAR dotW[];
|
|
|
|
extern const WCHAR dotdotW[];
|
|
|
|
extern const WCHAR starW[];
|
|
|
|
extern const WCHAR slashW[];
|
|
|
|
extern const WCHAR equalW[];
|
2007-06-03 23:07:42 +02:00
|
|
|
extern WCHAR anykey[];
|
|
|
|
extern WCHAR version_string[];
|
2007-02-23 23:21:27 +01:00
|
|
|
|
2007-02-28 00:18:57 +01:00
|
|
|
/* Translated messages */
|
2007-06-03 23:07:43 +02:00
|
|
|
#define WCMD_ALLHELP 1000
|
2007-06-03 23:07:39 +02:00
|
|
|
#define WCMD_CONFIRM 1001
|
|
|
|
#define WCMD_YES 1002
|
|
|
|
#define WCMD_NO 1003
|
|
|
|
#define WCMD_NOASSOC 1004
|
|
|
|
#define WCMD_NOFTYPE 1005
|
|
|
|
#define WCMD_OVERWRITE 1006
|
|
|
|
#define WCMD_MORESTR 1007
|
|
|
|
#define WCMD_TRUNCATEDLINE 1008
|
|
|
|
#define WCMD_NYI 1009
|
|
|
|
#define WCMD_NOARG 1010
|
|
|
|
#define WCMD_SYNTAXERR 1011
|
|
|
|
#define WCMD_FILENOTFOUND 1012
|
|
|
|
#define WCMD_NOCMDHELP 1013
|
|
|
|
#define WCMD_NOTARGET 1014
|
|
|
|
#define WCMD_CURRENTDATE 1015
|
|
|
|
#define WCMD_CURRENTTIME 1016
|
|
|
|
#define WCMD_NEWDATE 1017
|
|
|
|
#define WCMD_NEWTIME 1018
|
|
|
|
#define WCMD_MISSINGENV 1019
|
|
|
|
#define WCMD_READFAIL 1020
|
|
|
|
#define WCMD_CALLINSCRIPT 1021
|
|
|
|
#define WCMD_ALL 1022
|
|
|
|
#define WCMD_DELPROMPT 1023
|
|
|
|
#define WCMD_ECHOPROMPT 1024
|
|
|
|
#define WCMD_VERIFYPROMPT 1025
|
|
|
|
#define WCMD_VERIFYERR 1026
|
|
|
|
#define WCMD_ARGERR 1027
|
2011-12-14 13:22:58 +01:00
|
|
|
#define WCMD_VOLUMESERIALNO 1028
|
2007-06-03 23:07:39 +02:00
|
|
|
#define WCMD_VOLUMEPROMPT 1029
|
2007-06-03 23:07:42 +02:00
|
|
|
#define WCMD_NOPATH 1030
|
|
|
|
#define WCMD_ANYKEY 1031
|
|
|
|
#define WCMD_CONSTITLE 1032
|
|
|
|
#define WCMD_VERSION 1033
|
2007-06-15 21:59:19 +02:00
|
|
|
#define WCMD_MOREPROMPT 1034
|
2009-03-02 19:45:50 +01:00
|
|
|
#define WCMD_LINETOOLONG 1035
|
2011-12-14 13:22:58 +01:00
|
|
|
#define WCMD_VOLUMELABEL 1036
|
|
|
|
#define WCMD_VOLUMENOLABEL 1037
|
2012-01-23 17:37:47 +01:00
|
|
|
#define WCMD_YESNO 1038
|
|
|
|
#define WCMD_YESNOALL 1039
|