Subversion Repositories wimsdev

Rev

Rev 10 | Rev 8147 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10 Rev 7676
Line 13... Line 13...
13
 *  You should have received a copy of the GNU General Public License
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
14
 *  along with this program; if not, write to the Free Software
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 */
16
 */
17
 
17
 
18
        /* This is an internal program,
18
/* This is an internal program,
19
         * used to show statistics of frequentation, module by module. */
19
 * used to show statistics of frequentation, module by module. */
20
 
20
 
21
#include "../wims.h"
21
#include "../wims.h"
22
 
22
 
23
#define MAX_FLEN 102400
23
#define MAX_FLEN 102400
24
#define MAX_LANGS   16
24
#define MAX_LANGS   16
Line 38... Line 38...
38
void *xmalloc(size_t n)
38
void *xmalloc(size_t n)
39
{
39
{
40
    void *p;
40
    void *p;
41
    p=malloc(n);
41
    p=malloc(n);
42
    if(p==NULL) {
42
    if(p==NULL) {
43
        printf("Malloc failure.\n");
43
      printf("Malloc failure.\n");
44
        exit(1);
44
      exit(1);
45
    }
45
    }
46
    return p;
46
    return p;
47
}
47
}
48
 
48
 
49
        /* Points to the end of the word */
49
/* Points to the end of the word */
50
char *find_word_end(char *p)
50
char *find_word_end(char *p)
51
{
51
{
52
    int i;
52
    int i;
53
    for(i=0;!isspace(*p) && *p!=0 && i<MAX_LINELEN; p++,i++);
53
    for(i=0;!isspace(*p) && *p!=0 && i<MAX_LINELEN; p++,i++);
54
    return p;
54
    return p;
55
}
55
}
56
 
56
 
57
        /* Strips leading spaces */
57
/* Strips leading spaces */
58
char *find_word_start(char *p)
58
char *find_word_start(char *p)
59
{
59
{
60
    int i;
60
    int i;
61
    for(i=0; isspace(*p) && i<MAX_LINELEN; p++,i++);
61
    for(i=0; isspace(*p) && i<MAX_LINELEN; p++,i++);
62
    return p;
62
    return p;
63
}
63
}
64
 
64
 
65
        /* Find first occurrence of word */
65
/* Find first occurrence of word */
66
char *wordchr(char *p, char *w)
66
char *wordchr(char *p, char *w)
67
{
67
{
68
    char *r;
68
    char *r;
69
 
69
 
70
    for(r=strstr(p,w);r!=NULL &&
70
    for(r=strstr(p,w);r!=NULL &&
71
        ( (r>p && !isspace(*(r-1))) || (!isspace(*(r+strlen(w))) && *(r+strlen(w))!=0) );
71
      ( (r>p && !isspace(*(r-1))) || (!isspace(*(r+strlen(w))) && *(r+strlen(w))!=0) );
72
        r=strstr(r+1,w));
72
      r=strstr(r+1,w));
73
    return r;
73
    return r;
74
}
74
}
75
 
75
 
76
        /* find a variable in a string (math expression).
76
/* find a variable in a string (math expression).
77
         * Returns the pointer or NULL. */
77
 * Returns the pointer or NULL. */
78
char *varchr(char *p, char *v)
78
char *varchr(char *p, char *v)
79
{
79
{
80
    char *pp; int n=strlen(v);
80
    char *pp; int n=strlen(v);
81
    for(pp=strstr(p,v); pp!=NULL; pp=strstr(pp+1,v)) {
81
    for(pp=strstr(p,v); pp!=NULL; pp=strstr(pp+1,v)) {
82
        if((pp==p || !isalnum(*(pp-1))) &&
82
      if((pp==p || !isalnum(*(pp-1))) &&
83
           (!isalnum(*(pp+n)) || *(pp+n)==0)) break;
83
         (!isalnum(*(pp+n)) || *(pp+n)==0)) break;
84
    }
84
    }
85
    return pp;
85
    return pp;
86
}
86
}
87
 
87
 
88
        /* strip trailing spaces; return string end. */
