winegcc: Add support for @file arguments.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2020-05-25 20:34:08 +02:00 committed by Alexandre Julliard
parent f42e4431fb
commit c5ee64a101
1 changed files with 39 additions and 1 deletions

View File

@ -1623,7 +1623,45 @@ int main(int argc, char **argv)
for (i = 1; i < argc; i++)
{
strarray_add( opts.args, argv[i] );
char *input_buffer = NULL, *iter, *opt, *out;
struct stat st;
int fd;
if (argv[i][0] != '@' || (fd = open( argv[i] + 1, O_RDONLY | O_BINARY )) == -1)
{
strarray_add( opts.args, argv[i] );
continue;
}
if ((fstat( fd, &st ) == -1)) error( "Cannot stat %s", argv[i] + 1 );
if (st.st_size)
{
input_buffer = xmalloc( st.st_size + 1 );
if (read( fd, input_buffer, st.st_size ) != st.st_size) error( "Cannot read %s\n", argv[i] + 1 );
}
close( fd );
for (iter = input_buffer; iter < input_buffer + st.st_size; iter++)
{
char quote = 0;
while (iter < input_buffer + st.st_size && isspace(*iter)) iter++;
if (iter == input_buffer + st.st_size) break;
opt = out = iter;
while (iter < input_buffer + st.st_size && (quote || !isspace(*iter)))
{
if (*iter == quote)
{
iter++;
quote = 0;
}
else if (*iter == '\'' || *iter == '"') quote = *iter++;
else
{
if (*iter == '\\' && iter + 1 < input_buffer + st.st_size) iter++;
*out++ = *iter++;
}
}
*out = 0;
strarray_add( opts.args, opt );
}
}
/* parse options */