diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2012-07-26 22:27:54 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2012-07-26 22:27:54 +0300 |
commit | 652a11e5fbe9862a2b8e961b32b9748b3c2c418b (patch) | |
tree | 003fe14ab86a1f521522a8815f22b618ebffd842 | |
parent | c3d3c83b0a60454c7b1bc335c022051b58f393e3 (diff) | |
download | egawk-652a11e5fbe9862a2b8e961b32b9748b3c2c418b.tar.gz egawk-652a11e5fbe9862a2b8e961b32b9748b3c2c418b.tar.bz2 egawk-652a11e5fbe9862a2b8e961b32b9748b3c2c418b.zip |
Add set_RT to API and to readdir extension.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | awk.h | 2 | ||||
-rw-r--r-- | extension/ChangeLog | 3 | ||||
-rw-r--r-- | extension/readdir.c | 12 | ||||
-rw-r--r-- | gawkapi.c | 34 | ||||
-rw-r--r-- | gawkapi.h | 4 | ||||
-rw-r--r-- | io.c | 26 |
7 files changed, 84 insertions, 6 deletions
@@ -1,3 +1,12 @@ +2012-07-26 Arnold D. Robbins <arnold@skeeve.com> + + * awk.h (set_RT_to_null, set_RT): Declare functions. + * io.c (set_RT_to_null, set_RT): New functions. + (iop_close): Init ret to zero. + * gawkapi.c (api_register_input_parser): Check for null pointer. + (api_set_RT): New function. + * gawkapi.h (api_set_RT): New function. + 2012-07-26 Andrew J. Schorr <aschorr@telemetry-investments.com> * gawkapi.h (IOBUF_PUBLIC): Document the get_record and close_func @@ -1544,6 +1544,8 @@ extern void init_io(void); extern void register_input_parser(awk_input_parser_t *input_parser); extern void set_FNR(void); extern void set_NR(void); +extern void set_RT_to_null(void); +extern void set_RT(const char *str, size_t len); extern struct redirect *redirect(NODE *redir_exp, int redirtype, int *errflg); extern NODE *do_close(int nargs); diff --git a/extension/ChangeLog b/extension/ChangeLog index 52dca767..758f1b68 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -3,6 +3,9 @@ * configure.ac: Extremely crude hack to get the value of ENABLE_NLS so that gettext will work in extensions. + * readdir.c (dir_get_record): Call set_RT. + (dir_can_take_file): Make parameter const. + 2012-07-26 Andrew J. Schorr <aschorr@telemetry-investments.com> * readdir.c (dir_get_record): No need to set *errcode to 0. diff --git a/extension/readdir.c b/extension/readdir.c index c838ea72..a0a82a2d 100644 --- a/extension/readdir.c +++ b/extension/readdir.c @@ -102,6 +102,7 @@ dir_get_record(char **out, struct iobuf_public *iobuf, int *errcode) struct dirent *dirent; char buf[1000]; size_t len; + static const awk_value_t null_val = { AWK_UNDEFINED }; if (out == NULL || iobuf == NULL || iobuf->opaque == NULL) return EOF; @@ -111,7 +112,7 @@ dir_get_record(char **out, struct iobuf_public *iobuf, int *errcode) * error occurs. */ - /* FIXME: Need stuff for setting RT */ + set_RT((awk_value_t *) & null_val); dp = (DIR *) iobuf->opaque; dirent = readdir(dp); if (dirent == NULL) @@ -142,7 +143,7 @@ dir_close(struct iobuf_public *iobuf) /* dir_can_take_file --- return true if we want the file */ static int -dir_can_take_file(IOBUF_PUBLIC *iobuf) +dir_can_take_file(const IOBUF_PUBLIC *iobuf) { struct stat sbuf; int fd; @@ -154,12 +155,15 @@ dir_can_take_file(IOBUF_PUBLIC *iobuf) return (fd >= 0 && fstat(fd, & sbuf) >= 0 && S_ISDIR(sbuf.st_mode)); } -/* dir_take_control_of --- set up input parser. We can assume that dir_can_take_file just returned true, and no state has changed since then. */ +/* + * dir_take_control_of --- set up input parser. + * We can assume that dir_can_take_file just returned true, + * and no state has changed since then. + */ static int dir_take_control_of(IOBUF_PUBLIC *iobuf) { - struct stat sbuf; DIR *dp; dp = fdopendir(iobuf->fd); @@ -222,9 +222,41 @@ api_register_input_parser(awk_ext_id_t id, awk_input_parser_t *input_parser) { (void) id; + if (input_parser == NULL) + return; + register_input_parser(input_parser); } +/* api_set_RT --- set RT's value */ + +static void +api_set_RT(awk_ext_id_t id, awk_value_t *value) +{ + NODE *n; + + (void) id; + + if (value == NULL) + return; + + switch (value->val_type) { + case AWK_UNDEFINED: + set_RT_to_null(); + break; + case AWK_ARRAY: + case AWK_VALUE_COOKIE: + break; + case AWK_STRING: + case AWK_NUMBER: + case AWK_SCALAR: + n = awk_value_to_node(value); + force_string(n); + set_RT(n->stptr, n->stlen); + unref(n); + } +} + /* Functions to update ERRNO */ /* api_update_ERRNO_int --- update ERRNO with an integer value */ @@ -567,7 +599,6 @@ api_sym_update_scalar(awk_ext_id_t id, awk_value_t *value) { NODE *node = (NODE *) cookie; - NODE *new_value; if (value == NULL || node == NULL @@ -958,6 +989,7 @@ gawk_api_t api_impl = { api_lintwarn, api_register_input_parser, + api_set_RT, api_update_ERRNO_int, api_update_ERRNO_string, @@ -324,6 +324,9 @@ typedef struct gawk_api { /* Register an input parser; for opening files read-only */ void (*api_register_input_parser)(awk_ext_id_t id, awk_input_parser_t *input_parser); + /* Set RT - pass AWK_UNDEFINED to set to null string */ + void (*api_set_RT)(awk_ext_id_t id, awk_value_t *value); + /* Functions to update ERRNO */ void (*api_update_ERRNO_int)(awk_ext_id_t id, int errno_val); void (*api_update_ERRNO_string)(awk_ext_id_t id, const char *string); @@ -504,6 +507,7 @@ typedef struct gawk_api { #define lintwarn api->api_lintwarn #define register_input_parser(parser) (api->api_register_input_parser(ext_id, parser)) +#define set_RT(value) (api->api_set_RT(ext_id, value)) #define update_ERRNO_int(e) (api->api_update_ERRNO_int(ext_id, e)) #define update_ERRNO_string(str) \ @@ -536,7 +536,7 @@ remap_std_file(int oldfd) static int iop_close(IOBUF *iop) { - int ret; + int ret = 0; if (iop == NULL) return 0; @@ -2667,6 +2667,30 @@ iop_alloc(int fd, const char *name, bool do_input_parsers) return iop; } +/* set_RT_to_null --- real function for use by extension API */ + +void +set_RT_to_null() +{ + if (! do_traditional) { + unref(RT_node->var_value); + RT_node->var_value = dupnode(Nnull_string); + } +} + +/* set_RT --- real function for use by extension API */ + +void +set_RT(const char *str, size_t len) +{ + if (! do_traditional) { + unref(RT_node->var_value); + RT_node->var_value = make_str_node(str, len, ALREADY_MALLOCED); + } +} + +/* macros for speed in default implementation */ + #define set_RT_to_null() \ (void)(! do_traditional && (unref(RT_node->var_value), \ RT_node->var_value = dupnode(Nnull_string))) |