Annotation of ratfiv/epstopdf.c.1, revision 1.1.1.1

1.1       brouard     1: /*
                      2: # epstopdf: written by Kong Hoon Lee konghoon@hyowon.cc.pusan.ac.kr<4/1/1999>
                      3: #
                      4: # It converts an EPS file to an encapsulated PDF File and
                      5: # coded with the perl script 'epstopdf' by Sebastian Rahtz on
                      6: # http://tug.org/applications/pdftex/epstopdf .
                      7: # It works like as the perl script without 'perl' for Windows 95
                      8: # but requires 'Ghostscript' for Windows.
                      9: #
                     10: */
                     11: 
                     12: #include <stdio.h>
                     13: #include <stdlib.h>
                     14: #define MAX_IN 10000
                     15: 
                     16: #ifndef GS_LIB
                     17: #  define GS_LIB "GS_LIB"
                     18: #endif
                     19: 
                     20: main(int argc,char *argv[])
                     21: {
                     22:        FILE *in,*out,*inn;
                     23:        char tmpname_tmp[FILENAME_MAX];
                     24:        char tmpname[FILENAME_MAX];
                     25:        char filename[FILENAME_MAX];
                     26:        char command[MAX_IN];
                     27:        char ch[MAX_IN];
                     28:        char ch1[MAX_IN];
                     29:        int bbox[4],width,height,xoffset,yoffset;
                     30:        int i=0,j,count=0;
                     31:         const char *gs_lib = getenv(GS_LIB);
                     32:         if(gs_lib == NULL) gs_lib="c:\\gstools\\gs5.50;c:\\gstools\\gs5.50\\fonts";
                     33: 
                     34:        if(argc < 2 || argc >2) {
                     35:                printf("%s:\n",argv[0]);
                     36:                printf("written by Kong Hoon Lee, konghoon@hyowon.cc.pusan.ac.kr <4/1/1999>\n\n");
                     37:                 printf("It converts an EPS file to an encapsulated PDF File and is written\n");
                     38:                 printf("based on the perl script 'epstopdf' by Sebastian Rahtz on\n");
                     39:                 printf("http://tug.org/applications/pdftex/epstopdf .\n");
                     40:                 printf("It works like as the perl script without 'perl' for Windows 95\n");
                     41:                 printf("but requires 'Ghostscript' for Windows.\n\n");
                     42: 
                     43:                 printf("This program invokes 'GSWIN32C.EXE' and the path including 'GSWIN32C.EXE'\n");
                     44:                printf("should be included to the environment variable 'PATH'. In addition\n");
                     45:                printf("the variable 'GS_LIB' should be set before using this program,\n");
                     46:                printf("otherwise 'GS_LIB=c:\\gstools\\gs5.50;c:\\gstools\\gs5.50\\fonts' is used.\n\n");
                     47: 
                     48:                printf("Usage: %s filename-of-an-eps-file\n\n",argv[0]);
                     49:                return;
                     50:        }
                     51: 
                     52:        if((in=fopen(argv[1],"r")) == NULL) {
                     53:                printf("%s: File not found!\n",argv[1]);
                     54:                printf("Usage: %s filename-of-an-eps-file\n\n",argv[0]);
                     55:                return;
                     56:        }
                     57:        fclose(in);
                     58:        
                     59:        strcpy(tmpname,argv[1]);
                     60:        strget(tmpname);
                     61:        strcat(tmpname,"_epstopdf.0");
                     62:        count=0;
                     63:        while ((out=fopen(tmpname,"r")) != NULL ) {
                     64:                    fclose(out);
                     65:                    count++;
                     66:                    strget(tmpname);
                     67:                    strcpy(tmpname_tmp,tmpname);
                     68:                    sprintf(tmpname,"%s.%d",tmpname_tmp,count);
                     69:     }
                     70: 
                     71:        strcpy(filename,argv[1]);
                     72:        strget(filename);
                     73:        strcat(filename,".pdf");
                     74:        
                     75:        printf("Converting %s to %s ..... ",argv[1],filename);
                     76: 
                     77:        in=fopen(argv[1],"r");
                     78:        out=fopen(tmpname,"w");
                     79:        while ((fgets(ch,MAX_IN,in)) !=NULL){
                     80:                strcpy(ch1,ch+2);
                     81:                *(ch1+11)='\0';
                     82:                if (strcmp(ch1,"BoundingBox") == 0 ) {
                     83:                        strcpy(command,ch+15);
                     84:                        read_number(command,4,bbox);
                     85:                width=bbox[2]-bbox[0];
                     86:                height=bbox[3]-bbox[1];
                     87:                xoffset=0-bbox[0];
                     88:                yoffset=0-bbox[1];
                     89:                fprintf(out,"\%\%BoundingBox: %d %d %d %d\n",0,0,width,height);
                     90:                        fprintf(out,"<< /PageSize [%d %d] >> setpagedevice \n",width,height);
                     91:                        fprintf(out,"gsave %d %d translate\n",xoffset,yoffset);
                     92:                } else
                     93:                        fputs(ch,out);
                     94:        }
                     95:        fclose(in);
                     96:        fclose(out);
                     97: 
                     98:        sprintf(command,"gswin32c -I%s -q -dNOPAUSE -dBATCH -dUseFlateCompression=true -sDEVICE=pdfwrite -sOutputFile=%s -c save pop -f %s",
                     99:                        gs_lib,filename,tmpname);
                    100: 
                    101:        /*
                    102:        puts(command);
                    103:        */
                    104:         system(command);
                    105:        remove(tmpname);
                    106:        printf("Done\n");
                    107: }
                    108: 
                    109: strget(char *string)
                    110: {
                    111:        int i=0;
                    112:        int size;
                    113:        
                    114:        size=strlen(string);
                    115:        for (i=0;i<size;i++) {
                    116:                if ( *(string+i) == '.' ) {
                    117:             *(string+i)='\0';
                    118:                        break;
                    119:                }
                    120:        }
                    121: }
                    122: 
                    123: read_number(char *number,int num,int *value)
                    124: {
                    125:    char ch;
                    126:    char e_num[MAX_IN];
                    127:    int count = 0;
                    128:    int j;
                    129:    int counter[num];
                    130:    int counters[num];
                    131: 
                    132:    for (j=0;j<num;j++){
                    133:       while ((ch=number[count++]) !='\0' && isspace(ch)) { }
                    134:       counters[j]=count-1;
                    135:       while ((ch=number[count++]) !='\0' && !isspace(ch)) { }
                    136:       counter[j]=count;
                    137:    }
                    138:    for (j=0;j<num;j++) {
                    139:       strcpy(e_num,number+counters[j]);
                    140:       *(e_num+counter[j]-counters[j]-1)='\0';
                    141:       /* printf("%s,",e_num); */
                    142:       *(value+j)=atoi(e_num);
                    143:    }
                    144: }
                    145: 
                    146: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>