Back to index

wims  3.65+svn20090927
Defines | Functions | Variables
modstat.c File Reference
#include "../wims.h"

Go to the source code of this file.

Defines

#define MAX_FLEN   102400
#define MAX_LANGS   16

Functions

void * xmalloc (size_t n)
char * find_word_end (char *p)
char * find_word_start (char *p)
char * wordchr (char *p, char *w)
char * varchr (char *p, char *v)
char * strip_trailing_spaces (char *p)
void getlangs (void)
int onefile (char *name)
void onemodule (char *mod)
int main ()

Variables

char mbuf [MAX_LINELEN+1]
char mbase [MAX_LINELEN+1]
char indexfile [MAX_LINELEN+1]
char modify_time [1024]
char vbuf [MAX_LINELEN+1]
char * tlist
char * mlist
char * slist
char * langs
char language [MAX_LANGS][4]
int start
int end
int mstart
int mend
int modtype
int reqs
int sites
int languagecnt = 0
int count [MAX_LANGS]
int tcount

Define Documentation

#define MAX_FLEN   102400

Definition at line 23 of file modstat.c.

#define MAX_LANGS   16

Definition at line 24 of file modstat.c.


Function Documentation

char* find_word_end ( char *  p)

Definition at line 50 of file modstat.c.

{
    int i;
    for(i=0;!isspace(*p) && *p!=0 && i<MAX_LINELEN; p++,i++);
    return p;
}
char* find_word_start ( char *  p)

Definition at line 58 of file modstat.c.

{
    int i;
    for(i=0; isspace(*p) && i<MAX_LINELEN; p++,i++);
    return p;
}
void getlangs ( void  )

Definition at line 97 of file modstat.c.

