… | |
… | |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
24 | *----------------------------------------------------------------------*/ |
24 | *----------------------------------------------------------------------*/ |
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 */ |
|
|
29 | |
28 | |
30 | char * |
29 | char * |
31 | rxvt_wcstombs (const wchar_t *str, int len) |
30 | rxvt_wcstombs (const wchar_t *str, int len) |
32 | { |
31 | { |
33 | if (len < 0) len = wcslen (str); |
32 | if (len < 0) len = wcslen (str); |
… | |
… | |
37 | |
36 | |
38 | char *dst = r; |
37 | char *dst = r; |
39 | while (len--) |
38 | while (len--) |
40 | { |
39 | { |
41 | ssize_t l = wcrtomb (dst, *str++, mbs); |
40 | ssize_t l = wcrtomb (dst, *str++, mbs); |
|
|
41 | |
42 | if (l < 0) |
42 | if (l < 0) |
43 | *dst++ = '?'; |
43 | *dst++ = '?'; |
44 | else |
44 | else |
45 | dst += l; |
45 | dst += l; |
46 | } |
46 | } |
… | |
… | |
168 | rxvt_strdup (const char *str) |
168 | rxvt_strdup (const char *str) |
169 | { |
169 | { |
170 | return str ? strdup (str) : 0; |
170 | return str ? strdup (str) : 0; |
171 | } |
171 | } |
172 | |
172 | |
173 | /* INTPROTO */ |
|
|
174 | char * |
173 | char * |
175 | rxvt_r_basename (const char *str) |
174 | rxvt_r_basename (const char *str) |
176 | { |
175 | { |
177 | char *base = strrchr (str, '/'); |
176 | char *base = strrchr (str, '/'); |
178 | |
177 | |
… | |
… | |
180 | } |
179 | } |
181 | |
180 | |
182 | /* |
181 | /* |
183 | * Print an error message |
182 | * Print an error message |
184 | */ |
183 | */ |
185 | /* INTPROTO */ |
|
|
186 | void |
184 | void |
187 | rxvt_vlog (const char *fmt, va_list arg_ptr) |
185 | rxvt_vlog (const char *fmt, va_list arg_ptr) |
188 | { |
186 | { |
189 | char msg[1024]; |
187 | char msg[1024]; |
190 | |
188 | |
… | |
… | |
194 | (*GET_R->log_hook) (msg); |
192 | (*GET_R->log_hook) (msg); |
195 | else |
193 | else |
196 | write (STDOUT_FILENO, msg, strlen (msg)); |
194 | write (STDOUT_FILENO, msg, strlen (msg)); |
197 | } |
195 | } |
198 | |
196 | |
199 | /* INTPROTO */ |
|
|
200 | void |
197 | void |
201 | rxvt_log (const char *fmt,...) |
198 | rxvt_log (const char *fmt,...) |
202 | { |
199 | { |
203 | va_list arg_ptr; |
200 | va_list arg_ptr; |
204 | |
201 | |
… | |
… | |
208 | } |
205 | } |
209 | |
206 | |
210 | /* |
207 | /* |
211 | * Print an error message |
208 | * Print an error message |
212 | */ |
209 | */ |
213 | /* INTPROTO */ |
|
|
214 | void |
210 | void |
215 | rxvt_warn (const char *fmt,...) |
211 | rxvt_warn (const char *fmt,...) |
216 | { |
212 | { |
217 | va_list arg_ptr; |
213 | va_list arg_ptr; |
218 | |
214 | |
… | |
… | |
221 | va_start (arg_ptr, fmt); |
217 | va_start (arg_ptr, fmt); |
222 | rxvt_vlog (fmt, arg_ptr); |
218 | rxvt_vlog (fmt, arg_ptr); |
223 | va_end (arg_ptr); |
219 | va_end (arg_ptr); |
224 | } |
220 | } |
225 | |
221 | |
226 | /* INTPROTO */ |
|
|
227 | void |
222 | void |
228 | rxvt_fatal (const char *fmt,...) |
223 | rxvt_fatal (const char *fmt,...) |
229 | { |
224 | { |
230 | va_list arg_ptr; |
225 | va_list arg_ptr; |
231 | |
226 | |
… | |
… | |
238 | rxvt_exit_failure (); |
233 | rxvt_exit_failure (); |
239 | } |
234 | } |
240 | |
235 | |
241 | class rxvt_failure_exception rxvt_failure_exception; |
236 | class rxvt_failure_exception rxvt_failure_exception; |
242 | |
237 | |
243 | /* INTPROTO */ |
|
|
244 | void |
238 | void |
245 | rxvt_exit_failure () |
239 | rxvt_exit_failure () |
246 | { |
240 | { |
247 | throw (rxvt_failure_exception); |
241 | throw (rxvt_failure_exception); |
248 | } |
242 | } |
… | |
… | |
253 | * No Match |
247 | * No Match |
254 | * return: 0 |
248 | * return: 0 |
255 | * Match |
249 | * Match |
256 | * return: strlen (S2) |
250 | * return: strlen (S2) |
257 | */ |
251 | */ |
258 | /* INTPROTO */ |
|
|
259 | int |
252 | int |
260 | rxvt_Str_match (const char *s1, const char *s2) |
253 | rxvt_Str_match (const char *s1, const char *s2) |
261 | { |
254 | { |
262 | int n = strlen (s2); |
255 | int n = strlen (s2); |
263 | |
256 | |
264 | return ((strncmp (s1, s2, n) == 0) ? n : 0); |
257 | return ((strncmp (s1, s2, n) == 0) ? n : 0); |
265 | } |
258 | } |
266 | |
259 | |
267 | /* INTPROTO */ |
|
|
268 | const char * |
260 | const char * |
269 | rxvt_Str_skip_space (const char *str) |
261 | rxvt_Str_skip_space (const char *str) |
270 | { |
262 | { |
271 | if (str) |
263 | if (str) |
272 | while (*str && isspace (*str)) |
264 | while (*str && isspace (*str)) |
… | |
… | |
277 | |
269 | |
278 | /* |
270 | /* |
279 | * remove leading/trailing space and strip-off leading/trailing quotes. |
271 | * remove leading/trailing space and strip-off leading/trailing quotes. |
280 | * in place. |
272 | * in place. |
281 | */ |
273 | */ |
282 | /* INTPROTO */ |
|
|
283 | char * |
274 | char * |
284 | rxvt_Str_trim (char *str) |
275 | rxvt_Str_trim (char *str) |
285 | { |
276 | { |
286 | char *r, *s; |
277 | char *r, *s; |
287 | |
278 | |
… | |
… | |
325 | * "M-x" prefixed strings, append "\r" if needed |
316 | * "M-x" prefixed strings, append "\r" if needed |
326 | * "\E]" prefixed strings (XTerm escape sequence) append ST if needed |
317 | * "\E]" prefixed strings (XTerm escape sequence) append ST if needed |
327 | * |
318 | * |
328 | * returns the converted string length |
319 | * returns the converted string length |
329 | */ |
320 | */ |
330 | /* INTPROTO */ |
|
|
331 | int |
321 | int |
332 | rxvt_Str_escaped (char *str) |
322 | rxvt_Str_escaped (char *str) |
333 | { |
323 | { |
334 | char ch, *s, *d; |
324 | char ch, *s, *d; |
335 | int i, num, append = 0; |
325 | int i, num, append = 0; |
… | |
… | |
402 | /* |
392 | /* |
403 | * Split a comma-separated string into an array, stripping leading and |
393 | * Split a comma-separated string into an array, stripping leading and |
404 | * trailing spaces from each entry. Empty strings are properly returned |
394 | * trailing spaces from each entry. Empty strings are properly returned |
405 | * Caller should free each entry and array when done |
395 | * Caller should free each entry and array when done |
406 | */ |
396 | */ |
407 | /* INTPROTO */ |
|
|
408 | char ** |
397 | char ** |
409 | rxvt_splitcommastring (const char *cs) |
398 | rxvt_splitcommastring (const char *cs) |
410 | { |
399 | { |
411 | int l, n, p; |
400 | int l, n, p; |
412 | const char *s, *t; |
401 | const char *s, *t; |
… | |
… | |
456 | * search for FILE in the current working directory, and within the |
445 | * search for FILE in the current working directory, and within the |
457 | * colon-delimited PATHLIST, adding the file extension EXT if required. |
446 | * colon-delimited PATHLIST, adding the file extension EXT if required. |
458 | * |
447 | * |
459 | * FILE is either semi-colon or zero terminated |
448 | * FILE is either semi-colon or zero terminated |
460 | */ |
449 | */ |
461 | /* INTPROTO */ |
|
|
462 | char * |
450 | char * |
463 | rxvt_File_search_path (const char *pathlist, const char *file, const char *ext) |
451 | rxvt_File_search_path (const char *pathlist, const char *file, const char *ext) |
464 | { |
452 | { |
465 | int maxpath, len; |
453 | int maxpath, len; |
466 | const char *p, *path; |
454 | const char *p, *path; |
… | |
… | |
529 | } |
517 | } |
530 | } |
518 | } |
531 | return NULL; |
519 | return NULL; |
532 | } |
520 | } |
533 | |
521 | |
534 | /* INTPROTO */ |
|
|
535 | char * |
522 | char * |
536 | rxvt_File_find (const char *file, const char *ext, const char *path) |
523 | rxvt_File_find (const char *file, const char *ext, const char *path) |
537 | { |
524 | { |
538 | char *f; |
525 | char *f; |
539 | |
526 | |
540 | if (file == NULL || *file == '\0') |
527 | if (file == NULL || *file == '\0') |
541 | return NULL; |
528 | return NULL; |
542 | |
529 | |
543 | /* search environment variables here too */ |
|
|
544 | if ((f = rxvt_File_search_path (path, file, ext)) == NULL) |
530 | f = rxvt_File_search_path (path, file, ext); |
545 | #ifdef PATH_ENV |
|
|
546 | if ((f = rxvt_File_search_path (getenv (PATH_ENV), file, ext)) == NULL) |
|
|
547 | #endif |
|
|
548 | f = rxvt_File_search_path (getenv ("PATH"), file, ext); |
|
|
549 | |
531 | |
550 | #ifdef DEBUG_SEARCH_PATH |
532 | #ifdef DEBUG_SEARCH_PATH |
551 | if (f) |
533 | if (f) |
552 | fprintf (stderr, "found: \"%s\"\n", f); |
534 | fprintf (stderr, "found: \"%s\"\n", f); |
553 | #endif |
535 | #endif |
… | |
… | |
562 | |
544 | |
563 | /* |
545 | /* |
564 | * Draw top/left and bottom/right border shadows around windows |
546 | * Draw top/left and bottom/right border shadows around windows |
565 | */ |
547 | */ |
566 | #if defined(RXVT_SCROLLBAR) || defined(MENUBAR) |
548 | #if defined(RXVT_SCROLLBAR) || defined(MENUBAR) |
567 | /* INTPROTO */ |
|
|
568 | void |
549 | void |
569 | rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h) |
550 | rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h) |
570 | { |
551 | { |
571 | int shadow; |
552 | int shadow; |
572 | |
553 | |
573 | shadow = (w == 0 || h == 0) ? 1 : SHADOW; |
554 | shadow = (w == 0 || h == 0) ? 1 : MENU_SHADOW; |
574 | w += x - 1; |
555 | w += x - 1; |
575 | h += y - 1; |
556 | h += y - 1; |
576 | for (; shadow-- > 0; x++, y++, w--, h--) |
557 | for (; shadow-- > 0; x++, y++, w--, h--) |
577 | { |
558 | { |
578 | XDrawLine (display, win, topShadow, x, y, w, y); |
559 | XDrawLine (display, win, topShadow, x, y, w, y); |
… | |
… | |
583 | } |
564 | } |
584 | #endif |
565 | #endif |
585 | |
566 | |
586 | /* button shapes */ |
567 | /* button shapes */ |
587 | #ifdef MENUBAR |
568 | #ifdef MENUBAR |
588 | /* INTPROTO */ |
|
|
589 | void |
569 | void |
590 | rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type) |
570 | rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type) |
591 | { |
571 | { |
592 | switch (type) |
572 | switch (type) |
593 | { |
573 | { |
… | |
… | |
624 | #endif |
604 | #endif |
625 | |
605 | |
626 | } |
606 | } |
627 | } |
607 | } |
628 | #endif |
608 | #endif |
|
|
609 | |
|
|
610 | // should not be used in interactive programs, for obvious reasons |
|
|
611 | void rxvt_usleep (int usecs) |
|
|
612 | { |
|
|
613 | #if HAVE_NANOSLEEP |
|
|
614 | struct timespec ts; |
|
|
615 | |
|
|
616 | ts.tv_sec = 0; |
|
|
617 | ts.tv_nsec = usecs * 1000; |
|
|
618 | nanosleep (&ts, NULL); |
|
|
619 | #else |
|
|
620 | /* use select for timing */ |
|
|
621 | struct timeval tv; |
|
|
622 | |
|
|
623 | tv.tv_sec = 0; |
|
|
624 | tv.tv_usec = usecs; |
|
|
625 | select (0, NULL, NULL, NULL, &tv); |
|
|
626 | #endif |
|
|
627 | } |
|
|
628 | |
629 | /*----------------------- end-of-file (C source) -----------------------*/ |
629 | /*----------------------- end-of-file (C source) -----------------------*/ |
|
|
630 | |