1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
--- src/app/main.c.orig Sun Nov 6 08:52:50 2005
+++ src/app/main.c Tue Feb 28 04:00:28 2006
@@ -19,6 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#include <sys/param.h>
#include "./main.h"
#include "./globals.h"
// Gtkglext - 2005-11
@@ -48,37 +49,21 @@
if (command) free(command);
}
+char *get_current_dir_name() {
+ char *buf = malloc(MAXPATHLEN);
+ getwd(buf);
+ return buf;
+}
+
gchar *find_config_file() {
// Returns the config file name (name OPTIONS_FILE, defined in globals.h),
// with its full path
gchar *default_dir, *path_n_file, *buf, *command;
gboolean shortcuts;
-// We try:
-// 1. in the current directory. (./OPTIONS_FILE = ./geomorphrc)
-// 2. if not found, we try ./DEFAULT_DIR/OPTIONS_FILE (./geomorph/geomorphrc)
-// 3. if not found, we try $HOME/OPTIONS_FILE (~/geomorphrc)
-// 4. if not found, we try in $HOME/DEFAULT_DIR (~/geomorph/geomorphrc)
-// --> if OPTIONS_FILE was not found, and
-// if $HOME/DEFAULT_DIR doesn't exist, we create the required files
-// The directory where OPTIONS_FILE is found becomes the default one (DEF_DIR)
-
- // Try ./OPTIONS_FILE
- default_dir = (gchar *) get_current_dir_name();
- path_n_file = concat_dname_fname(default_dir,OPTIONS_FILE);
- if (!filexists(path_n_file)) { // Try ./DEFAULT_DIR/OPTIONS_FILE
- default_dir = concat_dname_fname(default_dir,DEFAULT_DIR);
- if (path_n_file)
- free(path_n_file);
- path_n_file = concat_dname_fname(default_dir,OPTIONS_FILE);
- if (!filexists(path_n_file)) { // Try in the home directory - ~/OPTIONS_FILE
+ // Config file is located under $HOME/.geomorph/geomorphrc
default_dir = getenv("HOME");
- if (path_n_file)
- free(path_n_file);
- path_n_file = concat_dname_fname(default_dir, OPTIONS_FILE);
- if (!filexists(path_n_file)) { // Try ~/DEFAULT_DIR/OPTIONS_FILE
default_dir = concat_dname_fname(default_dir,DEFAULT_DIR);
- if (path_n_file) free(path_n_file);
path_n_file = concat_dname_fname(default_dir, OPTIONS_FILE);
if (directory_exists(default_dir)) {
if (!filexists(path_n_file)) {
@@ -109,9 +94,6 @@
}
if (path_n_file) free(path_n_file);
}
- }
- }
- }
return add_filesep(default_dir);
}
|