home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / sarg1221.zip / sort.c < prev    next >
C/C++ Source or Header  |  2002-10-11  |  2KB  |  91 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.  
  9. void tmpsort(const char *dirname, int debug, char *TempDir, char *TopuserSortField, char *UserSortField, char *TopuserSortOrder, char *UserSortOrder, int indexonly)
  10. {
  11.  
  12.    DIR *dirp;
  13.    struct dirent *direntp;
  14.  
  15.    char csort[MAXLEN];
  16.    char wentp[MAXLEN];
  17.    char arqou[MAXLEN], arqin[MAXLEN], wnome[MAXLEN], wnome2[MAXLEN];
  18.    char field1[10]="2,2";
  19.    char field2[10]="1,1";
  20.    char field3[10]="3,3";
  21.    char order[4]="-r";
  22.  
  23.    if(indexonly) return;
  24.    if(strstr(ReportType,"users_sites") == 0) return;
  25.  
  26.    wnome[0]='\0';
  27.    wnome2[0]='\0';
  28.  
  29.    dirp = opendir(dirname);
  30.    while ( (direntp = readdir( dirp )) != NULL ){
  31.       if(strstr(direntp->d_name,".tmp") == 0)
  32.          continue;
  33.  
  34.       strcpy(wentp,direntp->d_name);
  35.  
  36.       wnome[0]='\0'; 
  37.       striptmp:
  38.       getword(wnome2,wentp,'.');
  39.       strcat(wnome,wnome2);
  40.  
  41.       if(strcmp(wentp,"tmp") !=0) {
  42.          strcat(wnome,".");
  43.          goto striptmp;
  44.       }
  45.  
  46.       strcpy(arqou,dirname);
  47.       strcat(arqou,"/");
  48.       strcpy(arqin,arqou);
  49.       strcat(arqou,wnome);
  50.       strcat(arqin,direntp->d_name);
  51.  
  52.       if(debug) {
  53.          sprintf(msg,"%s: %s",text[54],arqou);
  54.          debuga(msg);
  55.       }
  56.  
  57.       strup(UserSortField);
  58.       strlow(UserSortOrder);
  59.  
  60.       if(strcmp(UserSortField,"CONNECT") == 0) {
  61.          strcpy(field1,"1,1");
  62.          strcpy(field2,"2,2");
  63.          strcpy(field3,"3,3");
  64.       }
  65.  
  66.       if(strcmp(UserSortField,"SITE") == 0) {
  67.          strcpy(field1,"3,3");
  68.          strcpy(field2,"2,2");
  69.          strcpy(field3,"1,1");
  70.       }
  71.  
  72.       if(strcmp(UserSortField,"TIME") == 0) {
  73.          strcpy(field1,"5,5");
  74.          strcpy(field2,"2,2");
  75.          strcpy(field3,"1,1");
  76.       }
  77.  
  78.       if(strcmp(UserSortOrder,"normal") == 0)
  79.          order[0]='\0';
  80.         
  81.       strcat(arqou,".txt");
  82.       sprintf(csort, SORT" -n -T %s %s -k %s -k %s -k %s -o %s %s",TempDir,order,field1,field2,field3,arqou,arqin);
  83.       system(csort);
  84.  
  85.       unlink(arqin);
  86.  
  87.    }
  88.    (void)closedir( dirp );
  89.    return;
  90. }
  91.