#include #include #include #include #include #include int CorF; int Ipr=14; char pr[]={"bcdefhpqrtuvwx"}; int Icr=5; char cr[]={"agsyz"}; typedef struct PREFIX{ char ch[4]; char sp[32]; char sb[32]; int Lp; /* length of superscript */ int Lb; /* length of subscript */ int L; /* length of core for \c{b} and \c{t} or of prefix */ }PREFIX; typedef struct CORE{ char ch[32]; char sp[32]; char sb[32]; int Lp; /* length of superscript */ int Lb; /* length of subscript */ int L; int nB; /* length of buffer B1 for LaTeX */ char B1[256]; /* buffer for LaTeX */ char B2[256]; /* buffer for LaTeX */ }CORE; typedef struct SUFFIX{ char sp[32]; char sb[32]; int Lp; int Lb; int L; }SUFFIX; typedef struct OOPER{ char ch; int p; int iCr; char B1[32]; /* buffer for LaTeX */ }OOPER; typedef struct TEXDEF{ char ch; char Obj[512]; int iW; int iH; int iP; int iB; int iD; int iT; }TEXDEF; int nPr=0; PREFIX Pr[16]; int nCore=0; CORE Core[16]; int nSuff=0; SUFFIX Suff[16]; int nOp=0; OOPER Op[16]; int nDf=0; TEXDEF Df[32]; int IsExtDigitChar(char ch) { if(('0' <= ch && ch <= '9') || ('i' <= ch && ch <= 'n')){ return(1); } return(0); } int IsPseudoDigitChar(char ch) { if('i' <= ch && ch <= 'n'){ return(1); } return(0); } int CleanOper(OOPER *P) { int i; P->ch ='\0'; P->p =0; P->iCr=0; for(i=0; i < 32; i++){ P->B1[i] ='\0'; } return(0); } int CleanPrefix(PREFIX *P) { int i; P->ch[0] ='\0'; P->ch[1] ='\0'; P->ch[2] ='\0'; P->ch[3] ='\0'; for(i=0; i < 32; i++){ P->sp[i] ='\0'; P->sb[i] ='\0'; } P->Lp =0; P->Lb =0; P->L =0; return(0); } int IsOper(char *str) { int i,L; char *p; CleanOper(Op+nOp); p =str+1; if(*str != 'o' || !isalpha(*p) || *(p+1) == '\0'){ return(0); } Op[nOp].ch =*p; Op[nOp].iCr =nCore; switch(*p){ case '.': Op[nOp].p =5; break; case 'h': Op[nOp].p =4; break; case 'c': case 'f': case 'x': Op[nOp].p =3; break; case 'm': case 'p': Op[nOp].p =2; break; case 'a': case 'r': Op[nOp].p =1; break; default : break; } return(2); } int IsPrefixChar(char *p) { int i; char ch; ch =*p; i =0; while(i < Ipr && ch != pr[i]){ i++; } if(i == Ipr || (ch == 'f' && !isalpha(*(p+1)))){ return(0); } if(ch == 'c' && *(p+1) != 'm'){ for(i=0; i < nPr; i++){ if(Pr[i].ch[0] == 'c' && Pr[i].ch[1] != 'm'){ return(0); } } } if('u' <= ch && ch <= 'w'){ for(i=0; i < nPr; i++){ if('u' <= Pr[i].ch[0] && Pr[i].ch[0] <= 'w'){ return(0); } } } return(1); } int IsPrefix(char *str) { int i,iu; int id1,id2,kd1,kd2; char d1[32]; char *p,*t; CleanPrefix(Pr+nPr); p =str; if(IsPrefixChar(p) == 0){ return(0); } p++; /* Return if there is no argument */ Pr[nPr].ch[0] =*str; if(*str == 'f' || (*str == 'c' && *p == 'm')){ Pr[nPr].ch[1] =*p++; if(!IsExtDigitChar(*p) && *p != '_'){ if(*p == '\0' || (*p == 'o' && isalpha (*(p+1)) && *(p+2) != '\0')){ return(0); } return(2); } } else{ if((*str == 'b' || *str == 't' || *str == 'd') && !isdigit(*p) && *p != '_'){ if(*p == '\0' || (*p == 'o' && isalpha (*(p+1)) && *(p+2) != '\0')){ return(0); } return(1); } if(*str != 'b' && *str != 't' && *str != 'd' && !IsExtDigitChar(*p) && *p != '_'){ if(*p == '\0' || (*p == 'o' && isalpha (*(p+1)) && *(p+2) != '\0')){ return(0); } return(1); } } /* Argument */ if(*p == '0' && (*str < 'u' || *str > 'w')){ return(0); } iu =0; kd1 =0; kd2 =0; if(*str == 'b' || *str == 't'){ id1 =0; while(isdigit(*p)){ d1[id1++] =*p++; } if(id1){ i =0; kd1 =d1[0]-'0'; i++; while(i < id1){ kd1 =kd1*10+d1[i]-'0'; i++; } } if(*p == '_'){ p++; iu =1; if(*p == '0'){ return(0); } id1 =0; while(isdigit(*p)){ d1[id1++] =*p++; } if(id1){ i =0; kd2 =d1[0]-'0'; i++; while(i < id1){ kd2 =kd2*10+d1[i]-'0'; i++; } } } if(kd1+kd2 == 0){ return(0); } if(kd1 > 32){ printf("%d - too big length in numerical argument\n",kd1); kd1 =32; } if(kd2 > 32){ printf("%d - too big length in numerical argument\n",kd2); kd2 =32; } i =0; t =Pr[nPr].sp; while(*p != '\0' && i < kd1){ *t++ =*p++; i++; } if(i < kd1){ return(0); } i =0; t =Pr[nPr].sb; while(*p != '\0' && i < kd2){ *t++ =*p++; i++; } if(i < kd2){ return(0); } if(iu && (*p == '\0' || *p == '_' || (*p == 'o' && isalpha (*(p+1)) && *(p+2) != '\0'))){ return(0); } if(iu){ Pr[nPr].Lp=kd1; Pr[nPr].Lb=kd2; } else{ Pr[nPr].L =kd1; } return((int)(p-str)); } if(*str == 'd'){ id1 =0; t =Pr[nPr].sp; while(isdigit(*p)){ *t++ =*p++; id1++; } Pr[nPr].Lp =id1; if(id1){ t =Pr[nPr].sp; kd1 =*t-'0'; t++; while(*t != '\0'){ kd1 =kd1*10+(*t-'0'); t++; } } if(*p == '_'){ p++; iu =1; if(*p == '0'){ return(0); } id1 =0; while(isdigit(*p)){ d1[id1++] =*p++; } if(id1){ i =0; kd2 =d1[0]-'0'; i++; while(i < id1){ kd2 =kd2*10+d1[i]-'0'; i++; } } if(kd1 == 0){ t =Pr[nPr].sp; i =0; while(i < id1){ *t++ =d1[i++]; } Pr[nPr].Lp =id1; kd1 =kd2; } if(kd2 == 0){ kd2 =kd1; } } if(kd1 == 0){ return(0); } if(kd2 > 32){ printf("%d - too big length in numerical argument\n",kd2); kd2 =32; } i =0; t =Pr[nPr].sb; while(*p != '\0' && i < kd2){ *t++ =*p++; i++; } if((kd2 && i < kd2) || *p == '\0' || *p == '_' || (*p == 'o' && isalpha (*(p+1)) && *(p+2) != '\0')){ return(0); } Pr[nPr].Lb=kd2; return((int)(p-str)); } t =Pr[nPr].sp; while(IsExtDigitChar(*p)){ *t++ =*p++; kd1++; } Pr[nPr].Lp =kd1; if(*p == '_'){ p++; iu =1; if(*p == '0'){ return(0); } t =Pr[nPr].sb; while(IsExtDigitChar(*p)){ *t++ =*p++; kd2++; } Pr[nPr].Lb =kd2; } if(kd1+kd2 == 0 || *p == '\0' || *p == '_' || (*p == 'o' && isalpha (*(p+1)) && *(p+2) != '\0')){ return(0); } if(*str == 'u' || *str == 'w'){ if(kd2 == 0 && iu == 0){ t =Pr[nPr].sp; i =0; while(*t != '\0'){ Pr[nPr].sb[i++] =*t; *t++ ='\0'; } Pr[nPr].Lb =kd1; Pr[nPr].Lp =0; } } return((int)(p-str)); } int PrintPrefix() { int i; char *t; if(nPr){ printf("Prefix:\n"); for(i=0; i < nPr; i++){ putchar(Pr[i].ch[0]); t =Pr[i].sp; if(*t != '\0'){ putchar('^'); while(*t != '\0'){ putchar(*t); t++; } } t =Pr[i].sb; if(*t != '\0'){ putchar('_'); while(*t != '\0'){ putchar(*t); t++; } } printf(" Lp=%d Lb=%d L=%d\n",Pr[i].Lp,Pr[i].Lb,Pr[i].L); } } return(0); } int CleanCore(CORE *P) { int i; for(i=0; i < 32; i++){ P->ch[i] ='\0'; P->sp[i] ='\0'; P->sb[i] ='\0'; } P->ch[0] ='s'; P->Lp =0; P->Lb =0; P->L =0; P->nB =0; return(0); } int PrintCore() { char *t; printf("Core:\n"); if(Core[nCore].ch[1] != '\0'){ if(CorF && Core[nCore].ch[0] == 'a'){ putchar(toupper(Core[nCore].ch[1])); } else{ putchar(Core[nCore].ch[1]); } printf(" Lp=%d Lb=%d L=%d\n",Core[nCore].Lp,Core[nCore].Lb,Core[nCore].L); return(0); } printf(" Lp=%d Lb=%d L=%d\n",Core[nCore].Lp,Core[nCore].Lb,Core[nCore].L); return(0); } int IsGoodCoreArg(char *str) { int i,L; char *p; p =Core[nCore].ch+1; if('A' <= *p && *p <= 'Z' && (Core[nCore].ch[0] == 's' || Core[nCore].ch[0] == 'y' #ifdef H || (Core[nCore].ch[0] == 'a' && Core[nCore].L == 0) #endif )){ return(0); } if(CorF == 0 && 'a' <= *p && *p <= 'z' && Core[nCore].ch[0] == 'a'){ return(0); } if(Core[nCore].ch[0] == 'y'){ char ch; ch =Core[nCore].ch[1]; if(ch == 'c' || ch == 'd' || ch == 'e' || ch == 'm' || ch == 'p' || ch == 'x'){ return(1); } } if(Core[nCore].Lp){ p =Core[nCore].sp; if(*p == '0'){ return(0); } Core[nCore].Lp =*p-'0'; *p++ ='\0'; while(*p != '\0'){ Core[nCore].Lp =Core[nCore].Lp*10+(*p-'0'); *p++ ='\0'; } } if(Core[nCore].Lb){ p =Core[nCore].sb; if(*p == '0'){ return(0); } Core[nCore].Lb =*p-'0'; *p++ ='\0'; while(*p != '\0'){ Core[nCore].Lb =Core[nCore].Lb*10+(*p-'0'); *p++ ='\0'; } } L =Core[nCore].Lp+Core[nCore].Lb; Core[nCore].L =L; i =0; p =str+1; while(*p != '\0' && i < L){ p++; i++; } if(i == L){ return(1); } return(0); } int IsCore(char *str){ int i; char *p,*t; CleanCore(Core+nCore); p =str; if(*p == '_'){ p++; Core[nCore].ch[1] =' '; while(*p == '_'){ p++; } return(p-str); } i =0; while(i < Icr && *p != cr[i]){ i++; } if(i == Icr){ if('A' <= *p && *p <= 'Z'){ Core[nCore].ch[0] ='A'; Core[nCore].ch[1] =*p; return(1); } if(isdigit(*p)){ Core[nCore].ch[0] ='y'; Core[nCore].ch[1] ='d'; } else{ Core[nCore].ch[1] =*p; return(1); } } if(!isdigit(*p)){ Core[nCore].ch[0] =*p; p++; if(*p == '\0'){ Core[nCore].ch[1] =Core[nCore].ch[0]; Core[nCore].ch[0] ='s'; return(1); } } t =Core[nCore].sp; while(isdigit(*p)){ *t++ =*p++; } Core[nCore].Lp =t-Core[nCore].sp; Core[nCore].L =Core[nCore].Lp; if(*p == '_'){ p++; t =Core[nCore].sb; while(isdigit(*p)){ *t++ =*p++; } Core[nCore].Lb =t-Core[nCore].sb; Core[nCore].L +=Core[nCore].Lb; if(Core[nCore].ch[1] == 'd'){ return((int)(p-str)); } Core[nCore].ch[1] =*p; } else{ if(Core[nCore].ch[1] == 'd'){ return((int)(p-str)); } Core[nCore].ch[1] =*p; t =Core[nCore].ch+1; if(Core[nCore].ch[0] != 'y' || (*t != 'c' && *t != 'd' && *t != 'e' && *t != 'f' && *t != 'h' && *t != 'm' && *t != 'p' && *t != 'x')){ t =Core[nCore].sp; i =0; while(*t != '\0'){ Core[nCore].sb[i] =*t; *t++ ='\0'; i++; } Core[nCore].Lb =i; Core[nCore].Lp =0; } } if(*p != '\0' && IsGoodCoreArg(p)){ return((int)(p+1-str)); } Core[nCore].ch[1] =Core[nCore].ch[0]; Core[nCore].ch[0] ='s'; t =Core[nCore].sp; while(*t != '\0'){ *t++ ='\0'; } t =Core[nCore].sb; while(*t != '\0'){ *t++ ='\0'; } Core[nCore].Lp =0; Core[nCore].Lb =0; Core[nCore].L =0; return(1); } int CleanSuffix(SUFFIX *S) { int i; for(i=0; i < 32; i++){ S->sp[i] ='\0'; S->sb[i] ='\0'; } S->Lp =0; S->Lb =0; S->L =0; return(0); } int PrintSuffix() { char *t; printf("Suffix:\n"); t =Suff[nSuff].sp; if(*t != '\0'){ putchar('^'); putchar(*t); t++; while(*t != '\0'){ putchar(*t); t++; } } t =Suff[nSuff].sb; if(*t != '\0'){ putchar('_'); putchar(*t); t++; while(*t != '\0'){ putchar(*t); t++; } } printf(" Lp=%d Lb=%d L=%d\n",Suff[nSuff].Lp,Suff[nSuff].Lb,Suff[nSuff].L); return(0); } int IsCSuffix(char *str){ char *p,*t; CleanSuffix(Suff+nSuff); t =Core[nCore].ch+1; if(*t == ' ' ||*t == '\0' || (Core[nCore].ch[0] == 'y' && (*t == 'c' || *t == 'd' || *t == 'e' || *t == 'm' || *t == 'p' || *t == 'x'))){ return(0); } p =str; if(Core[nCore].L){ int i,L; L =Core[nCore].Lp; Suff[nSuff].Lp =L; t =Suff[nSuff].sp; i =0; for(i=0; i < L; i++){ *t++ =*p++; } L =Core[nCore].Lb; Suff[nSuff].Lb =L; t =Suff[nSuff].sb; i =0; for(i=0; i < L; i++){ *t++ =*p++; } Suff[nSuff].L =Suff[nSuff].Lp+Suff[nSuff].Lb; } else{ t =Suff[nSuff].sp; if(Core[nCore].ch[0] == 'A' && 'A' <= Core[nCore].ch[1] && Core[nCore].ch[1] <= 'Z'){ while(*p != '\0' && *p != '_' && (*p < 'A' || 'Z' < *p)){ *t++ =*p++; } } else{ while(IsExtDigitChar(*p)){ *t++ =*p++; } } Suff[nSuff].Lp =t-Suff[nSuff].sp; if(*p == '_'){ p++; t =Suff[nSuff].sb; if(Core[nCore].ch[0] == 'A' && 'A' <= Core[nCore].ch[1] && Core[nCore].ch[1] <= 'Z'){ while(*p != '\0' && *p != '_' && (*p < 'A' || 'Z' < *p)){ *t++ =*p++; } } else{ while(IsExtDigitChar(*p)){ *t++ =*p++; } } Suff[nSuff].Lb =t-Suff[nSuff].sb; Suff[nSuff].L =Suff[nSuff].Lp+Suff[nSuff].Lb; if(Suff[nSuff].L == 0){ return(0); } } else{ char *v; v =Suff[nSuff].sp; t =Suff[nSuff].sb; while(*v != '\0'){ *t++ =*v; *v++ ='\0'; } Suff[nSuff].Lb =Suff[nSuff].Lp; Suff[nSuff].Lp =0; Suff[nSuff].L =Suff[nSuff].Lb; } } return((int)(p-str)); } int IsCTokenName(char *str) { int i,m,k; char *p,*t; m =0; p =str; if(IsPseudoDigitChar(*p) && isalpha(*(p+1))){ CleanPrefix(Pr); Pr[nPr].ch[0] =*p; nPr++; p++; m++; } while(i=IsPrefix(p)){ p +=i; m +=i; k =nPr; nPr++; if(Pr[k].L && (Pr[k].ch[0] == 'b' || Pr[k].ch[0] == 't')){ CleanCore(Core+nCore); break; } } if(nPr == 0 || Pr[nPr-1].L == 0){ i =IsCore(p); m +=i; p +=i; } i =IsCSuffix(p); m +=i; p +=i; #ifdef H PrintPrefix(); PrintCore(); PrintSuffix(); printf("Rest:\n"); printf("%s\n",p); #endif return(m); } static int nB=0,nE=0; static char *beg,*end; static int iW; /* number of horizontal tokens */ static int iH; /* number of vertical tokens */ static int iP; /* presence of superscript */ static int iB; /* presence of subscript */ static int iD; /* presence of dashed derivatives */ static int iT; /* presence of top symbol */ static int iF; /* font choice */ int Oper2LaTeX() { char *e; e =Op[nOp].B1; switch(Op[nOp].ch){ case 'a': *e++ ='\\'; *e++ ='&'; *e++ =' '; break; case 'c': *e++ ='\\'; *e++ ='c'; *e++ ='d'; *e++ ='o'; *e++ ='t'; *e++ =' '; break; case 'd': *e++ ='.'; break; case 'e': *e++ ='='; break; case 'f': *e++ ='/'; break; case 'h': *e++ ='\\'; *e++ ='h'; *e++ ='{'; *e++ ='\\'; *e++ =' '; *e++ ='}'; break; case 'i': *e++ ='\\'; *e++ ='i'; *e++ ='n'; *e++ ='t'; *e++ =' '; break; case 'm': *e++ ='-'; break; case 'p': *e++ ='+'; break; case 'r': *e++ ='\\'; *e++ ='p'; *e++ ='a'; *e++ ='r'; *e++ ='a'; *e++ ='l'; *e++ ='l'; *e++ ='e'; *e++ ='l'; *e++ =' '; break; case 'x': *e++ ='\\'; *e++ ='t'; *e++ ='i'; *e++ ='m'; *e++ ='e'; *e++ ='s'; *e++ =' '; break; default : *e++ ='@'; break; } return(0); } int Oper2LaTeXFile(FILE *fp, int iO) { char *e; int i; e =Op[iO].B1; while(*e != '\0'){ putc(*e++,fp); } putchar('\n'); return(0); } int Brackets2LaTeX(char l, char r) { *beg++ =l; *beg++ ='t'; *beg++ ='f'; *beg++ ='e'; *beg++ ='l'; *beg++ ='\\'; *end++ ='\\'; *end++ ='r'; *end++ ='i'; *end++ ='g'; *end++ ='h'; *end++ ='t'; *end++ =r; return(0); } int Fraction2Factor() { int k; if(Pr[nPr].Lp == 0 && Pr[nPr].Lb == 0){ return(0); } k =0; if(Pr[nPr].Lb == 1 && Pr[nPr].sb[0] == '1'){ Pr[nPr].Lb =0; Pr[nPr].sb[0] ='\0'; k |=1; } if(Pr[nPr].Lb == 0 && Pr[nPr].Lp == 1 && Pr[nPr].sp[0] == '1'){ Pr[nPr].Lp =0; Pr[nPr].sp[0] ='\0'; k |=2; } if(k && Pr[nPr].Lp == 0 && Pr[nPr].Lb == 0){ Pr[nPr].Lp =1; Pr[nPr].sp[0] ='1'; return(1); } return(2); } int Fraction2LaTeX() { int i; char *t; *beg++ ='}'; i =Pr[nPr].Lb; t =Pr[nPr].sb+i; while(i){ i--; t--; *beg++ =*t; } *beg++ ='{'; *beg++ ='}'; i =Pr[nPr].Lp; if(i){ t =Pr[nPr].sp+i; while(i){ i--; t--; *beg++ =*t; } } else{ *beg++ ='1'; } *beg++ ='{'; *beg++ ='R'; *beg++ ='\\'; return(0); } int Factor2LaTeX() { int i; char *t; if(Pr[nPr].Lp == 0){ return(0); } i =Pr[nPr].Lp; t =Pr[nPr].sp+i; while(i){ i--; t--; *beg++ =*t; } return(0); } int InvFraction2Factor() { int k; if(Pr[nPr].Lp == 0 && Pr[nPr].Lb == 0){ return(0); } k =0; if(Pr[nPr].Lp == 1 && Pr[nPr].sp[0] == '1'){ Pr[nPr].Lp =0; Pr[nPr].sp[0] ='\0'; k |=1; } if(Pr[nPr].Lp == 0 && Pr[nPr].Lb == 1 && Pr[nPr].sb[0] == '1'){ Pr[nPr].Lb =0; Pr[nPr].sb[0] ='\0'; k |=2; } if(k && Pr[nPr].Lp == 0 && Pr[nPr].Lb == 0){ Pr[nPr].Lb =1; Pr[nPr].sb[0] ='1'; return(1); } return(2); } int InvFraction2LaTeX() { int i; char *t; *beg++ ='}'; i =Pr[nPr].Lp; t =Pr[nPr].sp+i; while(i){ i--; t--; *beg++ =*t; } *beg++ ='{'; *beg++ ='}'; i =Pr[nPr].Lb; if(i){ t =Pr[nPr].sb+i; while(i){ i--; t--; *beg++ =*t; } } else{ *beg++ ='1'; } *beg++ ='{'; *beg++ ='R'; *beg++ ='\\'; return(0); } int InvFactor2LaTeX() { int i; char *t; if(Pr[nPr].Lb == 0){ return(0); } i =Pr[nPr].Lb; t =Pr[nPr].sb+i; while(i){ i--; t--; *beg++ =*t; } return(0); } int Power2Latex(int ind1) { int n,k; char ch,*t; n =0; while(nPr >= 0 && ((ch=Pr[nPr].ch[0]) == 'p' || ch == 'q' || (ch == 'r' && Pr[nPr].Lp == 0 && Pr[nPr].Lb == 0))){ nPr--; n++; } k =nPr+1; while(n > 0){ nPr++; n--; switch(Pr[nPr].ch[0]){ case 'p': Fraction2Factor(); if(Pr[nPr].Lb){ *end++ ='\\'; *end++ ='R'; *end++ ='{'; if(Pr[nPr].Lp){ t =Pr[nPr].sp; while(*t != '\0'){ *end++ =*t++; } } else{ *end++ ='1'; } *end++ ='}'; *end++ ='{'; t =Pr[nPr].sb; while(*t != '\0'){ *end++ =*t++; } *end++ ='}'; } else{ if(Pr[nPr].Lp){ t =Pr[nPr].sp; while(*t != '\0'){ *end++ =*t++; } } else{ *end++ ='2'; } } if(n){ ch =Pr[nPr+1].ch[0]; if(ch == 'p' || ch == 'q'){ *end++ ='+'; } } break; case 'q': InvFraction2Factor(); if(Pr[nPr].Lp){ *end++ ='\\'; *end++ ='R'; *end++ ='{'; if(Pr[nPr].Lb){ t =Pr[nPr].sb; while(*t != '\0'){ *end++ =*t++; } } else{ *end++ ='1'; } *end++ ='}'; *end++ ='{'; t =Pr[nPr].sp; while(*t != '\0'){ *end++ =*t++; } *end++ ='}'; } else{ if(Pr[nPr].Lb){ t =Pr[nPr].sb; while(*t != '\0'){ *end++ =*t++; } } else{ *end++ ='\\'; *end++ ='r'; *end++ ='{'; *end++ ='2'; *end++ ='}'; } } if(n){ ch =Pr[nPr+1].ch[0]; if(ch == 'p' || ch == 'q'){ *end++ ='+'; } } break; case 'r': if(n){ ch =Pr[nPr+1].ch[0]; *end++ ='-'; if(ch != 'p' && ch != 'q'){ *end++ ='1'; } } else{ *end++ ='-'; *end++ ='1'; } break; default : break; } } nPr =k; return(0); } int Prefix2LaTeX() { int i; char ch,*t; /* Prefix */ while(nPr){ nPr--; if(Pr[nPr].ch[0] < 'f'){ switch(Pr[nPr].ch[0]){ case 'b': if(Pr[nPr].Lp || Pr[nPr].Lb){ if(iW > 1 || iH || iP || iB || iD || iT > 1){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; iT =0; } } if(Pr[nPr].Lp){ iP++; *end++ ='^'; *end++ ='{'; t =Pr[nPr].sp; while(*t != '\0'){ if(*t == '_'){ *end++ ='\\'; } *end++ =*t++; } *end++ ='}'; } if(Pr[nPr].Lb){ iB++; *end++ ='_'; *end++ ='{'; t =Pr[nPr].sb; while(*t != '\0'){ if(*t == '_'){ *end++ ='\\'; } *end++ =*t++; } *end++ ='}'; } if(Pr[nPr].sp[0] == '\0' && Pr[nPr].sb[0] == '\0'){ *beg++ ='{'; *beg++ ='b'; *beg++ ='\\'; *end++ ='}'; iT++; } break; case 'c': /* */ i =Fraction2Factor(); if(i < 2 && Pr[nPr].ch[1] != 'm'){ break; } if(iW > 1){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; iT =0; } if(Pr[nPr].Lb){ Fraction2LaTeX(); iW++; iH =1; } else{ if(i > 1){ Factor2LaTeX(); iW++; } } if(Pr[nPr].ch[1] == 'm'){ *beg++ ='-'; iW++; } break; case 'd': if(iW > 1 || iH || iP || iD || iT > 1 || (iB && Pr[nPr].Lb)){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; } if(Pr[nPr].Lp){ t =Pr[nPr].sp; i =*t-'0'; t++; while(*t != '\0'){ i =i*10+(*t-'0'); t++; } if(i > 3){ *end++ ='^'; *end++ ='{'; *end++ ='('; t =Pr[nPr].sp; while(*t != '\0'){ *end++ =*t++; } *end++ =')'; *end++ ='}'; iP++; } else{ while(i > 0){ *end++ ='\''; i--; iD++; } } if(Pr[nPr].Lb){ *end++ ='_'; if(Pr[nPr].Lb > 1){ *end++ ='{'; t =Pr[nPr].sb; while(*t != '\0'){ *end++ =*t++; } *end++ ='}'; } else{ *end++ =Pr[nPr].sb[0]; } iB++; } } else{ *beg++ ='{'; *beg++ ='d'; *beg++ ='\\'; *end++ ='}'; iT++; } break; case 'e': iH =0; i =Fraction2Factor(); if(iW > 1){ Brackets2LaTeX('(',')'); } *beg++ ='{'; *beg++ ='^'; if(Pr[nPr].Lb){ *beg++ =')'; *beg++ ='t'; *beg++ ='h'; *beg++ ='g'; *beg++ ='i'; *beg++ ='r'; *beg++ ='\\'; Fraction2LaTeX(); *beg++ ='('; *beg++ ='t'; *beg++ ='f'; *beg++ ='e'; *beg++ ='l'; *beg++ ='\\'; iH =1; } else{ if(i){ if(Pr[nPr].Lp > 1){ *beg++ =')'; *beg++ ='t'; *beg++ ='h'; *beg++ ='g'; *beg++ ='i'; *beg++ ='r'; *beg++ ='\\'; } Factor2LaTeX(); if(Pr[nPr].Lp > 1){ *beg++ ='('; *beg++ ='t'; *beg++ ='f'; *beg++ ='e'; *beg++ ='l'; *beg++ ='\\'; } } else{ *beg++ ='e'; } } *end++ ='}'; iW =1; iP =1; iB =0; iD =0; iT =0; break; default : break; } } if(Pr[nPr].ch[0] == 'f'){ if(Pr[nPr].ch[1] < 'o'){ switch(Pr[nPr].ch[1]){ case 'a': i =Fraction2Factor(); if(iW > 1){ Brackets2LaTeX('(',')'); } if(Pr[nPr].Lb){ Fraction2LaTeX(); } else{ if(i > 1){ Factor2LaTeX(); } } Brackets2LaTeX('|','|'); iW =1; iH =0; iP =0; iB =0; iD =0; break; case 'c': i =Fraction2Factor(); if(iW > 1){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; } if(Pr[nPr].Lb){ Fraction2LaTeX(); iW++; iH++; } else{ if(i > 1){ Factor2LaTeX(); iW++; } } *beg++ =' '; *beg++ ='s'; *beg++ ='o'; *beg++ ='c'; *beg++ ='\\'; iW++; break; case 'l': i =Fraction2Factor(); if(iW > 1){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; } if(Pr[nPr].Lb){ *beg++ ='}'; Fraction2LaTeX(); *beg++ ='{'; iW++; iH++; } else{ if(i){ *beg++ ='}'; Factor2LaTeX(); *beg++ ='{'; iW++; } } if(i){ *beg++ ='_'; *beg++ ='g'; *beg++ ='o'; *beg++ ='l'; *beg++ ='\\'; iB++; } else{ *beg++ =' '; *beg++ ='n'; *beg++ ='l'; *beg++ ='\\'; } iW++; break; default : i =Fraction2Factor(); if(iW > 1){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; } if(Pr[nPr].Lb){ Fraction2LaTeX(); iW++; iH++; } else{ if(i > 1){ Factor2LaTeX(); iW++; } } *beg++ ='}'; *beg++ ='#'; *beg++ ='\\'; *beg++ ='{'; iW++; break; } } if(Pr[nPr].ch[1] >= 'o'){ switch(Pr[nPr].ch[1]){ case 's': i =Fraction2Factor(); if(iW > 1){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; iT =0; } if(Pr[nPr].Lb){ Fraction2LaTeX(); iW++; iH++; } else{ if(i > 1){ Factor2LaTeX(); iW++; } } iW++; *beg++ =' '; *beg++ ='n'; *beg++ ='i'; *beg++ ='s'; *beg++ ='\\'; break; default : i =Fraction2Factor(); if(iW > 1){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; } if(Pr[nPr].Lb){ Fraction2LaTeX(); iW++; iH++; } else{ if(i > 1){ Factor2LaTeX(); iW++; } } *beg++ ='}'; *beg++ ='#'; *beg++ ='\\'; *beg++ ='{'; iW++; break; } } } if(Pr[nPr].ch[0] > 'f'){ switch(Pr[nPr].ch[0]){ case 'h': i =InvFraction2Factor(); if(i == 1 && (nPr == 0 || (Pr[nPr-1].ch[0] != 'p' && Pr[nPr-1].ch[0] != 'q' && (Pr[nPr-1].ch[0] != 'r' || Pr[nPr-1].Lp || Pr[nPr-1].Lb)))){ break; } if(iW > 1 && (Pr[nPr].Lp || Pr[nPr].Lb)){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; iT =0; } if(Pr[nPr].Lp){ InvFraction2LaTeX(); iW++; iH++; } else{ if(Pr[nPr].Lb){ InvFactor2LaTeX(); iW++; } else{ *beg++ ='{'; *beg++ ='h'; *beg++ ='\\'; *end++ ='}'; iT++; } } break; case 'p': i =Fraction2Factor(); if(i == 1 && (nPr == 0 || (Pr[nPr-1].ch[0] != 'p' && Pr[nPr-1].ch[0] != 'q' && (Pr[nPr-1].ch[0] != 'r' || Pr[nPr-1].Lp || Pr[nPr-1].Lb)))){ break; } if(iW > 1 || iH || iP || iT > 1){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; iT =0; } *end++ ='^'; *end++ ='{'; Power2Latex(i); *end++ ='}'; iP++; break; case 'q': i =InvFraction2Factor(); if(nPr == 0 || (Pr[nPr-1].ch[0] != 'p' && Pr[nPr-1].ch[0] != 'q' && (Pr[nPr-1].ch[0] != 'r' || Pr[nPr-1].Lp || Pr[nPr-1].Lb))){ if(i == 1){ break; } if((Pr[nPr].Lp == 0 && Pr[nPr].Lb == 0) || (Pr[nPr].sp[0] == '2' && Pr[nPr].Lp == 1 && (Pr[nPr].Lb == 0 || (Pr[nPr].Lb == 1 && Pr[nPr].sb[0] == '1')))){ *beg++ ='{'; *beg++ ='q'; *beg++ ='\\'; *end++ ='}'; iW =1; iH =0; iP =0; iB =0; iD =0; iT =1; break; } } if(iW > 1 || iH || iP || iT > 1){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; iT =0; } *end++ ='^'; *end++ ='{'; Power2Latex(i); *end++ ='}'; iP++; break; case 'r': i =Fraction2Factor(); if(i == 0 && nPr && (Pr[nPr-1].ch[0] == 'p' || Pr[nPr-1].ch[0] == 'q' || (Pr[nPr-1].ch[0] == 'r' && Pr[nPr-1].Lp == 0 && Pr[nPr-1].Lb == 0) )){ if(iW > 1 || iH || iP || iT > 1){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; iT =0; } *end++ ='^'; *end++ ='{'; Power2Latex(i); *end++ ='}'; iP++; break; } if(iW > 1 && Pr[nPr].Lb){ Brackets2LaTeX('(',')'); } if(Pr[nPr].Lb){ i =Pr[nPr].Lb; t =Pr[nPr].sb+i; while(i > 0){ i--; t--; *beg++ =*t; } } *beg++ ='{'; if(Pr[nPr].Lp){ *beg++ ='}'; i =Pr[nPr].Lp; t =Pr[nPr].sp+i; while(i > 0){ i--; t--; *beg++ =*t; } *beg++ ='{'; *beg++ ='R'; *beg++ ='\\'; } else{ *beg++ ='r'; *beg++ ='\\'; } *end++ ='}'; iW =1; iH =1; iP =0; iB =0; iD =0; iT =0; break; case 't': if(Pr[nPr].Lp || Pr[nPr].Lb){ if(iW > 1 || iH || iP || iB || iD || iT > 1){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; iT =0; } } if(Pr[nPr].Lp){ char *b; Df[nDf].ch ='p'; Df[nDf].iW =iW; Df[nDf].iH =iH; Df[nDf].iP =iP; Df[nDf].iB =iB; Df[nDf].iD =iD; Df[nDf].iT =iT; t =Pr[i].sp; b =Df[nDf].Obj; while(*t != '\0'){ *b++ =*t++; } *b++ ='\0'; *end++ ='^'; *end++ ='{'; *end++ ='\\'; *end++ ='N'; *end++ ='G'; *end++ ='S'; *end++ ='a'+nDf; *end++ ='}'; nDf++; iP++; } if(Pr[nPr].Lb){ char *b; Df[nDf].ch ='p'; Df[nDf].iW =iW; Df[nDf].iH =iH; Df[nDf].iP =iP; Df[nDf].iB =iB; Df[nDf].iD =iD; Df[nDf].iT =iT; t =Pr[i].sb; b =Df[nDf].Obj; while(*t != '\0'){ *b++ =*t++; } *b++ ='\0'; *end++ ='_'; *end++ ='{'; *end++ ='\\'; *end++ ='N'; *end++ ='G'; *end++ ='S'; *end++ ='a'+nDf; *end++ ='}'; nDf++; iB++; } if(Pr[nPr].sp[0] == '\0' && Pr[nPr].sb[0] == '\0'){ *beg++ ='{'; *beg++ ='t'; *beg++ ='\\'; *end++ ='}'; iT++; } break; case 'u': if(iH || (Pr[nPr].Lp && (iW > 1 || iP || iT > 1)) || (Pr[nPr].Lb && (iW > 1 || iB))){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; iT =0; } if(Pr[nPr].Lp || Pr[nPr].Lb){ if(Pr[nPr].Lp){ iP++; *end++ ='^'; *end++ ='{'; *end++ ='['; t =Pr[nPr].sp; while(*t != '\0'){ *end++ =*t++; } *end++ =']'; *end++ ='}'; iP++; } if(Pr[nPr].Lb){ iP++; *end++ ='_'; *end++ ='{'; *end++ ='['; t =Pr[nPr].sb; while(*t != '\0'){ *end++ =*t++; } *end++ =']'; *end++ ='}'; iB++; } } else{ *beg++ ='{'; *beg++ ='u'; *beg++ ='\\'; *end++ ='}'; } break; case 'v': if(iH || (Pr[nPr].Lp && (iW > 1 || iP || iT > 1)) || (Pr[nPr].Lb && (iW > 1 || iB))){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; iT =0; } if(Pr[nPr].Lp || Pr[nPr].Lb){ if(Pr[nPr].Lp){ iP++; *end++ ='^'; *end++ ='{'; *end++ ='['; t =Pr[nPr].sp; while(*t != '\0'){ *end++ =*t++; } *end++ =']'; *end++ ='}'; iP++; } if(Pr[nPr].Lb){ iP++; *end++ ='_'; *end++ ='{'; *end++ ='['; t =Pr[nPr].sb; while(*t != '\0'){ *end++ =*t++; } *end++ =']'; *end++ ='}'; iB++; } } else{ *beg++ ='{'; *beg++ ='v'; *beg++ ='\\'; *end++ ='}'; iT++; } break; case 'w': if(iH || (Pr[nPr].Lp && (iW > 1 || iP || iT > 1)) || (Pr[nPr].Lb && (iW > 1 || iB))){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; iT =0; } if(Pr[nPr].Lp || Pr[nPr].Lb){ if(Pr[nPr].Lp){ iP++; *end++ ='^'; *end++ ='{'; *end++ ='['; t =Pr[nPr].sp; while(*t != '\0'){ *end++ =*t++; } *end++ =']'; *end++ ='}'; iP++; } if(Pr[nPr].Lb){ iP++; *end++ ='_'; *end++ ='{'; *end++ ='['; t =Pr[nPr].sb; while(*t != '\0'){ *end++ =*t++; } *end++ =']'; *end++ ='}'; iB++; } } break; case 'x': i =Fraction2Factor(); if(i == 1){ break; } if(iW > 1){ Brackets2LaTeX('(',')'); iW =1; iH =0; iP =0; iB =0; iD =0; iT =0; } if(Pr[nPr].Lb){ Fraction2LaTeX(); iW++; iH =1; } else{ if(i){ Factor2LaTeX(); iW++; } else{ *end++ ='^'; *end++ ='*'; iP++; } } break; default : if(nPr == 0 && IsExtDigitChar(Pr[nPr].ch[0]) && Core[nCore].ch[0] == 'y'){ *beg++ =Pr[nPr].ch[0]; iW++; } break; } } } } int CoreFraction2Factor() { int k; if(Core[nCore].Lp == 0 && Core[nCore].Lb == 0){ return(0); } if(Core[nCore].Lb == 1 && Core[nCore].sb[0] == '1'){ Core[nCore].Lb =0; Core[nCore].sb[0] ='\0'; } if(Core[nCore].Lb == 0 && Core[nCore].Lp == 1 && Core[nCore].sp[0] == '1'){ Core[nCore].Lp =0; Core[nCore].sp[0] ='\0'; } return(0); } int CoreFraction2Latex() { int i; char *t; if(Core[nCore].Lb){ if(Core[nCore].Lp){ *end++ ='\\'; *end++ ='R'; *end++ ='{'; t =Core[nCore].sp; while(*t != '\0'){ *end++ =*t++; } *end++ ='}'; *end++ ='{'; } else{ *end++ ='\\'; *end++ ='r'; *end++ ='{'; } t =Core[nCore].sb; while(*t != '\0'){ *end++ =*t++; } *end++ ='}'; return(1); } i =0; if(Core[nCore].Lp){ t =Core[nCore].sp; while(*t != '\0'){ *end++ =*t++; i++; } } return(i); } int Core2Latex() { int i; char ch,*t; if(Core[nCore].ch[1] == '\0'){ return(0); } switch(Core[nCore].ch[0]){ case 'a': *end++ =CorF ? toupper(Core[nCore].ch[1]) : Core[nCore].ch[1]; iW++; break; case 'g': *end++ ='\\'; *end++ ='g'; *end++ =Core[nCore].ch[1]; iW++; break; case 'y': switch(Core[nCore].ch[1]){ case 'a': *end++ ='\\'; *end++ ='&'; iW++; break; case 'c': *end++ ='\\'; *end++ ='c'; *end++ ='d'; *end++ ='o'; *end++ ='t'; iW++; CoreFraction2Factor(); iW +=CoreFraction2Latex(); if(Core[nCore].Lb){ iH++; } break; case 'd': t =Core[nCore].sp; while(*t != '\0'){ *end++ =*t++; iW++; } if(Core[nCore].Lb || Core[nCore].Lp == 0){ *end++ ='.'; iW++; } t =Core[nCore].sb; while(*t != '\0'){ *end++ =*t++; iW++; } break; case 'e': *end++ ='='; iW++; CoreFraction2Factor(); iW +=CoreFraction2Latex(); if(Core[nCore].Lb){ iH++; } break; case 'f': if(Core[nCore].L == 0){ *end++ ='/'; iW++; } break; case 'g': *end++ ='\\'; *end++ ='n'; *end++ ='a'; iW++; break; case 'h': if(Core[nCore].L == 0){ *end++ ='\\'; *end++ ='h'; *end++ ='{'; *end++ ='\\'; *end++ =' '; *end++ ='}'; iW++; } break; case 'i': *end++ ='\\'; *end++ ='i'; *end++ ='n'; *end++ ='t'; iW++; break; case 'm': *end++ ='-'; iW++; CoreFraction2Factor(); iW +=CoreFraction2Latex(); if(Core[nCore].Lb){ iH++; } break; case 'n': *end++ ='\\'; *end++ ='p'; *end++ ='r'; *end++ ='o'; *end++ ='d'; iW++; break; case 'o': *end++ ='\\'; *end++ ='o'; *end++ ='i'; *end++ ='n'; *end++ ='t'; iW++; break; case 'p': *end++ ='+'; iW++; CoreFraction2Factor(); iW +=CoreFraction2Latex(); if(Core[nCore].Lb){ iH++; } break; case 'r': *end++ ='\\'; *end++ ='p'; *end++ ='a'; *end++ ='r'; *end++ ='a'; *end++ ='l'; *end++ ='l'; *end++ ='e'; *end++ ='l'; iW++; break; case 's': *end++ ='\\'; *end++ ='s'; *end++ ='u'; *end++ ='m'; iW++; break; case 't': *end++ ='\\'; *end++ ='g'; *end++ ='D'; iW++; break; case 'x': *end++ ='\\'; *end++ ='t'; *end++ ='i'; *end++ ='m'; *end++ ='e'; *end++ ='s'; iW++; CoreFraction2Factor(); iW +=CoreFraction2Latex(); if(Core[nCore].Lb){ iH++; } break; default : *end++ ='@'; break; } break; case 'z': *end++ ='\\'; *end++ ='z'; *end++ =Core[nCore].ch[1]; iW++; break; default : if(nCore && Core[nCore].ch[1] == ' '){ *end++ ='\\'; } *end++ =Core[nCore].ch[1]; iW++; break; } return(0); } int TokenName2LaTeX() { int i; char ch,*t; iW =0; iH =0; iP =0; iB =0; iD =0; iT =0; beg =Core[nCore].B1; end =Core[nCore].B2; /* Core font */ iF =0; if(IsExtDigitChar(Pr[0].ch[0])){ iF =1; } for(i=0; i < nPr; i++){ ch =Pr[i].ch[0]; if(ch == 'c'){ iF |=1; } if((Pr[i].Lp || Pr[i].Lb) && (ch == 'u' || ch == 'v')){ iF |=2; } if(ch == 'w'){ iF |=4; } } i =nPr-1; if(nPr && Pr[i].L){ if(Pr[i].ch[0] == 'b'){ int k; t =Pr[i].sp+Pr[i].L; k =Pr[i].L; while(k > 0){ k--; t--; *beg++ =*t; iW++; if(*t == '_'){ *beg++ ='\\'; } } } if(Pr[i].ch[0] == 't'){ char *b; Df[nDf].ch ='c'; Df[nDf].iW =iW; Df[nDf].iH =iH; Df[nDf].iP =iP; Df[nDf].iB =iB; Df[nDf].iD =iD; Df[nDf].iT =iT; t =Pr[i].sp; b =Df[nDf].Obj; while(*t != '\0'){ *b++ =*t++; } *b++ ='\0'; *beg++ ='}'; *beg++ ='a'+nDf; *beg++ ='S'; *beg++ ='G'; *beg++ ='N'; *beg++ ='\\'; *beg++ ='{'; nDf++; } } Core2Latex(); if(iF){ if((iF&4)){ *beg++ =' '; *beg++ ='f'; *beg++ ='b'; *beg++ ='\\'; *beg++ ='{'; } else{ *beg++ ='{'; if((iF&2)){ *beg++ ='w'; } else{ *beg++ ='c'; } *beg++ ='\\'; } *end++ ='}'; } if(Core[nCore].L){ char *b; Df[nDf].iW =iW; Df[nDf].iH =iH; Df[nDf].iP =iP; Df[nDf].iB =iB; Df[nDf].iD =iD; Df[nDf].iT =iT; if(Core[nCore].ch[0] == 'y' && Core[nCore].ch[1] == 'h'){ if(Suff[nSuff].Lp){ t =Suff[nSuff].sp; Df[nDf].ch ='p'; b =Df[nDf].Obj; while(*t != '\0'){ *b++ =*t++; } *b++ ='\0'; *end++ ='^'; if(Suff[nSuff].Lb){ *end++ ='{'; *end++ ='\\'; *end++ ='R'; } *end++ ='{'; *end++ ='\\'; *end++ ='N'; *end++ ='G'; *end++ ='S'; *end++ ='a'+nDf; *end++ ='}'; nDf++; if(Suff[nSuff].Lb){ t =Suff[nSuff].sb; Df[nDf].ch ='b'; b =Df[nDf].Obj; while(*t != '\0'){ *b++ =*t++; } *b++ ='\0'; *end++ ='{'; *end++ ='\\'; *end++ ='N'; *end++ ='G'; *end++ ='S'; *end++ ='a'+nDf; *end++ ='}'; *end++ ='}'; nDf++; } } else{ t =Suff[nSuff].sb; Df[nDf].ch ='b'; b =Df[nDf].Obj; while(*t != '\0'){ *b++ =*t++; } *b++ ='\0'; *end++ ='^'; *end++ ='{'; *end++ ='\\'; *end++ ='r'; *end++ ='{'; *end++ ='\\'; *end++ ='N'; *end++ ='G'; *end++ ='S'; *end++ ='a'+nDf; *end++ ='}'; *end++ ='}'; nDf++; } Suff[nSuff].Lp =0; Suff[nSuff].Lb =0; iP++; } if(Core[nCore].ch[0] == 'y' && Core[nCore].ch[1] == 'f'){ if(Suff[nSuff].Lp){ t =Suff[nSuff].sp; Df[nDf].ch ='p'; b =Df[nDf].Obj; while(*t != '\0'){ *b++ =*t++; } *b++ ='\0'; if(Suff[nSuff].Lb){ *end++ ='\\'; *end++ ='R'; } *end++ ='{'; *end++ ='\\'; *end++ ='N'; *end++ ='G'; *end++ ='S'; *end++ ='a'+nDf; *end++ ='}'; nDf++; if(Suff[nSuff].Lb){ t =Suff[nSuff].sb; Df[nDf].ch ='b'; b =Df[nDf].Obj; while(*t != '\0'){ *b++ =*t++; } *b++ ='\0'; *end++ ='{'; *end++ ='\\'; *end++ ='N'; *end++ ='G'; *end++ ='S'; *end++ ='a'+nDf; *end++ ='}'; nDf++; } } else{ t =Suff[nSuff].sb; Df[nDf].ch ='b'; b =Df[nDf].Obj; while(*t != '\0'){ *b++ =*t++; } *b++ ='\0'; *end++ ='\\'; *end++ ='r'; *end++ ='{'; *end++ ='\\'; *end++ ='N'; *end++ ='G'; *end++ ='S'; *end++ ='a'+nDf; *end++ ='}'; nDf++; } Suff[nSuff].Lp =0; Suff[nSuff].Lb =0; iH++; } if(Suff[nSuff].Lp){ t =Suff[nSuff].sp; Df[nDf].ch ='p'; b =Df[nDf].Obj; while(*t != '\0'){ *b++ =*t++; } *b++ ='\0'; *end++ ='^'; *end++ ='{'; *end++ ='\\'; *end++ ='N'; *end++ ='G'; *end++ ='S'; *end++ ='a'+nDf; *end++ ='}'; iP++; nDf++; } if(Suff[nSuff].Lb){ t =Suff[nSuff].sb; Df[nDf].ch ='b'; b =Df[nDf].Obj; while(*t != '\0'){ *b++ =*t++; } *b++ ='\0'; *end++ ='_'; *end++ ='{'; *end++ ='\\'; *end++ ='N'; *end++ ='G'; *end++ ='S'; *end++ ='a'+nDf; *end++ ='}'; iB++; nDf++; } } else{ t =Suff[nSuff].sp; if(*t != '\0'){ *end++ ='^'; if(Suff[nSuff].Lp > 1){ *end++ ='{'; } while(*t != '\0'){ *end++ =*t++; } if(Suff[nSuff].Lp > 1){ *end++ ='}'; } iP++; } t =Suff[nSuff].sb; if(*t != '\0'){ *end++ ='_'; if(Suff[nSuff].Lb > 1){ *end++ ='{'; } while(*t != '\0'){ *end++ =*t++; } if(Suff[nSuff].Lb > 1){ *end++ ='}'; } iB++; } } Prefix2LaTeX(); *beg ='\0'; *end ='\0'; Core[nCore].nB =beg-Core[nCore].B1; printf("LaTeX Token: |"); i =Core[nCore].nB; t =beg; while(i){ i--; t--; putchar(*t); } end =Core[nCore].B2; while(*end != '\0'){ putchar(*end++); } putchar('|'); putchar('\n'); return(0); } int TokenName2LaTeXFile(FILE *fp,int iCr) { int i; i =Core[iCr].nB; beg =Core[iCr].B1+i; while(i){ i--; beg--; putc(*beg,fp); } end =Core[iCr].B2; while(*end != '\0'){ putc(*end++,fp); } putc(' ',fp); return(0); } int WriteZZ1(FILE *fp) { fprintf(fp,"\\documentclass[10pt]{article}\n"); fprintf(fp,"\\usepackage{ngs}\n"); fprintf(fp,"\\begin{document}\n"); fprintf(fp,"\\oddsidemargin -1in\n"); fprintf(fp,"\\evensidemargin -1in\n"); fprintf(fp,"\\topmargin -1in\n"); fprintf(fp,"\\textheight 3in\n"); fprintf(fp,"\\textwidth 6.5in\n"); if(CorF){ fprintf(fp,"\\ \\vskip-0.5in\n" "\\fbox{\\tt FORTRAN}-names ({\\em Type \\c{Cntr-F} for \\c{C}})\n"); } else{ fprintf(fp,"\\ \\vskip-0.5in\n" "\\fbox{\\tt C}-names ({\\em Type \\c{Cntr-F} for \\c{FORTRAN}})\n"); } fprintf(fp,"\nTo exit, {\\em type either \\c{bye} or \\c{quit} or \\c{exit}}\n"); return(0); } int WriteZZ2(FILE *fp) { fprintf(fp,"\\end{document}\n"); return(0); } static int FlXdvi=0; int IsEndFile(char *str) { static FILE *lF; static char FF=0; char *ls; if(FF == 0){ lF =fopen("ngs.in","r"); if(lF == NULL){ return(1); } FF =1; } if(feof(lF)){ fclose(lF); return(1); } *str ='\0'; ls =str; *ls=fgetc(lF); ls++; if(*ls == EOF){ fclose(lF); return(1); } while((*ls=fgetc(lF)) != '\n'){ if(*ls == EOF){ break; } ls++; } if(*ls == EOF){ fclose(lF); return(1); } *ls ='\0'; if(FlXdvi == 0){ printf("Type 2s or 3s in Xdvi window to adjust the size of the text\n"); FlXdvi=1; } printf("%c-name from ngs.in=>%s",CorF ? 'F' : 'C',str); if(strcmp(str,"end") && strcmp(str,"quit") && strcmp(str,"bye") && strcmp(str,"exit")){ getchar(); return(0); } fclose(lF); return(1); } int IsKbdEndString(char *str) { char *ls; if(FlXdvi == 0){ printf("Type 3s or 2s in Xdvi window to adjust the size of the text\n"); FlXdvi=1; } printf("%c-name =>",CorF ? 'F' : 'C'); *str ='\0'; ls =str; while((*ls=getchar()) != '\n'){ if(*ls == 6){ CorF ^=1; } else{ ls++; } } *ls ='\0'; if(strcmp(str,"end") && strcmp(str,"quit") && strcmp(str,"bye") && strcmp(str,"exit")){ return(0); } return(1); } int Check4DviFile() { FILE *fp; char sty[]={ 0x5c,0x6e,0x65,0x77,0x66,0x6f,0x6e,0x74,0x7b,0x5c, 0x77,0x6e,0x63,0x79,0x72,0x49,0x49,0x49,0x7d,0x7b, 0x77,0x6e,0x63,0x79,0x72,0x38,0x20,0x73,0x63,0x61, 0x6c,0x65,0x64,0x5c,0x6d,0x61,0x67,0x73,0x74,0x65, 0x70,0x31,0x7d,0x0a,0x5c,0x6e,0x65,0x77,0x66,0x6f, 0x6e,0x74,0x7b,0x5c,0x68,0x65,0x6c,0x76,0x54,0x7d, 0x7b,0x70,0x68,0x76,0x72,0x38,0x72,0x20,0x73,0x63, 0x61,0x6c,0x65,0x64,0x5c,0x6d,0x61,0x67,0x73,0x74, 0x65,0x70,0x30,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c, 0x6d,0x66,0x6e,0x74,0x7b,0x5c,0x68,0x65,0x6c,0x76, 0x54,0x7d,0x0a,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67, 0x61,0x3d,0x5c,0x61,0x6c,0x70,0x68,0x61,0x0a,0x5c, 0x6c,0x65,0x74,0x5c,0x67,0x62,0x3d,0x5c,0x62,0x65, 0x74,0x61,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x63, 0x3d,0x5c,0x63,0x68,0x69,0x0a,0x5c,0x6c,0x65,0x74, 0x5c,0x67,0x64,0x3d,0x5c,0x64,0x65,0x6c,0x74,0x61, 0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x65,0x3d,0x5c, 0x65,0x70,0x73,0x69,0x6c,0x6f,0x6e,0x0a,0x5c,0x6c, 0x65,0x74,0x5c,0x67,0x66,0x3d,0x5c,0x76,0x61,0x72, 0x70,0x68,0x69,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67, 0x67,0x3d,0x5c,0x67,0x61,0x6d,0x6d,0x61,0x0a,0x5c, 0x6c,0x65,0x74,0x5c,0x67,0x68,0x3d,0x5c,0x65,0x74, 0x61,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x69,0x3d, 0x5c,0x69,0x6f,0x74,0x61,0x0a,0x5c,0x6c,0x65,0x74, 0x5c,0x67,0x6a,0x3d,0x5c,0x70,0x68,0x69,0x0a,0x5c, 0x6c,0x65,0x74,0x5c,0x67,0x6b,0x3d,0x5c,0x6b,0x61, 0x70,0x70,0x61,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67, 0x6c,0x3d,0x5c,0x6c,0x61,0x6d,0x62,0x64,0x61,0x0a, 0x5c,0x6c,0x65,0x74,0x5c,0x67,0x6d,0x3d,0x5c,0x6d, 0x75,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x6e,0x3d, 0x5c,0x6e,0x75,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67, 0x6f,0x3d,0x6f,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67, 0x70,0x3d,0x5c,0x70,0x69,0x0a,0x5c,0x6c,0x65,0x74, 0x5c,0x67,0x71,0x3d,0x5c,0x74,0x68,0x65,0x74,0x61, 0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x72,0x3d,0x5c, 0x72,0x68,0x6f,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67, 0x73,0x3d,0x5c,0x73,0x69,0x67,0x6d,0x61,0x0a,0x5c, 0x6c,0x65,0x74,0x5c,0x67,0x74,0x3d,0x5c,0x74,0x61, 0x75,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x75,0x3d, 0x5c,0x75,0x70,0x73,0x69,0x6c,0x6f,0x6e,0x0a,0x5c, 0x6c,0x65,0x74,0x5c,0x67,0x76,0x3d,0x5c,0x76,0x61, 0x72,0x70,0x69,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67, 0x77,0x3d,0x5c,0x6f,0x6d,0x65,0x67,0x61,0x0a,0x5c, 0x6c,0x65,0x74,0x5c,0x67,0x78,0x3d,0x5c,0x78,0x69, 0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x79,0x3d,0x5c, 0x70,0x73,0x69,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67, 0x7a,0x3d,0x5c,0x7a,0x65,0x74,0x61,0x0a,0x5c,0x6c, 0x65,0x74,0x5c,0x67,0x41,0x3d,0x41,0x0a,0x5c,0x6c, 0x65,0x74,0x5c,0x67,0x42,0x3d,0x42,0x0a,0x5c,0x6c, 0x65,0x74,0x5c,0x67,0x43,0x3d,0x58,0x0a,0x5c,0x6c, 0x65,0x74,0x5c,0x67,0x44,0x3d,0x5c,0x44,0x65,0x6c, 0x74,0x61,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x45, 0x3d,0x45,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x46, 0x3d,0x5c,0x50,0x68,0x69,0x0a,0x5c,0x6c,0x65,0x74, 0x5c,0x67,0x47,0x3d,0x5c,0x47,0x61,0x6d,0x6d,0x61, 0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x48,0x3d,0x48, 0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x49,0x3d,0x49, 0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x4a,0x3d,0x5c, 0x76,0x61,0x72,0x74,0x68,0x65,0x74,0x61,0x0a,0x5c, 0x6c,0x65,0x74,0x5c,0x67,0x4b,0x3d,0x4b,0x0a,0x5c, 0x6c,0x65,0x74,0x5c,0x67,0x4c,0x3d,0x5c,0x4c,0x61, 0x6d,0x62,0x64,0x61,0x0a,0x5c,0x6c,0x65,0x74,0x5c, 0x67,0x4d,0x3d,0x4d,0x0a,0x5c,0x6c,0x65,0x74,0x5c, 0x67,0x4e,0x3d,0x4e,0x0a,0x5c,0x6c,0x65,0x74,0x5c, 0x67,0x4f,0x3d,0x4f,0x0a,0x5c,0x6c,0x65,0x74,0x5c, 0x67,0x50,0x3d,0x5c,0x50,0x69,0x0a,0x5c,0x6c,0x65, 0x74,0x5c,0x67,0x51,0x3d,0x5c,0x54,0x68,0x65,0x74, 0x61,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x52,0x3d, 0x52,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x53,0x3d, 0x5c,0x53,0x69,0x67,0x6d,0x61,0x0a,0x5c,0x6c,0x65, 0x74,0x5c,0x67,0x54,0x3d,0x54,0x0a,0x5c,0x6c,0x65, 0x74,0x5c,0x67,0x55,0x3d,0x5c,0x55,0x70,0x73,0x69, 0x6c,0x6f,0x6e,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67, 0x56,0x3d,0x5c,0x76,0x61,0x72,0x73,0x69,0x67,0x6d, 0x61,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x57,0x3d, 0x5c,0x4f,0x6d,0x65,0x67,0x61,0x0a,0x5c,0x6c,0x65, 0x74,0x5c,0x67,0x58,0x3d,0x5c,0x58,0x69,0x0a,0x5c, 0x6c,0x65,0x74,0x5c,0x67,0x59,0x3d,0x5c,0x50,0x73, 0x69,0x0a,0x5c,0x6c,0x65,0x74,0x5c,0x67,0x5a,0x3d, 0x5a,0x0a,0x5c,0x6d,0x61,0x74,0x68,0x63,0x68,0x61, 0x72,0x64,0x65,0x66,0x5c,0x6d,0x75,0x63,0x68,0x67, 0x3d,0x22,0x33,0x32,0x31,0x44,0x0a,0x5c,0x6c,0x65, 0x74,0x5c,0x6e,0x61,0x3d,0x5c,0x6e,0x61,0x62,0x6c, 0x61,0x0a,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x61, 0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e, 0x63,0x79,0x72,0x49,0x49,0x49,0x20,0x61,0x7d,0x7d, 0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x62,0x7b,0x5c, 0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79, 0x72,0x49,0x49,0x49,0x20,0x62,0x7d,0x7d,0x0a,0x5c, 0x64,0x65,0x66,0x5c,0x7a,0x63,0x7b,0x5c,0x6d,0x62, 0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79,0x72,0x49, 0x49,0x49,0x20,0x63,0x7d,0x7d,0x0a,0x5c,0x64,0x65, 0x66,0x5c,0x7a,0x64,0x7b,0x5c,0x6d,0x62,0x6f,0x78, 0x7b,0x5c,0x77,0x6e,0x63,0x79,0x72,0x49,0x49,0x49, 0x20,0x64,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c, 0x7a,0x65,0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c, 0x77,0x6e,0x63,0x79,0x72,0x49,0x49,0x49,0x20,0x65, 0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x66, 0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e, 0x63,0x79,0x72,0x49,0x49,0x49,0x20,0x66,0x7d,0x7d, 0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x67,0x7b,0x5c, 0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79, 0x72,0x49,0x49,0x49,0x20,0x67,0x7d,0x7d,0x0a,0x5c, 0x64,0x65,0x66,0x5c,0x7a,0x68,0x7b,0x5c,0x6d,0x62, 0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79,0x72,0x49, 0x49,0x49,0x20,0x68,0x7d,0x7d,0x0a,0x5c,0x64,0x65, 0x66,0x5c,0x7a,0x69,0x7b,0x5c,0x6d,0x62,0x6f,0x78, 0x7b,0x5c,0x77,0x6e,0x63,0x79,0x72,0x49,0x49,0x49, 0x20,0x69,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c, 0x7a,0x6a,0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c, 0x77,0x6e,0x63,0x79,0x72,0x49,0x49,0x49,0x20,0x6a, 0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x6b, 0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e, 0x63,0x79,0x72,0x49,0x49,0x49,0x20,0x6b,0x7d,0x7d, 0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x6c,0x7b,0x5c, 0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79, 0x72,0x49,0x49,0x49,0x20,0x6c,0x7d,0x7d,0x0a,0x5c, 0x64,0x65,0x66,0x5c,0x7a,0x6d,0x7b,0x5c,0x6d,0x62, 0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79,0x72,0x49, 0x49,0x49,0x20,0x6d,0x7d,0x7d,0x0a,0x5c,0x64,0x65, 0x66,0x5c,0x7a,0x6e,0x7b,0x5c,0x6d,0x62,0x6f,0x78, 0x7b,0x5c,0x77,0x6e,0x63,0x79,0x72,0x49,0x49,0x49, 0x20,0x6e,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c, 0x7a,0x6f,0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c, 0x77,0x6e,0x63,0x79,0x72,0x49,0x49,0x49,0x20,0x6f, 0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x70, 0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e, 0x63,0x79,0x72,0x49,0x49,0x49,0x20,0x70,0x7d,0x7d, 0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x71,0x7b,0x5c, 0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79, 0x72,0x49,0x49,0x49,0x20,0x71,0x7d,0x7d,0x0a,0x5c, 0x64,0x65,0x66,0x5c,0x7a,0x72,0x7b,0x5c,0x6d,0x62, 0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79,0x72,0x49, 0x49,0x49,0x20,0x72,0x7d,0x7d,0x0a,0x5c,0x64,0x65, 0x66,0x5c,0x7a,0x73,0x7b,0x5c,0x6d,0x62,0x6f,0x78, 0x7b,0x5c,0x77,0x6e,0x63,0x79,0x72,0x49,0x49,0x49, 0x20,0x73,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c, 0x7a,0x74,0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c, 0x77,0x6e,0x63,0x79,0x72,0x49,0x49,0x49,0x20,0x74, 0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x75, 0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e, 0x63,0x79,0x72,0x49,0x49,0x49,0x20,0x75,0x7d,0x7d, 0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x76,0x7b,0x5c, 0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79, 0x72,0x49,0x49,0x49,0x20,0x76,0x7d,0x7d,0x0a,0x5c, 0x64,0x65,0x66,0x5c,0x7a,0x77,0x7b,0x5c,0x6d,0x62, 0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79,0x72,0x49, 0x49,0x49,0x20,0x77,0x7d,0x7d,0x0a,0x5c,0x64,0x65, 0x66,0x5c,0x7a,0x78,0x7b,0x5c,0x6d,0x62,0x6f,0x78, 0x7b,0x5c,0x77,0x6e,0x63,0x79,0x72,0x49,0x49,0x49, 0x20,0x78,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c, 0x7a,0x79,0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c, 0x77,0x6e,0x63,0x79,0x72,0x49,0x49,0x49,0x20,0x79, 0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x7a, 0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e, 0x63,0x79,0x72,0x49,0x49,0x49,0x20,0x7a,0x7d,0x7d, 0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x41,0x7b,0x5c, 0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79, 0x62,0x49,0x49,0x49,0x20,0x41,0x7d,0x7d,0x0a,0x5c, 0x64,0x65,0x66,0x5c,0x7a,0x42,0x7b,0x5c,0x6d,0x62, 0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79,0x62,0x49, 0x49,0x49,0x20,0x42,0x7d,0x7d,0x0a,0x5c,0x64,0x65, 0x66,0x5c,0x7a,0x43,0x7b,0x5c,0x6d,0x62,0x6f,0x78, 0x7b,0x5c,0x77,0x6e,0x63,0x79,0x62,0x49,0x49,0x49, 0x20,0x43,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c, 0x7a,0x44,0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c, 0x77,0x6e,0x63,0x79,0x62,0x49,0x49,0x49,0x20,0x44, 0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x45, 0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e, 0x63,0x79,0x62,0x49,0x49,0x49,0x20,0x45,0x7d,0x7d, 0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x46,0x7b,0x5c, 0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79, 0x62,0x49,0x49,0x49,0x20,0x46,0x7d,0x7d,0x0a,0x5c, 0x64,0x65,0x66,0x5c,0x7a,0x47,0x7b,0x5c,0x6d,0x62, 0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79,0x62,0x49, 0x49,0x49,0x20,0x47,0x7d,0x7d,0x0a,0x5c,0x64,0x65, 0x66,0x5c,0x7a,0x48,0x7b,0x5c,0x6d,0x62,0x6f,0x78, 0x7b,0x5c,0x77,0x6e,0x63,0x79,0x62,0x49,0x49,0x49, 0x20,0x48,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c, 0x7a,0x49,0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c, 0x77,0x6e,0x63,0x79,0x62,0x49,0x49,0x49,0x20,0x49, 0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x4a, 0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e, 0x63,0x79,0x62,0x49,0x49,0x49,0x20,0x4a,0x7d,0x7d, 0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x4b,0x7b,0x5c, 0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79, 0x62,0x49,0x49,0x49,0x20,0x4b,0x7d,0x7d,0x0a,0x5c, 0x64,0x65,0x66,0x5c,0x7a,0x4c,0x7b,0x5c,0x6d,0x62, 0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79,0x62,0x49, 0x49,0x49,0x20,0x4c,0x7d,0x7d,0x0a,0x5c,0x64,0x65, 0x66,0x5c,0x7a,0x4d,0x7b,0x5c,0x6d,0x62,0x6f,0x78, 0x7b,0x5c,0x77,0x6e,0x63,0x79,0x62,0x49,0x49,0x49, 0x20,0x4d,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c, 0x7a,0x4e,0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c, 0x77,0x6e,0x63,0x79,0x62,0x49,0x49,0x49,0x20,0x4e, 0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x4f, 0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e, 0x63,0x79,0x62,0x49,0x49,0x49,0x20,0x4f,0x7d,0x7d, 0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x50,0x7b,0x5c, 0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79, 0x62,0x49,0x49,0x49,0x20,0x50,0x7d,0x7d,0x0a,0x5c, 0x64,0x65,0x66,0x5c,0x7a,0x51,0x7b,0x5c,0x6d,0x62, 0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79,0x62,0x49, 0x49,0x49,0x20,0x51,0x7d,0x7d,0x0a,0x5c,0x64,0x65, 0x66,0x5c,0x7a,0x52,0x7b,0x5c,0x6d,0x62,0x6f,0x78, 0x7b,0x5c,0x77,0x6e,0x63,0x79,0x62,0x49,0x49,0x49, 0x20,0x52,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c, 0x7a,0x53,0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c, 0x77,0x6e,0x63,0x79,0x62,0x49,0x49,0x49,0x20,0x53, 0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x54, 0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e, 0x63,0x79,0x62,0x49,0x49,0x49,0x20,0x54,0x7d,0x7d, 0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x55,0x7b,0x5c, 0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79, 0x62,0x49,0x49,0x49,0x20,0x55,0x7d,0x7d,0x0a,0x5c, 0x64,0x65,0x66,0x5c,0x7a,0x56,0x7b,0x5c,0x6d,0x62, 0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79,0x62,0x49, 0x49,0x49,0x20,0x56,0x7d,0x7d,0x0a,0x5c,0x64,0x65, 0x66,0x5c,0x7a,0x57,0x7b,0x5c,0x6d,0x62,0x6f,0x78, 0x7b,0x5c,0x77,0x6e,0x63,0x79,0x62,0x49,0x49,0x49, 0x20,0x57,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c, 0x7a,0x58,0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c, 0x77,0x6e,0x63,0x79,0x62,0x49,0x49,0x49,0x20,0x58, 0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x59, 0x7b,0x5c,0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e, 0x63,0x79,0x62,0x49,0x49,0x49,0x20,0x59,0x7d,0x7d, 0x0a,0x5c,0x64,0x65,0x66,0x5c,0x7a,0x5a,0x7b,0x5c, 0x6d,0x62,0x6f,0x78,0x7b,0x5c,0x77,0x6e,0x63,0x79, 0x62,0x49,0x49,0x49,0x20,0x5a,0x7d,0x7d,0x0a,0x0a, 0x5c,0x64,0x65,0x66,0x5c,0x62,0x23,0x31,0x7b,0x5c, 0x6f,0x76,0x65,0x72,0x6c,0x69,0x6e,0x65,0x7b,0x23, 0x31,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x63, 0x23,0x31,0x7b,0x7b,0x5c,0x74,0x74,0x20,0x23,0x31, 0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x64,0x23, 0x31,0x7b,0x7b,0x5c,0x64,0x6f,0x74,0x7b,0x23,0x31, 0x7d,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x65, 0x23,0x31,0x7b,0x7b,0x65,0x5e,0x7b,0x23,0x31,0x7d, 0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x68,0x23, 0x31,0x7b,0x5c,0x77,0x69,0x64,0x65,0x68,0x61,0x74, 0x7b,0x23,0x31,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66, 0x5c,0x71,0x23,0x31,0x7b,0x5c,0x73,0x71,0x72,0x74, 0x7b,0x23,0x31,0x7d,0x7d,0x0a,0x5c,0x64,0x65,0x66, 0x5c,0x72,0x23,0x31,0x7b,0x7b,0x31,0x5c,0x6f,0x76, 0x65,0x72,0x20,0x23,0x31,0x7d,0x7d,0x20,0x20,0x20, 0x20,0x5c,0x64,0x65,0x66,0x5c,0x52,0x23,0x31,0x23, 0x32,0x7b,0x7b,0x23,0x31,0x5c,0x6f,0x76,0x65,0x72, 0x20,0x23,0x32,0x7d,0x7d,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x0a,0x5c,0x64,0x65, 0x66,0x5c,0x74,0x23,0x31,0x7b,0x5c,0x77,0x69,0x64, 0x65,0x74,0x69,0x6c,0x64,0x65,0x7b,0x23,0x31,0x7d, 0x7d,0x0a,0x5c,0x64,0x65,0x66,0x5c,0x75,0x23,0x31, 0x7b,0x5c,0x75,0x6e,0x64,0x65,0x72,0x6c,0x69,0x6e, 0x65,0x7b,0x23,0x31,0x7d,0x7d,0x0a,0x5c,0x64,0x65, 0x66,0x5c,0x76,0x23,0x31,0x7b,0x5c,0x6f,0x76,0x65, 0x72,0x72,0x69,0x67,0x68,0x74,0x61,0x72,0x72,0x6f, 0x77,0x7b,0x23,0x31,0x7d,0x7d,0x0a,0x5c,0x64,0x65, 0x66,0x5c,0x77,0x23,0x31,0x7b,0x5c,0x6d,0x62,0x6f, 0x78,0x7b,0x5c,0x6d,0x66,0x6e,0x74,0x20,0x23,0x31, 0x7d,0x7d,0x0a,0x0a,0x5c,0x65,0x6e,0x64,0x69,0x6e, 0x70,0x75,0x74,0x0a,0x00}; fp =fopen("ngs.sty","r"); if(fp == NULL){ fp =fopen("ngs.sty","w+"); fprintf(fp,"%s",sty); } fclose(fp); fp =fopen("zz.dvi","r"); if(fp == NULL){ fp =fopen("zz.tex","w+"); WriteZZ1(fp); fprintf(fp,"$$\\c{p2b}\n\\to\nb^2$$\n"); WriteZZ2(fp); fclose(fp); system("latex zz.tex > /dev/null"); } else{ fclose(fp); } return(0); } int Sty2ByteArray() { FILE *fp,*ft; char ch,ch1; int i; ft =fopen("t","w"); fp =fopen("ngs.sty","r"); if(fp == NULL){ return(0); } i =0; ch =getc(fp); fprintf(ft," "); ch1 =ch; while((ch=getc(fp)) != EOF){ fprintf(ft,"0x%2.2x,",ch1); i++; if(i%10 == 0){ fprintf(ft,"\n "); } ch1 =ch; } fprintf(ft,"0x%2.2x,0x00};\n",ch1); fclose(fp); fclose(ft); return(0); } int NameObj2Str(char *Buff,int *K,int nK) { int i,k,kd[16]; int nC,nO,nc,d; char *p,*b; nC =0; nO =0; nc =0; d =0; b =Buff; for(k=0; k < nK; k++){ if(K[k]){ switch(Op[nO].ch){ case 'h': p ="\\right)^{"; while(*p != '\0'){ *b++ =*p++; } kd[d++] =nc; nc =0; break; case 'f': p ="}{"; while(*p != '\0'){ *b++ =*p++; } kd[d++] =nc; nc =0; break; default : p =Op[nO].B1; while(*p != '\0'){ *b++ =*p++; } if(nOp-nO > 1){ p ="\\left("; nc++; while(*p != '\0'){ *b++ =*p++; } } break; } nO++; } else{ if(nO < nOp){ if(Op[nO].ch == 'h'){ p ="\\left("; while(*p != '\0'){ *b++ =*p++; } } if(Op[nO].ch == 'f'){ p ="\\R{"; while(*p != '\0'){ *b++ =*p++; } } } i =Core[nC].nB; p =Core[nC].B1+i; while(i){ i--; p--; *b++ =*p; } p =Core[nC].B2; while(*p != '\0'){ *b++ =*p++; } *b++ =' '; nC++; } } if(d == 0){ while(nc > 0){ p ="\\right)"; while(*p != '\0'){ *b++ =*p++; } nc--; } } while(d > 0){ d--; *b++ ='}'; nc =kd[d]; while(nc > 0){ p ="\\right)"; while(*p != '\0'){ *b++ =*p++; } nc--; } } *b ='\0'; return(0); } int CodeName2LaTeX(char *Buff, char *str) { int iw,ih,ip,ib,id,it; int i,k,m,nK,K[32]; char *p; p =str; nK =0; nCore =0; nOp =0; nDf =1; iw =0; ih =0; ip =0; ib =0; id =0; it =0; while(*p != '\0'){ nPr =0; nSuff =0; m =0; if(nCore){ m =IsOper(p); if(m){ Oper2LaTeX(); K[nK++] =1; nOp++;; } } p +=m; m =IsCTokenName(p); p +=m; if(m){ TokenName2LaTeX(); iw +=iW; K[nK++] =0; nCore++; } } ih =iH; ip =iP; ib =iB; id =iD; it =iT; NameObj2Str(Buff,K,nK); Df[0].ch ='c'; Df[0].iW =iw; Df[0].iH =ih; Df[0].iP =ip; Df[0].iB =ib; Df[0].iD =id; Df[0].iT =it; for(k=1; k < nDf; k++){ p =Df[k].Obj; nK =0; nCore =0; nOp =0; iw =0; ih =0; ip =0; ib =0; id =0; it =0; while(*p != '\0'){ nPr =0; nSuff =0; m =0; if(nCore){ m =IsOper(p); if(m){ Oper2LaTeX(); K[nK++] =1; nOp++;; } } p +=m; m =IsCTokenName(p); p +=m; if(m){ TokenName2LaTeX(); iw +=iW; K[nK++] =0; nCore++; } } ih =iH; ip =iP; ib =iB; id =iD; it =iT; NameObj2Str(Df[k].Obj,K,nK); Df[k].iW =iw; Df[k].iH =ih; Df[k].iP =ip; Df[k].iB =ib; Df[k].iD =id; Df[k].iT =it; } return(0); } int CodeName2CFstring(char *strC,char *strF,char *Nm) { int i; char *p,*t,*v; if(!isalpha(*Nm) && *Nm != '_'){ printf("%s - has a wrong first character\n",Nm); return(0); } p =Nm; i =0; v =strC; t =strF; while(isalnum(*p) || *p == '_'){ *t++ =tolower(*p); *v++ =*p++; i++; } *v ='\0'; *t ='\0'; if(*p != '\0'){ printf("%s Wrong name starting from\n%s\n",Nm,p); return(0); } if(i > 31){ printf("%s Too long name\n",Nm); return(0); } return(1); } int Latex2File(char *str,char *strF,char *Nm) { FILE *fp; int i; char *p; fp =fopen("zz.tex","w+"); WriteZZ1(fp); i =nDf; while(i > 1){ i--; if(Df[i].iW > 1 || (Df[i].ch == 'c' && (Df[i].iH || Df[i].iP || Df[i].iB || Df[i].iD || Df[i].iT > 1))){ fprintf(fp,"\\def\\NGS%c{\\left(%s\\right)}\n",'a'+i,Df[i].Obj); } else{ fprintf(fp,"\\def\\NGS%c{%s}\n",'a'+i,Df[i].Obj); } } fprintf(fp,"$$\n\\c{"); p =Nm; while(*p !='\0'){ if(*p == '_'){ putc('\\',fp); } putc(*p++,fp); } fprintf(fp,"}\n\\to\n"); if(CorF){ fprintf(fp,"\\c{"); p =strF; while(*p !='\0'){ if(*p == '_'){ putc('\\',fp); } putc(*p++,fp); } fprintf(fp,"}\n\\to\n"); } fprintf(fp,"%s\n",str); fprintf(fp,"$$\n"); WriteZZ2(fp); fclose(fp); return(0); } int main() { FILE *fp; int i; char *str,strC[64],strF[64],Nm[64]; pid_t pid=0; #ifdef H Sty2ByteArray(); #endif Check4DviFile(); pid =fork(); if(pid == -1){ exit(0); } if(pid == 0){ pid=getpid(); execlp("xdvi", "xdvi","-geometry","1200x250+80+300" ,"-s","3","zz.dvi",NULL); printf("Child finished\n"); exit(127); } CorF =0; while(IsEndFile(Nm) == 0){ if(CodeName2CFstring(strC,strF,Nm)){ str =CorF ? strF : strC; CodeName2LaTeX(Df[0].Obj,str); Latex2File(Df[0].Obj,strF,Nm); system("latex zz.tex > /dev/null"); kill(pid,SIGUSR1); } } while(IsKbdEndString(Nm) == 0){ if(CodeName2CFstring(strC,strF,Nm)){ str =CorF ? strF : strC; CodeName2LaTeX(Df[0].Obj,str); Latex2File(Df[0].Obj,strF,Nm); system("latex zz.tex > /dev/null"); kill(pid,SIGUSR1); } } kill(pid,SIGINT); return(1); }