Subversion Repositories wimsdev

Rev

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

  1. /*    Copyright (C) 2002-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. /* tex 2 gif translator */
  19.  
  20. #include "texgif.h"
  21. char *progname;
  22. char *tmpdir="/tmp";
  23. char *fontdir="/tmp";
  24. char *headerfile="";
  25. char *texstyle="";
  26. char *outfile="/tmp/texgif.gif";
  27. char cwd[1024];
  28. double blacker=0.4;
  29. int basedensity=100, density;
  30. int compressratio=1;
  31. int wrapexec=0;
  32. int currentcolor;
  33.  
  34. FONT wfont[FONT_NUMBER_LIMIT];
  35. int fontcnt;
  36.  
  37. enum {tt_plain, tt_latex};
  38. int textype=tt_plain;
  39. char *texname="tex";
  40.  
  41. #include "basic.c"
  42. #include "colors.c"
  43. #include "tfm.c"
  44. #include "gf.c"
  45. #include "font.c"
  46. #include "image.c"
  47. #include "dvi.c"
  48.  
  49. void checktextype(char *p)
  50. {
  51.     if(strstr(p,"\\begin{")!=NULL ||
  52.        strstr(p,"\\end{")!=NULL ||
  53.        strstr(p,"\\underset")!=NULL ||
  54.        strstr(p,"\\overset")!=NULL ||
  55.        strstr(p,"\\displaystyle")!=NULL) {
  56.         textype=tt_latex; texname="latex";
  57.     }
  58. }
  59.  
  60.         /* pass thru tex */
  61. void tex(void)
  62. {
  63.     char *src;
  64.     char *hd;
  65.     char fbuf[1024], nbuf[2048];
  66.     char *parmbuf[8];
  67.     FILE *f;
  68.     long int l;
  69.     src=getenv("texgif_src");
  70.     if(src==NULL || *src==0) error("No source.");
  71.     checktextype(src);
  72.     snprintf(fbuf,sizeof(fbuf),"%s/texgif.tex",tmpdir);
  73.     if(*headerfile) {
  74.         if(strstr(headerfile,".tex")==NULL)
  75.           snprintf(nbuf,sizeof(nbuf),"%s.%s",headerfile,texname);
  76.         else
  77.           snprintf(nbuf,sizeof(nbuf),"%s",headerfile);
  78.         f=fopen(nbuf,"r");
  79.         if(f!=NULL) {
  80.             fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET);
  81.             if(l>0 && l<FILE_LENGTH_LIMIT) {
  82.                 hd=xmalloc(l+16); fread(hd,1,l,f);
  83.             }
  84.             else {l=0; hd="";}
  85.             fclose(f); f=fopen(fbuf,"w");
  86.             fwrite(hd,1,l,f); free(hd);
  87.         }
  88.         else f=fopen(fbuf,"w");
  89.     }
  90.     else f=fopen(fbuf,"w");
  91.     if(textype==tt_plain) {
  92.         fprintf(f,"%s %s %s\n\\end\n",texstyle, src, texstyle); fclose(f);
  93.     }
  94.     else {
  95.         fprintf(f,"{\\newpage\\clearpage\n\
  96. %s %s %s\n\
  97. \\clearpage}\n\
  98. \\end{document}\n",texstyle, src, texstyle); fclose(f);
  99.     }
  100.     chdir(tmpdir);
  101.     parmbuf[0]=texname; parmbuf[1]="texgif"; parmbuf[2]=NULL;
  102.     wrapexec=1;
  103.     execredirected(texname,NULL,NULL,NULL,parmbuf);
  104.     if(cwd[0]) chdir(cwd);
  105. }
  106.  
  107. void parms(void)
  108. {
  109.     char *p;
  110.     int t;
  111.     p=getenv("tmp_dir"); if(p!=NULL && *p!=0) tmpdir=p;
  112.     p=getenv("texgif_tmpdir"); if(p!=NULL && *p!=0) tmpdir=p;
  113.     p=getenv("texgif_fontdir"); if(p!=NULL && *p!=0) fontdir=p;
  114.     p=getenv("texgif_outfile"); if(p!=NULL && *p!=0) outfile=p;
  115.     p=getenv("texgif_texheader"); if(p!=NULL && *p!=0) headerfile=p;
  116.     p=getenv("texgif_style"); if(p!=NULL && *p!=0) texstyle=p;
  117.     p=getenv("texgif_density"); if(p!=NULL && *p!=0) {
  118.         t=atoi(p); if(t>10 && t<1000) basedensity=t;
  119.     }
  120.     p=getenv("texgif_compressratio"); if(p!=NULL && *p!=0) {
  121.         t=atoi(p); if(t>1 && t<=5) compressratio=t;
  122.     }
  123.     if(getcwd(cwd,sizeof(cwd))==NULL) cwd[0]=0;
  124. }
  125.  
  126. int main(int argc, char *argv[])
  127. {
  128.     progname=argv[0];
  129.     parms();
  130.     fontcnt=0;
  131.     tex();
  132.     setreuid(geteuid(),geteuid());setregid(getegid(),getegid());
  133.     dvi();
  134.     return 0;
  135. }
  136.  
  137.