GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — reactos/base/shell/cmd/start.c at master · reactos/reactos

Expand file tree

/

start.c

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
345 lines (323 loc) · 10.1 KB
/

start.c

Copy path

File metadata and controls

345 lines (323 loc) · 10.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/*
* START.C - start internal command.
*
*
* History:
*
* 24-Jul-1999 (Eric Kohl)
* Started.
*
* 30-Apr-2005 (Magnus Olsen <[email protected]>)
* Remove all hardcoded strings in En.rc
*/
#include "precomp.h"
#ifdef INCLUDE_CMD_START
/* Find the end of an option, and turn it into a nul-terminated string
* in place. (It's moved back one character, to make room for the nul) */
static TCHAR *GetParameter(TCHAR **pPointer)
{
BOOL bInQuote = FALSE;
TCHAR *start = *pPointer;
TCHAR *p;
for (p = start; *p; p++)
{
if (!bInQuote && (*p == _T('/') || _istspace(*p)))
break;
bInQuote ^= (*p == _T('"'));
p[-1] = *p;
}
p[-1] = _T('\0');
*pPointer = p;
return start - 1;
}
INT cmd_start (LPTSTR Rest)
{
TCHAR szFullName[CMDLINE_LENGTH];
TCHAR szUnquotedName[CMDLINE_LENGTH];
TCHAR *param = NULL;
TCHAR *dot;
INT size;
LPTSTR comspec;
BOOL bWait = FALSE;
BOOL bBat = FALSE;
BOOL bCreate = FALSE;
TCHAR szFullCmdLine[CMDLINE_LENGTH];
PROCESS_INFORMATION prci;
STARTUPINFO stui;
#ifdef UNICODE
DWORD dwCreationFlags = CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT;
#else
DWORD dwCreationFlags = CREATE_NEW_CONSOLE;
#endif
DWORD dwAffinityMask = 0;
LPTSTR lpTitle = NULL;
LPTSTR lpDirectory = NULL;
LPTSTR lpEnvironment = NULL;
WORD wShowWindow = SW_SHOWNORMAL;
while (1)
{
if (_istspace(*Rest))
{
Rest++;
}
else if (*Rest == _T('"') && !lpTitle)
{
lpTitle = GetParameter(&Rest);
StripQuotes(lpTitle);
}
else if (*Rest == _T('/'))
{
LPTSTR option;
Rest++;
option = GetParameter(&Rest);
if (*option == _T('?'))
{
ConOutResPaging(TRUE,STRING_START_HELP1);
return 0;
}
else if (_totupper(*option) == _T('D'))
{
lpDirectory = option + 1;
if (!*lpDirectory)
{
while (_istspace(*Rest))
Rest++;
lpDirectory = GetParameter(&Rest);
}
StripQuotes(lpDirectory);
}
else if (_totupper(*option) == _T('I'))
{
/* rest of the option is apparently ignored */
lpEnvironment = lpOriginalEnvironment;
}
else if (!_tcsicmp(option, _T("MIN")))
{
wShowWindow = SW_MINIMIZE;
}
else if (!_tcsicmp(option, _T("MAX")))
{
wShowWindow = SW_MAXIMIZE;
}
else if (!_tcsicmp(option, _T("AFFINITY")))
{
TCHAR *end;
while (_istspace(*Rest))
Rest++;
option = GetParameter(&Rest);
/* Affinity mask is given in hexadecimal */
dwAffinityMask = _tcstoul(option, &end, 16);
if (*end != _T('\0') || dwAffinityMask == 0 ||
dwAffinityMask == (DWORD)-1)
{
ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, option);
return 1;
}
dwCreationFlags |= CREATE_SUSPENDED;
}
else if (!_tcsicmp(option, _T("B")))
{
dwCreationFlags &= ~CREATE_NEW_CONSOLE;
dwCreationFlags |= CREATE_NEW_PROCESS_GROUP;
}
else if (!_tcsicmp(option, _T("LOW")))
{
dwCreationFlags |= IDLE_PRIORITY_CLASS;
}
else if (!_tcsicmp(option, _T("NORMAL")))
{
dwCreationFlags |= NORMAL_PRIORITY_CLASS;
}
else if (!_tcsicmp(option, _T("HIGH")))
{
dwCreationFlags |= HIGH_PRIORITY_CLASS;
}
else if (!_tcsicmp(option, _T("REALTIME")))
{
dwCreationFlags |= REALTIME_PRIORITY_CLASS;
}
else if (!_tcsicmp(option, _T("ABOVENORMAL")))
{
dwCreationFlags |= ABOVE_NORMAL_PRIORITY_CLASS;
}
else if (!_tcsicmp(option, _T("BELOWNORMAL")))
{
dwCreationFlags |= BELOW_NORMAL_PRIORITY_CLASS;
}
else if (!_tcsicmp(option, _T("SEPARATE")))
{
dwCreationFlags |= CREATE_SEPARATE_WOW_VDM;
}
else if (!_tcsicmp(option, _T("SHARED")))
{
dwCreationFlags |= CREATE_SHARED_WOW_VDM;
}
else if (!_tcsicmp(option, _T("W")) ||
!_tcsicmp(option, _T("WAIT")))
{
bWait = TRUE;
}
else
{
ConErrResPrintf(STRING_TYPE_ERROR, option);
return 0;
}
}
else
{
/* It's not an option - must be the beginning of
* the actual command. Leave the loop. */
break;
}
}
/* get comspec */
comspec = cmd_alloc ( MAX_PATH * sizeof(TCHAR));
if (!comspec)
{
WARN("Cannot allocate memory for start comspec!\n");
error_out_of_memory();
return 1;
}
SetLastError(0);
size = GetEnvironmentVariable (_T("COMSPEC"), comspec, MAX_PATH);
if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
{
_tcscpy(comspec, _T("cmd"));
}
else
{
if (size > MAX_PATH)
{
LPTSTR Oldcomspec = comspec;
comspec = cmd_realloc(comspec,size * sizeof(TCHAR) );
if (comspec==NULL)
{
cmd_free(Oldcomspec);
return 1;
}
size = GetEnvironmentVariable (_T("COMSPEC"), comspec, size);
}
}
nErrorLevel = 0;
if (!*Rest)
{
Rest = _T("cmd.exe");
}
else
/* Parsing the command that gets called by start, and it's parameters */
{
BOOL bInside = FALSE;
INT i;
/* find the end of the command and put the arguments in param */
for (i = 0; Rest[i]; i++)
{
if (Rest[i] == _T('\"'))
bInside = !bInside;
if (_istspace(Rest[i]) && !bInside)
{
param = &Rest[i+1];
Rest[i] = _T('\0');
break;
}
}
}
_tcscpy(szUnquotedName, Rest);
StripQuotes(szUnquotedName);
/* get the PATH environment variable and parse it */
/* search the PATH environment variable for the binary */
if (SearchForExecutable(szUnquotedName, szFullName))
{
/* check if this is a .BAT or .CMD file */
dot = _tcsrchr(szFullName, _T('.'));
if (dot && (!_tcsicmp(dot, _T(".bat")) || !_tcsicmp(dot, _T(".cmd"))))
{
bBat = TRUE;
_stprintf(szFullCmdLine, _T("\"%s\" /K %s"), comspec, Rest);
TRACE ("[BATCH: %s %s]\n", debugstr_aw(szFullName), debugstr_aw(Rest));
}
else
{
TRACE ("[EXEC: %s %s]\n", debugstr_aw(szFullName), debugstr_aw(Rest));
_tcscpy(szFullCmdLine, szFullName);
}
/* build command line for CreateProcess() */
if (param != NULL)
{
_tcsncat(szFullCmdLine, _T(" "), CMDLINE_LENGTH - _tcslen(szFullCmdLine));
_tcsncat(szFullCmdLine, param, CMDLINE_LENGTH - _tcslen(szFullCmdLine));
}
/* fill startup info */
memset (&stui, 0, sizeof (STARTUPINFO));
stui.cb = sizeof (STARTUPINFO);
stui.dwFlags = STARTF_USESHOWWINDOW;
stui.lpTitle = lpTitle;
stui.wShowWindow = wShowWindow;
bCreate = CreateProcess(bBat ? comspec : szFullName,
szFullCmdLine, NULL, NULL, TRUE, dwCreationFlags,
lpEnvironment, lpDirectory, &stui, &prci);
if (bCreate)
{
if (dwAffinityMask)
{
SetProcessAffinityMask(prci.hProcess, dwAffinityMask);
ResumeThread(prci.hThread);
}
CloseHandle(prci.hThread);
}
}
else
{
/* The file name did not seem to be valid, but maybe it's actually a
* directory or URL, so we still want to pass it to ShellExecute. */
_tcscpy(szFullName, szUnquotedName);
}
if (!bCreate)
{
/* CreateProcess didn't work; try ShellExecute */
DWORD flags = SEE_MASK_NOCLOSEPROCESS;
if (!(dwCreationFlags & CREATE_NEW_CONSOLE))
flags |= SEE_MASK_NO_CONSOLE;
prci.hProcess = RunFile(flags, szFullName, param, lpDirectory, wShowWindow);
}
if (prci.hProcess != NULL)
{
if (bWait)
{
DWORD dwExitCode;
WaitForSingleObject (prci.hProcess, INFINITE);
GetExitCodeProcess (prci.hProcess, &dwExitCode);
nErrorLevel = (INT)dwExitCode;
}
CloseHandle (prci.hProcess);
/* Update the local code page cache */
{
UINT uNewInputCodePage = GetConsoleCP();
UINT uNewOutputCodePage = GetConsoleOutputCP();
if ((InputCodePage != uNewInputCodePage) ||
(OutputCodePage != uNewOutputCodePage))
{
InputCodePage = uNewInputCodePage;
OutputCodePage = uNewOutputCodePage;
/* Reset the current thread UI language */
if (IsConsoleHandle(ConStreamGetOSHandle(StdOut)) ||
IsConsoleHandle(ConStreamGetOSHandle(StdErr)))
{
ConSetThreadUILanguage(0);
}
/* Update the streams cached code page */
ConStdStreamsSetCacheCodePage(InputCodePage, OutputCodePage);
/* Update the locale as well */
InitLocale();
}
}
}
else
{
ErrorMessage(GetLastError (),
_T("Error executing CreateProcess()!!\n"));
}
cmd_free(comspec);
return 0;
}
#endif
/* EOF */
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.