implemented binary symbol search in awk modules

This commit is contained in:
hyung-hwan 2012-11-05 09:49:54 +00:00
parent 2179278c41
commit dfc5fdfdea
6 changed files with 67 additions and 35 deletions

2
qse/configure vendored
View File

@ -16991,7 +16991,7 @@ _ACEOF
LIBS="-lltdl $LIBS" LIBS="-lltdl $LIBS"
else else
as_fn_error $? "installed libltdl is too old" "$LINENO" 5 as_fn_error $? "installed libltdl is too old. install a newer libltdl or specify --with-included-ltdl" "$LINENO" 5
fi fi
LDFLAGS="$save_LDFLAGS" LDFLAGS="$save_LDFLAGS"

View File

@ -55,7 +55,7 @@ if test "x$with_included_ltdl" != "xyes"; then
CFLAGS="$CFLAGS $LTDLINCL" CFLAGS="$CFLAGS $LTDLINCL"
LDFLAGS="$LDFLAGS $LIBLTDL" LDFLAGS="$LDFLAGS $LIBLTDL"
AC_CHECK_LIB([ltdl], [lt_dladvise_init], [], AC_CHECK_LIB([ltdl], [lt_dladvise_init], [],
[AC_MSG_ERROR([installed libltdl is too old])]) [AC_MSG_ERROR([installed libltdl is too old. install a newer libltdl or specify --with-included-ltdl])])
LDFLAGS="$save_LDFLAGS" LDFLAGS="$save_LDFLAGS"
CFLAGS="$save_CFLAGS" CFLAGS="$save_CFLAGS"
fi fi

View File

@ -2500,13 +2500,11 @@ static int add_globals (qse_awk_t* awk)
xtn->gbl_argc = add_global (awk, QSE_T("ARGC"), 4); xtn->gbl_argc = add_global (awk, QSE_T("ARGC"), 4);
xtn->gbl_argv = add_global (awk, QSE_T("ARGV"), 4); xtn->gbl_argv = add_global (awk, QSE_T("ARGV"), 4);
if (xtn->gbl_argc <= -1 || xtn->gbl_argv <= -1) return -1;
xtn->gbl_environ = add_global (awk, QSE_T("ENVIRON"), 7); xtn->gbl_environ = add_global (awk, QSE_T("ENVIRON"), 7);
if (xtn->gbl_environ <= -1) return -1;
return 0; return (xtn->gbl_argc <= -1 ||
xtn->gbl_argv <= -1 ||
xtn->gbl_environ <= -1)? -1: 0;
} }
struct fnctab_t struct fnctab_t

View File

