Back to index

wims  3.65+svn20090927
Defines | Functions | Variables
insmath.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define andorcnt   (sizeof(andor)/sizeof(andor[0]))

Functions

void exec_instex (char *p)
void calc_instexst (char *p)
int mathml (char *p)
int instex_ready (char *p, char *n)
char * instex_check_static (char *p)
void __insmath (char *p)
void _mathlogic (char *p, void _put(char *pp))
void insmath (char *p)

Variables

struct {
char src [124]
char name [128]
int size
oldinstex [100]
int oldtexcnt = 0
char tnames []
char * andor [] = {"and","or","not","is","isnot"}
char * andorlang [andorcnt]
char andorlangbuf [1024]
int andorlangcnt = -1

Define Documentation

#define andorcnt   (sizeof(andor)/sizeof(andor[0]))

Definition at line 159 of file insmath.c.


Function Documentation

void __insmath ( char *  p)

Definition at line 84 of file insmath.c.

{
    char *f, *pp, *pe, *p1, buf[MAX_LINELEN+1], nbuf[256];
    int ts, n, rawmathready;

    strcpy(buf,p); strip_trailing_spaces(buf);
    p1=getvar("insmath_slashsubst");
    if(p1!=NULL && strstr(p1,"yes")!=NULL) slashsubst(buf);
    f=instex_check_static(buf); substit(buf);
    for(pp=strstr(buf,".."); pp!=NULL; pp=strstr(pp,"..")) {
       if(*(pp+2)=='.' || *(pp+2)==',') {
           do pp++; while(*pp=='.'); continue;
       }
       *pp=','; *(pp+1)=' ';
    }
    ts=0; if(strchr(buf,'\\') || strchr(buf,'}')) ts=1;
    rawmathready=0; if(!ts) {
       pp=getvar("insmath_rawmath");
       if(pp!=NULL && strstr(pp,"yes")!=NULL) {
           rawmath(buf); rawmathready=1;
       }
    }
    if(ts || mathalign_base==2 ||
       (strchr(buf,'[')!=NULL && 
       (strchr(buf,',')!=NULL || strchr(buf,';')!=NULL))) {
       char alignbak[2048];
       tex: instex_style="$$";
       if(!ts) texmath(buf);
       else {
           char *p1;
           p1=find_word_start(buf);
           if(*p1=='\\') {
              int i;
              char *pt;
              for(i=1;isalnum(p1[i]);i++);
              if(p1[i]==0 && (pt=mathfont(p1))!=NULL) {
                  _output_(pt); *p=0; return;
              }
           }
       }
       if(mathalign_base==2 && mathml(buf)) {*p=0; return;}
       pp=getvar("ins_align");
       if(pp!=NULL) mystrncpy(alignbak,pp,sizeof(alignbak));
       setvar("ins_align","middle");
       mystrncpy(ins_alt,buf,sizeof(ins_alt));
       if(f==NULL) {
           calc_instexst(buf); output("%s",buf);
       }
       else {
           instex_usedynamic=1; exec_instex(buf); instex_usedynamic=0;
       }
       instex_style=""; 
       if(alignbak[0]) setvar("ins_align",alignbak);
       return;
    }
    for(pp=find_mathvar_start(buf); *pp; pp=find_mathvar_start(pe)) {
       pe=find_mathvar_end(pp); n=pe-pp;
       if(!isalpha(*pp) || n<3 || n>16) continue;
       memmove(nbuf,pp,n); nbuf[n]=0;
       if(wordchr(tnames,nbuf)!=NULL) goto tex;
    }
/*    for(pp=strchr(buf,'{'); pp!=NULL; pp=strchr(pp+1,'{')) *pp='(';
    for(pp=strchr(buf,'}'); pp!=NULL; pp=strchr(pp+1,'}')) *pp=')';
*/    for(pp=strchr(buf,'/'); pp!=NULL && *find_word_start(pp+1)!='(';
       pp=strchr(pp+1,'/'));
    if(pp!=NULL) goto tex;
    if(rawmathready) rawmath_easy=1;
    for(pp=strchr(buf,'<'); pp!=NULL; pp=strchr(pp+1,'<'))
      string_modify(buf,pp,pp+1,"&lt;");
    for(pp=strchr(buf,'>'); pp!=NULL; pp=strchr(pp+1,'>'))
      string_modify(buf,pp,pp+1,"&gt;");
    htmlmath(buf); output("%s",buf); rawmath_easy=0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _mathlogic ( char *  p,
void   _putchar *pp 
)

Definition at line 164 of file insmath.c.

{
    char *p1, *p2, *ps;
    int i;
    if(strstr(p,"qzis")==NULL) {
       for(i=0;i<andorcnt && varchr(p,andor[i])==NULL; i++);
       if(i>=andorcnt) {
           _put(p); return;
       }
    }
    if(andorlangcnt<0) {
       char buf[MAX_LINELEN+1];
       accessfile(buf,"r","bases/sys/andor.%s",lang);
       mystrncpy(andorlangbuf,find_word_start(buf),sizeof(andorlangbuf));
       for(i=0,p1=andorlangbuf;i<andorcnt;i++,p1=find_word_start(p2)) {
           p2=strchr(p1,',');
           if(p2==NULL) p2=p1+strlen(p1); else *p2++=0;
           strip_trailing_spaces(p1);
           if(*p1) andorlang[i]=p1; else break;      
       }
       andorlangcnt=i;
    }
    for(ps=p, p1=find_mathvar_start(p); *p1; p1=find_mathvar_start(p2)) {
       p2=find_mathvar_end(p1);
       if(!isalpha(*p1)) continue;
       if(strncmp(p1,"qzis",4)==0) {
           char *p3, *p4, *p5;
           int tt;
           p4=find_word_start(p2);
           if(*p4!='(') continue;
           if(strncmp(p1+4,"not",3)==0) {tt=4; p3=p1+7;}
           else {tt=3; p3=p1+4;}
           if(!isalpha(*p3)) continue;
           p4++; p5=find_matching(p4,')');
           if(*p5!=')') continue;
           *p5=0; *p2=0; p2=p5+1;
           
           
           
           
           continue;
       }
       for(i=0;i<andorlangcnt;i++) if(strncmp(p1,andor[i],p2-p1)==0) break;
       if(i<andorlangcnt) {
           *p1=0; ps=find_word_start(ps); if(*ps) _put(ps);
           output(" %s ",andorlang[i]); ps=p2;
       }
    }
    ps=find_word_start(ps); if(*ps) _put(ps);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void calc_instexst ( char *  p)

Definition at line 1076 of file calc.c.

{
    char nbuf[MAX_FNAME+1], bufc[MAX_LINELEN+1];
    char buf2[1024], altbuf[1024], buf[MAX_LINELEN+1], urlbuf[MAX_LINELEN+1];
    char *b, *at, *al, *md1, *md2;
    int t, border, vspace;
    struct stat st,stc;
    char *p1, *p2, *p3, *ppp, *pt;

    if(robot_access) {*p=0; return;}
    p1=find_word_start(p); p2=find_word_end(p1);
    p3=p2-4; vspace=0;
    fix_tex_size();
    t=untrust; untrust=0; 
    if(find_module_file(m_file.name,bufc,0)) module_error(m_file.name);
    else stat(bufc,&stc);
    untrust=t;
    if(*p3=='.' && (memcmp(p3+1,"gif",3)==0 || memcmp(p3+1,"png",3)==0)) {
       char mbuf[MAX_LINELEN+1];
       if(*p2!=0) *p2++=0;
       p2=find_word_start(p2);
       strcpy(mbuf,p1); substit(mbuf);
       if(strstr(mbuf,parent_dir_string)!=NULL) {
           setvar(error_data_string,mbuf);
           module_error("illegal_fname"); return;
       }
       mkfname(nbuf,"%s/%s",module_prefix,mbuf);
    }
    else {
       ppp=getvar(ro_name[ro_module]);
       if(ppp==NULL) internal_error("calc_instexst(): module name vanishes.");
       p2=p1;
       mkfname(nbuf,"w/instex/%d/%s/%s_%d.gif",
               current_tex_size,ppp,m_file.name,m_file.l);
    }
    snprintf(urlbuf,sizeof(urlbuf),"%s%s?%X",ref_base,nbuf,
            (unsigned short int) stc.st_mtime);
    mystrncpy(buf,nbuf,sizeof(buf));
    if((ppp=strrchr(buf,'/'))!=NULL) {
       *ppp=0;mkdirs(buf);
    }
    b=getvar("ins_border");
    at=getvar("ins_attr");
    al=getvar("ins_align");
    if(at==NULL) at="";
    if(al==NULL) al="";al=find_word_start(al);
    if(*al!=0) snprintf(buf2,sizeof(buf2),"align=%s",al); else buf2[0]=0;
    if(b==NULL || *b==0) border=0;
    else border=atoi(b);
    if(border<0) border=0; if(border>100) border=100;
    if(instex_ready(p2,urlbuf)) goto prt;
    if(stat(nbuf,&st)!=0 || st.st_mtime<stc.st_mtime || st.st_size<45) {
       setenv("texgif_style",instex_style,1);
       setenv("texgif_src",p2,1);
       setenv("texgif_outfile",nbuf,1);
       setenv("texgif_tmpdir",tmp_dir,1); exportall();
       wrapexec=0; call_ssh("%s &>%s/instexst.log",tex2gif,tmp_dir);
       setenv("instexst_src","",1);
    }
    prt: md1=md2="";
    if(strcasecmp(al,"middle")==0) {
       md1=mathalign_sup1; md2=mathalign_sup2;
       vspace=5;
    }
    if(ins_alt[0]==0) mystrncpy(ins_alt,p2,sizeof(ins_alt));
    if(strchr(ins_alt,'"')!=NULL || strlen(ins_alt)>256) ins_alt[0]=0;
    pt=getvar("wims_ins_alt"); if(pt==NULL) pt="";
    if(ins_alt[0] && strcmp(pt,"none")!=0)
      snprintf(altbuf,sizeof(altbuf)," alt=\"%s\"",ins_alt);
    else altbuf[0]=0;
    snprintf(p,MAX_LINELEN,"%s<img src=\"%s\" border=%d vspace=%d %s %s%s>%s",
            md1,urlbuf,border,vspace,at,buf2,altbuf,md2);
    setvar("ins_attr",""); ins_alt[0]=0;
    setvar("ins_url",urlbuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void exec_instex ( char *  p)

Definition at line 1147 of file exec.c.

{
    char *ts, *tc, *f, *mh, buf[MAX_FNAME+1];
    
    if(robot_access) {
       *p=0; return;
    }
    f=instex_check_static(p); substit(p);
    if(f==NULL) {
       /* Use static instex if there is no real substitution
        * and the source file is not in sessions directory. */
       calc_instexst(p); if(outputing) _output_(p);
       return;
    }
    if(ismhelp) mh="mh"; else mh="";
    fix_tex_size(); f="gif";
    setenv("texgif_style",instex_style,1);
    setenv("texgif_tmpdir",tmp_dir,1);
    setenv("texgif_src",p,1);
    if(ins_alt[0]==0) mystrncpy(ins_alt,p,sizeof(ins_alt));
    mkfname(buf,"%s/insert%s-%d.gif",tmp_dir,mh,insert_no+1);
    setenv("texgif_outfile",buf,1);
    ts=getvar("wims_texsize"); tc=getvar("instex_color");
    if(lastout_file!=-1 && (tc==NULL || *tc==0) &&       
       (ts==NULL || *ts==0 || strcmp(ts,"0")==0) &&
       strstr(p,"\\begin{")==NULL) {
       int ls, ln;
       char *pagebreak;
       ls=strlen(instex_src); ln=strlen(instex_fname);
       if(ls+strlen(p)>=MAX_LINELEN-256 || 
          ln+strlen(buf)>=MAX_LINELEN-16) {
           instex_flush(); ls=ln=0;
       }
       if(instex_cnt>0) pagebreak="\\pagebreak\n"; else pagebreak="";
       snprintf(instex_src+ls,MAX_LINELEN-ls,"%s %s %s %s\n",
               pagebreak,instex_style,p,instex_style);
       snprintf(instex_fname+ln,MAX_LINELEN-ln,"%s\n",buf);
       grouped_ins=1;
    }
    mkfname(buf,"%s/texgif.dvi",tmp_dir); unlink(buf);
    wrapexec=0; _exec_ins(p,instex_processor,f);
    if(grouped_ins) instex_cnt++;
    grouped_ins=0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void insmath ( char *  p)

Definition at line 216 of file insmath.c.

{
    char *pt;
    if(!outputing) goto end;
    pt=getvar("insmath_logic");
    if(pt==NULL || strstr(pt,"yes")==NULL) {
       __insmath(p); 
       end: *p=0; return;
    }
    _mathlogic(p,__insmath);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* instex_check_static ( char *  p)

Definition at line 69 of file insmath.c.

{
    char *f;
    if(instex_usedynamic) return p;
    for(f=strchr(p,'$');
       f!=NULL && *(f+1)!='(' && *(f+1)!='[' && *(f+1)!='_' && !isalnum(*(f+1));
       f=strchr(f+2,'$'));
    if(f==NULL) f=strstr(m_file.name,"sessions/");
    return f;
}

Here is the caller graph for this function:

int instex_ready ( char *  p,
char *  n 
)

Definition at line 47 of file insmath.c.

{
    int i;
    char *cl, buf[MAX_LINELEN+1];
    
    if(strlen(p)>=124) return 0;
    cl=getvar("instex_color"); if(cl!=NULL && *cl!=0) return 0;
    mystrncpy(buf,p,sizeof(buf)); tex_nospace(buf);
    for(i=0;i<oldtexcnt;i++) {
       if(oldinstex[i].size==current_tex_size &&
          strcmp(oldinstex[i].src,buf)==0) {
           strcpy(n,oldinstex[i].name); return 1;
       }
    }
    if(strlen(n)>=128 || oldtexcnt>=100) return 0;
    strcpy(oldinstex[oldtexcnt].src,buf);
    strcpy(oldinstex[oldtexcnt].name,n);
    oldinstex[oldtexcnt].size=current_tex_size;
    oldtexcnt++; return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mathml ( char *  p)

Definition at line 32 of file insmath.c.

{
/*    char *p1, buf[MAX_LINELEN+1];
    if(strlen(p)==1 && isalpha(*p)) {
       output("<math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n");
       snprintf(buf,sizeof(buf),
               "<mrow><mi>%c</mi></mrow></math>\n",*p);
       output("%s",buf); return 1;
    }
    output("<pre>%s</pre>\n",p); return 1;
*/    
    return 0;
}

Here is the caller graph for this function:


Variable Documentation

char* andor[] = {"and","or","not","is","isnot"}

Definition at line 158 of file insmath.c.

Definition at line 160 of file insmath.c.

char andorlangbuf[1024]

Definition at line 160 of file insmath.c.

int andorlangcnt = -1

Definition at line 161 of file insmath.c.

struct { ... } oldinstex[100]
int oldtexcnt = 0

Definition at line 27 of file insmath.c.

char tnames[]
Initial value:
"sqrt int integrate sum prod product \
Int Sum Prod conj abs"

Definition at line 80 of file insmath.c.