*/
void __getmainargs(int* argc, char*** argv, char*** env, int expand_wildcards, int* new_mode)
{
- int i, doexpand, slashesAdded, escapedQuote, inQuotes, bufferIndex;
+ int i, doexpand, slashesAdded, escapedQuote, inQuotes, bufferIndex, anyLetter;
size_t len;
char* buffer;
i = 0;
doexpand = expand_wildcards;
escapedQuote = FALSE;
+ anyLetter = FALSE;
slashesAdded = 0;
inQuotes = 0;
bufferIndex = 0;
// Arguments are delimited by white space, which is either a space or a tab.
if (i >= len || ((_acmdln[i] == ' ' || _acmdln[i] == '\t') && !inQuotes))
{
- aexpand(strndup(buffer, bufferIndex), doexpand);
+ // Handle the case when empty spaces are in the end of the cmdline
+ if (anyLetter)
+ {
+ aexpand(strndup(buffer, bufferIndex), doexpand);
+ }
// Copy the last element from buffer and quit the loop
if (i >= len)
{
while (_acmdln[i] == ' ' || _acmdln[i] == '\t')
++i;
+ anyLetter = FALSE;
bufferIndex = 0;
slashesAdded = 0;
escapedQuote = FALSE;
continue;
}
+ anyLetter = TRUE;
+
if (_acmdln[i] == '\\')
{
buffer[bufferIndex++] = _acmdln[i];
void __wgetmainargs(int* argc, wchar_t*** wargv, wchar_t*** wenv,
int expand_wildcards, int* new_mode)
{
- int i, doexpand, slashesAdded, escapedQuote, inQuotes, bufferIndex;
+ int i, doexpand, slashesAdded, escapedQuote, inQuotes, bufferIndex, anyLetter;
size_t len;
wchar_t* buffer;
i = 0;
doexpand = expand_wildcards;
escapedQuote = FALSE;
+ anyLetter = TRUE;
slashesAdded = 0;
inQuotes = 0;
bufferIndex = 0;
// Arguments are delimited by white space, which is either a space or a tab.
if (i >= len || ((_wcmdln[i] == ' ' || _wcmdln[i] == '\t') && !inQuotes))
{
- wexpand(wcsndup(buffer, bufferIndex), doexpand);
+ // Handle the case when empty spaces are in the end of the cmdline
+ if (anyLetter)
+ {
+ wexpand(wcsndup(buffer, bufferIndex), doexpand);
+ }
// Copy the last element from buffer and quit the loop
if (i >= len)
{
while (_wcmdln[i] == ' ' || _wcmdln[i] == '\t')
++i;
+ anyLetter = FALSE;
bufferIndex = 0;
slashesAdded = 0;
escapedQuote = FALSE;
continue;
}
+ anyLetter = TRUE;
+
if (_wcmdln[i] == '\\')
{
buffer[bufferIndex++] = _wcmdln[i];