… | |
… | |
8 | * Portions of this file were derived from sources bearing the following license: |
8 | * Portions of this file were derived from sources bearing the following license: |
9 | * Copyright © 2003-2004 E. Will et al. |
9 | * Copyright © 2003-2004 E. Will et al. |
10 | * Copyright © 2005-2006 Atheme Development Group |
10 | * Copyright © 2005-2006 Atheme Development Group |
11 | * Rights to this code are as documented in doc/pod/license.pod. |
11 | * Rights to this code are as documented in doc/pod/license.pod. |
12 | * |
12 | * |
13 | * $Id: tools.h,v 1.9 2007/09/16 18:54:42 pippijn Exp $ |
13 | * $Id: tools.h,v 1.10 2007/09/22 14:27:26 pippijn Exp $ |
14 | */ |
14 | */ |
15 | |
15 | |
16 | #ifndef _TOOLS_H |
16 | #ifndef _TOOLS_H |
17 | #define _TOOLS_H |
17 | #define _TOOLS_H |
18 | |
18 | |
… | |
… | |
98 | /* misc string stuff */ |
98 | /* misc string stuff */ |
99 | E char *gen_pw (int sz); |
99 | E char *gen_pw (int sz); |
100 | E void tb2sp (char *line); |
100 | E void tb2sp (char *line); |
101 | E char *replace (char *s, int size, char const * const oldstr, char const * const newstr); |
101 | E char *replace (char *s, int size, char const * const oldstr, char const * const newstr); |
102 | |
102 | |
103 | /* reverse of atoi() */ |
|
|
104 | template<typename T> |
|
|
105 | static inline char * |
|
|
106 | itoa (T num) |
|
|
107 | { |
|
|
108 | static char ret[32]; |
|
|
109 | itoa (num, ret); |
|
|
110 | return ret; |
|
|
111 | } |
|
|
112 | |
|
|
113 | E int validemail (char *email); |
103 | E int validemail (char *email); |
114 | E bool validhostmask (char *host); |
104 | E bool validhostmask (char *host); |
115 | E char const *sbytes (float x); |
105 | E char const *sbytes (float x); |
116 | E float bytes (float x); |
106 | E float bytes (float x); |
117 | |
107 | |
118 | E unsigned long makekey (void); |
108 | E unsigned long makekey (void); |
119 | |
|
|
120 | /* time stuff */ |
|
|
121 | #if HAVE_GETTIMEOFDAY |
|
|
122 | E void s_time (struct timeval *sttime); |
|
|
123 | E void e_time (struct timeval sttime, struct timeval *ttime); |
|
|
124 | E int tv2ms (struct timeval *tv); |
|
|
125 | #endif |
|
|
126 | E char *time_ago (time_t event); |
|
|
127 | E char *timediff (time_t seconds); |
|
|
128 | |
|
|
129 | #ifdef timersub |
|
|
130 | #undef timersub |
|
|
131 | inline void |
|
|
132 | timersub (timeval *tvp, timeval *uvp, timeval *vvp) |
|
|
133 | { |
|
|
134 | vvp->tv_sec = tvp->tv_sec - uvp->tv_sec; |
|
|
135 | vvp->tv_usec = tvp->tv_usec - uvp->tv_usec; |
|
|
136 | if (vvp->tv_usec < 0) |
|
|
137 | { |
|
|
138 | vvp->tv_sec--; |
|
|
139 | vvp->tv_usec += 1000000; |
|
|
140 | } |
|
|
141 | } |
|
|
142 | #endif |
|
|
143 | |
109 | |
144 | /* tokenize.c */ |
110 | /* tokenize.c */ |
145 | E int sjtoken (char *message, char delimiter, char **parv, int limit = 256); |
111 | E int sjtoken (char *message, char delimiter, char **parv, int limit = 256); |
146 | E int tokenize (char *message, char **parv); |
112 | E int tokenize (char *message, char **parv); |
147 | |
113 | |