Subversion Repositories wimsdev

Rev

Rev 3718 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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.  
  18. /* internal variable */
  19. int rawmath_easy=0;
  20.  
  21. #include "hmname.c"
  22.  
  23. enum {RM_UNKNOWN, RM_FN, RM_VAR, RM_PREFIX};
  24.  
  25. struct {
  26.     char *name;
  27.     int style;
  28.     char *replace;
  29. } mathname[]={
  30.       {"Arc",   RM_PREFIX,      "arc"},
  31.       {"Arg",   RM_PREFIX,      "arg"},
  32.       {"Ci",    RM_FN,          ""},
  33.       {"E",     RM_VAR,         ""},
  34.       {"Euler", RM_VAR,         ""},
  35.       {"I",     RM_VAR,         ""},
  36.       {"Int",   RM_FN,          ""},
  37.       {"PI",    RM_VAR,         ""},
  38.       {"Pi",    RM_VAR,         ""},
  39.       {"Prod",  RM_FN,          ""},
  40.       {"Si",    RM_FN,          ""},
  41.       {"Sum",   RM_FN,          ""},
  42.       {"arc",   RM_PREFIX,      ""},
  43.       {"arg",   RM_PREFIX,      ""},
  44.       {"binomial",RM_FN,        ""},
  45.       {"diff",  RM_FN,          ""},
  46.       {"e",     RM_VAR,         ""},
  47.       {"erf",   RM_FN,          ""},
  48.       {"euler", RM_VAR,         ""},
  49.       {"i",     RM_VAR,         ""},
  50.       {"infinity",RM_VAR,       ""},
  51.       {"int",   RM_FN,          ""},
  52.       {"integrate",RM_FN,       ""},
  53.       {"neq",   RM_VAR,         ""},
  54.       {"pi",    RM_VAR,         ""},
  55.       {"prod",  RM_FN,          ""},
  56.       {"product",RM_FN,         ""},
  57.       {"psi",   RM_FN,          ""},
  58.       {"sum",   RM_FN,          ""},
  59.       {"theta", RM_FN,          ""},
  60.       {"x",     RM_VAR,         ""},
  61.       {"y",     RM_VAR,         ""},
  62.       {"z",     RM_VAR,         ""},
  63.       {"zeta",  RM_FN,          ""},
  64. };
  65. #define mathname_no (sizeof(mathname)/sizeof(mathname[0]))
  66. char rm_vbuf[MAX_LINELEN+1],rm_fbuf[MAX_LINELEN+1];
  67. char *rm_uservar[MAX_LINELEN+1],*rm_userfn[MAX_LINELEN+1];
  68. int  rm_uservars,rm_userfns;
  69.  
  70.         /* add user-defined variables and function names,
  71.          * internal, only called by rawmath(). */
  72. void getuservar(void)
  73. {
  74.     char *p1, *p2, *p;
  75.     rm_uservars=rm_userfns=0;
  76.     p=getvar("wims_rawmath_variables");
  77.     if(p!=NULL && *p!=0) {
  78.         strcpy(rm_vbuf,p);
  79.         for(p=rm_vbuf;*p;p++) if(*p==',') *p=' ';
  80.         for(p1=find_word_start(rm_vbuf);*p1;p1=find_word_start(p2)) {
  81.             rm_uservar[rm_uservars++]=p1;
  82.             p2=find_word_end(p1);
  83.             if(*p2!=0) *(p2++)=0;
  84.         }
  85.     }
  86.     p=getvar("wims_rawmath_functions");
  87.     if(p!=NULL && *p!=0) {
  88.         strcpy(rm_fbuf,p);
  89.         for(p=rm_fbuf;*p;p++) if(*p==',') *p=' ';
  90.         for(p1=find_word_start(rm_fbuf);*p1;p1=find_word_start(p2)) {
  91.             rm_userfn[rm_userfns++]=p1;
  92.             p2=find_word_end(p1);
  93.             if(*p2!=0) *(p2++)=0;
  94.         }
  95.     }
  96. }
  97.  
  98.         /* Try to split a word into recognizable variables */
  99. char *mathname_split(char *p)
  100. {
  101.     int c,i,j,type;
  102.  
  103.     c=0;
  104.     beg: for(i=get_evalcnt()-1;
  105.         i>=0 && strncmp(p,get_evalname(i),strlen(get_evalname(i)))!=0;
  106.         i--);
  107.     if(i>=0 && get_evaltype(i)>0) {
  108.         type=RM_FN;
  109.         j=strlen(get_evalname(i));
  110.         gotit:
  111.         if(!*(p+j)) return p;
  112.         if(myisdigit(*(p+j)) && type!=RM_FN) return NULL;
  113.         if(!c) {string_modify(p,p+j,p+j," "); p+=j+1;}
  114.         else p+=j;
  115.         c++; goto beg;
  116.     }
  117.     for(i=mathname_no-1;
  118.         i>=0 &&
  119.         (strncmp(p,mathname[i].name,strlen(mathname[i].name))!=0
  120.          || mathname[i].style==RM_PREFIX);
  121.         i--);
  122.     if(i>=0) {
  123.         type=mathname[i].style;
  124.         j=strlen(mathname[i].name);
  125.         goto gotit;
  126.     }
  127.     for(i=0;i<rm_uservars &&
  128.         strncmp(rm_uservar[i],p,strlen(rm_uservar[i]));i++);
  129.     if(i<rm_uservars) {
  130.         type=RM_VAR;
  131.         j=strlen(rm_uservar[i]); goto gotit;
  132.     }
  133.     for(i=0;i<rm_userfns &&
  134.         strncmp(p,rm_userfn[i],strlen(rm_userfn[i]));i++);
  135.     if(i<rm_userfns) {
  136.         type=RM_FN;
  137.         j=strlen(rm_userfn[i]); goto gotit;
  138.     }
  139.     return NULL;    
  140. }
  141.  
  142.         /* Error-tolerante raw math translation routine */
  143.         /* Translate error-laden raw math into machine-understandable form. */
  144. void rawmath(char *p)
  145. {
  146.     char *p1, *p2, *p3, *p4;
  147.     char warnbuf[1024];
  148.     int modified=0,user_prohibited=0;
  149.     int ambiguous=0,unknown=0,flatpower=0,badprec=0,unmatch=0;
  150.  
  151.         /* looks like a TeX source */
  152.     if(strchr(p,'\\')!=NULL || strchr(p,'{')!=NULL) return;
  153.     if(strchr(p,'^')==NULL) flatpower=-1;
  154.     if(strlen(p)>=MAX_LINELEN) {*p=0; return;}
  155.     if(strncmp(p,"1-1+",strlen("1-1+"))==0) user_prohibited=1;
  156.     p1=find_word_start(p);if(*p1==0) return;
  157.     while(*p1=='+') p1++;
  158.     if(p1>p) strcpy(p,p1);
  159.         /* translate ** into ^ */
  160.     while((p1=strstr(p,"**"))!=NULL) {
  161.         string_modify(p,p1,p1+strlen("**"),"^");
  162.         modified++;
  163.     }
  164.     while((p1=strchr(p,'²'))!=NULL) {
  165.         string_modify(p,p1,p1+1,"^2 ");
  166.         flatpower=1;
  167.         modified++;
  168.     }
  169.     while((p1=strchr(p,'³'))!=NULL) {
  170.         string_modify(p,p1,p1+1,"^3 ");
  171.         flatpower=1;
  172.         modified++;
  173.     }
  174.     while((p1=strchr(p,'¨'))!=NULL) {
  175.         *p1='^'; modified++;
  176.     }
  177.         /* translate |x| into abs(x) */
  178.     while((p1=strchr(p,'|'))!=NULL) {
  179.         p2=find_matching(p1+1,'|');
  180.         if(p2==NULL) {unmatch=1; break;}        /* error; drop it. */
  181.         *p2=')'; string_modify(p,p1,p1+1,"abs(");
  182.     }
  183.         /* signs: translate ++, +-, -+, ... into one sign. */
  184.     for(p1=p;*p1!=0;p1++) {
  185.         int sign, redundant;
  186.         if(*p1!='+' && *p1!='-') continue;
  187.         if(*p1=='+') sign=1; else sign=-1;
  188.         redundant=0;
  189.         for(p2=find_word_start(p1+1);*p2=='+' || *p2=='-';
  190.             p2=find_word_start(p2+1)) {
  191.              if(*p2=='-') sign*=-1;
  192.              redundant=1;
  193.         }
  194.         if(redundant && *p2!='>' && strncmp(p2,"&gt;",4)!=0) {
  195.             if(sign==1) *p1='+'; else *p1='-';
  196.             strcpy(p1+1,p2);
  197.             modified++;
  198.         }
  199.     }
  200.         /* First translation: lower cases, parentheses, new-lines, tabs. */
  201.     for(p1=p;*p1!=0; p1++) {
  202.         /* *p1=tolower(*p1); */
  203. /*      if(*p1=='[' || *p1=='{') *p1='(';
  204.         if(*p1==']' || *p1=='}') *p1=')';
  205. */      if(*p1=='\\' || isspace(*p1)) *p1=' ';
  206.         if(*p1=='\"') {
  207.             string_modify(p,p1,p1+1,"''"); p1++;
  208.         }
  209.     }
  210.         /* dangling decimal points */
  211.     for(p1=strchr(p,'.'); p1!=NULL; p1=strchr(p1+1,'.')) {
  212.                 /* multiple .. is conserved */
  213.         if(*(p1+1)=='.') {
  214.             do p1++; while(*p1=='.'); continue;
  215.         }
  216.         if(p1>p && myisdigit(*(p1-1)) && myisdigit(*(p1+1))) continue;
  217.                 /* Non-digit dangling '.' is removed */
  218.         if((p1<=p || !myisdigit(*(p1-1))) && !myisdigit(*(p1+1))) {
  219.             strcpy(p1,p1+1); p1--; continue;
  220.         }
  221.         if(p1==p || !myisdigit(*(p1-1))) {
  222.             string_modify(p,p1,p1,"0"); p1++;
  223.         }
  224.         if(!myisdigit(*(p1+1))) string_modify(p,p1+1,p1+1,"0");
  225.     }
  226.     if(rawmath_easy || user_prohibited) return;
  227.         /* Principal translation: justapositions to multiplications */
  228.     if(strstr(p,"^1/")!=NULL) badprec=1;
  229.     getuservar();
  230.     for(p1=p;*p1;p1++) {
  231.         if(!isalnum(*p1) && *p1!=')' && *p1!=']') continue;
  232.         if(*p1==')' || *p1==']') {
  233.             p2=find_word_start(++p1);
  234.             add_star:
  235.             if(isalnum(*p2) || *p2=='(' || *p2=='[') {
  236.                 if(*p2=='(' && *p1==')') ambiguous=1;
  237.                 if(p2>p1) *p1='*';
  238.                 else string_modify(p,p1,p1,"*");
  239.                 modified++;
  240.             }
  241.             p1--;continue;
  242.         }
  243.         p2=find_mathvar_end(p1); p3=find_word_start(p2);
  244.         if(myisdigit(*p1)) {
  245.             p1=p2; p2=p3; goto add_star;
  246.         }
  247.         else {
  248.             char buf[MAX_LINELEN+1];
  249.             int i;
  250.             if(p2-p2>30) goto ambig;
  251.             memcpy(buf,p1,p2-p1);buf[p2-p1]=0;
  252.             i=search_evaltab(buf);
  253.             if(i>=0 && get_evaltype(i)>0) {
  254.                 fnname1:
  255.                 p1=p2;p2=p3;
  256.                 /*fnname:*/
  257.                 if(*p2 && *p2!='(' && *p2!='*' && *p2!='/') {
  258.                     char hatbuf[MAX_LINELEN+1];
  259.                     hatbuf[0]=')'; hatbuf[1]=0;
  260.                     if(*p2=='^') {
  261.                         p3=p2+1;while(*p3==' ' || *p3=='+' || *p3=='-') p3++;
  262.                         if(*p3=='(') {
  263.                             p3=find_matching(p3+1,')');
  264.                             if(p3==NULL) {unmatch=1; p3=p+strlen(p);}
  265.                             else p3++;
  266.                         }
  267.                         else p3=find_mathvar_end(p3);
  268.                         memmove(hatbuf+1,p2,p3-p2);hatbuf[p3-p2+1]=0;
  269.                         strcpy(p2,p3);
  270.                         while(*p2==' ') p2++;
  271.                         if(*p2=='*' || *p2=='/') {
  272.                             p1--;continue;
  273.                         }
  274.                         if(*p2=='(') {
  275.                             p3=find_matching(p2+1,')');
  276.                             if(p3==NULL) {unmatch=1; p3=p+strlen(p);}
  277.                             else p3++;
  278.                             string_modify(p,p3,p3,"%s",hatbuf+1);
  279.                             goto dd2;
  280.                         }
  281.                     }
  282.                     p3=p2;if(*p3=='+' || *p3=='-') p3++;
  283.                     while(isalnum(*p3) || *p3=='*' || *p3=='/' || *p3=='.')
  284.                       p3++;
  285.                     for(p4=p2; p4<p3 && !isalnum(*p4); p4++);
  286.                     if(p4>=p3) {
  287.                         if(hatbuf[1]) string_modify(p,p2,p2,"%s",hatbuf+1);
  288.                     }
  289.                     else {
  290.                         string_modify(p,p3,p3,"%s",hatbuf);
  291.                         if(p1==p2) string_modify(p,p2,p2,"(");
  292.                         else *p1='(';
  293.                     }
  294.                     dd2:
  295.                     modified++;ambiguous=1;
  296.                 }
  297.                 p1--;continue;
  298.             }
  299.             i=search_list(mathname,mathname_no,sizeof(mathname[0]),buf);
  300.             if(i>=0) {
  301.                 if(mathname[i].replace[0]!=0) {
  302.                     string_modify(p,p1,p2,mathname[i].replace);
  303.                     p2=p1+strlen(mathname[i].replace);
  304.                     p3=find_word_start(p2);
  305.                 }
  306.                 switch(mathname[i].style) {
  307.                     case RM_FN:
  308.                       goto fnname1;
  309.                    
  310.                     case RM_VAR:
  311.                       p1=p2;p2=p3; goto add_star;
  312.                    
  313.                     case RM_PREFIX:
  314.                       if(*p3!='c' && *p3!='s' && *p3!='t' &&
  315.                          *p3!='C' && *p3!='S' && *p3!='T') break;
  316.                       ambiguous=1;
  317.                       strcpy(p2,p3); p1--; continue;
  318.                 }
  319.             }
  320.             i=search_list(hmname,hmname_no,sizeof(hmname[0]),buf);
  321.             if(i>=0) {
  322.                 p1=p2; p2=p3; goto add_star;
  323.             }
  324.             for(i=0;i<rm_uservars && strcmp(buf,rm_uservar[i]);i++);
  325.             if(i<rm_uservars) {
  326.                 p1=p2;p2=p3;goto add_star;
  327.             }
  328.             for(i=0;i<rm_userfns && strcmp(buf,rm_userfn[i]);i++);
  329.             if(i<rm_userfns) goto fnname1;
  330.             if(p2-p1>8) goto ambig;
  331.             if(mathname_split(buf)!=NULL) {
  332.                 ambiguous=1;
  333.                 string_modify(p,p1,p2,"%s",buf);
  334.                 p1--; continue;
  335.             }
  336.              /* unknown name */
  337.             ambig: p1=p2;p2=p3;
  338.             if(strlen(buf)>1) {
  339.                 for(p3=buf;*p3!=0 && !myisdigit(*p3);p3++);
  340.                 if(*p3!=0 && flatpower!=0) flatpower=1;
  341.                 else {
  342.                     unknown=1;
  343.                     force_setvar("wims_warn_rawmath_parm",buf);
  344.                 }
  345.             }
  346.             else {
  347.                 if(*p2=='(') ambiguous=1;
  348.             }
  349.             if(isalnum(*p2)) {
  350.                 if(p2>p1) *p1='*';
  351.                 else string_modify(p,p1,p1,"*");
  352.                 modified++;
  353.             }
  354.             p1--;continue;
  355.         }
  356.     }
  357.     warnbuf[0]=0;
  358.     if(ambiguous) strcat(warnbuf," ambiguous");
  359.     if(unknown) strcat(warnbuf," unknown");
  360.     if(flatpower>0) strcat(warnbuf," flatpower");
  361.     if(badprec>0) strcat(warnbuf," badprec");
  362.     if(unmatch>0) strcat(warnbuf," unmatched_parentheses");
  363.     if(warnbuf[0]) {
  364.         char buf[MAX_LINELEN+1],*p;
  365.         p=getvar("wims_warn_rawmath");
  366.         if(p!=NULL && *p!=0) {
  367.             snprintf(buf,sizeof(buf),"%s %s",p,warnbuf);
  368.             force_setvar("wims_warn_rawmath",buf);
  369.         }
  370.         else force_setvar("wims_warn_rawmath",warnbuf);
  371.     }
  372. }
  373.  
  374.         /* translate raw math expression into best html way */
  375. void htmlmath(char *p)
  376. {
  377.     char *p1,*p2,*p3,*pp,pbuf[16];
  378.     char c;
  379.  
  380.     if(!rawmath_easy) {
  381.         rawmath_easy=1; rawmath(p); rawmath_easy=0;
  382.     }
  383.     p1=getvar("htmlmath_gtlt"); if(p1!=NULL && strcmp(p1,"yes")==0) {
  384.         for(pp=strchr(p,'<'); pp!=NULL; pp=strchr(pp+1,'<'))
  385.           string_modify(p,pp,pp+1,"&lt;");
  386.         for(pp=strchr(p,'>'); pp!=NULL; pp=strchr(pp+1,'>'))
  387.           string_modify(p,pp,pp+1,"&gt;");
  388.     }
  389.       /* exponents */
  390.     for(p1=strchr(p,'^');p1!=NULL;p1=strchr(p1+1,'^')) {
  391.         p3=p2=find_word_start(p1+1);
  392.         if(*p2=='+' || *p2=='-') p2++;
  393.         p2=find_word_start(p2);
  394.         if(*p2=='(') {
  395.             p2=find_matching(p2+1,')');
  396.             if(p2==NULL) p2=p+strlen(p); else p2++;
  397.             if(*p3=='(') for(pp=p3+1;pp<p2-1;pp++) {
  398.                 if(!isalnum(*pp)) {
  399.                     p3++;*(p2-1)=0;break;
  400.                 }
  401.             }
  402.         }
  403.         else {
  404.             char *ptt=p2;
  405.             p2=find_word_start(find_mathvar_end(p2));
  406.             if(*p2=='(' && isalpha(*ptt)) {
  407.                 char *p2t;
  408.                 p2t=find_matching(p2+1,')'); if(p2t!=NULL) p2=p2t+1;
  409.             }
  410.         }
  411.         c=*p2;if(c!=0) *p2++=0;
  412.         string_modify(p,p1,p2,"<sup>%s</sup>%c",p3,c);
  413.     }
  414.         /* explicit subscription */
  415.     for(p1=strchr(p,'_');p1!=NULL;p1=strchr(p1+1,'_')) {
  416.         char buff[256];
  417.         p2=p1+1;
  418.         if(*p2=='(') p2=find_matching(p2+1,')');
  419.         else p2=find_mathvar_end(p2);
  420.         if(p2==NULL || p2>p1+64) continue;
  421.         if(*(p1+1)=='(') p2++;
  422.         memmove(buff,p1+1,p2-p1-1); buff[p2-p1-1]=0;
  423.         strip_enclosing_par(buff);
  424.         string_modify(p,p1,p2,"<sub>%s</sub>",buff);
  425.     }
  426.       /* get rid of 1*.. ..*1 */
  427.     for(p1=p;*p1;p1++) {
  428.         if(*p1!='1') continue;
  429.         if(myisdigit(*(p1+1)) || *(p1+1)=='.' ||
  430.            (p1>p && (isalnum(*(p1-1)) || *(p1-1)=='.')) ) continue;
  431.         p2=find_word_start(p1+1);
  432.         if(p1>p+2 && (*(p1-1)=='-' || *(p1-1)=='+')) {
  433.             for(p3=p1-2; p3>p && isspace(*p3); p3--);
  434.             if(p3>p+1 && (*p3=='E' || *p3=='e')) {
  435.                 p3--; while(p3>p && isspace(*p3)) p3--;
  436.                 if(myisdigit(*p3) || *p3=='.') continue;
  437.             }
  438.         }
  439.         if(p1==p) p3="+";
  440.         else for(p3=p1-1;p3>p && isspace(*p3);p3--);
  441.         if(*p2=='*' && *p3!='/') {
  442.             strcpy(p1,p2+1);continue;
  443.         }
  444.         if(isalpha(*p2) && *p3!='/') {
  445.             strcpy(p1,p2);continue;
  446.         }
  447.         if(*p3=='/' && *p2!='<') strcpy(p3,p2);
  448.  
  449.     }
  450.         /* exponents of 10, or greek letters */
  451.     for(p1=find_mathvar_start(p);*p1!=0;p1=find_mathvar_start(p2)) {
  452.         char buf[MAX_LINELEN+1];
  453.         char expstr[]=" &times; 10<sup>";
  454.         p2=find_mathvar_end(p1);
  455.         memmove(buf,p1,p2-p1);buf[p2-p1]=0;
  456.         if(myisdigit(buf[0])) { /* number */
  457.             int k;
  458.             if((p3=strchr(buf,'e'))==NULL && (p3=strchr(buf,'E'))==NULL)
  459.               continue;
  460.             p1+=p3-buf;
  461.             for(k=1;*(p1+k)=='0' || *(p1+k)=='+';k++);
  462.             string_modify(p,p1,p1+k,expstr);
  463.             p2+=strlen(expstr)-1;
  464.             string_modify(p,p2,p2,"</sup>");
  465.             p2+=strlen("</sup>");
  466.         }
  467.         else {  /* alphabetic name */
  468.             int i;
  469.             i=search_list(hmname,hmname_no,sizeof(hmname[0]),buf);
  470.             if(i<0) {
  471.                 if(myisdigit(buf[strlen(buf)-1])) {
  472.                     int k;
  473.                     for(k=strlen(buf);k>0 && myisdigit(buf[k-1]); k--);
  474.                     string_modify(buf,buf+k,buf+k,"<sub>");
  475.                     string_modify(p,p1,p2,"%s</sub>",buf);
  476.                     p2+=strlen("<sub>")+strlen("</sub>");
  477.                 }
  478.                 continue;
  479.             }
  480.             if(hmname[i].replace[0]==0) {
  481.                 string_modify(p,p1,p2,"$(m_%s)",hmname[i].name);
  482.                 p2=p1+strlen(hmname[i].name)+5;
  483.             }
  484.             else {
  485.                 string_modify(p,p1,p2,"%s",hmname[i].replace);
  486.                 p2=p1+strlen(hmname[i].replace);
  487.             }
  488.         }
  489.     }
  490.       /* get rid of '*' */
  491.     for(p1=strchr(p,'*');p1!=NULL;p1=strchr(p1+1,'*')) {
  492.         char *pq;
  493.         pq=find_word_start(p1+1);
  494.         if(myisdigit(*pq)) {
  495.             string_modify(p,p1,pq,"&times;");
  496.             continue;
  497.         }
  498.         if(p1>p && (isalpha(*(p1-1)) || *(p1-1)==')' || *(p1-1)=='>')
  499.            && (isalnum(*pq) || *pq=='$')) *p1=' ';
  500.         else {
  501.             strcpy(p1,p1+1);p1--;
  502.         }
  503.     }
  504.         /* <=, >=, ->, =>, <=> */
  505.     for(p1=strstr(p,"&lt;="); p1!=NULL; p1=strstr(p1+1,"&lt;=")) {
  506.         if(*(p1+5)!='&' && *(p1+5)!='=')
  507.           string_modify(p,p1,p1+5,"$(m_le)");
  508.         else {
  509.             for(p2=p1+5; *p2=='='; p2++);
  510.             if(strncmp(p2,"&gt;",4)==0) {
  511.                 if(p2>p1+5) string_modify(p,p1,p2+4,"$(m_Longleftrightarrow)");
  512.                 else string_modify(p,p1,p2+4,"$(m_Leftrightarrow)");
  513.             }
  514.             else string_modify(p,p1,p2,"$(m_Longleftarrow)");
  515.         }
  516.     }
  517.     for(p1=strstr(p,"&gt;="); p1!=NULL; p1=strstr(p1+1,"&gt;=")) {
  518.         if(*(p1+5)!='=') string_modify(p,p1,p1+5,"$(m_ge)");
  519.     }
  520.     for(p1=strstr(p,"-&gt;"); p1; p1=strstr(p1+1,"-&gt;")) {
  521.         for(p2=p1; p2>p && *(p2-1)=='-'; p2--);
  522.         if(p2>p && *(p2-1)==';') continue;
  523.         if(p2<p1) string_modify(p,p2,p1+5,"$(m_longrightarrow)");
  524.         else string_modify(p,p1,p1+5,"$(m_rightarrow)");
  525.     }
  526.     for(p1=strstr(p,"=&gt;"); p1; p1=strstr(p1+1,"=&gt;")) {
  527.         for(p2=p1; p2>p && *(p2-1)=='='; p2--);
  528.         if(p2>p && *(p2-1)==';') continue;
  529.         if(p2<p1) string_modify(p,p2,p1+5,"$(m_Longrightarrow)");
  530.         else string_modify(p,p1,p1+5,"$(m_Rightarrow)");
  531.     }
  532.         /* Not equal */
  533.     for(p1=strstr(p,"!="); p1; p1=strstr(p1+1,"!=")) {
  534.         if(p1>p && !isspace(*(p1-1))) continue;
  535.         string_modify(p,p1,p1+2,"$(m_neq)");
  536.     }
  537.         /* Now make substitutions */
  538.     substit(p);
  539.         /* Make single names italic */
  540.     for(p1=p;*p1;p1++) {
  541.         if(*p1=='<') {
  542.             p1=strchr(p1,'>'); if(p1==NULL) break;
  543.             else continue;
  544.         }
  545.         if(*p1=='=' && *(p1+1)=='-') {
  546.             string_modify(p,p1+1,p1+1," "); p1+=2; continue;
  547.         }
  548.         if(*p1=='\'') {
  549.             for(p2=p1+1;*p2=='\'';p2++);
  550.             memmove(pbuf,p1,p2-p1); pbuf[p2-p1]=0;
  551.             string_modify(p,p1,p2,"<i><tt>%s</tt></i>",pbuf);
  552.             p1=p2+strlen("<i><tt></i></tt>")-1;
  553.             continue;
  554.         }
  555.         if(!isalpha(*p1)) continue;
  556.         for(p2=p1+1;isalpha(*p2);p2++);
  557.         p3=find_word_start(p2);
  558.         if(p2>p1+5 ||
  559.            (p2>p1+1 && (*p3==';' || *p3=='(' || myisdigit(*p2))))
  560.             {p1=p2-1; continue;}
  561.         if(strncasecmp(p3,"</i>",strlen("</i>"))==0) continue;
  562.         memmove(pbuf,p1,p2-p1); pbuf[p2-p1]=0;
  563.         string_modify(p,p1,p2,"<i>%s</i>",pbuf);
  564.         p1=p2+strlen("<i></i>")-1;
  565.     }
  566.     strip_trailing_spaces(p);
  567. }
  568.  
  569.