[Getdata-commits] SF.net SVN: getdata:[875] trunk/getdata
Scientific Database Format
Brought to you by:
ketiltrout
|
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.
|