tAdd functioning program for adjusting time by factor - filmtools - various tools for photographic film development and darkroom printing
 (HTM) git clone git://src.adamsgaard.dk/filmtools
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit 925ca743c9d9b8cad49b4dcfb36a93893f5c666c
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Mon,  6 Jan 2020 12:10:00 +0100
       
       Add functioning program for adjusting time by factor
       
       Diffstat:
         A Makefile                            |      20 ++++++++++++++++++++
         A timeadj.c                           |      43 ++++++++++++++++++++++++++++++
       
       2 files changed, 63 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/Makefile b/Makefile
       t@@ -0,0 +1,20 @@
       +.POSIX:
       +
       +SRC = timeadj.c
       +BIN = timeadj
       +LDFLAGS = -lm
       +
       +OBJ = ${SRC:.c=.o}
       +
       +all: ${BIN}
       +
       +.o:
       +        ${CC} ${LDFLAGS} -o $@
       +
       +.c.o:
       +        ${CC} -c ${CFLAGS} -o $@ -c $<
       +
       +clean:
       +        rm -f ${BIN} ${OBJ}
       +
       +.PHONY: all clean
 (DIR) diff --git a/timeadj.c b/timeadj.c
       t@@ -0,0 +1,43 @@
       +#include <stdio.h>
       +#include <unistd.h>
       +#include <err.h>
       +#include <math.h>
       +
       +#define PROGNAME "timadj"
       +
       +void
       +usage()
       +{
       +        printf("usage: %s FACTOR TIME\n", PROGNAME);
       +        puts("where TIME is in format MM:SS");
       +}
       +
       +int
       +main(int argc, char** argv)
       +{
       +        double factor;
       +        int min, sec, sec_equiv;
       +
       +#ifdef __OpenBSD__
       +        if (pledge("stdio", NULL) == -1)
       +                err(1, "pledge");
       +#endif
       +
       +        if (argc < 3) {
       +                usage();
       +                err(1, NULL);
       +        }
       +
       +        if (sscanf(argv[1], "%lg", &factor) != 1)
       +                err(2, "could not parse FACTOR");
       +        if (sscanf(argv[2], "%d:%d", &min, &sec) != 2)
       +                err(2, "could not parse TIME in MM:SS format");
       +
       +        sec_equiv = min*60 + sec;
       +
       +        printf("%d:%02d\n",
       +               (int)(sec_equiv*factor/60.0),
       +               (int)(sec_equiv*factor) % 60);
       +
       +        return 0;
       +}