]>
jfr.im git - solanum.git/blob - src/irc_string.c
2 * ircd-ratbox: A slightly useful ircd.
3 * irc_string.c: IRC string functions.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: irc_string.c 678 2006-02-03 20:25:01Z jilles $
28 #include "sprintf_irc.h"
29 #include "irc_string.h"
47 * myctime - This is like standard ctime()-function, but it zaps away
48 * the newline from the end of that string. Also, it takes
49 * the time value as parameter, instead of pointer to it.
50 * Note that it is necessary to copy the string to alternate
51 * buffer (who knows how ctime() implements it, maybe it statically
52 * has newline there and never 'refreshes' it -- zapping that
53 * might break things in other places...)
56 * Thu Nov 24 18:22:48 1986
64 strcpy(buf
, ctime(&value
));
65 if((p
= strchr(buf
, '\n')) != NULL
)
72 * clean_string - clean up a string possibly containing garbage
74 * *sigh* Before the kiddies find this new and exciting way of
75 * annoying opers, lets clean up what is sent to local opers
79 clean_string(char *dest
, const unsigned char *src
, size_t len
)
85 if(dest
== NULL
|| src
== NULL
)
88 len
-= 3; /* allow for worst case, '^A\0' */
90 while(*src
&& (len
> 0))
92 if(*src
& 0x80) /* if high bit is set */
97 else if(!IsPrint(*src
)) /* if NOT printable */
101 *d
++ = 0x40 + *src
; /* turn it into a printable */
113 * strip_tabs(dst, src, length)
115 * Copies src to dst, while converting all \t (tabs) into spaces.
117 * NOTE: jdc: I have a gut feeling there's a faster way to do this.
120 strip_tabs(char *dest
, const unsigned char *src
, size_t len
)
123 /* Sanity check; we don't want anything nasty... */
127 if(dest
== NULL
|| src
== NULL
)
130 while(*src
&& (len
> 0))
134 *d
++ = ' '; /* Translate the tab into a space */
138 *d
++ = *src
; /* Copy src to dst */
143 *d
= '\0'; /* Null terminate, thanks and goodbye */
148 * strtoken - walk through a string of tokens, using a set of separators
153 strtoken(char **save
, char *str
, const char *fs
)
155 char *pos
= *save
; /* keep last position across calls */
159 pos
= str
; /* new string scan */
161 while(pos
&& *pos
&& strchr(fs
, *pos
) != NULL
)
162 ++pos
; /* skip leading separators */
165 return (pos
= *save
= NULL
); /* string contains only sep's */
167 tmp
= pos
; /* now, keep position of the token */
169 while(*pos
&& strchr(fs
, *pos
) == NULL
)
170 ++pos
; /* skip content of the token */
173 *pos
++ = '\0'; /* remove first sep after the token */
175 pos
= NULL
; /* end of string */
182 * Copyright (c) 1996-1999 by Internet Software Consortium.
184 * Permission to use, copy, modify, and distribute this software for any
185 * purpose with or without fee is hereby granted, provided that the above
186 * copyright notice and this permission notice appear in all copies.
188 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
189 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
190 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
191 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
192 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
193 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
194 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
198 #define SPRINTF(x) ((size_t)rb_sprintf x)
201 strip_colour(char *string
)
205 char *last_non_space
= NULL
;
206 /* c is source, c2 is target */
216 if(c
[1] == ',' && isdigit(c
[2]))
242 *last_non_space
= '\0';