/*ARGSUSED*/ int OsLookupColor(int screen, char *name, unsigned int len, unsigned short *pred, unsigned short *pgreen, unsigned short *pblue) { datum dbent; RGB rgb; char buf[64]; char *lowername; if(!rgb_dbm) return(0); /* we use xalloc here so that we can compile with cc without alloca * when otherwise using gcc */ if (len < sizeof(buf)) lowername = buf; else if (!(lowername = (char *)xalloc(len + 1))) return(0); CopyISOLatin1Lowered ((unsigned char *) lowername, (unsigned char *) name, (int)len); dbent.dptr = lowername; dbent.dsize = len; #ifdef NDBM dbent = dbm_fetch(rgb_dbm, dbent); #else dbent = fetch (dbent); #endif if (len >= sizeof(buf)) xfree(lowername); if(dbent.dptr) { memmove((char *) &rgb, dbent.dptr, sizeof (RGB)); *pred = rgb.red; *pgreen = rgb.green; *pblue = rgb.blue; return (1); } return(0); }
static dbEntryPtr lookup(char *name, int len, Bool create) { unsigned int h = 0, g; dbEntryPtr entry, *prev = NULL; char *str = name; if (!(name = (char*)ALLOCATE_LOCAL(len +1))) return NULL; CopyISOLatin1Lowered((unsigned char *)name, (unsigned char *)str, len); name[len] = '\0'; for(str = name; *str; str++) { h = (h << 4) + *str; if ((g = h) & 0xf0000000) h ^= (g >> 24); h &= g; } h %= HASHSIZE; if ( (entry = hashTab[h]) ) { for( ; entry; prev = (dbEntryPtr*)entry, entry = entry->link ) if (! strcmp(name, entry->name) ) break; } else prev = &(hashTab[h]); if (!entry && create && (entry = (dbEntryPtr)xalloc(sizeof(dbEntry) +len))) { *prev = entry; entry->link = NULL; strcpy( entry->name, name ); } DEALLOCATE_LOCAL(name); return entry; }
static Bool AddFileNameAliases(FontDirectoryPtr dir) { int i; char copy[MAXFONTFILENAMELEN]; char *fileName; FontTablePtr table; FontRendererPtr renderer; int len; FontNameRec name; table = &dir->nonScalable; for (i = 0; i < table->used; i++) { if (table->entries[i].type != FONT_ENTRY_BITMAP) continue; fileName = table->entries[i].u.bitmap.fileName; renderer = FontFileMatchRenderer (fileName); if (!renderer) continue; len = strlen (fileName) - renderer->fileSuffixLen; if (len >= sizeof(copy)) continue; CopyISOLatin1Lowered (copy, fileName, len); copy[len] = '\0'; name.name = copy; name.length = len; name.ndashes = FontFileCountDashes (copy, len); if (!FontFileFindNameInDir(table, &name)) { if (!FontFileAddFontAlias (dir, copy, table->entries[i].name.name)) return FALSE; } } return TRUE; }
static int ReadFontAlias(char *directory, Bool isFile, FontDirectoryPtr *pdir) { char alias[MAXFONTNAMELEN]; char font_name[MAXFONTNAMELEN]; char alias_file[MAXFONTFILENAMELEN]; FILE *file; FontDirectoryPtr dir; int token; char *lexToken; int status = Successful; struct stat statb; if (strlen(directory) >= sizeof(alias_file)) return BadFontPath; dir = *pdir; strcpy(alias_file, directory); if (!isFile) { if (strlen(directory) + 1 + sizeof(FontAliasFile) > sizeof(alias_file)) return BadFontPath; if (directory[strlen(directory) - 1] != '/') strcat(alias_file, "/"); strcat(alias_file, FontAliasFile); } file = fopen(alias_file, "rt"); if (!file) return ((errno == ENOENT) ? Successful : BadFontPath); if (!dir) *pdir = dir = FontFileMakeDir(directory, 10); if (!dir) { fclose (file); return AllocError; } #ifndef WIN32 if (fstat (fileno (file), &statb) == -1) #else if (stat (alias_file, &statb) == -1) #endif { fclose (file); return BadFontPath; } dir->alias_mtime = statb.st_mtime; while (status == Successful) { token = lexAlias(file, &lexToken); switch (token) { case NEWLINE: break; case DONE: fclose(file); return Successful; case EALLOC: status = AllocError; break; case NAME: if (strlen(lexToken) >= sizeof(alias)) { status = BadFontPath; break; } strcpy(alias, lexToken); token = lexAlias(file, &lexToken); switch (token) { case NEWLINE: if (strcmp(alias, "FILE_NAMES_ALIASES")) status = BadFontPath; else if (!AddFileNameAliases(dir)) status = AllocError; break; case DONE: status = BadFontPath; break; case EALLOC: status = AllocError; break; case NAME: if (strlen(lexToken) >= sizeof(font_name)) { status = BadFontPath; break; } CopyISOLatin1Lowered(alias, alias, strlen(alias)); CopyISOLatin1Lowered(font_name, lexToken, strlen(lexToken)); if (!FontFileAddFontAlias (dir, alias, font_name)) status = AllocError; break; } } } fclose(file); return status; }