home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_11 / splash / cislog.cpp < prev    next >
Text File  |  1993-01-15  |  2KB  |  79 lines

  1. //
  2. // Display monthly connect time to CIS
  3. //
  4.  
  5. #include    <fstream.h>
  6. #include    <stdlib.h>
  7. #include    "splash.h"
  8. #include    "assoc.h"
  9.  
  10. void main()
  11. {
  12. char buf[80];
  13. ifstream fin("cis.log");
  14. int ln= 1, gotit= 0;
  15. Assoc<int> tot("", 0);
  16. Regexp reet("(..):(..):(..)"), remnth("^(..)/../..");
  17. Regexp r1("^(../../..) (..:..).. (.*)");
  18. SPString s;
  19.  
  20.     fin >> s;    // eat first line
  21.  
  22.     while(fin >> s){
  23.     ln++;
  24. //        cout << "line " << ln << ": <" << s << ">" << endl;
  25.  
  26.         SPStringList l;
  27.  
  28. //05/20/92 10:48PM CIS 2400 988-5366
  29. //05/21/92 09:24PM OFFLINE                                   00:00:06
  30.         if(s.m(r1, l)){
  31.             if(l.scalar() < 4){
  32.                 cerr << "Didn't match all expressions" << endl;
  33.                 exit(1);
  34.         }
  35. //            cout << "Expressions matched: " << endl << l << endl;
  36.         SPString a= l[3];
  37.         if(a.m("^CIS")) gotit= 1;
  38.         else if(a.m("^OFFLINE") && gotit){ // extract Elapsed time
  39.                 SPStringList et, mnth;
  40.                 int hr, mn, sc, tm;
  41.  
  42.         if(a.m(reet, et) != 4){
  43.             cerr << "Failed to extract Elapsed time" << endl;
  44.                     exit(1);
  45.         }
  46.                 hr= atoi(et[1]); mn= atoi(et[2]); sc= atoi(et[3]);
  47.                 tm= (hr*60) + mn + ((sc >= 30) ? 1 : 0);
  48.  
  49.         gotit= 0;
  50.         // extract month
  51.                 if(l[1].m(remnth, mnth) != 2){
  52.                     cerr << "Failed to extract Month" << endl;
  53.                     exit(1);
  54.                 }
  55.  
  56. //                cout << "Month: " << mnth[1] << " Elapsed Time = " << tm << " mins" << endl;
  57.         tot(mnth[1]) += tm;
  58.                                  
  59.             }else gotit= 0;
  60.             
  61.      }else{
  62.             cerr << "Didn't match any expressions" << endl;
  63.             exit(1);
  64.         }
  65.  
  66.     };
  67. //    cout << "tot = " << endl << tot << endl;
  68.     Assoc<SPString> months;
  69.     months("01")= "January"; months("02")= "February"; months("03")= "March";
  70.     months("04")= "April"; months("05")= "May"; months("06")= "June";
  71.     months("07")= "July"; months("08")= "August"; months("09")= "September";
  72.     months("10")= "October"; months("11")= "November"; months("12")= "December";
  73.  
  74.     for(int i=0;i<tot.scalar();i++)
  75.         cout << months(tot[i].key()) << ": " << tot[i].value() << " mins $"
  76.              << tot[i].value() * (12.50/60.0) << endl;
  77. }
  78.  
  79.