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