Subversion Repositories wimsdev

Rev

Rev 242 | 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.         textype=tt_latex; texname="latex";
  56.     }
  57. }
  58.  
  59.         /* pass thru tex */
  60. void tex(void)
  61. {
  62.     char *src;
  63.     char *hd;
  64.     char fbuf[1024], nbuf[2048];
  65.     char *parmbuf[8];
  66.     FILE *f;
  67.     long int l;
  68.     src=getenv("texgif_src");
  69.     if(src==NULL || *src==0) error("No source.");
  70.     checktextype(src);
  71.     snprintf(fbuf,sizeof(fbuf),"%s/texgif.tex",tmpdir);
  72.     if(*headerfile) {
  73.         if(strstr(headerfile,".tex")==NULL)
  74.           snprintf(nbuf,sizeof(nbuf),"%s.%s",headerfile,texname);
  75.         else
  76.           snprintf(nbuf,sizeof(nbuf),"%s",headerfile);
  77.         f=fopen(nbuf,"r");
  78.         if(f!=NULL) {
  79.             fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET);
  80.             if(l>0 && l<FILE_LENGTH_LIMIT) {
  81.                 hd=xmalloc(l+16); fread(hd,1,l,f);
  82.             }
  83.             else {l=0; hd="";}
  84.             fclose(f); f=fopen(fbuf,"w");
  85.             fwrite(hd,1,l,f); free(hd);
  86.         }
  87.         else f=fopen(fbuf,"w");
  88.     }
  89.     else f=fopen(fbuf,"w");
  90.     if(textype==tt_plain) {
  91.         fprintf(f,"%s %s %s\n\\end\n",texstyle, src, texstyle); fclose(f);
  92.     }
  93.     else {
  94.         fprintf(f,"{\\newpage\\clearpage\n\
  95. %s %s %s\n\
  96. \\clearpage}\n\
  97. \\end{document}\n",texstyle, src, texstyle); fclose(f);
  98.     }
  99.     chdir(tmpdir);
  100.     parmbuf[0]=texname; parmbuf[1]="texgif"; parmbuf[2]=NULL;
  101.     wrapexec=1;
  102.     execredirected(texname,NULL,NULL,NULL,parmbuf);
  103.     if(cwd[0]) chdir(cwd);
  104. }
  105.  
  106. void parms(void)
  107. {
  108.     char *p;
  109.     int t;
  110.     p=getenv("tmp_dir"); if(p!=NULL && *p!=0) tmpdir=p;
  111.     p=getenv("texgif_tmpdir"); if(p!=NULL && *p!=0) tmpdir=p;
  112.     p=getenv("texgif_fontdir"); if(p!=NULL && *p!=0) fontdir=p;
  113.     p=getenv("texgif_outfile"); if(p!=NULL && *p!=0) outfile=p;
  114.     p=getenv("texgif_texheader"); if(p!=NULL && *p!=0) headerfile=p;
  115.     p=getenv("texgif_style"); if(p!=NULL && *p!=0) texstyle=p;
  116.     p=getenv("texgif_density"); if(p!=NULL && *p!=0) {
  117.         t=atoi(p); if(t>10 && t<1000) basedensity=t;
  118.     }
  119.     p=getenv("texgif_compressratio"); if(p!=NULL && *p!=0) {
  120.         t=atoi(p); if(t>1 && t<=5) compressratio=t;
  121.     }
  122.     if(getcwd(cwd,sizeof(cwd))==NULL) cwd[0]=0;
  123. }
  124.  
  125. int main(int argc, char *argv[])
  126. {
  127.     progname=argv[0];
  128.     parms();
  129.     fontcnt=0;
  130.     tex();
  131.     setreuid(geteuid(),geteuid());setregid(getegid(),getegid());
  132.     dvi();
  133.     return 0;
  134. }
  135.  
  136.