- 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)
#include <sys/stat.h>
#include <signal.h>
#include <fcntl.h>
+#include <errno.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
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);
"If you continue all changes will "
"be lost. Do you want to continue?", FALSE)) {
close_config();
- close_database();
+ /*close_database();*/
close_ui();
exit(1);
}
}
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);
}
#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
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);
}
}
-#if 0
+#if 1
void
save_options()
{