1999-04-16 Federico Mena Quintero <federico@nuclecu.unam.mx>

* 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().
This commit is contained in:
Miguel de Icaza 1999-04-16 22:02:09 +00:00
parent 1270687440
commit 60f80115f3
9 changed files with 106 additions and 53 deletions

View File

@ -1,5 +1,7 @@
1999-04-16 Federico Mena Quintero <federico@nuclecu.unam.mx>
* 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().

View File

@ -701,7 +701,7 @@ static int
gtk_dtree_save_tree (void)
{
dirty_tag = -1;
mc_tree_store_save ();
tree_store_save ();
return FALSE;
}

View File

@ -1,3 +1,23 @@
1999-04-16 Federico Mena Quintero <federico@nuclecu.unam.mx>
* 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 <nwarmuth@privat.circular.de>
* wtools.c (message): Use g_vsnprintf instead of vsprintf.

View File

@ -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 ();

View File

@ -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)

View File

@ -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,

View File

@ -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

View File

@ -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)
{

View File

@ -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);