Thread: [Getdata-commits] SF.net SVN: getdata:[854] trunk/getdata (Page 8)
Scientific Database Format
Brought to you by:
ketiltrout
From: <ket...@us...> - 2013-10-22 20:55:26
|
Revision: 854 http://sourceforge.net/p/getdata/code/854 Author: ketiltrout Date: 2013-10-22 20:55:24 +0000 (Tue, 22 Oct 2013) Log Message: ----------- Merge OOP write and temp file code in the encoding bookkeeping layer. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/src/add.c trunk/getdata/src/encoding.c trunk/getdata/src/fpos.c trunk/getdata/src/getdata.c trunk/getdata/src/mod.c trunk/getdata/src/move.c trunk/getdata/src/parse.c trunk/getdata/src/putdata.c trunk/getdata/test/Makefile.am Added Paths: ----------- trunk/getdata/test/gzip_put_endian.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2013-10-19 03:12:50 UTC (rev 853) +++ trunk/getdata/ChangeLog 2013-10-22 20:55:24 UTC (rev 854) @@ -1,3 +1,12 @@ +2013-10-19 D. V. Wiebe <ge...@ke...> svn:854 + * src/add.c (_GD_Add) src/fpos.c (_GD_GetFilePos _GD_WriteSeek _GD_Seek) + src/getdata.c (_GD_DoRaw) src/mod.c (_GD_Change) src/move.c + (_GD_MogrifyFile) src/parse.c (_GD_ParseFieldSpec) src/putdata.c + (_GD_DoRawOut): Compute the swap argument correctly in _GD_InitRawIO calls. + * src/encoding.c (_GD_InitRawIO): Merge oop_write and temp file creation + code; also, assume that the caller has figured out the swap parameter. + * test/gzip_put_endian.c: Added. + 2013-10-19 D. V. Wiebe <ge...@ke...> svn:852 _GD_MakeTempFile patch from Seth: Modified: trunk/getdata/src/add.c =================================================================== --- trunk/getdata/src/add.c 2013-10-19 03:12:50 UTC (rev 853) +++ trunk/getdata/src/add.c 2013-10-22 20:55:24 UTC (rev 854) @@ -301,7 +301,8 @@ GD_SIZE(E->EN(raw,data_type))) == 0) _GD_SetError(D, GD_E_BAD_TYPE, entry->EN(raw,data_type), NULL, 0, NULL); else if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, - GD_FILE_WRITE | GD_FILE_TOUCH, 0)) + GD_FILE_WRITE | GD_FILE_TOUCH, + _GD_FileSwapBytes(D, E->fragment_index))) { ; } else if (D->fragment[E->fragment_index].ref_name == NULL) { Modified: trunk/getdata/src/encoding.c =================================================================== --- trunk/getdata/src/encoding.c 2013-10-19 03:12:50 UTC (rev 853) +++ trunk/getdata/src/encoding.c 2013-10-22 20:55:24 UTC (rev 854) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2012 D. V. Wiebe +/* Copyright (C) 2008-2013 D. V. Wiebe * *************************************************************************** * @@ -486,7 +486,6 @@ int fragment, const struct encoding_t *enc, unsigned int funcs, unsigned int mode, int swap) { - int temp_fd = -1; const int touch = mode & GD_FILE_TOUCH; int oop_write = 0; @@ -538,59 +537,41 @@ if (fragment == -1) fragment = E->fragment_index; - if (mode & GD_FILE_TEMP) { + if (oop_write || mode & GD_FILE_TEMP) { /* create temporary file in file[1] */ - if ((*enc->name)(D, (const char*)D->fragment[E->fragment_index].enc_data, + if ((*enc->name)(D, (const char*)D->fragment[fragment].enc_data, E->e->u.raw.file + 1, filebase, 1, 0)) { ; /* error already set */ - } else if ((*enc->open)(D->fragment[fragment].dirfd, E->e->u.raw.file + 1, swap, - GD_FILE_WRITE | GD_FILE_TEMP)) + dreturn("%i", 1); + return 1; + } else if ((*enc->open)(D->fragment[fragment].dirfd, E->e->u.raw.file + 1, + swap, GD_FILE_WRITE | GD_FILE_TEMP)) { _GD_SetError(D, GD_E_RAW_IO, 0, E->e->u.raw.file[1].name, errno, NULL); - } - - if (D->error) { dreturn("%i", 1); return 1; } - dreturn("%i", 0); - return 0; - } - if (oop_write) { - /* an out-of-place write requires us to open a temporary file and pass - * in its fd */ - if ((*enc->name)(D, (const char*)D->fragment[E->fragment_index].enc_data, - E->e->u.raw.file + 1, filebase, 1, 0)) - { - dreturn("%i", 1); - return 1; - } else if ((temp_fd = _GD_MakeTempFile(D, - D->fragment[E->fragment_index].dirfd, E->e->u.raw.file[1].name)) - < 0) - { - dreturn("%i", 1); - return 1; - } else if ((*enc->open)(temp_fd, E->e->u.raw.file + 1, _GD_FileSwapBytes(D, - E->fragment_index), GD_FILE_WRITE)) { - _GD_SetError(D, GD_E_RAW_IO, 0, E->e->u.raw.file[0].name, errno, NULL); - dreturn("%i", 1); - return 1; + if (oop_write) { + /* The read file in OOP mode is flagged as RW. */ + mode = GD_FILE_RDWR; + } else { + /* Temp file creation complete */ + dreturn("%i", 0); + return 0; } - /* The read file in OOP mode is flagged as RW. */ - mode = GD_FILE_RDWR; } /* open a regular file, if necessary */ if (E->e->u.raw.file[0].idata < 0) { - if ((*enc->name)(D, (const char*)D->fragment[E->fragment_index].enc_data, + if ((*enc->name)(D, (const char*)D->fragment[fragment].enc_data, E->e->u.raw.file, filebase, 0, 0)) { dreturn("%i", 1); return 1; - } else if ((*enc->open)(D->fragment[E->fragment_index].dirfd, - E->e->u.raw.file, _GD_FileSwapBytes(D, E->fragment_index), mode)) + } else if ((*enc->open)(D->fragment[fragment].dirfd, E->e->u.raw.file, swap, + mode)) { /* In oop_write mode, it doesn't matter if the old file doesn't exist */ if (!oop_write || errno != ENOENT) { @@ -603,7 +584,7 @@ } if (touch) - _GD_FiniRawIO(D, E, E->fragment_index, GD_FINIRAW_KEEP); + _GD_FiniRawIO(D, E, fragment, GD_FINIRAW_KEEP); dreturn("%i", 0); return 0; Modified: trunk/getdata/src/fpos.c =================================================================== --- trunk/getdata/src/fpos.c 2013-10-19 03:12:50 UTC (rev 853) +++ trunk/getdata/src/fpos.c 2013-10-22 20:55:24 UTC (rev 854) @@ -1,4 +1,4 @@ -/* Copyright (C) 2011-2012 D. V. Wiebe +/* Copyright (C) 2011-2013 D. V. Wiebe * *************************************************************************** * @@ -38,8 +38,11 @@ case GD_RAW_ENTRY: /* We must open the file to know its starting offset */ if (E->e->u.raw.file[0].idata < 0) - if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_READ, 0)) + if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_READ, + _GD_FileSwapBytes(D, E->fragment_index))) + { break; + } pos = E->e->u.raw.file[0].pos + E->EN(raw,spf) * D->fragment[E->fragment_index].frame_offset; break; @@ -171,7 +174,8 @@ if (_GD_FiniRawIO(D, E, E->fragment_index, GD_FINIRAW_KEEP)) { dreturn("%i", -1); return -1; - } else if (_GD_InitRawIO(D, E, NULL, 0, NULL, GD_EF_SEEK, GD_FILE_WRITE, 0)) + } else if (_GD_InitRawIO(D, E, NULL, 0, NULL, GD_EF_SEEK, GD_FILE_WRITE, + _GD_FileSwapBytes(D, E->fragment_index))) { dreturn("%i", -1); return -1; @@ -250,8 +254,11 @@ switch (E->field_type) { case GD_RAW_ENTRY: /* open/create the file, if necessary */ - if (_GD_InitRawIO(D, E, NULL, 0, NULL, GD_EF_SEEK, mode, 0)) + if (_GD_InitRawIO(D, E, NULL, 0, NULL, GD_EF_SEEK, mode, + _GD_FileSwapBytes(D, E->fragment_index))) + { break; + } /* The requested offset is before the start of the file, so I guess * pretend we've repositioned it... Modified: trunk/getdata/src/getdata.c =================================================================== --- trunk/getdata/src/getdata.c 2013-10-19 03:12:50 UTC (rev 853) +++ trunk/getdata/src/getdata.c 2013-10-22 20:55:24 UTC (rev 854) @@ -286,7 +286,7 @@ if (ns > 0) { /** open the file (and cache the fp) if it hasn't been opened yet. */ if (_GD_InitRawIO(D, E, NULL, 0, NULL, GD_EF_SEEK | GD_EF_READ, - GD_FILE_READ, 0)) + GD_FILE_READ, _GD_FileSwapBytes(D, E->fragment_index))) { free(databuffer); dreturn("%i", 0); Modified: trunk/getdata/src/mod.c =================================================================== --- trunk/getdata/src/mod.c 2013-10-19 03:12:50 UTC (rev 853) +++ trunk/getdata/src/mod.c 2013-10-22 20:55:24 UTC (rev 854) @@ -323,9 +323,11 @@ enc = gd_ef_ + E->e->u.raw.file[0].subenc; /* open the old file */ - if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_READ, 0)) + if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_READ, + _GD_FileSwapBytes(D, E->fragment_index))) + { break; - else if ((*enc->seek)(E->e->u.raw.file, 0, E->EN(raw,data_type), + } else if ((*enc->seek)(E->e->u.raw.file, 0, E->EN(raw,data_type), GD_FILE_READ) == -1) { _GD_SetError(D, GD_E_RAW_IO, 0, E->e->u.raw.file[0].name, errno, Modified: trunk/getdata/src/move.c =================================================================== --- trunk/getdata/src/move.c 2013-10-19 03:12:50 UTC (rev 853) +++ trunk/getdata/src/move.c 2013-10-22 20:55:24 UTC (rev 854) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2011 D. V. Wiebe +/* Copyright (C) 2008-2013 D. V. Wiebe * *************************************************************************** * @@ -138,7 +138,9 @@ } /* Open the input file, if necessary */ - if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_READ, 0)) { + if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_READ, + _GD_FileSwapBytes(D, E->fragment_index))) + { free(new_filebase); dreturn("%i", -1); return -1; Modified: trunk/getdata/src/parse.c =================================================================== --- trunk/getdata/src/parse.c 2013-10-19 03:12:50 UTC (rev 853) +++ trunk/getdata/src/parse.c 2013-10-22 20:55:24 UTC (rev 854) @@ -1545,7 +1545,8 @@ /* If the encoding scheme is unsupported, we can't add the field */ _GD_SetError(D, GD_E_UNSUPPORTED, 0, NULL, 0, NULL); else - _GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_WRITE | GD_FILE_TOUCH, 0); + _GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_WRITE | GD_FILE_TOUCH, + _GD_FileSwapBytes(D, E->fragment_index)); } /* Is this the first raw field ever defined? */ Modified: trunk/getdata/src/putdata.c =================================================================== --- trunk/getdata/src/putdata.c 2013-10-19 03:12:50 UTC (rev 853) +++ trunk/getdata/src/putdata.c 2013-10-22 20:55:24 UTC (rev 854) @@ -1,6 +1,6 @@ /* Copyright (C) 2003-2005 C. Barth Netterfield * Copyright (C) 2003-2005 Theodore Kisner - * Copyright (C) 2005-2012 D. V. Wiebe + * Copyright (C) 2005-2013 D. V. Wiebe * *************************************************************************** * @@ -93,7 +93,9 @@ } /* write data to file. */ - if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_WRITE, 0)) { + if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_WRITE, + _GD_FileSwapBytes(D, E->fragment_index))) + { free(databuffer); dreturn("%i", 0); return 0; Index: trunk/getdata/test =================================================================== --- trunk/getdata/test 2013-10-19 03:12:50 UTC (rev 853) +++ trunk/getdata/test 2013-10-22 20:55:24 UTC (rev 854) Property changes on: trunk/getdata/test ___________________________________________________________________ Modified: svn:ignore ## -485,6 +485,7 ## gzip_move_to gzip_nframes gzip_put +gzip_put_endian gzip_put_get header_complex hide Modified: trunk/getdata/test/Makefile.am =================================================================== --- trunk/getdata/test/Makefile.am 2013-10-19 03:12:50 UTC (rev 853) +++ trunk/getdata/test/Makefile.am 2013-10-22 20:55:24 UTC (rev 854) @@ -190,7 +190,8 @@ GLOBAL_TESTS=global_flags global_name global_ref global_ref_empty global_ref_set GZIP_TESTS=gzip_add gzip_get gzip_get_get gzip_get_get2 gzip_get_put \ - gzip_move_from gzip_move_to gzip_nframes gzip_put gzip_put_get + gzip_move_from gzip_move_to gzip_nframes gzip_put gzip_put_endian \ + gzip_put_get HEADER_TESTS=header_complex Added: trunk/getdata/test/gzip_put_endian.c =================================================================== --- trunk/getdata/test/gzip_put_endian.c (rev 0) +++ trunk/getdata/test/gzip_put_endian.c 2013-10-22 20:55:24 UTC (rev 854) @@ -0,0 +1,125 @@ +/* Copyright (C) 2013 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +#include <inttypes.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> +#include <stdio.h> + +int main(void) +{ +#ifndef TEST_GZIP + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data_gz = "dirfile/data.gz"; + const char *data = "dirfile/data"; + const char *format_data = "data RAW UINT16 8\n" +#ifdef WORDS_BIGENDIAN + "ENDIAN little\n"; +#else + "ENDIAN big\n"; +#endif + uint16_t c[8]; +#ifdef USE_GZIP + char command[4096]; + uint16_t d; +#endif + struct stat buf; + int fd, i, n, error, stat_data, unlink_data, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (i = 0; i < 8; ++i) + c[i] = (uint16_t)(0x102 * i); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + +#ifdef USE_GZIP + D = gd_open(filedir, GD_RDWR | GD_GZIP_ENCODED | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDWR | GD_GZIP_ENCODED); +#endif + n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT16, c); + error = gd_error(D); + + gd_discard(D); + + stat_data = stat(data_gz, &buf); +#ifdef USE_GZIP + if (stat_data) { + perror("stat"); + } + CHECKI(stat_data, 0); +#else + CHECKI(stat_data, -1); +#endif + +#ifdef USE_GZIP + /* uncompress */ + snprintf(command, 4096, "%s -f %s > /dev/null", GUNZIP, data); + if (gd_system(command)) { + r = 1; + } else { + fd = open(data, O_RDONLY | O_BINARY); + if (fd >= 0) { + i = 0; + while (read(fd, &d, sizeof(uint16_t))) { + if (i < 40 || i > 48) { + CHECKIi(i, d, 0); + } else + CHECKIi(i, d, 0x201 * (i - 40)); + i++; + } + CHECKI(i, 48); + close(fd); + } + } +#endif + + unlink_data = unlink(data); + unlink(format); + rmdir(filedir); + +#ifdef USE_GZIP + CHECKI(unlink_data, 0); + CHECKI(error, GD_E_OK); + CHECKI(n, 8); +#else + CHECKI(unlink_data, -1); + CHECKI(error, GD_E_UNSUPPORTED); + CHECKI(n, 0); +#endif + + return r; +#endif +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2013-10-24 00:48:05
|
Revision: 857 http://sourceforge.net/p/getdata/code/857 Author: ketiltrout Date: 2013-10-24 00:48:01 +0000 (Thu, 24 Oct 2013) Log Message: ----------- Throw out phpize and do things ourselves: not worth the effort. Modified Paths: -------------- trunk/getdata/bindings/php/Makefile.am trunk/getdata/bindings/php/test/Makefile.am trunk/getdata/configure.ac trunk/getdata/m4/php.m4 Added Paths: ----------- trunk/getdata/bindings/php/getdata.c trunk/getdata/bindings/php/php_getdata.h Removed Paths: ------------- trunk/getdata/bindings/php/getdata/ Property Changed: ---------------- trunk/getdata/bindings/php/ Index: trunk/getdata/bindings/php =================================================================== --- trunk/getdata/bindings/php 2013-10-24 00:37:28 UTC (rev 856) +++ trunk/getdata/bindings/php 2013-10-24 00:48:01 UTC (rev 857) Property changes on: trunk/getdata/bindings/php ___________________________________________________________________ Modified: svn:ignore ## -1,2 +1,3 ## Makefile Makefile.in +.deps Modified: trunk/getdata/bindings/php/Makefile.am =================================================================== --- trunk/getdata/bindings/php/Makefile.am 2013-10-24 00:37:28 UTC (rev 856) +++ trunk/getdata/bindings/php/Makefile.am 2013-10-24 00:48:01 UTC (rev 857) @@ -18,32 +18,23 @@ # along with GetData; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # -all-local: getdata/Makefile - cd getdata && ${MAKE} +php_LTLIBRARIES = getdata.la +AM_CFLAGS = ${WALL} ${WEXTRA} +AM_CPPFLAGS = ${CPPFLAGS} ${PHP_CPPFLAGS} +getdata_la_LDFLAGS = -module -avoid-version ${PHP_LDFLAGS} +getdata_la_LIBADD = ${PHP_LIBS} ../../src/libgetdata.la +getdata_la_SOURCES = getdata.c php_getdata.h +nodist_getdata_la_SOURCES = constants.c -BUILT_SOURCES=getdata/constants.c +BUILT_SOURCES=constants.c -getdata/constants.c: ../make_parameters ../../src/getdata.h +constants.c: ../make_parameters ../../src/getdata.h ../make_parameters h > $@ ../make_parameters: ../make_parameters.c ../../src/gd_config.h cd .. && ${MAKE} make_parameters -getdata/modules: getdata/Makefile - -getdata/Makefile: getdata/configure - cd getdata && \ - ./configure --enable-getdata && \ - ${SED} -e "s/make test/make check/" < Makefile > Makefile.temp && \ - mv -f Makefile.temp Makefile - -getdata/configure: getdata/config.m4 - cd getdata && ${PHPIZE} - clean-local: -if MAKE_PHPBINDINGS - cd getdata && ${PHPIZE} --clean -endif - rm -rf *~ getdata/*~ ${BUILT_SOURCES} getdata/Makefile.temp + rm -rf *~ ${BUILT_SOURCES} SUBDIRS=. test Copied: trunk/getdata/bindings/php/getdata.c (from rev 854, trunk/getdata/bindings/php/getdata/getdata.c) =================================================================== --- trunk/getdata/bindings/php/getdata.c (rev 0) +++ trunk/getdata/bindings/php/getdata.c 2013-10-24 00:48:01 UTC (rev 857) @@ -0,0 +1,4865 @@ +/* Copyright (C) 2013 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "php_getdata.h" +#include "php_ini.h" + +/* corresponding type of the PHP integer */ +#if SIZEOF_LONG == 4 +#define GDPHP_LONG GD_INT32 +typedef int32_t gdphp_long_t; +#elif SIZEOF_LONG == 8 +#define GDPHP_LONG GD_INT64 +typedef int64_t gdphp_long_t; +#endif + +/* PHP globals */ +ZEND_DECLARE_MODULE_GLOBALS(getdata) + +ZEND_BEGIN_MODULE_GLOBALS(getdata) + zend_bool degrade_complex; + zend_bool unpack; +ZEND_END_MODULE_GLOBALS(getdata) + +#ifdef ZTS +# define GDPHP_G(v) TSRMG(getdata_globals_id, zend_getdata_globals *, v) +# define dtracetsrm(fmt, ...) dtrace(fmt ", %p", __VA_ARGS__, tsrm_ls) +#else +# define GDPHP_G(v) (getdata_globals.v) +# define dtracetsrm dtrace +#endif + +/* PHP INI entries */ +PHP_INI_BEGIN() + STD_PHP_INI_ENTRY("getdata.degrade_complex", "true", PHP_INI_ALL, + OnUpdateBool, degrade_complex, zend_getdata_globals, getdata_globals) + STD_PHP_INI_ENTRY("getdata.unpack", "false", PHP_INI_ALL, OnUpdateBool, + unpack, zend_getdata_globals, getdata_globals) +PHP_INI_END() + +/* Common idioms */ +#define GDPHP_FETCH_DIRFILE(r, z) do { \ + r = (gdphp_dirfile*)zend_fetch_resource(&(z) TSRMLS_CC, -1, "Dirfile", NULL, \ + 2, le_gdphp_dirfile, le_gdphp_dirfile_persist); \ + if (!r) { GDPHP_RETURN_F; } \ +} while(0) + +#define GDPHP_RETURN_T do { dreturn("%s", "TRUE"); RETURN_TRUE; } while(0) +#define GDPHP_RETURN_F do { dreturn("%s", "FALSE"); RETURN_FALSE; } while(0) +#define GDPHP_CHECK_ERROR(D) do { if (gd_error(D)) GDPHP_RETURN_F; } while(0) +#define GDPHP_RETURN_ERROR(D) do { \ + if (gd_error(D)) GDPHP_RETURN_F; \ + else GDPHP_RETURN_T; \ +} while(0) +#define GDPHP_RETURN_BOOL(e) do { \ + if (e) GDPHP_RETURN_F; else GDPHP_RETURN_T; } while (0) + +#define GDPHP_PARSE(...) do { \ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, __VA_ARGS__) \ + != SUCCESS) { \ + GDPHP_RETURN_F; \ + } \ +} while(0) + +#define GDPHP_PARSED(vars, ...) do { \ + zval *gdphp_dirfile_zval; \ + gdphp_dirfile *gdphp_dirfile_rsrc; \ + GDPHP_PARSE("r" vars, &gdphp_dirfile_zval, __VA_ARGS__); \ + GDPHP_FETCH_DIRFILE(gdphp_dirfile_rsrc, gdphp_dirfile_zval); \ + D = gdphp_dirfile_rsrc->D; \ +} while(0) + +#define GDPHP_PARSED_ONLY() do { \ + zval *gdphp_dirfile_zval; \ + gdphp_dirfile *gdphp_dirfile_rsrc; \ + GDPHP_PARSE("r", &gdphp_dirfile_zval); \ + GDPHP_FETCH_DIRFILE(gdphp_dirfile_rsrc, gdphp_dirfile_zval); \ + D = gdphp_dirfile_rsrc->D; \ +} while(0) + +#define dtracephp() dtrace("%i, %p, %p, %p, %i", ht, return_value, \ + return_value_ptr, this_ptr, return_value_used) + +struct gdphp_din { + void *data; + gd_type_t type; + int free_din; + size_t ns; +}; + +/* error reporting */ +struct gdphp_context_t { + int p; + const char *k; + int i; +}; + +#define dtracectx(fmt, ...) dtrace(fmt " {%i,%s,%i}", __VA_ARGS__, ctx->p, \ + ctx->k ? ctx->k : "-", ctx->i) +#define GDPHP_CONTEXT(v) struct gdphp_context_t v = { 0, NULL, -1 }; +#define GDPHP_CONTEXTp(v,p) struct gdphp_context_t v = { p, NULL, -1 }; +#define GDPHP_DIE_BUFFER_LEN 1000 +#define GDPHP_DIE(x,fmt) do { \ + char gdphp_die_buffer[GDPHP_DIE_BUFFER_LEN]; \ + zend_error(E_ERROR,fmt " in %s", gdphp_context(gdphp_die_buffer,x)); \ +} while (0) +#define GDPHP_DIE2(x,fmt,...) do { \ + char gdphp_die_buffer[GDPHP_DIE_BUFFER_LEN]; \ + zend_error(E_ERROR,fmt " in %s", __VA_ARGS__, \ + gdphp_context(gdphp_die_buffer,x)); \ +} while (0) + +/* report the context (for error messages) */ +static char *gdphp_context(char *buffer, const struct gdphp_context_t *ctx) +{ + dtrace("%p, %p", buffer, ctx); + + if (ctx->k) { + if (ctx->i >= 0) + snprintf(buffer, GDPHP_DIE_BUFFER_LEN, + "element %i of '%s' of parameter %i", ctx->i, ctx->k, ctx->p + 1); + else + snprintf(buffer, GDPHP_DIE_BUFFER_LEN, "element '%s' of parameter %i", + ctx->k, ctx->p + 1); + } else if (ctx->i >= 0) + snprintf(buffer, GDPHP_DIE_BUFFER_LEN, "element %i of parameter %i", ctx->i, + ctx->p + 1); + else + snprintf(buffer, GDPHP_DIE_BUFFER_LEN, "parameter %i", ctx->p + 1); + + dreturn("\"%s\"", buffer); + return buffer; +} + +/* the dirfile resource */ +typedef struct _gdphp_dirfile { + DIRFILE *D; + char *callback; + int callback_len; + zval **callback_data; + char *key; + int key_len; +} gdphp_dirfile; + +int le_gdphp_dirfile; +int le_gdphp_dirfile_persist; + +static void gdphp_dirfile_dtor(zend_rsrc_list_entry *z TSRMLS_DC) +{ + dtracetsrm("%p", z); + + gdphp_dirfile *r = (gdphp_dirfile*)(z->ptr); + + gd_discard(r->D); + + if (r->callback) + efree(r->callback); + if (r->callback_data && *(r->callback_data)) + Z_DELREF_PP(r->callback_data); + efree(r->key); + efree(r); + + dreturnvoid(); +} + +static void gdphp_dirfile_pdtor(zend_rsrc_list_entry *z TSRMLS_DC) +{ + dtracetsrm("%p", z); + + gdphp_dirfile *r = (gdphp_dirfile*)(z->ptr); + + gd_discard(r->D); + + if (r->callback) + pefree(r->callback, 1); + if (r->callback_data) + Z_DELREF_PP(r->callback_data); + pefree(r->key, 1); + pefree(r, 1); + + dreturnvoid(); +} + +/* callback wrapper */ +static int gdphp_callback(gd_parser_data_t *pdata, void *extra) +{ + int sem = GD_SYNTAX_ABORT; + int new_line = 0; + char *ptr; + gdphp_dirfile *r = (gdphp_dirfile*)extra; + zval *response; + zval *function_name; + zval *zpdata; + zval **params[2] = { &zpdata, r->callback_data }; + + dtrace("%p, %p", pdata, r->callback_data); + + if (r->callback == NULL) { /* nothing to do */ + dreturn("%i", GD_SYNTAX_ABORT); + return GD_SYNTAX_ABORT; + } + + TSRMLS_FETCH(); + + /* make a zval for the function name */ + ALLOC_INIT_ZVAL(function_name); + ZVAL_STRINGL(function_name, r->callback, r->callback_len, 1); + + /* make a hashtable for the parser data */ + ALLOC_INIT_ZVAL(zpdata); + array_init(zpdata); + add_assoc_long(zpdata, "suberror", pdata->suberror); + add_assoc_long(zpdata, "linenum", pdata->linenum); + add_assoc_string(zpdata, "line", pdata->line, 1); + add_assoc_string(zpdata, "filename", (char*)pdata->filename, 1); + + /* call the callback */ + if (call_user_function_ex(CG(function_table), NULL, function_name, &response, + 2, params, 0, NULL TSRMLS_CC) != SUCCESS) + { + zend_error(E_ERROR, "Unable to execute GetData callback"); + } + + zval_ptr_dtor(&function_name); + + /* interpret the response */ + switch (Z_TYPE_P(response)) { + case IS_DOUBLE: /* I suppose */ + sem = (int)Z_DVAL_P(response); + break; + case IS_LONG: + sem = (int)Z_LVAL_P(response); + break; + case IS_STRING: /* this means rescan */ + ptr = strdup(Z_STRVAL_P(response)); + if (ptr == NULL) + zend_error(E_ERROR, "Out of memory"); + pdata->line = ptr; + sem = GD_SYNTAX_RESCAN; + new_line = 1; + break; + default: + zend_error(E_ERROR, "Bad response from GetData callback"); + } + + /* copy the line out of the zpdata hash, if necessary and possible */ + if (sem == GD_SYNTAX_RESCAN && new_line == 0) { + zval *line; + if (zend_hash_find(Z_ARRVAL_P(zpdata), "line", sizeof("line"), + (void**)&line) == SUCCESS) + { + if (Z_TYPE_P(line) == IS_STRING) { + ptr = strdup(Z_STRVAL_P(response)); + if (ptr == NULL) + zend_error(E_ERROR, "Out of memory"); + pdata->line = ptr; + } + } + } + + zval_ptr_dtor(&zpdata); + + dreturn("%i", sem); + return sem; +} + +/* create a dirfile resource */ +static gdphp_dirfile *gdphp_open(const char *dirfilename, int len, long flags, + const char *callback, int callback_len, zval **callback_data, int persist) +{ + gdphp_dirfile *r; + DIRFILE *D; + + dtrace("\"%s\", %i, 0x%lX, \"%s\", %i, %p, %i", dirfilename, len, flags, + callback, callback_len, callback_data, persist); + + /* create the resource */ + r = pemalloc(sizeof(gdphp_dirfile), persist); + memset(r, 0, sizeof(gdphp_dirfile)); + + r->callback_len = callback_len; + if (callback) + r->callback = pestrdup(callback, persist); + + r->key_len = len; + if (len > 0) { + r->key = pemalloc(len, persist); + memcpy(r->key, dirfilename, len); + } + + if (callback_data) { + Z_ADDREF_PP(callback_data); + r->callback_data = callback_data; + } + + /* open */ + if (callback) + D = gd_cbopen(dirfilename, (unsigned)flags, gdphp_callback, r); + else + D = gd_open(dirfilename, (unsigned)flags); + + /* record the dirfile */ + r->D = D; + + dreturn("%p", r); + return r; +} + +/* convert a complex pair to a 2-element array */ +static zval *gdphp_from_complex(zval *z, double r, double i) +{ + dtrace("%p, %g, %g", z, r, i); + + TSRMLS_FETCH(); + + if (z == NULL) + ALLOC_INIT_ZVAL(z); + + if (i == 0 && GDPHP_G(degrade_complex)) { + ZVAL_DOUBLE(z, r); + } else { + array_init(z); + add_index_double(z, 0, r); + add_index_double(z, 1, i); + } + + dreturn("%p", z); + return z; +} + +/* add a complex scalar to a hash */ +static void gdphp_add_assoc_complex(zval *z, const char *key, double r, + double i) +{ + dtrace("%p, \"%s\", %g, %g", z, key, r, i); + + add_assoc_zval(z, key, gdphp_from_complex(NULL, r, i)); + + dreturnvoid(); +} + +/* add an array of complex data to a hash */ +static void gdphp_add_assoc_cmparray(zval *z, const char *key, double *l, + int n) +{ + zval *a; + int i; + + dtrace("%p, \"%s\", %p, %i", z, key, l, n); + + ALLOC_INIT_ZVAL(a); + array_init(a); + + for (i = 0; i < n; ++i) + add_index_zval(a, i, gdphp_from_complex(NULL, l[i * 2], l[i * 2 + 1])); + + add_assoc_zval(z, key, a); + + dreturnvoid(); +} + +/* add an array of strings to a hash */ +static void gdphp_add_assoc_string_arr(zval *z, const char *key, char **l, + int n) +{ + zval *a; + int i; + + dtrace("%p, \"%s\", %p, %i", z, key, l, n); + + ALLOC_INIT_ZVAL(a); + array_init(a); + + for (i = 0; i < n; ++i) + add_index_string(a, i, l[i], 1); + + add_assoc_zval(z, key, a); + + dreturnvoid(); +} + +/* add scalars to a entry hash */ +static void gdphp_add_assoc_scalars(zval *z, gd_entry_t *E, unsigned mask) +{ + int i; + + zval *scalar; + zval *lm; + + dtrace("%p, %p, 0x%X", z, E, mask); + + ALLOC_INIT_ZVAL(scalar); + array_init(scalar); + + for (i = 0; i <= GD_MAX_POLYORD; ++i) + if (mask & (1 << i)) + if (E->scalar[i]) { + ALLOC_INIT_ZVAL(lm); + array_init(lm); + add_index_string(lm, 0, E->scalar[i], 1); + add_index_long(lm, 1, E->scalar_ind[i]); + add_index_zval(scalar, i, lm); + } + + add_assoc_zval(z, "scalar", scalar); + + dreturnvoid(); +} + +/* convert from a gd_entry_t to a hash */ +static void gdphp_from_entry(zval *z, gd_entry_t *E) +{ + dtrace("%p, %p", z, E); + + array_init(z); + + add_assoc_string(z, "field", E->field, 1); + add_assoc_long(z, "field_type", E->field_type); + add_assoc_long(z, "fragment_index", E->fragment_index); + switch (E->field_type) { + case GD_BIT_ENTRY: + case GD_SBIT_ENTRY: + gdphp_add_assoc_string_arr(z, "in_fields", E->in_fields, 1); + add_assoc_long(z, "bitnum", E->EN(bit,bitnum)); + add_assoc_long(z, "numbits", E->EN(bit,numbits)); + gdphp_add_assoc_scalars(z, E, 0x3); + break; + case GD_CARRAY_ENTRY: + add_assoc_long(z, "array_len", E->EN(scalar,array_len)); + /* fallthrough */ + case GD_CONST_ENTRY: + add_assoc_long(z, "const_type", E->EN(scalar,const_type)); + break; + case GD_LINCOM_ENTRY: + add_assoc_long(z, "n_fields", E->EN(lincom,n_fields)); + gdphp_add_assoc_string_arr(z, "in_fields", E->in_fields, + E->EN(lincom,n_fields)); + gdphp_add_assoc_cmparray(z, "m", (double*)E->EN(lincom,cm), + E->EN(lincom,n_fields)); + gdphp_add_assoc_cmparray(z, "b", (double*)E->EN(lincom,cb), + E->EN(lincom,n_fields)); + gdphp_add_assoc_scalars(z, E, ((1 << E->EN(lincom,n_fields)) - 1) * 9); + break; + case GD_LINTERP_ENTRY: + gdphp_add_assoc_string_arr(z, "in_fields", E->in_fields, 1); + add_assoc_string(z, "table", E->EN(linterp,table), 1); + break; + case GD_MULTIPLY_ENTRY: + case GD_DIVIDE_ENTRY: + gdphp_add_assoc_string_arr(z, "in_fields", E->in_fields, 2); + break; + case GD_PHASE_ENTRY: + gdphp_add_assoc_string_arr(z, "in_fields", E->in_fields, 1); + add_assoc_long(z, "shift", E->EN(phase,shift)); + gdphp_add_assoc_scalars(z, E, 0x1); + break; + case GD_POLYNOM_ENTRY: + gdphp_add_assoc_string_arr(z, "in_fields", E->in_fields, 1); + add_assoc_long(z, "poly_ord", E->EN(polynom,poly_ord)); + gdphp_add_assoc_cmparray(z, "a", (double*)E->EN(polynom,ca), + E->EN(polynom,poly_ord) + 1); + gdphp_add_assoc_scalars(z, E, (1 << (E->EN(polynom,poly_ord) + 1)) - 1); + break; + case GD_RECIP_ENTRY: + gdphp_add_assoc_string_arr(z, "in_fields", E->in_fields, 1); + gdphp_add_assoc_complex(z, "dividend", creal(E->EN(recip,cdividend)), + cimag(E->EN(recip,cdividend))); + gdphp_add_assoc_scalars(z, E, 0x1); + break; + case GD_RAW_ENTRY: + add_assoc_long(z, "spf", E->EN(raw,spf)); + add_assoc_long(z, "data_type", E->EN(raw,data_type)); + gdphp_add_assoc_scalars(z, E, 0x1); + break; + case GD_WINDOW_ENTRY: + gdphp_add_assoc_string_arr(z, "in_fields", E->in_fields, 2); + add_assoc_long(z, "windop", E->EN(window,windop)); + switch (E->EN(window,windop)) { + case GD_WINDOP_EQ: + case GD_WINDOP_NE: + add_assoc_long(z, "threshold", E->EN(window,threshold.u)); + break; + case GD_WINDOP_SET: + case GD_WINDOP_CLR: + add_assoc_long(z, "threshold", E->EN(window,threshold.i)); + break; + default: + add_assoc_double(z, "threshold", E->EN(window,threshold.r)); + break; + } + gdphp_add_assoc_scalars(z, E, 0x1); + break; + case GD_MPLEX_ENTRY: + gdphp_add_assoc_string_arr(z, "in_fields", E->in_fields, 2); + add_assoc_long(z, "count_val", E->EN(mplex,count_val)); + add_assoc_long(z, "period", E->EN(mplex,period)); + gdphp_add_assoc_scalars(z, E, 0x3); + break; + case GD_INDEX_ENTRY: + case GD_STRING_ENTRY: + case GD_NO_ENTRY: + case GD_ALIAS_ENTRY: + break; + } + + dreturnvoid(); +} + +/* interpret a long as a gd_type_t symbol */ +static gd_type_t gdphp_type_from_long(zval *z, struct gdphp_context_t *ctx) +{ + gd_type_t t = GD_UNKNOWN; + dtracectx("%p", z); + + if (Z_TYPE_P(z) != IS_LONG) + GDPHP_DIE(ctx, "Bad type code"); + + switch (Z_LVAL_P(z)) { + case GD_NULL: + case GD_UINT8: + case GD_INT8: + case GD_UINT16: + case GD_INT16: + case GD_UINT32: + case GD_INT32: + case GD_UINT64: + case GD_INT64: + case GD_FLOAT32: + case GD_FLOAT64: + case GD_COMPLEX64: + case GD_COMPLEX128: + t = Z_LVAL_P(z); + } + + dreturn("0x%X", t); + return t; +} + +static int gdphp_to_datum(void *dst, gd_type_t type, zval *src, int complain, + struct gdphp_context_t *ctx); + +/* convert an array to a complex number -- z is known to be an array; returns + * zero on success, non-zero (or doesn't return) on error */ +static int gdphp_to_complex(double *r, double *i, zval *z, int complain, + struct gdphp_context_t *ctx) +{ + int n, converted = 0; + + dtracectx("%p, %p, %p, %i", r, i, z, complain); + + HashTable *a = Z_ARRVAL_P(z); + + n = zend_hash_num_elements(a); + + if (n == 2) { + zval **d; + + if (zend_hash_index_find(a, 0, (void**)&d) == SUCCESS) + if (gdphp_to_datum(r, GD_FLOAT64, *d, 0, ctx) == 0) + converted++; + + if (zend_hash_index_find(a, 1, (void**)&d) == SUCCESS) + if (gdphp_to_datum(i, GD_FLOAT64, *d, 0, ctx) == 0) + converted++; + } + + if (converted < 2) { + if (complain) + GDPHP_DIE(ctx, "Bad numeric data"); + dreturn("%i", 1); + return 1; + } + + dreturn("%i (%g, %g)", 0, *r, *i); + return 0; +} + +/* return a GD type based on a PHP type */ +static gd_type_t gdphp_get_type(zval *z, struct gdphp_context_t *ctx) +{ + gd_type_t t = GD_UNKNOWN; + double r, i; + + dtracectx("%p", z); + + switch (Z_TYPE_P(z)) { + case IS_NULL: + t = GD_NULL; + break; + case IS_LONG: + case IS_BOOL: + t = GD_INT64; + break; + case IS_DOUBLE: + t = GD_FLOAT64; + break; + case IS_ARRAY: /* check for complex by tring to convert */ + if (gdphp_to_complex(&r, &i, z, 0, ctx) == 0) + t = GD_COMPLEX128; + } + + dreturn("0x%X", t); + return t; +} + +#define CCONVERT_ZVAL(t) \ + do { \ + switch (Z_TYPE_P(src)) { \ + double r, i; \ + case IS_NULL: ((t*)dst)[0] = ((t*)dst)[1] = 0; break; \ + case IS_LONG: case IS_BOOL: ((t*)dst)[0] = Z_LVAL_P(src); \ + ((t*)dst)[1] = 0; break; \ + case IS_DOUBLE: ((t*)dst)[0] = Z_DVAL_P(src); \ + ((t*)dst)[1] = 0; break; \ + case IS_ARRAY: gdphp_to_complex(&r, &i, src, 1, ctx); \ + ((t*)dst)[0] = r; ((t*)dst)[1] = i; break; \ + default: if (complain) GDPHP_DIE(ctx, "bad numeric type"); r = 1; \ + } \ + } while (0) + +#define CONVERT_ZVAL(t) \ + do { \ + switch (Z_TYPE_P(src)) { \ + double r, i; \ + case IS_LONG: case IS_BOOL: *((t*)dst) = Z_LVAL_P(src); break; \ + case IS_DOUBLE: *((t*)dst) = Z_DVAL_P(src); break; \ + case IS_ARRAY: gdphp_to_complex(&r, &i, src, 1, ctx); \ + *((t*)dst) = r; break; \ + default: if (complain) GDPHP_DIE(ctx, "bad numeric type"); r = 1; \ + } \ + } while (0) + +/* convert a zval to a C numeric type */ +static int gdphp_to_datum(void *dst, gd_type_t type, zval *src, int complain, + struct gdphp_context_t *ctx) +{ + int r = 0; + dtracectx("%p, 0x%X, %p, %i", dst, type, src, complain); + + switch (type) { + case GD_NULL: case GD_UNKNOWN: break; + case GD_UINT8: CONVERT_ZVAL( uint8_t); break; + case GD_INT8: CONVERT_ZVAL( int8_t); break; + case GD_UINT16: CONVERT_ZVAL(uint16_t); break; + case GD_INT16: CONVERT_ZVAL( int16_t); break; + case GD_UINT32: CONVERT_ZVAL(uint32_t); break; + case GD_INT32: CONVERT_ZVAL( int32_t); break; + case GD_UINT64: CONVERT_ZVAL(uint64_t); break; + case GD_INT64: CONVERT_ZVAL( int64_t); break; + case GD_FLOAT32: CONVERT_ZVAL( float); break; + case GD_FLOAT64: CONVERT_ZVAL( double); break; + case GD_COMPLEX64: CCONVERT_ZVAL( float); break; + case GD_COMPLEX128: CCONVERT_ZVAL( double); break; + } + + dreturn("%i", r); + return r; +} + +static gd_type_t gdphp_to_datum_and_type(void *datum, zval *z, + struct gdphp_context_t *ctx) +{ + gd_type_t t = GD_UNKNOWN; + + dtracectx("%p, %p", datum, z); + + switch (Z_TYPE_P(z)) { + case IS_LONG: + t = GDPHP_LONG; + *((gdphp_long_t*)datum) = Z_LVAL_P(z); + break; + case IS_DOUBLE: + t = GD_FLOAT64; + *((double*)datum) = Z_DVAL_P(z); + break; + case IS_ARRAY: + /* check if it is a complex array */ + if (gdphp_to_complex(datum, ((double*)datum) + 1, z, 0, ctx) == 0) { + t = GD_COMPLEX128; + break; + } + /* FALLTHROUGH */ + default: + GDPHP_DIE(ctx, "expected numeric scalar"); + } + + dreturn("0x%X", t); + return t; +} + +gd_static_inline_ char *gdphp_check_null_string(char *v) +{ + dtrace("\"%s\"", v); + if (v == NULL || v[0] == 0) { + dreturn("%p", NULL); + return NULL; + } + + dreturn("\"%s\"", v); + return v; +} + +static void gdphp_to_threshold(gd_triplet_t *t, gd_windop_t windop, zval *z, + struct gdphp_context_t *ctx) +{ + dtracectx("%p, %i, %p", t, windop, z); + + switch (windop) { + case GD_WINDOP_EQ: + case GD_WINDOP_NE: + gdphp_to_datum(&t->i, GD_INT64, z, 1, ctx); + break; + case GD_WINDOP_SET: + case GD_WINDOP_CLR: + gdphp_to_datum(&t->u, GD_UINT64, z, 1, ctx); + break; + default: + gdphp_to_datum(&t->r, GD_FLOAT64, z, 1, ctx); + break; + } + + dreturnvoid(); +} + +/* doesn't return on error */ +static void gdphp_validate_type(gd_type_t t, struct gdphp_context_t *ctx) { + dtracectx("0x%X", t); + + if (GD_SIZE(t) == 0) + GDPHP_DIE(ctx, "bad data type"); + + dreturnvoid(); +} + +/* convert a PHP array ot an array of complex data; returns length */ +static int gdphp_convert_cmparray(double *out, zval *z, int min, int max, + unsigned mask, struct gdphp_context_t *ctx) +{ + HashTable *a = Z_ARRVAL_P(z); + HashPosition i; + zval **d = NULL; + int n = -1; + unsigned key_len; + char *key; + long index; + + int *have; + + dtracectx("%p, %p, %i, %i, 0x%X", out, z, min, max, mask); + + /* remember which elements we've seen */ + have = emalloc(sizeof(int) * max); + memset(have, 0, sizeof(int) * max); + + for (index = 0; index < max; ++index) + if (mask & (1 << index)) + have[index] = 1; + + /* populate the C array */ + for (zend_hash_internal_pointer_reset_ex(a, &i); + zend_hash_get_current_data_ex(a, (void*)&d, &i) == SUCCESS; + zend_hash_move_forward_ex(a, &i)) + { + /* check key */ + if (zend_hash_get_current_key_ex(a, &key, &key_len, (ulong*)&index, 0, &i) + == HASH_KEY_IS_STRING) + { + GDPHP_DIE(ctx, "cannot use associative array"); + } else if (index < 0 || index >= max) + GDPHP_DIE2(ctx, "bad array index (%li)", index); + + if (!have[index]) { + gdphp_to_datum(out + index * 2, GD_COMPLEX128, *d, 1, ctx); + have[index] = 1; + } + } + + /* check for holes and calculate n */ + for (index = max - 1; index >= 0; --index) { + if (have[index] == 0 && n != -1) + GDPHP_DIE(ctx, "uninitialised data in numeric array"); + else if (have[index] && n == -1) + n = index + 1; + } + + if (n < min || n > max) + GDPHP_DIE(ctx, "bad array count"); + + efree(have); + + dreturn("%i", n); + return n; +} + +/* convert a PHP array to an array of strings; returns the number of elements */ +static int gdphp_convert_sarray(char **out, zval *z, int min, int max, + struct gdphp_context_t *ctx) +{ + HashTable *a = Z_ARRVAL_P(z); + HashPosition i; + zval **d = NULL; + int n = -1; + unsigned key_len; + char *key; + long index; + + dtracectx("%p, %p, %i, %i", out, z, min, max); + + /* santitise */ + memset(out, 0, sizeof(char*) * max); + + /* populate the C array */ + for (zend_hash_internal_pointer_reset_ex(a, &i); + zend_hash_get_current_data_ex(a, (void*)&d, &i) == SUCCESS; + zend_hash_move_forward_ex(a, &i)) + { + /* check key */ + if (zend_hash_get_current_key_ex(a, &key, &key_len, (ulong*)&index, 0, &i) + == HASH_KEY_IS_STRING) + { + GDPHP_DIE(ctx, "cannot use associative array"); + } else if (index < 0 || index >= max) + GDPHP_DIE2(ctx, "bad array index (%li)", index); + + if (Z_TYPE_PP(d) != IS_STRING) + GDPHP_DIE(ctx, "string array required"); + + out[index] = Z_STRVAL_PP(d); + } + + /* check for holes and calculate n */ + for (index = max - 1; index >= 0; --index) { + if (out[index] == NULL && n != -1) + GDPHP_DIE(ctx, "uninitialised data in string array"); + else if (out[index] && n == -1) + n = index + 1; + } + + if (n < min || n > max) + GDPHP_DIE(ctx, "bad string array count"); + + dreturn("%i", n); + return n; +} + +/* convert an array to data */ +static void gdphp_convert_array(struct gdphp_din *din, zval *zdata, + struct gdphp_context_t *ctx) +{ + HashTable *a = Z_ARRVAL_P(zdata); + HashPosition i; + zval **d = NULL; + char *key; + unsigned key_len; + long index; + + dtracectx("%p, %p", din, zdata); + + din->ns = 0; + + /* pass 1: validate data and determine ns */ + for (zend_hash_internal_pointer_reset_ex(a, &i); + zend_hash_get_current_data_ex(a, (void*)&d, &i) == SUCCESS; + zend_hash_move_forward_ex(a, &i)) + { + /* make sure this isn't an associative array */ + if (zend_hash_get_current_key_ex(a, &key, &key_len, (ulong*)&index, 0, &i) + == HASH_KEY_IS_STRING) + { + GDPHP_DIE(ctx, "cannot use associative arrays"); + } else if (index < 0) /* does zend_hash_get_current_key_ex return ulong + or a long? */ + GDPHP_DIE(ctx, "bad array index"); + + if ((unsigned long)index + 1 > din->ns) + din->ns = index + 1; + + if (din->type == GD_UNKNOWN) { + din->type = gdphp_get_type(*d, ctx); + if (din->type == GD_UNKNOWN) + GDPHP_DIE(ctx, "bad numeric type"); + else if (din->type == GD_NULL) + din->type = GD_UNKNOWN; + } + } + + if (din->ns == 0 || din->type == GD_UNKNOWN) { + din->type = GD_NULL; + din->ns = 0; + } else { + /* allocate the buffer */ + din->free_din = 1; + din->data = emalloc(din->ns * GD_SIZE(din->type)); + + /* zero */ + if (din->type == GD_FLOAT64 || din->type == GD_COMPLEX128) { + size_t j, ns = din->ns; + + if (din->type == GD_COMPLEX128) + ns *= 2; + + for (j = 0; j < ns; ++j) + ((double*)(din->data))[j] = NAN; + } else if (din->type == GD_FLOAT32 || din->type == GD_COMPLEX64) { + size_t j, ns = din->ns; + + if (din->type == GD_COMPLEX128) + ns *= 2; + + for (j = 0; j < ns; ++j) + ((float*)(din->data))[j] = (float)NAN; + } else + memset(din->data, 0, din->ns * GD_SIZE(din->type)); + + /* pass 2: convert the data */ + for (zend_hash_internal_pointer_reset_ex(a, &i); + zend_hash_get_current_data_ex(a, (void*)&d, &i) == SUCCESS; + zend_hash_move_forward_ex(a, &i)) + { + zend_hash_get_current_key_ex(a, &key, &key_len, (ulong*)&index, 0, &i); + + gdphp_to_datum(((char*)(din->data)) + index * GD_SIZE(din->type), + din->type, *d, 1, ctx); + } + } + + dreturn("0x%X, %zu", din->type, din->ns); +} + +/* convert input data */ +static struct gdphp_din gdphp_convert_data(zval *zdata1, zval *zdata2, int p1, + int p2) +{ + struct gdphp_din din; + + dtrace("%p, %p, %i, %i", zdata1, zdata2, p1, p2); + + if (zdata2 == NULL) { + GDPHP_CONTEXTp(ctx,p1); + + if (Z_TYPE_P(zdata1) == IS_ARRAY) { + din.type = GD_UNKNOWN; + gdphp_convert_array(&din, zdata1, &ctx); + } else + GDPHP_DIE(&ctx, "bad input data: expected array or type code"); + } else { + /* in the two argument case, the first argument is taken to be a type code + */ + GDPHP_CONTEXTp(ctx,p1); + + din.type = gdphp_type_from_long(zdata1, &ctx); /* doesn't return on error */ + + ctx.p = p2; + + switch (Z_TYPE_P(zdata2)) { + case IS_STRING: /* packed data -- just use it in place */ + din.data = Z_STRVAL_P(zdata2); + din.ns = Z_STRLEN_P(zdata2) / GD_SIZE(din.type); + din.free_din = 0; + break; + case IS_ARRAY: + gdphp_convert_array(&din, zdata2, &ctx); + break; + default: + GDPHP_DIE(&ctx, "bad input data: expected array or string"); + } + } + + dreturn("{%p, 0x%X, %i, %zu}", din.data, din.type, din.free_din, din.ns); + return din; +} + +static long gdphp_convert_long(zval *z, struct gdphp_context_t *ctx) +{ + long l; + + dtracectx("%p", z); + + if (Z_TYPE_P(z) != IS_LONG && Z_TYPE_P(z) != IS_DOUBLE) + GDPHP_DIE(ctx, "expected number"); + + convert_to_long(z); /* coerce */ + l = Z_LVAL_P(z); + + dreturn("%li", l); + return l; +} + +static double gdphp_convert_double(zval *z, struct gdphp_context_t *ctx) +{ + double d; + + dtracectx("%p", z); + + if (Z_TYPE_P(z) != IS_LONG && Z_TYPE_P(z) != IS_DOUBLE) + GDPHP_DIE(ctx, "expected number"); + + convert_to_double(z); /* coerce */ + d = Z_DVAL_P(z); + + dreturn("%g", d); + return d; +} + +/* convert PHP string with error checking */ +static char *gdphp_convert_string(zval *z, struct gdphp_context_t *ctx) +{ + char *s; + + dtracectx("%p", z); + + if (Z_TYPE_P(z) != IS_STRING) + GDPHP_DIE(ctx, "expected string"); + + s = Z_STRVAL_P(z); + + dreturn("\"%s\"", s); + return s; +} + +static void gdphp_entry_complex(double *v, HashTable *a, const char *key, + size_t len, int partial, struct gdphp_context_t *ctx) +{ + zval **z; + + dtracectx("%p, %p, \"%s\", %zu, %i", v, a, key, len, partial); + + if (zend_hash_find(a, key, len, (void**)&z) == SUCCESS) { + ctx->k = key; + gdphp_to_datum(v, GD_COMPLEX128, *z, 1, ctx); + ctx->k = NULL; + } else if (!partial) + GDPHP_DIE2(ctx, "required key '%s' not found", key); + + dreturnvoid(); +} + +static long gdphp_entry_long(HashTable *a, const char *key, size_t len, + int *missing, int partial, struct gdphp_context_t *ctx) +{ + long r = 0; + zval **z; + + dtracectx("%p, \"%s\", %zu, %p, %i", a, key, len, missing, partial); + + if (zend_hash_find(a, key, len, (void**)&z) == SUCCESS) { + ctx->k = key; + r = gdphp_convert_long(*z, ctx); + ctx->k = NULL; + if (missing != NULL) + *missing = 0; + } else if (missing != NULL) + *missing = 1; + else if (!partial) + GDPHP_DIE2(ctx, "required key '%s' not found", key); + + dreturn("%li", r); + return r; +} + +static double gdphp_entry_double(HashTable *a, const char *key, size_t len, + int partial, struct gdphp_context_t *ctx) +{ + double r = 0; + zval **z; + + dtracectx("%p, \"%s\", %zu, %i", a, key, len, partial); + + if (zend_hash_find(a, key, len, (void**)&z) == SUCCESS) { + ctx->k = key; + r = gdphp_convert_double(*z, ctx); + ctx->k = NULL; + } else if (!partial) + GDPHP_DIE2(ctx, "required key '%s' not found", key); + + dreturn("%g", r); + return r; +} + +static int gdphp_entry_infields(char **l, HashTable *a, int min, int max, + int partial, struct gdphp_context_t *ctx) +{ + zval **z; + int n = 0; + + dtracectx("%p, %p, %i, %i, %i", l, a, min, max, partial); + + if (zend_hash_find(a, "in_fields", sizeof("in_fields"), (void**)&z) == + SUCCESS) + { + ctx->k = "in_fields"; + if (Z_TYPE_PP(z) == IS_ARRAY) + n = gdphp_convert_sarray(l, *z, min, max, ctx); + else if (Z_TYPE_PP(z) == IS_STRING) { + if (min > 1) + GDPHP_DIE(ctx, "bad string array count"); + n = 1; + l[0] = gdphp_convert_string(*z, ctx); + } else + GDPHP_DIE(ctx, "expected string or string array"); + ctx->k = NULL; + } else if (!partial) + GDPHP_DIE(ctx, "required key 'in_fields' not found"); + + dreturn("%i", n); + return n; +} + +static int gdphp_entry_cmparray(double *l, HashTable *a, char *key, size_t len, + int min, int max, unsigned mask, int partial, struct gdphp_context_t *ctx) +{ + zval **z; + int n = 0; + + dtracectx("%p, %p, \"%s\", %zu, %i, %i, 0x%X", l, a, key, len, min, max, + mask); + + if (zend_hash_find(a, key, len, (void**)&z) == SUCCESS) { + ctx->k = key; + if (Z_TYPE_PP(z) == IS_ARRAY) + n = gdphp_convert_cmparray(l, *z, min, max, mask, ctx); + else if (Z_TYPE_PP(z) == IS_DOUBLE) { + if (min > 1) + GDPHP_DIE(ctx, "bad array count"); + n = 1; + l[0] = Z_DVAL_PP(z); + } else + GDPHP_DIE(ctx, "expected array or float"); + ctx->k = NULL; + } else if (!partial) + GDPHP_DIE2(ctx, "required key '%s' not found", key); + + dreturn("%i", n); + return n; +} + +/* populate an entry from the scalar array in an entry array; returns a + * bitmask of the elements set */ +static unsigned gdphp_entry_scalars(char** scalar, int *scalar_ind, + HashTable *a, unsigned mask, struct gdphp_context_t *ctx) +{ + unsigned mask_out = 0; + zval **z; + int i; + + dtracectx("%p, %p, %p, 0x%X", scalar, scalar_ind, a, mask); + + /* find 'scalar' in the entry array */ + if (zend_hash_find(a, "scalar", sizeof("scalar"), (void**)&z) != SUCCESS) { + dreturn("%i", 0); + return 0; + } + + ctx->k = "scalar"; + + /* 'scalar' must be an array (or null) */ + if (Z_TYPE_PP(z) == IS_NULL) { + ctx->k = NULL; + dreturn("%i", 0); + return 0; + } else if (Z_TYPE_PP(z) != IS_ARRAY) + GDPHP_DIE(ctx, "expected array"); + + /* loop through the array of scalars */ + a = Z_ARRVAL_PP(z); + for (i = 0; i < 2 * GD_MAX_LINCOM; ++i) { + if (!(mask & (1 << i))) + continue; + + /* get the i'th scalar array element */ + ctx->i = i; + if (zend_hash_index_find(a, i, (void**)&z) == SUCCESS) { + HashTable *sa; + + if (Z_TYPE_PP(z) == IS_NULL) + continue; + if (Z_TYPE_PP(z) != IS_ARRAY) + GDPHP_DIE(ctx, "expected array"); + + sa = Z_ARRVAL_PP(z); + + /* element zero should be the name of a scalar field. */ + if (zend_hash_index_find(sa, 0, (void**)&z) == SUCCESS) { + if (Z_TYPE_PP(z) != IS_STRING) + GDPHP_DIE(ctx, "expected scalar field name"); + scalar[i] = Z_STRVAL_PP(z); + } else + GDPHP_DIE(ctx, "element zero of should be scalar field name"); + + mask_out |= 1 << i; + + /* element one should be the index; if missing zero is assumed */ + if (zend_hash_index_find(sa, 1, (void**)&z) == SUCCESS) { + convert_to_long(*z); /* coerce */ + scalar_ind[i] = Z_LVAL_PP(z); + } else + scalar_ind[i] = 0; + } + } + + ctx->k = NULL; + ctx->i = -1; + dreturn("0x%02X", mask_out); + return mask_out; +} + +static char *gdphp_entry_string(HashTable *a, const char *key, + size_t len, int partial, struct gdphp_context_t *ctx) +{ + char *s = NULL; + zval **z; + + dtracectx("%p, \"%s\", %zu, %i", a, key, len, partial); + + if (zend_hash_find(a, key, len, (void**)&z) == SUCCESS) { + ctx->k = key; + s = gdphp_convert_string(*z, ctx); + ctx->k = NULL; + } else if (!partial) + GDPHP_DIE2(ctx, "required key '%s' not found", key); + + dreturn("\"%s\"", s); + return s; +} + +/* convert an entry array to a gd_entry_t; z is known to be an array */ +static void gdphp_to_entry(gd_entry_t *E, zval *z, const gd_entry_t *old_E, + int no_fragment, struct gdphp_context_t *ctx) +{ + /* lincom scalar masks */ + const unsigned lincom_mask[4] = { 0x00, 0x09, 0x1B, 0x3F }; + const int partial = (old_E != NULL); + + int n, missing = 0, min = 0, max = 0; + unsigned mask, tmask; + HashTable *a = Z_ARRVAL_P(z); + + dtracectx("%p, %p, %p, %i", E, z, old_E, no_fragment); + + if (old_E) + memcpy(E, old_E, sizeof(gd_entry_t)); + else + memset(E, 0, sizeof(gd_entry_t)); + + if (!partial) + E->field = gdphp_entry_string(a, "field", sizeof("field"), partial, ctx); + + E->field_type = gdphp_entry_long(a, "field_type", sizeof("field_type"), NULL, + partial, ctx); + + if (no_fragment) + E->fragment_index = 0; + else + E->fragment_index = gdphp_entry_long(a, "fragment_index", + sizeof("fragment_index"), NULL, partial, ctx); + + + switch (E->field_type) { + case GD_BIT_ENTRY: + case GD_SBIT_ENTRY: + gdphp_entry_infields((char**)E->in_fields, a, 1, 1, partial, ctx); + + mask = gdphp_entry_scalars(E->scalar, E->scalar_ind, a, 3, ctx); + + if (!(mask & 1)) + E->EN(bit,bitnum) = gdphp_entry_long(a, "bitnum", sizeof("bitnum"), + NULL, partial, ctx); + + if (!(mask & 2)) { + E->EN(bit,numbits) = gdphp_entry_long(a, "numbits", sizeof("numbits"), + &missing, partial, ctx); + + if (missing && !partial) + E->EN(bit,numbits) = 1; + } + break; + case GD_CARRAY_ENTRY: + E->EN(scalar,array_len) = gdphp_entry_long(a, "array_len", + sizeof("array_len"), NULL, partial, ctx); + /* FALLTHROUGH */ + case GD_CONST_ENTRY: + E->EN(scalar,const_type) = gdphp_entry_long(a, "const_type", + sizeof("const_type"), NULL, partial, ctx); + break; + case GD_LINCOM_ENTRY: + /* honour n_fields, if given */ + n = gdphp_entry_long(a, "n_fields", sizeof("n_fields"), &missing, + partial, ctx); + if (missing) { + min = 1; + max = GD_MAX_LINCOM; + } else if (n < 1 || n > GD_MAX_LINCOM) { + GDPHP_DIE2(ctx, "bad value for 'n_fields' (%i)", n); + } else + min = max = n; + + E->EN(lincom,n_fields) = gdphp_entry_infields((char**)E->in_fields, a, + min, max, partial, ctx); + + if (E->EN(lincom,n_fields) != 0) + min = max = E->EN(lincom,n_fields); + + mask = gdphp_entry_scalars(E->scalar, E->scalar_ind, a, lincom_mask[max], + ctx); + + E->comp_scal = 1; + tmask = (1 << max) - 1; + + if ((mask & tmask) != tmask) + gdphp_entry_cmparray((double*)E->EN(lincom,cm), a, "m", sizeof("m"), + min, max, mask, partial, ctx); + + if (((mask >> GD_MAX_LINCOM) & tmask) != tmask) + gdphp_entry_cmparray((double*)E->EN(lincom,cb), a, "b", sizeof("m"), + min, max, mask >> GD_MAX_LINCOM, partial, ctx); + else + E->EN(lincom,n_fields) = max; + break; + case GD_LINTERP_ENTRY: + gdphp_entry_infields((char**)E->in_fields, a, 1, 1, partial, ctx); + E->EN(linterp,table) = gdphp_entry_string(a, "table", sizeof("table"), + partial, ctx); + break; + case GD_MPLEX_ENTRY: + gdphp_entry_infields((char**)E->in_fields, a, 2, 2, partial, ctx); + mask = gdphp_entry_scalars(E->scalar, E->scalar_ind, a, 3, ctx); + + if (!(mask & 1)) + E->EN(mplex,count_val) = gdphp_entry_long(a, "count_val", + sizeof("count_val"), NULL, partial, ctx); + + if (!(mask & 2)) { + E->EN(mplex,period) = gdphp_entry_long(a, "period", sizeof("period"), + &missing, partial, ctx); + + if (missing) + E->EN(mplex,period) = 0; + } + break; + case GD_MULTIPLY_ENTRY: + case GD_DIVIDE_ENTRY: + gdphp_entry_infields((char**)E->in_fields, a, 2, 2, partial, ctx); + break; + case GD_PHASE_ENTRY: + gdphp_entry_infields((char**)E->in_fields, a, 1, 1, partial, ctx); + mask = gdphp_entry_scalars(E->scalar, E->scalar_ind, a, 1, ctx); + if (!(mask & 1)) + E->EN(phase,shift) = gdphp_entry_long(a, "shift", sizeof("shift"), NULL, + partial, ctx); + break; + case GD_POLYNOM_ENTRY: + /* honour poly_ord, if given */ + n = gdphp_entry_long(a, "poly_ord", sizeof("poly_ord"), &missing, partial, + ctx); + if (missing) { + min = 2; + max = GD_MAX_POLYORD + 1; + } else if (n < 1 || n > GD_MAX_POLYORD) { + GDPHP_DIE2(ctx, "bad value for 'poly_ord' (%i)", n); + } else + min = max = n + 1; + + gdphp_entry_infields((char**)E->in_fields, a, 1, 1, partial, ctx); + + mask = gdphp_entry_scalars(E->scalar, E->scalar_ind, a, (1 << max) - 1, + ctx); + + E->comp_scal = 1; + tmask = (1 << max) - 1; + if ((mask & tmask) != tmask) + E->EN(polynom,poly_ord) = + gdphp_entry_cmparray((double*)E->EN(polynom,ca), a, "a", sizeof("a"), + min, max, mask, partial, ctx) - 1; + else + E->EN(polynom,poly_ord) = max - 1; + break; + case GD_RAW_ENTRY: + E->EN(raw,data_type) = gdphp_entry_long(a, "data_type", + sizeof("data_type"), NULL, partial, ctx); + E->EN(raw,spf) = gdphp_entry_long(a, "spf", sizeof("spf"), NULL, partial, + ctx); + break; + case GD_RECIP_ENTRY: + gdphp_entry_infields((char**)E->in_fields, a, 1, 1, partial, ctx); + mask = gdphp_entry_scalars(E->scalar, E->scalar_ind, a, 1, ctx); + E->comp_scal = 1; + if (!(mask & 1)) + gdphp_entry_complex((double*)gd_csp_(E->EN(recip,cdividend)), a, + "dividend", sizeof("dividend"), partial, ctx); + break; + case GD_STRING_ENTRY: + /* nothing to do */ + break; + case GD_WINDOW_ENTRY: + gdphp_entry_infields((char**)E->in_fields, a, 2, 2, partial, ctx); + mask = gdphp_entry_scalars(E->scalar, E->scalar_ind, a, 1, ctx); + E->EN(window,windop) = gdphp_entry_long(a, "windop", sizeof("windop"), + NULL, partial, ctx); + if (!(mask & 1)) + switch (E->EN(window,windop)) { + case GD_WINDOP_EQ: + case GD_WINDOP_NE: + E->EN(window,threshold.i) = gdphp_entry_long(a, "threshold", + sizeof("threshold"), NULL, partial, ctx); + break; + case GD_WINDOP_SET: + case GD_WINDOP_CLR: + E->EN(window,threshold.u) = gdphp_entry_long(a, "threshold", + sizeof("threshold"), NULL, partial, ctx); + break; + default: + E->EN(window,threshold.r) = gdphp_entry_double(a, "threshold", + sizeof("threshold"), partial, ctx); + break; + } + break; + default: + GDPHP_DIE2(ctx, "bad field type (%i)", E->field_type); + } + + dreturnvoid(); +} + +/* convert a C string list to a array of strings */ +static void gdphp_to_string_array(zval *z, const char **l, int n) +{ + int i; + + dtrace("%p, %p, %i", z, l, n); + + array_init(z); + + for (i = 0; (l[i] && n == 0) || (n > 0 && i < n); ++i) + if (l[i] == NULL) + add_index_null(z, i); + else + add_index_string(z, i, l[i], 1); + + dreturnvoid(); +} + +/* convert a datum to a PHP value */ +static void gdphp_from_datum(zval *z, void *datum, gd_type_t type) +{ + dtrace("%p, %p, 0x%X", z, datum, type); + + switch (type) { + case GD_UINT8: + ZVAL_LONG(z, *((uint8_t*)datum)); + break; + case GD_INT8: + ZVAL_LONG(z, *((int8_t*)datum)); + break; + case GD_UINT16: + ZVAL_LONG(z, *((uint16_t*)datum)); + break; + case GD_INT16: + ZVAL_LONG(z, *((int16_t*)datum)); + break; + case GD_UINT32: + ZVAL_LONG(z, *((uint32_t*)datum)); + break; + case GD_INT32: + ZVAL_LONG(z, *((int32_t*)datum)); + break; + case GD_UINT64: + ZVAL_LONG(z, *((uint64_t*)datum)); + break; + case GD_INT64: + ZVAL_LONG(z, *((int64_t*)datum)); + break; + case GD_FLOAT32: + ZVAL_DOUBLE(z, *((float*)datum)); + break; + case GD_FLOAT64: + ZVAL_DOUBLE(z, *((double*)datum)); + break; + case GD_COMPLEX64: + gdphp_from_complex(z, ((float*)datum)[0], ((float*)datum)[1]); + break; + case GD_COMPLEX128: + gdphp_from_complex(z, ((double*)datum)[0], ((double*)datum)[1]); + break; + default: + ZVAL_NULL(z); + break; + } + + dreturnvoid(); +} + +/* convert a data vector to a PHP array -- <a> must already be initialised as + * an array */ +static void gdphp_data_to_array(zval *a, const void *data, gd_type_t type, + size_t n) +{ + size_t i; + + dtrace("%p, %p, 0x%X, %zu", a, data, type, n); + + switch (type) { + case GD_UINT8: + for (i = 0; i < n; ++i) + add_index_long(a, i, ((uint8_t*)(data))[i]); + break; + case GD_INT8: + for (i = 0; i < n; ++i) + add_index_long(a, i, ((int8_t*)(data))[i]); + break; + case GD_UINT16: + for (i = 0; i < n; ++i) + add_index_long(a, i, ((uint16_t*)(data))[i]); + break; + case GD_INT16: + for (i = 0; i < n; ++i) + add_index_long(a, i, ((int16_t*)(data))[i]); + break; + case GD_UINT32: + for (i = 0; i < n; ++i) + add_index_long(a, i, ((uint32_t*)(data))[i]); + break; + case GD_INT32: + for (i = 0; i < n; ++i) + add_index_long(a, i, ((int32_t*)(data))[i]); + break; + case GD_UINT64: + for (i = 0; i < n; ++i) + add_index_long(a, i, ((uint64_t*)(data))[i]); + break; + case GD_INT64: + for (i = 0; i < n; ++i) + add_index_long(a, i, ((int64_t*)(data))[i]); + break; + case GD_FLOAT32: + for (i = 0; i < n; ++i) + add_index_double(a, i, ((float*)(data))[i]); + break; + case GD_FLOAT64: + for (i = 0; i < n; ++i) + add_index_double(a, i, ((double*)(data))[i]); + break; + case GD_COMPLEX64: + for (i = 0; i < n; ++i) + add_index_zval(a, i, gdphp_from_complex(NULL, ((float*)(data))[i * 2], + ((float*)(data))[i * 2 + 1])); + case GD_COMPLEX128: + for (i = 0; i < n; ++i) + add_index_zval(a, i, gdphp_from_complex(NULL, ((double*)(data))[i * 2], + ((double*)(data))[i * 2 + 1])); + break; + default: + /* fill with nulls */ + for (i = 0; i < n; ++i) + add_index_null(a, i); + break; + } + + dreturnvoid(); +} + +static zval *gdphp_from_data(zval *z, size_t n, gd_type_t data_type, void *data, + int duplicate, int unpack) +{ + dtrace("%p, %zu, 0x%X, %p, %i, %i", z, n, data_type, data, duplicate, unpack); + + if (z == NULL) + ALLOC_INIT_ZVAL(z); + + if (unpack) { + array_init(z); + gdphp_data_to_array(z, data, data_type, n); + if (!duplicate) + efree(data); + } else { /* packed data */ + if (n == 0) { + if (!duplicate) + efree(data); + ZVAL_EMPTY_STRING(z); + } else { + if (!duplicate) + data = erealloc(data, n * GD_SIZE(data_type)); /* trim excess */ + ZVAL_STRINGL(z, data, n * GD_SIZE(data_type), duplicate); + } + } + + dreturn("%p", z); + return z; +} + +/* convert a zval to a long, with null checking - unfortunately PHP + * automatically converts nulls passed as longs into zero */ +static int gdphp_long_from_zval_null(zval *z, long dflt) +{ + long v = dflt; + + dtrace("%p, %li", z, dflt); + + if (z != NULL && Z_TYPE_P(z) != IS_NULL) { + convert_to_long(z); /* coerce */ + v = Z_LVAL_P(z); + } + + dreturn("%li", v); + return v; +} + +/* get the unpack value */ +static zend_bool gdphp_unpack(zval *z) +{ + zend_bool unpack; + + dtrace("%p", z); + + TSRMLS_FETCH(); + + if (z != NULL && Z_TYPE_P(z) != IS_NULL) { + convert_to_boolean(z); /* coerce */ + unpack = Z_BVAL_P(z); + } else + unpack = GDPHP_G(unpack); + + dreturn("%i", unpack); + return unpack; +} + +static void gdphp_init_globals(zend_getdata_globals *g) +{ + dtrace("%p", g); + + g->unpack = 0; + g->degrade_complex = 1; + + dreturnvoid(); +} + +/* module init function */ +PHP_MINIT_FUNCTION(getdata) +{ + dtracetsrm("%i, %i", type, module_number); + + /* initialise globals */ + ZEND_INIT_MODULE_GLOBALS(getdata, gdphp_init_globals, NULL); + + /* Register constants */ + gdphp_register_constants(module_number); + + /* conveniences */ + zend_register_long_constant(ZEND_STRS("GD_INT"), GDPHP_LONG, CONST_CS, + module_number TSRMLS_CC); + zend_register_long_constant(ZEND_STRS("GD_FLOAT"), GD_FLOAT64, CONST_CS, + module_number TSRMLS_CC); + + /* INI entries */ + REGISTER_INI_ENTRIES(); + + /* dirfile resource */ + le_gdphp_dirfile = zend_register_list_destructors_ex(gdphp_dirfile_dtor, NULL, + "Dirfile", module_number); + le_gdphp_dirfile_persist = zend_register_list_destructors_ex(NULL, + gdphp_dirfile_pdtor, "Dirfile", module_number); + + dreturn("%i", 0); + return 0; +} + +PHP_MSHUTDOWN_FUNCTION(getdata) +{ + dtracetsrm("%i, %i", type, module_number); + + UNREGISTER_INI_ENTRIES(); + + dreturn("%i", SUCCESS); + return SUCCESS; +} + +PHP_MINFO_FUNCTION(getdata) +{ + dtracetsrm("%p", zend_module); + + php_info_print_table_start(); + php_info_print_table_header(2, "GetData support", "enabled"); + php_info_print_table_row(2, "Version", PACKAGE_VERSION); + php_info_print_table_end(); + + dreturnvoid(); +} + + +/* BINDINGS */ +PHP_FUNCTION(gd_add) +{ + zval *z; + + gd_entry_t E; + DIRFILE *D; + + GDPHP_CONTEXTp(ctx,2); + + dtracephp(); + + GDPHP_PARSED("a", &z); + + gdphp_to_entry(&E, z, NULL, 0, &ctx); + + /* no need to free entry strings */ + GDPHP_RETURN_BOOL(gd_add(D, &E)); +} + +PHP_FUNCTION(gd_add_alias) +{ + char *field_code, *target; + int field_code_len, target_len; + long index = 0; + + DIRFILE *D; + + dtracephp(); + + GDPHP_PARSED("ss|l", &field_code, &field_code_len, &target, &target_len, + &index); + + GDPHP_RETURN_BOOL(gd_add_alias(D, field_code, target, index)); +} + +PHP_FUNCTION(gd_add_bit) +{ + char *field_code, *in_field; + int field_code_len, in_field_len; + long bitnum, index = 0; + zval *znumbits = NULL; + + int numbits; + DIRFILE *D; + + dtracephp(); + + GDPHP_PARSED("ssl|zl", &field_code, &field_code_len, &in_field, &in_field_len, + &bitnum, &znumbits, &index); + + numbits = gdphp_long_from_zval_null(znumbits, 1); + + GDPHP_RETURN_BOOL(gd_add_bit(D, field_code, in_field, bitnum, numbits, + index)); +} + +PHP_FUNCTION(gd_add_carray) +{ + char *field_code; + int field_code_len; + long data_type; + zval *z1, *z2 = NULL, *z3 = NULL; + DIRFILE *D; + + int r; + struct gdphp_din din; + int index = 0; + + dtracephp(); + + GDPHP_PARSED("slz|zz", &field_code, &field_code_len, &data_type, &z1, &z2, + &z3); + + /* allowed types for the last three parameters: + * + * 1: anything: data + * 2: array, anything: data, index + * 3: other, anything: type, data + * 4: other, anything, anything: type, data, index + */ + if (z2 == NULL) /* 1 */ + din = gdphp_convert_data(z1, NULL, 3, 4); + else if (Z_TYPE_P(z1) == IS_ARRAY) { /* 2 */ + din = gdphp_convert_data(z1, NULL, 3, 3); + convert_to_long(z2); /* coerce */ + index = Z_LVAL_P(z2); + } else if (z3 == NULL) /* 3 */ + din = gdphp_convert_data(z1, z2, 3, 4); + else { /* 4 */ + din = gdphp_convert_data(z1, z2, 3, 4); + convert_to_long(z3); /* coerce */ + index = Z_LVAL_P(z3); + } + + r = gd_add_carray(D, field_code, data_type, din.ns, din.type, din.data, + index); + + if (din.free_din) + efree(din.data); + + GDPHP_RETURN_BOOL(r); +} + +PHP_FUNCTION(gd_add_const) +{ + char *field_code; + int field_code_len; + long data_type, index = 0; + zval *z; + + DIRFILE *D; + char data[16]; + GDPHP_CONTEXTp(ctx,3); + + dtracephp(); + + GDPHP_PARSED("slz|l", &field_code, &field_code_len, &data_type, &z, &index); + + /* might as well convert to the storage type now */ + gdphp_to_datum(data, data_type, z, 1, &ctx); + + GDPHP_RETURN_BOOL(gd_add_const(D, field_code, data_type, data_type, data, + index)); +} + +PHP_FUNCTION(gd_add_divide) +{ + char *field_code, *in1, *in2; + int field_code_len, in1_len, in2_len; + long index = 0; + + DIRFILE *D; + + dtracephp(); + + GDPHP_PARSED("sss|l", &field_code, &field_code_len, &in1, &in1_len, &in2, + &in2_len, &index); + + GDPHP_RETURN_BOOL(gd_add_divide(D, field_code, in1, in2, index)); +} + +PHP_FUNCTION(gd_add_lincom) +{ + char *field_code; + int field_code_len; + long index = 0; + zval *zin, *zm, *zb; + + char *in[GD_MAX_LINCOM]; + double m[GD_MAX_LINCOM * 2]; + double b[GD_MAX_LINCOM * 2]; + int n; + + DIRFILE *D; + GDPHP_CONTEXT(ctx); + + dtracephp(); + + GDPHP_PARSED("saaa|l", &field_code, &field_code_len, &zin, &zm, &zb, &index); + + /* these don't return on error */ + ctx.p = 2; + n = gdphp_convert_sarray((char**)in, zin, 1, GD_MAX_LINCOM, &ctx); + ctx.p = 3; + gdphp_convert_cmparray(m, zm, n, n, 0, &ctx); + ctx.p = 4; + gdphp_convert_cmparray(b, zb, n, n, 0, &ctx); + + GDPHP_RETURN_BOOL(gd_add_clincom(D, field_code, n, (const char**)in, + (GD_DCOMPLEXP_t)m, (GD_DCOMPLEXP_t)b, index)); +} + +PHP_FUNCTION(gd_add_linterp) +{ + char *field_code, *in_field, *table; + int field_code_len, in_field_len, table_len; + long index = 0; + + DIRFILE *D; + + dtracephp(); + + GDPHP_PARSED("ssp|l", &field_code, &field_code_len, &in_field, &in_field_len, + &table, &table_len, &index); + + GDPHP_RETURN_BOOL(gd_add_linterp(D, field_code, in_field, table, index)); +} + +PHP_FUNCTION(gd_add_mplex) +{ + char *field_code, *in1, *in2; + int field_code_len, in1_len, in2_len; + long count, period = 0, index = 0; + + DIRFILE *D; + + dtracephp(); + + GDPHP_PARSED("sssl|ll", &field_code, &field_code_len, &in1, &in1_len, &in2, + &in2_len, &count, &period, &index); + + GDPHP_RETURN_BOOL(gd_add_mplex(D, field_code, in1, in2, count, period, + index)); +} + +PHP_FUNCTION(gd_add_multiply) +{ + char *field_code, *in1, *in2; + int field_code_len, in1_len, in2_len; + long index = 0; + + DIRFILE *D; + + dtracephp(); + + GDPHP_PARSED("sss|l", &field_code, &field_code_len, &in1, &in1_len, &in2, + &in2_len, &index); + + GDPHP_RETURN_BOOL(gd_add_multiply(D, field_code, in1, in2, index)); +} + +PHP_FUNCTION(gd_add_phase) +{ + char *field_code, *in_field; + int field_code_len, in_field_len; + long shift, index = 0; + + DIRFILE *D; + + dtracephp(); + + GDPHP_PARSED("ssl|l", &field_code, &field_code_len, &in_field, &in_field_len, + &shift, &index); + + GDPHP_RETURN_BOOL(gd_add_phase(D, field_code, in_field, shift, index)); +} + +PHP_FUNCTION(gd_add_polynom) +{ + char *field_code, *in_field; + int field_code_len, in_field_len; + long index = 0; + zval *za; + + double a[GD_MAX_POLYORD + 1]; + int o; + + DIRFILE *D; + GDPHP_CONTEXTp(ctx,3); + + dtracephp(); + + GDPHP_PARSED("ssa|l", &field_code, &field_code_len, &in_field, &in_field_len, + &za, &index); + + /* doesn't return on error */ + o = gdphp_convert_cmparray(a, za, 2, GD_MAX_POLYORD + 1, 0, &ctx) - 1; + + GDPHP_RETURN_BOOL(gd_add_cpolynom(D, field_code, o, in_field, + (GD_DCOMPLEXP_t)a, index)); +} + +PHP_FUNCTION(gd_add_raw) +{ + char *field_code; + int field_code_len; + long data_type, spf, index = 0; + + DIRFILE *D; + + dtracephp(); + + GDPHP_PARSED("pll|l", &field_code, &field_code_len, &data_type, &spf, + &index); + + GDPHP_RETURN_BOOL(gd_add_raw(D, field_code, data_type, spf, index)); +} + +PHP_FUNCTION(gd_add_recip) +{ + char *field_code, *in_field; + int field_code_len, in_field_len; + zval *zdividend; + long index = 0; + + double dividend[2]; + DIRFILE *D; + GDPHP_CONTEXTp(ctx,3); + + dtracephp(); + + GDPHP_PARSED("ssz|l", &field_code, &field_code_len, &in_field, &in_field_len, + &zdividend, &index); + + gdphp_to_datum(dividend, GD_COMPLEX128, zdividend, 1, &ctx); + + GDPHP_RETURN_BOOL(gd_add_crecip89(D, field_code, in_field, dividend, index)); +} + +PHP_FUNCTION(gd_add_sbit) +{ + char *field_code, *in_field; + int field_code_len, in_field_len; + long bitnum, index = 0; + zval *znumbits = NULL; + + int numbits; + DIRFILE *D; + + dtracephp(); + + GDPHP_PARSED("ssl|zl", &field_code, &field_code_len, &in_field, &in_field_len, + &bitnum, &znumbits, &index); + + numbits = gdphp_long_from_zval_null(znumbits, 1); + + GDPHP_RETURN_BOOL(gd_add_sbit(D, field_code, in_field, bitnum, numbits, + index)); +} + +PHP_FUNCTION(gd_add_spec) +{ + char *spec; + int spec_len; + long index = 0; + + DIRFILE *D; + + dtracephp(); + + GDPHP_PARSED("s|l", &spec, &spec_len, &index); + + GDPHP_RETURN_BOOL(gd_add_spec(D, spec, index)); +} + +PHP_FUNCTION(gd_add_string) +{ + char *field_code, *value; + int field_code_len, value_len; + long index = 0; + + DIRFILE *D; + + dtracephp(); + + GDPHP_PARSED("ss|l", &field_code, &field_code_len, &value, &value_len, + &index); + + GDPHP_RETURN_BOOL(gd_add_string(D, field_code, value, index)); +} + +PHP_FUNCTION(gd_add_window) +{ + char *field_code, *in1, *in2; + int field_code_len, in1_len, in2_len; + long windop, index = 0; + zval *zthreshold; + + gd_triplet_t threshold; + DIRFILE *D; + GDPHP_CONTEXTp(ctx,5); + + dtracephp(); + + GDPHP_PARSED("ssslz|l", &field_code, &field_code_len, &in1, &in1_len, &in2, + &in2_len, &windop, &zthreshold, &index); + + gdphp_to_threshold(&threshold, windop, zthreshold, &ctx); + + GDPHP_RETURN_BOOL(gd_add_window(D, field_code, in1, in2, windop, threshold, + index)); +} + +PHP_FUNCTION(gd_alias_target) +{ + char *field_code; + int field_code_len; + + DIRFILE *D; + const char *s; + + dtracephp(); + + GDPHP_PARSED("s", &field_code, &field_code_len); + + s = gd_alias_target(D, field_code); + + if (s == NULL) + GDPHP_RETURN_F; + + dreturn("\"%s\"", s); + RETURN_STRING(s, 1); +} + +PHP_FUNCTION(gd_aliases) +{ + char *field_code; + int field_code_len; + + DIRFILE *D; + const char **fl; + + dtracephp(); + + GDPHP_PARSED("s", &field_code, &field_code_len); + + fl = gd_aliases(D, field_code); + + if (fl == NULL) + GDPHP_RETURN_F; + + gdphp_to_string_array(return_value, fl, 0); + + dreturnvoid(); +} + +PHP_FUNCTION(gd_alter_affixes) +{ + zval *zprefix, *zsuffix; + long index; + + char *prefix = NULL, *suffix = NULL; + DIRFILE *D; + + dtracephp(); + + GDPHP_PARSED("lzz", &index, &zprefix, &zsuffix); + + if (Z_TYPE_P(zprefix) != IS_NULL) { + convert_to_string(zprefix); /* coerce */ + prefix = Z_STRVAL_P(zprefix); + } + + if (Z_TYPE_P(zsuffix) != IS_NULL) { + convert_to_string(zsuffix); /* coerce */ + suffix = Z_STRVAL_P(zsuffix); + } + + GDPHP_RETURN_BOOL(gd_alter_affixes(D, index, prefix, suffix)); +} + +PHP_FUNCTION(gd_alter_bit) +{ + char *field_code, *in_field = N... [truncated message content] |
From: <ket...@us...> - 2013-10-26 02:36:50
|
Revision: 862 http://sourceforge.net/p/getdata/code/862 Author: ketiltrout Date: 2013-10-26 02:36:47 +0000 (Sat, 26 Oct 2013) Log Message: ----------- Add version information to public header. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/cmake/CMakeLists.txt trunk/getdata/configure.ac trunk/getdata/src/getdata.h.in trunk/getdata/src/internal.h Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2013-10-25 22:23:34 UTC (rev 861) +++ trunk/getdata/ChangeLog 2013-10-26 02:36:47 UTC (rev 862) @@ -1,3 +1,8 @@ +2013-10-26 D. V. Wiebe <ge...@ke...> svn:862 + * src/getdata.h.in: Add GD_GETDATA_VERSION and GD_GETDATA_INT_VERSION + * configure.ac cmake/CMakeLists.txt: Calculate GD_GETDATA_VERSION and + GD_GETDATA_INT_VERSION. + 2013-10-19 D. V. Wiebe <ge...@ke...> svn:854 * src/add.c (_GD_Add) src/fpos.c (_GD_GetFilePos _GD_WriteSeek _GD_Seek) src/getdata.c (_GD_DoRaw) src/mod.c (_GD_Change) src/move.c Modified: trunk/getdata/cmake/CMakeLists.txt =================================================================== --- trunk/getdata/cmake/CMakeLists.txt 2013-10-25 22:23:34 UTC (rev 861) +++ trunk/getdata/cmake/CMakeLists.txt 2013-10-26 02:36:47 UTC (rev 862) @@ -26,7 +26,7 @@ #TODO add configure add_definitions( -DPACKAGE_NAME=\"GetData\" - -DPACKAGE_VERSION=\"0.8.x\" + -DPACKAGE_VERSION=\"0.9.x\" -DPACKAGE_BUGREPORT=\"get...@li...\" -DUNALIGNED_ACCESS_OK ) @@ -34,6 +34,10 @@ # kst2 doesn't need the legacy API set(DEFINE_GD_LEGACY_API "/* #undef GD_LEGACY_API */") +# Version macros +set(DEFINE_GD_GETDATA_VERSION "#define GD_GETDATA_VERSION \"0.9.x\"") +set(DEFINE_GD_GETDATA_INT_VERSION "#define GD_GETDATA_INT_VERSION 900") + if(MSVC) ## Substitutions needed to build getdata.h # build in ANSI C mode Modified: trunk/getdata/configure.ac =================================================================== --- trunk/getdata/configure.ac 2013-10-25 22:23:34 UTC (rev 861) +++ trunk/getdata/configure.ac 2013-10-26 02:36:47 UTC (rev 862) @@ -362,6 +362,15 @@ GD_MSYS_SHELL +dnl verion info +AC_SUBST([DEFINE_GD_GETDATA_VERSION], ["#define GD_GETDATA_VERSION \"]dnl" +getdata_version[\""]) +[DEFINE_GD_GETDATA_INT_VERSION="#define GD_GETDATA_INT_VERSION `${PRINTF} ]dnl +ifelse(`getdata_major', `0',dnl" +[%i%02i getdata_minor getdata_revision`"],dnl` +[%i%02i%02i getdata_major getdata_minor getdata_revision`"])dnl` +AC_SUBST([DEFINE_GD_GETDATA_INT_VERSION]) + echo echo "*** Checking host environment" echo Modified: trunk/getdata/src/getdata.h.in =================================================================== --- trunk/getdata/src/getdata.h.in 2013-10-25 22:23:34 UTC (rev 861) +++ trunk/getdata/src/getdata.h.in 2013-10-26 02:36:47 UTC (rev 862) @@ -1155,6 +1155,12 @@ # endif #endif +/* Library version information */ +@DEFINE_GD_GETDATA_VERSION@ + +/* This is (major * 10000) + (minor * 100) + revision */ +@DEFINE_GD_GETDATA_INT_VERSION@ + /* function aliases */ #ifdef GD_FUNCTION_ALIASES # warning "Using deprecated function aliases." Modified: trunk/getdata/src/internal.h =================================================================== --- trunk/getdata/src/internal.h 2013-10-25 22:23:34 UTC (rev 861) +++ trunk/getdata/src/internal.h 2013-10-26 02:36:47 UTC (rev 862) @@ -388,6 +388,7 @@ __FUNCTION__, ##__VA_ARGS__) #define dwatch(fmt, v) printf("%s %s = " fmt "\n", gd_colnil(), #v, v) #else +#define gd_colclear() #define dtracevoid() #define dtrace(...) #define dprintf(...) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2013-11-13 21:40:29
|
Revision: 863 http://sourceforge.net/p/getdata/code/863 Author: ketiltrout Date: 2013-11-13 21:40:26 +0000 (Wed, 13 Nov 2013) Log Message: ----------- Fix segfault in RawEntry destructor. Patch from S. J. Benton. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/NEWS trunk/getdata/bindings/cxx/rawentry.cpp Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2013-10-26 02:36:47 UTC (rev 862) +++ trunk/getdata/ChangeLog 2013-11-13 21:40:26 UTC (rev 863) @@ -1,3 +1,7 @@ +2013-11-13 D. V. Wiebe <ge...@ke...> svn:863 + * bindings/cxx/rawentry.cpp (RawEntry::RawEntry): Initialise filename. + Patch from S. J. Benton. + 2013-10-26 D. V. Wiebe <ge...@ke...> svn:862 * src/getdata.h.in: Add GD_GETDATA_VERSION and GD_GETDATA_INT_VERSION * configure.ac cmake/CMakeLists.txt: Calculate GD_GETDATA_VERSION and Modified: trunk/getdata/NEWS =================================================================== --- trunk/getdata/NEWS 2013-10-26 02:36:47 UTC (rev 862) +++ trunk/getdata/NEWS 2013-11-13 21:40:26 UTC (rev 863) @@ -58,6 +58,9 @@ * F95 BUG FIX: fgd_add and fgd_alter_entry no longer ignore named scalar parameters provided in supplied entry structures. + * C++ BUG FIX: Fixed segfault in RawEntry distructor. Reported by S. J. + Benton. + |==============================================================================| New in verison 0.8.5: Modified: trunk/getdata/bindings/cxx/rawentry.cpp =================================================================== --- trunk/getdata/bindings/cxx/rawentry.cpp 2013-10-26 02:36:47 UTC (rev 862) +++ trunk/getdata/bindings/cxx/rawentry.cpp 2013-11-13 21:40:26 UTC (rev 863) @@ -30,6 +30,7 @@ E.u.raw.spf = spf; E.u.raw.data_type = (gd_type_t)data_type; E.fragment_index = fragment_index; + filename = NULL; } RawEntry::~RawEntry() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2013-11-15 22:39:49
|
Revision: 866 http://sourceforge.net/p/getdata/code/866 Author: ketiltrout Date: 2013-11-15 22:39:46 +0000 (Fri, 15 Nov 2013) Log Message: ----------- Rename some tests. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/test/Makefile.am Added Paths: ----------- trunk/getdata/test/add_add.c trunk/getdata/test/close_close.c trunk/getdata/test/del_del.c trunk/getdata/test/flush_flush.c trunk/getdata/test/include_include.c trunk/getdata/test/index_index.c trunk/getdata/test/move_move.c trunk/getdata/test/name_name.c trunk/getdata/test/nfields_nfields.c trunk/getdata/test/nframes_nframes.c trunk/getdata/test/open_open.c trunk/getdata/test/spf_raw.c Removed Paths: ------------- trunk/getdata/test/add.c trunk/getdata/test/close.c trunk/getdata/test/del.c trunk/getdata/test/flush.c trunk/getdata/test/include.c trunk/getdata/test/index.c trunk/getdata/test/move.c trunk/getdata/test/name.c trunk/getdata/test/nfields.c trunk/getdata/test/nframes.c trunk/getdata/test/open.c trunk/getdata/test/spf.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2013-11-15 22:01:40 UTC (rev 865) +++ trunk/getdata/ChangeLog 2013-11-15 22:39:46 UTC (rev 866) @@ -1,3 +1,9 @@ +2013-11-15 D. V. Wiebe <ge...@ke...> svn:867 + * test/add_add.c test/close_close.c test/del_del.c test/flush_flush.c + test/include_include.c test/index_index.c test/move_move.c test/name_name.c + test/nfields_nfields.c test/nframes_nframes.c test/open_open.c + test/spf_raw.c: Renamed. + 2013-11-13 D. V. Wiebe <ge...@ke...> svn:863 * bindings/cxx/rawentry.cpp (RawEntry::RawEntry): Initialise filename. Patch from S. J. Benton. Index: trunk/getdata/test =================================================================== --- trunk/getdata/test 2013-11-15 22:01:40 UTC (rev 865) +++ trunk/getdata/test 2013-11-15 22:39:46 UTC (rev 866) Property changes on: trunk/getdata/test ___________________________________________________________________ Modified: svn:ignore ## -7,7 +7,7 ## *.exe .deps .libs -add +add_add add_affix add_alias add_alias_affix ## -138,8 +138,8 ## bzip_move_from bzip_nframes bzip_put -close close_bad +close_close close_discard close_null convert_complex128_complex64 ## -273,13 +273,13 ## cvlist_meta cvlist_meta_hidden cvlist_meta_invalid -del del_carray del_carray_deref del_const del_const_deref del_const_force del_data +del_del del_derived del_derived_after del_derived_force ## -360,9 +360,9 ## flist_type_meta flist_type_meta_hidden flist_type_meta_invalid -flush flush_all flush_bad_code +flush_flush flush_invalid flush_meta flush_ref ## -491,13 +491,13 ## hide hide_hidden hide_unhide -include include_accmode include_affix include_auto include_cb include_creat include_ignore +include_include include_index include_invalid include_nonexistent ## -505,8 +505,8 ## include_ref include_sub include_syntax -index index_domain +index_index index_range legacy_get legacy_get_put ## -549,7 +549,6 ## madd_spec_resolv madd_string madd_window -move move_affix move_affix_dup move_alias ## -560,15 +559,16 ## move_data_nop move_index move_meta +move_move move_protect move_subdir -name name_affix name_affix_bad name_alias name_dup name_move name_move_alias +name_name name_updb name_updb_alias name_updb_const ## -577,19 +577,19 ## nentries_hidden nentries_noalias nentries_scalar -nfields nfields_hidden nfields_invalid +nfields_nfields nfields_type nfields_type_hidden nfields_type_invalid nfields_vector nfields_vector_hidden nfields_vector_invalid -nframes nframes64 nframes_empty nframes_invalid +nframes_nframes nframes_off64 nframes_spf nmeta ## -605,7 +605,6 ## nmeta_vectors_hidden nmeta_vectors_invalid nmeta_vectors_parent -open open_abs open_cb_abort open_cb_cont ## -615,6 +614,7 ## open_eaccess open_nonexistent open_notdirfile +open_open open_sym_a open_sym_al open_sym_at ## -867,7 +867,6 ## slim_get slim_nframes slim_put -spf spf_alias spf_alias_meta spf_alias_missing ## -875,6 +874,7 ## spf_lincom spf_multiply spf_polynom +spf_raw spf_recip spf_recurse svlist Modified: trunk/getdata/test/Makefile.am =================================================================== --- trunk/getdata/test/Makefile.am 2013-11-15 22:01:40 UTC (rev 865) +++ trunk/getdata/test/Makefile.am 2013-11-15 22:39:46 UTC (rev 866) @@ -25,20 +25,20 @@ EXTRA_DIST=test.h -ADD_TESTS=add add_affix add_alias add_alias_affix add_alias_meta add_bit \ +ADD_TESTS=add_add add_affix add_alias add_alias_affix add_alias_meta add_bit \ add_bit_bitnum add_bit_bitsize add_bit_invalid add_bit_numbits \ - add_bit_scalars add_carray add_clincom add_code add_const add_cpolynom \ - add_crecip add_crecip89 add_divide add_divide_invalid add_duplicate \ - add_format add_invalid add_lincom add_lincom_affix add_lincom_invalid \ - add_lincom_nfields add_linterp add_linterp_invalid add_meta \ - add_meta_alias add_mplex add_mplex_scalars add_multiply \ - add_multiply_invalid add_phase add_phase_invalid add_polynom \ - add_polynom_scalar add_protect add_raw add_raw_include add_raw_invalid \ - add_raw_spf add_raw_spf_scalar add_raw_type add_rdonly add_recip \ - add_resolv add_sbit add_scalar add_scalar_carray add_scalar_carray_bad \ - add_sort add_spec add_spec_directive add_spec_invalid add_spec_meta \ - add_spec_resolv add_string add_string_affix add_type add_window \ - add_window_op + add_bit_scalars add_carray add_clincom add_code add_const \ + add_cpolynom add_crecip add_crecip89 add_divide add_divide_invalid \ + add_duplicate add_format add_invalid add_lincom add_lincom_affix \ + add_lincom_invalid add_lincom_nfields add_linterp \ + add_linterp_invalid add_meta add_meta_alias add_mplex \ + add_mplex_scalars add_multiply add_multiply_invalid add_phase \ + add_phase_invalid add_polynom add_polynom_scalar add_protect add_raw \ + add_raw_include add_raw_invalid add_raw_spf add_raw_spf_scalar \ + add_raw_type add_rdonly add_recip add_resolv add_sbit add_scalar \ + add_scalar_carray add_scalar_carray_bad add_sort add_spec \ + add_spec_directive add_spec_invalid add_spec_meta add_spec_resolv \ + add_string add_string_affix add_type add_window add_window_op ALIAS_TESTS=alias_list alias_list_alias alias_list_missing alias_num \ alias_num_alias alias_num_missing alias_target alias_target_alias \ @@ -69,7 +69,7 @@ cvlist_array_meta_hidden cvlist_hidden cvlist_invalid cvlist_meta \ cvlist_meta_hidden cvlist_meta_invalid -CLOSE_TESTS=close close_bad close_discard close_null +CLOSE_TESTS=close_bad close_close close_discard close_null CONVERT_TESTS=convert_complex128_complex64 convert_complex128_float64 \ convert_complex128_int64 convert_complex128_uint64 \ @@ -122,9 +122,9 @@ CREAT_TESTS=creat creat_excl creat_rdonly -DEL_TESTS=del del_carray del_carray_deref del_const del_const_deref \ +DEL_TESTS=del_carray del_carray_deref del_const del_const_deref \ del_const_force del_data del_derived del_derived_after \ - del_derived_force del_meta del_meta_force + del_derived_force del_del del_meta del_meta_force DFES_TESTS=dfes_bit dfes_divide dfes_lincom dfes_linterp dfes_multiply \ dfes_null dfes_phase dfes_raw dfes_recip dfes_zero @@ -156,8 +156,8 @@ flist_meta_invalid flist_type flist_type_hidden flist_type_invalid \ flist_type_meta flist_type_meta_hidden flist_type_meta_invalid -FLUSH_TESTS=flush flush_all flush_bad_code flush_invalid flush_meta flush_ref \ - flush_spec +FLUSH_TESTS=flush_all flush_bad_code flush_flush flush_invalid flush_meta \ + flush_ref flush_spec FOFFS_TESTS=foffs_alter foffs_get foffs_move @@ -167,15 +167,16 @@ GET_TESTS=get64 get_affix get_bad_code get_bit get_carray get_carray_len \ get_carray_c2r get_carray_slice get_char get_clincom get_complex128 \ - get_complex64 get_const get_const_complex get_const_repr get_cpolynom \ - get_divide get_endian8 get_endian16 get_endian32 get_endian64 \ - get_endian_complex128_arm get_endian_complex128_big \ + get_complex64 get_const get_const_complex get_const_repr \ + get_cpolynom get_divide get_endian8 get_endian16 get_endian32 \ + get_endian64 get_endian_complex128_arm get_endian_complex128_big \ get_endian_complex128_little get_endian_complex64_arm \ get_endian_complex64_big get_endian_complex64_little \ - get_endian_float32_arm get_endian_float32_big get_endian_float32_little \ - get_endian_float64_arm get_endian_float64_big get_endian_float64_little \ - get_ff get_float32 get_float64 get_foffs get_fs get_here get_here_foffs \ - get_heres get_int8 get_int16 get_int32 get_int64 get_invalid get_lincom1 \ + get_endian_float32_arm get_endian_float32_big \ + get_endian_float32_little get_endian_float64_arm \ + get_endian_float64_big get_endian_float64_little get_ff get_float32 \ + get_float64 get_foffs get_fs get_here get_here_foffs get_heres \ + get_int8 get_int16 get_int32 get_int64 get_invalid get_lincom1 \ get_lincom2 get_lincom3 get_lincom_noin get_lincom_non \ get_lincom_null get_lincom_spf get_linterp get_linterp_noin \ get_linterp_notab get_linterp_sort get_mplex get_mplex_bof \ @@ -197,12 +198,12 @@ HIDE_TESTS=hide hide_hidden hide_unhide -INCLUDE_TESTS=include include_accmode include_affix include_auto include_cb \ - include_creat include_ignore include_index include_invalid \ - include_nonexistent include_pc include_ref include_sub \ - include_syntax +INCLUDE_TESTS=include_accmode include_affix include_auto include_cb \ + include_creat include_ignore include_include include_index \ + include_invalid include_nonexistent include_pc include_ref \ + include_sub include_syntax -INDEX_TESTS=index index_domain index_range +INDEX_TESTS=index_domain index_index index_range if INCLUDE_LEGACY_API LEGACY_TESTS=legacy_get legacy_get_put legacy_get_rofs legacy_nframes \ @@ -219,21 +220,21 @@ madd_polynom madd_recip madd_sbit madd_spec madd_spec_directive \ madd_spec_invalid madd_spec_resolv madd_string madd_window -MOVE_TESTS=move move_affix move_affix_dup move_alias move_data_enc_ar \ +MOVE_TESTS=move_affix move_affix_dup move_alias move_data_enc_ar \ move_data_enc_ra move_data_endian move_data_foffs move_data_nop \ - move_index move_meta move_protect move_subdir + move_index move_meta move_move move_protect move_subdir -NAME_TESTS=name name_affix name_affix_bad name_alias name_dup name_move \ - name_move_alias name_updb name_updb_alias name_updb_const \ +NAME_TESTS=name_affix name_affix_bad name_alias name_dup name_move \ + name_move_alias name_name name_updb name_updb_alias name_updb_const \ name_updb_const_alias NENTRIES_TESTS=nentries_alias nentries_hidden nentries_noalias nentries_scalar -NFIELDS_TESTS=nfields nfields_hidden nfields_invalid nfields_type \ +NFIELDS_TESTS=nfields_hidden nfields_invalid nfields_nfields nfields_type \ nfields_type_hidden nfields_type_invalid nfields_vector \ nfields_vector_hidden nfields_vector_invalid -NFRAMES_TESTS=nframes nframes64 nframes_empty nframes_invalid \ +NFRAMES_TESTS=nframes64 nframes_empty nframes_invalid nframes_nframes \ nframes_off64 nframes_spf NMETA_TESTS=nmeta nmeta_hidden nmeta_invalid nmeta_parent nmeta_type \ @@ -241,9 +242,9 @@ nmeta_vectors nmeta_vectors_del nmeta_vectors_hidden \ nmeta_vectors_invalid nmeta_vectors_parent -OPEN_TESTS=open open_abs open_cb_abort open_cb_cont open_cb_ignore \ - open_cb_invalid open_cb_rescan open_eaccess open_nonexistent \ - open_notdirfile open_sym_a open_sym_al open_sym_at open_sym_c \ +OPEN_TESTS=open_abs open_cb_abort open_cb_cont open_cb_ignore open_cb_invalid \ + open_cb_rescan open_eaccess open_nonexistent open_notdirfile \ + open_open open_sym_a open_sym_al open_sym_at open_sym_c \ open_sym_cl open_sym_ct open_sym_p open_sym_pl open_sym_pt PARSE_TESTS=parse_alias parse_alias_code parse_alias_dup parse_alias_meta \ @@ -324,9 +325,8 @@ SVLIST_TESTS=svlist svlist_hidden svlist_invalid svlist_meta \ svlist_meta_hidden svlist_meta_invalid -SPF_TESTS=spf spf_alias spf_alias_missing spf_alias_meta \ - spf_divide spf_lincom spf_multiply \ - spf_polynom spf_recip spf_recurse +SPF_TESTS=spf_alias spf_alias_missing spf_alias_meta spf_divide spf_lincom \ + spf_multiply spf_polynom spf_raw spf_recip spf_recurse TABLE_TESTS=table table_code table_type Deleted: trunk/getdata/test/add.c =================================================================== --- trunk/getdata/test/add.c 2013-11-15 22:01:40 UTC (rev 865) +++ trunk/getdata/test/add.c 2013-11-15 22:39:46 UTC (rev 866) @@ -1,75 +0,0 @@ -/* Copyright (C) 2008-2011 D. V. Wiebe - * - *************************************************************************** - * - * This file is part of the GetData project. - * - * GetData is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * GetData is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GetData; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* Add a dirfile field */ -#include "test.h" - -#include <stdlib.h> -#include <stdio.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> -#include <errno.h> - -int main(void) -{ - const char *filedir = "dirfile"; - const char *format = "dirfile/format"; - const char *data = "dirfile/data"; - int error, r = 0; - DIRFILE *D; - gd_entry_t E, e; - - rmdirfile(); - memset(&E, 0, sizeof(E)); - E.field = "data"; - E.field_type = GD_RAW_ENTRY; - E.EN(raw,spf) = 2; - E.EN(raw,data_type) = GD_UINT8; - E.scalar[0] = NULL; - - D = gd_open(filedir, GD_RDWR | GD_CREAT | GD_VERBOSE); - gd_add(D, &E); - error = gd_error(D); - - /* check */ - gd_entry(D, "data", &e); - if (gd_error(D)) - r = 1; - else { - CHECKI(e.field_type, GD_RAW_ENTRY); - CHECKI(e.fragment_index, 0); - CHECKI(e.EN(raw,spf), 2); - CHECKI(e.EN(raw,data_type), GD_UINT8); - CHECKP(e.scalar[0]); - gd_free_entry_strings(&e); - } - - gd_close(D); - - unlink(data); - unlink(format); - rmdir(filedir); - - CHECKI(error, GD_E_OK); - - return r; -} Copied: trunk/getdata/test/add_add.c (from rev 865, trunk/getdata/test/add.c) =================================================================== --- trunk/getdata/test/add_add.c (rev 0) +++ trunk/getdata/test/add_add.c 2013-11-15 22:39:46 UTC (rev 866) @@ -0,0 +1,75 @@ +/* Copyright (C) 2008-2011 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +/* Add a dirfile field */ +#include "test.h" + +#include <stdlib.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data"; + int error, r = 0; + DIRFILE *D; + gd_entry_t E, e; + + rmdirfile(); + memset(&E, 0, sizeof(E)); + E.field = "data"; + E.field_type = GD_RAW_ENTRY; + E.EN(raw,spf) = 2; + E.EN(raw,data_type) = GD_UINT8; + E.scalar[0] = NULL; + + D = gd_open(filedir, GD_RDWR | GD_CREAT | GD_VERBOSE); + gd_add(D, &E); + error = gd_error(D); + + /* check */ + gd_entry(D, "data", &e); + if (gd_error(D)) + r = 1; + else { + CHECKI(e.field_type, GD_RAW_ENTRY); + CHECKI(e.fragment_index, 0); + CHECKI(e.EN(raw,spf), 2); + CHECKI(e.EN(raw,data_type), GD_UINT8); + CHECKP(e.scalar[0]); + gd_free_entry_strings(&e); + } + + gd_close(D); + + unlink(data); + unlink(format); + rmdir(filedir); + + CHECKI(error, GD_E_OK); + + return r; +} Deleted: trunk/getdata/test/close.c =================================================================== --- trunk/getdata/test/close.c 2013-11-15 22:01:40 UTC (rev 865) +++ trunk/getdata/test/close.c 2013-11-15 22:39:46 UTC (rev 866) @@ -1,50 +0,0 @@ -/* Copyright (C) 2008-2011 D. V. Wiebe - * - *************************************************************************** - * - * This file is part of the GetData project. - * - * GetData is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * GetData is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GetData; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* Closing a dirfile should succeed cleanly */ -#include "test.h" - -#include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> - -int main(void) -{ - const char *filedir = "dirfile"; - const char *format = "dirfile/format"; - int error, r = 0; - DIRFILE *D; - - rmdirfile(); - mkdir(filedir, 0777); - close(open(format, O_CREAT | O_EXCL | O_WRONLY, 0666)); - - D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); - error = gd_close(D); - - unlink(format); - rmdir(filedir); - - CHECKI(error, 0); - - return r; -} Copied: trunk/getdata/test/close_close.c (from rev 865, trunk/getdata/test/close.c) =================================================================== --- trunk/getdata/test/close_close.c (rev 0) +++ trunk/getdata/test/close_close.c 2013-11-15 22:39:46 UTC (rev 866) @@ -0,0 +1,50 @@ +/* Copyright (C) 2008-2011 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +/* Closing a dirfile should succeed cleanly */ +#include "test.h" + +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + int error, r = 0; + DIRFILE *D; + + rmdirfile(); + mkdir(filedir, 0777); + close(open(format, O_CREAT | O_EXCL | O_WRONLY, 0666)); + + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); + error = gd_close(D); + + unlink(format); + rmdir(filedir); + + CHECKI(error, 0); + + return r; +} Deleted: trunk/getdata/test/del.c =================================================================== --- trunk/getdata/test/del.c 2013-11-15 22:01:40 UTC (rev 865) +++ trunk/getdata/test/del.c 2013-11-15 22:39:46 UTC (rev 866) @@ -1,76 +0,0 @@ -/* Copyright (C) 2008-2011 D. V. Wiebe - * - *************************************************************************** - * - * This file is part of the GetData project. - * - * GetData is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * GetData is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GetData; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* Attempt to delete a field */ -#include "test.h" - -#include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> -#include <errno.h> -#include <stdio.h> - -int main(void) -{ - const char *filedir = "dirfile"; - const char *format = "dirfile/format"; - const char *data = "dirfile/data"; - const char *format_data = "data RAW UINT8 8\n"; - unsigned char c[8]; - unsigned char data_data[256]; - int fd, ret, error1, n, error2, r = 0; - DIRFILE *D; - - memset(c, 0, 8); - rmdirfile(); - mkdir(filedir, 0777); - - for (fd = 0; fd < 256; ++fd) - data_data[fd] = (unsigned char)fd; - - fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); - write(fd, format_data, strlen(format_data)); - close(fd); - - fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); - write(fd, data_data, 256); - close(fd); - - D = gd_open(filedir, GD_RDWR); - ret = gd_delete(D, "data", 0); - error1 = gd_error(D); - n = gd_getdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); - error2 = gd_error(D); - gd_close(D); - - fd = unlink(data); - unlink(format); - rmdir(filedir); - - CHECKI(fd, 0); - CHECKI(error1, GD_E_OK); - CHECKI(n, 0); - CHECKI(ret, 0); - CHECKI(error2, GD_E_BAD_CODE); - - return r; -} Copied: trunk/getdata/test/del_del.c (from rev 865, trunk/getdata/test/del.c) =================================================================== --- trunk/getdata/test/del_del.c (rev 0) +++ trunk/getdata/test/del_del.c 2013-11-15 22:39:46 UTC (rev 866) @@ -0,0 +1,76 @@ +/* Copyright (C) 2008-2011 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +/* Attempt to delete a field */ +#include "test.h" + +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> +#include <stdio.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data"; + const char *format_data = "data RAW UINT8 8\n"; + unsigned char c[8]; + unsigned char data_data[256]; + int fd, ret, error1, n, error2, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (fd = 0; fd < 256; ++fd) + data_data[fd] = (unsigned char)fd; + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, data_data, 256); + close(fd); + + D = gd_open(filedir, GD_RDWR); + ret = gd_delete(D, "data", 0); + error1 = gd_error(D); + n = gd_getdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); + error2 = gd_error(D); + gd_close(D); + + fd = unlink(data); + unlink(format); + rmdir(filedir); + + CHECKI(fd, 0); + CHECKI(error1, GD_E_OK); + CHECKI(n, 0); + CHECKI(ret, 0); + CHECKI(error2, GD_E_BAD_CODE); + + return r; +} Deleted: trunk/getdata/test/flush.c =================================================================== --- trunk/getdata/test/flush.c 2013-11-15 22:01:40 UTC (rev 865) +++ trunk/getdata/test/flush.c 2013-11-15 22:39:46 UTC (rev 866) @@ -1,88 +0,0 @@ -/* Copyright (C) 2008-2011 D. V. Wiebe - * - *************************************************************************** - * - * This file is part of the GetData project. - * - * GetData is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * GetData is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GetData; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* Attempt to flush */ -#include "test.h" - -#include <inttypes.h> -#include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> -#include <errno.h> - -int main(void) -{ - const char *filedir = "dirfile"; - const char *format = "dirfile/format"; - const char *data = "dirfile/data"; - const char *format_data = "data RAW UINT8 8\n"; - uint8_t c[8], d; - int fd, i, n, error; - struct stat buf; - DIRFILE *D; - - memset(c, 0, 8); - rmdirfile(); - mkdir(filedir, 0777); - - for (i = 0; i < 8; ++i) - c[i] = (uint8_t)(40 + i); - - fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); - write(fd, format_data, strlen(format_data)); - close(fd); - - D = gd_open(filedir, GD_RDWR | GD_UNENCODED | GD_VERBOSE); - n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); - gd_flush(D, "data"); - error = gd_error(D); - - gd_close(D); - - if (stat(data, &buf)) - return 1; - if (buf.st_size != 40 + 8 * sizeof(uint8_t)) - return 1; - - fd = open(data, O_RDONLY | O_BINARY); - i = 0; - while (read(fd, &d, sizeof(uint8_t))) { - if (i < 40 || i > 48) { - if (d != 0) - return 1; - } else if (d != i) - return 1; - i++; - } - close(fd); - - unlink(data); - unlink(format); - rmdir(filedir); - - if (error) - return 1; - if (n != 8) - return 1; - - return 0; -} Copied: trunk/getdata/test/flush_flush.c (from rev 865, trunk/getdata/test/flush.c) =================================================================== --- trunk/getdata/test/flush_flush.c (rev 0) +++ trunk/getdata/test/flush_flush.c 2013-11-15 22:39:46 UTC (rev 866) @@ -0,0 +1,88 @@ +/* Copyright (C) 2008-2011 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +/* Attempt to flush */ +#include "test.h" + +#include <inttypes.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data"; + const char *format_data = "data RAW UINT8 8\n"; + uint8_t c[8], d; + int fd, i, n, error; + struct stat buf; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (i = 0; i < 8; ++i) + c[i] = (uint8_t)(40 + i); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + D = gd_open(filedir, GD_RDWR | GD_UNENCODED | GD_VERBOSE); + n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); + gd_flush(D, "data"); + error = gd_error(D); + + gd_close(D); + + if (stat(data, &buf)) + return 1; + if (buf.st_size != 40 + 8 * sizeof(uint8_t)) + return 1; + + fd = open(data, O_RDONLY | O_BINARY); + i = 0; + while (read(fd, &d, sizeof(uint8_t))) { + if (i < 40 || i > 48) { + if (d != 0) + return 1; + } else if (d != i) + return 1; + i++; + } + close(fd); + + unlink(data); + unlink(format); + rmdir(filedir); + + if (error) + return 1; + if (n != 8) + return 1; + + return 0; +} Deleted: trunk/getdata/test/include.c =================================================================== --- trunk/getdata/test/include.c 2013-11-15 22:01:40 UTC (rev 865) +++ trunk/getdata/test/include.c 2013-11-15 22:39:46 UTC (rev 866) @@ -1,67 +0,0 @@ -/* Copyright (C) 2008-2011 D. V. Wiebe - * - *************************************************************************** - * - * This file is part of the GetData project. - * - * GetData is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * GetData is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GetData; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* Test include */ -#include "test.h" - -#include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> -#include <errno.h> - -int main(void) -{ - const char *filedir = "dirfile"; - const char *format = "dirfile/format"; - const char *format1 = "dirfile/format1"; - const char *format_data = "#\n"; - const char *format1_data = "data RAW UINT8 11\n"; - int fd, error, r = 0; - unsigned int spf; - DIRFILE *D; - - rmdirfile(); - mkdir(filedir, 0777); - - fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); - write(fd, format_data, strlen(format_data)); - close(fd); - - fd = open(format1, O_CREAT | O_EXCL | O_WRONLY, 0666); - write(fd, format1_data, strlen(format1_data)); - close(fd); - - D = gd_open(filedir, GD_RDWR | GD_VERBOSE); - gd_include(D, "format1", 0, 0); - error = gd_error(D); - spf = gd_spf(D, "data"); - gd_close(D); - - unlink(format1); - unlink(format); - rmdir(filedir); - - CHECKI(error, 0); - CHECKU(spf, 11); - - return r; -} Copied: trunk/getdata/test/include_include.c (from rev 865, trunk/getdata/test/include.c) =================================================================== --- trunk/getdata/test/include_include.c (rev 0) +++ trunk/getdata/test/include_include.c 2013-11-15 22:39:46 UTC (rev 866) @@ -0,0 +1,67 @@ +/* Copyright (C) 2008-2011 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +/* Test include */ +#include "test.h" + +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *format1 = "dirfile/format1"; + const char *format_data = "#\n"; + const char *format1_data = "data RAW UINT8 11\n"; + int fd, error, r = 0; + unsigned int spf; + DIRFILE *D; + + rmdirfile(); + mkdir(filedir, 0777); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(format1, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format1_data, strlen(format1_data)); + close(fd); + + D = gd_open(filedir, GD_RDWR | GD_VERBOSE); + gd_include(D, "format1", 0, 0); + error = gd_error(D); + spf = gd_spf(D, "data"); + gd_close(D); + + unlink(format1); + unlink(format); + rmdir(filedir); + + CHECKI(error, 0); + CHECKU(spf, 11); + + return r; +} Deleted: trunk/getdata/test/index.c =================================================================== --- trunk/getdata/test/index.c 2013-11-15 22:01:40 UTC (rev 865) +++ trunk/getdata/test/index.c 2013-11-15 22:39:46 UTC (rev 866) @@ -1,75 +0,0 @@ -/* Copyright (C) 2009-2011 D. V. Wiebe - * - *************************************************************************** - * - * This file is part of the GetData project. - * - * GetData is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * GetData is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GetData; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* Frameindex look-up */ -#include "test.h" - -#include <stdlib.h> -#include <stdio.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> -#include <math.h> -#include <errno.h> - -int main(void) -{ - const char *filedir = "dirfile"; - const char *format = "dirfile/format"; - const char *data = "dirfile/data"; - const char *format_data = "data RAW FLOAT64 1\n"; - double d[1000], f1, f2, f3; - int i, error, r = 0; - DIRFILE *D; - - rmdirfile(); - mkdir(filedir, 0777); - - for (i = 0; i < 1000; ++i) - d[i] = sqrt((i+600) / 500.); - - i = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); - write(i, format_data, strlen(format_data)); - close(i); - - i = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); - write(i, d, 1000 * sizeof(double)); - close(i); - - D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); - f1 = gd_framenum(D, "data", 1.09); - f2 = gd_framenum(D, "data", 1.49); - f3 = gd_framenum(D, "data", 1.79); - error = gd_error(D); - - gd_close(D); - - unlink(data); - unlink(format); - rmdir(filedir); - - CHECKI(error, 0); - CHECKF(f1, -5.96730894763915); - CHECKF(f2, 510.050010695549); - CHECKF(f3, 1002.04807025292); - - return r; -} Copied: trunk/getdata/test/index_index.c (from rev 865, trunk/getdata/test/index.c) =================================================================== --- trunk/getdata/test/index_index.c (rev 0) +++ trunk/getdata/test/index_index.c 2013-11-15 22:39:46 UTC (rev 866) @@ -0,0 +1,75 @@ +/* Copyright (C) 2009-2011 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +/* Frameindex look-up */ +#include "test.h" + +#include <stdlib.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <math.h> +#include <errno.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data"; + const char *format_data = "data RAW FLOAT64 1\n"; + double d[1000], f1, f2, f3; + int i, error, r = 0; + DIRFILE *D; + + rmdirfile(); + mkdir(filedir, 0777); + + for (i = 0; i < 1000; ++i) + d[i] = sqrt((i+600) / 500.); + + i = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(i, format_data, strlen(format_data)); + close(i); + + i = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(i, d, 1000 * sizeof(double)); + close(i); + + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); + f1 = gd_framenum(D, "data", 1.09); + f2 = gd_framenum(D, "data", 1.49); + f3 = gd_framenum(D, "data", 1.79); + error = gd_error(D); + + gd_close(D); + + unlink(data); + unlink(format); + rmdir(filedir); + + CHECKI(error, 0); + CHECKF(f1, -5.96730894763915); + CHECKF(f2, 510.050010695549); + CHECKF(f3, 1002.04807025292); + + return r; +} Deleted: trunk/getdata/test/move.c =================================================================== --- trunk/getdata/test/move.c 2013-11-15 22:01:40 UTC (rev 865) +++ trunk/getdata/test/move.c 2013-11-15 22:39:46 UTC (rev 866) @@ -1,71 +0,0 @@ -/* Copyright (C) 2008-2011 D. V. Wiebe - * - *************************************************************************** - * - * This file is part of the GetData project. - * - * GetData is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * GetData is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GetData; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* Test move */ -#include "test.h" - -#include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> -#include <stdio.h> -#include <errno.h> - -int main(void) -{ - const char *filedir = "dirfile"; - const char *format = "dirfile/format"; - const char *format1 = "dirfile/format1"; - const char *format_data = "INCLUDE format1\ndata RAW UINT8 11"; - const char *format1_data = "#\n"; - int fd, ret, error, ge_ret, r = 0; - gd_entry_t E; - DIRFILE *D; - - rmdirfile(); - mkdir(filedir, 0777); - - fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); - write(fd, format_data, strlen(format_data)); - close(fd); - - fd = open(format1, O_CREAT | O_EXCL | O_WRONLY, 0666); - write(fd, format1_data, strlen(format1_data)); - close(fd); - - D = gd_open(filedir, GD_RDWR | GD_UNENCODED | GD_VERBOSE); - ret = gd_move(D, "data", 1, 0); - error = gd_error(D); - ge_ret = gd_entry(D, "data", &E); - gd_close(D); - - unlink(format1); - unlink(format); - rmdir(filedir); - - CHECKI(ret, 0); - CHECKI(error, GD_E_OK); - CHECKI(ge_ret, 0); - CHECKI(E.fragment_index, 1); - gd_free_entry_strings(&E); - - return r; -} Copied: trunk/getdata/test/move_move.c (from rev 865, trunk/getdata/test/move.c) =================================================================== --- trunk/getdata/test/move_move.c (rev 0) +++ trunk/getdata/test/move_move.c 2013-11-15 22:39:46 UTC (rev 866) @@ -0,0 +1,71 @@ +/* Copyright (C) 2008-2011 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +/* Test move */ +#include "test.h" + +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> +#include <errno.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *format1 = "dirfile/format1"; + const char *format_data = "INCLUDE format1\ndata RAW UINT8 11"; + const char *format1_data = "#\n"; + int fd, ret, error, ge_ret, r = 0; + gd_entry_t E; + DIRFILE *D; + + rmdirfile(); + mkdir(filedir, 0777); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(format1, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format1_data, strlen(format1_data)); + close(fd); + + D = gd_open(filedir, GD_RDWR | GD_UNENCODED | GD_VERBOSE); + ret = gd_move(D, "data", 1, 0); + error = gd_error(D); + ge_ret = gd_entry(D, "data", &E); + gd_close(D); + + unlink(format1); + unlink(format); + rmdir(filedir); + + CHECKI(ret, 0); + CHECKI(error, GD_E_OK); + CHECKI(ge_ret, 0); + CHECKI(E.fragment_index, 1); + gd_free_entry_strings(&E); + + return r; +} Deleted: trunk/getdata/test/name.c =================================================================== --- trunk/getdata/test/name.c 2013-11-15 22:01:40 UTC (rev 865) +++ trunk/getdata/test/name.c 2013-11-15 22:39:46 UTC (rev 866) @@ -1,133 +0,0 @@ -/* Copyright (C) 2008-2012 D. V. Wiebe - * - *************************************************************************** - * - * This file is part of the GetData project. - * - * GetData is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * GetData is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GetData; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* Attempt to rename a field */ -#include "test.h" - -#include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> -#include <errno.h> -#include <stdio.h> - -int main(void) -{ - const char *filedir = "dirfile"; - const char *format = "dirfile/format"; - const char *data = "dirfile/data"; - const char *zata = "dirfile/zata"; - const char *format_data = - "early PHASE data 0\n" - "late PHASE data 0\n" - "/ALIAS bata data\n" - "cata RAW UINT8 8\n" - "data RAW UINT8 8\n" - "eata RAW UINT8 8\n"; - unsigned char data_data[256]; - int fd, ret, e1, e2, e3, e4, unlink_data, unlink_zata, r = 0; - const char **fl; - char *field_list[6]; - char *s1, *s2, *s3; - DIRFILE *D; - gd_entry_t E; - - rmdirfile(); - mkdir(filedir, 0777); - - for (fd = 0; fd < 256; ++fd) - data_data[fd] = (unsigned char)fd; - - fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); - write(fd, format_data, strlen(format_data)); - close(fd); - - fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); - write(fd, data_data, 256); - close(fd); - - D = gd_open(filedir, GD_RDWR); - gd_validate(D, "early"); - ret = gd_rename(D, "data", "zata", 0); - e1 = gd_error(D); - gd_spf(D, "early"); - e2 = gd_error(D); - gd_spf(D, "late"); - e3 = gd_error(D); - fl = gd_field_list(D); - - field_list[0] = strdup(fl[0]); - field_list[1] = strdup(fl[1]); - field_list[2] = strdup(fl[2]); - field_list[3] = strdup(fl[3]); - field_list[4] = strdup(fl[4]); - field_list[5] = strdup(fl[5]); - - gd_entry(D, "early", &E); - s1 = E.in_fields[0]; - E.in_fields[0] = NULL; - gd_free_entry_strings(&E); - - gd_entry(D, "late", &E); - s2 = E.in_fields[0]; - E.in_fields[0] = NULL; - gd_free_entry_strings(&E); - - gd_entry(D, "bata", &E); - e4 = gd_error(D); - s3 = strdup(gd_alias_target(D, "bata")); - - gd_close(D); - - unlink_data = unlink(data); - unlink_zata = unlink(zata); - unlink(format); - rmdir(filedir); - - CHECKI(e1,0); - CHECKI(e2,GD_E_BAD_CODE); - CHECKI(e3,GD_E_BAD_CODE); - CHECKI(e4,GD_E_BAD_CODE); - CHECKI(ret,0); - CHECKS(field_list[0], "INDEX"); - CHECKS(field_list[1], "cata"); - CHECKS(field_list[2], "early"); - CHECKS(field_list[3], "eata"); - CHECKS(field_list[4], "late"); - CHECKS(field_list[5], "zata"); - CHECKI(unlink_data, 0); - CHECKI(unlink_zata, -1); - CHECKS(s1, "data"); - CHECKS(s2, "data"); - CHECKS(s3, "data"); - - free(s1); - free(s2); - free(s3); - free(field_list[0]); - free(field_list[1]); - free(field_list[2]); - free(field_list[3]); - free(field_list[4]); - free(field_list[5]); - - return r; -} Copied: trunk/getdata/test/name_name.c (from rev 865, trunk/getdata/test/name.c) =================================================================== --- trunk/getdata/test/name_name.c (rev 0) +++ trunk/getdata/test/name_name.c 2013-11-15 22:39:46 UTC (rev 866) @@ -0,0 +1,133 @@ +/* Copyright (C) 2008-2012 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +/* Attempt to rename a field */ +#include "test.h" + +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> +#include <stdio.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data"; + const char *zata = "dirfile/zata"; + const char *format_data = + "early PHASE data 0\n" + "late PHASE data 0\n" + "/ALIAS bata data\n" + "cata RAW UINT8 8\n" + "data RAW UINT8 8\n" + "eata RAW UINT8 8\n"; + unsigned char data_data[256]; + int fd, ret, e1, e2, e3, e4, unlink_data, unlink_zata, r = 0; + const char **fl; + char *field_list[6]; + char *s1, *s2, *s3; + DIRFILE *D; + gd_entry_t E; + + rmdirfile(); + mkdir(filedir, 0777); + + for (fd = 0; fd < 256; ++fd) + data_data[fd] = (unsigned char)fd; + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, data_data, 256); + close(fd); + + D = gd_open(filedir, GD_RDWR); + gd_validate(D, "early"); + ret = gd_rename(D, "data", "zata", 0); + e1 = gd_error(D); + gd_spf(D, "early"); + e2 = gd_error(D); + gd_spf(D, "late"); + e3 = gd_error(D); + fl = gd_field_list(D); + + field_list[0] = strdup(fl[0]); + field_list[1] = strdup(fl[1]); + field_list[2] = strdup(fl[2]); + field_list[3] = strdup(fl[3]); + field_list[4] = strdup(fl[4]); + field_list[5] = strdup(fl[5]); + + gd_entry(D, "early", &E); + s1 = E.in_fields[0]; + E.in_fields[0] = NULL; + gd_free_entry_strings(&E); + + gd_entry(D, "late", &E); + s2 = E.in_fields[0]; + E.in_fields[0] = NULL; + gd_free_entry_strings(&E); + + gd_entry(D, "bata", &E); + e4 = gd_error(D); + s3 = strdup(gd_alias_target(D, "bata")); + + gd_close(D); + + unlink_data = unlink(data); + unlink_zata = unlink(zata); + unlink(format); + rmdir(filedir); + + CHECKI(e1,0); + CHECKI(e2,GD_E_BAD_CODE); + CHECKI(e3,GD_E_BAD_CODE); + CHECKI(e4,GD_E_BAD_CODE); + CHECKI(ret,0); + CHECKS(field_list[0], "INDEX"); + CHECKS(field_list[1], "cata"); + CHECKS(field_list[2], "early"); + CHECKS(field_list[3], "eata"); + CHECKS(field_list[4], "late"); + CHECKS(field_list[5], "zata"); + CHECKI(unlink_data, 0); + CHECKI(unlink_zata, -1); + CHECKS(s1, "data"); + CHECKS(s2, "data"); + CHECKS(s3, "data"); + + free(s1); + free(s2); + free(s3); + free(field_list[0]); + free(field_list[1]); + free(field_list[2]); + free(field_list[3]); + free(field_list[4]); + free(field_list[5]); + + return r; +} Deleted: trunk/getdata/test/nfields.c =================================================================== --- trunk/getdata/test/nfields.c 2013-11-15 22:01:40 UTC (rev 865) +++ trunk/getdata/test/nfields.c 2013-11-15 22:39:46 UTC (rev 866) @@ -1,72 +0,0 @@ -/* Copyright (C) 2008-2011 D. V. Wiebe - * - *************************************************************************** - * - * This file is part of the GetData project. - * - * GetData is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * GetData is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GetData; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* Retreiving the number of fields of a field should succeed cleanly */ -#include "test.h" - -#include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> -#include <errno.h> - -int main(void) -{ - const char *filedir = "dirfile"; - const char *format = "dirfile/format"; - const char *format_data = - "raw1 RAW UINT8 1\n" - "META raw1 linterp1 LINTERP raw2 table\n" - "META raw1 linterp2 LINTERP raw3 table\n" - "META raw1 linterp3 LINTERP raw4 table\n" - "META raw1 const CONST UINT8 1\n" - "META raw1 string STRING value\n" - "META raw1 string2 STRING value\n" - "raw2 RAW UINT8 1\n" - "raw3 RAW UINT8 1\n" - "raw4 RAW UINT8 1\n" - "const CONST UINT8 1\n" - "string STRING value\n" - "string2 STRING value\n"; - int fd, error, r = 0; - unsigned int nfields; - DIRFILE *D; - - rmdirfile(); - mkdir(filedir, 0777); - - fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); - write(fd, format_data, strlen(format_data)); - close(fd); - - D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); - nfields = gd_nfields(D); - error = gd_error(D); - gd_close(D); - - unlink(format); - rmdir(filedir); - - CHECKI(error, 0); - CHECKI(nfields, 8); - - return r; -} Copied: trunk/getdata/test/nfields_nfields.c (from rev 865, trunk/getdata/test/nfields.c) =================================================================== --- trunk/getdata/test/nfields_nfields.c (rev 0) +++ trunk/getdata/test/nfields_nfields.c 2013-11-15 22:39:46 UTC (rev 866) @@ -0,0 +1,72 @@ +/* Copyright (C) 2008-2011 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +/* Retreiving the number of fields of a field should succeed cleanly */ +#include "test.h" + +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *format_data = + "raw1 RAW UINT8 1\n" + "META raw1 linterp1 LINTERP raw2 table\n" + "META raw1 linterp2 LINTERP raw3 table\n" + "META raw1 linterp3 LINTERP raw4 table\n" + "META raw1 const CONST UINT8 1\n" + "META raw1 string STRING value\n" + "META raw1 string2 STRING value\n" + "raw2 RAW UINT8 1\n" + "raw3 RAW UINT8 1\n" + "raw4 RAW UINT8 1\n" + "const CONST UINT8 1\n" + "string STRING value\n" + "string2 STRING value\n"; + int fd, error, r = 0; + unsigned int nfields; + DIRFILE *D; + + rmdirfile(); + mkdir(filedir, 0777); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); + nfields = gd_nfields(D); + error = gd_error(D); + gd_close(D); + + unlink(format); + rmdir(filedir); + + CHECKI(error, 0); + CHECKI(nfields, 8); + + return r; +} Deleted: trunk/getdata/test/nframes.c =================================================================== --- trunk/getdata/test/nframes.c 2013-11-15 22:01:40 UTC (rev 865) +++ trunk/getdata/test/nframes.c 2013-11-15 22:39:46 UTC (rev 866) @@ -1,66 +0,0 @@ -/* Copyright (C) 2008-2011 D. V. Wiebe - * - *************************************************************************** - * - * This file is part of the GetData project. - * - * GetData is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * GetData is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GetData; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* Retreiving the number of frames should succeed cleanly */ -#include "test.h" - -#include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> -#include <errno.h> - -int main(void) -{ - const char *filedir = "dirfile"; - const char *format = "dirfile/format"; - const char *data = "dirfile/data"; - const char *format_data = "data RAW UINT16 1\n"; - int fd, error, r = 0; - const size_t len = strlen(data); - off_t n; - DIRFILE *D; - - rmdirfile(); - mkdir(filedir, 0777); - - fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); - write(fd, format_data, strlen(format_data)); - close(fd); - - fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); - write(fd, data, len); - close(fd); - - D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); - n = gd_nframes(D); - error = gd_error(D); - gd_close(D); - - unlink(data); - unlink(format); - rmdir(filedir); - - CHECKI(error, 0); - CHECKI(n, (off_t)len / 2); - - return r; -} Copied: trunk/getdata/test/nframes_nframes.c (from rev 865, trunk/getdata/test/nframes.c) =================================================================== --- trunk/getdata/test/nframes_nframes.c (rev 0) +++ trunk/getdata/test/nframes_nframes.c 2013-11-15 22:39:46 UTC (rev 866) @@ -0,0 +1,66 @@ +/* Copyright (C) 2008-2011 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be... [truncated message content] |
From: <ket...@us...> - 2013-12-07 01:48:40
|
Revision: 867 http://sourceforge.net/p/getdata/code/867 Author: ketiltrout Date: 2013-12-07 01:48:34 +0000 (Sat, 07 Dec 2013) Log Message: ----------- Test suite additions, with resultant bug fixes. This includes a fairly substantial rewrite of the guts of gd_move and gd_rename (including the deletion of gd_move_alias), and also of the sample index encoding stuff (sie.c). Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/NEWS trunk/getdata/bindings/cxx/dirfile.cpp trunk/getdata/bindings/cxx/entry.cpp trunk/getdata/bindings/cxx/getdata/dirfile.h trunk/getdata/bindings/cxx/getdata/entry.h trunk/getdata/bindings/cxx/test/big_test.cpp trunk/getdata/bindings/f77/fgetdata.c trunk/getdata/bindings/f77/getdata.f.in trunk/getdata/bindings/f77/getdata.f90.in trunk/getdata/bindings/f77/test/big_test.f trunk/getdata/bindings/f77/test/big_test95.f90 trunk/getdata/bindings/idl/getdata.c trunk/getdata/bindings/idl/test/big_test.pro trunk/getdata/bindings/make_parameters.c trunk/getdata/bindings/perl/simple_funcs.xsin trunk/getdata/bindings/perl/t/big_test.t trunk/getdata/bindings/php/getdata.c trunk/getdata/bindings/php/test/big_test.php trunk/getdata/bindings/python/pydirfile.c trunk/getdata/bindings/python/test/big_test.py trunk/getdata/doc/list.tests trunk/getdata/man/Makefile.am trunk/getdata/man/gd_alter_entry.3 trunk/getdata/man/gd_entry.3 trunk/getdata/man/gd_free_entry_strings.3 trunk/getdata/man/gd_move.3 trunk/getdata/man/gd_rename.3 trunk/getdata/src/add.c trunk/getdata/src/ascii.c trunk/getdata/src/common.c trunk/getdata/src/constant.c trunk/getdata/src/del.c trunk/getdata/src/encoding.c trunk/getdata/src/entry.c trunk/getdata/src/errors.c trunk/getdata/src/field_list.c trunk/getdata/src/flimits.c trunk/getdata/src/flush.c trunk/getdata/src/fpos.c trunk/getdata/src/getdata.c trunk/getdata/src/getdata.h.in trunk/getdata/src/gzip.c trunk/getdata/src/index.c trunk/getdata/src/internal.h trunk/getdata/src/legacy.c trunk/getdata/src/mod.c trunk/getdata/src/move.c trunk/getdata/src/name.c trunk/getdata/src/native.c trunk/getdata/src/open.c trunk/getdata/src/parse.c trunk/getdata/src/putdata.c trunk/getdata/src/sie.c trunk/getdata/test/Makefile.am trunk/getdata/test/alter_const.c trunk/getdata/test/alter_const_c2r.c trunk/getdata/test/alter_linterp.c trunk/getdata/test/del_const_deref.c trunk/getdata/test/entry_raw_scalar_code.c trunk/getdata/test/entry_raw_scalar_type.c trunk/getdata/test/get_linterp.c trunk/getdata/test/index_index.c trunk/getdata/test/move_alias.c trunk/getdata/test/move_data_enc_ar.c trunk/getdata/test/move_data_enc_ra.c trunk/getdata/test/move_data_endian.c trunk/getdata/test/move_data_foffs.c trunk/getdata/test/move_data_nop.c trunk/getdata/test/move_subdir.c trunk/getdata/test/name_affix.c trunk/getdata/test/name_alias.c trunk/getdata/test/name_name.c trunk/getdata/test/name_updb.c trunk/getdata/test/name_updb_const.c trunk/getdata/test/sie_get_big.c trunk/getdata/test/sie_put_big.c trunk/getdata/test/test.h Added Paths: ----------- trunk/getdata/test/add_dot.c trunk/getdata/test/alter_clincom.c trunk/getdata/test/alter_const_r2c.c trunk/getdata/test/alter_const_r2r.c trunk/getdata/test/alter_cpolynom_null.c trunk/getdata/test/alter_crecip89_null.c trunk/getdata/test/alter_entry_lincom.c trunk/getdata/test/alter_entry_recode_recalc.c trunk/getdata/test/alter_entry_scalar1.c trunk/getdata/test/alter_entry_scalar3c.c trunk/getdata/test/alter_index.c trunk/getdata/test/alter_spec_polynom.c trunk/getdata/test/ascii_get_complex.c trunk/getdata/test/ascii_sync.c trunk/getdata/test/bof_bit.c trunk/getdata/test/bof_index.c trunk/getdata/test/bof_phase_neg.c trunk/getdata/test/cvlist_array0.c trunk/getdata/test/cvlist_array_free.c trunk/getdata/test/cvlist_array_meta0.c trunk/getdata/test/cvlist_array_meta_free.c trunk/getdata/test/cvlist_meta0.c trunk/getdata/test/del_alias.c trunk/getdata/test/del_data_enoent.c trunk/getdata/test/del_data_open.c trunk/getdata/test/del_ref.c trunk/getdata/test/desync_path.c trunk/getdata/test/encode_alter_all.c trunk/getdata/test/encode_alter_open.c trunk/getdata/test/encode_recode.c trunk/getdata/test/encode_recode_open.c trunk/getdata/test/endian_alter_all.c trunk/getdata/test/eof_bit.c trunk/getdata/test/eof_phase_neg.c trunk/getdata/test/flist0.c trunk/getdata/test/flist2.c trunk/getdata/test/flist_meta2.c trunk/getdata/test/flush_lincom.c trunk/getdata/test/flush_lincom1.c trunk/getdata/test/flush_mult.c trunk/getdata/test/flush_raw_close.c trunk/getdata/test/flush_string.c trunk/getdata/test/flush_sync.c trunk/getdata/test/foffs_alter_all.c trunk/getdata/test/fragment_affix_alter_code.c trunk/getdata/test/fragment_affix_alter_nop.c trunk/getdata/test/get_cpolynom1.c trunk/getdata/test/get_cpolynom_int.c trunk/getdata/test/get_dim.c trunk/getdata/test/get_divide_ccin.c trunk/getdata/test/get_divide_crin.c trunk/getdata/test/get_divide_crinr.c trunk/getdata/test/get_divide_rcin.c trunk/getdata/test/get_divide_s.c trunk/getdata/test/get_index_complex.c trunk/getdata/test/get_lincom2s.c trunk/getdata/test/get_lincom3s.c trunk/getdata/test/get_lincom_mdt.c trunk/getdata/test/get_linterp1.c trunk/getdata/test/get_linterp_abs.c trunk/getdata/test/get_linterp_complex.c trunk/getdata/test/get_linterp_empty.c trunk/getdata/test/get_mplex_complex.c trunk/getdata/test/get_mplex_s.c trunk/getdata/test/get_mplex_saved.c trunk/getdata/test/get_multiply_ccin.c trunk/getdata/test/get_multiply_crin.c trunk/getdata/test/get_multiply_crinr.c trunk/getdata/test/get_multiply_rcin.c trunk/getdata/test/get_multiply_s.c trunk/getdata/test/get_neg.c trunk/getdata/test/get_polynom_cmpin.c trunk/getdata/test/get_window_complex.c trunk/getdata/test/get_window_s.c trunk/getdata/test/get_zero_complex.c trunk/getdata/test/get_zero_float.c trunk/getdata/test/gzip_del.c trunk/getdata/test/gzip_put_back.c trunk/getdata/test/gzip_sync.c trunk/getdata/test/index_s.c trunk/getdata/test/index_subset.c trunk/getdata/test/legacy_error.c trunk/getdata/test/legacy_estring.c trunk/getdata/test/legacy_format.c trunk/getdata/test/move_affix_meta.c trunk/getdata/test/move_affix_updb.c trunk/getdata/test/move_data_foffs_neg.c trunk/getdata/test/name_dangle.c trunk/getdata/test/name_dot.c trunk/getdata/test/name_meta.c trunk/getdata/test/name_updb_affix.c trunk/getdata/test/native_bit.c trunk/getdata/test/native_const.c trunk/getdata/test/native_index.c trunk/getdata/test/native_lincom.c trunk/getdata/test/native_lincom_cmpin.c trunk/getdata/test/native_lincom_cmpscal.c trunk/getdata/test/native_linterp.c trunk/getdata/test/native_linterp_cmp.c trunk/getdata/test/native_mult.c trunk/getdata/test/native_mult1.c trunk/getdata/test/native_mult2.c trunk/getdata/test/native_phase.c trunk/getdata/test/native_polynom.c trunk/getdata/test/native_polynom_cmpin.c trunk/getdata/test/native_polynom_cmpscal.c trunk/getdata/test/native_raw.c trunk/getdata/test/native_recip.c trunk/getdata/test/native_recip_cmpin.c trunk/getdata/test/native_recip_cmpscal.c trunk/getdata/test/native_sbit.c trunk/getdata/test/native_string.c trunk/getdata/test/open_cb_rescan_alloc.c trunk/getdata/test/open_invalid.c trunk/getdata/test/open_sym_as.c trunk/getdata/test/open_sym_d.c trunk/getdata/test/open_sym_l.c trunk/getdata/test/parse_hex.c trunk/getdata/test/parse_include_affix_bad.c trunk/getdata/test/parse_literal_cmpbad.c trunk/getdata/test/parse_literal_fltcmp.c trunk/getdata/test/parse_literal_fltcmp0.c trunk/getdata/test/parse_literal_intcmp.c trunk/getdata/test/parse_literal_intcmp0.c trunk/getdata/test/parse_literal_uintcmp.c trunk/getdata/test/parse_literal_uintcmp0.c trunk/getdata/test/parse_meta_frag.c trunk/getdata/test/parse_octal_zero.c trunk/getdata/test/parse_raw_char_bad.c trunk/getdata/test/parse_utf8.c trunk/getdata/test/parse_utf8_invalid.c trunk/getdata/test/parse_utf8_zero.c trunk/getdata/test/protect_alter_all.c trunk/getdata/test/put_carray_client.c trunk/getdata/test/put_clincom1.c trunk/getdata/test/put_cpolynom.c trunk/getdata/test/put_crecip.c trunk/getdata/test/put_mplex_complex.c trunk/getdata/test/repr_bad.c trunk/getdata/test/seek_index.c trunk/getdata/test/seek_lincom.c trunk/getdata/test/seek_mult.c trunk/getdata/test/seek_phase.c trunk/getdata/test/sie_put_append.c trunk/getdata/test/sie_put_append2.c trunk/getdata/test/sie_put_back.c trunk/getdata/test/sie_put_pad.c trunk/getdata/test/sie_put_pad0.c trunk/getdata/test/sie_put_trunc.c trunk/getdata/test/sie_put_trunc2.c trunk/getdata/test/sie_sync.c trunk/getdata/test/svlist0.c trunk/getdata/test/svlist2.c trunk/getdata/test/svlist_meta0.c trunk/getdata/test/unclude_open.c Removed Paths: ------------- trunk/getdata/test/encode_move.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/ChangeLog 2013-12-07 01:48:34 UTC (rev 867) @@ -1,4 +1,181 @@ -2013-11-15 D. V. Wiebe <ge...@ke...> svn:867 +2013-12-06 D. V. Wiebe <ge...@ke...> svn:867 + * test/add_dot.c test/alter_clincom.c test/alter_const_r2c.c test/sie_sync.c + test/alter_const_r2r.c test/alter_cpolynom_null.c test/alter_crecip89_null.c + test/alter_entry_lincom.c test/alter_entry_recode_recalc.c test/get_divide_s.c + test/alter_entry_scalar1.c test/alter_entry_scalar3c.c test/alter_index.c + test/alter_spec_polynom.c test/ascii_get_complex.c test/ascii_sync.c + test/bof_bit.c test/bof_index.c test/bof_phase_neg.c test/cvlist_array0.c + test/cvlist_array_free.c test/cvlist_array_meta0.c test/native_polynom_cmpin.c + test/cvlist_array_meta_free.c test/cvlist_meta0.c test/del_alias.c + test/del_data_enoent.c test/del_data_open.c test/del_ref.c test/desync_path.c + test/encode_alter_all.c test/encode_alter_open.c test/svlist_meta0.c + test/encode_recode_open.c test/endian_alter_all.c test/eof_bit.c test/flist2.c + test/eof_phase_neg.c test/flist0.c test/flist_meta2.c test/flush_lincom.c + test/flush_lincom1.c test/flush_mult.c test/sie_put_back.c test/put_cpolynom.c + test/flush_raw_close.c test/flush_string.c test/flush_sync.c test/svlist2.c + test/foffs_alter_all.c test/fragment_affix_alter_code.c test/native_recip.c + test/fragment_affix_alter_nop.c test/get_cpolynom1.c test/get_cpolynom_int.c + test/get_dim.c test/get_divide_ccin.c test/get_divide_crin.c test/native_raw.c + test/get_divide_crinr.c test/get_divide_rcin.c test/get_index_complex.c + test/get_lincom2s.c test/get_lincom3s.c test/get_lincom_mdt.c test/parse_hex.c + test/get_linterp1.c test/get_linterp_abs.c test/get_linterp_complex.c + test/get_linterp_empty.c test/get_mplex_complex.c test/get_mplex_s.c + test/get_mplex_saved.c test/get_multiply_ccin.c test/get_multiply_crin.c + test/get_multiply_crinr.c test/get_multiply_rcin.c test/get_multiply_s.c + test/get_neg.c test/get_polynom_cmpin.c test/get_window_complex.c + test/get_window_s.c test/get_zero_complex.c test/get_zero_float.c + test/gzip_del.c test/gzip_put_back.c test/gzip_sync.c test/index_s.c + test/index_subset.c test/legacy_error.c test/legacy_estring.c test/seek_mult.c + test/legacy_format.c test/move_affix_meta.c test/move_affix_updb.c + test/move_data_foffs_neg.c test/name_dangle.c test/name_dot.c test/name_meta.c + test/name_updb_affix.c test/native_bit.c test/native_const.c test/repr_bad.c + test/native_index.c test/native_lincom.c test/native_lincom_cmpin.c + test/native_lincom_cmpscal.c test/native_linterp.c test/native_linterp_cmp.c + test/native_mult.c test/native_mult1.c test/native_mult2.c test/native_phase.c + test/native_polynom.c test/native_polynom_cmpscal.c test/native_recip_cmpin.c + test/native_recip_cmpscal.c test/native_sbit.c test/native_string.c + test/open_cb_rescan_alloc.c test/open_invalid.c test/open_sym_as.c + test/open_sym_d.c test/open_sym_l.c test/parse_include_affix_bad.c + test/parse_literal_cmpbad.c test/parse_literal_fltcmp.c test/parse_meta_frag.c + test/parse_literal_fltcmp0.c test/parse_literal_intcmp.c test/sie_put_append.c + test/parse_literal_intcmp0.c test/parse_literal_uintcmp.c test/sie_put_trunc.c + test/parse_literal_uintcmp0.c test/parse_octal_zero.c test/protect_alter_all.c + test/parse_raw_char_bad.c test/parse_utf8.c test/parse_utf8_invalid.c + test/parse_utf8_zero.c test/put_carray_client.c test/put_clincom1.c + test/put_crecip.c test/put_mplex_complex.c test/svlist0.c test/seek_index.c + test/seek_lincom.c test/seek_phase.c test/sie_put_append2.c test/sie_put_pad.c + test/sie_put_trunc2.c test/sie_put_pad0.c test/unclude_open.c: Added. + + * test/encode_recode.c: Renamed. + + * src/add.c (_GD_Add): Set the right suberror (GD_E_ENTRY_POLYORD) for + poly_ord out of range. + + * src/add.c (gd_add_alias) src/field_list.c (_GD_EntryList): Remove + duplicate check for invalid dirfile. + + * src/ascii.c (_GD_ScanFormat): Append a newline. + + * src/ascii.c (_GD_AsciiRead): Use ferror instead of feof to check for stdio + errors. + + * src/common.c (_GD_ReadLinterpFile): Zero the LUT pointer on error. + * src/mod.c (_GD_Change): reset the LUT length to force table re-read. + Also, release the LUT directory. + + * src/common.c (_GD_CanonicalPath): Set errno to ELOOP late. + + * src/constant.c (_GD_PutCarraySlice): Added. + * src/constant.c (gd_put_carray_slice gd_put_carray): Call + _GD_PutCarraySlice. + + * src/del.c (_GD_Delete): Always close an open raw file, even when + deleting it. + + * src/encoding.c (_GD_RecodeFragment): Use _GD_FiniRawIO to close raw files. + Clear the internal cache of raw filenames. + + * src/entry.c (_GD_GetScalar): Return non-zero on error. Always call + _GD_DoField. + * src/entry.c (gd_entry): Return uncalculable entries rather than failing. + + * src/flimits.c (_GD_GetBOF): Also zero *ds if we're before sample zero. + + * src/flush.c (_GD_Flush): Validate input fields before trying to flush + them. Don't flush the second lincom field if it's not used. + + * src/flush.c (_GD_StringEscapeise): Remove duplicate check for ". + + * src/fpos.c (_GD_Seek): Fix sign on PHASE shift. + + * src/fpos.c (gd_seek64): Pass index_pos=-1 to _GD_GetFilePos. + + * src/getdata.c (_GD_CPolynomData _GD_CMultiplyData _GD_CDivideData): + Delete unused code: type is guaranteed to be complex in these calls. + * src/getdata.c (_GD_CDivideData): Fix computation of complex division. + + * src/getdata.c (_GD_DoLinterp): Delete check for uninitialised LUT: the + native type check done in DoField has already initialised the LUT. + + * src/index.c (_GD_GetIndex): Fix extrapolations performed when required to + search for the EOF. + * src/index.c (gd_framenum_subset64): Fix conversion of field_end from + frames to samples. + + * src/legacy.c (GetFormat): Allocate Format.mplexEntries. + + * src/mod.c (_GD_Change): Ensure a RAW entry is calculated before trying to + modify the data file. + + * src/mod.c (gd_alter_spec gd_malter_spec): Set move flags for POLYNOM + entries to ensure co-efficients are updated. + + * src/getdata.h.in: Added struct gd_rename_data_. Added GD_REN_DANGLE, + GD_REN_FORCE. + * src/move.c (_GD_Move) src/name.c (_GD_Rename): Call _GD_PrepareRename and + _GD_PerformRename to handle metadata updates resulting from name changes. + * src/move.c (gd_move): Replace move_data with flags argument, which accepts + the GD_REN_* flags. + * src/name.c (_GD_MatchCode _GD_MakeNewCode _GD_SetNewCode _GD_UpdateInputs + _GD_CleanUpRename _GD_PerformRename _GD_PrepareRename): Added. + * src/name.c (_GD_InvalidateConst _GD_InvalidateVect): Deleted. (Combined into + _GD_UpdateInputs). + * src/name.c (_GD_UpdateScalar _GD_UpdateInField): Call _GD_MatchCode + _GD_MakeNewCode _GD_SetNewCode for common code. Return non-zero on failure. + Update gd_rename_data_ struct in-place. + * src/name.c (_GD_MungeCode): If err_ok is 2, dont' worry at all about + errors. + * src/name.c (_GD_CheckCodeAffixes): Add set_error argument. Remember + success or failure separately from the DIRFILE error. + + * src/move.c (gd_move_alias): Deleted. + * src/move.c (gd_move): Don't delalias the provided field code. + * bindings/cxx/dirfile.cpp (Dirfile::MoveAlias) bindings/f77/fgetdata.c + (GDMOVA) bindings/f77/getdata.f90.in (fgd_move_alias) + bindings/perl/simple_funcs.xsin (move_alias) bindings/php/getdata.c + (gd_move_alias) bindings/python/pydirfile.c (gdpy_dirfile_movealias): + Deleted. + * bindings/idl/getdata.c (gdidl_move gdidl_rename): Remove keyword ALIAS; + add keywords DANGLE, FORCE, UPDATEDB. + * bindings/cxx/test/big_test.cpp bindings/f77/test/big_test.f + bindings/f77/test/big_test95.f90 bindings/idl/test/big_test.pro + bindings/perl/t/big_test.t bindings/php/test/big_test.php + bindings/python/test/big_test.py: Delete test 224. + + * src/native.c (_GD_NativeType): Don't always return GD_FLOAT64 for LINCOMs. + + * src/errors.c: Added GD_E_OPEN_IO. + * src/open.c (_GD_Open): Throw GD_E_OPEN instead of GD_E_RAW_IO if resolving + the supplied path fails. + + * src/parse.c (_GD_SetScalar): Allow literals in semicolon (complex) form in + all cases but require a zero imaginary part for non-complex data. + + * src/parse.c (_GD_Tokenise): Fix parsing of \x and \u. Don't unnecessarily + overwrite earlier errors with GD_E_FORMAT_UNTERM. + + * src/putdata.c (_GD_MplexOutData): Fix computation of complex data. + + * src/sie.c: Added l, have_l and bof to struct gd_siedata. Also, f->d[0] + is no longer endianness corrected (ie. f->d is now simply the raw record), + which means we use f->s in most places where we used f->d[0] previously. + + * src/sie.c (_GD_Advance): remember the previous record in f->l. Also set + f->bof. + + * src/sie.c (_GD_SampIndSeek): check stdio calls for failure. Correctly + format a padding record when write seeking past the EOF. + + * src/sie.c (_GD_SampIndWrite): Correctly deal with appending data, + including backing up a record when necessary to check whether we need to + combine the start of the new data with that record. Compose p with the + output endianness. + + * bindings/idl/getdata.c (gdidl_rename): Fix handling of UPDATEDB. + + * bindings/php/getdata.c (gd_rewrite_fragment): Initalise zi. + +2013-11-15 D. V. Wiebe <ge...@ke...> svn:866 * test/add_add.c test/close_close.c test/del_del.c test/flush_flush.c test/include_include.c test/index_index.c test/move_move.c test/name_name.c test/nfields_nfields.c test/nframes_nframes.c test/open_open.c Modified: trunk/getdata/NEWS =================================================================== --- trunk/getdata/NEWS 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/NEWS 2013-12-07 01:48:34 UTC (rev 867) @@ -2,8 +2,26 @@ Library Changes: - * The gd_free_entry_strings() function now NULLs pointers after freeing them. + * Literals in format metadata may now have complex form (i.e. include a + semicolon) when the parameter is purely real. However, a non-zero imaginary + part is still an error. + * BUG FIX: The parsing of the \x and \u escape sequences are now correct. + + * BUG FIX: Computation of LINCOMs with complex valued input fields now + correctly happens in the complex plane. As a side effect, gd_native_type() + now also correctly reports such LINCOM fields to be complex valued. + + * BUG FIX: If performing a metadata update due to renaming fields (perhaps + by passing GD_REN_UPDB to gd_rename()) results in an invalid field code + due to affix restrictions, the update now fails (but see GD_REN_FORCE). + Previously the invalid field code would be stored, leading to errors when + flushing the modified metadata to disk. + + * BUG FIX: When performing a metadata update due to a renamed field, the field + codes containing subfields of the renamed field are now also updated, + including field codes specifying meta subfield which do not exist. + * BUG FIX: The gd_[m]add() functions now ignore zero-length scalar strings. Previously they would store these invalid field codes, causing problems later. @@ -26,6 +44,88 @@ * BUG FIX: gd_alter_entry() no longer corrupts the DIRFILE when modifying named scalars of MPLEX fields. + * BUG FIX: reading a LINTERP table with fewer than two lines no longer results + in a segfault on close/discard. + + * BUG FIX: DIVIDE fields with complex valued divisors are now properly + computed. + + * BUG FIX: Writing complex MPLEX fields no longer corrupts the stored data. + + * BUG FIX: Several fixes have been made to the sample index encoding (SIE) + engine, which should now produce properly encoded data when performing + random writes. + + API Changes: + + * gd_free_entry_strings() now NULLs pointers after freeing them. + + * gd_entry() now returns entry metadata when they contain scalar field codes + which do not exist. Previously, it would fail with the error + GD_E_BAD_SCALAR and return nothing. + + * Two new rename flags have been added: + - GD_REN_DANGLE which indicates the library shouldn't update ALIASes whose + target has been renamed (turning them into dangling aliases) + - GD_REN_FORCE which causes the library to skip updating field codes which + would be invalid due to affixes instead of failing. + + * gd_rename() now by default updates the target of ALIASes pointing to a + renamed field to point to the new field instead of leaving them dangle. + (But see GD_REN_DANGLE). + + * The move_data argument of gd_move() has been replaced with a flags argument + which accepts the GD_REN_* flags, which have the same meaning as they do + with gd_rename(). + + * gd_move_alias() has been deleted: its function is now performed by + gd_move(). If gd_move() is passed the field code of an alias, the alias is + now moved, instead of moving the field the alias points to. + + * BUG FIX: If the dirfile path provided cannot be resolved (due to, for + instance, a symbolic link pointing to a non-existent path), gd_open() and + friends now return GD_E_OPEN, as documented, instead of GD_E_RAW_IO. + + * BUG FIX: gd_bof() now returns the correct number (i.e.: zero) when reporting + the beginning of field of derived fields shifted to before the start of the + dirfile. Previously, this function incorrectly returned values ranging from + zero to one less than the samples-per-frame of the requested field. + + * BUG FIX: gd_flush(), gd_sync(), gd_raw_close() no longer segfault when + operating on a LINCOM with only one input field. + + * BUG FIX: gd_seek() now works correctly on PHASE fields; previously, the + sign of the PHASE shift was flipped. + + * BUG FIX: gd_seek() now correctly positions the virtual I/O pointer of the + INDEX field. + + * BUG FIX: gd_framenum_subset() now returns the correct value when passed a + field_end which is beyond the end of field, and then is required to + extrapolate outside of the specified frame range. + + * BUG FIX: gd_add_polynom() and similar now produce the correct error string + when encountering a poly_ord out of range. + + * BUG FIX: gd_alter_raw() and similar no longer fail when asked to re-encode + the data file of a RAW field which has not been previously accessed. + + * BUG FIX: A previously-read LINTERP table is now always deleted when changing + table paths with gd_alter_linterp() or similar. Previously these obsolete, + cached LUTs would sometimes linger, causing incorrect LINTERP computation. + + * BUG FIX: gd_[m]alter_spec() no longer ignore co-efficients specified for + POLYNOM entries. + + * BUG FIX: gd_alter_encoding() now deletes the internal cache of RAW filenames + of the affected fragment; previously, these old, cached filenames could lead + to I/O errors when reading and writing the re-encoded RAW data files. + + Legacy API Changes: + + * BUG FIX: Calling GetFormat on a Dirfile with MPLEX or WINDOW fields no + longer results in a segmentation fault. + Bindings Changes: * PHP bindings have been added. @@ -53,14 +153,17 @@ * PERL: alter_entry() now only updates defined elements in the passed entry hash. + * C++ BUG FIX: Fixed segfault in RawEntry destructor. Reported by S. J. + Benton. + * F77 and F95 BUG FIX: Named scalar indices are now indexed from one instead of zero, like all other array indices are in the Fortran GetData bindings. * F95 BUG FIX: fgd_add and fgd_alter_entry no longer ignore named scalar parameters provided in supplied entry structures. - * C++ BUG FIX: Fixed segfault in RawEntry destructor. Reported by S. J. - Benton. + * IDL BUG FIX: the /UPDATEDB flag to gd_rename now operates as expected. + Previously it would act like /MOVE_DATA. |==============================================================================| Modified: trunk/getdata/bindings/cxx/dirfile.cpp =================================================================== --- trunk/getdata/bindings/cxx/dirfile.cpp 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/cxx/dirfile.cpp 2013-12-07 01:48:34 UTC (rev 867) @@ -496,11 +496,6 @@ return gd_madd_alias(D, parent, name, target); } -int Dirfile::MoveAlias(const char* field_code, int new_fragment) const -{ - return gd_move_alias(D, field_code, new_fragment); -} - int Dirfile::NAliases(const char* field_code) const { return gd_naliases(D, field_code); Modified: trunk/getdata/bindings/cxx/entry.cpp =================================================================== --- trunk/getdata/bindings/cxx/entry.cpp 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/cxx/entry.cpp 2013-12-07 01:48:34 UTC (rev 867) @@ -76,12 +76,12 @@ return 1; } -int Entry::Move(int new_fragment, int move_data) +int Entry::Move(int new_fragment, unsigned flags) { int ret = -1; if (D != NULL) - ret = gd_move(D->D, E.field, new_fragment, move_data); + ret = gd_move(D->D, E.field, new_fragment, flags); if (!ret) E.fragment_index = new_fragment; @@ -89,13 +89,13 @@ return ret; } -int Entry::Rename(const char* new_name, int move_data) +int Entry::Rename(const char* new_name, unsigned flags) { char* ptr; int ret = -1; if (D != NULL) - ret = gd_rename(D->D, E.field, new_name, move_data); + ret = gd_rename(D->D, E.field, new_name, flags); if (ret) { if (E.field == NULL) { Modified: trunk/getdata/bindings/cxx/getdata/dirfile.h =================================================================== --- trunk/getdata/bindings/cxx/getdata/dirfile.h 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/cxx/getdata/dirfile.h 2013-12-07 01:48:34 UTC (rev 867) @@ -205,8 +205,6 @@ const char **MStrings(const char *parent) const; - int MoveAlias(const char* field_code, int new_fragment) const; - const char **MVectorList(const char *parent) const; int NAliases(const char* field_code) const; Modified: trunk/getdata/bindings/cxx/getdata/entry.h =================================================================== --- trunk/getdata/bindings/cxx/getdata/entry.h 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/cxx/getdata/entry.h 2013-12-07 01:48:34 UTC (rev 867) @@ -89,9 +89,9 @@ int FragmentIndex() const { return E.fragment_index; }; - int Move(int new_fragment, int move_data = 0); + int Move(int new_fragment, unsigned flags = 0); - int Rename(const char* new_name, int move_data = 0); + int Rename(const char* new_name, unsigned flags = 0); /* Specific data */ virtual const char *Input(int index = 0) const { Modified: trunk/getdata/bindings/cxx/test/big_test.cpp =================================================================== --- trunk/getdata/bindings/cxx/test/big_test.cpp 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/cxx/test/big_test.cpp 2013-12-07 01:48:34 UTC (rev 867) @@ -1573,19 +1573,11 @@ d->IncludeAffix("format1", 0, "A", "Z", GD_CREAT | GD_EXCL); CHECK_OK(223); - // 224: gd_move_alias check - d->MoveAlias("new20", 1); - CHECK_OK2(224, 1); - - n = d->FragmentIndex("Anew20Z"); - CHECK_OK2(224, 2); - CHECK_INT(224, n, 1); - // 225: gd_delete_alias check - d->DeleteAlias("Anew20Z", 0); + d->DeleteAlias("new20", 0); CHECK_OK2(225, 1); - n = d->FragmentIndex("Anew20Z"); + n = d->FragmentIndex("new20"); CHECK_ERROR2(225, 2, GD_E_BAD_CODE); CHECK_INT(225, n, -1); Modified: trunk/getdata/bindings/f77/fgetdata.c =================================================================== --- trunk/getdata/bindings/f77/fgetdata.c 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/f77/fgetdata.c 2013-12-07 01:48:34 UTC (rev 867) @@ -2910,15 +2910,15 @@ /* gd_move wrapper */ void F77_FUNC(gdmove, GDMOVE) (const int32_t *dirfile, const char *field_code, const int32_t *field_code_l, const int32_t *new_fragment, - const int32_t *move_data) + const int32_t *flags) { char *fc; dtrace("%i, %p, %i, %i, %i", *dirfile, field_code, *field_code_l, - *new_fragment, *move_data); + *new_fragment, *flags); gd_move(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, - *field_code_l), *new_fragment, *move_data); + *field_code_l), *new_fragment, *flags); free(fc); dreturnvoid(); @@ -2927,15 +2927,15 @@ /* gd_rename wrapper */ void F77_FUNC(gdrenm, GDRENM) (const int32_t *dirfile, const char *field_code, const int32_t *field_code_l, const char *new_name, - const int32_t *new_name_l, const int32_t *move_data) + const int32_t *new_name_l, const int32_t *flags) { char *fc, *nn; dtrace("%i, %p, %i, %p, %i, %i", *dirfile, field_code, *field_code_l, - new_name, *new_name_l, *move_data); + new_name, *new_name_l, *flags); gd_rename(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, - *field_code_l), _GDF_CString(&nn, new_name, *new_name_l), *move_data); + *field_code_l), _GDF_CString(&nn, new_name, *new_name_l), *flags); free(nn); free(fc); @@ -3787,21 +3787,6 @@ dreturnvoid(); } -/* gd_move_alias wrapper */ -void F77_FUNC(gdmova, GDMOVA) (const int32_t *dirfile, const char *field_code, - const int32_t *field_code_l, const int32_t *new_fragment) -{ - char *fc; - - dtrace("%i, %p, %i, %i", *dirfile, field_code, *field_code_l, *new_fragment); - - gd_move_alias(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, - *field_code_l), *new_fragment); - - free(fc); - dreturnvoid(); -} - /* gd_include_affix wrapper */ void F77_FUNC(gdinca, GDINCA) (const int32_t *dirfile, const char *file, const int32_t *file_l, const int32_t *fragment_index, const char *prefix, Modified: trunk/getdata/bindings/f77/getdata.f.in =================================================================== --- trunk/getdata/bindings/f77/getdata.f.in 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/f77/getdata.f.in 2013-12-07 01:48:34 UTC (rev 867) @@ -337,8 +337,6 @@ EXTERNAL GDMFNX C Correpsonding to gd_malter_spec(3) EXTERNAL GDMLSP -C Correpsonding to gd_move_alias(3) - EXTERNAL GDMOVA C Correpsonding to gd_move(3) EXTERNAL GDMOVE C Corresponding to gd_mstrings(3) (sort of) Modified: trunk/getdata/bindings/f77/getdata.f90.in =================================================================== --- trunk/getdata/bindings/f77/getdata.f90.in 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/f77/getdata.f90.in 2013-12-07 01:48:34 UTC (rev 867) @@ -1624,12 +1624,12 @@ LEN_TRIM(field_code)) end function -subroutine fgd_move (dirfile, field_code, new_fragment, move_data) - integer, intent(in) :: dirfile, new_fragment, move_data +subroutine fgd_move (dirfile, field_code, new_fragment, flags) + integer, intent(in) :: dirfile, new_fragment, flags character (len=*), intent(in) :: field_code call gdmove (dirfile, TRIM(field_code), LEN_TRIM(field_code), new_fragment, & - move_data) + flags) end subroutine ! calculate in_fields string lengths @@ -1966,12 +1966,12 @@ LEN_TRIM(parent), recode) end subroutine -subroutine fgd_rename (dirfile, field_code, new_name, move_data) - integer, intent(in) :: dirfile, move_data +subroutine fgd_rename (dirfile, field_code, new_name, flags) + integer, intent(in) :: dirfile, flags character (len=*), intent(in) :: field_code, new_name call gdrenm(dirfile, TRIM(field_code), LEN_TRIM(field_code), TRIM(new_name), & - LEN_TRIM(new_name), move_data) + LEN_TRIM(new_name), flags) end subroutine subroutine fgd_delete (dirfile, field_code, flags) @@ -2865,13 +2865,6 @@ LEN_TRIM(field_code), TRIM(targ), LEN_TRIM(targ)) end subroutine -subroutine fgd_move_alias (dirfile, field_code, new_fragment) - integer, intent(in) :: dirfile, new_fragment - character (len=*), intent(in) :: field_code - - call gdmova (dirfile, TRIM(field_code), LEN_TRIM(field_code), new_fragment) -end subroutine - subroutine fgd_include_affix (dirfile, fragmentname, fragment_index, prefix, & suffix, flags) integer, intent(in) :: dirfile, fragment_index, flags Modified: trunk/getdata/bindings/f77/test/big_test.f =================================================================== --- trunk/getdata/bindings/f77/test/big_test.f 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/f77/test/big_test.f 2013-12-07 01:48:34 UTC (rev 867) @@ -1990,19 +1990,11 @@ CALL GDINCA(d, 'format1', 7, 0, 'A', 1, 'Z', 1, GD_CR + GD_EX) CALL CHKEOK(ne, 223, d) -C 224: GDMOVA check - CALL GDMOVA(d, 'new20', 5, 1) - CALL CHKOK2(ne, 224, 1, d) - - CALL GDFRGI(n, d, 'Anew20Z', 7) - CALL CHKOK2(ne, 224, 2, d) - CALL CHKINT(ne, 224, n, 1) - C 225: GDDELA check - CALL GDDELA(d, 'Anew20Z', 7, 0) + CALL GDDELA(d, 'new20', 7, 0) CALL CHKOK2(ne, 225, 1, d) - CALL GDFRGI(n, d, 'Anew20Z', 7) + CALL GDFRGI(n, d, 'new20', 7) CALL CHKER2(ne, 225, 2, d, GD_EBC) CALL CHKINT(ne, 225, n, -1) Modified: trunk/getdata/bindings/f77/test/big_test95.f90 =================================================================== --- trunk/getdata/bindings/f77/test/big_test95.f90 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/f77/test/big_test95.f90 2013-12-07 01:48:34 UTC (rev 867) @@ -2405,19 +2405,11 @@ call fgd_include_affix(d, 'format1', 0, 'A', 'Z', GD_CREAT + GD_EXCL) call check_ok(ne, 223, d) -! 224: GDMOVA check - call fgd_move_alias(d, 'new20', 1) - call check_ok2(ne, 224, 1, d) - - n = fgd_fragment_index(d, 'Anew20Z') - call check_ok2(ne, 224, 2, d) - call check_int(ne, 224, n, 1) - ! 225: fgd_delete_alias check - call fgd_delete_alias(d, 'Anew20Z', 0) + call fgd_delete_alias(d, 'new20', 0) call check_ok2(ne, 225, 1, d) - n = fgd_fragment_index(d, 'Anew20Z') + n = fgd_fragment_index(d, 'new20') call check_err2(ne, 225, 2, d, GD_E_BAD_CODE) call check_int(ne, 225, n, -1) Modified: trunk/getdata/bindings/idl/getdata.c =================================================================== --- trunk/getdata/bindings/idl/getdata.c 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/idl/getdata.c 2013-12-07 01:48:34 UTC (rev 867) @@ -3355,19 +3355,20 @@ typedef struct { IDL_KW_RESULT_FIRST_FIELD; GDIDL_KW_RESULT_ERROR; - int move_data; - int alias; + int dangle, force, move_data, updatedb; } KW_RESULT; KW_RESULT kw; - kw.move_data = kw.alias = 0; + kw.dangle = kw.force = kw.move_data = kw.updatedb = 0; GDIDL_KW_INIT_ERROR; static IDL_KW_PAR kw_pars[] = { - { "ALIAS", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(alias) }, + { "DANGLE", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(dangle) }, GDIDL_KW_PAR_ERROR, GDIDL_KW_PAR_ESTRING, + { "FORCE", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(force) }, { "MOVE_DATA", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(move_data) }, + { "UPDATEDB", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(updatedb) }, { NULL } }; @@ -3376,10 +3377,11 @@ DIRFILE* D = gdidl_get_dirfile(IDL_LongScalar(argv[0])); const char* field_code = IDL_VarGetString(argv[1]); - if (kw.alias) - gd_move_alias(D, field_code, IDL_LongScalar(argv[2])); - else - gd_move(D, field_code, IDL_LongScalar(argv[2]), kw.move_data); + gd_move(D, field_code, IDL_LongScalar(argv[2]), + (kw.dangle ? GD_REN_DANGLE : 0) | + (kw.force ? GD_REN_FORCE : 0) | + (kw.move_data ? GD_REN_DATA : 0) | + (kw.updatedb ? GD_REN_UPDB : 0)); GDIDL_SET_ERROR(D); @@ -3550,17 +3552,18 @@ typedef struct { IDL_KW_RESULT_FIRST_FIELD; GDIDL_KW_RESULT_ERROR; - int updatedb; - int move_data; + int dangle, force, move_data, updatedb; } KW_RESULT; KW_RESULT kw; - kw.move_data = kw.updatedb = 0; + kw.dangle = kw.force = kw.move_data = kw.updatedb = 0; GDIDL_KW_INIT_ERROR; static IDL_KW_PAR kw_pars[] = { + { "DANGLE", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(dangle) }, GDIDL_KW_PAR_ERROR, GDIDL_KW_PAR_ESTRING, + { "FORCE", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(force) }, { "MOVE_DATA", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(move_data) }, { "UPDATEDB", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(updatedb) }, { NULL } @@ -3572,8 +3575,11 @@ const char* field_code = IDL_VarGetString(argv[1]); const char* new_code = IDL_VarGetString(argv[2]); - gd_rename(D, field_code, new_code, (kw.move_data ? GD_REN_DATA : 0) | - (kw.move_data ? GD_REN_UPDB : 0)); + gd_rename(D, field_code, new_code, + (kw.dangle ? GD_REN_DANGLE : 0) | + (kw.force ? GD_REN_FORCE : 0) | + (kw.move_data ? GD_REN_DATA : 0) | + (kw.updatedb ? GD_REN_UPDB : 0)); GDIDL_SET_ERROR(D); Modified: trunk/getdata/bindings/idl/test/big_test.pro =================================================================== --- trunk/getdata/bindings/idl/test/big_test.pro 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/idl/test/big_test.pro 2013-12-07 01:48:34 UTC (rev 867) @@ -1259,19 +1259,11 @@ gd_include, d, 'format1', prefix='A', suffix='Z', /CREAT, /EXCL nume += check_ok(223, d) -; 224: GDMOVA check -gd_move, d, 'new20', 1, /ALIAS -nume += check_ok2(224, 1, d) - -n = gd_fragment_index(d, 'Anew20Z') -nume += check_ok2(224, 2, d) -nume += check_simple(224, n, 1) - ; 225: gd_delete_alias check -gd_delete, d, 'Anew20Z', /ALIAS +gd_delete, d, 'new20', /ALIAS nume += check_ok2(225, 1, d) -n = gd_fragment_index(d, 'Anew20Z') +n = gd_fragment_index(d, 'new20') nume += check_error2(225, 2, d, !GD.E_BAD_CODE) nume += check_simple(225, n, -1) Modified: trunk/getdata/bindings/make_parameters.c =================================================================== --- trunk/getdata/bindings/make_parameters.c 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/make_parameters.c 2013-12-07 01:48:34 UTC (rev 867) @@ -166,6 +166,8 @@ CONSTANT(DEL_FORCE, "GDD_FO", 5), CONSTANT(REN_DATA, "GDR_DT", 5), CONSTANT(REN_UPDB, "GDR_UP", 5), + CONSTANT(REN_DANGLE, "GDR_DL", 5), + CONSTANT(REN_FORCE, "GDR_FO", 5), CONSTANT(PROTECT_NONE, "GDPR_N", 6), CONSTANT(PROTECT_FORMAT, "GDPR_F", 6), Modified: trunk/getdata/bindings/perl/simple_funcs.xsin =================================================================== --- trunk/getdata/bindings/perl/simple_funcs.xsin 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/perl/simple_funcs.xsin 2013-12-07 01:48:34 UTC (rev 867) @@ -123,7 +123,6 @@ int hidden(DIRFILE *dirfile, const char *field_code) int unhide(DIRFILE *dirfile, const char *field_code) int sync(DIRFILE *dirfile, const char *field_code) -int move_alias(DIRFILE *dirfile, const char *field_code, int new_fragment) int delete_alias(DIRFILE *dirfile, const char *field_code, unsigned int flags=0) const char *alias_target(DIRFILE *dirfile, const char *field_code) int add_alias(DIRFILE *dirfile, const char *field_code, const char *target, Modified: trunk/getdata/bindings/perl/t/big_test.t =================================================================== --- trunk/getdata/bindings/perl/t/big_test.t 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/perl/t/big_test.t 2013-12-07 01:48:34 UTC (rev 867) @@ -22,7 +22,7 @@ use GetData; use Math::Complex; use strict; -use Test::More tests => 1521; +use Test::More tests => 1518; my $ne = 0; my ($s, @a, %h); @@ -1601,19 +1601,11 @@ $s = $_->include('format1', 0, $GetData::CREAT | $GetData::EXCL, 'A', 'Z'); CheckOK(223); -# 224: GDMOVA check -$s = $_->move_alias('new20', 1); -CheckOK2(224, 1); - -$s = $_->fragment_index('Anew20Z'); -CheckOK2(224, 2); -CheckNum(224, $s, 1); - # 225: gd_delete_alias check -$s = $_->delete_alias('Anew20Z', 0); +$s = $_->delete_alias('new20', 0); CheckOK2(225, 1); -$_->fragment_index('Anew20Z'); +$_->fragment_index('new20'); CheckError2(225, 2, $GetData::E_BAD_CODE); # 226: gd_fragment_affixes check Modified: trunk/getdata/bindings/php/getdata.c =================================================================== --- trunk/getdata/bindings/php/getdata.c 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/php/getdata.c 2013-12-07 01:48:34 UTC (rev 867) @@ -3900,32 +3900,17 @@ char *field_code; int field_code_len; long new_fragment; - zend_bool move_data = 0; + long flags = 0; DIRFILE *D; dtracephp(); - GDPHP_PARSED("sl|b", &field_code, &field_code_len, &new_fragment, &move_data); + GDPHP_PARSED("sl|l", &field_code, &field_code_len, &new_fragment, &flags); - GDPHP_RETURN_BOOL(gd_move(D, field_code, new_fragment, move_data)); + GDPHP_RETURN_BOOL(gd_move(D, field_code, new_fragment, flags)); } -PHP_FUNCTION(gd_move_alias) -{ - char *field_code; - int field_code_len; - long new_fragment; - - DIRFILE *D; - - dtracephp(); - - GDPHP_PARSED("sl", &field_code, &field_code_len, &new_fragment); - - GDPHP_RETURN_BOOL(gd_move_alias(D, field_code, new_fragment)); -} - PHP_FUNCTION(gd_mplex_lookback) { long lookback; @@ -4482,7 +4467,7 @@ PHP_FUNCTION(gd_rewrite_fragment) { - zval *zi; + zval *zi = NULL; long i; @@ -4803,7 +4788,6 @@ PHP_FE(gd_mfield_list, NULL) PHP_FE(gd_mfield_list_by_type, NULL) PHP_FE(gd_move, NULL) - PHP_FE(gd_move_alias, NULL) PHP_FE(gd_mplex_lookback, NULL) PHP_FE(gd_mstrings, NULL) PHP_FE(gd_mvector_list, NULL) Modified: trunk/getdata/bindings/php/test/big_test.php =================================================================== --- trunk/getdata/bindings/php/test/big_test.php 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/php/test/big_test.php 2013-12-07 01:48:34 UTC (rev 867) @@ -1357,21 +1357,12 @@ check_ok2(223, 0, $D); check_var2(223, 1, $v, 1); -# 224: move alias -$v = gd_move_alias($D, 'new20', 1); -check_ok2(224, 0, $D); -check_var2(224, 1, $v, TRUE); - -$v = gd_fragment_index($D, 'Anew20Z'); -check_ok2(224, 2, $D); -check_var2(224, 3, $v, 1); - # 225: delete alias -$v = gd_delete_alias($D, 'Anew20Z'); +$v = gd_delete_alias($D, 'new20'); check_ok2(225, 0, $D); check_var2(225, 1, $v, TRUE); -$v = gd_fragment_index($D, 'Anew20Z'); +$v = gd_fragment_index($D, 'new20'); check_error2(225, 2, $D, GD_E_BAD_CODE); check_var2(225, 3, $v, FALSE); Modified: trunk/getdata/bindings/python/pydirfile.c =================================================================== --- trunk/getdata/bindings/python/pydirfile.c 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/python/pydirfile.c 2013-12-07 01:48:34 UTC (rev 867) @@ -2157,20 +2157,20 @@ static PyObject *gdpy_dirfile_move(struct gdpy_dirfile_t *self, PyObject *args, PyObject *keys) { - char *keywords[] = { "field_code", "new_fragment", "move_data", NULL }; + char *keywords[] = { "field_code", "new_fragment", "flags", NULL }; const char *field_code; int new_fragment; - int move_data = 0; + unsigned flags = 0; dtrace("%p, %p, %p", self, args, keys); - if (!PyArg_ParseTupleAndKeywords(args, keys, "si|i:pygetdata.dirfile.move", - keywords, &field_code, &new_fragment, &move_data)) { + if (!PyArg_ParseTupleAndKeywords(args, keys, "si|I:pygetdata.dirfile.move", + keywords, &field_code, &new_fragment, &flags)) { dreturn ("%p", NULL); return NULL; } - gd_move(self->D, field_code, new_fragment, move_data); + gd_move(self->D, field_code, new_fragment, flags); PYGD_CHECK_ERROR(self->D, NULL); @@ -2429,32 +2429,6 @@ return pyobj; } -static PyObject *gdpy_dirfile_movealias(struct gdpy_dirfile_t *self, - PyObject *args, PyObject *keys) -{ - char *keywords[] = { "field_code", "new_fragment", NULL }; - const char *field_code; - int new_fragment; - - dtrace("%p, %p, %p", self, args, keys); - - if (!PyArg_ParseTupleAndKeywords(args, keys, - "si:pygetdata.dirfile.move_alias", keywords, &field_code, - &new_fragment)) - { - dreturn ("%p", NULL); - return NULL; - } - - gd_move_alias(self->D, field_code, new_fragment); - - PYGD_CHECK_ERROR(self->D, NULL); - - Py_INCREF(Py_None); - dreturn("%p", Py_None); - return Py_None; -} - static PyObject *gdpy_dirfile_deletealias(struct gdpy_dirfile_t *self, void *args, void *keys) { @@ -3081,7 +3055,6 @@ METH_VARARGS | METH_KEYWORDS, "linterp_tablename(field_code)\n\n" "Return the pathname of the look-up table (LUT) on disk used by the\n" - /* ------- handy ruler ---------------------------------------------| */ "LINTERP field specified by 'field_code'. See\n" "gd_linterp_tablename(3)." }, @@ -3273,12 +3246,12 @@ "Flush all pending metadata changes to disk. See gd_metaflush(3)." }, {"move", (PyCFunction)gdpy_dirfile_move, METH_VARARGS | METH_KEYWORDS, - "move(field_code, new_fragment [, move_data])\n\n" + "move(field_code, new_fragment [, flags])\n\n" "Move the specification of the field given by 'field_code' to the\n" - "format file fragment indexed by 'new_fragment'. If 'move_data' is\n" - "given and is non-zero, and 'field_code' specifies a RAW field, the\n" - "associated file on disk will also be moved, if necessary. See\n" - "gd_move(3)." + /* ------- handy ruler ---------------------------------------------| */ + "format file fragment indexed by 'new_fragment'. If 'flags' is given\n" + "and is non-zero, it should be a bitwise or'd collection of the\n" + "pygetdat.REN_* symbols. See gd_move(3)." }, {"put_carray", (PyCFunction)gdpy_dirfile_putcarray, METH_VARARGS | METH_KEYWORDS, @@ -3394,12 +3367,6 @@ "field. If field_code is valid, this will be at least one. See\n" "gd_naliases(3)." }, - {"move_alias", (PyCFunction)gdpy_dirfile_movealias, - METH_VARARGS | METH_KEYWORDS, - "move_alias(field_code, new_fragment)\n\n" - "This moves the alias specified by 'field_code' to the fragment\n" - "indexed by 'new_fragment'. See gd_move_alias(3)." - }, {"delete_alias", (PyCFunction)gdpy_dirfile_deletealias, METH_VARARGS | METH_KEYWORDS, "delete_alias(field_code[, flags])\n\n" Modified: trunk/getdata/bindings/python/test/big_test.py =================================================================== --- trunk/getdata/bindings/python/test/big_test.py 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/bindings/python/test/big_test.py 2013-12-07 01:48:34 UTC (rev 867) @@ -1794,26 +1794,14 @@ except: CheckOK(223) -# 224: gd_move_alias check -try: - d.move_alias('new20', 1) -except: - CheckOK2(224, 1) - -try: - n = d.fragment_index('Anew20Z') -except: - CheckOK2(224, 2) -CheckSimple(224, n, 1) - # 225: gd_delete_alias check try: - d.delete_alias('Anew20Z', 0) + d.delete_alias('new20', 0) except: CheckOK2(225, 1) try: - n = d.fragment_index('Anew20Z') + n = d.fragment_index('new20') except: CheckException2(255, 2, pygetdata.BadCodeError) Modified: trunk/getdata/doc/list.tests =================================================================== --- trunk/getdata/doc/list.tests 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/doc/list.tests 2013-12-07 01:48:34 UTC (rev 867) @@ -222,7 +222,7 @@ 221 F9CIpPmh gd_naliases 222 F9CIpPmh gd_aliases 223 F9CIpPmh gd_include_affix -224 F9CIpPmh gd_move_alias +224 ........ (unused) 225 F9CIpPmh gd_delete_alias 226 F9CIpPmh gd_fragment_affixes 227 F9CIpPmh gd_alter_affixes Modified: trunk/getdata/man/Makefile.am =================================================================== --- trunk/getdata/man/Makefile.am 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/man/Makefile.am 2013-12-07 01:48:34 UTC (rev 867) @@ -86,7 +86,6 @@ gd_put_carray_slice.3:gd_put_carray.3 \ gd_put_carray_slice.3:gd_put_constant.3 \ gd_delete.3:gd_delete_alias.3 \ - gd_move.3:gd_move_alias.3 \ gd_hide.3:gd_unhide.3 \ gd_add_alias.3:gd_madd_alias.3 \ gd_flush.3:gd_sync.3 gd_flush.3:gd_raw_close.3 \ Modified: trunk/getdata/man/gd_alter_entry.3 =================================================================== --- trunk/getdata/man/gd_alter_entry.3 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/man/gd_alter_entry.3 2013-12-07 01:48:34 UTC (rev 867) @@ -13,7 +13,7 @@ .\" Texts. A copy of the license is included in the `COPYING.DOC' file .\" as part of this distribution. .\" -.TH gd_alter_entry 3 "1 October 2013" "Version 0.9.0" "GETDATA" +.TH gd_alter_entry 3 "27 November 2013" "Version 0.9.0" "GETDATA" .SH NAME gd_alter_entry \(em modify the metadata of a dirfile field .SH SYNOPSIS @@ -146,10 +146,10 @@ .IR entry -> scalar_ind element should also be set. .IP \(bu 4 -a pointer the empty string (""). In this case, no change is made to the field -code for the corresponding field parameter: if one already existed, it is kept, -otherwise the corresponding literal numerical parameter is used. If the value -of the corresponding numerical +a pointer to the empty string (""). In this case, no change is made to the +field code for the corresponding field parameter: if one already existed, it is +kept, otherwise the corresponding literal numerical parameter is used. If the +value of the corresponding numerical .I entry member is the special value listed above indicating no change, no change is made to the field parameter at all. Modified: trunk/getdata/man/gd_entry.3 =================================================================== --- trunk/getdata/man/gd_entry.3 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/man/gd_entry.3 2013-12-07 01:48:34 UTC (rev 867) @@ -61,6 +61,9 @@ .BR gd_free_entry_strings (3) function is provided as a convenience to do this. +If the entry's metadata contains scalar field codes which cannot be dereferenced, +the associated numerical field parameter will be initialised to zero. + The returned .I entry structure, including strings and their pointers may be freely modified by the @@ -90,9 +93,6 @@ The representation suffix specified in .I field_code was not recognised. -.TP -.B GD_E_BAD_SCALAR -A scalar parameter used in the definition of the field was invalid. .PP The dirfile error may be retrieved by calling .BR gd_error (3). Modified: trunk/getdata/man/gd_free_entry_strings.3 =================================================================== --- trunk/getdata/man/gd_free_entry_strings.3 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/man/gd_free_entry_strings.3 2013-12-07 01:48:34 UTC (rev 867) @@ -1,6 +1,6 @@ .\" gd_free_entry_strings.3. The gd_free_entry_strings man page. .\" -.\" Copyright (C) 2008, 2010 D. V. Wiebe +.\" Copyright (C) 2008, 2010, 2013 D. V. Wiebe .\" .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .\" @@ -13,7 +13,7 @@ .\" Texts. A copy of the license is included in the `COPYING.DOC' file .\" as part of this distribution. .\" -.TH gd_free_entry_strings 3 "16 June 2010" "Version 0.7.0" "GETDATA" +.TH gd_free_entry_strings 3 "7 December 2013" "Version 0.9.0" "GETDATA" .SH NAME gd_free_entry_strings \(em free strings in a GetData gd_entry_t object .SH SYNOPSIS @@ -31,7 +31,7 @@ .I entry which were previously allocated by a call to .BR gd_entry (3). -If +After freeing a string, the associated pointer is set to NULL. If .I entry is NULL, this function does nothing. @@ -52,9 +52,9 @@ See .BR gd_entry (3) -for a complete description of the gd_entry_t data type. +for a description of the gd_entry_t data type. .SH RETURN VALUE -A call to +The function .BR gd_free_entry_strings () always returns its input, .IR entry . Modified: trunk/getdata/man/gd_move.3 =================================================================== --- trunk/getdata/man/gd_move.3 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/man/gd_move.3 2013-12-07 01:48:34 UTC (rev 867) @@ -1,6 +1,6 @@ .\" gd_move.3. The gd_move man page. .\" -.\" Copyright (C) 2008, 2009, 2010, 2012 D. V. Wiebe +.\" Copyright (C) 2008, 2009, 2010, 2012, 2013 D. V. Wiebe .\" .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .\" @@ -13,25 +13,22 @@ .\" Texts. A copy of the license is included in the `COPYING.DOC' file .\" as part of this distribution. .\" -.TH gd_move 3 "1 January 2012" "Version 0.8.0" "GETDATA" +.TH gd_move 3 "7 Decmeber 2013" "Version 0.9.0" "GETDATA" .SH NAME -gd_move, gd_move_alias \(em move a dirfile entry between format specification fragments +gd_move \(em move a dirfile entry between format specification fragments .SH SYNOPSIS .B #include <getdata.h> .HP .nh .ad l .BI "int gd_move(DIRFILE *" dirfile ", const char" -.BI * field_code ", int " new_fragment ", int " move_data ); -.HP -.BI "int gd_move_alias(DIRFILE *" dirfile ", const char" -.BI * alias_name ", int " new_fragment ); +.BI * field_code ", int " new_fragment ", unsigned int " flags ); .hy .ad n .SH DESCRIPTION The .BR gd_move () -function transfers the field specified by +function transfers the field or alias specified by .IR field_code , which should not have a representation suffix, defined in the dirfile specified by @@ -42,23 +39,26 @@ .IR new_fragment , this function does nothing. +If the new fragment has different affixes, the field will be renamed as part of +the move. See +.BR gd_rename (3) +for details on field renaming. + The -.BR gd_move_alias () -function behaves similarly, but moves the alias named -.I alias_name -to the new fragment. (Passing -.I alias_name -to -.BR gd_move () -as +.I flags +parameter should be zero or more of the following flags, bitwise or'd together: +.TP +.B GD_REN_DANGLE +By default, if the move results in a change of name for the field due to +differing fragment affixes, +.B ALIAS +entries pointing to this field will be updated with the field's new name. +Specifying this flag prohibits this behaviour, turning these aliases into +dangling aliases. If moving the field doesn't rename it, this flag is ignored. +.TP +.B GD_REN_DATA +If .I field_code -will result in the field ultimately pointed to be the alias being moved, and -not the alias itself.) - -If the flag -.I move_data -is one, and -.I field_code specifies a .B RAW field, the binary file associated with the field will be translated to account @@ -70,15 +70,25 @@ .I field_code specifies a field of type other than .BR RAW , -the -.I move_data -flag is ignored. +this flag is ignored. If the binary file is translated, and the frame offset of the destination fragment is larger than that of the source fragment, this will result in permanent deletion of data from the database. If the new frame offset is smaller than the old frame offset, the binary file will be padded at the front with zeroes. +.TP +.B GD_REN_FORCE +Skip updating entries which would be invalid (see +.BR gd_rename (3) +for details). By default, an invalid field causes the move to fail. If moving +the field doesn't rename it, this flag is ignored. +.TP +.B GD_REN_UPDB +If moving the field renames it, update entries which use this field as an input +to account for the new name (see +.BR gd_rename (3)). +If moving the field doesn't rename it, this flag is ignored. .SH RETURN VALUE On success, @@ -95,7 +105,9 @@ .B GD_E_BAD_CODE The field specified by .I field_code -was not found. +was not found, or else the move resulted in the field being renamed and +the resultant metadata update tried to change a field code into something +prohibited by a fragment's affixes. .TP .B GD_E_BAD_DIRFILE The supplied dirfile was invalid. Modified: trunk/getdata/man/gd_rename.3 =================================================================== --- trunk/getdata/man/gd_rename.3 2013-11-15 22:39:46 UTC (rev 866) +++ trunk/getdata/man/gd_rename.3 2013-12-07 01:48:34 UTC (rev 867) @@ -1,6 +1,6 @@ .\" gd_rename.3. The gd_rename man page. .\" -.\" Copyright (C) 2008, 2009, 2010, 2011, 2012 D. V. Wiebe +.\" Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013 D. V. Wiebe .\" .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .\" @@ -13,7 +13,7 @@ .\" Texts. A copy of the license is included in the `COPYING.DOC' file .\" as part of this distribution. .\" -.TH gd_rename 3 "27 June 2012" "Version 0.8.0" "GETDATA" +.TH gd_rename 3 "7 December 2013" "Version 0.9.0" "GETDATA" .SH NAME gd_rename \(em change the name of a dirfile field or alias .SH SYNOPSIS @@ -43,10 +43,29 @@ .I new_name should only contain the new name (without slash). +If +.I old_code +specifies a top-level field with meta subfields, the subfields will be renamed, +too. By default, this function also updates +.B ALIAS +entries whose target contains +.I old_code +to point to the new field. Similarly, specifying the +.B GD_REN_UPDB +flag will cause this function to modify any field entry containing +.IR old_code . +As a result, this function may cause more than one metadata fragment to be +modified. + The .I flags parameter should be zero or more of the following flags, bitwise or'd together: .TP +.B GD_REN_DANGLE +Don't update +.B ALIAS +entries, instead turning them into dangling aliases. +.TP .B GD_REN_DATA if .I old_code @@ -59,6 +78,16 @@ .BR RAW , this flag is ignored. .TP +.B GD_REN_FORCE +When updating field metadata (either the target of an alias, or else when +specified along with +.BR GD_REN_UPDB ), +skip updating field codes which would be invalid (due to +.B /INCLUDE +affixes). Without this flag, such invalid field codes causes this function to +fail with the error +.BR GD_E_BAD_CODE . +.TP .B GD_REN_UPDB Rename the field in any other field specifications which use this field as an input (either as a vector input field to a derived field, or else as a scalar @@ -80,7 +109,8 @@ .B GD_E_BAD_CODE The field specified by .I old_code -was not found. +was not found. Or else the resultant metadata update tried to change a +field code into something prohibited by a fragment's affixes. .TP .B GD_E_BAD_DIRFILE The supplied dirfile was invalid. @@ -94,9 +124,10 @@ The new name specified is already in use by another entry. .TP .B GD_E_PROTECTED -The metadata of the format specification fragment containing the entry was -protected from change, or the binary data of the fragments was protected from -change and a binary file move was requested. +The metadata of the format specification fragment containing the renamed entry, +or another entry affected by this change, was protected from change, or the +binary data of the fragment was protected from change and a binary file move +was requested. .TP .B GD_E_RAW_IO An I/O error occurred while attempting to rename the binary file. Modified: trunk/getdata/src/add.c =================================================================== --- trun... [truncated message content] |
From: <ket...@us...> - 2013-12-11 00:16:58
|
Revision: 868 http://sourceforge.net/p/getdata/code/868 Author: ketiltrout Date: 2013-12-11 00:16:49 +0000 (Wed, 11 Dec 2013) Log Message: ----------- Merge gd_entry_t members 'comp_scal' and 'hidden', plus private member 'calculated' into (public) member 'flags'. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/NEWS trunk/getdata/bindings/cxx/getdata/entry.h trunk/getdata/bindings/cxx/getdata/lincomentry.h trunk/getdata/bindings/cxx/getdata/polynomentry.h trunk/getdata/bindings/cxx/getdata/recipentry.h trunk/getdata/bindings/cxx/lincomentry.cpp trunk/getdata/bindings/cxx/polynomentry.cpp trunk/getdata/bindings/cxx/recipentry.cpp trunk/getdata/bindings/f77/fgetdata.c trunk/getdata/bindings/f77/fgetdata.h trunk/getdata/bindings/f77/getdata.f.in trunk/getdata/bindings/f77/getdata.f90.in trunk/getdata/bindings/f77/test/big_test.f trunk/getdata/bindings/f77/test/big_test95.f90 trunk/getdata/bindings/idl/getdata.c trunk/getdata/bindings/idl/test/big_test.pro trunk/getdata/bindings/make_parameters.c trunk/getdata/bindings/perl/GetData.xs trunk/getdata/bindings/php/getdata.c trunk/getdata/bindings/python/pyentry.c trunk/getdata/man/gd_add.3 trunk/getdata/man/gd_alter_entry.3 trunk/getdata/man/gd_entry.3 trunk/getdata/man/gd_hidden.3 trunk/getdata/man/gd_hide.3 trunk/getdata/src/add.c trunk/getdata/src/constant.c trunk/getdata/src/entry.c trunk/getdata/src/field_list.c trunk/getdata/src/flush.c trunk/getdata/src/getdata.c trunk/getdata/src/getdata.h.in trunk/getdata/src/include.c trunk/getdata/src/internal.h trunk/getdata/src/mod.c trunk/getdata/src/name.c trunk/getdata/src/native.c trunk/getdata/src/open.c trunk/getdata/src/parse.c trunk/getdata/src/putdata.c trunk/getdata/src/spf.c trunk/getdata/test/add_clincom.c trunk/getdata/test/add_cpolynom.c trunk/getdata/test/add_crecip.c trunk/getdata/test/add_crecip89.c trunk/getdata/test/add_lincom.c trunk/getdata/test/add_lincom_affix.c trunk/getdata/test/add_polynom.c trunk/getdata/test/add_polynom_scalar.c trunk/getdata/test/add_recip.c trunk/getdata/test/add_scalar.c trunk/getdata/test/add_scalar_carray.c trunk/getdata/test/add_scalar_carray_bad.c trunk/getdata/test/alter_clincom.c trunk/getdata/test/alter_cpolynom_null.c trunk/getdata/test/alter_crecip89_null.c trunk/getdata/test/alter_entry_hidden.c trunk/getdata/test/alter_entry_lincom.c trunk/getdata/test/alter_polynom_coeff.c trunk/getdata/test/alter_spec_polynom.c trunk/getdata/test/cvlist_array0.c trunk/getdata/test/cvlist_array_meta0.c trunk/getdata/test/cvlist_meta0.c trunk/getdata/test/del_alias.c trunk/getdata/test/del_ref.c trunk/getdata/test/endian_alter_all.c trunk/getdata/test/entry_lincom.c trunk/getdata/test/entry_polynom.c trunk/getdata/test/entry_polynom_scalar.c trunk/getdata/test/entry_recip.c trunk/getdata/test/flush_ref.c trunk/getdata/test/get_linterp1.c trunk/getdata/test/get_mplex_s.c trunk/getdata/test/get_neg.c trunk/getdata/test/get_uint32.c trunk/getdata/test/get_uint64.c trunk/getdata/test/gzip_del.c trunk/getdata/test/gzip_sync.c trunk/getdata/test/header_complex.c trunk/getdata/test/legacy_format.c trunk/getdata/test/madd_cpolynom.c trunk/getdata/test/madd_crecip.c trunk/getdata/test/madd_crecip89.c trunk/getdata/test/madd_lincom.c trunk/getdata/test/madd_polynom.c trunk/getdata/test/madd_recip.c trunk/getdata/test/name_name.c trunk/getdata/test/parse_hex.c trunk/getdata/test/seek_index.c trunk/getdata/test/sie_sync.c trunk/getdata/test/zzslim_get.c Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/ChangeLog 2013-12-11 00:16:49 UTC (rev 868) @@ -1,3 +1,24 @@ +2013-12-10 D. V. Wiebe <ge...@ke...> svn:868 + * src/getdata.h.in src/internal.h: Merge gd_entry_t members 'comp_scal' and + 'hidden', plus private member 'calculated' into (public) member 'flags', and + add GD_EN_CALC, GD_EN_COMPSCAL and GD_EN_HIDDEN flags. + * bindings/make_parameters.c: Add entry flags. + * bindings/cxx/getdata/entry.h (Entry::Flags) bindings/f77/fgetdata.c + (GDENFL): Added. + * bindings/f77/fgetdata.c (GDCSCL): Deleted. + * bindings/f77/getdata.f90.in: Replaced comp_scal with flags in gd_entry + type. + * bindings/idl/getdata.c: Replaced COMP_SCAL with FLAGS member in gd_entry + struct. + + * src/mod.c (_GD_Change): Allow hiddenness modification. + * test/alter_entry_hidden.c: Update test: hiddenness should change. + + * test/cvlist_meta0.c: Check error. + + * bindings/cxx/ getdata/entry.h (Entry::CompScal): Allow non-zero for + RECIP, too. + 2013-12-06 D. V. Wiebe <ge...@ke...> svn:867 * test/add_dot.c test/alter_clincom.c test/alter_const_r2c.c test/sie_sync.c test/alter_const_r2r.c test/alter_cpolynom_null.c test/alter_crecip89_null.c Modified: trunk/getdata/NEWS =================================================================== --- trunk/getdata/NEWS 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/NEWS 2013-12-11 00:16:49 UTC (rev 868) @@ -60,10 +60,20 @@ * gd_free_entry_strings() now NULLs pointers after freeing them. + * The comp_scal member of the gd_entry_t object has been replaced with a flags + member, containing a flag (GD_EN_COMPSCAL) with the meaning of the former + comp_scal member. There are also flags for hiddenness (GD_EN_HIDDEN) and + whether the scalar entries have been computed (GD_EN_CALC). + * gd_entry() now returns entry metadata when they contain scalar field codes - which do not exist. Previously, it would fail with the error - GD_E_BAD_SCALAR and return nothing. + which do not exist. In this case the GD_EN_CALC flag in the object will + not be set. Previously, on such entries, this function would fail with the + error GD_E_BAD_SCALAR and return nothing. + * gd_[m]add() and gd_alter_entry() can now be used to set or change the + hiddenness of a field by setting or clearing the GD_EN_HIDDEN bit in the + supplied gd_entry_t object. + * Two new rename flags have been added: - GD_REN_DANGLE which indicates the library shouldn't update ALIASes whose target has been renamed (turning them into dangling aliases) @@ -156,6 +166,10 @@ * C++ BUG FIX: Fixed segfault in RawEntry destructor. Reported by S. J. Benton. + * C++ BUG FIX: Entry::ComplexScalars() now returns non-zero for RECIP + entries when appropriate, instead of always returning zero. (The + RecipEntry::ComplexScalars() method always returned the correct value.) + * F77 and F95 BUG FIX: Named scalar indices are now indexed from one instead of zero, like all other array indices are in the Fortran GetData bindings. Modified: trunk/getdata/bindings/cxx/getdata/entry.h =================================================================== --- trunk/getdata/bindings/cxx/getdata/entry.h 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/cxx/getdata/entry.h 2013-12-11 00:16:49 UTC (rev 868) @@ -100,10 +100,17 @@ }; virtual int ComplexScalars() const { - return (E.field_type == GD_LINCOM_ENTRY || - E.field_type == GD_POLYNOM_ENTRY) ? E.comp_scal : 0; + if (E.field_type == GD_LINCOM_ENTRY || + E.field_type == GD_POLYNOM_ENTRY || + E.field_type == GD_RECIP_ENTRY) + if (E.flags & GD_EN_COMPSCAL) + return 1; + + return 0; } + unsigned int Flags() const { return E.flags; }; + virtual const char *Scalar(int index = 0) const; virtual int ScalarIndex(int index = 0) const; Modified: trunk/getdata/bindings/cxx/getdata/lincomentry.h =================================================================== --- trunk/getdata/bindings/cxx/getdata/lincomentry.h 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/cxx/getdata/lincomentry.h 2013-12-11 00:16:49 UTC (rev 868) @@ -46,7 +46,9 @@ E.in_fields[index] : NULL; }; - virtual int ComplexScalars() const { return E.comp_scal; } + virtual int ComplexScalars() const { + return (E.flags & GD_EN_COMPSCAL) ? 1 : 0; + } virtual int NFields() const { return E.u.lincom.n_fields; }; Modified: trunk/getdata/bindings/cxx/getdata/polynomentry.h =================================================================== --- trunk/getdata/bindings/cxx/getdata/polynomentry.h 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/cxx/getdata/polynomentry.h 2013-12-11 00:16:49 UTC (rev 868) @@ -42,7 +42,9 @@ virtual const char *Input() const { return E.in_fields[0]; }; - virtual int ComplexScalars() const { return E.comp_scal; } + virtual int ComplexScalars() const { + return (E.flags & GD_EN_COMPSCAL) ? 1 : 0; + } virtual int PolyOrd() const { return E.u.polynom.poly_ord; }; Modified: trunk/getdata/bindings/cxx/getdata/recipentry.h =================================================================== --- trunk/getdata/bindings/cxx/getdata/recipentry.h 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/cxx/getdata/recipentry.h 2013-12-11 00:16:49 UTC (rev 868) @@ -46,7 +46,9 @@ virtual int ScalarIndex() const { return E.scalar_ind[0]; }; - virtual int ComplexScalars() const { return E.comp_scal; } + virtual int ComplexScalars() const { + return (E.flags & GD_EN_COMPSCAL) ? 1 : 0; + } virtual double Dividend() const { return E.u.recip.dividend; }; Modified: trunk/getdata/bindings/cxx/lincomentry.cpp =================================================================== --- trunk/getdata/bindings/cxx/lincomentry.cpp 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/cxx/lincomentry.cpp 2013-12-11 00:16:49 UTC (rev 868) @@ -32,7 +32,7 @@ E.field_type = GD_LINCOM_ENTRY; E.u.lincom.n_fields = n_fields; E.fragment_index = fragment_index; - E.comp_scal = 0; + E.flags = 0; for (i = 0; i < n_fields; ++i) { E.in_fields[i] = strdup(in_fields[i]); E.u.lincom.m[i] = m[i]; @@ -50,7 +50,7 @@ E.field_type = GD_LINCOM_ENTRY; E.u.lincom.n_fields = n_fields; E.fragment_index = fragment_index; - E.comp_scal = 1; + E.flags = GD_EN_COMPSCAL; for (i = 0; i < n_fields; ++i) { E.in_fields[i] = strdup(in_fields[i]); E.u.lincom.cm[i][0] = cm[i].real(); @@ -121,7 +121,7 @@ E.u.lincom.m[index] = E.u.lincom.cm[index][0] = scale.real(); E.u.lincom.cm[index][1] = scale.imag(); - E.comp_scal = 1; + E.flags = GD_EN_COMPSCAL; if (D != NULL) return gd_alter_entry(D->D, E.field, &E, 0); @@ -171,7 +171,7 @@ E.u.lincom.b[index] = E.u.lincom.cb[index][0] = offset.real(); E.u.lincom.cb[index][1] = offset.imag(); - E.comp_scal = 1; + E.flags = GD_EN_COMPSCAL; if (D != NULL) return gd_alter_entry(D->D, E.field, &E, 0); Modified: trunk/getdata/bindings/cxx/polynomentry.cpp =================================================================== --- trunk/getdata/bindings/cxx/polynomentry.cpp 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/cxx/polynomentry.cpp 2013-12-11 00:16:49 UTC (rev 868) @@ -31,7 +31,7 @@ E.field_type = GD_POLYNOM_ENTRY; E.u.polynom.poly_ord = poly_ord; E.fragment_index = fragment_index; - E.comp_scal = 0; + E.flags = 0; E.in_fields[0] = strdup(in_field); for (i = 0; i <= poly_ord; ++i) E.u.polynom.a[i] = a[i]; @@ -47,7 +47,7 @@ E.field_type = GD_POLYNOM_ENTRY; E.u.polynom.poly_ord = poly_ord; E.fragment_index = fragment_index; - E.comp_scal = 1; + E.flags = GD_EN_COMPSCAL; E.in_fields[0] = strdup(in_field); for (i = 0; i <= poly_ord; ++i) { E.u.polynom.ca[i][0] = ca[i].real(); @@ -113,7 +113,7 @@ E.u.polynom.a[index] = E.u.polynom.ca[index][0] = coeff.real(); E.u.polynom.ca[index][1] = coeff.imag(); - E.comp_scal = 1; + E.flags = GD_EN_COMPSCAL; if (D != NULL) return gd_alter_entry(D->D, E.field, &E, 0); Modified: trunk/getdata/bindings/cxx/recipentry.cpp =================================================================== --- trunk/getdata/bindings/cxx/recipentry.cpp 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/cxx/recipentry.cpp 2013-12-11 00:16:49 UTC (rev 868) @@ -31,7 +31,7 @@ E.scalar[0] = 0; E.u.recip.cdividend[0] = E.u.recip.dividend = dividend; E.u.recip.cdividend[1] = 0; - E.comp_scal = 0; + E.flags = 0; E.fragment_index = fragment_index; } @@ -44,7 +44,7 @@ E.scalar[0] = 0; E.u.recip.cdividend[0] = E.u.recip.dividend = dividend.real(); E.u.recip.cdividend[1] = dividend.imag(); - E.comp_scal = 1; + E.flags = GD_EN_COMPSCAL; E.fragment_index = fragment_index; } @@ -97,7 +97,7 @@ { E.u.recip.dividend = E.u.recip.cdividend[0] = dividend.real(); E.u.recip.cdividend[1] = dividend.imag(); - E.comp_scal = 1; + E.flags = GD_EN_COMPSCAL; if (D != NULL) return gd_alter_entry(D->D, E.field, &E, 0); Modified: trunk/getdata/bindings/f77/fgetdata.c =================================================================== --- trunk/getdata/bindings/f77/fgetdata.c 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/f77/fgetdata.c 2013-12-11 00:16:49 UTC (rev 868) @@ -2979,30 +2979,27 @@ dreturn("%i", *type); } -/* returns the value of the comp_scal member */ -void F77_FUNC(gdcscl, GDCSCL) (int32_t *comp_scal, const int32_t *dirfile, +/* returns the entry flags */ +void F77_FUNC(gdenfl, GDENFL) (int32_t *flags, const int32_t *dirfile, const char *field_code, const int32_t *field_code_l) { char *fc; gd_entry_t E; DIRFILE *D; - dtrace("%p, %i, %p, %i", comp_scal, *dirfile, field_code, *field_code_l); + dtrace("%p, %i, %p, %i", flags, *dirfile, field_code, *field_code_l); D = _GDF_GetDirfile(*dirfile); - *comp_scal = 0; + if (gd_entry(D, _GDF_CString(&fc, field_code, *field_code_l), &E) == 0) { + *flags = E.flags; - gd_entry(D, _GDF_CString(&fc, field_code, *field_code_l), &E); - - if (!gd_error(D) && (E.field_type == GD_LINCOM_ENTRY || - E.field_type == GD_POLYNOM_ENTRY || E.field_type == GD_RECIP_ENTRY)) - *comp_scal = E.comp_scal; - - gd_free_entry_strings(&E); + gd_free_entry_strings(&E); + } else + *flags = -1; free(fc); - dreturn("%i", *comp_scal); + dreturn("%i", *flags); } /* gd_validate wrapper */ @@ -4075,7 +4072,6 @@ E.fragment_index = *fragment_index; n = E.EN(lincom,n_fields) = *n_fields; _GDF_CString(&E.field, field_code, *field_code_l); - E.comp_scal = 0; _GDF_CString(E.in_fields + 0, in_field1, *in_field1_l); _GDF_CString(E.scalar + 0, m1_scalar, *m1_scalar_l); @@ -4155,7 +4151,7 @@ E.fragment_index = *fragment_index; n = E.EN(lincom,n_fields) = *n_fields; _GDF_CString(&E.field, field_code, *field_code_l); - E.comp_scal = 1; + E.flags = GD_EN_COMPSCAL; _GDF_CString(E.in_fields + 0, in_field1, *in_field1_l); _GDF_CString(E.scalar + 0, m1_scalar, *m1_scalar_l); @@ -4231,7 +4227,6 @@ _GDF_CString(&E.in_fields[0], in_field, *in_field_l); E.fragment_index = *fragment_index; n = E.EN(polynom,poly_ord) = *poly_ord; - E.comp_scal = 0; if (n > 5) n = 5; @@ -4311,7 +4306,7 @@ _GDF_CString(&E.in_fields[0], in_field, *in_field_l); E.fragment_index = *fragment_index; n = E.EN(polynom,poly_ord) = *poly_ord; - E.comp_scal = 1; + E.flags = GD_EN_COMPSCAL; if (n > 5) n = 5; @@ -4585,7 +4580,6 @@ E.field_type = GD_POLYNOM_ENTRY; _GDF_CString(&E.in_fields[0], in_field, *in_field_l); n = E.EN(polynom,poly_ord) = *poly_ord; - E.comp_scal = 0; if (n > 5) n = 5; @@ -4664,7 +4658,7 @@ E.field_type = GD_POLYNOM_ENTRY; _GDF_CString(&E.in_fields[0], in_field, *in_field_l); n = E.EN(polynom,poly_ord) = *poly_ord; - E.comp_scal = 1; + E.flags = GD_EN_COMPSCAL; if (n > 5) n = 5; @@ -4936,7 +4930,6 @@ memset(&E, 0, sizeof(E)); E.field_type = GD_LINCOM_ENTRY; n = E.EN(lincom,n_fields) = *n_fields; - E.comp_scal = 0; _GDF_CString(E.in_fields + 0, in_field1, *in_field1_l); _GDF_CString(E.scalar + 0, m1_scalar, *m1_scalar_l); @@ -5015,7 +5008,7 @@ memset(&E, 0, sizeof(E)); E.field_type = GD_LINCOM_ENTRY; n = E.EN(lincom,n_fields) = *n_fields; - E.comp_scal = 1; + E.flags = GD_EN_COMPSCAL; _GDF_CString(E.in_fields + 0, in_field1, *in_field1_l); _GDF_CString(E.scalar + 0, m1_scalar, *m1_scalar_l); @@ -5106,7 +5099,7 @@ memset(&E, 0, sizeof(E)); E.field_type = GD_RECIP_ENTRY; - E.comp_scal = 1; + E.flags = GD_EN_COMPSCAL; _GDF_CString(&E.in_fields[0], in_field, *in_field_l); gd_li2cs_(E.EN(recip,cdividend), dividend[0], dividend[1]); _GDF_CString(E.scalar + 0, dividend_scalar, *dividend_scalar_l); Modified: trunk/getdata/bindings/f77/fgetdata.h =================================================================== --- trunk/getdata/bindings/f77/fgetdata.h 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/f77/fgetdata.h 2013-12-11 00:16:49 UTC (rev 868) @@ -470,7 +470,7 @@ const GD_DCOMPLEXP(a2), const GD_DCOMPLEXP(a3), const GD_DCOMPLEXP(a4), const GD_DCOMPLEXP(a5)); -void F77_FUNC(gdcscl, GDCSCL) (int32_t *comp_scal, const int32_t *dirfile, +void F77_FUNC(gdenfl, GDENFL) (int32_t *flags, const int32_t *dirfile, const char *field_code, const int32_t *field_code_l); void F77_FUNC(gdvldt, GDVLDT) (int32_t *valid, const int32_t *dirfile, Modified: trunk/getdata/bindings/f77/getdata.f.in =================================================================== --- trunk/getdata/bindings/f77/getdata.f.in 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/f77/getdata.f.in 2013-12-11 00:16:49 UTC (rev 868) @@ -153,8 +153,6 @@ EXTERNAL GDCONS C Corresponding to gd_copen(3) EXTERNAL GDCOPN -C Check whether an entry contains complex scalars - EXTERNAL GDCSCL C Correpsonding to gd_delete_alias(3) EXTERNAL GDDELA C Correpsonding to gd_delete(3) @@ -165,6 +163,8 @@ EXTERNAL GDDSYN C Corresponding to gd_error_count(3) EXTERNAL GDECNT +C Returns entry flags + EXTERNAL GDENFL C Corresponding to gd_entry_list(3) (sort of) EXTERNAL GDENTN C Returns the maximum entry name length Modified: trunk/getdata/bindings/f77/getdata.f90.in =================================================================== --- trunk/getdata/bindings/f77/getdata.f90.in 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/f77/getdata.f90.in 2013-12-11 00:16:49 UTC (rev 868) @@ -29,7 +29,7 @@ type gd_entry integer :: field_type, n_fields, spf, data_type, bitnum, numbits, shift - integer :: fragment_index, comp_scal, poly_ord, array_len, windop, ithreshold + integer :: fragment_index, flags, poly_ord, array_len, windop, ithreshold integer :: count_val, period character (len=GD_FIELD_LEN), dimension(3) :: field character (len=GD_FIELD_LEN), dimension(6) :: scalar @@ -801,6 +801,9 @@ ! get field type from f77 library call gdenty(fgd_entry, dirfile, TRIM(field_code), LEN_TRIM(field_code)) + ! flags + call gdenfl(ent%flags, dirfile, TRIM(field_code), LEN_TRIM(field_code)) + if (fgd_entry .EQ. GD_RAW_ENTRY) then ! raw call gdgerw(ent%spf, ent%data_type, ent%fragment_index, dirfile, & @@ -809,8 +812,7 @@ TRIM(field_code), LEN_TRIM(field_code), 1) else if (fgd_entry .EQ. GD_LINCOM_ENTRY) then ! lincom - call gdcscl(ent%comp_scal, dirfile, TRIM(field_code), LEN_TRIM(field_code)) - if (ent%comp_scal .NE. 0) then + if (IAND(GD_EN_COMPSCAL, ent%flags) .NE. 0) then call gdgecl(ent%n_fields, ent%field(1), len1, ent%cm(1), ent%cb(1), & ent%field(2), len2, ent%cm(2), ent%cb(2), ent%field(3), len3, ent%cm(3), & ent%cb(3), ent%fragment_index, dirfile, TRIM(field_code), & @@ -866,8 +868,7 @@ TRIM(field_code), LEN_TRIM(field_code), 1) else if (fgd_entry .EQ. GD_POLYNOM_ENTRY) then ! polynom - call gdcscl(ent%comp_scal, dirfile, TRIM(field_code), LEN_TRIM(field_code)) - if (ent%comp_scal .NE. 0) then + if (IAND(GD_EN_COMPSCAL, ent%flags) .NE. 0) then call gdgecp(ent%poly_ord, ent%field(1), len1, ent%ca(1), ent%ca(2), & ent%ca(3), ent%ca(4), ent%ca(5), ent%ca(6), ent%fragment_index, dirfile, & TRIM(field_code), LEN_TRIM(field_code)) @@ -883,8 +884,7 @@ end do else if (fgd_entry .EQ. GD_RECIP_ENTRY) then ! recip - call gdcscl(ent%comp_scal, dirfile, TRIM(field_code), LEN_TRIM(field_code)) - if (ent%comp_scal .NE. 0) then + if (IAND(GD_EN_COMPSCAL, ent%flags) .NE. 0) then call gdgecr(ent%field(1), len1, ent%cdividend, ent%fragment_index, & dirfile, TRIM(field_code), LEN_TRIM(field_code)) else @@ -965,7 +965,7 @@ ent%data_type, ent%spf, TRIM(ent%scalar(1)), LEN_TRIM(ent%scalar(1)), & ent%scalar_ind(1), ent%fragment_index) else if (ent%field_type .EQ. GD_LINCOM_ENTRY) then - if (ent%comp_scal .EQ. 0) then + if (IAND(GD_EN_COMPSCAL, ent%flags) .EQ. 0) then call gdaslc(dirfile, TRIM(field_code), LEN_TRIM(field_code), & ent%n_fields, TRIM(ent%field(1)), LEN_TRIM(ent%field(1)), ent%m(1), & TRIM(ent%scalar(1)), LEN_TRIM(ent%scalar(1)), ent%scalar_ind(1), & @@ -1021,7 +1021,7 @@ TRIM(ent%scalar(1)), LEN_TRIM(ent%scalar(1)), ent%scalar_ind(1), & ent%fragment_index) else if (ent%field_type .EQ. GD_POLYNOM_ENTRY) then - if (ent%comp_scal .EQ. 0) then + if (IAND(GD_EN_COMPSCAL, ent%flags) .EQ. 0) then call gdaspn(dirfile, TRIM(field_code), LEN_TRIM(field_code), & ent%poly_ord, TRIM(ent%field(1)), LEN_TRIM(ent%field(1)), ent%a(1), & TRIM(ent%scalar(1)), LEN_TRIM(ent%scalar(1)), ent%scalar_ind(1), & @@ -1045,7 +1045,7 @@ LEN_TRIM(ent%scalar(6)), ent%scalar_ind(6), ent%fragment_index) end if else if (ent%field_type .EQ. GD_RECIP_ENTRY) then - if (ent%comp_scal .EQ. 0) then + if (IAND(GD_EN_COMPSCAL, ent%flags) .EQ. 0) then call gdasrc(dirfile, TRIM(field_code), LEN_TRIM(field_code), & TRIM(ent%field(1)), LEN_TRIM(ent%field(1)), ent%dividend, & TRIM(ent%scalar(1)), LEN_TRIM(ent%scalar(1)), ent%scalar_ind(1), & @@ -1247,7 +1247,7 @@ character (len=1) :: nil = "" if (ent%field_type .EQ. GD_LINCOM_ENTRY) then - if (ent%comp_scal .NE. 0) then + if (IAND(GD_EN_COMPSCAL, ent%flags) .NE. 0) then call gdmdcl(dirfile, TRIM(parent), LEN_TRIM(parent), TRIM(field_code), & LEN_TRIM(field_code), ent%n_fields, TRIM(ent%field(1)), & LEN_TRIM(ent%field(1)), ent%cm(1), ent%cb(1), TRIM(ent%field(2)), & @@ -1281,7 +1281,7 @@ LEN_TRIM(field_code), TRIM(ent%field(1)), LEN_TRIM(ent%field(1)), & TRIM(ent%field(2)), LEN_TRIM(ent%field(2))) else if (ent%field_type .EQ. GD_POLYNOM_ENTRY) then - if (ent%comp_scal .NE. 0) then + if (IAND(GD_EN_COMPSCAL, ent%flags) .NE. 0) then call gdmdcp(dirfile, TRIM(parent), LEN_TRIM(parent), TRIM(field_code), & LEN_TRIM(field_code), ent%poly_ord, TRIM(ent%field(1)), & LEN_TRIM(ent%field(1)), ent%ca(1), ent%ca(2), ent%ca(3), ent%ca(4), & @@ -1293,7 +1293,7 @@ ent%a(5), ent%a(6)) end if else if (ent%field_type .EQ. GD_RECIP_ENTRY) then - if (ent%comp_scal .NE. 0) then + if (IAND(GD_EN_COMPSCAL, ent%flags) .NE. 0) then call gdmdcr(dirfile, TRIM(parent), LEN_TRIM(parent), TRIM(field_code), & LEN_TRIM(field_code), TRIM(ent%field(1)), LEN_TRIM(ent%field(1)), & ent%cdividend) @@ -1694,7 +1694,7 @@ call fgd__set_scalar_len(scalar_len, remove_scalars, lincom_mask(n), ent) call fgd__set_field_len(field_len, n, ent) - if (ent%comp_scal .NE. 0) then + if (IAND(GD_EN_COMPSCAL, ent%flags) .NE. 0) then call gdlscl(dirfile, TRIM(field_code), LEN_TRIM(field_code), & ent%n_fields, TRIM(ent%field(1)), field_len(1), & ent%cm(1), TRIM(ent%scalar(1)), scalar_len(1), ent%scalar_ind(1), & @@ -1763,7 +1763,7 @@ call fgd__set_scalar_len(scalar_len, remove_scalars, polynom_mask(n), ent) call fgd__set_field_len(field_len, 1, ent) - if (ent%comp_scal .NE. 0) then + if (IAND(GD_EN_COMPSCAL, ent%flags) .NE. 0) then call gdlscp(dirfile, TRIM(field_code), LEN_TRIM(field_code), & ent%poly_ord, TRIM(ent%field(1)), field_len(1), & ent%ca(1), TRIM(ent%scalar(1)), scalar_len(1), ent%scalar_ind(1), & @@ -1786,7 +1786,7 @@ call fgd__set_scalar_len(scalar_len, remove_scalars, 1, ent) call fgd__set_field_len(field_len, 1, ent) - if (ent%comp_scal .NE. 0) then + if (IAND(GD_EN_COMPSCAL, ent%flags) .NE. 0) then call gdlscr(dirfile, TRIM(field_code), LEN_TRIM(field_code), & TRIM(ent%field(1)), field_len(1), ent%cdividend, TRIM(ent%scalar(1)), & scalar_len(1), ent%scalar_ind(1)) Modified: trunk/getdata/bindings/f77/test/big_test.f =================================================================== --- trunk/getdata/bindings/f77/test/big_test.f 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/f77/test/big_test.f 2013-12-11 00:16:49 UTC (rev 868) @@ -1403,10 +1403,10 @@ CALL CHKEOK(ne, 129, d) CALL CHKINT(ne, 129, n, GD_I8) -C 130: GDCSCL check - CALL GDCSCL(n, d, 'polynom', 7) +C 130: GDENFL check + CALL GDENFL(n, d, 'polynom', 7) CALL CHKEOK(ne, 130, d) - CALL CHKINT(ne, 130, n, 1) + CALL CHKINT(ne, 130, n, GDE_CS + GDE_CA) C 131: GDVLDT check CALL GDVLDT(n, d, 'new7', 4) @@ -2181,9 +2181,9 @@ +'in3', 3, 1.4d0, '', -1, -1, 0d0, 'carray', 6, 5, 0) CALL CHKOK2(ne, 243, 1, d) - CALL GDCSCL(n, d, 'new243', 6) + CALL GDENFL(n, d, 'new243', 6) CALL CHKOK2(ne, 243, 2, d) - CALL CHKIN2(ne, 243, 3, n, 0) + CALL CHKIN2(ne, 243, 3, n, GDE_CA) l = flen CALL GDGELC(i, fields(1), l, p(1), p(2), fields(2), l, p(3), @@ -2246,9 +2246,9 @@ +0d0, '', -1, -1, 0d0, '', -1, -1, 0) CALL CHKOK2(ne, 244, 1, d) - CALL GDCSCL(n, d, 'new244', 6) + CALL GDENFL(n, d, 'new244', 6) CALL CHKOK2(ne, 244, 2, d) - CALL CHKIN2(ne, 244, 3, n, 0) + CALL CHKIN2(ne, 244, 3, n, GDE_CA) l = flen CALL GDGEPN(i, fn, l, p(1), p(2), p(3), p(4), p(5), p(6), @@ -2336,9 +2336,9 @@ CALL GDASRC(d, 'new251', 6, 'in1', 3, 0d0, 'carray', 6, 4, 0) CALL CHKOK2(ne, 251, 1, d) - CALL GDCSCL(n, d, 'new251', 6) + CALL GDENFL(n, d, 'new251', 6) CALL CHKOK2(ne, 251, 2, d) - CALL CHKIN2(ne, 251, 3, n, 0) + CALL CHKIN2(ne, 251, 3, n, GDE_CA) l = flen CALL GDGERC(fn, l, dp, n, d, 'new251', 6) @@ -2415,9 +2415,9 @@ +'carray', 6, 5, 0) CALL CHKOK2(ne, 255, 1, d) - CALL GDCSCL(n, d, 'new255', 6) + CALL GDENFL(n, d, 'new255', 6) CALL CHKOK2(ne, 255, 2, d) - CALL CHKIN2(ne, 255, 3, n, 1) + CALL CHKIN2(ne, 255, 3, n, GDE_CS + GDE_CA) l = flen CALL GDGECL(i, fields(1), l, cp(1), cp(2), fields(2), l, cp(3), @@ -2481,9 +2481,9 @@ +dcmplx(0, 0), '', -1, -1, 0) CALL CHKOK2(ne, 256, 1, d) - CALL GDCSCL(n, d, 'new256', 6) + CALL GDENFL(n, d, 'new256', 6) CALL CHKOK2(ne, 256, 2, d) - CALL CHKIN2(ne, 256, 3, n, 1) + CALL CHKIN2(ne, 256, 3, n, GDE_CS + GDE_CA) l = flen CALL GDGECP(i, fn, l, cp(1), cp(2), cp(3), cp(4), cp(5), cp(6), @@ -2528,9 +2528,9 @@ CALL GDASCR(d, 'new257', 6, 'in1', 3, 0d0, 'carray', 6, 4, 0) CALL CHKOK2(ne, 257, 1, d) - CALL GDCSCL(n, d, 'new257', 6) + CALL GDENFL(n, d, 'new257', 6) CALL CHKOK2(ne, 257, 2, d) - CALL CHKIN2(ne, 257, 3, n, 0) + CALL CHKIN2(ne, 257, 3, n, GDE_CA) l = flen CALL GDGECR(fn, l, dc, n, d, 'new257', 6) @@ -2578,9 +2578,9 @@ +'', -1, 0d0, 'const', 5, -1, 0d0, 'const', 5, -1) CALL CHKOK2(ne, 259, 1, d) - CALL GDCSCL(n, d, 'new243', 6) + CALL GDENFL(n, d, 'new243', 6) CALL CHKOK2(ne, 259, 2, d) - CALL CHKIN2(ne, 259, 3, n, 0) + CALL CHKIN2(ne, 259, 3, n, GDE_CA) l = flen CALL GDGELC(i, fields(1), l, p(1), p(2), fields(2), l, p(3), @@ -2644,9 +2644,9 @@ +'', -1, dcmplx(0, 0), '', 0, -1, dcmplx(0, 0), '', 0, -1) CALL CHKOK2(ne, 260, 1, d) - CALL GDCSCL(n, d, 'new243', 6) + CALL GDENFL(n, d, 'new243', 6) CALL CHKOK2(ne, 260, 2, d) - CALL CHKIN2(ne, 260, 3, n, 1) + CALL CHKIN2(ne, 260, 3, n, GDE_CS + GDE_CA) l = flen CALL GDGECL(i, fields(1), l, cp(1), cp(2), fields(2), l, cp(3), @@ -2709,9 +2709,9 @@ +0d0, '', -1, 0, 0d0, '', -1, 0) CALL CHKOK2(ne, 261, 1, d) - CALL GDCSCL(n, d, 'new244', 6) + CALL GDENFL(n, d, 'new244', 6) CALL CHKOK2(ne, 261, 2, d) - CALL CHKIN2(ne, 261, 3, n, 0) + CALL CHKIN2(ne, 261, 3, n, GDE_CA) l = flen CALL GDGEPN(i, fn, l, p(1), p(2), p(3), p(4), p(5), p(6), @@ -2759,9 +2759,9 @@ +dcmplx(0d0, 0d0), '', -1, 0, dcmplx(0d0, 0d0), '', -1, 0) CALL CHKOK2(ne, 262, 1, d) - CALL GDCSCL(n, d, 'new244', 6) + CALL GDENFL(n, d, 'new244', 6) CALL CHKOK2(ne, 262, 2, d) - CALL CHKIN2(ne, 262, 3, n, 0) + CALL CHKIN2(ne, 262, 3, n, GDE_CA) l = flen CALL GDGECP(i, fn, l, cp(1), cp(2), cp(3), cp(4), cp(5), cp(6), @@ -2874,9 +2874,9 @@ CALL GDLSRC(d, 'new251', 6, 'in5', 3, 0d0, 'carray', 6, 2) CALL CHKOK2(ne, 266, 1, d) - CALL GDCSCL(n, d, 'new251', 6) + CALL GDENFL(n, d, 'new251', 6) CALL CHKOK2(ne, 266, 2, d) - CALL CHKIN2(ne, 266, 3, n, 0) + CALL CHKIN2(ne, 266, 3, n, GDE_CA) l = flen CALL GDGERC(fn, l, dp, n, d, 'new251', 6) @@ -2897,9 +2897,9 @@ +-1) CALL CHKOK2(ne, 267, 1, d) - CALL GDCSCL(n, d, 'new251', 6) + CALL GDENFL(n, d, 'new251', 6) CALL CHKOK2(ne, 267, 2, d) - CALL CHKIN2(ne, 267, 3, n, 1) + CALL CHKIN2(ne, 267, 3, n, GDE_CS + GDE_CA) l = flen CALL GDGECR(fn, l, dc, n, d, 'new251', 6) Modified: trunk/getdata/bindings/f77/test/big_test95.f90 =================================================================== --- trunk/getdata/bindings/f77/test/big_test95.f90 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/f77/test/big_test95.f90 2013-12-11 00:16:49 UTC (rev 868) @@ -589,7 +589,7 @@ call check_str2(ne, 42, 4, ent%field(1), 'data') call check_str2(ne, 42, 5 , ent%field(2), 'INDEX') call check_str2(ne, 42, 6, ent%field(3), 'linterp') - call check_int2(ne, 42, 7, ent%comp_scal, 1) + call check_int2(ne, 42, 7, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) call check_str2(ne, 42, 8, ent%scalar(1), '') call check_str2(ne, 42, 9, ent%scalar(2), '') call check_str2(ne, 42, 10, ent%scalar(3), 'const') @@ -709,7 +709,7 @@ call check_int2(ne, 54, 5, ent%fragment_index, 0) call check_str2(ne, 54, 6, ent%field(1), 'in1') call check_str2(ne, 54, 7, ent%field(2), 'in2') - call check_int2(ne, 54, 8, ent%comp_scal, 0) + call check_int2(ne, 54, 8, ent%flags, GD_EN_CALC) q = (/ 9.9d0, 8.8d0, 7.7d0, 6.6d0, 5.5d0, 5.5d0 /) do i=1,2 @@ -733,7 +733,7 @@ call check_int2(ne, 55, 5, ent%fragment_index, 0) call check_str2(ne, 55, 6, ent%field(1), 'in1') call check_str2(ne, 55, 7, ent%field(2), 'in2') - call check_int2(ne, 55, 8, ent%comp_scal, 1) + call check_int2(ne, 55, 8, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) cq(1) = dcmplx(1.1, 1.2) cq(2) = dcmplx(1.3, 1.4) @@ -755,7 +755,7 @@ call check_int2(ne, 56, 2, ent%poly_ord, 3) call check_int2(ne, 56, 3, ent%fragment_index, 0) call check_str2(ne, 56, 4, ent%field(1), 'in1') - call check_int2(ne, 56, 5, ent%comp_scal, 0) + call check_int2(ne, 56, 5, ent%flags, GD_EN_CALC) q = (/ 3d3, 4d4, 5d5, 6d6, 5.5d0, 5.5d0 /) DO i=1,4 @@ -777,7 +777,7 @@ call check_int2(ne, 57, 2, ent%poly_ord, 3) call check_int2(ne, 57, 3, ent%fragment_index, 0) call check_str2(ne, 57, 4, ent%field(1), 'in1') - call check_int2(ne, 57, 5, ent%comp_scal, 1) + call check_int2(ne, 57, 5, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) cq(1) = dcmplx(3.1, 7.0) cq(2) = dcmplx(4.2, 8.0) @@ -927,7 +927,7 @@ call check_int2(ne, 71, 5, ent%fragment_index, 0) call check_str2(ne, 71, 6, ent%field(1), 'in1') call check_str2(ne, 71, 7, ent%field(2), 'in2') - call check_int2(ne, 71, 8, ent%comp_scal, 0) + call check_int2(ne, 71, 8, ent%flags, GD_EN_CALC) q = (/ 9.9d0, 8.8d0, 7.7d0, 6.6d0, 5.5d0, 5.5d0 /) DO i=1,2 @@ -951,7 +951,7 @@ call check_int2(ne, 72, 3, ent%fragment_index, 0) call check_str2(ne, 72, 4, ent%field(1), 'in1') call check_str2(ne, 72, 5, ent%field(2), 'in2') - call check_int2(ne, 72, 6, ent%comp_scal, 1) + call check_int2(ne, 72, 6, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) cq(1) = dcmplx(1.1, 1.2) cq(2) = dcmplx(1.3, 1.4) @@ -1255,7 +1255,7 @@ call check_str2(ne, 100, 6, ent%field(1), 'in4') call check_str2(ne, 100, 7, ent%field(2), 'in5') call check_str2(ne, 100, 8, ent%field(3), 'in6') - call check_int2(ne, 100, 5, ent%comp_scal, 0) + call check_int2(ne, 100, 5, ent%flags, GD_EN_CALC) q = (/ 9.9d-1, 7.8d0, 1.1d1, 2.2d-2, 1.96d0, 0d0 /) DO i=1,3 @@ -1279,7 +1279,7 @@ call check_int2(ne, 101, 3, ent%fragment_index, 0) call check_str2(ne, 101, 4, ent%field(1), 'in4') call check_str2(ne, 101, 5, ent%field(2), 'in3') - call check_int2(ne, 101, 6, ent%comp_scal, 1) + call check_int2(ne, 101, 6, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) cq(1) = dcmplx(0.1, 0.2) cq(2) = dcmplx(0.3, 0.4) @@ -1321,7 +1321,7 @@ call check_int2(ne, 103, 2, ent%poly_ord, 3) call check_int2(ne, 103, 3, ent%fragment_index, 0) call check_str2(ne, 103, 4, ent%field(1), 'in1') - call check_int2(ne, 103, 5, ent%comp_scal, 1) + call check_int2(ne, 103, 5, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) cq(1) = dcmplx(1.1, 5.0) cq(2) = dcmplx(1.2, 4.0) @@ -1562,7 +1562,7 @@ ! 135: fgd_add raw ent%data_type = GD_FLOAT32 ent%fragment_index = 0 - ent%spf = 0; + ent%spf = 0 ent%field_type = GD_RAW_ENTRY ent%scalar(1) = 'carray' ent%scalar_ind(1) = 2 @@ -1626,7 +1626,7 @@ call check_ok(ne, 145, d) call check_int2(ne, 145, 1, n, GD_RECIP_ENTRY) call check_int2(ne, 145, 2, ent%fragment_index, 0) - call check_int2(ne, 145, 3, ent%comp_scal, 1) + call check_int2(ne, 145, 3, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) call check_str2(ne, 145, 4, ent%field(1), 'div') call check_cpx2(ne, 145, 5, ent%cdividend, dcmplx(6.5d0, 4.3d0)) @@ -1650,7 +1650,7 @@ call check_int2(ne, 147, 1, n, GD_RECIP_ENTRY) call check_int2(ne, 147, 2, ent%fragment_index, 0) call check_str2(ne, 147, 3, ent%field(1), 'in1') - call check_int2(ne, 147, 4, ent%comp_scal, 0) + call check_int2(ne, 147, 4, ent%flags, GD_EN_CALC) call check_dbl2(ne, 147, 5, ent%dividend, 31.9d0) ! 148: fgd_add_recip check @@ -1662,7 +1662,7 @@ call check_int2(ne, 148, 1, n, GD_RECIP_ENTRY) call check_int2(ne, 148, 2, ent%fragment_index, 0) call check_str2(ne, 148, 3, ent%field(1), 'in1') - call check_int2(ne, 148, 4, ent%comp_scal, 1) + call check_int2(ne, 148, 4, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) call check_cpx2(ne, 148, 5, ent%cdividend, dcmplx(31.9d0, 38.2d0)) ! 149: fgd_madd_divide check @@ -1685,7 +1685,7 @@ call check_int2(ne, 150, 1, n, GD_RECIP_ENTRY) call check_int2(ne, 150, 2, ent%fragment_index, 0) call check_str2(ne, 150, 3, ent%field(1), 'in0') - call check_int2(ne, 150, 4, ent%comp_scal, 0) + call check_int2(ne, 150, 4, ent%flags, GD_EN_CALC) call check_dbl2(ne, 150, 5, ent%dividend, 95.5d0) ! 151: fgd_madd_recip check @@ -1697,7 +1697,7 @@ call check_int2(ne, 151, 1, n, GD_RECIP_ENTRY) call check_int2(ne, 151, 2, ent%fragment_index, 0) call check_str2(ne, 151, 3, ent%field(1), 'in3') - call check_int2(ne, 151, 4, ent%comp_scal, 1) + call check_int2(ne, 151, 4, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) call check_cpx2(ne, 151, 5, ent%cdividend, dcmplx(8.47d0, 6.22d0)) ! 152: fgd_alter_divide check @@ -2562,7 +2562,7 @@ ent%field_type = GD_LINCOM_ENTRY ent%fragment_index = 0 ent%n_fields = 3 - ent%comp_scal = 0 + ent%flags = 0 ent%field(1) = 'in1' ent%field(2) = 'in2' ent%field(3) = 'in3' @@ -2589,7 +2589,7 @@ call check_str2(ne, 243, 6, ent%field(1), 'in1') call check_str2(ne, 243, 7, ent%field(2), 'in2') call check_str2(ne, 243, 8, ent%field(3), 'in3') - call check_int2(ne, 243, 9, ent%comp_scal, 0) + call check_int2(ne, 243, 9, ent%flags, GD_EN_CALC) call check_str2(ne, 243, 10, ent%scalar(1), '') call check_str2(ne, 243, 11, ent%scalar(2), 'const') call check_str2(ne, 243, 12, ent%scalar(3), '') @@ -2611,7 +2611,7 @@ ent%field_type = GD_POLYNOM_ENTRY ent%fragment_index = 0 ent%field(1) = 'in1' - ent%comp_scal = 0 + ent%flags = 0 ent%a(1) = 33d0 ent%a(2) = 44d0 ent%a(3) = 66d0 @@ -2630,7 +2630,7 @@ call check_int2(ne, 244, 4, ent%poly_ord, 3) call check_int2(ne, 244, 5, ent%fragment_index, 0) call check_str2(ne, 244, 6, ent%field(1), 'in1') - call check_int2(ne, 244, 7, ent%comp_scal, 0) + call check_int2(ne, 244, 7, ent%flags, GD_EN_CALC) call check_dbl2(ne, 244, 8, ent%a(1), 33d0) call check_dbl2(ne, 244, 9, ent%a(2), 44d0) call check_dbl2(ne, 244, 10, ent%a(3), 66d0) @@ -2686,7 +2686,7 @@ ent%field_type = GD_RECIP_ENTRY ent%fragment_index = 0 ent%scalar(1) = 'carray' - ent%comp_scal = 0 + ent%flags = 0 ent%scalar_ind = 4 call fgd_add(d, 'new251', ent) call check_ok2(ne, 251, 1, d) @@ -2695,7 +2695,7 @@ call check_ok2(ne, 251, 2, d) call check_int2(ne, 251, 3, n, GD_RECIP_ENTRY) call check_int2(ne, 251, 4, ent%fragment_index, 0) - call check_int2(ne, 251, 5, ent%comp_scal, 0) + call check_int2(ne, 251, 5, ent%flags, GD_EN_CALC) call check_str2(ne, 251, 6, ent%field(1), 'in1') call check_dbl2(ne, 251, 7, ent%dividend, 180d0) call check_str2(ne, 251, 8, ent%scalar(1), 'carray') @@ -2751,7 +2751,7 @@ ent%field_type = GD_LINCOM_ENTRY ent%fragment_index = 0 ent%n_fields = 3 - ent%comp_scal = 1 + ent%flags = GD_EN_COMPSCAL ent%field(1) = 'in1' ent%field(2) = 'in2' ent%field(3) = 'in3' @@ -2778,7 +2778,7 @@ call check_str2(ne, 255, 6, ent%field(1), 'in1') call check_str2(ne, 255, 7, ent%field(2), 'in2') call check_str2(ne, 255, 8, ent%field(3), 'in3') - call check_int2(ne, 255, 9, ent%comp_scal, 1) + call check_int2(ne, 255, 9, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) call check_str2(ne, 255, 10, ent%scalar(1), '') call check_str2(ne, 255, 11, ent%scalar(2), 'const') call check_str2(ne, 255, 12, ent%scalar(3), '') @@ -2799,7 +2799,7 @@ ent%field_type = GD_POLYNOM_ENTRY ent%fragment_index = 0 ent%field(1) = 'in1' - ent%comp_scal = 1 + ent%flags = GD_EN_COMPSCAL ent%ca(1) = dcmplx(22d0, 33d0) ent%ca(2) = dcmplx(44d0, 55d0) ent%ca(3) = dcmplx(66d0, 77d0) @@ -2818,7 +2818,7 @@ call check_int2(ne, 256, 4, ent%poly_ord, 3) call check_int2(ne, 256, 5, ent%fragment_index, 0) call check_str2(ne, 256, 6, ent%field(1), 'in1') - call check_int2(ne, 256, 7, ent%comp_scal, 1) + call check_int2(ne, 256, 7, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) call check_cpx2(ne, 256, 8, ent%ca(1), dcmplx(22d0, 33d0)) call check_cpx2(ne, 256, 9, ent%ca(2), dcmplx(44d0, 55d0)) call check_cpx2(ne, 256, 10, ent%ca(3), dcmplx(66d0, 77d0)) @@ -2834,7 +2834,7 @@ ent%field_type = GD_RECIP_ENTRY ent%fragment_index = 0 ent%scalar(1) = 'carray' - ent%comp_scal = 1 + ent%flags = GD_EN_COMPSCAL ent%scalar_ind = 4 call fgd_add(d, 'new257', ent) call check_ok2(ne, 257, 1, d) @@ -2843,7 +2843,7 @@ call check_ok2(ne, 257, 2, d) call check_int2(ne, 257, 3, n, GD_RECIP_ENTRY) call check_int2(ne, 257, 4, ent%fragment_index, 0) - call check_int2(ne, 257, 5, ent%comp_scal, 0) + call check_int2(ne, 257, 5, ent%flags, GD_EN_CALC) call check_str2(ne, 257, 6, ent%field(1), 'in1') call check_dbl2(ne, 257, 7, ent%dividend, 180d0) call check_str2(ne, 257, 8, ent%scalar(1), 'carray') @@ -2872,8 +2872,8 @@ ! 259: fgd_alter_entry lincom ent%field_type = GD_LINCOM_ENTRY ent%field(2) = 'in4' - ent%comp_scal = 0; - ent%m(1) = 2.2d0; + ent%flags = 0 + ent%m(1) = 2.2d0 ent%scalar(2) = '' ent%scalar(3) = 'const' ent%scalar(4) = 'carray' @@ -2891,7 +2891,7 @@ call check_str2(ne, 259, 6, ent%field(1), 'in1') call check_str2(ne, 259, 7, ent%field(2), 'in4') call check_str2(ne, 259, 8, ent%field(3), 'in3') - call check_int2(ne, 259, 9, ent%comp_scal, 0) + call check_int2(ne, 259, 9, ent%flags, GD_EN_CALC) call check_str2(ne, 259, 10, ent%scalar(1), '') call check_str2(ne, 259, 11, ent%scalar(2), 'const') call check_str2(ne, 259, 12, ent%scalar(3), 'const') @@ -2914,7 +2914,7 @@ ent%field(2) = 'in4' ent%field(3) = 'in3' ent%field_type = GD_LINCOM_ENTRY - ent%comp_scal = 1 + ent%flags = GD_EN_COMPSCAL ent%cm(1) = dcmplx(9d0, 8d0) ent%scalar(2) = '' ent%scalar(3) = '' @@ -2932,7 +2932,7 @@ call check_str2(ne, 260, 6, ent%field(1), 'in1') call check_str2(ne, 260, 7, ent%field(2), 'in4') call check_str2(ne, 260, 8, ent%field(3), 'in3') - call check_int2(ne, 260, 9, ent%comp_scal, 1) + call check_int2(ne, 260, 9, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) call check_str2(ne, 260, 10, ent%scalar(1), '') call check_str2(ne, 260, 11, ent%scalar(2), 'const') call check_str2(ne, 260, 12, ent%scalar(3), 'const') @@ -2953,7 +2953,7 @@ ! 261: fgd_alter_entry POLYNOM ent%field(1) = 'in3' ent%field_type = GD_POLYNOM_ENTRY - ent%comp_scal = 0 + ent%flags = 0 ent%a(1) = 2d0 ent%a(2) = 6d0 ent%scalar(1) = '' @@ -2969,7 +2969,7 @@ call check_int2(ne, 261, 4, ent%poly_ord, 3) call check_int2(ne, 261, 5, ent%fragment_index, 0) call check_str2(ne, 261, 6, ent%field(1), 'in3') - call check_int2(ne, 261, 7, ent%comp_scal, 0) + call check_int2(ne, 261, 7, ent%flags, GD_EN_CALC) call check_dbl2(ne, 261, 8, ent%a(1), 2d0) call check_dbl2(ne, 261, 9, ent%a(2), 6d0) call check_dbl2(ne, 261, 10, ent%a(3), 15d0) @@ -2982,7 +2982,7 @@ ! 262: fgd_alter_entry CPOLYNOM ent%field_type = GD_POLYNOM_ENTRY - ent%comp_scal = 1 + ent%flags = GD_EN_COMPSCAL ent%ca(3) = dcmplx(26d0, 2d0) ent%scalar(1) = 'const' ent%scalar(2) = 'const' @@ -2997,7 +2997,7 @@ call check_int2(ne, 262, 4, ent%poly_ord, 3) call check_int2(ne, 262, 5, ent%fragment_index, 0) call check_str2(ne, 262, 6, ent%field(1), 'in3') - call check_int2(ne, 262, 7, ent%comp_scal, 1) + call check_int2(ne, 262, 7, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) call check_cpx2(ne, 262, 8, ent%ca(1), dcmplx(93d0, 0)) call check_cpx2(ne, 262, 9, ent%ca(2), dcmplx(93d0, 0)) call check_cpx2(ne, 262, 10, ent%ca(3), dcmplx(26d0, 2d0)) @@ -3061,7 +3061,7 @@ ! 266: fgd_alter_entry RECIP ent%field_type = GD_RECIP_ENTRY - ent%comp_scal = 0 + ent%flags = 0 ent%field(1) = 'in5' ent%scalar(1) = 'carray' ent%scalar_ind(1) = 2 @@ -3072,7 +3072,7 @@ call check_ok2(ne, 266, 2, d) call check_int2(ne, 266, 3, n, GD_RECIP_ENTRY) call check_int2(ne, 266, 4, ent%fragment_index, 0) - call check_int2(ne, 266, 5, ent%comp_scal, 0) + call check_int2(ne, 266, 5, ent%flags, GD_EN_CALC) call check_str2(ne, 266, 6, ent%field(1), 'in5') call check_dbl2(ne, 266, 7, ent%dividend, 12d0) call check_str2(ne, 266, 8, ent%scalar(1), 'carray') @@ -3081,7 +3081,7 @@ ! 267: fgd_alter_entry CRECIP ent%field_type = GD_RECIP_ENTRY ent%field(1) = 'in4' - ent%comp_scal = 1 + ent%flags = GD_EN_COMPSCAL ent%cdividend = dcmplx(12d0, 14d0) call fgd_alter_entry(d, 'new251', ent, 15, 0) call check_ok2(ne, 267, 1, d) @@ -3090,7 +3090,7 @@ call check_ok2(ne, 267, 2, d) call check_int2(ne, 267, 3, n, GD_RECIP_ENTRY) call check_int2(ne, 267, 4, ent%fragment_index, 0) - call check_int2(ne, 267, 5, ent%comp_scal, 1) + call check_int2(ne, 267, 5, ent%flags, GD_EN_CALC + GD_EN_COMPSCAL) call check_str2(ne, 267, 6, ent%field(1), 'in4') call check_cpx2(ne, 267, 7, ent%cdividend, dcmplx(12d0, 14d0)) call check_str2(ne, 267, 8, ent%scalar(1), '') Modified: trunk/getdata/bindings/idl/getdata.c =================================================================== --- trunk/getdata/bindings/idl/getdata.c 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/idl/getdata.c 2013-12-11 00:16:49 UTC (rev 868) @@ -446,6 +446,9 @@ "IN_FIELDS", IDL_MSG_LONGJMP, NULL)), E->in_fields[0]); } + *(IDL_UINT*)(data + IDL_StructTagInfoByName(gdidl_entry_def, + "FLAGS", IDL_MSG_LONGJMP, NULL)) = E->flags; + switch (E->field_type) { case GD_RAW_ENTRY: @@ -461,8 +464,6 @@ case GD_LINCOM_ENTRY: *(IDL_INT*)(data + IDL_StructTagInfoByName(gdidl_entry_def, "N_FIELDS", IDL_MSG_LONGJMP, NULL)) = E->n_fields; - *(IDL_INT*)(data + IDL_StructTagInfoByName(gdidl_entry_def, - "COMP_SCAL", IDL_MSG_LONGJMP, NULL)) = E->comp_scal; for (i = 0; i < E->n_fields; ++i) { IDL_StrStore((IDL_STRING*)(data + IDL_StructTagInfoByName(gdidl_entry_def, "IN_FIELDS", @@ -519,8 +520,6 @@ "IN_FIELDS", IDL_MSG_LONGJMP, NULL)) + 1, E->in_fields[1]); break; case GD_RECIP_ENTRY: - *(IDL_INT*)(data + IDL_StructTagInfoByName(gdidl_entry_def, - "COMP_SCAL", IDL_MSG_LONGJMP, NULL)) = E->comp_scal; IDL_StrStore((IDL_STRING*)(data + IDL_StructTagInfoByName(gdidl_entry_def, "SCALAR", IDL_MSG_LONGJMP, NULL)), E->scalar[0]); ((int16_t*)(data + IDL_StructTagInfoByName(gdidl_entry_def, @@ -542,8 +541,6 @@ break; case GD_POLYNOM_ENTRY: *(IDL_INT*)(data + IDL_StructTagInfoByName(gdidl_entry_def, - "COMP_SCAL", IDL_MSG_LONGJMP, NULL)) = E->comp_scal; - *(IDL_INT*)(data + IDL_StructTagInfoByName(gdidl_entry_def, "POLY_ORD", IDL_MSG_LONGJMP, NULL)) = E->poly_ord; for (i = 0; i <= E->poly_ord; ++i) { @@ -960,7 +957,7 @@ if (E->n_fields > 0) min = max = E->n_fields; - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; tmask = (1 << max) - 1; mask = gdidl_get_entry_scalars(E, 9 * tmask, v); @@ -1010,7 +1007,7 @@ break; case GD_RECIP_ENTRY: gdidl_get_in_fields((char**)E->in_fields, v, 1, 1, miss_ok); - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; mask = gdidl_get_entry_scalars(E, 0x1, v); @@ -1043,7 +1040,7 @@ tmask = (1 << max) - 1; mask = gdidl_get_entry_scalars(E, tmask, v); - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; if ((mask & tmask) != tmask) E->poly_ord = gdidl_get_entry_cmparr(E->ca, v, 'A', min, max, mask, @@ -5947,6 +5944,7 @@ static IDL_STRUCT_TAG_DEF gdidl_entry[] = { { "FIELD", 0, (void*)IDL_TYP_STRING }, { "FIELD_TYPE", 0, (void*)IDL_TYP_INT }, + { "FLAGS", 0, (void*)IDL_TYP_UINT }, { "FRAGMENT", 0, (void*)IDL_TYP_INT }, { "IN_FIELDS", lincom_dims, (void*)IDL_TYP_STRING }, @@ -5956,7 +5954,6 @@ { "B", lincom_dims, (void*)IDL_TYP_DOUBLE }, /* LINCOM */ { "CB", lincom_dims, (void*)IDL_TYP_DCOMPLEX }, /* LINCOM */ { "BITNUM", 0, (void*)IDL_TYP_INT }, /* (S)BIT */ - { "COMP_SCAL", 0, (void*)IDL_TYP_INT }, /* LINCOM / POLYNOM */ { "COUNT_VAL", 0, (void*)IDL_TYP_INT }, /* MPLEX */ { "DATA_TYPE", 0, (void*)IDL_TYP_INT }, /* RAW / CONST / CARRAY */ { "DIVIDEND", 0, (void*)IDL_TYP_DOUBLE }, /* RECIP */ Modified: trunk/getdata/bindings/idl/test/big_test.pro =================================================================== --- trunk/getdata/bindings/idl/test/big_test.pro 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/idl/test/big_test.pro 2013-12-11 00:16:49 UTC (rev 868) @@ -187,7 +187,7 @@ nume += check_simple2(42, 3, n.fragment, 0) nume += check_simple2(42, 4, n.n_fields, 3) nume += check_simple2(42, 5, n.in_fields, [ "data", "INDEX", "linterp" ]) -nume += check_simple2(42, 6, n.comp_scal, 1) +nume += check_simple2(42, 6, n.flags, !GD.EN_COMPSCAL + !GD.EN_CALC) nume += check_simple2(42, 7, n.cm, [ DCOMPLEX(1.1D,0), DCOMPLEX(2.2D,0), $ DCOMPLEX(5.5D,0) ]) nume += check_simple2(42, 8, n.cb, [ DCOMPLEX(2.2D,0), DCOMPLEX(3.3D,4.4D), $ @@ -202,7 +202,7 @@ nume += check_simple2(44, 3, n.fragment, 0) nume += check_simple2(44, 4, n.poly_ord, 5) nume += check_simple2(44, 5, n.in_fields, [ "data" ]) -nume += check_simple2(44, 6, n.comp_scal, 1) +nume += check_simple2(44, 6, n.flags, !GD.EN_COMPSCAL + !GD.EN_CALC) nume += check_simple2(44, 7, n.ca, [ DCOMPLEX(1.1D,0), DCOMPLEX(2.2D,0), $ DCOMPLEX(2.2D,0), DCOMPLEX(3.3D,4.4D), DCOMPLEX(5.5D,0), DCOMPLEX(5.5D,0) ]) nume += check_simple2(44, 8, n.scalar, [ "", "", "", "", "const", "const" ]) @@ -297,7 +297,7 @@ nume += check_simple2(55, 3, n.fragment, 0) nume += check_simple2(55, 4, n.n_fields, 2) nume += check_simple2(55, 5, n.in_fields, [ "in1", "in2" ]) -nume += check_simple2(55, 6, n.comp_scal, 1) +nume += check_simple2(55, 6, n.flags, !GD.EN_COMPSCAL + !GD.EN_CALC) nume += check_simple2(55, 7, n.cm, [ DCOMPLEX(1.1,1.2), DCOMPLEX(1.4,1.5) ]) nume += check_simple2(55, 8, n.cb, [ DCOMPLEX(1.3,1.4), DCOMPLEX(1.6,1.7) ]) @@ -313,7 +313,7 @@ nume += check_simple2(57, 3, n.fragment, 0) nume += check_simple2(57, 4, n.poly_ord, 3) nume += check_simple2(57, 5, n.in_fields, [ "in1" ]) -nume += check_simple2(57, 6, n.comp_scal, 1) +nume += check_simple2(57, 6, n.flags, !GD.EN_COMPSCAL + !GD.EN_CALC) nume += check_simple2(57, 7, n.ca, [ DCOMPLEX(3.1,7.0D), DCOMPLEX(4.2,8.0), $ DCOMPLEX(5.2,9.0), DCOMPLEX(6.3,4.4) ]) @@ -445,7 +445,7 @@ nume += check_simple2(71, 3, n.fragment, 0) nume += check_simple2(71, 4, n.n_fields, 2) nume += check_simple2(71, 5, n.in_fields, [ "in1", "in2" ]) -nume += check_simple2(71, 6, n.comp_scal, 0) +nume += check_simple2(71, 6, n.flags, !GD.EN_CALC) nume += check_simple2(71, 7, n.m, [ 9.9D, 7.7D ]) nume += check_simple2(71, 8, n.b, [ 8.8D, 6.6D ]) @@ -461,7 +461,7 @@ nume += check_simple2(73, 3, n.fragment, 0) nume += check_simple2(73, 4, n.poly_ord, 3) nume += check_simple2(73, 5, n.in_fields, [ "in1" ]) -nume += check_simple2(73, 6, n.comp_scal, 0) +nume += check_simple2(73, 6, n.flags, !GD.EN_CALC) nume += check_simple2(73, 7, n.a, [ 3.3D, 4.4D, 5.5D, 6.6D ]) ; 75: gd_madd_linterp @@ -658,7 +658,7 @@ nume += check_simple2(101, 3, n.fragment, 0) nume += check_simple2(101, 4, n.n_fields, 2) nume += check_simple2(101, 5, n.in_fields, [ "in3", "in4" ]) -nume += check_simple2(101, 6, n.comp_scal, 1) +nume += check_simple2(101, 6, n.flags, !GD.EN_COMPSCAL + !GD.EN_CALC) nume += check_simple2(101, 7, n.cm, [ DCOMPLEX(2.3,4.5), DCOMPLEX(6.7,8.9) ]) nume += check_simple2(101, 8, n.cb, [ DCOMPLEX(1.3,1.4), DCOMPLEX(1.6,1.7) ]) @@ -674,7 +674,7 @@ nume += check_simple2(103, 3, n.fragment, 0) nume += check_simple2(103, 4, n.poly_ord, 4) nume += check_simple2(103, 5, n.in_fields, [ "in1" ]) -nume += check_simple2(103, 6, n.comp_scal, 1) +nume += check_simple2(103, 6, n.flags, !GD.EN_COMPSCAL + !GD.EN_CALC) nume += check_simple2(103, 7, n.ca, [ DCOMPLEX(1.2,3.4), DCOMPLEX(5.6,7.8), $ DCOMPLEX(9.0,1.2), DCOMPLEX(3.4,5.6), DCOMPLEX(7.8,9.0) ]) @@ -959,7 +959,7 @@ nume += check_simple2(145, 2, n.field, "recip") nume += check_simple2(145, 3, n.fragment, 0) nume += check_simple2(145, 4, n.in_fields, [ "div" ]) -nume += check_simple2(145, 5, n.comp_scal, 1) +nume += check_simple2(145, 5, n.flags, !GD.EN_COMPSCAL + !GD.EN_CALC) nume += check_simple2(145, 6, n.cdividend, DCOMPLEX(6.5D,4.3D)) ; 146: gd_add_divide @@ -983,7 +983,7 @@ nume += check_simple2(148, 2, n.field, "new16") nume += check_simple2(148, 3, n.fragment, 0) nume += check_simple2(148, 4, n.in_fields, [ "in2" ]) -nume += check_simple2(148, 5, n.comp_scal, 1) +nume += check_simple2(148, 5, n.flags, !GD.EN_COMPSCAL + !GD.EN_CALC) nume += check_simple2(148, 6, n.cdividend, DCOMPLEX(33.3, 44.4)) ; 152: gd_alter_divide @@ -1006,7 +1006,7 @@ nume += check_simple2(153, 1, n.field_type, !GD.RECIP_ENTRY) nume += check_simple2(153, 2, n.field, "new16") nume += check_simple2(153, 3, n.fragment, 0) -nume += check_simple2(153, 5, n.comp_scal, 0) +nume += check_simple2(153, 5, n.flags, !GD.EN_CALC) nume += check_simple2(153, 4, n.in_fields, [ "in2" ]) nume += check_simple2(153, 6, n.dividend, 1.01) @@ -1393,7 +1393,7 @@ nume += check_simple2(243, 5, n.fragment, 0) nume += check_simple2(243, 6, n.n_fields, 3) nume += check_simple2(243, 7, n.in_fields, [ "in1", "in2", "in3" ]) -nume += check_simple2(243, 8, n.comp_scal, 0) +nume += check_simple2(243, 8, n.flags, !GD.EN_CALC) nume += check_simple2(243, 9, n.cm, [ DCOMPLEX(1.1D,0), DCOMPLEX(86D,0), $ DCOMPLEX(1.4D,0) ]) nume += check_simple2(243, 10, n.m, [ 1.1D, 86D, 1.4D ]) @@ -1418,7 +1418,7 @@ nume += check_simple2(244, 5, n.fragment, 0) nume += check_simple2(244, 6, n.poly_ord, 3) nume += check_simple2(244, 7, n.in_fields, [ "in2" ]) -nume += check_simple2(244, 8, n.comp_scal, 1) +nume += check_simple2(244, 8, n.flags, !GD.EN_COMPSCAL + !GD.EN_CALC) nume += check_simple2(244, 9, n.ca, [ DCOMPLEX(33D, 0), DCOMPLEX(44D, 55D), $ DCOMPLEX(66D, 0) ]) nume += check_simple2(244, 10, n.a, [ 33D, 44D, 66D ]) @@ -1526,7 +1526,7 @@ nume += check_simple2(145, 4, n.field, "Bnew251") nume += check_simple2(145, 5, n.fragment, 1) nume += check_simple2(145, 6, n.in_fields, [ "Bin1" ]) -nume += check_simple2(145, 7, n.comp_scal, 1) +nume += check_simple2(145, 7, n.flags, !GD.EN_COMPSCAL + !GD.EN_CALC) nume += check_simple2(145, 8, n.cdividend, DCOMPLEX(33.3, 44.4)) nume += check_simple2(145, 9, n.dividend, 33.3) @@ -1590,7 +1590,7 @@ nume += check_simple2(259, 5, n.fragment, 0) nume += check_simple2(259, 6, n.n_fields, 3) nume += check_simple2(259, 7, n.in_fields, [ "in1", "in2", "in3" ]) -nume += check_simple2(259, 8, n.comp_scal, 0) +nume += check_simple2(259, 8, n.flags, !GD.EN_CALC) nume += check_simple2(259, 9, n.cm, [ DCOMPLEX(1.1D,0), DCOMPLEX(86D,0), $ DCOMPLEX(86D,0) ]) nume += check_simple2(259, 10, n.m, [ 1.1D, 86D, 86D ]) Modified: trunk/getdata/bindings/make_parameters.c =================================================================== --- trunk/getdata/bindings/make_parameters.c 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/make_parameters.c 2013-12-11 00:16:49 UTC (rev 868) @@ -45,6 +45,7 @@ * 12: window operations * 13: desynced flags (not in IDL) * 14: entry_list constants (not in IDL) + * 15: entry flags * 98: miscellaneous constants not in IDL * 99: miscellaneous constants */ @@ -232,6 +233,10 @@ CONSTANT(ENTRIES_HIDDEN, "GDEN_H", 14), CONSTANT(ENTRIES_NOALIAS, "GDEN_N", 14), + CONSTANT(EN_CALC, "GDE_CA", 15), + CONSTANT(EN_HIDDEN, "GDE_HI", 15), + CONSTANT(EN_COMPSCAL, "GDE_CS", 15), + CONSTANT(ALL_FRAGMENTS, "GD_ALL", 99), CONSTANT(DEFAULT_LOOKBACK, "GDLB_D", 99), CONSTANT(DIRFILE_STANDARDS_VERSION, "GD_DSV", 99), @@ -358,6 +363,13 @@ parameter(constant_list[j].lname, constant_list[j].fname, constant_list[j].value, i); + printf("\\\n%c Entry object flags\\\n", c); + + for (j = 0; constant_list[j].lname != NULL; ++j) + if (constant_list[j].type == 15) + parameter(constant_list[j].lname, constant_list[j].fname, + constant_list[j].value, i); + printf("\\\n%c Miscellaneous parameters\\\n", c); for (j = 0; constant_list[j].lname != NULL; ++j) Modified: trunk/getdata/bindings/perl/GetData.xs =================================================================== --- trunk/getdata/bindings/perl/GetData.xs 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/perl/GetData.xs 2013-12-11 00:16:49 UTC (rev 868) @@ -445,7 +445,7 @@ if (E->EN(lincom,n_fields) != 0) min = max = E->EN(lincom,n_fields); - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; tmask = (1 << max) - 1; mask = gdp_fetch_scalars(E, (HV*)sv, ((1 << max) - 1) * 9, pkg, func); @@ -497,7 +497,7 @@ mask = gdp_fetch_scalars(E, (HV*)sv, (1 << (max + 1)) - 1, pkg, func); tmask = (1 << max) - 1; - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; if ((mask & tmask) != tmask) E->EN(polynom,poly_ord) = gdp_fetch_cmp_list(E->EN(polynom,ca), (HV*)sv, partial, 'a', min, max, mask, pkg, func) - 1; @@ -508,7 +508,7 @@ gdp_fetch_in_fields(E->in_fields, sv, partial, 1, 1, pkg, func); mask = gdp_fetch_scalars(E, (HV*)sv, 1, pkg, func); - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; if (!(mask & 1)) GDP_EHASH_FETCH_CMP(partial, "dividend", EN(recip,cdividend)); break; Modified: trunk/getdata/bindings/php/getdata.c =================================================================== --- trunk/getdata/bindings/php/getdata.c 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/php/getdata.c 2013-12-11 00:16:49 UTC (rev 868) @@ -1320,7 +1320,7 @@ mask = gdphp_entry_scalars(E->scalar, E->scalar_ind, a, lincom_mask[max], ctx); - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; tmask = (1 << max) - 1; if ((mask & tmask) != tmask) @@ -1382,7 +1382,7 @@ mask = gdphp_entry_scalars(E->scalar, E->scalar_ind, a, (1 << max) - 1, ctx); - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; tmask = (1 << max) - 1; if ((mask & tmask) != tmask) E->EN(polynom,poly_ord) = @@ -1400,7 +1400,7 @@ case GD_RECIP_ENTRY: gdphp_entry_infields((char**)E->in_fields, a, 1, 1, partial, ctx); mask = gdphp_entry_scalars(E->scalar, E->scalar_ind, a, 1, ctx); - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; if (!(mask & 1)) gdphp_entry_complex((double*)gd_csp_(E->EN(recip,cdividend)), a, "dividend", sizeof("dividend"), partial, ctx); Modified: trunk/getdata/bindings/python/pyentry.c =================================================================== --- trunk/getdata/bindings/python/pyentry.c 2013-12-07 01:48:34 UTC (rev 867) +++ trunk/getdata/bindings/python/pyentry.c 2013-12-11 00:16:49 UTC (rev 868) @@ -254,9 +254,9 @@ obj = PyTuple_GetItem(parm2, i); if (PyComplex_Check(obj)) { - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; gdpy_as_complex(gd_csp_(E->EN(lincom,cm)[i]), obj); - } else if (E->comp_scal) + } else if (E->flags & GD_EN_COMPSCAL) gdpy_set_scalar_from_pyobj(obj, GD_COMPLEX128, &E->scalar[i], &E->EN(lincom,cm)[i]); else { @@ -272,9 +272,9 @@ obj = PyTuple_GetItem(parm3, i); if (PyComplex_Check(obj)) { - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; gdpy_as_complex(gd_csp_(E->EN(lincom,cb)[i]), obj); - } else if (E->comp_scal) + } else if (E->flags & GD_EN_COMPSCAL) gdpy_set_scalar_from_pyobj(obj, GD_COMPLEX128, &E->scalar[i + GD_MAX_LINCOM], &E->EN(lincom,cb)[i]); else { @@ -349,9 +349,9 @@ obj = PyTuple_GetItem(tuple, 1); if (PyComplex_Check(obj)) { - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; gdpy_as_complex(gd_csp_(E->EN(recip,cdividend)), obj); - } else if (E->comp_scal) + } else if (E->flags & GD_EN_COMPSCAL) gdpy_set_scalar_from_pyobj(obj, GD_COMPLEX128, &E->scalar[0], &E->EN(recip,cdividend)); else { @@ -399,10 +399,10 @@ for (i = 0; i <= count; ++i) { obj = PyTuple_GetItem(parm2, i); if (PyComplex_Check(obj)) { - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; gdpy_as_complex(gd_csp_(E->EN(polynom,ca)[i]), obj); E->scalar[i] = NULL; - } else if (E->comp_scal) + } else if (E->flags & GD_EN_COMPSCAL) gdpy_set_scalar_from_pyobj(obj, GD_COMPLEX128, &E->scalar[i], &E->EN(polynom,ca)[i]); else { @@ -972,7 +972,7 @@ if (t != -1) { sprintf(buffer, "%s%i", (t & GD_COMPLEX) ? "COMPLEX" : - (t & GD_IEEE754) ? "FLOAT" : (t & GD... [truncated message content] |
From: <ket...@us...> - 2013-12-12 03:33:58
|
Revision: 872 http://sourceforge.net/p/getdata/code/872 Author: ketiltrout Date: 2013-12-12 03:33:54 +0000 (Thu, 12 Dec 2013) Log Message: ----------- ANSI C fixes. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/NEWS trunk/getdata/bindings/f77/fgetdata.c trunk/getdata/bindings/perl/GetData.xs trunk/getdata/configure.ac trunk/getdata/src/common.c trunk/getdata/src/entry.c trunk/getdata/src/getdata.c trunk/getdata/src/internal.h trunk/getdata/src/mod.c trunk/getdata/src/name.c trunk/getdata/test/alter_clincom.c trunk/getdata/test/alter_cpolynom_null.c trunk/getdata/test/alter_entry_recode_recalc.c trunk/getdata/test/alter_entry_scalar1.c trunk/getdata/test/alter_entry_scalar3c.c Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/ChangeLog 2013-12-12 03:33:54 UTC (rev 872) @@ -1,3 +1,15 @@ +2013-12-12 D. V. Wiebe <ge...@ke...> svn:872 + * configure.ac: Disable PHP bindings if we don't have a C99 compiler. + + * src/common.c (_GD_CInvertData): Correct algebra in C89 INVERT macro. + * src/getdata.c (_GD_PolynomData): Implement correct C89 POLYNOMC macro. + * src/getdata.c (_GD_CDivideData): Correct algebra in C89 DIVIDEC macro. + + * src/entry.c (_GD_CalculateEntry): Return success or failure separately + from Dirfile error. + + * src/internal.h: Fix pointer arithmetic in C89 gd_cap_ macro. + 2013-12-10 D. V. Wiebe <ge...@ke...> svn:868 * src/getdata.h.in src/internal.h: Merge gd_entry_t members 'comp_scal' and 'hidden', plus private member 'calculated' into (public) member 'flags', and Modified: trunk/getdata/NEWS =================================================================== --- trunk/getdata/NEWS 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/NEWS 2013-12-12 03:33:54 UTC (rev 872) @@ -50,6 +50,9 @@ * BUG FIX: DIVIDE fields with complex valued divisors are now properly computed. + * BUG FIX: Complex-valued DIVIDE, POLYNOM, and RECIP fields are now computed + properly when the library is built in ANSI C mode. + * BUG FIX: Writing complex MPLEX fields no longer corrupts the stored data. * BUG FIX: Several fixes have been made to the sample index encoding (SIE) Modified: trunk/getdata/bindings/f77/fgetdata.c =================================================================== --- trunk/getdata/bindings/f77/fgetdata.c 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/bindings/f77/fgetdata.c 2013-12-12 03:33:54 UTC (rev 872) @@ -141,10 +141,10 @@ /* create a gd_triple_t value */ static gd_triplet_t _GDF_SetTriplet(gd_windop_t op, const void *data) { + gd_triplet_t t; + dtrace("%i, %p", op, data); - gd_triplet_t t; - switch(op) { case GD_WINDOP_EQ: case GD_WINDOP_NE: @@ -3253,11 +3253,13 @@ const int32_t *return_type, const int32_t *field_num) { const void *v; + DIRFILE *D; + unsigned int nfields; dtrace("%p, %i, 0x%x, %i", value, *dirfile, *return_type, *field_num); - DIRFILE *D = _GDF_GetDirfile(*dirfile); - unsigned int nfields = gd_nfields_by_type(D, GD_CONST_ENTRY); + D = _GDF_GetDirfile(*dirfile); + nfields = gd_nfields_by_type(D, GD_CONST_ENTRY); if (!gd_error(D) && (*field_num > 0) && (*field_num <= (int)nfields)) { v = gd_constants(D, (gd_type_t)*return_type); @@ -3301,11 +3303,13 @@ const int32_t *dirfile, const int32_t *field_num) { const char **v; + DIRFILE *D; + unsigned int nfields; dtrace("%p, %i, %i, %i", value, *value_l, *dirfile, *field_num); - DIRFILE *D = _GDF_GetDirfile(*dirfile); - unsigned int nfields = gd_nfields_by_type(D, GD_STRING_ENTRY); + D = _GDF_GetDirfile(*dirfile); + nfields = gd_nfields_by_type(D, GD_STRING_ENTRY); if (!gd_error(D) && (*field_num > 0) && (*field_num <= (int)nfields)) { v = gd_strings(D); @@ -3347,13 +3351,16 @@ /* Return the maximum string value length */ void F77_FUNC(gdstrx, GDSTRX) (int32_t *max, const int32_t *dirfile) { - dtrace("%p, %i", max, *dirfile); - const char **v; size_t len = 0; - DIRFILE *D = _GDF_GetDirfile(*dirfile); - unsigned int i, nfields = gd_nfields_by_type(D, GD_STRING_ENTRY); + DIRFILE *D; + unsigned int i, nfields; + dtrace("%p, %i", max, *dirfile); + + D = _GDF_GetDirfile(*dirfile); + nfields = gd_nfields_by_type(D, GD_STRING_ENTRY); + if (!gd_error(D)) { v = gd_strings(D); @@ -3553,10 +3560,11 @@ size_t len = 0; char *fc; unsigned int i, nalias; + DIRFILE *D; dtrace("%p, %i, %p, %i", max, *dirfile, field_code, *field_code_l); - DIRFILE* D = _GDF_GetDirfile(*dirfile); + D = _GDF_GetDirfile(*dirfile); _GDF_CString(&fc, field_code, *field_code_l); nalias = gd_naliases(D, fc); @@ -3598,11 +3606,12 @@ const char **al; char *fc; unsigned int nalias; + DIRFILE *D; dtrace("%p, %i, %i, %p, %i, %i", alias, *alias_l, *dirfile, field_code, *field_code_l, *num); - DIRFILE* D = _GDF_GetDirfile(*dirfile); + D = _GDF_GetDirfile(*dirfile); _GDF_CString(&fc, field_code, *field_code_l); nalias = gd_naliases(D, fc); @@ -4079,8 +4088,8 @@ GDF_SCIND_F2C(E.scalar_ind[0], *m1_scalar_ind); GDF_SCIND_F2C(E.scalar_ind[0 + GD_MAX_LINCOM], *b1_scalar_ind); - E.m[0] = *m1; - E.b[0] = *b1; + E.EN(lincom,m[0]) = *m1; + E.EN(lincom,b[0]) = *b1; if (n > 1) { _GDF_CString(E.in_fields + 1, in_field2, *in_field2_l); @@ -4089,8 +4098,8 @@ GDF_SCIND_F2C(E.scalar_ind[1], *m2_scalar_ind); GDF_SCIND_F2C(E.scalar_ind[1 + GD_MAX_LINCOM], *b2_scalar_ind); - E.m[1] = *m2; - E.b[1] = *b2; + E.EN(lincom,m[1]) = *m2; + E.EN(lincom,b[1]) = *b2; } if (n > 2) { @@ -4100,8 +4109,8 @@ GDF_SCIND_F2C(E.scalar_ind[2], *m3_scalar_ind); GDF_SCIND_F2C(E.scalar_ind[2 + GD_MAX_LINCOM], *b3_scalar_ind); - E.m[2] = *m3; - E.b[2] = *b3; + E.EN(lincom,m[2]) = *m3; + E.EN(lincom,b[2]) = *b3; } gd_add(_GDF_GetDirfile(*dirfile), &E); @@ -4137,13 +4146,13 @@ dtrace("%i, %p, %i, %i, %p, %i, %g;%g, %p, %i, %i, %g;%g, %p, %i, %i, %p, " "%i, %g;%g, %p, %i, %i, %g;%g, %p, %i, %i, %p, %i, %g;%g, %p, %i, %i, " "%g;%g, %p, %i, %i, %i", *dirfile, field_code, *field_code_l, *n_fields, - in_field1, *in_field1_l, creal(*m1), cimag(*m1), m1_scalar, *m1_scalar_l, - *m1_scalar_ind, creal(*b1), cimag(*b1), b1_scalar, *b1_scalar_l, - *b1_scalar_ind, in_field2, *in_field2_l, creal(*m2), cimag(*m2), - m2_scalar, *m2_scalar_l, *m2_scalar_ind, creal(*b2), cimag(*b2), + in_field1, *in_field1_l, crealp(m1), cimagp(m1), m1_scalar, *m1_scalar_l, + *m1_scalar_ind, crealp(b1), cimagp(b1), b1_scalar, *b1_scalar_l, + *b1_scalar_ind, in_field2, *in_field2_l, crealp(m2), cimagp(m2), + m2_scalar, *m2_scalar_l, *m2_scalar_ind, crealp(b2), cimagp(b2), b2_scalar, *b2_scalar_l, *b2_scalar_ind, in_field3, *in_field3_l, - creal(*m3), cimag(*m3), m3_scalar, *m3_scalar_l, *m3_scalar_ind, - creal(*b3), cimag(*b3), b3_scalar, *b3_scalar_l, *b3_scalar_ind, + crealp(m3), cimagp(m3), m3_scalar, *m3_scalar_l, *m3_scalar_ind, + crealp(b3), cimagp(b3), b3_scalar, *b3_scalar_l, *b3_scalar_ind, *fragment_index); memset(&E, 0, sizeof(E)); @@ -4159,8 +4168,8 @@ GDF_SCIND_F2C(E.scalar_ind[0], *m1_scalar_ind); GDF_SCIND_F2C(E.scalar_ind[0 + GD_MAX_LINCOM], *b1_scalar_ind); - gd_cp2ca_(E.cm, 0, m1); - gd_cp2ca_(E.cb, 0, b1); + gd_cp2cs_(E.EN(lincom,cm)[0], m1); + gd_cp2cs_(E.EN(lincom,cb)[0], b1); if (n > 1) { _GDF_CString(E.in_fields + 1, in_field2, *in_field2_l); @@ -4169,8 +4178,8 @@ GDF_SCIND_F2C(E.scalar_ind[1], *m2_scalar_ind); GDF_SCIND_F2C(E.scalar_ind[1 + GD_MAX_LINCOM], *b2_scalar_ind); - gd_cp2ca_(E.cm, 1, m2); - gd_cp2ca_(E.cb, 1, b2); + gd_cp2cs_(E.EN(lincom,cm)[1], m2); + gd_cp2cs_(E.EN(lincom,cb)[1], b2); } if (n > 2) { @@ -4180,8 +4189,8 @@ GDF_SCIND_F2C(E.scalar_ind[2], *m3_scalar_ind); GDF_SCIND_F2C(E.scalar_ind[2 + GD_MAX_LINCOM], *b3_scalar_ind); - gd_cp2ca_(E.cm, 2, m3); - gd_cp2ca_(E.cb, 2, b3); + gd_cp2cs_(E.EN(lincom,cm)[2], m3); + gd_cp2cs_(E.EN(lincom,cb)[2], b3); } gd_add(_GDF_GetDirfile(*dirfile), &E); @@ -4237,30 +4246,30 @@ case 5: _GDF_CString(E.scalar + 5, a5_scalar, *a5_scalar_l); GDF_SCIND_F2C(E.scalar_ind[5], *a5_scalar_ind); - E.a[5] = *a5; + E.EN(polynom,a[5]) = *a5; /* fallthrough */ case 4: _GDF_CString(E.scalar + 4, a4_scalar, *a4_scalar_l); GDF_SCIND_F2C(E.scalar_ind[4], *a4_scalar_ind); - E.a[4] = *a4; + E.EN(polynom,a[4]) = *a4; /* fallthrough */ case 3: _GDF_CString(E.scalar + 3, a3_scalar, *a3_scalar_l); GDF_SCIND_F2C(E.scalar_ind[3], *a3_scalar_ind); - E.a[3] = *a3; + E.EN(polynom,a[3]) = *a3; /* fallthrough */ case 2: _GDF_CString(E.scalar + 2, a2_scalar, *a2_scalar_l); GDF_SCIND_F2C(E.scalar_ind[2], *a2_scalar_ind); - E.a[2] = *a2; + E.EN(polynom,a[2]) = *a2; /* fallthrough */ default: _GDF_CString(E.scalar + 1, a1_scalar, *a1_scalar_l); GDF_SCIND_F2C(E.scalar_ind[1], *a1_scalar_ind); - E.a[1] = *a1; + E.EN(polynom,a[1]) = *a1; _GDF_CString(E.scalar + 0, a0_scalar, *a0_scalar_l); GDF_SCIND_F2C(E.scalar_ind[0], *a0_scalar_ind); - E.a[0] = *a0; + E.EN(polynom,a[0]) = *a0; } gd_add(_GDF_GetDirfile(*dirfile), &E); @@ -4292,12 +4301,12 @@ dtrace("%i, %p, %i, %i, %p, %i, %g;%g, %p, %i, %i, %g;%g, %p, %i, %i, %g;%g, " "%p, %i, %i, %g;%g, %p, %i, %i, %g;%g, %p, %i, %i, %g;%g, %p, %i, %i, %i", *dirfile, field_code, *field_code_l, *poly_ord, in_field, *in_field_l, - creal(*a0), cimag(*a0), a0_scalar, *a0_scalar_l, *a0_scalar_ind, - creal(*a1), cimag(*a1), a1_scalar, *a1_scalar_l, *a1_scalar_ind, - creal(*a2), cimag(*a2), a2_scalar, *a2_scalar_l, *a2_scalar_ind, - creal(*a3), cimag(*a3), a3_scalar, *a3_scalar_l, *a3_scalar_ind, - creal(*a4), cimag(*a4), a4_scalar, *a4_scalar_l, *a4_scalar_ind, - creal(*a5), cimag(*a5), a5_scalar, *a5_scalar_l, *a5_scalar_ind, + crealp(a0), cimagp(a0), a0_scalar, *a0_scalar_l, *a0_scalar_ind, + crealp(a1), cimagp(a1), a1_scalar, *a1_scalar_l, *a1_scalar_ind, + crealp(a2), cimagp(a2), a2_scalar, *a2_scalar_l, *a2_scalar_ind, + crealp(a3), cimagp(a3), a3_scalar, *a3_scalar_l, *a3_scalar_ind, + crealp(a4), cimagp(a4), a4_scalar, *a4_scalar_l, *a4_scalar_ind, + crealp(a5), cimagp(a5), a5_scalar, *a5_scalar_l, *a5_scalar_ind, *fragment_index); memset(&E, 0, sizeof(E)); @@ -4317,30 +4326,30 @@ case 5: _GDF_CString(E.scalar + 5, a5_scalar, *a5_scalar_l); GDF_SCIND_F2C(E.scalar_ind[5], *a5_scalar_ind); - gd_cp2ca_(E.ca, 5, a5); + gd_cp2cs_(E.EN(polynom,ca)[5], a5); /* fallthrough */ case 4: _GDF_CString(E.scalar + 4, a4_scalar, *a4_scalar_l); GDF_SCIND_F2C(E.scalar_ind[4], *a4_scalar_ind); - gd_cp2ca_(E.ca, 4, a4); + gd_cp2cs_(E.EN(polynom,ca)[4], a4); /* fallthrough */ case 3: _GDF_CString(E.scalar + 3, a3_scalar, *a3_scalar_l); GDF_SCIND_F2C(E.scalar_ind[3], *a3_scalar_ind); - gd_cp2ca_(E.ca, 3, a3); + gd_cp2cs_(E.EN(polynom,ca)[3], a3); /* fallthrough */ case 2: _GDF_CString(E.scalar + 2, a2_scalar, *a2_scalar_l); GDF_SCIND_F2C(E.scalar_ind[2], *a2_scalar_ind); - gd_cp2ca_(E.ca, 2, a2); + gd_cp2cs_(E.EN(polynom,ca)[2], a2); /* fallthrough */ default: _GDF_CString(E.scalar + 1, a1_scalar, *a1_scalar_l); GDF_SCIND_F2C(E.scalar_ind[1], *a1_scalar_ind); - gd_cp2ca_(E.ca, 1, a1); + gd_cp2cs_(E.EN(polynom,ca)[1], a1); _GDF_CString(E.scalar + 0, a0_scalar, *a0_scalar_l); GDF_SCIND_F2C(E.scalar_ind[0], *a0_scalar_ind); - gd_cp2ca_(E.ca, 0, a0); + gd_cp2cs_(E.EN(polynom,ca)[0], a0); } gd_add(_GDF_GetDirfile(*dirfile), &E); @@ -4431,7 +4440,7 @@ _GDF_CString(&E.field, field_code, *field_code_l); _GDF_CString(&E.in_fields[0], in_field, *in_field_l); E.fragment_index = *fragment_index; - gd_li2cs_(E.EN(recip,dividend), dividend[0], dividend[1]); + gd_li2cs_(E.EN(recip,cdividend), dividend[0], dividend[1]); _GDF_CString(E.scalar + 0, dividend_scalar, *dividend_scalar_l); GDF_SCIND_F2C(E.scalar_ind[0], *dividend_scalar_ind); @@ -4464,8 +4473,8 @@ _GDF_CString(&E.in_fields[0], in_field, *in_field_l); _GDF_CString(&E.in_fields[1], check_field, *check_field_l); E.fragment_index = *fragment_index; - E.windop = *windop; - E.threshold = _GDF_SetTriplet(E.windop, threshold); + E.EN(window,windop) = *windop; + E.EN(window,threshold) = _GDF_SetTriplet(E.EN(window,windop), threshold); _GDF_CString(E.scalar + 0, threshold_scalar, *threshold_scalar_l); GDF_SCIND_F2C(E.scalar_ind[0], *threshold_scalar_ind); @@ -4502,8 +4511,8 @@ _GDF_CString(&E.in_fields[0], in_field, *in_field_l); _GDF_CString(&E.in_fields[1], count_field, *count_field_l); E.fragment_index = *fragment_index; - E.count_val = *val; - E.period = *period; + E.EN(mplex,count_val) = *val; + E.EN(mplex,period) = *period; _GDF_CString(E.scalar + 0, val_scalar, *val_scalar_l); GDF_SCIND_F2C(E.scalar_ind[0], *val_scalar_ind); _GDF_CString(E.scalar + 1, period_scalar, *period_scalar_l); @@ -4647,12 +4656,12 @@ dtrace("%i, %p, %i, %i, %p, %i, %g;%g, %p, %i, %i, %g;%g, %p, %i, %i, %g;%g, " "%p, %i, %i, %g;%g, %p, %i, %i, %g;%g, %p, %i, %i, %g;%g, %p, %i, %i", *dirfile, field_code, *field_code_l, *poly_ord, in_field, *in_field_l, - creal(*a0), cimag(*a0), a0_scalar, *a0_scalar_l, *a0_scalar_ind, - creal(*a1), cimag(*a1), a1_scalar, *a1_scalar_l, *a1_scalar_ind, - creal(*a2), cimag(*a2), a2_scalar, *a2_scalar_l, *a2_scalar_ind, - creal(*a3), cimag(*a3), a3_scalar, *a3_scalar_l, *a3_scalar_ind, - creal(*a4), cimag(*a4), a4_scalar, *a4_scalar_l, *a4_scalar_ind, - creal(*a5), cimag(*a5), a5_scalar, *a5_scalar_l, *a5_scalar_ind); + crealp(a0), cimagp(a0), a0_scalar, *a0_scalar_l, *a0_scalar_ind, + crealp(a1), cimagp(a1), a1_scalar, *a1_scalar_l, *a1_scalar_ind, + crealp(a2), cimagp(a2), a2_scalar, *a2_scalar_l, *a2_scalar_ind, + crealp(a3), cimagp(a3), a3_scalar, *a3_scalar_l, *a3_scalar_ind, + crealp(a4), cimagp(a4), a4_scalar, *a4_scalar_l, *a4_scalar_ind, + crealp(a5), cimagp(a5), a5_scalar, *a5_scalar_l, *a5_scalar_ind); memset(&E, 0, sizeof(E)); E.field_type = GD_POLYNOM_ENTRY; @@ -4669,30 +4678,30 @@ case 5: _GDF_CString(E.scalar + 5, a5_scalar, *a5_scalar_l); GDF_SCIND_F2C(E.scalar_ind[5], *a5_scalar_ind); - gd_cp2ca_(E.ca, 5, a5); + gd_cp2cs_(E.EN(polynom,ca)[5], a5); /* fallthrough */ case 4: _GDF_CString(E.scalar + 4, a4_scalar, *a4_scalar_l); GDF_SCIND_F2C(E.scalar_ind[4], *a4_scalar_ind); - gd_cp2ca_(E.ca, 4, a4); + gd_cp2cs_(E.EN(polynom,ca)[4], a4); /* fallthrough */ case 3: _GDF_CString(E.scalar + 3, a3_scalar, *a3_scalar_l); GDF_SCIND_F2C(E.scalar_ind[3], *a3_scalar_ind); - gd_cp2ca_(E.ca, 3, a3); + gd_cp2cs_(E.EN(polynom,ca)[3], a3); /* fallthrough */ case 2: _GDF_CString(E.scalar + 2, a2_scalar, *a2_scalar_l); GDF_SCIND_F2C(E.scalar_ind[2], *a2_scalar_ind); - gd_cp2ca_(E.ca, 2, a2); + gd_cp2cs_(E.EN(polynom,ca)[2], a2); /* fallthrough */ default: _GDF_CString(E.scalar + 1, a1_scalar, *a1_scalar_l); GDF_SCIND_F2C(E.scalar_ind[1], *a1_scalar_ind); - gd_cp2ca_(E.ca, 1, a1); + gd_cp2cs_(E.EN(polynom,ca)[1], a1); _GDF_CString(E.scalar + 0, a0_scalar, *a0_scalar_l); GDF_SCIND_F2C(E.scalar_ind[0], *a0_scalar_ind); - gd_cp2ca_(E.ca, 0, a0); + gd_cp2cs_(E.EN(polynom,ca)[0], a0); } gd_alter_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, @@ -4725,8 +4734,8 @@ E.field_type = GD_WINDOW_ENTRY; _GDF_CString(&E.in_fields[0], in_field, *in_field_l); _GDF_CString(&E.in_fields[1], check_field, *check_field_l); - E.windop = *windop; - E.threshold = _GDF_SetTriplet(E.windop, threshold); + E.EN(window,windop) = *windop; + E.EN(window,threshold) = _GDF_SetTriplet(E.EN(window,windop), threshold); _GDF_CString(E.scalar + 0, threshold_scalar, *threshold_scalar_l); GDF_SCIND_F2C(E.scalar_ind[0], *threshold_scalar_ind); @@ -4937,8 +4946,8 @@ GDF_SCIND_F2C(E.scalar_ind[0], *m1_scalar_ind); GDF_SCIND_F2C(E.scalar_ind[0 + GD_MAX_LINCOM], *b1_scalar_ind); - E.m[0] = *m1; - E.b[0] = *b1; + E.EN(lincom,m[0]) = *m1; + E.EN(lincom,b[0]) = *b1; if (n > 1) { _GDF_CString(E.in_fields + 1, in_field2, *in_field2_l); @@ -4947,8 +4956,8 @@ GDF_SCIND_F2C(E.scalar_ind[1], *m2_scalar_ind); GDF_SCIND_F2C(E.scalar_ind[1 + GD_MAX_LINCOM], *b2_scalar_ind); - E.m[1] = *m2; - E.b[1] = *b2; + E.EN(lincom,m[1]) = *m2; + E.EN(lincom,b[1]) = *b2; } if (n > 2) { @@ -4958,8 +4967,8 @@ GDF_SCIND_F2C(E.scalar_ind[2], *m3_scalar_ind); GDF_SCIND_F2C(E.scalar_ind[2 + GD_MAX_LINCOM], *b3_scalar_ind); - E.m[2] = *m3; - E.b[2] = *b3; + E.EN(lincom,m[2]) = *m3; + E.EN(lincom,b[2]) = *b3; } gd_alter_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, @@ -4997,13 +5006,13 @@ dtrace("%i, %p, %i, %i, %p, %i, %g;%g, %p, %i, %i, %g;%g, %p, %i, %i, %p, " "%i, %g;%g, %p, %i, %i, %g;%g, %p, %i, %i, %p, %i, %g;%g, %p, %i, %i, " "%g;%g, %p, %i, %i", *dirfile, field_code, *field_code_l, *n_fields, - in_field1, *in_field1_l, creal(*m1), cimag(*m1), m1_scalar, *m1_scalar_l, - *m1_scalar_ind, creal(*b1), cimag(*b1), b1_scalar, *b1_scalar_l, - *b1_scalar_ind, in_field2, *in_field2_l, creal(*m2), cimag(*m2), - m2_scalar, *m2_scalar_l, *m2_scalar_ind, creal(*b2), cimag(*b2), + in_field1, *in_field1_l, crealp(m1), cimagp(m1), m1_scalar, *m1_scalar_l, + *m1_scalar_ind, crealp(b1), cimagp(b1), b1_scalar, *b1_scalar_l, + *b1_scalar_ind, in_field2, *in_field2_l, crealp(m2), cimagp(m2), + m2_scalar, *m2_scalar_l, *m2_scalar_ind, crealp(b2), cimagp(b2), b2_scalar, *b2_scalar_l, *b2_scalar_ind, in_field3, *in_field3_l, - creal(*m3), cimag(*m3), m3_scalar, *m3_scalar_l, *m3_scalar_ind, - creal(*b3), cimag(*b3), b3_scalar, *b3_scalar_l, *b3_scalar_ind); + crealp(m3), cimagp(m3), m3_scalar, *m3_scalar_l, *m3_scalar_ind, + crealp(b3), cimagp(b3), b3_scalar, *b3_scalar_l, *b3_scalar_ind); memset(&E, 0, sizeof(E)); E.field_type = GD_LINCOM_ENTRY; @@ -5016,8 +5025,8 @@ GDF_SCIND_F2C(E.scalar_ind[0], *m1_scalar_ind); GDF_SCIND_F2C(E.scalar_ind[0 + GD_MAX_LINCOM], *b1_scalar_ind); - gd_cp2ca_(E.cm, 0, m1); - gd_cp2ca_(E.cb, 0, b1); + gd_cp2cs_(E.EN(lincom,cm)[0], m1); + gd_cp2cs_(E.EN(lincom,cb)[0], b1); if (n > 1) { _GDF_CString(E.in_fields + 1, in_field2, *in_field2_l); @@ -5026,8 +5035,8 @@ GDF_SCIND_F2C(E.scalar_ind[1], *m2_scalar_ind); GDF_SCIND_F2C(E.scalar_ind[1 + GD_MAX_LINCOM], *b2_scalar_ind); - gd_cp2ca_(E.cm, 1, m2); - gd_cp2ca_(E.cb, 1, b2); + gd_cp2cs_(E.EN(lincom,cm)[1], m2); + gd_cp2cs_(E.EN(lincom,cb)[1], b2); } if (n > 2) { @@ -5037,8 +5046,8 @@ GDF_SCIND_F2C(E.scalar_ind[2], *m3_scalar_ind); GDF_SCIND_F2C(E.scalar_ind[2 + GD_MAX_LINCOM], *b3_scalar_ind); - gd_cp2ca_(E.cm, 2, m3); - gd_cp2ca_(E.cb, 2, b3); + gd_cp2cs_(E.EN(lincom,cm)[2], m3); + gd_cp2cs_(E.EN(lincom,cb)[2], b3); } gd_alter_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, @@ -5163,8 +5172,8 @@ E.field_type = GD_MPLEX_ENTRY; _GDF_CString(&E.in_fields[0], in_field, *in_field_l); _GDF_CString(&E.in_fields[1], count_field, *count_field_l); - E.count_val = *val; - E.period = *period; + E.EN(mplex,count_val) = *val; + E.EN(mplex,period) = *period; _GDF_CString(E.scalar + 0, val_scalar, *val_scalar_l); GDF_SCIND_F2C(E.scalar_ind[0], *val_scalar_ind); _GDF_CString(E.scalar + 1, period_scalar, *period_scalar_l); Modified: trunk/getdata/bindings/perl/GetData.xs =================================================================== --- trunk/getdata/bindings/perl/GetData.xs 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/bindings/perl/GetData.xs 2013-12-12 03:33:54 UTC (rev 872) @@ -1359,7 +1359,8 @@ GDP_PUSHrvavcmp(E.EN(lincom,cm), E.EN(lincom,n_fields)); GDP_PUSHpvn("b"); GDP_PUSHrvavcmp(E.EN(lincom,cb), E.EN(lincom,n_fields)); - sp = gdp_store_scalars(sp, &E, ((1 << E.EN(lincom,n_fields)) - 1) * 9); + sp = gdp_store_scalars(sp, &E, + ((1 << E.EN(lincom,n_fields)) - 1) * 9); break; case GD_LINTERP_ENTRY: GDP_PUSHpvn("in_fields"); Modified: trunk/getdata/configure.ac =================================================================== --- trunk/getdata/configure.ac 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/configure.ac 2013-12-12 03:33:54 UTC (rev 872) @@ -929,11 +929,20 @@ fi fi -dnl matlab +dnl php if test "x$make_phpbindings" = "xyes"; then echo echo "*** Configuring PHP bindings" echo + AC_MSG_CHECKING([whether C99 is supported]) + if test "x$disable_c99" = "xno"; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + make_phpbindings=no + fi +fi +if test "x$make_phpbindings" = "xyes"; then GD_PHP if test "x$have_php" = "xno"; then make_phpbindings=no Modified: trunk/getdata/src/common.c =================================================================== --- trunk/getdata/src/common.c 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/src/common.c 2013-12-12 03:33:54 UTC (rev 872) @@ -764,7 +764,7 @@ for (i = 0; i < n_read; i++) { \ const t d = ((t *)data)[2 * i] * ((t *)data)[2 * i] + \ ((t *)data)[2 * i + 1] * ((t *)data)[2 * i + 1]; \ - ((t *)data)[2 * i] = (t)((dividend[0] * ((t *)data)[2 * i] - \ + ((t *)data)[2 * i] = (t)((dividend[0] * ((t *)data)[2 * i] + \ dividend[1] * ((t *)data)[2 * i + 1]) / d); \ ((t *)data)[2 * i + 1] = (t)((dividend[1] * ((t *)data)[2 * i] - \ dividend[0] * ((t *)data)[2 * i]) / d); \ Modified: trunk/getdata/src/entry.c =================================================================== --- trunk/getdata/src/entry.c 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/src/entry.c 2013-12-12 03:33:54 UTC (rev 872) @@ -209,21 +209,24 @@ /* resolve non-literal scalars */ int _GD_CalculateEntry(DIRFILE *restrict D, gd_entry_t *restrict E, int err) { - int i, cs = 0; + int i, e = 0, cs = 0; dtrace("%p, %p, %i", D, E, err); switch(E->field_type) { case GD_RAW_ENTRY: - _GD_GetScalar(D, E, 0, GD_UINT_TYPE, &E->EN(raw,spf), err); + e = _GD_GetScalar(D, E, 0, GD_UINT_TYPE, &E->EN(raw,spf), err); break; case GD_POLYNOM_ENTRY: for (i = 0; i <= E->EN(polynom,poly_ord); ++i) { - _GD_GetScalar(D, E, i, GD_COMPLEX128, &E->EN(polynom,ca)[i], err); - E->EN(polynom,a)[i] = creal(E->EN(polynom,ca)[i]); + if (_GD_GetScalar(D, E, i, GD_COMPLEX128, &E->EN(polynom,ca)[i], err)) + e = 1; + else { + E->EN(polynom,a)[i] = creal(E->EN(polynom,ca)[i]); - if (!cs && cimag(E->EN(polynom,ca)[i])) - cs = 1; + if (!cs && cimag(E->EN(polynom,ca)[i])) + cs = 1; + } if (D->error) break; @@ -231,55 +234,67 @@ break; case GD_LINCOM_ENTRY: for (i = 0; i < E->EN(lincom,n_fields); ++i) { - _GD_GetScalar(D, E, i, GD_COMPLEX128, &E->EN(lincom,cm)[i], err); - E->EN(lincom,m)[i] = creal(E->EN(lincom,cm)[i]); + if (_GD_GetScalar(D, E, i, GD_COMPLEX128, &E->EN(lincom,cm)[i], err)) + e = 1; + else { + E->EN(lincom,m)[i] = creal(E->EN(lincom,cm)[i]); - if (!cs && cimag(E->EN(lincom,cm)[i])) - cs = 1; + if (!cs && cimag(E->EN(lincom,cm)[i])) + cs = 1; + } - _GD_GetScalar(D, E, i + GD_MAX_LINCOM, GD_COMPLEX128, - &E->EN(lincom,cb)[i], err); - E->EN(lincom,b)[i] = creal(E->EN(lincom,cb)[i]); + if (_GD_GetScalar(D, E, i + GD_MAX_LINCOM, GD_COMPLEX128, + &E->EN(lincom,cb)[i], err)) + { + e = 1; + } else { + E->EN(lincom,b)[i] = creal(E->EN(lincom,cb)[i]); - if (!cs && cimag(E->EN(lincom,cb)[i])) - cs = 1; + if (!cs && cimag(E->EN(lincom,cb)[i])) + cs = 1; + } if (D->error) break; } break; case GD_RECIP_ENTRY: - _GD_GetScalar(D, E, 0, GD_COMPLEX128, &E->EN(recip,cdividend), err); - E->EN(recip,dividend) = creal(E->EN(recip,cdividend)); - if (cimag(E->EN(recip,cdividend))) - cs = 1; + if (_GD_GetScalar(D, E, 0, GD_COMPLEX128, &E->EN(recip,cdividend), err)) + e = 1; + else { + E->EN(recip,dividend) = creal(E->EN(recip,cdividend)); + if (cimag(E->EN(recip,cdividend))) + cs = 1; + } break; case GD_BIT_ENTRY: case GD_SBIT_ENTRY: - _GD_GetScalar(D, E, 0, GD_INT_TYPE, &E->EN(bit,bitnum), err); - _GD_GetScalar(D, E, 1, GD_INT_TYPE, &E->EN(bit,numbits), err); + e = _GD_GetScalar(D, E, 0, GD_INT_TYPE, &E->EN(bit,bitnum), err); + e |= _GD_GetScalar(D, E, 1, GD_INT_TYPE, &E->EN(bit,numbits), err); break; case GD_PHASE_ENTRY: - _GD_GetScalar(D, E, 0, GD_INT64, &E->EN(phase,shift), err); + e = _GD_GetScalar(D, E, 0, GD_INT64, &E->EN(phase,shift), err); break; case GD_WINDOW_ENTRY: switch (E->EN(window,windop)) { case GD_WINDOP_EQ: case GD_WINDOP_NE: - _GD_GetScalar(D, E, 0, GD_INT64, &E->EN(window,threshold.i), err); + e = _GD_GetScalar(D, E, 0, GD_INT64, &E->EN(window,threshold.i), err); break; case GD_WINDOP_SET: case GD_WINDOP_CLR: - _GD_GetScalar(D, E, 0, GD_UINT64, &E->EN(window,threshold.u), err); + e = _GD_GetScalar(D, E, 0, GD_UINT64, &E->EN(window,threshold.u), + err); break; default: - _GD_GetScalar(D, E, 0, GD_FLOAT64, &E->EN(window,threshold.r), err); + e = _GD_GetScalar(D, E, 0, GD_FLOAT64, &E->EN(window,threshold.r), + err); break; } break; case GD_MPLEX_ENTRY: - _GD_GetScalar(D, E, 0, GD_INT_TYPE, &E->EN(mplex,count_val), err); - _GD_GetScalar(D, E, 1, GD_INT_TYPE, &E->EN(mplex,period), err); + e = _GD_GetScalar(D, E, 0, GD_INT_TYPE, &E->EN(mplex,count_val), err); + e |= _GD_GetScalar(D, E, 1, GD_INT_TYPE, &E->EN(mplex,period), err); break; case GD_NO_ENTRY: case GD_LINTERP_ENTRY: @@ -293,7 +308,7 @@ break; } - if (!D->error) + if (!e) E->flags |= GD_EN_CALC; if (cs) @@ -301,8 +316,8 @@ else E->flags &= ~GD_EN_COMPSCAL; - dreturn("%i", (E->flags & GD_EN_CALC) ? 1 : 0); - return (E->flags & GD_EN_CALC) ? 1 : 0; + dreturn("%i", !e); + return !e; } char* gd_raw_filename(DIRFILE* D, const char* field_code_in) gd_nothrow Modified: trunk/getdata/src/getdata.c =================================================================== --- trunk/getdata/src/getdata.c 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/src/getdata.c 2013-12-12 03:33:54 UTC (rev 872) @@ -386,12 +386,90 @@ #ifdef GD_NO_C99_API #define POLYNOMC(t) \ switch (n) { \ - case 2: POLYNOM2(t,2 * npts); break; \ - case 3: POLYNOM3(t,2 * npts); break; \ - case 4: POLYNOM4(t,2 * npts); break; \ - case 5: POLYNOM5(t,2 * npts); break; \ + case 2: POLYNOMC2(t,npts); break; \ + case 3: POLYNOMC3(t,npts); break; \ + case 4: POLYNOMC4(t,npts); break; \ + case 5: POLYNOMC5(t,npts); break; \ default: _GD_InternalError(D); \ } + +#define POLYNOMC5(t,npts) \ + do { \ + for (i = 0; i < npts; i++) { \ + const double x = ((t*)data)[2 * i]; \ + const double x2 = x * x; \ + const double x3 = x2 * x; \ + const double x4 = x3 * x; \ + const double x5 = x4 * x; \ + const double y = ((t*)data)[2 * i + 1]; \ + const double y2 = y * y; \ + const double y3 = y2 * y; \ + const double y4 = y3 * y; \ + const double y5 = y4 * y; \ + ((t*)data)[2 * i] = (t)( \ + a[5] * (x5 - 10 * x3 * y2 + 5 * x * y4) \ + - a[4] * (x4 - 6 * x2 * y2 + y4) - a[3] * (x3 - 3 * x * y2) \ + + a[2] * (x2 - y2) + a[1] * x + a[0] \ + ); \ + ((t*)data)[2 * i + 1] = (t)( \ + a[5] * (5 * x4 * y - 10 * x3 * y2 + y5) \ + + a[4] * (4 * x3 * y - 4 * x * y3) + a[3] * (3 * x2 * y - y3) \ + + a[2] * 2 * x * y + a[1] * y \ + ); \ + } \ + } while (0) + +#define POLYNOMC4(t,npts) \ + do { \ + for (i = 0; i < npts; i++) { \ + const double x = ((t*)data)[2 * i]; \ + const double x2 = x * x; \ + const double x3 = x2 * x; \ + const double x4 = x3 * x; \ + const double y = ((t*)data)[2 * i + 1]; \ + const double y2 = y * y; \ + const double y3 = y2 * y; \ + const double y4 = y3 * y; \ + ((t*)data)[2 * i] = (t)( \ + a[4] * (x4 - 6 * x2 * y2 + y4) + a[3] * (x3 - 3 * x * y2) \ + + a[2] * (x2 - y2) + a[1] * x + a[0] \ + ); \ + ((t*)data)[2 * i + 1] = (t)( \ + a[4] * (4 * x3 * y - 4 * x * y3) + a[3] * (3 * x2 * y - y3) \ + + a[2] * 2 * x * y + a[1] * y \ + ); \ + } \ + } while (0) + +#define POLYNOMC3(t,npts) \ + do { \ + for (i = 0; i < npts; i++) { \ + const double x = ((t*)data)[2 * i]; \ + const double x2 = x * x; \ + const double x3 = x2 * x; \ + const double y = ((t*)data)[2 * i + 1]; \ + const double y2 = y * y; \ + const double y3 = y2 * y; \ + ((t*)data)[2 * i] = (t)( \ + a[3] * (x3 - 3 * x * y2) + a[2] * (x2 - y2) + a[1] * x + a[0] \ + ); \ + ((t*)data)[2 * i + 1] = (t)( \ + a[3] * (3 * x2 * y - y3) + a[2] * 2 * x * y + a[1] * y \ + ); \ + } \ + } while (0) + +#define POLYNOMC2(t,npts) \ + do { \ + for (i = 0; i < npts; i++) { \ + const double x = ((t*)data)[2 * i]; \ + const double x2 = x * x; \ + const double y = ((t*)data)[2 * i + 1]; \ + const double y2 = y * y; \ + ((t*)data)[2 * i] = (t)(a[2] * (x2 - y2) + a[1] * x + a[0]); \ + ((t*)data)[2 * i + 1] = (t)(a[2] * 2 * x * y + a[1] * y); \ + } \ + } while (0) #else #define POLYNOMC(t) POLYNOM(complex t) #endif @@ -442,7 +520,11 @@ } #ifdef GD_NO_C99_API -#undef POLYNOMC +#undef POLYNOMC5 +#undef POLYNOMC4 +#undef POLYNOMC3 +#undef POLYNOMC2 +#undef POLYNOMC1 #define POLYNOMC5(t,npts) \ do { \ @@ -545,15 +627,6 @@ ); \ } \ } while (0) - -#define POLYNOMC(t) \ - switch (n) { \ - case 2: POLYNOMC2(t,npts); break; \ - case 3: POLYNOMC3(t,npts); break; \ - case 4: POLYNOMC4(t,npts); break; \ - case 5: POLYNOMC5(t,npts); break; \ - default: _GD_InternalError(D); \ - } #endif @@ -743,9 +816,9 @@ const int i2 = 2 * (i * spfB / spfA); \ const t x = ((t*)A)[2 * i]; \ const t y = ((t*)A)[2 * i + 1]; \ - const double d = B[i2] * B[i2] - B[i2 + 1] * B[i2 + 1]; \ + const double d = B[i2] * B[i2] + B[i2 + 1] * B[i2 + 1]; \ ((t*)A)[2 * i] = (t)((x * B[i2] + y * B[i2 + 1]) / d); \ - ((t*)A)[2 * i + 1] = (t)((x * B[i2] - y * B[i2 + 1]) / d); \ + ((t*)A)[2 * i + 1] = (t)((y * B[i2] - x * B[i2 + 1]) / d); \ } \ } while (0) Modified: trunk/getdata/src/internal.h =================================================================== --- trunk/getdata/src/internal.h 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/src/internal.h 2013-12-12 03:33:54 UTC (rev 872) @@ -155,13 +155,15 @@ /* imaginary part of (*z) */ # define cimagp(z) cimag(z) /* a pointer to element i of GD_DCOMPLEXP_t array a */ -# define gd_cap_(a,i) ((GD_DCOMPLEXP_t)(a + 2 * i)) +# define gd_cap_(a,i) (((GD_DCOMPLEXP_t)(a)) + 2 * i) /* a pointer to a complex scalar */ # define gd_csp_(a) ((GD_DCOMPLEXP_t)a) /* assign real two-element array b to scalar a */ # define gd_ra2cs_(a,b) gd_cs2cs_(a,b) /* assign scalar b to scalar a */ # define gd_cs2cs_(a,b) do { (a)[0] = (b)[0]; (a)[1] = (b)[1]; } while(0) +/* assign scalar *b to scalar a */ +# define gd_cp2cs_(a,b) gd_cs2cs_(a,b) /* assign scalar b to scalar (*a) */ # define gd_cs2cp_(a,b) gd_cs2cs_(a,b) /* assign b[i] to scalar a */ @@ -206,15 +208,16 @@ # define gd_csp_(a) (&(a)) # define gd_ra2cs_(a,b) a = *((double complex*)(b)) # define gd_cs2cs_(a,b) a = b -# define gd_cs2cp_(a,b) *a = b +# define gd_cp2cs_(a,b) a = *(b) +# define gd_cs2cp_(a,b) *(a) = b # define gd_ca2cs_(a,b,i) a = b[i] # define gd_cp2ca_(a,i,b) (a)[i] = *(b) # define gd_li2cs_(a,x,y) a = (x + _Complex_I * y) -# define gd_li2cp_(a,x,y) *a = (x + _Complex_I * y) +# define gd_li2cp_(a,x,y) *(a) = (x + _Complex_I * y) # define gd_po2cs_(a,r,p) a = (r) * cexp(p) -# define gd_po2cp_(a,r,p) *a = (r) * cexp(p) +# define gd_po2cp_(a,r,p) *(a) = (r) * cexp(p) # define gd_rs2cs_(a,b) a = b -# define gd_rs2cp_(a,b) *a = b +# define gd_rs2cp_(a,b) *(a) = b # define gd_cs2ca_(a,i,b,t) ((complex t*)a)[i] = (complex t)(b) # define gd_rs2ca_(a,i,b,t) gd_cs2ca_(a,i,b,t) # define gd_ccmpl_(a,x,y) (a == (x + _Complex_I * y)) Modified: trunk/getdata/src/mod.c =================================================================== --- trunk/getdata/src/mod.c 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/src/mod.c 2013-12-12 03:33:54 UTC (rev 872) @@ -123,7 +123,7 @@ if (D->error) r |= GD_AS_ERROR; - dreturn("%i", r); + dreturn("0x%X", r); return r; } Modified: trunk/getdata/src/name.c =================================================================== --- trunk/getdata/src/name.c 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/src/name.c 2013-12-12 03:33:54 UTC (rev 872) @@ -428,8 +428,6 @@ unsigned u; int i; - dtrace("%p, %p, %i", D, rdat, perform); - /* look for meta fields */ const int search_meta = (rdat->E->e->n_meta != -1); @@ -447,6 +445,8 @@ const int amode = (update_aliases ? GD_UPDU : 0) | (perform ? 0 : GD_UPDI); + dtrace("%p, %p, %i", D, rdat, perform); + /* reset the code count */ rdat->n_code = 0; @@ -454,7 +454,7 @@ if (update_vectors) switch (D->entry[u]->field_type) { case GD_LINCOM_ENTRY: - for (i = 0; i < D->entry[u]->n_fields; ++i) { + for (i = 0; i < D->entry[u]->EN(lincom,n_fields); ++i) { if (_GD_UpdateInField(D, D->entry[u], rdat, i, search_meta, mode)) { dreturn("%i", -1); return -1; Modified: trunk/getdata/test/alter_clincom.c =================================================================== --- trunk/getdata/test/alter_clincom.c 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/test/alter_clincom.c 2013-12-12 03:33:54 UTC (rev 872) @@ -68,7 +68,7 @@ gd_entry(D, "lincom", &E); CHECKX(E.flags, GD_EN_COMPSCAL | GD_EN_CALC); - CHECKI(E.n_fields, 2); + CHECKI(E.EN(lincom,n_fields), 2); #ifdef GD_NO_C99_API CHECKC(E.EN(lincom,cm)[0], m); CHECKC(E.EN(lincom,cm)[1], m + 2); Modified: trunk/getdata/test/alter_cpolynom_null.c =================================================================== --- trunk/getdata/test/alter_cpolynom_null.c 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/test/alter_cpolynom_null.c 2013-12-12 03:33:54 UTC (rev 872) @@ -38,7 +38,7 @@ "polynom POLYNOM data 1;2 2;3 1;9\n"; int fd, i, ret, error, n, error2, r = 0; gd_entry_t E; -#ifdef GD_NO_C89_API +#ifdef GD_NO_C99_API const double a[2][2] = {{1, 2}, {2, 3}}; #endif DIRFILE *D; Modified: trunk/getdata/test/alter_entry_recode_recalc.c =================================================================== --- trunk/getdata/test/alter_entry_recode_recalc.c 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/test/alter_entry_recode_recalc.c 2013-12-12 03:33:54 UTC (rev 872) @@ -70,6 +70,9 @@ ret = gd_alter_entry(D, "data", &E, 1); error = gd_error(D); n = gd_nframes(D); + CHECKI(error, 0); + CHECKI(n, 32); + CHECKI(ret, 0); gd_discard(D); @@ -87,13 +90,9 @@ r = 1; } -// unlink(data); + unlink(data); unlink(format); rmdir(filedir); - CHECKI(error, 0); - CHECKI(n, 32); - CHECKI(ret, 0); - return r; } Modified: trunk/getdata/test/alter_entry_scalar1.c =================================================================== --- trunk/getdata/test/alter_entry_scalar1.c 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/test/alter_entry_scalar1.c 2013-12-12 03:33:54 UTC (rev 872) @@ -48,8 +48,8 @@ memset(&E, 0, sizeof(E)); E.field_type = GD_BIT_ENTRY; - E.bitnum = 4; - E.numbits = 3; + E.EN(bit,bitnum) = 4; + E.EN(bit,numbits) = 3; E.in_fields[0] = "in"; E.scalar[0] = ""; Modified: trunk/getdata/test/alter_entry_scalar3c.c =================================================================== --- trunk/getdata/test/alter_entry_scalar3c.c 2013-12-11 22:35:43 UTC (rev 871) +++ trunk/getdata/test/alter_entry_scalar3c.c 2013-12-12 03:33:54 UTC (rev 872) @@ -48,8 +48,8 @@ memset(&E, 0, sizeof(E)); E.field_type = GD_BIT_ENTRY; - E.bitnum = -1; - E.numbits = 3; + E.EN(bit,bitnum) = -1; + E.EN(bit,numbits) = 3; E.in_fields[0] = "in"; ret = gd_alter_entry(D, "data", &E, 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2013-12-17 02:04:56
|
Revision: 874 http://sourceforge.net/p/getdata/code/874 Author: ketiltrout Date: 2013-12-17 02:04:49 +0000 (Tue, 17 Dec 2013) Log Message: ----------- Perform all the endianness-correction detection logic in one place (_GD_CheckByteSex) instead of duplicating it all over the place; unrelated doc updates. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/man/gd_add_bit.3 trunk/getdata/man/gd_alter_bit.3 trunk/getdata/src/add.c trunk/getdata/src/encoding.c trunk/getdata/src/endian.c trunk/getdata/src/flimits.c trunk/getdata/src/fpos.c trunk/getdata/src/getdata.c trunk/getdata/src/internal.h trunk/getdata/src/mod.c trunk/getdata/src/move.c trunk/getdata/src/nframes.c trunk/getdata/src/parse.c trunk/getdata/src/putdata.c Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/ChangeLog 2013-12-17 02:04:49 UTC (rev 874) @@ -1,3 +1,13 @@ +2013-12-12 D. V. Wiebe <ge...@ke...> svn:874 + * src/endian.c (_GD_CheckByteSex): Added. + * src/endian.c (_GD_FileSwapBytes): Added (replacing macro in internal.h). + * src/endian.c (_GD_FixEndianness): Call _GD_CheckByteSex() to check wether + correction is needed. + + * src/getdata.c (_GD_DoRaw) src/move.c (_GD_MogrifyFile) src/putdata.c + (_GD_DoRawOut): Let _GD_FixEndianness and _GD_CheckByteSex do the endianness + logic. + 2013-12-12 D. V. Wiebe <ge...@ke...> svn:872 * configure.ac: Disable PHP bindings if we don't have a C99 compiler. Modified: trunk/getdata/man/gd_add_bit.3 =================================================================== --- trunk/getdata/man/gd_add_bit.3 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/man/gd_add_bit.3 2013-12-17 02:04:49 UTC (rev 874) @@ -311,7 +311,7 @@ is 2**24. It is larger on a 64-bit system. The C89 GetData API provides different prototypes for -.BR gd_add_clincom ()", " gd_add_cpolynom (), +.BR gd_add_clincom "(), " gd_add_cpolynom (), and .BR gd_add_crecip (): .PP @@ -331,7 +331,7 @@ .BI int " fragment_index ); .HP .BI "int gd_add_crecip(DIRFILE *" dirfile ", const char *" field_name , -.BI "const char *" in_field ", double " cdividend [2], +.BI "const char *" in_field ", const double " cdividend [2], .BI "int " fragment_index ); .hy .ad n Modified: trunk/getdata/man/gd_alter_bit.3 =================================================================== --- trunk/getdata/man/gd_alter_bit.3 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/man/gd_alter_bit.3 2013-12-17 02:04:49 UTC (rev 874) @@ -302,7 +302,7 @@ .BI "int " poly_ord ", const char *" in_fields ", const double *" ca ); .HP .BI "int gd_alter_crecip(DIRFILE *" dirfile ", const char *" field_code , -.BI "const char *" in_field ", double " cdividend [2]); +.BI "const char *" in_field ", const double " cdividend [2]); .hy .ad n .PP @@ -337,7 +337,10 @@ .BR gd_alter_crecip () is always available, and may be accessed as .BR gd_alter_crecip89 (), -with the C89 prototype, in both the C99 and C89 APIs. +with the C89 prototype, in both the C99 and C89 APIs. Passing NULL as +.I cdividend +is equivalent to specifying a dividend of zero: it indicates no change to the +dividend parameter. .SH SEE ALSO .BR gd_alter_entry (3), Modified: trunk/getdata/src/add.c =================================================================== --- trunk/getdata/src/add.c 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/src/add.c 2013-12-17 02:04:49 UTC (rev 874) @@ -298,8 +298,7 @@ GD_SIZE(E->EN(raw,data_type))) == 0) _GD_SetError(D, GD_E_BAD_TYPE, entry->EN(raw,data_type), NULL, 0, NULL); else if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, - GD_FILE_WRITE | GD_FILE_TOUCH, - _GD_FileSwapBytes(D, E->fragment_index))) + GD_FILE_WRITE | GD_FILE_TOUCH, _GD_FileSwapBytes(D, E))) { ; } else if (D->fragment[E->fragment_index].ref_name == NULL) { Modified: trunk/getdata/src/encoding.c =================================================================== --- trunk/getdata/src/encoding.c 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/src/encoding.c 2013-12-17 02:04:49 UTC (rev 874) @@ -36,6 +36,7 @@ NULL #define GD_EF_GENERIC_SET &_GD_GenericName, NULL, NULL, NULL, NULL, NULL, \ NULL, NULL, &_GD_GenericMove, &_GD_GenericUnlink + #ifdef USE_MODULES #define GD_EXT_ENCODING_NULL(sc,ex,ec,af,ff) \ { sc,ex,ec,af,ff,GD_EF_PROVIDES,GD_EF_NULL_SET } Modified: trunk/getdata/src/endian.c =================================================================== --- trunk/getdata/src/endian.c 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/src/endian.c 2013-12-17 02:04:49 UTC (rev 874) @@ -63,7 +63,7 @@ break; /* if the field's data type is one byte long, and no in-framework - * byte-swapping is required, do nothing */ + * byte-swapping is performed, do nothing */ if (D->entry[i]->e->u.raw.size == 1 && !(gd_ef_[D->entry[i]->e->u.raw.file[0].subenc].flags & GD_EF_SWAP)) continue; @@ -174,40 +174,164 @@ return D->fragment[fragment].byte_sex; } -void _GD_ArmEndianise(uint64_t* databuffer, int is_complex, size_t ns) +static void _GD_ArmEndianise(uint64_t* databuffer, size_t ns) { uint64_t *p; - dtrace("%p, %i, %zi", databuffer, is_complex, ns); + dtrace("%p, %zi", databuffer, ns); - if (is_complex) - ns *= 2; - for (p = databuffer; p < databuffer + ns; ++p) *p = ((*p & 0xffffffff) << 32) | ((*p & 0xffffffff00000000ULL) >> 32); dreturnvoid(); } -void _GD_FixEndianness(void* databuffer, size_t size, size_t ns) +/* determine byte sex flags for the machine endianness */ +#ifdef FLOATS_BIGENDIAN +#define GD_FLOAT_SEX GD_BIG_ENDIAN +#else +#define GD_FLOAT_SEX GD_LITTLE_ENDIAN +#endif + +#ifdef WORDS_BIGENDIAN +#define GD_INT_SEX GD_BIG_ENDIAN +#else +#define GD_INT_SEX GD_LITTLE_ENDIAN +#endif + +/* returns non-zero if sex1 and sex2 imply byte sex correction is required, and + * sets *arm_fix if middle-ended double correction is needed; returns + */ +int _GD_CheckByteSex(gd_type_t type, unsigned sex1, unsigned sex2, + int skip_bytes, int *restrict arm_fix) { + int endian_fix = 0; + + dtrace("0x%X, 0x%X, 0x%X, %p", type, sex1, sex2, arm_fix); + + /* the trivial case */ + if (GD_SIZE(type) < 1 || (skip_bytes && GD_SIZE(type) == 1)) { + if (arm_fix) + *arm_fix = 0; + dreturn("%i/%i", 0, 0); + return 0; + } + + /* ensure we have exactly one of GD_BIG_ENDIAN or GD_LITTLE_ENDIAN set in + * both bitfields */ + if (type & (GD_IEEE754 | GD_COMPLEX)) { + /* arm check */ + if (arm_fix) { + if (type == GD_FLOAT64 || type == GD_COMPLEX128) + *arm_fix = ((sex1 & GD_ARM_FLAG) != (sex2 & GD_ARM_FLAG)); + else + *arm_fix = 0; + } + + switch (sex1 & (GD_LITTLE_ENDIAN | GD_BIG_ENDIAN)) { + case 0: + sex1 |= GD_FLOAT_SEX; + break; + case GD_LITTLE_ENDIAN | GD_BIG_ENDIAN: + sex1 &= ~GD_FLOAT_SEX; + break; + default: + break; /* bits are okay */ + } + switch (sex2 & (GD_LITTLE_ENDIAN | GD_BIG_ENDIAN)) { + case 0: + sex2 |= GD_FLOAT_SEX; + break; + case GD_LITTLE_ENDIAN | GD_BIG_ENDIAN: + sex2 &= ~GD_FLOAT_SEX; + break; + default: + break; /* bits are okay */ + } + } else { + if (arm_fix) + *arm_fix = 0; + + switch (sex1 & (GD_LITTLE_ENDIAN | GD_BIG_ENDIAN)) { + case 0: + sex1 |= GD_INT_SEX; + break; + case GD_LITTLE_ENDIAN | GD_BIG_ENDIAN: + sex1 &= ~GD_INT_SEX; + break; + default: + break; /* bits are okay */ + } + switch (sex2 & (GD_LITTLE_ENDIAN | GD_BIG_ENDIAN)) { + case 0: + sex2 |= GD_INT_SEX; + break; + case GD_LITTLE_ENDIAN | GD_BIG_ENDIAN: + sex2 &= ~GD_INT_SEX; + break; + default: + break; /* bits are okay */ + } + } + + /* endianness check */ + endian_fix = ((sex1 & (GD_LITTLE_ENDIAN | GD_BIG_ENDIAN)) != + (sex2 & (GD_LITTLE_ENDIAN | GD_BIG_ENDIAN))); + + dreturn("%i/%i", endian_fix, arm_fix ? *arm_fix : -1); + return endian_fix; +} + +/* returns non-zero if the byte sex of RAW entry E is different than the native + * machine endianness */ +int _GD_FileSwapBytes(const DIRFILE *restrict D, const gd_entry_t *restrict E) +{ + int swap; + + dtrace("%p, %p", D, E); + + swap = _GD_CheckByteSex(E->EN(raw,data_type), + D->fragment[E->fragment_index].byte_sex, 0, 0, NULL); + + dreturn("%i", swap); + return swap; +} + +void _GD_FixEndianness(void* databuffer, size_t ns, gd_type_t type, unsigned + old_sex, unsigned new_sex) +{ size_t i; + int endian_fix, arm_fix; - dtrace("%p, %zu, %" PRNsize_t, databuffer, size, ns); + dtrace("%p, %" PRNsize_t ", 0x%X, 0x%X, 0x%X", databuffer, ns, type, old_sex, + new_sex); - switch (size) { - case 2: - for (i = 0; i < ns; ++i) - ((uint16_t*)databuffer)[i] = gd_swap16(((uint16_t*)databuffer)[i]); - break; - case 4: - for (i = 0; i < ns; ++i) - ((uint32_t*)databuffer)[i] = gd_swap32(((uint32_t*)databuffer)[i]); - break; - case 8: - for (i = 0; i < ns; ++i) - ((uint64_t*)databuffer)[i] = gd_swap64(((uint64_t*)databuffer)[i]); - break; + /* compare byte sexes */ + endian_fix = _GD_CheckByteSex(type, old_sex, new_sex, 1, &arm_fix); + + /* complex data - treat as twice as many floating point */ + if (type & GD_COMPLEX) { + ns *= 2; + type = (GD_SIZE(type) >> 1) | GD_IEEE754; } + if (arm_fix) + _GD_ArmEndianise(databuffer, ns); + + if (endian_fix) + switch (GD_SIZE(type)) { + case 2: + for (i = 0; i < ns; ++i) + ((uint16_t*)databuffer)[i] = gd_swap16(((uint16_t*)databuffer)[i]); + break; + case 4: + for (i = 0; i < ns; ++i) + ((uint32_t*)databuffer)[i] = gd_swap32(((uint32_t*)databuffer)[i]); + break; + case 8: + for (i = 0; i < ns; ++i) + ((uint64_t*)databuffer)[i] = gd_swap64(((uint64_t*)databuffer)[i]); + break; + } + dreturnvoid(); } Modified: trunk/getdata/src/flimits.c =================================================================== --- trunk/getdata/src/flimits.c 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/src/flimits.c 2013-12-17 02:04:49 UTC (rev 874) @@ -201,7 +201,7 @@ ns = (*gd_ef_[E->e->u.raw.file[0].subenc].size)( D->fragment[E->fragment_index].dirfd, E->e->u.raw.file, - E->EN(raw,data_type), _GD_FileSwapBytes(D, E->fragment_index)); + E->EN(raw,data_type), _GD_FileSwapBytes(D, E)); if (ns < 0) { _GD_SetError(D, GD_E_RAW_IO, 0, E->e->u.raw.file[0].name, errno, NULL); Modified: trunk/getdata/src/fpos.c =================================================================== --- trunk/getdata/src/fpos.c 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/src/fpos.c 2013-12-17 02:04:49 UTC (rev 874) @@ -39,7 +39,7 @@ /* We must open the file to know its starting offset */ if (E->e->u.raw.file[0].idata < 0) if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_READ, - _GD_FileSwapBytes(D, E->fragment_index))) + _GD_FileSwapBytes(D, E))) { break; } @@ -175,7 +175,7 @@ dreturn("%i", -1); return -1; } else if (_GD_InitRawIO(D, E, NULL, 0, NULL, GD_EF_SEEK, GD_FILE_WRITE, - _GD_FileSwapBytes(D, E->fragment_index))) + _GD_FileSwapBytes(D, E))) { dreturn("%i", -1); return -1; @@ -255,7 +255,7 @@ case GD_RAW_ENTRY: /* open/create the file, if necessary */ if (_GD_InitRawIO(D, E, NULL, 0, NULL, GD_EF_SEEK, mode, - _GD_FileSwapBytes(D, E->fragment_index))) + _GD_FileSwapBytes(D, E))) { break; } Modified: trunk/getdata/src/getdata.c =================================================================== --- trunk/getdata/src/getdata.c 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/src/getdata.c 2013-12-17 02:04:49 UTC (rev 874) @@ -253,8 +253,8 @@ static size_t _GD_DoRaw(DIRFILE *restrict D, gd_entry_t *restrict E, off64_t s0, size_t ns, gd_type_t return_type, void *restrict data_out) { - size_t n_read = 0; - ssize_t samples_read; + size_t n_read, zeroed_samples = 0; + ssize_t samples_read = 0; char *databuffer; size_t zero_pad = 0; @@ -274,11 +274,10 @@ } if (zero_pad > 0) { - n_read = _GD_FillZero(databuffer, E->EN(raw,data_type), (zero_pad > ns) ? - ns : - zero_pad); - ns -= n_read; - E->e->u.raw.file[0].pos = s0 + n_read - E->EN(raw,spf) * + zeroed_samples = _GD_FillZero(databuffer, E->EN(raw,data_type), + (zero_pad > ns) ? ns : zero_pad); + ns -= zeroed_samples; + E->e->u.raw.file[0].pos = s0 + zeroed_samples - E->EN(raw,spf) * D->fragment[E->fragment_index].frame_offset; s0 = 0; } @@ -286,7 +285,7 @@ if (ns > 0) { /** open the file (and cache the fp) if it hasn't been opened yet. */ if (_GD_InitRawIO(D, E, NULL, 0, NULL, GD_EF_SEEK | GD_EF_READ, - GD_FILE_READ, _GD_FileSwapBytes(D, E->fragment_index))) + GD_FILE_READ, _GD_FileSwapBytes(D, E))) { free(databuffer); dreturn("%i", 0); @@ -302,9 +301,9 @@ return 0; } - samples_read = - (*gd_ef_[E->e->u.raw.file[0].subenc].read)(E->e->u.raw.file, - databuffer + n_read * E->e->u.raw.size, E->EN(raw,data_type), ns); + samples_read = (*gd_ef_[E->e->u.raw.file[0].subenc].read)(E->e->u.raw.file, + databuffer + zeroed_samples * E->e->u.raw.size, E->EN(raw,data_type), + ns); if (samples_read == -1) { _GD_SetError(D, GD_E_RAW_IO, 0, E->e->u.raw.file[0].name, errno, NULL); @@ -313,35 +312,15 @@ return 0; } - if (gd_ef_[E->e->u.raw.file[0].subenc].flags & GD_EF_ECOR) { - /* convert to/from middle-ended doubles */ - if ((E->EN(raw,data_type) == GD_FLOAT64 || - E->EN(raw,data_type) == GD_COMPLEX128) && - D->fragment[E->fragment_index].byte_sex & GD_ARM_FLAG) - { - _GD_ArmEndianise((uint64_t *)(databuffer + n_read * E->e->u.raw.size), - E->EN(raw,data_type) & GD_COMPLEX, samples_read); - } + if (gd_ef_[E->e->u.raw.file[0].subenc].flags & GD_EF_ECOR) + _GD_FixEndianness(databuffer + zeroed_samples * E->e->u.raw.size, + samples_read, E->EN(raw,data_type), + D->fragment[E->fragment_index].byte_sex, 0); - if (D->fragment[E->fragment_index].byte_sex & -#ifdef WORDS_BIGENDIAN - GD_LITTLE_ENDIAN -#else - GD_BIG_ENDIAN -#endif - ) - { - if (E->EN(raw,data_type) & GD_COMPLEX) - _GD_FixEndianness(databuffer + n_read * E->e->u.raw.size, - E->e->u.raw.size / 2, samples_read * 2); - else - _GD_FixEndianness(databuffer + n_read * E->e->u.raw.size, - E->e->u.raw.size, samples_read); - } - } + } - n_read += samples_read; - } + n_read = samples_read + zeroed_samples; + _GD_ConvertType(D, databuffer, E->EN(raw,data_type), data_out, return_type, n_read); Modified: trunk/getdata/src/internal.h =================================================================== --- trunk/getdata/src/internal.h 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/src/internal.h 2013-12-17 02:04:49 UTC (rev 874) @@ -807,7 +807,12 @@ #define GD_E_ARG_NO_VERS 5 #define GD_E_ARG_BAD_VERS 6 +/* the size of the memory buffer used for various bulk I/O operations */ +#define BUFFER_SIZE 9000000 +/* number of lines chunked-in from a LINTERP table at a time */ +#define GD_LUT_CHUNK 100 + /* I/O flags */ #define GD_FILE_READ 0x1 #define GD_FILE_WRITE 0x2 @@ -899,20 +904,19 @@ } u; }; -#define GD_ENC_NONE 0 -#define GD_ENC_SLIM 1 -#define GD_ENC_GZ_RAW 2 -#define GD_ENC_BZ2_RAW 3 -#define GD_ENC_ASCII 4 -#define GD_ENC_LZMA_RAW 5 -#define GD_ENC_XZ_RAW 6 -#define GD_ENC_SIE 7 -#define GD_ENC_ZZIP 8 -#define GD_ENC_ZZSLIM 9 -#define GD_ENC_UNKNOWN 10 +/* _GD_FiniRawIO flags */ +#define GD_FINIRAW_KEEP 0x0 +#define GD_FINIRAW_DISCARD 0x1 +#define GD_FINIRAW_DEFER 0x2 +#define GD_FINIRAW_CLOTEMP 0x4 -#define GD_N_SUBENCODINGS (GD_ENC_UNKNOWN + 1) +/* number of subencodings (ie. the length of the gd_ef_ array */ +#define GD_N_SUBENCODINGS 11 +/* the last record of the gd_ef_ array is always the unknown encoding */ +#define GD_ENC_UNKNOWN (GD_N_SUBENCODINGS - 1) + +/* external module function provides flags */ #define GD_EF_NAME 0x0001 #define GD_EF_OPEN 0x0002 #define GD_EF_CLOSE 0x0004 @@ -924,21 +928,7 @@ #define GD_EF_MOVE 0x0100 #define GD_EF_UNLINK 0x0200 -#define GD_FINIRAW_KEEP 0x0 -#define GD_FINIRAW_DISCARD 0x1 -#define GD_FINIRAW_DEFER 0x2 -#define GD_FINIRAW_CLOTEMP 0x4 - -#define BUFFER_SIZE 9000000 - -#define GD_LUT_CHUNK 100 - -/* helper macro */ -#if defined ARM_ENDIAN_FLOATS || \ - ((defined WORDS_BIGENDIAN) ^ (defined FLOATS_BIGENDIAN)) -# define SCREWY_FLOATS -#endif - +/* encoding scheme method prototypes */ typedef int (*gd_ef_name_t)(DIRFILE *D, const char *, struct gd_raw_file_*, const char*, int, int); typedef int (*gd_ef_open_t)(int, struct gd_raw_file_*, int, unsigned int); @@ -955,17 +945,38 @@ /* Encoding scheme flags */ #define GD_EF_ECOR 0x1 /* post-framework byte-sex correction required */ -#define GD_EF_SWAP 0x2 /* in-framework byte-sex metadata correction required */ +#define GD_EF_SWAP 0x2 /* in-framework byte-sex metadata correction occurs */ #define GD_EF_OOP 0x4 /* writes occur out-of-place */ #define GD_EF_EDAT 0x8 /* The /ENCODING datum is used */ + +/* Just so we're clear on the difference between GD_EF_ECOR and GD_EF_SWAP: + * + * - ECOR means the data returned by the encoding framework has the byte sex of + * the fragment; GetData needs to swap bytes around after the framework + * finishes if this is different than the machine endianness. Most binary + * formats set ECOR, but TEXT doesn't, since sscanf() puts stuff into the + * machine endianness. + * + * - SWAP means that internal workings of the encoding needs to know whether + * the byte sex of the fragment is different than the machine endianness. + * This is set by SIE since its sample indices are stored in the fragment + * endianness, which need to be converted by within the encoding scheme itself + * to be able to read opposite endian data files. + * + * Note: any encoding scheme could set SWAP instead of ECOR and then perform its + * own byte sex correction to hide it from GetData proper, but this should be + * avoided because it can lead to more byte swapping than necessary. + */ + /* Encoding schemes */ extern struct encoding_t { - unsigned long int scheme; - const char* ext; - unsigned int flags; /* flags */ - const char* affix; - const char* ffname; - unsigned int provides; + unsigned long int scheme; /* scheme number (the gd_open() flag value) */ + const char* ext; /* filename extension */ + unsigned int flags; /* encoding flags */ + const char* affix; /* function name prefix (NULL for internal scheme)*/ + const char* ffname; /* /ENCODING directive name */ + unsigned int provides; /* bitfield of functions provided by external + module (0 for internal scheme) */ gd_ef_name_t name; gd_ef_open_t open; gd_ef_close_t close; @@ -980,14 +991,10 @@ /* Format file fragment metadata */ struct gd_fragment_t { - /* Canonical name (full path) */ - char* cname; - /* Subdirectory name */ - char* sname; - /* basename */ - char *bname; - /* External name (the one that appears in the format file) */ - char* ename; + char* cname; /* Canonical name (full path) */ + char* sname; /* Subdirectory name (path relative to dirfile or absolute) */ + char *bname; /* basename (filename) */ + char* ename; /* External name (the one that appears in the format file) */ void *enc_data; int modified; int parent; @@ -1011,7 +1018,7 @@ int rc; }; -/* internal flags */ +/* internal dirfile flags */ #define GD_MULTISTANDARD 0x20000000 /* have multiple standards in format */ #define GD_HAVE_VERSION 0x40000000 /* have computed the version */ #define GD_INVALID 0x80000000 /* the dirfile is invalid */ @@ -1023,6 +1030,7 @@ #define GD_REPR_MOD 'm' #define GD_REPR_ARG 'a' +/* the implicit representation */ #define GD_REPR_AUTO GD_REPR_REAL /* The DIRFILE struct. */ @@ -1089,7 +1097,6 @@ /* forward declarations */ void *_GD_Alloc(DIRFILE*, gd_type_t, size_t) __attribute_malloc__; -void _GD_ArmEndianise(uint64_t*, int, size_t); int _GD_BadInput(DIRFILE *, const gd_entry_t *, int, int); #define _GD_BadWindop(op) \ @@ -1101,6 +1108,7 @@ int _GD_CalculateEntry(DIRFILE *restrict, gd_entry_t *restrict, int); char *_GD_CanonicalPath(const char *restrict, const char *restrict); +int _GD_CheckByteSex(gd_type_t, unsigned, unsigned, int, int *restrict); gd_entry_t *_GD_CheckParent(DIRFILE *restrict D, char **restrict name, int me, int linenum); int _GD_CheckCodeAffixes(DIRFILE *D, const gd_entry_t *P, @@ -1131,12 +1139,8 @@ gd_entry_t *_GD_FindFieldAndRepr(DIRFILE *restrict, const char *restrict, char **restrict, int *restrict, unsigned int *restrict, int, int); uint64_t _GD_FindVersion(DIRFILE *D); -void _GD_FixEndianness(void* databuffer, size_t size, size_t ns); -#ifdef WORDS_BIGENDIAN -#define _GD_FileSwapBytes(D,i) ((D)->fragment[i].byte_sex & GD_LITTLE_ENDIAN) -#else -#define _GD_FileSwapBytes(D,i) ((D)->fragment[i].byte_sex & GD_BIG_ENDIAN) -#endif +void _GD_FixEndianness(void*, size_t, gd_type_t, unsigned, unsigned); +int _GD_FileSwapBytes(const DIRFILE *restrict, const gd_entry_t *restrict); int _GD_FiniRawIO(DIRFILE*, const gd_entry_t*, int, int); void _GD_Flush(DIRFILE *restrict, gd_entry_t *restrict, int, int); void _GD_FlushMeta(DIRFILE* D, int fragment, int force); @@ -1347,6 +1351,7 @@ # define gd_nothrow #endif +/* deal with GD_ANON */ #ifdef GD_C89_API # define EN(t,v) u.t.v #else Modified: trunk/getdata/src/mod.c =================================================================== --- trunk/getdata/src/mod.c 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/src/mod.c 2013-12-17 02:04:49 UTC (rev 874) @@ -335,7 +335,7 @@ /* open the old file */ if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_READ, - _GD_FileSwapBytes(D, E->fragment_index))) + _GD_FileSwapBytes(D, E))) { break; } else if ((*enc->seek)(E->e->u.raw.file, 0, E->EN(raw,data_type), @@ -350,7 +350,7 @@ /* Create a temporary file and open it */ if (_GD_InitRawIO(D, E, NULL, -1, enc, 0, GD_FILE_WRITE | GD_FILE_TEMP, - _GD_FileSwapBytes(D, E->fragment_index))) + _GD_FileSwapBytes(D, E))) break; else if (_GD_WriteSeek(D, E, enc, 0, GD_FILE_WRITE | GD_FILE_TEMP) == -1) Modified: trunk/getdata/src/move.c =================================================================== --- trunk/getdata/src/move.c 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/src/move.c 2013-12-17 02:04:49 UTC (rev 874) @@ -30,7 +30,7 @@ ssize_t nread, nwrote; int subencoding = GD_ENC_UNKNOWN; int i, ef_swap; - int arm_endianise; + int arm_fix = 0, endian_fix = 0; void *buffer; dtrace("%p, %p, %lu, %lu, %lli, %i, %i, %p", D, E, encoding, byte_sex, @@ -92,33 +92,41 @@ enc_in = gd_ef_ + E->e->u.raw.file[0].subenc; - /* Need to do the ARM thing? */ - arm_endianise = (((byte_sex & GD_ARM_FLAG) && (enc_out->flags & GD_EF_ECOR)) ^ - ((D->fragment[E->fragment_index].byte_sex & GD_ARM_FLAG) && - (enc_in->flags & GD_EF_ECOR))) && (E->EN(raw,data_type) == GD_FLOAT64 || - E->EN(raw,data_type) == GD_COMPLEX128); + /* if neither encoding scheme does internal byte swapping, and the data + * type can't be endianness swapped, sex differences can't matter */ + if (GD_SIZE(E->e->u.raw.size) != 1 || (enc_in->flags & GD_EF_SWAP) || + (enc_out->flags & GD_EF_SWAP)) + { + /* figure out whether endianness correction is required */ + if ((enc_in->flags & GD_EF_ECOR) || (enc_in->flags & GD_EF_ECOR)) { + unsigned in_sex = D->fragment[E->fragment_index].byte_sex; + unsigned out_sex = byte_sex; - /* Normalise endiannesses */ -#ifdef WORDS_BIGENDIAN - ef_swap = (byte_sex & GD_LITTLE_ENDIAN) ? 1 : 0; - byte_sex = ((byte_sex & GD_LITTLE_ENDIAN) && - (enc_out->flags & (GD_EF_ECOR | GD_EF_SWAP))) ^ - ((D->fragment[E->fragment_index].byte_sex & GD_LITTLE_ENDIAN) && - (enc_in->flags & (GD_EF_ECOR | GD_EF_SWAP))); -#else - ef_swap = (byte_sex & GD_BIG_ENDIAN) ? 1 : 0; - byte_sex = ((byte_sex & GD_BIG_ENDIAN) && - (enc_out->flags & (GD_EF_ECOR | GD_EF_SWAP))) ^ - ((D->fragment[E->fragment_index].byte_sex & GD_BIG_ENDIAN) && - (enc_in->flags & (GD_EF_ECOR | GD_EF_SWAP))); -#endif - /* Now byte_sex is true if endianness conversion is required. */ + /* fix endian flags for encoding behaviour */ + if (!(enc_in->flags & (GD_EF_SWAP | GD_EF_ECOR))) { + in_sex = (in_sex & ~(GD_LITTLE_ENDIAN | GD_BIG_ENDIAN)) | + (out_sex & (GD_LITTLE_ENDIAN | GD_BIG_ENDIAN)); + if (!(enc_in->flags & GD_EF_ECOR)) + in_sex = (in_sex & ~GD_ARM_FLAG) | (out_sex & GD_ARM_FLAG); + } + if (!(enc_out->flags & (GD_EF_SWAP | GD_EF_ECOR))) { + out_sex = (out_sex & ~(GD_LITTLE_ENDIAN | GD_BIG_ENDIAN)) | + (in_sex & (GD_LITTLE_ENDIAN | GD_BIG_ENDIAN)); + if (!(enc_out->flags & GD_EF_ECOR)) + out_sex = (out_sex & ~GD_ARM_FLAG) | (in_sex | GD_ARM_FLAG); + } + + endian_fix = _GD_CheckByteSex(E->EN(raw,data_type), in_sex, out_sex, 0, + &arm_fix); + } + } + /* If all that's changing is the byte sex, but we don't need to do * endianness conversion, don't do anything */ if (offset == 0 && encoding == D->fragment[E->fragment_index].encoding && - !byte_sex && !arm_endianise && strcmp(new_filebase, - E->e->u.raw.filebase) == 0 && D->fragment[new_fragment].dirfd == + !endian_fix && !arm_fix && strcmp(new_filebase, E->e->u.raw.filebase) == 0 + && D->fragment[new_fragment].dirfd == D->fragment[E->fragment_index].dirfd) { free(new_filebase); @@ -139,13 +147,16 @@ /* Open the input file, if necessary */ if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_READ, - _GD_FileSwapBytes(D, E->fragment_index))) + _GD_FileSwapBytes(D, E))) { free(new_filebase); dreturn("%i", -1); return -1; } + /* set ef_swap, the output encoding in-framework endian correction flag */ + ef_swap = _GD_CheckByteSex(E->EN(raw,data_type), byte_sex, 0, 0, NULL); + /* Create the output file and open it. If we're changing encodings, we * could write to the new file directly. However, we use a temporary file * anyway just to keep things clean. */ @@ -202,18 +213,9 @@ if (nread == 0) break; - /* fix army-ness, if required */ - if (arm_endianise) - _GD_ArmEndianise((uint64_t *)buffer, E->EN(raw,data_type) & GD_COMPLEX, - nread); - /* swap endianness, if required */ - if (byte_sex) { - if (E->EN(raw,data_type) & GD_COMPLEX) - _GD_FixEndianness((char *)buffer, E->e->u.raw.size / 2, nread * 2); - else - _GD_FixEndianness((char *)buffer, E->e->u.raw.size, nread); - } + _GD_FixEndianness(buffer, nread, E->EN(raw,data_type), + D->fragment[E->fragment_index].byte_sex, byte_sex); nwrote = _GD_WriteOut(E, enc_out, buffer, E->EN(raw,data_type), nread, 1); Modified: trunk/getdata/src/nframes.c =================================================================== --- trunk/getdata/src/nframes.c 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/src/nframes.c 2013-12-17 02:04:49 UTC (rev 874) @@ -57,9 +57,8 @@ nf = (*gd_ef_[D->reference_field->e->u.raw.file[0].subenc].size)( D->fragment[D->reference_field->fragment_index].dirfd, - D->reference_field->e->u.raw.file, - D->reference_field->EN(raw,data_type), _GD_FileSwapBytes(D, - D->reference_field->fragment_index)); + D->reference_field->e->u.raw.file, D->reference_field->EN(raw,data_type), + _GD_FileSwapBytes(D, D->reference_field)); if (nf < 0) { _GD_SetError(D, GD_E_RAW_IO, 0, D->reference_field->e->u.raw.file[0].name, Modified: trunk/getdata/src/parse.c =================================================================== --- trunk/getdata/src/parse.c 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/src/parse.c 2013-12-17 02:04:49 UTC (rev 874) @@ -1573,7 +1573,7 @@ _GD_SetError(D, GD_E_UNSUPPORTED, 0, NULL, 0, NULL); else _GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_WRITE | GD_FILE_TOUCH, - _GD_FileSwapBytes(D, E->fragment_index)); + _GD_FileSwapBytes(D, E)); } /* Is this the first raw field ever defined? */ Modified: trunk/getdata/src/putdata.c =================================================================== --- trunk/getdata/src/putdata.c 2013-12-13 00:43:41 UTC (rev 873) +++ trunk/getdata/src/putdata.c 2013-12-17 02:04:49 UTC (rev 874) @@ -67,34 +67,14 @@ return 0; } - if (gd_ef_[E->e->u.raw.file[0].subenc].flags & GD_EF_ECOR) { - /* convert to/from middle-ended doubles */ - if ((E->EN(raw,data_type) == GD_FLOAT64 || E->EN(raw,data_type) == - GD_COMPLEX128) && - D->fragment[E->fragment_index].byte_sex & GD_ARM_FLAG) - { - _GD_ArmEndianise((uint64_t*)databuffer, E->EN(raw,data_type) & GD_COMPLEX, - ns); - } + /* fix endianness, if necessary */ + if (gd_ef_[E->e->u.raw.file[0].subenc].flags & GD_EF_ECOR) + _GD_FixEndianness(databuffer, ns, E->EN(raw,data_type), 0, + D->fragment[E->fragment_index].byte_sex); - if (D->fragment[E->fragment_index].byte_sex & -#ifdef WORDS_BIGENDIAN - GD_LITTLE_ENDIAN -#else - GD_BIG_ENDIAN -#endif - ) - { - if (E->EN(raw,data_type) & GD_COMPLEX) - _GD_FixEndianness((char *)databuffer, E->e->u.raw.size / 2, ns * 2); - else - _GD_FixEndianness((char *)databuffer, E->e->u.raw.size, ns); - } - } /* write data to file. */ - if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_WRITE, - _GD_FileSwapBytes(D, E->fragment_index))) + _GD_FileSwapBytes(D, E))) { free(databuffer); dreturn("%i", 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2013-12-17 23:55:25
|
Revision: 875 http://sourceforge.net/p/getdata/code/875 Author: ketiltrout Date: 2013-12-17 23:55:22 +0000 (Tue, 17 Dec 2013) Log Message: ----------- Make subdirfiles work again. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/man/gd_error_count.3 trunk/getdata/src/add.c trunk/getdata/src/encoding.c trunk/getdata/src/errors.c trunk/getdata/src/fpos.c trunk/getdata/src/getdata.c trunk/getdata/src/internal.h trunk/getdata/src/mod.c trunk/getdata/src/move.c trunk/getdata/src/parse.c trunk/getdata/src/putdata.c trunk/getdata/test/Makefile.am Added Paths: ----------- trunk/getdata/test/add_raw_sub.c trunk/getdata/test/ascii_get_sub.c trunk/getdata/test/gzip_put_sub.c trunk/getdata/test/put_sub.c trunk/getdata/test/seek_sub.c trunk/getdata/test/tell_sub.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/ChangeLog 2013-12-17 23:55:22 UTC (rev 875) @@ -1,3 +1,13 @@ +2013-12-17 D. V. Wiebe <ge...@ke...> svn:875 + * src/add.c (_GD_Add) src/fpos.c (_GD_GetFilePos _GD_WriteSeek _GD_Seek) + src/getdata.c (_GD_DoRaw) src/mod.c (_GD_Change) src/move.c + (_GD_MogrifyFile) src/parse.c (_GD_ParseFieldSpec) src/putdata.c + (_GD_InitRawIO): Call _GD_InitRawIO with fragment = -1. + * test/add_raw_sub.c test/ascii_get_sub.c test/gzip_put_sub.c test/put_sub.c + test/seek_sub.c test/tell_sub.c: Added. + + * src/errors.c src/internal.h: Add GD_E_UNCLEAN_CALL suberror. + 2013-12-12 D. V. Wiebe <ge...@ke...> svn:874 * src/endian.c (_GD_CheckByteSex): Added. * src/endian.c (_GD_FileSwapBytes): Added (replacing macro in internal.h). Modified: trunk/getdata/man/gd_error_count.3 =================================================================== --- trunk/getdata/man/gd_error_count.3 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/man/gd_error_count.3 2013-12-17 23:55:22 UTC (rev 875) @@ -1,6 +1,6 @@ .\" gd_error_count.3. The gd_error_count man page. .\" -.\" Copyright (C) 2011 D. V. Wiebe +.\" Copyright (C) 2011, 2013 D. V. Wiebe .\" .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .\" @@ -13,7 +13,7 @@ .\" Texts. A copy of the license is included in the `COPYING.DOC' file .\" as part of this distribution. .\" -.TH gd_error_count 3 "18 August 2011" "Version 0.8.0" "GETDATA" +.TH gd_error_count 3 "17 December 2013" "Version 0.9.0" "GETDATA" .SH NAME gd_error_count \(em report the number of errors encountered by the GetData library @@ -22,7 +22,7 @@ .HP .nh .ad l -.BI "int gd_error_check(DIRFILE *" dirfile ); +.BI "int gd_error_count(DIRFILE *" dirfile ); .hy .ad n .SH DESCRIPTION @@ -31,14 +31,15 @@ is called with the DIRFILE object .IR dirfile , it returns the number of errors encountered by the GetData library while -operating on the specified DIRFILE object, since the DIRFILE's creation. -Calling this function resets the internal count, so that subsequent calls to +operating on +.I dirfile +since its creation. Calling this function resets the internal count, so +that subsequent calls to .BR gd_error_count () return the number of errors encountered only since the previous call to this function, for the specified DIRFILE. -The errors themselves are not cached by the library. The error status of -the +The errors themselves are not cached by the library. The error status of the .I last library call on .I dirfile Modified: trunk/getdata/src/add.c =================================================================== --- trunk/getdata/src/add.c 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/src/add.c 2013-12-17 23:55:22 UTC (rev 875) @@ -297,7 +297,7 @@ else if (E->EN(raw,data_type) & 0x40 || (E->e->u.raw.size = GD_SIZE(E->EN(raw,data_type))) == 0) _GD_SetError(D, GD_E_BAD_TYPE, entry->EN(raw,data_type), NULL, 0, NULL); - else if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, + else if (_GD_InitRawIO(D, E, NULL, -1, NULL, 0, GD_FILE_WRITE | GD_FILE_TOUCH, _GD_FileSwapBytes(D, E))) { ; Modified: trunk/getdata/src/encoding.c =================================================================== --- trunk/getdata/src/encoding.c 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/src/encoding.c 2013-12-17 23:55:22 UTC (rev 875) @@ -340,7 +340,8 @@ file[1].name = NULL; } errno = move_errno; - _GD_SetError(D, GD_E_UNCLEAN_DB, 0, D->fragment[fragment].cname, 0, NULL); + _GD_SetError(D, GD_E_UNCLEAN_DB, GD_E_UNCLEAN_CALL, + D->fragment[fragment].cname, errno, "gd_RenameAt"); D->flags |= GD_INVALID; dreturn("%i", -1); return -1; Modified: trunk/getdata/src/errors.c =================================================================== --- trunk/getdata/src/errors.c 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/src/errors.c 2013-12-17 23:55:22 UTC (rev 875) @@ -185,9 +185,11 @@ { GD_E_CALLBACK, 0, "Unrecognised response from callback function: {3}", 0 }, /* GD_E_ExISTS: (nothing) */ { GD_E_EXISTS, 0, "Dirfile exists", 0 }, - /* GD_E_UNCLEAN_DB: 3 = fragment */ + /* GD_E_UNCLEAN_DB: 2 = fragment, 3 = errno; 4 = call */ + { GD_E_UNCLEAN_DB, GD_E_UNCLEAN_CALL, + "Unexpected system error processing {2}; database unclean: {4}: ", 1 }, { GD_E_UNCLEAN_DB, 0, - "Unexpected system error processing {3}; database unclean", 0 }, + "Unexpected system error processing {2}; database unclean", 0 }, /* GD_E_DOMAIN: (nothing) */ { GD_E_DOMAIN, GD_E_DOMAIN_COMPLEX, "Improper domain: complex valued", 0 }, { GD_E_DOMAIN, GD_E_DOMAIN_EMPTY, "Improper domain: empty set", 0 }, Modified: trunk/getdata/src/fpos.c =================================================================== --- trunk/getdata/src/fpos.c 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/src/fpos.c 2013-12-17 23:55:22 UTC (rev 875) @@ -38,7 +38,7 @@ case GD_RAW_ENTRY: /* We must open the file to know its starting offset */ if (E->e->u.raw.file[0].idata < 0) - if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_READ, + if (_GD_InitRawIO(D, E, NULL, -1, NULL, 0, GD_FILE_READ, _GD_FileSwapBytes(D, E))) { break; @@ -174,7 +174,7 @@ if (_GD_FiniRawIO(D, E, E->fragment_index, GD_FINIRAW_KEEP)) { dreturn("%i", -1); return -1; - } else if (_GD_InitRawIO(D, E, NULL, 0, NULL, GD_EF_SEEK, GD_FILE_WRITE, + } else if (_GD_InitRawIO(D, E, NULL, -1, NULL, GD_EF_SEEK, GD_FILE_WRITE, _GD_FileSwapBytes(D, E))) { dreturn("%i", -1); @@ -254,7 +254,7 @@ switch (E->field_type) { case GD_RAW_ENTRY: /* open/create the file, if necessary */ - if (_GD_InitRawIO(D, E, NULL, 0, NULL, GD_EF_SEEK, mode, + if (_GD_InitRawIO(D, E, NULL, -1, NULL, GD_EF_SEEK, mode, _GD_FileSwapBytes(D, E))) { break; Modified: trunk/getdata/src/getdata.c =================================================================== --- trunk/getdata/src/getdata.c 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/src/getdata.c 2013-12-17 23:55:22 UTC (rev 875) @@ -284,7 +284,7 @@ if (ns > 0) { /** open the file (and cache the fp) if it hasn't been opened yet. */ - if (_GD_InitRawIO(D, E, NULL, 0, NULL, GD_EF_SEEK | GD_EF_READ, + if (_GD_InitRawIO(D, E, NULL, -1, NULL, GD_EF_SEEK | GD_EF_READ, GD_FILE_READ, _GD_FileSwapBytes(D, E))) { free(databuffer); Modified: trunk/getdata/src/internal.h =================================================================== --- trunk/getdata/src/internal.h 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/src/internal.h 2013-12-17 23:55:22 UTC (rev 875) @@ -782,6 +782,8 @@ #define GD_E_REPR_UNKNOWN 1 #define GD_E_REPR_PUT 2 +#define GD_E_UNCLEAN_CALL 1 + #define GD_E_DOMAIN_COMPLEX 1 #define GD_E_DOMAIN_EMPTY 2 #define GD_E_DOMAIN_ANTITONIC 3 Modified: trunk/getdata/src/mod.c =================================================================== --- trunk/getdata/src/mod.c 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/src/mod.c 2013-12-17 23:55:22 UTC (rev 875) @@ -334,7 +334,7 @@ enc = gd_ef_ + E->e->u.raw.file[0].subenc; /* open the old file */ - if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_READ, + if (_GD_InitRawIO(D, E, NULL, -1, NULL, 0, GD_FILE_READ, _GD_FileSwapBytes(D, E))) { break; Modified: trunk/getdata/src/move.c =================================================================== --- trunk/getdata/src/move.c 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/src/move.c 2013-12-17 23:55:22 UTC (rev 875) @@ -146,7 +146,7 @@ } /* Open the input file, if necessary */ - if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_READ, + if (_GD_InitRawIO(D, E, NULL, -1, NULL, 0, GD_FILE_READ, _GD_FileSwapBytes(D, E))) { free(new_filebase); Modified: trunk/getdata/src/parse.c =================================================================== --- trunk/getdata/src/parse.c 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/src/parse.c 2013-12-17 23:55:22 UTC (rev 875) @@ -1572,7 +1572,7 @@ /* If the encoding scheme is unsupported, we can't add the field */ _GD_SetError(D, GD_E_UNSUPPORTED, 0, NULL, 0, NULL); else - _GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_WRITE | GD_FILE_TOUCH, + _GD_InitRawIO(D, E, NULL, -1, NULL, 0, GD_FILE_WRITE | GD_FILE_TOUCH, _GD_FileSwapBytes(D, E)); } Modified: trunk/getdata/src/putdata.c =================================================================== --- trunk/getdata/src/putdata.c 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/src/putdata.c 2013-12-17 23:55:22 UTC (rev 875) @@ -73,7 +73,7 @@ D->fragment[E->fragment_index].byte_sex); /* write data to file. */ - if (_GD_InitRawIO(D, E, NULL, 0, NULL, 0, GD_FILE_WRITE, + if (_GD_InitRawIO(D, E, NULL, -1, NULL, 0, GD_FILE_WRITE, _GD_FileSwapBytes(D, E))) { free(databuffer); Index: trunk/getdata/test =================================================================== --- trunk/getdata/test 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/test 2013-12-17 23:55:22 UTC (rev 875) Property changes on: trunk/getdata/test ___________________________________________________________________ Modified: svn:ignore ## -53,6 +53,7 ## add_raw_invalid add_raw_spf add_raw_spf_scalar +add_raw_sub add_raw_type add_rdonly add_recip ## -141,6 +142,7 ## ascii_get ascii_get_complex ascii_get_get +ascii_get_sub ascii_nframes ascii_put ascii_sync ## -564,6 +566,7 ## gzip_put_back gzip_put_endian gzip_put_get +gzip_put_sub gzip_sync header_complex hide ## -960,6 +963,7 ## put_ss put_string put_string_protect +put_sub put_type put_uint16 put_uint32 ## -998,6 +1002,7 ## seek_neg seek_phase seek_set +seek_sub sie_get_big sie_get_little sie_move_from ## -1042,6 +1047,7 ## tell tell64 tell_multidiv +tell_sub tok_arg tok_escape tok_quote Modified: trunk/getdata/test/Makefile.am =================================================================== --- trunk/getdata/test/Makefile.am 2013-12-17 02:04:49 UTC (rev 874) +++ trunk/getdata/test/Makefile.am 2013-12-17 23:55:22 UTC (rev 875) @@ -35,8 +35,8 @@ add_mplex_scalars add_multiply add_multiply_invalid add_phase \ add_phase_invalid add_polynom add_polynom_scalar add_protect add_raw \ add_raw_include add_raw_invalid add_raw_spf add_raw_spf_scalar \ - add_raw_type add_rdonly add_recip add_resolv add_sbit add_scalar \ - add_scalar_carray add_scalar_carray_bad add_sort add_spec \ + add_raw_sub add_raw_type add_rdonly add_recip add_resolv add_sbit \ + add_scalar add_scalar_carray add_scalar_carray_bad add_sort add_spec \ add_spec_directive add_spec_invalid add_spec_meta add_spec_resolv \ add_string add_string_affix add_type add_window add_window_op @@ -60,8 +60,8 @@ alter_recip alter_recip_zero alter_scalar_affix alter_spec \ alter_spec_affix alter_spec_meta alter_spec_polynom alter_window -ASCII_TESTS=ascii_add ascii_get ascii_get_complex ascii_get_get ascii_nframes \ - ascii_put ascii_sync +ASCII_TESTS=ascii_add ascii_get ascii_get_complex ascii_get_get ascii_get_sub \ + ascii_nframes ascii_put ascii_sync BOF_TESTS=bof bof_bit bof_index bof_lincom bof_phase bof_phase_neg @@ -209,7 +209,7 @@ GZIP_TESTS=gzip_add gzip_del gzip_get gzip_get_get gzip_get_get2 gzip_get_put \ gzip_move_from gzip_move_to gzip_nframes gzip_put gzip_put_back \ - gzip_put_endian gzip_put_get gzip_sync + gzip_put_endian gzip_put_get gzip_put_sub gzip_sync HEADER_TESTS=header_complex @@ -337,7 +337,7 @@ put_multiply put_null put_off64 put_phase put_phase_noin \ put_polynom1 put_polynom2 put_polynom_noin put_protect put_rdonly \ put_recip put_recurse put_repr put_rofs put_sbit put_sf put_ss \ - put_string put_string_protect put_type put_uint16 put_uint32 \ + put_string put_string_protect put_sub put_type put_uint16 put_uint32 \ put_uint64 put_window put_zero REF_TESTS=ref ref_none ref_two @@ -348,7 +348,7 @@ repr_uint64 repr_uint8 SEEK_TESTS=seek64 seek_cur seek_end seek_foffs seek_index seek_lincom \ - seek_mult seek_neg seek_phase seek_set + seek_mult seek_neg seek_phase seek_set seek_sub SIE_TESTS=sie_get_big sie_get_little sie_move_from sie_move_to sie_nframes_big \ sie_nframes_little sie_put_append sie_put_append2 sie_put_back \ @@ -365,7 +365,7 @@ TABLE_TESTS=table table_code table_type -TELL_TESTS=tell tell64 tell_multidiv +TELL_TESTS=tell tell64 tell_multidiv tell_sub TOK_TESTS=tok_arg tok_escape tok_quote Added: trunk/getdata/test/add_raw_sub.c =================================================================== --- trunk/getdata/test/add_raw_sub.c (rev 0) +++ trunk/getdata/test/add_raw_sub.c 2013-12-17 23:55:22 UTC (rev 875) @@ -0,0 +1,85 @@ +/* Copyright (C) 2013 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +#include <stdlib.h> +#include <sys/types.h> +#include <stdio.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *subdir = "dirfile/sub"; + const char *format = "dirfile/format"; + const char *format1 = "dirfile/sub/format1"; + const char *data = "dirfile/sub/data"; + const char *format_data = "/INCLUDE sub/format1\n"; + const char *format1_data = "#\n"; + gd_entry_t e; + int error, fd, r = 0; + DIRFILE *D; + + rmdirfile(); + mkdir(filedir, 0777); + mkdir(subdir, 0777); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(format1, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format1_data, strlen(format1_data)); + close(fd); + + D = gd_open(filedir, GD_RDWR | GD_VERBOSE | GD_UNENCODED); + gd_add_raw(D, "data", GD_UINT8, 2, 1); + error = gd_error(D); + + /* check */ + gd_entry(D, "data", &e); + if (gd_error(D)) + r = 1; + else { + CHECKI(e.field_type, GD_RAW_ENTRY); + CHECKI(e.fragment_index, 1); + CHECKI(e.EN(raw,spf), 2); + CHECKI(e.EN(raw,data_type), GD_UINT8); + gd_free_entry_strings(&e); + } + + gd_discard(D); + + if (unlink(data)) { + perror("unlink"); + r = 1; + } + unlink(format1); + unlink(format); + rmdir(subdir); + rmdir(filedir); + + CHECKI(error, GD_E_OK); + return r; +} Added: trunk/getdata/test/ascii_get_sub.c =================================================================== --- trunk/getdata/test/ascii_get_sub.c (rev 0) +++ trunk/getdata/test/ascii_get_sub.c 2013-12-17 23:55:22 UTC (rev 875) @@ -0,0 +1,82 @@ +/* Copyright (C) 2013 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> +#include <errno.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *subdir = "dirfile/sub"; + const char *format = "dirfile/format"; + const char *format1 = "dirfile/sub/format1"; + const char *data = "dirfile/sub/data.txt"; + const char *format1_data = "data RAW UINT8 8\n"; + const char *format_data = "/INCLUDE sub/format1\n"; + unsigned char c[8]; + int fd, i, n, error, r = 0; + DIRFILE *D; + FILE* stream; + + memset(c, 0, 8); + rmdirfile(); + + mkdir(filedir, 0777); + mkdir(subdir, 0777); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(format1, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format1_data, strlen(format1_data)); + close(fd); + + stream = fopen(data, "w"); + for (i = 0; i < 256; ++i) + fprintf(stream, "%i\n", i); + fclose(stream); + + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); + n = gd_getdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); + error = gd_error(D); + + CHECKI(error, 0); + CHECKI(n, 8); + for (i = 0; i < 8; ++i) + CHECKIi(i,c[i], 40 + i); + + gd_discard(D); + + unlink(data); + unlink(format); + unlink(format1); + rmdir(subdir); + rmdir(filedir); + + return r; +} Added: trunk/getdata/test/gzip_put_sub.c =================================================================== --- trunk/getdata/test/gzip_put_sub.c (rev 0) +++ trunk/getdata/test/gzip_put_sub.c 2013-12-17 23:55:22 UTC (rev 875) @@ -0,0 +1,120 @@ +/* Copyright (C) 2013 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +#include <inttypes.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> +#include <stdio.h> + +int main(void) +{ +#if ! (defined TEST_GZIP) || ! (defined USE_GZIP) + return 77; +#else + const char *filedir = "dirfile"; + const char *subdir = "dirfile/sub"; + const char *format = "dirfile/format"; + const char *format1 = "dirfile/sub/format1"; + const char *data_gz = "dirfile/sub/data.gz"; + const char *data = "dirfile/sub/data"; + const char *format_data = "/INCLUDE sub/format1\n"; + const char *format1_data = "data RAW UINT8 8\n"; + uint8_t c[8]; + char command[4096]; + uint8_t d; + struct stat buf; + int fd, i, n1, n2, e1, e2, e3, stat_data, unlink_data, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + mkdir(subdir, 0777); + + for (i = 0; i < 8; ++i) + c[i] = (uint8_t)(40 + i); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(format1, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format1_data, strlen(format1_data)); + close(fd); + + D = gd_open(filedir, GD_RDWR | GD_GZIP_ENCODED | GD_VERBOSE); + n1 = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); + e1 = gd_error(D); + CHECKI(e1, GD_E_OK); + CHECKI(n1, 8); + + n2 = gd_putdata(D, "data", 0, 0, 1, 0, GD_UINT8, c); + e2 = gd_error(D); + CHECKI(e2, GD_E_OK); + CHECKI(n2, 8); + + e3 = gd_close(D); + CHECKI(e3, 0); + + stat_data = stat(data_gz, &buf); + if (stat_data) { + perror("stat"); + } + CHECKI(stat_data, 0); + + /* uncompress */ + snprintf(command, 4096, "%s -f %s > /dev/null", GUNZIP, data); + if (gd_system(command)) { + r = 1; + } else { + fd = open(data, O_RDONLY | O_BINARY); + if (fd >= 0) { + i = 0; + while (read(fd, &d, sizeof(uint8_t))) { + if (i < 8) { + CHECKIi(i, d, i + 40); + } else if (i < 40 || i > 48) { + CHECKIi(i, d, 0); + } else + CHECKIi(i, d, i); + i++; + } + CHECKI(i, 48); + close(fd); + } + } + + unlink_data = unlink(data); + unlink(format1); + unlink(format); + rmdir(subdir); + rmdir(filedir); + + CHECKI(unlink_data, 0); + + return r; +#endif +} Added: trunk/getdata/test/put_sub.c =================================================================== --- trunk/getdata/test/put_sub.c (rev 0) +++ trunk/getdata/test/put_sub.c 2013-12-17 23:55:22 UTC (rev 875) @@ -0,0 +1,98 @@ +/* Copyright (C) 2013 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +#include <inttypes.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *subdir = "dirfile/sub"; + const char *format = "dirfile/format"; + const char *format1 = "dirfile/sub/format1"; + const char *data = "dirfile/sub/data"; + const char *format_data = "/INCLUDE sub/format1\n"; + const char *format1_data = "data RAW UINT8 8\n"; + uint8_t c[8], d; + int fd, i, n, e1, e2, r = 0; + DIRFILE *D; + struct stat buf; + + for (i = 0; i < 8; ++i) + c[i] = (uint8_t)(40 + i); + + rmdirfile(); + mkdir(filedir, 0777); + mkdir(subdir, 0777); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(format1, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format1_data, strlen(format1_data)); + close(fd); + + D = gd_open(filedir, GD_RDWR | GD_UNENCODED | GD_VERBOSE); + n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); + e1 = gd_error(D); + CHECKI(n,8); + CHECKI(e1, 0); + + e2 = gd_close(D); + CHECKI(e2, 0); + + if (stat(data, &buf)) { + perror("stat"); + r = 1; + } else + CHECKI(buf.st_size, 48 * sizeof(uint8_t)); + + fd = open(data, O_RDONLY | O_BINARY); + if (fd < 0) { + perror("open"); + r = 1; + } else { + i = 0; + while (read(fd, &d, sizeof(uint8_t))) { + if (i < 40 || i > 48) { + CHECKUi(i,d,0); + } else + CHECKUi(i,d,i); + i++; + } + close(fd); + } + + unlink(data); + unlink(format1); + unlink(format); + rmdir(subdir); + rmdir(filedir); + + return r; +} Added: trunk/getdata/test/seek_sub.c =================================================================== --- trunk/getdata/test/seek_sub.c (rev 0) +++ trunk/getdata/test/seek_sub.c 2013-12-17 23:55:22 UTC (rev 875) @@ -0,0 +1,83 @@ +/* Copyright (C) 2013 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *subdir = "dirfile/sub"; + const char *format = "dirfile/format"; + const char *format1 = "dirfile/sub/format1"; + const char *data = "dirfile/sub/data"; + const char *format_data = "/INCLUDE sub/format1\n"; + const char *format1_data = "data RAW UINT8 8\n"; + unsigned char data_data[256]; + int fd, e1, e2, r = 0; + off_t m, n; + DIRFILE *D; + + rmdirfile(); + mkdir(filedir, 0777); + mkdir(subdir, 0777); + + for (fd = 0; fd < 256; ++fd) + data_data[fd] = (unsigned char)fd; + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(format1, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format1_data, strlen(format1_data)); + close(fd); + + fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, data_data, 256); + close(fd); + + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); + m = gd_seek(D, "data", 6, 0, GD_SEEK_SET); + e1 = gd_error(D); + CHECKI(e1, 0); + CHECKI(m, 48); + + n = gd_tell(D, "data"); + e2 = gd_error(D); + CHECKI(e2, 0); + CHECKI(n, 48); + + gd_discard(D); + + unlink(data); + unlink(format); + unlink(format1); + rmdir(subdir); + rmdir(filedir); + + return r; +} Added: trunk/getdata/test/tell_sub.c =================================================================== --- trunk/getdata/test/tell_sub.c (rev 0) +++ trunk/getdata/test/tell_sub.c 2013-12-17 23:55:22 UTC (rev 875) @@ -0,0 +1,78 @@ +/* Copyright (C) 2013 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <errno.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *subdir = "dirfile/sub"; + const char *format = "dirfile/format"; + const char *format1 = "dirfile/sub/format1"; + const char *data = "dirfile/sub/data"; + const char *format_data = "/INCLUDE sub/format1\n"; + const char *format1_data = "data RAW UINT8 8\nFRAMEOFFSET 6\n"; + unsigned char data_data[256]; + int fd, e1, r = 0; + off_t n; + DIRFILE *D; + + rmdirfile(); + mkdir(filedir, 0777); + mkdir(subdir, 0777); + + for (fd = 0; fd < 256; ++fd) + data_data[fd] = (unsigned char)fd; + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(format1, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format1_data, strlen(format1_data)); + close(fd); + + fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, data_data, 256); + close(fd); + + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); + n = gd_tell(D, "data"); + e1 = gd_error(D); + CHECKI(e1, 0); + CHECKI(n, 48); + + gd_discard(D); + + unlink(data); + unlink(format1); + unlink(format); + rmdir(subdir); + rmdir(filedir); + + return r; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2014-02-13 21:26:21
|
Revision: 876 http://sourceforge.net/p/getdata/code/876 Author: ketiltrout Date: 2014-02-13 21:26:18 +0000 (Thu, 13 Feb 2014) Log Message: ----------- Typos. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/NEWS trunk/getdata/bindings/python/pyfragment.c trunk/getdata/doc/README.f77 Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2013-12-17 23:55:22 UTC (rev 875) +++ trunk/getdata/ChangeLog 2014-02-13 21:26:18 UTC (rev 876) @@ -1,3 +1,7 @@ +2014-02-21 D. V. Wiebe <ge...@ke...> svn:876 + * bindings/python/pyfragment.c (gdpy_fragment_init): Fix typo in keyword + names. + 2013-12-17 D. V. Wiebe <ge...@ke...> svn:875 * src/add.c (_GD_Add) src/fpos.c (_GD_GetFilePos _GD_WriteSeek _GD_Seek) src/getdata.c (_GD_DoRaw) src/mod.c (_GD_Change) src/move.c @@ -3067,7 +3071,7 @@ * util/dirfile2ascii.c util/checkdirfile.c: Update for new function names. - * util/checkdirifle.c: Report standards version compliance. + * util/checkdirfile.c: Report standards version compliance. * bindings/python/test/big_test.py bindings/cxx/test/big_test.cpp bindings/f77/test/big_test.f bindings/f77/test/big_test95.f90 Modified: trunk/getdata/NEWS =================================================================== --- trunk/getdata/NEWS 2013-12-17 23:55:22 UTC (rev 875) +++ trunk/getdata/NEWS 2014-02-13 21:26:18 UTC (rev 876) @@ -20,7 +20,7 @@ * BUG FIX: When performing a metadata update due to a renamed field, the field codes containing subfields of the renamed field are now also updated, - including field codes specifying meta subfield which do not exist. + including field codes specifying meta subfields which do not exist. * BUG FIX: The gd_[m]add() functions now ignore zero-length scalar strings. Previously they would store these invalid field codes, causing problems @@ -117,8 +117,8 @@ field_end which is beyond the end of field, and then is required to extrapolate outside of the specified frame range. - * BUG FIX: gd_add_polynom() and similar now produce the correct error string - when encountering a poly_ord out of range. + * BUG FIX: gd_error_string() now produces the correct string when reporting + an out-of-range poly_ord encountered by gd_add_polynom() and similar. * BUG FIX: gd_alter_raw() and similar no longer fail when asked to re-encode the data file of a RAW field which has not been previously accessed. @@ -182,6 +182,9 @@ * IDL BUG FIX: the /UPDATEDB flag to gd_rename now operates as expected. Previously it would act like /MOVE_DATA. + * PYTHON BUG FIX: The keyword for the "dirfile" parameter in the + getdata.fragment constructor is now properly spelled. + |==============================================================================| New in verison 0.8.5: @@ -1442,7 +1445,7 @@ Miscellaneous: - * BUG FIX: The dirifle_madd_bit(3) manual page has been corrected to show + * BUG FIX: The dirfile_madd_bit(3) manual page has been corrected to show the correct order or parameters for all the dirfile_madd_<field_type> functions. Modified: trunk/getdata/bindings/python/pyfragment.c =================================================================== --- trunk/getdata/bindings/python/pyfragment.c 2013-12-17 23:55:22 UTC (rev 875) +++ trunk/getdata/bindings/python/pyfragment.c 2014-02-13 21:26:18 UTC (rev 876) @@ -50,7 +50,7 @@ static int gdpy_fragment_init(struct gdpy_fragment_t *self, PyObject *args, PyObject *keys) { - char *keywords[] = {"dirifle", "index", NULL}; + char *keywords[] = {"dirfile", "index", NULL}; dtrace("%p, %p, %p", self, args, keys); Modified: trunk/getdata/doc/README.f77 =================================================================== --- trunk/getdata/doc/README.f77 2013-12-17 23:55:22 UTC (rev 875) +++ trunk/getdata/doc/README.f77 2014-02-13 21:26:18 UTC (rev 876) @@ -677,9 +677,9 @@ Input: INTEGER dirfile_unit - This wraps diriflename(3). The name of the dirfile will be returned in name. - If the name of the dirfile is longer than name_len, it will return the actual - length of the name in name_len and not modify the name argument. + This wraps gd_dirfilename(3). The name of the dirfile will be returned in + name. If the name of the dirfile is longer than name_len, it will return the + actual length of the name in name_len and not modify the name argument. * GDREFE(name, name_len, dirfile_unit, field_code, field_code_len) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2014-02-19 00:22:59
|
Revision: 877 http://sourceforge.net/p/getdata/code/877 Author: ketiltrout Date: 2014-02-19 00:22:56 +0000 (Wed, 19 Feb 2014) Log Message: ----------- Fix bugs reported by Coverity Scan. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/NEWS trunk/getdata/bindings/cxx/entry.cpp trunk/getdata/bindings/cxx/fragment.cpp trunk/getdata/bindings/f77/fgetdata.c trunk/getdata/bindings/idl/getdata.c trunk/getdata/bindings/make_parameters.c trunk/getdata/bindings/php/getdata.c trunk/getdata/bindings/python/pydirfile.c trunk/getdata/bindings/python/pyentry.c trunk/getdata/bindings/python/pygetdata.h trunk/getdata/src/add.c trunk/getdata/src/bzip.c trunk/getdata/src/common.c trunk/getdata/src/entry.c trunk/getdata/src/getdata.h.in trunk/getdata/src/gzip.c trunk/getdata/src/include.c trunk/getdata/src/lzma.c trunk/getdata/src/mod.c trunk/getdata/src/name.c trunk/getdata/src/open.c trunk/getdata/src/parse.c trunk/getdata/src/putdata.c trunk/getdata/src/sie.c trunk/getdata/src/types.c trunk/getdata/test/add_alias.c trunk/getdata/test/add_alias_affix.c trunk/getdata/test/add_alias_meta.c trunk/getdata/test/add_resolv.c trunk/getdata/test/add_spec_resolv.c trunk/getdata/test/alias_num.c trunk/getdata/test/alias_num_alias.c trunk/getdata/test/alias_num_missing.c trunk/getdata/test/madd_alias.c trunk/getdata/test/madd_alias_affix.c trunk/getdata/test/madd_spec_resolv.c trunk/getdata/util/checkdirfile.c trunk/getdata/util/dirfile2ascii.c Added Paths: ----------- trunk/getdata/doc/cov_mod.c Property Changed: ---------------- trunk/getdata/ Index: trunk/getdata =================================================================== --- trunk/getdata 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata 2014-02-19 00:22:56 UTC (rev 877) Property changes on: trunk/getdata ___________________________________________________________________ Modified: svn:ignore ## -7,6 +7,7 ## config.status config.sub configure +cov-int depcomp getdata_win-*.zip getdata_win-*.sig Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/ChangeLog 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,58 @@ -2014-02-21 D. V. Wiebe <ge...@ke...> svn:876 +2014-02-14 D. V. Wiebe <ge...@ke...> svn:877 + * bindings/cxx/entry.cpp (Entry::Entry): Zero E if gd_entry call fails. + + * bindings/cxx/fragment.cpp (Fragment::Fragment): Handle error in + gd_fragment_affixes call. + + * bindings/f77/fgetdata.c (GDASCA): Handle error in gd_entry call. + + * bindings/php/getdata.c (gdphp_data_to_array): Add missing break. + + * bindings/php/getdata.c (gd_error_string): Handle error in gd_error_string + call. + + * bindings/python/pygetdata.h (PYGD_REPORT_ERROR): Added. + + * bindings/python/pydirfile.c (gdpy_dirfile_getentry gdpy_dirfile_getstring + gdpy_dirfile_putcarray gdpy_dirfile_putdata) src/include.c (_GD_Include) + src/name.c (_GD_PrepareRename) src/putdata.c (_GD_DoMplexOut) src/sie.c + (_GD_SampIndWrite) src/types.c (_GD_ConvertType): Deallocate buffers on error. + + * bindings/python/pyentry.c (gdpy_entry_seta): Set a[i] if the pyobj is + complex. + + * src/bzip.c (_GD_Bzip2Size): Free ptr only after we're done with it. + + * src/common.c (_GD_CanonicalPath): Don't let readlink overrun the buffer. + Also fix double free. + + * src/entry.c (_GD_FreeE): Fix overrun on zeroing of in_fields. + + * src/entry.c (gd_linterp_tablename): Don't use field_code after free. + + * src/getdata.h.in: Remove __nonnull__ from parameter two of + gd_verbose_prefix. + + * src/gzip.c (_GD_GzipOpen): Check that _GD_MakeTempFile() worked. + + * src/open.c (_GD_CreateDirfile _GD_Open): Close descriptors on error. + + * src/parse.c (_GD_ParseCarray): Return on error. + + * src/parse.c (_GD_ParseFieldSpec): Only resize the dot_list when necessary. + Also, clean up if the resize doesn't work. + + * util/dirfile2ascii.c (main): Fix check for too many fields. + + * src/entry.c (gd_naliases): Return unsigned int and zero on error per + documentation. + * bindings/idl/getdata.c (gdidl_naliases) src/entry.c (gd_aliases) + test/add_alias.c test/add_alias_affix.c test/add_alias_meta.c + test/add_resolv.c test/add_spec_resolv.c test/alias_num.c + test/alias_num_alias.c test/alias_num_missing.c test/madd_alias.c + test/madd_alias_affix.c test/madd_spec_resolv.c: Handle unsigned gd_naliases. + +2014-02-13 D. V. Wiebe <ge...@ke...> svn:876 * bindings/python/pyfragment.c (gdpy_fragment_init): Fix typo in keyword names. Modified: trunk/getdata/NEWS =================================================================== --- trunk/getdata/NEWS 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/NEWS 2014-02-19 00:22:56 UTC (rev 877) @@ -6,6 +6,17 @@ semicolon) when the parameter is purely real. However, a non-zero imaginary part is still an error. + * gd_free_entry_strings() now NULLs pointers after freeing them. + + * gd_entry() now returns entry metadata when they contain scalar field codes + which do not exist. In this case the GD_EN_CALC flag in the object will + not be set. Previously, on such entries, this function would fail with the + error GD_E_BAD_SCALAR, and return nothing. + + * gd_rename() now by default updates the target of ALIASes pointing to a + renamed field to point to the new field instead of leaving them dangle. + (But see GD_REN_DANGLE). + * BUG FIX: The parsing of the \x and \u escape sequences are now correct. * BUG FIX: Computation of LINCOMs with complex valued input fields now @@ -26,7 +37,7 @@ Previously they would store these invalid field codes, causing problems later. - * BUG FIX: Returning complex-valued CARRAYs as purely real now works. + * BUG FIX: Returning complex-valued CARRAYs as purely real data now works. Previously only the first element requested would be returned, the remaining output buffer containing uninitialised data. @@ -34,10 +45,10 @@ entry is no longer ignored by gd_[m]add(). * BUG FIX: Entry members spf, bitnum, numbits, and period are now completely - ignored by gd_[m]add() when corresponding named scalars are specified. + ignored by gd_[m]add() if corresponding named scalars are specified. Previously, an invalid value in these members would result in the entry - being rejected, even though the rest of GetData ignored the invalid, unsued - value. + being rejected, even though the invalid value was immediately discarded + when the field was added. * BUG FIX: gd_[m]add() no longer rejects MPLEX fields with negative count_val. @@ -47,58 +58,19 @@ * BUG FIX: reading a LINTERP table with fewer than two lines no longer results in a segfault on close/discard. - * BUG FIX: DIVIDE fields with complex valued divisors are now properly + * BUG FIX: DIVIDE fields with complex-valued divisors are now properly computed. * BUG FIX: Complex-valued DIVIDE, POLYNOM, and RECIP fields are now computed properly when the library is built in ANSI C mode. - * BUG FIX: Writing complex MPLEX fields no longer corrupts the stored data. + * BUG FIX: Writing complex-valued MPLEX fields no longer corrupts the stored + data. * BUG FIX: Several fixes have been made to the sample index encoding (SIE) engine, which should now produce properly encoded data when performing random writes. - API Changes: - - * gd_free_entry_strings() now NULLs pointers after freeing them. - - * The comp_scal member of the gd_entry_t object has been replaced with a flags - member, containing a flag (GD_EN_COMPSCAL) with the meaning of the former - comp_scal member. There are also flags for hiddenness (GD_EN_HIDDEN) and - whether the scalar entries have been computed (GD_EN_CALC). - - * gd_entry() now returns entry metadata when they contain scalar field codes - which do not exist. In this case the GD_EN_CALC flag in the object will - not be set. Previously, on such entries, this function would fail with the - error GD_E_BAD_SCALAR and return nothing. - - * gd_[m]add() and gd_alter_entry() can now be used to set or change the - hiddenness of a field by setting or clearing the GD_EN_HIDDEN bit in the - supplied gd_entry_t object. - - * Two new rename flags have been added: - - GD_REN_DANGLE which indicates the library shouldn't update ALIASes whose - target has been renamed (turning them into dangling aliases) - - GD_REN_FORCE which causes the library to skip updating field codes which - would be invalid due to affixes instead of failing. - - * gd_rename() now by default updates the target of ALIASes pointing to a - renamed field to point to the new field instead of leaving them dangle. - (But see GD_REN_DANGLE). - - * The move_data argument of gd_move() has been replaced with a flags argument - which accepts the GD_REN_* flags, which have the same meaning as they do - with gd_rename(). - - * gd_move_alias() has been deleted: its function is now performed by - gd_move(). If gd_move() is passed the field code of an alias, the alias is - now moved, instead of moving the field the alias points to. - - * BUG FIX: If the dirfile path provided cannot be resolved (due to, for - instance, a symbolic link pointing to a non-existent path), gd_open() and - friends now return GD_E_OPEN, as documented, instead of GD_E_RAW_IO. - * BUG FIX: gd_bof() now returns the correct number (i.e.: zero) when reporting the beginning of field of derived fields shifted to before the start of the dirfile. Previously, this function incorrectly returned values ranging from @@ -134,11 +106,41 @@ of the affected fragment; previously, these old, cached filenames could lead to I/O errors when reading and writing the re-encoded RAW data files. - Legacy API Changes: + * BUG FIX: Calling the Legacy API function GetFormat() on a Dirfile with MPLEX + or WINDOW fields no longer results in a segmentation fault. - * BUG FIX: Calling GetFormat on a Dirfile with MPLEX or WINDOW fields no - longer results in a segmentation fault. + API Changes: + * The comp_scal member of the gd_entry_t object has been replaced with a flags + member, containing a flag (GD_EN_COMPSCAL) with the meaning of the former + comp_scal member. There are also flags for hiddenness (GD_EN_HIDDEN) and + whether the scalar entries have been computed (GD_EN_CALC). + + * gd_[m]add() and gd_alter_entry() can now be used to set or change the + hiddenness of a field by setting or clearing the GD_EN_HIDDEN bit in the + supplied gd_entry_t object. + + * Two new rename flags have been added: + - GD_REN_DANGLE which indicates the library shouldn't update ALIASes whose + target has been renamed (turning them into dangling aliases) + - GD_REN_FORCE which causes the library to skip updating field codes which + would be invalid due to affixes instead of failing. + + * The move_data argument of gd_move() has been replaced with a flags argument + which accepts the GD_REN_* flags, which have the same meaning as they do + with gd_rename(). + + * gd_move_alias() has been deleted: its function is now performed by + gd_move(). If gd_move() is passed the field code of an alias, the alias is + now moved, instead of moving the field the alias points to. + + * BUG FIX: If the dirfile path provided cannot be resolved (due to, for + instance, a symbolic link pointing to a non-existent path), gd_open() and + friends now return GD_E_OPEN, as documented, instead of GD_E_RAW_IO. + + * BUG FIX: gd_naliases() now returns an unsigned int, and zero on error, + as documented. + Bindings Changes: * PHP bindings have been added. @@ -240,10 +242,6 @@ Library Changes: - * The count_max member of the gd_entry_t object has been renamed to period. - The corresponding dummy argument in various function prototypes has been - similarly renamed. - * BUG FIX: The library no longer incorrectly rejects negative count_val MPLEX parameters. Furthermore, a count_val of -1 in gd_alter_entry or gd_[m]alter_mplex calls is not a special value: it just sets count_val to @@ -273,6 +271,12 @@ included with affixes is no longer corrupted by spurious application of the affixes when the subfragment's metadata are (re-)written. Reported by Seth. + API Changes: + + * The count_max member of the gd_entry_t object has been renamed to period. + The corresponding dummy argument in various function prototypes has been + similarly renamed. + Bindings Changes: * C++: The Entry and MplexEntry member functions CountMax and SetCountMax have @@ -340,6 +344,9 @@ Library Changes: + * gd_dirfilename() now returns a fully canonicalised version of the dirfile + path. + * BUG FIX: A segfault when negotiating symbolic links in file paths, typically manifesting in gd_open calls, has been fixed. @@ -358,6 +365,13 @@ the current Standards Version, potentially leading to rejected valid dirfiles. Reported by Daniel Flanigan. + * BUG FIX: gd_alter_entry() and gd_madd_alias() weren't clearing the Dirfile + error before operation, resulting in them failing erroneously in certain + situations. + + * BUG FIX: When including an existing fragment which itself has subfragments, + gd_include() no longer returns the wrong fragment index. + * WIN32 BUG FIX: On Windows, the parser can now properly handle hexadecimal floating point. @@ -368,21 +382,11 @@ suffix, if any, which should remove the need to do manual affix bookkeeping when reading metadata. The other side to this change is that when modifying metdata (gd_add(), gd_alter_entry(), &c.), supplied field codes must also - contain the appropriate suffixes. + contain the appropriate affixes. - * gd_dirfilename() now returns a fully canonicalised version of the dirfile - path. - * A new function, gd_linterp_tablename() has been added which returns a fully canonicalised version of the look-up table pathname for a LINTERP. - * BUG FIX: gd_alter_entry() and gd_madd_alias() weren't clearing the Dirfile - error before operation, resulting in them failing erroneously in certain - situations. - - * BUG FIX: When including an existing fragment which itself has subfragments, - gd_include() no longer returns the wrong fragment index. - Bindings Changes: * F77 BUG FIX: A memory leak has been fixed in GDALLC. @@ -537,6 +541,9 @@ documentation indicates it should) and checks the protection of the fragment containing the parent field. + * BUG FIX: calling gd_putdata() with num_frames and num_samples both zero + no longer confuses GetData: instead it simply does nothing. + API Changes: * Functions which add fields (gd_add(), gd_add_<type>(), &c.) can now be @@ -640,9 +647,6 @@ * C89 API: Passing NULL to gd_alter_crecip() for cdividend is now treated as if it were passed zero (ie. it indicates no change for cdividend). - * BUG FIX: calling gd_putdata() with num_frames and num_samples both zero - no longer confuses GetData: instead it simply does nothing. - * BUG FIX: gd_spf() now returns GD_E_DIMENSION when passed a scalar field code, as the documentation says it should. Previously it returned GD_E_BAD_FIELD_TYPE. @@ -799,6 +803,7 @@ Bindings Changes: * F77 BUG FIX: A memory leak in GDASCA has been fixed. + * Python BUG FIX: The first element of a python list (instead of a NumPy array) is no longer dropped when passed to pygetdata on 64-bit systems. Modified: trunk/getdata/bindings/cxx/entry.cpp =================================================================== --- trunk/getdata/bindings/cxx/entry.cpp 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/bindings/cxx/entry.cpp 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -// Copyright (C) 2008-2012 D. V. Wiebe +// Copyright (C) 2008-2012, 2014 D. V. Wiebe // /////////////////////////////////////////////////////////////////////////// // @@ -31,7 +31,8 @@ Entry::Entry(const GetData::Dirfile *dirfile, const char* field_code) { D = dirfile; - gd_entry(D->D, field_code, &E); + if (gd_entry(D->D, field_code, &E)) + memset(&E, 0, sizeof(E)); } Entry::~Entry() @@ -101,6 +102,19 @@ if (E.field == NULL) { E.field = strdup(new_name); } else { + /* this buffer is used if E is a metafield, in which case we'll + * replace the subfield name in E.field with new_name. The length + * of the new code is + * + * strlen(E.field) - strlen(<subfield-name>) + strlen(new_name) + * + 1 (for the trailing NUL). + * + * The subfield name in E.field must be at least one character long, so + * the length of the new code is at most: + * + * strlen(E.field) - 1 + strlen(new_name) + 1 + * = strlen(E.field) + strlen(new_name) + */ char* nn = (char*)malloc(strlen(E.field) + strlen(new_name)); strcpy(nn, E.field); ptr = strchr(nn, '/'); Modified: trunk/getdata/bindings/cxx/fragment.cpp =================================================================== --- trunk/getdata/bindings/cxx/fragment.cpp 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/bindings/cxx/fragment.cpp 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -// Copyright (C) 2008, 2010, 2011 D. V. Wiebe +// Copyright (C) 2008, 2010, 2011, 2014 D. V. Wiebe // /////////////////////////////////////////////////////////////////////////// // @@ -35,8 +35,10 @@ prot = gd_protection(D->D, index); name = gd_fragmentname(D->D, index); parent = (index == 0) ? -1 : gd_parent_fragment(D->D, index); - gd_fragment_affixes(D->D, index, &prefix, &suffix); + if (gd_fragment_affixes(D->D, index, &prefix, &suffix) == -1) + prefix = suffix = NULL; + dreturnvoid(); } Modified: trunk/getdata/bindings/f77/fgetdata.c =================================================================== --- trunk/getdata/bindings/f77/fgetdata.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/bindings/f77/fgetdata.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2013 D. V. Wiebe +/* Copyright (C) 2008-2014 D. V. Wiebe * ************************************************************************* * @@ -3142,7 +3142,10 @@ return; } - gd_entry(D, _GDF_CString(&fc, field_code, *field_code_l), &E); + if (gd_entry(D, _GDF_CString(&fc, field_code, *field_code_l), &E) == -1) { + dreturnvoid(); + return; + } switch (E.field_type) { case GD_NO_ENTRY: Modified: trunk/getdata/bindings/idl/getdata.c =================================================================== --- trunk/getdata/bindings/idl/getdata.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/bindings/idl/getdata.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2013 D. V. Wiebe +/* Copyright (C) 2009-2014 D. V. Wiebe * *************************************************************************** * @@ -5466,7 +5466,7 @@ { dtraceidl(); - int nalias; + unsigned int nalias; GDIDL_KW_ONLY_ERROR; @@ -5479,7 +5479,7 @@ IDL_KW_FREE; - IDL_VPTR r = IDL_GettmpLong(nalias); + IDL_VPTR r = IDL_GettmpUInt(nalias); dreturn("%p", r); return r; } Modified: trunk/getdata/bindings/make_parameters.c =================================================================== --- trunk/getdata/bindings/make_parameters.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/bindings/make_parameters.c 2014-02-19 00:22:56 UTC (rev 877) @@ -470,7 +470,7 @@ printf("s/@PARAMLIST@/"); for (i = 0; constant_list[i].lname != NULL; ++i) - printf("%s ", constant_list[i].sname, constant_list[i].value); + printf("%s ", constant_list[i].sname); printf("/\n"); } Modified: trunk/getdata/bindings/php/getdata.c =================================================================== --- trunk/getdata/bindings/php/getdata.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/bindings/php/getdata.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 D. V. Wiebe +/* Copyright (C) 2013, 2014 D. V. Wiebe * *************************************************************************** * @@ -1560,6 +1560,7 @@ for (i = 0; i < n; ++i) add_index_zval(a, i, gdphp_from_complex(NULL, ((float*)(data))[i * 2], ((float*)(data))[i * 2 + 1])); + break; case GD_COMPLEX128: for (i = 0; i < n; ++i) add_index_zval(a, i, gdphp_from_complex(NULL, ((double*)(data))[i * 2], @@ -3017,9 +3018,12 @@ s = gd_error_string(D, NULL, 0); - RETVAL_STRING(s, 1); - free(s); - dreturn("\"%s\"", s); + if (s) { + RETVAL_STRING(s, 1); + dreturn("\"%s\"", s); + free(s); + } else + GDPHP_RETURN_F; } PHP_FUNCTION(gd_field_list) Modified: trunk/getdata/bindings/python/pydirfile.c =================================================================== --- trunk/getdata/bindings/python/pydirfile.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/bindings/python/pydirfile.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2013 D. V. Wiebe +/* Copyright (C) 2009-2014 D. V. Wiebe * *************************************************************************** * @@ -728,6 +728,7 @@ const char *field_code; struct gdpy_entry_t *obj; gd_entry_t *E; + int e; dtrace("%p, %p, %p", self, args, keys); @@ -748,12 +749,20 @@ gd_entry(self->D, field_code, E); - PYGD_CHECK_ERROR(self->D, NULL); + if ((e = gd_error(D))) { + PYGD_REPORT_ERROR(D,e); + gd_free_entry_strings(E); + free(E); + dreturn("%p", NULL); + return NULL; + } obj = (struct gdpy_entry_t*)gdpy_entry.tp_alloc(&gdpy_entry, 0); if (obj == NULL) { PyErr_NoMemory(); + gd_free_entry_strings(E); + free(E); dreturn("%p", NULL); return NULL; } @@ -1682,7 +1691,7 @@ gd_get_string(self->D, field_code, len, data); - PYGD_CHECK_ERROR(self->D, NULL); + PYGD_CHECK_ERROR2(self->D, NULL, free(data)); pyobj = PyString_FromString(data); @@ -1848,6 +1857,7 @@ if (type == GD_UNKNOWN) { PyErr_SetString(PyExc_ValueError, "pygetdata.dirfile.put_carray() unknown data type for argument 2."); + free(data); dreturn ("%p", NULL); return NULL; } @@ -1961,6 +1971,7 @@ if (type == GD_UNKNOWN) { PyErr_SetString(PyExc_ValueError, "pygetdata.dirfile.putdata() unknown data type for argument 2."); + free(data); dreturn ("%p", NULL); return NULL; } Modified: trunk/getdata/bindings/python/pyentry.c =================================================================== --- trunk/getdata/bindings/python/pyentry.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/bindings/python/pyentry.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2013 D. V. Wiebe +/* Copyright (C) 2009-2014 D. V. Wiebe * *************************************************************************** * @@ -1828,6 +1828,8 @@ PyObject *obj = PyTuple_GetItem(value, i); if (PyComplex_Check(obj)) { comp_scal = GD_EN_COMPSCAL; + gdpy_as_complex(gd_csp_(ca[i]), obj); + a[i] = creal(ca[i]); scalar[i] = NULL; } else if (comp_scal) { gdpy_set_scalar_from_pyobj(obj, GD_COMPLEX128, scalar + i, ca + i); Modified: trunk/getdata/bindings/python/pygetdata.h =================================================================== --- trunk/getdata/bindings/python/pygetdata.h 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/bindings/python/pygetdata.h 2014-02-19 00:22:56 UTC (rev 877) @@ -69,17 +69,26 @@ #define PYGD_CHECK_ERROR2(D,R,E) \ do { \ - int the_error; \ - if ((the_error = gd_error(D))) { \ - char buffer[GD_MAX_LINE_LENGTH]; \ - PyErr_SetString(gdpy_exceptions[the_error], gd_error_string((D), \ - buffer, GD_MAX_LINE_LENGTH)); \ + int e; \ + if ((e = gd_error(D))) { \ + PYGD_REPORT_ERROR(D,e); \ E; \ dreturnvoid(); \ return (R); \ } \ } while(0) +#define PYGD_REPORT_ERROR(D,e) \ + do { \ + char *buffer = gd_error_string((D), NULL, 0); \ + if (buffer) { \ + PyErr_SetString(gdpy_exceptions[e], buffer); \ + free(buffer); \ + } else \ + PyErr_SetString(gdpy_exceptions[e], "Unspecified error"); \ + } while (0) + + extern PyObject *gdpy_exceptions[GD_N_ERROR_CODES]; extern PyTypeObject gdpy_dirfile; extern PyTypeObject gdpy_entry; Added: trunk/getdata/doc/cov_mod.c =================================================================== --- trunk/getdata/doc/cov_mod.c (rev 0) +++ trunk/getdata/doc/cov_mod.c 2014-02-19 00:22:56 UTC (rev 877) @@ -0,0 +1,87 @@ +/* This is the GetData model file for Coverity Scan. It provides hints to + * Coverity Scan's static code analysis. + * + * Although this looks like a C source file, it isn't meant to be compiled. + * Expect to see stack variables being used without initialisation. + */ + +#define assert(...) /* */ +typedef struct {int error;} DIRFILE; +typedef struct {} gd_entry_t; + +/* sets D->error to non-zero when it returns zero */ +unsigned int _GD_GetSPF(DIRFILE *D, gd_entry_t *E) +{ + unsigned int spf; + + if (spf == 0) { + assert(D->error != 0); + } + return spf; +} + +/* only allocates memory if supplied no buffer */ +char *gd_error_string(const DIRFILE *D, char *buffer, size_t buflen) +{ + if (buffer == 0) + __coverity_alloc__(buffer); + + return buffer; +} + + +/* sets D->error to non-zero when it returns NULL */ +char *_GD_MungeFrag(DIRFILE *D, const gd_entry_t *P, int me, const char *code, + int *offset) +{ + char *new_code; + if (new_code == 0) { + assert(D->error != 0); + } + return new_code; +} + +/* sets D->error to non-zero when it returns NULL */ +gd_entry_t *_GD_FindField(const DIRFILE *D, const char *field_code, + gd_entry_t *const *list, unsigned int u, int dealias, unsigned int *index) +{ + gd_entry_t *E; + if (E == 0) { + assert(D->error != 0); + } + return E; +} + +/* either sets D->error to non-zero and returns NULL or else allocates memory */ +void *_GD_Malloc(DIRFILE *D, size_t size) +{ + void *ptr; + + __coverity_alloc__(ptr); + if (ptr == 0) { + assert(D->error != 0); + } + return ptr; +} + +/* When fdopendir returns non-NULL, it has stolen the descriptor */ +typedef struct {int fd} DIR; +DIR *fdopendir(int fd) +{ + DIR *d; + if (d) { + d->fd = fd; + } + return d; +} + +int closedir(DIR *d) +{ + __coverity_close__(d->fd); +} + +/* doesn't return */ +void zend_error(int type, const char *format, ...) +{ + __coverity_panic__(); +} Modified: trunk/getdata/src/add.c =================================================================== --- trunk/getdata/src/add.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/add.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2013 D. V. Wiebe +/* Copyright (C) 2008-2014 D. V. Wiebe * *************************************************************************** * @@ -2037,25 +2037,25 @@ offset = strlen(parent) + 1; munged_code = (char *)_GD_Malloc(D, offset + strlen(field_code) + 1); - if (munged_code) { - strcpy(munged_code, parent); - munged_code[offset - 1] = '/'; - strcpy(munged_code + offset, field_code); - } - } else + if (munged_code == NULL) + goto add_alias_error; + + strcpy(munged_code, parent); + munged_code[offset - 1] = '/'; + strcpy(munged_code + offset, field_code); + } else { /* this will check for affixes and take care of detecting Barth-style * metafield definitions */ P = _GD_FixName(D, &munged_code, field_code, fragment_index, &offset); - if (D->error) - goto add_alias_error; + if (D->error) + goto add_alias_error; + } /* check alias name */ - if (munged_code && _GD_ValidateField(munged_code + offset, D->standards, 1, 0, - NULL)) - { + if (_GD_ValidateField(munged_code + offset, D->standards, 1, 0, NULL)) _GD_SetError(D, GD_E_BAD_CODE, GD_E_CODE_INVALID, NULL, 0, field_code); - } else if (_GD_FindField(D, munged_code, D->entry, D->n_entries, 1, &u)) + else if (_GD_FindField(D, munged_code, D->entry, D->n_entries, 1, &u)) _GD_SetError(D, GD_E_DUPLICATE, 0, NULL, 0, munged_code); else _GD_CheckCodeAffixes(D, NULL, target, fragment_index, 1); /* check target */ Modified: trunk/getdata/src/bzip.c =================================================================== --- trunk/getdata/src/bzip.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/bzip.c 2014-02-19 00:22:56 UTC (rev 877) @@ -268,9 +268,9 @@ ptr->pos = 0; ptr->end = n; } else { - free(ptr); BZ2_bzReadClose(&ptr->bzerror, ptr->bzfile); fclose(ptr->stream); + free(ptr); dreturn("%i", -1); return -1; } Modified: trunk/getdata/src/common.c =================================================================== --- trunk/getdata/src/common.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/common.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,5 +1,5 @@ /* Copyright (C) 2002-2005 C. Barth Netterfield - * Copyright (C) 2005-2013 D. V. Wiebe + * Copyright (C) 2005-2014 D. V. Wiebe * *************************************************************************** * @@ -1024,7 +1024,6 @@ work = (char*)malloc(PATH_MAX); if (res == NULL || work == NULL) { free(res); - free(res); dreturn("%p", NULL); return NULL; } @@ -1164,7 +1163,7 @@ } /* get the link target */ - slen = readlink(res, target, PATH_MAX); + slen = readlink(res, target, PATH_MAX - 1); if (slen == -1) { free(res); free(work); Modified: trunk/getdata/src/entry.c =================================================================== --- trunk/getdata/src/entry.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/entry.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2013 D. V. Wiebe +/* Copyright (C) 2008-2014 D. V. Wiebe * *************************************************************************** * @@ -127,7 +127,7 @@ free(entry); } else { entry->field = NULL; - memset(entry->in_fields, 0, sizeof(char*) * GD_MAX_LINCOM * 2); + memset(entry->in_fields, 0, sizeof(char*) * GD_MAX_LINCOM); memset(entry->scalar, 0, sizeof(char*) * GD_MAX_LINCOM * 2); } @@ -523,8 +523,8 @@ const char **gd_aliases(DIRFILE *D, const char *field_code) gd_nothrow { gd_entry_t *E; - int n, j = 1; - unsigned u; + int j = 1; + unsigned u, n; dtrace("%p, \"%s\"", D, field_code); @@ -573,26 +573,25 @@ return E->e->alias_list; } -int gd_naliases(DIRFILE *D, const char *field_code) gd_nothrow +unsigned int gd_naliases(DIRFILE *D, const char *field_code) gd_nothrow { gd_entry_t *E; - int n = 1; - unsigned u; + unsigned u, n = 1; dtrace("%p, \"%s\"", D, field_code); if (D->flags & GD_INVALID) { _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); - dreturn("%i", -1); - return -1; + dreturn("%u", 0); + return 0; } E = _GD_FindField(D, field_code, D->entry, D->n_entries, 1, NULL); if (E == NULL) { _GD_SetError(D, GD_E_BAD_CODE, GD_E_CODE_MISSING, NULL, 0, field_code); - dreturn("%i", -1); - return -1; + dreturn("%u", 0); + return 0; } for (u = 0; u < D->n_entries; ++u) @@ -602,7 +601,7 @@ n++; } - dreturn("%i", n); + dreturn("%u", n); return n; } @@ -870,7 +869,8 @@ free(field_code); if (E->field_type != GD_LINTERP_ENTRY) { - _GD_SetError(D, GD_E_BAD_FIELD_TYPE, GD_E_FIELD_BAD, NULL, 0, field_code); + _GD_SetError(D, GD_E_BAD_FIELD_TYPE, GD_E_FIELD_BAD, NULL, 0, + field_code_in); dreturn("%p", NULL); return NULL; } Modified: trunk/getdata/src/getdata.h.in =================================================================== --- trunk/getdata/src/getdata.h.in 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/getdata.h.in 2014-02-19 00:22:56 UTC (rev 877) @@ -1,6 +1,6 @@ /* Copyright (C) 2002-2005 C. Barth Netterfield * Copyright (C) 2003-2005 Theodore Kisner - * Copyright (C) 2005-2013 D. V. Wiebe + * Copyright (C) 2005-2014 D. V. Wiebe * *************************************************************************** * @@ -855,8 +855,8 @@ extern const char *gd_dirfilename(DIRFILE *dirfile) gd_nothrow gd_nonnull ((1)); -extern int gd_naliases(DIRFILE *dirfile, const char *field_code) gd_nothrow -gd_nonnull ((1,2)); +extern unsigned int gd_naliases(DIRFILE *dirfile, + const char *field_code) gd_nothrow gd_nonnull ((1,2)); extern gd_type_t gd_native_type(DIRFILE *dirfile, const char *field_code) gd_nothrow gd_nonnull ((1,2)); @@ -921,7 +921,7 @@ gd_nonnull((1,2)); extern int gd_verbose_prefix(DIRFILE *D, const char *prefix) gd_nothrow -gd_nonnull ((1,2)); +gd_nonnull ((1)); extern const char **gd_vector_list(DIRFILE *dirfile) gd_nothrow gd_nonnull((1)); Modified: trunk/getdata/src/gzip.c =================================================================== --- trunk/getdata/src/gzip.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/gzip.c 2014-02-19 00:22:56 UTC (rev 877) @@ -45,11 +45,6 @@ if (mode & GD_FILE_READ) { file->idata = gd_OpenAt(file->D, fd, file->name, O_RDONLY | O_BINARY, 0666); - - if (file->idata == -1) { - dreturn("%i", 1); - return 1; - } gzmode = "r"; } else if (mode & GD_FILE_TEMP) { file->idata = _GD_MakeTempFile(file->D, fd, file->name); @@ -59,6 +54,11 @@ return 1; } + if (file->idata == -1) { + dreturn("%i", 1); + return 1; + } + file->edata = gzdopen(file->idata, gzmode); if (file->edata == NULL) { Modified: trunk/getdata/src/include.c =================================================================== --- trunk/getdata/src/include.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/include.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2011 D. V. Wiebe +/* Copyright (C) 2008-2011, 2014 D. V. Wiebe * *************************************************************************** * @@ -197,6 +197,7 @@ ptr = _GD_Realloc(D, D->fragment, (++D->n_fragment) * sizeof(struct gd_fragment_t)); if (ptr == NULL) { + fclose(new_fp); _GD_ReleaseDir(D, dirfd); D->n_fragment--; goto include_error; Modified: trunk/getdata/src/lzma.c =================================================================== --- trunk/getdata/src/lzma.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/lzma.c 2014-02-19 00:22:56 UTC (rev 877) @@ -110,11 +110,9 @@ int _GD_LzmaOpen(int dirfd, struct gd_raw_file_* file, int swap gd_unused_, unsigned int mode gd_unused_) { - struct gd_lzmadata *ptr; - dtrace("%i, %p, <unused>, <unused>", dirfd, file); - file->edata = ptr = _GD_LzmaDoOpen(dirfd, file); + file->edata = _GD_LzmaDoOpen(dirfd, file); if (file->edata == NULL) { dreturn("%i", 1); Modified: trunk/getdata/src/mod.c =================================================================== --- trunk/getdata/src/mod.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/mod.c 2014-02-19 00:22:56 UTC (rev 877) @@ -112,8 +112,6 @@ *(int32_t *)lout = *(int32_t *)lin; else if (type == GD_UINT32) *(uint32_t *)lout = *(uint32_t *)lin; - else if (type == GD_INT64) - *(int64_t *)lout = *(int64_t *)lin; else if (type == GD_UINT64) *(uint64_t *)lout = *(uint64_t *)lin; else Modified: trunk/getdata/src/name.c =================================================================== --- trunk/getdata/src/name.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/name.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2013 D. V. Wiebe +/* Copyright (C) 2008-2014 D. V. Wiebe * *************************************************************************** * @@ -694,6 +694,7 @@ * fails */ rdat->meta_name = (char**)_GD_Malloc(D, sizeof(char *) * rdat->n_meta); if (!rdat->meta_name) { + _GD_CleanUpRename(rdat, 1); dreturn("%p", NULL); return NULL; } Modified: trunk/getdata/src/open.c =================================================================== --- trunk/getdata/src/open.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/open.c 2014-02-19 00:22:56 UTC (rev 877) @@ -347,6 +347,10 @@ _GD_SetError(D, GD_E_CREAT, GD_E_CREAT_FORMAT, format_file, errno, NULL); free(dirfile); free(format_file); +#ifndef GD_NO_DIR_OPEN + if (dirfd >= 0) + close(dirfd); +#endif dreturn("%p", NULL); return NULL; } @@ -364,6 +368,10 @@ free(dirfile); free(format_file); close(fd); +#ifndef GD_NO_DIR_OPEN + if (dirfd >= 0) + close(dirfd); +#endif dreturn("%p", NULL); return NULL; } @@ -459,7 +467,8 @@ if (D == NULL) { free(dirfile); #ifndef GD_NO_DIR_OPEN - close(dirfd); + if (dirfd >= 0) + close(dirfd); #endif dreturn("%p", NULL); return NULL; @@ -482,7 +491,8 @@ if (dirfile == NULL) { _GD_SetError(D, GD_E_OPEN, GD_E_OPEN_IO, filedir, dirfd_error, NULL); #ifndef GD_NO_DIR_OPEN - close(dirfd); + if (dirfd >= 0) + close(dirfd); #endif dreturn("%p", D); return D; @@ -524,7 +534,8 @@ if ((fp = _GD_CreateDirfile(D, dirfd, dirfd_error, dirfile, &mtime)) == NULL) { #ifndef GD_NO_DIR_OPEN - close(dirfd); + if (dirfd >= 0) + close(dirfd); #endif D->name = NULL; /* so a subsequent gd_discard() doesn't go awry. */ dreturn("%p", D); @@ -536,6 +547,7 @@ D->name = strdup(filedir); if (D->name == NULL) { + fclose(fp); _GD_SetError(D, GD_E_ALLOC, 0, NULL, 0, NULL); dreturn("%p", D); return D; Modified: trunk/getdata/src/parse.c =================================================================== --- trunk/getdata/src/parse.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/parse.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,5 +1,5 @@ /* Copyright (C) 2002-2005 C. Barth Netterfield - * Copyright (C) 2005-2013 D. V. Wiebe + * Copyright (C) 2005-2014 D. V. Wiebe * *************************************************************************** * @@ -1335,6 +1335,8 @@ _GD_FreeE(D, E, 1); _GD_SetError(D, GD_E_FORMAT, GD_E_FORMAT_LITERAL, format_file, line, in_cols[c]); + dreturn("%p", NULL); + return NULL; } } @@ -1626,15 +1628,6 @@ _GD_SetError(D, GD_E_FORMAT, GD_E_FORMAT_BAD_LINE, format_file, linenum, NULL); - if (is_dot) { - ptr = _GD_Realloc(D, D->dot_list, (D->n_dot + 1) * sizeof(gd_entry_t*)); - if (ptr == NULL) { - dreturn ("%p", NULL); - return NULL; - } - D->dot_list = (gd_entry_t **)ptr; - } - if (insert && D->error == GD_E_OK && E != NULL) { /* the Format file fragment index */ unsigned int u; @@ -1651,6 +1644,16 @@ return NULL; } + if (is_dot) { + ptr = _GD_Realloc(D, D->dot_list, (D->n_dot + 1) * sizeof(gd_entry_t*)); + if (ptr == NULL) { + _GD_FreeE(D, E, 1); + dreturn ("%p", NULL); + return NULL; + } + D->dot_list = (gd_entry_t **)ptr; + } + /* Initialse the meta counts */ if (P != NULL) { E->e->n_meta = -1; @@ -1663,6 +1666,9 @@ dreturn ("%p", NULL); return NULL; } + + /* Nothing may fail from now on */ + P->e->p.meta_entry = (gd_entry_t **)ptr; P->e->p.meta_entry[P->e->n_meta++] = E; } Modified: trunk/getdata/src/putdata.c =================================================================== --- trunk/getdata/src/putdata.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/putdata.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,6 +1,6 @@ /* Copyright (C) 2003-2005 C. Barth Netterfield * Copyright (C) 2003-2005 Theodore Kisner - * Copyright (C) 2005-2013 D. V. Wiebe + * Copyright (C) 2005-2014 D. V. Wiebe * *************************************************************************** * @@ -574,6 +574,7 @@ cntbuf = (int*)_GD_Alloc(D, GD_INT_TYPE, num_samp2); if (tmpbuf == NULL || cntbuf == NULL) { + free(cntbuf); free(tmpbuf); dreturn("%i", 0); return 0; Modified: trunk/getdata/src/sie.c =================================================================== --- trunk/getdata/src/sie.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/sie.c 2014-02-19 00:22:56 UTC (rev 877) @@ -335,7 +335,7 @@ f->p += nelem - count; count = nelem; } else { - cur = _GD_Duplicate(cur, f->d + 1, GD_SIZE(data_type), f->s - f->p + 1); + _GD_Duplicate(cur, f->d + 1, GD_SIZE(data_type), f->s - f->p + 1); count += f->s - f->p + 1; f->p = f->s + 1; } @@ -569,6 +569,7 @@ /* truncate the file if necessary */ if (rin < rout) { if (gd_truncate(fileno(f->fp), (nrec - rout + rin) * size)) { + free(p); dreturn("%i", -1); return -1; } Modified: trunk/getdata/src/types.c =================================================================== --- trunk/getdata/src/types.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/src/types.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,5 +1,5 @@ /* Copyright (C) 2002-2005 C. Barth Netterfield - * Copyright (C) 2005-2010 D. V. Wiebe + * Copyright (C) 2005-2010, 2014 D. V. Wiebe * *************************************************************************** * @@ -633,6 +633,7 @@ _GD_SetError(D, GD_E_BAD_TYPE, out_type, NULL, 0, NULL); break; } + break; case GD_COMPLEX128: switch (out_type) { case GD_INT8: Modified: trunk/getdata/test/add_alias.c =================================================================== --- trunk/getdata/test/add_alias.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/test/add_alias.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 D. V. Wiebe +/* Copyright (C) 2011, 2014 D. V. Wiebe * *************************************************************************** * @@ -26,7 +26,8 @@ const char *format = "dirfile/format"; const char *data = "dirfile/data"; const char *target; - int error, i, n, r = 0; + int error, i, r = 0; + unsigned int n; DIRFILE *D; rmdirfile(); @@ -51,7 +52,7 @@ CHECKI(error, GD_E_OK); CHECKI(i, 0); - CHECKI(n, 2); + CHECKU(n, 2); return r; } Modified: trunk/getdata/test/add_alias_affix.c =================================================================== --- trunk/getdata/test/add_alias_affix.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/test/add_alias_affix.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 D. V. Wiebe +/* Copyright (C) 2012, 2014 D. V. Wiebe * *************************************************************************** * @@ -27,7 +27,8 @@ const char *format1 = "dirfile/format"; const char *data = "dirfile/data"; const char *target; - int e1, e2, e3, i, n, r = 0; + int e1, e2, e3, i, r = 0; + unsigned int n; DIRFILE *D; rmdirfile(); @@ -60,7 +61,7 @@ CHECKI(e2, GD_E_BAD_CODE); CHECKI(e3, GD_E_OK); CHECKI(i, 1); - CHECKI(n, 2); + CHECKU(n, 2); return r; } Modified: trunk/getdata/test/add_alias_meta.c =================================================================== --- trunk/getdata/test/add_alias_meta.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/test/add_alias_meta.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 D. V. Wiebe +/* Copyright (C) 2012, 2014 D. V. Wiebe * *************************************************************************** * @@ -26,8 +26,9 @@ const char *format = "dirfile/format"; const char *data = "dirfile/data"; const char *target; - int error, i, n, r = 0; + int error, i, r = 0; DIRFILE *D; + unsigned int n; rmdirfile(); @@ -51,7 +52,7 @@ CHECKI(error, GD_E_OK); CHECKI(i, 0); - CHECKI(n, 2); + CHECKU(n, 2); return r; } Modified: trunk/getdata/test/add_resolv.c =================================================================== --- trunk/getdata/test/add_resolv.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/test/add_resolv.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 D. V. Wiebe +/* Copyright (C) 2011, 2014 D. V. Wiebe * *************************************************************************** * @@ -25,7 +25,8 @@ const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data"; - int error, i, n, r = 0; + int error, i, r = 0; + unsigned int n; DIRFILE *D; const char *target; @@ -51,7 +52,7 @@ CHECKI(error, GD_E_OK); CHECKI(i, 0); - CHECKI(n, 2); + CHECKU(n, 2); return r; } Modified: trunk/getdata/test/add_spec_resolv.c =================================================================== --- trunk/getdata/test/add_spec_resolv.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/test/add_spec_resolv.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 D. V. Wiebe +/* Copyright (C) 2011, 2014 D. V. Wiebe * *************************************************************************** * @@ -25,7 +25,8 @@ const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data"; - int error, i, n, r = 0; + int error, i, r = 0; + unsigned int n; DIRFILE *D; const char *target; @@ -51,7 +52,7 @@ CHECKI(error, GD_E_OK); CHECKI(i, 0); - CHECKI(n, 2); + CHECKU(n, 2); return r; } Modified: trunk/getdata/test/alias_num.c =================================================================== --- trunk/getdata/test/alias_num.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/test/alias_num.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2011, 2013 D. V. Wiebe +/* Copyright (C) 2011, 2013, 2014 D. V. Wiebe * *************************************************************************** * @@ -31,7 +31,8 @@ "/ALIAS c d\n" "/ALIAS d f\n" "f CONST UINT8 1\n"; - int fd, e, n, r = 0; + int fd, e, r = 0; + unsigned int n; DIRFILE *D; rmdirfile(); @@ -47,7 +48,7 @@ e = gd_error(D); CHECKI(e, GD_E_OK); - CHECKI(n, 6); + CHECKU(n, 6); gd_discard(D); unlink(format); Modified: trunk/getdata/test/alias_num_alias.c =================================================================== --- trunk/getdata/test/alias_num_alias.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/test/alias_num_alias.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2011, 2013 D. V. Wiebe +/* Copyright (C) 2011, 2013, 2014 D. V. Wiebe * *************************************************************************** * @@ -31,7 +31,8 @@ "/ALIAS c d\n" "/ALIAS d f\n" "f CONST UINT8 1\n"; - int fd, e, n, r = 0; + int fd, e, r = 0; + unsigned int n; DIRFILE *D; rmdirfile(); @@ -47,7 +48,7 @@ e = gd_error(D); CHECKI(e, GD_E_OK); - CHECKI(n, 6); + CHECKU(n, 6); gd_discard(D); unlink(format); Modified: trunk/getdata/test/alias_num_missing.c =================================================================== --- trunk/getdata/test/alias_num_missing.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/test/alias_num_missing.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2011, 2013 D. V. Wiebe +/* Copyright (C) 2011, 2013, 2014 D. V. Wiebe * *************************************************************************** * @@ -30,7 +30,8 @@ "/ALIAS b d\n" "/ALIAS c d\n" "/ALIAS d f\n"; - int fd, e, n, r = 0; + int fd, e, r = 0; + unsigned n; DIRFILE *D; rmdirfile(); @@ -46,7 +47,7 @@ e = gd_error(D); CHECKI(e, GD_E_BAD_CODE); - CHECKI(n, -1); + CHECKU(n, 0); gd_discard(D); unlink(format); Modified: trunk/getdata/test/madd_alias.c =================================================================== --- trunk/getdata/test/madd_alias.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/test/madd_alias.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 D. V. Wiebe +/* Copyright (C) 2011, 2014 D. V. Wiebe * *************************************************************************** * @@ -25,8 +25,9 @@ const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data"; - int error, i, n, r = 0; + int error, i, r = 0; DIRFILE *D; + unsigned int n; const char *target; rmdirfile(); @@ -51,7 +52,7 @@ CHECKI(error, GD_E_OK); CHECKI(i, 0); - CHECKI(n, 2); + CHECKU(n, 2); return r; } Modified: trunk/getdata/test/madd_alias_affix.c =================================================================== --- trunk/getdata/test/madd_alias_affix.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/test/madd_alias_affix.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 D. V. Wiebe +/* Copyright (C) 2012, 2014 D. V. Wiebe * *************************************************************************** * @@ -27,7 +27,8 @@ const char *format1 = "dirfile/format"; const char *data = "dirfile/data"; const char *target1, *target2; - int e1, e2, e3, e4, e5, i, n, r = 0; + int e1, e2, e3, e4, e5, i, r = 0; + unsigned int n; DIRFILE *D; rmdirfile(); @@ -69,7 +70,7 @@ CHECKI(e4, GD_E_OK); CHECKI(e5, GD_E_OK); CHECKI(i, 1); - CHECKI(n, 4); + CHECKU(n, 4); return r; } Modified: trunk/getdata/test/madd_spec_resolv.c =================================================================== --- trunk/getdata/test/madd_spec_resolv.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/test/madd_spec_resolv.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 D. V. Wiebe +/* Copyright (C) 2011, 2014 D. V. Wiebe * *************************************************************************** * @@ -25,7 +25,8 @@ const char *filedir = "dirfile"; const char *format = "dirfile/format"; const char *data = "dirfile/data"; - int error, i, n, r = 0; + int error, i, r = 0; + unsigned int n; DIRFILE *D; const char *target; @@ -52,7 +53,7 @@ CHECKI(error, GD_E_OK); CHECKI(i, 0); - CHECKI(n, 2); + CHECKU(n, 2); return r; } Modified: trunk/getdata/util/checkdirfile.c =================================================================== --- trunk/getdata/util/checkdirfile.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/util/checkdirfile.c 2014-02-19 00:22:56 UTC (rev 877) @@ -82,7 +82,8 @@ return 1; } - /* open the dirfile */ + /* open the dirfile -- the callback will print syntax errors as + * found, and return the number of lines with errors in ne. */ puts("Checking syntax..."); dirfile = gd_cbopen(argv[1], GD_RDONLY, callback, &ne); @@ -107,6 +108,10 @@ printf(" Syntax OK.\n\n"); + /* Run through every known standards version and check whether the dirfile + * is conformant by trying to set the loaded dirfile's version to that + * value + */ for (i = 0; i <= GD_DIRFILE_STANDARDS_VERSION; ++i) { if (gd_dirfile_standards(dirfile, i) == i) { vers[i] = 1; @@ -121,6 +126,7 @@ printf("Dirfile conforms to Standards %s ", (nvers == 1) ? "Version" : "Versions"); + /* pretty-print the list of conformed versions */ for (i = 0; i <= GD_DIRFILE_STANDARDS_VERSION; ++i) { if (vers[i]) { if (first == -1) @@ -161,7 +167,7 @@ } - /* Check the validity of each field defined */ + /* Check the validity of each entry defined */ ne = 0; puts("\nChecking fields..."); flist = gd_entry_list(dirfile, NULL, 0, GD_ENTRIES_HIDDEN | @@ -186,6 +192,8 @@ nfields++; } + /* ferret out dangling meta ALIASes by first collecting a list + * of all of them, and then trying to use them as field codes */ mflist = gd_entry_list(dirfile, flist[i], GD_ALIAS_ENTRIES, GD_ENTRIES_HIDDEN); for (j = 0; mflist[j] != NULL; ++j) { @@ -205,7 +213,8 @@ } } - /* look for dangling aliases */ + /* ferret out dangling ALIASes by first collecting a list + * of all of them, and then trying to use them as field codes */ flist = gd_entry_list(dirfile, NULL, GD_ALIAS_ENTRIES, GD_ENTRIES_HIDDEN); for (i = 0; flist[i] != NULL; ++i) { if (gd_entry_type(dirfile, flist[i]) == GD_NO_ENTRY) { Modified: trunk/getdata/util/dirfile2ascii.c =================================================================== --- trunk/getdata/util/dirfile2ascii.c 2014-02-13 21:26:18 UTC (rev 876) +++ trunk/getdata/util/dirfile2ascii.c 2014-02-19 00:22:56 UTC (rev 877) @@ -1,5 +1,5 @@ /* Copyright (C) 2010, 2011 Matthew Truch - * Copyright (C) 2010 D. V. Wiebe + * Copyright (C) 2010, 2014 D. V. Wiebe * *************************************************************************** * @@ -61,7 +61,7 @@ void version(void) { printf("dirfile2ascii (%s)\n" - "Copyright (C) 2010 Matthew Truch\n\n" + "Copyright (C) 2010, 2011, 2014 Matthew Truch and others\n\n" "Please send reports of bugs and other communication to:\n %s\n\n" "This program comes with NO WARRANTY, not even for MERCHANTABILITY " "or FITNESS\n" @@ -236,7 +236,7 @@ if (dirfile_name == NULL) { dirfile_name = optarg; } else { /* Standard output field */ - if (numfields > BUF_LEN) { + if (numfields >= BUF_LEN) { fprintf(stderr, "Error: Too many fields!\n"); exit(-2); } @@ -260,7 +260,7 @@ case 'F': case 'A': case 'a': - if (numfields > BUF_LEN) { + if (numfields >= BUF_LEN) { fprintf(stderr, "Error: Too many fields!\n"); exit(-2); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2014-03-11 01:12:32
|
Revision: 880 http://sourceforge.net/p/getdata/code/880 Author: ketiltrout Date: 2014-03-11 01:12:26 +0000 (Tue, 11 Mar 2014) Log Message: ----------- Fix matlab bindings. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/bindings/matlab/Makefile.am trunk/getdata/bindings/matlab/matlab.c trunk/getdata/bindings/matlab/test/big_test.m trunk/getdata/m4/matlab.m4 Removed Paths: ------------- trunk/getdata/bindings/matlab/gd_move_alias.c Property Changed: ---------------- trunk/getdata/bindings/matlab/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2014-03-05 22:25:36 UTC (rev 879) +++ trunk/getdata/ChangeLog 2014-03-11 01:12:26 UTC (rev 880) @@ -1,3 +1,7 @@ +2014-03-10 D. V. Wiebe <ge...@ke...> svn:880 + * bindings/matlab/gd_move_alias.c: Deleted. + * bindings/matlab/test/big_test/m: Delete test 224. + 2014-02-14 D. V. Wiebe <ge...@ke...> svn:877 * bindings/cxx/entry.cpp (Entry::Entry): Zero E if gd_entry call fails. Index: trunk/getdata/bindings/matlab =================================================================== --- trunk/getdata/bindings/matlab 2014-03-05 22:25:36 UTC (rev 879) +++ trunk/getdata/bindings/matlab 2014-03-11 01:12:26 UTC (rev 880) Property changes on: trunk/getdata/bindings/matlab ___________________________________________________________________ Modified: svn:ignore ## -53,6 +53,7 ## gd_get_string.m gd_hidden.m gd_hide.m +gd_include.m gd_include_affix.m gd_invalid_dirfile.m gd_linterp_tablename.m ## -66,7 +67,6 ## gd_mcarrays.m gd_mconstants.m gd_metaflush.m -gd_move_alias.m gd_move.m gd_mplex_lookback.m gd_mstrings.m Modified: trunk/getdata/bindings/matlab/Makefile.am =================================================================== --- trunk/getdata/bindings/matlab/Makefile.am 2014-03-05 22:25:36 UTC (rev 879) +++ trunk/getdata/bindings/matlab/Makefile.am 2014-03-11 01:12:26 UTC (rev 880) @@ -62,7 +62,7 @@ gd_linterp_tablename gd_madd gd_madd_alias \ gd_madd_carray gd_madd_const gd_madd_spec gd_madd_string \ gd_malter_spec gd_mcarrays \ - gd_mconstants gd_metaflush gd_move gd_move_alias gd_mplex_lookback \ + gd_mconstants gd_metaflush gd_move gd_mplex_lookback \ gd_mstrings gd_naliases gd_native_type gd_nentries gd_nfragments \ gd_nframes gd_open gd_parent_fragment gd_protection \ gd_put_carray_slice \ Deleted: trunk/getdata/bindings/matlab/gd_move_alias.c =================================================================== --- trunk/getdata/bindings/matlab/gd_move_alias.c 2014-03-05 22:25:36 UTC (rev 879) +++ trunk/getdata/bindings/matlab/gd_move_alias.c 2014-03-11 01:12:26 UTC (rev 880) @@ -1,55 +0,0 @@ -/* Copyright (C) 2013 D. V. Wiebe - * - *************************************************************************** - * - * This file is part of the GetData project. - * - * GetData is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * GetData is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with GetData; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "gd_matlab.h" - -/* - % GD_MOVE_ALIAS Move an alias between fragments - % - % GD_MOVE_ALIAS(DIRFILE,NAME,NEW_FRAGMENT) - % moves the alias called NAME to the fragment indexed by - % NEW_FRAGMENT. - % - % The DIRFILE object should have previously been created with GD_OPEN. - % - % See the documentation on the C API function gd_move_alias(3) in - % section 3 of the UNIX manual for more details. - % - % See also GD_MOVE, GD_OPEN - */ - -void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) -{ - DIRFILE *D; - char *field_code; - int new_frag; - - GDMX_NO_LHS; - GDMX_CHECK_RHS(3); - - D = gdmx_to_dirfile(prhs[0]); - field_code = gdmx_to_string(prhs, 1, 0); - new_frag = gdmx_to_int(prhs, 2); - - gd_move_alias(D, field_code, new_frag); - - mxFree(field_code); - gdmx_err(D, 0); -} Modified: trunk/getdata/bindings/matlab/matlab.c =================================================================== --- trunk/getdata/bindings/matlab/matlab.c 2014-03-05 22:25:36 UTC (rev 879) +++ trunk/getdata/bindings/matlab/matlab.c 2014-03-11 01:12:26 UTC (rev 880) @@ -954,7 +954,7 @@ mxSetField(lhs, 0, "in_fields", gdmx_from_nstring_list((const char**)E->in_fields, E->EN(lincom,n_fields))); - if (E->comp_scal) { + if (E->flags & GD_EN_COMPSCAL) { mxSetField(lhs, 0, "m", gdmx_from_data(E->EN(lincom,cm), GD_COMPLEX128, E->EN(lincom,n_fields))); mxSetField(lhs, 0, "b", gdmx_from_data(E->EN(lincom,cb), GD_COMPLEX128, @@ -990,7 +990,7 @@ break; case GD_POLYNOM_ENTRY: mxSetField(lhs, 0, "in_fields", mxCreateString(E->in_fields[0])); - if (E->comp_scal) { + if (E->flags & GD_EN_COMPSCAL) { mxSetField(lhs, 0, "a", gdmx_from_data(E->EN(polynom,ca), GD_COMPLEX128, E->EN(polynom,poly_ord) + 1)); } else { @@ -1006,7 +1006,7 @@ break; case GD_RECIP_ENTRY: mxSetField(lhs, 0, "in_fields", mxCreateString(E->in_fields[0])); - if (E->comp_scal) + if (E->flags & GD_EN_COMPSCAL) mxSetField(lhs, 0, "dividend", gdmx_from_cdouble((double*)&E->EN(recip,cdividend))); else @@ -1285,7 +1285,7 @@ break; case GD_LINCOM_ENTRY: E->EN(lincom,n_fields) = gdmx_convert_in_fields(rhs[n], &ctx, E); - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; gdmx_convert_entry_array(rhs[n], &ctx, "m", E->EN(lincom,cm), E->EN(lincom,n_fields)); gdmx_convert_entry_array(rhs[n], &ctx, "b", E->EN(lincom,cb), @@ -1309,7 +1309,7 @@ break; case GD_POLYNOM_ENTRY: gdmx_convert_in_fields(rhs[n], &ctx, E); - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; E->EN(polynom,poly_ord) = gdmx_convert_entry_array(rhs[n], &ctx, "a", E->EN(polynom,ca), GD_MAX_POLYORD + 1) - 1; break; @@ -1322,7 +1322,7 @@ break; case GD_RECIP_ENTRY: gdmx_convert_in_fields(rhs[n], &ctx, E); - E->comp_scal = 1; + E->flags |= GD_EN_COMPSCAL; gdmx_convert_struct_scalar(rhs[n], &ctx, "dividend", GD_COMPLEX128, &E->EN(recip,cdividend)); break; Modified: trunk/getdata/bindings/matlab/test/big_test.m =================================================================== --- trunk/getdata/bindings/matlab/test/big_test.m 2014-03-05 22:25:36 UTC (rev 879) +++ trunk/getdata/bindings/matlab/test/big_test.m 2014-03-11 01:12:26 UTC (rev 880) @@ -1809,29 +1809,15 @@ ne = ne + check_ok2(exc, 41, 1); end - % 224: move_alias - try - gd_move_alias(D, 'new20', 1); - catch exc - ne = ne + check_ok2(exc, 224, 1); - end - - try - d = gd_fragment_index(D, 'Anew20Z'); - ne = ne + check_num(224, d, 1); - catch exc - ne = ne + check_ok2(exc, 224, 2); - end - % 225: delete_alias try - gd_delete_alias(D, 'Anew20Z'); + gd_delete_alias(D, 'new20'); catch exc ne = ne + check_ok2(exc, 225, 1); end try - d = gd_fragment_index(D, 'Anew20Z'); + d = gd_fragment_index(D, 'new20'); catch exc ne = ne + check_exc2(exc, 225, 2, 'BadCode'); end Modified: trunk/getdata/m4/matlab.m4 =================================================================== --- trunk/getdata/m4/matlab.m4 2014-03-05 22:25:36 UTC (rev 879) +++ trunk/getdata/m4/matlab.m4 2014-03-11 01:12:26 UTC (rev 880) @@ -38,12 +38,18 @@ dnl try to find mex MEX="not found" if test "x$user_mex" != "x"; then - AC_MSG_CHECKING([if $user_mex is a MATLAB mex compiler]) - mex_out=`$user_mex 2>&1` + MEX=$user_mex +else + AC_PATH_PROG([MEX], [mex], [not found]) +fi + +if test "x$MEX" != "xnot found"; then + AC_MSG_CHECKING([if $MEX is a MATLAB mex compiler]) + mex_out=`$MEX 2>&1` mex_status=$? if test $mex_status -eq 1; then - if echo $mex_out | grep -q 'consult the MATLAB External Interfaces Guide'; then - MEX=$user_mex + if ! echo $mex_out | grep -q 'consult the MATLAB External Interfaces Guide'; then + MEX="not found"; fi fi if test "x$MEX" = "xnot found"; then @@ -51,14 +57,13 @@ else AC_MSG_RESULT([yes]) fi -else - AC_PATH_PROG([MEX], [mex], [not found]) fi if test "x$MEX" = "xnot found"; then have_matlab="no" MEX= fi + AC_SUBST([MEX]) ]) @@ -107,21 +112,23 @@ dnl find matlab if test "x${have_matlab}" != "xno"; then dnl try to find matlab - MATLAB="not found" if test "x$user_matlab" != "x"; then - AC_MSG_CHECKING([if $user_matlab is a MATLAB interpreter]) - GD_MATLAB_EVAL([matlab_ver], [version], [$user_matlab]) - if test "x$matlab_ver" = "x"; then - AC_MSG_RESULT([no]) - else - AC_MSG_RESULT([yes]) - MATLAB=$user_matlab - MATLAB_VERSION=$matlab_ver - fi + MATLAB=$user_matlab; else AC_PATH_PROG([MATLAB], [matlab], [not found]) fi + if test "x$MATLAB" != "xnot found"; then + AC_MSG_CHECKING([$MATLAB version]) + GD_MATLAB_EVAL([MATLAB_VERSION], [version], [$MATLAB]) + if test "x$MATLAB_VERSION" = "x"; then + AC_MSG_RESULT([none]) + MATLAB="not found" + else + AC_MSG_RESULT([$MATLAB_VERSION]) + fi + fi + if test "x$MATLAB" = "xnot found"; then have_matlab=no MATLAB= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2014-03-21 00:08:05
|
Revision: 882 http://sourceforge.net/p/getdata/code/882 Author: ketiltrout Date: 2014-03-21 00:08:01 +0000 (Fri, 21 Mar 2014) Log Message: ----------- Minor bug fixes. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/Makefile.am trunk/getdata/NEWS trunk/getdata/bindings/php/getdata.c trunk/getdata/bindings/php/test/big_test.php trunk/getdata/bindings/python/pydirfile.c trunk/getdata/test/zzslim_get.c Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2014-03-11 23:26:25 UTC (rev 881) +++ trunk/getdata/ChangeLog 2014-03-21 00:08:01 UTC (rev 882) @@ -1,3 +1,8 @@ +2014-03-20 D. V. Wiebe <ge...@ke...> svn:882 + * bindings/php/getdata.c (gd_add_polynom gd_madd_polynom): Fix array size. + * bindings/python/pydirfile.c (gdpy_dirfile_getentry): Fix segfault. + * test/zzslim_get.c: Fix. + 2014-03-10 D. V. Wiebe <ge...@ke...> svn:880 * bindings/matlab/gd_move_alias.c: Deleted. * bindings/matlab/test/big_test/m: Delete test 224. Modified: trunk/getdata/Makefile.am =================================================================== --- trunk/getdata/Makefile.am 2014-03-11 23:26:25 UTC (rev 881) +++ trunk/getdata/Makefile.am 2014-03-21 00:08:01 UTC (rev 882) @@ -1,4 +1,4 @@ -# Copyright (C) 2008, 2011 D. V. Wiebe +# Copyright (C) 2008, 2011, 2014 D. V. Wiebe # ########################################################################## # @@ -18,7 +18,7 @@ # along with GetData; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # -AUTOMAKE_OPTIONS = foreign dist-bzip2 check-news 1.10 +AUTOMAKE_OPTIONS = foreign dist-xz check-news 1.10 EXTRA_DIST = ChangeLog @@ -131,9 +131,9 @@ rm -rf crlf_export # package lists -PACKAGES=$(distdir).tar.gz $(distdir).tar.bz2 idl_$(distdir).tar.gz \ - idl_$(distdir).tar.bz2 getdata_win-$(PACKAGE_VERSION).zip \ - matlab_$(distdir).tar.gz matlab_$(distdir).tar.bz2 +PACKAGES=$(distdir).tar.gz $(distdir).tar.xz idl_$(distdir).tar.gz \ + idl_$(distdir).tar.xz getdata_win-$(PACKAGE_VERSION).zip \ + matlab_$(distdir).tar.gz matlab_$(distdir).tar.xz SIGS=$(addsuffix .sig,$(PACKAGES)) # release stuff Modified: trunk/getdata/NEWS =================================================================== --- trunk/getdata/NEWS 2014-03-11 23:26:25 UTC (rev 881) +++ trunk/getdata/NEWS 2014-03-21 00:08:01 UTC (rev 882) @@ -114,7 +114,8 @@ * The comp_scal member of the gd_entry_t object has been replaced with a flags member, containing a flag (GD_EN_COMPSCAL) with the meaning of the former comp_scal member. There are also flags for hiddenness (GD_EN_HIDDEN) and - whether the scalar entries have been computed (GD_EN_CALC). + whether the scalar entry codes in the field definition have been + dereferenced (GD_EN_CALC). * gd_[m]add() and gd_alter_entry() can now be used to set or change the hiddenness of a field by setting or clearing the GD_EN_HIDDEN bit in the Modified: trunk/getdata/bindings/php/getdata.c =================================================================== --- trunk/getdata/bindings/php/getdata.c 2014-03-11 23:26:25 UTC (rev 881) +++ trunk/getdata/bindings/php/getdata.c 2014-03-21 00:08:01 UTC (rev 882) @@ -1949,7 +1949,7 @@ long index = 0; zval *za; - double a[GD_MAX_POLYORD + 1]; + double a[2 * (GD_MAX_POLYORD + 1)]; int o; DIRFILE *D; @@ -3657,7 +3657,7 @@ int field_code_len, in_field_len, parent_len; zval *za; - double a[GD_MAX_POLYORD + 1]; + double a[2 * (GD_MAX_POLYORD + 1)]; int o; DIRFILE *D; Modified: trunk/getdata/bindings/php/test/big_test.php =================================================================== --- trunk/getdata/bindings/php/test/big_test.php 2014-03-11 23:26:25 UTC (rev 881) +++ trunk/getdata/bindings/php/test/big_test.php 2014-03-21 00:08:01 UTC (rev 882) @@ -1,5 +1,5 @@ <?php -# Copyright (C) 2013 D. V. Wiebe +# Copyright (C) 2013, 2014 D. V. Wiebe # ########################################################################## # Modified: trunk/getdata/bindings/python/pydirfile.c =================================================================== --- trunk/getdata/bindings/python/pydirfile.c 2014-03-11 23:26:25 UTC (rev 881) +++ trunk/getdata/bindings/python/pydirfile.c 2014-03-21 00:08:01 UTC (rev 882) @@ -751,7 +751,6 @@ if ((e = gd_error(self->D))) { PYGD_REPORT_ERROR(self->D,e); - gd_free_entry_strings(E); free(E); dreturn("%p", NULL); return NULL; Modified: trunk/getdata/test/zzslim_get.c =================================================================== --- trunk/getdata/test/zzslim_get.c 2014-03-11 23:26:25 UTC (rev 881) +++ trunk/getdata/test/zzslim_get.c 2014-03-21 00:08:01 UTC (rev 882) @@ -1,4 +1,4 @@ -/* Copyright (C) 2012-2013 D. V. Wiebe +/* Copyright (C) 2012-2014 D. V. Wiebe * *************************************************************************** * @@ -36,7 +36,7 @@ uint16_t c[8]; char command[4096]; uint16_t data_data[256]; - int fd, n, error, r = 0; + int i, fd, n, error, r = 0; DIRFILE *D; memset(c, 0, 8); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2014-04-04 00:09:37
|
Revision: 883 http://sourceforge.net/p/getdata/code/883 Author: ketiltrout Date: 2014-04-04 00:09:31 +0000 (Fri, 04 Apr 2014) Log Message: ----------- Don't duplicate code between the C99 and C89 gd_add_crecip, gd_madd_crecip, gd_alter_crecip functions. Fix calcuation of GD_MAX_CARRAY_LENGTH. Minor doc fixes. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/bindings/idl/test/getdata_idl_test_routines.pro trunk/getdata/man/gd_add.3 trunk/getdata/man/gd_add_bit.3 trunk/getdata/man/gd_alter_bit.3 trunk/getdata/man/gd_alter_spec.3 trunk/getdata/man/gd_bof64.3 trunk/getdata/man/gd_cbopen.3 trunk/getdata/man/gd_eof64.3 trunk/getdata/man/gd_framenum_subset64.3 trunk/getdata/man/gd_frameoffset64.3 trunk/getdata/man/gd_getdata64.3 trunk/getdata/man/gd_madd_bit.3 trunk/getdata/man/gd_nframes64.3 trunk/getdata/man/gd_putdata64.3 trunk/getdata/man/gd_seek64.3 trunk/getdata/man/gd_tell64.3 trunk/getdata/src/add.c trunk/getdata/src/getdata.c trunk/getdata/src/getdata.h.in trunk/getdata/src/mod.c trunk/getdata/src/parse.c Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/ChangeLog 2014-04-04 00:09:31 UTC (rev 883) @@ -1,3 +1,9 @@ +2014-04-03 D. V. Wiebe <ge...@ke...> svn:883 + * src/add.c (gd_add_crecip gd_madd_crecip) src/mod.c (gd_alter_crecip): Call + the ...crecip89 function. + + * src/getdata.h.in: Fix GD_MAX_CARRAY_LENGTH computation. + 2014-03-20 D. V. Wiebe <ge...@ke...> svn:882 * bindings/php/getdata.c (gd_add_polynom gd_madd_polynom): Fix array size. * bindings/python/pydirfile.c (gdpy_dirfile_getentry): Fix segfault. Modified: trunk/getdata/bindings/idl/test/getdata_idl_test_routines.pro =================================================================== --- trunk/getdata/bindings/idl/test/getdata_idl_test_routines.pro 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/bindings/idl/test/getdata_idl_test_routines.pro 2014-04-04 00:09:31 UTC (rev 883) @@ -1,3 +1,25 @@ +; vim: ft=idlang +; +; Copyright (C) 2009-2011 D. V. Wiebe +; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; This file is part of the GetData project. +; +; GetData is free software; you can redistribute it and/or modify it under +; the terms of the GNU Lesser General Public License as published by the +; Free Software Foundation; either version 2.1 of the License, or (at your +; option) any later version. +; +; GetData is distributed in the hope that it will be useful, but WITHOUT +; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +; FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +; License for more details. +; +; You should have received a copy of the GNU Lesser General Public License +; along with GetData; if not, write to the Free Software Foundation, Inc., +; 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + pro timed_demo_mode print,"" print,"**********************************************" Modified: trunk/getdata/man/gd_add.3 =================================================================== --- trunk/getdata/man/gd_add.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_add.3 2014-04-04 00:09:31 UTC (rev 883) @@ -205,8 +205,9 @@ to the value of the symbol GD_MAX_CARRAY_LENGTH defined in getdata.h. This is done to be certain that the .B CARRAY -won't overrun the line when flushed to disk. On a 32-bit system, this number -is 2**24. It is larger on a 64-bit system. +won't overrun the line when flushed to disk. On platforms with a \fIn\fR-bit +.BR size_t , +GD_MAX_CARRAY_LENGTH is 2**(\fIn\fR-8)-1. .SH SEE ALSO .BR gd_add_bit (3), Modified: trunk/getdata/man/gd_add_bit.3 =================================================================== --- trunk/getdata/man/gd_add_bit.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_add_bit.3 2014-04-04 00:09:31 UTC (rev 883) @@ -307,8 +307,9 @@ to the value of the symbol GD_MAX_CARRAY_LENGTH defined in getdata.h. This is done to be certain that the .B CARRAY -won't overrun the line when flushed to disk. On a 32-bit system, this number -is 2**24. It is larger on a 64-bit system. +won't overrun the line when flushed to disk. On platforms with a \fIn\fR-bit +.BR size_t , +GD_MAX_CARRAY_LENGTH is 2**(\fIn\fR-8)-1. The C89 GetData API provides different prototypes for .BR gd_add_clincom "(), " gd_add_cpolynom (), @@ -317,6 +318,7 @@ .PP .nf .B #define GD_C89_API +.br .B #include <getdata.h> .fi .HP @@ -328,10 +330,10 @@ .HP .BI "int gd_add_cpolynom(DIRFILE *" dirfile ", const char *" field_name , .BI "int " poly_ord ", const char *" in_fields ", const double *" ca , -.BI int " fragment_index ); +.BI "int " fragment_index ); .HP .BI "int gd_add_crecip(DIRFILE *" dirfile ", const char *" field_name , -.BI "const char *" in_field ", const double " cdividend [2], +.BI "const char *" in_field ", const double " cdividend\fR[2] , .BI "int " fragment_index ); .hy .ad n @@ -341,7 +343,7 @@ or .IR ca should have twice as many (purely real) elements, consisting of alternating -real and imaginary parts for the complex data. For example, +real and imaginary parts for the complex data. That is, for example, .IR ca [0] should be the real part of the first co-efficient, .IR ca [1] Modified: trunk/getdata/man/gd_alter_bit.3 =================================================================== --- trunk/getdata/man/gd_alter_bit.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_alter_bit.3 2014-04-04 00:09:31 UTC (rev 883) @@ -289,6 +289,7 @@ .PP .nf .B #define GD_C89_API +.br .B #include <getdata.h> .fi .HP @@ -302,7 +303,7 @@ .BI "int " poly_ord ", const char *" in_fields ", const double *" ca ); .HP .BI "int gd_alter_crecip(DIRFILE *" dirfile ", const char *" field_code , -.BI "const char *" in_field ", const double " cdividend [2]); +.BI "const char *" in_field ", const double " cdividend\fR[2] ); .hy .ad n .PP @@ -311,7 +312,7 @@ or .IR ca should have twice as many (purely real) elements, consisting of alternating -real and imaginary parts for the complex data. For example, +real and imaginary parts for the complex data. That is, for example, .IR ca [0] should be the real part of the first co-efficient, .IR ca [1] Modified: trunk/getdata/man/gd_alter_spec.3 =================================================================== --- trunk/getdata/man/gd_alter_spec.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_alter_spec.3 2014-04-04 00:09:31 UTC (rev 883) @@ -152,12 +152,13 @@ A descriptive error string for the last error encountered can be obtained from a call to .BR gd_error_string (3). -.SH BUGS +.SH NOTES If a .B CARRAY field with more than GD_MAX_CARRAY_LENGTH elements is provided, subsequent -elements will be silently truncated. GD_MAX_CARRAY_LENGTH is 2**24 on 32-bit -systems. It is larger on 64-bit systems. +elements will be silently truncated. On platforms with a \fIn\fR-bit +.BR size_t , +GD_MAX_CARRAY_LENGTH is 2**(\fIn\fR-8)-1. .SH SEE ALSO .BR gd_alter_bit (3), .BR gd_alter_const (3), Modified: trunk/getdata/man/gd_bof64.3 =================================================================== --- trunk/getdata/man/gd_bof64.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_bof64.3 2014-04-04 00:09:31 UTC (rev 883) @@ -18,7 +18,7 @@ gd_bof64 \(em retrieve data from a dirfile database, with largefile support .SH SYNOPSIS .B #define GD_64BIT_API - +.br .B #include <getdata.h> .HP .nh Modified: trunk/getdata/man/gd_cbopen.3 =================================================================== --- trunk/getdata/man/gd_cbopen.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_cbopen.3 2014-04-04 00:09:31 UTC (rev 883) @@ -720,8 +720,10 @@ .B CARRAY field to GD_MAX_CARRAY_LENGTH elements, to be certain it is always able to write the CARRAY back to disk without overrunning its maximum line length. -On 32-bit systems, GD_MAX_CARRAY_LENGTH is 2**24. It is larger on 64-bit -systems. Excess elements are silently truncated on dirfile open. +On platforms with a \fIn\fR-bit +.BR size_t , +GD_MAX_CARRAY_LENGTH is 2**(\fIn\fR-8)-1. Excess elements are silently +truncated on dirfile open. GetData's parser assumes it is running on an ASCII-compatible platform. Format specification parsing will fail gloriously on an EBCDIC platform. Modified: trunk/getdata/man/gd_eof64.3 =================================================================== --- trunk/getdata/man/gd_eof64.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_eof64.3 2014-04-04 00:09:31 UTC (rev 883) @@ -18,7 +18,7 @@ gd_eof64 \(em retrieve data from a dirfile database, with largefile support .SH SYNOPSIS .B #define GD_64BIT_API - +.br .B #include <getdata.h> .HP .nh Modified: trunk/getdata/man/gd_framenum_subset64.3 =================================================================== --- trunk/getdata/man/gd_framenum_subset64.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_framenum_subset64.3 2014-04-04 00:09:31 UTC (rev 883) @@ -19,7 +19,7 @@ field, with largefile support. .SH SYNOPSIS .B #define GD_64BIT_API - +.br .B #include <getdata.h> .HP .nh Modified: trunk/getdata/man/gd_frameoffset64.3 =================================================================== --- trunk/getdata/man/gd_frameoffset64.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_frameoffset64.3 2014-04-04 00:09:31 UTC (rev 883) @@ -19,7 +19,7 @@ offset of fields in a dirfile, with largefile support .SH SYNOPSIS .B #define GD_64BIT_API - +.br .B #include <getdata.h> .HP .nh Modified: trunk/getdata/man/gd_getdata64.3 =================================================================== --- trunk/getdata/man/gd_getdata64.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_getdata64.3 2014-04-04 00:09:31 UTC (rev 883) @@ -18,7 +18,7 @@ gd_getdata64 \(em retrieve data from a dirfile database, with largefile support .SH SYNOPSIS .B #define GD_64BIT_API - +.br .B #include <getdata.h> .HP .nh Modified: trunk/getdata/man/gd_madd_bit.3 =================================================================== --- trunk/getdata/man/gd_madd_bit.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_madd_bit.3 2014-04-04 00:09:31 UTC (rev 883) @@ -260,6 +260,7 @@ .BR gd_madd_crecip (): .PP .B #define GD_C89_API +.br .B #include <getdata.h> .HP .nh @@ -283,7 +284,7 @@ or .IR ca should have twice as many (purely real) elements, consisting of alternating -real and imaginary parts for the complex data. For example, +real and imaginary parts for the complex data. That is, for example, .IR ca [0] should be the real part of the first co-efficient, .IR ca [1] Modified: trunk/getdata/man/gd_nframes64.3 =================================================================== --- trunk/getdata/man/gd_nframes64.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_nframes64.3 2014-04-04 00:09:31 UTC (rev 883) @@ -18,7 +18,7 @@ gd_nframes64 \(em report the size of a dirfile, with largefile support .SH SYNOPSIS .B #define GD_64BIT_API - +.br .B #include <getdata.h> .HP .nh Modified: trunk/getdata/man/gd_putdata64.3 =================================================================== --- trunk/getdata/man/gd_putdata64.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_putdata64.3 2014-04-04 00:09:31 UTC (rev 883) @@ -18,7 +18,7 @@ gd_putdata64 \(em write data to a dirfile database, with largefile support .SH SYNOPSIS .B #define GD_64BIT_API - +.br .B #include <getdata.h> .HP .nh Modified: trunk/getdata/man/gd_seek64.3 =================================================================== --- trunk/getdata/man/gd_seek64.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_seek64.3 2014-04-04 00:09:31 UTC (rev 883) @@ -18,7 +18,7 @@ gd_seek64 \(em retrieve data from a dirfile database, with largefile support .SH SYNOPSIS .B #define GD_64BIT_API - +.br .B #include <getdata.h> .HP .nh Modified: trunk/getdata/man/gd_tell64.3 =================================================================== --- trunk/getdata/man/gd_tell64.3 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/man/gd_tell64.3 2014-04-04 00:09:31 UTC (rev 883) @@ -18,7 +18,7 @@ gd_tell64 \(em retrieve data from a dirfile database, with largefile support .SH SYNOPSIS .B #define GD_64BIT_API - +.br .B #include <getdata.h> .HP .nh Modified: trunk/getdata/src/add.c =================================================================== --- trunk/getdata/src/add.c 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/src/add.c 2014-04-04 00:09:31 UTC (rev 883) @@ -1087,22 +1087,9 @@ dtrace("%p, \"%s\", \"%s\", %g;%g, %i", D, field_code, in_field, creal(cdividend), cimag(cdividend), fragment_index); - if (D->flags & GD_INVALID) {/* don't crash */ - _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); - dreturn("%i", -1); - return -1; - } + error = gd_add_crecip89(D, field_code, in_field, (const double*)(&cdividend), + fragment_index); - gd_entry_t E; - memset(&E, 0, sizeof(gd_entry_t)); - E.field = (char *)field_code; - E.field_type = GD_RECIP_ENTRY; - E.EN(recip,cdividend) = cdividend; - E.flags = GD_EN_COMPSCAL; - E.in_fields[0] = (char *)in_field; - E.fragment_index = fragment_index; - error = (_GD_Add(D, &E, NULL) == NULL) ? -1 : 0; - dreturn("%i", error); return error; } @@ -1788,21 +1775,9 @@ dtrace("%p, \"%s\", \"%s\", \"%s\", %g;%g", D, parent, field_code, in_field, creal(cdividend), cimag(cdividend)); - if (D->flags & GD_INVALID) {/* don't crash */ - _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); - dreturn("%i", -1); - return -1; - } + error = gd_madd_crecip89(D, parent, field_code, in_field, + (const double*)(&cdividend)); - gd_entry_t E; - memset(&E, 0, sizeof(gd_entry_t)); - E.field = (char *)field_code; - E.field_type = GD_RECIP_ENTRY; - E.EN(recip,cdividend) = cdividend; - E.flags = GD_EN_COMPSCAL; - E.in_fields[0] = (char *)in_field; - error = (_GD_Add(D, &E, parent) == NULL) ? -1 : 0; - dreturn("%i", error); return error; } Modified: trunk/getdata/src/getdata.c =================================================================== --- trunk/getdata/src/getdata.c 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/src/getdata.c 2014-04-04 00:09:31 UTC (rev 883) @@ -1808,7 +1808,7 @@ return 0; } - dreturn("%i", len); + dreturn("%zu", len); return len; } Modified: trunk/getdata/src/getdata.h.in =================================================================== --- trunk/getdata/src/getdata.h.in 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/src/getdata.h.in 2014-04-04 00:09:31 UTC (rev 883) @@ -120,7 +120,7 @@ * whatever fits on a format file line, but that's hard to calculate. This is * 2**(n-8)-1 on a n-bit system. */ -#define GD_MAX_CARRAY_LENGTH ((int)(((unsigned int)-1) >> 8)) +#define GD_MAX_CARRAY_LENGTH (((size_t)-1) >> 8) /* error codes */ Modified: trunk/getdata/src/mod.c =================================================================== --- trunk/getdata/src/mod.c 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/src/mod.c 2014-04-04 00:09:31 UTC (rev 883) @@ -1303,26 +1303,12 @@ double complex cdividend) { int ret; - gd_entry_t N; dtrace("%p, \"%s\", \"%s\", %g;%g", D, field_code, in_field, creal(cdividend), cimag(cdividend)); - if (D->flags & GD_INVALID) {/* don't crash */ - _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); - dreturn("%i", -1); - return -1; - } + ret = gd_alter_crecip89(D, field_code, in_field, (const double*)(&cdividend)); - memset(&N, 0, sizeof(gd_entry_t)); - N.field_type = GD_RECIP_ENTRY; - N.in_fields[0] = (char *)in_field; - N.scalar[0] = (cdividend == 0) ? "" : NULL; - N.EN(recip,cdividend) = cdividend; - N.flags = GD_EN_COMPSCAL; - - ret = _GD_Change(D, field_code, &N, 0); - dreturn("%i", ret); return ret; } @@ -1334,7 +1320,7 @@ int ret; gd_entry_t N; - dtrace("%p, \"%s\", \"%s\", {%g, %g}", D, field_code, in_field, + dtrace("%p, \"%s\", \"%s\", %p={%g, %g}", D, field_code, in_field, cdividend, (cdividend == NULL) ? 0 : cdividend[0], (cdividend == NULL) ? 0 : cdividend[1]); Modified: trunk/getdata/src/parse.c =================================================================== --- trunk/getdata/src/parse.c 2014-03-21 00:08:01 UTC (rev 882) +++ trunk/getdata/src/parse.c 2014-04-04 00:09:31 UTC (rev 883) @@ -1242,7 +1242,8 @@ int pedantic, int *restrict is_dot, char **outstring, const char *tok_pos) { unsigned dummy; - int offset, c, first, n, new_z, s, z; + int offset, c, first, new_z, s, z; + size_t n; gd_type_t t; char* ptr; void *data; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2014-04-27 18:34:35
|
Revision: 887 http://sourceforge.net/p/getdata/code/887 Author: ketiltrout Date: 2014-04-27 18:34:22 +0000 (Sun, 27 Apr 2014) Log Message: ----------- SARRAY Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/man/gd_put_carray_slice.3 trunk/getdata/src/add.c trunk/getdata/src/compat.c trunk/getdata/src/constant.c trunk/getdata/src/del.c trunk/getdata/src/encoding.c trunk/getdata/src/entry.c trunk/getdata/src/errors.c trunk/getdata/src/flimits.c trunk/getdata/src/flush.c trunk/getdata/src/fpos.c trunk/getdata/src/getdata.c trunk/getdata/src/getdata.h.in trunk/getdata/src/internal.h trunk/getdata/src/legacy.c trunk/getdata/src/mod.c trunk/getdata/src/name.c trunk/getdata/src/native.c trunk/getdata/src/parse.c trunk/getdata/src/putdata.c trunk/getdata/src/spf.c trunk/getdata/src/string.c trunk/getdata/test/Makefile.am Added Paths: ----------- trunk/getdata/test/add_sarray.c trunk/getdata/test/alter_sarray.c trunk/getdata/test/get_sarray.c trunk/getdata/test/get_sarray_len.c trunk/getdata/test/get_sarray_slice.c trunk/getdata/test/get_string.c trunk/getdata/test/madd_sarray.c trunk/getdata/test/parse_sarray.c trunk/getdata/test/parse_sarray_long.c trunk/getdata/test/put_sarray.c trunk/getdata/test/put_sarray_slice.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2014-04-12 19:20:16 UTC (rev 886) +++ trunk/getdata/ChangeLog 2014-04-27 18:34:22 UTC (rev 887) @@ -1,3 +1,44 @@ +2014-04-03 D. V. Wiebe <ge...@ke...> svn:887 + * src/entry.c (_GD_FreeE _GD_CalculateEntry gd_entry gd_validate) + src/legacy.c (GetFormat) src/getdata.c (_GD_DoField) src/name.c + (_GD_UpdateInputs) src/flush.c (_GD_Flush _GD_FieldSpec _GD_FindVersion) + src/native.c (_GD_NativeType) src/spf.c (_GD_GetSPF) src/putdata.c + (_GD_DoFieldOut) src/del.c (_GD_DeReference) src/flimits.c (_GD_GetEOF + _GD_GetBOF) src/fpos.c (_GD_GetFilePos _GD_Seek) src/mod.c (_GD_Change) + src/add.c (_GD_InvalidEntype _GD_Add): Handle GD_SARRAY_ENTRY. + * src/string.c (gd_get_sarray_slice gd_get_sarray gd_sarray_len + gd_put_sarray_slice gd_put_sarray) src/mod.c (gd_alter_sarray) src/add.c + (gd_add_sarraygd_madd_sarray): Added. + * src/string.c (_GD_PutSarraySlice): Renamed from _GD_DoStringOut and + updated to handle SARRAYs. Made static. + * src/parse.c (_GD_ParseArray): Renamed from _GD_ParseCarray and updated to + handle SARRAYs. + + * test/get_sarray.c test/add_sarray.c test/get_sarray_len.c + test/get_string.c test/get_sarray_slice.c test/alter_sarray.c + test/parse_sarray.c test/madd_sarray.c test/put_sarray.c + test/put_sarray_slice.c test/parse_sarray_long.c: Added. + + * src/add.c (gd_add_string gd_madd_string): Don't call _GD_DoStringOut to + set the value, just set it directly. + + * src/compat.c: Define AT_SYMLINK_NOFOLLOW if necessary. + + * src/mod.c (_GD_Change): Report AlterScalar errors for LINCOMs. + + * src/errors.c: Add GD_E_FLUSH_WRITE and GD_E_FLUSH_TOO_LONG. + * src/flush.c (_GD_StringEscapeise): Return -1 on error; don't write + anything if stream == NULL. + * src/flush.c (_GD_StringEscapeise _GD_WriteFieldCode _GD_WriteConst + _GD_FieldSpec _GD_FlushFragment): Report write errors. + + * src/flush.c (_GD_WriteFieldCode): Write a trailing space if requested. + + * src/flush.c (_GD_FlushFragment): Try USER if LOGNAME not available. + + * src/constant.c (gd_get_carray_slice _GD_PutCarraySlice + gd_put_carray_slice): Make first long. + 2014-04-03 D. V. Wiebe <ge...@ke...> svn:883 * src/add.c (gd_add_crecip gd_madd_crecip) src/mod.c (gd_alter_crecip): Call the ...crecip89 function. Modified: trunk/getdata/man/gd_put_carray_slice.3 =================================================================== --- trunk/getdata/man/gd_put_carray_slice.3 2014-04-12 19:20:16 UTC (rev 886) +++ trunk/getdata/man/gd_put_carray_slice.3 2014-04-27 18:34:22 UTC (rev 887) @@ -139,9 +139,10 @@ .BR gd_open (3). .SH RETURN VALUE On success, -.BR gd_put_carray () +.BR gd_put_carray (), +.BR gd_put_carray_slice () and -.BR gd_put_carray_slice () +.BR gd_put_constant () return zero. On error, they return -1 and set the dirfile error to a non-zero value. Possible error values are: .TP 8 Modified: trunk/getdata/src/add.c =================================================================== --- trunk/getdata/src/add.c 2014-04-12 19:20:16 UTC (rev 886) +++ trunk/getdata/src/add.c 2014-04-27 18:34:22 UTC (rev 887) @@ -27,7 +27,8 @@ t != GD_BIT_ENTRY && t != GD_MULTIPLY_ENTRY && t != GD_PHASE_ENTRY && t != GD_CONST_ENTRY && t != GD_POLYNOM_ENTRY && t != GD_SBIT_ENTRY && t != GD_DIVIDE_ENTRY && t != GD_RECIP_ENTRY && t != GD_WINDOW_ENTRY && - t != GD_MPLEX_ENTRY && t != GD_CARRAY_ENTRY && t != GD_STRING_ENTRY) + t != GD_MPLEX_ENTRY && t != GD_CARRAY_ENTRY && t != GD_STRING_ENTRY && + t != GD_SARRAY_ENTRY) { dreturn("%i", -1); return -1; @@ -507,6 +508,19 @@ memset(E->e->u.scalar.d, 0, size); } break; + case GD_SARRAY_ENTRY: + E->EN(scalar,const_type) = GD_NULL; + E->EN(scalar,array_len) = entry->EN(scalar,array_len); + + if (E->EN(scalar,array_len) > GD_MAX_CARRAY_LENGTH) + _GD_SetError(D, GD_E_BOUNDS, 0, NULL, 0, NULL); + else { + size_t size = sizeof(const char *) * E->EN(scalar,array_len); + E->e->u.scalar.d = _GD_Malloc(D, size); + if (E->e->u.scalar.d) + memset(E->e->u.scalar.d, 0, size); + } + break; case GD_STRING_ENTRY: E->e->u.string = _GD_Strdup(D, ""); break; @@ -1296,6 +1310,7 @@ { gd_entry_t *entry; gd_entry_t S; + char *ptr; dtrace("%p, \"%s\", \"%s\", %i", D, field_code, value, fragment_index); @@ -1309,14 +1324,25 @@ S.field = (char *)field_code; S.field_type = GD_STRING_ENTRY; S.fragment_index = fragment_index; + + /* duplicate early, in case of failure */ + ptr = _GD_Strdup(D, value); + if (ptr == NULL) { + dreturn("%i", -1); + return -1; + } + entry = _GD_Add(D, &S, NULL); - /* Actually store the string, now */ - if (entry) - _GD_DoStringOut(D, entry, value); + if (D->error) { + free(ptr); + dreturn("%i", -1); + return -1; + } - dreturn("%i", D->error ? -1 : 0); - return D->error ? -1 : 0; + entry->e->u.string = ptr; + dreturn("%i", 0); + return 0; } /* add a CONST entry */ @@ -1383,6 +1409,66 @@ return D->error ? -1 : 0; } +/* add a SARRAY entry */ +int gd_add_sarray(DIRFILE* D, const char* field_code, size_t array_len, + const char **values, int fragment_index) gd_nothrow +{ + size_t i; + gd_entry_t *entry; + gd_entry_t E; + char **data; + + dtrace("%p, \"%s\", %" PRNsize_t ", %p, %i", D, field_code, array_len, values, + fragment_index); + + if (D->flags & GD_INVALID) { + _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); + dreturn("%i", -1); + return -1; + } + + memset(&E, 0, sizeof(gd_entry_t)); + E.field = (char *)field_code; + E.field_type = GD_SARRAY_ENTRY; + E.EN(scalar,array_len) = array_len; + E.fragment_index = fragment_index; + + /* duplicate early, in case of failure */ + data = _GD_Malloc(D, array_len * sizeof(char *)); + if (data == NULL) { + dreturn("%i", -1); + return -1; + } + + memset(data, 0, array_len * sizeof(char*)); + for (i = 0; i < array_len; ++i) + data[i] = _GD_Strdup(D, values[i]); + + if (D->error) { + for (i = 0; i < array_len; ++i) + free(data[i]); + free(data); + dreturn("%i", -1); + return -1; + } + + entry = _GD_Add(D, &E, NULL); + + if (D->error) { + for (i = 0; i < array_len; ++i) + free(data[i]); + free(data); + dreturn("%i", -1); + return -1; + } + + free(entry->e->u.scalar.d); + entry->e->u.scalar.d = data; + + dreturn("%i", 0); + return 0; +} + int gd_madd(DIRFILE* D, const gd_entry_t* entry, const char* parent) gd_nothrow { int ret; @@ -1877,6 +1963,7 @@ { gd_entry_t *entry; gd_entry_t S; + char *ptr; dtrace("%p, \"%s\", \"%s\", \"%s\"", D, parent, field_code, value); @@ -1890,14 +1977,25 @@ S.field = (char *)field_code; S.field_type = GD_STRING_ENTRY; S.fragment_index = 0; + + /* duplicate early, in case of failure */ + ptr = _GD_Strdup(D, value); + if (ptr == NULL) { + dreturn("%i", -1); + return -1; + } + entry = _GD_Add(D, &S, parent); - /* Actually store the string, now */ - if (entry) - _GD_DoStringOut(D, entry, value); + if (D->error) { + free(ptr); + dreturn("%i", -1); + return -1; + } - dreturn("%i", D->error ? -1 : 0); - return D->error ? -1 : 0; + entry->e->u.string = ptr; + dreturn("%i", 0); + return 0; } /* add a META CONST entry */ @@ -1964,6 +2062,65 @@ return D->error ? -1 : 0; } +/* Add META SARRAY */ +int gd_madd_sarray(DIRFILE* D, const char *parent, const char *field_code, + size_t array_len, const char **values) gd_nothrow +{ + size_t i; + gd_entry_t *entry; + gd_entry_t E; + char **data; + + dtrace("%p, \"%s\", \"%s\", %" PRNsize_t ", %p", D, parent, field_code, + array_len, values); + + if (D->flags & GD_INVALID) { + _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); + dreturn("%i", -1); + return -1; + } + + memset(&E, 0, sizeof(gd_entry_t)); + E.field = (char *)field_code; + E.field_type = GD_SARRAY_ENTRY; + E.EN(scalar,array_len) = array_len; + + /* duplicate early, in case of failure */ + data = _GD_Malloc(D, array_len * sizeof(char *)); + if (data == NULL) { + dreturn("%i", -1); + return -1; + } + + memset(data, 0, array_len * sizeof(char*)); + for (i = 0; i < array_len; ++i) + data[i] = _GD_Strdup(D, values[i]); + + if (D->error) { + for (i = 0; i < array_len; ++i) + free(data[i]); + free(data); + dreturn("%i", -1); + return -1; + } + + entry = _GD_Add(D, &E, parent); + + if (D->error) { + for (i = 0; i < array_len; ++i) + free(data[i]); + free(data); + dreturn("%i", -1); + return -1; + } + + free(entry->e->u.scalar.d); + entry->e->u.scalar.d = data; + + dreturn("%i", 0); + return 0; +} + /* add an alias */ static int _GD_AddAlias(DIRFILE *restrict D, const char *restrict parent, const char *restrict field_code, const char *restrict target, Modified: trunk/getdata/src/compat.c =================================================================== --- trunk/getdata/src/compat.c 2014-04-12 19:20:16 UTC (rev 886) +++ trunk/getdata/src/compat.c 2014-04-27 18:34:22 UTC (rev 887) @@ -1,4 +1,4 @@ -/* Copyright (C) 2010, 2011, 2012 D. V. Wiebe +/* Copyright (C) 2010-2012, 2014 D. V. Wiebe * *************************************************************************** * @@ -91,6 +91,9 @@ #endif #ifndef HAVE_FSTATAT +#ifndef AT_SYMLINK_NOFOLLOW +#define AT_SYMLINK_NOFOLLOW 0 /* will never match */ +#endif int gd_StatAt(const DIRFILE* D, int dirfd, const char* name, struct stat* buf, int flags) { @@ -100,7 +103,7 @@ dtrace("%p, %i, \"%s\", %p, %x", D, dirfd, name, buf, flags); path = _GD_MakeFullPathOnly(D, dirfd, name); -#if defined(HAVE_LSTAT) && defined(AT_SYMLINK_NOFOLLOW) +#ifdef HAVE_LSTAT if (flags & AT_SYMLINK_NOFOLLOW) ret = lstat(path, buf); else Modified: trunk/getdata/src/constant.c =================================================================== --- trunk/getdata/src/constant.c 2014-04-12 19:20:16 UTC (rev 886) +++ trunk/getdata/src/constant.c 2014-04-27 18:34:22 UTC (rev 887) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2010 D. V. Wiebe +/* Copyright (C) 2008-2010, 2014 D. V. Wiebe * *************************************************************************** * @@ -20,16 +20,16 @@ */ #include "internal.h" -int gd_get_carray_slice(DIRFILE* D, const char *field_code_in, - unsigned int start, size_t n, gd_type_t return_type, void *data_out) +int gd_get_carray_slice(DIRFILE *D, const char *field_code_in, + unsigned long start, size_t n, gd_type_t return_type, void *data_out) gd_nothrow { gd_entry_t *entry; char* field_code; int repr; - dtrace("%p, \"%s\", %i, %" PRNsize_t ", 0x%x, %p", D, field_code_in, - (int)start, n, return_type, data_out); + dtrace("%p, \"%s\", %lu, %" PRNsize_t ", 0x%x, %p", D, field_code_in, start, + n, return_type, data_out); if (D->flags & GD_INVALID) { _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); @@ -118,7 +118,7 @@ int gd_get_constant(DIRFILE* D, const char *field_code_in, gd_type_t return_type, void *data_out) gd_nothrow { - return gd_get_carray_slice(D, field_code_in, 0, 1, return_type, data_out); + return gd_get_carray(D, field_code_in, return_type, data_out); } size_t gd_carray_len(DIRFILE *D, const char *field_code_in) gd_nothrow @@ -166,12 +166,12 @@ } static int _GD_PutCarraySlice(DIRFILE* D, gd_entry_t *E, int repr, - unsigned int first, size_t n, gd_type_t data_type, const void *data_in) + unsigned long first, size_t n, gd_type_t data_type, const void *data_in) gd_nothrow { int i; - dtrace("%p, %p, %i, %u, %" PRNsize_t ", 0x%X, %p", D, E, repr, first, n, + dtrace("%p, %p, %i, %lu, %" PRNsize_t ", 0x%X, %p", D, E, repr, first, n, data_type, data_in); if ((D->flags & GD_ACCMODE) != GD_RDWR) { @@ -206,15 +206,15 @@ } int gd_put_carray_slice(DIRFILE* D, const char *field_code_in, - unsigned int first, size_t n, gd_type_t data_type, const void *data_in) + unsigned long first, size_t n, gd_type_t data_type, const void *data_in) gd_nothrow { gd_entry_t *entry; - int repr, r = 1; + int repr, r = -1; char* field_code; - dtrace("%p, \"%s\", %u, %" PRNsize_t ", 0x%X, %p", D, field_code_in, first, n, - data_type, data_in); + dtrace("%p, \"%s\", %lu, %" PRNsize_t ", 0x%X, %p", D, field_code_in, first, + n, data_type, data_in); if (D->flags & GD_INVALID) { _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); @@ -250,7 +250,7 @@ const void *data_in) gd_nothrow { gd_entry_t *entry; - int repr, r = 1; + int repr, r = -1; char* field_code; dtrace("%p, \"%s\", 0x%x, %p", D, field_code_in, data_type, data_in); Modified: trunk/getdata/src/del.c =================================================================== --- trunk/getdata/src/del.c 2014-04-12 19:20:16 UTC (rev 886) +++ trunk/getdata/src/del.c 2014-04-27 18:34:22 UTC (rev 887) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2012 D. V. Wiebe +/* Copyright (C) 2008-2012, 2014 D. V. Wiebe * *************************************************************************** * @@ -213,6 +213,7 @@ case GD_STRING_ENTRY: case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: + case GD_SARRAY_ENTRY: case GD_INDEX_ENTRY: case GD_ALIAS_ENTRY: break; Modified: trunk/getdata/src/encoding.c =================================================================== --- trunk/getdata/src/encoding.c 2014-04-12 19:20:16 UTC (rev 886) +++ trunk/getdata/src/encoding.c 2014-04-27 18:34:22 UTC (rev 887) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2013 D. V. Wiebe +/* Copyright (C) 2008-2014 D. V. Wiebe * *************************************************************************** * @@ -641,7 +641,7 @@ if (scheme == gd_ef_[i].scheme) { file->subenc = i; dreturn("0x%08lx", gd_ef_[i].scheme); - return gd_ef_[i].scheme;; + return gd_ef_[i].scheme; } } Modified: trunk/getdata/src/entry.c =================================================================== --- trunk/getdata/src/entry.c 2014-04-12 19:20:16 UTC (rev 886) +++ trunk/getdata/src/entry.c 2014-04-27 18:34:22 UTC (rev 887) @@ -23,6 +23,7 @@ void _GD_FreeE(DIRFILE *restrict D, gd_entry_t *restrict entry, int priv) { int i; + size_t n; dtrace("%p, %p, %i", D, entry, priv); @@ -77,6 +78,13 @@ if (priv) free(entry->e->u.string); break; + case GD_SARRAY_ENTRY: + if (priv) { + for (n = 0; n < entry->EN(scalar,array_len); ++n) + free(((char **)entry->e->u.scalar.d)[n]); + free(entry->e->u.scalar.d); + } + break; case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: if (priv) { @@ -103,12 +111,12 @@ free(entry->in_fields[0]); free(entry->in_fields[1]); break; + case GD_ALIAS_ENTRY: + free(entry->in_fields[0]); + break; case GD_INDEX_ENTRY: case GD_NO_ENTRY: break; - default: - if (entry->field_type == GD_ALIAS_ENTRY) - free(entry->in_fields[0]); } if (priv) { @@ -303,6 +311,7 @@ case GD_STRING_ENTRY: case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: + case GD_SARRAY_ENTRY: case GD_INDEX_ENTRY: case GD_ALIAS_ENTRY: break; @@ -480,6 +489,7 @@ case GD_INDEX_ENTRY: case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: + case GD_SARRAY_ENTRY: case GD_STRING_ENTRY: case GD_NO_ENTRY: case GD_ALIAS_ENTRY: @@ -826,6 +836,7 @@ case GD_RAW_ENTRY: case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: + case GD_SARRAY_ENTRY: case GD_STRING_ENTRY: case GD_INDEX_ENTRY: case GD_NO_ENTRY: Modified: trunk/getdata/src/errors.c =================================================================== --- trunk/getdata/src/errors.c 2014-04-12 19:20:16 UTC (rev 886) +++ trunk/getdata/src/errors.c 2014-04-27 18:34:22 UTC (rev 887) @@ -1,5 +1,5 @@ /* Copyright (C) 2002-2005 C. Barth Netterfield - * Copyright (C) 2005-2013 D. V. Wiebe + * Copyright (C) 2005-2014 D. V. Wiebe * *************************************************************************** * @@ -199,10 +199,13 @@ { GD_E_BAD_REPR, GD_E_REPR_UNKNOWN, "Unknown field representation: .{4}", 0 }, { GD_E_BAD_REPR, GD_E_REPR_PUT, "Unable to write to field reprentation: .{4}", 0 }, - /* GD_E_FLUSH: 3 = suberror, 4 = filename */ + /* GD_E_FLUSH: 3 = suberror */ { GD_E_FLUSH, GD_E_FLUSH_MKTMP, "I/O error creating temporary file: ", 1 }, { GD_E_FLUSH, GD_E_FLUSH_OPEN, "I/O error opening temporary file: ", 1 }, { GD_E_FLUSH, GD_E_FLUSH_RENAME, "I/O error replacing format metadata: ", 1 }, + { GD_E_FLUSH, GD_E_FLUSH_WRITE, "I/O error writing format metadata: ", 1 }, + { GD_E_FLUSH, GD_E_FLUSH_TOO_LONG, "Line too long writing format metadata", + 0 }, /* GD_E_BOUNDS: (nothing) */ { GD_E_BOUNDS, 0, "CARRAY length out of bounds", 0 }, /* GD_E_LINE_TOO_LONG: 2 = fragment, 3 = line number */ Modified: trunk/getdata/src/flimits.c =================================================================== --- trunk/getdata/src/flimits.c 2014-04-12 19:20:16 UTC (rev 886) +++ trunk/getdata/src/flimits.c 2014-04-27 18:34:22 UTC (rev 887) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2012 D. V. Wiebe +/* Copyright (C) 2008-2012, 2014 D. V. Wiebe * *************************************************************************** * @@ -330,6 +330,7 @@ break; case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: + case GD_SARRAY_ENTRY: case GD_STRING_ENTRY: if (parent) _GD_SetError(D, GD_E_DIMENSION, GD_E_DIM_FORMAT, parent, 0, E->field); @@ -520,6 +521,7 @@ break; case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: + case GD_SARRAY_ENTRY: case GD_STRING_ENTRY: if (parent) _GD_SetError(D, GD_E_DIMENSION, GD_E_DIM_FORMAT, parent, 0, E->field); Modified: trunk/getdata/src/flush.c =================================================================== --- trunk/getdata/src/flush.c 2014-04-12 19:20:16 UTC (rev 886) +++ trunk/getdata/src/flush.c 2014-04-27 18:34:22 UTC (rev 887) @@ -79,6 +79,7 @@ _GD_Flush(D, E->e->entry[0], syn, clo); case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: + case GD_SARRAY_ENTRY: case GD_STRING_ENTRY: case GD_INDEX_ENTRY: case GD_NO_ENTRY: @@ -222,22 +223,28 @@ return ptr; } -static size_t _GD_StringEscapeise(FILE *stream, const char *in, int meta, +static ssize_t _GD_StringEscapeise(FILE *stream, const char *in, int meta, int permissive, int standards) { const char* HexDigit = "0123456789ABCDEF"; - size_t len = 0; + ssize_t len = 0; - dtrace("%p, \"%s\", %i, %i", stream, in, permissive, standards); + dtrace("%p, \"%s\", %i, %i, %i", stream, in, meta, permissive, standards); if (in == NULL || in[0] == '\0') { - fputs("\"\"", stream); + if (stream) { + if (fputs("\"\"", stream) == EOF) + goto WRITE_ERR; + } + dreturn("%i", 2); return 2; } if (!permissive && standards < 6) { - fputs(in, stream); + if (stream) + if (fputs(in, stream) == EOF) + goto WRITE_ERR; dreturn("%" PRNsize_t, strlen(in)); return strlen(in); } @@ -251,80 +258,110 @@ #if CHAR_MIN != 0 && *in >= 0x00 #endif - ) { - fputs("\\x", stream); - fputc(HexDigit[*in >> 8], stream); - fputc(HexDigit[*in & 0xF], stream); + ) + { + if (stream) { + if (fputs("\\x", stream) == EOF) + goto WRITE_ERR; + if (fputc(HexDigit[*in >> 8], stream) == EOF) + goto WRITE_ERR; + if (fputc(HexDigit[*in & 0xF], stream) == EOF) + goto WRITE_ERR; + } len += 4; } else if (meta && *in == '/') break; else { - fputc(*in, stream); + if (stream) + if (fputc(*in, stream) == EOF) + goto WRITE_ERR; len++; } } dreturn("%" PRNsize_t, len); return len; + +WRITE_ERR: + dreturn("%i", -1); + return -1; } /* write a field code, taking care of stripping off affixes; returns the length * written */ -static size_t _GD_WriteFieldCode(DIRFILE *D, FILE *stream, int me, - const char *code, int permissive, int standards) +static ssize_t _GD_WriteFieldCode(DIRFILE *D, FILE *stream, int me, + const char *code, int permissive, int standards, int space) { int dummy; - size_t len; + ssize_t len; char *ptr; - dtrace("%p, %p, %i, \"%s\", %i, %i", D, stream, me, code, permissive, - standards); + dtrace("%p, %p, %i, \"%s\", %i, %i, %i", D, stream, me, code, permissive, + standards, space); ptr = _GD_MungeCode(D, NULL, D->fragment[me].prefix, D->fragment[me].suffix, NULL, NULL, code, &dummy, 0); len = _GD_StringEscapeise(stream, ptr, 0, permissive, standards); + /* append a space */ + if (space && len > 0) { + if (fputc(' ', stream) == EOF) + len = -1; + else + len++; + } + free(ptr); - dreturn("%" PRNsize_t, len); + dreturn("%" PRNssize_t, len); return len; } /* write a field, padding to the specified length */ -static void _GD_PadField(DIRFILE *D, FILE *stream, int me, const char *in, - size_t len, int permissive, int standards) +static ssize_t _GD_PadField(DIRFILE *D, FILE *stream, int me, const char *in, + ssize_t len, int permissive, int standards) { - size_t i; + ssize_t i; dtrace("%p, %p, %i, \"%s\", %" PRNsize_t ", %i, %i", D, stream, me, in, len, permissive, standards); - for (i = _GD_WriteFieldCode(D, stream, me, in, permissive, standards); - i < len; ++i) - { - fputc(' ', stream); - } + i = _GD_WriteFieldCode(D, stream, me, in, permissive, standards, 0); - dreturnvoid(); + if (i >= 0) + for (; i < len; ++i) + if (fputc(' ', stream) == EOF) { + i = -1; + break; + } + + dreturn("%" PRNssize_t, i); + return i; } /* Write a litteral parameter or CONST name or CARRAY element */ -static void _GD_WriteConst(DIRFILE *D, FILE* stream, int me, int permissive, - int type, const void* value, const char* scalar, int index, - const char* postamble) +static int _GD_WriteConst(DIRFILE *D, FILE *stream, int me, int permissive, + int type, const void* value, const char *scalar, int index, + const char *postamble) { + int e; + dtrace("%p, %p, %i, %i, 0x%X, %p, \"%s\", %i, \"%s\"", D, stream, me, permissive, type, value, scalar, index, postamble); if (scalar != NULL) { - _GD_WriteFieldCode(D, stream, me, scalar, permissive, D->standards); + if (_GD_WriteFieldCode(D, stream, me, scalar, permissive, D->standards, 0) + < 0) + { + dreturn("%i", -1); + return -1; + } if (index == -1) fprintf(stream, "%s", postamble); else fprintf(stream, "<%i>%s", index, postamble); - } - else if (type == GD_UINT64) + } else if (type == GD_UINT64) fprintf(stream, "%" PRIu64 "%s", *(uint64_t *)value, postamble); else if (type == GD_INT64) fprintf(stream, "%" PRIi64 "%s", *(int64_t *)value, postamble); @@ -341,260 +378,393 @@ else if (type == GD_COMPLEX128) fprintf(stream, "%.15g;%.15g%s", *(double *)value, ((double *)value)[1], postamble); - else + else { _GD_InternalError(D); + dreturn("%i", -1); + return -1; + } - dreturnvoid(); + e = ferror(stream); + dreturn("%i", e); + return e; } /* Write a field specification line */ -static void _GD_FieldSpec(DIRFILE* D, FILE* stream, const gd_entry_t* E, +static int _GD_FieldSpec(DIRFILE* D, FILE* stream, const gd_entry_t* E, int me, int meta, size_t max_len, int pretty, int permissive) { int i; + char *ptr; + ssize_t len, pos; + char buffer[1000]; size_t z; - char *ptr; dtrace("%p, %p, %p, %i, %i, %" PRNsize_t ", %i, %i", D, stream, E, me, meta, max_len, pretty, permissive); /* INDEX is implicit, and it is an error to define it in the format file */ if (E->field_type == GD_INDEX_ENTRY) { - dreturnvoid(); - return; + dreturn("%i", 0); + return 0; } /* aliases */ if (E->field_type == GD_ALIAS_ENTRY) { - fputs("/ALIAS ", stream); - _GD_WriteFieldCode(D, stream, me, E->field, permissive, D->standards); - fputc(' ', stream); - _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, - D->standards); - fputc('\n', stream); + if (fputs("/ALIAS ", stream) == EOF) + goto WRITE_ERR; + if (_GD_WriteFieldCode(D, stream, me, E->field, permissive, D->standards, 1) + < 0) + { + goto WRITE_ERR; + } + if (_GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, + D->standards, 0) < 0) + { + goto WRITE_ERR; + } + if (fputc('\n', stream) == EOF) + goto WRITE_ERR; } else { ptr = E->field; /* From Standards Version 7 and on, just use Barth-style */ if (meta && D->standards < 7) { - fputs("META ", stream); - _GD_StringEscapeise(stream, ptr, 1, permissive, D->standards); - fputc(' ', stream); + if (fputs("META ", stream) == EOF) + goto WRITE_ERR; + if (_GD_StringEscapeise(stream, ptr, 1, permissive, D->standards) < 0) + goto WRITE_ERR; + if (fputc(' ', stream) == EOF) + goto WRITE_ERR; ptr = strchr(E->field, '/') + 1; } /* field name */ - _GD_PadField(D, stream, me, ptr, max_len, permissive, D->standards); + if (_GD_PadField(D, stream, me, ptr, max_len, permissive, D->standards) < 0) + goto WRITE_ERR; switch(E->field_type) { case GD_RAW_ENTRY: - fprintf(stream, " RAW%s %s ", pretty ? " " : "", - (permissive || D->standards >= 5) ? _GD_TypeName(D, - E->EN(raw,data_type)) : _GD_OldTypeName(D, E->EN(raw,data_type))); - _GD_WriteConst(D, stream, me, permissive, GD_UINT_TYPE, &E->EN(raw,spf), - E->scalar[0], E->scalar_ind[0], "\n"); + if (fprintf(stream, " RAW%s %s ", pretty ? " " : "", (permissive || + D->standards >= 5) ? _GD_TypeName(D, E->EN(raw,data_type)) : + _GD_OldTypeName(D, E->EN(raw,data_type))) < 0 || + _GD_WriteConst(D, stream, me, permissive, GD_UINT_TYPE, + &E->EN(raw,spf), E->scalar[0], E->scalar_ind[0], "") < 0) + { + goto WRITE_ERR; + } break; case GD_LINCOM_ENTRY: - fprintf(stream, " LINCOM%s %i", pretty ? " " : "", - E->EN(lincom,n_fields)); + if (fprintf(stream, " LINCOM%s %i ", pretty ? " " : "", + E->EN(lincom,n_fields)) < 0) + { + goto WRITE_ERR; + } for (i = 0; i < E->EN(lincom,n_fields); ++i) { - fputc(' ', stream); - _GD_WriteFieldCode(D, stream, me, E->in_fields[i], permissive, - D->standards); - fputc(' ', stream); + if (_GD_WriteFieldCode(D, stream, me, E->in_fields[i], permissive, + D->standards, 1) < 0) + { + goto WRITE_ERR; + } + if (E->flags & GD_EN_COMPSCAL) { - _GD_WriteConst(D, stream, me, permissive, GD_COMPLEX128, - &E->EN(lincom,cm)[i], E->scalar[i], E->scalar_ind[i], " "); - _GD_WriteConst(D, stream, me, permissive, GD_COMPLEX128, - &E->EN(lincom,cb)[i], E->scalar[i + GD_MAX_LINCOM], - E->scalar_ind[i + GD_MAX_LINCOM], ""); + if (_GD_WriteConst(D, stream, me, permissive, GD_COMPLEX128, + &E->EN(lincom,cm)[i], E->scalar[i], E->scalar_ind[i], " ") < 0 + || _GD_WriteConst(D, stream, me, permissive, GD_COMPLEX128, + &E->EN(lincom,cb)[i], E->scalar[i + GD_MAX_LINCOM], + E->scalar_ind[i + GD_MAX_LINCOM], + i == E->EN(lincom,n_fields) - 1 ? "" : " ") < 0) + { + goto WRITE_ERR; + } } else { - _GD_WriteConst(D, stream, me, permissive, GD_FLOAT64, - &E->EN(lincom,m)[i], E->scalar[i], E->scalar_ind[i], " "); - _GD_WriteConst(D, stream, me, permissive, GD_FLOAT64, - &E->EN(lincom,b)[i], E->scalar[i + GD_MAX_LINCOM], - E->scalar_ind[i + GD_MAX_LINCOM], ""); + if (_GD_WriteConst(D, stream, me, permissive, GD_FLOAT64, + &E->EN(lincom,m)[i], E->scalar[i], E->scalar_ind[i], " ") < 0 + || _GD_WriteConst(D, stream, me, permissive, GD_FLOAT64, + &E->EN(lincom,b)[i], E->scalar[i + GD_MAX_LINCOM], + E->scalar_ind[i + GD_MAX_LINCOM], + i == E->EN(lincom,n_fields) - 1 ? "" : " ") < 0) + { + goto WRITE_ERR; + } } } - fputc('\n', stream); break; case GD_LINTERP_ENTRY: - fprintf(stream, " LINTERP%s ", pretty ? " " : ""); - _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, - D->standards); - fputc(' ', stream); - _GD_StringEscapeise(stream, E->EN(linterp,table), 0, permissive, - D->standards); - fputc('\n', stream); + if (fprintf(stream, " LINTERP%s ", pretty ? " " : "") < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, + D->standards, 1) < 0 || + _GD_StringEscapeise(stream, E->EN(linterp,table), 0, permissive, + D->standards) < 0) + { + goto WRITE_ERR; + } break; case GD_BIT_ENTRY: - fprintf(stream, " BIT%s ", pretty ? " " : ""); - _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, - D->standards); - fputc(' ', stream); - _GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, - &E->EN(bit,bitnum), E->scalar[0], E->scalar_ind[0], " "); - _GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, - &E->EN(bit,numbits), E->scalar[1], E->scalar_ind[1], "\n"); + if (fprintf(stream, " BIT%s ", pretty ? " " : "") < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, + D->standards, 1) < 0 || + _GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, + &E->EN(bit,bitnum), E->scalar[0], E->scalar_ind[0], " ") < 0 || + _GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, + &E->EN(bit,numbits), E->scalar[1], E->scalar_ind[1], "") < 0) + { + goto WRITE_ERR; + } break; case GD_DIVIDE_ENTRY: - fprintf(stream, " DIVIDE%s ", pretty ? " " : ""); - _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, - D->standards); - fputc(' ', stream); - _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive, - D->standards); - fputc('\n', stream); + if (fprintf(stream, " DIVIDE%s ", pretty ? " " : "") < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, + D->standards, 1) < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive, + D->standards, 0) < 0) + { + goto WRITE_ERR; + } break; case GD_RECIP_ENTRY: - fprintf(stream, " RECIP%s ", pretty ? " " : ""); - _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, - D->standards); - fputc(' ', stream); - _GD_WriteConst(D, stream, me, permissive, GD_COMPLEX128, - &E->EN(recip,cdividend), E->scalar[0], E->scalar_ind[0], "\n"); + if (fprintf(stream, " RECIP%s ", pretty ? " " : "") < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, + D->standards, 1) < 0 || + _GD_WriteConst(D, stream, me, permissive, GD_COMPLEX128, + &E->EN(recip,cdividend), E->scalar[0], E->scalar_ind[0], "") < 0) + { + goto WRITE_ERR; + } break; case GD_MULTIPLY_ENTRY: - fputs(" MULTIPLY ", stream); - _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, - D->standards); - fputc(' ', stream); - _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive, - D->standards); - fputc('\n', stream); + if (fputs(" MULTIPLY ", stream) == EOF || + _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, + D->standards, 1) < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive, + D->standards, 0) < 0) + { + goto WRITE_ERR; + } break; case GD_PHASE_ENTRY: - fprintf(stream, " PHASE%s ", pretty ? " " : ""); - _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, - D->standards); - fputc(' ', stream); - _GD_WriteConst(D, stream, me, permissive, GD_INT64, &E->EN(phase,shift), - E->scalar[0], E->scalar_ind[0], "\n"); + if (fprintf(stream, " PHASE%s ", pretty ? " " : "") < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, + D->standards, 1) < 0 || + _GD_WriteConst(D, stream, me, permissive, GD_INT64, + &E->EN(phase,shift), E->scalar[0], E->scalar_ind[0], "") < 0) + { + goto WRITE_ERR; + } break; case GD_POLYNOM_ENTRY: - fprintf(stream, " POLYNOM%s ", pretty ? " " : ""); - _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, - D->standards); - fputc(' ', stream); + if (fprintf(stream, " POLYNOM%s ", pretty ? " " : "") < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, + D->standards, 1) < 0) + { + goto WRITE_ERR; + } for (i = 0; i <= E->EN(polynom,poly_ord); ++i) - if (E->flags & GD_EN_COMPSCAL) - _GD_WriteConst(D, stream, me, permissive, GD_COMPLEX128, + if (E->flags & GD_EN_COMPSCAL) { + if (_GD_WriteConst(D, stream, me, permissive, GD_COMPLEX128, &E->EN(polynom,ca)[i], E->scalar[i], E->scalar_ind[i], - (i == E->EN(polynom,poly_ord)) ? "\n" : " "); - else - _GD_WriteConst(D, stream, me, permissive, GD_FLOAT64, + (i == E->EN(polynom,poly_ord)) ? "" : " ") < 0) + { + goto WRITE_ERR; + } + } else { + if (_GD_WriteConst(D, stream, me, permissive, GD_FLOAT64, &E->EN(polynom,a)[i], E->scalar[i], E->scalar_ind[i], - (i == E->EN(polynom,poly_ord)) ? "\n" : " "); + (i == E->EN(polynom,poly_ord)) ? "" : " ") < 0) + { + goto WRITE_ERR; + } + } break; case GD_SBIT_ENTRY: - fprintf(stream, " SBIT%s ", pretty ? " " : ""); - _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, - D->standards); - fputc(' ', stream); - _GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, - &E->EN(bit,bitnum), E->scalar[0], E->scalar_ind[0], " "); - _GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, - &E->EN(bit,numbits), E->scalar[1], E->scalar_ind[1], "\n"); + if (fprintf(stream, " SBIT%s ", pretty ? " " : "") < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, + D->standards, 1) < 0 || + _GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, + &E->EN(bit,bitnum), E->scalar[0], E->scalar_ind[0], " ") < 0 || + _GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, + &E->EN(bit,numbits), E->scalar[1], E->scalar_ind[1], "") < 0) + { + goto WRITE_ERR; + } break; case GD_WINDOW_ENTRY: - fprintf(stream, " WINDOW%s ", pretty ? " " : ""); - _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, - D->standards); - fputc(' ', stream); - _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive, - D->standards); - fprintf(stream, " %s ", _GD_WindopName(D, E->EN(window,windop))); + if (fprintf(stream, " WINDOW%s ", pretty ? " " : "") < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, + D->standards, 1) < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive, + D->standards, 0) < 0 || + fprintf(stream, " %s ", _GD_WindopName(D, E->EN(window,windop))) + < 0) + { + goto WRITE_ERR; + } switch (E->EN(window,windop)) { case GD_WINDOP_EQ: case GD_WINDOP_NE: - _GD_WriteConst(D, stream, me, permissive, GD_INT64, - &E->EN(window,threshold.i), E->scalar[0], E->scalar_ind[0], - "\n"); + if (_GD_WriteConst(D, stream, me, permissive, GD_INT64, + &E->EN(window,threshold.i), E->scalar[0], E->scalar_ind[0], + "") < 0) + { + goto WRITE_ERR; + } break; case GD_WINDOP_SET: case GD_WINDOP_CLR: - _GD_WriteConst(D, stream, me, permissive, GD_UINT64, + if (_GD_WriteConst(D, stream, me, permissive, GD_UINT64, &E->EN(window,threshold.u), E->scalar[0], E->scalar_ind[0], - "\n"); + "") < 0) + { + goto WRITE_ERR; + } break; default: - _GD_WriteConst(D, stream, me, permissive, GD_FLOAT64, + if (_GD_WriteConst(D, stream, me, permissive, GD_FLOAT64, &E->EN(window,threshold.r), E->scalar[0], E->scalar_ind[0], - "\n"); + "") < 0) + { + goto WRITE_ERR; + } break; } break; case GD_MPLEX_ENTRY: - fprintf(stream, " MPLEX%s ", pretty ? " " : ""); - _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, - D->standards); - fputc(' ', stream); - _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive, - D->standards); - fputc(' ', stream); - _GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, - &E->EN(mplex,count_val), E->scalar[0], E->scalar_ind[0], ""); - if (E->EN(mplex,period) > 0 || E->scalar[1]) { - fputc(' ', stream); - _GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, - &E->EN(mplex,period), E->scalar[1], E->scalar_ind[1], "\n"); - } else - fputc('\n', stream); + if (fprintf(stream, " MPLEX%s ", pretty ? " " : "") < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, + D->standards, 1) < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive, + D->standards, 1) < 0 || + _GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, + &E->EN(mplex,count_val), E->scalar[0], E->scalar_ind[0], " ") < 0 + || _GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, + &E->EN(mplex,period), E->scalar[1], E->scalar_ind[1], "") < 0) + { + goto WRITE_ERR; + } break; case GD_CONST_ENTRY: - fprintf(stream, " CONST%s %s ", pretty ? " " : "", _GD_TypeName(D, - E->EN(scalar,const_type))); - if (E->EN(scalar,const_type) & GD_SIGNED) - fprintf(stream, "%" PRIi64 "\n", *(int64_t*)E->e->u.scalar.d); - else if (E->EN(scalar,const_type) & GD_IEEE754) - fprintf(stream, "%.15g\n", *(double*)E->e->u.scalar.d); - else if (E->EN(scalar,const_type) & GD_COMPLEX) - fprintf(stream, "%.15g;%.15g\n", *(double*)E->e->u.scalar.d, - *((double*)E->e->u.scalar.d + 1)); - else - fprintf(stream, "%" PRIu64 "\n", *(uint64_t*)E->e->u.scalar.d); + if (fprintf(stream, " CONST%s %s ", pretty ? " " : "", _GD_TypeName(D, + E->EN(scalar,const_type))) < 0) + { + goto WRITE_ERR; + } + if (E->EN(scalar,const_type) & GD_SIGNED) { + if (fprintf(stream, "%" PRIi64, *(int64_t*)E->e->u.scalar.d) < 0) + goto WRITE_ERR; + } else if (E->EN(scalar,const_type) & GD_IEEE754) { + if (fprintf(stream, "%.15g", *(double*)E->e->u.scalar.d) < 0) + goto WRITE_ERR; + } else if (E->EN(scalar,const_type) & GD_COMPLEX) { + if (fprintf(stream, "%.15g;%.15g", *(double*)E->e->u.scalar.d, + *((double*)E->e->u.scalar.d + 1)) < 0) + { + goto WRITE_ERR; + } + } else + if (fprintf(stream, "%" PRIu64, *(uint64_t*)E->e->u.scalar.d) < 0) + goto WRITE_ERR; break; case GD_CARRAY_ENTRY: - fprintf(stream, " CARRAY%s %s", pretty ? " " : "", _GD_TypeName(D, - E->EN(scalar,const_type))); - if (E->EN(scalar,const_type) & GD_SIGNED) - for (z = 0; z < E->EN(scalar,array_len); ++z) - fprintf(stream, " %" PRIi64, ((int64_t*)E->e->u.scalar.d)[z]); - else if (E->EN(scalar,const_type) & GD_IEEE754) - for (z = 0; z < E->EN(scalar,array_len); ++z) - fprintf(stream, " %.15g", ((double*)E->e->u.scalar.d)[z]); - else if (E->EN(scalar,const_type) & GD_COMPLEX) - for (z = 0; z < E->EN(scalar,array_len); ++z) - fprintf(stream, " %.15g;%.15g", ((double*)E->e->u.scalar.d)[2 * z], + pos = fprintf(stream, " CARRAY%s %s", pretty ? " " : "", + _GD_TypeName(D, E->EN(scalar,const_type))); + if (pos < 0) + goto WRITE_ERR; + + for (z = 0; z < E->EN(scalar,array_len); ++z) { + if (E->EN(scalar,const_type) & GD_SIGNED) + len = sprintf(buffer, " %" PRIi64, ((int64_t*)E->e->u.scalar.d)[z]); + else if (E->EN(scalar,const_type) & GD_IEEE754) + len = sprintf(buffer, " %.15g", ((double*)E->e->u.scalar.d)[z]); + else if (E->EN(scalar,const_type) & GD_COMPLEX) + len = sprintf(buffer, " %.15g;%.15g", + ((double*)E->e->u.scalar.d)[2 * z], ((double*)E->e->u.scalar.d)[2 * z + 1]); - else - for (z = 0; z < E->EN(scalar,array_len); ++z) - fprintf(stream, " %" PRIu64, ((uint64_t*)E->e->u.scalar.d)[z]); - fputc('\n', stream); + else + len = sprintf(buffer, " %" PRIu64, + ((uint64_t*)E->e->u.scalar.d)[z]); + + /* don't write lines that are too long + * also, add one to length for the trailing '\n' */ + if (GD_SSIZE_T_MAX - (len + 1) <= pos) { + _GD_SetError(D, GD_E_FLUSH, GD_E_FLUSH_TOO_LONG, NULL, 0, NULL); + dreturn("%i", -1); + return -1; + } + if (fputs(buffer, stream) == EOF) + goto WRITE_ERR; + } break; case GD_STRING_ENTRY: - fprintf(stream, " STRING%s ", pretty ? " " : ""); - _GD_StringEscapeise(stream, E->e->u.string, 0, permissive, - D->standards); - fputc('\n', stream); + if (fprintf(stream, " STRING%s ", pretty ? " " : "") < 0) + goto WRITE_ERR; + if (_GD_StringEscapeise(stream, E->e->u.string, 0, permissive, + D->standards) < 0) + { + goto WRITE_ERR; + } break; + case GD_SARRAY_ENTRY: + pos = fprintf(stream, " SARRAY%s", pretty ? " " : ""); + if (pos < 0) + goto WRITE_ERR; + + for (z = 0; z < E->EN(scalar,array_len); ++z) { + if (fputc(' ', stream) == EOF) + goto WRITE_ERR; + pos++; + + /* compute length */ + len = _GD_StringEscapeise(NULL, ((char**)E->e->u.scalar.d)[z], 0, + permissive, D->standards); + + /* don't write lines that are too long + * also, add one to length for the trailing '\n' */ + if (GD_SSIZE_T_MAX - (len + 1) <= pos) { + _GD_SetError(D, GD_E_FLUSH, GD_E_FLUSH_TOO_LONG, NULL, 0, NULL); + dreturn("%i", -1); + return -1; + } + + if (_GD_StringEscapeise(stream, ((char**)E->e->u.scalar.d)[z], 0, + permissive, D->standards) < 0) + { + goto WRITE_ERR; + } + } + break; case GD_INDEX_ENTRY: case GD_ALIAS_ENTRY: case GD_NO_ENTRY: _GD_InternalError(D); - break; + dreturn("%i", -1); + return -1; } + + if (fputc('\n', stream) == EOF) + goto WRITE_ERR; } if (!D->error && (E->flags & GD_EN_HIDDEN) && (permissive || D->standards >= 9)) { - fputs("/HIDDEN ", stream); - _GD_WriteFieldCode(D, stream, me, E->field, permissive, D->standards); - fputc('\n', stream); + if (fputs("/HIDDEN ", stream) == EOF) + goto WRITE_ERR; + if (_GD_WriteFieldCode(D, stream, me, E->field, permissive, D->standards, 0) + < 0) + { + goto WRITE_ERR; + } + if (fputc('\n', stream) == EOF) + goto WRITE_ERR; } - dreturnvoid(); + dreturn("%i", 0); + return 0; + +WRITE_ERR: + if (!D->error) + _GD_SetError(D, GD_E_FLUSH, GD_E_FLUSH_WRITE, NULL, errno, NULL); + dreturn("%i", -1); + return -1; } static void _GD_FlushFragment(DIRFILE* D, int i, int permissive) @@ -607,7 +777,7 @@ struct tm now; int fd, dummy; int pretty = 0; - size_t max_len = 0; + ssize_t max_len = 0; unsigned int u; #ifdef HAVE_FCHMOD mode_t mode; @@ -629,25 +799,25 @@ /* open a temporary file */ fd = _GD_MakeTempFile(D, dirfd, temp_file); if (fd == -1) { - _GD_SetError(D, GD_E_FLUSH, GD_E_FLUSH_MKTMP, NULL, errno, temp_file); + _GD_SetError(D, GD_E_FLUSH, GD_E_FLUSH_MKTMP, NULL, errno, NULL); dreturnvoid(); return; } stream = fdopen(fd, "wb+"); if (stream == NULL) { - _GD_SetError(D, GD_E_FLUSH, GD_E_FLUSH_OPEN, NULL, errno, temp_file); + _GD_SetError(D, GD_E_FLUSH, GD_E_FLUSH_OPEN, NULL, errno, NULL); dreturnvoid(); return; } if (D->flags & GD_PRETTY_PRINT) { size_t t = 0; - size_t m = 0; + ssize_t m = 0; int n = 0; pretty = 1; for (u = 0; u < D->n_entries; ++u) if (D->entry[u]->fragment_index == i && D->entry[u]->e->n_meta != -1) { - size_t l = strlen(D->entry[u]->field); + ssize_t l = strlen(D->entry[u]->field); if (m < l) m = l; t += l; @@ -664,93 +834,141 @@ t = time(NULL); strftime(buffer, GD_MAX_LINE_LENGTH, "%c", gmtime_r(&t, &now)); - fprintf(stream, "# This is a dirfile format file.\n" + if (fprintf(stream, "# This is a dirfile format file.\n" "# It was written using version %s of the GetData Library.\n" - "# Written on %s UTC", PACKAGE_VERSION, buffer); + "# Written on %s UTC", PACKAGE_VERSION, buffer) < 0) + { + goto WRITE_ERR; + } - if ((ptr = getenv("LOGNAME")) != NULL) { - fprintf(stream, " by %s", ptr); + ptr = getenv("LOGNAME"); + if (ptr == NULL) + ptr = getenv("USER"); + + if (ptr != NULL) { + if (fprintf(stream, " by %s", ptr) < 0) + goto WRITE_ERR; if ((ptr = getenv("HOSTNAME")) != NULL) - fprintf(stream, "@%s", ptr); + if (fprintf(stream, "@%s", ptr) < 0) + goto WRITE_ERR; } - fputs(".\n\n", stream); + if (fputs(".\n\n", stream) == EOF) + goto WRITE_ERR; - if (permissive) - fprintf(stream, "# WARNING: This fragment may not conform to any " - "Dirfile Standards Version.\n"); - else if (D->standards >= 5) - fprintf(stream, "/VERSION %i\n", D->standards); - else - fprintf(stream, "# This fragment conforms to " - "Dirfile Standards Version %i.\n", D->standards); + /* version */ + if (permissive) { + if (fprintf(stream, "# WARNING: This file may not conform to any " + "Dirfile Standards Version.\n") < 0) + { + goto WRITE_ERR; + } + } else if (D->standards >= 5) { + if (fprintf(stream, "/VERSION %i\n", D->standards) < 0) + goto WRITE_ERR; + } else + if (fprintf(stream, + "# This file conforms to Dirfile Standards Version %i.\n", + D->standards) < 0) + { + goto WRITE_ERR; + } /* Byte Sex */ if (permissive || D->standards >= 5) - fprintf(stream, "/ENDIAN %s%s\n", - (D->fragment[i].byte_sex & GD_LITTLE_ENDIAN) ? "little" : "big", - ((permissive || D->standards >= 8) && - (D->fragment[i].byte_sex & GD_ARM_FLAG) == GD_ARM_ENDIAN) ? " arm" : - ""); + if (fprintf(stream, "/ENDIAN %s%s\n", + (D->fragment[i].byte_sex & GD_LITTLE_ENDIAN) ? "little" : "big", + ((permissive || D->standards >= 8) && + (D->fragment[i].byte_sex & GD_ARM_FLAG) == GD_ARM_ENDIAN) ? " arm" : + "") < 0) + { + goto WRITE_ERR; + } + /* Protection */ if (permissive || D->standards >= 6) { - if (D->fragment[i].protection == GD_PROTECT_NONE) - fputs("/PROTECT none\n", stream); - else if (D->fragment[i].protection == GD_PROTECT_FORMAT) - fputs("/PROTECT format\n", stream); - else if (D->fragment[i].protection == GD_PROTECT_DATA) - fputs("/PROTECT data\n", stream); - else - fputs("/PROTECT all\n", stream); + if (D->fragment[i].protection == GD_PROTECT_NONE) { + if (fputs("/PROTECT none\n", stream) == EOF) + goto WRITE_ERR; + } else if (D->fragment[i].protection == GD_PROTECT_FORMAT) { + if (fputs("/PROTECT format\n", stream) == EOF) + goto WRITE_ERR; + } else if (D->fragment[i].protection == GD_PROTECT_DATA) { + if (fputs("/PROTECT data\n", stream) == EOF) + goto WRITE_ERR; + } else { + if (fputs("/PROTECT all\n", stream) == EOF) + goto WRITE_ERR; + } } + /* Frame offset */ if (permissive || D->standards >= 1) if (D->fragment[i].frame_offset != 0) - fprintf(stream, "%sFRAMEOFFSET %llu\n", (D->standards >= 5) ? "/" : "", - (unsigned long long)D->fragment[i].frame_offset); + if (fprintf(stream, "%sFRAMEOFFSET %llu\n", + (D->standards >= 5) ? "/" : "", + (unsigned long long)D->fragment[i].frame_offset) < 0) + { + goto WRITE_ERR; + } + /* Encoding */ if (permissive || D->standards >= 6) { + const char *encoding = NULL; + int use_encdat = 0; switch(D->fragment[i].encoding) { case GD_UNENCODED: - fputs("/ENCODING none\n", stream); + encoding = "none"; break; case GD_BZIP2_ENCODED: - fputs("/ENCODING bzip2\n", stream); + encoding = "bzip2"; break; case GD_GZIP_ENCODED: - fputs("/ENCODING gzip\n", stream); + encoding = "gzip"; break; case GD_LZMA_ENCODED: - fputs("/ENCODING lzma\n", stream); + encoding = "lzma"; break; case GD_SLIM_ENCODED: - fputs("/ENCODING slim\n", stream); + encoding = "slim"; break; case GD_TEXT_ENCODED: - fputs("/ENCODING text\n", stream); + encoding = "text"; break; case GD_SIE_ENCODED: - fputs("/ENCODING sie\n", stream); + encoding = "sie"; break; case GD_ZZIP_ENCODED: - if (D->fragment[i].enc_data) - fprintf(stream, "/ENCODING zzip %s\n", - (char*)D->fragment[i].enc_data); - else - fputs("/ENCODING zzip\n", stream); + encoding = "zzip"; + use_encdat = 1; break; case GD_ZZSLIM_ENCODED: - if (D->fragment[i].enc_data) - fprintf(stream, "/ENCODING zzslim %s\n", - (char*)D->fragment[i].enc_data); - else - fputs("/ENCODING zzslim\n", stream); + encoding = "zzslim"; + use_encdat = 1; break; case GD_AUTO_ENCODED: /* an unresolved, auto-encoded fragment */ break; default: - fprintf(stream, "/ENCODING unknown # (%lx)\n", D->fragment[i].encoding); + if (fprintf(stream, "/ENCODING unknown # (%lx)\n", + D->fragment[i].encoding) < 0) + { + goto WRITE_ERR; + } break; } + + if (encoding != NULL) { + if (use_encdat && D->fragment[i].enc_data) { + + if (fprintf(stream, "/ENCODING %s %s\n", encoding, + (char*)D->fragment[i].enc_data) < 0) + { + goto WRITE_ERR; + } + } else { + if (fprintf(stream, "/ENCODING %s\n", encoding) < 0) + goto WRITE_ERR; + } + } } /* The includes */ @@ -762,60 +980,84 @@ char *suffix = _GD_MungeCode(D, NULL, NULL, D->fragment[i].suffix, NULL, NULL, D->fragment[j].suffix, &dummy, 0); - fprintf(stream, "%sINCLUDE ", (D->standards >= 5) ? "/" : ""); - _GD_StringEscapeise(stream, D->fragment[j].ename, 0, permissive, - D->standards); + if (fprintf(stream, "%sINCLUDE ", (D->standards >= 5) ? "/" : "") < 0 || + _GD_StringEscapeise(stream, D->fragment[j].ename, 0, permissive, + D->standards) < 0) + { + goto WRITE_ERR; + } if (prefix || suffix) { - fputc(' ', stream); - _GD_StringEscapeise(stream, prefix, 0, permissive, D->standards); + if (fputc(' ', stream) == EOF || _GD_StringEscapeise(stream, prefix, + 0, permissive, D->standards) < 0) + { + goto WRITE_ERR; + } free(prefix); } if (suffix) { - fputc(' ', stream); - _GD_StringEscapeise(stream, suffix, 0, permissive, D->standards); + if (fputc(' ', stream) == EOF || _GD_StringEscapeise(stream, suffix, + 0, permissive, D->standards) < 0) + { + goto WRITE_ERR; + } free(suffix); } - fputc('\n', stream); + if (fputc('\n', stream) == EOF) + goto WRITE_ERR; } /* The fields */ for (u = 0; u < D->n_entries; ++u) if (D->entry[u]->fragment_index == i && D->entry[u]->e->n_meta != -1) { - _GD_FieldSpec(D, stream, D->entry[u], i, 0, max_len, pretty, permissive); + if (_GD_FieldSpec(D, stream, D->entry[u], i, 0, max_len, pretty, + permissive) < 0) + { + goto WRITE_ERR; + } if (permissive || D->standards >= 6) for (j = 0; j < D->entry[u]->e->n_meta; ++j) - _GD_FieldSpec(D, stream, D->entry[u]->e->p.meta_entry[j], i, 1, 0, - pretty, permissive); + if (_GD_FieldSpec(D, stream, D->entry[u]->e->p.meta_entry[j], i, 1, 0, + pretty, permissive) < 0) + { + goto WRITE_ERR; + } } /* REFERENCE is written at the end, because its effect can propagate * upwards */ if (permissive || D->standards >= 6) if (D->fragment[i].ref_name != NULL) { - fputs("/REFERENCE ", stream); - _GD_WriteFieldCode(D, stream, i, D->fragment[i].ref_name, permissive, - D->standards); - fputc('\n', stream); + if (fputs("/REFERENCE ", stream) == EOF || + _GD_WriteFieldCode(D, stream, i, D->fragment[i].ref_name, permissive, + D->standards, 0) < 0 || fputc('\n', stream) == EOF) + { + goto WRITE_ERR; + } } - /* That's all; flush, sync, and close */ - fflush(stream); - fsync(fd); + /* That's all */ #ifdef HAVE_FCHMOD - fchmod(fd, mode); + if (fchmod(fd, mode)) + goto WRITE_ERR; #endif - fclose(stream); + /* if there's no error, try closing */ + if (ferror(stream) || fclose(stream) == EOF) { +WRITE_ERR: + if (!D->error) + _GD_SetError(D, GD_E_FLUSH, GD_E_FLUSH_WRITE, NULL, errno, NULL); + fclose(stream); + } + /* If no error was encountered, move the temporary file over the * old format file, otherwise abort */ /* Only assume we've synced the file if the rename succeeds */ if (D->error != GD_E_OK) - gd_UnlinkAt(D, dirfd, temp_file, 0); + ;//gd_UnlinkAt(D, dirfd, temp_file, 0); else if (gd_RenameAt(D, dirfd, temp_file, dirfd, D->fragment[i].bname)) { - _GD_SetError(D, GD_E_FLUSH, GD_E_FLUSH_RENAME, NULL, errno, - D->fragment[i].cname); + _GD_SetError(D, GD_E_FLUSH, GD_E_FLUSH_RENAME, NULL, errno, NULL); gd_UnlinkAt(D, dirfd, temp_file, 0); } else D->fragment[i].modified = 0; @@ -977,6 +1219,7 @@ #define GD_VERS_GE_7 0xFFFFFF80UL #define GD_VERS_GE_8 0xFFFFFF00UL #define GD_VERS_GE_9 0xFFFFFE00UL +#define GD_VERS_GE_10 0xFFFFFC00UL #define GD_VERS_LE_0 0x00000001UL #define GD_VERS_LE_1 0x00000003UL @@ -988,6 +1231,7 @@ #define GD_VERS_LE_7 0x000000ffUL #define GD_VERS_LE_8 0x000001ffUL #define GD_VERS_LE_9 0x000003ffUL +#define GD_VERS_LE_10 0x000007ffUL uint64_t _GD_FindVersion(DIRFILE *D) { @@ -1073,6 +1317,9 @@ case GD_STRING_ENTRY: D->av &= GD_VERS_GE_6; break; + case GD_SARRAY_ENTRY: + D->av &= GD_VERS_GE_10; + break; case GD_BIT_ENTRY: if (D->entry[i]->EN(bit,numbits) > 1) D->av &= GD_VERS_GE_1; Modified: trunk/getdata/src/fpos.c =================================================================== --- trunk/getdata/src/fpos.c 2014-04-12 19:20:16 UTC (rev 886) +++ trunk/getdata/src/fpos.c 2014-04-27 18:34:22 UTC (rev 887) @@ -1,4 +1,4 @@ -/* Copyright (C) 2011-2013 D. V. Wiebe +/* Copyright (C) 2011-2014 D. V. Wiebe * *************************************************************************** * @@ -106,6 +106,7 @@ case GD_CONST_ENTRY: case GD_STRING_ENTRY: case GD_CARRAY_ENTRY: + case GD_SARRAY_ENTRY: case GD_ALIAS_ENTRY: _GD_InternalError(D); } @@ -312,6 +313,7 @@ case GD_CONST_ENTRY: case GD_STRING_ENTRY: case GD_CARRAY_ENTRY: + case GD_SARRAY_ENTRY: case GD_ALIAS_ENTRY: _GD_InternalError(D); } Modified: trunk/getdata/src/getdata.c =================================================================== --- trunk/getdata/src/getdata.c 2014-04-12 19:20:16 UTC (rev 886) +++ trunk/getdata/src/getdata.c 2014-04-27 18:34:22 UTC (rev 887) @@ -1,5 +1,5 @@ /* Copyright (C) 2002-2005 C. Barth Netterfield - * Copyright (C) 2005-2013 D. V. Wiebe + * Copyright (C) 2005-2014 D. V. Wiebe * *************************************************************************** * @@ -1928,6 +1928,7 @@ n_read = _GD_DoConst(D, E, first_samp, num_samp, return_type, data_out); break; case GD_STRING_ENTRY: + case GD_SARRAY_ENTRY: case GD_ALIAS_ENTRY: case GD_NO_ENTRY: /* Can't get here */ Modified: trunk/getdata/src/getdata.h.in =================================================... [truncated message content] |
From: <ket...@us...> - 2014-04-30 18:10:30
|
Revision: 889 http://sourceforge.net/p/getdata/code/889 Author: ketiltrout Date: 2014-04-30 18:10:25 +0000 (Wed, 30 Apr 2014) Log Message: ----------- Bump DSV. INDIR and SINDIR. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/src/add.c trunk/getdata/src/common.c trunk/getdata/src/del.c trunk/getdata/src/entry.c trunk/getdata/src/errors.c trunk/getdata/src/flimits.c trunk/getdata/src/flush.c trunk/getdata/src/fpos.c trunk/getdata/src/getdata.c trunk/getdata/src/getdata.h.in trunk/getdata/src/internal.h trunk/getdata/src/legacy.c trunk/getdata/src/mod.c trunk/getdata/src/name.c trunk/getdata/src/native.c trunk/getdata/src/parse.c trunk/getdata/src/putdata.c trunk/getdata/src/spf.c trunk/getdata/src/string.c trunk/getdata/test/Makefile.am trunk/getdata/test/name_updb.c trunk/getdata/test/native_const.c trunk/getdata/test/version_9_strict.c trunk/getdata/test/version_9_write.c Added Paths: ----------- trunk/getdata/test/add_indir.c trunk/getdata/test/add_sarray_nil.c trunk/getdata/test/add_sindir.c trunk/getdata/test/alter_entry_sarray.c trunk/getdata/test/alter_indir.c trunk/getdata/test/alter_sindir.c trunk/getdata/test/get_indir.c trunk/getdata/test/get_sindir.c trunk/getdata/test/getstr_here.c trunk/getdata/test/getstr_sindir.c trunk/getdata/test/getstr_type.c trunk/getdata/test/madd_indir.c trunk/getdata/test/madd_sindir.c trunk/getdata/test/name_updb_carray.c trunk/getdata/test/name_updb_sarray.c trunk/getdata/test/parse_indir.c trunk/getdata/test/parse_sindir.c trunk/getdata/test/put_indir.c trunk/getdata/test/put_sindir.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/ChangeLog 2014-04-30 18:10:25 UTC (rev 889) @@ -1,5 +1,46 @@ -2014-04-03 D. V. Wiebe <ge...@ke...> svn:887 +2014-04-30 D. V. Wiebe <ge...@ke...> svn:889 + * test/parse_indir.c test/get_sindir.c test/alter_entry_sarray.c + test/add_sindir.c test/getstr_sindir.c test/name_updb_sarray.c + test/add_indir.c test/get_indir.c test/getstr_here.c test/alter_sindir.c + test/parse_sindir.c test/alter_indir.c test/getstr_type.c + test/name_updb_carray.c test/madd_sindir.c test/put_indir.c + test/put_sindir.c test/madd_indir.c test/add_sarray_nil.c: Added. + * test/name_updb.c test/native_const.c: Update. + * src/entry.c (_GD_FreeE _GD_CalculateEntry gd_entry gd_validate) + src/legacy.c (GetFormat) src/getdata.c (_GD_DoField gd_getdata64) src/name.c + (_GD_UpdateInputs) src/flush.c (_GD_Flush _GD_FieldSpec _GD_FindVersion) + src/native.c (_GD_NativeType) src/spf.c (_GD_GetSPF) src/putdata.c + (_GD_DoFieldOut) src/del.c (_GD_ClearDerived _GD_DeReference _GD_Delete) + src/flimits.c (_GD_GetEOF _GD_GetBOF) src/fpos.c (_GD_GetFilePos _GD_Seek) + src/parse.c (_GD_ParseFieldSpec) src/mod.c (_GD_Change) src/add.c + (_GD_InvalidEntype _GD_Add): Handle INDIR and SINDIR. + * src/getdata.c (_GD_IndirData _GD_DoIndir gd_getstrdata64 gd_getdata64) + src/parse.c (_GD_ParseYoke) src/mod.c (_GD_AlterYoke gd_alter_indir + gd_alter_sindir) src/add.c (_GD_AddYoke gd_add_indir gd_add_sindir + _GD_MAddYoke gd_madd_indir gd_madd_sindir): Added. + * src/common.c (_GD_BadInput): Add entry type parameter and allow non-vector + input fields. + + * src/parse.c (_GD_ParseDivide _GD_ParseMultiply): Deleted (merged into + _GD_ParseYoke). + * src/mod.c (gd_alter_divide gd_alter_multiply): Call _GD_AlterYoke. + * src/add.c (gd_add_multiply gd_add_divide): Call _GD_AddYoke. + * src/add.c (gd_madd_multiply gd_madd_divide): Call _GD_MAddYoke. + + * src/errors.c: Add GD_E_FIELD_FORMAT and GD_E_FIELD_STR. + + * src/native.c (_GD_NativeType): Return internal type for CONST/CARRAY not + storage type (ie. run it through _GD_ConstType). + + * src/string.c (gd_get_sarray_slice gd_get_sarray) src/mod.c (_GD_Change) + src/add.c (_GD_Add): Nilify new SARRAYs on creation, not on read. + + * src/getdata.h.in: Bump GD_DIRFILE_STANDARDS_VERSION. Add GD_INDIR_ENTRY + and GD_SINDIR_ENTRY. + +2014-04-27 D. V. Wiebe <ge...@ke...> svn:887 + * src/entry.c (_GD_FreeE _GD_CalculateEntry gd_entry gd_validate) src/legacy.c (GetFormat) src/getdata.c (_GD_DoField) src/name.c (_GD_UpdateInputs) src/flush.c (_GD_Flush _GD_FieldSpec _GD_FindVersion) src/native.c (_GD_NativeType) src/spf.c (_GD_GetSPF) src/putdata.c Modified: trunk/getdata/src/add.c =================================================================== --- trunk/getdata/src/add.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/add.c 2014-04-30 18:10:25 UTC (rev 889) @@ -28,7 +28,7 @@ t != GD_CONST_ENTRY && t != GD_POLYNOM_ENTRY && t != GD_SBIT_ENTRY && t != GD_DIVIDE_ENTRY && t != GD_RECIP_ENTRY && t != GD_WINDOW_ENTRY && t != GD_MPLEX_ENTRY && t != GD_CARRAY_ENTRY && t != GD_STRING_ENTRY && - t != GD_SARRAY_ENTRY) + t != GD_SARRAY_ENTRY && t != GD_INDIR_ENTRY && t != GD_SINDIR_ENTRY) { dreturn("%i", -1); return -1; @@ -131,6 +131,7 @@ int i, is_dot, offset; void *new_list; void *new_ref = NULL; + size_t z; unsigned int u; unsigned mask; gd_entry_t *E; @@ -364,6 +365,8 @@ break; case GD_MULTIPLY_ENTRY: case GD_DIVIDE_ENTRY: + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: if (_GD_CheckCodeAffixes(D, NULL, entry->in_fields[0], entry->fragment_index, 1) || _GD_CheckCodeAffixes(D, NULL, entry->in_fields[1], entry->fragment_index, 1)) @@ -509,17 +512,13 @@ } break; case GD_SARRAY_ENTRY: - E->EN(scalar,const_type) = GD_NULL; E->EN(scalar,array_len) = entry->EN(scalar,array_len); - if (E->EN(scalar,array_len) > GD_MAX_CARRAY_LENGTH) - _GD_SetError(D, GD_E_BOUNDS, 0, NULL, 0, NULL); - else { - size_t size = sizeof(const char *) * E->EN(scalar,array_len); - E->e->u.scalar.d = _GD_Malloc(D, size); - if (E->e->u.scalar.d) - memset(E->e->u.scalar.d, 0, size); - } + E->e->u.scalar.d = _GD_Malloc(D, + sizeof(const char *) * E->EN(scalar,array_len)); + if (E->e->u.scalar.d) + for (z = 0; z < E->EN(scalar,array_len); ++z) + ((const char**)E->e->u.scalar.d)[z] = _GD_Strdup(D, ""); break; case GD_STRING_ENTRY: E->e->u.string = _GD_Strdup(D, ""); @@ -1008,15 +1007,14 @@ return error; } -/* add a MULTIPLY entry */ -int gd_add_multiply(DIRFILE* D, const char* field_code, const char* in_field1, - const char* in_field2, int fragment_index) gd_nothrow +static int _GD_AddYoke(DIRFILE* D, gd_entype_t t, const char* field_code, + const char* in_field1, const char* in_field2, int fragment_index) gd_nothrow { gd_entry_t M; int error; - dtrace("%p, \"%s\", \"%s\", \"%s\", %i", D, field_code, in_field1, in_field2, - fragment_index); + dtrace("%p, 0x%X, \"%s\", \"%s\", \"%s\", %i", D, t, field_code, in_field1, + in_field2, fragment_index); if (D->flags & GD_INVALID) {/* don't crash */ _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); @@ -1026,7 +1024,7 @@ memset(&M, 0, sizeof(gd_entry_t)); M.field = (char *)field_code; - M.field_type = GD_MULTIPLY_ENTRY; + M.field_type = t; M.in_fields[0] = (char *)in_field1; M.in_fields[1] = (char *)in_field2; M.fragment_index = fragment_index; @@ -1036,32 +1034,32 @@ return error; } -/* add a DIVIDE entry */ +int gd_add_multiply(DIRFILE* D, const char* field_code, const char* in_field1, + const char* in_field2, int fragment_index) gd_nothrow +{ + return _GD_AddYoke(D, GD_MULTIPLY_ENTRY, field_code, in_field1, in_field2, + fragment_index); +} + int gd_add_divide(DIRFILE* D, const char* field_code, const char* in_field1, const char* in_field2, int fragment_index) gd_nothrow { - gd_entry_t E; - int error; + return _GD_AddYoke(D, GD_DIVIDE_ENTRY, field_code, in_field1, in_field2, + fragment_index); +} - dtrace("%p, \"%s\", \"%s\", \"%s\", %i", D, field_code, in_field1, in_field2, +int gd_add_indir(DIRFILE* D, const char* field_code, const char* in_field1, + const char* in_field2, int fragment_index) gd_nothrow +{ + return _GD_AddYoke(D, GD_INDIR_ENTRY, field_code, in_field1, in_field2, fragment_index); +} - if (D->flags & GD_INVALID) {/* don't crash */ - _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); - dreturn("%i", -1); - return -1; - } - - memset(&E, 0, sizeof(gd_entry_t)); - E.field = (char *)field_code; - E.field_type = GD_DIVIDE_ENTRY; - E.in_fields[0] = (char *)in_field1; - E.in_fields[1] = (char *)in_field2; - E.fragment_index = fragment_index; - error = (_GD_Add(D, &E, NULL) == NULL) ? -1 : 0; - - dreturn("%i", error); - return error; +int gd_add_sindir(DIRFILE* D, const char* field_code, const char* in_field1, + const char* in_field2, int fragment_index) gd_nothrow +{ + return _GD_AddYoke(D, GD_SINDIR_ENTRY, field_code, in_field1, in_field2, + fragment_index); } /* add a RECIP entry */ @@ -1660,14 +1658,14 @@ return error; } -/* add a META MULTIPLY entry */ -int gd_madd_multiply(DIRFILE* D, const char* parent, const char* field_code, - const char* in_field1, const char* in_field2) gd_nothrow +static int _GD_MAddYoke(DIRFILE* D, gd_entype_t t, const char* parent, + const char* field_code, const char* in_field1, const char* in_field2) +gd_nothrow { gd_entry_t M; int error; - dtrace("%p, \"%s\", \"%s\", \"%s\", \"%s\"", D, field_code, parent, + dtrace("%p, 0x%X, \"%s\", \"%s\", \"%s\", \"%s\"", D, t, field_code, parent, in_field1, in_field2); if (D->flags & GD_INVALID) {/* don't crash */ @@ -1678,7 +1676,7 @@ memset(&M, 0, sizeof(gd_entry_t)); M.field = (char *)field_code; - M.field_type = GD_MULTIPLY_ENTRY; + M.field_type = t; M.in_fields[0] = (char *)in_field1; M.in_fields[1] = (char *)in_field2; M.fragment_index = 0; @@ -1688,6 +1686,13 @@ return error; } +int gd_madd_multiply(DIRFILE* D, const char *parent, const char* field_code, + const char* in_field1, const char* in_field2) gd_nothrow +{ + return _GD_MAddYoke(D, GD_MULTIPLY_ENTRY, parent, field_code, in_field1, + in_field2); +} + /* add a META PHASE entry */ int gd_madd_phase(DIRFILE* D, const char* parent, const char* field_code, const char* in_field, gd_shift_t shift) gd_nothrow @@ -1798,31 +1803,25 @@ return error; } -/* add a META DIVIDE entry */ int gd_madd_divide(DIRFILE* D, const char *parent, const char* field_code, const char* in_field1, const char* in_field2) gd_nothrow { - int error; - gd_entry_t E; + return _GD_MAddYoke(D, GD_DIVIDE_ENTRY, parent, field_code, in_field1, + in_field2); +} - dtrace("%p, \"%s\", \"%s\", \"%s\", \"%s\"", D, parent, field_code, in_field1, +int gd_madd_indir(DIRFILE* D, const char *parent, const char* field_code, + const char* in_field1, const char* in_field2) gd_nothrow +{ + return _GD_MAddYoke(D, GD_INDIR_ENTRY, parent, field_code, in_field1, in_field2); +} - if (D->flags & GD_INVALID) {/* don't crash */ - _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); - dreturn("%i", -1); - return -1; - } - - memset(&E, 0, sizeof(gd_entry_t)); - E.field = (char *)field_code; - E.field_type = GD_DIVIDE_ENTRY; - E.in_fields[0] = (char *)in_field1; - E.in_fields[1] = (char *)in_field2; - error = (_GD_Add(D, &E, parent) == NULL) ? -1 : 0; - - dreturn("%i", error); - return error; +int gd_madd_sindir(DIRFILE *D, const char *parent, const char* field_code, + const char* in_field1, const char* in_field2) gd_nothrow +{ + return _GD_MAddYoke(D, GD_SINDIR_ENTRY, parent, field_code, in_field1, + in_field2); } /* add a RECIP entry */ Modified: trunk/getdata/src/common.c =================================================================== --- trunk/getdata/src/common.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/common.c 2014-04-30 18:10:25 UTC (rev 889) @@ -855,11 +855,11 @@ } /* Ensure that an input field has been identified (with error checking) */ -int _GD_BadInput(DIRFILE *D, const gd_entry_t *E, int i, int err) +int _GD_BadInput(DIRFILE *D, const gd_entry_t *E, int i, gd_entype_t t, int err) { char *code; - dtrace("%p, %p, %i, %i", D, E, i, err); + dtrace("%p, %p, %i, 0x%X, %i", D, E, i, t, err); if (E->e->entry[i] == NULL) { E->e->entry[i] = _GD_FindFieldAndRepr(D, E->in_fields[i], &code, @@ -874,9 +874,17 @@ free(code); } - /* scalar entries not allowed */ - if (E->e->entry[i]->field_type & GD_SCALAR_ENTRY_BIT) { - _GD_SetError(D, GD_E_DIMENSION, GD_E_DIM_FORMAT, E->field, 0, + /* check field type */ + if (t == GD_NO_ENTRY) { + /* scalar entries not allowed */ + if (E->e->entry[i]->field_type & GD_SCALAR_ENTRY_BIT) { + _GD_SetError(D, GD_E_DIMENSION, GD_E_DIM_FORMAT, E->field, 0, + E->e->entry[i]->field); + dreturn("%i", 1); + return 1; + } + } else if (E->e->entry[i]->field_type != t) { + _GD_SetError(D, GD_E_BAD_FIELD_TYPE, GD_E_FIELD_FORMAT, E->field, 0, E->e->entry[i]->field); dreturn("%i", 1); return 1; Modified: trunk/getdata/src/del.c =================================================================== --- trunk/getdata/src/del.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/del.c 2014-04-30 18:10:25 UTC (rev 889) @@ -42,6 +42,8 @@ case GD_DIVIDE_ENTRY: case GD_WINDOW_ENTRY: case GD_MPLEX_ENTRY: + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: if (strcmp(E->in_fields[1], C->field) == 0) { if (check) _GD_SetError(D, GD_E_DELETE, GD_E_DEL_DERIVED, E->field, 0, @@ -214,6 +216,8 @@ case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: case GD_SARRAY_ENTRY: + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: case GD_INDEX_ENTRY: case GD_ALIAS_ENTRY: break; @@ -308,8 +312,10 @@ if ((del_list[i]->field_type == GD_CONST_ENTRY || del_list[i]->field_type == GD_CARRAY_ENTRY) && ~flags & GD_DEL_DEREF) + { _GD_DeReference(D, D->entry[j], del_list[i], 1); - else if (del_list[i]->field_type != GD_STRING_ENTRY) + } + if (!D->error) _GD_ClearDerived(D, D->entry[j], del_list[i], 1); if (D->error) { Modified: trunk/getdata/src/entry.c =================================================================== --- trunk/getdata/src/entry.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/entry.c 2014-04-30 18:10:25 UTC (rev 889) @@ -55,6 +55,8 @@ break; case GD_DIVIDE_ENTRY: case GD_MULTIPLY_ENTRY: + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: free(entry->in_fields[1]); free(entry->in_fields[0]); break; @@ -312,6 +314,8 @@ case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: case GD_SARRAY_ENTRY: + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: case GD_INDEX_ENTRY: case GD_ALIAS_ENTRY: break; @@ -451,6 +455,8 @@ break; case GD_MULTIPLY_ENTRY: case GD_DIVIDE_ENTRY: + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: entry->in_fields[0] = strdup(E->in_fields[0]); entry->in_fields[1] = strdup(E->in_fields[1]); break; @@ -817,13 +823,21 @@ switch (E->field_type) { case GD_LINCOM_ENTRY: for (i = 0; i < E->EN(lincom,n_fields); ++i) - _GD_BadInput(D, E, i, 1); + _GD_BadInput(D, E, i, GD_NO_ENTRY, 1); break; + case GD_INDIR_ENTRY: + _GD_BadInput(D, E, 0, GD_NO_ENTRY, 1); + _GD_BadInput(D, E, 0, GD_CARRAY_ENTRY, 1); + break; + case GD_SINDIR_ENTRY: + _GD_BadInput(D, E, 0, GD_NO_ENTRY, 1); + _GD_BadInput(D, E, 0, GD_SARRAY_ENTRY, 1); + break; case GD_DIVIDE_ENTRY: case GD_MULTIPLY_ENTRY: case GD_WINDOW_ENTRY: case GD_MPLEX_ENTRY: - _GD_BadInput(D, E, 1, 1); + _GD_BadInput(D, E, 1, GD_NO_ENTRY, 1); /* fallthrough */ case GD_LINTERP_ENTRY: case GD_BIT_ENTRY: @@ -831,7 +845,7 @@ case GD_POLYNOM_ENTRY: case GD_SBIT_ENTRY: case GD_RECIP_ENTRY: - _GD_BadInput(D, E, 0, 1); + _GD_BadInput(D, E, 0, GD_NO_ENTRY, 1); /* Fallthrough */ case GD_RAW_ENTRY: case GD_CONST_ENTRY: Modified: trunk/getdata/src/errors.c =================================================================== --- trunk/getdata/src/errors.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/errors.c 2014-04-30 18:10:25 UTC (rev 889) @@ -114,10 +114,13 @@ "Recursion too deep including {4} on line {3} of {2}", 0 }, /* GD_E_BAD_DIRFILE: (nothing) */ { GD_E_BAD_DIRFILE, 0, "Invalid dirfile", 0 }, - /* GD_E_BAD_FIELD_TYPE: 4 = fieldcode */ + /* GD_E_BAD_FIELD_TYPE: 2 = parent field (if any) 4 = fieldcode */ { GD_E_BAD_FIELD_TYPE, GD_E_FIELD_PUT, "No method to write field {4}", 0 }, { GD_E_BAD_FIELD_TYPE, GD_E_FIELD_BAD, "Invalid field type for {4}", 0 }, { GD_E_BAD_FIELD_TYPE, GD_E_FIELD_MATCH, "Field type mismatch for {4}", 0 }, + { GD_E_BAD_FIELD_TYPE, GD_E_FIELD_FORMAT, + "Bad field type for {4} in definition of {2}", 0 }, + { GD_E_BAD_FIELD_TYPE, GD_E_FIELD_STR, "Non-numeric data in {4}", 0 }, /* GD_E_ACCMODE: (nothing) */ { GD_E_ACCMODE, 0, "Dirfile has been opened read-only", 0 }, /* GD_E_UNSUPPORTED: (nothing) */ Modified: trunk/getdata/src/flimits.c =================================================================== --- trunk/getdata/src/flimits.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/flimits.c 2014-04-30 18:10:25 UTC (rev 889) @@ -216,7 +216,9 @@ case GD_SBIT_ENTRY: case GD_POLYNOM_ENTRY: case GD_RECIP_ENTRY: - if (_GD_BadInput(D, E, 0, 1)) + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) break; ns = _GD_GetEOF(D, E->e->entry[0], E->field, is_index); @@ -225,8 +227,11 @@ case GD_MULTIPLY_ENTRY: case GD_WINDOW_ENTRY: case GD_MPLEX_ENTRY: - if (_GD_BadInput(D, E, 0, 1) || _GD_BadInput(D, E, 1, 1)) + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1) || + _GD_BadInput(D, E, 1, GD_NO_ENTRY, 1)) + { break; + } ns = _GD_GetEOF(D, E->e->entry[0], E->field, is_index); @@ -263,7 +268,7 @@ } break; case GD_LINCOM_ENTRY: - if (_GD_BadInput(D, E, 0, 1)) + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) break; ns = _GD_GetEOF(D, E->e->entry[0], E->field, is_index); @@ -284,7 +289,7 @@ } for (i = 1; i < E->EN(lincom,n_fields); ++i) { - if (_GD_BadInput(D, E, i, 1)) { + if (_GD_BadInput(D, E, i, GD_NO_ENTRY, 1)) { ns = -1; break; } @@ -313,7 +318,7 @@ } break; case GD_PHASE_ENTRY: - if (_GD_BadInput(D, E, 0, 1)) + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) break; ns = _GD_GetEOF(D, E->e->entry[0], E->field, is_index); @@ -423,13 +428,15 @@ case GD_LINTERP_ENTRY: case GD_POLYNOM_ENTRY: case GD_RECIP_ENTRY: - if (_GD_BadInput(D, E, 0, 1)) + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) break; bof = _GD_GetBOF(D, E->e->entry[0], E->field, spf, ds); break; case GD_PHASE_ENTRY: - if (_GD_BadInput(D, E, 0, 1)) + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) break; bof = _GD_GetBOF(D, E->e->entry[0], E->field, spf, ds); @@ -458,8 +465,11 @@ case GD_DIVIDE_ENTRY: case GD_WINDOW_ENTRY: case GD_MPLEX_ENTRY: - if (_GD_BadInput(D, E, 0, 1) || _GD_BadInput(D, E, 1, 1)) + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1) || + _GD_BadInput(D, E, 1, GD_NO_ENTRY, 1)) + { break; + } bof = _GD_GetBOF(D, E->e->entry[0], E->field, spf, ds); @@ -483,7 +493,7 @@ } break; case GD_LINCOM_ENTRY: - if (_GD_BadInput(D, E, 0, 1)) + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) break; bof = _GD_GetBOF(D, E->e->entry[0], E->field, spf, ds); @@ -494,7 +504,7 @@ } for (i = 1; i < E->EN(lincom,n_fields); ++i) { - if (_GD_BadInput(D, E, i, 1)) { + if (_GD_BadInput(D, E, i, GD_NO_ENTRY, 1)) { bof = -1; break; } Modified: trunk/getdata/src/flush.c =================================================================== --- trunk/getdata/src/flush.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/flush.c 2014-04-30 18:10:25 UTC (rev 889) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2012 D. V. Wiebe +/* Copyright (C) 2008-2012, 2014 D. V. Wiebe * *************************************************************************** * @@ -58,7 +58,7 @@ break; case GD_LINCOM_ENTRY: for (i = 0; i < E->EN(lincom,n_fields); ++i) { - if (!_GD_BadInput(D, E, i, 0)) + if (!_GD_BadInput(D, E, i, GD_NO_ENTRY, 0)) _GD_Flush(D, E->e->entry[i], syn, clo); } break; @@ -66,7 +66,7 @@ case GD_DIVIDE_ENTRY: case GD_WINDOW_ENTRY: case GD_MPLEX_ENTRY: - if (!_GD_BadInput(D, E, 1, 0)) + if (!_GD_BadInput(D, E, 1, GD_NO_ENTRY, 0)) _GD_Flush(D, E->e->entry[1], syn, clo); /* fallthrough */ case GD_LINTERP_ENTRY: @@ -75,7 +75,9 @@ case GD_POLYNOM_ENTRY: case GD_SBIT_ENTRY: case GD_RECIP_ENTRY: - if (!_GD_BadInput(D, E, 0, 0)) + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: + if (!_GD_BadInput(D, E, 0, GD_NO_ENTRY, 0)) _GD_Flush(D, E->e->entry[0], syn, clo); case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: @@ -731,6 +733,26 @@ } } break; + case GD_INDIR_ENTRY: + if (fprintf(stream, " INDIR%s ", pretty ? " " : "") < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, + D->standards, 1) < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive, + D->standards, 0) < 0) + { + goto WRITE_ERR; + } + break; + case GD_SINDIR_ENTRY: + if (fprintf(stream, " SINDIR%s ", pretty ? " " : "") < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive, + D->standards, 1) < 0 || + _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive, + D->standards, 0) < 0) + { + goto WRITE_ERR; + } + break; case GD_INDEX_ENTRY: case GD_ALIAS_ENTRY: case GD_NO_ENTRY: @@ -1318,6 +1340,8 @@ D->av &= GD_VERS_GE_6; break; case GD_SARRAY_ENTRY: + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: D->av &= GD_VERS_GE_10; break; case GD_BIT_ENTRY: Modified: trunk/getdata/src/fpos.c =================================================================== --- trunk/getdata/src/fpos.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/fpos.c 2014-04-30 18:10:25 UTC (rev 889) @@ -47,13 +47,13 @@ D->fragment[E->fragment_index].frame_offset; break; case GD_LINCOM_ENTRY: - if (_GD_BadInput(D, E, 0, 1)) + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) break; pos = _GD_GetFilePos(D, E->e->entry[0], -1); if (!D->error) for (i = 1; i < E->EN(lincom,n_fields); ++i) { - if (_GD_BadInput(D, E, i, 1)) { + if (_GD_BadInput(D, E, i, GD_NO_ENTRY, 1)) { pos = -1; break; } @@ -70,7 +70,9 @@ case GD_POLYNOM_ENTRY: case GD_SBIT_ENTRY: case GD_RECIP_ENTRY: - if (_GD_BadInput(D, E, 0, 1)) + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) break; pos = _GD_GetFilePos(D, E->e->entry[0], -1); break; @@ -78,8 +80,11 @@ case GD_DIVIDE_ENTRY: case GD_WINDOW_ENTRY: case GD_MPLEX_ENTRY: - if (_GD_BadInput(D, E, 0, 1) || _GD_BadInput(D, E, 1, 1)) + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1) || + _GD_BadInput(D, E, 1, GD_NO_ENTRY, 1)) + { break; + } pos = _GD_GetFilePos(D, E->e->entry[0], -1); if (D->error) break; @@ -90,7 +95,7 @@ } break; case GD_PHASE_ENTRY: - if (_GD_BadInput(D, E, 0, 1)) + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) break; pos = _GD_GetFilePos(D, E->e->entry[0], -1); if (pos >= 0) @@ -280,7 +285,7 @@ break; case GD_LINCOM_ENTRY: for (i = 0; i < E->EN(lincom,n_fields); ++i) - if (!_GD_BadInput(D, E, i, 1)) + if (!_GD_BadInput(D, E, i, GD_NO_ENTRY, 1)) _GD_Seek(D, E->e->entry[i], offset, mode); else break; @@ -289,7 +294,7 @@ case GD_DIVIDE_ENTRY: case GD_WINDOW_ENTRY: case GD_MPLEX_ENTRY: - if (_GD_BadInput(D, E, 1, 1)) + if (_GD_BadInput(D, E, 1, GD_NO_ENTRY, 1)) break; if (_GD_Seek(D, E->e->entry[1], offset, mode)) break; @@ -299,11 +304,13 @@ case GD_POLYNOM_ENTRY: case GD_SBIT_ENTRY: case GD_RECIP_ENTRY: - if (!_GD_BadInput(D, E, 0, 1)) + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: + if (!_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) _GD_Seek(D, E->e->entry[0], offset, mode); break; case GD_PHASE_ENTRY: - if (!_GD_BadInput(D, E, 0, 1)) + if (!_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) _GD_Seek(D, E->e->entry[0], offset - E->EN(phase,shift), mode); break; case GD_INDEX_ENTRY: Modified: trunk/getdata/src/getdata.c =================================================================== --- trunk/getdata/src/getdata.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/getdata.c 2014-04-30 18:10:25 UTC (rev 889) @@ -983,7 +983,7 @@ /* input field checks */ for (i = 0; i < E->EN(lincom,n_fields); ++i) { - if (_GD_BadInput(D, E, i, 1)) { + if (_GD_BadInput(D, E, i, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } @@ -1116,12 +1116,12 @@ num_samp, return_type, data_out); /* Check input fields */ - if (_GD_BadInput(D, E, 0, 1)) { + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } - if (_GD_BadInput(D, E, 1, 1)) { + if (_GD_BadInput(D, E, 1, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } @@ -1209,7 +1209,7 @@ num_samp, return_type, data_out); /* Check input fields */ - if (_GD_BadInput(D, E, 0, 1)) { + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } @@ -1255,7 +1255,9 @@ num_samp, return_type, data_out); /* Check input fields */ - if (_GD_BadInput(D, E, 0, 1) || _GD_BadInput(D, E, 1, 1)) { + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1) || + _GD_BadInput(D, E, 1, GD_NO_ENTRY, 1)) + { dreturn("%i", 0); return 0; } @@ -1350,7 +1352,7 @@ dtrace("%p, %p, %i, %lli, %" PRNsize_t ", 0x%X, %p", D, E, is_signed, (long long)first_samp, num_samp, return_type, data_out); - if (_GD_BadInput(D, E, 0, 1)) { + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } @@ -1403,7 +1405,7 @@ dtrace("%p, %p, %lli, %" PRNsize_t ", 0x%X, %p", D, E, (long long)first_samp, num_samp, return_type, data_out); - if (_GD_BadInput(D, E, 0, 1)) { + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } @@ -1427,7 +1429,7 @@ dtrace("%p, %p, %lli, %" PRNsize_t ", 0x%X, %p", D, E, (long long)first_samp, num_samp, return_type, data_out); - if (_GD_BadInput(D, E, 0, 1)) { + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } @@ -1469,7 +1471,7 @@ dtrace("%p, %p, %lli, %" PRNsize_t ", 0x%X, %p", D, E, (long long)first_samp, num_samp, return_type, data_out); - if (_GD_BadInput(D, E, 0, 1)) { + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } @@ -1516,12 +1518,12 @@ num_samp, return_type, data_out); /* Check input fields */ - if (_GD_BadInput(D, E, 0, 1)) { + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } - if (_GD_BadInput(D, E, 1, 1)) { + if (_GD_BadInput(D, E, 1, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } @@ -1622,12 +1624,12 @@ num_samp, return_type, data_out); /* Check input fields */ - if (_GD_BadInput(D, E, 0, 1)) { + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } - if (_GD_BadInput(D, E, 1, 1)) { + if (_GD_BadInput(D, E, 1, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } @@ -1789,8 +1791,7 @@ return n_read; } -/* _GD_DoConst: Read from a const. Returns number of samples read (ie. 1). -*/ +/* _GD_DoConst: Read from a const. Returns number of samples read */ static size_t _GD_DoConst(DIRFILE *restrict D, const gd_entry_t *restrict E, off64_t first, size_t len, gd_type_t return_type, void *restrict data_out) { @@ -1812,6 +1813,94 @@ return len; } +/* simple */ +static void _GD_IndirData(DIRFILE *restrict D, char *restrict cbuf, + gd_type_t ctype, const int64_t *restrict ibuf, size_t n, const void *carray, + size_t len) +{ + size_t i; + const int size = GD_SIZE(ctype); + int64_t ilen = (len > GD_INT64_MAX) ? GD_INT64_MAX : len; + + dtrace("%p, %p, 0x%X, %p, %" PRNsize_t ", %p, %" PRNsize_t, D, cbuf, ctype, + ibuf, n, carray, len); + + for (i = 0; i < n; ++i) + if (ibuf[i] < 0 || ibuf[i] >= ilen) + _GD_FillZero(cbuf + size * i, ctype, 1); + else + memcpy(cbuf + size * i, carray + size * ibuf[i], size); + + dreturnvoid(); +} + +/* _GD_DoIndir: Read from an indir. */ +static size_t _GD_DoIndir(DIRFILE *restrict D, const gd_entry_t *restrict E, + off64_t first_samp, size_t num_samp, gd_type_t return_type, + void *restrict data_out) +{ + size_t n_read; + int64_t *ibuf = NULL; + void *cbuf = NULL; + gd_type_t ctype; + + dtrace("%p, %p, %lli, %" PRNsize_t ", 0x%X, %p", D, E, (long long)first_samp, + num_samp, return_type, data_out); + + /* Check input fields */ + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { + dreturn("%i", 0); + return 0; + } + + if (_GD_BadInput(D, E, 1, GD_CARRAY_ENTRY, 1)) { + dreturn("%i", 0); + return 0; + } + + /* index buffer */ + ibuf = _GD_Alloc(D, GD_INT64, num_samp); + if (D->error) { + dreturn("%i", 0); + return 0; + } + + /* read the index field and record the number of samples returned */ + n_read = _GD_DoField(D, E->e->entry[0], E->e->repr[0], first_samp, num_samp, + GD_INT64, ibuf); + + if (D->error || n_read == 0) { + free(ibuf); + dreturn("%i", 0); + return 0; + } + + /* the intermediate buffer: it has the load type of the carray */ + ctype = _GD_ConstType(D, E->e->entry[1]->EN(scalar,const_type)); + cbuf = _GD_Alloc(D, ctype, n_read); + if (D->error) { + free(ibuf); + dreturn("%i", 0); + return 0; + } + + _GD_IndirData(D, cbuf, GD_SIZE(ctype), ibuf, n_read, + E->e->entry[1]->e->u.scalar.d, E->e->entry[1]->EN(scalar,array_len)); + + free(ibuf); + + /* type convert into output buffer */ + _GD_ConvertType(D, cbuf, ctype, data_out, return_type, n_read); + + free(cbuf); + + if (D->error) + n_read = 0; + + dreturn("%" PRNsize_t, n_read); + return n_read; +} + /* _GD_DoField: Locate the field in the database and read it. */ size_t _GD_DoField(DIRFILE *restrict D, gd_entry_t *restrict E, int repr, @@ -1927,8 +2016,12 @@ case GD_CARRAY_ENTRY: n_read = _GD_DoConst(D, E, first_samp, num_samp, return_type, data_out); break; + case GD_INDIR_ENTRY: + n_read = _GD_DoIndir(D, E, first_samp, num_samp, return_type, data_out); + break; case GD_STRING_ENTRY: case GD_SARRAY_ENTRY: + case GD_SINDIR_ENTRY: case GD_ALIAS_ENTRY: case GD_NO_ENTRY: /* Can't get here */ @@ -1949,6 +2042,110 @@ return n_read; } +/* this returns string vector data (ie. SINDIR) */ +size_t gd_getstrdata64(DIRFILE *D, const char *field_code, off64_t first_frame, + off64_t first_samp, size_t num_frames, size_t num_samp, + const char **data_out) +{ + size_t i, n_read = 0; + gd_entry_t *E; + unsigned int spf; + int64_t *ibuf = NULL; + int64_t len; + + dtrace("%p, \"%s\", %lli %lli, %" PRNsize_t ", %" PRNsize_t ", %p", D, + field_code, (long long)first_frame, (long long)first_samp, num_frames, + num_samp, data_out); + + if (D->flags & GD_INVALID) { + _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); + dreturn("%i", 0); + return 0; + } + + _GD_ClearError(D); + + E = _GD_FindField(D, field_code, D->entry, D->n_entries, 1, NULL); + + if (E == NULL) { + _GD_SetError(D, GD_E_BAD_CODE, GD_E_CODE_MISSING, NULL, 0, field_code); + dreturn("%i", 0); + return 0; + } + + if (E->field_type != GD_SINDIR_ENTRY) { + _GD_SetError(D, GD_E_BAD_FIELD_TYPE, GD_E_FIELD_BAD, NULL, 0, field_code); + dreturn("%i", 0); + return 0; + } + + if (first_frame == GD_HERE || first_samp == GD_HERE) { + first_samp = GD_HERE; + first_frame = 0; + } + + if (first_frame > 0 || num_frames > 0) { + /* get the samples per frame */ + spf = _GD_GetSPF(D, E); + + if (D->error) { + dreturn("%i", 0); + return 0; + } + + first_samp += spf * first_frame; + num_samp += spf * num_frames; + } + + if (first_samp < 0 && (first_samp != GD_HERE || first_frame != 0)) { + _GD_SetError(D, GD_E_RANGE, GD_E_OUT_OF_RANGE, NULL, 0, NULL); + dreturn("%i", 0); + return 0; + } + + /* Check input fields */ + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { + dreturn("%i", 0); + return 0; + } + + if (_GD_BadInput(D, E, 1, GD_SARRAY_ENTRY, 1)) { + dreturn("%i", 0); + return 0; + } + + /* index buffer */ + ibuf = _GD_Alloc(D, GD_INT64, num_samp); + if (D->error) { + dreturn("%i", 0); + return 0; + } + + /* read the index field and record the number of samples returned */ + n_read = _GD_DoField(D, E->e->entry[0], E->e->repr[0], first_samp, num_samp, + GD_INT64, ibuf); + + if (D->error || n_read == 0) { + free(ibuf); + dreturn("%i", 0); + return 0; + } + + len = (E->e->entry[1]->EN(scalar,array_len) > GD_INT64_MAX) ? GD_INT64_MAX + : E->e->entry[1]->EN(scalar,array_len); + + for (i = 0; i < n_read; ++i) + if (ibuf[i] < 0 || ibuf[i] >= len) + data_out[i] = NULL; + else + data_out[i] = ((const char **)E->e->entry[1]->e->u.scalar.d)[ibuf[i]]; + + free(ibuf); + + dreturn("%" PRNsize_t, n_read); + return n_read; +} + /* this function is little more than a public boilerplate for _GD_DoField */ size_t gd_getdata64(DIRFILE* D, const char *field_code_in, off64_t first_frame, off64_t first_samp, size_t num_frames, size_t num_samp, @@ -1982,6 +2179,8 @@ if (entry->field_type & GD_SCALAR_ENTRY_BIT) _GD_SetError(D, GD_E_DIMENSION, GD_E_DIM_CALLER, NULL, 0, field_code); + else if (entry->field_type == GD_SINDIR_ENTRY) + _GD_SetError(D, GD_E_BAD_FIELD_TYPE, GD_E_FIELD_STR, NULL, 0, field_code); if (field_code != field_code_in) free(field_code); @@ -2023,6 +2222,13 @@ } /* 32(ish)-bit wrapper for the 64-bit version, when needed */ +size_t gd_getstrdata(DIRFILE *D, const char *field_code, off_t first_frame, + off_t first_samp, size_t num_frames, size_t num_samp, const char **data_out) +{ + return gd_getstrdata64(D, field_code, first_frame, first_samp, num_frames, + num_samp, data_out); +} + size_t gd_getdata(DIRFILE* D, const char *field_code, off_t first_frame, off_t first_samp, size_t num_frames, size_t num_samp, gd_type_t return_type, void *data_out) Modified: trunk/getdata/src/getdata.h.in =================================================================== --- trunk/getdata/src/getdata.h.in 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/getdata.h.in 2014-04-30 18:10:25 UTC (rev 889) @@ -59,7 +59,7 @@ #endif /* The most recent standards version supported by this library */ -#define GD_DIRFILE_STANDARDS_VERSION 9 +#define GD_DIRFILE_STANDARDS_VERSION 10 #include <math.h> #include <sys/types.h> @@ -241,6 +241,8 @@ GD_RECIP_ENTRY = 0x0B, GD_WINDOW_ENTRY = 0x0C, GD_MPLEX_ENTRY = 0x0D, + GD_INDIR_ENTRY = 0x0E, + GD_SINDIR_ENTRY = 0x0F, GD_CONST_ENTRY = GD_SCALAR_ENTRY_BIT | 0x00, GD_STRING_ENTRY = GD_SCALAR_ENTRY_BIT | 0x01, GD_CARRAY_ENTRY = GD_SCALAR_ENTRY_BIT | 0x02, @@ -546,6 +548,10 @@ const char *in_field1, const char *in_field2, int fragment_index) gd_nothrow gd_nonnull ((1,2,3,4)); +extern int gd_add_indir(DIRFILE *dirfile, const char *field_code, + const char *in_field1, const char *in_field2, int fragment_index) +gd_nothrow gd_nonnull ((1,2,3,4)); + extern int gd_add_lincom(DIRFILE *dirfile, const char *field_code, int n_fields, const char **in_fields, const double *m, const double *b, int fragment_index) gd_nothrow gd_nonnull ((1,2,4,5,6)); @@ -582,6 +588,10 @@ const char *in_field, int bitnum, int numbits, int fragment_index) gd_nothrow gd_nonnull ((1,2,3)); +extern int gd_add_sindir(DIRFILE *dirfile, const char *field_code, + const char *in_field1, const char *in_field2, int fragment_index) +gd_nothrow gd_nonnull ((1,2,3,4)); + extern int gd_add_string(DIRFILE *dirfile, const char *field_code, const char *value, int fragment_index) gd_nothrow gd_nonnull((1,2,3)); @@ -632,6 +642,9 @@ extern int gd_alter_divide(DIRFILE *dirfile, const char *field_code, const char *in_field1, const char *in_field2) gd_nothrow gd_nonnull((1,2)); +extern int gd_alter_indir(DIRFILE *dirfile, const char *field_code, + const char *in_field1, const char *in_field2) gd_nothrow gd_nonnull((1,2)); + extern int gd_alter_lincom(DIRFILE *dirfile, const char *field_code, int n_fields, const char **in_fields, const double *m, const double *b) gd_nothrow gd_nonnull((1,2)); @@ -660,6 +673,9 @@ const char *in_field, int bitnum, int numbits) gd_nothrow gd_nonnull((1,2)); +extern int gd_alter_sindir(DIRFILE *dirfile, const char *field_code, + const char *in_field1, const char *in_field2) gd_nothrow gd_nonnull((1,2)); + extern int gd_alter_window(DIRFILE *dirfile, const char *field_code, const char *in_field, const char *check_field, gd_windop_t windop, gd_triplet_t threshold) gd_nothrow gd_nonnull((1,2)); @@ -792,6 +808,10 @@ const char *field_code, const char *in_field1, const char *in_field2) gd_nothrow gd_nonnull ((1,2,3,4,5)); +extern int gd_madd_indir(DIRFILE *dirfile, const char *parent, + const char *field_code, const char *in_field1, const char *in_field2) +gd_nothrow gd_nonnull ((1,2,3,4,5)); + extern int gd_madd_lincom(DIRFILE *dirfile, const char *parent, const char *field_code, int n_fields, const char **in_fields, const double *m, const double *b) gd_nothrow gd_nonnull((1,2,3,5,6,7)); @@ -829,6 +849,10 @@ const char *field_code, const char *in_field, int bitnum, int numbits) gd_nothrow gd_nonnull ((1,2,3,4)); +extern int gd_madd_sindir(DIRFILE *dirfile, const char *parent, + const char *field_code, const char *in_field1, const char *in_field2) +gd_nothrow gd_nonnull ((1,2,3,4,5)); + extern int gd_madd_spec(DIRFILE *dirfile, const char *line, const char *parent) gd_nothrow gd_nonnull ((1,2,3)); @@ -1041,6 +1065,10 @@ off_t first_frame, off_t first_sample, size_t num_frames, size_t num_samples, gd_type_t return_type, void *data) gd_nonnull ((1, 2)); +extern size_t gd_getstrdata(DIRFILE *dirfile, const char *field_code, + off_t first_frame, off_t first_sample, size_t num_frames, + size_t num_samples, const char **data) gd_nonnull ((1, 2)); + extern size_t gd_putdata(DIRFILE *dirfile, const char *field_code, off_t first_frame, off_t first_sample, size_t num_frames, size_t num_samples, gd_type_t data_type, const void *data) @@ -1089,6 +1117,11 @@ off_t first_frame, off_t first_samp, size_t num_frames, size_t num_samp, gd_type_t return_type, void *data), gd_getdata64) gd_nonnull ((1, 2)); +extern size_t __REDIRECT (gd_getstrdata, (DIRFILE *dirfile, + const char *field_code, off_t first_frame, off_t first_samp, + size_t num_frames, size_t num_samp, const char **data), gd_getstrdata64) +gd_nonnull ((1, 2)); + extern size_t __REDIRECT (gd_putdata, (DIRFILE *dirfile, const char *field_code, off_t first_frame, off_t first_sample, size_t num_frames, size_t num_samples, gd_type_t data_type, const void *data), @@ -1110,6 +1143,7 @@ # else # define gd_alter_frameoffset gd_alter_frameoffset64 # define gd_getdata gd_getdata64 +# define gd_getstrdata gd_getstrdata64 # define gd_putdata gd_putdata64 # define gd_nframes gd_nframes64 # define gd_eof gd_eof64 @@ -1142,6 +1176,10 @@ gd_off64_t first_frame, gd_off64_t first_samp, size_t num_frames, size_t num_samp, gd_type_t return_type, void *data) gd_nonnull ((1, 2)); +extern size_t gd_getstrdata64(DIRFILE *dirfile, const char *field_code, + gd_off64_t first_frame, gd_off64_t first_samp, size_t num_frames, + size_t num_samp, const char **data) gd_nonnull ((1, 2)); + extern size_t gd_putdata64(DIRFILE *dirfile, const char *field_code, gd_off64_t first_frame, gd_off64_t first_sample, size_t num_frames, size_t num_samples, gd_type_t data_type, const void *data) Modified: trunk/getdata/src/internal.h =================================================================== --- trunk/getdata/src/internal.h 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/internal.h 2014-04-30 18:10:25 UTC (rev 889) @@ -269,16 +269,18 @@ #define SIZEOF_UNSIGNED_INT (sizeof(unsigned int)) #endif +#define GD_INT_TYPE ((gd_type_t)(SIZEOF_INT | GD_SIGNED)) +#define GD_UINT_TYPE ((gd_type_t)(SIZEOF_UNSIGNED_INT)) + +/* a few integer limits */ #ifndef SIZEOF_SIZE_T #define SIZEOF_SIZE_T (sizeof(size_t)) #endif +#define GD_INT64_MAX ((int64_t)((uint64_t)-1>>1)) #define GD_SSIZE_T_MAX ((ssize_t)((size_t)-1>>1)) #define GD_SIZE_T_MAX ((size_t)-1) -#define GD_INT_TYPE ((gd_type_t)(SIZEOF_INT | GD_SIGNED)) -#define GD_UINT_TYPE ((gd_type_t)(SIZEOF_UNSIGNED_INT)) - /* default buffer size */ #if SIZEOF_INT < 4 #define GD_BUFFER_SIZE 32767 @@ -753,6 +755,8 @@ #define GD_E_FIELD_PUT 1 #define GD_E_FIELD_BAD 2 #define GD_E_FIELD_MATCH 3 +#define GD_E_FIELD_FORMAT 4 +#define GD_E_FIELD_STR 5 #define GD_E_ENTRY_TYPE 1 #define GD_E_ENTRY_METARAW 2 @@ -1101,7 +1105,7 @@ /* forward declarations */ void *_GD_Alloc(DIRFILE*, gd_type_t, size_t) __attribute_malloc__; -int _GD_BadInput(DIRFILE *, const gd_entry_t *, int, int); +int _GD_BadInput(DIRFILE *, const gd_entry_t *, int, gd_entype_t, int); #define _GD_BadWindop(op) \ ( \ Modified: trunk/getdata/src/legacy.c =================================================================== --- trunk/getdata/src/legacy.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/legacy.c 2014-04-30 18:10:25 UTC (rev 889) @@ -439,6 +439,8 @@ break; case GD_MULTIPLY_ENTRY: case GD_DIVIDE_ENTRY: + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: Format.n_multiply++; break; case GD_PHASE_ENTRY: @@ -517,6 +519,8 @@ break; case GD_MULTIPLY_ENTRY: case GD_DIVIDE_ENTRY: + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: CopyMultDivEntry(&Format.multiplyEntries[nmultiply++], D->entry[i]); break; case GD_PHASE_ENTRY: Modified: trunk/getdata/src/mod.c =================================================================== --- trunk/getdata/src/mod.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/mod.c 2014-04-30 18:10:25 UTC (rev 889) @@ -614,6 +614,8 @@ break; case GD_MULTIPLY_ENTRY: case GD_DIVIDE_ENTRY: + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: j = _GD_AlterInField(D, 0, Q.in_fields, N->in_fields, E->in_fields, E->fragment_index, 0); if (j < 0) @@ -974,9 +976,9 @@ break; if (Q.EN(scalar,array_len) > E->EN(scalar,array_len)) { - memset(((char**)Qe.u.scalar.d) + E->EN(scalar,array_len), 0, - sizeof(char**) * (Q.EN(scalar,array_len) - - E->EN(scalar,array_len))); + size_t i; + for (i = E->EN(scalar,array_len); i < Q.EN(scalar,array_len); ++i) + ((const char**)Qe.u.scalar.d)[i] = _GD_Strdup(D, ""); } } else Qe.u.scalar.d = E->e->u.scalar.d; @@ -1375,13 +1377,14 @@ return ret; } -int gd_alter_divide(DIRFILE* D, const char* field_code, const char* in_field1, - const char* in_field2) gd_nothrow +static int _GD_AlterYoke(DIRFILE* D, gd_entype_t t, const char* field_code, + const char* in_field1, const char* in_field2) gd_nothrow { int ret; gd_entry_t N; - dtrace("%p, \"%s\", \"%s\", \"%s\"", D, field_code, in_field1, in_field2); + dtrace("%p, 0x%X, \"%s\", \"%s\", \"%s\"", D, t, field_code, in_field1, + in_field2); if (D->flags & GD_INVALID) {/* don't crash */ _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); @@ -1390,7 +1393,7 @@ } memset(&N, 0, sizeof(gd_entry_t)); - N.field_type = GD_DIVIDE_ENTRY; + N.field_type = t; N.in_fields[0] = (char *)in_field1; N.in_fields[1] = (char *)in_field2; @@ -1400,29 +1403,28 @@ return ret; } +int gd_alter_divide(DIRFILE* D, const char* field_code, const char* in_field1, + const char* in_field2) gd_nothrow +{ + return _GD_AlterYoke(D, GD_DIVIDE_ENTRY, field_code, in_field1, in_field2); +} + int gd_alter_multiply(DIRFILE* D, const char* field_code, const char* in_field1, const char* in_field2) gd_nothrow { - int ret; - gd_entry_t N; + return _GD_AlterYoke(D, GD_MULTIPLY_ENTRY, field_code, in_field1, in_field2); +} - dtrace("%p, \"%s\", \"%s\", \"%s\"", D, field_code, in_field1, in_field2); +int gd_alter_indir(DIRFILE* D, const char* field_code, const char* in_field1, + const char* in_field2) gd_nothrow +{ + return _GD_AlterYoke(D, GD_INDIR_ENTRY, field_code, in_field1, in_field2); +} - if (D->flags & GD_INVALID) {/* don't crash */ - _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); - dreturn("%i", -1); - return -1; - } - - memset(&N, 0, sizeof(gd_entry_t)); - N.field_type = GD_MULTIPLY_ENTRY; - N.in_fields[0] = (char *)in_field1; - N.in_fields[1] = (char *)in_field2; - - ret = _GD_Change(D, field_code, &N, 0); - - dreturn("%i", ret); - return ret; +int gd_alter_sindir(DIRFILE* D, const char* field_code, const char* in_field1, + const char* in_field2) gd_nothrow +{ + return _GD_AlterYoke(D, GD_SINDIR_ENTRY, field_code, in_field1, in_field2); } int gd_alter_phase(DIRFILE* D, const char* field_code, const char* in_field, Modified: trunk/getdata/src/name.c =================================================================== --- trunk/getdata/src/name.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/name.c 2014-04-30 18:10:25 UTC (rev 889) @@ -451,46 +451,72 @@ rdat->n_code = 0; for (u = 0; u < D->n_entries; ++u) { - if (update_vectors) - switch (D->entry[u]->field_type) { - case GD_LINCOM_ENTRY: + switch (D->entry[u]->field_type) { + case GD_LINCOM_ENTRY: + if (update_vectors) for (i = 0; i < D->entry[u]->EN(lincom,n_fields); ++i) { if (_GD_UpdateInField(D, D->entry[u], rdat, i, search_meta, mode)) { dreturn("%i", -1); return -1; } } - break; - case GD_MULTIPLY_ENTRY: - case GD_DIVIDE_ENTRY: - case GD_WINDOW_ENTRY: - case GD_MPLEX_ENTRY: + break; + case GD_MULTIPLY_ENTRY: + case GD_DIVIDE_ENTRY: + case GD_WINDOW_ENTRY: + case GD_MPLEX_ENTRY: + if (update_vectors) if (_GD_UpdateInField(D, D->entry[u], rdat, 1, search_meta, mode)) { dreturn("%i", -1); return -1; } - /* Fallthrough */ - case GD_LINTERP_ENTRY: - case GD_BIT_ENTRY: - case GD_PHASE_ENTRY: - case GD_POLYNOM_ENTRY: - case GD_RECIP_ENTRY: - case GD_SBIT_ENTRY: + /* Fallthrough */ + case GD_LINTERP_ENTRY: + case GD_BIT_ENTRY: + case GD_PHASE_ENTRY: + case GD_POLYNOM_ENTRY: + case GD_RECIP_ENTRY: + case GD_SBIT_ENTRY: + if (update_vectors) if (_GD_UpdateInField(D, D->entry[u], rdat, 0, search_meta, mode)) { dreturn("%i", -1); return -1; } - break; - case GD_INDEX_ENTRY: - case GD_RAW_ENTRY: - case GD_NO_ENTRY: - case GD_CONST_ENTRY: - case GD_CARRAY_ENTRY: - case GD_SARRAY_ENTRY: - case GD_STRING_ENTRY: - case GD_ALIAS_ENTRY: - break; - } + break; + case GD_INDIR_ENTRY: + if (update_vectors) + if (_GD_UpdateInField(D, D->entry[u], rdat, 0, search_meta, mode)) { + dreturn("%i", -1); + return -1; + } + if (rdat->E->field_type == GD_CARRAY_ENTRY || search_meta) + if (_GD_UpdateInField(D, D->entry[u], rdat, 1, search_meta, mode)) { + dreturn("%i", -1); + return -1; + } + break; + case GD_SINDIR_ENTRY: + if (update_vectors) + if (_GD_UpdateInField(D, D->entry[u], rdat, 0, search_meta, mode)) { + dreturn("%i", -1); + return -1; + } + if (rdat->E->field_type == GD_SARRAY_ENTRY || search_meta) + if (_GD_UpdateInField(D, D->entry[u], rdat, 1, search_meta, mode)) { + dreturn("%i", -1); + return -1; + } + break; + case GD_INDEX_ENTRY: + case GD_RAW_ENTRY: + case GD_NO_ENTRY: + case GD_CONST_ENTRY: + case GD_CARRAY_ENTRY: + case GD_SARRAY_ENTRY: + case GD_STRING_ENTRY: + case GD_ALIAS_ENTRY: + break; + } if (update_scalars) switch (D->entry[u]->field_type) { case GD_LINCOM_ENTRY: @@ -536,6 +562,8 @@ case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: case GD_SARRAY_ENTRY: + case GD_INDIR_ENTRY: + case GD_SINDIR_ENTRY: case GD_ALIAS_ENTRY: break; } Modified: trunk/getdata/src/native.c =================================================================== --- trunk/getdata/src/native.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/native.c 2014-04-30 18:10:25 UTC (rev 889) @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2012 D. V. Wiebe +/* Copyright (C) 2009-2012, 2014 D. V. Wiebe * *************************************************************************** * @@ -49,7 +49,7 @@ type = GD_FLOAT64; for (i = 0; i < E->EN(lincom,n_fields); ++i) { - if (_GD_BadInput(D, E, i, 1)) + if (_GD_BadInput(D, E, i, GD_NO_ENTRY, 1)) break; if (_GD_NativeType(D, E->e->entry[i], E->e->repr[i]) & GD_COMPLEX) { @@ -70,8 +70,11 @@ break; case GD_MULTIPLY_ENTRY: case GD_DIVIDE_ENTRY: - if (_GD_BadInput(D, E, 0, 1) || _GD_BadInput(D, E, 1, 1)) + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1) || + _GD_BadInput(D, E, 1, GD_NO_ENTRY, 1)) + { break; + } type = (_GD_NativeType(D, E->e->entry[0], E->e->repr[0]) & GD_COMPLEX || _GD_NativeType(D, E->e->entry[1], E->e->repr[1]) & GD_COMPLEX) @@ -81,7 +84,7 @@ if (!(E->flags & GD_EN_CALC)) _GD_CalculateEntry(D, E, 1); - if (_GD_BadInput(D, E, 0, 1)) + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) break; type = ((_GD_NativeType(D, E->e->entry[0], E->e->repr[0]) & GD_COMPLEX) @@ -94,7 +97,7 @@ case GD_PHASE_ENTRY: case GD_WINDOW_ENTRY: case GD_MPLEX_ENTRY: - if (_GD_BadInput(D, E, 0, 1)) + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) break; type = _GD_NativeType(D, E->e->entry[0], E->e->repr[0]); @@ -108,7 +111,7 @@ break; } - if (_GD_BadInput(D, E, 0, 1)) + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) break; type = (_GD_NativeType(D, E->e->entry[0], E->e->repr[0]) & GD_COMPLEX) ? @@ -120,10 +123,18 @@ break; case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: - type = E->EN(scalar,const_type); + type = _GD_ConstType(D, E->EN(scalar,const_type)); break; + case GD_INDIR_ENTRY: + if (_GD_BadInput(D, E, 1, GD_CARRAY_ENTRY, 1)) + break; + + type = _GD_NativeType(D, E->e->entry[1], E->e->repr[1]); + + break; case GD_STRING_ENTRY: case GD_SARRAY_ENTRY: + case GD_SINDIR_ENTRY: type = GD_NULL; break; case GD_NO_ENTRY: Modified: trunk/getdata/src/parse.c =================================================================== --- trunk/getdata/src/parse.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/parse.c 2014-04-30 18:10:25 UTC (rev 889) @@ -526,9 +526,10 @@ return E; } -/* _GD_ParseMultiply: parse MULTIPLY entry in format file. +/* _GD_ParseYoke: parse a field specified by two input fields only (MULTIPLY, + * DIVIDE, INDIR, SINDIR) */ -static gd_entry_t *_GD_ParseMultiply(DIRFILE *restrict D, +static gd_entry_t *_GD_ParseYoke(DIRFILE *restrict D, gd_entype_t type, char *gd_restrict_arr in_cols[MAX_IN_COLS], int n_cols, const gd_entry_t *restrict parent, const char *restrict format_file, int line, int me, int standards, int pedantic, int *restrict is_dot) @@ -536,8 +537,8 @@ gd_entry_t *E; int offset; - dtrace("%p, %p, %i, %p, \"%s\", %i, %i, %i, %i, %p", D, in_cols, n_cols, - parent, format_file, line, me, standards, pedantic, is_dot); + dtrace("%p, 0x%X, %p, %i, %p, \"%s\", %i, %i, %i, %i, %p", D, type, in_cols, + n_cols, parent, format_file, line, me, standards, pedantic, is_dot); if (n_cols < 4) { _GD_SetError(D, GD_E_FORMAT, GD_E_FORMAT_N_TOK, format_file, line, NULL); @@ -561,7 +562,7 @@ } memset(E->e, 0, sizeof(struct gd_private_entry_)); - E->field_type = GD_MULTIPLY_ENTRY; + E->field_type = type; E->in_fields[0] = E->in_fields[1] = NULL; E->e->entry[0] = E->e->entry[1] = NULL; E->flags |= GD_EN_CALC; @@ -818,69 +819,6 @@ return E; } -/* _GD_ParseDivide: parse DIVIDE entry in format file. -*/ -static gd_entry_t *_GD_ParseDivide(DIRFILE *restrict D, - char *gd_restrict_arr in_cols[MAX_IN_COLS], int n_cols, - const gd_entry_t *restrict parent, const char *restrict format_file, - int line, int me, int standards, int pedantic, int *restrict is_dot) -{ - gd_entry_t *E; - int offset; - - dtrace("%p, %p, %i, %p, \"%s\", %i, %i, %i, %i, %p", D, in_cols, n_cols, - parent, format_file, line, me, standards, pedantic, is_dot); - - if (n_cols < 4) { - _GD_SetError(D, GD_E_FORMAT, GD_E_FORMAT_N_TOK, format_file, line, NULL); - dreturn("%p", NULL); - return NULL; - } - - E = (gd_entry_t *)_GD_Malloc(D, sizeof(gd_entry_t)); - if (E == NULL) { - dreturn("%p", NULL); - return NULL; - } - memset(E, 0, sizeof(gd_entry_t)); - - E->e = (struct gd_private_entry_ *)_GD_Malloc(D, - sizeof(struct gd_private_entry_)); - if (E->e == NULL) { - free(E); - dreturn("%p", NULL); - return NULL; - } - memset(E->e, 0, sizeof(struct gd_private_entry_)); - - E->field_type = GD_DIVIDE_ENTRY; - E->in_fields[0] = E->in_fields[1] = NULL; - E->e->entry[0] = E->e->entry[1] = NULL; - - E->field = _GD_MungeFromFrag(D, parent, me, in_cols[0], &offset); - if (E->field && _GD_ValidateField(E->field + offset, standards, pedantic, 0, - is_dot)) - { - _GD_SetError(D, GD_E_FORMAT, GD_E_FORMAT_BAD_NAME, format_file, line, - in_cols[0]); - _GD_FreeE(D, E, 1); - dreturn("%p", NULL); - return NULL; - } - - E->in_fields[0] = _GD_MungeFromFrag(D, NULL, me, in_cols[2], &offset); - E->in_fields[1] = _GD_MungeFromFrag(D, NULL, me, in_cols[3], &offset); - - if (D->error) { - _GD_FreeE(D, E, 1); - dreturn("%p", NULL); - return NULL; - } - - dreturn("%p", E); - return E; -} - /* _GD_ParseBit: parse BIT entry in format file. */ static gd_entry_t *_GD_ParseBit(DIRFILE *restrict D, int is_signed, @@ -1602,8 +1540,8 @@ E = _GD_ParseLinterp(D, in_cols, n_cols, P, format_file, linenum, me, standards, pedantic, &is_dot); else if (strcmp(in_cols[1], "MULTIPLY") == 0 && (!pedantic || standards >= 2)) - E = _GD_ParseMultiply(D, in_cols, n_cols, P, format_file, linenum, me, - standards, pedantic, &is_dot); + E = _GD_ParseYoke(D, GD_MULTIPLY_ENTRY, in_cols, n_cols, P, format_file, + linenum, me, standards, pedantic, &is_dot); else if (strcmp(in_cols[1], "BIT") == 0) E = _GD_ParseBit(D, 0, in_cols, n_cols, P, format_file, linenum, me, standards, pedantic, &is_dot); @@ -1617,8 +1555,8 @@ E = _GD_ParseBit(D, 1, in_cols, n_cols, P, format_file, linenum, me, standards, pedantic, &is_dot); else if (strcmp(in_cols[1], "DIVIDE") == 0 && (!pedantic || standards >= 8)) - E = _GD_ParseDivide(D, in_cols, n_cols, P, format_file, linenum, me, - standards, pedantic, &is_dot); + E = _GD_ParseYoke(D, GD_DIVIDE_ENTRY, in_cols, n_cols, P, format_file, + linenum, me, standards, pedantic, &is_dot); else if (strcmp(in_cols[1], "RECIP") == 0 && (!pedantic || standards >= 8)) E = _GD_ParseRecip(D, in_cols, n_cols, P, format_file, linenum, me, standards, pedantic, &is_dot); @@ -1628,6 +1566,12 @@ else if (strcmp(in_cols[1], "MPLEX") == 0 && (!pedantic || standards >= 9)) E = _GD_ParseMplex(D, in_cols, n_cols, P, format_file, linenum, me, standards, pedantic, &is_dot); + else if (strcmp(in_cols[1], "INDIR") == 0 && (!pedantic || standards >= 10)) + E = _GD_ParseYoke(D, GD_INDIR_ENTRY, in_cols, n_cols, P, format_file, + linenum, me, standards, pedantic, &is_dot); + else if (strcmp(in_cols[1], "SINDIR") == 0 && (!pedantic || standards >= 10)) + E = _GD_ParseYoke(D, GD_SINDIR_ENTRY, in_cols, n_cols, P, format_file, + linenum, me, standards, pedantic, &is_dot); else if (strcmp(in_cols[1], "CONST") == 0 && (!pedantic || standards >= 6)) E = _GD_ParseConst(D, in_cols, n_cols, P, format_file, linenum, me, standards, pedantic, &is_dot); @@ -1637,7 +1581,7 @@ else if (strcmp(in_cols[1], "STRING") == 0 && (!pedantic || standards >= 6)) E = _GD_ParseString(D, in_cols, n_cols, P, format_file, linenum, me, standards, pedantic, &is_dot); - else if (strcmp(in_cols[1], "SARRAY") == 0 && (!pedantic || standards >= 8)) + else if (strcmp(in_cols[1], "SARRAY") == 0 && (!pedantic || standards >= 10)) E = _GD_ParseArray(D, 1, in_cols, n_cols, P, format_file, linenum, me, standards, pedantic, &is_dot, outstring, tok_pos); else if (standards <= GD_DIRFILE_STANDARDS_VERSION || pedantic) Modified: trunk/getdata/src/putdata.c =================================================================== --- trunk/getdata/src/putdata.c 2014-04-27 21:29:36 UTC (rev 888) +++ trunk/getdata/src/putdata.c 2014-04-30 18:10:25 UTC (rev 889) @@ -116,7 +116,7 @@ dtrace("%p, %p, %lli, %" PRNsize_t ", 0x%X, %p", D, E, (long long)first_samp, num_samp, data_type, data_in); - if (_GD_BadInput(D, E, 0, 1)) { + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } @@ -226,7 +226,7 @@ return 0; } - if (_GD_BadInput(D, E, 0, 1)) { + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } @@ -296,7 +296,7 @@ dtrace("%p, %p, %lli, %" PRNsize_t ", 0x%X, %p", D, E, (long long)first_samp, num_samp, data_type, data_in); - if (_GD_BadInput(D, E, 0, 1)) { + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } @@ -351,7 +351,7 @@ dtrace("%p, %p, %lli, %" PRNsize_t ", 0x%X, %p", D, E, (long long)first_samp, num_samp, data_type, data_in); - if (_GD_BadInput(D, E, 0, 1)) { + if (_GD_BadInput(D, E, 0, GD_NO_ENTRY, 1)) { dreturn("%i", 0); return 0; } @@ -374,7 +374,7 @@ dtrace("%p, %p, %lli, %" PRNsize_t ", ... [truncated message content] |
From: <ket...@us...> - 2014-04-30 21:52:03
|
Revision: 891 http://sourceforge.net/p/getdata/code/891 Author: ketiltrout Date: 2014-04-30 21:51:58 +0000 (Wed, 30 Apr 2014) Log Message: ----------- Fix gd_get_const and gd_get_string. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/Makefile.am trunk/getdata/src/constant.c trunk/getdata/src/string.c trunk/getdata/test/Makefile.am Added Paths: ----------- trunk/getdata/test/get_const_carray.c Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2014-04-30 21:48:53 UTC (rev 890) +++ trunk/getdata/ChangeLog 2014-04-30 21:51:58 UTC (rev 891) @@ -1,3 +1,11 @@ +2014-04-30 D. V. Wiebe <ge...@ke...> svn:890 svn:891 + * bindings/cxx/test/big_test.cpp bindings/f77/test/big_test.f + bindings/f77/test/big_test95.f90 bindings/idl/test/big_test.pro + bindings/python/test/big_test.py: Fix test 157 for DSV 10. + * src/constant.c (gd_get_constant) src/string.c (gd_get_string): Fix call in + the case of using a [CS]ARRAY after breaking it. + * test/get_const_carray.c: Added. + 2014-04-30 D. V. Wiebe <ge...@ke...> svn:889 * test/parse_indir.c test/get_sindir.c test/alter_entry_sarray.c test/add_sindir.c test/getstr_sindir.c test/name_updb_sarray.c Modified: trunk/getdata/Makefile.am =================================================================== --- trunk/getdata/Makefile.am 2014-04-30 21:48:53 UTC (rev 890) +++ trunk/getdata/Makefile.am 2014-04-30 21:51:58 UTC (rev 891) @@ -18,7 +18,7 @@ # along with GetData; if not, write to the Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # -AUTOMAKE_OPTIONS = foreign dist-xz check-news 1.10 +AUTOMAKE_OPTIONS = foreign dist-xz check-news 1.11 EXTRA_DIST = ChangeLog Modified: trunk/getdata/src/constant.c =================================================================== --- trunk/getdata/src/constant.c 2014-04-30 21:48:53 UTC (rev 890) +++ trunk/getdata/src/constant.c 2014-04-30 21:51:58 UTC (rev 891) @@ -118,7 +118,7 @@ int gd_get_constant(DIRFILE* D, const char *field_code_in, gd_type_t return_type, void *data_out) gd_nothrow { - return gd_get_carray(D, field_code_in, return_type, data_out); + return gd_get_carray_slice(D, field_code_in, 0, 1, return_type, data_out); } size_t gd_carray_len(DIRFILE *D, const char *field_code_in) gd_nothrow Modified: trunk/getdata/src/string.c =================================================================== --- trunk/getdata/src/string.c 2014-04-30 21:48:53 UTC (rev 890) +++ trunk/getdata/src/string.c 2014-04-30 21:51:58 UTC (rev 891) @@ -121,7 +121,7 @@ dtrace("%p, \"%s\", %" PRNsize_t ", %p", D, field_code, len, data_out); /* get string */ - if (gd_get_sarray(D, field_code, &ptr)) { + if (gd_get_sarray_slice(D, field_code, 0, 1, &ptr)) { dreturn("%i", 0); return 0; } Modified: trunk/getdata/test/Makefile.am =================================================================== --- trunk/getdata/test/Makefile.am 2014-04-30 21:48:53 UTC (rev 890) +++ trunk/getdata/test/Makefile.am 2014-04-30 21:51:58 UTC (rev 891) @@ -180,11 +180,11 @@ GET_TESTS=get64 get_affix get_bad_code get_bit get_carray get_carray_len \ get_carray_c2r get_carray_slice get_char get_clincom get_complex128 \ - get_complex64 get_const get_const_complex get_const_repr \ - get_cpolynom get_cpolynom1 get_cpolynom_int get_dim get_divide \ - get_divide_ccin get_divide_crin get_divide_crinr get_divide_rcin \ - get_divide_s get_endian8 get_endian16 get_endian32 get_endian64 \ - get_endian_complex128_arm get_endian_complex128_big \ + get_complex64 get_const get_const_carray get_const_complex \ + get_const_repr get_cpolynom get_cpolynom1 get_cpolynom_int get_dim \ + get_divide get_divide_ccin get_divide_crin get_divide_crinr \ + get_divide_rcin get_divide_s get_endian8 get_endian16 get_endian32 \ + get_endian64 get_endian_complex128_arm get_endian_complex128_big \ get_endian_complex128_little get_endian_complex64_arm \ get_endian_complex64_big get_endian_complex64_little \ get_endian_float32_arm get_endian_float32_big \ Added: trunk/getdata/test/get_const_carray.c =================================================================== --- trunk/getdata/test/get_const_carray.c (rev 0) +++ trunk/getdata/test/get_const_carray.c 2014-04-30 21:51:58 UTC (rev 891) @@ -0,0 +1,57 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +int main(void) +{ + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *format_data = "carray CARRAY FLOAT64 8.3 7.2 6.1 5.0 3.9 2.8 1.7\n"; + double c; + int fd, i, n, error, r = 0; + DIRFILE *D; + + rmdirfile(); + mkdir(filedir, 0777); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); + n = gd_get_constant(D, "carray", GD_FLOAT64, &c); + error = gd_error(D); + + CHECKI(error, 0); + CHECKI(n, 0); + CHECKF(c, 8.3); + + gd_discard(D); + + unlink(format); + rmdir(filedir); + + return r; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2014-05-05 20:38:51
|
Revision: 895 http://sourceforge.net/p/getdata/code/895 Author: ketiltrout Date: 2014-05-05 20:38:45 +0000 (Mon, 05 May 2014) Log Message: ----------- * Remove GD_MAX_CARRAY_LENGTH. * Add gd_encoding_support(). Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/NEWS trunk/getdata/man/Makefile.am trunk/getdata/man/gd_add.3 trunk/getdata/man/gd_add_bit.3 trunk/getdata/man/gd_alter_spec.3 trunk/getdata/man/gd_cbopen.3 trunk/getdata/src/add.c trunk/getdata/src/encoding.c trunk/getdata/src/getdata.h.in trunk/getdata/src/mod.c trunk/getdata/src/parse.c trunk/getdata/test/Makefile.am Added Paths: ----------- trunk/getdata/man/gd_encoding_support.3 trunk/getdata/test/encode_support.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/ChangeLog 2014-05-05 20:38:45 UTC (rev 895) @@ -1,3 +1,19 @@ +2014-05-05 D. V. Wiebe <ge...@ke...> svn:895 + * src/getdata.h.in: Remove GD_MAX_CARRAY_LENGTH. + * src/add.c (_GD_Add) src/mod.c (_GD_Change) src/parse.c (_GD_ParseArray): + Remove references to GD_MAX_CARRAY_LENGTH. + + * src/add.c (gd_add_raw gd_add_lincom gd_add_clincom gd_add_linterp + gd_add_bit gd_add_sbit _GD_AddYoke gd_add_recip gd_add_crecip89 + gd_add_polynom gd_add_cpolynom gd_add_phase gd_add_window gd_add_mplex + gd_madd_lincom gd_madd_clincom gd_madd_linterp gd_madd_bit gd_madd_sbit + _GD_MAddYoke gd_madd_phase gd_madd_polynom gd_madd_cpolynom gd_madd_recip + gd_madd_crecip89 gd_madd_window gd_madd_mplex): Call _GD_Add in a slightly + less ridiculous way. + + * src/encoding.c (gd_encoding_support): Added. + * man/gd_encoding_support.3 test/encode_support.c: Added. + 2014-04-30 D. V. Wiebe <ge...@ke...> svn:890 svn:891 * bindings/cxx/test/big_test.cpp bindings/f77/test/big_test.f bindings/f77/test/big_test95.f90 bindings/idl/test/big_test.pro Modified: trunk/getdata/NEWS =================================================================== --- trunk/getdata/NEWS 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/NEWS 2014-05-05 20:38:45 UTC (rev 895) @@ -17,6 +17,13 @@ renamed field to point to the new field instead of leaving them dangle. (But see GD_REN_DANGLE). + * CARRAYs are no longer truncated to GD_MAX_CARRAY_LENGTH elements. Flushing + metadata to disk will now fail if writing a CARRAY would overflow a format + file line. (It's platform specific, but format file lines are typically + permitted to be at least 2**31 bytes long, so such an error usually + indicates something pathological happening.) The GD_MAX_CARRAY_LENGTH + symbol has been removed from the GetData header file. + * BUG FIX: The parsing of the \x and \u escape sequences are now correct. * BUG FIX: Computation of LINCOMs with complex valued input fields now @@ -135,6 +142,9 @@ gd_move(). If gd_move() is passed the field code of an alias, the alias is now moved, instead of moving the field the alias points to. + * gd_encoding_support() has been added to permit run-time determination of + supported encodings. + * BUG FIX: If the dirfile path provided cannot be resolved (due to, for instance, a symbolic link pointing to a non-existent path), gd_open() and friends now return GD_E_OPEN, as documented, instead of GD_E_RAW_IO. Modified: trunk/getdata/man/Makefile.am =================================================================== --- trunk/getdata/man/Makefile.am 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/man/Makefile.am 2014-05-05 20:38:45 UTC (rev 895) @@ -28,17 +28,17 @@ gd_alter_protection.3 gd_alter_spec.3 gd_bof.3 gd_bof64.3 \ gd_carray_len.3 gd_carrays.3 gd_cbopen.3 gd_close.3 \ gd_constants.3 gd_delete.3 gd_desync.3 gd_dirfile_standards.3 \ - gd_dirfilename.3 gd_encoding.3 gd_endianness.3 gd_entry.3 \ - gd_entry_list.3 gd_entry_type.3 gd_eof.3 gd_eof64.3 gd_error.3 \ - gd_error_count.3 gd_error_string.3 gd_flags.3 gd_flush.3 \ - gd_fragment_affixes.3 gd_fragment_index.3 gd_fragmentname.3 \ - gd_framenum_subset.3 gd_framenum_subset64.3 gd_frameoffset.3 \ - gd_frameoffset64.3 gd_free_entry_strings.3 \ - gd_get_carray_slice.3 gd_get_string.3 gd_getdata.3 \ - gd_getdata64.3 gd_hidden.3 gd_hide.3 gd_include_affix.3 \ - gd_invalid_dirfile.3 gd_linterp_tablename.3 gd_madd_bit.3 \ - gd_mcarrays.3 gd_mconstants.3 gd_metaflush.3 gd_move.3 \ - gd_mplex_lookback.3 gd_mstrings.3 gd_naliases.3 \ + gd_dirfilename.3 gd_encoding.3 gd_encoding_support.3 \ + gd_endianness.3 gd_entry.3 gd_entry_list.3 gd_entry_type.3 \ + gd_eof.3 gd_eof64.3 gd_error.3 gd_error_count.3 \ + gd_error_string.3 gd_flags.3 gd_flush.3 gd_fragment_affixes.3 \ + gd_fragment_index.3 gd_fragmentname.3 gd_framenum_subset.3 \ + gd_framenum_subset64.3 gd_frameoffset.3 gd_frameoffset64.3 \ + gd_free_entry_strings.3 gd_get_carray_slice.3 gd_get_string.3 \ + gd_getdata.3 gd_getdata64.3 gd_hidden.3 gd_hide.3 \ + gd_include_affix.3 gd_invalid_dirfile.3 gd_linterp_tablename.3 \ + gd_madd_bit.3 gd_mcarrays.3 gd_mconstants.3 gd_metaflush.3 \ + gd_move.3 gd_mplex_lookback.3 gd_mstrings.3 gd_naliases.3 \ gd_native_type.3 gd_nentries.3 gd_nfragments.3 gd_nframes.3 \ gd_nframes64.3 gd_parent_fragment.3 gd_parser_callback.3 \ gd_protection.3 gd_put_carray_slice.3 \ Modified: trunk/getdata/man/gd_add.3 =================================================================== --- trunk/getdata/man/gd_add.3 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/man/gd_add.3 2014-05-05 20:38:45 UTC (rev 895) @@ -13,7 +13,7 @@ .\" Texts. A copy of the license is included in the `COPYING.DOC' file .\" as part of this distribution. .\" -.TH gd_add 3 "10 December 2013" "Version 0.9.0" "GETDATA" +.TH gd_add 3 "5 May 2014" "Version 0.9.0" "GETDATA" .SH NAME gd_add, gd_madd \(em add a field to a dirfile .SH SYNOPSIS @@ -153,13 +153,6 @@ .B CARRAY entry, was invalid. .TP -.B GD_E_BOUNDS -The -.IR entry -> array_len -parameter provided with a -.B CARRAY -entry was greater than GD_MAX_CARRAY_LENGTH. -.TP .B GD_E_DUPLICATE The field name provided in .IR entry -> field @@ -199,15 +192,6 @@ A descriptive error string for the last error encountered can be obtained from a call to .BR gd_error_string (3). -.SH NOTES -GetData artificially limits the number of elements in a -.B CARRAY -to the value of the symbol GD_MAX_CARRAY_LENGTH defined in getdata.h. This is -done to be certain that the -.B CARRAY -won't overrun the line when flushed to disk. On platforms with a \fIn\fR-bit -.BR size_t , -GD_MAX_CARRAY_LENGTH is 2**(\fIn\fR-8)-1. .SH SEE ALSO .BR gd_add_bit (3), Modified: trunk/getdata/man/gd_add_bit.3 =================================================================== --- trunk/getdata/man/gd_add_bit.3 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/man/gd_add_bit.3 2014-05-05 20:38:45 UTC (rev 895) @@ -13,7 +13,7 @@ .\" Texts. A copy of the license is included in the `COPYING.DOC' file .\" as part of this distribution. .\" -.TH gd_add_bit 3 "30 September 2013" "Version 0.9.0" "GETDATA" +.TH gd_add_bit 3 "5 May 2014" "Version 0.9.0" "GETDATA" .SH NAME gd_add_bit, gd_add_carray gd_add_clincom, gd_add_const, gd_add_cpolynom, gd_add_crecip, gd_add_divide, gd_add_lincom, gd_add_linterp, gd_add_multiply, @@ -254,13 +254,6 @@ .BR gd_add_raw "() or " gd_add_const (), was invalid. .TP -.B GD_E_BOUNDS -The -.I array_len -parameter provided to -.BR gd_add_carray () -was greater than GD_MAX_CARRAY_LENGTH. -.TP .B GD_E_DUPLICATE The .IR field_name @@ -302,15 +295,6 @@ .BR gd_error_string (3). .SH NOTES -GetData artificially limits the number of elements in a -.B CARRAY -to the value of the symbol GD_MAX_CARRAY_LENGTH defined in getdata.h. This is -done to be certain that the -.B CARRAY -won't overrun the line when flushed to disk. On platforms with a \fIn\fR-bit -.BR size_t , -GD_MAX_CARRAY_LENGTH is 2**(\fIn\fR-8)-1. - The C89 GetData API provides different prototypes for .BR gd_add_clincom "(), " gd_add_cpolynom (), and Modified: trunk/getdata/man/gd_alter_spec.3 =================================================================== --- trunk/getdata/man/gd_alter_spec.3 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/man/gd_alter_spec.3 2014-05-05 20:38:45 UTC (rev 895) @@ -13,7 +13,7 @@ .\" Texts. A copy of the license is included in the `COPYING.DOC' file .\" as part of this distribution. .\" -.TH gd_alter_spec 3 "17 August 2011" "Version 0.8.0" "GETDATA" +.TH gd_alter_spec 3 "5 May 2014" "Version 0.9.0" "GETDATA" .SH NAME gd_alter_spec, gd_malter_spec \(em modify a field in a dirfile .SH SYNOPSIS @@ -152,13 +152,6 @@ A descriptive error string for the last error encountered can be obtained from a call to .BR gd_error_string (3). -.SH NOTES -If a -.B CARRAY -field with more than GD_MAX_CARRAY_LENGTH elements is provided, subsequent -elements will be silently truncated. On platforms with a \fIn\fR-bit -.BR size_t , -GD_MAX_CARRAY_LENGTH is 2**(\fIn\fR-8)-1. .SH SEE ALSO .BR gd_alter_bit (3), .BR gd_alter_const (3), Modified: trunk/getdata/man/gd_cbopen.3 =================================================================== --- trunk/getdata/man/gd_cbopen.3 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/man/gd_cbopen.3 2014-05-05 20:38:45 UTC (rev 895) @@ -13,7 +13,7 @@ .\" Texts. A copy of the license is included in the `COPYING.DOC' file .\" as part of this distribution. .\" -.TH gd_cbopen 3 "3 April 2013" "Version 0.8.4" "GETDATA" +.TH gd_cbopen 3 "5 May 2014" "Version 0.9.0" "GETDATA" .SH NAME gd_cbopen, gd_open \(em open or create a dirfile .SH SYNOPSIS @@ -716,15 +716,6 @@ .B GD_LITTLE_ENDIAN should be specified by the caller. -GetData artificially limits the size of a -.B CARRAY -field to GD_MAX_CARRAY_LENGTH elements, to be certain it is always able to -write the CARRAY back to disk without overrunning its maximum line length. -On platforms with a \fIn\fR-bit -.BR size_t , -GD_MAX_CARRAY_LENGTH is 2**(\fIn\fR-8)-1. Excess elements are silently -truncated on dirfile open. - GetData's parser assumes it is running on an ASCII-compatible platform. Format specification parsing will fail gloriously on an EBCDIC platform. .SH SEE ALSO Added: trunk/getdata/man/gd_encoding_support.3 =================================================================== --- trunk/getdata/man/gd_encoding_support.3 (rev 0) +++ trunk/getdata/man/gd_encoding_support.3 2014-05-05 20:38:45 UTC (rev 895) @@ -0,0 +1,69 @@ +.\" gd_encoding_support.3. The gd_encoding_support man page. +.\" +.\" Copyright (C) 2014 D. V. Wiebe +.\" +.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.\" +.\" This file is part of the GetData project. +.\" +.\" Permission is granted to copy, distribute and/or modify this document +.\" under the terms of the GNU Free Documentation License, Version 1.2 or +.\" any later version published by the Free Software Foundation; with no +.\" Invariant Sections, with no Front-Cover Texts, and with no Back-Cover +.\" Texts. A copy of the license is included in the `COPYING.DOC' file +.\" as part of this distribution. +.\" +.TH gd_encoding_support 3 "5 May 2014" "Version 0.9.0" "GETDATA" +.SH NAME +gd_encoding_support \(em determine GetData library support for data encodings +.SH SYNOPSIS +.B #include <getdata.h> +.HP +.nh +.ad l +.BI "int gd_encoding_support(unsigned long " encoding ); +.hy +.ad n +.SH DESCRIPTION +The +.BR gd_encoding_support () +function reports whether the Dirfile encoding specified by +.I encoding +is supported by the GetData library. The +.I encoding +argument should be one of the following symbols, indicating the encoding type: +.IP +.nh +.ad l +.BR GD_UNENCODED ", " GD_BZIP2_ENCODED ", " GD_GZIP_ENCODED , +.BR GD_LZMA_ENCODED ", " GD_SIE_ENCODED ", " GD_SLIM_ENCODED , +.BR GD_TEXT_ENCODED ", " GD_ZZIP_ENCODED ", " GD_ZZSLIM_ENCODED . +.ad n +.hy +.PP +See +.BR gd_cbopen (3) +and dirfile-encoding(5) for the meanings of these symbols and details on the +known encoding schemes. + +.SH RETURN VALUE +The function +.BR gd_encoding_support () +returns +.B GD_RDWR +if the GetData library can read from and write to the specified encoding, +.B GD_RDONLY +if the GetData library can only read from the specified encoding, or -1 if +neither reading nor writing is supported, or if +.I encoding +was not one of the symbols listed above. +.SH NOTES +GetData's encoding support framework is more finely grained than the three-way +system reported by this function. It is possible for the library to have +partial support for reading or writing a particular encoding. This function +will only report positive support if all functions of a given class (read-only +or read-write) are supported. +.SH SEE ALSO +dirfile-encoding(5), +.BR gd_cbopen (3), +.BR gd_encoding (3) Modified: trunk/getdata/src/add.c =================================================================== --- trunk/getdata/src/add.c 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/src/add.c 2014-05-05 20:38:45 UTC (rev 895) @@ -500,9 +500,7 @@ == 0) { _GD_SetError(D, GD_E_BAD_TYPE, E->EN(scalar,const_type), NULL, 0, NULL); - } else if (E->EN(scalar,array_len) > GD_MAX_CARRAY_LENGTH) - _GD_SetError(D, GD_E_BOUNDS, 0, NULL, 0, NULL); - else { + } else { size_t size = GD_SIZE(_GD_ConstType(D, E->EN(scalar,const_type))) * E->EN(scalar,array_len); if (!D->error) @@ -817,7 +815,6 @@ unsigned int spf, int fragment_index) { gd_entry_t R; - int error; dtrace("%p, \"%s\", 0x%X, %i, %i", D, field_code, data_type, spf, fragment_index); @@ -834,10 +831,14 @@ R.EN(raw,spf) = spf; R.EN(raw,data_type) = data_type; R.fragment_index = fragment_index; - error = (_GD_Add(D, &R, NULL) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &R, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a LINCOM entry */ @@ -845,7 +846,7 @@ const char** in_fields, const double* m, const double* b, int fragment_index) gd_nothrow { - int i, error; + int i; gd_entry_t L; dtrace("%p, \"%s\", %i, %p, %p, %p, %i", D, field_code, n_fields, in_fields, @@ -874,10 +875,14 @@ L.EN(lincom,m)[i] = m[i]; L.EN(lincom,b)[i] = b[i]; } - error = (_GD_Add(D, &L, NULL) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &L, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a LINCOM entry with complex scalars */ @@ -885,7 +890,7 @@ const char** in_fields, const GD_DCOMPLEXP(cm), const GD_DCOMPLEXP(cb), int fragment_index) gd_nothrow { - int i, error; + int i; gd_entry_t L; dtrace("%p, \"%s\", %i, %p, %p, %p, %i", D, field_code, n_fields, in_fields, @@ -915,10 +920,14 @@ gd_ca2cs_(L.EN(lincom,cm)[i], cm, i); gd_ca2cs_(L.EN(lincom,cb)[i], cb, i); } - error = (_GD_Add(D, &L, NULL) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &L, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a LINTERP entry */ @@ -926,7 +935,6 @@ const char* table, int fragment_index) gd_nothrow { gd_entry_t L; - int error; dtrace("%p, \"%s\", \"%s\", \"%s\", %i", D, field_code, in_field, table, fragment_index); @@ -943,10 +951,14 @@ L.in_fields[0] = (char *)in_field; L.EN(linterp,table) = (char *)table; L.fragment_index = fragment_index; - error = (_GD_Add(D, &L, NULL) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &L, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a BIT entry */ @@ -954,7 +966,6 @@ int bitnum, int numbits, int fragment_index) gd_nothrow { gd_entry_t B; - int error; dtrace("%p, \"%s\", \"%s\", %i, %i, %i", D, field_code, in_field, bitnum, numbits, fragment_index); @@ -972,10 +983,14 @@ B.EN(bit,bitnum) = bitnum; B.EN(bit,numbits) = numbits; B.fragment_index = fragment_index; - error = (_GD_Add(D, &B, NULL) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &B, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a SBIT entry */ @@ -983,7 +998,6 @@ int bitnum, int numbits, int fragment_index) gd_nothrow { gd_entry_t B; - int error; dtrace("%p, \"%s\", \"%s\", %i, %i, %i", D, field_code, in_field, bitnum, numbits, fragment_index); @@ -1001,17 +1015,20 @@ B.EN(bit,bitnum) = bitnum; B.EN(bit,numbits) = numbits; B.fragment_index = fragment_index; - error = (_GD_Add(D, &B, NULL) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &B, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } static int _GD_AddYoke(DIRFILE* D, gd_entype_t t, const char* field_code, const char* in_field1, const char* in_field2, int fragment_index) gd_nothrow { gd_entry_t M; - int error; dtrace("%p, 0x%X, \"%s\", \"%s\", \"%s\", %i", D, t, field_code, in_field1, in_field2, fragment_index); @@ -1028,10 +1045,14 @@ M.in_fields[0] = (char *)in_field1; M.in_fields[1] = (char *)in_field2; M.fragment_index = fragment_index; - error = (_GD_Add(D, &M, NULL) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &M, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } int gd_add_multiply(DIRFILE* D, const char* field_code, const char* in_field1, @@ -1067,7 +1088,6 @@ double dividend, int fragment_index) gd_nothrow { gd_entry_t E; - int error; dtrace("%p, \"%s\", \"%s\", %g, %i", D, field_code, in_field, dividend, fragment_index); @@ -1084,10 +1104,14 @@ E.EN(recip,dividend) = dividend; E.in_fields[0] = (char *)in_field; E.fragment_index = fragment_index; - error = (_GD_Add(D, &E, NULL) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &E, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } #ifndef GD_NO_C99_API @@ -1111,7 +1135,6 @@ const double cdividend[2], int fragment_index) gd_nothrow { gd_entry_t E; - int error; dtrace("%p, \"%s\", \"%s\", {%g, %g}, %i", D, field_code, in_field, cdividend[0], cdividend[1], fragment_index); @@ -1129,17 +1152,21 @@ E.flags = GD_EN_COMPSCAL; E.in_fields[0] = (char *)in_field; E.fragment_index = fragment_index; - error = (_GD_Add(D, &E, NULL) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &E, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a POLYNOM entry */ int gd_add_polynom(DIRFILE* D, const char* field_code, int poly_ord, const char* in_field, const double* a, int fragment_index) gd_nothrow { - int i, error; + int i; gd_entry_t E; dtrace("%p, \"%s\", %i, \"%s\", %p, %i", D, field_code, poly_ord, in_field, @@ -1167,16 +1194,19 @@ for (i = 0; i <= poly_ord; ++i) E.EN(polynom,a)[i] = a[i]; - error = (_GD_Add(D, &E, NULL) == NULL) ? -1 : 0; + if (_GD_Add(D, &E, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } - dreturn("%i", error); - return error; + dreturn("%i", 0); + return 0; } int gd_add_cpolynom(DIRFILE* D, const char* field_code, int poly_ord, const char* in_field, const GD_DCOMPLEXP(ca), int fragment_index) gd_nothrow { - int i, error; + int i; gd_entry_t E; dtrace("%p, \"%s\", %i, \"%s\", %p, %i", D, field_code, poly_ord, in_field, @@ -1205,10 +1235,13 @@ for (i = 0; i <= poly_ord; ++i) gd_ca2cs_(E.EN(polynom,ca)[i], ca, i); - error = (_GD_Add(D, &E, NULL) == NULL) ? -1 : 0; + if (_GD_Add(D, &E, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } - dreturn("%i", error); - return error; + dreturn("%i", 0); + return 0; } /* add a PHASE entry */ @@ -1216,7 +1249,6 @@ gd_shift_t shift, int fragment_index) gd_nothrow { gd_entry_t P; - int error; dtrace("%p, \"%s\", \"%s\", %lli, %i", D, field_code, in_field, (long long)shift, fragment_index); @@ -1233,10 +1265,14 @@ P.in_fields[0] = (char *)in_field; P.EN(phase,shift) = shift; P.fragment_index = fragment_index; - error = (_GD_Add(D, &P, NULL) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &P, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a WINDOW entry */ @@ -1245,7 +1281,6 @@ int fragment_index) gd_nothrow { gd_entry_t E; - int error; dtrace("%p, \"%s\", \"%s\", \"%s\", %i, {%g,%llx,%lli}, %i", D, field_code, in_field, check_field, windop, threshold.r, @@ -1265,10 +1300,14 @@ E.in_fields[0] = (char *)in_field; E.in_fields[1] = (char *)check_field; E.fragment_index = fragment_index; - error = (_GD_Add(D, &E, NULL) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &E, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a MPLEX entry */ @@ -1277,7 +1316,6 @@ gd_nothrow { gd_entry_t E; - int error; dtrace("%p, \"%s\", \"%s\", \"%s\", %i, %i, %i", D, field_code, in_field, count_field, count_val, period, fragment_index); @@ -1296,10 +1334,14 @@ E.in_fields[0] = (char *)in_field; E.in_fields[1] = (char *)count_field; E.fragment_index = fragment_index; - error = (_GD_Add(D, &E, NULL) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &E, NULL) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a STRING entry */ @@ -1490,7 +1532,7 @@ int n_fields, const char** in_fields, const double* m, const double* b) gd_nothrow { - int i, error; + int i; gd_entry_t L; dtrace("%p, \"%s\", \"%s\", %i, %p, %p, %p", D, field_code, parent, @@ -1521,10 +1563,14 @@ L.scalar[i] = NULL; L.scalar[i + GD_MAX_LINCOM] = NULL; } - error = (_GD_Add(D, &L, parent) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &L, parent) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a META LINCOM entry, with complex scalaras */ @@ -1532,7 +1578,7 @@ int n_fields, const char** in_fields, const GD_DCOMPLEXP(cm), const GD_DCOMPLEXP(cb)) gd_nothrow { - int i, error; + int i; gd_entry_t L; dtrace("%p, \"%s\", \"%s\", %i, %p, %p, %p", D, field_code, parent, @@ -1564,10 +1610,14 @@ L.scalar[i] = NULL; L.scalar[i + GD_MAX_LINCOM] = NULL; } - error = (_GD_Add(D, &L, parent) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &L, parent) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a META LINTERP entry */ @@ -1575,7 +1625,6 @@ const char* field_code, const char* in_field, const char* table) gd_nothrow { gd_entry_t L; - int error; dtrace("%p, \"%s\", \"%s\", \"%s\", \"%s\"", D, field_code, parent, in_field, table); @@ -1592,10 +1641,14 @@ L.in_fields[0] = (char *)in_field; L.EN(linterp,table) = (char *)table; L.fragment_index = 0; - error = (_GD_Add(D, &L, parent) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &L, parent) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a META BIT entry */ @@ -1603,7 +1656,6 @@ const char* in_field, int bitnum, int numbits) gd_nothrow { gd_entry_t B; - int error; dtrace("%p, \"%s\", \"%s\", \"%s\", %i, %in", D, field_code, parent, in_field, bitnum, numbits); @@ -1622,10 +1674,14 @@ B.EN(bit,numbits) = numbits; B.fragment_index = 0; B.scalar[0] = B.scalar[1] = NULL; - error = (_GD_Add(D, &B, parent) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &B, parent) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a META SBIT entry */ @@ -1633,7 +1689,6 @@ const char* in_field, int bitnum, int numbits) gd_nothrow { gd_entry_t B; - int error; dtrace("%p, \"%s\", \"%s\", \"%s\", %i, %in", D, field_code, parent, in_field, bitnum, numbits); @@ -1652,10 +1707,14 @@ B.EN(bit,numbits) = numbits; B.fragment_index = 0; B.scalar[0] = B.scalar[1] = NULL; - error = (_GD_Add(D, &B, parent) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &B, parent) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } static int _GD_MAddYoke(DIRFILE* D, gd_entype_t t, const char* parent, @@ -1663,7 +1722,6 @@ gd_nothrow { gd_entry_t M; - int error; dtrace("%p, 0x%X, \"%s\", \"%s\", \"%s\", \"%s\"", D, t, field_code, parent, in_field1, in_field2); @@ -1680,10 +1738,14 @@ M.in_fields[0] = (char *)in_field1; M.in_fields[1] = (char *)in_field2; M.fragment_index = 0; - error = (_GD_Add(D, &M, parent) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &M, parent) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } int gd_madd_multiply(DIRFILE* D, const char *parent, const char* field_code, @@ -1697,7 +1759,6 @@ int gd_madd_phase(DIRFILE* D, const char* parent, const char* field_code, const char* in_field, gd_shift_t shift) gd_nothrow { - int error; gd_entry_t P; dtrace("%p, \"%s\", \"%s\", \"%s\", %lli", D, field_code, parent, in_field, @@ -1716,17 +1777,21 @@ P.EN(phase,shift) = shift; P.fragment_index = 0; P.scalar[0] = NULL; - error = (_GD_Add(D, &P, parent) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &P, parent) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a META POLYNOM entry */ int gd_madd_polynom(DIRFILE* D, const char* parent, const char* field_code, int poly_ord, const char* in_field, const double* a) gd_nothrow { - int i, error; + int i; gd_entry_t E; dtrace("%p, \"%s\", \"%s\", %i, \"%s\", %p", D, field_code, parent, poly_ord, @@ -1756,17 +1821,20 @@ E.scalar[i] = NULL; } - error = (_GD_Add(D, &E, parent) == NULL) ? -1 : 0; + if (_GD_Add(D, &E, parent) == NULL) { + dreturn("%i", -1); + return -1; + } - dreturn("%i", error); - return error; + dreturn("%i", 0); + return 0; } /* add a META POLYNOM entry */ int gd_madd_cpolynom(DIRFILE* D, const char* parent, const char* field_code, int poly_ord, const char* in_field, const GD_DCOMPLEXP(ca)) gd_nothrow { - int i, error; + int i; gd_entry_t E; dtrace("%p, \"%s\", \"%s\", %i, \"%s\", %p", D, field_code, parent, poly_ord, @@ -1797,10 +1865,13 @@ E.scalar[i] = NULL; } - error = (_GD_Add(D, &E, parent) == NULL) ? -1 : 0; + if (_GD_Add(D, &E, parent) == NULL) { + dreturn("%i", -1); + return -1; + } - dreturn("%i", error); - return error; + dreturn("%i", 0); + return 0; } int gd_madd_divide(DIRFILE* D, const char *parent, const char* field_code, @@ -1828,7 +1899,6 @@ int gd_madd_recip(DIRFILE* D, const char *parent, const char* field_code, const char* in_field, double dividend) gd_nothrow { - int error; gd_entry_t E; dtrace("%p, \"%s\", \"%s\", \"%s\", %g", D, parent, field_code, in_field, @@ -1845,10 +1915,14 @@ E.field_type = GD_RECIP_ENTRY; E.EN(recip,dividend) = dividend; E.in_fields[0] = (char *)in_field; - error = (_GD_Add(D, &E, parent) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &E, parent) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } #ifndef GD_NO_C99_API @@ -1872,7 +1946,6 @@ const char* in_field, const double cdividend[2]) gd_nothrow { gd_entry_t E; - int error; dtrace("%p, \"%s\", \"%s\", \"%s\", {%g, %g}", D, parent, field_code, in_field, cdividend[0], cdividend[1]); @@ -1889,10 +1962,14 @@ gd_ra2cs_(E.EN(recip,cdividend), cdividend); E.flags = GD_EN_COMPSCAL; E.in_fields[0] = (char *)in_field; - error = (_GD_Add(D, &E, parent) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &E, parent) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a META WINDOW entry */ @@ -1900,7 +1977,6 @@ const char *in_field, const char *check_field, gd_windop_t windop, gd_triplet_t threshold) gd_nothrow { - int error; gd_entry_t E; dtrace("%p, \"%s\", \"%s\", \"%s\", \"%s\", %i, {%g,%llx,%lli}", D, parent, @@ -1920,10 +1996,14 @@ E.EN(window,windop) = windop; E.in_fields[0] = (char *)in_field; E.in_fields[1] = (char *)check_field; - error = (_GD_Add(D, &E, parent) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &E, parent) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a META MPLEX entry */ @@ -1931,7 +2011,6 @@ const char *in_field, const char *count_field, int count_val, int period) gd_nothrow { - int error; gd_entry_t E; dtrace("%p, \"%s\", \"%s\", \"%s\", \"%s\", %i, %i", D, parent, field_code, @@ -1950,10 +2029,14 @@ E.EN(mplex,period) = period; E.in_fields[0] = (char *)in_field; E.in_fields[1] = (char *)count_field; - error = (_GD_Add(D, &E, parent) == NULL) ? -1 : 0; - dreturn("%i", error); - return error; + if (_GD_Add(D, &E, parent) == NULL) { + dreturn("%i", -1); + return -1; + } + + dreturn("%i", 0); + return 0; } /* add a META STRING entry */ Modified: trunk/getdata/src/encoding.c =================================================================== --- trunk/getdata/src/encoding.c 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/src/encoding.c 2014-05-05 20:38:45 UTC (rev 895) @@ -195,7 +195,8 @@ ((encoding == GD_UNENCODED || encoding == GD_SLIM_ENCODED || \ encoding == GD_GZIP_ENCODED || encoding == GD_BZIP2_ENCODED || \ encoding == GD_TEXT_ENCODED || encoding == GD_LZMA_ENCODED || \ - encoding == GD_SIE_ENCODED)) + encoding == GD_SIE_ENCODED || encoding == GD_ZZIP_ENCODED || \ + encoding == GD_ZZSLIM_ENCODED)) #ifdef USE_MODULES static void *_GD_ResolveSymbol(lt_dlhandle lib, struct encoding_t *restrict enc, @@ -920,6 +921,47 @@ return reported_encoding; } +/* report whether a particular encoding is supported */ +int gd_encoding_support(unsigned long encoding) gd_nothrow +{ + int i; + + const unsigned int read_funcs = GD_EF_NAME | GD_EF_OPEN | GD_EF_CLOSE | + GD_EF_SEEK | GD_EF_READ | GD_EF_SIZE; + const unsigned int write_funcs = read_funcs | GD_EF_WRITE | GD_EF_SYNC | + GD_EF_MOVE | GD_EF_UNLINK; + + dtrace("0x%lX", encoding); + + /* make sure we have a valid encoding */ + if (!_GD_EncodingUnderstood(encoding)) { + dreturn("%i", -1); + return -1; + } + + /* Loop through valid subencodings checking for write support */ + for (i = 0; gd_ef_[i].scheme != GD_ENC_UNSUPPORTED; i++) + if (gd_ef_[i].scheme == encoding) { + if (!_GD_MissingFramework(i, write_funcs)) { + dreturn("%i", GD_RDWR); + return GD_RDWR; + } + } + + /* No write support; try read support */ + for (i = 0; gd_ef_[i].scheme != GD_ENC_UNSUPPORTED; i++) + if (gd_ef_[i].scheme == encoding) { + if (!_GD_MissingFramework(i, read_funcs)) { + dreturn("%i", GD_RDONLY); + return GD_RDONLY; + } + } + + /* nope */ + dreturn("%i", -1); + return -1; +} + /* This is basically the non-existant POSIX funcion mkstempat. There are two * approaches we could take here: * 1) fchdir to dirfd, use mkstemp to grab a file descriptor; fchdir back to Modified: trunk/getdata/src/getdata.h.in =================================================================== --- trunk/getdata/src/getdata.h.in 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/src/getdata.h.in 2014-05-05 20:38:45 UTC (rev 895) @@ -116,13 +116,6 @@ */ #define GD_MAX_LINE_LENGTH 4096 -/* maximum number of elements allowed in a CARRAY. Really the maximum should be - * whatever fits on a format file line, but that's hard to calculate. This is - * 2**(n-8)-1 on a n-bit system. - */ -#define GD_MAX_CARRAY_LENGTH (((size_t)-1) >> 8) - - /* error codes */ #define GD_E_OK 0 /* this MUST be zero */ #define GD_E_OPEN 1 @@ -717,6 +710,8 @@ extern unsigned long int gd_encoding(DIRFILE *dirfile, int fragment) gd_nothrow gd_nonnull ((1)); +extern int gd_encoding_support(unsigned long encoding) gd_nothrow; + extern unsigned long int gd_endianness(DIRFILE *dirfile, int fragment) gd_nothrow gd_nonnull((1)); Modified: trunk/getdata/src/mod.c =================================================================== --- trunk/getdata/src/mod.c 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/src/mod.c 2014-05-05 20:38:45 UTC (rev 895) @@ -926,9 +926,6 @@ _GD_SetError(D, GD_E_BAD_TYPE, Q.EN(scalar,const_type), NULL, 0, NULL); break; - } else if (Q.EN(scalar,array_len) > GD_MAX_CARRAY_LENGTH) { - _GD_SetError(D, GD_E_BOUNDS, 0, NULL, 0, NULL); - break; } type = _GD_ConstType(D, Q.EN(scalar,const_type)); @@ -965,11 +962,6 @@ if (Q.EN(scalar,array_len) != E->EN(scalar,array_len)) { modified = 1; - if (Q.EN(scalar,array_len) > GD_MAX_CARRAY_LENGTH) { - _GD_SetError(D, GD_E_BOUNDS, 0, NULL, 0, NULL); - break; - } - Qe.u.scalar.d = _GD_Realloc(D, E->e->u.scalar.d, sizeof(const char *) * Q.EN(scalar,array_len)); if (Qe.u.scalar.d == NULL) Modified: trunk/getdata/src/parse.c =================================================================== --- trunk/getdata/src/parse.c 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/src/parse.c 2014-05-05 20:38:45 UTC (rev 895) @@ -1263,6 +1263,9 @@ } for (c = first; c < n_cols; ++c) { + if (n == GD_SIZE_T_MAX) + break; + if (string) { ((const char**)data)[n++] = _GD_Strdup(D, in_cols[c]); @@ -1286,9 +1289,6 @@ return NULL; } } - - if (n == GD_MAX_CARRAY_LENGTH) - break; } if (n_cols < MAX_IN_COLS) Index: trunk/getdata/test =================================================================== --- trunk/getdata/test 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/test 2014-05-05 20:38:45 UTC (rev 895) Property changes on: trunk/getdata/test ___________________________________________________________________ Modified: svn:ignore ## -346,6 +346,7 ## encode_get encode_recode encode_recode_open +encode_support endian_alter endian_alter_all endian_alter_sie Modified: trunk/getdata/test/Makefile.am =================================================================== --- trunk/getdata/test/Makefile.am 2014-05-03 00:06:48 UTC (rev 894) +++ trunk/getdata/test/Makefile.am 2014-05-05 20:38:45 UTC (rev 895) @@ -142,7 +142,7 @@ ELIST_TESTS=elist_alias elist_hidden elist_noalias elist_scalar ENCODE_TESTS=encode_alter encode_alter_all encode_alter_open encode_get \ - encode_recode encode_recode_open + encode_recode encode_recode_open encode_support ENDIAN_TESTS=endian_alter endian_alter_all endian_alter_sie endian_get \ endian_move Added: trunk/getdata/test/encode_support.c =================================================================== --- trunk/getdata/test/encode_support.c (rev 0) +++ trunk/getdata/test/encode_support.c 2014-05-05 20:38:45 UTC (rev 895) @@ -0,0 +1,89 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +/* figure out expected support */ +#ifdef USE_SLIM +#define GD_SLIM_MODE GD_RDONLY +#else +#define GD_SLIM_MODE -1 +#endif + +#ifdef USE_GZIP +#define GD_GZIP_MODE GD_RDWR +#else +#define GD_GZIP_MODE -1 +#endif + +#ifdef USE_BZIP2 +#define GD_BZIP2_MODE GD_RDONLY +#else +#define GD_BZIP2_MODE -1 +#endif + +#ifdef USE_LZMA +#define GD_LZMA_MODE GD_RDONLY +#else +#define GD_LZMA_MODE -1 +#endif + +#ifdef USE_ZZIP +#define GD_ZZIP_MODE GD_RDONLY +#else +#define GD_ZZIP_MODE -1 +#endif + +#ifdef USE_ZZSLIM +#define GD_ZZSLIM_MODE GD_RDONLY +#else +#define GD_ZZSLIM_MODE -1 +#endif + +#define N 13 +int main(void) +{ + int i, r = 0; + struct { + unsigned long e; + int v; + } d[N] = { + { GD_AUTO_ENCODED, -1 }, /* 0 */ + { GD_UNENCODED, GD_RDWR }, /* 1 */ + { GD_TEXT_ENCODED, GD_RDWR }, /* 2 */ + { GD_SLIM_ENCODED, GD_SLIM_MODE }, /* 3 */ + { GD_GZIP_ENCODED, GD_GZIP_MODE }, /* 4 */ + { GD_BZIP2_ENCODED, GD_BZIP2_MODE }, /* 5 */ + { GD_LZMA_ENCODED, GD_LZMA_MODE }, /* 6 */ + { GD_SIE_ENCODED, GD_RDWR }, /* 7 */ + { GD_ZZIP_ENCODED, GD_ZZIP_MODE }, /* 8 */ + { GD_ZZSLIM_ENCODED, GD_ZZSLIM_MODE }, /* 9 */ + { GD_ENC_UNSUPPORTED, -1 }, /* 10 */ + { GD_ENCODING, -1 }, /* 11 */ + { 765, -1 } /* 12 */ + }; + + for (i = 0; i < N; ++i) { + int q = gd_encoding_support(d[i].e); + CHECKIi(i, q, d[i].v); + } + + return r; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2014-05-05 21:17:06
|
Revision: 896 http://sourceforge.net/p/getdata/code/896 Author: ketiltrout Date: 2014-05-05 21:16:59 +0000 (Mon, 05 May 2014) Log Message: ----------- Make gd_encoding_support() work with modules. Do some sorting of configure.ac. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/configure.ac trunk/getdata/src/encoding.c Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2014-05-05 20:38:45 UTC (rev 895) +++ trunk/getdata/ChangeLog 2014-05-05 21:16:59 UTC (rev 896) @@ -1,3 +1,6 @@ +2014-05-05 D. V. Wiebe <ge...@ke...> svn:896 + * src/encoding.c (gd_encoding_support): Call _GD_InitialiseFramework(). + 2014-05-05 D. V. Wiebe <ge...@ke...> svn:895 * src/getdata.h.in: Remove GD_MAX_CARRAY_LENGTH. * src/add.c (_GD_Add) src/mod.c (_GD_Change) src/parse.c (_GD_ParseArray): Modified: trunk/getdata/configure.ac =================================================================== --- trunk/getdata/configure.ac 2014-05-05 20:38:45 UTC (rev 895) +++ trunk/getdata/configure.ac 2014-05-05 21:16:59 UTC (rev 896) @@ -183,8 +183,8 @@ dnl Fortran 77 bindings AC_ARG_ENABLE(fortran, AS_HELP_STRING([--disable-fortran], - [don't build the Fortran 77 bindings (libfgetdata) nor the - Fortran 95 bindings (libf95getdata)]), + [don't build the Fortran 77 bindings (libfgetdata) nor ]dnl' + [the Fortran 95 bindings (libf95getdata)]), [ case "${enableval}" in no) make_f77bindings="no" ;; @@ -194,7 +194,7 @@ dnl Fortran 95 bindings AC_ARG_ENABLE(fortran95, AS_HELP_STRING([--disable-fortran95], - [don't build the Fortran 95 bindings (libf95getdata)]), + [don't build the Fortran 95 bindings (libf95getdata)]),dnl' [ case "${enableval}" in no) make_f95bindings="no" ;; @@ -212,29 +212,10 @@ AC_MSG_CHECKING([whether to include the Fortran 77 bindings]) AC_MSG_RESULT([$make_f77bindings]) -dnl DL library path munging for test suite -case "${host}" in - *-apple-darwin*) DL_LIBRARY_PATH="DYLD_LIBRARY_PATH" ;; - *) DL_LIBRARY_PATH="LD_LIBRARY_PATH" ;; -esac -AC_SUBST([DL_LIBRARY_PATH]) - -dnl Python bindings -AC_ARG_ENABLE(python, AS_HELP_STRING([--disable-python], - [don't build the Python bindings (pygetdata)]), - [ - case "${enableval}" in - no) make_pybindings="no" ;; - *) make_pybindings="yes" ;; - esac - ]) - -AC_MSG_CHECKING([whether to include the Python bindings]) -AC_MSG_RESULT([$make_pybindings]) - dnl IDL bindings AC_ARG_ENABLE(idl, AS_HELP_STRING([--disable-idl], - [don't build the Interactive Data Language (IDL) bindings (IDL_GetData)]), + [don't build the Interactive Data Language (IDL) bindings ]dnl' + [(IDL_GetData)]), [ case "${enableval}" in no) make_idlbindings="no" ;; @@ -245,6 +226,19 @@ AC_MSG_CHECKING([whether to include the IDL bindings]) AC_MSG_RESULT([$make_idlbindings]) +dnl MATLAB bindings +AC_ARG_ENABLE(matlab, AS_HELP_STRING([--disable-matlab], + [don't build the MATLAB bindings]),dnl' + [ + case "${enableval}" in + no) make_matlabbindings="no" ;; + *) make_matlabbindings="yes" ;; + esac + ]) + +AC_MSG_CHECKING([whether to include the MATLAB bindings]) +AC_MSG_RESULT([$make_matlabbindings]) + dnl Perl bindings AC_ARG_ENABLE(perl, AS_HELP_STRING([--disable-perl], [don't build the Perl bindings (GetData)]),dnl' @@ -258,19 +252,6 @@ AC_MSG_CHECKING([whether to include the Perl bindings]) AC_MSG_RESULT([$make_perlbindings]) -dnl MATLAB bindings -AC_ARG_ENABLE(matlab, AS_HELP_STRING([--disable-matlab], - [don't build the MATLAB bindings]),dnl' - [ - case "${enableval}" in - no) make_matlabbindings="no" ;; - *) make_matlabbindings="yes" ;; - esac - ]) - -AC_MSG_CHECKING([whether to include the MATLAB bindings]) -AC_MSG_RESULT([$make_matlabbindings]) - dnl PHP bindings AC_ARG_ENABLE(php, AS_HELP_STRING([--disable-php], [don't build the PHP bindings]),dnl' @@ -281,6 +262,19 @@ esac ]) +dnl Python bindings +AC_ARG_ENABLE(python, AS_HELP_STRING([--disable-python], + [don't build the Python bindings (pygetdata)]),dnl' + [ + case "${enableval}" in + no) make_pybindings="no" ;; + *) make_pybindings="yes" ;; + esac + ]) + +AC_MSG_CHECKING([whether to include the Python bindings]) +AC_MSG_RESULT([$make_pybindings]) + AC_MSG_CHECKING([whether to include the PHP bindings]) AC_MSG_RESULT([$make_phpbindings]) @@ -451,6 +445,13 @@ AC_MSG_RESULT([yes]) fi +dnl DL library path munging for test suite +case "${host}" in + *-apple-darwin*) DL_LIBRARY_PATH="DYLD_LIBRARY_PATH" ;; + *) DL_LIBRARY_PATH="LD_LIBRARY_PATH" ;; +esac +AC_SUBST([DL_LIBRARY_PATH]) + echo echo "*** Checking C compiler characteristics" echo @@ -865,48 +866,6 @@ #endif ]) -dnl python -if test "x$make_pybindings" = "xyes"; then - echo - echo "*** Configuring python bindings" - echo - GD_PYTHON([2.3]) - have_numpy="no" - if test "x$have_python" = "xno"; then - make_pybindings="no" - else - AC_MSG_CHECKING([for NumPy]) - cat > conftest.py << EOF -import sys -try: - import numpy -except ImportError: - sys.exit(1) -EOF - if $PYTHON conftest.py > /dev/null 2>&1; then - have_numpy="yes" - fi - AC_MSG_RESULT([$have_numpy]) - fi - if test "x$have_numpy" = "xyes"; then - AC_MSG_CHECKING([NumPy includes]) - NUMPY_CPPFLAGS=-I`$PYTHON -c "import numpy; print numpy.get_include()"` - AC_MSG_RESULT([$NUMPY_CPPFLAGS]) - - saved_cppflags=$CPPFLAGS - CPPFLAGS="${CPPFLAGS} ${PYTHON_CPPFLAGS} ${NUMPY_CPPFLAGS}" - AC_CHECK_HEADERS([numpy/arrayobject.h],,[have_numpy="no"],[ -#include<Python.h> -]) - CPPFLAGS=$saved_cppflags - fi - - if test "x$have_numpy" = "xyes"; then - AC_DEFINE([USE_NUMPY], [], - [ Define to enable NumPy support in the Python bindings ]) - fi -fi - dnl idl if test "x$make_idlbindings" = "xyes"; then echo @@ -927,6 +886,17 @@ fi fi +dnl matlab +if test "x$make_matlabbindings" = "xyes"; then + echo + echo "*** Configuring MATLAB bindings" + echo + GD_MATLAB + if test "x$have_matlab" = "xno"; then + make_matlabbindings=no + fi +fi + dnl perl if test "x$make_perlbindings" = "xyes"; then echo @@ -938,17 +908,6 @@ fi fi -dnl matlab -if test "x$make_matlabbindings" = "xyes"; then - echo - echo "*** Configuring MATLAB bindings" - echo - GD_MATLAB - if test "x$have_matlab" = "xno"; then - make_matlabbindings=no - fi -fi - dnl php if test "x$make_phpbindings" = "xyes"; then echo @@ -969,6 +928,48 @@ fi fi +dnl python +if test "x$make_pybindings" = "xyes"; then + echo + echo "*** Configuring python bindings" + echo + GD_PYTHON([2.3]) + have_numpy="no" + if test "x$have_python" = "xno"; then + make_pybindings="no" + else + AC_MSG_CHECKING([for NumPy]) + cat > conftest.py << EOF +import sys +try: + import numpy +except ImportError: + sys.exit(1) +EOF + if $PYTHON conftest.py > /dev/null 2>&1; then + have_numpy="yes" + fi + AC_MSG_RESULT([$have_numpy]) + fi + if test "x$have_numpy" = "xyes"; then + AC_MSG_CHECKING([NumPy includes]) + NUMPY_CPPFLAGS=-I`$PYTHON -c "import numpy; print numpy.get_include()"` + AC_MSG_RESULT([$NUMPY_CPPFLAGS]) + + saved_cppflags=$CPPFLAGS + CPPFLAGS="${CPPFLAGS} ${PYTHON_CPPFLAGS} ${NUMPY_CPPFLAGS}" + AC_CHECK_HEADERS([numpy/arrayobject.h],,[have_numpy="no"],[ +#include<Python.h> +]) + CPPFLAGS=$saved_cppflags + fi + + if test "x$have_numpy" = "xyes"; then + AC_DEFINE([USE_NUMPY], [], + [ Define to enable NumPy support in the Python bindings ]) + fi +fi + dnl external encodings GD_CHECK_ENCODING([bzip2],[bz2],[BZ2_bzReadOpen],[bzlib.h],[bzip2],[bunzip2],[]) GD_CHECK_ENCODING([gzip],[z],[gzopen],[zlib.h],[gzip],[gunzip],[]) @@ -980,8 +981,8 @@ dnl zzslim hackery -- there's no easy way to check whether slim supports zzip AC_ARG_ENABLE(zzslim, AS_HELP_STRING([--enable-zzslim], [skip probing for zzslim required features and enable the zzslim - encoding. The default is to autodetect support. Note: zzslim - encoding support requires both slim and zzip encoding support.]), + encoding. Note: zzslim encoding support requires both slim and + zzip encoding support. [default: autodetect]]), [ case "${enableval}" in no) zzslim_override="no" ;; Modified: trunk/getdata/src/encoding.c =================================================================== --- trunk/getdata/src/encoding.c 2014-05-05 20:38:45 UTC (rev 895) +++ trunk/getdata/src/encoding.c 2014-05-05 21:16:59 UTC (rev 896) @@ -933,6 +933,9 @@ dtrace("0x%lX", encoding); + /* spin up ltdl if needed */ + _GD_InitialiseFramework(); + /* make sure we have a valid encoding */ if (!_GD_EncodingUnderstood(encoding)) { dreturn("%i", -1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2014-05-06 02:33:55
|
Revision: 898 http://sourceforge.net/p/getdata/code/898 Author: ketiltrout Date: 2014-05-06 02:33:52 +0000 (Tue, 06 May 2014) Log Message: ----------- VPATH build fixes. Modified Paths: -------------- trunk/getdata/Makefile.am trunk/getdata/bindings/php/Makefile.am trunk/getdata/bindings/python/Makefile.am trunk/getdata/bindings/python/setup.py.in Modified: trunk/getdata/Makefile.am =================================================================== --- trunk/getdata/Makefile.am 2014-05-05 23:50:42 UTC (rev 897) +++ trunk/getdata/Makefile.am 2014-05-06 02:33:52 UTC (rev 898) @@ -36,6 +36,7 @@ DISTCHECK_CONFIGURE_FLAGS = --with-idl-dlm-dir="$$dc_install_base/idl" \ --with-perl-dir="$$dc_install_base/perl" \ + --with-php-dir="$$dc_install_base/php" \ --with-python-module-dir="$$dc_install_base/python" # matlab-only package Modified: trunk/getdata/bindings/php/Makefile.am =================================================================== --- trunk/getdata/bindings/php/Makefile.am 2014-05-05 23:50:42 UTC (rev 897) +++ trunk/getdata/bindings/php/Makefile.am 2014-05-06 02:33:52 UTC (rev 898) @@ -20,7 +20,7 @@ # php_LTLIBRARIES = getdata.la AM_CFLAGS = ${WALL} ${WEXTRA} -AM_CPPFLAGS = ${CPPFLAGS} ${PHP_CPPFLAGS} +AM_CPPFLAGS = -I$(top_srcdir)/src ${CPPFLAGS} ${PHP_CPPFLAGS} getdata_la_LDFLAGS = -module -avoid-version -shared ${PHP_LDFLAGS} getdata_la_LIBADD = ${PHP_LIBS} ../../src/libgetdata.la getdata_la_SOURCES = getdata.c php_getdata.h Modified: trunk/getdata/bindings/python/Makefile.am =================================================================== --- trunk/getdata/bindings/python/Makefile.am 2014-05-05 23:50:42 UTC (rev 897) +++ trunk/getdata/bindings/python/Makefile.am 2014-05-06 02:33:52 UTC (rev 898) @@ -26,6 +26,8 @@ BUILT_SOURCES = pyconstants.c +EXTRA_DIST = pydirfile.c pygetdata.c pyentry.c pygetdata.h pyfragment.c + distutils_path=build/lib.${PYTHON_PLATFORM}-${PYTHON_VERSION} pygetdata.so: ${distutils_path}/pygetdata.so cp $< $@ Modified: trunk/getdata/bindings/python/setup.py.in =================================================================== --- trunk/getdata/bindings/python/setup.py.in 2014-05-05 23:50:42 UTC (rev 897) +++ trunk/getdata/bindings/python/setup.py.in 2014-05-06 02:33:52 UTC (rev 898) @@ -23,7 +23,9 @@ from distutils.core import setup from distutils.extension import Extension from distutils.command.clean import clean as clean +from distutils.command.build import build as build from os.path import join +from os.path import exists from os import unlink from shutil import copy @@ -52,20 +54,25 @@ unlink(x) clean.run(self) +class gd_build(build): + def run(self): + # if we don't do this, the object files will end up in + # @top_builddir@/bindings/bindings/python, + # instead of + # @builddir@/build/temp.<whatever> + # like they're supposed to. It seems to work, but it's a little crazier + # than we're willing to deal with. + for x in sources: + if not exists(x): + copy(join(srcdir, x), x) + build.run(self) + # deal with out-of-place (VPATH) builds if srcdir != '.': includes.append(srcdir) # to find pygetdata.h - # if we don't do this, the object files will end up in - # @top_builddir@/bindings/bindings/python, - # instead of - # @builddir@/build/temp.<whatever> - # like they're supposed to. It seems to work, but it's a little crazier - # than we're willing to deal with. - for x in sources: - copy(join(srcdir, x), x) - - # handle clean up + # handle set up and clean up + cmdclass['build'] = gd_build cmdclass['clean'] = gd_clean # now add this built source; it always ends up where distutils wants it to be This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2014-05-06 22:47:51
|
Revision: 899 http://sourceforge.net/p/getdata/code/899 Author: ketiltrout Date: 2014-05-06 22:47:46 +0000 (Tue, 06 May 2014) Log Message: ----------- * Fix compiler warnings * Fix test/gzip_del Modified Paths: -------------- trunk/getdata/bindings/python/pygetdata.c trunk/getdata/src/getdata.c trunk/getdata/test/gzip_del.c Modified: trunk/getdata/bindings/python/pygetdata.c =================================================================== --- trunk/getdata/bindings/python/pygetdata.c 2014-05-06 02:33:52 UTC (rev 898) +++ trunk/getdata/bindings/python/pygetdata.c 2014-05-06 22:47:46 UTC (rev 899) @@ -362,14 +362,14 @@ dtrace("%p, %02x, %zi", data, type, ns); - if (type != GD_NULL) - pyobj = PyList_New(0); + if (type == GD_NULL) { + Py_INCREF(Py_None); + dreturn("%p", Py_None); + return Py_None; + } + pyobj = PyList_New(0); switch(type) { - case GD_NULL: - Py_INCREF(Py_None); - dreturn("%p", Py_None); - return Py_None; case GD_UINT8: for (i = 0; i < ns; ++i) if (PyList_Append(pyobj, PyInt_FromLong((long)((uint8_t*)data)[i]))) @@ -433,6 +433,7 @@ if (PyList_Append(pyobj, gdpy_from_complexp(((double*)data) + 2 * i))) return NULL; break; + case GD_NULL: case GD_UNKNOWN: /* prevent compiler warning */ break; } Modified: trunk/getdata/src/getdata.c =================================================================== --- trunk/getdata/src/getdata.c 2014-05-06 02:33:52 UTC (rev 898) +++ trunk/getdata/src/getdata.c 2014-05-06 22:47:46 UTC (rev 899) @@ -1814,16 +1814,19 @@ } /* simple */ -static void _GD_IndirData(DIRFILE *restrict D, char *restrict cbuf, - gd_type_t ctype, const int64_t *restrict ibuf, size_t n, const void *carray, - size_t len) +static void _GD_IndirData(char *restrict cbuf, gd_type_t ctype, + const int64_t *restrict ibuf, size_t n, const void *carray, size_t len) { size_t i; const int size = GD_SIZE(ctype); - int64_t ilen = (len > GD_INT64_MAX) ? GD_INT64_MAX : len; + int64_t ilen = +#if SIZEOF_SIZE_T == 8 + (len > GD_INT64_MAX) ? GD_INT64_MAX : +#endif + len; - dtrace("%p, %p, 0x%X, %p, %" PRNsize_t ", %p, %" PRNsize_t, D, cbuf, ctype, - ibuf, n, carray, len); + dtrace("%p, 0x%X, %p, %" PRNsize_t ", %p, %" PRNsize_t, cbuf, ctype, ibuf, n, + carray, len); for (i = 0; i < n; ++i) if (ibuf[i] < 0 || ibuf[i] >= ilen) @@ -1884,7 +1887,7 @@ return 0; } - _GD_IndirData(D, cbuf, GD_SIZE(ctype), ibuf, n_read, + _GD_IndirData(cbuf, GD_SIZE(ctype), ibuf, n_read, E->e->entry[1]->e->u.scalar.d, E->e->entry[1]->EN(scalar,array_len)); free(ibuf); @@ -2131,8 +2134,11 @@ return 0; } - len = (E->e->entry[1]->EN(scalar,array_len) > GD_INT64_MAX) ? GD_INT64_MAX - : E->e->entry[1]->EN(scalar,array_len); + len = +#if SIZEOF_SIZE_T == 8 + (E->e->entry[1]->EN(scalar,array_len) > GD_INT64_MAX) ? GD_INT64_MAX : +#endif + E->e->entry[1]->EN(scalar,array_len); for (i = 0; i < n_read; ++i) if (ibuf[i] < 0 || ibuf[i] >= len) Modified: trunk/getdata/test/gzip_del.c =================================================================== --- trunk/getdata/test/gzip_del.c 2014-05-06 02:33:52 UTC (rev 898) +++ trunk/getdata/test/gzip_del.c 2014-05-06 22:47:46 UTC (rev 899) @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 D. V. Wiebe +/* Copyright (C) 2013, 2014 D. V. Wiebe * *************************************************************************** * @@ -20,14 +20,6 @@ */ #include "test.h" -#include <inttypes.h> -#include <stdlib.h> -#include <sys/types.h> -#include <fcntl.h> -#include <string.h> -#include <errno.h> -#include <stdio.h> - /* this tests discarding OOP-writable (also temporary) RAW files */ int main(void) { @@ -54,16 +46,30 @@ write(fd, format_data, strlen(format_data)); close(fd); +#if defined USE_GZIP D = gd_open(filedir, GD_RDWR | GD_GZIP_ENCODED | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDWR | GD_GZIP_ENCODED); +#endif n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); e1 = gd_error(D); +#if defined USE_GZIP CHECKI(n, 8); CHECKI(e1, GD_E_OK); +#else + CHECKI(n, 0); + CHECKI(e1, GD_E_UNSUPPORTED); +#endif ret = gd_delete(D, "data", GD_DEL_DATA); e2 = gd_error(D); +#if defined USE_GZIP CHECKI(ret, 0); CHECKI(e2, GD_E_OK); +#else + CHECKI(ret, -1); + CHECKI(e2, GD_E_UNSUPPORTED); +#endif e3 = gd_close(D); CHECKI(e3, 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2014-05-07 18:03:44
|
Revision: 901 http://sourceforge.net/p/getdata/code/901 Author: ketiltrout Date: 2014-05-07 18:03:39 +0000 (Wed, 07 May 2014) Log Message: ----------- Bzip2 write support. Also fixed seeking past the EOF of a gzipped file. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/NEWS trunk/getdata/bindings/matlab/matlab.c trunk/getdata/bindings/perl/GetData.xs trunk/getdata/src/bzip.c trunk/getdata/src/compat.c trunk/getdata/src/encoding.c trunk/getdata/src/fpos.c trunk/getdata/src/gzip.c trunk/getdata/src/internal.h trunk/getdata/src/sie.c trunk/getdata/test/Makefile.am trunk/getdata/test/bzip_put.c trunk/getdata/test/test.h Added Paths: ----------- trunk/getdata/test/bzip_add.c trunk/getdata/test/bzip_get_far.c trunk/getdata/test/bzip_get_get2.c trunk/getdata/test/bzip_get_put.c trunk/getdata/test/bzip_move_to.c trunk/getdata/test/bzip_put_back.c trunk/getdata/test/bzip_put_endian.c trunk/getdata/test/bzip_put_get.c trunk/getdata/test/bzip_put_pad.c trunk/getdata/test/bzip_put_sub.c trunk/getdata/test/bzip_sync.c trunk/getdata/test/gzip_get_far.c trunk/getdata/test/gzip_put_pad.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/ChangeLog 2014-05-07 18:03:39 UTC (rev 901) @@ -1,3 +1,26 @@ +2014-05-06 D. V. Wiebe <ge...@ke...> svn:901 + * src/encoding.c: Add bzip2 OOP write support. + * src/bzip.c (_GD_Bzip2DoOpen _GD_Bzip2Open _GD_Bzip2Seek _GD_Bzip2Close + _GD_Bzip2Read): Handle writes. Properly clean up on error. Track file->pos. + * src/bzip.c (_GD_Bzip2Write _GD_Bzip2Sync): Added. + * test/bzip_add.c test/bzip_put_back.c test/bzip_move_to.c + test/bzip_get_far.c test/bzip_put_pad.c test/bzip_put_sub.c + test/bzip_get_get2.c test/bzip_put_get.c test/bzip_put_endian.c + test/bzip_sync.c test/bzip_get_put.c: Added. + * test/bzip_put.c: Replaced with a working test. + + * src/fpos.c (_GD_WriteSeek): Fix offset in the seek call. + * src/gzip.c (_GD_GzipSeek): Handle seeks past the EOF while reading. + * test/gzip_get_far.c test/gzip_put_pad.c: Added. + + * test/test.h: Remove unnecessary include statements. + + * src/encoding.c (_GD_MoveOver): Don't attempt to change mode if not needed. + + * bindings/matlab/matlab.c (gdmx_from_string_list): Use mxFree. + + * bindings/perl/GetData.xs (gdp_get_type): Fix undef check. + 2014-05-05 D. V. Wiebe <ge...@ke...> svn:896 * src/encoding.c (gd_encoding_support): Call _GD_InitialiseFramework(). Modified: trunk/getdata/NEWS =================================================================== --- trunk/getdata/NEWS 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/NEWS 2014-05-07 18:03:39 UTC (rev 901) @@ -15,7 +15,7 @@ * gd_rename() now by default updates the target of ALIASes pointing to a renamed field to point to the new field instead of leaving them dangle. - (But see GD_REN_DANGLE). + (But see GD_REN_DANGLE in the API section below). * CARRAYs are no longer truncated to GD_MAX_CARRAY_LENGTH elements. Flushing metadata to disk will now fail if writing a CARRAY would overflow a format @@ -24,6 +24,10 @@ indicates something pathological happening.) The GD_MAX_CARRAY_LENGTH symbol has been removed from the GetData header file. + * Write support for bzip2-encoded data has been added. This works identically + to how writing gzip-encoded data is written. See the gzip discussion in the + 0.8.0 section below for important notes. + * BUG FIX: The parsing of the \x and \u escape sequences are now correct. * BUG FIX: Computation of LINCOMs with complex valued input fields now @@ -116,6 +120,9 @@ * BUG FIX: Calling the Legacy API function GetFormat() on a Dirfile with MPLEX or WINDOW fields no longer results in a segmentation fault. + * BUG FIX: Attempts to read past the EOF of a gzipped field no longer results + in an I/O errorr, but successfully returns no data. + API Changes: * The comp_scal member of the gd_entry_t object has been replaced with a flags @@ -130,7 +137,7 @@ * Two new rename flags have been added: - GD_REN_DANGLE which indicates the library shouldn't update ALIASes whose - target has been renamed (turning them into dangling aliases) + target has been renamed (instead it will turn them into dangling aliases) - GD_REN_FORCE which causes the library to skip updating field codes which would be invalid due to affixes instead of failing. Modified: trunk/getdata/bindings/matlab/matlab.c =================================================================== --- trunk/getdata/bindings/matlab/matlab.c 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/bindings/matlab/matlab.c 2014-05-07 18:03:39 UTC (rev 901) @@ -799,7 +799,7 @@ for (i = 0; l[i]; ++i) { ptr = (mxArray **)mxRealloc(s, sizeof(mxArray*) * (i + 1)); if (ptr == NULL) { - free(s); + mxFree(s); mexErrMsgIdAndTxt("GetData:GDMX:Alloc", "Out of memory."); } s = ptr; Modified: trunk/getdata/bindings/perl/GetData.xs =================================================================== --- trunk/getdata/bindings/perl/GetData.xs 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/bindings/perl/GetData.xs 2014-05-07 18:03:39 UTC (rev 901) @@ -96,7 +96,7 @@ { dtrace("%p, \"%s\", \"%s\"", sv, pkg, func); - if (sv == NULL && *sv == undef) + if (sv == NULL || *sv == undef) croak("%s::%s() - Value may not be undef", pkg, func); if (sv_isa(*sv, "Math::Complex")) { @@ -867,6 +867,8 @@ SV *ret, **dummy; int n, sem = GD_SYNTAX_ABORT; int was_rv = 0; + AV *av; + int len; /* local stack pointer */ dSP; @@ -919,56 +921,53 @@ /* ferret out response */ switch (SvTYPE(ret)) { - AV *av; - int len; - case SVt_IV: - sem = SvIV(ret); - break; + sem = SvIV(ret); + break; case SVt_PVAV: - av = (AV *)ret; - len = av_len(av); - if (len < 0) { - croak("GetData: parser callback returned empty array."); - return GD_SYNTAX_ABORT; /* ca'n't get here */ - } else if (len > 1) { - croak("GetData: too many elements in array returned by parser " - "callback."); - return GD_SYNTAX_ABORT; /* ca'n't get here */ - } else if (len == 0) { - SV **val = av_fetch(av, 0, 0); - if (val == NULL || SvROK(*val)) { - croak("GetData: bad data type in array returned by parser callback."); + av = (AV *)ret; + len = av_len(av); + if (len < 0) { + croak("GetData: parser callback returned empty array."); return GD_SYNTAX_ABORT; /* ca'n't get here */ - } - - if (SvTYPE(*val) == SVt_IV) { - sem = SvIV(*val); - } else if (SvTYPE(*val) == SVt_PV) { - pdata->line = strdup(SvPV_nolen(*val)); - sem = GD_SYNTAX_RESCAN; - } else { - croak("GetData: bad data type in array returned by parser callback."); + } else if (len > 1) { + croak("GetData: too many elements in array returned by parser " + "callback."); return GD_SYNTAX_ABORT; /* ca'n't get here */ - } - } else { /* len == 1 */ - SV **val0 = av_fetch(av, 0, 0); - SV **val1 = av_fetch(av, 1, 0); + } else if (len == 0) { + SV **val = av_fetch(av, 0, 0); + if (val == NULL || SvROK(*val)) { + croak("GetData: bad data type in array returned by parser callback."); + return GD_SYNTAX_ABORT; /* ca'n't get here */ + } - if (val0 == NULL || SvROK(*val0) || val1 == NULL || SvROK(*val1)) { - croak("GetData: bad data type in array returned by parser callback."); - return GD_SYNTAX_ABORT; /* ca'n't get here */ - } + if (SvTYPE(*val) == SVt_IV) { + sem = SvIV(*val); + } else if (SvTYPE(*val) == SVt_PV) { + pdata->line = strdup(SvPV_nolen(*val)); + sem = GD_SYNTAX_RESCAN; + } else { + croak("GetData: bad data type in array returned by parser callback."); + return GD_SYNTAX_ABORT; /* ca'n't get here */ + } + } else { /* len == 1 */ + SV **val0 = av_fetch(av, 0, 0); + SV **val1 = av_fetch(av, 1, 0); - if (SvTYPE(*val0) == SVt_IV && SvTYPE(*val1) == SVt_PV) { - sem = SvIV(*val0); - pdata->line = strdup(SvPV_nolen(*val1)); - } else { - croak("GetData: bad data type in array returned by parser callback."); - return GD_SYNTAX_ABORT; /* ca'n't get here */ + if (val0 == NULL || SvROK(*val0) || val1 == NULL || SvROK(*val1)) { + croak("GetData: bad data type in array returned by parser callback."); + return GD_SYNTAX_ABORT; /* ca'n't get here */ + } + + if (SvTYPE(*val0) == SVt_IV && SvTYPE(*val1) == SVt_PV) { + sem = SvIV(*val0); + pdata->line = strdup(SvPV_nolen(*val1)); + } else { + croak("GetData: bad data type in array returned by parser callback."); + return GD_SYNTAX_ABORT; /* ca'n't get here */ + } } - } - break; + break; case SVt_PV: pdata->line = strdup(SvPV_nolen(ret)); sem = GD_SYNTAX_RESCAN; Modified: trunk/getdata/src/bzip.c =================================================================== --- trunk/getdata/src/bzip.c 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/src/bzip.c 2014-05-07 18:03:39 UTC (rev 901) @@ -28,6 +28,8 @@ #define _GD_Bzip2Open libgetdatabzip2_LTX_GD_Bzip2Open #define _GD_Bzip2Seek libgetdatabzip2_LTX_GD_Bzip2Seek #define _GD_Bzip2Read libgetdatabzip2_LTX_GD_Bzip2Read +#define _GD_Bzip2Write libgetdatabzip2_LTX_GD_Bzip2Write +#define _GD_Bzip2Sync libgetdatabzip2_LTX_GD_Bzip2Sync #define _GD_Bzip2Close libgetdatabzip2_LTX_GD_Bzip2Close #define _GD_Bzip2Size libgetdatabzip2_LTX_GD_Bzip2Size #endif @@ -42,6 +44,7 @@ BZFILE* bzfile; FILE* stream; int bzerror; + int write; int stream_end; int pos, end; off64_t base; @@ -51,36 +54,60 @@ /* The bzip encoding scheme uses edata as a gd_bzdata pointer. If a file is * open, idata = 0 otherwise idata = -1. */ -static struct gd_bzdata *_GD_Bzip2DoOpen(int dirfd, struct gd_raw_file_* file) +static struct gd_bzdata *_GD_Bzip2DoOpen(int dirfd, struct gd_raw_file_* file, + unsigned int mode) { int fd; struct gd_bzdata *ptr; + FILE *stream; + const char *fdmode = "rb"; - dtrace("%i, %p", dirfd, file); + dtrace("%i, %p, 0x%X", dirfd, file, mode); - if ((ptr = (struct gd_bzdata *)malloc(sizeof(struct gd_bzdata))) == NULL) { + if (mode & GD_FILE_READ) { + fd = gd_OpenAt(file->D, dirfd, file->name, O_RDONLY | O_BINARY, 0666); + } else if (mode & GD_FILE_TEMP) { + fd = _GD_MakeTempFile(file->D, dirfd, file->name); + fdmode = "wb"; + } else { /* internal error */ + errno = EINVAL; /* I guess ... ? */ dreturn("%p", NULL); return NULL; } - if ((fd = gd_OpenAt(file->D, dirfd, file->name, O_RDONLY, 0666)) == -1) { - free(ptr); + if (fd < 0) { dreturn("%p", NULL); return NULL; } - if ((ptr->stream = fdopen(fd, "rb")) == NULL) { + if ((stream = fdopen(fd, fdmode)) == NULL) { close(fd); - free(ptr); dreturn("%p", NULL); return NULL; } + if ((ptr = (struct gd_bzdata *)malloc(sizeof(struct gd_bzdata))) == NULL) { + dreturn("%p", NULL); + return NULL; + } + + ptr->stream = stream; ptr->bzerror = ptr->stream_end = 0; - ptr->bzfile = BZ2_bzReadOpen(&ptr->bzerror, ptr->stream, 0, 0, NULL, 0); + if (mode & GD_FILE_READ) { + ptr->bzfile = BZ2_bzReadOpen(&ptr->bzerror, stream, 0, 0, NULL, 0); + ptr->write = 0; + } else { + ptr->bzfile = BZ2_bzWriteOpen(&ptr->bzerror, stream, 9, 0, 30); + ptr->write = 1; + memset(ptr->data, 0, GD_BZIP_BUFFER_SIZE); + } - if (ptr->bzfile == NULL || ptr->bzerror != BZ_OK) { - fclose(ptr->stream); + if (ptr->bzerror != BZ_OK) { + if (mode & GD_FILE_READ) + BZ2_bzReadClose(&ptr->bzerror, ptr->bzfile); + else + BZ2_bzWriteClose(&ptr->bzerror, ptr->bzfile, 0, NULL, NULL); + fclose(stream); free(ptr); dreturn("%p", NULL); return NULL; @@ -88,81 +115,115 @@ ptr->pos = ptr->end = 0; ptr->base = 0; + file->pos = 0; dreturn("%p", ptr); return ptr; } int _GD_Bzip2Open(int dirfd, struct gd_raw_file_* file, int swap gd_unused_, - unsigned int mode gd_unused_) + unsigned int mode) { - dtrace("%i, %p, <unused>, <unused>", dirfd, file); + dtrace("%i, %p, <unused>, 0x%X", dirfd, file, mode); - file->edata = _GD_Bzip2DoOpen(dirfd, file); + file->edata = _GD_Bzip2DoOpen(dirfd, file, mode); if (file->edata == NULL) { dreturn("%i", 1); return 1; } - file->mode = GD_FILE_READ; + file->mode = mode; file->idata = 0; dreturn("%i", 0); return 0; } off64_t _GD_Bzip2Seek(struct gd_raw_file_* file, off64_t count, - gd_type_t data_type, unsigned int mode gd_unused_) + gd_type_t data_type, unsigned int mode) { - struct gd_bzdata *ptr = (struct gd_bzdata *)file->edata; + struct gd_bzdata *ptr; - dtrace("%p, %lli, 0x%X, <unused>", file, (long long)count, data_type); + dtrace("%p, %lli, 0x%X, 0x%X", file, (long long)count, data_type, mode); + ptr = (struct gd_bzdata *)(file[(mode == GD_FILE_WRITE) ? 1 : 0].edata); + + /* nothing to do */ + if (ptr->base + ptr->pos == count * GD_SIZE(data_type)) { + dreturn("%lli", (long long)count); + return count; + } + count *= GD_SIZE(data_type); - if (ptr->base > count) { - /* a backwards seek -- reopen the file */ - ptr->bzerror = 0; - BZ2_bzReadClose(&ptr->bzerror, ptr->bzfile); - ptr->bzfile = BZ2_bzReadOpen(&ptr->bzerror, ptr->stream, 0, 0, NULL, 0); + if (mode == GD_FILE_WRITE) { + /* we only get here when we need to pad */ + count -= file->pos * GD_SIZE(data_type); + while (ptr->base < count) { + int n; + if (count > GD_BZIP_BUFFER_SIZE) + n = GD_BZIP_BUFFER_SIZE; + else + n = count; - if (ptr->bzfile == NULL || ptr->bzerror != BZ_OK) { - fclose(ptr->stream); - dreturn("%i", -1); - return -1; + _GD_Bzip2Write(file + 1, ptr->data, GD_UINT8, n); + count -= n; } - ptr->pos = ptr->end = 0; - ptr->base = ptr->stream_end = 0; - } + } else { + if (ptr->base > count) { + /* a backwards seek: reopen the file */ + ptr->bzerror = 0; + BZ2_bzReadClose(&ptr->bzerror, ptr->bzfile); + if (ptr->bzerror != BZ_OK) { + fclose(ptr->stream); + dreturn("%i", -1); + return -1; + } - /* seek forward the slow way */ - while (ptr->base + ptr->end < count) { - int n; + rewind(ptr->stream); + ptr->bzfile = BZ2_bzReadOpen(&ptr->bzerror, ptr->stream, 0, 0, NULL, 0); - ptr->bzerror = 0; - n = BZ2_bzRead(&ptr->bzerror, ptr->bzfile, ptr->data, - GD_BZIP_BUFFER_SIZE); + if (ptr->bzerror != BZ_OK) { + BZ2_bzReadClose(&ptr->bzerror, ptr->bzfile); + fclose(ptr->stream); + dreturn("%i", -1); + return -1; + } + ptr->pos = ptr->end = 0; + ptr->base = ptr->stream_end = 0; + } - if (ptr->bzerror == BZ_OK || ptr->bzerror == BZ_STREAM_END) { - ptr->base += ptr->end; - ptr->end = n; - } else { - dreturn("%i", -1); - return -1; + /* seek forward the slow way */ + while (ptr->base + ptr->end < count) { + int n; + + /* eof */ + if (ptr->stream_end) + break; + + ptr->bzerror = 0; + n = BZ2_bzRead(&ptr->bzerror, ptr->bzfile, ptr->data, + GD_BZIP_BUFFER_SIZE); + + if (ptr->bzerror == BZ_OK || ptr->bzerror == BZ_STREAM_END) { + ptr->base += ptr->end; + ptr->end = n; + if (ptr->bzerror == BZ_STREAM_END) + ptr->stream_end = 1; + } else { + dreturn("%i", -1); + return -1; + } } - /* eof */ - if (ptr->bzerror != BZ_OK) { - ptr->stream_end = 1; - break; - } + ptr->pos = (ptr->stream_end && count >= ptr->base + ptr->end) ? ptr->end : + count - ptr->base; } + + file->pos = (ptr->base + ptr->pos) / GD_SIZE(data_type); - ptr->pos = (ptr->bzerror == BZ_STREAM_END && count >= ptr->base + ptr->end) ? - ptr->end : count - ptr->base; - - dreturn("%lli", (long long)((ptr->base + ptr->pos) / GD_SIZE(data_type))); - return (ptr->base + ptr->pos) / GD_SIZE(data_type); + dreturn("%lli", (long long)file->pos); + return file->pos;; } ssize_t _GD_Bzip2Read(struct gd_raw_file_ *restrict file, void *restrict data, @@ -217,18 +278,59 @@ nbytes = 0; } + file->pos = (ptr->base + ptr->pos) / GD_SIZE(data_type); + dreturn("%li", (long)(nmemb - nbytes / GD_SIZE(data_type))); return nmemb - nbytes / GD_SIZE(data_type); } +ssize_t _GD_Bzip2Write(struct gd_raw_file_ *file, const void *data, + gd_type_t data_type, size_t nmemb) +{ + struct gd_bzdata *ptr = (struct gd_bzdata *)file->edata; + ssize_t n; + + dtrace("%p, %p, 0x%X, %" PRNsize_t, file, data, data_type, nmemb); + + n = GD_SIZE(data_type) * nmemb; + if (n > INT_MAX) + n = INT_MAX; + + BZ2_bzWrite(&ptr->bzerror, ptr->bzfile, (void*)data, (int)n); + + if (ptr->bzerror) + n = -1; + else { + ptr->base += n; + n /= GD_SIZE(data_type); + file->pos += n; + } + + dreturn("%" PRNssize_t, n); + return n; +} + +/* This function does nothing */ +int _GD_Bzip2Sync(struct gd_raw_file_ *file gd_unused_) +{ + dtrace("<unused>"); + + dreturn("%i", 0); + return 0; +} + int _GD_Bzip2Close(struct gd_raw_file_ *file) { struct gd_bzdata *ptr = (struct gd_bzdata *)file->edata; dtrace("%p", file); ptr->bzerror = 0; - BZ2_bzReadClose(&ptr->bzerror, ptr->bzfile); - if (fclose(ptr->stream)) { + if (ptr->write) + BZ2_bzWriteClose(&ptr->bzerror, ptr->bzfile, 0, NULL, NULL); + else + BZ2_bzReadClose(&ptr->bzerror, ptr->bzfile); + + if (ptr->bzerror || fclose(ptr->stream)) { dreturn("%i", 1); return 1; } @@ -248,14 +350,14 @@ dtrace("%i, %p, 0x%X, <unused>", dirfd, file, data_type); - ptr = _GD_Bzip2DoOpen(dirfd, file); + ptr = _GD_Bzip2DoOpen(dirfd, file, GD_FILE_READ); if (ptr == NULL) { dreturn("%i", -1); return -1; } - /* seek forward the slow way to the end */ + /* seek forward the slow way to the end */ while (ptr->bzerror != BZ_STREAM_END) { int n; Modified: trunk/getdata/src/compat.c =================================================================== --- trunk/getdata/src/compat.c 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/src/compat.c 2014-05-07 18:03:39 UTC (rev 901) @@ -49,7 +49,7 @@ int ret; char *path; - dtrace("%p, %i, \"%s\", %x, 0%o", D, dirfd, name, flags, mode); + dtrace("%p, %i, \"%s\", 0x%X, 0%o", D, dirfd, name, flags, mode); path = _GD_MakeFullPathOnly(D, dirfd, name); ret = open(path, flags | O_BINARY, mode); @@ -100,7 +100,7 @@ int ret; char *path; - dtrace("%p, %i, \"%s\", %p, %x", D, dirfd, name, buf, flags); + dtrace("%p, %i, \"%s\", %p, 0x%X", D, dirfd, name, buf, flags); path = _GD_MakeFullPathOnly(D, dirfd, name); #ifdef HAVE_LSTAT Modified: trunk/getdata/src/encoding.c =================================================================== --- trunk/getdata/src/encoding.c 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/src/encoding.c 2014-05-07 18:03:39 UTC (rev 901) @@ -74,16 +74,18 @@ #ifdef USE_BZIP2 #define GD_EF_PROVIDES \ - GD_EF_OPEN | GD_EF_CLOSE | GD_EF_SEEK | GD_EF_READ | GD_EF_SIZE + GD_EF_OPEN | GD_EF_CLOSE | GD_EF_SEEK | GD_EF_READ | GD_EF_SIZE | \ + GD_EF_WRITE | GD_EF_SYNC #define GD_INT_FUNCS \ &_GD_GenericName, &_GD_Bzip2Open, &_GD_Bzip2Close, &_GD_Bzip2Seek, \ - &_GD_Bzip2Read, &_GD_Bzip2Size, NULL /* WRITE */, NULL /* SYNC */, \ + &_GD_Bzip2Read, &_GD_Bzip2Size, &_GD_Bzip2Write, &_GD_Bzip2Sync, \ &_GD_GenericMove, &_GD_GenericUnlink #else #define GD_INT_FUNCS GD_EF_NULL_SET #define GD_EF_PROVIDES 0 #endif - GD_EXT_ENCODING_GEN(GD_BZIP2_ENCODED, ".bz2", GD_EF_ECOR, "Bzip2", "bzip2"), + GD_EXT_ENCODING_GEN(GD_BZIP2_ENCODED, ".bz2", GD_EF_ECOR | GD_EF_OOP, "Bzip2", + "bzip2"), #undef GD_INT_FUNCS #undef GD_EF_PROVIDES @@ -323,13 +325,18 @@ #ifdef HAVE_FCHMOD int fd; struct stat stat_buf; - mode_t mode; + mode_t mode, tmode; #endif dtrace("%p, %i, %p", D, fragment, file); #ifdef HAVE_FCHMOD + if (gd_StatAt(D, dirfd, file[1].name, &stat_buf, 0)) + tmode = 0644; + else + tmode = stat_buf.st_mode; + if (gd_StatAt(D, dirfd, file[0].name, &stat_buf, 0)) - mode = 0644; + mode = tmode; else mode = stat_buf.st_mode; #endif @@ -349,9 +356,11 @@ } #ifdef HAVE_FCHMOD - fd = gd_OpenAt(file->D, dirfd, file[0].name, O_RDONLY, 0666); - fchmod(fd, mode); - close(fd); + if (tmode != mode) { + fd = gd_OpenAt(file->D, dirfd, file[0].name, O_RDONLY, 0666); + fchmod(fd, mode); + close(fd); + } #endif dreturn("%i", 0); Modified: trunk/getdata/src/fpos.c =================================================================== --- trunk/getdata/src/fpos.c 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/src/fpos.c 2014-05-07 18:03:39 UTC (rev 901) @@ -176,63 +176,65 @@ dtrace("%p, %p, %p, %lli, 0x%X", D, E, enc, (long long)offset, mode); /* in this case we need to close and then re-open the file */ - if ((offset < E->e->u.raw.file[which].pos) && oop_write) { - if (_GD_FiniRawIO(D, E, E->fragment_index, GD_FINIRAW_KEEP)) { - dreturn("%i", -1); - return -1; - } else if (_GD_InitRawIO(D, E, NULL, -1, NULL, GD_EF_SEEK, GD_FILE_WRITE, - _GD_FileSwapBytes(D, E))) - { - dreturn("%i", -1); - return -1; + if (oop_write) { + if (offset < E->e->u.raw.file[which].pos) { + if (_GD_FiniRawIO(D, E, E->fragment_index, GD_FINIRAW_KEEP)) { + dreturn("%i", -1); + return -1; + } else if (_GD_InitRawIO(D, E, NULL, -1, NULL, GD_EF_SEEK, GD_FILE_WRITE, + _GD_FileSwapBytes(D, E))) + { + dreturn("%i", -1); + return -1; + } } - } - if (oop_write && E->e->u.raw.file[0].idata >= 0) { - /* read from the old file until we reach the point we're interested in or - * run out of data */ - char buffer[GD_BUFFER_SIZE]; - ssize_t n_read, n_wrote; + if (E->e->u.raw.file[0].idata >= 0) { + /* read from the old file until we reach the point we're interested in or + * run out of data */ + char buffer[GD_BUFFER_SIZE]; + ssize_t n_read, n_wrote; - while (offset * GD_SIZE(E->EN(raw,data_type)) > GD_BUFFER_SIZE) { - n_read = (*enc->read)(E->e->u.raw.file, buffer, E->EN(raw,data_type), + while (offset * GD_SIZE(E->EN(raw,data_type)) > GD_BUFFER_SIZE) { + n_read = (*enc->read)(E->e->u.raw.file, buffer, E->EN(raw,data_type), GD_BUFFER_SIZE); - if (n_read > 0) { - n_wrote = (*enc->write)(E->e->u.raw.file + 1, buffer, - E->EN(raw,data_type), n_read); - if (n_wrote != n_read) { + if (n_read > 0) { + n_wrote = (*enc->write)(E->e->u.raw.file + 1, buffer, + E->EN(raw,data_type), n_read); + if (n_wrote != n_read) { + dreturn("%i", -1); + return -1; + } + offset -= n_wrote; + pos += n_wrote; + } else if (n_read < 0) { dreturn("%i", -1); return -1; } - offset -= n_wrote; - pos += n_wrote; - } else if (n_read < 0) { - dreturn("%i", -1); - return -1; } - } - if (offset > 0) { - n_read = (*enc->read)(E->e->u.raw.file, buffer, E->EN(raw,data_type), + if (offset > 0) { + n_read = (*enc->read)(E->e->u.raw.file, buffer, E->EN(raw,data_type), offset); - if (n_read > 0) { - n_wrote = (*enc->write)(E->e->u.raw.file + 1, buffer, - E->EN(raw,data_type), n_read); - if (n_wrote != n_read) { + if (n_read > 0) { + n_wrote = (*enc->write)(E->e->u.raw.file + 1, buffer, + E->EN(raw,data_type), n_read); + if (n_wrote != n_read) { + dreturn("%i", -1); + return -1; + } + offset -= n_wrote; + pos += n_wrote; + } else if (n_read < 0) { dreturn("%i", -1); return -1; } - offset -= n_wrote; - pos += n_wrote; - } else if (n_read < 0) { - dreturn("%i", -1); - return -1; } } } - pos += (*enc->seek)(E->e->u.raw.file + which, offset, E->EN(raw,data_type), - mode); + pos = (*enc->seek)(E->e->u.raw.file + which, pos + offset, + E->EN(raw,data_type), mode); dreturn("%lli", (long long)pos); return pos; @@ -331,7 +333,7 @@ } /* Set the I/O position of the given field - */ +*/ off64_t gd_seek64(DIRFILE *D, const char *field_code_in, off64_t frame_num, off64_t sample_num, int whence) { Modified: trunk/getdata/src/gzip.c =================================================================== --- trunk/getdata/src/gzip.c 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/src/gzip.c 2014-05-07 18:03:39 UTC (rev 901) @@ -93,8 +93,13 @@ (off_t)count, SEEK_SET); if (n == -1) { - dreturn("%i", -1); - return -1; + /* gzseek returns error on attempts to seek past the EOF in read mode */ + if (mode != GD_FILE_WRITE && gzeof((gzFile)file[0].edata)) + n = gztell((gzFile)file[0].edata); + else { + dreturn("%i", -1); + return -1; + } } n /= GD_SIZE(data_type); Modified: trunk/getdata/src/internal.h =================================================================== --- trunk/getdata/src/internal.h 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/src/internal.h 2014-05-07 18:03:39 UTC (rev 901) @@ -96,6 +96,9 @@ #ifdef HAVE_DIRECT_H #include <direct.h> #endif +#ifdef HAVE_IO_H +#include <io.h> +#endif /* MSVC types */ #ifdef _MSC_VER @@ -326,18 +329,6 @@ #endif #endif -/* For the C99 integer types */ -#ifdef HAVE_INTTYPES_H -# ifndef __STDC_FORMAT_MACROS -# define __STDC_FORMAT_MACROS -# endif -#include <inttypes.h> -#endif - -#ifdef HAVE_IO_H -# include <io.h> -#endif - #define GD_ARM_FLAG (GD_ARM_ENDIAN | GD_NOT_ARM_ENDIAN) /* Internal type conventions: @@ -1277,9 +1268,11 @@ gd_type_t data_type, unsigned int); ssize_t _GD_Bzip2Read(struct gd_raw_file_ *restrict, void *restrict, gd_type_t, size_t); -int _GD_Bzip2Close(struct gd_raw_file_* file); -off64_t _GD_Bzip2Size(int, struct gd_raw_file_* file, gd_type_t data_type, - int swap); +ssize_t _GD_Bzip2Write(struct gd_raw_file_ *restrict, const void *restrict, + gd_type_t, size_t); +int _GD_Bzip2Sync(struct gd_raw_file_*); +int _GD_Bzip2Close(struct gd_raw_file_*); +off64_t _GD_Bzip2Size(int, struct gd_raw_file_*, gd_type_t, int); /* gzip I/O methods */ int _GD_GzipOpen(int, struct gd_raw_file_* file, int swap, unsigned int); Modified: trunk/getdata/src/sie.c =================================================================== --- trunk/getdata/src/sie.c 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/src/sie.c 2014-05-07 18:03:39 UTC (rev 901) @@ -495,7 +495,7 @@ rin++; for (i = 0; i < (size_t)rin; ++i) { - dprintf_sie("%i: 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X", + dprintf_sie("%zu: 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X", i, ((char*)p)[size * i + 0], ((char*)p)[size * i + 1], ((char*)p)[size * i + 2], ((char*)p)[size * i + 3], ((char*)p)[size * i + 4], ((char*)p)[size * i + 5], Index: trunk/getdata/test =================================================================== --- trunk/getdata/test 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/test 2014-05-07 18:03:39 UTC (rev 901) Property changes on: trunk/getdata/test ___________________________________________________________________ Modified: svn:ignore ## -160,11 +160,22 ## bof_lincom bof_phase bof_phase_neg +bzip_add bzip_get +bzip_get_far bzip_get_get +bzip_get_get2 +bzip_get_put bzip_move_from +bzip_move_to bzip_nframes bzip_put +bzip_put_back +bzip_put_endian +bzip_put_get +bzip_put_pad +bzip_put_sub +bzip_sync close_bad close_close close_discard ## -575,6 +586,7 ## gzip_add gzip_del gzip_get +gzip_get_far gzip_get_get gzip_get_get2 gzip_get_put ## -585,6 +597,7 ## gzip_put_back gzip_put_endian gzip_put_get +gzip_put_pad gzip_put_sub gzip_sync header_complex Modified: trunk/getdata/test/Makefile.am =================================================================== --- trunk/getdata/test/Makefile.am 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/test/Makefile.am 2014-05-07 18:03:39 UTC (rev 901) @@ -68,7 +68,10 @@ BOF_TESTS=bof bof_bit bof_index bof_lincom bof_phase bof_phase_neg -BZIP_TESTS=bzip_get bzip_get_get bzip_move_from bzip_nframes +BZIP_TESTS=bzip_add bzip_get bzip_get_far bzip_get_get bzip_get_get2 \ + bzip_get_put bzip_move_from bzip_move_to bzip_nframes bzip_put \ + bzip_put_back bzip_put_endian bzip_put_get bzip_put_pad \ + bzip_put_sub bzip_sync CVLIST_TESTS=cvlist cvlist_array cvlist_array0 cvlist_array_free \ cvlist_array_hidden cvlist_array_meta cvlist_array_meta0 \ @@ -214,9 +217,10 @@ GLOBAL_TESTS=global_flags global_name global_ref global_ref_empty global_ref_set -GZIP_TESTS=gzip_add gzip_del gzip_get gzip_get_get gzip_get_get2 gzip_get_put \ - gzip_move_from gzip_move_to gzip_nframes gzip_put gzip_put_back \ - gzip_put_endian gzip_put_get gzip_put_sub gzip_sync +GZIP_TESTS=gzip_add gzip_del gzip_get gzip_get_far gzip_get_get gzip_get_get2 \ + gzip_get_put gzip_move_from gzip_move_to gzip_nframes gzip_put \ + gzip_put_back gzip_put_endian gzip_put_get gzip_put_pad \ + gzip_put_sub gzip_sync HEADER_TESTS=header_complex Added: trunk/getdata/test/bzip_add.c =================================================================== --- trunk/getdata/test/bzip_add.c (rev 0) +++ trunk/getdata/test/bzip_add.c 2014-05-07 18:03:39 UTC (rev 901) @@ -0,0 +1,77 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#ifndef TEST_BZIP2 + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data.bz2"; + gd_entry_t e; + int e1, e2, e3, unlink_data, r = 0; + DIRFILE *D; + + rmdirfile(); +#ifdef USE_BZIP2 + D = gd_open(filedir, GD_RDWR | GD_CREAT | GD_VERBOSE | GD_BZIP2_ENCODED); +#else + D = gd_open(filedir, GD_RDWR | GD_CREAT | GD_BZIP2_ENCODED); +#endif + gd_add_raw(D, "data", GD_UINT8, 2, 0); + e1 = gd_error(D); + + /* check */ + e2 = gd_entry(D, "data", &e); +#ifdef USE_BZIP2 + CHECKI(e2, 0); + if (e2 == 0) { + CHECKI(e.field_type, GD_RAW_ENTRY); + CHECKI(e.fragment_index, 0); + CHECKI(e.EN(raw,spf), 2); + CHECKI(e.EN(raw,data_type), GD_UINT8); + gd_free_entry_strings(&e); + } +#else + CHECKI(e2, -1); +#endif + + e3 = gd_close(D); + CHECKI(e3, 0); + + unlink_data = unlink(data); + +#ifdef USE_BZIP2 + CHECKI(unlink_data, 0); + CHECKI(e1, GD_E_OK); +#else + CHECKI(unlink_data, -1); + CHECKI(e1, GD_E_UNSUPPORTED); +#endif + + unlink(format); + rmdir(filedir); + + return r; +#endif +} Added: trunk/getdata/test/bzip_get_far.c =================================================================== --- trunk/getdata/test/bzip_get_far.c (rev 0) +++ trunk/getdata/test/bzip_get_far.c 2014-05-07 18:03:39 UTC (rev 901) @@ -0,0 +1,82 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#ifndef TEST_BZIP2 + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data"; + const char *bz2data = "dirfile/data.bz2"; + const char *format_data = "data RAW UINT16 8\n"; + uint16_t c[8]; + char command[4096]; + uint16_t data_data[256]; + int fd, n, error, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (fd = 0; fd < 256; ++fd) + data_data[fd] = (unsigned char)fd; + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, data_data, 256 * sizeof(uint16_t)); + close(fd); + + /* compress */ + snprintf(command, 4096, "%s -f %s > /dev/null", BZIP2, data); + if (gd_system(command)) + return 1; + +#ifdef USE_BZIP2 + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDONLY); +#endif + n = gd_getdata(D, "data", 1000, 0, 1, 0, GD_UINT16, c); + error = gd_error(D); + + gd_discard(D); + + unlink(bz2data); + unlink(format); + rmdir(filedir); + +#ifdef USE_BZIP2 + CHECKI(error, 0); +#else + CHECKI(error, GD_E_UNSUPPORTED); +#endif + CHECKI(n, 0); + + return r; +#endif +} Added: trunk/getdata/test/bzip_get_get2.c =================================================================== --- trunk/getdata/test/bzip_get_get2.c (rev 0) +++ trunk/getdata/test/bzip_get_get2.c 2014-05-07 18:03:39 UTC (rev 901) @@ -0,0 +1,82 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#if !defined USE_BZIP2 || !defined TEST_BZIP2 + return 77; /* skip test */ +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data"; + const char *bz2data = "dirfile/data.bz2"; + const char *format_data = "data RAW UINT16 8\n"; + uint16_t c1[8], c2[8]; + char command[4096]; + uint16_t data_data[256]; + int fd, i, n1, error1, n2, error2, r = 0; + DIRFILE *D; + + memset(c1, 0, 16); + memset(c2, 0, 16); + rmdirfile(); + mkdir(filedir, 0777); + + for (fd = 0; fd < 256; ++fd) + data_data[fd] = (unsigned char)fd; + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, data_data, 256 * sizeof(uint16_t)); + close(fd); + + /* compress */ + snprintf(command, 4096, "%s -f %s > /dev/null", BZIP2, data); + if (gd_system(command)) + return 1; + + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); + n1 = gd_getdata(D, "data", 0, 0, 1, 0, GD_UINT16, c1); + error1 = gd_error(D); + n2 = gd_getdata(D, "data", 0, 0, 1, 0, GD_UINT16, c2); + error2 = gd_error(D); + gd_discard(D); + + unlink(bz2data); + unlink(format); + rmdir(filedir); + + CHECKI(error1, 0); + CHECKI(error2, 0); + CHECKI(n1, 8); + CHECKI(n2, 8); + for (i = 0; i < 8; ++i) { + CHECKUi(i,c1[i], i); + CHECKUi(i,c2[i], i); + } + + return r; +#endif +} Added: trunk/getdata/test/bzip_get_put.c =================================================================== --- trunk/getdata/test/bzip_get_put.c (rev 0) +++ trunk/getdata/test/bzip_get_put.c 2014-05-07 18:03:39 UTC (rev 901) @@ -0,0 +1,170 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#ifndef TEST_BZIP2 + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data_bz2 = "dirfile/data.bz2"; + const char *data = "dirfile/data"; + const char *format_data = "data RAW UINT8 8\n"; + const unsigned char bz2data[425] = { + 0x42, 0x5a, 0x68, 0x39, 0x31, 0x41, 0x59, 0x26, + 0x53, 0x59, 0xb6, 0xb5, 0xee, 0x95, 0x00, 0x00, + 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xb0, 0x00, 0xc5, 0x52, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x30, 0x09, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x04, + 0xc0, 0x04, 0x98, 0x00, 0x26, 0x00, 0x02, 0x60, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x4c, 0x00, 0x13, 0x00, + 0x01, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x08, + 0x0c, 0x10, 0x14, 0x18, 0x1c, 0x20, 0x24, 0x28, + 0x2c, 0x30, 0x34, 0x38, 0x3c, 0x40, 0x44, 0x48, + 0x4c, 0x50, 0x54, 0x58, 0x5c, 0x60, 0x64, 0x68, + 0x6c, 0x70, 0x74, 0x78, 0x7c, 0x80, 0x84, 0x88, + 0x8c, 0x90, 0x94, 0x98, 0x9c, 0xa0, 0xa4, 0xa8, + 0xac, 0xb0, 0xb4, 0xb8, 0xbc, 0xc0, 0xc4, 0xc8, + 0xcc, 0xd0, 0xd4, 0xd8, 0xdc, 0xe0, 0xe4, 0xe8, + 0xec, 0xf0, 0xf4, 0xf8, 0xfd, 0x01, 0x05, 0x09, + 0x0d, 0x11, 0x15, 0x19, 0x1d, 0x21, 0x25, 0x29, + 0x2d, 0x31, 0x35, 0x39, 0x3d, 0x41, 0x45, 0x49, + 0x4d, 0x51, 0x55, 0x59, 0x5d, 0x61, 0x65, 0x69, + 0x6d, 0x71, 0x75, 0x79, 0x7d, 0x81, 0x85, 0x89, + 0x8d, 0x91, 0x85, 0x89, 0x8d, 0x91, 0x95, 0x99, + 0x9d, 0xa1, 0xa5, 0xa9, 0xad, 0xb1, 0xb5, 0xb9, + 0xbd, 0xc1, 0xc5, 0xc9, 0xcd, 0xd1, 0xd5, 0xd9, + 0xdd, 0xe1, 0xe5, 0xe9, 0xed, 0xf1, 0xf5, 0xf9, + 0xfe, 0x02, 0x06, 0x0a, 0x0e, 0x12, 0x16, 0x1a, + 0x1e, 0x22, 0x26, 0x2a, 0x2e, 0x32, 0x36, 0x3a, + 0x3e, 0x42, 0x46, 0x4a, 0x56, 0x5a, 0x5e, 0x62, + 0x66, 0x6a, 0x6e, 0x72, 0x76, 0x7a, 0x7e, 0x82, + 0x86, 0x8a, 0x8e, 0x92, 0x96, 0x9a, 0x9e, 0xa2, + 0xa6, 0xaa, 0xae, 0xb2, 0xb6, 0xba, 0xbe, 0xc2, + 0xc6, 0xca, 0xce, 0xd2, 0xd6, 0xda, 0xde, 0xe2, + 0xe6, 0xea, 0xee, 0xf2, 0xf6, 0xfa, 0xff, 0x03, + 0x07, 0x0b, 0x0f, 0x13, 0x17, 0x1b, 0x17, 0x1b, + 0x1f, 0x23, 0x27, 0x2b, 0x2f, 0x33, 0x37, 0x3b, + 0x3f, 0x43, 0x47, 0x4b, 0x4f, 0x53, 0x57, 0x5b, + 0x5f, 0x63, 0x67, 0x6b, 0x6f, 0x73, 0x77, 0x7b, + 0x7f, 0x83, 0x87, 0x8b, 0x8f, 0x93, 0x97, 0x9b, + 0x9f, 0xa3, 0xa7, 0xab, 0xaf, 0xb3, 0xb7, 0xbb, + 0xbf, 0xc3, 0xc7, 0xcb, 0xcf, 0xd3, 0xd7, 0xdb, + 0xdf, 0xe3, 0xe7, 0xeb, 0xef, 0xf3, 0xf4, 0x5d, + 0xc9, 0x14, 0xe1, 0x42, 0x42, 0xda, 0xd7, 0xba, + 0x54 + }; + uint8_t b, c[8], d[8]; + char command[4096]; + int fd, i, m, n, e1, e2, e3, unlink_data, unlink_databz2, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (i = 0; i < 8; ++i) + d[i] = (uint8_t)(80 + i); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(data_bz2, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, bz2data, 425); + close(fd); + +#ifdef USE_BZIP2 + D = gd_open(filedir, GD_RDWR | GD_BZIP2_ENCODED | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDWR | GD_BZIP2_ENCODED); +#endif + n = gd_getdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); + e1 = gd_error(D); + m = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, d); + e2 = gd_error(D); + + e3 = gd_close(D); + CHECKI(e3, 0); + +#ifdef USE_BZIP2 + /* uncompress */ + snprintf(command, 4096, "%s -f %s > /dev/null", BUNZIP2, data_bz2); + if (gd_system(command)) { + r = 1; + } else { + fd = open(data, O_RDONLY | O_BINARY); + if (fd >= 0) { + i = 0; + while (read(fd, &b, sizeof(uint8_t))) { + if (i < 40 || i >= 48) { + CHECKIi(i, b, i); + } else + CHECKIi(i, b, i + 40); + i++; + } + CHECKI(i, 256); + close(fd); + } + } + + for (i = 0; i < 8; ++i) + CHECKIi(i, c[i], 40 + i); +#endif + + unlink_data = unlink(data); + unlink_databz2 = unlink(data_bz2); + unlink(format); + rmdir(filedir); + +#ifdef USE_BZIP2 + CHECKI(unlink_data, 0); + CHECKI(unlink_databz2, -1); + CHECKI(e1, GD_E_OK); + CHECKI(e2, GD_E_OK); + CHECKI(n, 8); + CHECKI(m, 8); +#else + CHECKI(unlink_data, -1); + CHECKI(unlink_databz2, 0); + CHECKI(e1, GD_E_UNSUPPORTED); + CHECKI(e2, GD_E_UNSUPPORTED); + CHECKI(n, 0); + CHECKI(m, 0); +#endif + + return r; +#endif +} Added: trunk/getdata/test/bzip_move_to.c =================================================================== --- trunk/getdata/test/bzip_move_to.c (rev 0) +++ trunk/getdata/test/bzip_move_to.c 2014-05-07 18:03:39 UTC (rev 901) @@ -0,0 +1,111 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data_bz2 = "dirfile/data.bz2"; + const char *data_raw = "dirfile/data"; + const char *format_data = "data RAW UINT8 8\n/ENCODING none\n/ENDIAN little\n"; + uint8_t data_in[256]; + DIRFILE *D; +#ifdef USE_BZIP2 + uint8_t d; + char command[4096]; + int i; +#endif + int fd, e1, e2, unlink_raw, r = 0; + struct stat buf; + + rmdirfile(); + mkdir(filedir, 0777); + + for (fd = 0; fd < 256; ++fd) + data_in[fd] = (unsigned char)fd; + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(data_raw, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, data_in, 256); + close(fd); + +#ifdef USE_BZIP2 + D = gd_open(filedir, GD_RDWR | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDWR); +#endif + gd_alter_encoding(D, GD_BZIP2_ENCODED, 0, 1); + e1 = gd_error(D); + + e2 = gd_close(D); + CHECKI(e2, 0); + +#ifdef USE_BZIP2 + if (stat(data_bz2, &buf)) { + perror("stat"); + r = 1; + } + CHECKI(stat(data_raw, &buf), -1); +#else + if (stat(data_raw, &buf)) { + perror("stat"); + r = 1; + } + CHECKI(stat(data_bz2, &buf), -1); +#endif + +#ifdef USE_BZIP2 + /* uncompress */ + snprintf(command, 4096, "%s -f %s > /dev/null", BUNZIP2, data_bz2); + if (gd_system(command)) { + fprintf(stderr, "command failed: %s\n", command); + r = 1; + } else { + fd = open(data_raw, O_RDONLY | O_BINARY); + if (fd >= 0) { + i = 0; + while (read(fd, &d, sizeof(uint8_t))) { + CHECKIi(i, d, i); + i++; + } + CHECKI(i, 256); + close(fd); + } + } +#endif + + unlink_raw = unlink(data_raw); + unlink(format); + rmdir(filedir); + + CHECKI(unlink_raw, 0); +#ifdef USE_BZIP2 + CHECKI(e1, GD_E_OK); +#else + CHECKI(e1, GD_E_UNSUPPORTED); +#endif + + return r; +} Modified: trunk/getdata/test/bzip_put.c =================================================================== --- trunk/getdata/test/bzip_put.c 2014-05-06 23:43:33 UTC (rev 900) +++ trunk/getdata/test/bzip_put.c 2014-05-07 18:03:39 UTC (rev 901) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2011, 2013 D. V. Wiebe +/* Copyright (C) 2014 D. V. Wiebe * *************************************************************************** * @@ -18,29 +18,25 @@ * along with GetData; if not, write to the Free Software Foundation, Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -/* Attempt to write UINT8 */ #include "test.h" -#include <inttypes.h> -#include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <string.h> -#include <errno.h> -#include <stdio.h> - int main(void) { - return 77; /* writing not supported */ -#if 0 +#ifndef TEST_BZIP2 + return 77; +#else const char *filedir = "dirfile"; const char *format = "dirfile/format"; - const char *data = "dirfile/data.txt"; + const char *data_bz2 = "dirfile/data.bz2"; + const char *data = "dirfile/data"; const char *format_data = "data RAW UINT8 8\n"; - uint8_t c[8], d; - int fd, n, error, i; + uint8_t c[8]; +#ifdef USE_BZIP2 + char command[4096]; + uint8_t d; +#endif struct stat buf; + int fd, i, n, e1, e2, stat_data, unlink_data, unlink_bz2, r = 0; DIRFILE *D; memset(c, 0, 8); @@ -54,36 +50,66 @@ write(fd, format_data, strlen(format_data)); close(fd); - D = gd_open(filedir, GD_RDWR | GD_TEXT_ENCODED | GD_VERBOSE); +#ifdef USE_BZIP2 + D = gd_open(filedir, GD_RDWR | GD_BZIP2_ENCODED | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDWR | GD_BZIP2_ENCODED); +#endif n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); - error = gd_error(D); + e1 = gd_error(D); - gd_discard(D); + e2 = gd_close(D); + CHECKI(e2, 0); - if (stat(data, &buf)) - return 1; + stat_data = stat(data_bz2, &buf); +#ifdef USE_BZIP2 + if (stat_data) { + perror("stat"); + } + CHECKI(stat_data, 0); +#else + CHECKI(stat_data, -1); +#endif - fd = open(data, O_RDONLY | O_BINARY); - i = 0; - while (read(fd, &d, sizeof(uint8_t))) { - if (i < 40 || i > 48) { - if (d != 0) - return 1; - } else if (d != i) - return 1; - i++; +#ifdef USE_BZIP2 + /* uncompress */ + snprintf(command, 4096, "%s -f %s > /dev/null", BUNZIP2, data_bz2); + if (gd_system(command)) { + r = 1; + } else { + fd = open(data, O_RDONLY | O_BINARY); + if (fd >= 0) { + i = 0; + while (read(fd, &d, sizeof(uint8_t))) { + if (i < 40 || i > 48) { + CHECKIi(i, d, 0); + } else + CHECKIi(i, d, i); + i++; + } + CHECKI(i, 48); + close(fd); + } } - fclose(stream); +#endif - unlink(data); + unlink_bz2 = unlink(data_bz2); + CHECKI(unlink_bz2, -1); + + unlink_data = unlink(data); unlink(format); rmdir(filedir); - if (error) - return 1; - if (n != 8) - return 1; +#ifdef USE_BZIP2 + CHECKI(unlink_data, 0); + CHECKI(e1, GD_E_OK); + CHECKI(n, 8); +#else + CHECKI(unlink_data, -1); + CHECKI(e1, GD_E_UNSUPPORTED); + CHECKI(n, 0); +#endif - return 0; + return r; #endif } Added: trunk/getdata/test/bzip_put_back.c =================================================================== --- trunk/getdata/test/bzip_put_back.c (rev 0) +++ trunk/getdata/test/bzip_put_back.c 2014-05-07 18:03:39 UTC (rev 901) @@ -0,0 +1,101 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#if ! (defined TEST_BZIP2) || ! (defined USE_BZIP2) + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data_bz2 = "dirfile/data.bz2"; + const char *data = "dirfile/data"; + const char *format_data = "data RAW UINT8 8\n"; + uint8_t c[8]; + char command[4096]; + uint8_t d; + struct stat buf; + int fd, i, n1, n2, e1, e2, e3, stat_data, unlink_data, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (i = 0; i < 8; ++i) + c[i] = (uint8_t)(40 + i); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + D = gd_open(filedir, GD_RDWR | GD_BZIP2_ENCODED | GD_VERBOSE); + n1 = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); + e1 = gd_error(D); + CHECKI(e1, GD_E_OK); + CHECKI(n1, 8); + + n2 = gd_putdata(D, "data", 0, 0, 1, 0, GD_UINT8, c); + e2 = gd_error(D); + CHECKI(e2, GD_E_OK); + CHECKI(n2, 8); + + e3 = gd_close(D); + CHECKI(e3, 0); + + stat_data = stat(data_bz2, &buf); + if (stat_data) { + perror("stat"); + } + CHECKI(stat_data, 0); + + /* uncompress */ + snprintf(command, 4096, "%s -f %s > /dev/null", BUNZIP2, data_bz2); + if (gd_system(command)) { + r = 1; + } else { + fd = open(data, O_RDONLY | O_BINARY); + if (fd >= 0) { + i = 0; + while (read(fd, &d, sizeof(uint8_t))) { + if (i < 8) { + CHECKIi(i, d, i + 40); + } else if (i < 40 || i > 48) { + CHECKIi(i, d, 0); + } else + CHECKIi(i, d, i); + i++; + } + CHECKI(i, 48); + close(fd); + } + } + + unlink_data = unlink(data); + unlink(format); + rmdir(filedir); + + CHECKI(unlink_data, 0); + + return r; +#endif +} Added: trunk/getdata/test/bzip_put_endian.c =================================================================== --- trunk/getdata/test/bzip_put_endian.c (rev 0) +++ trunk/getdata/test/bzip_put_endian.c 2014-05-07 18:03:39 UTC (rev 901) @@ -0,0 +1,117 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#ifndef TEST_BZIP2 + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data_bz2 = "dirfile/data.bz2"; + const char *data = "dirfile/data"; + const char *format_data = "data RAW UINT16 8\n" +#ifdef WORDS_BIGENDIAN + "ENDIAN little\n"; +#else + "ENDIAN big\n"; +#endif + uint16_t c[8]; +#ifdef USE_BZIP2 + char command[4096]; + uint16_t d; +#endif + struct stat buf; + int fd, i, n, e1, e2, stat_data, unlink_data, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (i = 0; i < 8; ++i) + c[i] = (uint16_t)(0x102 * i); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + +#ifdef USE_BZIP2 + D = gd_open(filedir, GD_RDWR | GD_BZIP2_ENCODED | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDWR | GD_BZIP2_ENCODED); +#endif + n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT16, c); + e1 = gd_error(D); + + e2 = gd_close(D); + CHECKI(e2, 0); + + stat_data = stat(data_bz2, &buf); +#ifdef USE_BZIP2 + if (stat_data) { + perror("stat"); + } + CHECKI(stat_data, 0); +#else + CHECKI(stat_data, -1); +#endif + +#ifdef USE_BZIP2 + /* uncompress */ + snprintf(command, 4096, "%s -f %s > /dev/null", BUNZIP2, data_bz2); + if (gd_system(command)) { + r = 1; + } else { + fd = open(data, O_RDONLY | O_BINARY); + if (fd >= 0) { + i = 0; + while (read(fd, &d, sizeof(uint16_t))) { + if (i < 40 || i > 48) { + CHECKIi(i, d, 0); + } else + CHECKIi(i, d, 0x201 * (i - 40)); + i++; + } + CHECKI(i, 48); + close(fd); + } + } +#endif + + unlink_data = unlink(data); + unlink(format); + rmdir(filedir); + +#ifdef USE_BZIP2 + CHECKI(unlink_data, 0); + CHECKI(e1, GD_E_OK); + CHECKI(n, 8); +#else + CHECKI(unlink_data, -1); + CHECKI(e1, GD_E_UNSUPPORTED); + CHECKI(n, 0); +#endif + + return r; +#endif +} Added: trunk/getdata/test/bzip_put_get.c =================================================================== --- trunk/getdata/test/bzip_put_get.c (rev 0) +++ trunk/getdata/test/bzip_put_get.c 2014-05-07 18:03:39 UTC (rev 901) @@ -0,0 +1,83 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#ifndef TEST_BZIP2 + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data.bz2"; + const char *format_data = "data RAW UINT8 8\n"; + uint8_t c[8], d[8]; + int fd, i, m, n, e1, e2, e3, unlink_data, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (i = 0; i < 8; ++i) + c[i] = (uint8_t)(40 + i); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + +#ifdef USE_BZIP2 + D = gd_open(filedir, GD_RDWR | GD_BZIP2_ENCODED | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDWR | GD_BZIP2_ENCODED); +#endif + n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); + e1 = gd_error(D); + m = gd_getdata(D, "data", 5, 0, 1, 0, GD_UINT8, d); + e2 = gd_error(D); + + for (i = 0; i < m; ++i) + CHECKIi(i, d[i], c[i]); + + e3 = gd_close(D); + CHECKI(e3, 0); + + unlink_data = unlink(data); + unlink(format); + rmdir(filedir); + +#ifdef USE_BZIP2 + CHECKI(unlink_data, 0); + CHECKI(e1, GD_E_OK); + CHECKI(e2, GD_E_OK); + CHECKI(n, 8); + CHECKI(m, 8); +#else + CHECKI(unlink_data, -1); + CHECKI(e1, GD_E_UNSUPPORTED); + CHECKI(e2, GD_E_UNSUPPORTED); + CHECKI(n, 0); + CHECKI(m, 0); +#endif + + return r; +#endif +} Added: trunk/getdata/test/bzip_put_pad.c =================================================================== --- trunk/getdata/test/bzip_put_pad.c (rev 0) +++ trunk/getdata/test/bzip_put_pad.c 2014-05-07 18:03:39 UTC (rev 901) @@ -0,0 +1,103 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#if ! (defined TEST_BZIP2) || ! (defined USE_BZIP2) + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data_bz2 = "dirfile/data.bz2"; + const char *data = "dirfile/data"; + const char *format_data = "data RAW UINT8 8\n"; + uint8_t c[8]; + char command[4096]; + uint8_t d; + struct stat buf; + int fd, i, n1, n2, e1, e2, e3, stat_data, unlink_data, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (i = 0; i < 8; ++i) + c[i] = (uint8_t)(40 +... [truncated message content] |
From: <ket...@us...> - 2014-05-10 01:22:00
|
Revision: 903 http://sourceforge.net/p/getdata/code/903 Author: ketiltrout Date: 2014-05-10 01:21:54 +0000 (Sat, 10 May 2014) Log Message: ----------- Use slimdopen and slimdrawsize when available. Modified Paths: -------------- trunk/getdata/configure.ac trunk/getdata/src/slim.c Modified: trunk/getdata/configure.ac =================================================================== --- trunk/getdata/configure.ac 2014-05-07 19:49:19 UTC (rev 902) +++ trunk/getdata/configure.ac 2014-05-10 01:21:54 UTC (rev 903) @@ -981,7 +981,7 @@ GD_CHECK_ENCODING([gzip],[z],[gzopen],[zlib.h],[gzip],[gunzip],[]) GD_CHECK_ENCODING([lzma],[lzma],[lzma_auto_decoder],[lzma.h],[xz],[],[]) GD_CHECK_ENCODING([slim],[slim],[slimopen],[slimlib.h], [slim slimdata], - [unslim],[slimdopen]) + [unslim],[slimdopen slimdrawsize]) GD_CHECK_ENCODING([zzip],[zzip],[zzip_open],[zzip/lib.h],[zip],[unzip],[]) dnl zzslim hackery -- there's no easy way to check whether slim supports zzip Modified: trunk/getdata/src/slim.c =================================================================== --- trunk/getdata/src/slim.c 2014-05-07 19:49:19 UTC (rev 902) +++ trunk/getdata/src/slim.c 2014-05-10 01:21:54 UTC (rev 903) @@ -38,24 +38,43 @@ int _GD_SlimOpen(int dirfd, struct gd_raw_file_* file, int swap gd_unused_, unsigned int mode gd_unused_) { - char *filepath; - dtrace("%i, %p, <unused>, <unused>", dirfd, file); - /* this is easily broken, but the best we can do for now... */ - filepath = gd_MakeFullPathOnly(file->D, dirfd, file->name); - if (filepath == NULL) { - dreturn("%i", 1); - return 1; +#ifdef HAVE_SLIMDOPEN + { + int fd = gd_OpenAt(file->D, dirfd, file->name, O_RDONLY | O_BINARY, 0666); + if (fd < 0) { + dreturn("%i", -1); + return -1; + } + + file->edata = slimdopen(fd, "r"); + + if (file->edata == NULL) { + close(fd); + dreturn("%i", 1); + return 1; + } } +#else + { + char *filepath; + /* this is easily broken, but the best we can do in this case */ + filepath = gd_MakeFullPathOnly(file->D, dirfd, file->name); + if (filepath == NULL) { + dreturn("%i", 1); + return 1; + } - file->edata = slimopen(filepath, "r"); - free(filepath); + file->edata = slimopen(filepath, "r"); + free(filepath); - if (file->edata == NULL) { - dreturn("%i", 1); - return 1; + if (file->edata == NULL) { + dreturn("%i", 1); + return 1; + } } +#endif file->mode = GD_RDONLY; file->idata = 0; @@ -115,20 +134,34 @@ off64_t _GD_SlimSize(int dirfd, struct gd_raw_file_ *file, gd_type_t data_type, int swap gd_unused_) { - char *filepath; off64_t size; dtrace("%i, %p, 0x%X", dirfd, file, data_type); - /* this is easily broken, but the best we can do for now... */ - filepath = gd_MakeFullPathOnly(file->D, dirfd, file->name); - if (filepath == NULL) { - dreturn("%i", 1); - return 1; +#ifdef HAVE_SLIMDRAWSIZE + { + int fd = gd_OpenAt(file->D, dirfd, file->name, O_RDONLY | O_BINARY, 0666); + if (fd < 0) { + dreturn("%i", -1); + return -1; + } + + size = slimdrawsize(fd); + close(fd); } +#else + { + /* this is easily broken, but the best we can do in this case */ + char *filepath = gd_MakeFullPathOnly(file->D, dirfd, file->name); + if (filepath == NULL) { + dreturn("%i", -1); + return -1; + } - size = slimrawsize(filepath); - free(filepath); + size = slimrawsize(filepath); + free(filepath); + } +#endif if (size < 0) { dreturn("%i", -1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2014-05-19 19:46:25
|
Revision: 904 http://sourceforge.net/p/getdata/code/904 Author: ketiltrout Date: 2014-05-19 19:46:21 +0000 (Mon, 19 May 2014) Log Message: ----------- LZMA write support and bug fixing. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/NEWS trunk/getdata/src/bzip.c trunk/getdata/src/encoding.c trunk/getdata/src/internal.h trunk/getdata/src/lzma.c trunk/getdata/src/raw.c trunk/getdata/test/Makefile.am trunk/getdata/test/encode_support.c Added Paths: ----------- trunk/getdata/test/lzma_put.c trunk/getdata/test/lzma_xz_add.c trunk/getdata/test/lzma_xz_get.c trunk/getdata/test/lzma_xz_get_far.c trunk/getdata/test/lzma_xz_get_get.c trunk/getdata/test/lzma_xz_get_get2.c trunk/getdata/test/lzma_xz_get_put.c trunk/getdata/test/lzma_xz_move_to.c trunk/getdata/test/lzma_xz_nframes.c trunk/getdata/test/lzma_xz_put.c trunk/getdata/test/lzma_xz_put_back.c trunk/getdata/test/lzma_xz_put_endian.c trunk/getdata/test/lzma_xz_put_get.c trunk/getdata/test/lzma_xz_put_pad.c trunk/getdata/test/lzma_xz_sync.c Removed Paths: ------------- trunk/getdata/test/xz_get.c trunk/getdata/test/xz_nframes.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2014-05-10 01:21:54 UTC (rev 903) +++ trunk/getdata/ChangeLog 2014-05-19 19:46:21 UTC (rev 904) @@ -1,3 +1,18 @@ +2014-05-19 D. V. Wiebe <ge...@ke...> svn:904 + * src/lzma.c: Rewritten with better understanding of liblzma. Includes + write support. + * src/encoding.c: LZMA write support. + * test/lzma_xz_get_get.c test/lzma_xz_get_get2.c test/lzma_xz_put.c + test/lzma_xz_get_put.c test/lzma_xz_add.c test/lzma_xz_sync.c + test/lzma_xz_move_to.c test/lzma_put.c test/lzma_xz_get_far.c + test/lzma_xz_put_pad.c test/lzma_xz_put_endian.c test/lzma_xz_put_back.c + test/lzma_xz_put_get.c: Added. + * test/lzma_xz_get.c test/lzma_xz_nframes.c: Renamed from + xz_{get|nframes}.c. + * test/encode_support.c: Update for LZMA writes. + + * src/bzip.c: Remove unnecessary .write member. + 2014-05-06 D. V. Wiebe <ge...@ke...> svn:901 * src/encoding.c: Add bzip2 OOP write support. * src/bzip.c (_GD_Bzip2DoOpen _GD_Bzip2Open _GD_Bzip2Seek _GD_Bzip2Close Modified: trunk/getdata/NEWS =================================================================== --- trunk/getdata/NEWS 2014-05-10 01:21:54 UTC (rev 903) +++ trunk/getdata/NEWS 2014-05-19 19:46:21 UTC (rev 904) @@ -24,10 +24,16 @@ indicates something pathological happening.) The GD_MAX_CARRAY_LENGTH symbol has been removed from the GetData header file. - * Write support for bzip2-encoded data has been added. This works identically - to how writing gzip-encoded data is written. See the gzip discussion in the - 0.8.0 section below for important notes. + * Write support for bzip2-encoded and lzma-encoded data has been added. LZMA + write support is only available for .xz files, not the obsolete .lzma + format. The write support occurs out-of-place, just like how writing + gzip-encoded data works. See the gzip discussion in the 0.8.0 section below + for important notes. + * BUG FIX: In addition to the addition of write support mentioned above, a + number of problems with reading LZMA files has been fixed, which should + result in fewer segmentaion faults. + * BUG FIX: The parsing of the \x and \u escape sequences are now correct. * BUG FIX: Computation of LINCOMs with complex valued input fields now Modified: trunk/getdata/src/bzip.c =================================================================== --- trunk/getdata/src/bzip.c 2014-05-10 01:21:54 UTC (rev 903) +++ trunk/getdata/src/bzip.c 2014-05-19 19:46:21 UTC (rev 904) @@ -44,7 +44,6 @@ BZFILE* bzfile; FILE* stream; int bzerror; - int write; int stream_end; int pos, end; off64_t base; @@ -95,10 +94,8 @@ ptr->bzerror = ptr->stream_end = 0; if (mode & GD_FILE_READ) { ptr->bzfile = BZ2_bzReadOpen(&ptr->bzerror, stream, 0, 0, NULL, 0); - ptr->write = 0; } else { ptr->bzfile = BZ2_bzWriteOpen(&ptr->bzerror, stream, 9, 0, 30); - ptr->write = 1; memset(ptr->data, 0, GD_BZIP_BUFFER_SIZE); } @@ -325,10 +322,10 @@ dtrace("%p", file); ptr->bzerror = 0; - if (ptr->write) + if (file->mode & GD_FILE_READ) + BZ2_bzReadClose(&ptr->bzerror, ptr->bzfile); + else BZ2_bzWriteClose(&ptr->bzerror, ptr->bzfile, 0, NULL, NULL); - else - BZ2_bzReadClose(&ptr->bzerror, ptr->bzfile); if (ptr->bzerror || fclose(ptr->stream)) { dreturn("%i", 1); Modified: trunk/getdata/src/encoding.c =================================================================== --- trunk/getdata/src/encoding.c 2014-05-10 01:21:54 UTC (rev 903) +++ trunk/getdata/src/encoding.c 2014-05-19 19:46:21 UTC (rev 904) @@ -106,18 +106,35 @@ #undef GD_EF_PROVIDES +/* We only provide write support for .xz files, not .lzma */ #ifdef USE_LZMA #define GD_EF_PROVIDES \ - GD_EF_OPEN | GD_EF_CLOSE | GD_EF_SEEK | GD_EF_READ | GD_EF_SIZE + GD_EF_OPEN | GD_EF_CLOSE | GD_EF_SEEK | GD_EF_READ | GD_EF_SIZE | \ + GD_EF_WRITE | GD_EF_SYNC #define GD_INT_FUNCS \ &_GD_GenericName, &_GD_LzmaOpen, &_GD_LzmaClose, &_GD_LzmaSeek, \ + &_GD_LzmaRead, &_GD_LzmaSize, &_GD_LzmaWrite, &_GD_LzmaSync, \ + &_GD_GenericMove, &_GD_GenericUnlink +#else +#define GD_INT_FUNCS GD_EF_NULL_SET +#define GD_EF_PROVIDES 0 +#endif + GD_EXT_ENCODING_GEN(GD_LZMA_ENCODED, ".xz", GD_EF_ECOR | GD_EF_OOP, "Lzma", + "lzma"), +#undef GD_INT_FUNCS +#undef GD_EF_PROVIDES + +#ifdef USE_LZMA +#define GD_EF_PROVIDES \ + GD_EF_OPEN | GD_EF_CLOSE | GD_EF_SEEK | GD_EF_READ | GD_EF_SIZE +#define GD_INT_FUNCS \ + &_GD_GenericName, &_GD_LzmaOpen, &_GD_LzmaClose, &_GD_LzmaSeek, \ &_GD_LzmaRead, &_GD_LzmaSize, NULL /* WRITE */, NULL /* SYNC */, \ &_GD_GenericMove, &_GD_GenericUnlink #else #define GD_INT_FUNCS GD_EF_NULL_SET #define GD_EF_PROVIDES 0 #endif - GD_EXT_ENCODING_GEN(GD_LZMA_ENCODED, ".xz", GD_EF_ECOR, "Lzma", "lzma"), GD_EXT_ENCODING_GEN(GD_LZMA_ENCODED, ".lzma", GD_EF_ECOR, "Lzma", "lzma"), #undef GD_INT_FUNCS #undef GD_EF_PROVIDES Modified: trunk/getdata/src/internal.h =================================================================== --- trunk/getdata/src/internal.h 2014-05-10 01:21:54 UTC (rev 903) +++ trunk/getdata/src/internal.h 2014-05-19 19:46:21 UTC (rev 904) @@ -1282,7 +1282,7 @@ size_t); ssize_t _GD_GzipWrite(struct gd_raw_file_ *restrict, const void *restrict, gd_type_t, size_t); -int _GD_GzipSync(struct gd_raw_file_* file); +int _GD_GzipSync(struct gd_raw_file_*); int _GD_GzipClose(struct gd_raw_file_* file); off64_t _GD_GzipSize(int, struct gd_raw_file_* file, gd_type_t data_type, int swap); @@ -1293,7 +1293,10 @@ gd_type_t data_type, unsigned int); ssize_t _GD_LzmaRead(struct gd_raw_file_ *restrict, void *restrict, gd_type_t, size_t); +ssize_t _GD_LzmaWrite(struct gd_raw_file_ *restrict, const void *restrict, + gd_type_t, size_t); int _GD_LzmaClose(struct gd_raw_file_* file); +int _GD_LzmaSync(struct gd_raw_file_ *file); off64_t _GD_LzmaSize(int, struct gd_raw_file_* file, gd_type_t data_type, int swap); Modified: trunk/getdata/src/lzma.c =================================================================== --- trunk/getdata/src/lzma.c 2014-05-10 01:21:54 UTC (rev 903) +++ trunk/getdata/src/lzma.c 2014-05-19 19:46:21 UTC (rev 904) @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2011 D. V. Wiebe +/* Copyright (C) 2014 D. V. Wiebe * *************************************************************************** * @@ -33,200 +33,277 @@ #endif #if SIZEOF_INT < 4 -#define GD_LZMA_BUFFER_SIZE 32767 +#define GD_LZMA_DATA_OUT 32767 #else -#define GD_LZMA_BUFFER_SIZE 1000000 +#define GD_LZMA_DATA_OUT 1000000 #endif +#define GD_LZMA_DATA_IN 4096 +#define GD_LZMA_LOOKBACK 4096 struct gd_lzmadata { - lzma_stream xzfile; + lzma_stream xz; FILE* stream; - int xzerror; - int stream_end; /* uncompressed file ran out of data */ - int input_eof; /* compressed file ran out of data */ - int read_in; /* location of the end of valid data in data_in */ - int out_pos; /* library's current position relative to the start of - data_out */ - int end; /* location of the end of valid data in data_out */ - off64_t base; /* position of the start of data_out in the uncompressed - stream */ - uint8_t data_in[GD_LZMA_BUFFER_SIZE]; - uint8_t data_out[GD_LZMA_BUFFER_SIZE]; + int stream_end; + int input_eof; + int offset; + uint8_t data_in[GD_LZMA_DATA_IN]; + uint8_t data_out[GD_LZMA_DATA_OUT]; }; -/* The bzip encoding scheme uses edata as a gd_lzmadata pointer. If a file is +/* total bytes in the output buffer */ +#define NOUT(p) (GD_LZMA_DATA_OUT - (p).xz.avail_out) + +/* byte position of the start of the output buffer */ +#define BASE(p) ((p).xz.total_out - NOUT(p)) + +/* bytes of unused data in output buffer */ +#define READY(p) (NOUT(p) - (p).offset) + +/* At EOF */ +#define LZEOF(p) ((p).stream_end || (p).input_eof) + +/* The lzma encoding scheme uses edata as a gd_lzmadata pointer. If a file is * open, idata = 0 otherwise idata = -1. */ -static struct gd_lzmadata *_GD_LzmaDoOpen(int dirfd, struct gd_raw_file_* file) +static struct gd_lzmadata *_GD_LzmaDoOpen(int dirfd, struct gd_raw_file_* file, + unsigned int mode) { - struct gd_lzmadata *ptr; + struct gd_lzmadata *lzd; int fd; + lzma_ret e; + const char *fdmode = "rb"; + FILE *stream; + const lzma_stream stream_init = LZMA_STREAM_INIT; - dtrace("%i, %p", dirfd, file); + dtrace("%i, %p, %i", dirfd, file, mode); - if ((ptr = (struct gd_lzmadata *)malloc(sizeof(struct gd_lzmadata))) == NULL) - { + if (mode & GD_FILE_READ) { + fd = gd_OpenAt(file->D, dirfd, file->name, O_RDONLY | O_BINARY, 0666); + } else if (mode & GD_FILE_TEMP) { + fd = _GD_MakeTempFile(file->D, dirfd, file->name); + fdmode = "wb"; + } else { /* internal error */ + errno = EINVAL; /* I guess ... ? */ dreturn("%p", NULL); return NULL; } - if ((fd = gd_OpenAt(file->D, dirfd, file->name, O_RDONLY | O_BINARY, 0666)) - == -1) - { - free(ptr); + if (fd < 0) { dreturn("%p", NULL); return NULL; } - if ((ptr->stream = fdopen(fd, "rb")) == NULL) { + if ((stream = fdopen(fd, fdmode)) == NULL) { close(fd); - free(ptr); dreturn("%p", NULL); return NULL; } - memset(&ptr->xzfile, 0, sizeof(lzma_stream)); - ptr->xzfile.next_in = ptr->data_in; - ptr->xzfile.next_out = ptr->data_out; - ptr->xzfile.avail_in = 0; - ptr->xzfile.avail_out = GD_LZMA_BUFFER_SIZE; - ptr->xzerror = lzma_auto_decoder(&ptr->xzfile, 1000000000, 0); - ptr->xzfile.total_in = 0; + if ((lzd = (struct gd_lzmadata *)malloc(sizeof(struct gd_lzmadata))) == NULL) + { + dreturn("%p", NULL); + return NULL; + } + memset(lzd, 0, sizeof(*lzd)); - if (ptr->xzerror != LZMA_OK) { - fclose(ptr->stream); - free(ptr); + lzd->xz = stream_init; + lzd->stream = stream; + lzd->xz.next_in = lzd->data_in; + lzd->xz.next_out = lzd->data_out; + lzd->xz.avail_out = GD_LZMA_DATA_OUT; + if (mode & GD_FILE_READ) + e = lzma_auto_decoder(&lzd->xz, UINT64_MAX, 0); + else { + e = lzma_easy_encoder(&lzd->xz, 9, LZMA_CHECK_CRC64); + memset(lzd->data_in, 0, GD_LZMA_DATA_IN); + } + + if (e != LZMA_OK) { + fclose(lzd->stream); + free(lzd); dreturn("%p", NULL); return NULL; } - ptr->read_in = ptr->out_pos = ptr->end = 0; - ptr->base = ptr->stream_end = ptr->input_eof = 0; - - dreturn("%p", ptr); - return ptr; + dreturn("%p", lzd); + return lzd; } int _GD_LzmaOpen(int dirfd, struct gd_raw_file_* file, int swap gd_unused_, - unsigned int mode gd_unused_) + unsigned int mode) { - dtrace("%i, %p, <unused>, <unused>", dirfd, file); + dtrace("%i, %p, <unused>, 0x%X", dirfd, file, mode); - file->edata = _GD_LzmaDoOpen(dirfd, file); + file->edata = _GD_LzmaDoOpen(dirfd, file, mode); if (file->edata == NULL) { dreturn("%i", 1); return 1; } - file->mode = GD_FILE_READ; + file->mode = mode; file->pos = 0; file->idata = 0; dreturn("%i", 0); return 0; } -/* Read as much data as possible, and then run the converter on it, leaving - * unused input at the front of the input buffer, and updating read_in as - * appropriate. Returns -1 on error */ -static int _GD_LzmaDecode(struct gd_lzmadata *ptr) +/* Read and decode until the there's enough data ready in the output buffer, or + * it's full, or we hit EOF. Returns -1 on error, data ready size otherwise. + * + * This doesn't update next_out, so we don't have to worry about updating + * offset. + */ +static int _GD_LzmaReady(struct gd_lzmadata *lzd, size_t nreq) { - int n = 0; + lzma_ret e; + int ready = READY(*lzd); - dtrace("%p", ptr); + dtrace("%p, %" PRNsize_t, lzd, nreq); - if (!ptr->input_eof) { - n = fread(ptr->data_in + ptr->read_in, 1, GD_LZMA_BUFFER_SIZE - - ptr->read_in, ptr->stream); + /* already have enough data, or no more data to read */ + if (LZEOF(*lzd) || (size_t)ready >= nreq) { + dreturn("%i", ready); + return ready; + } - if (n < GD_LZMA_BUFFER_SIZE - ptr->read_in) { - if (feof(ptr->stream)) - ptr->input_eof = 1; - else { - dreturn("%i", -1); - return -1; + /* coding loop */ + while (lzd->xz.avail_out > 0 && (size_t)ready < nreq) { + /* No input data, so read some */ + if (lzd->xz.avail_in == 0) { + size_t n = fread(lzd->data_in, 1, GD_LZMA_DATA_IN, lzd->stream); + if (n == 0) { + if (ferror(lzd->stream)) { + dreturn("%i", -1); + return -1; + } + /* end of input */ + lzd->input_eof = 1; + break; } + lzd->xz.avail_in = n; + lzd->xz.next_in = lzd->data_in; } - } - ptr->xzfile.avail_in = ptr->read_in + n; + /* code */ + e = lzma_code(&lzd->xz, LZMA_RUN); + if (e != LZMA_OK && e != LZMA_STREAM_END) { + dreturn("%i", -1); + return -1; + } - /* no more data to convert -- end of stream reached */ - if (ptr->xzfile.avail_in == 0) { - ptr->stream_end = 1; - dreturn("%i", 0); - return 0; + ready = READY(*lzd); + if (e == LZMA_STREAM_END) { + lzd->stream_end = 1; + break; + } } - /* amount of data = amount already in buffer + amount just now read */ - ptr->xzerror = lzma_code(&ptr->xzfile, LZMA_RUN); + dreturn("%i", ready); + return ready; +} - if (ptr->xzerror == LZMA_OK || ptr->xzerror == LZMA_STREAM_END) { - ptr->base += ptr->end; - ptr->end = ptr->xzfile.total_out; - /* shift unused input to start of buffer */ - memmove(ptr->data_in, ptr->data_in + ptr->xzfile.total_in, - ptr->xzfile.avail_in); - ptr->read_in = ptr->xzfile.avail_in; - } else { - dreturn("%i", -1); - return -1; - } +/* clear the output buffer, retaining a bit of data for lookback purposes */ +static void _GD_LzmaClear(struct gd_lzmadata *lzd) +{ + int n; - dreturn("%i", 0); - return 0; + dtrace("%p", lzd); + + /* amount of data to keep */ + n = NOUT(*lzd); + if (n > GD_LZMA_LOOKBACK) + n = GD_LZMA_LOOKBACK; + + memmove(lzd->data_out, lzd->xz.next_out - n, n); + lzd->xz.next_out = lzd->data_out + n; + lzd->xz.avail_out = GD_LZMA_DATA_OUT - n; + + dreturnvoid(); } off64_t _GD_LzmaSeek(struct gd_raw_file_* file, off64_t count, - gd_type_t data_type, unsigned int mode gd_unused_) + gd_type_t data_type, unsigned int mode) { - struct gd_lzmadata *ptr = (struct gd_lzmadata *)file->edata; + struct gd_lzmadata *lzd; + lzma_ret e; + uint64_t bcount; - dtrace("%p, %lli, 0x%X, <unused>", file, (long long)count, data_type); + dtrace("%p, %lli, 0x%X, 0x%X", file, (long long)count, data_type, mode); - count *= GD_SIZE(data_type); + bcount = count * GD_SIZE(data_type); - /* the easy case */ - if (file->pos == count) { - dreturn("%lli", (long long)count); - return count; + if (mode == GD_FILE_WRITE) + lzd = (struct gd_lzmadata *)file[1].edata; + else + lzd = (struct gd_lzmadata *)file[0].edata; + + /* the easy case -- position is somewhere within our current output buffer */ + if (bcount < lzd->xz.total_out && bcount >= BASE(*lzd)) { + lzd->offset = bcount - BASE(*lzd); + file->pos = count; + + dreturn("%lli", (long long)(file->pos)); + return file->pos; } - if (ptr->base > count) { - /* a backwards seek -- rewind to the beginning */ - lzma_end(&ptr->xzfile); - ptr->xzfile.avail_in = 0; - ptr->xzfile.avail_out = GD_LZMA_BUFFER_SIZE; - ptr->xzerror = lzma_auto_decoder(&ptr->xzfile, 1000000000, 0); - ptr->xzfile.total_in = GD_LZMA_BUFFER_SIZE; - if (ptr->xzerror != LZMA_OK) { - file->idata = -1; - fclose(ptr->stream); - dreturn("%i", 1); - return 1; + if (mode != GD_FILE_WRITE) { + if (BASE(*lzd) > bcount) { + /* a backwards seek -- rewind to the beginning */ + lzd->xz.avail_in = 0; + lzd->xz.avail_out = GD_LZMA_DATA_OUT; + lzd->xz.total_in = lzd->xz.total_out = 0; + lzd->xz.next_in = lzd->data_in; + lzd->xz.next_out = lzd->data_out; + e = lzma_auto_decoder(&lzd->xz, UINT64_MAX, 0); + if (e != LZMA_OK) { + file->idata = -1; + free(lzd); + file->edata = NULL; + fclose(lzd->stream); + dreturn("%i", 1); + return 1; + } + rewind(lzd->stream); + lzd->input_eof = lzd->stream_end = 0; } - rewind(ptr->stream); - ptr->read_in = ptr->out_pos = ptr->end = 0; - ptr->base = ptr->input_eof = ptr->stream_end = 0; - } - /* seek forward the slow way */ - while (ptr->base + ptr->end < count) { - if (_GD_LzmaDecode(ptr)) { - dreturn("%i", -1); - return -1; + /* seek forward the slow way */ + while (lzd->xz.total_out < bcount) { + /* discard output */ + _GD_LzmaClear(lzd); + + if (_GD_LzmaReady(lzd, lzd->xz.avail_out) < 0) { + dreturn("%i", -1); + return -1; + } + + /* eof */ + if (LZEOF(*lzd)) + break; } - /* eof */ - if (ptr->stream_end) - break; + if (lzd->xz.total_out < bcount) { + /* ran out of data */ + lzd->offset = NOUT(*lzd); + file->pos = lzd->xz.total_out / GD_SIZE(data_type); + } else { + lzd->offset = bcount - BASE(*lzd); + file->pos = count; + } + } else { + /* we only get here when we need to pad */ + while (lzd->xz.total_in < bcount) { + int n = bcount - lzd->xz.total_in; + if (n > GD_LZMA_DATA_IN) + n = GD_LZMA_DATA_IN; + + _GD_LzmaWrite(file + 1, lzd->data_in, GD_UINT8, n); + } + lzd->offset = 0; + file->pos = lzd->xz.total_in / GD_SIZE(data_type); } - ptr->out_pos = (ptr->stream_end && count >= ptr->base + ptr->end) ? ptr->end - : count - ptr->base; - - file->pos = (ptr->base + ptr->out_pos) / GD_SIZE(data_type); - dreturn("%lli", (long long)(file->pos)); return file->pos; } @@ -234,103 +311,205 @@ ssize_t _GD_LzmaRead(struct gd_raw_file_ *file, void *data, gd_type_t data_type, size_t nmemb) { - char* output = (char *)data; - struct gd_lzmadata *ptr = (struct gd_lzmadata *)file->edata; - uint64_t nbytes = nmemb * GD_SIZE(data_type); + uint64_t bcount; + struct gd_lzmadata *lzd = (struct gd_lzmadata *)file->edata; + ssize_t nread = 0; dtrace("%p, %p, 0x%X, %" PRNsize_t, file, data, data_type, nmemb); - /* this loops over chunks of uncompressed data of size data_out until we - * have as much data as we need in data_out, or until EOF */ - while (nbytes > (uint64_t)(ptr->end - ptr->out_pos)) { - memcpy(output, ptr->data_out + ptr->out_pos, ptr->end - ptr->out_pos); - output += ptr->end - ptr->out_pos; - nbytes -= ptr->end - ptr->out_pos; - ptr->out_pos = ptr->end; + if (nmemb > GD_SSIZE_T_MAX / GD_SIZE(data_type)) + nmemb = GD_SSIZE_T_MAX / GD_SIZE(data_type); + bcount = nmemb * GD_SIZE(data_type); - if (ptr->stream_end) { - dreturn("%li", (long)(nmemb - nbytes / GD_SIZE(data_type))); - return nmemb - nbytes / GD_SIZE(data_type); - } + /* decoding loop */ + while (bcount > 0) { + int bready, nready; - if (_GD_LzmaDecode(ptr)) { + /* clear the output buffer if it's full */ + if (lzd->xz.avail_out == 0) + _GD_LzmaClear(lzd); + + bready = _GD_LzmaReady(lzd, bcount); + if (bready < 0) { dreturn("%i", -1); return -1; } - /* eof */ - if (ptr->stream_end) + /* copy whole samples */ + nready = bready / GD_SIZE(data_type); + if (nready > (ssize_t)nmemb) + nready = nmemb; + + bready = nready * GD_SIZE(data_type); + + memcpy(data, lzd->data_out + lzd->offset, bready); + lzd->offset += bready; + bcount -= bready; + data += bready; + nread += nready; + + if (LZEOF(*lzd)) break; } - /* If we still have more data than we need (no EOF), copy it all, otherwise - * (reached EOF) copy as much as we have */ - if (nbytes > (uint64_t)(ptr->end - ptr->out_pos)) { - memcpy(output, ptr->data_out + ptr->out_pos, ptr->end - ptr->out_pos); - ptr->out_pos = ptr->end; - nbytes -= ptr->end; - } else { - memcpy(output, ptr->data_out + ptr->out_pos, nbytes); - ptr->out_pos += nbytes; - nbytes = 0; + dreturn("%" PRNssize_t, nread); + return nread; +} + +/* flush the output buffer to the stream */ +static int _GD_LzmaFlush(struct gd_lzmadata *lzd) +{ + uint8_t *ptr; + + dtrace("%p", lzd); + + ptr = lzd->data_out; + while (NOUT(*lzd) > 0) { + ssize_t nw = fwrite(ptr, 1, NOUT(*lzd), lzd->stream); + if (nw == 0 && ferror(lzd->stream)) { + dreturn("%i", 1); + return 1; + } + + ptr += nw; + lzd->xz.avail_out += nw; } - file->pos += nmemb - nbytes / GD_SIZE(data_type); + /* reset output buffer */ + lzd->xz.next_out = lzd->data_out; - dreturn("%li", (long)(nmemb - nbytes / GD_SIZE(data_type))); - return nmemb - nbytes / GD_SIZE(data_type); + dreturn("%i", 0); + return 0; } +ssize_t _GD_LzmaWrite(struct gd_raw_file_ *file, const void *data, + gd_type_t data_type, size_t nmemb) +{ + lzma_ret e; + size_t n; + struct gd_lzmadata *lzd = (struct gd_lzmadata *)file->edata; + + dtrace("%p, %p, 0x%X, %" PRNsize_t, file, data, data_type, nmemb); + + n = nmemb * GD_SIZE(data_type); + + /* We let liblzma read directly from the caller's buffer */ + lzd->xz.next_in = data; + lzd->xz.avail_in = n; + + /* code */ + while (lzd->xz.avail_in > 0) { + e = lzma_code(&lzd->xz, LZMA_RUN); + if (e != LZMA_OK) { + dreturn("%i", -1); + return -1; + } + + if (_GD_LzmaFlush(lzd)) { + dreturn("%i", -1); + return -1; + } + } + + /* we always write all the input, if successful */ + dreturn("%" PRNssize_t, (ssize_t)nmemb); + return nmemb; +} + int _GD_LzmaClose(struct gd_raw_file_ *file) { - struct gd_lzmadata *ptr = (struct gd_lzmadata *)file->edata; + lzma_ret e; + struct gd_lzmadata *lzd = (struct gd_lzmadata *)file->edata; dtrace("%p", file); - ptr->xzerror = 0; - lzma_end(&ptr->xzfile); - if (fclose(ptr->stream)) { + /* finialise */ + if (!(file->mode & GD_FILE_READ)) { + /* ensure we don't read any more data */ + lzd->xz.avail_in = 0; + for (;;) { + e = lzma_code(&lzd->xz, LZMA_FINISH); + if (e != LZMA_OK && e != LZMA_STREAM_END) { + dreturn("%i", 1); + return 1; + } + + if (_GD_LzmaFlush(lzd)) { + dreturn("%i", 1); + return 1; + } + + if (e == LZMA_STREAM_END) + break; + } + } + + /* shutdown */ + lzma_end(&lzd->xz); + if (fclose(lzd->stream)) { dreturn("%i", 1); return 1; } file->idata = -1; - file->mode = 0; free(file->edata); + file->edata = NULL; dreturn("%i", 0); return 0; } +/* We don't flush the encoder since it may degrade compression, but we can + * flush the stdio buffer */ +int _GD_LzmaSync(struct gd_raw_file_ *file) +{ + int r = 0; + dtrace("%p", file); + + if (file->mode & GD_FILE_WRITE) { + struct gd_lzmadata *lzd = (struct gd_lzmadata *)file[1].edata; + + r = fflush(lzd->stream); + } + + dreturn("%i", r); + return r; +} + off64_t _GD_LzmaSize(int dirfd, struct gd_raw_file_ *file, gd_type_t data_type, int swap gd_unused_) { - struct gd_lzmadata *ptr; - off_t n; + struct gd_lzmadata *lzd; + off64_t n; dtrace("%i, %p, 0x%X, <unused>", dirfd, file, data_type); - ptr = _GD_LzmaDoOpen(dirfd, file); + lzd = _GD_LzmaDoOpen(dirfd, file, GD_FILE_READ); - if (ptr == NULL) { + if (lzd == NULL) { dreturn("%i", -1); return -1; } - /* seek forward the slow way to the end */ - while (!ptr->stream_end) { - if (_GD_LzmaDecode(ptr)) { - lzma_end(&ptr->xzfile); - fclose(ptr->stream); + /* read until EOF */ + while (!LZEOF(*lzd)) { + if (_GD_LzmaReady(lzd, GD_LZMA_DATA_OUT) < 0) { dreturn("%i", -1); return -1; } + + /* discard output */ + lzd->xz.next_out = lzd->data_out; + lzd->xz.avail_out = GD_LZMA_DATA_OUT; } - lzma_end(&ptr->xzfile); - fclose(ptr->stream); - n = (ptr->base + ptr->end) / GD_SIZE(data_type); - free(ptr); + /* liblzma very graciously does the bookkeeping for us */ + n = lzd->xz.total_out / GD_SIZE(data_type); + lzma_end(&lzd->xz); + fclose(lzd->stream); + + free(lzd); + dreturn("%lli", (long long)n); return n; } Modified: trunk/getdata/src/raw.c =================================================================== --- trunk/getdata/src/raw.c 2014-05-10 01:21:54 UTC (rev 903) +++ trunk/getdata/src/raw.c 2014-05-19 19:46:21 UTC (rev 904) @@ -110,7 +110,14 @@ int _GD_RawSync(struct gd_raw_file_ *file) { - return fsync(file->idata); + int r; + + dtrace("%p", file); + + r = fsync(file->idata); + + dreturn("%i", r); + return r; } int _GD_RawClose(struct gd_raw_file_ *file) Index: trunk/getdata/test =================================================================== --- trunk/getdata/test 2014-05-10 01:21:54 UTC (rev 903) +++ trunk/getdata/test 2014-05-19 19:46:21 UTC (rev 904) Property changes on: trunk/getdata/test ___________________________________________________________________ Modified: svn:ignore ## -635,6 +635,21 ## legacy_spf lzma_get lzma_nframes +lzma_put +lzma_xz_add +lzma_xz_get +lzma_xz_get_far +lzma_xz_get_get +lzma_xz_get_get2 +lzma_xz_get_put +lzma_xz_move_to +lzma_xz_nframes +lzma_xz_put +lzma_xz_put_back +lzma_xz_put_endian +lzma_xz_put_get +lzma_xz_put_pad +lzma_xz_sync madd madd_affix madd_alias ## -1137,8 +1152,6 ## vlist_meta vlist_meta_hidden vlist_meta_invalid -xz_get -xz_nframes zzip_data zzip_get zzip_get_get Modified: trunk/getdata/test/Makefile.am =================================================================== --- trunk/getdata/test/Makefile.am 2014-05-10 01:21:54 UTC (rev 903) +++ trunk/getdata/test/Makefile.am 2014-05-19 19:46:21 UTC (rev 904) @@ -239,7 +239,10 @@ legacy_spf endif -LZMA_TESTS=lzma_get lzma_nframes +LZMA_TESTS=lzma_get lzma_nframes lzma_put lzma_xz_add lzma_xz_get \ + lzma_xz_get_far lzma_xz_get_get lzma_xz_get_get2 lzma_xz_get_put \ + lzma_xz_move_to lzma_xz_nframes lzma_xz_put lzma_xz_put_back \ + lzma_xz_put_endian lzma_xz_put_get lzma_xz_put_pad lzma_xz_sync MADD_TESTS=madd madd_affix madd_alias madd_alias_affix madd_bit \ madd_bit_invalid madd_carray madd_clincom madd_const madd_cpolynom \ @@ -396,8 +399,6 @@ VLIST_TESTS=vlist vlist_alias vlist_hidden vlist_invalid vlist_meta \ vlist_meta_hidden vlist_meta_invalid -XZ_TESTS=xz_get xz_nframes - ZZIP_TESTS=zzip_data zzip_get zzip_get_get zzip_nframes ZZSLIM_TESTS=zzslim_get zzslim_nframes @@ -417,7 +418,7 @@ $(SEEK_TESTS) $(SIE_TESTS) $(SLIM_TESTS) $(SPF_TESTS) \ $(SVLIST_TESTS) $(TABLE_TESTS) $(TELL_TESTS) $(TOK_TESTS) \ $(TRUNC_TESTS) $(UNCLUDE_TESTS) $(VERSION_TESTS) $(VLIST_TESTS) \ - $(XZ_TESTS) $(ZZIP_TESTS) $(ZZSLIM_TESTS) + $(ZZIP_TESTS) $(ZZSLIM_TESTS) check_PROGRAMS=$(TESTS) Modified: trunk/getdata/test/encode_support.c =================================================================== --- trunk/getdata/test/encode_support.c 2014-05-10 01:21:54 UTC (rev 903) +++ trunk/getdata/test/encode_support.c 2014-05-19 19:46:21 UTC (rev 904) @@ -40,7 +40,7 @@ #endif #ifdef USE_LZMA -#define GD_LZMA_MODE GD_RDONLY +#define GD_LZMA_MODE GD_RDWR #else #define GD_LZMA_MODE -1 #endif Added: trunk/getdata/test/lzma_put.c =================================================================== --- trunk/getdata/test/lzma_put.c (rev 0) +++ trunk/getdata/test/lzma_put.c 2014-05-19 19:46:21 UTC (rev 904) @@ -0,0 +1,73 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#ifndef TEST_LZMA + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data_lzma = "dirfile/data.lzma"; + const char *data = "dirfile/data"; + const char *format_data = "data RAW UINT8 8\n"; + uint8_t c[8] = {40, 41, 42, 43, 44, 45, 46, 47}; + uint8_t data_data[256]; + char command[4096]; + int fd, n, e1, e2, r = 0; + DIRFILE *D; + + rmdirfile(); + mkdir(filedir, 0777); + + for (fd = 0; fd < 256; ++fd) + data_data[fd] = (uint8_t)fd; + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, data_data, 256 * sizeof(uint16_t)); + close(fd); + + /* compress */ + snprintf(command, 4096, "%s -F lzma -f %s > /dev/null", XZ, data); + if (gd_system(command)) + return 1; + + D = gd_open(filedir, GD_RDWR); + n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); + e1 = gd_error(D); + CHECKI(e1, GD_E_UNSUPPORTED); + CHECKI(n, 0); + + e2 = gd_discard(D); + CHECKI(e2, 0); + + unlink(data_lzma); + unlink(format); + rmdir(filedir); + + return r; +#endif +} Added: trunk/getdata/test/lzma_xz_add.c =================================================================== --- trunk/getdata/test/lzma_xz_add.c (rev 0) +++ trunk/getdata/test/lzma_xz_add.c 2014-05-19 19:46:21 UTC (rev 904) @@ -0,0 +1,77 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#ifndef TEST_LZMA + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data.xz"; + gd_entry_t e; + int e1, e2, e3, unlink_data, r = 0; + DIRFILE *D; + + rmdirfile(); +#ifdef USE_LZMA + D = gd_open(filedir, GD_RDWR | GD_CREAT | GD_VERBOSE | GD_LZMA_ENCODED); +#else + D = gd_open(filedir, GD_RDWR | GD_CREAT | GD_LZMA_ENCODED); +#endif + gd_add_raw(D, "data", GD_UINT8, 2, 0); + e1 = gd_error(D); + + /* check */ + e2 = gd_entry(D, "data", &e); +#ifdef USE_LZMA + CHECKI(e2, 0); + if (e2 == 0) { + CHECKI(e.field_type, GD_RAW_ENTRY); + CHECKI(e.fragment_index, 0); + CHECKI(e.EN(raw,spf), 2); + CHECKI(e.EN(raw,data_type), GD_UINT8); + gd_free_entry_strings(&e); + } +#else + CHECKI(e2, -1); +#endif + + e3 = gd_close(D); + CHECKI(e3, 0); + + unlink_data = unlink(data); + +#ifdef USE_LZMA + CHECKI(unlink_data, 0); + CHECKI(e1, GD_E_OK); +#else + CHECKI(unlink_data, -1); + CHECKI(e1, GD_E_UNSUPPORTED); +#endif + + unlink(format); + rmdir(filedir); + + return r; +#endif +} Copied: trunk/getdata/test/lzma_xz_get.c (from rev 903, trunk/getdata/test/xz_get.c) =================================================================== --- trunk/getdata/test/lzma_xz_get.c (rev 0) +++ trunk/getdata/test/lzma_xz_get.c 2014-05-19 19:46:21 UTC (rev 904) @@ -0,0 +1,88 @@ +/* Copyright (C) 2009-2011, 2013 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#ifndef TEST_LZMA + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data"; + const char *xzdata = "dirfile/data.xz"; + const char *format_data = "data RAW UINT16 8\n"; + uint16_t c[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + char command[4096]; + uint16_t data_data[256]; +#ifdef USE_LZMA + int i; +#endif + int fd, n, error, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (fd = 0; fd < 256; ++fd) + data_data[fd] = (unsigned char)fd; + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, data_data, 256 * sizeof(uint16_t)); + close(fd); + + /* compress */ + snprintf(command, 4096, "%s -f %s > /dev/null", XZ, data); + if (gd_system(command)) + return 1; + +#ifdef USE_LZMA + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDONLY); +#endif + n = gd_getdata(D, "data", 5, 0, 1, 0, GD_UINT16, c); + error = gd_error(D); + + gd_discard(D); + + unlink(xzdata); + unlink(format); + rmdir(filedir); + +#ifdef USE_LZMA + CHECKI(error,0); + CHECKI(n,8); + for (i = 0; i < 8; ++i) + CHECKXi(i,c[i],40 + i); +#else + CHECKI(error,GD_E_UNSUPPORTED); + CHECKI(n,0); +#endif + + return r; +#endif +} Added: trunk/getdata/test/lzma_xz_get_far.c =================================================================== --- trunk/getdata/test/lzma_xz_get_far.c (rev 0) +++ trunk/getdata/test/lzma_xz_get_far.c 2014-05-19 19:46:21 UTC (rev 904) @@ -0,0 +1,82 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#ifndef TEST_LZMA + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data"; + const char *xzdata = "dirfile/data.xz"; + const char *format_data = "data RAW UINT16 8\n"; + uint16_t c[8]; + char command[4096]; + uint16_t data_data[256]; + int fd, n, error, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (fd = 0; fd < 256; ++fd) + data_data[fd] = (unsigned char)fd; + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, data_data, 256 * sizeof(uint16_t)); + close(fd); + + /* compress */ + snprintf(command, 4096, "%s -f %s > /dev/null", XZ, data); + if (gd_system(command)) + return 1; + +#ifdef USE_LZMA + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDONLY); +#endif + n = gd_getdata(D, "data", 1000, 0, 1, 0, GD_UINT16, c); + error = gd_error(D); + + gd_discard(D); + + unlink(xzdata); + unlink(format); + rmdir(filedir); + +#ifdef USE_LZMA + CHECKI(error, 0); +#else + CHECKI(error, GD_E_UNSUPPORTED); +#endif + CHECKI(n, 0); + + return r; +#endif +} Added: trunk/getdata/test/lzma_xz_get_get.c =================================================================== --- trunk/getdata/test/lzma_xz_get_get.c (rev 0) +++ trunk/getdata/test/lzma_xz_get_get.c 2014-05-19 19:46:21 UTC (rev 904) @@ -0,0 +1,87 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#if !defined USE_LZMA || !defined TEST_LZMA + return 77; /* skip test */ +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data"; + const char *xzdata = "dirfile/data.xz"; + const char *format_data = "data RAW UINT16 8\n"; + uint16_t c1[8], c2[8]; + char command[4096]; + uint16_t data_data[256]; + int fd, i, n1, e1, e2, n2, e3, r = 0; + DIRFILE *D; + + memset(c1, 0, 16); + memset(c2, 0, 16); + rmdirfile(); + mkdir(filedir, 0777); + + for (fd = 0; fd < 256; ++fd) + data_data[fd] = (unsigned char)fd; + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, data_data, 256 * sizeof(uint16_t)); + close(fd); + + /* compress */ + snprintf(command, 4096, "%s -f %s > /dev/null", XZ, data); + if (gd_system(command)) + return 1; + + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); + n1 = gd_getdata(D, "data", 5, 0, 1, 0, GD_UINT16, c1); + CHECKI(n1, 8); + e1 = gd_error(D); + CHECKI(e1, 0); + + e2 = gd_close(D); + CHECKI(e2, 0); + + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); + n2 = gd_getdata(D, "data", 5, 0, 1, 0, GD_UINT16, c2); + e3 = gd_error(D); + CHECKI(e3, 0); + CHECKI(n2, 8); + for (i = 0; i < 8; ++i) { + CHECKIi(i,c1[i], 40 + i); + CHECKIi(i,c2[i], 40 + i); + } + + gd_discard(D); + + unlink(xzdata); + unlink(format); + rmdir(filedir); + + return r; +#endif +} Added: trunk/getdata/test/lzma_xz_get_get2.c =================================================================== --- trunk/getdata/test/lzma_xz_get_get2.c (rev 0) +++ trunk/getdata/test/lzma_xz_get_get2.c 2014-05-19 19:46:21 UTC (rev 904) @@ -0,0 +1,82 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#if !defined USE_LZMA || !defined TEST_LZMA + return 77; /* skip test */ +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data"; + const char *xzdata = "dirfile/data.xz"; + const char *format_data = "data RAW UINT16 8\n"; + uint16_t c1[8], c2[8]; + char command[4096]; + uint16_t data_data[256]; + int fd, i, n1, error1, n2, error2, r = 0; + DIRFILE *D; + + memset(c1, 0, 16); + memset(c2, 0, 16); + rmdirfile(); + mkdir(filedir, 0777); + + for (fd = 0; fd < 256; ++fd) + data_data[fd] = (unsigned char)fd; + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, data_data, 256 * sizeof(uint16_t)); + close(fd); + + /* compress */ + snprintf(command, 4096, "%s -f %s > /dev/null", XZ, data); + if (gd_system(command)) + return 1; + + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); + n1 = gd_getdata(D, "data", 0, 0, 1, 0, GD_UINT16, c1); + error1 = gd_error(D); + n2 = gd_getdata(D, "data", 0, 0, 1, 0, GD_UINT16, c2); + error2 = gd_error(D); + gd_discard(D); + + unlink(xzdata); + unlink(format); + rmdir(filedir); + + CHECKI(error1, 0); + CHECKI(error2, 0); + CHECKI(n1, 8); + CHECKI(n2, 8); + for (i = 0; i < 8; ++i) { + CHECKUi(i,c1[i], i); + CHECKUi(i,c2[i], i); + } + + return r; +#endif +} Added: trunk/getdata/test/lzma_xz_get_put.c =================================================================== --- trunk/getdata/test/lzma_xz_get_put.c (rev 0) +++ trunk/getdata/test/lzma_xz_get_put.c 2014-05-19 19:46:21 UTC (rev 904) @@ -0,0 +1,154 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#ifndef TEST_LZMA + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data_xz = "dirfile/data.xz"; + const char *data = "dirfile/data"; + const char *format_data = "data RAW UINT8 8\n"; + const unsigned char xzdata[300] = { + 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00, 0x00, 0x04, + 0xe6, 0xd6, 0xb4, 0x46, 0x02, 0x00, 0x21, 0x01, + 0x16, 0x00, 0x00, 0x00, 0x74, 0x2f, 0xe5, 0xa3, + 0xe0, 0x00, 0xff, 0x00, 0xea, 0x5d, 0x00, 0x00, + 0x00, 0x52, 0x50, 0x0a, 0x84, 0xf9, 0x9b, 0xb2, + 0x80, 0x21, 0xa9, 0x69, 0xd6, 0x27, 0xe0, 0x3e, + 0x06, 0x5a, 0x5f, 0x04, 0x8d, 0x53, 0xd4, 0x04, + 0xba, 0x39, 0x57, 0x05, 0x09, 0xc1, 0x55, 0x24, + 0xde, 0x9d, 0xb8, 0x71, 0x59, 0x31, 0x60, 0xa1, + 0x9f, 0xf9, 0x6f, 0x49, 0x73, 0xf2, 0xc8, 0xea, + 0x8c, 0xba, 0x1a, 0x8b, 0x29, 0x69, 0x21, 0x80, + 0xfe, 0x33, 0x83, 0x66, 0xaf, 0x46, 0x6d, 0xec, + 0x9e, 0x89, 0x8a, 0x0b, 0x83, 0xf0, 0x3c, 0x0e, + 0x89, 0x8e, 0x3f, 0xed, 0x5f, 0xe7, 0x9e, 0x90, + 0xd9, 0x1c, 0xff, 0x32, 0xf4, 0xb2, 0xe0, 0x39, + 0x51, 0xb2, 0xd2, 0x14, 0x15, 0xb4, 0xc5, 0x71, + 0xba, 0xdb, 0x06, 0xe3, 0x79, 0x9a, 0x9f, 0xbb, + 0x38, 0xc1, 0xb0, 0x00, 0xac, 0x93, 0x0b, 0xaa, + 0x06, 0x19, 0x03, 0x12, 0x08, 0x15, 0x5b, 0x9b, + 0xc8, 0x48, 0xf0, 0x32, 0x2e, 0xfe, 0x2d, 0xa0, + 0x87, 0xc8, 0xf0, 0xa4, 0xe0, 0xd2, 0x51, 0xeb, + 0x8d, 0x67, 0x56, 0x92, 0xb2, 0x4d, 0x84, 0xc5, + 0xf1, 0x86, 0x31, 0xdf, 0x6a, 0x62, 0x5b, 0xc2, + 0x79, 0x2d, 0xd9, 0xf7, 0x3c, 0x73, 0xba, 0x74, + 0x74, 0x07, 0xd8, 0x3c, 0xa9, 0x56, 0x22, 0x24, + 0xa1, 0x66, 0xf8, 0x5a, 0x84, 0x5f, 0x30, 0x67, + 0xd2, 0xf6, 0x4b, 0x49, 0x2e, 0x7f, 0x20, 0xeb, + 0xdb, 0xf8, 0x10, 0x0e, 0x94, 0x78, 0x77, 0xc7, + 0x3f, 0x6b, 0xef, 0xb4, 0xcd, 0x95, 0xe2, 0x6f, + 0xf6, 0x44, 0x6e, 0x06, 0xcf, 0x0b, 0x82, 0x1a, + 0xcb, 0xdb, 0x7a, 0xf0, 0x57, 0x8d, 0x98, 0xff, + 0x90, 0xc0, 0x3e, 0xe6, 0xc1, 0x12, 0x41, 0x75, + 0xee, 0x03, 0x28, 0x96, 0xeb, 0x09, 0x37, 0x0e, + 0x1e, 0x00, 0x00, 0x00, 0xb0, 0x3a, 0xdb, 0x65, + 0x2f, 0x4b, 0x41, 0x72, 0x00, 0x01, 0x86, 0x02, + 0x80, 0x02, 0x00, 0x00, 0x2d, 0x12, 0xa1, 0x9f, + 0xb1, 0xc4, 0x67, 0xfb, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x04, 0x59, 0x5a + }; + uint8_t b, c[8], d[8]; + char command[4096]; + int fd, i, m, n, e1, e2, e3, unlink_data, unlink_dataxz, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (i = 0; i < 8; ++i) + d[i] = (uint8_t)(80 + i); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(data_xz, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, xzdata, 300); + close(fd); + +#ifdef USE_LZMA + D = gd_open(filedir, GD_RDWR | GD_LZMA_ENCODED | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDWR | GD_LZMA_ENCODED); +#endif + n = gd_getdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); + e1 = gd_error(D); + m = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, d); + e2 = gd_error(D); + + e3 = gd_close(D); + CHECKI(e3, 0); + +#ifdef USE_LZMA + /* uncompress */ + snprintf(command, 4096, "%s --decompress -f %s > /dev/null", XZ, data_xz); + if (gd_system(command)) { + r = 1; + } else { + fd = open(data, O_RDONLY | O_BINARY); + if (fd >= 0) { + i = 0; + while (read(fd, &b, sizeof(uint8_t))) { + if (i < 40 || i >= 48) { + CHECKIi(i, b, i); + } else + CHECKIi(i, b, i + 40); + i++; + } + CHECKI(i, 256); + close(fd); + } + } + + for (i = 0; i < 8; ++i) + CHECKIi(i, c[i], 40 + i); +#endif + + unlink_data = unlink(data); + unlink_dataxz = unlink(data_xz); + unlink(format); + rmdir(filedir); + +#ifdef USE_LZMA + CHECKI(unlink_data, 0); + CHECKI(unlink_dataxz, -1); + CHECKI(e1, GD_E_OK); + CHECKI(e2, GD_E_OK); + CHECKI(n, 8); + CHECKI(m, 8); +#else + CHECKI(unlink_data, -1); + CHECKI(unlink_dataxz, 0); + CHECKI(e1, GD_E_UNSUPPORTED); + CHECKI(e2, GD_E_UNSUPPORTED); + CHECKI(n, 0); + CHECKI(m, 0); +#endif + + return r; +#endif +} Added: trunk/getdata/test/lzma_xz_move_to.c =================================================================== --- trunk/getdata/test/lzma_xz_move_to.c (rev 0) +++ trunk/getdata/test/lzma_xz_move_to.c 2014-05-19 19:46:21 UTC (rev 904) @@ -0,0 +1,111 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data_xz = "dirfile/data.xz"; + const char *data_raw = "dirfile/data"; + const char *format_data = "data RAW UINT8 8\n/ENCODING none\n/ENDIAN little\n"; + uint8_t data_in[256]; + DIRFILE *D; +#ifdef USE_LZMA + uint8_t d; + char command[4096]; + int i; +#endif + int fd, e1, e2, unlink_raw, r = 0; + struct stat buf; + + rmdirfile(); + mkdir(filedir, 0777); + + for (fd = 0; fd < 256; ++fd) + data_in[fd] = (unsigned char)fd; + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + fd = open(data_raw, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(fd, data_in, 256); + close(fd); + +#ifdef USE_LZMA + D = gd_open(filedir, GD_RDWR | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDWR); +#endif + gd_alter_encoding(D, GD_LZMA_ENCODED, 0, 1); + e1 = gd_error(D); + + e2 = gd_close(D); + CHECKI(e2, 0); + +#ifdef USE_LZMA + if (stat(data_xz, &buf)) { + perror("stat"); + r = 1; + } + CHECKI(stat(data_raw, &buf), -1); +#else + if (stat(data_raw, &buf)) { + perror("stat"); + r = 1; + } + CHECKI(stat(data_xz, &buf), -1); +#endif + +#ifdef USE_LZMA + /* uncompress */ + snprintf(command, 4096, "%s --decompress -f %s > /dev/null", XZ, data_xz); + if (gd_system(command)) { + fprintf(stderr, "command failed: %s\n", command); + r = 1; + } else { + fd = open(data_raw, O_RDONLY | O_BINARY); + if (fd >= 0) { + i = 0; + while (read(fd, &d, sizeof(uint8_t))) { + CHECKIi(i, d, i); + i++; + } + CHECKI(i, 256); + close(fd); + } + } +#endif + + unlink_raw = unlink(data_raw); + unlink(format); + rmdir(filedir); + + CHECKI(unlink_raw, 0); +#ifdef USE_LZMA + CHECKI(e1, GD_E_OK); +#else + CHECKI(e1, GD_E_UNSUPPORTED); +#endif + + return r; +} Copied: trunk/getdata/test/lzma_xz_nframes.c (from rev 903, trunk/getdata/test/xz_nframes.c) =================================================================== --- trunk/getdata/test/lzma_xz_nframes.c (rev 0) +++ trunk/getdata/test/lzma_xz_nframes.c 2014-05-19 19:46:21 UTC (rev 904) @@ -0,0 +1,90 @@ +/* Copyright (C) 2009-2011, 2013 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +/* Retrieving the number of frames should succeed cleanly */ +#include "test.h" + +#include <stdlib.h> +#include <sys/types.h> +#include <stdio.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <inttypes.h> + +int main(void) +{ +#ifndef TEST_LZMA + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data"; + const char *xzdata = "dirfile/data.xz"; + const char *format_data = "data RAW UINT16 1\n"; + char command[4096]; + uint16_t data_data[256]; + int i, error, r = 0; + DIRFILE *D; + size_t n; + + rmdirfile(); + mkdir(filedir, 0777); + + for (i = 0; i < 256; ++i) + data_data[i] = (uint16_t)i; + + i = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(i, format_data, strlen(format_data)); + close(i); + + i = open(data, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, 0666); + write(i, data_data, 256 * sizeof(uint16_t)); + close(i); + + /* compress */ + snprintf(command, 4096, "%s -f %s > /dev/null", XZ, data); + if (gd_system(command)) + return 1; + +#ifdef USE_LZMA + D = gd_open(filedir, GD_RDONLY | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDONLY); +#endif + n = gd_nframes(D); + error = gd_error(D); + gd_discard(D); + + unlink(xzdata); + unlink(format); + rmdir(filedir); + +#ifdef USE_LZMA + CHECKI(error,0); + CHECKI(n,256); +#else + CHECKI(error,GD_E_UNSUPPORTED); + CHECKI(n,0); +#endif + + return r; +#endif +} Added: trunk/getdata/test/lzma_xz_put.c =================================================================== --- trunk/getdata/test/lzma_xz_put.c (rev 0) +++ trunk/getdata/test/lzma_xz_put.c 2014-05-19 19:46:21 UTC (rev 904) @@ -0,0 +1,115 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#ifndef TEST_LZMA + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data_xz = "dirfile/data.xz"; + const char *data = "dirfile/data"; + const char *format_data = "data RAW UINT8 8\n"; + uint8_t c[8]; +#ifdef USE_LZMA + char command[4096]; + uint8_t d; +#endif + struct stat buf; + int fd, i, n, e1, e2, stat_data, unlink_data, unlink_xz, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (i = 0; i < 8; ++i) + c[i] = (uint8_t)(40 + i); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + +#ifdef USE_LZMA + D = gd_open(filedir, GD_RDWR | GD_LZMA_ENCODED | GD_VERBOSE); +#else + D = gd_open(filedir, GD_RDWR | GD_LZMA_ENCODED); +#endif + n = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); + e1 = gd_error(D); + + e2 = gd_close(D); + CHECKI(e2, 0); + + stat_data = stat(data_xz, &buf); +#ifdef USE_LZMA + if (stat_data) { + perror("stat"); + } + CHECKI(stat_data, 0); +#else + CHECKI(stat_data, -1); +#endif + +#ifdef USE_LZMA + /* uncompress */ + snprintf(command, 4096, "%s --decompress -f %s > /dev/null", XZ, data_xz); + if (gd_system(command)) { + r = 1; + } else { + fd = open(data, O_RDONLY | O_BINARY); + if (fd >= 0) { + i = 0; + while (read(fd, &d, sizeof(uint8_t))) { + if (i < 40 || i > 48) { + CHECKIi(i, d, 0); + } else + CHECKIi(i, d, i); + i++; + } + CHECKI(i, 48); + close(fd); + } + } +#endif + + unlink_xz = unlink(data_xz); + CHECKI(unlink_xz, -1); + + unlink_data = unlink(data); + unlink(format); + rmdir(filedir); + +#ifdef USE_LZMA + CHECKI(unlink_data, 0); + CHECKI(e1, GD_E_OK); + CHECKI(n, 8); +#else + CHECKI(unlink_data, -1); + CHECKI(e1, GD_E_UNSUPPORTED); + CHECKI(n, 0); +#endif + + return r; +#endif +} Added: trunk/getdata/test/lzma_xz_put_back.c =================================================================== --- trunk/getdata/test/lzma_xz_put_back.c (rev 0) +++ trunk/getdata/test/lzma_xz_put_back.c 2014-05-19 19:46:21 UTC (rev 904) @@ -0,0 +1,101 @@ +/* Copyright (C) 2014 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of the GetData project. + * + * GetData is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your + * option) any later version. + * + * GetData is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with GetData; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "test.h" + +int main(void) +{ +#if ! (defined TEST_LZMA) || ! (defined USE_LZMA) + return 77; +#else + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data_xz = "dirfile/data.xz"; + const char *data = "dirfile/data"; + const char *format_data = "data RAW UINT8 8\n"; + uint8_t c[8]; + char command[4096]; + uint8_t d; + struct stat buf; + int fd, i, n1, n2, e1, e2, e3, stat_data, unlink_data, r = 0; + DIRFILE *D; + + memset(c, 0, 8); + rmdirfile(); + mkdir(filedir, 0777); + + for (i = 0; i < 8; ++i) + c[i] = (uint8_t)(40 + i); + + fd = open(format, O_CREAT | O_EXCL | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + D = gd_open(filedir, GD_RDWR | GD_LZMA_ENCODED | GD_VERBOSE); + n1 = gd_putdata(D, "data", 5, 0, 1, 0, GD_UINT8, c); + e1 = gd_error(D); + CHECKI(e1, GD_E_OK); + CHECKI(n1, 8); + + n2 = gd_putdata(D, "data", 0, 0, 1, 0, GD_UINT8, c); + e2 = gd_error(D); + CHECKI(e2, GD_E_OK); + CHECKI(n2, 8); + + e3 = ... [truncated message content] |