--- rxvt-unicode/src/misc.C 2006/02/20 22:40:35 1.39 +++ rxvt-unicode/src/misc.C 2007/09/08 20:55:49 1.45 @@ -1,4 +1,4 @@ -/*--------------------------------*-C-*---------------------------------* +/*----------------------------------------------------------------------* * File: misc.C *----------------------------------------------------------------------* * @@ -235,34 +235,7 @@ } /* - * 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) NOTHROW -{ - int n = strlen (s2); - - return ((strncmp (s1, s2, n) == 0) ? n : 0); -} - -const char * -rxvt_Str_skip_space (const char *str) NOTHROW -{ - if (str) - while (*str && isspace (*str)) - str++; - - return str; -} - -/* - * remove leading/trailing space and strip-off leading/trailing quotes. - * in place. + * remove leading/trailing space in place. */ char * rxvt_Str_trim (char *str) NOTHROW @@ -282,15 +255,6 @@ while (r > s && isspace (*r)) r--; -#if 0 - /* skip matching leading/trailing quotes */ - if (*s == '"' && *r == '"' && n > 1) - { - s++; - n -= 2; - } -#endif - memmove (str, s, r + 1 - s); str[r + 1 - s] = 0; @@ -298,91 +262,6 @@ } /* - * in-place interpretation of string: - * - * backslash-escaped: "\a\b\E\e\n\r\t", "\octal" - * Ctrl chars: ^@ .. ^_, ^? - * - * Emacs-style: "M-" prefix - * - * Also, - * "M-x" prefixed strings, append "\r" if needed - * "\E]" prefixed strings (XTerm escape sequence) append ST if needed - * - * returns the converted string length - */ -int -rxvt_Str_escaped (char *str) NOTHROW -{ - char ch, *s, *d; - int i, num, append = 0; - - if (!str || !*str) - return 0; - - d = s = str; - - if (*s == 'M' && s[1] == '-') - { - /* Emacs convenience, replace leading `M-..' with `\E..' */ - *d++ = C0_ESC; - s += 2; - if (toupper (*s) == 'X') - /* append carriage-return for `M-xcommand' */ - for (*d++ = 'x', append = '\r', s++; isspace (*s); s++) ; - } - for (; (ch = *s++);) - { - if (ch == '\\') - { - ch = *s++; - if (ch >= '0' && ch <= '7') - { /* octal */ - num = ch - '0'; - for (i = 0; i < 2; i++, s++) - { - ch = *s; - if (ch < '0' || ch > '7') - break; - num = num * 8 + ch - '0'; - } - ch = (char)num; - } - else if (ch == 'a') - ch = C0_BEL; /* bell */ - else if (ch == 'b') - ch = C0_BS; /* backspace */ - else if (ch == 'E' || ch == 'e') - ch = C0_ESC; /* escape */ - else if (ch == 'n') - ch = '\n'; /* newline */ - else if (ch == 'r') - ch = '\r'; /* carriage-return */ - else if (ch == 't') - ch = C0_HT; /* tab */ - } - else if (ch == '^') - { - ch = *s++; - ch = toupper (ch); - ch = (ch == '?' ? 127 : (ch - '@')); - } - *d++ = ch; - } - - /* ESC] is an XTerm escape sequence, must be terminated */ - if (*str == '\0' && str[1] == C0_ESC && str[2] == ']') - append = CHAR_ST; - - /* add trailing character as required */ - if (append && d[-1] != append) - *d++ = append; - *d = '\0'; - - return (d - str); -} - -/* * Split a comma-separated string into an array, stripping leading and * trailing spaces from each entry. Empty strings are properly returned * Caller should free each entry and array when done @@ -427,95 +306,5 @@ free (cs); } -/*----------------------------------------------------------------------* - * file searching - */ - -#ifdef XPM_BACKGROUND -/* - * 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) NOTHROW -{ - 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); - - /* 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) NOTHROW -{ - char *f; - - if (file == NULL || *file == '\0') - return NULL; - - f = rxvt_File_search_path (path, file, ext); - - return f; -} -#endif