예제 #1
0
/*---------------------------------------------------------------------------
 Next part is the implementaion of all functions 
---------------------------------------------------------------------------*/
XF86ConfigPtr ReadConfigFile (char *filename) {
	const char *file = NULL; 
	XF86ConfigPtr conf;

	char CONFPATH[SIZE]=
		"%A,%R,/etc/%R,%P/etc/X11/%R,%E,%F,/etc/X11/%F," \
		"%P/etc/X11/%F,%D/%X,/etc/X11/%X,/etc/%X,%P/etc/X11/%X.%H," \
		"%P/etc/X11/%X,%P/lib/X11/%X.%H,%P/lib/X11/%X";

	//===================================
	// X11 version 4.1 or higher...
	//-----------------------------------
	if (!(file = (char*)xf86openConfigFile (CONFPATH, filename, NULL))) {
		fprintf (stderr, "Unable to open config file\n");
		return(NULL);
	}

	if ((conf = (XF86ConfigPtr)xf86readConfigFile ()) == NULL) {
		fprintf (stderr, "Problem when parsing config file\n");
		xf86closeConfigFile ();
		return(NULL);
	}
	xf86closeConfigFile ();
	return(conf);
}
예제 #2
0
파일: cpconfig.c 프로젝트: narenas/nx-libs
int
main (int argc, char *argv[])
{
	const char *filename;
	char *cmdline = NULL;
	XF86ConfigPtr conf;

	if (argc > 1)
	{
		cmdline = argv[1];
	}
	if ((filename = xf86openConfigFile (CONFPATH, cmdline, NULL)))
	{
		fprintf (stderr, "Opened %s for the config file\n", filename);
	}
	else
	{
		fprintf (stderr, "Unable to open config file\n");
		exit (1);
	}

	if ((conf = xf86readConfigFile ()) == NULL)
	{
		fprintf (stderr, "Problem when parsing config file\n");
	}
	else
	{
		fprintf (stderr, "Config file parsed OK\n");
	}
	xf86closeConfigFile ();

	if (argc > 2) {
		fprintf(stderr, "Writing config file to `%s'\n", argv[2]);
		xf86writeConfigFile (argv[2], conf);
	}
	exit(0);
}
예제 #3
0
Bool
winReadConfigfile()
{
    Bool retval = TRUE;
    char *filename, *dirname;
    MessageType filefrom = X_DEFAULT;
    MessageType dirfrom = X_DEFAULT;
    char *xf86ConfigFile = NULL;
    char *xf86ConfigDir = NULL;

    if (g_cmdline.configFile) {
        filefrom = X_CMDLINE;
        xf86ConfigFile = g_cmdline.configFile;
    }
    if (g_cmdline.configDir) {
        dirfrom = X_CMDLINE;
        xf86ConfigDir = g_cmdline.configDir;
    }

    /* Parse config file into data structure */
    xf86initConfigFiles();
    dirname = xf86openConfigDirFiles(CONFIGDIRPATH, xf86ConfigDir, PROJECTROOT);
    filename = xf86openConfigFile(CONFIGPATH, xf86ConfigFile, PROJECTROOT);

    /* Hack for backward compatibility */
    if (!filename && from == X_DEFAULT)
        filename = xf86openConfigFile(CONFIGPATH, "XF86Config", PROJECTROOT);

    if (filename) {
        winDebug ("Using config file: \"%s\"\n", filename);
    }
    else {
        ErrorF ("Unable to locate/open config file");
        if (xf86ConfigFile)
            ErrorF(": \"%s\"", xf86ConfigFile);
        ErrorF("\n");
    }
    if (dirname) {
        winDebug("Using config directory: \"%s\"\n", dirname);
    }
    else {
        winDebug("Unable to locate/open config directory");
        if (xf86ConfigDir)
            ErrorF(": \"%s\"", xf86ConfigDir);
        ErrorF("\n");
    }
    if (!filename && !dirname) {
        return FALSE;
    }
    free(filename);
    free(dirname);
    if ((g_xf86configptr = xf86readConfigFile()) == NULL) {
        ErrorF ("Problem parsing the config file\n");
        return FALSE;
    }
    xf86closeConfigFile();

    LogPrintMarkers();

    /* set options from data structure */

    if (g_xf86configptr->conf_layout_lst == NULL ||
        g_cmdline.screenname != NULL) {
        if (g_cmdline.screenname == NULL) {
            winDebug ("No Layout section. Using the first Screen section.\n");
        }
        if (!configImpliedLayout(&g_winConfigLayout,
                                 g_xf86configptr->conf_screen_lst)) {
            ErrorF ("Unable to determine the screen layout\n");
            return FALSE;
        }
    }
    else {
        /* Check if layout is given in the config file */
        if (g_xf86configptr->conf_flags != NULL) {
            char *dfltlayout = NULL;
            void *optlist = g_xf86configptr->conf_flags->flg_option_lst;

            if (optlist && winFindOption(optlist, "defaultserverlayout"))
                dfltlayout =
                    winSetStrOption(optlist, "defaultserverlayout", NULL);

            if (!configLayout(&g_winConfigLayout,
                              g_xf86configptr->conf_layout_lst, dfltlayout)) {
                ErrorF ("Unable to determine the screen layout\n");
                return FALSE;
            }
        }
        else {
            if (!configLayout(&g_winConfigLayout,
                              g_xf86configptr->conf_layout_lst, NULL)) {
                ErrorF ("Unable to determine the screen layout\n");
                return FALSE;
            }
        }
    }

    /* setup special config files */
    winConfigFiles();
    return retval;
}