summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrcyeske <rcyeske>2001-03-02 05:25:02 +0000
committerrcyeske <rcyeske>2001-03-02 05:25:02 +0000
commit11932954e0122c115be23862aabfacb565a4cbed (patch)
tree5d624b34129748104728d697a9e24e9b54de892a
parent9d783e1994f521940955a29b5a7df33b50fb0c9d (diff)
downloadratpoison-11932954e0122c115be23862aabfacb565a4cbed.zip
* actions.c (cmd_source): Open the file. Error report as
appropriate. * main.c (read_rc_file): Take a file pointer rather than a filename. (read_startup_files): If ~/.ratpoisonrc is not readable try /etc/ratpoisonrc. * actions.c: Use PRINT_DEBUG instead of fprintf. Put useful error text in calls to message(). (cmd_select): Show the window list if there is no such window number.
-rw-r--r--src/ChangeLog8
-rw-r--r--src/actions.c10
-rw-r--r--src/main.c94
-rw-r--r--src/ratpoison.h2
4 files changed, 76 insertions, 38 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index e826213..58d8802 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,13 @@
2001-03-01 Ryan Yeske <rcyeske@cut.hotdog.tmp>
+ * actions.c (cmd_source): Open the file. Error report as
+ appropriate.
+
+ * main.c (read_rc_file): Take a file pointer rather than a
+ filename.
+ (read_startup_files): If ~/.ratpoisonrc is not readable try
+ /etc/ratpoisonrc.
+
* actions.c: Use PRINT_DEBUG instead of fprintf. Put useful error
text in calls to message().
(cmd_select): Show the window list if there is no such window
diff --git a/src/actions.c b/src/actions.c
index eacb481..f3ebef8 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -267,7 +267,15 @@ cmd_unimplemented (void *data)
void
cmd_source (void *data)
{
- read_rc_file ((char*)data);
+ FILE *fileptr;
+
+ if ((fileptr = fopen ((char*) data, "r")) == NULL)
+ message (" source: error opening file ");
+ else
+ {
+ read_rc_file (fileptr);
+ fclose (fileptr);
+ }
}
void
diff --git a/src/main.c b/src/main.c
index 276df1d..802d37f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -185,66 +185,88 @@ print_help ()
}
void
-read_rc_file (char *filename)
+read_rc_file (FILE *file)
{
- FILE *rcfile;
+ size_t n = 256;
+ char *partial;
+ char *line;
+ int linesize = n;
- if ((rcfile = fopen (filename, "r")) == NULL)
- {
- PRINT_DEBUG ("ratpoison: could not open %s\n", filename);
- }
- else
+ partial = (char*)malloc(n);
+ line = (char*)malloc(linesize);
+
+ *line = '\0';
+ while (fgets (partial, n, file) != NULL)
{
- size_t n = 256;
- char *partial;
- char *line;
- int linesize = n;
+ if ((strlen (line) + strlen (partial)) <= linesize)
+ {
+ linesize *= 2;
+ line = (char*) realloc (line, linesize);
+ }
- partial = (char*)malloc(n);
- line = (char*)malloc(linesize);
+ strcat (line, partial);
- *line = '\0';
- while (fgets (partial, n, rcfile) != NULL)
+ if (feof(file) || (*(line + strlen(line) - 1) == '\n'))
{
- if ((strlen (line) + strlen (partial)) <= linesize)
- {
- linesize *= 2;
- line = (char*) realloc (line, linesize);
- }
+ /* FIXME: this is a hack, command() should properly parse
+ the command and args (ie strip whitespace, etc)
- strcat (line, partial);
+ We should not care if there is a newline (or vertical
+ tabs or linefeeds for that matter) at the end of the
+ command (or anywhere between tokens). */
+ if (*(line + strlen(line) - 1) == '\n')
+ *(line + strlen(line) - 1) = '\0';
- if (feof(rcfile) || (*(line + strlen(line) - 1) == '\n'))
- {
- PRINT_DEBUG ("rcfile line: %s\n", line);
+ PRINT_DEBUG ("rcfile line: %s\n", line);
- /* do it */
- command (line);
+ /* do it */
+ command (line);
- *line = '\0';
- }
+ *line = '\0';
}
+ }
- free (line);
- free (partial);
- }
+ free (line);
+ free (partial);
}
static void
read_startup_files ()
{
char *homedir;
+ FILE *fileptr;
- homedir = getenv ("HOME");
+ /* first check $HOME/.ratpoisonrc and if that does not exist then try
+ /etc/ratpoisonrc */
+ homedir = getenv ("HOME");
if (!homedir)
- fprintf (stderr, "$HOME not set!?\n");
+ fprintf (stderr, "ratpoison: $HOME not set!?\n");
else
{
- char *rcfile = (char*)malloc (strlen (homedir) + strlen ("/.ratpoisonrc") + 1);
- sprintf (rcfile, "%s/.ratpoisonrc", homedir);
- read_rc_file (rcfile);
+ char *filename = (char*)malloc (strlen (homedir) + strlen ("/.ratpoisonrc") + 1);
+ sprintf (filename, "%s/.ratpoisonrc", homedir);
+
+ if ((fileptr = fopen (filename, "r")) == NULL)
+ {
+ /* we probably don't need to report this, its not an error */
+ fprintf (stderr, "ratpoison: could not open %s\n", filename);
+
+ if ((fileptr = fopen ("/etc/ratpoisonrc", "r")) == NULL)
+ {
+ /* neither is this */
+ fprintf (stderr, "ratpoison: could not open /etc/ratpoisonrc\n");
+ }
+ }
+
+ if (fileptr)
+ {
+ read_rc_file (fileptr);
+ fclose (fileptr);
+ }
+
+ free (filename);
}
}
diff --git a/src/ratpoison.h b/src/ratpoison.h
index 00920db..3a06d5e 100644
--- a/src/ratpoison.h
+++ b/src/ratpoison.h
@@ -61,6 +61,6 @@ extern XGCValues gv;
void clean_up ();
screen_info *find_screen (Window w);
-void read_rc_file (char *filename);
+void read_rc_file (FILE *file);
#endif /* ! _RATPOISON_H */