moved id-to-data mapping functions to imap-imp.h out of mod-dir.c
This commit is contained in:
parent
546d34d732
commit
86c1819a1d
@ -1135,7 +1135,7 @@ static void open_mpi (mpi_t* mpi, int argc, qse_achar_t* argv[])
|
||||
|
||||
if (lt_dlinit () != 0) return;
|
||||
|
||||
if (lt_dladvise_init (&adv) != 0) goto oops;
|
||||
if (lt_dladvise_init(&adv) != 0) goto oops;
|
||||
|
||||
/* If i don't set the global option, loading may end up with an error
|
||||
* like this depending on your MPI library.
|
||||
@ -1143,23 +1143,23 @@ static void open_mpi (mpi_t* mpi, int argc, qse_achar_t* argv[])
|
||||
* symbol lookup error: /usr/lib/openmpi/lib/openmpi/mca_paffinity_linux.so: undefined symbol: mca_base_param_reg_int
|
||||
*/
|
||||
|
||||
if (lt_dladvise_global (&adv) != 0 || lt_dladvise_ext (&adv) != 0)
|
||||
if (lt_dladvise_global(&adv) != 0 || lt_dladvise_ext(&adv) != 0)
|
||||
{
|
||||
lt_dladvise_destroy (&adv);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
mpi->h = lt_dlopenadvise (DEFAULT_MODPREFIX "mpi" DEFAULT_MODPOSTFIX, adv);
|
||||
mpi->h = lt_dlopenadvise(DEFAULT_MODPREFIX "mpi" DEFAULT_MODPOSTFIX, adv);
|
||||
lt_dladvise_destroy (&adv);
|
||||
|
||||
if (mpi->h)
|
||||
{
|
||||
mpi->i = lt_dlsym (mpi->h, "qse_awk_mod_mpi_init");
|
||||
mpi->f = lt_dlsym (mpi->h, "qse_awk_mod_mpi_fini");
|
||||
mpi->i = lt_dlsym(mpi->h, "qse_awk_mod_mpi_init");
|
||||
mpi->f = lt_dlsym(mpi->h, "qse_awk_mod_mpi_fini");
|
||||
|
||||
if (mpi->i == QSE_NULL ||
|
||||
mpi->f == QSE_NULL ||
|
||||
mpi->i (argc, argv) <= -1)
|
||||
mpi->i(argc, argv) <= -1)
|
||||
{
|
||||
lt_dlclose (mpi->h);
|
||||
mpi->h = QSE_NULL;
|
||||
|
@ -37,7 +37,7 @@ endif
|
||||
noinst_HEADERS = awk-prv.h err.h rio.h val.h fnc.h misc.h parse.h run.h tree.h std.h
|
||||
|
||||
lib_LTLIBRARIES = libqseawk.la
|
||||
libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c val-imp.h fnc.c misc.c misc-imp.h rio.c std.c
|
||||
libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c val-imp.h fnc.c imap-imp.h misc.c misc-imp.h rio.c std.c
|
||||
libqseawk_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
||||
libqseawk_la_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
||||
libqseawk_la_LIBADD = $(LIBADD_LIB_COMMON)
|
||||
|
@ -219,7 +219,7 @@ libqseawk_sys_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
|
||||
am__DEPENDENCIES_4 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
|
||||
$(am__DEPENDENCIES_3)
|
||||
am__libqseawk_la_SOURCES_DIST = awk.c err.c tree.c parse.c run.c rec.c \
|
||||
val.c val-imp.h fnc.c misc.c misc-imp.h rio.c std.c mod-dir.c \
|
||||
val.c val-imp.h fnc.c imap-imp.h misc.c misc-imp.h rio.c std.c mod-dir.c \
|
||||
mod-dir.h mod-math.c mod-math.h mod-str.c mod-str.h mod-sys.c \
|
||||
mod-sys.h
|
||||
@ENABLE_STATIC_MODULE_TRUE@am__objects_1 = libqseawk_la-mod-dir.lo \
|
||||
@ -516,7 +516,7 @@ LIBADD_LIB_COMMON = -lqsecmn -lqsesi $(LIBM) $(am__append_1) \
|
||||
noinst_HEADERS = awk-prv.h err.h rio.h val.h fnc.h misc.h parse.h run.h tree.h std.h
|
||||
lib_LTLIBRARIES = libqseawk.la $(am__append_5)
|
||||
libqseawk_la_SOURCES = awk.c err.c tree.c parse.c run.c rec.c val.c \
|
||||
val-imp.h fnc.c misc.c misc-imp.h rio.c std.c $(am__append_6)
|
||||
val-imp.h fnc.c imap-imp.h misc.c misc-imp.h rio.c std.c $(am__append_6)
|
||||
libqseawk_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
||||
libqseawk_la_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
||||
libqseawk_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_7) \
|
||||
|
155
qse/lib/awk/imap-imp.h
Normal file
155
qse/lib/awk/imap-imp.h
Normal file
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2006-2014 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.
|
||||
*/
|
||||
|
||||
/* THIS FILE IS SUPPOSED TO BE INCLUDED BY MODULE SOURCE THAT MAINTAINS MAPPING BETWEEN ID AND DATA */
|
||||
|
||||
typedef struct __IMAP_NODE_T __IMAP_NODE_T;
|
||||
struct __IMAP_NODE_T
|
||||
{
|
||||
__IMAP_NODE_T* prev;
|
||||
__IMAP_NODE_T* next;
|
||||
int id;
|
||||
|
||||
__IMAP_NODE_T_DATA
|
||||
};
|
||||
|
||||
struct __IMAP_LIST_T
|
||||
{
|
||||
__IMAP_NODE_T* head;
|
||||
__IMAP_NODE_T* tail;
|
||||
__IMAP_NODE_T* free;
|
||||
|
||||
/* mapping table to map 'id' to 'node' */
|
||||
struct
|
||||
{
|
||||
__IMAP_NODE_T** tab;
|
||||
int capa;
|
||||
int high;
|
||||
} map;
|
||||
|
||||
__IMAP_LIST_T_DATA
|
||||
};
|
||||
|
||||
static __IMAP_NODE_T* __MAKE_IMAP_NODE (qse_awk_rtx_t* rtx, __IMAP_LIST_T* list)
|
||||
{
|
||||
/* create a new context node and append it to the list tail */
|
||||
__IMAP_NODE_T* node;
|
||||
|
||||
node = QSE_NULL;
|
||||
|
||||
if (list->free) node = list->free;
|
||||
else
|
||||
{
|
||||
node = qse_awk_rtx_callocmem(rtx, QSE_SIZEOF(*node));
|
||||
if (!node) goto oops;
|
||||
}
|
||||
|
||||
if (node == list->free) list->free = node->next;
|
||||
else
|
||||
{
|
||||
if (list->map.high <= list->map.capa)
|
||||
{
|
||||
qse_size_t newcapa, inc;
|
||||
__IMAP_NODE_T** tmp;
|
||||
|
||||
inc = QSE_TYPE_MAX(int) - list->map.capa;
|
||||
if (inc == 0) goto oops; /* too many ndoes */
|
||||
|
||||
if (inc > 64) inc = 64;
|
||||
newcapa = (qse_size_t)list->map.capa + inc;
|
||||
|
||||
tmp = (__IMAP_NODE_T**)qse_awk_rtx_reallocmem(rtx, list->map.tab, QSE_SIZEOF(*tmp) * newcapa);
|
||||
if (!tmp) goto oops;
|
||||
|
||||
QSE_MEMSET (&tmp[list->map.capa], 0, QSE_SIZEOF(*tmp) * (newcapa - list->map.capa));
|
||||
|
||||
list->map.tab = tmp;
|
||||
list->map.capa = newcapa;
|
||||
}
|
||||
|
||||
node->id = list->map.high;
|
||||
QSE_ASSERT (list->map.tab[node->id] == QSE_NULL);
|
||||
list->map.tab[node->id] = node;
|
||||
list->map.high++;
|
||||
}
|
||||
|
||||
/* append it to the tail */
|
||||
node->next = QSE_NULL;
|
||||
node->prev = list->tail;
|
||||
if (list->tail) list->tail->next = node;
|
||||
else list->head = node;
|
||||
list->tail = node;
|
||||
|
||||
return node;
|
||||
|
||||
oops:
|
||||
if (node) qse_awk_rtx_freemem (rtx, node);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
static void __FREE_IMAP_NODE (qse_awk_rtx_t* rtx, __IMAP_LIST_T* list, __IMAP_NODE_T* node)
|
||||
{
|
||||
if (node->prev) node->prev->next = node->next;
|
||||
if (node->next) node->next->prev = node->prev;
|
||||
if (list->head == node) list->head = node->next;
|
||||
if (list->tail == node) list->tail = node->prev;
|
||||
|
||||
list->map.tab[node->id] = QSE_NULL;
|
||||
|
||||
if (list->map.high == node->id + 1)
|
||||
{
|
||||
/* destroy the actual node if the node to be freed has the
|
||||
* highest id */
|
||||
qse_awk_rtx_freemem (rtx, node);
|
||||
list->map.high--;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* otherwise, chain the node to the free list */
|
||||
node->next = list->free;
|
||||
list->free = node;
|
||||
}
|
||||
|
||||
/* however, i destroy the whole free list when all the nodes are
|
||||
* chanined to the free list */
|
||||
if (list->head == QSE_NULL)
|
||||
{
|
||||
__IMAP_NODE_T* curnode;
|
||||
|
||||
while (list->free)
|
||||
{
|
||||
curnode = list->free;
|
||||
list->free = list->free->next;
|
||||
QSE_ASSERT (curnode->ctx == QSE_NULL);
|
||||
qse_awk_rtx_freemem (rtx, curnode);
|
||||
}
|
||||
|
||||
qse_awk_rtx_freemem (rtx, list->map.tab);
|
||||
list->map.high = 0;
|
||||
list->map.capa = 0;
|
||||
list->map.tab = QSE_NULL;
|
||||
}
|
||||
}
|
@ -62,31 +62,6 @@ enum
|
||||
DIR_EMAPTOSCALAR
|
||||
};
|
||||
|
||||
struct dir_node_t
|
||||
{
|
||||
int id;
|
||||
qse_dir_t* ctx;
|
||||
dir_node_t* prev;
|
||||
dir_node_t* next;
|
||||
};
|
||||
|
||||
struct dir_list_t
|
||||
{
|
||||
dir_node_t* head;
|
||||
dir_node_t* tail;
|
||||
dir_node_t* free;
|
||||
|
||||
/* mapping table to map 'id' to 'node' */
|
||||
struct
|
||||
{
|
||||
dir_node_t** tab;
|
||||
qse_size_t capa;
|
||||
qse_size_t high;
|
||||
} map;
|
||||
|
||||
int errnum;
|
||||
};
|
||||
|
||||
static int dir_err_to_errnum (qse_dir_errnum_t num)
|
||||
{
|
||||
switch (num)
|
||||
@ -131,131 +106,46 @@ static int awk_err_to_errnum (qse_awk_errnum_t num)
|
||||
}
|
||||
}
|
||||
|
||||
#define __IMAP_NODE_T_DATA qse_dir_t* ctx;
|
||||
#define __IMAP_LIST_T_DATA int errnum;
|
||||
#define __IMAP_LIST_T dir_list_t
|
||||
#define __IMAP_NODE_T dir_node_t
|
||||
#define __MAKE_IMAP_NODE __new_dir_node
|
||||
#define __FREE_IMAP_NODE __free_dir_node
|
||||
#include "imap-imp.h"
|
||||
|
||||
static dir_node_t* new_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, const qse_char_t* path, qse_awk_int_t flags)
|
||||
{
|
||||
/* create a new context node and append it to the list tail */
|
||||
dir_node_t* node;
|
||||
qse_dir_errnum_t oe;
|
||||
|
||||
node = QSE_NULL;
|
||||
|
||||
if (list->free) node = list->free;
|
||||
else
|
||||
{
|
||||
node = qse_awk_rtx_callocmem (rtx, QSE_SIZEOF(*node));
|
||||
node = __new_dir_node(rtx, list);
|
||||
if (!node)
|
||||
{
|
||||
list->errnum = DIR_ENOMEM;
|
||||
goto oops;
|
||||
}
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
node->ctx = qse_dir_open (qse_awk_rtx_getmmgr(rtx), 0, path, flags, &oe);
|
||||
node->ctx = qse_dir_open(qse_awk_rtx_getmmgr(rtx), 0, path, flags, &oe);
|
||||
if (!node->ctx)
|
||||
{
|
||||
list->errnum = dir_err_to_errnum (oe);
|
||||
goto oops;
|
||||
list->errnum = dir_err_to_errnum(oe);
|
||||
__free_dir_node (rtx, list, node);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
if (node == list->free) list->free = node->next;
|
||||
else
|
||||
{
|
||||
if (list->map.high <= list->map.capa)
|
||||
{
|
||||
qse_size_t newcapa;
|
||||
dir_node_t** tmp;
|
||||
|
||||
newcapa = list->map.capa + 64;
|
||||
if (newcapa < list->map.capa) goto oops; /* overflow */
|
||||
|
||||
tmp = (dir_node_t**) qse_awk_rtx_reallocmem (
|
||||
rtx, list->map.tab, QSE_SIZEOF(*tmp) * newcapa);
|
||||
if (!tmp)
|
||||
{
|
||||
list->errnum = DIR_ENOMEM;
|
||||
goto oops;
|
||||
}
|
||||
|
||||
QSE_MEMSET (&tmp[list->map.capa], 0,
|
||||
QSE_SIZEOF(*tmp) * (newcapa - list->map.capa));
|
||||
|
||||
list->map.tab = tmp;
|
||||
list->map.capa = newcapa;
|
||||
}
|
||||
|
||||
node->id = list->map.high;
|
||||
QSE_ASSERT (list->map.tab[node->id] == QSE_NULL);
|
||||
list->map.tab[node->id] = node;
|
||||
list->map.high++;
|
||||
}
|
||||
|
||||
/* append it to the tail */
|
||||
node->next = QSE_NULL;
|
||||
node->prev = list->tail;
|
||||
if (list->tail) list->tail->next = node;
|
||||
else list->head = node;
|
||||
list->tail = node;
|
||||
|
||||
return node;
|
||||
|
||||
oops:
|
||||
if (node) qse_awk_rtx_freemem (rtx, node);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
static void free_dir_node (qse_awk_rtx_t* rtx, dir_list_t* list, dir_node_t* node)
|
||||
{
|
||||
if (node->prev) node->prev->next = node->next;
|
||||
if (node->next) node->next->prev = node->prev;
|
||||
if (list->head == node) list->head = node->next;
|
||||
if (list->tail == node) list->tail = node->prev;
|
||||
|
||||
list->map.tab[node->id] = QSE_NULL;
|
||||
|
||||
if (node->ctx)
|
||||
{
|
||||
qse_dir_close (node->ctx);
|
||||
}
|
||||
|
||||
if (list->map.high == node->id + 1)
|
||||
{
|
||||
/* destroy the actual node if the node to be freed has the
|
||||
* highest id */
|
||||
QSE_MMGR_FREE (qse_awk_rtx_getmmgr(rtx), node);
|
||||
list->map.high--;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* otherwise, chain the node to the free list */
|
||||
qse_dir_close(node->ctx);
|
||||
node->ctx = QSE_NULL;
|
||||
node->next = list->free;
|
||||
list->free = node;
|
||||
}
|
||||
|
||||
/* however, i destroy the whole free list when all the nodes are
|
||||
* chanined to the free list */
|
||||
if (list->head == QSE_NULL)
|
||||
{
|
||||
qse_mmgr_t* mmgr;
|
||||
dir_node_t* curnode;
|
||||
|
||||
mmgr = qse_awk_rtx_getmmgr(rtx);
|
||||
|
||||
while (list->free)
|
||||
{
|
||||
curnode = list->free;
|
||||
list->free = list->free->next;
|
||||
QSE_ASSERT (curnode->ctx == QSE_NULL);
|
||||
QSE_MMGR_FREE (mmgr, curnode);
|
||||
}
|
||||
|
||||
QSE_MMGR_FREE (mmgr, list->map.tab);
|
||||
list->map.high = 0;
|
||||
list->map.capa = 0;
|
||||
list->map.tab = QSE_NULL;
|
||||
}
|
||||
__free_dir_node (rtx, list, node);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
static int close_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_awk_int_t id)
|
||||
@ -276,7 +166,7 @@ static int reset_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_awk_int_t id, c
|
||||
{
|
||||
if (id >= 0 && id < list->map.high && list->map.tab[id])
|
||||
{
|
||||
if (qse_dir_reset (list->map.tab[id]->ctx, path) <= -1)
|
||||
if (qse_dir_reset(list->map.tab[id]->ctx, path) <= -1)
|
||||
{
|
||||
list->errnum = dir_err_to_errnum (qse_dir_geterrnum (list->map.tab[id]->ctx));
|
||||
return -1;
|
||||
@ -298,10 +188,10 @@ static int read_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_awk_int_t id, qs
|
||||
qse_dir_ent_t ent;
|
||||
qse_awk_val_t* tmp;
|
||||
|
||||
y = qse_dir_read (list->map.tab[id]->ctx, &ent);
|
||||
y = qse_dir_read(list->map.tab[id]->ctx, &ent);
|
||||
if (y <= -1)
|
||||
{
|
||||
list->errnum = dir_err_to_errnum (qse_dir_geterrnum (list->map.tab[id]->ctx));
|
||||
list->errnum = dir_err_to_errnum(qse_dir_geterrnum (list->map.tab[id]->ctx));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -336,7 +226,7 @@ static int read_byid (qse_awk_rtx_t* rtx, dir_list_t* list, qse_awk_int_t id, qs
|
||||
static QSE_INLINE dir_list_t* rtx_to_list (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
{
|
||||
qse_rbt_pair_t* pair;
|
||||
pair = qse_rbt_search ((qse_rbt_t*)fi->mod->ctx, &rtx, QSE_SIZEOF(rtx));
|
||||
pair = qse_rbt_search((qse_rbt_t*)fi->mod->ctx, &rtx, QSE_SIZEOF(rtx));
|
||||
QSE_ASSERT (pair != QSE_NULL);
|
||||
return (dir_list_t*)QSE_RBT_VPTR(pair);
|
||||
}
|
||||
@ -346,7 +236,7 @@ static int fnc_dir_errno (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
dir_list_t* list;
|
||||
qse_awk_val_t* retv;
|
||||
|
||||
list = rtx_to_list (rtx, fi);
|
||||
list = rtx_to_list(rtx, fi);
|
||||
|
||||
retv = qse_awk_rtx_makeintval (rtx, list->errnum);
|
||||
if (retv == QSE_NULL) return -1;
|
||||
@ -375,7 +265,7 @@ static int fnc_dir_errstr (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
qse_awk_val_t* retv;
|
||||
qse_awk_int_t errnum;
|
||||
|
||||
list = rtx_to_list (rtx, fi);
|
||||
list = rtx_to_list(rtx, fi);
|
||||
|
||||
if (qse_awk_rtx_getnargs (rtx) <= 0 ||
|
||||
qse_awk_rtx_valtoint (rtx, qse_awk_rtx_getarg (rtx, 0), &errnum) <= -1)
|
||||
@ -402,7 +292,7 @@ static int fnc_dir_open (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
qse_awk_val_t* a0;
|
||||
qse_awk_int_t flags = 0;
|
||||
|
||||
list = rtx_to_list (rtx, fi);
|
||||
list = rtx_to_list(rtx, fi);
|
||||
|
||||
a0 = qse_awk_rtx_getarg (rtx, 0);
|
||||
path = qse_awk_rtx_getvalstr (rtx, a0, QSE_NULL);
|
||||
@ -446,17 +336,17 @@ static int fnc_dir_close (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
qse_awk_int_t id;
|
||||
int ret;
|
||||
|
||||
list = rtx_to_list (rtx, fi);
|
||||
list = rtx_to_list(rtx, fi);
|
||||
|
||||
ret = qse_awk_rtx_valtoint (rtx, qse_awk_rtx_getarg (rtx, 0), &id);
|
||||
ret = qse_awk_rtx_valtoint(rtx, qse_awk_rtx_getarg (rtx, 0), &id);
|
||||
if (ret <= -1)
|
||||
{
|
||||
list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx));
|
||||
list->errnum = awk_err_to_errnum(qse_awk_rtx_geterrnum (rtx));
|
||||
ret = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = close_byid (rtx, list, id);
|
||||
ret = close_byid(rtx, list, id);
|
||||
}
|
||||
|
||||
qse_awk_rtx_setretval (rtx, qse_awk_rtx_makeintval (rtx, ret));
|
||||
@ -470,7 +360,7 @@ static int fnc_dir_reset (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
int ret;
|
||||
qse_char_t* path;
|
||||
|
||||
list = rtx_to_list (rtx, fi);
|
||||
list = rtx_to_list(rtx, fi);
|
||||
|
||||
ret = qse_awk_rtx_valtoint (rtx, qse_awk_rtx_getarg (rtx, 0), &id);
|
||||
if (ret <= -1)
|
||||
@ -507,12 +397,12 @@ static int fnc_dir_read (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
qse_awk_int_t id;
|
||||
int ret;
|
||||
|
||||
list = rtx_to_list (rtx, fi);
|
||||
list = rtx_to_list(rtx, fi);
|
||||
|
||||
ret = qse_awk_rtx_valtoint (rtx, qse_awk_rtx_getarg (rtx, 0), &id);
|
||||
ret = qse_awk_rtx_valtoint(rtx, qse_awk_rtx_getarg (rtx, 0), &id);
|
||||
if (ret <= -1)
|
||||
{
|
||||
list->errnum = awk_err_to_errnum (qse_awk_rtx_geterrnum (rtx));
|
||||
list->errnum = awk_err_to_errnum(qse_awk_rtx_geterrnum (rtx));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -630,7 +520,7 @@ static void fini (qse_awk_mod_t* mod, qse_awk_rtx_t* rtx)
|
||||
rbt = (qse_rbt_t*)mod->ctx;
|
||||
|
||||
/* garbage clean-up */
|
||||
pair = qse_rbt_search (rbt, &rtx, QSE_SIZEOF(rtx));
|
||||
pair = qse_rbt_search(rbt, &rtx, QSE_SIZEOF(rtx));
|
||||
if (pair)
|
||||
{
|
||||
dir_list_t* list;
|
||||
@ -669,7 +559,7 @@ int qse_awk_mod_dir (qse_awk_mod_t* mod, qse_awk_t* awk)
|
||||
mod->init = init;
|
||||
mod->fini = fini;
|
||||
|
||||
rbt = qse_rbt_open (qse_awk_getmmgr(awk), 0, 1, 1);
|
||||
rbt = qse_rbt_open(qse_awk_getmmgr(awk), 0, 1, 1);
|
||||
if (rbt == QSE_NULL)
|
||||
{
|
||||
qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL);
|
||||
|
@ -282,11 +282,11 @@ int qse_awk_mod_mpi (qse_awk_mod_t* mod, qse_awk_t* awk)
|
||||
* and the module wasn't built. So you can't access mpi::xxx symbols either
|
||||
*/
|
||||
|
||||
QSE_EXPORT int qse_awk_mod_mpi_init (int argc, qse_achar_t* argv[])
|
||||
int qse_awk_mod_mpi_init (int argc, qse_achar_t* argv[])
|
||||
{
|
||||
int rx;
|
||||
|
||||
if (MPI_Init (&argc, &argv) != MPI_SUCCESS) rx = -1;
|
||||
if (MPI_Init(&argc, &argv) != MPI_SUCCESS) rx = -1;
|
||||
else
|
||||
{
|
||||
MPI_Comm_set_errhandler (MPI_COMM_WORLD, MPI_ERRORS_RETURN);
|
||||
@ -296,7 +296,7 @@ QSE_EXPORT int qse_awk_mod_mpi_init (int argc, qse_achar_t* argv[])
|
||||
return rx;
|
||||
}
|
||||
|
||||
QSE_EXPORT void qse_awk_mod_mpi_fini (void)
|
||||
void qse_awk_mod_mpi_fini (void)
|
||||
{
|
||||
MPI_Finalize ();
|
||||
}
|
||||
|
@ -35,6 +35,10 @@ extern "C" {
|
||||
|
||||
QSE_EXPORT int qse_awk_mod_mpi (qse_awk_mod_t* mod, qse_awk_t* awk);
|
||||
|
||||
|
||||
QSE_EXPORT int qse_awk_mod_mpi_init (int argc, qse_achar_t* argv[]);
|
||||
QSE_EXPORT void qse_awk_mod_mpi_fini (void);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
@ -25,9 +25,41 @@
|
||||
*/
|
||||
|
||||
#include "mod-mysql.h"
|
||||
#include <mysql/mysql.h>
|
||||
|
||||
#define __IMAP_NODE_T_DATA MYSQL ctx;
|
||||
#define __IMAP_LIST_T_DATA /* nothing */
|
||||
#define __IMAP_LIST_T sql_list_t
|
||||
#define __IMAP_NODE_T sql_node_t
|
||||
#define __MAKE_IMAP_NODE __new_sql_node
|
||||
#define __FREE_IMAP_NODE __free_sql_node
|
||||
#include "../lib/awk/imap-imp.h"
|
||||
|
||||
static sql_node_t* new_sql_node (qse_awk_rtx_t* rtx, sql_list_t* list)
|
||||
{
|
||||
sql_node_t* node;
|
||||
|
||||
node = __new_sql_node(rtx, list);
|
||||
if (!node) return QSE_NULL;
|
||||
|
||||
if (mysql_init(&node->ctx) == QSE_NULL)
|
||||
{
|
||||
__free_sql_node (rtx, list, node);
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static void free_sql_node (qse_awk_rtx_t* rtx, sql_list_t* list, sql_node_t* node)
|
||||
{
|
||||
mysqL_close (&node->ctx);
|
||||
__free_sql_node (rtx, list, node);
|
||||
}
|
||||
|
||||
static int fnc_open (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||
{
|
||||
sql_node_t* node;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -115,12 +147,14 @@ static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qs
|
||||
|
||||
static int init (qse_awk_mod_t* mod, qse_awk_rtx_t* rtx)
|
||||
{
|
||||
mysql_library_init (0, QSE_NULL, QSE_NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void fini (qse_awk_mod_t* mod, qse_awk_rtx_t* rtx)
|
||||
{
|
||||
/* TODO: anything */
|
||||
mysql_library_end ();
|
||||
}
|
||||
|
||||
static void unload (qse_awk_mod_t* mod, qse_awk_t* awk)
|
||||
@ -139,5 +173,19 @@ int qse_awk_mod_mysql (qse_awk_mod_t* mod, qse_awk_t* awk)
|
||||
mod->ctx...
|
||||
*/
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int qse_awk_mod_mysql_init (int argc, qse_achar_t* argv[])
|
||||
{
|
||||
if (mysql_library_init(argc, argv, QSE_NULL) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void qse_awk_mod_mysql_fini (void)
|
||||
{
|
||||
mysql_library_end ();
|
||||
}
|
||||
|
@ -35,6 +35,10 @@ extern "C" {
|
||||
|
||||
QSE_EXPORT int qse_awk_mod_mysql (qse_awk_mod_t* mod, qse_awk_t* awk);
|
||||
|
||||
|
||||
QSE_EXPORT int qse_awk_mod_mysql_init (int argc, qse_achar_t* argv[]);
|
||||
QSE_EXPORT void qse_awk_mod_mysql_fini (void);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user