diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | extension/ChangeLog | 5 | ||||
-rw-r--r-- | extension/ordchr.c | 16 | ||||
-rw-r--r-- | gawkapi.h | 25 |
4 files changed, 42 insertions, 9 deletions
@@ -1,3 +1,8 @@ +2012-06-29 Arnold D. Robbins <arnold@skeeve.com> + + * gawkapi.h: Improve the documentation of the return values + per Andrew Schorr. + 2012-06-25 Arnold D. Robbins <arnold@skeeve.com> * TODO.xgawk: Updated. diff --git a/extension/ChangeLog b/extension/ChangeLog index a1ba2e90..a0cc713d 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -1,3 +1,8 @@ +2012-06-29 Arnold D. Robbins <arnold@skeeve.com> + + * ordchr.c (do_ord, do_chr): Improve argument checking and + lint messages. + 2012-06-25 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (EXTRA_DIST): Remove *.awk. diff --git a/extension/ordchr.c b/extension/ordchr.c index ba29d132..8d7eac8f 100644 --- a/extension/ordchr.c +++ b/extension/ordchr.c @@ -61,8 +61,12 @@ do_ord(int nargs, awk_value_t *result) if (get_argument(0, AWK_STRING, & str)) { ret = str.str_value.str[0]; - } else if (do_lint) - lintwarn(ext_id, "ord: called with no arguments"); + } else if (do_lint) { + if (nargs == 0) + lintwarn(ext_id, "ord: called with no arguments"); + else + lintwarn(ext_id, "ord: called with inappropriate argument(s)"); + } /* Set the return value */ return make_number(ret, result); @@ -91,8 +95,12 @@ do_chr(int nargs, awk_value_t *result) ret &= 0xff; str[0] = ret; str[1] = '\0'; - } else if (do_lint) - lintwarn(ext_id, "chr: called with no arguments"); + } else if (do_lint) { + if (nargs == 0) + lintwarn(ext_id, "chr: called with no arguments"); + else + lintwarn(ext_id, "chr: called with inappropriate argument(s)"); + } /* Set the return value */ return dup_string(str, 1, result); @@ -190,7 +190,10 @@ typedef struct gawk_api { #define gawk_do_mpfr 5 /* - * Get the count'th paramater, zero-based. + * All of the functions that return a value from inside gawk + * (get a parameter, get a global variable, get an array element) + * behave in the same way. + * * Returns false if count is out of range, or if actual paramater * does not match what is specified in wanted. In that case, * result->val_type will hold the actual type of what was passed. @@ -202,14 +205,25 @@ typedef struct gawk_api { +----------+----------+-------+-----------+ | String | Number | Array | Undefined | +---------+-----------+----------+----------+-------+-----------+ - | Type | String | String | false | false | String | + | Type | String | String | Number if| false | String | + | | | | it can be| | | + | | | |converted,| | | + | | | | else | | | + | | | | false | | | | of +-----------+----------+----------+-------+-----------+ - | Actual | Number | false | Number | false | Number | + | Actual | Number | String | Number | false | Number | | Value: +-----------+----------+----------+-------+-----------+ | | Array | false | false | Array | Array | | +-----------+----------+----------+-------+-----------+ | | Undefined | false | false | false | Undefined | +---------+-----------+----------+----------+-------+-----------+ + */ + + /* + * Get the count'th paramater, zero-based. + * Returns false if count is out of range, or if actual paramater + * does not match what is specified in wanted. In that case, + * result->val_type is as described above. */ awk_bool_t (*get_argument)(awk_ext_id_t id, size_t count, awk_valtype_t wanted, @@ -258,8 +272,9 @@ typedef struct gawk_api { /* * Lookup a variable, fills in value. No messing with the value * returned. Returns false if the variable doesn't exist - * or the wrong type was requested. - * In the latter case, fills in vaule->val_type with the real type. + * or if the wrong type was requested. + * In the latter case, fills in vaule->val_type with the real type, + * as described above. * Built-in variables (except PROCINFO) may not be accessed by an * extension. * |