{
    char *p;
    
    langs=getenv("w_wims_site_languages"); if(langs==NULL) langs="";
    for(p=langs;strlen(p)>=2 && languagecnt<MAX_LANGS;
       p=find_word_start(find_word_end(p))) {
       if(!isalpha(*p) || !isalpha(*(p+1))) continue;
       memmove(language[languagecnt],p,2);
       language[languagecnt][2]=0;
       languagecnt++;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( void  )

Definition at line 166 of file modstat.c.

{
    char mmbuf[MAX_LINELEN+1];
    char *p1, *p2, *pp;
    int i;
    
    mlist=getenv("ll");
    if(mlist==NULL || *mlist==0) return 1;
    pp=getenv("start"); if(pp==NULL || *pp==0) return 1;
    start=atoi(pp);
    pp=getenv("end"); if(pp==NULL || *pp==0) return 1;
    end=atoi(pp);
    pp=getenv("w_module_type"); 
    if(pp==NULL || (*pp!='2' && *pp!='3')) modtype=1; else modtype=*pp-'0';
    getlangs();
    for(p1=find_word_start(mlist);*p1!=0 && !isspace(*p1); p1=find_word_start(p2)) {
       p2=find_word_end(p1);
       if(p2-p1>MAX_LINELEN) continue;
       memmove(mmbuf,p1,p2-p1);mmbuf[p2-p1]=0;
       onemodule(mmbuf);
       printf("%d %d %s",tcount,mstart,mmbuf);
       for(i=0;i<languagecnt;i++) printf(" %d",count[i]);
       printf("\n");
    }
    return 0;
}

Here is the call graph for this function:

int onefile ( char *  name)

Definition at line 111 of file modstat.c.

{
    FILE *f;
    char *buf, *p, *pe, *p2, *p3;
    long int len,len2;
    int s,i,j,k,t,u;
    
    f=fopen(name,"r"); if(f==NULL) return 0;
    fseek(f,0,SEEK_END);len=ftell(f);
    if(len<=0 || len>MAX_FLEN) return 0;
    fseek(f,0,SEEK_SET);buf=xmalloc(len+1);
    len2=fread(buf,1,len,f);
    if(len2<=0 || len2>len) {
       free(buf); return 0;
    }
    buf[len2]=0; fclose(f); s=t=u=0;
    for(p=buf;p!=NULL && p<buf+len2;p=pe) {
       p=find_word_start(p); pe=strchr(p,'\n');
       if(pe!=NULL) *pe++=0;
       p2=find_word_end(p);
       if(*p2!=0) *p2++=0;
       p2=find_word_start(p2);
       p3=find_word_start(find_word_end(p2));
       *find_word_end(p3)=0;
       if(*p!=0) i=atoi(p); else i=0;
       if(*p2!=0) j=atoi(p2); else j=0;
       if(*p3!=0) k=atoi(p3); else k=0;
       if(t==0 && i<mstart) mstart=i;
       if(i>=start && i<=end) {s+=j; u+=k;}
       t=1;
    }
    reqs+=s; sites+=u;
    if(modtype==3) return u;
    else return s;
}

Here is the call graph for this function:

void onemodule ( char *  mod)

Definition at line 147 of file modstat.c.

{
    char ibuf[MAX_LINELEN+5];
    int i,k,sum;
    
    sum=reqs=sites=0;mstart=end;
    k=onefile(mod);sum+=k;
    for(i=0;i<languagecnt;i++) {
       snprintf(ibuf,sizeof(ibuf),"%s.%s",mod,language[i]);
       k=onefile(ibuf);sum+=k;
       count[i]=k;
    }
    if(modtype!=2) tcount=sum;
    else {
       if(sites>0) tcount=(double) (100*reqs/sites+0.5);
       else tcount=0;
    }
}

Here is the call graph for this function:

char* strip_trailing_spaces ( char *  p)

Definition at line 89 of file modstat.c.

{
    char *pp;
    if(*p==0) return p;
    for(pp=p+strlen(p)-1; pp>=p && isspace(*pp); *(pp--)=0);
    return pp;
}
char* varchr ( char *  p,
char *  v 
)

Definition at line 78 of file modstat.c.

{
    char *pp; int n=strlen(v);
    for(pp=strstr(p,v); pp!=NULL; pp=strstr(pp+1,v)) {
       if((pp==p || !isalnum(*(pp-1))) &&
          (!isalnum(*(pp+n)) || *(pp+n)==0)) break;
    }
    return pp;
}
char* wordchr ( char *  p,
char *  w 
)

Definition at line 66 of file modstat.c.

{
    char *r;

    for(r=strstr(p,w);r!=NULL && 
       ( (r>p && !isspace(*(r-1))) || (!isspace(*(r+strlen(w))) && *(r+strlen(w))!=0) );
       r=strstr(r+1,w));
    return r;
}
void* xmalloc ( size_t  n)

Definition at line 38 of file modstat.c.

{
    void *p;
    p=malloc(n);
    if(p==NULL) {
       printf("Malloc failure.\n");
       exit(1);
    }
    return p;
}

Variable Documentation

Definition at line 36 of file modstat.c.

int end

Definition at line 34 of file modstat.c.

Definition at line 27 of file modstat.c.

char* langs

Definition at line 31 of file modstat.c.

char language[MAX_LANGS][4]

Definition at line 32 of file modstat.c.

int languagecnt = 0

Definition at line 35 of file modstat.c.

char mbase[MAX_LINELEN+1]

Definition at line 26 of file modstat.c.

char mbuf[MAX_LINELEN+1]

Definition at line 25 of file modstat.c.

int mend

Definition at line 34 of file modstat.c.

char * mlist

Definition at line 30 of file modstat.c.

char modify_time[1024]

Definition at line 28 of file modstat.c.

int modtype

Definition at line 34 of file modstat.c.

int mstart

Definition at line 34 of file modstat.c.

int reqs

Definition at line 34 of file modstat.c.

int sites

Definition at line 34 of file modstat.c.

char * slist

Definition at line 30 of file modstat.c.

int start

Definition at line 34 of file modstat.c.

int tcount

Definition at line 36 of file modstat.c.

char* tlist

Definition at line 30 of file modstat.c.

char vbuf[MAX_LINELEN+1]

Definition at line 29 of file modstat.c.