fixed the wrong defintion of qse_strbeg().

started wrting qse_env_delete()
This commit is contained in:
hyung-hwan 2011-08-06 21:25:08 +00:00
parent a5e86b984c
commit c73a51dbbc
3 changed files with 60 additions and 24 deletions

View File

@ -54,7 +54,8 @@ QSE_DEFINE_COMMON_FUNCTIONS(env)
qse_env_t* qse_env_open ( qse_env_t* qse_env_open (
qse_mmgr_t* mmgr, qse_mmgr_t* mmgr,
qse_size_t xtnsize qse_size_t xtnsize,
int fromcurenv
); );
void qse_env_close ( void qse_env_close (
@ -63,7 +64,8 @@ void qse_env_close (
qse_env_t* qse_env_init ( qse_env_t* qse_env_init (
qse_env_t* env, qse_env_t* env,
qse_mmgr_t* mmgr qse_mmgr_t* mmgr,
int fromcurenv
); );
void qse_env_fini ( void qse_env_fini (
@ -77,19 +79,15 @@ void qse_env_clear (
#define qse_env_getstr(env) ((env)->str.ptr) #define qse_env_getstr(env) ((env)->str.ptr)
#define qse_env_getarr(env) ((env)->arr.ptr) #define qse_env_getarr(env) ((env)->arr.ptr)
int qse_env_addvar ( int qse_env_insert (
qse_env_t* env, qse_env_t* env,
const qse_char_t* name, const qse_char_t* name,
const qse_char_t* value const qse_char_t* value
); );
int qse_env_addraw ( int qse_env_delete (
qse_env_t* env, /**< env */ qse_env_t* env,
const qse_char_t* raw /**< name=value */ const qse_char_t* name
);
int qse_env_loadcurvars (
qse_env_t* env
); );
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,5 +1,5 @@
/* /*
* $Id: str.h 535 2011-08-05 17:08:21Z hyunghwan.chung $ * $Id: str.h 536 2011-08-06 03:25:08Z hyunghwan.chung $
* *
Copyright 2006-2011 Chung, Hyung-Hwan. Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -1342,12 +1342,12 @@ qse_wchar_t* qse_wcsxnbeg (
); );
#ifdef QSE_CHAR_IS_MCHAR #ifdef QSE_CHAR_IS_MCHAR
# define qse_strbeg(str,sub) qse_mbsxbeg(str,sub) # define qse_strbeg(str,sub) qse_mbsbeg(str,sub)
# define qse_strxbeg(str,len,sub) qse_mbsxbeg(str,len,sub) # define qse_strxbeg(str,len,sub) qse_mbsxbeg(str,len,sub)
# define qse_strnbeg(str,sub,len) qse_mbsnbeg(str,sub,len) # define qse_strnbeg(str,sub,len) qse_mbsnbeg(str,sub,len)
# define qse_strxnbeg(str,len1,sub,len2) qse_mbsxnbeg(str,len1,sub,len2) # define qse_strxnbeg(str,len1,sub,len2) qse_mbsxnbeg(str,len1,sub,len2)
#else #else
# define qse_strbeg(str,sub) qse_wcsxbeg(str,sub) # define qse_strbeg(str,sub) qse_wcsbeg(str,sub)
# define qse_strxbeg(str,len,sub) qse_wcsxbeg(str,len,sub) # define qse_strxbeg(str,len,sub) qse_wcsxbeg(str,len,sub)
# define qse_strnbeg(str,sub,len) qse_wcsnbeg(str,sub,len) # define qse_strnbeg(str,sub,len) qse_wcsnbeg(str,sub,len)
# define qse_strxnbeg(str,len1,sub,len2) qse_wcsxnbeg(str,len1,sub,len2) # define qse_strxnbeg(str,len1,sub,len2) qse_wcsxnbeg(str,len1,sub,len2)

View File

@ -28,7 +28,9 @@
QSE_IMPLEMENT_COMMON_FUNCTIONS(env) QSE_IMPLEMENT_COMMON_FUNCTIONS(env)
qse_env_t* qse_env_open (qse_mmgr_t* mmgr, qse_size_t xtnsize) static int load_curenv (qse_env_t* env);
qse_env_t* qse_env_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, int fromcurenv)
{ {
qse_env_t* env; qse_env_t* env;
@ -45,7 +47,7 @@ qse_env_t* qse_env_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
env = QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_env_t) + xtnsize); env = QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_env_t) + xtnsize);
if (env == QSE_NULL) return QSE_NULL; if (env == QSE_NULL) return QSE_NULL;
if (qse_env_init (env, mmgr) == QSE_NULL) if (qse_env_init (env, mmgr, fromcurenv) == QSE_NULL)
{ {
QSE_MMGR_FREE (mmgr, env); QSE_MMGR_FREE (mmgr, env);
return QSE_NULL; return QSE_NULL;
@ -60,10 +62,12 @@ void qse_env_close (qse_env_t* env)
QSE_MMGR_FREE (env->mmgr, env); QSE_MMGR_FREE (env->mmgr, env);
} }
qse_env_t* qse_env_init (qse_env_t* env, qse_mmgr_t* mmgr) qse_env_t* qse_env_init (qse_env_t* env, qse_mmgr_t* mmgr, int fromcurenv)
{ {
QSE_MEMSET (env, 0, QSE_SIZEOF(*env)); QSE_MEMSET (env, 0, QSE_SIZEOF(*env));
env->mmgr = mmgr; env->mmgr = mmgr;
if (fromcurenv && load_curenv (env) <= -1) return QSE_NULL;
return env; return env;
} }
@ -75,8 +79,16 @@ void qse_env_fini (qse_env_t* env)
void qse_env_clear (qse_env_t* env) void qse_env_clear (qse_env_t* env)
{ {
if (env->str.ptr) env->str.ptr[0] = QSE_T('\0'); if (env->str.ptr)
if (env->arr.ptr) env->arr.ptr = QSE_NULL; {
env->str.ptr[0] = QSE_T('\0');
env->str.len = 0;
}
if (env->arr.ptr)
{
env->arr.ptr = QSE_NULL;
env->arr.len = 0;
}
} }
static int expandarr (qse_env_t* env) static int expandarr (qse_env_t* env)
@ -111,7 +123,8 @@ static int expandstr (qse_env_t* env, qse_size_t inc)
return 0; return 0;
} }
int qse_env_addvar (qse_env_t* env, const qse_char_t* name, const qse_char_t* value) int qse_env_insert (
qse_env_t* env, const qse_char_t* name, const qse_char_t* value)
{ {
qse_size_t nl, vl, tl; qse_size_t nl, vl, tl;
@ -136,7 +149,33 @@ int qse_env_addvar (qse_env_t* env, const qse_char_t* name, const qse_char_t* va
return -1; return -1;
} }
int qse_env_addraw (qse_env_t* env, const qse_char_t* nv) int qse_env_delete (qse_env_t* env, const qse_char_t* name)
{
const qse_char_t* p = env->str.ptr;
qse_size_t i;
for (i = 0; i < env->arr.len; i++)
{
const qse_char_t* eq;
const qse_char_t* vp;
vp = env->arr.ptr[i];
eq = qse_strbeg (vp, name);
if (eq && *eq == QSE_T('='))
{
#if 0
/* bingo */
len = qse_strlen (vp) + 1;
QSE_MEMCPY (vp, vp + len, ... );
#endif
}
}
return 0;
}
static int add_envstr (qse_env_t* env, const qse_char_t* nv)
{ {
qse_size_t tl; qse_size_t tl;
@ -155,8 +194,7 @@ int qse_env_addraw (qse_env_t* env, const qse_char_t* nv)
return 0; return 0;
} }
/* add current environment variables */ static int load_curenv (qse_env_t* env)
int qse_env_loadcurvars (qse_env_t* env)
{ {
#if defined(_WIN32) #if defined(_WIN32)
qse_char_t* envstr; qse_char_t* envstr;
@ -205,7 +243,7 @@ done:
x = qse_mbstowcsdup (*p, env->mmgr); x = qse_mbstowcsdup (*p, env->mmgr);
if (x == QSE_NULL) return -1; if (x == QSE_NULL) return -1;
n = qse_env_addraw (env, x); n = add_envstr (env, x);
QSE_MMGR_FREE (env->mmgr, x); QSE_MMGR_FREE (env->mmgr, x);
if (n <= -1) return -1; if (n <= -1) return -1;