diff recpt1/recpt1.c @ 47:edd904628e2f

a bit improved support for time format. now recpt1 recognize string such as 1h05m10s.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sun, 19 Jul 2009 04:55:44 +0900
parents 9b36fdf7d5d0
children c8051f6da2ab
line wrap: on
line diff
--- a/recpt1/recpt1.c	Sun Jul 19 03:39:29 2009 +0900
+++ b/recpt1/recpt1.c	Sun Jul 19 04:55:44 2009 +0900
@@ -12,6 +12,7 @@
 #include <signal.h>
 #include <errno.h>
 #include <sys/time.h>
+#include <ctype.h>
 
 #include <netdb.h>
 #include <arpa/inet.h>
@@ -510,7 +511,7 @@
 {
     int tfd, wfd;
     int lp;
-    int recsec;
+    int recsec = 0;
     int indefinite = FALSE;
     time_t start_time, cur_time;
     FREQUENCY freq;
@@ -703,16 +704,43 @@
 
     /* get recsec */
     char *rectimestr = argv[optind + 1];
+
     if(!strcmp("-", rectimestr)) {
         indefinite = TRUE;
         recsec = -1;
     }
-    else if(strrchr(rectimestr, 'H') || strrchr(rectimestr, 'h'))
-        recsec = atoi(rectimestr) * 3600;
-    else if(strrchr(rectimestr, 'M') || strrchr(rectimestr, 'm'))
-        recsec = atoi(rectimestr) * 60;
-    else
-        recsec = atoi(rectimestr);
+    else {
+        char *tmpstr;
+        char *p1, *p2;
+
+        tmpstr = strdup(rectimestr);
+        p1 = tmpstr;
+        while(!isdigit(*p1))
+            p1++;
+
+        /* hour */
+        if((p2 = strchr(p1, 'H')) || (p2 = strchr(p1, 'h'))) {
+            *p2 = '\0';
+            recsec += atoi(p1) * 3600;
+            p1 = p2 + 1;
+            while(!isdigit(*p1))
+                p1++;
+        }
+
+        /* minute */
+        if((p2 = strchr(p1, 'M')) || (p2 = strchr(p1, 'm'))) {
+            *p2 = '\0';
+            recsec += atoi(p1) * 60;
+            p1 = p2 + 1;
+            while(!isdigit(*p1))
+                p1++;
+        }
+
+        /* second */
+        recsec += atoi(p1);
+
+        free(tmpstr);
+    }
 
     /* open output file */
     char *destfile = argv[optind + 2];