octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: configure test for 'strptime'


From: Thomas Treichl
Subject: Re: configure test for 'strptime'
Date: Tue, 18 Sep 2007 19:54:01 +0200
User-agent: Thunderbird 2.0.0.6 (Macintosh/20070728)

John W. Eaton schrieb:
On 18-Sep-2007, Thomas Treichl wrote:

| Hi,
| | please consider the attached patch as a replacement for the platform dependent | 'strptime' test. I've also attached an aclocal.m4 and a configure.in file if | somebody wants to play with it in a way like | | bash$ autoconf && autoheader && ./configure && cat config.h | | I've tested this function on DebianEtch where I get the result | | /* Define to 1 if you have a working `strptime' function. */
|    #define HAVE_STRPTIME 1
| | and on MacOSX IA32 | | /* Define to 1 if you have a working `strptime' function. */
|    /* #undef HAVE_STRPTIME */
| | Thomas

This looks good, but how about combining the check for strptime and
the check to see if it works for our purposes in one macro, so we can
just write

  OCTAVE_CHECK_STRPTIME

in configure.in?

Thanks,

jwe

Yes sure, I just thought if we (maybe somewhen) don't need the fix anymore then we just need to erase the three lines again. Replacing the lines (maybe somewhen) isn't more work either ;) Find attached the new (and once again tested) files.

  Thomas


--- octave/configure.in.~1.574.~        2007-09-18 18:13:12.000000000 +0200
+++ octave/configure.in 2007-09-18 19:05:10.000000000 +0200
@@ -1452,17 +1452,7 @@
   ;;
 esac
 
-case "$canonical_host_type" in
-  *-apple-darwin* | *-*-cygwin*)
-    ## The weekday function, which uses strptime, is broken because
-    ## strptime is apparently not setting wday correctly for formats
-    ## like "%d-%m-%Y", so use our version.  We could use an actual
-    ## configure test for this.
-  ;;
-  *)
-    AC_CHECK_FUNCS(strptime)
-  ;;
-esac
+OCTAVE_CHECK_STRPTIME
 
 OCTAVE_SMART_PUTENV
 
--- octave/aclocal.m4.~1.108.~  2007-09-18 18:13:12.000000000 +0200
+++ octave/aclocal.m4   2007-09-18 19:05:52.000000000 +0200
@@ -987,6 +987,67 @@
   if test "$octave_cv_hdf5_dll" = yes; then
     AC_DEFINE(_HDF5USEDLL_, 1, [Define if using HDF5 dll (Win32)])
   fi])
