]> git.pld-linux.org Git - packages/screen.git/blob - screen-home_etc.patch
locate screenrc using $CONFIG_DIR
[packages/screen.git] / screen-home_etc.patch
1 diff -rNu screen-3.9.4-orig/Makefile.in screen-3.9.4/Makefile.in
2 --- screen-3.9.4-orig/Makefile.in       Wed Aug 11 22:19:51 1999
3 +++ screen-3.9.4/Makefile.in    Wed Feb  2 20:55:17 2000
4 @@ -55,12 +55,12 @@
5         search.c tty.c term.c window.c utmp.c loadav.c putenv.c help.c \
6         termcap.c input.c attacher.c pty.c process.c display.c comm.c \
7         kmapdef.c acls.c braille.c braille_tsi.c logfile.c layer.c \
8 -       sched.c teln.c nethack.c
9 +       sched.c teln.c nethack.c userdir.c
10  OFILES=        screen.o ansi.o fileio.o mark.o misc.o resize.o socket.o \
11         search.o tty.o term.o window.o utmp.o loadav.o putenv.o help.o \
12         termcap.o input.o attacher.o pty.o process.o display.o comm.o \
13         kmapdef.o acls.o braille.o braille_tsi.o logfile.o layer.o \
14 -       sched.o teln.o nethack.o
15 +       sched.o teln.o nethack.o userdir.o
16  
17  all:   screen
18  
19 @@ -270,7 +270,7 @@
20   comm.h layer.h term.h image.h display.h window.h braille.h extern.h \
21   logfile.h
22  fileio.o: fileio.c rcs.h config.h screen.h os.h osdef.h ansi.h acls.h \
23 - comm.h layer.h term.h image.h display.h window.h extern.h
24 + comm.h layer.h term.h image.h display.h window.h extern.h userdir.h
25  mark.o: mark.c rcs.h config.h screen.h os.h osdef.h ansi.h acls.h \
26   comm.h layer.h term.h image.h display.h window.h mark.h extern.h
27  misc.o: misc.c rcs.h config.h screen.h os.h osdef.h ansi.h acls.h \
28 diff -rNu screen-3.9.4-orig/config.h.in screen-3.9.4/config.h.in
29 --- screen-3.9.4-orig/config.h.in       Wed Aug 11 22:19:51 1999
30 +++ screen-3.9.4/config.h.in    Wed Feb  2 20:38:44 2000
31 @@ -55,7 +55,7 @@
32  
33  /*
34   * Screen sources two startup files. First a global file with a path
35 - * specified here, second your local $HOME/.screenrc
36 + * specified here, second your local $HOME/etc/screenrc
37   * Don't define this, if you don't want it.
38   */
39  #ifndef ETCSCREENRC
40 diff -rNu screen-3.9.4-orig/fileio.c screen-3.9.4/fileio.c
41 --- screen-3.9.4-orig/fileio.c  Mon Jul 26 19:51:02 1999
42 +++ screen-3.9.4/fileio.c       Wed Feb  2 21:02:40 2000
43 @@ -28,6 +28,7 @@
44  #include <sys/types.h>
45  #include <fcntl.h>
46  #include <sys/stat.h>
47 +#include <sys/param.h>
48  
49  #ifndef SIGINT
50  # include <signal.h>
51 @@ -36,6 +37,7 @@
52  #include "config.h" 
53  #include "screen.h"
54  #include "extern.h"
55 +#include "userdir.h"
56  
57  extern struct display *display, *displays;
58  extern struct win *fore;
59 @@ -94,8 +96,9 @@
60  findrcfile(rcfile)
61  char *rcfile;
62  {
63 -  static char buf[256];
64 +  static char buf[MAXPATHLEN];
65    char *rc, *p;
66 +  struct cfv etcfile;
67  
68    if (rcfile)
69      {
70 @@ -112,11 +115,22 @@
71         }
72        else
73         {
74 -         debug("  ...nothing in $SCREENRC, defaulting $HOME/.screenrc\n");
75 -         if (strlen(home) > sizeof(buf) - 12)
76 -           Panic(0, "Rc: home too large");
77 -         sprintf(buf, "%s/.screenrc", home);
78 -         rc = SaveStr(buf);
79 +         debug("  ...nothing in $SCREENRC, defaulting $HOME/etc/screenrc\n");
80 +         etcfile.variable = "CONFIG_DIR";
81 +          etcfile.home_dir = NULL;
82 +          etcfile.home_scd = NULL; 
83 +          etcfile.subname = "screenrc";
84 +          etcfile.prefix = "."; 
85 +          etcfile.suffix = ""; 
86 +          etcfile.mode = M_REGULAR_FILE; 
87 +          if ((usercfv (&etcfile)) == -1) {
88 +               if (strlen(home) > sizeof(buf) - 12)
89 +                   Panic(0, "Rc: home too large");
90 +               sprintf(buf, "%s/.screenrc", home);
91 +               rc = SaveStr(buf);
92 +         }   
93 +         else 
94 +               rc = SaveStr(etcfile.result); 
95         }
96      }
97    return rc;
98 diff -rNu screen-3.9.4-orig/userdir.c screen-3.9.4/userdir.c
99 --- screen-3.9.4-orig/userdir.c Thu Jan  1 01:00:00 1970
100 +++ screen-3.9.4/userdir.c      Wed Feb  2 00:18:04 2000
101 @@ -0,0 +1,92 @@
102 +#include "userdir.h"
103 +    
104 +static char *nonulhome = "";
105 +
106 +/******************************************************************************/
107 +    
108 +int getusercfv (char *variable, 
109 +                   char *home_dir, 
110 +                   char *user_dir, 
111 +                   size_t stringsize)
112 +       {
113 +       struct stat st;
114 +       char *d;
115 +       
116 +       bzero (user_dir, stringsize);
117 +       if (variable == NULL || *variable == '\0') return (-1);
118 +       if (home_dir == NULL) home_dir = nonulhome;
119 +       d = getenv (variable);  
120 +       if (d == NULL || *d == '\0') return (-1);
121 +       if (*d == '/') 
122 +           {
123 +           strncpy (user_dir, d, stringsize-1);
124 +           }
125 +       else
126 +           {
127 +           snprintf (user_dir, stringsize-1, "%s/%s", home_dir, d);
128 +           }
129 +           
130 +       if (stat(user_dir,&st) != -1 && S_ISDIR(st.st_mode)) 
131 +           {
132 +           return (0);
133 +           }
134 +       
135 +       return (-1);
136 +       }
137 +
138 +/******************************************************************************/
139 +
140 +int usercfv (struct cfv *CFV)
141 +       {
142 +       int gr;
143 +       struct stat st;
144 +       char *p;
145 +       
146 +       if (CFV->subname == NULL) CFV->subname = nonulhome;
147 +       if (CFV->home_dir == NULL) CFV->home_dir = getenv ("HOME");
148 +       if (CFV->home_dir == NULL) CFV->home_dir = CFV->home_scd;
149 +       if (CFV->home_dir == NULL) return (-1);
150 +       
151 +       gr = getusercfv (CFV->variable, 
152 +                       CFV->home_dir, 
153 +                       CFV->result,
154 +                       MAXPATHLEN);
155 +                       
156 +       if (gr != -1)   /* have main directory */
157 +           {
158 +           if ((p = strrchr(CFV->result, '/')) && *(p+1) == '\0') 
159 +               p = '\0';
160 +           snprintf ((rindex(CFV->result,'\0')), MAXPATHLEN-1, "/%s", CFV->subname);
161 +           if (stat( CFV->result,&st) != -1 
162 +                && CFV->mode ? S_ISDIR(st.st_mode) : S_ISREG(st.st_mode)) /* have file or dir */
163 +               return (1);
164 +           }
165 +
166 +       /* don't have main directory or a proper variable set */
167 +       
168 +       if (CFV->home_dir == NULL || *(CFV->home_dir) == '\0') return (-1);
169 +       if (CFV->prefix == NULL && CFV->suffix == NULL) return (-1);
170 +       snprintf (CFV->result, MAXPATHLEN-1, "%s/%s%s%s", 
171 +                      CFV->home_dir, 
172 +                      CFV->prefix? CFV->prefix:"",
173 +                      CFV->subname,
174 +                      CFV->suffix? CFV->suffix:"");
175 +       if (stat(CFV->result,&st) != -1 
176 +                && CFV->mode ? S_ISDIR(st.st_mode) : S_ISREG(st.st_mode)) /* have file or dir */
177 +               return (2);
178 +       return (-1);
179 +       }
180 +       
181 +/******************************************************************************/
182 +       
183 +FILE *fopencfv (struct cfv *CFV, const char *mode)
184 +    {
185 +    FILE *cfvfile = NULL;
186 +    
187 +    CFV->mode = M_REGULAR_FILE;
188 +    if ((usercfv (CFV)) == -1) return (NULL);  
189 +    cfvfile = fopen (CFV->result, mode);
190 +    return (cfvfile);
191 +    }
192 +    
193 +/******************************************************************************/
194 \ No newline at end of file
195 diff -rNu screen-3.9.4-orig/userdir.h screen-3.9.4/userdir.h
196 --- screen-3.9.4-orig/userdir.h Thu Jan  1 01:00:00 1970
197 +++ screen-3.9.4/userdir.h      Wed Feb  2 00:18:04 2000
198 @@ -0,0 +1,35 @@
199 +#ifndef USERDIR__H
200 +#define USERDIR__H
201 +
202 +#include <unistd.h>
203 +#include <string.h>
204 +#include <stdio.h>
205 +#include <stdlib.h>
206 +#include <sys/types.h>
207 +#include <sys/stat.h>
208 +#include <sys/param.h>
209 +
210 +#define        M_REGULAR_FILE  0
211 +#define        M_DIRECTORY     1
212 +
213 +struct cfv {
214 +       char result[MAXPATHLEN];        /* our result                   */
215 +       char *variable; /* name of an environment variable              */
216 +       char *home_dir; /* home directory or NULL for autodetect        */
217 +       char *home_scd; /* directory if home_dir==NULL and no result    */
218 +       char *subname;  /* core name of a file/directory                */
219 +       char *prefix;   /* prefix when using directly home_dir          */
220 +       char *suffix;   /* suffix when using directly home_dir          */
221 +       int mode;       /* expected: M_REGULAR_FILE or M_DIRECTORY      */
222 +       };
223 +
224 +int getusercfv (char *variable, 
225 +                   char *home_dir, 
226 +                   char *user_dir,
227 +                   size_t stringsize);
228 +
229 +int usercfv (struct cfv *CFV);
230 +
231 +FILE *fopencfv (struct cfv *CFV, const char *mode);
232 +
233 +#endif
234 \ No newline at end of file
This page took 0.079792 seconds and 4 git commands to generate.