moved the xma mmgr to std.c with the new function hawk_init_xma_mmgr() and hawk_fini_xma_mmgr()

This commit is contained in:
hyung-hwan 2025-06-03 21:53:33 +09:00
parent 2a03c6f061
commit 715085c778
28 changed files with 3298 additions and 720 deletions

View File

@ -30,8 +30,8 @@
#include <hawk-utl.h>
#include <hawk-fmt.h>
#include <hawk-cli.h>
#include <hawk-xma.h>
#include <hawk-glob.h>
#include <hawk-xma.h>
#if !defined(_GNU_SOURCE)
# define _GNU_SOURCE
@ -75,7 +75,6 @@
#endif
static hawk_rtx_t* app_rtx = HAWK_NULL;
static int app_debug = 0;
typedef struct gv_t gv_t;
typedef struct gvm_t gvm_t;
@ -123,11 +122,9 @@ struct arg_t
unsigned int classic: 1;
int opton;
int optoff;
int debug;
hawk_uintptr_t memlimit;
#if defined(HAWK_BUILD_DEBUG)
hawk_uintptr_t failmalloc;
#endif
};
@ -547,9 +544,6 @@ static void print_usage (FILE* out, const hawk_bch_t* argv0, const hawk_bch_t* r
fprintf (out, " -m/--memory-limit number limit the memory usage (bytes)\n");
fprintf (out, " -w expand datafile wildcards\n");
#if defined(HAWK_BUILD_DEBUG)
fprintf (out, " -X number fail the number'th memory allocation\n");
#endif
#if defined(HAWK_OOCH_IS_UCH)
fprintf (out, " --script-encoding string specify script file encoding name\n");
fprintf (out, " --console-encoding string specify console encoding name\n");
@ -674,7 +668,6 @@ static int process_argv (int argc, hawk_bch_t* argv[], const hawk_bch_t* real_ar
{ ":field-separator", 'F' },
{ ":assign", 'v' },
{ ":memory-limit", 'm' },
{ ":mode", 'M' },
{ ":script-encoding", '\0' },
{ ":console-encoding", '\0' },
@ -690,11 +683,7 @@ static int process_argv (int argc, hawk_bch_t* argv[], const hawk_bch_t* real_ar
static hawk_bcli_t opt =
{
#if defined(HAWK_BUILD_DEBUG)
"hDc:f:d:t:F:v:m:I:wX:",
#else
"hDc:f:d:t:F:v:m:I:w",
#endif
lng
};
@ -726,7 +715,7 @@ static int process_argv (int argc, hawk_bch_t* argv[], const hawk_bch_t* real_ar
goto oops;
case 'D':
app_debug = 1;
arg->debug = 1;
break;
case 'c':
@ -843,15 +832,6 @@ static int process_argv (int argc, hawk_bch_t* argv[], const hawk_bch_t* real_ar
break;
}
#if defined(HAWK_BUILD_DEBUG)
case 'X':
{
arg->failmalloc = strtoul(opt.arg, HAWK_NULL, 10);
break;
}
#endif
case '\0':
{
/* a long option with no corresponding short option */
@ -1033,89 +1013,12 @@ static void print_hawk_rtx_error (hawk_rtx_t* rtx)
);
}
static void* xma_alloc (hawk_mmgr_t* mmgr, hawk_oow_t size)
{
return hawk_xma_alloc(mmgr->ctx, size);
}
static void* xma_realloc (hawk_mmgr_t* mmgr, void* ptr, hawk_oow_t size)
{
return hawk_xma_realloc(mmgr->ctx, ptr, size);
}
static void xma_free (hawk_mmgr_t* mmgr, void* ptr)
{
hawk_xma_free (mmgr->ctx, ptr);
}
static hawk_mmgr_t xma_mmgr =
{
xma_alloc,
xma_realloc,
xma_free,
HAWK_NULL
};
static void xma_dumper_without_hawk (void* ctx, const hawk_bch_t* fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
}
#if defined(HAWK_BUILD_DEBUG)
static hawk_uintptr_t debug_mmgr_count = 0;
static hawk_uintptr_t debug_mmgr_alloc_count = 0;
static hawk_uintptr_t debug_mmgr_realloc_count = 0;
static hawk_uintptr_t debug_mmgr_free_count = 0;
static void* debug_mmgr_alloc (hawk_mmgr_t* mmgr, hawk_oow_t size)
{
void* ptr;
struct arg_t* arg = (struct arg_t*)mmgr->ctx;
debug_mmgr_count++;
if (debug_mmgr_count % arg->failmalloc == 0) return HAWK_NULL;
ptr = malloc (size);
if (ptr) debug_mmgr_alloc_count++;
return ptr;
}
static void* debug_mmgr_realloc (hawk_mmgr_t* mmgr, void* ptr, hawk_oow_t size)
{
void* rptr;
struct arg_t* arg = (struct arg_t*)mmgr->ctx;
debug_mmgr_count++;
if (debug_mmgr_count % arg->failmalloc == 0) return HAWK_NULL;
rptr = realloc (ptr, size);
if (rptr)
{
if (ptr) debug_mmgr_realloc_count++;
else debug_mmgr_alloc_count++;
}
return rptr;
}
static void debug_mmgr_free (hawk_mmgr_t* mmgr, void* ptr)
{
debug_mmgr_free_count++;
free (ptr);
}
static hawk_mmgr_t debug_mmgr =
{
debug_mmgr_alloc,
debug_mmgr_realloc,
debug_mmgr_free,
HAWK_NULL
};
#endif
static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[], const hawk_bch_t* real_argv0)
{
hawk_t* hawk = HAWK_NULL;
hawk_rtx_t* rtx = HAWK_NULL;
hawk_val_t* retv;
hawk_mmgr_t xma_mmgr;
int i;
struct arg_t arg;
int ret = -1;
@ -1150,18 +1053,9 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[], const hawk_bc
psout.u.fileb.cmgr = arg.script_cmgr;
}
#if defined(HAWK_BUILD_DEBUG)
if (arg.failmalloc > 0)
{
debug_mmgr.ctx = &arg;
mmgr = &debug_mmgr;
}
else
#endif
if (arg.memlimit > 0)
{
xma_mmgr.ctx = hawk_xma_open(hawk_get_sys_mmgr(), 0, HAWK_NULL, arg.memlimit);
if (xma_mmgr.ctx == HAWK_NULL)
if (hawk_init_xma_mmgr(&xma_mmgr, arg.memlimit) <= -1)
{
print_error ("cannot open memory heap\n");
goto oops;
@ -1180,7 +1074,7 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[], const hawk_bc
if (arg.modern) i = HAWK_MODERN;
else if (arg.classic) i = HAWK_CLASSIC;
else hawk_getopt (hawk, HAWK_OPT_TRAIT, &i);
else hawk_getopt(hawk, HAWK_OPT_TRAIT, &i);
if (arg.opton) i |= arg.opton;
if (arg.optoff) i &= ~arg.optoff;
hawk_setopt (hawk, HAWK_OPT_TRAIT, &i);
@ -1293,7 +1187,7 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[], const hawk_bc
hawk_int_t tmp;
hawk_rtx_refdownval (rtx, retv);
if (app_debug) dprint_return (rtx, retv);
if (arg.debug) dprint_return (rtx, retv);
ret = 0;
if (hawk_rtx_valtoint(rtx, retv, &tmp) >= 0) ret = tmp;
@ -1310,27 +1204,13 @@ oops:
unset_intr_pipe ();
if (xma_mmgr.ctx)
if (arg.memlimit > 0)
{
if (app_debug) hawk_xma_dump (xma_mmgr.ctx, xma_dumper_without_hawk, HAWK_NULL);
hawk_xma_close (xma_mmgr.ctx);
if (arg.debug) hawk_xma_dump (xma_mmgr.ctx, main_xma_dumper_without_hawk, HAWK_NULL);
hawk_fini_xma_mmgr (&xma_mmgr);
}
freearg (&arg);
#if defined(HAWK_BUILD_DEBUG)
/*
if (arg.failmalloc > 0)
{
hawk_fprintf (HAWK_STDERR, HAWK_T("\n"));
hawk_fprintf (HAWK_STDERR, HAWK_T("-[MALLOC COUNTS]---------------------------------------\n"));
hawk_fprintf (HAWK_STDERR, HAWK_T("ALLOC: %lu FREE: %lu: REALLOC: %lu\n"),
(unsigned long)debug_mmgr_alloc_count,
(unsigned long)debug_mmgr_free_count,
(unsigned long)debug_mmgr_realloc_count);
hawk_fprintf (HAWK_STDERR, HAWK_T("-------------------------------------------------------\n"));
}*/
#endif
return ret;
}

View File

@ -26,8 +26,19 @@
#include "main.h"
#include <hawk.h>
#include <hawk-xma.h>
#include <stdio.h>
void main_xma_dumper_without_hawk (void* ctx, const hawk_bch_t* fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
}
/* -------------------------------------------------------- */
static int main_version(int argc, hawk_bch_t* argv[], const hawk_bch_t* real_argv0)
{
printf ("%s %s\n", hawk_get_base_name_bcstr(real_argv0), HAWK_PACKAGE_VERSION);

View File

@ -36,6 +36,8 @@ extern "C" {
int main_hawk(int argc, hawk_bch_t* argv[], const hawk_bch_t* real_argv0);
int main_sed(int argc, hawk_bch_t* argv[], const hawk_bch_t* real_argv0);
void main_xma_dumper_without_hawk (void* ctx, const hawk_bch_t* fmt, ...);
#if defined(__cplusplus)
}

174
bin/sed.c
View File

@ -23,13 +23,14 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "main.h"
#include <hawk-sed.h>
#include <hawk-xma.h>
#include <hawk-cli.h>
#include <hawk-fmt.h>
#include <hawk-utl.h>
#include <hawk-std.h>
#include <hawk-xma.h>
#if !defined(_GNU_SOURCE)
# define _GNU_SOURCE
@ -87,89 +88,14 @@ struct arg_t
int inplace;
int wildcard;
int debug;
#if defined(HAWK_ENABLE_SEDTRACER)
int trace;
#endif
hawk_uintptr_t memlimit;
#if defined(HAWK_BUILD_DEBUG)
hawk_uintptr_t failmalloc;
#endif
};
/* ------------------------------------------------------------------- */
static void* xma_alloc (hawk_mmgr_t* mmgr, hawk_oow_t size)
{
return hawk_xma_alloc (mmgr->ctx, size);
}
static void* xma_realloc (hawk_mmgr_t* mmgr, void* ptr, hawk_oow_t size)
{
return hawk_xma_realloc (mmgr->ctx, ptr, size);
}
static void xma_free (hawk_mmgr_t* mmgr, void* ptr)
{
hawk_xma_free (mmgr->ctx, ptr);
}
static hawk_mmgr_t xma_mmgr =
{
xma_alloc,
xma_realloc,
xma_free,
HAWK_NULL
};
/* ------------------------------------------------------------------- */
#if defined(HAWK_BUILD_DEBUG)
static hawk_uintptr_t debug_mmgr_count = 0;
static hawk_uintptr_t debug_mmgr_alloc_count = 0;
static hawk_uintptr_t debug_mmgr_realloc_count = 0;
static hawk_uintptr_t debug_mmgr_free_count = 0;
static void* debug_mmgr_alloc (hawk_mmgr_t* mmgr, hawk_oow_t size)
{
void* ptr;
struct arg_t* arg = (struct arg_t*)mmgr->ctx;
debug_mmgr_count++;
if (debug_mmgr_count % arg->failmalloc == 0) return HAWK_NULL;
ptr = malloc(size);
if (ptr) debug_mmgr_alloc_count++;
return ptr;
}
static void* debug_mmgr_realloc (hawk_mmgr_t* mmgr, void* ptr, hawk_oow_t size)
{
void* rptr;
struct arg_t* arg = (struct arg_t*)mmgr->ctx;
debug_mmgr_count++;
if (debug_mmgr_count % arg->failmalloc == 0) return HAWK_NULL;
rptr = realloc(ptr, size);
if (rptr)
{
if (ptr) debug_mmgr_realloc_count++;
else debug_mmgr_alloc_count++;
}
return rptr;
}
static void debug_mmgr_free (hawk_mmgr_t* mmgr, void* ptr)
{
debug_mmgr_free_count++;
free (ptr);
}
static hawk_mmgr_t debug_mmgr =
{
debug_mmgr_alloc,
debug_mmgr_realloc,
debug_mmgr_free,
HAWK_NULL
};
#endif
/* ------------------------------------------------------------------- */
static void print_error (const hawk_bch_t* fmt, ...)
@ -201,33 +127,31 @@ static void print_usage (FILE* out, const hawk_bch_t* argv0, const hawk_bch_t* r
fprintf (out, " %s%s%s [options] -e script [file]\n", b1, b2, b3);
fprintf (out, "Options as follows:\n");
fprintf (out, " -h/--help show this message\n");
fprintf (out, " -n disable auto-print\n");
fprintf (out, " -e script specify a script\n");
fprintf (out, " -f file specify a script file\n");
fprintf (out, " -o file specify an output file\n");
fprintf (out, " -r use the extended regular expression\n");
fprintf (out, " -R enable non-standard extensions to the regular\n");
fprintf (out, " expression\n");
fprintf (out, " -i perform in-place editing. imply -s\n");
fprintf (out, " -s process input files separately\n");
fprintf (out, " -a perform strict address and label check\n");
fprintf (out, " -b allow extended address formats\n");
fprintf (out, " <start~step>,<start,+line>,<start,~line>,<0,/regex/>\n");
fprintf (out, " -x allow text on the same line as c, a, i\n");
fprintf (out, " -y ensure a newline at text end\n");
fprintf (out, " -m number specify the maximum amount of memory to use in bytes\n");
fprintf (out, " -w expand file wildcards\n");
fprintf (out, " -h/--help show this message\n");
fprintf (out, " -D show extra information\n");
fprintf (out, " -n disable auto-print\n");
fprintf (out, " -e script specify a script\n");
fprintf (out, " -f file specify a script file\n");
fprintf (out, " -o file specify an output file\n");
fprintf (out, " -r use the extended regular expression\n");
fprintf (out, " -R enable non-standard extensions to the regular\n");
fprintf (out, " expression\n");
fprintf (out, " -i perform in-place editing. imply -s\n");
fprintf (out, " -s process input files separately\n");
fprintf (out, " -a perform strict address and label check\n");
fprintf (out, " -b allow extended address formats\n");
fprintf (out, " <start~step>,<start,+line>,<start,~line>,<0,/regex/>\n");
fprintf (out, " -x allow text on the same line as c, a, i\n");
fprintf (out, " -y ensure a newline at text end\n");
fprintf (out, " -m/--memory-limit number specify the maximum amount of memory to use in bytes\n");
fprintf (out, " -w expand file wildcards\n");
#if defined(HAWK_ENABLE_SEDTRACER)
fprintf (out, " -t print command traces\n");
#endif
#if defined(HAWK_BUILD_DEBUG)
fprintf (out, " -X number fail the number'th memory allocation\n");
fprintf (out, " -t print command traces\n");
#endif
#if defined(HAWK_OOCH_IS_UCH)
fprintf (out, " --script-encoding string specify script file encoding name\n");
fprintf (out, " --infile-encoding string specify input file encoding name\n");
fprintf (out, " --outfile-encoding string specify output file encoding name\n");
fprintf (out, " --script-encoding string specify script file encoding name\n");
fprintf (out, " --infile-encoding string specify input file encoding name\n");
fprintf (out, " --outfile-encoding string specify output file encoding name\n");
#endif
}
@ -288,17 +212,13 @@ static int handle_args (int argc, hawk_bch_t* argv[], const hawk_bch_t* real_arg
{ ":infile-encoding", '\0' },
{ ":outfile-encoding", '\0' },
#endif
{ ":memory-limit", 'm' },
{ "help", 'h' },
{ HAWK_NULL, '\0' }
};
static hawk_bcli_t opt =
{
#if defined(HAWK_BUILD_DEBUG)
"hne:f:o:rRisabxytm:wX:",
#else
"hne:f:o:rRisabxytm:w",
#endif
"hDne:f:o:rRisabxytm:w",
lng
};
hawk_bci_t c;
@ -325,6 +245,10 @@ static int handle_args (int argc, hawk_bch_t* argv[], const hawk_bch_t* real_arg
print_usage (stdout, argv[0], real_argv0);
goto done;
case 'D':
arg->debug = 1;
break;
case 'n':
arg->option |= HAWK_SED_QUIET;
break;
@ -390,12 +314,6 @@ static int handle_args (int argc, hawk_bch_t* argv[], const hawk_bch_t* real_arg
arg->wildcard = 1;
break;
#if defined(HAWK_BUILD_DEBUG)
case 'X':
arg->failmalloc = strtoul(opt.arg, HAWK_NULL, 10);
break;
#endif
case '\0':
{
if (hawk_comp_bcstr(opt.lngopt, "script-encoding", 0) == 0)
@ -790,6 +708,7 @@ static HAWK_INLINE int execute_sed (int argc, hawk_bch_t* argv[], const hawk_bch
int xarg_inited = 0;
hawk_mmgr_t* mmgr = hawk_get_sys_mmgr();
hawk_cmgr_t* cmgr = hawk_get_cmgr_by_id(HAWK_CMGR_UTF8);
hawk_mmgr_t xma_mmgr;
memset (&arg, 0, HAWK_SIZEOF(arg));
ret = handle_args(argc, argv, real_argv0, &arg);
@ -798,18 +717,9 @@ static HAWK_INLINE int execute_sed (int argc, hawk_bch_t* argv[], const hawk_bch
ret = -1;
#if defined(HAWK_BUILD_DEBUG)
if (arg.failmalloc > 0)
{
debug_mmgr.ctx = &arg;
mmgr = &debug_mmgr;
}
else
#endif
if (arg.memlimit > 0)
{
xma_mmgr.ctx = hawk_xma_open(hawk_get_sys_mmgr(), 0, HAWK_NULL, arg.memlimit);
if (xma_mmgr.ctx == HAWK_NULL)
if (hawk_init_xma_mmgr(&xma_mmgr, arg.memlimit) <= -1)
{
print_error ("cannot open memory heap\n");
goto oops;
@ -1085,21 +995,13 @@ static HAWK_INLINE int execute_sed (int argc, hawk_bch_t* argv[], const hawk_bch
oops:
if (xarg_inited) purge_xarg (&xarg);
if (sed) hawk_sed_close (sed);
if (xma_mmgr.ctx) hawk_xma_close (xma_mmgr.ctx);
if (arg.memlimit > 0)
{
if (arg.debug) hawk_xma_dump (xma_mmgr.ctx, main_xma_dumper_without_hawk, HAWK_NULL);
hawk_fini_xma_mmgr (&xma_mmgr);
}
free_scripts ();
#if defined(HAWK_BUILD_DEBUG)
if (arg.failmalloc > 0)
{
fprintf (stderr, "\n");
fprintf (stderr, "-[MALLOC COUNTS]---------------------------------------\n");
fprintf (stderr, "ALLOC: %lu FREE: %lu: REALLOC: %lu\n",
(unsigned long)debug_mmgr_alloc_count,
(unsigned long)debug_mmgr_free_count,
(unsigned long)debug_mmgr_realloc_count);
fprintf (stderr, "-------------------------------------------------------\n");
}
#endif
return ret;
}

View File

@ -231,7 +231,7 @@ public:
///
/// The getErrorNumber() function gets the number of the last
/// error occurred. It returns HAWK_SED_ENOERR if the stream editor
/// error occurred. It returns HAWK_ENOERR if the stream editor
/// has not been initialized with the open() function.
///
hawk_errnum_t getErrorNumber () const;

View File

@ -55,6 +55,7 @@ pkginclude_HEADERS = \
hawk-chr.h \
hawk-cli.h \
hawk-cmn.h \
hawk-cut.h \
hawk-dir.h \
hawk-ecs.h \
hawk-fio.h \
@ -90,6 +91,8 @@ libhawk_la_SOURCES = \
$(pkginclude_HEADERS) \
arr.c \
chr.c \
cut-prv.h \
cut.c \
dir.c \
ecs-imp.h \
ecs.c \
@ -169,6 +172,7 @@ libhawk_la_SOURCES += \
syscall.h \
tio.c \
std.c \
std-cut.c \
std-json.c \
std-sed.c

View File

@ -247,30 +247,30 @@ libhawk_la_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_6) $(am__DEPENDENCIES_7) \
$(am__DEPENDENCIES_8) $(am__DEPENDENCIES_9)
am__libhawk_la_SOURCES_DIST = hawk.h hawk-arr.h hawk-chr.h hawk-cli.h \
hawk-cmn.h hawk-dir.h hawk-ecs.h hawk-fio.h hawk-fmt.h \
hawk-gem.h hawk-glob.h hawk-htb.h hawk-json.h hawk-map.h \
hawk-mtx.h hawk-rbt.h hawk-pac1.h hawk-pio.h hawk-skad.h \
hawk-utl.h hawk-sed.h hawk-sio.h hawk-std.h hawk-str.h \
hawk-tio.h hawk-tre.h hawk-upac.h hawk-xma.h Hawk.hpp \
Hawk-Sed.hpp arr.c chr.c dir.c ecs-imp.h ecs.c err-prv.h err.c \
err-sys.c fmt-imp.h fmt.c fnc-prv.h fnc.c gem.c gem-glob.c \
gem-nwif.c gem-nwif2.c hawk-prv.h hawk.c htb.c idmap-imp.h \
json.c json-prv.h mb8.c misc-imp.h misc-prv.h misc.c \
parse-prv.h parse.c rbt.c rec.c rio-prv.h rio.c run-prv.h \
run.c sed-prv.h sed.c skad-prv.h skad.c tre-prv.h tre-ast.c \
tre-ast.h tre-compile.c tre-compile.h tre-match-bt.c \
tre-match-pa.c tre-match-ut.h tre-mem.c tre-mem.h tre-parse.c \
tre-parse.h tre-stack.h tre-stack.c tre.c tree-prv.h tree.c \
uch-prop.h uch-case.h utf16.c utf8.c utl-ass.c utl-cmgr.c \
utl-rnd.c utl-sort.c utl-str.c utl-sys.c utl-xstr.c utl.c \
val-prv.h val.c xma.c cli-imp.h cli.c fio.c mtx.c pio.c sio.c \
syscall.h tio.c std.c std-json.c std-sed.c Hawk.cpp Std.cpp \
Sed.cpp Std-Sed.cpp mod-hawk.c mod-hawk.h mod-math.c \
mod-math.h mod-str.c mod-str.h mod-sys.c mod-sys.h \
../mod/mod-ffi.c ../mod/mod-ffi.h ../mod/mod-memc.c \
../mod/mod-memc.h ../mod/mod-mysql.c ../mod/mod-mysql.h \
../mod/mod-sed.c ../mod/mod-sed.h ../mod/mod-uci.c \
../mod/mod-uci.h
hawk-cmn.h hawk-cut.h hawk-dir.h hawk-ecs.h hawk-fio.h \
hawk-fmt.h hawk-gem.h hawk-glob.h hawk-htb.h hawk-json.h \
hawk-map.h hawk-mtx.h hawk-rbt.h hawk-pac1.h hawk-pio.h \
hawk-skad.h hawk-utl.h hawk-sed.h hawk-sio.h hawk-std.h \
hawk-str.h hawk-tio.h hawk-tre.h hawk-upac.h hawk-xma.h \
Hawk.hpp Hawk-Sed.hpp arr.c chr.c cut-prv.h cut.c dir.c \
ecs-imp.h ecs.c err-prv.h err.c err-sys.c fmt-imp.h fmt.c \
fnc-prv.h fnc.c gem.c gem-glob.c gem-nwif.c gem-nwif2.c \
hawk-prv.h hawk.c htb.c idmap-imp.h json.c json-prv.h mb8.c \
misc-imp.h misc-prv.h misc.c parse-prv.h parse.c rbt.c rec.c \
rio-prv.h rio.c run-prv.h run.c sed-prv.h sed.c skad-prv.h \
skad.c tre-prv.h tre-ast.c tre-ast.h tre-compile.c \
tre-compile.h tre-match-bt.c tre-match-pa.c tre-match-ut.h \
tre-mem.c tre-mem.h tre-parse.c tre-parse.h tre-stack.h \
tre-stack.c tre.c tree-prv.h tree.c uch-prop.h uch-case.h \
utf16.c utf8.c utl-ass.c utl-cmgr.c utl-rnd.c utl-sort.c \
utl-str.c utl-sys.c utl-xstr.c utl.c val-prv.h val.c xma.c \
cli-imp.h cli.c fio.c mtx.c pio.c sio.c syscall.h tio.c std.c \
std-cut.c std-json.c std-sed.c Hawk.cpp Std.cpp Sed.cpp \
Std-Sed.cpp mod-hawk.c mod-hawk.h mod-math.c mod-math.h \
mod-str.c mod-str.h mod-sys.c mod-sys.h ../mod/mod-ffi.c \
../mod/mod-ffi.h ../mod/mod-memc.c ../mod/mod-memc.h \
../mod/mod-mysql.c ../mod/mod-mysql.h ../mod/mod-sed.c \
../mod/mod-sed.h ../mod/mod-uci.c ../mod/mod-uci.h
am__objects_1 =
am__objects_2 = $(am__objects_1)
@ENABLE_CXX_TRUE@am__objects_3 = libhawk_la-Hawk.lo libhawk_la-Std.lo \
@ -291,28 +291,30 @@ am__dirstamp = $(am__leading_dot)dirstamp
@ENABLE_MOD_UCI_STATIC_TRUE@am__objects_9 = \
@ENABLE_MOD_UCI_STATIC_TRUE@ ../mod/libhawk_la-mod-uci.lo
am_libhawk_la_OBJECTS = $(am__objects_2) libhawk_la-arr.lo \
libhawk_la-chr.lo libhawk_la-dir.lo libhawk_la-ecs.lo \
libhawk_la-err.lo libhawk_la-err-sys.lo libhawk_la-fmt.lo \
libhawk_la-fnc.lo libhawk_la-gem.lo libhawk_la-gem-glob.lo \
libhawk_la-gem-nwif.lo libhawk_la-gem-nwif2.lo \
libhawk_la-hawk.lo libhawk_la-htb.lo libhawk_la-json.lo \
libhawk_la-mb8.lo libhawk_la-misc.lo libhawk_la-parse.lo \
libhawk_la-rbt.lo libhawk_la-rec.lo libhawk_la-rio.lo \
libhawk_la-run.lo libhawk_la-sed.lo libhawk_la-skad.lo \
libhawk_la-tre-ast.lo libhawk_la-tre-compile.lo \
libhawk_la-tre-match-bt.lo libhawk_la-tre-match-pa.lo \
libhawk_la-tre-mem.lo libhawk_la-tre-parse.lo \
libhawk_la-tre-stack.lo libhawk_la-tre.lo libhawk_la-tree.lo \
libhawk_la-utf16.lo libhawk_la-utf8.lo libhawk_la-utl-ass.lo \
libhawk_la-chr.lo libhawk_la-cut.lo libhawk_la-dir.lo \
libhawk_la-ecs.lo libhawk_la-err.lo libhawk_la-err-sys.lo \
libhawk_la-fmt.lo libhawk_la-fnc.lo libhawk_la-gem.lo \
libhawk_la-gem-glob.lo libhawk_la-gem-nwif.lo \
libhawk_la-gem-nwif2.lo libhawk_la-hawk.lo libhawk_la-htb.lo \
libhawk_la-json.lo libhawk_la-mb8.lo libhawk_la-misc.lo \
libhawk_la-parse.lo libhawk_la-rbt.lo libhawk_la-rec.lo \
libhawk_la-rio.lo libhawk_la-run.lo libhawk_la-sed.lo \
libhawk_la-skad.lo libhawk_la-tre-ast.lo \
libhawk_la-tre-compile.lo libhawk_la-tre-match-bt.lo \
libhawk_la-tre-match-pa.lo libhawk_la-tre-mem.lo \
libhawk_la-tre-parse.lo libhawk_la-tre-stack.lo \
libhawk_la-tre.lo libhawk_la-tree.lo libhawk_la-utf16.lo \
libhawk_la-utf8.lo libhawk_la-utl-ass.lo \
libhawk_la-utl-cmgr.lo libhawk_la-utl-rnd.lo \
libhawk_la-utl-sort.lo libhawk_la-utl-str.lo \
libhawk_la-utl-sys.lo libhawk_la-utl-xstr.lo libhawk_la-utl.lo \
libhawk_la-val.lo libhawk_la-xma.lo libhawk_la-cli.lo \
libhawk_la-fio.lo libhawk_la-mtx.lo libhawk_la-pio.lo \
libhawk_la-sio.lo libhawk_la-tio.lo libhawk_la-std.lo \
libhawk_la-std-json.lo libhawk_la-std-sed.lo $(am__objects_3) \
$(am__objects_4) $(am__objects_5) $(am__objects_6) \
$(am__objects_7) $(am__objects_8) $(am__objects_9)
libhawk_la-std-cut.lo libhawk_la-std-json.lo \
libhawk_la-std-sed.lo $(am__objects_3) $(am__objects_4) \
$(am__objects_5) $(am__objects_6) $(am__objects_7) \
$(am__objects_8) $(am__objects_9)
libhawk_la_OBJECTS = $(am_libhawk_la_OBJECTS)
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@ -339,7 +341,8 @@ am__depfiles_remade = ../mod/$(DEPDIR)/libhawk_la-mod-ffi.Plo \
./$(DEPDIR)/libhawk_la-Std-Sed.Plo \
./$(DEPDIR)/libhawk_la-Std.Plo ./$(DEPDIR)/libhawk_la-arr.Plo \
./$(DEPDIR)/libhawk_la-chr.Plo ./$(DEPDIR)/libhawk_la-cli.Plo \
./$(DEPDIR)/libhawk_la-dir.Plo ./$(DEPDIR)/libhawk_la-ecs.Plo \
./$(DEPDIR)/libhawk_la-cut.Plo ./$(DEPDIR)/libhawk_la-dir.Plo \
./$(DEPDIR)/libhawk_la-ecs.Plo \
./$(DEPDIR)/libhawk_la-err-sys.Plo \
./$(DEPDIR)/libhawk_la-err.Plo ./$(DEPDIR)/libhawk_la-fio.Plo \
./$(DEPDIR)/libhawk_la-fmt.Plo ./$(DEPDIR)/libhawk_la-fnc.Plo \
@ -359,6 +362,7 @@ am__depfiles_remade = ../mod/$(DEPDIR)/libhawk_la-mod-ffi.Plo \
./$(DEPDIR)/libhawk_la-rec.Plo ./$(DEPDIR)/libhawk_la-rio.Plo \
./$(DEPDIR)/libhawk_la-run.Plo ./$(DEPDIR)/libhawk_la-sed.Plo \
./$(DEPDIR)/libhawk_la-sio.Plo ./$(DEPDIR)/libhawk_la-skad.Plo \
./$(DEPDIR)/libhawk_la-std-cut.Plo \
./$(DEPDIR)/libhawk_la-std-json.Plo \
./$(DEPDIR)/libhawk_la-std-sed.Plo \
./$(DEPDIR)/libhawk_la-std.Plo ./$(DEPDIR)/libhawk_la-tio.Plo \
@ -435,12 +439,12 @@ am__can_run_installinfo = \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__pkginclude_HEADERS_DIST = hawk.h hawk-arr.h hawk-chr.h hawk-cli.h \
hawk-cmn.h hawk-dir.h hawk-ecs.h hawk-fio.h hawk-fmt.h \
hawk-gem.h hawk-glob.h hawk-htb.h hawk-json.h hawk-map.h \
hawk-mtx.h hawk-rbt.h hawk-pac1.h hawk-pio.h hawk-skad.h \
hawk-utl.h hawk-sed.h hawk-sio.h hawk-std.h hawk-str.h \
hawk-tio.h hawk-tre.h hawk-upac.h hawk-xma.h Hawk.hpp \
Hawk-Sed.hpp
hawk-cmn.h hawk-cut.h hawk-dir.h hawk-ecs.h hawk-fio.h \
hawk-fmt.h hawk-gem.h hawk-glob.h hawk-htb.h hawk-json.h \
hawk-map.h hawk-mtx.h hawk-rbt.h hawk-pac1.h hawk-pio.h \
hawk-skad.h hawk-utl.h hawk-sed.h hawk-sio.h hawk-std.h \
hawk-str.h hawk-tio.h hawk-tre.h hawk-upac.h hawk-xma.h \
Hawk.hpp Hawk-Sed.hpp
HEADERS = $(pkginclude_HEADERS)
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \
hawk-cfg.h.in
@ -666,28 +670,29 @@ BUILT_SOURCES = \
utl-str.c
pkginclude_HEADERS = hawk.h hawk-arr.h hawk-chr.h hawk-cli.h \
hawk-cmn.h hawk-dir.h hawk-ecs.h hawk-fio.h hawk-fmt.h \
hawk-gem.h hawk-glob.h hawk-htb.h hawk-json.h hawk-map.h \
hawk-mtx.h hawk-rbt.h hawk-pac1.h hawk-pio.h hawk-skad.h \
hawk-utl.h hawk-sed.h hawk-sio.h hawk-std.h hawk-str.h \
hawk-tio.h hawk-tre.h hawk-upac.h hawk-xma.h $(am__append_7)
hawk-cmn.h hawk-cut.h hawk-dir.h hawk-ecs.h hawk-fio.h \
hawk-fmt.h hawk-gem.h hawk-glob.h hawk-htb.h hawk-json.h \
hawk-map.h hawk-mtx.h hawk-rbt.h hawk-pac1.h hawk-pio.h \
hawk-skad.h hawk-utl.h hawk-sed.h hawk-sio.h hawk-std.h \
hawk-str.h hawk-tio.h hawk-tre.h hawk-upac.h hawk-xma.h \
$(am__append_7)
pkglib_LTLIBRARIES = libhawk.la $(am__append_11)
libhawk_la_SOURCES = $(pkginclude_HEADERS) arr.c chr.c dir.c ecs-imp.h \
ecs.c err-prv.h err.c err-sys.c fmt-imp.h fmt.c fnc-prv.h \
fnc.c gem.c gem-glob.c gem-nwif.c gem-nwif2.c hawk-prv.h \
hawk.c htb.c idmap-imp.h json.c json-prv.h mb8.c misc-imp.h \
misc-prv.h misc.c parse-prv.h parse.c rbt.c rec.c rio-prv.h \
rio.c run-prv.h run.c sed-prv.h sed.c skad-prv.h skad.c \
tre-prv.h tre-ast.c tre-ast.h tre-compile.c tre-compile.h \
tre-match-bt.c tre-match-pa.c tre-match-ut.h tre-mem.c \
tre-mem.h tre-parse.c tre-parse.h tre-stack.h tre-stack.c \
tre.c tree-prv.h tree.c uch-prop.h uch-case.h utf16.c utf8.c \
utl-ass.c utl-cmgr.c utl-rnd.c utl-sort.c utl-str.c utl-sys.c \
utl-xstr.c utl.c val-prv.h val.c xma.c cli-imp.h cli.c fio.c \
mtx.c pio.c sio.c syscall.h tio.c std.c std-json.c std-sed.c \
$(am__append_8) $(am__append_9) $(am__append_12) \
$(am__append_14) $(am__append_16) $(am__append_20) \
$(am__append_21)
libhawk_la_SOURCES = $(pkginclude_HEADERS) arr.c chr.c cut-prv.h cut.c \
dir.c ecs-imp.h ecs.c err-prv.h err.c err-sys.c fmt-imp.h \
fmt.c fnc-prv.h fnc.c gem.c gem-glob.c gem-nwif.c gem-nwif2.c \
hawk-prv.h hawk.c htb.c idmap-imp.h json.c json-prv.h mb8.c \
misc-imp.h misc-prv.h misc.c parse-prv.h parse.c rbt.c rec.c \
rio-prv.h rio.c run-prv.h run.c sed-prv.h sed.c skad-prv.h \
skad.c tre-prv.h tre-ast.c tre-ast.h tre-compile.c \
tre-compile.h tre-match-bt.c tre-match-pa.c tre-match-ut.h \
tre-mem.c tre-mem.h tre-parse.c tre-parse.h tre-stack.h \
tre-stack.c tre.c tree-prv.h tree.c uch-prop.h uch-case.h \
utf16.c utf8.c utl-ass.c utl-cmgr.c utl-rnd.c utl-sort.c \
utl-str.c utl-sys.c utl-xstr.c utl.c val-prv.h val.c xma.c \
cli-imp.h cli.c fio.c mtx.c pio.c sio.c syscall.h tio.c std.c \
std-cut.c std-json.c std-sed.c $(am__append_8) $(am__append_9) \
$(am__append_12) $(am__append_14) $(am__append_16) \
$(am__append_20) $(am__append_21)
libhawk_la_CPPFLAGS = $(CPPFLAGS_ALL_COMMON) $(CPPFLAGS_PFMOD) \
$(am__append_3) $(am__append_17)
libhawk_la_CFLAGS = $(CFLAGS_ALL_COMMON)
@ -876,6 +881,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-arr.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-chr.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-cli.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-cut.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-dir.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-ecs.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-err-sys.Plo@am__quote@ # am--include-marker
@ -906,6 +912,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-sed.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-sio.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-skad.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-std-cut.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-std-json.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-std-sed.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-std.Plo@am__quote@ # am--include-marker
@ -1007,6 +1014,13 @@ libhawk_la-chr.lo: chr.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) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -c -o libhawk_la-chr.lo `test -f 'chr.c' || echo '$(srcdir)/'`chr.c
libhawk_la-cut.lo: cut.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -MT libhawk_la-cut.lo -MD -MP -MF $(DEPDIR)/libhawk_la-cut.Tpo -c -o libhawk_la-cut.lo `test -f 'cut.c' || echo '$(srcdir)/'`cut.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-cut.Tpo $(DEPDIR)/libhawk_la-cut.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cut.c' object='libhawk_la-cut.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) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -c -o libhawk_la-cut.lo `test -f 'cut.c' || echo '$(srcdir)/'`cut.c
libhawk_la-dir.lo: dir.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -MT libhawk_la-dir.lo -MD -MP -MF $(DEPDIR)/libhawk_la-dir.Tpo -c -o libhawk_la-dir.lo `test -f 'dir.c' || echo '$(srcdir)/'`dir.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-dir.Tpo $(DEPDIR)/libhawk_la-dir.Plo
@ -1357,6 +1371,13 @@ libhawk_la-std.lo: std.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) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -c -o libhawk_la-std.lo `test -f 'std.c' || echo '$(srcdir)/'`std.c
libhawk_la-std-cut.lo: std-cut.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -MT libhawk_la-std-cut.lo -MD -MP -MF $(DEPDIR)/libhawk_la-std-cut.Tpo -c -o libhawk_la-std-cut.lo `test -f 'std-cut.c' || echo '$(srcdir)/'`std-cut.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-std-cut.Tpo $(DEPDIR)/libhawk_la-std-cut.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='std-cut.c' object='libhawk_la-std-cut.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) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -c -o libhawk_la-std-cut.lo `test -f 'std-cut.c' || echo '$(srcdir)/'`std-cut.c
libhawk_la-std-json.lo: std-json.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(libhawk_la_CFLAGS) $(CFLAGS) -MT libhawk_la-std-json.lo -MD -MP -MF $(DEPDIR)/libhawk_la-std-json.Tpo -c -o libhawk_la-std-json.lo `test -f 'std-json.c' || echo '$(srcdir)/'`std-json.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-std-json.Tpo $(DEPDIR)/libhawk_la-std-json.Plo
@ -1660,6 +1681,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/libhawk_la-arr.Plo
-rm -f ./$(DEPDIR)/libhawk_la-chr.Plo
-rm -f ./$(DEPDIR)/libhawk_la-cli.Plo
-rm -f ./$(DEPDIR)/libhawk_la-cut.Plo
-rm -f ./$(DEPDIR)/libhawk_la-dir.Plo
-rm -f ./$(DEPDIR)/libhawk_la-ecs.Plo
-rm -f ./$(DEPDIR)/libhawk_la-err-sys.Plo
@ -1690,6 +1712,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/libhawk_la-sed.Plo
-rm -f ./$(DEPDIR)/libhawk_la-sio.Plo
-rm -f ./$(DEPDIR)/libhawk_la-skad.Plo
-rm -f ./$(DEPDIR)/libhawk_la-std-cut.Plo
-rm -f ./$(DEPDIR)/libhawk_la-std-json.Plo
-rm -f ./$(DEPDIR)/libhawk_la-std-sed.Plo
-rm -f ./$(DEPDIR)/libhawk_la-std.Plo
@ -1777,6 +1800,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/libhawk_la-arr.Plo
-rm -f ./$(DEPDIR)/libhawk_la-chr.Plo
-rm -f ./$(DEPDIR)/libhawk_la-cli.Plo
-rm -f ./$(DEPDIR)/libhawk_la-cut.Plo
-rm -f ./$(DEPDIR)/libhawk_la-dir.Plo
-rm -f ./$(DEPDIR)/libhawk_la-ecs.Plo
-rm -f ./$(DEPDIR)/libhawk_la-err-sys.Plo
@ -1807,6 +1831,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/libhawk_la-sed.Plo
-rm -f ./$(DEPDIR)/libhawk_la-sio.Plo
-rm -f ./$(DEPDIR)/libhawk_la-skad.Plo
-rm -f ./$(DEPDIR)/libhawk_la-std-cut.Plo
-rm -f ./$(DEPDIR)/libhawk_la-std-json.Plo
-rm -f ./$(DEPDIR)/libhawk_la-std-sed.Plo
-rm -f ./$(DEPDIR)/libhawk_la-std.Plo

124
lib/cut-prv.h Normal file
View File

@ -0,0 +1,124 @@
/*
Copyright (c) 2006-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _HAWK_CUT_PRV_H_
#define _HAWK_CUT_PRV_H_
#include <hawk-cut.h>
#include <hawk-ecs.h>
typedef struct hawk_cut_sel_blk_t hawk_cut_sel_blk_t;
struct hawk_cut_sel_blk_t
{
hawk_oow_t len;
struct
{
enum
{
HAWK_SED_SEL_CHAR = HAWK_T('c'),
HAWK_SED_SEL_FIELD = HAWK_T('f')
} id;
hawk_oow_t start;
hawk_oow_t end;
} range[128];
hawk_cut_sel_blk_t* next;
};
struct hawk_cut_t
{
HAWK_CUT_HDR;
#if 0
hawk_cut_errstr_t errstr; /**< error string getter */
hawk_cut_errnum_t errnum; /**< stores an error number */
hawk_ooch_t errmsg[128]; /**< error message holder */
#endif
int option; /**< stores options */
struct
{
hawk_cut_sel_blk_t fb; /**< the first block is static */
hawk_cut_sel_blk_t* lb; /**< points to the last block */
hawk_ooch_t din; /**< input field delimiter */
hawk_ooch_t dout; /**< output field delimiter */
hawk_oow_t count;
hawk_oow_t fcount;
hawk_oow_t ccount;
} sel;
struct
{
/** data needed for output streams */
struct
{
hawk_cut_io_impl_t fun; /**< an output handler */
hawk_cut_io_arg_t arg; /**< output handling data */
hawk_ooch_t buf[2048];
hawk_oow_t len;
int eof;
} out;
/** data needed for input streams */
struct
{
hawk_cut_io_impl_t fun; /**< an input handler */
hawk_cut_io_arg_t arg; /**< input handling data */
hawk_ooch_t xbuf[1]; /**< a read-ahead buffer */
int xbuf_len; /**< data length in the buffer */
hawk_ooch_t buf[2048]; /**< input buffer */
hawk_oow_t len; /**< data length in the buffer */
hawk_oow_t pos; /**< current position in the buffer */
int eof; /**< EOF indicator */
hawk_ooecs_t line; /**< pattern space */
hawk_oow_t num; /**< current line number */
hawk_oow_t nflds; /**< the number of fields */
hawk_oow_t cflds; /**< capacity of flds field */
hawk_oocs_t sflds[128]; /**< static field buffer */
hawk_oocs_t* flds;
int delimited;
} in;
} e;
};
#ifdef __cplusplus
extern "C" {
#endif
/* NOTHING */
#ifdef __cplusplus
}
#endif
#endif

745
lib/cut.c Normal file
View File

@ -0,0 +1,745 @@
/*
Copyright (c) 2006-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "cut-prv.h"
#include "hawk-prv.h"
#include <hawk-chr.h>
static int hawk_cut_init (hawk_cut_t* cut, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr);
static void hawk_cut_fini (hawk_cut_t* cut);
#define SETERR0(cut,num) \
do { hawk_cut_seterrnum (cut, HAWK_NULL, num); } while (0)
#define DFL_LINE_CAPA 256
static int add_selector_block (hawk_cut_t* cut)
{
hawk_cut_sel_blk_t* b;
b = (hawk_cut_sel_blk_t*)hawk_cut_allocmem(cut, HAWK_SIZEOF(*b));
if (HAWK_UNLIKELY(!b)) return -1;
HAWK_MEMSET(b, 0, HAWK_SIZEOF(*b));
b->next = HAWK_NULL;
b->len = 0;
cut->sel.lb->next = b;
cut->sel.lb = b;
cut->sel.count = 0;
cut->sel.fcount = 0;
cut->sel.ccount = 0;
return 0;
}
static void free_all_selector_blocks (hawk_cut_t* cut)
{
hawk_cut_sel_blk_t* b;
for (b = cut->sel.fb.next; b != HAWK_NULL; )
{
hawk_cut_sel_blk_t* nxt = b->next;
hawk_cut_freemem(cut, b);
b = nxt;
}
cut->sel.lb = &cut->sel.fb;
cut->sel.lb->len = 0;
cut->sel.lb->next = HAWK_NULL;
cut->sel.count = 0;
cut->sel.fcount = 0;
cut->sel.ccount = 0;
}
hawk_cut_t* hawk_cut_open (hawk_mmgr_t* mmgr, hawk_oow_t xtnsize, hawk_cmgr_t* cmgr, hawk_errnum_t* errnum)
{
hawk_cut_t* cut;
cut = (hawk_cut_t*)HAWK_MMGR_ALLOC(mmgr, HAWK_SIZEOF(hawk_cut_t) + xtnsize);
if (HAWK_LIKELY(cut))
{
if (hawk_cut_init(cut, mmgr, cmgr) <= -1)
{
if (errnum) *errnum = hawk_cut_geterrnum(cut);
HAWK_MMGR_FREE (mmgr, cut);
cut = HAWK_NULL;
}
else HAWK_MEMSET(cut + 1, 0, xtnsize);
}
else if (errnum) *errnum = HAWK_ENOMEM;
return cut;
}
void hawk_cut_close (hawk_cut_t* cut)
{
hawk_cut_fini (cut);
HAWK_MMGR_FREE (hawk_cut_getmmgr(cut), cut);
}
static int hawk_cut_init (hawk_cut_t* cut, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr)
{
HAWK_MEMSET (cut, 0, HAWK_SIZEOF(*cut));
cut->_instsize = HAWK_SIZEOF(*cut);
cut->_gem.mmgr = mmgr;
cut->_gem.cmgr = cmgr;
/* initialize error handling fields */
cut->_gem.errnum = HAWK_ENOERR;
cut->_gem.errmsg[0] = '\0';
cut->_gem.errloc.line = 0;
cut->_gem.errloc.colm = 0;
cut->_gem.errloc.file = HAWK_NULL;
cut->_gem.errstr = hawk_dfl_errstr;
/* on init, the last points to the first */
cut->sel.lb = &cut->sel.fb;
/* the block has no data yet */
cut->sel.fb.len = 0;
cut->e.in.cflds = HAWK_COUNTOF(cut->e.in.sflds);
cut->e.in.flds = cut->e.in.sflds;
if (hawk_ooecs_init(&cut->e.in.line, hawk_cut_getgem(cut), DFL_LINE_CAPA) <= -1) return -1;
return 0;
}
static void hawk_cut_fini (hawk_cut_t* cut)
{
free_all_selector_blocks (cut);
if (cut->e.in.flds != cut->e.in.sflds) hawk_cut_freemem(cut, cut->e.in.flds);
hawk_ooecs_fini(&cut->e.in.line);
}
void hawk_cut_setoption (hawk_cut_t* cut, int option)
{
cut->option = option;
}
int hawk_cut_getoption (hawk_cut_t* cut)
{
return cut->option;
}
void hawk_cut_clear (hawk_cut_t* cut)
{
free_all_selector_blocks (cut);
if (cut->e.in.flds != cut->e.in.sflds) hawk_cut_freemem(cut, cut->e.in.flds);
cut->e.in.cflds = HAWK_COUNTOF(cut->e.in.sflds);
cut->e.in.flds = cut->e.in.sflds;
hawk_ooecs_clear(&cut->e.in.line);
hawk_ooecs_setcapa(&cut->e.in.line, DFL_LINE_CAPA);
}
int hawk_cut_comp (hawk_cut_t* cut, const hawk_ooch_t* str, hawk_oow_t len)
{
const hawk_ooch_t* p = str;
const hawk_ooch_t* xnd = str + len;
hawk_ooci_t c;
int sel = HAWK_SED_SEL_CHAR;
#define CC(x,y) (((x) <= (y))? ((hawk_ooci_t)*(x)): HAWK_OOCI_EOF)
#define NC(x,y) (((x) < (y))? ((hawk_ooci_t)*(++(x))): HAWK_OOCI_EOF)
#define EOF(x) ((x) == HAWK_OOCI_EOF)
#define MASK_START (1 << 1)
#define MASK_END (1 << 2)
#define MAX HAWK_TYPE_MAX(hawk_oow_t)
/* free selector blocks compiled previously */
free_all_selector_blocks (cut);
/* set the default delimiters */
cut->sel.din = HAWK_T(' ');
cut->sel.dout = HAWK_T(' ');
/* if the selector string is empty, don't need to proceed */
if (len <= 0) return 0;
/* compile the selector string */
xnd--; c = CC (p, xnd);
while (1)
{
hawk_oow_t start = 0, end = 0;
int mask = 0;
while (hawk_is_ooch_space(c)) c = NC(p, xnd);
if (EOF(c))
{
if (cut->sel.count > 0)
{
SETERR0 (cut, HAWK_CUT_ESELNV);
return -1;
}
break;
}
if (c == HAWK_T('d'))
{
/* the next character is the input delimiter.
* the output delimiter defaults to the input
* delimiter. */
c = NC(p, xnd);
if (EOF(c))
{
SETERR0 (cut, HAWK_CUT_ESELNV);
return -1;
}
cut->sel.din = c;
cut->sel.dout = c;
c = NC(p, xnd);
}
else if (c == HAWK_T('D'))
{
/* the next two characters are the input and
* the output delimiter each. */
c = NC(p, xnd);
if (EOF(c))
{
SETERR0 (cut, HAWK_CUT_ESELNV);
return -1;
}
cut->sel.din = c;
c = NC(p, xnd);
if (EOF(c))
{
SETERR0 (cut, HAWK_CUT_ESELNV);
return -1;
}
cut->sel.dout = c;
c = NC(p, xnd);
}
else
{
if (c == HAWK_T('c') || c == HAWK_T('f'))
{
sel = c;
c = NC(p, xnd);
while (hawk_is_ooch_space(c)) c = NC(p, xnd);
}
if (hawk_is_ooch_digit(c))
{
do
{
start = start * 10 + (c - HAWK_T('0'));
c = NC(p, xnd);
}
while (hawk_is_ooch_digit(c));
while (hawk_is_ooch_space(c)) c = NC(p, xnd);
mask |= MASK_START;
}
else start++;
if (c == HAWK_T('-'))
{
c = NC(p, xnd);
while (hawk_is_ooch_space(c)) c = NC(p, xnd);
if (hawk_is_ooch_digit(c))
{
do
{
end = end * 10 + (c - HAWK_T('0'));
c = NC(p, xnd);
}
while (hawk_is_ooch_digit(c));
mask |= MASK_END;
}
else end = MAX;
while (hawk_is_ooch_space(c)) c = NC(p, xnd);
}
else end = start;
if (!(mask & (MASK_START | MASK_END)))
{
SETERR0 (cut, HAWK_CUT_ESELNV);
return -1;
}
if (cut->sel.lb->len >= HAWK_COUNTOF(cut->sel.lb->range))
{
if (add_selector_block (cut) <= -1)
{
return -1;
}
}
cut->sel.lb->range[cut->sel.lb->len].id = sel;
cut->sel.lb->range[cut->sel.lb->len].start = start;
cut->sel.lb->range[cut->sel.lb->len].end = end;
cut->sel.lb->len++;
cut->sel.count++;
if (sel == HAWK_SED_SEL_FIELD) cut->sel.fcount++;
else cut->sel.ccount++;
}
if (EOF(c)) break;
if (c == HAWK_T(',')) c = NC(p, xnd);
}
return 0;
}
static int read_char (hawk_cut_t* cut, hawk_ooch_t* c)
{
hawk_ooi_t n;
if (cut->e.in.pos >= cut->e.in.len)
{
n = cut->e.in.fun(cut, HAWK_CUT_IO_READ, &cut->e.in.arg, cut->e.in.buf, HAWK_COUNTOF(cut->e.in.buf));
if (n <= -1) return -1;
if (n == 0) return 0; /* end of file */
cut->e.in.len = n;
cut->e.in.pos = 0;
}
*c = cut->e.in.buf[cut->e.in.pos++];
return 1;
}
static int read_line (hawk_cut_t* cut)
{
hawk_oow_t len = 0;
hawk_ooch_t c;
int n;
hawk_ooecs_clear(&cut->e.in.line);
if (cut->e.in.eof) return 0;
while (1)
{
n = read_char(cut, &c);
if (n <= -1) return -1;
if (n == 0)
{
cut->e.in.eof = 1;
if (len == 0) return 0;
break;
}
if (c == HAWK_T('\n'))
{
/* don't include the line terminater to a line */
/* TODO: support different line end convension */
break;
}
if (hawk_ooecs_ccat(&cut->e.in.line, c) == (hawk_oow_t)-1) return -1;
len++;
}
cut->e.in.num++;
if (cut->option & HAWK_CUT_TRIMSPACE) hawk_ooecs_trim(&cut->e.in.line, HAWK_TRIM_LEFT | HAWK_TRIM_RIGHT);
if (cut->option & HAWK_CUT_NORMSPACE) hawk_ooecs_compact(&cut->e.in.line);
return 1;
}
static int flush (hawk_cut_t* cut)
{
hawk_oow_t pos = 0;
hawk_ooi_t n;
while (cut->e.out.len > 0)
{
n = cut->e.out.fun(cut, HAWK_CUT_IO_WRITE, &cut->e.out.arg, &cut->e.out.buf[pos], cut->e.out.len);
if (n <= -1) return -1;
if (n == 0) return -1; /* reached the end of file - this is also an error */
pos += n;
cut->e.out.len -= n;
}
return 0;
}
static int write_char (hawk_cut_t* cut, hawk_ooch_t c)
{
cut->e.out.buf[cut->e.out.len++] = c;
if (c == HAWK_T('\n') || cut->e.out.len >= HAWK_COUNTOF(cut->e.out.buf)) return flush(cut);
return 0;
}
static int write_linebreak (hawk_cut_t* cut)
{
/* TODO: different line termination convention */
return write_char(cut, HAWK_T('\n'));
}
static int write_str (hawk_cut_t* cut, const hawk_ooch_t* str, hawk_oow_t len)
{
hawk_oow_t i;
for (i = 0; i < len; i++)
{
if (write_char(cut, str[i]) <= -1) return -1;
}
return 0;
}
static int cut_chars (hawk_cut_t* cut, hawk_oow_t start, hawk_oow_t end, int delim)
{
const hawk_ooch_t* ptr = HAWK_OOECS_PTR(&cut->e.in.line);
hawk_oow_t len = HAWK_OOECS_LEN(&cut->e.in.line);
if (len <= 0) return 0;
if (start <= end)
{
if (start <= len && end > 0)
{
if (start >= 1) start--;
if (end >= 1) end--;
if (end >= len) end = len - 1;
if (delim && write_char(cut, cut->sel.dout) <= -1) return -1;
if (write_str(cut, &ptr[start], end-start+1) <= -1) return -1;
return 1;
}
}
else
{
if (start > 0 && end <= len)
{
hawk_oow_t i;
if (start >= 1) start--;
if (end >= 1) end--;
if (start >= len) start = len - 1;
if (delim && write_char (cut, cut->sel.dout) <= -1)
return -1;
for (i = start; i >= end; i--)
{
if (write_char (cut, ptr[i]) <= -1)
return -1;
}
return 1;
}
}
return 0;
}
static int isdelim (hawk_cut_t* cut, hawk_ooch_t c)
{
return ((cut->option & HAWK_CUT_WHITESPACE) && hawk_is_ooch_space(c)) ||
(!(cut->option & HAWK_CUT_WHITESPACE) && c == cut->sel.din);
}
static int split_line (hawk_cut_t* cut)
{
const hawk_ooch_t* ptr = HAWK_OOECS_PTR(&cut->e.in.line);
hawk_oow_t len = HAWK_OOECS_LEN(&cut->e.in.line);
hawk_oow_t i, x = 0, xl = 0;
cut->e.in.delimited = 0;
cut->e.in.flds[x].ptr = ptr;
for (i = 0; i < len; )
{
hawk_ooch_t c = ptr[i++];
if (isdelim(cut,c))
{
if (cut->option & HAWK_CUT_FOLDDELIMS)
{
while (i < len && isdelim(cut,ptr[i])) i++;
}
cut->e.in.flds[x++].len = xl;
if (x >= cut->e.in.cflds)
{
hawk_oocs_t* tmp;
hawk_oow_t nsz;
nsz = cut->e.in.cflds;
if (nsz > 100000) nsz += 100000;
else nsz *= 2;
tmp = hawk_cut_allocmem(cut, HAWK_SIZEOF(*tmp) * nsz);
if (HAWK_UNLIKELY(!tmp)) return -1;
HAWK_MEMCPY (tmp, cut->e.in.flds, HAWK_SIZEOF(*tmp) * cut->e.in.cflds);
if (cut->e.in.flds != cut->e.in.sflds) hawk_cut_freemem(cut, cut->e.in.flds);
cut->e.in.flds = tmp;
cut->e.in.cflds = nsz;
}
xl = 0;
cut->e.in.flds[x].ptr = &ptr[i];
cut->e.in.delimited = 1;
}
else xl++;
}
cut->e.in.flds[x].len = xl;
cut->e.in.nflds = ++x;
return 0;
}
static int cut_fields (hawk_cut_t* cut, hawk_oow_t start, hawk_oow_t end, int delim)
{
hawk_oow_t len = cut->e.in.nflds;
if (!cut->e.in.delimited /*|| len <= 0*/) return 0;
HAWK_ASSERT (len > 0);
if (start <= end)
{
if (start <= len && end > 0)
{
hawk_oow_t i;
if (start >= 1) start--;
if (end >= 1) end--;
if (end >= len) end = len - 1;
if (delim && write_char(cut, cut->sel.dout) <= -1) return -1;
for (i = start; i <= end; i++)
{
if (write_str(cut, cut->e.in.flds[i].ptr, cut->e.in.flds[i].len) <= -1) return -1;
if (i < end && write_char(cut, cut->sel.dout) <= -1) return -1;
}
return 1;
}
}
else
{
if (start > 0 && end <= len)
{
hawk_oow_t i;
if (start >= 1) start--;
if (end >= 1) end--;
if (start >= len) start = len - 1;
if (delim && write_char (cut, cut->sel.dout) <= -1)
return -1;
for (i = start; i >= end; i--)
{
if (write_str(cut, cut->e.in.flds[i].ptr, cut->e.in.flds[i].len) <= -1) return -1;
if (i > end && write_char (cut, cut->sel.dout) <= -1) return -1;
}
return 1;
}
}
return 0;
}
int hawk_cut_exec (hawk_cut_t* cut, hawk_cut_io_impl_t inf, hawk_cut_io_impl_t outf)
{
int ret = 0;
hawk_ooi_t n;
cut->e.out.fun = outf;
cut->e.out.eof = 0;
cut->e.out.len = 0;
cut->e.in.fun = inf;
cut->e.in.eof = 0;
cut->e.in.len = 0;
cut->e.in.pos = 0;
cut->e.in.num = 0;
n = cut->e.in.fun(cut, HAWK_CUT_IO_OPEN, &cut->e.in.arg, HAWK_NULL, 0);
if (n <= -1)
{
ret = -1;
goto done3;
}
if (n == 0)
{
/* EOF reached upon opening an input stream.
* no data to process. this is success */
goto done2;
}
n = cut->e.out.fun (cut, HAWK_CUT_IO_OPEN, &cut->e.out.arg, HAWK_NULL, 0);
if (n <= -1)
{
ret = -1;
goto done2;
}
if (n == 0)
{
/* still don't know if we will write something.
* just mark EOF on the output stream and continue */
cut->e.out.eof = 1;
}
while (1)
{
hawk_cut_sel_blk_t* b;
int id = 0; /* mark 'no output' so far */
int delimited = 0;
int linebreak = 0;
n = read_line (cut);
if (n <= -1) { ret = -1; goto done; }
if (n == 0) goto done;
if (cut->sel.fcount > 0)
{
if (split_line (cut) <= -1) { ret = -1; goto done; }
delimited = cut->e.in.delimited;
}
for (b = &cut->sel.fb; b != HAWK_NULL; b = b->next)
{
hawk_oow_t i;
for (i = 0; i < b->len; i++)
{
if (b->range[i].id == HAWK_SED_SEL_CHAR)
{
n = cut_chars (
cut,
b->range[i].start,
b->range[i].end,
id == 2
);
if (n >= 1)
{
/* mark a char's been output */
id = 1;
}
}
else
{
n = cut_fields (
cut,
b->range[i].start,
b->range[i].end,
id > 0
);
if (n >= 1)
{
/* mark a field's been output */
id = 2;
}
}
if (n <= -1) { ret = -1; goto done; }
}
}
if (cut->sel.ccount > 0)
{
/* so long as there is a character selector,
* a newline must be printed */
linebreak = 1;
}
else if (cut->sel.fcount > 0)
{
/* if only field selectors are specified */
if (delimited)
{
/* and if the input line is delimited,
* write a line break */
linebreak = 1;
}
else if (!(cut->option & HAWK_CUT_DELIMONLY))
{
/* if not delimited, write the
* entire undelimited input line depending
* on the option set. */
if (write_str(cut, HAWK_OOECS_PTR(&cut->e.in.line), HAWK_OOECS_LEN(&cut->e.in.line)) <= -1)
{
ret = -1; goto done;
}
/* a line break is needed in this case */
linebreak = 1;
}
}
if (linebreak && write_linebreak(cut) <= -1)
{
ret = -1; goto done;
}
}
done:
cut->e.out.fun (cut, HAWK_CUT_IO_CLOSE, &cut->e.out.arg, HAWK_NULL, 0);
done2:
cut->e.in.fun (cut, HAWK_CUT_IO_CLOSE, &cut->e.in.arg, HAWK_NULL, 0);
done3:
return ret;
}
/* -------------------------------------- */
void* hawk_cut_allocmem (hawk_cut_t* cut, hawk_oow_t size)
{
void* ptr = HAWK_MMGR_ALLOC(hawk_cut_getmmgr(cut), size);
if (HAWK_UNLIKELY(!ptr)) hawk_cut_seterrnum(cut, HAWK_NULL, HAWK_ENOMEM);
return ptr;
}
void* hawk_cut_callocmem (hawk_cut_t* cut, hawk_oow_t size)
{
void* ptr = HAWK_MMGR_ALLOC(hawk_cut_getmmgr(cut), size);
if (HAWK_LIKELY(ptr)) HAWK_MEMSET(ptr, 0, size);
else hawk_cut_seterrnum(cut, HAWK_NULL, HAWK_ENOMEM);
return ptr;
}
void* hawk_cut_reallocmem (hawk_cut_t* cut, void* ptr, hawk_oow_t size)
{
void* nptr = HAWK_MMGR_REALLOC(hawk_cut_getmmgr(cut), ptr, size);
if (HAWK_UNLIKELY(!nptr)) hawk_cut_seterrnum(cut, HAWK_NULL, HAWK_ENOMEM);
return nptr;
}
void hawk_cut_freemem (hawk_cut_t* cut, void* ptr)
{
HAWK_MMGR_FREE(hawk_cut_getmmgr(cut), ptr);
}

View File

@ -447,3 +447,26 @@ hawk_oow_t FN(fmt) (str_t* str, const char_t* fmt, ...)
return x;
}
hawk_oow_t FN(compact) (str_t* str)
{
if (str->val.ptr)
{
str->val.len = compact_chars(str->val.ptr, str->val.len);
str->val.ptr[str->val.len] = '\0';
}
return str->val.len;
}
hawk_oow_t FN(trim) (str_t* str, int flags)
{
if (str->val.ptr)
{
const char_t* ptr;
hawk_oow_t len = str->val.len;
ptr = trim_chars(str->val.ptr, &len, flags);
copy_chars(str->val.ptr, ptr, len);
str->val.ptr[len] = '\0';
}
return str->val.len;
}

View File

@ -34,12 +34,18 @@
#undef char_t
#undef cstr_t
#undef count_chars
#undef compact_chars
#undef copy_chars
#undef trim_chars
#define FN(verb) _FN(becs,verb)
#define T(x) HAWK_BT(x)
#define str_t hawk_becs_t
#define char_t hawk_bch_t
#define cstr_t hawk_bcs_t
#define count_chars(x) hawk_count_bcstr(x)
#define compact_chars(x,l) hawk_compact_bchars(x,l)
#define copy_chars(x,y,l) hawk_copy_bchars(x,y,l)
#define trim_chars(x,l,f) hawk_trim_bchars(x,l,f)
#define BUILD_BECS
#include "ecs-imp.h"
@ -51,12 +57,18 @@
#undef char_t
#undef cstr_t
#undef count_chars
#undef compact_chars
#undef copy_chars
#undef trim_chars
#define FN(verb) _FN(uecs,verb)
#define T(x) HAWK_UT(x)
#define str_t hawk_uecs_t
#define char_t hawk_uch_t
#define cstr_t hawk_ucs_t
#define count_chars(x) hawk_count_ucstr(x)
#define compact_chars(x,l) hawk_compact_uchars(x,l)
#define copy_chars(x,y,l) hawk_copy_uchars(x,y,l)
#define trim_chars(x,l,f) hawk_trim_uchars(x,l,f)
#define BUILD_UECS
#include "ecs-imp.h"

View File

@ -209,6 +209,10 @@ const hawk_ooch_t* hawk_dfl_errstr (hawk_errnum_t errnum)
HAWK_T("occurrence specifier too large"),
HAWK_T("no previous regular expression"),
HAWK_T("cut selector not valid"),
HAWK_T("I/O error with file '${0}'"),
/* cut error messages */
HAWK_T("selector not valid"),
HAWK_T("I/O error with file '${0}'")
};

View File

@ -1079,6 +1079,10 @@ enum hawk_errnum_t
HAWK_SED_ECSLNV, /**< cut selector not valid */
HAWK_SED_EIOFIL, /**< io error with file '${0}' */
/* cut errors */
HAWK_CUT_ESELNV, /**< selector not valid */
HAWK_CUT_EIOFIL, /**< io error with file '${0}'*/
/* the number of error numbers, internal use only */
HAWK_NUMERRNUMS
};

481
lib/hawk-cut.h Normal file
View File

@ -0,0 +1,481 @@
/*
Copyright (c) 2006-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _HAWK_CUT_H_
#define _HAWK_CUT_H_
#include <hawk-cmn.h>
#include <hawk-gem.h>
#include <hawk-sio.h>
/** @file
* This file defines a text cutter utility.
*
* @todo HAWK_CUT_ORDEREDSEL - A selector 5,3,1 is ordered to 1,3,5
*/
/**
* @example cut.c
* This example implements a simple cut utility.
*/
/** @struct hawk_cut_t
* The hawk_cut_t type defines a text cutter. The details are hidden as it is
* a large complex structure vulnerable to unintended changes.
*/
typedef struct hawk_cut_t hawk_cut_t;
#define HAWK_CUT_HDR \
hawk_oow_t _instsize; \
hawk_gem_t _gem
typedef struct hawk_cut_alt_t hawk_cut_alt_t;
struct hawk_cut_alt_t
{
/* ensure that hawk_cut_alt_t matches the beginning part of hawk_cut_t */
HAWK_CUT_HDR;
};
/**
* The hawk_cut_option_t type defines various option codes for a text cutter.
* Options can be OR'ed with each other and be passed to a text cutter with
* the hawk_cut_setoption() function.
*/
enum hawk_cut_option_t
{
/** show delimited line only. if not set, undelimited lines are
* shown in its entirety */
HAWK_CUT_DELIMONLY = (1 << 0),
/** treat any whitespaces as an input delimiter */
HAWK_CUT_WHITESPACE = (1 << 2),
/** fold adjacent delimiters */
HAWK_CUT_FOLDDELIMS = (1 << 3),
/** trim leading and trailing whitespaces off the input line */
HAWK_CUT_TRIMSPACE = (1 << 4),
/** normalize whitespaces in the input line */
HAWK_CUT_NORMSPACE = (1 << 5)
};
typedef enum hawk_cut_option_t hawk_cut_option_t;
/**
* The hawk_cut_io_cmd_t type defines I/O command codes. The code indicates
* the action to take in an I/O handler.
*/
enum hawk_cut_io_cmd_t
{
HAWK_CUT_IO_OPEN = 0,
HAWK_CUT_IO_CLOSE = 1,
HAWK_CUT_IO_READ = 2,
HAWK_CUT_IO_WRITE = 3
};
typedef enum hawk_cut_io_cmd_t hawk_cut_io_cmd_t;
/**
* The hawk_cut_io_arg_t type defines a data structure required by
* an I/O handler.
*/
struct hawk_cut_io_arg_t
{
void* handle; /**< I/O handle */
const hawk_ooch_t* path; /**< file path. HAWK_NULL for a console */
};
typedef struct hawk_cut_io_arg_t hawk_cut_io_arg_t;
/**
* The hawk_cut_io_impl_t type defines an I/O handler. hawk_cut_exec() calls
* I/O handlers to read from and write to a text stream.
*/
typedef hawk_ooi_t (*hawk_cut_io_impl_t) (
hawk_cut_t* cut,
hawk_cut_io_cmd_t cmd,
hawk_cut_io_arg_t* arg,
hawk_ooch_t* data,
hawk_oow_t count
);
/* ------------------------------------------------------------------------ */
/**
* The hawk_cut_iostd_type_t type defines types of standard
* I/O resources.
*/
enum hawk_cut_iostd_type_t
{
HAWK_CUT_IOSTD_NULL, /**< null resource type */
HAWK_CUT_IOSTD_FILE, /**< file */
HAWK_CUT_IOSTD_FILEB, /**< file */
HAWK_CUT_IOSTD_FILEU, /**< file */
HAWK_CUT_IOSTD_OOCS, /**< string */
HAWK_CUT_IOSTD_BCS,
HAWK_CUT_IOSTD_UCS,
HAWK_CUT_IOSTD_SIO /**< sio */
};
typedef enum hawk_cut_iostd_type_t hawk_cut_iostd_type_t;
/**
* The hawk_cut_iostd_t type defines a standard I/O resource.
*/
struct hawk_cut_iostd_t
{
/** resource type */
hawk_cut_iostd_type_t type;
/** union describing the resource of the specified type */
union
{
/** file path with character encoding */
struct
{
/** file path to open. #HAWK_NULL or '-' for stdin/stdout. */
const hawk_ooch_t* path;
/** a stream created with the file path is set with this
* cmgr if it is not #HAWK_NULL. */
hawk_cmgr_t* cmgr;
} file;
struct
{
const hawk_bch_t* path;
hawk_cmgr_t* cmgr;
} fileb;
struct
{
const hawk_uch_t* path;
hawk_cmgr_t* cmgr;
} fileu;
/**
* input string or dynamically allocated output string
*
* For input, the ptr and the len field of str indicates the
* pointer and the length of a string to read. You must set
* these two fields before calling hawk_cut_execstd().
*
* For output, the ptr and the len field of str indicates the
* pointer and the length of produced output. The output
* string is dynamically allocated. You don't need to set these
* fields before calling hawk_cut_execstd() because they are
* set by hawk_cut_execstd() and valid while the relevant cut
* object is alive. You must free the memory chunk pointed to by
* the ptr field with hawk_cut_freemem() once you're done with it
* to avoid memory leaks.
*/
hawk_oocs_t oocs;
hawk_bcs_t bcs;
hawk_ucs_t ucs;
/** pre-opened sio stream */
hawk_sio_t* sio;
} u;
};
typedef struct hawk_cut_iostd_t hawk_cut_iostd_t;
#if defined(__cplusplus)
extern "C" {
#endif
/**
* The hawk_cut_open() function creates a text cutter.
* @return A pointer to a text cutter on success, #HAWK_NULL on failure
*/
HAWK_EXPORT hawk_cut_t* hawk_cut_open (
hawk_mmgr_t* mmgr, /**< memory manager */
hawk_oow_t xtnsize, /**< extension size in bytes */
hawk_cmgr_t* cmgr,
hawk_errnum_t* errnum
);
/**
* The hawk_cut_close() function destroys a text cutter.
*/
HAWK_EXPORT void hawk_cut_close (
hawk_cut_t* cut /**< text cutter */
);
#if defined(HAWK_HAVE_INLINE)
/**
* The hawk_cut_getxtn() function returns the pointer to the extension area
* placed behind the actual cut object.
*/
static HAWK_INLINE void* hawk_cut_getxtn (hawk_cut_t* cut) { return (void*)((hawk_uint8_t*)cut + ((hawk_cut_alt_t*)cut)->_instsize); }
/**
* The hawk_cut_getgem() function gets the pointer to the gem structure of the
* cut object.
*/
static HAWK_INLINE hawk_gem_t* hawk_cut_getgem (hawk_cut_t* cut) { return &((hawk_cut_alt_t*)cut)->_gem; }
/**
* The hawk_cut_getmmgr() function gets the memory manager ucut in
* hawk_cut_open().
*/
static HAWK_INLINE hawk_mmgr_t* hawk_cut_getmmgr (hawk_cut_t* cut) { return ((hawk_cut_alt_t*)cut)->_gem.mmgr; }
static HAWK_INLINE hawk_cmgr_t* hawk_cut_getcmgr (hawk_cut_t* cut) { return ((hawk_cut_alt_t*)cut)->_gem.cmgr; }
static HAWK_INLINE void hawk_cut_setcmgr (hawk_cut_t* cut, hawk_cmgr_t* cmgr) { ((hawk_cut_alt_t*)cut)->_gem.cmgr = cmgr; }
#else
#define hawk_cut_getxtn(cut) ((void*)((hawk_uint8_t*)cut + ((hawk_cut_alt_t*)cut)->_instsize))
#define hawk_cut_getgem(cut) (&((hawk_cut_alt_t*)(cut))->_gem)
#define hawk_cut_getmmgr(cut) (((hawk_cut_alt_t*)(cut))->_gem.mmgr)
#define hawk_cut_getcmgr(cut) (((hawk_cut_alt_t*)(cut))->_gem.cmgr)
#define hawk_cut_setcmgr(cut,_cmgr) (((hawk_cut_alt_t*)(cut))->_gem.cmgr = (_cmgr))
#endif /* HAWK_HAVE_INLINE */
/**
* The hawk_cut_getoption() function retrieves the current options set in
* a text cutter.
* @return 0 or a number OR'ed of #hawk_cut_option_t values
*/
HAWK_EXPORT int hawk_cut_getoption (
hawk_cut_t* cut /**< text cutter */
);
/**
* The hawk_cut_setoption() function sets the option code.
*/
HAWK_EXPORT void hawk_cut_setoption (
hawk_cut_t* cut, /**< text cutter */
int opt /**< 0 or a number OR'ed of #hawk_cut_option_t values */
);
HAWK_EXPORT hawk_errstr_t hawk_cut_geterrstr (
hawk_cut_t* cut
);
/**
* The hawk_cut_geterrnum() function returns the number of the last error
* occurred.
* \return error number
*/
/**
* The hawk_cut_geterror() function gets an error number, an error location,
* and an error message. The information is set to the memory area pointed
* to by each parameter.
*/
#if defined(HAWK_HAVE_INLINE)
static HAWK_INLINE hawk_errnum_t hawk_cut_geterrnum (hawk_cut_t* cut) { return hawk_gem_geterrnum(hawk_cut_getgem(cut)); }
static HAWK_INLINE const hawk_loc_t* hawk_cut_geterrloc (hawk_cut_t* cut) { return hawk_gem_geterrloc(hawk_cut_getgem(cut)); }
static HAWK_INLINE const hawk_bch_t* hawk_cut_geterrbmsg (hawk_cut_t* cut) { return hawk_gem_geterrbmsg(hawk_cut_getgem(cut)); }
static HAWK_INLINE const hawk_uch_t* hawk_cut_geterrumsg (hawk_cut_t* cut) { return hawk_gem_geterrumsg(hawk_cut_getgem(cut)); }
static HAWK_INLINE void hawk_cut_geterrbinf (hawk_cut_t* cut, hawk_errbinf_t* errinf) { return hawk_gem_geterrbinf(hawk_cut_getgem(cut), errinf); }
static HAWK_INLINE void hawk_cut_geterruinf (hawk_cut_t* cut, hawk_erruinf_t* errinf) { return hawk_gem_geterruinf(hawk_cut_getgem(cut), errinf); }
static HAWK_INLINE void hawk_cut_geterror (hawk_cut_t* cut, hawk_errnum_t* errnum, const hawk_ooch_t** errmsg, hawk_loc_t* errloc) { return hawk_gem_geterror(hawk_cut_getgem(cut), errnum, errmsg, errloc); }
#else
#define hawk_cut_geterrnum(cut) hawk_gem_geterrnum(hawk_cut_getgem(cut))
#define hawk_cut_geterrloc(cut) hawk_gem_geterrloc(hawk_cut_getgem(cut))
#define hawk_cut_geterrbmsg(cut) hawk_gem_geterrbmsg(hawk_cut_getgem(cut))
#define hawk_cut_geterrumsg(cut) hawk_gem_geterrumsg(hawk_cut_getgem(cut))
#define hawk_cut_geterrbinf(cut, errinf) (hawk_gem_geterrbinf(hawk_cut_getgem(cut), errinf))
#define hawk_cut_geterruinf(cut, errinf) (hawk_gem_geterruinf(hawk_cut_getgem(cut), errinf))
#define hawk_cut_geterror(cut, errnum, errmsg, errloc) (hawk_gem_geterror(hawk_cut_getgem(cut), errnum, errmsg, errloc))
#endif
#if defined(HAWK_OOCH_IS_BCH)
# define hawk_cut_geterrmsg hawk_cut_geterrbmsg
# define hawk_cut_geterrinf hawk_cut_geterrbinf
#else
# define hawk_cut_geterrmsg hawk_cut_geterrumsg
# define hawk_cut_geterrinf hawk_cut_geterruinf
#endif
/**
* The hawk_cut_seterrnum() function sets the error information omitting
* error location. You must pass a non-NULL for \a errarg if the specified
* error number \a errnum requires one or more arguments to format an
* error message.
*/
#if defined(HAWK_HAVE_INLINE)
static HAWK_INLINE void hawk_cut_seterrnum (hawk_cut_t* cut, const hawk_loc_t* errloc, hawk_errnum_t errnum) { hawk_gem_seterrnum (hawk_cut_getgem(cut), errloc, errnum); }
static HAWK_INLINE void hawk_cut_seterrinf (hawk_cut_t* cut, const hawk_errinf_t* errinf) { hawk_gem_seterrinf (hawk_cut_getgem(cut), errinf); }
static HAWK_INLINE void hawk_cut_seterror (hawk_cut_t* cut, const hawk_loc_t* errloc, hawk_errnum_t errnum, const hawk_oocs_t* errarg) { hawk_gem_seterror(hawk_cut_getgem(cut), errloc, errnum, errarg); }
static HAWK_INLINE const hawk_ooch_t* hawk_cut_backuperrmsg (hawk_cut_t* cut) { return hawk_gem_backuperrmsg(hawk_cut_getgem(cut)); }
#else
#define hawk_cut_seterrnum(cut, errloc, errnum) hawk_gem_seterrnum(hawk_cut_getgem(cut), errloc, errnum)
#define hawk_cut_seterrinf(cut, errinf) hawk_gem_seterrinf(hawk_cut_getgem(cut), errinf)
#define hawk_cut_seterror(cut, errloc, errnum, errarg) hawk_gem_seterror(hawk_cut_getgem(cut), errloc, errnum, errarg)
#define hawk_cut_backuperrmsg(cut) hawk_gem_backuperrmsg(hawk_cut_getgem(cut))
#endif
HAWK_EXPORT void hawk_cut_seterrbfmt (
hawk_cut_t* cut,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_bch_t* fmt,
...
);
HAWK_EXPORT void hawk_cut_seterrufmt (
hawk_cut_t* cut,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_uch_t* fmt,
...
);
HAWK_EXPORT void hawk_cut_seterrbvfmt (
hawk_cut_t* cut,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_bch_t* errfmt,
va_list ap
);
HAWK_EXPORT void hawk_cut_seterruvfmt (
hawk_cut_t* cut,
const hawk_loc_t* errloc,
hawk_errnum_t errnum,
const hawk_uch_t* errfmt,
va_list ap
);
/**
* The hawk_cut_clear() function clears memory buffers internally allocated.
*/
HAWK_EXPORT void hawk_cut_clear (
hawk_cut_t* cut /**< text cutter */
);
/**
* The hawk_cut_comp() function compiles a selector into an internal form.
* @return 0 on success, -1 on error
*/
HAWK_EXPORT int hawk_cut_comp (
hawk_cut_t* cut, /**< text cutter */
const hawk_ooch_t* str, /**< selector pointer */
hawk_oow_t len /**< selector length */
);
/**
* The hawk_cut_exec() function executes the compiled commands.
* @return 0 on success, -1 on error
*/
HAWK_EXPORT int hawk_cut_exec (
hawk_cut_t* cut, /**< text cutter */
hawk_cut_io_impl_t inf, /**< input text stream */
hawk_cut_io_impl_t outf /**< output text stream */
);
/**
* The hawk_cut_allocmem() function allocates a chunk of memory using
* the memory manager of \a cut.
*/
HAWK_EXPORT void* hawk_cut_allocmem (
hawk_cut_t* cut,
hawk_oow_t size
);
/**
* The hawk_cut_callocmem() function allocates a chunk of memory using
* the memory manager of \a cut and clears it to zeros.
*/
HAWK_EXPORT void* hawk_cut_callocmem (
hawk_cut_t* cut,
hawk_oow_t size
);
/**
* The hawk_cut_reallocmem() function reallocates a chunk of memory using
* the memory manager of \a cut.
*/
HAWK_EXPORT void* hawk_cut_reallocmem (
hawk_cut_t* cut,
void* ptr,
hawk_oow_t size
);
/**
* The hawk_cut_freemem() function frees a chunk of memory using
* the memory manager of \a cut.
*/
HAWK_EXPORT void hawk_cut_freemem (
hawk_cut_t* cut,
void* ptr
);
/**
* The hawk_cut_openstd() function creates a text cutter with the default
* memory manager and initialized it for other hawk_cut_xxxxstd functions.
* @return pointer to a text cutter on success, QSE_NULL on failure.
*/
HAWK_EXPORT hawk_cut_t* hawk_cut_openstd (
hawk_oow_t xtnsize, /**< extension size in bytes */
hawk_errnum_t* errnum
);
/**
* The hawk_cut_openstdwithmmgr() function creates a text cutter with a
* user-defined memory manager. It is equivalent to hawk_cut_openstd(),
* except that you can specify your own memory manager.
* @return pointer to a text cutter on success, QSE_NULL on failure.
*/
HAWK_EXPORT hawk_cut_t* hawk_cut_openstdwithmmgr (
hawk_mmgr_t* mmgr, /**< memory manager */
hawk_oow_t xtnsize, /**< extension size in bytes */
hawk_cmgr_t* cmgr,
hawk_errnum_t* errnum
);
/**
* The hawk_cut_compstd() function compiles a null-terminated selector.
* Call hawk_cut_comp() for a length delimited selector.
*/
HAWK_EXPORT int hawk_cut_compstd (
hawk_cut_t* cut,
const hawk_ooch_t* str
);
/**
* The hawk_cut_execstd() function executes the compiled script
* over an input file @a infile and an output file @a outfile.
* If @a infile is QSE_NULL, the standard console input is used.
* If @a outfile is QSE_NULL, the standard console output is used..
*/
HAWK_EXPORT int hawk_cut_execstd (
hawk_cut_t* cut,
hawk_cut_iostd_t in[],
hawk_cut_iostd_t* out
);
HAWK_EXPORT int hawk_cut_execstdfile (
hawk_cut_t* cut,
const hawk_ooch_t* infile,
const hawk_ooch_t* outfile,
hawk_cmgr_t* cmgr
);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -335,6 +335,15 @@ HAWK_EXPORT hawk_oow_t hawk_becs_fmt (
...
);
HAWK_EXPORT hawk_oow_t hawk_becs_compact (
hawk_becs_t* str
);
HAWK_EXPORT hawk_oow_t hawk_becs_trim (
hawk_becs_t* str,
int flags
);
/* ------------------------------------------------------------------------ */
/**
@ -550,6 +559,15 @@ HAWK_EXPORT hawk_oow_t hawk_uecs_fmt (
...
);
HAWK_EXPORT hawk_oow_t hawk_uecs_compact (
hawk_uecs_t* str
);
HAWK_EXPORT hawk_oow_t hawk_uecs_trim (
hawk_uecs_t* str,
int flags
);
#if defined(HAWK_OOCH_IS_UCH)
# define hawk_ooecs_open hawk_uecs_open
# define hawk_ooecs_close hawk_uecs_close
@ -579,6 +597,8 @@ HAWK_EXPORT hawk_oow_t hawk_uecs_fmt (
# define hawk_ooecs_fcat hawk_uecs_fcat
# define hawk_ooecs_vfmt hawk_uecs_vfmt
# define hawk_ooecs_fmt hawk_uecs_fmt
# define hawk_ooecs_compact hawk_uecs_compact
# define hawk_ooecs_trim hawk_uecs_trim
#else
# define hawk_ooecs_open hawk_becs_open
# define hawk_ooecs_close hawk_becs_close
@ -608,6 +628,8 @@ HAWK_EXPORT hawk_oow_t hawk_uecs_fmt (
# define hawk_ooecs_fcat hawk_becs_fcat
# define hawk_ooecs_vfmt hawk_becs_vfmt
# define hawk_ooecs_fmt hawk_becs_fmt
# define hawk_ooecs_compact hawk_becs_compact
# define hawk_ooecs_trim hawk_becs_trim
#endif
HAWK_EXPORT hawk_oow_t hawk_becs_ncatuchars (

View File

@ -499,7 +499,7 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_update (
* hawk_htb_t* htb, hawk_htb_pair_t* pair,
* void* kptr, hawk_oow_t klen, void* ctx)
* {
* hawk_cstr_t* v = (hawk_cstr_t*)ctx;
* hawk_oocs_t* v = (hawk_oocs_t*)ctx;
* if (pair == HAWK_NULL)
* {
* // no existing key for the key
@ -552,7 +552,7 @@ HAWK_EXPORT hawk_htb_pair_t* hawk_htb_update (
*
* for (i = 0; i < HAWK_COUNTOF(vals); i++)
* {
* hawk_cstr_t ctx;
* hawk_oocs_t ctx;
* ctx.ptr = vals[i]; ctx.len = hawk_count_oocstr(vals[i]);
* hawk_htb_cbsert (s1,
* keys[i%HAWK_COUNTOF(keys)], hawk_count_oocstr(keys[i%HAWK_COUNTOF(keys)]),

View File

@ -463,7 +463,7 @@ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_update (
* hawk_rbt_t* rbt, hawk_rbt_pair_t* pair,
* void* kptr, hawk_oow_t klen, void* ctx)
* {
* hawk_cstr_t* v = (hawk_cstr_t*)ctx;
* hawk_oocs_t* v = (hawk_oocs_t*)ctx;
* if (pair == HAWK_NULL)
* {
* // no existing key for the key
@ -515,7 +515,7 @@ HAWK_EXPORT hawk_rbt_pair_t* hawk_rbt_update (
*
* for (i = 0; i < HAWK_COUNTOF(vals); i++)
* {
* hawk_cstr_t ctx;
* hawk_oocs_t ctx;
* ctx.ptr = vals[i]; ctx.len = hawk_count_oocstr(vals[i]);
* hawk_rbt_cbsert (s1,
* keys[i%HAWK_COUNTOF(keys)], hawk_count_oocstr(keys[i%HAWK_COUNTOF(keys)]),

View File

@ -735,6 +735,15 @@ HAWK_EXPORT void hawk_sed_setlinenum (
hawk_oow_t num /**< a line number */
);
/**
* The hawk_sed_getspace() function gets the pointer and the length
* to a buffer space specfied by \a space.
*/
HAWK_EXPORT void hawk_sed_getspace (
hawk_sed_t* sed,
hawk_sed_space_t space,
hawk_oocs_t* str
);
/**
* The hawk_sed_allocmem() function allocates a chunk of memory using
@ -746,7 +755,7 @@ HAWK_EXPORT void* hawk_sed_allocmem (
);
/**
* The hawk_sed_allocmem() function allocates a chunk of memory using
* The hawk_sed_callocmem() function allocates a chunk of memory using
* the memory manager of \a sed and clears it to zeros.
*/
HAWK_EXPORT void* hawk_sed_callocmem (
@ -755,7 +764,7 @@ HAWK_EXPORT void* hawk_sed_callocmem (
);
/**
* The hawk_sed_allocmem() function reallocates a chunk of memory using
* The hawk_sed_reallocmem() function reallocates a chunk of memory using
* the memory manager of \a sed.
*/
HAWK_EXPORT void* hawk_sed_reallocmem (
@ -765,7 +774,7 @@ HAWK_EXPORT void* hawk_sed_reallocmem (
);
/**
* The hawk_sed_allocmem() function frees a chunk of memory using
* The hawk_sed_freemem() function frees a chunk of memory using
* the memory manager of \a sed.
*/
HAWK_EXPORT void hawk_sed_freemem (
@ -773,16 +782,6 @@ HAWK_EXPORT void hawk_sed_freemem (
void* ptr
);
/**
* The hawk_sed_getspace() function gets the pointer and the length
* to a buffer space specfied by \a space.
*/
HAWK_EXPORT void hawk_sed_getspace (
hawk_sed_t* sed,
hawk_sed_space_t space,
hawk_oocs_t* str
);
/* ------------------------------------------------------------------------ */
/**

View File

@ -272,10 +272,39 @@ HAWK_EXPORT const hawk_ooch_t* hawk_stdgetfileindirs (
/* ------------------------------------------------------------------------- */
/**
* The hawk_get_sys_mmgr() function returns a pointer to a stock memory manager structure
* that can be used where a custom memory manager is not required. The returned structure
* is managed internally and should not be modified or finalized by the caller.
*
* \return Pointer to the system-wide default memory manager.
*/
HAWK_EXPORT hawk_mmgr_t* hawk_get_sys_mmgr (
void
);
/**
* This hawk_init_xma_mmgr() function initializes the memory manager structure pointed
* to by `mmgr` with the specified memory limit `memlimit`. The caller is responsible for
* allocating the memory for `mmgr` prior to calling this function.
*
* \return 0 on success, or a negative value on failure
*/
HAWK_EXPORT int hawk_init_xma_mmgr (
hawk_mmgr_t* mmgr,
hawk_oow_t memlimit
);
/**
* The hawk_fini_xma_mmgr() function cleans up resources associated with the memory
* manager structure previously initialized by `hawk_init_xma_mmgr()`. After this call,
* the `mmgr` structure should not be used unless it is re-initialized.
*
*/
HAWK_EXPORT void hawk_fini_xma_mmgr (
hawk_mmgr_t* mmgr
);
#if defined(__cplusplus)
}
#endif

View File

@ -72,9 +72,8 @@
*/
#include <hawk-cmn.h>
#if defined(HAWK_BUILD_DEBUG)
# define HAWK_XMA_ENABLE_STAT
#endif
/*#define HAWK_XMA_ENABLE_STAT*/
#define HAWK_XMA_ENABLE_STAT
/** @struct hawk_xma_t
* The hawk_xma_t type defines a simple memory allocator over a memory zone.
@ -109,10 +108,19 @@ struct hawk_xma_t
struct
{
hawk_oow_t total;
hawk_oow_t alloc;
hawk_oow_t avail;
hawk_oow_t nused;
hawk_oow_t nfree;
hawk_oow_t alloc; /* allocated size */
hawk_oow_t avail; /* available size */
hawk_oow_t nused; /* nubmer of used blocks */
hawk_oow_t nfree; /* number of free blocks */
hawk_oow_t alloc_hwmark; /* high watermark - highest total memory ever allocated */
hawk_oow_t nallocops; /* number of alloc operations */
hawk_oow_t nallocgoodops; /* number of successful alloc operations */
hawk_oow_t nallocbadops; /* number of failed alloc operations */
hawk_oow_t nreallocops; /* number of realloc operations */
hawk_oow_t nreallocgoodops; /* number of good realloc operations */
hawk_oow_t nreallocbadops; /* number of failed realloc operations - could fall back to normal alloc*/
hawk_oow_t nfreeops; /* number of free operations */
} stat;
#endif
};

521
lib/run.c

File diff suppressed because it is too large Load Diff

View File

@ -2050,10 +2050,7 @@ static int read_char (hawk_sed_t* sed, hawk_ooch_t* c)
{
if (sed->e.in.pos >= sed->e.in.len)
{
n = sed->e.in.fun (
sed, HAWK_SED_IO_READ, &sed->e.in.arg,
sed->e.in.buf, HAWK_COUNTOF(sed->e.in.buf)
);
n = sed->e.in.fun(sed, HAWK_SED_IO_READ, &sed->e.in.arg, sed->e.in.buf, HAWK_COUNTOF(sed->e.in.buf));
if (n <= -1) return -1;
if (n == 0) return 0; /* end of file */
@ -2127,10 +2124,7 @@ static int flush (hawk_sed_t* sed)
while (sed->e.out.len > 0)
{
n = sed->e.out.fun (
sed, HAWK_SED_IO_WRITE, &sed->e.out.arg,
&sed->e.out.buf[pos], sed->e.out.len);
n = sed->e.out.fun(sed, HAWK_SED_IO_WRITE, &sed->e.out.arg, &sed->e.out.buf[pos], sed->e.out.len);
if (n <= -1) return -1;
if (n == 0) return -1; /* reached the end of file - this is also an error */
@ -2144,12 +2138,7 @@ static int flush (hawk_sed_t* sed)
static int write_char (hawk_sed_t* sed, hawk_ooch_t c)
{
sed->e.out.buf[sed->e.out.len++] = c;
if (c == HAWK_T('\n') ||
sed->e.out.len >= HAWK_COUNTOF(sed->e.out.buf))
{
return flush (sed);
}
if (c == HAWK_T('\n') || sed->e.out.len >= HAWK_COUNTOF(sed->e.out.buf)) return flush (sed);
return 0;
}
@ -3949,6 +3938,21 @@ void hawk_sed_pushecb (hawk_sed_t* sed, hawk_sed_ecb_t* ecb)
sed->ecb = ecb;
}
void hawk_sed_getspace (hawk_sed_t* sed, hawk_sed_space_t space, hawk_oocs_t* str)
{
switch (space)
{
case HAWK_SED_SPACE_HOLD:
str->ptr = HAWK_OOECS_PTR(&sed->e.txt.hold);
str->len = HAWK_OOECS_LEN(&sed->e.txt.hold);
break;
case HAWK_SED_SPACE_PATTERN:
str->ptr = HAWK_OOECS_PTR(&sed->e.in.line);
str->len = HAWK_OOECS_LEN(&sed->e.in.line);
break;
}
}
void* hawk_sed_allocmem (hawk_sed_t* sed, hawk_oow_t size)
{
void* ptr = HAWK_MMGR_ALLOC(hawk_sed_getmmgr(sed), size);
@ -3975,19 +3979,3 @@ void hawk_sed_freemem (hawk_sed_t* sed, void* ptr)
{
HAWK_MMGR_FREE (hawk_sed_getmmgr(sed), ptr);
}
void hawk_sed_getspace (hawk_sed_t* sed, hawk_sed_space_t space, hawk_oocs_t* str)
{
switch (space)
{
case HAWK_SED_SPACE_HOLD:
str->ptr = HAWK_OOECS_PTR(&sed->e.txt.hold);
str->len = HAWK_OOECS_LEN(&sed->e.txt.hold);
break;
case HAWK_SED_SPACE_PATTERN:
str->ptr = HAWK_OOECS_PTR(&sed->e.in.line);
str->len = HAWK_OOECS_LEN(&sed->e.in.line);
break;
}
}

1217
lib/std-cut.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -120,13 +120,14 @@ hawk_sed_t* hawk_sed_openstdwithmmgr (hawk_mmgr_t* mmgr, hawk_oow_t xtnsize, haw
if (!cmgr) cmgr = hawk_get_cmgr_by_id(HAWK_CMGR_UTF8);
sed = hawk_sed_open(mmgr, HAWK_SIZEOF(xtn_t) + xtnsize, cmgr, errnum);
if (!sed) return HAWK_NULL;
if (HAWK_UNLIKELY(!sed)) return HAWK_NULL;
sed->_instsize += HAWK_SIZEOF(xtn_t);
return sed;
}
/* ------------------------------------------------------------- */
static int verify_iostd_in (hawk_sed_t* sed, hawk_sed_iostd_t in[])
{
hawk_oow_t i;
@ -135,7 +136,7 @@ static int verify_iostd_in (hawk_sed_t* sed, hawk_sed_iostd_t in[])
{
/* if 'in' is specified, it must contains at least one
* valid entry */
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_EINVAL, "no input handler provided");
hawk_sed_seterrbfmt(sed, HAWK_NULL, HAWK_EINVAL, "no input handler provided");
return -1;
}
@ -149,7 +150,7 @@ static int verify_iostd_in (hawk_sed_t* sed, hawk_sed_iostd_t in[])
in[i].type != HAWK_SED_IOSTD_UCS &&
in[i].type != HAWK_SED_IOSTD_SIO)
{
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_EINVAL, "unsupported input type provided - handler %d type %d", i, in[i].type);
hawk_sed_seterrbfmt(sed, HAWK_NULL, HAWK_EINVAL, "unsupported input type provided - handler %d type %d", i, in[i].type);
return -1;
}
}
@ -165,7 +166,7 @@ static hawk_sio_t* open_sio_file (hawk_sed_t* sed, const hawk_ooch_t* file, int
if (sio == HAWK_NULL)
{
const hawk_ooch_t* bem = hawk_sed_backuperrmsg(sed);
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to open %js - %js", file, bem);
hawk_sed_seterrbfmt(sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to open %js - %js", file, bem);
}
return sio;
}
@ -188,7 +189,7 @@ static hawk_ooch_t* add_sio_name_with_uchars (hawk_sed_t* sed, const hawk_uch_t*
link = (hawk_link_t*)hawk_sed_callocmem(sed, HAWK_SIZEOF(*link) + HAWK_SIZEOF(hawk_uch_t) * (len + 1));
if (!link) return HAWK_NULL;
hawk_copy_uchars_to_ucstr_unlimited ((hawk_uch_t*)(link + 1), ptr, len);
hawk_copy_uchars_to_ucstr_unlimited((hawk_uch_t*)(link + 1), ptr, len);
#else
hawk_oow_t bcslen, ucslen;
@ -200,7 +201,7 @@ static hawk_ooch_t* add_sio_name_with_uchars (hawk_sed_t* sed, const hawk_uch_t*
ucslen = len;
bcslen = bcslen + 1;
hawk_gem_convutobchars (hawk_sed_getgem(sed), ptr, &ucslen, (hawk_bch_t*)(link + 1), &bcslen);
hawk_gem_convutobchars(hawk_sed_getgem(sed), ptr, &ucslen, (hawk_bch_t*)(link + 1), &bcslen);
((hawk_bch_t*)(link + 1))[bcslen] = '\0';
#endif
@ -228,14 +229,14 @@ static hawk_ooch_t* add_sio_name_with_bchars (hawk_sed_t* sed, const hawk_bch_t*
bcslen = len;
ucslen = ucslen + 1;
hawk_gem_convbtouchars (hawk_sed_getgem(sed), ptr, &bcslen, (hawk_uch_t*)(link + 1), &ucslen, 0);
hawk_gem_convbtouchars(hawk_sed_getgem(sed), ptr, &bcslen, (hawk_uch_t*)(link + 1), &ucslen, 0);
((hawk_uch_t*)(link + 1))[ucslen] = '\0';
#else
link = (hawk_link_t*)hawk_sed_callocmem(sed, HAWK_SIZEOF(*link) + HAWK_SIZEOF(hawk_bch_t) * (len + 1));
if (!link) return HAWK_NULL;
hawk_copy_bchars_to_bcstr_unlimited ((hawk_bch_t*)(link + 1), ptr, len);
hawk_copy_bchars_to_bcstr_unlimited((hawk_bch_t*)(link + 1), ptr, len);
#endif
link->link = xtn->sio_names;
@ -265,7 +266,7 @@ static hawk_sio_t* open_sio_std (hawk_sed_t* sed, hawk_sio_std_t std, int flags)
if (sio == HAWK_NULL)
{
const hawk_ooch_t* bem = hawk_sed_backuperrmsg(sed);
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to open %js - %js", &sio_std_names[std], bem);
hawk_sed_seterrbfmt(sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to open %js - %js", &sio_std_names[std], bem);
}
return sio;
}
@ -284,25 +285,25 @@ static void set_eiofil_for_iostd (hawk_sed_t* sed, hawk_sed_iostd_t* io)
case HAWK_SED_IOSTD_FILE:
#endif
case HAWK_SED_IOSTD_FILEB:
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "I/O error with file '%hs' - %js", io->u.fileb.path, bem);
hawk_sed_seterrbfmt(sed, HAWK_NULL, HAWK_SED_EIOFIL, "I/O error with file '%hs' - %js", io->u.fileb.path, bem);
break;
#if defined(HAWK_OOCH_IS_UCH)
case HAWK_SED_IOSTD_FILE:
#endif
case HAWK_SED_IOSTD_FILEU:
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "I/O error with file '%ls' - %js", io->u.fileu.path, bem);
hawk_sed_seterrbfmt(sed, HAWK_NULL, HAWK_SED_EIOFIL, "I/O error with file '%ls' - %js", io->u.fileu.path, bem);
break;
default:
HAWK_ASSERT (!"should never happen - unknown file I/O type");
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINVAL);
hawk_sed_seterrnum(sed, HAWK_NULL, HAWK_EINVAL);
break;
}
}
else
{
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "I/O error with file '%js' - %js", &sio_std_names[HAWK_SIO_STDIN], bem);
hawk_sed_seterrbfmt(sed, HAWK_NULL, HAWK_SED_EIOFIL, "I/O error with file '%js' - %js", &sio_std_names[HAWK_SIO_STDIN], bem);
}
}
@ -314,7 +315,7 @@ static void close_main_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, hawk_sed
case HAWK_SED_IOSTD_FILE:
case HAWK_SED_IOSTD_FILEB:
case HAWK_SED_IOSTD_FILEU:
hawk_sio_close (arg->handle);
hawk_sio_close(arg->handle);
break;
case HAWK_SED_IOSTD_OOCS:
@ -412,7 +413,7 @@ static int open_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, hawk_sed_
default:
HAWK_ASSERT (!"should never happen - io-type must be one of SIO,FILE,FILEB,FILEU,STR");
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINTERN);
hawk_sed_seterrnum(sed, HAWK_NULL, HAWK_EINTERN);
return -1;
}
@ -576,7 +577,7 @@ static int open_output_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, hawk_sed
default:
HAWK_ASSERT (!"should never happen - io-type must be one of SIO,FILE,FILEB,FILEU,STR");
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINTERN);
hawk_sed_seterrnum(sed, HAWK_NULL, HAWK_EINTERN);
return -1;
}
@ -624,7 +625,7 @@ static hawk_ooi_t read_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, ha
wcslen = len;
if ((m = hawk_conv_bchars_to_uchars_with_cmgr(&io->u.bcs.ptr[base->mempos], &mbslen, buf, &wcslen, hawk_sed_getcmgr(sed), 0)) <= -1 && m != -2)
{
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EECERR);
hawk_sed_seterrnum(sed, HAWK_NULL, HAWK_EECERR);
n = -1;
}
else
@ -646,7 +647,7 @@ static hawk_ooi_t read_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, ha
mbslen = len;
if ((m = hawk_conv_uchars_to_bchars_with_cmgr(&io->u.ucs.ptr[base->mempos], &wcslen, buf, &mbslen, hawk_sed_getcmgr(sed))) <= -1 && m != -2)
{
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EECERR);
hawk_sed_seterrnum(sed, HAWK_NULL, HAWK_EECERR);
n = -1;
}
else
@ -714,7 +715,7 @@ static hawk_ooi_t read_input_stream (hawk_sed_t* sed, hawk_sed_io_arg_t* arg, ha
arg->handle = old;
/* close the previous stream */
close_main_stream (sed, arg, io);
close_main_stream(sed, arg, io);
arg->handle = new;
@ -739,7 +740,7 @@ static hawk_ooi_t s_in (hawk_sed_t* sed, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_
case HAWK_SED_IO_CLOSE:
{
close_main_stream (sed, arg, xtn->s.in.cur);
close_main_stream(sed, arg, xtn->s.in.cur);
return 0;
}
@ -751,7 +752,7 @@ static hawk_ooi_t s_in (hawk_sed_t* sed, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_
default:
{
HAWK_ASSERT (!"should never happen - cmd must be one of OPEN,CLOSE,READ");
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINTERN);
hawk_sed_seterrnum(sed, HAWK_NULL, HAWK_EINTERN);
return -1;
}
}
@ -799,13 +800,13 @@ static hawk_ooi_t x_in (hawk_sed_t* sed, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_
{
/* main data stream */
if (xtn->e.in.ptr == HAWK_NULL)
hawk_sio_close (arg->handle);
hawk_sio_close(arg->handle);
else
close_main_stream (sed, arg, xtn->e.in.cur);
close_main_stream(sed, arg, xtn->e.in.cur);
}
else
{
hawk_sio_close (arg->handle);
hawk_sio_close(arg->handle);
}
return 0;
@ -823,7 +824,7 @@ static hawk_ooi_t x_in (hawk_sed_t* sed, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_
if (n <= -1)
{
const hawk_ooch_t* bem = hawk_sed_backuperrmsg(sed);
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to read '%js' - %js", &sio_std_names[HAWK_SIO_STDIN], bem);
hawk_sed_seterrbfmt(sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to read '%js' - %js", &sio_std_names[HAWK_SIO_STDIN], bem);
}
return n;
}
@ -839,7 +840,7 @@ static hawk_ooi_t x_in (hawk_sed_t* sed, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_
if (n <= -1)
{
const hawk_ooch_t* bem = hawk_sed_backuperrmsg(sed);
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to read '%js' - %js", arg->path, bem);
hawk_sed_seterrbfmt(sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to read '%js' - %js", arg->path, bem);
}
return n;
}
@ -847,7 +848,7 @@ static hawk_ooi_t x_in (hawk_sed_t* sed, hawk_sed_io_cmd_t cmd, hawk_sed_io_arg_
default:
HAWK_ASSERT (!"should never happen - cmd must be one of OPEN,CLOSE,READ");
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINTERN);
hawk_sed_seterrnum(sed, HAWK_NULL, HAWK_EINTERN);
return -1;
}
}
@ -908,13 +909,13 @@ static hawk_ooi_t x_out (
if (arg->path == HAWK_NULL)
{
if (xtn->e.out.ptr == HAWK_NULL)
hawk_sio_close (arg->handle);
hawk_sio_close(arg->handle);
else
close_main_stream (sed, arg, xtn->e.out.ptr);
close_main_stream(sed, arg, xtn->e.out.ptr);
}
else
{
hawk_sio_close (arg->handle);
hawk_sio_close(arg->handle);
}
return 0;
}
@ -977,7 +978,7 @@ static hawk_ooi_t x_out (
if (n <= -1)
{
const hawk_ooch_t* bem = hawk_sed_backuperrmsg(sed);
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to write '%js' - %js", arg->path, bem);
hawk_sed_seterrbfmt(sed, HAWK_NULL, HAWK_SED_EIOFIL, "unable to write '%js' - %js", arg->path, bem);
}
return n;
}
@ -985,11 +986,13 @@ static hawk_ooi_t x_out (
default:
HAWK_ASSERT (!"should never happen - cmd must be one of OPEN,CLOSE,WRITE");
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINTERN);
hawk_sed_seterrnum(sed, HAWK_NULL, HAWK_EINTERN);
return -1;
}
}
/* ------------------------------------------------------------- */
int hawk_sed_compstd (hawk_sed_t* sed, hawk_sed_iostd_t in[], hawk_oow_t* count)
{
xtn_t* xtn = GET_XTN(sed);
@ -998,7 +1001,7 @@ int hawk_sed_compstd (hawk_sed_t* sed, hawk_sed_iostd_t in[], hawk_oow_t* count)
if (in == HAWK_NULL)
{
/* it requires a valid array unlike hawk_sed_execstd(). */
hawk_sed_seterrbfmt (sed, HAWK_NULL, HAWK_EINVAL, "no input handler provided");
hawk_sed_seterrbfmt(sed, HAWK_NULL, HAWK_EINVAL, "no input handler provided");
if (count) *count = 0;
return -1;
}
@ -1008,7 +1011,7 @@ int hawk_sed_compstd (hawk_sed_t* sed, hawk_sed_iostd_t in[], hawk_oow_t* count)
return -1;
}
HAWK_MEMSET (&xtn->s, 0, HAWK_SIZEOF(xtn->s));
HAWK_MEMSET(&xtn->s, 0, HAWK_SIZEOF(xtn->s));
xtn->s.in.ptr = in;
xtn->s.in.cur = in;
@ -1016,7 +1019,7 @@ int hawk_sed_compstd (hawk_sed_t* sed, hawk_sed_iostd_t in[], hawk_oow_t* count)
if (count) *count = xtn->s.in.cur - xtn->s.in.ptr;
clear_sio_names (sed);
clear_sio_names(sed);
return ret;
}
@ -1035,12 +1038,12 @@ int hawk_sed_execstd (hawk_sed_t* sed, hawk_sed_iostd_t in[], hawk_sed_iostd_t*
out->type != HAWK_SED_IOSTD_OOCS &&
out->type != HAWK_SED_IOSTD_SIO)
{
hawk_sed_seterrnum (sed, HAWK_NULL, HAWK_EINVAL);
hawk_sed_seterrnum(sed, HAWK_NULL, HAWK_EINVAL);
return -1;
}
}
HAWK_MEMSET (&xtn->e, 0, HAWK_SIZEOF(xtn->e));
HAWK_MEMSET(&xtn->e, 0, HAWK_SIZEOF(xtn->e));
xtn->e.in.ptr = in;
xtn->e.in.cur = in;
xtn->e.out.ptr = out;
@ -1060,7 +1063,7 @@ int hawk_sed_execstd (hawk_sed_t* sed, hawk_sed_iostd_t in[], hawk_sed_iostd_t*
HAWK_ASSERT (xtn->e.out.memstr.be != HAWK_NULL);
hawk_becs_yield (xtn->e.out.memstr.be, &out->u.bcs, 0);
}
if (xtn->e.out.memstr.be) hawk_becs_close (xtn->e.out.memstr.be);
if (xtn->e.out.memstr.be) hawk_becs_close(xtn->e.out.memstr.be);
break;
#if defined(HAWK_OOCH_IS_UCH)
@ -1072,7 +1075,7 @@ int hawk_sed_execstd (hawk_sed_t* sed, hawk_sed_iostd_t in[], hawk_sed_iostd_t*
HAWK_ASSERT (xtn->e.out.memstr.ue != HAWK_NULL);
hawk_uecs_yield (xtn->e.out.memstr.ue, &out->u.ucs, 0);
}
if (xtn->e.out.memstr.ue) hawk_uecs_close (xtn->e.out.memstr.ue);
if (xtn->e.out.memstr.ue) hawk_uecs_close(xtn->e.out.memstr.ue);
break;
default:
@ -1082,7 +1085,7 @@ int hawk_sed_execstd (hawk_sed_t* sed, hawk_sed_iostd_t in[], hawk_sed_iostd_t*
}
clear_sio_names (sed);
clear_sio_names(sed);
return n;
}

