Subversion Repositories wimsdev

Rev

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
    FILE *f;
36
  FILE *f;
37
    long int flen;
37
  long int flen;
38
 
38
 
39
    filelen=0;
39
  filelen=0;
40
    f=fopen(filename,"r"); if(f==NULL) return;
40
  f=fopen(filename,"r"); if(f==NULL) return;
41
    fseek(f,0,SEEK_END);flen=ftell(f); fseek(f,0,SEEK_SET);
41
  fseek(f,0,SEEK_END);flen=ftell(f); fseek(f,0,SEEK_SET);
42
    if(flen>buflim) return;
42
  if(flen>buflim) return;
43
    filebuf=xmalloc(2*flen+1024);flen=fread(filebuf,1,flen,f);
43
  filebuf=xmalloc(2*flen+1024);flen=fread(filebuf,1,flen,f);
44
    fclose(f);
44
  fclose(f);
45
    if(flen>0 && flen<buflim) filebuf[flen]=0; else flen=0;
45
  if(flen>0 && flen<buflim) filebuf[flen]=0; else flen=0;
46
    filelen=flen;
46
  filelen=flen;
47
}
47
}
48
 
48
 
49
int main(int argc, char *argv[])
49
int main(int argc, char *argv[])
50
{
50
{
51
    char *ftype="text";
51
  char *ftype="text";
52
    char *p;
52
  char *p;
53
    char *mod, *unt;
53
  char *mod, *unt;
54
 
54
 
55
    unt=getenv("untrust");
55
  unt=getenv("untrust");
56
    if(unt!=NULL && strcasecmp(unt,"yes")==0) return 1;
56
  if(unt!=NULL && strcasecmp(unt,"yes")==0) return 1;
57
    mod=getenv("w_module");
57
  mod=getenv("w_module");
58
    if(mod==NULL) p=argv[1]; else p=getenv("wims_exec_parm");
58
  if(mod==NULL) p=argv[1]; else p=getenv("wims_exec_parm");
59
    if(p==NULL || *p==0) return 1;
59
  if(p==NULL || *p==0) return 1;
60
    snprintf(filename,sizeof(filename)-128,"%s",p);
60
  snprintf(filename,sizeof(filename)-128,"%s",p);
61
    prepare_file();
61
  prepare_file();
62
    for(p=filebuf;p<filebuf+filelen;p++) {
62
  for(p=filebuf;p<filebuf+filelen;p++) {
63
      if((*p>=0 && *p<=6) || (127&*p)<=1)
63
    if((*p>=0 && *p<=6) || (127&*p)<=1)
64
          {ftype="binary"; goto fin;}
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
    if(strstr(filebuf,"\\begin{")!=NULL ||
76
  if(strstr(filebuf,"\\begin{")!=NULL ||
77
       strstr(filebuf,"\\end{")!=NULL ||
77
     strstr(filebuf,"\\end{")!=NULL ||
78
       (strchr(filebuf,'$')!=NULL && strchr(filebuf,'\\')!=NULL &&
78
     (strchr(filebuf,'$')!=NULL && strchr(filebuf,'\\')!=NULL &&
79
      strchr(filebuf,'{')!=NULL)) {
79
    strchr(filebuf,'{')!=NULL)) {
80
      ftype="latex"; goto fin;
80
    ftype="latex"; goto fin;
81
    }
81
  }
82
    fin: printf("%s",ftype);
82
  fin: printf("%s",ftype);
83
    return 0;
83
  return 0;
84
}
84
}
85
 
-