/* * NAME * LoadColornameDB - Load the Color Name Database * * SYNOPSIS */ static Status LoadColornameDB(void) /* * DESCRIPTION * Loads the Color Name Database from a text file. * * RETURNS * XcmsSuccess if succeeded, otherwise XcmsFailure. * */ { int size; FILE *stream; char *pathname; struct stat txt; int length; /* use and name of this env var is not part of the standard */ /* implementation-dependent feature */ if ((pathname = getenv("XCMSDB")) == NULL) { pathname = XCMSDB; } #ifdef __UNIXOS2__ pathname = __XOS2RedirRoot(pathname); #endif length = strlen(pathname); if ((length == 0) || (length >= (BUFSIZ - 5))){ XcmsColorDbState = XcmsDbInitFailure; return(XcmsFailure); } if (stat(pathname, &txt)) { /* can't stat file */ XcmsColorDbState = XcmsDbInitFailure; return(XcmsFailure); } if ((stream = _XFopenFile (pathname, "r")) == NULL) { return(XcmsFailure); } stringSectionSize(stream, &nEntries, &size); rewind(stream); strings = (char *) Xmalloc(size); pairs = (XcmsPair *)Xcalloc(nEntries, sizeof(XcmsPair)); ReadColornameDB(stream, pairs, strings); (void) fclose(stream); /* * sort the pair recs */ qsort((char *)pairs, nEntries, sizeof(XcmsPair), FirstCmp); XcmsColorDbState = XcmsDbInitSuccess; return(XcmsSuccess); }
char *__XOS2RedirRoot1(char *format, char *arg1, char *arg2, char *arg3) { /* this first constructs a name from a format and up to three * components, then adds a path */ char buf[300]; sprintf(buf,format,arg1,arg2,arg3); return __XOS2RedirRoot(buf); }
static char * prependRoot (char *pathname) { #ifndef __EMX__ return pathname; #else /* XXXX caveat: multiple path components in line */ return (char *) __XOS2RedirRoot (pathname); #endif }
void __imlib_RescanLoaders(void) { static time_t last_scan_time = 0; static time_t last_modified_system_time = 0; time_t current_time; char do_reload = 0; /* dont stat the dir and rescan if we checked in the last 5 seconds */ current_time = time(NULL); if ((current_time - last_scan_time) < 5) return; /* ok - was the system loaders dir contents modified ? */ last_scan_time = current_time; #ifndef __EMX__ if (__imlib_FileIsDir(SYS_LOADERS_PATH "/loaders/")) #else if (__imlib_FileIsDir(__XOS2RedirRoot(SYS_LOADERS_PATH "/loaders/"))) #endif { #ifndef __EMX__ current_time = __imlib_FileModDate(SYS_LOADERS_PATH "/loaders/"); #else current_time = __imlib_FileModDate(__XOS2RedirRoot(SYS_LOADERS_PATH "/loaders/")); #endif if (current_time > last_modified_system_time) { /* yup - set the "do_reload" flag */ do_reload = 1; last_modified_system_time = current_time; } } /* if we dont ned to reload the loaders - get out now */ if (!do_reload) return; __imlib_RemoveAllLoaders(); __imlib_LoadAllLoaders(); }
void init_path_strings (void) { char* homedir = NULL; const char* intl_suffix = ""; #if defined (WIN32) find_libdir (); homedir = LIBDIR; #elif defined (__EMX__) strcpy(LIBDIR, __XOS2RedirRoot(OS2_DEFAULT_LIBDIR)); #else homedir = getenv ("HOME"); #endif #if defined (ENABLE_NLS) #if defined (HAVE_LC_MESSAGES) intl_suffix = guess_category_value(LC_MESSAGES,"LC_MESSAGES"); #else intl_suffix = guess_category_value(0,"LC_MESSAGES"); #endif #endif printf ("intl_suffix is %s\n", intl_suffix); lc_save_dir_len = strlen (homedir) + strlen (LC_SAVE_DIR) + 1; if ((lc_save_dir = (char *) malloc (lc_save_dir_len + 1)) == 0) malloc_failure (); sprintf (lc_save_dir, "%s%c%s", homedir, PATH_SLASH, LC_SAVE_DIR); sprintf (colour_pal_file, "%s%c%s", LIBDIR, PATH_SLASH, "colour.pal"); sprintf (opening_path, "%s%c%s", LIBDIR, PATH_SLASH, "opening"); #if defined (WIN32) sprintf (opening_pic, "%s%c%s",opening_path,PATH_SLASH,"open.tga"); #else sprintf (opening_pic, "%s%c%s",opening_path,PATH_SLASH,"open.tga.gz"); #endif sprintf (graphic_path, "%s%c%s%c", LIBDIR, PATH_SLASH, "icons", PATH_SLASH); if (strcmp(intl_suffix,"C") && strcmp(intl_suffix,"")) { sprintf (message_path, "%s%c%s%c%s%c", LIBDIR, PATH_SLASH, "messages", PATH_SLASH, intl_suffix, PATH_SLASH); sprintf (help_path, "%s%c%s%c%s%c", LIBDIR, PATH_SLASH, "help", PATH_SLASH, intl_suffix, PATH_SLASH); printf ("Trying Message Path %s\n", message_path); if (!directory_exists(message_path)) { sprintf (message_path, "%s%c%s%c", LIBDIR, PATH_SLASH, "messages", PATH_SLASH); printf ("Settling for message Path %s\n", message_path); } if (!directory_exists(help_path)) { sprintf (help_path, "%s%c%s%c", LIBDIR, PATH_SLASH, "help", PATH_SLASH); } } else { sprintf (message_path, "%s%c%s%c", LIBDIR, PATH_SLASH, "messages", PATH_SLASH); sprintf (help_path, "%s%c%s%c", LIBDIR, PATH_SLASH, "help", PATH_SLASH); printf ("Default message path %s\n", message_path); } sprintf (fontfile, "%s%c%s", opening_path, PATH_SLASH, "iso8859-1-8x8.raw"); #if defined (WIN32) /* GCS: Use windows font for extra speed */ strcpy (windowsfontfile, LIBDIR); if (!pix_double) strcat (windowsfontfile, "\\opening\\iso8859-1-8x8.fnt"); else strcat (windowsfontfile, "\\opening\\iso8859-1-9x15.fnt"); #endif lc_temp_filename = (char *) malloc (lc_save_dir_len + 16); if (lc_temp_filename == 0) { malloc_failure (); } sprintf (lc_temp_filename, "%s%c%s", lc_save_dir, PATH_SLASH, "tmp-file"); }
static void xlocalelibdir( char *buf, int buf_len) { char *p = buf; int len = 0; #ifndef NO_XLOCALEDIR char *dir; int priv = 1; dir = getenv("XLOCALELIBDIR"); if (dir) { #ifndef WIN32 /* * Only use the user-supplied path if the process isn't priviledged. */ if (getuid() == geteuid() && getgid() == getegid()) { #if defined(HASSETUGID) priv = issetugid(); #elif defined(HASGETRESUID) { uid_t ruid, euid, suid; gid_t rgid, egid, sgid; if ((getresuid(&ruid, &euid, &suid) == 0) && (getresgid(&rgid, &egid, &sgid) == 0)) priv = (euid != suid) || (egid != sgid); } #else /* * If there are saved ID's the process might still be priviledged * even though the above test succeeded. If issetugid() and * getresgid() aren't available, test this by trying to set * euid to 0. * * Note: this only protects setuid-root clients. It doesn't * protect other setuid or any setgid clients. If this tradeoff * isn't acceptable, set DisableXLocaleDirEnv to YES in host.def. */ unsigned int oldeuid; oldeuid = geteuid(); if (seteuid(0) != 0) { priv = 0; } else { if (seteuid(oldeuid) == -1) { /* XXX ouch, coudn't get back to original uid what can we do ??? */ _exit(127); } priv = 1; } #endif } #else priv = 0; #endif if (!priv) { len = strlen(dir); strncpy(p, dir, buf_len); if (len < buf_len) { p[len++] = LC_PATHDELIM; p += len; } } } #endif /* NO_XLOCALEDIR */ if (len < buf_len) #ifndef __UNIXOS2__ strncpy(p, XLOCALELIBDIR, buf_len - len); #else strncpy(p,__XOS2RedirRoot(XLOCALELIBDIR), buf_len - len); #endif buf[buf_len-1] = '\0'; }
/* * version that reads pixmap data as well as bitmap data */ Pixmap XmuLocatePixmapFile(Screen *screen, _Xconst char *name, unsigned long fore, unsigned long back, unsigned int depth, char *srcname, int srcnamelen, int *widthp, int *heightp, int *xhotp, int *yhotp) { #ifndef BITMAPDIR #define BITMAPDIR "/usr/include/X11/bitmaps" #endif Display *dpy = DisplayOfScreen (screen); Window root = RootWindowOfScreen (screen); Bool try_plain_name = True; XmuCvtCache *cache = _XmuCCLookupDisplay (dpy); char **file_paths = (char **) NULL; char filename[PATH_MAX]; #if 0 char* bitmapdir = BITMAPDIR; #endif unsigned int width, height; int xhot, yhot; int i; /* * look in cache for bitmap path */ if (cache) { if (!cache->string_to_bitmap.bitmapFilePath) { XrmName xrm_name[2]; XrmClass xrm_class[2]; XrmRepresentation rep_type; XrmValue value; xrm_name[0] = XrmPermStringToQuark ("bitmapFilePath"); xrm_name[1] = NULLQUARK; xrm_class[0] = XrmPermStringToQuark ("BitmapFilePath"); xrm_class[1] = NULLQUARK; if (!XrmGetDatabase(dpy)) { /* what a hack; need to initialize it */ (void) XGetDefault (dpy, "", ""); } if (XrmQGetResource (XrmGetDatabase(dpy), xrm_name, xrm_class, &rep_type, &value) && rep_type == XrmPermStringToQuark("String")) { cache->string_to_bitmap.bitmapFilePath = split_path_string (value.addr); } } file_paths = cache->string_to_bitmap.bitmapFilePath; } /* * Search order: * 1. name if it begins with / or ./ * 2. "each prefix in file_paths"/name * 3. BITMAPDIR/name * 4. name if didn't begin with / or . */ for (i = 1; i <= 4; i++) { char *fn = filename; Pixmap pixmap; unsigned char *data; switch (i) { case 1: #ifndef __UNIXOS2__ if (!(name[0] == '/' || ((name[0] == '.') && name[1] == '/'))) #else if (!(name[0] == '/' || (name[0] == '.' && name[1] == '/') || (isalpha(name[0]) && name[1] == ':'))) #endif continue; fn = (char *) name; try_plain_name = False; break; case 2: if (file_paths && *file_paths) { XmuSnprintf(filename, sizeof(filename), "%s/%s", *file_paths, name); file_paths++; i--; break; } continue; case 3: XmuSnprintf(filename, sizeof(filename), "%s/%s", BITMAPDIR, name); break; case 4: if (!try_plain_name) continue; fn = (char *) name; break; } data = NULL; pixmap = None; #ifdef __UNIXOS2__ fn = (char*)__XOS2RedirRoot(fn); #endif if (XmuReadBitmapDataFromFile (fn, &width, &height, &data, &xhot, &yhot) == BitmapSuccess) { pixmap = XCreatePixmapFromBitmapData (dpy, root, (char *) data, width, height, fore, back, depth); XFree ((char *)data); } if (pixmap) { if (widthp) *widthp = (int)width; if (heightp) *heightp = (int)height; if (xhotp) *xhotp = xhot; if (yhotp) *yhotp = yhot; if (srcname && srcnamelen > 0) { strncpy (srcname, fn, srcnamelen - 1); srcname[srcnamelen - 1] = '\0'; } return pixmap; } } return None; }
char * _XkbGetCharset(void) { /* * PAGE USAGE TUNING: explicitly initialize to move these to data * instead of bss */ static char buf[100] = { 0 }; char lang[256]; char *start,*tmp,*end,*next,*set; char *country,*charset; char *locale; tmp = getenv( "_XKB_CHARSET" ); if ( tmp ) return tmp; locale = setlocale(LC_CTYPE,NULL); if ( locale == NULL ) return NULL; if (strlen(locale) >= sizeof(lang)) return NULL; for (tmp = lang; *tmp = *locale++; tmp++) { if (isupper(*tmp)) *tmp = tolower(*tmp); } country = strchr( lang, '_'); if ( country ) { *country++ = '\0'; charset = strchr( country, '.' ); if ( charset ) *charset++ = '\0'; if ( charset ) { strncpy(buf,charset,99); buf[99] = '\0'; return buf; } } else { charset = NULL; } if ((tmp = getenv("_XKB_LOCALE_CHARSETS"))!=NULL) { start = _XkbAlloc(strlen(tmp) + 1); strcpy(start, tmp); tmp = start; } else { struct stat sbuf; FILE *file; #ifndef __UNIXOS2__ char *cf = CHARSET_FILE; #else char *cf = __XOS2RedirRoot(CHARSET_FILE); #endif #ifndef S_ISREG # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) #endif if ( (stat(cf,&sbuf)==0) && S_ISREG(sbuf.st_mode) && (file = fopen(cf,"r")) ) { tmp = _XkbAlloc(sbuf.st_size+1); if (tmp!=NULL) { sbuf.st_size = (long)fread(tmp,1,sbuf.st_size,file); tmp[sbuf.st_size] = '\0'; } fclose(file); } } if ( tmp == NULL ) { tmp = _XkbAlloc(strlen(_XkbKnownLanguages) + 1); if (!tmp) return NULL; strcpy(tmp, _XkbKnownLanguages); } start = tmp; do { if ( (set=strchr(tmp,'=')) == NULL ) break; *set++ = '\0'; if ( (next=strchr(set,':')) != NULL ) *next++ = '\0'; while ( tmp && *tmp ) { if ( (end=strchr(tmp,',')) != NULL ) *end++ = '\0'; if ( Strcmp( tmp, lang ) == 0 ) { strncpy(buf,set,100); buf[99] = '\0'; Xfree(start); return buf; } tmp = end; } tmp = next; } while ( tmp && *tmp ); Xfree(start); return NULL; }
static char * FindModule(const char *module, const char *dir, const char **subdirlist, PatternPtr patterns) { char buf[PATH_MAX + 1]; char *dirpath = NULL; char *name = NULL; struct stat stat_buf; int len, dirlen; char *fp; DIR *d; const char **subdirs = NULL; PatternPtr p = NULL; const char **s; struct dirent *dp; regmatch_t match[2]; subdirs = InitSubdirs(subdirlist); if (!subdirs) return NULL; #ifndef __EMX__ dirpath = (char *)dir; #else dirpath = xalloc(strlen(dir) + 10); strcpy(dirpath, (char *)__XOS2RedirRoot(dir)); #endif if (strlen(dirpath) > PATH_MAX) return NULL; /*xf86Msg(X_INFO,"OS2DIAG: FindModule: dirpath=%s\n",dirpath); */ for (s = subdirs; *s; s++) { if ((dirlen = strlen(dirpath) + strlen(*s)) > PATH_MAX) continue; strcpy(buf, dirpath); strcat(buf, *s); /*xf86Msg(X_INFO,"OS2DIAG: FindModule: buf=%s\n",buf); */ fp = buf + dirlen; if (stat(buf, &stat_buf) == 0 && S_ISDIR(stat_buf.st_mode) && (d = opendir(buf))) { if (buf[dirlen - 1] != '/') { buf[dirlen++] = '/'; fp++; } while ((dp = readdir(d))) { if (dirlen + strlen(dp->d_name) + 1 > PATH_MAX) continue; strcpy(fp, dp->d_name); if (!(stat(buf, &stat_buf) == 0 && S_ISREG(stat_buf.st_mode))) continue; for (p = patterns; p->pattern; p++) { if (regexec(&p->rex, dp->d_name, 2, match, 0) == 0 && match[1].rm_so != -1) { len = match[1].rm_eo - match[1].rm_so; if (len == strlen(module) && strncmp(module, dp->d_name + match[1].rm_so, len) == 0) { /*xf86Msg(X_INFO,"OS2DIAG: matching %s\n",buf); */ name = buf; break; } } } if (name) break; } closedir(d); if (name) break; } } FreeSubdirs(subdirs); if (dirpath != dir) xfree(dirpath); if (name) { return xstrdup(name); } return NULL; }
void find_libdir (void) { strcpy(LIBDIR, __XOS2RedirRoot(OS2_DEFAULT_LIBDIR)); }
Bool XkbDDXCompileNamedKeymap( XkbDescPtr xkb, XkbComponentNamesPtr names, char * nameRtrn, int nameRtrnLen) { char *cmd = NULL,file[PATH_MAX],xkm_output_dir[PATH_MAX],*map,*outFile; if (names->keymap==NULL) return False; strncpy(file,names->keymap,PATH_MAX); file[PATH_MAX-1]= '\0'; if ((map= strrchr(file,'('))!=NULL) { char *tmp; if ((tmp= strrchr(map,')'))!=NULL) { *map++= '\0'; *tmp= '\0'; } else { map= NULL; } } if ((outFile= strrchr(file,'/'))!=NULL) outFile= _XkbDupString(&outFile[1]); else outFile= _XkbDupString(file); XkbEnsureSafeMapName(outFile); OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir)); #ifdef NXAGENT_SERVER if (_NXGetXkbCompPath(XkbBaseDirectory) != NULL) { #else if (XkbBaseDirectory!=NULL) { #endif #ifndef __UNIXOS2__ #ifdef NXAGENT_SERVER char *xkbbasedir = _NXGetXkbBasePath(XkbBaseDirectory); char *xkbbindir = _NXGetXkbCompPath(XkbBinDirectory); #else char *xkbbasedir = XkbBaseDirectory; char *xkbbindir = XkbBinDirectory; #endif #else /* relocate the basedir and replace the slashes with backslashes */ #ifdef NXAGENT_SERVER char *xkbbasedir = (char*)__XOS2RedirRoot(_NXGetXkbBasePath(XkbBaseDirectory)); char *xkbbindir = (char*)__XOS2RedirRoot(_NXGetXkbCompPath(XkbBinDirectory)); #else char *xkbbasedir = (char*)__XOS2RedirRoot(XkbBaseDirectory); char *xkbbindir = (char*)__XOS2RedirRoot(XkbBinDirectory); #endif int i; for (i=0; i<strlen(xkbbasedir); i++) if (xkbbasedir[i]=='/') xkbbasedir[i]='\\'; for (i=0; i<strlen(xkbbindir); i++) if (xkbbindir[i]=='/') xkbbindir[i]='\\'; #endif cmd = Xprintf("\"%s" PATHSEPARATOR "xkbcomp\" -w %d \"-R%s\" -xkm %s%s -em1 %s -emp %s -eml %s keymap/%s \"%s%s.xkm\"", xkbbindir, ((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)), xkbbasedir,(map?"-m ":""),(map?map:""), PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,file, xkm_output_dir,outFile); } else { cmd = Xprintf("xkbcomp -w %d -xkm %s%s -em1 %s -emp %s -eml %s keymap/%s \"%s%s.xkm\"", ((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)), (map?"-m ":""),(map?map:""), PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,file, xkm_output_dir,outFile); } #ifdef DEBUG if (xkbDebugFlags) { ErrorF("XkbDDXCompileNamedKeymap compiling keymap using:\n"); ErrorF(" \"cmd\"\n"); } #endif #ifdef DEBUG_CMD ErrorF("xkb executes: %s\n",cmd); #endif if (System(cmd)==0) { if (nameRtrn) { strncpy(nameRtrn,outFile,nameRtrnLen); nameRtrn[nameRtrnLen-1]= '\0'; } if (outFile!=NULL) _XkbFree(outFile); if (cmd!=NULL) xfree(cmd); return True; } #ifdef DEBUG ErrorF("Error compiling keymap (%s)\n",names->keymap); #endif if (outFile!=NULL) _XkbFree(outFile); if (cmd!=NULL) xfree(cmd); return False; } Bool XkbDDXCompileKeymapByNames( XkbDescPtr xkb, XkbComponentNamesPtr names, unsigned want, unsigned need, char * nameRtrn, int nameRtrnLen) { FILE * out; char *buf = NULL, keymap[PATH_MAX],xkm_output_dir[PATH_MAX]; #ifdef WIN32 char tmpname[PATH_MAX]; #endif if ((names->keymap==NULL)||(names->keymap[0]=='\0')) { sprintf(keymap,"server-%s",display); } else { if (strlen(names->keymap) > PATH_MAX - 1) { ErrorF("name of keymap (%s) exceeds max length\n", names->keymap); return False; } strcpy(keymap,names->keymap); } XkbEnsureSafeMapName(keymap); OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir)); #ifdef WIN32 strcpy(tmpname, Win32TempDir()); strcat(tmpname, "\\xkb_XXXXXX"); (void) mktemp(tmpname); #endif #ifdef NXAGENT_SERVER if (_NXGetXkbCompPath(XkbBaseDirectory)!=NULL) { #else if (XkbBaseDirectory!=NULL) { #endif #ifndef WIN32 char *xkmfile = "-"; #else /* WIN32 has no popen. The input must be stored in a file which is used as input for xkbcomp. xkbcomp does not read from stdin. */ char *xkmfile = tmpname; #endif #ifndef __UNIXOS2__ #ifdef NXAGENT_SERVER char *xkbbasedir = _NXGetXkbBasePath(XkbBaseDirectory); char *xkbbindir = _NXGetXkbCompPath(XkbBinDirectory); #else char *xkbbasedir = XkbBaseDirectory; char *xkbbindir = XkbBinDirectory; #endif #else int i; #ifdef NXAGENT_SERVER char *xkbbasedir = (char*)__XOS2RedirRoot(_NXGetXkbBasePath(XkbBaseDirectory)); char *xkbbindir = (char*)__XOS2RedirRoot(_NXGetXkbCompPath(XkbBinDirectory)); #else char *xkbbasedir = (char*)__XOS2RedirRoot(XkbBaseDirectory); char *xkbbindir = (char*)__XOS2RedirRoot(XkbBinDirectory); #endif for (i=0; i<strlen(xkbbasedir); i++) if (xkbbasedir[i]=='/') xkbbasedir[i]='\\'; for (i=0; i<strlen(xkbbindir); i++) if (xkbbindir[i]=='/') xkbbindir[i]='\\'; #endif buf = Xprintf( "\"%s" PATHSEPARATOR "xkbcomp\" -w %d \"-R%s\" -xkm \"%s\" -em1 %s -emp %s -eml %s \"%s%s.xkm\"", xkbbindir, ((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)), xkbbasedir, xkmfile, PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1, xkm_output_dir,keymap); } else { #ifndef WIN32 char *xkmfile = "-"; #else char *xkmfile = tmpname; #endif buf = Xprintf( "xkbcomp -w %d -xkm \"%s\" -em1 %s -emp %s -eml %s \"%s%s.xkm\"", ((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)), xkmfile, PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1, xkm_output_dir,keymap); } #ifdef TEST if (buf != NULL) fprintf(stderr, "XkbDDXCompileKeymapByNames: " "Executing command [%s].\n", buf); else fprintf(stderr, "XkbDDXCompileKeymapByNames: " "Callin Popen() with null command.\n"); #endif #ifndef WIN32 out= Popen(buf,"w"); #else out= fopen(tmpname, "w"); #endif if (out!=NULL) { #ifdef DEBUG if (xkbDebugFlags) { ErrorF("XkbDDXCompileKeymapByNames compiling keymap:\n"); XkbWriteXKBKeymapForNames(stderr,names,NULL,xkb,want,need); } #endif XkbWriteXKBKeymapForNames(out,names,NULL,xkb,want,need); #ifndef WIN32 #ifdef __sun if (Pclose(out) != 0) { ErrorF("Warning: Spurious failure reported in Pclose() runnning 'xkbcomp'.\n"); } if (1) #else if (Pclose(out)==0) #endif #else if (fclose(out)==0 && System(buf) >= 0) #endif { #ifdef DEBUG_CMD ErrorF("xkb executes: %s\n",buf); ErrorF("xkbcomp input:\n"); XkbWriteXKBKeymapForNames(stderr,names,NULL,xkb,want,need); ErrorF("end xkbcomp input\n"); #endif if (nameRtrn) { strncpy(nameRtrn,keymap,nameRtrnLen); nameRtrn[nameRtrnLen-1]= '\0'; } #if defined(Lynx) && defined(__i386__) && defined(NEED_POPEN_WORKAROUND) /* somehow popen/pclose is broken on LynxOS AT 2.3.0/2.4.0! * the problem usually shows up with XF86Setup * this hack waits at max 5 seconds after pclose() returns * for the output of the xkbcomp output file. * I didn't manage to get a patch in time for the 3.2 release */ { int i; char name[PATH_MAX]; #ifdef NXAGENT_SERVER if (_NXGetXkbCompPath(XkbBaseDirectory)!=NULL) sprintf(name,"%s/%s%s.xkm", _NXGetXkbCompPath(XkbBaseDirectory) ,xkm_output_dir, keymap); #else if (XkbBaseDirectory!=NULL) sprintf(name,"%s/%s%s.xkm", XkbBaseDirectory ,xkm_output_dir, keymap); #endif else sprintf(name,"%s%s.xkm", xkm_output_dir, keymap); for (i = 0; i < 10; i++) { if (access(name, 0) == 0) break; usleep(500000); } #ifdef DEBUG if (i) ErrorF(">>>> Waited %d times for %s\n", i, name); #endif } #endif if (buf != NULL) xfree (buf); return True; } #ifdef DEBUG else ErrorF("Error compiling keymap (%s)\n",keymap); #endif #ifdef WIN32 /* remove the temporary file */ unlink(tmpname); #endif } #ifdef DEBUG else { #ifndef WIN32 ErrorF("Could not invoke keymap compiler\n"); #else ErrorF("Could not open file %s\n", tmpname); #endif } #endif if (nameRtrn) nameRtrn[0]= '\0'; if (buf != NULL) xfree (buf); return False; } FILE * XkbDDXOpenConfigFile(char *mapName,char *fileNameRtrn,int fileNameRtrnLen) { char buf[PATH_MAX],xkm_output_dir[PATH_MAX]; FILE * file; buf[0]= '\0'; if (mapName!=NULL) { OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir)); if ((XkbBaseDirectory!=NULL)&&(xkm_output_dir[0]!='/') #ifdef WIN32 &&(!isalpha(xkm_output_dir[0]) || xkm_output_dir[1]!=':') #endif ) { if (strlen(XkbBaseDirectory)+strlen(xkm_output_dir) +strlen(mapName)+6 <= PATH_MAX) { sprintf(buf,"%s/%s%s.xkm",XkbBaseDirectory, xkm_output_dir,mapName); } } else if (strlen(xkm_output_dir)+strlen(mapName)+5 <= PATH_MAX) sprintf(buf,"%s%s.xkm",xkm_output_dir,mapName); if (buf[0] != '\0') file= fopen(buf,"rb"); else file= NULL; } else file= NULL; if ((fileNameRtrn!=NULL)&&(fileNameRtrnLen>0)) { strncpy(fileNameRtrn,buf,fileNameRtrnLen); buf[fileNameRtrnLen-1]= '\0'; } return file; }
String XtFindFile( _Xconst char* path, Substitution substitutions, Cardinal num_substitutions, XtFilePredicate predicate) { char *buf, *buf1, *buf2, *colon; int len; Boolean firstTime = TRUE; buf = buf1 = __XtMalloc((unsigned)PATH_MAX); buf2 = __XtMalloc((unsigned)PATH_MAX); if (predicate == NULL) predicate = TestFile; while (1) { colon = (String)path; /* skip leading colons */ while (*colon) { if (*colon != ':') break; colon++; path++; } /* now look for an un-escaped colon */ for ( ; *colon ; colon++) { if (*colon == '%' && *(path+1)) { colon++; /* bump it an extra time to skip %. */ continue; } if (*colon == ':') #ifdef __UNIXOS2__ if (colon > (path+1)) #endif break; } len = colon - path; if (Resolve(path, len, substitutions, num_substitutions, buf, '/')) { if (firstTime || strcmp(buf1,buf2) != 0) { #ifdef __UNIXOS2__ { char *bufx = (char*)__XOS2RedirRoot(buf); strcpy(buf,bufx); } #endif #ifdef XNL_DEBUG printf("Testing file %s\n", buf); #endif /* XNL_DEBUG */ /* Check out the file */ if ((*predicate) (buf)) { /* We've found it, return it */ #ifdef XNL_DEBUG printf("File found.\n"); #endif /* XNL_DEBUG */ if (buf == buf1) XtFree(buf2); else XtFree(buf1); return buf; } if (buf == buf1) buf = buf2; else buf = buf1; firstTime = FALSE; } } /* Nope...any more paths? */ if (*colon == '\0') break; path = colon+1; } /* No file found */ XtFree(buf1); XtFree(buf2); return NULL; }
Bool OsInitColors(void) { FILE *rgb; char *path; char line[BUFSIZ]; char name[BUFSIZ]; int red, green, blue, lineno = 0; dbEntryPtr entry; static Bool was_here = FALSE; if (!was_here) { #ifndef __UNIXOS2__ path = (char*)ALLOCATE_LOCAL(strlen(rgbPath) +5); strcpy(path, rgbPath); strcat(path, ".txt"); #else char *tmp = (char*)__XOS2RedirRoot(rgbPath); path = (char*)ALLOCATE_LOCAL(strlen(tmp) +5); strcpy(path, tmp); strcat(path, ".txt"); #endif if (!(rgb = fopen(path, "r"))) { ErrorF( "Couldn't open RGB_DB '%s'\n", rgbPath ); DEALLOCATE_LOCAL(path); return FALSE; } while(fgets(line, sizeof(line), rgb)) { lineno++; #ifndef __UNIXOS2__ if (sscanf(line,"%d %d %d %[^\n]\n", &red, &green, &blue, name) == 4) #else if (sscanf(line,"%d %d %d %[^\n\r]\n", &red, &green, &blue, name) == 4) #endif { if (red >= 0 && red <= 0xff && green >= 0 && green <= 0xff && blue >= 0 && blue <= 0xff) { if ((entry = lookup(name, strlen(name), TRUE))) { entry->red = (red * 65535) / 255; entry->green = (green * 65535) / 255; entry->blue = (blue * 65535) / 255; } } else ErrorF("Value out of range: %s:%d\n", path, lineno); } else if (*line && *line != '#' && *line != '!') ErrorF("Syntax Error: %s:%d\n", path, lineno); } fclose(rgb); DEALLOCATE_LOCAL(path); was_here = TRUE; } return TRUE; }
int XReadBitmapFileData ( _Xconst char *filename, unsigned int *width, /* RETURNED */ unsigned int *height, /* RETURNED */ unsigned char **data, /* RETURNED */ int *x_hot, /* RETURNED */ int *y_hot) /* RETURNED */ { FILE *fstream; /* handle on file */ unsigned char *bits = NULL; /* working variable */ char line[MAX_SIZE]; /* input line from file */ int size; /* number of bytes of data */ char name_and_type[MAX_SIZE]; /* an input line */ char *type; /* for parsing */ int value; /* from an input line */ int version10p; /* boolean, old format */ int padding; /* to handle alignment */ int bytes_per_line; /* per scanline of data */ unsigned int ww = 0; /* width */ unsigned int hh = 0; /* height */ int hx = -1; /* x hotspot */ int hy = -1; /* y hotspot */ #ifdef __UNIXOS2__ filename = __XOS2RedirRoot(filename); #endif if (!(fstream = fopen(filename, "r"))) return BitmapOpenFailed; /* error cleanup and return macro */ #define RETURN(code) \ { if (bits) Xfree ((char *)bits); fclose (fstream); return code; } while (fgets(line, MAX_SIZE, fstream)) { if (strlen(line) == MAX_SIZE-1) RETURN (BitmapFileInvalid); if (sscanf(line,"#define %s %d",name_and_type,&value) == 2) { if (!(type = strrchr(name_and_type, '_'))) type = name_and_type; else type++; if (!strcmp("width", type)) ww = (unsigned int) value; if (!strcmp("height", type)) hh = (unsigned int) value; if (!strcmp("hot", type)) { if (type-- == name_and_type || type-- == name_and_type) continue; if (!strcmp("x_hot", type)) hx = value; if (!strcmp("y_hot", type)) hy = value; } continue; } if (sscanf(line, "static short %s = {", name_and_type) == 1) version10p = 1; else if (sscanf(line,"static unsigned char %s = {",name_and_type) == 1) version10p = 0; else if (sscanf(line, "static char %s = {", name_and_type) == 1) version10p = 0; else continue; if (!(type = strrchr(name_and_type, '_'))) type = name_and_type; else type++; if (strcmp("bits[]", type)) continue; if (!ww || !hh) RETURN (BitmapFileInvalid); if ((ww % 16) && ((ww % 16) < 9) && version10p) padding = 1; else padding = 0; bytes_per_line = (ww+7)/8 + padding; size = bytes_per_line * hh; bits = (unsigned char *) Xmalloc ((unsigned int) size); if (!bits) RETURN (BitmapNoMemory); if (version10p) { unsigned char *ptr; int bytes; for (bytes=0, ptr=bits; bytes<size; (bytes += 2)) { if ((value = NextInt(fstream)) < 0) RETURN (BitmapFileInvalid); *(ptr++) = value; if (!padding || ((bytes+2) % bytes_per_line)) *(ptr++) = value >> 8; } } else { unsigned char *ptr; int bytes; for (bytes=0, ptr=bits; bytes<size; bytes++, ptr++) { if ((value = NextInt(fstream)) < 0) RETURN (BitmapFileInvalid); *ptr=value; } } } /* end while */
int parse_database() { FILE *f; char buf[128]; int i, lineno; char filename[128]; #ifndef __UNIXOS2__ strcpy(filename, CARD_DATABASE_FILE); #else strcpy(filename, (char*)__XOS2RedirRoot(CARD_DATABASE_FILE)); #endif f = fopen(filename, "r"); if (f == NULL) return -1; lastcard = -1; lineno = 0; for (;;) { if (getnextline(f, buf)) break; lineno++; if (buf[0] == '#') /* Comment. */ continue; if (strncmp(buf, "END", 3) == 0) /* End of database. */ break; if (strncmp(buf, "LINE", 4) == 0 && lastcard>=0) { /* Line of Device comment. */ /* Append to existing lines. */ appendstring(&card[lastcard].lines, buf + 5); continue; } /* * The following keywords require the trailing newline * to be deleted. */ i = strlen(buf); buf[--i] = '\0'; /* remove trailing spaces or tabs */ for(--i; i>=0 && (buf[i] == ' ' || buf[i] == '\011'); i--) ; if (i>=0) buf[i+1] = '\0'; else continue; /* skip empty lines */ if (strncmp(buf, "NAME", 4) == 0) { /* New entry. */ lastcard++; card[lastcard].name = malloc(strlen(buf + 5) + 1); strcpy(card[lastcard].name, buf + 5); card[lastcard].chipset = NULL; card[lastcard].server = NULL; card[lastcard].driver = NULL; card[lastcard].ramdac = NULL; card[lastcard].clockchip = NULL; card[lastcard].dacspeed = NULL; card[lastcard].flags = 0; card[lastcard].lines = ""; continue; } if (lastcard < 0) /* no NAME line found yet */ continue; if (strncmp(buf, "SEE", 3) == 0) { /* Reference to another entry. */ int i; i = lookupcard(buf + 4); if (i == -1) { printf("Error in database, invalid reference: %s.\n", buf + 4); free(card[lastcard].name); lastcard--; continue; } if (card[lastcard].chipset == NULL) card[lastcard].chipset = card[i].chipset; if (card[lastcard].server == NULL) card[lastcard].server = card[i].server; if (card[lastcard].driver == NULL) card[lastcard].driver = card[i].driver; if (card[lastcard].ramdac == NULL) card[lastcard].ramdac = card[i].ramdac; if (card[lastcard].clockchip == NULL) card[lastcard].clockchip = card[i].clockchip; if (card[lastcard].dacspeed == NULL) card[lastcard].dacspeed = card[i].dacspeed; card[lastcard].flags |= card[i].flags; appendstring(&card[lastcard].lines, card[i].lines); continue; } if (strncmp(buf, "CHIPSET", 7) == 0) { /* Chipset description. */ card[lastcard].chipset = malloc(strlen(buf + 8) + 1); strcpy(card[lastcard].chipset, buf + 8); continue; } if (strncmp(buf, "SERVER", 6) == 0) { /* Server identifier. */ card[lastcard].server = malloc(strlen(buf + 7) + 1); strcpy(card[lastcard].server, buf + 7); continue; } if (strncmp(buf, "DRIVER", 6) == 0) { /* Driver identifier. */ card[lastcard].driver = malloc(strlen(buf + 7) + 1); strcpy(card[lastcard].driver, buf + 7); continue; } if (strncmp(buf, "RAMDAC", 6) == 0) { /* Ramdac indentifier. */ card[lastcard].ramdac = malloc(strlen(buf + 7) + 1); strcpy(card[lastcard].ramdac, buf + 7); continue; } if (strncmp(buf, "CLOCKCHIP", 9) == 0) { /* Clockchip indentifier. */ card[lastcard].clockchip = malloc(strlen(buf + 10) + 1); strcpy(card[lastcard].clockchip, buf + 10); card[lastcard].flags |= NOCLOCKPROBE; continue; } if (strncmp(buf, "DACSPEED", 8) == 0) { /* Clockchip indentifier. */ card[lastcard].dacspeed = malloc(strlen(buf + 9) + 1); strcpy(card[lastcard].dacspeed, buf + 9); continue; } if (strncmp(buf, "NOCLOCKPROBE", 12) == 0) { card[lastcard].flags |= NOCLOCKPROBE; continue; } if (strncmp(buf, "UNSUPPORTED", 12) == 0) { card[lastcard].flags |= UNSUPPORTED; continue; } /* test for missing required fields */ if (card[lastcard].driver == NULL) { fprintf(stderr, "Warning DRIVER specification missing " "in Card database entry %s (line %d).\n", card[lastcard].name, lineno); keypress(); card[lastcard].driver = "unknown"; } if (card[lastcard].chipset == NULL) { fprintf(stderr, "Warning CHIPSET specification missing " "in Card database entry %s (line %d).\n", card[lastcard].name, lineno); keypress(); card[lastcard].chipset = "unknown"; } } fclose(f); /* * Add general comments. */ for (i = 0; i <= lastcard; i++) { if (card[i].server && strcmp(card[i].server, "S3") == 0) appendstring(&card[i].lines, s3_comment); if (card[i].chipset && strncmp(card[i].chipset, "CL-GD", 5) == 0) appendstring(&card[i].lines, cirrus_comment); } sort_database(); return 0; }