diff --git a/qse/cmd/awk/awk.c b/qse/cmd/awk/awk.c index 1cfb4c1e..674f59d3 100644 --- a/qse/cmd/awk/awk.c +++ b/qse/cmd/awk/awk.c @@ -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. @@ -549,7 +549,7 @@ static qse_awk_t* open_awk (void) { qse_awk_t* awk; - awk = qse_awk_openstd (); + awk = qse_awk_openstd (0); if (awk == QSE_NULL) { qse_printf (QSE_T("ERROR: cannot open awk\n")); diff --git a/qse/include/qse/awk/awk.h b/qse/include/qse/awk/awk.h index 63599bef..7b73cabd 100644 --- a/qse/include/qse/awk/awk.h +++ b/qse/include/qse/awk/awk.h @@ -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. @@ -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 */ /******/ -/* 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 # define QSE_AWK_VAL_HDR \ 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_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) ( qse_awk_t* awk, @@ -213,6 +205,11 @@ typedef qse_cint_t (*qse_awk_toccls_t) ( 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 { QSE_AWK_SIO_OPEN = 0, @@ -220,8 +217,8 @@ enum qse_awk_sio_cmd_t QSE_AWK_SIO_READ = 2, QSE_AWK_SIO_WRITE = 3 }; - typedef enum qse_awk_sio_cmd_t qse_awk_sio_cmd_t; +/******/ /****t* AWK/qse_awk_siof_t * NAME @@ -245,23 +242,8 @@ enum qse_awk_rio_cmd_t QSE_AWK_RIO_FLUSH = 4, QSE_AWK_RIO_NEXT = 5 }; - 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 * NAME * 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; } 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 { qse_awk_pow_t pow; @@ -333,20 +336,41 @@ struct qse_awk_prm_t ); #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 { qse_awk_siof_t in; 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 { qse_awk_riof_t pipe; qse_awk_riof_t file; 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 { int (*on_enter) ( @@ -360,6 +384,8 @@ struct qse_awk_rcb_t void* data; }; +typedef struct qse_awk_rcb_t qse_awk_rcb_t; +/******/ /* various options */ enum qse_awk_option_t diff --git a/qse/include/qse/awk/std.h b/qse/include/qse/awk/std.h index 3660d092..6218fe58 100644 --- a/qse/include/qse/awk/std.h +++ b/qse/include/qse/awk/std.h @@ -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. @@ -89,7 +89,17 @@ extern "C" { * SYNOPSIS */ 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 ); /******/ diff --git a/qse/lib/awk/awk.c b/qse/lib/awk/awk.c index 0220251f..826c41fb 100644 --- a/qse/lib/awk/awk.c +++ b/qse/lib/awk/awk.c @@ -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. @@ -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; /* progagate the primitive functions */ + QSE_ASSERT (prm != QSE_NULL); QSE_ASSERT (prm->pow != QSE_NULL); QSE_ASSERT (prm->sprintf != QSE_NULL); QSE_ASSERT (prm->isccls != 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; /* build a character classifier from the primitive functions */ diff --git a/qse/lib/awk/parse.c b/qse/lib/awk/parse.c index 0aeef62f..75bab391 100644 --- a/qse/lib/awk/parse.c +++ b/qse/lib/awk/parse.c @@ -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. @@ -469,9 +469,16 @@ int qse_awk_parse (qse_awk_t* awk, qse_awk_sio_t* sio) { int n; - QSE_ASSERTX ( - sio != QSE_NULL && sio->in != QSE_NULL, + QSE_ASSERTX (sio != 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"); + 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.expr == 0); diff --git a/qse/lib/awk/std.c b/qse/lib/awk/std.c index 81c7017e..a85b4bde 100644 --- a/qse/lib/awk/std.c +++ b/qse/lib/awk/std.c @@ -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. @@ -138,7 +138,7 @@ static qse_cint_t custom_awk_toccls ( 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_prm_t prm; @@ -150,7 +150,8 @@ qse_awk_t* qse_awk_openstd (void) prm.toccls = custom_awk_toccls; /* 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; /* initialize extension */ @@ -167,6 +168,11 @@ qse_awk_t* qse_awk_openstd (void) return awk; } +void* qse_awk_getxtnstd (qse_awk_t* awk) +{ + return (void*)((xtn_t*)QSE_XTN(awk) + 1); +} + /*** PARSESTD ***/ static qse_ssize_t sf_in ( diff --git a/qse/lib/awk/val.c b/qse/lib/awk/val.c index a99a0ade..ade7b4a0 100644 --- a/qse/lib/awk/val.c +++ b/qse/lib/awk/val.c @@ -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. @@ -22,33 +22,7 @@ #include #endif -#define CHUNKSIZE 100 - -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]; -}; +#define CHUNKSIZE QSE_AWK_VAL_CHUNK_SIZE static qse_char_t* str_to_str ( qse_awk_rtx_t* run, const qse_char_t* str, qse_size_t str_len, diff --git a/qse/lib/awk/val.h b/qse/lib/awk/val.h index f404b140..ade31923 100644 --- a/qse/lib/awk/val.h +++ b/qse/lib/awk/val.h @@ -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. @@ -19,6 +19,35 @@ #ifndef _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 extern "C" { #endif diff --git a/qse/test/awk/awk01.c b/qse/test/awk/awk01.c index 486808db..73c6b90b 100644 --- a/qse/test/awk/awk01.c +++ b/qse/test/awk/awk01.c @@ -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. @@ -44,7 +44,7 @@ int main () qse_awk_parsestd_in_t psin; int ret; - awk = qse_awk_openstd (); + awk = qse_awk_openstd (0); if (awk == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); diff --git a/qse/test/awk/awk02.c b/qse/test/awk/awk02.c index c64075fe..31559892 100644 --- a/qse/test/awk/awk02.c +++ b/qse/test/awk/awk02.c @@ -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. @@ -50,7 +50,7 @@ int main () int ret; - awk = qse_awk_openstd (); + awk = qse_awk_openstd (0); if (awk == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); diff --git a/qse/test/awk/awk03.c b/qse/test/awk/awk03.c index b9168beb..60d2f0c6 100644 --- a/qse/test/awk/awk03.c +++ b/qse/test/awk/awk03.c @@ -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. @@ -54,7 +54,7 @@ int main () int ret, i; /* create a main processor */ - awk = qse_awk_openstd (); + awk = qse_awk_openstd (0); if (awk == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n")); diff --git a/qse/test/awk/awk04.c b/qse/test/awk/awk04.c index cbfcba42..91be4c5a 100644 --- a/qse/test/awk/awk04.c +++ b/qse/test/awk/awk04.c @@ -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. @@ -44,7 +44,7 @@ int main () int ret, i; /* create a main processor */ - awk = qse_awk_openstd (); + awk = qse_awk_openstd (0); if (awk == QSE_NULL) { qse_fprintf (QSE_STDERR, QSE_T("error: cannot open awk\n"));