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