Rev 8185 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8185 | Rev 12248 | ||
---|---|---|---|
Line 31... | Line 31... | ||
31 | int filelen=0; |
31 | int filelen=0; |
32 | 32 | ||
33 | /* get the file */ |
33 | /* get the file */ |
34 | void prepare_file(void) |
34 | void prepare_file(void) |
35 | { |
35 | { |
36 |
|
36 | FILE *f; |
37 |
|
37 | long int flen; |
38 | 38 | ||
39 |
|
39 | filelen=0; |
40 |
|
40 | f=fopen(filename,"r"); if(f==NULL) return; |
41 |
|
41 | fseek(f,0,SEEK_END);flen=ftell(f); fseek(f,0,SEEK_SET); |
42 |
|
42 | if(flen>buflim) return; |
43 |
|
43 | filebuf=xmalloc(2*flen+1024);flen=fread(filebuf,1,flen,f); |
44 |
|
44 | fclose(f); |
45 |
|
45 | if(flen>0 && flen<buflim) filebuf[flen]=0; else flen=0; |
46 |
|
46 | filelen=flen; |
47 | } |
47 | } |
48 | 48 | ||
49 | int main(int argc, char *argv[]) |
49 | int main(int argc, char *argv[]) |
50 | { |
50 | { |
51 |
|
51 | char *ftype="text"; |
52 |
|
52 | char *p; |
53 |
|
53 | char *mod, *unt; |
54 | 54 | ||
55 |
|
55 | unt=getenv("untrust"); |
56 |
|
56 | if(unt!=NULL && strcasecmp(unt,"yes")==0) return 1; |
57 |
|
57 | mod=getenv("w_module"); |
58 |
|
58 | if(mod==NULL) p=argv[1]; else p=getenv("wims_exec_parm"); |
59 |
|
59 | if(p==NULL || *p==0) return 1; |
60 |
|
60 | snprintf(filename,sizeof(filename)-128,"%s",p); |
61 |
|
61 | prepare_file(); |
62 |
|
62 | for(p=filebuf;p<filebuf+filelen;p++) { |
63 |
|
63 | if((*p>=0 && *p<=6) || (127&*p)<=1) |
64 |
|
64 | {ftype="binary"; goto fin;} |
- | 65 | } |
|
- | 66 | for(p=strchr(filebuf,'<'); p!=NULL; p=strchr(p,'<')) { |
|
- | 67 | p++; |
|
- | 68 | if((strncasecmp(p,"body",4)==0 && !isalnum(*(p+4))) || |
|
- | 69 | (strncasecmp(p,"html",4)==0 && !isalnum(*(p+4))) || |
|
- | 70 | (strncasecmp(p,"img",3)==0 && isspace(*(p+3))) || |
|
- | 71 | strncasecmp(p,"p>",2)==0 || |
|
- | 72 | strncasecmp(p,"/a>",3)==0) { |
|
- | 73 | ftype="html"; goto fin; |
|
65 | } |
74 | } |
66 | for(p=strchr(filebuf,'<'); p!=NULL; p=strchr(p,'<')) { |
- | |
67 | p++; |
- | |
68 | if((strncasecmp(p,"body",4)==0 && !isalnum(*(p+4))) || |
- | |
69 | (strncasecmp(p,"html",4)==0 && !isalnum(*(p+4))) || |
- | |
70 | (strncasecmp(p,"img",3)==0 && isspace(*(p+3))) || |
- | |
71 | strncasecmp(p,"p>",2)==0 || |
- | |
72 | strncasecmp(p,"/a>",3)==0) { |
- | |
73 | ftype="html"; goto fin; |
- | |
74 | } |
- | |
75 |
|
75 | } |
76 |
|
76 | if(strstr(filebuf,"\\begin{")!=NULL || |
77 |
|
77 | strstr(filebuf,"\\end{")!=NULL || |
78 |
|
78 | (strchr(filebuf,'$')!=NULL && strchr(filebuf,'\\')!=NULL && |
79 |
|
79 | strchr(filebuf,'{')!=NULL)) { |
80 |
|
80 | ftype="latex"; goto fin; |
81 |
|
81 | } |
82 |
|
82 | fin: printf("%s",ftype); |
83 |
|
83 | return 0; |
84 | } |
84 | } |
85 | - |