C version: adding the default behaviour of showing time spent in last task
authorviric <viriketo@gmail.com>
Mon, 15 Mar 2010 23:26:05 +0100
changeset 11 4c3c80ec2180
parent 10 29610784a302
child 12 5925d3fbb330
C version: adding the default behaviour of showing time spent in last task bugfix: I removed an 'abort()' I introduced for debugging purposes.
tt.c
--- a/tt.c	Mon Mar 15 23:22:50 2010 +0100
+++ b/tt.c	Mon Mar 15 23:26:05 2010 +0100
@@ -125,8 +125,6 @@
         abort();
     *ptr_end = '\0';
     sscanf(ptr_begin, "%d", &t.tm_hour);
-    if (t.tm_hour == 0)
-        abort();
 
     ptr_begin = ptr_end + 1;
     ptr_end = strchr(ptr_begin, ':');
@@ -180,7 +178,7 @@
 }
 
 static void
-list_task_times()
+list_task_times(int show_only_last)
 {
     FILE *f = open_file("r");
 
@@ -217,7 +215,7 @@
             start_task = end_date + 1;
 
             time = str2time(buf);
-            if (is_prev_time_read)
+            if (is_prev_time_read && !show_only_last)
             {
                 int diff = time - prev_time;
                 char *hms = seconds2hms(diff);
@@ -356,15 +354,17 @@
 {
     if (argc >= 2)
         if (strcmp(argv[1], "-t") == 0)
-            list_task_times();
+            list_task_times(/* show only last */ 0);
         else if (strcmp(argv[1], "-s") == 0)
             sum_times();
+        else if (strcmp(argv[1], "-l") == 0)
+            list_task_switches();
         else if (strcmp(argv[1], "-h") == 0)
             show_help(argv[0]);
         else
             new_task(argv[1]);
     else
-        list_task_switches();
+        list_task_times(/* show only last */ 1);
 
     return 0;
 }