home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / sarg1221.zip / convlog.c < prev    next >
C/C++ Source or Header  |  2002-06-13  |  1KB  |  52 lines

  1. /*
  2.  * sarg - Squid user management log
  3.  * Mar/98 - Pedro L Orso - orso@onda.com.br
  4.  */
  5.  
  6. #include "include/conf.h"
  7.  
  8. void convlog(char *arq, char *df, int dfrom, int duntil)
  9. {
  10.  
  11.    FILE *fp_in;
  12.    char buf[8192];
  13.    char data[30];
  14.    char dia[11];
  15.    char hora[9];
  16.    char wdata[20];
  17.    time_t tt;
  18.    int idata=0;
  19.    struct tm *t;
  20.  
  21.    if(arq[0] == '\0')
  22.       strcpy(arq,"/usr/local/squid/logs/access.log");
  23.  
  24.    if((fp_in=fopen(arq,"r"))==NULL) {
  25.       fprintf(stderr, "SARG: (convlog) %s: %s\n",text[8],arq);
  26.       exit(1);
  27.    }
  28.  
  29.    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
  30.       getword(data,buf,' ');
  31.       tt=atoi(data);
  32.       t=localtime(&tt);
  33.  
  34.       if(dfrom) {
  35.          strftime(wdata, 127, "%Y%m%d", t);
  36.          idata=atoi(wdata);
  37.      if(idata < dfrom || idata > duntil)
  38.          continue;
  39.       }
  40.  
  41.       if(strncmp(df,"e",1) == 0)
  42.          strftime(dia, 127, "%d/%m/%Y", t);
  43.        else
  44.          strftime(dia, 127, "%m/%d/%Y", t);
  45.       sprintf(hora,"%02d:%02d:%02d",t->tm_hour,t->tm_min,t->tm_sec);
  46.  
  47.       printf("%s %s %s",dia,hora,buf);
  48.    }
  49.  
  50.    fclose(fp_in);
  51. }
  52.