[Getdata-commits] SF.net SVN: getdata:[756] trunk/defile
Scientific Database Format
Brought to you by:
ketiltrout
|
From: <ket...@us...> - 2012-08-13 23:22:53
|
Revision: 756
http://getdata.svn.sourceforge.net/getdata/?rev=756&view=rev
Author: ketiltrout
Date: 2012-08-13 23:22:42 +0000 (Mon, 13 Aug 2012)
Log Message:
-----------
Get dirfile plugin working.
Modified Paths:
--------------
trunk/defile/bin/cli.c
trunk/defile/configure.ac
trunk/defile/doc/Makefile.am
trunk/defile/doc/defile-input.7
trunk/defile/doc/df_add_alias.3
trunk/defile/doc/df_add_entry.3
trunk/defile/doc/df_add_framedef.3
trunk/defile/doc/df_init.3
trunk/defile/doc/df_nframes_allowed.3
trunk/defile/doc/df_offset.3
trunk/defile/doc/df_push_frame.3
trunk/defile/doc/df_set_const.3
trunk/defile/input/dirfile.c
trunk/defile/lib/defile.h
trunk/defile/lib/internal.h
trunk/defile/lib/libdefile.c
trunk/defile/test/make.c
trunk/defile/test/make.h
Added Paths:
-----------
trunk/defile/doc/df_add_fragment.3
trunk/defile/doc/df_add_lut.3
trunk/defile/doc/df_copy_file.3
trunk/defile/doc/df_hide.3
trunk/defile/doc/df_include.3
trunk/defile/doc/df_subset_contains.3
trunk/defile/doc/df_subset_init.3
trunk/defile/doc/df_subset_reset.3
trunk/defile/doc/df_subset_update.3
Removed Paths:
-------------
trunk/defile/doc/df_bsearch.3
Modified: trunk/defile/bin/cli.c
===================================================================
--- trunk/defile/bin/cli.c 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/bin/cli.c 2012-08-13 23:22:42 UTC (rev 756)
@@ -77,9 +77,9 @@
"The list of defile\noptions and the list of input options are separated " \
"by a double dash (--) to\ndistinguish them. If no input options are " \
"needed, this section, including the\ndouble dash, may be omitted.\n\n" \
-"The first bare argument (i.e. the first argument not associated with " \
+"The first bare argument (i.e. the first argument not associated with " \
"an option)\nbefore the double dash, if present, is taken to be INPUT. " \
-"If INPUT starts with\na dash (and would, therefore, be interpreted as " \
+"If INPUT starts with\n- or + (and would, therefore, be interpreted as " \
"an option), the --input= defile\noption can be used to specify it " \
"instead (see below).\n\n" \
"Defile options are listed below. For help with input options, which " \
@@ -487,44 +487,6 @@
return -1;
}
-static int DF_UpdateOFL(const char *name, int incl)
-{
- int is_new = 0, r;
-
- /* the type of the OFL may be changed when nothing is in it */
- if (df->nofl == 0)
- df->ofl_incl = incl;
-
- /* find the location */
- r = df_bsearch(name, df->ofl, 0, df->nofl - 1, sizeof(char*), &is_new,
- df_strcmp);
-
- if (df->ofl_incl == incl) {
- if (is_new) {
- /* insert */
- if (df->nofl + 1 > df->ofl_size)
- df->ofl = DF_Embiggen(df->ofl, sizeof(char*) * (++df->ofl_size));
- memmove(df->ofl + r + 1, df->ofl + r, sizeof(char*) * (df->nofl++ - r));
- df->ofl[r] = strdup(name);
- if (df->ofl[r] == NULL) {
- perror("malloc");
- exit(1);
- }
- }
- } else {
- if (!is_new) {
- /* remove */
- free(df->ofl[r]);
- memmove(df->ofl + r, df->ofl + r + 1, sizeof(char*) * (df->nofl-- - r));
- /* an empty OFL always means write everything */
- if (df->nofl == 0)
- df->ofl_incl = 0;
- }
- }
-
- return 0;
-}
-
enum {
DF_WOPT_ADD = 1, DF_WOPT_APPEND, DF_WOPT_ASYNC, DF_WOPT_AUTOTYPE,
DF_WOPT_BHEAD, DF_WOPT_BLEN, DF_WOPT_CLOBBER, DF_WOPT_CUTDIR, DF_WOPT_DEBUG,
@@ -538,7 +500,6 @@
static int DF_OutputOpt(struct df_defile *df, struct df_rc_config *config,
struct df_rc_data *rcd)
{
- int i;
struct df_fwk_list l;
if (df->mode_switch == 1) {
@@ -570,16 +531,17 @@
df->mode_switch = 1;
break;
case DF_WOPT_ADD: /* -F */
- DF_UpdateOFL(config->argument, 1);
+ if (df_subset_update(df->ofl, config->argument,
+ strlen(config->argument) + 1, DF_SUBSET_ADD))
+ exit(1);
break;
case DF_WOPT_DEL: /* +F */
- DF_UpdateOFL(config->argument, 0);
+ if (df_subset_update(df->ofl, config->argument,
+ strlen(config->argument) + 1, DF_SUBSET_DEL))
+ exit(0);
break;
case DF_WOPT_OFLCLR: /* --reset-field-list */
- for (i = 0; i < df->nofl; ++i)
- free(df->ofl[i]);
- df->nofl = 0;
- df->ofl_incl = 0;
+ df_subset_reset(df->ofl, DF_SUBSET_INIT);
break;
case DF_WOPT_INPUT: /* -i */
if (df->input == NULL) {
@@ -1159,9 +1121,7 @@
{
int i;
- for (i = 0; i < df->nofl; ++i)
- free(df->ofl[i]);
- free(df->ofl);
+ df_subset_delete(df->ofl);
for (i = 1; i < df->iargc; ++i)
free(df->iargv[i]);
@@ -1213,10 +1173,10 @@
{ DF_WOPT_NOCLOBBER, DF_OPT_NO_ARG, 0, "no-clobber", "NoClobber", 0, NULL,
"don't overwrite an existing dirfile (default)"
},
- { DF_WOPT_CUTDIR, DF_OPT_ARG_RQ, '0', "cut-dirs", "CutDirs", 0, "NUM",
+ { DF_WOPT_CUTDIR, DF_OPT_ARG_RQ, 0, "cut-dirs", "CutDirs", 0, "NUM",
"remove all but the last NUM path elements from the output name"
},
- { DF_WOPT_NOCUTDIR, DF_OPT_NO_ARG, '0', "no-cut-dirs", "NpCutDirs", 0, NULL,
+ { DF_WOPT_NOCUTDIR, DF_OPT_NO_ARG, 0, "no-cut-dirs", "NpCutDirs", 0, NULL,
"don't remove path elements from the output name (default)"
},
{ DF_WOPT_DIR, DF_OPT_ARG_RQ, 'D', "directory", "Directory", DF_OPT_EXPAND,
@@ -1320,6 +1280,10 @@
lt_dlinit();
atexit(DF_ShutdownLTDL);
+ /* initialise and parse command line */
+ df->ofl = df_subset_init(DF_SUBSET_FULL, df_subset_strcmp);
+ if (df->ofl == NULL)
+ exit(1);
DF_Parse(argc, argv, &rcd, df);
/* sanitise */
Modified: trunk/defile/configure.ac
===================================================================
--- trunk/defile/configure.ac 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/configure.ac 2012-08-13 23:22:42 UTC (rev 756)
@@ -151,10 +151,18 @@
AC_CHECK_TYPES([_Complex float, _Complex double])
+dnl Declare a few feature test macros
+AC_DEFINE([_GNU_SOURCE], [1], [ Expose GNU extensions ])
+AC_DEFINE([_BSD_SOURCE], [1], [ Expose BSD-derived definitions ])
+AC_DEFINE([_SVID_SOURCE], [1], [ Expose System V-derived definitions ])
+AC_DEFINE([_POSIX_SOURCE], [1], [ Expose POSIX.1-1990 conforming definitions ])
+AC_DEFINE([_POSIX_C_SOURCE], [200809L],
+ [ Expose POSIX:2008 conforming definitions ])
+
echo
echo "*** Looking for additional library functions"
echo
-AC_CHECK_FUNCS([pipe wordexp])
+AC_CHECK_FUNCS([canonicalize_file_name realpath wordexp])
echo
echo "*** Looking for external programs"
Modified: trunk/defile/doc/Makefile.am
===================================================================
--- trunk/defile/doc/Makefile.am 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/doc/Makefile.am 2012-08-13 23:22:42 UTC (rev 756)
@@ -20,10 +20,36 @@
#
AUTOMAKE_OPTIONS = foreign
-BUILT_SOURCES=defile.1
+nodist_man_MANS = defile.1
man_MANS = defile.1 defile-input.7 df_add_alias.3 df_add_entry.3 \
- df_add_framedef.3 df_bsearch.3 df_check_abort.3 df_field_in_input.3 \
+ df_add_fragment.3 df_add_framedef.3 df_add_lut.3 df_check_abort.3 \
+ df_copy_file.3 df_field_in_input.3 df_hide.3 df_include.3 \
df_init.3 df_input_name.3 df_mode.3 df_nframes_allowed.3 \
df_offset.3 df_on_abort.3 df_push_frame.3 df_ready.3 \
- df_set_const.3 df_shell_expand.3
+ df_set_const.3 df_shell_expand.3 df_subset_contains.3 \
+ df_subset_init.3 df_subset_reset.3 df_subset_update.3
+
+# these are real_file:alias
+MAN3ALIASES=df_add_entry.3:df_add_spec \
+ df_init.3:df_reinit.3 \
+ df_set_const:df_set_carray df_set_const:df_set_string \
+ df_subset_init:df_subset_delete df_subset_init:df_subset_strcmp
+
+
+install-data-hook:
+ cd $(DESTDIR)$(mandir)/man3 && \
+ for m in $(MAN3ALIASES); do \
+ rm -f `echo $$m | $(SED) -e 's/.*://'`; \
+ $(LN_S) `echo $$m | $(SED) -e 's/:/ /'`; \
+ done
+
+uninstall-hook:
+ cd $(DESTDIR)$(mandir)/man3 && \
+ for m in $(MAN3ALIASES); do \
+ rm -f `echo $$m | $(SED) -e 's/.*://'`; \
+ done
+
+clean-local:
+ rm -f *~
+ rm -f $(nodist_man_MANS)
Modified: trunk/defile/doc/defile-input.7
===================================================================
--- trunk/defile/doc/defile-input.7 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/doc/defile-input.7 2012-08-13 23:22:42 UTC (rev 756)
@@ -394,7 +394,7 @@
occur in separate threads within defile. To achieve synchronisation between
input and output, defile operates in one of several states while converting
data. During any particular state of operation, the input plugin is restricted
-to a certain subset of the defile input API. A consice list of functions
+to a certain subset of the defile input API. A concise list of functions
available in each state is provided below in the
.B API REFERNCE
section. We now discuss basic operation of defile.
@@ -406,8 +406,8 @@
.BR ABORT .
The input plugin's role in each state is discussed below.
-The input plugin may return at any time, if it's job is complete (or if it ran
-into an unrecoverable error). Returning a value of zero indicates to defile
+The input plugin may return at any time if it's job is complete, or if it ran
+into an unrecoverable error. Returning a value of zero indicates to defile
that the input plugin completed normally (success). Returning any other value
indicates that the input plugin encountered an unrecoverable error (failure).
@@ -566,7 +566,9 @@
interrupt). Most of the input plugin API functions check whether defile has
entered this state and return
.B DF_ABORT
-when detected. The input should monitor the return value of these functions to
+when detected (see
+.BR "Standard API Return Semaphores" ).
+The input should monitor the return value of these functions to
detect an unexpected transition into the
.B ABORT
state.
@@ -664,6 +666,50 @@
disable cancelability for long periods of time may be subject to more drastic
measures without forewarning.
+.SS Standard API Return Semaphores
+
+Many API functions return a standard
+.I int
+semaphore indicating success or failure of the operation. The standard return
+semaphore values are:
+.TP
+.B DF_SUCCESS \fR(=0)
+The operation completed successfully. (Some functions return a non-negative
+number on success instead.)
+.TP
+.B DF_ABORT
+A catastrophic error occurred. See
+.BR "ABORT state" .
+If an abort handler is registered by the plugin (using
+.BR df_on_abort (3))
+this value will never be returned, and the function simply does not return.
+.TP
+.B DF_SYSTEM
+A system error (usually a memory allocation error) occurred. The input plugin
+may try the call again, although the same error may result.
+.TP
+.B DF_SEQUENCE
+A
+.I sequencing error
+occurred: a call was made to a function which is not available in the current
+defile state (see
+.B API REFERENCE
+for a list of functions broken down by state).
+The call should not be repeated until the correct state is achieved.
+.TP
+.B DF_INPUT
+A bad call was made to the API, typically due to passing bad parameter data.
+The call should not be repeated without correction.
+.TP
+.B DF_OUTPUT
+An error occurred manipulating the output dirfile. The input plugin may try the
+call again, although the same error may result.
+.P
+Except for
+.BR DF_SUCCESS ,
+which evaluates to zero, these all have negative values. See the specific
+function manual pages for more details on function return values.
+
.SH AUTOMATIC TYPE DETECTION
If desired, and possible, the plugin may participate in the automatic type
detection system used by defile when an explicit input type is not provided.
Modified: trunk/defile/doc/df_add_alias.3
===================================================================
--- trunk/defile/doc/df_add_alias.3 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/doc/df_add_alias.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -67,7 +67,7 @@
.B DF_SEQUENCE
The function was called while defile was not in the
.B BUILD
-state. (See defile-input (7)).
+state. (See defile-input(7)).
.PP
All errors are accompanied by a message on standard error.
.SH SEE ALSO
Modified: trunk/defile/doc/df_add_entry.3
===================================================================
--- trunk/defile/doc/df_add_entry.3 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/doc/df_add_entry.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -101,7 +101,7 @@
.B DF_SEQUENCE
The function was called while defile was not in the
.B BUILD
-state. (See defile-input (7)).
+state. (See defile-input(7)).
.PP
All errors are accompanied by a message on standard error.
.SH SEE ALSO
Added: trunk/defile/doc/df_add_fragment.3
===================================================================
--- trunk/defile/doc/df_add_fragment.3 (rev 0)
+++ trunk/defile/doc/df_add_fragment.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -0,0 +1,117 @@
+.\" df_add_fragment.3. The df_add_fragment man page.
+.\"
+.\" Copyright (C) 2012 D. V. Wiebe
+.\"
+.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.\"
+.\" This file is part of the Defile package.
+.\"
+.\" 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 df_add_fragment 3 "13 August 2012" "Version 0.0.0" DEFILE
+.SH NAME
+df_add_fragment \(em create a new fragment in the defile output dirfile
+.SH SYNOPSIS
+.nh
+.ad l
+.fam C
+.B #include <defile.h>
+.HP
+.BI "int df_add_fragment(const char *" name ", int " parent ,
+.BI "unsigned int " encoding ", unsigned long " byte_sex ,
+.BI "const char *" prefix ", const char *" suffix );
+.fam
+.ad
+.hy
+.SH DESCRIPTION
+This function is part of the defile input plugin C API. See defile-input(7) for
+an overview.
+.PP
+The
+.BR df_add_fragment ()
+creates a new format file fragment (see dirfile-format(5)) called
+.I name
+in the defile output dirfile. The
+.I name
+may contain path elements relative to the base output dirfile directory.
+Subdirectories specified in
+.I name
+will be created if they do not already exist. The new fragment will be included
+in the fragment indexed by
+.IR parent ,
+which should be zero (for the primary format file) or else a fragment index
+returned by a previous call to
+.BR df_add_fragment ().
+
+The encoding of data files used in the new fragment is specified with
+.IR encoding ,
+which should be one of the symbols listed in
+.BR gd_alter_encoding (3),
+although not all encodings provide write capability (see dirfile-encoding(5) for
+details). If this is set to
+.BR GD_AUTO_ENCODED ,
+the encoding scheme will be chosen by defile. The byte sex of data files in
+the new fragment is specified with
+.IR byte_sex ,
+which should be one of the values listed in
+.BR gd_alter_endianness (3).
+To use default values for these parameters, set them to zero.
+
+The prefix and suffix of the new fragment may specified by
+.I prefix
+and
+.IR suffix ,
+which may be NULL if the corresponding affix is not needed.
+
+In append mode (see
+.BR df_mode (3)),
+this function only tests for the existence of
+.IR name ,
+and returns an error if it is not found. In that case, all other parameters are
+ignored.
+
+.SH RETURN VALUE
+Upon success,
+.BR df_add_fragment ()
+returns a positive integer fragment index corresponding to the newly created
+fragment. The value should be cached by the caller and used in subsequent calls
+requiring a fragment index. On error, one of the following error values (all
+less than zero) will be returned:
+.TP
+.B DF_ABORT
+Another defile subprocess has requested the input plugin immediately abort.
+Upon receiving this signal the plugin should shutdown and return. If it takes
+too long, defile will cancel it. If an abort handler has been registered (see
+.BR df_on_abort (3)),
+this value is never returned and, instead, this function does not return.
+.TP
+.B DF_OUTPUT
+An error occured attempting to add the fragment to the output dirfile. See
+.BR gd_include_affix (3)
+and
+.BR mkdir (2)
+for possible reasons. Or, defile was in append mode, and the specified
+.I name
+did not exist.
+.TP
+.B DF_SEQUENCE
+The function was called while defile was not in the
+.B BUILD
+state. (See defile-input(7)).
+.TP
+.B DF_SYSTEM
+A memory allocation error occurred.
+.PP
+All errors are accompanied by a message on standard error.
+.SH SEE ALSO
+.PP
+defile-input(7), defile(1),
+.BR df_include (3),
+.BR gd_include_affix (3),
+.BR gd_alter_encoding (3),
+.BR gd_alter_endianness (3)
Modified: trunk/defile/doc/df_add_framedef.3
===================================================================
--- trunk/defile/doc/df_add_framedef.3 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/doc/df_add_framedef.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -1,4 +1,4 @@
-.\" df_add_framdef.3. The df_add_framdef man page.
+.\" df_add_framedef.3. The df_add_framedef man page.
.\"
.\" Copyright (C) 2012 D. V. Wiebe
.\"
@@ -13,9 +13,9 @@
.\" Texts. A copy of the license is included in the `COPYING.DOC' file
.\" as part of this distribution.
.\"
-.TH df_add_framdef 3 "27 February 2012" "Version 0.0.0" DEFILE
+.TH df_add_framedef 3 "27 February 2012" "Version 0.0.0" DEFILE
.SH NAME
-df_add_framdef \(em define a defile input subframe
+df_add_framedef \(em define a defile input subframe
.SH SYNOPSIS
.nh
.ad l
@@ -32,7 +32,7 @@
an overview.
.PP
The
-.BR df_add_framdef ()
+.BR df_add_framedef ()
function defines a defile subframe definition,
.IR fdef ,
and adds
@@ -149,7 +149,7 @@
(see defile(1)) are accepted in subframe definitions and simply ignored.
.SH RETURN VALUE
Upon success,
-.BR df_add_framdef ()
+.BR df_add_framedef ()
returns the assigned index number of this subframe definition, which is always
greater than or equal to zero. This number should be cached by the input plugin
and used in subsequent calls to
@@ -177,7 +177,7 @@
.B DF_SEQUENCE
The function was called while defile was not in the
.B BUILD
-state. (See defile-input (7)).
+state. (See defile-input(7)).
.TP
.B DF_SYSTEM
A memory allocation error occurred.
Added: trunk/defile/doc/df_add_lut.3
===================================================================
--- trunk/defile/doc/df_add_lut.3 (rev 0)
+++ trunk/defile/doc/df_add_lut.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -0,0 +1,116 @@
+.\" df_add_lut.3. The df_add_lut man page.
+.\"
+.\" Copyright (C) 2012 D. V. Wiebe
+.\"
+.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.\"
+.\" This file is part of the Defile package.
+.\"
+.\" 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 df_add_lut 3 "13 August 2012" "Version 0.0.0" DEFILE
+.SH NAME
+df_add_lut \(em create a look-up table in the defile output dirfile
+.SH SYNOPSIS
+.nh
+.ad l
+.fam C
+.B #include <defile.h>
+.HP
+.BI "int df_add_lut(const char *" name ", size_t " n ", gd_type_t " x_type ,
+.BI "const void *" x ", gd_type_t " y_type ", const void *" y );
+.fam
+.ad
+.hy
+.SH DESCRIPTION
+This function is part of the defile input plugin C API. See defile-input(7) for
+an overview.
+.PP
+The
+.BR df_add_lut ()
+creates a dirfile-compatible LINTERP look-up table (LUT) called
+.I name
+in the defile output dirfile from the supplied data. The
+.I name
+may contain path elements relative to the base output dirfile directory.
+Subdirectories specified in
+.I name
+will be created if they do not already exist.
+
+The data for the LUT are given in the arrays pointed to by
+.I x
+and
+.I y .
+The data types of the two arrays are given by
+.I x_type
+and
+.IR y_type ,
+which should be one of the GetData data type symbols (see
+.BR gd_add_raw (3)),
+with the further restriction that the
+.I x
+data type may not be complex valued.
+
+In append mode (see
+.BR df_mode (3)),
+this function only tests for the existence of
+.IR name ,
+and returns an error if it is not found. In that case, all other parameters are
+ignored.
+
+This function does not add any references to the created file to the output
+dirfile.
+
+.SH RETURN VALUE
+Upon success,
+.BR df_add_lut ()
+returns
+.B DF_SUCCESS
+(=0). On error, one of the following error values (all less than zero) will be
+returned:
+.TP
+.B DF_ABORT
+Another defile subprocess has requested the input plugin immediately abort.
+Upon receiving this signal the plugin should shutdown and return. If it takes
+too long, defile will cancel it. If an abort handler has been registered (see
+.BR df_on_abort (3)),
+this value is never returned and, instead, this function does not return.
+.TP
+.B DF_INPUT
+The value of
+.I x_type
+or
+.I y_type
+was invalid.
+.B DF_OUTPUT
+An error occured attempting to create the LUT. See
+.BR mkdir (2),
+.BR open (2),
+.BR fcntl (2),
+.BR fclose (3),
+.BR fprintf (3),
+and
+.BR fputc (3)
+for possible reasons. Or, defile was in append mode, and the specified
+.I name
+did not exist.
+.TP
+.TP
+.B DF_SEQUENCE
+The function was called while defile was not in the
+.B BUILD
+state. (See defile-input(7)).
+.TP
+.B DF_SYSTEM
+A memory allocation error occurred.
+.PP
+All errors are accompanied by a message on standard error.
+.SH SEE ALSO
+.PP
+defile-input(7), defile(1), dirfile-format(5),
+.BR df_copy_file (3)
Deleted: trunk/defile/doc/df_bsearch.3
===================================================================
--- trunk/defile/doc/df_bsearch.3 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/doc/df_bsearch.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -1,164 +0,0 @@
-.\" df_bsearch.3. The df_bsearch man page.
-.\"
-.\" Copyright (C) 2012 D. V. Wiebe
-.\"
-.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
-.\"
-.\" This file is part of the Defile package.
-.\"
-.\" 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 df_bsearch 3 "27 February 2012" "Version 0.0.0" DEFILE
-.SH NAME
-df_bsearch, df_strcmp \(em perform a binary search within defile
-.SH SYNOPSIS
-.nh
-.ad l
-.fam C
-.B #include <defile.h>
-.HP
-.BI "int df_bsearch(const void *" needle ", const void *" haystack ,
-.BI "int " start ", int " end ", size_t " size ", int *" is_new ,
-.BI "int (*" compar ")(const void*, const void*));
-.HP
-.BI "int df_strcmp(const void *" needle ", const void *" candidate );
-.fam
-.ad
-.hy
-.SH DESCRIPTION
-These functions are part of the defile input plugin C API. See defile-input(7)
-for an overview.
-.PP
-The
-.BR df_bsearch ()
-function performs a binary search on a subset of the array
-.IR haystack ,
-which has elements of size
-.I size
-bytes, looking for the element
-.IR needle ,
-using the comparison function
-.IR compar .
-The first element considered is indexed by
-.I start
-and the last element considered is immediately before the element indexed by
-.IR end .
-(In other words, to search the entirety of a
-.IR n -element
-.IR haystack ,
-set
-.I start
-to zero and
-.I end
-to
-.IR n .)
-.P
-If
-.I needle
-is not found,
-.BI * is_new
-is set to one and the index where it would be, were it in the array, is
-returned.
-If
-.I needle
-is found in
-.IR haystack ,
-its index is returned, and
-.BI * is_new
-is left untouched (so the caller should zero it beforehand, if necessary). This
-function is similar to
-.BR bsearch (3),
-but behaves differently in the case where
-.I needle
-is not in
-.IR haystack .
-It is designed for use during an insertion sort.
-.PP
-The function pointed to by
-.I compar
-will be called to compare elements of
-.I haystack
-to
-.IR needle .
-The first argument passed to
-.I compar
-is always
-.IR needle ;
-the second argument will be a pointer to the candidate array element.
-.PP
-The
-.BR df_strcmp ()
-function is provided as a potential
-.I compar
-function, useable when
-.I haystack
-is an array of character strings. The call
-.RS
-.HP
-.nh
-.ad l
-.fam C
-.BI df_strcmp( a ", " b )
-.fam
-.ad
-.hy
-.RE
-.PP
-is equivalent to the
-.BR strcmp (3)
-call:
-.RS
-.HP
-.nh
-.ad l
-.fam C
-.BI "strcmp((const char*)" a ", *(const char**)" b ")\fR.
-.fam
-.ad
-.hy
-.RE
-.PP
-(ie. it derefences its second parameter).
-.PP
-These functions are used internally by defile(1) and are simply exported to the
-defile C API as a convenience to input plugin authors. Error checking is
-minimal: out of range
-.I start
-or
-.I end
-values may cause segmentation faults. No restriction is placed on when this
-function may be called in an input plugin.
-.SH RETURN VALUE
-The
-.BR df_bsearch ()
-function returns the location of
-.I needle
-in
-.IR haystack ,
-if found, or the element in which to insert
-.I needle
-if not found. Note: while the returned value will be strictly less than
-.I end
-if found, if not found,
-.I end
-may be returned (indicating that
-.I needle
-should be appended to
-.IR haystack .
-.PP
-The
-.BR df_strcmp ()
-function returns a number with the same meaning as the return value of
-.BR strcmp (3),
-as indicated in the
-.B DISCUSSION
-section above.
-.SH SEE ALSO
-defile-input(7),
-.BR bsearch (3),
-.BR strcmp (3).
Added: trunk/defile/doc/df_copy_file.3
===================================================================
--- trunk/defile/doc/df_copy_file.3 (rev 0)
+++ trunk/defile/doc/df_copy_file.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -0,0 +1,100 @@
+.\" df_add_lut.3. The df_add_lut man page.
+.\"
+.\" Copyright (C) 2012 D. V. Wiebe
+.\"
+.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.\"
+.\" This file is part of the Defile package.
+.\"
+.\" 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 df_copy_file 3 "13 August 2012" "Version 0.0.0" DEFILE
+.SH NAME
+df_add_lut \(em create a file in the defile output dirfile
+.SH SYNOPSIS
+.nh
+.ad l
+.fam C
+.B #include <defile.h>
+.HP
+.BI "int df_copy_file(const char *" name ", int " fd );
+.fam
+.ad
+.hy
+.SH DESCRIPTION
+This function is part of the defile input plugin C API. See defile-input(7) for
+an overview.
+.PP
+The
+.BR df_copy_file ()
+creates a new file called
+.I name
+in the defile output dirfile and copyies the contents of the open file
+referenced by the file descriptor
+.I fd
+to it. The
+.I name
+may contain path elements relative to the base output dirfile directory.
+Subdirectories specified in
+.I name
+will be created if they do not already exist.
+
+In append mode (see
+.BR df_mode (3)),
+this function only tests for the existence of
+.IR name ,
+and returns an error if it is not found. In that case, all other parameters are
+ignored.
+
+This function does not add any references to the created file to the output
+dirfile.
+
+.SH RETURN VALUE
+Upon success,
+.BR df_copy_file ()
+returns
+.B DF_SUCCESS
+(=0). On error, one of the following error values (all less than zero) will be
+returned:
+.TP
+.B DF_ABORT
+Another defile subprocess has requested the input plugin immediately abort.
+Upon receiving this signal the plugin should shutdown and return. If it takes
+too long, defile will cancel it. If an abort handler has been registered (see
+.BR df_on_abort (3)),
+this value is never returned and, instead, this function does not return.
+.TP
+.B DF_OUTPUT
+An error occured attempting to create the file. See
+.BR mkdir (2),
+.BR open (2),
+.BR read (2),
+.BR write (2),
+and
+.BR close (2)
+for possible reasons. Or, defile was in append mode, and the specified
+.I name
+did not exist.
+.TP
+.B DF_SEQUENCE
+The function was called while defile was not in the
+.B BUILD
+state. (See defile-input(7)).
+.TP
+.B DF_SYSTEM
+A memory allocation error occurred.
+.PP
+All errors are accompanied by a message on standard error.
+.SH NOTES
+Don't use this function to create raw data files. (The desire to do so is
+often an indication that your input plugin doesn't really need to be using
+defile at all.)
+.SH SEE ALSO
+.PP
+defile-input(7), defile(1), dirfile-format(5),
+.BR df_add_lut (3)
Added: trunk/defile/doc/df_hide.3
===================================================================
--- trunk/defile/doc/df_hide.3 (rev 0)
+++ trunk/defile/doc/df_hide.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -0,0 +1,82 @@
+.\" df_hide.3. The df_hide man page.
+.\"
+.\" Copyright (C) 2012 D. V. Wiebe
+.\"
+.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.\"
+.\" This file is part of the Defile package.
+.\"
+.\" 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 df_hide 3 "21 July 2012" "Version 0.0.0" DEFILE
+.SH NAME
+df_hide \(em hide a field in the defile output dirfile
+.SH SYNOPSIS
+.nh
+.ad l
+.fam C
+.B #include <defile.h>
+.HP
+.BI "int df_hide(const char *" name );
+.fam
+.ad
+.hy
+.SH DESCRIPTION
+This function is part of the defile input plugin C API. See defile-input(7) for
+an overview.
+.PP
+The
+.BR df_hide ()
+hides the field or alias called
+.I name
+in the output dirfile. The field must have been previously added to the
+output dirfile using
+.B df_add_alias (3),
+.B df_add_framedef (3),
+.B df_add_entry (3),
+or
+.B df_add_spec (3).
+.PP
+If the field has been excluded from the output dirfile by the Output Field List
+(see defile(1)), this functions does nothing and succeeds.
+
+If defile is in append mode (see
+.BR df_mode (3)),
+this function simply checks whether the specified field is hidden in the
+output dirfile and returns an error if it is not.
+.SH RETURN VALUE
+Upon success,
+.BR df_hide ()
+returns
+.B DF_SUCCESS
+(=0). On error the field is not hidden, and one of the following error values
+(all less than zero) will be returned:
+.TP
+.B DF_ABORT
+Another defile subprocess has requested the input plugin immediately abort.
+Upon receiving this signal the plugin should shutdown and return. If it takes
+too long, defile will cancel it. If an abort handler has been registered (see
+.BR df_on_abort (3)),
+this value is never returned and, instead, this function does not return.
+.TP
+.B DF_OUTPUT
+An error occured attempting to hide the field. See
+.BR gd_hide (3)
+for possible reasons. Or, defile was in append mode and the specified field
+wasn't already hidden.
+.TP
+.B DF_SEQUENCE
+The function was called while defile was not in the
+.B BUILD
+state. (See defile-input(7)).
+.PP
+All errors are accompanied by a message on standard error.
+.SH SEE ALSO
+.PP
+defile-input(7), defile(1),
+.BR gd_hide (3)
Added: trunk/defile/doc/df_include.3
===================================================================
--- trunk/defile/doc/df_include.3 (rev 0)
+++ trunk/defile/doc/df_include.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -0,0 +1,96 @@
+.\" df_include.3. The df_include man page.
+.\"
+.\" Copyright (C) 2012 D. V. Wiebe
+.\"
+.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.\"
+.\" This file is part of the Defile package.
+.\"
+.\" 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 df_include 3 "13 August 2012" "Version 0.0.0" DEFILE
+.SH NAME
+df_include \(em include an existing fragment in the defile output dirfile
+.SH SYNOPSIS
+.nh
+.ad l
+.fam C
+.B #include <defile.h>
+.HP
+.BI "int df_include(const char *" filename ", int " parent ,
+.BI "const char *" prefix ", const char *" suffix );
+.fam
+.ad
+.hy
+.SH DESCRIPTION
+This function is part of the defile input plugin C API. See defile-input(7) for
+an overview.
+.PP
+The
+.BR df_include ()
+inserts an
+.B /INCLUDE
+directive (see dirfile-format(5)) into the output dirfile fragment indexed by
+.IR parent ,
+which should be zero (for the primary format file) or else a fragment index
+returned by a previous call to
+.BR df_add_fragment (3).
+The included fragment is given by
+.IR filename .
+The the prefix and suffix for the inclusion are given by
+.I prefix
+and
+.IR suffix ,
+which may be NULL, if no corresponding affix is needed.
+
+The fragment specified by
+.I filename
+must already exist. (Use
+.BR gd_add_fragment (3)
+to create a new fragment.)
+
+In append mode (see
+.BR df_mode (3)),
+this function only tests whether the specified fragment is present in the
+output dirfile. In that case, all other parameters are ignored.
+
+.SH RETURN VALUE
+Upon success,
+.BR df_include ()
+returns
+.B DF_SUCCESS
+(=0). On error, one of the following error values (all less than zero) will be
+returned:
+.TP
+.B DF_ABORT
+Another defile subprocess has requested the input plugin immediately abort.
+Upon receiving this signal the plugin should shutdown and return. If it takes
+too long, defile will cancel it. If an abort handler has been registered (see
+.BR df_on_abort (3)),
+this value is never returned and, instead, this function does not return.
+.TP
+.B DF_OUTPUT
+An error occured attempting to add the fragment to the output dirfile. See
+.BR gd_include_affix (3)
+for possible reasons. Or defile was in append mode and the specified fragment
+wasn't in the output dirfile.
+.TP
+.B DF_SEQUENCE
+The function was called while defile was not in the
+.B BUILD
+state. (See defile-input(7)).
+.TP
+.B DF_SYSTEM
+A memory allocation error occurred.
+.PP
+All errors are accompanied by a message on standard error.
+.SH SEE ALSO
+.PP
+defile-input(7), defile(1),
+.BR df_add_fragment (3),
+.BR gd_include_affix (3)
Modified: trunk/defile/doc/df_init.3
===================================================================
--- trunk/defile/doc/df_init.3 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/doc/df_init.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -43,7 +43,7 @@
.TP
.I nframes
the total length, in frames, of the input data. In follow mode (see
-defile-input (7)) this is ignored. If the total length is unknown or difficult
+defile-input(7)) this is ignored. If the total length is unknown or difficult
to calculate, this should be zero. This is only used for informational purposes
to the user; the input plugin may provide a different number of frames than
specified here without error.
@@ -66,7 +66,7 @@
specified here.
.TP
.I rate
-the expected frame rate for live data in follow mode (see defile-input (7)). If
+the expected frame rate for live data in follow mode (see defile-input(7)). If
unknown or difficult to calculate, this may be -1. This value is used to prime
the IIR filter in the rate calculator in the running information provided to the
user, and does not set actual restictions on the data rate. In no-follow mode,
Modified: trunk/defile/doc/df_nframes_allowed.3
===================================================================
--- trunk/defile/doc/df_nframes_allowed.3 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/doc/df_nframes_allowed.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -86,7 +86,7 @@
.B DF_SEQUENCE
The function was called while defile was not in the
.B RUN
-state. (See defile-input (7)).
+state. (See defile-input(7)).
.PP
All errors are accompanied by a message on standard error.
.SH SEE ALSO
Modified: trunk/defile/doc/df_offset.3
===================================================================
--- trunk/defile/doc/df_offset.3 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/doc/df_offset.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -77,7 +77,7 @@
.B BUILD
nor
.B RUN
-states. (See defile-input (7)).
+states. (See defile-input(7)).
.SH SEE ALSO
defile(1), defile-input(7),
.BR df_init (3),
Modified: trunk/defile/doc/df_push_frame.3
===================================================================
--- trunk/defile/doc/df_push_frame.3 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/doc/df_push_frame.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -87,7 +87,7 @@
.B DF_SEQUENCE
The function was called while defile was not in the
.B RUN
-state. (See defile-input (7)).
+state. (See defile-input(7)).
.PP
All errors are accompanied by a message on standard error.
.SH SEE ALSO
Modified: trunk/defile/doc/df_set_const.3
===================================================================
--- trunk/defile/doc/df_set_const.3 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/doc/df_set_const.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -125,7 +125,7 @@
.B BUILD
nor
.B RUN
-states. (See defile-input (7)).
+states. (See defile-input(7)).
.PP
All errors are accompanied by a message on standard error.
.SH SEE ALSO
Added: trunk/defile/doc/df_subset_contains.3
===================================================================
--- trunk/defile/doc/df_subset_contains.3 (rev 0)
+++ trunk/defile/doc/df_subset_contains.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -0,0 +1,55 @@
+.\" df_subset_contains.3. The df_subset_contains man page.
+.\"
+.\" Copyright (C) 2012 D. V. Wiebe
+.\"
+.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.\"
+.\" This file is part of the Defile package.
+.\"
+.\" 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 df_subset_contains 3 "10 August 2012" "Version 0.0.0" DEFILE
+.SH NAME
+df_subset_contains \(em modify a defile subset object
+.SH SYNOPSIS
+.nh
+.ad l
+.fam C
+.B #include <defile.h>
+.HP
+.BI "int df_subset_contains(df_subset *" subset ", const void *" value );
+.fam
+.ad
+.hy
+.SH DESCRIPTION
+This function is part of the defile input plugin C API. See defile-input(7)
+for an overview.
+.PP
+The
+.BR df_subset_contains ()
+returns a non-zero value if the df_subset object
+.I subset
+contains the item
+.IR value.
+The item
+.I value
+is assumed to be a member of the containing superset.
+.PP
+No restriction is placed on when this function may be called in an input plugin.
+.SH RETURN VALUE
+If
+.I value
+is contained in
+.IR subset ,
+a non-zero number is returned. Otherwise zero is returned.
+.SH SEE ALSO
+defile-input(7),
+.BR df_subset_delete (3),
+.BR df_subset_init (3),
+.BR df_subset_reset (3),
+.BR df_subset_update (3).
Added: trunk/defile/doc/df_subset_init.3
===================================================================
--- trunk/defile/doc/df_subset_init.3 (rev 0)
+++ trunk/defile/doc/df_subset_init.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -0,0 +1,137 @@
+.\" df_subset_init.3. The df_subset_init man page.
+.\"
+.\" Copyright (C) 2012 D. V. Wiebe
+.\"
+.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.\"
+.\" This file is part of the Defile package.
+.\"
+.\" 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 df_subset_init 3 "10 August 2012" "Version 0.0.0" DEFILE
+.SH NAME
+df_subset_init, df_subset_delete, df_subset_strcmp \(em initialise or delete a
+defile subset object
+.SH SYNOPSIS
+.nh
+.ad l
+.fam C
+.B #include <defile.h>
+.HP
+.BI "df_subset *df_subset_init(int " init ,
+.BI "int (*" compar ")(const void*, const void*));
+.HP
+.BI "void df_subset_delete(df_subset *" subset );
+.HP
+.BI "int df_subset_strcmp(const void *" candidate ", const void **" item );
+.fam
+.ad
+.hy
+.SH DESCRIPTION
+These functions are part of the defile input plugin C API. See defile-input(7)
+for an overview.
+.PP
+The
+.BR df_subset_init ()
+initialises a defile df_subset object, returning a pointer to the new object.
+The df_subset object represents a set of items which are part of a larger
+containing superset, without knowing the contents of the superset. The subset
+is built up by including or excluding specific elements from the subset (see
+.BR df_subset_update (3)).
+
+The defile Output Field List (see defile(1)) is an example of such a data
+object.
+
+The initial contents of the df_subset is given by
+.I init
+which should be either
+.BR DF_SUBSET_EMPTY ,
+indicating the set is initially the empty set, or else
+.BR DF_SUBSET_FULL ,
+indicating that the set is initially equal to the containing subset (but see
+.BR df_subset_update (3)
+for special handling of the initial subset).
+
+A comparison function
+.I compar
+must be specified which takes two pointers:
+.IR candidate ,
+which points to an item against which to compare, and
+.IR item ,
+is
+.I a pointer to
+a pointer to an object in the subset. The comparison function should return a
+number less than, equal to, or greater than zero if
+.I candidate
+is, respectively, lexically before, equal to, or after
+.BI * item\fR.
+
+The
+.BR df_subset_delete ()
+function deallocates a df_subset object previously created by a call to
+.BR df_subset_init ().
+After calling this function, the df_subset object passed to it should be
+considered invalid. If
+.BR df_subset_delete ()
+is passed NULL, it does nothing.
+
+The
+.BR df_subset_strcmp ()
+function is provided as a potential
+.I compar
+function, useable when the df_subset contains character strings. The call
+.RS
+.HP
+.nh
+.ad l
+.fam C
+.BI df_subset_strcmp( a ", " b )
+.fam
+.ad
+.hy
+.RE
+.PP
+is equivalent to the
+.BR strcmp (3)
+call:
+.RS
+.HP
+.nh
+.ad l
+.fam C
+.BI "strcmp((const char*)" a ", *(const char**)" b ")\fR.
+.fam
+.ad
+.hy
+.RE
+.PP
+(ie. it derefences its second parameter).
+.PP
+No restriction is placed on when these functions may be called in an input
+plugin.
+.SH RETURN VALUE
+The
+.BR df_subset_init ()
+function returns a pointer to a newly created df_subset object, or NULL if a
+memory allocation error occurred. The
+.BR df_subset_delete ()
+function returns no value.
+.PP
+The
+.BR df_subset_strcmp ()
+function returns a number with the same meaning as the return value of
+.BR strcmp (3),
+as indicated in the
+.B DISCUSSION
+section above.
+.SH SEE ALSO
+defile-input(7),
+.BR df_subset_contains (3),
+.BR df_subset_update (3),
+.BR df_subset_reset (3),
+.BR strcmp (3).
Added: trunk/defile/doc/df_subset_reset.3
===================================================================
--- trunk/defile/doc/df_subset_reset.3 (rev 0)
+++ trunk/defile/doc/df_subset_reset.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -0,0 +1,68 @@
+.\" df_subset_reset.3. The df_subset_reset man page.
+.\"
+.\" Copyright (C) 2012 D. V. Wiebe
+.\"
+.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.\"
+.\" This file is part of the Defile package.
+.\"
+.\" 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 df_subset_reset 3 "10 August 2012" "Version 0.0.0" DEFILE
+.SH NAME
+df_subset_reset \(em reset the contents of a defile subset object
+.SH SYNOPSIS
+.nh
+.ad l
+.fam C
+.B #include <defile.h>
+.HP
+.BI "int df_subset_reset(df_subset *" subset ", int " mode );
+.fam
+.ad
+.hy
+.SH DESCRIPTION
+This function is part of the defile input plugin C API. See defile-input(7)
+for an overview.
+.PP
+The
+.BR df_subset_reset ()
+function re-initialises the defile df_subset object
+.I subset
+according to the
+.I mode
+parameter given which must be one of:
+.TP
+.B DF_SUBSET_FULL
+the df_subset object is reset to contain all elements from it's containing
+superset,
+.TP
+.B DF_SUBSET_EMPTY
+the df_subset object is reset to the empty set,
+.TP
+.B DF_SUBSET_INIT
+the df_subset object is reset to its initial value specified in the call to
+.BR df_subset_init (3).
+.PP
+No restriction is placed on when this function may be called in an input plugin.
+.SH RETURN VALUE
+The
+.BR df_subset_reset ()
+returns
+.BR DF_SUCCESS
+(=0) on success or else
+.BR DF_INPUT
+if the
+.I mode
+parameter is invalid.
+.SH SEE ALSO
+defile-input(7),
+.BR df_subset_contains (3),
+.BR df_subset_delete (3),
+.BR df_subset_init (3),
+.BR df_subset_update (3).
Added: trunk/defile/doc/df_subset_update.3
===================================================================
--- trunk/defile/doc/df_subset_update.3 (rev 0)
+++ trunk/defile/doc/df_subset_update.3 2012-08-13 23:22:42 UTC (rev 756)
@@ -0,0 +1,82 @@
+.\" df_subset_update.3. The df_subset_update man page.
+.\"
+.\" Copyright (C) 2012 D. V. Wiebe
+.\"
+.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+.\"
+.\" This file is part of the Defile package.
+.\"
+.\" 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 df_subset_update 3 "10 August 2012" "Version 0.0.0" DEFILE
+.SH NAME
+df_subset_update \(em modify a defile subset object
+.SH SYNOPSIS
+.nh
+.ad l
+.fam C
+.B #include <defile.h>
+.HP
+.BI "int df_subset_update(df_subset *" subset ", const void *" value ,
+.BI "size_t " len ", int " mode );
+.fam
+.ad
+.hy
+.SH DESCRIPTION
+This function is part of the defile input plugin C API. See defile-input(7)
+for an overview.
+.PP
+The
+.BR df_subset_update ()
+function modifies a df_subset object previously created by a call to
+.BR df_subset_init (3).
+The operation performed is specified by
+.IR mode ,
+which should be either
+.B DF_SUBSET_ADD
+or
+.B DF_SUBSET_DEL
+which indicates insertion or removal of the object
+.I value
+to the subset. This inserted or removed object has a size
+.I len
+bytes. An attempt to remove an object which is not currently in the subset, or
+add one that is, does nothing and succeeds.
+.PP
+A completely full or completely empty df_subset object is treated specially:
+attempting to add an item to a full subset will first cause the subset to be
+emptied. Conversely, removing an object from an empty subset will first cause
+it to be filled completely.
+.PP
+No restriction is placed on when this function may be called in an input plugin.
+.SH RETURN VALUE
+The
+.BR df_subset_update ()
+returns
+.BR DF_SUCCESS
+(=0) on success or else
+.BR DF_SYSTEM
+if a memory allocation error occurred.
+.SH NOTES
+Because the elements of the containing superset are not enumerated, it is not
+possible to completely fill an originally empty subset by successive adds, nor
+empty an originally full one by successive removals. These states may only
+be achieved through
+.BR df_subset_init (),
+or
+.BR df_subset_reset (),
+or by undoing all previous
+.BR df_subset_update ()
+calls since the last time the subset was completely full or empty, and so
+reverting to that state.
+.SH SEE ALSO
+defile-input(7),
+.BR df_subset_contains (3),
+.BR df_subset_delete (3),
+.BR df_subset_init (3),
+.BR df_subset_reset (3).
Modified: trunk/defile/input/dirfile.c
===================================================================
--- trunk/defile/input/dirfile.c 2012-08-04 01:42:13 UTC (rev 755)
+++ trunk/defile/input/dirfile.c 2012-08-13 23:22:42 UTC (rev 756)
@@ -24,9 +24,14 @@
#endif
#include "internal.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <complex.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
+#include <libgen.h>
#include <getdata.h>
#define DIRFILE_COPYRIGHT "Copyright (C) 2012 D. V. Wiebe"
@@ -34,12 +39,22 @@
"Please send reports of bugs and other communication to:\n " PACKAGE_BUGREPORT
#define DIRFILE_DESCRIPTION "dirfile databases"
+#define DIE() do { \
+ fprintf(stderr, "abort in %s @ %s,%i\n", __func__, __FILE__, __LINE__); \
+ df_exit(1,1); \
+} while(0)
+
#define CHUNK_SIZE 65535 /* in bytes, the largest amount of data we're willing
to read in one go */
/* globals */
-static DIRFILE *D;
+static DIRFILE *D = NULL;
+static const char *dirfilename;
+static size_t dirfilename_len;
static unsigned int nraw;
+static int *frag_cnc;
+static char **lut_list = NULL;
+static int n_lut = 0;
static struct dirfile_raw {
char *name;
int index;
@@ -48,8 +63,122 @@
int fpc; /* frames per bufsize */
char *b; /* buffer */
size_t blen; /* current length of data in the buffer in SAMPLES */
+ gd_off64_t pos; /* current position (in samples) */
} *raw;
+static struct {
+ df_subset *expand;
+ int link_ext;
+ int link_lut;
+ int flatten;
+ char *ext_dir;
+ size_t ext_dir_len;
+ char *lut_dir;
+ size_t lut_dir_len;
+} conf;
+
+/* options definition */
+enum {
+ OPT_EXPAND_ALL = 1, OPT_EXPAND_NONE, OPT_EXPAND, OPT_FLATTEN, OPT_DONT_EXPAND,
+ OPT_LINK_LUT, OPT_COPY_LUT, OPT_LINK_EXT, OPT_COPY_EXT, OPT_EXT_DIR,
+ OPT_LUT_DIR, OPT_NO_FLATTEN
+};
+
+static const struct df_optdef opts[] = {
+ { OPT_EXPAND_ALL, DF_OPT_NO_ARG, 'E', "expand-all", "ExpandAll", 0, NULL,
+ "expand all derived channels (turn them into RAW channels)" },
+ { OPT_EXPAND_NONE, DF_OPT_NO_ARG, 'E', "expand-none", "ExpandNone",
+ DF_OPT_PLUS, NULL, "keep all derived channels as-is (default)" },
+ { OPT_EXPAND, DF_OPT_ARG_RQ, 'e', "expand", "Expand", 0, "FIELD",
+ "expand derived channel FIELD (turn it into a RAW channel)" },
+ { OPT_DONT_EXPAND, DF_OPT_ARG_RQ, 'e', "dont-expand", "DontExpand",
+ DF_OPT_PLUS, "FIELD", "don't expand derived channel FIELD" },
+ { OPT_FLATTEN, DF_OPT_NO_ARG, 'f', "flatten", "Flatten", 0, NULL,
+ "merge all fragments into one" },
+ { OPT_NO_FLATTEN, DF_OPT_NO_ARG, 'f', "no-flatten", "NoFlatten", DF_OPT_PLUS,
+ NULL, "don't merge all fragments into one (default)" },
+ { OPT_LINK_LUT, DF_OPT_NO_ARG, 'L', "link-extern-lut", "LinkExternLUTs", 0,
+ NULL, "link to LINTERP tables outside the source dirfile instead of "
+ "duplicating them"
+ },
+ { OPT_COPY_LUT, DF_OPT_NO_ARG, 'L', "copy-extern-lut", "CopyExternLUTs",
+ DF_OPT_PLUS, NULL,
+ "duplicate LINTERP tables outside the source dirfile (default)" },
+ { OPT_LINK_EXT, DF_OPT_NO_ARG, 'X', "link-extern-frag", "LinkExternFragments",
+ 0, NULL,
+ "link to fragments outside the source dirfile instead of duplicating them"
+ },
+ { OPT_COPY_EXT, DF_OPT_NO_ARG, 'X', "copy-extern-frag", "CopyExternFragments",
+ DF_OPT_PLUS, NULL,
+ "duplicate fragments outside the source dirfile (default)" },
+ { OPT_EXT_DIR, DF_OPT_ARG_RQ, 0, "ext-dir", "ExtDir", 0, "DIR",
+ "put external subdirfiles copied into the output in subdirectory DIR. "
+ "The default is \"<ext>\"" },
+ { OPT_LUT_DIR, DF_OPT_ARG_RQ, 0, "lut-dir", "LUTDir", 0, "DIR",
+ "put LINTERP lookup tables copied into the output in subdirectory DIR. "
+ "The default is \"<lut>\"" },
+ DF_OPT_ENDOPT
+};
+
+static int parse_config(const struct df_config *config)
+{
+ int i, n;
+ char *ptr;
+
+ conf.expand = df_subset_init(DF_SUBSET_EMPTY, df_subset_strcmp);
+
+ for (i = 0; i < config->n_config; ++i) {
+ switch (config->value[i]) {
+ case OPT_EXPAND_ALL:
+ df_subset_reset(conf.expand, DF_SUBSET_FULL);
+ break;
+ case OPT_EXPAND_NONE:
+ df_subset_reset(conf.expand, DF_SUBSET_EMPTY);
+ break;
+ case OPT_EXPAND:
+ df_subset_update(conf.expand, config->arg[i],
+ strlen(config->arg[i]) + 1, DF_SUBSET_ADD);
+ break;
+ case OPT_DONT_EXPAND:
+ df_subset_update(conf.expand, config->arg[i],
+ strlen(config->arg[i]) + 1, DF_SUBSET_DEL);
+ break;
+ case OPT_LINK_EXT:
+ conf.link_ext = 1;
+ break;
+ case OPT_COPY_EXT:
+ conf.link_ext = 0;
+ break;
+ case OPT_LINK_LUT:
+ conf.link_lut = 1;
+ break;
+ case OPT_COPY_LUT:
+ conf.link_lut = 0;
+ break;
+ case OPT_FLATTEN:
+ conf.flatten = 1;
+ break;
+ case OPT_NO_FLATTEN:
+ conf.flatten = 0;
+ break;
+ default:
+ fprintf(stderr, "defile-dirfile: internal error: "
+ "unhandled configuration: %i\n", config->value[i]);
+ return 1;
+ }
+ }
+
+ /* paths */
+ if (conf.ext_dir == NULL || conf.ext_dir[0] == 0)
+ conf.ext_dir = "<ext>";
+ if (conf.lut_dir == NULL || conf.lut_dir[0] == 0)
+ conf.lut_dir = "<lut>";
+ conf.ext_dir_len = strlen(conf.ext_dir);
+ conf.lut_dir_len = strlen(conf.lut_dir);
+
+ return 0;
+}
+
static int dirfile_probe(const char *name)
{
int take = 1;
@@ -74,37 +203,35 @@
}
/* clean up the dirfile */
-static int dirfile_cleanup(void)
+static int dirfile_abort(void)
{
unsigned int i;
+ df_subset_delete(conf.expand);
+
for (i = 0; i < nraw; ++i) {
free(raw[i].name);
free(raw[i].b);
}
free(raw);
+ free(frag_cnc);
+ for (i = 0; i < n_lut; ++i)
+ free(lut_list[i]);
+ free(lut_list);
gd_discard(D);
-}
-/* abort handler */
-static int dirfile_abort(void)
-{
- dirfile_cleanup();
return 0;
}
-static int dirfile_check_gd_error(int i)
+static void check_gd_error(int i)
{
if (gd_error(D)) {
char *err = gd_error_string(D, NULL, 0);
- fprintf(stderr, "defile-dirfile: getdata %i: %s\n", i, err);
+ fprintf(stderr, "defile-dirfile: getdata error line %i: %s\n", i, err);
free(err);
- dirfile_cleanup();
- return 1;
+ df_exit(1, 1);
}
-
- return 0;
}
static ssize_t dirfile_copy_raw(int r, int debug)
@@ -116,28 +243,29 @@
if (nf == 0) {
/* read a bunch o' data */
- size_t n = gd_getdata(D, raw[r].name, GD_HERE, 0, raw[r].fpc, 0,
+ size_t n = gd_getdata64(D, raw[r].name, 0, raw[r].pos, raw[r].fpc, 0,
raw[r].type, raw[r].b + raw[r].blen * GD_SIZE(raw[r].type));
- if (dirfile_check_gd_error(4))
- return -1;
- else if (n == 0) /* out of data, nothing more to do */
+ check_gd_error(__LINE__);
+
+ if (n == 0) /* out of data, nothing more to do */
return 0;
-
+
raw[r].blen += n;
nf = raw[r].blen / raw[r].spf;
if (debug)
- fprintf(stderr, "defile-dirfile: read %zi frames of field %s\n",
- nf, raw[r].name);
+ fprintf(stderr, "defile-dirfile: "
+ "read %zi frames of field %s from sample %llu (fdef #%i)\n",
+ nf, raw[r].name, (unsigned long long)raw[r].pos, raw[r].index);
+
+ raw[r].pos += n;
}
/* shove it as much as possible up into defile */
nw = df_push_frame(raw[r].index, nf, raw[r].b, 0);
- if (nw < 0) {
- dirfile_cleanup();
- return -1;
- }
+ if (nw < 0)
+ df_exit(1, 1);
/* save any trailing part */
raw[r].blen -= nw * raw[r].spf;
@@ -147,10 +275,176 @@
return nf;
}
+/* add a fragment */
+static int add_frag(int i, int ext, const char *fragname)
+{
+ char *buf, *pbase, *prefix, *suffix;
+ int pos;
+ int fragnum, parent;
+ unsigned long byte_sex, encoding = GD_AUTO_ENCODED;
+
+ byte_sex = gd_endianness(D, i);
+ check_gd_error(__LINE__);
+
+ parent = gd_parent_fragment(D, i);
+ check_gd_error(__LINE__);
+
+ gd_fragment_affixes(D, i, &pbase, &suffix);
+ check_gd_error(__LINE__);
+ prefix = pbase;
+
+ /* subtract the parent's affixes */
+ if (prefix || suffix) {
+ char *pprefix, *psuffix;
+
+ gd_fragment_affixes(D, parent, &pprefix, &psuffix);
+ check_gd_error(__LINE__);
+
+ if (pprefix) {
+ pos = 0;
+ while (pprefix[pos] && pprefix[pos] == prefix[pos])
+ pos++;
+
+ prefix += pos;
+ free(pprefix);
+ }
+
+ if (psuffix) {
+ char *ptr = suffix + strlen(suffix) - 1;
+ char *pptr = psuffix + strlen(psuffix) - 1;
+
+ while (ptr > suffix && *ptr == *pptr) {
+ *(ptr--) = 0;
+ pptr--;
+ }
+
+ free(psuffix);
+ }
+ }
+
+ if (ext) {
+ if (conf.link_ext) {
+ if (df_include(fragname, frag_cnc[parent], prefix, suffix))
+ df_exit(1, 1);
+ free(pbase);
+ free(suffix);
+ return -1;
+ }
+ /* prepend extdir; extract directory and filename */
+ buf = malloc(strlen(fragname) + conf.ext_dir_len + 2);
+ sprintf(buf, "%s%s", conf.ext_dir, fragname);
+ } else {
+ pos = 0;
+ while (fragname[pos] && dirfilename[pos] == fragname[pos])
+ pos++;
+
+ if (fragname[pos] == '/')
+ pos++;
+
+ /* extract directory and filename */
+ buf = strdup(fragname + pos);
+ }
+
+ /* add new fragment */
+ fragnum = df_add_fragment(buf, frag_cnc[parent], encoding, byte_sex, prefix,
+ suffix);
+
+ free(buf);
+ free(pbase);
+ free(suffix);
+
+ if (fragnum < 0)
+ df_exit(1, 1);
+
+ return fragnum;
+}
+
+/* returns true if "path" is outside the input directory tree */
+static int is_extern(const char *path)
+{
+ return strncmp(path, dirfilename, dirfilename_len);
+}
+
+/* returns true if we're supposed to expand this derived field */
+static int expand(const gd_entry_t *E)
+{
+ int i;
+
+ /* skip inappropriate field types */
+ if (E->field_type == GD_INDEX_ENTRY || (E->field_type & GD_SCALAR_ENTRY_BIT))
+ return 0;
+
+ return df_subset_contains(conf.expand, E->field);
+}
+
+/* modify a LUT table path */
+static void update_tablename(gd_entry_t *E)
+{
+ const char *old_lut;
+ char *lut;
+ int i, fd, ext, found = 0;
+
+ old_lut = gd_linterp_tablename(D, E->field);
+ check_gd_error(__LINE__);
+
+ /* check it exists */
+ fd = open(old_lut, O_RDONLY);
+ if (fd < 0) {
+ /* if the LUT doesn't exist, we simply do nothing, keeping the old invalid
+ * path in the field specification */
+ return;
+ }
+
+ ext = is_extern(old_lut);
+
+ /* convert the name, if necessary */
+ if ((ext && !conf.link_lut) || conf.flatten) {
+ size_t old_lut_len = strlen(old_lut);
+ free(E->table);
+ E->table = malloc(old_lut_len + conf.lut_dir_len + 2);
+ sprintf(E->table, "%s%s", conf.lut_dir, old_lut);
+ lut = malloc(dirfilename_len + old_lut_len + conf.lut_dir_len + 3);
+ sprintf(lut, "%s/%s", dirfilename, E->table);
+ } else
+ lut = strdup(old_lut);
+
+ if (lut == NULL) {
+ close(fd);
+ perror("defile-dirfile:");
+ df_exit(1, 1);
+ }
+
+ /* check whether we've already handled this LUT */
+ for (i = 0; i < n_lut; ++i) {
+ if (strcmp(lut, lut_list[i]) == 0) {
+ found = 1;
+ break;
+ }
+ }
+
+ /* no, add it and copy it to the output dirfile */
+ if (!found) {
+ ...
[truncated message content] |