]> git.deb.at Git - pkg/abook.git/commitdiff
Store rcfile and addressbook to .abook directory
authorJaakko Heinonen <jheinonen@users.sourceforge.net>
Fri, 8 Feb 2002 11:30:48 +0000 (11:30 +0000)
committerJaakko Heinonen <jheinonen@users.sourceforge.net>
Fri, 8 Feb 2002 11:30:48 +0000 (11:30 +0000)
ChangeLog
abook.c
abook.h
options.c
options.h

index 0e188aadcaa2f77cb2a3f191027a810c0734250e..a71b6ef1919832d97471a8574ecd99acafd2dab3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
  - abook can be compiled with g++
  - attempt to improve --datafile behavior
  - html filter update (Morten Brix Pedersen)
+ - store rcfile and addressbook to .abook directory
 
 2002-02-04
  - use getopt to parse command line (also new options added)
diff --git a/abook.c b/abook.c
index 45eb83d54bc28abf0aadb95f97b66e4ec1de168d..acf95ca871c68578f4ef76c766060525c2f090bc 100644 (file)
--- a/abook.c
+++ b/abook.c
@@ -12,6 +12,7 @@
 #include <sys/stat.h>
 #include <signal.h>
 #include <fcntl.h>
+#include <errno.h>
 #ifdef HAVE_CONFIG_H
 #      include "config.h"
 #endif
@@ -62,10 +63,46 @@ datafile_writeable()
        return TRUE;
 }
 
+static void
+check_abook_directory()
+{
+       struct stat s;
+       char *dir;
+       
+       assert(!is_ui_initialized());
+
+       if(alternative_datafile)
+               return;
+
+       dir = strconcat(getenv("HOME"), "/" DIR_IN_HOME, NULL);
+       assert(dir != NULL);
+       
+       if(stat(dir, &s) == -1) {
+               if(errno != ENOENT) {
+                       perror(dir);
+                        free(dir);
+                        exit(1);
+               }
+               if(mkdir(dir, 0700) == -1) {
+                       printf("Cannot create directory %s\n", dir);
+                       perror(dir);
+                       free(dir);
+                       exit(1);
+               }
+       } else if(!S_ISDIR(s.st_mode)) {
+               printf("%s is not a directory\n", dir);
+               free(dir);
+               exit(1);
+       }
+
+       free(dir);
+}
+
 static void
 init_abook()
 {
        set_filenames();
+       check_abook_directory();
        init_options();
 
        signal(SIGKILL, quit_abook_sig);
@@ -85,7 +122,7 @@ init_abook()
                                        "If you continue all changes will "
                                "be lost. Do you want to continue?", FALSE)) {
                        close_config();
-                       close_database();
+                       /*close_database();*/
                        close_ui();
                        exit(1);
                }
@@ -154,10 +191,12 @@ set_filenames()
        }
 
        if(!datafile)
-               datafile = strconcat(getenv("HOME"), "/" DATAFILE, NULL);
+               datafile = strconcat(getenv("HOME"), "/" DIR_IN_HOME "/"
+                               DATAFILE, NULL);
 
        if(!rcfile)
-               rcfile = strconcat(getenv("HOME"), "/" RCFILE, NULL);
+               rcfile = strconcat(getenv("HOME"), "/" DIR_IN_HOME "/"
+                               RCFILE, NULL);
 
        atexit(free_filenames);
 }
diff --git a/abook.h b/abook.h
index 8fa08cd5f20d1059d9f2db1d8dc699c8b54d2b5b..1ca99625352768579af944cbfde74fcadd96426c 100644 (file)
--- a/abook.h
+++ b/abook.h
@@ -23,7 +23,8 @@ int           strncasecmp (const char *, const char *, size_t);
 #define MIN_COLS       70      
 
 #define DEFAULT_UMASK  066
-#define DATAFILE       ".abook.addressbook"
+#define DIR_IN_HOME    ".abook.dev"
+#define DATAFILE       "addressbook.0"
 
 /*
  * some "abookwide" useful macros
index 2b0353f60d790c3d8cde7edafaf53da4e9f7bb9b..e1a554391b2d2a56313c833de2077ccdf24c4b74 100644 (file)
--- a/options.c
+++ b/options.c
@@ -80,15 +80,17 @@ init_options()
                default_options();
 }
 
+
+#if 1
+extern int alternative_rcfile;
+#endif
+
 void
 close_config()
 {
-       /*
-        * we don't save the configuration file since user can specify
-        * alternative configuration files
-        */
-#if 0
-       save_options();
+#if 1
+       if(!alternative_rcfile)
+               save_options();
 #endif
 
        conff_free_nodes(abook_config);
@@ -120,7 +122,7 @@ load_options()
        }
 }
 
-#if 0
+#if 1
 void
 save_options()
 {
index 7e3ee27b8a317ea287d3d98f1f5072309bb014c8..0dc7e1777796dea893f5c670e41bf0b21b06380c 100644 (file)
--- a/options.h
+++ b/options.h
@@ -1,7 +1,7 @@
 #ifndef _OPTIONS_H
 #define _OPTIONS_H
 
-#define RCFILE         ".abookrc"
+#define RCFILE         "abookrc.0"
 #define SYSWIDE_RCFILE "/etc/abookrc"
 
 #include "conff.h"