… | |
… | |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 1996 mj olesen <olesen@me.QueensU.CA> Queen's Univ at Kingston |
6 | * Copyright (c) 1996 mj olesen <olesen@me.QueensU.CA> Queen's Univ at Kingston |
7 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
7 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
8 | * Copyright (c) 1998-2000 Geoff Wing <gcw@pobox.com> |
8 | * Copyright (c) 1998-2000 Geoff Wing <gcw@pobox.com> |
|
|
9 | * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> |
9 | * |
10 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License as published by |
12 | * it under the terms of the GNU General Public License as published by |
12 | * the Free Software Foundation; either version 2 of the License, or |
13 | * the Free Software Foundation; either version 2 of the License, or |
13 | * (at your option) any later version. |
14 | * (at your option) any later version. |
… | |
… | |
32 | { |
33 | { |
33 | return str ? strdup (str) : 0; |
34 | return str ? strdup (str) : 0; |
34 | } |
35 | } |
35 | |
36 | |
36 | /* EXTPROTO */ |
37 | /* EXTPROTO */ |
37 | char * |
38 | char * |
38 | rxvt_r_basename (const char *str) |
39 | rxvt_r_basename (const char *str) |
39 | { |
40 | { |
40 | char *base = STRRCHR (str, '/'); |
41 | char *base = STRRCHR (str, '/'); |
41 | |
42 | |
42 | return (char *) (base ? base + 1 : str); |
43 | return (char *) (base ? base + 1 : str); |
43 | } |
44 | } |
44 | |
45 | |
45 | /* |
46 | /* |
… | |
… | |
47 | */ |
48 | */ |
48 | /* EXTPROTO */ |
49 | /* EXTPROTO */ |
49 | void |
50 | void |
50 | rxvt_print_error (const char *fmt,...) |
51 | rxvt_print_error (const char *fmt,...) |
51 | { |
52 | { |
52 | va_list arg_ptr; |
53 | va_list arg_ptr; |
53 | |
54 | |
54 | va_start (arg_ptr, fmt); |
55 | va_start (arg_ptr, fmt); |
55 | fprintf (stderr, APL_NAME ": "); |
56 | fprintf (stderr, APL_NAME ": "); |
56 | vfprintf (stderr, fmt, arg_ptr); |
57 | vfprintf (stderr, fmt, arg_ptr); |
57 | fprintf (stderr, "\n"); |
58 | fprintf (stderr, "\n"); |
… | |
… | |
68 | */ |
69 | */ |
69 | /* EXTPROTO */ |
70 | /* EXTPROTO */ |
70 | int |
71 | int |
71 | rxvt_Str_match (const char *s1, const char *s2) |
72 | rxvt_Str_match (const char *s1, const char *s2) |
72 | { |
73 | { |
73 | int n = STRLEN (s2); |
74 | int n = STRLEN (s2); |
74 | |
75 | |
75 | return ((STRNCMP (s1, s2, n) == 0) ? n : 0); |
76 | return ((STRNCMP (s1, s2, n) == 0) ? n : 0); |
76 | } |
77 | } |
77 | |
78 | |
78 | /* EXTPROTO */ |
79 | /* EXTPROTO */ |
79 | const char * |
80 | const char * |
80 | rxvt_Str_skip_space (const char *str) |
81 | rxvt_Str_skip_space (const char *str) |
81 | { |
82 | { |
82 | if (str) |
83 | if (str) |
83 | while (*str && isspace (*str)) |
84 | while (*str && isspace (*str)) |
84 | str++; |
85 | str++; |
|
|
86 | |
85 | return str; |
87 | return str; |
86 | } |
88 | } |
87 | |
89 | |
88 | /* |
90 | /* |
89 | * remove leading/trailing space and strip-off leading/trailing quotes. |
91 | * remove leading/trailing space and strip-off leading/trailing quotes. |
… | |
… | |
91 | */ |
93 | */ |
92 | /* EXTPROTO */ |
94 | /* EXTPROTO */ |
93 | char * |
95 | char * |
94 | rxvt_Str_trim (char *str) |
96 | rxvt_Str_trim (char *str) |
95 | { |
97 | { |
96 | char *r, *s; |
98 | char *r, *s; |
97 | int n; |
99 | int n; |
98 | |
100 | |
99 | if (!str || !*str) /* shortcut */ |
101 | if (!str || !*str) /* shortcut */ |
100 | return str; |
102 | return str; |
101 | |
103 | |
102 | /* skip leading spaces */ |
104 | /* skip leading spaces */ |
… | |
… | |
113 | if (*s == '"' && *r == '"' && n > 1) |
115 | if (*s == '"' && *r == '"' && n > 1) |
114 | { |
116 | { |
115 | s++; |
117 | s++; |
116 | n -= 2; |
118 | n -= 2; |
117 | } |
119 | } |
|
|
120 | |
118 | /* copy back over: forwards copy */ |
121 | /* copy back over: forwards copy */ |
119 | for (r = str; n; n--) |
122 | for (r = str; n; n--) |
120 | *r++ = *s++; |
123 | *r++ = *s++; |
121 | *r = '\0'; |
124 | *r = '\0'; |
122 | |
125 | |