X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f Date: Sun, 31 Oct 2004 02:12:15 -0700 From: Brian Inglis Subject: Re: tests/libc/ansi/time/makefile problems In-reply-to: <200410242105.i9OL5N5r017512@speedy.ludd.ltu.se> To: djgpp-workers AT delorie DOT com Message-id: Organization: Systematic Software MIME-version: 1.0 X-Mailer: Forte Agent 1.93/32.576 English (American) Content-type: text/plain; charset=us-ascii References: <200410242105 DOT i9OL5N5r017512 AT speedy DOT ludd DOT ltu DOT se> Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id i9V9CJpv032344 Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk ROn Sun, 24 Oct 2004 23:05:23 +0200 (CEST), ams AT ludd DOT ltu DOT se wrote: >Can anyone run make successfully in tests/libc/ansi/time/? Yes -- okay. There are some warnings with recent gcc versions. >When I try I get: >../../../makefile.inc:11: *** Recursive variable `CFLAGS' references itself (eventuall). Stop. > >I'm using make version 3.79.1. No problems with make 3.77. >I suspect it the line that reads > >xstrftm.exe: CFLAGS += -Wno-error > >that is the problem. The following patches should take care of the warnings. Then the CFLAGS line can be removed from the makefile, if that is causing the problem. Index: strftime.c =================================================================== RCS file: /cvs/djgpp/djgpp/tests/libc/ansi/time/strftime.c,v retrieving revision 1.3 diff -p -u -r1.3 strftime.c --- strftime.c 26 May 2002 16:12:46 -0000 1.3 +++ strftime.c 31 Oct 2004 07:07:57 -0000 @@ -11,6 +11,86 @@ #include #include + +#undef CMP +#define CMP(Fmt, Expected) n_fail += compare ((Fmt), tm, (Expected)) + + +typedef struct cmp +{ + const char *fmt; + const char *expected; + +} cmp; + + +struct cmp comparisons[] = +{ + { "%-m", "1" }, /* GNU */ + { "%A", "Friday" }, + { "%^A", "FRIDAY" }, /* GNU */ + { "%B", "January" }, + { "%^B", "JANUARY" }, + { "%C", "19" }, /* POSIX.2 */ + { "%D", "01/09/70" }, /* POSIX.2 */ + { "%E", "E" }, /* C99 */ + { "%F", "1970-01-09"}, /* C99 */ + { "%G", "1970" }, /* GNU */ + { "%H", "13" }, + { "%I", "01" }, + { "%J", "J" }, + { "%K", "K" }, + { "%L", "L" }, + { "%M", "06" }, + { "%N", "N" }, + { "%O", "O" }, /* C99 */ + { "%P", "P" }, + { "%Q", "Q" }, + { "%R", "13:06" }, /* POSIX.2 */ + { "%S", "07" }, + { "%T", "13:06:07" }, /* POSIX.2 */ + { "%U", "01" }, + { "%V", "02" }, + { "%W", "01" }, + { "%X", "13:06:07" }, + { "%Y", "1970" }, + { "%Z", "GMT" }, + { "%_m", " 1" }, /* GNU */ + { "%a", "Fri" }, + { "%^a", "FRI" }, + { "%b", "Jan" }, + { "%^b", "JAN" }, + { "%c", "Fri Jan 9 13:06:07 1970" }, + { "%^c", "FRI JAN 9 13:06:07 1970" }, + { "%d", "09" }, + { "%e", " 9" }, /* POSIX.2 */ + { "%f", "f" }, /* ISO */ + { "%g", "70" }, /* GNU */ + { "%h", "Jan" }, /* POSIX.2 */ + { "%^h", "JAN" }, + { "%i", "i" }, + { "%j", "009" }, + { "%k", "13" }, /* GNU */ + { "%l", " 1" }, /* GNU */ + { "%m", "01" }, + { "%n", "\n" }, /* POSIX.2 */ + { "%o", "o" }, + { "%p", "PM" }, + { "%q", "q" }, + { "%r", "01:06:07 PM"}, /* POSIX.2 */ + { "%s", "738367" }, /* GNU */ + { "%t", "\t" }, /* POSIX.2 */ + { "%u", "5" }, /* POSIX.2 */ + { "%v", "v" }, + { "%w", "5" }, + { "%x", "01/09/70" }, + { "%y", "70" }, + { "%z", "+0000" }, /* GNU */ + { "%%", "%" }, + +}; /* comparisons[] */ + + static int compare (const char *fmt, const struct tm *tm, const char *expected) { @@ -19,7 +99,8 @@ compare (const char *fmt, const struct t if (strcmp (buf, expected)) { #if 1 - printf ("fmt: \"%s\", expected \"%s\", got \"%s\"\n", + printf ("\n fmt: \"%-3s\" expected: \"%s\" \n" + " got: \"%s\" \n", fmt, expected, buf); #endif return 1; @@ -27,68 +108,24 @@ compare (const char *fmt, const struct t return 0; } + int main (void) { - int n_fail = 0; - struct tm *tm; - time_t t = 738367; /* Fri Jan 9 13:06:07 1970 */ - tm = gmtime (&t); + struct cmp * c; + int n_fail = 0; + time_t t = 738367; /* Fri Jan 9 13:06:07 1970 */ + struct tm * tm = gmtime (&t); + /* This is necessary to make strftime give consistent zone strings and e.g., seconds since the epoch (%s). */ putenv (unconst("TZ=GMT0", char *)); -#undef CMP -#define CMP(Fmt, Expected) n_fail += compare ((Fmt), tm, (Expected)) - - CMP ("%-m", "1"); /* GNU */ - CMP ("%A", "Friday"); - CMP ("%^A", "FRIDAY"); /* The ^ is a GNU extension. */ - CMP ("%B", "January"); - CMP ("%^B", "JANUARY"); - CMP ("%C", "19"); /* POSIX.2 */ - CMP ("%D", "01/09/70"); /* POSIX.2 */ - CMP ("%G", "1970"); /* GNU */ - CMP ("%H", "13"); - CMP ("%I", "01"); - CMP ("%M", "06"); - CMP ("%M", "06"); - CMP ("%R", "13:06"); /* POSIX.2 */ - CMP ("%S", "07"); - CMP ("%T", "13:06:07"); /* POSIX.2 */ - CMP ("%U", "01"); - CMP ("%V", "02"); - CMP ("%W", "01"); - CMP ("%X", "13:06:07"); - CMP ("%Y", "1970"); - CMP ("%Z", "GMT"); - CMP ("%_m", " 1"); /* GNU */ - CMP ("%a", "Fri"); - CMP ("%^a", "FRI"); - CMP ("%b", "Jan"); - CMP ("%^b", "JAN"); - CMP ("%c", "Fri Jan 9 13:06:07 1970"); - CMP ("%^c", "FRI JAN 9 13:06:07 1970"); - CMP ("%d", "09"); - CMP ("%e", " 9"); /* POSIX.2 */ - CMP ("%g", "70"); /* GNU */ - CMP ("%h", "Jan"); /* POSIX.2 */ - CMP ("%^h", "JAN"); - CMP ("%j", "009"); - CMP ("%k", "13"); /* GNU */ - CMP ("%l", " 1"); /* GNU */ - CMP ("%m", "01"); - CMP ("%n", "\n"); /* POSIX.2 */ - CMP ("%p", "PM"); - CMP ("%r", "01:06:07 PM"); /* POSIX.2 */ - CMP ("%s", "738367"); /* GNU */ - CMP ("%t", "\t"); /* POSIX.2 */ - CMP ("%u", "5"); /* POSIX.2 */ - CMP ("%w", "5"); - CMP ("%x", "01/09/70"); - CMP ("%y", "70"); - CMP ("%z", "+0000"); /* GNU */ + for (c = comparisons; c < comparisons + sizeof comparisons / sizeof *comparisons; ++ c) + { + CMP( c->fmt, c->expected); + } exit (n_fail ? 1 : 0); } Index: xstrftm.c =================================================================== RCS file: /cvs/djgpp/djgpp/tests/libc/ansi/time/xstrftm.c,v retrieving revision 1.1 diff -p -u -r1.1 xstrftm.c --- xstrftm.c 8 Nov 2003 12:19:41 -0000 1.1 +++ xstrftm.c 31 Oct 2004 07:07:57 -0000 @@ -1,19 +1,38 @@ +#include #include #include #include -extern char __dj_date_format[10]; -extern char __dj_time_format[16]; +extern char __dj_date_format[]; +extern char __dj_time_format[]; int main(int ac, char *av[]) { char buf[99]; time_t t = time(NULL); + const char *locale; +/* default C locale */ + locale = setlocale( LC_TIME, NULL ); + strftime(buf, sizeof(buf), "%x %X", gmtime(&t)); + printf("%s locale %s\n", locale, buf); + +/* current locale */ + locale = setlocale( LC_TIME, "" ); + strftime(buf, sizeof(buf), "%x %X", gmtime(&t)); + printf("%s locale %s\n", locale, buf); + +/* custom locale */ + locale = "custom"; strcpy(__dj_date_format, "%d|%m|%Y"); strcpy(__dj_time_format, "[%H|%M|%S]"); + strftime(buf, sizeof(buf), "%x %X", gmtime(&t)); + printf("%s locale %s\n", locale, buf); +/* default C locale */ + locale = setlocale( LC_TIME, "C" ); strftime(buf, sizeof(buf), "%x %X", gmtime(&t)); - printf("%s\n", buf); + printf("%s locale %s\n", locale, buf); + return 0; } Index: strftimt.c =================================================================== RCS file: /cvs/djgpp/djgpp/tests/libc/ansi/time/strftimt.c,v diff -p -u /dev/null strftimt.c --- /dev/null 0000-00-00 00:00:00.000000000 -0000 +++ strftimt.c 2004-10-31 00:39:18.000000000 -0600 @@ -0,0 +1,192 @@ +/* @(#)strftimt.c 1.1 31 Oct 2004 BWI */ + + + +#include +#include +#include +#include +#include +#include + + + +static const struct +{ + const char * locale; + const char * tz; + const char * format; + const char * text; + struct tm tm; +} tests[] = +/* locale tz format text */ +/* sec min hr day mon year wdy ydy dst */ +/* -1 -1970 0-6 0-* -=+ */ +{ +/* 1 */ { "C", "Universal", "%u %Y-%m-%d %H:%M:%S", "7 1999-01-31 21:01:10", + { 10, 1, 21, 31, 0, 99, 0, 30,-1 }}, +/* 2 */ { "C", "Universal", "%u %C%y.%b.%e %I.%M %p","7 1999.Feb.28 09.01 PM", + { 10, 1, 21, 28, 1, 99, 0, 58,-1 }}, +/* 3 */ { "C", "Universal", "%w %y/%h %j %k-%M-%S", "2 00/Feb 060 16-30-46", + { 46, 30, 16, 29, 1, 100, 2, 59,-1 }}, +/* 4 */ { "C", "Universal", "%a %y %B %e %l:%M %p", "Sat 00 January 1 12:34 PM", + { 12, 34, 12, 1, 0, 100, 6, 0,-1 }}, +/* 5 */ { "C", "Universal", "%A %y-%m-%d %T","Friday 00-03-03 17:41:01", + { 1, 41, 17, 3, 2, 100, 5, 62,-1 }}, +/* 6 */ { "C", "Universal", "%W %F %R", "36 1999-09-09 21:01", + { 10, 1, 21, 9, 8, 99, 4, 251,-1 }}, +/* 7 */ { "C", "Universal", "%U %D %X", "18 05/02/99 12:34:12", + { 12, 34, 12, 2, 4, 99, 1, 121,-1 }}, +/* 8 */ { "C", "Universal", "%x %t %r", "05/21/01 \t 09:01:10 PM", + { 10, 1, 21, 21, 4, 101, 1, 140,-1 }}, +/* 9 */ { "C", "Universal", "%c %n", "Mon May 21 16:30:46 2001 \n", + { 46, 30, 16, 21, 4, 101, 1, 140,-1 }}, +/* 10 */ { "C", "Universal", "%F %T %Z", "2000-01-05 17:41:01 UTC", + { 1, 41, 17, 5, 0, 100, 3, 4,-1 }}, +/* 11 */ { "C", "Universal", "%F %T %z", "2000-01-05 17:41:01 +0000", + { 1, 41, 17, 5, 0, 100, 3, 4,-1 }}, +/* 12 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "1975-12-29 1976-W01-1 1975-w52-1 1975-u52-1", + { 0, 0, 0, 29, 11, 75, 0, 362,-1 }}, +/* 13 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "1977-01-02 1976-W53-7 1977-w00-7 1977-u01-0", + { 0, 0, 0, 2, 0, 77, 0, 1,-1 }}, +/* 14 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "1999-01-02 1998-W53-6 1999-w00-6 1999-u00-6", + { 0, 0, 0, 2, 0, 99, 5, 1,-1 }}, +/* 15 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "1999-12-27 1999-W52-1 1999-w52-1 1999-u52-1", + { 0, 0, 0, 27, 11, 99, 0, 360,-1 }}, +/* 16 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "2000-01-02 1999-W52-7 2000-w00-7 2000-u01-0", + { 0, 0, 0, 2, 0, 100, 0, 1,-1 }}, +/* 17 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "2003-12-28 2003-W52-7 2003-w51-7 2003-u52-0", + { 0, 0, 0, 28, 11, 103, 0, 361,-1 }}, +/* 18 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "2003-12-29 2004-W01-1 2003-w52-1 2003-u52-1", + { 0, 0, 0, 29, 11, 103, 0, 362,-1 }}, +/* 19 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "2003-12-31 2004-W01-3 2003-w52-3 2003-u52-3", + { 0, 0, 0, 31, 11, 103, 2, 364,-1 }}, +/* 20 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "2004-01-01 2004-W01-4 2004-w00-4 2004-u00-4", + { 0, 0, 0, 1, 0, 104, 3, 0,-1 }}, +/* 21 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "2004-01-04 2004-W01-7 2004-w00-7 2004-u01-0", + { 0, 0, 0, 4, 0, 104, 0, 3,-1 }}, +/* 22 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "2004-01-05 2004-W02-1 2004-w01-1 2004-u01-1", + { 0, 0, 0, 5, 0, 104, 0, 4,-1 }}, +/* 23 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "2004-12-26 2004-W52-7 2004-w51-7 2004-u52-0", + { 0, 0, 0, 26, 11, 104, 0, 360,-1 }}, +/* 24 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "2004-12-27 2004-W53-1 2004-w52-1 2004-u52-1", + { 0, 0, 0, 27, 11, 104, 0, 361,-1 }}, +/* 25 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "2004-12-31 2004-W53-5 2004-w52-5 2004-u52-5", + { 0, 0, 0, 31, 11, 104, 4, 365,-1 }}, +/* 26 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "2005-01-01 2004-W53-6 2005-w00-6 2005-u00-6", + { 0, 0, 0, 1, 0, 105, 5, 0,-1 }}, +/* 27 */ { "C", "Universal", "%F %G-W%V-%u %Y-w%W-%u %Y-u%U-%w", "2005-01-03 2005-W01-1 2005-w01-1 2005-u01-1", + { 0, 0, 0, 3, 0, 105, 0, 2,-1 }}, +/* 28 */ { "C", "Universal", "%F %g-W%V-%u %y-w%W-%u %y-u%U-%w", "2012-01-01 11-W52-7 12-w00-7 12-u01-0", + { 0, 0, 0, 1, 0, 112, 0, 0,-1 }}, +/* 29 */ { "C", "Universal", "%F %g-W%V-%u %y-w%W-%u %y-u%U-%w", "2012-02-29 12-W09-3 12-w09-3 12-u09-3", + { 0, 0, 0, 29, 01, 112, 2, 59,-1 }}, +/* 30 */ { "C", "Universal", "%F %g-W%V-%u %y-w%W-%u %y-u%U-%w", "2012-12-31 13-W01-1 12-w53-1 12-u53-1", + { 0, 0, 0, 31, 11, 112, 0, 365,-1 }}, +/* 31 */ { "C", "EST5EDT", "%c %Z %s W%V w%W u%U", "Fri Oct 1 15:30:34 1993 EDT 749503834 W39 w39 u39", + { 34, 30, 15, 1, 9, 93, 5, 273,-1 }}, +/* 32 */ { "C", "Europe/Berlin","%d.%m.%Y %T %Z","01.08.2000 05:06:07 CEST", + { 7, 6, 5, 1, 7, 100, 0, 0,-1 }}, +/* 33 */ { "C", "Europe/Berlin","%d.%m.%Y %T %z","01.08.2000 05:06:07 +0200", + { 7, 6, 5, 1, 7, 100, 0, 0,-1 }}, +#if 0 /* not yet supported */ +/* 34 */ { "ja_JP.EUC-JP","Universal", "%Y %U %a", "2001 20 \xb7\xee", + { 0, 0, 0, 21, 4, 101, 1, 140,-1 }}, +/* 35 */ { "ja_JP.EUC-JP","Universal", "%Y %W %a", "2001 21 \xb7\xee", + { 0, 0, 0, 21, 4, 101, 1, 140,-1 }}, +/* 36 */ { "ja_JP.EUC-JP","Asia/Tokyo", "%Y %W %a", "2001 21 \xb7\xee", + { 0, 0, 0, 21, 4, 101, 1, 140,-1 }}, + +#endif /* 0 */ +}; + + + +int +main (int argc, char *argv[]) +{ + time_t tt; + size_t t; + size_t len = 0; + int rc = 0; + int errs = 0; + struct tm tm = { 0 }; + char text[BUFSIZ] = ""; + + for (t = 0; t < sizeof tests / sizeof *tests; ++t) + { + errno = 0; + + if (setlocale( LC_TIME, tests[t].locale) == NULL) + { + if (errno) perror( "setlocale()" ); + printf( "test %3lu error %6s set locale '%s' category '%s'(%d) \n", + t + 1, "NULL", tests[t].locale, "LC_TIME", LC_TIME); + ++errs; + continue; + } + + if ((rc = setenv( "TZ", tests[t].tz, 1))) + { + if (errno) perror( "setenv()" ); + printf( "test %3lu error %6d set environment '%s' '%s' \n", + t + 1, rc, "TZ", tests[t].tz); + ++errs; + continue; + } + + tzset(); + + tm = tests[t].tm; + + if ((tt = mktime( &tm )) == -1) + { + if (errno) perror( "mktime()" ); + printf( "test %3lu error %6d make time " + "%04d-%02d-%02d %02d:%02d:%02d j%03d w%01d dst %d \n", + t + 1, tt, + tests[t].tm.tm_year + 1900, + tests[t].tm.tm_mon + 1, + tests[t].tm.tm_mday, + tests[t].tm.tm_hour, + tests[t].tm.tm_min, + tests[t].tm.tm_sec, + tests[t].tm.tm_yday + 1, + tests[t].tm.tm_wday, + tests[t].tm.tm_isdst); + ++errs; + continue; + } + + if (!(len = strftime( text, sizeof text, tests[t].format, &tm))) + { + if (errno) perror( "strftime()" ); + printf( "test %3lu error %6lu time format '%s' \n", + t + 1, len, tests[t].format); + ++errs; + continue; + } + + if (strlen( tests[t].text ) != strlen( text ) + || strcmp( tests[t].text, text)) + { + printf( "\n test %3lu error %6s expected '%s' \n" + " actual '%s' \n", + t + 1, "FAILED", tests[t].text, text); + ++errs; + continue; + } + } + + if (errs) + { + printf( "tests %2lu errors %5d passed %lu \n", + sizeof tests / sizeof *tests, + errs, + sizeof tests / sizeof *tests - errs); + } + + return errs; + +} /* main() */ +