From 9b35fab3495a816a0d8fe48a0d7a22f2217f040d Mon Sep 17 00:00:00 2001 From: peavey Date: Sun, 2 Aug 2009 22:36:45 +0000 Subject: Fix our getops implementation on windows. Have optind available, and make sure it always points to the next entry in the argv list as described by POSIX. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11466 e03df62e-2008-0410-955e-edbf42e46eb7 --- win/inspircd_win32wrapper.cpp | 17 +++++++++-------- win/inspircd_win32wrapper.h | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'win') diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp index 0bff707db..9d75fd2ea 100644 --- a/win/inspircd_win32wrapper.cpp +++ b/win/inspircd_win32wrapper.cpp @@ -236,16 +236,17 @@ int printf_c(const char * format, ...) return c; } -int arg_counter = 1; +int optind = 1; char optarg[514]; int getopt_long_only(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind) { // burlex todo: handle the shortops, at the moment it only works with longopts. - if (___argc == 1 || arg_counter == ___argc) // No arguments (apart from filename) + if (___argc == 1 || optind == ___argc) // No arguments (apart from filename) return -1; - const char * opt = ___argv[arg_counter]; + const char * opt = ___argv[optind]; + optind++; // if we're not an option, return an error. if (strnicmp(opt, "--", 2) != 0) @@ -262,18 +263,18 @@ int getopt_long_only(int ___argc, char *const *___argv, const char *__shortopts, { // woot, found a valid argument =) char * par = 0; - if ((arg_counter + 1) != ___argc) + if ((optind) != ___argc) { // grab the parameter from the next argument (if its not another argument) - if (strnicmp(___argv[arg_counter+1], "--", 2) != 0) + if (strnicmp(___argv[optind], "--", 2) != 0) { - arg_counter++; // Trash this next argument, we won't be needing it. - par = ___argv[arg_counter]; +// optind++; // Trash this next argument, we won't be needing it. + par = ___argv[optind-1]; } } // increment the argument for next time - arg_counter++; +// optind++; // determine action based on type if (__longopts[i].has_arg == required_argument && !par) diff --git a/win/inspircd_win32wrapper.h b/win/inspircd_win32wrapper.h index e0cc77291..4d156eddb 100644 --- a/win/inspircd_win32wrapper.h +++ b/win/inspircd_win32wrapper.h @@ -150,6 +150,7 @@ struct option int *flag; int val; }; +extern int optind; extern char optarg[514]; int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind); -- cgit v1.2.3