#include <string.h>
#include <time.h>
-/* for testing purposes */
-#ifndef SIZEOF_VOID_P
-# warning SIZEOF_VOID_P not defined yet!
-# define SIZEOF_VOID_P 4
-# define SIZEOF_LONG 4
-#endif
-
/* Inhibit complaints when we use GCC extensions */
-#ifdef __GNUC__
+#if defined(__GNUC__) && defined(HAVE_LONG_LONG)
# define EXTENSION __extension__
#else
# define EXTENSION
size_t buf_size; /* maximum size of buffer */
size_t buf_overflow; /* how much buffer has been overflowed */
size_t buf_loc; /* where we are in the buffer */
- size_t limit; /* max # of chars to convert */
+ short limit; /* max # of chars to convert */
size_t overflow; /* how much we overflowed the limit */
};
};
/* Add a character to the buffer */
-static __inline__ void
+static void
addc(struct BufData *buf_p, int c)
{
int overflow = 0;
}
/* Add a string to the buffer */
-static __inline__ void
+static void
adds(struct BufData *buf_p, int s_len, const char *s)
{
int overflow = 0;
}
/* Add padding */
-static __inline__ void
+static void
do_pad(struct BufData *buf_p, int padlen, char *pad)
{
/* do chunks of PAD_LENGTH first */
}
/* Find string length up to maxlen */
-static __inline__ int
+static int
my_strnlen(const char *str, int maxlen)
{
int len = 0;
if (state <= OPT) {
state = OPT;
if (fld_s.flags & TYPE_LONG) /* We support 'll' */
- fld_s.flags |= TYPE_QUAD;
+ fld_s.flags |= TYPE_QUAD | TYPE_LONGDOUBLE;
else if (!(fld_s.flags & TYPE_MASK))
fld_s.flags |= TYPE_LONG;
}
continue;
- case 'q': /* it's a quad */
- if (state <= OPT) {
- state = OPT;
- if (!(fld_s.flags & TYPE_MASK))
- fld_s.flags |= TYPE_QUAD;
- }
- continue;
-
- case 'L': /* it's a quad or long double */
+ case 'q': case 'L': /* it's a quad or long double */
if (state <= OPT) {
state = OPT;
if (!(fld_s.flags & TYPE_MASK))
char intbuf[INTBUF_LEN], **table = 0, *tstr;
int ibuf_loc = INTBUF_LEN, ilen, zlen = 0, plen = 0, elen = 0;
- if (fld_s.prec < 0) /* default precision is 1 */
- fld_s.prec = 1;
-
if (fld_s.base == BASE_OCTAL) /* select string table to use */
table = octal;
else if (fld_s.base == BASE_DECIMAL)
elen = 2; /* account for the length of 0x */
}
+ if (fld_s.prec < 0) { /* default precision is 1 */
+ if ((fld_s.flags & (FLAG_MINUS | FLAG_ZERO)) == FLAG_ZERO &&
+ fld_s.width) {
+ fld_s.prec = fld_s.width - elen;
+ fld_s.width = 0;
+ } else
+ fld_s.prec = 1;
+ }
+
/* If there's a sign flag, account for it */
if (fld_s.flags & (FLAG_PLUS | FLAG_SPACE | INFO_NEGATIVE))
elen++;
} else if ((fld_s.flags & CONV_MASK) == CONV_STRING ||
fld_s.value.v_ptr == 0) { /* spaces or null pointers */
int slen, plen;
- char *str = fld_s.value.v_ptr;
+ char *str = (char*) fld_s.value.v_ptr;
if (!str) /* NULL pointers print "(null)" */
str = "(null)";
do_pad(buf_p, plen, spaces); /* post-padding */
} else if ((fld_s.flags & CONV_MASK) == CONV_VARARGS) {
struct BufData buf_s = BUFDATA_INIT;
- struct VarData *vdata = fld_s.value.v_ptr;
+ struct VarData *vdata = (struct VarData*) fld_s.value.v_ptr;
int plen, tlen;
buf_s.buf = buf_p->buf + buf_p->buf_loc;
vdata->vd_chars = buf_s.buf_loc; /* return relevant data */
vdata->vd_overflow = SNP_MAX(buf_s.buf_overflow, buf_s.overflow);
} else if ((fld_s.flags & CONV_MASK) == CONV_CLIENT) {
- struct Client *cptr = fld_s.value.v_ptr;
+ struct Client *cptr = (struct Client*) fld_s.value.v_ptr;
char *str1 = 0, *str2 = 0;
int slen1 = 0, slen2 = 0, plen = 0;
- if (IsServer(dest)) {
- if (IsServer(cptr))
+ /* &me is used if it's not a definite server */
+ if (dest && (IsServer(dest) || IsMe(dest))) {
+ if (IsServer(cptr) || IsMe(cptr))
str1 = cptr->yxx;
else {
str1 = cptr->user->server->yxx;