Пример #1
0
char *wfindfileinarray(WMPropList *array, const char *file)
{
	int i;
	char *path;
	int len, flen;
	char *fullpath;

	if (!file)
		return NULL;

	if (*file == '/' || *file == '~' || !array) {
		if (access(file, F_OK) < 0) {
			fullpath = wexpandpath(file);
			if (!fullpath)
				return NULL;

			if (access(fullpath, F_OK) < 0) {
				wfree(fullpath);
				return NULL;
			} else {
				return fullpath;
			}
		} else {
			return wstrdup(file);
		}
	}

	flen = strlen(file);
	for (i = 0; i < WMGetPropListItemCount(array); i++) {
		WMPropList *prop;
		char *p;

		prop = WMGetFromPLArray(array, i);
		if (!prop)
			continue;
		p = WMGetFromPLString(prop);

		len = strlen(p);
		path = wmalloc(len + flen + 2);
		path = memcpy(path, p, len);
		path[len] = 0;
		if (wstrlcat(path, "/", len + flen + 2) >= len + flen + 2 ||
		    wstrlcat(path, file, len + flen + 2) >= len + flen + 2) {
			wfree(path);
			return NULL;
		}
		/* expand tilde */
		fullpath = wexpandpath(path);
		wfree(path);
		if (fullpath) {
			/* check if file exists */
			if (access(fullpath, F_OK) == 0) {
				return fullpath;
			}
			wfree(fullpath);
		}
	}
	return NULL;
}
Пример #2
0
/*
 *----------------------------------------------------------------------
 * findfile--
 * 	Finds a file in a : separated list of paths. ~ expansion is also
 * done.
 *
 * Returns:
 * 	The complete path for the file (in a newly allocated string) or
 * NULL if the file was not found.
 *
 * Side effects:
 * 	A new string is allocated. It must be freed later.
 *
 *----------------------------------------------------------------------
 */
char*
wfindfile(char *paths, char *file)
{
    char *path;
    char *tmp, *tmp2;
    int len, flen;
    char *fullpath;

    if (!file)
        return NULL;

    if (*file=='/' || *file=='~' || *file=='$' || !paths || *paths==0) {
        if (access(file, F_OK)<0) {
            fullpath = wexpandpath(file);
            if (!fullpath)
                return NULL;

            if (access(fullpath, F_OK)<0) {
                wfree(fullpath);
                return NULL;
            } else {
                return fullpath;
            }
        } else {
            return wstrdup(file);
        }
    }

    flen = strlen(file);
    tmp = paths;
    while (*tmp) {
        tmp = skipchar(tmp, ':');
        if (*tmp==0)
            break;
        tmp2 = nextchar(tmp, ':');
        len = tmp2 - tmp;
        path = wmalloc(len+flen+2);
        path = memcpy(path, tmp, len);
        path[len]=0;
        if (path[len-1] != '/')
            strcat(path, "/");
        strcat(path, file);
        fullpath = wexpandpath(path);
        wfree(path);
        if (fullpath) {
            if (access(fullpath, F_OK)==0) {
                return fullpath;
            }
            wfree(fullpath);
        }
        tmp = tmp2;
    }

    return NULL;
}
Пример #3
0
char *wfindfileinlist(char *const *path_list, const char *file)
{
	int i;
	char *path;
	int len, flen;
	char *fullpath;

	if (!file)
		return NULL;

	if (*file == '/' || *file == '~' || !path_list) {
		if (access(file, F_OK) < 0) {
			fullpath = wexpandpath(file);
			if (!fullpath)
				return NULL;

			if (access(fullpath, F_OK) < 0) {
				wfree(fullpath);
				return NULL;
			} else {
				return fullpath;
			}
		} else {
			return wstrdup(file);
		}
	}

	flen = strlen(file);
	for (i = 0; path_list[i] != NULL; i++) {
		len = strlen(path_list[i]);
		path = wmalloc(len + flen + 2);
		path = memcpy(path, path_list[i], len);
		path[len] = 0;
		if (wstrlcat(path, "/", len + flen + 2) >= len + flen + 2 ||
		    wstrlcat(path, file, len + flen + 2) >= len + flen + 2) {
			wfree(path);
			return NULL;
		}
		/* expand tilde */
		fullpath = wexpandpath(path);
		wfree(path);
		if (fullpath) {
			/* check if file exists */
			if (access(fullpath, F_OK) == 0) {
				return fullpath;
			}
			wfree(fullpath);
		}
	}

	return NULL;
}
Пример #4
0
static void
addPathToList(WMList *list, int index, char *path)
{
    char *fpath = wexpandpath(path);
    WMListItem *item;

    item = WMInsertListItem(list, index, path);

    if (access(fpath, X_OK)!=0) {
        item->uflags = 1;
    }
    wfree(fpath);
}
Пример #5
0
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);
}