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 - batch interface. |
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 |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 22 | #include "wcmd.h" |
Jason Edmeades | b692411 | 2007-09-11 21:43:03 +0100 | [diff] [blame] | 23 | #include "wine/debug.h" |
| 24 | |
| 25 | WINE_DEFAULT_DEBUG_CHANNEL(cmd); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 26 | |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 27 | extern int echo_mode; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 28 | extern WCHAR quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH]; |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 29 | extern BATCH_CONTEXT *context; |
Dave Pickles | ebecf50 | 2000-08-01 22:02:18 +0000 | [diff] [blame] | 30 | extern DWORD errorlevel; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 31 | |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 32 | /**************************************************************************** |
| 33 | * WCMD_batch |
| 34 | * |
| 35 | * Open and execute a batch file. |
| 36 | * On entry *command includes the complete command line beginning with the name |
| 37 | * of the batch file (if a CALL command was entered the CALL has been removed). |
| 38 | * *file is the name of the file, which might not exist and may not have the |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 39 | * .BAT suffix on. Called is 1 for a CALL, 0 otherwise. |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 40 | * |
| 41 | * We need to handle recursion correctly, since one batch program might call another. |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 42 | * So parameters for this batch file are held in a BATCH_CONTEXT structure. |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 43 | * |
| 44 | * To support call within the same batch program, another input parameter is |
| 45 | * a label to goto once opened. |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 46 | */ |
| 47 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 48 | void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HANDLE pgmHandle) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 49 | |
Stefan Leichter | a127ad1 | 2003-03-25 00:33:56 +0000 | [diff] [blame] | 50 | #define WCMD_BATCH_EXT_SIZE 5 |
| 51 | |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 52 | HANDLE h = INVALID_HANDLE_VALUE; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 53 | WCHAR string[MAXSTRING]; |
| 54 | static const WCHAR extension_batch[][WCMD_BATCH_EXT_SIZE] = {{'.','b','a','t','\0'}, |
| 55 | {'.','c','m','d','\0'}}; |
| 56 | static const WCHAR extension_exe[WCMD_BATCH_EXT_SIZE] = {'.','e','x','e','\0'}; |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 57 | unsigned int i; |
| 58 | BATCH_CONTEXT *prev_context; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 59 | |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 60 | if (startLabel == NULL) { |
Rob Shearman | 271eaf5 | 2008-02-25 09:00:07 +0000 | [diff] [blame] | 61 | for(i=0; (i<sizeof(extension_batch)/(WCMD_BATCH_EXT_SIZE * sizeof(WCHAR))) && |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 62 | (h == INVALID_HANDLE_VALUE); i++) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 63 | strcpyW (string, file); |
| 64 | CharLower (string); |
| 65 | if (strstrW (string, extension_batch[i]) == NULL) strcatW (string, extension_batch[i]); |
| 66 | h = CreateFile (string, GENERIC_READ, FILE_SHARE_READ, |
| 67 | NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
Vincent Béron | 95571e6 | 2005-03-28 10:01:31 +0000 | [diff] [blame] | 68 | } |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 69 | if (h == INVALID_HANDLE_VALUE) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 70 | strcpyW (string, file); |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 71 | CharLower (string); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 72 | if (strstrW (string, extension_exe) == NULL) strcatW (string, extension_exe); |
Lance Jackson | d56217e | 2008-01-03 18:03:44 -0600 | [diff] [blame] | 73 | if (GetFileAttributes (string) != INVALID_FILE_ATTRIBUTES) { |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 74 | WCMD_run_program (command, 0); |
| 75 | } else { |
| 76 | SetLastError (ERROR_FILE_NOT_FOUND); |
| 77 | WCMD_print_error (); |
| 78 | } |
| 79 | return; |
| 80 | } |
| 81 | } else { |
| 82 | DuplicateHandle(GetCurrentProcess(), pgmHandle, |
| 83 | GetCurrentProcess(), &h, |
| 84 | 0, FALSE, DUPLICATE_SAME_ACCESS); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 88 | * Create a context structure for this batch file. |
| 89 | */ |
| 90 | |
| 91 | prev_context = context; |
| 92 | context = (BATCH_CONTEXT *)LocalAlloc (LMEM_FIXED, sizeof (BATCH_CONTEXT)); |
| 93 | context -> h = h; |
| 94 | context -> command = command; |
Jason Edmeades | 612dc9d | 2007-03-08 00:50:37 +0000 | [diff] [blame] | 95 | memset(context -> shift_count, 0x00, sizeof(context -> shift_count)); |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 96 | context -> prev_context = prev_context; |
Jason Edmeades | c366648 | 2007-02-20 17:49:08 +0000 | [diff] [blame] | 97 | context -> skip_rest = FALSE; |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 98 | |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 99 | /* If processing a call :label, 'goto' the label in question */ |
| 100 | if (startLabel) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 101 | strcpyW(param1, startLabel); |
Jason Edmeades | 929a92f | 2007-06-15 20:59:22 +0100 | [diff] [blame] | 102 | WCMD_goto(NULL); |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 105 | /* |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 106 | * Work through the file line by line. Specific batch commands are processed here, |
| 107 | * the rest are handled by the main command processor. |
| 108 | */ |
| 109 | |
Jason Edmeades | a88a6c8 | 2007-06-15 20:59:19 +0100 | [diff] [blame] | 110 | while (context -> skip_rest == FALSE) { |
| 111 | CMD_LIST *toExecute = NULL; /* Commands left to be executed */ |
| 112 | if (WCMD_ReadAndParseLine(NULL, &toExecute, h) == NULL) |
| 113 | break; |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 114 | WCMD_process_commands(toExecute, FALSE, NULL, NULL); |
Jason Edmeades | a88a6c8 | 2007-06-15 20:59:19 +0100 | [diff] [blame] | 115 | WCMD_free_commands(toExecute); |
| 116 | toExecute = NULL; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 117 | } |
| 118 | CloseHandle (h); |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * If invoked by a CALL, we return to the context of our caller. Otherwise return |
| 122 | * to the caller's caller. |
| 123 | */ |
| 124 | |
| 125 | LocalFree ((HANDLE)context); |
| 126 | if ((prev_context != NULL) && (!called)) { |
Jason Edmeades | 85c5dcb | 2007-07-24 23:36:30 +0100 | [diff] [blame] | 127 | prev_context -> skip_rest = TRUE; |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 128 | context = prev_context; |
| 129 | } |
Jason Edmeades | 85c5dcb | 2007-07-24 23:36:30 +0100 | [diff] [blame] | 130 | context = prev_context; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 133 | /******************************************************************* |
| 134 | * WCMD_parameter - extract a parameter from a command line. |
| 135 | * |
Jason Edmeades | 118f3a6 | 2007-09-11 21:43:04 +0100 | [diff] [blame] | 136 | * Returns the 'n'th delimited parameter on the command line (zero-based). |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 137 | * Parameter is in static storage overwritten on the next call. |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 138 | * Parameters in quotes (and brackets) are handled. |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 139 | * Also returns a pointer to the location of the parameter in the command line. |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 140 | */ |
| 141 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 142 | WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 143 | |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 144 | int i = 0; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 145 | static WCHAR param[MAX_PATH]; |
| 146 | WCHAR *p; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 147 | |
Jason Edmeades | a7c5906 | 2007-02-27 23:21:59 +0000 | [diff] [blame] | 148 | if (where != NULL) *where = NULL; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 149 | p = param; |
| 150 | while (TRUE) { |
| 151 | switch (*s) { |
Jason Edmeades | 118f3a6 | 2007-09-11 21:43:04 +0100 | [diff] [blame] | 152 | case ' ': /* Skip leading spaces */ |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 153 | s++; |
| 154 | break; |
| 155 | case '"': |
Jason Edmeades | a7c5906 | 2007-02-27 23:21:59 +0000 | [diff] [blame] | 156 | if (where != NULL && i==n) *where = s; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 157 | s++; |
| 158 | while ((*s != '\0') && (*s != '"')) { |
| 159 | *p++ = *s++; |
| 160 | } |
| 161 | if (i == n) { |
| 162 | *p = '\0'; |
| 163 | return param; |
| 164 | } |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 165 | if (*s == '"') s++; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 166 | param[0] = '\0'; |
| 167 | i++; |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 168 | p = param; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 169 | break; |
Jason Edmeades | 54d890c | 2007-06-15 20:59:28 +0100 | [diff] [blame] | 170 | /* The code to handle bracketed parms is removed because it should no longer |
| 171 | be necessary after the multiline support has been added and the for loop |
| 172 | set of data is now parseable individually. */ |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 173 | case '\0': |
| 174 | return param; |
| 175 | default: |
Jason Edmeades | e7dc3f1 | 2007-02-20 18:02:29 +0000 | [diff] [blame] | 176 | /* Only return where if it is for the right parameter */ |
| 177 | if (where != NULL && i==n) *where = s; |
Jason Edmeades | 118f3a6 | 2007-09-11 21:43:04 +0100 | [diff] [blame] | 178 | while ((*s != '\0') && (*s != ' ') && (*s != ',') && (*s != '=')) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 179 | *p++ = *s++; |
| 180 | } |
Jason Edmeades | 118f3a6 | 2007-09-11 21:43:04 +0100 | [diff] [blame] | 181 | if (i == n && (p!=param)) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 182 | *p = '\0'; |
| 183 | return param; |
| 184 | } |
Jason Edmeades | 118f3a6 | 2007-09-11 21:43:04 +0100 | [diff] [blame] | 185 | /* Skip double delimiters, eg. dir a.a,,,,,b.b */ |
| 186 | if (p != param) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 187 | param[0] = '\0'; |
| 188 | i++; |
Jason Edmeades | 118f3a6 | 2007-09-11 21:43:04 +0100 | [diff] [blame] | 189 | } else { |
Francois Gouget | 8a18e0e | 2008-04-07 13:01:02 +0200 | [diff] [blame] | 190 | s++; /* Skip delimiter */ |
Jason Edmeades | 118f3a6 | 2007-09-11 21:43:04 +0100 | [diff] [blame] | 191 | } |
Dave Pickles | 036a9f7 | 1999-07-10 11:36:45 +0000 | [diff] [blame] | 192 | p = param; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
Dave Pickles | ebecf50 | 2000-08-01 22:02:18 +0000 | [diff] [blame] | 197 | /**************************************************************************** |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 198 | * WCMD_fgets |
| 199 | * |
| 200 | * Get one line from a batch file. We can't use the native f* functions because |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 201 | * of the filename syntax differences between DOS and Unix. Also need to lose |
| 202 | * the LF (or CRLF) from the line. |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 203 | */ |
| 204 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 205 | WCHAR *WCMD_fgets (WCHAR *s, int noChars, HANDLE h) { |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 206 | |
Alexandre Julliard | abfe105 | 2007-03-01 12:43:19 +0100 | [diff] [blame] | 207 | DWORD bytes; |
| 208 | BOOL status; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 209 | WCHAR *p; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 210 | |
| 211 | p = s; |
| 212 | do { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 213 | status = WCMD_ReadFile (h, s, 1, &bytes, NULL); |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 214 | if ((status == 0) || ((bytes == 0) && (s == p))) return NULL; |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 215 | if (*s == '\n') bytes = 0; |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 216 | else if (*s != '\r') { |
| 217 | s++; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 218 | noChars--; |
Dave Pickles | 5f8f4f7 | 1999-06-26 10:24:08 +0000 | [diff] [blame] | 219 | } |
| 220 | *s = '\0'; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 221 | } while ((bytes == 1) && (noChars > 1)); |
Dave Pickles | 74f440e | 1999-06-06 15:24:04 +0000 | [diff] [blame] | 222 | return p; |
| 223 | } |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 224 | |
Jason Edmeades | 409368e | 2007-02-27 23:19:24 +0000 | [diff] [blame] | 225 | /* WCMD_splitpath - copied from winefile as no obvious way to use it otherwise */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 226 | void WCMD_splitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext) |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 227 | { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 228 | const WCHAR* end; /* end of processed string */ |
| 229 | const WCHAR* p; /* search pointer */ |
| 230 | const WCHAR* s; /* copy pointer */ |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 231 | |
| 232 | /* extract drive name */ |
| 233 | if (path[0] && path[1]==':') { |
| 234 | if (drv) { |
| 235 | *drv++ = *path++; |
| 236 | *drv++ = *path++; |
| 237 | *drv = '\0'; |
| 238 | } |
| 239 | } else if (drv) |
| 240 | *drv = '\0'; |
| 241 | |
| 242 | /* search for end of string or stream separator */ |
| 243 | for(end=path; *end && *end!=':'; ) |
| 244 | end++; |
| 245 | |
| 246 | /* search for begin of file extension */ |
| 247 | for(p=end; p>path && *--p!='\\' && *p!='/'; ) |
| 248 | if (*p == '.') { |
| 249 | end = p; |
| 250 | break; |
| 251 | } |
| 252 | |
| 253 | if (ext) |
| 254 | for(s=end; (*ext=*s++); ) |
| 255 | ext++; |
| 256 | |
| 257 | /* search for end of directory name */ |
| 258 | for(p=end; p>path; ) |
| 259 | if (*--p=='\\' || *p=='/') { |
| 260 | p++; |
| 261 | break; |
| 262 | } |
| 263 | |
| 264 | if (name) { |
| 265 | for(s=p; s<end; ) |
| 266 | *name++ = *s++; |
| 267 | |
| 268 | *name = '\0'; |
| 269 | } |
| 270 | |
| 271 | if (dir) { |
| 272 | for(s=path; s<p; ) |
| 273 | *dir++ = *s++; |
| 274 | |
| 275 | *dir = '\0'; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | /**************************************************************************** |
| 280 | * WCMD_HandleTildaModifiers |
| 281 | * |
| 282 | * Handle the ~ modifiers when expanding %0-9 or (%a-z in for command) |
| 283 | * %~xxxxxV (V=0-9 or A-Z) |
| 284 | * Where xxxx is any combination of: |
| 285 | * ~ - Removes quotes |
| 286 | * f - Fully qualified path (assumes current dir if not drive\dir) |
| 287 | * d - drive letter |
| 288 | * p - path |
| 289 | * n - filename |
| 290 | * x - file extension |
| 291 | * s - path with shortnames |
| 292 | * a - attributes |
| 293 | * t - date/time |
| 294 | * z - size |
| 295 | * $ENVVAR: - Searches ENVVAR for (contents of V) and expands to fully |
| 296 | * qualified path |
| 297 | * |
| 298 | * To work out the length of the modifier: |
| 299 | * |
| 300 | * Note: In the case of %0-9 knowing the end of the modifier is easy, |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 301 | * but in a for loop, the for end WCHARacter may also be a modifier |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 302 | * eg. for %a in (c:\a.a) do echo XXX |
| 303 | * where XXX = %~a (just ~) |
| 304 | * %~aa (~ and attributes) |
| 305 | * %~aaxa (~, attributes and extension) |
| 306 | * BUT %~aax (~ and attributes followed by 'x') |
| 307 | * |
| 308 | * Hence search forwards until find an invalid modifier, and then |
| 309 | * backwards until find for variable or 0-9 |
| 310 | */ |
Jason Edmeades | b692411 | 2007-09-11 21:43:03 +0100 | [diff] [blame] | 311 | void WCMD_HandleTildaModifiers(WCHAR **start, WCHAR *forVariable, WCHAR *forValue, BOOL justFors) { |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 312 | |
| 313 | #define NUMMODIFIERS 11 |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 314 | static const WCHAR validmodifiers[NUMMODIFIERS] = { |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 315 | '~', 'f', 'd', 'p', 'n', 'x', 's', 'a', 't', 'z', '$' |
| 316 | }; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 317 | static const WCHAR space[] = {' ', '\0'}; |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 318 | |
| 319 | WIN32_FILE_ATTRIBUTE_DATA fileInfo; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 320 | WCHAR outputparam[MAX_PATH]; |
| 321 | WCHAR finaloutput[MAX_PATH]; |
| 322 | WCHAR fullfilename[MAX_PATH]; |
| 323 | WCHAR thisoutput[MAX_PATH]; |
| 324 | WCHAR *pos = *start+1; |
| 325 | WCHAR *firstModifier = pos; |
| 326 | WCHAR *lastModifier = NULL; |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 327 | int modifierLen = 0; |
| 328 | BOOL finished = FALSE; |
| 329 | int i = 0; |
| 330 | BOOL exists = TRUE; |
| 331 | BOOL skipFileParsing = FALSE; |
| 332 | BOOL doneModifier = FALSE; |
| 333 | |
Jason Edmeades | b692411 | 2007-09-11 21:43:03 +0100 | [diff] [blame] | 334 | /* Search forwards until find invalid character modifier */ |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 335 | while (!finished) { |
| 336 | |
Jason Edmeades | b692411 | 2007-09-11 21:43:03 +0100 | [diff] [blame] | 337 | /* Work on the previous character */ |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 338 | if (lastModifier != NULL) { |
| 339 | |
| 340 | for (i=0; i<NUMMODIFIERS; i++) { |
| 341 | if (validmodifiers[i] == *lastModifier) { |
| 342 | |
| 343 | /* Special case '$' to skip until : found */ |
| 344 | if (*lastModifier == '$') { |
| 345 | while (*pos != ':' && *pos) pos++; |
| 346 | if (*pos == 0x00) return; /* Invalid syntax */ |
| 347 | pos++; /* Skip ':' */ |
| 348 | } |
| 349 | break; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | if (i==NUMMODIFIERS) { |
| 354 | finished = TRUE; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | /* Save this one away */ |
| 359 | if (!finished) { |
| 360 | lastModifier = pos; |
| 361 | pos++; |
| 362 | } |
| 363 | } |
| 364 | |
Jason Edmeades | b692411 | 2007-09-11 21:43:03 +0100 | [diff] [blame] | 365 | while (lastModifier > firstModifier) { |
| 366 | WINE_TRACE("Looking backwards for parameter id: %s / %s\n", |
| 367 | wine_dbgstr_w(lastModifier), wine_dbgstr_w(forVariable)); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 368 | |
Jason Edmeades | b692411 | 2007-09-11 21:43:03 +0100 | [diff] [blame] | 369 | if (!justFors && context && (*lastModifier >= '0' || *lastModifier <= '9')) { |
| 370 | /* Its a valid parameter identifier - OK */ |
| 371 | break; |
| 372 | |
| 373 | } else if (forVariable && *lastModifier == *(forVariable+1)) { |
| 374 | /* Its a valid parameter identifier - OK */ |
| 375 | break; |
| 376 | |
| 377 | } else { |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 378 | lastModifier--; |
| 379 | } |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 380 | } |
Jason Edmeades | b692411 | 2007-09-11 21:43:03 +0100 | [diff] [blame] | 381 | if (lastModifier == firstModifier) return; /* Invalid syntax */ |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 382 | |
| 383 | /* Extract the parameter to play with */ |
| 384 | if ((*lastModifier >= '0' && *lastModifier <= '9')) { |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 385 | strcpyW(outputparam, WCMD_parameter (context -> command, |
Jason Edmeades | 612dc9d | 2007-03-08 00:50:37 +0000 | [diff] [blame] | 386 | *lastModifier-'0' + context -> shift_count[*lastModifier-'0'], NULL)); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 387 | } else { |
Jason Edmeades | b692411 | 2007-09-11 21:43:03 +0100 | [diff] [blame] | 388 | strcpyW(outputparam, forValue); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /* So now, firstModifier points to beginning of modifiers, lastModifier |
| 392 | points to the variable just after the modifiers. Process modifiers |
| 393 | in a specific order, remembering there could be duplicates */ |
| 394 | modifierLen = lastModifier - firstModifier; |
| 395 | finaloutput[0] = 0x00; |
| 396 | |
| 397 | /* Useful for debugging purposes: */ |
| 398 | /*printf("Modifier string '%*.*s' and variable is %c\n Param starts as '%s'\n", |
| 399 | (modifierLen), (modifierLen), firstModifier, *lastModifier, |
| 400 | outputparam);*/ |
| 401 | |
| 402 | /* 1. Handle '~' : Strip surrounding quotes */ |
| 403 | if (outputparam[0]=='"' && |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 404 | memchrW(firstModifier, '~', modifierLen) != NULL) { |
| 405 | int len = strlenW(outputparam); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 406 | if (outputparam[len-1] == '"') { |
| 407 | outputparam[len-1]=0x00; |
| 408 | len = len - 1; |
| 409 | } |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 410 | memmove(outputparam, &outputparam[1], (len * sizeof(WCHAR))-1); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* 2. Handle the special case of a $ */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 414 | if (memchrW(firstModifier, '$', modifierLen) != NULL) { |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 415 | /* Special Case: Search envar specified in $[envvar] for outputparam |
| 416 | Note both $ and : are guaranteed otherwise check above would fail */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 417 | WCHAR *start = strchrW(firstModifier, '$') + 1; |
| 418 | WCHAR *end = strchrW(firstModifier, ':'); |
| 419 | WCHAR env[MAX_PATH]; |
| 420 | WCHAR fullpath[MAX_PATH]; |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 421 | |
| 422 | /* Extract the env var */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 423 | memcpy(env, start, (end-start) * sizeof(WCHAR)); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 424 | env[(end-start)] = 0x00; |
| 425 | |
Francois Gouget | 44b52b1 | 2008-01-16 12:20:50 +0100 | [diff] [blame] | 426 | /* If env var not found, return empty string */ |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 427 | if ((GetEnvironmentVariable(env, fullpath, MAX_PATH) == 0) || |
| 428 | (SearchPath(fullpath, outputparam, NULL, |
| 429 | MAX_PATH, outputparam, NULL) == 0)) { |
| 430 | finaloutput[0] = 0x00; |
| 431 | outputparam[0] = 0x00; |
| 432 | skipFileParsing = TRUE; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | /* After this, we need full information on the file, |
| 437 | which is valid not to exist. */ |
| 438 | if (!skipFileParsing) { |
| 439 | if (GetFullPathName(outputparam, MAX_PATH, fullfilename, NULL) == 0) |
| 440 | return; |
| 441 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 442 | exists = GetFileAttributesExW(fullfilename, GetFileExInfoStandard, |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 443 | &fileInfo); |
| 444 | |
| 445 | /* 2. Handle 'a' : Output attributes */ |
| 446 | if (exists && |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 447 | memchrW(firstModifier, 'a', modifierLen) != NULL) { |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 448 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 449 | WCHAR defaults[] = {'-','-','-','-','-','-','-','-','-','\0'}; |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 450 | doneModifier = TRUE; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 451 | strcpyW(thisoutput, defaults); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 452 | if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
| 453 | thisoutput[0]='d'; |
| 454 | if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY) |
| 455 | thisoutput[1]='r'; |
| 456 | if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) |
| 457 | thisoutput[2]='a'; |
| 458 | if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) |
| 459 | thisoutput[3]='h'; |
| 460 | if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) |
| 461 | thisoutput[4]='s'; |
| 462 | if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) |
| 463 | thisoutput[5]='c'; |
| 464 | /* FIXME: What are 6 and 7? */ |
| 465 | if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) |
| 466 | thisoutput[8]='l'; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 467 | strcatW(finaloutput, thisoutput); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /* 3. Handle 't' : Date+time */ |
| 471 | if (exists && |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 472 | memchrW(firstModifier, 't', modifierLen) != NULL) { |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 473 | |
| 474 | SYSTEMTIME systime; |
| 475 | int datelen; |
| 476 | |
| 477 | doneModifier = TRUE; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 478 | if (finaloutput[0] != 0x00) strcatW(finaloutput, space); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 479 | |
| 480 | /* Format the time */ |
| 481 | FileTimeToSystemTime(&fileInfo.ftLastWriteTime, &systime); |
| 482 | GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systime, |
| 483 | NULL, thisoutput, MAX_PATH); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 484 | strcatW(thisoutput, space); |
| 485 | datelen = strlenW(thisoutput); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 486 | GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &systime, |
| 487 | NULL, (thisoutput+datelen), MAX_PATH-datelen); |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 488 | strcatW(finaloutput, thisoutput); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | /* 4. Handle 'z' : File length */ |
| 492 | if (exists && |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 493 | memchrW(firstModifier, 'z', modifierLen) != NULL) { |
Francois Gouget | 7b0cde8 | 2007-03-06 14:26:24 +0100 | [diff] [blame] | 494 | /* FIXME: Output full 64 bit size (sprintf does not support I64 here) */ |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 495 | ULONG/*64*/ fullsize = /*(fileInfo.nFileSizeHigh << 32) +*/ |
| 496 | fileInfo.nFileSizeLow; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 497 | static const WCHAR fmt[] = {'%','u','\0'}; |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 498 | |
| 499 | doneModifier = TRUE; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 500 | if (finaloutput[0] != 0x00) strcatW(finaloutput, space); |
| 501 | wsprintf(thisoutput, fmt, fullsize); |
| 502 | strcatW(finaloutput, thisoutput); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Francois Gouget | 7b0cde8 | 2007-03-06 14:26:24 +0100 | [diff] [blame] | 505 | /* 4. Handle 's' : Use short paths (File doesn't have to exist) */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 506 | if (memchrW(firstModifier, 's', modifierLen) != NULL) { |
| 507 | if (finaloutput[0] != 0x00) strcatW(finaloutput, space); |
Francois Gouget | 7b0cde8 | 2007-03-06 14:26:24 +0100 | [diff] [blame] | 508 | /* Don't flag as doneModifier - %~s on its own is processed later */ |
Rob Shearman | 1d6922b | 2008-02-25 09:00:14 +0000 | [diff] [blame] | 509 | GetShortPathName(outputparam, outputparam, |
| 510 | sizeof(outputparam)/sizeof(outputparam[0])); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Francois Gouget | 7b0cde8 | 2007-03-06 14:26:24 +0100 | [diff] [blame] | 513 | /* 5. Handle 'f' : Fully qualified path (File doesn't have to exist) */ |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 514 | /* Note this overrides d,p,n,x */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 515 | if (memchrW(firstModifier, 'f', modifierLen) != NULL) { |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 516 | doneModifier = TRUE; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 517 | if (finaloutput[0] != 0x00) strcatW(finaloutput, space); |
| 518 | strcatW(finaloutput, fullfilename); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 519 | } else { |
| 520 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 521 | WCHAR drive[10]; |
| 522 | WCHAR dir[MAX_PATH]; |
| 523 | WCHAR fname[MAX_PATH]; |
| 524 | WCHAR ext[MAX_PATH]; |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 525 | BOOL doneFileModifier = FALSE; |
| 526 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 527 | if (finaloutput[0] != 0x00) strcatW(finaloutput, space); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 528 | |
| 529 | /* Split into components */ |
Jason Edmeades | 409368e | 2007-02-27 23:19:24 +0000 | [diff] [blame] | 530 | WCMD_splitpath(fullfilename, drive, dir, fname, ext); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 531 | |
| 532 | /* 5. Handle 'd' : Drive Letter */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 533 | if (memchrW(firstModifier, 'd', modifierLen) != NULL) { |
| 534 | strcatW(finaloutput, drive); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 535 | doneModifier = TRUE; |
| 536 | doneFileModifier = TRUE; |
| 537 | } |
| 538 | |
| 539 | /* 6. Handle 'p' : Path */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 540 | if (memchrW(firstModifier, 'p', modifierLen) != NULL) { |
| 541 | strcatW(finaloutput, dir); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 542 | doneModifier = TRUE; |
| 543 | doneFileModifier = TRUE; |
| 544 | } |
| 545 | |
| 546 | /* 7. Handle 'n' : Name */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 547 | if (memchrW(firstModifier, 'n', modifierLen) != NULL) { |
| 548 | strcatW(finaloutput, fname); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 549 | doneModifier = TRUE; |
| 550 | doneFileModifier = TRUE; |
| 551 | } |
| 552 | |
| 553 | /* 8. Handle 'x' : Ext */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 554 | if (memchrW(firstModifier, 'x', modifierLen) != NULL) { |
| 555 | strcatW(finaloutput, ext); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 556 | doneModifier = TRUE; |
| 557 | doneFileModifier = TRUE; |
| 558 | } |
| 559 | |
| 560 | /* If 's' but no other parameter, dump the whole thing */ |
| 561 | if (!doneFileModifier && |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 562 | memchrW(firstModifier, 's', modifierLen) != NULL) { |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 563 | doneModifier = TRUE; |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 564 | if (finaloutput[0] != 0x00) strcatW(finaloutput, space); |
| 565 | strcatW(finaloutput, outputparam); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 566 | } |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | /* If No other modifier processed, just add in parameter */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 571 | if (!doneModifier) strcpyW(finaloutput, outputparam); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 572 | |
| 573 | /* Finish by inserting the replacement into the string */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 574 | pos = WCMD_strdupW(lastModifier+1); |
| 575 | strcpyW(*start, finaloutput); |
| 576 | strcatW(*start, pos); |
Jason Edmeades | fcec39f | 2007-02-20 17:49:43 +0000 | [diff] [blame] | 577 | free(pos); |
| 578 | } |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 579 | |
| 580 | /******************************************************************* |
| 581 | * WCMD_call - processes a batch call statement |
| 582 | * |
| 583 | * If there is a leading ':', calls within this batch program |
| 584 | * otherwise launches another program. |
| 585 | */ |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 586 | void WCMD_call (WCHAR *command) { |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 587 | |
| 588 | /* Run other program if no leading ':' */ |
| 589 | if (*command != ':') { |
| 590 | WCMD_run_program(command, 1); |
| 591 | } else { |
| 592 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 593 | WCHAR gotoLabel[MAX_PATH]; |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 594 | |
Jason Edmeades | b8aa5fc | 2007-06-03 22:07:42 +0100 | [diff] [blame] | 595 | strcpyW(gotoLabel, param1); |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 596 | |
| 597 | if (context) { |
| 598 | |
| 599 | LARGE_INTEGER li; |
| 600 | |
| 601 | /* Save the current file position, call the same file, |
| 602 | restore position */ |
| 603 | li.QuadPart = 0; |
Francois Gouget | e46b99d | 2007-03-04 01:59:59 +0100 | [diff] [blame] | 604 | li.u.LowPart = SetFilePointer(context -> h, li.u.LowPart, |
| 605 | &li.u.HighPart, FILE_CURRENT); |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 606 | |
| 607 | WCMD_batch (param1, command, 1, gotoLabel, context->h); |
| 608 | |
Francois Gouget | e46b99d | 2007-03-04 01:59:59 +0100 | [diff] [blame] | 609 | SetFilePointer(context -> h, li.u.LowPart, |
| 610 | &li.u.HighPart, FILE_BEGIN); |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 611 | } else { |
Jason Edmeades | 5cc492c | 2007-06-03 22:07:39 +0100 | [diff] [blame] | 612 | WCMD_output_asis( WCMD_LoadMessage(WCMD_CALLINSCRIPT)); |
Jason Edmeades | 327d7ef | 2007-02-23 22:19:25 +0000 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | } |