diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config.h.in | 31 | ||||
-rw-r--r-- | src/gflags.cc | 22 | ||||
-rw-r--r-- | src/gflags.h | 6 | ||||
-rw-r--r-- | src/gflags_declare.h.in | 116 | ||||
-rw-r--r-- | src/gflags_reporting.cc | 27 | ||||
-rw-r--r-- | src/mutex.h | 14 | ||||
-rw-r--r-- | src/util.h | 22 | ||||
-rw-r--r-- | src/windows_port.cc | 4 | ||||
-rw-r--r-- | src/windows_port.h | 13 |
9 files changed, 137 insertions, 118 deletions
diff --git a/src/config.h.in b/src/config.h.in index 33987f9..ed254fe 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -2,6 +2,8 @@ // Note: This header file is only used internally. It is not part of public interface! +#include "gflags_declare.h" // system checks + // --------------------------------------------------------------------------- // Additional meta-information @@ -27,35 +29,6 @@ #define PACKAGE_BUGREPORT @PACKAGE_BUGREPORT@ // --------------------------------------------------------------------------- -// Available system headers - -// Define to 1 if you have the <fnmatch.h> header file. -#define HAVE_FNMATCH_H @HAVE_FNMATCH_H@ - -// Define to 1 if you have the <inttypes.h> header file. -#define HAVE_INTTYPES_H @HAVE_INTTYPES_H@ - -// Define to 1 if you have the <unistd.h> header file. -#define HAVE_UNISTD_H @HAVE_UNISTD_H@ - -// Define to 1 if you have the <sys/stat.h> header file. -#define HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@ - -// Define to 1 if you have the strtoll function. -#define HAVE_STRTOLL @HAVE_STRTOLL@ - -// Define to 1 if you have the strtoq function. -#define HAVE_STRTOQ @HAVE_STRTOQ@ - -// Define to 1 if you have the <pthread.h> header file. -#define HAVE_PTHREAD @HAVE_PTHREAD@ - -// gcc requires this to get PRId64, etc. -#if HAVE_INTTYPES_H && !defined(__STDC_FORMAT_MACROS) -# define __STDC_FORMAT_MACROS 1 -#endif - -// --------------------------------------------------------------------------- // Path separator #define PATH_SEPARATOR '/' diff --git a/src/gflags.cc b/src/gflags.cc index b273ddc..0e6ea7d 100644 --- a/src/gflags.cc +++ b/src/gflags.cc @@ -93,7 +93,7 @@ #include <assert.h> #include <ctype.h> #include <errno.h> -#if HAVE_FNMATCH_H +#ifdef HAVE_FNMATCH_H # include <fnmatch.h> #endif #include <stdarg.h> // For va_list and related operations @@ -111,20 +111,16 @@ // Special flags, type 1: the 'recursive' flags. They set another flag's val. -DEFINE_string(flagfile, "", - "load flags from file"); -DEFINE_string(fromenv, "", - "set flags from the environment" - " [use 'export FLAGS_flag1=value']"); -DEFINE_string(tryfromenv, "", - "set flags from the environment if present"); +DEFINE_string(flagfile, "", "load flags from file"); +DEFINE_string(fromenv, "", "set flags from the environment" + " [use 'export FLAGS_flag1=value']"); +DEFINE_string(tryfromenv, "", "set flags from the environment if present"); // Special flags, type 2: the 'parsing' flags. They modify how we parse. -DEFINE_string(undefok, "", - "comma-separated list of flag names that it is okay to specify " - "on the command line even if the program does not define a flag " - "with that name. IMPORTANT: flags in this list that have " - "arguments MUST use the flag=value format"); +DEFINE_string(undefok, "", "comma-separated list of flag names that it is okay to specify " + "on the command line even if the program does not define a flag " + "with that name. IMPORTANT: flags in this list that have " + "arguments MUST use the flag=value format"); namespace GFLAGS_NAMESPACE { diff --git a/src/gflags.h b/src/gflags.h index 3a16777..41f53d9 100644 --- a/src/gflags.h +++ b/src/gflags.h @@ -270,8 +270,8 @@ extern std::string SetCommandLineOptionWithMode(const char* name, const char* va // // without worrying about restoring the FLAG values. // } // -// Note: This class is marked with ATTRIBUTE_UNUSED because all the -// work is done in the constructor and destructor, so in the standard +// Note: This class is marked with GFLAGS_ATTRIBUTE_UNUSED because all +// the work is done in the constructor and destructor, so in the standard // usage example above, the compiler would complain that it's an // unused variable. // @@ -291,7 +291,7 @@ class GFLAGS_DLL_DECL FlagSaver { FlagSaver(const FlagSaver&); // no copying! void operator=(const FlagSaver&); } -GFLAGS__ATTRIBUTE__UNUSED; +GFLAGS_ATTRIBUTE_UNUSED; // -------------------------------------------------------------------- // Some deprecated or hopefully-soon-to-be-deprecated functions. diff --git a/src/gflags_declare.h.in b/src/gflags_declare.h.in index 7141e99..2a25f1d 100644 --- a/src/gflags_declare.h.in +++ b/src/gflags_declare.h.in @@ -56,7 +56,7 @@ // --------------------------------------------------------------------------- // Unused attribute declaration for GNU GCC. -#define GFLAGS__ATTRIBUTE__UNUSED @GFLAGS__ATTRIBUTE_UNUSED@ +#define GFLAGS_ATTRIBUTE_UNUSED @GFLAGS_ATTRIBUTE_UNUSED@ // --------------------------------------------------------------------------- // Windows DLL import/export. @@ -97,32 +97,102 @@ #endif // --------------------------------------------------------------------------- -// Types -#include <string> -#if @HAVE_STDINT_H@ -# include <stdint.h> // the normal place uint16_t is defined +// Available system headers + +// Define if you have the <stdint.h> header file. +#cmakedefine GFLAGS_HAVE_STDINT_H + +// Define if you have the <sys/types.h> header file. +#cmakedefine GFLAGS_HAVE_SYS_TYPES_H + +// Define if you have the <inttypes.h> header file. +#cmakedefine GFLAGS_HAVE_INTTYPES_H + +// Define if you have the <sys/stat.h> header file. +#cmakedefine GFLAGS_HAVE_SYS_STAT_H + +// Define if you have the <unistd.h> header file. +#cmakedefine GFLAGS_HAVE_UNISTD_H + +// Define if you have the <fnmatch.h> header file. +#cmakedefine GFLAGS_HAVE_FNMATCH_H + +// Define if you have the strtoll function. +#cmakedefine GFLAGS_HAVE_STRTOLL + +// Define if you have the strtoq function. +#cmakedefine GFLAGS_HAVE_STRTOQ + +// Define if you have the <pthread.h> header file. +#cmakedefine GFLAGS_HAVE_PTHREAD + +// Backwards compatibility in case users defined these macros themselves +// or allow users to use these more general macros if the gflags library +// is build as part of a user project, e.g., included as Git submodule +#if defined(HAVE_STDINT_H) && !defined(GFLAGS_HAVE_STDINT_H) +# define GFLAGS_HAVE_STDINT_H +#endif +#if defined(HAVE_SYS_TYPES_H) && !defined(GFLAGS_HAVE_SYS_TYPES_H) +# define GFLAGS_HAVE_SYS_TYPES_H #endif -#if @HAVE_SYS_TYPES_H@ -# include <sys/types.h> // the normal place u_int16_t is defined +#if defined(HAVE_INTTYPES_H) && !defined(GFLAGS_HAVE_INTTYPES_H) +# define GFLAGS_HAVE_INTTYPES_H #endif -#if @HAVE_INTTYPES_H@ -# include <inttypes.h> // a third place for uint16_t or u_int16_t +#if defined(HAVE_SYS_STAT_H) && !defined(GFLAGS_HAVE_SYS_STAT_H) +# define GFLAGS_HAVE_SYS_STAT_H +#endif +#if defined(HAVE_UNISTD_H) && !defined(GFLAGS_HAVE_UNISTD_H) +# define GFLAGS_HAVE_UNISTD_H +#endif +#if defined(HAVE_FNMATCH_H) && !defined(GFLAGS_HAVE_FNMATCH_H) +# define GFLAGS_HAVE_FNMATCH_H +#endif +#if defined(HAVE_STRTOLL) && !defined(GFLAGS_HAVE_STRTOLL) +# define GFLAGS_HAVE_STRTOLL +#endif +#if defined(HAVE_STRTOLQ) && !defined(GFLAGS_HAVE_STRTOLQ) +# define GFLAGS_HAVE_STRTOLQ +#endif +#if defined(HAVE_PTHREAD) && !defined(GFLAGS_HAVE_PTHREAD) +# define GFLAGS_HAVE_PTHREAD +#endif +#if defined(HAVE_RWLOCK) && !defined(GFLAGS_HAVE_RWLOCK) +# define GFLAGS_HAVE_RWLOCK +#endif + +// gcc requires this to get PRId64, etc. +#if defined(GFLAGS_HAVE_INTTYPES_H) && !defined(__STDC_FORMAT_MACROS) +# define __STDC_FORMAT_MACROS 1 +#endif + +// --------------------------------------------------------------------------- +// Flag types +#include <string> +#if defined(GFLAGS_HAVE_STDINT_H) +# include <stdint.h> // the normal place uint32_t is defined +#elif defined(GFLAGS_HAVE_SYS_TYPES_H) +# include <sys/types.h> // the normal place u_int32_t is defined +#elif defined(GFLAGS_HAVE_INTTYPES_H) +# include <inttypes.h> // a third place for uint32_t or u_int32_t #endif +#cmakedefine GFLAGS_INTTYPES_FORMAT_C99 +#cmakedefine GFLAGS_INTTYPES_FORMAT_BSD +#cmakedefine GFLAGS_INTTYPES_FORMAT_VC7 namespace GFLAGS_NAMESPACE { -#if @HAVE_uint16_t@ // the C99 format -typedef int32_t int32; -typedef uint32_t uint32; -typedef int64_t int64; -typedef uint64_t uint64; -#elif @HAVE_u_int16_t@ // the BSD format -typedef int32_t int32; -typedef u_int32_t uint32; -typedef int64_t int64; -typedef u_int64_t uint64; -#elif @HAVE___int16@ // the windows (vc7) format +#if defined(GFLAGS_INTTYPES_FORMAT_C99) +typedef int32_t int32; +typedef uint32_t uint32; +typedef int64_t int64; +typedef uint64_t uint64; +#elif defined(GFLAGS_INTTYPES_FORMAT_BSD) +typedef int32_t int32; +typedef u_int32_t uint32; +typedef int64_t int64; +typedef u_int64_t uint64; +#elif defined(GFLAGS_INTTYPES_FORMAT_VC7) // Windows typedef __int32 int32; typedef unsigned __int32 uint32; typedef __int64 int64; @@ -154,13 +224,13 @@ typedef std::string clstring; DECLARE_VARIABLE(bool, B, name) #define DECLARE_int32(name) \ - DECLARE_VARIABLE(@ac_google_namespace@::int32, I, name) + DECLARE_VARIABLE(GFLAGS_NAMESPACE::int32, I, name) #define DECLARE_int64(name) \ - DECLARE_VARIABLE(@ac_google_namespace@::int64, I64, name) + DECLARE_VARIABLE(GFLAGS_NAMESPACE::int64, I64, name) #define DECLARE_uint64(name) \ - DECLARE_VARIABLE(@ac_google_namespace@::uint64, U64, name) + DECLARE_VARIABLE(GFLAGS_NAMESPACE::uint64, U64, name) #define DECLARE_double(name) \ DECLARE_VARIABLE(double, D, name) diff --git a/src/gflags_reporting.cc b/src/gflags_reporting.cc index 595af97..a33c553 100644 --- a/src/gflags_reporting.cc +++ b/src/gflags_reporting.cc @@ -48,8 +48,6 @@ // called after all flag-values have been assigned, that is, after // parsing the command-line. -#include "config.h" - #include <stdio.h> #include <string.h> #include <ctype.h> @@ -57,28 +55,21 @@ #include <string> #include <vector> +#include "config.h" #include "gflags.h" #include "gflags_completions.h" #include "util.h" // The 'reporting' flags. They all call gflags_exitfunc(). -DEFINE_bool(help, false, - "show help on all flags [tip: all flags can have two dashes]"); -DEFINE_bool(helpfull, false, - "show help on all flags -- same as -help"); -DEFINE_bool(helpshort, false, - "show help on only the main module for this program"); -DEFINE_string(helpon, "", - "show help on the modules named by this flag value"); -DEFINE_string(helpmatch, "", - "show help on modules whose name contains the specified substr"); -DEFINE_bool(helppackage, false, - "show help on all modules in the main package"); -DEFINE_bool(helpxml, false, - "produce an xml version of help"); -DEFINE_bool(version, false, - "show version and build info and exit"); +DEFINE_bool (help, false, "show help on all flags [tip: all flags can have two dashes]"); +DEFINE_bool (helpfull, false, "show help on all flags -- same as -help"); +DEFINE_bool (helpshort, false, "show help on only the main module for this program"); +DEFINE_string(helpon, "", "show help on the modules named by this flag value"); +DEFINE_string(helpmatch, "", "show help on modules whose name contains the specified substr"); +DEFINE_bool (helppackage, false, "show help on all modules in the main package"); +DEFINE_bool (helpxml, false, "produce an xml version of help"); +DEFINE_bool (version, false, "show version and build info and exit"); namespace GFLAGS_NAMESPACE { diff --git a/src/mutex.h b/src/mutex.h index cfca32f..3b27f84 100644 --- a/src/mutex.h +++ b/src/mutex.h @@ -106,10 +106,10 @@ #ifndef GFLAGS_MUTEX_H_ #define GFLAGS_MUTEX_H_ -#include "config.h" // to figure out pthreads support +#include "gflags_declare.h" // to figure out pthreads support #if defined(NO_THREADS) - typedef int MutexType; // to keep a lock-count + typedef int MutexType; // to keep a lock-count #elif defined(_WIN32) || defined(__CYGWIN32__) || defined(__CYGWIN64__) # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN // We only need minimal includes @@ -127,9 +127,9 @@ # endif # include <windows.h> typedef CRITICAL_SECTION MutexType; -#elif defined(HAVE_PTHREAD) && defined(HAVE_RWLOCK) +#elif defined(GFLAGS_HAVE_PTHREAD) && defined(GFLAGS_HAVE_RWLOCK) // Needed for pthread_rwlock_*. If it causes problems, you could take it - // out, but then you'd have to unset HAVE_RWLOCK (at least on linux -- it + // out, but then you'd have to unset GFLAGS_HAVE_RWLOCK (at least on linux -- it // *does* cause problems for FreeBSD, or MacOSX, but isn't needed // for locking there.) # ifdef __linux__ @@ -140,7 +140,7 @@ # endif # include <pthread.h> typedef pthread_rwlock_t MutexType; -#elif HAVE_PTHREAD +#elif defined(GFLAGS_HAVE_PTHREAD) # include <pthread.h> typedef pthread_mutex_t MutexType; #else @@ -247,7 +247,7 @@ bool Mutex::TryLock() { return is_safe_ ? void Mutex::ReaderLock() { Lock(); } // we don't have read-write locks void Mutex::ReaderUnlock() { Unlock(); } -#elif defined(HAVE_PTHREAD) && defined(HAVE_RWLOCK) +#elif defined(GFLAGS_HAVE_PTHREAD) && defined(GFLAGS_HAVE_RWLOCK) #define SAFE_PTHREAD(fncall) do { /* run fncall if is_safe_ is true */ \ if (is_safe_ && fncall(&mutex_) != 0) abort(); \ @@ -272,7 +272,7 @@ void Mutex::ReaderLock() { SAFE_PTHREAD(pthread_rwlock_rdlock); } void Mutex::ReaderUnlock() { SAFE_PTHREAD(pthread_rwlock_unlock); } #undef SAFE_PTHREAD -#elif defined(HAVE_PTHREAD) +#elif defined(GFLAGS_HAVE_PTHREAD) #define SAFE_PTHREAD(fncall) do { /* run fncall if is_safe_ is true */ \ if (is_safe_ && fncall(&mutex_) != 0) abort(); \ @@ -38,7 +38,7 @@ #include <assert.h> #include <config.h> -#if HAVE_INTTYPES_H +#ifdef GFLAGS_HAVE_INTTYPES_H # include <inttypes.h> #endif #include <stdarg.h> // for va_* @@ -46,9 +46,9 @@ #include <stdio.h> #include <iostream> #include <string> -#if HAVE_SYS_STAT_H -# include <sys/stat.h> -#endif // for mkdir() +#ifdef GFLAGS_HAVE_SYS_STAT_H +# include <sys/stat.h> // for mkdir +#endif namespace GFLAGS_NAMESPACE { @@ -58,20 +58,20 @@ namespace GFLAGS_NAMESPACE { extern GFLAGS_DLL_DECL void (*gflags_exitfunc)(int); // Work properly if either strtoll or strtoq is on this system -#if HAVE_STRTOLL +#if defined(GFLAGS_HAVE_STRTOLL) # define strto64 strtoll -# define strtou64 strtoull -#elif HAVE_STRTOQ +# define strtou64 strtoull +#elif defined(GFLAGS_HAVE_STRTOQ) # define strto64 strtoq -# define strtou64 strtouq +# define strtou64 strtouq #else // Neither strtoll nor strtoq are defined. I hope strtol works! -# define strto64 strtol +# define strto64 strtol # define strtou64 strtoul #endif -// If we have inttypes.h, it will have defined PRId32/etc for us. If -// not, take our best guess. +// If we have inttypes.h, it will have defined PRId32/etc for us. +// If not, take our best guess. #ifndef PRId32 # define PRId32 "d" #endif diff --git a/src/windows_port.cc b/src/windows_port.cc index d122673..5511f8d 100644 --- a/src/windows_port.cc +++ b/src/windows_port.cc @@ -32,14 +32,14 @@ */ #ifndef _WIN32 -# error You should only be including windows/port.cc in a windows environment! +# error You should only be including windows/port.cc in a windows environment! #endif -#include <config.h> #include <string.h> // for strlen(), memset(), memcmp() #include <assert.h> #include <stdarg.h> // for va_list, va_start, va_end #include <windows.h> + #include "windows_port.h" // These call the windows _vsnprintf, but always NUL-terminate. diff --git a/src/windows_port.h b/src/windows_port.h index 8a0e49b..6da8796 100644 --- a/src/windows_port.h +++ b/src/windows_port.h @@ -40,18 +40,7 @@ #ifndef GFLAGS_WINDOWS_PORT_H_ #define GFLAGS_WINDOWS_PORT_H_ -#ifndef GFLAGS_DLL_DECL -# if defined(_MSC_VER) && defined(GFLAGS_SHARED_LIBS) -# ifdef GFLAGS_DLL_EXPORT -# define GFLAGS_DLL_DECL __declspec(dllexport) -# else -# define GFLAGS_DLL_DECL __declspec(dllimport) -# endif -# else -# define GFLAGS_DLL_DECL -# endif -#endif - +#include "config.h" #ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN /* We always want minimal includes */ |