Prechádzať zdrojové kódy

2009-07-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Handle the situation where struct option.name is char *.
	* configure.ac
	* src/OptionParser.cc
Tatsuhiro Tsujikawa 16 rokov pred
rodič
commit
55a35ad2a2
5 zmenil súbory, kde vykonal 96 pridanie a 0 odobranie
  1. 6 0
      ChangeLog
  2. 3 0
      config.h.in
  3. 64 0
      configure
  4. 19 0
      configure.ac
  5. 4 0
      src/OptionParser.cc

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2009-07-14  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Handle the situation where struct option.name is char *.
+	* configure.ac
+	* src/OptionParser.cc
+
 2009-07-14  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Code cleanup

+ 3 - 0
config.h.in

@@ -284,6 +284,9 @@
 /* Define to 1 if you have old openssl. */
 #undef HAVE_OLD_LIBSSL
 
+/* Define 1 if struct option.name is const char* */
+#undef HAVE_OPTION_CONST_NAME
+
 /* Define to 1 if you have the `posix_fallocate' function. */
 #undef HAVE_POSIX_FALLOCATE
 

+ 64 - 0
configure

@@ -23141,6 +23141,70 @@ _ACEOF
 fi
 
 
+# Check struct option.name is assignable from const char*.  struct
+# option.name in opensolaris is of type char*. In Linux, it is const
+# char*
+{ $as_echo "$as_me:$LINENO: checking whether struct option.name is assignable from const char*" >&5
+$as_echo_n "checking whether struct option.name is assignable from const char*... " >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+#include <unistd.h>
+#include <getopt.h>
+
+int
+main ()
+{
+
+const char* s = "const char";
+option op;
+op.name = s;
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  have_option_const_name=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	have_option_const_name=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:$LINENO: result: $have_option_const_name" >&5
+$as_echo "$have_option_const_name" >&6; }
+if test "x$have_option_const_name" = "xyes"; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_OPTION_CONST_NAME 1
+_ACEOF
+
+fi
+
 ac_config_files="$ac_config_files Makefile src/Makefile test/Makefile po/Makefile.in m4/Makefile intl/Makefile lib/Makefile doc/Makefile"
 
 cat >confcache <<\_ACEOF

+ 19 - 0
configure.ac

@@ -349,6 +349,25 @@ AC_CHECK_MEMBER([struct sockaddr_in.sin_len],
                 [],
                 [[#include <netinet/in.h>]])
 
+# Check struct option.name is assignable from const char*.  struct
+# option.name in opensolaris is of type char*. In Linux, it is const
+# char*
+AC_MSG_CHECKING([whether struct option.name is assignable from const char*])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include <unistd.h>
+#include <getopt.h>
+]],
+[[
+const char* s = "const char";
+option op;
+op.name = s;
+]])],
+[have_option_const_name=yes], [have_option_const_name=no])
+AC_MSG_RESULT([$have_option_const_name])
+if test "x$have_option_const_name" = "xyes"; then
+  AC_DEFINE([HAVE_OPTION_CONST_NAME], [1], [Define 1 if struct option.name is const char*])
+fi
+
 AC_CONFIG_FILES([Makefile
 		src/Makefile
 		test/Makefile

+ 4 - 0
src/OptionParser.cc

@@ -71,7 +71,11 @@ static void putOptions(struct option* longOpts, int* plopt,
 {
   for(; first != last; ++first) {
     if(!(*first)->isHidden()) {
+#ifdef HAVE_OPTION_CONST_NAME
       (*longOpts).name = (*first)->getName().c_str();
+#else // !HAVE_OPTION_CONST_NAME
+      (*longOpts).name = strdup((*first)->getName().c_str());
+#endif // !HAVE_OPTION_CONST_NAME
       switch((*first)->getArgType()) {
       case OptionHandler::REQ_ARG:
 	(*longOpts).has_arg = required_argument;