From 72557c239bc7946060c3ba787473ea69e55149cf Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 1 Dec 2020 14:44:53 +0000 Subject: [PATCH] added hawk::modlibdirs() --- hawk/lib/hawk-prv.h | 25 +++++++++++++++++++++++++ hawk/lib/mod-hawk.c | 17 +++++++++++++++-- hawk/lib/parse.c | 21 --------------------- hawk/t/Makefile.in | 1 + hawk/t/bibtex-to-html.hawk | 2 +- hawk/t/bibtex-to-html.out | 1 - hawk/t/h-003.hawk | 2 +- hawk/t/journal-toc-html.out | 1 - hawk/t/journal-toc.hawk | 2 +- 9 files changed, 44 insertions(+), 28 deletions(-) diff --git a/hawk/lib/hawk-prv.h b/hawk/lib/hawk-prv.h index 5cc202a9..b1b9dd76 100644 --- a/hawk/lib/hawk-prv.h +++ b/hawk/lib/hawk-prv.h @@ -588,6 +588,31 @@ static HAWK_INLINE void HAWK_RTX_STACK_POP (hawk_rtx_t* rtx) #define HAWK_RTX_IS_STRIPRECSPC_ON(rtx) ((rtx)->gbl.striprecspc > 0 || ((rtx)->gbl.striprecspc < 0 && ((rtx)->hawk->parse.pragma.trait & HAWK_STRIPRECSPC))) #define HAWK_RTX_IS_STRIPSTRSPC_ON(rtx) ((rtx)->gbl.stripstrspc > 0 || ((rtx)->gbl.stripstrspc < 0 && ((rtx)->hawk->parse.pragma.trait & HAWK_STRIPSTRSPC))) + + + +#if !defined(HAWK_DEFAULT_MODLIBDIRS) +# define HAWK_DEFAULT_MODLIBDIRS "" +#endif + +#if !defined(HAWK_DEFAULT_MODPREFIX) +# if defined(_WIN32) +# define HAWK_DEFAULT_MODPREFIX "hawk-" +# elif defined(__OS2__) +# define HAWK_DEFAULT_MODPREFIX "hawk" +# elif defined(__DOS__) +# define HAWK_DEFAULT_MODPREFIX "hawk" +# else +# define HAWK_DEFAULT_MODPREFIX "libhawk-" +# endif +#endif + +#if !defined(HAWK_DEFAULT_MODPOSTFIX) +# define HAWK_DEFAULT_MODPOSTFIX "" +#endif + + + #if defined(__cplusplus) extern "C" { #endif diff --git a/hawk/lib/mod-hawk.c b/hawk/lib/mod-hawk.c index 9b8370d2..b2ad7e12 100644 --- a/hawk/lib/mod-hawk.c +++ b/hawk/lib/mod-hawk.c @@ -303,7 +303,7 @@ static int fnc_isnil (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) a0 = hawk_rtx_getarg(rtx, 0); r = hawk_rtx_makeintval(rtx, HAWK_RTX_GETVALTYPE(rtx, a0) == HAWK_VAL_NIL); - if (r == HAWK_NULL) return -1; + if (HAWK_UNLIKELY(!r)) return -1; hawk_rtx_setretval (rtx, r); return 0; @@ -337,6 +337,18 @@ static int fnc_isarr (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) return 0; } +static int fnc_modlibdirs (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) +{ + hawk_t* hawk = hawk_rtx_gethawk(rtx); + hawk_val_t* r; + + r = hawk_rtx_makestrvalwithoocstr(rtx, (hawk->opt.mod[0].len > 0)? hawk->opt.mod[0].ptr: HAWK_T(HAWK_DEFAULT_MODLIBDIRS)); + if (HAWK_UNLIKELY(!r)) return -1; + + hawk_rtx_setretval (rtx, r); + return 0; +} + static int fnc_typename (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) { hawk_val_t* a0; @@ -347,7 +359,7 @@ static int fnc_typename (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) name = hawk_rtx_getvaltypename(rtx, a0); r = hawk_rtx_makestrvalwithoocstr(rtx, name); - if (r == HAWK_NULL) return -1; + if (HAWK_UNLIKELY(!r)) return -1; hawk_rtx_setretval (rtx, r); return 0; @@ -385,6 +397,7 @@ static fnctab_t fnctab[] = { HAWK_T("ismap"), { { 1, 1, HAWK_NULL }, fnc_ismap, 0 } }, { HAWK_T("isnil"), { { 1, 1, HAWK_NULL }, fnc_isnil, 0 } }, { HAWK_T("map"), { { 0, A_MAX, HAWK_NULL }, fnc_map, 0 } }, + { HAWK_T("modlibdirs"), { { 0, 0, HAWK_NULL }, fnc_modlibdirs, 0 } }, { HAWK_T("typename"), { { 1, 1, HAWK_NULL }, fnc_typename, 0 } } }; diff --git a/hawk/lib/parse.c b/hawk/lib/parse.c index a0473864..be861ac8 100644 --- a/hawk/lib/parse.c +++ b/hawk/lib/parse.c @@ -26,27 +26,6 @@ #include "hawk-prv.h" -#if !defined(HAWK_DEFAULT_MODLIBDIRS) -# define HAWK_DEFAULT_MODLIBDIRS "" -#endif - -#if !defined(HAWK_DEFAULT_MODPREFIX) -# if defined(_WIN32) -# define HAWK_DEFAULT_MODPREFIX "hawk-" -# elif defined(__OS2__) -# define HAWK_DEFAULT_MODPREFIX "hawk" -# elif defined(__DOS__) -# define HAWK_DEFAULT_MODPREFIX "hawk" -# else -# define HAWK_DEFAULT_MODPREFIX "libhawk-" -# endif -#endif - -#if !defined(HAWK_DEFAULT_MODPOSTFIX) -# define HAWK_DEFAULT_MODPOSTFIX "" -#endif - - #define FMT_EBADVAR HAWK_T("'%.*js' not a valid variable name") #define FMT_ECOMMA HAWK_T("comma expected in place of '%.*js'") #define FMT_ECOLON HAWK_T("colon expected in place of '%.*js'") diff --git a/hawk/t/Makefile.in b/hawk/t/Makefile.in index 256a9651..67aec334 100644 --- a/hawk/t/Makefile.in +++ b/hawk/t/Makefile.in @@ -558,6 +558,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ diff --git a/hawk/t/bibtex-to-html.hawk b/hawk/t/bibtex-to-html.hawk index 267f9f63..5401fab6 100644 --- a/hawk/t/bibtex-to-html.hawk +++ b/hawk/t/bibtex-to-html.hawk @@ -334,7 +334,7 @@ function begin_file( f) ## print " BibTeX bibliography " FILENAME > f print " BibTeX bibliography " BASE_FILENAME > f print " " > f - print " " > f +## print " " > f print " " > f print " " > f print "" > f diff --git a/hawk/t/bibtex-to-html.out b/hawk/t/bibtex-to-html.out index fcbbb30f..ca49334a 100644 --- a/hawk/t/bibtex-to-html.out +++ b/hawk/t/bibtex-to-html.out @@ -13,7 +13,6 @@ BibTeX bibliography journal-toc.in - diff --git a/hawk/t/h-003.hawk b/hawk/t/h-003.hawk index c9881731..fd5b5176 100644 --- a/hawk/t/h-003.hawk +++ b/hawk/t/h-003.hawk @@ -51,7 +51,7 @@ function run_test (x, more_opts, in_name, out_name) outf = sprintf("/tmp/%s.%d.out", out_name, sys::getpid()); ##print TDIR, inf, expf, outf; - cmd=sprintf("%s %s -f %s/%s.hawk %s > %s", ARGV[0], more_opts, TDIR, x, inf, outf); + cmd=sprintf("%s %s -f %s/%s.hawk --modlibdirs=%s %s > %s", ARGV[0], more_opts, TDIR, x, hawk::modlibdirs(), inf, outf); ##print cmd; system (cmd); diff --git a/hawk/t/journal-toc-html.out b/hawk/t/journal-toc-html.out index 9947ee08..4448671e 100644 --- a/hawk/t/journal-toc-html.out +++ b/hawk/t/journal-toc-html.out @@ -9,7 +9,6 @@ ACM Transactions on Mathematical Software - diff --git a/hawk/t/journal-toc.hawk b/hawk/t/journal-toc.hawk index 2df9547c..20fd33eb 100644 --- a/hawk/t/journal-toc.hawk +++ b/hawk/t/journal-toc.hawk @@ -663,7 +663,7 @@ function html_header() print prefix(2) "" print prefix(3) Journal print prefix(2) "" - print prefix(2) "" + ##print prefix(2) "" print prefix(1) "" print "" print prefix(1) ""