work in progress - refactoring fmtout

This commit is contained in:
hyunghwan.chung 2019-05-27 17:50:24 +00:00
parent ea9f9b81e1
commit 57c30e4563
9 changed files with 1882 additions and 1356 deletions

View File

@ -69,6 +69,7 @@ libmoo_la_SOURCES = \
dic.c \
err.c \
exec.c \
fmt.c \
fmtout.c \
fmtoutv.h \
gc.c \

View File

@ -159,12 +159,12 @@ LTLIBRARIES = $(pkglib_LTLIBRARIES)
am__DEPENDENCIES_1 =
am_libmoo_la_OBJECTS = libmoo_la-bigint.lo libmoo_la-comp.lo \
libmoo_la-debug.lo libmoo_la-decode.lo libmoo_la-dic.lo \
libmoo_la-err.lo libmoo_la-exec.lo libmoo_la-fmtout.lo \
libmoo_la-gc.lo libmoo_la-heap.lo libmoo_la-mb8.lo \
libmoo_la-moo.lo libmoo_la-number.lo libmoo_la-obj.lo \
libmoo_la-pf-basic.lo libmoo_la-pf-sys.lo libmoo_la-pf-utf8.lo \
libmoo_la-rbt.lo libmoo_la-sym.lo libmoo_la-utf8.lo \
libmoo_la-utf16.lo libmoo_la-utl.lo
libmoo_la-err.lo libmoo_la-exec.lo libmoo_la-fmt.lo \
libmoo_la-fmtout.lo libmoo_la-gc.lo libmoo_la-heap.lo \
libmoo_la-mb8.lo libmoo_la-moo.lo libmoo_la-number.lo \
libmoo_la-obj.lo libmoo_la-pf-basic.lo libmoo_la-pf-sys.lo \
libmoo_la-pf-utf8.lo libmoo_la-rbt.lo libmoo_la-sym.lo \
libmoo_la-utf8.lo libmoo_la-utf16.lo libmoo_la-utl.lo
libmoo_la_OBJECTS = $(am_libmoo_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@ -406,6 +406,7 @@ pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
@ -465,6 +466,7 @@ libmoo_la_SOURCES = \
dic.c \
err.c \
exec.c \
fmt.c \
fmtout.c \
fmtoutv.h \
gc.c \
@ -607,6 +609,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-dic.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-err.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-exec.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-fmt.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-fmtout.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-gc.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-heap.Plo@am__quote@
@ -699,6 +702,13 @@ libmoo_la-exec.lo: exec.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-exec.lo `test -f 'exec.c' || echo '$(srcdir)/'`exec.c
libmoo_la-fmt.lo: fmt.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-fmt.lo -MD -MP -MF $(DEPDIR)/libmoo_la-fmt.Tpo -c -o libmoo_la-fmt.lo `test -f 'fmt.c' || echo '$(srcdir)/'`fmt.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-fmt.Tpo $(DEPDIR)/libmoo_la-fmt.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='fmt.c' object='libmoo_la-fmt.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-fmt.lo `test -f 'fmt.c' || echo '$(srcdir)/'`fmt.c
libmoo_la-fmtout.lo: fmtout.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-fmtout.lo -MD -MP -MF $(DEPDIR)/libmoo_la-fmtout.Tpo -c -o libmoo_la-fmtout.lo `test -f 'fmtout.c' || echo '$(srcdir)/'`fmtout.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-fmtout.Tpo $(DEPDIR)/libmoo_la-fmtout.Plo

1761
moo/lib/fmt.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -427,43 +427,8 @@ static int print_object (moo_t* moo, moo_bitmask_t mask, moo_oop_t oop, moo_outb
}
else if (c == moo->_fixed_point_decimal)
{
#if 1
if (!moo_numtostr(moo, oop, 10 | MOO_NUMTOSTR_NONEWOBJ)) return -1;
if (outbfmt(moo, mask, "%.*js", moo->inttostr.xbuf.len, moo->inttostr.xbuf.ptr) <= -1) return -1;
#else
moo_ooch_t* ptr;
moo_oow_t len;
moo_ooi_t scale;
if (!moo_inttostr(moo, ((moo_oop_fpdec_t)oop)->value, 10 | MOO_INTTOSTR_NONEWOBJ)) return -1;
ptr = moo->inttostr.xbuf.ptr;
len = moo->inttostr.xbuf.len;
if (ptr[0] == '-')
{
if (outbfmt(moo, mask, "-") <= -1) return -1;
ptr++;
len--;
}
scale = MOO_OOP_TO_SMOOI(((moo_oop_fpdec_t)oop)->scale);
if (scale >= len)
{
moo_oow_t i;
if (outbfmt(moo, mask, "0.") <= -1) return -1;
for (i = len; i < scale; i++)
{
if (outbfmt(moo, mask, "0") <= -1) return -1;
}
if (outbfmt(moo, mask, "%.*js", len, ptr) <= -1) return -1;
}
else
{
if (outbfmt(moo, mask, "%.*js.%.*js", len - scale, &ptr[0], scale, &ptr[len - scale]) <= -1) return -1;
}
#endif
}
else if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_CHAR)
{
@ -618,6 +583,7 @@ static int print_object (moo_t* moo, moo_bitmask_t mask, moo_oop_t oop, moo_outb
/* ------------------------------------------------------------------------- */
#undef FMTCHAR_IS_BCH
#undef FMTCHAR_IS_UCH
#undef FMTCHAR_IS_OOCH
@ -655,6 +621,8 @@ static int _logufmtv (moo_t* moo, const moo_uch_t* fmt, moo_fmtout_data_t* data,
return __logufmtv(moo, fmt, data, ap, moo_logbfmt);
}
#if 0
moo_ooi_t moo_logbfmt (moo_t* moo, moo_bitmask_t mask, const moo_bch_t* fmt, ...)
{
int x;
@ -726,7 +694,7 @@ moo_ooi_t moo_logufmt (moo_t* moo, moo_bitmask_t mask, const moo_uch_t* fmt, ...
return (x <= -1)? -1: fo.count;
}
#endif
/* --------------------------------------------------------------------------
* ERROR MESSAGE FORMATTING

View File

@ -422,6 +422,8 @@ typedef struct moo_bcs_t moo_bcs_t;
# define MOO_SIZEOF_OOCH_T MOO_SIZEOF_BCH_T
#endif
typedef unsigned int moo_bitmask_t;
/* =========================================================================
* BASIC OOP ENCODING
* ========================================================================= */

View File

@ -29,7 +29,6 @@
#include "moo.h"
#include "moo-utl.h"
#include <stdarg.h>
/* you can define this to either 1 or 2 */
#define MOO_BCODE_LONG_PARAM_SIZE 2

View File

@ -28,6 +28,7 @@
#define _MOO_UTL_H_
#include "moo-cmn.h"
#include <stdarg.h>
/* =========================================================================
* DOUBLY LINKED LIST
@ -294,6 +295,52 @@ enum moo_cmgr_id_t
};
typedef enum moo_cmgr_id_t moo_cmgr_id_t;
/* =========================================================================
* FORMATTED OUTPUT
* ========================================================================= */
typedef struct moo_fmtout_t moo_fmtout_t;
typedef int (*moo_fmtout_putbcs_t) (
moo_fmtout_t* fmtout,
const moo_bch_t* ptr,
moo_oow_t len
);
typedef int (*moo_fmtout_putucs_t) (
moo_fmtout_t* fmtout,
const moo_uch_t* ptr,
moo_oow_t len
);
typedef int (*moo_fmtout_putobj_t) (
moo_fmtout_t* fmtout,
moo_oop_t obj;
);
enum moo_fmtout_fmt_type_t
{
MOO_FMTOUT_FMT_TYPE_BCH = 0,
MOO_FMTOUT_FMT_TYPE_UCH
};
typedef enum moo_fmtout_fmt_type_t moo_fmtout_fmt_type_t;
struct moo_fmtout_t
{
moo_oow_t count; /* out */
moo_fmtout_putbcs_t putbcs; /* in */
moo_fmtout_putucs_t putucs; /* in */
moo_fmtout_putobj_t putobj; /* in - %O is not handled if it's not set. */
moo_bitmask_t mask; /* in */
void* ctx; /* in */
moo_fmtout_fmt_type_t fmt_type;
const void* fmt_str;
};
#if defined(__cplusplus)
extern "C" {
#endif
@ -805,6 +852,34 @@ MOO_EXPORT moo_oow_t moo_mb8_to_uc (
moo_uch_t* uc
);
/* =========================================================================
* FORMATTED OUTPUT
* ========================================================================= */
MOO_EXPORT int moo_bfmt_outv (
moo_fmtout_t* fmtout,
const moo_bch_t* fmt,
va_list ap
);
MOO_EXPORT int moo_ufmt_outv (
moo_fmtout_t* fmtout,
const moo_uch_t* fmt,
va_list ap
);
MOO_EXPORT int moo_bfmt_out (
moo_fmtout_t* fmtout,
const moo_bch_t* fmt,
...
);
MOO_EXPORT int moo_ufmt_out (
moo_fmtout_t* fmtout,
const moo_uch_t* fmt,
...
);
/* =========================================================================
* BIT SWAP
* ========================================================================= */

View File

@ -40,7 +40,6 @@
typedef struct moo_mod_t moo_mod_t;
typedef unsigned int moo_bitmask_t;
/* ========================================================================== */

File diff suppressed because it is too large Load Diff