Changeset b363d83


Ignore:
Timestamp:
Jul 8, 2007, 3:37:43 PM (17 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
be98ba5
Parents:
93f65b6
Message:
Adding a -s switch to change the location of the config dir (~/.owl)
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    r987ff51 rb363d83  
    21422142    char *filename;
    21432143   
    2144     filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
     2144    filename=owl_global_get_startupfile(&g);
    21452145    owl_function_popless_file(filename);
    2146     owl_free(filename);
    21472146  } else if (!strcmp(argv[1], "errors")) {
    21482147    owl_function_showerrs();
  • functions.c

    r48609ce rb363d83  
    34613461  char *filename;
    34623462
    3463   filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
     3463  filename=owl_global_get_startupfile(&g);
    34643464  file=fopen(filename, "a");
    34653465  if (!file) {
    34663466    owl_function_error("Error opening startupfile for new command");
    3467     owl_free(filename);
    34683467    return;
    34693468  }
     
    34713470  /* delete earlier copies */
    34723471  owl_util_file_deleteline(filename, buff, 1);
    3473   owl_free(filename);
    34743472
    34753473  /* add this line */
     
    34833481{
    34843482  char *filename;
    3485   filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
     3483  filename=owl_global_get_startupfile(&g);
    34863484  owl_util_file_deleteline(filename, buff, 1);
    3487   owl_free(filename);
    34883485}
    34893486
     
    34973494
    34983495  if (!filename) {
    3499     filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
     3496    filename=owl_global_get_startupfile(&g);
    35003497    file=fopen(filename, "r");
    3501     owl_free(filename);
    35023498  } else {
    35033499    file=fopen(filename, "r");
  • global.c

    rf1fc47f rb363d83  
    8686  g->homedir=owl_strdup(getenv("HOME"));
    8787
     88  g->confdir = NULL;
     89  g->startupfile = NULL;
     90  char * cd = owl_sprintf("%s/%s", g->homedir, OWL_CONFIG_DIR);
     91  owl_global_set_confdir(g, cd);
     92  owl_free(cd);
     93
    8894  owl_messagelist_create(&(g->msglist));
    8995  owl_mainwin_init(&(g->mw));
     
    319325}
    320326
     327char *owl_global_get_confdir(owl_global *g) {
     328  if (g->confdir) return(g->confdir);
     329  return("/");
     330}
     331
     332/*
     333 * Setting this also sets startupfile to confdir/startup
     334 */
     335void owl_global_set_confdir(owl_global *g, char *cd) {
     336  free(g->confdir);
     337  g->confdir = owl_strdup(cd);
     338  free(g->startupfile);
     339  g->startupfile = owl_sprintf("%s/startup", cd);
     340}
     341
     342char *owl_global_get_startupfile(owl_global *g) {
     343  if(g->startupfile) return(g->startupfile);
     344  return("/");
     345}
     346
    321347int owl_global_get_direction(owl_global *g) {
    322348  return(g->direction);
  • owl.c

    r13a3c1db rb363d83  
    6464owl_global g;
    6565
     66char * owl_get_datadir() {
     67    char * datadir = getenv("BARNOWL_DATA_DIR");
     68    if(datadir != NULL)
     69        return strchr(datadir, '=') + 1;
     70    return DATADIR;
     71}
     72
    6673int main(int argc, char **argv, char **env)
    6774{
     
    7380  struct sigaction sigact;
    7481  char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE];
     82  char *confdir;
    7583  owl_filter *f;
    7684  owl_style *s;
     
    8795  argvsave=argv;
    8896  configfile=NULL;
     97  confdir = NULL;
    8998  tty=NULL;
    9099  debug=0;
     
    101110    } else if (!strcmp(argv[0], "-c")) {
    102111      if (argc<2) {
    103         fprintf(stderr, "Too few arguments to -c\n");
    104         usage();
    105         exit(1);
     112        fprintf(stderr, "Too few arguments to -c\n");
     113        usage();
     114        exit(1);
    106115      }
    107116      configfile=argv[1];
     
    110119    } else if (!strcmp(argv[0], "-t")) {
    111120      if (argc<2) {
    112         fprintf(stderr, "Too few arguments to -t\n");
    113         usage();
    114         exit(1);
     121        fprintf(stderr, "Too few arguments to -t\n");
     122        usage();
     123        exit(1);
    115124      }
    116125      tty=argv[1];
     126      argv+=2;
     127      argc-=2;
     128    } else if (!strcmp(argv[0], "-s")){
     129      if (argc<2) {
     130        fprintf(stderr, "Too few arguments to -s\n");
     131        usage();
     132        exit(1);
     133      }
     134      confdir = argv[1];
    117135      argv+=2;
    118136      argc-=2;
     
    191209  /* owl global init */
    192210  owl_global_init(&g);
    193     if (debug) owl_global_set_debug_on(&g);
     211  if (debug) owl_global_set_debug_on(&g);
     212  if (confdir) owl_global_set_confdir(&g, confdir);
    194213  owl_function_debugmsg("startup: first available debugging message");
    195214  owl_global_set_startupargs(&g, argcsave, argvsave);
     
    213232  /* create the owl directory, in case it does not exist */
    214233  owl_function_debugmsg("startup: creating owl directory, if not present");
    215   dir=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_CONFIG_DIR);
     234  dir=owl_global_get_confdir(&g);
    216235  mkdir(dir, S_IRWXU);
    217   owl_free(dir);
    218236
    219237  /* set the tty, either from the command line, or by figuring it out */
     
    697715{
    698716  fprintf(stderr, "Owl version %s\n", OWL_VERSION_STRING);
    699   fprintf(stderr, "Usage: owl [-n] [-d] [-D] [-v] [-h] [-c <configfile>] [-t <ttyname>]\n");
     717  fprintf(stderr, "Usage: owl [-n] [-d] [-D] [-v] [-h] [-c <configfile>] [-s <confdir>] [-t <ttyname>]\n");
    700718  fprintf(stderr, "  -n      don't load zephyr subscriptions\n");
    701719  fprintf(stderr, "  -d      enable debugging\n");
     
    704722  fprintf(stderr, "  -h      print this help message\n");
    705723  fprintf(stderr, "  -c      specify an alternate config file\n");
     724  fprintf(stderr, "  -s      specify an alternate config dir (default ~/.owl)\n");
    706725  fprintf(stderr, "  -t      set the tty name\n");
    707726}
  • owl.h

    r80e54a7 rb363d83  
    559559  char *thishost;
    560560  char *homedir;
     561  char *confdir;
     562  char *startupfile;
    561563  int direction;
    562564  int zaway;
  • perlglue.xs

    r13a3c1db rb363d83  
    199199get_data_dir ()
    200200        CODE:
    201                 RETVAL = (char *) DATADIR;
     201                RETVAL = (char *) owl_get_datadir();
    202202        OUTPUT:
    203203        RETVAL
     204
     205char *
     206get_config_dir ()
     207        CODE:
     208                RETVAL = (char *) owl_global_get_confdir(&g);
     209        OUTPUT:
     210        RETVAL 
    204211
    205212void
  • perlwrap.pm

    r42947f1 rb363d83  
    2121};
    2222
    23 use lib(get_data_dir()."/lib");
    24 use lib($ENV{HOME}."/.owl/lib");
    25 
     23use lib(get_data_dir() . "/lib");
     24use lib(get_config_dir() . "/lib");
     25
     26# perlconfig.c will set this to the value of the -c command-line
     27# switch, if present.
    2628our $configfile;
    2729
Note: See TracChangeset for help on using the changeset viewer.