Subversion Repositories wimsdev

Rev

Rev 7676 | Rev 8185 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 reyssat 1
/*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
2
 *
3
 *  This program is free software; you can redistribute it and/or modify
4
 *  it under the terms of the GNU General Public License as published by
5
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  (at your option) any later version.
7
 *
8
 *  This program is distributed in the hope that it will be useful,
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  GNU General Public License for more details.
12
 *
13
 *  You should have received a copy of the GNU General Public License
14
 *  along with this program; if not, write to the Free Software
15
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 */
17
 
7676 bpr 18
/* Check type of a file */
10 reyssat 19
 
20
/*************** Customization: change values hereafter ****************/
21
 
7676 bpr 22
/* limit of data buffers */
10 reyssat 23
#define buflim 1024*1024*16
24
 
25
/***************** Nothing should need change hereafter *****************/
26
 
27
#include "../wims.h"
8147 bpr 28
#include "../Lib/libwims.h"
10 reyssat 29
 
30
char filename[1024]="";
31
char *filebuf;
32
int filelen=0;
33
 
7676 bpr 34
/* get the file */
10 reyssat 35
void prepare_file(void)
36
{
37
    FILE *f;
38
    long int flen;
39
 
40
    filelen=0;
41
    f=fopen(filename,"r"); if(f==NULL) return;
42
    fseek(f,0,SEEK_END);flen=ftell(f); fseek(f,0,SEEK_SET);
43
    if(flen>buflim) return;
44
    filebuf=xmalloc(2*flen+1024);flen=fread(filebuf,1,flen,f);
45
    fclose(f);
46
    if(flen>0 && flen<buflim) filebuf[flen]=0; else flen=0;
47
    filelen=flen;
48
}
49
 
50
int main(int argc, char *argv[])
51
{
52
    char *ftype="text";
53
    char *p;
54
    char *mod, *unt;
55
 
56
    unt=getenv("untrust");
57
    if(unt!=NULL && strcasecmp(unt,"yes")==0) return 1;
58
    mod=getenv("w_module");
59
    if(mod==NULL) p=argv[1]; else p=getenv("wims_exec_parm");
60
    if(p==NULL || *p==0) return 1;
61
    snprintf(filename,sizeof(filename)-128,"%s",p);
62
    prepare_file();
63
    for(p=filebuf;p<filebuf+filelen;p++) {
7676 bpr 64
      if((*p>=0 && *p<=6) || (127&*p)<=1)
65
          {ftype="binary"; goto fin;}
10 reyssat 66
    }
67
    for(p=strchr(filebuf,'<'); p!=NULL; p=strchr(p,'<')) {
7676 bpr 68
      p++;
69
      if((strncasecmp(p,"body",4)==0 && !isalnum(*(p+4))) ||
70
         (strncasecmp(p,"html",4)==0 && !isalnum(*(p+4))) ||
71
         (strncasecmp(p,"img",3)==0 && isspace(*(p+3))) ||
72
         strncasecmp(p,"p>",2)==0 ||
73
         strncasecmp(p,"/a>",3)==0) {
74
          ftype="html"; goto fin;
75
      }
10 reyssat 76
    }
77
    if(strstr(filebuf,"\\begin{")!=NULL ||
78
       strstr(filebuf,"\\end{")!=NULL ||
79
       (strchr(filebuf,'$')!=NULL && strchr(filebuf,'\\')!=NULL &&
7676 bpr 80
      strchr(filebuf,'{')!=NULL)) {
81
      ftype="latex"; goto fin;
10 reyssat 82
    }
83
    fin: printf("%s",ftype);
84
    return 0;
85
}
86