"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "extension/rwarray.c" between
gawk-5.0.1.tar.xz and gawk-5.1.0.tar.xz

About: GNU awk - pattern scanning and processing language.

rwarray.c  (gawk-5.0.1.tar.xz):rwarray.c  (gawk-5.1.0.tar.xz)
/* /*
* rwarray.c - Builtin functions to binary read / write arrays to a file. * rwarray.c - Builtin functions to binary read / write arrays to a file.
* *
* Arnold Robbins * Arnold Robbins
* May 2009 * May 2009
* Redone June 2012 * Redone June 2012
* Improved September 2017 * Improved September 2017
*/ */
/* /*
* Copyright (C) 2009-2014, 2017, 2018 the Free Software Foundation, Inc. * Copyright (C) 2009-2014, 2017, 2018, 2020 the Free Software Foundation, Inc.
* *
* This file is part of GAWK, the GNU implementation of the * This file is part of GAWK, the GNU implementation of the
* AWK Programming Language. * AWK Programming Language.
* *
* GAWK is free software; you can redistribute it and/or modify * GAWK is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* GAWK is distributed in the hope that it will be useful, * GAWK is distributed in the hope that it will be useful,
skipping to change at line 119 skipping to change at line 119
uint32_t minor = MINOR; uint32_t minor = MINOR;
assert(result != NULL); assert(result != NULL);
make_number(0.0, result); make_number(0.0, result);
if (nargs < 2) if (nargs < 2)
goto out; goto out;
/* filename is first arg, array to dump is second */ /* filename is first arg, array to dump is second */
if (! get_argument(0, AWK_STRING, & filename)) { if (! get_argument(0, AWK_STRING, & filename)) {
fprintf(stderr, _("do_writea: argument 0 is not a string\n")); warning(ext_id, _("do_writea: first argument is not a string"));
errno = EINVAL; errno = EINVAL;
goto done1; goto done1;
} }
if (! get_argument(1, AWK_ARRAY, & array)) { if (! get_argument(1, AWK_ARRAY, & array)) {
fprintf(stderr, _("do_writea: argument 1 is not an array\n")); warning(ext_id, _("do_writea: second argument is not an array"));
errno = EINVAL; errno = EINVAL;
goto done1; goto done1;
} }
/* open the file, if error, set ERRNO and return */ /* open the file, if error, set ERRNO and return */
fp = fopen(filename.str_value.str, "wb"); fp = fopen(filename.str_value.str, "wb");
if (fp == NULL) if (fp == NULL)
goto done1; goto done1;
if (fwrite(MAGIC, 1, strlen(MAGIC), fp) != strlen(MAGIC)) if (fwrite(MAGIC, 1, strlen(MAGIC), fp) != strlen(MAGIC))
skipping to change at line 171 skipping to change at line 171
/* write_array --- write out an array or a sub-array */ /* write_array --- write out an array or a sub-array */
static awk_bool_t static awk_bool_t
write_array(FILE *fp, awk_array_t array) write_array(FILE *fp, awk_array_t array)
{ {
uint32_t i; uint32_t i;
uint32_t count; uint32_t count;
awk_flat_array_t *flat_array; awk_flat_array_t *flat_array;
if (! flatten_array(array, & flat_array)) { if (! flatten_array(array, & flat_array)) {
fprintf(stderr, _("write_array: could not flatten array\n")); warning(ext_id, _("write_array: could not flatten array"));
return awk_false; return awk_false;
} }
count = htonl(flat_array->count); count = htonl(flat_array->count);
if (fwrite(& count, 1, sizeof(count), fp) != sizeof(count)) if (fwrite(& count, 1, sizeof(count), fp) != sizeof(count))
return awk_false; return awk_false;
for (i = 0; i < flat_array->count; i++) { for (i = 0; i < flat_array->count; i++) {
if (! write_elem(fp, & flat_array->elements[i])) { if (! write_elem(fp, & flat_array->elements[i])) {
(void) release_flattened_array(array, flat_array); (void) release_flattened_array(array, flat_array);
return awk_false; return awk_false;
} }
} }
if (! release_flattened_array(array, flat_array)) { if (! release_flattened_array(array, flat_array)) {
fprintf(stderr, _("write_array: could not release flattened array \n")); warning(ext_id, _("write_array: could not release flattened array "));
return awk_false; return awk_false;
} }
return awk_true; return awk_true;
} }
/* write_elem --- write out a single element */ /* write_elem --- write out a single element */
static awk_bool_t static awk_bool_t
write_elem(FILE *fp, awk_element_t *element) write_elem(FILE *fp, awk_element_t *element)
skipping to change at line 291 skipping to change at line 291
char magic_buf[30]; char magic_buf[30];
assert(result != NULL); assert(result != NULL);
make_number(0.0, result); make_number(0.0, result);
if (nargs < 2) if (nargs < 2)
goto out; goto out;
/* directory is first arg, array to read is second */ /* directory is first arg, array to read is second */
if (! get_argument(0, AWK_STRING, & filename)) { if (! get_argument(0, AWK_STRING, & filename)) {
fprintf(stderr, _("do_reada: argument 0 is not a string\n")); warning(ext_id, _("do_reada: first argument is not a string"));
errno = EINVAL; errno = EINVAL;
goto done1; goto done1;
} }
if (! get_argument(1, AWK_ARRAY, & array)) { if (! get_argument(1, AWK_ARRAY, & array)) {
fprintf(stderr, _("do_reada: argument 1 is not an array\n")); warning(ext_id, _("do_reada: second argument is not an array"));
errno = EINVAL; errno = EINVAL;
goto done1; goto done1;
} }
fp = fopen(filename.str_value.str, "rb"); fp = fopen(filename.str_value.str, "rb");
if (fp == NULL) if (fp == NULL)
goto done1; goto done1;
memset(magic_buf, '\0', sizeof(magic_buf)); memset(magic_buf, '\0', sizeof(magic_buf));
if (fread(magic_buf, 1, strlen(MAGIC), fp) != strlen(MAGIC)) { if (fread(magic_buf, 1, strlen(MAGIC), fp) != strlen(MAGIC)) {
skipping to change at line 341 skipping to change at line 341
} }
minor = ntohl(minor); minor = ntohl(minor);
if (minor != MINOR) { if (minor != MINOR) {
errno = EBADF; errno = EBADF;
goto done1; goto done1;
} }
if (! clear_array(array.array_cookie)) { if (! clear_array(array.array_cookie)) {
errno = ENOMEM; errno = ENOMEM;
fprintf(stderr, _("do_reada: clear_array failed\n")); warning(ext_id, _("do_reada: clear_array failed"));
goto done1; goto done1;
} }
if (read_array(fp, array.array_cookie)) { if (read_array(fp, array.array_cookie)) {
make_number(1.0, result); make_number(1.0, result);
goto done0; goto done0;
} }
done1: done1:
update_ERRNO_int(errno); update_ERRNO_int(errno);
skipping to change at line 377 skipping to change at line 377
if (fread(& count, 1, sizeof(count), fp) != sizeof(count)) if (fread(& count, 1, sizeof(count), fp) != sizeof(count))
return awk_false; return awk_false;
count = ntohl(count); count = ntohl(count);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (read_elem(fp, & new_elem)) { if (read_elem(fp, & new_elem)) {
/* add to array */ /* add to array */
if (! set_array_element_by_elem(array, & new_elem)) { if (! set_array_element_by_elem(array, & new_elem)) {
fprintf(stderr, _("read_array: set_array_element failed\n")); warning(ext_id, _("read_array: set_array_element failed"));
return awk_false; return awk_false;
} }
} else } else
break; break;
} }
if (i != count) if (i != count)
return awk_false; return awk_false;
return awk_true; return awk_true;
 End of changes. 9 change blocks. 
9 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)