diff options
Diffstat (limited to 'gawkapi.h')
-rw-r--r-- | gawkapi.h | 59 |
1 files changed, 55 insertions, 4 deletions
@@ -261,7 +261,7 @@ typedef struct awk_two_way_processor { } awk_two_way_processor_t; #define gawk_api_major_version 1 -#define gawk_api_minor_version 1 +#define gawk_api_minor_version 2 /* Current version of the API. */ enum { @@ -278,6 +278,12 @@ enum { * The API deals exclusively with regular chars; these strings may * be multibyte encoded in the current locale's encoding and character * set. Gawk will convert internally to wide characters if necessary. + * + * Note that the string may not be terminated with a '\0' character. + * In particular, this happens for field values $n where n > 0 and n < NF, + * since the string points directly into the $0 buffer. All other strings, + * including those created by extensions, should be NUL-terminated. In general + * though, extension code should not assume that the string is NUL-terminated! */ typedef struct awk_string { char *str; /* data */ @@ -374,11 +380,15 @@ typedef struct awk_flat_array { * Each extension function may decide what to do if the number of * arguments isn't what it expected. Following awk functions, it * is likely OK to ignore extra arguments. + + * Note that the 'max_expected_args' value should be used by the + * extension function itself only to trigger a lint warning if more + * arguments are passed to the function. */ typedef struct awk_ext_func { const char *name; awk_value_t *(*function)(int num_actual_args, awk_value_t *result); - size_t num_expected_args; + size_t max_expected_args; } awk_ext_func_t; typedef void *awk_ext_id_t; /* opaque type for extension id */ @@ -507,7 +517,7 @@ typedef struct gawk_api { awk_value_t *result); /* - * Convert a paramter that was undefined into an array + * Convert a parameter that was undefined into an array * (provide call-by-reference for arrays). Returns false * if count is too big, or if the argument's type is * not undefined. @@ -677,6 +687,43 @@ typedef struct gawk_api { void *(*api_calloc)(size_t nmemb, size_t size); void *(*api_realloc)(void *ptr, size_t size); void (*api_free)(void *ptr); + + /* + * Look up a file. If the name is NULL or name_len is 0, it returns + * data for the currently open input file corresponding to FILENAME + * (and it will not access the filetype argument, so that may be + * undefined). + * If the file is not already open, it tries to open it. + * The "filetype" argument should be one of: + * ">", ">>", "<", "|>", "|<", and "|&" + * If the file is not already open, and the fd argument is non-negative, + * gawk will use that file descriptor instead of opening the file + * in the usual way. If the fd is non-negative, but the file exists + * already, gawk ignores the fd and returns the existing file. It is + * the caller's responsibility to notice that the fd in the returned + * awk_input_buf_t does not match the requested value. Note that + * supplying a file descriptor is currently NOT supported for pipes. + * It should work for input, output, append, and two-way (coprocess) + * sockets. If the filetype is two-way, we assume that it is a socket! + * Note that in the two-way case, the input and output file descriptors + * may differ. To check for success, one must check that either of + * them matches. + */ + awk_bool_t (*api_get_file)(awk_ext_id_t id, + const char *name, + size_t name_len, + const char *filetype, + int fd, + /* + * Return values (on success, one or both should + * be non-NULL): + */ + const awk_input_buf_t **ibufp, + const awk_output_buf_t **obufp); + + /* Print nonfatal error message */ + void (*api_nonfatal)(awk_ext_id_t id, const char *format, ...); + } gawk_api_t; #ifndef GAWK /* these are not for the gawk code itself! */ @@ -698,6 +745,7 @@ typedef struct gawk_api { (api->api_set_argument(ext_id, count, new_array)) #define fatal api->api_fatal +#define nonfatal api->api_nonfatal #define warning api->api_warning #define lintwarn api->api_lintwarn @@ -759,6 +807,9 @@ typedef struct gawk_api { #define release_value(value) \ (api->api_release_value(ext_id, value)) +#define get_file(name, namelen, filetype, fd, ibuf, obuf) \ + (api->api_get_file(ext_id, name, namelen, filetype, fd, ibuf, obuf)) + #define register_ext_version(version) \ (api->api_register_ext_version(ext_id, version)) @@ -794,7 +845,7 @@ r_make_string(const gawk_api_t *api, /* needed for emalloc */ result->str_value.len = length; if (duplicate) { - emalloc(cp, char *, length + 2, "r_make_string"); + emalloc(cp, char *, length + 1, "r_make_string"); memcpy(cp, string, length); cp[length] = '\0'; result->str_value.str = cp; |