[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
gEDA-cvs: gaf.git: branch: master updated (1.5.1-20081221-194-g3c0d85e)
The branch, master has been updated
via 3c0d85eae92d5764aa7dee2899c6a066c3470ee3 (commit)
via 7cc4a67795c9ee8dcb28edc6d71b895c5b4f1dc9 (commit)
from 985966c57e1d3f57b8e6407756ecc7a7150484fd (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
=========
Summary
=========
gattrib/src/gattrib.c | 8 +---
gattrib/src/x_window.c | 8 +---
gnetlist/src/gnetlist.c | 5 +--
gschem/src/g_rc.c | 17 ++----
gschem/src/gschem.c | 5 +--
gschem/src/gschem_dialog.c | 8 +--
gschem/src/x_menus.c | 12 ++---
gsymcheck/src/gsymcheck.c | 6 +--
libgeda/include/libgeda/prototype.h | 4 +-
libgeda/src/g_rc.c | 69 +++--------------------
libgeda/src/g_register.c | 4 +-
libgeda/src/libgeda.c | 6 --
libgeda/src/s_basic.c | 78 ++++++++++++++++++++++++++
libgeda/src/s_log.c | 103 +++++++++++++++++++++++++++++++----
utils/gschlas/gschlas.c | 5 +--
15 files changed, 202 insertions(+), 136 deletions(-)
=================
Commit Messages
=================
commit 3c0d85eae92d5764aa7dee2899c6a066c3470ee3
Author: Peter TB Brett <peter@xxxxxxxxxxxxx>
Date: Wed Jan 21 14:11:39 2009 +0000
Write logs to $HOME/.gEDA/logs/.
Rewrite s_log_init() to put log files in a centralised location. A
user application (e.g. gnetlist) provides a prefix, and log file is
opened at:
$HOME/.gEDA/logs/<prefix>-<YYYYmmdd>-<serial>.log [1]
The serial is found by the following procedure:
1. Read through the directory to find the highest existing <serial>.
2. Starting with that number, repeatedly attempt to open()
incrementing files with O_CREAT|O_EXCL flags to guarantee that a
new file is created.
3. If after LOG_OPEN_ATTEMPTS = 5 attempts a unique filename hasn't
been found, fail.
The logic *intentionally* does not fill in gaps in the sequence -- if
I delete logs, I still want a new log to appear at the end of the
list.
[1] The actual location is a subdirectory "logs" of the user config
directory, which may not be ~/.gEDA on all platforms.
:100644 100644 e5f6818... 3f29e7f... M gattrib/src/gattrib.c
:100644 100644 1f73dbb... ac4966b... M gnetlist/src/gnetlist.c
:100644 100644 1c3122a... af4511e... M gschem/src/gschem.c
:100644 100644 04b1ae3... c3cba93... M gsymcheck/src/gsymcheck.c
:100644 100644 fcc087c... 3412577... M libgeda/src/s_log.c
:100644 100644 a30de63... 085a328... M utils/gschlas/gschlas.c
commit 7cc4a67795c9ee8dcb28edc6d71b895c5b4f1dc9
Author: Peter TB Brett <peter@xxxxxxxxxxxxx>
Date: Wed Jan 21 14:10:41 2009 +0000
Refactor finding paths for config etc.
This is intended to provide a centralised place for determining the
paths more "smartly" in the future (e.g. for platforms with different
conventions on where config should go).
Only user-visible change should be that log messages when loading
config files no longer hardcode "~/.gEDA".
:100644 100644 235377c... 62173bf... M gattrib/src/x_window.c
:100644 100644 52f1ae5... 88ed0c2... M gschem/src/g_rc.c
:100644 100644 6d0583b... 4a4f788... M gschem/src/gschem_dialog.c
:100644 100644 bf40173... 926246c... M gschem/src/x_menus.c
:100644 100644 d1d2a8f... 7ed1b34... M libgeda/include/libgeda/prototype.h
:100644 100644 793ae31... f4fb565... M libgeda/src/g_rc.c
:100644 100644 c254765... 6865c01... M libgeda/src/g_register.c
:100644 100644 3031880... d00345b... M libgeda/src/libgeda.c
:100644 100644 1f25519... d56a3fc... M libgeda/src/s_basic.c
=========
Changes
=========
commit 3c0d85eae92d5764aa7dee2899c6a066c3470ee3
Author: Peter TB Brett <peter@xxxxxxxxxxxxx>
Date: Wed Jan 21 14:11:39 2009 +0000
Write logs to $HOME/.gEDA/logs/.
Rewrite s_log_init() to put log files in a centralised location. A
user application (e.g. gnetlist) provides a prefix, and log file is
opened at:
$HOME/.gEDA/logs/<prefix>-<YYYYmmdd>-<serial>.log [1]
The serial is found by the following procedure:
1. Read through the directory to find the highest existing <serial>.
2. Starting with that number, repeatedly attempt to open()
incrementing files with O_CREAT|O_EXCL flags to guarantee that a
new file is created.
3. If after LOG_OPEN_ATTEMPTS = 5 attempts a unique filename hasn't
been found, fail.
The logic *intentionally* does not fill in gaps in the sequence -- if
I delete logs, I still want a new log to appear at the end of the
list.
[1] The actual location is a subdirectory "logs" of the user config
directory, which may not be ~/.gEDA on all platforms.
diff --git a/gattrib/src/gattrib.c b/gattrib/src/gattrib.c
index e5f6818..3f29e7f 100644
--- a/gattrib/src/gattrib.c
+++ b/gattrib/src/gattrib.c
@@ -118,8 +118,6 @@ void gattrib_main(void *closure, int argc, char *argv[])
/* GtkWidget *main_window is a global */
int argv_index;
- gchar *cwd;
- gchar *logfile;
#ifdef HAVE_GTHREAD
/* Gattrib isn't threaded, but some of GTK's file chooser
@@ -142,11 +140,7 @@ void gattrib_main(void *closure, int argc, char *argv[])
/* ---------- create log file right away ---------- */
/* ---------- even if logging is enabled ---------- */
- cwd = g_get_current_dir();
- logfile = g_build_filename (cwd, "gattrib.log", NULL);
- s_log_init (logfile);
- g_free (logfile);
- g_free (cwd);
+ s_log_init ("gattrib");
s_log_message
("gEDA/gattrib version %s%s.%s\n", PREPEND_VERSION_STRING,
diff --git a/gnetlist/src/gnetlist.c b/gnetlist/src/gnetlist.c
index 1f73dbb..ac4966b 100644
--- a/gnetlist/src/gnetlist.c
+++ b/gnetlist/src/gnetlist.c
@@ -112,7 +112,6 @@ void main_prog(void *closure, int argc, char *argv[])
int argv_index;
char *cwd;
GSList *list_pnt;
- gchar *logfile;
gchar *str;
gchar *filename;
@@ -143,9 +142,7 @@ void main_prog(void *closure, int argc, char *argv[])
/* create log file right away */
/* even if logging is enabled */
- logfile = g_build_filename (cwd, "gnetlist.log", NULL);
- s_log_init (logfile);
- g_free (logfile);
+ s_log_init ("gnetlist");
s_log_message("gEDA/gnetlist version %s%s.%s\n", PREPEND_VERSION_STRING,
DOTTED_VERSION, DATE_VERSION);
diff --git a/gschem/src/gschem.c b/gschem/src/gschem.c
index 1c3122a..af4511e 100644
--- a/gschem/src/gschem.c
+++ b/gschem/src/gschem.c
@@ -178,11 +178,8 @@ void main_prog(void *closure, int argc, char *argv[])
load_newer_backup_func = x_fileselect_load_backup;
select_func = o_select_object;
- /*! \todo Probably the file name shuold be defined elsewhere */
/* create log file right away even if logging is enabled */
- filename = g_build_filename (cwd, "gschem.log", NULL);
- s_log_init (filename);
- g_free (filename);
+ s_log_init ("gschem");
s_log_message(
_("gEDA/gschem version %s%s.%s\n"), PREPEND_VERSION_STRING,
diff --git a/gsymcheck/src/gsymcheck.c b/gsymcheck/src/gsymcheck.c
index 04b1ae3..c3cba93 100644
--- a/gsymcheck/src/gsymcheck.c
+++ b/gsymcheck/src/gsymcheck.c
@@ -52,8 +52,6 @@ main_prog(void *closure, int argc, char *argv[])
int exit_status;
char *cwd;
- char *logfile;
-
TOPLEVEL *pr_current;
argv_index = parse_commandline(argc, argv);
@@ -63,10 +61,8 @@ main_prog(void *closure, int argc, char *argv[])
/* create log file right away */
/* even if logging is enabled */
- logfile = g_build_filename (cwd, "gsymcheck.log", NULL);
x_log_update_func = s_log_update;
- s_log_init (logfile);
- g_free (logfile);
+ s_log_init ("gsymcheck");
logging_dest=STDOUT_TTY;
if (!quiet_mode)
diff --git a/libgeda/src/s_log.c b/libgeda/src/s_log.c
index fcc087c..3412577 100644
--- a/libgeda/src/s_log.c
+++ b/libgeda/src/s_log.c
@@ -42,6 +42,8 @@
#include "libgeda_priv.h"
+#include <time.h>
+
#ifdef HAVE_LIBDMALLOC
#include <dmalloc.h>
#endif
@@ -57,6 +59,8 @@ int do_logging = TRUE;
#define PRINT_LOG_LEVELS (CATCH_LOG_LEVELS ^ \
(G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE))
+#define LOG_OPEN_ATTEMPTS 5
+
static void s_log_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
@@ -73,27 +77,102 @@ static guint log_handler_id;
*
* \param [in] filename Character string with file name to log to.
*/
-void s_log_init (const gchar *filename)
+void s_log_init (const gchar *prefix)
{
+ /* FIXME we assume that the prefix is in the filesystem encoding. */
+
+ time_t nowt;
+ struct tm *nowtm;
+ gchar *full_prefix = NULL;
+ size_t full_prefix_len = 0;
+ gchar *dir_path = NULL;
+ gchar *filename = NULL;
+ int s, i;
+ int last_exist_logn = 0;
+ GDir *logdir = NULL;
+
+ if (logfile_fd != -1) {
+ g_critical ("s_log_init: Log already initialised.\n");
+ return;
+ }
if (do_logging == FALSE) {
- logfile_fd = -1;
return;
}
- /* create log file */
- logfile_fd = open (filename, O_RDWR|O_CREAT|O_TRUNC, 0600);
- if (logfile_fd == -1) {
- fprintf(stderr, "Could not open log file: %s\n", filename);
- fprintf(stderr, "Errno was: %d\n", errno);
+ time (&nowt);
+ nowtm = gmtime (&nowt);
+
+ /* create "real" prefix -- this has the form "<prefix>-<date>-" */
+ full_prefix = g_strdup_printf ("%s-%04i%02i%02i-", prefix,
+ nowtm->tm_year + 1900, nowtm->tm_mon + 1,
+ nowtm->tm_mday);
+ full_prefix_len = strlen (full_prefix);
+
+ /* Find/create the directory where we're going to put the logs.
+ * FIXME should this be configured somehow?
+ *
+ * Then run through it finding the "biggest" existing filename with
+ * a matching prefix & date. */
+ dir_path = g_build_filename (s_path_user_config (), "logs", NULL);
+ /* Try to create the directory. */
+ s = g_mkdir_with_parents (dir_path, 0777/*octal*/);
+ if (s != 0) {
+ /* It's okay to use the logging functions from here, because
+ * there's already a default handler. */
+ g_warning ("Could not create log directory %s: %s\n",
+ dir_path, strerror (errno));
+ g_free (dir_path);
+ g_free (full_prefix);
return;
}
- /* install the log handler */
- log_handler_id = g_log_set_handler (NULL,
- CATCH_LOG_LEVELS,
- s_log_handler,
- NULL);
+ logdir = g_dir_open (dir_path, 0, NULL);
+ while (TRUE) {
+ const gchar *file = g_dir_read_name (logdir);
+ int n;
+ if (file == NULL) break;
+ if (strncmp (full_prefix, file, full_prefix_len)) continue;
+
+ s = sscanf (file + full_prefix_len, "%i", &n);
+ if (s != 1) continue;
+
+ if (n > last_exist_logn) last_exist_logn = n;
+ }
+
+ /* Now try and create a new file. When we fail, increment the number. */
+ i = 0;
+ while (logfile_fd == -1 && (LOG_OPEN_ATTEMPTS > i++)) {
+ filename = g_strdup_printf ("%s%s%s%i.log", dir_path,
+ G_DIR_SEPARATOR_S, full_prefix,
+ ++last_exist_logn);
+ logfile_fd = open (filename, O_RDWR|O_CREAT|O_EXCL, 0600);
+
+ if (logfile_fd == -1 && (errno != EEXIST)) break;
+ }
+
+ if (logfile_fd != -1) {
+
+ /* install the log handler */
+ log_handler_id = g_log_set_handler (NULL,
+ CATCH_LOG_LEVELS,
+ s_log_handler,
+ NULL);
+
+ } else {
+ /* It's okay to use the logging functions from here, because
+ * there's already a default handler. */
+ if (errno == EEXIST) {
+ g_warning ("Could not create unique log filename in %s\n",
+ dir_path);
+ } else {
+ g_warning ("Could not create log file in %s: %s\n",
+ dir_path, strerror (errno));
+ }
+ }
+ g_free (filename);
+ g_free (dir_path);
+ g_free (full_prefix);
}
/*! \brief Terminates the logging of messages.
diff --git a/utils/gschlas/gschlas.c b/utils/gschlas/gschlas.c
index a30de63..085a328 100644
--- a/utils/gschlas/gschlas.c
+++ b/utils/gschlas/gschlas.c
@@ -53,7 +53,6 @@ main_prog(void *closure, int argc, char *argv[])
int i;
int argv_index;
char *cwd;
- char *logfile;
TOPLEVEL *pr_current;
@@ -68,9 +67,7 @@ main_prog(void *closure, int argc, char *argv[])
/* create log file right away */
/* even if logging is enabled */
- logfile = g_build_filename (cwd, "gschlas.log", NULL);
- s_log_init (logfile);
- g_free (logfile);
+ s_log_init ("gschlas");
logging_dest=STDOUT_TTY;
if (!quiet_mode)
commit 7cc4a67795c9ee8dcb28edc6d71b895c5b4f1dc9
Author: Peter TB Brett <peter@xxxxxxxxxxxxx>
Date: Wed Jan 21 14:10:41 2009 +0000
Refactor finding paths for config etc.
This is intended to provide a centralised place for determining the
paths more "smartly" in the future (e.g. for platforms with different
conventions on where config should go).
Only user-visible change should be that log messages when loading
config files no longer hardcode "~/.gEDA".
diff --git a/gattrib/src/x_window.c b/gattrib/src/x_window.c
index 235377c..62173bf 100644
--- a/gattrib/src/x_window.c
+++ b/gattrib/src/x_window.c
@@ -236,7 +236,6 @@ x_window_create_menu(GtkWindow *window, GtkWidget **menubar)
GtkUIManager *ui;
GtkActionGroup *action_group;
GError *error = NULL;
- const char *gedadata_path;
/* Create and fill the action group object */
action_group = gtk_action_group_new("");
@@ -247,12 +246,7 @@ x_window_create_menu(GtkWindow *window, GtkWidget **menubar)
gtk_ui_manager_insert_action_group(ui, action_group, 0);
- gedadata_path = g_getenv("GEDADATA"); /* do not free returned string */
- if (gedadata_path != NULL) {
- menu_file = g_build_filename(gedadata_path, "gattrib-menus.xml", NULL);
- } else {
- menu_file = g_build_filename(GEDADATADIR, "gattrib-menus.xml", NULL);
- }
+ menu_file = g_build_filename(s_path_sys_data (), "gattrib-menus.xml", NULL);
gtk_ui_manager_add_ui_from_file(ui, menu_file, &error);
if(error != NULL) {
diff --git a/gschem/src/g_rc.c b/gschem/src/g_rc.c
index 52f1ae5..88ed0c2 100644
--- a/gschem/src/g_rc.c
+++ b/gschem/src/g_rc.c
@@ -49,21 +49,14 @@
void g_rc_parse_gtkrc()
{
gchar *filename;
- const gchar *home;
- filename = g_build_filename (g_rc_parse_path (), "gschem-gtkrc", NULL);
+ filename = g_build_filename (s_path_sys_config (), "gschem-gtkrc", NULL);
+ gtk_rc_parse (filename);
+ g_free (filename);
+
+ filename = g_build_filename (s_path_user_config (), "gschem-gtkrc", NULL);
gtk_rc_parse (filename);
g_free (filename);
-
- home = g_getenv ("HOME");
- if (home == NULL)
- home = g_get_home_dir ();
- if (home != NULL) {
- filename = g_build_filename (home, ".gEDA", "gschem-gtkrc", NULL);
- gtk_rc_parse (filename);
- g_free (filename);
- }
-
}
/*! \todo Finish function documentation!!!
diff --git a/gschem/src/gschem_dialog.c b/gschem/src/gschem_dialog.c
index 6d0583b..4a4f788 100644
--- a/gschem/src/gschem_dialog.c
+++ b/gschem/src/gschem_dialog.c
@@ -104,7 +104,7 @@ static void save_geometry_to_file(gpointer user_data)
g_assert( dialog_geometry != NULL );
data = g_key_file_to_data(dialog_geometry, NULL, NULL);
- file = g_build_filename(g_get_home_dir (), ".gEDA", DIALOG_GEOMETRY_STORE,
+ file = g_build_filename(s_path_user_config (), DIALOG_GEOMETRY_STORE,
NULL);
g_file_set_contents(file, data, -1, NULL);
g_free(data);
@@ -170,7 +170,7 @@ static void setup_keyfile ()
if (dialog_geometry != NULL)
return;
- gchar *file = g_build_filename (g_get_home_dir (), ".gEDA",
+ gchar *file = g_build_filename (s_path_user_config (),
DIALOG_GEOMETRY_STORE, NULL);
dialog_geometry = g_key_file_new();
@@ -179,9 +179,7 @@ static void setup_keyfile ()
gschem_atexit(save_geometry_to_file, NULL);
if (!g_file_test (file, G_FILE_TEST_EXISTS)) {
- gchar *dir = g_build_filename (g_get_home_dir (), ".gEDA", NULL);
- g_mkdir (dir, S_IRWXU | S_IRWXG);
- g_free (dir);
+ g_mkdir (s_path_user_config (), S_IRWXU | S_IRWXG);
g_file_set_contents (file, "", -1, NULL);
}
diff --git a/gschem/src/x_menus.c b/gschem/src/x_menus.c
index bf40173..926246c 100644
--- a/gschem/src/x_menus.c
+++ b/gschem/src/x_menus.c
@@ -386,7 +386,7 @@ out:
/* The list of recently loaded files. */
static GList *recent_files = NULL;
-#define RECENT_FILES_STORE ".gEDA/gschem-recent-files"
+#define RECENT_FILES_STORE "gschem-recent-files"
#define MAX_RECENT_FILES 10
struct recent_file_menu_data {
@@ -593,7 +593,7 @@ static void recent_files_create_empty()
gchar *c;
const gchar * const tmp[] = { NULL };
GKeyFile *kf = g_key_file_new();
- gchar *file = g_build_filename(g_get_home_dir(), RECENT_FILES_STORE, NULL);
+ gchar *file = g_build_filename(s_path_user_config (), RECENT_FILES_STORE, NULL);
g_key_file_set_string_list(kf, "Recent files", "Files", tmp, 0);
c = g_key_file_to_data(kf, NULL, NULL);
@@ -613,7 +613,7 @@ void recent_files_save(gpointer user_data)
gchar *files[MAX_RECENT_FILES];
int num = 0;
gchar *c;
- gchar *file = g_build_filename(g_get_home_dir(), RECENT_FILES_STORE, NULL);
+ gchar *file = g_build_filename(s_path_user_config (), RECENT_FILES_STORE, NULL);
GList *p = recent_files;
if(p == NULL) {
@@ -647,12 +647,10 @@ void recent_files_save(gpointer user_data)
void recent_files_load()
{
GKeyFile *kf = g_key_file_new();
- gchar *file = g_build_filename(g_get_home_dir(), RECENT_FILES_STORE, NULL);
+ gchar *file = g_build_filename(s_path_user_config (), RECENT_FILES_STORE, NULL);
if(!g_file_test(file, G_FILE_TEST_EXISTS)) {
- gchar *dir = g_build_filename(g_get_home_dir(), ".gEDA", NULL);
- g_mkdir(dir, S_IRWXU | S_IRWXG);
- g_free(dir);
+ g_mkdir(s_path_user_config (), S_IRWXU | S_IRWXG);
recent_files_create_empty();
}
diff --git a/libgeda/include/libgeda/prototype.h b/libgeda/include/libgeda/prototype.h
index d1d2a8f..7ed1b34 100644
--- a/libgeda/include/libgeda/prototype.h
+++ b/libgeda/include/libgeda/prototype.h
@@ -37,7 +37,6 @@ SCM g_rc_mode_general(SCM scmmode, const char *rc_name, int *mode_var,
gint g_rc_parse_general(TOPLEVEL *toplevel,
const gchar *fname,
const gchar *ok_msg, const gchar *err_msg);
-const char *g_rc_parse_path(void);
gint g_rc_parse_system_rc(TOPLEVEL *toplevel, const gchar *rcname);
gint g_rc_parse_home_rc(TOPLEVEL *toplevel, const gchar *rcname);
gint g_rc_parse_local_rc(TOPLEVEL *toplevel, const gchar *rcname);
@@ -314,6 +313,9 @@ void s_delete_object_glist(TOPLEVEL *toplevel, GList *list);
char *remove_nl(char *string);
char *remove_last_nl(char *string);
gchar *s_expand_env_variables (const gchar *string);
+const char *s_path_sys_data ();
+const char *s_path_sys_config ();
+const char *s_path_user_config ();
/* s_clib.c */
void s_clib_free (void);
diff --git a/libgeda/src/g_rc.c b/libgeda/src/g_rc.c
index 793ae31..f4fb565 100644
--- a/libgeda/src/g_rc.c
+++ b/libgeda/src/g_rc.c
@@ -154,30 +154,6 @@ gint g_rc_parse_general(TOPLEVEL *toplevel,
}
-/*! \brief Read gEDA root path from RC file.
- * \par Function Description
- * This function will read the RC file and parse the root path for gEDA.
- *
- * \return String containing rc root path
- *
- * \warning Do not free the returned character string.
- */
-const gchar* g_rc_parse_path(void)
-{
- const gchar *rc_path;
-
- if (g_strcasecmp (GEDARCDIR, "none") == 0) {
- /* rc dir not specified at configure time, so search for config in */
- /* the normal GEDADATA directory */
- rc_path = g_getenv ("GEDADATA");
- } else {
- /* rc path specified at configure time, always return specified path */
- rc_path = GEDARCDIR;
- }
-
- return(rc_path);
-}
-
/*! \brief Parses a system RC file.
* \par Function Description
* This function wil open and parse a system rc file.
@@ -188,18 +164,12 @@ const gchar* g_rc_parse_path(void)
*/
gint g_rc_parse_system_rc(TOPLEVEL *toplevel, const gchar *rcname)
{
- const gchar *geda_data = g_getenv ("GEDADATA");
gint found_rc;
gchar *tmp;
char *filename;
gchar *ok_msg, *err_msg;
- if (geda_data == NULL) {
- fprintf(stderr, "You must set the GEDADATA environment variable!\n");
- exit(-1);
- }
-
- tmp = g_strconcat (g_rc_parse_path (),
+ tmp = g_strconcat (s_path_sys_config (),
G_DIR_SEPARATOR_S,
"system-", rcname,
NULL);
@@ -208,10 +178,8 @@ gint g_rc_parse_system_rc(TOPLEVEL *toplevel, const gchar *rcname)
return 0;
}
- ok_msg = g_strdup_printf (_("Read system-%s file [%%s]\n"),
- rcname);
- err_msg = g_strdup_printf (_("Did not find required system-%s file [%%s]\n"),
- rcname);
+ ok_msg = g_strdup_printf (_("Read system config file [%%s]\n"));
+ err_msg = g_strdup_printf (_("Did not find required system config file [%%s]\n"));
found_rc = g_rc_parse_general(toplevel, filename, ok_msg, err_msg);
g_free(ok_msg);
@@ -232,30 +200,21 @@ gint g_rc_parse_system_rc(TOPLEVEL *toplevel, const gchar *rcname)
*/
gint g_rc_parse_home_rc(TOPLEVEL *toplevel, const gchar *rcname)
{
- const gchar *home;
gint found_rc;
gchar *tmp;
char *filename;
gchar *ok_msg, *err_msg;
- home = g_getenv ("HOME");
- if (home == NULL)
- home = g_get_home_dir ();
+ if (s_path_user_config () == NULL) return 0;
- if (home == NULL) {
- return 0;
- }
-
- tmp = g_build_filename (home, ".gEDA", rcname, NULL);
+ tmp = g_build_filename (s_path_user_config (), rcname, NULL);
filename = f_normalize_filename (tmp, NULL);
if (filename == NULL) {
return 0;
}
- ok_msg = g_strdup_printf (_("Read ~/.gEDA/%s file [%%s]\n"),
- rcname);
- err_msg = g_strdup_printf (_("Did not find optional ~/.gEDA/%s file [%%s]\n"),
- rcname);
+ ok_msg = g_strdup_printf (_("Read user config file [%%s]\n"));
+ err_msg = g_strdup_printf (_("Did not find optional user config file [%%s]\n"));
found_rc = g_rc_parse_general(toplevel, filename, ok_msg, err_msg);
g_free(ok_msg);
@@ -286,10 +245,8 @@ gint g_rc_parse_local_rc(TOPLEVEL *toplevel, const gchar *rcname)
return 0;
}
- ok_msg = g_strdup_printf (_("Read local %s file [%%s]\n"),
- rcname);
- err_msg = g_strdup_printf (_("Did not find optional local %s file [%%s]\n"),
- rcname);
+ ok_msg = g_strdup_printf (_("Read local config file [%%s]\n"));
+ err_msg = g_strdup_printf (_("Did not find optional local config file [%%s]\n"));
found_rc = g_rc_parse_general(toplevel, filename, ok_msg, err_msg);
g_free(ok_msg);
@@ -357,15 +314,7 @@ void g_rc_parse(TOPLEVEL *toplevel,
const gchar *rcname, const gchar *specified_rc_filename)
{
gint found_rc = 0;
- char *rc_path;
- /* set the GEDADATARC environment variable so that the rc files */
- /* know where to look for others */
- rc_path = f_normalize_filename (g_rc_parse_path (), NULL);
-
- g_setenv ("GEDADATARC", rc_path, TRUE);
- g_free (rc_path);
-
/* visit rc files in order */
/* Changed by SDB 1.2.2005 in response to Peter Kaiser's bug report.
* Read gafrc files first */
diff --git a/libgeda/src/g_register.c b/libgeda/src/g_register.c
index c254765..6865c01 100644
--- a/libgeda/src/g_register.c
+++ b/libgeda/src/g_register.c
@@ -99,9 +99,9 @@ void g_register_libgeda_funcs (void)
void g_register_libgeda_vars (void)
{
scm_c_define("geda-rc-path",
- scm_from_locale_string (g_rc_parse_path()));
+ scm_from_locale_string (s_path_sys_config ()));
scm_c_define("geda-data-path",
- scm_from_locale_string (g_getenv ("GEDADATA")));
+ scm_from_locale_string (s_path_sys_data ()));
scm_c_define("path-sep",
scm_from_locale_string(G_DIR_SEPARATOR_S));
diff --git a/libgeda/src/libgeda.c b/libgeda/src/libgeda.c
index 3031880..d00345b 100644
--- a/libgeda/src/libgeda.c
+++ b/libgeda/src/libgeda.c
@@ -46,12 +46,6 @@
*/
void libgeda_init(void)
{
- char *geda_data = getenv("GEDADATA");
-
- if (geda_data == NULL) {
- g_setenv ("GEDADATA", GEDADATADIR, FALSE);
- }
-
/* Initialise gettext */
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
diff --git a/libgeda/src/s_basic.c b/libgeda/src/s_basic.c
index 1f25519..d56a3fc 100644
--- a/libgeda/src/s_basic.c
+++ b/libgeda/src/s_basic.c
@@ -486,3 +486,81 @@ s_expand_env_variables (const gchar *string)
/* never reached */
return NULL;
}
+
+
+/* -------------------------------------------------- */
+
+/*! \brief Get the directory with the gEDA system data.
+ * \par Function description
+ * Returns the path to be searched for gEDA data shared between all
+ * users. If the GEDADATA environment variable is set, returns its
+ * value; otherwise, uses a compiled-in path.
+ *
+ * \warning The returned string is owned by libgeda and should not be
+ * modified or free'd.
+ *
+ * \todo On Windows, we probably shouldn't use the compiled-in
+ * default.
+ */
+const char *s_path_sys_data () {
+ static const char *p = NULL;
+ if (p == NULL) {
+ p = g_getenv ("GEDADATA");
+ }
+ if (p == NULL) {
+ p = GEDADATADIR;
+ g_setenv ("GEDADATA", p, FALSE);
+ }
+ return p;
+}
+
+/*! \brief Get the directory with the gEDA system configuration.
+ * \par Function description
+ * Returns the path to be searched for gEDA configuration shared
+ * between all users. If the GEDADATARC environment variable is set,
+ * returns its value; otherwise, uses a compiled-in path.
+ *
+ * \warning The returned string is owned by libgeda and should not be
+ * modified or free'd.
+ */
+const char *s_path_sys_config () {
+ static const char *p = NULL;
+
+ /* If GEDADATARC is set in the environment, use that path */
+ if (p == NULL) {
+ p = g_getenv ("GEDADATARC");
+ }
+ if (p == NULL) {
+ if (g_strcasecmp (GEDARCDIR, "none") != 0) {
+ /* If available, use the rc directory set during configure. */
+ p = GEDARCDIR;
+ } else {
+ /* Otherwise, just use the data directory */
+ p = s_path_sys_data ();
+ }
+ g_setenv("GEDADATARC", p, FALSE);
+ }
+ return p;
+}
+
+/*! \brief Get the directory with the gEDA user configuration.
+ * \par Function description
+ * Returns the path to be searched for the current user's gEDA
+ * configuration. Currently defaults to a directory ".gEDA" in the
+ * user's home directory.
+ *
+ * \warning The returned string is owned by libgeda and should not be
+ * modified or free'd.
+ *
+ * \todo On Windows, we should use APPDATA.
+ */
+const char *s_path_user_config () {
+ static const char *p = NULL;
+
+ if (p == NULL) {
+ const char *home = g_getenv ("HOME");
+ if (home == NULL) home = g_get_home_dir ();
+ p = g_build_filename(home, ".gEDA", NULL);
+ }
+ return p;
+}
_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs