summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsabetts <sabetts>2003-11-25 06:46:11 +0000
committersabetts <sabetts>2003-11-25 06:46:11 +0000
commitc5eaee5bda09b72d3f03fe7316c83801778f3f44 (patch)
treec92fc648f93fd25dc534b841c12f88e289d8d953 /src
parent863e018ef2cf8851694cbd9b7c3889d52fe50b17 (diff)
downloadratpoison-c5eaee5bda09b72d3f03fe7316c83801778f3f44.zip
(ratpoison_longopts): add "file"
(ratpoison_opts): add f: option (print_help): print help for --file option (read_startup_files): take an alternative rc file as an argument and use it if it is non-NULL. (main): parse the --file option. pass alt_rcfile to read_startup_files.
Diffstat (limited to 'src')
-rw-r--r--src/main.c76
1 files changed, 47 insertions, 29 deletions
diff --git a/src/main.c b/src/main.c
index e252d75..bcec4f6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -54,9 +54,10 @@ static struct option ratpoison_longopts[] =
{"command", required_argument, 0, 'c'},
{"display", required_argument, 0, 'd'},
{"screen", required_argument, 0, 's'},
+ {"file", required_argument, 0, 'f'},
{0, 0, 0, 0} };
-static char ratpoison_opts[] = "hvic:d:s:";
+static char ratpoison_opts[] = "hvic:d:s:f:";
void
fatal (const char *msg)
@@ -291,7 +292,8 @@ print_help ()
printf ("-d, --display <dpy> Set the X display to use\n");
printf ("-s, --screen <num> Only use the specified screen\n");
printf ("-c, --command <cmd> Send ratpoison a colon-command\n");
- printf ("-i, --interactive Execute commands in interactive mode\n\n");
+ printf ("-i, --interactive Execute commands in interactive mode\n");
+ printf ("-f, --file <file> Specify an alternative configuration file\n\n");
printf ("Report bugs to ratpoison-devel@lists.sourceforge.net\n\n");
@@ -363,44 +365,54 @@ read_rc_file (FILE *file)
}
static void
-read_startup_files ()
+read_startup_files (char *alt_rcfile)
{
char *homedir;
- FILE *fileptr;
+ FILE *fileptr = NULL;
- /* first check $HOME/.ratpoisonrc and if that does not exist then try
- /etc/ratpoisonrc */
-
- homedir = getenv ("HOME");
- if (!homedir)
+ if (alt_rcfile)
{
- PRINT_ERROR (("ratpoison: $HOME not set!?\n"));
+ if ((fileptr = fopen (alt_rcfile, "r")) == NULL)
+ {
+ /* we probably don't need to report this, its not an error */
+ PRINT_DEBUG (("ratpoison: could not open %s\n", alt_rcfile));
+ }
}
else
{
- char *filename = (char*)xmalloc (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 */
- PRINT_DEBUG (("ratpoison: could not open %s\n", filename));
+ /* first check $HOME/.ratpoisonrc and if that does not exist then try
+ /etc/ratpoisonrc */
- if ((fileptr = fopen ("/etc/ratpoisonrc", "r")) == NULL)
- {
- /* neither is this */
- PRINT_DEBUG (("ratpoison: could not open /etc/ratpoisonrc\n"));
- }
+ homedir = getenv ("HOME");
+ if (!homedir)
+ {
+ PRINT_ERROR (("ratpoison: $HOME not set!?\n"));
}
-
- if (fileptr)
+ else
{
- set_close_on_exec(fileptr);
- read_rc_file (fileptr);
- fclose (fileptr);
+ char *filename = (char*)xmalloc (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 */
+ PRINT_DEBUG (("ratpoison: could not open %s\n", filename));
+
+ if ((fileptr = fopen ("/etc/ratpoisonrc", "r")) == NULL)
+ {
+ /* neither is this */
+ PRINT_DEBUG (("ratpoison: could not open /etc/ratpoisonrc\n"));
+ }
+ }
+ free (filename);
}
+ }
- free (filename);
+ if (fileptr)
+ {
+ set_close_on_exec(fileptr);
+ read_rc_file (fileptr);
+ fclose (fileptr);
}
}
@@ -497,6 +509,7 @@ main (int argc, char *argv[])
int screen_num = 0;
char *display = NULL;
unsigned char interactive = 0;
+ char *alt_rcfile = NULL;
myargv = argv;
@@ -540,6 +553,9 @@ main (int argc, char *argv[])
case 'i':
interactive = 1;
break;
+ case 'f':
+ alt_rcfile = xstrdup (optarg);
+ break;
default:
exit (EXIT_FAILURE);
@@ -653,7 +669,9 @@ main (int argc, char *argv[])
}
}
- read_startup_files ();
+ read_startup_files (alt_rcfile);
+ if (alt_rcfile)
+ free (alt_rcfile);
/* Indicate to the user that ratpoison has booted. */
if (defaults.startup_message)