home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / duucp-1.17 / AU-117b4-src.lha / src / uucico / xferstat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-24  |  3.0 KB  |  165 lines

  1. /* Original by Andrew Kopp, modified by John Bickers */
  2. /* small mods for logging device, unit, and failed messages by Steve Drew */
  3.  
  4. #include "includes.h"
  5.  
  6. Prototype void xferinit (char *);
  7. Prototype void xferstat (char *phonenum, char *comment);
  8. Prototype void xferlog (char *, ...);
  9.  
  10. Prototype XferStat xfer;
  11.  
  12. XferStat xfer;
  13.  
  14. static const char
  15.     statname [] = "UUSpool:XferStat";
  16.  
  17. void
  18. xferinit (char *host)
  19. {
  20.     time_t
  21.         t;
  22.     char
  23.         proto [sizeof (xfer.proto)];
  24.  
  25.     memcpy (proto, xfer.proto, sizeof (proto));
  26.     memset (&xfer, 0, sizeof (xfer));
  27.     memcpy (xfer.proto, proto, sizeof (xfer.proto));
  28.     strncpy (xfer.host, host, sizeof (xfer.host) - 1);
  29.     t = time (NULL);
  30.     xfer.time_start = t;
  31.     xfer.time_stop    = t;
  32.  
  33.     return;
  34. }
  35.  
  36. void
  37. xferstat (char *phonenum, char *comment)
  38. {
  39.     FILE
  40.         *fo;
  41.     struct tm
  42.         st,
  43.         et;
  44.     long
  45.         hh,
  46.         mm,
  47.         ss,
  48.         calc,
  49.         fcalc,
  50.         perc;
  51.  
  52.     if (xfer.flags & XFERF_WRITTEN)
  53.         return;
  54.  
  55.     fo = fopen (statname, "a");
  56.     if (!fo)
  57.         return;
  58.  
  59.     xfer.flags |= XFERF_WRITTEN;   /* indicate output done */
  60.  
  61.       /* Indicator for type of link   */
  62.     fprintf (fo, "%c %-8s ", (xfer.flags & XFERF_OUTGOING) ? '<' : '>', xfer.host);
  63.  
  64.     st = *localtime (&xfer.time_start);
  65.     et = *localtime (&xfer.time_stop);
  66.  
  67.     fprintf (fo, "%02d-%02d-%02d %02d:%02d:%02d > ",
  68.         st.tm_mday, st.tm_mon + 1, st.tm_year,
  69.         st.tm_hour, st.tm_min, st.tm_sec);
  70.     fprintf (fo, "%02d-%02d-%02d %02d:%02d:%02d ",
  71.         et.tm_mday, et.tm_mon + 1, et.tm_year,
  72.         et.tm_hour, et.tm_min, et.tm_sec);
  73.  
  74.     hh = et.tm_hour - st.tm_hour;
  75.     if (hh < 0)
  76.         hh += 24;
  77.     mm = et.tm_min    - st.tm_min;
  78.     ss = et.tm_sec    - st.tm_sec;
  79.     if (ss < 0) {
  80.         ss += 60;
  81.         mm--;
  82.     }
  83.     if (mm < 0) {
  84.         mm += 60;
  85.         hh--;
  86.     }
  87.     if (hh < 0)
  88.         hh += 24;
  89.  
  90.     fprintf (fo, "(%02d:%02d:%02d)", hh, mm, ss);
  91.  
  92.     ss += (hh * 3600L) + (mm * 60L);
  93.  
  94.     calc = xfer.bytes_recv + xfer.bytes_send;
  95.     calc = ss ? (calc / ss) : 0L;
  96.     fprintf (fo, "%6ld", calc);
  97.  
  98.     fcalc = xfer.fbytes_recv + xfer.fbytes_send;
  99.     fcalc = ss ? (fcalc / ss) : 0L;
  100.     fprintf (fo," %6ld", fcalc);
  101.  
  102.     perc = calc ? ((100 * fcalc) / calc) : 0L;
  103.     fprintf (fo, " %3ld%%\n", perc);
  104.  
  105.     switch (xfer.proto [0]) {
  106.         case ('g'):
  107.         case ('G'):
  108.             {
  109.             int
  110.                 psize;
  111.  
  112.             psize = (1 << (xfer.proto [2] + 4));
  113.             fprintf (fo, "| %c %1d %4d", xfer.proto [0], xfer.proto [1], psize);
  114.             }
  115.             break;
  116.         default:
  117.             fprintf (fo, "| %c       ", xfer.proto [0]);
  118.     }
  119.  
  120.     fprintf (fo, " %8ld %8ld # %8ld %8ld # %4ld %4ld\n",
  121.         xfer.bytes_recv, xfer.bytes_send,
  122.         xfer.fbytes_recv, xfer.fbytes_send,
  123.         xfer.files_recv, xfer.files_send
  124.     );
  125.  
  126.     /*
  127.      * serial port, and comment passed from uucico mods by Steve Drew
  128.      */
  129.  
  130.     fprintf (fo, "| VIA device %s unit %d", DeviceName, DeviceUnit);
  131.     if (phonenum) {
  132.         fprintf (fo, " number %s\n", phonenum);
  133.     }
  134.     else {
  135.         fprintf (fo, "\n");
  136.     }
  137.  
  138.     if (comment) {
  139.         fprintf (fo, "%s\n", comment);
  140.     }
  141.  
  142.     fclose (fo);
  143.  
  144.     return;
  145. }
  146.  
  147. /* Perhaps put file handle into xfer? */
  148. void
  149. xferlog (char *cp, ...)
  150. {
  151.     FILE
  152.         *fo;
  153.     va_list
  154.         args;
  155.  
  156.     if (cp && (fo = fopen (statname, "a"))) {
  157.         va_start (args,cp);
  158.         vfprintf (fo, cp, args)
  159.         va_end (args);
  160.         fclose (fo);
  161.     }
  162.  
  163.     return;
  164. }
  165.