avr-libc-commit
[Top][All Lists]
Advanced

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

[avr-libc-commit] [2357] Add file libc/time/print_lz.c, an auxillary fun


From: Mike Rice
Subject: [avr-libc-commit] [2357] Add file libc/time/print_lz.c, an auxillary function shared between isotime_r and asctime_r.
Date: Sun, 21 Apr 2013 16:25:31 +0000

Revision: 2357
          http://svn.sv.gnu.org/viewvc/?view=rev&root=avr-libc&revision=2357
Author:   swfltek
Date:     2013-04-21 16:25:30 +0000 (Sun, 21 Apr 2013)
Log Message:
-----------
Add file libc/time/print_lz.c, an auxillary function shared between isotime_r 
and asctime_r.
asctime now avoids sprintf() and all that entails.

Modified Paths:
--------------
    trunk/avr-libc/libc/time/Files.am
    trunk/avr-libc/libc/time/asctime_r.c
    trunk/avr-libc/libc/time/isotime_r.c

Added Paths:
-----------
    trunk/avr-libc/libc/time/print_lz.c

Modified: trunk/avr-libc/libc/time/Files.am
===================================================================
--- trunk/avr-libc/libc/time/Files.am   2013-04-21 16:20:01 UTC (rev 2356)
+++ trunk/avr-libc/libc/time/Files.am   2013-04-21 16:25:30 UTC (rev 2357)
@@ -27,45 +27,46 @@
  # $Id$
 
 time_a_c_sources = \
-    asc_store.c \
-    asctime.c \
-    asctime_r.c \
-    ctime.c \
-    ctime_r.c \
-    daylight_seconds.c \
-    difftime.c \
-    dst_pointer.c \
-    equation_of_time.c \
-    fatfs_time.c \
-    geo_location.c \
-    gm_sidereal.c \
-    gmtime.c \
-    gmtime_r.c \
-    isLeap.c \
-    isotime.c \
-    isotime_r.c \
-    lm_sidereal.c \
-    localtime.c \
-    localtime_r.c \
-    mk_gmtime.c \
-    mktime.c \
-    month_length.c \
-    moon_phase.c \
-    set_dst.c \
-    set_position.c \
-    set_system_time.c \
-    set_zone.c \
-    solar_declination.c \
-    solar_noon.c \
-    strftime.c \
-    sun_rise.c \
-    sun_set.c \
-    system_time.c \
-    time.c \
-    tm_store.c \
-    utc_offset.c \
-    week_of_month.c \
-    week_of_year.c
+       asc_store.c \
+       asctime.c \
+       asctime_r.c \
+       ctime.c \
+       ctime_r.c \
+       daylight_seconds.c \
+       difftime.c \
+       dst_pointer.c \
+       equation_of_time.c \
+       fatfs_time.c \
+       geo_location.c \
+       gm_sidereal.c \
+       gmtime.c \
+       gmtime_r.c \
+       isLeap.c \
+       isotime.c \
+       isotime_r.c \
+       lm_sidereal.c \
+       localtime.c \
+       localtime_r.c \
+       mk_gmtime.c \
+       mktime.c \
+       month_length.c \
+       moon_phase.c \
+       print_lz.c \
+       set_dst.c \
+       set_position.c \
+       set_system_time.c \
+       set_zone.c \
+       solar_declination.c \
+       solar_noon.c \
+       strftime.c \
+       sun_rise.c \
+       sun_set.c \
+       system_time.c \
+       time.c \
+       tm_store.c \
+       utc_offset.c \
+       week_of_month.c \
+       week_of_year.c
 
 time_a_asm_sources = \
-        system_tick.S
+       system_tick.S

Modified: trunk/avr-libc/libc/time/asctime_r.c
===================================================================
--- trunk/avr-libc/libc/time/asctime_r.c        2013-04-21 16:20:01 UTC (rev 
2356)
+++ trunk/avr-libc/libc/time/asctime_r.c        2013-04-21 16:25:30 UTC (rev 
2357)
@@ -30,43 +30,53 @@
 
 /*
        Re-entrant version of asctime().
-       
+
 */
 #include <time.h>
-#include <stdio.h>
+#include <stdlib.h>
 
 #ifdef __MEMX
