ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/misc.C
(Generate patch)

Comparing rxvt-unicode/src/misc.C (file contents):
Revision 1.25 by root, Mon Feb 7 01:17:03 2005 UTC vs.
Revision 1.31 by root, Fri Jan 6 20:50:58 2006 UTC

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
30char * 29char *
31rxvt_wcstombs (const wchar_t *str, int len) 30rxvt_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 }
168rxvt_strdup (const char *str) 168rxvt_strdup (const char *str)
169{ 169{
170 return str ? strdup (str) : 0; 170 return str ? strdup (str) : 0;
171} 171}
172 172
173/* INTPROTO */
174char * 173char *
175rxvt_r_basename (const char *str) 174rxvt_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 */
186void 184void
187rxvt_vlog (const char *fmt, va_list arg_ptr) 185rxvt_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 */
200void 197void
201rxvt_log (const char *fmt,...) 198rxvt_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 */
214void 210void
215rxvt_warn (const char *fmt,...) 211rxvt_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 */
227void 222void
228rxvt_fatal (const char *fmt,...) 223rxvt_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
241class rxvt_failure_exception rxvt_failure_exception; 236class rxvt_failure_exception rxvt_failure_exception;
242 237
243/* INTPROTO */
244void 238void
245rxvt_exit_failure () 239rxvt_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 */
259int 252int
260rxvt_Str_match (const char *s1, const char *s2) 253rxvt_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 */
268const char * 260const char *
269rxvt_Str_skip_space (const char *str) 261rxvt_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 */
283char * 274char *
284rxvt_Str_trim (char *str) 275rxvt_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 */
331int 321int
332rxvt_Str_escaped (char *str) 322rxvt_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 */
408char ** 397char **
409rxvt_splitcommastring (const char *cs) 398rxvt_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 */
462char * 450char *
463rxvt_File_search_path (const char *pathlist, const char *file, const char *ext) 451rxvt_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 */
535char * 522char *
536rxvt_File_find (const char *file, const char *ext, const char *path) 523rxvt_File_find (const char *file, const char *ext, const char *path)
537{ 524{
538 char *f; 525 char *f;
539 526
562 549
563/* 550/*
564 * Draw top/left and bottom/right border shadows around windows 551 * Draw top/left and bottom/right border shadows around windows
565 */ 552 */
566#if defined(RXVT_SCROLLBAR) || defined(MENUBAR) 553#if defined(RXVT_SCROLLBAR) || defined(MENUBAR)
567/* INTPROTO */
568void 554void
569rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h) 555rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h)
570{ 556{
571 int shadow; 557 int shadow;
572 558
573 shadow = (w == 0 || h == 0) ? 1 : SHADOW; 559 shadow = (w == 0 || h == 0) ? 1 : MENU_SHADOW;
574 w += x - 1; 560 w += x - 1;
575 h += y - 1; 561 h += y - 1;
576 for (; shadow-- > 0; x++, y++, w--, h--) 562 for (; shadow-- > 0; x++, y++, w--, h--)
577 { 563 {
578 XDrawLine (display, win, topShadow, x, y, w, y); 564 XDrawLine (display, win, topShadow, x, y, w, y);
583} 569}
584#endif 570#endif
585 571
586/* button shapes */ 572/* button shapes */
587#ifdef MENUBAR 573#ifdef MENUBAR
588/* INTPROTO */
589void 574void
590rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type) 575rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type)
591{ 576{
592 switch (type) 577 switch (type)
593 { 578 {
624#endif 609#endif
625 610
626 } 611 }
627} 612}
628#endif 613#endif
614
615// should not be used in interactive programs, for obvious reasons
616void 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
629/*----------------------- end-of-file (C source) -----------------------*/ 634/*----------------------- end-of-file (C source) -----------------------*/
635

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines