From 2064181c1f120e8d537952b3eeed5ab6938a59bb Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 23 Sep 2021 11:52:15 +0200 Subject: [PATCH] winegcc: Unify the strarray implementation with the one from makedep. Signed-off-by: Alexandre Julliard --- tools/winegcc/utils.c | 157 +++----- tools/winegcc/utils.h | 31 +- tools/winegcc/winegcc.c | 862 ++++++++++++++++++++-------------------- 3 files changed, 491 insertions(+), 559 deletions(-) diff --git a/tools/winegcc/utils.c b/tools/winegcc/utils.c index 63d675122c0..8bd20321d1f 100644 --- a/tools/winegcc/utils.c +++ b/tools/winegcc/utils.c @@ -34,12 +34,6 @@ # define min(x,y) (((x) < (y)) ? (x) : (y)) #endif -#if defined(_WIN32) && !defined(__CYGWIN__) -# define PATH_SEPARATOR ';' -#else -# define PATH_SEPARATOR ':' -#endif - int verbose = 0; void error(const char* s, ...) @@ -83,8 +77,8 @@ int strendswith(const char* str, const char* end) { int l = strlen(str); int m = strlen(end); - - return l >= m && strcmp(str + l - m, end) == 0; + + return l >= m && strcmp(str + l - m, end) == 0; } char* strmake(const char* fmt, ...) @@ -106,82 +100,60 @@ char* strmake(const char* fmt, ...) } } -strarray* strarray_alloc(void) +void strarray_add( struct strarray *array, const char *str ) { - strarray* arr = xmalloc(sizeof(*arr)); - arr->maximum = arr->size = 0; - arr->base = NULL; - return arr; -} - -void strarray_free(strarray* arr) -{ - free(arr->base); - free(arr); -} - -void strarray_add(strarray* arr, const char* str) -{ - if (arr->size == arr->maximum) + if (array->count == array->size) { - arr->maximum += 10; - arr->base = xrealloc(arr->base, sizeof(*(arr->base)) * arr->maximum); + if (array->size) array->size *= 2; + else array->size = 16; + array->str = xrealloc( array->str, sizeof(array->str[0]) * array->size ); } - arr->base[arr->size++] = str; + array->str[array->count++] = str; } -void strarray_del(strarray* arr, unsigned int i) -{ - if (i >= arr->size) error("Invalid index i=%d\n", i); - memmove(&arr->base[i], &arr->base[i + 1], (arr->size - i - 1) * sizeof(arr->base[0])); - arr->size--; -} - -void strarray_addall(strarray* arr, const strarray* from) +void strarray_addall( struct strarray *array, struct strarray added ) { unsigned int i; - for (i = 0; i < from->size; i++) - strarray_add(arr, from->base[i]); + for (i = 0; i < added.count; i++) strarray_add( array, added.str[i] ); } -strarray* strarray_dup(const strarray* arr) +struct strarray strarray_fromstring( const char *str, const char *delim ) { - strarray* dup = strarray_alloc(); - unsigned int i; + struct strarray array = empty_strarray; + char *buf = xstrdup( str ); + const char *tok; - for (i = 0; i < arr->size; i++) - strarray_add(dup, arr->base[i]); - - return dup; + for (tok = strtok( buf, delim ); tok; tok = strtok( NULL, delim )) + strarray_add( &array, xstrdup( tok )); + free( buf ); + return array; } -strarray* strarray_fromstring(const char* str, const char* delim) +static struct strarray strarray_frompath( const char *path ) { - strarray* arr = strarray_alloc(); - char* buf = strdup(str); - const char* tok; - - for(tok = strtok(buf, delim); tok; tok = strtok(0, delim)) - strarray_add(arr, strdup(tok)); - - free(buf); - return arr; + if (!path) return empty_strarray; +#if defined(_WIN32) && !defined(__CYGWIN__) + return strarray_fromstring( path, ";" ); +#else + return strarray_fromstring( path, ":" ); +#endif } -char* strarray_tostring(const strarray* arr, const char* sep) +char *strarray_tostring( struct strarray array, const char *sep ) { - char *str, *newstr; - unsigned int i; + char *str; + unsigned int i, len = 1 + (array.count - 1) * strlen(sep); - str = strmake("%s", arr->base[0]); - for (i = 1; i < arr->size; i++) + if (!array.count) return xstrdup(""); + for (i = 0; i < array.count; i++) len += strlen( array.str[i] ); + str = xmalloc( len ); + strcpy( str, array.str[0] ); + for (i = 1; i < array.count; i++) { - newstr = strmake("%s%s%s", str, sep, arr->base[i]); - free(str); - str = newstr; + strcat( str, sep ); + strcat( str, array.str[i] ); } - return str; } @@ -296,24 +268,25 @@ static file_type guess_lib_type(enum target_platform platform, const char* dir, return file_na; } -file_type get_lib_type(enum target_platform platform, strarray* path, const char *library, +file_type get_lib_type(enum target_platform platform, struct strarray path, const char *library, const char *prefix, const char *suffix, char** file) { unsigned int i; if (!suffix) suffix = ".a"; - for (i = 0; i < path->size; i++) + for (i = 0; i < path.count; i++) { - file_type type = guess_lib_type(platform, path->base[i], library, prefix, suffix, file); + file_type type = guess_lib_type(platform, path.str[i], library, prefix, suffix, file); if (type != file_na) return type; } return file_na; } -const char *find_binary( const strarray* prefix, const char *name ) +const char *find_binary( struct strarray prefix, const char *name ) { char *file_name, *args; - static strarray *path; + struct strarray dirs = empty_strarray; + static struct strarray path; unsigned int i; if (strchr( name, '/' )) return name; @@ -321,47 +294,29 @@ const char *find_binary( const strarray* prefix, const char *name ) file_name = xstrdup( name ); if ((args = strchr( file_name, ' ' ))) *args++ = 0; - if (prefix) - { - for (i = 0; i < prefix->size; i++) - { - struct stat st; - char *prog = strmake( "%s/%s%s", prefix->base[i], file_name, EXEEXT ); - if (stat( prog, &st ) == 0 && S_ISREG( st.st_mode ) && (st.st_mode & 0111)) - return args ? strmake( "%s %s", prog, args ) : prog; - free( prog ); - } - } - if (!path) - { - path = strarray_alloc(); + if (!path.count) strarray_addall( &path, strarray_frompath( getenv( "PATH" ))); - /* then append the PATH directories */ - if (getenv( "PATH" )) - { - char *p = xstrdup( getenv( "PATH" )); - while (*p) - { - strarray_add( path, p ); - while (*p && *p != PATH_SEPARATOR) p++; - if (!*p) break; - *p++ = 0; - } - } + strarray_addall( &dirs, prefix ); + strarray_addall( &dirs, path ); + for (i = 0; i < dirs.count; i++) + { + struct stat st; + char *prog = strmake( "%s/%s%s", dirs.str[i], file_name, EXEEXT ); + if (stat( prog, &st ) == 0 && S_ISREG( st.st_mode ) && (st.st_mode & 0111)) + return args ? strmake( "%s %s", prog, args ) : prog; + free( prog ); } - return prefix == path ? NULL : find_binary( path, name ); + return NULL; } -int spawn(const strarray* prefix, const strarray* args, int ignore_errors) +int spawn(struct strarray prefix, struct strarray args, int ignore_errors) { unsigned int i; int status; - strarray* arr = strarray_dup(args); const char** argv; - char* prog = 0; - strarray_add(arr, NULL); - argv = arr->base; + strarray_add( &args, NULL); + argv = args.str; argv[0] = find_binary( prefix, argv[0] ); if (verbose) @@ -381,7 +336,5 @@ int spawn(const strarray* prefix, const strarray* args, int ignore_errors) exit(3); } - free(prog); - strarray_free(arr); return status; } diff --git a/tools/winegcc/utils.h b/tools/winegcc/utils.h index 39fe8a8d08a..09bda31e8a9 100644 --- a/tools/winegcc/utils.h +++ b/tools/winegcc/utils.h @@ -61,20 +61,19 @@ char *xstrdup( const char *str ); char* strmake(const char* fmt, ...) __attribute__((__format__ (__printf__, 1, 2 ))); int strendswith(const char* str, const char* end); -typedef struct { - size_t maximum; - size_t size; - const char** base; -} strarray; +struct strarray +{ + unsigned int count; /* strings in use */ + unsigned int size; /* total allocated size */ + const char **str; +}; -strarray* strarray_alloc(void); -strarray* strarray_dup(const strarray* arr); -void strarray_free(strarray* arr); -void strarray_add(strarray* arr, const char* str); -void strarray_del(strarray* arr, unsigned int i); -void strarray_addall(strarray* arr, const strarray* from); -strarray* strarray_fromstring(const char* str, const char* delim); -char* strarray_tostring(const strarray* arr, const char* sep); +static const struct strarray empty_strarray; + +void strarray_add( struct strarray *array, const char *str ); +void strarray_addall( struct strarray *array, struct strarray added ); +struct strarray strarray_fromstring( const char *str, const char *delim ); +char *strarray_tostring( struct strarray array, const char *sep ); typedef enum { file_na, file_other, file_obj, file_res, file_rc, @@ -84,9 +83,9 @@ typedef enum { char* get_basename(const char* file); void create_file(const char* name, int mode, const char* fmt, ...); file_type get_file_type(const char* filename); -file_type get_lib_type(enum target_platform platform, strarray* path, const char *library, +file_type get_lib_type(enum target_platform platform, struct strarray path, const char *library, const char *prefix, const char *suffix, char** file); -const char *find_binary( const strarray* prefix, const char *name ); -int spawn(const strarray* prefix, const strarray* arr, int ignore_errors); +const char *find_binary( struct strarray prefix, const char *name ); +int spawn(struct strarray prefix, struct strarray arr, int ignore_errors); extern int verbose; diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c index 5bad8451113..0cb5ae390de 100644 --- a/tools/winegcc/winegcc.c +++ b/tools/winegcc/winegcc.c @@ -143,7 +143,7 @@ static const char *output_file_name; static const char *output_debug_file; static const char *output_implib; static int keep_generated = 0; -static strarray* tmp_files; +static struct strarray tmp_files; #ifdef HAVE_SIGSET_T static sigset_t signal_mask; #endif @@ -233,14 +233,14 @@ struct options const char* prelink; const char* debug_file; const char* out_implib; - strarray* prefix; - strarray* lib_dirs; - strarray* args; - strarray* linker_args; - strarray* compiler_args; - strarray* winebuild_args; - strarray* files; - strarray* delayimports; + struct strarray prefix; + struct strarray lib_dirs; + struct strarray args; + struct strarray linker_args; + struct strarray compiler_args; + struct strarray winebuild_args; + struct strarray files; + struct strarray delayimports; }; #ifdef __i386__ @@ -284,8 +284,8 @@ static void clean_temp_files(void) if (keep_generated) return; - for (i = 0; i < tmp_files->size; i++) - unlink(tmp_files->base[i]); + for (i = 0; i < tmp_files.count; i++) + unlink(tmp_files.str[i]); } /* clean things up when aborting on a signal */ @@ -317,7 +317,7 @@ static char* get_temp_file(const char* prefix, const char* suffix) if (fd == -1) error( "could not create temp file\n" ); } close( fd ); - strarray_add(tmp_files, tmp); + strarray_add(&tmp_files, tmp); #ifdef HAVE_SIGPROCMASK sigprocmask( SIG_SETMASK, &old_set, NULL ); #endif @@ -360,13 +360,13 @@ static const struct { "objcopy", "llvm-objcopy" }, }; -static strarray* build_tool_name( struct options *opts, enum tool tool ) +static struct strarray build_tool_name( struct options *opts, enum tool tool ) { const char *base = tool_names[tool].base; const char *llvm_base = tool_names[tool].llvm_base; const char *deflt = tool_names[tool].deflt; const char *path; - strarray *ret; + struct strarray ret = empty_strarray; char* str; if (opts->target && opts->version) @@ -392,7 +392,7 @@ static strarray* build_tool_name( struct options *opts, enum tool tool ) if (!path) { error( "Could not find %s\n", base ); - return NULL; + return ret; } ret = strarray_fromstring( path, " " ); @@ -400,16 +400,16 @@ static strarray* build_tool_name( struct options *opts, enum tool tool ) { if (opts->target) { - strarray_add( ret, "-target" ); - strarray_add( ret, opts->target ); + strarray_add( &ret, "-target" ); + strarray_add( &ret, opts->target ); } - strarray_add( ret, "-Wno-unused-command-line-argument" ); - strarray_add( ret, "-fuse-ld=lld" ); + strarray_add( &ret, "-Wno-unused-command-line-argument" ); + strarray_add( &ret, "-fuse-ld=lld" ); } return ret; } -static strarray* get_translator(struct options *opts) +static struct strarray get_translator(struct options *opts) { enum tool tool; @@ -431,21 +431,22 @@ static strarray* get_translator(struct options *opts) return build_tool_name( opts, tool ); } -static int try_link( const strarray *prefix, const strarray *link_tool, const char *cflags ) +static int try_link( struct strarray prefix, struct strarray link_tool, const char *cflags ) { const char *in = get_temp_file( "try_link", ".c" ); const char *out = get_temp_file( "try_link", ".out" ); const char *err = get_temp_file( "try_link", ".err" ); - strarray *link = strarray_dup( link_tool ); + struct strarray link = empty_strarray; int sout = -1, serr = -1; int ret; create_file( in, 0644, "int main(void){return 1;}\n" ); - strarray_add( link, "-o" ); - strarray_add( link, out ); - strarray_addall( link, strarray_fromstring( cflags, " " ) ); - strarray_add( link, in ); + strarray_addall( &link, link_tool ); + strarray_add( &link, "-o" ); + strarray_add( &link, out ); + strarray_addall( &link, strarray_fromstring( cflags, " " ) ); + strarray_add( &link, in ); sout = dup( fileno(stdout) ); freopen( err, "w", stdout ); @@ -462,42 +463,41 @@ static int try_link( const strarray *prefix, const strarray *link_tool, const ch dup2( serr, fileno(stderr) ); close( serr ); } - strarray_free( link ); return ret; } -static strarray *get_link_args( struct options *opts, const char *output_name ) +static struct strarray get_link_args( struct options *opts, const char *output_name ) { - strarray *link_args = get_translator( opts ); - strarray *flags = strarray_alloc(); + struct strarray link_args = get_translator( opts ); + struct strarray flags = empty_strarray; - strarray_addall( link_args, opts->linker_args ); + strarray_addall( &link_args, opts->linker_args ); - if (verbose > 1) strarray_add( flags, "-v" ); + if (verbose > 1) strarray_add( &flags, "-v" ); switch (opts->target_platform) { case PLATFORM_APPLE: - strarray_add( flags, opts->unix_lib ? "-dynamiclib" : "-bundle" ); - strarray_add( flags, "-multiply_defined" ); - strarray_add( flags, "suppress" ); + strarray_add( &flags, opts->unix_lib ? "-dynamiclib" : "-bundle" ); + strarray_add( &flags, "-multiply_defined" ); + strarray_add( &flags, "suppress" ); if (opts->target_cpu == CPU_POWERPC) { - strarray_add( flags, "-read_only_relocs" ); - strarray_add( flags, "warning" ); + strarray_add( &flags, "-read_only_relocs" ); + strarray_add( &flags, "warning" ); } if (opts->image_base) { - strarray_add( flags, "-image_base" ); - strarray_add( flags, opts->image_base ); + strarray_add( &flags, "-image_base" ); + strarray_add( &flags, opts->image_base ); } - if (opts->strip) strarray_add( flags, "-Wl,-x" ); + if (opts->strip) strarray_add( &flags, "-Wl,-x" ); if (opts->unix_lib) { - strarray_add( flags, "-install_name" ); - strarray_add( flags, strmake( "@loader_path/%s.so", output_name ) ); + strarray_add( &flags, "-install_name" ); + strarray_add( &flags, strmake( "@loader_path/%s.so", output_name ) ); } - strarray_addall( link_args, flags ); + strarray_addall( &link_args, flags ); return link_args; case PLATFORM_SOLARIS: @@ -506,113 +506,113 @@ static strarray *get_link_args( struct options *opts, const char *output_name ) const char *align = opts->section_align ? opts->section_align : "0x1000"; create_file( mapfile, 0644, "text = A%s;\ndata = A%s;\n", align, align ); - strarray_add( flags, strmake("-Wl,-M,%s", mapfile) ); - strarray_add( tmp_files, mapfile ); + strarray_add( &flags, strmake("-Wl,-M,%s", mapfile) ); + strarray_add( &tmp_files, mapfile ); } break; case PLATFORM_ANDROID: /* the Android loader requires a soname for all libraries */ - strarray_add( flags, strmake( "-Wl,-soname,%s.so", output_name )); + strarray_add( &flags, strmake( "-Wl,-soname,%s.so", output_name )); break; case PLATFORM_MINGW: case PLATFORM_CYGWIN: if (opts->shared || opts->win16_app) { - strarray_add( flags, "-shared" ); - strarray_add( flags, "-Wl,--kill-at" ); + strarray_add( &flags, "-shared" ); + strarray_add( &flags, "-Wl,--kill-at" ); } - else strarray_add( flags, opts->gui_app ? "-mwindows" : "-mconsole" ); + else strarray_add( &flags, opts->gui_app ? "-mwindows" : "-mconsole" ); - if (opts->unicode_app) strarray_add( flags, "-municode" ); - if (opts->nodefaultlibs || opts->use_msvcrt) strarray_add( flags, "-nodefaultlibs" ); - if (opts->nostartfiles || opts->use_msvcrt) strarray_add( flags, "-nostartfiles" ); - if (opts->subsystem) strarray_add( flags, strmake("-Wl,--subsystem,%s", opts->subsystem )); + if (opts->unicode_app) strarray_add( &flags, "-municode" ); + if (opts->nodefaultlibs || opts->use_msvcrt) strarray_add( &flags, "-nodefaultlibs" ); + if (opts->nostartfiles || opts->use_msvcrt) strarray_add( &flags, "-nostartfiles" ); + if (opts->subsystem) strarray_add( &flags, strmake("-Wl,--subsystem,%s", opts->subsystem )); - strarray_add( flags, "-Wl,--nxcompat" ); + strarray_add( &flags, "-Wl,--nxcompat" ); - if (opts->image_base) strarray_add( flags, strmake("-Wl,--image-base,%s", opts->image_base )); + if (opts->image_base) strarray_add( &flags, strmake("-Wl,--image-base,%s", opts->image_base )); if (opts->large_address_aware && opts->target_cpu == CPU_x86) - strarray_add( flags, "-Wl,--large-address-aware" ); + strarray_add( &flags, "-Wl,--large-address-aware" ); /* make sure we don't need a libgcc_s dll on Windows */ - strarray_add( flags, "-static-libgcc" ); + strarray_add( &flags, "-static-libgcc" ); if (opts->debug_file && strendswith(opts->debug_file, ".pdb")) - strarray_add(link_args, strmake("-Wl,-pdb,%s", opts->debug_file)); + strarray_add(&link_args, strmake("-Wl,-pdb,%s", opts->debug_file)); if (opts->out_implib) - strarray_add(link_args, strmake("-Wl,--out-implib,%s", opts->out_implib)); + strarray_add(&link_args, strmake("-Wl,--out-implib,%s", opts->out_implib)); if (!try_link( opts->prefix, link_args, "-Wl,--file-alignment,0x1000" )) - strarray_add( link_args, strmake( "-Wl,--file-alignment,%s", + strarray_add( &link_args, strmake( "-Wl,--file-alignment,%s", opts->file_align ? opts->file_align : "0x1000" )); else if (!try_link( opts->prefix, link_args, "-Wl,-Xlink=-filealign:0x1000" )) /* lld from llvm 10 does not support mingw style --file-alignment, * but it's possible to use msvc syntax */ - strarray_add( link_args, strmake( "-Wl,-Xlink=-filealign:%s", + strarray_add( &link_args, strmake( "-Wl,-Xlink=-filealign:%s", opts->file_align ? opts->file_align : "0x1000" )); - strarray_addall( link_args, flags ); + strarray_addall( &link_args, flags ); return link_args; case PLATFORM_WINDOWS: if (opts->shared || opts->win16_app) { - strarray_add( flags, "-shared" ); - strarray_add( flags, "-Wl,-kill-at" ); + strarray_add( &flags, "-shared" ); + strarray_add( &flags, "-Wl,-kill-at" ); } - if (opts->unicode_app) strarray_add( flags, "-municode" ); - if (opts->nodefaultlibs || opts->use_msvcrt) strarray_add( flags, "-nodefaultlibs" ); - if (opts->nostartfiles || opts->use_msvcrt) strarray_add( flags, "-nostartfiles" ); - if (opts->image_base) strarray_add( flags, strmake("-Wl,-base:%s", opts->image_base )); + if (opts->unicode_app) strarray_add( &flags, "-municode" ); + if (opts->nodefaultlibs || opts->use_msvcrt) strarray_add( &flags, "-nodefaultlibs" ); + if (opts->nostartfiles || opts->use_msvcrt) strarray_add( &flags, "-nostartfiles" ); + if (opts->image_base) strarray_add( &flags, strmake("-Wl,-base:%s", opts->image_base )); if (opts->subsystem) - strarray_add( flags, strmake("-Wl,-subsystem:%s", opts->subsystem )); + strarray_add( &flags, strmake("-Wl,-subsystem:%s", opts->subsystem )); else - strarray_add( flags, strmake("-Wl,-subsystem:%s", opts->gui_app ? "windows" : "console" )); + strarray_add( &flags, strmake("-Wl,-subsystem:%s", opts->gui_app ? "windows" : "console" )); if (opts->debug_file && strendswith(opts->debug_file, ".pdb")) { - strarray_add(link_args, "-Wl,-debug"); - strarray_add(link_args, strmake("-Wl,-pdb:%s", opts->debug_file)); + strarray_add(&link_args, "-Wl,-debug"); + strarray_add(&link_args, strmake("-Wl,-pdb:%s", opts->debug_file)); } else if (!opts->strip) - strarray_add(link_args, "-Wl,-debug:dwarf"); + strarray_add(&link_args, "-Wl,-debug:dwarf"); if (opts->out_implib) - strarray_add(link_args, strmake("-Wl,-implib:%s", opts->out_implib)); + strarray_add(&link_args, strmake("-Wl,-implib:%s", opts->out_implib)); - strarray_add( link_args, strmake( "-Wl,-filealign:%s", opts->file_align ? opts->file_align : "0x1000" )); + strarray_add( &link_args, strmake( "-Wl,-filealign:%s", opts->file_align ? opts->file_align : "0x1000" )); - strarray_addall( link_args, flags ); + strarray_addall( &link_args, flags ); return link_args; default: if (opts->image_base) { if (!try_link( opts->prefix, link_args, strmake("-Wl,-Ttext-segment=%s", opts->image_base)) ) - strarray_add( flags, strmake("-Wl,-Ttext-segment=%s", opts->image_base) ); + strarray_add( &flags, strmake("-Wl,-Ttext-segment=%s", opts->image_base) ); else opts->prelink = PRELINK; } if (!try_link( opts->prefix, link_args, "-Wl,-z,max-page-size=0x1000")) - strarray_add( flags, "-Wl,-z,max-page-size=0x1000"); - if (opts->unix_lib) strarray_add( flags, strmake( "-Wl,-soname,%s.so", output_name )); + strarray_add( &flags, "-Wl,-z,max-page-size=0x1000"); + if (opts->unix_lib) strarray_add( &flags, strmake( "-Wl,-soname,%s.so", output_name )); break; } /* generic Unix shared library flags */ - strarray_add( link_args, "-shared" ); - strarray_add( link_args, "-Wl,-Bsymbolic" ); + strarray_add( &link_args, "-shared" ); + strarray_add( &link_args, "-Wl,-Bsymbolic" ); if (!opts->noshortwchar && opts->target_cpu == CPU_ARM) - strarray_add( flags, "-Wl,--no-wchar-size-warning" ); + strarray_add( &flags, "-Wl,--no-wchar-size-warning" ); if (!try_link( opts->prefix, link_args, "-Wl,-z,defs" )) - strarray_add( flags, "-Wl,-z,defs" ); + strarray_add( &flags, "-Wl,-z,defs" ); - strarray_addall( link_args, flags ); + strarray_addall( &link_args, flags ); return link_args; } @@ -774,15 +774,14 @@ static void init_argv0_dir( const char *argv0 ) static void compile(struct options* opts, const char* lang) { - strarray* comp_args = strarray_alloc(); + struct strarray comp_args = get_translator(opts); unsigned int i, j; int gcc_defs = 0; - strarray* gcc; - strarray* gpp; + struct strarray gcc; + struct strarray gpp; - strarray_addall(comp_args, get_translator(opts)); if (opts->force_pointer_size) - strarray_add( comp_args, strmake("-m%u", 8 * opts->force_pointer_size ) ); + strarray_add( &comp_args, strmake("-m%u", 8 * opts->force_pointer_size ) ); switch(opts->processor) { case proc_cpp: gcc_defs = 1; break; @@ -793,17 +792,15 @@ static void compile(struct options* opts, const char* lang) case proc_cxx: gcc = build_tool_name(opts, TOOL_CC); gpp = build_tool_name(opts, TOOL_CXX); - for ( j = 0; !gcc_defs && j < comp_args->size; j++ ) + for ( j = 0; !gcc_defs && j < comp_args.count; j++ ) { - const char *cc = comp_args->base[j]; + const char *cc = comp_args.str[j]; - for (i = 0; !gcc_defs && i < gcc->size; i++) - gcc_defs = gcc->base[i][0] != '-' && strendswith(cc, gcc->base[i]); - for (i = 0; !gcc_defs && i < gpp->size; i++) - gcc_defs = gpp->base[i][0] != '-' && strendswith(cc, gpp->base[i]); + for (i = 0; !gcc_defs && i < gcc.count; i++) + gcc_defs = gcc.str[i][0] != '-' && strendswith(cc, gcc.str[i]); + for (i = 0; !gcc_defs && i < gpp.count; i++) + gcc_defs = gpp.str[i][0] != '-' && strendswith(cc, gpp.str[i]); } - strarray_free(gcc); - strarray_free(gpp); break; } @@ -814,30 +811,30 @@ static void compile(struct options* opts, const char* lang) { if (gcc_defs && !opts->wine_objdir && !opts->noshortwchar) { - strarray_add(comp_args, "-fshort-wchar"); - strarray_add(comp_args, "-DWINE_UNICODE_NATIVE"); + strarray_add(&comp_args, "-fshort-wchar"); + strarray_add(&comp_args, "-DWINE_UNICODE_NATIVE"); } - strarray_add(comp_args, "-D_REENTRANT"); + strarray_add(&comp_args, "-D_REENTRANT"); if (opts->pic) - strarray_add(comp_args, "-fPIC"); + strarray_add(&comp_args, "-fPIC"); else - strarray_add(comp_args, "-fno-PIC"); + strarray_add(&comp_args, "-fno-PIC"); } if (opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64) { - strarray_add(comp_args, "-DWIN64"); - strarray_add(comp_args, "-D_WIN64"); - strarray_add(comp_args, "-D__WIN64"); - strarray_add(comp_args, "-D__WIN64__"); + strarray_add(&comp_args, "-DWIN64"); + strarray_add(&comp_args, "-D_WIN64"); + strarray_add(&comp_args, "-D__WIN64"); + strarray_add(&comp_args, "-D__WIN64__"); } - strarray_add(comp_args, "-DWIN32"); - strarray_add(comp_args, "-D_WIN32"); - strarray_add(comp_args, "-D__WIN32"); - strarray_add(comp_args, "-D__WIN32__"); - strarray_add(comp_args, "-D__WINNT"); - strarray_add(comp_args, "-D__WINNT__"); + strarray_add(&comp_args, "-DWIN32"); + strarray_add(&comp_args, "-D_WIN32"); + strarray_add(&comp_args, "-D__WIN32"); + strarray_add(&comp_args, "-D__WIN32__"); + strarray_add(&comp_args, "-D__WINNT"); + strarray_add(&comp_args, "-D__WINNT__"); if (gcc_defs) { @@ -845,77 +842,76 @@ static void compile(struct options* opts, const char* lang) { case CPU_x86_64: case CPU_ARM64: - strarray_add(comp_args, "-D__stdcall=__attribute__((ms_abi))"); - strarray_add(comp_args, "-D__cdecl=__stdcall"); - strarray_add(comp_args, "-D__fastcall=__stdcall"); + strarray_add(&comp_args, "-D__stdcall=__attribute__((ms_abi))"); + strarray_add(&comp_args, "-D__cdecl=__stdcall"); + strarray_add(&comp_args, "-D__fastcall=__stdcall"); break; case CPU_x86: - strarray_add(comp_args, "-D__stdcall=__attribute__((__stdcall__)) __attribute__((__force_align_arg_pointer__))"); - strarray_add(comp_args, "-D__cdecl=__attribute__((__cdecl__)) __attribute__((__force_align_arg_pointer__))"); - strarray_add(comp_args, "-D__fastcall=__attribute__((__fastcall__))"); + strarray_add(&comp_args, "-D__stdcall=__attribute__((__stdcall__)) __attribute__((__force_align_arg_pointer__))"); + strarray_add(&comp_args, "-D__cdecl=__attribute__((__cdecl__)) __attribute__((__force_align_arg_pointer__))"); + strarray_add(&comp_args, "-D__fastcall=__attribute__((__fastcall__))"); break; case CPU_ARM: - strarray_add(comp_args, "-D__stdcall=__attribute__((pcs(\"aapcs-vfp\")))"); - strarray_add(comp_args, "-D__cdecl=__stdcall"); - strarray_add(comp_args, "-D__fastcall=__stdcall"); + strarray_add(&comp_args, "-D__stdcall=__attribute__((pcs(\"aapcs-vfp\")))"); + strarray_add(&comp_args, "-D__cdecl=__stdcall"); + strarray_add(&comp_args, "-D__fastcall=__stdcall"); break; case CPU_POWERPC: - strarray_add(comp_args, "-D__stdcall="); - strarray_add(comp_args, "-D__cdecl="); - strarray_add(comp_args, "-D__fastcall="); + strarray_add(&comp_args, "-D__stdcall="); + strarray_add(&comp_args, "-D__cdecl="); + strarray_add(&comp_args, "-D__fastcall="); break; } - strarray_add(comp_args, "-D_stdcall=__stdcall"); - strarray_add(comp_args, "-D_cdecl=__cdecl"); - strarray_add(comp_args, "-D_fastcall=__fastcall"); - strarray_add(comp_args, "-D__declspec(x)=__declspec_##x"); - strarray_add(comp_args, "-D__declspec_align(x)=__attribute__((aligned(x)))"); - strarray_add(comp_args, "-D__declspec_allocate(x)=__attribute__((section(x)))"); - strarray_add(comp_args, "-D__declspec_deprecated=__attribute__((deprecated))"); - strarray_add(comp_args, "-D__declspec_dllimport=__attribute__((dllimport))"); - strarray_add(comp_args, "-D__declspec_dllexport=__attribute__((dllexport))"); - strarray_add(comp_args, "-D__declspec_naked=__attribute__((naked))"); - strarray_add(comp_args, "-D__declspec_noinline=__attribute__((noinline))"); - strarray_add(comp_args, "-D__declspec_noreturn=__attribute__((noreturn))"); - strarray_add(comp_args, "-D__declspec_nothrow=__attribute__((nothrow))"); - strarray_add(comp_args, "-D__declspec_novtable=__attribute__(())"); /* ignore it */ - strarray_add(comp_args, "-D__declspec_selectany=__attribute__((weak))"); - strarray_add(comp_args, "-D__declspec_thread=__thread"); + strarray_add(&comp_args, "-D_stdcall=__stdcall"); + strarray_add(&comp_args, "-D_cdecl=__cdecl"); + strarray_add(&comp_args, "-D_fastcall=__fastcall"); + strarray_add(&comp_args, "-D__declspec(x)=__declspec_##x"); + strarray_add(&comp_args, "-D__declspec_align(x)=__attribute__((aligned(x)))"); + strarray_add(&comp_args, "-D__declspec_allocate(x)=__attribute__((section(x)))"); + strarray_add(&comp_args, "-D__declspec_deprecated=__attribute__((deprecated))"); + strarray_add(&comp_args, "-D__declspec_dllimport=__attribute__((dllimport))"); + strarray_add(&comp_args, "-D__declspec_dllexport=__attribute__((dllexport))"); + strarray_add(&comp_args, "-D__declspec_naked=__attribute__((naked))"); + strarray_add(&comp_args, "-D__declspec_noinline=__attribute__((noinline))"); + strarray_add(&comp_args, "-D__declspec_noreturn=__attribute__((noreturn))"); + strarray_add(&comp_args, "-D__declspec_nothrow=__attribute__((nothrow))"); + strarray_add(&comp_args, "-D__declspec_novtable=__attribute__(())"); /* ignore it */ + strarray_add(&comp_args, "-D__declspec_selectany=__attribute__((weak))"); + strarray_add(&comp_args, "-D__declspec_thread=__thread"); } - strarray_add(comp_args, "-D__int8=char"); - strarray_add(comp_args, "-D__int16=short"); - strarray_add(comp_args, "-D__int32=int"); + strarray_add(&comp_args, "-D__int8=char"); + strarray_add(&comp_args, "-D__int16=short"); + strarray_add(&comp_args, "-D__int32=int"); if (opts->target_cpu == CPU_x86_64 || opts->target_cpu == CPU_ARM64) - strarray_add(comp_args, "-D__int64=long"); + strarray_add(&comp_args, "-D__int64=long"); else - strarray_add(comp_args, "-D__int64=long long"); + strarray_add(&comp_args, "-D__int64=long long"); no_compat_defines: - strarray_add(comp_args, "-D__WINE__"); + strarray_add(&comp_args, "-D__WINE__"); /* options we handle explicitly */ if (opts->compile_only) - strarray_add(comp_args, "-c"); + strarray_add(&comp_args, "-c"); if (opts->output_name) { - strarray_add(comp_args, "-o"); - strarray_add(comp_args, opts->output_name); + strarray_add(&comp_args, "-o"); + strarray_add(&comp_args, opts->output_name); } /* the rest of the pass-through parameters */ - for ( j = 0 ; j < opts->compiler_args->size ; j++ ) - strarray_add(comp_args, opts->compiler_args->base[j]); + strarray_addall(&comp_args, opts->compiler_args); /* the language option, if any */ if (lang && strcmp(lang, "-xnone")) - strarray_add(comp_args, lang); + strarray_add(&comp_args, lang); /* last, but not least, the files */ - for ( j = 0; j < opts->files->size; j++ ) + for ( j = 0; j < opts->files.count; j++ ) { - if (opts->files->base[j][0] != '-' || !opts->files->base[j][1]) /* not an option or bare '-' (i.e. stdin) */ - strarray_add(comp_args, opts->files->base[j]); + if (opts->files.str[j][0] != '-' || !opts->files.str[j][1]) /* not an option or bare '-' (i.e. stdin) */ + strarray_add(&comp_args, opts->files.str[j]); } /* standard includes come last in the include search path */ @@ -928,31 +924,30 @@ no_compat_defines: if (opts->use_msvcrt) { - if (includedir) strarray_add( comp_args, strmake( "%s%s/wine/msvcrt", isystem, includedir )); + if (includedir) strarray_add( &comp_args, strmake( "%s%s/wine/msvcrt", isystem, includedir )); for (j = 0; j < ARRAY_SIZE(incl_dirs); j++) { if (j && !strcmp( incl_dirs[0], incl_dirs[j] )) continue; - strarray_add(comp_args, strmake( "%s%s%s/wine/msvcrt", isystem, root, incl_dirs[j] )); + strarray_add(&comp_args, strmake( "%s%s%s/wine/msvcrt", isystem, root, incl_dirs[j] )); } - strarray_add(comp_args, "-D__MSVCRT__"); + strarray_add(&comp_args, "-D__MSVCRT__"); } if (includedir) { - strarray_add( comp_args, strmake( "%s%s/wine/windows", isystem, includedir )); - strarray_add( comp_args, strmake( "%s%s", idirafter, includedir )); + strarray_add( &comp_args, strmake( "%s%s/wine/windows", isystem, includedir )); + strarray_add( &comp_args, strmake( "%s%s", idirafter, includedir )); } for (j = 0; j < ARRAY_SIZE(incl_dirs); j++) { if (j && !strcmp( incl_dirs[0], incl_dirs[j] )) continue; - strarray_add(comp_args, strmake( "%s%s%s/wine/windows", isystem, root, incl_dirs[j] )); - strarray_add(comp_args, strmake( "%s%s%s", idirafter, root, incl_dirs[j] )); + strarray_add(&comp_args, strmake( "%s%s%s/wine/windows", isystem, root, incl_dirs[j] )); + strarray_add(&comp_args, strmake( "%s%s%s", idirafter, root, incl_dirs[j] )); } } else if (opts->wine_objdir) - strarray_add(comp_args, strmake("-I%s/include", opts->wine_objdir) ); + strarray_add(&comp_args, strmake("-I%s/include", opts->wine_objdir) ); spawn(opts->prefix, comp_args, 0); - strarray_free(comp_args); } static const char* compile_to_object(struct options* opts, const char* file, const char* lang) @@ -966,21 +961,20 @@ static const char* compile_to_object(struct options* opts, const char* file, con copts = *opts; copts.output_name = get_temp_file(base_name, ".o"); copts.compile_only = 1; - copts.files = strarray_alloc(); - strarray_add(copts.files, file); + copts.files = empty_strarray; + strarray_add(&copts.files, file); compile(&copts, lang); - strarray_free(copts.files); free(base_name); return copts.output_name; } /* return the initial set of options needed to run winebuild */ -static strarray *get_winebuild_args(struct options *opts) +static struct strarray get_winebuild_args(struct options *opts) { const char* winebuild = getenv("WINEBUILD"); const char *binary = NULL; - strarray *spec_args = strarray_alloc(); + struct strarray spec_args = empty_strarray; unsigned int i; if (opts->winebuild) @@ -994,43 +988,38 @@ static strarray *get_winebuild_args(struct options *opts) else binary = find_binary( opts->prefix, "winebuild" ); if (!binary) error( "Could not find winebuild\n" ); - strarray_add( spec_args, binary ); - if (verbose) strarray_add( spec_args, "-v" ); - if (keep_generated) strarray_add( spec_args, "--save-temps" ); + strarray_add( &spec_args, binary ); + if (verbose) strarray_add( &spec_args, "-v" ); + if (keep_generated) strarray_add( &spec_args, "--save-temps" ); if (opts->target) { - strarray_add( spec_args, "--target" ); - strarray_add( spec_args, opts->target ); + strarray_add( &spec_args, "--target" ); + strarray_add( &spec_args, opts->target ); } - if (opts->prefix) - { - for (i = 0; i < opts->prefix->size; i++) - strarray_add( spec_args, strmake( "-B%s", opts->prefix->base[i] )); - } - strarray_addall( spec_args, opts->winebuild_args ); - if (opts->unwind_tables) strarray_add( spec_args, "-fasynchronous-unwind-tables" ); - else strarray_add( spec_args, "-fno-asynchronous-unwind-tables" ); + for (i = 0; i < opts->prefix.count; i++) + strarray_add( &spec_args, strmake( "-B%s", opts->prefix.str[i] )); + strarray_addall( &spec_args, opts->winebuild_args ); + if (opts->unwind_tables) strarray_add( &spec_args, "-fasynchronous-unwind-tables" ); + else strarray_add( &spec_args, "-fno-asynchronous-unwind-tables" ); return spec_args; } static void fixup_constructors( struct options *opts, const char *file ) { - strarray *args = get_winebuild_args( opts ); + struct strarray args = get_winebuild_args( opts ); - strarray_add( args, "--fixup-ctors" ); - strarray_add( args, file ); + strarray_add( &args, "--fixup-ctors" ); + strarray_add( &args, file ); spawn( opts->prefix, args, 0 ); - strarray_free( args ); } static void make_wine_builtin( struct options *opts, const char *file ) { - strarray *args = get_winebuild_args( opts ); + struct strarray args = get_winebuild_args( opts ); - strarray_add( args, "--builtin" ); - strarray_add( args, file ); + strarray_add( &args, "--builtin" ); + strarray_add( &args, file ); spawn( opts->prefix, args, 0 ); - strarray_free( args ); } /* check if there is a static lib associated to a given dll */ @@ -1042,18 +1031,19 @@ static char *find_static_lib( const char *dll ) return NULL; } -static const char *find_libgcc(const strarray *prefix, const strarray *link_tool) +static const char *find_libgcc(struct strarray prefix, struct strarray link_tool) { const char *out = get_temp_file( "find_libgcc", ".out" ); const char *err = get_temp_file( "find_libgcc", ".err" ); - strarray *link = strarray_dup( link_tool ); + struct strarray link = empty_strarray; int sout = -1, serr = -1; char *libgcc, *p; struct stat st; size_t cnt; int ret; - strarray_add( link, "-print-libgcc-file-name" ); + strarray_addall( &link, link_tool ); + strarray_add( &link, "-print-libgcc-file-name" ); sout = dup( fileno(stdout) ); freopen( out, "w", stdout ); @@ -1070,7 +1060,6 @@ static const char *find_libgcc(const strarray *prefix, const strarray *link_tool dup2( serr, fileno(stderr) ); close( serr ); } - strarray_free( link ); if (ret || stat(out, &st) || !st.st_size) return NULL; @@ -1086,7 +1075,8 @@ static const char *find_libgcc(const strarray *prefix, const strarray *link_tool /* add specified library to the list of files */ -static void add_library( struct options *opts, strarray *lib_dirs, strarray *files, const char *library ) +static void add_library( struct options *opts, struct strarray lib_dirs, + struct strarray *files, const char *library ) { char *static_lib, *fullname = 0; @@ -1114,12 +1104,12 @@ static void add_library( struct options *opts, strarray *lib_dirs, strarray *fil /* run winebuild to generate the .spec.o file */ static const char *build_spec_obj( struct options *opts, const char *spec_file, const char *output_file, - strarray *files, strarray *lib_dirs, const char *entry_point ) + struct strarray files, struct strarray lib_dirs, const char *entry_point ) { unsigned int i; int is_pe = is_pe_target( opts ); - strarray *spec_args = get_winebuild_args( opts ); - strarray *tool; + struct strarray spec_args = get_winebuild_args( opts ); + struct strarray tool; const char *spec_o_name, *output_name; int fake_module = strendswith(output_file, ".fake"); @@ -1127,90 +1117,95 @@ static const char *build_spec_obj( struct options *opts, const char *spec_file, if ((output_name = strrchr(output_file, '/'))) output_name++; else output_name = output_file; - if ((tool = build_tool_name( opts, TOOL_CC ))) strarray_add( spec_args, strmake( "--cc-cmd=%s", strarray_tostring( tool, " " ))); - if (!is_pe && (tool = build_tool_name( opts, TOOL_LD ))) strarray_add( spec_args, strmake( "--ld-cmd=%s", strarray_tostring( tool, " " ))); + tool = build_tool_name( opts, TOOL_CC ); + strarray_add( &spec_args, strmake( "--cc-cmd=%s", strarray_tostring( tool, " " ))); + if (!is_pe) + { + tool = build_tool_name( opts, TOOL_LD ); + strarray_add( &spec_args, strmake( "--ld-cmd=%s", strarray_tostring( tool, " " ))); + } spec_o_name = get_temp_file(output_name, ".spec.o"); if (opts->force_pointer_size) - strarray_add(spec_args, strmake("-m%u", 8 * opts->force_pointer_size )); - if (opts->pic && !is_pe) strarray_add(spec_args, "-fPIC"); - strarray_add(spec_args, opts->shared ? "--dll" : "--exe"); + strarray_add(&spec_args, strmake("-m%u", 8 * opts->force_pointer_size )); + if (opts->pic && !is_pe) strarray_add(&spec_args, "-fPIC"); + strarray_add(&spec_args, opts->shared ? "--dll" : "--exe"); if (fake_module) { - strarray_add(spec_args, "--fake-module"); - strarray_add(spec_args, "-o"); - strarray_add(spec_args, output_file); + strarray_add(&spec_args, "--fake-module"); + strarray_add(&spec_args, "-o"); + strarray_add(&spec_args, output_file); } else { - strarray_add(spec_args, "-o"); - strarray_add(spec_args, spec_o_name); + strarray_add(&spec_args, "-o"); + strarray_add(&spec_args, spec_o_name); } if (spec_file) { - strarray_add(spec_args, "-E"); - strarray_add(spec_args, spec_file); + strarray_add(&spec_args, "-E"); + strarray_add(&spec_args, spec_file); } if (!opts->shared) { - strarray_add(spec_args, "-F"); - strarray_add(spec_args, output_name); - strarray_add(spec_args, "--subsystem"); - strarray_add(spec_args, opts->gui_app ? "windows" : "console"); - if (opts->large_address_aware) strarray_add( spec_args, "--large-address-aware" ); + strarray_add(&spec_args, "-F"); + strarray_add(&spec_args, output_name); + strarray_add(&spec_args, "--subsystem"); + strarray_add(&spec_args, opts->gui_app ? "windows" : "console"); + if (opts->large_address_aware) strarray_add( &spec_args, "--large-address-aware" ); } - if (opts->target_platform == PLATFORM_WINDOWS) strarray_add(spec_args, "--safeseh"); + if (opts->target_platform == PLATFORM_WINDOWS) strarray_add(&spec_args, "--safeseh"); if (entry_point) { - strarray_add(spec_args, "--entry"); - strarray_add(spec_args, entry_point); + strarray_add(&spec_args, "--entry"); + strarray_add(&spec_args, entry_point); } if (opts->subsystem) { - strarray_add(spec_args, "--subsystem"); - strarray_add(spec_args, opts->subsystem); + strarray_add(&spec_args, "--subsystem"); + strarray_add(&spec_args, opts->subsystem); } - for (i = 0; i < lib_dirs->size; i++) - strarray_add(spec_args, strmake("-L%s", lib_dirs->base[i])); + for (i = 0; i < lib_dirs.count; i++) + strarray_add(&spec_args, strmake("-L%s", lib_dirs.str[i])); if (!is_pe) { - for (i = 0; i < opts->delayimports->size; i++) - strarray_add(spec_args, strmake("-d%s", opts->delayimports->base[i])); + for (i = 0; i < opts->delayimports.count; i++) + strarray_add(&spec_args, strmake("-d%s", opts->delayimports.str[i])); } /* add resource files */ - for (i = 0; i < files->size; i++) - if (files->base[i][1] == 'r') strarray_add(spec_args, files->base[i]); + for (i = 0; i < files.count; i++) + if (files.str[i][1] == 'r') strarray_add(&spec_args, files.str[i]); /* add other files */ - strarray_add(spec_args, "--"); - for (i = 0; i < files->size; i++) + strarray_add(&spec_args, "--"); + for (i = 0; i < files.count; i++) { - switch(files->base[i][1]) + switch(files.str[i][1]) { case 'd': case 'a': case 'o': - strarray_add(spec_args, files->base[i] + 2); + strarray_add(&spec_args, files.str[i] + 2); break; } } spawn(opts->prefix, spec_args, 0); - strarray_free (spec_args); return spec_o_name; } static void build(struct options* opts) { - strarray *lib_dirs, *files; - strarray *link_args, *implib_args, *tool; + struct strarray lib_dirs = empty_strarray; + struct strarray files = empty_strarray; + struct strarray link_args; char *output_file, *output_path; const char *spec_o_name = NULL, *libgcc = NULL; const char *output_name, *spec_file, *lang; @@ -1233,9 +1228,9 @@ static void build(struct options* opts) output_file = strdup( opts->output_name ? opts->output_name : "a.out" ); /* 'winegcc -o app xxx.exe.so' only creates the load script */ - if (opts->files->size == 1 && strendswith(opts->files->base[0], ".exe.so")) + if (opts->files.count == 1 && strendswith(opts->files.str[0], ".exe.so")) { - create_file(output_file, 0755, app_loader_template, opts->files->base[0]); + create_file(output_file, 0755, app_loader_template, opts->files.str[0]); return; } @@ -1262,24 +1257,22 @@ static void build(struct options* opts) if (!opts->wine_objdir) { char *lib_dir = get_lib_dir( opts ); - lib_dirs = strarray_dup(opts->lib_dirs); - strarray_add( lib_dirs, strmake( "%s%s", lib_dir, + strarray_addall( &lib_dirs, opts->lib_dirs ); + strarray_add( &lib_dirs, strmake( "%s%s", lib_dir, get_wine_arch_dir( opts->target_cpu, opts->target_platform ))); - strarray_add( lib_dirs, lib_dir ); + strarray_add( &lib_dirs, lib_dir ); } else { - lib_dirs = strarray_alloc(); - strarray_add(lib_dirs, strmake("%s/dlls", opts->wine_objdir)); - strarray_addall(lib_dirs, opts->lib_dirs); + strarray_add(&lib_dirs, strmake("%s/dlls", opts->wine_objdir)); + strarray_addall(&lib_dirs, opts->lib_dirs); } /* mark the files with their appropriate type */ spec_file = lang = 0; - files = strarray_alloc(); - for ( j = 0; j < opts->files->size; j++ ) + for ( j = 0; j < opts->files.count; j++ ) { - const char* file = opts->files->base[j]; + const char* file = opts->files.str[j]; if (file[0] != '-') { switch(get_file_type(file)) @@ -1295,10 +1288,10 @@ static void build(struct options* opts) error("Can't compile .rc file at the moment: %s\n", file); break; case file_res: - strarray_add(files, strmake("-r%s", file)); + strarray_add(&files, strmake("-r%s", file)); break; case file_obj: - strarray_add(files, strmake("-o%s", file)); + strarray_add(&files, strmake("-o%s", file)); break; case file_arh: if (opts->use_msvcrt) @@ -1308,26 +1301,26 @@ static void build(struct options* opts) else p = file; if (!strncmp(p, "libmsvcr", 8) || !strncmp(p, "libucrt", 7)) crt_lib = file; } - strarray_add(files, strmake("-a%s", file)); + strarray_add(&files, strmake("-a%s", file)); break; case file_so: - strarray_add(files, strmake("-s%s", file)); + strarray_add(&files, strmake("-s%s", file)); break; case file_na: error("File does not exist: %s\n", file); break; default: file = compile_to_object(opts, file, lang); - strarray_add(files, strmake("-o%s", file)); + strarray_add(&files, strmake("-o%s", file)); break; } } else if (file[1] == 'l') - add_library(opts, lib_dirs, files, file + 2 ); + add_library(opts, lib_dirs, &files, file + 2 ); else if (file[1] == 'x') lang = file; else if(file[1] == 'W') - strarray_add(files, file); + strarray_add(&files, file); } /* add the default libraries, if needed */ @@ -1336,17 +1329,17 @@ static void build(struct options* opts) { if (opts->gui_app) { - add_library(opts, lib_dirs, files, "shell32"); - add_library(opts, lib_dirs, files, "comdlg32"); - add_library(opts, lib_dirs, files, "gdi32"); + add_library(opts, lib_dirs, &files, "shell32"); + add_library(opts, lib_dirs, &files, "comdlg32"); + add_library(opts, lib_dirs, &files, "gdi32"); } - add_library(opts, lib_dirs, files, "advapi32"); - add_library(opts, lib_dirs, files, "user32"); + add_library(opts, lib_dirs, &files, "advapi32"); + add_library(opts, lib_dirs, &files, "user32"); } if (!opts->nodefaultlibs && !opts->unix_lib) { - add_library(opts, lib_dirs, files, "winecrt0"); + add_library(opts, lib_dirs, &files, "winecrt0"); if (opts->use_msvcrt) { if (!crt_lib) @@ -1354,13 +1347,13 @@ static void build(struct options* opts) if (strncmp( output_name, "msvcr", 5 ) && strncmp( output_name, "ucrt", 4 ) && strcmp( output_name, "crtdll.dll" )) - add_library(opts, lib_dirs, files, "ucrtbase"); + add_library(opts, lib_dirs, &files, "ucrtbase"); } - else strarray_add(files, strmake("-a%s", crt_lib)); + else strarray_add(&files, strmake("-a%s", crt_lib)); } - if (opts->win16_app) add_library(opts, lib_dirs, files, "kernel"); - add_library(opts, lib_dirs, files, "kernel32"); - add_library(opts, lib_dirs, files, "ntdll"); + if (opts->win16_app) add_library(opts, lib_dirs, &files, "kernel"); + add_library(opts, lib_dirs, &files, "kernel32"); + add_library(opts, lib_dirs, &files, "ntdll"); } /* set default entry point, if needed */ @@ -1388,11 +1381,11 @@ static void build(struct options* opts) if (!libgcc) libgcc = "-lgcc"; } - strarray_add(link_args, "-o"); - strarray_add(link_args, output_path); + strarray_add(&link_args, "-o"); + strarray_add(&link_args, output_path); - for ( j = 0; j < lib_dirs->size; j++ ) - strarray_add(link_args, strmake("-L%s", lib_dirs->base[j])); + for ( j = 0; j < lib_dirs.count; j++ ) + strarray_add(&link_args, strmake("-L%s", lib_dirs.str[j])); if (is_pe && opts->use_msvcrt && !entry_point && (opts->shared || opts->win16_app)) entry_point = opts->target_cpu == CPU_x86 ? "DllMainCRTStartup@12" : "DllMainCRTStartup"; @@ -1400,37 +1393,37 @@ static void build(struct options* opts) if (is_pe && entry_point) { if (opts->target_platform == PLATFORM_WINDOWS) - strarray_add(link_args, strmake("-Wl,-entry:%s", entry_point)); + strarray_add(&link_args, strmake("-Wl,-entry:%s", entry_point)); else - strarray_add(link_args, strmake("-Wl,--entry,%s%s", + strarray_add(&link_args, strmake("-Wl,--entry,%s%s", is_pe && opts->target_cpu == CPU_x86 ? "_" : "", entry_point)); } - if (spec_o_name) strarray_add(link_args, spec_o_name); + if (spec_o_name) strarray_add(&link_args, spec_o_name); if (is_pe) { - for (j = 0; j < opts->delayimports->size; j++) + for (j = 0; j < opts->delayimports.count; j++) { if (opts->target_platform == PLATFORM_WINDOWS) - strarray_add(link_args, strmake("-Wl,-delayload:%s", opts->delayimports->base[j])); + strarray_add(&link_args, strmake("-Wl,-delayload:%s", opts->delayimports.str[j])); else - strarray_add(link_args, strmake("-Wl,-delayload,%s",opts->delayimports->base[j])); + strarray_add(&link_args, strmake("-Wl,-delayload,%s",opts->delayimports.str[j])); } } - for ( j = 0; j < files->size; j++ ) + for ( j = 0; j < files.count; j++ ) { - const char* name = files->base[j] + 2; - switch(files->base[j][1]) + const char* name = files.str[j] + 2; + switch(files.str[j][1]) { case 'l': - strarray_add(link_args, strmake("-l%s", name)); + strarray_add(&link_args, strmake("-l%s", name)); break; case 's': case 'o': - strarray_add(link_args, name); + strarray_add(&link_args, name); break; case 'a': if (is_pe && !opts->use_msvcrt && !opts->lib_suffix && strchr(name, '/')) @@ -1448,28 +1441,28 @@ static void build(struct options* opts) if (ext) *ext = 0; p += 3; - strarray_add(link_args, strmake("-L%s", lib )); - strarray_add(link_args, strmake("-l%s", p )); + strarray_add(&link_args, strmake("-L%s", lib )); + strarray_add(&link_args, strmake("-l%s", p )); free( lib ); break; } free( lib ); } - strarray_add(link_args, name); + strarray_add(&link_args, name); break; case 'W': - strarray_add(link_args, files->base[j]); + strarray_add(&link_args, files.str[j]); break; } } if (!opts->nostdlib && !is_pe) { - strarray_add(link_args, "-lm"); - strarray_add(link_args, "-lc"); + strarray_add(&link_args, "-lm"); + strarray_add(&link_args, "-lc"); } - if (libgcc) strarray_add(link_args, libgcc); + if (libgcc) strarray_add(&link_args, libgcc); output_file_name = output_path; output_debug_file = opts->debug_file; @@ -1477,52 +1470,53 @@ static void build(struct options* opts) atexit( cleanup_output_files ); spawn(opts->prefix, link_args, 0); - strarray_free (link_args); if (opts->debug_file && !strendswith(opts->debug_file, ".pdb")) { - strarray *tool, *objcopy = build_tool_name(opts, TOOL_OBJCOPY); + struct strarray tool, objcopy = build_tool_name(opts, TOOL_OBJCOPY); - tool = strarray_dup(objcopy); - strarray_add(tool, "--only-keep-debug"); - strarray_add(tool, output_path); - strarray_add(tool, opts->debug_file); + strarray_addall( &tool, objcopy ); + strarray_add(&tool, "--only-keep-debug"); + strarray_add(&tool, output_path); + strarray_add(&tool, opts->debug_file); spawn(opts->prefix, tool, 1); - strarray_free(tool); - tool = strarray_dup(objcopy); - strarray_add(tool, "--strip-debug"); - strarray_add(tool, output_path); + tool = empty_strarray; + strarray_addall( &tool, objcopy ); + strarray_add(&tool, "--strip-debug"); + strarray_add(&tool, output_path); spawn(opts->prefix, tool, 1); - strarray_free(tool); - tool = objcopy; - strarray_add(tool, "--add-gnu-debuglink"); - strarray_add(tool, opts->debug_file); - strarray_add(tool, output_path); + tool = empty_strarray; + strarray_addall( &tool, objcopy ); + strarray_add(&tool, "--add-gnu-debuglink"); + strarray_add(&tool, opts->debug_file); + strarray_add(&tool, output_path); spawn(opts->prefix, tool, 0); - strarray_free(tool); } if (opts->unix_lib) return; if (opts->out_implib && !is_pe) { + struct strarray tool, implib_args; + if (!spec_file) error("--out-implib requires a .spec or .def file\n"); implib_args = get_winebuild_args( opts ); - if ((tool = build_tool_name( opts, TOOL_CC ))) strarray_add( implib_args, strmake( "--cc-cmd=%s", strarray_tostring( tool, " " ))); - if ((tool = build_tool_name( opts, TOOL_LD ))) strarray_add( implib_args, strmake( "--ld-cmd=%s", strarray_tostring( tool, " " ))); + tool = build_tool_name( opts, TOOL_CC ); + strarray_add( &implib_args, strmake( "--cc-cmd=%s", strarray_tostring( tool, " " ))); + tool = build_tool_name( opts, TOOL_LD ); + strarray_add( &implib_args, strmake( "--ld-cmd=%s", strarray_tostring( tool, " " ))); - strarray_add(implib_args, "--implib"); - strarray_add(implib_args, "-o"); - strarray_add(implib_args, opts->out_implib); - strarray_add(implib_args, "--export"); - strarray_add(implib_args, spec_file); + strarray_add(&implib_args, "--implib"); + strarray_add(&implib_args, "-o"); + strarray_add(&implib_args, opts->out_implib); + strarray_add(&implib_args, "--export"); + strarray_add(&implib_args, spec_file); spawn(opts->prefix, implib_args, 0); - strarray_free (implib_args); } /* set the base address with prelink if linker support is not present */ @@ -1530,13 +1524,12 @@ static void build(struct options* opts) { if (opts->prelink[0] && strcmp(opts->prelink,"false")) { - strarray *prelink_args = strarray_alloc(); - strarray_add(prelink_args, opts->prelink); - strarray_add(prelink_args, "--reloc-only"); - strarray_add(prelink_args, opts->image_base); - strarray_add(prelink_args, output_path); + struct strarray prelink_args = empty_strarray; + strarray_add(&prelink_args, opts->prelink); + strarray_add(&prelink_args, "--reloc-only"); + strarray_add(&prelink_args, opts->image_base); + strarray_add(&prelink_args, output_path); spawn(opts->prefix, prelink_args, 1); - strarray_free(prelink_args); } } @@ -1551,13 +1544,11 @@ static void build(struct options* opts) static void forward( struct options *opts ) { - strarray* args = strarray_alloc(); + struct strarray args = get_translator(opts); - strarray_addall(args, get_translator(opts)); - strarray_addall(args, opts->compiler_args); - strarray_addall(args, opts->linker_args); + strarray_addall(&args, opts->compiler_args); + strarray_addall(&args, opts->linker_args); spawn(opts->prefix, args, 0); - strarray_free (args); } static int is_linker_arg(const char* arg) @@ -1653,15 +1644,15 @@ static void parse_target_option( struct options *opts, const char *target ) static int is_option( struct options *opts, int i, const char *option, const char **option_arg ) { - if (!strcmp( opts->args->base[i], option )) + if (!strcmp( opts->args.str[i], option )) { - if (opts->args->size == i) error( "option %s requires an argument\n", opts->args->base[i] ); - *option_arg = opts->args->base[i + 1]; + if (opts->args.count == i) error( "option %s requires an argument\n", opts->args.str[i] ); + *option_arg = opts->args.str[i + 1]; return 1; } - if (!strncmp( opts->args->base[i], option, strlen(option) ) && opts->args->base[i][strlen(option)] == '=') + if (!strncmp( opts->args.str[i], option, strlen(option) ) && opts->args.str[i][strlen(option)] == '=') { - *option_arg = opts->args->base[i] + strlen(option) + 1; + *option_arg = opts->args.str[i] + strlen(option) + 1; return 1; } return 0; @@ -1690,20 +1681,12 @@ int main(int argc, char **argv) init_argv0_dir( argv[0] ); /* setup tmp file removal at exit */ - tmp_files = strarray_alloc(); atexit(clean_temp_files); /* initialize options */ memset(&opts, 0, sizeof(opts)); opts.target_cpu = build_cpu; opts.target_platform = build_platform; - opts.lib_dirs = strarray_alloc(); - opts.files = strarray_alloc(); - opts.linker_args = strarray_alloc(); - opts.compiler_args = strarray_alloc(); - opts.winebuild_args = strarray_alloc(); - opts.delayimports = strarray_alloc(); - opts.args = strarray_alloc(); opts.pic = 1; /* determine the processor type */ @@ -1718,7 +1701,7 @@ int main(int argc, char **argv) if (argv[i][0] != '@' || (fd = open( argv[i] + 1, O_RDONLY | O_BINARY )) == -1) { - strarray_add( opts.args, argv[i] ); + strarray_add( &opts.args, argv[i] ); continue; } if ((fstat( fd, &st ) == -1)) error( "Cannot stat %s\n", argv[i] + 1 ); @@ -1749,83 +1732,82 @@ int main(int argc, char **argv) } } *out = 0; - strarray_add( opts.args, opt ); + strarray_add( &opts.args, opt ); } } /* parse options */ - for (i = 0; i < opts.args->size; i++) + for (i = 0; i < opts.args.count; i++) { - if (opts.args->base[i][0] == '-' && opts.args->base[i][1]) /* option, except '-' alone is stdin, which is a file */ + if (opts.args.str[i][0] == '-' && opts.args.str[i][1]) /* option, except '-' alone is stdin, which is a file */ { /* determine if this switch is followed by a separate argument */ next_is_arg = 0; option_arg = 0; - switch(opts.args->base[i][1]) + switch(opts.args.str[i][1]) { case 'x': case 'o': case 'D': case 'U': case 'I': case 'A': case 'l': case 'u': case 'b': case 'V': case 'G': case 'L': case 'B': case 'R': case 'z': - if (opts.args->base[i][2]) option_arg = &opts.args->base[i][2]; + if (opts.args.str[i][2]) option_arg = &opts.args.str[i][2]; else next_is_arg = 1; break; case 'i': next_is_arg = 1; break; case 'a': - if (strcmp("-aux-info", opts.args->base[i]) == 0) + if (strcmp("-aux-info", opts.args.str[i]) == 0) next_is_arg = 1; - if (strcmp("-arch", opts.args->base[i]) == 0) + if (strcmp("-arch", opts.args.str[i]) == 0) next_is_arg = 1; break; case 'X': - if (strcmp("-Xlinker", opts.args->base[i]) == 0) + if (strcmp("-Xlinker", opts.args.str[i]) == 0) next_is_arg = 1; break; case 'M': - c = opts.args->base[i][2]; + c = opts.args.str[i][2]; if (c == 'F' || c == 'T' || c == 'Q') { - if (opts.args->base[i][3]) option_arg = &opts.args->base[i][3]; + if (opts.args.str[i][3]) option_arg = &opts.args.str[i][3]; else next_is_arg = 1; } break; case 'f': - if (strcmp("-framework", opts.args->base[i]) == 0) + if (strcmp("-framework", opts.args.str[i]) == 0) next_is_arg = 1; break; case 't': - next_is_arg = strcmp("-target", opts.args->base[i]) == 0; + next_is_arg = strcmp("-target", opts.args.str[i]) == 0; break; case '-': - next_is_arg = (strcmp("--param", opts.args->base[i]) == 0 || - strcmp("--sysroot", opts.args->base[i]) == 0 || - strcmp("--target", opts.args->base[i]) == 0 || - strcmp("--wine-objdir", opts.args->base[i]) == 0 || - strcmp("--winebuild", opts.args->base[i]) == 0 || - strcmp("--lib-suffix", opts.args->base[i]) == 0); + next_is_arg = (strcmp("--param", opts.args.str[i]) == 0 || + strcmp("--sysroot", opts.args.str[i]) == 0 || + strcmp("--target", opts.args.str[i]) == 0 || + strcmp("--wine-objdir", opts.args.str[i]) == 0 || + strcmp("--winebuild", opts.args.str[i]) == 0 || + strcmp("--lib-suffix", opts.args.str[i]) == 0); break; } if (next_is_arg) { - if (i + 1 >= opts.args->size) error("option -%c requires an argument\n", opts.args->base[i][1]); - option_arg = opts.args->base[i+1]; + if (i + 1 >= opts.args.count) error("option -%c requires an argument\n", opts.args.str[i][1]); + option_arg = opts.args.str[i+1]; } /* determine what options go 'as is' to the linker & the compiler */ - raw_linker_arg = is_linker_arg(opts.args->base[i]); + raw_linker_arg = is_linker_arg(opts.args.str[i]); raw_compiler_arg = !raw_linker_arg; raw_winebuild_arg = 0; /* do a bit of semantic analysis */ - switch (opts.args->base[i][1]) + switch (opts.args.str[i][1]) { case 'B': str = strdup(option_arg); if (strendswith(str, "/")) str[strlen(str) - 1] = 0; - if (!opts.prefix) opts.prefix = strarray_alloc(); - strarray_add(opts.prefix, str); + strarray_add(&opts.prefix, str); raw_linker_arg = 1; break; case 'b': @@ -1838,83 +1820,83 @@ int main(int argc, char **argv) break; case 'c': /* compile or assemble */ raw_compiler_arg = 0; - if (opts.args->base[i][2] == 0) opts.compile_only = 1; + if (opts.args.str[i][2] == 0) opts.compile_only = 1; /* fall through */ case 'S': /* generate assembler code */ case 'E': /* preprocess only */ - if (opts.args->base[i][2] == 0) linking = 0; + if (opts.args.str[i][2] == 0) linking = 0; break; case 'f': - if (strcmp("-fno-short-wchar", opts.args->base[i]) == 0) + if (strcmp("-fno-short-wchar", opts.args.str[i]) == 0) opts.noshortwchar = 1; - else if (!strcmp("-fasynchronous-unwind-tables", opts.args->base[i])) + else if (!strcmp("-fasynchronous-unwind-tables", opts.args.str[i])) opts.unwind_tables = 1; - else if (!strcmp("-fno-asynchronous-unwind-tables", opts.args->base[i])) + else if (!strcmp("-fno-asynchronous-unwind-tables", opts.args.str[i])) opts.unwind_tables = 0; - else if (!strcmp("-fPIC", opts.args->base[i]) || !strcmp("-fpic", opts.args->base[i])) + else if (!strcmp("-fPIC", opts.args.str[i]) || !strcmp("-fpic", opts.args.str[i])) opts.pic = 1; - else if (!strcmp("-fno-PIC", opts.args->base[i]) || !strcmp("-fno-pic", opts.args->base[i])) + else if (!strcmp("-fno-PIC", opts.args.str[i]) || !strcmp("-fno-pic", opts.args.str[i])) opts.pic = 0; break; case 'i': - if (!strcmp( "-isysroot", opts.args->base[i] )) opts.isysroot = opts.args->base[i + 1]; + if (!strcmp( "-isysroot", opts.args.str[i] )) opts.isysroot = opts.args.str[i + 1]; break; case 'l': - strarray_add(opts.files, strmake("-l%s", option_arg)); + strarray_add(&opts.files, strmake("-l%s", option_arg)); raw_compiler_arg = 0; break; case 'L': - strarray_add(opts.lib_dirs, option_arg); + strarray_add(&opts.lib_dirs, option_arg); raw_compiler_arg = 0; break; case 'M': /* map file generation */ linking = 0; break; case 'm': - if (strcmp("-mno-cygwin", opts.args->base[i]) == 0) + if (strcmp("-mno-cygwin", opts.args.str[i]) == 0) { opts.use_msvcrt = 1; raw_compiler_arg = 0; raw_winebuild_arg = 1; } - if (strcmp("-mcygwin", opts.args->base[i]) == 0) + if (strcmp("-mcygwin", opts.args.str[i]) == 0) { opts.use_msvcrt = 0; raw_compiler_arg = 0; } - else if (strcmp("-mwindows", opts.args->base[i]) == 0) + else if (strcmp("-mwindows", opts.args.str[i]) == 0) { opts.gui_app = 1; raw_compiler_arg = 0; } - else if (strcmp("-mconsole", opts.args->base[i]) == 0) + else if (strcmp("-mconsole", opts.args.str[i]) == 0) { opts.gui_app = 0; raw_compiler_arg = 0; } - else if (strcmp("-municode", opts.args->base[i]) == 0) + else if (strcmp("-municode", opts.args.str[i]) == 0) { opts.unicode_app = 1; raw_compiler_arg = 0; raw_winebuild_arg = 1; } - else if (strcmp("-mthreads", opts.args->base[i]) == 0) + else if (strcmp("-mthreads", opts.args.str[i]) == 0) { raw_compiler_arg = 0; } - else if (strcmp("-munix", opts.args->base[i]) == 0) + else if (strcmp("-munix", opts.args.str[i]) == 0) { opts.unix_lib = 1; raw_compiler_arg = 0; raw_winebuild_arg = 1; } - else if (strcmp("-m16", opts.args->base[i]) == 0) + else if (strcmp("-m16", opts.args.str[i]) == 0) { opts.win16_app = 1; raw_compiler_arg = 0; raw_winebuild_arg = 1; } - else if (strcmp("-m32", opts.args->base[i]) == 0) + else if (strcmp("-m32", opts.args.str[i]) == 0) { if (opts.target_cpu == CPU_x86_64) opts.target_cpu = CPU_x86; @@ -1923,7 +1905,7 @@ int main(int argc, char **argv) opts.force_pointer_size = 4; raw_linker_arg = 1; } - else if (strcmp("-m64", opts.args->base[i]) == 0) + else if (strcmp("-m64", opts.args.str[i]) == 0) { if (opts.target_cpu == CPU_x86) opts.target_cpu = CPU_x86_64; @@ -1932,25 +1914,25 @@ int main(int argc, char **argv) opts.force_pointer_size = 8; raw_linker_arg = 1; } - else if (!strcmp("-marm", opts.args->base[i] ) || !strcmp("-mthumb", opts.args->base[i] )) + else if (!strcmp("-marm", opts.args.str[i] ) || !strcmp("-mthumb", opts.args.str[i] )) { raw_linker_arg = 1; raw_winebuild_arg = 1; } - else if (!strncmp("-mcpu=", opts.args->base[i], 6) || - !strncmp("-mfpu=", opts.args->base[i], 6) || - !strncmp("-march=", opts.args->base[i], 7) || - !strncmp("-mfloat-abi=", opts.args->base[i], 12)) + else if (!strncmp("-mcpu=", opts.args.str[i], 6) || + !strncmp("-mfpu=", opts.args.str[i], 6) || + !strncmp("-march=", opts.args.str[i], 7) || + !strncmp("-mfloat-abi=", opts.args.str[i], 12)) raw_winebuild_arg = 1; break; case 'n': - if (strcmp("-nostdinc", opts.args->base[i]) == 0) + if (strcmp("-nostdinc", opts.args.str[i]) == 0) opts.nostdinc = 1; - else if (strcmp("-nodefaultlibs", opts.args->base[i]) == 0) + else if (strcmp("-nodefaultlibs", opts.args.str[i]) == 0) opts.nodefaultlibs = 1; - else if (strcmp("-nostdlib", opts.args->base[i]) == 0) + else if (strcmp("-nostdlib", opts.args.str[i]) == 0) opts.nostdlib = 1; - else if (strcmp("-nostartfiles", opts.args->base[i]) == 0) + else if (strcmp("-nostartfiles", opts.args.str[i]) == 0) opts.nostartfiles = 1; break; case 'o': @@ -1958,25 +1940,25 @@ int main(int argc, char **argv) raw_compiler_arg = 0; break; case 'p': - if (strcmp("-pthread", opts.args->base[i]) == 0) + if (strcmp("-pthread", opts.args.str[i]) == 0) { raw_compiler_arg = 1; raw_linker_arg = 1; } break; case 's': - if (strcmp("-static", opts.args->base[i]) == 0) + if (strcmp("-static", opts.args.str[i]) == 0) linking = -1; - else if(strcmp("-save-temps", opts.args->base[i]) == 0) + else if(strcmp("-save-temps", opts.args.str[i]) == 0) keep_generated = 1; - else if (strncmp("-specs=", opts.args->base[i], 7) == 0) + else if (strncmp("-specs=", opts.args.str[i], 7) == 0) raw_linker_arg = 1; - else if(strcmp("-shared", opts.args->base[i]) == 0) + else if(strcmp("-shared", opts.args.str[i]) == 0) { opts.shared = 1; raw_compiler_arg = raw_linker_arg = 0; } - else if (strcmp("-s", opts.args->base[i]) == 0 && opts.target_platform == PLATFORM_APPLE) + else if (strcmp("-s", opts.args.str[i]) == 0 && opts.target_platform == PLATFORM_APPLE) { /* On Mac, change -s into -Wl,-x. ld's -s switch * is deprecated, and it doesn't work on Tiger with @@ -1994,96 +1976,94 @@ int main(int argc, char **argv) } break; case 'v': - if (opts.args->base[i][2] == 0) verbose++; + if (opts.args.str[i][2] == 0) verbose++; break; case 'W': - if (strncmp("-Wl,", opts.args->base[i], 4) == 0) + if (strncmp("-Wl,", opts.args.str[i], 4) == 0) { unsigned int j; - strarray* Wl = strarray_fromstring(opts.args->base[i] + 4, ","); - for (j = 0; j < Wl->size; j++) + struct strarray Wl = strarray_fromstring(opts.args.str[i] + 4, ","); + for (j = 0; j < Wl.count; j++) { - if (!strcmp(Wl->base[j], "--image-base") && j < Wl->size - 1) + if (!strcmp(Wl.str[j], "--image-base") && j < Wl.count - 1) { - opts.image_base = strdup( Wl->base[++j] ); + opts.image_base = strdup( Wl.str[++j] ); continue; } - if (!strcmp(Wl->base[j], "--section-alignment") && j < Wl->size - 1) + if (!strcmp(Wl.str[j], "--section-alignment") && j < Wl.count - 1) { - opts.section_align = strdup( Wl->base[++j] ); + opts.section_align = strdup( Wl.str[++j] ); continue; } - if (!strcmp(Wl->base[j], "--file-alignment") && j < Wl->size - 1) + if (!strcmp(Wl.str[j], "--file-alignment") && j < Wl.count - 1) { - opts.file_align = strdup( Wl->base[++j] ); + opts.file_align = strdup( Wl.str[++j] ); continue; } - if (!strcmp(Wl->base[j], "--large-address-aware")) + if (!strcmp(Wl.str[j], "--large-address-aware")) { opts.large_address_aware = 1; continue; } - if (!strcmp(Wl->base[j], "--wine-builtin")) + if (!strcmp(Wl.str[j], "--wine-builtin")) { opts.wine_builtin = 1; continue; } - if (!strcmp(Wl->base[j], "--subsystem") && j < Wl->size - 1) + if (!strcmp(Wl.str[j], "--subsystem") && j < Wl.count - 1) { - opts.subsystem = strdup( Wl->base[++j] ); + opts.subsystem = strdup( Wl.str[++j] ); continue; } - if (!strcmp(Wl->base[j], "--entry") && j < Wl->size - 1) + if (!strcmp(Wl.str[j], "--entry") && j < Wl.count - 1) { - opts.entry_point = strdup( Wl->base[++j] ); + opts.entry_point = strdup( Wl.str[++j] ); continue; } - if (!strcmp(Wl->base[j], "-delayload") && j < Wl->size - 1) + if (!strcmp(Wl.str[j], "-delayload") && j < Wl.count - 1) { - strarray_add( opts.delayimports, Wl->base[++j] ); + strarray_add( &opts.delayimports, Wl.str[++j] ); continue; } - if (!strcmp(Wl->base[j], "--debug-file") && j < Wl->size - 1) + if (!strcmp(Wl.str[j], "--debug-file") && j < Wl.count - 1) { - opts.debug_file = strdup( Wl->base[++j] ); + opts.debug_file = strdup( Wl.str[++j] ); continue; } - if (!strcmp(Wl->base[j], "--whole-archive") || - !strcmp(Wl->base[j], "--no-whole-archive") || - !strcmp(Wl->base[j], "--start-group") || - !strcmp(Wl->base[j], "--end-group")) + if (!strcmp(Wl.str[j], "--whole-archive") || + !strcmp(Wl.str[j], "--no-whole-archive") || + !strcmp(Wl.str[j], "--start-group") || + !strcmp(Wl.str[j], "--end-group")) { - strarray_add( opts.files, strmake( "-Wl,%s", Wl->base[j] )); + strarray_add( &opts.files, strmake( "-Wl,%s", Wl.str[j] )); continue; } - if (!strcmp(Wl->base[j], "--out-implib")) + if (!strcmp(Wl.str[j], "--out-implib")) { - opts.out_implib = strdup( Wl->base[++j] ); + opts.out_implib = strdup( Wl.str[++j] ); continue; } - if (!strcmp(Wl->base[j], "-static")) linking = -1; - strarray_add(opts.linker_args, strmake("-Wl,%s",Wl->base[j])); + if (!strcmp(Wl.str[j], "-static")) linking = -1; + strarray_add(&opts.linker_args, strmake("-Wl,%s",Wl.str[j])); } - strarray_free(Wl); raw_compiler_arg = raw_linker_arg = 0; } - else if (strncmp("-Wb,", opts.args->base[i], 4) == 0) + else if (strncmp("-Wb,", opts.args.str[i], 4) == 0) { - strarray* Wb = strarray_fromstring(opts.args->base[i] + 4, ","); - strarray_addall(opts.winebuild_args, Wb); - strarray_free(Wb); + strarray_addall( &opts.winebuild_args, + strarray_fromstring( opts.args.str[i] + 4, ",") ); /* don't pass it to the compiler, it generates errors */ raw_compiler_arg = raw_linker_arg = 0; } break; case 'x': lang = strmake("-x%s", option_arg); - strarray_add(opts.files, lang); + strarray_add(&opts.files, lang); /* we'll pass these flags ourselves, explicitly */ raw_compiler_arg = raw_linker_arg = 0; break; case '-': - if (strcmp("-static", opts.args->base[i]+1) == 0) + if (strcmp("-static", opts.args.str[i]+1) == 0) linking = -1; else if (is_option( &opts, i, "--sysroot", &option_arg )) { @@ -2114,23 +2094,23 @@ int main(int argc, char **argv) } /* put the arg into the appropriate bucket */ - if (raw_linker_arg) + if (raw_linker_arg) { - strarray_add( opts.linker_args, opts.args->base[i] ); - if (next_is_arg && (i + 1 < opts.args->size)) - strarray_add( opts.linker_args, opts.args->base[i + 1] ); + strarray_add( &opts.linker_args, opts.args.str[i] ); + if (next_is_arg && (i + 1 < opts.args.count)) + strarray_add( &opts.linker_args, opts.args.str[i + 1] ); } if (raw_compiler_arg) { - strarray_add( opts.compiler_args, opts.args->base[i] ); - if (next_is_arg && (i + 1 < opts.args->size)) - strarray_add( opts.compiler_args, opts.args->base[i + 1] ); + strarray_add( &opts.compiler_args, opts.args.str[i] ); + if (next_is_arg && (i + 1 < opts.args.count)) + strarray_add( &opts.compiler_args, opts.args.str[i + 1] ); } if (raw_winebuild_arg) { - strarray_add( opts.winebuild_args, opts.args->base[i] ); - if (next_is_arg && (i + 1 < opts.args->size)) - strarray_add( opts.winebuild_args, opts.args->base[i + 1] ); + strarray_add( &opts.winebuild_args, opts.args.str[i] ); + if (next_is_arg && (i + 1 < opts.args.count)) + strarray_add( &opts.winebuild_args, opts.args.str[i + 1] ); } /* skip the next token if it's an argument */ @@ -2138,8 +2118,8 @@ int main(int argc, char **argv) } else { - strarray_add( opts.files, opts.args->base[i] ); - } + strarray_add( &opts.files, opts.args.str[i] ); + } } if (opts.processor == proc_cpp) linking = 0; @@ -2147,7 +2127,7 @@ int main(int argc, char **argv) if (!opts.wine_objdir && is_pe_target( &opts )) opts.use_msvcrt = 1; - if (opts.files->size == 0) forward(&opts); + if (opts.files.count == 0) forward(&opts); else if (linking) build(&opts); else compile(&opts, lang);