summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrcyeske <rcyeske>2001-02-24 23:37:18 +0000
committerrcyeske <rcyeske>2001-02-24 23:37:18 +0000
commit854ddcaf13f857e969bf24a966ea1647a011c42f (patch)
tree8ebfcf97da5e8b9e991ee837186291c69cafdaf0 /src
parentbef606ab426fd0a8234970da06c5d3fd1e150880 (diff)
downloadratpoison-854ddcaf13f857e969bf24a966ea1647a011c42f.zip
added initialization file support "~/.ratpoisonrc"
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog4
-rw-r--r--src/main.c54
2 files changed, 56 insertions, 2 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index d3a5e5a..c1dd9bf 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
2001-02-24 Ryan Yeske <rcyeske@cut.hotdog.tmp>
+ * main.c (load_rc_file): new function
+ (read_initialization_files): new function
+ (main): read the initialization files
+
* conf.h: remove themes support
* themes.h: remove file
diff --git a/src/main.c b/src/main.c
index daa47f4..1a85969 100644
--- a/src/main.c
+++ b/src/main.c
@@ -176,6 +176,54 @@ print_help ()
exit (EXIT_SUCCESS);
}
+static void
+load_rc_file (char *filename)
+{
+ FILE *rcfile;
+
+ char *lineptr;
+ size_t n;
+
+ n = 0;
+ lineptr = NULL;
+
+ if ((rcfile = fopen (filename, "r")) == NULL)
+ {
+ fprintf (stderr, "ratpoison: could not open %s\n", filename);
+ }
+ else
+ {
+ size_t retval;
+ n = 256;
+ lineptr = (char*)malloc(n);
+
+ while ((retval = getline (&lineptr, &n, rcfile)) != EOF)
+ {
+ fprintf (stderr, "read command: %s\n", lineptr);
+
+ command (lineptr);
+ }
+
+ free (lineptr);
+ }
+}
+
+static void
+read_initialization_files ()
+{
+ char *homedir;
+
+ homedir = getenv ("HOME");
+
+ if (!homedir)
+ fprintf (stderr, "$HOME not set!?\n");
+ else
+ {
+ char *rcfile = (char*)malloc (strlen (homedir) + strlen ("/.ratpoisonrc") + 1);
+ sprintf (rcfile, "%s/.ratpoisonrc", homedir);
+ load_rc_file (rcfile);
+ }
+}
int
main (int argc, char *argv[])
@@ -281,6 +329,8 @@ main (int argc, char *argv[])
initialize_default_keybindings ();
+ read_initialization_files ();
+
/* Set an initial window as active. */
set_active_window (find_window_other ());
@@ -376,5 +426,5 @@ find_screen (Window w)
for (i=0; i<num_screens; i++)
if (screens[i].root == w) return &screens[i];
- return NULL;
-}
+ return NULL;
+ }