Back to index

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

Go to the source code of this file.

Defines

#define buflim   1024*1024*16

Functions

void * xmalloc (size_t n)
void prepare_file (void)
int main (int argc, char *argv[])

Variables

char filename [1024] = ""
char * filebuf
int filelen = 0

Define Documentation

#define buflim   1024*1024*16

Definition at line 23 of file ftype.c.


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 57 of file ftype.c.

{
    char *ftype="text";
    char *p;
    char *mod, *unt;

    unt=getenv("untrust");
    if(unt!=NULL && strcasecmp(unt,"yes")==0) return 1;
    mod=getenv("w_module");
    if(mod==NULL) p=argv[1]; else p=getenv("wims_exec_parm");
    if(p==NULL || *p==0) return 1;
    snprintf(filename,sizeof(filename)-128,"%s",p);
    prepare_file();
    for(p=filebuf;p<filebuf+filelen;p++) {
       if((*p>=0 && *p<=6) || (127&*p)<=1) 
           {ftype="binary"; goto fin;}
    }
    for(p=strchr(filebuf,'<'); p!=NULL; p=strchr(p,'<')) {
       p++;
       if((strncasecmp(p,"body",4)==0 && !isalnum(*(p+4))) ||
          (strncasecmp(p,"html",4)==0 && !isalnum(*(p+4))) ||
          (strncasecmp(p,"img",3)==0 && isspace(*(p+3))) ||
          strncasecmp(p,"p>",2)==0 ||
          strncasecmp(p,"/a>",3)==0) {
           ftype="html"; goto fin;
       }
    }
    if(strstr(filebuf,"\\begin{")!=NULL ||
       strstr(filebuf,"\\end{")!=NULL ||
       (strchr(filebuf,'$')!=NULL && strchr(filebuf,'\\')!=NULL &&
       strchr(filebuf,'{')!=NULL)) {
       ftype="latex"; goto fin;
    }
    fin: printf("%s",ftype);
    return 0;
}

Here is the call graph for this function:

void prepare_file ( void  )

Definition at line 42 of file ftype.c.

{
    FILE *f;
    long int flen;

    filelen=0;
    f=fopen(filename,"r"); if(f==NULL) return;
    fseek(f,0,SEEK_END);flen=ftell(f); fseek(f,0,SEEK_SET);
    if(flen>buflim) return;
    filebuf=xmalloc(2*flen+1024);flen=fread(filebuf,1,flen,f);
    fclose(f);
    if(flen>0 && flen<buflim) filebuf[flen]=0; else flen=0;
    filelen=flen;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* xmalloc ( size_t  n)

Definition at line 33 of file ftype.c.

{
    void *p;
    p=malloc(n);
    if(p==NULL) exit(1);
    return p;
}

Variable Documentation

char* filebuf

Definition at line 30 of file ftype.c.

int filelen = 0

Definition at line 31 of file ftype.c.

char filename[1024] = ""

Definition at line 29 of file ftype.c.