2010-09-04 06:50:08 +00:00
|
|
|
#include <qse/cmn/mem.h>
|
|
|
|
#include <qse/cmn/str.h>
|
|
|
|
#include <qse/cmn/dll.h>
|
2016-04-29 03:55:42 +00:00
|
|
|
#include <qse/si/sio.h>
|
2010-09-04 06:50:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define R(f) \
|
|
|
|
do { \
|
|
|
|
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
|
|
|
|
if (f() == -1) return -1; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static qse_dll_walk_t walk_dll (qse_dll_t* dll, qse_dll_node_t* n, void* arg)
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("[%.*s]\n"), (int)QSE_DLL_DLEN(n), QSE_DLL_DPTR(n));
|
|
|
|
return QSE_DLL_WALK_FORWARD;
|
|
|
|
}
|
|
|
|
|
|
|
|
static qse_dll_walk_t rwalk_dll (qse_dll_t* dll, qse_dll_node_t* n, void* arg)
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("[%.*s]\n"), (int)QSE_DLL_DLEN(n), QSE_DLL_DPTR(n));
|
|
|
|
return QSE_DLL_WALK_BACKWARD;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test1 ()
|
|
|
|
{
|
|
|
|
qse_dll_t* s1;
|
|
|
|
qse_dll_node_t* p;
|
|
|
|
qse_char_t* x[] =
|
|
|
|
{
|
|
|
|
QSE_T("this is so good"),
|
|
|
|
QSE_T("what the hack"),
|
|
|
|
QSE_T("do you like it?")
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
s1 = qse_dll_open (QSE_MMGR_GETDFL(), 0);
|
|
|
|
if (s1 == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("cannot open a string\n"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_dll_setcopier (s1, QSE_DLL_COPIER_INLINE);
|
|
|
|
qse_dll_setscale (s1, QSE_SIZEOF(qse_char_t));
|
|
|
|
|
|
|
|
for (i = 0; i < QSE_COUNTOF(x); i++)
|
|
|
|
{
|
|
|
|
qse_dll_pushtail (s1, x[i], qse_strlen(x[i]));
|
|
|
|
}
|
2013-11-26 13:47:58 +00:00
|
|
|
qse_printf (QSE_T("s1 holding [%zu] nodes\n"), QSE_DLL_SIZE(s1));
|
2010-09-04 06:50:08 +00:00
|
|
|
qse_dll_walk (s1, walk_dll, QSE_NULL);
|
|
|
|
|
|
|
|
|
|
|
|
p = qse_dll_search (s1, QSE_NULL, x[0], qse_strlen(x[0]));
|
|
|
|
if (p != QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_dll_delete (s1, p);
|
|
|
|
}
|
2013-11-26 13:47:58 +00:00
|
|
|
qse_printf (QSE_T("s1 holding [%zu] nodes\n"), QSE_DLL_SIZE(s1));
|
2010-09-04 06:50:08 +00:00
|
|
|
qse_dll_walk (s1, walk_dll, QSE_NULL);
|
|
|
|
|
|
|
|
qse_dll_close (s1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test2 ()
|
|
|
|
{
|
|
|
|
qse_dll_t* s1;
|
|
|
|
qse_dll_node_t* p;
|
|
|
|
qse_char_t* x[] =
|
|
|
|
{
|
|
|
|
QSE_T("this is so good"),
|
|
|
|
QSE_T("what the hack"),
|
|
|
|
QSE_T("do you like it?")
|
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
s1 = qse_dll_open (QSE_MMGR_GETDFL(), 0);
|
|
|
|
if (s1 == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("cannot open a string\n"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_dll_setcopier (s1, QSE_DLL_COPIER_INLINE);
|
|
|
|
qse_dll_setscale (s1, QSE_SIZEOF(qse_char_t));
|
|
|
|
|
|
|
|
for (i = 0; i < QSE_COUNTOF(x); i++)
|
|
|
|
{
|
|
|
|
qse_dll_pushtail (s1, x[i], qse_strlen(x[i]));
|
|
|
|
}
|
2013-11-26 13:47:58 +00:00
|
|
|
qse_printf (QSE_T("s1 holding [%zu] nodes\n"), QSE_DLL_SIZE(s1));
|
2010-09-04 06:50:08 +00:00
|
|
|
qse_dll_rwalk (s1, rwalk_dll, QSE_NULL);
|
|
|
|
|
|
|
|
|
|
|
|
p = qse_dll_search (s1, QSE_NULL, x[0], qse_strlen(x[0]));
|
|
|
|
if (p != QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_dll_delete (s1, p);
|
|
|
|
}
|
2013-11-26 13:47:58 +00:00
|
|
|
qse_printf (QSE_T("s1 holding [%zu] nodes\n"), QSE_DLL_SIZE(s1));
|
2010-09-04 06:50:08 +00:00
|
|
|
qse_dll_rwalk (s1, rwalk_dll, QSE_NULL);
|
|
|
|
|
|
|
|
qse_dll_close (s1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main ()
|
|
|
|
{
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_open_stdsios ();
|
2013-11-26 13:47:58 +00:00
|
|
|
|
2010-09-04 06:50:08 +00:00
|
|
|
R (test1);
|
|
|
|
R (test2);
|
2013-11-26 13:47:58 +00:00
|
|
|
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_close_stdsios ();
|
2010-09-04 06:50:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|