added HAWK_OPT_MODLIBDIRS to specify search path for module files

This commit is contained in:
hyung-hwan 2020-04-15 15:12:28 +00:00
parent a36dbd9c2f
commit 5f4635d455
11 changed files with 149 additions and 103 deletions

View File

@ -107,6 +107,8 @@ struct arg_t
hawk_bch_t* call; /* function to call */ hawk_bch_t* call; /* function to call */
hawk_cmgr_t* script_cmgr; hawk_cmgr_t* script_cmgr;
hawk_cmgr_t* console_cmgr; hawk_cmgr_t* console_cmgr;
hawk_bch_t* includedirs;
hawk_bch_t* modlibdirs;
unsigned int modern: 1; unsigned int modern: 1;
unsigned int classic: 1; unsigned int classic: 1;
@ -345,7 +347,7 @@ static hawk_htb_walk_t print_awk_value (hawk_htb_t* map, hawk_htb_pair_t* pair,
return HAWK_HTB_WALK_FORWARD; return HAWK_HTB_WALK_FORWARD;
} }
static int add_gvs_to_awk (hawk_t* hawk, arg_t* arg) static int add_gvs_to_hawk (hawk_t* hawk, arg_t* arg)
{ {
if (arg->gvm.size > 0) if (arg->gvm.size > 0)
{ {
@ -539,6 +541,9 @@ static void print_usage (FILE* out, const hawk_bch_t* argv0)
fprintf (out, " --script-encoding string specify script file encoding name\n"); fprintf (out, " --script-encoding string specify script file encoding name\n");
fprintf (out, " --console-encoding string specify console encoding name\n"); fprintf (out, " --console-encoding string specify console encoding name\n");
#endif #endif
fprintf (out, " --includedirs specify directories to look for module files in\n");
fprintf (out, " --modlibdirs specify directories to look for include files in\n");
fprintf (out, " --modern run in the modern mode(default)\n"); fprintf (out, " --modern run in the modern mode(default)\n");
fprintf (out, " --classic run in the classic mode\n"); fprintf (out, " --classic run in the classic mode\n");
@ -659,6 +664,10 @@ static int process_argv (int argc, hawk_bch_t* argv[], struct arg_t* arg)
{ ":script-encoding", '\0' }, { ":script-encoding", '\0' },
{ ":console-encoding", '\0' }, { ":console-encoding", '\0' },
#if 0
{ ":includedirs", '\0' },
#endif
{ ":modlibdirs", '\0' },
{ "modern", '\0' }, { "modern", '\0' },
{ "classic", '\0' }, { "classic", '\0' },
@ -863,6 +872,16 @@ static int process_argv (int argc, hawk_bch_t* argv[], struct arg_t* arg)
{ {
arg->classic = 1; arg->classic = 1;
} }
#if 0
else if (hawk_comp_bcstr(opt.lngopt, "includedirs", 0) == 0)
{
arg->includedirs = opt.arg;
}
#endif
else if (hawk_comp_bcstr(opt.lngopt, "modlibdirs", 0) == 0)
{
arg->modlibdirs = opt.arg;
}
else else
{ {
for (i = 0; opttab[i].name; i++) for (i = 0; opttab[i].name; i++)
@ -1083,7 +1102,7 @@ static hawk_mmgr_t debug_mmgr =
static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[]) static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[])
{ {
hawk_t* awk = HAWK_NULL; hawk_t* hawk = HAWK_NULL;
hawk_rtx_t* rtx = HAWK_NULL; hawk_rtx_t* rtx = HAWK_NULL;
hawk_val_t* retv; hawk_val_t* retv;
int i; int i;
@ -1142,60 +1161,98 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[])
} }
#endif #endif
awk = hawk_openstd(0, HAWK_NULL); hawk = hawk_openstd(0, HAWK_NULL);
if (awk == HAWK_NULL) if (HAWK_UNLIKELY(!hawk))
{ {
print_error ("cannot open awk\n"); print_error ("cannot open hawk\n");
goto oops; goto oops;
} }
if (arg.modern) i = HAWK_MODERN; if (arg.modern) i = HAWK_MODERN;
else if (arg.classic) i = HAWK_CLASSIC; else if (arg.classic) i = HAWK_CLASSIC;
else hawk_getopt (awk, HAWK_OPT_TRAIT, &i); else hawk_getopt (hawk, HAWK_OPT_TRAIT, &i);
if (arg.opton) i |= arg.opton; if (arg.opton) i |= arg.opton;
if (arg.optoff) i &= ~arg.optoff; if (arg.optoff) i &= ~arg.optoff;
hawk_setopt (awk, HAWK_OPT_TRAIT, &i); hawk_setopt (hawk, HAWK_OPT_TRAIT, &i);
/* TODO: get depth from command line */ /* TODO: get depth from command line */
{ {
hawk_oow_t tmp; hawk_oow_t tmp;
tmp = 50; tmp = 50;
hawk_setopt (awk, HAWK_OPT_DEPTH_BLOCK_PARSE, &tmp); hawk_setopt (hawk, HAWK_OPT_DEPTH_BLOCK_PARSE, &tmp);
hawk_setopt (awk, HAWK_OPT_DEPTH_EXPR_PARSE, &tmp); hawk_setopt (hawk, HAWK_OPT_DEPTH_EXPR_PARSE, &tmp);
tmp = 500; tmp = 500;
hawk_setopt (awk, HAWK_OPT_DEPTH_BLOCK_RUN, &tmp); hawk_setopt (hawk, HAWK_OPT_DEPTH_BLOCK_RUN, &tmp);
hawk_setopt (awk, HAWK_OPT_DEPTH_EXPR_RUN, &tmp); hawk_setopt (hawk, HAWK_OPT_DEPTH_EXPR_RUN, &tmp);
tmp = 64; tmp = 64;
hawk_setopt (awk, HAWK_OPT_DEPTH_INCLUDE, &tmp); hawk_setopt (hawk, HAWK_OPT_DEPTH_INCLUDE, &tmp);
} }
if (add_gvs_to_awk(awk, &arg) <= -1) #if 0
if (arg.includedirs)
{ {
print_hawk_error (awk); #if defined(HAWK_OOCH_IS_UCH)
hawk_ooch_t* tmp;
tmp = hawk_dupbtoucstr(hawk, arg.includedirs, HAWK_NULL, 1);
if (HAWK_UNLIKELY(!tmp))
{
print_hawk_error (hawk);
goto oops; goto oops;
} }
if (hawk_parsestd(awk, arg.psin, ((arg.osf == HAWK_NULL)? HAWK_NULL: &psout)) <= -1) hawk_setopt (hawk, HAWK_OPT_INCLUDEDIRS, tmp);
hawk_freemem (hawk, tmp);
#else
hawk_setopt (hawk, HAWK_OPT_INCLUDEDIRS, arg.includedirs);
#endif
}
#endif
if (arg.modlibdirs)
{ {
print_hawk_error (awk); #if defined(HAWK_OOCH_IS_UCH)
hawk_ooch_t* tmp;
tmp = hawk_dupbtoucstr(hawk, arg.modlibdirs, HAWK_NULL, 1);
if (HAWK_UNLIKELY(!tmp))
{
print_hawk_error (hawk);
goto oops;
}
hawk_setopt (hawk, HAWK_OPT_MODLIBDIRS, tmp);
hawk_freemem (hawk, tmp);
#else
hawk_setopt (hawk, HAWK_OPT_MODLIBDIRS, arg.modlibdirs);
#endif
}
if (add_gvs_to_hawk(hawk, &arg) <= -1)
{
print_hawk_error (hawk);
goto oops;
}
if (hawk_parsestd(hawk, arg.psin, ((arg.osf == HAWK_NULL)? HAWK_NULL: &psout)) <= -1)
{
print_hawk_error (hawk);
goto oops; goto oops;
} }
rtx = hawk_rtx_openstdwithbcstr( rtx = hawk_rtx_openstdwithbcstr(
awk, 0, argv[0], hawk, 0, argv[0],
(arg.call? HAWK_NULL: arg.icf.ptr), /* console input */ (arg.call? HAWK_NULL: arg.icf.ptr), /* console input */
arg.ocf.ptr, /* console output */ arg.ocf.ptr, /* console output */
arg.console_cmgr arg.console_cmgr
); );
if (rtx == HAWK_NULL) if (HAWK_UNLIKELY(!rtx))
{ {
print_hawk_error (awk); print_hawk_error (hawk);
goto oops; goto oops;
} }
if (apply_fs_and_gvs_to_rtx(rtx, &arg) <= -1) if (apply_fs_and_gvs_to_rtx(rtx, &arg) <= -1)
{ {
print_hawk_error (awk); print_hawk_error (hawk);
goto oops; goto oops;
} }
@ -1241,7 +1298,7 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[])
oops: oops:
if (rtx) hawk_rtx_close (rtx); if (rtx) hawk_rtx_close (rtx);
if (awk) hawk_close (awk); if (hawk) hawk_close (hawk);
#if 0 #if 0
if (xma_mmgr.ctx) hawk_xma_close (xma_mmgr.ctx); if (xma_mmgr.ctx) hawk_xma_close (xma_mmgr.ctx);

View File

@ -150,9 +150,11 @@ int HawkStd::open ()
if (!this->stdmod_up) if (!this->stdmod_up)
{ {
/*
#if defined(USE_DLFCN) #if defined(USE_DLFCN)
if (hawk_setopt(this->hawk, HAWK_OPT_MODPOSTFIX, HAWK_T(".so")) <= -1) goto oops; if (hawk_setopt(this->hawk, HAWK_OPT_MODPOSTFIX, HAWK_T(".so")) <= -1) goto oops;
#endif #endif
*/
if (hawk_stdmodstartup(this->hawk) <= -1) goto oops; if (hawk_stdmodstartup(this->hawk) <= -1) goto oops;
this->stdmod_up = true; this->stdmod_up = true;

View File

@ -18,9 +18,9 @@ endif
if WIN32 if WIN32
# you must adjust the value of DEFAULT_MODPOSTFIX according # you must adjust the value of DEFAULT_MODPOSTFIX according
# to the first number in -version-info above # to the first number in -version-info above
CPPFLAGS_PFMOD = -DHAWK_DEFAULT_MODPREFIX=\"libhawk-\" -DHAWK_DEFAULT_MODPOSTFIX=\"-1.dll\" CPPFLAGS_PFMOD = -DHAWK_DEFAULT_MODLIBDIRS=\"\" -DHAWK_DEFAULT_MODPREFIX=\"libhawk-\" -DHAWK_DEFAULT_MODPOSTFIX=\"-1.dll\"
else else
CPPFLAGS_PFMOD = -DHAWK_DEFAULT_MODPREFIX=\"$(libdir)/libhawk-\" CPPFLAGS_PFMOD = -DHAWK_DEFAULT_MODLIBDIRS=\"$(libdir)\" -DHAWK_DEFAULT_MODPREFIX=\"libhawk-\"
if MACOSX if MACOSX
CPPFLAGS_PFMOD += -DHAWK_DEFAULT_MODPOSTFIX=\".dylib\" CPPFLAGS_PFMOD += -DHAWK_DEFAULT_MODPOSTFIX=\".dylib\"
else else

View File

@ -571,8 +571,8 @@ CPPFLAGS_ALL_COMMON = \
@ENABLE_STATIC_MODULE_FALSE@LDFLAGS_ALL_COMMON = -L$(abs_builddir) -L$(libdir) @ENABLE_STATIC_MODULE_FALSE@LDFLAGS_ALL_COMMON = -L$(abs_builddir) -L$(libdir)
@ENABLE_STATIC_MODULE_TRUE@LDFLAGS_ALL_COMMON = -L$(abs_builddir)/../mod -L$(abs_builddir) -L$(libdir) @ENABLE_STATIC_MODULE_TRUE@LDFLAGS_ALL_COMMON = -L$(abs_builddir)/../mod -L$(abs_builddir) -L$(libdir)
@WIN32_FALSE@CPPFLAGS_PFMOD = \ @WIN32_FALSE@CPPFLAGS_PFMOD = -DHAWK_DEFAULT_MODLIBDIRS=\"$(libdir)\" \
@WIN32_FALSE@ -DHAWK_DEFAULT_MODPREFIX=\"$(libdir)/libhawk-\" \ @WIN32_FALSE@ -DHAWK_DEFAULT_MODPREFIX=\"libhawk-\" \
@WIN32_FALSE@ $(am__append_1) $(am__append_2) @WIN32_FALSE@ $(am__append_1) $(am__append_2)
################################################## ##################################################
@ -581,7 +581,8 @@ CPPFLAGS_ALL_COMMON = \
# you must adjust the value of DEFAULT_MODPOSTFIX according # you must adjust the value of DEFAULT_MODPOSTFIX according
# to the first number in -version-info above # to the first number in -version-info above
@WIN32_TRUE@CPPFLAGS_PFMOD = -DHAWK_DEFAULT_MODPREFIX=\"libhawk-\" \ @WIN32_TRUE@CPPFLAGS_PFMOD = -DHAWK_DEFAULT_MODLIBDIRS=\"\" \
@WIN32_TRUE@ -DHAWK_DEFAULT_MODPREFIX=\"libhawk-\" \
@WIN32_TRUE@ -DHAWK_DEFAULT_MODPOSTFIX=\"-1.dll\" \ @WIN32_TRUE@ -DHAWK_DEFAULT_MODPOSTFIX=\"-1.dll\" \
@WIN32_TRUE@ $(am__append_1) $(am__append_2) @WIN32_TRUE@ $(am__append_1) $(am__append_2)
pkginclude_HEADERS = hawk.h hawk-arr.h hawk-chr.h hawk-cmn.h \ pkginclude_HEADERS = hawk.h hawk-arr.h hawk-chr.h hawk-cmn.h \

View File

@ -210,7 +210,7 @@ struct hawk_t
{ {
int trait; int trait;
hawk_oocs_t mod[3]; hawk_oocs_t mod[3];
hawk_oocs_t incldirs; hawk_oocs_t includedirs;
union union
{ {

View File

@ -175,7 +175,7 @@ int hawk_init (hawk_t* awk, hawk_mmgr_t* mmgr, hawk_cmgr_t* cmgr, const hawk_prm
init_token(awk, &awk->ntok) <= -1) goto oops; init_token(awk, &awk->ntok) <= -1) goto oops;
awk->opt.trait = HAWK_MODERN; awk->opt.trait = HAWK_MODERN;
#if defined(__OS2__) || defined(_WIN32) || defined(__DOS__) #if defined(__WIN32__) || defined(_OS2) || defined(__DOS__)
awk->opt.trait |= HAWK_CRLF; awk->opt.trait |= HAWK_CRLF;
#endif #endif
awk->opt.rtx_stack_limit = HAWK_DFL_RTX_STACK_LIMIT; awk->opt.rtx_stack_limit = HAWK_DFL_RTX_STACK_LIMIT;
@ -427,22 +427,22 @@ void hawk_clear (hawk_t* awk)
*/ */
} }
void hawk_getprm (hawk_t* awk, hawk_prm_t* prm) void hawk_getprm (hawk_t* hawk, hawk_prm_t* prm)
{ {
*prm = awk->prm; *prm = hawk->prm;
} }
void hawk_setprm (hawk_t* awk, const hawk_prm_t* prm) void hawk_setprm (hawk_t* hawk, const hawk_prm_t* prm)
{ {
awk->prm = *prm; hawk->prm = *prm;
} }
static int dup_str_opt (hawk_t* awk, const void* value, hawk_oocs_t* tmp) static int dup_str_opt (hawk_t* hawk, const void* value, hawk_oocs_t* tmp)
{ {
if (value) if (value)
{ {
tmp->ptr = hawk_dupoocstr(awk, value, &tmp->len); tmp->ptr = hawk_dupoocstr(hawk, value, &tmp->len);
if (!tmp->ptr) return -1; if (HAWK_UNLIKELY(!tmp->ptr)) return -1;
} }
else else
{ {
@ -461,7 +461,7 @@ int hawk_setopt (hawk_t* hawk, hawk_opt_t id, const void* value)
hawk->opt.trait = *(const int*)value; hawk->opt.trait = *(const int*)value;
return 0; return 0;
case HAWK_OPT_MODLIBDIR: case HAWK_OPT_MODLIBDIRS:
case HAWK_OPT_MODPREFIX: case HAWK_OPT_MODPREFIX:
case HAWK_OPT_MODPOSTFIX: case HAWK_OPT_MODPOSTFIX:
{ {
@ -470,7 +470,7 @@ int hawk_setopt (hawk_t* hawk, hawk_opt_t id, const void* value)
if (dup_str_opt(hawk, value, &tmp) <= -1) return -1; if (dup_str_opt(hawk, value, &tmp) <= -1) return -1;
idx = id - HAWK_OPT_MODLIBDIR; idx = id - HAWK_OPT_MODLIBDIRS;
if (hawk->opt.mod[idx].ptr) hawk_freemem (hawk, hawk->opt.mod[idx].ptr); if (hawk->opt.mod[idx].ptr) hawk_freemem (hawk, hawk->opt.mod[idx].ptr);
hawk->opt.mod[idx] = tmp; hawk->opt.mod[idx] = tmp;
@ -481,8 +481,8 @@ int hawk_setopt (hawk_t* hawk, hawk_opt_t id, const void* value)
{ {
hawk_oocs_t tmp; hawk_oocs_t tmp;
if (dup_str_opt(hawk, value, &tmp) <= -1) return -1; if (dup_str_opt(hawk, value, &tmp) <= -1) return -1;
if (hawk->opt.incldirs.ptr) hawk_freemem (hawk, hawk->opt.incldirs.ptr); if (hawk->opt.includedirs.ptr) hawk_freemem (hawk, hawk->opt.includedirs.ptr);
hawk->opt.incldirs = tmp; hawk->opt.includedirs = tmp;
return 0; return 0;
} }
@ -525,14 +525,14 @@ int hawk_getopt (hawk_t* hawk, hawk_opt_t id, void* value)
*(int*)value = hawk->opt.trait; *(int*)value = hawk->opt.trait;
return 0; return 0;
case HAWK_OPT_MODLIBDIR: case HAWK_OPT_MODLIBDIRS:
case HAWK_OPT_MODPREFIX: case HAWK_OPT_MODPREFIX:
case HAWK_OPT_MODPOSTFIX: case HAWK_OPT_MODPOSTFIX:
*(const hawk_ooch_t**)value = hawk->opt.mod[id - HAWK_OPT_MODLIBDIR].ptr; *(const hawk_ooch_t**)value = hawk->opt.mod[id - HAWK_OPT_MODLIBDIRS].ptr;
return 0; return 0;
case HAWK_OPT_INCLUDEDIRS: case HAWK_OPT_INCLUDEDIRS:
*(const hawk_ooch_t**)value = hawk->opt.incldirs.ptr; *(const hawk_ooch_t**)value = hawk->opt.includedirs.ptr;
return 0; return 0;
case HAWK_OPT_DEPTH_INCLUDE: case HAWK_OPT_DEPTH_INCLUDE:

View File

@ -1144,7 +1144,7 @@ enum hawk_opt_t
/** trait option. 0 or bitwise-ORed of ::hawk_trait_t values */ /** trait option. 0 or bitwise-ORed of ::hawk_trait_t values */
HAWK_OPT_TRAIT, HAWK_OPT_TRAIT,
HAWK_OPT_MODLIBDIR, HAWK_OPT_MODLIBDIRS,
HAWK_OPT_MODPREFIX, HAWK_OPT_MODPREFIX,
HAWK_OPT_MODPOSTFIX, HAWK_OPT_MODPOSTFIX,

View File

@ -26,8 +26,8 @@
#include "hawk-prv.h" #include "hawk-prv.h"
#if !defined(HAWK_DEFAULT_MODLIBDIR) #if !defined(HAWK_DEFAULT_MODLIBDIRS)
# define HAWK_DEFAULT_MODLIBDIR "" # define HAWK_DEFAULT_MODLIBDIRS ""
#endif #endif
#if !defined(HAWK_DEFAULT_MODPREFIX) #if !defined(HAWK_DEFAULT_MODPREFIX)
@ -836,7 +836,7 @@ static int begin_include (hawk_t* awk, int once)
return -1; return -1;
} }
if (awk->opt.incldirs.ptr) if (awk->opt.includedirs.ptr)
{ {
/* include directory is set... */ /* include directory is set... */
/* TODO: search target files in these directories */ /* TODO: search target files in these directories */
@ -890,7 +890,6 @@ static int begin_include (hawk_t* awk, int once)
if (get_token(awk) <= -1) return -1; /* skip the include file name */ if (get_token(awk) <= -1) return -1; /* skip the include file name */
if (MATCH(awk, TOK_SEMICOLON) || MATCH(awk, TOK_NEWLINE)) if (MATCH(awk, TOK_SEMICOLON) || MATCH(awk, TOK_NEWLINE))
{ {
if (get_token(awk) <= -1) return -1; /* skip the semicolon */ if (get_token(awk) <= -1) return -1; /* skip the semicolon */
} }
} }
@ -3703,8 +3702,7 @@ static int fold_constants_for_binop (
/* TODO: can i shorten various comparisons below? /* TODO: can i shorten various comparisons below?
* i hate to repeat similar code just for type difference */ * i hate to repeat similar code just for type difference */
if (left->type == HAWK_NDE_INT && if (left->type == HAWK_NDE_INT && right->type == HAWK_NDE_INT)
right->type == HAWK_NDE_INT)
{ {
fold = HAWK_NDE_INT; fold = HAWK_NDE_INT;
switch (opcode) switch (opcode)
@ -3760,8 +3758,7 @@ static int fold_constants_for_binop (
break; break;
} }
} }
else if (left->type == HAWK_NDE_FLT && else if (left->type == HAWK_NDE_FLT && right->type == HAWK_NDE_FLT)
right->type == HAWK_NDE_FLT)
{ {
fold = HAWK_NDE_FLT; fold = HAWK_NDE_FLT;
switch (opcode) switch (opcode)
@ -3800,8 +3797,7 @@ static int fold_constants_for_binop (
break; break;
} }
} }
else if (left->type == HAWK_NDE_INT && else if (left->type == HAWK_NDE_INT && right->type == HAWK_NDE_FLT)
right->type == HAWK_NDE_FLT)
{ {
fold = HAWK_NDE_FLT; fold = HAWK_NDE_FLT;
switch (opcode) switch (opcode)
@ -3842,8 +3838,7 @@ static int fold_constants_for_binop (
break; break;
} }
} }
else if (left->type == HAWK_NDE_FLT && else if (left->type == HAWK_NDE_FLT && right->type == HAWK_NDE_INT)
right->type == HAWK_NDE_INT)
{ {
fold = HAWK_NDE_FLT; fold = HAWK_NDE_FLT;
switch (opcode) switch (opcode)
@ -3908,59 +3903,55 @@ static hawk_nde_t* new_exp_bin_node (
return (hawk_nde_t*)tmp; return (hawk_nde_t*)tmp;
} }
static hawk_nde_t* new_int_node ( static hawk_nde_t* new_int_node (hawk_t* hawk, hawk_int_t lv, const hawk_loc_t* loc)
hawk_t* awk, hawk_int_t lv, const hawk_loc_t* loc)
{ {
hawk_nde_int_t* tmp; hawk_nde_int_t* tmp;
tmp = (hawk_nde_int_t*) hawk_callocmem (awk, HAWK_SIZEOF(*tmp)); tmp = (hawk_nde_int_t*)hawk_callocmem(hawk, HAWK_SIZEOF(*tmp));
if (tmp) if (HAWK_LIKELY(tmp))
{ {
tmp->type = HAWK_NDE_INT; tmp->type = HAWK_NDE_INT;
tmp->loc = *loc; tmp->loc = *loc;
tmp->val = lv; tmp->val = lv;
} }
else ADJERR_LOC (awk, loc); else ADJERR_LOC (hawk, loc);
return (hawk_nde_t*)tmp; return (hawk_nde_t*)tmp;
} }
static hawk_nde_t* new_flt_node ( static hawk_nde_t* new_flt_node (hawk_t* hawk, hawk_flt_t rv, const hawk_loc_t* loc)
hawk_t* awk, hawk_flt_t rv, const hawk_loc_t* loc)
{ {
hawk_nde_flt_t* tmp; hawk_nde_flt_t* tmp;
tmp = (hawk_nde_flt_t*) hawk_callocmem (awk, HAWK_SIZEOF(*tmp)); tmp = (hawk_nde_flt_t*)hawk_callocmem(hawk, HAWK_SIZEOF(*tmp));
if (tmp) if (HAWK_LIKELY(tmp))
{ {
tmp->type = HAWK_NDE_FLT; tmp->type = HAWK_NDE_FLT;
tmp->loc = *loc; tmp->loc = *loc;
tmp->val = rv; tmp->val = rv;
} }
else ADJERR_LOC (awk, loc); else ADJERR_LOC (hawk, loc);
return (hawk_nde_t*)tmp; return (hawk_nde_t*)tmp;
} }
static HAWK_INLINE void update_int_node ( static HAWK_INLINE void update_int_node (hawk_t* hawk, hawk_nde_int_t* node, hawk_int_t lv)
hawk_t* awk, hawk_nde_int_t* node, hawk_int_t lv)
{ {
node->val = lv; node->val = lv;
if (node->str) if (node->str)
{ {
hawk_freemem (awk, node->str); hawk_freemem (hawk, node->str);
node->str = HAWK_NULL; node->str = HAWK_NULL;
node->len = 0; node->len = 0;
} }
} }
static HAWK_INLINE void update_flt_node ( static HAWK_INLINE void update_flt_node (hawk_t* hawk, hawk_nde_flt_t* node, hawk_flt_t rv)
hawk_t* awk, hawk_nde_flt_t* node, hawk_flt_t rv)
{ {
node->val = rv; node->val = rv;
if (node->str) if (node->str)
{ {
hawk_freemem (awk, node->str); hawk_freemem (hawk, node->str);
node->str = HAWK_NULL; node->str = HAWK_NULL;
node->len = 0; node->len = 0;
} }
@ -3976,7 +3967,7 @@ static hawk_nde_t* parse_binary (
hawk_loc_t rloc; hawk_loc_t rloc;
left = next_level_func(awk, xloc); left = next_level_func(awk, xloc);
if (left == HAWK_NULL) goto oops; if (HAWK_UNLIKELY(!left)) goto oops;
do do
{ {
@ -7340,43 +7331,36 @@ static hawk_mod_t* query_module (hawk_t* awk, const hawk_oocs_t segs[], int nseg
goto done; goto done;
} }
#endif #endif
/* attempt to find an external module */
HAWK_MEMSET (&spec, 0, HAWK_SIZEOF(spec));
spec.prefix = (awk->opt.mod[1].len > 0)? awk->opt.mod[1].ptr: HAWK_T(HAWK_DEFAULT_MODPREFIX);
spec.postfix = (awk->opt.mod[2].len > 0)? awk->opt.mod[2].ptr: HAWK_T(HAWK_DEFAULT_MODPOSTFIX);
spec.name = segs[0].ptr;
if (!awk->prm.modopen || !awk->prm.modgetsym || !awk->prm.modclose) if (!awk->prm.modopen || !awk->prm.modgetsym || !awk->prm.modclose)
{ {
hawk_seterrfmt (awk, HAWK_NULL, HAWK_EINVAL, HAWK_T("module callbacks not set properly")); hawk_seterrfmt (awk, HAWK_NULL, HAWK_EINVAL, HAWK_T("module callbacks not set properly"));
goto open_fail; goto open_fail;
} }
hawk_seterrnum (awk, HAWK_NULL, HAWK_ENOERR); spec.libdir = (awk->opt.mod[0].len > 0)? awk->opt.mod[0].ptr: HAWK_T(HAWK_DEFAULT_MODLIBDIRS);
/* attempt to find an external module */
HAWK_MEMSET (&spec, 0, HAWK_SIZEOF(spec));
if (awk->opt.mod[0].len > 0)
spec.libdir = awk->opt.mod[0].ptr;
else
spec.libdir = HAWK_T(HAWK_DEFAULT_MODLIBDIR);
if (awk->opt.mod[1].len > 0)
spec.prefix = awk->opt.mod[1].ptr;
else spec.prefix = HAWK_T(HAWK_DEFAULT_MODPREFIX);
if (awk->opt.mod[2].len > 0)
spec.postfix = awk->opt.mod[2].ptr;
else spec.postfix = HAWK_T(HAWK_DEFAULT_MODPOSTFIX);
HAWK_MEMSET (&md, 0, HAWK_SIZEOF(md));
spec.name = segs[0].ptr;
do do
{ {
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
# define LIBDIR_SEPARATOR ';'
#else
# define LIBDIR_SEPARATOR ':'
#endif
hawk_ooch_t* colon; hawk_ooch_t* colon;
colon = hawk_find_oochar_in_oocstr(spec.libdir, LIBDIR_SEPARATOR);
colon = hawk_find_oochar_in_oocstr(spec.libdir, ':');
if (colon) *colon = '\0'; if (colon) *colon = '\0';
HAWK_MEMSET (&md, 0, HAWK_SIZEOF(md));
md.handle = awk->prm.modopen(awk, &spec); md.handle = awk->prm.modopen(awk, &spec);
if (!colon) break; if (!colon) break;
*colon = ':'; *colon = LIBDIR_SEPARATOR;
spec.libdir = colon + 1;
#undef LIBDIR_SEPARATOR
} }
while (!md.handle); while (!md.handle);

View File

@ -914,6 +914,7 @@ hawk_t* hawk_openstdwithmmgr (hawk_mmgr_t* mmgr, hawk_oow_t xtnsize, hawk_cmgr_t
/* adjust the object size by the sizeof xtn_t so that hawk_getxtn() returns the right pointer. */ /* adjust the object size by the sizeof xtn_t so that hawk_getxtn() returns the right pointer. */
awk->_instsize += HAWK_SIZEOF(xtn_t); awk->_instsize += HAWK_SIZEOF(xtn_t);
/*
#if defined(USE_DLFCN) #if defined(USE_DLFCN)
if (hawk_setopt(awk, HAWK_OPT_MODPOSTFIX, HAWK_T(".so")) <= -1) if (hawk_setopt(awk, HAWK_OPT_MODPOSTFIX, HAWK_T(".so")) <= -1)
{ {
@ -921,6 +922,7 @@ hawk_t* hawk_openstdwithmmgr (hawk_mmgr_t* mmgr, hawk_oow_t xtnsize, hawk_cmgr_t
goto oops; goto oops;
} }
#endif #endif
*/
/* initialize extension */ /* initialize extension */
xtn = GET_XTN(awk); xtn = GET_XTN(awk);

View File

@ -42,4 +42,4 @@ TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
TEST_EXTENSIONS = .hawk TEST_EXTENSIONS = .hawk
HAWK_LOG_COMPILER = ../bin/hawk HAWK_LOG_COMPILER = ../bin/hawk
AM_HAWK_LOG_FLAGS = -f AM_HAWK_LOG_FLAGS = --modlibdirs=../lib/.libs:../mod/.libs -f

View File

@ -576,7 +576,7 @@ t_005_DEPENDENCIES = ../lib/libhawk.la
TESTS = $(check_PROGRAMS) $(check_SCRIPTS) TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
TEST_EXTENSIONS = .hawk TEST_EXTENSIONS = .hawk
HAWK_LOG_COMPILER = ../bin/hawk HAWK_LOG_COMPILER = ../bin/hawk
AM_HAWK_LOG_FLAGS = -f AM_HAWK_LOG_FLAGS = --modlibdirs=../lib/.libs:../mod/.libs -f
all: all-am all: all-am
.SUFFIXES: .SUFFIXES: