diff -rubB xdvik-22.40/libs/t1lib/lib/t1lib/t1enc.c xdvik/libs/t1lib/lib/t1lib/t1enc.c --- xdvik-22.40/libs/t1lib/lib/t1lib/t1enc.c Thu Apr 19 01:23:16 2001 +++ xdvik/libs/t1lib/lib/t1lib/t1enc.c Mon Jun 4 01:22:04 2001 @@ -61,24 +61,99 @@ #include "t1finfo.h" -#define DEFAULTENCODINGNAME "Unspecified" +static char *defaultencodingname="Unspecified"; +static char *notdef=".notdef"; + +/* ScanForWord(): Tokenizer for ScanEncodingFile. Will skip whitespace and + comments and return the tokens/words in the vector passed */ + +char *ScanForWord(char *lb,int size) +{ + static int i=-1; + static save_char=0; + int j; + int comment; + + /* Reset tokenizer */ + if (lb==NULL) { + i=-1; + save_char=0; + return NULL; + } + + if (save_char) + lb[i]=save_char; + comment=0; + j=-1; + + while (++i word */ + if (j==-1) { + j=i; + continue; + } + } + + /* We're at the end of the buffer. Do we have a word? */ + if (j!=-1) + return &lb[j]; + + /* We have nothing */ + return NULL; +} + /* ScanEncodingFile(): Read an encoding file of an appropriate format and prepare the read data for usage with the type1 rasterizer, i.e. generate an array char *enc[256]. Return the pointer to the data area or NULL in case of an error. - */ + + Enhanced to read more postscript like syntax as well as the + restricted t1lib syntax for compatability with existing postscript + .enc files - janl 2/6/2001 +*/ char **ScanEncodingFile( char *FileName) { char *linebuf; + char *token; char *charnames; char save_char; char **encoding; + char postscript=0; + char *encname=NULL; FILE *enc_fp; - int filesize, i, j, k, l=0, charname_count; + int filesize, i, j, k, charname_count; if ((enc_fp=fopen( FileName,"r"))==NULL){ T1_errno=T1ERR_FILE_OPEN_ERR; @@ -86,7 +161,6 @@ => no encoding read */ } - /* enc_fp points now to a (hopefully) valid encoding file */ /* Get the file size */ fseek( enc_fp, 0, SEEK_END); @@ -102,7 +176,7 @@ /* Allocate space for character names, assume the worst case and realloc later: */ - if ((charnames=(char *)calloc( filesize + strlen(DEFAULTENCODINGNAME), + if ((charnames=(char *)calloc( filesize + strlen(defaultencodingname), sizeof(char)))==NULL){ T1_errno=T1ERR_ALLOC_MEM; return(NULL); @@ -113,91 +187,111 @@ i=0; - while(i now, 256 lines should follow, each + +/* keyword found => now, 256 lines/words should follow, each specifying a character name and optionally some comment to enhance readability: */ - break; - } - i++; - } - k=0; + k=-1; charname_count=0; - while((i 257th entry */ + i=-1; + do { + charnames[++k]=encname[++i]; + } while (encname[i]); + if (encname!=defaultencodingname) free(encname); free(linebuf); /* We alloc 257 to save the encoding's name at the 257th entry */ - if ((encoding=(char **)malloc(257*sizeof(char *)))==NULL){ + if ((encoding=(char **)malloc(257*sizeof(char *)))==NULL) { free(charnames); T1_errno=T1ERR_ALLOC_MEM; return(NULL); } /* k should still contain the number of characters copied, so let's now realloc charnames */ + k++; /* It started at -1 */ charnames=(char *)realloc( charnames, k*sizeof(char)); /* Now initialize the array with the start-addresses of the character name strings */