tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
slang: respect TERMINFO_DIRS
Linus Heckemann
6 years ago
8bf5d3a3
1800e3ca
+174
2 changed files
expand all
collapse all
unified
split
pkgs
development
libraries
slang
default.nix
terminfo-dirs.patch
+2
pkgs/development/libraries/slang/default.nix
···
9
9
10
10
outputs = [ "out" "dev" "man" "doc" ];
11
11
12
12
+
patches = [ ./terminfo-dirs.patch ];
13
13
+
12
14
# Fix some wrong hardcoded paths
13
15
preConfigure = ''
14
16
sed -i -e "s|/usr/lib/terminfo|${ncurses.out}/lib/terminfo|" configure
+172
pkgs/development/libraries/slang/terminfo-dirs.patch
···
1
1
+
commit c7aa0c07b6522fbbb47ef47bd22f47f1611e7423
2
2
+
Author: John E. Davis <jed@jedsoft.org>
3
3
+
Date: Wed Nov 28 00:46:28 2018 -0500
4
4
+
5
5
+
pre2.3.3-5: Added support for TERMINFO_DIRS env var
6
6
+
7
7
+
Modified: removed changes to changelog and version number.
8
8
+
9
9
+
diff --git a/src/sltermin.c b/src/sltermin.c
10
10
+
index a06d0e4..65d3bbc 100644
11
11
+
--- a/src/sltermin.c
12
12
+
+++ b/src/sltermin.c
13
13
+
@@ -133,6 +133,9 @@ static FILE *open_terminfo (char *file, SLterminfo_Type *h)
14
14
+
unsigned char buf[12];
15
15
+
int magic;
16
16
+
17
17
+
+#ifdef SLANG_UNTIC
18
18
+
+ (void) fprintf (stdout,"# Trying %s\n", file);
19
19
+
+#endif
20
20
+
/* Alan Cox reported a security problem here if the application using the
21
21
+
* library is setuid. So, I need to make sure open the file as a normal
22
22
+
* user. Unfortunately, there does not appear to be a portable way of
23
23
+
@@ -269,10 +272,73 @@ static char *read_string_table (FILE *fp, SLterminfo_Type *t)
24
24
+
* are implemented by multiple links to the same compiled file.
25
25
+
*/
26
26
+
27
27
+
+static FILE *try_open_tidir (SLterminfo_Type *ti, const char *tidir, const char *term)
28
28
+
+{
29
29
+
+ char file[1024];
30
30
+
+
31
31
+
+ if (sizeof (file) > strlen (tidir) + 5 + strlen (term))
32
32
+
+ {
33
33
+
+ FILE *fp;
34
34
+
+
35
35
+
+ sprintf (file, "%s/%c/%s", tidir, *term, term);
36
36
+
+ if (NULL != (fp = open_terminfo (file, ti)))
37
37
+
+ return fp;
38
38
+
+
39
39
+
+ sprintf (file, "%s/%02x/%s", tidir, (unsigned char)*term, term);
40
40
+
+ if (NULL != (fp = open_terminfo (file, ti)))
41
41
+
+ return fp;
42
42
+
+ }
43
43
+
+
44
44
+
+ return NULL;
45
45
+
+}
46
46
+
+
47
47
+
+static FILE *try_open_env (SLterminfo_Type *ti, const char *term, const char *envvar)
48
48
+
+{
49
49
+
+ char *tidir;
50
50
+
+
51
51
+
+ if (NULL == (tidir = _pSLsecure_getenv (envvar)))
52
52
+
+ return NULL;
53
53
+
+
54
54
+
+ return try_open_tidir (ti, tidir, term);
55
55
+
+}
56
56
+
+
57
57
+
+static FILE *try_open_home (SLterminfo_Type *ti, const char *term)
58
58
+
+{
59
59
+
+ char home_ti[1024];
60
60
+
+ char *env;
61
61
+
+
62
62
+
+ if (NULL == (env = _pSLsecure_getenv ("HOME")))
63
63
+
+ return NULL;
64
64
+
+
65
65
+
+ strncpy (home_ti, env, sizeof (home_ti) - 11);
66
66
+
+ home_ti [sizeof(home_ti) - 11] = 0;
67
67
+
+ strcat (home_ti, "/.terminfo");
68
68
+
+
69
69
+
+ return try_open_tidir (ti, home_ti, term);
70
70
+
+}
71
71
+
+
72
72
+
+static FILE *try_open_env_path (SLterminfo_Type *ti, const char *term, const char *envvar)
73
73
+
+{
74
74
+
+ char tidir[1024];
75
75
+
+ char *env;
76
76
+
+ unsigned int i;
77
77
+
+
78
78
+
+ if (NULL == (env = _pSLsecure_getenv (envvar)))
79
79
+
+ return NULL;
80
80
+
+
81
81
+
+ i = 0;
82
82
+
+ while (-1 != SLextract_list_element (env, i, ':', tidir, sizeof(tidir)))
83
83
+
+ {
84
84
+
+ FILE *fp = try_open_tidir (ti, tidir, term);
85
85
+
+ if (fp != NULL) return fp;
86
86
+
+ i++;
87
87
+
+ }
88
88
+
+
89
89
+
+ return NULL;
90
90
+
+}
91
91
+
+
92
92
+
static SLCONST char *Terminfo_Dirs [] =
93
93
+
{
94
94
+
- "", /* $TERMINFO */
95
95
+
- "", /* $HOME/.terminfo */
96
96
+
#ifdef MISC_TERMINFO_DIRS
97
97
+
MISC_TERMINFO_DIRS,
98
98
+
#endif
99
99
+
@@ -287,6 +353,23 @@ static SLCONST char *Terminfo_Dirs [] =
100
100
+
NULL,
101
101
+
};
102
102
+
103
103
+
+static FILE *try_open_hardcoded (SLterminfo_Type *ti, const char *term)
104
104
+
+{
105
105
+
+ const char *tidir, **tidirs;
106
106
+
+
107
107
+
+ tidirs = Terminfo_Dirs;
108
108
+
+ while (NULL != (tidir = *tidirs++))
109
109
+
+ {
110
110
+
+ FILE *fp;
111
111
+
+
112
112
+
+ if ((*tidir != 0)
113
113
+
+ && (NULL != (fp = try_open_tidir (ti, tidir, term))))
114
114
+
+ return fp;
115
115
+
+ }
116
116
+
+
117
117
+
+ return NULL;
118
118
+
+}
119
119
+
+
120
120
+
void _pSLtt_tifreeent (SLterminfo_Type *t)
121
121
+
{
122
122
+
if (t == NULL)
123
123
+
@@ -305,11 +388,7 @@ void _pSLtt_tifreeent (SLterminfo_Type *t)
124
124
+
125
125
+
SLterminfo_Type *_pSLtt_tigetent (SLCONST char *term)
126
126
+
{
127
127
+
- SLCONST char **tidirs, *tidir;
128
128
+
FILE *fp = NULL;
129
129
+
- char file[1024];
130
130
+
- static char home_ti [1024];
131
131
+
- char *env;
132
132
+
SLterminfo_Type *ti;
133
133
+
134
134
+
if (
135
135
+
@@ -341,33 +420,10 @@ SLterminfo_Type *_pSLtt_tigetent (SLCONST char *term)
136
136
+
/* If we are on a termcap based system, use termcap */
137
137
+
if (0 == tcap_getent (term, ti)) return ti;
138
138
+
139
139
+
- if (NULL != (env = _pSLsecure_getenv ("TERMINFO")))
140
140
+
- Terminfo_Dirs[0] = env;
141
141
+
-
142
142
+
- if (NULL != (env = _pSLsecure_getenv ("HOME")))
143
143
+
- {
144
144
+
- strncpy (home_ti, env, sizeof (home_ti) - 11);
145
145
+
- home_ti [sizeof(home_ti) - 11] = 0;
146
146
+
- strcat (home_ti, "/.terminfo");
147
147
+
- Terminfo_Dirs [1] = home_ti;
148
148
+
- }
149
149
+
-
150
150
+
- tidirs = Terminfo_Dirs;
151
151
+
- while (NULL != (tidir = *tidirs++))
152
152
+
- {
153
153
+
- if (*tidir == 0)
154
154
+
- continue;
155
155
+
-
156
156
+
- if (sizeof (file) > strlen (tidir) + 5 + strlen (term))
157
157
+
- {
158
158
+
- sprintf (file, "%s/%c/%s", tidir, *term, term);
159
159
+
- if (NULL != (fp = open_terminfo (file, ti)))
160
160
+
- break;
161
161
+
- sprintf (file, "%s/%02x/%s", tidir, (unsigned char)*term, term);
162
162
+
- if (NULL != (fp = open_terminfo (file, ti)))
163
163
+
- break;
164
164
+
- }
165
165
+
- }
166
166
+
+ fp = try_open_env_path (ti, term, "TERMINFO_DIRS");
167
167
+
+ if (fp == NULL) fp = try_open_env (ti, term, "TERMINFO");
168
168
+
+ if (fp == NULL) fp = try_open_home (ti, term);
169
169
+
+ if (fp == NULL) fp = try_open_hardcoded (ti, term);
170
170
+
171
171
+
#ifdef SLANG_UNTIC
172
172
+
fp_open_label: