Back to index

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

Go to the source code of this file.

Defines

#define buflim   1024*1024*16

Functions

void prepare_file (void)
void processbuf (void)
void output (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 phtmltext.c.


Function Documentation

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

Definition at line 123 of file phtmltext.c.

{
    if(argc<=1) return 0;
    snprintf(filename,sizeof(filename)-128,"%s",argv[1]);
    prepare_file();
    processbuf();
    output();
    return 0;
}

Here is the call graph for this function:

void output ( void  )

Definition at line 60 of file phtmltext.c.

{
    char *p, *pp, lastc;
    p=find_word_start(filebuf); lastc=0;
    if(*p=='!' || *p==':') goto cont1;
    for(;*p;p++) {
       if(*p=='\n') {
           if(!isspace(lastc)) {printf(" "); lastc=' ';}
           cont2: p=find_word_start(p);
           if(*p=='!' || *p==':') {
              if(lastc!='   ') printf(". "); lastc='    ';
              cont1: p=strchr(p,'\n');
              if(p==NULL) return;
              if(*(p-1)=='\\') {p++; goto cont1;}
              goto cont2;
           }
           for(pp=p; isalnum(*pp) || *pp=='_' || *pp=='$'; pp++);
           pp=find_word_start(pp);
           if(*pp=='=') goto cont1;
       }
       if(*p=='\\' && *(p+1)=='\n') {
           printf("\n"); p++; continue;
       }
       if(*p=='<' && (isalpha(*(p+1)) || *(p+1)=='/')) {
           p=strchr(p,'>'); goto nextp;
       }
       if(*p=='$') {
           if(lastc != '    ') {
              if(!isspace(lastc)) printf(" ");
              printf(". "); lastc='       ';
           }
           p++; 
           if(*p=='(') {p=find_matching(p+1,')'); goto nextp;}
           if(*p=='[') {p=find_matching(p+1,']'); goto nextp;}
           while(isalnum(*p) || *p=='_') p++;
           p--; continue;
       }
       if(*p=='&') {
           char *p2;
           for(p2=p+1; isalnum(*p2) || *p2=='#'; p2++);
           if(*p2==';') {
              p++; if(isalpha(*p)) {printf("%c",*p); lastc=*p;}
              p=p2; continue;
           }
       }
       if(!isspace(*p) && strchr(":!?.;,\"()[]{}=/\\+*^%@~`<>|",*p)==NULL)
           {printf("%c",*p); lastc=*p;}
       else {
           if(isspace(*p) && !isspace(lastc)) {
              printf(" "); lastc=' ';
           }
           if(!isspace(*p)) {
              switch(lastc) {
                  case ' ': printf(". "); lastc='       '; break;
                  case '    ': break;
                  default: printf(" . "); lastc='       '; break;
              }
           }
       }
       nextp: if(p==NULL || *p==0) break;
    }
}

Here is the call graph for this function:

void prepare_file ( void  )

Definition at line 34 of file phtmltext.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:

void processbuf ( void  )

Definition at line 49 of file phtmltext.c.

{
    char *p;
    deaccent(filebuf);
    for(p=filebuf; *p; p++) *p=tolower(*p);
    for(p=strpbrk(filebuf,"'-"); p!=NULL; p=strpbrk(p+1,"'-")) *p=' ';
    for(p=strstr(filebuf,"&nbsp;"); p!=NULL; p=strstr(p+1,"&nbsp;")) {
       *p=' '; strcpy(p+1,p+6);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* filebuf

Definition at line 30 of file phtmltext.c.

int filelen = 0

Definition at line 31 of file phtmltext.c.

char filename[1024] = ""

Definition at line 29 of file phtmltext.c.