renamed QSE_AWK_EXTRAKWS to QSE_AWK_NEXTOFILE
fixed a minor glitch in qse_pio_t fixed the nil field to xnil in qse_rbt_t to minimize collision with external header files since nil is a commonly found macro added a simple optimization to qse_memcpy()
This commit is contained in:
@ -107,14 +107,18 @@ enum tok_t
|
||||
TOK_ATSIGN,
|
||||
|
||||
/* == begin reserved words == */
|
||||
/* === extended reserved words === */
|
||||
TOK_XGLOBAL,
|
||||
TOK_XLOCAL,
|
||||
TOK_XINCLUDE,
|
||||
TOK_XABORT,
|
||||
TOK_XRESET,
|
||||
|
||||
/* === normal reserved words === */
|
||||
TOK_BEGIN,
|
||||
TOK_END,
|
||||
TOK_FUNCTION,
|
||||
|
||||
TOK_XLOCAL,
|
||||
TOK_XGLOBAL,
|
||||
TOK_XINCLUDE,
|
||||
|
||||
TOK_IF,
|
||||
TOK_ELSE,
|
||||
TOK_WHILE,
|
||||
@ -124,15 +128,13 @@ enum tok_t
|
||||
TOK_CONTINUE,
|
||||
TOK_RETURN,
|
||||
TOK_EXIT,
|
||||
TOK_XABORT,
|
||||
TOK_DELETE,
|
||||
TOK_NEXT,
|
||||
TOK_NEXTFILE,
|
||||
TOK_NEXTOFILE,
|
||||
TOK_DELETE,
|
||||
TOK_XRESET,
|
||||
|
||||
TOK_PRINT,
|
||||
TOK_PRINTF,
|
||||
|
||||
TOK_GETLINE,
|
||||
/* == end reserved words == */
|
||||
|
||||
@ -292,7 +294,7 @@ static kwent_t kwtab[] =
|
||||
{ { QSE_T("in"), 2 }, TOK_IN, 0 },
|
||||
{ { QSE_T("next"), 4 }, TOK_NEXT, QSE_AWK_PABLOCK },
|
||||
{ { QSE_T("nextfile"), 8 }, TOK_NEXTFILE, QSE_AWK_PABLOCK },
|
||||
{ { QSE_T("nextofile"), 9 }, TOK_NEXTOFILE, QSE_AWK_PABLOCK | QSE_AWK_EXTRAKWS },
|
||||
{ { QSE_T("nextofile"), 9 }, TOK_NEXTOFILE, QSE_AWK_PABLOCK | QSE_AWK_NEXTOFILE },
|
||||
{ { QSE_T("print"), 5 }, TOK_PRINT, QSE_AWK_RIO },
|
||||
{ { QSE_T("printf"), 6 }, TOK_PRINTF, QSE_AWK_RIO },
|
||||
{ { QSE_T("return"), 6 }, TOK_RETURN, 0 },
|
||||
@ -310,6 +312,10 @@ struct global_t
|
||||
|
||||
static global_t gtab[] =
|
||||
{
|
||||
/*
|
||||
* this table must match the order of the qse_awk_gbl_id_t enumerators
|
||||
*/
|
||||
|
||||
/* output real-to-str conversion format for other cases than 'print' */
|
||||
{ QSE_T("CONVFMT"), 7, 0 },
|
||||
|
||||
@ -334,7 +340,7 @@ static global_t gtab[] =
|
||||
{ QSE_T("NR"), 2, QSE_AWK_PABLOCK },
|
||||
|
||||
/* current output file name */
|
||||
{ QSE_T("OFILENAME"), 9, QSE_AWK_PABLOCK | QSE_AWK_EXTRAKWS },
|
||||
{ QSE_T("OFILENAME"), 9, QSE_AWK_PABLOCK | QSE_AWK_NEXTOFILE },
|
||||
|
||||
/* output real-to-str conversion format for 'print' */
|
||||
{ QSE_T("OFMT"), 4, QSE_AWK_RIO },
|
||||
@ -4741,6 +4747,11 @@ static int dup_ident_and_get_next (
|
||||
|
||||
if (get_token(awk) <= -1) goto oops;
|
||||
|
||||
/* the identifier after ::
|
||||
* allow reserved words as well since i view the whole name(mod::ident)
|
||||
* as one segment. however, i don't want the identifier part to begin
|
||||
* with @. some extended keywords begin with @ like @include.
|
||||
* TOK_XGLOBAL to TOK_XRESET are excuded from the check for that reason. */
|
||||
if (!MATCH(awk, TOK_IDENT) && !(MATCH_RANGE(awk, TOK_BEGIN, TOK_GETLINE)))
|
||||
{
|
||||
SETERR_TOK (awk, QSE_AWK_EIDENT);
|
||||
|
@ -666,7 +666,7 @@ int qse_awk_rtx_setofilename (
|
||||
qse_awk_val_t* tmp;
|
||||
int n;
|
||||
|
||||
if (rtx->awk->opt.trait & QSE_AWK_EXTRAKWS)
|
||||
if (rtx->awk->opt.trait & QSE_AWK_NEXTOFILE)
|
||||
{
|
||||
if (len == 0) tmp = qse_awk_val_zls;
|
||||
else
|
||||
|
@ -84,6 +84,25 @@ void* qse_memcpy (void* dst, const void* src, qse_size_t n)
|
||||
qse_byte_t* d;
|
||||
qse_byte_t* s;
|
||||
|
||||
if (n < 8)
|
||||
{
|
||||
d = (qse_byte_t*)dst;
|
||||
s = (qse_byte_t*)src;
|
||||
|
||||
switch (n)
|
||||
{
|
||||
case 7: *d++ = *s++;
|
||||
case 6: *d++ = *s++;
|
||||
case 5: *d++ = *s++;
|
||||
case 4: *d++ = *s++;
|
||||
case 3: *d++ = *s++;
|
||||
case 2: *d++ = *s++;
|
||||
case 1: *d++ = *s++;
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
if (n >= QSE_SIZEOF(qse_size_t) && IS_BOTH_ALIGNED(dst,src))
|
||||
{
|
||||
qse_size_t* du = (qse_size_t*)dst;
|
||||
|
@ -1264,7 +1264,7 @@ create_process:
|
||||
if (!(flags & QSE_PIO_NOCLOEXEC))
|
||||
{
|
||||
int fd = get_highest_fd ();
|
||||
while (--fd > 2)
|
||||
while (fd > 2)
|
||||
{
|
||||
if (fd == handle[0] || fd == handle[1] ||
|
||||
fd == handle[2] || fd == handle[3] ||
|
||||
@ -1280,6 +1280,7 @@ create_process:
|
||||
pio->errnum = syserr_to_errnum (pserr);
|
||||
goto oops;
|
||||
}
|
||||
fd--;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1419,7 +1420,7 @@ create_process:
|
||||
|
||||
/* close all other unknown open handles except
|
||||
* stdin/out/err and the pipes. */
|
||||
while (--fd > 2)
|
||||
while (fd > 2)
|
||||
{
|
||||
if (fd != handle[0] && fd != handle[1] &&
|
||||
fd != handle[2] && fd != handle[3] &&
|
||||
@ -1427,6 +1428,7 @@ create_process:
|
||||
{
|
||||
QSE_SYSCALL1 (dummy, SYS_close, fd);
|
||||
}
|
||||
fd--;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1610,7 +1612,7 @@ create_process:
|
||||
|
||||
/* close all other unknown open handles except
|
||||
* stdin/out/err and the pipes. */
|
||||
while (--fd > 2)
|
||||
while (fd > 2)
|
||||
{
|
||||
if (fd != handle[0] && fd != handle[1] &&
|
||||
fd != handle[2] && fd != handle[3] &&
|
||||
@ -1618,6 +1620,7 @@ create_process:
|
||||
{
|
||||
QSE_CLOSE (fd);
|
||||
}
|
||||
fd--;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@
|
||||
#define ENSERT 3
|
||||
#define INSERT 4
|
||||
|
||||
#define IS_NIL(rbt,x) ((x) == &((rbt)->nil))
|
||||
#define IS_NIL(rbt,x) ((x) == &((rbt)->xnil))
|
||||
#define LEFT 0
|
||||
#define RIGHT 1
|
||||
#define left child[LEFT]
|
||||
@ -76,8 +76,8 @@ QSE_INLINE pair_t* qse_rbt_allocpair (
|
||||
|
||||
n->color = QSE_RBT_RED;
|
||||
n->parent = QSE_NULL;
|
||||
n->child[LEFT] = &rbt->nil;
|
||||
n->child[RIGHT] = &rbt->nil;
|
||||
n->child[LEFT] = &rbt->xnil;
|
||||
n->child[RIGHT] = &rbt->xnil;
|
||||
|
||||
KLEN(n) = klen;
|
||||
if (kcop == QSE_RBT_COPIER_SIMPLE)
|
||||
@ -231,13 +231,13 @@ int qse_rbt_init (rbt_t* rbt, mmgr_t* mmgr, int kscale, int vscale)
|
||||
rbt->mancbs = &mancbs[0];
|
||||
|
||||
/* self-initializing nil */
|
||||
QSE_MEMSET(&rbt->nil, 0, QSE_SIZEOF(rbt->nil));
|
||||
rbt->nil.color = QSE_RBT_BLACK;
|
||||
rbt->nil.left = &rbt->nil;
|
||||
rbt->nil.right = &rbt->nil;
|
||||
QSE_MEMSET(&rbt->xnil, 0, QSE_SIZEOF(rbt->xnil));
|
||||
rbt->xnil.color = QSE_RBT_BLACK;
|
||||
rbt->xnil.left = &rbt->xnil;
|
||||
rbt->xnil.right = &rbt->xnil;
|
||||
|
||||
/* root is set to nil initially */
|
||||
rbt->root = &rbt->nil;
|
||||
rbt->root = &rbt->xnil;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -546,7 +546,7 @@ static pair_t* insert (
|
||||
if (x_par == QSE_NULL)
|
||||
{
|
||||
/* the tree contains no pair */
|
||||
QSE_ASSERT (rbt->root == &rbt->nil);
|
||||
QSE_ASSERT (rbt->root == &rbt->xnil);
|
||||
rbt->root = x_new;
|
||||
}
|
||||
else
|
||||
@ -555,12 +555,12 @@ static pair_t* insert (
|
||||
int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(x_par), KLEN(x_par));
|
||||
if (n > 0)
|
||||
{
|
||||
QSE_ASSERT (x_par->right == &rbt->nil);
|
||||
QSE_ASSERT (x_par->right == &rbt->xnil);
|
||||
x_par->right = x_new;
|
||||
}
|
||||
else
|
||||
{
|
||||
QSE_ASSERT (x_par->left == &rbt->nil);
|
||||
QSE_ASSERT (x_par->left == &rbt->xnil);
|
||||
x_par->left = x_new;
|
||||
}
|
||||
|
||||
@ -666,7 +666,7 @@ pair_t* qse_rbt_cbsert (
|
||||
if (x_par == QSE_NULL)
|
||||
{
|
||||
/* the tree contains no pair */
|
||||
QSE_ASSERT (rbt->root == &rbt->nil);
|
||||
QSE_ASSERT (rbt->root == &rbt->xnil);
|
||||
rbt->root = x_new;
|
||||
}
|
||||
else
|
||||
@ -675,12 +675,12 @@ pair_t* qse_rbt_cbsert (
|
||||
int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(x_par), KLEN(x_par));
|
||||
if (n > 0)
|
||||
{
|
||||
QSE_ASSERT (x_par->right == &rbt->nil);
|
||||
QSE_ASSERT (x_par->right == &rbt->xnil);
|
||||
x_par->right = x_new;
|
||||
}
|
||||
else
|
||||
{
|
||||
QSE_ASSERT (x_par->left == &rbt->nil);
|
||||
QSE_ASSERT (x_par->left == &rbt->xnil);
|
||||
x_par->left = x_new;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user