* actually print args for %g and %e
*
* Hrvoje Niksic <hniksic@xemacs.org> 2005-04-15
- * use the PARAMS macro to handle prototypes.
* write function definitions in the ansi2knr-friendly way.
* if string precision is specified, don't read VALUE past it.
* fix bug in fmtfp that caused 0.01 to be printed as 0.1.
#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
-#ifdef HAVE_STRING_H
-# include <string.h>
-#else
-# include <strings.h>
-#endif
+#include <string.h>
#include <sys/types.h>
#include <stdio.h> /* for NULL */
-/* varargs declarations: */
-
-#if defined(HAVE_STDARG_H)
-# include <stdarg.h>
-# define HAVE_STDARGS /* let's hope that works everywhere (mj) */
-# define VA_LOCAL_DECL va_list ap
-# define VA_START(f) va_start(ap, f)
-# define VA_SHIFT(v,t) ; /* no-op for ANSI */
-# define VA_END va_end(ap)
-#else
-# include <varargs.h>
-# undef HAVE_STDARGS
-# define VA_LOCAL_DECL va_list ap
-# define VA_START(f) va_start(ap) /* f is ignored! */
-# define VA_SHIFT(v,t) v = va_arg(ap,t)
-# define VA_END va_end(ap)
-#endif
+#include <stdarg.h>
#ifdef HAVE_LONG_DOUBLE
#define LDOUBLE long double
# define vsnprintf test_vsnprintf
#endif
-#ifdef HAVE_STDARGS
int snprintf (char *str, size_t count, const char *fmt, ...);
int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
-#else
-int snprintf ();
-int vsnprintf ();
-#endif
-
-#ifndef PARAMS
-# define PARAMS(x) x
-#endif
-static int dopr PARAMS ((char *buffer, size_t maxlen, const char *format,
- va_list args));
-static int fmtstr PARAMS ((char *buffer, size_t *currlen, size_t maxlen,
- char *value, int flags, int min, int max));
-static int fmtint PARAMS ((char *buffer, size_t *currlen, size_t maxlen,
- LLONG value, int base, int min, int max, int flags));
-static int fmtfp PARAMS ((char *buffer, size_t *currlen, size_t maxlen,
- LDOUBLE fvalue, int min, int max, int flags));
-static int dopr_outch PARAMS ((char *buffer, size_t *currlen, size_t maxlen,
- char c));
+static int dopr (char *buffer, size_t maxlen, const char *format,
+ va_list args);
+static int fmtstr (char *buffer, size_t *currlen, size_t maxlen,
+ const char *value, int flags, int min, int max);
+static int fmtint (char *buffer, size_t *currlen, size_t maxlen,
+ LLONG value, int base, int min, int max, int flags);
+static int fmtfp (char *buffer, size_t *currlen, size_t maxlen,
+ LDOUBLE fvalue, int min, int max, int flags);
+static int dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c);
/*
* dopr(): poor man's version of doprintf
#define MAX(p,q) ((p >= q) ? p : q)
#define MIN(p,q) ((p <= q) ? p : q)
-static int
-dopr (char *buffer, size_t maxlen, const char *format, va_list args)
+static int dopr (char *buffer, size_t maxlen, const char *format, va_list args)
{
char ch;
LLONG value;
return total;
}
-static int
-fmtstr (char *buffer, size_t *currlen, size_t maxlen,
- char *value, int flags, int min, int max)
+static int fmtstr (char *buffer, size_t *currlen, size_t maxlen,
+ const char *value, int flags, int min, int max)
{
int padlen, strln; /* amount to pad */
int cnt = 0;
/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
-static int
-fmtint (char *buffer, size_t *currlen, size_t maxlen,
- LLONG value, int base, int min, int max, int flags)
+static int fmtint (char *buffer, size_t *currlen, size_t maxlen,
+ LLONG value, int base, int min, int max, int flags)
{
int signvalue = 0;
unsigned LLONG uvalue;
return total;
}
-static LDOUBLE
-abs_val (LDOUBLE value)
+static LDOUBLE abs_val (LDOUBLE value)
{
LDOUBLE result = value;
return result;
}
-static LDOUBLE
-pow10 (int exp)
+static LDOUBLE pow10 (int exp)
{
LDOUBLE result = 1;
return result;
}
-static LLONG
-round (LDOUBLE value)
+static LLONG round (LDOUBLE value)
{
LLONG intpart;
return intpart;
}
-static int
-fmtfp (char *buffer, size_t *currlen, size_t maxlen,
- LDOUBLE fvalue, int min, int max, int flags)
+static int fmtfp (char *buffer, size_t *currlen, size_t maxlen,
+ LDOUBLE fvalue, int min, int max, int flags)
{
int signvalue = 0;
LDOUBLE ufvalue;
return total;
}
-static int
-dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c)
+static int dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c)
{
if (*currlen + 1 < maxlen)
buffer[(*currlen)++] = c;
}
#ifndef HAVE_VSNPRINTF
-int
-vsnprintf (char *str, size_t count, const char *fmt, va_list args)
+int vsnprintf (char *str, size_t count, const char *fmt, va_list args)
{
if (str != NULL)
str[0] = 0;
#endif /* !HAVE_VSNPRINTF */
#ifndef HAVE_SNPRINTF
-int
-snprintf (char *str, size_t count,const char *fmt,...)
+int snprintf (char *str, size_t count, const char *fmt,...)
{
-#ifndef HAVE_STDARGS
- char *str;
- size_t count;
- char *fmt;
-#endif
- VA_LOCAL_DECL;
+ va_list ap;
int total;
-
- VA_START (fmt);
- VA_SHIFT (str, char *);
- VA_SHIFT (count, size_t );
- VA_SHIFT (fmt, char *);
- total = vsnprintf(str, count, fmt, ap);
- VA_END;
+
+ va_start (ap, fmt);
+ total = vsnprintf (str, count, fmt, ap);
+ va_end (ap);
return total;
}
#endif /* !HAVE_SNPRINTF */
# define LONG_STRING 1024
# endif
-int
-main (void)
+int main (void)
{
char buf1[LONG_STRING];
char buf2[LONG_STRING];