Bool
xf86AutoConfig(void)
{
    char *deviceList[20];
    char **p;
    const char **cp;
    char buf[1024];
    ConfigStatus ret;

    listPossibleVideoDrivers(deviceList, 20);

    for (p = deviceList; *p; p++) {
	snprintf(buf, sizeof(buf), BUILTIN_DEVICE_SECTION, *p, 0, *p);
	AppendToConfig(buf);
	snprintf(buf, sizeof(buf), BUILTIN_SCREEN_SECTION, *p, 0, *p, 0);
	AppendToConfig(buf);
    }

    AppendToConfig(BUILTIN_LAYOUT_SECTION_PRE);
    for (p = deviceList; *p; p++) {
	snprintf(buf, sizeof(buf), BUILTIN_LAYOUT_SCREEN_LINE, *p, 0);
	AppendToConfig(buf);
    }
    AppendToConfig(BUILTIN_LAYOUT_SECTION_POST);

    for (p = deviceList; *p; p++) {
	free(*p);
    }

    xf86MsgVerb(X_DEFAULT, 0,
		"Using default built-in configuration (%d lines)\n",
		builtinLines);

    xf86MsgVerb(X_DEFAULT, 3, "--- Start of built-in configuration ---\n");
    for (cp = builtinConfig; *cp; cp++)
	xf86ErrorFVerb(3, "\t%s", *cp);
    xf86MsgVerb(X_DEFAULT, 3, "--- End of built-in configuration ---\n");

    xf86initConfigFiles();
    xf86setBuiltinConfig(builtinConfig);
    ret = xf86HandleConfigFile(TRUE);
    FreeConfig();

    if (ret != CONFIG_OK)
	xf86Msg(X_ERROR, "Error parsing the built-in default configuration.\n");

    return ret == CONFIG_OK;
}
Exemplo n.º 2
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;
}