Esempio n. 1
0
File: SmDB.c Progetto: juddy/edcde
static Boolean
_getStringArrayResource(XrmDatabase xrmDB, char *fmtStr,
			char *clientID, char ***resourcePtr,
			char **defaultVal)
{
    XrmQuark resourceName[3];
    XrmQuark resourceClass[3];
    char *resourceType;
    XrmValue resourceValue;
    int nStrings;

    resourceName[0] = resourceName[1] = anyQuark;
    resourceName[2] = NULLQUARK;

    if (NULL == resourceBuf) resourceBuf = XtMalloc(RESOURCE_BUF_SZ);
    sprintf(resourceBuf, fmtStr, clientID);
    XrmStringToQuarkList(resourceBuf, resourceClass);

    nStrings = 0;
    XrmEnumerateDatabase(xrmDB, resourceName, resourceClass,
			 XrmEnumOneLevel, _countProc,
			 (XPointer)&nStrings);

    if (nStrings > 0)
    {
	char **stringsPtr;
	int i;

	if ((stringsPtr = (char **)XtMalloc((nStrings + 1) * sizeof(char *)))
	    == (char **)NULL)
	    return False;

	/* Initialize array entries to NULL so free can work. */
	/* NOTE: Final entry (nStrings) will remain NULL. */
	for (i = 0; i <= nStrings; i++)
	    stringsPtr[i] = (char *)NULL;

	if (XrmEnumerateDatabase(xrmDB,
				 resourceName, resourceClass,
				 XrmEnumOneLevel, _fillStringArrayProc,
				 (XPointer)stringsPtr))
	{
	    for (i = 0; i < nStrings; i++)
		XtFree(stringsPtr[i]);
	    XtFree((char *)stringsPtr);
	    return False;
	}

	*resourcePtr = stringsPtr;
	return True;
    }

    *resourcePtr = defaultVal;
    return True;
}
Esempio n. 2
0
int
main (int argc, char *argv[])
{
    Widget toplevel;
    char *iname = NONAME, *cname = NONAME;
    XtAppContext xtcontext;
    XrmName names[101];
    XrmClass classes[101];
    int i;
    int mode = XrmEnumAllLevels;

    ProgramName = argv[0];
    if (argc > 1 && argv[1][0] != '-') {
	cname = argv[1];
	if (argc > 2 && argv[2][0] != '-')
	    iname = argv[2];
    }

    XrmStringToClassList(cname, classes);
    XrmStringToNameList(iname, names);
    for (i = 0; names[i]; i++)
	;
    if (!i || classes[i] || !classes[i-1]) usage ();
    argv[0] = XrmNameToString(names[0]);

    toplevel = XtAppInitialize(&xtcontext, XrmClassToString(classes[0]),
			       NULL, 0, &argc, argv, NULL, NULL, 0);

    iname = NULL;
    cname = NULL;
    for (i = 1; i < argc; i++) {
	if (!strcmp(argv[i], "-1"))
	    mode = XrmEnumOneLevel;
	else if (!strcmp(argv[i], "-V")) {
	    printf("%s\n", PACKAGE_STRING);
	    exit(0);
	}
	else if (argv[i][0] == '-')
	    usage();
	else if (!cname)
	    cname = argv[i];
	else if (!iname)
	    iname = argv[i];
	else
	    usage();
    }

    if (!iname) {
	XtGetApplicationNameAndClass(XtDisplay(toplevel), &iname, &cname);
	names[0] = XrmStringToName(iname);
    }

    XrmQString = XrmPermStringToQuark("String");

    XrmEnumerateDatabase(XtDatabase(XtDisplay(toplevel)),
			 names, classes, mode,
			 DumpEntry, (XPointer)stdout);

    return (0);
}
Esempio n. 3
0
static XrmDatabase CopyDB(XrmDatabase db)
{
    XrmDatabase copy = NULL;
    XrmQuark empty = NULLQUARK;

    XrmEnumerateDatabase(db, &empty, &empty, XrmEnumAllLevels,
			 StoreDBEntry, (XPointer)&copy);
    return copy;
}
Esempio n. 4
0
Bool
InitializeOptionsDatabase(void)
{
    static int first = 1;
    static Bool result = True;

    if (first) {
	XrmQuark names[2];
	XrmQuark classes[2];

	first = 0;
	XrmInitialize();
	if ((options_xrm = XrmGetFileDatabase(Options)) == (XrmDatabase)0) {
	    fprintf(stderr, "Cannot open '%s' database.\n", Options);
	    return (False);
	}

	/* rebuild database, using only lowercase characters */
	names[0] = classes[0] = names[1] = classes[1] = NULLQUARK;
	(void)XrmEnumerateDatabase(options_xrm, (XrmNameList)&names,
				   (XrmClassList)&classes, XrmEnumAllLevels,
				   EnumDatabase, NULL);

	/* free previous database, as it is not guaranteed to be
         * "case insensitive" */
	XrmDestroyDatabase(options_xrm);

	/* create case insensitive database by making everything lowercase */
	if (rebuild_xrm.string == NULL ||
	    (options_xrm = XrmGetStringDatabase(rebuild_xrm.string)) ==
	    (XrmDatabase)0) {
	    fprintf(stderr, "Cannot rebuild '%s' database.\n", Options);
	    XtFree(rebuild_xrm.string);
	    return (False);
	}
	XtFree(rebuild_xrm.string);
    }

    return (result);
}
Esempio n. 5
0
File: SmDB.c Progetto: juddy/edcde
ClientDB
OpenInputClientDB(char *fileName,
		  char **version,
		  char **dtsessionID)
{
    ClientDBRec *inputDB;
    char **tmpPtr;
    char *resourceType;
    XrmValue resourceValue;

    *version = (char *)NULL;
    *dtsessionID = (char *)NULL;

    _initXrm();

    if ((fileName == (char *)NULL) ||
	((inputDB = (ClientDBRec *)XtMalloc(sizeof(ClientDBRec)))
	 == (ClientDBRec *)NULL))
	return (ClientDB)NULL;

    if ((inputDB->xrmDB = XrmGetFileDatabase(fileName))
	== (XrmDatabase)NULL)
    {
	XtFree((char *)inputDB);
	return (ClientDB)NULL;
    }

    inputDB->openForInput = True;
    inputDB->XSMPClients = inputDB->proxyClients = (char **)NULL;
    inputDB->nXSMPClients = inputDB->nProxyClients = 0;
    inputDB->nextXSMPClientIndex = inputDB->nextProxyClientIndex = 0;

    /* Count the number of XSMP and Proxy clients. */
    XrmEnumerateDatabase(inputDB->xrmDB, XSMPName, XSMPClass,
			 XrmEnumOneLevel, _countProc,
			 (XPointer)&inputDB->nXSMPClients);
    XrmEnumerateDatabase(inputDB->xrmDB, proxyName, proxyClass,
			 XrmEnumOneLevel, _countProc,
			 (XPointer)&inputDB->nProxyClients);

    /* Allocate space for the client IDs and fill from database. */
    if (inputDB->nXSMPClients > 0)
    {
	if ((inputDB->XSMPClients =
	     (char **)XtMalloc(inputDB->nXSMPClients * sizeof(char *)))
	    == (char **)NULL)
	{
	    XrmDestroyDatabase(inputDB->xrmDB);
	    XtFree((char *)inputDB);
	    return (ClientDB)NULL;
	}

	tmpPtr = inputDB->XSMPClients;
	XrmEnumerateDatabase(inputDB->xrmDB, XSMPName, XSMPClass,
			     XrmEnumOneLevel, _fillClientIDProc,
			     (XPointer)&tmpPtr);
    }
    if (inputDB->nProxyClients > 0)
    {
	if ((inputDB->proxyClients =
	     (char **)XtMalloc(inputDB->nProxyClients * sizeof(char *)))
	    == (char **)NULL)
	{
	    XrmDestroyDatabase(inputDB->xrmDB);
	    XtFree((char *)inputDB->XSMPClients);
	    XtFree((char *)inputDB);
	    return (ClientDB)NULL;
	}

	tmpPtr = inputDB->proxyClients;
	XrmEnumerateDatabase(inputDB->xrmDB, proxyName, proxyClass,
			     XrmEnumOneLevel, _fillClientIDProc,
			     (XPointer)&tmpPtr);
    }

    if ((!XrmGetResource(inputDB->xrmDB, versionStr, versionStr,
			 &resourceType, &resourceValue)) ||
	((*version = XtNewString(resourceValue.addr)) == (char *)NULL) ||
	(!XrmGetResource(inputDB->xrmDB, dtsessionIDStr, dtsessionIDStr,
			 &resourceType, &resourceValue)) ||
	((*dtsessionID = XtNewString(resourceValue.addr)) == (char *)NULL))
    {
	if (*version)
	{
	    XtFree(*version);
	    *version = (char *)NULL;
	}
	XrmDestroyDatabase(inputDB->xrmDB);
	XtFree((char *)inputDB->XSMPClients);
	XtFree((char *)inputDB->proxyClients);
	XtFree((char *)inputDB);
	return (ClientDB)NULL;
    }

    return (ClientDB)inputDB;
}
Esempio n. 6
0
Bool
LoaderInitializeOptions(void)
{
    static int first = 1;
    static char *modules = "lib/modules";
    volatile Bool options_ok = False;
    char *ptr, query[256];
    char *ptr2, query2[256];
    char *type;
    XrmValue value;
    XrmQuark names[2];
    XrmQuark classes[2];
    volatile int i;
    static ModuleType module_types[] = {
	GenericModule, FontRendererModule, InputModule, VideoModule, NullModule
    };

    /* The offset in this vector must match loader.h:enum ModuleType values */
    static char *module_strs[] = {
	"Null Module", "Video Module", "Input Module", "Generic Module", "Font Module"
    };

    if (first) {
	checkerLegend = (char**)
	    XtCalloc(1, sizeof(char*) * (CHECKER_LAST_MESSAGE + 1));
	checkerErrors = (int*)
	    XtCalloc(1, sizeof(int) * (CHECKER_LAST_MESSAGE + 1));
	xf86cfgLoaderInit();
	first = 0;

	checkerLegend[CHECKER_OPTIONS_FILE_MISSING] =
	"The Options file, normally /usr/X11R6/lib/X11/Options was not found.\n";
	checkerLegend[CHECKER_OPTION_DESCRIPTION_MISSING] =
	"No description for the module option. The description should be in\n"
	"in the Options file, and using the sintax:\n"
	"Module.Option:	any text describing the option";
	checkerLegend[CHECKER_LOAD_FAILED] =
	"Failed to load the module. Usually the loader will print a complete\n"
	"description for the reason the module was not loaded. Use the -verbose\n"
	"command line option if it is not printing any messages.";
	checkerLegend[CHECKER_RECOGNIZED_AS] =
	"This message means the module code did not follow what was expected\n"
	"by the checker. For video drivers, it did not call xf86AddDriver,\n"
	"a input module did not call xf86AddInputDriver and a font renderer\n"
	"module did not call LoadFont. This message can also be printed if\n"
	"the module is in the incorrect directory.";
	checkerLegend[CHECKER_NO_OPTIONS_AVAILABLE] =
	"The driver does not have an AvailableOptions function, or that\n"
	"function is returning NULL. If the driver is returning NULL, and\n"
	"really does not need any options from "__XCONFIGFILE__", than the message\n"
	"can be ignored.";
	checkerLegend[CHECKER_NO_VENDOR_CHIPSET] =
	"The checker could not fetch the PCI chipset/vendor information from\n"
	"the module. The checker currently wraps xf86PrintChipsets and\n"
	"xf86MatchPciInstances to read the information from the module.";
	checkerLegend[CHECKER_CANNOT_VERIFY_CHIPSET] =
	"The vendor id was not found, so it is not possible to search the list\n"
	"of chipsets.";
	checkerLegend[CHECKER_OPTION_UNUSED] =
	"The option description is defined in the Options file, but the option\n"
	"was name not retrieved when calling the module AvailableOptions.";
	checkerLegend[CHECKER_NOMATCH_CHIPSET_STRINGS] =
	"The string specified in the module does not match the one in\n"
	"common/xf86PciInfo.h";
	checkerLegend[CHECKER_CHIPSET_NOT_LISTED] =
	"This means that common/xf86PciInfo.h does not have an entry for the\n"
	"given vendor and id.";
	checkerLegend[CHECKER_CHIPSET_NOT_SUPPORTED] =
	"The chipset is listed in common/xf86PciInfo.h, but the driver does\n"
	"not support it, or does not list it in the chipsets fetched by the checker.";
	checkerLegend[CHECKER_CHIPSET_NO_VENDOR] =
	"The vendor id specified to xf86MatchPciInstances is not defined in\n"
	"common/xf86PciInfo.h";
	checkerLegend[CHECKER_NO_CHIPSETS] =
	"No chipsets were passed to xf86MatchPciIntances.";
	checkerLegend[CHECKER_FILE_MODULE_NAME_MISMATCH] =
	"The module name string does not match the the modname field of the\n"
	"XF86ModuleVersionInfo structure. This generally is not an error, but\n"
	"to may be a good idea to use the same string to avoid confusion.";
    }

    if (XF86Module_path == NULL) {
	XF86Module_path = malloc(strlen(XFree86Dir) + strlen(modules) + 2);
	sprintf(XF86Module_path, "%s/%s", XFree86Dir, modules);
    }

    if (loaderPath == NULL || strcmp(XF86Module_path, loaderPath))
	loaderPath = strdup(XF86Module_path);
    else
	/* nothing new */
	return (True);

    if (!noverify) {
	options_ok = InitializeOptionsDatabase();
	InitializePciInfo();
    }

    for (i = 0; module_types[i] != NullModule; i++) {
	xf86cfgLoaderInitList(module_types[i]);
	if (!noverify)
	    ErrorF("================= Checking modules of type \"%s\" =================\n",
		   module_strs[module_types[i]]);

	if (loaderList) {
	    for (ploaderList = loaderList; *ploaderList; ploaderList++) {
		signal_caught = 0;
		signal(SIGTRAP, sig_handler);
		signal(SIGBUS, sig_handler);
		signal(SIGSEGV, sig_handler);
		signal(SIGILL, sig_handler);
		signal(SIGFPE, sig_handler);
		if (sigsetjmp(jmp, 1) == 0) {
		    if (!noverify) {
			int ok, nfont_modules;

			nfont_modules = numFontModules;
			error_level = 0;
			ErrorF("CHECK MODULE %s\n", *ploaderList);
			if ((ok = xf86cfgCheckModule()) == 0) {
			    CheckMsg(CHECKER_LOAD_FAILED,
				     "ERROR Failed to load module.\n");
			    error_level += 50;
			}
			else if (module_type != module_types[i]) {
			    CheckMsg(CHECKER_RECOGNIZED_AS,
				     "WARNING %s recognized as a \"%s\"\n", *ploaderList,
				     module_strs[module_type]);
			    ++error_level;
			}
			if (ok) {
			    if (options_ok) {
				if ((module_options == NULL || module_options->option == NULL) &&
				    module_type != GenericModule) {
				    CheckMsg(CHECKER_NO_OPTIONS_AVAILABLE,
					     "WARNING Not a generic module, but no options available.\n");
				    ++error_level;
				}
				else if (module_options && strcmp(module_options->name, *ploaderList) == 0) {
				    ErrorF("  CHECK OPTIONS\n");
				    option = module_options->option;

				    while (option->name) {
					XmuSnprintf(query, sizeof(query), "%s.%s", *ploaderList, option->name);
					for (ptr = query, ptr2 = query2; *ptr; ptr++) {
					    if (*ptr != '_' && *ptr != ' ' && *ptr != '\t')
						*ptr2 = tolower(*ptr);
					}
					*ptr2 = '\0';
					/* all resources are in lowercase */
					if (!XrmGetResource(options_xrm, query2, "Module.Option", &type, &value) ||
					    value.addr == NULL) {
					    CheckMsg(CHECKER_OPTION_DESCRIPTION_MISSING,
						     "WARNING no description for %s\n", query);
					    ++error_level;
					}
					++option;
				    }

				    /* now do a linear search for Options file entries that are not
				     * in the driver.
				     */
				    names[0] = XrmPermStringToQuark(module_options->name);
				    classes[0] = XrmPermStringToQuark("Option");
				    names[1] = classes[1] = NULLQUARK;
				    (void)XrmEnumerateDatabase(options_xrm, (XrmNameList)&names, (XrmClassList)&classes,
							       XrmEnumOneLevel, EnumDatabase, NULL);
				}
			    }
			    else {
				CheckMsg(CHECKER_OPTIONS_FILE_MISSING,
					 "ERROR Options file missing.\n");
				error_level += 10;
			    }

			    if (module_type == VideoModule &&
				(module_options == NULL || module_options->vendor < 0 ||
				 module_options->chipsets == NULL)) {
				CheckMsg(CHECKER_NO_VENDOR_CHIPSET,
				         "WARNING No vendor/chipset information available.\n");
				++error_level;
			    }
			    else if (module_type == VideoModule) {
				if (module_options == NULL) {
				    /* No description for this, if this happen,
				     * something really strange happened. */
				    ErrorF("  ERROR No module_options!?!\n");
				    error_level += 50;
				}
				else {
				    ErrorF("  CHECK CHIPSETS\n");
				    CheckChipsets(module_options, &error_level);
				}
			    }

			    /* font modules check */
			    if (module_type == FontRendererModule) {
				if (strcmp(*ploaderList, font_module->name)) {
				    /* not an error */
				    ErrorF("  NOTICE FontModule->name specification mismatch: \"%s\" \"%s\"\n",
					   *ploaderList, font_module->name);
				}
				if (nfont_modules + 1 != numFontModules) {
				    /* not an error */
				    ErrorF("  NOTICE font module \"%s\" loaded more than one font renderer.\n",
					   *ploaderList);
				}
			    }
			    else if (nfont_modules != numFontModules) {
				ErrorF("  WARNING number of font modules changed from %d to %d.\n",
				       nfont_modules, numFontModules);
				++error_level;
			    }
			}
			ErrorF("  SUMMARY error_level set to %d.\n\n", error_level);
		    }
		    else
			(void)xf86cfgCheckModule();
		}
		signal(SIGTRAP, SIG_DFL);
		signal(SIGBUS, SIG_DFL);
		signal(SIGSEGV, SIG_DFL);
		signal(SIGILL, SIG_DFL);
		signal(SIGFPE, SIG_DFL);
	    }
	    xf86cfgLoaderFreeList();
	}
	else
	    ErrorF("  ERROR Failed to initialize module list.\n");
    }

    if (!noverify) {
	ErrorF("===================================== LEGEND ===============================\n");
	ErrorF("NOTICE lines are just informative.\n");
	ErrorF("WARNING lines add 1 to error_level.\n");
	ErrorF("ERROR lines add 2 or more (based on the severity of the error) to error_level.\n\n");
	for (i = 0; i <= CHECKER_LAST_MESSAGE; i++)
	    if (checkerErrors[i]) {
		ErrorF("%3d\n%s\n\n", i, checkerLegend[i]);
	    }
    }

    return (True);
}