⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fontdir.c

📁 unix vnc 协议源码. VNC是一款远程控制工具软件.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $XConsortium: fontdir.c /main/24 1996/09/28 16:49:04 rws $ *//* $XFree86: xc/lib/font/fontfile/fontdir.c,v 3.7 1996/12/23 06:02:21 dawes Exp $ *//*Copyright (c) 1991  X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.*//* * Author:  Keith Packard, MIT X Consortium */#include    "fntfilst.h"#include    <X11/keysym.h>BoolFontFileInitTable (table, size)    FontTablePtr    table;    int		    size;{    if (size)    {	table->entries = (FontEntryPtr) xalloc(sizeof(FontEntryRec) * size);	if (!table->entries)	    return FALSE;    }    else	table->entries = 0;    table->used = 0;    table->size = size;    table->sorted = FALSE;    return TRUE;}FontFileFreeEntry (entry)    FontEntryPtr    entry;{    FontScalableExtraPtr   extra;    int i;    if (entry->name.name)	xfree(entry->name.name);    switch (entry->type)    {    case FONT_ENTRY_SCALABLE:	xfree (entry->u.scalable.fileName);	extra = entry->u.scalable.extra;	for (i = 0; i < extra->numScaled; i++)	    if (extra->scaled[i].vals.ranges)		xfree (extra->scaled[i].vals.ranges);	xfree (extra->scaled);	xfree (extra);	break;    case FONT_ENTRY_BITMAP:	xfree (entry->u.bitmap.fileName);	break;    case FONT_ENTRY_ALIAS:	xfree (entry->u.alias.resolved);	break;#ifdef NOTYET    case FONT_ENTRY_BC:	break;#endif    }}FontFileFreeTable (table)    FontTablePtr    table;{    int	i;    for (i = 0; i < table->used; i++)	FontFileFreeEntry (&table->entries[i]);    xfree (table->entries);}FontDirectoryPtrFontFileMakeDir(dirName, size)    char       *dirName;    int         size;{    FontDirectoryPtr	dir;    int			dirlen;    int			needslash = 0;#ifdef FONTDIRATTRIB    char		*attrib;    int			attriblen;#endif#ifdef FONTDIRATTRIB#ifndef __EMX__    attrib = strchr(dirName, ':');#else    /* OS/2 uses the colon in the drive letter descriptor, skip this */    attrib = strchr(dirName+2, ':');#endif    if (attrib) {	dirlen = attrib - dirName;	attriblen = strlen(attrib);    } else {	dirlen = strlen(dirName);	attriblen = 0;    }#else    dirlen = strlen(dirName);#endif    if (dirName[dirlen - 1] != '/')#ifdef NCD    if (dirlen)     /* leave out slash for builtins */#endif	needslash = 1;#ifdef FONTDIRATTRIB    dir = (FontDirectoryPtr) xalloc(sizeof *dir + dirlen + needslash + 1 +				    (attriblen ? attriblen + 1 : 0));#else    dir = (FontDirectoryPtr) xalloc(sizeof *dir + dirlen + needslash + 1);#endif    if (!dir)	return (FontDirectoryPtr)0;    if (!FontFileInitTable (&dir->scalable, 0))    {	xfree (dir);	return (FontDirectoryPtr)0;    }    if (!FontFileInitTable (&dir->nonScalable, size))    {	FontFileFreeTable (&dir->scalable);	xfree (dir);	return (FontDirectoryPtr)0;    }    dir->directory = (char *) (dir + 1);    dir->dir_mtime = 0;    dir->alias_mtime = 0;#ifdef FONTDIRATTRIB    if (attriblen)	dir->attributes = dir->directory + dirlen + needslash + 1;    else	dir->attributes = NULL;    strncpy(dir->directory, dirName, dirlen);    dir->directory[dirlen] = '\0';    if (dir->attributes)	strcpy(dir->attributes, attrib);#else    strcpy(dir->directory, dirName);#endif    if (needslash)	strcat(dir->directory, "/");    return dir;}FontFileFreeDir (dir)    FontDirectoryPtr	dir;{    FontFileFreeTable (&dir->scalable);    FontFileFreeTable (&dir->nonScalable);    xfree(dir);}FontEntryPtrFontFileAddEntry(table, prototype)    FontTablePtr	table;    FontEntryPtr	prototype;{    FontEntryPtr    entry;    int		    newsize;    /* can't add entries to a sorted table, pointers get broken! */    if (table->sorted)	return (FontEntryPtr) 0;    /* "cannot" happen */    if (table->used == table->size) {	newsize = table->size + 100;	entry = (FontEntryPtr) xrealloc(table->entries,					   newsize * sizeof(FontEntryRec));	if (!entry)	    return (FontEntryPtr)0;	table->size = newsize;	table->entries = entry;    }    entry = &table->entries[table->used];    *entry = *prototype;    entry->name.name = (char *) xalloc(prototype->name.length + 1);    if (!entry->name.name)	return (FontEntryPtr)0;    memcpy (entry->name.name, prototype->name.name, prototype->name.length);    entry->name.name[entry->name.length] = '\0';    table->used++;    return entry;}static intFontFileNameCompare(a, b)    char       *a,               *b;{    FontEntryPtr    a_name = (FontEntryPtr) a,		    b_name = (FontEntryPtr) b;    return strcmp(a_name->name.name, b_name->name.name);}FontFileSortTable (table)    FontTablePtr    table;{    if (!table->sorted) {	qsort((char *) table->entries, table->used, sizeof(FontEntryRec),	      FontFileNameCompare);	table->sorted = TRUE;    }}FontFileSortDir(dir)    FontDirectoryPtr	dir;{    FontFileSortTable (&dir->scalable);    FontFileSortTable (&dir->nonScalable);    /* now that the table is fixed in size, swizzle the pointers */    FontFileSwitchStringsToBitmapPointers (dir);}/*  Given a Font Table, SetupWildMatch() sets up various pointers and state  information so the table can be searched for name(s) that match a given  fontname pattern -- which may contain wildcards.  Under certain  circumstances, SetupWildMatch() will find the one table entry that  matches the pattern.  If those circumstances do not pertain,  SetupWildMatch() returns a range within the the table that should be  searched for matching name(s).  With the information established by  SetupWildMatch(), including state information in "private", the  PatternMatch() procedure is then used to test names in the range for a  match.*/#define isWild(c)   ((c) == XK_asterisk || (c) == XK_question)static intSetupWildMatch(table, pat, leftp, rightp, privatep)    FontTablePtr    table;    FontNamePtr	    pat;    int		    *leftp,		    *rightp;    int		    *privatep;{    int         nDashes;    char        c;    char       *t;    char       *firstWild;    int         first;    int         center,                left,                right;    int         result;    char	*name;    name = pat->name;    nDashes = pat->ndashes;    firstWild = 0;    t = name;    while (c = *t++) {	if (isWild(c)) {	    if (!firstWild)		firstWild = t - 1;	}    }    left = 0;    right = table->used;    if (firstWild)	*privatep = nDashes;    else	*privatep = -1;    if (!table->sorted) {	*leftp = left;	*rightp = right;	return -1;    } else if (firstWild) {	first = firstWild - name;	while (left < right) {	    center = (left + right) / 2;	    result = strncmp(name, table->entries[center].name.name, first);	    if (result == 0)		break;	    if (result < 0)		right = center;	    else		left = center + 1;	}	*leftp = left;	*rightp = right;	return -1;    } else {	while (left < right) {	    center = (left + right) / 2;	    result = strcmp(name, table->entries[center].name.name);	    if (result == 0)		return center;	    if (result < 0)		right = center;	    else		left = center + 1;	}	*leftp = 1;	*rightp = 0;	return -1;    }}staticPatternMatch(pat, patdashes, string, stringdashes)    char       *pat;    char       *string;{    char        c,                t;    if (stringdashes < patdashes)	return 0;    for (;;) {	switch (c = *pat++) {	case '*':	    if (!(c = *pat++))		return 1;	    if (c == XK_minus) {		patdashes--;		for (;;) {		    while ((t = *string++) != XK_minus)			if (!t)			    return 0;		    stringdashes--;		    if (PatternMatch(pat, patdashes, string, stringdashes))			return 1;		    if (stringdashes == patdashes)			return 0;		}	    } else {		for (;;) {		    while ((t = *string++) != c) {			if (!t)			    return 0;			if (t == XK_minus) {			    if (stringdashes-- < patdashes)				return 0;			}		    }		    if (PatternMatch(pat, patdashes, string, stringdashes))			return 1;		}	    }	case '?':	    if (*string++ == XK_minus)		stringdashes--;	    break;	case '\0':	    return (*string == '\0');	case XK_minus:	    if (*string++ == XK_minus) {		patdashes--;		stringdashes--;		break;	    }	    return 0;	default:	    if (c == *string++)		break;	    return 0;	}    }}intFontFileCountDashes (name, namelen)    char    *name;    int	    namelen;{    int	ndashes = 0;    while (namelen--)	if (*name++ == '\055')	/* avoid non ascii systems */	    ++ndashes;    return ndashes;}char *FontFileSaveString (s)    char    *s;{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -