added qse_awk_getxtnstd() and enhanced qse_awk_openstd()

This commit is contained in:
hyung-hwan 2009-02-27 04:56:12 +00:00
parent 58a47ba425
commit 651f6d2dfa
12 changed files with 136 additions and 74 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c 76 2009-02-22 14:18:06Z hyunghwan.chung $ * $Id: awk.c 85 2009-02-26 10:56:12Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -549,7 +549,7 @@ static qse_awk_t* open_awk (void)
{ {
qse_awk_t* awk; qse_awk_t* awk;
awk = qse_awk_openstd (); awk = qse_awk_openstd (0);
if (awk == QSE_NULL) if (awk == QSE_NULL)
{ {
qse_printf (QSE_T("ERROR: cannot open awk\n")); qse_printf (QSE_T("ERROR: cannot open awk\n"));

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.h 79 2009-02-24 03:57:28Z hyunghwan.chung $ * $Id: awk.h 85 2009-02-26 10:56:12Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -49,9 +49,6 @@ typedef struct qse_awk_t qse_awk_t;
typedef struct qse_awk_rtx_t qse_awk_rtx_t; /* (R)untime con(T)e(X)t */ typedef struct qse_awk_rtx_t qse_awk_rtx_t; /* (R)untime con(T)e(X)t */
/******/ /******/
/* this is not a value. it is just a value holder */
typedef struct qse_awk_val_chunk_t qse_awk_val_chunk_t;
#if QSE_SIZEOF_INT == 2 #if QSE_SIZEOF_INT == 2
# define QSE_AWK_VAL_HDR \ # define QSE_AWK_VAL_HDR \
unsigned int type: 3; \ unsigned int type: 3; \
@ -181,11 +178,6 @@ struct qse_awk_val_ref_t
}; };
typedef struct qse_awk_val_ref_t qse_awk_val_ref_t; typedef struct qse_awk_val_ref_t qse_awk_val_ref_t;
typedef struct qse_awk_prm_t qse_awk_prm_t;
typedef struct qse_awk_sio_t qse_awk_sio_t;
typedef struct qse_awk_rio_t qse_awk_rio_t;
typedef struct qse_awk_riod_t qse_awk_riod_t;
typedef struct qse_awk_rcb_t qse_awk_rcb_t;
typedef qse_real_t (*qse_awk_pow_t) ( typedef qse_real_t (*qse_awk_pow_t) (
qse_awk_t* awk, qse_awk_t* awk,
@ -213,6 +205,11 @@ typedef qse_cint_t (*qse_awk_toccls_t) (
qse_ccls_id_t type qse_ccls_id_t type
); );
/****e* AWK/qse_awk_sio_cmd_t
* NAME
* qse_awk_sio_cmd_t - define source IO commands
* SYNOPSIS
*/
enum qse_awk_sio_cmd_t enum qse_awk_sio_cmd_t
{ {
QSE_AWK_SIO_OPEN = 0, QSE_AWK_SIO_OPEN = 0,
@ -220,8 +217,8 @@ enum qse_awk_sio_cmd_t
QSE_AWK_SIO_READ = 2, QSE_AWK_SIO_READ = 2,
QSE_AWK_SIO_WRITE = 3 QSE_AWK_SIO_WRITE = 3
}; };
typedef enum qse_awk_sio_cmd_t qse_awk_sio_cmd_t; typedef enum qse_awk_sio_cmd_t qse_awk_sio_cmd_t;
/******/
/****t* AWK/qse_awk_siof_t /****t* AWK/qse_awk_siof_t
* NAME * NAME
@ -245,23 +242,8 @@ enum qse_awk_rio_cmd_t
QSE_AWK_RIO_FLUSH = 4, QSE_AWK_RIO_FLUSH = 4,
QSE_AWK_RIO_NEXT = 5 QSE_AWK_RIO_NEXT = 5
}; };
typedef enum qse_awk_rio_cmd_t qse_awk_rio_cmd_t; typedef enum qse_awk_rio_cmd_t qse_awk_rio_cmd_t;
/****f* AWK/qse_awk_riof_t
* NAME
* qse_awk_riof_t - define a runtime IO function
* SYNOPSIS
*/
typedef qse_ssize_t (*qse_awk_riof_t) (
qse_awk_rtx_t* rtx,
qse_awk_rio_cmd_t cmd,
qse_awk_riod_t* riod,
qse_char_t* data,
qse_size_t count
);
/******/
/****f* AWK/qse_awk_riod_t /****f* AWK/qse_awk_riod_t
* NAME * NAME
* qse_awk_riod_f - define the data passed to a rio function * qse_awk_riod_f - define the data passed to a rio function
@ -291,10 +273,31 @@ struct qse_awk_riod_t
qse_bool_t eos; qse_bool_t eos;
} out; } out;
qse_awk_riod_t* next; struct qse_awk_riod_t* next;
}; };
typedef struct qse_awk_riod_t qse_awk_riod_t;
/******/ /******/
/****f* AWK/qse_awk_riof_t
* NAME
* qse_awk_riof_t - define a runtime IO function
* SYNOPSIS
*/
typedef qse_ssize_t (*qse_awk_riof_t) (
qse_awk_rtx_t* rtx,
qse_awk_rio_cmd_t cmd,
qse_awk_riod_t* riod,
qse_char_t* data,
qse_size_t count
);
/******/
/****s* AWK/qse_awk_prm_t
* NAME
* qse_awk_prm_t - define primitive functions
* SYNOPSIS
*/
struct qse_awk_prm_t struct qse_awk_prm_t
{ {
qse_awk_pow_t pow; qse_awk_pow_t pow;
@ -333,20 +336,41 @@ struct qse_awk_prm_t
); );
#endif #endif
}; };
typedef struct qse_awk_prm_t qse_awk_prm_t;
/******/
/****s* AWK/qse_awk_sio_t
* NAME
* qse_awk_sio_t - define source code IO
* SYNOPSIS
*/
struct qse_awk_sio_t struct qse_awk_sio_t
{ {
qse_awk_siof_t in; qse_awk_siof_t in;
qse_awk_siof_t out; qse_awk_siof_t out;
}; };
typedef struct qse_awk_sio_t qse_awk_sio_t;
/******/
/****s* AWK/qse_awk_rio_t
* NAME
* qse_awk_rio_t - define runtime IO
* SYNOPSIS
*/
struct qse_awk_rio_t struct qse_awk_rio_t
{ {
qse_awk_riof_t pipe; qse_awk_riof_t pipe;
qse_awk_riof_t file; qse_awk_riof_t file;
qse_awk_riof_t console; qse_awk_riof_t console;
}; };
typedef struct qse_awk_rio_t qse_awk_rio_t;
/******/
/****s* AWK/qse_awk_rcb_t
* NAME
* qse_awk_rcb_t - define runtime callbacks
* SYNOPSIS
*/
struct qse_awk_rcb_t struct qse_awk_rcb_t
{ {
int (*on_enter) ( int (*on_enter) (
@ -360,6 +384,8 @@ struct qse_awk_rcb_t
void* data; void* data;
}; };
typedef struct qse_awk_rcb_t qse_awk_rcb_t;
/******/
/* various options */ /* various options */
enum qse_awk_option_t enum qse_awk_option_t

View File

@ -1,5 +1,5 @@
/* /*
* $Id: std.h 84 2009-02-25 10:35:22Z hyunghwan.chung $ * $Id: std.h 85 2009-02-26 10:56:12Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -89,7 +89,17 @@ extern "C" {
* SYNOPSIS * SYNOPSIS
*/ */
qse_awk_t* qse_awk_openstd ( qse_awk_t* qse_awk_openstd (
void qse_size_t xtnsize
);
/******/
/****f* AWK/qse_awk_getxtnstd
* NAME
* qse_awk_getxtnstd - get the pointer to extension space
* SYNOPSIS
*/
void* qse_awk_getxtnstd (
qse_awk_t* awk
); );
/******/ /******/

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk.c 75 2009-02-22 14:10:34Z hyunghwan.chung $ * $Id: awk.c 85 2009-02-26 10:56:12Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -78,10 +78,20 @@ qse_awk_t* qse_awk_open (qse_mmgr_t* mmgr, qse_size_t xtn, qse_awk_prm_t* prm)
awk->mmgr = mmgr; awk->mmgr = mmgr;
/* progagate the primitive functions */ /* progagate the primitive functions */
QSE_ASSERT (prm != QSE_NULL);
QSE_ASSERT (prm->pow != QSE_NULL); QSE_ASSERT (prm->pow != QSE_NULL);
QSE_ASSERT (prm->sprintf != QSE_NULL); QSE_ASSERT (prm->sprintf != QSE_NULL);
QSE_ASSERT (prm->isccls != QSE_NULL); QSE_ASSERT (prm->isccls != QSE_NULL);
QSE_ASSERT (prm->toccls != QSE_NULL); QSE_ASSERT (prm->toccls != QSE_NULL);
if (prm == QSE_NULL ||
prm->pow == QSE_NULL ||
prm->sprintf == QSE_NULL ||
prm->isccls == QSE_NULL ||
prm->toccls == QSE_NULL)
{
QSE_AWK_FREE (awk, awk);
return QSE_NULL;
}
awk->prm = *prm; awk->prm = *prm;
/* build a character classifier from the primitive functions */ /* build a character classifier from the primitive functions */

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c 75 2009-02-22 14:10:34Z hyunghwan.chung $ * $Id: parse.c 85 2009-02-26 10:56:12Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -469,9 +469,16 @@ int qse_awk_parse (qse_awk_t* awk, qse_awk_sio_t* sio)
{ {
int n; int n;
QSE_ASSERTX ( QSE_ASSERTX (sio != QSE_NULL ,
sio != QSE_NULL && sio->in != QSE_NULL, "the source code istream must be provided");
QSE_ASSERTX (sio->in != QSE_NULL,
"the source code input stream must be provided at least"); "the source code input stream must be provided at least");
if (sio == QSE_NULL || sio->in == QSE_NULL)
{
SETERR (awk, QSE_AWK_EINVAL);
return -1;
}
QSE_ASSERT (awk->parse.depth.cur.loop == 0); QSE_ASSERT (awk->parse.depth.cur.loop == 0);
QSE_ASSERT (awk->parse.depth.cur.expr == 0); QSE_ASSERT (awk->parse.depth.cur.expr == 0);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: std.c 84 2009-02-25 10:35:22Z hyunghwan.chung $ * $Id: std.c 85 2009-02-26 10:56:12Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -138,7 +138,7 @@ static qse_cint_t custom_awk_toccls (
static int add_functions (qse_awk_t* awk); static int add_functions (qse_awk_t* awk);
qse_awk_t* qse_awk_openstd (void) qse_awk_t* qse_awk_openstd (qse_size_t xtnsize)
{ {
qse_awk_t* awk; qse_awk_t* awk;
qse_awk_prm_t prm; qse_awk_prm_t prm;
@ -150,7 +150,8 @@ qse_awk_t* qse_awk_openstd (void)
prm.toccls = custom_awk_toccls; prm.toccls = custom_awk_toccls;
/* create an object */ /* create an object */
awk = qse_awk_open (QSE_MMGR_GETDFL(), QSE_SIZEOF(xtn_t), &prm); awk = qse_awk_open (
QSE_MMGR_GETDFL(), QSE_SIZEOF(xtn_t) + xtnsize, &prm);
if (awk == QSE_NULL) return QSE_NULL; if (awk == QSE_NULL) return QSE_NULL;
/* initialize extension */ /* initialize extension */
@ -167,6 +168,11 @@ qse_awk_t* qse_awk_openstd (void)
return awk; return awk;
} }
void* qse_awk_getxtnstd (qse_awk_t* awk)
{
return (void*)((xtn_t*)QSE_XTN(awk) + 1);
}
/*** PARSESTD ***/ /*** PARSESTD ***/
static qse_ssize_t sf_in ( static qse_ssize_t sf_in (

View File

@ -1,5 +1,5 @@
/* /*
* $Id: val.c 78 2009-02-23 14:03:28Z hyunghwan.chung $ * $Id: val.c 85 2009-02-26 10:56:12Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -22,33 +22,7 @@
#include <qse/utl/stdio.h> #include <qse/utl/stdio.h>
#endif #endif
#define CHUNKSIZE 100 #define CHUNKSIZE QSE_AWK_VAL_CHUNK_SIZE
typedef struct qse_awk_val_ichunk_t qse_awk_val_ichunk_t;
typedef struct qse_awk_val_rchunk_t qse_awk_val_rchunk_t;
struct qse_awk_val_chunk_t
{
qse_awk_val_chunk_t* next;
};
struct qse_awk_val_ichunk_t
{
qse_awk_val_chunk_t* next;
/* make sure that it has the same fields as
qse_awk_val_chunk_t up to this point */
qse_awk_val_int_t slot[CHUNKSIZE];
};
struct qse_awk_val_rchunk_t
{
qse_awk_val_chunk_t* next;
/* make sure that it has the same fields as
qse_awk_val_chunk_t up to this point */
qse_awk_val_real_t slot[CHUNKSIZE];
};
static qse_char_t* str_to_str ( static qse_char_t* str_to_str (
qse_awk_rtx_t* run, const qse_char_t* str, qse_size_t str_len, qse_awk_rtx_t* run, const qse_char_t* str, qse_size_t str_len,

View File

@ -1,5 +1,5 @@
/* /*
* $Id: val.h 75 2009-02-22 14:10:34Z hyunghwan.chung $ * $Id: val.h 85 2009-02-26 10:56:12Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -19,6 +19,35 @@
#ifndef _QSE_LIB_AWK_VAL_H_ #ifndef _QSE_LIB_AWK_VAL_H_
#define _QSE_LIB_AWK_VAL_H_ #define _QSE_LIB_AWK_VAL_H_
#define QSE_AWK_VAL_CHUNK_SIZE 100
typedef struct qse_awk_val_chunk_t qse_awk_val_chunk_t;
typedef struct qse_awk_val_ichunk_t qse_awk_val_ichunk_t;
typedef struct qse_awk_val_rchunk_t qse_awk_val_rchunk_t;
struct qse_awk_val_chunk_t
{
qse_awk_val_chunk_t* next;
};
struct qse_awk_val_ichunk_t
{
qse_awk_val_chunk_t* next;
/* make sure that it has the same fields as
qse_awk_val_chunk_t up to this point */
qse_awk_val_int_t slot[QSE_AWK_VAL_CHUNK_SIZE];
};
struct qse_awk_val_rchunk_t
{
qse_awk_val_chunk_t* next;
/* make sure that it has the same fields as
qse_awk_val_chunk_t up to this point */
qse_awk_val_real_t slot[QSE_AWK_VAL_CHUNK_SIZE];
};
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk01.c 76 2009-02-22 14:18:06Z hyunghwan.chung $ * $Id: awk01.c 85 2009-02-26 10:56:12Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -44,7 +44,7 @@ int main ()
qse_awk_parsestd_in_t psin; qse_awk_parsestd_in_t psin;
int ret; int ret;
awk = qse_awk_openstd (); awk = qse_awk_openstd (0);
if (awk == QSE_NULL) if (awk == QSE_NULL)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n"));

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk02.c 76 2009-02-22 14:18:06Z hyunghwan.chung $ * $Id: awk02.c 85 2009-02-26 10:56:12Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -50,7 +50,7 @@ int main ()
int ret; int ret;
awk = qse_awk_openstd (); awk = qse_awk_openstd (0);
if (awk == QSE_NULL) if (awk == QSE_NULL)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n"));

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk03.c 76 2009-02-22 14:18:06Z hyunghwan.chung $ * $Id: awk03.c 85 2009-02-26 10:56:12Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -54,7 +54,7 @@ int main ()
int ret, i; int ret, i;
/* create a main processor */ /* create a main processor */
awk = qse_awk_openstd (); awk = qse_awk_openstd (0);
if (awk == QSE_NULL) if (awk == QSE_NULL)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n"));

View File

@ -1,5 +1,5 @@
/* /*
* $Id: awk04.c 76 2009-02-22 14:18:06Z hyunghwan.chung $ * $Id: awk04.c 85 2009-02-26 10:56:12Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -44,7 +44,7 @@ int main ()
int ret, i; int ret, i;
/* create a main processor */ /* create a main processor */
awk = qse_awk_openstd (); awk = qse_awk_openstd (0);
if (awk == QSE_NULL) if (awk == QSE_NULL)
{ {
qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n"));