Fixed CPlayer init, it was called too early.
nothing important on the logger
3 #include "sm_stringutil.h"
5 #define ALT 0x00000001 /* alternate form */
6 #define HEXPREFIX 0x00000002 /* add 0x or 0X prefix */
7 #define LADJUST 0x00000004 /* left adjustment */
8 #define LONGDBL 0x00000008 /* long double */
9 #define LONGINT 0x00000010 /* long integer */
10 #define QUADINT 0x00000020 /* quad integer */
11 #define SHORTINT 0x00000040 /* short integer */
12 #define ZEROPAD 0x00000080 /* zero (as opposed to blank) pad */
13 #define FPT 0x00000100 /* floating point number */
14 #define to_digit(c) ((c) - '0')
15 #define is_digit(c) ((unsigned)to_digit(c) <= 9)
16 #define to_char(n) ((n) + '0')
18 //:TODO: fix this macro when we have a debugger
20 #define CHECK_ARGS(n)/* \
21 if ((arg+n) > args) { \
22 LogError(amx, AMX_ERR_PARAMS, "String formatted incorrectly - parameter %d (total %d)", arg, args); \
27 void AddString(char **buf_p, size_t &maxlen, const char *string, int width, int prec)
31 static char nlstr[] = {'(','n','u','l','l',')','\0'};
43 for (size = 0; size < prec; size++)
45 if (string[size] == '\0')
51 while (string[size++]);
55 if (size > (int)maxlen)
68 while ((width-- > 0) && maxlen)
77 void AddFloat(char **buf_p, size_t &maxlen, double fval, int width, int prec)
92 // write the float number
97 text[digits++] = '0' + val % 10;
103 text[digits++] = '-';
108 while ((digits < width) && maxlen)
115 while ((digits--) && maxlen)
117 *buf++ = text[digits];
127 // write the fraction
129 while (digits < prec)
134 text[digits++] = '0' + val % 10;
137 if ((digits > 0) && maxlen)
142 for (prec = 0; maxlen && (prec < digits); prec++)
151 void AddUInt(char **buf_p, size_t &maxlen, unsigned int val, int width, int flags)
160 text[digits++] = '0' + val % 10;
166 if (!(flags & LADJUST))
168 while (digits < width && maxlen)
170 *buf++ = (flags & ZEROPAD) ? '0' : ' ';
176 while (digits-- && maxlen)
178 *buf++ = text[digits];
185 while (width-- && maxlen)
187 *buf++ = (flags & ZEROPAD) ? '0' : ' ';
195 void AddInt(char **buf_p, size_t &maxlen, int val, int width, int flags)
201 unsigned int unsignedVal;
207 /* we want the unsigned version */
208 unsignedVal = abs(val);
214 text[digits++] = '0' + unsignedVal % 10;
216 } while (unsignedVal);
220 text[digits++] = '-';
225 if (!(flags & LADJUST))
227 while ((digits < width) && maxlen)
229 *buf++ = (flags & ZEROPAD) ? '0' : ' ';
235 while (digits-- && maxlen)
237 *buf++ = text[digits];
244 while (width-- && maxlen)
246 *buf++ = (flags & ZEROPAD) ? '0' : ' ';
254 size_t atcprintf(char *buffer, size_t maxlen, const char *format, IPluginContext *pCtx, const cell_t *params, int *param)
257 //int args = params[0] / sizeof(cell); //:TODO: wrong, i think params[0] has now the param count not the byte count
258 // either way this is only used when the above macro is fixed, until then not needed
267 size_t llen = maxlen - 1;
275 // run through the format string until we hit a '%' or '\0'
276 for (ch = *fmt; llen && ((ch = *fmt) != '\0') && (ch != '%'); fmt++)
281 if ((ch == '\0') || (llen <= 0))
289 // reset formatting state
308 while(is_digit((ch = *fmt++)))
310 n = 10 * n + (ch - '0');
312 prec = (n < 0) ? -1 : n;
333 n = 10 * n + (ch - '0');
335 } while(is_digit(ch));
347 pCtx->LocalToString(params[arg], &c);
358 pCtx->LocalToPhysAddr(params[arg], &value);
359 AddInt(&buf_p, llen, static_cast<int>(*value), width, flags);
367 pCtx->LocalToPhysAddr(params[arg], &value);
368 AddUInt(&buf_p, llen, static_cast<unsigned int>(*value), width, flags);
376 pCtx->LocalToPhysAddr(params[arg], &value);
377 AddFloat(&buf_p, llen, sp_ctof(*value), width, prec);
385 pCtx->LocalToString(params[arg], &str);
386 AddString(&buf_p, llen, str, width, prec);
426 return (maxlen - llen - 1);
429 const char *stristr(const char *str, const char *substr)
433 return ((char *)str);
436 char *needle = (char *)substr;
437 char *prevloc = (char *)str;
438 char *haystack = (char *)str;
442 if (tolower(*haystack) == tolower(*needle))
450 haystack = ++prevloc;
451 needle = (char *)substr;
458 unsigned int strncopy(char *dest, const char *src, size_t count)
466 while ((*src) && (--count))
472 return (dest - start);