void ExecExitScript() { char *file, *paths; paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker"); paths = wstrappend(paths, ":"DEF_CONFIG_PATHS); file = wfindfile(paths, DEF_EXIT_SCRIPT); wfree(paths); if (file) { if (system(file) != 0) { wsyserror(_("%s:could not execute exit script"), file); } #if 0 if (fork()==0) { execl("/bin/sh", "/bin/sh", "-c", file, NULL); wsyserror(_("%s:could not execute exit script"), file); exit(1); } #endif wfree(file); } }
static WMPropList* getDefaultMenu(_Panel *panel) { WMPropList *menu; char *menuPath, *gspath; gspath = wusergnusteppath(); menuPath = wmalloc(strlen(gspath)+128); sprintf(menuPath, "%s/Library/WindowMaker/plmenu", gspath); menu = WMReadPropListFromFile(menuPath); if (!menu) { char *buffer, *msg; msg = _("Could not open default menu from '%s'"); buffer = wmalloc(strlen(msg) + strlen(menuPath) + 10); sprintf(buffer, msg, menuPath); WMRunAlertPanel(WMWidgetScreen(panel->parent), panel->parent, _("Error"), buffer, _("OK"), NULL, NULL); wfree(buffer); } wfree(menuPath); return menu; }
static void showData(_Panel *panel) { char *gspath; char *menuPath; WMPropList *pmenu; gspath = wusergnusteppath(); menuPath = wmalloc(strlen(gspath)+32); strcpy(menuPath, gspath); strcat(menuPath, "/Defaults/WMRootMenu"); pmenu = WMReadPropListFromFile(menuPath); 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; buildMenuFromPL(panel, pmenu); WMReleasePropList(pmenu); }
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); }
static void storeCommandInScript(const char *cmd, const char *line) { char *path; FILE *f; char buffer[128]; mode_t permissions; /* Calculate permission to be Executable but taking into account user's umask */ permissions = umask(0); umask(permissions); permissions = (S_IRWXU | S_IRWXG | S_IRWXO) & (~permissions); path = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart"); f = fopen(path, "rb"); if (!f) { f = fopen(path, "wb"); if (!f) { werror(_("could not create %s"), path); goto end; } fprintf(f, "#!/bin/sh\n"); fputs(line, f); fputs("\n", f); } else { int len = strlen(cmd); int ok = 0; char *tmppath; FILE *fo; tmppath = wstrconcat(wusergnusteppath(), "/Library/WindowMaker/autostart.tmp"); fo = fopen(tmppath, "wb"); if (!fo) { werror(_("could not create temporary file %s"), tmppath); wfree(tmppath); goto end; } while (!feof(f)) { if (!fgets(buffer, 127, f)) { break; } if (buffer[0] == '\n') { /* don't write empty lines, else the file will grow * indefinitely (one '\n' added at end of file on each save). */ continue; } if (strncmp(buffer, cmd, len) == 0) { if (!ok) { fputs(line, fo); fputs("\n", fo); ok = 1; } } else { fputs(buffer, fo); } } if (!ok) { fputs(line, fo); fputs("\n", fo); } fsync(fileno(fo)); fclose(fo); if (rename(tmppath, path) != 0) { werror(_("could not rename file %s to %s"), tmppath, path); } wfree(tmppath); } if (chmod(path, permissions) != 0) wwarning(_("could not set permission 0%03o on file \"%s\""), permissions, path); end: wfree(path); if (f) { fsync(fileno(f)); /* this may be rw */ fclose(f); } }
static void makeThemePack(WMPropList * style, const char *themeName) { WMPropList *keys; WMPropList *key; WMPropList *value; int i; size_t themeNameLen; char *themeDir; const char *user_base; user_base = wusergnusteppath(); if (user_base == NULL) return; themeNameLen = strlen(user_base) + sizeof(THEME_SUBPATH) + strlen(themeName) + sizeof(THEME_EXTDIR) + 1; themeDir = wmalloc(themeNameLen); snprintf(themeDir, themeNameLen, "%s" THEME_SUBPATH "%s" THEME_EXTDIR, user_base, themeName); ThemePath = themeDir; if (!wmkdirhier(themeDir)) { wwarning("Could not make theme dir %s\n", themeDir); return; } keys = WMGetPLDictionaryKeys(style); for (i = 0; i < WMGetPropListItemCount(keys); i++) { key = WMGetFromPLArray(keys, i); value = WMGetFromPLDictionary(style, key); if (value && WMIsPLArray(value) && WMGetPropListItemCount(value) > 2) { WMPropList *type; char *t; type = WMGetFromPLArray(value, 0); t = WMGetFromPLString(type); if (t == NULL) continue; if (strcasecmp(t, "tpixmap") == 0 || strcasecmp(t, "spixmap") == 0 || strcasecmp(t, "cpixmap") == 0 || strcasecmp(t, "mpixmap") == 0 || strcasecmp(t, "tdgradient") == 0 || strcasecmp(t, "tvgradient") == 0 || strcasecmp(t, "thgradient") == 0) { WMPropList *file; char *p; char *newPath; file = WMGetFromPLArray(value, 1); p = strrchr(WMGetFromPLString(file), '/'); if (p) { newPath = wstrdup(p + 1); wcopy_file(themeDir, WMGetFromPLString(file), newPath); WMDeleteFromPLArray(value, 1); WMInsertInPLArray(value, 1, WMCreatePLString(newPath)); free(newPath); } else { findCopyFile(themeDir, WMGetFromPLString(file)); } } else if (strcasecmp(t, "bitmap") == 0) { WMPropList *file; char *p; char *newPath; file = WMGetFromPLArray(value, 1); p = strrchr(WMGetFromPLString(file), '/'); if (p) { newPath = wstrdup(p + 1); wcopy_file(themeDir, WMGetFromPLString(file), newPath); WMDeleteFromPLArray(value, 1); WMInsertInPLArray(value, 1, WMCreatePLString(newPath)); free(newPath); } else { findCopyFile(themeDir, WMGetFromPLString(file)); } file = WMGetFromPLArray(value, 2); p = strrchr(WMGetFromPLString(file), '/'); if (p) { newPath = wstrdup(p + 1); wcopy_file(themeDir, WMGetFromPLString(file), newPath); WMDeleteFromPLArray(value, 2); WMInsertInPLArray(value, 2, WMCreatePLString(newPath)); free(newPath); } else { findCopyFile(themeDir, WMGetFromPLString(file)); } } } } WMReleasePropList(keys); }