-a/--average option implemented.
authorshort <>
Tue, 21 Nov 2000 15:06:43 +0000 (15:06 +0000)
committershort <>
Tue, 21 Nov 2000 15:06:43 +0000 (15:06 +0000)
timeplan.c

index c489ce0..7818e43 100644 (file)
@@ -29,11 +29,12 @@ static const char version[]="This is TimePlan, version 1.0\n";
 static const char *pname;
 static char *finame;
 static FILE *fi;
-static int verbose=0,tree=0;
+static int verbose=0,tree=0,doaverage=0;
 static char *formtotal=DEF_FORMTOTAL;
 static char buf[LINE_MAX];
 static int line=0;
 static enum { SORT_NO,SORT_TIMETOT,SORT_STORES } sortby=SORT_TIMETOT;
+static unsigned lifetime_days=0;
 
 static void usage(void)
 {
@@ -50,6 +51,7 @@ Usage: timeplan [-u|--unsort] [-s|--stores] [-T|--timetot]  [-t|--tree]\n\
   -s, --stores\t\tSort the result by stores count\n\
   -T, --timetot\t\tSort the result by total time (default)\n\
   -t, --tree\t\tOrganize data as hierarchy tree\n\
+  -a, --average\t\tDisplay all times as average-per-day value\n\
   -c, --condition\tDefine condition variable\n\
   -f, --formtotal\tFormat \"Total\" column (\"text *val/val:width text\")\n\
   -r, --rule\t\tAdd to the end of .rc file this rule (':'->'\\t')\n\
@@ -65,6 +67,7 @@ static const struct option longopts[]={
 {"stores"   ,0,0,'s'},
 {"timetot"  ,0,0,'T'},
 {"tree"     ,0,0,'t'},
+{"average"  ,0,0,'a'},
 {"condition",1,0,'c'},
 {"formtotal",1,0,'f'},
 {"rule"     ,1,0,'r'},
@@ -87,16 +90,18 @@ static int hashtable_tot=0;
 
 static int dumpaction(const struct action *action)
 {
-int tot FAKEUSE,mins FAKEUSE,hours FAKEUSE,days FAKEUSE,origtot;
+int tot,mins FAKEUSE,hours FAKEUSE,days FAKEUSE,origtot;
 char *s,fmt[]="%?d";
 
        if (action) {
                tot=(action->timetot+30)/60;
+               if (doaverage && lifetime_days)
+                       tot/=lifetime_days;
                mins=tot; hours=mins/60; days=hours/24;
                mins%=60; hours%=24;
-               origtot=tot;
                }
-       else origtot=0;
+       else tot=0;
+       origtot=tot;
        for (s=formtotal;*s;s++)
                switch (*s) {
                        case '*': case '/': {
@@ -484,7 +489,7 @@ time_t basetime=-1,currtime;
 int hour,min,sec;
 
        pname=argv[0];
-       while ((optc=getopt_long(argc,argv,"b:pw:qusTtc:f:r:vhV",longopts,NULL))!=EOF) switch (optc) {
+       while ((optc=getopt_long(argc,argv,"b:pw:qusTtac:f:r:vhV",longopts,NULL))!=EOF) switch (optc) {
                
                case 'u':
                        sortby=SORT_NO;
@@ -498,6 +503,9 @@ int hour,min,sec;
                case 't':
                        tree=1;
                        break;
+               case 'a':
+                       doaverage=1;
+                       break;
                case 'c':
                        if (iscondition(optarg))
                                fprintf(ERRH1"Condition \"%s\" already set!\n",ERRH2,optarg);
@@ -596,6 +604,7 @@ const char *days[]={"Ne","Po","Ut","St","Ct","Pa","So"};
 #undef WANTED
                        basetime=t;
                        store(MARK_DAY,0);
+                       lifetime_days++;
                        continue;
                        }