#include <stdio.h>
#include <string.h>
-#include "lc_defines.h"
+#include "util.h"
#include "lc_printf.h"
/* Default appendable implementations */
static int str_snadd(lc_appendable_t *obj, const char *str, size_t n)
{
- size_t to_write = LC_MIN(obj->limit - obj->written - 1, n);
+ size_t to_write = MIN(obj->limit - obj->written - 1, n);
char *tgt = (char*)obj->obj;
strncpy(tgt + obj->written, str, to_write);
obj->written += to_write;
+++ /dev/null
-/*
- libcore: library for basic data structures and algorithms.
- Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-
-/**
- * Central definitions for the libcore.
- * @author Sebastian Hack
- * @date 22.12.2004
- */
-#ifndef _LC_CONFIG_H
-#define _LC_CONFIG_H
-
-#if defined(__GNUC__)
-
-#define inline __inline__
-#define LC_FUNCNAME __FUNCTION__
-#define LC_PRINTF(m) __attribute__((format(printf,m,(m)+1)))
-
-#ifdef __STRICT_ANSI__
-#define LC_LONGLONG long
-#define LC_LONGDOUBLE double
-#else
-#define LC_LONGLONG long long
-#define LC_LONGDOUBLE long double
-#endif
-
-#elif defined(_MSC_VER)
-
-#define LC_FUNCNAME "<unknown>"
-#define LC_PRINTF(m)
-
-#define LC_LONGLONG __int64
-#define LC_LONGDOUBLE long double
-
-/* disable warning: 'foo' was declared deprecated, use 'bla' instead */
-/* of course MS had to make 'bla' incompatible to 'foo', so a simple */
-/* define will not work :-((( */
-#pragma warning( disable : 4996 )
-
-#ifdef _WIN32
-#define snprintf _snprintf
-#endif /* _WIN32 */
-
-#if _MSC_VER <= 1200
-typedef __int16 int16;
-typedef __int32 int32;
-typedef __int64 int64;
-typedef unsigned __int16 uint16;
-typedef unsigned __int32 uint32;
-typedef unsigned __int64 uint64;
-#endif /* _MSC_VER <= 1200 */
-
-/* default definitions */
-#else /* !defined(__GNUC__) && !defined(_MSC_VER) */
-
-#define inline
-#define LC_FUNCNAME "<unknown>"
-#define LC_LONGLONG long
-#define LC_LONGDOUBLE double
-#define LC_PRINTF(m)
-
-#endif
-
-#endif /* _LC_CONFIG_H */
+++ /dev/null
-/*
- libcore: library for basic data structures and algorithms.
- Copyright (C) 2005 IPD Goos, Universit"at Karlsruhe, Germany
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-
-/**
- * Some common defines.
- * @author Sebastian Hack
- * @date 22.12.2004
- */
-
-#ifndef _LIBCORE_DEFINES_H
-#define _LIBCORE_DEFINES_H
-
-#define LC_ARRSIZE(x) (sizeof(x) / sizeof(x[0]))
-
-#define LC_MIN(x,y) ((x) < (y) ? (x) : (y))
-#define LC_MAX(x,y) ((x) > (y) ? (x) : (y))
-
-/** define a readable fourcc code */
-#define LC_FOURCC(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
-#define LC_FOURCC_STR(str) LC_FOURCC(str[0], str[1], str[2], str[3])
-
-#endif
#include "lc_opts_enum.h"
#include "hashptr.h"
#include "lc_printf.h"
+#include "util.h"
#include "xmalloc.h"
#include "obst.h"
case lc_opt_type_bit:
case lc_opt_type_negbit:
strtolower(buf, sizeof(buf), value);
- for (i = 0; i < LC_ARRSIZE(bool_strings); ++i) {
+ for (i = 0; i < ARRAY_SIZE(bool_strings); ++i) {
if (strcmp(buf, bool_strings[i].str) == 0) {
val->integer = bool_strings[i].val;
error = lc_opt_err_none;
#include "lc_opts.h"
#include "list.h"
-#include "lc_defines.h"
-
typedef struct {
struct list_head opts;
struct list_head grps;
#include "xmalloc.h"
#include "lc_printf.h"
-#include "lc_defines.h"
#include "hashptr.h"
+#include "util.h"
#include "set.h"
/* printf implementation */
if (!occ->flag_minus && occ->flag_zero)
pad = '0';
- return lc_appendable_snwadd(app, str, len, LC_MAX(0, occ->width), occ->flag_minus, pad);
+ return lc_appendable_snwadd(app, str, len, MAX(0, occ->width), occ->flag_minus, pad);
}
assert(occ->modifier && "modifier must not be NULL");
strncpy(mod, occ->modifier, sizeof(mod) - 1);
- mod[LC_MIN(sizeof(mod) - 1, occ->modifier_length)] = '\0';
+ mod[MIN(sizeof(mod) - 1, occ->modifier_length)] = '\0';
#ifdef _MSC_VER
/* work-around for buggy mscrt not supporting z, j, and t modifier */
default:
{
- int len = LC_MAX(128, occ->width + 1);
+ int len = MAX(128, occ->width + 1);
char *buf = XMALLOCN(char, len);
res = dispatch_snprintf(buf, len, fmt, occ->lc_arg_type, val);
res = lc_appendable_snadd(app, buf, res);
/* Negative or lacking precision after a '.' is treated as
* precision 0. */
- occ.precision = LC_MAX(0, precision);
+ occ.precision = MAX(0, precision);
}
/*
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
-
/**
* Flexible printf().
* @author Sebastian Hack
* @date 3.1.2005
*/
-
#ifndef _LIBCORE_LC_PRINTF_H
#define _LIBCORE_LC_PRINTF_H
#include <obstack.h>
-#include "lc_config.h"
#include "lc_appendable.h"
typedef struct lc_arg_occ_t {
int lc_evfprintf(const lc_arg_env_t *env, FILE *f, const char *fmt, va_list args);
int lc_evoprintf(const lc_arg_env_t *env, struct obstack *obst, const char *fmt, va_list args);
-int lc_printf(const char *fmt, ...) LC_PRINTF(1);
-int lc_snprintf(char *buf, size_t len, const char *fmt, ...) LC_PRINTF(3);
-int lc_fprintf(FILE *f, const char *fmt, ...) LC_PRINTF(2);
-int lc_oprintf(struct obstack *obst, const char *fmt, ...) LC_PRINTF(2);
+int lc_printf(const char *fmt, ...);
+int lc_snprintf(char *buf, size_t len, const char *fmt, ...);
+int lc_fprintf(FILE *f, const char *fmt, ...);
+int lc_oprintf(struct obstack *obst, const char *fmt, ...);
int lc_vprintf(const char *fmt, va_list args);
int lc_vsnprintf(char *buf, size_t len, const char *fmt, va_list args);
LC_ARG_TYPE(short, short, int)
LC_ARG_TYPE(int, int, int)
LC_ARG_TYPE(long, long, long)
-LC_ARG_TYPE(LC_LONGLONG, long_long, LC_LONGLONG)
+LC_ARG_TYPE(long long, long_long, long long)
LC_ARG_TYPE(double, double, double)
-LC_ARG_TYPE(LC_LONGDOUBLE, long_double, LC_LONGDOUBLE)
+LC_ARG_TYPE(long double, long_double, long double)
LC_ARG_TYPE(void *, ptr, void *)
LC_ARG_TYPE(intmax_t, intmax_t, intmax_t)
LC_ARG_TYPE(ptrdiff_t, ptrdiff_t, ptrdiff_t)