diff options
Diffstat (limited to 'gawkapi.h')
-rw-r--r-- | gawkapi.h | 80 |
1 files changed, 50 insertions, 30 deletions
@@ -308,7 +308,8 @@ typedef enum { AWK_STRING, AWK_ARRAY, AWK_SCALAR, /* opaque access to a variable */ - AWK_VALUE_COOKIE /* for updating a previously created value */ + AWK_VALUE_COOKIE, /* for updating a previously created value */ + AWK_REGEX /* last for binary compatibility */ } awk_valtype_t; /* @@ -325,6 +326,7 @@ typedef struct awk_value { awk_value_cookie_t vc; } u; #define str_value u.s +#define regex_value str_value #define num_value u.d #define array_cookie u.a #define scalar_cookie u.scl @@ -493,27 +495,29 @@ typedef struct gawk_api { Table entry is type returned: - +-------------------------------------------------+ - | Type of Actual Value: | - +------------+------------+-----------+-----------+ - | String | Number | Array | Undefined | - +-----------+-----------+------------+------------+-----------+-----------+ - | | String | String | String | false | false | - | |-----------+------------+------------+-----------+-----------+ - | | Number | Number if | Number | false | false | - | | | can be | | | | - | | | converted, | | | | - | | | else false | | | | - | |-----------+------------+------------+-----------+-----------+ - | Type | Array | false | false | Array | false | - | Requested |-----------+------------+------------+-----------+-----------+ - | | Scalar | Scalar | Scalar | false | false | - | |-----------+------------+------------+-----------+-----------+ - | | Undefined | String | Number | Array | Undefined | - | |-----------+------------+------------+-----------+-----------+ - | | Value | false | false | false | false | - | | Cookie | | | | | - +-----------+-----------+------------+------------+-----------+-----------+ + +-------------------------------------------------------------+ + | Type of Actual Value: | + +------------+------------+-----------+-----------+-----------+ + | String | Number | Regex | Array | Undefined | + +-----------+-----------+------------+------------+-----------+-----------+-----------+ + | | String | String | String | String | false | false | + | +-----------+------------+------------+-----------+-----------+-----------+ + | | Number | Number if | Number | false | false | false | + | | | can be | | | | | + | | | converted, | | | | | + | | | else false | | | | | + | +-----------+------------+------------+-----------+-----------+-----------+ + | | Regex | false | false | Regex | false | false | + | +-----------+------------+------------+-----------+-----------+-----------+ + | Type | Array | false | false | false | Array | false | + | Requested +-----------+------------+------------+-----------+-----------+-----------+ + | | Scalar | Scalar | Scalar | Scalar | false | false | + | +-----------+------------+------------+-----------+-----------+-----------+ + | | Undefined | String | Number | Regex | Array | Undefined | + | +-----------+------------+------------+-----------+-----------+-----------+ + | | Value | false | false | false | false | false | + | | Cookie | | | | | | + +-----------+-----------+------------+------------+-----------+-----------+-----------+ */ /* Functions to handle parameters passed to the extension. */ @@ -839,21 +843,22 @@ typedef struct gawk_api { /* Constructor functions */ -/* r_make_string --- make a string value in result from the passed-in string */ +/* r_make_string_type --- make a string or regexp value in result from the passed-in string */ static inline awk_value_t * -r_make_string(const gawk_api_t *api, /* needed for emalloc */ - awk_ext_id_t *ext_id, /* ditto */ - const char *string, - size_t length, - awk_bool_t duplicate, - awk_value_t *result) +r_make_string_type(const gawk_api_t *api, /* needed for emalloc */ + awk_ext_id_t *ext_id, /* ditto */ + const char *string, + size_t length, + awk_bool_t duplicate, + awk_value_t *result, + awk_valtype_t val_type) { char *cp = NULL; memset(result, 0, sizeof(*result)); - result->val_type = AWK_STRING; + result->val_type = val_type; result->str_value.len = length; if (duplicate) { @@ -868,8 +873,22 @@ r_make_string(const gawk_api_t *api, /* needed for emalloc */ return result; } +/* r_make_string --- make a string value in result from the passed-in string */ + +static inline awk_value_t * +r_make_string(const gawk_api_t *api, /* needed for emalloc */ + awk_ext_id_t *ext_id, /* ditto */ + const char *string, + size_t length, + awk_bool_t duplicate, + awk_value_t *result) +{ + return r_make_string_type(api, ext_id, string, length, duplicate, result, AWK_STRING); +} + #define make_const_string(str, len, result) r_make_string(api, ext_id, str, len, 1, result) #define make_malloced_string(str, len, result) r_make_string(api, ext_id, str, len, 0, result) +#define make_regex(str, len, result) r_make_string_type(api, ext_id, str, len, 1, result, AWK_REGEX) /* make_null_string --- make a null string value */ @@ -895,6 +914,7 @@ make_number(double num, awk_value_t *result) return result; } + /* * Each extension must define a function with this prototype: * |