@ -174,25 +174,37 @@ static inttab_t inttab[] =
static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym) static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym)
{ {
qse_cstr_t ea; qse_cstr_t ea;
int i; int left, right, mid, n;
/* TODO: binary search or something better */ left = 0; right = QSE_COUNTOF(fnctab) - 1;
for (i = 0; i < QSE_COUNTOF(fnctab); i++)
while (left <= right)
{ {
if (qse_strcmp (fnctab[i].name, name) == 0) mid = (left + right) / 2;
n = qse_strcmp (fnctab[mid].name, name);
if (n > 0) right = mid - 1;
else if (n < 0) left = mid + 1;
else
{ {
sym->type = QSE_AWK_MOD_FNC; sym->type = QSE_AWK_MOD_FNC;
sym->u.fnc = fnctab[i].info; sym->u.fnc = fnctab[mid].info;
return 0; return 0;
} }
} }
for (i = 0; i < QSE_COUNTOF(inttab); i++) left = 0; right = QSE_COUNTOF(inttab) - 1;
while (left <= right)
{ {
if (qse_strcmp (inttab[i].name, name) == 0) mid = (left + right) / 2;
n = qse_strcmp (inttab[mid].name, name);
if (n > 0) right = mid - 1;
else if (n < 0) left = mid + 1;
else
{ {
sym->type = QSE_AWK_MOD_INT; sym->type = QSE_AWK_MOD_INT;
sym->u.in = inttab[i].info; sym->u.in = inttab[mid].info;
return 0; return 0;
} }
} }

View File

@ -454,6 +454,8 @@ struct inttab_t
static fnctab_t fnctab[] = static fnctab_t fnctab[] =
{ {
/* keep this table sorted for binary search in query(). */
{ QSE_T("fork"), { { 0, 0, QSE_NULL }, fnc_fork, 0 } }, { QSE_T("fork"), { { 0, 0, QSE_NULL }, fnc_fork, 0 } },
{ QSE_T("getegid"), { { 0, 0, QSE_NULL }, fnc_getegid, 0 } }, { QSE_T("getegid"), { { 0, 0, QSE_NULL }, fnc_getegid, 0 } },
{ QSE_T("getenv"), { { 1, 1, QSE_NULL }, fnc_getenv, 0 } }, { QSE_T("getenv"), { { 1, 1, QSE_NULL }, fnc_getenv, 0 } },
@ -498,14 +500,16 @@ static fnctab_t fnctab[] =
static inttab_t inttab[] = static inttab_t inttab[] =
{ {
/* keep this table sorted for binary search in query(). */
{ QSE_T("SIGABRT"), { SIGABRT } }, { QSE_T("SIGABRT"), { SIGABRT } },
{ QSE_T("SIGALRM"), { SIGALRM } }, { QSE_T("SIGALRM"), { SIGALRM } },
{ QSE_T("SIGHUP"), { SIGHUP } }, { QSE_T("SIGHUP"), { SIGHUP } },
{ QSE_T("SIGINT"), { SIGINT } }, { QSE_T("SIGINT"), { SIGINT } },
{ QSE_T("SIGKILL"), { SIGKILL } }, { QSE_T("SIGKILL"), { SIGKILL } },
{ QSE_T("SIGQUIT"), { SIGQUIT } },
{ QSE_T("SIGSEGV"), { SIGSEGV } }, { QSE_T("SIGSEGV"), { SIGSEGV } },
{ QSE_T("SIGTERM"), { SIGTERM } }, { QSE_T("SIGTERM"), { SIGTERM } }
{ QSE_T("SIGQUIT"), { SIGQUIT } }
/* /*
{ QSE_T("WNOHANG"), { WNOHANG } }, { QSE_T("WNOHANG"), { WNOHANG } },
@ -515,25 +519,37 @@ static inttab_t inttab[] =
static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym) static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym)
{ {
qse_cstr_t ea; qse_cstr_t ea;
int i; int left, right, mid, n;
/* TODO: binary search or something better */ left = 0; right = QSE_COUNTOF(fnctab) - 1;
for (i = 0; i < QSE_COUNTOF(fnctab); i++)
while (left <= right)
{ {
if (qse_strcmp (fnctab[i].name, name) == 0) mid = (left + right) / 2;
n = qse_strcmp (fnctab[mid].name, name);
if (n > 0) right = mid - 1;
else if (n < 0) left = mid + 1;
else
{ {
sym->type = QSE_AWK_MOD_FNC; sym->type = QSE_AWK_MOD_FNC;
sym->u.fnc = fnctab[i].info; sym->u.fnc = fnctab[mid].info;
return 0; return 0;
} }
} }
for (i = 0; i < QSE_COUNTOF(inttab); i++) left = 0; right = QSE_COUNTOF(inttab) - 1;
while (left <= right)
{ {
if (qse_strcmp (inttab[i].name, name) == 0) mid = (left + right) / 2;
n = qse_strcmp (inttab[mid].name, name);
if (n > 0) right = mid - 1;
else if (n < 0) left = mid + 1;
else
{ {
sym->type = QSE_AWK_MOD_INT; sym->type = QSE_AWK_MOD_INT;
sym->u.in = inttab[i].info; sym->u.in = inttab[mid].info;
return 0; return 0;
} }
} }

View File

@ -1233,15 +1233,21 @@ static fnctab_t fnctab[] =
static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym) static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym)
{ {
qse_cstr_t ea; qse_cstr_t ea;
int i; int left, right, mid, n;
/* TODO: binary search */ left = 0; right = QSE_COUNTOF(fnctab) - 1;
for (i = 0; i < QSE_COUNTOF(fnctab); i++)
while (left <= right)
{ {
if (qse_strcmp (fnctab[i].name, name) == 0) mid = (left + right) / 2;
n = qse_strcmp (fnctab[mid].name, name);
if (n > 0) right = mid - 1;
else if (n < 0) left = mid + 1;
else
{ {
sym->type = QSE_AWK_MOD_FNC; sym->type = QSE_AWK_MOD_FNC;
sym->u.fnc = fnctab[i].info; sym->u.fnc = fnctab[mid].info;
return 0; return 0;
} }
} }