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.26 by root, Wed Feb 16 20:32:05 2005 UTC vs.
Revision 1.32 by root, Wed Jan 11 00:59:58 2006 UTC

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 }
167rxvt_strdup (const char *str) 168rxvt_strdup (const char *str)
168{ 169{
169 return str ? strdup (str) : 0; 170 return str ? strdup (str) : 0;
170} 171}
171 172
172/* INTPROTO */
173char * 173char *
174rxvt_r_basename (const char *str) 174rxvt_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 */
185void 184void
186rxvt_vlog (const char *fmt, va_list arg_ptr) 185rxvt_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 */
199void 197void
200rxvt_log (const char *fmt,...) 198rxvt_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 */
213void 210void
214rxvt_warn (const char *fmt,...) 211rxvt_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 */
226void 222void
227rxvt_fatal (const char *fmt,...) 223rxvt_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
240class rxvt_failure_exception rxvt_failure_exception; 236class rxvt_failure_exception rxvt_failure_exception;
241 237
242/* INTPROTO */
243void 238void
244rxvt_exit_failure () 239rxvt_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 */
258int 252int
259rxvt_Str_match (const char *s1, const char *s2) 253rxvt_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 */
267const char * 260const char *
268rxvt_Str_skip_space (const char *str) 261rxvt_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 */
282char * 274char *
283rxvt_Str_trim (char *str) 275rxvt_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 */
330int 321int
331rxvt_Str_escaped (char *str) 322rxvt_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 */
407char ** 397char **
408rxvt_splitcommastring (const char *cs) 398rxvt_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 */
461char * 450char *
462rxvt_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)
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 */
534char * 522char *
535rxvt_File_find (const char *file, const char *ext, const char *path) 523rxvt_File_find (const char *file, const char *ext, const char *path)
536{ 524{
537 char *f; 525 char *f;
538 526
539 if (file == NULL || *file == '\0') 527 if (file == NULL || *file == '\0')
540 return NULL; 528 return NULL;
541 529
542 /* search environment variables here too */
543 if ((f = rxvt_File_search_path (path, file, ext)) == NULL) 530 f = rxvt_File_search_path (path, file, ext);
544#ifdef PATH_ENV
545 if ((f = rxvt_File_search_path (getenv (PATH_ENV), file, ext)) == NULL)
546#endif
547 f = rxvt_File_search_path (getenv ("PATH"), file, ext);
548 531
549#ifdef DEBUG_SEARCH_PATH 532#ifdef DEBUG_SEARCH_PATH
550 if (f) 533 if (f)
551 fprintf (stderr, "found: \"%s\"\n", f); 534 fprintf (stderr, "found: \"%s\"\n", f);
552#endif 535#endif
561 544
562/* 545/*
563 * Draw top/left and bottom/right border shadows around windows 546 * Draw top/left and bottom/right border shadows around windows
564 */ 547 */
565#if defined(RXVT_SCROLLBAR) || defined(MENUBAR) 548#if defined(RXVT_SCROLLBAR) || defined(MENUBAR)
566/* INTPROTO */
567void 549void
568rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h) 550rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h)
569{ 551{
570 int shadow; 552 int shadow;
571 553
572 shadow = (w == 0 || h == 0) ? 1 : SHADOW; 554 shadow = (w == 0 || h == 0) ? 1 : MENU_SHADOW;
573 w += x - 1; 555 w += x - 1;
574 h += y - 1; 556 h += y - 1;
575 for (; shadow-- > 0; x++, y++, w--, h--) 557 for (; shadow-- > 0; x++, y++, w--, h--)
576 { 558 {
577 XDrawLine (display, win, topShadow, x, y, w, y); 559 XDrawLine (display, win, topShadow, x, y, w, y);
582} 564}
583#endif 565#endif
584 566
585/* button shapes */ 567/* button shapes */
586#ifdef MENUBAR 568#ifdef MENUBAR
587/* INTPROTO */
588void 569void
589rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type) 570rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type)
590{ 571{
591 switch (type) 572 switch (type)
592 { 573 {
623#endif 604#endif
624 605
625 } 606 }
626} 607}
627#endif 608#endif
609
610// should not be used in interactive programs, for obvious reasons
611void 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
628/*----------------------- end-of-file (C source) -----------------------*/ 629/*----------------------- end-of-file (C source) -----------------------*/
630

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines