diff options
Diffstat (limited to 'awk.h')
-rw-r--r-- | awk.h | 74 |
1 files changed, 48 insertions, 26 deletions
@@ -294,6 +294,7 @@ typedef enum nodevals { Node_param_list, /* lnode is a variable, rnode is more list */ Node_func, /* lnode is param. list, rnode is body */ Node_ext_func, /* extension function, code_ptr is builtin code */ + Node_old_ext_func, /* extension function, code_ptr is builtin code */ Node_array_ref, /* array passed by ref as parameter */ Node_array_tree, /* Hashed array tree (HAT) */ @@ -344,7 +345,7 @@ typedef union bucket_item { struct exp_instruction; typedef int (*Func_print)(FILE *, const char *, ...); -typedef struct exp_node **(*array_ptr)(struct exp_node *, struct exp_node *); +typedef struct exp_node **(*afunc_t)(struct exp_node *, struct exp_node *); /* * NOTE - this struct is a rather kludgey -- it is packed to minimize @@ -357,13 +358,14 @@ typedef struct exp_node { struct exp_node *lptr; struct exp_instruction *li; long ll; - array_ptr *lp; + afunc_t *lp; } l; union { struct exp_node *rptr; Regexp *preg; struct exp_node **av; BUCKET **bv; + void *aq; void (*uptr)(void); struct exp_instruction *iptr; } r; @@ -496,6 +498,7 @@ typedef struct exp_node { /* Node_var_array: */ #define buckets sub.nodep.r.bv #define nodes sub.nodep.r.av +#define a_opaque sub.nodep.r.aq #define array_funcs sub.nodep.l.lp #define array_base sub.nodep.l.ll #define table_size sub.nodep.reflags @@ -504,17 +507,21 @@ typedef struct exp_node { #define xarray sub.nodep.rn #define parent_array sub.nodep.x.extra -/* array_funcs[0] is the array initialization function and - * array_funcs[1] is the index type checking function - */ -#define alookup array_funcs[2] -#define aexists array_funcs[3] -#define aclear array_funcs[4] -#define aremove array_funcs[5] -#define alist array_funcs[6] -#define acopy array_funcs[7] -#define adump array_funcs[8] -#define NUM_AFUNCS 9 /* # of entries in array_funcs */ +#define ainit array_funcs[0] +#define atypeof array_funcs[1] +#define alength array_funcs[2] +#define alookup array_funcs[3] +#define aexists array_funcs[4] +#define aclear array_funcs[5] +#define aremove array_funcs[6] +#define alist array_funcs[7] +#define acopy array_funcs[8] +#define adump array_funcs[9] +#define astore array_funcs[10] +#define NUM_AFUNCS 11 /* # of entries in array_funcs */ + +/* array func to index mapping */ +#define AFUNC(F) (& ((NODE *) 0)->F - ((NODE *) 0)->array_funcs) /* Node_array_ref: */ #define orig_array lnode @@ -622,6 +629,7 @@ typedef enum opcodeval { Op_builtin, Op_sub_builtin, /* sub, gsub and gensub */ Op_ext_builtin, + Op_old_ext_builtin, /* temporary */ Op_in_array, /* boolean test of membership in array */ /* function call instruction */ @@ -651,6 +659,7 @@ typedef enum opcodeval { Op_var_update, /* update value of NR, NF or FNR */ Op_var_assign, Op_field_assign, + Op_subscript_assign, Op_after_beginfile, Op_after_endfile, @@ -956,6 +965,8 @@ typedef struct srcfile { int fd; int maxlen; /* size of the longest line */ + void (*fini_func)(); /* dynamic extension of type SRC_EXTLIB */ + char *lexptr; char *lexend; char *lexeme; @@ -994,6 +1005,8 @@ enum block_id { BLOCK_MAX /* count */ }; +typedef int (*Func_pre_exec)(INSTRUCTION **); +typedef void (*Func_post_exec)(INSTRUCTION *); #ifndef LONG_MAX #define LONG_MAX ((long)(~(1L << (sizeof (long) * 8 - 1)))) @@ -1040,8 +1053,10 @@ extern NODE *(*str2number)(NODE *); extern NODE *(*format_val)(const char *, int, NODE *); extern int (*cmp_numbers)(const NODE *, const NODE *); -typedef int (*Func_pre_exec)(INSTRUCTION **); -typedef void (*Func_post_exec)(INSTRUCTION *); +/* built-in array types */ +extern afunc_t str_array_func[]; +extern afunc_t cint_array_func[]; +extern afunc_t int_array_func[]; extern BLOCK nextfree[]; extern bool field0_valid; @@ -1291,7 +1306,8 @@ if (val++) \ if (--val) \ memcpy((char *) tag, (const char *) (stack), sizeof(jmp_buf)) -#define array_empty(a) ((a)->table_size == 0) +#define assoc_length(a) ((*((a)->alength(a, NULL)))->table_size) +#define assoc_empty(a) (assoc_length(a) == 0) #define assoc_lookup(a, s) ((a)->alookup(a, s)) /* assoc_clear --- flush all the values in symbol[] */ @@ -1302,8 +1318,8 @@ if (--val) \ /* ------------- Function prototypes or defs (as appropriate) ------------- */ /* array.c */ -typedef enum sort_context { SORTED_IN = 1, ASORT, ASORTI } SORT_CTXT; -enum assoc_list_flags { +typedef enum { SORTED_IN = 1, ASORT, ASORTI } sort_context_t; +typedef enum { AINDEX = 0x001, /* list of indices */ AVALUE = 0x002, /* list of values */ AINUM = 0x004, /* numeric index */ @@ -1313,20 +1329,22 @@ enum assoc_list_flags { AASC = 0x040, /* ascending order */ ADESC = 0x080, /* descending order */ ADELETE = 0x100 /* need a single index; for use in do_delete_loop */ -}; +} assoc_kind_t; extern NODE *make_array(void); -extern void init_array(NODE *symbol); -extern NODE *get_array(NODE *symbol, bool canfatal); +extern void null_array(NODE *symbol); +extern NODE *force_array(NODE *symbol, bool canfatal); extern const char *make_aname(const NODE *symbol); extern const char *array_vname(const NODE *symbol); extern void array_init(void); -extern int register_array_func(array_ptr *afunc); +extern int register_array_func(afunc_t *afunc); +extern NODE **null_length(NODE *symbol, NODE *subs); +extern NODE **null_afunc(NODE *symbol, NODE *subs); extern void set_SUBSEP(void); extern NODE *concat_exp(int nargs, bool do_subsep); extern NODE *assoc_copy(NODE *symbol, NODE *newsymb); extern void assoc_dump(NODE *symbol, NODE *p); -extern NODE **assoc_list(NODE *symbol, const char *sort_str, SORT_CTXT sort_ctxt); +extern NODE **assoc_list(NODE *symbol, const char *sort_str, sort_context_t sort_ctxt); extern void assoc_info(NODE *subs, NODE *val, NODE *p, const char *aname); extern void do_delete(NODE *symbol, int nsubs); extern void do_delete_loop(NODE *symbol, NODE **lhs); @@ -1428,8 +1446,12 @@ extern STACK_ITEM *grow_stack(void); extern void dump_fcall_stack(FILE *fp); extern int register_exec_hook(Func_pre_exec preh, Func_post_exec posth); /* ext.c */ -void load_ext(const char *lib_name); +extern NODE *do_ext(int nargs); +void load_ext(const char *lib_name); /* temporary */ +extern NODE *load_old_ext(SRCFILE *s, const char *init_func, const char *fini_func, NODE *obj); +extern void close_extensions(void); #ifdef DYNAMIC +extern void make_old_builtin(const char *, NODE *(*)(int), int); extern awk_bool_t make_builtin(const awk_ext_func_t *); extern NODE *get_argument(int); extern NODE *get_actual_argument(int, bool, bool); @@ -1690,7 +1712,7 @@ POP_ARRAY() { NODE *t = POP(); - return (t->type == Node_var_array) ? t : get_array(t, true); + return (t->type == Node_var_array) ? t : force_array(t, true); } /* POP_PARAM --- get the top parameter, array or scalar */ @@ -1700,7 +1722,7 @@ POP_PARAM() { NODE *t = POP(); - return (t->type == Node_var_array) ? t : get_array(t, false); + return (t->type == Node_var_array) ? t : force_array(t, false); } /* POP_SCALAR --- pop the scalar at the top of the stack */ |