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