--- rxvt-unicode/src/misc.C 2006/01/06 20:50:58 1.31 +++ rxvt-unicode/src/misc.C 2007/08/27 20:53:16 1.43 @@ -1,4 +1,4 @@ -/*--------------------------------*-C-*---------------------------------* +/*----------------------------------------------------------------------* * File: misc.C *----------------------------------------------------------------------* * @@ -6,7 +6,7 @@ * Copyright (c) 1996 mj olesen Queen's Univ at Kingston * Copyright (c) 1997,1998 Oezguer Kesim * Copyright (c) 1998-2000 Geoff Wing - * Copyright (c) 2003-2004 Marc Lehmann + * Copyright (c) 2003-2006 Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -165,13 +165,7 @@ } char * -rxvt_strdup (const char *str) -{ - return str ? strdup (str) : 0; -} - -char * -rxvt_r_basename (const char *str) +rxvt_r_basename (const char *str) NOTHROW { char *base = strrchr (str, '/'); @@ -182,7 +176,7 @@ * Print an error message */ void -rxvt_vlog (const char *fmt, va_list arg_ptr) +rxvt_vlog (const char *fmt, va_list arg_ptr) NOTHROW { char msg[1024]; @@ -195,7 +189,7 @@ } void -rxvt_log (const char *fmt,...) +rxvt_log (const char *fmt,...) NOTHROW { va_list arg_ptr; @@ -208,7 +202,7 @@ * Print an error message */ void -rxvt_warn (const char *fmt,...) +rxvt_warn (const char *fmt,...) NOTHROW { va_list arg_ptr; @@ -220,7 +214,7 @@ } void -rxvt_fatal (const char *fmt,...) +rxvt_fatal (const char *fmt,...) THROW ((class rxvt_failure_exception)) { va_list arg_ptr; @@ -233,46 +227,19 @@ rxvt_exit_failure (); } -class rxvt_failure_exception rxvt_failure_exception; - void -rxvt_exit_failure () +rxvt_exit_failure () THROW ((class rxvt_failure_exception)) { + static class rxvt_failure_exception rxvt_failure_exception; throw (rxvt_failure_exception); } /* - * check that the first characters of S1 match S2 - * - * No Match - * return: 0 - * Match - * return: strlen (S2) - */ -int -rxvt_Str_match (const char *s1, const char *s2) -{ - int n = strlen (s2); - - return ((strncmp (s1, s2, n) == 0) ? n : 0); -} - -const char * -rxvt_Str_skip_space (const char *str) -{ - if (str) - while (*str && isspace (*str)) - str++; - - return str; -} - -/* * remove leading/trailing space and strip-off leading/trailing quotes. * in place. */ char * -rxvt_Str_trim (char *str) +rxvt_Str_trim (char *str) NOTHROW { char *r, *s; @@ -319,7 +286,7 @@ * returns the converted string length */ int -rxvt_Str_escaped (char *str) +rxvt_Str_escaped (char *str) NOTHROW { char ch, *s, *d; int i, num, append = 0; @@ -395,7 +362,7 @@ * Caller should free each entry and array when done */ char ** -rxvt_splitcommastring (const char *cs) +rxvt_splitcommastring (const char *cs) NOTHROW { int l, n, p; const char *s, *t; @@ -426,7 +393,7 @@ } void -rxvt_freecommastring (char **cs) +rxvt_freecommastring (char **cs) NOTHROW { for (int i = 0; cs[i]; ++i) free (cs[i]); @@ -434,202 +401,5 @@ free (cs); } -/*----------------------------------------------------------------------* - * file searching - */ - -/* #define DEBUG_SEARCH_PATH */ - -#if defined (XPM_BACKGROUND) || (MENUBAR_MAX) -/* - * search for FILE in the current working directory, and within the - * colon-delimited PATHLIST, adding the file extension EXT if required. - * - * FILE is either semi-colon or zero terminated - */ -char * -rxvt_File_search_path (const char *pathlist, const char *file, const char *ext) -{ - int maxpath, len; - const char *p, *path; - char name[256]; - - if (!access (file, R_OK)) /* found (plain name) in current directory */ - return strdup (file); - - /* semi-colon delimited */ - if ((p = strchr (file, ';'))) - len = (p - file); - else - len = strlen (file); - -#ifdef DEBUG_SEARCH_PATH - getcwd (name, sizeof (name)); - fprintf (stderr, "pwd: \"%s\"\n", name); - fprintf (stderr, "find: \"%.*s\"\n", len, file); -#endif - - /* leave room for an extra '/' and trailing '\0' */ - maxpath = sizeof (name) - (len + (ext ? strlen (ext) : 0) + 2); - if (maxpath <= 0) - return NULL; - - /* check if we can find it now */ - strncpy (name, file, len); - name[len] = '\0'; - - if (!access (name, R_OK)) - return strdup (name); - if (ext) - { - strcat (name, ext); - if (!access (name, R_OK)) - return strdup (name); - } - for (path = pathlist; path != NULL && *path != '\0'; path = p) - { - int n; - - /* colon delimited */ - if ((p = strchr (path, ':')) == NULL) - p = strchr (path, '\0'); - - n = (p - path); - if (*p != '\0') - p++; - - if (n > 0 && n <= maxpath) - { - strncpy (name, path, n); - if (name[n - 1] != '/') - name[n++] = '/'; - name[n] = '\0'; - strncat (name, file, len); - - if (!access (name, R_OK)) - return strdup (name); - if (ext) - { - strcat (name, ext); - if (!access (name, R_OK)) - return strdup (name); - } - } - } - return NULL; -} - -char * -rxvt_File_find (const char *file, const char *ext, const char *path) -{ - char *f; - - if (file == NULL || *file == '\0') - return NULL; - - /* search environment variables here too */ - if ((f = rxvt_File_search_path (path, file, ext)) == NULL) -#ifdef PATH_ENV - if ((f = rxvt_File_search_path (getenv (PATH_ENV), file, ext)) == NULL) -#endif - f = rxvt_File_search_path (getenv ("PATH"), file, ext); - -#ifdef DEBUG_SEARCH_PATH - if (f) - fprintf (stderr, "found: \"%s\"\n", f); -#endif - - return f; -} -#endif /* defined (XPM_BACKGROUND) || (MENUBAR_MAX) */ - -/*----------------------------------------------------------------------* - * miscellaneous drawing routines - */ - -/* - * Draw top/left and bottom/right border shadows around windows - */ -#if defined(RXVT_SCROLLBAR) || defined(MENUBAR) -void -rxvt_Draw_Shadow (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int h) -{ - int shadow; - - shadow = (w == 0 || h == 0) ? 1 : MENU_SHADOW; - w += x - 1; - h += y - 1; - for (; shadow-- > 0; x++, y++, w--, h--) - { - XDrawLine (display, win, topShadow, x, y, w, y); - XDrawLine (display, win, topShadow, x, y, x, h); - XDrawLine (display, win, botShadow, w, h, w, y + 1); - XDrawLine (display, win, botShadow, w, h, x + 1, h); - } -} -#endif - -/* button shapes */ -#ifdef MENUBAR -void -rxvt_Draw_Triangle (Display *display, Window win, GC topShadow, GC botShadow, int x, int y, int w, int type) -{ - switch (type) - { - case 'r': /* right triangle */ - XDrawLine (display, win, topShadow, x, y, x, y + w); - XDrawLine (display, win, topShadow, x, y, x + w, y + w / 2); - XDrawLine (display, win, botShadow, x, y + w, x + w, y + w / 2); - break; - - case 'l': /* left triangle */ - XDrawLine (display, win, botShadow, x + w, y + w, x + w, y); - XDrawLine (display, win, botShadow, x + w, y + w, x, y + w / 2); - XDrawLine (display, win, topShadow, x, y + w / 2, x + w, y); - break; - - case 'd': /* down triangle */ - XDrawLine (display, win, topShadow, x, y, x + w / 2, y + w); - XDrawLine (display, win, topShadow, x, y, x + w, y); - XDrawLine (display, win, botShadow, x + w, y, x + w / 2, y + w); - break; - - case 'u': /* up triangle */ - XDrawLine (display, win, botShadow, x + w, y + w, x + w / 2, y); - XDrawLine (display, win, botShadow, x + w, y + w, x, y + w); - XDrawLine (display, win, topShadow, x, y + w, x + w / 2, y); - break; -#if 0 - case 's': /* square */ - XDrawLine (display, win, topShadow, x + w, y, x, y); - XDrawLine (display, win, topShadow, x, y, x, y + w); - XDrawLine (display, win, botShadow, x, y + w, x + w, y + w); - XDrawLine (display, win, botShadow, x + w, y + w, x + w, y); - break; -#endif - - } -} -#endif - -// should not be used in interactive programs, for obvious reasons -void rxvt_usleep (int usecs) -{ -#if HAVE_NANOSLEEP - struct timespec ts; - - ts.tv_sec = 0; - ts.tv_nsec = usecs * 1000; - nanosleep (&ts, NULL); -#else - /* use select for timing */ - struct timeval tv; - - tv.tv_sec = 0; - tv.tv_usec = usecs; - select (0, NULL, NULL, NULL, &tv); -#endif -} -/*----------------------- end-of-file (C source) -----------------------*/