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.7 by pcg, Fri Feb 13 12:16:21 2004 UTC vs.
Revision 1.10 by pcg, Sat Mar 6 00:05:01 2004 UTC

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.
26#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
27#include "misc.intpro" /* PROTOS for internal routines */ 28#include "misc.intpro" /* PROTOS for internal routines */
28 29
29/* EXTPROTO */ 30/* EXTPROTO */
30char * 31char *
32rxvt_wcstombs (const wchar_t *str, int len)
33{
34 mbstate mbs;
35 char *r = (char *)rxvt_malloc (len * MB_CUR_MAX + 1);
36
37 char *dst = r;
38 while (len--)
39 {
40 int l = wcrtomb (dst, *str++, mbs);
41 if (l < 0)
42 *dst++ = '?';
43 else
44 dst += l;
45 }
46
47 *dst++ = 0;
48
49 return r;
50}
51
52/* EXTPROTO */
53char *
31rxvt_strdup (const char *str) 54rxvt_strdup (const char *str)
32{ 55{
33 return str ? strdup (str) : 0; 56 return str ? strdup (str) : 0;
34} 57}
35 58
36/* EXTPROTO */ 59/* EXTPROTO */
37char * 60char *
38rxvt_r_basename (const char *str) 61rxvt_r_basename (const char *str)
39{ 62{
40 char *base = STRRCHR (str, '/'); 63 char *base = STRRCHR (str, '/');
41 64
42 return (char *) (base ? base + 1 : str); 65 return (char *) (base ? base + 1 : str);
43} 66}
44 67
45/* 68/*
47 */ 70 */
48/* EXTPROTO */ 71/* EXTPROTO */
49void 72void
50rxvt_print_error (const char *fmt,...) 73rxvt_print_error (const char *fmt,...)
51{ 74{
52 va_list arg_ptr; 75 va_list arg_ptr;
53 76
54 va_start (arg_ptr, fmt); 77 va_start (arg_ptr, fmt);
55 fprintf (stderr, APL_NAME ": "); 78 fprintf (stderr, RESNAME ": ");
56 vfprintf (stderr, fmt, arg_ptr); 79 vfprintf (stderr, fmt, arg_ptr);
57 fprintf (stderr, "\n"); 80 fprintf (stderr, "\n");
58 va_end (arg_ptr); 81 va_end (arg_ptr);
59} 82}
60 83
68 */ 91 */
69/* EXTPROTO */ 92/* EXTPROTO */
70int 93int
71rxvt_Str_match (const char *s1, const char *s2) 94rxvt_Str_match (const char *s1, const char *s2)
72{ 95{
73 int n = STRLEN (s2); 96 int n = STRLEN (s2);
74 97
75 return ((STRNCMP (s1, s2, n) == 0) ? n : 0); 98 return ((STRNCMP (s1, s2, n) == 0) ? n : 0);
76} 99}
77 100
78/* EXTPROTO */ 101/* EXTPROTO */
79const char * 102const char *
80rxvt_Str_skip_space (const char *str) 103rxvt_Str_skip_space (const char *str)
81{ 104{
82 if (str) 105 if (str)
83 while (*str && isspace (*str)) 106 while (*str && isspace (*str))
84 str++; 107 str++;
108
85 return str; 109 return str;
86} 110}
87 111
88/* 112/*
89 * remove leading/trailing space and strip-off leading/trailing quotes. 113 * remove leading/trailing space and strip-off leading/trailing quotes.
91 */ 115 */
92/* EXTPROTO */ 116/* EXTPROTO */
93char * 117char *
94rxvt_Str_trim (char *str) 118rxvt_Str_trim (char *str)
95{ 119{
96 char *r, *s; 120 char *r, *s;
97 int n; 121 int n;
98 122
99 if (!str || !*str) /* shortcut */ 123 if (!str || !*str) /* shortcut */
100 return str; 124 return str;
101 125
102 /* skip leading spaces */ 126 /* skip leading spaces */
113 if (*s == '"' && *r == '"' && n > 1) 137 if (*s == '"' && *r == '"' && n > 1)
114 { 138 {
115 s++; 139 s++;
116 n -= 2; 140 n -= 2;
117 } 141 }
142
118 /* copy back over: forwards copy */ 143 /* copy back over: forwards copy */
119 for (r = str; n; n--) 144 for (r = str; n; n--)
120 *r++ = *s++; 145 *r++ = *s++;
121 *r = '\0'; 146 *r = '\0';
122 147

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines