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