]> pd.if.org Git - pdclib/commitdiff
Started implementation of <time.h>
authorMartin Baute <solar@rootdirectory.de>
Mon, 28 Mar 2016 20:04:11 +0000 (22:04 +0200)
committerMartin Baute <solar@rootdirectory.de>
Mon, 28 Mar 2016 20:04:11 +0000 (22:04 +0200)
15 files changed:
functions/time/asctime.c
functions/time/clock.c
functions/time/ctime.c
functions/time/difftime.c
functions/time/gmtime.c
functions/time/localtime.c
functions/time/mktime.c
functions/time/strftime.c
functions/time/time.c
functions/time/timespec.c
includes/locale.h
includes/time.h
internals/_PDCLIB_int.h
platform/example/functions/_PDCLIB/_PDCLIB_stdinit.c
platform/example/internals/_PDCLIB_config.h

index d9665748f6fb61cd4394c38b8d3133293e704272..8c9db6051e5ae8618c604792067694b50d2a9ef5 100644 (file)
@@ -21,7 +21,8 @@ char * asctime( const struct tm * timeptr )
 
 int main( void )
 {
-    return NO_TESTDRIVER;
+    TESTCASE( NO_TESTDRIVER );
+    return TEST_RESULTS;
 }
 
 #endif
index e4cca240ba85ff14bb342e6af228a6b87d484273..4be69e382e41a5ee8c087a83e77759ce650f540c 100644 (file)
@@ -21,7 +21,8 @@ clock_t clock( void )
 
 int main( void )
 {
-    return NO_TESTDRIVER;
+    TESTCASE( NO_TESTDRIVER );
+    return TEST_RESULTS;
 }
 
 #endif
index e9c37c9a2bb397b78d22922a02aa39e5f1aadf6f..d021a7d3277fd219120d73d28fa905d5b3bbb164 100644 (file)
@@ -21,7 +21,8 @@ char * ctime( const time_t * timer )
 
 int main( void )
 {
-    return NO_TESTDRIVER;
+    TESTCASE( NO_TESTDRIVER );
+    return TEST_RESULTS;
 }
 
 #endif
index 858ff39116ef7d626535aef20129ee64c6dbb568..d2dcfacbce7d79916ce1211d7ce7df31fdfc6f18 100644 (file)
@@ -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
index 7c4c6e36d2b7f1e1d5e42134b8b9d055264514eb..3bd001c3aa9a1ec7b7128fd21cb9eee302f21a8f 100644 (file)
@@ -21,7 +21,8 @@ struct tm * gmtime( const time_t * timer )
 
 int main( void )
 {
-    return NO_TESTDRIVER;
+    TESTCASE( NO_TESTDRIVER );
+    return TEST_RESULTS;
 }
 
 #endif
index 6fda174b83256c6dbc3ad0d90c9cae39017fe9e5..91c0618de733b2479243c586cadc10fed8b8b453 100644 (file)
@@ -21,7 +21,8 @@ struct tm * localtime( const time_t * timer )
 
 int main( void )
 {
-    return NO_TESTDRIVER;
+    TESTCASE( NO_TESTDRIVER );
+    return TEST_RESULTS;
 }
 
 #endif
index fc3759eb28a31c777cb99f9f6d706af7e9578007..0b8596a437b191f04021eec183cb0601f8f1b42c 100644 (file)
@@ -21,7 +21,8 @@ time_t mktime( struct tm * timeptr )
 
 int main( void )
 {
-    return NO_TESTDRIVER;
+    TESTCASE( NO_TESTDRIVER );
+    return TEST_RESULTS;
 }
 
 #endif
index 2402f8cb82b8963e9c9ddb856142ab09b71c5d56..715a321adbde1d8e10edcd73972bc766077a2ad1 100644 (file)
@@ -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
index ec67f50b0db00d6dea2c85239eb80d7a38eb6d4c..4ef5180cf6aba918e291cf00330c03148e4544f2 100644 (file)
@@ -21,7 +21,8 @@ time_t time( time_t * timer )
 
 int main( void )
 {
-    return NO_TESTDRIVER;
+    TESTCASE( NO_TESTDRIVER );
+    return TEST_RESULTS;
 }
 
 #endif
index 2781e6c1287bbd7cee5dcf5c71cd4c256f91741c..7ebe547dbf53c9f0ece94e9d249ac86ef027908d 100644 (file)
@@ -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
index 6d46536f2d2414e7a7052b47308ea35cad9f6d02..da9138245082ee2995d9471690725893d2b59c9b 100644 (file)
@@ -34,6 +34,10 @@ struct lconv
 {
     struct _PDCLIB_ctype_t * ctype;  /* internal <ctype.h> 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  */
index 216150f69f10d71c6960e4a9729e33828b9159c4..00de956bfaf21f665fcbb35f92263c297cf69231 100644 (file)
@@ -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
index 562393233195b2f4c77fa43432ff8e2fa01cbc12..d9e7f07508a5aac6b3cf2fe229149d360a1416ad 100644 (file)
@@ -301,6 +301,13 @@ struct _PDCLIB_file_t
     struct _PDCLIB_file_t * next;     /* Pointer to next struct (internal) */
 };
 
+/* -------------------------------------------------------------------------- */
+/* Various <time.h> internals                                                 */
+/* -------------------------------------------------------------------------- */
+
+typedef _PDCLIB_time            _PDCLIB_time_t;
+typedef _PDCLIB_clock           _PDCLIB_clock_t;
+
 /* -------------------------------------------------------------------------- */
 /* Internal data types                                                        */
 /* -------------------------------------------------------------------------- */
index d7a0c84804344329d7188e28f10412ac4696ed0e..9bcf4559fd291dc14fd77fa00204e98c1928c98c 100644 (file)
@@ -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 *)"",
index 13600b41148c307dc1ada973bca11a071c61da90..4dd5e3a125d4b07df9af0876f50549ef290116d6 100755 (executable)
@@ -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                                                             */
 /* -------------------------------------------------------------------------- */