-const __memx char ascformat[] = "%s %s %d %.2d:%.2d:%.2d %d";
 const __memx char ascmonths[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
 const __memx char ascdays[] = "SunMonTueWedThuFriSat";
-#define _SPR sprintf_P
 #else
-const char      ascformat[] = "%s %s %d %.2d:%.2d:%.2d %d";
 const char      ascmonths[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
 const char      ascdays[] = "SunMonTueWedThuFriSat";
-#define _SPR sprintf
 #endif
 
+extern void __print_lz(int , char *, char );
+
 void
 asctime_r(const struct tm * timeptr, char *buffer)
 {
-       unsigned char   i, mnth, day;
-       char            d[4];
-       char            m[4];
+       unsigned char   i, m, d;
+       div_t result;
 
-       day = timeptr->tm_wday * 3;
-       mnth = timeptr->tm_mon * 3;
+       d = timeptr->tm_wday * 3;
+       m = timeptr->tm_mon * 3;
        for (i = 0; i < 3; i++) {
-               m[i] = ascmonths[mnth++];
-               d[i] = ascdays[day++];
+           buffer[i] = ascdays[d++];
+           buffer[i+4] = ascmonths[m++];
        }
-       m[3] = d[3] = 0;
+       buffer[3]=buffer[7]=' ';
+       buffer += 8;
 
-       _SPR(buffer, ascformat, d, m, \
-            timeptr->tm_mday, \
-            timeptr->tm_hour, \
-            timeptr->tm_min, \
-            timeptr->tm_sec,
-            timeptr->tm_year + 1900 \
-               );
+       __print_lz(timeptr->tm_mday,buffer,' ');
+       buffer += 3;
+
+       __print_lz(timeptr->tm_hour,buffer,':');
+       buffer += 3;
+
+       __print_lz(timeptr->tm_min,buffer,':');
+       buffer += 3;
+
+       __print_lz(timeptr->tm_sec,buffer,' ');
+       buffer += 3;
+
+       result = div(timeptr->tm_year + 1900 , 100);
+
+       __print_lz(result.quot,buffer,' ');
+       buffer += 2;
+
+       __print_lz(result.rem,buffer,0);
+
 }

Modified: trunk/avr-libc/libc/time/isotime_r.c
===================================================================
--- trunk/avr-libc/libc/time/isotime_r.c        2013-04-21 16:20:01 UTC (rev 
2356)
+++ trunk/avr-libc/libc/time/isotime_r.c        2013-04-21 16:25:30 UTC (rev 
2357)
@@ -35,46 +35,36 @@
 #include <stdlib.h>
 #include <time.h>
 
-void
-__printem(int i, char *buffer, char s)
-{
-    div_t result;
+extern void __print_lz(int , char *, char );
 
-    result = div(i, 10);
-
-       *buffer++ = result.quot + '0';
-       *buffer++ = result.rem + '0';
-       *buffer = s;
-}
-
 void
 isotime_r(struct tm * tmptr, char *buffer)
 {
        int             i;
 
        i = tmptr->tm_year + 1900;
-       __printem(i/100, buffer, '-');
+       __print_lz(i/100, buffer, '-');
        buffer+=2;
-       __printem(i%100, buffer,'-');
+       __print_lz(i%100, buffer,'-');
        buffer+=3;
 
        i = tmptr->tm_mon + 1;
-       __printem(i, buffer,'-');
+       __print_lz(i, buffer,'-');
        buffer+=3;
 
        i = tmptr->tm_mday;
-       __printem(i, buffer,' ');
+       __print_lz(i, buffer,' ');
        buffer+=3;
 
        i = tmptr->tm_hour;
-       __printem(i, buffer,':');
+       __print_lz(i, buffer,':');
        buffer+=3;
 
        i = tmptr->tm_min;
-       __printem(i, buffer,':');
+       __print_lz(i, buffer,':');
        buffer+=3;
 
        i = tmptr->tm_sec;
-       __printem(i, buffer,0);
+       __print_lz(i, buffer,0);
 
 }

Added: trunk/avr-libc/libc/time/print_lz.c
===================================================================
--- trunk/avr-libc/libc/time/print_lz.c                         (rev 0)
+++ trunk/avr-libc/libc/time/print_lz.c 2013-04-21 16:25:30 UTC (rev 2357)
@@ -0,0 +1,45 @@
+/*
+ * (C)2012 Michael Duane Rice All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer. Redistributions in binary
+ * form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution. Neither the name of the copyright holders
+ * nor the names of contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $Id$ */
+
+/* print 2 digit integer with leading zero: auxillary function for isotime and 
asctime */
+
+#include <stdlib.h>
+
+void
+__print_lz(int i, char *buffer, char s)
+{
+    div_t result;
+
+    result = div(i, 10);
+
+       *buffer++ = result.quot + '0';
+       *buffer++ = result.rem + '0';
+       *buffer = s;
+}


Property changes on: trunk/avr-libc/libc/time/print_lz.c
___________________________________________________________________
Added: svn:keywords
   + ID




reply via email to

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