extfs dir in ~/.mc
Oskar Liljeblad
oskar at osk.mine.nu
Thu Dec 30 10:19:49 UTC 2004
Here's a small patch for extfs that allows the user to place
extfs.ini as well as extfs program files inside ~/.mc/extfs
as well as (mc_dir)/extfs. The idea is simple: look in
~/.mc/extfs first. If the file is found there, use it.
Otherwise look in (mc_dir)/extfs. See the attached patch.
The patch is against CVS as of today.
Regards,
Oskar Liljeblad (oskar at osk.mine.nu)
-------------- next part --------------
diff -u -p extfs.c.v0 extfs.c
--- extfs.c.v0 2004-12-29 08:32:41.000000000 +0100
+++ extfs.c 2004-12-30 11:16:06.087327304 +0100
@@ -210,6 +210,26 @@ static void extfs_free_archive (struct a
g_free (archive);
}
+static char *
+extfs_lookup_file(const char *name)
+{
+ char *dir;
+ char *file;
+ struct stat sb;
+
+ dir = concat_dir_and_file (home_dir, ".mc" PATH_SEP_STR "extfs" PATH_SEP_STR);
+ file = g_strconcat (dir, name, NULL);
+ g_free(dir);
+ if (stat(file, &sb) >= 0)
+ return file;
+ g_free(file);
+
+ dir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
+ file = g_strconcat (dir, name, NULL);
+ g_free(dir);
+ return file;
+}
+
static FILE *
extfs_open_archive (int fstype, const char *name, struct archive **pparc)
{
@@ -217,7 +237,7 @@ extfs_open_archive (int fstype, const ch
FILE *result;
mode_t mode;
char *cmd;
- char *mc_extfsdir;
+ char *mc_extfsfile;
struct stat mystat;
struct archive *current_archive;
struct entry *root_entry;
@@ -235,12 +255,11 @@ extfs_open_archive (int fstype, const ch
tmp = name_quote (name, 0);
}
- mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
- cmd =
- g_strconcat (mc_extfsdir, extfs_prefixes[fstype], " list ",
- local_name ? local_name : tmp, (char *) NULL);
+ mc_extfsfile = extfs_lookup_file(extfs_prefixes[fstype]);
+ cmd = g_strconcat (mc_extfsfile, " list ",
+ local_name ? local_name : tmp, (char *) NULL);
g_free (tmp);
- g_free (mc_extfsdir);
+ g_free (mc_extfsfile);
open_error_pipe ();
result = popen (cmd, "r");
g_free (cmd);
@@ -599,7 +618,7 @@ extfs_cmd (const char *extfs_cmd, struct
char *quoted_file;
char *quoted_localname;
char *archive_name;
- char *mc_extfsdir;
+ char *mc_extfsfile;
char *cmd;
int retval;
@@ -609,13 +628,13 @@ extfs_cmd (const char *extfs_cmd, struct
archive_name = name_quote (extfs_get_archive_name (archive), 0);
quoted_localname = name_quote (localname, 0);
- mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
- cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype],
+ mc_extfsfile = extfs_lookup_file(extfs_prefixes[archive->fstype]);
+ cmd = g_strconcat (mc_extfsfile,
extfs_cmd, archive_name, " ", quoted_file, " ",
quoted_localname, (char *) NULL);
g_free (quoted_file);
g_free (quoted_localname);
- g_free (mc_extfsdir);
+ g_free (mc_extfsfile);
g_free (archive_name);
open_error_pipe ();
@@ -629,7 +648,7 @@ static void
extfs_run (struct vfs_class *me, const char *file)
{
struct archive *archive;
- char *p, *q, *archive_name, *mc_extfsdir;
+ char *p, *q, *archive_name, *mc_extfsfile;
char *cmd;
if ((p = extfs_get_path (me, file, &archive, 0, 0)) == NULL)
@@ -638,10 +657,10 @@ extfs_run (struct vfs_class *me, const c
g_free (p);
archive_name = name_quote (extfs_get_archive_name (archive), 0);
- mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
- cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype],
+ mc_extfsfile = extfs_lookup_file(extfs_prefixes[archive->fstype]);
+ cmd = g_strconcat (mc_extfsfile,
" run ", archive_name, " ", q, (char *) NULL);
- g_free (mc_extfsdir);
+ g_free (mc_extfsfile);
g_free (archive_name);
g_free (q);
shell_execute (cmd, 0);
@@ -1275,7 +1294,7 @@ static int extfs_init (struct vfs_class
char *mc_extfsini;
char key[256];
- mc_extfsini = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR "extfs.ini");
+ mc_extfsini = extfs_lookup_file("extfs.ini");
cfg = fopen (mc_extfsini, "r");
/* We may not use vfs_die() message or message or similar,
More information about the mc-devel
mailing list