View File

@ -26,6 +26,7 @@
#include <hawk-std.h>
#include <hawk-pio.h>
#include <hawk-sio.h>
#include <hawk-xma.h>
#include <stdio.h>
#include <stdarg.h>
@ -233,6 +234,47 @@ hawk_mmgr_t* hawk_get_sys_mmgr (void)
{
return &sys_mmgr;
}
/* ----------------------------------------------------------------------- */
static void* xma_alloc (hawk_mmgr_t* mmgr, hawk_oow_t size)
{
return hawk_xma_alloc(mmgr->ctx, size);
}
static void* xma_realloc (hawk_mmgr_t* mmgr, void* ptr, hawk_oow_t size)
{
return hawk_xma_realloc(mmgr->ctx, ptr, size);
}
static void xma_free (hawk_mmgr_t* mmgr, void* ptr)
{
hawk_xma_free (mmgr->ctx, ptr);
}
int hawk_init_xma_mmgr (hawk_mmgr_t* mmgr, hawk_oow_t memlimit)
{
hawk_xma_t* xma;
xma = hawk_xma_open(hawk_get_sys_mmgr(), 0, HAWK_NULL, memlimit);
if (HAWK_UNLIKELY(!xma)) return -1;
HAWK_MEMSET(mmgr, 0, HAWK_SIZEOF(*mmgr));
mmgr->alloc = xma_alloc;
mmgr->realloc = xma_realloc;
mmgr->free = xma_free;
mmgr->ctx = xma;
return 0;
}
void hawk_fini_xma_mmgr (hawk_mmgr_t* mmgr)
{
if (mmgr->ctx) hawk_xma_close(mmgr->ctx);
mmgr->ctx = HAWK_NULL;
}
/* ----------------------------------------------------------------------- */
@ -2490,14 +2532,13 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod)
if (rxtn->c.out.count == 0)
{
sio = open_sio_std_rtx (
sio = open_sio_std_rtx(
rtx, HAWK_SIO_STDOUT,
HAWK_SIO_WRITE | HAWK_SIO_IGNOREECERR | HAWK_SIO_LINEBREAK
);
if (sio == HAWK_NULL) return -1;
if (rxtn->c.cmgr) hawk_sio_setcmgr (sio, rxtn->c.cmgr);
riod->handle = sio;
rxtn->c.out.count++;
return 1;

View File

@ -720,7 +720,7 @@ hawk_flt_t hawk_uchars_to_flt (const hawk_uch_t* str, hawk_oow_t len, const hawk
end = str + len;
/* Strip off leading blanks and check for a sign */
/*while (AWK_IS_SPACE(*p)) p++;*/
/*while (hawk_is_uch_space(*p)) p++;*/
if (stripspc)
{
/* strip off leading spaces */
@ -929,7 +929,7 @@ hawk_flt_t hawk_bchars_to_flt (const hawk_bch_t* str, hawk_oow_t len, const hawk
end = str + len;
/* Strip off leading blanks and check for a sign */
/*while (AWK_IS_SPACE(*p)) p++;*/
/*while (hawk_is_bch_space(*p)) p++;*/
if (stripspc)
{
/* strip off leading spaces */

102
lib/xma.c
View File

@ -197,18 +197,18 @@ hawk_xma_t* hawk_xma_open (hawk_mmgr_t* mmgr, hawk_oow_t xtnsize, void* zoneptr,
if (hawk_xma_init(xma, mmgr, zoneptr, zonesize) <= -1)
{
HAWK_MMGR_FREE (mmgr, xma);
HAWK_MMGR_FREE(mmgr, xma);
return HAWK_NULL;
}
HAWK_MEMSET (xma + 1, 0, xtnsize);
HAWK_MEMSET(xma + 1, 0, xtnsize);
return xma;
}
void hawk_xma_close (hawk_xma_t* xma)
{
hawk_xma_fini (xma);
HAWK_MMGR_FREE (xma->_mmgr, xma);
HAWK_MMGR_FREE(xma->_mmgr, xma);
}
int hawk_xma_init (hawk_xma_t* xma, hawk_mmgr_t* mmgr, void* zoneptr, hawk_oow_t zonesize)
@ -246,7 +246,7 @@ int hawk_xma_init (hawk_xma_t* xma, hawk_mmgr_t* mmgr, void* zoneptr, hawk_oow_t
first->free_prev = HAWK_NULL;
first->free_next = HAWK_NULL;
HAWK_MEMSET (xma, 0, HAWK_SIZEOF(*xma));
HAWK_MEMSET(xma, 0, HAWK_SIZEOF(*xma));
xma->_mmgr = mmgr;
xma->bdec = szlog2(FIXED * ALIGN); /* precalculate the decrement value */
@ -268,6 +268,15 @@ int hawk_xma_init (hawk_xma_t* xma, hawk_mmgr_t* mmgr, void* zoneptr, hawk_oow_t
xma->stat.avail = zonesize - MBLKHDRSIZE;
xma->stat.nfree = 1;
xma->stat.nused = 0;
xma->stat.alloc_hwmark = 0;
xma->stat.nallocops = 0;
xma->stat.nallocgoodops = 0;
xma->stat.nallocbadops = 0;
xma->stat.nreallocops = 0;
xma->stat.nreallocgoodops = 0;
xma->stat.nreallocbadops = 0;
xma->stat.nfreeops = 0;
#endif
return 0;
@ -277,7 +286,7 @@ void hawk_xma_fini (hawk_xma_t* xma)
{
/* the head must point to the free chunk allocated in init().
* let's deallocate it */
if (xma->internal) HAWK_MMGR_FREE (xma->_mmgr, xma->start);
if (xma->internal) HAWK_MMGR_FREE(xma->_mmgr, xma->start);
xma->start = HAWK_NULL;
xma->end = HAWK_NULL;
}
@ -390,6 +399,7 @@ static hawk_xma_fblk_t* alloc_from_freelist (hawk_xma_t* xma, hawk_oow_t xfi, ha
xma->stat.nused++;
xma->stat.alloc += cand->size;
xma->stat.avail -= cand->size;
if (xma->stat.alloc > xma->stat.alloc_hwmark) xma->stat.alloc_hwmark = xma->stat.alloc;
#endif
return cand;
}
@ -406,6 +416,9 @@ void* hawk_xma_alloc (hawk_xma_t* xma, hawk_oow_t size)
DBG_VERIFY (xma, "alloc start");
#if defined(HAWK_XMA_ENABLE_STAT)
xma->stat.nallocops++;
#endif
/* round up 'size' to the multiples of ALIGN */
if (size < MINALLOCSIZE) size = MINALLOCSIZE;
size = HAWK_ALIGN_POW2(size, ALIGN);
@ -425,18 +438,25 @@ void* hawk_xma_alloc (hawk_xma_t* xma, hawk_oow_t size)
detach_from_freelist (xma, cand);
cand->free = 0;
#if defined(HAWK_XMA_ENABLE_STAT)
#if defined(HAWK_XMA_ENABLE_STAT)
xma->stat.nfree--;
xma->stat.nused++;
xma->stat.alloc += cand->size;
xma->stat.avail -= cand->size;
#endif
if (xma->stat.alloc > xma->stat.alloc_hwmark) xma->stat.alloc_hwmark = xma->stat.alloc;
#endif
}
else if (xfi == XFIMAX(xma))
{
/* huge block */
cand = alloc_from_freelist(xma, XFIMAX(xma), size);
if (!cand) return HAWK_NULL;
if (HAWK_UNLIKELY(!cand))
{
#if defined(HAWK_XMA_ENABLE_STAT)
xma->stat.nallocbadops++;
#endif
return HAWK_NULL;
}
}
else
{
@ -465,10 +485,19 @@ void* hawk_xma_alloc (hawk_xma_t* xma, hawk_oow_t size)
cand = alloc_from_freelist(xma, xfi, size);
if (cand) break;
}
if (!cand) return HAWK_NULL;
if (!cand)
{
#if defined(HAWK_XMA_ENABLE_STAT)
xma->stat.nallocbadops++;
#endif
return HAWK_NULL;
}
}
}
#if defined(HAWK_XMA_ENABLE_STAT)
xma->stat.nallocgoodops++;
#endif
DBG_VERIFY (xma, "alloc end");
return SYS_TO_USR(cand);
}
@ -522,10 +551,11 @@ static void* _realloc_merge (hawk_xma_t* xma, void* b, hawk_oow_t size)
z = next_mblk(y);
if ((hawk_uint8_t*)z < xma->end) z->prev_size = y->size;
#if defined(HAWK_XMA_ENABLE_STAT)
#if defined(HAWK_XMA_ENABLE_STAT)
xma->stat.alloc += req;
xma->stat.avail -= req; /* req + MBLKHDRSIZE(tmp) - MBLKHDRSIZE(n) */
#endif
if (xma->stat.alloc > xma->stat.alloc_hwmark) xma->stat.alloc_hwmark = xma->stat.alloc;
#endif
}
else
{
@ -538,11 +568,12 @@ static void* _realloc_merge (hawk_xma_t* xma, void* b, hawk_oow_t size)
z = next_mblk(blk);
if ((hawk_uint8_t*)z < xma->end) z->prev_size = blk->size;
#if defined(HAWK_XMA_ENABLE_STAT)
#if defined(HAWK_XMA_ENABLE_STAT)
xma->stat.nfree--;
xma->stat.alloc += MBLKHDRSIZE + n->size;
xma->stat.avail -= n->size;
#endif
if (xma->stat.alloc > xma->stat.alloc_hwmark) xma->stat.alloc_hwmark = xma->stat.alloc;
#endif
}
}
else if (size < blk->size)
@ -577,10 +608,10 @@ static void* _realloc_merge (hawk_xma_t* xma, void* b, hawk_oow_t size)
z = next_mblk(y); /* get adjacent block to the merged block */
if ((hawk_uint8_t*)z < xma->end) z->prev_size = y->size;
#if defined(HAWK_XMA_ENABLE_STAT)
#if defined(HAWK_XMA_ENABLE_STAT)
xma->stat.alloc -= rem;
xma->stat.avail += rem; /* rem - MBLKHDRSIZE(y) + MBLKHDRSIZE(n) */
#endif
#endif
}
else
{
@ -598,11 +629,11 @@ static void* _realloc_merge (hawk_xma_t* xma, void* b, hawk_oow_t size)
/*n = next_mblk(y);
if ((hawk_uint8_t*)n < xma->end)*/ n->prev_size = y->size;
#if defined(HAWK_XMA_ENABLE_STAT)
#if defined(HAWK_XMA_ENABLE_STAT)
xma->stat.nfree++;
xma->stat.alloc -= rem;
xma->stat.avail += y->size;
#endif
#endif
}
}
}
@ -614,7 +645,7 @@ static void* _realloc_merge (hawk_xma_t* xma, void* b, hawk_oow_t size)
void* hawk_xma_calloc (hawk_xma_t* xma, hawk_oow_t size)
{
void* ptr = hawk_xma_alloc(xma, size);
if (ptr) HAWK_MEMSET (ptr, 0, size);
if (HAWK_LIKELY(ptr)) HAWK_MEMSET(ptr, 0, size);
return ptr;
}
@ -630,9 +661,15 @@ void* hawk_xma_realloc (hawk_xma_t* xma, void* b, hawk_oow_t size)
else
{
/* try reallocation by merging the adjacent continuous blocks */
#if defined(HAWK_XMA_ENABLE_STAT)
xma->stat.nreallocops++;
#endif
n = _realloc_merge (xma, b, size);
if (!n)
{
#if defined(HAWK_XMA_ENABLE_STAT)
xma->stat.nreallocbadops++;
#endif
/* reallocation by merging failed. fall back to the slow
* allocation-copy-free scheme */
n = hawk_xma_alloc(xma, size);
@ -642,6 +679,12 @@ void* hawk_xma_realloc (hawk_xma_t* xma, void* b, hawk_oow_t size)
hawk_xma_free (xma, b);
}
}
else
{
#if defined(HAWK_XMA_ENABLE_STAT)
xma->stat.nreallocgoodops++;
#endif
}
}
return n;
@ -661,6 +704,7 @@ void hawk_xma_free (hawk_xma_t* xma, void* b)
/* update statistical variables */
xma->stat.nused--;
xma->stat.alloc -= org_blk_size;
xma->stat.nfreeops++;
#endif
x = prev_mblk(blk);
@ -800,9 +844,10 @@ void hawk_xma_dump (hawk_xma_t* xma, hawk_xma_dumper_t dumper, void* ctx)
#if defined(HAWK_XMA_ENABLE_STAT)
dumper (ctx, "== statistics ==\n");
dumper (ctx, "total = %zu\n", xma->stat.total);
dumper (ctx, "alloc = %zu\n", xma->stat.alloc);
dumper (ctx, "avail = %zu\n", xma->stat.avail);
dumper (ctx, "Total = %zu\n", xma->stat.total);
dumper (ctx, "Alloc = %zu\n", xma->stat.alloc);
dumper (ctx, "Avail = %zu\n", xma->stat.avail);
dumper (ctx, "Alloc High Watermark = %zu\n", xma->stat.alloc_hwmark);
#endif
dumper (ctx, "== blocks ==\n");
@ -819,13 +864,20 @@ void hawk_xma_dump (hawk_xma_t* xma, hawk_xma_dumper_t dumper, void* ctx)
#endif
dumper (ctx, "---------------------------------------\n");
dumper (ctx, "Allocated blocks: %18zu bytes\n", asum);
dumper (ctx, "Available blocks: %18zu bytes\n", fsum);
dumper (ctx, "Allocated blocks : %18zu bytes\n", asum);
dumper (ctx, "Available blocks : %18zu bytes\n", fsum);
#if defined(HAWK_XMA_ENABLE_STAT)
dumper (ctx, "Internal use : %18zu bytes\n", isum);
dumper (ctx, "Total : %18zu bytes\n", (asum + fsum + isum));
dumper (ctx, "Internal use : %18zu bytes\n", isum);
dumper (ctx, "Total : %18zu bytes\n", (asum + fsum + isum));
dumper (ctx, "Alloc operations : %18zu\n", xma->stat.nallocops);
dumper (ctx, "Good alloc operations : %18zu\n", xma->stat.nallocgoodops);
dumper (ctx, "Bad alloc operations : %18zu\n", xma->stat.nallocbadops);
dumper (ctx, "Realloc operations : %18zu\n", xma->stat.nreallocops);
dumper (ctx, "Good realloc operations: %18zu\n", xma->stat.nreallocgoodops);
dumper (ctx, "Bad realloc operations : %18zu\n", xma->stat.nreallocbadops);
dumper (ctx, "Free operations : %18zu\n", xma->stat.nfreeops);
#endif
#if defined(HAWK_XMA_ENABLE_STAT)

View File

@ -13,12 +13,15 @@ int main ()
{
hawk_json_t* json;
hawk_json_prim_t prim;
/* const hawk_ooch_t* TODO */
no_plan();
prim.instcb = on_json_element;
json = hawk_json_openstd(0, &prim, HAWK_NULL);
OK (json != HAWK_NULL, "instantiation must be successful");
/* hawk_json_feed(json, "{\"hello\": \"world\"}", & TODO */
hawk_json_close(json);
return exit_status();