From 761281caf431d264d568aec797095ef2c28f3910 Mon Sep 17 00:00:00 2001 From: Martin Baute Date: Mon, 28 Mar 2016 22:04:11 +0200 Subject: [PATCH] Started implementation of --- functions/time/asctime.c | 3 +- functions/time/clock.c | 3 +- functions/time/ctime.c | 3 +- functions/time/difftime.c | 3 +- functions/time/gmtime.c | 3 +- functions/time/localtime.c | 3 +- functions/time/mktime.c | 3 +- functions/time/strftime.c | 173 +++++++++++++++++- functions/time/time.c | 3 +- functions/time/timespec.c | 3 +- includes/locale.h | 4 + includes/time.h | 18 +- internals/_PDCLIB_int.h | 7 + .../functions/_PDCLIB/_PDCLIB_stdinit.c | 50 +++++ platform/example/internals/_PDCLIB_config.h | 11 ++ 15 files changed, 270 insertions(+), 20 deletions(-) diff --git a/functions/time/asctime.c b/functions/time/asctime.c index d966574..8c9db60 100644 --- a/functions/time/asctime.c +++ b/functions/time/asctime.c @@ -21,7 +21,8 @@ char * asctime( const struct tm * timeptr ) int main( void ) { - return NO_TESTDRIVER; + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; } #endif diff --git a/functions/time/clock.c b/functions/time/clock.c index e4cca24..4be69e3 100644 --- a/functions/time/clock.c +++ b/functions/time/clock.c @@ -21,7 +21,8 @@ clock_t clock( void ) int main( void ) { - return NO_TESTDRIVER; + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; } #endif diff --git a/functions/time/ctime.c b/functions/time/ctime.c index e9c37c9..d021a7d 100644 --- a/functions/time/ctime.c +++ b/functions/time/ctime.c @@ -21,7 +21,8 @@ char * ctime( const time_t * timer ) int main( void ) { - return NO_TESTDRIVER; + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; } #endif diff --git a/functions/time/difftime.c b/functions/time/difftime.c index 858ff39..d2dcfac 100644 --- a/functions/time/difftime.c +++ b/functions/time/difftime.c @@ -21,7 +21,8 @@ double difftime( time_t time1, time_t time0 ) int main( void ) { - return NO_TESTDRIVER; + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; } #endif diff --git a/functions/time/gmtime.c b/functions/time/gmtime.c index 7c4c6e3..3bd001c 100644 --- a/functions/time/gmtime.c +++ b/functions/time/gmtime.c @@ -21,7 +21,8 @@ struct tm * gmtime( const time_t * timer ) int main( void ) { - return NO_TESTDRIVER; + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; } #endif diff --git a/functions/time/localtime.c b/functions/time/localtime.c index 6fda174..91c0618 100644 --- a/functions/time/localtime.c +++ b/functions/time/localtime.c @@ -21,7 +21,8 @@ struct tm * localtime( const time_t * timer ) int main( void ) { - return NO_TESTDRIVER; + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; } #endif diff --git a/functions/time/mktime.c b/functions/time/mktime.c index fc3759e..0b8596a 100644 --- a/functions/time/mktime.c +++ b/functions/time/mktime.c @@ -21,7 +21,8 @@ time_t mktime( struct tm * timeptr ) int main( void ) { - return NO_TESTDRIVER; + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; } #endif diff --git a/functions/time/strftime.c b/functions/time/strftime.c index 2402f8c..715a321 100644 --- a/functions/time/strftime.c +++ b/functions/time/strftime.c @@ -8,8 +8,176 @@ #ifndef REGTEST -size_t strftime( char * restrict s, size_t maxsize, const char * restrict format, const struct tm * restrict timeptr ) +size_t strftime( char * _PDCLIB_restrict s, size_t maxsize, const char * _PDCLIB_restrict format, const struct tm * _PDCLIB_restrict timeptr ) { + /* + If the total number of resulting characters including the terminating null character is not + more than maxsize, the strftime function returns the number of characters placed + into the array pointed to by s not including the terminating null character. + (i.e., < maxsize) + */ + size_t rc = 0; + + while ( rc < maxsize ) + { + if ( *format != '%' ) + { + if ( ( *s++ = *format++ ) == '\0' ) + { + return rc; + } + else + { + ++rc; + } + } + else + { + char flag = 0; + switch ( *++format ) + { + case 'E': + case 'O': + flag = *format++; + break; + default: + /* EMPTY */ + break; + } + switch( *format++ ) + { + case 'a': + /* tm_wday abbreviated */ + break; + case 'A': + /* tm_wday full */ + break; + case 'b': + case 'h': + /* tm_mon abbreviated */ + break; + case 'B': + /* tm_mon full */ + break; + case 'c': + /* locale's date / time representation, %a %b %e %T %Y for C locale */ + /* 'E' for locale's alternative representation */ + break; + case 'C': + /* tm_year divided by 100, truncated to decimal (00-99) */ + /* 'E' for base year (period) in locale's alternative representation */ + break; + case 'd': + /* tm_mday as decimal (01-31) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'D': + /* %m/%d/%y */ + break; + case 'e': + /* tm_mday as decimal ( 1-31) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'F': + /* %Y-%m-%d */ + break; + case 'g': + /* last 2 digits of the week-based year as decimal (00-99) */ + break; + case 'G': + /* week-based year as decimal (e.g. 1997) */ + break; + case 'H': + /* tm_hour as 24h decimal (00-23) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'I': + /* tm_hour as 12h decimal (01-12) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'j': + /* tm_yday as decimal (001-366) */ + break; + case 'm': + /* tm_mon as decimal (01-12) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'M': + /* tm_min as decimal (00-59) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'n': + /* newline */ + break; + case 'p': + /* tm_hour locale's AM/PM designations */ + break; + case 'r': + /* tm_hour / tm_min / tm_sec as locale's 12-hour clock time, %I:%M:%S %p for C locale */ + break; + case 'R': + /* %H:%M */ + break; + case 'S': + /* tm_sec as decimal (00-60) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 't': + /* tabulator */ + break; + case 'T': + /* %H:%M:%S */ + break; + case 'u': + /* tm_wday as decimal (1-7) with Monday == 1 */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'U': + /* week number of the year (first Sunday as the first day of week 1) as decimal (00-53) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'V': + /* week number as decimal (01-53) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'w': + /* tm_wday as decimal number (0-6) with Sunday == 0 */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'W': + /* week number of the year (first Monday as the first day of week 1) as decimal (00-53) */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'x': + /* locale's date representation, %m/%d/%y for C locale */ + /* 'E' for locale's alternative representation */ + break; + case 'X': + /* locale's time representation, %T for C locale */ + /* 'E' for locale's alternative representation */ + break; + case 'y': + /* last 2 digits of tm_year as decimal (00-99) */ + /* 'E' for offset from %EC (year only) in locale's alternative representation */ + /* 'O' for locale's alternative numeric symbols */ + break; + case 'Y': + /* tm_year as decimal (e.g. 1997) */ + /* 'E' for locale's alternative representation */ + break; + case 'z': + /* tm_isdst / UTC offset in ISO8601 format (e.g. -0430 meaning 4 hours 30 minutes behind Greenwich), or no characters */ + break; + case 'Z': + /* tm_isdst / locale's time zone name or abbreviation, or no characters */ + break; + case '%': + /* '%' character */ + break; + } + } + } + return 0; } @@ -21,7 +189,8 @@ size_t strftime( char * restrict s, size_t maxsize, const char * restrict format int main( void ) { - return NO_TESTDRIVER; + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; } #endif diff --git a/functions/time/time.c b/functions/time/time.c index ec67f50..4ef5180 100644 --- a/functions/time/time.c +++ b/functions/time/time.c @@ -21,7 +21,8 @@ time_t time( time_t * timer ) int main( void ) { - return NO_TESTDRIVER; + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; } #endif diff --git a/functions/time/timespec.c b/functions/time/timespec.c index 2781e6c..7ebe547 100644 --- a/functions/time/timespec.c +++ b/functions/time/timespec.c @@ -21,7 +21,8 @@ int timespec_get( struct timespec * ts, int base ) int main( void ) { - return NO_TESTDRIVER; + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; } #endif diff --git a/includes/locale.h b/includes/locale.h index 6d46536..da91382 100644 --- a/includes/locale.h +++ b/includes/locale.h @@ -34,6 +34,10 @@ struct lconv { struct _PDCLIB_ctype_t * ctype; /* internal information */ char * _PDCLIB_errno_texts[_PDCLIB_ERRNO_MAX]; /* strerror() / perror() */ + char * _PDCLIB_month_name_abbr[12]; /* month names, abbreviated */ + char * _PDCLIB_month_name_full[12]; /* month names, full */ + char * _PDCLIB_day_name_abbr[7]; /* weekday names, abbreviated */ + char * _PDCLIB_day_name_full[7]; /* weekday names, full */ char * decimal_point; /* decimal point character */ char * thousands_sep; /* character for seperating groups of digits */ char * grouping; /* string indicating the size of digit groups */ diff --git a/includes/time.h b/includes/time.h index 216150f..00de956 100644 --- a/includes/time.h +++ b/includes/time.h @@ -49,48 +49,48 @@ struct tm Returns -1 if the value cannot be represented in the return type or is not available. */ -clock_t clock( void ) _PDCLIB_nothrow; +clock_t clock( void ); /* Returns the difference between two calendar times in seconds. */ -double difftime( time_t time1, time_t time0 ) _PDCLIB_nothrow; +double difftime( time_t time1, time_t time0 ); /* Normalizes the values in the broken-down time pointed to by timeptr. Returns the calender time specified by the broken-down time. */ -time_t mktime( struct tm * timeptr ) _PDCLIB_nothrow; +time_t mktime( struct tm * timeptr ); /* Returns the current calender time. If timer is not a NULL pointer, stores the current calender time at that address as well. */ -time_t time( time_t * timer ) _PDCLIB_nothrow; +time_t time( time_t * timer ); /* Sets the interval pointed to by ts to the current calender time, based on the specified base. Returns base, if successful, otherwise zero. */ -int timespec_get( struct timespec * ts, int base ) _PDCLIB_nothrow; +int timespec_get( struct timespec * ts, int base ); /* Converts the broken-down time pointed to by timeptr into a string in the form "Sun Sep 16 01:03:52 1973\n\0". */ -char * asctime( const struct tm * timeptr ) _PDCLIB_nothrow; +char * asctime( const struct tm * timeptr ); /* Equivalent to asctime( localtime( timer ) ). */ -char * ctime( const time_t * timer ) _PDCLIB_nothrow; +char * ctime( const time_t * timer ); /* Converts the calender time pointed to by timer into a broken-down time expressed as UTC. Returns a pointer to the broken-down time, or a NULL pointer if it cannot be represented. */ -struct tm * gmtime( const time_t * timer ) _PDCLIB_nothrow; +struct tm * gmtime( const time_t * timer ); /* Converts the calender time pointed to by timer into a broken-down time expressed as local time. Returns a pointer to the broken-down time, or a NULL pointer if if cannot be represented. */ -struct tm * localtime( const time_t * timer ) _PDCLIB_nothrow; +struct tm * localtime( const time_t * timer ); /* Writes the broken-down time pointed to by timeptr into the character array pointed to by s. The string pointed to by format controls the diff --git a/internals/_PDCLIB_int.h b/internals/_PDCLIB_int.h index 5623932..d9e7f07 100644 --- a/internals/_PDCLIB_int.h +++ b/internals/_PDCLIB_int.h @@ -301,6 +301,13 @@ struct _PDCLIB_file_t struct _PDCLIB_file_t * next; /* Pointer to next struct (internal) */ }; +/* -------------------------------------------------------------------------- */ +/* Various internals */ +/* -------------------------------------------------------------------------- */ + +typedef _PDCLIB_time _PDCLIB_time_t; +typedef _PDCLIB_clock _PDCLIB_clock_t; + /* -------------------------------------------------------------------------- */ /* Internal data types */ /* -------------------------------------------------------------------------- */ diff --git a/platform/example/functions/_PDCLIB/_PDCLIB_stdinit.c b/platform/example/functions/_PDCLIB/_PDCLIB_stdinit.c index d7a0c84..9bcf455 100644 --- a/platform/example/functions/_PDCLIB/_PDCLIB_stdinit.c +++ b/platform/example/functions/_PDCLIB/_PDCLIB_stdinit.c @@ -311,6 +311,56 @@ struct lconv _PDCLIB_lconv = { /* EDOM */ (char *)"EDOM (Domain error)", /* EILSEQ */ (char *)"EILSEQ (Illegal sequence)" }, + /* _PDCLIB_month_name_abbr */ + { + (char *)"Jan", + (char *)"Feb", + (char *)"Mar", + (char *)"Apr", + (char *)"May", + (char *)"Jun", + (char *)"Jul", + (char *)"Aug", + (char *)"Sep", + (char *)"Oct", + (char *)"Now", + (char *)"Dec" + }, + /* _PDCLIB_month_name_full */ + { + (char *)"January", + (char *)"February", + (char *)"March", + (char *)"April", + (char *)"May", + (char *)"June", + (char *)"July", + (char *)"August", + (char *)"September", + (char *)"October", + (char *)"November", + (char *)"December" + }, + /* _PDCLIB_day_name_abbr */ + { + (char *)"Sun", + (char *)"Mon", + (char *)"Tue", + (char *)"Wed", + (char *)"Thu", + (char *)"Fri", + (char *)"Sat" + }, + /* _PDCLIB_day_name_full */ + { + (char *)"Sunday", + (char *)"Monday", + (char *)"Tuesday", + (char *)"Wednesday", + (char *)"Thursday", + (char *)"Friday", + (char *)"Saturday" + }, /* decimal_point */ (char *)".", /* thousands_sep */ (char *)"", /* grouping */ (char *)"", diff --git a/platform/example/internals/_PDCLIB_config.h b/platform/example/internals/_PDCLIB_config.h index 13600b4..4dd5e3a 100755 --- a/platform/example/internals/_PDCLIB_config.h +++ b/platform/example/internals/_PDCLIB_config.h @@ -170,6 +170,17 @@ struct _PDCLIB_imaxdiv_t _PDCLIB_intmax rem; }; +/* -------------------------------------------------------------------------- */ +/* Time types */ +/* -------------------------------------------------------------------------- */ + +#define _PDCLIB_time long + +#define _PDCLIB_clock long +#define _PDCLIB_CLOCKS_PER_SEC 1000000 + +#define _PDCLIB_TIME_UTC 1 + /* -------------------------------------------------------------------------- */ /* Floating Point */ /* -------------------------------------------------------------------------- */ -- 2.40.0