From 9f82f60fd2c41572168dc3546a76aa53dff2029e Mon Sep 17 00:00:00 2001 From: David Phillips Date: Tue, 7 Jul 2015 00:06:56 +1200 Subject: Shifted seconds conversion etc into own function, whitespace fixes --- misc.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'misc.c') diff --git a/misc.c b/misc.c index 3b78d4a..c3dc439 100644 --- a/misc.c +++ b/misc.c @@ -28,9 +28,25 @@ #include "misc.h" /* Grabs a 'mm:ss:ff' stamp from stdin */ -int get_stamp(int *m, int *s, int *f) +double get_sec() { - return fscanf(stdin, "%d:%d:%d\n", m, s, f); + int mm = 0; + int ss = 0; + int ff = 0; + int items = fscanf(stdin, "%d:%d:%d\n", &mm, &ss, &ff); + + /* EOF means this is the last track; return invalid time */ + if (items == EOF) + { + return -1; + } + + if (items != 3) + { + fprintf(stderr, "Timestamp malformed\n"); + exit(EXIT_FAILURE); + } + return SEC_FROM_TS(mm, ss, ff); } /* Constructs an output filename in the specified buffer based on the given format and track number -- cgit v1.1