This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h 233 2008-06-29 13:41:11Z baconevi $
|
||||
* $Id: awk.h 237 2008-07-09 13:20:08Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
@ -18,6 +18,7 @@
|
||||
#include <ase/types.h>
|
||||
#include <ase/macros.h>
|
||||
#include <ase/cmn/map.h>
|
||||
#include <ase/cmn/str.h>
|
||||
|
||||
typedef struct ase_awk_t ase_awk_t;
|
||||
typedef struct ase_awk_run_t ase_awk_run_t;
|
||||
@ -454,21 +455,163 @@ enum ase_awk_global_id_t
|
||||
ASE_AWK_MAX_GLOBAL_ID = ASE_AWK_GLOBAL_SUBSEP
|
||||
};
|
||||
|
||||
enum ase_awk_val_type_t
|
||||
{
|
||||
/* the values between ASE_AWK_VAL_NIL and ASE_AWK_VAL_STR inclusive
|
||||
* must be synchronized with an internal table of the __cmp_val
|
||||
* function in run.c */
|
||||
ASE_AWK_VAL_NIL = 0,
|
||||
ASE_AWK_VAL_INT = 1,
|
||||
ASE_AWK_VAL_REAL = 2,
|
||||
ASE_AWK_VAL_STR = 3,
|
||||
|
||||
ASE_AWK_VAL_REX = 4,
|
||||
ASE_AWK_VAL_MAP = 5,
|
||||
ASE_AWK_VAL_REF = 6
|
||||
};
|
||||
|
||||
enum ase_awk_val_ref_id_t
|
||||
{
|
||||
/* keep these items in the same order as corresponding items
|
||||
* in tree.h */
|
||||
ASE_AWK_VAL_REF_NAMED,
|
||||
ASE_AWK_VAL_REF_GLOBAL,
|
||||
ASE_AWK_VAL_REF_LOCAL,
|
||||
ASE_AWK_VAL_REF_ARG,
|
||||
ASE_AWK_VAL_REF_NAMEDIDX,
|
||||
ASE_AWK_VAL_REF_GLOBALIDX,
|
||||
ASE_AWK_VAL_REF_LOCALIDX,
|
||||
ASE_AWK_VAL_REF_ARGIDX,
|
||||
ASE_AWK_VAL_REF_POS
|
||||
};
|
||||
|
||||
enum ase_awk_valtostr_opt_t
|
||||
{
|
||||
ASE_AWK_VALTOSTR_CLEAR = (1 << 0),
|
||||
ASE_AWK_VALTOSTR_FIXED = (1 << 1),/* this overrides CLEAR */
|
||||
ASE_AWK_VALTOSTR_PRINT = (1 << 2)
|
||||
};
|
||||
|
||||
typedef struct ase_awk_val_nil_t ase_awk_val_nil_t;
|
||||
typedef struct ase_awk_val_int_t ase_awk_val_int_t;
|
||||
typedef struct ase_awk_val_real_t ase_awk_val_real_t;
|
||||
typedef struct ase_awk_val_str_t ase_awk_val_str_t;
|
||||
typedef struct ase_awk_val_rex_t ase_awk_val_rex_t;
|
||||
typedef struct ase_awk_val_map_t ase_awk_val_map_t;
|
||||
typedef struct ase_awk_val_ref_t ase_awk_val_ref_t;
|
||||
|
||||
/* this is not a value. it is just a value holder */
|
||||
typedef struct ase_awk_val_chunk_t ase_awk_val_chunk_t;
|
||||
|
||||
#if ASE_SIZEOF_INT == 2
|
||||
#define ASE_AWK_VAL_HDR \
|
||||
unsigned int type: 3; \
|
||||
unsigned int ref: 13
|
||||
#else
|
||||
#define ASE_AWK_VAL_HDR \
|
||||
unsigned int type: 3; \
|
||||
unsigned int ref: 29
|
||||
#endif
|
||||
|
||||
#define ASE_AWK_VAL_TYPE(x) ((x)->type)
|
||||
|
||||
struct ase_awk_val_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_NIL */
|
||||
struct ase_awk_val_nil_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_INT */
|
||||
struct ase_awk_val_int_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
ase_long_t val;
|
||||
void* nde;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_REAL */
|
||||
struct ase_awk_val_real_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
ase_real_t val;
|
||||
void* nde;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_STR */
|
||||
struct ase_awk_val_str_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
ase_char_t* buf;
|
||||
ase_size_t len;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_REX */
|
||||
struct ase_awk_val_rex_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
ase_char_t* buf;
|
||||
ase_size_t len;
|
||||
void* code;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_MAP */
|
||||
struct ase_awk_val_map_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
|
||||
/* TODO: make val_map to array if the indices used are all
|
||||
* integers switch to map dynamically once the
|
||||
* non-integral index is seen.
|
||||
*/
|
||||
ase_map_t* map;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_REF */
|
||||
struct ase_awk_val_ref_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
|
||||
int id;
|
||||
/* if id is ASE_AWK_VAL_REF_POS, adr holds an index of the
|
||||
* positional variable. Otherwise, adr points to the value
|
||||
* directly. */
|
||||
ase_awk_val_t** adr;
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern ase_awk_val_t* ase_awk_val_nil;
|
||||
extern ase_awk_val_t* ase_awk_val_zls;
|
||||
extern ase_awk_val_t* ase_awk_val_negone;
|
||||
extern ase_awk_val_t* ase_awk_val_zero;
|
||||
extern ase_awk_val_t* ase_awk_val_one;
|
||||
|
||||
/**
|
||||
* @brief opens an awk interpreter
|
||||
*/
|
||||
ase_awk_t* ase_awk_open (const ase_awk_prmfns_t* prmfns);
|
||||
|
||||
/**
|
||||
* @brief opens an awk interpreter
|
||||
*/
|
||||
int ase_awk_close (ase_awk_t* awk);
|
||||
|
||||
/**
|
||||
* @brief clears an awk interpreter
|
||||
*/
|
||||
int ase_awk_clear (ase_awk_t* awk);
|
||||
|
||||
/**
|
||||
* @function ase_awk_setassocdata
|
||||
* @brief associats the user-specified data with an interpreter
|
||||
*/
|
||||
void ase_awk_setassocdata (ase_awk_t* awk, void* data);
|
||||
/**
|
||||
* @function ase_awk_getassocdata
|
||||
* @brief returns the user-specified data associated with an interpreter
|
||||
*/
|
||||
void* ase_awk_getassocdata (ase_awk_t* awk);
|
||||
@ -677,6 +820,51 @@ ase_size_t ase_awk_longtostr (
|
||||
ase_long_t value, int radix, const ase_char_t* prefix,
|
||||
ase_char_t* buf, ase_size_t size);
|
||||
|
||||
/* value manipulation functions */
|
||||
ase_awk_val_t* ase_awk_makeintval (ase_awk_run_t* run, ase_long_t v);
|
||||
ase_awk_val_t* ase_awk_makerealval (ase_awk_run_t* run, ase_real_t v);
|
||||
|
||||
ase_awk_val_t* ase_awk_makestrval0 (
|
||||
ase_awk_run_t* run, const ase_char_t* str);
|
||||
ase_awk_val_t* ase_awk_makestrval (
|
||||
ase_awk_run_t* run, const ase_char_t* str, ase_size_t len);
|
||||
ase_awk_val_t* ase_awk_makestrval_nodup (
|
||||
ase_awk_run_t* run, ase_char_t* str, ase_size_t len);
|
||||
ase_awk_val_t* ase_awk_makestrval2 (
|
||||
ase_awk_run_t* run,
|
||||
const ase_char_t* str1, ase_size_t len1,
|
||||
const ase_char_t* str2, ase_size_t len2);
|
||||
|
||||
ase_awk_val_t* ase_awk_makerexval (
|
||||
ase_awk_run_t* run, const ase_char_t* buf, ase_size_t len, void* code);
|
||||
ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run);
|
||||
ase_awk_val_t* ase_awk_makerefval (
|
||||
ase_awk_run_t* run, int id, ase_awk_val_t** adr);
|
||||
|
||||
ase_bool_t ase_awk_isstaticval (ase_awk_val_t* val);
|
||||
|
||||
void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache);
|
||||
|
||||
void ase_awk_refupval (ase_awk_run_t* run, ase_awk_val_t* val);
|
||||
void ase_awk_refdownval (ase_awk_run_t* run, ase_awk_val_t* val);
|
||||
void ase_awk_refdownval_nofree (ase_awk_run_t* run, ase_awk_val_t* val);
|
||||
|
||||
void ase_awk_freevalchunk (ase_awk_run_t* run, ase_awk_val_chunk_t* chunk);
|
||||
|
||||
ase_bool_t ase_awk_valtobool (
|
||||
ase_awk_run_t* run, ase_awk_val_t* val);
|
||||
|
||||
ase_char_t* ase_awk_valtostr (
|
||||
ase_awk_run_t* run, ase_awk_val_t* val,
|
||||
int opt, ase_str_t* buf, ase_size_t* len);
|
||||
|
||||
int ase_awk_valtonum (
|
||||
ase_awk_run_t* run, ase_awk_val_t* v, ase_long_t* l, ase_real_t* r);
|
||||
int ase_awk_strtonum (
|
||||
ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len,
|
||||
ase_long_t* l, ase_real_t* r);
|
||||
|
||||
void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
|
||||
pkginclude_HEADERS = awk.h val.h Awk.hpp StdAwk.hpp
|
||||
pkginclude_HEADERS = awk.h Awk.hpp StdAwk.hpp
|
||||
pkgincludedir= $(includedir)/ase/awk
|
||||
CLEANFILES = *dist
|
||||
|
@ -1,213 +0,0 @@
|
||||
/*
|
||||
* $Id: val.h 194 2008-06-06 13:00:39Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#ifndef _ASE_AWK_VAL_H_
|
||||
#define _ASE_AWK_VAL_H_
|
||||
|
||||
#ifndef _ASE_AWK_AWK_H_
|
||||
#error Include <ase/awk/awk.h> first
|
||||
#endif
|
||||
|
||||
#include <ase/cmn/str.h>
|
||||
|
||||
enum ase_awk_val_type_t
|
||||
{
|
||||
/* the values between ASE_AWK_VAL_NIL and ASE_AWK_VAL_STR inclusive
|
||||
* must be synchronized with an internal table of the __cmp_val
|
||||
* function in run.c */
|
||||
ASE_AWK_VAL_NIL = 0,
|
||||
ASE_AWK_VAL_INT = 1,
|
||||
ASE_AWK_VAL_REAL = 2,
|
||||
ASE_AWK_VAL_STR = 3,
|
||||
|
||||
ASE_AWK_VAL_REX = 4,
|
||||
ASE_AWK_VAL_MAP = 5,
|
||||
ASE_AWK_VAL_REF = 6
|
||||
};
|
||||
|
||||
enum ase_awk_val_ref_id_t
|
||||
{
|
||||
/* keep these items in the same order as corresponding items
|
||||
* in tree.h */
|
||||
ASE_AWK_VAL_REF_NAMED,
|
||||
ASE_AWK_VAL_REF_GLOBAL,
|
||||
ASE_AWK_VAL_REF_LOCAL,
|
||||
ASE_AWK_VAL_REF_ARG,
|
||||
ASE_AWK_VAL_REF_NAMEDIDX,
|
||||
ASE_AWK_VAL_REF_GLOBALIDX,
|
||||
ASE_AWK_VAL_REF_LOCALIDX,
|
||||
ASE_AWK_VAL_REF_ARGIDX,
|
||||
ASE_AWK_VAL_REF_POS
|
||||
};
|
||||
|
||||
enum ase_awk_valtostr_opt_t
|
||||
{
|
||||
ASE_AWK_VALTOSTR_CLEAR = (1 << 0),
|
||||
ASE_AWK_VALTOSTR_FIXED = (1 << 1),/* this overrides CLEAR */
|
||||
ASE_AWK_VALTOSTR_PRINT = (1 << 2)
|
||||
};
|
||||
|
||||
typedef struct ase_awk_val_nil_t ase_awk_val_nil_t;
|
||||
typedef struct ase_awk_val_int_t ase_awk_val_int_t;
|
||||
typedef struct ase_awk_val_real_t ase_awk_val_real_t;
|
||||
typedef struct ase_awk_val_str_t ase_awk_val_str_t;
|
||||
typedef struct ase_awk_val_rex_t ase_awk_val_rex_t;
|
||||
typedef struct ase_awk_val_map_t ase_awk_val_map_t;
|
||||
typedef struct ase_awk_val_ref_t ase_awk_val_ref_t;
|
||||
|
||||
/* this is not a value. it is just a value holder */
|
||||
typedef struct ase_awk_val_chunk_t ase_awk_val_chunk_t;
|
||||
|
||||
#if ASE_SIZEOF_INT == 2
|
||||
#define ASE_AWK_VAL_HDR \
|
||||
unsigned int type: 3; \
|
||||
unsigned int ref: 13
|
||||
#else
|
||||
#define ASE_AWK_VAL_HDR \
|
||||
unsigned int type: 3; \
|
||||
unsigned int ref: 29
|
||||
#endif
|
||||
|
||||
#ifndef ASE_AWK_NDE_INT_DEFINED
|
||||
#define ASE_AWK_NDE_INT_DEFINED
|
||||
typedef struct ase_awk_nde_int_t ase_awk_nde_int_t;
|
||||
#endif
|
||||
|
||||
#ifndef ASE_AWK_NDE_REAL_DEFINED
|
||||
#define ASE_AWK_NDE_REAL_DEFINED
|
||||
typedef struct ase_awk_nde_real_t ase_awk_nde_real_t;
|
||||
#endif
|
||||
|
||||
#define ASE_AWK_VAL_TYPE(x) ((x)->type)
|
||||
|
||||
struct ase_awk_val_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_NIL */
|
||||
struct ase_awk_val_nil_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_INT */
|
||||
struct ase_awk_val_int_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
ase_long_t val;
|
||||
ase_awk_nde_int_t* nde;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_REAL */
|
||||
struct ase_awk_val_real_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
ase_real_t val;
|
||||
ase_awk_nde_real_t* nde;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_STR */
|
||||
struct ase_awk_val_str_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
ase_char_t* buf;
|
||||
ase_size_t len;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_REX */
|
||||
struct ase_awk_val_rex_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
ase_char_t* buf;
|
||||
ase_size_t len;
|
||||
void* code;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_MAP */
|
||||
struct ase_awk_val_map_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
|
||||
/* TODO: make val_map to array if the indices used are all
|
||||
* integers switch to map dynamically once the
|
||||
* non-integral index is seen.
|
||||
*/
|
||||
ase_map_t* map;
|
||||
};
|
||||
|
||||
/* ASE_AWK_VAL_REF */
|
||||
struct ase_awk_val_ref_t
|
||||
{
|
||||
ASE_AWK_VAL_HDR;
|
||||
|
||||
int id;
|
||||
/* if id is ASE_AWK_VAL_REF_POS, adr holds an index of the
|
||||
* positional variable. Otherwise, adr points to the value
|
||||
* directly. */
|
||||
ase_awk_val_t** adr;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern ase_awk_val_t* ase_awk_val_nil;
|
||||
extern ase_awk_val_t* ase_awk_val_zls;
|
||||
extern ase_awk_val_t* ase_awk_val_negone;
|
||||
extern ase_awk_val_t* ase_awk_val_zero;
|
||||
extern ase_awk_val_t* ase_awk_val_one;
|
||||
|
||||
ase_awk_val_t* ase_awk_makeintval (ase_awk_run_t* run, ase_long_t v);
|
||||
ase_awk_val_t* ase_awk_makerealval (ase_awk_run_t* run, ase_real_t v);
|
||||
|
||||
ase_awk_val_t* ase_awk_makestrval0 (
|
||||
ase_awk_run_t* run, const ase_char_t* str);
|
||||
ase_awk_val_t* ase_awk_makestrval (
|
||||
ase_awk_run_t* run, const ase_char_t* str, ase_size_t len);
|
||||
ase_awk_val_t* ase_awk_makestrval_nodup (
|
||||
ase_awk_run_t* run, ase_char_t* str, ase_size_t len);
|
||||
ase_awk_val_t* ase_awk_makestrval2 (
|
||||
ase_awk_run_t* run,
|
||||
const ase_char_t* str1, ase_size_t len1,
|
||||
const ase_char_t* str2, ase_size_t len2);
|
||||
|
||||
ase_awk_val_t* ase_awk_makerexval (
|
||||
ase_awk_run_t* run, const ase_char_t* buf, ase_size_t len, void* code);
|
||||
ase_awk_val_t* ase_awk_makemapval (ase_awk_run_t* run);
|
||||
ase_awk_val_t* ase_awk_makerefval (
|
||||
ase_awk_run_t* run, int id, ase_awk_val_t** adr);
|
||||
|
||||
ase_bool_t ase_awk_isstaticval (ase_awk_val_t* val);
|
||||
|
||||
void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache);
|
||||
|
||||
void ase_awk_refupval (ase_awk_run_t* run, ase_awk_val_t* val);
|
||||
void ase_awk_refdownval (ase_awk_run_t* run, ase_awk_val_t* val);
|
||||
void ase_awk_refdownval_nofree (ase_awk_run_t* run, ase_awk_val_t* val);
|
||||
|
||||
void ase_awk_freevalchunk (ase_awk_run_t* run, ase_awk_val_chunk_t* chunk);
|
||||
|
||||
ase_bool_t ase_awk_valtobool (
|
||||
ase_awk_run_t* run, ase_awk_val_t* val);
|
||||
|
||||
ase_char_t* ase_awk_valtostr (
|
||||
ase_awk_run_t* run, ase_awk_val_t* val,
|
||||
int opt, ase_str_t* buf, ase_size_t* len);
|
||||
|
||||
int ase_awk_valtonum (
|
||||
ase_awk_run_t* run, ase_awk_val_t* v, ase_long_t* l, ase_real_t* r);
|
||||
int ase_awk_strtonum (
|
||||
ase_awk_run_t* run, const ase_char_t* ptr, ase_size_t len,
|
||||
ase_long_t* l, ase_real_t* r);
|
||||
|
||||
void ase_awk_dprintval (ase_awk_run_t* run, ase_awk_val_t* val);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user