char *FindImage(const char *paths, const char *file) { char *tmp, *path = NULL; tmp = strrchr(file, ':'); if (tmp) { *tmp = 0; path = wfindfile(paths, file); *tmp = ':'; } if (!tmp || !path) path = wfindfile(paths, file); return path; }
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); } }
/* determine whether (first token of) given file is in $PATH */ Bool fileInPath(const char *file) { char *p, *t; static char *path = NULL; if (!file || !*file) return False; /* if it's an absolute path spec, don't override the user. * s/he might just know better. */ if (*file == '/') return True; /* if it has a directory separator at random places, * we might know better. */ p = strchr(file, '/'); if (p) return False; if (!path) { path = getenv("PATH"); if (!path) return False; } p = wstrdup(file); t = strpbrk(p, " \t"); if (t) *t = '\0'; t = wfindfile(path, p); wfree(p); if (t) { wfree(t); return True; } return False; }
/* pick a terminal emulator by finding the first existing entry of `terminals' * in $PATH. the returned pointer should be wfreed later. * if $WMMENU_TERMINAL exists in the environment, it's value overrides this * detection. */ char *find_terminal_emulator(void) { char *path, *t; int i; t = getenv("WMMENU_TERMINAL"); if (t) return wstrdup(t); path = getenv("PATH"); if (!path) return NULL; for (i = 0; i < wlengthof(terminals); i++) { t = wfindfile(path, terminals[i]); if (t) { wfree(t); return wstrdup(terminals[i]); } } return NULL; }
static RImage *loadImage(RContext * rc, const char *file) { char *path; RImage *image; if (access(file, F_OK) != 0) { path = wfindfile(PixmapPath, file); if (!path) { wwarning("%s:could not find image file used in texture", file); return NULL; } } else { path = wstrdup(file); } image = RLoadImage(rc, path, 0); if (!image) { wwarning("%s:could not load image file used in texture:%s", path, RMessageForError(RErrorCode)); } wfree(path); return image; }
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); }