Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1 | /* |
Dan Kegel | 3985744 | 2006-09-03 21:13:08 -0700 | [diff] [blame] | 2 | * CMD - Wine-compatible command line interface - built-in functions. |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 3 | * |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 4 | * Copyright (C) 1999 D A Pickles |
Jason Edmeades | 1ee7538 | 2007-09-11 21:43:08 +0100 | [diff] [blame] | 5 | * Copyright (C) 2007 J Edmeades |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 6 | * |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 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 |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * NOTES: |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 24 | * On entry to each function, global variables quals, param1, param2 contain |
| 25 | * the qualifiers (uppercased and concatenated) and parameters entered, with |
| 26 | * environment-variable and batch parameter substitution already done. |
| 27 | */ |
| 28 | |
| 29 | /* |
| 30 | * FIXME: |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 31 | * - No support for pipes, shell parameters |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 32 | * - Lots of functionality missing from builtins |
| 33 | * - Messages etc need international support |
| 34 | */ |
| 35 | |
Mike McCormack | 7d66567 | 2006-01-16 20:41:34 +0100 | [diff] [blame] | 36 | #define WIN32_LEAN_AND_MEAN |
| 37 | |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 38 | #include "wcmd.h" |
Jason Edmeades | 69194ce | 2007-02-26 23:04:40 +0000 | [diff] [blame] | 39 | #include <shellapi.h> |
Jason Edmeades | 0efa91d | 2007-03-04 22:33:27 +0000 | [diff] [blame] | 40 | #include "wine/debug.h" |
| 41 | |
| 42 | WINE_DEFAULT_DEBUG_CHANNEL(cmd); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 43 | |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 44 | static void WCMD_part_execute(CMD_LIST **commands, WCHAR *firstcmd, WCHAR *variable, |
| 45 | WCHAR *value, BOOL isIF, BOOL conditionTRUE); |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 46 | |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 47 | struct env_stack *saved_environment; |
Jason Edmeades | 365f86f | 2007-02-23 22:17:28 +0000 | [diff] [blame] | 48 | struct env_stack *pushd_directories; |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 49 | |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 50 | extern HINSTANCE hinst; |
Jason Edmeades | afe4d80 | 2007-06-03 22:07:43 +0100 | [diff] [blame] | 51 | extern WCHAR inbuilt[][10]; |
Jason Edmeades | e37463f | 2007-03-08 00:37:44 +0000 | [diff] [blame] | 52 | extern int echo_mode, verify_mode, defaultColor; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 53 | extern WCHAR quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH]; |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 54 | extern BATCH_CONTEXT *context; |
Dave Pickles | ebecf50 | 2000-08-01 22:02:18 +0000 | [diff] [blame] | 55 | extern DWORD errorlevel; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 56 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 57 | static const WCHAR dotW[] = {'.','\0'}; |
| 58 | static const WCHAR dotdotW[] = {'.','.','\0'}; |
| 59 | static const WCHAR slashW[] = {'\\','\0'}; |
| 60 | static const WCHAR starW[] = {'*','\0'}; |
| 61 | static const WCHAR equalW[] = {'=','\0'}; |
| 62 | static const WCHAR fslashW[] = {'/','\0'}; |
| 63 | static const WCHAR onW[] = {'O','N','\0'}; |
| 64 | static const WCHAR offW[] = {'O','F','F','\0'}; |
| 65 | static const WCHAR parmY[] = {'/','Y','\0'}; |
| 66 | static const WCHAR parmNoY[] = {'/','-','Y','\0'}; |
| 67 | static const WCHAR nullW[] = {'\0'}; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 68 | |
Francois Gouget | e7b1257 | 2009-01-05 19:57:31 +0100 | [diff] [blame] | 69 | /************************************************************************** |
| 70 | * WCMD_ask_confirm |
| 71 | * |
| 72 | * Issue a message and ask 'Are you sure (Y/N)', waiting on a valid |
| 73 | * answer. |
| 74 | * |
| 75 | * Returns True if Y (or A) answer is selected |
| 76 | * If optionAll contains a pointer, ALL is allowed, and if answered |
| 77 | * set to TRUE |
| 78 | * |
| 79 | */ |
| 80 | static BOOL WCMD_ask_confirm (WCHAR *message, BOOL showSureText, BOOL *optionAll) { |
| 81 | |
| 82 | WCHAR msgbuffer[MAXSTRING]; |
| 83 | WCHAR Ybuffer[MAXSTRING]; |
| 84 | WCHAR Nbuffer[MAXSTRING]; |
| 85 | WCHAR Abuffer[MAXSTRING]; |
| 86 | WCHAR answer[MAX_PATH] = {'\0'}; |
| 87 | DWORD count = 0; |
| 88 | |
| 89 | /* Load the translated 'Are you sure', plus valid answers */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 90 | LoadStringW(hinst, WCMD_CONFIRM, msgbuffer, sizeof(msgbuffer)/sizeof(WCHAR)); |
| 91 | LoadStringW(hinst, WCMD_YES, Ybuffer, sizeof(Ybuffer)/sizeof(WCHAR)); |
| 92 | LoadStringW(hinst, WCMD_NO, Nbuffer, sizeof(Nbuffer)/sizeof(WCHAR)); |
| 93 | LoadStringW(hinst, WCMD_ALL, Abuffer, sizeof(Abuffer)/sizeof(WCHAR)); |
Francois Gouget | e7b1257 | 2009-01-05 19:57:31 +0100 | [diff] [blame] | 94 | |
| 95 | /* Loop waiting on a Y or N */ |
| 96 | while (answer[0] != Ybuffer[0] && answer[0] != Nbuffer[0]) { |
| 97 | static const WCHAR startBkt[] = {' ','(','\0'}; |
| 98 | static const WCHAR endBkt[] = {')','?','\0'}; |
| 99 | |
| 100 | WCMD_output_asis (message); |
| 101 | if (showSureText) { |
| 102 | WCMD_output_asis (msgbuffer); |
| 103 | } |
| 104 | WCMD_output_asis (startBkt); |
| 105 | WCMD_output_asis (Ybuffer); |
| 106 | WCMD_output_asis (fslashW); |
| 107 | WCMD_output_asis (Nbuffer); |
| 108 | if (optionAll) { |
| 109 | WCMD_output_asis (fslashW); |
| 110 | WCMD_output_asis (Abuffer); |
| 111 | } |
| 112 | WCMD_output_asis (endBkt); |
| 113 | WCMD_ReadFile (GetStdHandle(STD_INPUT_HANDLE), answer, |
| 114 | sizeof(answer)/sizeof(WCHAR), &count, NULL); |
| 115 | answer[0] = toupperW(answer[0]); |
| 116 | } |
| 117 | |
| 118 | /* Return the answer */ |
| 119 | return ((answer[0] == Ybuffer[0]) || |
| 120 | (optionAll && (answer[0] == Abuffer[0]))); |
| 121 | } |
| 122 | |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 123 | /**************************************************************************** |
| 124 | * WCMD_clear_screen |
| 125 | * |
| 126 | * Clear the terminal screen. |
| 127 | */ |
| 128 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 129 | void WCMD_clear_screen (void) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 130 | |
Jason Edmeades | a4c214e | 2002-04-29 17:12:57 +0000 | [diff] [blame] | 131 | /* Emulate by filling the screen from the top left to bottom right with |
| 132 | spaces, then moving the cursor to the top left afterwards */ |
Jason Edmeades | a4c214e | 2002-04-29 17:12:57 +0000 | [diff] [blame] | 133 | CONSOLE_SCREEN_BUFFER_INFO consoleInfo; |
| 134 | HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 135 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 136 | if (GetConsoleScreenBufferInfo(hStdOut, &consoleInfo)) |
| 137 | { |
| 138 | COORD topLeft; |
Mike McCormack | 516a577 | 2005-08-19 10:04:03 +0000 | [diff] [blame] | 139 | DWORD screenSize; |
| 140 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 141 | screenSize = consoleInfo.dwSize.X * (consoleInfo.dwSize.Y + 1); |
Jason Edmeades | a4c214e | 2002-04-29 17:12:57 +0000 | [diff] [blame] | 142 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 143 | topLeft.X = 0; |
| 144 | topLeft.Y = 0; |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 145 | FillConsoleOutputCharacterW(hStdOut, ' ', screenSize, topLeft, &screenSize); |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 146 | SetConsoleCursorPosition(hStdOut, topLeft); |
| 147 | } |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /**************************************************************************** |
| 151 | * WCMD_change_tty |
| 152 | * |
| 153 | * Change the default i/o device (ie redirect STDin/STDout). |
| 154 | */ |
| 155 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 156 | void WCMD_change_tty (void) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 157 | |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 158 | WCMD_output (WCMD_LoadMessage(WCMD_NYI)); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 159 | |
| 160 | } |
| 161 | |
| 162 | /**************************************************************************** |
| 163 | * WCMD_copy |
| 164 | * |
| 165 | * Copy a file or wildcarded set. |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 166 | * FIXME: Add support for a+b+c type syntax |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 167 | */ |
| 168 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 169 | void WCMD_copy (void) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 170 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 171 | WIN32_FIND_DATAW fd; |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 172 | HANDLE hff; |
| 173 | BOOL force, status; |
Andrew Nguyen | 203c538 | 2009-10-03 17:00:59 -0500 | [diff] [blame] | 174 | WCHAR outpath[MAX_PATH], srcpath[MAX_PATH], copycmd[4]; |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 175 | DWORD len; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 176 | static const WCHAR copyCmdW[] = {'C','O','P','Y','C','M','D','\0'}; |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 177 | BOOL copyToDir = FALSE; |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 178 | WCHAR srcspec[MAX_PATH]; |
| 179 | DWORD attribs; |
| 180 | WCHAR drive[10]; |
| 181 | WCHAR dir[MAX_PATH]; |
| 182 | WCHAR fname[MAX_PATH]; |
| 183 | WCHAR ext[MAX_PATH]; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 184 | |
Markus Amsler | 765ff5d | 2006-10-31 21:11:28 +0100 | [diff] [blame] | 185 | if (param1[0] == 0x00) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 186 | WCMD_output (WCMD_LoadMessage(WCMD_NOARG)); |
Markus Amsler | 765ff5d | 2006-10-31 21:11:28 +0100 | [diff] [blame] | 187 | return; |
| 188 | } |
| 189 | |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 190 | /* Convert source into full spec */ |
| 191 | WINE_TRACE("Copy source (supplied): '%s'\n", wine_dbgstr_w(param1)); |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 192 | GetFullPathNameW(param1, sizeof(srcpath)/sizeof(WCHAR), srcpath, NULL); |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 193 | if (srcpath[strlenW(srcpath) - 1] == '\\') |
| 194 | srcpath[strlenW(srcpath) - 1] = '\0'; |
| 195 | |
| 196 | if ((strchrW(srcpath,'*') == NULL) && (strchrW(srcpath,'?') == NULL)) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 197 | attribs = GetFileAttributesW(srcpath); |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 198 | } else { |
| 199 | attribs = 0; |
| 200 | } |
| 201 | strcpyW(srcspec, srcpath); |
| 202 | |
| 203 | /* If a directory, then add \* on the end when searching */ |
| 204 | if (attribs & FILE_ATTRIBUTE_DIRECTORY) { |
| 205 | strcatW(srcpath, slashW); |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 206 | strcatW(srcspec, slashW); |
| 207 | strcatW(srcspec, starW); |
| 208 | } else { |
| 209 | WCMD_splitpath(srcpath, drive, dir, fname, ext); |
| 210 | strcpyW(srcpath, drive); |
| 211 | strcatW(srcpath, dir); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 212 | } |
Jason Edmeades | 13c5117 | 2002-04-20 20:54:38 +0000 | [diff] [blame] | 213 | |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 214 | WINE_TRACE("Copy source (calculated): path: '%s'\n", wine_dbgstr_w(srcpath)); |
| 215 | |
Jason Edmeades | 13c5117 | 2002-04-20 20:54:38 +0000 | [diff] [blame] | 216 | /* If no destination supplied, assume current directory */ |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 217 | WINE_TRACE("Copy destination (supplied): '%s'\n", wine_dbgstr_w(param2)); |
Jason Edmeades | 13c5117 | 2002-04-20 20:54:38 +0000 | [diff] [blame] | 218 | if (param2[0] == 0x00) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 219 | strcpyW(param2, dotW); |
Jason Edmeades | 13c5117 | 2002-04-20 20:54:38 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 222 | GetFullPathNameW(param2, sizeof(outpath)/sizeof(WCHAR), outpath, NULL); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 223 | if (outpath[strlenW(outpath) - 1] == '\\') |
| 224 | outpath[strlenW(outpath) - 1] = '\0'; |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 225 | attribs = GetFileAttributesW(outpath); |
Dmitry Potapov | f918d17 | 2007-10-13 04:07:57 +0400 | [diff] [blame] | 226 | if (attribs != INVALID_FILE_ATTRIBUTES && (attribs & FILE_ATTRIBUTE_DIRECTORY)) { |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 227 | strcatW (outpath, slashW); |
| 228 | copyToDir = TRUE; |
Dave Pickles | ebecf50 | 2000-08-01 22:02:18 +0000 | [diff] [blame] | 229 | } |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 230 | WINE_TRACE("Copy destination (calculated): '%s'(%d)\n", |
| 231 | wine_dbgstr_w(outpath), copyToDir); |
Jason Edmeades | 13c5117 | 2002-04-20 20:54:38 +0000 | [diff] [blame] | 232 | |
Alexander Farber | f6ec441 | 2007-02-28 14:49:46 +0100 | [diff] [blame] | 233 | /* /-Y has the highest priority, then /Y and finally the COPYCMD env. variable */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 234 | if (strstrW (quals, parmNoY)) |
Alexander Farber | f6ec441 | 2007-02-28 14:49:46 +0100 | [diff] [blame] | 235 | force = FALSE; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 236 | else if (strstrW (quals, parmY)) |
Alexander Farber | f6ec441 | 2007-02-28 14:49:46 +0100 | [diff] [blame] | 237 | force = TRUE; |
| 238 | else { |
Andrew Nguyen | 203c538 | 2009-10-03 17:00:59 -0500 | [diff] [blame] | 239 | /* By default, we will force the overwrite in batch mode and ask for |
| 240 | * confirmation in interactive mode. */ |
| 241 | force = !!context; |
| 242 | |
| 243 | /* If COPYCMD is set, then we force the overwrite with /Y and ask for |
| 244 | * confirmation with /-Y. If COPYCMD is neither of those, then we use the |
| 245 | * default behavior. */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 246 | len = GetEnvironmentVariableW(copyCmdW, copycmd, sizeof(copycmd)/sizeof(WCHAR)); |
Andrew Nguyen | 203c538 | 2009-10-03 17:00:59 -0500 | [diff] [blame] | 247 | if (len && len < (sizeof(copycmd)/sizeof(WCHAR))) { |
| 248 | if (!lstrcmpiW (copycmd, parmY)) |
| 249 | force = TRUE; |
| 250 | else if (!lstrcmpiW (copycmd, parmNoY)) |
| 251 | force = FALSE; |
| 252 | } |
Alexander Farber | f6ec441 | 2007-02-28 14:49:46 +0100 | [diff] [blame] | 253 | } |
| 254 | |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 255 | /* Loop through all source files */ |
| 256 | WINE_TRACE("Searching for: '%s'\n", wine_dbgstr_w(srcspec)); |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 257 | hff = FindFirstFileW(srcspec, &fd); |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 258 | if (hff != INVALID_HANDLE_VALUE) { |
| 259 | do { |
| 260 | WCHAR outname[MAX_PATH]; |
| 261 | WCHAR srcname[MAX_PATH]; |
| 262 | BOOL overwrite = force; |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 263 | |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 264 | /* Destination is either supplied filename, or source name in |
| 265 | supplied destination directory */ |
| 266 | strcpyW(outname, outpath); |
| 267 | if (copyToDir) strcatW(outname, fd.cFileName); |
| 268 | strcpyW(srcname, srcpath); |
| 269 | strcatW(srcname, fd.cFileName); |
| 270 | |
| 271 | WINE_TRACE("Copying from : '%s'\n", wine_dbgstr_w(srcname)); |
| 272 | WINE_TRACE("Copying to : '%s'\n", wine_dbgstr_w(outname)); |
| 273 | |
| 274 | /* Skip . and .., and directories */ |
| 275 | if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
| 276 | overwrite = FALSE; |
| 277 | WINE_TRACE("Skipping directories\n"); |
| 278 | } |
| 279 | |
| 280 | /* Prompt before overwriting */ |
| 281 | else if (!overwrite) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 282 | attribs = GetFileAttributesW(outname); |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 283 | if (attribs != INVALID_FILE_ATTRIBUTES) { |
| 284 | WCHAR buffer[MAXSTRING]; |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 285 | wsprintfW(buffer, WCMD_LoadMessage(WCMD_OVERWRITE), outname); |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 286 | overwrite = WCMD_ask_confirm(buffer, FALSE, NULL); |
| 287 | } |
| 288 | else overwrite = TRUE; |
| 289 | } |
| 290 | |
| 291 | /* Do the copy as appropriate */ |
| 292 | if (overwrite) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 293 | status = CopyFileW(srcname, outname, FALSE); |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 294 | if (!status) WCMD_print_error (); |
| 295 | } |
| 296 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 297 | } while (FindNextFileW(hff, &fd) != 0); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 298 | FindClose (hff); |
Jason Edmeades | a766ba0 | 2007-07-27 21:43:37 +0100 | [diff] [blame] | 299 | } else { |
| 300 | status = ERROR_FILE_NOT_FOUND; |
| 301 | WCMD_print_error (); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
| 305 | /**************************************************************************** |
| 306 | * WCMD_create_dir |
| 307 | * |
| 308 | * Create a directory. |
Aric Stewart | 1d5adff | 2005-12-03 18:02:15 +0100 | [diff] [blame] | 309 | * |
Francois Gouget | 8a18e0e | 2008-04-07 13:01:02 +0200 | [diff] [blame] | 310 | * this works recursively. so mkdir dir1\dir2\dir3 will create dir1 and dir2 if |
Aric Stewart | 1d5adff | 2005-12-03 18:02:15 +0100 | [diff] [blame] | 311 | * they do not already exist. |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 312 | */ |
| 313 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 314 | static BOOL create_full_path(WCHAR* path) |
Aric Stewart | 1d5adff | 2005-12-03 18:02:15 +0100 | [diff] [blame] | 315 | { |
| 316 | int len; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 317 | WCHAR *new_path; |
Aric Stewart | 1d5adff | 2005-12-03 18:02:15 +0100 | [diff] [blame] | 318 | BOOL ret = TRUE; |
| 319 | |
Dan Kegel | 15998c2 | 2010-02-02 17:42:01 -0800 | [diff] [blame] | 320 | new_path = HeapAlloc(GetProcessHeap(),0,(strlenW(path)+1) * sizeof(WCHAR)); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 321 | strcpyW(new_path,path); |
Aric Stewart | 1d5adff | 2005-12-03 18:02:15 +0100 | [diff] [blame] | 322 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 323 | while ((len = strlenW(new_path)) && new_path[len - 1] == '\\') |
Aric Stewart | 1d5adff | 2005-12-03 18:02:15 +0100 | [diff] [blame] | 324 | new_path[len - 1] = 0; |
| 325 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 326 | while (!CreateDirectoryW(new_path,NULL)) |
Aric Stewart | 1d5adff | 2005-12-03 18:02:15 +0100 | [diff] [blame] | 327 | { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 328 | WCHAR *slash; |
Aric Stewart | 1d5adff | 2005-12-03 18:02:15 +0100 | [diff] [blame] | 329 | DWORD last_error = GetLastError(); |
| 330 | if (last_error == ERROR_ALREADY_EXISTS) |
| 331 | break; |
| 332 | |
| 333 | if (last_error != ERROR_PATH_NOT_FOUND) |
| 334 | { |
| 335 | ret = FALSE; |
| 336 | break; |
| 337 | } |
| 338 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 339 | if (!(slash = strrchrW(new_path,'\\')) && ! (slash = strrchrW(new_path,'/'))) |
Aric Stewart | 1d5adff | 2005-12-03 18:02:15 +0100 | [diff] [blame] | 340 | { |
| 341 | ret = FALSE; |
| 342 | break; |
| 343 | } |
| 344 | |
| 345 | len = slash - new_path; |
| 346 | new_path[len] = 0; |
| 347 | if (!create_full_path(new_path)) |
| 348 | { |
| 349 | ret = FALSE; |
| 350 | break; |
| 351 | } |
| 352 | new_path[len] = '\\'; |
| 353 | } |
| 354 | HeapFree(GetProcessHeap(),0,new_path); |
| 355 | return ret; |
| 356 | } |
| 357 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 358 | void WCMD_create_dir (void) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 359 | |
Markus Amsler | 765ff5d | 2006-10-31 21:11:28 +0100 | [diff] [blame] | 360 | if (param1[0] == 0x00) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 361 | WCMD_output (WCMD_LoadMessage(WCMD_NOARG)); |
Markus Amsler | 765ff5d | 2006-10-31 21:11:28 +0100 | [diff] [blame] | 362 | return; |
| 363 | } |
Aric Stewart | 1d5adff | 2005-12-03 18:02:15 +0100 | [diff] [blame] | 364 | if (!create_full_path(param1)) WCMD_print_error (); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /**************************************************************************** |
| 368 | * WCMD_delete |
| 369 | * |
| 370 | * Delete a file or wildcarded set. |
| 371 | * |
Jason Edmeades | b822e73 | 2007-02-27 23:20:55 +0000 | [diff] [blame] | 372 | * Note on /A: |
| 373 | * - Testing shows /A is repeatable, eg. /a-r /ar matches all files |
| 374 | * - Each set is a pattern, eg /ahr /as-r means |
| 375 | * readonly+hidden OR nonreadonly system files |
| 376 | * - The '-' applies to a single field, ie /a:-hr means read only |
| 377 | * non-hidden files |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 378 | */ |
| 379 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 380 | BOOL WCMD_delete (WCHAR *command, BOOL expectDir) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 381 | |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 382 | int argno = 0; |
| 383 | int argsProcessed = 0; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 384 | WCHAR *argN = command; |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 385 | BOOL foundAny = FALSE; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 386 | static const WCHAR parmA[] = {'/','A','\0'}; |
| 387 | static const WCHAR parmQ[] = {'/','Q','\0'}; |
| 388 | static const WCHAR parmP[] = {'/','P','\0'}; |
| 389 | static const WCHAR parmS[] = {'/','S','\0'}; |
| 390 | static const WCHAR parmF[] = {'/','F','\0'}; |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 391 | |
| 392 | /* If not recursing, clear error flag */ |
| 393 | if (expectDir) errorlevel = 0; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 394 | |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 395 | /* Loop through all args */ |
| 396 | while (argN) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 397 | WCHAR *thisArg = WCMD_parameter (command, argno++, &argN); |
| 398 | WCHAR argCopy[MAX_PATH]; |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 399 | |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 400 | if (argN && argN[0] != '/') { |
Jason Edmeades | 409368e | 2007-02-27 23:19:24 +0000 | [diff] [blame] | 401 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 402 | WIN32_FIND_DATAW fd; |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 403 | HANDLE hff; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 404 | WCHAR fpath[MAX_PATH]; |
| 405 | WCHAR *p; |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 406 | BOOL handleParm = TRUE; |
| 407 | BOOL found = FALSE; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 408 | static const WCHAR anyExt[]= {'.','*','\0'}; |
Jason Edmeades | 409368e | 2007-02-27 23:19:24 +0000 | [diff] [blame] | 409 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 410 | strcpyW(argCopy, thisArg); |
| 411 | WINE_TRACE("del: Processing arg %s (quals:%s)\n", |
| 412 | wine_dbgstr_w(argCopy), wine_dbgstr_w(quals)); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 413 | argsProcessed++; |
Jason Edmeades | 409368e | 2007-02-27 23:19:24 +0000 | [diff] [blame] | 414 | |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 415 | /* If filename part of parameter is * or *.*, prompt unless |
| 416 | /Q supplied. */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 417 | if ((strstrW (quals, parmQ) == NULL) && (strstrW (quals, parmP) == NULL)) { |
Jason Edmeades | 409368e | 2007-02-27 23:19:24 +0000 | [diff] [blame] | 418 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 419 | WCHAR drive[10]; |
| 420 | WCHAR dir[MAX_PATH]; |
| 421 | WCHAR fname[MAX_PATH]; |
| 422 | WCHAR ext[MAX_PATH]; |
Jason Edmeades | 409368e | 2007-02-27 23:19:24 +0000 | [diff] [blame] | 423 | |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 424 | /* Convert path into actual directory spec */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 425 | GetFullPathNameW(argCopy, sizeof(fpath)/sizeof(WCHAR), fpath, NULL); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 426 | WCMD_splitpath(fpath, drive, dir, fname, ext); |
Jason Edmeades | 409368e | 2007-02-27 23:19:24 +0000 | [diff] [blame] | 427 | |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 428 | /* Only prompt for * and *.*, not *a, a*, *.a* etc */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 429 | if ((strcmpW(fname, starW) == 0) && |
| 430 | (*ext == 0x00 || (strcmpW(ext, anyExt) == 0))) { |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 431 | BOOL ok; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 432 | WCHAR question[MAXSTRING]; |
| 433 | static const WCHAR fmt[] = {'%','s',' ','\0'}; |
Jason Edmeades | 10c3764d | 2007-02-27 23:20:25 +0000 | [diff] [blame] | 434 | |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 435 | /* Note: Flag as found, to avoid file not found message */ |
| 436 | found = TRUE; |
| 437 | |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 438 | /* Ask for confirmation */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 439 | wsprintfW(question, fmt, fpath); |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 440 | ok = WCMD_ask_confirm(question, TRUE, NULL); |
Jason Edmeades | 10c3764d | 2007-02-27 23:20:25 +0000 | [diff] [blame] | 441 | |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 442 | /* Abort if answer is 'N' */ |
| 443 | if (!ok) continue; |
| 444 | } |
| 445 | } |
Jason Edmeades | b822e73 | 2007-02-27 23:20:55 +0000 | [diff] [blame] | 446 | |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 447 | /* First, try to delete in the current directory */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 448 | hff = FindFirstFileW(argCopy, &fd); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 449 | if (hff == INVALID_HANDLE_VALUE) { |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 450 | handleParm = FALSE; |
| 451 | } else { |
| 452 | found = TRUE; |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 453 | } |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 454 | |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 455 | /* Support del <dirname> by just deleting all files dirname\* */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 456 | if (handleParm && (strchrW(argCopy,'*') == NULL) && (strchrW(argCopy,'?') == NULL) |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 457 | && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 458 | WCHAR modifiedParm[MAX_PATH]; |
| 459 | static const WCHAR slashStar[] = {'\\','*','\0'}; |
| 460 | |
| 461 | strcpyW(modifiedParm, argCopy); |
| 462 | strcatW(modifiedParm, slashStar); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 463 | FindClose(hff); |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 464 | found = TRUE; |
| 465 | WCMD_delete(modifiedParm, FALSE); |
Jason Edmeades | b822e73 | 2007-02-27 23:20:55 +0000 | [diff] [blame] | 466 | |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 467 | } else if (handleParm) { |
Jason Edmeades | b822e73 | 2007-02-27 23:20:55 +0000 | [diff] [blame] | 468 | |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 469 | /* Build the filename to delete as <supplied directory>\<findfirst filename> */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 470 | strcpyW (fpath, argCopy); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 471 | do { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 472 | p = strrchrW (fpath, '\\'); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 473 | if (p != NULL) { |
| 474 | *++p = '\0'; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 475 | strcatW (fpath, fd.cFileName); |
Jason Edmeades | b822e73 | 2007-02-27 23:20:55 +0000 | [diff] [blame] | 476 | } |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 477 | else strcpyW (fpath, fd.cFileName); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 478 | if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { |
| 479 | BOOL ok = TRUE; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 480 | WCHAR *nextA = strstrW (quals, parmA); |
Jason Edmeades | b822e73 | 2007-02-27 23:20:55 +0000 | [diff] [blame] | 481 | |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 482 | /* Handle attribute matching (/A) */ |
| 483 | if (nextA != NULL) { |
| 484 | ok = FALSE; |
| 485 | while (nextA != NULL && !ok) { |
Jason Edmeades | b822e73 | 2007-02-27 23:20:55 +0000 | [diff] [blame] | 486 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 487 | WCHAR *thisA = (nextA+2); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 488 | BOOL stillOK = TRUE; |
| 489 | |
| 490 | /* Skip optional : */ |
| 491 | if (*thisA == ':') thisA++; |
| 492 | |
| 493 | /* Parse each of the /A[:]xxx in turn */ |
| 494 | while (*thisA && *thisA != '/') { |
| 495 | BOOL negate = FALSE; |
| 496 | BOOL attribute = FALSE; |
| 497 | |
| 498 | /* Match negation of attribute first */ |
| 499 | if (*thisA == '-') { |
| 500 | negate=TRUE; |
| 501 | thisA++; |
| 502 | } |
| 503 | |
| 504 | /* Match attribute */ |
| 505 | switch (*thisA) { |
| 506 | case 'R': attribute = (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY); |
| 507 | break; |
| 508 | case 'H': attribute = (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN); |
| 509 | break; |
| 510 | case 'S': attribute = (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM); |
| 511 | break; |
| 512 | case 'A': attribute = (fd.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE); |
| 513 | break; |
| 514 | default: |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 515 | WCMD_output (WCMD_LoadMessage(WCMD_SYNTAXERR)); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /* Now check result, keeping a running boolean about whether it |
Francois Gouget | 8a18e0e | 2008-04-07 13:01:02 +0200 | [diff] [blame] | 519 | matches all parsed attributes so far */ |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 520 | if (attribute && !negate) { |
| 521 | stillOK = stillOK; |
| 522 | } else if (!attribute && negate) { |
| 523 | stillOK = stillOK; |
| 524 | } else { |
| 525 | stillOK = FALSE; |
| 526 | } |
| 527 | thisA++; |
| 528 | } |
| 529 | |
| 530 | /* Save the running total as the final result */ |
| 531 | ok = stillOK; |
| 532 | |
| 533 | /* Step on to next /A set */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 534 | nextA = strstrW (nextA+1, parmA); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 535 | } |
| 536 | } |
| 537 | |
| 538 | /* /P means prompt for each file */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 539 | if (ok && strstrW (quals, parmP) != NULL) { |
| 540 | WCHAR question[MAXSTRING]; |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 541 | |
| 542 | /* Ask for confirmation */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 543 | wsprintfW(question, WCMD_LoadMessage(WCMD_DELPROMPT), fpath); |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 544 | ok = WCMD_ask_confirm(question, FALSE, NULL); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | /* Only proceed if ok to */ |
| 548 | if (ok) { |
| 549 | |
| 550 | /* If file is read only, and /F supplied, delete it */ |
| 551 | if (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY && |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 552 | strstrW (quals, parmF) != NULL) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 553 | SetFileAttributesW(fpath, fd.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | /* Now do the delete */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 557 | if (!DeleteFileW(fpath)) WCMD_print_error (); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | } |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 561 | } while (FindNextFileW(hff, &fd) != 0); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 562 | FindClose (hff); |
Jason Edmeades | b822e73 | 2007-02-27 23:20:55 +0000 | [diff] [blame] | 563 | } |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 564 | |
Francois Gouget | 5a8fc34 | 2007-04-30 02:06:11 +0200 | [diff] [blame] | 565 | /* Now recurse into all subdirectories handling the parameter in the same way */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 566 | if (strstrW (quals, parmS) != NULL) { |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 567 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 568 | WCHAR thisDir[MAX_PATH]; |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 569 | int cPos; |
| 570 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 571 | WCHAR drive[10]; |
| 572 | WCHAR dir[MAX_PATH]; |
| 573 | WCHAR fname[MAX_PATH]; |
| 574 | WCHAR ext[MAX_PATH]; |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 575 | |
| 576 | /* Convert path into actual directory spec */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 577 | GetFullPathNameW(argCopy, sizeof(thisDir)/sizeof(WCHAR), thisDir, NULL); |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 578 | WCMD_splitpath(thisDir, drive, dir, fname, ext); |
| 579 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 580 | strcpyW(thisDir, drive); |
| 581 | strcatW(thisDir, dir); |
| 582 | cPos = strlenW(thisDir); |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 583 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 584 | WINE_TRACE("Searching recursively in '%s'\n", wine_dbgstr_w(thisDir)); |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 585 | |
| 586 | /* Append '*' to the directory */ |
| 587 | thisDir[cPos] = '*'; |
| 588 | thisDir[cPos+1] = 0x00; |
| 589 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 590 | hff = FindFirstFileW(thisDir, &fd); |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 591 | |
| 592 | /* Remove residual '*' */ |
| 593 | thisDir[cPos] = 0x00; |
| 594 | |
| 595 | if (hff != INVALID_HANDLE_VALUE) { |
| 596 | DIRECTORY_STACK *allDirs = NULL; |
| 597 | DIRECTORY_STACK *lastEntry = NULL; |
| 598 | |
| 599 | do { |
| 600 | if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 601 | (strcmpW(fd.cFileName, dotdotW) != 0) && |
| 602 | (strcmpW(fd.cFileName, dotW) != 0)) { |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 603 | |
| 604 | DIRECTORY_STACK *nextDir; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 605 | WCHAR subParm[MAX_PATH]; |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 606 | |
| 607 | /* Work out search parameter in sub dir */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 608 | strcpyW (subParm, thisDir); |
| 609 | strcatW (subParm, fd.cFileName); |
| 610 | strcatW (subParm, slashW); |
| 611 | strcatW (subParm, fname); |
| 612 | strcatW (subParm, ext); |
| 613 | WINE_TRACE("Recursive, Adding to search list '%s'\n", wine_dbgstr_w(subParm)); |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 614 | |
| 615 | /* Allocate memory, add to list */ |
Michael Stefaniuc | 6519a83 | 2007-06-27 00:12:22 +0200 | [diff] [blame] | 616 | nextDir = HeapAlloc(GetProcessHeap(),0,sizeof(DIRECTORY_STACK)); |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 617 | if (allDirs == NULL) allDirs = nextDir; |
| 618 | if (lastEntry != NULL) lastEntry->next = nextDir; |
| 619 | lastEntry = nextDir; |
| 620 | nextDir->next = NULL; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 621 | nextDir->dirName = HeapAlloc(GetProcessHeap(),0, |
| 622 | (strlenW(subParm)+1) * sizeof(WCHAR)); |
| 623 | strcpyW(nextDir->dirName, subParm); |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 624 | } |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 625 | } while (FindNextFileW(hff, &fd) != 0); |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 626 | FindClose (hff); |
| 627 | |
| 628 | /* Go through each subdir doing the delete */ |
| 629 | while (allDirs != NULL) { |
| 630 | DIRECTORY_STACK *tempDir; |
| 631 | |
| 632 | tempDir = allDirs->next; |
| 633 | found |= WCMD_delete (allDirs->dirName, FALSE); |
| 634 | |
| 635 | HeapFree(GetProcessHeap(),0,allDirs->dirName); |
| 636 | HeapFree(GetProcessHeap(),0,allDirs); |
| 637 | allDirs = tempDir; |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | /* Keep running total to see if any found, and if not recursing |
| 642 | issue error message */ |
| 643 | if (expectDir) { |
| 644 | if (!found) { |
| 645 | errorlevel = 1; |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 646 | WCMD_output (WCMD_LoadMessage(WCMD_FILENOTFOUND), argCopy); |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 647 | } |
| 648 | } |
| 649 | foundAny |= found; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 650 | } |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /* Handle no valid args */ |
| 654 | if (argsProcessed == 0) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 655 | WCMD_output (WCMD_LoadMessage(WCMD_NOARG)); |
Jason Edmeades | a97d120 | 2007-03-04 22:35:09 +0000 | [diff] [blame] | 656 | } |
Jason Edmeades | 68b11d1 | 2007-04-23 23:24:38 +0100 | [diff] [blame] | 657 | |
| 658 | return foundAny; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | /**************************************************************************** |
| 662 | * WCMD_echo |
| 663 | * |
| 664 | * Echo input to the screen (or not). We don't try to emulate the bugs |
| 665 | * in DOS (try typing "ECHO ON AGAIN" for an example). |
| 666 | */ |
| 667 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 668 | void WCMD_echo (const WCHAR *command) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 669 | |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 670 | int count; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 671 | |
Mike McCormack | 8d02010 | 2004-03-18 04:01:32 +0000 | [diff] [blame] | 672 | if ((command[0] == '.') && (command[1] == 0)) { |
| 673 | WCMD_output (newline); |
| 674 | return; |
| 675 | } |
| 676 | if (command[0]==' ') |
| 677 | command++; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 678 | count = strlenW(command); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 679 | if (count == 0) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 680 | if (echo_mode) WCMD_output (WCMD_LoadMessage(WCMD_ECHOPROMPT), onW); |
| 681 | else WCMD_output (WCMD_LoadMessage(WCMD_ECHOPROMPT), offW); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 682 | return; |
| 683 | } |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 684 | if (lstrcmpiW(command, onW) == 0) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 685 | echo_mode = 1; |
| 686 | return; |
| 687 | } |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 688 | if (lstrcmpiW(command, offW) == 0) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 689 | echo_mode = 0; |
| 690 | return; |
| 691 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 692 | WCMD_output_asis (command); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 693 | WCMD_output (newline); |
| 694 | |
| 695 | } |
| 696 | |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 697 | /************************************************************************** |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 698 | * WCMD_for |
| 699 | * |
| 700 | * Batch file loop processing. |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 701 | * |
| 702 | * On entry: cmdList contains the syntax up to the set |
| 703 | * next cmdList and all in that bracket contain the set data |
| 704 | * next cmdlist contains the DO cmd |
| 705 | * following that is either brackets or && entries (as per if) |
| 706 | * |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 707 | */ |
| 708 | |
Jason Edmeades | 8f12d8b | 2007-06-15 20:59:21 +0100 | [diff] [blame] | 709 | void WCMD_for (WCHAR *p, CMD_LIST **cmdList) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 710 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 711 | WIN32_FIND_DATAW fd; |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 712 | HANDLE hff; |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 713 | int i; |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 714 | const WCHAR inW[] = {'i', 'n', ' ', '\0'}; |
| 715 | const WCHAR doW[] = {'d', 'o', ' ', '\0'}; |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 716 | CMD_LIST *setStart, *thisSet, *cmdStart, *cmdEnd; |
| 717 | WCHAR variable[4]; |
| 718 | WCHAR *firstCmd; |
| 719 | int thisDepth; |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 720 | |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 721 | WCHAR *curPos = p; |
| 722 | BOOL expandDirs = FALSE; |
| 723 | BOOL useNumbers = FALSE; |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 724 | BOOL doFileset = FALSE; |
| 725 | LONG numbers[3] = {0,0,0}; /* Defaults to 0 in native */ |
| 726 | int itemNum; |
| 727 | CMD_LIST *thisCmdStart; |
| 728 | |
| 729 | |
| 730 | /* Handle optional qualifiers (multiple are allowed) */ |
| 731 | while (*curPos && *curPos == '/') { |
| 732 | WINE_TRACE("Processing qualifier at %s\n", wine_dbgstr_w(curPos)); |
| 733 | curPos++; |
| 734 | switch (toupperW(*curPos)) { |
| 735 | case 'D': curPos++; expandDirs = TRUE; break; |
| 736 | case 'L': curPos++; useNumbers = TRUE; break; |
| 737 | |
| 738 | /* Recursive is special case - /R can have an optional path following it */ |
| 739 | /* filenamesets are another special case - /F can have an optional options following it */ |
| 740 | case 'R': |
| 741 | case 'F': |
| 742 | { |
| 743 | BOOL isRecursive = (*curPos == 'R'); |
| 744 | |
Gerald Pfeifer | 02a0bd3 | 2010-05-01 16:24:45 +0200 | [diff] [blame] | 745 | if (!isRecursive) |
| 746 | doFileset = TRUE; |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 747 | |
| 748 | /* Skip whitespace */ |
| 749 | curPos++; |
| 750 | while (*curPos && *curPos==' ') curPos++; |
| 751 | |
| 752 | /* Next parm is either qualifier, path/options or variable - |
| 753 | only care about it if it is the path/options */ |
| 754 | if (*curPos && *curPos != '/' && *curPos != '%') { |
| 755 | if (isRecursive) WINE_FIXME("/R needs to handle supplied root\n"); |
| 756 | else WINE_FIXME("/F needs to handle options\n"); |
| 757 | } |
| 758 | break; |
| 759 | } |
| 760 | default: |
| 761 | WINE_FIXME("for qualifier '%c' unhandled\n", *curPos); |
| 762 | curPos++; |
| 763 | } |
| 764 | |
| 765 | /* Skip whitespace between qualifiers */ |
| 766 | while (*curPos && *curPos==' ') curPos++; |
| 767 | } |
| 768 | |
| 769 | /* Skip whitespace before variable */ |
| 770 | while (*curPos && *curPos==' ') curPos++; |
| 771 | |
| 772 | /* Ensure line continues with variable */ |
| 773 | if (!*curPos || *curPos != '%') { |
| 774 | WCMD_output (WCMD_LoadMessage(WCMD_SYNTAXERR)); |
| 775 | return; |
| 776 | } |
| 777 | |
| 778 | /* Variable should follow */ |
| 779 | i = 0; |
| 780 | while (curPos[i] && curPos[i]!=' ') i++; |
| 781 | memcpy(&variable[0], curPos, i*sizeof(WCHAR)); |
| 782 | variable[i] = 0x00; |
| 783 | WINE_TRACE("Variable identified as %s\n", wine_dbgstr_w(variable)); |
| 784 | curPos = &curPos[i]; |
| 785 | |
| 786 | /* Skip whitespace before IN */ |
| 787 | while (*curPos && *curPos==' ') curPos++; |
| 788 | |
| 789 | /* Ensure line continues with IN */ |
| 790 | if (!*curPos || lstrcmpiW (curPos, inW)) { |
| 791 | WCMD_output (WCMD_LoadMessage(WCMD_SYNTAXERR)); |
| 792 | return; |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 793 | } |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 794 | |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 795 | /* Save away where the set of data starts and the variable */ |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 796 | thisDepth = (*cmdList)->bracketDepth; |
| 797 | *cmdList = (*cmdList)->nextcommand; |
| 798 | setStart = (*cmdList); |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 799 | |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 800 | /* Skip until the close bracket */ |
| 801 | WINE_TRACE("Searching %p as the set\n", *cmdList); |
| 802 | while (*cmdList && |
| 803 | (*cmdList)->command != NULL && |
| 804 | (*cmdList)->bracketDepth > thisDepth) { |
| 805 | WINE_TRACE("Skipping %p which is part of the set\n", *cmdList); |
| 806 | *cmdList = (*cmdList)->nextcommand; |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 807 | } |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 808 | |
| 809 | /* Skip the close bracket, if there is one */ |
| 810 | if (*cmdList) *cmdList = (*cmdList)->nextcommand; |
| 811 | |
| 812 | /* Syntax error if missing close bracket, or nothing following it |
| 813 | and once we have the complete set, we expect a DO */ |
| 814 | WINE_TRACE("Looking for 'do' in %p\n", *cmdList); |
| 815 | if ((*cmdList == NULL) || |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 816 | (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 817 | (*cmdList)->command, 3, doW, -1) != 2)) { |
| 818 | WCMD_output (WCMD_LoadMessage(WCMD_SYNTAXERR)); |
| 819 | return; |
| 820 | } |
| 821 | |
| 822 | /* Save away the starting position for the commands (and offset for the |
| 823 | first one */ |
| 824 | cmdStart = *cmdList; |
| 825 | cmdEnd = *cmdList; |
| 826 | firstCmd = (*cmdList)->command + 3; /* Skip 'do ' */ |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 827 | itemNum = 0; |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 828 | |
| 829 | thisSet = setStart; |
| 830 | /* Loop through all set entries */ |
| 831 | while (thisSet && |
| 832 | thisSet->command != NULL && |
| 833 | thisSet->bracketDepth >= thisDepth) { |
| 834 | |
| 835 | /* Loop through all entries on the same line */ |
| 836 | WCHAR *item; |
Jason Edmeades | f3ae48c | 2007-09-11 21:43:06 +0100 | [diff] [blame] | 837 | WCHAR *itemStart; |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 838 | |
| 839 | WINE_TRACE("Processing for set %p\n", thisSet); |
| 840 | i = 0; |
Jason Edmeades | f3ae48c | 2007-09-11 21:43:06 +0100 | [diff] [blame] | 841 | while (*(item = WCMD_parameter (thisSet->command, i, &itemStart))) { |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 842 | |
| 843 | /* |
| 844 | * If the parameter within the set has a wildcard then search for matching files |
| 845 | * otherwise do a literal substitution. |
| 846 | */ |
| 847 | static const WCHAR wildcards[] = {'*','?','\0'}; |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 848 | thisCmdStart = cmdStart; |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 849 | |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 850 | itemNum++; |
| 851 | WINE_TRACE("Processing for item %d '%s'\n", itemNum, wine_dbgstr_w(item)); |
| 852 | |
| 853 | if (!useNumbers && !doFileset) { |
| 854 | if (strpbrkW (item, wildcards)) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 855 | hff = FindFirstFileW(item, &fd); |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 856 | if (hff != INVALID_HANDLE_VALUE) { |
| 857 | do { |
| 858 | BOOL isDirectory = FALSE; |
| 859 | |
| 860 | if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) isDirectory = TRUE; |
| 861 | |
| 862 | /* Handle as files or dirs appropriately, but ignore . and .. */ |
| 863 | if (isDirectory == expandDirs && |
| 864 | (strcmpW(fd.cFileName, dotdotW) != 0) && |
| 865 | (strcmpW(fd.cFileName, dotW) != 0)) |
| 866 | { |
| 867 | thisCmdStart = cmdStart; |
| 868 | WINE_TRACE("Processing FOR filename %s\n", wine_dbgstr_w(fd.cFileName)); |
| 869 | WCMD_part_execute (&thisCmdStart, firstCmd, variable, |
| 870 | fd.cFileName, FALSE, TRUE); |
| 871 | } |
| 872 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 873 | } while (FindNextFileW(hff, &fd) != 0); |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 874 | FindClose (hff); |
Jason Edmeades | 196fb10 | 2007-06-15 20:59:29 +0100 | [diff] [blame] | 875 | } |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 876 | } else { |
| 877 | WCMD_part_execute(&thisCmdStart, firstCmd, variable, item, FALSE, TRUE); |
| 878 | } |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 879 | |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 880 | } else if (useNumbers) { |
| 881 | /* Convert the first 3 numbers to signed longs and save */ |
| 882 | if (itemNum <=3) numbers[itemNum-1] = atolW(item); |
| 883 | /* else ignore them! */ |
| 884 | |
Jason Edmeades | f3ae48c | 2007-09-11 21:43:06 +0100 | [diff] [blame] | 885 | /* Filesets - either a list of files, or a command to run and parse the output */ |
| 886 | } else if (doFileset && *itemStart != '"') { |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 887 | |
| 888 | HANDLE input; |
Jason Edmeades | c7b88e9 | 2007-09-11 21:43:07 +0100 | [diff] [blame] | 889 | WCHAR temp_file[MAX_PATH]; |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 890 | |
| 891 | WINE_TRACE("Processing for filespec from item %d '%s'\n", itemNum, |
| 892 | wine_dbgstr_w(item)); |
| 893 | |
Jason Edmeades | c7b88e9 | 2007-09-11 21:43:07 +0100 | [diff] [blame] | 894 | /* If backquote or single quote, we need to launch that command |
| 895 | and parse the results - use a temporary file */ |
| 896 | if (*itemStart == '`' || *itemStart == '\'') { |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 897 | |
Jason Edmeades | c7b88e9 | 2007-09-11 21:43:07 +0100 | [diff] [blame] | 898 | WCHAR temp_path[MAX_PATH], temp_cmd[MAXSTRING]; |
Jason Edmeades | 1ee7538 | 2007-09-11 21:43:08 +0100 | [diff] [blame] | 899 | static const WCHAR redirOut[] = {'>','%','s','\0'}; |
Jason Edmeades | c7b88e9 | 2007-09-11 21:43:07 +0100 | [diff] [blame] | 900 | static const WCHAR cmdW[] = {'C','M','D','\0'}; |
| 901 | |
| 902 | /* Remove trailing character */ |
| 903 | itemStart[strlenW(itemStart)-1] = 0x00; |
| 904 | |
| 905 | /* Get temp filename */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 906 | GetTempPathW(sizeof(temp_path)/sizeof(WCHAR), temp_path); |
| 907 | GetTempFileNameW(temp_path, cmdW, 0, temp_file); |
Jason Edmeades | c7b88e9 | 2007-09-11 21:43:07 +0100 | [diff] [blame] | 908 | |
| 909 | /* Execute program and redirect output */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 910 | wsprintfW(temp_cmd, redirOut, (itemStart+1), temp_file); |
Jason Edmeades | 1ee7538 | 2007-09-11 21:43:08 +0100 | [diff] [blame] | 911 | WCMD_execute (itemStart, temp_cmd, NULL, NULL, NULL); |
Jason Edmeades | c7b88e9 | 2007-09-11 21:43:07 +0100 | [diff] [blame] | 912 | |
| 913 | /* Open the file, read line by line and process */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 914 | input = CreateFileW(temp_file, GENERIC_READ, FILE_SHARE_READ, |
Jason Edmeades | c7b88e9 | 2007-09-11 21:43:07 +0100 | [diff] [blame] | 915 | NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 916 | } else { |
| 917 | |
| 918 | /* Open the file, read line by line and process */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 919 | input = CreateFileW(item, GENERIC_READ, FILE_SHARE_READ, |
Jason Edmeades | c7b88e9 | 2007-09-11 21:43:07 +0100 | [diff] [blame] | 920 | NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 921 | } |
| 922 | |
| 923 | /* Process the input file */ |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 924 | if (input == INVALID_HANDLE_VALUE) { |
| 925 | WCMD_print_error (); |
| 926 | WCMD_output (WCMD_LoadMessage(WCMD_READFAIL), item); |
| 927 | errorlevel = 1; |
| 928 | return; /* FOR loop aborts at first failure here */ |
| 929 | |
| 930 | } else { |
| 931 | |
| 932 | WCHAR buffer[MAXSTRING] = {'\0'}; |
| 933 | WCHAR *where, *parm; |
| 934 | |
| 935 | while (WCMD_fgets (buffer, sizeof(buffer)/sizeof(WCHAR), input)) { |
| 936 | |
| 937 | /* Skip blank lines*/ |
| 938 | parm = WCMD_parameter (buffer, 0, &where); |
| 939 | WINE_TRACE("Parsed parameter: %s from %s\n", wine_dbgstr_w(parm), |
| 940 | wine_dbgstr_w(buffer)); |
| 941 | |
| 942 | if (where) { |
Jason Edmeades | f3ae48c | 2007-09-11 21:43:06 +0100 | [diff] [blame] | 943 | /* FIXME: The following should be moved into its own routine and |
| 944 | reused for the string literal parsing below */ |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 945 | thisCmdStart = cmdStart; |
| 946 | WCMD_part_execute(&thisCmdStart, firstCmd, variable, parm, FALSE, TRUE); |
| 947 | cmdEnd = thisCmdStart; |
| 948 | } |
| 949 | |
| 950 | buffer[0] = 0x00; |
| 951 | |
| 952 | } |
| 953 | CloseHandle (input); |
| 954 | } |
Jason Edmeades | f3ae48c | 2007-09-11 21:43:06 +0100 | [diff] [blame] | 955 | |
Jason Edmeades | c7b88e9 | 2007-09-11 21:43:07 +0100 | [diff] [blame] | 956 | /* Delete the temporary file */ |
| 957 | if (*itemStart == '`' || *itemStart == '\'') { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 958 | DeleteFileW(temp_file); |
Jason Edmeades | c7b88e9 | 2007-09-11 21:43:07 +0100 | [diff] [blame] | 959 | } |
| 960 | |
Jason Edmeades | f3ae48c | 2007-09-11 21:43:06 +0100 | [diff] [blame] | 961 | /* Filesets - A string literal */ |
| 962 | } else if (doFileset && *itemStart == '"') { |
| 963 | WCHAR buffer[MAXSTRING] = {'\0'}; |
| 964 | WCHAR *where, *parm; |
| 965 | |
| 966 | /* Skip blank lines, and re-extract parameter now string has quotes removed */ |
| 967 | strcpyW(buffer, item); |
| 968 | parm = WCMD_parameter (buffer, 0, &where); |
| 969 | WINE_TRACE("Parsed parameter: %s from %s\n", wine_dbgstr_w(parm), |
| 970 | wine_dbgstr_w(buffer)); |
| 971 | |
| 972 | if (where) { |
| 973 | /* FIXME: The following should be moved into its own routine and |
| 974 | reused for the string literal parsing below */ |
| 975 | thisCmdStart = cmdStart; |
| 976 | WCMD_part_execute(&thisCmdStart, firstCmd, variable, parm, FALSE, TRUE); |
| 977 | cmdEnd = thisCmdStart; |
| 978 | } |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | WINE_TRACE("Post-command, cmdEnd = %p\n", cmdEnd); |
| 982 | cmdEnd = thisCmdStart; |
| 983 | i++; |
| 984 | } |
| 985 | |
| 986 | /* Move onto the next set line */ |
| 987 | thisSet = thisSet->nextcommand; |
| 988 | } |
| 989 | |
Jason Edmeades | dc37217 | 2007-09-11 21:43:02 +0100 | [diff] [blame] | 990 | /* If /L is provided, now run the for loop */ |
| 991 | if (useNumbers) { |
| 992 | WCHAR thisNum[20]; |
| 993 | static const WCHAR fmt[] = {'%','d','\0'}; |
| 994 | |
| 995 | WINE_TRACE("FOR /L provided range from %d to %d step %d\n", |
| 996 | numbers[0], numbers[2], numbers[1]); |
| 997 | for (i=numbers[0]; |
| 998 | (numbers[1]<0)? i>numbers[2] : i<numbers[2]; |
| 999 | i=i + numbers[1]) { |
| 1000 | |
| 1001 | sprintfW(thisNum, fmt, i); |
| 1002 | WINE_TRACE("Processing FOR number %s\n", wine_dbgstr_w(thisNum)); |
| 1003 | |
| 1004 | thisCmdStart = cmdStart; |
| 1005 | WCMD_part_execute(&thisCmdStart, firstCmd, variable, thisNum, FALSE, TRUE); |
| 1006 | cmdEnd = thisCmdStart; |
| 1007 | } |
| 1008 | } |
| 1009 | |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 1010 | /* When the loop ends, either something like a GOTO or EXIT /b has terminated |
| 1011 | all processing, OR it should be pointing to the end of && processing OR |
| 1012 | it should be pointing at the NULL end of bracket for the DO. The return |
| 1013 | value needs to be the NEXT command to execute, which it either is, or |
| 1014 | we need to step over the closing bracket */ |
| 1015 | *cmdList = cmdEnd; |
| 1016 | if (cmdEnd && cmdEnd->command == NULL) *cmdList = cmdEnd->nextcommand; |
| 1017 | } |
| 1018 | |
| 1019 | |
| 1020 | /***************************************************************************** |
| 1021 | * WCMD_part_execute |
| 1022 | * |
| 1023 | * Execute a command, and any && or bracketed follow on to the command. The |
| 1024 | * first command to be executed may not be at the front of the |
Jason Edmeades | 8e08983 | 2007-07-27 21:43:38 +0100 | [diff] [blame] | 1025 | * commands->thiscommand string (eg. it may point after a DO or ELSE) |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 1026 | */ |
| 1027 | void WCMD_part_execute(CMD_LIST **cmdList, WCHAR *firstcmd, WCHAR *variable, |
| 1028 | WCHAR *value, BOOL isIF, BOOL conditionTRUE) { |
| 1029 | |
| 1030 | CMD_LIST *curPosition = *cmdList; |
| 1031 | int myDepth = (*cmdList)->bracketDepth; |
| 1032 | |
| 1033 | WINE_TRACE("cmdList(%p), firstCmd(%p), with '%s'='%s', doIt(%d)\n", |
| 1034 | cmdList, wine_dbgstr_w(firstcmd), |
| 1035 | wine_dbgstr_w(variable), wine_dbgstr_w(value), |
| 1036 | conditionTRUE); |
| 1037 | |
| 1038 | /* Skip leading whitespace between condition and the command */ |
| 1039 | while (firstcmd && *firstcmd && (*firstcmd==' ' || *firstcmd=='\t')) firstcmd++; |
| 1040 | |
| 1041 | /* Process the first command, if there is one */ |
| 1042 | if (conditionTRUE && firstcmd && *firstcmd) { |
| 1043 | WCHAR *command = WCMD_strdupW(firstcmd); |
Jason Edmeades | 1ee7538 | 2007-09-11 21:43:08 +0100 | [diff] [blame] | 1044 | WCMD_execute (firstcmd, (*cmdList)->redirects, variable, value, cmdList); |
Francois Gouget | 0c01b71 | 2009-06-15 10:59:45 +0200 | [diff] [blame] | 1045 | HeapFree(GetProcessHeap(), 0, command); |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | |
Francois Gouget | a3317a5 | 2007-07-05 16:10:30 +0200 | [diff] [blame] | 1049 | /* If it didn't move the position, step to next command */ |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 1050 | if (curPosition == *cmdList) *cmdList = (*cmdList)->nextcommand; |
| 1051 | |
| 1052 | /* Process any other parts of the command */ |
| 1053 | if (*cmdList) { |
| 1054 | BOOL processThese = TRUE; |
| 1055 | |
| 1056 | if (isIF) processThese = conditionTRUE; |
| 1057 | |
| 1058 | while (*cmdList) { |
| 1059 | const WCHAR ifElse[] = {'e','l','s','e',' ','\0'}; |
| 1060 | |
| 1061 | /* execute all appropriate commands */ |
| 1062 | curPosition = *cmdList; |
| 1063 | |
Jason Edmeades | 84f02a6 | 2008-03-03 23:14:29 +0000 | [diff] [blame] | 1064 | WINE_TRACE("Processing cmdList(%p) - delim(%d) bd(%d / %d)\n", |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 1065 | *cmdList, |
Jason Edmeades | 84f02a6 | 2008-03-03 23:14:29 +0000 | [diff] [blame] | 1066 | (*cmdList)->prevDelim, |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 1067 | (*cmdList)->bracketDepth, myDepth); |
| 1068 | |
Jason Edmeades | 84f02a6 | 2008-03-03 23:14:29 +0000 | [diff] [blame] | 1069 | /* Execute any statements appended to the line */ |
| 1070 | /* FIXME: Only if previous call worked for && or failed for || */ |
| 1071 | if ((*cmdList)->prevDelim == CMD_ONFAILURE || |
Dan Kegel | 8110dde | 2010-02-17 23:11:04 -0800 | [diff] [blame] | 1072 | (*cmdList)->prevDelim == CMD_ONSUCCESS) { |
Juan Lang | 9c7ded0 | 2009-08-12 18:15:37 -0700 | [diff] [blame] | 1073 | if (processThese && (*cmdList)->command) { |
Jason Edmeades | 1ee7538 | 2007-09-11 21:43:08 +0100 | [diff] [blame] | 1074 | WCMD_execute ((*cmdList)->command, (*cmdList)->redirects, variable, |
| 1075 | value, cmdList); |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 1076 | } |
| 1077 | if (curPosition == *cmdList) *cmdList = (*cmdList)->nextcommand; |
| 1078 | |
| 1079 | /* Execute any appended to the statement with (...) */ |
| 1080 | } else if ((*cmdList)->bracketDepth > myDepth) { |
| 1081 | if (processThese) { |
| 1082 | *cmdList = WCMD_process_commands(*cmdList, TRUE, variable, value); |
| 1083 | WINE_TRACE("Back from processing commands, (next = %p)\n", *cmdList); |
| 1084 | } |
| 1085 | if (curPosition == *cmdList) *cmdList = (*cmdList)->nextcommand; |
| 1086 | |
| 1087 | /* End of the command - does 'ELSE ' follow as the next command? */ |
| 1088 | } else { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1089 | if (isIF && CompareStringW(LOCALE_USER_DEFAULT, |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 1090 | NORM_IGNORECASE | SORT_STRINGSORT, |
| 1091 | (*cmdList)->command, 5, ifElse, -1) == 2) { |
| 1092 | |
| 1093 | /* Swap between if and else processing */ |
| 1094 | processThese = !processThese; |
| 1095 | |
| 1096 | /* Process the ELSE part */ |
| 1097 | if (processThese) { |
| 1098 | WCHAR *cmd = ((*cmdList)->command) + strlenW(ifElse); |
| 1099 | |
| 1100 | /* Skip leading whitespace between condition and the command */ |
| 1101 | while (*cmd && (*cmd==' ' || *cmd=='\t')) cmd++; |
| 1102 | if (*cmd) { |
Jason Edmeades | 1ee7538 | 2007-09-11 21:43:08 +0100 | [diff] [blame] | 1103 | WCMD_execute (cmd, (*cmdList)->redirects, variable, value, cmdList); |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 1104 | } |
| 1105 | } |
| 1106 | if (curPosition == *cmdList) *cmdList = (*cmdList)->nextcommand; |
| 1107 | } else { |
| 1108 | WINE_TRACE("Found end of this IF statement (next = %p)\n", *cmdList); |
| 1109 | break; |
| 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | return; |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1117 | /************************************************************************** |
| 1118 | * WCMD_give_help |
| 1119 | * |
| 1120 | * Simple on-line help. Help text is stored in the resource file. |
| 1121 | */ |
| 1122 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1123 | void WCMD_give_help (WCHAR *command) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1124 | |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 1125 | int i; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1126 | |
| 1127 | command = WCMD_strtrim_leading_spaces(command); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1128 | if (strlenW(command) == 0) { |
Jason Edmeades | afe4d80 | 2007-06-03 22:07:43 +0100 | [diff] [blame] | 1129 | WCMD_output_asis (WCMD_LoadMessage(WCMD_ALLHELP)); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1130 | } |
| 1131 | else { |
| 1132 | for (i=0; i<=WCMD_EXIT; i++) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1133 | if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, |
Arjun Comar | a607f53 | 2010-03-02 16:26:09 -0500 | [diff] [blame] | 1134 | command, -1, inbuilt[i], -1) == 2) { |
Jason Edmeades | afe4d80 | 2007-06-03 22:07:43 +0100 | [diff] [blame] | 1135 | WCMD_output_asis (WCMD_LoadMessage(i)); |
Dave Pickles | ebecf50 | 2000-08-01 22:02:18 +0000 | [diff] [blame] | 1136 | return; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1137 | } |
| 1138 | } |
Arjun Comar | a607f53 | 2010-03-02 16:26:09 -0500 | [diff] [blame] | 1139 | WCMD_output (WCMD_LoadMessage(WCMD_NOCMDHELP), command); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1140 | } |
| 1141 | return; |
| 1142 | } |
| 1143 | |
| 1144 | /**************************************************************************** |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 1145 | * WCMD_go_to |
| 1146 | * |
| 1147 | * Batch file jump instruction. Not the most efficient algorithm ;-) |
| 1148 | * Prints error message if the specified label cannot be found - the file pointer is |
| 1149 | * then at EOF, effectively stopping the batch file. |
| 1150 | * FIXME: DOS is supposed to allow labels with spaces - we don't. |
| 1151 | */ |
| 1152 | |
Jason Edmeades | 929a92f | 2007-06-15 20:59:22 +0100 | [diff] [blame] | 1153 | void WCMD_goto (CMD_LIST **cmdList) { |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 1154 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1155 | WCHAR string[MAX_PATH]; |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 1156 | |
Jason Edmeades | 929a92f | 2007-06-15 20:59:22 +0100 | [diff] [blame] | 1157 | /* Do not process any more parts of a processed multipart or multilines command */ |
Jason Edmeades | b692411 | 2007-09-11 21:43:03 +0100 | [diff] [blame] | 1158 | if (cmdList) *cmdList = NULL; |
Jason Edmeades | 929a92f | 2007-06-15 20:59:22 +0100 | [diff] [blame] | 1159 | |
Markus Amsler | 765ff5d | 2006-10-31 21:11:28 +0100 | [diff] [blame] | 1160 | if (param1[0] == 0x00) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 1161 | WCMD_output (WCMD_LoadMessage(WCMD_NOARG)); |
Markus Amsler | 765ff5d | 2006-10-31 21:11:28 +0100 | [diff] [blame] | 1162 | return; |
| 1163 | } |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 1164 | if (context != NULL) { |
Nikolay Sivov | e22f6aa | 2010-03-23 22:45:25 -0500 | [diff] [blame] | 1165 | WCHAR *paramStart = param1, *str; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1166 | static const WCHAR eofW[] = {':','e','o','f','\0'}; |
Jason Edmeades | 5482924 | 2007-02-20 18:00:37 +0000 | [diff] [blame] | 1167 | |
| 1168 | /* Handle special :EOF label */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1169 | if (lstrcmpiW (eofW, param1) == 0) { |
Jason Edmeades | 5482924 | 2007-02-20 18:00:37 +0000 | [diff] [blame] | 1170 | context -> skip_rest = TRUE; |
| 1171 | return; |
| 1172 | } |
| 1173 | |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 1174 | /* Support goto :label as well as goto label */ |
| 1175 | if (*paramStart == ':') paramStart++; |
| 1176 | |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 1177 | SetFilePointer (context -> h, 0, NULL, FILE_BEGIN); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1178 | while (WCMD_fgets (string, sizeof(string)/sizeof(WCHAR), context -> h)) { |
Nikolay Sivov | e22f6aa | 2010-03-23 22:45:25 -0500 | [diff] [blame] | 1179 | str = string; |
| 1180 | while (isspaceW(*str)) str++; |
| 1181 | if ((*str == ':') && (lstrcmpiW (++str, paramStart) == 0)) return; |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 1182 | } |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 1183 | WCMD_output (WCMD_LoadMessage(WCMD_NOTARGET)); |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 1184 | } |
| 1185 | return; |
| 1186 | } |
| 1187 | |
Jason Edmeades | 365f86f | 2007-02-23 22:17:28 +0000 | [diff] [blame] | 1188 | /***************************************************************************** |
| 1189 | * WCMD_pushd |
| 1190 | * |
| 1191 | * Push a directory onto the stack |
| 1192 | */ |
| 1193 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1194 | void WCMD_pushd (WCHAR *command) { |
Jason Edmeades | 365f86f | 2007-02-23 22:17:28 +0000 | [diff] [blame] | 1195 | struct env_stack *curdir; |
Jason Edmeades | 365f86f | 2007-02-23 22:17:28 +0000 | [diff] [blame] | 1196 | WCHAR *thisdir; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1197 | static const WCHAR parmD[] = {'/','D','\0'}; |
Jason Edmeades | 365f86f | 2007-02-23 22:17:28 +0000 | [diff] [blame] | 1198 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1199 | if (strchrW(command, '/') != NULL) { |
Jason Edmeades | 91aa8a0 | 2007-03-08 00:44:46 +0000 | [diff] [blame] | 1200 | SetLastError(ERROR_INVALID_PARAMETER); |
| 1201 | WCMD_print_error(); |
| 1202 | return; |
| 1203 | } |
| 1204 | |
Jason Edmeades | 365f86f | 2007-02-23 22:17:28 +0000 | [diff] [blame] | 1205 | curdir = LocalAlloc (LMEM_FIXED, sizeof (struct env_stack)); |
| 1206 | thisdir = LocalAlloc (LMEM_FIXED, 1024 * sizeof(WCHAR)); |
| 1207 | if( !curdir || !thisdir ) { |
| 1208 | LocalFree(curdir); |
| 1209 | LocalFree(thisdir); |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 1210 | WINE_ERR ("out of memory\n"); |
Jason Edmeades | 365f86f | 2007-02-23 22:17:28 +0000 | [diff] [blame] | 1211 | return; |
| 1212 | } |
| 1213 | |
Jason Edmeades | ffbaede | 2007-03-08 00:50:14 +0000 | [diff] [blame] | 1214 | /* Change directory using CD code with /D parameter */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1215 | strcpyW(quals, parmD); |
Jason Edmeades | 365f86f | 2007-02-23 22:17:28 +0000 | [diff] [blame] | 1216 | GetCurrentDirectoryW (1024, thisdir); |
Jason Edmeades | e5a26bc | 2007-03-08 00:44:09 +0000 | [diff] [blame] | 1217 | errorlevel = 0; |
| 1218 | WCMD_setshow_default(command); |
| 1219 | if (errorlevel) { |
Jason Edmeades | 365f86f | 2007-02-23 22:17:28 +0000 | [diff] [blame] | 1220 | LocalFree(curdir); |
| 1221 | LocalFree(thisdir); |
| 1222 | return; |
| 1223 | } else { |
| 1224 | curdir -> next = pushd_directories; |
| 1225 | curdir -> strings = thisdir; |
Jason Edmeades | 8049ae1 | 2007-03-04 22:34:20 +0000 | [diff] [blame] | 1226 | if (pushd_directories == NULL) { |
Francois Gouget | 540d818 | 2007-03-12 10:35:13 +0100 | [diff] [blame] | 1227 | curdir -> u.stackdepth = 1; |
Jason Edmeades | 8049ae1 | 2007-03-04 22:34:20 +0000 | [diff] [blame] | 1228 | } else { |
Francois Gouget | 540d818 | 2007-03-12 10:35:13 +0100 | [diff] [blame] | 1229 | curdir -> u.stackdepth = pushd_directories -> u.stackdepth + 1; |
Jason Edmeades | 8049ae1 | 2007-03-04 22:34:20 +0000 | [diff] [blame] | 1230 | } |
Jason Edmeades | 365f86f | 2007-02-23 22:17:28 +0000 | [diff] [blame] | 1231 | pushd_directories = curdir; |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | |
| 1236 | /***************************************************************************** |
| 1237 | * WCMD_popd |
| 1238 | * |
| 1239 | * Pop a directory from the stack |
| 1240 | */ |
| 1241 | |
| 1242 | void WCMD_popd (void) { |
| 1243 | struct env_stack *temp = pushd_directories; |
| 1244 | |
| 1245 | if (!pushd_directories) |
| 1246 | return; |
| 1247 | |
| 1248 | /* pop the old environment from the stack, and make it the current dir */ |
| 1249 | pushd_directories = temp->next; |
| 1250 | SetCurrentDirectoryW(temp->strings); |
| 1251 | LocalFree (temp->strings); |
| 1252 | LocalFree (temp); |
| 1253 | } |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 1254 | |
| 1255 | /**************************************************************************** |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1256 | * WCMD_if |
| 1257 | * |
| 1258 | * Batch file conditional. |
Jason Edmeades | d2e7b40 | 2007-06-15 20:59:27 +0100 | [diff] [blame] | 1259 | * |
| 1260 | * On entry, cmdlist will point to command containing the IF, and optionally |
| 1261 | * the first command to execute (if brackets not found) |
| 1262 | * If &&'s were found, this may be followed by a record flagged as isAmpersand |
| 1263 | * If ('s were found, execute all within that bracket |
| 1264 | * Command may optionally be followed by an ELSE - need to skip instructions |
| 1265 | * in the else using the same logic |
| 1266 | * |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 1267 | * FIXME: Much more syntax checking needed! |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1268 | */ |
| 1269 | |
Jason Edmeades | 8f12d8b | 2007-06-15 20:59:21 +0100 | [diff] [blame] | 1270 | void WCMD_if (WCHAR *p, CMD_LIST **cmdList) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1271 | |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 1272 | int negate = 0, test = 0; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1273 | WCHAR condition[MAX_PATH], *command, *s; |
| 1274 | static const WCHAR notW[] = {'n','o','t','\0'}; |
| 1275 | static const WCHAR errlvlW[] = {'e','r','r','o','r','l','e','v','e','l','\0'}; |
| 1276 | static const WCHAR existW[] = {'e','x','i','s','t','\0'}; |
| 1277 | static const WCHAR defdW[] = {'d','e','f','i','n','e','d','\0'}; |
| 1278 | static const WCHAR eqeqW[] = {'=','=','\0'}; |
Trey Hunner | afb374b | 2010-02-02 01:09:06 -0800 | [diff] [blame] | 1279 | static const WCHAR parmI[] = {'/','I','\0'}; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1280 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1281 | if (!lstrcmpiW (param1, notW)) { |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 1282 | negate = 1; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1283 | strcpyW (condition, param2); |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 1284 | } |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 1285 | else { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1286 | strcpyW (condition, param1); |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 1287 | } |
Jason Edmeades | bcaf4fb | 2007-09-11 21:43:05 +0100 | [diff] [blame] | 1288 | WINE_TRACE("Condition: %s\n", wine_dbgstr_w(condition)); |
| 1289 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1290 | if (!lstrcmpiW (condition, errlvlW)) { |
| 1291 | if (errorlevel >= atoiW(WCMD_parameter (p, 1+negate, NULL))) test = 1; |
Alexandre Julliard | 36bf792 | 2003-01-15 03:35:32 +0000 | [diff] [blame] | 1292 | WCMD_parameter (p, 2+negate, &command); |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 1293 | } |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1294 | else if (!lstrcmpiW (condition, existW)) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1295 | if (GetFileAttributesW(WCMD_parameter (p, 1+negate, NULL)) != INVALID_FILE_ATTRIBUTES) { |
Jason Edmeades | c79342a | 2005-02-14 11:01:35 +0000 | [diff] [blame] | 1296 | test = 1; |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 1297 | } |
Alexandre Julliard | 36bf792 | 2003-01-15 03:35:32 +0000 | [diff] [blame] | 1298 | WCMD_parameter (p, 2+negate, &command); |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 1299 | } |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1300 | else if (!lstrcmpiW (condition, defdW)) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1301 | if (GetEnvironmentVariableW(WCMD_parameter (p, 1+negate, NULL), NULL, 0) > 0) { |
Jason Edmeades | 758a397 | 2007-02-20 17:47:35 +0000 | [diff] [blame] | 1302 | test = 1; |
| 1303 | } |
| 1304 | WCMD_parameter (p, 2+negate, &command); |
| 1305 | } |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1306 | else if ((s = strstrW (p, eqeqW))) { |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 1307 | s += 2; |
Trey Hunner | afb374b | 2010-02-02 01:09:06 -0800 | [diff] [blame] | 1308 | if (strstrW (quals, parmI) == NULL) { |
| 1309 | if (!lstrcmpW (condition, WCMD_parameter (s, 0, NULL))) test = 1; |
| 1310 | } |
| 1311 | else { |
| 1312 | if (!lstrcmpiW (condition, WCMD_parameter (s, 0, NULL))) test = 1; |
| 1313 | } |
Alexandre Julliard | 36bf792 | 2003-01-15 03:35:32 +0000 | [diff] [blame] | 1314 | WCMD_parameter (s, 1, &command); |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 1315 | } |
| 1316 | else { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 1317 | WCMD_output (WCMD_LoadMessage(WCMD_SYNTAXERR)); |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 1318 | return; |
| 1319 | } |
Jason Edmeades | d2e7b40 | 2007-06-15 20:59:27 +0100 | [diff] [blame] | 1320 | |
| 1321 | /* Process rest of IF statement which is on the same line |
| 1322 | Note: This may process all or some of the cmdList (eg a GOTO) */ |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 1323 | WCMD_part_execute(cmdList, command, NULL, NULL, TRUE, (test != negate)); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | /**************************************************************************** |
| 1327 | * WCMD_move |
| 1328 | * |
| 1329 | * Move a file, directory tree or wildcarded set of files. |
| 1330 | */ |
| 1331 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 1332 | void WCMD_move (void) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1333 | |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1334 | int status; |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1335 | WIN32_FIND_DATAW fd; |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1336 | HANDLE hff; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1337 | WCHAR input[MAX_PATH]; |
| 1338 | WCHAR output[MAX_PATH]; |
| 1339 | WCHAR drive[10]; |
| 1340 | WCHAR dir[MAX_PATH]; |
| 1341 | WCHAR fname[MAX_PATH]; |
| 1342 | WCHAR ext[MAX_PATH]; |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 1343 | |
Markus Amsler | 765ff5d | 2006-10-31 21:11:28 +0100 | [diff] [blame] | 1344 | if (param1[0] == 0x00) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 1345 | WCMD_output (WCMD_LoadMessage(WCMD_NOARG)); |
Markus Amsler | 765ff5d | 2006-10-31 21:11:28 +0100 | [diff] [blame] | 1346 | return; |
| 1347 | } |
| 1348 | |
Jason Edmeades | 13c5117 | 2002-04-20 20:54:38 +0000 | [diff] [blame] | 1349 | /* If no destination supplied, assume current directory */ |
| 1350 | if (param2[0] == 0x00) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1351 | strcpyW(param2, dotW); |
Jason Edmeades | 13c5117 | 2002-04-20 20:54:38 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | /* If 2nd parm is directory, then use original filename */ |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1355 | /* Convert partial path to full path */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1356 | GetFullPathNameW(param1, sizeof(input)/sizeof(WCHAR), input, NULL); |
| 1357 | GetFullPathNameW(param2, sizeof(output)/sizeof(WCHAR), output, NULL); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1358 | WINE_TRACE("Move from '%s'('%s') to '%s'\n", wine_dbgstr_w(input), |
| 1359 | wine_dbgstr_w(param1), wine_dbgstr_w(output)); |
Jason Edmeades | 13c5117 | 2002-04-20 20:54:38 +0000 | [diff] [blame] | 1360 | |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1361 | /* Split into components */ |
| 1362 | WCMD_splitpath(input, drive, dir, fname, ext); |
| 1363 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1364 | hff = FindFirstFileW(input, &fd); |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1365 | while (hff != INVALID_HANDLE_VALUE) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1366 | WCHAR dest[MAX_PATH]; |
| 1367 | WCHAR src[MAX_PATH]; |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1368 | DWORD attribs; |
| 1369 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1370 | WINE_TRACE("Processing file '%s'\n", wine_dbgstr_w(fd.cFileName)); |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1371 | |
| 1372 | /* Build src & dest name */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1373 | strcpyW(src, drive); |
| 1374 | strcatW(src, dir); |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1375 | |
| 1376 | /* See if dest is an existing directory */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1377 | attribs = GetFileAttributesW(output); |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1378 | if (attribs != INVALID_FILE_ATTRIBUTES && |
| 1379 | (attribs & FILE_ATTRIBUTE_DIRECTORY)) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1380 | strcpyW(dest, output); |
| 1381 | strcatW(dest, slashW); |
| 1382 | strcatW(dest, fd.cFileName); |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1383 | } else { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1384 | strcpyW(dest, output); |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1385 | } |
| 1386 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1387 | strcatW(src, fd.cFileName); |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1388 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1389 | WINE_TRACE("Source '%s'\n", wine_dbgstr_w(src)); |
| 1390 | WINE_TRACE("Dest '%s'\n", wine_dbgstr_w(dest)); |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1391 | |
| 1392 | /* Check if file is read only, otherwise move it */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1393 | attribs = GetFileAttributesW(src); |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1394 | if ((attribs != INVALID_FILE_ATTRIBUTES) && |
| 1395 | (attribs & FILE_ATTRIBUTE_READONLY)) { |
| 1396 | SetLastError(ERROR_ACCESS_DENIED); |
| 1397 | status = 0; |
| 1398 | } else { |
Jason Edmeades | 2f5bfc0 | 2007-04-11 22:25:53 +0100 | [diff] [blame] | 1399 | BOOL ok = TRUE; |
| 1400 | |
| 1401 | /* If destination exists, prompt unless /Y supplied */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1402 | if (GetFileAttributesW(dest) != INVALID_FILE_ATTRIBUTES) { |
Jason Edmeades | 2f5bfc0 | 2007-04-11 22:25:53 +0100 | [diff] [blame] | 1403 | BOOL force = FALSE; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1404 | WCHAR copycmd[MAXSTRING]; |
Jason Edmeades | 2f5bfc0 | 2007-04-11 22:25:53 +0100 | [diff] [blame] | 1405 | int len; |
| 1406 | |
| 1407 | /* /-Y has the highest priority, then /Y and finally the COPYCMD env. variable */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1408 | if (strstrW (quals, parmNoY)) |
Jason Edmeades | 2f5bfc0 | 2007-04-11 22:25:53 +0100 | [diff] [blame] | 1409 | force = FALSE; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1410 | else if (strstrW (quals, parmY)) |
Jason Edmeades | 2f5bfc0 | 2007-04-11 22:25:53 +0100 | [diff] [blame] | 1411 | force = TRUE; |
| 1412 | else { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1413 | const WCHAR copyCmdW[] = {'C','O','P','Y','C','M','D','\0'}; |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1414 | len = GetEnvironmentVariableW(copyCmdW, copycmd, sizeof(copycmd)/sizeof(WCHAR)); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1415 | force = (len && len < (sizeof(copycmd)/sizeof(WCHAR)) |
| 1416 | && ! lstrcmpiW (copycmd, parmY)); |
Jason Edmeades | 2f5bfc0 | 2007-04-11 22:25:53 +0100 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | /* Prompt if overwriting */ |
| 1420 | if (!force) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1421 | WCHAR question[MAXSTRING]; |
| 1422 | WCHAR yesChar[10]; |
Jason Edmeades | 2f5bfc0 | 2007-04-11 22:25:53 +0100 | [diff] [blame] | 1423 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1424 | strcpyW(yesChar, WCMD_LoadMessage(WCMD_YES)); |
Jason Edmeades | 2f5bfc0 | 2007-04-11 22:25:53 +0100 | [diff] [blame] | 1425 | |
| 1426 | /* Ask for confirmation */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1427 | wsprintfW(question, WCMD_LoadMessage(WCMD_OVERWRITE), dest); |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 1428 | ok = WCMD_ask_confirm(question, FALSE, NULL); |
Jason Edmeades | 2f5bfc0 | 2007-04-11 22:25:53 +0100 | [diff] [blame] | 1429 | |
| 1430 | /* So delete the destination prior to the move */ |
| 1431 | if (ok) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1432 | if (!DeleteFileW(dest)) { |
Jason Edmeades | 2f5bfc0 | 2007-04-11 22:25:53 +0100 | [diff] [blame] | 1433 | WCMD_print_error (); |
| 1434 | errorlevel = 1; |
| 1435 | ok = FALSE; |
| 1436 | } |
| 1437 | } |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | if (ok) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1442 | status = MoveFileW(src, dest); |
Jason Edmeades | 2f5bfc0 | 2007-04-11 22:25:53 +0100 | [diff] [blame] | 1443 | } else { |
| 1444 | status = 1; /* Anything other than 0 to prevent error msg below */ |
| 1445 | } |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | if (!status) { |
| 1449 | WCMD_print_error (); |
| 1450 | errorlevel = 1; |
| 1451 | } |
| 1452 | |
| 1453 | /* Step on to next match */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1454 | if (FindNextFileW(hff, &fd) == 0) { |
Jason Edmeades | d0a6fe1 | 2007-04-11 22:25:52 +0100 | [diff] [blame] | 1455 | FindClose(hff); |
| 1456 | hff = INVALID_HANDLE_VALUE; |
| 1457 | break; |
| 1458 | } |
| 1459 | } |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | /**************************************************************************** |
| 1463 | * WCMD_pause |
| 1464 | * |
| 1465 | * Wait for keyboard input. |
| 1466 | */ |
| 1467 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 1468 | void WCMD_pause (void) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1469 | |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 1470 | DWORD count; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1471 | WCHAR string[32]; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1472 | |
| 1473 | WCMD_output (anykey); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1474 | WCMD_ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, |
| 1475 | sizeof(string)/sizeof(WCHAR), &count, NULL); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | /**************************************************************************** |
| 1479 | * WCMD_remove_dir |
| 1480 | * |
| 1481 | * Delete a directory. |
| 1482 | */ |
| 1483 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1484 | void WCMD_remove_dir (WCHAR *command) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1485 | |
Jason Edmeades | 0efa91d | 2007-03-04 22:33:27 +0000 | [diff] [blame] | 1486 | int argno = 0; |
| 1487 | int argsProcessed = 0; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1488 | WCHAR *argN = command; |
| 1489 | static const WCHAR parmS[] = {'/','S','\0'}; |
| 1490 | static const WCHAR parmQ[] = {'/','Q','\0'}; |
Jason Edmeades | 0efa91d | 2007-03-04 22:33:27 +0000 | [diff] [blame] | 1491 | |
| 1492 | /* Loop through all args */ |
| 1493 | while (argN) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1494 | WCHAR *thisArg = WCMD_parameter (command, argno++, &argN); |
Jason Edmeades | 0efa91d | 2007-03-04 22:33:27 +0000 | [diff] [blame] | 1495 | if (argN && argN[0] != '/') { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1496 | WINE_TRACE("rd: Processing arg %s (quals:%s)\n", wine_dbgstr_w(thisArg), |
| 1497 | wine_dbgstr_w(quals)); |
Jason Edmeades | 0efa91d | 2007-03-04 22:33:27 +0000 | [diff] [blame] | 1498 | argsProcessed++; |
| 1499 | |
| 1500 | /* If subdirectory search not supplied, just try to remove |
| 1501 | and report error if it fails (eg if it contains a file) */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1502 | if (strstrW (quals, parmS) == NULL) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1503 | if (!RemoveDirectoryW(thisArg)) WCMD_print_error (); |
Jason Edmeades | 0efa91d | 2007-03-04 22:33:27 +0000 | [diff] [blame] | 1504 | |
| 1505 | /* Otherwise use ShFileOp to recursively remove a directory */ |
| 1506 | } else { |
| 1507 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1508 | SHFILEOPSTRUCTW lpDir; |
Jason Edmeades | 0efa91d | 2007-03-04 22:33:27 +0000 | [diff] [blame] | 1509 | |
| 1510 | /* Ask first */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1511 | if (strstrW (quals, parmQ) == NULL) { |
Jason Edmeades | 0efa91d | 2007-03-04 22:33:27 +0000 | [diff] [blame] | 1512 | BOOL ok; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1513 | WCHAR question[MAXSTRING]; |
| 1514 | static const WCHAR fmt[] = {'%','s',' ','\0'}; |
Jason Edmeades | 0efa91d | 2007-03-04 22:33:27 +0000 | [diff] [blame] | 1515 | |
| 1516 | /* Ask for confirmation */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1517 | wsprintfW(question, fmt, thisArg); |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 1518 | ok = WCMD_ask_confirm(question, TRUE, NULL); |
Jason Edmeades | 0efa91d | 2007-03-04 22:33:27 +0000 | [diff] [blame] | 1519 | |
| 1520 | /* Abort if answer is 'N' */ |
| 1521 | if (!ok) return; |
| 1522 | } |
| 1523 | |
| 1524 | /* Do the delete */ |
| 1525 | lpDir.hwnd = NULL; |
| 1526 | lpDir.pTo = NULL; |
| 1527 | lpDir.pFrom = thisArg; |
| 1528 | lpDir.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI; |
| 1529 | lpDir.wFunc = FO_DELETE; |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1530 | if (SHFileOperationW(&lpDir)) WCMD_print_error (); |
Jason Edmeades | 0efa91d | 2007-03-04 22:33:27 +0000 | [diff] [blame] | 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | /* Handle no valid args */ |
| 1536 | if (argsProcessed == 0) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 1537 | WCMD_output (WCMD_LoadMessage(WCMD_NOARG)); |
Markus Amsler | 765ff5d | 2006-10-31 21:11:28 +0100 | [diff] [blame] | 1538 | return; |
| 1539 | } |
Jason Edmeades | 69194ce | 2007-02-26 23:04:40 +0000 | [diff] [blame] | 1540 | |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | /**************************************************************************** |
| 1544 | * WCMD_rename |
| 1545 | * |
| 1546 | * Rename a file. |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1547 | */ |
| 1548 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 1549 | void WCMD_rename (void) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1550 | |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1551 | int status; |
| 1552 | HANDLE hff; |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1553 | WIN32_FIND_DATAW fd; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1554 | WCHAR input[MAX_PATH]; |
| 1555 | WCHAR *dotDst = NULL; |
| 1556 | WCHAR drive[10]; |
| 1557 | WCHAR dir[MAX_PATH]; |
| 1558 | WCHAR fname[MAX_PATH]; |
| 1559 | WCHAR ext[MAX_PATH]; |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1560 | DWORD attribs; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1561 | |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1562 | errorlevel = 0; |
| 1563 | |
| 1564 | /* Must be at least two args */ |
Markus Amsler | 765ff5d | 2006-10-31 21:11:28 +0100 | [diff] [blame] | 1565 | if (param1[0] == 0x00 || param2[0] == 0x00) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 1566 | WCMD_output (WCMD_LoadMessage(WCMD_NOARG)); |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1567 | errorlevel = 1; |
Markus Amsler | 765ff5d | 2006-10-31 21:11:28 +0100 | [diff] [blame] | 1568 | return; |
| 1569 | } |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1570 | |
| 1571 | /* Destination cannot contain a drive letter or directory separator */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1572 | if ((strchrW(param1,':') != NULL) || (strchrW(param1,'\\') != NULL)) { |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1573 | SetLastError(ERROR_INVALID_PARAMETER); |
| 1574 | WCMD_print_error(); |
| 1575 | errorlevel = 1; |
| 1576 | return; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1577 | } |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1578 | |
| 1579 | /* Convert partial path to full path */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1580 | GetFullPathNameW(param1, sizeof(input)/sizeof(WCHAR), input, NULL); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1581 | WINE_TRACE("Rename from '%s'('%s') to '%s'\n", wine_dbgstr_w(input), |
| 1582 | wine_dbgstr_w(param1), wine_dbgstr_w(param2)); |
| 1583 | dotDst = strchrW(param2, '.'); |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1584 | |
| 1585 | /* Split into components */ |
| 1586 | WCMD_splitpath(input, drive, dir, fname, ext); |
| 1587 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1588 | hff = FindFirstFileW(input, &fd); |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1589 | while (hff != INVALID_HANDLE_VALUE) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1590 | WCHAR dest[MAX_PATH]; |
| 1591 | WCHAR src[MAX_PATH]; |
| 1592 | WCHAR *dotSrc = NULL; |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1593 | int dirLen; |
| 1594 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1595 | WINE_TRACE("Processing file '%s'\n", wine_dbgstr_w(fd.cFileName)); |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1596 | |
| 1597 | /* FIXME: If dest name or extension is *, replace with filename/ext |
| 1598 | part otherwise use supplied name. This supports: |
| 1599 | ren *.fred *.jim |
| 1600 | ren jim.* fred.* etc |
Francois Gouget | 4c8e218 | 2008-02-13 22:11:01 +0100 | [diff] [blame] | 1601 | However, windows has a more complex algorithm supporting eg |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1602 | ?'s and *'s mid name */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1603 | dotSrc = strchrW(fd.cFileName, '.'); |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1604 | |
| 1605 | /* Build src & dest name */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1606 | strcpyW(src, drive); |
| 1607 | strcatW(src, dir); |
| 1608 | strcpyW(dest, src); |
| 1609 | dirLen = strlenW(src); |
| 1610 | strcatW(src, fd.cFileName); |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1611 | |
| 1612 | /* Build name */ |
| 1613 | if (param2[0] == '*') { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1614 | strcatW(dest, fd.cFileName); |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1615 | if (dotSrc) dest[dirLen + (dotSrc - fd.cFileName)] = 0x00; |
| 1616 | } else { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1617 | strcatW(dest, param2); |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1618 | if (dotDst) dest[dirLen + (dotDst - param2)] = 0x00; |
| 1619 | } |
| 1620 | |
| 1621 | /* Build Extension */ |
| 1622 | if (dotDst && (*(dotDst+1)=='*')) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1623 | if (dotSrc) strcatW(dest, dotSrc); |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1624 | } else if (dotDst) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1625 | if (dotDst) strcatW(dest, dotDst); |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1626 | } |
| 1627 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1628 | WINE_TRACE("Source '%s'\n", wine_dbgstr_w(src)); |
| 1629 | WINE_TRACE("Dest '%s'\n", wine_dbgstr_w(dest)); |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1630 | |
| 1631 | /* Check if file is read only, otherwise move it */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1632 | attribs = GetFileAttributesW(src); |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1633 | if ((attribs != INVALID_FILE_ATTRIBUTES) && |
| 1634 | (attribs & FILE_ATTRIBUTE_READONLY)) { |
| 1635 | SetLastError(ERROR_ACCESS_DENIED); |
| 1636 | status = 0; |
| 1637 | } else { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1638 | status = MoveFileW(src, dest); |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | if (!status) { |
| 1642 | WCMD_print_error (); |
| 1643 | errorlevel = 1; |
| 1644 | } |
| 1645 | |
| 1646 | /* Step on to next match */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1647 | if (FindNextFileW(hff, &fd) == 0) { |
Jason Edmeades | 32fc366 | 2007-04-11 22:25:51 +0100 | [diff] [blame] | 1648 | FindClose(hff); |
| 1649 | hff = INVALID_HANDLE_VALUE; |
| 1650 | break; |
| 1651 | } |
| 1652 | } |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | /***************************************************************************** |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1656 | * WCMD_dupenv |
| 1657 | * |
| 1658 | * Make a copy of the environment. |
| 1659 | */ |
Eric Pouech | 5c2a891 | 2004-11-29 18:00:10 +0000 | [diff] [blame] | 1660 | static WCHAR *WCMD_dupenv( const WCHAR *env ) |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1661 | { |
| 1662 | WCHAR *env_copy; |
| 1663 | int len; |
| 1664 | |
| 1665 | if( !env ) |
| 1666 | return NULL; |
| 1667 | |
| 1668 | len = 0; |
| 1669 | while ( env[len] ) |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1670 | len += (strlenW(&env[len]) + 1); |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1671 | |
| 1672 | env_copy = LocalAlloc (LMEM_FIXED, (len+1) * sizeof (WCHAR) ); |
| 1673 | if (!env_copy) |
| 1674 | { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 1675 | WINE_ERR("out of memory\n"); |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1676 | return env_copy; |
| 1677 | } |
| 1678 | memcpy (env_copy, env, len*sizeof (WCHAR)); |
| 1679 | env_copy[len] = 0; |
| 1680 | |
| 1681 | return env_copy; |
| 1682 | } |
| 1683 | |
| 1684 | /***************************************************************************** |
| 1685 | * WCMD_setlocal |
| 1686 | * |
| 1687 | * setlocal pushes the environment onto a stack |
| 1688 | * Save the environment as unicode so we don't screw anything up. |
| 1689 | */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1690 | void WCMD_setlocal (const WCHAR *s) { |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1691 | WCHAR *env; |
| 1692 | struct env_stack *env_copy; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1693 | WCHAR cwd[MAX_PATH]; |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1694 | |
| 1695 | /* DISABLEEXTENSIONS ignored */ |
| 1696 | |
| 1697 | env_copy = LocalAlloc (LMEM_FIXED, sizeof (struct env_stack)); |
| 1698 | if( !env_copy ) |
| 1699 | { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 1700 | WINE_ERR ("out of memory\n"); |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1701 | return; |
| 1702 | } |
| 1703 | |
| 1704 | env = GetEnvironmentStringsW (); |
| 1705 | |
| 1706 | env_copy->strings = WCMD_dupenv (env); |
| 1707 | if (env_copy->strings) |
| 1708 | { |
| 1709 | env_copy->next = saved_environment; |
| 1710 | saved_environment = env_copy; |
Jason Edmeades | 86140e3 | 2007-03-08 00:48:49 +0000 | [diff] [blame] | 1711 | |
| 1712 | /* Save the current drive letter */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1713 | GetCurrentDirectoryW(MAX_PATH, cwd); |
Francois Gouget | 540d818 | 2007-03-12 10:35:13 +0100 | [diff] [blame] | 1714 | env_copy->u.cwd = cwd[0]; |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1715 | } |
| 1716 | else |
| 1717 | LocalFree (env_copy); |
| 1718 | |
| 1719 | FreeEnvironmentStringsW (env); |
Jason Edmeades | 86140e3 | 2007-03-08 00:48:49 +0000 | [diff] [blame] | 1720 | |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | /***************************************************************************** |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1724 | * WCMD_endlocal |
| 1725 | * |
| 1726 | * endlocal pops the environment off a stack |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1727 | * Note: When searching for '=', search from WCHAR position 1, to handle |
Jason Edmeades | 86140e3 | 2007-03-08 00:48:49 +0000 | [diff] [blame] | 1728 | * special internal environment variables =C:, =D: etc |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1729 | */ |
| 1730 | void WCMD_endlocal (void) { |
| 1731 | WCHAR *env, *old, *p; |
| 1732 | struct env_stack *temp; |
| 1733 | int len, n; |
| 1734 | |
| 1735 | if (!saved_environment) |
| 1736 | return; |
| 1737 | |
| 1738 | /* pop the old environment from the stack */ |
| 1739 | temp = saved_environment; |
| 1740 | saved_environment = temp->next; |
| 1741 | |
| 1742 | /* delete the current environment, totally */ |
| 1743 | env = GetEnvironmentStringsW (); |
| 1744 | old = WCMD_dupenv (GetEnvironmentStringsW ()); |
| 1745 | len = 0; |
| 1746 | while (old[len]) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1747 | n = strlenW(&old[len]) + 1; |
| 1748 | p = strchrW(&old[len] + 1, '='); |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1749 | if (p) |
| 1750 | { |
| 1751 | *p++ = 0; |
| 1752 | SetEnvironmentVariableW (&old[len], NULL); |
| 1753 | } |
| 1754 | len += n; |
| 1755 | } |
| 1756 | LocalFree (old); |
| 1757 | FreeEnvironmentStringsW (env); |
Jason Edmeades | fda7229 | 2007-02-27 23:18:57 +0000 | [diff] [blame] | 1758 | |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1759 | /* restore old environment */ |
| 1760 | env = temp->strings; |
| 1761 | len = 0; |
| 1762 | while (env[len]) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1763 | n = strlenW(&env[len]) + 1; |
| 1764 | p = strchrW(&env[len] + 1, '='); |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1765 | if (p) |
| 1766 | { |
| 1767 | *p++ = 0; |
| 1768 | SetEnvironmentVariableW (&env[len], p); |
| 1769 | } |
| 1770 | len += n; |
| 1771 | } |
Jason Edmeades | 86140e3 | 2007-03-08 00:48:49 +0000 | [diff] [blame] | 1772 | |
| 1773 | /* Restore current drive letter */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1774 | if (IsCharAlphaW(temp->u.cwd)) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1775 | WCHAR envvar[4]; |
| 1776 | WCHAR cwd[MAX_PATH]; |
| 1777 | static const WCHAR fmt[] = {'=','%','c',':','\0'}; |
| 1778 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1779 | wsprintfW(envvar, fmt, temp->u.cwd); |
| 1780 | if (GetEnvironmentVariableW(envvar, cwd, MAX_PATH)) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1781 | WINE_TRACE("Resetting cwd to %s\n", wine_dbgstr_w(cwd)); |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1782 | SetCurrentDirectoryW(cwd); |
Jason Edmeades | 86140e3 | 2007-03-08 00:48:49 +0000 | [diff] [blame] | 1783 | } |
| 1784 | } |
| 1785 | |
Mike McCormack | 9643b79 | 2004-03-22 22:56:58 +0000 | [diff] [blame] | 1786 | LocalFree (env); |
| 1787 | LocalFree (temp); |
| 1788 | } |
| 1789 | |
| 1790 | /***************************************************************************** |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1791 | * WCMD_setshow_attrib |
| 1792 | * |
| 1793 | * Display and optionally sets DOS attributes on a file or directory |
| 1794 | * |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1795 | */ |
| 1796 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 1797 | void WCMD_setshow_attrib (void) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1798 | |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 1799 | DWORD count; |
| 1800 | HANDLE hff; |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1801 | WIN32_FIND_DATAW fd; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1802 | WCHAR flags[9] = {' ',' ',' ',' ',' ',' ',' ',' ','\0'}; |
Dan Kegel | 81e5c76 | 2009-09-24 10:52:36 -0700 | [diff] [blame] | 1803 | WCHAR *name = param1; |
| 1804 | DWORD attrib_set=0; |
| 1805 | DWORD attrib_clear=0; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1806 | |
Dan Kegel | 81e5c76 | 2009-09-24 10:52:36 -0700 | [diff] [blame] | 1807 | if (param1[0] == '+' || param1[0] == '-') { |
| 1808 | DWORD attrib = 0; |
| 1809 | /* FIXME: the real cmd can handle many more than two args; this should be in a loop */ |
| 1810 | switch (param1[1]) { |
| 1811 | case 'H': case 'h': attrib |= FILE_ATTRIBUTE_HIDDEN; break; |
| 1812 | case 'S': case 's': attrib |= FILE_ATTRIBUTE_SYSTEM; break; |
| 1813 | case 'R': case 'r': attrib |= FILE_ATTRIBUTE_READONLY; break; |
| 1814 | case 'A': case 'a': attrib |= FILE_ATTRIBUTE_ARCHIVE; break; |
| 1815 | default: |
| 1816 | WCMD_output (WCMD_LoadMessage(WCMD_NYI)); |
| 1817 | return; |
| 1818 | } |
| 1819 | switch (param1[0]) { |
| 1820 | case '+': attrib_set = attrib; break; |
| 1821 | case '-': attrib_clear = attrib; break; |
| 1822 | } |
| 1823 | name = param2; |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
Dan Kegel | 81e5c76 | 2009-09-24 10:52:36 -0700 | [diff] [blame] | 1826 | if (strlenW(name) == 0) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1827 | static const WCHAR slashStarW[] = {'\\','*','\0'}; |
| 1828 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1829 | GetCurrentDirectoryW(sizeof(param2)/sizeof(WCHAR), name); |
Dan Kegel | 81e5c76 | 2009-09-24 10:52:36 -0700 | [diff] [blame] | 1830 | strcatW (name, slashStarW); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1833 | hff = FindFirstFileW(name, &fd); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1834 | if (hff == INVALID_HANDLE_VALUE) { |
Dan Kegel | 81e5c76 | 2009-09-24 10:52:36 -0700 | [diff] [blame] | 1835 | WCMD_output (WCMD_LoadMessage(WCMD_FILENOTFOUND), name); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1836 | } |
| 1837 | else { |
| 1838 | do { |
Dan Kegel | 81e5c76 | 2009-09-24 10:52:36 -0700 | [diff] [blame] | 1839 | if (attrib_set || attrib_clear) { |
| 1840 | fd.dwFileAttributes &= ~attrib_clear; |
| 1841 | fd.dwFileAttributes |= attrib_set; |
| 1842 | if (!fd.dwFileAttributes) |
| 1843 | fd.dwFileAttributes |= FILE_ATTRIBUTE_NORMAL; |
| 1844 | SetFileAttributesW(name, fd.dwFileAttributes); |
| 1845 | } else { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1846 | static const WCHAR fmt[] = {'%','s',' ',' ',' ','%','s','\n','\0'}; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1847 | if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) { |
| 1848 | flags[0] = 'H'; |
| 1849 | } |
| 1850 | if (fd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) { |
| 1851 | flags[1] = 'S'; |
| 1852 | } |
| 1853 | if (fd.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) { |
| 1854 | flags[2] = 'A'; |
| 1855 | } |
| 1856 | if (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) { |
| 1857 | flags[3] = 'R'; |
| 1858 | } |
| 1859 | if (fd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) { |
| 1860 | flags[4] = 'T'; |
| 1861 | } |
| 1862 | if (fd.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) { |
| 1863 | flags[5] = 'C'; |
| 1864 | } |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1865 | WCMD_output (fmt, flags, fd.cFileName); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1866 | for (count=0; count < 8; count++) flags[count] = ' '; |
| 1867 | } |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1868 | } while (FindNextFileW(hff, &fd) != 0); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1869 | } |
| 1870 | FindClose (hff); |
| 1871 | } |
| 1872 | |
| 1873 | /***************************************************************************** |
| 1874 | * WCMD_setshow_default |
| 1875 | * |
| 1876 | * Set/Show the current default directory |
| 1877 | */ |
| 1878 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1879 | void WCMD_setshow_default (WCHAR *command) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1880 | |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 1881 | BOOL status; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1882 | WCHAR string[1024]; |
| 1883 | WCHAR cwd[1024]; |
| 1884 | WCHAR *pos; |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1885 | WIN32_FIND_DATAW fd; |
Jason Edmeades | 5c8c694 | 2007-03-08 00:43:09 +0000 | [diff] [blame] | 1886 | HANDLE hff; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1887 | static const WCHAR parmD[] = {'/','D','\0'}; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1888 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1889 | WINE_TRACE("Request change to directory '%s'\n", wine_dbgstr_w(command)); |
Jason Edmeades | ffbaede | 2007-03-08 00:50:14 +0000 | [diff] [blame] | 1890 | |
| 1891 | /* Skip /D and trailing whitespace if on the front of the command line */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1892 | if (CompareStringW(LOCALE_USER_DEFAULT, |
Jason Edmeades | ffbaede | 2007-03-08 00:50:14 +0000 | [diff] [blame] | 1893 | NORM_IGNORECASE | SORT_STRINGSORT, |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1894 | command, 2, parmD, -1) == 2) { |
Jason Edmeades | ffbaede | 2007-03-08 00:50:14 +0000 | [diff] [blame] | 1895 | command += 2; |
| 1896 | while (*command && *command==' ') command++; |
| 1897 | } |
| 1898 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1899 | GetCurrentDirectoryW(sizeof(cwd)/sizeof(WCHAR), cwd); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1900 | if (strlenW(command) == 0) { |
| 1901 | strcatW (cwd, newline); |
Jason Edmeades | ffbaede | 2007-03-08 00:50:14 +0000 | [diff] [blame] | 1902 | WCMD_output (cwd); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1903 | } |
| 1904 | else { |
Jason Edmeades | eb6d084 | 2007-03-08 00:42:33 +0000 | [diff] [blame] | 1905 | /* Remove any double quotes, which may be in the |
| 1906 | middle, eg. cd "C:\Program Files"\Microsoft is ok */ |
| 1907 | pos = string; |
| 1908 | while (*command) { |
| 1909 | if (*command != '"') *pos++ = *command; |
| 1910 | command++; |
| 1911 | } |
| 1912 | *pos = 0x00; |
| 1913 | |
Francois Gouget | 8a18e0e | 2008-04-07 13:01:02 +0200 | [diff] [blame] | 1914 | /* Search for appropriate directory */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1915 | WINE_TRACE("Looking for directory '%s'\n", wine_dbgstr_w(string)); |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1916 | hff = FindFirstFileW(string, &fd); |
Jason Edmeades | 5c8c694 | 2007-03-08 00:43:09 +0000 | [diff] [blame] | 1917 | while (hff != INVALID_HANDLE_VALUE) { |
| 1918 | if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1919 | WCHAR fpath[MAX_PATH]; |
| 1920 | WCHAR drive[10]; |
| 1921 | WCHAR dir[MAX_PATH]; |
| 1922 | WCHAR fname[MAX_PATH]; |
| 1923 | WCHAR ext[MAX_PATH]; |
| 1924 | static const WCHAR fmt[] = {'%','s','%','s','%','s','\0'}; |
Jason Edmeades | 5c8c694 | 2007-03-08 00:43:09 +0000 | [diff] [blame] | 1925 | |
| 1926 | /* Convert path into actual directory spec */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1927 | GetFullPathNameW(string, sizeof(fpath)/sizeof(WCHAR), fpath, NULL); |
Jason Edmeades | 5c8c694 | 2007-03-08 00:43:09 +0000 | [diff] [blame] | 1928 | WCMD_splitpath(fpath, drive, dir, fname, ext); |
| 1929 | |
| 1930 | /* Rebuild path */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1931 | wsprintfW(string, fmt, drive, dir, fd.cFileName); |
Jason Edmeades | 5c8c694 | 2007-03-08 00:43:09 +0000 | [diff] [blame] | 1932 | |
| 1933 | FindClose(hff); |
| 1934 | hff = INVALID_HANDLE_VALUE; |
| 1935 | break; |
| 1936 | } |
| 1937 | |
| 1938 | /* Step on to next match */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1939 | if (FindNextFileW(hff, &fd) == 0) { |
Jason Edmeades | 5c8c694 | 2007-03-08 00:43:09 +0000 | [diff] [blame] | 1940 | FindClose(hff); |
| 1941 | hff = INVALID_HANDLE_VALUE; |
| 1942 | break; |
| 1943 | } |
| 1944 | } |
| 1945 | |
Jason Edmeades | eb6d084 | 2007-03-08 00:42:33 +0000 | [diff] [blame] | 1946 | /* Change to that directory */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1947 | WINE_TRACE("Really changing to directory '%s'\n", wine_dbgstr_w(string)); |
Jason Edmeades | 2b03d7d | 2007-03-08 00:47:45 +0000 | [diff] [blame] | 1948 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1949 | status = SetCurrentDirectoryW(string); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1950 | if (!status) { |
Jason Edmeades | 121a830 | 2007-03-08 00:43:32 +0000 | [diff] [blame] | 1951 | errorlevel = 1; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1952 | WCMD_print_error (); |
| 1953 | return; |
Jason Edmeades | ffbaede | 2007-03-08 00:50:14 +0000 | [diff] [blame] | 1954 | } else { |
| 1955 | |
Jason Edmeades | 4492334 | 2008-03-03 23:14:30 +0000 | [diff] [blame] | 1956 | /* Save away the actual new directory, to store as current location */ |
| 1957 | GetCurrentDirectoryW (sizeof(string)/sizeof(WCHAR), string); |
| 1958 | |
Jason Edmeades | ffbaede | 2007-03-08 00:50:14 +0000 | [diff] [blame] | 1959 | /* Restore old directory if drive letter would change, and |
| 1960 | CD x:\directory /D (or pushd c:\directory) not supplied */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1961 | if ((strstrW(quals, parmD) == NULL) && |
Jason Edmeades | ffbaede | 2007-03-08 00:50:14 +0000 | [diff] [blame] | 1962 | (param1[1] == ':') && (toupper(param1[0]) != toupper(cwd[0]))) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1963 | SetCurrentDirectoryW(cwd); |
Jason Edmeades | ffbaede | 2007-03-08 00:50:14 +0000 | [diff] [blame] | 1964 | } |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1965 | } |
Jason Edmeades | 2b03d7d | 2007-03-08 00:47:45 +0000 | [diff] [blame] | 1966 | |
Jason Edmeades | ffbaede | 2007-03-08 00:50:14 +0000 | [diff] [blame] | 1967 | /* Set special =C: type environment variable, for drive letter of |
| 1968 | change of directory, even if path was restored due to missing |
| 1969 | /D (allows changing drive letter when not resident on that |
| 1970 | drive */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1971 | if ((string[1] == ':') && IsCharAlphaW(string[0])) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1972 | WCHAR env[4]; |
| 1973 | strcpyW(env, equalW); |
| 1974 | memcpy(env+1, string, 2 * sizeof(WCHAR)); |
Jason Edmeades | 2b03d7d | 2007-03-08 00:47:45 +0000 | [diff] [blame] | 1975 | env[3] = 0x00; |
Alexandre Julliard | abc5fef | 2007-06-08 12:54:21 +0200 | [diff] [blame] | 1976 | WINE_TRACE("Setting '%s' to '%s'\n", wine_dbgstr_w(env), wine_dbgstr_w(string)); |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1977 | SetEnvironmentVariableW(env, string); |
Jason Edmeades | 2b03d7d | 2007-03-08 00:47:45 +0000 | [diff] [blame] | 1978 | } |
| 1979 | |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1980 | } |
| 1981 | return; |
| 1982 | } |
| 1983 | |
| 1984 | /**************************************************************************** |
| 1985 | * WCMD_setshow_date |
| 1986 | * |
| 1987 | * Set/Show the system date |
| 1988 | * FIXME: Can't change date yet |
| 1989 | */ |
| 1990 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 1991 | void WCMD_setshow_date (void) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1992 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1993 | WCHAR curdate[64], buffer[64]; |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 1994 | DWORD count; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1995 | static const WCHAR parmT[] = {'/','T','\0'}; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 1996 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1997 | if (strlenW(param1) == 0) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 1998 | if (GetDateFormatW(LOCALE_USER_DEFAULT, 0, NULL, NULL, |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 1999 | curdate, sizeof(curdate)/sizeof(WCHAR))) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2000 | WCMD_output (WCMD_LoadMessage(WCMD_CURRENTDATE), curdate); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2001 | if (strstrW (quals, parmT) == NULL) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2002 | WCMD_output (WCMD_LoadMessage(WCMD_NEWDATE)); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2003 | WCMD_ReadFile (GetStdHandle(STD_INPUT_HANDLE), |
| 2004 | buffer, sizeof(buffer)/sizeof(WCHAR), &count, NULL); |
Jason Edmeades | 988ef41 | 2007-03-08 00:45:05 +0000 | [diff] [blame] | 2005 | if (count > 2) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2006 | WCMD_output (WCMD_LoadMessage(WCMD_NYI)); |
Jason Edmeades | 988ef41 | 2007-03-08 00:45:05 +0000 | [diff] [blame] | 2007 | } |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2008 | } |
| 2009 | } |
| 2010 | else WCMD_print_error (); |
| 2011 | } |
| 2012 | else { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2013 | WCMD_output (WCMD_LoadMessage(WCMD_NYI)); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2014 | } |
| 2015 | } |
| 2016 | |
| 2017 | /**************************************************************************** |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2018 | * WCMD_compare |
| 2019 | */ |
Eric Pouech | 5c2a891 | 2004-11-29 18:00:10 +0000 | [diff] [blame] | 2020 | static int WCMD_compare( const void *a, const void *b ) |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2021 | { |
| 2022 | int r; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2023 | const WCHAR * const *str_a = a, * const *str_b = b; |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2024 | r = CompareStringW( LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2025 | *str_a, -1, *str_b, -1 ); |
| 2026 | if( r == CSTR_LESS_THAN ) return -1; |
| 2027 | if( r == CSTR_GREATER_THAN ) return 1; |
| 2028 | return 0; |
| 2029 | } |
| 2030 | |
| 2031 | /**************************************************************************** |
| 2032 | * WCMD_setshow_sortenv |
| 2033 | * |
| 2034 | * sort variables into order for display |
Jason Edmeades | 1c632cd | 2007-02-26 23:06:11 +0000 | [diff] [blame] | 2035 | * Optionally only display those who start with a stub |
| 2036 | * returns the count displayed |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2037 | */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2038 | static int WCMD_setshow_sortenv(const WCHAR *s, const WCHAR *stub) |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2039 | { |
Jason Edmeades | 1c632cd | 2007-02-26 23:06:11 +0000 | [diff] [blame] | 2040 | UINT count=0, len=0, i, displayedcount=0, stublen=0; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2041 | const WCHAR **str; |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2042 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2043 | if (stub) stublen = strlenW(stub); |
Jason Edmeades | 1c632cd | 2007-02-26 23:06:11 +0000 | [diff] [blame] | 2044 | |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2045 | /* count the number of strings, and the total length */ |
| 2046 | while ( s[len] ) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2047 | len += (strlenW(&s[len]) + 1); |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2048 | count++; |
| 2049 | } |
| 2050 | |
| 2051 | /* add the strings to an array */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2052 | str = LocalAlloc (LMEM_FIXED | LMEM_ZEROINIT, count * sizeof (WCHAR*) ); |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2053 | if( !str ) |
Jason Edmeades | 1c632cd | 2007-02-26 23:06:11 +0000 | [diff] [blame] | 2054 | return 0; |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2055 | str[0] = s; |
| 2056 | for( i=1; i<count; i++ ) |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2057 | str[i] = str[i-1] + strlenW(str[i-1]) + 1; |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2058 | |
| 2059 | /* sort the array */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2060 | qsort( str, count, sizeof (WCHAR*), WCMD_compare ); |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2061 | |
| 2062 | /* print it */ |
Rein Klazes | a18ea3d | 2005-12-01 15:58:16 +0100 | [diff] [blame] | 2063 | for( i=0; i<count; i++ ) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2064 | if (!stub || CompareStringW(LOCALE_USER_DEFAULT, |
Jason Edmeades | 1c632cd | 2007-02-26 23:06:11 +0000 | [diff] [blame] | 2065 | NORM_IGNORECASE | SORT_STRINGSORT, |
| 2066 | str[i], stublen, stub, -1) == 2) { |
Jason Edmeades | d1317f5 | 2007-03-08 00:48:17 +0000 | [diff] [blame] | 2067 | /* Don't display special internal variables */ |
| 2068 | if (str[i][0] != '=') { |
| 2069 | WCMD_output_asis(str[i]); |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2070 | WCMD_output_asis(newline); |
Jason Edmeades | d1317f5 | 2007-03-08 00:48:17 +0000 | [diff] [blame] | 2071 | displayedcount++; |
| 2072 | } |
Jason Edmeades | 1c632cd | 2007-02-26 23:06:11 +0000 | [diff] [blame] | 2073 | } |
Rein Klazes | a18ea3d | 2005-12-01 15:58:16 +0100 | [diff] [blame] | 2074 | } |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2075 | |
| 2076 | LocalFree( str ); |
Jason Edmeades | 1c632cd | 2007-02-26 23:06:11 +0000 | [diff] [blame] | 2077 | return displayedcount; |
Mike McCormack | bbe0e2c | 2003-12-30 19:17:31 +0000 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | /**************************************************************************** |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2081 | * WCMD_setshow_env |
| 2082 | * |
| 2083 | * Set/Show the environment variables |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2084 | */ |
| 2085 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2086 | void WCMD_setshow_env (WCHAR *s) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2087 | |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 2088 | LPVOID env; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2089 | WCHAR *p; |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 2090 | int status; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2091 | static const WCHAR parmP[] = {'/','P','\0'}; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2092 | |
Jason Edmeades | 87f0293 | 2007-03-13 00:11:31 +0000 | [diff] [blame] | 2093 | errorlevel = 0; |
Jason Edmeades | 4b1ef91 | 2007-03-13 00:11:04 +0000 | [diff] [blame] | 2094 | if (param1[0] == 0x00 && quals[0] == 0x00) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2095 | env = GetEnvironmentStringsW(); |
Jason Edmeades | 1c632cd | 2007-02-26 23:06:11 +0000 | [diff] [blame] | 2096 | WCMD_setshow_sortenv( env, NULL ); |
Jason Edmeades | 4b1ef91 | 2007-03-13 00:11:04 +0000 | [diff] [blame] | 2097 | return; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2098 | } |
Jason Edmeades | 4b1ef91 | 2007-03-13 00:11:04 +0000 | [diff] [blame] | 2099 | |
| 2100 | /* See if /P supplied, and if so echo the prompt, and read in a reply */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2101 | if (CompareStringW(LOCALE_USER_DEFAULT, |
Jason Edmeades | 4b1ef91 | 2007-03-13 00:11:04 +0000 | [diff] [blame] | 2102 | NORM_IGNORECASE | SORT_STRINGSORT, |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2103 | s, 2, parmP, -1) == 2) { |
| 2104 | WCHAR string[MAXSTRING]; |
Jason Edmeades | 4b1ef91 | 2007-03-13 00:11:04 +0000 | [diff] [blame] | 2105 | DWORD count; |
| 2106 | |
| 2107 | s += 2; |
| 2108 | while (*s && *s==' ') s++; |
André Hentschel | 765d9a1 | 2009-08-28 18:34:32 +0200 | [diff] [blame] | 2109 | if (*s=='\"') |
| 2110 | WCMD_opt_s_strip_quotes(s); |
Jason Edmeades | 4b1ef91 | 2007-03-13 00:11:04 +0000 | [diff] [blame] | 2111 | |
| 2112 | /* If no parameter, or no '=' sign, return an error */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2113 | if (!(*s) || ((p = strchrW (s, '=')) == NULL )) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2114 | WCMD_output (WCMD_LoadMessage(WCMD_NOARG)); |
Jason Edmeades | 4b1ef91 | 2007-03-13 00:11:04 +0000 | [diff] [blame] | 2115 | return; |
| 2116 | } |
| 2117 | |
| 2118 | /* Output the prompt */ |
| 2119 | *p++ = '\0'; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2120 | if (strlenW(p) != 0) WCMD_output(p); |
Jason Edmeades | 4b1ef91 | 2007-03-13 00:11:04 +0000 | [diff] [blame] | 2121 | |
| 2122 | /* Read the reply */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2123 | WCMD_ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, |
| 2124 | sizeof(string)/sizeof(WCHAR), &count, NULL); |
Jason Edmeades | 4b1ef91 | 2007-03-13 00:11:04 +0000 | [diff] [blame] | 2125 | if (count > 1) { |
| 2126 | string[count-1] = '\0'; /* ReadFile output is not null-terminated! */ |
| 2127 | if (string[count-2] == '\r') string[count-2] = '\0'; /* Under Windoze we get CRLF! */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2128 | WINE_TRACE("set /p: Setting var '%s' to '%s'\n", wine_dbgstr_w(s), |
| 2129 | wine_dbgstr_w(string)); |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2130 | status = SetEnvironmentVariableW(s, string); |
Jason Edmeades | 4b1ef91 | 2007-03-13 00:11:04 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | } else { |
Jason Edmeades | 87f0293 | 2007-03-13 00:11:31 +0000 | [diff] [blame] | 2134 | DWORD gle; |
André Hentschel | 765d9a1 | 2009-08-28 18:34:32 +0200 | [diff] [blame] | 2135 | |
| 2136 | if (*s=='\"') |
| 2137 | WCMD_opt_s_strip_quotes(s); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2138 | p = strchrW (s, '='); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2139 | if (p == NULL) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2140 | env = GetEnvironmentStringsW(); |
Jason Edmeades | 1c632cd | 2007-02-26 23:06:11 +0000 | [diff] [blame] | 2141 | if (WCMD_setshow_sortenv( env, s ) == 0) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2142 | WCMD_output (WCMD_LoadMessage(WCMD_MISSINGENV), s); |
Jason Edmeades | 87f0293 | 2007-03-13 00:11:31 +0000 | [diff] [blame] | 2143 | errorlevel = 1; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 2144 | } |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2145 | return; |
| 2146 | } |
| 2147 | *p++ = '\0'; |
Jason Edmeades | a5910f4 | 2000-08-01 02:14:33 +0000 | [diff] [blame] | 2148 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2149 | if (strlenW(p) == 0) p = NULL; |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2150 | status = SetEnvironmentVariableW(s, p); |
Jason Edmeades | 87f0293 | 2007-03-13 00:11:31 +0000 | [diff] [blame] | 2151 | gle = GetLastError(); |
| 2152 | if ((!status) & (gle == ERROR_ENVVAR_NOT_FOUND)) { |
| 2153 | errorlevel = 1; |
| 2154 | } else if ((!status)) WCMD_print_error(); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2155 | } |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | /**************************************************************************** |
| 2159 | * WCMD_setshow_path |
| 2160 | * |
| 2161 | * Set/Show the path environment variable |
| 2162 | */ |
| 2163 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2164 | void WCMD_setshow_path (WCHAR *command) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2165 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2166 | WCHAR string[1024]; |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 2167 | DWORD status; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2168 | static const WCHAR pathW[] = {'P','A','T','H','\0'}; |
| 2169 | static const WCHAR pathEqW[] = {'P','A','T','H','=','\0'}; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2170 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2171 | if (strlenW(param1) == 0) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2172 | status = GetEnvironmentVariableW(pathW, string, sizeof(string)/sizeof(WCHAR)); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2173 | if (status != 0) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2174 | WCMD_output_asis ( pathEqW); |
Rein Klazes | 0bf64a4 | 2005-12-02 11:25:51 +0100 | [diff] [blame] | 2175 | WCMD_output_asis ( string); |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2176 | WCMD_output_asis ( newline); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2177 | } |
| 2178 | else { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2179 | WCMD_output (WCMD_LoadMessage(WCMD_NOPATH)); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2180 | } |
| 2181 | } |
| 2182 | else { |
Jason Edmeades | 7358798 | 2007-02-20 00:37:47 +0000 | [diff] [blame] | 2183 | if (*command == '=') command++; /* Skip leading '=' */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2184 | status = SetEnvironmentVariableW(pathW, command); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2185 | if (!status) WCMD_print_error(); |
| 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | /**************************************************************************** |
| 2190 | * WCMD_setshow_prompt |
| 2191 | * |
| 2192 | * Set or show the command prompt. |
| 2193 | */ |
| 2194 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 2195 | void WCMD_setshow_prompt (void) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2196 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2197 | WCHAR *s; |
| 2198 | static const WCHAR promptW[] = {'P','R','O','M','P','T','\0'}; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2199 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2200 | if (strlenW(param1) == 0) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2201 | SetEnvironmentVariableW(promptW, NULL); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2202 | } |
| 2203 | else { |
| 2204 | s = param1; |
| 2205 | while ((*s == '=') || (*s == ' ')) s++; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2206 | if (strlenW(s) == 0) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2207 | SetEnvironmentVariableW(promptW, NULL); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2208 | } |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2209 | else SetEnvironmentVariableW(promptW, s); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | /**************************************************************************** |
| 2214 | * WCMD_setshow_time |
| 2215 | * |
| 2216 | * Set/Show the system time |
| 2217 | * FIXME: Can't change time yet |
| 2218 | */ |
| 2219 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 2220 | void WCMD_setshow_time (void) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2221 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2222 | WCHAR curtime[64], buffer[64]; |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 2223 | DWORD count; |
| 2224 | SYSTEMTIME st; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2225 | static const WCHAR parmT[] = {'/','T','\0'}; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2226 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2227 | if (strlenW(param1) == 0) { |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 2228 | GetLocalTime(&st); |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2229 | if (GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2230 | curtime, sizeof(curtime)/sizeof(WCHAR))) { |
Christian Costa | 656b627 | 2008-12-30 13:26:53 +0100 | [diff] [blame] | 2231 | WCMD_output (WCMD_LoadMessage(WCMD_CURRENTTIME), curtime); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2232 | if (strstrW (quals, parmT) == NULL) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2233 | WCMD_output (WCMD_LoadMessage(WCMD_NEWTIME)); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2234 | WCMD_ReadFile (GetStdHandle(STD_INPUT_HANDLE), buffer, |
| 2235 | sizeof(buffer)/sizeof(WCHAR), &count, NULL); |
Jason Edmeades | b6ed73b | 2007-03-08 00:45:27 +0000 | [diff] [blame] | 2236 | if (count > 2) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2237 | WCMD_output (WCMD_LoadMessage(WCMD_NYI)); |
Jason Edmeades | b6ed73b | 2007-03-08 00:45:27 +0000 | [diff] [blame] | 2238 | } |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2239 | } |
| 2240 | } |
| 2241 | else WCMD_print_error (); |
| 2242 | } |
| 2243 | else { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2244 | WCMD_output (WCMD_LoadMessage(WCMD_NYI)); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2245 | } |
| 2246 | } |
| 2247 | |
| 2248 | /**************************************************************************** |
| 2249 | * WCMD_shift |
| 2250 | * |
| 2251 | * Shift batch parameters. |
Jason Edmeades | 612dc9d | 2007-03-08 00:50:37 +0000 | [diff] [blame] | 2252 | * Optional /n says where to start shifting (n=0-8) |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2253 | */ |
| 2254 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2255 | void WCMD_shift (WCHAR *command) { |
Jason Edmeades | 612dc9d | 2007-03-08 00:50:37 +0000 | [diff] [blame] | 2256 | int start; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2257 | |
Jason Edmeades | 612dc9d | 2007-03-08 00:50:37 +0000 | [diff] [blame] | 2258 | if (context != NULL) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2259 | WCHAR *pos = strchrW(command, '/'); |
Jason Edmeades | 612dc9d | 2007-03-08 00:50:37 +0000 | [diff] [blame] | 2260 | int i; |
| 2261 | |
| 2262 | if (pos == NULL) { |
| 2263 | start = 0; |
| 2264 | } else if (*(pos+1)>='0' && *(pos+1)<='8') { |
| 2265 | start = (*(pos+1) - '0'); |
| 2266 | } else { |
| 2267 | SetLastError(ERROR_INVALID_PARAMETER); |
| 2268 | WCMD_print_error(); |
| 2269 | return; |
| 2270 | } |
| 2271 | |
| 2272 | WINE_TRACE("Shifting variables, starting at %d\n", start); |
| 2273 | for (i=start;i<=8;i++) { |
| 2274 | context -> shift_count[i] = context -> shift_count[i+1] + 1; |
| 2275 | } |
| 2276 | context -> shift_count[9] = context -> shift_count[9] + 1; |
| 2277 | } |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2278 | |
| 2279 | } |
| 2280 | |
| 2281 | /**************************************************************************** |
Jason Edmeades | bcc6256 | 2002-05-04 18:29:31 +0000 | [diff] [blame] | 2282 | * WCMD_title |
| 2283 | * |
| 2284 | * Set the console title |
| 2285 | */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2286 | void WCMD_title (WCHAR *command) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2287 | SetConsoleTitleW(command); |
Jason Edmeades | bcc6256 | 2002-05-04 18:29:31 +0000 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | /**************************************************************************** |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2291 | * WCMD_type |
| 2292 | * |
| 2293 | * Copy a file to standard output. |
| 2294 | */ |
| 2295 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2296 | void WCMD_type (WCHAR *command) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2297 | |
Jason Edmeades | 4ef2f8b | 2007-03-13 00:09:33 +0000 | [diff] [blame] | 2298 | int argno = 0; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2299 | WCHAR *argN = command; |
Jason Edmeades | 4ef2f8b | 2007-03-13 00:09:33 +0000 | [diff] [blame] | 2300 | BOOL writeHeaders = FALSE; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2301 | |
Markus Amsler | 765ff5d | 2006-10-31 21:11:28 +0100 | [diff] [blame] | 2302 | if (param1[0] == 0x00) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2303 | WCMD_output (WCMD_LoadMessage(WCMD_NOARG)); |
Markus Amsler | 765ff5d | 2006-10-31 21:11:28 +0100 | [diff] [blame] | 2304 | return; |
| 2305 | } |
Jason Edmeades | 4ef2f8b | 2007-03-13 00:09:33 +0000 | [diff] [blame] | 2306 | |
| 2307 | if (param2[0] != 0x00) writeHeaders = TRUE; |
| 2308 | |
| 2309 | /* Loop through all args */ |
| 2310 | errorlevel = 0; |
| 2311 | while (argN) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2312 | WCHAR *thisArg = WCMD_parameter (command, argno++, &argN); |
Jason Edmeades | 4ef2f8b | 2007-03-13 00:09:33 +0000 | [diff] [blame] | 2313 | |
| 2314 | HANDLE h; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2315 | WCHAR buffer[512]; |
Jason Edmeades | 4ef2f8b | 2007-03-13 00:09:33 +0000 | [diff] [blame] | 2316 | DWORD count; |
| 2317 | |
| 2318 | if (!argN) break; |
| 2319 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2320 | WINE_TRACE("type: Processing arg '%s'\n", wine_dbgstr_w(thisArg)); |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2321 | h = CreateFileW(thisArg, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, |
Jason Edmeades | 4ef2f8b | 2007-03-13 00:09:33 +0000 | [diff] [blame] | 2322 | FILE_ATTRIBUTE_NORMAL, NULL); |
| 2323 | if (h == INVALID_HANDLE_VALUE) { |
| 2324 | WCMD_print_error (); |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2325 | WCMD_output (WCMD_LoadMessage(WCMD_READFAIL), thisArg); |
Jason Edmeades | 4ef2f8b | 2007-03-13 00:09:33 +0000 | [diff] [blame] | 2326 | errorlevel = 1; |
| 2327 | } else { |
| 2328 | if (writeHeaders) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2329 | static const WCHAR fmt[] = {'\n','%','s','\n','\n','\0'}; |
| 2330 | WCMD_output(fmt, thisArg); |
Jason Edmeades | 4ef2f8b | 2007-03-13 00:09:33 +0000 | [diff] [blame] | 2331 | } |
Nikolay Sivov | 2dd1b3b | 2009-02-17 22:45:21 +0300 | [diff] [blame] | 2332 | while (WCMD_ReadFile (h, buffer, sizeof(buffer)/sizeof(WCHAR) - 1, &count, NULL)) { |
Jason Edmeades | 4ef2f8b | 2007-03-13 00:09:33 +0000 | [diff] [blame] | 2333 | if (count == 0) break; /* ReadFile reports success on EOF! */ |
| 2334 | buffer[count] = 0; |
| 2335 | WCMD_output_asis (buffer); |
| 2336 | } |
| 2337 | CloseHandle (h); |
Nikolay Sivov | 78f38a7 | 2009-02-17 22:39:42 +0300 | [diff] [blame] | 2338 | if (!writeHeaders) |
| 2339 | WCMD_output_asis (newline); |
Jason Edmeades | 4ef2f8b | 2007-03-13 00:09:33 +0000 | [diff] [blame] | 2340 | } |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2341 | } |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | /**************************************************************************** |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2345 | * WCMD_more |
| 2346 | * |
| 2347 | * Output either a file or stdin to screen in pages |
| 2348 | */ |
| 2349 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2350 | void WCMD_more (WCHAR *command) { |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2351 | |
| 2352 | int argno = 0; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2353 | WCHAR *argN = command; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2354 | WCHAR moreStr[100]; |
| 2355 | WCHAR moreStrPage[100]; |
| 2356 | WCHAR buffer[512]; |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2357 | DWORD count; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2358 | static const WCHAR moreStart[] = {'-','-',' ','\0'}; |
| 2359 | static const WCHAR moreFmt[] = {'%','s',' ','-','-','\n','\0'}; |
| 2360 | static const WCHAR moreFmt2[] = {'%','s',' ','(','%','2','.','2','d','%','%', |
| 2361 | ')',' ','-','-','\n','\0'}; |
| 2362 | static const WCHAR conInW[] = {'C','O','N','I','N','$','\0'}; |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2363 | |
| 2364 | /* Prefix the NLS more with '-- ', then load the text */ |
| 2365 | errorlevel = 0; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2366 | strcpyW(moreStr, moreStart); |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2367 | LoadStringW(hinst, WCMD_MORESTR, &moreStr[3], |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2368 | (sizeof(moreStr)/sizeof(WCHAR))-3); |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2369 | |
| 2370 | if (param1[0] == 0x00) { |
| 2371 | |
| 2372 | /* Wine implements pipes via temporary files, and hence stdin is |
| 2373 | effectively reading from the file. This means the prompts for |
Francois Gouget | 8a18e0e | 2008-04-07 13:01:02 +0200 | [diff] [blame] | 2374 | more are satisfied by the next line from the input (file). To |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2375 | avoid this, ensure stdin is to the console */ |
| 2376 | HANDLE hstdin = GetStdHandle(STD_INPUT_HANDLE); |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2377 | HANDLE hConIn = CreateFileW(conInW, GENERIC_READ | GENERIC_WRITE, |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2378 | FILE_SHARE_READ, NULL, OPEN_EXISTING, |
| 2379 | FILE_ATTRIBUTE_NORMAL, 0); |
Jason Edmeades | 84f02a6 | 2008-03-03 23:14:29 +0000 | [diff] [blame] | 2380 | WINE_TRACE("No parms - working probably in pipe mode\n"); |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2381 | SetStdHandle(STD_INPUT_HANDLE, hConIn); |
| 2382 | |
| 2383 | /* Warning: No easy way of ending the stream (ctrl+z on windows) so |
| 2384 | once you get in this bit unless due to a pipe, its going to end badly... */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2385 | wsprintfW(moreStrPage, moreFmt, moreStr); |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2386 | |
| 2387 | WCMD_enter_paged_mode(moreStrPage); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2388 | while (WCMD_ReadFile (hstdin, buffer, (sizeof(buffer)/sizeof(WCHAR))-1, &count, NULL)) { |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2389 | if (count == 0) break; /* ReadFile reports success on EOF! */ |
| 2390 | buffer[count] = 0; |
| 2391 | WCMD_output_asis (buffer); |
| 2392 | } |
| 2393 | WCMD_leave_paged_mode(); |
| 2394 | |
| 2395 | /* Restore stdin to what it was */ |
| 2396 | SetStdHandle(STD_INPUT_HANDLE, hstdin); |
| 2397 | CloseHandle(hConIn); |
| 2398 | |
| 2399 | return; |
| 2400 | } else { |
| 2401 | BOOL needsPause = FALSE; |
| 2402 | |
| 2403 | /* Loop through all args */ |
Jason Edmeades | 84f02a6 | 2008-03-03 23:14:29 +0000 | [diff] [blame] | 2404 | WINE_TRACE("Parms supplied - working through each file\n"); |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2405 | WCMD_enter_paged_mode(moreStrPage); |
| 2406 | |
| 2407 | while (argN) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2408 | WCHAR *thisArg = WCMD_parameter (command, argno++, &argN); |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2409 | HANDLE h; |
| 2410 | |
| 2411 | if (!argN) break; |
| 2412 | |
| 2413 | if (needsPause) { |
| 2414 | |
| 2415 | /* Wait */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2416 | wsprintfW(moreStrPage, moreFmt2, moreStr, 100); |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2417 | WCMD_leave_paged_mode(); |
| 2418 | WCMD_output_asis(moreStrPage); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2419 | WCMD_ReadFile (GetStdHandle(STD_INPUT_HANDLE), buffer, |
| 2420 | sizeof(buffer)/sizeof(WCHAR), &count, NULL); |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2421 | WCMD_enter_paged_mode(moreStrPage); |
| 2422 | } |
| 2423 | |
| 2424 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2425 | WINE_TRACE("more: Processing arg '%s'\n", wine_dbgstr_w(thisArg)); |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2426 | h = CreateFileW(thisArg, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2427 | FILE_ATTRIBUTE_NORMAL, NULL); |
| 2428 | if (h == INVALID_HANDLE_VALUE) { |
| 2429 | WCMD_print_error (); |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2430 | WCMD_output (WCMD_LoadMessage(WCMD_READFAIL), thisArg); |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2431 | errorlevel = 1; |
| 2432 | } else { |
| 2433 | ULONG64 curPos = 0; |
| 2434 | ULONG64 fileLen = 0; |
| 2435 | WIN32_FILE_ATTRIBUTE_DATA fileInfo; |
| 2436 | |
| 2437 | /* Get the file size */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2438 | GetFileAttributesExW(thisArg, GetFileExInfoStandard, (void*)&fileInfo); |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2439 | fileLen = (((ULONG64)fileInfo.nFileSizeHigh) << 32) + fileInfo.nFileSizeLow; |
| 2440 | |
| 2441 | needsPause = TRUE; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2442 | while (WCMD_ReadFile (h, buffer, (sizeof(buffer)/sizeof(WCHAR))-1, &count, NULL)) { |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2443 | if (count == 0) break; /* ReadFile reports success on EOF! */ |
| 2444 | buffer[count] = 0; |
| 2445 | curPos += count; |
| 2446 | |
| 2447 | /* Update % count (would be used in WCMD_output_asis as prompt) */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2448 | wsprintfW(moreStrPage, moreFmt2, moreStr, (int) min(99, (curPos * 100)/fileLen)); |
Jason Edmeades | ce87522 | 2007-04-13 21:34:05 +0100 | [diff] [blame] | 2449 | |
| 2450 | WCMD_output_asis (buffer); |
| 2451 | } |
| 2452 | CloseHandle (h); |
| 2453 | } |
| 2454 | } |
| 2455 | |
| 2456 | WCMD_leave_paged_mode(); |
| 2457 | } |
| 2458 | } |
| 2459 | |
| 2460 | /**************************************************************************** |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2461 | * WCMD_verify |
| 2462 | * |
| 2463 | * Display verify flag. |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 2464 | * FIXME: We don't actually do anything with the verify flag other than toggle |
| 2465 | * it... |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2466 | */ |
| 2467 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2468 | void WCMD_verify (WCHAR *command) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2469 | |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 2470 | int count; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2471 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2472 | count = strlenW(command); |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 2473 | if (count == 0) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2474 | if (verify_mode) WCMD_output (WCMD_LoadMessage(WCMD_VERIFYPROMPT), onW); |
| 2475 | else WCMD_output (WCMD_LoadMessage(WCMD_VERIFYPROMPT), offW); |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 2476 | return; |
| 2477 | } |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2478 | if (lstrcmpiW(command, onW) == 0) { |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 2479 | verify_mode = 1; |
| 2480 | return; |
| 2481 | } |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2482 | else if (lstrcmpiW(command, offW) == 0) { |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 2483 | verify_mode = 0; |
| 2484 | return; |
| 2485 | } |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2486 | else WCMD_output (WCMD_LoadMessage(WCMD_VERIFYERR)); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | /**************************************************************************** |
| 2490 | * WCMD_version |
| 2491 | * |
| 2492 | * Display version info. |
| 2493 | */ |
| 2494 | |
Eric Pouech | b2f079b | 2003-02-27 01:41:21 +0000 | [diff] [blame] | 2495 | void WCMD_version (void) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2496 | |
| 2497 | WCMD_output (version_string); |
| 2498 | |
| 2499 | } |
| 2500 | |
| 2501 | /**************************************************************************** |
| 2502 | * WCMD_volume |
| 2503 | * |
| 2504 | * Display volume info and/or set volume label. Returns 0 if error. |
| 2505 | */ |
| 2506 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2507 | int WCMD_volume (int mode, WCHAR *path) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2508 | |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 2509 | DWORD count, serial; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2510 | WCHAR string[MAX_PATH], label[MAX_PATH], curdir[MAX_PATH]; |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 2511 | BOOL status; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2512 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2513 | if (strlenW(path) == 0) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2514 | status = GetCurrentDirectoryW(sizeof(curdir)/sizeof(WCHAR), curdir); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2515 | if (!status) { |
| 2516 | WCMD_print_error (); |
| 2517 | return 0; |
| 2518 | } |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2519 | status = GetVolumeInformationW(NULL, label, sizeof(label)/sizeof(WCHAR), |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2520 | &serial, NULL, NULL, NULL, 0); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2521 | } |
| 2522 | else { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2523 | static const WCHAR fmt[] = {'%','s','\\','\0'}; |
| 2524 | if ((path[1] != ':') || (strlenW(path) != 2)) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2525 | WCMD_output (WCMD_LoadMessage(WCMD_SYNTAXERR)); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2526 | return 0; |
| 2527 | } |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2528 | wsprintfW (curdir, fmt, path); |
| 2529 | status = GetVolumeInformationW(curdir, label, sizeof(label)/sizeof(WCHAR), |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2530 | &serial, NULL, |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2531 | NULL, NULL, 0); |
| 2532 | } |
| 2533 | if (!status) { |
| 2534 | WCMD_print_error (); |
| 2535 | return 0; |
| 2536 | } |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2537 | WCMD_output (WCMD_LoadMessage(WCMD_VOLUMEDETAIL), |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2538 | curdir[0], label, HIWORD(serial), LOWORD(serial)); |
| 2539 | if (mode) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2540 | WCMD_output (WCMD_LoadMessage(WCMD_VOLUMEPROMPT)); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2541 | WCMD_ReadFile (GetStdHandle(STD_INPUT_HANDLE), string, |
| 2542 | sizeof(string)/sizeof(WCHAR), &count, NULL); |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 2543 | if (count > 1) { |
| 2544 | string[count-1] = '\0'; /* ReadFile output is not null-terminated! */ |
| 2545 | if (string[count-2] == '\r') string[count-2] = '\0'; /* Under Windoze we get CRLF! */ |
| 2546 | } |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2547 | if (strlenW(path) != 0) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2548 | if (!SetVolumeLabelW(curdir, string)) WCMD_print_error (); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2549 | } |
| 2550 | else { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2551 | if (!SetVolumeLabelW(NULL, string)) WCMD_print_error (); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 2552 | } |
| 2553 | } |
| 2554 | return 1; |
| 2555 | } |
Jason Edmeades | c366648 | 2007-02-20 17:49:08 +0000 | [diff] [blame] | 2556 | |
| 2557 | /************************************************************************** |
| 2558 | * WCMD_exit |
| 2559 | * |
| 2560 | * Exit either the process, or just this batch program |
| 2561 | * |
| 2562 | */ |
| 2563 | |
Jason Edmeades | d2474de | 2007-06-15 20:59:24 +0100 | [diff] [blame] | 2564 | void WCMD_exit (CMD_LIST **cmdList) { |
Jason Edmeades | c366648 | 2007-02-20 17:49:08 +0000 | [diff] [blame] | 2565 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2566 | static const WCHAR parmB[] = {'/','B','\0'}; |
| 2567 | int rc = atoiW(param1); /* Note: atoi of empty parameter is 0 */ |
Jason Edmeades | c366648 | 2007-02-20 17:49:08 +0000 | [diff] [blame] | 2568 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2569 | if (context && lstrcmpiW(quals, parmB) == 0) { |
Jason Edmeades | c366648 | 2007-02-20 17:49:08 +0000 | [diff] [blame] | 2570 | errorlevel = rc; |
| 2571 | context -> skip_rest = TRUE; |
Jason Edmeades | d2474de | 2007-06-15 20:59:24 +0100 | [diff] [blame] | 2572 | *cmdList = NULL; |
Jason Edmeades | c366648 | 2007-02-20 17:49:08 +0000 | [diff] [blame] | 2573 | } else { |
| 2574 | ExitProcess(rc); |
| 2575 | } |
| 2576 | } |
Jason Edmeades | fda7229 | 2007-02-27 23:18:57 +0000 | [diff] [blame] | 2577 | |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2578 | |
| 2579 | /***************************************************************************** |
| 2580 | * WCMD_assoc |
| 2581 | * |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2582 | * Lists or sets file associations (assoc = TRUE) |
| 2583 | * Lists or sets file types (assoc = FALSE) |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2584 | */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2585 | void WCMD_assoc (WCHAR *command, BOOL assoc) { |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2586 | |
| 2587 | HKEY key; |
| 2588 | DWORD accessOptions = KEY_READ; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2589 | WCHAR *newValue; |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2590 | LONG rc = ERROR_SUCCESS; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2591 | WCHAR keyValue[MAXSTRING]; |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2592 | DWORD valueLen = MAXSTRING; |
| 2593 | HKEY readKey; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2594 | static const WCHAR shOpCmdW[] = {'\\','S','h','e','l','l','\\', |
| 2595 | 'O','p','e','n','\\','C','o','m','m','a','n','d','\0'}; |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2596 | |
| 2597 | /* See if parameter includes '=' */ |
| 2598 | errorlevel = 0; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2599 | newValue = strchrW(command, '='); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2600 | if (newValue) accessOptions |= KEY_WRITE; |
| 2601 | |
| 2602 | /* Open a key to HKEY_CLASSES_ROOT for enumerating */ |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2603 | if (RegOpenKeyExW(HKEY_CLASSES_ROOT, nullW, 0, |
| 2604 | accessOptions, &key) != ERROR_SUCCESS) { |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2605 | WINE_FIXME("Unexpected failure opening HKCR key: %d\n", GetLastError()); |
| 2606 | return; |
| 2607 | } |
| 2608 | |
Francois Gouget | 7b0cde8 | 2007-03-06 14:26:24 +0100 | [diff] [blame] | 2609 | /* If no parameters then list all associations */ |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2610 | if (*command == 0x00) { |
| 2611 | int index = 0; |
| 2612 | |
| 2613 | /* Enumerate all the keys */ |
| 2614 | while (rc != ERROR_NO_MORE_ITEMS) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2615 | WCHAR keyName[MAXSTRING]; |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2616 | DWORD nameLen; |
| 2617 | |
| 2618 | /* Find the next value */ |
| 2619 | nameLen = MAXSTRING; |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2620 | rc = RegEnumKeyExW(key, index++, keyName, &nameLen, NULL, NULL, NULL, NULL); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2621 | |
| 2622 | if (rc == ERROR_SUCCESS) { |
| 2623 | |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2624 | /* Only interested in extension ones if assoc, or others |
| 2625 | if not assoc */ |
| 2626 | if ((keyName[0] == '.' && assoc) || |
| 2627 | (!(keyName[0] == '.') && (!assoc))) |
| 2628 | { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2629 | WCHAR subkey[MAXSTRING]; |
| 2630 | strcpyW(subkey, keyName); |
| 2631 | if (!assoc) strcatW(subkey, shOpCmdW); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2632 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2633 | if (RegOpenKeyExW(key, subkey, 0, accessOptions, &readKey) == ERROR_SUCCESS) { |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2634 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2635 | valueLen = sizeof(keyValue)/sizeof(WCHAR); |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2636 | rc = RegQueryValueExW(readKey, NULL, NULL, NULL, (LPBYTE)keyValue, &valueLen); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2637 | WCMD_output_asis(keyName); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2638 | WCMD_output_asis(equalW); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2639 | /* If no default value found, leave line empty after '=' */ |
| 2640 | if (rc == ERROR_SUCCESS) { |
| 2641 | WCMD_output_asis(keyValue); |
| 2642 | } |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2643 | WCMD_output_asis(newline); |
Lance Jackson | d56217e | 2008-01-03 18:03:44 -0600 | [diff] [blame] | 2644 | RegCloseKey(readKey); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2645 | } |
| 2646 | } |
| 2647 | } |
| 2648 | } |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2649 | |
| 2650 | } else { |
| 2651 | |
| 2652 | /* Parameter supplied - if no '=' on command line, its a query */ |
| 2653 | if (newValue == NULL) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2654 | WCHAR *space; |
| 2655 | WCHAR subkey[MAXSTRING]; |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2656 | |
| 2657 | /* Query terminates the parameter at the first space */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2658 | strcpyW(keyValue, command); |
| 2659 | space = strchrW(keyValue, ' '); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2660 | if (space) *space=0x00; |
| 2661 | |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2662 | /* Set up key name */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2663 | strcpyW(subkey, keyValue); |
| 2664 | if (!assoc) strcatW(subkey, shOpCmdW); |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2665 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2666 | if (RegOpenKeyExW(key, subkey, 0, accessOptions, &readKey) == ERROR_SUCCESS) { |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2667 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2668 | rc = RegQueryValueExW(readKey, NULL, NULL, NULL, (LPBYTE)keyValue, &valueLen); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2669 | WCMD_output_asis(command); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2670 | WCMD_output_asis(equalW); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2671 | /* If no default value found, leave line empty after '=' */ |
| 2672 | if (rc == ERROR_SUCCESS) WCMD_output_asis(keyValue); |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2673 | WCMD_output_asis(newline); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2674 | RegCloseKey(readKey); |
| 2675 | |
| 2676 | } else { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2677 | WCHAR msgbuffer[MAXSTRING]; |
| 2678 | WCHAR outbuffer[MAXSTRING]; |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2679 | |
| 2680 | /* Load the translated 'File association not found' */ |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2681 | if (assoc) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2682 | LoadStringW(hinst, WCMD_NOASSOC, msgbuffer, sizeof(msgbuffer)/sizeof(WCHAR)); |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2683 | } else { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2684 | LoadStringW(hinst, WCMD_NOFTYPE, msgbuffer, sizeof(msgbuffer)/sizeof(WCHAR)); |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2685 | } |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2686 | wsprintfW(outbuffer, msgbuffer, keyValue); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2687 | WCMD_output_asis(outbuffer); |
| 2688 | errorlevel = 2; |
| 2689 | } |
| 2690 | |
| 2691 | /* Not a query - its a set or clear of a value */ |
| 2692 | } else { |
| 2693 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2694 | WCHAR subkey[MAXSTRING]; |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2695 | |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2696 | /* Get pointer to new value */ |
| 2697 | *newValue = 0x00; |
| 2698 | newValue++; |
| 2699 | |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2700 | /* Set up key name */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2701 | strcpyW(subkey, command); |
| 2702 | if (!assoc) strcatW(subkey, shOpCmdW); |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2703 | |
| 2704 | /* If nothing after '=' then clear value - only valid for ASSOC */ |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2705 | if (*newValue == 0x00) { |
| 2706 | |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2707 | if (assoc) rc = RegDeleteKeyW(key, command); |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2708 | if (assoc && rc == ERROR_SUCCESS) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2709 | WINE_TRACE("HKCR Key '%s' deleted\n", wine_dbgstr_w(command)); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2710 | |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2711 | } else if (assoc && rc != ERROR_FILE_NOT_FOUND) { |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2712 | WCMD_print_error(); |
| 2713 | errorlevel = 2; |
| 2714 | |
| 2715 | } else { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2716 | WCHAR msgbuffer[MAXSTRING]; |
| 2717 | WCHAR outbuffer[MAXSTRING]; |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2718 | |
| 2719 | /* Load the translated 'File association not found' */ |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2720 | if (assoc) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2721 | LoadStringW(hinst, WCMD_NOASSOC, msgbuffer, |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2722 | sizeof(msgbuffer)/sizeof(WCHAR)); |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2723 | } else { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2724 | LoadStringW(hinst, WCMD_NOFTYPE, msgbuffer, |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2725 | sizeof(msgbuffer)/sizeof(WCHAR)); |
Jason Edmeades | 9e041c6 | 2007-03-13 00:06:58 +0000 | [diff] [blame] | 2726 | } |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2727 | wsprintfW(outbuffer, msgbuffer, keyValue); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2728 | WCMD_output_asis(outbuffer); |
| 2729 | errorlevel = 2; |
| 2730 | } |
| 2731 | |
| 2732 | /* It really is a set value = contents */ |
| 2733 | } else { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2734 | rc = RegCreateKeyExW(key, subkey, 0, NULL, REG_OPTION_NON_VOLATILE, |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2735 | accessOptions, NULL, &readKey, NULL); |
| 2736 | if (rc == ERROR_SUCCESS) { |
Alexandre Julliard | 79b0072 | 2009-12-09 18:52:40 +0100 | [diff] [blame] | 2737 | rc = RegSetValueExW(readKey, NULL, 0, REG_SZ, |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2738 | (LPBYTE)newValue, strlenW(newValue)); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2739 | RegCloseKey(readKey); |
| 2740 | } |
| 2741 | |
| 2742 | if (rc != ERROR_SUCCESS) { |
| 2743 | WCMD_print_error(); |
| 2744 | errorlevel = 2; |
| 2745 | } else { |
| 2746 | WCMD_output_asis(command); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2747 | WCMD_output_asis(equalW); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2748 | WCMD_output_asis(newValue); |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2749 | WCMD_output_asis(newline); |
Jason Edmeades | 79aa1a0 | 2007-03-04 22:34:45 +0000 | [diff] [blame] | 2750 | } |
| 2751 | } |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | /* Clean up */ |
| 2756 | RegCloseKey(key); |
| 2757 | } |
Jason Edmeades | e37463f | 2007-03-08 00:37:44 +0000 | [diff] [blame] | 2758 | |
| 2759 | /**************************************************************************** |
| 2760 | * WCMD_color |
| 2761 | * |
| 2762 | * Clear the terminal screen. |
| 2763 | */ |
| 2764 | |
| 2765 | void WCMD_color (void) { |
| 2766 | |
| 2767 | /* Emulate by filling the screen from the top left to bottom right with |
| 2768 | spaces, then moving the cursor to the top left afterwards */ |
| 2769 | CONSOLE_SCREEN_BUFFER_INFO consoleInfo; |
| 2770 | HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); |
| 2771 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2772 | if (param1[0] != 0x00 && strlenW(param1) > 2) { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 2773 | WCMD_output (WCMD_LoadMessage(WCMD_ARGERR)); |
Jason Edmeades | e37463f | 2007-03-08 00:37:44 +0000 | [diff] [blame] | 2774 | return; |
| 2775 | } |
| 2776 | |
| 2777 | if (GetConsoleScreenBufferInfo(hStdOut, &consoleInfo)) |
| 2778 | { |
| 2779 | COORD topLeft; |
| 2780 | DWORD screenSize; |
| 2781 | DWORD color = 0; |
| 2782 | |
| 2783 | screenSize = consoleInfo.dwSize.X * (consoleInfo.dwSize.Y + 1); |
| 2784 | |
| 2785 | topLeft.X = 0; |
| 2786 | topLeft.Y = 0; |
| 2787 | |
| 2788 | /* Convert the color hex digits */ |
| 2789 | if (param1[0] == 0x00) { |
| 2790 | color = defaultColor; |
| 2791 | } else { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 2792 | color = strtoulW(param1, NULL, 16); |
Jason Edmeades | e37463f | 2007-03-08 00:37:44 +0000 | [diff] [blame] | 2793 | } |
| 2794 | |
| 2795 | /* Fail if fg == bg color */ |
| 2796 | if (((color & 0xF0) >> 4) == (color & 0x0F)) { |
| 2797 | errorlevel = 1; |
| 2798 | return; |
| 2799 | } |
| 2800 | |
| 2801 | /* Set the current screen contents and ensure all future writes |
| 2802 | remain this color */ |
| 2803 | FillConsoleOutputAttribute(hStdOut, color, screenSize, topLeft, &screenSize); |
| 2804 | SetConsoleTextAttribute(hStdOut, color); |
| 2805 | } |
| 2806 | } |