[641] in BarnOwl Developers
[D-O-H] r741 - trunk/owl
daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:08:13 2009
Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Sun, 8 Jul 2007 15:37:45 -0400 (EDT)
Author: nelhage
Date: 2007-07-08 15:37:43 -0400 (Sun, 08 Jul 2007)
New Revision: 741
Modified:
trunk/owl/commands.c
trunk/owl/functions.c
trunk/owl/global.c
trunk/owl/owl.c
trunk/owl/owl.h
trunk/owl/perlglue.xs
trunk/owl/perlwrap.pm
Log:
Adding a -s switch to change the location of the config dir (~/.owl)
Modified: trunk/owl/commands.c
===================================================================
--- trunk/owl/commands.c 2007-07-07 23:46:16 UTC (rev 740)
+++ trunk/owl/commands.c 2007-07-08 19:37:43 UTC (rev 741)
@@ -2141,9 +2141,8 @@
} else if (!strcmp(argv[1], "startup")) {
char *filename;
- filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
+ filename=owl_global_get_startupfile(&g);
owl_function_popless_file(filename);
- owl_free(filename);
} else if (!strcmp(argv[1], "errors")) {
owl_function_showerrs();
} else {
Modified: trunk/owl/functions.c
===================================================================
--- trunk/owl/functions.c 2007-07-07 23:46:16 UTC (rev 740)
+++ trunk/owl/functions.c 2007-07-08 19:37:43 UTC (rev 741)
@@ -3460,17 +3460,15 @@
FILE *file;
char *filename;
- filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
+ filename=owl_global_get_startupfile(&g);
file=fopen(filename, "a");
if (!file) {
owl_function_error("Error opening startupfile for new command");
- owl_free(filename);
return;
}
/* delete earlier copies */
owl_util_file_deleteline(filename, buff, 1);
- owl_free(filename);
/* add this line */
fprintf(file, "%s\n", buff);
@@ -3482,9 +3480,8 @@
void owl_function_delstartup(char *buff)
{
char *filename;
- filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
+ filename=owl_global_get_startupfile(&g);
owl_util_file_deleteline(filename, buff, 1);
- owl_free(filename);
}
/* Execute owl commands from the given filename. If the filename
@@ -3496,9 +3493,8 @@
char buff[LINE];
if (!filename) {
- filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
+ filename=owl_global_get_startupfile(&g);
file=fopen(filename, "r");
- owl_free(filename);
} else {
file=fopen(filename, "r");
}
Modified: trunk/owl/global.c
===================================================================
--- trunk/owl/global.c 2007-07-07 23:46:16 UTC (rev 740)
+++ trunk/owl/global.c 2007-07-08 19:37:43 UTC (rev 741)
@@ -85,6 +85,12 @@
/* TODO: come back later and check passwd file first */
g->homedir=owl_strdup(getenv("HOME"));
+ g->confdir = NULL;
+ g->startupfile = NULL;
+ char * cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR);
+ owl_global_set_confdir(g, cd);
+ owl_free(cd);
+
owl_messagelist_create(&(g->msglist));
owl_mainwin_init(&(g->mw));
owl_popwin_init(&(g->pw));
@@ -318,6 +324,26 @@
return("/");
}
+char *owl_global_get_confdir(owl_global *g) {
+ if (g->confdir) return(g->confdir);
+ return("/");
+}
+
+/*
+ * Setting this also sets startupfile to confdir/startup
+ */
+void owl_global_set_confdir(owl_global *g, char *cd) {
+ free(g->confdir);
+ g->confdir = owl_strdup(cd);
+ free(g->startupfile);
+ g->startupfile = owl_sprintf("%s/startup", cd);
+}
+
+char *owl_global_get_startupfile(owl_global *g) {
+ if(g->startupfile) return(g->startupfile);
+ return("/");
+}
+
int owl_global_get_direction(owl_global *g) {
return(g->direction);
}
Modified: trunk/owl/owl.c
===================================================================
--- trunk/owl/owl.c 2007-07-07 23:46:16 UTC (rev 740)
+++ trunk/owl/owl.c 2007-07-08 19:37:43 UTC (rev 741)
@@ -63,6 +63,13 @@
owl_global g;
+char * owl_get_datadir() {
+ char * datadir = getenv("BARNOWL_DATA_DIR");
+ if(datadir != NULL)
+ return strchr(datadir, '=') + 1;
+ return DATADIR;
+}
+
int main(int argc, char **argv, char **env)
{
WINDOW *recwin, *sepwin, *typwin, *msgwin;
@@ -72,6 +79,7 @@
int newmsgs, nexttimediff;
struct sigaction sigact;
char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE];
+ char *confdir;
owl_filter *f;
owl_style *s;
time_t nexttime, now;
@@ -86,6 +94,7 @@
argcsave=argc;
argvsave=argv;
configfile=NULL;
+ confdir = NULL;
tty=NULL;
debug=0;
initialsubs=1;
@@ -100,22 +109,31 @@
argc--;
} else if (!strcmp(argv[0], "-c")) {
if (argc<2) {
- fprintf(stderr, "Too few arguments to -c\n");
- usage();
- exit(1);
+ fprintf(stderr, "Too few arguments to -c\n");
+ usage();
+ exit(1);
}
configfile=argv[1];
argv+=2;
argc-=2;
} else if (!strcmp(argv[0], "-t")) {
if (argc<2) {
- fprintf(stderr, "Too few arguments to -t\n");
- usage();
- exit(1);
+ fprintf(stderr, "Too few arguments to -t\n");
+ usage();
+ exit(1);
}
tty=argv[1];
argv+=2;
argc-=2;
+ } else if (!strcmp(argv[0], "-s")){
+ if (argc<2) {
+ fprintf(stderr, "Too few arguments to -s\n");
+ usage();
+ exit(1);
+ }
+ confdir = argv[1];
+ argv+=2;
+ argc-=2;
} else if (!strcmp(argv[0], "-d")) {
debug=1;
argv++;
@@ -190,7 +208,8 @@
/* owl global init */
owl_global_init(&g);
- if (debug) owl_global_set_debug_on(&g);
+ if (debug) owl_global_set_debug_on(&g);
+ if (confdir) owl_global_set_confdir(&g, confdir);
owl_function_debugmsg("startup: first available debugging message");
owl_global_set_startupargs(&g, argcsave, argvsave);
owl_global_set_haveaim(&g);
@@ -212,9 +231,8 @@
/* create the owl directory, in case it does not exist */
owl_function_debugmsg("startup: creating owl directory, if not present");
- dir=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_CONFIG_DIR);
+ dir=owl_global_get_confdir(&g);
mkdir(dir, S_IRWXU);
- owl_free(dir);
/* set the tty, either from the command line, or by figuring it out */
owl_function_debugmsg("startup: setting tty name");
@@ -696,13 +714,14 @@
void usage()
{
fprintf(stderr, "Owl version %s\n", OWL_VERSION_STRING);
- fprintf(stderr, "Usage: owl [-n] [-d] [-D] [-v] [-h] [-c <configfile>] [-t <ttyname>]\n");
+ fprintf(stderr, "Usage: owl [-n] [-d] [-D] [-v] [-h] [-c <configfile>] [-s <confdir>] [-t <ttyname>]\n");
fprintf(stderr, " -n don't load zephyr subscriptions\n");
fprintf(stderr, " -d enable debugging\n");
fprintf(stderr, " -D enable debugging and delete previous debug file\n");
fprintf(stderr, " -v print the Owl version number and exit\n");
fprintf(stderr, " -h print this help message\n");
fprintf(stderr, " -c specify an alternate config file\n");
+ fprintf(stderr, " -s specify an alternate config dir (default ~/.owl)\n");
fprintf(stderr, " -t set the tty name\n");
}
Modified: trunk/owl/owl.h
===================================================================
--- trunk/owl/owl.h 2007-07-07 23:46:16 UTC (rev 740)
+++ trunk/owl/owl.h 2007-07-08 19:37:43 UTC (rev 741)
@@ -558,6 +558,8 @@
int typwinactive;
char *thishost;
char *homedir;
+ char *confdir;
+ char *startupfile;
int direction;
int zaway;
char *cur_zaway_msg;
Modified: trunk/owl/perlglue.xs
===================================================================
--- trunk/owl/perlglue.xs 2007-07-07 23:46:16 UTC (rev 740)
+++ trunk/owl/perlglue.xs 2007-07-08 19:37:43 UTC (rev 741)
@@ -198,10 +198,17 @@
char *
get_data_dir ()
CODE:
- RETVAL = (char *) DATADIR;
+ RETVAL = (char *) owl_get_datadir();
OUTPUT:
RETVAL
+char *
+get_config_dir ()
+ CODE:
+ RETVAL = (char *) owl_global_get_confdir(&g);
+ OUTPUT:
+ RETVAL
+
void
popless_text(text)
char *text
Modified: trunk/owl/perlwrap.pm
===================================================================
--- trunk/owl/perlwrap.pm 2007-07-07 23:46:16 UTC (rev 740)
+++ trunk/owl/perlwrap.pm 2007-07-08 19:37:43 UTC (rev 741)
@@ -20,9 +20,11 @@
bootstrap BarnOwl 1.2;
};
-use lib(get_data_dir()."/lib");
-use lib($ENV{HOME}."/.owl/lib");
+use lib(get_data_dir() . "/lib");
+use lib(get_config_dir() . "/lib");
+# perlconfig.c will set this to the value of the -c command-line
+# switch, if present.
our $configfile;
if(!$configfile && -f $ENV{HOME} . "/.barnowlconf") {