xfree(name_to_match);
LoadPEXFontFile(length, fontname, pFont)    unsigned	    length;    char *	    fontname;    diFontHandle    pFont;{    char                fname[100];    FILE               *fp;    Font_file_header    header;    Property           *properties = 0;    Dispatch           *table = 0;    miFontHeader       *font = (miFontHeader *)(pFont->deviceData);    int                 found_first, found_it = 0, err = Success, numChars, np;    char		name_to_match[100];    char		lowered_entry[100];#ifdef WIN32    HANDLE		fontdirh;    WIN32_FIND_DATA	dir_entry;    char	        path[MAX_PATH];#else    DIR		       *fontdir;    ENTRY              *dir_entry;#endif    register int        i;    register Ch_stroke_data **ch_font, *ch_stroke = 0;    register Dispatch  *tblptr = 0;    register Property  *propptr = 0;    register pexFontProp *fpptr = 0;    CopyISOLatin1Lowered((unsigned char *)name_to_match,			 (unsigned char *)fontname, length);    /* open up the font directory and look for matching file names */#ifdef WIN32    sprintf(path, "%s/*.*", pex_get_font_directory_path());    if ((fontdirh = FindFirstFile(path, &dir_entry)) == INVALID_HANDLE_VALUE)	return (PEXERR(PEXFontError));#else    if (!(fontdir = opendir(pex_get_font_directory_path())))	return (PEXERR(PEXFontError));#endif#ifdef WIN32    do#else    while(!found_it && (dir_entry = readdir(fontdir)))#endif	{	    /* strip off .phont and make all lower case */	    if (!get_lowered_truncated_entry(FileName(dir_entry), lowered_entry))		continue;			    /* does this match what got passed in? */	    if (strcmp(lowered_entry, name_to_match) == 0)		found_it = 1;	}#ifdef WIN32    while (!found_it && FindNextFile(fontdirh, &dir_entry) && !found_it);#endif        if (!found_it)	return (PEXERR(PEXFontError));        (void) strcpy(fname, pex_get_font_directory_path());    (void) strcat(fname, "/");    (void) strcat(fname, FileName(dir_entry));    #ifdef WIN32    FindClose(fontdirh);#else    closedir(fontdir);#endif    if ((fp = fopen(fname, "r")) == NULL)	return (PEXERR(PEXFontError));    /*     * read in the file header.  The file header has fields containing the     * num of characters in the font, the extreme values, and number of font     * properties defined, if any.     */    tblptr = 0;    if (fread((char *) &header, sizeof(header), 1, fp) != 1) {	(void) ClosePEXFontFile(fp);	return (PEXERR(PEXFontError)); }        /* Initialize font structure */    (void) strcpy(font->name, header.name);    font->font_type = FONT_POLYLINES;    font->top = header.top;    font->bottom = header.bottom;    font->num_ch = header.num_ch;    font->font_info.numProps = (CARD32)header.num_props;    font->max_width = header.max_width;    /* read in the font properties, if any, into font data area */    if (header.num_props > 0) {	(void) SetPEXFontFilePtr(fp, START_PROPS);   /* Get to props position */	properties = (Property *) xalloc(header.num_props * sizeof(Property));	if (properties == NULL) {	    (void) ClosePEXFontFile(fp);	    return (BadAlloc); }	if (fread((char *) properties, sizeof(Property), 		  header.num_props, fp) != header.num_props) {	    xfree((char *) properties);	    (void) ClosePEXFontFile(fp);	    return (PEXERR(PEXFontError)); }    	/* Create space for font properties in the font data area */	font->properties =	    (pexFontProp *) xalloc( (unsigned long)(header.num_props				    * sizeof(pexFontProp)));	if (font->properties == NULL) {	    xfree((char *) properties);	    (void) ClosePEXFontFile(fp);	    return (BadAlloc); }	np = header.num_props;	for (	i=0, propptr = properties, fpptr = font->properties;		i < np;		i++, propptr++, fpptr++) {	    if (propptr->propname == NULL) {		(header.num_props)--;		continue; }	    fpptr->name = MakeAtom( (char *)propptr->propname,				    strlen(propptr->propname), 1);	    if (propptr->propvalue != NULL)		fpptr->value = MakeAtom((char *)propptr->propvalue,					strlen(propptr->propvalue), 1);	    else fpptr->value = 0;	}	/* free up local storage allocated for properties */	 xfree((char *) properties);    }    /* position file pointer to dispatch data */    (void) SetPEXFontFilePtr(fp, (long) START_DISPATCH(header.num_props));    /*     * read in the distable font, use the offset to see if the     * character is defined or not.  The strokes are defined in Phigs style.     * The "center" of the character is not the physical center. It is the     * center defined by the font designer.  The actual center is half the     * "right" value.     */    table = (Dispatch *)xalloc((unsigned long)(sizeof(Dispatch) *font->num_ch));        if (table == NULL) {	(void) ClosePEXFontFile(fp);	return (BadAlloc); }        if (fread((char *) table, sizeof(Dispatch), font->num_ch, fp)	    != font->num_ch) {	xfree((char *) table);	(void) ClosePEXFontFile(fp);	return (PEXERR(PEXFontError)); }        font->ch_data =	(Ch_stroke_data **) xalloc((unsigned long)(sizeof(Ch_stroke_data *) * 						    font->num_ch));    if (font->ch_data == NULL) {	xfree((char *) table);	(void) ClosePEXFontFile(fp);	return (BadAlloc); }        /* The next loop initializes all ch_data pointers to null; essential	for non-crashing during font clean-up in case of failed font file	read.  Also count the number of non-blank chars.     */    for (   i = 0, ch_font = font->ch_data, tblptr = table, numChars = 0;	    i < font->num_ch;	    i++, ch_font++, tblptr++) {	*ch_font = NULL;	if (tblptr->offset != 0) numChars++; }    ch_stroke = (Ch_stroke_data *)xalloc((unsigned long)(numChars *						    sizeof(Ch_stroke_data)));    if (!ch_stroke) {	err = BadAlloc;	goto disaster;    }    /* read in the char data  (the font file format should be changed	so that the allocation can be done outside this loop--this	method is inefficient)     */    for (   i = 0, ch_font = font->ch_data, tblptr = table, found_first = 0;	    i < font->num_ch;	    i++, ch_font++, tblptr++) {	if (tblptr->offset != 0) {	    (*ch_font) = ch_stroke++;	    (*ch_font)->strokes.ddList = NULL;	    (*ch_font)->center = table[i].center;	    (*ch_font)->right = table[i].right;	    	    (void) SetPEXFontFilePtr(fp, tblptr->offset);	    /* read in the type, number of subpaths, and n_vertices fields */	    if (    (fread(&((*ch_font)->type),			   sizeof(Font_path_type), 1, fp) != 1) 		||  (fread(&((*ch_font)->strokes.numLists),			   sizeof(ddULONG),1,fp) != 1)		||  (fread(&((*ch_font)->n_vertices),			   sizeof(ddULONG), 1, fp) != 1) )		{		  		    err = PEXERR(PEXFontError);		    goto disaster;		}	    	    (*ch_font)->strokes.maxLists = (*ch_font)->strokes.numLists;	    if ((*ch_font)->strokes.numLists > 0) {	    		if (get_stroke(*ch_font, fp)) {		    err = BadAlloc;		    goto disaster; }	    		if (!found_first) {		    font->font_info.firstGlyph = i;		    found_first = 1; }		font->font_info.lastGlyph = i; }	    }    }    xfree((char *)table);    (void) ClosePEXFontFile(fp);        return (Success);disaster:    (void) ClosePEXFontFile(fp);    if (table) xfree(table);#if 0    if (pFont == defaultPEXFont) defaultPEXFont = 0;	/* force free */#endif    FreePEXFont((diFontHandle) pFont, pFont->id);    return (err);    }