static int getBool(WMPropList *value) { char *val; if (!WMIsPLString(value)) return 0; if (!(val = WMGetFromPLString(value))) return 0; if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y' || val[0] == 'T' || val[0] == 't' || val[0] == '1')) || (strcasecmp(val, "YES") == 0 || strcasecmp(val, "TRUE") == 0)) { return 1; } else if ((val[1] == '\0' && (val[0] == 'n' || val[0] == 'N' || val[0] == 'F' || val[0] == 'f' || val[0] == '0')) || (strcasecmp(val, "NO") == 0 || strcasecmp(val, "FALSE") == 0)) { return 0; } else { wwarning(_("can't convert \"%s\" to boolean"), val); return 0; } }
/* * char *text; * WDMCheckPLString(pl, NULL, &text); */ Bool WDMCheckPLString(WMPropList * pl, void *def, void *target) { char **charptr_target = (char **)target; char *value = (char *)def; WDMDebug("WDMCheckPLString(%p, %p, %p)\n", (void *)pl, def, target); if (pl && WMIsPLString(pl)) { value = WMGetFromPLString(pl); } *charptr_target = value ? wstrdup(value) : value; return True; }
/* * This function will check if pl is string or array of strings. * It always returns WMArray. In case of string, new array will be * created and that string will be added to it. * def is ignored here. */ Bool WDMCheckPLStringOrArray(WMPropList * pl, void *def, void *target) { char *text; WMArray **array_target = (WMArray **) target; static WDMArraySpec array_of_strings = { WDMCheckPLString, NULL, wfree, False }; if (pl && WMIsPLString(pl)) { if (WDMCheckPLString(pl, NULL, &text) && text) { *array_target = WMCreateArrayWithDestructor(1, wfree); WMAddToArray(*array_target, text); return True; } } return WDMCheckPLArray(pl, &array_of_strings, target); }
static Bool WDMCheckPLUInteger(WMPropList *pl, void *def, void *target) { unsigned int *int_target = (unsigned int *)target; unsigned int int_def = (unsigned int)def; char *text = NULL; char *endptr = NULL; WDMDebug("WDMCheckPLUInteger(%p, %p, %p)\n", (void*)pl, def, target); *int_target = int_def; if(pl && WMIsPLString(pl)) { text = WMGetFromPLString(pl); if(text != NULL) *int_target = strtoul(text, &endptr, 0); } return True; }
/* * Bool bool; * WDMCheckPLBool(pl, True, &bool); */ Bool WDMCheckPLBool(WMPropList * pl, void *def, void *target) { Bool *bool_target = (Bool *) target; char *text = NULL; WDMDebug("WDMCheckPLBool(%p, %p, %p)\n", (void *)pl, def, target); *bool_target = (Bool)(intptr_t) def; if (pl && WMIsPLString(pl)) { text = WMGetFromPLString(pl); if (!strcasecmp(text, "yes")) { *bool_target = True; } else if (!strcasecmp(text, "no")) { *bool_target = False; } } return True; }
void ParseWindowName(WMPropList *value, char **winstance, char **wclass, const char *where) { char *name; *winstance = *wclass = NULL; if (!WMIsPLString(value)) { wwarning(_("bad window name value in %s state info"), where); return; } name = WMGetFromPLString(value); if (!name || strlen(name) == 0) { wwarning(_("bad window name value in %s state info"), where); return; } UnescapeWM_CLASS(name, winstance, wclass); }
static void showData(_Panel * panel) { const char *gspath; char *menuPath, *labelText; char buf[1024]; WMPropList *pmenu; gspath = wusergnusteppath(); menuPath = wmalloc(strlen(gspath) + 32); strcpy(menuPath, gspath); strcat(menuPath, "/Defaults/WMRootMenu"); pmenu = WMReadPropListFromFile(menuPath); /* check if WMRootMenu references another file, and if so, if that file is in proplist format */ while (WMIsPLString(pmenu)) { char *path = NULL; path = wexpandpath(WMGetFromPLString(pmenu)); if (access(path, F_OK) < 0) path = wfindfile(DEF_CONFIG_PATHS, path); /* TODO: if needed, concatenate locale suffix to path. See getLocalizedMenuFile() in src/rootmenu.c. */ if (!path) break; if (access(path, W_OK) < 0) { snprintf(buf, 1024, _("The menu file \"%s\" referenced by " "WMRootMenu is read-only.\n" "You cannot use WPrefs to modify it."), path); WMRunAlertPanel(WMWidgetScreen(panel->parent), panel->parent, _("Warning"), buf, _("OK"), NULL, NULL); panel->dontSave = True; wfree(path); return; } pmenu = WMReadPropListFromFile(path); menuPath = path; } if (!pmenu || !WMIsPLArray(pmenu)) { int res; res = WMRunAlertPanel(WMWidgetScreen(panel->parent), panel->parent, _("Warning"), _("The menu file format currently in use is not supported\n" "by this tool. Do you want to discard the current menu\n" "to use this tool?"), _("Yes, Discard and Update"), _("No, Keep Current Menu"), NULL); if (res == WAPRDefault) { pmenu = getDefaultMenu(panel); if (!pmenu) { pmenu = WMCreatePLArray(WMCreatePLString("Applications"), NULL); } } else { panel->dontSave = True; return; } } panel->menuPath = menuPath; snprintf(buf, 1024, _("\n\nWhen saved, the menu will be written to the file\n\"%s\"."), menuPath); labelText = WMGetLabelText(panel->sections[NoInfo][0]); labelText = wstrconcat(labelText, buf); WMSetLabelText(panel->sections[NoInfo][0], labelText); wfree(labelText); buildMenuFromPL(panel, pmenu); WMReleasePropList(pmenu); }
int main(int argc, char **argv) { WMPropList *window_name, *icon_key, *window_attrs, *icon_value; WMPropList *all_windows, *iconset, *keylist; char *path; int i, ch; struct option longopts[] = { { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { NULL, 0, NULL, 0 } }; prog_name = argv[0]; while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) switch(ch) { case 'v': printf("%s (Window Maker %s)\n", prog_name, VERSION); return 0; /* NOTREACHED */ case 'h': print_help(1, 0); /* NOTREACHED */ case 0: break; default: print_help(0, 1); /* NOTREACHED */ } argc -= optind; argv += optind; path = wdefaultspathfordomain("WMWindowAttributes"); all_windows = WMReadPropListFromFile(path); if (!all_windows) { printf("%s: could not load WindowMaker configuration file \"%s\".\n", prog_name, path); return 1; } iconset = WMCreatePLDictionary(NULL, NULL); keylist = WMGetPLDictionaryKeys(all_windows); icon_key = WMCreatePLString("Icon"); for (i = 0; i < WMGetPropListItemCount(keylist); i++) { WMPropList *icondic; window_name = WMGetFromPLArray(keylist, i); if (!WMIsPLString(window_name)) continue; window_attrs = WMGetFromPLDictionary(all_windows, window_name); if (window_attrs && WMIsPLDictionary(window_attrs)) { icon_value = WMGetFromPLDictionary(window_attrs, icon_key); if (icon_value) { icondic = WMCreatePLDictionary(icon_key, icon_value, NULL); WMPutInPLDictionary(iconset, window_name, icondic); } } } if (argc == 1) { WMWritePropListToFile(iconset, argv[0]); } else { puts(WMGetPropListDescription(iconset, True)); } return 0; }
int main(int argc, char **argv) { WMPropList *window_name, *icon_key, *window_attrs, *icon_value; WMPropList *all_windows, *iconset, *keylist; int i; char *path = NULL; ProgName = argv[0]; if (argc < 2) { printf("%s: missing argument\n", ProgName); printf("Try '%s --help' for more information\n", ProgName); } for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-h")==0 || strcmp(argv[i], "--help")==0) { print_help(); exit(0); } else if (strcmp(argv[i], "--version")==0) { puts(PROG_VERSION); exit(0); } else { if (path) { printf("%s: invalid argument '%s'\n", ProgName, argv[i]); printf("Try '%s --help' for more information\n", ProgName); exit(1); } path = argv[i]; } } path = defaultsPathForDomain("WMWindowAttributes"); all_windows = WMReadPropListFromFile(path); if (!all_windows) { printf("%s:could not load WindowMaker configuration file \"%s\".\n", ProgName, path); exit(1); } iconset = WMReadPropListFromFile(argv[1]); if (!iconset) { printf("%s:could not load icon set file \"%s\".\n", ProgName, argv[1]); exit(1); } keylist = WMGetPLDictionaryKeys(iconset); icon_key = WMCreatePLString("Icon"); for (i=0; i<WMGetPropListItemCount(keylist); i++) { window_name = WMGetFromPLArray(keylist, i); if (!WMIsPLString(window_name)) continue; icon_value = WMGetFromPLDictionary(iconset, window_name); if (!icon_value || !WMIsPLDictionary(icon_value)) continue; window_attrs = WMGetFromPLDictionary(all_windows, window_name); if (window_attrs) { if (WMIsPLDictionary(window_attrs)) { WMMergePLDictionaries(window_attrs, icon_value, True); } } else { WMPutInPLDictionary(all_windows, window_name, icon_value); } } WMWritePropListToFile(all_windows, path, True); exit(0); }