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

📄 xrm.c

📁 Nxlib,一个模拟xlib的程序。使用microwindows的库来运行需要xlib支持的程序。
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (!db)	return False;    _XLockMutex(&db->linfo);    eclosure.db = db;    eclosure.proc = proc;    eclosure.closure = closure;    eclosure.bindings = bindings;    eclosure.quarks = quarks;    eclosure.mode = mode;    table = db->table;    if (table && !table->leaf && !*names && mode == XrmEnumOneLevel)	table = table->next;    if (table) {	if (!table->leaf)	    retval = EnumNTable(table, names, classes, 0, &eclosure);	else	    retval = EnumLTable((LTable)table, names, classes, 0, &eclosure);    }    _XUnlockMutex(&db->linfo);    return retval;}static void PrintBindingQuarkList(bindings, quarks, stream)    XrmBindingList      bindings;    XrmQuarkList	quarks;    FILE		*stream;{    Bool	firstNameSeen;    for (firstNameSeen = False; *quarks; bindings++, quarks++) {	if (*bindings == XrmBindLoosely) {	    (void) fprintf(stream, "*");	} else if (firstNameSeen) {	    (void) fprintf(stream, ".");	}	firstNameSeen = True;	(void) fputs(XrmQuarkToString(*quarks), stream);    }}/* output out the entry in correct file syntax *//*ARGSUSED*/static Bool DumpEntry(db, bindings, quarks, type, value, data)    XrmDatabase		*db;    XrmBindingList      bindings;    XrmQuarkList	quarks;    XrmRepresentation   *type;    XrmValuePtr		value;    XPointer		data;{    FILE			*stream = (FILE *)data;    register unsigned int	i;    register char		*s;    register char		c;    if (*type != XrmQString)	(void) putc('!', stream);    PrintBindingQuarkList(bindings, quarks, stream);    s = value->addr;    i = value->size;    if (*type == XrmQString) {	(void) fputs(":\t", stream);	if (i)	    i--;    }    else	(void) fprintf(stream, "=%s:\t", XrmRepresentationToString(*type));    if (i && (*s == ' ' || *s == '\t'))	(void) putc('\\', stream); /* preserve leading whitespace */    while (i--) {	c = *s++;	if (c == '\n') {	    if (i)		(void) fputs("\\n\\\n", stream);	    else		(void) fputs("\\n", stream);	} else if (c == '\\')	    (void) fputs("\\\\", stream);	else if ((c < ' ' && c != '\t') ||		 ((unsigned char)c >= 0x7f && (unsigned char)c < 0xa0))	    (void) fprintf(stream, "\\%03o", (unsigned char)c);	else	    (void) putc(c, stream);    }    (void) putc('\n', stream);    return ferror(stream) != 0;}#ifdef DEBUGvoid PrintTable(table, file)    NTable table;    FILE *file;{    XrmBinding  bindings[MAXDBDEPTH+1];    XrmQuark	quarks[MAXDBDEPTH+1];    EClosureRec closure;    XrmQuark	empty = NULLQUARK;    closure.db = (XrmDatabase)NULL;    closure.proc = DumpEntry;    closure.closure = (XPointer)file;    closure.bindings = bindings;    closure.quarks = quarks;    closure.mode = XrmEnumAllLevels;    if (table->leaf)	EnumLTable((LTable)table, &empty, &empty, 0, &closure);    else	EnumNTable(table, &empty, &empty, 0, &closure);}#endif /* DEBUG */#if NeedFunctionPrototypesvoid XrmPutFileDatabase(    XrmDatabase db,    _Xconst char *fileName)#elsevoid XrmPutFileDatabase(db, fileName)    XrmDatabase db;    char 	*fileName;#endif{    FILE	*file;    XrmQuark empty = NULLQUARK;    if (!db) return;    if (!(file = fopen(fileName, "w"))) return;    if (XrmEnumerateDatabase(db, &empty, &empty, XrmEnumAllLevels,			     DumpEntry, (XPointer) file))	unlink((char *)fileName);    fclose(file);}/* macros used in get/search functions *//* find entries named ename, leafness leaf, tight or loose, and call get */#define GTIGHTLOOSE(ename,looseleaf) \    NFIND(ename); \    if (entry) { \	if (leaf == entry->leaf) { \	    if (!leaf && !entry->tight && entry->next && \		entry->next->name == q && entry->next->tight && \		entry->next->hasloose && \		looseleaf((LTable)entry->next, names+1, classes+1, closure)) \		return True; \	    if ((*get)(entry, names+1, classes+1, closure)) \		return True; \	    if (entry->tight && (entry = entry->next) && \		entry->name == q && leaf == entry->leaf && \		(*get)(entry, names+1, classes+1, closure)) \		return True; \	} else if (entry->leaf) { \	    if (entry->hasloose && \		looseleaf((LTable)entry, names+1, classes+1, closure)) \		return True; \	    if (entry->tight && (entry = entry->next) && \		entry->name == q && entry->hasloose && \		looseleaf((LTable)entry, names+1, classes+1, closure)) \		return True; \	} \    }/* find entries named ename, leafness leaf, loose only, and call get */#define GLOOSE(ename,looseleaf) \    NFIND(ename); \    if (entry && entry->tight && (entry = entry->next) && entry->name != q) \	entry = (NTable)NULL; \    if (entry) { \	if (leaf == entry->leaf) { \	    if ((*get)(entry, names+1, classes+1, closure)) \		return True; \	} else if (entry->leaf && entry->hasloose) { \	    if (looseleaf((LTable)entry, names+1, classes+1, closure)) \		return True; \	} \    }/* add tight/loose entry to the search list, return True if list is full *//*ARGSUSED*/static Bool AppendLEntry(table, names, classes, closure)    LTable		table;    XrmNameList		names;    XrmClassList 	classes;    register SClosure	closure;{    /* check for duplicate */    if (closure->idx >= 0 && closure->list[closure->idx] == table)	return False;    if (closure->idx == closure->limit)	return True;    /* append it */    closure->idx++;    closure->list[closure->idx] = table;    return False;}/* add loose entry to the search list, return True if list is full *//*ARGSUSED*/static Bool AppendLooseLEntry(table, names, classes, closure)    LTable		table;    XrmNameList		names;    XrmClassList 	classes;    register SClosure	closure;{    /* check for duplicate */    if (closure->idx >= 0 && closure->list[closure->idx] == table)	return False;    if (closure->idx >= closure->limit - 1)	return True;    /* append it */    closure->idx++;    closure->list[closure->idx] = LOOSESEARCH;    closure->idx++;    closure->list[closure->idx] = table;    return False;}/* search for a leaf table */static Bool SearchNEntry(table, names, classes, closure)    NTable		table;    XrmNameList		names;    XrmClassList 	classes;    SClosure		closure;{    register NTable	entry;    register XrmQuark	q;    register unsigned int leaf;    Bool		(*get)();    if (names[1]) {	get = SearchNEntry; /* recurse */	leaf = 0;    } else {	get = AppendLEntry; /* bottom of recursion */	leaf = 1;    }    GTIGHTLOOSE(*names, AppendLooseLEntry);   /* do name, tight and loose */    GTIGHTLOOSE(*classes, AppendLooseLEntry); /* do class, tight and loose */    if (table->hasany) {	GTIGHTLOOSE(XrmQANY, AppendLooseLEntry); /* do ANY, tight and loose */    }    if (table->hasloose) {	while (1) {	    names++;	    classes++;	    if (!*names)		break;	    if (!names[1]) {		get = AppendLEntry; /* bottom of recursion */		leaf = 1;	    }	    GLOOSE(*names, AppendLooseLEntry);   /* loose names */	    GLOOSE(*classes, AppendLooseLEntry); /* loose classes */	    if (table->hasany) {		GLOOSE(XrmQANY, AppendLooseLEntry); /* loose ANY */	    }	}    }    /* now look for matching leaf nodes */    entry = table->next;    if (!entry)	return False;    if (entry->leaf) {	if (entry->tight && !table->tight)	    entry = entry->next;    } else {	entry = entry->next;	if (!entry || !entry->tight)	    return False;    }    if (!entry || entry->name != table->name)	return False;    /* found one */    if (entry->hasloose &&	AppendLooseLEntry((LTable)entry, names, classes, closure))	return True;    if (entry->tight && entry == table->next && (entry = entry->next) &&	entry->name == table->name && entry->hasloose)	return AppendLooseLEntry((LTable)entry, names, classes, closure);    return False;}Bool XrmQGetSearchList(db, names, classes, searchList, listLength)    XrmDatabase     db;    XrmNameList	    names;    XrmClassList    classes;    XrmSearchList   searchList;	/* RETURN */    int		    listLength;{    register NTable	table;    SClosureRec		closure;    if (listLength <= 0)	return False;    closure.list = (LTable *)searchList;    closure.idx = -1;    closure.limit = listLength - 2;    if (db) {	_XLockMutex(&db->linfo);	table = db->table;	if (*names) {	    if (table && !table->leaf) {		if (SearchNEntry(table, names, classes, &closure)) {		    _XUnlockMutex(&db->linfo);		    return False;		}	    } else if (table && table->hasloose &&		       AppendLooseLEntry((LTable)table, names, classes,					 &closure)) {		_XUnlockMutex(&db->linfo);		return False;	    }	} else {	    if (table && !table->leaf)		table = table->next;	    if (table && 		AppendLEntry((LTable)table, names, classes, &closure)) {		_XUnlockMutex(&db->linfo);		return False;	    }	}	_XUnlockMutex(&db->linfo);    }    closure.list[closure.idx + 1] = (LTable)NULL;    return True;}Bool XrmQGetSearchResource(searchList, name, class, pType, pValue)	     XrmSearchList	searchList;    register XrmName		name;    register XrmClass		class;    	     XrmRepresentation	*pType;  /* RETURN */    	     XrmValue		*pValue; /* RETURN */{    register LTable *list;    register LTable table;    register VEntry entry;    int flags;/* find tight or loose entry */#define VTIGHTLOOSE(q) \    entry = LeafHash(table, q); \    while (entry && entry->name != q) \	entry = entry->next; \    if (entry) \	break/* find loose entry */#define VLOOSE(q) \    entry = LeafHash(table, q); \    while (entry && entry->name != q) \	entry = entry->next; \    if (entry) { \	if (!entry->tight) \	    break; \	if ((entry = entry->next) && entry->name == q) \	    break; \    }    list = (LTable *)searchList;    /* figure out which combination of name and class we need to search for */    flags = 0;    if (IsResourceQuark(name))	flags = 2;    if (IsResourceQuark(class))	flags |= 1;    if (!flags) {	/* neither name nor class has ever been used to name a resource */	table = (LTable)NULL;    } else if (flags == 3) {	/* both name and class */	while ((table = *list++)) {	    if (table != LOOSESEARCH) {		VTIGHTLOOSE(name);  /* do name, tight and loose */		VTIGHTLOOSE(class); /* do class, tight and loose */	    } else {		table = *list++;		VLOOSE(name);  /* do name, loose only */		VLOOSE(class); /* do class, loose only */	    }	}    } else {	/* just one of name or class */	if (flags == 1)	    name = class;	while ((table = *list++)) {	    if (table != LOOSESEARCH) {		VTIGHTLOOSE(name); /* tight and loose */	    } else {		table = *list++;		VLOOSE(name); /* loose only */	    }	}    }    if (table) {	/* found a match */	if (entry->string) {	    *pType = XrmQString;	    pValue->addr = StringValue(entry);	} else {	    *pType = RepType(entry);	    pValue->addr = DataValue(entry);	}	pValue->size = entry->size;	return True;    }    *pType = NULLQUARK;    pValue->addr = (XPointer)NULL;    pValue->size = 0;    return False;#undef VTIGHTLOOSE#undef VLOOSE}/* look for a tight/loose value */static Bool GetVEntry(table, names, classes, closure)    LTable		table;    XrmNameList		names;    XrmClassList 	classes;    VClosure		closure;{    register VEntry entry;    register XrmQuark q;    /* try name first */    q = *names;    entry = LeafHash(table, q);    while (entry && entry->name != q)	entry = entry->next;    if (!entry) {	/* not found, try class */	q = *classes;	entry = LeafHash(table, q);	while (entry && entry->name != q)	    entry = entry->next;	if (!entry)	    return False;    }    if (entry->string) {	*closure->type = XrmQString;	closure->value->addr = StringValue(entry);    } else {	*closure->type = RepType(entry);	closure->value->addr = DataValue(entry);    }    closure->value->size = entry->size;    return True;}/* look for a loose value */static Bool GetLooseVEntry(table, names, classes, closure)    LTable		table;    XrmNameList		names;    XrmClassList 	classes;    VClosure		closure;{    register VEntry	entry;    register XrmQuark	q;#define VLOOSE(ename) \    q = ename; \    entry = LeafHash(table, q); \    while (entry && entry->name != q) \	entry = entry->next; \    if (entry && entry->tight && (entry = entry->next) && entry->name != q) \	entry = (VEntry)NULL;    /* bump to last component */    while (names[1]) {	names++;	classes++;    }    VLOOSE(*names);  /* do name, loose only */    if (!entry) {	VLOOSE(*classes); /* do class, loose only */	if (!entry)	    return False;    }    if (entry->string) {	*closure->type = XrmQString;	closure->value->addr = StringValue(entry);    } else {	*closure->type = RepType(entry);	closure->value->addr = DataValue(entry);    }    closure->value->size = entry->size;    return True;#undef VLOOSE}/* recursive search for a value */static Bool GetNEntry(table, names, clas

⌨️ 快捷键说明

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