88
/* strip trailing spaces; return string end. */
89
char *strip_trailing_spaces(char *p)
89
char *strip_trailing_spaces(char *p)
90
{
90
{
91
    char *pp;
91
    char *pp;
92
    if(*p==0) return p;
92
    if(*p==0) return p;
93
    for(pp=p+strlen(p)-1; pp>=p && isspace(*pp); *(pp--)=0);
93
    for(pp=p+strlen(p)-1; pp>=p && isspace(*pp); *(pp--)=0);
Line 95... Line 95...
95
}
95
}
96
 
96
 
97
void getlangs(void)
97
void getlangs(void)
98
{
98
{
99
    char *p;
99
    char *p;
100
   
100
 
101
    langs=getenv("w_wims_site_languages"); if(langs==NULL) langs="";
101
    langs=getenv("w_wims_site_languages"); if(langs==NULL) langs="";
102
    for(p=langs;strlen(p)>=2 && languagecnt<MAX_LANGS;
102
    for(p=langs;strlen(p)>=2 && languagecnt<MAX_LANGS;
103
        p=find_word_start(find_word_end(p))) {
103
      p=find_word_start(find_word_end(p))) {
104
        if(!isalpha(*p) || !isalpha(*(p+1))) continue;
104
      if(!isalpha(*p) || !isalpha(*(p+1))) continue;
105
        memmove(language[languagecnt],p,2);
105
      memmove(language[languagecnt],p,2);
106
        language[languagecnt][2]=0;
106
      language[languagecnt][2]=0;
107
        languagecnt++;
107
      languagecnt++;
108
    }
108
    }
109
}
109
}
110
 
110
 
111
int onefile(char *name)
111
int onefile(char *name)
112
{
112
{
113
    FILE *f;
113
    FILE *f;
114
    char *buf, *p, *pe, *p2, *p3;
114
    char *buf, *p, *pe, *p2, *p3;
115
    long int len,len2;
115
    long int len,len2;
116
    int s,i,j,k,t,u;
116
    int s,i,j,k,t,u;
117
   
117
 
118
    f=fopen(name,"r"); if(f==NULL) return 0;
118
    f=fopen(name,"r"); if(f==NULL) return 0;
119
    fseek(f,0,SEEK_END);len=ftell(f);
119
    fseek(f,0,SEEK_END);len=ftell(f);
120
    if(len<=0 || len>MAX_FLEN) return 0;
120
    if(len<=0 || len>MAX_FLEN) return 0;
121
    fseek(f,0,SEEK_SET);buf=xmalloc(len+1);
121
    fseek(f,0,SEEK_SET);buf=xmalloc(len+1);
122
    len2=fread(buf,1,len,f);
122
    len2=fread(buf,1,len,f);
123
    if(len2<=0 || len2>len) {
123
    if(len2<=0 || len2>len) {
124
        free(buf); return 0;
124
      free(buf); return 0;
125
    }
125
    }
126
    buf[len2]=0; fclose(f); s=t=u=0;
126
    buf[len2]=0; fclose(f); s=t=u=0;
127
    for(p=buf;p!=NULL && p<buf+len2;p=pe) {
127
    for(p=buf;p!=NULL && p<buf+len2;p=pe) {
128
        p=find_word_start(p); pe=strchr(p,'\n');
128
      p=find_word_start(p); pe=strchr(p,'\n');
129
        if(pe!=NULL) *pe++=0;
129
      if(pe!=NULL) *pe++=0;
130
        p2=find_word_end(p);
130
      p2=find_word_end(p);
131
        if(*p2!=0) *p2++=0;
131
      if(*p2!=0) *p2++=0;
132
        p2=find_word_start(p2);
132
      p2=find_word_start(p2);
133
        p3=find_word_start(find_word_end(p2));
133
      p3=find_word_start(find_word_end(p2));
134
        *find_word_end(p3)=0;
134
      *find_word_end(p3)=0;
135
        if(*p!=0) i=atoi(p); else i=0;
135
      if(*p!=0) i=atoi(p); else i=0;
136
        if(*p2!=0) j=atoi(p2); else j=0;
136
      if(*p2!=0) j=atoi(p2); else j=0;
137
        if(*p3!=0) k=atoi(p3); else k=0;
137
      if(*p3!=0) k=atoi(p3); else k=0;
138
        if(t==0 && i<mstart) mstart=i;
138
      if(t==0 && i<mstart) mstart=i;
139
        if(i>=start && i<=end) {s+=j; u+=k;}
139
      if(i>=start && i<=end) {s+=j; u+=k;}
140
        t=1;
140
      t=1;
141
    }
141
    }
142
    reqs+=s; sites+=u;
142
    reqs+=s; sites+=u;
143
    if(modtype==3) return u;
143
    if(modtype==3) return u;
144
    else return s;
144
    else return s;
145
}
145
}
146
 
