cleaned up code
This commit is contained in:
parent
07af9f53fb
commit
35e65743ab
@ -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.
|
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("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("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("strictnaming"), QSE_AWK_STRICTNAMING, QSE_T("enable the strict naming rule") },
|
||||||
|
{ QSE_T("include"), QSE_AWK_INCLUDE, QSE_T("enable 'include'") },
|
||||||
{ QSE_NULL, 0 }
|
{ 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(":rexbound"), QSE_T('\0') },
|
||||||
{ QSE_T(":ncmponstr"), QSE_T('\0') },
|
{ QSE_T(":ncmponstr"), QSE_T('\0') },
|
||||||
{ QSE_T(":strictnaming"), QSE_T('\0') },
|
{ QSE_T(":strictnaming"), QSE_T('\0') },
|
||||||
|
{ QSE_T(":include"), QSE_T('\0') },
|
||||||
|
|
||||||
{ QSE_T(":call"), QSE_T('c') },
|
{ QSE_T(":call"), QSE_T('c') },
|
||||||
{ QSE_T(":file"), QSE_T('f') },
|
{ QSE_T(":file"), QSE_T('f') },
|
||||||
|
@ -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.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -873,7 +873,10 @@ public:
|
|||||||
* - 9 is greater if #QSE_AWK_NCMPONSTR is off;
|
* - 9 is greater if #QSE_AWK_NCMPONSTR is off;
|
||||||
* - "10.9" is greater if #QSE_AWK_NCMPONSTR is on
|
* - "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 */
|
/** Gets the option */
|
||||||
int getOption () const;
|
int getOption () const;
|
||||||
@ -991,28 +994,20 @@ public:
|
|||||||
*/
|
*/
|
||||||
/*@{*/
|
/*@{*/
|
||||||
int getWord (
|
int getWord (
|
||||||
const char_t* ow, qse_size_t owl,
|
const cstr_t* ow,
|
||||||
const char_t** nw, qse_size_t* nwl
|
cstr_t* nw
|
||||||
);
|
);
|
||||||
|
|
||||||
int setWord (
|
int setWord (
|
||||||
const char_t* ow, const char_t* nw
|
const cstr_t* ow,
|
||||||
);
|
const cstr_t* nw
|
||||||
|
|
||||||
int setWord (
|
|
||||||
const char_t* ow, qse_size_t owl,
|
|
||||||
const char_t* nw, qse_size_t nwl
|
|
||||||
);
|
);
|
||||||
|
|
||||||
int unsetWord (
|
int unsetWord (
|
||||||
const char_t* ow
|
const cstr_t* ow
|
||||||
);
|
);
|
||||||
|
|
||||||
int unsetWord (
|
void unsetAllWords ();
|
||||||
const char_t* ow, qse_size_t owl
|
|
||||||
);
|
|
||||||
|
|
||||||
int unsetAllWords ();
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -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.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -574,6 +574,11 @@ enum qse_awk_option_t
|
|||||||
*/
|
*/
|
||||||
QSE_AWK_STRICTNAMING = (1 << 15),
|
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
|
* makes #qse_awk_t to behave as compatibly as classical AWK
|
||||||
* implementations
|
* implementations
|
||||||
@ -1059,17 +1064,14 @@ void qse_awk_setmaxdepth (
|
|||||||
);
|
);
|
||||||
|
|
||||||
int qse_awk_getword (
|
int qse_awk_getword (
|
||||||
qse_awk_t* awk,
|
qse_awk_t* awk,
|
||||||
const qse_char_t* okw,
|
const qse_cstr_t* okw,
|
||||||
qse_size_t olen,
|
qse_cstr_t* nkw
|
||||||
const qse_char_t** nkw,
|
|
||||||
qse_size_t* nlen
|
|
||||||
);
|
);
|
||||||
|
|
||||||
int qse_awk_unsetword (
|
int qse_awk_unsetword (
|
||||||
qse_awk_t* awk,
|
qse_awk_t* awk,
|
||||||
const qse_char_t* kw,
|
const qse_cstr_t* kw
|
||||||
qse_size_t len
|
|
||||||
);
|
);
|
||||||
|
|
||||||
void qse_awk_unsetallwords (
|
void qse_awk_unsetallwords (
|
||||||
@ -1089,16 +1091,9 @@ void qse_awk_unsetallwords (
|
|||||||
* @return 0 on success, -1 on failure
|
* @return 0 on success, -1 on failure
|
||||||
*/
|
*/
|
||||||
int qse_awk_setword (
|
int qse_awk_setword (
|
||||||
/* the pointer to a qse_awk_t instance */
|
qse_awk_t* awk, /**< awk object */
|
||||||
qse_awk_t* awk,
|
const qse_cstr_t* okw, /**< old keyword */
|
||||||
/* the pointer to an old keyword */
|
const qse_cstr_t* nkw /**< new 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
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -34,6 +34,7 @@
|
|||||||
* - add code to treat a function as a value
|
* - add code to treat a function as a value
|
||||||
* - add RQ and LQ for more powerful record splitting
|
* - add RQ and LQ for more powerful record splitting
|
||||||
* - improve performance in qse_awk_rtx_readio() if RS is logner than 2 chars.
|
* - improve performance in qse_awk_rtx_readio() if RS is logner than 2 chars.
|
||||||
|
* - implement 'include'
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -1579,42 +1579,28 @@ int Awk::deleteFunction (const char_t* name)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Awk::getWord (
|
int Awk::getWord (const cstr_t* ow, cstr_t* nw)
|
||||||
const char_t* ow, qse_size_t owl,
|
|
||||||
const char_t** nw, qse_size_t* nwl)
|
|
||||||
{
|
{
|
||||||
QSE_ASSERT (awk != QSE_NULL);
|
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)
|
int Awk::setWord (const cstr_t* ow, const cstr_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)
|
|
||||||
{
|
{
|
||||||
QSE_ASSERT (awk != QSE_NULL);
|
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)
|
int Awk::unsetWord (const cstr_t* w)
|
||||||
{
|
|
||||||
return unsetWord (ow, qse_strlen(ow));
|
|
||||||
}
|
|
||||||
|
|
||||||
int Awk::unsetWord (const char_t* ow, qse_size_t owl)
|
|
||||||
{
|
{
|
||||||
QSE_ASSERT (awk != QSE_NULL);
|
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);
|
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 (
|
Awk::ssize_t Awk::readSource (
|
||||||
|
@ -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.
|
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 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)
|
static void free_fun (qse_map_t* map, void* vptr, qse_size_t vlen)
|
||||||
{
|
{
|
||||||
qse_awk_t* awk = *(qse_awk_t**)QSE_XTN(map);
|
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;
|
awk->stopall = QSE_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int qse_awk_getword (qse_awk_t* awk,
|
int qse_awk_getword (qse_awk_t* awk, const qse_cstr_t* okw, qse_cstr_t* nkw)
|
||||||
const qse_char_t* okw, qse_size_t olen,
|
|
||||||
const qse_char_t** nkw, qse_size_t* nlen)
|
|
||||||
{
|
{
|
||||||
qse_map_pair_t* p;
|
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;
|
if (p == QSE_NULL) return -1;
|
||||||
|
|
||||||
*nkw = ((qse_cstr_t*)p->vptr)->ptr;
|
nkw->ptr = ((qse_cstr_t*)p->vptr)->ptr;
|
||||||
*nlen = ((qse_cstr_t*)p->vptr)->len;
|
nkw->len = ((qse_cstr_t*)p->vptr)->len;
|
||||||
|
|
||||||
return 0;
|
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;
|
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)
|
if (p == QSE_NULL)
|
||||||
{
|
{
|
||||||
SETERRARG (awk, QSE_AWK_ENOENT, 0, kw, len);
|
qse_awk_seterror (awk, QSE_AWK_ENOENT, 0, kw);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
qse_map_delete (awk->rwtab, QSE_MAP_VPTR(p), QSE_MAP_VLEN(p));
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,39 +389,45 @@ void qse_awk_unsetallwords (qse_awk_t* awk)
|
|||||||
qse_map_clear (awk->rwtab);
|
qse_map_clear (awk->rwtab);
|
||||||
}
|
}
|
||||||
|
|
||||||
int qse_awk_setword (qse_awk_t* awk,
|
int qse_awk_setword (
|
||||||
const qse_char_t* okw, qse_size_t olen,
|
qse_awk_t* awk, const qse_cstr_t* okw, const qse_cstr_t* nkw)
|
||||||
const qse_char_t* nkw, qse_size_t nlen)
|
|
||||||
{
|
{
|
||||||
if (nkw == QSE_NULL || nlen == 0)
|
if (nkw == QSE_NULL)
|
||||||
{
|
{
|
||||||
if (okw == QSE_NULL || olen == 0)
|
if (okw == QSE_NULL)
|
||||||
{
|
{
|
||||||
/* clear the entire table */
|
/* clear the entire table */
|
||||||
qse_awk_unsetallwords (awk);
|
qse_awk_unsetallwords (awk);
|
||||||
return 0;
|
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);
|
SETERR (awk, QSE_AWK_EINVAL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSE_ASSERT (okw->ptr != QSE_NULL);
|
||||||
|
QSE_ASSERT (nkw->ptr != QSE_NULL);
|
||||||
|
|
||||||
/* set the word */
|
/* set the word */
|
||||||
if (qse_map_upsert (awk->wtab,
|
if (qse_map_upsert (
|
||||||
(qse_char_t*)okw, olen, (qse_char_t*)nkw, nlen) == QSE_NULL)
|
awk->wtab,
|
||||||
|
(qse_char_t*)okw->ptr, okw->len,
|
||||||
|
(qse_char_t*)nkw->ptr, nkw->len) == QSE_NULL)
|
||||||
{
|
{
|
||||||
SETERR (awk, QSE_AWK_ENOMEM);
|
SETERR (awk, QSE_AWK_ENOMEM);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qse_map_upsert (awk->rwtab,
|
if (qse_map_upsert (
|
||||||
(qse_char_t*)nkw, nlen, (qse_char_t*)okw, olen) == QSE_NULL)
|
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);
|
SETERR (awk, QSE_AWK_ENOMEM);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -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.
|
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||||
|
|
||||||
@ -36,6 +36,7 @@ enum kw_t
|
|||||||
KW_GLOBAL,
|
KW_GLOBAL,
|
||||||
KW_IF,
|
KW_IF,
|
||||||
KW_IN,
|
KW_IN,
|
||||||
|
KW_INCLUDE,
|
||||||
KW_LOCAL,
|
KW_LOCAL,
|
||||||
KW_NEXT,
|
KW_NEXT,
|
||||||
KW_NEXTFILE,
|
KW_NEXTFILE,
|
||||||
|
Loading…
Reference in New Issue
Block a user