From 60f80115f386a0ddb8d2d66b3267e1b2fce62ffa Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Fri, 16 Apr 1999 22:02:09 +0000 Subject: [PATCH] 1999-04-16 Federico Mena Quintero * treestore.c (tree_store_save_to): Moved the functionality from tree_store_save() to here. (tree_store_save): Save the tree in the default location in an atomic fashion. (tree_store_load_from): Moved the functionality from tree_store_load() to here. (tree_store_load): Load the tree from the default location. * treestore.h (MC_TREE_TMP): Added a #define for the temporary name we'll use when saving the tree. Moved the #defines from tree.h over to here. * main.c (main): Use tree_store_load() and tree_store_save(). Removed the mc_tree_store_load/save() versions. * tree.c (load_tree): Use tree_store_load(). (save_tree): Use tree_store_save(). --- gnome/ChangeLog | 2 ++ gnome/gtkdtree.c | 2 +- src/ChangeLog | 20 ++++++++++++++ src/main.c | 28 +++---------------- src/main.h | 3 -- src/tree.c | 13 ++------- src/tree.h | 6 ---- src/treestore.c | 71 ++++++++++++++++++++++++++++++++++++++++++++---- src/treestore.h | 14 ++++++++-- 9 files changed, 106 insertions(+), 53 deletions(-) diff --git a/gnome/ChangeLog b/gnome/ChangeLog index 65dfc864a..8fd311d30 100644 --- a/gnome/ChangeLog +++ b/gnome/ChangeLog @@ -1,5 +1,7 @@ 1999-04-16 Federico Mena Quintero + * gtkdtree.c (gtk_dtree_save_tree): Use tree_store_save(). + * gscreen.c (panel_tree_check_auto_expand): Enabled auto-collapse functionality again. Made the code a simpler by using gtk_dtree_is_ancestor(). diff --git a/gnome/gtkdtree.c b/gnome/gtkdtree.c index 4a470226d..301bfdb78 100644 --- a/gnome/gtkdtree.c +++ b/gnome/gtkdtree.c @@ -701,7 +701,7 @@ static int gtk_dtree_save_tree (void) { dirty_tag = -1; - mc_tree_store_save (); + tree_store_save (); return FALSE; } diff --git a/src/ChangeLog b/src/ChangeLog index 444bd3052..781bcb130 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,23 @@ +1999-04-16 Federico Mena Quintero + + * treestore.c (tree_store_save_to): Moved the functionality from + tree_store_save() to here. + (tree_store_save): Save the tree in the default location in an + atomic fashion. + (tree_store_load_from): Moved the functionality from + tree_store_load() to here. + (tree_store_load): Load the tree from the default location. + + * treestore.h (MC_TREE_TMP): Added a #define for the temporary + name we'll use when saving the tree. Moved the #defines from + tree.h over to here. + + * main.c (main): Use tree_store_load() and tree_store_save(). + Removed the mc_tree_store_load/save() versions. + + * tree.c (load_tree): Use tree_store_load(). + (save_tree): Use tree_store_save(). + Fri Apr 16 07:51:42 1999 Norbert Warmuth * wtools.c (message): Use g_vsnprintf instead of vsprintf. diff --git a/src/main.c b/src/main.c index 76efb2a97..af4d7718a 100644 --- a/src/main.c +++ b/src/main.c @@ -2919,28 +2919,8 @@ compatibility_move_mc_files (void) } #endif -void -mc_tree_store_load (void) -{ - char *tree_file; - - tree_file = concat_dir_and_file (home_dir, MC_TREE); - tree_store_init (); - tree_store_load (tree_file); - g_free (tree_file); -} - -void -mc_tree_store_save (void) -{ - char *tree_file; - - tree_file = concat_dir_and_file (home_dir, MC_TREE); - tree_store_save (tree_file); - g_free (tree_file); -} - -int main (int argc, char *argv []) +int +main (int argc, char *argv []) { /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */ setlocale (LC_ALL, ""); @@ -2989,7 +2969,7 @@ int main (int argc, char *argv []) handle_args(argc, argv); - mc_tree_store_load (); + tree_store_load (); session_init (); probably_finish_program (); @@ -3125,7 +3105,7 @@ int main (int argc, char *argv []) do_nc (); /* Save the tree store */ - mc_tree_store_save (); + tree_store_save (); /* Virtual File System shutdown */ vfs_shut (); diff --git a/src/main.h b/src/main.h index f84bd5871..bd95c8191 100644 --- a/src/main.h +++ b/src/main.h @@ -25,9 +25,6 @@ enum { extern int quote; extern volatile int quit; -void mc_tree_store_load (void); -void mc_tree_store_save (void); - /* Execute functions: the base and the routines that use it */ void do_execute (const char *shell, const char *command, int internal_command); #define execute_internal(command,args) do_execute (command, args, 1) diff --git a/src/tree.c b/src/tree.c index 383a4aa5b..0912a2201 100644 --- a/src/tree.c +++ b/src/tree.c @@ -176,15 +176,9 @@ void tree_destroy (WTree *tree) /* Loads the .mc.tree file */ void load_tree (WTree *tree) { - char *filename; - int v; - - filename = concat_dir_and_file (home_dir, MC_TREE); - v = tree_store_load (filename); - g_free (filename); + tree_store_load (); tree->selected_ptr = tree->store->tree_first; - tree_chdir (tree, home_dir); } @@ -192,11 +186,8 @@ void load_tree (WTree *tree) void save_tree (WTree *tree) { int error; - char *filename; - filename = concat_dir_and_file (home_dir, MC_TREE); - error = tree_store_save (filename); - g_free (filename); + error = tree_store_save (); if (error){ fprintf (stderr, _("Can't open the %s file for writing:\n%s\n"), MC_TREE, diff --git a/src/tree.h b/src/tree.h index f028910ae..bc271b964 100644 --- a/src/tree.h +++ b/src/tree.h @@ -52,10 +52,4 @@ extern int xtree_mode; WTree *tree_new (int is_panel, int y, int x, int lines, int cols); extern WTree *the_tree; -#ifdef OS2_NT -# define MC_TREE "mcn.tre" -#else -# define MC_TREE ".mc/Tree" -#endif - #endif diff --git a/src/treestore.c b/src/treestore.c index b8e9c4a06..b1bad9867 100644 --- a/src/treestore.c +++ b/src/treestore.c @@ -195,8 +195,9 @@ decode (char *buffer) return res; } -int -tree_store_load (char *name) +/* Loads the tree store from the specified filename */ +static int +tree_store_load_from (char *name) { FILE *file; char buffer [MC_MAXPATHLEN + 20], oldname[MC_MAXPATHLEN]; @@ -204,7 +205,7 @@ tree_store_load (char *name) int len, common; int do_load; - g_return_val_if_fail (name != NULL, TRUE); + g_return_val_if_fail (name != NULL, FALSE); if (ts.loaded) return TRUE; @@ -292,6 +293,27 @@ tree_store_load (char *name) return TRUE; } +/** + * tree_store_load: + * @void: + * + * Loads the tree from the default location. + * + * Return value: TRUE if success, FALSE otherwise. + **/ +int +tree_store_load (void) +{ + char *name; + int retval; + + name = concat_dir_and_file (home_dir, MC_TREE); + retval = tree_store_load_from (name); + g_free (name); + + return retval; +} + static char * encode (char *string) { @@ -327,8 +349,9 @@ encode (char *string) return res; } -int -tree_store_save (char *name) +/* Saves the tree to the specified filename */ +static int +tree_store_save_to (char *name) { tree_entry *current; FILE *file; @@ -345,7 +368,8 @@ tree_store_save (char *name) if (vfs_file_is_local (current->name)){ /* Clear-text compression */ - if (current->prev && (common = str_common (current->prev->name, current->name)) > 2){ + if (current->prev + && (common = str_common (current->prev->name, current->name)) > 2){ char *encoded = encode (current->name + common); i = fprintf (file, "%d:%d %s\n", current->scanned, common, encoded); @@ -371,6 +395,41 @@ tree_store_save (char *name) return 0; } +/** + * tree_store_save: + * @void: + * + * Saves the tree to the default file in an atomic fashion. + * + * Return value: 0 if success, errno on error. + **/ +int +tree_store_save (void) +{ + char *tmp; + char *name; + int retval; + + tmp = concat_dir_and_file (home_dir, MC_TREE_TMP); + retval = tree_store_save_to (tmp); + + if (retval) { + g_free (tmp); + return retval; + } + + name = concat_dir_and_file (home_dir, MC_TREE); + retval = rename (tmp, name); + + g_free (tmp); + g_free (name); + + if (retval) + return errno; + else + return 0; +} + tree_entry * tree_store_add_entry (char *name) { diff --git a/src/treestore.h b/src/treestore.h index d05f7941d..b2d800167 100644 --- a/src/treestore.h +++ b/src/treestore.h @@ -1,6 +1,16 @@ #ifndef __TREE_STORE_H #define __TREE_STORE_H +/* Default filenames for the tree */ + +#ifdef OS2_NT +# define MC_TREE "mcn.tre" +# define MC_TREE_TMP "mcn.tr~" +#else +# define MC_TREE ".mc/Tree" +# define MC_TREE_TMP ".mc/Tree.tmp" +#endif + typedef struct tree_entry { char *name; /* The full path of directory */ int sublevel; /* Number of parent directories (slashes) */ @@ -35,8 +45,8 @@ typedef struct { extern void (*tree_store_dirty_notify)(int state); TreeStore *tree_store_init (void); -int tree_store_load (char *name); -int tree_store_save (char *name); +int tree_store_load (void); +int tree_store_save (void); tree_entry *tree_store_add_entry (char *name); void tree_store_remove_entry (char *name); void tree_store_destroy (void);