Пример #1
0
static void
enter_dir (MsOle *ole)
{
	char *newpath, *ptr, *p;

	p = arg_data [arg_cur++];

	if (!p) {
		printf ("Takes a directory argument\n");
		return;
	}

	if (!g_strcasecmp (p, "..")) {
		guint lp;
		char **tmp;
		GString *newp = g_string_new ("");

		tmp = g_strsplit (cur_dir, "/", -1);
		lp  = 0;
		if (!tmp[lp])
			return;

		while (tmp[lp+1]) {
			g_string_sprintfa (newp, "%s/", tmp[lp]);
			lp++;
		}
		g_free (cur_dir);
		cur_dir = newp->str;
		g_string_free (newp, FALSE);
	} else {
		MsOleStat s;
		MsOleErr  result;

		ptr = get_regexp_name (p, cur_dir, ole);
		if (!ptr)
			return;

		newpath = g_strconcat (cur_dir, ptr, "/", NULL);

		result = ms_ole_stat (&s, ole, newpath, "");
		if (result == MS_OLE_ERR_EXIST) {
			printf ("Storage '%s' not found\n", ptr);
			g_free (newpath);
			return;
		}
		if (result != MS_OLE_ERR_OK) {
			g_warning ("internal error");
			g_free (newpath);
			return;
		}
		if (s.type == MsOleStreamT) {
			printf ("Trying to enter a stream. (%d)\n", s.type);
			g_free (newpath);
			return;
		}

		g_free (cur_dir);
		cur_dir = newpath;
	}
}
static void
do_cd (void)
{
	char *p;

	p = arg_data [arg_cur++];

	if (!p) {
		fprintf (vfserr, "Takes a directory argument\n");
		return;
	}

	if (!g_ascii_strcasecmp (p, "..")) {
		guint lp;
		char **tmp;
		GString *newp = g_string_new ("");
		const char *ptr = g_path_skip_root (cur_dir);

		g_string_append_len (newp, cur_dir, ptr - cur_dir);

		tmp = g_strsplit_set (ptr, DIR_SEPARATORS, -1);
		lp  = 0;
		if (!tmp [lp])
			return;

		while (tmp [lp + 1] && strlen (tmp [lp + 1]) > 0) {
			g_string_append_printf (newp, "%s" G_DIR_SEPARATOR_S, tmp [lp]);
			lp++;
		}
		cur_dir = newp->str;
		g_string_free (newp, FALSE);
	} else if (!g_ascii_strcasecmp (p, ".")) {
	} else {
		char *newpath;

		if (g_path_is_absolute (p)) {
			if (!G_IS_DIR_SEPARATOR (p [strlen (p) - 1]))
				newpath = g_strconcat (p, G_DIR_SEPARATOR_S, NULL);
			else
				newpath = g_strdup (p);
		} else {
			char *ptr;
			
			ptr = get_regexp_name (p, cur_dir, TRUE);
			if (!ptr) {
				fprintf (vfserr, "Can't find '%s'\n", p);
				return;
			}

			newpath = g_strconcat (cur_dir, ptr, G_DIR_SEPARATOR_S, NULL);
		}

		if (validate_path (newpath)) {
			cur_dir = newpath;
		} else
			fprintf (vfserr, "Invalid path %s\n", newpath);
	}
}
Пример #3
0
static MsOleErr
test_stream_open (MsOleStream ** const stream, MsOle *f,
		  const char *path, const char *fname, char mode)
{
	MsOleErr err;
	char    *name;

	name = get_regexp_name (fname, path, f);
	if (name) {
		err = ms_ole_stream_open (stream, f, path, name, mode);
		g_free (name);
	} else /* Fall back to original */
		err = ms_ole_stream_open (stream, f, fname, name, mode);

	return err;
}
static char *
get_fname (void)
{
	char *fname, *reg_name, *f;

	if (!arg_data [arg_cur])
		return NULL;
	
	reg_name = arg_data [arg_cur++];
	fname = get_regexp_name (reg_name, cur_dir, FALSE);

	if (!fname)
		fname = reg_name;
	
	if (g_path_is_absolute (fname))
		f = g_strdup (fname);
	else if (cur_dir)
		f = g_build_filename (cur_dir, fname, NULL);
	else
		f = g_strdup (fname);

	return f;
}