winehq.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2025
February
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
January
2003
December
November
October
September
August
July
June
May
April
March
February
January
2002
December
November
October
September
August
July
June
May
April
March
February
January
2001
December
November
October
September
August
July
June
May
April
March
February
List overview
wine-commits
October 2021
----- 2025 -----
February 2025
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
January 2004
----- 2003 -----
December 2003
November 2003
October 2003
September 2003
August 2003
July 2003
June 2003
May 2003
April 2003
March 2003
February 2003
January 2003
----- 2002 -----
December 2002
November 2002
October 2002
September 2002
August 2002
July 2002
June 2002
May 2002
April 2002
March 2002
February 2002
January 2002
----- 2001 -----
December 2001
November 2001
October 2001
September 2001
August 2001
July 2001
June 2001
May 2001
April 2001
March 2001
February 2001
wine-commits@winehq.org
2 participants
1165 discussions
Start a n
N
ew thread
Alexandre Julliard : libport: Remove the getopt_long() implementation.
by Alexandre Julliard
05 Oct '21
05 Oct '21
Module: wine Branch: master Commit: a01532200d7e04ab087380ec73125f8183ae9840 URL:
https://source.winehq.org/git/wine.git/?a=commit;h=a01532200d7e04ab087380ec…
Author: Alexandre Julliard <julliard(a)winehq.org> Date: Tue Oct 5 11:54:00 2021 +0200 libport: Remove the getopt_long() implementation. Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- configure | 16 - configure.ac | 8 - include/config.h.in | 9 - include/wine/port.h | 25 -- libs/port/Makefile.in | 1 - libs/port/getopt.c | 1140 ------------------------------------------------- 6 files changed, 1199 deletions(-) Diff:
https://source.winehq.org/git/wine.git/?a=commitdiff;h=a01532200d7e04ab0873…
1
0
0
0
Alexandre Julliard : server: Avoid mkstemps().
by Alexandre Julliard
05 Oct '21
05 Oct '21
Module: wine Branch: master Commit: 93609869c89a589588fb5bb176a45ded3a1a05c9 URL:
https://source.winehq.org/git/wine.git/?a=commit;h=93609869c89a589588fb5bb1…
Author: Alexandre Julliard <julliard(a)winehq.org> Date: Tue Oct 5 11:51:42 2021 +0200 server: Avoid mkstemps(). Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- server/mapping.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/server/mapping.c b/server/mapping.c index eb500ea67f4..8a53c2d89d3 100644 --- a/server/mapping.c +++ b/server/mapping.c @@ -263,14 +263,29 @@ int grow_file( int unix_fd, file_pos_t new_size ) return 0; } +/* simplified version of mkstemps() */ +static int make_temp_file( char name[16] ) +{ + static unsigned int value; + int i, fd = -1; + + value += (current_time >> 16) + current_time; + for (i = 0; i < 0x8000 && fd < 0; i++, value += 7777) + { + sprintf( name, "tmpmap-%08x", value ); + fd = open( name, O_RDWR | O_CREAT | O_EXCL, 0600 ); + } + return fd; +} + /* check if the current directory allows exec mappings */ static int check_current_dir_for_exec(void) { int fd; - char tmpfn[] = "anonmap.XXXXXX"; + char tmpfn[16]; void *ret = MAP_FAILED; - fd = mkstemps( tmpfn, 0 ); + fd = make_temp_file( tmpfn ); if (fd == -1) return 0; if (grow_file( fd, 1 )) { @@ -286,7 +301,7 @@ static int check_current_dir_for_exec(void) static int create_temp_file( file_pos_t size ) { static int temp_dir_fd = -1; - char tmpfn[] = "anonmap.XXXXXX"; + char tmpfn[16]; int fd; if (temp_dir_fd == -1) @@ -304,7 +319,7 @@ static int create_temp_file( file_pos_t size ) } else if (temp_dir_fd != server_dir_fd) fchdir( temp_dir_fd ); - fd = mkstemps( tmpfn, 0 ); + fd = make_temp_file( tmpfn ); if (fd != -1) { if (!grow_file( fd, size ))
1
0
0
0
Alexandre Julliard : server: Avoid using getopt_long().
by Alexandre Julliard
05 Oct '21
05 Oct '21
Module: wine Branch: master Commit: 6a7c4947a0c6f76938ddcffe4385c4b662766ce2 URL:
https://source.winehq.org/git/wine.git/?a=commit;h=6a7c4947a0c6f76938ddcffe…
Author: Alexandre Julliard <julliard(a)winehq.org> Date: Tue Oct 5 11:53:02 2021 +0200 server: Avoid using getopt_long(). Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- server/main.c | 192 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 140 insertions(+), 52 deletions(-) diff --git a/server/main.c b/server/main.c index d7aed0da199..4021d55d52c 100644 --- a/server/main.c +++ b/server/main.c @@ -28,9 +28,6 @@ #include <stdlib.h> #include <sys/time.h> #include <unistd.h> -#ifdef HAVE_GETOPT_H -# include <getopt.h> -#endif #include "object.h" #include "file.h" @@ -60,64 +57,154 @@ static void usage( FILE *fh ) fprintf(fh, "\n"); } -static void parse_args( int argc, char *argv[] ) +static void option_callback( int optc, char *optarg ) { - int ret, optc; + int ret; - static struct option long_options[] = + switch (optc) { - {"debug", 2, NULL, 'd'}, - {"foreground", 0, NULL, 'f'}, - {"help", 0, NULL, 'h'}, - {"kill", 2, NULL, 'k'}, - {"persistent", 2, NULL, 'p'}, - {"version", 0, NULL, 'v'}, - {"wait", 0, NULL, 'w'}, - { NULL, 0, NULL, 0} - }; + case 'd': + if (optarg && isdigit(*optarg)) + debug_level = atoi( optarg ); + else + debug_level++; + break; + case 'f': + foreground = 1; + break; + case 'h': + usage(stdout); + exit(0); + break; + case 'k': + if (optarg && isdigit(*optarg)) + ret = kill_lock_owner( atoi( optarg ) ); + else + ret = kill_lock_owner(-1); + exit( !ret ); + case 'p': + if (optarg && isdigit(*optarg)) + master_socket_timeout = (timeout_t)atoi( optarg ) * -TICKS_PER_SEC; + else + master_socket_timeout = TIMEOUT_INFINITE; + break; + case 'v': + fprintf( stderr, "%s\n", PACKAGE_STRING ); + exit(0); + case 'w': + wait_for_lock(); + exit(0); + } +} - server_argv0 = argv[0]; +/* command-line option parsing */ +/* partly based on the GLibc getopt() implementation */ + +static struct long_option +{ + const char *name; + int has_arg; + int val; +} long_options[] = +{ + {"debug", 2, 'd'}, + {"foreground", 0, 'f'}, + {"help", 0, 'h'}, + {"kill", 2, 'k'}, + {"persistent", 2, 'p'}, + {"version", 0, 'v'}, + {"wait", 0, 'w'}, + { NULL } +}; - while ((optc = getopt_long( argc, argv, "d::fhk::p::vw", long_options, NULL )) != -1) +static void parse_options( int argc, char **argv, const char *short_opts, + const struct long_option *long_opts, void (*callback)( int, char* ) ) +{ + const char *flag; + char *start, *end; + int i; + + for (i = 1; i < argc; i++) { - switch(optc) + if (argv[i][0] != '-' || !argv[i][1]) /* not an option */ + continue; + if (!strcmp( argv[i], "--" )) + break; + start = argv[i] + 1 + (argv[i][1] == '-'); + + if (argv[i][1] == '-') { - case 'd': - if (optarg && isdigit(*optarg)) - debug_level = atoi( optarg ); - else - debug_level++; - break; - case 'f': - foreground = 1; - break; - case 'h': - usage(stdout); - exit(0); - break; - case 'k': - if (optarg && isdigit(*optarg)) - ret = kill_lock_owner( atoi( optarg ) ); - else - ret = kill_lock_owner(-1); - exit( !ret ); - case 'p': - if (optarg && isdigit(*optarg)) - master_socket_timeout = (timeout_t)atoi( optarg ) * -TICKS_PER_SEC; - else - master_socket_timeout = TIMEOUT_INFINITE; + /* handle long option */ + const struct long_option *opt, *found = NULL; + int count = 0; + + if (!(end = strchr( start, '=' ))) end = start + strlen(start); + for (opt = long_opts; opt && opt->name; opt++) + { + if (strncmp( opt->name, start, end - start )) continue; + if (!opt->name[end - start]) /* exact match */ + { + found = opt; + count = 1; + break; + } + if (!found) + { + found = opt; + count++; + } + else if (found->has_arg != opt->has_arg || found->val != opt->val) + { + count++; + } + } + + if (count > 1) goto error; + + if (found) + { + if (*end) + { + if (!found->has_arg) goto error; + end++; /* skip '=' */ + } + else if (found->has_arg == 1) + { + if (i == argc - 1) goto error; + end = argv[++i]; + } + else end = NULL; + + callback( found->val, end ); + continue; + } + goto error; + } + + /* handle short option */ + for ( ; *start; start++) + { + if (!(flag = strchr( short_opts, *start ))) goto error; + if (flag[1] == ':') + { + end = start + 1; + if (!*end) end = NULL; + if (flag[2] != ':' && !end) + { + if (i == argc - 1) goto error; + end = argv[++i]; + } + callback( *start, end ); break; - case 'v': - fprintf( stderr, "%s\n", PACKAGE_STRING ); - exit(0); - case 'w': - wait_for_lock(); - exit(0); - default: - usage(stderr); - exit(1); + } + callback( *start, NULL ); } } + return; + +error: + usage( stderr ); + exit(1); } static void sigterm_handler( int signum ) @@ -128,7 +215,8 @@ static void sigterm_handler( int signum ) int main( int argc, char *argv[] ) { setvbuf( stderr, NULL, _IOLBF, 0 ); - parse_args( argc, argv ); + server_argv0 = argv[0]; + parse_options( argc, argv, "d::fhk::p::vw", long_options, option_callback ); /* setup temporary handlers before the real signal initialization is done */ signal( SIGPIPE, SIG_IGN );
1
0
0
0
Alexandre Julliard : make_xftmpl: Avoid using getopt().
by Alexandre Julliard
05 Oct '21
05 Oct '21
Module: wine Branch: master Commit: 5f921c7f1bbe8ebab5193e42cca06eb1536a91be URL:
https://source.winehq.org/git/wine.git/?a=commit;h=5f921c7f1bbe8ebab5193e42…
Author: Alexandre Julliard <julliard(a)winehq.org> Date: Tue Oct 5 11:52:57 2021 +0200 make_xftmpl: Avoid using getopt(). Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- tools/make_xftmpl.c | 58 +++++++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/tools/make_xftmpl.c b/tools/make_xftmpl.c index 45204b62643..686beeb449c 100644 --- a/tools/make_xftmpl.c +++ b/tools/make_xftmpl.c @@ -25,9 +25,6 @@ #include <stdarg.h> #include <stdio.h> #include <stdlib.h> -#ifdef HAVE_GETOPT_H -# include <getopt.h> -#endif #ifdef HAVE_UNISTD_H # include <unistd.h> #endif @@ -91,8 +88,6 @@ static const struct keyword reserved_words[] = { {"WORD", TOKEN_WORD} }; -extern int getopt(int argc, char *const *argv, const char *optstring); - static BOOL option_header; static char *option_inc_var_name = NULL; static char *option_inc_size_name = NULL; @@ -419,50 +414,47 @@ static void usage(void) program_name); } -static char **parse_options(int argc, char **argv) +static void option_callback( int optc, char *optarg ) { - int optc; - - while ((optc = getopt(argc, argv, "hHi:o:s:")) != -1) + switch (optc) { - switch (optc) - { - case 'h': - usage(); - exit(0); - case 'H': - option_header = TRUE; - break; - case 'i': - option_header = TRUE; - option_inc_var_name = xstrdup(optarg); - break; - case 'o': - option_outfile_name = xstrdup(optarg); - break; - case 's': - option_inc_size_name = xstrdup(optarg); - break; - } + case 'h': + usage(); + exit(0); + case 'H': + option_header = TRUE; + break; + case 'i': + option_header = TRUE; + option_inc_var_name = xstrdup(optarg); + break; + case 'o': + option_outfile_name = xstrdup(optarg); + break; + case 's': + option_inc_size_name = xstrdup(optarg); + break; + case '?': + fprintf( stderr, "%s: %s\n", program_name, optarg ); + exit(1); } - return &argv[optind]; } int main(int argc, char **argv) { char header[16]; - char **args; + struct strarray args; char *header_name = NULL; program_name = argv[0]; - args = parse_options(argc, argv); - infile_name = *args++; - if (!infile_name || *args) + args = parse_options(argc, argv, "hHi:o:s:", NULL, 0, option_callback ); + if (!args.count) { usage(); return 1; } + infile_name = args.str[0]; infile = stdin; outfile = NULL;
1
0
0
0
Alexandre Julliard : sfnt2fon: Avoid using getopt_long().
by Alexandre Julliard
05 Oct '21
05 Oct '21
Module: wine Branch: master Commit: e0ef12241be91b25aefd66e9c6979dca404357c3 URL:
https://source.winehq.org/git/wine.git/?a=commit;h=e0ef12241be91b25aefd66e9…
Author: Alexandre Julliard <julliard(a)winehq.org> Date: Tue Oct 5 11:52:53 2021 +0200 sfnt2fon: Avoid using getopt_long(). Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- tools/sfnt2fon/sfnt2fon.c | 85 ++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 46 deletions(-) diff --git a/tools/sfnt2fon/sfnt2fon.c b/tools/sfnt2fon/sfnt2fon.c index fe8f33103c7..303293c18e5 100644 --- a/tools/sfnt2fon/sfnt2fon.c +++ b/tools/sfnt2fon/sfnt2fon.c @@ -27,9 +27,6 @@ #include <signal.h> #include <stdio.h> #include <stdlib.h> -#ifdef HAVE_GETOPT_H -# include <getopt.h> -#endif #ifdef HAVE_FREETYPE @@ -438,9 +435,11 @@ static const char *output_name; static FT_Library ft_library; -static void usage(char **argv) +static const char *argv0; + +static void usage(void) { - fprintf(stderr, "%s [options] input.ttf ppem,enc,avg_width ...\n", argv[0]); + fprintf(stderr, "%s [options] input.ttf ppem,enc,avg_width ...\n", argv0); fprintf(stderr, "Options:\n"); fprintf(stderr, " -h Display help\n" ); fprintf(stderr, " -d char Set the font default char\n" ); @@ -825,41 +824,36 @@ static void write_fontinfo( const struct fontinfo *info, FILE *fp ) fwrite( info->data, info->hdr.dfSize - info->hdr.fi.dfBitsOffset, 1, fp ); } -/* parse options from the argv array and remove all the recognized ones */ -static char **parse_options( int argc, char **argv ) +static void option_callback( int optc, char *optarg ) { - int optc; - - while ((optc = getopt_long( argc, argv, "d:ho:qr:s", NULL, NULL )) != -1) + switch(optc) { - switch(optc) - { - case 'd': - option_defchar = atoi( optarg ); - break; - case 'o': - option_output = xstrdup( optarg ); - break; - case 'q': - option_quiet = 1; - break; - case 'r': - option_dpi = atoi( optarg ); - break; - case 's': - option_fnt_mode = 1; - break; - case 'h': - usage(argv); - exit(0); - case '?': - usage(argv); - exit(1); - } + case 'd': + option_defchar = atoi( optarg ); + break; + case 'o': + option_output = xstrdup( optarg ); + break; + case 'q': + option_quiet = 1; + break; + case 'r': + option_dpi = atoi( optarg ); + break; + case 's': + option_fnt_mode = 1; + break; + case 'h': + usage(); + exit(0); + case '?': + fprintf( stderr, "%s: %s\n\n", argv0, optarg ); + usage(); + exit(1); } - return &argv[optind]; } + int main(int argc, char **argv) { int i, j; @@ -875,18 +869,19 @@ int main(int argc, char **argv) NE_TYPEINFO rc_type; NE_NAMEINFO rc_name; struct fontinfo **info; - char *input_file; - char **args; + const char *input_file; + struct strarray args; short tmp16; - args = parse_options( argc, argv ); + argv0 = argv[0]; + args = parse_options( argc, argv, "d:ho:qr:s", NULL, 0, option_callback ); - input_file = *args++; - if (!input_file || !*args) + if (!args.count) { - usage(argv); + usage(); exit(1); } + input_file = args.str[0]; if(FT_Init_FreeType(&ft_library)) error("ft init failure\n"); @@ -894,9 +889,7 @@ int main(int argc, char **argv) FT_Version.major=FT_Version.minor=FT_Version.patch=-1; FT_Library_Version(ft_library,&FT_Version.major,&FT_Version.minor,&FT_Version.patch); - num_files = 0; - while (args[num_files]) num_files++; - + num_files = args.count - 1; if (option_fnt_mode && num_files > 1) error( "can only specify one font in .fnt mode\n" ); @@ -906,9 +899,9 @@ int main(int argc, char **argv) int ppem, enc, avg_width; const char *name; - if (sscanf( args[i], "%d,%d,%d", &ppem, &enc, &avg_width ) != 3) + if (sscanf( args.str[i + 1], "%d,%d,%d", &ppem, &enc, &avg_width ) != 3) { - usage(argv); + usage(); exit(1); } if (!(info[i] = fill_fontinfo( input_file, ppem, enc, option_dpi, option_defchar, avg_width )))
1
0
0
0
Alexandre Julliard : winebuild: Avoid using getopt_long().
by Alexandre Julliard
05 Oct '21
05 Oct '21
Module: wine Branch: master Commit: 3eb1855c7e13ef0def19db4c26059913709f9845 URL:
https://source.winehq.org/git/wine.git/?a=commit;h=3eb1855c7e13ef0def19db4c…
Author: Alexandre Julliard <julliard(a)winehq.org> Date: Tue Oct 5 11:52:49 2021 +0200 winebuild: Avoid using getopt_long(). Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- tools/winebuild/main.c | 470 ++++++++++++++++++++++++------------------------- 1 file changed, 231 insertions(+), 239 deletions(-) Diff:
https://source.winehq.org/git/wine.git/?a=commitdiff;h=3eb1855c7e13ef0def19…
1
0
0
0
Alexandre Julliard : wrc: Avoid using getopt_long().
by Alexandre Julliard
05 Oct '21
05 Oct '21
Module: wine Branch: master Commit: 3b0540edd0e0cbe4534e2b4b44aecf53144bd8ab URL:
https://source.winehq.org/git/wine.git/?a=commit;h=3b0540edd0e0cbe4534e2b4b…
Author: Alexandre Julliard <julliard(a)winehq.org> Date: Tue Oct 5 11:52:26 2021 +0200 wrc: Avoid using getopt_long(). Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- tools/wrc/wrc.c | 345 +++++++++++++++++++++++++++----------------------------- tools/wrc/wrc.h | 3 +- 2 files changed, 167 insertions(+), 181 deletions(-) Diff:
https://source.winehq.org/git/wine.git/?a=commitdiff;h=3b0540edd0e0cbe4534e…
1
0
0
0
Alexandre Julliard : wmc: Avoid using getopt_long().
by Alexandre Julliard
05 Oct '21
05 Oct '21
Module: wine Branch: master Commit: 7420715b99c1414f8d252c4e20dc76dfe08c72ca URL:
https://source.winehq.org/git/wine.git/?a=commit;h=7420715b99c1414f8d252c4e…
Author: Alexandre Julliard <julliard(a)winehq.org> Date: Tue Oct 5 11:52:21 2021 +0200 wmc: Avoid using getopt_long(). Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- tools/wmc/wmc.c | 200 ++++++++++++++++++++++++++------------------------------ tools/wmc/wmc.h | 2 +- 2 files changed, 93 insertions(+), 109 deletions(-) diff --git a/tools/wmc/wmc.c b/tools/wmc/wmc.c index d76468c8bb5..618a6ab2472 100644 --- a/tools/wmc/wmc.c +++ b/tools/wmc/wmc.c @@ -25,9 +25,6 @@ #include <stdlib.h> #include <string.h> #include <signal.h> -#ifdef HAVE_GETOPT_H -# include <getopt.h> -#endif #include "wmc.h" #include "utils.h" @@ -107,7 +104,7 @@ static int dodebug = 0; static char *po_dir; char *output_name = NULL; /* The name given by the -o option */ -char *input_name = NULL; /* The name given on the command-line */ +const char *input_name = NULL; /* The name given on the command-line */ char *header_name = NULL; /* The name given by the -H option */ const char *nlsdirs[3] = { NULL, NLSDIR, NULL }; @@ -136,15 +133,16 @@ enum long_options_values }; static const char short_options[] = "B:cdDhH:io:O:P:uUvVW"; -static const struct option long_options[] = +static const struct long_option long_options[] = { - { "help", 0, NULL, 'h' }, - { "nls-dir", 1, NULL, LONG_OPT_NLS_DIR }, - { "output", 1, NULL, 'o' }, - { "output-format", 1, NULL, 'O' }, - { "pedantic", 0, NULL, 'W' }, - { "po-dir", 1, NULL, 'P' }, - { "version", 0, NULL, 'v' } + { "help", 0, 'h' }, + { "nls-dir", 1, LONG_OPT_NLS_DIR }, + { "output", 1, 'o' }, + { "output-format", 1, 'O' }, + { "pedantic", 0, 'W' }, + { "po-dir", 1, 'P' }, + { "version", 0, 'v' }, + { NULL } }; static void segvhandler(int sig); @@ -179,14 +177,91 @@ static void init_argv0_dir( const char *argv0 ) #endif } +static void option_callback( int optc, char *optarg ) +{ + switch(optc) + { + case 'B': + switch(optarg[0]) + { + case 'n': + case 'N': + byteorder = WMC_BO_NATIVE; + break; + case 'l': + case 'L': + byteorder = WMC_BO_LITTLE; + break; + case 'b': + case 'B': + byteorder = WMC_BO_BIG; + break; + default: + error("Byteordering must be n[ative], l[ittle] or b[ig]\n"); + } + break; + case 'c': + custombit = 1; + break; + case 'd': + decimal = 1; + break; + case 'D': + dodebug = 1; + break; + case 'h': + printf("%s", usage); + exit(0); + /* No return */ + case 'H': + header_name = xstrdup(optarg); + break; + case 'i': + rcinline = 1; + break; + case 'o': + output_name = xstrdup(optarg); + break; + case 'O': + if (!strcmp( optarg, "rc" )) output_format = FORMAT_RC; + else if (!strcmp( optarg, "res" )) output_format = FORMAT_RES; + else if (!strcmp( optarg, "pot" )) output_format = FORMAT_POT; + else error("Output format must be rc or res\n" ); + break; + case 'P': + po_dir = xstrdup( optarg ); + break; + case 'u': + unicodein = 1; + break; + case 'U': /* ignored for backwards compatibility */ + break; + case 'v': + show_languages(); + exit(0); + /* No return */ + case 'V': + printf(version_string); + exit(0); + /* No return */ + case 'W': + pedantic = 1; + break; + case LONG_OPT_NLS_DIR: + nlsdirs[0] = xstrdup( optarg ); + break; + case '?': + fprintf(stderr, "wmc: %s\n\n%s", optarg, usage); + exit(1); + } +} + int main(int argc,char *argv[]) { - int optc; - int opti = 0; - int lose = 0; int ret; int i; int cmdlen; + struct strarray files; atexit( cleanup_files ); signal(SIGSEGV, segvhandler); @@ -211,95 +286,7 @@ int main(int argc,char *argv[]) strcat(cmdline, " "); } - while((optc = getopt_long(argc, argv, short_options, long_options, &opti)) != EOF) - { - switch(optc) - { - case 'B': - switch(optarg[0]) - { - case 'n': - case 'N': - byteorder = WMC_BO_NATIVE; - break; - case 'l': - case 'L': - byteorder = WMC_BO_LITTLE; - break; - case 'b': - case 'B': - byteorder = WMC_BO_BIG; - break; - default: - fprintf(stderr, "Byteordering must be n[ative], l[ittle] or b[ig]\n"); - lose++; - } - break; - case 'c': - custombit = 1; - break; - case 'd': - decimal = 1; - break; - case 'D': - dodebug = 1; - break; - case 'h': - printf("%s", usage); - exit(0); - /* No return */ - case 'H': - header_name = xstrdup(optarg); - break; - case 'i': - rcinline = 1; - break; - case 'o': - output_name = xstrdup(optarg); - break; - case 'O': - if (!strcmp( optarg, "rc" )) output_format = FORMAT_RC; - else if (!strcmp( optarg, "res" )) output_format = FORMAT_RES; - else if (!strcmp( optarg, "pot" )) output_format = FORMAT_POT; - else - { - fprintf(stderr, "Output format must be rc or res\n" ); - lose++; - } - break; - case 'P': - po_dir = xstrdup( optarg ); - break; - case 'u': - unicodein = 1; - break; - case 'U': /* ignored for backwards compatibility */ - break; - case 'v': - show_languages(); - exit(0); - /* No return */ - case 'V': - printf(version_string); - exit(0); - /* No return */ - case 'W': - pedantic = 1; - break; - case LONG_OPT_NLS_DIR: - nlsdirs[0] = xstrdup( optarg ); - break; - default: - lose++; - break; - } - } - - if(lose) - { - fprintf(stderr, "%s", usage); - return 1; - } + files = parse_options( argc, argv, short_options, long_options, 0, option_callback ); mcy_debug = dodebug; if(dodebug) @@ -309,10 +296,7 @@ int main(int argc,char *argv[]) } /* Check for input file on command-line */ - if(optind < argc) - { - input_name = argv[optind]; - } + if (files.count) input_name = files.str[0]; /* Guess output format */ if (output_format == FORMAT_UNKNOWN) diff --git a/tools/wmc/wmc.h b/tools/wmc/wmc.h index ae3a1dc1d3a..438a645ebfc 100644 --- a/tools/wmc/wmc.h +++ b/tools/wmc/wmc.h @@ -45,7 +45,7 @@ extern int unicodein; extern int rcinline; extern char *output_name; -extern char *input_name; +extern const char *input_name; extern char *header_name; extern char *cmdline;
1
0
0
0
Alexandre Julliard : widl: Avoid using getopt_long().
by Alexandre Julliard
05 Oct '21
05 Oct '21
Module: wine Branch: master Commit: 4bc52e3324a505e6f12652a526cdbd09c24e7afc URL:
https://source.winehq.org/git/wine.git/?a=commit;h=4bc52e3324a505e6f12652a5…
Author: Alexandre Julliard <julliard(a)winehq.org> Date: Tue Oct 5 11:52:15 2021 +0200 widl: Avoid using getopt_long(). Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- tools/widl/widl.c | 113 +++++++++++++++++++++++++++--------------------------- 1 file changed, 57 insertions(+), 56 deletions(-) diff --git a/tools/widl/widl.c b/tools/widl/widl.c index 72888c35ac7..5c11f6285ea 100644 --- a/tools/widl/widl.c +++ b/tools/widl/widl.c @@ -33,9 +33,6 @@ #include <assert.h> #include <ctype.h> #include <signal.h> -#ifdef HAVE_GETOPT_H -# include <getopt.h> -#endif #include "widl.h" #include "utils.h" @@ -153,6 +150,8 @@ char *temp_name; const char *prefix_client = ""; const char *prefix_server = ""; static const char *includedir; +static char *output_name; +static const char *sysroot = ""; int line_number = 1; @@ -186,29 +185,29 @@ enum { static const char short_options[] = "b:cC:d:D:EhH:I:m:No:O:pP:rsS:tT:uU:VW"; -static const struct option long_options[] = { - { "acf", 1, NULL, ACF_OPTION }, - { "app_config", 0, NULL, APP_CONFIG_OPTION }, - { "dlldata", 1, NULL, DLLDATA_OPTION }, - { "dlldata-only", 0, NULL, DLLDATA_ONLY_OPTION }, - { "help", 0, NULL, PRINT_HELP }, - { "local-stubs", 1, NULL, LOCAL_STUBS_OPTION }, - { "nostdinc", 0, NULL, NOSTDINC_OPTION }, - { "ns_prefix", 0, NULL, RT_NS_PREFIX }, - { "oldnames", 0, NULL, OLDNAMES_OPTION }, - { "output", 0, NULL, 'o' }, - { "prefix-all", 1, NULL, PREFIX_ALL_OPTION }, - { "prefix-client", 1, NULL, PREFIX_CLIENT_OPTION }, - { "prefix-server", 1, NULL, PREFIX_SERVER_OPTION }, - { "robust", 0, NULL, ROBUST_OPTION }, - { "sysroot", 1, NULL, SYSROOT_OPTION }, - { "target", 0, NULL, 'b' }, - { "winrt", 0, NULL, RT_OPTION }, - { "win32", 0, NULL, WIN32_OPTION }, - { "win64", 0, NULL, WIN64_OPTION }, - { "win32-align", 1, NULL, WIN32_ALIGN_OPTION }, - { "win64-align", 1, NULL, WIN64_ALIGN_OPTION }, - { NULL, 0, NULL, 0 } +static const struct long_option long_options[] = { + { "acf", 1, ACF_OPTION }, + { "app_config", 0, APP_CONFIG_OPTION }, + { "dlldata", 1, DLLDATA_OPTION }, + { "dlldata-only", 0, DLLDATA_ONLY_OPTION }, + { "help", 0, PRINT_HELP }, + { "local-stubs", 1, LOCAL_STUBS_OPTION }, + { "nostdinc", 0, NOSTDINC_OPTION }, + { "ns_prefix", 0, RT_NS_PREFIX }, + { "oldnames", 0, OLDNAMES_OPTION }, + { "output", 0, 'o' }, + { "prefix-all", 1, PREFIX_ALL_OPTION }, + { "prefix-client", 1, PREFIX_CLIENT_OPTION }, + { "prefix-server", 1, PREFIX_SERVER_OPTION }, + { "robust", 0, ROBUST_OPTION }, + { "sysroot", 1, SYSROOT_OPTION }, + { "target", 0, 'b' }, + { "winrt", 0, RT_OPTION }, + { "win32", 0, WIN32_OPTION }, + { "win64", 0, WIN64_OPTION }, + { "win32-align", 1, WIN32_ALIGN_OPTION }, + { "win64-align", 1, WIN64_ALIGN_OPTION }, + { NULL } }; static const struct @@ -576,26 +575,10 @@ static void init_argv0_dir( const char *argv0 ) #endif } -int main(int argc,char *argv[]) +static void option_callback( int optc, char *optarg ) { - int i, optc; - int ret = 0; - int opti = 0; - char *output_name = NULL; - const char *sysroot = ""; - - signal( SIGTERM, exit_on_signal ); - signal( SIGINT, exit_on_signal ); -#ifdef SIGHUP - signal( SIGHUP, exit_on_signal ); -#endif - init_argv0_dir( argv[0] ); - init_argv0_target( argv[0] ); - - now = time(NULL); - - while((optc = getopt_long_only(argc, argv, short_options, long_options, &opti)) != EOF) { - switch(optc) { + switch (optc) + { case DLLDATA_OPTION: dlldata_name = xstrdup(optarg); break; @@ -625,7 +608,7 @@ int main(int argc,char *argv[]) break; case PRINT_HELP: fprintf(stderr, "%s", usage); - return 0; + exit(0); case RT_OPTION: winrt_mode = 1; break; @@ -743,15 +726,33 @@ int main(int argc,char *argv[]) break; case 'V': printf("%s", version_string); - return 0; + exit(0); case 'W': pedantic = 1; break; - default: - fprintf(stderr, "%s", usage); - return 1; + case '?': + fprintf(stderr, "widl: %s\n\n%s", optarg, usage); + exit(1); } - } +} + +int main(int argc,char *argv[]) +{ + int i; + int ret = 0; + struct strarray files; + + signal( SIGTERM, exit_on_signal ); + signal( SIGINT, exit_on_signal ); +#ifdef SIGHUP + signal( SIGHUP, exit_on_signal ); +#endif + init_argv0_dir( argv[0] ); + init_argv0_target( argv[0] ); + + now = time(NULL); + + files = parse_options( argc, argv, short_options, long_options, 1, option_callback ); if (stdinc) { @@ -835,21 +836,21 @@ int main(int argc,char *argv[]) if (!dlldata_name && do_dlldata) dlldata_name = xstrdup("dlldata.c"); - if(optind < argc) { + if (files.count) { if (do_dlldata && !do_everything) { struct strarray filenames = empty_strarray; - for ( ; optind < argc; ++optind) - strarray_add(&filenames, replace_extension( get_basename( argv[optind] ), ".idl", "" )); + for (i = 0; i < files.count; i++) + strarray_add(&filenames, replace_extension( get_basename( files.str[i] ), ".idl", "" )); write_dlldata_list(filenames, 0 /* FIXME */ ); return 0; } - else if (optind != argc - 1) { + else if (files.count > 1) { fprintf(stderr, "%s", usage); return 1; } else - input_idl_name = input_name = xstrdup(argv[optind]); + input_idl_name = input_name = xstrdup(files.str[0]); } else { fprintf(stderr, "%s", usage);
1
0
0
0
Alexandre Julliard : tools: Implement a replacement for getopt_long().
by Alexandre Julliard
05 Oct '21
05 Oct '21
Module: wine Branch: master Commit: 9c4cbde78fa6357aec1c235265d92ea2cdbb69e7 URL:
https://source.winehq.org/git/wine.git/?a=commit;h=9c4cbde78fa6357aec1c2352…
Author: Alexandre Julliard <julliard(a)winehq.org> Date: Tue Oct 5 11:51:57 2021 +0200 tools: Implement a replacement for getopt_long(). Signed-off-by: Alexandre Julliard <julliard(a)winehq.org> --- tools/tools.h | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/winedump/main.c | 6 +-- 2 files changed, 113 insertions(+), 3 deletions(-) diff --git a/tools/tools.h b/tools/tools.h index 8b658079952..f013bf7a510 100644 --- a/tools/tools.h +++ b/tools/tools.h @@ -310,4 +310,114 @@ static inline int make_temp_file( const char *prefix, const char *suffix, char * exit(1); } + +/* command-line option parsing */ +/* partly based on the Glibc getopt() implementation */ + +struct long_option +{ + const char *name; + int has_arg; + int val; +}; + +static inline struct strarray parse_options( int argc, char **argv, const char *short_opts, + const struct long_option *long_opts, int long_only, + void (*callback)( int, char* ) ) +{ + struct strarray ret = empty_strarray; + const char *flag; + char *start, *end; + int i; + +#define OPT_ERR(fmt) { callback( '?', strmake( fmt, argv[1] )); continue; } + + for (i = 1; i < argc; i++) + { + if (argv[i][0] != '-' || !argv[i][1]) /* not an option */ + { + strarray_add( &ret, argv[i] ); + continue; + } + if (!strcmp( argv[i], "--" )) + { + /* add remaining args */ + while (++i < argc) strarray_add( &ret, argv[i] ); + break; + } + start = argv[i] + 1 + (argv[i][1] == '-'); + + if (argv[i][1] == '-' || (long_only && (argv[i][2] || !strchr( short_opts, argv[i][1] )))) + { + /* handle long option */ + const struct long_option *opt, *found = NULL; + int count = 0; + + if (!(end = strchr( start, '=' ))) end = start + strlen(start); + for (opt = long_opts; opt && opt->name; opt++) + { + if (strncmp( opt->name, start, end - start )) continue; + if (!opt->name[end - start]) /* exact match */ + { + found = opt; + count = 1; + break; + } + if (!found) + { + found = opt; + count++; + } + else if (long_only || found->has_arg != opt->has_arg || found->val != opt->val) + { + count++; + } + } + + if (count > 1) OPT_ERR( "option '%s' is ambiguous" ); + + if (found) + { + if (*end) + { + if (!found->has_arg) OPT_ERR( "argument not allowed in '%s'" ); + end++; /* skip '=' */ + } + else if (found->has_arg == 1) + { + if (i == argc - 1) OPT_ERR( "option '%s' requires an argument" ); + end = argv[++i]; + } + else end = NULL; + + callback( found->val, end ); + continue; + } + if (argv[i][1] == '-' || !long_only || !strchr( short_opts, argv[i][1] )) + OPT_ERR( "unrecognized option '%s'" ); + } + + /* handle short option */ + for ( ; *start; start++) + { + if (!(flag = strchr( short_opts, *start ))) OPT_ERR( "invalid option '%s'" ); + if (flag[1] == ':') + { + end = start + 1; + if (!*end) end = NULL; + if (flag[2] != ':' && !end) + { + if (i == argc - 1) OPT_ERR( "option '%s' requires an argument" ); + end = argv[++i]; + } + callback( *start, end ); + break; + } + callback( *start, NULL ); + } + } + return ret; +#undef OPT_ERR +} + #endif /* __WINE_TOOLS_H */ diff --git a/tools/winedump/main.c b/tools/winedump/main.c index 818180e6d8c..b60868d0d89 100644 --- a/tools/winedump/main.c +++ b/tools/winedump/main.c @@ -257,11 +257,11 @@ void do_usage (const char *arg) /******************************************************************* - * parse_options + * parse_cmdline * * Parse options from the argv array */ -static void parse_options (char *argv[]) +static void parse_cmdline (char *argv[]) { const struct my_option *opt; char *const *ptr; @@ -388,7 +388,7 @@ int main (int argc, char *argv[]) globals.input_name = NULL; globals.dumpsect = NULL; - parse_options (argv); + parse_cmdline (argv); memset (&symbol, 0, sizeof (parsed_symbol));
1
0
0
0
← Newer
1
...
99
100
101
102
103
104
105
...
117
Older →
Jump to page:
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
Results per page:
10
25
50
100
200