/*
# epstopdf: written by Kong Hoon Lee konghoon@hyowon.cc.pusan.ac.kr<4/1/1999>
#
# It converts an EPS file to an encapsulated PDF File and
# coded with the perl script 'epstopdf' by Sebastian Rahtz on
# http://tug.org/applications/pdftex/epstopdf .
# It works like as the perl script without 'perl' for Windows 95
# but requires 'Ghostscript' for Windows.
#
*/
#include <stdio.h>
#include <stdlib.h>
#define MAX_IN 10000
#ifndef GS_LIB
# define GS_LIB "GS_LIB"
#endif
main(int argc,char *argv[])
{
FILE *in,*out,*inn;
char tmpname_tmp[FILENAME_MAX];
char tmpname[FILENAME_MAX];
char filename[FILENAME_MAX];
char command[MAX_IN];
char ch[MAX_IN];
char ch1[MAX_IN];
int bbox[4],width,height,xoffset,yoffset;
int i=0,j,count=0;
const char *gs_lib = getenv(GS_LIB);
if(gs_lib == NULL) gs_lib="c:\\gstools\\gs5.50;c:\\gstools\\gs5.50\\fonts";
if(argc < 2 || argc >2) {
printf("%s:\n",argv[0]);
printf("written by Kong Hoon Lee, konghoon@hyowon.cc.pusan.ac.kr <4/1/1999>\n\n");
printf("It converts an EPS file to an encapsulated PDF File and is written\n");
printf("based on the perl script 'epstopdf' by Sebastian Rahtz on\n");
printf("http://tug.org/applications/pdftex/epstopdf .\n");
printf("It works like as the perl script without 'perl' for Windows 95\n");
printf("but requires 'Ghostscript' for Windows.\n\n");
printf("This program invokes 'GSWIN32C.EXE' and the path including 'GSWIN32C.EXE'\n");
printf("should be included to the environment variable 'PATH'. In addition\n");
printf("the variable 'GS_LIB' should be set before using this program,\n");
printf("otherwise 'GS_LIB=c:\\gstools\\gs5.50;c:\\gstools\\gs5.50\\fonts' is used.\n\n");
printf("Usage: %s filename-of-an-eps-file\n\n",argv[0]);
return;
}
if((in=fopen(argv[1],"r")) == NULL) {
printf("%s: File not found!\n",argv[1]);
printf("Usage: %s filename-of-an-eps-file\n\n",argv[0]);
return;
}
fclose(in);
strcpy(tmpname,argv[1]);
strget(tmpname);
strcat(tmpname,"_epstopdf.0");
count=0;
while ((out=fopen(tmpname,"r")) != NULL ) {
fclose(out);
count++;
strget(tmpname);
strcpy(tmpname_tmp,tmpname);
sprintf(tmpname,"%s.%d",tmpname_tmp,count);
}
strcpy(filename,argv[1]);
strget(filename);
strcat(filename,".pdf");
printf("Converting %s to %s ..... ",argv[1],filename);
in=fopen(argv[1],"r");
out=fopen(tmpname,"w");
while ((fgets(ch,MAX_IN,in)) !=NULL){
strcpy(ch1,ch+2);
*(ch1+11)='\0';
if (strcmp(ch1,"BoundingBox") == 0 ) {
strcpy(command,ch+15);
read_number(command,4,bbox);
width=bbox[2]-bbox[0];
height=bbox[3]-bbox[1];
xoffset=0-bbox[0];
yoffset=0-bbox[1];
fprintf(out,"\%\%BoundingBox: %d %d %d %d\n",0,0,width,height);
fprintf(out,"<< /PageSize [%d %d] >> setpagedevice \n",width,height);
fprintf(out,"gsave %d %d translate\n",xoffset,yoffset);
} else
fputs(ch,out);
}
fclose(in);
fclose(out);
sprintf(command,"gswin32c -I%s -q -dNOPAUSE -dBATCH -dUseFlateCompression=true -sDEVICE=pdfwrite -sOutputFile=%s -c save pop -f %s",
gs_lib,filename,tmpname);
/*
puts(command);
*/
system(command);
remove(tmpname);
printf("Done\n");
}
strget(char *string)
{
int i=0;
int size;
size=strlen(string);
for (i=0;i<size;i++) {
if ( *(string+i) == '.' ) {
*(string+i)='\0';
break;
}
}
}
read_number(char *number,int num,int *value)
{
char ch;
char e_num[MAX_IN];
int count = 0;
int j;
int counter[num];
int counters[num];
for (j=0;j<num;j++){
while ((ch=number[count++]) !='\0' && isspace(ch)) { }
counters[j]=count-1;
while ((ch=number[count++]) !='\0' && !isspace(ch)) { }
counter[j]=count;
}
for (j=0;j<num;j++) {
strcpy(e_num,number+counters[j]);
*(e_num+counter[j]-counters[j]-1)='\0';
/* printf("%s,",e_num); */
*(value+j)=atoi(e_num);
}
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>