2011-08-06 11:08:21 +00:00
|
|
|
#include <qse/cmn/env.h>
|
2011-12-28 14:26:02 +00:00
|
|
|
#include <qse/cmn/mem.h>
|
2011-08-06 11:08:21 +00:00
|
|
|
#include <qse/cmn/str.h>
|
2016-04-29 03:55:42 +00:00
|
|
|
#include <qse/si/sio.h>
|
2011-08-06 11:08:21 +00:00
|
|
|
|
|
|
|
#define R(f) \
|
|
|
|
do { \
|
|
|
|
qse_printf (QSE_T("== %s ==\n"), QSE_T(#f)); \
|
|
|
|
if (f() == -1) return -1; \
|
|
|
|
} while (0)
|
|
|
|
|
2011-08-10 10:08:26 +00:00
|
|
|
static void dump (qse_env_t* env)
|
|
|
|
{
|
|
|
|
const qse_env_char_t* envstr;
|
|
|
|
qse_env_char_t** envarr;
|
|
|
|
|
|
|
|
envstr = qse_env_getstr (env);
|
|
|
|
#if (defined(QSE_ENV_CHAR_IS_WCHAR) && defined(QSE_CHAR_IS_WCHAR)) || \
|
|
|
|
(defined(QSE_ENV_CHAR_IS_MCHAR) && defined(QSE_CHAR_IS_MCHAR))
|
2011-08-11 10:18:35 +00:00
|
|
|
while (*envstr != QSE_T('\0'))
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("%p [%s]\n"), envstr, envstr);
|
|
|
|
envstr += qse_strlen(envstr) + 1;
|
|
|
|
}
|
2011-08-10 10:08:26 +00:00
|
|
|
#elif defined(QSE_ENV_CHAR_IS_WCHAR)
|
2011-08-11 10:18:35 +00:00
|
|
|
while (*envstr != QSE_WT('\0'))
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("%p [%S]\n"), envstr, envstr);
|
|
|
|
envstr += qse_wcslen(envstr) + 1;
|
|
|
|
}
|
2011-08-10 10:08:26 +00:00
|
|
|
#else
|
2011-08-11 10:18:35 +00:00
|
|
|
while (*envstr != QSE_MT('\0'))
|
|
|
|
{
|
|
|
|
qse_printf (QSE_T("%p [%S]\n"), envstr, envstr);
|
|
|
|
envstr += qse_mbslen(envstr) + 1;
|
2011-08-10 10:08:26 +00:00
|
|
|
}
|
2011-08-11 10:18:35 +00:00
|
|
|
#endif
|
2011-08-10 10:08:26 +00:00
|
|
|
|
2011-08-11 10:18:35 +00:00
|
|
|
qse_printf (QSE_T("-------------\n"));
|
2011-08-10 10:08:26 +00:00
|
|
|
envarr = qse_env_getarr (env);
|
2011-08-11 10:18:35 +00:00
|
|
|
while (*envarr)
|
2011-08-10 10:08:26 +00:00
|
|
|
{
|
|
|
|
#if (defined(QSE_ENV_CHAR_IS_WCHAR) && defined(QSE_CHAR_IS_WCHAR)) || \
|
|
|
|
(defined(QSE_ENV_CHAR_IS_MCHAR) && defined(QSE_CHAR_IS_MCHAR))
|
2011-08-11 10:18:35 +00:00
|
|
|
qse_printf (QSE_T("%p [%s]\n"), *envarr, *envarr);
|
2011-08-10 10:08:26 +00:00
|
|
|
#else
|
2011-08-11 10:18:35 +00:00
|
|
|
qse_printf (QSE_T("%p [%S]\n"), *envarr, *envarr);
|
2011-08-10 10:08:26 +00:00
|
|
|
#endif
|
2011-08-11 10:18:35 +00:00
|
|
|
envarr++;
|
2011-08-10 10:08:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-06 11:08:21 +00:00
|
|
|
static int test1 (void)
|
|
|
|
{
|
|
|
|
qse_env_t* env;
|
|
|
|
|
2011-12-28 14:26:02 +00:00
|
|
|
env = qse_env_open (QSE_MMGR_GETDFL(), 0, 0);
|
2011-08-06 11:08:21 +00:00
|
|
|
|
2011-08-07 09:41:27 +00:00
|
|
|
qse_env_clear (env);
|
|
|
|
qse_env_insert (env, QSE_T("alice"), QSE_T("wonderland"));
|
|
|
|
qse_env_insert (env, QSE_T("cool"), QSE_T("mint"));
|
|
|
|
qse_env_insert (env, QSE_T("smurf"), QSE_T("happy song"));
|
|
|
|
qse_env_insert (env, QSE_T("donkey"), QSE_T("mule"));
|
|
|
|
qse_env_insert (env, QSE_T("lily"), QSE_T("rose"));
|
|
|
|
|
|
|
|
qse_env_clear (env);
|
|
|
|
qse_env_insert (env, QSE_T("alice"), QSE_T("wonderland"));
|
|
|
|
qse_env_insert (env, QSE_T("cool"), QSE_T("mint"));
|
|
|
|
qse_env_insert (env, QSE_T("smurf"), QSE_T("happy song"));
|
|
|
|
qse_env_insert (env, QSE_T("donkey"), QSE_T("mule"));
|
|
|
|
qse_env_insert (env, QSE_T("lily"), QSE_T("rose"));
|
|
|
|
|
|
|
|
qse_env_delete (env, QSE_T("cool"));
|
|
|
|
qse_env_insert (env, QSE_T("spider"), QSE_T("man"));
|
|
|
|
|
2011-08-10 10:08:26 +00:00
|
|
|
dump (env);
|
2011-08-07 09:41:27 +00:00
|
|
|
|
|
|
|
qse_env_close (env);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test2 (void)
|
|
|
|
{
|
|
|
|
qse_env_t* env;
|
|
|
|
|
2011-12-28 14:26:02 +00:00
|
|
|
env = qse_env_open (QSE_MMGR_GETDFL(), 0, 1);
|
2011-08-07 09:41:27 +00:00
|
|
|
|
|
|
|
qse_printf (QSE_T("DELETING HOME => %s\n"),
|
|
|
|
(qse_env_delete (env, QSE_T("HOME")) == 0?
|
|
|
|
QSE_T("SUCCESS"): QSE_T("FAILURE"))
|
|
|
|
);
|
|
|
|
qse_printf (QSE_T("DELETING wolf => %s\n"),
|
|
|
|
(qse_env_delete (env, QSE_T("wolf")) == 0?
|
|
|
|
QSE_T("SUCCESS"): QSE_T("FAILURE"))
|
|
|
|
);
|
2011-08-06 11:08:21 +00:00
|
|
|
|
2011-08-10 10:08:26 +00:00
|
|
|
dump (env);
|
2011-08-06 11:08:21 +00:00
|
|
|
|
|
|
|
qse_env_close (env);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-11 10:18:35 +00:00
|
|
|
static int test3 (void)
|
|
|
|
{
|
|
|
|
qse_env_t* env;
|
|
|
|
|
2011-12-28 14:26:02 +00:00
|
|
|
env = qse_env_open (QSE_MMGR_GETDFL(), 0, 0);
|
2011-08-11 10:18:35 +00:00
|
|
|
|
2014-10-11 14:33:26 +00:00
|
|
|
qse_printf (QSE_T("appending to PATH => %d\n"), qse_env_append (env, QSE_T("xxx"))); /* this should fail as there's no item in the environment */
|
2012-02-08 12:59:59 +00:00
|
|
|
qse_printf (QSE_T("inserting PATH => %d\n"), qse_env_insert (env, QSE_T("PATH"), QSE_NULL));
|
2014-10-11 14:33:26 +00:00
|
|
|
qse_printf (QSE_T("appending to PATH => %d\n"), qse_env_append (env, QSE_T(":/usr/xxx/bin:/tmp/bin:/var/lib/qse/bin/sbin/test/bin")));
|
|
|
|
qse_printf (QSE_T("appending to PATH => %d\n"), qse_env_append (env, QSE_T("")));
|
|
|
|
|
2012-02-08 12:59:59 +00:00
|
|
|
qse_printf (QSE_T("inserting HOME => %d\n"), qse_env_insertmbs (env, QSE_MT("HOME"), QSE_NULL));
|
|
|
|
qse_printf (QSE_T("inserting USER => %d\n"), qse_env_insertwcs (env, QSE_WT("USER"), QSE_NULL));
|
|
|
|
qse_printf (QSE_T("inserting WHAT => %d\n"), qse_env_insert (env, QSE_T("WHAT"), QSE_NULL));
|
|
|
|
qse_printf (QSE_T("inserting an empty string => %d\n"), qse_env_insert (env, QSE_T(""), QSE_NULL));
|
2011-08-11 10:18:35 +00:00
|
|
|
|
|
|
|
dump (env);
|
|
|
|
|
|
|
|
qse_env_close (env);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
2011-08-06 11:08:21 +00:00
|
|
|
int main ()
|
|
|
|
{
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_open_stdsios();
|
2014-10-11 14:33:26 +00:00
|
|
|
|
2011-08-06 11:08:21 +00:00
|
|
|
R (test1);
|
2011-08-07 09:41:27 +00:00
|
|
|
R (test2);
|
2011-08-11 10:18:35 +00:00
|
|
|
R (test3);
|
2014-10-11 14:33:26 +00:00
|
|
|
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_close_stdsios();
|
2011-08-06 11:08:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|