I was working in the WPrefs file. This is only a ligth patch. The idea is break this big function in three smaller, and reuse one of them.
I was thinking about WPrefs and src/Windowmaker.h and probably the should use the same WPreferences structure. Now WPrefs reads the information from the config file using a own function and WindowMaker do the same using other function. I will try to join that. WPrefs read the info and save it in a PropList WindowMaker reads and save it in a wPreferences structure. My idea is remove the proplists in WPrefs and make a "readConf" "writeConf" (random names) functions. The functions and the structure will be in the WindowMaker folder (src) and WPrefs will include it (#include ../src/xyz.h). Comments? kix >From 1edd5a8e4ff0fc4e8e731a4a33bcec88a27c1d5f Mon Sep 17 00:00:00 2001 From: Rodolfo García Peñas (kix) <[email protected]> Date: Tue, 14 Feb 2012 20:06:43 +0100 Subject: [PATCH] WPrefs: PropList load rewrited The load of the configuration PropLists are re-writed. Now uses a new common function for the load, and includes a lot of comments. --- WPrefs.app/WPrefs.c | 254 +++++++++++++++++++++++++++------------------------ 1 files changed, 134 insertions(+), 120 deletions(-) diff --git a/WPrefs.app/WPrefs.c b/WPrefs.app/WPrefs.c index 2b69b51..6d63b55 100644 --- a/WPrefs.app/WPrefs.c +++ b/WPrefs.app/WPrefs.c @@ -95,8 +95,11 @@ static char *WindowMakerDBPath = NULL; static Bool TIFFOK = False; #define INITIALIZED_PANEL (1<<0) +/* Prototyples */ +WMPropList *loadConfigurationProplist(WMScreen *scr, WMWindow *mainw, char *config_file); +static void loadConfigurations(WMScreen *scr, WMWindow * mainw); +char *get_global_filename(WMScreen *scr, WMWindow *mainw); -static void loadConfigurations(WMScreen * scr, WMWindow * mainw); static void savePanelData(Panel * panel); @@ -638,125 +641,6 @@ WMWindow *GetWindow(Panel * panel) return WPrefs.win; } -static void loadConfigurations(WMScreen * scr, WMWindow * mainw) -{ - WMPropList *db, *gdb; - char *path; - FILE *file; - char buffer[1024]; - char mbuf[1024]; - int v1, v2, v3; - - path = wdefaultspathfordomain("WindowMaker"); - WindowMakerDBPath = path; - - db = WMReadPropListFromFile(path); - if (db) { - if (!WMIsPLDictionary(db)) { - WMReleasePropList(db); - db = NULL; - sprintf(mbuf, _("Window Maker domain (%s) is corrupted!"), path); - WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL); - } - } else { - sprintf(mbuf, _("Could not load Window Maker domain (%s) from defaults database."), path); - WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL); - } - - path = getenv("WMAKER_BIN_NAME"); - if (!path) - path = "wmaker"; - { - char *command; - - command = wstrconcat(path, " --version"); - file = popen(command, "r"); - wfree(command); - } - if (!file || !fgets(buffer, 1023, file)) { - werror(_("could not extract version information from Window Maker")); - wfatal(_("Make sure wmaker is in your search path.")); - - WMRunAlertPanel(scr, mainw, _("Error"), - _ - ("Could not extract version from Window Maker. Make sure it is correctly installed and is in your PATH environment variable."), - _("OK"), NULL, NULL); - exit(1); - } - if (file) - pclose(file); - - if (sscanf(buffer, "Window Maker %i.%i.%i", &v1, &v2, &v3) != 3 - && sscanf(buffer, "WindowMaker %i.%i.%i", &v1, &v2, &v3) != 3) { - WMRunAlertPanel(scr, mainw, _("Error"), - _("Could not extract version from Window Maker. " - "Make sure it is correctly installed and the path " - "where it installed is in the PATH environment " - "variable."), _("OK"), NULL, NULL); - exit(1); - } - if (v1 == 0 && (v2 < 18 || v3 < 0)) { - sprintf(mbuf, _("WPrefs only supports Window Maker 0.18.0 or newer.\n" - "The version installed is %i.%i.%i\n"), v1, v2, v3); - WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL); - exit(1); - - } - if (v1 > 1 || (v1 == 1 && (v2 > 0))) { - sprintf(mbuf, - _ - ("Window Maker %i.%i.%i, which is installed in your system, is not fully supported by this version of WPrefs."), - v1, v2, v3); - WMRunAlertPanel(scr, mainw, _("Warning"), mbuf, _("OK"), NULL, NULL); - } - - { - char *command; - - command = wstrconcat(path, " --global_defaults_path"); - file = popen(command, "r"); - wfree(command); - } - if (!file || !fgets(buffer, 1023, file)) { - werror(_("could not run \"%s --global_defaults_path\"."), path); - exit(1); - } else { - char *ptr; - ptr = strchr(buffer, '\n'); - if (ptr) - *ptr = 0; - strcat(buffer, "/WindowMaker"); - } - - if (file) - pclose(file); - - gdb = WMReadPropListFromFile(buffer); - - if (gdb) { - if (!WMIsPLDictionary(gdb)) { - WMReleasePropList(gdb); - gdb = NULL; - sprintf(mbuf, _("Window Maker domain (%s) is corrupted!"), buffer); - WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL); - } - } else { - sprintf(mbuf, _("Could not load global Window Maker domain (%s)."), buffer); - WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL); - } - - if (!db) { - db = WMCreatePLDictionary(NULL, NULL); - } - if (!gdb) { - gdb = WMCreatePLDictionary(NULL, NULL); - } - - GlobalDB = gdb; - - WindowMakerDB = db; -} - WMPropList *GetObjectForKey(char *defaultName) { WMPropList *object = NULL; @@ -966,3 +850,131 @@ int GetSpeedForKey(char *defaultName) } return i; } + + +/* This function load the user and global configuration files */ +/* WMScreen and WMWindow are used to show warnings */ +static void loadConfigurations(WMScreen *scr, WMWindow *mainw) +{ + char *GlobalDBPath; + + /* Get the name of the user configuration file */ + WindowMakerDBPath = wdefaultspathfordomain("WindowMaker"); + + /* Load the global configuration */ + WindowMakerDB = loadConfigurationProplist(scr, mainw, WindowMakerDBPath); + + /* Get the name of the global configuration file */ + GlobalDBPath = get_global_filename(scr, mainw); + + /* Load the global configuration */ + GlobalDB = loadConfigurationProplist(scr, mainw, GlobalDBPath); + + if (GlobalDBPath) + wfree(GlobalDBPath); +} + +/* This function returns the PropList with the configuration file "config_file" */ +/* WMScreen and WMWindow are used to show warnings */ +WMPropList *loadConfigurationProplist(WMScreen *scr, WMWindow *mainw, char *config_file) +{ + WMPropList *db; + char mbuf[1024]; + + /* Read the data */ + db = WMReadPropListFromFile(config_file); + + /* Check if the file contains data and if the data is correct */ + if (db) { + if (!WMIsPLDictionary(db)) { + WMReleasePropList(db); + db = NULL; + sprintf(mbuf, _("Window Maker domain (%s) is corrupted!"), config_file); + WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL); + } + } + + /* If no configuration loaded, then create */ + if (!db) { + sprintf(mbuf, _("Couldn't load Window Maker domain (%s) from database."), config_file); + WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL); + db = WMCreatePLDictionary(NULL, NULL); + } + + return(db); +} + +/* This function returns the global configuration file name */ +/* WMScreen and WMWindow are used to show warnings */ +char *get_global_filename(WMScreen *scr, WMWindow *mainw) +{ + char *path, *command, *buffer; + FILE *file; + char mbuf[1024]; + int v1, v2, v3; + + path = getenv("WMAKER_BIN_NAME"); + if (!path) + path = "wmaker"; + + command = wstrconcat(path, " --version"); + file = popen(command, "r"); + wfree(command); + + buffer = wmalloc(1024); + + if (!file || !fgets(buffer, 1023, file)) { + werror(_("Could not extract version information from Window Maker")); + wfatal(_("Make sure wmaker is in your search path.")); + WMRunAlertPanel(scr, mainw, _("Error"), + _("Could not extract version from Window Maker. Make sure it is " + "correctly installed and is in your PATH environment variable."), + _("OK"), NULL, NULL); + exit(1); + } + + if (file) + pclose(file); + + if ((sscanf(buffer, "Window Maker %i.%i.%i", &v1, &v2, &v3) != 3) && + sscanf(buffer, "WindowMaker %i.%i.%i", &v1, &v2, &v3) != 3) { + WMRunAlertPanel(scr, mainw, _("Error"), + _("Could not extract version from Window Maker. Maker sure it is " + "correctly installed and is in your PATH environment variable."), + _("OK"), NULL, NULL); + exit(1); + } + + if (v1 == 0 && (v2 < 18 || v3 < 0)) { + sprintf(mbuf, _("WPrefs only supports Window Maker 0.18.0 or newer.\n" + "The version installed is %i.%i.%i\n"), v1, v2, v3); + WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL); + exit(1); + } + + if (v1 > 1 || (v1 == 1 && (v2 > 0))) { + sprintf(mbuf, _("Window Maker %i.%i.%i, which is installed in your system, " + "is not fully supported by this version of WPrefs."), v1, v2, v3); + WMRunAlertPanel(scr, mainw, _("Warning"), mbuf, _("OK"), NULL, NULL); + } + + command = wstrconcat(path, " --global_defaults_path"); + file = popen(command, "r"); + wfree(command); + + if (!file || !fgets(buffer, 1023, file)) { + werror(_("could not run \"%s --global_defaults_path\"."), path); + exit(1); + } else { + char *ptr; + ptr = strchr(buffer, '\n'); + if (ptr) + *ptr = 0; + strcat(buffer, "/WindowMaker"); + } + + if (file) + pclose(file); + + return(buffer); +} -- 1.7.8.3 -- To unsubscribe, send mail to [email protected].
