Subversion Repositories wimsdev

Rev

Rev 8185 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 reyssat 1
/*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
2
 *
3
 *  This program is free software; you can redistribute it and/or modify
4
 *  it under the terms of the GNU General Public License as published by
5
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  (at your option) any later version.
7
 *
8
 *  This program is distributed in the hope that it will be useful,
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  GNU General Public License for more details.
12
 *
13
 *  You should have received a copy of the GNU General Public License
14
 *  along with this program; if not, write to the Free Software
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 */
17
 
7676 bpr 18
/* This is an internal program,
19
 * used to show statistics of frequentation, module by module. */
10 reyssat 20
 
8147 bpr 21
#include "../Lib/libwims.h"
8185 bpr 22
 
10 reyssat 23
#define MAX_FLEN 102400
8185 bpr 24
#define MAX_LANGS MAX_LANGUAGES /*#define MAX_LANGS   16*/
10 reyssat 25
char mbuf[MAX_LINELEN+1];
26
char mbase[MAX_LINELEN+1];
27
char indexfile[MAX_LINELEN+1];
28
char modify_time[1024];
29
char vbuf[MAX_LINELEN+1];
30
char *tlist, *mlist, *slist; /* fields, modules, sqled modules */
31
char *langs; /* site languages */
32
char language[MAX_LANGS][4];
33
 
34
int start,end,mstart,mend,modtype,reqs,sites;
35
int languagecnt=0;
36
int count[MAX_LANGS],tcount;
37
 
38
void getlangs(void)
39
{
12248 bpr 40
  char *p;
7676 bpr 41
 
12248 bpr 42
  langs=getenv("w_wims_site_languages"); if(langs==NULL) langs="";
43
  for(p=langs;strlen(p)>=2 && languagecnt<MAX_LANGS;
7676 bpr 44
      p=find_word_start(find_word_end(p))) {
12248 bpr 45
    if(!isalpha(*p) || !isalpha(*(p+1))) continue;
46
    memmove(language[languagecnt],p,2);
47
    language[languagecnt][2]=0;
48
    languagecnt++;
49
  }
10 reyssat 50
}
51
 
52
int onefile(char *name)
53
{
12248 bpr 54
  FILE *f;
55
  char *buf, *p, *pe, *p2, *p3;
56
  long int len,len2;
57
  int s,i,j,k,t,u;
7676 bpr 58
 
12248 bpr 59
  f=fopen(name,"r"); if(f==NULL) return 0;
60
  fseek(f,0,SEEK_END);len=ftell(f);
61
  if(len<=0 || len>MAX_FLEN) return 0;
62
  fseek(f,0,SEEK_SET);buf=xmalloc(len+1);
63
  len2=fread(buf,1,len,f);
64
  if(len2<=0 || len2>len) {
65
    free(buf); return 0;
66
  }
67
  buf[len2]=0; fclose(f); s=t=u=0;
68
  for(p=buf;p!=NULL && p<buf+len2;p=pe) {
69
    p=find_word_start(p); pe=strchr(p,'\n');
70
    if(pe!=NULL) *pe++=0;
71
    p2=find_word_end(p);
72
    if(*p2!=0) *p2++=0;
73
    p2=find_word_start(p2);
74
    p3=find_word_start(find_word_end(p2));
75
    *find_word_end(p3)=0;
76
    if(*p!=0) i=atoi(p); else i=0;
77
    if(*p2!=0) j=atoi(p2); else j=0;
78
    if(*p3!=0) k=atoi(p3); else k=0;
79
    if(t==0 && i<mstart) mstart=i;
7676 bpr 80
      if(i>=start && i<=end) {s+=j; u+=k;}
81
      t=1;
12248 bpr 82
  }
83
  reqs+=s; sites+=u;
84
  if(modtype==3) return u;
85
  else return s;
10 reyssat 86
}
87
 
88
void onemodule(char *mod)
89
{
12248 bpr 90
  char ibuf[MAX_LINELEN+5];
91
  int i,k,sum;
7676 bpr 92
 
12248 bpr 93
  sum=reqs=sites=0;mstart=end;
94
  k=onefile(mod);sum+=k;
95
  for(i=0;i<languagecnt;i++) {
96
    snprintf(ibuf,sizeof(ibuf),"%s.%s",mod,language[i]);
97
    k=onefile(ibuf);sum+=k;
98
    count[i]=k;
99
  }
100
  if(modtype!=2) tcount=sum;
101
  else {
102
    if(sites>0) tcount=(double) (100*reqs/sites+0.5);
103
    else tcount=0;
104
  }
10 reyssat 105
}
7676 bpr 106
 
10 reyssat 107
int main()
108
{
12248 bpr 109
  char mmbuf[MAX_LINELEN+1];
110
  char *p1, *p2, *pp;
111
  int i;
7676 bpr 112
 
12248 bpr 113
  mlist=getenv("ll");
114
  if(mlist==NULL || *mlist==0) return 1;
115
  pp=getenv("start"); if(pp==NULL || *pp==0) return 1;
116
  start=atoi(pp);
117
  pp=getenv("end"); if(pp==NULL || *pp==0) return 1;
118
  end=atoi(pp);
119
  pp=getenv("w_module_type");
120
  if(pp==NULL || (*pp!='2' && *pp!='3')) modtype=1; else modtype=*pp-'0';
121
  getlangs();
122
  for(p1=find_word_start(mlist);*p1!=0 && !isspace(*p1); p1=find_word_start(p2)) {
123
    p2=find_word_end(p1);
124
    if(p2-p1>MAX_LINELEN) continue;
125
    memmove(mmbuf,p1,p2-p1);mmbuf[p2-p1]=0;
126
    onemodule(mmbuf);
127
    printf("%d %d %s",tcount,mstart,mmbuf);
128
    for(i=0;i<languagecnt;i++) printf(" %d",count[i]);
129
    printf("\n");
130
  }
131
  return 0;
10 reyssat 132
}
133