Rev 8185 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8185 | Rev 12248 | ||
---|---|---|---|
Line 35... | Line 35... | ||
35 | int languagecnt=0; |
35 | int languagecnt=0; |
36 | int count[MAX_LANGS],tcount; |
36 | int count[MAX_LANGS],tcount; |
37 | 37 | ||
38 | void getlangs(void) |
38 | void getlangs(void) |
39 | { |
39 | { |
40 |
|
40 | char *p; |
41 | 41 | ||
42 |
|
42 | langs=getenv("w_wims_site_languages"); if(langs==NULL) langs=""; |
43 |
|
43 | for(p=langs;strlen(p)>=2 && languagecnt<MAX_LANGS; |
44 | p=find_word_start(find_word_end(p))) { |
44 | p=find_word_start(find_word_end(p))) { |
45 |
|
45 | if(!isalpha(*p) || !isalpha(*(p+1))) continue; |
46 |
|
46 | memmove(language[languagecnt],p,2); |
47 |
|
47 | language[languagecnt][2]=0; |
48 |
|
48 | languagecnt++; |
49 |
|
49 | } |
50 | } |
50 | } |
51 | 51 | ||
52 | int onefile(char *name) |
52 | int onefile(char *name) |
53 | { |
53 | { |
54 |
|
54 | FILE *f; |
55 |
|
55 | char *buf, *p, *pe, *p2, *p3; |
56 |
|
56 | long int len,len2; |
57 |
|
57 | int s,i,j,k,t,u; |
58 | 58 | ||
59 |
|
59 | f=fopen(name,"r"); if(f==NULL) return 0; |
60 |
|
60 | fseek(f,0,SEEK_END);len=ftell(f); |
61 |
|
61 | if(len<=0 || len>MAX_FLEN) return 0; |
62 |
|
62 | fseek(f,0,SEEK_SET);buf=xmalloc(len+1); |
63 |
|
63 | len2=fread(buf,1,len,f); |
64 |
|
64 | if(len2<=0 || len2>len) { |
65 |
|
65 | free(buf); return 0; |
66 |
|
66 | } |
67 |
|
67 | buf[len2]=0; fclose(f); s=t=u=0; |
68 |
|
68 | for(p=buf;p!=NULL && p<buf+len2;p=pe) { |
69 |
|
69 | p=find_word_start(p); pe=strchr(p,'\n'); |
70 |
|
70 | if(pe!=NULL) *pe++=0; |
71 |
|
71 | p2=find_word_end(p); |
72 |
|
72 | if(*p2!=0) *p2++=0; |
73 |
|
73 | p2=find_word_start(p2); |
74 |
|
74 | p3=find_word_start(find_word_end(p2)); |
75 |
|
75 | *find_word_end(p3)=0; |
76 |
|
76 | if(*p!=0) i=atoi(p); else i=0; |
77 |
|
77 | if(*p2!=0) j=atoi(p2); else j=0; |
78 |
|
78 | if(*p3!=0) k=atoi(p3); else k=0; |
79 |
|
79 | if(t==0 && i<mstart) mstart=i; |
80 | if(i>=start && i<=end) {s+=j; u+=k;} |
80 | if(i>=start && i<=end) {s+=j; u+=k;} |
81 | t=1; |
81 | t=1; |
82 |
|
82 | } |
83 |
|
83 | reqs+=s; sites+=u; |
84 |
|
84 | if(modtype==3) return u; |
85 |
|
85 | else return s; |
86 | } |
86 | } |
87 | 87 | ||
88 | void onemodule(char *mod) |
88 | void onemodule(char *mod) |
89 | { |
89 | { |
90 |
|
90 | char ibuf[MAX_LINELEN+5]; |
91 |
|
91 | int i,k,sum; |
92 | 92 | ||
93 |
|
93 | sum=reqs=sites=0;mstart=end; |
94 |
|
94 | k=onefile(mod);sum+=k; |
95 |
|
95 | for(i=0;i<languagecnt;i++) { |
96 |
|
96 | snprintf(ibuf,sizeof(ibuf),"%s.%s",mod,language[i]); |
97 |
|
97 | k=onefile(ibuf);sum+=k; |
98 |
|
98 | count[i]=k; |
99 |
|
99 | } |
100 |
|
100 | if(modtype!=2) tcount=sum; |
101 |
|
101 | else { |
102 |
|
102 | if(sites>0) tcount=(double) (100*reqs/sites+0.5); |
103 |
|
103 | else tcount=0; |
104 |
|
104 | } |
105 | } |
105 | } |
106 | 106 | ||
107 | int main() |
107 | int main() |
108 | { |
108 | { |
109 |
|
109 | char mmbuf[MAX_LINELEN+1]; |
110 |
|
110 | char *p1, *p2, *pp; |
111 |
|
111 | int i; |
112 | 112 | ||
113 |
|
113 | mlist=getenv("ll"); |
114 |
|
114 | if(mlist==NULL || *mlist==0) return 1; |
115 |
|
115 | pp=getenv("start"); if(pp==NULL || *pp==0) return 1; |
116 |
|
116 | start=atoi(pp); |
117 |
|
117 | pp=getenv("end"); if(pp==NULL || *pp==0) return 1; |
118 |
|
118 | end=atoi(pp); |
119 |
|
119 | pp=getenv("w_module_type"); |
120 |
|
120 | if(pp==NULL || (*pp!='2' && *pp!='3')) modtype=1; else modtype=*pp-'0'; |
121 |
|
121 | getlangs(); |
122 |
|
122 | for(p1=find_word_start(mlist);*p1!=0 && !isspace(*p1); p1=find_word_start(p2)) { |
123 |
|
123 | p2=find_word_end(p1); |
124 |
|
124 | if(p2-p1>MAX_LINELEN) continue; |
125 |
|
125 | memmove(mmbuf,p1,p2-p1);mmbuf[p2-p1]=0; |
126 |
|
126 | onemodule(mmbuf); |
127 |
|
127 | printf("%d %d %s",tcount,mstart,mmbuf); |
128 |
|
128 | for(i=0;i<languagecnt;i++) printf(" %d",count[i]); |
129 |
|
129 | printf("\n"); |
130 |
|
130 | } |
131 |
|
131 | return 0; |
132 | } |
132 | } |
133 | 133 |