home *** CD-ROM | disk | FTP | other *** search
/ Toolkit for DOOM / DOOMTOOL.ISO / net_doom / ihhd.zip / showlog.c < prev    next >
C/C++ Source or Header  |  1994-02-20  |  1KB  |  65 lines

  1. #include <sys/time.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include <ctype.h>
  5.  
  6. /*
  7.  * showlog - display the content of a dialer created log file
  8.  *
  9.  * usage: showlog logfile
  10.  */
  11.  
  12. static char* sccsid = "@(#)showlog.c    1.2    5/13/93";
  13.  
  14. main(argc, argv)
  15.     int argc;
  16.     char** argv;
  17. {
  18.     FILE* logf = fopen(*++argv, "r");
  19.     struct timeval tv;
  20.     struct tm* tm;
  21.     unsigned char buf[1024];
  22.     int bytecount;
  23.     int i;
  24.  
  25.     if (!logf) {
  26.         fprintf(stderr, "cannot open %s\n", *argv);
  27.         exit(1);
  28.     }
  29.  
  30.     while (fread(&tv, sizeof(tv), 1, logf)) {
  31.         tm = localtime((time_t*)&tv.tv_sec);
  32.  
  33.         printf("%02.2d:%02.2d:%02.2d.%06.6d: ",tm->tm_hour, tm->tm_min, tm->tm_sec,
  34.                tv.tv_usec);
  35.  
  36.         if (!fread(&bytecount, sizeof(bytecount), 1, logf)) {
  37.             fprintf(stderr, "premature EOF\n");
  38.             exit(1);
  39.         }
  40.         printf("%d bytes: ", bytecount);
  41.  
  42.         if (fread(buf, sizeof(char), bytecount, logf) != bytecount) {
  43.             fprintf(stderr, "premature EOF\n");
  44.             exit(1);
  45.         }
  46.  
  47.         for (i = 0; i < bytecount; i++) {
  48.             if (buf[i] > 0177) {
  49.                 printf("M-");
  50.                 buf[i] &= 0177;
  51.             }
  52.             if (iscntrl(buf[i])) {
  53.                 printf("^");
  54.                 buf[i] = (buf[i] + '@') & 0177;
  55.             }
  56.             if (isprint(buf[i]))
  57.                 printf("%c", buf[i]);
  58.             else
  59.                 fprintf(stderr, "unprintable char???");
  60.         }
  61.  
  62.         printf("\n");
  63.     }
  64. }
  65.