diff options
-rw-r--r-- | extension/ChangeLog | 6 | ||||
-rw-r--r-- | extension/select.c | 44 |
2 files changed, 18 insertions, 32 deletions
diff --git a/extension/ChangeLog b/extension/ChangeLog index 6778e2e6..efb38249 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -1,5 +1,11 @@ 2013-07-02 Andrew J. Schorr <aschorr@telemetry-investments.com> + * select.c (do_select): Now that the API flatten_array call has been + patched to ensure that the index values are strings, we can remove + the code to check for the AWK_NUMBER case. + +2013-07-02 Andrew J. Schorr <aschorr@telemetry-investments.com> + * select.c (do_select): Do not treat a numeric command value as a file descriptor unless the command type is empty. diff --git a/extension/select.c b/extension/select.c index be17dcf5..89dbf6c3 100644 --- a/extension/select.c +++ b/extension/select.c @@ -238,41 +238,21 @@ do_select(int nargs, awk_value_t *result) if (flatten_array(fds[i].array.array_cookie, &fds[i].flat)) { emalloc(fds[i].array2fd, int *, fds[i].flat->count*sizeof(int), "select"); for (j = 0; j < fds[i].flat->count; j++) { + long x; fds[i].array2fd[j] = -1; - switch (EL.index.val_type) { - case AWK_NUMBER: - if ((EL.value.val_type == AWK_UNDEFINED) || ((EL.value.val_type == AWK_STRING) && ! EL.value.str_value.len)) { - if (EL.index.num_value >= 0) - fds[i].array2fd[j] = EL.index.num_value; - if (fds[i].array2fd[j] != EL.index.num_value) { - fds[i].array2fd[j] = -1; - warning(ext_id, _("select: invalid numeric index `%g' in `%s' array (should be a non-negative integer)"), EL.index.num_value, argname[i]); - } - } + /* note: the index is always delivered as a string */ + + if (((EL.value.val_type == AWK_UNDEFINED) || ((EL.value.val_type == AWK_STRING) && ! EL.value.str_value.len)) && (integer_string(EL.index.str_value.str, &x) == 0) && (x >= 0)) + fds[i].array2fd[j] = x; + else if (EL.value.val_type == AWK_STRING) { + const awk_input_buf_t *buf; + if ((buf = get_file(EL.index.str_value.str, EL.index.str_value.len, EL.value.str_value.str, EL.value.str_value.len)) != NULL) + fds[i].array2fd[j] = buf->fd; else - warning(ext_id, _("select: numeric index `%g' in `%s' array should have an empty command type to be treated as a file descriptor"), EL.index.num_value, argname[i]); - break; - case AWK_STRING: - { - long x; - - if ((integer_string(EL.index.str_value.str, &x) == 0) && (x >= 0) && ((EL.value.val_type == AWK_UNDEFINED) || ((EL.value.val_type == AWK_STRING) && ! EL.value.str_value.len))) - fds[i].array2fd[j] = x; - else if (EL.value.val_type == AWK_STRING) { - const awk_input_buf_t *buf; - if ((buf = get_file(EL.index.str_value.str, EL.index.str_value.len, EL.value.str_value.str, EL.value.str_value.len)) != NULL) - fds[i].array2fd[j] = buf->fd; - else - warning(ext_id, _("select: get_file(`%s', `%s') failed in `%s' array"), EL.index.str_value.str, EL.value.str_value.str, argname[i]); - } - else - warning(ext_id, _("select: command type should be a string for `%s' in `%s' array"), EL.index.str_value.str, argname[i]); - } - break; - default: - warning(ext_id, _("select: invalid index type in `%s' array (must be a string or a non-negative integer"), argname[i]); - break; + warning(ext_id, _("select: get_file(`%s', `%s') failed in `%s' array"), EL.index.str_value.str, EL.value.str_value.str, argname[i]); } + else + warning(ext_id, _("select: command type should be a string for `%s' in `%s' array"), EL.index.str_value.str, argname[i]); if (fds[i].array2fd[j] < 0) { update_ERRNO_string(_("select: get_file failed")); if (! release_flattened_array(fds[i].array.array_cookie, fds[i].flat)) |