ttimeadj.c - 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) LICENSE
---
ttimeadj.c (758B)
---
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <err.h>
4 #include <math.h>
5
6 char *argv0;
7
8 static void
9 usage()
10 {
11 printf("usage: %s factor time\n", argv0);
12 puts("where time is in format MM:SS");
13 }
14
15 int
16 main(int argc, char **argv)
17 {
18 double factor;
19 int min, sec, sec_equiv;
20 argv0 = *argv;
21
22 #ifdef __OpenBSD__
23 if (pledge("stdio", NULL) == -1)
24 err(1, "pledge");
25 #endif
26
27 if (argc != 3) {
28 usage();
29 errx(1, "incorrect arguments");
30 }
31
32 if (sscanf(argv[1], "%lg", &factor) != 1)
33 errx(2, "could not parse FACTOR");
34 if (sscanf(argv[2], "%d:%d", &min, &sec) != 2)
35 errx(2, "could not parse TIME in MM:SS format");
36
37 sec_equiv = min * 60 + sec;
38
39 printf("%d:%02d\n",
40 (int)(sec_equiv*factor/60.0),
41 (int)(sec_equiv*factor)%60);
42
43 return 0;
44 }