From c5ee64a101a09366b02c18bb6f43ab9503d86af4 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 25 May 2020 20:34:08 +0200 Subject: [PATCH] winegcc: Add support for @file arguments. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- tools/winegcc/winegcc.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c index d350adc724c..a1ba0340097 100644 --- a/tools/winegcc/winegcc.c +++ b/tools/winegcc/winegcc.c @@ -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 */