+dnl 
+dnl Check to see if the function 'strptime' fills all fields of the tm
+dnl structure correctly or if some systems maybe forget about the tm_wday
+dnl and tm_yday fields (see inline comments below)
+dnl
+AC_DEFUN([OCTAVE_CHECK_STRPTIME],[
+  AC_CHECK_FUNC(strptime)
+  if test "$ac_cv_func_strptime" == yes; then
+    AC_MSG_CHECKING([whether strptime works])
+    AC_CACHE_VAL([octave_cv_strptime],[
+      AC_TRY_RUN([#include <stdio.h>
+      #include <time.h>
+
+      int main (int argc, char *argv[]) {
+
+        struct tm tm;
+        time_t t;
+
+        /* Checks for a handle error if return value == NULL, if so then
+           return an error number immediately */
+        if (strptime("17-09-2007 12:10:20", "%d-%m-%Y %H:%M:%S", &tm) == NULL) 
{
+          /* printf ("strptime: An handle error occured\n"); */
+          return (1);
+        }
+        /* printf("year: %d; month: %d; day: %d;\n", 
+             tm.tm_year, tm.tm_mon, tm.tm_mday);
+           printf("hour: %d; minute: %d; second: %d\n", 
+             tm.tm_hour, tm.tm_min, tm.tm_sec);
+           printf("strptime: week day: %d, year day: %d\n",
+             tm.tm_wday, tm.tm_yday); */
+
+        /* The hard coded date from above is a 'Monday' and the day
+           number '259' of the year 2007, so tm_wday == 1 and
+           tm_yday == 259, if these values are not set then return 
+           the error number 1 */
+        if (tm.tm_year != 107) return (1);
+        if (tm.tm_mon  != 8)   return (1);
+        if (tm.tm_mday != 17)  return (1);
+        if (tm.tm_hour != 12)  return (1);
+        if (tm.tm_min  != 10)  return (1);
+        if (tm.tm_sec  != 20)  return (1);
+        /* On some system eg. MacOSX and Cygwin the following two fields
+           may be zero, ie. the function does not work as expected */
+        if (tm.tm_wday != 1)   return (1);
+        if (tm.tm_yday != 259) return (1);
+
+        /* If not already returned from this test program then function
+           seems to work correctly */
+        return (0);
+      
}],[octave_cv_strptime=yes],[octave_cv_strptime=no],[octave_cv_strptime=no]
+      ) # end of TRY_RUN
+    ])  # end of CACHE_VAL
+
+    AC_MSG_RESULT([$octave_cv_strptime])
+    if test x$octave_cv_strptime = xyes
+    then
+      AC_DEFINE(HAVE_STRPTIME, 1,
+         [Define to 1 if you have a working `strptime' function.])
+    fi
+  fi # if test "$ac_cv_func_strptime" == yes; then
+]) # end of AC_DEFUN of OCTAVE_CHECK_STRPTIME
 dnl
 dnl Check for the QHull version.
 dnl
dnl 
dnl Check to see if the function 'strptime' fills all fields of the tm
dnl structure correctly or if some systems maybe forget about the tm_wday
dnl and tm_yday fields (see inline comments below)
dnl
AC_DEFUN([OCTAVE_CHECK_STRPTIME],[
  AC_CHECK_FUNC(strptime)
  if test "$ac_cv_func_strptime" == yes; then
    AC_MSG_CHECKING([whether strptime works])
    AC_CACHE_VAL([octave_cv_strptime],[
      AC_TRY_RUN([#include <stdio.h>
      #include <time.h>

      int main (int argc, char *argv[]) {

        struct tm tm;
        time_t t;

        /* Checks for a handle error if return value == NULL, if so then
           return an error number immediately */
        if (strptime("17-09-2007 12:10:20", "%d-%m-%Y %H:%M:%S", &tm) == NULL) {
          /* printf ("strptime: An handle error occured\n"); */
          return (1);
        }
        /* printf("year: %d; month: %d; day: %d;\n", 
             tm.tm_year, tm.tm_mon, tm.tm_mday);
           printf("hour: %d; minute: %d; second: %d\n", 
             tm.tm_hour, tm.tm_min, tm.tm_sec);
           printf("strptime: week day: %d, year day: %d\n",
             tm.tm_wday, tm.tm_yday); */

        /* The hard coded date from above is a 'Monday' and the day
           number '259' of the year 2007, so tm_wday == 1 and
           tm_yday == 259, if these values are not set then return 
           the error number 1 */
        if (tm.tm_year != 107) return (1);
        if (tm.tm_mon  != 8)   return (1);
        if (tm.tm_mday != 17)  return (1);
        if (tm.tm_hour != 12)  return (1);
        if (tm.tm_min  != 10)  return (1);
        if (tm.tm_sec  != 20)  return (1);
        /* On some system eg. MacOSX and Cygwin the following two fields
           may be zero, ie. the function does not work as expected */
        if (tm.tm_wday != 1)   return (1);
        if (tm.tm_yday != 259) return (1);

        /* If not already returned from this test program then function
           seems to work correctly */
        return (0);
      
}],[octave_cv_strptime=yes],[octave_cv_strptime=no],[octave_cv_strptime=no]
      ) # end of TRY_RUN
    ])  # end of CACHE_VAL

    AC_MSG_RESULT([$octave_cv_strptime])
    if test x$octave_cv_strptime = xyes
    then
      AC_DEFINE(HAVE_STRPTIME, 1,
         [Define to 1 if you have a working `strptime' function.])
    fi
  fi # if test "$ac_cv_func_strptime" == yes; then
]) # end of AC_DEFUN of OCTAVE_CHECK_STRPTIME
AC_INIT([STRPTIME], [1.0], [])
AC_CONFIG_HEADER(config.h)


OCTAVE_CHECK_STRPTIME


AC_OUTPUT

reply via email to

[Prev in Thread] Current Thread [Next in Thread]