1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: misc.c |
2 | * File: misc.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: misc.C,v 1.3 2004/01/31 00:20:21 pcg Exp $ |
|
|
5 | * |
4 | * |
6 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
7 | * Copyright (c) 1996 mj olesen <olesen@me.QueensU.CA> Queen's Univ at Kingston |
6 | * Copyright (c) 1996 mj olesen <olesen@me.QueensU.CA> Queen's Univ at Kingston |
8 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
7 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
9 | * Copyright (c) 1998-2000 Geoff Wing <gcw@pobox.com> |
8 | * Copyright (c) 1998-2000 Geoff Wing <gcw@pobox.com> |
|
|
9 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
10 | * |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License as published by |
12 | * it under the terms of the GNU General Public License as published by |
13 | * the Free Software Foundation; either version 2 of the License, or |
13 | * the Free Software Foundation; either version 2 of the License, or |
14 | * (at your option) any later version. |
14 | * (at your option) any later version. |
… | |
… | |
25 | |
25 | |
26 | #include "../config.h" /* NECESSARY */ |
26 | #include "../config.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
28 | #include "misc.intpro" /* PROTOS for internal routines */ |
28 | #include "misc.intpro" /* PROTOS for internal routines */ |
29 | |
29 | |
30 | /* EXTPROTO */ |
30 | /* INTPROTO */ |
|
|
31 | char * |
|
|
32 | rxvt_wcstombs (const wchar_t *str, int len) |
|
|
33 | { |
|
|
34 | mbstate mbs; |
|
|
35 | char *r = (char *)rxvt_malloc (len * MB_CUR_MAX + 1); |
|
|
36 | |
|
|
37 | char *dst = r; |
|
|
38 | while (len--) |
|
|
39 | { |
|
|
40 | int l = wcrtomb (dst, *str++, mbs); |
|
|
41 | if (l < 0) |
|
|
42 | *dst++ = '?'; |
|
|
43 | else |
|
|
44 | dst += l; |
|
|
45 | } |
|
|
46 | |
|
|
47 | *dst++ = 0; |
|
|
48 | |
|
|
49 | return r; |
|
|
50 | } |
|
|
51 | |
|
|
52 | /* INTPROTO */ |
31 | char * |
53 | char * |
32 | rxvt_strdup (const char *str) |
54 | rxvt_strdup (const char *str) |
33 | { |
55 | { |
34 | return str ? strdup (str) : 0; |
56 | return str ? strdup (str) : 0; |
35 | } |
57 | } |
36 | |
58 | |
37 | /* EXTPROTO */ |
59 | /* INTPROTO */ |
38 | char * |
60 | char * |
39 | rxvt_r_basename(const char *str) |
61 | rxvt_r_basename (const char *str) |
40 | { |
62 | { |
41 | char *base = STRRCHR(str, '/'); |
63 | char *base = strrchr (str, '/'); |
42 | |
64 | |
43 | return (char *)(base ? base + 1 : str); |
65 | return (char *) (base ? base + 1 : str); |
44 | } |
66 | } |
45 | |
67 | |
46 | /* |
68 | /* |
47 | * Print an error message |
69 | * Print an error message |
48 | */ |
70 | */ |
49 | /* EXTPROTO */ |
71 | /* INTPROTO */ |
50 | void |
72 | void |
|
|
73 | rxvt_vlog (const char *fmt, va_list arg_ptr) |
|
|
74 | { |
|
|
75 | char msg[1024]; |
|
|
76 | |
|
|
77 | vsnprintf (msg, sizeof msg, fmt, arg_ptr); |
|
|
78 | |
|
|
79 | if (GET_R && GET_R->log_hook) |
|
|
80 | (*GET_R->log_hook) (msg); |
|
|
81 | else |
|
|
82 | write (STDOUT_FILENO, msg, strlen (msg)); |
|
|
83 | } |
|
|
84 | |
|
|
85 | /* INTPROTO */ |
|
|
86 | void |
51 | rxvt_print_error(const char *fmt,...) |
87 | rxvt_log (const char *fmt,...) |
52 | { |
88 | { |
53 | va_list arg_ptr; |
89 | va_list arg_ptr; |
54 | |
90 | |
55 | va_start(arg_ptr, fmt); |
91 | va_start (arg_ptr, fmt); |
56 | fprintf(stderr, APL_NAME ": "); |
92 | rxvt_vlog (fmt, arg_ptr); |
57 | vfprintf(stderr, fmt, arg_ptr); |
|
|
58 | fprintf(stderr, "\n"); |
|
|
59 | va_end(arg_ptr); |
93 | va_end (arg_ptr); |
|
|
94 | } |
|
|
95 | |
|
|
96 | /* |
|
|
97 | * Print an error message |
|
|
98 | */ |
|
|
99 | /* INTPROTO */ |
|
|
100 | void |
|
|
101 | rxvt_warn (const char *fmt,...) |
|
|
102 | { |
|
|
103 | va_list arg_ptr; |
|
|
104 | |
|
|
105 | rxvt_log ("%s: ", RESNAME); |
|
|
106 | |
|
|
107 | va_start (arg_ptr, fmt); |
|
|
108 | rxvt_vlog (fmt, arg_ptr); |
|
|
109 | va_end (arg_ptr); |
|
|
110 | } |
|
|
111 | |
|
|
112 | /* INTPROTO */ |
|
|
113 | void |
|
|
114 | rxvt_fatal (const char *fmt,...) |
|
|
115 | { |
|
|
116 | va_list arg_ptr; |
|
|
117 | |
|
|
118 | rxvt_log ("%s: ", RESNAME); |
|
|
119 | |
|
|
120 | va_start (arg_ptr, fmt); |
|
|
121 | rxvt_vlog (fmt, arg_ptr); |
|
|
122 | va_end (arg_ptr); |
|
|
123 | |
|
|
124 | rxvt_exit_failure (); |
|
|
125 | } |
|
|
126 | |
|
|
127 | class rxvt_failure_exception rxvt_failure_exception; |
|
|
128 | |
|
|
129 | /* INTPROTO */ |
|
|
130 | void |
|
|
131 | rxvt_exit_failure () |
|
|
132 | { |
|
|
133 | throw (rxvt_failure_exception); |
60 | } |
134 | } |
61 | |
135 | |
62 | /* |
136 | /* |
63 | * check that the first characters of S1 match S2 |
137 | * check that the first characters of S1 match S2 |
64 | * |
138 | * |
65 | * No Match |
139 | * No Match |
66 | * return: 0 |
140 | * return: 0 |
67 | * Match |
141 | * Match |
68 | * return: STRLEN (S2) |
142 | * return: strlen (S2) |
69 | */ |
143 | */ |
70 | /* EXTPROTO */ |
144 | /* INTPROTO */ |
71 | int |
145 | int |
72 | rxvt_Str_match(const char *s1, const char *s2) |
146 | rxvt_Str_match (const char *s1, const char *s2) |
73 | { |
147 | { |
74 | int n = STRLEN(s2); |
148 | int n = strlen (s2); |
75 | |
149 | |
76 | return ((STRNCMP(s1, s2, n) == 0) ? n : 0); |
150 | return ((strncmp (s1, s2, n) == 0) ? n : 0); |
77 | } |
151 | } |
78 | |
152 | |
79 | /* EXTPROTO */ |
153 | /* INTPROTO */ |
80 | const char * |
154 | const char * |
81 | rxvt_Str_skip_space(const char *str) |
155 | rxvt_Str_skip_space (const char *str) |
82 | { |
156 | { |
83 | if (str) |
157 | if (str) |
84 | while (*str && isspace(*str)) |
158 | while (*str && isspace (*str)) |
85 | str++; |
159 | str++; |
|
|
160 | |
86 | return str; |
161 | return str; |
87 | } |
162 | } |
88 | |
163 | |
89 | /* |
164 | /* |
90 | * remove leading/trailing space and strip-off leading/trailing quotes. |
165 | * remove leading/trailing space and strip-off leading/trailing quotes. |
91 | * in place. |
166 | * in place. |
92 | */ |
167 | */ |
93 | /* EXTPROTO */ |
168 | /* INTPROTO */ |
94 | char * |
169 | char * |
95 | rxvt_Str_trim(char *str) |
170 | rxvt_Str_trim (char *str) |
96 | { |
171 | { |
97 | char *r, *s; |
172 | char *r, *s; |
98 | int n; |
173 | int n; |
99 | |
174 | |
100 | if (!str || !*str) /* shortcut */ |
175 | if (!str || !*str) /* shortcut */ |
101 | return str; |
|
|
102 | |
|
|
103 | /* skip leading spaces */ |
|
|
104 | for (s = str; *s && isspace(*s); s++) ; |
|
|
105 | /* goto end of string */ |
|
|
106 | for (n = 0, r = s; *r++; n++) ; |
|
|
107 | r -= 2; |
|
|
108 | /* dump return */ |
|
|
109 | if (n > 0 && *r == '\n') |
|
|
110 | n--, r--; |
|
|
111 | /* backtrack along trailing spaces */ |
|
|
112 | for (; n > 0 && isspace(*r); r--, n--) ; |
|
|
113 | /* skip matching leading/trailing quotes */ |
|
|
114 | if (*s == '"' && *r == '"' && n > 1) { |
|
|
115 | s++; |
|
|
116 | n -= 2; |
|
|
117 | } |
|
|
118 | /* copy back over: forwards copy */ |
|
|
119 | for (r = str; n; n--) |
|
|
120 | *r++ = *s++; |
|
|
121 | *r = '\0'; |
|
|
122 | |
|
|
123 | return str; |
176 | return str; |
|
|
177 | |
|
|
178 | /* skip leading spaces */ |
|
|
179 | for (s = str; *s && isspace (*s); s++) ; |
|
|
180 | /* goto end of string */ |
|
|
181 | for (n = 0, r = s; *r++; n++) ; |
|
|
182 | r -= 2; |
|
|
183 | /* dump return */ |
|
|
184 | if (n > 0 && *r == '\n') |
|
|
185 | n--, r--; |
|
|
186 | /* backtrack along trailing spaces */ |
|
|
187 | for (; n > 0 && isspace (*r); r--, n--) ; |
|
|
188 | /* skip matching leading/trailing quotes */ |
|
|
189 | if (*s == '"' && *r == '"' && n > 1) |
|
|
190 | { |
|
|
191 | s++; |
|
|
192 | n -= 2; |
|
|
193 | } |
|
|
194 | |
|
|
195 | /* copy back over: forwards copy */ |
|
|
196 | for (r = str; n; n--) |
|
|
197 | *r++ = *s++; |
|
|
198 | *r = '\0'; |
|
|
199 | |
|
|
200 | return str; |
124 | } |
201 | } |
125 | |
202 | |
126 | /* |
203 | /* |
127 | * in-place interpretation of string: |
204 | * in-place interpretation of string: |
128 | * |
205 | * |
… | |
… | |
135 | * "M-x" prefixed strings, append "\r" if needed |
212 | * "M-x" prefixed strings, append "\r" if needed |
136 | * "\E]" prefixed strings (XTerm escape sequence) append ST if needed |
213 | * "\E]" prefixed strings (XTerm escape sequence) append ST if needed |
137 | * |
214 | * |
138 | * returns the converted string length |
215 | * returns the converted string length |
139 | */ |
216 | */ |
140 | /* EXTPROTO */ |
217 | /* INTPROTO */ |
141 | int |
218 | int |
142 | rxvt_Str_escaped(char *str) |
219 | rxvt_Str_escaped (char *str) |
143 | { |
220 | { |
144 | char ch, *s, *d; |
221 | char ch, *s, *d; |
145 | int i, num, append = 0; |
222 | int i, num, append = 0; |
146 | |
223 | |
147 | if (!str || !*str) |
224 | if (!str || !*str) |
148 | return 0; |
225 | return 0; |
149 | |
226 | |
150 | d = s = str; |
227 | d = s = str; |
151 | |
228 | |
152 | if (*s == 'M' && s[1] == '-') { |
229 | if (*s == 'M' && s[1] == '-') |
|
|
230 | { |
153 | /* Emacs convenience, replace leading `M-..' with `\E..' */ |
231 | /* Emacs convenience, replace leading `M-..' with `\E..' */ |
154 | *d++ = C0_ESC; |
232 | *d++ = C0_ESC; |
155 | s += 2; |
233 | s += 2; |
156 | if (toupper(*s) == 'X') |
234 | if (toupper (*s) == 'X') |
157 | /* append carriage-return for `M-xcommand' */ |
235 | /* append carriage-return for `M-xcommand' */ |
158 | for (*d++ = 'x', append = '\r', s++; isspace(*s); s++) ; |
236 | for (*d++ = 'x', append = '\r', s++; isspace (*s); s++) ; |
159 | } |
237 | } |
160 | for (; (ch = *s++);) { |
238 | for (; (ch = *s++);) |
|
|
239 | { |
161 | if (ch == '\\') { |
240 | if (ch == '\\') |
|
|
241 | { |
162 | ch = *s++; |
242 | ch = *s++; |
163 | if (ch >= '0' && ch <= '7') { /* octal */ |
243 | if (ch >= '0' && ch <= '7') |
164 | num = ch - '0'; |
244 | { /* octal */ |
|
|
245 | num = ch - '0'; |
165 | for (i = 0; i < 2; i++, s++) { |
246 | for (i = 0; i < 2; i++, s++) |
166 | ch = *s; |
247 | { |
|
|
248 | ch = *s; |
167 | if (ch < '0' || ch > '7') |
249 | if (ch < '0' || ch > '7') |
168 | break; |
250 | break; |
169 | num = num * 8 + ch - '0'; |
251 | num = num * 8 + ch - '0'; |
170 | } |
252 | } |
171 | ch = (char)num; |
253 | ch = (char)num; |
172 | } else if (ch == 'a') |
254 | } |
|
|
255 | else if (ch == 'a') |
173 | ch = C0_BEL; /* bell */ |
256 | ch = C0_BEL; /* bell */ |
174 | else if (ch == 'b') |
257 | else if (ch == 'b') |
175 | ch = C0_BS; /* backspace */ |
258 | ch = C0_BS; /* backspace */ |
176 | else if (ch == 'E' || ch == 'e') |
259 | else if (ch == 'E' || ch == 'e') |
177 | ch = C0_ESC; /* escape */ |
260 | ch = C0_ESC; /* escape */ |
|
|
261 | else if (ch == 'n') |
|
|
262 | ch = '\n'; /* newline */ |
|
|
263 | else if (ch == 'r') |
|
|
264 | ch = '\r'; /* carriage-return */ |
|
|
265 | else if (ch == 't') |
|
|
266 | ch = C0_HT; /* tab */ |
|
|
267 | } |
178 | else if (ch == 'n') |
268 | else if (ch == '^') |
179 | ch = '\n'; /* newline */ |
269 | { |
180 | else if (ch == 'r') |
|
|
181 | ch = '\r'; /* carriage-return */ |
|
|
182 | else if (ch == 't') |
|
|
183 | ch = C0_HT; /* tab */ |
|
|
184 | } else if (ch == '^') { |
|
|
185 | ch = *s++; |
270 | ch = *s++; |
186 | ch = toupper(ch); |
271 | ch = toupper (ch); |
187 | ch = (ch == '?' ? 127 : (ch - '@')); |
272 | ch = (ch == '?' ? 127 : (ch - '@')); |
188 | } |
273 | } |
189 | *d++ = ch; |
274 | *d++ = ch; |
190 | } |
275 | } |
191 | |
276 | |
192 | /* ESC] is an XTerm escape sequence, must be terminated */ |
277 | /* ESC] is an XTerm escape sequence, must be terminated */ |
193 | if (*str == '\0' && str[1] == C0_ESC && str[2] == ']') |
278 | if (*str == '\0' && str[1] == C0_ESC && str[2] == ']') |
194 | append = CHAR_ST; |
279 | append = CHAR_ST; |
195 | |
280 | |
196 | /* add trailing character as required */ |
281 | /* add trailing character as required */ |
197 | if (append && d[-1] != append) |
282 | if (append && d[-1] != append) |
198 | *d++ = append; |
283 | *d++ = append; |
199 | *d = '\0'; |
284 | *d = '\0'; |
200 | |
285 | |
201 | return (d - str); |
286 | return (d - str); |
202 | } |
287 | } |
203 | |
288 | |
204 | /* |
289 | /* |
205 | * Split a comma-separated string into an array, stripping leading and |
290 | * Split a comma-separated string into an array, stripping leading and |
206 | * trailing spaces (and paired quotes) from each entry. Empty strings |
291 | * trailing spaces (and paired quotes) from each entry. Empty strings |
207 | * are properly returned |
292 | * are properly returned |
208 | * Caller should free each entry and array when done |
293 | * Caller should free each entry and array when done |
209 | */ |
294 | */ |
210 | /* EXTPROTO */ |
295 | /* INTPROTO */ |
211 | char ** |
296 | char ** |
212 | rxvt_splitcommastring(const char *cs) |
297 | rxvt_splitcommastring (const char *cs) |
213 | { |
298 | { |
214 | int l, n, p; |
299 | int l, n, p; |
215 | const char *s, *t; |
300 | const char *s, *t; |
216 | char **ret; |
301 | char **ret; |
217 | |
302 | |
218 | if ((s = cs) == NULL) |
303 | if ((s = cs) == NULL) |
219 | s = ""; |
304 | s = ""; |
220 | |
305 | |
221 | for (n = 1, t = s; *t; t++) |
306 | for (n = 1, t = s; *t; t++) |
222 | if (*t == ',') |
307 | if (*t == ',') |
223 | n++; |
308 | n++; |
224 | ret = (char **)malloc((n + 1) * sizeof(char *)); |
309 | ret = (char **)malloc ((n + 1) * sizeof (char *)); |
225 | ret[n] = NULL; |
310 | ret[n] = NULL; |
226 | |
311 | |
227 | for (l = 0, t = s; l < n; l++) { |
312 | for (l = 0, t = s; l < n; l++) |
|
|
313 | { |
228 | for ( ; *t && *t != ','; t++) ; |
314 | for ( ; *t && *t != ','; t++) ; |
229 | p = t - s; |
315 | p = t - s; |
230 | ret[l] = (char *)malloc(p + 1); |
316 | ret[l] = (char *)malloc (p + 1); |
231 | strncpy(ret[l], s, p); |
317 | strncpy (ret[l], s, p); |
232 | ret[l][p] = '\0'; |
318 | ret[l][p] = '\0'; |
233 | rxvt_Str_trim(ret[l]); |
319 | rxvt_Str_trim (ret[l]); |
234 | s = ++t; |
320 | s = ++t; |
235 | } |
321 | } |
236 | return ret; |
322 | return ret; |
237 | } |
323 | } |
238 | |
324 | |
239 | /*----------------------------------------------------------------------* |
325 | /*----------------------------------------------------------------------* |
240 | * file searching |
326 | * file searching |
241 | */ |
327 | */ |
… | |
… | |
249 | * |
335 | * |
250 | * FILE is either semi-colon or zero terminated |
336 | * FILE is either semi-colon or zero terminated |
251 | */ |
337 | */ |
252 | /* INTPROTO */ |
338 | /* INTPROTO */ |
253 | char * |
339 | char * |
254 | rxvt_File_search_path(const char *pathlist, const char *file, const char *ext) |
340 | rxvt_File_search_path (const char *pathlist, const char *file, const char *ext) |
255 | { |
341 | { |
256 | int maxpath, len; |
342 | int maxpath, len; |
257 | const char *p, *path; |
343 | const char *p, *path; |
258 | char name[256]; |
344 | char name[256]; |
259 | |
345 | |
260 | if (!access(file, R_OK)) /* found (plain name) in current directory */ |
346 | if (!access (file, R_OK)) /* found (plain name) in current directory */ |
261 | return STRDUP(file); |
347 | return strdup (file); |
262 | |
348 | |
263 | /* semi-colon delimited */ |
349 | /* semi-colon delimited */ |
264 | if ((p = STRCHR(file, ';'))) |
350 | if ((p = strchr (file, ';'))) |
265 | len = (p - file); |
351 | len = (p - file); |
266 | else |
352 | else |
267 | len = STRLEN(file); |
353 | len = strlen (file); |
268 | |
354 | |
269 | #ifdef DEBUG_SEARCH_PATH |
355 | #ifdef DEBUG_SEARCH_PATH |
270 | getcwd(name, sizeof(name)); |
356 | getcwd (name, sizeof (name)); |
271 | fprintf(stderr, "pwd: \"%s\"\n", name); |
357 | fprintf (stderr, "pwd: \"%s\"\n", name); |
272 | fprintf(stderr, "find: \"%.*s\"\n", len, file); |
358 | fprintf (stderr, "find: \"%.*s\"\n", len, file); |
273 | #endif |
359 | #endif |
274 | |
360 | |
275 | /* leave room for an extra '/' and trailing '\0' */ |
361 | /* leave room for an extra '/' and trailing '\0' */ |
276 | maxpath = sizeof(name) - (len + (ext ? STRLEN(ext) : 0) + 2); |
362 | maxpath = sizeof (name) - (len + (ext ? strlen (ext) : 0) + 2); |
277 | if (maxpath <= 0) |
363 | if (maxpath <= 0) |
278 | return NULL; |
|
|
279 | |
|
|
280 | /* check if we can find it now */ |
|
|
281 | STRNCPY(name, file, len); |
|
|
282 | name[len] = '\0'; |
|
|
283 | |
|
|
284 | if (!access(name, R_OK)) |
|
|
285 | return STRDUP(name); |
|
|
286 | if (ext) { |
|
|
287 | STRCAT(name, ext); |
|
|
288 | if (!access(name, R_OK)) |
|
|
289 | return STRDUP(name); |
|
|
290 | } |
|
|
291 | for (path = pathlist; path != NULL && *path != '\0'; path = p) { |
|
|
292 | int n; |
|
|
293 | |
|
|
294 | /* colon delimited */ |
|
|
295 | if ((p = STRCHR(path, ':')) == NULL) |
|
|
296 | p = STRCHR(path, '\0'); |
|
|
297 | |
|
|
298 | n = (p - path); |
|
|
299 | if (*p != '\0') |
|
|
300 | p++; |
|
|
301 | |
|
|
302 | if (n > 0 && n <= maxpath) { |
|
|
303 | STRNCPY(name, path, n); |
|
|
304 | if (name[n - 1] != '/') |
|
|
305 | name[n++] = '/'; |
|
|
306 | name[n] = '\0'; |
|
|
307 | STRNCAT(name, file, len); |
|
|
308 | |
|
|
309 | if (!access(name, R_OK)) |
|
|
310 | return STRDUP(name); |
|
|
311 | if (ext) { |
|
|
312 | STRCAT(name, ext); |
|
|
313 | if (!access(name, R_OK)) |
|
|
314 | return STRDUP(name); |
|
|
315 | } |
|
|
316 | } |
|
|
317 | } |
|
|
318 | return NULL; |
364 | return NULL; |
319 | } |
|
|
320 | |
365 | |
|
|
366 | /* check if we can find it now */ |
|
|
367 | strncpy (name, file, len); |
|
|
368 | name[len] = '\0'; |
|
|
369 | |
|
|
370 | if (!access (name, R_OK)) |
|
|
371 | return strdup (name); |
|
|
372 | if (ext) |
|
|
373 | { |
|
|
374 | strcat (name, ext); |
|
|
375 | if (!access (name, R_OK)) |
|
|
376 | return strdup (name); |
|
|
377 | } |
|
|
378 | for (path = pathlist; path != NULL && *path != '\0'; path = p) |
|
|
379 | { |
|
|
380 | int n; |
|
|
381 | |
|
|
382 | /* colon delimited */ |
|
|
383 | if ((p = strchr (path, ':')) == NULL) |
|
|
384 | p = strchr (path, '\0'); |
|
|
385 | |
|
|
386 | n = (p - path); |
|
|
387 | if (*p != '\0') |
|
|
388 | p++; |
|
|
389 | |
|
|
390 | if (n > 0 && n <= maxpath) |
|
|
391 | { |
|
|
392 | strncpy (name, path, n); |
|
|
393 | if (name[n - 1] != '/') |
|
|
394 | name[n++] = '/'; |
|
|
395 | name[n] = '\0'; |
|
|
396 | strncat (name, file, len); |
|
|
397 | |
|
|
398 | if (!access (name, R_OK)) |
|
|
399 | return strdup (name); |
|
|
400 | if (ext) |
|
|
401 | { |
|
|
402 | strcat (name, ext); |
|
|
403 | if (!access (name, R_OK)) |
|
|
404 | return strdup (name); |
|
|
405 | } |
|
|
406 | } |
|
|
407 | } |
|
|
408 | return NULL; |
|
|
409 | } |
|
|
410 | |
321 | /* EXTPROTO */ |
411 | /* INTPROTO */ |
322 | char * |
412 | char * |
323 | rxvt_File_find(const char *file, const char *ext, const char *path) |
413 | rxvt_File_find (const char *file, const char *ext, const char *path) |
324 | { |
414 | { |
325 | char *f; |
415 | char *f; |
326 | |
416 | |
327 | if (file == NULL || *file == '\0') |
417 | if (file == NULL || *file == '\0') |
328 | return NULL; |
418 | return NULL; |
329 | |
419 | |
330 | /* search environment variables here too */ |
420 | /* search environment variables here too */ |
331 | if ((f = rxvt_File_search_path(path, file, ext)) == NULL) |
421 | if ((f = rxvt_File_search_path (path, file, ext)) == NULL) |
332 | #ifdef PATH_ENV |
422 | #ifdef PATH_ENV |
333 | if ((f = rxvt_File_search_path(getenv(PATH_ENV), file, ext)) == NULL) |
423 | if ((f = rxvt_File_search_path (getenv (PATH_ENV), file, ext)) == NULL) |
334 | #endif |
424 | #endif |
335 | f = rxvt_File_search_path(getenv("PATH"), file, ext); |
425 | f = rxvt_File_search_path (getenv ("PATH"), file, ext); |
336 | |
426 | |
337 | #ifdef DEBUG_SEARCH_PATH |
427 | #ifdef DEBUG_SEARCH_PATH |
338 | if (f) |
428 | if (f) |
339 | fprintf(stderr, "found: \"%s\"\n", f); |
429 | fprintf (stderr, "found: \"%s\"\n", f); |
340 | #endif |
430 | #endif |
341 | |
431 | |
342 | return f; |
432 | return f; |
343 | } |
433 | } |
344 | #endif /* defined (XPM_BACKGROUND) || (MENUBAR_MAX) */ |
434 | #endif /* defined (XPM_BACKGROUND) || (MENUBAR_MAX) */ |
345 | |
435 | |
346 | /*----------------------------------------------------------------------* |
436 | /*----------------------------------------------------------------------* |
347 | * miscellaneous drawing routines |
437 | * miscellaneous drawing routines |
… | |
… | |
349 | |
439 | |
350 | /* |
440 | /* |
351 | * Draw top/left and bottom/right border shadows around windows |
441 | * Draw top/left and bottom/right border shadows around windows |
352 | */ |
442 | */ |
353 | #if defined(RXVT_SCROLLBAR) || defined(MENUBAR) |
443 | #if defined(RXVT_SCROLLBAR) || defined(MENUBAR) |
354 | /* EXTPROTO */ |
444 | /* INTPROTO */ |
355 | void |
445 | void |
356 | rxvt_Draw_Shadow(Display *Xdisplay, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h) |
446 | rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h) |
357 | { |
447 | { |
358 | int shadow; |
448 | int shadow; |
359 | |
449 | |
360 | shadow = (w == 0 || h == 0) ? 1 : SHADOW; |
450 | shadow = (w == 0 || h == 0) ? 1 : SHADOW; |
361 | w += x - 1; |
451 | w += x - 1; |
362 | h += y - 1; |
452 | h += y - 1; |
363 | for (; shadow-- > 0; x++, y++, w--, h--) { |
453 | for (; shadow-- > 0; x++, y++, w--, h--) |
|
|
454 | { |
364 | XDrawLine(Xdisplay, win, topShadow, x, y, w, y); |
455 | XDrawLine (display, win, topShadow, x, y, w, y); |
365 | XDrawLine(Xdisplay, win, topShadow, x, y, x, h); |
456 | XDrawLine (display, win, topShadow, x, y, x, h); |
366 | XDrawLine(Xdisplay, win, botShadow, w, h, w, y + 1); |
457 | XDrawLine (display, win, botShadow, w, h, w, y + 1); |
367 | XDrawLine(Xdisplay, win, botShadow, w, h, x + 1, h); |
458 | XDrawLine (display, win, botShadow, w, h, x + 1, h); |
368 | } |
459 | } |
369 | } |
460 | } |
370 | #endif |
461 | #endif |
371 | |
462 | |
372 | /* button shapes */ |
463 | /* button shapes */ |
373 | #ifdef MENUBAR |
464 | #ifdef MENUBAR |
374 | /* EXTPROTO */ |
465 | /* INTPROTO */ |
375 | void |
466 | void |
376 | rxvt_Draw_Triangle(Display *Xdisplay, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type) |
467 | rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type) |
377 | { |
468 | { |
378 | switch (type) { |
469 | switch (type) |
|
|
470 | { |
379 | case 'r': /* right triangle */ |
471 | case 'r': /* right triangle */ |
380 | XDrawLine(Xdisplay, win, topShadow, x, y, x, y + w); |
472 | XDrawLine (display, win, topShadow, x, y, x, y + w); |
381 | XDrawLine(Xdisplay, win, topShadow, x, y, x + w, y + w / 2); |
473 | XDrawLine (display, win, topShadow, x, y, x + w, y + w / 2); |
382 | XDrawLine(Xdisplay, win, botShadow, x, y + w, x + w, y + w / 2); |
474 | XDrawLine (display, win, botShadow, x, y + w, x + w, y + w / 2); |
383 | break; |
475 | break; |
384 | |
476 | |
385 | case 'l': /* left triangle */ |
477 | case 'l': /* left triangle */ |
386 | XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x + w, y); |
478 | XDrawLine (display, win, botShadow, x + w, y + w, x + w, y); |
387 | XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x, y + w / 2); |
479 | XDrawLine (display, win, botShadow, x + w, y + w, x, y + w / 2); |
388 | XDrawLine(Xdisplay, win, topShadow, x, y + w / 2, x + w, y); |
480 | XDrawLine (display, win, topShadow, x, y + w / 2, x + w, y); |
389 | break; |
481 | break; |
390 | |
482 | |
391 | case 'd': /* down triangle */ |
483 | case 'd': /* down triangle */ |
392 | XDrawLine(Xdisplay, win, topShadow, x, y, x + w / 2, y + w); |
484 | XDrawLine (display, win, topShadow, x, y, x + w / 2, y + w); |
393 | XDrawLine(Xdisplay, win, topShadow, x, y, x + w, y); |
485 | XDrawLine (display, win, topShadow, x, y, x + w, y); |
394 | XDrawLine(Xdisplay, win, botShadow, x + w, y, x + w / 2, y + w); |
486 | XDrawLine (display, win, botShadow, x + w, y, x + w / 2, y + w); |
395 | break; |
487 | break; |
396 | |
488 | |
397 | case 'u': /* up triangle */ |
489 | case 'u': /* up triangle */ |
398 | XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x + w / 2, y); |
490 | XDrawLine (display, win, botShadow, x + w, y + w, x + w / 2, y); |
399 | XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x, y + w); |
491 | XDrawLine (display, win, botShadow, x + w, y + w, x, y + w); |
400 | XDrawLine(Xdisplay, win, topShadow, x, y + w, x + w / 2, y); |
492 | XDrawLine (display, win, topShadow, x, y + w, x + w / 2, y); |
401 | break; |
493 | break; |
402 | #if 0 |
494 | #if 0 |
403 | case 's': /* square */ |
495 | case 's': /* square */ |
404 | XDrawLine(Xdisplay, win, topShadow, x + w, y, x, y); |
496 | XDrawLine (display, win, topShadow, x + w, y, x, y); |
405 | XDrawLine(Xdisplay, win, topShadow, x, y, x, y + w); |
497 | XDrawLine (display, win, topShadow, x, y, x, y + w); |
406 | XDrawLine(Xdisplay, win, botShadow, x, y + w, x + w, y + w); |
498 | XDrawLine (display, win, botShadow, x, y + w, x + w, y + w); |
407 | XDrawLine(Xdisplay, win, botShadow, x + w, y + w, x + w, y); |
499 | XDrawLine (display, win, botShadow, x + w, y + w, x + w, y); |
408 | break; |
500 | break; |
409 | #endif |
501 | #endif |
|
|
502 | |
410 | } |
503 | } |
411 | } |
504 | } |
412 | #endif |
505 | #endif |
413 | /*----------------------- end-of-file (C source) -----------------------*/ |
506 | /*----------------------- end-of-file (C source) -----------------------*/ |