Subversion Repositories wimsdev

Rev

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