cmd: Constify some function parameters.

This commit is contained in:
Frédéric Delanoy 2011-08-20 01:58:59 +02:00 committed by Alexandre Julliard
parent bb47576f59
commit ff501904a7
5 changed files with 54 additions and 46 deletions

View File

@ -291,7 +291,8 @@ void WCMD_splitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHA
* Hence search forwards until find an invalid modifier, and then * Hence search forwards until find an invalid modifier, and then
* backwards until find for variable or 0-9 * backwards until find for variable or 0-9
*/ */
void WCMD_HandleTildaModifiers(WCHAR **start, WCHAR *forVariable, WCHAR *forValue, BOOL justFors) { void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable,
const WCHAR *forValue, BOOL justFors) {
#define NUMMODIFIERS 11 #define NUMMODIFIERS 11
static const WCHAR validmodifiers[NUMMODIFIERS] = { static const WCHAR validmodifiers[NUMMODIFIERS] = {

View File

@ -41,8 +41,9 @@
WINE_DEFAULT_DEBUG_CHANNEL(cmd); WINE_DEFAULT_DEBUG_CHANNEL(cmd);
static void WCMD_part_execute(CMD_LIST **commands, WCHAR *firstcmd, WCHAR *variable, static void WCMD_part_execute(CMD_LIST **commands, const WCHAR *firstcmd,
WCHAR *value, BOOL isIF, BOOL conditionTRUE); const WCHAR *variable, const WCHAR *value,
BOOL isIF, BOOL conditionTRUE);
struct env_stack *saved_environment; struct env_stack *saved_environment;
struct env_stack *pushd_directories; struct env_stack *pushd_directories;
@ -77,7 +78,8 @@ static const WCHAR nullW[] = {'\0'};
* set to TRUE * set to TRUE
* *
*/ */
static BOOL WCMD_ask_confirm (WCHAR *message, BOOL showSureText, BOOL *optionAll) { static BOOL WCMD_ask_confirm (const WCHAR *message, BOOL showSureText,
const BOOL *optionAll) {
WCHAR msgbuffer[MAXSTRING]; WCHAR msgbuffer[MAXSTRING];
WCHAR Ybuffer[MAXSTRING]; WCHAR Ybuffer[MAXSTRING];
@ -164,7 +166,7 @@ void WCMD_change_tty (void) {
* *
*/ */
void WCMD_choice (WCHAR * command) { void WCMD_choice (const WCHAR * command) {
static const WCHAR bellW[] = {7,0}; static const WCHAR bellW[] = {7,0};
static const WCHAR commaW[] = {',',0}; static const WCHAR commaW[] = {',',0};
@ -186,7 +188,7 @@ void WCMD_choice (WCHAR * command) {
have_console = GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &oldmode); have_console = GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &oldmode);
errorlevel = 0; errorlevel = 0;
my_command = WCMD_strdupW(WCMD_skip_leading_spaces(command)); my_command = WCMD_strdupW(WCMD_skip_leading_spaces((WCHAR*) command));
if (!my_command) if (!my_command)
return; return;
@ -587,7 +589,7 @@ static void WCMD_delete_parse_attributes(DWORD *wantSet, DWORD *wantClear) {
* *pPrompted is set to TRUE if the user is prompted. * *pPrompted is set to TRUE if the user is prompted.
* (If /P supplied, del will prompt for individual files later.) * (If /P supplied, del will prompt for individual files later.)
*/ */
static BOOL WCMD_delete_confirm_wildcard(WCHAR *filename, BOOL *pPrompted) { static BOOL WCMD_delete_confirm_wildcard(const WCHAR *filename, BOOL *pPrompted) {
static const WCHAR parmP[] = {'/','P','\0'}; static const WCHAR parmP[] = {'/','P','\0'};
static const WCHAR parmQ[] = {'/','Q','\0'}; static const WCHAR parmQ[] = {'/','Q','\0'};
@ -627,7 +629,7 @@ static BOOL WCMD_delete_confirm_wildcard(WCHAR *filename, BOOL *pPrompted) {
* If /S was given, does it recursively. * If /S was given, does it recursively.
* Returns TRUE if a file was deleted. * Returns TRUE if a file was deleted.
*/ */
static BOOL WCMD_delete_one (WCHAR *thisArg) { static BOOL WCMD_delete_one (const WCHAR *thisArg) {
static const WCHAR parmP[] = {'/','P','\0'}; static const WCHAR parmP[] = {'/','P','\0'};
static const WCHAR parmS[] = {'/','S','\0'}; static const WCHAR parmS[] = {'/','S','\0'};
@ -1215,8 +1217,9 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
* first command to be executed may not be at the front of the * first command to be executed may not be at the front of the
* commands->thiscommand string (eg. it may point after a DO or ELSE) * commands->thiscommand string (eg. it may point after a DO or ELSE)
*/ */
void WCMD_part_execute(CMD_LIST **cmdList, WCHAR *firstcmd, WCHAR *variable, static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
WCHAR *value, BOOL isIF, BOOL conditionTRUE) { const WCHAR *variable, const WCHAR *value,
BOOL isIF, BOOL conditionTRUE) {
CMD_LIST *curPosition = *cmdList; CMD_LIST *curPosition = *cmdList;
int myDepth = (*cmdList)->bracketDepth; int myDepth = (*cmdList)->bracketDepth;
@ -1311,11 +1314,11 @@ void WCMD_part_execute(CMD_LIST **cmdList, WCHAR *firstcmd, WCHAR *variable,
* Simple on-line help. Help text is stored in the resource file. * Simple on-line help. Help text is stored in the resource file.
*/ */
void WCMD_give_help (WCHAR *command) { void WCMD_give_help (const WCHAR *command) {
int i; int i;
command = WCMD_skip_leading_spaces(command); command = WCMD_skip_leading_spaces((WCHAR*) command);
if (strlenW(command) == 0) { if (strlenW(command) == 0) {
WCMD_output_asis (WCMD_LoadMessage(WCMD_ALLHELP)); WCMD_output_asis (WCMD_LoadMessage(WCMD_ALLHELP));
} }
@ -2077,7 +2080,7 @@ void WCMD_setshow_attrib (void) {
* Set/Show the current default directory * Set/Show the current default directory
*/ */
void WCMD_setshow_default (WCHAR *command) { void WCMD_setshow_default (const WCHAR *command) {
BOOL status; BOOL status;
WCHAR string[1024]; WCHAR string[1024];
@ -2361,7 +2364,7 @@ void WCMD_setshow_env (WCHAR *s) {
* Set/Show the path environment variable * Set/Show the path environment variable
*/ */
void WCMD_setshow_path (WCHAR *command) { void WCMD_setshow_path (const WCHAR *command) {
WCHAR string[1024]; WCHAR string[1024];
DWORD status; DWORD status;
@ -2452,7 +2455,7 @@ void WCMD_setshow_time (void) {
* Optional /n says where to start shifting (n=0-8) * Optional /n says where to start shifting (n=0-8)
*/ */
void WCMD_shift (WCHAR *command) { void WCMD_shift (const WCHAR *command) {
int start; int start;
if (context != NULL) { if (context != NULL) {
@ -2483,7 +2486,7 @@ void WCMD_shift (WCHAR *command) {
* *
* Set the console title * Set the console title
*/ */
void WCMD_title (WCHAR *command) { void WCMD_title (const WCHAR *command) {
SetConsoleTitleW(command); SetConsoleTitleW(command);
} }
@ -2663,7 +2666,7 @@ void WCMD_more (WCHAR *command) {
* it... * it...
*/ */
void WCMD_verify (WCHAR *command) { void WCMD_verify (const WCHAR *command) {
int count; int count;
@ -2702,7 +2705,7 @@ void WCMD_version (void) {
* Display volume info and/or set volume label. Returns 0 if error. * Display volume info and/or set volume label. Returns 0 if error.
*/ */
int WCMD_volume (int mode, WCHAR *path) { int WCMD_volume (int mode, const WCHAR *path) {
DWORD count, serial; DWORD count, serial;
WCHAR string[MAX_PATH], label[MAX_PATH], curdir[MAX_PATH]; WCHAR string[MAX_PATH], label[MAX_PATH], curdir[MAX_PATH];
@ -2780,7 +2783,7 @@ void WCMD_exit (CMD_LIST **cmdList) {
* Lists or sets file associations (assoc = TRUE) * Lists or sets file associations (assoc = TRUE)
* Lists or sets file types (assoc = FALSE) * Lists or sets file types (assoc = FALSE)
*/ */
void WCMD_assoc (WCHAR *command, BOOL assoc) { void WCMD_assoc (const WCHAR *command, BOOL assoc) {
HKEY key; HKEY key;
DWORD accessOptions = KEY_READ; DWORD accessOptions = KEY_READ;

View File

@ -283,7 +283,7 @@ cleanup:
HeapFree(GetProcessHeap(), 0, (LPVOID)actual_cmd_data); HeapFree(GetProcessHeap(), 0, (LPVOID)actual_cmd_data);
} }
static void run_from_file(char *file_name) static void run_from_file(const char *file_name)
{ {
char out_name[MAX_PATH]; char out_name[MAX_PATH];
const char *test_data, *out_data; const char *test_data, *out_data;

View File

@ -48,11 +48,11 @@ typedef struct _CMD_LIST {
WCHAR pipeFile[MAX_PATH]; /* Where to get input from for pipes */ WCHAR pipeFile[MAX_PATH]; /* Where to get input from for pipes */
} CMD_LIST; } CMD_LIST;
void WCMD_assoc (WCHAR *, BOOL); void WCMD_assoc (const WCHAR *, BOOL);
void WCMD_batch (WCHAR *, WCHAR *, int, WCHAR *, HANDLE); void WCMD_batch (WCHAR *, WCHAR *, int, WCHAR *, HANDLE);
void WCMD_call (WCHAR *command); void WCMD_call (WCHAR *command);
void WCMD_change_tty (void); void WCMD_change_tty (void);
void WCMD_choice (WCHAR *); void WCMD_choice (const WCHAR *);
void WCMD_clear_screen (void); void WCMD_clear_screen (void);
void WCMD_color (void); void WCMD_color (void);
void WCMD_copy (void); void WCMD_copy (void);
@ -64,7 +64,7 @@ void WCMD_endlocal (void);
void WCMD_enter_paged_mode(const WCHAR *); void WCMD_enter_paged_mode(const WCHAR *);
void WCMD_exit (CMD_LIST **cmdList); void WCMD_exit (CMD_LIST **cmdList);
void WCMD_for (WCHAR *, CMD_LIST **cmdList); void WCMD_for (WCHAR *, CMD_LIST **cmdList);
void WCMD_give_help (WCHAR *command); void WCMD_give_help (const WCHAR *command);
void WCMD_goto (CMD_LIST **cmdList); void WCMD_goto (CMD_LIST **cmdList);
void WCMD_if (WCHAR *, CMD_LIST **cmdList); void WCMD_if (WCHAR *, CMD_LIST **cmdList);
void WCMD_leave_paged_mode(void); void WCMD_leave_paged_mode(void);
@ -82,36 +82,38 @@ void WCMD_run_program (WCHAR *command, int called);
void WCMD_setlocal (const WCHAR *command); void WCMD_setlocal (const WCHAR *command);
void WCMD_setshow_attrib (void); void WCMD_setshow_attrib (void);
void WCMD_setshow_date (void); void WCMD_setshow_date (void);
void WCMD_setshow_default (WCHAR *command); void WCMD_setshow_default (const WCHAR *command);
void WCMD_setshow_env (WCHAR *command); void WCMD_setshow_env (WCHAR *command);
void WCMD_setshow_path (WCHAR *command); void WCMD_setshow_path (const WCHAR *command);
void WCMD_setshow_prompt (void); void WCMD_setshow_prompt (void);
void WCMD_setshow_time (void); void WCMD_setshow_time (void);
void WCMD_shift (WCHAR *command); void WCMD_shift (const WCHAR *command);
void WCMD_title (WCHAR *); void WCMD_title (const WCHAR *);
void WCMD_type (WCHAR *); void WCMD_type (WCHAR *);
void WCMD_verify (WCHAR *command); void WCMD_verify (const WCHAR *command);
void WCMD_version (void); void WCMD_version (void);
int WCMD_volume (int mode, WCHAR *command); int WCMD_volume (int mode, const WCHAR *command);
WCHAR *WCMD_fgets (WCHAR *s, int n, HANDLE stream); WCHAR *WCMD_fgets (WCHAR *s, int n, HANDLE stream);
WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where); WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where);
WCHAR *WCMD_skip_leading_spaces (WCHAR *string); WCHAR *WCMD_skip_leading_spaces (WCHAR *string);
void WCMD_HandleTildaModifiers(WCHAR **start, WCHAR *forVariable, WCHAR *forValue, BOOL justFors); void WCMD_HandleTildaModifiers(WCHAR **start, const WCHAR *forVariable, const WCHAR *forValue, BOOL justFors);
void WCMD_splitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext); void WCMD_splitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext);
void WCMD_opt_s_strip_quotes(WCHAR *cmd); void WCMD_opt_s_strip_quotes(WCHAR *cmd);
WCHAR *WCMD_LoadMessage(UINT id); WCHAR *WCMD_LoadMessage(UINT id);
WCHAR *WCMD_strdupW(WCHAR *input); WCHAR *WCMD_strdupW(const WCHAR *input);
void WCMD_strsubstW(WCHAR *start, WCHAR* next, WCHAR* insert, int len); void WCMD_strsubstW(WCHAR *start, const WCHAR* next, const WCHAR* insert, int len);
BOOL WCMD_ReadFile(const HANDLE hIn, WCHAR *intoBuf, const DWORD maxChars, BOOL WCMD_ReadFile(const HANDLE hIn, WCHAR *intoBuf, const DWORD maxChars,
LPDWORD charsRead, const LPOVERLAPPED unused); LPDWORD charsRead, const LPOVERLAPPED unused);
WCHAR *WCMD_ReadAndParseLine(WCHAR *initialcmd, CMD_LIST **output, HANDLE readFrom); WCHAR *WCMD_ReadAndParseLine(const WCHAR *initialcmd, CMD_LIST **output, HANDLE readFrom);
CMD_LIST *WCMD_process_commands(CMD_LIST *thisCmd, BOOL oneBracket, WCHAR *var, WCHAR *val); CMD_LIST *WCMD_process_commands(CMD_LIST *thisCmd, BOOL oneBracket,
const WCHAR *var, const WCHAR *val);
void WCMD_free_commands(CMD_LIST *cmds); void WCMD_free_commands(CMD_LIST *cmds);
void WCMD_execute (WCHAR *orig_command, WCHAR *redirects, WCHAR *parameter, void WCMD_execute (const WCHAR *orig_command, const WCHAR *redirects,
WCHAR *substitution, CMD_LIST **cmdList); const WCHAR *parameter, const WCHAR *substitution,
CMD_LIST **cmdList);
/* Data structure to hold context when executing batch files */ /* Data structure to hold context when executing batch files */

View File

@ -417,7 +417,7 @@ static void WCMD_show_prompt (void) {
* WCMD_strdupW * WCMD_strdupW
* A wide version of strdup as its missing from unicode.h * A wide version of strdup as its missing from unicode.h
*/ */
WCHAR *WCMD_strdupW(WCHAR *input) { WCHAR *WCMD_strdupW(const WCHAR *input) {
int len=strlenW(input)+1; int len=strlenW(input)+1;
WCHAR *result = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); WCHAR *result = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
memcpy(result, input, len * sizeof(WCHAR)); memcpy(result, input, len * sizeof(WCHAR));
@ -430,7 +430,7 @@ WCHAR *WCMD_strdupW(WCHAR *input) {
* It's up to the caller to ensure there is enough space in the * It's up to the caller to ensure there is enough space in the
* destination buffer. * destination buffer.
*/ */
void WCMD_strsubstW(WCHAR* start, WCHAR* next, WCHAR* insert, int len) { void WCMD_strsubstW(WCHAR *start, const WCHAR *next, const WCHAR *insert, int len) {
if (len < 0) if (len < 0)
len=insert ? lstrlenW(insert) : 0; len=insert ? lstrlenW(insert) : 0;
@ -511,7 +511,8 @@ static inline BOOL WCMD_is_magic_envvar(const WCHAR *s, const WCHAR *magicvar)
* *
* Expands environment variables, allowing for WCHARacter substitution * Expands environment variables, allowing for WCHARacter substitution
*/ */
static WCHAR *WCMD_expand_envvar(WCHAR *start, WCHAR *forVar, WCHAR *forVal) { static WCHAR *WCMD_expand_envvar(WCHAR *start,
const WCHAR *forVar, const WCHAR *forVal) {
WCHAR *endOfVar = NULL, *s; WCHAR *endOfVar = NULL, *s;
WCHAR *colonpos = NULL; WCHAR *colonpos = NULL;
WCHAR thisVar[MAXSTRING]; WCHAR thisVar[MAXSTRING];
@ -765,7 +766,8 @@ static WCHAR *WCMD_expand_envvar(WCHAR *start, WCHAR *forVar, WCHAR *forVal) {
* read in and not again, except for 'for' variable substitution. * read in and not again, except for 'for' variable substitution.
* eg. As evidence, "echo %1 && shift && echo %1" or "echo %%path%%" * eg. As evidence, "echo %1 && shift && echo %1" or "echo %%path%%"
*/ */
static void handleExpansion(WCHAR *cmd, BOOL justFors, WCHAR *forVariable, WCHAR *forValue) { static void handleExpansion(WCHAR *cmd, BOOL justFors,
const WCHAR *forVariable, const WCHAR *forValue) {
/* For commands in a context (batch program): */ /* For commands in a context (batch program): */
/* Expand environment variables in a batch file %{0-9} first */ /* Expand environment variables in a batch file %{0-9} first */
@ -841,7 +843,7 @@ static void handleExpansion(WCHAR *cmd, BOOL justFors, WCHAR *forVariable, WCHAR
* second in p2. Any subsequent non-qualifier strings are lost. * second in p2. Any subsequent non-qualifier strings are lost.
* Parameters in quotes are handled. * Parameters in quotes are handled.
*/ */
static void WCMD_parse (WCHAR *s, WCHAR *q, WCHAR *p1, WCHAR *p2) static void WCMD_parse (const WCHAR *s, WCHAR *q, WCHAR *p1, WCHAR *p2)
{ {
int p = 0; int p = 0;
@ -1191,8 +1193,8 @@ void WCMD_run_program (WCHAR *command, int called) {
* Process one command. If the command is EXIT this routine does not return. * Process one command. If the command is EXIT this routine does not return.
* We will recurse through here executing batch files. * We will recurse through here executing batch files.
*/ */
void WCMD_execute (WCHAR *command, WCHAR *redirects, void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
WCHAR *forVariable, WCHAR *forValue, const WCHAR *forVariable, const WCHAR *forValue,
CMD_LIST **cmdList) CMD_LIST **cmdList)
{ {
WCHAR *cmd, *p, *redir; WCHAR *cmd, *p, *redir;
@ -1673,7 +1675,7 @@ static void WCMD_addCommand(WCHAR *command, int *commandLen,
* Returns TRUE if this is an end quote, and FALSE if it is not. * Returns TRUE if this is an end quote, and FALSE if it is not.
* *
*/ */
static BOOL WCMD_IsEndQuote(WCHAR *quote, int quoteIndex) static BOOL WCMD_IsEndQuote(const WCHAR *quote, int quoteIndex)
{ {
int quoteCount = quoteIndex; int quoteCount = quoteIndex;
int i; int i;
@ -1725,7 +1727,7 @@ static BOOL WCMD_IsEndQuote(WCHAR *quote, int quoteIndex)
* - Anything else gets put into the command string (including * - Anything else gets put into the command string (including
* redirects) * redirects)
*/ */
WCHAR *WCMD_ReadAndParseLine(WCHAR *optionalcmd, CMD_LIST **output, HANDLE readFrom) { WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE readFrom) {
WCHAR *curPos; WCHAR *curPos;
int inQuotes = 0; int inQuotes = 0;
@ -2156,7 +2158,7 @@ WCHAR *WCMD_ReadAndParseLine(WCHAR *optionalcmd, CMD_LIST **output, HANDLE readF
* Process all the commands read in so far * Process all the commands read in so far
*/ */
CMD_LIST *WCMD_process_commands(CMD_LIST *thisCmd, BOOL oneBracket, CMD_LIST *WCMD_process_commands(CMD_LIST *thisCmd, BOOL oneBracket,
WCHAR *var, WCHAR *val) { const WCHAR *var, const WCHAR *val) {
int bdepth = -1; int bdepth = -1;