--- texgd.c.orig	2006-06-02 18:33:25.000000000 +0200
+++ texgd.c	2006-06-02 18:39:23.000000000 +0200
@@ -16,14 +16,16 @@
  */
 
 /* tex 2 gif translator */
-
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include "texgif.h"
 char *progname;
 char *tmpdir="/tmp";
 char *fontdir="/tmp";
 char *headerfile="";
 char *texstyle="";
-char *outfile="/tmp/texgif.gif";
+char *outfile="/tmp/texgd.png";
 char cwd[1024];
 double blacker=0.4;
 int basedensity=100, density;
@@ -44,7 +46,7 @@
 #include "gf.c"
 #include "font.c"
 #include "image.c"
-#include "dvi.c"
+#include "gddvi.c"
 
 void checktextype(char *p)
 {
@@ -65,15 +67,19 @@
     char *parmbuf[8];
     FILE *f;
     long int l;
-    src=getenv("texgif_src");
+    struct stat *buf= malloc(sizeof(struct stat));
+    src=getenv("texgd_src");
     if(src==NULL || *src==0) error("No source.");
     checktextype(src);
-    snprintf(fbuf,sizeof(fbuf),"%s/texgif.tex",tmpdir);
+    snprintf(fbuf,sizeof(fbuf),"%s/texgd.tex",tmpdir);
     if(*headerfile) {
-	if(strstr(headerfile,".tex")==NULL)
-	  snprintf(nbuf,sizeof(nbuf),"%s.%s",headerfile,texname);
-	else
+        if (stat(headerfile, buf)<0){
+	  if(strstr(headerfile,".tex")==NULL)
+	    snprintf(nbuf,sizeof(nbuf),"%s.%s",headerfile,texname);
+	  /* headerfile does not exist, let's try to add a .tex suffix      */
+	} else { /* headerfile readily exists, no need to add a .tex suffix */
 	  snprintf(nbuf,sizeof(nbuf),"%s",headerfile);
+	}
 	f=fopen(nbuf,"r");
 	if(f!=NULL) {
 	    fseek(f,0,SEEK_END); l=ftell(f); fseek(f,0,SEEK_SET);
@@ -97,7 +103,7 @@
 \\end{document}\n",texstyle, src, texstyle); fclose(f);
     }
     chdir(tmpdir);
-    parmbuf[0]=texname; parmbuf[1]="texgif"; parmbuf[2]=NULL;
+    parmbuf[0]=texname; parmbuf[1]="texgd"; parmbuf[2]=NULL;
     wrapexec=1;
     execredirected(texname,NULL,NULL,NULL,parmbuf);
     if(cwd[0]) chdir(cwd);
@@ -108,15 +114,15 @@
     char *p;
     int t;
     p=getenv("tmp_dir"); if(p!=NULL && *p!=0) tmpdir=p;
-    p=getenv("texgif_tmpdir"); if(p!=NULL && *p!=0) tmpdir=p;
-    p=getenv("texgif_fontdir"); if(p!=NULL && *p!=0) fontdir=p;
-    p=getenv("texgif_outfile"); if(p!=NULL && *p!=0) outfile=p;
-    p=getenv("texgif_texheader"); if(p!=NULL && *p!=0) headerfile=p;
-    p=getenv("texgif_style"); if(p!=NULL && *p!=0) texstyle=p;
-    p=getenv("texgif_density"); if(p!=NULL && *p!=0) {
+    p=getenv("texgd_tmpdir"); if(p!=NULL && *p!=0) tmpdir=p;
+    p=getenv("texgd_fontdir"); if(p!=NULL && *p!=0) fontdir=p;
+    p=getenv("texgd_outfile"); if(p!=NULL && *p!=0) outfile=p;
+    p=getenv("texgd_texheader"); if(p!=NULL && *p!=0) headerfile=p;
+    p=getenv("texgd_style"); if(p!=NULL && *p!=0) texstyle=p;
+    p=getenv("texgd_density"); if(p!=NULL && *p!=0) {
 	t=atoi(p); if(t>10 && t<1000) basedensity=t;
     }
-    p=getenv("texgif_compressratio"); if(p!=NULL && *p!=0) {
+    p=getenv("texgd_compressratio"); if(p!=NULL && *p!=0) {
 	t=atoi(p); if(t>1 && t<=5) compressratio=t;
     }
     if(getcwd(cwd,sizeof(cwd))==NULL) cwd[0]=0;
