cleaned up code

This commit is contained in:
hyung-hwan 2009-07-19 06:02:24 +00:00
parent 07af9f53fb
commit 35e65743ab
8 changed files with 399 additions and 690 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c 238 2009-07-17 12:42:02Z hyunghwan.chung $
* $Id: awk.c 239 2009-07-18 12:02:24Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -339,6 +339,7 @@ struct opttab_t
{ QSE_T("rexbound"), QSE_AWK_REXBOUND, QSE_T("enable {n,m} in a regular expression") },
{ QSE_T("ncmponstr"), QSE_AWK_NCMPONSTR, QSE_T("perform numeric comparsion on numeric strings") },
{ QSE_T("strictnaming"), QSE_AWK_STRICTNAMING, QSE_T("enable the strict naming rule") },
{ QSE_T("include"), QSE_AWK_INCLUDE, QSE_T("enable 'include'") },
{ QSE_NULL, 0 }
};
@ -384,6 +385,7 @@ static int comparg (int argc, qse_char_t* argv[], struct arg_t* arg)
{ QSE_T(":rexbound"), QSE_T('\0') },
{ QSE_T(":ncmponstr"), QSE_T('\0') },
{ QSE_T(":strictnaming"), QSE_T('\0') },
{ QSE_T(":include"), QSE_T('\0') },
{ QSE_T(":call"), QSE_T('c') },
{ QSE_T(":file"), QSE_T('f') },

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp 238 2009-07-17 12:42:02Z hyunghwan.chung $
* $Id: Awk.hpp 239 2009-07-18 12:02:24Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -873,7 +873,10 @@ public:
* - 9 is greater if #QSE_AWK_NCMPONSTR is off;
* - "10.9" is greater if #QSE_AWK_NCMPONSTR is on
*/
OPT_NCMPONSTR = QSE_AWK_NCMPONSTR
OPT_NCMPONSTR = QSE_AWK_NCMPONSTR,
/** Enables 'include' */
OPT_INCLUDE = QSE_AWK_INCLUDE
};
/** Gets the option */
int getOption () const;
@ -991,28 +994,20 @@ public:
*/
/*@{*/
int getWord (
const char_t* ow, qse_size_t owl,
const char_t** nw, qse_size_t* nwl
const cstr_t* ow,
cstr_t* nw
);
int setWord (
const char_t* ow, const char_t* nw
);
int setWord (
const char_t* ow, qse_size_t owl,
const char_t* nw, qse_size_t nwl
const cstr_t* ow,
const cstr_t* nw
);
int unsetWord (
const char_t* ow
const cstr_t* ow
);
int unsetWord (
const char_t* ow, qse_size_t owl
);
int unsetAllWords ();
void unsetAllWords ();
/*@}*/
protected:

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 238 2009-07-17 12:42:02Z hyunghwan.chung $
* $Id: awk.h 239 2009-07-18 12:02:24Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -574,6 +574,11 @@ enum qse_awk_option_t
*/
QSE_AWK_STRICTNAMING = (1 << 15),
/**
* supports file inclusion by enabling a keyword 'include'
*/
QSE_AWK_INCLUDE = (1 << 16),
/**
* makes #qse_awk_t to behave as compatibly as classical AWK
* implementations
@ -1060,16 +1065,13 @@ void qse_awk_setmaxdepth (
int qse_awk_getword (
qse_awk_t* awk,
const qse_char_t* okw,
qse_size_t olen,
const qse_char_t** nkw,
qse_size_t* nlen
const qse_cstr_t* okw,
qse_cstr_t* nkw
);
int qse_awk_unsetword (
qse_awk_t* awk,
const qse_char_t* kw,
qse_size_t len
const qse_cstr_t* kw
);
void qse_awk_unsetallwords (
@ -1089,16 +1091,9 @@ void qse_awk_unsetallwords (
* @return 0 on success, -1 on failure
*/
int qse_awk_setword (
/* the pointer to a qse_awk_t instance */
qse_awk_t* awk,
/* the pointer to an old keyword */
const qse_char_t* okw,
/* the length of the old keyword */
qse_size_t olen,
/* the pointer to an new keyword */
const qse_char_t* nkw,
/* the length of the new keyword */
qse_size_t nlen
qse_awk_t* awk, /**< awk object */
const qse_cstr_t* okw, /**< old keyword */
const qse_cstr_t* nkw /**< new keyword */
);
/**

View File

@ -1,5 +1,5 @@
/*
* $Id: std.h 232 2009-07-14 08:06:14Z hyunghwan.chung $
* $Id: std.h 239 2009-07-18 12:02:24Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -34,6 +34,7 @@
* - add code to treat a function as a value
* - add RQ and LQ for more powerful record splitting
* - improve performance in qse_awk_rtx_readio() if RS is logner than 2 chars.
* - implement 'include'
*/
/**

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp 236 2009-07-16 08:27:53Z hyunghwan.chung $
* $Id: Awk.cpp 239 2009-07-18 12:02:24Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -1579,42 +1579,28 @@ int Awk::deleteFunction (const char_t* name)
return n;
}
int Awk::getWord (
const char_t* ow, qse_size_t owl,
const char_t** nw, qse_size_t* nwl)
int Awk::getWord (const cstr_t* ow, cstr_t* nw)
{
QSE_ASSERT (awk != QSE_NULL);
return qse_awk_getword (awk, ow, owl, nw, nwl);
return qse_awk_getword (awk, ow, nw);
}
int Awk::setWord (const char_t* ow, const char_t* nw)
{
return setWord (ow, qse_strlen(ow), nw, qse_strlen(nw));
}
int Awk::setWord (
const char_t* ow, qse_size_t owl,
const char_t* nw, qse_size_t nwl)
int Awk::setWord (const cstr_t* ow, const cstr_t* nw)
{
QSE_ASSERT (awk != QSE_NULL);
return qse_awk_setword (awk, ow, owl, nw, nwl);
return qse_awk_setword (awk, ow, nw);
}
int Awk::unsetWord (const char_t* ow)
{
return unsetWord (ow, qse_strlen(ow));
}
int Awk::unsetWord (const char_t* ow, qse_size_t owl)
int Awk::unsetWord (const cstr_t* w)
{
QSE_ASSERT (awk != QSE_NULL);
return qse_awk_setword (awk, ow, owl, QSE_NULL, 0);
return qse_awk_unsetword (awk, w);
}
int Awk::unsetAllWords ()
void Awk::unsetAllWords ()
{
QSE_ASSERT (awk != QSE_NULL);
return qse_awk_setword (awk, QSE_NULL, 0, QSE_NULL, 0);
qse_awk_unsetallwords (awk);
}
Awk::ssize_t Awk::readSource (

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c 232 2009-07-14 08:06:14Z hyunghwan.chung $
* $Id: awk.c 239 2009-07-18 12:02:24Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -27,14 +27,6 @@ QSE_IMPLEMENT_COMMON_FUNCTIONS (awk)
#define SETERR(awk,code) qse_awk_seterrnum(awk,code)
#define SETERRARG(awk,code,line,arg,leng) \
do { \
qse_cstr_t errarg; \
errarg.len = (leng); \
errarg.ptr = (arg); \
qse_awk_seterror ((awk), (code), (line), &errarg); \
} while (0)
static void free_fun (qse_map_t* map, void* vptr, qse_size_t vlen)
{
qse_awk_t* awk = *(qse_awk_t**)QSE_XTN(map);
@ -360,34 +352,34 @@ void qse_awk_stopall (qse_awk_t* awk)
awk->stopall = QSE_TRUE;
}
int qse_awk_getword (qse_awk_t* awk,
const qse_char_t* okw, qse_size_t olen,
const qse_char_t** nkw, qse_size_t* nlen)
int qse_awk_getword (qse_awk_t* awk, const qse_cstr_t* okw, qse_cstr_t* nkw)
{
qse_map_pair_t* p;
p = qse_map_search (awk->wtab, okw, olen);
p = qse_map_search (awk->wtab, okw->ptr, okw->len);
if (p == QSE_NULL) return -1;
*nkw = ((qse_cstr_t*)p->vptr)->ptr;
*nlen = ((qse_cstr_t*)p->vptr)->len;
nkw->ptr = ((qse_cstr_t*)p->vptr)->ptr;
nkw->len = ((qse_cstr_t*)p->vptr)->len;
return 0;
}
int qse_awk_unsetword (qse_awk_t* awk, const qse_char_t* kw, qse_size_t len)
int qse_awk_unsetword (qse_awk_t* awk, const qse_cstr_t* kw)
{
qse_map_pair_t* p;
p = qse_map_search (awk->wtab, kw, len);
QSE_ASSERT (kw->ptr != QSE_NULL);
p = qse_map_search (awk->wtab, kw->ptr, kw->len);
if (p == QSE_NULL)
{
SETERRARG (awk, QSE_AWK_ENOENT, 0, kw, len);
qse_awk_seterror (awk, QSE_AWK_ENOENT, 0, kw);
return -1;
}
qse_map_delete (awk->rwtab, QSE_MAP_VPTR(p), QSE_MAP_VLEN(p));
qse_map_delete (awk->wtab, kw, len);
qse_map_delete (awk->wtab, kw->ptr, kw->len);
return 0;
}
@ -397,39 +389,45 @@ void qse_awk_unsetallwords (qse_awk_t* awk)
qse_map_clear (awk->rwtab);
}
int qse_awk_setword (qse_awk_t* awk,
const qse_char_t* okw, qse_size_t olen,
const qse_char_t* nkw, qse_size_t nlen)
int qse_awk_setword (
qse_awk_t* awk, const qse_cstr_t* okw, const qse_cstr_t* nkw)
{
if (nkw == QSE_NULL || nlen == 0)
if (nkw == QSE_NULL)
{
if (okw == QSE_NULL || olen == 0)
if (okw == QSE_NULL)
{
/* clear the entire table */
qse_awk_unsetallwords (awk);
return 0;
}
return qse_awk_unsetword (awk, okw, olen);
return qse_awk_unsetword (awk, okw);
}
else if (okw == QSE_NULL || olen == 0)
else if (okw == QSE_NULL)
{
SETERR (awk, QSE_AWK_EINVAL);
return -1;
}
QSE_ASSERT (okw->ptr != QSE_NULL);
QSE_ASSERT (nkw->ptr != QSE_NULL);
/* set the word */
if (qse_map_upsert (awk->wtab,
(qse_char_t*)okw, olen, (qse_char_t*)nkw, nlen) == QSE_NULL)
if (qse_map_upsert (
awk->wtab,
(qse_char_t*)okw->ptr, okw->len,
(qse_char_t*)nkw->ptr, nkw->len) == QSE_NULL)
{
SETERR (awk, QSE_AWK_ENOMEM);
return -1;
}
if (qse_map_upsert (awk->rwtab,
(qse_char_t*)nkw, nlen, (qse_char_t*)okw, olen) == QSE_NULL)
if (qse_map_upsert (
awk->rwtab,
(qse_char_t*)nkw->ptr, nkw->len,
(qse_char_t*)okw->ptr, okw->len) == QSE_NULL)
{
qse_map_delete (awk->wtab, okw, olen);
qse_map_delete (awk->wtab, okw->ptr, okw->len);
SETERR (awk, QSE_AWK_ENOMEM);
return -1;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* $Id: parse.h 75 2009-02-22 14:10:34Z hyunghwan.chung $
* $Id: parse.h 239 2009-07-18 12:02:24Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -36,6 +36,7 @@ enum kw_t
KW_GLOBAL,
KW_IF,
KW_IN,
KW_INCLUDE,
KW_LOCAL,
KW_NEXT,
KW_NEXTFILE,