tmove time formatting into separate utility source file - stopwatch - simple timer for console or x root window
 (HTM) git clone git://src.adamsgaard.dk/stopwatch
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit ef1f4ceda141836715a03af2ef4b4dfa743bc7f3
 (DIR) parent 2a1619b38698fc684593f26ba052a929ed6acca9
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Thu,  5 Nov 2020 08:15:25 +0100
       
       move time formatting into separate utility source file
       
       Diffstat:
         M stopwatch.c                         |      20 ++------------------
         A timeutil.c                          |      20 ++++++++++++++++++++
         A timeutil.h                          |       1 +
       
       3 files changed, 23 insertions(+), 18 deletions(-)
       ---
 (DIR) diff --git a/stopwatch.c b/stopwatch.c
       t@@ -7,6 +7,8 @@
        #include <err.h>
        #include <X11/Xlib.h>
        
       +#include "timeutil.h"
       +
        void
        usage(char *argv0)
        {
       t@@ -14,24 +16,6 @@ usage(char *argv0)
        }
        
        void
       -format_time(char *out, size_t outsiz, time_t t_elapsed, char *prefix, char *postfix)
       -{
       -        time_t h = 0, m = 0, s = 0;
       -
       -        h = t_elapsed / 3600;
       -        m = (t_elapsed % 3600) / 60;
       -        s = t_elapsed % 60;
       -
       -        if (h > 0)
       -                snprintf(out, outsiz, "%s%lld:%02lld:%02lld%s",
       -                         prefix, h, m, s, postfix);
       -        else if (m > 0)
       -                snprintf(out, outsiz, "%s%lld:%02lld%s", prefix, m, s, postfix);
       -        else
       -                snprintf(out, outsiz, "%s%lld s%s", prefix, s, postfix);
       -}
       -
       -void
        print_loop(unsigned int interval, char *prefix, char *postfix)
        {
                char buf[LINE_MAX];
 (DIR) diff --git a/timeutil.c b/timeutil.c
       t@@ -0,0 +1,20 @@
       +#include <stdio.h>
       +#include <string.h>
       +
       +void
       +format_time(char *out, size_t outsiz, time_t t_elapsed, char *prefix, char *postfix)
       +{
       +        time_t h = 0, m = 0, s = 0;
       +
       +        h = t_elapsed / 3600;
       +        m = (t_elapsed % 3600) / 60;
       +        s = t_elapsed % 60;
       +
       +        if (h > 0)
       +                snprintf(out, outsiz, "%s%lld:%02lld:%02lld%s",
       +                         prefix, h, m, s, postfix);
       +        else if (m > 0)
       +                snprintf(out, outsiz, "%s%lld:%02lld%s", prefix, m, s, postfix);
       +        else
       +                snprintf(out, outsiz, "%s%lld s%s", prefix, s, postfix);
       +}
 (DIR) diff --git a/timeutil.h b/timeutil.h
       t@@ -0,0 +1 @@
       +void format_time(char *out, size_t outsiz, time_t t_elapsed, char *prefix, char *postfix);