146
 
147
void onemodule(char *mod)
147
void onemodule(char *mod)
148
{
148
{
149
    char ibuf[MAX_LINELEN+5];
149
    char ibuf[MAX_LINELEN+5];
150
    int i,k,sum;
150
    int i,k,sum;
151
   
151
 
152
    sum=reqs=sites=0;mstart=end;
152
    sum=reqs=sites=0;mstart=end;
153
    k=onefile(mod);sum+=k;
153
    k=onefile(mod);sum+=k;
154
    for(i=0;i<languagecnt;i++) {
154
    for(i=0;i<languagecnt;i++) {
155
        snprintf(ibuf,sizeof(ibuf),"%s.%s",mod,language[i]);
155
      snprintf(ibuf,sizeof(ibuf),"%s.%s",mod,language[i]);
156
        k=onefile(ibuf);sum+=k;
156
      k=onefile(ibuf);sum+=k;
157
        count[i]=k;
157
      count[i]=k;
158
    }
158
    }
159
    if(modtype!=2) tcount=sum;
159
    if(modtype!=2) tcount=sum;
160
    else {
160
    else {
161
        if(sites>0) tcount=(double) (100*reqs/sites+0.5);
161
      if(sites>0) tcount=(double) (100*reqs/sites+0.5);
162
        else tcount=0;
162
      else tcount=0;
163
    }
163
    }
164
}
164
}
165
       
165
 
166
int main()
166
int main()
167
{
167
{
168
    char mmbuf[MAX_LINELEN+1];
168
    char mmbuf[MAX_LINELEN+1];
169
    char *p1, *p2, *pp;
169
    char *p1, *p2, *pp;
170
    int i;
170
    int i;
171
   
171
 
172
    mlist=getenv("ll");
172
    mlist=getenv("ll");
173
    if(mlist==NULL || *mlist==0) return 1;
173
    if(mlist==NULL || *mlist==0) return 1;
174
    pp=getenv("start"); if(pp==NULL || *pp==0) return 1;
174
    pp=getenv("start"); if(pp==NULL || *pp==0) return 1;
175
    start=atoi(pp);
175
    start=atoi(pp);
176
    pp=getenv("end"); if(pp==NULL || *pp==0) return 1;
176
    pp=getenv("end"); if(pp==NULL || *pp==0) return 1;
177
    end=atoi(pp);
177
    end=atoi(pp);
178
    pp=getenv("w_module_type");
178
    pp=getenv("w_module_type");
179
    if(pp==NULL || (*pp!='2' && *pp!='3')) modtype=1; else modtype=*pp-'0';
179
    if(pp==NULL || (*pp!='2' && *pp!='3')) modtype=1; else modtype=*pp-'0';
180
    getlangs();
180
    getlangs();
181
    for(p1=find_word_start(mlist);*p1!=0 && !isspace(*p1); p1=find_word_start(p2)) {
181
    for(p1=find_word_start(mlist);*p1!=0 && !isspace(*p1); p1=find_word_start(p2)) {
182
        p2=find_word_end(p1);
182
      p2=find_word_end(p1);
183
        if(p2-p1>MAX_LINELEN) continue;
183
      if(p2-p1>MAX_LINELEN) continue;
184
        memmove(mmbuf,p1,p2-p1);mmbuf[p2-p1]=0;
184
      memmove(mmbuf,p1,p2-p1);mmbuf[p2-p1]=0;
185
        onemodule(mmbuf);
185
      onemodule(mmbuf);
186
        printf("%d %d %s",tcount,mstart,mmbuf);
186
      printf("%d %d %s",tcount,mstart,mmbuf);
187
        for(i=0;i<languagecnt;i++) printf(" %d",count[i]);
187
      for(i=0;i<languagecnt;i++) printf(" %d",count[i]);
188
        printf("\n");
188
      printf("\n");
189
    }
189
    }
190
    return 0;
190
    return 0;
191
}
191
}
192
 
192