Commit 690172b4 authored by Craig Silverstein's avatar Craig Silverstein

Thu Apr 19 15:15:07 2007 Google Inc. <opensource@google.com>

	* google-gflags: version 0.4
	* Remove is_default from GetCommandLineFlagInfo (csilvers)
	* Portability fixes: includes, strtoll, gcc4.3 errors (csilvers)
	* A few doc typo cleanups (csilvers)


git-svn-id: https://gflags.googlecode.com/svn/trunk@13 6586e3c6-dcc4-952a-343f-ff74eb82781d
parent 290da389
......@@ -20,3 +20,10 @@ Wed Mar 28 12:15:56 2007 Google Inc. <opensource@google.com>
* Add is_default to CommandLineFlagInfo (pchien)
* Make docs a bit prettier (csilvers)
* Actually include the python files in the distribution! :-/ (csilvers)
Thu Apr 19 15:15:07 2007 Google Inc. <opensource@google.com>
* google-gflags: version 0.4
* Remove is_default from GetCommandLineFlagInfo (csilvers)
* Portability fixes: includes, strtoll, gcc4.3 errors (csilvers)
* A few doc typo cleanups (csilvers)
......@@ -21,7 +21,7 @@ docdir = $(prefix)/share/doc/$(PACKAGE)-$(VERSION)
## Add your documentation files (in doc/) in addition to these
## top-level boilerplate files. Also add a TODO file if you have one.
dist_doc_DATA = AUTHORS COPYING ChangeLog INSTALL NEWS README \
doc/gflags.html
doc/designstyle.css doc/gflags.html
## The libraries (.so's) you want to install
lib_LTLIBRARIES =
......
......@@ -240,7 +240,7 @@ googleincludedir = $(includedir)/google
googleinclude_HEADERS = src/google/gflags.h
docdir = $(prefix)/share/doc/$(PACKAGE)-$(VERSION)
dist_doc_DATA = AUTHORS COPYING ChangeLog INSTALL NEWS README \
doc/gflags.html
doc/designstyle.css doc/gflags.html
lib_LTLIBRARIES = libgflags.la
TESTS = gflags_unittest
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,7 +3,7 @@
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
timestamp='2006-01-30'
timestamp='2005-08-03'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
......@@ -106,7 +106,7 @@ set_cc_for_build='
trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
: ${TMPDIR=/tmp} ;
{ tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
{ tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
{ test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
{ tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
{ echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
......@@ -206,9 +206,6 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
*:ekkoBSD:*:*)
echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
exit ;;
*:SolidBSD:*:*)
echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
exit ;;
macppc:MirBSD:*:*)
echo powerppc-unknown-mirbsd${UNAME_RELEASE}
exit ;;
......@@ -767,12 +764,7 @@ EOF
echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
exit ;;
*:FreeBSD:*:*)
case ${UNAME_MACHINE} in
pc98)
echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
*)
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
esac
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
exit ;;
i*:CYGWIN*:*)
echo ${UNAME_MACHINE}-pc-cygwin
......@@ -787,7 +779,7 @@ EOF
i*:PW*:*)
echo ${UNAME_MACHINE}-pc-pw32
exit ;;
x86:Interix*:[345]*)
x86:Interix*:[34]*)
echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//'
exit ;;
[345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
......@@ -859,11 +851,7 @@ EOF
#endif
#endif
EOF
eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
/^CPU/{
s: ::g
p
}'`"
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
;;
mips64:Linux:*:*)
......@@ -882,11 +870,7 @@ EOF
#endif
#endif
EOF
eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
/^CPU/{
s: ::g
p
}'`"
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
;;
or32:Linux:*:*)
......@@ -935,9 +919,6 @@ EOF
sparc:Linux:*:* | sparc64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
vax:Linux:*:*)
echo ${UNAME_MACHINE}-dec-linux-gnu
exit ;;
x86_64:Linux:*:*)
echo x86_64-unknown-linux-gnu
exit ;;
......@@ -983,7 +964,7 @@ EOF
LIBC=gnulibc1
# endif
#else
#if defined(__INTEL_COMPILER) || defined(__PGI)
#ifdef __INTEL_COMPILER
LIBC=gnu
#else
LIBC=gnuaout
......@@ -993,11 +974,7 @@ EOF
LIBC=dietlibc
#endif
EOF
eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
/^LIBC/{
s: ::g
p
}'`"
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
test x"${LIBC}" != x && {
echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
exit
......@@ -1208,6 +1185,7 @@ EOF
*:Darwin:*:*)
UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
case $UNAME_PROCESSOR in
*86) UNAME_PROCESSOR=i686 ;;
unknown) UNAME_PROCESSOR=powerpc ;;
esac
echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
......@@ -1286,9 +1264,6 @@ EOF
i*86:skyos:*:*)
echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
exit ;;
i*86:rdos:*:*)
echo ${UNAME_MACHINE}-pc-rdos
exit ;;
esac
#echo '(No uname command or uname output not recognized.)' 1>&2
......
......@@ -3,7 +3,7 @@
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
# 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
timestamp='2006-01-02'
timestamp='2005-07-08'
# This file is (in principle) common to ALL GNU software.
# The presence of a machine in this file suggests that SOME GNU software
......@@ -119,9 +119,8 @@ esac
# Here we must recognize all the valid KERNEL-OS combinations.
maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
case $maybe_os in
nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
storm-chaos* | os2-emx* | rtmk-nova*)
nto-qnx* | linux-gnu* | linux-dietlibc | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | \
kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*)
os=-$maybe_os
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
;;
......@@ -172,10 +171,6 @@ case $os in
-hiux*)
os=-hiuxwe2
;;
-sco6)
os=-sco5v6
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco5)
os=-sco3.2v5
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
......@@ -192,10 +187,6 @@ case $os in
# Don't forget version if it is 3.2v4 or newer.
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco5v6*)
# Don't forget version if it is 3.2v4 or newer.
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco*)
os=-sco3.2v2
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
......@@ -248,7 +239,7 @@ case $basic_machine in
| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
| i370 | i860 | i960 | ia64 \
| ip2k | iq2000 \
| m32r | m32rle | m68000 | m68k | m88k | maxq | mb | microblaze | mcore \
| m32r | m32rle | m68000 | m68k | m88k | maxq | mcore \
| mips | mipsbe | mipseb | mipsel | mipsle \
| mips16 \
| mips64 | mips64el \
......@@ -266,7 +257,7 @@ case $basic_machine in
| mipsisa64sr71k | mipsisa64sr71kel \
| mipstx39 | mipstx39el \
| mn10200 | mn10300 \
| mt \
| ms1 \
| msp430 \
| ns16k | ns32k \
| or32 \
......@@ -295,9 +286,6 @@ case $basic_machine in
;;
m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
;;
ms1)
basic_machine=mt-unknown
;;
# We use `pc' rather than `unknown'
# because (1) that's what they normally are, and
......@@ -348,7 +336,7 @@ case $basic_machine in
| mipsisa64sr71k-* | mipsisa64sr71kel-* \
| mipstx39-* | mipstx39el-* \
| mmix-* \
| mt-* \
| ms1-* \
| msp430-* \
| none-* | np1-* | ns16k-* | ns32k-* \
| orion-* \
......@@ -708,9 +696,6 @@ case $basic_machine in
basic_machine=i386-pc
os=-msdos
;;
ms1-*)
basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
;;
mvs)
basic_machine=i370-ibm
os=-mvs
......@@ -818,12 +803,6 @@ case $basic_machine in
pc532 | pc532-*)
basic_machine=ns32k-pc532
;;
pc98)
basic_machine=i386-pc
;;
pc98-*)
basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentium | p5 | k5 | k6 | nexgen | viac3)
basic_machine=i586-pc
;;
......@@ -880,10 +859,6 @@ case $basic_machine in
basic_machine=i586-unknown
os=-pw32
;;
rdos)
basic_machine=i386-pc
os=-rdos
;;
rom68k)
basic_machine=m68k-rom68k
os=-coff
......@@ -1199,23 +1174,21 @@ case $os in
| -aos* \
| -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
| -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
| -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
| -openbsd* | -solidbsd* \
| -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* | -openbsd* \
| -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
| -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
| -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
| -chorusos* | -chorusrdb* \
| -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
| -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
| -uxpv* | -beos* | -mpeix* | -udk* \
| -mingw32* | -linux-gnu* | -linux-uclibc* | -uxpv* | -beos* | -mpeix* | -udk* \
| -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
| -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
| -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
| -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
| -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
| -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
| -skyos* | -haiku* | -rdos*)
| -skyos* | -haiku*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-qnx*)
......
This diff is collapsed.
......@@ -10,7 +10,7 @@
# make sure we're interpreted by some minimal autoconf
AC_PREREQ(2.57)
AC_INIT(gflags, 0.3, opensource@google.com)
AC_INIT(gflags, 0.4, opensource@google.com)
# The argument here is just something that should be in the current directory
# (for sanity checking)
AC_CONFIG_SRCDIR(README)
......@@ -40,6 +40,9 @@ AC_CHECK_TYPE(uint16_t, ac_cv_have_uint16_t=1, ac_cv_have_uint16_t=0)
AC_CHECK_TYPE(u_int16_t, ac_cv_have_u_int16_t=1, ac_cv_have_u_int16_t=0)
AC_CHECK_TYPE(__uint16, ac_cv_have___uint16=1, ac_cv_have___uint16=0)
AC_CHECK_FUNCS(strtoll)
AC_CHECK_FUNCS(strtoq)
AX_C___ATTRIBUTE__
ACX_PTHREAD
......
......@@ -159,7 +159,7 @@ use a flag that's defined in another file. For instance, if I were
writing <code>bar.cc</code> but wanted to access the big_menu, flag, I
would put this near the top of <code>bar.cc</code>:</p>
<pre>
DEFINE_bool(big_menu);
DECLARE_bool(big_menu);
</pre>
<p>This is functionally equivalent to saying <code>extern
......@@ -280,7 +280,7 @@ processing. So in <code>foo -f1 1 -- -f2 2</code>, <code>f1</code> is
considered a flag, but <code>-f2</code> is not.</p>
<p>Note that flags do not have single-letter synonyms, like they do in
the getopt library, nor do we allowing "combining" flags behind a
the getopt library, nor do we allow "combining" flags behind a
single dash, as in <code>ls -la</code>.</p>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
google-gflags (0.4-1) unstable; urgency=low
* google-gflags: version 0.4
* Remove is_default from GetCommandLineFlagInfo (csilvers)
* Portability fixes: includes, strtoll, gcc4.3 errors (csilvers)
* A few doc typo cleanups (csilvers)
-- Google Inc. <opensource@google.com> Thu, 19 Apr 2007 15:18:43 -0700
google-gflags (0.3-1) unstable; urgency=low
* google-gflags: version 0.2
* added support for python commandlineflags, as well as c++
* gflags2man, a script to turn flags into a man page (dchristian)
-- Google Inc. <opensource@google.com> Mon, 22 Jan 2007 15:33:06 -0800
google-gflags (0.2-1) unstable; urgency=low
* google-gflags: version 0.3
* python portability fix: use popen instead of subprocess (csilvers)
* Add is_default to CommandLineFlagInfo (pchien)
* Make docs a bit prettier (csilvers)
* Actually include the python files in the distribution! :-/ (csilvers)
-- Google Inc. <opensource@google.com> Wed, 28 Mar 2007 12:15:56 -0700
google-gflags (0.1-1) unstable; urgency=low
* Initial release.
......
......@@ -9,17 +9,17 @@ Section: libdevel
Architecture: any
Depends: libgoogle-gflags0 (= ${Source-Version})
Description: a library that implements commandline flags
processing. As such it's a replacement for getopt(). It has increased
flexibility, including built-in support for C++ types like string, and
the ability to define flags in the source file in which they're used.
The devel package contains static and debug libraries and header files
for developing applications that use the google-gflags package.
processing. As such it's a replacement for getopt(). It has increased
flexibility, including built-in support for C++ types like string, and
the ability to define flags in the source file in which they're used.
The devel package contains static and debug libraries and header files
for developing applications that use the google-gflags package.
Package: libgoogle-gflags0
Section: libs
Architecture: any
Depends: ${shlibs:Depends}
Description: a library that implements commandline flags
processing. As such it's a replacement for getopt(). It has increased
flexibility, including built-in support for C++ types like string, and
the ability to define flags in the source file in which they're used.
\ No newline at end of file
processing. As such it's a replacement for getopt(). It has increased
flexibility, including built-in support for C++ types like string, and
the ability to define flags in the source file in which they're used.
\ No newline at end of file
......@@ -4,4 +4,5 @@ ChangeLog
INSTALL
NEWS
README
doc/designstyle.css
doc/gflags.html
......@@ -52,7 +52,7 @@ rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%doc AUTHORS COPYING ChangeLog INSTALL NEWS README doc/gflags.html
%doc AUTHORS COPYING ChangeLog INSTALL NEWS README doc/designstyle.css doc/gflags.html
%{prefix}/lib/libgflags.so.0
%{prefix}/lib/libgflags.so.0.0.0
......
......@@ -32,7 +32,7 @@
from distutils.core import setup
setup(name='gflags',
version='0.3',
version='0.4',
description='Google Commandline Flags Module',
license='BSD',
author='Google Inc.',
......
......@@ -30,6 +30,12 @@
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the `strtoll' function. */
#undef HAVE_STRTOLL
/* Define to 1 if you have the `strtoq' function. */
#undef HAVE_STRTOQ
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
......
......@@ -35,6 +35,7 @@
// stuff.
#include "config.h"
#include <stdio.h> // for snprintf
#include <ctype.h>
#include <errno.h>
#include <string.h>
......@@ -53,6 +54,19 @@
#define PATH_SEPARATOR '/'
#endif
// Work properly if either strtoll or strtoq is on this system
#ifdef HAVE_STRTOLL
# define strtoint64 strtoll
# define strtouint64 strtoull
#elif HAVE_STRTOQ
# define strtoint64 strtoq
# define strtouint64 strtouq
#else
// Neither strtoll nor strtoq are defined. I hope strtol works!
# define strtoint64 strtol
# define strtouint64 strtoul
#endif
using std::string;
using std::map;
using std::vector;
......@@ -138,7 +152,7 @@ FlagValue::FlagValue(void* valbuf, const char* type) : value_buffer_(valbuf) {
else if (strcmp(type, "uint64") == 0) type_ = FV_UINT64;
else if (strcmp(type, "double") == 0) type_ = FV_DOUBLE;
else if (strcmp(type, "string") == 0) type_ = FV_STRING;
else assert("" == "Unknown typename");
else assert(false); // Unknown typename
}
FlagValue::~FlagValue() {
......@@ -185,7 +199,7 @@ bool FlagValue::ParseFrom(const char* value) {
switch (type_) {
case FV_INT32: {
const int64 r = strtoq(value, &end, base);
const int64 r = strtoint64(value, &end, base);
if (errno || end != value + strlen(value)) return false; // bad parse
if (static_cast<int32>(r) != r) // worked, but number out of range
return false;
......@@ -193,7 +207,7 @@ bool FlagValue::ParseFrom(const char* value) {
return true;
}
case FV_INT64: {
const int64 r = strtoq(value, &end, base);
const int64 r = strtoint64(value, &end, base);
if (errno || end != value + strlen(value)) return false; // bad parse
SET_VALUE_AS(int64, r);
return true;
......@@ -201,7 +215,7 @@ bool FlagValue::ParseFrom(const char* value) {
case FV_UINT64: {
while (*value == ' ') value++;
if (*value == '-') return false; // negative number
const uint64 r = strtouq(value, &end, base);
const uint64 r = strtouint64(value, &end, base);
if (errno || end != value + strlen(value)) return false; // bad parse
SET_VALUE_AS(uint64, r);
return true;
......@@ -213,7 +227,7 @@ bool FlagValue::ParseFrom(const char* value) {
return true;
}
default: {
assert("" == "unknown type");
assert(false); // unknown type
return false;
}
}
......@@ -239,7 +253,7 @@ string FlagValue::ToString() const {
case FV_STRING:
return VALUE_AS(string);
default:
assert("" == "unknown type"); return "";
assert(false); return ""; // unknown type
}
}
......@@ -251,7 +265,7 @@ const char* FlagValue::TypeName() const {
case FV_UINT64: return "uint64";
case FV_DOUBLE: return "double";
case FV_STRING: return "string";
default: assert("" == "unknown type"); return "";
default: assert(false); return ""; // unknown type
}
}
......@@ -265,7 +279,7 @@ bool FlagValue::Equal(const FlagValue& x) const {
case FV_UINT64: return VALUE_AS(uint64) == OTHER_VALUE_AS(x, uint64);
case FV_DOUBLE: return VALUE_AS(double) == OTHER_VALUE_AS(x, double);
case FV_STRING: return VALUE_AS(string) == OTHER_VALUE_AS(x, string);
default: assert("" == "unknown type"); return false;
default: assert(false); return false; // unknown type
}
}
......@@ -277,7 +291,7 @@ FlagValue* FlagValue::New() const {
case FV_UINT64: return new FlagValue(new uint64, "uint64");
case FV_DOUBLE: return new FlagValue(new double, "double");
case FV_STRING: return new FlagValue(new string, "string");
default: assert("" == "unknown type"); return NULL;
default: assert(false); return NULL; // assert false
}
}
......@@ -290,7 +304,7 @@ void FlagValue::CopyFrom(const FlagValue& x) {
case FV_UINT64: SET_VALUE_AS(uint64, OTHER_VALUE_AS(x, uint64)); break;
case FV_DOUBLE: SET_VALUE_AS(double, OTHER_VALUE_AS(x, double)); break;
case FV_STRING: SET_VALUE_AS(string, OTHER_VALUE_AS(x, string)); break;
default: assert("" == "unknown type");
default: assert(false); // unknown type
}
}
......@@ -611,7 +625,8 @@ bool FlagRegistry::SetFlagLocked(CommandLineFlag* flag,
break;
}
default: {
assert("" == "unknown set_mode"); return false;
// unknown set_mode
assert(false); return false;
}
}
......@@ -1155,13 +1170,11 @@ string CommandLineFlagParser::ProcessOptionsFromStringLocked(
// All of these work on the default, global registry.
// For GetCommandLineOption, return false if no such flag
// is known, true otherwise. We clear "value" if a suitable
// flag is found. If is_default_value is non-NULL, we set it to
// contain whether the value is a default or was explicitly set.
// flag is found.
// --------------------------------------------------------------------
bool GetCommandLineOption(const char* name, string* value,
bool *is_default_value) {
bool GetCommandLineOption(const char* name, string* value) {
if (NULL == name)
return false;
assert(value);
......@@ -1174,10 +1187,6 @@ bool GetCommandLineOption(const char* name, string* value,
return false;
} else {
*value = flag->current_value();
if (is_default_value) {
flag->UpdateModifiedBit();
*is_default_value = !flag->modified_;
}
registry->Unlock();
return true;
}
......
......@@ -763,36 +763,29 @@ TEST(ProgramUsageTest, BaseTest) { // Depends on 1st arg to InitGoogle in main()
TEST(GetCommandLineOptionTest, NameExistsAndIsDefault) {
string value("will be changed");
bool is_default;
bool r = GetCommandLineOption("test_bool", &value, &is_default);
bool r = GetCommandLineOption("test_bool", &value);
EXPECT_EQ(true, r);
EXPECT_EQ("false", value);
EXPECT_EQ(true, is_default);
r = GetCommandLineOption("test_int32", &value, &is_default);
r = GetCommandLineOption("test_int32", &value);
EXPECT_EQ(true, r);
EXPECT_EQ("-1", value);
EXPECT_EQ(true, is_default);
}
TEST(GetCommandLineOptionTest, NameExistsAndWasAssigned) {
FLAGS_test_int32 = 400;
string value("will be changed");
bool is_default;
const bool r = GetCommandLineOption("test_int32", &value, &is_default);
const bool r = GetCommandLineOption("test_int32", &value);
EXPECT_EQ(true, r);
EXPECT_EQ("400", value);
EXPECT_EQ(false, is_default);
}
TEST(GetCommandLineOptionTest, NameExistsAndWasSet) {
SetCommandLineOption("test_int32", "700");
string value("will be changed");
bool is_default;
const bool r = GetCommandLineOption("test_int32", &value, &is_default);
const bool r = GetCommandLineOption("test_int32", &value);
EXPECT_EQ(true, r);
EXPECT_EQ("700", value);
EXPECT_EQ(false, is_default);
}
TEST(GetCommandLineOptionTest, NameExistsAndWasNotSet) {
......@@ -800,42 +793,26 @@ TEST(GetCommandLineOptionTest, NameExistsAndWasNotSet) {
// is_default is still true, but the 'default' value returned has changed!
SetCommandLineOptionWithMode("test_int32", "800", SET_FLAGS_DEFAULT);
string value("will be changed");
bool is_default;
const bool r = GetCommandLineOption("test_int32", &value, &is_default);
const bool r = GetCommandLineOption("test_int32", &value);
EXPECT_EQ(true, r);
EXPECT_EQ("800", value);
EXPECT_EQ(true, is_default);
EXPECT_EQ(true, GetCommandLineFlagInfoOrDie("test_int32").is_default);
}
TEST(GetCommandLineOptionTest, NameExistsAndWasConditionallySet) {
SetCommandLineOptionWithMode("test_int32", "900", SET_FLAG_IF_DEFAULT);
string value("will be changed");
bool is_default;
const bool r = GetCommandLineOption("test_int32", &value, &is_default);
const bool r = GetCommandLineOption("test_int32", &value);
EXPECT_EQ(true, r);
EXPECT_EQ("900", value);
EXPECT_EQ(false, is_default);
}
TEST(GetCommandLineOptionTest, NameDoesNotExist) {
string value("will not be changed");
bool is_default = false;
const bool r = GetCommandLineOption("test_int3210", &value, &is_default);
const bool r = GetCommandLineOption("test_int3210", &value);
EXPECT_EQ(false, r);
EXPECT_EQ("will not be changed", value);
EXPECT_EQ(false, is_default);
}
TEST(GetCommandLineOptionTest, NoLastArg) {
// Mostly, makes sure passing in NULL as last arg doesn't cause a crash
string value("will not be changed, at first");
bool r = GetCommandLineOption("test_int3210", &value, NULL);
EXPECT_EQ(false, r);
EXPECT_EQ("will not be changed, at first", value);
r = GetCommandLineOption("test_int32", &value, NULL);
EXPECT_EQ(true, r);
EXPECT_EQ("-1", value);
}
TEST(GetCommandLineFlagInfoTest, FlagExists) {
......@@ -845,19 +822,49 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) {
EXPECT_EQ("test_int32", info.name);
EXPECT_EQ("int32", info.type);
EXPECT_EQ("", info.description);
EXPECT_EQ("-1", info.current_value);
EXPECT_EQ("-1", info.default_value);
EXPECT_EQ(true, info.is_default);
FLAGS_test_bool = true;
r = GetCommandLineFlagInfo("test_bool", &info);
EXPECT_EQ(true, r);
EXPECT_EQ("test_bool", info.name);
EXPECT_EQ("bool", info.type);
EXPECT_EQ("tests bool-ness", info.description);
EXPECT_EQ("true", info.current_value);
EXPECT_EQ("false", info.default_value);
EXPECT_EQ(false, info.is_default);
FLAGS_test_bool = false;
r = GetCommandLineFlagInfo("test_bool", &info);
EXPECT_EQ(true, r);
EXPECT_EQ("test_bool", info.name);
EXPECT_EQ("bool", info.type);
EXPECT_EQ("tests bool-ness", info.description);
EXPECT_EQ("false", info.current_value);
EXPECT_EQ("false", info.default_value);
EXPECT_EQ(false, info.is_default); // value is same, but flag *was* modified
}
TEST(GetCommandLineFlagInfoTest, FlagDoesNotExist) {
CommandLineFlagInfo info;
// Set to some random values that GetCommandLineFlagInfo should not change
info.name = "name";
info.type = "type";
info.current_value = "curr";
info.default_value = "def";
info.filename = "/";
info.is_default = false;
bool r = GetCommandLineFlagInfo("test_int3210", &info);
EXPECT_EQ(false, r);
EXPECT_EQ("name", info.name);
EXPECT_EQ("type", info.type);
EXPECT_EQ("", info.description);
EXPECT_EQ("curr", info.current_value);
EXPECT_EQ("def", info.default_value);
EXPECT_EQ("/", info.filename);
EXPECT_EQ(false, info.is_default);
}
TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndIsDefault) {
......@@ -866,12 +873,14 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndIsDefault) {
EXPECT_EQ("test_int32", info.name);
EXPECT_EQ("int32", info.type);
EXPECT_EQ("", info.description);
EXPECT_EQ("-1", info.current_value);
EXPECT_EQ("-1", info.default_value);
EXPECT_EQ(true, info.is_default);
info = GetCommandLineFlagInfoOrDie("test_bool");
EXPECT_EQ("test_bool", info.name);
EXPECT_EQ("bool", info.type);
EXPECT_EQ("tests bool-ness", info.description);
EXPECT_EQ("false", info.current_value);
EXPECT_EQ("false", info.default_value);
EXPECT_EQ(true, info.is_default);
}
......@@ -883,6 +892,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndWasAssigned) {
EXPECT_EQ("test_int32", info.name);
EXPECT_EQ("int32", info.type);
EXPECT_EQ("", info.description);
EXPECT_EQ("400", info.current_value);
EXPECT_EQ("-1", info.default_value);
EXPECT_EQ(false, info.is_default);
FLAGS_test_bool = true;
......@@ -890,6 +900,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndWasAssigned) {
EXPECT_EQ("test_bool", info.name);
EXPECT_EQ("bool", info.type);
EXPECT_EQ("tests bool-ness", info.description);
EXPECT_EQ("true", info.current_value);
EXPECT_EQ("false", info.default_value);
EXPECT_EQ(false, info.is_default);
}
......
......@@ -136,22 +136,18 @@ extern const char* ProgramUsage(); // string set by SetUsageMessage()
// commonly, via the DEFINE_foo macro). But if you need a bit more
// control, we have programmatic ways to get/set the flags as well.
// Return true iff the flagname was found. If is_default_value is not
// NULL, set to true iff the flag's value had never been set explicitly.
// Return true iff the flagname was found.
// OUTPUT is set to the flag's value, or unchanged if we return false.
extern bool GetCommandLineOption(const char* name, std::string* OUTPUT,
bool *is_default_value = NULL);
extern bool GetCommandLineOption(const char* name, std::string* OUTPUT);
// Return true iff the flagname was found. OUTPUT is set to the flag's
// CommandLineFlagInfo or unchanged if we return false.
extern bool GetCommandLineFlagInfo(const char* name,
CommandLineFlagInfo* OUTPUT);
// Return the CommandLineFlagInfo of the flagname.
// assertion failure if the flagname was not found.
//
// Example to check if a flag has default value:
// if (GetCommandLineFlagInfoOrDie("foo").is_default)
// Return the CommandLineFlagInfo of the flagname. exit() if name not found.
// Example usage, to check if a flag's value is currently the default value:
// if (GetCommandLineFlagInfoOrDie("foo").is_default) ...
extern CommandLineFlagInfo GetCommandLineFlagInfoOrDie(const char* name);
enum FlagSettingMode {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment