📄 xrm.c
字号:
/*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) { table = db->table; if (*names) { if (table && !table->leaf) { if (SearchNEntry(table, names, classes, &closure)) return False; } else if (table && table->hasloose && AppendLooseLEntry((LTable)table, names, classes, &closure)) return False; } else { if (table && !table->leaf) table = table->next; if (table && AppendLEntry((LTable)table, names, classes, &closure)) return False; } } 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, classes, closure) NTable table; XrmNameList names; XrmClassList classes; VClosure closure;{ register NTable entry; register XrmQuark q; register unsigned int leaf; Bool (*get)(); NTable otable; if (names[2]) { get = GetNEntry; /* recurse */ leaf = 0; } else { get = GetVEntry; /* bottom of recursion */ leaf = 1; } GTIGHTLOOSE(*names, GetLooseVEntry); /* do name, tight and loose */ GTIGHTLOOSE(*classes, GetLooseVEntry); /* do class, tight and loose */ if (table->hasany) { GTIGHTLOOSE(XrmQANY, GetLooseVEntry); /* do ANY, tight and loose */ } if (table->hasloose) { while (1) { names++; classes++; if (!names[1]) break; if (!names[2]) { get = GetVEntry; /* bottom of recursion */ leaf = 1; } GLOOSE(*names, GetLooseVEntry); /* do name, loose only */ GLOOSE(*classes, GetLooseVEntry); /* do class, loose only */ if (table->hasany) { GLOOSE(XrmQANY, GetLooseVEntry); /* do ANY, loose only */ } } } /* look for matching leaf tables */ otable = table; table = table->next; if (!table) return False; if (table->leaf) { if (table->tight && !otable->tight) table = table->next; } else { table = table->next; if (!table || !table->tight) return False; } if (!table || table->name != otable->name) return False; /* found one */ if (table->hasloose && GetLooseVEntry((LTable)table, names, classes, closure)) return True; if (table->tight && table == otable->next) { table = table->next; if (table && table->name == otable->name && table->hasloose) return GetLooseVEntry((LTable)table, names, classes, closure); } return False;}Bool XrmQGetResource(db, names, classes, pType, pValue) XrmDatabase db; XrmNameList names; XrmClassList classes; XrmRepresentation *pType; /* RETURN */ XrmValuePtr pValue; /* RETURN */{ register NTable table; VClosureRec closure; if (db && *names) { closure.type = pType; closure.value = pValue; table = db->table; if (names[1]) { if (table && !table->leaf) { if (GetNEntry(table, names, classes, &closure)) return True; } else if (table && table->hasloose && GetLooseVEntry((LTable)table, names, classes, &closure)) return True; } else { if (table && !table->leaf) table = table->next; if (table && GetVEntry((LTable)table, names, classes, &closure)) return True; } } *pType = NULLQUARK; pValue->addr = (XPointer)NULL; pValue->size = 0; return False;}#if NeedFunctionPrototypesBool XrmGetResource(db, name_str, class_str, pType_str, pValue) XrmDatabase db; _Xconst char *name_str; _Xconst char *class_str; XrmString *pType_str; /* RETURN */ XrmValuePtr pValue; /* RETURN */#elseBool XrmGetResource(db, name_str, class_str, pType_str, pValue) XrmDatabase db; XrmString name_str; XrmString class_str; XrmString *pType_str; /* RETURN */ XrmValuePtr pValue; /* RETURN */#endif{ XrmName names[MAXDBDEPTH+1]; XrmClass classes[MAXDBDEPTH+1]; XrmRepresentation fromType; Bool result; XrmStringToNameList(name_str, names); XrmStringToClassList(class_str, classes); result = XrmQGetResource(db, names, classes, &fromType, pValue); (*pType_str) = XrmQuarkToString(fromType); return result;}/* destroy all values, plus table itself */static void DestroyLTable(table) LTable table;{ register int i; register VEntry *buckets; register VEntry entry, next; buckets = table->buckets; for (i = table->table.mask; i >= 0; i--, buckets++) { for (next = *buckets; entry = next; ) { next = entry->next; Xfree((char *)entry); } } Xfree((char *)table->buckets); Xfree((char *)table);}/* destroy all contained tables, plus table itself */static void DestroyNTable(table) NTable table;{ register int i; register NTable *buckets; register NTable entry, next; buckets = NodeBuckets(table); for (i = table->mask; i >= 0; i--, buckets++) { for (next = *buckets; entry = next; ) { next = entry->next; if (entry->leaf) DestroyLTable((LTable)entry); else DestroyNTable(entry); } } Xfree((char *)table);}char *XrmLocaleOfDatabase(db) XrmDatabase db;{ return (*db->methods->lcname)(db->mbstate);}void XrmDestroyDatabase(db) XrmDatabase db;{ register NTable table, next; if (db) { for (next = db->table; table = next; ) { next = table->next; if (table->leaf) DestroyLTable((LTable)table); else DestroyNTable(table); } (*db->methods->destroy)(db->mbstate); Xfree((char *)db); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -