From: Jaakko Heinonen Date: Fri, 8 Feb 2002 11:30:48 +0000 (+0000) Subject: Store rcfile and addressbook to .abook directory X-Git-Tag: upstream/0.6.1~2^2~300 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=ca9cda9e7096dad72f1335a810314001daca7314;p=pkg%2Fabook.git Store rcfile and addressbook to .abook directory --- diff --git a/ChangeLog b/ChangeLog index 0e188aa..a71b6ef 100644 --- 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 45eb83d..acf95ca 100644 --- a/abook.c +++ b/abook.c @@ -12,6 +12,7 @@ #include #include #include +#include #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 8fa08cd..1ca9962 100644 --- 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 diff --git a/options.c b/options.c index 2b0353f..e1a5543 100644 --- 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() { diff --git a/options.h b/options.h index 7e3ee27..0dc7e17 100644 --- 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"