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