diff -rNu screen-3.9.4-orig/Makefile.in screen-3.9.4/Makefile.in --- screen-3.9.4-orig/Makefile.in Wed Aug 11 22:19:51 1999 +++ screen-3.9.4/Makefile.in Wed Feb 2 20:55:17 2000 @@ -55,12 +55,12 @@ search.c tty.c term.c window.c utmp.c loadav.c putenv.c help.c \ termcap.c input.c attacher.c pty.c process.c display.c comm.c \ kmapdef.c acls.c braille.c braille_tsi.c logfile.c layer.c \ - sched.c teln.c nethack.c + sched.c teln.c nethack.c userdir.c OFILES= screen.o ansi.o fileio.o mark.o misc.o resize.o socket.o \ search.o tty.o term.o window.o utmp.o loadav.o putenv.o help.o \ termcap.o input.o attacher.o pty.o process.o display.o comm.o \ kmapdef.o acls.o braille.o braille_tsi.o logfile.o layer.o \ - sched.o teln.o nethack.o + sched.o teln.o nethack.o userdir.o all: screen @@ -270,7 +270,7 @@ comm.h layer.h term.h image.h display.h window.h braille.h extern.h \ logfile.h fileio.o: fileio.c rcs.h config.h screen.h os.h osdef.h ansi.h acls.h \ - comm.h layer.h term.h image.h display.h window.h extern.h + comm.h layer.h term.h image.h display.h window.h extern.h userdir.h mark.o: mark.c rcs.h config.h screen.h os.h osdef.h ansi.h acls.h \ comm.h layer.h term.h image.h display.h window.h mark.h extern.h misc.o: misc.c rcs.h config.h screen.h os.h osdef.h ansi.h acls.h \ diff -rNu screen-3.9.4-orig/config.h.in screen-3.9.4/config.h.in --- screen-3.9.4-orig/config.h.in Wed Aug 11 22:19:51 1999 +++ screen-3.9.4/config.h.in Wed Feb 2 20:38:44 2000 @@ -55,7 +55,7 @@ /* * Screen sources two startup files. First a global file with a path - * specified here, second your local $HOME/.screenrc + * specified here, second your local $HOME/etc/screenrc * Don't define this, if you don't want it. */ #ifndef ETCSCREENRC diff -rNu screen-3.9.4-orig/fileio.c screen-3.9.4/fileio.c --- screen-3.9.4-orig/fileio.c Mon Jul 26 19:51:02 1999 +++ screen-3.9.4/fileio.c Wed Feb 2 21:02:40 2000 @@ -28,6 +28,7 @@ #include #include #include +#include #ifndef SIGINT # include @@ -36,6 +37,7 @@ #include "config.h" #include "screen.h" #include "extern.h" +#include "userdir.h" extern struct display *display, *displays; extern struct win *fore; @@ -94,8 +96,9 @@ findrcfile(rcfile) char *rcfile; { - static char buf[256]; + static char buf[MAXPATHLEN]; char *rc, *p; + struct cfv etcfile; if (rcfile) { @@ -112,11 +115,22 @@ } else { - debug(" ...nothing in $SCREENRC, defaulting $HOME/.screenrc\n"); - if (strlen(home) > sizeof(buf) - 12) - Panic(0, "Rc: home too large"); - sprintf(buf, "%s/.screenrc", home); - rc = SaveStr(buf); + debug(" ...nothing in $SCREENRC, defaulting $HOME/etc/screenrc\n"); + etcfile.variable = "CONFIG_DIR"; + etcfile.home_dir = NULL; + etcfile.home_scd = NULL; + etcfile.subname = "screenrc"; + etcfile.prefix = "."; + etcfile.suffix = ""; + etcfile.mode = M_REGULAR_FILE; + if ((usercfv (&etcfile)) == -1) { + if (strlen(home) > sizeof(buf) - 12) + Panic(0, "Rc: home too large"); + sprintf(buf, "%s/.screenrc", home); + rc = SaveStr(buf); + } + else + rc = SaveStr(etcfile.result); } } return rc; diff -rNu screen-3.9.4-orig/userdir.c screen-3.9.4/userdir.c --- screen-3.9.4-orig/userdir.c Thu Jan 1 01:00:00 1970 +++ screen-3.9.4/userdir.c Wed Feb 2 00:18:04 2000 @@ -0,0 +1,92 @@ +#include "userdir.h" + +static char *nonulhome = ""; + +/******************************************************************************/ + +int getusercfv (char *variable, + char *home_dir, + char *user_dir, + size_t stringsize) + { + struct stat st; + char *d; + + bzero (user_dir, stringsize); + if (variable == NULL || *variable == '\0') return (-1); + if (home_dir == NULL) home_dir = nonulhome; + d = getenv (variable); + if (d == NULL || *d == '\0') return (-1); + if (*d == '/') + { + strncpy (user_dir, d, stringsize-1); + } + else + { + snprintf (user_dir, stringsize-1, "%s/%s", home_dir, d); + } + + if (stat(user_dir,&st) != -1 && S_ISDIR(st.st_mode)) + { + return (0); + } + + return (-1); + } + +/******************************************************************************/ + +int usercfv (struct cfv *CFV) + { + int gr; + struct stat st; + char *p; + + if (CFV->subname == NULL) CFV->subname = nonulhome; + if (CFV->home_dir == NULL) CFV->home_dir = getenv ("HOME"); + if (CFV->home_dir == NULL) CFV->home_dir = CFV->home_scd; + if (CFV->home_dir == NULL) return (-1); + + gr = getusercfv (CFV->variable, + CFV->home_dir, + CFV->result, + MAXPATHLEN); + + if (gr != -1) /* have main directory */ + { + if ((p = strrchr(CFV->result, '/')) && *(p+1) == '\0') + p = '\0'; + snprintf ((rindex(CFV->result,'\0')), MAXPATHLEN-1, "/%s", CFV->subname); + if (stat( CFV->result,&st) != -1 + && CFV->mode ? S_ISDIR(st.st_mode) : S_ISREG(st.st_mode)) /* have file or dir */ + return (1); + } + + /* don't have main directory or a proper variable set */ + + if (CFV->home_dir == NULL || *(CFV->home_dir) == '\0') return (-1); + if (CFV->prefix == NULL && CFV->suffix == NULL) return (-1); + snprintf (CFV->result, MAXPATHLEN-1, "%s/%s%s%s", + CFV->home_dir, + CFV->prefix? CFV->prefix:"", + CFV->subname, + CFV->suffix? CFV->suffix:""); + if (stat(CFV->result,&st) != -1 + && CFV->mode ? S_ISDIR(st.st_mode) : S_ISREG(st.st_mode)) /* have file or dir */ + return (2); + return (-1); + } + +/******************************************************************************/ + +FILE *fopencfv (struct cfv *CFV, const char *mode) + { + FILE *cfvfile = NULL; + + CFV->mode = M_REGULAR_FILE; + if ((usercfv (CFV)) == -1) return (NULL); + cfvfile = fopen (CFV->result, mode); + return (cfvfile); + } + +/******************************************************************************/ \ No newline at end of file diff -rNu screen-3.9.4-orig/userdir.h screen-3.9.4/userdir.h --- screen-3.9.4-orig/userdir.h Thu Jan 1 01:00:00 1970 +++ screen-3.9.4/userdir.h Wed Feb 2 00:18:04 2000 @@ -0,0 +1,35 @@ +#ifndef USERDIR__H +#define USERDIR__H + +#include +#include +#include +#include +#include +#include +#include + +#define M_REGULAR_FILE 0 +#define M_DIRECTORY 1 + +struct cfv { + char result[MAXPATHLEN]; /* our result */ + char *variable; /* name of an environment variable */ + char *home_dir; /* home directory or NULL for autodetect */ + char *home_scd; /* directory if home_dir==NULL and no result */ + char *subname; /* core name of a file/directory */ + char *prefix; /* prefix when using directly home_dir */ + char *suffix; /* suffix when using directly home_dir */ + int mode; /* expected: M_REGULAR_FILE or M_DIRECTORY */ + }; + +int getusercfv (char *variable, + char *home_dir, + char *user_dir, + size_t stringsize); + +int usercfv (struct cfv *CFV); + +FILE *fopencfv (struct cfv *CFV, const char *mode); + +#endif \ No newline at end of file