getdata-commits Mailing List for GetData (Page 11)
Scientific Database Format
Brought to you by:
ketiltrout
This list is closed, nobody may subscribe to it.
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(5) |
Oct
(20) |
Nov
(21) |
Dec
(16) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2011 |
Jan
(1) |
Feb
(1) |
Mar
(56) |
Apr
(20) |
May
(4) |
Jun
(2) |
Jul
(3) |
Aug
(11) |
Sep
(2) |
Oct
(4) |
Nov
(18) |
Dec
(16) |
2012 |
Jan
(8) |
Feb
(12) |
Mar
(30) |
Apr
(13) |
May
(10) |
Jun
(17) |
Jul
(18) |
Aug
(19) |
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(9) |
2013 |
Jan
(1) |
Feb
(4) |
Mar
(27) |
Apr
(6) |
May
(3) |
Jun
(1) |
Jul
(10) |
Aug
|
Sep
(3) |
Oct
(15) |
Nov
(4) |
Dec
(9) |
2014 |
Jan
|
Feb
(3) |
Mar
(4) |
Apr
(10) |
May
(15) |
Jun
|
Jul
(14) |
Aug
|
Sep
(2) |
Oct
(6) |
Nov
|
Dec
(9) |
2015 |
Jan
(2) |
Feb
(3) |
Mar
(1) |
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <ket...@us...> - 2012-03-24 02:54:23
|
Revision: 685 http://getdata.svn.sourceforge.net/getdata/?rev=685&view=rev Author: ketiltrout Date: 2012-03-24 02:54:17 +0000 (Sat, 24 Mar 2012) Log Message: ----------- Correct. Modified Paths: -------------- trunk/getdata/man/gd_alias_target.3 Modified: trunk/getdata/man/gd_alias_target.3 =================================================================== --- trunk/getdata/man/gd_alias_target.3 2012-03-22 23:01:51 UTC (rev 684) +++ trunk/getdata/man/gd_alias_target.3 2012-03-24 02:54:17 UTC (rev 685) @@ -21,7 +21,8 @@ .HP .nh .ad l -.BI "const char *gd_alias(DIRFILE *" dirfile ", const char *" alias_name ); +.BI "const char *gd_alias_target(DIRFILE *" dirfile ", const char *" alias_name +.B ); .hy .ad n .SH DESCRIPTION This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-22 23:01:58
|
Revision: 684 http://getdata.svn.sourceforge.net/getdata/?rev=684&view=rev Author: ketiltrout Date: 2012-03-22 23:01:51 +0000 (Thu, 22 Mar 2012) Log Message: ----------- Append mode. Also, be threadsafe. Modified Paths: -------------- trunk/defile/bin/cli.c trunk/defile/input/Makefile.am trunk/defile/input/ascii.c trunk/defile/input/dirfile.c trunk/defile/lib/defile.h trunk/defile/lib/internal.h trunk/defile/lib/libdefile.c Modified: trunk/defile/bin/cli.c =================================================================== --- trunk/defile/bin/cli.c 2012-03-22 01:39:48 UTC (rev 683) +++ trunk/defile/bin/cli.c 2012-03-22 23:01:51 UTC (rev 684) @@ -25,6 +25,7 @@ #include "internal.h" +#include <errno.h> #include <signal.h> #include <stdlib.h> #include <stdio.h> @@ -87,20 +88,23 @@ #define CLRSTRING(x,y) SETSTATE(x,y,free(df-> y),df ->y = NULL,"%s") #define SETFLOAT(x,y) SETSIMPLE(x,y,atof(config->argument),,"%g") #define SETLFLOAT(x,y,b) SETSIMPLE(x,y,b,,"%g" ) -#define SETINT(x,y) SETSIMPLE(x,y,strol(config->argument, NULL, 0),,"%i") +#define SETINT(x,y) SETSIMPLE(x,y,strtol(config->argument, NULL, 0),,"%i") #define SETLINT(x,y,b) SETSIMPLE(x,y,b,,"%i" ) #define SETULONG(x,y) SETSIMPLE(x,y,strtoul(config->argument, NULL, 0),,\ "%lu") +#define SETULLONG(x,y) SETSIMPLE(x,y,strtoull(config->argument, NULL, 0),,\ + "%llu") -#define ABORT_DELAY 60000000 /* sixty seconds; this is less than the maximum TCP - * round-trip timeout. Do we care? */ +#define ABORT_DELAY 10000000 /* ten seconds */ /* the very defile object */ static struct df_defile the_defile; struct df_defile *const df = &the_defile; -/* state mutex */ +/* mutices */ pthread_mutex_t state_mx = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t config_mx = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t rate_mx = PTHREAD_MUTEX_INITIALIZER; static void DF_SignalHandler(int sig) { @@ -264,7 +268,7 @@ result = 4; lt_dlclose(lib); } - if (df->config.mode_flags & DF_MODE_DEBUG) { + if (df->mode_flags & DF_MODE_DEBUG) { fprintf(stderr, "defile: probing %s; result: %s\n", filename, (result) ? "fail" : "pass"); } @@ -333,7 +337,7 @@ /* run through the search path looking for candidate libraries */ if (dlp) { - if (df->config.mode_flags & DF_MODE_DEBUG) + if (df->mode_flags & DF_MODE_DEBUG) fprintf(stderr, "defile: searching local paths: %s\n", dlp); lt_dlforeachfile(dlp, DF_LTDLSearchFunc, l); } @@ -341,7 +345,7 @@ /* the default plugin dir if the above didn't work; or if we're compiling a * list */ if (type == NULL || l->r != 0) { - if (df->config.mode_flags & DF_MODE_DEBUG) + if (df->mode_flags & DF_MODE_DEBUG) fprintf(stderr, "defile: searching default path: %s\n", DEFILE_MODULEDIR); lt_dlforeachfile(DEFILE_MODULEDIR, DF_LTDLSearchFunc, l); } @@ -503,11 +507,13 @@ } enum { - DF_WOPT_ADD = 1, DF_WOPT_ASYNC, DF_WOPT_AUTOTYPE, DF_WOPT_BHEAD, DF_WOPT_BLEN, - DF_WOPT_CLOBBER, DF_WOPT_DEBUG, DF_WOPT_DEL, DF_WOPT_DIR, DF_WOPT_GZIP, - DF_WOPT_INPUT, DF_WOPT_LIBDIR, DF_WOPT_LIST, DF_WOPT_NOCLOBBER, - DF_WOPT_NODEBUG, DF_WOPT_NOFOLLOW, DF_WOPT_OFLCLR, DF_WOPT_OUTPUT, - DF_WOPT_FOLLOW, DF_WOPT_QUIET, DF_WOPT_SYNC, DF_WOPT_TYPE, DF_WOPT_VERBOSE + 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, + DF_WOPT_DEL, DF_WOPT_DIR, DF_WOPT_FOLLOW, DF_WOPT_GZIP, DF_WOPT_INPUT, + DF_WOPT_LIBDIR, DF_WOPT_LIST, DF_WOPT_NOAPPEND, DF_WOPT_NOCLOBBER, + DF_WOPT_NOCUTDIR, DF_WOPT_NODEBUG, DF_WOPT_NOFOLLOW, DF_WOPT_OFLCLR, + DF_WOPT_OUTPUT, DF_WOPT_QUIET, DF_WOPT_SKIP, DF_WOPT_SYNC, DF_WOPT_TYPE, + DF_WOPT_VERBOSE }; static int DF_OutputOpt(struct df_defile *df, struct df_rc_config *config, @@ -572,27 +578,35 @@ return 0; + SETBIT(APPEND, mode_flags, DF_MODE_APPEND); + CLRBIT(NOAPPEND, mode_flags, DF_MODE_APPEND); + SETULONG(BHEAD, bufhead); - SETULONG(BLEN, config.buflen); + SETULONG(BLEN, buflen); SETLINT(CLOBBER, clobber, 1); SETLINT(NOCLOBBER, clobber, 0); + SETINT(CUTDIR, cutdir); + SETLINT(NOCUTDIR, cutdir, 0); + SETSTRING(DIR, dir); SETSTRING(OUTPUT, output); - SETBIT(FOLLOW, config.mode_flags, DF_MODE_FOLLOW); - CLRBIT(NOFOLLOW, config.mode_flags, DF_MODE_FOLLOW); + SETBIT(FOLLOW, mode_flags, DF_MODE_FOLLOW); + CLRBIT(NOFOLLOW, mode_flags, DF_MODE_FOLLOW); SETLINT(QUIET, quiet, 1); SETLINT(VERBOSE, quiet, 0); - SETBIT(DEBUG, config.mode_flags, DF_MODE_DEBUG); - CLRBIT(NODEBUG, config.mode_flags, DF_MODE_DEBUG); + SETBIT(DEBUG, mode_flags, DF_MODE_DEBUG); + CLRBIT(NODEBUG, mode_flags, DF_MODE_DEBUG); - SETBIT(ASYNC, config.mode_flags, DF_MODE_ASYNC); - CLRBIT(SYNC, config.mode_flags, DF_MODE_ASYNC); + SETULLONG(SKIP, offset); + SETBIT(ASYNC, mode_flags, DF_MODE_ASYNC); + CLRBIT(SYNC, mode_flags, DF_MODE_ASYNC); + SETSTRING(TYPE, type); CLRSTRING(AUTOTYPE, type); } @@ -612,15 +626,27 @@ } else ptr = strdup(output); } else if (output == NULL) { - char *ptr2, *ptr3; - ptr2 = strdup(input); + int cutleft = df->cutdir; + char *ptr_base, *ptr2, *ptr3; + ptr_base = strdup(input); + + /* cut directories */ + if (cutleft == 0) + ptr2 = ptr_base; + else { + cutleft = df->cutdir; + for (ptr2 = ptr_base + strlen(ptr_base); ptr2 > ptr_base; --ptr2) + if (*(ptr2 - 1) == '/') + if (--cutleft == 0) + break; + } /* remove forbidden characters */ for (ptr3 = ptr2; *ptr3; ++ptr3) if (*ptr3 == '/') *ptr3 = '_'; ptr = malloc(strlen(dir) + strlen(ptr2) + 2); sprintf(ptr, "%s/%s", dir, ptr2); - free(ptr2); + free(ptr_base); } else if (output[0] == '/') { ptr = strdup(output); } else { @@ -658,29 +684,61 @@ return 0; } -static int DF_CreateOutput(unsigned long flags) +static int DF_CreateOutput(int clobber, int append) { - int gderr; + int new = 1; - df->flags = flags; + /* check wether it already exists */ + df->D = gd_open(df->dirfile, GD_RDWR | GD_CREAT | GD_EXCL); - df->D = gd_open(df->dirfile, GD_RDWR | GD_CREAT | ((flags & DF_CLOBBER) ? - (GD_TRUNC | GD_TRUNCSUB) : GD_EXCL) | GD_VERBOSE); + /* abort on error */ + if (df->D == NULL) { + fprintf(stderr, "defile: unexplained catastrophe attempting to create %s\n", + df->dirfile); + return 1; + } else if (gd_error(df->D) == GD_E_EXISTS && (clobber || append)) { + new = 0; + /* destroy invalid object and reopen */ + gd_discard(df->D); + df->D = gd_open(df->dirfile, GD_RDWR | + (append ? 0 : GD_TRUNC | GD_TRUNCSUB)); - if ((gderr = gd_error(df->D))) { - char *err = gd_error_string(df->D, NULL, 0); - fprintf(stderr, "defile: getdata error: %s\n", err); - free(err); - if (gderr == GD_E_CREAT) { /* no clobber: allow the input to try again */ - pthread_mutex_lock(&state_mx); - DF_OUTSTATE(INIT); - pthread_mutex_unlock(&state_mx); - } else + if (df->D == NULL) { + fprintf(stderr, + "defile: unexplained catastrophe attempting to create %s\n", + df->dirfile); return 1; + } + } else if (gd_error(df->D) == GD_E_OK) { + pthread_mutex_lock(&config_mx); + df->mode_flags &= ~DF_MODE_APPEND; + pthread_mutex_unlock(&config_mx); + append = 0; } + if (gd_error(df->D)) { + char *estring = gd_error_string(df->D, NULL, 0); + fprintf(stderr, "defile: libgetdata: %s\n", estring); + gd_discard(df->D); + free(estring); + return 1; + } + + /* set up GetData's verbose mode */ + gd_flags(df->D, GD_VERBOSE, 0); + gd_verbose_prefix(df->D, "defile: "); + + if (append) { + unsigned long long nf = gd_nframes(df->D); + pthread_mutex_lock(&config_mx); + if (df->offset < nf) + df->offset = nf; + pthread_mutex_unlock(&config_mx); + } + if (!df->quiet) - printf("defile: writing to %s\n\n", df->dirfile); + printf("defile: %s %s\n\n", append ? "appending to" : new ? "created" : + "overwriting", df->dirfile); return 0; } @@ -731,7 +789,7 @@ /* wait while the input does something */ static inline void DF_WaitWhileInputStates(int state1, int state2, int quiet) { - if (!quiet && df->config.mode_flags & DF_MODE_DEBUG) + if (!quiet && df_mode() & DF_MODE_DEBUG) fprintf(stderr, "defile: output waiting on input for end of %s and %s\n", DF_STATENAME(state1), DF_STATENAME(state2)); while (df->input_state == state1 || df->input_state == state2) @@ -741,7 +799,7 @@ /* wait while the input does something */ static inline void DF_WaitWhileInputState(int state, int quiet) { - if (!quiet && df->config.mode_flags & DF_MODE_DEBUG) + if (!quiet && df_mode() & DF_MODE_DEBUG) fprintf(stderr, "defile: output waiting on input for end of %s\n", DF_STATENAME(state)); while (df->input_state == state) @@ -756,7 +814,7 @@ if (!df->dirfile) return 1; - if (DF_CreateOutput(df->clobber ? DF_CLOBBER : 0)) + if (DF_CreateOutput(df->clobber, df_mode() & DF_MODE_APPEND)) return 1; if (df->output_state == DF_ST_ABORT) @@ -766,7 +824,7 @@ DF_OUTSTATE_MX(BUILD); /* wait for the input to build the dirfile */ - DF_WaitWhileInputStates(DF_ST_BUILD, DF_ST_INIT, 0); + DF_WaitWhileInputState(DF_ST_BUILD, 0); if (df->output_state == DF_ST_ABORT) return 1; @@ -783,10 +841,11 @@ /* output thread */ static void *DF_OutputThread(void) { - int i, j, last_pass = 0; + int i, j, last_pass = 0, wait = 1; size_t nwrote; struct df_raw *r; - unsigned long in, out, nf; + unsigned long nf, out; + const int debug = df_mode() & DF_MODE_DEBUG; /* wait for the input to initialise */ DF_WaitWhileInputState(DF_ST_START, 0); @@ -803,6 +862,7 @@ /* loop through raws, writing ones that have full buffer heads */ while (!last_pass) { + wait = 1; if (df->input_state != DF_ST_RUN) last_pass = 1; @@ -818,7 +878,8 @@ if (DF_OutputFini(delete)) { DF_OUTSTATE_MX(ERROR); return NULL; - } else if (DF_MakeOutput()) { + } + if (DF_MakeOutput()) { DF_OUTSTATE_MX(ERROR); return NULL; } @@ -836,26 +897,45 @@ } } r = df->raw + i; - in = r->in; + + /* skip this field for now, if we can't lock it */ + if (pthread_mutex_trylock(&r->mx) == EBUSY) { + if (debug) + fprintf(stderr, "\nlockmiss on %s\n", r->name); + continue; + } + out = r->out; - nf = (in == out) ? df->config.buflen - 1 : - ((in + r->buflen - out) % r->buflen) / r->framesize - 1; - if (nf == 0 || (!last_pass && nf <= df->bufhead)) + nf = (r->in == out) ? df->buflen - 1 : + ((r->in + r->buflen - out) % r->buflen) / r->framesize - 1; + + if (nf == 0 || (!last_pass && nf <= df->bufhead)) { + pthread_mutex_unlock(&r->mx); continue; + } + + if (!(df_mode() & DF_MODE_ASYNC)) { + /* in synchronous mode, the reference field is special: we only write + * frames to it if all other fields have those frames committed */ + if (i == df->ref_ind) { + /* adjust for shorter sticks */ + for (j = 0; j < df->nraw; ++j) + if (j != df->ref_ind) + if (nf > df->raw[j].ahead) + nf = df->raw[j].ahead; + } else { + /* in synchronous mode, we never want to get more than one buflen + * ahead of the referenc efield */ + if (r->ahead + nf >= df->buflen) + nf = df->buflen - r->ahead - 1; + } - /* in synchronous mode, the reference field is special: we only write - * frames to it if all other fields have those frames committed */ - if (i == df->ref_ind && !(df->config.mode_flags & DF_MODE_ASYNC)) { - /* adjust for shorter sticks */ - for (j = 0; j < df->nraw; ++j) - if (j != df->ref_ind) - if (nf > df->raw[j].ahead) - nf = df->raw[j].ahead; - /* check again */ - if (nf == 0 || (!last_pass && nf <= df->bufhead)) + if (nf == 0 || (!last_pass && nf <= df->bufhead)) { + pthread_mutex_unlock(&r->mx); continue; + } } /* point the local output pointer to the next datum to write */ @@ -876,6 +956,7 @@ /* bail on error */ if (gd_error(df->D)) { DF_OUTSTATE_MX(ERROR); + pthread_mutex_unlock(&r->mx); return NULL; } @@ -886,12 +967,13 @@ if (j != df->ref_ind) /* XXX */ df->raw[j].ahead -= nf; } else - r->ahead += nwrote / r->spf; + r->ahead += nf; if (nwrote > 0) { last_pass = 0; - if (df->config.mode_flags & DF_MODE_DEBUG) { - if (i != df->ref_ind && !(df->config.mode_flags & DF_MODE_ASYNC)) + wait = 0; + if (debug) { + if (i != df->ref_ind && !(df_mode() & DF_MODE_ASYNC)) fprintf(stderr, "defile: output %lu %s of field %s " "(lead is %lu %s)\n", nf, (nf == 1) ? "frame" : "frames", r->name, r->ahead, @@ -904,15 +986,19 @@ /* update write pointer */ r->out = (r->out + nwrote * GD_SIZE(r->type)) % r->buflen; + pthread_mutex_unlock(&r->mx); /* update write counts */ + pthread_mutex_lock(&rate_mx); df->wpartial += nwrote * GD_SIZE(r->type); while (df->wpartial >= df->wframesize) { df->nwrote++; df->wpartial -= df->wframesize; } + pthread_mutex_unlock(&rate_mx); } - usleep(10000); + if (wait) + usleep(10000); } /* finished */ @@ -947,16 +1033,19 @@ static unsigned long long lw = 0; static int init = 2; - const char eol = (df->config.mode_flags & DF_MODE_DEBUG) ? '\n' : '\r'; + const char eol = (df_mode() & DF_MODE_DEBUG) ? '\n' : '\r'; double delta, drate; - unsigned long long nf; - const unsigned long long nw = df->nwrote; - const unsigned long long nr = df->nread; + unsigned long long nf, nw, nr; char si; struct timezone tz; struct timeval now; + pthread_mutex_lock(&rate_mx); + nw = df->nwrote; + nr = df->nread; + pthread_mutex_unlock(&rate_mx); + if (df->quiet) return rate; @@ -1063,6 +1152,12 @@ struct sigaction action; const struct df_optdef options[] = { + { DF_WOPT_APPEND, DF_OPT_NO_ARG, 'A', "append", "Append", 0, NULL, + "append data to an already existing output" + }, + { DF_WOPT_NOAPPEND, DF_OPT_NO_ARG, 'A', "no-append", "NoAppend", 0, NULL, + "don't append data (default)" + }, { DF_WOPT_ASYNC, DF_OPT_NO_ARG, 'a', "asyncrhonous", "Asynchronous", 0, NULL, "operate in asynchronous mode" }, @@ -1075,6 +1170,12 @@ { 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", + "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, + "don't remove path elements from the output name (default)" + }, { DF_WOPT_DIR, DF_OPT_ARG_RQ, 'D', "directory", "Directory", DF_OPT_EXPAND, "DIR", "write the output dirfile as a subdirectory under DIR" }, @@ -1084,6 +1185,14 @@ { DF_WOPT_NODEBUG, DF_OPT_NO_ARG, 'd', "no-debug", "NoDebug", DF_OPT_PLUS, NULL, "suppress printing debugging messages (default)" }, + { DF_WOPT_FOLLOW, DF_OPT_NO_ARG, 'f', "follow", "Follow", 0, NULL, + "keep monitoring the input and write data to the outpu as it becomes " + "available" + }, + { DF_WOPT_NOFOLLOW, DF_OPT_NO_ARG, 'f', "no-follow", "NoFollow", + DF_OPT_PLUS, NULL, + "exit successfully upon reaching the end of the input (default)" + }, { DF_WOPT_ADD, DF_OPT_ARG_RQ, 'F', "include", "IncludeField", 0, "FIELD", "include FIELD in the output dirfile, if available" }, @@ -1117,29 +1226,28 @@ { DF_WOPT_OUTPUT, DF_OPT_ARG_RQ, 'o', "output", "Output", DF_OPT_EXPAND, "PATH", "write data to a dirfile called PATH" }, - { DF_WOPT_FOLLOW, DF_OPT_NO_ARG, 'f', "follow", "Follow", 0, NULL, - "keep monitoring the input and write data to the outpu as it becomes " - "available" - }, - { DF_WOPT_NOFOLLOW, DF_OPT_NO_ARG, 'f', "no-follow", "NoFollow", - DF_OPT_PLUS, NULL, - "exit successfully upon reaching the end of the input (default)" - }, { DF_WOPT_QUIET, DF_OPT_NO_ARG, 'q', "quiet", "Quiet", 0, NULL, "be less verbose" }, { DF_WOPT_VERBOSE, DF_OPT_NO_ARG, 'q', "verbose", "Verbose", DF_OPT_PLUS, NULL, "be normally verbose" }, +#if 0 + { DF_WOPT_SKIP, DF_OPT_ARG_RQ, 's', "skip", "SkipFrames", 0, "NUM", + "skip the first NUM frames of the input (default: 0)" + }, +#endif { DF_WOPT_TYPE, DF_OPT_ARG_RQ, 't', "type", "InputType", 0, "TYPE", "use TYPE as the input data type" }, { DF_WOPT_AUTOTYPE, DF_OPT_NO_ARG, 't', "autotype", "AutoType", DF_OPT_PLUS, NULL, "attempt to automatically determine the data type of the input" }, - // { DF_WOPT_GZIP, DF_OPT_NO_ARG, 'z', "gzip", "GZip", 0, NULL, - // "gzip compress the output raw data" - // }, +#if 0 + { DF_WOPT_GZIP, DF_OPT_NO_ARG, 'z', "gzip", "GZip", 0, NULL, + "gzip compress the output raw data" + }, +#endif DF_OPT_ENDOPT }; @@ -1163,7 +1271,7 @@ df->iargv = malloc(sizeof(char*)); df->iargv[0] = argv[0]; df->iargc = 1; - df->config.buflen = DF_BUFLEN; + df->buflen = DF_BUFLEN; /* initialise LTDL and register its cleanup function */ lt_dlinit(); @@ -1172,10 +1280,10 @@ DF_Parse(argc, argv, &rcd, df); /* sanitise */ - if (df->config.buflen < df->bufhead) - df->config.buflen = df->bufhead; - if (df->config.buflen < 2) - df->config.buflen = 2; + if (df->buflen < df->bufhead) + df->buflen = df->bufhead; + if (df->buflen < 2) + df->buflen = 2; if (!df->quiet) puts(PACKAGE_STRING " " DEFILE_COPYRIGHT); @@ -1251,7 +1359,7 @@ /* wait until the initialisation is done */ fflush(stdout); - DF_WaitWhileInputStates(DF_ST_START, DF_ST_INIT, 1); + DF_WaitWhileInputState(DF_ST_START, 1); DF_WaitWhileInputState(DF_ST_BUILD, 1); /* record our "start" time */ Modified: trunk/defile/input/Makefile.am =================================================================== --- trunk/defile/input/Makefile.am 2012-03-22 01:39:48 UTC (rev 683) +++ trunk/defile/input/Makefile.am 2012-03-22 23:01:51 UTC (rev 684) @@ -20,11 +20,10 @@ # AUTOMAKE_OPTIONS = foreign +LDFLAGS = -module -shared -release $(PACKAGE_VERSION) module_LTLIBRARIES = libdefile-dirfile.la libdefile-ascii.la libdefile_dirfile_la_SOURCES = dirfile.c -libdefile_dirfile_la_LDFLAGS = -module libdefile_dirfile_la_LIBADD = ../lib/libdefile.la libdefile_ascii_la_SOURCES = ascii.c -libdefile_ascii_la_LDFLAGS = -module libdefile_ascii_la_LIBADD = ../lib/libdefile.la Modified: trunk/defile/input/ascii.c =================================================================== --- trunk/defile/input/ascii.c 2012-03-22 01:39:48 UTC (rev 683) +++ trunk/defile/input/ascii.c 2012-03-22 23:01:51 UTC (rev 684) @@ -216,7 +216,7 @@ } /* in non-persistant mode, count lines */ - if (!(config->mode_flags & DF_MODE_FOLLOW)) { + if (!(df_mode() & DF_MODE_FOLLOW)) { while ((n = fgetc(s)) != EOF) if (ferror(s)) { perror("defile-ascii: read error"); @@ -322,7 +322,7 @@ } /* in persistant mode, wait a bit, and then go back and try again */ - if (config->mode_flags & DF_MODE_FOLLOW) + if (df_mode() & DF_MODE_FOLLOW) usleep(100000); else /* otherwise, we're done */ break; Modified: trunk/defile/input/dirfile.c =================================================================== --- trunk/defile/input/dirfile.c 2012-03-22 01:39:48 UTC (rev 683) +++ trunk/defile/input/dirfile.c 2012-03-22 23:01:51 UTC (rev 684) @@ -156,7 +156,7 @@ unsigned int r = 0; ssize_t nw; const char **field; - const int debug = config->mode_flags & DF_MODE_DEBUG; + const int debug = df_mode() & DF_MODE_DEBUG; void *buffer = NULL; /* set the abort handler */ @@ -170,7 +170,7 @@ /* In non-persist mode, it's useful to tell the writer how many frames we * have */ - if (!(config->mode_flags & DF_MODE_FOLLOW)) + if (!(df_mode() & DF_MODE_FOLLOW)) nframes = (uint64_t)gd_nframes(D); /* Initialise -- dirfiles don't contain rate information so we leave that @@ -333,7 +333,7 @@ } while (have_data); /* in persistant mode, wait a bit, and then go back and try again */ - if (config->mode_flags & DF_MODE_FOLLOW) + if (df_mode() & DF_MODE_FOLLOW) usleep(100000); else /* otherwise, we're done */ break; Modified: trunk/defile/lib/defile.h =================================================================== --- trunk/defile/lib/defile.h 2012-03-22 01:39:48 UTC (rev 683) +++ trunk/defile/lib/defile.h 2012-03-22 23:01:51 UTC (rev 684) @@ -77,14 +77,13 @@ }; /* mode flags */ -#define DF_MODE_ASYNC 0x1 /* asynchronous writing */ -#define DF_MODE_FOLLOW 0x2 /* follow mode */ +#define DF_MODE_APPEND 0x1 /* append mode */ +#define DF_MODE_ASYNC 0x2 /* asynchronous writing */ #define DF_MODE_DEBUG 0x4 /* debug mode */ +#define DF_MODE_FOLLOW 0x8 /* follow mode */ /* defile configuration */ struct df_config { - unsigned int mode_flags; - unsigned long buflen; int n_config; int *value; const char **arg; @@ -153,6 +152,8 @@ int df_check_abort(void); int df_field_in_output(const char *name); const char *df_input_name(int shell_expand); +unsigned int df_mode(void); +unsigned long long df_offset(void); df_abort_func_t df_on_abort(df_abort_func_t func); char *df_shell_expand(const char *s); int df_strcmp(const void *needle, const void *candidate); Modified: trunk/defile/lib/internal.h =================================================================== --- trunk/defile/lib/internal.h 2012-03-22 01:39:48 UTC (rev 683) +++ trunk/defile/lib/internal.h 2012-03-22 23:01:51 UTC (rev 684) @@ -26,6 +26,7 @@ #include <getdata.h> #include <syslog.h> +#include <pthread.h> #ifdef HAVE_LTDL_H #include <ltdl.h> @@ -41,7 +42,7 @@ /* maximum allowed length of a input type name */ #define DF_TYPE_MAXLEN 256 -/* Plugin status values */ +/* plugin state values */ #define DF_ST_ERROR -1 /* thread reported an error */ #define DF_ST_START 0 /* thread start */ #define DF_ST_BUILD 1 /* building the frame */ @@ -49,8 +50,7 @@ #define DF_ST_DONE 3 /* finished */ #define DF_ST_ABORT 4 /* thread must abort processing and exit */ -/* non-public (ie. output-only) states */ -#define DF_ST_INIT 5 /* the output couldn't initialise */ +/* special states */ #define DF_ST_SAVESTART 6 /* save the current output and restart (OUT only) */ #define DF_ST_DROPSTART 7 /* drop the current output and restart (OUT only) */ @@ -59,7 +59,7 @@ #define DF_SETSTATE(w,n,s) \ do { \ df-> w ## _state = DF_ST_ ## s; \ - if (df->config.mode_flags & DF_MODE_DEBUG) \ + if (df->mode_flags & DF_MODE_DEBUG) \ fputs("defile: " n " state: " #s "\n", stderr); \ } while (0) #define DF_SETSTATE_MX(w,n,s) \ @@ -80,7 +80,6 @@ ((i) == DF_ST_DONE) ? "DONE" : \ ((i) == DF_ST_ABORT) ? "ABORT" : \ ((i) == DF_ST_ERROR) ? "ERROR" : \ - ((i) == DF_ST_INIT) ? "INIT" : \ ((i) == DF_ST_DROPSTART) ? "DROPSTART" : \ ((i) == DF_ST_SAVESTART) ? "SAVESTART" : \ "UNKNOWN") @@ -97,6 +96,7 @@ unsigned long ahead; /* difference between the number of frames written to this raw and the reference -- only used in synchronous mode */ + pthread_mutex_t mx; /* buffer mutex */ }; /* internal framedef */ @@ -115,14 +115,19 @@ }; struct df_defile { - unsigned long flags; + /* the input plugin */ + lt_dlhandle inhandle; + const struct df_input_framework *input_framework; + + /* pathname handling */ char *input; - lt_dlhandle inhandle; char *dir; char *type; char *output; char *dirfile; + int cutdir; + /* threadkeeping */ pthread_t input_id; int input_state; pthread_t output_id; @@ -143,10 +148,15 @@ unsigned long long nwrote, nread; unsigned long long nframes; + /* operations */ struct df_config config; + unsigned long long offset; + unsigned long buflen; + unsigned int mode_flags; unsigned long bufhead; + /* output buffering */ int nraw; struct df_raw *raw; @@ -157,18 +167,18 @@ int ref_ind; /* parser stuff */ - const struct df_input_framework *input_framework; int mode_switch; int quiet; int clobber; int iargc; char **iargv; - unsigned long long offset; DIRFILE *D; }; extern struct df_defile *const df; extern pthread_mutex_t state_mx; +extern pthread_mutex_t config_mx; +extern pthread_mutex_t rate_mx; #endif Modified: trunk/defile/lib/libdefile.c =================================================================== --- trunk/defile/lib/libdefile.c 2012-03-22 01:39:48 UTC (rev 683) +++ trunk/defile/lib/libdefile.c 2012-03-22 23:01:51 UTC (rev 684) @@ -147,28 +147,60 @@ /* skip RAW fields */ if (E->field_type == GD_RAW_ENTRY) { - fputs("libdefile: Attempt to define RAW field via df_add_entry().\n", + fputs("libdefile: attempt to define RAW field via df_add_entry().\n", stderr); return DF_INPUT; } /* skip fields we've been asked to exclude */ - if (df_field_in_output(E->field)) - if (gd_add(df->D, E)) + if (df_field_in_output(E->field)) { + if (df_mode() & DF_MODE_APPEND) { + /* check for existing field */ + gd_entype_t type = gd_entry_type(df->D, E->field); + if (type == GD_NO_ENTRY) + return DF_INPUT; + else if (E->field_type != type) { + fprintf(stderr, "libdefile: incongruous specification of derived " + "field %s\n", E->field); + return DF_OUTPUT; + } + } else if (gd_add(df->D, E)) return DF_OUTPUT; + } return DF_SUCCESS; } +#define DF_CHAR2ENTYPE(n) if (strcmp(t, #n) == 0) return GD_ ## n ## _ENTRY; +const static df_type_from_token(const char *t) +{ + DF_CHAR2ENTYPE(BIT); + DF_CHAR2ENTYPE(CARRAY); + DF_CHAR2ENTYPE(CONST); + DF_CHAR2ENTYPE(DIVIDE); + DF_CHAR2ENTYPE(LINCOM); + DF_CHAR2ENTYPE(LINTERP); + DF_CHAR2ENTYPE(MPLEX); + DF_CHAR2ENTYPE(MULTIPLY); + DF_CHAR2ENTYPE(PHASE); + DF_CHAR2ENTYPE(POLYNOM); + DF_CHAR2ENTYPE(RECIP); + DF_CHAR2ENTYPE(SBIT); + DF_CHAR2ENTYPE(STRING); + DF_CHAR2ENTYPE(WINDOW); + + return GD_NO_ENTRY; +} + int df_add_spec(const char *spec, int fragment) { - char *ptr; + char *name, *type; DF_CHECK_SEQUENCE(DF_ST_BUILD); /* skip fields we've been asked to exclude, this requires isolating the * field name; use GetData's parser to do this. */ - ptr = gd_tokenise(df->D, spec); - if (ptr == NULL) { + name = gd_tokenise(df->D, spec); + if (name == NULL) { if (gd_error(df->D) == GD_E_ALLOC) return DF_OUTPUT; /* better to just fold this into gd_add_spec failures than return DF_SYSTEM */ @@ -176,24 +208,42 @@ } /* check OFL */ - if (!df_field_in_output(ptr)) { - free(ptr); + if (!df_field_in_output(name)) { + free(name); return DF_SUCCESS; } - free(ptr); /* check the second token to see if it's a RAW field */ - ptr = gd_tokenise(df->D, NULL); - if (ptr && strcmp(ptr, "RAW") == 0) { + type = gd_tokenise(df->D, NULL); + if (type && strcmp(type, "RAW") == 0) { fputs("libdefile: Attempt to define RAW field via df_add_spec().\n", stderr); + free(name); + free(type); return DF_INPUT; } - free(ptr); - - /* add it */ - if (gd_add_spec(df->D, spec, fragment)) + + /* check for existing field in append mode */ + if (df_mode() & DF_MODE_APPEND) { + gd_entype_t entype = gd_entry_type(df->D, name); + if (type == GD_NO_ENTRY) { + free(name); + free(type); + return DF_INPUT; + } else if (df_type_from_token(type) != entype) { + fprintf(stderr, "libdefile: incongruous specification of derived " + "field: %s\n", name); + free(name); + free(type); + return DF_OUTPUT; + } + } else if (gd_add_spec(df->D, spec, fragment)) { + free(name); + free(type); return DF_OUTPUT; + } + free(name); + free(type); return DF_SUCCESS; } @@ -252,6 +302,7 @@ static int df_set_raw(const struct df_fdef_field *f, int i, int count, int fragment) { + const int append = df_mode() & DF_MODE_APPEND; int r, is_new = 0; void *ptr; @@ -270,10 +321,13 @@ perror("libdefile: strdup"); return DF_SYSTEM; } - /* try adding it to the dirfile */ - if (gd_add_raw(df->D, f->name, f->type, f->spf, fragment)) - return DF_OUTPUT; + if (!append) { + /* try adding it to the dirfile */ + if (gd_add_raw(df->D, f->name, f->type, f->spf, fragment)) + return DF_OUTPUT; + } + /* add a new record */ ptr = realloc(df->raw, sizeof(struct df_raw) * (df->nraw + 1)); if (ptr == NULL) { @@ -297,16 +351,17 @@ df->raw[r].spf = f->spf * count; df->raw[r].in = 0; df->raw[r].b = NULL; + pthread_mutex_init(&df->raw[r].mx, NULL); } else { /* increase the samples per frame of this raw */ df->raw[r].spf += f->spf * count; - if (gd_alter_raw(df->D, f->name, f->type, df->raw[r].spf, 0)) + if (!append && gd_alter_raw(df->D, f->name, f->type, df->raw[r].spf, 0)) return DF_OUTPUT; } /* finalise buffer */ df->raw[r].framesize = GD_SIZE(f->type) * df->raw[r].spf; - df->raw[r].buflen = df->raw[r].framesize * df->config.buflen; + df->raw[r].buflen = df->raw[r].framesize * df->buflen; df->raw[r].out = df->raw[r].buflen - df->raw[r].framesize; ptr = realloc(df->raw[r].b, df->raw[r].buflen); if (ptr == NULL) { @@ -418,7 +473,7 @@ df->rframesize += fd->framesize * count; /* debug */ - if (df->config.mode_flags & DF_MODE_DEBUG) { + if (df_mode() & DF_MODE_DEBUG) { fprintf(stderr, "defile: fdef #%i (x%i):\ndefile: size: %lli bytes\n" "defile: [\n", df->nfd, count, (long long)df->fd[df->nfd].framesize); for (i = 0; i < fd->n_fields; ++i) { @@ -443,7 +498,7 @@ /* wait while the output does something */ static inline void df_wait_while_output_state(int state) { - if (df->config.mode_flags & DF_MODE_DEBUG) + if (df_mode() & DF_MODE_DEBUG) fprintf(stderr, "defile: input waiting on output for end of %s\n", DF_STATENAME(state)); while (df->output_state == state) @@ -463,27 +518,26 @@ return DF_SYSTEM; } } + + pthread_mutex_lock(&config_mx); if (rate >= 0) df->rate = rate; - df->nframes = (uint64_t)nframes; - df->offset = (uint64_t)offset; + df->nframes = nframes; + if (offset > df->offset) + df->offset = offset; + pthread_mutex_unlock(&config_mx); /* wait for the output thread to create the dirfile */ - DF_INSTATE_MX(INIT); + DF_INSTATE_MX(BUILD); df_wait_while_output_state(DF_ST_START); - pthread_mutex_lock(&state_mx); if (df->output_state != DF_ST_BUILD) { - /* something went wrong: stay in start state */ - DF_INSTATE(START); - pthread_mutex_unlock(&state_mx); - return DF_OUTPUT; + /* something went wrong: time for aborting */ + DF_INSTATE_MX(ABORT); + return df_input_abort(); } /* good to go */ - DF_INSTATE(BUILD); - pthread_mutex_unlock(&state_mx); - return DF_SUCCESS; } @@ -504,10 +558,55 @@ int df_ready(const char *reference) { - int missing = 0, set_reference = 1; + int i, missing = 0, set_reference = 1; + const int append = df_mode() & DF_MODE_APPEND; + unsigned long long offset; DF_CHECK_SEQUENCE(DF_ST_BUILD); + /* in append mode, make sure the input has defined all the existing raw + * fields, and that all raw fields it DID define are in the dirfile + */ + if (append) { + const char **fl; + gd_entry_t E; + + /* check fields defined by the input */ + for (i = 0; i < df->nraw; ++i) { + if (gd_entry(df->D, df->raw[i].name, &E)) + return DF_OUTPUT; + + if (E.field_type != GD_RAW_ENTRY) { + fprintf(stderr, "libdefile: existing raw field %s redefined as derived " + "type 0x%X\n", df->raw[i].name, E.field_type); + gd_free_entry_strings(&E); + return DF_OUTPUT; + } else if (E.spf != df->raw[i].spf) { + fprintf(stderr, "libdefile: existing raw field %s redefined with " + "different sample rate %u\n", df->raw[i].name, E.spf); + gd_free_entry_strings(&E); + return DF_OUTPUT; + } else if (E.data_type != df->raw[i].type) { + fprintf(stderr, "libdefile: existing raw field %s redefined with " + "different data type 0x%X\n", df->raw[i].name, E.data_type); + gd_free_entry_strings(&E); + return DF_OUTPUT; + } + gd_free_entry_strings(&E); + } + + /* cross-check fields defined in the existing dirifle */ + for (fl = gd_field_list_by_type(df->D, GD_RAW_ENTRY); *fl; ++fl) { + missing = 0; + df_rawsearch(df->raw, df->nraw, &missing, *fl); + if (missing) { + fprintf(stderr, "libdefile: missing definition of existing field %s", + *fl); + return DF_OUTPUT; + } + } + } + /* if there's no reference field given, or if the chosen reference field has * been excluded by the OFL, just use whichever one GetData was going to use * by default */ @@ -518,6 +617,7 @@ /* set the reference field, if possible */ if (reference) { + missing = 0; df->ref_ind = df_rawsearch(df->raw, df->nraw, &missing, reference); if (missing) { fprintf(stderr, "libdefile: internal error in input plugin: bad " @@ -528,6 +628,16 @@ gd_reference(df->D, reference); } + /* seek to the start frame */ + offset = df_offset(); + if (offset > 0) + for (i = 0; i < df->nraw; ++i) + if (gd_seek(df->D, df->raw[i].name, offset, 0, + GD_SEEK_SET | GD_SEEK_WRITE) < 0) + { + return DF_OUTPUT; + } + DF_INSTATE_MX(RUN); /* wait for the output thread to finish the metadata */ @@ -539,10 +649,9 @@ ssize_t df_nframes_allowed(int ifd) { int i; - size_t nf = df->config.buflen, n; + size_t nf = df->buflen, n; const struct df_infdef *fd = df->fd + ifd; - const struct df_raw *r; - unsigned long out; + struct df_raw *r; DF_CHECK_SEQUENCE(DF_ST_RUN); @@ -555,9 +664,10 @@ continue; r = df->raw + fd->field[i].index; - out = r->out; - n = (r->in == out) ? 0 : (r->buflen - - ((r->in + r->buflen - out) % r->buflen)) / fd->field[i].framesize; + pthread_mutex_lock(&r->mx); + n = (r->in == r->out) ? 0 : (r->buflen - + ((r->in + r->buflen - r->out) % r->buflen)) / fd->field[i].framesize; + pthread_mutex_unlock(&r->mx); if (n < nf) nf = n; } @@ -579,6 +689,7 @@ continue; r = df->raw + f->index; + pthread_mutex_lock(&r->mx); if (f->cadence == 0) { /* contiguous data */ if (r->in + f->framesize > r->buflen) { @@ -598,6 +709,7 @@ r->in = (r->in + GD_SIZE(r->type)) % r->buflen; } } + pthread_mutex_unlock(&r->mx); } } @@ -637,17 +749,19 @@ usleep(10000); } - if (df->config.mode_flags & DF_MODE_DEBUG && nf_total > 0) + if (df_mode() & DF_MODE_DEBUG) fprintf(stderr, "defile: buffered %zi of %zu %s offered of fdef #%i\n", nf_total, nf_offered, (nf_offered == 1) ? "frame" : "frames", ifd); /* update read counts */ + pthread_mutex_lock(&rate_mx); df->nread += (fd->framesize * nf_total) / df->rframesize; df->rpartial += (fd->framesize * nf_total) % df->rframesize; while (df->rpartial >= df->rframesize) { df->nread++; df->rpartial -= df->rframesize; } + pthread_mutex_unlock(&rate_mx); return nf_total; } @@ -655,9 +769,26 @@ int df_reinit(unsigned long long nframes, unsigned long long offset, double rate, const char *name, int mode) { - DF_CHECK_SEQUENCE2(DF_ST_RUN, DF_ST_INIT); + DF_CHECK_SEQUENCE(DF_ST_RUN); + /* update input */ + if (name) { + free(df->input); + df->input = strdup(name); + if (df->input == NULL) { + perror("libdefile: strdup"); + return DF_SYSTEM; + } + } + + /* restart */ + pthread_mutex_lock(&config_mx); + df->offset = offset; + df->mode_flags &= ~DF_MODE_APPEND; + pthread_mutex_unlock(&config_mx); + /* trigger and wait for completion of the output */ + DF_INSTATE_MX(BUILD); if (mode == DF_REINIT_DROP) { DF_OUTSTATE_MX(DROPSTART); df_wait_while_output_state(DF_ST_DROPSTART); @@ -667,36 +798,18 @@ } /* after the restart of the output we should either be in BUILD state, or - * else something's gone wrong. If something's gone wrong, either it's - * catastrophic and the output has already exited (ERROR state which will - * transition to ABORT the next time the main thread notices) or else there - * was an error with the dirfile's name, in which case we'll be in the INIT - * state - */ - pthread_mutex_lock(&state_mx); + * else something's gone wrong. If something's gone wrong, the output has + * already exited (ERROR), so we might as well skip a step and just tell the + * input to abort now. */ if (df->output_state != DF_ST_BUILD) { - /* half-finished? */ - DF_INSTATE(INIT); + DF_INSTATE_MX(ABORT); pthread_mutex_unlock(&state_mx); - return DF_OUTPUT; + return df_input_abort(); } - /* restart */ - DF_INSTATE(BUILD); - pthread_mutex_unlock(&state_mx); - if (rate >= 0) df->rate = rate; df->nframes = (uint64_t)nframes; - df->offset = (uint64_t)offset; - if (name) { - free(df->input); - df->input = strdup(name); - if (df->input == NULL) { - perror("libdefile: strdup"); - return DF_SYSTEM; - } - } return DF_SUCCESS; } @@ -768,6 +881,7 @@ int df_add_fragment(const char *subdir, const char *name, unsigned int encoding, unsigned long byte_sex, int parent) { + const int append = df_mode() & DF_MODE_APPEND; int ind; struct stat stat_buf; char *subdirpath; @@ -786,6 +900,13 @@ if (S_ISDIR(stat_buf.st_mode)) goto DF_HAVE_DIR; + if (append) { + fprintf(stderr, "libdefile: unexpected request for creation of " + "non-existant directory: %s\n", subdir); + free(subdirpath); + return DF_INPUT; + } + if (mkdir(subdirpath, 0777) == 0) goto DF_HAVE_DIR; free(subdirpath); @@ -805,14 +926,35 @@ perror("libdefile: strdup"); return DF_SYSTEM; } + if (append) + return 0; /* attempt to add the new fragment */ ind = gd_include(df->D, subdirpath, 0, GD_CREAT | GD_EXCL | encoding | byte_sex); free(subdirpath); + if (ind < 0) return DF_OUTPUT; return ind; } + +unsigned int df_mode(void) +{ + unsigned int mode; + pthread_mutex_lock(&config_mx); + mode = df->mode_flags; + pthread_mutex_unlock(&config_mx); + return mode; +} + +unsigned long long df_offset(void) +{ + unsigned long long offset; + pthread_mutex_lock(&config_mx); + offset = df->offset; + pthread_mutex_unlock(&config_mx); + return offset; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-22 01:39:55
|
Revision: 683 http://getdata.svn.sourceforge.net/getdata/?rev=683&view=rev Author: ketiltrout Date: 2012-03-22 01:39:48 +0000 (Thu, 22 Mar 2012) Log Message: ----------- * Fix SIE truncation. * Make return_type and num_{frames,samples} optional in Python's dirfile.getdata(). Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/bindings/python/pydirfile.c trunk/getdata/src/globals.c trunk/getdata/src/sie.c Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2012-03-21 00:21:47 UTC (rev 682) +++ trunk/getdata/ChangeLog 2012-03-22 01:39:48 UTC (rev 683) @@ -1,3 +1,9 @@ +2012-03-22 D. V. Wiebe <ge...@ke...> svn:683 + * src/sie.c (_GD_SampIndWrite): Fix file size calculation during truncation. + + * bindings/python/pydirfile.c (gdpy_dirfile_getdata): Make return_type and + num_<foo> optional. + 2012-03-16 D. V. Wiebe <ge...@ke...> svn:680 * src/globals.c (gd_flags gd_verbose_prefix): Added. * src/errors.c (_GD_SetError): Print verbose prefix, if present. Modified: trunk/getdata/bindings/python/pydirfile.c =================================================================== --- trunk/getdata/bindings/python/pydirfile.c 2012-03-21 00:21:47 UTC (rev 682) +++ trunk/getdata/bindings/python/pydirfile.c 2012-03-22 01:39:48 UTC (rev 683) @@ -575,6 +575,7 @@ const char* field_code; PY_LONG_LONG first_frame = 0, first_sample = 0; PyObject *num_frames_obj = NULL, *num_samples_obj = NULL; + PyObject *return_type_obj = NULL; long int num_frames = 0, num_samples = 0; int as_list = 0; gd_type_t return_type; @@ -585,22 +586,32 @@ #endif if (!PyArg_ParseTupleAndKeywords(args, keys, - "si|LLOOi:pygetdata.dirfile.getdata", keywords, &field_code, - &return_type, &first_frame, &first_sample, &num_frames_obj, + "s|OLLOOi:pygetdata.dirfile.getdata", keywords, &field_code, + &return_type_obj, &first_frame, &first_sample, &num_frames_obj, &num_samples_obj, &as_list)) { dreturn("%p", NULL); return NULL; } - - /* sanity check */ - if (num_frames_obj == NULL && num_samples_obj == NULL) { - PyErr_SetString(PyExc_ValueError, "pygetdata.dirfile.gd_getdata(): at " - "least one of num_frames and num_samples must be specified"); + + /* get return type */ + if (return_type_obj) { + return_type = (gd_type_t)PyInt_AsLong(return_type_obj); + if (PyErr_Occurred()) { dreturn("%p", NULL); return NULL; + } + } else { + return_type = gd_native_type(self->D, field_code); + PYGD_CHECK_ERROR(self->D, NULL); } + /* get num frames/samples */ + if (num_frames_obj == NULL && num_samples_obj == NULL) { + num_frames = gd_nframes(self->D); + PYGD_CHECK_ERROR(self->D, NULL); + } + if (num_frames_obj) { num_frames = PyInt_AsLong(num_frames_obj); if (num_frames == -1 && PyErr_Occurred()) { @@ -2708,7 +2719,7 @@ "and values, unlike the C API counterpart." }, {"getdata", (PyCFunction)gdpy_dirfile_getdata, METH_VARARGS | METH_KEYWORDS, - "getdata(field_code, return_type [, first_frame, first_sample,\n" + "getdata(field_code [, return_type, first_frame, first_sample,\n" "num_frames, num_samples, as_list])\n\n" "Retrieve a data vector from the dirfile. If NumPy support is\n" "present in pygetdata, and 'as_list' is not given or zero, a NumPy\n" @@ -2721,12 +2732,16 @@ "indicated. For list data it should be (typically) one of:\n" "pygetdata.INT, pygetdata.LONG, pygetdata.ULONG, pygetdata.FLOAT, or\n" "pygetdata.COMPLEX, although any GetData data type code is permitted.\n" + "If omitted, the return type defaults to the native type of the field\n" + "(see dirfile.native_type()).\n\n" + /* ------- handy ruler ---------------------------------------------| */ "The 'first_frame' and 'first_sample' parameters indicate first\n" "datum to read. If they are both omitted, data is read from the\n" "first sample. Similarly, 'num_frames' and 'num_samples' indicate\n" - "the amount of data. Omitting both of these results in an error.\n" - "Fewer samples than requested may be returned without causing an\n" - "error. See gd_getdata(3)." + "the amount of data. Omitting both is equivalent to setting\n" + "'num_frames' to dirfile.nframes (ie. all available data). Fewer\n" + "samples than requested may be returned without causing an error.\n" + "See gd_getdata(3)." }, { "entry", (PyCFunction)gdpy_dirfile_getentry, METH_VARARGS | METH_KEYWORDS, @@ -3137,7 +3152,6 @@ {"verbose_prefix", (PyCFunction)gdpy_dirfile_verbose_prefix, METH_VARARGS | METH_KEYWORDS, "verbose_prefix([prefix])\n\n" "Set the verbose prefix to prefix (if given) or else remove the\n" - /* ------- handy ruler ---------------------------------------------| */ "previously defined prefix. See gd_verbose_prefix (3)." }, { NULL, NULL, 0, NULL } Modified: trunk/getdata/src/globals.c =================================================================== --- trunk/getdata/src/globals.c 2012-03-21 00:21:47 UTC (rev 682) +++ trunk/getdata/src/globals.c 2012-03-22 01:39:48 UTC (rev 683) @@ -118,11 +118,11 @@ unsigned long gd_flags(DIRFILE *D, unsigned long set, unsigned long reset) gd_nothrow { - dtrace("%p, 0x%X, 0x%X", D, set, reset); + dtrace("%p, 0x%lX, 0x%lX", D, set, reset); if (D->flags & GD_INVALID) { _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); - dreturn("%p", 0); + dreturn("0x%X", 0); return 0; } @@ -134,7 +134,7 @@ D->flags = (D->flags | set) & ~(D->flags & reset); D->open_flags = (D->open_flags | set) & ~(D->open_flags & reset); - dreturn("0x%X", D->flags & GD_FLAG_MASK); + dreturn("0x%lX", D->flags & GD_FLAG_MASK); return D->flags & GD_FLAG_MASK; } @@ -145,8 +145,8 @@ if (D->flags & GD_INVALID) { _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); - dreturn("%p", 0); - return 0; + dreturn("%i", -1); + return -1; } _GD_ClearError(D); @@ -154,7 +154,7 @@ if (prefix) { ptr = _GD_Strdup(D, prefix); if (D->error) { - dreturn("%p", -1); + dreturn("%i", -1); return -1; } } Modified: trunk/getdata/src/sie.c =================================================================== --- trunk/getdata/src/sie.c 2012-03-21 00:21:47 UTC (rev 682) +++ trunk/getdata/src/sie.c 2012-03-22 01:39:48 UTC (rev 683) @@ -288,8 +288,7 @@ } ssize_t _GD_SampIndWrite(struct _gd_raw_file *restrict file, - const void *restrict ptr, - gd_type_t data_type, size_t nelem) + const void *restrict ptr, gd_type_t data_type, size_t nelem) { ssize_t nrec; void *p; @@ -406,11 +405,12 @@ } /* truncate the file if necessary */ - if (rin < rout) - if (gd_truncate(fileno(f->fp), nrec - rout + rin)) { + if (rin < rout) { + if (gd_truncate(fileno(f->fp), (nrec - rout + rin) * size)) { dreturn("%i", -1); return -1; } + } /* update the current record */ memcpy(f->d, (char *)p + (rin - 1) * size, size); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-21 00:21:54
|
Revision: 682 http://getdata.svn.sourceforge.net/getdata/?rev=682&view=rev Author: ketiltrout Date: 2012-03-21 00:21:47 +0000 (Wed, 21 Mar 2012) Log Message: ----------- Update. Modified Paths: -------------- trunk/getdata/man/gd_seek.3 Modified: trunk/getdata/man/gd_seek.3 =================================================================== --- trunk/getdata/man/gd_seek.3 2012-03-20 02:54:59 UTC (rev 681) +++ trunk/getdata/man/gd_seek.3 2012-03-21 00:21:47 UTC (rev 682) @@ -1,6 +1,6 @@ .\" gd_getdata.3. The gd_getdata man page. .\" -.\" Copyright (C) 2011 D. V. Wiebe +.\" Copyright (C) 2011, 2012 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_seek 3 "14 October 2011" "Version 0.8.0" "GETDATA" +.TH gd_seek 3 "21 March 2012" "Version 0.8.0" "GETDATA" .SH NAME gd_seek \(em reposition a dirfile field pointer .SH SYNOPSIS @@ -51,24 +51,24 @@ In addition to one of the symbols above, the .I flags parameter may also, optionally, be bitwise or'd with -.BR GD_SEEK_PAD , +.BR GD_SEEK_WRITE , which will result in the field being padded (with zero for integer types or a IEEE-754 conforming not-a-number otherwise) in the event of seeking past the end-of-field marker. Note: for some data encodings, the padding may be deferred until a write occurs. The result of calling .BR gd_seek () with -.BR GD_SEEK_PAD , +.BR GD_SEEK_WRITE , but without a subsequent call to .BR gd_putdata (3), is encoding specific, and may not actually advance the end of field. Attempting to seek past the end-of-field marker without specifying -.B GD_SEEK_PAD +.B GD_SEEK_WRITE is also encoding specific: in some encodings the field pointer will be moved past the end-of-field marker, while in others, it will result in an error. In general, -.B GD_SEEK_PAD +.B GD_SEEK_WRITE should be used on .BR gd_seek () calls before a write via @@ -76,13 +76,13 @@ while calls before a read via .BR gd_getdata (3) should omit the -.B GD_SEEK_PAD +.B GD_SEEK_WRITE flag. So the following: .IP .nh .ad l .BI "gd_seek(" dirfile ", " field_code ", " a ", " b , -.B GD_SEEK_SET | GD_SEEK_PAD); +.B GD_SEEK_SET | GD_SEEK_WRITE); .br .BI "gd_putdata(" dirfile ", "field_code ", GD_HERE, 0, " c ", " d ", " type , .IB data ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-20 02:55:06
|
Revision: 681 http://getdata.svn.sourceforge.net/getdata/?rev=681&view=rev Author: ketiltrout Date: 2012-03-20 02:54:59 +0000 (Tue, 20 Mar 2012) Log Message: ----------- IDL Modified Paths: -------------- trunk/getdata/bindings/idl/getdata.c trunk/getdata/bindings/idl/test/big_test.pro Modified: trunk/getdata/bindings/idl/getdata.c =================================================================== --- trunk/getdata/bindings/idl/getdata.c 2012-03-20 02:40:21 UTC (rev 680) +++ trunk/getdata/bindings/idl/getdata.c 2012-03-20 02:54:59 UTC (rev 681) @@ -5648,8 +5648,8 @@ unsigned long flags, set = 0, reset = 0; typedef struct { IDL_KW_RESULT_FIRST_FIELD; - GDIDL_KW_RESULT_ERRROR; - int pretty, verbose; + GDIDL_KW_RESULT_ERROR; + short int pretty, verbose; } KW_RESULT; KW_RESULT kw; @@ -5659,8 +5659,8 @@ static IDL_KW_PAR kw_pars[] = { GDIDL_KW_PAR_ERROR, GDIDL_KW_PAR_ESTRING, - { "PRETTY_PRINT", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(pathcheck) }, - { "VERBOSE", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(pathcheck) }, + { "PRETTY_PRINT", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(pretty) }, + { "VERBOSE", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(verbose) }, { NULL } }; @@ -5704,7 +5704,7 @@ KW_RESULT kw; GDIDL_KW_INIT_ERROR; - kw.fragment_index = kw.prefix_x = kw.suffix_x = 0; + kw.prefix_x = 0; static IDL_KW_PAR kw_pars[] = { GDIDL_KW_PAR_ERROR, Modified: trunk/getdata/bindings/idl/test/big_test.pro =================================================================== --- trunk/getdata/bindings/idl/test/big_test.pro 2012-03-20 02:40:21 UTC (rev 680) +++ trunk/getdata/bindings/idl/test/big_test.pro 2012-03-20 02:54:59 UTC (rev 681) @@ -1355,10 +1355,10 @@ ; 235: gd_flags check n = gd_flags(d, /PRETTY_PRINT) nume += check_ok(235, d) -nume += check_simple(235, n, !GD_PRETTY_PRINT) +nume += check_simple(235, n, !GD.PRETTY_PRINT) ; 236: gd_verbose_prefix -gd_verbose_prefix, d, "big_test" +gd_verbose_prefix, d, prefix="big_test" nume += check_ok(236, d) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-20 02:40:31
|
Revision: 680 http://getdata.svn.sourceforge.net/getdata/?rev=680&view=rev Author: ketiltrout Date: 2012-03-20 02:40:21 +0000 (Tue, 20 Mar 2012) Log Message: ----------- * gd_flags(), gd_verbose_prefix() + bindings * avoid FPE in _GD_FlushFragment * zero errno in _GD_Open * add misisng IDL open flags Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/bindings/cxx/dirfile.cpp trunk/getdata/bindings/cxx/getdata/dirfile.h trunk/getdata/bindings/cxx/test/big_test.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/simple_funcs.xsin trunk/getdata/bindings/perl/test/big_test.t trunk/getdata/bindings/python/pydirfile.c trunk/getdata/bindings/python/test/big_test.py trunk/getdata/configure.ac trunk/getdata/doc/list.tests trunk/getdata/src/add.c trunk/getdata/src/errors.c trunk/getdata/src/flush.c trunk/getdata/src/getdata.h.in trunk/getdata/src/globals.c trunk/getdata/src/internal.h trunk/getdata/src/open.c trunk/getdata/test/Makefile.am trunk/getdata/test/test.h Added Paths: ----------- trunk/getdata/test/error_verbose.c trunk/getdata/test/error_verbose_prefix.c trunk/getdata/test/global_flags.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2012-03-17 02:40:29 UTC (rev 679) +++ trunk/getdata/ChangeLog 2012-03-20 02:40:21 UTC (rev 680) @@ -1,3 +1,32 @@ +2012-03-16 D. V. Wiebe <ge...@ke...> svn:680 + * src/globals.c (gd_flags gd_verbose_prefix): Added. + * src/errors.c (_GD_SetError): Print verbose prefix, if present. + + * make_parameters.c: Promote GD_VERBOSE and GD_PRETTY_PRINT. + * bindings/cxx/dirfile.cpp (Dirfile::Flags Dirfile::VerbosePrefix) + bindings/python/pydirfile.c (gdpy_dirfile_getflags gdpy_dirfile_setflags + gdpy_dirfile_verbose_prefix) bindings/perl/simple_funcs.xsin (flags + verbose_prefix) bindings/f77/fgetdata.c (GDFLAG GDVBPX) + bindings/f77/getdata.f90.in (fgd_flags fgd_verbose_prefix) + bindings/idl/getdata.c (gdidl_flags gdidl_verbose_prefix): Added. + * bindings/python/test/big_test.py bindings/cxx/test/big_test.cpp + bindings/perl/test/big_test.t bindings/f77/test/big_test.f + bindings/f77/test/big_test95.f90 bindings/idl/test/big_test.pro: Add tests + 235, 236. + + * src/open.c (_GD_Open): Reset errno to prevent spurious error messages. + + * src/flush.c (_GD_FlushFragment): Avoid FPE. + + * test/global_flags.c test/error_verbose.c test/error_verbose_prefix.c: + Added. + + * bindings/idl/getdata.c (gdidl_open): Add missing IGNORE_REFS, + PRETTY_PRINT, TRUNCSUB. + + * bindings/f77/fgetdata.c (_GDF_CString): Take care of the malloc'ing rather + than forcing the caller to do it. + 2012-03-16 D. V. Wiebe <ge...@ke...> svn:678 * src/errors.c src/getdata.h.in: Add GD_E_EXISTS * src/open.c (_GD_CreateDirfile): Replace GD_E_CREAT:GD_E_CREAT_EXCL with Modified: trunk/getdata/bindings/cxx/dirfile.cpp =================================================================== --- trunk/getdata/bindings/cxx/dirfile.cpp 2012-03-17 02:40:29 UTC (rev 679) +++ trunk/getdata/bindings/cxx/dirfile.cpp 2012-03-20 02:40:21 UTC (rev 680) @@ -539,3 +539,13 @@ return desync; } + +unsigned long Dirfile::Flags(unsigned long set, unsigned long reset) +{ + return gd_flags(D, set, reset); +} + +void Dirfile::VerbosePrefix(const char *prefix) const +{ + gd_verbose_prefix(D, prefix); +} Modified: trunk/getdata/bindings/cxx/getdata/dirfile.h =================================================================== --- trunk/getdata/bindings/cxx/getdata/dirfile.h 2012-03-17 02:40:29 UTC (rev 679) +++ trunk/getdata/bindings/cxx/getdata/dirfile.h 2012-03-20 02:40:21 UTC (rev 680) @@ -131,6 +131,8 @@ const char *ErrorString(); const char *ErrorString(size_t n) gd_deprecated; + unsigned long Flags(unsigned long set = 0, unsigned long reset = 0); + const char **FieldList() const; const char **FieldListByType(EntryType type) const; @@ -259,6 +261,8 @@ int Validate(const char* field_code) const; + void VerbosePrefix(const char *prefix = NULL) const; + const char **VectorList() const; private: Modified: trunk/getdata/bindings/cxx/test/big_test.cpp =================================================================== --- trunk/getdata/bindings/cxx/test/big_test.cpp 2012-03-17 02:40:29 UTC (rev 679) +++ trunk/getdata/bindings/cxx/test/big_test.cpp 2012-03-20 02:40:21 UTC (rev 680) @@ -1658,13 +1658,22 @@ CHECK_OK(234); CHECK_INT(234, n, 0); + // 235: gd_flags check + n = d->Flags(GD_PRETTY_PRINT, 0); + CHECK_OK(235); + CHECK_INT(235, n, GD_PRETTY_PRINT); + // 236: gd_verbose_prefix + d->VerbosePrefix("big_test: "); + CHECK_OK(236); + + // =================================================================== d->Discard(); delete d; Modified: trunk/getdata/bindings/f77/fgetdata.c =================================================================== --- trunk/getdata/bindings/f77/fgetdata.c 2012-03-17 02:40:29 UTC (rev 679) +++ trunk/getdata/bindings/f77/fgetdata.c 2012-03-20 02:40:21 UTC (rev 680) @@ -64,18 +64,25 @@ } /* make a C string */ -static char* _GDF_CString(char* out, const char* in, int l) +static char *_GDF_CString(char **out, const char *in, int l) { int i; dtrace("%p, %p, %i", out, in, l); + if (l < 0) { + *out = NULL; + dreturn("%p", NULL); + return *out; + } + + *out = (char*)malloc(l + 1); for (i = 0; i < l; ++i) - out[i] = in[i]; - out[l] = '\0'; + (*out)[i] = in[i]; + (*out)[l] = '\0'; - dreturn("\"%s\"", out); - return out; + dreturn("\"%s\"", *out); + return *out; } /* convert an int to a DIRFILE* */ @@ -216,11 +223,11 @@ void F77_FUNC(gdopen, GDOPEN) (int* dirfile, const char* dirfilename, const int* dirfilename_l, const int* flags) { + char *out; + dtrace("%p, %p, %i, %i", dirfile, dirfilename, *dirfilename_l, *flags); - char* out = (char *)malloc(*dirfilename_l + 1); - - *dirfile = _GDF_SetDirfile(gd_open(_GDF_CString(out, dirfilename, + *dirfile = _GDF_SetDirfile(gd_open(_GDF_CString(&out, dirfilename, *dirfilename_l), *flags)); free(out); @@ -251,8 +258,8 @@ if (field_code_l == 0) gd_flush(_GDF_GetDirfile(*dirfile), NULL); else { - char *out = (char *)malloc(*field_code_l + 1); - gd_flush(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + char *out; + gd_flush(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l)); free(out); } @@ -267,13 +274,13 @@ const int* num_frames, const int* num_samples, const int* return_type, void* data_out) { + char *out; + dtrace("%p, %i, %p, %i, %i, %i, %i, %i, 0x%x, %p", n_read, *dirfile, field_code, *field_code_l, *first_frame, *first_sample, *num_frames, *num_samples, *return_type, data_out); - char* out = (char *)malloc(*field_code_l + 1); - - *n_read = gd_getdata(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + *n_read = gd_getdata(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), *first_frame, *first_sample, *num_frames, *num_samples, (gd_type_t)*return_type, data_out); free(out); @@ -286,19 +293,24 @@ { const char **fl; size_t len = 0; - DIRFILE* D = _GDF_GetDirfile(*dirfile); - unsigned int i, nfields = gd_nfields(D); + DIRFILE* D; + unsigned int i, nfields; - if (D->error) - return; + dtrace("%p, %i", max, *dirfile); - fl = gd_field_list(D); + D = _GDF_GetDirfile(*dirfile); + nfields = gd_nfields(D); - for (i = 0; i < nfields; ++i) - if (strlen(fl[i]) > len) - len = strlen(fl[i]); + if (!D->error) { + fl = gd_field_list(D); + for (i = 0; i < nfields; ++i) + if (strlen(fl[i]) > len) + len = strlen(fl[i]); + } + *max = len; + dreturn("%i", *max); } /* Return the maximum field name length for a meta list */ @@ -309,26 +321,25 @@ unsigned int i, nfields; size_t len = 0; DIRFILE* D = _GDF_GetDirfile(*dirfile); - char* pa = (char *)malloc(*parent_l + 1); + char *pa; - _GDF_CString(pa, parent, *parent_l); + dtrace("%p, %i, %p, %i", max, *dirfile, parent, *parent_l); + _GDF_CString(&pa, parent, *parent_l); nfields = gd_nmfields(D, pa); - if (D->error) { - free(pa); - return; + if (!D->error) { + fl = gd_mfield_list(D, pa); + + for (i = 0; i < nfields; ++i) + if (strlen(fl[i]) > len) + len = strlen(fl[i]); } - fl = gd_mfield_list(D, pa); - - for (i = 0; i < nfields; ++i) - if (strlen(fl[i]) > len) - len = strlen(fl[i]); - *max = len; free(pa); + dreturn("%i", *max); } /* gd_field_list wrapper -- this only returns one field name */ @@ -336,16 +347,21 @@ const int* field_num) { const char** fl; - DIRFILE* D = _GDF_GetDirfile(*dirfile); - unsigned int nfields = gd_nfields(D); - if (D->error) - return; + DIRFILE* D; + unsigned int nfields; - if (*field_num > 0 && *field_num <= (int)nfields) { + dtrace("%p, %p, %i, %i", name, name_l, *dirfile, *field_num); + + D = _GDF_GetDirfile(*dirfile); + nfields = gd_nfields(D); + + if (!D->error && *field_num > 0 && *field_num <= (int)nfields) { fl = gd_field_list(D); _GDF_FString(name, name_l, fl[*field_num - 1]); } else *name_l = 0; + + dreturn("%i", *name_l); } /* gd_mfield_list wrapper -- this only returns one field name */ @@ -355,23 +371,23 @@ const char** fl; unsigned int nfields; DIRFILE* D = _GDF_GetDirfile(*dirfile); - char* pa = (char *)malloc(*parent_l + 1); + char *pa; - _GDF_CString(pa, parent, *parent_l); + dtrace("%p, %p, %i, %p, %i, %i", name, name_l, *dirfile, parent, *parent_l, + *field_num); + _GDF_CString(&pa, parent, *parent_l); nfields = gd_nmfields(D, pa); - if (D->error) { - free(pa); - return; - } - if (*field_num > 0 && *field_num <= (int)nfields) { + if (!D->error && *field_num > 0 && *field_num <= (int)nfields) { fl = gd_mfield_list(D, pa); _GDF_FString(name, name_l, fl[*field_num - 1]); } else *name_l = 0; free(pa); + + dreturn("%i", *name_l); } /* gd_nfields wrapper */ @@ -384,20 +400,28 @@ void F77_FUNC(gdgbof, GDGBOF) (int* bof, const int* dirfile, const char* field_code, const int* field_code_l) { - char *fc = (char *)malloc(*field_code_l + 1); - *bof = gd_bof(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + char* fc; + dtrace("%p, %i, %p, %i", bof, *dirfile, field_code, *field_code_l); + + *bof = gd_bof(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l)); + free(fc); + dreturn("%i", *bof); } /* gd_eof wrapper */ void F77_FUNC(gdgeof, GDGEOF) (int* eof, const int* dirfile, const char* field_code, const int* field_code_l) { - char *fc = (char *)malloc(*field_code_l + 1); - *eof = gd_eof(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + char *fc; + dtrace("%p, %i, %p, %i", eof, *dirfile, field_code, *field_code_l); + + *eof = gd_eof(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l)); free(fc); + + dreturn("%i", *eof); } /* gd_nframes wrapper */ @@ -410,10 +434,13 @@ void F77_FUNC(gdgspf, GDGSPF) (int* spf, const int* dirfile, const char* field_code, const int* field_code_l) { - char* out = (char *)malloc(*field_code_l + 1); + char* out; + dtrace("%p, %i, %p, %i", spf, *dirfile, field_code, *field_code_l); + *spf = gd_spf(_GDF_GetDirfile(*dirfile), - _GDF_CString(out, field_code, *field_code_l)); + _GDF_CString(&out, field_code, *field_code_l)); free(out); + dreturn("%i", *spf); } /* gd_putdata wrapper */ @@ -422,13 +449,13 @@ const int* first_sample, const int* num_frames, const int* num_samples, const int* data_type, const void* data_in) { + char *out; dtrace("%p, %i, %p, %i, %i, %i, %i, %i, 0x%x, %p", n_wrote, *dirfile, field_code, *field_code_l, *first_frame, *first_sample, *num_frames, *num_samples, *data_type, data_in); - char* out = (char *)malloc(*field_code_l + 1); - *n_wrote = gd_putdata(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, - *field_code_l), *first_frame, *first_sample, *num_frames, + *n_wrote = gd_putdata(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, + field_code, *field_code_l), *first_frame, *first_sample, *num_frames, *num_samples, (gd_type_t)*data_type, data_in); free(out); @@ -477,9 +504,7 @@ dtrace("%p, %i, %p, %i", type, *dirfile, field_code, *field_code_l); - fc = (char *)malloc(*field_code_l + 1); - - *type = (int)gd_entry_type(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, + *type = (int)gd_entry_type(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l)); free(fc); @@ -497,9 +522,7 @@ dtrace("%p, %p, %p, %i, %p, %i", spf, dtype, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_RAW_ENTRY) *spf = 0; else { @@ -530,9 +553,7 @@ infield3, infield3_l, m3, b3, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_LINCOM_ENTRY) *nfields = 0; else { @@ -577,9 +598,7 @@ infield3, infield3_l, m3, b3, fragment_index, *dirfile, field_code, *field_code_l); - fc = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), &E)) *nfields = 0; else if (E.field_type != GD_LINCOM_ENTRY) { @@ -625,9 +644,7 @@ infield, *infield_l, a0, a1, a2, a3, a4, a5, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_POLYNOM_ENTRY) *poly_ord = 0; else { @@ -669,9 +686,7 @@ infield, *infield_l, a0, a1, a2, a3, a4, a5, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_POLYNOM_ENTRY) *poly_ord = 0; else { @@ -712,9 +727,7 @@ dtrace("%p, %i, %p, %i, %p, %i, %p, %i", in_field, *in_field_l, table, *table_l, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_LINTERP_ENTRY) *in_field_l = 0; else { @@ -739,9 +752,7 @@ dtrace("%p, %i, %p, %p, %p, %i, %p, %i", in_field, *in_field_l, bitnum, numbits, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_BIT_ENTRY) *in_field_l = 0; else { @@ -767,9 +778,7 @@ dtrace("%p, %i, %p, %p, %p, %i, %p, %i", in_field, *in_field_l, bitnum, numbits, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_SBIT_ENTRY) *in_field_l = 0; else { @@ -796,9 +805,7 @@ in_field2, *in_field2_l, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_MULTIPLY_ENTRY) *in_field1_l = 0; else { @@ -824,9 +831,7 @@ in_field2, *in_field2_l, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_DIVIDE_ENTRY) *in_field1_l = 0; else { @@ -854,9 +859,7 @@ check_field, *check_field_l, windop, ithreshold, rthreshold, fragment_index, *dirfile, field_code, *field_code_l); - fc = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), &E) || E.field_type != GD_WINDOW_ENTRY) *in_field_l = 0; else { @@ -898,9 +901,7 @@ count_field, *count_field_l, val, max, fragment_index, *dirfile, field_code, *field_code_l); - fc = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), &E) || E.field_type != GD_MPLEX_ENTRY) *in_field_l = 0; else { @@ -928,9 +929,7 @@ dtrace("%p, %i, %p, %p, %i, %p, %i", in_field, *in_field_l, dividend, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_RECIP_ENTRY) *in_field_l = 0; else { @@ -955,9 +954,7 @@ dtrace("%p, %i, %p, %p, %i, %p, %i", in_field, *in_field_l, cdividend, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_RECIP_ENTRY) *in_field_l = 0; else { @@ -983,9 +980,7 @@ dtrace("%p, %i, %p, %p, %i, %p, %i", in_field, *in_field_l, shift, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_PHASE_ENTRY) *in_field_l = 0; else { @@ -1009,9 +1004,7 @@ dtrace("%p, %p, %i, %p, %i", data_type, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_CONST_ENTRY) *data_type = 0; else { @@ -1035,9 +1028,7 @@ dtrace("%p, %p, %p, %i, %p, %i", data_type, array_len, fragment_index, *dirfile, field_code, *field_code_l); - out = (char *)malloc(*field_code_l + 1); - - if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + if (gd_entry(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), &E) || E.field_type != GD_CARRAY_ENTRY) *data_type = 0; else { @@ -1055,13 +1046,12 @@ void F77_FUNC(gdfrgi, GDFRGI) (int* fragment_index, const int* dirfile, const char* field_code, const int* field_code_l) { + char *fc; dtrace("%p, %i, %p, %i", fragment_index, *dirfile, field_code, *field_code_l); - char* fc = (char *)malloc(*field_code_l + 1); - *fragment_index = gd_fragment_index(_GDF_GetDirfile(*dirfile), - _GDF_CString(fc, field_code, *field_code_l)); + _GDF_CString(&fc, field_code, *field_code_l)); free(fc); @@ -1073,11 +1063,16 @@ const int* field_code_l, const int* data_type, const int* spf, const int* fragment_index) { - char* out = (char *)malloc(*field_code_l + 1); - gd_add_raw(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + char *out; + + dtrace("%i, %p, %i, %i, %i, %i", *dirfile, field_code, *field_code_l, + *data_type, *spf, *fragment_index); + + gd_add_raw(_GDF_GetDirfile(*dirfile), _GDF_CString(&out, field_code, *field_code_l), (gd_type_t)(*data_type), (gd_spf_t)*spf, *fragment_index); free(out); + dreturnvoid(); } /* gd_add_lincom wrapper */ @@ -1088,39 +1083,42 @@ const double* b2, const char* in_field3, const int* in_field3_l, const double* m3, const double* b3, const int* fragment_index) { - char* fc = (char *)malloc(*field_code_l + 1); + char *fc; char* in_fields[3] = {NULL, NULL, NULL}; double m[3] = {0, 0, 0}; double b[3] = {0, 0, 0}; - int nf = *n_fields; + const int nf = *n_fields; + dtrace("%i, %p, %i, %i, %p, %i, %p, %p, %p, %i, %p, %p, %p, %i, %p, %p, %i", + *dirfile, field_code, *field_code_l, *n_fields, in_field1, *in_field1_l, + m1, b1, in_field2, *in_field2_l, m2, b2, in_field3, *in_field3_l, m3, b3, + *fragment_index); + if (nf > 0) { - in_fields[0] = (char *)malloc(*in_field1_l + 1); - _GDF_CString(in_fields[0], in_field1, *in_field1_l); + _GDF_CString(in_fields, in_field1, *in_field1_l); m[0] = *m1; b[0] = *b1; } if (nf > 1) { - in_fields[1] = (char *)malloc(*in_field2_l + 1); - _GDF_CString(in_fields[1], in_field2, *in_field2_l); + _GDF_CString(in_fields + 1, in_field2, *in_field2_l); m[1] = *m2; b[1] = *b2; } if (nf > 2) { - in_fields[2] = (char *)malloc(*in_field3_l + 1); - _GDF_CString(in_fields[2], in_field3, *in_field3_l); + _GDF_CString(in_fields + 2, in_field3, *in_field3_l); m[2] = *m3; b[2] = *b3; } - gd_add_lincom(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + gd_add_lincom(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), nf, (const char**)in_fields, m, b, *fragment_index); free(fc); free(in_fields[0]); free(in_fields[1]); free(in_fields[2]); + dreturnvoid(); } void F77_FUNC(gdadcl, GDADCL) (const int* dirfile, const char* field_code, @@ -1131,7 +1129,7 @@ const GD_DCOMPLEXP(m3), const GD_DCOMPLEXP(b3), const int* fragment_index) { - char* fc = (char *)malloc(*field_code_l + 1); + char *fc; char* in_fields[3] = {NULL, NULL, NULL}; #ifdef GD_NO_C99_API double cm[6] = {0, 0, 0, 0, 0, 0}; @@ -1140,35 +1138,38 @@ double complex cm[3] = {0, 0, 0}; double complex cb[3] = {0, 0, 0}; #endif - int nf = *n_fields; + const int nf = *n_fields; + dtrace("%i, %p, %i, %i, %p, %i, %p, %p, %p, %i, %p, %p, %p, %i, %p, %p, %i", + *dirfile, field_code, *field_code_l, *n_fields, in_field1, *in_field1_l, + m1, b1, in_field2, *in_field2_l, m2, b2, in_field3, *in_field3_l, m3, b3, + *fragment_index); + if (nf > 0) { - in_fields[0] = (char *)malloc(*in_field1_l + 1); - _GDF_CString(in_fields[0], in_field1, *in_field1_l); + _GDF_CString(in_fields, in_field1, *in_field1_l); _gd_cp2ca(cm, 0, m1); _gd_cp2ca(cb, 0, b1); } if (nf > 1) { - in_fields[1] = (char *)malloc(*in_field2_l + 1); - _GDF_CString(in_fields[1], in_field2, *in_field2_l); + _GDF_CString(in_fields + 1, in_field2, *in_field2_l); _gd_cp2ca(cm, 1, m2); _gd_cp2ca(cb, 1, b2); } if (nf > 2) { - in_fields[2] = (char *)malloc(*in_field3_l + 1); - _GDF_CString(in_fields[2], in_field3, *in_field3_l); + _GDF_CString(in_fields + 2, in_field3, *in_field3_l); _gd_cp2ca(cm, 2, m3); _gd_cp2ca(cb, 2, b3); } - gd_add_clincom(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + gd_add_clincom(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), nf, (const char**)in_fields, cm, cb, *fragment_index); free(fc); free(in_fields[0]); free(in_fields[1]); free(in_fields[2]); + dreturnvoid(); } /* gd_add_polynom wrapper */ @@ -1178,16 +1179,15 @@ const double* a3, const double* a4, const double* a5, const int* fragment_index) { - char* fc = (char *)malloc(*field_code_l + 1); - char* inf = NULL; + char *fc, *inf; double a[6] = {0, 0, 0, 0, 0, 0}; - int po = *poly_ord; - if (po > 5) - po = 5; + const int po = (*poly_ord > 5) ? 5 : *poly_ord; - inf = (char *)malloc(*in_field_l + 1); - _GDF_CString(inf, in_field, *in_field_l); + dtrace("%i, %p, %i, %i, %p, %i, %p, %p, %p, %p, %p, %p", *dirfile, field_code, + *field_code_l, *poly_ord, in_field, *in_field_l, a0, a1, a2, a3, a4, a5); + _GDF_CString(&inf, in_field, *in_field_l); + switch (po) { case 5: a[5] = *a5; @@ -1202,10 +1202,11 @@ a[0] = *a0; } - gd_add_polynom(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + gd_add_polynom(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), po, inf, a, *fragment_index); free(fc); free(inf); + dreturnvoid(); } void F77_FUNC(gdadcp, GDADCP) (const int* dirfile, const char* field_code, @@ -1215,20 +1216,19 @@ const GD_DCOMPLEXP(a4), const GD_DCOMPLEXP(a5), const int* fragment_index) { - char* fc = (char *)malloc(*field_code_l + 1); - char* inf = NULL; + char *fc, *inf; #ifdef GD_NO_C99_API double ca[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; #else double complex ca[6] = {0, 0, 0, 0, 0, 0}; #endif - int po = *poly_ord; - if (po > 5) - po = 5; + const int po = (*poly_ord > 5) ? 5 : *poly_ord; - inf = (char *)malloc(*in_field_l + 1); - _GDF_CString(inf, in_field, *in_field_l); + dtrace("%i, %p, %i, %i, %p, %i, %p, %p, %p, %p, %p, %p", *dirfile, field_code, + *field_code_l, *poly_ord, in_field, *in_field_l, a0, a1, a2, a3, a4, a5); + _GDF_CString(&inf, in_field, *in_field_l); + switch (po) { case 5: _gd_cp2ca(ca, 5, a5); @@ -1243,10 +1243,11 @@ _gd_cp2ca(ca, 0, a0); } - gd_add_cpolynom(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + gd_add_cpolynom(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), po, inf, ca, *fragment_index); free(fc); free(inf); + dreturnvoid(); } /* gd_add_linterp wrapper */ @@ -1254,16 +1255,18 @@ const int* field_code_l, const char* in_field, const int* in_field_l, const char* table, const int* table_l, const int* fragment_index) { - char* fc = (char *)malloc(*field_code_l + 1); - char* in = (char *)malloc(*in_field_l + 1); - char* tab = (char *)malloc(*table_l + 1); + char *fc, *in, *tab; - gd_add_linterp(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, - *field_code_l), _GDF_CString(in, in_field, *in_field_l), - _GDF_CString(tab, table, *table_l), *fragment_index); + dtrace("%i, %p, %i, %p, %i, %p, %i, %i", *dirfile, field_code, *field_code_l, + in_field, *in_field_l, table, *table_l, *fragment_index); + + gd_add_linterp(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, + *field_code_l), _GDF_CString(&in, in_field, *in_field_l), + _GDF_CString(&tab, table, *table_l), *fragment_index); free(fc); free(in); free(tab); + dreturnvoid(); } /* gd_add_bit wrapper */ @@ -1271,14 +1274,17 @@ const int* field_code_l, const char* in_field, const int* in_field_l, const int* bitnum, const int* numbits, const int* fragment_index) { - char* fc = (char *)malloc(*field_code_l + 1); - char* in = (char *)malloc(*in_field_l + 1); + char *fc, *in; - gd_add_bit(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, - *field_code_l), _GDF_CString(in, in_field, *in_field_l), + dtrace("%i, %p, %i, %p, %i, %i, %i, %i", *dirfile, field_code, *field_code_l, + in_field, *in_field_l, *bitnum, *numbits, *fragment_index); + + gd_add_bit(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, + *field_code_l), _GDF_CString(&in, in_field, *in_field_l), (gd_bit_t)*bitnum, (gd_bit_t)*numbits, *fragment_index); free(fc); free(in); + dreturnvoid(); } /* gd_add_sbit wrapper */ @@ -1286,14 +1292,17 @@ const int* field_code_l, const char* in_field, const int* in_field_l, const int* bitnum, const int* numbits, const int* fragment_index) { - char* fc = (char *)malloc(*field_code_l + 1); - char* in = (char *)malloc(*in_field_l + 1); + char *fc, *in; - gd_add_sbit(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, - *field_code_l), _GDF_CString(in, in_field, *in_field_l), + dtrace("%i, %p, %i, %p, %i, %i, %i, %i", *dirfile, field_code, *field_code_l, + in_field, *in_field_l, *bitnum, *numbits, *fragment_index); + + gd_add_sbit(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, + *field_code_l), _GDF_CString(&in, in_field, *in_field_l), (gd_bit_t)*bitnum, (gd_bit_t)*numbits, *fragment_index); free(fc); free(in); + dreturnvoid(); } /* gd_add_multiply wrapper */ @@ -1301,17 +1310,19 @@ const int* field_code_l, const char* in_field1, const int* in_field1_l, const char* in_field2, const int* in_field2_l, const int* fragment_index) { - char* fc = (char *)malloc(*field_code_l + 1); - char* in1 = (char *)malloc(*in_field1_l + 1); - char* in2 = (char *)malloc(*in_field2_l + 1); + char *fc, *in1, *in2; - gd_add_multiply(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, - *field_code_l), _GDF_CString(in1, in_field1, *in_field1_l), - _GDF_CString(in2, in_field2, *in_field2_l), *fragment_index); + dtrace("%i, %p, %i, %p, %i, %p, %i, %i", *dirfile, field_code, *field_code_l, + in_field1, *in_field1_l, in_field2, *in_field2_l, *fragment_index); + gd_add_multiply(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, + *field_code_l), _GDF_CString(&in1, in_field1, *in_field1_l), + _GDF_CString(&in2, in_field2, *in_field2_l), *fragment_index); + free(fc); free(in1); free(in2); + dreturnvoid(); } /* gd_add_divide wrapper */ @@ -1324,14 +1335,10 @@ dtrace("%i, %p, %i, %p, %i, %p, %i, %i", *dirfile, field_code, *field_code_l, in_field1, *in_field1_l, in_field2, *in_field2_l, *fragment_index); - fc = (char *)malloc(*field_code_l + 1); - in1 = (char *)malloc(*in_field1_l + 1); - in2 = (char *)malloc(*in_field2_l + 1); + gd_add_divide(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, + *field_code_l), _GDF_CString(&in1, in_field1, *in_field1_l), + _GDF_CString(&in2, in_field2, *in_field2_l), *fragment_index); - gd_add_divide(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, - *field_code_l), _GDF_CString(in1, in_field1, *in_field1_l), - _GDF_CString(in2, in_field2, *in_field2_l), *fragment_index); - free(fc); free(in1); free(in2); @@ -1349,11 +1356,8 @@ dtrace("%i, %p, %i, %p, %i, %g, %i", *dirfile, field_code, *field_code_l, in_field, *in_field_l, *dividend, *fragment_index); - fc = (char *)malloc(*field_code_l + 1); - in = (char *)malloc(*in_field_l + 1); - - gd_add_recip(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, - *field_code_l), _GDF_CString(in, in_field, *in_field_l), *dividend, + gd_add_recip(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, + *field_code_l), _GDF_CString(&in, in_field, *in_field_l), *dividend, *fragment_index); free(fc); @@ -1372,16 +1376,13 @@ in_field, *in_field_l, crealp(cdividend), cimagp(cdividend), *fragment_index); - fc = (char *)malloc(*field_code_l + 1); - in = (char *)malloc(*in_field_l + 1); - #ifdef GD_NO_C99_API - gd_add_crecip89(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, - *field_code_l), _GDF_CString(in, in_field, *in_field_l), cdividend, + gd_add_crecip89(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, + *field_code_l), _GDF_CString(&in, in_field, *in_field_l), cdividend, *fragment_index); #else - gd_add_crecip(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, - *field_code_l), _GDF_CString(in, in_field, *in_field_l), *cdividend, + gd_add_crecip(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, + *field_code_l), _GDF_CString(&in, in_field, *in_field_l), *cdividend, *fragment_index); #endif @@ -1396,15 +1397,18 @@ const int* field_code_l, const char* in_field, const int* in_field_l, const int* shift, const int* fragment_index) { - char* fc = (char *)malloc(*field_code_l + 1); - char* in = (char *)malloc(*in_field_l + 1); + char *fc, *in; - gd_add_phase(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, - *field_code_l), _GDF_CString(in, in_field, *in_field_l), *shift, + dtrace("%i, %p, %i, %p, %i, %i, %i", *dirfile, field_code, *field_code_l, + in_field, *in_field_l, *shift, *fragment_index); + + gd_add_phase(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, + *field_code_l), _GDF_CString(&in, in_field, *in_field_l), *shift, *fragment_index); free(fc); free(in); + dreturnvoid(); } /* gd_fragmentname wrapper */ @@ -1447,12 +1451,16 @@ void F77_FUNC(gdincl, GDINCL) (const int* dirfile, const char* file, const int* file_l, const int* fragment_index, const int* flags) { - char* fi = (char *)malloc(*file_l + 1); + char *fi; - gd_include(_GDF_GetDirfile(*dirfile), _GDF_CString(fi, file, *file_l), + dtrace("%i, %p, %i, %i, 0x%X", *dirfile, file, *file_l, *fragment_index, + *flags); + + gd_include(_GDF_GetDirfile(*dirfile), _GDF_CString(&fi, file, *file_l), *fragment_index, *flags); free(fi); + dreturnvoid(); } /* gd_nfield_by_type wrapper */ @@ -1477,16 +1485,21 @@ const int* type, const int* field_num) { const char** fl; - DIRFILE* D = _GDF_GetDirfile(*dirfile); - unsigned int nfields = gd_nfields_by_type(D, (gd_entype_t)*type); - if (D->error) - return; + DIRFILE* D; + unsigned int nfields; - if (*field_num > 0 && *field_num <= (int)nfields) { + dtrace("%p, %p, %i, 0x%X, %i", name, name_l, *dirfile, *type, *field_num); + + D = _GDF_GetDirfile(*dirfile); + nfields = gd_nfields_by_type(D, (gd_entype_t)*type); + + if (!D->error && *field_num > 0 && *field_num <= (int)nfields) { fl = gd_field_list_by_type(D, (gd_entype_t)*type); _GDF_FString(name, name_l, fl[*field_num - 1]); } else *name_l = 0; + + dreturn("%i", *name_l); } /* gd_vector_list wrapper -- this only returns one field name */ @@ -1502,16 +1515,13 @@ D = _GDF_GetDirfile(*dirfile); nfields = gd_nvectors(D); - if (D->error) - return; - - if (*field_num > 0 && *field_num <= (int)nfields) { + if (!D->error && *field_num > 0 && *field_num <= (int)nfields) { fl = gd_vector_list(D); _GDF_FString(name, name_l, fl[*field_num - 1]); } else *name_l = 0; - dreturnvoid(); + dreturn("%i", *name_l); } /* gd_mfield_list_by_type wrapper -- this only returns one field name */ @@ -1528,18 +1538,14 @@ *parent_l, *type, *field_num); D = _GDF_GetDirfile(*dirfile); - pa = (char *)malloc(*parent_l + 1); + _GDF_CString(&pa, parent, *parent_l); - _GDF_CString(pa, parent, *parent_l); - nfields = gd_nmfields_by_type(D, pa, (gd_entype_t)*type); - if (!D->error) { - if (*field_num > 0 && *field_num <= (int)nfields) { - fl = gd_mfield_list_by_type(D, pa, (gd_entype_t)*type); - _GDF_FString(name, name_l, fl[*field_num - 1]); - } else - *name_l = 0; - } + if (!D->error && *field_num > 0 && *field_num <= (int)nfields) { + fl = gd_mfield_list_by_type(D, pa, (gd_entype_t)*type); + _GDF_FString(name, name_l, fl[*field_num - 1]); + } else + *name_l = 0; free(pa); dreturnvoid(); @@ -1551,24 +1557,23 @@ { const char** fl; unsigned int nfields; - DIRFILE* D = _GDF_GetDirfile(*dirfile); - char* pa = (char *)malloc(*parent_l + 1); + DIRFILE* D; + char* pa; - _GDF_CString(pa, parent, *parent_l); + dtrace("%p, %p, %i, %i", name, name_l, *dirfile, *field_num); + D = _GDF_GetDirfile(*dirfile); + _GDF_CString(&pa, parent, *parent_l); + nfields = gd_nmvectors(D, pa); - if (D->error) { - free(pa); - return; - } - - if (*field_num > 0 && *field_num <= (int)nfields) { + if (!D->error && *field_num > 0 && *field_num <= (int)nfields) { fl = gd_mvector_list(D, pa); _GDF_FString(name, name_l, fl[*field_num - 1]); } else *name_l = 0; free(pa); + dreturn("%i", *name_l); } /* gd_madd_lincom wrapper */ @@ -1580,42 +1585,44 @@ const char* in_field3, const int* in_field3_l, const double* m3, const double* b3) { - char* pa = (char *)malloc(*parent_l + 1); - char* fc = (char *)malloc(*field_code_l + 1); + char *pa, *fc; char* in_fields[3] = {NULL, NULL, NULL}; double m[3] = {0, 0, 0}; double b[3] = {0, 0, 0}; - int nf = *n_fields; + const int nf = *n_fields; + dtrace("%i, %p, %i, %p, %i, %i, %p, %i, %p, %p, %p, %i, %p, %p, %p, %i, %p, " + "%p", *dirfile, parent, *parent_l, field_code, *field_code_l, *n_fields, + in_field1, *in_field1_l, m1, b1, in_field2, *in_field2_l, m2, b2, + in_field3, *in_field3_l, m3, b3); + if (nf > 0) { - in_fields[0] = (char *)malloc(*in_field1_l + 1); - _GDF_CString(in_fields[0], in_field1, *in_field1_l); + _GDF_CString(in_fields, in_field1, *in_field1_l); m[0] = *m1; b[0] = *b1; } if (nf > 1) { - in_fields[1] = (char *)malloc(*in_field2_l + 1); - _GDF_CString(in_fields[1], in_field2, *in_field2_l); + _GDF_CString(in_fields + 1, in_field2, *in_field2_l); m[1] = *m2; b[1] = *b2; } if (nf > 2) { - in_fields[2] = (char *)malloc(*in_field3_l + 1); - _GDF_CString(in_fields[2], in_field3, *in_field3_l); + _GDF_CString(in_fields + 2, in_field3, *in_field3_l); m[2] = *m3; b[2] = *b3; } - gd_madd_lincom(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), nf, + gd_madd_lincom(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), nf, (const char**)in_fields, m, b); free(pa); free(fc); free(in_fields[0]); free(in_fields[1]); free(in_fields[2]); + dreturnvoid(); } void F77_FUNC(gdmdcl, GDMDCL) (const int* dirfile, const char* parent, @@ -1626,8 +1633,7 @@ const char* in_field3, const int* in_field3_l, const GD_DCOMPLEXP(m3), const GD_DCOMPLEXP(b3)) { - char* pa = (char *)malloc(*parent_l + 1); - char* fc = (char *)malloc(*field_code_l + 1); + char *pa, *fc; char* in_fields[3] = {NULL, NULL, NULL}; #ifdef GD_NO_C99_API double cm[6] = {0, 0, 0, 0, 0, 0}; @@ -1636,37 +1642,40 @@ double complex cm[3] = {0, 0, 0}; double complex cb[3] = {0, 0, 0}; #endif - int nf = *n_fields; + const int nf = *n_fields; + dtrace("%i, %p, %i, %p, %i, %i, %p, %i, %p, %p, %p, %i, %p, %p, %p, %i, %p, " + "%p", *dirfile, parent, *parent_l, field_code, *field_code_l, *n_fields, + in_field1, *in_field1_l, m1, b1, in_field2, *in_field2_l, m2, b2, + in_field3, *in_field3_l, m3, b3); + if (nf > 0) { - in_fields[0] = (char *)malloc(*in_field1_l + 1); - _GDF_CString(in_fields[0], in_field1, *in_field1_l); + _GDF_CString(in_fields, in_field1, *in_field1_l); _gd_cp2ca(cm, 0, m1); _gd_cp2ca(cb, 0, b1); } if (nf > 1) { - in_fields[1] = (char *)malloc(*in_field2_l + 1); - _GDF_CString(in_fields[1], in_field2, *in_field2_l); + _GDF_CString(in_fields + 1, in_field2, *in_field2_l); _gd_cp2ca(cm, 1, m2); _gd_cp2ca(cb, 1, b2); } if (nf > 2) { - in_fields[2] = (char *)malloc(*in_field3_l + 1); - _GDF_CString(in_fields[2], in_field3, *in_field3_l); + _GDF_CString(in_fields + 2, in_field3, *in_field3_l); _gd_cp2ca(cm, 2, m3); _gd_cp2ca(cb, 2, b3); } - gd_madd_clincom(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), nf, + gd_madd_clincom(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), nf, (const char**)in_fields, cm, cb); free(pa); free(fc); free(in_fields[0]); free(in_fields[1]); free(in_fields[2]); + dreturnvoid(); } /* gd_madd_polynom wrapper */ @@ -1676,17 +1685,16 @@ const double* a0, const double* a1, const double* a2, const double* a3, const double* a4, const double* a5) { - char* pa = (char *)malloc(*parent_l + 1); - char* fc = (char *)malloc(*field_code_l + 1); - char* inf = NULL; + char *pa, *fc, *inf; double a[6] = {0, 0, 0, 0, 0, 0}; - int po = *poly_ord; - if (po > 5) - po = 5; + const int po = (*poly_ord > 5) ? 5 : *poly_ord; - inf = (char *)malloc(*in_field_l + 1); - _GDF_CString(inf, in_field, *in_field_l); + dtrace("%i, %p, %i, %p, %i, %i, %p, %i, %p, %p, %p, %p, %p, %p", *dirfile, + parent, *parent_l, field_code, *field_code_l, *poly_ord, in_field, + *in_field_l, a0, a1, a2, a3, a4, a5); + _GDF_CString(&inf, in_field, *in_field_l); + switch (po) { case 5: a[5] = *a5; @@ -1696,16 +1704,17 @@ a[3] = *a3; case 2: a[2] = *a2; - case 1: + default: a[1] = *a1; a[0] = *a0; } - gd_madd_polynom(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), po, inf, a); + gd_madd_polynom(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), po, inf, a); free(pa); free(fc); free(inf); + dreturnvoid(); } void F77_FUNC(gdmdcp, GDMDCP) (const int* dirfile, const char* parent, @@ -1715,9 +1724,7 @@ const GD_DCOMPLEXP(a2), const GD_DCOMPLEXP(a3), const GD_DCOMPLEXP(a4), const GD_DCOMPLEXP(a5)) { - char* pa = (char *)malloc(*parent_l + 1); - char* fc = (char *)malloc(*field_code_l + 1); - char* inf = NULL; + char *pa, *fc, *inf; #ifdef GD_NO_C99_API double ca[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; #else @@ -1727,9 +1734,12 @@ if (po > 5) po = 5; - inf = (char *)malloc(*in_field_l + 1); - _GDF_CString(inf, in_field, *in_field_l); + dtrace("%i, %p, %i, %p, %i, %i, %p, %i, %p, %p, %p, %p, %p, %p", *dirfile, + parent, *parent_l, field_code, *field_code_l, *poly_ord, in_field, + *in_field_l, a0, a1, a2, a3, a4, a5); + _GDF_CString(&inf, in_field, *in_field_l); + switch (po) { case 5: _gd_cp2ca(ca, 5, a5); @@ -1744,11 +1754,12 @@ _gd_cp2ca(ca, 0, a0); } - gd_madd_cpolynom(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), po, inf, ca); + gd_madd_cpolynom(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), po, inf, ca); free(pa); free(fc); free(inf); + dreturnvoid(); } /* gd_madd_linterp wrapper */ @@ -1757,19 +1768,20 @@ const char* in_field, const int* in_field_l, const char* table, const int* table_l) { - char* pa = (char *)malloc(*parent_l + 1); - char* fc = (char *)malloc(*field_code_l + 1); - char* in = (char *)malloc(*in_field_l + 1); - char* tab = (char *)malloc(*table_l + 1); + char *pa, *fc, *in, *tab; - gd_madd_linterp(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), - _GDF_CString(in, in_field, *in_field_l), _GDF_CString(tab, table, + dtrace("%i, %p, %i, %p, %i, %p, %i, %p, %i", *dirfile, parent, *parent_l, + field_code, *field_code_l, in_field, *in_field_l, table, *table_l); + + gd_madd_linterp(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), + _GDF_CString(&in, in_field, *in_field_l), _GDF_CString(&tab, table, *table_l)); free(pa); free(fc); free(in); free(tab); + dreturnvoid(); } /* gd_madd_bit wrapper */ @@ -1778,17 +1790,19 @@ const char* in_field, const int* in_field_l, const int* bitnum, const int* numbits) { - char* pa = (char *)malloc(*parent_l + 1); - char* fc = (char *)malloc(*field_code_l + 1); - char* in = (char *)malloc(*in_field_l + 1); + char *pa, *fc, *in; - gd_madd_bit(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), - _GDF_CString(in, in_field, *in_field_l), (gd_bit_t)*bitnum, + dtrace("%i, %p, %i, %p, %i, %p, %i, %i, %i", *dirfile, parent, *parent_l, + field_code, *field_code_l, in_field, *in_field_l, *bitnum, *numbits); + + gd_madd_bit(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), + _GDF_CString(&in, in_field, *in_field_l), (gd_bit_t)*bitnum, (gd_bit_t)*numbits); free(pa); free(fc); free(in); + dreturnvoid(); } /* gd_madd_sbit wrapper */ @@ -1797,17 +1811,19 @@ const char* in_field, const int* in_field_l, const int* bitnum, const int* numbits) { - char* pa = (char *)malloc(*parent_l + 1); - char* fc = (char *)malloc(*field_code_l + 1); - char* in = (char *)malloc(*in_field_l + 1); + char *pa, *fc, *in; - gd_madd_sbit(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), - _GDF_CString(in, in_field, *in_field_l), (gd_bit_t)*bitnum, + dtrace("%i, %p, %i, %p, %i, %p, %i, %i, %i", *dirfile, parent, *parent_l, + field_code, *field_code_l, in_field, *in_field_l, *bitnum, *numbits); + + gd_madd_sbit(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), + _GDF_CString(&in, in_field, *in_field_l), (gd_bit_t)*bitnum, (gd_bit_t)*numbits); free(pa); free(fc); free(in); + dreturnvoid(); } /* gd_madd_multiply wrapper */ @@ -1816,20 +1832,22 @@ const char* in_field1, const int* in_field1_l, const char* in_field2, const int* in_field2_l) { - char* pa = (char *)malloc(*parent_l + 1); - char* fc = (char *)malloc(*field_code_l + 1); - char* in1 = (char *)malloc(*in_field1_l + 1); - char* in2 = (char *)malloc(*in_field2_l + 1); + char *pa, *fc, *in1, *in2; - gd_madd_multiply(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), - _GDF_CString(in1, in_field1, *in_field1_l), _GDF_CString(in2, in_field2, + dtrace("%i, %p, %i, %p, %i, %p, %i, %p, %i", *dirfile, parent, *parent_l, + field_code, *field_code_l, in_field1, *in_field1_l, in_field2, + *in_field2_l); + + gd_madd_multiply(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), + _GDF_CString(&in1, in_field1, *in_field1_l), _GDF_CString(&in2, in_field2, *in_field2_l)); free(pa); free(fc); free(in1); free(in2); + dreturnvoid(); } /* gd_madd_divide wrapper */ @@ -1844,14 +1862,9 @@ field_code, *field_code_l, in_field1, *in_field1_l, in_field2, *in_field2_l); - pa = (char *)malloc(*parent_l + 1); - fc = (char *)malloc(*field_code_l + 1); - in1 = (char *)malloc(*in_field1_l + 1); - in2 = (char *)malloc(*in_field2_l + 1); - - gd_madd_divide(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), - _GDF_CString(in1, in_field1, *in_field1_l), _GDF_CString(in2, in_field2, + gd_madd_divide(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), + _GDF_CString(&in1, in_field1, *in_field1_l), _GDF_CString(&in2, in_field2, *in_field2_l)); free(pa); @@ -1872,14 +1885,10 @@ dtrace("%i, %p, %i, %p, %i, %p, %i, %g", *dirfile, parent, *parent_l, field_code, *field_code_l, in_field, *in_field_l, *dividend); - pa = (char *)malloc(*parent_l + 1); - fc = (char *)malloc(*field_code_l + 1); - in1 = (char *)malloc(*in_field_l + 1); + gd_madd_recip(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), + _GDF_CString(&in1, in_field, *in_field_l), *dividend); - gd_madd_recip(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), - _GDF_CString(in1, in_field, *in_field_l), *dividend); - free(pa); free(fc); free(in1); @@ -1898,18 +1907,14 @@ field_code, *field_code_l, in_field, *in_field_l, crealp(cdividend), cimagp(cdividend)); - pa = (char *)malloc(*parent_l + 1); - fc = (char *)malloc(*field_code_l + 1); - in1 = (char *)malloc(*in_field_l + 1); - #ifdef GD_NO_C99_API - gd_madd_crecip89(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), - _GDF_CString(in1, in_field, *in_field_l), cdividend); + gd_madd_crecip89(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), + _GDF_CString(&in1, in_field, *in_field_l), cdividend); #else - gd_madd_crecip(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), - _GDF_CString(in1, in_field, *in_field_l), *cdividend); + gd_madd_crecip(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), + _GDF_CString(&in1, in_field, *in_field_l), *cdividend); #endif free(pa); @@ -1924,17 +1929,19 @@ const int* parent_l, const char* field_code, const int* field_code_l, const char* in_field, const int* in_field_l, const int* shift) { - char* pa = (char *)malloc(*parent_l + 1); - char* fc = (char *)malloc(*field_code_l + 1); - char* in = (char *)malloc(*in_field_l + 1); + char *pa, *fc, *in; - gd_madd_phase(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), - _GDF_CString(in, in_field, *in_field_l), *shift); + dtrace("%i, %p, %i, %p, %i, %p, %i, %i", *dirfile, parent, *parent_l, + field_code, *field_code_l, in_field, *in_field_l, *shift); + gd_madd_phase(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), + _GDF_CString(&in, in_field, *in_field_l), *shift); + free(pa); free(fc); free(in); + dreturnvoid(); } /* gd_add_const wrapper */ @@ -1942,13 +1949,17 @@ const int* field_code_l, const int* const_type, const int* data_type, const void* value, const int* fragment_index) { - char* fc = (char *)malloc(*field_code_l + 1); + char *fc; - gd_add_const(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + dtrace("%i, %p, %i, %i, %i, %p, %i", *dirfile, field_code, *field_code_l, + *const_type, *data_type, value, *fragment_index); + + gd_add_const(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), (gd_type_t)*const_type, (gd_type_t)*data_type, value, *fragment_index); free(fc); + dreturnvoid(); } /* gd_madd_const wrapper */ @@ -1956,15 +1967,18 @@ const int* parent_l, const char* field_code, const int* field_code_l, const int* const_type, const int* data_type, const void* value) { - char* pa = (char *)malloc(*parent_l + 1); - char* fc = (char *)malloc(*field_code_l + 1); + char *pa, *fc; - gd_madd_const(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), + dtrace("%i, %p, %i, %p, %i, %i, %i, %p", *dirfile, parent, *parent_l, + field_code, *field_code_l, *const_type, *data_type, value); + + gd_madd_const(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), (gd_type_t)*const_type, (gd_type_t)*data_type, value); free(pa); free(fc); + dreturnvoid(); } /* gd_add_carray wrapper */ @@ -1978,9 +1992,7 @@ *field_code_l, *const_type, *array_len, *data_type, value, *fragment_index); - fc = (char *)malloc(*field_code_l + 1); - - gd_add_carray(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + gd_add_carray(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), (gd_type_t)*const_type, *array_len, (gd_type_t)*data_type, value, *fragment_index); @@ -1999,11 +2011,8 @@ dtrace("%i, %p, %i, %p, %i, %x, %i, %x, %p", *dirfile, parent, *parent_l, field_code, *field_code_l, *const_type, *array_len, *data_type, value); - pa = (char *)malloc(*parent_l + 1); - fc = (char *)malloc(*field_code_l + 1); - - gd_madd_carray(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), + gd_madd_carray(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), (gd_type_t)*const_type, *array_len, (gd_type_t)*data_type, value); free(pa); @@ -2016,14 +2025,17 @@ const int* field_code_l, const char* value, const int* value_l, const int* fragment_index) { - char* fc = (char *)malloc(*field_code_l + 1); - char* va = (char *)malloc(*value_l + 1); + char *fc, *va; - gd_add_string(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, - *field_code_l), _GDF_CString(va, value, *value_l), *fragment_index); + dtrace("%i, %p, %i, %p, %i, %i", *dirfile, field_code, *field_code_l, value, + *value_l, *fragment_index); + gd_add_string(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, + *field_code_l), _GDF_CString(&va, value, *value_l), *fragment_index); + free(fc); free(va); + dreturnvoid(); } /* gd_madd_string wrapper */ @@ -2031,43 +2043,51 @@ const int* parent_l, const char* field_code, const int* field_code_l, const char* value, const int* value_l) { - char* pa = (char *)malloc(*parent_l + 1); - char* fc = (char *)malloc(*field_code_l + 1); - char* va = (char *)malloc(*value_l + 1); + char *pa, *fc, *va; - gd_madd_string(_GDF_GetDirfile(*dirfile), _GDF_CString(pa, parent, - *parent_l), _GDF_CString(fc, field_code, *field_code_l), - _GDF_CString(va, value, *value_l)); + dtrace("%i, %p, %i, %p, %i, %p, %i", *dirfile, parent, *parent_l, field_code, + *field_code_l, value, *value_l); + gd_madd_string(_GDF_GetDirfile(*dirfile), _GDF_CString(&pa, parent, + *parent_l), _GDF_CString(&fc, field_code, *field_code_l), + _GDF_CString(&va, value, *value_l)); + free(pa); free(fc); free(va); + dreturnvoid(); } /* gd_add_spec wrapper */ void F77_FUNC(gdadsp, GDADSP) (const int* dirfile, const char* spec, const int* spec_l, const int* fragment_index) { - char* sp = (char *)malloc(*spec_l + 1); + char *sp; - gd_add_spec(_GDF_GetDirfile(*dirfile), _GDF_CString(sp, spec, *spec_l), + dtrace("%i, %p, %i, %i", *dirfile, spec, *spec_l, *fragment_index); + + gd_add_spec(_GDF_GetDirfile(*dirfile), _GDF_CString(&sp, spec, *spec_l), *fragment_index); free(sp); + dreturnvoid(); } /* gd_madd_spec wrapper */ void F77_FUNC(gdmdsp, GDMDSP) (const int* dirfile, const char* spec, const int* spec_l, const char *parent, const int* parent_l) { - char* pa = (char *)malloc(*parent_l + 1); - char* sp = (char *)malloc(*spec_l + 1); + char *pa, *sp; - gd_madd_spec(_GDF_GetDirfile(*dirfile), _GDF_CString(sp, spec, - *spec_l), _GDF_CString(pa, parent, *parent_l)); + dtrace("%i, %p, %i, %p, %i", *dirfile, spec, *spec_l, parent, *parent_l); + gd_madd_spec(_GDF_GetDirfile(*dirfile), _GDF_CString(&sp, spec, + *spec_l), _GDF_CString(&pa, parent, *parent_l)); + free(pa); free(sp); + + dreturnvoid(); } /* gd_get_constant wrapper */ @@ -2079,8 +2099,7 @@ dtrace("%i, %p, %i, %i, %p", *dirfile, field_code, *field_code_l, *return_type, data_out); - fc = (char *)malloc(*field_code_l + 1); - gd_get_constant(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + gd_get_constant(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), (gd_type_t)*return_type, data_out); free(fc); @@ -2096,8 +2115,7 @@ dtrace("%i, %p, %i, %x, %p", *dirfile, field_code, *field_code_l, *return_type, data_out); - fc = (char *)malloc(*field_code_l + 1); - gd_get_carray(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + gd_get_carray(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), (gd_type_t)*return_type, data_out); free(fc); @@ -2114,8 +2132,7 @@ dtrace("%i, %p, %i, %i, %i, %x, %p", *dirfile, field_code, *field_code_l, *start, *n, *return_type, data_out); - fc = (char *)malloc(*field_code_l + 1); - gd_get_carray_slice(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + gd_get_carray_slice(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), *start - 1, (size_t)*n, (gd_type_t)*return_type, data_out); free(fc); @@ -2131,8 +2148,7 @@ dtrace("%p, %i, %p, %i", len, *dirfile, field_code, *field_code_l); - fc = (char *)malloc(*field_code_l + 1); - *len = gd_carray_len(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + *len = gd_carray_len(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l)); free(fc); @@ -2144,16 +2160,22 @@ const char *field_code, const int *field_code_l, const int *len, char *data_out) { - char *fc = (char *)malloc(*field_code_l + 1); - char *out = (char *)malloc(*len + 1); + char *fc, *out; int l = *len; - *size = gd_get_string(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + dtrace("%p, %i, %p, %i, %i, %p", size, *dirfile, field_code, *field_code_l, + *len, data_out); + + out = (char*)malloc(l + 1); + + *size = gd_get_string(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), (size_t)*len, out) - 1; _GDF_FString(data_out, &l, out); free(fc); free(out); + + dreturn("%i", *size); } /* gd_put_constant wrapper */ @@ -2165,8 +2187,7 @@ dtrace("%i, %p, %i, %x, %p", *dirfile, field_code, *field_code_l, *data_type, data_in); - fc = (char *)malloc(*field_code_l + 1); - gd_put_constant(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + gd_put_constant(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), (gd_type_t)*data_type, data_in); free(fc); @@ -2182,8 +2203,7 @@ dtrace("%i, %p, %i, %x, %p", *dirfile, field_code, *field_code_l, *data_type, data_in); - fc = (char *)malloc(*field_code_l + 1); - gd_put_carray(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + gd_put_carray(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), (gd_type_t)*data_type, data_in); free(fc); @@ -2200,8 +2220,7 @@ dtrace("%i, %p, %i, %i, %i, %x, %p", *dirfile, field_code, *field_code_l, *start, *n, *data_type, data_in); - fc = (char *)malloc(*field_code_l + 1); - gd_put_carray_slice(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, + gd_put_carray_slice(_GDF_GetDirfile(*dirfile), _GDF_CString(&fc, field_code, *field_code_l), *start - 1, (size_t)*n, ... [truncated message content] |
From: <ket...@us...> - 2012-03-17 02:40:36
|
Revision: 679 http://getdata.svn.sourceforge.net/getdata/?rev=679&view=rev Author: ketiltrout Date: 2012-03-17 02:40:29 +0000 (Sat, 17 Mar 2012) Log Message: ----------- Update tests for same. Modified Paths: -------------- trunk/getdata/test/creat_excl.c Modified: trunk/getdata/test/creat_excl.c =================================================================== --- trunk/getdata/test/creat_excl.c 2012-03-17 02:37:11 UTC (rev 678) +++ trunk/getdata/test/creat_excl.c 2012-03-17 02:40:29 UTC (rev 679) @@ -45,7 +45,7 @@ unlink(format); rmdir(filedir); - CHECKI(error, GD_E_CREAT); + CHECKI(error, GD_E_EXISTS); return r; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-17 02:37:17
|
Revision: 678 http://getdata.svn.sourceforge.net/getdata/?rev=678&view=rev Author: ketiltrout Date: 2012-03-17 02:37:11 +0000 (Sat, 17 Mar 2012) Log Message: ----------- Added GD_E_EXISTS. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/bindings/make_parameters.c trunk/getdata/man/gd_cbopen.3 trunk/getdata/src/errors.c trunk/getdata/src/getdata.h.in trunk/getdata/src/internal.h trunk/getdata/src/legacy.c trunk/getdata/src/open.c Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2012-03-15 23:05:42 UTC (rev 677) +++ trunk/getdata/ChangeLog 2012-03-17 02:37:11 UTC (rev 678) @@ -1,3 +1,8 @@ +2012-03-16 D. V. Wiebe <ge...@ke...> svn:678 + * src/errors.c src/getdata.h.in: Add GD_E_EXISTS + * src/open.c (_GD_CreateDirfile): Replace GD_E_CREAT:GD_E_CREAT_EXCL with + GD_E_EXISTS. + 2012-03-16 D. V. Wiebe <ge...@ke...> svn:676 * configure.ac bindings/idl/package/configure.ac src/include.h bindings/make_parameters.c bindings/cxx/internal.h bindings/idl/getdata.c Modified: trunk/getdata/bindings/make_parameters.c =================================================================== --- trunk/getdata/bindings/make_parameters.c 2012-03-15 23:05:42 UTC (rev 677) +++ trunk/getdata/bindings/make_parameters.c 2012-03-17 02:37:11 UTC (rev 678) @@ -63,7 +63,6 @@ CONSTANT(E_BAD_TYPE, "GD_EBT", 0), CONSTANT(E_RAW_IO, "GD_ERW", 0), CONSTANT(E_OPEN_FRAGMENT, "GD_EOF", 0), - CONSTANT(E_OPEN_INCLUDE, "GD_EOI", 0), /* deprecated */ CONSTANT(E_INTERNAL_ERROR, "GD_EIE", 0), CONSTANT(E_ALLOC, "GD_EAL", 0), CONSTANT(E_RANGE, "GD_ERA", 0), @@ -83,9 +82,8 @@ CONSTANT(E_PROTECTED, "GD_EPT", 0), CONSTANT(E_DELETE, "GD_EDL", 0), CONSTANT(E_ARGUMENT, "GD_EAR", 0), - CONSTANT(E_BAD_ENDIANNESS, "GD_EEN", 0), /* deprecated */ CONSTANT(E_CALLBACK, "GD_ECB", 0), - CONSTANT(E_BAD_PROTECTION, "GD_EBP", 0), /* deprecated */ + CONSTANT(E_EXISTS, "GD_EEX", 0), CONSTANT(E_UNCLEAN_DB, "GD_UCL", 0), CONSTANT(E_DOMAIN, "GD_EDO", 0), CONSTANT(E_BAD_REPR, "GD_ERP", 0), @@ -94,6 +92,10 @@ CONSTANT(E_BOUNDS, "GD_EBO", 0), CONSTANT(E_LINE_TOO_LONG, "GD_ETL", 0), + CONSTANT(E_OPEN_INCLUDE, "GD_EOI", 0), /* deprecated */ + CONSTANT(E_BAD_ENDIANNESS, "GD_EEN", 0), /* deprecated */ + CONSTANT(E_BAD_PROTECTION, "GD_EBP", 0), /* deprecated */ + CONSTANT(RDONLY, "GD_RO", 1), CONSTANT(RDWR, "GD_RW", 1), CONSTANT(FORCE_ENDIAN, "GD_FE", 1), Modified: trunk/getdata/man/gd_cbopen.3 =================================================================== --- trunk/getdata/man/gd_cbopen.3 2012-03-15 23:05:42 UTC (rev 677) +++ trunk/getdata/man/gd_cbopen.3 2012-03-17 02:37:11 UTC (rev 678) @@ -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 "1 January 2012" "Version 0.8.0" "GETDATA" +.TH gd_cbopen 3 "17 March 2012" "Version 0.8.0" "GETDATA" .SH NAME gd_cbopen, gd_open \(em open or create a dirfile .SH SYNOPSIS @@ -623,7 +623,10 @@ returned an unrecognised response. .TP .B GD_E_CREAT -The library was unable to create the dirfile, or the dirfile exists and both +The library was unable to create the dirfile. +.TP +.B GD_E_EXISTS +The dirfile already exists and both .BR GD_CREAT " and " GD_EXCL were specified. .TP Modified: trunk/getdata/src/errors.c =================================================================== --- trunk/getdata/src/errors.c 2012-03-15 23:05:42 UTC (rev 677) +++ trunk/getdata/src/errors.c 2012-03-17 02:37:11 UTC (rev 678) @@ -85,8 +85,6 @@ { GD_E_CREAT, GD_E_CREAT_DIR, "Unable to create directory {2}: ", 1 }, { GD_E_CREAT, GD_E_CREAT_OPEN, "Unable to open directory {2}: ", 1 }, { GD_E_CREAT, GD_E_CREAT_FORMAT, "Unable to create format file {2}: ", 1 }, - { GD_E_CREAT, GD_E_CREAT_EXCL, "Unable to create dirfile {2}: already exists", - 0 }, /* GD_E_BAD_CODE: 4 = field code */ { GD_E_BAD_CODE, GD_E_CODE_MISSING, "Field not found: {4}", 0 }, { GD_E_BAD_CODE, GD_E_CODE_INVALID, "Bad field name: {4}", 0 }, @@ -181,6 +179,8 @@ { GD_E_ARGUMENT, 0, "Bad argument", 0 }, /* GD_E_CALLBACK: 3 = response */ { 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, 0, "Unexpected system error processing {3}; database unclean", 0 }, Modified: trunk/getdata/src/getdata.h.in =================================================================== --- trunk/getdata/src/getdata.h.in 2012-03-15 23:05:42 UTC (rev 677) +++ trunk/getdata/src/getdata.h.in 2012-03-17 02:37:11 UTC (rev 678) @@ -144,7 +144,7 @@ #define GD_E_DELETE 26 #define GD_E_ARGUMENT 27 #define GD_E_CALLBACK 28 -/* unused 29 */ +#define GD_E_EXISTS 29 #define GD_E_UNCLEAN_DB 30 #define GD_E_DOMAIN 31 #define GD_E_BAD_REPR 32 Modified: trunk/getdata/src/internal.h =================================================================== --- trunk/getdata/src/internal.h 2012-03-15 23:05:42 UTC (rev 677) +++ trunk/getdata/src/internal.h 2012-03-17 02:37:11 UTC (rev 678) @@ -618,9 +618,8 @@ #define GD_E_TRUNC_DIR 3 #define GD_E_CREAT_FORMAT 1 -#define GD_E_CREAT_EXCL 2 -#define GD_E_CREAT_DIR 3 -#define GD_E_CREAT_OPEN 4 +#define GD_E_CREAT_DIR 2 +#define GD_E_CREAT_OPEN 3 #define GD_E_CODE_MISSING 1 #define GD_E_CODE_INVALID 2 Modified: trunk/getdata/src/legacy.c =================================================================== --- trunk/getdata/src/legacy.c 2012-03-15 23:05:42 UTC (rev 677) +++ trunk/getdata/src/legacy.c 2012-03-17 02:37:11 UTC (rev 678) @@ -72,7 +72,7 @@ NULL, /* GD_E_DELETE */ "Bad argument", /* GD_E_ARGUMENT */ NULL, /* GD_E_CALLBACK */ - NULL, /* unused */ + NULL, /* GD_E_EXISTS */ NULL, /* GD_E_UNCLEAN_DB */ "Improper domain", /* GD_E_DOMAIN */ "Bad representation", /* GD_E_BAD_REPR */ Modified: trunk/getdata/src/open.c =================================================================== --- trunk/getdata/src/open.c 2012-03-15 23:05:42 UTC (rev 677) +++ trunk/getdata/src/open.c 2012-03-17 02:37:11 UTC (rev 678) @@ -260,7 +260,7 @@ /* It does exist, but we were asked to exclusively create it */ if (!format_error && (D->flags & GD_CREAT) && (D->flags & GD_EXCL)) { - _GD_SetError(D, GD_E_CREAT, GD_E_CREAT_EXCL, dirfile, 0, NULL); + _GD_SetError(D, GD_E_EXISTS, 0, NULL, 0, NULL); free(dirfile); close(fd); dreturn("%p", NULL); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-15 23:05:48
|
Revision: 677 http://getdata.svn.sourceforge.net/getdata/?rev=677&view=rev Author: ketiltrout Date: 2012-03-15 23:05:42 +0000 (Thu, 15 Mar 2012) Log Message: ----------- svn:ignore Property Changed: ---------------- trunk/getdata/bindings/perl/ Property changes on: trunk/getdata/bindings/perl ___________________________________________________________________ Modified: svn:ignore - simple_funcs.xs Makefile.in GetData.pm GetData.c .deps make_parameters.sed Makefile MYMETA.yml MYMETA.json _build Build lib debug.c blib Build.PL + simple_funcs.xs Makefile.in GetData.pm GetData.c .deps make_parameters.sed Makefile MYMETA.yml MYMETA.json _build Build lib debug.c blib Build.PL t MANIFEST This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-15 23:03:45
|
Revision: 676 http://getdata.svn.sourceforge.net/getdata/?rev=676&view=rev Author: ketiltrout Date: 2012-03-15 23:03:36 +0000 (Thu, 15 Mar 2012) Log Message: ----------- * VPATH build fixes. * Fix GD_DESYNC_REOPEN. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/bindings/cxx/internal.h trunk/getdata/bindings/cxx/test/big_test.cpp trunk/getdata/bindings/f77/fgetdata.h trunk/getdata/bindings/f77/test/Makefile.am trunk/getdata/bindings/idl/getdata.c trunk/getdata/bindings/idl/package/README trunk/getdata/bindings/idl/package/configure.ac trunk/getdata/bindings/make_parameters.c trunk/getdata/bindings/perl/Makefile.am trunk/getdata/configure.ac trunk/getdata/man/Makefile.am trunk/getdata/man/gd_flush.3 trunk/getdata/man/gd_metaflush.3 trunk/getdata/src/fragment.c trunk/getdata/src/internal.h trunk/getdata/test/Makefile.am trunk/getdata/test/bzip_get.c trunk/getdata/test/bzip_move_from.c trunk/getdata/test/bzip_nframes.c trunk/getdata/test/endian_alter.c trunk/getdata/test/endian_alter_sie.c trunk/getdata/test/endian_get.c trunk/getdata/test/endian_move.c trunk/getdata/test/gzip_get.c trunk/getdata/test/gzip_get_get.c trunk/getdata/test/gzip_get_put.c trunk/getdata/test/gzip_move_from.c trunk/getdata/test/gzip_nframes.c trunk/getdata/test/gzip_put.c trunk/getdata/test/gzip_put_get.c trunk/getdata/test/lzma_get.c trunk/getdata/test/lzma_nframes.c trunk/getdata/test/move_data_endian.c trunk/getdata/test/slim_get.c trunk/getdata/test/slim_nframes.c trunk/getdata/test/xz_get.c trunk/getdata/test/xz_nframes.c trunk/getdata/test/zzip_nframes.c trunk/getdata/test/zzslim_nframes.c trunk/getdata/util/checkdirfile.c trunk/getdata/util/dirfile2ascii.c Added Paths: ----------- trunk/getdata/bindings/perl/MANIFEST.in trunk/getdata/bindings/perl/test/ trunk/getdata/man/gd_desync.3 trunk/getdata/test/desync_reopen.c trunk/getdata/test/desync_reopen_inv.c Removed Paths: ------------- trunk/getdata/bindings/perl/MANIFEST trunk/getdata/bindings/perl/t/ Property Changed: ---------------- trunk/getdata/src/ trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/ChangeLog 2012-03-15 23:03:36 UTC (rev 676) @@ -1,3 +1,19 @@ +2012-03-16 D. V. Wiebe <ge...@ke...> svn:676 + * configure.ac bindings/idl/package/configure.ac src/include.h + bindings/make_parameters.c bindings/cxx/internal.h bindings/idl/getdata.c + test/test.h util/dirfile2ascii.c util/checkdirfile.c: Renamed config.h to + gd_config.h to get around lossage in the Perl CORE public headers. + + * bindings/perl/test: Renamed from t. + * bindings/perl/MANIFEST.in: Renamed from MANIFEST. + * bindings/perl Makefile.am bindings/f77/test/Makefile.am: VPATH fixes. + + * src/fragment.c (gd_desync): dup the dirfile fd before closing. + * test/desync_reopen.c test/desync_reopen_inv.c: Added. + + * bindings/idl/package/configure.ac bindings/idl/package/README: Bump + GetData min version. + 2012-03-15 D. V. Wiebe <ge...@ke...> svn:675 * src/internal.h: Add fragment->mtime, dirfile->open_flags. Deconst fragment->sname. Modified: trunk/getdata/bindings/cxx/internal.h =================================================================== --- trunk/getdata/bindings/cxx/internal.h 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/bindings/cxx/internal.h 2012-03-15 23:03:36 UTC (rev 676) @@ -19,7 +19,7 @@ // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // #ifdef HAVE_CONFIG_H -#include "../../src/config.h" +#include "gd_config.h" #endif #undef GETDATA_LEGACY_API #include "getdata/dirfile.h" Modified: trunk/getdata/bindings/cxx/test/big_test.cpp =================================================================== --- trunk/getdata/bindings/cxx/test/big_test.cpp 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/bindings/cxx/test/big_test.cpp 2012-03-15 23:03:36 UTC (rev 676) @@ -19,9 +19,9 @@ // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // #ifdef HAVE_CONFIG_H -#include "config.h" +#include "gd_config.h" +#endif #undef GETDATA_LEGACY_API -#endif #include "getdata/dirfile.h" #include <sys/stat.h> Modified: trunk/getdata/bindings/f77/fgetdata.h =================================================================== --- trunk/getdata/bindings/f77/fgetdata.h 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/bindings/f77/fgetdata.h 2012-03-15 23:03:36 UTC (rev 676) @@ -21,12 +21,8 @@ #ifndef FGETDATA_H #define FGETDATA_H -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#include "internal.h" -#include "../../src/internal.h" - /* If F77_FUNC isn't defined, we have no knowledge of the F77 mangling scheme */ #ifndef F77_FUNC # error The F77_FUNC macro must be defined to build the F77 bindings Modified: trunk/getdata/bindings/f77/test/Makefile.am =================================================================== --- trunk/getdata/bindings/f77/test/Makefile.am 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/bindings/f77/test/Makefile.am 2012-03-15 23:03:36 UTC (rev 676) @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2010 D. V. Wiebe +# Copyright (C) 2008-2010, 2012 D. V. Wiebe # ########################################################################## # @@ -42,8 +42,8 @@ BUILT_SOUCES = test_getdata.f -FFLAGS += -I.. $(F77_WALL) $(F77_WEXTRA) $(F77_ASSUME) -FCFLAGS += -I.. $(F77_WALL) $(FC_WEXTRA) $(FC_ASSUME) +FFLAGS += -I. -I.. $(F77_WALL) $(F77_WEXTRA) $(F77_ASSUME) +FCFLAGS += -I. -I.. $(F77_WALL) $(FC_WEXTRA) $(FC_ASSUME) F95LDADD=../libf95getdata.la $(F77LDADD) F77LDADD=../libfgetdata.la AM_LDFLAGS = -L.. Modified: trunk/getdata/bindings/idl/getdata.c =================================================================== --- trunk/getdata/bindings/idl/getdata.c 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/bindings/idl/getdata.c 2012-03-15 23:03:36 UTC (rev 676) @@ -29,7 +29,7 @@ #undef _SVID_SOURCE #ifdef HAVE_CONFIG_H -# include "config.h" +# include "gd_config.h" #endif #ifdef GDIDL_EXTERNAL Modified: trunk/getdata/bindings/idl/package/README =================================================================== --- trunk/getdata/bindings/idl/package/README 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/bindings/idl/package/README 2012-03-15 23:03:36 UTC (rev 676) @@ -79,7 +79,7 @@ PREREQUISITES ============= -These bindings require GetData 0.7 or newer to build, as well as an IDL +These bindings require GetData 0.8 or newer to build, as well as an IDL interpreter verison 5.5 or later. No other external libraries are required, save for the C Standard Library. Modified: trunk/getdata/bindings/idl/package/configure.ac =================================================================== --- trunk/getdata/bindings/idl/package/configure.ac 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/bindings/idl/package/configure.ac 2012-03-15 23:03:36 UTC (rev 676) @@ -1,4 +1,4 @@ -dnl Copyright (C) 2008-2011 D. V. Wiebe +dnl Copyright (C) 2008-2012 D. V. Wiebe dnl dnl llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll dnl @@ -39,7 +39,7 @@ AC_CONFIG_AUX_DIR([.]) AC_CONFIG_SRCDIR([src/getdata.c]) -AC_CONFIG_HEADER([src/config.h]) +AC_CONFIG_HEADER([src/gd_config.h]) dnl Features echo "*** Checking GetData configuration" @@ -126,7 +126,7 @@ echo echo "*** Looking for getdata" echo -PKG_CHECK_MODULES([GETDATA], [getdata >= 0.7.0]) +PKG_CHECK_MODULES([GETDATA], [getdata >= 0.8.0]) dnl headers echo Modified: trunk/getdata/bindings/make_parameters.c =================================================================== --- trunk/getdata/bindings/make_parameters.c 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/bindings/make_parameters.c 2012-03-15 23:03:36 UTC (rev 676) @@ -19,7 +19,7 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include "gd_config.h" #endif #include <stdlib.h> Deleted: trunk/getdata/bindings/perl/MANIFEST =================================================================== --- trunk/getdata/bindings/perl/MANIFEST 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/bindings/perl/MANIFEST 2012-03-15 23:03:36 UTC (rev 676) @@ -1,2 +0,0 @@ -MANIFEST This list of files -GetData.pm Copied: trunk/getdata/bindings/perl/MANIFEST.in (from rev 675, trunk/getdata/bindings/perl/MANIFEST) =================================================================== --- trunk/getdata/bindings/perl/MANIFEST.in (rev 0) +++ trunk/getdata/bindings/perl/MANIFEST.in 2012-03-15 23:03:36 UTC (rev 676) @@ -0,0 +1,2 @@ +MANIFEST This list of files +GetData.pm Modified: trunk/getdata/bindings/perl/Makefile.am =================================================================== --- trunk/getdata/bindings/perl/Makefile.am 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/bindings/perl/Makefile.am 2012-03-15 23:03:36 UTC (rev 676) @@ -1,4 +1,4 @@ -# Copyright (C) 2011 D. V. Wiebe +# Copyright (C) 2011, 2012 D. V. Wiebe # ########################################################################## # @@ -21,48 +21,60 @@ AUTOMAKE_OPTIONS = foreign EXTRA_DIST=funclist.pl GetData.xs simple_funcs.pl simple_funcs.xsin typemap \ - GetData.pm.in MANIFEST + GetData.pm.in MANIFEST.in test if GETDATA_DEBUG TEST_VERBOSE=verbose=1 endif +PERL_TESTS=t/big_test.t t/callback.t + +t: + mkdir t + +t/%.t: test/%.t t + cat $< > $@ + lib: mkdir lib -lib/GetData.xs: $(srcdir)/GetData.xs +lib/GetData.xs: GetData.xs $(MAKE) lib - cat $< > $@ + cat $(srcdir)/GetData.xs > $@ -lib/typemap: $(srcdir)/typemap +lib/typemap: typemap $(MAKE) lib - cat $< > $@ + cat $(srcdir)/typemap > $@ -lib/simple_funcs.xs: $(srcdir)/simple_funcs.xsin $(srcdir)/simple_funcs.pl - $(PERL) $(srcdir)/simple_funcs.pl $< > $@ +lib/simple_funcs.xs: simple_funcs.xsin simple_funcs.pl + $(PERL) $(srcdir)/simple_funcs.pl $(srcdir)/simple_funcs.xsin > $@ +MANIFEST: MANIFEST.in + cat $(srcdir)/MANIFEST.in > $@ + make_parameters.sed: ../make_parameters ../../src/getdata.h ../make_parameters P > $@ -../make_parameters: $(srcdir)/../make_parameters.c +../make_parameters: ../make_parameters.c cd .. && ${MAKE} make_parameters -GetData.pm: $(srcdir)/GetData.pm.in make_parameters.sed $(srcdir)/funclist.pl \ - lib/GetData.xs lib/simple_funcs.xs +GetData.pm: GetData.pm.in make_parameters.sed funclist.pl lib/GetData.xs \ + lib/simple_funcs.xs rm -f $@ - $(SED) -f make_parameters.sed $< | \ + $(SED) -f make_parameters.sed $(srcdir)/GetData.pm.in | \ $(PERL) $(srcdir)/funclist.pl lib/GetData.xs lib/simple_funcs.xs > $@ chmod a-w $@ all-local: lib blib/arch/auto/GetData/GetData.bs blib/arch/auto/GetData/GetData.bs: Build - $(PERL) $< build + $(PERL) Build build touch $@ .PRECIOUS: Build -Build: Build.PL GetData.pm lib/GetData.xs lib/simple_funcs.xs lib/typemap - perl $< +Build: Build.PL GetData.pm lib/GetData.xs lib/simple_funcs.xs lib/typemap \ + MANIFEST + $(PERL) Build.PL clean-local: rm -rf lib @@ -70,14 +82,14 @@ $(PERL) Build clean; \ fi rm -f $(BUILT_SOURCES) make_parameters.sed MYMETA.yml MYMETA.json GetData.pm - rm -rf Build _build + rm -rf Build _build MANIFEST t if TEST_PERL -check: - $(MAKE) test +check: $(PERL_TESTS) + ${DL_LIBRARY_PATH}=${${DL_LIBRARY_PATH}}:../../src/.libs $(PERL) ./Build test ${TEST_VERBOSE} -test testdb testcover: +testdb testcover: $(PERL_TESTS) ${DL_LIBRARY_PATH}=${${DL_LIBRARY_PATH}}:../../src/.libs $(PERL) ./Build $@ ${TEST_VERBOSE} -.PHONY: test testdb testcover +.PHONY: check testdb testcover endif Modified: trunk/getdata/configure.ac =================================================================== --- trunk/getdata/configure.ac 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/configure.ac 2012-03-15 23:03:36 UTC (rev 676) @@ -46,7 +46,7 @@ AC_SUBST(F95GETDATA_VERSION, [f95getdata_version]) AC_CONFIG_SRCDIR([src/getdata.c]) -AC_CONFIG_HEADER([src/config.h]) +AC_CONFIG_HEADER([src/gd_config.h]) dnl Features BUINDINGS_BUILT= Modified: trunk/getdata/man/Makefile.am =================================================================== --- trunk/getdata/man/Makefile.am 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/man/Makefile.am 2012-03-15 23:03:36 UTC (rev 676) @@ -56,6 +56,7 @@ dirfile.5 dirfile-encoding.5 dirfile-format.5 \ $(LFS_transitional_mans) +# these are real_file:alias MAN3ALIASES=gd_add_bit.3:gd_add_carray.3 gd_add_bit.3:gd_add_clincom.3 \ gd_add_bit.3:gd_add_const.3 gd_add_bit.3:gd_add_cpolynom.3 \ gd_add_bit.3:gd_add_crecip.3 gd_add_bit.3:gd_add_divide.3 \ @@ -83,7 +84,8 @@ gd_alter_spec.3:gd_malter_spec.3 gd_framenum_subset.3:gd_framenum.3 \ gd_get_carray_slice.3:gd_get_carray.3 gd_put_carray_slice.3:gd_put_carray.3 \ gd_delete.3:gd_delete_alias.3 gd_hide.3:gd_unhide.3 \ - gd_add_alias.3:gd_madd_alias.3 $(MAN3ALIASES64) + gd_add_alias.3:gd_madd_alias.3 gd_flush.3:gd_sync.3 \ + gd_flush.3:gd_raw_close.3 $(MAN3ALIASES64) #man conversion HTMLMANS=$(addsuffix .html,$(nodist_man_MANS)) \ Added: trunk/getdata/man/gd_desync.3 =================================================================== --- trunk/getdata/man/gd_desync.3 (rev 0) +++ trunk/getdata/man/gd_desync.3 2012-03-15 23:03:36 UTC (rev 676) @@ -0,0 +1,129 @@ +.\" gd_desync.3. The gd_desync man page. +.\" +.\" Copyright (C) 2012 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_desync 3 "15 March 2012" "Version 0.8.0" "GETDATA" +.SH NAME +gd_desync \(em check for a change of metadata on disk +.SH SYNOPSIS +.B #include <getdata.h> +.HP +.nh +.ad l +.BI "int gd_desync(DIRFILE *" dirfile ", unsigned int " flags ); +.hy +.ad n +.SH DESCRIPTION +The +.BR gd_desync () +function reports whether the metadata of the loaded +.I dirfile +has become desynchronised from the format specification fragments on disk, due +to a third party modifying the Dirfile metadata on disk after GetData opened +it. If +.I dirfile +has become desynchronised, this function can, optionally, reload the dirfile. + +The +.I flags +argument influences how the function works. It should be zero, or else one +or more of the following flags, bitwise or'd together: +.TP 8 +.B GD_DESYNC_PATHCHECK +Ignore GetData's internal directory cache, and use the format specification +fragments' full path when checking for modifications. This flag is of +particular importance when the +.I dirfilename +passed to +.BR gd_cbopen (3), +or directory paths used in included fragments, contain symbolic links: with this +flag, these symbolic links will be re-evaluated. Without it, the target of +the symbolic links in effect when the dirfile was first opened will be +considered instead. +.TP +.B GD_DESYNC_REOPEN +If this flag is specified, and +.BR gd_desync () +detects desynchronisation, the Dirfile will be re-opened in place using the +exiting +.I dirfile +pointer. In this case, upon a positive result from this function, the caller +must discard all cached information about the dirfile, even the assumption that +.I dirfile +has been succesfully opened. + +Re-opening the dirfile is equivalent to calling +.BR gd_close (3), +and then +.BR gd_cbopen (3) +with the same arguments used when originally creating +.IR dirfile , +except that the +.I dirfile +pointer doesn't change its value. As a result, this function may invoke the +registered parser callback function (see +.BR gd_cbopen (3) +and +.BR gd_parser_callback (3)). +.SH RETURN VALUE +On successful deletion, zero is returned if the loaded dirfile has not +desynchronised, or 1 if it has. On error, -1 is returned, regardless of +desynchronisation and the dirfile error is set to a non-zero error value. +Possible error values are: +.TP 8 +.B GD_E_ALLOC +The library was unable to allocate memory. +.TP +.B GD_E_BAD_DIRFILE +The supplied dirfile was invalid. +.TP +.B GD_E_RAW_IO +An error occurred while trying to obtain the modification time of a fragment. +.PP +Additionally, if +.B GD_DESYNC_REOPEN +is used, this function may fail for any of the reasons listed in the +.BR gd_close (3) +and +.BR gd_cbopen (3) +manual pages. +.PP +The dirfile error may be retrieved by calling +.BR gd_error (3). +A descriptive error string for the last error encountered can be obtained from +a call to +.BR gd_error_string (3). +.SH LIMITATIONS +The current implementation uses file modification times as reported by +.BR stat (2) +to detect changes. These times have a granularity of, at best, one second. As +a result, desynchronisation will not be detected in the case when a fragment is +modified, then GetData reads it, then the fragment is modified again, all within +one second. The caller may wish to perform its own monitoring using the +pathnames returned by +.BR gd_fragmentname (3). +.PP +On systems lacking a POSIX.1-2008 conformant +.BR fstatat (2) +(q.v.), this function may always operate as if +.B GD_DESYNC_PATHCHECK +had been specified, regarless of the actual +.IR flags . +.SH SEE ALSO +.BR fstatat (2), +.BR gd_cbopen (3), +.BR gd_close (3), +.BR gd_error (3), +.BR gd_error_string (3), +.BR gd_parser_callback (3) Modified: trunk/getdata/man/gd_flush.3 =================================================================== --- trunk/getdata/man/gd_flush.3 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/man/gd_flush.3 2012-03-15 23:03:36 UTC (rev 676) @@ -1,6 +1,6 @@ .\" gd_flush.3. The gd_flush man page. .\" -.\" Copyright (C) 2008, 2009, 2010, 2011 D. V. Wiebe +.\" Copyright (C) 2008, 2009, 2010, 2011, 2012 D. V. Wiebe .\" .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .\" @@ -13,21 +13,27 @@ .\" Texts. A copy of the license is included in the `COPYING.DOC' file .\" as part of this distribution. .\" -.TH gd_flush 3 "18 August 2011" "Version 0.8.0" "GETDATA" +.TH gd_flush 3 "15 March 2012" "Version 0.8.0" "GETDATA" .SH NAME -gd_flush \(em write all pending dirfile changes to disk. +gd_flush gd_raw_close gd_sync \(em write all pending dirfile changes to disk or +close open raw fields .SH SYNOPSIS .B #include <getdata.h> .HP .nh .ad l +.HP .BI "int gd_flush(DIRFILE *" dirfile ", const char *" field_code ); +.HP +.BI "int gd_raw_close(DIRFILE *" dirfile ", const char *" field_code ); +.HP +.BI "int gd_sync(DIRFILE *" dirfile ", const char *" field_code ); .hy .ad n .SH DESCRIPTION The -.BR gd_flush () -function flushes and closes all file handles associated with +.BR gd_sync () +function flushes all pending writes to disk of raw data files associated with .IR field_code , or its input(s), in the dirfile specified by .IR dirfile . @@ -38,21 +44,33 @@ .I field_code is NULL, all fields in .I dirfile -will be flushed and closed. In this special case, modified metadata will -also be flushed to disk as if +will be flushed. In this special case, modified metadata will also be flushed +to disk as if .BR gd_metaflush (3) -had been called. +had been called. If the dirfile has been opened read-only, this function does +nothing. Additionally, some encoding schemes may implement this as a NOP. .PP -Metadata is written to disk using the current Standards Version as stored in the -.I dirfile -object. See -.BR gd_dirfile_standards (3) -to change or report the current Standards Version. If the dirfile metadata -conforms to no known Standards Version, a Standards non-compliant fragment will -be written. +The +.BR gd_raw_close () +function closes any raw data files which GetData has opened associated with +.IR field_code , +or its input(s). Again, if +.I field_code +is NULL, all open data files are closed. +.PP +Calling +.BR gd_flush () +is essentially equivalent to calling first +.BR gd_sync () +and then +.BR gd_raw_close () +(ie. it does both tasks), although, if +.I field_code +is NULL, the order of operations if may be different than making the two explict +calls. .SH RETURN VALUE -On success, zero is returned. On error, -1 is returned and the dirfile error is -set to a non-zero error value. Possible error values are: +On success, these functions return zero. On error, -1 is returned and the +dirfile error is set to a non-zero error value. Possible error values are: .TP 8 .B GD_E_ALLOC The library was unable to allocate memory. @@ -71,6 +89,8 @@ was not recognised. .TP .B GD_E_FLUSH +(Not +.BR gd_raw_close ().) A temporary file could not be opened into which to write the modified metadata, or renaming the temporary file over the original fragment failed. Only returned when Modified: trunk/getdata/man/gd_metaflush.3 =================================================================== --- trunk/getdata/man/gd_metaflush.3 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/man/gd_metaflush.3 2012-03-15 23:03:36 UTC (rev 676) @@ -1,6 +1,6 @@ .\" gd_metaflush.3. The gd_metaflush man page. .\" -.\" Copyright (C) 2008, 2010, 2011 D. V. Wiebe +.\" Copyright (C) 2008, 2010, 2011, 2012 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_metaflush 3 "19 August 2011" "Version 0.8.0" "GETDATA" +.TH gd_metaflush 3 "15 March 2012" "Version 0.8.0" "GETDATA" .SH NAME gd_metaflush \(em write modified dirfile metadata to disk .SH SYNOPSIS @@ -30,7 +30,7 @@ function flushes all pending metadata changes in the dirfile specified by .I dirfile to disk. This is accomplished by re-writing the format specification fragments -containing modified metadata overwriting the existing files. Format file +containing modified metadata, overwriting the existing files. Format file fragments which are unchanged are not touched. .PP Metadata is written to disk using the current Standards Version as stored in the @@ -42,7 +42,7 @@ be written. .PP This function flushes only metadata. To flush the field data as well, call -.BR gd_flush (3) +.BR gd_sync (3) instead. .SH RETURN VALUE On success, zero is returned. On error, -1 is returned and the dirfile error is @@ -77,5 +77,5 @@ .BR gd_dirfile_standards (3), .BR gd_error (3), .BR gd_error_string (3), -.BR gd_flush (3), -.BR gd_rewrite_fragment (3) +.BR gd_rewrite_fragment (3), +.BR gd_sync (3) Property changes on: trunk/getdata/src ___________________________________________________________________ Modified: svn:ignore - .deps .libs config.h config.h.in getdata.h getdata.pc stamp-h* Makefile Makefile.in *.lo *.la *.swp getdata.ah + .deps .libs gd_config.h gd_config.h.in getdata.h getdata.pc stamp-h* Makefile Makefile.in *.lo *.la *.swp getdata.ah Modified: trunk/getdata/src/fragment.c =================================================================== --- trunk/getdata/src/fragment.c 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/src/fragment.c 2012-03-15 23:03:36 UTC (rev 676) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008,2010,2011 D. V. Wiebe +/* Copyright (C) 2008, 2010, 2011, 2012 D. V. Wiebe * *************************************************************************** * @@ -378,8 +378,16 @@ gd_parser_callback_t sehandler = D->sehandler; void *extra = D->sehandler_extra; unsigned long int flags = D->open_flags; + int dirfd = -1; - int dirfd = (flags & GD_DESYNC_PATHCHECK) ? -1 : D->fragment[0].dirfd; + if (!(flags & GD_DESYNC_PATHCHECK)) { + dirfd = dup(D->fragment[0].dirfd); + if (dirfd == -1) { + _GD_SetError(D, GD_E_RAW_IO, 0, D->name, errno, NULL); + dreturn("%i", -1); + return -1; + } + } D->name = NULL; /* so FreeD doesn't delete it */ if (_GD_ShutdownDirfile(D, 0, 1)) { Modified: trunk/getdata/src/internal.h =================================================================== --- trunk/getdata/src/internal.h 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/src/internal.h 2012-03-15 23:03:36 UTC (rev 676) @@ -23,7 +23,7 @@ #define GETDATA_INTERNAL_H #ifdef HAVE_CONFIG_H -#include "config.h" +#include "gd_config.h" #endif #include "getdata.h" Property changes on: trunk/getdata/test ___________________________________________________________________ Modified: svn:ignore - Makefile Makefile.in *.o *.odirfile *.swp *.exe .deps .libs add add_affix add_alias add_alias_meta add_bit add_bit_bitnum add_bit_bitsize add_bit_invalid add_bit_numbits 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_invalid add_lincom_nfields add_linterp add_linterp_invalid add_meta add_meta_alias add_mplex add_mplex_val add_multiply add_multiply_invalid add_phase add_phase_invalid add_polynom add_protect add_raw add_raw_include add_raw_invalid add_raw_spf add_raw_type add_rdonly add_recip add_resolv add_sbit add_scalar add_scalar_carray 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_list alias_list_alias alias_list_missing alias_num alias_num_alias alias_num_missing alias_target alias_target_alias alias_target_missing alter_bit_bitnum alter_bit_numbits alter_carray_len alter_carray_type alter_const alter_cpolynom alter_crecip alter_crecip89 alter_crecip_zero alter_divide alter_entry alter_entry_affix alter_entry_hidden alter_entry_recode alter_entry_scalar2a alter_entry_scalar2n alter_entry_scalar3 alter_entry_scalar4 alter_lincom_23 alter_lincom_32 alter_lincom_input alter_lincom_offset alter_lincom_slope alter_linterp alter_linterp_move alter_mplex alter_mspec alter_mspec_affix alter_multiply alter_phase alter_polynom_coeff alter_polynom_input alter_polynom_ord alter_raw_spf alter_raw_type alter_recip alter_recip_zero alter_spec alter_spec_affix alter_spec_meta alter_window ascii_add ascii_get ascii_get_get ascii_nframes ascii_put bof bof_lincom bof_phase bzip_get bzip_get_get bzip_move_from bzip_nframes bzip_put close close_bad close_discard close_null convert_complex128_complex64 convert_complex128_float64 convert_complex128_int64 convert_complex128_uint64 convert_complex64_complex128 convert_complex64_float64 convert_complex64_int64 convert_complex64_uint64 convert_float32_complex128 convert_float32_complex64 convert_float32_float64 convert_float32_int16 convert_float32_int32 convert_float32_int64 convert_float32_int8 convert_float32_uint16 convert_float32_uint32 convert_float32_uint64 convert_float32_uint8 convert_float64_complex128 convert_float64_complex64 convert_float64_float32 convert_float64_int16 convert_float64_int32 convert_float64_int64 convert_float64_int8 convert_float64_uint16 convert_float64_uint32 convert_float64_uint64 convert_float64_uint8 convert_int16_complex128 convert_int16_complex64 convert_int16_float32 convert_int16_float64 convert_int16_int32 convert_int16_int64 convert_int16_int8 convert_int16_uint16 convert_int16_uint32 convert_int16_uint64 convert_int16_uint8 convert_int32_complex128 convert_int32_complex64 convert_int32_float32 convert_int32_float64 convert_int32_int16 convert_int32_int64 convert_int32_int8 convert_int32_uint16 convert_int32_uint32 convert_int32_uint64 convert_int32_uint8 convert_int64_complex128 convert_int64_complex64 convert_int64_float32 convert_int64_float64 convert_int64_int16 convert_int64_int32 convert_int64_int8 convert_int64_uint16 convert_int64_uint32 convert_int64_uint64 convert_int64_uint8 convert_int8_complex128 convert_int8_complex64 convert_int8_float32 convert_int8_float64 convert_int8_int16 convert_int8_int32 convert_int8_int64 convert_int8_uint16 convert_int8_uint32 convert_int8_uint64 convert_int8_uint8 convert_uint16_complex128 convert_uint16_complex64 convert_uint16_float32 convert_uint16_float64 convert_uint16_int16 convert_uint16_int32 convert_uint16_int64 convert_uint16_int8 convert_uint16_uint32 convert_uint16_uint64 convert_uint16_uint8 convert_uint32_complex128 convert_uint32_complex64 convert_uint32_float32 convert_uint32_float64 convert_uint32_int16 convert_uint32_int32 convert_uint32_int64 convert_uint32_int8 convert_uint32_uint16 convert_uint32_uint64 convert_uint32_uint8 convert_uint64_complex128 convert_uint64_complex64 convert_uint64_float32 convert_uint64_float64 convert_uint64_int16 convert_uint64_int32 convert_uint64_int64 convert_uint64_int8 convert_uint64_uint16 convert_uint64_uint32 convert_uint64_uint8 convert_uint8_complex128 convert_uint8_complex64 convert_uint8_float32 convert_uint8_float64 convert_uint8_int16 convert_uint8_int32 convert_uint8_int64 convert_uint8_int8 convert_uint8_uint16 convert_uint8_uint32 convert_uint8_uint64 creat creat_excl creat_rdonly cvlist cvlist_array cvlist_array_hidden cvlist_array_meta cvlist_array_meta_hidden cvlist_hidden cvlist_invalid 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_derived del_derived_after del_derived_force del_meta del_meta_force desync desync_flush dfes_bit dfes_divide dfes_lincom dfes_linterp dfes_multiply dfes_null dfes_phase dfes_raw dfes_recip dfes_zero encode_alter encode_get encode_move endian_alter endian_alter_sie endian_get endian_move entry_bad_code entry_bit entry_bit_scalar entry_divide entry_invalid entry_lincom entry_lincom_scalar entry_linterp entry_mplex entry_mplex_scalar entry_multiply entry_phase entry_phase_scalar entry_polynom entry_polynom_scalar entry_raw entry_raw_scalar entry_raw_scalar_code entry_raw_scalar_type entry_recip entry_scalar_repr entry_type entry_type_alias entry_window entry_window_scalar eof eof_index eof_lincom eof_phase error error_error error_num error_short file file_code file_type flist flist_hidden flist_invalid flist_meta flist_meta_hidden flist_meta_invalid flist_type flist_type_hidden flist_type_invalid flist_type_meta flist_type_meta_hidden flist_type_meta_invalid flush flush_all flush_bad_code flush_invalid flush_meta flush_spec foffs_alter foffs_get foffs_move fragment_affix fragment_affix_alter fragment_affix_alter2 fragment_affix_dup fragment_index fragment_index_alias fragment_name fragment_name_oor fragment_num fragment_parent get64 get_bad_code get_bit get_carray get_carray_len get_carray_slice get_char get_clincom get_complex128 get_complex64 get_const get_const_complex get_const_repr get_cpolynom get_divide get_endian16 get_endian32 get_endian64 get_endian8 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_int16 get_int32 get_int64 get_int8 get_invalid get_lincom1 get_lincom2 get_lincom3 get_lincom_noin get_lincom_non get_lincom_spf get_linterp get_linterp_noin get_linterp_notab get_linterp_sort get_mplex get_mplex_lb get_multiply get_multiply_noin get_nonexistent get_null get_off64 get_phase get_phase_affix get_polynom get_polynom_noin get_recip get_recip_const get_recurse get_rofs get_sbit get_sf get_ss get_type get_uint16 get_uint32 get_uint64 get_window get_window_clr get_window_ge get_window_gt get_window_le get_window_lt get_window_ne get_window_set get_zero global_name global_ref global_ref_empty global_ref_set gzip_add gzip_get gzip_get_get gzip_get_put gzip_move_from gzip_move_to gzip_nframes gzip_put gzip_put_get header_complex hide hide_hidden hide_unhide include include_accmode include_affix include_auto include_cb include_creat include_ignore include_index include_invalid include_nonexistent include_pc include_ref include_syntax index index_domain index_range legacy_get legacy_get_put legacy_get_rofs legacy_nframes legacy_nonexistent legacy_put legacy_spf lzma_get lzma_nframes madd madd_affix madd_alias madd_bit madd_bit_invalid madd_carray madd_clincom madd_const madd_cpolynom madd_crecip madd_crecip89 madd_divide madd_index madd_lincom madd_lincom_invalid madd_linterp madd_linterp_invalid madd_mplex madd_multiply madd_multiply_invalid madd_phase madd_phase_invalid madd_polynom madd_recip madd_sbit madd_spec madd_spec_directive madd_spec_invalid madd_spec_resolv madd_string madd_window move 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 name name_affix name_affix_bad name_after name_after_const name_dup name_move name_update name_update_const nfields nfields_hidden nfields_invalid nfields_type nfields_type_hidden nfields_type_invalid nfields_vector nfields_vector_hidden nfields_vector_invalid nframes nframes64 nframes_empty nframes_invalid nframes_off64 nframes_spf nmeta nmeta_hidden nmeta_invalid nmeta_parent nmeta_type nmeta_type_hidden nmeta_type_invalid nmeta_type_parent nmeta_vectors nmeta_vectors_del nmeta_vectors_hidden nmeta_vectors_invalid nmeta_vectors_parent open open_cb_abort open_cb_cont open_cb_ignore open_cb_invalid open_cb_rescan open_eaccess open_nonexistent open_notdirfile parse_alias parse_alias_code parse_alias_dup parse_alias_meta parse_alias_missing parse_badline parse_bit parse_bit4 parse_bit_bitnum parse_bit_bitsize parse_bit_ncols parse_bit_numbits parse_bit_scalar parse_carray parse_carray_long parse_const parse_const_ncols parse_divide parse_duplicate parse_duplicate_ignore parse_endian_bad parse_endian_big parse_endian_force parse_endian_little parse_endian_slash parse_eol parse_foffs parse_foffs_include parse_foffs_slash parse_hidden parse_hidden_field parse_hidden_meta parse_include parse_include_absolute parse_include_absrel parse_include_loop parse_include_nonexistent parse_include_prefix parse_include_prefix_dup parse_include_preprefix parse_include_relabs parse_include_relrel parse_include_slash parse_include_suffix parse_include_sufsuffix parse_index parse_lincom parse_lincom_ncols1 parse_lincom_ncols2 parse_lincom_nfields parse_lincom_nofields parse_lincom_non parse_lincom_non_ncols parse_lincom_scalar parse_linterp parse_linterp_ncols parse_malias parse_malias_dup parse_meta parse_meta_affix parse_meta_alias parse_meta_implicit parse_meta_implicit2 parse_meta_implicit_affix parse_meta_index parse_meta_index2 parse_meta_jump parse_meta_malias parse_meta_meta parse_meta_parent parse_meta_raw parse_mplex parse_mplex_ncols parse_mplex_scalar parse_multiply parse_multiply_ncols parse_name parse_name_dot parse_name_ext parse_name_pedantic parse_ncols parse_phase parse_phase_ncols parse_phase_scalar parse_polynom parse_polynom_ncols1 parse_polynom_ncols2 parse_polynom_scalar parse_protect_all parse_protect_bad parse_protect_data parse_protect_format parse_protect_none parse_quote parse_quote_mismatch parse_raw parse_raw_char parse_raw_ncols parse_raw_scalar parse_raw_spf parse_raw_type parse_recip parse_ref parse_ref_nonexistent parse_sbit parse_sort parse_string parse_string_ncols parse_string_null parse_version parse_version_89 parse_version_98 parse_version_include parse_version_p8 parse_version_p9 parse_version_permissive parse_version_slash parse_whitespace parse_window parse_window_ncols parse_window_op parse_window_scalar protect_alter protect_get put64 put_bad_code put_bit put_bof put_carray put_carray_slice put_char put_complex128 put_complex64 put_const put_const_protect put_divide put_endian16 put_endian32 put_endian64 put_endian8 put_endian_complex128_arm put_endian_complex128_big put_endian_complex128_little put_endian_complex64_arm put_endian_complex64_big put_endian_complex64_little put_endian_float32_arm put_endian_float32_big put_endian_float32_little put_endian_float64_arm put_endian_float64_big put_endian_float64_little put_ff put_float32 put_float64 put_foffs put_fs put_here put_heres put_int16 put_int32 put_int64 put_int8 put_invalid put_lincom1 put_lincom2 put_lincom_noin put_linterp put_linterp_noin put_linterp_nomono put_linterp_notab put_linterp_reverse put_mplex 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_uint64 put_window put_zero ref ref_none ref_two repr_a repr_float32 repr_float64 repr_i repr_int16 repr_int32 repr_int64 repr_int8 repr_m repr_r repr_real_a repr_real_i repr_real_m repr_real_r repr_uint16 repr_uint32 repr_uint64 repr_uint8 seek64 seek_cur seek_end seek_foffs seek_set sie_get_big sie_get_little sie_move_from sie_move_to sie_nframes_big sie_nframes_little sie_put_big sie_put_little slim_get slim_nframes slim_put spf spf_alias spf_alias_meta spf_alias_missing spf_divide spf_lincom spf_multiply spf_polynom spf_recip spf_recurse svlist svlist_hidden svlist_invalid svlist_meta svlist_meta_hidden svlist_meta_invalid tell tell64 trunc trunc_dir trunc_rdonly trunc_rofs trunc_truncsub unclude unclude_del unclude_move version_0 version_0_write version_1 version_1_write version_2 version_2_write version_3 version_3_write version_4 version_4_write version_5 version_5_strict version_5_write version_6 version_6_strict version_6_write version_7 version_7_strict version_7_write version_8 version_8_strict version_8_write version_9 version_9_strict version_9_write vlist vlist_alias vlist_hidden vlist_invalid vlist_meta vlist_meta_hidden vlist_meta_invalid xz_get xz_nframes zzip_data zzip_get zzip_get_get zzip_nframes zzslim_get zzslim_nframes + Makefile Makefile.in *.o dirfile *.swp *.exe .deps .libs add add_affix add_alias add_alias_meta add_bit add_bit_bitnum add_bit_bitsize add_bit_invalid add_bit_numbits 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_invalid add_lincom_nfields add_linterp add_linterp_invalid add_meta add_meta_alias add_mplex add_mplex_val add_multiply add_multiply_invalid add_phase add_phase_invalid add_polynom add_protect add_raw add_raw_include add_raw_invalid add_raw_spf add_raw_type add_rdonly add_recip add_resolv add_sbit add_scalar add_scalar_carray 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_list alias_list_alias alias_list_missing alias_num alias_num_alias alias_num_missing alias_target alias_target_alias alias_target_missing alter_bit_bitnum alter_bit_numbits alter_carray_len alter_carray_type alter_const alter_cpolynom alter_crecip alter_crecip89 alter_crecip_zero alter_divide alter_entry alter_entry_affix alter_entry_hidden alter_entry_recode alter_entry_scalar2a alter_entry_scalar2n alter_entry_scalar3 alter_entry_scalar4 alter_lincom_23 alter_lincom_32 alter_lincom_input alter_lincom_offset alter_lincom_slope alter_linterp alter_linterp_move alter_mplex alter_mspec alter_mspec_affix alter_multiply alter_phase alter_polynom_coeff alter_polynom_input alter_polynom_ord alter_raw_spf alter_raw_type alter_recip alter_recip_zero alter_spec alter_spec_affix alter_spec_meta alter_window ascii_add ascii_get ascii_get_get ascii_nframes ascii_put bof bof_lincom bof_phase bzip_get bzip_get_get bzip_move_from bzip_nframes bzip_put close close_bad close_discard close_null convert_complex128_complex64 convert_complex128_float64 convert_complex128_int64 convert_complex128_uint64 convert_complex64_complex128 convert_complex64_float64 convert_complex64_int64 convert_complex64_uint64 convert_float32_complex128 convert_float32_complex64 convert_float32_float64 convert_float32_int16 convert_float32_int32 convert_float32_int64 convert_float32_int8 convert_float32_uint16 convert_float32_uint32 convert_float32_uint64 convert_float32_uint8 convert_float64_complex128 convert_float64_complex64 convert_float64_float32 convert_float64_int16 convert_float64_int32 convert_float64_int64 convert_float64_int8 convert_float64_uint16 convert_float64_uint32 convert_float64_uint64 convert_float64_uint8 convert_int16_complex128 convert_int16_complex64 convert_int16_float32 convert_int16_float64 convert_int16_int32 convert_int16_int64 convert_int16_int8 convert_int16_uint16 convert_int16_uint32 convert_int16_uint64 convert_int16_uint8 convert_int32_complex128 convert_int32_complex64 convert_int32_float32 convert_int32_float64 convert_int32_int16 convert_int32_int64 convert_int32_int8 convert_int32_uint16 convert_int32_uint32 convert_int32_uint64 convert_int32_uint8 convert_int64_complex128 convert_int64_complex64 convert_int64_float32 convert_int64_float64 convert_int64_int16 convert_int64_int32 convert_int64_int8 convert_int64_uint16 convert_int64_uint32 convert_int64_uint64 convert_int64_uint8 convert_int8_complex128 convert_int8_complex64 convert_int8_float32 convert_int8_float64 convert_int8_int16 convert_int8_int32 convert_int8_int64 convert_int8_uint16 convert_int8_uint32 convert_int8_uint64 convert_int8_uint8 convert_uint16_complex128 convert_uint16_complex64 convert_uint16_float32 convert_uint16_float64 convert_uint16_int16 convert_uint16_int32 convert_uint16_int64 convert_uint16_int8 convert_uint16_uint32 convert_uint16_uint64 convert_uint16_uint8 convert_uint32_complex128 convert_uint32_complex64 convert_uint32_float32 convert_uint32_float64 convert_uint32_int16 convert_uint32_int32 convert_uint32_int64 convert_uint32_int8 convert_uint32_uint16 convert_uint32_uint64 convert_uint32_uint8 convert_uint64_complex128 convert_uint64_complex64 convert_uint64_float32 convert_uint64_float64 convert_uint64_int16 convert_uint64_int32 convert_uint64_int64 convert_uint64_int8 convert_uint64_uint16 convert_uint64_uint32 convert_uint64_uint8 convert_uint8_complex128 convert_uint8_complex64 convert_uint8_float32 convert_uint8_float64 convert_uint8_int16 convert_uint8_int32 convert_uint8_int64 convert_uint8_int8 convert_uint8_uint16 convert_uint8_uint32 convert_uint8_uint64 creat creat_excl creat_rdonly cvlist cvlist_array cvlist_array_hidden cvlist_array_meta cvlist_array_meta_hidden cvlist_hidden cvlist_invalid 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_derived del_derived_after del_derived_force del_meta del_meta_force desync desync_flush desync_reopen desync_reopen_inv dfes_bit dfes_divide dfes_lincom dfes_linterp dfes_multiply dfes_null dfes_phase dfes_raw dfes_recip dfes_zero encode_alter encode_get encode_move endian_alter endian_alter_sie endian_get endian_move entry_bad_code entry_bit entry_bit_scalar entry_divide entry_invalid entry_lincom entry_lincom_scalar entry_linterp entry_mplex entry_mplex_scalar entry_multiply entry_phase entry_phase_scalar entry_polynom entry_polynom_scalar entry_raw entry_raw_scalar entry_raw_scalar_code entry_raw_scalar_type entry_recip entry_scalar_repr entry_type entry_type_alias entry_window entry_window_scalar eof eof_index eof_lincom eof_phase error error_error error_num error_short file file_code file_type flist flist_hidden flist_invalid flist_meta flist_meta_hidden flist_meta_invalid flist_type flist_type_hidden flist_type_invalid flist_type_meta flist_type_meta_hidden flist_type_meta_invalid flush flush_all flush_bad_code flush_invalid flush_meta flush_spec foffs_alter foffs_get foffs_move fragment_affix fragment_affix_alter fragment_affix_alter2 fragment_affix_dup fragment_index fragment_index_alias fragment_name fragment_name_oor fragment_num fragment_parent get64 get_bad_code get_bit get_carray get_carray_len get_carray_slice get_char get_clincom get_complex128 get_complex64 get_const get_const_complex get_const_repr get_cpolynom get_divide get_endian16 get_endian32 get_endian64 get_endian8 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_int16 get_int32 get_int64 get_int8 get_invalid get_lincom1 get_lincom2 get_lincom3 get_lincom_noin get_lincom_non get_lincom_spf get_linterp get_linterp_noin get_linterp_notab get_linterp_sort get_mplex get_mplex_lb get_multiply get_multiply_noin get_nonexistent get_null get_off64 get_phase get_phase_affix get_polynom get_polynom_noin get_recip get_recip_const get_recurse get_rofs get_sbit get_sf get_ss get_type get_uint16 get_uint32 get_uint64 get_window get_window_clr get_window_ge get_window_gt get_window_le get_window_lt get_window_ne get_window_set get_zero global_name global_ref global_ref_empty global_ref_set gzip_add gzip_get gzip_get_get gzip_get_put gzip_move_from gzip_move_to gzip_nframes gzip_put gzip_put_get header_complex hide hide_hidden hide_unhide include include_accmode include_affix include_auto include_cb include_creat include_ignore include_index include_invalid include_nonexistent include_pc include_ref include_syntax index index_domain index_range legacy_get legacy_get_put legacy_get_rofs legacy_nframes legacy_nonexistent legacy_put legacy_spf lzma_get lzma_nframes madd madd_affix madd_alias madd_bit madd_bit_invalid madd_carray madd_clincom madd_const madd_cpolynom madd_crecip madd_crecip89 madd_divide madd_index madd_lincom madd_lincom_invalid madd_linterp madd_linterp_invalid madd_mplex madd_multiply madd_multiply_invalid madd_phase madd_phase_invalid madd_polynom madd_recip madd_sbit madd_spec madd_spec_directive madd_spec_invalid madd_spec_resolv madd_string madd_window move 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 name name_affix name_affix_bad name_after name_after_const name_dup name_move name_update name_update_const nfields nfields_hidden nfields_invalid nfields_type nfields_type_hidden nfields_type_invalid nfields_vector nfields_vector_hidden nfields_vector_invalid nframes nframes64 nframes_empty nframes_invalid nframes_off64 nframes_spf nmeta nmeta_hidden nmeta_invalid nmeta_parent nmeta_type nmeta_type_hidden nmeta_type_invalid nmeta_type_parent nmeta_vectors nmeta_vectors_del nmeta_vectors_hidden nmeta_vectors_invalid nmeta_vectors_parent open open_cb_abort open_cb_cont open_cb_ignore open_cb_invalid open_cb_rescan open_eaccess open_nonexistent open_notdirfile parse_alias parse_alias_code parse_alias_dup parse_alias_meta parse_alias_missing parse_badline parse_bit parse_bit4 parse_bit_bitnum parse_bit_bitsize parse_bit_ncols parse_bit_numbits parse_bit_scalar parse_carray parse_carray_long parse_const parse_const_ncols parse_divide parse_duplicate parse_duplicate_ignore parse_endian_bad parse_endian_big parse_endian_force parse_endian_little parse_endian_slash parse_eol parse_foffs parse_foffs_include parse_foffs_slash parse_hidden parse_hidden_field parse_hidden_meta parse_include parse_include_absolute parse_include_absrel parse_include_loop parse_include_nonexistent parse_include_prefix parse_include_prefix_dup parse_include_preprefix parse_include_relabs parse_include_relrel parse_include_slash parse_include_suffix parse_include_sufsuffix parse_index parse_lincom parse_lincom_ncols1 parse_lincom_ncols2 parse_lincom_nfields parse_lincom_nofields parse_lincom_non parse_lincom_non_ncols parse_lincom_scalar parse_linterp parse_linterp_ncols parse_malias parse_malias_dup parse_meta parse_meta_affix parse_meta_alias parse_meta_implicit parse_meta_implicit2 parse_meta_implicit_affix parse_meta_index parse_meta_index2 parse_meta_jump parse_meta_malias parse_meta_meta parse_meta_parent parse_meta_raw parse_mplex parse_mplex_ncols parse_mplex_scalar parse_multiply parse_multiply_ncols parse_name parse_name_dot parse_name_ext parse_name_pedantic parse_ncols parse_phase parse_phase_ncols parse_phase_scalar parse_polynom parse_polynom_ncols1 parse_polynom_ncols2 parse_polynom_scalar parse_protect_all parse_protect_bad parse_protect_data parse_protect_format parse_protect_none parse_quote parse_quote_mismatch parse_raw parse_raw_char parse_raw_ncols parse_raw_scalar parse_raw_spf parse_raw_type parse_recip parse_ref parse_ref_nonexistent parse_sbit parse_sort parse_string parse_string_ncols parse_string_null parse_version parse_version_89 parse_version_98 parse_version_include parse_version_p8 parse_version_p9 parse_version_permissive parse_version_slash parse_whitespace parse_window parse_window_ncols parse_window_op parse_window_scalar protect_alter protect_get put64 put_bad_code put_bit put_bof put_carray put_carray_slice put_char put_complex128 put_complex64 put_const put_const_protect put_divide put_endian16 put_endian32 put_endian64 put_endian8 put_endian_complex128_arm put_endian_complex128_big put_endian_complex128_little put_endian_complex64_arm put_endian_complex64_big put_endian_complex64_little put_endian_float32_arm put_endian_float32_big put_endian_float32_little put_endian_float64_arm put_endian_float64_big put_endian_float64_little put_ff put_float32 put_float64 put_foffs put_fs put_here put_heres put_int16 put_int32 put_int64 put_int8 put_invalid put_lincom1 put_lincom2 put_lincom_noin put_linterp put_linterp_noin put_linterp_nomono put_linterp_notab put_linterp_reverse put_mplex 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_uint64 put_window put_zero ref ref_none ref_two repr_a repr_float32 repr_float64 repr_i repr_int16 repr_int32 repr_int64 repr_int8 repr_m repr_r repr_real_a repr_real_i repr_real_m repr_real_r repr_uint16 repr_uint32 repr_uint64 repr_uint8 seek64 seek_cur seek_end seek_foffs seek_set sie_get_big sie_get_little sie_move_from sie_move_to sie_nframes_big sie_nframes_little sie_put_big sie_put_little slim_get slim_nframes slim_put spf spf_alias spf_alias_meta spf_alias_missing spf_divide spf_lincom spf_multiply spf_polynom spf_recip spf_recurse svlist svlist_hidden svlist_invalid svlist_meta svlist_meta_hidden svlist_meta_invalid tell tell64 trunc trunc_dir trunc_rdonly trunc_rofs trunc_truncsub unclude unclude_del unclude_move version_0 version_0_write version_1 version_1_write version_2 version_2_write version_3 version_3_write version_4 version_4_write version_5 version_5_strict version_5_write version_6 version_6_strict version_6_write version_7 version_7_strict version_7_write version_8 version_8_strict version_8_write version_9 version_9_strict version_9_write vlist vlist_alias vlist_hidden vlist_invalid vlist_meta vlist_meta_hidden vlist_meta_invalid xz_get xz_nframes zzip_data zzip_get zzip_get_get zzip_nframes zzslim_get zzslim_nframes Modified: trunk/getdata/test/Makefile.am =================================================================== --- trunk/getdata/test/Makefile.am 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/test/Makefile.am 2012-03-15 23:03:36 UTC (rev 676) @@ -144,7 +144,7 @@ DFES_TESTS=dfes_bit dfes_divide dfes_lincom dfes_linterp dfes_multiply \ dfes_null dfes_phase dfes_raw dfes_recip dfes_zero -DESYNC_TESTS=desync desync_flush +DESYNC_TESTS=desync desync_flush desync_reopen desync_reopen_inv ENCODE_TESTS=encode_alter encode_get encode_move Modified: trunk/getdata/test/bzip_get.c =================================================================== --- trunk/getdata/test/bzip_get.c 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/test/bzip_get.c 2012-03-15 23:03:36 UTC (rev 676) @@ -19,7 +19,6 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Attempt to read UINT8 */ -#include "../src/config.h" #include "test.h" #include <inttypes.h> Modified: trunk/getdata/test/bzip_move_from.c =================================================================== --- trunk/getdata/test/bzip_move_from.c 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/test/bzip_move_from.c 2012-03-15 23:03:36 UTC (rev 676) @@ -19,9 +19,6 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Test move */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif #include "test.h" #include <stdlib.h> Modified: trunk/getdata/test/bzip_nframes.c =================================================================== --- trunk/getdata/test/bzip_nframes.c 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/test/bzip_nframes.c 2012-03-15 23:03:36 UTC (rev 676) @@ -19,7 +19,6 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Retreiving the number of frames should succeed cleanly */ -#include "../src/config.h" #include "test.h" #include <stdlib.h> Added: trunk/getdata/test/desync_reopen.c =================================================================== --- trunk/getdata/test/desync_reopen.c (rev 0) +++ trunk/getdata/test/desync_reopen.c 2012-03-15 23:03:36 UTC (rev 676) @@ -0,0 +1,68 @@ +/* Copyright (C) 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 + */ +#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"; + const char *format_data = "data RAW UINT8 1\n"; + int e1, e2, e3, n1, n2, fd, 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); + e1 = gd_error(D); + + /* ensure mtime ticks over */ + sleep(1); + + /* modify the format file */ + fd = open(format, O_CREAT | O_TRUNC | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + n1 = gd_desync(D, GD_DESYNC_REOPEN); + e2 = gd_error(D); + n2 = gd_validate(D, "data"); + e3 = gd_error(D); + + gd_close(D); + + unlink(format); + rmdir(filedir); + + CHECKI(e1, 0); + CHECKI(e2, 0); + CHECKI(e3, 0); + CHECKI(n1, 1); + CHECKI(n2, 0); + return r; +} Added: trunk/getdata/test/desync_reopen_inv.c =================================================================== --- trunk/getdata/test/desync_reopen_inv.c (rev 0) +++ trunk/getdata/test/desync_reopen_inv.c 2012-03-15 23:03:36 UTC (rev 676) @@ -0,0 +1,68 @@ +/* Copyright (C) 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 + */ +#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"; + const char *format_data = "bad format\n"; + int e1, e2, e3, n1, n2, fd, r = 0; + DIRFILE *D; + + rmdirfile(); + mkdir(filedir, 0777); + close(open(format, O_CREAT | O_EXCL | O_WRONLY, 0666)); + + D = gd_open(filedir, GD_RDONLY); + e1 = gd_error(D); + + /* ensure mtime ticks over */ + sleep(1); + + /* modify the format file */ + fd = open(format, O_CREAT | O_TRUNC | O_WRONLY, 0666); + write(fd, format_data, strlen(format_data)); + close(fd); + + n1 = gd_desync(D, GD_DESYNC_REOPEN); + e2 = gd_error(D); + n2 = gd_validate(D, "data"); + e3 = gd_error(D); + + gd_close(D); + + unlink(format); + rmdir(filedir); + + CHECKI(e1, GD_E_OK); + CHECKI(e2, GD_E_FORMAT); + CHECKI(e3, GD_E_BAD_DIRFILE); + CHECKI(n1, -1); + CHECKI(n2, -1); + return r; +} Modified: trunk/getdata/test/endian_alter.c =================================================================== --- trunk/getdata/test/endian_alter.c 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/test/endian_alter.c 2012-03-15 23:03:36 UTC (rev 676) @@ -19,7 +19,6 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Test endianness */ -#include "../src/config.h" #include "test.h" #include <stdlib.h> Modified: trunk/getdata/test/endian_alter_sie.c =================================================================== --- trunk/getdata/test/endian_alter_sie.c 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/test/endian_alter_sie.c 2012-03-15 23:03:36 UTC (rev 676) @@ -19,7 +19,6 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Test endianness */ -#include "../src/config.h" #include "test.h" #include <stdlib.h> Modified: trunk/getdata/test/endian_get.c =================================================================== --- trunk/getdata/test/endian_get.c 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/test/endian_get.c 2012-03-15 23:03:36 UTC (rev 676) @@ -19,7 +19,6 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Test endianness */ -#include "../src/config.h" #include "test.h" #include <stdlib.h> Modified: trunk/getdata/test/endian_move.c =================================================================== --- trunk/getdata/test/endian_move.c 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/test/endian_move.c 2012-03-15 23:03:36 UTC (rev 676) @@ -19,7 +19,6 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Test endianness */ -#include "../src/config.h" #include "test.h" #include <stdlib.h> Modified: trunk/getdata/test/gzip_get.c =================================================================== --- trunk/getdata/test/gzip_get.c 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/test/gzip_get.c 2012-03-15 23:03:36 UTC (rev 676) @@ -19,9 +19,6 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Attempt to read UINT8 */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif #include "test.h" #include <inttypes.h> Modified: trunk/getdata/test/gzip_get_get.c =================================================================== --- trunk/getdata/test/gzip_get_get.c 2012-03-15 01:09:21 UTC (rev 675) +++ trunk/getdata/test/gzip_get_get.c 2012-03-15 23:03:36 UTC (rev 676) @@ -19,7 +19,6 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* Attempt to read UINT8 */ -#include "../src/config.h" #include "test.h" #include <inttypes.h> Modified: trunk/getdata/... [truncated message content] |
From: <ket...@us...> - 2012-03-15 01:09:29
|
Revision: 675 http://getdata.svn.sourceforge.net/getdata/?rev=675&view=rev Author: ketiltrout Date: 2012-03-15 01:09:21 +0000 (Thu, 15 Mar 2012) Log Message: ----------- * gd_desync * Use threadsafe readdir(3) while truncating. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/bindings/cxx/dirfile.cpp trunk/getdata/bindings/cxx/getdata/dirfile.h trunk/getdata/bindings/cxx/test/big_test.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/Makefile.am trunk/getdata/bindings/perl/simple_funcs.xsin trunk/getdata/bindings/perl/t/big_test.t trunk/getdata/bindings/python/pydirfile.c trunk/getdata/bindings/python/test/big_test.py trunk/getdata/configure.ac trunk/getdata/doc/list.tests trunk/getdata/src/close.c trunk/getdata/src/compat.c trunk/getdata/src/flush.c trunk/getdata/src/fragment.c trunk/getdata/src/getdata.h.in trunk/getdata/src/include.c trunk/getdata/src/internal.h trunk/getdata/src/open.c trunk/getdata/test/Makefile.am Added Paths: ----------- trunk/getdata/test/desync.c trunk/getdata/test/desync_flush.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/ChangeLog 2012-03-15 01:09:21 UTC (rev 675) @@ -1,4 +1,44 @@ -2012-03-14 D. V. Wiebe <ge...@ke...> svn:673 +2012-03-15 D. V. Wiebe <ge...@ke...> svn:675 + * src/internal.h: Add fragment->mtime, dirfile->open_flags. Deconst + fragment->sname. + * src/close.c (_GD_FreeD _GD_ShutdownDirfile): Add new parameter + (keep_dirfile) to prohibit deallocating the dirfile struct itself. + De-staticked _GD_ShutdownDirfile. + * src/include.c (_GD_Include): Compute the path relative to the parent of + fragment and store it in fragment->sname. Store mtime. + * src/close.c (_GD_FreeD): Free fragment->sname. + * src/flush.c (_GD_FlushFragment): Remove unnecessary strdup: we already + cache the basename. Update mtime. + * src/open.c (_GD_CreateDirfile): Return mtime. + * src/open.c (_GD_Open): Renamed from gd_cbopen; optionally take an existing + dirfd and DIRFILE pointer. Fix the dirfd/dirfile race condition by + canonicalising dirfile first. + * src/fragment.c (gd_desync) src/open.c (gd_cbopen): Added. + * src/getdata.h.in: Added GD_DESYNC_PATHCHECK GD_DESYNC_REOPEN. + * test/desync.c test/desync_flush.c: Added. + + * src/internal.h (offsetof): Added. + * src/compat.c (gd_readdir): Added. + * src/open.c (_GD_TruncDir): Use a thread-safe readdir where possible. + + * src/include.c (gd_include_affix): Don't call do stuff before validating + the dirfile. + + * bindings/make_parameters.c: Add desync flags. + * bindings/python/pydirfile.c (gdpy_dirfile_desync) bindings/cxx/dirfile.cpp + (Dirfile::DeSync) bindings/perl/simple_funcs.xsin (desync) + bindings/f77/getdata.f90.in (fgd_desync) bindings/f77/fgetdata.c (GDDSYN) + bindings/idl/getdata.c (gdidl_desync): Added. + * bindings/python/test/big_test.py bindings/cxx/test/big_test.cpp + bindings/perl/t/big_test.t bindings/f77/test/big_test.f + bindings/f77/test/big_test95.f90 bindings/idl/test/big_test.pro: Added test + 234. + + * bindings/cxx/test/big_test.cpp: Functionise to reduce compilation work. + + * bindings/perl/Makefile.am: Tweak yet some more. + +2012-03-14 D. V. Wiebe <ge...@ke...> svn:674 * src/open.c (gd_cbopen): Handle failure of _GD_CanonicalPath better. 2012-03-14 D. V. Wiebe <ge...@ke...> svn:671 Modified: trunk/getdata/bindings/cxx/dirfile.cpp =================================================================== --- trunk/getdata/bindings/cxx/dirfile.cpp 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/cxx/dirfile.cpp 2012-03-15 01:09:21 UTC (rev 675) @@ -525,3 +525,17 @@ { return gd_tokenise(D, string); } + +int Dirfile::DeSync(unsigned int flags) +{ + int desync = gd_desync(D, flags); + if (desync && flags & GD_DESYNC_REOPEN) { + free(error_string); + free(reference_name); + + error_string = NULL; + reference_name = NULL; + } + + return desync; +} Modified: trunk/getdata/bindings/cxx/getdata/dirfile.h =================================================================== --- trunk/getdata/bindings/cxx/getdata/dirfile.h 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/cxx/getdata/dirfile.h 2012-03-15 01:09:21 UTC (rev 675) @@ -116,6 +116,8 @@ int DeleteAlias(const char* field_code, int flags = 0) const; + int DeSync(unsigned int flags = 0); + int Discard(); GetData::Entry* Entry(const char *field_code) const; Modified: trunk/getdata/bindings/cxx/test/big_test.cpp =================================================================== --- trunk/getdata/bindings/cxx/test/big_test.cpp 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/cxx/test/big_test.cpp 2012-03-15 01:09:21 UTC (rev 675) @@ -48,67 +48,77 @@ using namespace std; using namespace GetData; -#define CHECK_ERRORb(d,t,g) \ - e = d->Error(); if (e != (g)) { ne++; cerr << "e[" << t << "] = " << e << endl; } -#define CHECK_ERROR2b(d,t,n,g) \ - e = d->Error(); if (e != (g)) { \ - ne++; cerr << "e[" << t << ", " << n << "] = " << e << endl; } -#define CHECK_ERROR(t,g) CHECK_ERRORb(d,t,g) -#define CHECK_ERROR2(t,n,g) CHECK_ERROR2b(d,t,n,g) +static int ne = 0; + +template <class T> static void CheckT(char c, int i, int t, int n, T v, T g, + int r) +{ + if (r) { + ne++; + cerr << c; + if (i != -1) + cerr << "(" << i << ")"; + cerr << "[" << t; + if (n != -1) + cerr << ", " << n; + cerr << "] = " << v << " (expected " << g << ")" << endl; + } +} + +static void CheckError(const Dirfile *d, int t, int n, int g) +{ + int e = d->Error(); + CheckT<int>('e', -1, t, n, e, g, e != g); +} + +static void CheckInt(int i, int t, int n, int v, int g) +{ + CheckT<int>('n', i, t, n, v, g, v != g); +} + +template <class T> static void CheckFloat(char c, int i, int t, int n, T v, T g) +{ + CheckT<T>(c, i, t, n, v, g, (abs((v) - (g)) > 1e-10)); +} +#define CHECK_ERROR(t,g) CheckError(d,t,-1,g) +#define CHECK_ERROR2(t,n,g) CheckError(d,t,n,g) #define CHECK_OK(t) CHECK_ERROR(t,GD_E_OK) #define CHECK_OK2(t,n) CHECK_ERROR2(t,n,GD_E_OK) -#define CHECK_NONNULL(t,v) \ - if ((v) == NULL) { ne++; cerr << "p[" << t << "] = " << (v) << endl; } +#define CHECK_NONNULL(t,v) CheckT<const void*>('p', -1, t, -1, v, NULL, !(v)) -#define CHECK_NULL(t,v) \ - if ((v) != NULL) { ne++; cerr << "p[" << t << "] = " << (v) << endl; } +#define CHECK_NULL(t,v) CheckT<const void*>('p', -1, t, -1, v, NULL, v) +#define CHECK_NULL2(t,n,v) CheckT<const void*>('p', -1, t, n, v, NULL, v) -#define CHECK_NULL2(t,n,v) \ - if ((v) != NULL) { \ - ne++; cerr << "n[" << t << ", " << n << "] = " << (v) << endl; } +#define CHECK_INT(t,v,g) CheckInt(-1, t, -1, v, g) +#define CHECK_INT2(t,n,v,g) CheckInt(-1, t, n, v, g) -#define CHECK_INT(t,v,g) \ - if ((v) != (g)) { ne++; cerr << "n[" << t << "] = " << (v) << endl; } -#define CHECK_INT2(t,n,v,g) \ - if ((v) != (g)) { \ - ne++; cerr << "n[" << t << ", " << n << "] = " << (v) << endl; } #define CHECK_INT_ARRAY(t,m,v,g) \ - for (i = 0; i < m; ++i) if ((v) != (g)) { \ - ne++; cerr << "n(" << i << ")[" << t << "] = " << (int)v << endl; } + for (i = 0; i < m; ++i) CheckInt(i, t, -1, v, g) -#define CHECK_DOUBLE(t,v,g) \ - if (fabs((v) - (g)) > 1e-10) { \ - ne++; cerr << "d[" << t << "] = " << (v) << endl; } -#define CHECK_DOUBLE2(t,m,v,g) \ - if (fabs((v) - (g)) > 1e-10) { \ - ne++; cerr << "d[" << t << ", " << m << "] = " << (v) << endl; } -#define CHECK_DOUBLE_ARRAY(t,m,n,v,g) \ - for (i = 0; i < n; ++i) if (fabs((v) - (g)) > 1e-10) { \ - ne++; cerr << "d(" << i << ")[" << t << ", " << m << "] = " << (v) << endl; } +#define CHECK_DOUBLE(t,v,g) CheckFloat<double>('d', -1, t, -1, v, g) +#define CHECK_DOUBLE2(t,n,v,g) CheckFloat<double>('d', -1, t, n, v, g) +#define CHECK_DOUBLE_ARRAY(t,n,m,v,g) \ + for (i = 0; i < m; ++i) CheckFloat<double>('d', i, t, n, v, g) + #define CHECK_STRING(t,v,g) \ - if (strcmp((v), (g))) { ne++; cerr << "s[" << t << "] = \"" << (v) << "\"" \ - << endl; } -#define CHECK_STRING2(t,m,v,g) \ - if (strcmp((v), (g))) { \ - ne++; cerr << "s[" << t << ", " << m << "] = \"" << (v) << "\"" << endl; } + CheckT<const char*>('s', -1, t, -1, v, g, (strcmp((v), (g)))) +#define CHECK_STRING2(t,n,v,g) \ + CheckT<const char*>('s', -1, t, n, v, g, (strcmp((v), (g)))) + #define CHECK_STRING_ARRAY(t,m,v,g) \ - for (i = 0; i < m; ++i) if (strcmp((v), (g))) { \ - ne++; cerr << "s(" << i << ")[" << t << "] = \"" << (v) << "\"" << endl; } + for (i = 0; i < m; ++i) \ +CheckT<const char*>('s', i, t, -1, v, g, (strcmp((v), (g)))) #define CHECK_EOSTRING(t,v,g) \ - if (strcmp((v) + strlen(v) - strlen(g), (g))) { ne++; cerr << "s[" << t << "] = \"" << (v) << \ - "\", expected ...\"" << g << "\"" << endl; } + CheckT<const char*>('S', -1, t, -1, v, g, \ + (strcmp((v) + strlen(v) - strlen(g), (g)))) -#define CHECK_COMPLEX2(t,m,v,g) \ - if (abs((v) - (g)) > 1e-10) { \ - ne++; cerr << "c[" << t << ", " << m << "] = " << (v).real() << ";" \ - << (v).imag() << endl; } +#define CHECK_COMPLEX2(t,n,v,g) \ + CheckFloat<complex<double> >('c', -1, t, n, v, g) #define CHECK_COMPLEX_ARRAY(t,m,v,g) \ - for (i = 0; i < m; ++i) if (abs((v) - (g)) > 1e-10) { \ - ne++; cerr << "c(" << i << ")[" << t << "] = " << v.real() \ - << ";" << v.imag() << endl; } + for (i = 0; i < m; ++i) CheckFloat<complex<double> >('c', i, t, -1, v, g) int main(void) { @@ -144,7 +154,7 @@ unsigned char c[8]; unsigned char data_data[80]; signed char sc; - int m, n, i, e, ne = 0; + int m, n, i; float fl; double dp, p[6], q[6]; const double *qp; @@ -1234,9 +1244,9 @@ // 156: Invalid Dirfile check Dirfile *id = new Dirfile(); - CHECK_ERROR2b(id,156,1,GD_E_OK); + CheckError(id,156,1,GD_E_OK); id->NFragments(); - CHECK_ERROR2b(id,156,2,GD_E_BAD_DIRFILE); + CheckError(id,156,2,GD_E_BAD_DIRFILE); delete id; // 157: Dirfile::Standards check @@ -1643,6 +1653,10 @@ d->RawClose("data"); CHECK_OK(233); + // 234: gd_desync check + n = d->DeSync(); + CHECK_OK(234); + CHECK_INT(234, n, 0); @@ -1650,6 +1664,7 @@ + // =================================================================== d->Discard(); delete d; Modified: trunk/getdata/bindings/f77/fgetdata.c =================================================================== --- trunk/getdata/bindings/f77/fgetdata.c 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/f77/fgetdata.c 2012-03-15 01:09:21 UTC (rev 675) @@ -3808,3 +3808,13 @@ dreturn("%i", *toke_l); } + +void F77_FUNC(gddsyn, GDDSYN) (int *desync, const int *dirfile, + const int *flags) +{ + dtrace("%p, %i, %i", desync, *dirfile, *flags); + + *desync = gd_desync(_GDF_GetDirfile(*dirfile), *flags); + + dreturn("%i", *desync); +} Modified: trunk/getdata/bindings/f77/fgetdata.h =================================================================== --- trunk/getdata/bindings/f77/fgetdata.h 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/f77/fgetdata.h 2012-03-15 01:09:21 UTC (rev 675) @@ -671,6 +671,9 @@ const int *fragment_index); void F77_FUNC(gdnocb, GDNOCB) (const int* dirfile); + +void F77_FUNC(gddsyn, GDDSYN) (int *desync, const int *dirfile, + const int *flags); #ifdef __cplusplus } #endif Modified: trunk/getdata/bindings/f77/getdata.f.in =================================================================== --- trunk/getdata/bindings/f77/getdata.f.in 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/f77/getdata.f.in 2012-03-15 01:09:21 UTC (rev 675) @@ -137,6 +137,8 @@ EXTERNAL GDDELE C Corresponding to gd_discard(3) EXTERNAL GDDSCD +C Corresponding to gd_desync(3) + EXTERNAL GDDSYN C Corresponding to gd_error_count(3) EXTERNAL GDECNT C Corresponding to gd_entry_type(3) Modified: trunk/getdata/bindings/f77/getdata.f90.in =================================================================== --- trunk/getdata/bindings/f77/getdata.f90.in 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/f77/getdata.f90.in 2012-03-15 01:09:21 UTC (rev 675) @@ -2789,4 +2789,11 @@ call gdtoke(token, l, dirfile, TRIM(string), LEN_TRIM(string), n) end subroutine +function fgd_desync (dirfile, flags) + integer :: fgd_desync + integer, intent(in) :: dirfile, flags + + call gddsyn(fgd_desync, dirfile, flags) +end function + end module Modified: trunk/getdata/bindings/f77/test/big_test.f =================================================================== --- trunk/getdata/bindings/f77/test/big_test.f 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/f77/test/big_test.f 2012-03-15 01:09:21 UTC (rev 675) @@ -2074,6 +2074,10 @@ CALL GDRCLO(d, 'data', 4) CALL CHKEOK(ne, 233, d) +C 234: GDDSYN check + CALL GDDSYN(n, d, 0) + CALL CHKEOK(ne, 234, d) + CALL CHKINT(ne, 234, n, 0) @@ -2082,6 +2086,7 @@ + C =============================================================== C Cleanup CALL GDDSCD(d) Modified: trunk/getdata/bindings/f77/test/big_test95.f90 =================================================================== --- trunk/getdata/bindings/f77/test/big_test95.f90 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/f77/test/big_test95.f90 2012-03-15 01:09:21 UTC (rev 675) @@ -2508,6 +2508,11 @@ call fgd_raw_close(d, 'data') call check_ok(ne, 233, d) +! 234: fgd_desync check + n = fgd_desync(d, 0) + call check_ok(ne, 234, d) + call check_int(ne, 234, n, 0) + Modified: trunk/getdata/bindings/idl/getdata.c =================================================================== --- trunk/getdata/bindings/idl/getdata.c 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/idl/getdata.c 2012-03-15 01:09:21 UTC (rev 675) @@ -5590,9 +5590,49 @@ return r; } +/* @@DLM: F gdidl_desync GD_DESYNC 1 1 KEYWORDS */ +IDL_VPTR gdidl_desync(int argc, IDL_VPTR argv[], char *argk) +{ + dtraceidl(); + int ret; + typedef struct { + IDL_KW_RESULT_FIRST_FIELD; + GDIDL_KW_RESULT_ERROR; + int pathcheck; + int reopen; + } KW_RESULT; + KW_RESULT kw; + GDIDL_KW_INIT_ERROR; + kw.pathcheck = kw.reopen = 0; + static IDL_KW_PAR kw_pars[] = { + GDIDL_KW_PAR_ERROR, + GDIDL_KW_PAR_ESTRING, + { "PATHCHECK", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(pathcheck) }, + { "REOPEN", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(reopen) }, + { NULL } + }; + + IDL_KWProcessByOffset(argc, argv, argk, kw_pars, NULL, 1, &kw); + + DIRFILE *D = gdidl_get_dirfile(IDL_LongScalar(argv[0])); + + ret = gd_desync(D, (kw.pathcheck ? GD_DESYNC_PATHCHECK : 0) | + (kw.reopen ? GD_DESYNC_REOPEN : 0)); + + GDIDL_SET_ERROR(D); + + IDL_KW_FREE; + + + IDL_VPTR r = IDL_GettmpInt(ret); + dreturn("%p", r); + return r; +} + + /**** Module initialisation ****/ /* These are defined in the automatically generated sublist.c */ Modified: trunk/getdata/bindings/idl/test/big_test.pro =================================================================== --- trunk/getdata/bindings/idl/test/big_test.pro 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/idl/test/big_test.pro 2012-03-15 01:09:21 UTC (rev 675) @@ -1,3 +1,5 @@ +; vim: ft=idlang +; ; Copyright (C) 2009-2012 D. V. Wiebe ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1345,6 +1347,11 @@ gd_flush, d, field_code='data', /nosync nume += check_ok(233, d) +; 234: gd_desync check +n = gd_desync(d) +nume += check_ok(234, d) +nume += check_simple(234, n, 0) + Modified: trunk/getdata/bindings/make_parameters.c =================================================================== --- trunk/getdata/bindings/make_parameters.c 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/make_parameters.c 2012-03-15 01:09:21 UTC (rev 675) @@ -43,6 +43,7 @@ * 10: gd_seek whence values * 11: gd_seek flags (not in IDL) * 12: window operations + * 13: desynced flags (not in IDL) * 99: miscellaneous constants */ #define CONSTANT(s,f,t) { "GD_" #s, #s, f, GD_ ## s, t } @@ -214,6 +215,9 @@ CONSTANT(WINDOP_SET, "GDW_ST", 12), CONSTANT(WINDOP_CLR, "GDW_CL", 12), + CONSTANT(DESYNC_PATHCHECK, "GDDS_P", 13), + CONSTANT(DESYNC_REOPEN, "GDDS_O", 13), + CONSTANT(ALL_FRAGMENTS, "GD_ALL", 99), CONSTANT(COUNT_MAX, "GD_CMX", 99), CONSTANT(DIRFILE_STANDARDS_VERSION, "GD_DSV", 99), @@ -325,6 +329,13 @@ parameter(constant_list[j].lname, constant_list[j].fname, constant_list[j].value, i); + printf("\\\n%c Desync flags\\\n", c); + + for (j = 0; constant_list[j].lname != NULL; ++j) + if (constant_list[j].type == 13) + 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) @@ -376,7 +387,7 @@ for (i = 0; constant_list[i].lname != NULL; ++i) if ((constant_list[i].type != 1) && (constant_list[i].type != 5) && (constant_list[i].type != 7) && (constant_list[i].type != 8) && - (constant_list[i].type != 11)) + (constant_list[i].type != 11) && (constant_list[i].type != 13)) { printf("{ \"%s\", 0, (void*)IDL_TYP_%s }, ", constant_list[i].sname, (constant_list[i].type == 2) ? "LONG" : "INT"); @@ -397,7 +408,7 @@ for (n = i = 0; constant_list[i].lname != NULL; ++i) if ((constant_list[i].type != 1) && (constant_list[i].type != 5) && (constant_list[i].type != 7) && (constant_list[i].type != 8) && - (constant_list[i].type != 11)) + (constant_list[i].type != 11) && (constant_list[i].type != 13)) { printf("*(IDL_%s*)(data + IDL_StructTagInfoByIndex(gdidl_const_def, %i, " "IDL_MSG_LONGJMP, NULL)) = %li;\n", (constant_list[i].type == 2) ? Modified: trunk/getdata/bindings/perl/Makefile.am =================================================================== --- trunk/getdata/bindings/perl/Makefile.am 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/perl/Makefile.am 2012-03-15 01:09:21 UTC (rev 675) @@ -58,6 +58,7 @@ blib/arch/auto/GetData/GetData.bs: Build $(PERL) $< build + touch $@ .PRECIOUS: Build Build: Build.PL GetData.pm lib/GetData.xs lib/simple_funcs.xs lib/typemap Modified: trunk/getdata/bindings/perl/simple_funcs.xsin =================================================================== --- trunk/getdata/bindings/perl/simple_funcs.xsin 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/perl/simple_funcs.xsin 2012-03-15 01:09:21 UTC (rev 675) @@ -153,3 +153,4 @@ const char *in_field, const char *count_field, gd_count_t count_val, gd_count_t count_max) int raw_close(DIRFILE *dirfile, const char *field_code) +int desync(DIRFILE *dirfile, unsigned int flags) Modified: trunk/getdata/bindings/perl/t/big_test.t =================================================================== --- trunk/getdata/bindings/perl/t/big_test.t 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/perl/t/big_test.t 2012-03-15 01:09:21 UTC (rev 675) @@ -22,7 +22,7 @@ use GetData; use Math::Complex; use strict; -use Test::More tests => 1266; +use Test::More tests => 1268; my $ne = 0; my ($s, @a, %h); @@ -1665,6 +1665,10 @@ $s = $_->raw_close('data'); CheckOK(233); +# 234: gd_desync +$s = $_->desync(0); +CheckOK(234); +CheckNum(234, $s, 0); @@ -1673,5 +1677,6 @@ + $d = $_ = undef; system "rm -rf dirfile"; Modified: trunk/getdata/bindings/python/pydirfile.c =================================================================== --- trunk/getdata/bindings/python/pydirfile.c 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/python/pydirfile.c 2012-03-15 01:09:21 UTC (rev 675) @@ -2457,6 +2457,29 @@ return pyobj; } +static PyObject *gdpy_dirfile_desync(struct gdpy_dirfile_t *self, + void *args, void *keys) +{ + dtrace("%p, %p, %p", self, args, keys); + + int ret; + char *keywords[] = { "flags", NULL }; + unsigned int flags = 0; + + if (!PyArg_ParseTupleAndKeywords(args, keys, "|I:pygetdata.dirfile.desync", + keywords, &flags)) + { + dreturn("%p", NULL); + return NULL; + } + + ret = gd_desync(self->D, flags); + + PyObject* pyobj = PyInt_FromLong((long)ret); + dreturn("%p", pyobj); + return pyobj; +} + static PyGetSetDef gdpy_dirfile_getset[] = { { "error", (getter)gdpy_dirfile_geterror, NULL, "The numerical error code encountered by the last call to the GetData\n" @@ -2985,7 +3008,6 @@ METH_VARARGS | METH_KEYWORDS, "raw_close([field_code])\n\n" "Close any open raw data files associated with field_code, freeing\n" - /* ------- handy ruler ---------------------------------------------| */ "resources which may be used for other purposes. If field_code is\n" "omitted, all open raw data files are closed. See gd_raw_close(3)." }, @@ -3043,6 +3065,14 @@ "provided. Note: an error will result if the string being parsed\n" "goes out of scope. See gd_tokenise(3)." }, + {"desync", (PyCFunction)gdpy_dirfile_desync, METH_VARARGS | METH_KEYWORDS, + "desync([flags])\n\n" + "Returns non-zero if the metadata on disk has changed since the\n" + "dirfile was opened, and optionally automatically reloads it. If\n" + "given, flags should be a bitwise or'd collection of the\n" + "pygetdata.DESYNC_... flags. See gd_desync(3)." + /* ------- handy ruler ---------------------------------------------| */ + }, { NULL, NULL, 0, NULL } }; Modified: trunk/getdata/bindings/python/test/big_test.py =================================================================== --- trunk/getdata/bindings/python/test/big_test.py 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/bindings/python/test/big_test.py 2012-03-15 01:09:21 UTC (rev 675) @@ -1922,6 +1922,12 @@ except: CheckOK(233) +try: + n = d.desync() +except: + CheckOK(234) +CheckSimple(234, n, 0) + Modified: trunk/getdata/configure.ac =================================================================== --- trunk/getdata/configure.ac 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/configure.ac 2012-03-15 01:09:21 UTC (rev 675) @@ -545,9 +545,9 @@ echo "*** Looking for additional header files" echo AC_CHECK_HEADERS([asm/unaligned.h Availability.h byteswap.h direct.h fcntl.h \ - inttypes.h io.h libgen.h libkern/OSByteOrder.h stdint.h \ - sys/endian.h sys/file.h sys/param.h sys/stat.h sys/types.h \ - unistd.h]) + inttypes.h io.h libgen.h libkern/OSByteOrder.h stddef.h \ + stdint.h sys/endian.h sys/file.h sys/param.h sys/stat.h \ + sys/types.h unistd.h]) if test "x$disable_c99" = "xno"; then AC_CHECK_HEADERS([complex.h]) fi @@ -693,13 +693,13 @@ echo echo "*** Looking for additional library functions" echo -AC_CHECK_FUNCS([_chsize _chsize_s _commit fchmod _fdopen fdopendir fseeko \ - fseeko64 _fstat fstat64 _fstat64 fstatat fstatat64 fsync \ - ftello ftello64 ftruncate ftruncate64 getcwd _getcwd getdelim \ - gmtime_r lseek64 _lseeki64 lstat lstat64 _mkdir nan _open \ - openat _read readlink renameat _rmdir snprintf _snprintf \ - stat64 _stat64 _strtoi64 strtoll _strtoui64 strtoull _unlink \ - unlinkat _write]) +AC_CHECK_FUNCS([_chsize _chsize_s _commit fchmod _fdopen fdopendir fpathconf \ + fseeko fseeko64 _fstat fstat64 _fstat64 fstatat fstatat64 \ + fsync ftello ftello64 ftruncate ftruncate64 getcwd _getcwd \ + getdelim gmtime_r lseek64 _lseeki64 lstat lstat64 _mkdir nan \ + _open openat pathconf _read readdir_r readlink renameat _rmdir \ + snprintf _snprintf stat64 _stat64 _strtoi64 strtoll _strtoui64 \ + strtoull _unlink unlinkat _write]) if test "x$disable_c99" = "xno"; then AC_CHECK_FUNCS([cabs]) fi @@ -745,6 +745,13 @@ #endif ]) +AC_CHECK_DECLS([offsetof],,, + [ +#ifdef HAVE_STDDEF_H +#include <stddef.h> +#endif +]) + AC_CHECK_DECLS([get_unaligned, put_unaligned],,, [ #ifdef HAVE_ASM_UNALIGNED_H Modified: trunk/getdata/doc/list.tests =================================================================== --- trunk/getdata/doc/list.tests 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/doc/list.tests 2012-03-15 01:09:21 UTC (rev 675) @@ -245,3 +245,4 @@ 231 F9CIpP gd_alter_mplex 232 F9CIpP gd_tokenise 233 F9CIpP gd_raw_close +234 F9CIpP gd_desync Modified: trunk/getdata/src/close.c =================================================================== --- trunk/getdata/src/close.c 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/src/close.c 2012-03-15 01:09:21 UTC (rev 675) @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2011 D. V. Wiebe +/* Copyright (C) 2008-2012 D. V. Wiebe * *************************************************************************** * @@ -22,12 +22,12 @@ /* _GD_FreeD: free the DIRFILE and its subordinates */ -static void _GD_FreeD(DIRFILE* D) +static void _GD_FreeD(DIRFILE *D, int keep_dirfile) { unsigned int i; int j; - dtrace("%p", D); + dtrace("%p, %i", D, keep_dirfile); for (i = 0; i < D->n_entries; ++i) _GD_FreeE(D, D->entry[i], 1); @@ -39,6 +39,7 @@ free(D->fragment[j].bname); free(D->fragment[j].cname); free(D->fragment[j].ename); + free(D->fragment[j].sname); free(D->fragment[j].ref_name); } @@ -61,16 +62,18 @@ for (i = 0; i < D->ndir; ++i) free(D->dir[i].path); free(D->dir); - free(D); + if (!keep_dirfile) + free(D); + dreturnvoid(); } -static int _GD_ShutdownDirfile(DIRFILE* D, int flush_meta) +int _GD_ShutdownDirfile(DIRFILE* D, int flush_meta, int keep_dirfile) { unsigned int i; - dtrace("%p, %i", D, flush_meta); + dtrace("%p, %i, %i", D, flush_meta, keep_dirfile); if (D == NULL) { dreturn("%i", 0); @@ -98,7 +101,7 @@ close(D->dir[i].fd); #endif - _GD_FreeD(D); + _GD_FreeD(D, keep_dirfile); dreturn("%i", 0); return 0; @@ -110,7 +113,7 @@ dtrace("%p", D); - ret = _GD_ShutdownDirfile(D, 1); + ret = _GD_ShutdownDirfile(D, 1, 0); dreturn("%i", ret); return ret; @@ -122,7 +125,7 @@ dtrace("%p", D); - ret = _GD_ShutdownDirfile(D, 0); + ret = _GD_ShutdownDirfile(D, 0, 0); dreturn("%i", ret); return ret; Modified: trunk/getdata/src/compat.c =================================================================== --- trunk/getdata/src/compat.c 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/src/compat.c 2012-03-15 01:09:21 UTC (rev 675) @@ -280,3 +280,30 @@ return count; } #endif + +/* emulate readdir_r(3) with non-threadsafe readdir(3) */ +#ifndef HAVE_READDIR_R +int gd_readdir(DIR *dirp, struct dirent *entry, struct dirent **result) +{ + struct dirent *local_entry; + + dtrace("%p, %p, %p", dirp, entry, result); + + errno = 0; + local_entry = readdir(dirp); + if (local_entry == NULL) { + *result = NULL; + if (errno) { + dreturn("%i", errno); + return errno; + } + dreturn("%i", 0); + return 0; + } + + *result = entry; + memcpy(entry, local_entry, sizeof(struct dirent)); + dreturn("%i", 0); + return 0; +} +#endif Modified: trunk/getdata/src/flush.c =================================================================== --- trunk/getdata/src/flush.c 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/src/flush.c 2012-03-15 01:09:21 UTC (rev 675) @@ -573,8 +573,8 @@ unsigned int u; #ifdef HAVE_FCHMOD mode_t mode; - struct stat stat_buf; #endif + struct stat stat_buf; time_t t; int dirfd = D->fragment[i].dirfd; @@ -760,23 +760,21 @@ /* If no error was encountered, move the temporary file over the * old format file, otherwise abort */ - ptr = _GD_Strdup(D, D->fragment[i].cname); - if (ptr == NULL) { - dreturnvoid(); - return; - } /* Only assume we've synced the file if the rename succeeds */ if (D->error != GD_E_OK) gd_UnlinkAt(D, dirfd, temp_file, 0); - else if (gd_RenameAt(D, dirfd, temp_file, dirfd, basename(ptr))) { + 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_UnlinkAt(D, dirfd, temp_file, 0); } else D->fragment[i].modified = 0; - free(ptr); + /* update mtime, if successful */ + if (!D->error && gd_StatAt(D, dirfd, D->fragment[i].bname, &stat_buf, 0) == 0) + D->fragment[i].mtime = stat_buf.st_mtime; + dreturnvoid(); } Modified: trunk/getdata/src/fragment.c =================================================================== --- trunk/getdata/src/fragment.c 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/src/fragment.c 2012-03-15 01:09:21 UTC (rev 675) @@ -300,3 +300,99 @@ dreturn("%i", D->fragment[fragment_index].parent); return D->fragment[fragment_index].parent; } + +/* returns non-zero if the metadata has changed on disk since the dirfile was + * opened and, optionally, re-opens the dirfile. + */ +int gd_desync(DIRFILE *D, unsigned int flags) +{ + int changed = 0, i; + struct stat statbuf; + + dtrace("%p, 0x%x", D, flags); + + /* if we can't open directories, we're stuck with the full path method */ +#ifdef GD_NO_DIR_OPEN + flags |= GD_DESYNC_PATHCECK; +#endif + + _GD_ClearError(D); + + if (D->flags & GD_INVALID) { + _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); + dreturn("%i", 0); + return 0; + } + + for (i = 0; i < D->n_fragment; ++i) { + if (flags & GD_DESYNC_PATHCHECK) { + /* stat the file via it's path relative to the original filedir */ + char *buffer; + if (D->fragment[i].sname) { + buffer = _GD_Malloc(D, strlen(D->name) + + strlen(D->fragment[i].bname) + strlen(D->fragment[i].sname) + 3); + if (buffer == NULL) { + dreturn("%i", -1); + return -1; + } + sprintf(buffer, "%s%c%s%c%s", D->name, GD_DIRSEP, D->fragment[i].sname, + GD_DIRSEP, D->fragment[i].bname); + } else { + buffer = _GD_Malloc(D, strlen(D->name) + strlen(D->fragment[i].bname) + + 2); + if (buffer == NULL) { + dreturn("%i", -1); + return -1; + } + sprintf(buffer, "%s%c%s", D->name, GD_DIRSEP, D->fragment[i].bname); + } + if (stat(buffer, &statbuf)) { + _GD_SetError(D, GD_E_RAW_IO, 0, buffer, errno, NULL); + free(buffer); + dreturn("%i", -1); + return -1; + } + free(buffer); + } else + /* stat the file based on it's name and our cached dirfd */ + if (gd_StatAt(D, D->fragment[i].dirfd, D->fragment[i].bname, &statbuf, 0)) + { + _GD_SetError(D, GD_E_RAW_IO, 0, D->fragment[i].cname, errno, NULL); + dreturn("%i", -1); + return -1; + } + + if (statbuf.st_mtime != D->fragment[i].mtime) { + changed = 1; + break; + } + } + + if (changed && flags & GD_DESYNC_REOPEN) { + /* reopening is easy: just delete everything and start again. In the + * non-PATHCHECK case, we also have to cache the dirfd to the root directory + */ + + /* remember how we were called */ + char *name = D->name; + gd_parser_callback_t sehandler = D->sehandler; + void *extra = D->sehandler_extra; + unsigned long int flags = D->open_flags; + + int dirfd = (flags & GD_DESYNC_PATHCHECK) ? -1 : D->fragment[0].dirfd; + + D->name = NULL; /* so FreeD doesn't delete it */ + if (_GD_ShutdownDirfile(D, 0, 1)) { + D->name = name; + dreturn("%i", -1); + return -1; + } + _GD_Open(D, dirfd, name, flags, sehandler, extra); + + if (D->error) + changed = -1; + } + + dreturn("%i", changed); + return changed; +} Modified: trunk/getdata/src/getdata.h.in =================================================================== --- trunk/getdata/src/getdata.h.in 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/src/getdata.h.in 2012-03-15 01:09:21 UTC (rev 675) @@ -471,6 +471,10 @@ #define GD_SEEK_END 0x2 #define GD_SEEK_WRITE 0x4 +/* desync flags */ +#define GD_DESYNC_PATHCHECK 0x1 +#define GD_DESYNC_REOPEN 0x2 + extern int gd_add_alias(DIRFILE *dirfile, const char *alias_name, const char *target_code, int fragment_index) gd_nothrow gd_nonnull ((1,2,3)); @@ -918,6 +922,8 @@ extern int gd_delete(DIRFILE *dirfile, const char *field_code, unsigned int flags) gd_nonnull ((1,2)); +extern int gd_desync(DIRFILE *dirfile, unsigned int flags); + extern int gd_discard(DIRFILE *dirfile); extern int gd_flush(DIRFILE *dirfile, const char *field_code) gd_nonnull ((1)); Modified: trunk/getdata/src/include.c =================================================================== --- trunk/getdata/src/include.c 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/src/include.c 2012-03-15 01:09:21 UTC (rev 675) @@ -90,10 +90,12 @@ int old_standards = *standards; int old_pedantic = *flags & GD_PEDANTIC; int dirfd = -1; - char *temp_buf1, *temp_buf2; + char *temp_buf1, *temp_buf2, *sname; char *base, *prefix = NULL, *suffix = NULL; void *ptr = NULL; FILE* new_fp = NULL; + time_t mtime = 0; + struct stat statbuf; dtrace("%p, \"%s\", \"%s\", %p, %i, %i, \"%s\", \"%s\", %p, %p, %i", D, ename, format_file, ref_name, linenum, me, prefix_in, suffix_in, standards, @@ -116,6 +118,7 @@ return -1; } + /* isolate filename */ temp_buf2 = _GD_Strdup(D, ename); if (temp_buf2 == NULL) { free(prefix); @@ -133,13 +136,35 @@ dreturn("%i", -1); return -1; } + free(temp_buf2); + /* isolate relative path */ + temp_buf2 = _GD_Strdup(D, ename); + if (temp_buf2 == NULL) { + free(base); + free(prefix); + free(suffix); + D->recurse_level--; + dreturn("%i", -1); + return -1; + } + sname = _GD_Strdup(D, dirname(temp_buf2)); + if (base == NULL) { + free(temp_buf2); + free(base); + free(prefix); + free(suffix); + D->recurse_level--; + dreturn("%i", -1); + return -1; + } + free(temp_buf2); + /* Open the containing directory */ dirfd = _GD_GrabDir(D, D->fragment[me].dirfd, ename); if (dirfd == -1 && D->error == GD_E_OK) _GD_SetError(D, GD_E_OPEN_FRAGMENT, errno, format_file, linenum, ename); if (D->error) { - free(temp_buf2); free(prefix); free(suffix); D->recurse_level--; @@ -148,7 +173,6 @@ } temp_buf1 = _GD_MakeFullPath(D, dirfd, base, 1); - free(temp_buf2); if (temp_buf1 == NULL) { _GD_ReleaseDir(D, dirfd); free(prefix); @@ -190,11 +214,16 @@ return -1; } + /* fstat the file and record the mtime */ + if (fstat(i, &statbuf) == 0) + mtime = statbuf.st_mtime; + /* If we got here, we managed to open the included file; parse it */ ptr = _GD_Realloc(D, D->fragment, (++D->n_fragment) * sizeof(struct gd_fragment_t)); if (ptr == NULL) { D->n_fragment--; + fclose(new_fp); free(prefix); free(suffix); free(base); @@ -225,20 +254,40 @@ D->fragment[D->n_fragment - 1].protection = GD_PROTECT_NONE; D->fragment[D->n_fragment - 1].prefix = prefix; D->fragment[D->n_fragment - 1].suffix = suffix; + D->fragment[D->n_fragment - 1].mtime = mtime; D->fragment[D->n_fragment - 1].vers = (*flags & GD_PEDANTIC) ? 1ULL << *standards : 0; - if (D->fragment[D->n_fragment - 1].ename == NULL) { + /* compute the (relative) subdirectory name */ + if (sname[0] == '.' && sname[1] == '\0') { + /* dirname is the same as the parent fragment's */ + D->fragment[D->n_fragment - 1].sname = (D->fragment[me].sname) ? + _GD_Strdup(D, D->fragment[me].sname) : NULL; + free(sname); + } else if (D->fragment[me].sname && _GD_AbsPath(sname)) { + /* have both a relative dirname and the parent's sname; squish them + * together */ + D->fragment[D->n_fragment - 1].sname = _GD_Malloc(D, strlen(sname) + + strlen(D->fragment[me].sname) + 2); + if (D->fragment[D->n_fragment - 1].sname) + sprintf(D->fragment[D->n_fragment - 1].sname, "%s%c%s", + D->fragment[me].sname, GD_DIRSEP, sname); + free(sname); + } else + /* just save the sname */ + D->fragment[D->n_fragment - 1].sname = sname; + + /* catch alloc errors */ + if (D->error) { D->n_fragment--; - free(base); + fclose(new_fp); + free(prefix); + free(suffix); D->recurse_level--; dreturn("%i", -1); return -1; } - /* extract the subdirectory name */ - D->fragment[D->n_fragment - 1].sname = _GD_DirName(D, dirfd); - *ref_name = _GD_ParseFragment(new_fp, D, D->n_fragment - 1, standards, flags, resolve); @@ -269,13 +318,6 @@ dtrace("%p, \"%s\", %i, \"%s\", \"%s\", 0x%lX", D, file, fragment_index, prefix, suffix, flags); - if (~D->flags & GD_HAVE_VERSION) - _GD_FindVersion(D); - - /* only set if the dirfile conforms to some standard */ - if (D->av) - standards = D->standards; - _GD_ClearError(D); if (D->flags & GD_INVALID) {/* don't crash */ @@ -305,10 +347,17 @@ return -1; } + if (~D->flags & GD_HAVE_VERSION) + _GD_FindVersion(D); + + /* only set if the dirfile conforms to some standard */ + if (D->av) + standards = D->standards; + /* if the caller specified no encoding scheme, but we were asked to create * the fragment, inherit it from the parent */ if ((flags & (GD_ENCODING | GD_CREAT)) == GD_CREAT) - flags |= D->flags & GD_ENCODING; + flags |= D->fragment[fragment_index].encoding; new_fragment = _GD_Include(D, file, "dirfile_include()", 0, &ref_name, fragment_index, prefix, suffix, &standards, &flags, 1); @@ -364,7 +413,7 @@ dtrace("%p, \"%s\", %i, 0x%lX", D, file, fragment_index, flags); new_fragment = gd_include_affix(D, file, fragment_index, NULL, NULL, flags); - + dreturn("%i", new_fragment); return new_fragment; } Modified: trunk/getdata/src/internal.h =================================================================== --- trunk/getdata/src/internal.h 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/src/internal.h 2012-03-15 01:09:21 UTC (rev 675) @@ -79,6 +79,9 @@ #ifdef HAVE_LIBGEN_H #include <libgen.h> #endif +#ifdef HAVE_STDDEF_H +#include <stddef.h> +#endif #ifdef HAVE_STDINT_H #include <stdint.h> #endif @@ -348,6 +351,16 @@ # endif #endif +#if !defined(HAVE_DECL_OFFSETOF) || ! HAVE_DECL_OFFSETOF +#define offsetof(t,m) ((size_t)((char*)&(((t)*)0)->(m) - (char*)0)) +#endif + +#ifdef HAVE_READDIR_R +# define gd_readdir readdir_r +#else +int gd_readdir(DIR *dirp, struct dirent *entry, struct dirent **result); +#endif + #ifdef HAVE__STRTOI64 # define gd_strtoll _strtoi64 #elif defined(HAVE_STRTOLL) @@ -836,7 +849,7 @@ /* Canonical name (full path) */ char* cname; /* Subdirectory name */ - const char* sname; + char* sname; /* basename */ char *bname; /* External name (the one that appears in the format file) */ @@ -845,6 +858,7 @@ int modified; int parent; int dirfd; + time_t mtime; unsigned long int encoding; unsigned long int byte_sex; int protection; @@ -894,6 +908,7 @@ /* global data */ unsigned long int flags; + unsigned long int open_flags; /* the original flags (used in gd_desynced) */ uint64_t av; int standards; int n_error; @@ -915,7 +930,7 @@ /* the reference field */ gd_entry_t* reference_field; - /* directory name */ + /* directory name (this is just whatever was passed to gd_open() */ char* name; /* directory list */ @@ -1049,6 +1064,8 @@ char *_GD_MungeFromFrag(DIRFILE *restrict, const gd_entry_t *restrict, int, const char *restrict, int *restrict); gd_type_t _GD_NativeType(DIRFILE *restrict, gd_entry_t *restrict, int); +DIRFILE *_GD_Open(DIRFILE*, int, const char*, unsigned long, + gd_parser_callback_t, void*); gd_entry_t *_GD_ParseFieldSpec(DIRFILE *restrict, int, char**, const gd_entry_t *restrict, const char *restrict, int, int, int, int, unsigned long, int, char**, const char*); @@ -1062,6 +1079,7 @@ void _GD_SetError(DIRFILE*, int, int, const char*, int, const char*); int _GD_SetTablePath(DIRFILE *restrict, const gd_entry_t *restrict, struct _gd_private_entry *restrict); +int _GD_ShutdownDirfile(DIRFILE*, int, int); int _GD_StrCmpNull(const char *restrict, const char *restrict); char *_GD_Strdup(DIRFILE *restrict, const char *restrict); int _GD_Supports(DIRFILE *, const gd_entry_t*, unsigned int funcs); Modified: trunk/getdata/src/open.c =================================================================== --- trunk/getdata/src/open.c 2012-03-14 22:22:55 UTC (rev 674) +++ trunk/getdata/src/open.c 2012-03-15 01:09:21 UTC (rev 675) @@ -26,9 +26,11 @@ { int format_trunc = 0; DIR* dir; - struct dirent* lamb; + struct dirent *lamb, *result; struct stat statbuf; - int fd = dirfd; + int fd = dirfd, ret; + size_t dirent_len = offsetof(struct dirent, d_name); + size_t dirfile_len = strlen(dirfile); dtrace("%p, %i, \"%s\", %i", D, dirfd, dirfile, root); @@ -41,29 +43,58 @@ return -1; } dir = fdopendir(fd); + +#ifdef HAVE_FPATHCONF + dirent_len += fpathconf(fd, _PC_NAME_MAX) + 1; +#elif defined HAVE_PATHCONF + dirent_len += pathconf(dirfile, _PC_NAME_MAX) + 1; #else + dirent_len += FILENAME_MAX; +#endif + +#else dir = opendir(dirfile); + +#ifdef HAVE_PATHCONF + dirent_len += pathconf(dirfile, _PC_NAME_MAX) + 1; +#else + dirent_len += FILENAME_MAX; #endif +#endif + if (dir == NULL) { _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_DIR, dirfile, errno, NULL); dreturn("%i", -1); return -1; } - while ((lamb = readdir(dir)) != NULL) { - char *name = (char *)malloc(strlen(dirfile) + strlen(lamb->d_name) + 2); - sprintf(name, "%s%c%s", dirfile, GD_DIRSEP, lamb->d_name); - if (lamb->d_name[0] == '.' && lamb->d_name[1] == '\0') { - free(name); + if ((lamb = _GD_Malloc(D, dirent_len)) == NULL) { + closedir(dir); + dreturn("%i", -1); + return -1; + } + + ret = gd_readdir(dir, lamb, &result); + for (; result; ret = gd_readdir(dir, lamb, &result)) { + char *name; + if (lamb->d_name[0] == '.' && lamb->d_name[1] == '\0') continue; /* skip current dir */ - } else if (lamb->d_name[0] == '.' && lamb->d_name[1] == '.' && + else if (lamb->d_name[0] == '.' && lamb->d_name[1] == '.' && lamb->d_name[2] == '\0') { - free(name); continue; /* skip parent dir */ - } else { - if ( + } + + name = (char *)_GD_Malloc(D, dirfile_len + strlen(lamb->d_name) + 2); + if (name == NULL) { + free(lamb); + closedir(dir); + dreturn("%i", -1); + return -1; + } + sprintf(name, "%s%c%s", dirfile, GD_DIRSEP, lamb->d_name); + if ( #if defined(HAVE_FSTATAT) && !defined(GD_NO_DIR_OPEN) fstatat(dirfd, lamb->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) #elif HAVE_LSTAT @@ -71,14 +102,13 @@ #else stat(name, &statbuf) #endif - ) - { - _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_STAT, name, errno, NULL); - free(name); - closedir(dir); - dreturn("%i", -1); - return -1; - } + ) + { + _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_STAT, name, errno, NULL); + free(name); + closedir(dir); + dreturn("%i", -1); + return -1; } /* check file type */ @@ -100,6 +130,7 @@ ) { _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_UNLINK, name, errno, NULL); + free(lamb); free(name); closedir(dir); dreturn("%i", -1); @@ -122,6 +153,7 @@ ) < 0) { _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_STAT, name, errno, NULL); + free(lamb); closedir(dir); free(name); dreturn("%i", -1); @@ -140,6 +172,7 @@ #endif ) { _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_UNLINK, name, errno, NULL); + free(lamb); free(name); closedir(dir); dreturn("%i", -1); @@ -149,15 +182,23 @@ } free(name); } + free(lamb); closedir(dir); + + if (ret) { + _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_DIR, dirfile, errno, NULL); + dreturn("%i", -1); + return -1; + } + dreturn("%i", format_trunc); return format_trunc; } /* attempt to open or create a new dirfile - set error appropriately */ static FILE *_GD_CreateDirfile(DIRFILE *restrict D, int dirfd, int dir_error, - char *restrict dirfile) + char *restrict dirfile, time_t *mtime) { #ifndef GD_NO_DIR_OPEN struct stat statbuf; @@ -166,7 +207,7 @@ int format_error = 0, format_trunc = 0; FILE* fp = NULL; - dtrace("%p, %i, %i, \"%s\"", D, dirfd, dir_error, dirfile); + dtrace("%p, %i, %i, \"%s\", %p", D, dirfd, dir_error, dirfile, mtime); /* naively try to open the format file */ if (dirfd < 0) @@ -326,6 +367,10 @@ D->dir[0].path = dirfile; D->ndir = 1; + /* get the mtime */ + if (fstat(fd, &statbuf) == 0) + *mtime = statbuf.st_mtime; + dreturn("%p", fp); return fp; } @@ -357,35 +402,31 @@ return D; } -/* dirfile_cbopen: open (or, perhaps, create) and parse the specified dirfile +/* _GD_Open: open (or, perhaps, create) and parse the specified dirfile */ -DIRFILE* gd_cbopen(const char* filedir, unsigned long flags, - gd_parser_callback_t sehandler, void* extra) +DIRFILE *_GD_Open(DIRFILE *D, int dirfd, const char *filedir, + unsigned long flags, gd_parser_callback_t sehandler, void *extra) { FILE *fp; char *ref_name; char *dirfile; - DIRFILE* D; gd_entry_t* E; - int dirfd = -1, dirfd_error = 0; + int dirfd_error = 0; + time_t mtime = 0; #ifdef GD_NO_DIR_OPEN gd_stat64_t statbuf; #endif - dtrace("\"%s\", 0x%lX, %p, %p", filedir, (unsigned long)flags, sehandler, - extra); + dtrace("%p, %i, \"%s\", 0x%lX, %p, %p", D, dirfd, filedir, + (unsigned long)flags, sehandler, extra); -#ifdef GD_NO_DIR_OPEN - /* if we can't cache directory descriptors, we just have to remember paths, - * so get the current directory, so that we're protected against the caller - * using chdir. - */ - - /* canonicalise the path */ + /* canonicalise the path to protect us against the caller chdir'ing away */ dirfile = _GD_CanonicalPath(NULL, filedir); - /* that done, now stat the path to see if it exists (and is a directory) */ +#ifdef GD_NO_DIR_OPEN + /* if we can't cache directory descriptors, we just have to remember paths. + * so stat the path to see if it exists (and is a directory) */ if (dirfile) { if (gd_stat64(dirfile, &statbuf)) dirfd_error = errno; @@ -396,17 +437,14 @@ } #else /* quickly, before it goes away, grab the directory (if it exists) */ - dirfd = open(filedir, O_RDONLY); + if (dirfd == -1) + dirfd = open(dirfile, O_RDONLY); dirfd_error = errno; - /* There's a race condition here: someone might change a path element in - * filedir after we get dirfd but before we canonicalise the path. For that - * reason, anything requiring a full path must be treated with suspicion. - */ - dirfile = _GD_CanonicalPath(NULL, filedir); #endif _GD_InitialiseFramework(); - D = (DIRFILE *)malloc(sizeof(DIRFILE)); + if (D == NULL) + D = (DIRFILE *)malloc(sizeof(DIRFILE)); if (D == NULL) { free(dirfile); #ifndef GD_NO_DIR_OPEN @@ -417,6 +455,8 @@ } memset(D, 0, sizeof(DIRFILE)); + /* user specified flags (used if we're forced to re-open) */ + D->open_flags = flags; /* clear GD_PERMISSIVE if it was specified along with GD_PEDANTIC */ if (flags & GD_PERMISSIVE && flags & GD_PEDANTIC) flags &= ~GD_PERMISSIVE; @@ -470,7 +510,8 @@ D->entry[0]->e->calculated = 1; /* open the format file (or create it) */ - if ((fp = _GD_CreateDirfile(D, dirfd, dirfd_error, dirfile)) == NULL) { + if ((fp = _GD_CreateDirfile(D, dirfd, dirfd_error, dirfile, &mtime)) == NULL) + { #ifndef GD_NO_DIR_OPEN close(dirfd); #endif @@ -530,6 +571,7 @@ ) | (D->flags & GD_ARM_FLAG); D->fragment[0].ref_name = NULL; D->fragment[0].frame_offset = 0; + D->fragment[0].mtime = mtime; D->fragment[0].protection = GD_PROTECT_NONE; D->fragment[0].vers = (flags & GD_PEDANTIC) ? GD_DIRFILE_STANDARDS_VERSION : 0; @@ -578,13 +620,27 @@ return D; } +DIRFILE *gd_cbopen(const char* filedir, unsigned long flags, + gd_parser_callback_t sehandler, void* extra) +{ + DIRFILE *D; + + dtrace("\"%s\", 0x%lX, %p, %p", filedir, (unsigned long)flags, sehandler, + extra); + + D = _GD_Open(NULL, -1, filedir, flags, sehandler, extra); + + dreturn("%p", D); + return D; +} + DIRFILE* gd_open(const char* filedir, unsigned long flags) { DIRFILE *D; dtrace("\"%s\", 0x%lX", filedir, (unsigned long)flags); - D = gd_cbopen(filedir, flags, NULL, NULL); + D = _GD_Open(NULL, -1, filedir, flags, NULL, NULL); dreturn("%p", D); return D; Property changes on: trunk/getdata/test ___________________________________________________________________ Modified: svn:ignore - Makefile Makefile.in *.o *.odirfile *.swp *.exe .deps .libs add add_affix add_alias add_alias_meta add_bit add_bit_bitnum add_bit_bitsize add_bit_invalid add_bit_numbits 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_invalid add_lincom_nfields add_linterp add_linterp_invalid add_meta add_meta_alias add_mplex add_mplex_val add_multiply add_multiply_invalid add_phase add_phase_invalid add_polynom add_protect add_raw add_raw_include add_raw_invalid add_raw_spf add_raw_type add_rdonly add_recip add_resolv add_sbit add_scalar add_scalar_carray 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_list alias_list_alias alias_list_missing alias_num alias_num_alias alias_num_missing alias_target alias_target_alias alias_target_missing alter_bit_bitnum alter_bit_numbits alter_carray_len alter_carray_type alter_const alter_cpolynom alter_crecip alter_crecip89 alter_crecip_zero alter_divide alter_entry alter_entry_affix alter_entry_hidden alter_entry_recode alter_entry_scalar2a alter_entry_scalar2n alter_entry_scalar3 alter_entry_scalar4 alter_lincom_23 alter_lincom_32 alter_lincom_input alter_lincom_offset alter_lincom_slope alter_linterp alter_linterp_move alter_mplex alter_mspec alter_mspec_affix alter_multiply alter_phase alter_polynom_coeff alter_polynom_input alter_polynom_ord alter_raw_spf alter_raw_type alter_recip alter_recip_zero alter_spec alter_spec_affix alter_spec_meta alter_window ascii_add ascii_get ascii_get_get ascii_nframes ascii_put bof bof_lincom bof_phase bzip_get bzip_get_get bzip_move_from bzip_nframes bzip_put close close_bad close_discard close_null convert_complex128_complex64 convert_complex128_float64 convert_complex128_int64 convert_complex128_uint64 convert_complex64_complex128 convert_complex64_float64 convert_complex64_int64 convert_complex64_uint64 convert_float32_complex128 convert_float32_complex64 convert_float32_float64 convert_float32_int16 convert_float32_int32 convert_float32_int64 convert_float32_int8 convert_float32_uint16 convert_float32_uint32 convert_float32_uint64 convert_float32_uint8 convert_float64_complex128 convert_float64_complex64 convert_float64_float32 convert_float64_int16 convert_float64_int32 convert_float64_int64 convert_float64_int8 convert_float64_uint16 convert_float64_uint32 convert_float64_uint64 convert_float64_uint8 convert_int16_complex128 convert_int16_complex64 convert_int16_float32 convert_int16_float64 convert_int16_int32 convert_int16_int64 convert_int16_int8 convert_int16_uint16 convert_int16_uint32 convert_int16_uint64 convert_int16_uint8 convert_int32_complex128 convert_int32_complex64 convert_int32_float32 convert_int32_float64 convert_int32_int16 convert_int32_int64 convert_int32_int8 convert_int32_uint16 convert_int32_uint32 convert_int32_uint64 convert_int32_uint8 convert_int64_complex128 convert_int64_complex64 convert_int64_float32 convert_int64_float64 convert_int64_int16 convert_int64_int32 convert_int64_int8 convert_int64_uint16 convert_int64_uint32 convert_int64_uint64 convert_int64_uint8 convert_int8_complex128 convert_int8_complex64 convert_int8_float32 convert_int8_float64 convert_int8_int16 convert_int8_int32 convert_int8_int64 convert_int8_uint16 convert_int8_uint32 convert_int8_uint64 convert_int8_uint8 convert_uint16_complex128 convert_uint16_complex64 convert_uint16_float32 convert_uint16_float64 convert_uint16_int16 convert_uint16_int32 convert_uint16_int64 convert_uint16_int8 convert_uint16_uint32 convert_uint16_uint64 convert_uint16_uint8 convert_uint32_complex128 convert_uint32_complex64 convert_uint32_float32 convert_uint32_float64 convert_uint32_int16 convert_uint32_int32 convert_uint32_int64 convert_uint32_int8 convert_uint32_uint16 convert_uint32_uint64 convert_uint32_uint8 convert_uint64_complex128 convert_uint64_complex64 convert_uint64_float32 convert_uint64_float64 convert_uint64_int16 convert_uint64_int32 convert_uint64_int64 convert_uint64_int8 convert_uint64_uint16 convert_uint64_uint32 convert_uint64_uint8 convert_uint8_complex128 convert_uint8_complex64 convert_uint8_float32 convert_uint8_float64 convert_uint8_int16 convert_uint8_int32 convert_uint8_int64 convert_uint8_int8 convert_uint8_uint16 convert_uint8_uint32 convert_uint8_uint64 creat creat_excl creat_rdonly cvlist cvlist_array cvlist_array_hidden cvlist_array_meta cvlist_array_meta_hidden cvlist_hidden cvlist_invalid 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_derived del_derived_after del_derived_force del_meta del_meta_force dfes_bit dfes_divide dfes_lincom dfes_linterp dfes_multiply dfes_null dfes_phase dfes_raw dfes_recip dfes_zero encode_alter encode_get encode_move endian_alter endian_alter_sie endian_get endian_move entry_bad_code entry_bit entry_bit_scalar entry_divide entry_invalid entry_lincom entry_lincom_scalar entry_linterp entry_mplex entry_mplex_scalar entry_multiply entry_phase entry_phase_scalar entry_polynom entry_polynom_scalar entry_raw entry_raw_scalar entry_raw_scalar_code entry_raw_scalar_type entry_recip entry_scalar_repr entry_type entry_type_alias entry_window entry_window_scalar eof eof_index eof_lincom eof_phase error error_error error_num error_short file file_code file_type flist flist_hidden flist_invalid flist_meta flist_meta_hidden flist_meta_invalid flist_type flist_type_hidden flist_type_invalid flist_type_meta flist_type_meta_hidden flist_type_meta_invalid flush flush_all flush_bad_code flush_invalid flush_meta flush_spec foffs_alter foffs_get foffs_move fragment_affix fragment_affix_alter fragment_affix_alter2 fragment_affix_dup fragment_index fragment_index_alias fragment_name fragment_name_oor fragment_num fragment_parent get64 get_bad_code get_bit get_carray get_carray_len get_carray_slice get_char get_clincom get_complex128 get_complex64 get_const get_const_complex get_const_repr get_cpolynom get_divide get_endian16 get_endian32 get_endian64 get_endian8 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_int16 get_int32 get_int64 get_int8 get_invalid get_lincom1 get_lincom2 get_lincom3 get_lincom_noin get_lincom_non get_lincom_spf get_linterp get_linterp_noin get_linterp_notab get_linterp_sort get_mplex get_mplex_lb get_multiply get_multiply_noin get_nonexistent get_null get_off64 get_phase get_phase_affix get_polynom get_polynom_noin get_recip get_recip_const get_recurse get_rofs get_sbit get_sf get_ss get_type get_uint16 get_uint32 get_uint64 get_window get_window_clr get_window_ge get_window_gt get_window_le get_window_lt get_window_ne get_window_set get_zero global_name global_ref global_ref_empty global_ref_set gzip_add gzip_get gzip_get_get gzip_get_put gzip_move_from gzip_move_to gzip_nframes gzip_put gzip_put_get header_complex hide hide_hidden hide_unhide include include_accmode include_affix include_auto include_cb include_creat include_ignore include_index include_invalid include_nonexistent include_pc include_ref include_syntax index index_domain index_range legacy_get legacy_get_put legacy_get_rofs legacy_nframes legacy_nonexistent legacy_put legacy_spf lzma_get lzma_nframes madd madd_affix madd_alias madd_bit madd_bit_invalid madd_carray madd_clincom madd_const madd_cpolynom madd_crecip madd_crecip89 madd_divide madd_index madd_lincom madd_lincom_invalid madd_linterp madd_linterp_invalid madd_mplex madd_multiply madd_multiply_invalid madd_phase madd_phase_invalid madd_polynom madd_recip madd_sbit madd_spec madd_spec_directive madd_spec_invalid madd_spec_resolv madd_string madd_window move 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 name name_affix name_affix_bad name_after name_after_const name_dup name_move name_update name_update_const nfields nfields_hidden nfields_invalid nfields_type nfields_type_hidden nfields_type_invalid nfields_vector nfields_vector_hidden nfields_vector_invalid nframes nframes64 nframes_empty nframes_invalid nframes_off64 nframes_spf nmeta nmeta_hidden nmeta_invalid nmeta_parent nmeta_type nmeta_type_hidden nmeta_type_invalid nmeta_type_parent nmeta_vectors nmeta_vectors_del nmeta_vectors_hidden nmeta_vectors_invalid nmeta_vectors_parent open open_cb_abort open_cb_cont open_cb_ignore open_cb_invalid open_cb_rescan open_eaccess open_nonexistent open_notdirfile parse_alias parse_alias_code parse_alias_dup parse_alias_meta parse_alias_missing parse_badline parse_bit parse_bit4 parse_bit_bitnum parse_bit_bitsize parse_bit_ncols parse_bit_numbits parse_bit_scalar parse_carray parse_carray_long parse_const parse_const_ncols parse_divide parse_duplicate parse_duplicate_ignore parse_endian_bad parse_endian_big parse_endian_force parse_endian_little parse_endian_slash parse_eol parse_foffs parse_foffs_include parse_foffs_slash parse_hidden parse_hidden_field parse_hidden_meta parse_include parse_include_absolute parse_include_absrel parse_include_loop parse_include_nonexistent parse_include_prefix parse_include_prefix_dup parse_include_preprefix parse_include_relabs parse_include_relrel parse_include_slash parse_include_suffix parse_include_sufsuffix parse_index parse_lincom parse_lincom_ncols1 parse_lincom_ncols2 parse_lincom_nfields parse_lincom_nofields parse_lincom_non parse_lincom_non_ncols parse_lincom_scalar parse_linterp parse_linterp_ncols parse_malias parse_malias_dup parse_meta parse_meta_affix parse_meta_alias parse_meta_implicit parse_meta_implicit2 parse_meta_implicit_affix parse_meta_index parse_meta_index2 parse_meta_jump parse_meta_malias parse_meta_meta parse_meta_parent parse_meta_raw parse_mplex parse_mplex_ncols parse_mplex_scalar parse_multiply parse_multiply_ncols parse_name parse_name_dot parse_name_ext parse_name_pedantic parse_ncols parse_phase parse_phase_ncols parse_phase_scalar parse_polynom parse_polynom_ncols1 parse_polynom_ncols2 parse_polynom_scalar parse_protect_all parse_protect_bad parse_protect_data parse_protect_format parse_protect_none parse_quote parse_quote_mismatch parse_raw parse_raw_char parse_raw_ncols parse_raw_scalar parse_raw_spf parse_raw_type parse... [truncated message content] |
From: <ket...@us...> - 2012-03-14 22:23:01
|
Revision: 674 http://getdata.svn.sourceforge.net/getdata/?rev=674&view=rev Author: ketiltrout Date: 2012-03-14 22:22:55 +0000 (Wed, 14 Mar 2012) Log Message: ----------- Handle failure of filedir canonicalisation better in gd_cbopen() Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/src/open.c Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2012-03-14 20:25:41 UTC (rev 673) +++ trunk/getdata/ChangeLog 2012-03-14 22:22:55 UTC (rev 674) @@ -1,3 +1,6 @@ +2012-03-14 D. V. Wiebe <ge...@ke...> svn:673 + * src/open.c (gd_cbopen): Handle failure of _GD_CanonicalPath better. + 2012-03-14 D. V. Wiebe <ge...@ke...> svn:671 * src/flush.c (_GD_FlushFragment): Write SIE encoding directives. Modified: trunk/getdata/src/open.c =================================================================== --- trunk/getdata/src/open.c 2012-03-14 20:25:41 UTC (rev 673) +++ trunk/getdata/src/open.c 2012-03-14 22:22:55 UTC (rev 674) @@ -407,7 +407,7 @@ _GD_InitialiseFramework(); D = (DIRFILE *)malloc(sizeof(DIRFILE)); - if (dirfile == NULL || D == NULL) { + if (D == NULL) { free(dirfile); #ifndef GD_NO_DIR_OPEN close(dirfd); @@ -427,6 +427,15 @@ D->sehandler_extra = extra; D->standards = GD_DIRFILE_STANDARDS_VERSION; + if (dirfile == NULL) { + _GD_SetError(D, GD_E_RAW_IO, 0, filedir, errno, NULL); +#ifndef GD_NO_DIR_OPEN + close(dirfd); +#endif + dreturn("%p", D); + return D; + } + /* Add the INDEX entry */ D->n_entries = 1; D->n[_GD_EntryIndex(GD_INDEX_ENTRY)] = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-14 20:25:48
|
Revision: 673 http://getdata.svn.sourceforge.net/getdata/?rev=673&view=rev Author: ketiltrout Date: 2012-03-14 20:25:41 +0000 (Wed, 14 Mar 2012) Log Message: ----------- Some legitimacy for neo-defile: add stuff needed for CHIME data conversion (input plugin elsewhere). Modified Paths: -------------- trunk/defile/bin/cli.c trunk/defile/bin/rc.c trunk/defile/doc/Makefile.am trunk/defile/input/ascii.c trunk/defile/input/dirfile.c trunk/defile/lib/Makefile.am trunk/defile/lib/defile.h trunk/defile/lib/libdefile.c Modified: trunk/defile/bin/cli.c =================================================================== --- trunk/defile/bin/cli.c 2012-03-14 20:01:01 UTC (rev 672) +++ trunk/defile/bin/cli.c 2012-03-14 20:25:41 UTC (rev 673) @@ -92,8 +92,8 @@ #define SETULONG(x,y) SETSIMPLE(x,y,strtoul(config->argument, NULL, 0),,\ "%lu") -#define ABORT_DELAY 60000 /* sixty seconds; this is less than the maximum TCP - * round-trip timeout. Do we care? */ +#define ABORT_DELAY 60000000 /* sixty seconds; this is less than the maximum TCP + * round-trip timeout. Do we care? */ /* the very defile object */ static struct df_defile the_defile; @@ -107,13 +107,13 @@ if (!df->quiet) switch (sig) { case SIGHUP: - puts("Aborting due to hang up."); + fputs("\ndefile: aborting due to hang up.\n", stderr); break; case SIGINT: - puts("Aborting due to interruption."); + fputs("\ndefile: aborting due to interruption.\n", stderr); break; case SIGTERM: - puts("Aborting due to unexpected termination."); + fputs("\ndefile: aborting due to unexpected termination.\n", stderr); break; } @@ -332,13 +332,19 @@ l->r = 3; /* run through the search path looking for candidate libraries */ - if (dlp) + if (dlp) { + if (df->config.mode_flags & DF_MODE_DEBUG) + fprintf(stderr, "defile: searching local paths: %s\n", dlp); lt_dlforeachfile(dlp, DF_LTDLSearchFunc, l); + } /* the default plugin dir if the above didn't work; or if we're compiling a * list */ - if ((type == NULL && input == NULL) || l->r != 0) + if (type == NULL || l->r != 0) { + if (df->config.mode_flags & DF_MODE_DEBUG) + fprintf(stderr, "defile: searching default path: %s\n", DEFILE_MODULEDIR); lt_dlforeachfile(DEFILE_MODULEDIR, DF_LTDLSearchFunc, l); + } if (print) { for (i = 0; i < l->n; ++i) { @@ -608,9 +614,12 @@ } else if (output == NULL) { char *ptr2, *ptr3; ptr2 = strdup(input); - ptr3 = basename(ptr2); - ptr = malloc(strlen(dir) + strlen(ptr3) + 2); - strcat(strcat(strcpy(ptr, dir), "/"), ptr3); + /* remove forbidden characters */ + for (ptr3 = ptr2; *ptr3; ++ptr3) + if (*ptr3 == '/') + *ptr3 = '_'; + ptr = malloc(strlen(dir) + strlen(ptr2) + 2); + sprintf(ptr, "%s/%s", dir, ptr2); free(ptr2); } else if (output[0] == '/') { ptr = strdup(output); @@ -656,7 +665,7 @@ df->flags = flags; df->D = gd_open(df->dirfile, GD_RDWR | GD_CREAT | ((flags & DF_CLOBBER) ? - GD_TRUNC : GD_EXCL) | GD_VERBOSE); + (GD_TRUNC | GD_TRUNCSUB) : GD_EXCL) | GD_VERBOSE); if ((gderr = gd_error(df->D))) { char *err = gd_error_string(df->D, NULL, 0); @@ -670,6 +679,9 @@ return 1; } + if (!df->quiet) + printf("defile: writing to %s\n\n", df->dirfile); + return 0; } @@ -778,6 +790,10 @@ /* wait for the input to initialise */ DF_WaitWhileInputState(DF_ST_START, 0); + if (df->input_state == DF_ST_DONE || df->input_state == DF_ST_ERROR) { + DF_OUTSTATE_MX(DONE); + return NULL; + } /* initialise the output */ if (DF_MakeOutput()) { @@ -1158,6 +1174,8 @@ /* sanitise */ if (df->config.buflen < df->bufhead) df->config.buflen = df->bufhead; + if (df->config.buflen < 2) + df->config.buflen = 2; if (!df->quiet) puts(PACKAGE_STRING " " DEFILE_COPYRIGHT); @@ -1168,10 +1186,6 @@ else /* Load the input plugin */ df->input_framework = DF_ResolveInput(df->type); - if (!df->quiet) - DF_InputBanner(stdout, NULL, df->input_framework, NULL); - putchar('\n'); - /* parse input options */ memset(&rcd, 0, sizeof(rcd)); rcd.contact = df->input_framework->contact; @@ -1195,6 +1209,10 @@ exit(1); } + if (!df->quiet) + DF_InputBanner(stdout, NULL, df->input_framework, NULL); + putchar('\n'); + /* set up signal masks and handlers */ sigemptyset(&signals); sigaddset(&signals, SIGHUP); @@ -1232,7 +1250,8 @@ pthread_sigmask(SIG_UNBLOCK, &signals, NULL); /* wait until the initialisation is done */ - DF_WaitWhileInputState(DF_ST_START, 1); + fflush(stdout); + DF_WaitWhileInputStates(DF_ST_START, DF_ST_INIT, 1); DF_WaitWhileInputState(DF_ST_BUILD, 1); /* record our "start" time */ Modified: trunk/defile/bin/rc.c =================================================================== --- trunk/defile/bin/rc.c 2012-03-14 20:01:01 UTC (rev 672) +++ trunk/defile/bin/rc.c 2012-03-14 20:25:41 UTC (rev 673) @@ -225,6 +225,15 @@ int nopt = 0; const struct df_optdef **opt; + if (rcd->name) + printf("defile-%s input plugin v%s ", rcd->name, rcd->version); + else + printf("%s ", PACKAGE_STRING); + + if (rcd->copyright) + puts(rcd->copyright); + putchar('\n'); + if (rcd->usage_preamble) { if (rcd->name == NULL) printf(rcd->usage_preamble, argv0, argv0); @@ -271,7 +280,7 @@ static void DF_Version(const struct df_rc_data *rcd, const char *argv0) { if (rcd->name) - printf("defile-%s input plugin v%s\n", rcd->name, rcd->version); + printf("\ndefile-%s input plugin v%s\n", rcd->name, rcd->version); else puts(PACKAGE_STRING); Modified: trunk/defile/doc/Makefile.am =================================================================== --- trunk/defile/doc/Makefile.am 2012-03-14 20:01:01 UTC (rev 672) +++ trunk/defile/doc/Makefile.am 2012-03-14 20:25:41 UTC (rev 673) @@ -20,5 +20,9 @@ # AUTOMAKE_OPTIONS = foreign -man_MANS = defile.1 df_bsearch.3 df_check_abort.3 df_field_in_input.3 \ - df_init.3 df_on_abort.3 defile-input.7 +BUILT_SOURCES=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_init.3 df_input_name.3 df_nframes_allowed.3 df_on_abort.3 \ + df_push_frame.3 df_ready.3 df_set_const.3 df_shell_expand.3 Modified: trunk/defile/input/ascii.c =================================================================== --- trunk/defile/input/ascii.c 2012-03-14 20:01:01 UTC (rev 672) +++ trunk/defile/input/ascii.c 2012-03-14 20:25:41 UTC (rev 673) @@ -279,7 +279,7 @@ } /* add it */ - n = df_add_framedef(&fd, 1); + n = df_add_framedef(&fd, 1, 0); if (n < 0) exit(1); Modified: trunk/defile/input/dirfile.c =================================================================== --- trunk/defile/input/dirfile.c 2012-03-14 20:01:01 UTC (rev 672) +++ trunk/defile/input/dirfile.c 2012-03-14 20:25:41 UTC (rev 673) @@ -210,7 +210,7 @@ /* add it and remember its index */ raw[r].name = fd_field.name; - raw[r].index = df_add_framedef(&fd, 1); + raw[r].index = df_add_framedef(&fd, 1, 0); if (raw[r].index < 0) { dirfile_cleanup(); return 1; Modified: trunk/defile/lib/Makefile.am =================================================================== --- trunk/defile/lib/Makefile.am 2012-03-14 20:01:01 UTC (rev 672) +++ trunk/defile/lib/Makefile.am 2012-03-14 20:25:41 UTC (rev 673) @@ -21,6 +21,7 @@ AUTOMAKE_OPTIONS = foreign lib_LTLIBRARIES = libdefile.la +include_HEADERS = defile.h AM_CPPFLAGS = ${GETDATA_CFLAGS} libdefile_la_SOURCES = libdefile.c defile.h internal.h libdefile_la_LDFLAGS = -export-dynamic -version-info \ Modified: trunk/defile/lib/defile.h =================================================================== --- trunk/defile/lib/defile.h 2012-03-14 20:01:01 UTC (rev 672) +++ trunk/defile/lib/defile.h 2012-03-14 20:25:41 UTC (rev 673) @@ -127,10 +127,12 @@ const char *name); /* can only be used while building the dirfile (BUILD state) */ -int df_add_alias(const char *name, const char *target); -int df_add_framedef(const struct df_fdef *fdef, int count); +int df_add_alias(const char *name, const char *target, int fragment); +int df_add_fragment(const char *subdir, const char *name, unsigned int encoding, + unsigned long byte_sex, int parent); +int df_add_framedef(const struct df_fdef *fdef, int count, int parent); int df_add_entry(const gd_entry_t *entry); -int df_add_spec(const char *spec); +int df_add_spec(const char *spec, int parent); int df_ready(const char *reference); /* can only be used while pushing data (RUN state) */ @@ -139,7 +141,7 @@ int df_reinit(unsigned long long nframes, unsigned long long offset, double rate, const char *name, int mode); -/* can only be used while building or pushing data (BUILD or RUN state */ +/* can only be used while building or pushing data (BUILD or RUN state) */ int df_set_const(const char *name, gd_type_t type, const void *data_in); int df_set_string(const char *name, const char *string); int df_set_carray(const char *name, unsigned int start, size_t len, Modified: trunk/defile/lib/libdefile.c =================================================================== --- trunk/defile/lib/libdefile.c 2012-03-14 20:01:01 UTC (rev 672) +++ trunk/defile/lib/libdefile.c 2012-03-14 20:25:41 UTC (rev 673) @@ -23,6 +23,8 @@ #include "config.h" #endif #include "internal.h" +#include <sys/types.h> +#include <sys/stat.h> #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -127,13 +129,13 @@ return ((missing && !df->ofl_incl) || (!missing && df->ofl_incl)); } -int df_add_alias(const char *name, const char *target) +int df_add_alias(const char *name, const char *target, int fragment) { DF_CHECK_SEQUENCE(DF_ST_BUILD); /* skip fields we've been asked to exclude */ if (df_field_in_output(name)) - if (gd_add_alias(df->D, name, target, 0)) + if (gd_add_alias(df->D, name, target, fragment)) return DF_OUTPUT; return DF_SUCCESS; @@ -145,7 +147,8 @@ /* skip RAW fields */ if (E->field_type == GD_RAW_ENTRY) { - fputs("libdefile: Attempt to define RAW field via df_add_entry().", stderr); + fputs("libdefile: Attempt to define RAW field via df_add_entry().\n", + stderr); return DF_INPUT; } @@ -157,7 +160,7 @@ return DF_SUCCESS; } -int df_add_spec(const char *spec) +int df_add_spec(const char *spec, int fragment) { char *ptr; DF_CHECK_SEQUENCE(DF_ST_BUILD); @@ -181,14 +184,15 @@ /* check the second token to see if it's a RAW field */ ptr = gd_tokenise(df->D, NULL); - if (ptr && strcmp(ptr, "RAW")) { - fputs("libdefile: Attempt to define RAW field via df_add_spec().", stderr); + if (ptr && strcmp(ptr, "RAW") == 0) { + fputs("libdefile: Attempt to define RAW field via df_add_spec().\n", + stderr); return DF_INPUT; } free(ptr); /* add it */ - if (gd_add_spec(df->D, spec, 0)) + if (gd_add_spec(df->D, spec, fragment)) return DF_OUTPUT; return DF_SUCCESS; @@ -245,7 +249,8 @@ } #define DF_NO_RAW (-9999) -static int df_set_raw(const struct df_fdef_field *f, int i, int count) +static int df_set_raw(const struct df_fdef_field *f, int i, int count, + int fragment) { int r, is_new = 0; void *ptr; @@ -262,17 +267,17 @@ char *name = strdup(f->name); if (name == NULL) { - perror("libdefile"); + perror("libdefile: strdup"); return DF_SYSTEM; } /* try adding it to the dirfile */ - if (gd_add_raw(df->D, f->name, f->type, f->spf, 0)) + if (gd_add_raw(df->D, f->name, f->type, f->spf, fragment)) return DF_OUTPUT; /* add a new record */ ptr = realloc(df->raw, sizeof(struct df_raw) * (df->nraw + 1)); if (ptr == NULL) { - perror("libdefile"); + perror("libdefile: realloc"); return DF_SYSTEM; } df->raw = (struct df_raw*)ptr; @@ -305,7 +310,7 @@ df->raw[r].out = df->raw[r].buflen - df->raw[r].framesize; ptr = realloc(df->raw[r].b, df->raw[r].buflen); if (ptr == NULL) { - perror("libdefile"); + perror("libdefile: realloc"); return DF_SYSTEM; } df->raw[r].b = ptr; @@ -313,7 +318,7 @@ return r; } -int df_add_framedef(const struct df_fdef *fd, int count) +int df_add_framedef(const struct df_fdef *fd, int count, int fragment) { size_t c; unsigned int i; @@ -367,7 +372,7 @@ /* copy the framedef into an internal framedef record */ ptr = realloc(df->fd, sizeof(struct df_infdef) * (df->nfd + 1)); if (ptr == NULL) { - perror("libdefile"); + perror("libdefile: realloc"); return DF_SYSTEM; } df->fd = (struct df_infdef*)ptr; @@ -381,11 +386,11 @@ (struct df_infdef_field *)malloc(sizeof(struct df_infdef_field) * fd->n_fields); if (field == NULL) { - perror("libdefile"); + perror("libdefile: malloc"); return DF_SYSTEM; } for (i = 0; i < fd->n_fields; ++i) { - field[i].index = df_set_raw(fd->field + i, i, count); + field[i].index = df_set_raw(fd->field + i, i, count, fragment); if (field[i].index < 0) { /* check for error */ if (field[i].index != DF_NO_RAW) { @@ -454,11 +459,12 @@ free(df->input); df->input = strdup(name); if (df->input == NULL) { - perror("libdefile"); + perror("libdefile: strdup"); return DF_SYSTEM; } } - df->rate = rate; + if (rate >= 0) + df->rate = rate; df->nframes = (uint64_t)nframes; df->offset = (uint64_t)offset; @@ -687,7 +693,7 @@ free(df->input); df->input = strdup(name); if (df->input == NULL) { - perror("libdefile"); + perror("libdefile: strdup"); return DF_SYSTEM; } } @@ -758,3 +764,55 @@ return DF_SUCCESS; } + +int df_add_fragment(const char *subdir, const char *name, unsigned int encoding, + unsigned long byte_sex, int parent) +{ + int ind; + struct stat stat_buf; + char *subdirpath; + + DF_CHECK_SEQUENCE(DF_ST_BUILD); + + /* make the subdir, if needed */ + if (subdir) { + subdirpath = malloc(strlen(df->dirfile) + strlen(subdir) + 2); + if (subdirpath == NULL) { + perror("libdefile: malloc"); + return DF_SYSTEM; + } + sprintf(subdirpath, "%s/%s", df->dirfile, subdir); + if (stat(subdirpath, &stat_buf) == 0) + if (S_ISDIR(stat_buf.st_mode)) + goto DF_HAVE_DIR; + + if (mkdir(subdirpath, 0777) == 0) + goto DF_HAVE_DIR; + free(subdirpath); + + fprintf(stderr, "libdefile: unable to create output subdirectory %s\n", + subdir); + return DF_OUTPUT; + +DF_HAVE_DIR: + free(subdirpath); + subdirpath = malloc(strlen(subdir) + strlen(name) + 2); + sprintf(subdirpath, "%s/%s", subdir, name); + } else + subdirpath = strdup(name); + + if (subdirpath == NULL) { + perror("libdefile: strdup"); + return DF_SYSTEM; + } + + /* attempt to add the new fragment */ + ind = gd_include(df->D, subdirpath, 0, + GD_CREAT | GD_EXCL | encoding | byte_sex); + free(subdirpath); + + if (ind < 0) + return DF_OUTPUT; + + return ind; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-14 20:01:10
|
Revision: 672 http://getdata.svn.sourceforge.net/getdata/?rev=672&view=rev Author: ketiltrout Date: 2012-03-14 20:01:01 +0000 (Wed, 14 Mar 2012) Log Message: ----------- NOSYNC Modified Paths: -------------- trunk/getdata/bindings/idl/getdata.c Modified: trunk/getdata/bindings/idl/getdata.c =================================================================== --- trunk/getdata/bindings/idl/getdata.c 2012-03-14 19:54:48 UTC (rev 671) +++ trunk/getdata/bindings/idl/getdata.c 2012-03-14 20:01:01 UTC (rev 672) @@ -3040,6 +3040,7 @@ IDL_STRING field_code; int field_code_x; int noclose; + int nosync; } KW_RESULT; KW_RESULT kw; @@ -3047,7 +3048,7 @@ GDIDL_KW_INIT_ERROR; kw.field_code_x = 0; - kw.noclose = 0; + kw.noclose = kw.nosync = 0; static IDL_KW_PAR kw_pars[] = { GDIDL_KW_PAR_ERROR, @@ -3055,7 +3056,7 @@ { "FIELD_CODE", IDL_TYP_STRING, 1, 0, IDL_KW_OFFSETOF(field_code_x), IDL_KW_OFFSETOF(field_code) }, { "NOCLOSE", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(noclose) }, - { "NOSYNC", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(noclose) }, + { "NOSYNC", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(nosync) }, { NULL } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-14 19:54:56
|
Revision: 671 http://getdata.svn.sourceforge.net/getdata/?rev=671&view=rev Author: ketiltrout Date: 2012-03-14 19:54:48 +0000 (Wed, 14 Mar 2012) Log Message: ----------- * Don't sync, just close in gd_{close,discard,uninclude}. * Added gd_raw_close() + bindings. * Fix initialisation of file->pos in SIE encoding. * Write SIE /encoding. * Fix perl build to fix dependency tracking. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/bindings/cxx/dirfile.cpp trunk/getdata/bindings/cxx/getdata/dirfile.h trunk/getdata/bindings/cxx/test/big_test.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/perl/Build.PL.in trunk/getdata/bindings/perl/simple_funcs.xsin trunk/getdata/bindings/perl/t/big_test.t trunk/getdata/bindings/python/pydirfile.c trunk/getdata/bindings/python/test/big_test.py trunk/getdata/configure.ac trunk/getdata/doc/list.tests trunk/getdata/src/close.c trunk/getdata/src/flush.c trunk/getdata/src/getdata.h.in trunk/getdata/src/include.c trunk/getdata/src/internal.h trunk/getdata/src/sie.c Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/ChangeLog 2012-03-14 19:54:48 UTC (rev 671) @@ -1,3 +1,28 @@ +2012-03-14 D. V. Wiebe <ge...@ke...> svn:671 + * src/flush.c (_GD_FlushFragment): Write SIE encoding directives. + + * src/sie.c (_GD_SampIndOpen): Initialise file->pos to 0 to avoid issues + with _GD_GetFilePos. + * src/sie.c (_GD_SampIndSeek): Don't short circuit if no record is loaded. + + * src/flush.c (_GD_Flush _GD_SyncOrClose): Make syncing optional with a new + parameter (syn). + * src/flush.c (gd_raw_close): Added. + * src/clsoe.c (_GD_ShutdownDirfile) src/include.c (gd_uninclude): Don't + sync, just close raw files. + + * bindings/python/pydirfile.c (gdpy_dirfile_raw_close) + bindings/cxx/dirfile.cpp (Dirfile::RawClose) bindings/perl/simple_funcs.xsin + (raw_close) bindings/f77/fgetdata.c (GDRCLO) bindings/f77/getdata.f90.in + (fgd_raw_close): Added. + * bindings/idl/getdata.c (gdidl_flush): Add /NOSYNC. + * bindings/python/test/big_test.py bindings/cxx/test/big_test.cpp + bindings/perl/t/big_test.t bindings/f77/test/big_test.f + bindings/f77/test/big_test95.f90: Added test 233. + + * bindings/perl/Build.PL.in: subclass Module::Build to properly handle + simple_funcs.xs dependency tracking. + 2012-03-06 D. V. Wiebe <ge...@ke...> svn:667 * src/errors.c: Change prefix on verbose output to "libgetdata". Modified: trunk/getdata/bindings/cxx/dirfile.cpp =================================================================== --- trunk/getdata/bindings/cxx/dirfile.cpp 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/cxx/dirfile.cpp 2012-03-14 19:54:48 UTC (rev 671) @@ -511,6 +511,11 @@ return gd_sync(D, field_code); } +int Dirfile::RawClose(const char* field_code) const +{ + return gd_raw_close(D, field_code); +} + int Dirfile::UnHide(const char* field_code) const { return gd_unhide(D, field_code); Modified: trunk/getdata/bindings/cxx/getdata/dirfile.h =================================================================== --- trunk/getdata/bindings/cxx/getdata/dirfile.h 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/cxx/getdata/dirfile.h 2012-03-14 19:54:48 UTC (rev 671) @@ -227,6 +227,8 @@ size_t PutString(const char *field_code, const char *data_in) const; + int RawClose(const char *field_code = NULL) const; + GetData::RawEntry *Reference(const char* field_code = NULL) const; const char *ReferenceFilename(); Modified: trunk/getdata/bindings/cxx/test/big_test.cpp =================================================================== --- trunk/getdata/bindings/cxx/test/big_test.cpp 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/cxx/test/big_test.cpp 2012-03-14 19:54:48 UTC (rev 671) @@ -1639,6 +1639,9 @@ CHECK_OK2(232, 3); CHECK_STRING2(232, 4, str, "test3 test4"); + // 233: gd_raw_close check + d->RawClose("data"); + CHECK_OK(233); @@ -1646,6 +1649,7 @@ + // =================================================================== d->Discard(); delete d; Modified: trunk/getdata/bindings/f77/fgetdata.c =================================================================== --- trunk/getdata/bindings/f77/fgetdata.c 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/f77/fgetdata.c 2012-03-14 19:54:48 UTC (rev 671) @@ -3765,6 +3765,24 @@ dreturnvoid(); } +/* gd_raw_close wrapper */ +void F77_FUNC(gdrclo, GDRCLO) (const int* dirfile, const char* field_code, + const int* field_code_l) +{ + dtrace("%i, %p, %i", *dirfile, field_code, *field_code_l); + + if (field_code_l == 0) + gd_sync(_GDF_GetDirfile(*dirfile), NULL); + else { + char *out = (char *)malloc(*field_code_l + 1); + gd_raw_close(_GDF_GetDirfile(*dirfile), _GDF_CString(out, field_code, + *field_code_l)); + free(out); + } + + dreturnvoid(); +} + void F77_FUNC(gdtoke, GDTOKE) (char *toke, int *toke_l, const int *dirfile, const char *string, const int *string_l, const int *n) { Modified: trunk/getdata/bindings/f77/fgetdata.h =================================================================== --- trunk/getdata/bindings/f77/fgetdata.h 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/f77/fgetdata.h 2012-03-14 19:54:48 UTC (rev 671) @@ -620,6 +620,9 @@ void F77_FUNC(gdsync, GDSYNC) (const int* dirfile, const char* field_code, const int* field_code_l); +void F77_FUNC(gdrclo, GDRCLO) (const int* dirfile, const char* field_code, + const int* field_code_l); + void F77_FUNC(gdinca, GDINCA) (const int* dirfile, const char* file, const int* file_l, const int* fragment_index, const char* prefix, const int* prefix_l, const char* suffix, const int* suffix_l, Modified: trunk/getdata/bindings/f77/getdata.f.in =================================================================== --- trunk/getdata/bindings/f77/getdata.f.in 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/f77/getdata.f.in 2012-03-14 19:54:48 UTC (rev 671) @@ -328,6 +328,8 @@ EXTERNAL GDPTST C Corresponding to gd_putdata(3) EXTERNAL GDPUTD +C Corresponding to gd_raw_close(3) + EXTERNAL GDRCLO C Corresponding to gd_reference(3) EXTERNAL GDREFE C Correpsonding to gd_rename(3) Modified: trunk/getdata/bindings/f77/getdata.f90.in =================================================================== --- trunk/getdata/bindings/f77/getdata.f90.in 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/f77/getdata.f90.in 2012-03-14 19:54:48 UTC (rev 671) @@ -2734,6 +2734,13 @@ call gdsync(dirfile, TRIM(field_code), LEN_TRIM(field_code)) end subroutine +subroutine fgd_raw_close (dirfile, field_code) + integer, intent(in) :: dirfile + character (len=*), intent(in) :: field_code + + call gdrclo(dirfile, TRIM(field_code), LEN_TRIM(field_code)) +end subroutine + subroutine fgd_fragment_affixes (prefix, pl, suffix, sl, dirfile, & fragment_index) character(len=*), intent(out) :: prefix, suffix Modified: trunk/getdata/bindings/f77/test/big_test.f =================================================================== --- trunk/getdata/bindings/f77/test/big_test.f 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/f77/test/big_test.f 2012-03-14 19:54:48 UTC (rev 671) @@ -2070,6 +2070,9 @@ CALL CHKIN2(ne, 232, 5, l, slen) CALL CHKST2(ne, 232, 6, str, 'test3 test4') +C 233: GDRCLO check + CALL GDRCLO(d, 'data', 4) + CALL CHKEOK(ne, 233, d) @@ -2078,6 +2081,7 @@ + C =============================================================== C Cleanup CALL GDDSCD(d) Modified: trunk/getdata/bindings/f77/test/big_test95.f90 =================================================================== --- trunk/getdata/bindings/f77/test/big_test95.f90 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/f77/test/big_test95.f90 2012-03-14 19:54:48 UTC (rev 671) @@ -2504,6 +2504,10 @@ call check_int2(ne, 232, 5, l, slen) call check_str2(ne, 232, 6, str, 'test3 test4') +! 233: fgd_raw_close check + call fgd_raw_close(d, 'data') + call check_ok(ne, 233, d) + Modified: trunk/getdata/bindings/idl/getdata.c =================================================================== --- trunk/getdata/bindings/idl/getdata.c 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/idl/getdata.c 2012-03-14 19:54:48 UTC (rev 671) @@ -3055,6 +3055,7 @@ { "FIELD_CODE", IDL_TYP_STRING, 1, 0, IDL_KW_OFFSETOF(field_code_x), IDL_KW_OFFSETOF(field_code) }, { "NOCLOSE", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(noclose) }, + { "NOSYNC", IDL_TYP_INT, 1, 0, 0, IDL_KW_OFFSETOF(noclose) }, { NULL } }; @@ -3065,8 +3066,12 @@ if (kw.field_code_x) field_code = IDL_STRING_STR(&kw.field_code); - if (kw.noclose) + if (kw.noclose && kw.nosync) + idl_kw_abort("nothing to do"); + else if (kw.noclose) gd_sync(D, field_code); + else if (kw.nosync) + gd_raw_close(D, field_code); else gd_flush(D, field_code); Modified: trunk/getdata/bindings/idl/test/big_test.pro =================================================================== --- trunk/getdata/bindings/idl/test/big_test.pro 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/idl/test/big_test.pro 2012-03-14 19:54:48 UTC (rev 671) @@ -1341,6 +1341,10 @@ nume += check_ok2(232, 3 ,d) nume += check_simple2(232, 4, str, "test3 test4") +; 233: gd_raw_close check +gd_flush, d, field_code='data', /nosync +nume += check_ok(233, d) + Modified: trunk/getdata/bindings/perl/Build.PL.in =================================================================== --- trunk/getdata/bindings/perl/Build.PL.in 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/perl/Build.PL.in 2012-03-14 19:54:48 UTC (rev 671) @@ -1,7 +1,24 @@ # @configure_input@ use Module::Build; -my $build = Module::Build->new( + +# divert up_to_date to allow consideration of simple_funcs.xs... is there an +# easier way to do this? +my $class = Module::Build->subclass( + class => "GetData::Build", + code => <<'SUBCLASS' ); + +sub up_to_date { + my ($self, $source, $derived) = @_; + + if ($source eq "lib/GetData.xs") { + return 0 if (not $self->up_to_date("lib/simple_funcs.xs", $derived)); + } + return $self->SUPER::up_to_date($source, $derived); +} +SUBCLASS + +my $build = $class->new( dist_abstract => "Perl bindings to the GetData library", dist_author => 'The GetData Project <@PACKAGE_BUGREPORT@>', dist_version_from => "GetData.pm", Modified: trunk/getdata/bindings/perl/simple_funcs.xsin =================================================================== --- trunk/getdata/bindings/perl/simple_funcs.xsin 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/perl/simple_funcs.xsin 2012-03-14 19:54:48 UTC (rev 671) @@ -152,3 +152,4 @@ int madd_mplex(DIRFILE *dirfile, const char *parent, const char *field_code, const char *in_field, const char *count_field, gd_count_t count_val, gd_count_t count_max) +int raw_close(DIRFILE *dirfile, const char *field_code) Modified: trunk/getdata/bindings/perl/t/big_test.t =================================================================== --- trunk/getdata/bindings/perl/t/big_test.t 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/perl/t/big_test.t 2012-03-14 19:54:48 UTC (rev 671) @@ -22,7 +22,7 @@ use GetData; use Math::Complex; use strict; -use Test::More tests => 1265; +use Test::More tests => 1266; my $ne = 0; my ($s, @a, %h); @@ -1661,6 +1661,9 @@ CheckOK(232); CheckSArray(232, \@a, "test1 test2", "test3 test4", "test5"); +# 233: gd_raw_close check +$s = $_->raw_close('data'); +CheckOK(233); @@ -1668,5 +1671,7 @@ + + $d = $_ = undef; system "rm -rf dirfile"; Modified: trunk/getdata/bindings/python/pydirfile.c =================================================================== --- trunk/getdata/bindings/python/pydirfile.c 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/python/pydirfile.c 2012-03-14 19:54:48 UTC (rev 671) @@ -909,6 +909,30 @@ return Py_None; } +static PyObject* gdpy_dirfile_raw_close(struct gdpy_dirfile_t* self, + PyObject* args, PyObject* keys) +{ + dtrace("%p, %p, %p", self, args, keys); + + char* keywords[] = { "field_code", NULL }; + const char* field_code = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, keys, "|s:pygetdata.dirfile.raw_close", + keywords, &field_code)) + { + dreturn("%p", NULL); + return NULL; + } + + gd_raw_close(self->D, field_code); + + PYGD_CHECK_ERROR(self->D, NULL); + + Py_INCREF(Py_None); + dreturn("%p", Py_None); + return Py_None; +} + static PyObject* gdpy_dirfile_include(struct gdpy_dirfile_t* self, PyObject* args, PyObject* keys) { @@ -2532,10 +2556,8 @@ }, {"flush", (PyCFunction)gdpy_dirfile_flush, METH_VARARGS | METH_KEYWORDS, "flush([field_code])\n\n" - "Flush pending writes to the specified field to disk. This does\n" - "not flush pending metadata changes. For that, use metaflush.\n" - "However, if field_code is omitted, all data *and* metadata will be\n" - "written to disk. See gd_flush(3)." + "Equivalent to sync([field_code]) && raw_close([field_code]).\n" + "See gd_flush(3)." }, {"bof", (PyCFunction)gdpy_dirfile_getbof, METH_VARARGS | METH_KEYWORDS, "bof(field_code)\n\n" @@ -2954,9 +2976,19 @@ }, {"sync", (PyCFunction)gdpy_dirfile_sync, METH_VARARGS | METH_KEYWORDS, "sync([field_code])\n\n" - "This is similar to using Flush, but without closing the affected\n" - "files. See gd_sync(3)." + "Flush pending writes to the specified field to disk. This does\n" + "not flush pending metadata changes. For that, use metaflush.\n" + "However, if field_code is omitted, all data *and* metadata will be\n" + "written to disk. See gd_sync(3)." }, + {"raw_close", (PyCFunction)gdpy_dirfile_raw_close, + METH_VARARGS | METH_KEYWORDS, + "raw_close([field_code])\n\n" + "Close any open raw data files associated with field_code, freeing\n" + /* ------- handy ruler ---------------------------------------------| */ + "resources which may be used for other purposes. If field_code is\n" + "omitted, all open raw data files are closed. See gd_raw_close(3)." + }, {"naliases", (PyCFunction)gdpy_dirfile_naliases, METH_VARARGS | METH_KEYWORDS, "naliases(field_code)\n\n" "This function returns the number of aliases defined for the specified\n" @@ -3005,7 +3037,6 @@ }, {"tokenise", (PyCFunction)gdpy_dirfile_tokenise, METH_VARARGS | METH_KEYWORDS, "tokenise([string])\n\n" - /* ------- handy ruler ---------------------------------------------| */ "If 'string' is given, runs the GetData tokeniser on 'string' and\n" "returns the first token. If 'string' is not given, returns\n" "subsequent tokens (one per call) of the last string that was\n" Modified: trunk/getdata/bindings/python/test/big_test.py =================================================================== --- trunk/getdata/bindings/python/test/big_test.py 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/bindings/python/test/big_test.py 2012-03-14 19:54:48 UTC (rev 671) @@ -1915,6 +1915,13 @@ except: CheckOK2(232, 3) CheckSimple2(232, 4, str, "test3 test4") + +# 233: gd_raw_close check +try: + d.raw_close('data') +except: + CheckOK(233) + Modified: trunk/getdata/configure.ac =================================================================== --- trunk/getdata/configure.ac 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/configure.ac 2012-03-14 19:54:48 UTC (rev 671) @@ -959,8 +959,8 @@ AC_CONFIG_FILES([man/gd_alter_endianness.3]) AC_CONFIG_FILES([man/gd_alter_frameoffset.3]) AC_CONFIG_FILES([src/Makefile]) -dnl This doubling allows us to build getdata.h as a normal AC_CONFIG_FILE, but use -dnl AC_CONFIG_HEADERS to check whether it has changed. +dnl This doubling allows us to build getdata.h as a normal AC_CONFIG_FILE, but +dnl use AC_CONFIG_HEADERS to check whether it has changed. AC_CONFIG_FILES([src/getdata.ah:src/getdata.h.in]) AC_CONFIG_HEADERS([src/getdata.h:src/getdata.ah], [chmod a-w src/getdata.h]) AC_CONFIG_FILES([src/getdata.pc]) Modified: trunk/getdata/doc/list.tests =================================================================== --- trunk/getdata/doc/list.tests 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/doc/list.tests 2012-03-14 19:54:48 UTC (rev 671) @@ -244,3 +244,4 @@ 230 F9CIpP gd_madd_mplex 231 F9CIpP gd_alter_mplex 232 F9CIpP gd_tokenise +233 F9CIpP gd_raw_close Modified: trunk/getdata/src/close.c =================================================================== --- trunk/getdata/src/close.c 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/src/close.c 2012-03-14 19:54:48 UTC (rev 671) @@ -85,7 +85,7 @@ for(i = 0; i < D->n_entries; ++i) if (D->entry[i]->field_type == GD_RAW_ENTRY) - _GD_Flush(D, D->entry[i], 1); + _GD_Flush(D, D->entry[i], 0, 1); if (D->error) { dreturn("%i", 1); Modified: trunk/getdata/src/flush.c =================================================================== --- trunk/getdata/src/flush.c 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/src/flush.c 2012-03-14 19:54:48 UTC (rev 671) @@ -22,11 +22,11 @@ #define GD_MAX_PRETTY_FIELD_WIDTH 80 -void _GD_Flush(DIRFILE* D, gd_entry_t *E, int clo) +void _GD_Flush(DIRFILE *D, gd_entry_t *E, int syn, int clo) { int i; - dtrace("%p, %p, %i", D, E, clo); + dtrace("%p, %p, %i, %i", D, E, syn, clo); if (++D->recurse_level >= GD_MAX_RECURSE_LEVEL) { _GD_SetError(D, GD_E_RECURSE_LEVEL, GD_E_RECURSE_CODE, NULL, 0, E->field); @@ -41,13 +41,15 @@ ((_gd_ef[E->e->u.raw.file[0].subenc].flags & GD_EF_OOP) && (E->e->u.raw.file[1].idata >= 0))) { - if ((D->flags & GD_ACCMODE) == GD_RDWR && + if (syn && (D->flags & GD_ACCMODE) == GD_RDWR && (E->e->u.raw.file[0].mode & GD_FILE_WRITE) && _gd_ef[E->e->u.raw.file[0].subenc].sync != NULL && (*_gd_ef[E->e->u.raw.file[0].subenc].sync)(E->e->u.raw.file)) + { _GD_SetError(D, GD_E_RAW_IO, 0, E->e->u.raw.file[0].name, errno, NULL); - else if (clo && _GD_FiniRawIO(D, E, E->fragment_index, GD_FINIRAW_KEEP)) + } else if (clo && _GD_FiniRawIO(D, E, E->fragment_index, + GD_FINIRAW_KEEP)) { _GD_SetError(D, GD_E_RAW_IO, 0, E->e->u.raw.file[0].name, errno, NULL); @@ -56,13 +58,13 @@ break; case GD_LINCOM_ENTRY: for (i = 2; i < E->EN(lincom,n_fields); ++i) - _GD_Flush(D, E->e->entry[i], clo); + _GD_Flush(D, E->e->entry[i], syn, clo); /* fallthrough */ case GD_MULTIPLY_ENTRY: case GD_DIVIDE_ENTRY: case GD_WINDOW_ENTRY: case GD_MPLEX_ENTRY: - _GD_Flush(D, E->e->entry[1], clo); + _GD_Flush(D, E->e->entry[1], syn, clo); /* fallthrough */ case GD_LINTERP_ENTRY: case GD_BIT_ENTRY: @@ -70,7 +72,7 @@ case GD_POLYNOM_ENTRY: case GD_SBIT_ENTRY: case GD_RECIP_ENTRY: - _GD_Flush(D, E->e->entry[0], clo); + _GD_Flush(D, E->e->entry[0], syn, clo); case GD_CONST_ENTRY: case GD_CARRAY_ENTRY: case GD_STRING_ENTRY: @@ -688,8 +690,14 @@ case GD_TEXT_ENCODED: fputs("/ENCODING text\n", stream); break; + case GD_SIE_ENCODED: + fputs("/ENCODING sie\n", stream); + break; case 0: break; + case GD_ZZIP_ENCODED: + case GD_ZZSLIM_ENCODED: + /* XXX do something here ... ? */ default: fprintf(stream, "/ENCODING unknown # (%lx)\n", D->fragment[i].encoding); break; @@ -842,14 +850,14 @@ return (D->error == GD_E_OK) ? 0 : -1; } -static int _GD_SyncOrClose(DIRFILE* D, const char* field_code, int clo) +static int _GD_SyncOrClose(DIRFILE* D, const char* field_code, int syn, int clo) { unsigned int i; int repr; char *simple_field_code; gd_entry_t *E; - dtrace("%p, \"%s\", %i", D, field_code, clo); + dtrace("%p, \"%s\", %i, %i", D, field_code, syn, clo); _GD_ClearError(D); @@ -860,14 +868,14 @@ if (!D->error) for (i = 0; i < D->n_entries; ++i) if (D->entry[i]->field_type == GD_RAW_ENTRY) - _GD_Flush(D, D->entry[i], clo); + _GD_Flush(D, D->entry[i], syn, clo); } else { /* discard representation */ E = _GD_FindFieldAndRepr(D, field_code, &simple_field_code, &repr, NULL, 1, 1); if (!D->error) - _GD_Flush(D, E, clo); + _GD_Flush(D, E, syn, clo); if (field_code != simple_field_code) free(simple_field_code); @@ -883,19 +891,31 @@ dtrace("%p, \"%s\"", D, field_code); - ret = _GD_SyncOrClose(D, field_code, 0); + ret = _GD_SyncOrClose(D, field_code, 1, 0); dreturn("%i", ret); return ret; } +int gd_raw_close(DIRFILE *D, const char *field_code) +{ + int ret; + + dtrace("%p, \"%s\"", D, field_code); + + ret = _GD_SyncOrClose(D, field_code, 0, 1); + + dreturn("%i", ret); + return ret; +} + int gd_flush(DIRFILE *D, const char *field_code) { int ret; dtrace("%p, \"%s\"", D, field_code); - ret = _GD_SyncOrClose(D, field_code, 1); + ret = _GD_SyncOrClose(D, field_code, 1, 1); dreturn("%i", ret); return ret; Modified: trunk/getdata/src/getdata.h.in =================================================================== --- trunk/getdata/src/getdata.h.in 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/src/getdata.h.in 2012-03-14 19:54:48 UTC (rev 671) @@ -943,6 +943,9 @@ extern DIRFILE *gd_open(const char *dirfilename, unsigned long int flags) gd_nonnull ((1)); +extern int gd_raw_close(DIRFILE *dirfile, + const char *field_code) gd_nonnull ((1)); + extern int gd_rename(DIRFILE *dirfile, const char *old_code, const char *new_name, unsigned flags) gd_nonnull ((1,2,3)); Modified: trunk/getdata/src/include.c =================================================================== --- trunk/getdata/src/include.c 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/src/include.c 2012-03-14 19:54:48 UTC (rev 671) @@ -463,7 +463,7 @@ if (D->entry[i]->field_type == GD_RAW_ENTRY && _GD_ContainsFragment(f, nf, D->entry[i]->fragment_index)) { - _GD_Flush(D, D->entry[i], 1); + _GD_Flush(D, D->entry[i], 0, 1); } /* flush the fragment's metadata, if requested */ Modified: trunk/getdata/src/internal.h =================================================================== --- trunk/getdata/src/internal.h 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/src/internal.h 2012-03-14 19:54:48 UTC (rev 671) @@ -1003,7 +1003,7 @@ #define _GD_FileSwapBytes(D,i) ((D)->fragment[i].byte_sex & GD_BIG_ENDIAN) #endif int _GD_FiniRawIO(DIRFILE*, const gd_entry_t*, int, int); -void _GD_Flush(DIRFILE *restrict, gd_entry_t *restrict, int); +void _GD_Flush(DIRFILE *restrict, gd_entry_t *restrict, int, int); void _GD_FlushMeta(DIRFILE* D, int fragment, int force); void _GD_FreeE(DIRFILE *restrict, gd_entry_t *restrict, int); off64_t _GD_GetEOF(DIRFILE *restrict, const gd_entry_t *restrict, Modified: trunk/getdata/src/sie.c =================================================================== --- trunk/getdata/src/sie.c 2012-03-12 22:35:14 UTC (rev 670) +++ trunk/getdata/src/sie.c 2012-03-14 19:54:48 UTC (rev 671) @@ -91,7 +91,7 @@ } file->mode = mode; - file->pos = -1; + file->pos = 0; dreturn("%i", 0); return 0; } @@ -140,7 +140,7 @@ dtrace("%p, %llx, 0x%X, 0x%X", file, (long long)sample, data_type, mode); - if (file->pos == sample) { + if (file->pos == sample && f->p >= 0) { dreturn("%lli", (long long)sample); return sample; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-12 22:35:20
|
Revision: 670 http://getdata.svn.sourceforge.net/getdata/?rev=670&view=rev Author: ketiltrout Date: 2012-03-12 22:35:14 +0000 (Mon, 12 Mar 2012) Log Message: ----------- Clean compiler warnings. Modified Paths: -------------- trunk/defile/lib/libdefile.c Modified: trunk/defile/lib/libdefile.c =================================================================== --- trunk/defile/lib/libdefile.c 2012-03-12 22:18:31 UTC (rev 669) +++ trunk/defile/lib/libdefile.c 2012-03-12 22:35:14 UTC (rev 670) @@ -352,13 +352,13 @@ c = fd->field[i].cadence ? fd->field[i].cadence : z; if (c < z) { fprintf(stderr, "libdefile: internal frame definition error in input " - "plugin: datatype size exceeds cadence (%i > %i)\n", z, c); + "plugin: datatype size exceeds cadence (%zu > %zu)\n", z, c); return DF_INPUT; } if (fd->field[i].offset + (fd->field[i].spf - 1) * c + z > fd->framesize) { fprintf(stderr, "libdefile: internal frame definition error in input " - "plugin: data extends beyond end of frame (%i > %i)\n", + "plugin: data extends beyond end of frame (%zu > %zu)\n", fd->field[i].offset + (fd->field[i].spf - 1) * c + z, fd->framesize); return DF_INPUT; } @@ -423,7 +423,7 @@ fprintf(stderr, "defile: %i: (excluded)\n", i); } else { fprintf(stderr, - "defile: %i: \"%s\" (=r%i) %zix%i bytes @ %lli,%zi\n", i, + "defile: %i: \"%s\" (=r%i) %ux%i bytes @ %lli,%zi\n", i, df->raw[f->index].name, f->index, f->spf, GD_SIZE(df->raw[f->index].type), (long long)f->offset, f->cadence); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-12 22:18:38
|
Revision: 669 http://getdata.svn.sourceforge.net/getdata/?rev=669&view=rev Author: ketiltrout Date: 2012-03-12 22:18:31 +0000 (Mon, 12 Mar 2012) Log Message: ----------- Clean compiler warnings. Modified Paths: -------------- trunk/getdata/bindings/perl/simple_funcs.pl trunk/getdata/src/ascii.c trunk/getdata/src/flush.c trunk/getdata/src/fpos.c trunk/getdata/src/getdata.c trunk/getdata/src/index.c trunk/getdata/src/putdata.c trunk/getdata/src/sie.c Modified: trunk/getdata/bindings/perl/simple_funcs.pl =================================================================== --- trunk/getdata/bindings/perl/simple_funcs.pl 2012-03-07 04:48:00 UTC (rev 668) +++ trunk/getdata/bindings/perl/simple_funcs.pl 2012-03-12 22:18:31 UTC (rev 669) @@ -41,10 +41,13 @@ my ($t, $n) = @$_; return "&$n" if ($t =~ /&$/); - return "(long long)$n" if ($t eq "off64_t" or $t eq "gd_shift_t"); + return "(long long)$n" if ($t eq "off64_t" or $t eq "gd_shift_t" or + $t eq "gdpu_shift_t" or $t eq "int64_t"); + return "(unsigned long long)$n" if ($t eq "uint64_t"); return "creal($n), cimag($n)" if ($t eq "_Complex double" or $t eq "gdpu_complex"); - return "$n.r, $n.u, $n.i" if ($t eq "gd_triplet_t"); + return "$n.r, (unsigned long long)$n.u, (long long)$n.i" + if ($t eq "gd_triplet_t"); return $n; } Modified: trunk/getdata/src/ascii.c =================================================================== --- trunk/getdata/src/ascii.c 2012-03-07 04:48:00 UTC (rev 668) +++ trunk/getdata/src/ascii.c 2012-03-12 22:18:31 UTC (rev 669) @@ -64,7 +64,7 @@ { char line[64]; - dtrace("%p, %lli, <unused>, 0x%X", file, count, mode); + dtrace("%p, %lli, <unused>, 0x%X", file, (long long)count, mode); if (count < file->pos) { rewind((FILE *)file->edata); @@ -388,6 +388,6 @@ fclose(stream); - dreturn("%lli", n); + dreturn("%lli", (long long)n); return n; } Modified: trunk/getdata/src/flush.c =================================================================== --- trunk/getdata/src/flush.c 2012-03-07 04:48:00 UTC (rev 668) +++ trunk/getdata/src/flush.c 2012-03-12 22:18:31 UTC (rev 669) @@ -1065,7 +1065,7 @@ } D->flags |= GD_HAVE_VERSION; - dreturn("0x%04llx", D->av); + dreturn("0x%04" PRIx64, D->av); return D->av; } Modified: trunk/getdata/src/fpos.c =================================================================== --- trunk/getdata/src/fpos.c 2012-03-07 04:48:00 UTC (rev 668) +++ trunk/getdata/src/fpos.c 2012-03-12 22:18:31 UTC (rev 669) @@ -316,8 +316,8 @@ int repr, is_index = 0; unsigned int mode = (whence & GD_SEEK_WRITE) ? GD_FILE_WRITE : GD_FILE_READ; - dtrace("%p, \"%s\", %lli, %lli, 0x%X", D, field_code_in, frame_num, - sample_num, whence); + dtrace("%p, \"%s\", %lli, %lli, 0x%X", D, field_code_in, (long long)frame_num, + (long long)sample_num, whence); if (D->flags & GD_INVALID) {/* don't crash */ _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); Modified: trunk/getdata/src/getdata.c =================================================================== --- trunk/getdata/src/getdata.c 2012-03-07 04:48:00 UTC (rev 668) +++ trunk/getdata/src/getdata.c 2012-03-12 22:18:31 UTC (rev 669) @@ -159,7 +159,7 @@ { size_t i; - dtrace("%p, 0x%X, %lli, %zu", dataout, rtype, s0, n); + dtrace("%p, 0x%X, %lli, %zu", dataout, rtype, (long long)s0, n); switch (rtype) { case GD_INT8: @@ -258,7 +258,8 @@ char *databuffer; size_t zero_pad = 0; - dtrace("%p, %p, %lli, %zu, 0x%X, %p)", D, E, s0, ns, return_type, data_out); + dtrace("%p, %p, %lli, %zu, 0x%X, %p)", D, E, (long long)s0, ns, return_type, + data_out); if (s0 < E->EN(raw,spf) * D->fragment[E->fragment_index].frame_offset) zero_pad = E->EN(raw,spf) * D->fragment[E->fragment_index].frame_offset - @@ -962,8 +963,8 @@ const gd_type_t ntype = (return_type & GD_COMPLEX) ? GD_COMPLEX128 : GD_FLOAT64; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, return_type, - data_out); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + return_type, data_out); /* input field checks */ for (i = 0; i < E->EN(lincom,n_fields); ++i) { @@ -1096,8 +1097,8 @@ off64_t first_samp2; gd_type_t type2; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, return_type, - data_out); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + return_type, data_out); /* Check input fields */ if (_GD_BadInput(D, E, 0, 1)) { @@ -1191,8 +1192,8 @@ { size_t n_read; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, return_type, - data_out); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + return_type, data_out); /* Check input fields */ if (_GD_BadInput(D, E, 0, 1)) { @@ -1237,8 +1238,8 @@ off64_t first_samp2; gd_type_t type2; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, return_type, - data_out); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + return_type, data_out); /* Check input fields */ if (_GD_BadInput(D, E, 0, 1) || _GD_BadInput(D, E, 1, 1)) { @@ -1333,8 +1334,8 @@ const uint64_t mask = (E->EN(bit,numbits) == 64) ? 0xffffffffffffffffULL : ((uint64_t)1 << E->EN(bit,numbits)) - 1; - dtrace("%p, %p, %i, %lli, %zu, 0x%X, %p", D, E, is_signed, first_samp, - num_samp, return_type, data_out); + dtrace("%p, %p, %i, %lli, %zu, 0x%X, %p", D, E, is_signed, + (long long)first_samp, num_samp, return_type, data_out); if (_GD_BadInput(D, E, 0, 1)) { dreturn("%i", 0); @@ -1386,8 +1387,8 @@ { size_t n_read; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, return_type, - data_out); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + return_type, data_out); if (_GD_BadInput(D, E, 0, 1)) { dreturn("%i", 0); @@ -1410,8 +1411,8 @@ size_t n_read = 0; double* data_in; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, return_type, - data_out); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + return_type, data_out); if (E->e->u.linterp.table_len < 0) { _GD_ReadLinterpFile(D, E); @@ -1460,8 +1461,8 @@ { size_t n_read; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, return_type, - data_out); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + return_type, data_out); if (_GD_BadInput(D, E, 0, 1)) { dreturn("%i", 0); @@ -1506,8 +1507,8 @@ off64_t first_samp2; gd_type_t type2; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, return_type, - data_out); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + return_type, data_out); /* Check input fields */ if (_GD_BadInput(D, E, 0, 1)) { @@ -1612,8 +1613,8 @@ const size_t size = GD_SIZE(return_type); off64_t first_samp2; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, return_type, - data_out); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + return_type, data_out); /* Check input fields */ if (_GD_BadInput(D, E, 0, 1)) { @@ -1772,8 +1773,8 @@ { gd_type_t type; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first, len, return_type, - data_out); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first, len, + return_type, data_out); type = _GD_ConstType(D, E->EN(scalar,const_type)); _GD_ConvertType(D, (char *)E->e->u.scalar.d + first * GD_SIZE(type), type, @@ -1816,7 +1817,7 @@ int out_of_place = 0; dtrace("%p, %p(%s), %i, %lli, %zu, 0x%X, %p", D, E, E->field, repr, - first_samp, num_samp, return_type, data_out); + (long long)first_samp, num_samp, return_type, data_out); if (++D->recurse_level >= GD_MAX_RECURSE_LEVEL) { _GD_SetError(D, GD_E_RECURSE_LEVEL, GD_E_RECURSE_CODE, NULL, 0, E->field); @@ -1951,7 +1952,8 @@ gd_spf_t spf; dtrace("%p, \"%s\", %lli, %lli, %zu, %zu, 0x%X, %p", D, field_code_in, - first_frame, first_samp, num_frames, num_samp, return_type, data_out); + (long long)first_frame, (long long)first_samp, num_frames, num_samp, + return_type, data_out); if (D->flags & GD_INVALID) {/* don't crash */ _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); Modified: trunk/getdata/src/index.c =================================================================== --- trunk/getdata/src/index.c 2012-03-07 04:48:00 UTC (rev 668) +++ trunk/getdata/src/index.c 2012-03-12 22:18:31 UTC (rev 669) @@ -29,7 +29,7 @@ double sample = NAN; double data[2]; - dtrace("%p, %p, %i, %g, %lli, %i", D, E, repr, value, limit, eof); + dtrace("%p, %p, %i, %g, %lli, %i", D, E, repr, value, (long long)limit, eof); /* load data */ n = _GD_DoField(D, E, repr, limit - eof, 2, GD_FLOAT64, data); @@ -60,8 +60,8 @@ double low_v, high_v, field_start_v, c_v; size_t n; - dtrace("%p, %p, %i, %g, %lli, %lli", D, E, repr, value, field_start, - field_end); + dtrace("%p, %p, %i, %g, %lli, %lli", D, E, repr, value, + (long long)field_start, (long long)field_end); /* find the end-points */ n = _GD_DoField(D, E, repr, field_start, 1, GD_FLOAT64, &low_v); @@ -214,8 +214,8 @@ int repr = GD_REPR_NONE; gd_spf_t spf; - dtrace("%p, \"%s\", %g, %lli, %lli", D, field_code_in, value, field_start, - field_end); + dtrace("%p, \"%s\", %g, %lli, %lli", D, field_code_in, value, + (long long)field_start, (long long)field_end); if (D->flags & GD_INVALID) {/* don't crash */ _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); Modified: trunk/getdata/src/putdata.c =================================================================== --- trunk/getdata/src/putdata.c 2012-03-07 04:48:00 UTC (rev 668) +++ trunk/getdata/src/putdata.c 2012-03-12 22:18:31 UTC (rev 669) @@ -36,7 +36,8 @@ return 0; } - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, s0, ns, data_type, data_in); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)s0, ns, data_type, + data_in); if (s0 < D->fragment[E->fragment_index].frame_offset * E->EN(raw,spf)) { _GD_SetError(D, GD_E_RANGE, GD_E_OUT_OF_RANGE, NULL, 0, NULL); @@ -130,8 +131,8 @@ double *tmpbuf; struct _gd_lut *tmp_lut; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, data_type, - data_in); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + data_type, data_in); if (_GD_BadInput(D, E, 0, 1)) { dreturn("%i", 0); @@ -231,8 +232,8 @@ size_t n_wrote; void* tmpbuf; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, data_type, - data_in); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + data_type, data_in); /* we cannot write to LINCOM fields that are a linear combination */ /* of more than one raw field (no way to know how to split data). */ @@ -310,8 +311,8 @@ const uint64_t mask = (E->EN(bit,numbits) == 64) ? 0xffffffffffffffffULL : ((uint64_t)1 << E->EN(bit,numbits)) - 1; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, data_type, - data_in); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + data_type, data_in); if (_GD_BadInput(D, E, 0, 1)) { dreturn("%i", 0); @@ -365,8 +366,8 @@ { size_t n_wrote; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, data_type, - data_in); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + data_type, data_in); if (_GD_BadInput(D, E, 0, 1)) { dreturn("%i", 0); @@ -388,8 +389,8 @@ size_t n_wrote; void* tmpbuf; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, data_type, - data_in); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + data_type, data_in); if (_GD_BadInput(D, E, 0, 1)) { dreturn("%i", 0); @@ -434,8 +435,8 @@ size_t n_wrote; void* tmpbuf; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, data_type, - data_in); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + data_type, data_in); /* we cannot write to POLYNOM fields that are quadradic or higher order */ @@ -562,8 +563,8 @@ off64_t first_samp2; gd_spf_t spf1, spf2; - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first_samp, num_samp, data_type, - data_in); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first_samp, num_samp, + data_type, data_in); if (_GD_BadInput(D, E, 0, 1)) { dreturn("%i", 0); @@ -631,7 +632,8 @@ off64_t first, size_t len, gd_type_t data_type, const void *restrict data_in) { - dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, first, len, data_type, data_in); + dtrace("%p, %p, %lli, %zu, 0x%X, %p", D, E, (long long)first, len, data_type, + data_in); /* check protection */ if (D->fragment[E->fragment_index].protection & GD_PROTECT_FORMAT) @@ -688,8 +690,8 @@ { size_t n_wrote = 0; - dtrace("%p, %p, %i, %lli, %zu, 0x%X, %p", D, E, repr, first_samp, num_samp, - data_type, data_in); + dtrace("%p, %p, %i, %lli, %zu, 0x%X, %p", D, E, repr, (long long)first_samp, + num_samp, data_type, data_in); if (++D->recurse_level >= GD_MAX_RECURSE_LEVEL) { _GD_SetError(D, GD_E_RECURSE_LEVEL, GD_E_RECURSE_CODE, NULL, 0, E->field); @@ -784,7 +786,8 @@ gd_spf_t spf = 0; dtrace("%p, \"%s\", %lli, %lli, %zu, %zu, 0x%X, %p", D, field_code_in, - first_frame, first_samp, num_frames, num_samp, data_type, data_in); + (long long)first_frame, (long long)first_samp, num_frames, num_samp, + data_type, data_in); if (D->flags & GD_INVALID) {/* don't crash */ _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); Modified: trunk/getdata/src/sie.c =================================================================== --- trunk/getdata/src/sie.c 2012-03-07 04:48:00 UTC (rev 668) +++ trunk/getdata/src/sie.c 2012-03-12 22:18:31 UTC (rev 669) @@ -141,7 +141,7 @@ dtrace("%p, %llx, 0x%X, 0x%X", file, (long long)sample, data_type, mode); if (file->pos == sample) { - dreturn("%lli", sample); + dreturn("%lli", (long long)sample); return sample; } @@ -184,7 +184,7 @@ } file->pos = f->p = sample; - dreturn("%llx", f->p); + dreturn("%" PRIi64 , f->p); return (off64_t)(f->p); } @@ -283,7 +283,7 @@ return -1; } - dreturn("%llx", statbuf.st_size / size); + dreturn("%zi", (ssize_t)(statbuf.st_size / size)); return (ssize_t)(statbuf.st_size / size); } @@ -407,7 +407,10 @@ /* truncate the file if necessary */ if (rin < rout) - gd_truncate(fileno(f->fp), nrec - rout + rin); + if (gd_truncate(fileno(f->fp), nrec - rout + rin)) { + dreturn("%i", -1); + return -1; + } /* update the current record */ memcpy(f->d, (char *)p + (rin - 1) * size, size); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-07 04:48:10
|
Revision: 668 http://getdata.svn.sourceforge.net/getdata/?rev=668&view=rev Author: ketiltrout Date: 2012-03-07 04:48:00 +0000 (Wed, 07 Mar 2012) Log Message: ----------- Bug fixes, extra functionality, docs. Modified Paths: -------------- trunk/defile/Makefile.am trunk/defile/bin/cli.c trunk/defile/bin/rc.c trunk/defile/configure.ac trunk/defile/input/ascii.c trunk/defile/input/dirfile.c trunk/defile/lib/defile.h trunk/defile/lib/internal.h trunk/defile/lib/libdefile.c Added Paths: ----------- trunk/defile/doc/ trunk/defile/doc/Makefile.am trunk/defile/doc/defile-input.7 trunk/defile/doc/defile.1.in 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_bsearch.3 trunk/defile/doc/df_check_abort.3 trunk/defile/doc/df_field_in_input.3 trunk/defile/doc/df_init.3 trunk/defile/doc/df_input_name.3 trunk/defile/doc/df_nframes_allowed.3 trunk/defile/doc/df_on_abort.3 trunk/defile/doc/df_push_frame.3 trunk/defile/doc/df_ready.3 trunk/defile/doc/df_set_const.3 trunk/defile/doc/df_shell_expand.3 Modified: trunk/defile/Makefile.am =================================================================== --- trunk/defile/Makefile.am 2012-03-06 01:45:18 UTC (rev 667) +++ trunk/defile/Makefile.am 2012-03-07 04:48:00 UTC (rev 668) @@ -22,4 +22,4 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = lib bin input test +SUBDIRS = lib bin input doc test Modified: trunk/defile/bin/cli.c =================================================================== --- trunk/defile/bin/cli.c 2012-03-06 01:45:18 UTC (rev 667) +++ trunk/defile/bin/cli.c 2012-03-07 04:48:00 UTC (rev 668) @@ -92,23 +92,37 @@ #define SETULONG(x,y) SETSIMPLE(x,y,strtoul(config->argument, NULL, 0),,\ "%lu") +#define ABORT_DELAY 60000 /* sixty seconds; this is less than the maximum TCP + * round-trip timeout. Do we care? */ + +/* the very defile object */ +static struct df_defile the_defile; +struct df_defile *const df = &the_defile; + +/* state mutex */ +pthread_mutex_t state_mx = PTHREAD_MUTEX_INITIALIZER; + static void DF_SignalHandler(int sig) { if (!df->quiet) switch (sig) { case SIGHUP: - puts("Aborting due to hang up"); + puts("Aborting due to hang up."); break; case SIGINT: - puts("Aborting due to interruption"); + puts("Aborting due to interruption."); break; case SIGTERM: - puts("Aborting due to unexpected termination"); + puts("Aborting due to unexpected termination."); break; } - df->input_state = DF_ST_ABORT; - df->output_state = DF_ST_ABORT; + pthread_mutex_lock(&state_mx); + if (df->output_state != DF_ST_DONE && df->output_state != DF_ST_ERROR) + DF_OUTSTATE(ABORT); + if (df->input_state != DF_ST_DONE && df->input_state != DF_ST_ERROR) + DF_INSTATE(ABORT); + pthread_mutex_unlock(&state_mx); } static void *DF_Embiggen(void *old, size_t size) @@ -250,6 +264,10 @@ result = 4; lt_dlclose(lib); } + if (df->config.mode_flags & DF_MODE_DEBUG) { + fprintf(stderr, "defile: probing %s; result: %s\n", filename, + (result) ? "fail" : "pass"); + } } /* success, add it to the list */ @@ -469,46 +487,24 @@ /* 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; } -static int DF_FileToOFL(const char *name, int incl) -{ - abort(); - - return 0; -} - enum { - DF_WOPT_ADD = 1, - DF_WOPT_ADDFROM, - DF_WOPT_ASYNC, - DF_WOPT_AUTOTYPE, - DF_WOPT_BHEAD, - DF_WOPT_BLEN, - DF_WOPT_CLOBBER, - DF_WOPT_DEL, - DF_WOPT_DELFROM, - DF_WOPT_DIR, - DF_WOPT_GZIP, - DF_WOPT_INPUT, - DF_WOPT_LIBDIR, - DF_WOPT_LIST, - DF_WOPT_NOCLOBBER, - DF_WOPT_OFLCLR, - DF_WOPT_OUTPUT, - DF_WOPT_PERSIST, - DF_WOPT_QUIET, - DF_WOPT_SYNC, - DF_WOPT_TERMEOF, - DF_WOPT_VERBOSE, - DF_WOPT_TYPE, + DF_WOPT_ADD = 1, DF_WOPT_ASYNC, DF_WOPT_AUTOTYPE, DF_WOPT_BHEAD, DF_WOPT_BLEN, + DF_WOPT_CLOBBER, DF_WOPT_DEBUG, DF_WOPT_DEL, DF_WOPT_DIR, DF_WOPT_GZIP, + DF_WOPT_INPUT, DF_WOPT_LIBDIR, DF_WOPT_LIST, DF_WOPT_NOCLOBBER, + DF_WOPT_NODEBUG, DF_WOPT_NOFOLLOW, DF_WOPT_OFLCLR, DF_WOPT_OUTPUT, + DF_WOPT_FOLLOW, DF_WOPT_QUIET, DF_WOPT_SYNC, DF_WOPT_TYPE, DF_WOPT_VERBOSE }; -static int DF_OutputOpt(df_defiler df, struct df_rc_config *config, +static int DF_OutputOpt(struct df_defile *df, struct df_rc_config *config, struct df_rc_data *rcd) { int i; @@ -542,18 +538,12 @@ case DF_RC_MODE_SW: df->mode_switch = 1; break; - case DF_WOPT_ADD: /* -f */ + case DF_WOPT_ADD: /* -F */ DF_UpdateOFL(config->argument, 1); break; - case DF_WOPT_DEL: /* +f */ + case DF_WOPT_DEL: /* +F */ DF_UpdateOFL(config->argument, 0); break; - case DF_WOPT_ADDFROM: /* -F */ - DF_FileToOFL(config->argument, 1); - break; - case DF_WOPT_DELFROM: /* +F */ - DF_FileToOFL(config->argument, 0); - break; case DF_WOPT_OFLCLR: /* --reset-field-list */ for (i = 0; i < df->nofl; ++i) free(df->ofl[i]); @@ -577,7 +567,7 @@ SETULONG(BHEAD, bufhead); - SETULONG(BLEN, buflen); + SETULONG(BLEN, config.buflen); SETLINT(CLOBBER, clobber, 1); SETLINT(NOCLOBBER, clobber, 0); @@ -585,12 +575,15 @@ SETSTRING(DIR, dir); SETSTRING(OUTPUT, output); - SETBIT(PERSIST, config.mode_flags, DF_MODE_PERSIST); - CLRBIT(TERMEOF, config.mode_flags, DF_MODE_PERSIST); + SETBIT(FOLLOW, config.mode_flags, DF_MODE_FOLLOW); + CLRBIT(NOFOLLOW, config.mode_flags, DF_MODE_FOLLOW); SETLINT(QUIET, quiet, 1); SETLINT(VERBOSE, quiet, 0); + SETBIT(DEBUG, config.mode_flags, DF_MODE_DEBUG); + CLRBIT(NODEBUG, config.mode_flags, DF_MODE_DEBUG); + SETBIT(ASYNC, config.mode_flags, DF_MODE_ASYNC); CLRBIT(SYNC, config.mode_flags, DF_MODE_ASYNC); @@ -629,60 +622,152 @@ return ptr; } -static void DF_OutputFini(int delete) +static int DF_OutputFini(int delete) { gd_close(df->D); if (delete) { pid_t pid = fork(); + int status; + if (pid > 0) waitpid(pid, NULL, 0); else if (pid == 0) { execl(PATH_RM, PATH_RM, "-rf", df->output, (char*)NULL); + /* can't get here */ + fputs("defile: exec failure while deleting discarded output\n", stderr); exit(1); } + waitpid(pid, &status, 0); + if (!WIFEXITED(status) || WEXITSTATUS(status)) { + fputs("defile: error deleting discarded output\n", stderr); + return 1; + } } free(df->output); + + return 0; } -static void DF_CreateOutput(unsigned long flags) +static int DF_CreateOutput(unsigned long flags) { + int gderr; + df->flags = flags; df->D = gd_open(df->dirfile, GD_RDWR | GD_CREAT | ((flags & DF_CLOBBER) ? GD_TRUNC : GD_EXCL) | GD_VERBOSE); - if (gd_error(df->D)) { + if ((gderr = gd_error(df->D))) { char *err = gd_error_string(df->D, NULL, 0); fprintf(stderr, "defile: getdata error: %s\n", err); free(err); - DF_OutputFini(0); - exit(1); + if (gderr == GD_E_CREAT) { /* no clobber: allow the input to try again */ + pthread_mutex_lock(&state_mx); + DF_OUTSTATE(INIT); + pthread_mutex_unlock(&state_mx); + } else + return 1; } + + return 0; } -/* check thread status; returns zero when we're done */ -static int DF_ThreadCheck(df_defiler df) +/* check thread status; returns zero when defile's done */ +static int DF_ThreadCheck(struct df_defile *df, const struct timeval *time) { - /* error */ - if (df->input_state < 0 || df->output_state < 0) - return 0; + /* this will overflow in the year 294,247 (Y294k bug) */ + const long long now = time->tv_sec * 1000000 + time->tv_usec; /* done */ if (df->input_state == DF_ST_DONE && df->output_state == DF_ST_DONE) return 0; + /* abort the other on error */ + if (df->abort_timer == 0) { + pthread_mutex_lock(&state_mx); + if (df->input_state == DF_ST_ERROR) { + DF_INSTATE(DONE); + if (df->output_state != DF_ST_DONE && df->output_state != DF_ST_ERROR) + DF_OUTSTATE(ABORT); + } + if (df->output_state == DF_ST_ERROR) { + DF_OUTSTATE(DONE); + if (df->input_state != DF_ST_DONE && df->input_state != DF_ST_ERROR) + DF_INSTATE(ABORT); + } + + if (df->output_state == DF_ST_ABORT || df->input_state == DF_ST_ABORT) + df->abort_timer = now + ABORT_DELAY; + pthread_mutex_unlock(&state_mx); + } else if (df->abort_timer < now) { + if (df->output_state != DF_ST_DONE) { + fputs("defile: cancelling unresponsive output\n", stderr); + pthread_cancel(df->output_id); + } + if (df->input_state != DF_ST_DONE) { + fputs("defile: cancelling unresponsive input\n", stderr); + pthread_cancel(df->input_id); + } + return 0; + } + /* still going */ return 1; } /* wait while the input does something */ -static inline void DF_WaitWhileInputState(int state) +static inline void DF_WaitWhileInputStates(int state1, int state2, int quiet) { + if (!quiet && df->config.mode_flags & DF_MODE_DEBUG) + fprintf(stderr, "defile: output waiting on input for end of %s and %s\n", + DF_STATENAME(state1), DF_STATENAME(state2)); + while (df->input_state == state1 || df->input_state == state2) + usleep(10000); +} + +/* wait while the input does something */ +static inline void DF_WaitWhileInputState(int state, int quiet) +{ + if (!quiet && df->config.mode_flags & DF_MODE_DEBUG) + fprintf(stderr, "defile: output waiting on input for end of %s\n", + DF_STATENAME(state)); while (df->input_state == state) usleep(10000); } +static int DF_MakeOutput(void) +{ + /* figure out the name of the output */ + df->dirfile = DF_OutputName(df->dir, df->output, df->input); + + if (!df->dirfile) + return 1; + + if (DF_CreateOutput(df->clobber ? DF_CLOBBER : 0)) + return 1; + + if (df->output_state == DF_ST_ABORT) + return 1; + + /* signal we're ready for metadata */ + DF_OUTSTATE_MX(BUILD); + + /* wait for the input to build the dirfile */ + DF_WaitWhileInputStates(DF_ST_BUILD, DF_ST_INIT, 0); + + if (df->output_state == DF_ST_ABORT) + return 1; + + /* write metadata to disk */ + gd_metaflush(df->D); + + /* signal we're ready for data */ + DF_OUTSTATE_MX(RUN); + + return 0; +} + /* output thread */ static void *DF_OutputThread(void) { @@ -692,37 +777,52 @@ unsigned long in, out, nf; /* wait for the input to initialise */ - DF_WaitWhileInputState(DF_ST_STARTUP); + DF_WaitWhileInputState(DF_ST_START, 0); /* initialise the output */ - df->dirfile = DF_OutputName(df->dir, df->output, df->input); - if (!df->dirfile) - exit(1); + if (DF_MakeOutput()) { + DF_OUTSTATE_MX(ERROR); + return NULL; + } - DF_CreateOutput(df->clobber ? DF_CLOBBER : 0); - - /* signal we're ready for metadata */ - df->output_state = DF_ST_BUILDING; - - /* wait for the input to build the dirfile */ - DF_WaitWhileInputState(DF_ST_BUILDING); - - /* write metadata to disk */ - gd_metaflush(df->D); - - /* signal we're ready to for data */ - df->output_state = DF_ST_RUNNING; - /* loop through raws, writing ones that have full buffer heads */ while (!last_pass) { - if (df->input_state != DF_ST_RUNNING) + if (df->input_state != DF_ST_RUN) last_pass = 1; for (i = 0; i < df->nraw; ++i) { + /* check for unexpected state change */ + if (df->output_state != DF_ST_RUN) { + int delete = 0; + switch(df->output_state) { + case DF_ST_DROPSTART: + delete = 1; + /* fallthrough */ + case DF_ST_SAVESTART: + if (DF_OutputFini(delete)) { + DF_OUTSTATE_MX(ERROR); + return NULL; + } else if (DF_MakeOutput()) { + DF_OUTSTATE_MX(ERROR); + return NULL; + } + break; + case DF_ST_ABORT: + DF_OutputFini(0); + DF_OUTSTATE_MX(DONE); + return NULL; + default: + fputs("defile: unexpected traversal in output state map.\n", + stderr); + DF_OutputFini(0); + DF_OUTSTATE_MX(ERROR); + return NULL; + } + } r = df->raw + i; in = r->in; out = r->out; - nf = (in == out) ? df->buflen - 1 : + nf = (in == out) ? df->config.buflen - 1 : ((in + r->buflen - out) % r->buflen) / r->framesize - 1; if (nf == 0 || (!last_pass && nf <= df->bufhead)) @@ -759,13 +859,10 @@ /* bail on error */ if (gd_error(df->D)) { - df->output_state = DF_ST_ERROR; - exit(1); + DF_OUTSTATE_MX(ERROR); + return NULL; } - if (nwrote > 0) - last_pass = 0; - /* update ahead counts */ nf = nwrote / r->spf; if (i == df->ref_ind) { @@ -775,6 +872,20 @@ } else r->ahead += nwrote / r->spf; + if (nwrote > 0) { + last_pass = 0; + if (df->config.mode_flags & DF_MODE_DEBUG) { + if (i != df->ref_ind && !(df->config.mode_flags & DF_MODE_ASYNC)) + fprintf(stderr, "defile: output %lu %s of field %s " + "(lead is %lu %s)\n", + nf, (nf == 1) ? "frame" : "frames", r->name, r->ahead, + (r->ahead == 1) ? "frame" : "frames"); + else + fprintf(stderr, "defile: output %lu %s of field %s\n", nf, + (nf == 1) ? "frame" : "frames", r->name); + } + } + /* update write pointer */ r->out = (r->out + nwrote * GD_SIZE(r->type)) % r->buflen; @@ -789,23 +900,25 @@ } /* finished */ - gd_close(df->D); + DF_OutputFini(0); /* done */ - df->output_state = DF_ST_DONE; + DF_OUTSTATE_MX(DONE); return NULL; } /* input thread container. */ static void *DF_InputThread(void) { - int status; - /* Execute the input and wait for it to finish */ - status = df->input_framework->entry(&df->config); + int ret = df->input_framework->entry(&df->config); - /* report status */ - df->input_state = status ? DF_ST_ERROR : DF_ST_DONE; + pthread_mutex_lock(&state_mx); + if (ret) + DF_INSTATE(ERROR); + else + DF_INSTATE(DONE); + pthread_mutex_unlock(&state_mx); /* done */ return NULL; @@ -818,6 +931,8 @@ static unsigned long long lw = 0; static int init = 2; + const char eol = (df->config.mode_flags & DF_MODE_DEBUG) ? '\n' : '\r'; + double delta, drate; unsigned long long nf; const unsigned long long nw = df->nwrote; @@ -876,13 +991,11 @@ si = 'm'; } if (df->nframes > 0) - printf("R:[%llu(%llu) of %llu] W:[%llu(%llu)] %.*f %cHz \r", nr, - (unsigned long long)df->rpartial, df->nframes, nw, - (unsigned long long)df->wpartial, - (drate >= 100) ? 1 : (drate >= 10) ? 2 : 3, drate, si); + printf("R:[%llu of %llu] W:[%llu] %.*f %cHz %c", nr, df->nframes, nw, + (drate >= 100) ? 1 : (drate >= 10) ? 2 : 3, drate, si, eol); else - printf("R:[%llu] W:[%llu] %.*f %cHz \r", nr, nw, - (drate >= 100) ? 1 : (drate >= 10) ? 2 : 3, drate, si); + printf("R:[%llu] W:[%llu] %.*f %cHz %c", nr, nw, + (drate >= 100) ? 1 : (drate >= 10) ? 2 : 3, drate, si, eol); fflush(stdout); return rate; @@ -925,8 +1038,6 @@ int main(int argc, char **argv) { - pthread_t input_thread, output_thread; - /* rate stuff */ double rate; struct timeval then; @@ -937,77 +1048,45 @@ const struct df_optdef options[] = { { DF_WOPT_ASYNC, DF_OPT_NO_ARG, 'a', "asyncrhonous", "Asynchronous", 0, - NULL, - "allow field in the output dirfile to be written to disk independantly " - "of each other; for some input types, this can greatly increase the " - "efficiency of the conversion" + NULL, "operate in asynchronous mode" }, { DF_WOPT_SYNC, DF_OPT_NO_ARG, 'a', "synchronous", "Synchronous", - DF_OPT_PLUS, NULL, - "ensure that the output dirfile's reference field never has more data " - "any other raw field (the default behaviour)" + DF_OPT_PLUS, NULL, "operate in synchronous mode" }, { DF_WOPT_CLOBBER, DF_OPT_NO_ARG, 0, "clobber", "Clobber", 0, NULL, - "if the output dirfile already exists, overwrite it; this will delete " - "every regular file in the target directory; use with caution" + "if the output dirfile already exists, overwrite it; use with caution" }, { DF_WOPT_NOCLOBBER, DF_OPT_NO_ARG, 0, "no-clobber", "NoClobber", 0, NULL, - "don't overwrite an existing dirfile (the default behaviour)" + "don't overwrite an existing dirfile (default)" }, - { DF_WOPT_DIR, DF_OPT_ARG_RQ, 'd', "directory", "Directory", DF_OPT_EXPAND, - "DIR", - "if -o is not specified, create the output dirfile as a subdirectory " - "under DIR, with a name based on the name of the input file; if -o is " - "used, but does not specify an absolute path, create the specified " - "output dirfile under DIR; if -o specifies an absolute path, this " - "option is ignored" + { DF_WOPT_DIR, DF_OPT_ARG_RQ, 'D', "directory", "Directory", DF_OPT_EXPAND, + "DIR", "write the output dirfile as a subdirectory under DIR" }, - { DF_WOPT_ADD, DF_OPT_ARG_RQ, 'f', "include", "WriteField", 0, "FIELD", - "add FIELD to the output field list; this option may be given multiple " - "times to build up a list of fields to include, and may be used in " - "conjunction with -F; however, mixing -[fF] with +[fF] may not work as " - "expected; inserting --reset-field-list before switching from -[fF] to " - "+[fF] is recommended" + { DF_WOPT_DEBUG, DF_OPT_NO_ARG, 'd', "debug", "Debug", 0, NULL, + "print debugging messages" }, - { DF_WOPT_DEL, DF_OPT_ARG_RQ, 'f', "exclude", "IgnoreField", DF_OPT_PLUS, - "FIELD", - "remove FIELD from the output field list; this option may be given " - "multiple times to build up a list of fields to exclude, and may be " - "used in conjunction with +F; however, mixing +[fF] with -[fF] may not " - "work as expected; inserting --reset-field-list before switching from " - "+[fF] to -[fF] is recommended" + { DF_WOPT_NODEBUG, DF_OPT_NO_ARG, 'd', "no-debug", "NoDebug", DF_OPT_PLUS, + NULL, "suppress printing debugging messages (default)" }, - { DF_WOPT_ADDFROM, DF_OPT_ARG_RQ, 'F', "include-from", "WriteAllFrom", - DF_OPT_EXPAND, "FILE", - "add all fields given in FILE (one field name per line) to the output " - "field list; this option may be given multiple times; see -f for " - "caveats concerning combinding this option with +f or +F" + { DF_WOPT_ADD, DF_OPT_ARG_RQ, 'F', "include", "IncludeField", 0, "FIELD", + "include FIELD in the output dirfile, if available" }, - { DF_WOPT_DELFROM, DF_OPT_ARG_RQ, 'F', "exclude-from", "IgnoreAllFrom", - DF_OPT_PLUS | DF_OPT_EXPAND, "FILE", - "remove all fields given in FILE (one field name per line) from the " - "output field list; this option may be given multiple times; see +f " - "for caveats concerning combinding this option with -f or -F" + { DF_WOPT_DEL, DF_OPT_ARG_RQ, 'F', "exclude", "ExcludeField", DF_OPT_PLUS, + "FIELD", "exclude FIELD from the output dirfile" }, { DF_WOPT_BHEAD, DF_OPT_ARG_RQ, 'h', "buf-head", "BufferHead", 0, "N", - "set the length of the output buffer head to N frames; defile waits for " - "the buffer head to fill up before writing the accumulated buffer to " - "disk; the default value is zero, meaning data are written as soon as " - "possible; setting this to a non-zero number may improve performance, " - "at the cost of latency and memory usage; see also -l below" + "set the length of the output buffer head to N frames; the default " + "value is zero" }, - { DF_WOPT_INPUT, DF_OPT_ARG_RQ, 'i', "input", "Input", 0, "PATH", - "read input data from PATH; typically the input PATH can be specified as " + { DF_WOPT_INPUT, DF_OPT_ARG_RQ, 'i', "input", "Input", 0, "NAME", + "read input data from NAME; typically the NAME can be specified as " "a bare argument, without the need for -i; this option is provided " - "only for use in situations where PATH begins with - or + (and would, " + "only for use in situations where NAME begins with - or + (and would, " "therefore, be mistaken for an option)" }, { DF_WOPT_BLEN, DF_OPT_ARG_RQ, 'l', "buf-len", "BufferLen", 0, "N", "set the length of the output buffer to N frames; the default value " - "is " DF_STRINGIFY(DF_BUFLEN) " frames; decreasing this will reduce " - "memory usage at the expense of performance; if this is smaller than " - "the buffer header (see -h above), the output buffer will be expanded " - "to accommodate it" + "is " DF_STRINGIFY(DF_BUFLEN) "" }, { DF_WOPT_LIBDIR, DF_OPT_NO_ARG, 0, "lib-dir", NULL, 0, NULL, "print the default input plugin path and exit" @@ -1015,25 +1094,20 @@ { DF_WOPT_LIST, DF_OPT_NO_ARG, 0, "list-types", NULL, 0, NULL, "print a list of available input plugins and exit" }, - { DF_WOPT_OFLCLR, DF_OPT_NO_ARG, 0, "reset-field-list", "ResetFieldList", 0, + { DF_WOPT_OFLCLR, DF_OPT_NO_ARG, 0, "clear-field-list", "ClearFieldList", 0, NULL, - "ignore all previous options which modifiy the ouput field list (-f, +f, " - "-F, +F); this is typically not needed, but can be used if the current " - "contents of the output field list is unknown" + "ignore all previous options which modifiy the ouput field list (-F, +F)" }, { DF_WOPT_OUTPUT, DF_OPT_ARG_RQ, 'o', "output", "Output", DF_OPT_EXPAND, - "PATH", "write data to a dirfile called PATH; if PATH is relative, it is " - "created relative the current directory, unless -d is also specified" + "PATH", "write data to a dirfile called PATH" }, - { DF_WOPT_PERSIST, DF_OPT_NO_ARG, 'p', "persistent", "Persistent", 0, NULL, - "upon reaching the end of the input, do not exit, but monitor the input " - "for additional data, and keep writing to the output as new data " - "appears; implies -s" + { DF_WOPT_FOLLOW, DF_OPT_NO_ARG, 'f', "follow", "Follow", 0, NULL, + "keep monitoring the input and write data to the outpu as it becomes " + "available" }, - { DF_WOPT_TERMEOF, DF_OPT_NO_ARG, 'p', "terminate-on-eof", "TerminateOnEOF", + { DF_WOPT_NOFOLLOW, DF_OPT_NO_ARG, 'f', "no-follow", "NoFollow", DF_OPT_PLUS, NULL, - "finalise the output and exit upon reaching the end of the input (the " - "default behaviour)" + "exit successfully upon reaching the end of the input (default)" }, { DF_WOPT_QUIET, DF_OPT_NO_ARG, 'q', "quiet", "Quiet", 0, NULL, "be less verbose" @@ -1047,10 +1121,10 @@ { DF_WOPT_AUTOTYPE, DF_OPT_NO_ARG, 't', "autotype", "AutoType", DF_OPT_PLUS, NULL, "attempt to automatically determine the data type of the input" }, - { DF_WOPT_GZIP, DF_OPT_NO_ARG, 'z', "gzip", "GZip", 0, NULL, - "gzip compress the output raw data" - }, - { DF_OPT_ENDOPT } + // { DF_WOPT_GZIP, DF_OPT_NO_ARG, 'z', "gzip", "GZip", 0, NULL, + // "gzip compress the output raw data" + // }, + DF_OPT_ENDOPT }; struct df_rc_data rcd = { @@ -1073,7 +1147,7 @@ df->iargv = malloc(sizeof(char*)); df->iargv[0] = argv[0]; df->iargc = 1; - df->buflen = DF_BUFLEN; + df->config.buflen = DF_BUFLEN; /* initialise LTDL and register its cleanup function */ lt_dlinit(); @@ -1082,8 +1156,8 @@ DF_Parse(argc, argv, &rcd, df); /* sanitise */ - if (df->buflen < df->bufhead) - df->buflen = df->bufhead; + if (df->config.buflen < df->bufhead) + df->config.buflen = df->bufhead; if (!df->quiet) puts(PACKAGE_STRING " " DEFILE_COPYRIGHT); @@ -1137,8 +1211,9 @@ pthread_sigmask(SIG_BLOCK, &signals, NULL); /* start the threads */ - df->input_state = DF_ST_STARTUP; - if (pthread_create(&input_thread, NULL, (void*(*)(void*))DF_InputThread, + DF_INSTATE(START); + DF_OUTSTATE(START); + if (pthread_create(&df->input_id, NULL, (void*(*)(void*))DF_InputThread, NULL)) { perror("pthread_create"); @@ -1146,8 +1221,7 @@ } /* start the output thread */ - df->output_state = DF_ST_STARTUP; - if (pthread_create(&output_thread, NULL, (void*(*)(void*))DF_OutputThread, + if (pthread_create(&df->output_id, NULL, (void*(*)(void*))DF_OutputThread, NULL)) { perror("pthread_create"); @@ -1158,8 +1232,8 @@ pthread_sigmask(SIG_UNBLOCK, &signals, NULL); /* wait until the initialisation is done */ - DF_WaitWhileInputState(DF_ST_STARTUP); - DF_WaitWhileInputState(DF_ST_BUILDING); + DF_WaitWhileInputState(DF_ST_START, 1); + DF_WaitWhileInputState(DF_ST_BUILD, 1); /* record our "start" time */ gettimeofday(&then, &tz); @@ -1167,18 +1241,21 @@ /* status loop */ df->tc = 1.; - while (DF_ThreadCheck(df)) { + do { /* print the status line, if necessary */ rate = DF_PrintRate(&then, rate); usleep(500000); /* ~2Hz refresh rate */ - } + } while (DF_ThreadCheck(df, &then)); DF_PrintRate(&then, rate); if (!df->quiet) putchar('\n'); - pthread_join(input_thread, NULL); - pthread_join(output_thread, NULL); + /* one last check */ + if (pthread_kill(df->input_id, 0) == 0) + fputs("defile: terminating with input still active!\n", stderr); + if (pthread_kill(df->output_id, 0) == 0) + fputs("defile: terminating with output still active!\n", stderr); return 0; } Modified: trunk/defile/bin/rc.c =================================================================== --- trunk/defile/bin/rc.c 2012-03-06 01:45:18 UTC (rev 667) +++ trunk/defile/bin/rc.c 2012-03-07 04:48:00 UTC (rev 668) @@ -63,7 +63,7 @@ "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA" static const struct df_optdef df_no_opts[] = { - { DF_OPT_ENDOPT } + DF_OPT_ENDOPT }; struct shortarg_s { @@ -348,6 +348,21 @@ } } +static void DF_DoRunControl (const char *val, const char *cwd, + struct df_rc_data *rcd) +{ + if (val == NULL) + logprintf(" Skipping unspecified configuration file.\n"); + else { + char file[4096]; + if (val[0] != '/' && val[0] != '~' && val[0] != '$') + snprintf(file, 4096, "%s/%s", cwd, val); + else + strcpy(file, val); + DF_ReadConfigFile(file, 0, val, rcd); + } +} + static void DF_PushConfig(int i, const char* val, int error, int no_dup, const char* cwd, const char* label, int line, int sopt, struct df_rc_data *rcd) @@ -361,22 +376,16 @@ rcd->options[i].value, rcd->confc, line); if (opt) { if (opt->type == DF_OPT_CONFIG) { - if (val == NULL) - logprintf(" Skipping unspecified configuration file.\n"); - else { - char file[4096]; - if (val[0] != '/' && val[0] != '~' && val[0] != '$') - snprintf(file, 4096, "%s/%s", cwd, val); - else - strcpy(file, val); - DF_ReadConfigFile(file, 0, val, rcd); - } + DF_DoRunControl(val, cwd, rcd); return; } if (val && opt->flags & DF_OPT_EXPAND) { - val = df_shell_expand(val); - no_dup = 1; + char *expanded = df_shell_expand(val); + if (expanded) { + val = expanded; + no_dup = 1; + } } } @@ -421,6 +430,14 @@ /* expand */ file = df_shell_expand(name); + if (file == NULL) { + if (skip_ok) + return; + + fprintf(stderr, "Could not read %s: %s\n", file, strerror(errno)); + exit(1); + } + strcpy(cwd, dirname(file)); free(file); file = df_shell_expand(name); @@ -472,6 +489,12 @@ logprintf(" Found directive `%s' with argument `%s' on line %i\n", opt, val, ln); + /* Include */ + if (strcasecmp(opt, "Include") == 0) { + DF_DoRunControl(val, cwd, rcd); + continue; + } + /* match directive */ found = 0; for (i = 0; rcd->options[i].type != DF_OPT_END_OO; ++i) @@ -620,6 +643,12 @@ DF_Version(rcd, argv[0]); } + /* conf */ + if (strcmp(&argv[i][2], "conf") == 0) { + DF_DoRunControl(value, ".", rcd); + continue; + } + /* match long option */ found = 0; for (k = 0; rcd->options[k].type != DF_OPT_END_OO; ++k) { Modified: trunk/defile/configure.ac =================================================================== --- trunk/defile/configure.ac 2012-03-06 01:45:18 UTC (rev 667) +++ trunk/defile/configure.ac 2012-03-07 04:48:00 UTC (rev 668) @@ -165,11 +165,29 @@ dnl` fi +dnl Calculate a few absolute directory paths (needed by the man pages) +cat <<EOF > conftest.sh +prefix=$prefix +test "x$prefix" = xNONE && prefix=$ac_default_prefix +exec_prefix=$exec_prefix +test "x$exec_prefix" = xNONE && exec_prefix=\$prefix +moduledir=$moduledir +PACKAGE_TARNAME=$PACKAGE_TARNAME +echo absolute_moduledir=$moduledir +echo absolute_sysconfdir=$sysconfdir +EOF + +eval `$SHELL conftest.sh` +AC_SUBST([absolute_moduledir]) +AC_SUBST([absolute_sysconfdir]) + echo echo "*** Writing configure output" echo AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([bin/Makefile]) +AC_CONFIG_FILES([doc/Makefile]) +AC_CONFIG_FILES([doc/defile.1]) AC_CONFIG_FILES([input/Makefile]) AC_CONFIG_FILES([lib/Makefile]) AC_CONFIG_FILES([test/Makefile]) Added: trunk/defile/doc/Makefile.am =================================================================== --- trunk/defile/doc/Makefile.am (rev 0) +++ trunk/defile/doc/Makefile.am 2012-03-07 04:48:00 UTC (rev 668) @@ -0,0 +1,24 @@ +# (C) 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 +# +AUTOMAKE_OPTIONS = foreign + +man_MANS = defile.1 df_bsearch.3 df_check_abort.3 df_field_in_input.3 \ + df_init.3 df_on_abort.3 defile-input.7 Added: trunk/defile/doc/defile-input.7 =================================================================== --- trunk/defile/doc/defile-input.7 (rev 0) +++ trunk/defile/doc/defile-input.7 2012-03-07 04:48:00 UTC (rev 668) @@ -0,0 +1,751 @@ +.\" defile.7. The defile input plugin 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 defile-input 7 "21 February 2012" "Version 0.1.0" DEFILE +.SH NAME +defile-input \(em overview of the defile input plugin API +.SH DESCRIPTION +This manual page describes how to write input plugins for defile(1), a program +which can convert data sources in a variety of formats into dirfile(5) +databases. + +Defile consists of three parts: a front\-end, which handles I/O with the +controlling terminal, including parsing of the command-line and associated +configuration files, the dirfile writer (the back\-end), which writes data to +the output dirfile, and the input plugin (the middle\-end?) which reads from the +input data source and provides data to the back\-end. + +Input plugins are loaded at runtime, based on options given to defile at the +time of invocation. See defile(1) for information on invoking defile. Because +the input plugin is loaded dynamically, input types available to defile(1) can +be extended easily, without having to modify defile itself. + +Defile provides a C API for input plugins. Functions provided by the API are +described in individual manual pages in section 3 of the manual. A list of +these is given below in the +.B API REFERENCE +section. The API is defined in the C header file <defile.h>. This document +provides an overview to the environment in which the input plugin runs and other +design considerations. For an outline of how an input plugin should operate, +see +.B DEFILE OPERATION +below. + +An input plugin is a dynamically loaded shared library which reads data from a +data source and passes it on to defile for output as a dirfile. Each input +plugin is identified by it's type name. The type name identifies the type of +data the input plugin is capable of reading. The type name should consist of +one or more lower case letters, numbers, or the underscore (_) character. The +type name must be unique among all defile input plugins: defile will only ever +consider the first input plugin with a given type name that it finds. + +The name of the shared library must be of the form: +.IP +.fam C +[\fIanything\fR]\fBdefile-<\fItype\fR>[\fI.ext\fR] +.fam +.PP +where +.I anything +is optional and may contain any valid filename characters (the host platform +may require a certain prefix for native dynamically loadable modules), +.B defile- +is literaly "defile" followed by a dash, +.I type +is the input type name, and +.I .ext +is a file extension appropriate for native dynamically loadable modules on the +host platform, if any. +.PP +The type name is also the value of the +.B \-\-type +option given to defile(1) to indicate which input plugin to use. + +.SH EXPORTED SYMBOLS + +The input plugin should export exactly one symbol: +.IP +.fam C +\fBextern const struct\fR df_input_framework <\fItype\fR>_framework; +.fam +.PP +where +.I type +is the input type name. The struct df_input_framework is defined in defile.h +as: +.IP +.nf +.fam C +struct df_input_framework { + const char *name; + const char *version; + const char *copyright; + const char *contact; + const char *description; + const char *preamble; + const char *postamble; + const struct df_optdef *opts; + int licence; + int (*probe)(const char*); + int (*entry)(const struct df_config*); +}; +.fam +.fi +.PP +where: +.TP +.I name +is the type name of the plugin. Defile will consider the module malformed and +ignore it if this is not identical to the type name used in both the exported +df_input_framework symbol, and the filename of the module itself. +.TP +.I version +a version string for the plugin, typically a verison triplet of the form +"XX.YY.ZZ", +.TP +.I copyright +is a copyright string for the plugin, typically of the form +"Copyright \(co <date> <author(s)>". (The non-ASCII \(co is typically +approximated by "(C)".) +.TP +.IR contact ", " preamble ", and " postamble +are formatted strings used in the usage or version information output to the +controlling terminal when requested. See the +.B HELP AND VERSION OUTPUT +section below. +.TP +.I description +is a short string describing the data type read by the plugin (not describing +the plugin itself). This is included when lists of input plugins are printed +by defile(1) (ie., if the +.B \-\-list\-types +option was given, or when automatic input type detection returns more than one +candidate input type). +.TP +.I opts +is the list of input options (and directives) supported by the module. This is +described in detail in the +.B INPUT OPTIONS +section below. +.TP +.I licence +indicates the licence type of the plugin. It affects what license boilerplate +(if any) is printed along with version information. See the +.B HELP AND VERSION OUTPUT +section below for details. +.TP +.I probe +is a function entry point which will be called during automatic type detection. +See the +.B AUTOMATIC TYPE DETECTION +section below for details. +.TP +.I entry +is the function entry point for the input plugin's main loop, which will be +called when defile conversion begins. See the +.B DEFILE OPERATION +section below. +.PP +All of the above members except for +.IR entry +are optional. If unneeded, they should be set to zero. + +.SH INPUT OPTIONS + +The input plugin may declare input options and directives which defile will +parse for it using the +.I opts +member of the framework. If the input plugin has none, this may simply be NULL. + +Defile treats input options and directives together. In the following, whenever +we refer input options, the remarks apply equally to input directives unless +otherwise stated. + +The +.I opts +member should be an array of elements of type struct df_optdef, which is defined +in defile.h as: +.IP +.nf +.fam C +struct df_optdef { + int value; + int type; + char sopt; + const char *lopt; + const char *directive; + unsigned int flags; + const char *argname; + const char *usage; +}; +.fam +.fi +.PP +where +.TP +.I value +is a positive number used by defile to indentify the option. Bare arguments +among the input options (those not associated with an option) are assigned a +value of zero, so that should be avoided in the definition of input options. +Unless two options should be treated as identical, each option should have a +unique value. There is no requirement that consequitive values be used. +After parsing the input options, defile will present the input plugin an array +of (value, argument) pairs. See the +.B Start State +subsection under +.B DEFILE OPTERATION +for information on how the value is used. Negative values are used internally +by defile for bookkeeping purposes and should be avoided. +.TP +.I type +should be one of the following symbols inidcating the type of option: +.RS +.TP +.B DF_OPT_NO_ARG +an option which takes no argument +.TP +.B DF_OPT_ARG_OP +an option which takes an optional argument +.TP +.B DF_OPT_ARG_RQ +an option which requires an argument +.RE +.TP +.I sopt +a character giving the name of the short (one character) command-line option +which matches this option record. This should be a lower or upper-case letter +(case is significant). If no short option is defined, this should be zero. +.TP +.I lopt +a character string giving the name of the long command-line option (excluding +the initial double dash) which matches this option record. If no long option is +defined, this should be NULL. +.TP +.I directive +a character string giving the name of the run control directive which matches +this option record. If no directive is defined, this should be NULL. +.TP +.I flags +either zero, or else one or more of the following flags providing further +information on how the option should be interpreted: +.RS +.TP +.B DF_OPT_EXPAND +the argument to the option should be shell expanded before being given to the +input plugin. This is typically useful for options which take filenames as +arguments. If the option is of type +.BR DF_OPT_NO_ARG , +this flag is ignored. +.TP +.B DF_OPT_PLUS +if +.I sopt +is, say, +.BR x , +the short option +.B +x +will match this option record instead of the standard +.B -x +on the command line. If +.I sopt +is zero (inidcating no short option is associated with this record) this flag +is ignored. +.RE +.TP +.I argname +the placeholder name of the argument used in usage output. For stylistic +consitency, it is recommended this consist of upper case letters only. If the +option is of type +.BR DF_OPT_NO_ARG , +this value is ignored and may be NULL. Otherwise, if this is NULL, a default +value of "ARG" is used. +.TP +.I usage +an unformated string explaining the argument. The strig will be used in the +usage output (see the +.B HELP AND VERSION OUTPUT +section below). It should contain no newlines; they will be inserted where +appropriate by defile. For stylistic consistency, it is recommended this begin +with a lower case letter, and have independent clauses separated by semicolons. +If this option record specifies neither +.I sopt +nor +.I lopt +but only a directive, this is ignored and may be NULL. +.PP +No requirements are put on the ordering of the +.I opts +array. The array should be terminated by the +.B DF_OPT_ENDOPT +macro, which inserts a properly formated record indicating the end of the option +list. + +Three long options and one directive are diverted by defile and should be +avoided in the input option list (since they will never be matched). These are +.BR \-\-help , +.BR \-\-version , +and +.BR \-\-conf , +and the directive +.B Input +which are handled specially, as they are in the defile options. See defile(1) +for their use. Even if an input plugin provides no input options (by setting +.I opts +to zero, these are always accepted as input options by defile. Briefly, +.B \-\-help +and +.B \-\-version +result in the output of help or version information (see +.B HELP AND VERSION OUTPUT +below) while +.B \-\-conf +and +.B Include +specify additional run control files to read for more configuration (see +defile(1)). + +.SH HELP AND VERSION OUTPUT + +When +.B \-\-help +is found among the input options, defile generates a usage text for the input +plugin based on the information provided and writes it on standard output, and +then exits succesfully. This usage text consists of, in order: +.IP \(bu +the name, version and copyright string of the module, +.IP \(bu +the +.I preamble +string given in the framework definition, if any, +.IP \(bu +an alphabetised and formatted list of the input options, including their usage +strings, generated from the input option list given in the framework +definiition, +.IP \(bu +the +.I postamble +string given in the framework definition, if any. +.PP +Unless the plugin is simple enough to be summarised in the usage text, plugin +developers are encouraged to provide an accompanying Unix manual page called +defile-<\fItype\fR>(1). Other documentation, if any, should be mentioned in the +usage preamble or postamble. +.PP +When +.B \-\-version +is found among the input options, defile generates a version and licensing text +for the input plugin based on information provided and writes it on standard +output, and then exits successfully. The version and licensing text consists +of, in order: +.IP \(bu +the name, version and copyright string of the module, +.IP \(bu +the +.I contact +string given in the framework definition, if any, +.IP \(bu +an optional licensing boilerplate text, chosen based on the value of +.IR licence , +which should be one of the symbols: +.RS +.TP +.BR DF_LICENCE_OTHER " (=0)" +indicating no boilerplate text should be written. In this case, it is assumed +that the +.I contact +string output just previously contains the licensing information. +.TP +.B DF_LICENCE_SAME +prints a boilerplate indicating that the plugin is distributed under the same +terms as defile itself (whatever that might be), and explains how to find +defile's own licensing terms, +.TP +.B DF_LICENCE_GPL +prints the standard licensing boilerplate text for the GNU General Public +License version 2 or later, +.TP +.B DF_LICENCE_LGPL +prints the standard licensing boilerplate text for the GNU Lesser General +Public License version 2.1 or later. +.PP +This feature is purely provided as a convenience to the plugin writer, and is +not meant to restrict the licensing choice of the developer. (The licence of +the input plugin must still comply with Defile's own terms.) + +.SH DEFILE OPERATION + +Reading (by the input plugin) and writing (by defile itself) of converted data +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 +available in each state is provided below in the +.B API REFERNCE +section. We now discuss basic operation of defile. + +During the course of a normal, successful conversion, defile will move through +the following four states: +.BR START ", " BUILD ", " RUN ", " DONE . +One other exceptional state exists: +.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 +that the input plugin completed normally (success). Returning any other value +indicates that the input plugin encountered an unrecoverable error (failure). + +.SS START State + +Defile begins in the +.B START +state. In this state, defile starts by processing the defile options. It +then determines the input plugin type to use, either as a result of an explicit +type specified by the user, or else by using automatic type detection on the +specified input (see +.B AUTOMATIC TYPE DETECTION +for information on how to get an input plugin to participate in this). +The input plugin is then loaded, and the input options are processed based on +the data provided in the input framework definition. + +Once this has completed successfully, both the reader (input plugin) and +output (dirfile writer) are started. The reader is started by calling the +.I entry +procedure defined in the input plugin's framework definition. The input plugin +will be passed a struct df_config pointer which provides the input plugin with +it's parsed configuration, and a few other important pieces of opterational +information. The struct df_config is defined as: +.IP +.nf +.fam C +struct df_config { + unsigned int mode_flags; + int n_config; + int *value; + const char **arg; +}; +.fam +.fi +.PP +where +.TP +.I mode_flags +a bitwise or'd collection of zero or more of the following flags, indicating +defile's operational mode: +.RS +.TP +.B DF_MODE_ASYNC +defile is operating in asynchronous mode and the input plugin is not required to +adhere to the restrictions of synchronous mode. (See the +.B RUN State +section below for a discussion of the implications of synchronous and +asynchronous modes.) An input plugin is not required to implement asynchronous +mode. (Implementing synchronous mode \fIis\fR required.) +.TP +.B DF_MODE_DEBUG +defile is operating in debug mode and is printing extra debugging messages on +standard error. This does not affect the operation of defile, but this flag may +be used by the input plugin to decide when to emit its own debugging messages. +Otherwise, it may be safely ignored by input plugins. +.TP +.B DF_MODE_FOLLOW +defile is operating in follow mode and requests the input plugin to continue +to monitor the input data source when it reaches the end, providing additional +data to defile as it appears. An input plugin is not required to implement +follow mode and, so, may exit upon running out of data regardless of this flag. +.RE +.TP +.I n_config +the number of elements in the configuration produced by parsing the input +options and input directives. +.TP +.I value +an array of integers of length +.I n_config +containing the values (see +.B INPUT OPTIONS above) +of the input options in the order they were encountered. Bare arguments +encountered (arguments which are not associated with an option) will have a +value of zero. Other options will have the corresponding value that was +specified in the options array in the framework definition. +.TP +.I arg +an array of character strings of length +.I n_config +containing the argument to each option (if any), or else NULL, if the option +had no argument. +.PP +During +.B STARTUP +the input plugin should perform initialisation, parse the input string +(obtainable from +.BR df_input_name (3)) +and verify that the data type of the input is understood by the plugin. Once +it is ready to proceed, it should call +.BR df_init (3), +which triggers the transition into the +.B BUILD +state. + +.SS BUILD State +The +.B BUILD +state is when the metadata of the output dirfile is generated. The input plugin +is required to define at least one subframe (via the +.BR df_add_framedef (3) +call) which describes the raw data in the data objects which the input plugin +uses to communicate with defile. It may also add derived channels to the output +dirfile using +.BR df_add_entry (3). +(See also the +.B DEFILE DATA MODEL +section below for an overview of how defile expects data to be marshalled.) + +When it has finished creating the output dirfile's metadata, it should call +.BR df_ready (3), +which triggers the transition into the +.B RUN +state. + +.SS RUN State +The +.B RUN +state is when data frames are read by the input plugin, transferred to the +dirfile writer, and written to disk. Typically defile will spend the bulk of +it's time in this state. + +The input plugin provides data to the dirfile writer by calling +.BR df_push_frame (3), +typically multiple times. (See also the +.B DEFILE DATA MODEL +section below for an overview of how defile expects data to be marshalled.) + +The +.B RUN +state operates in one of two modes. In +.IR "asynchronous mode" , +no restrictions are placed on the order of subframe data transferred to the +defile buffer, and data are written to the output dirfile as they become +available. In +.IR "syncrhonous mode" , +two restrictions are placed on the order in which data are written. First, the +reference field will never have more frames written to it than any other field, +and second, no other field may get more than one buffer length ahead of the +reference. If the input plugin is not careful about the order in which +subframes are pushed in synchronous mode, deadlock may result. See the +.B DEFILE DATA MODEL +section below. To avoid deadlock the input plugin should provide reference +field data regularly. + +The input plugin may trigger a return to the +.B BUILD +state by calling +.BR gd_reinit (3). +Otherwise, defile remains in the +.B RUN +state as long as the input plugin is running. The plugin returning success +(zero) will signal transition into the +.B DONE +state. + +.SS DONE State + +The input plugin does not participate in the +.B DONE +state, which is where defile finalises the output dirfile and terminates. + +The input plugin may itself trigger transition into this state by returning +success (zero) at any time. + +.SS ABORT State + +Defile enters the +.B ABORT +state in cases when an unrecoverable, catastrophic error occurs during +operation, or else when it receives an asynchronous request to cancel (for +example a keyboard interrupt). Most of the C 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 +detect an unexpected transition into the +.B ABORT +state. + +During the +.B ABORT +state, the input plugin is given a short amount of time to cleanly shutdown. If +it takes too long, it will be cancelled (see +.B Cancellation +below). The plugin should release all dynamically allocated resources and close +all open files and then return success (zero), unless an error occurred during +shutdown, in which case returning failure (non-zero) may be more appropriate. + +Handling the +.B ABORT +state may be automated by defining an abort handler using +.BR df_on_abort (3). +If the input plugin defines an abort handler, API functions which would have +returned +.B DF_ABORT +will instead call the handler and then cause the thread to exit. The abort +handler will be passed no arguments and should return an int (which would have +been the value returned by the input main loop). + +The input plugin may itself trigger transition into this state by returning +failure (non-zero) at any time. + +.SH DEFILE DATA MODEL +The defile data model is fundamentally rooted in limitations of the Dirfile +Standards (see dirfile(5)). The primarly limitation this imposes on data +presented by an input plugin to defile is that data are composed of +.I frames +of synchronously sampled data of fixed format. Every frame in the output +dirfile must contain one or more samples of every raw field in the dirfile. +For each field, the number of samples per frame is constant, but different +fields may have different number of samples per frame. As a result, not all +data need to be sampled at the same rate, but the ratio of sample rates of all +fields is fixed and the frame period must be some multiple of the lowest common +multiple of all sample periods. + +For data marshalling purposes, defile breaks the dirfile frame into one or more +subframes, each of fixed format (see +.BR df_add_framedef (3) +for particulars on how to define a subframe). A raw field may appear in more +than one subframe: the number of samples per frame of a given raw field in the +output dirfile is the sum of the samples per frame of that field in each of the +subframes defined. + +A raw field may have multiple samples within each subframe. The location of +each raw field in a subframe is described by two numbers: an offset from the +start of the subframe to the first sample, and cadence (the spacing of +successive samples). A cadence equal to the size of the data type implies +consecutive data. + +Defile performs no checks on the order in which subframes are presented by +the input plugin, but appends data as given. Neither does it check to ensure +that all necessary subframes have been provided. The input plugin is +responsible for ensuring subframes are ordered correctly within the frame, and +that no subframes are skipped. + +In synchronous mode, skipping subframes containing the reference field can +result in deadlock, since defile prohibits other fields from getting more than +one buffer length ahead of the reference, and will eventually refuse all other +data. Notably, if the buffer for a field contained in the subframe which also +contains the reference field has filled up, those subframes will be refused, +even though they contain the reference field. Bugs of this sort are exacerbated +by blocking calls to +.BR df_push_frame (3). + +Defile always writes whole frames: a partial frame at the end of the input will +be discarded. + +.SH OTHER CONSIDERATIONS WHILE RUNNING +A few other operational points to remember while writing the main loop for an +inpuy plugin are discussed below. + +.SS Signal Handling + +The signals +.BR SIGHUP ", " SIGINT , +and +.B SIGTERM +are captured by defile and are not available to the input plugin. Other signals +are not monitored by defile. The input plugin may alter the signal handling of +other signals to suit it's needs. It is, however, required to do this in a +thread-safe way. + +.SS Cancellation + +In certain exceptional circumstances, defile may cancel the input plugin (see +.BR pthread_cancel (3)). +The most common reason for this is the input plugin spending too long in the +.B ABORT +state, but it may happen in other exceptional circumstances. Input plugins which +disable cancelability for long periods of time may be subject to more drastic measures without forewarning. + +.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. +To participate in automatic type detection, the plugin must define the +.I probe +member of the framework definition to a function which takes a character string +(the input designator provided on the command line) and returns either zero, if +the input designator does not seem to specify something the plugin is willing to +deal with, or else any non-zero number, to indicate that the plugin is willing +to try to read the specified designator. + +Defile will call the probe function for every input plugin discovered that +provides such a function. The order in which plugins are probed is not +specified, and plugin probe functions may be called asynchronously. As a +result, speedy and efficient execution is generally preferable to exactness. + +A careful trade-off must be made between false negatives (returning zero in +cases where the input designator really does indicate something readable by the +input plugin) and false positives (returning non-zero in cases where the input +designator does not, after all, indicate something readable by the plugin. +False negatives cause defile to be unable to find a suitable input plugin; +excessive false positives can lead to multiple input plugins claiming the input +(resulting in neither being automatically given it). + +Note: if input designators for the plugin are pathnames, its probe function +should typically call +.BR df_shell_expand (3) +on the name passed to it to ensure it is fully resolved. + +.SH API REFERENCE + +The following functions are provided by the defile C API, grouped here by +sequencing restrictions. See the indicated manual pages for details. + +.TP +.RB "Functions which may be called at any time, regardless of current state:" +.BR df_bsearch (3), +.BR df_check_abort (3), +.BR df_field_in_output (3), +.BR df_input_name (3), +.BR df_on_abort (3), +.BR df_shell_expand (3), +.BR df_strcmp (3) +.TP +Functions which may be called during the \fBSTART\fR state: +.BR df_init (3) +.TP +Functions which may be called during the \fBBUILD\fR state: +.BR df_add_alias (3), +.BR df_add_entry (3), +.BR df_add_spec (3), +.BR df_add_framedef (3), +.BR df_ready (3), +.BR df_set_const (3), +.BR df_set_carray (3), +.BR df_set_string (3) +.TP +Functions which may be called during the \fBRUN\fR state: +.BR df_nframes_allowed (3), +.BR df_push_frame (3), +.BR df_reinit (3), +.BR df_set_const (3), +.BR df_set_carray (3), +.BR df_set_string (3) +.IP +NB: See +.BR df_reinit (3) +for caveats involving sequencing in the case when this function fails. + +.SH SEE ALSO +.BR defile (1), +dirfile(5), as well as the manual pages of the API functions listed above in the +.B API REFERENCE +section. Added: trunk/defile/doc/defile.1.in =================================================================== --- trunk/defile/doc/defile.1.in (rev 0) +++ trunk/defile/doc/defile.1.in 2012-03-07 04:48:00 UTC (rev 668) @@ -0,0 +1,586 @@ +.\" defile.1. The defile man page. +.\" +.\" @configure_input@ +.\" +.\" 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 defile 1 "21 February 2012" "Version 0.1.0" GETDATA +.SH NAME +defile \(em convert data in various formats into dirfiles +.SH SYNOPSIS +.nh +.ad l +\fBdefile\fR [ \fIDEFILE\-OPTION\fR ]... [ \fIINPUT\fR ] +[ \fB\-\-\fR [ \fIINPUT\-OPTION\fR ]... ] +.hy +.ad n +.SH DESCRIPTION +Defile converts data in a data source specified by +.I INPUT +into a dirfile(5) database. + +Arbitrary input data formats are supported through the use of input plugins +which are loaded at runtime. For inform... [truncated message content] |
From: <ket...@us...> - 2012-03-06 01:45:25
|
Revision: 667 http://getdata.svn.sourceforge.net/getdata/?rev=667&view=rev Author: ketiltrout Date: 2012-03-06 01:45:18 +0000 (Tue, 06 Mar 2012) Log Message: ----------- GD_TRUNCSUB fixes. Allow "parent/meta" in gd_add_alias, too. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/src/add.c trunk/getdata/src/compat.c trunk/getdata/src/errors.c trunk/getdata/src/internal.h trunk/getdata/src/open.c trunk/getdata/test/Makefile.am trunk/getdata/test/test.h Added Paths: ----------- trunk/getdata/test/add_alias_meta.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2012-03-03 04:48:18 UTC (rev 666) +++ trunk/getdata/ChangeLog 2012-03-06 01:45:18 UTC (rev 667) @@ -1,4 +1,16 @@ -2012-03-03 D. V. Wiebe <ge...@ke...> svn:??? +2012-03-06 D. V. Wiebe <ge...@ke...> svn:667 + * src/errors.c: Change prefix on verbose output to "libgetdata". + + * src/add.c (_GD_FixName): Added. + * src/add.c (_GD_Add _GD_AddAlias): Call _GD_FixName. + * test/add_alias_meta.c: Added. + + * src/open.c (_GD_TruncDir): Fix subdirectory truncation. + * src/internal.h: Remove conditional defition of AT_SYMLINK_NOFOLLOW. + * src/compat.c (gd_StatAt): Check for definition of AT_SYMLINK_NOFOLLOW + before use. + +2012-03-03 D. V. Wiebe <ge...@ke...> svn:665 * src/getdata.h.in bindings/make_parameters.c: Added GD_TRUNCSUB open flag. * src/open.c (_GD_TruncDir): Added. * src/open.c (_GD_CreateDirfile): Call _GD_TruncDir. Modified: trunk/getdata/src/add.c =================================================================== --- trunk/getdata/src/add.c 2012-03-03 04:48:18 UTC (rev 666) +++ trunk/getdata/src/add.c 2012-03-06 01:45:18 UTC (rev 667) @@ -20,6 +20,53 @@ */ #include "internal.h" +static gd_entry_t *_GD_FixName(DIRFILE *restrict D, char **restrict buffer, + const char *name, int frag, int *restrict offset) +{ + gd_entry_t *P; + char *ptr; + + dtrace("%p, %p, \"%s\", %i, %p", D, buffer, name, frag, offset); + + /* Apply prefix and suffix */ + *buffer = ptr = _GD_MungeFromFrag(D, NULL, frag, name, offset); + + if (ptr == NULL) { + free(ptr); + dreturn("%p", NULL); + return NULL; + } + + P = _GD_CheckParent(D, &ptr, -1, 0); + + if (D->error) { + free(*buffer); + dreturn("%p", NULL); + return NULL; + } + + if (P) { + char *temp2; + /* make the new name -- this may be different because P may have been + * dealiased */ + + *offset = strlen(P->field) + 1; + temp2 = _GD_Malloc(D, *offset + strlen(ptr) + 1); + if (temp2 == NULL) { + free(*buffer); + dreturn("%p", NULL); + return NULL; + } + + sprintf(temp2, "%s/%s", P->field, ptr); + free(*buffer); + *buffer = temp2; + } + + dreturn("%p [\"%s\", %i]", P, *buffer, *offset); + return P; +} + /* add an entry - returns the added entry on success. */ static gd_entry_t *_GD_Add(DIRFILE *restrict D, const gd_entry_t *restrict entry, const char *restrict parent) @@ -92,43 +139,15 @@ temp_buffer[offset - 1] = '/'; strcpy(temp_buffer + offset, entry->field); } else { - char *ptr; - /* Apply prefix and suffix */ - temp_buffer = ptr = _GD_MungeFromFrag(D, NULL, entry->fragment_index, - entry->field, &offset); + /* this will munge the name and take care of detecting Barth-style metafield + * definitions */ + P = _GD_FixName(D, &temp_buffer, entry->field, entry->fragment_index, + &offset); - if (temp_buffer == NULL) { - dreturn("%p", NULL); - return NULL; - } - - /* look for a Barth-style meta field. We do this after mungification - * to ensure that the parent field ends up with the right prefix and - * suffix */ - P = _GD_CheckParent(D, &ptr, -1, 0); - if (D->error) { - free(temp_buffer); dreturn("%p", NULL); return NULL; } - - if (P) { - /* make the new name -- this may be different because P may have been - * dealiased */ - offset = strlen(P->field) + 1; - char *temp2 = _GD_Malloc(D, offset + strlen(ptr) + 1); - if (temp2 == NULL) { - free(temp_buffer); - dreturn("%p", NULL); - return NULL; - } - - dwatch("%s", ptr); - sprintf(temp2, "%s/%s", P->field, ptr); - free(temp_buffer); - temp_buffer = temp2; - } } /* check for duplicate field */ @@ -1943,9 +1962,9 @@ strcpy(munged_code + offset, field_code); } } else - /* Apply prefix and suffix */ - munged_code = _GD_MungeFromFrag(D, NULL, fragment_index, field_code, - &offset); + /* this will munge the name and take care of detecting Barth-style metafield + * definitions */ + P = _GD_FixName(D, &munged_code, field_code, fragment_index, &offset); if (D->error) { free(munged_code); Modified: trunk/getdata/src/compat.c =================================================================== --- trunk/getdata/src/compat.c 2012-03-03 04:48:18 UTC (rev 666) +++ trunk/getdata/src/compat.c 2012-03-06 01:45:18 UTC (rev 667) @@ -100,7 +100,7 @@ dtrace("%p, %i, \"%s\", %p, %x", D, dirfd, name, buf, flags); path = _GD_MakeFullPathOnly(D, dirfd, name); -#ifdef HAVE_LSTAT +#if defined(HAVE_LSTAT) && defined(AT_SYMLINK_NOFOLLOW) if (flags & AT_SYMLINK_NOFOLLOW) ret = lstat(path, buf); else Modified: trunk/getdata/src/errors.c =================================================================== --- trunk/getdata/src/errors.c 2012-03-03 04:48:18 UTC (rev 666) +++ trunk/getdata/src/errors.c 2012-03-06 01:45:18 UTC (rev 667) @@ -234,7 +234,7 @@ if (D->flags & GD_VERBOSE) { char *error_string = gd_error_string(D, NULL, 0); - fprintf(stderr, PACKAGE_NAME ": %s\n", error_string); + fprintf(stderr, "libgetdata: %s\n", error_string); free(error_string); } Modified: trunk/getdata/src/internal.h =================================================================== --- trunk/getdata/src/internal.h 2012-03-03 04:48:18 UTC (rev 666) +++ trunk/getdata/src/internal.h 2012-03-06 01:45:18 UTC (rev 667) @@ -442,10 +442,6 @@ # endif #endif -#ifndef AT_SYMLINK_NOFOLLOW -#define AT_SYMLINK_NOFOLLOW 0x100 -#endif - #ifdef HAVE_OPENAT # ifdef GETDATA_DEBUG # define gd_unused_d /**/ Modified: trunk/getdata/src/open.c =================================================================== --- trunk/getdata/src/open.c 2012-03-03 04:48:18 UTC (rev 666) +++ trunk/getdata/src/open.c 2012-03-06 01:45:18 UTC (rev 667) @@ -28,6 +28,7 @@ DIR* dir; struct dirent* lamb; struct stat statbuf; + int fd = dirfd; dtrace("%p, %i, \"%s\", %i", D, dirfd, dirfile, root); @@ -51,15 +52,17 @@ } while ((lamb = readdir(dir)) != NULL) { + char *name = (char *)malloc(strlen(dirfile) + strlen(lamb->d_name) + 2); + sprintf(name, "%s%c%s", dirfile, GD_DIRSEP, lamb->d_name); if (lamb->d_name[0] == '.' && lamb->d_name[1] == '\0') { + free(name); continue; /* skip current dir */ } else if (lamb->d_name[0] == '.' && lamb->d_name[1] == '.' && lamb->d_name[2] == '\0') { + free(name); continue; /* skip parent dir */ } else { - char *name = (char *)malloc(strlen(dirfile) + strlen(lamb->d_name) + 2); - sprintf(name, "%s%c%s", dirfile, GD_DIRSEP, lamb->d_name); if ( #if defined(HAVE_FSTATAT) && !defined(GD_NO_DIR_OPEN) fstatat(dirfd, lamb->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) @@ -76,7 +79,6 @@ dreturn("%i", -1); return -1; } - free(name); } /* check file type */ @@ -89,10 +91,14 @@ if (root && strcmp(lamb->d_name, "format") == 0) { /* don't delete the format file; we'll truncate it later */ format_trunc = 1; - } else if (gd_UnlinkAt(D, dirfd, lamb->d_name, 0)) { - char *name = (char *)malloc(strlen(dirfile) + strlen(lamb->d_name) - + 2); - sprintf(name, "%s%c%s", dirfile, GD_DIRSEP, lamb->d_name); + } else if ( +#ifdef HAVE_UNLINKAT + unlinkat(dirfd, lamb->d_name, 0) +#else + unlink(name) +#endif + ) + { _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_UNLINK, name, errno, NULL); free(name); closedir(dir); @@ -104,9 +110,6 @@ /* descend into subdir if requested */ if (D->flags & GD_TRUNCSUB) { int subdirfd; - char *subdir = (char *)malloc(strlen(dirfile) + strlen(lamb->d_name) - + 2); - sprintf(subdir, "%s%c%s", dirfile, GD_DIRSEP, lamb->d_name); #ifdef GD_NO_DIR_OPEN subdirfd = 0; /* unused */ #else @@ -114,28 +117,37 @@ #ifdef HAVE_OPENAT subdirfd = openat(dirfd, lamb->d_name, O_RDONLY) #else - subdirfd = open(subdir, O_RDONLY) + subdirfd = open(name, O_RDONLY) #endif ) < 0) { - _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_STAT, subdir, errno, NULL); - free(subdir); + _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_STAT, name, errno, NULL); + closedir(dir); + free(name); dreturn("%i", -1); return -1; } #endif /* descend -- this will close subdirfd */ - _GD_TruncDir(D, subdirfd, subdir, 0); - free(subdir); + _GD_TruncDir(D, subdirfd, name, 0); /* delete */ -#ifdef HAVE_UNLINKAT___ - unlinkat(dirfd, lamb->d_name, /* AT_...? */); + if ( +#ifdef HAVE_UNLINKAT + unlinkat(dirfd, lamb->d_name, AT_REMOVEDIR) #else - rmdir(subdir); + rmdir(name) #endif + ) { + _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_UNLINK, name, errno, NULL); + free(name); + closedir(dir); + dreturn("%i", -1); + return -1; + } } } + free(name); } closedir(dir); Property changes on: trunk/getdata/test ___________________________________________________________________ Modified: svn:ignore - Makefile Makefile.in *.o *.odirfile *.swp *.exe .deps .libs add add_affix add_alias add_bit add_bit_bitnum add_bit_bitsize add_bit_invalid add_bit_numbits 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_invalid add_lincom_nfields add_linterp add_linterp_invalid add_meta add_meta_alias add_mplex add_mplex_val add_multiply add_multiply_invalid add_phase add_phase_invalid add_polynom add_protect add_raw add_raw_include add_raw_invalid add_raw_spf add_raw_type add_rdonly add_recip add_resolv add_sbit add_scalar add_scalar_carray 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_list alias_list_alias alias_list_missing alias_num alias_num_alias alias_num_missing alias_target alias_target_alias alias_target_missing alter_bit_bitnum alter_bit_numbits alter_carray_len alter_carray_type alter_const alter_cpolynom alter_crecip alter_crecip89 alter_crecip_zero alter_divide alter_entry alter_entry_affix alter_entry_hidden alter_entry_recode alter_entry_scalar2a alter_entry_scalar2n alter_entry_scalar3 alter_entry_scalar4 alter_lincom_23 alter_lincom_32 alter_lincom_input alter_lincom_offset alter_lincom_slope alter_linterp alter_linterp_move alter_mplex alter_mspec alter_mspec_affix alter_multiply alter_phase alter_polynom_coeff alter_polynom_input alter_polynom_ord alter_raw_spf alter_raw_type alter_recip alter_recip_zero alter_spec alter_spec_affix alter_spec_meta alter_window ascii_add ascii_get ascii_get_get ascii_nframes ascii_put bof bof_lincom bof_phase bzip_get bzip_get_get bzip_move_from bzip_nframes bzip_put close close_bad close_discard close_null convert_complex128_complex64 convert_complex128_float64 convert_complex128_int64 convert_complex128_uint64 convert_complex64_complex128 convert_complex64_float64 convert_complex64_int64 convert_complex64_uint64 convert_float32_complex128 convert_float32_complex64 convert_float32_float64 convert_float32_int16 convert_float32_int32 convert_float32_int64 convert_float32_int8 convert_float32_uint16 convert_float32_uint32 convert_float32_uint64 convert_float32_uint8 convert_float64_complex128 convert_float64_complex64 convert_float64_float32 convert_float64_int16 convert_float64_int32 convert_float64_int64 convert_float64_int8 convert_float64_uint16 convert_float64_uint32 convert_float64_uint64 convert_float64_uint8 convert_int16_complex128 convert_int16_complex64 convert_int16_float32 convert_int16_float64 convert_int16_int32 convert_int16_int64 convert_int16_int8 convert_int16_uint16 convert_int16_uint32 convert_int16_uint64 convert_int16_uint8 convert_int32_complex128 convert_int32_complex64 convert_int32_float32 convert_int32_float64 convert_int32_int16 convert_int32_int64 convert_int32_int8 convert_int32_uint16 convert_int32_uint32 convert_int32_uint64 convert_int32_uint8 convert_int64_complex128 convert_int64_complex64 convert_int64_float32 convert_int64_float64 convert_int64_int16 convert_int64_int32 convert_int64_int8 convert_int64_uint16 convert_int64_uint32 convert_int64_uint64 convert_int64_uint8 convert_int8_complex128 convert_int8_complex64 convert_int8_float32 convert_int8_float64 convert_int8_int16 convert_int8_int32 convert_int8_int64 convert_int8_uint16 convert_int8_uint32 convert_int8_uint64 convert_int8_uint8 convert_uint16_complex128 convert_uint16_complex64 convert_uint16_float32 convert_uint16_float64 convert_uint16_int16 convert_uint16_int32 convert_uint16_int64 convert_uint16_int8 convert_uint16_uint32 convert_uint16_uint64 convert_uint16_uint8 convert_uint32_complex128 convert_uint32_complex64 convert_uint32_float32 convert_uint32_float64 convert_uint32_int16 convert_uint32_int32 convert_uint32_int64 convert_uint32_int8 convert_uint32_uint16 convert_uint32_uint64 convert_uint32_uint8 convert_uint64_complex128 convert_uint64_complex64 convert_uint64_float32 convert_uint64_float64 convert_uint64_int16 convert_uint64_int32 convert_uint64_int64 convert_uint64_int8 convert_uint64_uint16 convert_uint64_uint32 convert_uint64_uint8 convert_uint8_complex128 convert_uint8_complex64 convert_uint8_float32 convert_uint8_float64 convert_uint8_int16 convert_uint8_int32 convert_uint8_int64 convert_uint8_int8 convert_uint8_uint16 convert_uint8_uint32 convert_uint8_uint64 creat creat_excl creat_rdonly cvlist cvlist_array cvlist_array_hidden cvlist_array_meta cvlist_array_meta_hidden cvlist_hidden cvlist_invalid 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_derived del_derived_after del_derived_force del_meta del_meta_force dfes_bit dfes_divide dfes_lincom dfes_linterp dfes_multiply dfes_null dfes_phase dfes_raw dfes_recip dfes_zero encode_alter encode_get encode_move endian_alter endian_alter_sie endian_get endian_move entry_bad_code entry_bit entry_bit_scalar entry_divide entry_invalid entry_lincom entry_lincom_scalar entry_linterp entry_mplex entry_mplex_scalar entry_multiply entry_phase entry_phase_scalar entry_polynom entry_polynom_scalar entry_raw entry_raw_scalar entry_raw_scalar_code entry_raw_scalar_type entry_recip entry_scalar_repr entry_type entry_type_alias entry_window entry_window_scalar eof eof_index eof_lincom eof_phase error error_error error_num error_short file file_code file_type flist flist_hidden flist_invalid flist_meta flist_meta_hidden flist_meta_invalid flist_type flist_type_hidden flist_type_invalid flist_type_meta flist_type_meta_hidden flist_type_meta_invalid flush flush_all flush_bad_code flush_invalid flush_meta flush_spec foffs_alter foffs_get foffs_move fragment_affix fragment_affix_alter fragment_affix_alter2 fragment_affix_dup fragment_index fragment_index_alias fragment_name fragment_name_oor fragment_num fragment_parent get64 get_bad_code get_bit get_carray get_carray_len get_carray_slice get_char get_clincom get_complex128 get_complex64 get_const get_const_complex get_const_repr get_cpolynom get_divide get_endian16 get_endian32 get_endian64 get_endian8 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_int16 get_int32 get_int64 get_int8 get_invalid get_lincom1 get_lincom2 get_lincom3 get_lincom_noin get_lincom_non get_lincom_spf get_linterp get_linterp_noin get_linterp_notab get_linterp_sort get_mplex get_mplex_lb get_multiply get_multiply_noin get_nonexistent get_null get_off64 get_phase get_phase_affix get_polynom get_polynom_noin get_recip get_recip_const get_recurse get_rofs get_sbit get_sf get_ss get_type get_uint16 get_uint32 get_uint64 get_window get_window_clr get_window_ge get_window_gt get_window_le get_window_lt get_window_ne get_window_set get_zero global_name global_ref global_ref_empty global_ref_set gzip_add gzip_get gzip_get_get gzip_get_put gzip_move_from gzip_move_to gzip_nframes gzip_put gzip_put_get header_complex hide hide_hidden hide_unhide include include_accmode include_affix include_auto include_cb include_creat include_ignore include_index include_invalid include_nonexistent include_pc include_ref include_syntax index index_domain index_range legacy_get legacy_get_put legacy_get_rofs legacy_nframes legacy_nonexistent legacy_put legacy_spf lzma_get lzma_nframes madd madd_affix madd_alias madd_bit madd_bit_invalid madd_carray madd_clincom madd_const madd_cpolynom madd_crecip madd_crecip89 madd_divide madd_index madd_lincom madd_lincom_invalid madd_linterp madd_linterp_invalid madd_mplex madd_multiply madd_multiply_invalid madd_phase madd_phase_invalid madd_polynom madd_recip madd_sbit madd_spec madd_spec_directive madd_spec_invalid madd_spec_resolv madd_string madd_window move 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 name name_affix name_affix_bad name_after name_after_const name_dup name_move name_update name_update_const nfields nfields_hidden nfields_invalid nfields_type nfields_type_hidden nfields_type_invalid nfields_vector nfields_vector_hidden nfields_vector_invalid nframes nframes64 nframes_empty nframes_invalid nframes_off64 nframes_spf nmeta nmeta_hidden nmeta_invalid nmeta_parent nmeta_type nmeta_type_hidden nmeta_type_invalid nmeta_type_parent nmeta_vectors nmeta_vectors_del nmeta_vectors_hidden nmeta_vectors_invalid nmeta_vectors_parent open open_cb_abort open_cb_cont open_cb_ignore open_cb_invalid open_cb_rescan open_eaccess open_nonexistent open_notdirfile parse_alias parse_alias_code parse_alias_dup parse_alias_meta parse_alias_missing parse_badline parse_bit parse_bit4 parse_bit_bitnum parse_bit_bitsize parse_bit_ncols parse_bit_numbits parse_bit_scalar parse_carray parse_carray_long parse_const parse_const_ncols parse_divide parse_duplicate parse_duplicate_ignore parse_endian_bad parse_endian_big parse_endian_force parse_endian_little parse_endian_slash parse_eol parse_foffs parse_foffs_include parse_foffs_slash parse_hidden parse_hidden_field parse_hidden_meta parse_include parse_include_absolute parse_include_absrel parse_include_loop parse_include_nonexistent parse_include_prefix parse_include_prefix_dup parse_include_preprefix parse_include_relabs parse_include_relrel parse_include_slash parse_include_suffix parse_include_sufsuffix parse_index parse_lincom parse_lincom_ncols1 parse_lincom_ncols2 parse_lincom_nfields parse_lincom_nofields parse_lincom_non parse_lincom_non_ncols parse_lincom_scalar parse_linterp parse_linterp_ncols parse_malias parse_malias_dup parse_meta parse_meta_affix parse_meta_alias parse_meta_implicit parse_meta_implicit2 parse_meta_implicit_affix parse_meta_index parse_meta_index2 parse_meta_jump parse_meta_malias parse_meta_meta parse_meta_parent parse_meta_raw parse_mplex parse_mplex_ncols parse_mplex_scalar parse_multiply parse_multiply_ncols parse_name parse_name_dot parse_name_ext parse_name_pedantic parse_ncols parse_phase parse_phase_ncols parse_phase_scalar parse_polynom parse_polynom_ncols1 parse_polynom_ncols2 parse_polynom_scalar parse_protect_all parse_protect_bad parse_protect_data parse_protect_format parse_protect_none parse_quote parse_quote_mismatch parse_raw parse_raw_char parse_raw_ncols parse_raw_scalar parse_raw_spf parse_raw_type parse_recip parse_ref parse_ref_nonexistent parse_sbit parse_sort parse_string parse_string_ncols parse_string_null parse_version parse_version_89 parse_version_98 parse_version_include parse_version_p8 parse_version_p9 parse_version_permissive parse_version_slash parse_whitespace parse_window parse_window_ncols parse_window_op parse_window_scalar protect_alter protect_get put64 put_bad_code put_bit put_bof put_carray put_carray_slice put_char put_complex128 put_complex64 put_const put_const_protect put_divide put_endian16 put_endian32 put_endian64 put_endian8 put_endian_complex128_arm put_endian_complex128_big put_endian_complex128_little put_endian_complex64_arm put_endian_complex64_big put_endian_complex64_little put_endian_float32_arm put_endian_float32_big put_endian_float32_little put_endian_float64_arm put_endian_float64_big put_endian_float64_little put_ff put_float32 put_float64 put_foffs put_fs put_here put_heres put_int16 put_int32 put_int64 put_int8 put_invalid put_lincom1 put_lincom2 put_lincom_noin put_linterp put_linterp_noin put_linterp_nomono put_linterp_notab put_linterp_reverse put_mplex 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_uint64 put_window put_zero ref ref_none ref_two repr_a repr_float32 repr_float64 repr_i repr_int16 repr_int32 repr_int64 repr_int8 repr_m repr_r repr_real_a repr_real_i repr_real_m repr_real_r repr_uint16 repr_uint32 repr_uint64 repr_uint8 seek64 seek_cur seek_end seek_foffs seek_set sie_get_big sie_get_little sie_move_from sie_move_to sie_nframes_big sie_nframes_little sie_put_big sie_put_little slim_get slim_nframes slim_put spf spf_alias spf_alias_meta spf_alias_missing spf_divide spf_lincom spf_multiply spf_polynom spf_recip spf_recurse svlist svlist_hidden svlist_invalid svlist_meta svlist_meta_hidden svlist_meta_invalid tell tell64 trunc trunc_dir trunc_rdonly trunc_rofs trunc_truncsub unclude unclude_del unclude_move version_0 version_0_write version_1 version_1_write version_2 version_2_write version_3 version_3_write version_4 version_4_write version_5 version_5_strict version_5_write version_6 version_6_strict version_6_write version_7 version_7_strict version_7_write version_8 version_8_strict version_8_write version_9 version_9_strict version_9_write vlist vlist_alias vlist_hidden vlist_invalid vlist_meta vlist_meta_hidden vlist_meta_invalid xz_get xz_nframes zzip_data zzip_get zzip_get_get zzip_nframes zzslim_get zzslim_nframes + Makefile Makefile.in *.o *.odirfile *.swp *.exe .deps .libs add add_affix add_alias add_alias_meta add_bit add_bit_bitnum add_bit_bitsize add_bit_invalid add_bit_numbits 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_invalid add_lincom_nfields add_linterp add_linterp_invalid add_meta add_meta_alias add_mplex add_mplex_val add_multiply add_multiply_invalid add_phase add_phase_invalid add_polynom add_protect add_raw add_raw_include add_raw_invalid add_raw_spf add_raw_type add_rdonly add_recip add_resolv add_sbit add_scalar add_scalar_carray 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_list alias_list_alias alias_list_missing alias_num alias_num_alias alias_num_missing alias_target alias_target_alias alias_target_missing alter_bit_bitnum alter_bit_numbits alter_carray_len alter_carray_type alter_const alter_cpolynom alter_crecip alter_crecip89 alter_crecip_zero alter_divide alter_entry alter_entry_affix alter_entry_hidden alter_entry_recode alter_entry_scalar2a alter_entry_scalar2n alter_entry_scalar3 alter_entry_scalar4 alter_lincom_23 alter_lincom_32 alter_lincom_input alter_lincom_offset alter_lincom_slope alter_linterp alter_linterp_move alter_mplex alter_mspec alter_mspec_affix alter_multiply alter_phase alter_polynom_coeff alter_polynom_input alter_polynom_ord alter_raw_spf alter_raw_type alter_recip alter_recip_zero alter_spec alter_spec_affix alter_spec_meta alter_window ascii_add ascii_get ascii_get_get ascii_nframes ascii_put bof bof_lincom bof_phase bzip_get bzip_get_get bzip_move_from bzip_nframes bzip_put close close_bad close_discard close_null convert_complex128_complex64 convert_complex128_float64 convert_complex128_int64 convert_complex128_uint64 convert_complex64_complex128 convert_complex64_float64 convert_complex64_int64 convert_complex64_uint64 convert_float32_complex128 convert_float32_complex64 convert_float32_float64 convert_float32_int16 convert_float32_int32 convert_float32_int64 convert_float32_int8 convert_float32_uint16 convert_float32_uint32 convert_float32_uint64 convert_float32_uint8 convert_float64_complex128 convert_float64_complex64 convert_float64_float32 convert_float64_int16 convert_float64_int32 convert_float64_int64 convert_float64_int8 convert_float64_uint16 convert_float64_uint32 convert_float64_uint64 convert_float64_uint8 convert_int16_complex128 convert_int16_complex64 convert_int16_float32 convert_int16_float64 convert_int16_int32 convert_int16_int64 convert_int16_int8 convert_int16_uint16 convert_int16_uint32 convert_int16_uint64 convert_int16_uint8 convert_int32_complex128 convert_int32_complex64 convert_int32_float32 convert_int32_float64 convert_int32_int16 convert_int32_int64 convert_int32_int8 convert_int32_uint16 convert_int32_uint32 convert_int32_uint64 convert_int32_uint8 convert_int64_complex128 convert_int64_complex64 convert_int64_float32 convert_int64_float64 convert_int64_int16 convert_int64_int32 convert_int64_int8 convert_int64_uint16 convert_int64_uint32 convert_int64_uint64 convert_int64_uint8 convert_int8_complex128 convert_int8_complex64 convert_int8_float32 convert_int8_float64 convert_int8_int16 convert_int8_int32 convert_int8_int64 convert_int8_uint16 convert_int8_uint32 convert_int8_uint64 convert_int8_uint8 convert_uint16_complex128 convert_uint16_complex64 convert_uint16_float32 convert_uint16_float64 convert_uint16_int16 convert_uint16_int32 convert_uint16_int64 convert_uint16_int8 convert_uint16_uint32 convert_uint16_uint64 convert_uint16_uint8 convert_uint32_complex128 convert_uint32_complex64 convert_uint32_float32 convert_uint32_float64 convert_uint32_int16 convert_uint32_int32 convert_uint32_int64 convert_uint32_int8 convert_uint32_uint16 convert_uint32_uint64 convert_uint32_uint8 convert_uint64_complex128 convert_uint64_complex64 convert_uint64_float32 convert_uint64_float64 convert_uint64_int16 convert_uint64_int32 convert_uint64_int64 convert_uint64_int8 convert_uint64_uint16 convert_uint64_uint32 convert_uint64_uint8 convert_uint8_complex128 convert_uint8_complex64 convert_uint8_float32 convert_uint8_float64 convert_uint8_int16 convert_uint8_int32 convert_uint8_int64 convert_uint8_int8 convert_uint8_uint16 convert_uint8_uint32 convert_uint8_uint64 creat creat_excl creat_rdonly cvlist cvlist_array cvlist_array_hidden cvlist_array_meta cvlist_array_meta_hidden cvlist_hidden cvlist_invalid 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_derived del_derived_after del_derived_force del_meta del_meta_force dfes_bit dfes_divide dfes_lincom dfes_linterp dfes_multiply dfes_null dfes_phase dfes_raw dfes_recip dfes_zero encode_alter encode_get encode_move endian_alter endian_alter_sie endian_get endian_move entry_bad_code entry_bit entry_bit_scalar entry_divide entry_invalid entry_lincom entry_lincom_scalar entry_linterp entry_mplex entry_mplex_scalar entry_multiply entry_phase entry_phase_scalar entry_polynom entry_polynom_scalar entry_raw entry_raw_scalar entry_raw_scalar_code entry_raw_scalar_type entry_recip entry_scalar_repr entry_type entry_type_alias entry_window entry_window_scalar eof eof_index eof_lincom eof_phase error error_error error_num error_short file file_code file_type flist flist_hidden flist_invalid flist_meta flist_meta_hidden flist_meta_invalid flist_type flist_type_hidden flist_type_invalid flist_type_meta flist_type_meta_hidden flist_type_meta_invalid flush flush_all flush_bad_code flush_invalid flush_meta flush_spec foffs_alter foffs_get foffs_move fragment_affix fragment_affix_alter fragment_affix_alter2 fragment_affix_dup fragment_index fragment_index_alias fragment_name fragment_name_oor fragment_num fragment_parent get64 get_bad_code get_bit get_carray get_carray_len get_carray_slice get_char get_clincom get_complex128 get_complex64 get_const get_const_complex get_const_repr get_cpolynom get_divide get_endian16 get_endian32 get_endian64 get_endian8 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_int16 get_int32 get_int64 get_int8 get_invalid get_lincom1 get_lincom2 get_lincom3 get_lincom_noin get_lincom_non get_lincom_spf get_linterp get_linterp_noin get_linterp_notab get_linterp_sort get_mplex get_mplex_lb get_multiply get_multiply_noin get_nonexistent get_null get_off64 get_phase get_phase_affix get_polynom get_polynom_noin get_recip get_recip_const get_recurse get_rofs get_sbit get_sf get_ss get_type get_uint16 get_uint32 get_uint64 get_window get_window_clr get_window_ge get_window_gt get_window_le get_window_lt get_window_ne get_window_set get_zero global_name global_ref global_ref_empty global_ref_set gzip_add gzip_get gzip_get_get gzip_get_put gzip_move_from gzip_move_to gzip_nframes gzip_put gzip_put_get header_complex hide hide_hidden hide_unhide include include_accmode include_affix include_auto include_cb include_creat include_ignore include_index include_invalid include_nonexistent include_pc include_ref include_syntax index index_domain index_range legacy_get legacy_get_put legacy_get_rofs legacy_nframes legacy_nonexistent legacy_put legacy_spf lzma_get lzma_nframes madd madd_affix madd_alias madd_bit madd_bit_invalid madd_carray madd_clincom madd_const madd_cpolynom madd_crecip madd_crecip89 madd_divide madd_index madd_lincom madd_lincom_invalid madd_linterp madd_linterp_invalid madd_mplex madd_multiply madd_multiply_invalid madd_phase madd_phase_invalid madd_polynom madd_recip madd_sbit madd_spec madd_spec_directive madd_spec_invalid madd_spec_resolv madd_string madd_window move 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 name name_affix name_affix_bad name_after name_after_const name_dup name_move name_update name_update_const nfields nfields_hidden nfields_invalid nfields_type nfields_type_hidden nfields_type_invalid nfields_vector nfields_vector_hidden nfields_vector_invalid nframes nframes64 nframes_empty nframes_invalid nframes_off64 nframes_spf nmeta nmeta_hidden nmeta_invalid nmeta_parent nmeta_type nmeta_type_hidden nmeta_type_invalid nmeta_type_parent nmeta_vectors nmeta_vectors_del nmeta_vectors_hidden nmeta_vectors_invalid nmeta_vectors_parent open open_cb_abort open_cb_cont open_cb_ignore open_cb_invalid open_cb_rescan open_eaccess open_nonexistent open_notdirfile parse_alias parse_alias_code parse_alias_dup parse_alias_meta parse_alias_missing parse_badline parse_bit parse_bit4 parse_bit_bitnum parse_bit_bitsize parse_bit_ncols parse_bit_numbits parse_bit_scalar parse_carray parse_carray_long parse_const parse_const_ncols parse_divide parse_duplicate parse_duplicate_ignore parse_endian_bad parse_endian_big parse_endian_force parse_endian_little parse_endian_slash parse_eol parse_foffs parse_foffs_include parse_foffs_slash parse_hidden parse_hidden_field parse_hidden_meta parse_include parse_include_absolute parse_include_absrel parse_include_loop parse_include_nonexistent parse_include_prefix parse_include_prefix_dup parse_include_preprefix parse_include_relabs parse_include_relrel parse_include_slash parse_include_suffix parse_include_sufsuffix parse_index parse_lincom parse_lincom_ncols1 parse_lincom_ncols2 parse_lincom_nfields parse_lincom_nofields parse_lincom_non parse_lincom_non_ncols parse_lincom_scalar parse_linterp parse_linterp_ncols parse_malias parse_malias_dup parse_meta parse_meta_affix parse_meta_alias parse_meta_implicit parse_meta_implicit2 parse_meta_implicit_affix parse_meta_index parse_meta_index2 parse_meta_jump parse_meta_malias parse_meta_meta parse_meta_parent parse_meta_raw parse_mplex parse_mplex_ncols parse_mplex_scalar parse_multiply parse_multiply_ncols parse_name parse_name_dot parse_name_ext parse_name_pedantic parse_ncols parse_phase parse_phase_ncols parse_phase_scalar parse_polynom parse_polynom_ncols1 parse_polynom_ncols2 parse_polynom_scalar parse_protect_all parse_protect_bad parse_protect_data parse_protect_format parse_protect_none parse_quote parse_quote_mismatch parse_raw parse_raw_char parse_raw_ncols parse_raw_scalar parse_raw_spf parse_raw_type parse_recip parse_ref parse_ref_nonexistent parse_sbit parse_sort parse_string parse_string_ncols parse_string_null parse_version parse_version_89 parse_version_98 parse_version_include parse_version_p8 parse_version_p9 parse_version_permissive parse_version_slash parse_whitespace parse_window parse_window_ncols parse_window_op parse_window_scalar protect_alter protect_get put64 put_bad_code put_bit put_bof put_carray put_carray_slice put_char put_complex128 put_complex64 put_const put_const_protect put_divide put_endian16 put_endian32 put_endian64 put_endian8 put_endian_complex128_arm put_endian_complex128_big put_endian_complex128_little put_endian_complex64_arm put_endian_complex64_big put_endian_complex64_little put_endian_float32_arm put_endian_float32_big put_endian_float32_little put_endian_float64_arm put_endian_float64_big put_endian_float64_little put_ff put_float32 put_float64 put_foffs put_fs put_here put_heres put_int16 put_int32 put_int64 put_int8 put_invalid put_lincom1 put_lincom2 put_lincom_noin put_linterp put_linterp_noin put_linterp_nomono put_linterp_notab put_linterp_reverse put_mplex 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_uint64 put_window put_zero ref ref_none ref_two repr_a repr_float32 repr_float64 repr_i repr_int16 repr_int32 repr_int64 repr_int8 repr_m repr_r repr_real_a repr_real_i repr_real_m repr_real_r repr_uint16 repr_uint32 repr_uint64 repr_uint8 seek64 seek_cur seek_end seek_foffs seek_set sie_get_big sie_get_little sie_move_from sie_move_to sie_nframes_big sie_nframes_little sie_put_big sie_put_little slim_get slim_nframes slim_put spf spf_alias spf_alias_meta spf_alias_missing spf_divide spf_lincom spf_multiply spf_polynom spf_recip spf_recurse svlist svlist_hidden svlist_invalid svlist_meta svlist_meta_hidden svlist_meta_invalid tell tell64 trunc trunc_dir trunc_rdonly trunc_rofs trunc_truncsub unclude unclude_del unclude_move version_0 version_0_write version_1 version_1_write version_2 version_2_write version_3 version_3_write version_4 version_4_write version_5 version_5_strict version_5_write version_6 version_6_strict version_6_write version_7 version_7_strict version_7_write version_8 version_8_strict version_8_write version_9 version_9_strict version_9_write vlist vlist_alias vlist_hidden vlist_invalid vlist_meta vlist_meta_hidden vlist_meta_invalid xz_get xz_nframes zzip_data zzip_get zzip_get_get zzip_nframes zzslim_get zzslim_nframes Modified: trunk/getdata/test/Makefile.am =================================================================== --- trunk/getdata/test/Makefile.am 2012-03-03 04:48:18 UTC (rev 666) +++ trunk/getdata/test/Makefile.am 2012-03-06 01:45:18 UTC (rev 667) @@ -44,11 +44,11 @@ EXTRA_DIST=test.h -ADD_TESTS=add add_affix add_alias add_bit add_bit_bitnum add_bit_bitsize \ - add_bit_invalid add_bit_numbits 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_invalid add_lincom_nfields add_linterp \ +ADD_TESTS=add add_affix add_alias add_alias_meta add_bit add_bit_bitnum \ + add_bit_bitsize add_bit_invalid add_bit_numbits 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_invalid add_lincom_nfields add_linterp \ add_linterp_invalid add_meta add_meta_alias add_mplex add_mplex_val \ add_multiply add_multiply_invalid add_phase add_phase_invalid \ add_polynom add_protect add_raw add_raw_include add_raw_invalid \ Added: trunk/getdata/test/add_alias_meta.c =================================================================== --- trunk/getdata/test/add_alias_meta.c (rev 0) +++ trunk/getdata/test/add_alias_meta.c 2012-03-06 01:45:18 UTC (rev 667) @@ -0,0 +1,57 @@ +/* Copyright (C) 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 + */ +#include "test.h" + +int main(void) +{ + const char *filedir = "dirfile"; + const char *format = "dirfile/format"; + const char *data = "dirfile/data"; + const char *target; + int error, i, n, r = 0; + DIRFILE *D; + + rmdirfile(); + + D = gd_open(filedir, GD_RDWR | GD_CREAT | GD_VERBOSE); + + gd_add_raw(D, "data", GD_UINT8, 1, 0); + gd_add_alias(D, "data/alias", "data", 0); + error = gd_error(D); + + /* check */ + target = gd_alias_target(D, "data/alias"); + CHECKS(target, "data"); + i = gd_fragment_index(D, "data/alias"); + n = gd_naliases(D, "data/alias"); + + gd_discard(D); + + unlink(data); + unlink(format); + rmdir(filedir); + + CHECKI(error, GD_E_OK); + CHECKI(i, 0); + CHECKI(n, 2); + + return r; +} Modified: trunk/getdata/test/test.h =================================================================== --- trunk/getdata/test/test.h 2012-03-03 04:48:18 UTC (rev 666) +++ trunk/getdata/test/test.h 2012-03-06 01:45:18 UTC (rev 667) @@ -61,6 +61,8 @@ __VA_ARGS__); } \ } while(0) +#define strcmpn(n,v) (((n) == NULL) ? 1 : strcmp((n),(v))) + #ifdef GD_NO_C99_API #define CHECKC(n,v) CHECK(sqrt(((n)[0]-(v)[0])*((n)[0]-(v)[0]) + \ (((n)[1]-(v)[1])*((n)[1]-(v)[1])))>1e-10,n,"%.15g;%.15g","%.15g;%.15g",\ @@ -89,8 +91,8 @@ #define CHECKPi(i,n) CHECKi(i,(n) != NULL,n,"%p","%s",n,"NULL") #define CHECKPN(n) CHECK((n) == NULL,n,"%p","%s",n,"non-NULL") #define CHECKPNi(i,n) CHECKi(i,(n) == NULL,n,"%p","%s",n,"non-NULL") -#define CHECKS(n,v) CHECK(strcmp((n),(v)),n,"\"%s\"","\"%s\"",(n),(v)); -#define CHECKSi(n,v) CHECKi(i,strcmp((n),(v)),n,"\"%s\"","\"%s\"",(n),(v)); +#define CHECKS(n,v) CHECK(strcmpn((n),(v)),n,"\"%s\"","\"%s\"",(n),(v)); +#define CHECKSi(n,v) CHECKi(i,strcmpn((n),(v)),n,"\"%s\"","\"%s\"",(n),(v)); #define CHECKSp(n,v) CHECK(strncmp((n),(v), sizeof(v) - 1),n,"\"%s\"",\ "\"%s\"",(n),(v)); #define CHECKEOS(n,v) CHECK(strcmp((n) + strlen(n) - sizeof(v) + 1,(v)),n,\ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-03 04:48:24
|
Revision: 666 http://getdata.svn.sourceforge.net/getdata/?rev=666&view=rev Author: ketiltrout Date: 2012-03-03 04:48:18 +0000 (Sat, 03 Mar 2012) Log Message: ----------- Tweak build. Modified Paths: -------------- trunk/getdata/bindings/perl/Makefile.am Modified: trunk/getdata/bindings/perl/Makefile.am =================================================================== --- trunk/getdata/bindings/perl/Makefile.am 2012-03-03 03:54:58 UTC (rev 665) +++ trunk/getdata/bindings/perl/Makefile.am 2012-03-03 04:48:18 UTC (rev 666) @@ -30,13 +30,15 @@ lib: mkdir lib -lib/GetData.xs: $(srcdir)/GetData.xs lib +lib/GetData.xs: $(srcdir)/GetData.xs + $(MAKE) lib cat $< > $@ -lib/typemap: $(srcdir)/typemap lib +lib/typemap: $(srcdir)/typemap + $(MAKE) lib cat $< > $@ -lib/simple_funcs.xs: $(srcdir)/simple_funcs.xsin $(srcdir)/simple_funcs.pl lib +lib/simple_funcs.xs: $(srcdir)/simple_funcs.xsin $(srcdir)/simple_funcs.pl $(PERL) $(srcdir)/simple_funcs.pl $< > $@ make_parameters.sed: ../make_parameters ../../src/getdata.h @@ -52,9 +54,9 @@ $(PERL) $(srcdir)/funclist.pl lib/GetData.xs lib/simple_funcs.xs > $@ chmod a-w $@ -all-local: blib/arch/auto/GetData/GetData.so +all-local: lib blib/arch/auto/GetData/GetData.bs -blib/arch/auto/GetData/GetData.so: Build +blib/arch/auto/GetData/GetData.bs: Build $(PERL) $< build .PRECIOUS: Build This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-03-03 03:55:07
|
Revision: 665 http://getdata.svn.sourceforge.net/getdata/?rev=665&view=rev Author: ketiltrout Date: 2012-03-03 03:54:58 +0000 (Sat, 03 Mar 2012) Log Message: ----------- GD_TRUNCSUB Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/bindings/cxx/windowentry.cpp trunk/getdata/bindings/f77/fgetdata.c trunk/getdata/bindings/make_parameters.c trunk/getdata/man/Makefile.am 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_endianness.3.in trunk/getdata/man/gd_alter_protection.3 trunk/getdata/man/gd_cbopen.3 trunk/getdata/man/gd_delete.3 trunk/getdata/man/gd_fragment_index.3 trunk/getdata/man/gd_move.3 trunk/getdata/man/gd_rename.3 trunk/getdata/src/fragment.c trunk/getdata/src/getdata.h.in trunk/getdata/src/open.c trunk/getdata/test/Makefile.am trunk/getdata/test/fragment_affix_alter.c trunk/getdata/test/fragment_affix_alter2.c trunk/getdata/test/fragment_affix_dup.c Added Paths: ----------- trunk/getdata/man/gd_add_alias.3 trunk/getdata/man/gd_alias_target.3 trunk/getdata/man/gd_aliases.3 trunk/getdata/man/gd_alter_affixes.3 trunk/getdata/man/gd_fragment_affixes.3 trunk/getdata/man/gd_hidden.3 trunk/getdata/man/gd_hide.3 trunk/getdata/man/gd_naliases.3 trunk/getdata/test/trunc_dir.c trunk/getdata/test/trunc_truncsub.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/ChangeLog 2012-03-03 03:54:58 UTC (rev 665) @@ -1,3 +1,14 @@ +2012-03-03 D. V. Wiebe <ge...@ke...> svn:??? + * src/getdata.h.in bindings/make_parameters.c: Added GD_TRUNCSUB open flag. + * src/open.c (_GD_TruncDir): Added. + * src/open.c (_GD_CreateDirfile): Call _GD_TruncDir. + * test/trunc_dir.c test/trunc_truncsub.c: Added. + + * src/fragment.c (gd_alter_affixes): Handle GD_E_ACCMODE and GD_E_PROTECTED + errors. + + * bindings/f77/fgetdata.c (GDDELA): Correct call to gd_delete_alias. + 2012-03-02 D. V. Wiebe <ge...@ke...> svn:664 * src/errors.c: Added GD_E_ARGUMENT:GD_E_ARG_NODATA. * src/parse.c (_GD_Tokenise): Take number of columns to return. Modified: trunk/getdata/bindings/cxx/windowentry.cpp =================================================================== --- trunk/getdata/bindings/cxx/windowentry.cpp 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/bindings/cxx/windowentry.cpp 2012-03-03 03:54:58 UTC (rev 665) @@ -78,7 +78,8 @@ { int ret = 0; - dtrace("{%g,%llX,%lli}", threshold.r, threshold.u, threshold.i); + dtrace("{%g,%llX,%lli}", threshold.r, (unsigned long long)threshold.u, + (long long)threshold.i); E.u.window.threshold = threshold; Modified: trunk/getdata/bindings/f77/fgetdata.c =================================================================== --- trunk/getdata/bindings/f77/fgetdata.c 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/bindings/f77/fgetdata.c 2012-03-03 03:54:58 UTC (rev 665) @@ -3615,7 +3615,7 @@ char *fc = (char *)malloc(*field_code_l + 1); gd_delete_alias(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, - *field_code_l), (unsigned)flags); + *field_code_l), (unsigned int)*flags); free(fc); dreturnvoid(); Modified: trunk/getdata/bindings/make_parameters.c =================================================================== --- trunk/getdata/bindings/make_parameters.c 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/bindings/make_parameters.c 2012-03-03 03:54:58 UTC (rev 665) @@ -110,6 +110,7 @@ CONSTANT(ARM_ENDIAN, "GD_AE", 2), CONSTANT(NOT_ARM_ENDIAN, "GD_NA", 2), CONSTANT(PERMISSIVE, "GD_PM", 1), + CONSTANT(TRUNCSUB, "GD_TS", 1), CONSTANT(AUTO_ENCODED, "GDE_AU", 1), CONSTANT(BZIP2_ENCODED, "GDE_BZ", 2), Modified: trunk/getdata/man/Makefile.am =================================================================== --- trunk/getdata/man/Makefile.am 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/man/Makefile.am 2012-03-03 03:54:58 UTC (rev 665) @@ -28,30 +28,33 @@ nodist_man_MANS = gd_alter_encoding.3 gd_alter_endianness.3 \ gd_alter_frameoffset.3 -dist_man_MANS = checkdirfile.1 dirfile2ascii.1 gd_add.3 gd_add_bit.3 \ - gd_add_spec.3 gd_alter_bit.3 gd_alter_entry.3 \ +dist_man_MANS = checkdirfile.1 dirfile2ascii.1 gd_add.3 gd_add_alias.3 \ + gd_add_bit.3 gd_add_spec.3 gd_alias_target.3 gd_aliases.3 \ + gd_alter_affixes.3 gd_alter_bit.3 gd_alter_entry.3 \ gd_alter_protection.3 gd_alter_spec.3 gd_bof.3 gd_carray_len.3 \ - gd_carrays.3 gd_cbopen.3 gd_close.3 gd_get_carray_slice.3 \ - gd_put_carray_slice.3 gd_get_constant.3 gd_put_constant.3 \ - gd_constants.3 gd_dirfile_standards.3 gd_getdata.3 \ - gd_putdata.3 gd_delete.3 gd_encoding.3 gd_endianness.3 \ - gd_entry.3 gd_entry_type.3 gd_eof.3 gd_error.3 \ - gd_error_count.3 gd_error_string.3 gd_field_list.3 \ - gd_field_list_by_type.3 gd_flush.3 gd_fragment_index.3 \ - gd_fragmentname.3 gd_framenum_subset.3 gd_frameoffset.3 \ - gd_free_entry_strings.3 gd_include.3 gd_invalid_dirfile.3 \ + gd_carrays.3 gd_cbopen.3 gd_close.3 gd_constants.3 \ + gd_dirfile_standards.3 gd_delete.3 gd_dirfilename.3 \ + gd_encoding.3 gd_endianness.3 gd_entry.3 gd_entry_type.3 \ + gd_eof.3 gd_error.3 gd_error_count.3 gd_error_string.3 \ + gd_field_list.3 gd_field_list_by_type.3 gd_flush.3 \ + gd_fragment_affixes.3 gd_fragment_index.3 gd_fragmentname.3 \ + gd_framenum_subset.3 gd_frameoffset.3 gd_free_entry_strings.3 \ + gd_get_carray_slice.3 gd_get_constant.3 gd_getdata.3 \ + gd_get_string.3 gd_hidden.3 gd_hide.3 gd_include.3 \ + gd_invalid_dirfile.3 \ gd_madd_bit.3 gd_mcarrays.3 gd_mconstants.3 gd_metaflush.3 \ gd_mfield_list.3 gd_mfield_list_by_type.3 gd_move.3 \ - gd_mstrings.3 gd_mvector_list.3 gd_dirfilename.3 \ + gd_mstrings.3 gd_mvector_list.3 gd_dirfilename.3 gd_naliases.3 \ gd_native_type.3 gd_nfields.3 gd_nfields_by_type.3 \ gd_nfragments.3 gd_nframes.3 gd_nmfields.3 \ gd_nmfields_by_type.3 gd_nmvectors.3 gd_nvectors.3 \ gd_parent_fragment.3 gd_parser_callback.3 gd_protection.3 \ - gd_raw_filename.3 gd_reference.3 gd_rename.3 \ - gd_rewrite_fragment.3 gd_seek.3 gd_spf.3 gd_get_string.3 \ - gd_put_string.3 gd_strings.3 gd_tell.3 gd_uninclude.3 \ - gd_validate.3 gd_vector_list.3 dirfile.5 dirfile-encoding.5 \ - dirfile-format.5 $(LFS_transitional_mans) + gd_put_carray_slice.3 gd_put_constant.3 gd_putdata.3 \ + gd_put_string.3 gd_raw_filename.3 gd_reference.3 gd_rename.3 \ + gd_rewrite_fragment.3 gd_seek.3 gd_spf.3 gd_strings.3 \ + gd_tell.3 gd_uninclude.3 gd_validate.3 gd_vector_list.3 \ + dirfile.5 dirfile-encoding.5 dirfile-format.5 \ + $(LFS_transitional_mans) MAN3ALIASES=gd_add_bit.3:gd_add_carray.3 gd_add_bit.3:gd_add_clincom.3 \ gd_add_bit.3:gd_add_const.3 gd_add_bit.3:gd_add_cpolynom.3 \ @@ -60,15 +63,15 @@ gd_add_bit.3:gd_add_multiply.3 gd_add_bit.3:gd_add_polynom.3 \ gd_add_bit.3:gd_add_phase.3 gd_add_bit.3:gd_add_raw.3 \ gd_add_bit.3:gd_add_recip.3 gd_add_bit.3:gd_add_sbit.3 \ - gd_add_bit.3:gd_add_string.3 gd_madd_bit.3:gd_madd_carray.3 \ - gd_madd_bit.3:gd_madd_clincom.3 gd_madd_bit.3:gd_madd_const.3 \ - gd_madd_bit.3:gd_madd_cpolynom.3 gd_madd_bit.3:gd_madd_crecip.3 \ - gd_madd_bit.3:gd_madd_divide.3 gd_madd_bit.3:gd_madd_lincom.3 \ - gd_madd_bit.3:gd_madd_linterp.3 gd_madd_bit.3:gd_madd_multiply.3 \ - gd_madd_bit.3:gd_madd_phase.3 gd_madd_bit.3:gd_madd_polynom.3 \ - gd_madd_bit.3:gd_madd_recip.3 gd_madd_bit.3:gd_madd_sbit.3 \ - gd_madd_bit.3:gd_madd_string.3 gd_add.3:gd_madd.3 \ - gd_add_spec.3:gd_madd_spec.3 gd_cbopen.3:gd_open.3 \ + gd_add_bit.3:gd_add_string.3 gd_add_bit.3:gd_add_window.3 \ + gd_madd_bit.3:gd_madd_carray.3 gd_madd_bit.3:gd_madd_clincom.3 \ + gd_madd_bit.3:gd_madd_const.3 gd_madd_bit.3:gd_madd_cpolynom.3 \ + gd_madd_bit.3:gd_madd_crecip.3 gd_madd_bit.3:gd_madd_divide.3 \ + gd_madd_bit.3:gd_madd_lincom.3 gd_madd_bit.3:gd_madd_linterp.3 \ + gd_madd_bit.3:gd_madd_multiply.3 gd_madd_bit.3:gd_madd_phase.3 \ + gd_madd_bit.3:gd_madd_polynom.3 gd_madd_bit.3:gd_madd_recip.3 \ + gd_madd_bit.3:gd_madd_sbit.3 gd_madd_bit.3:gd_madd_string.3 \ + gd_add.3:gd_madd.3 gd_add_spec.3:gd_madd_spec.3 gd_cbopen.3:gd_open.3 \ gd_close.3:gd_discard.3 gd_alter_bit.3:gd_alter_carray.3 \ gd_alter_bit.3:gd_alter_clincom.3 gd_alter_bit.3:gd_alter_const.3 \ gd_alter_bit.3:gd_alter_cpolynom.3 gd_alter_bit.3:gd_alter_crecip.3 \ @@ -76,9 +79,11 @@ gd_alter_bit.3:gd_alter_linterp.3 gd_alter_bit.3:gd_alter_multiply.3 \ gd_alter_bit.3:gd_alter_phase.3 gd_alter_bit.3:gd_alter_polynom.3 \ gd_alter_bit.3:gd_alter_recip.3 gd_alter_bit.3:gd_alter_raw.3 \ - gd_alter_bit.3:gd_alter_sbit.3 gd_alter_spec.3:gd_malter_spec.3 \ - gd_framenum_subset.3:gd_framenum.3 gd_get_carray_slice.3:gd_get_carray.3 \ - gd_put_carray_slice.3:gd_put_carray.3 $(MAN3ALIASES64) + gd_alter_bit.3:gd_alter_sbit.3 gd_alter_bit.3:gd_alter_window.3 \ + gd_alter_spec.3:gd_malter_spec.3 gd_framenum_subset.3:gd_framenum.3 \ + gd_get_carray_slice.3:gd_get_carray.3 gd_put_carray_slice.3:gd_put_carray.3 \ + gd_delete.3:gd_delete_alias.3 gd_hide.3:gd_unhide.3 \ + gd_add_alias.3:gd_madd_alias.3 $(MAN3ALIASES64) #man conversion HTMLMANS=$(addsuffix .html,$(nodist_man_MANS)) \ Modified: trunk/getdata/man/gd_add.3 =================================================================== --- trunk/getdata/man/gd_add.3 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/man/gd_add.3 2012-03-03 03:54:58 UTC (rev 665) @@ -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 "1 March 2012" "Version 0.8.0" "GETDATA" +.TH gd_add 3 "2 March 2012" "Version 0.8.0" "GETDATA" .SH NAME gd_add, gd_madd \(em add a field to a dirfile .SH SYNOPSIS @@ -106,7 +106,8 @@ .B GD_E_BAD_CODE The field name provided in .IR entry -> field -contained invalid characters. Alternately, the +contained invalid characters or did not contain the affected fragment's prefix +or suffix. Alternately, the .I parent field code was not found, or was already a metafield. .TP Added: trunk/getdata/man/gd_add_alias.3 =================================================================== --- trunk/getdata/man/gd_add_alias.3 (rev 0) +++ trunk/getdata/man/gd_add_alias.3 2012-03-03 03:54:58 UTC (rev 665) @@ -0,0 +1,101 @@ +.\" gd_add_alias.3. The gd_add_alias man page. +.\" +.\" Copyright (C) 2012 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_add_alias 3 "1 January 2012" "Version 0.8.0" "GETDATA" +.SH NAME +gd_add_alias, gd_madd_alias \(em add a field to a dirfile +.SH SYNOPSIS +.B #include <getdata.h> +.HP +.nh +.ad l +.BI "int gd_add_alias(DIRFILE *" dirfile ", const char *" alias_name , +.BI "const char *" target_code ", int " fragment_index ); +.HP +.BI "int gd_madd_alias(DIRFILE *" dirfile ", const char *" parent , +.BI "const char *" alias_name ", const char *" target_code ); +.hy +.ad n +.SH DESCRIPTION +The +.BR gd_add_alias () +function adds the alias named +.I alias_name +pointing to +.I target_code +to the fragment indexed by +.I fragment_index +in the dirfile specified by +.IR dirfile . +The +.BR gd_madd_alias () +function behaves similarly, but adds the field as a meta-entry under the field +indicated by the field code +.IR parent . + +.SH RETURN VALUE +On success, +.BR gd_add_alias () +and +.BR gd_madd_alias () +return zero. On error, -1 is returned and the dirfile error is set to a +non-zero error value. Possible error values are: +.TP 8 +.B GD_E_ACCMODE +The specified dirfile was opened read-only. +.TP +.B GD_E_ALLOC +The library was unable to allocate memory. +.TP +.B GD_E_BAD_CODE +The +.IR alias_name +parameter contained invalid characters or was missing the indicated fragment's +field prefix or suffix. Alternately, the +.I parent +field code was not found, or was already a metafield. +.TP +.B GD_E_BAD_DIRFILE +The supplied dirfile was invalid. +.TP +.B GD_E_BAD_INDEX +The +.I fragment_index +specified was out of range. +.TP +.B GD_E_DUPLICATE +The +.I alias_name +parameter duplicated that of an already existing entry. +.TP +.B GD_E_PROTECTED +The metadata of the fragment was protected from change. Or, the creation of a +.B RAW +field was attempted and the data of the fragment was protected. +.PP +The dirfile error may be retrieved by calling +.BR gd_error (3). +A descriptive error string for the last error encountered can be obtained from +a call to +.BR gd_error_string (3). + +.SH SEE ALSO +.BR gd_add (3), +.BR gd_alias_target (3), +.BR gd_entry (3), +.BR gd_madd (3), +.BR gd_metaflush (3), +.BR gd_open (3), +.BR dirfile-format (5) Modified: trunk/getdata/man/gd_add_bit.3 =================================================================== --- trunk/getdata/man/gd_add_bit.3 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/man/gd_add_bit.3 2012-03-03 03:54:58 UTC (rev 665) @@ -83,6 +83,10 @@ .HP .BI "int gd_add_string(DIRFILE *" dirfile ", const char *" field_name , .BI "const char *" value ", int " fragment_index ); +.HP +.BI "int gd_add_window(DIRFILE *" dirfile ", const char *" field_name , +.BI "const char *" in_field ", const char *" check_field ", gd_windop_t" +.IB windop ", gd_triplet_t " threshold ); .hy .ad n .SH DESCRIPTION @@ -206,7 +210,8 @@ .B GD_E_BAD_CODE The .IR field_name -argument contained invalid characters. +argument contained invalid characters or did not contain the affected fragment's +prefix or suffix. .TP .B GD_E_BAD_DIRFILE The supplied dirfile was invalid. Added: trunk/getdata/man/gd_alias_target.3 =================================================================== --- trunk/getdata/man/gd_alias_target.3 (rev 0) +++ trunk/getdata/man/gd_alias_target.3 2012-03-03 03:54:58 UTC (rev 665) @@ -0,0 +1,80 @@ +.\" gd_alias_target.3. The gd_alias_target man page. +.\" +.\" Copyright (C) 2012 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_alias_target 3 "1 January 2012" "Version 0.8.0" "GETDATA" +.SH NAME +gd_alias_target \(em return the target of an alias defined in a dirfile database +.SH SYNOPSIS +.B #include <getdata.h> +.HP +.nh +.ad l +.BI "const char *gd_alias(DIRFILE *" dirfile ", const char *" alias_name ); +.hy +.ad n +.SH DESCRIPTION +The +.BR gd_alias_target () +function queries a dirfile(5) database specified by +.I dirfile +and returns the target field code of the alias specified by +.IR alias_name . + +The +.I dirfile +argument must point to a valid DIRFILE object previously created by a call to +.BR gd_open (3). + +Note: the target may itself be the an alias, which will have its own target. To +obtain the canonical name of the field ultimately referenced by +.IR alias_name , +pass it to +.BR gd_entry (3) +and inspect the +.I field +member of the gd_entry_t structure returned. + +.SH RETURN VALUE +Upon successful completion, +.BR gd_alias_target () +returns a pointer to a read-only character string containing the name of the +target of the specified alias. On error, +.BR gd_alias_target () +returns NULL and sets the dirfile error a non-zero error value. Possible error +values are: +.TP 8 +.B GD_E_BAD_CODE +The name +.I alias_name +was not found in the dirfile. +.B GD_E_BAD_DIRFILE +The supplied dirfile was invalid. +.TP +.B GD_E_BAD_FIELD_TYPE +The entry specified by +.I alias_name +was not an alias. +.PP +The dirfile error may be retrieved by calling +.BR gd_error (3). +A descriptive error string for the last error encountered can be obtained from +a call to +.BR gd_error_string (3). + +.SH SEE ALSO +.BR gd_aliases (3), +.BR gd_entry (3), +.BR gd_open (3), +.BR dirfile (5) Added: trunk/getdata/man/gd_aliases.3 =================================================================== --- trunk/getdata/man/gd_aliases.3 (rev 0) +++ trunk/getdata/man/gd_aliases.3 2012-03-03 03:54:58 UTC (rev 665) @@ -0,0 +1,84 @@ +.\" gd_aliases.3. The gd_aliases man page. +.\" +.\" Copyright (C) 2012 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_aliases 3 "1 January 2012" "Version 0.8.0" "GETDATA" +.SH NAME +gd_aliases \(em retrieve a list of aliases for a field in a dirfile database +.SH SYNOPSIS +.B #include <getdata.h> +.HP +.nh +.ad l +.BI "const char **gd_aliases(DIRFILE *" dirfile ", const char *" field_code ); +.hy +.ad n +.SH DESCRIPTION +The +.BR gd_aliases () +function queries a dirfile(5) database specified by +.I dirfile +and returns a read-only list of aliases of the field specified by +.IR field_code . + +The +.I dirfile +argument must point to a valid DIRFILE object previously created by a call to +.BR gd_open (3). + +The array returned will be de-allocated by a call to +.BR gd_close (3) +and should not be de-allocated by the caller. The list returned should not be +assumed to be in any particular order. The array is terminated by a NULL +pointer. The number of strings in the array can be obtained from a call to +.BR gd_naliases (3). + +The caller may not modify any strings in the array, or the array itself. Doing +so may cause database corruption. The pointer returned is guaranteed to be +valid until +.BR gd_aliases () +is called again with the same arguments, or until the array is de-allocated by +a call to +.BR gd_close (3). + +.SH RETURN VALUE +Upon successful completion, +.BR gd_aliases () +returns a pointer to an array of strings containing the values of all the +aliases for the specified field. The array is terminated by a NULL pointer. +If successful, this list will always contain at least one entry, to wit: +.IR field_code . + +On error it returns NULL and sets the dirfile error to a non-zero error value. +Possible error values are: +.TP 8 +.B GD_E_ALLOC +The library was unable to allocate memory. +.TP +.B GD_E_BAD_CODE +The specified field code was not found in the database. +.TP +.B GD_E_BAD_DIRFILE +The supplied dirfile was invalid. +.PP +The dirfile error may be retrieved by calling +.BR gd_error (3). +A descriptive error string for the last error encountered can be obtained from +a call to +.BR gd_error_string (3). +.SH SEE ALSO +.BR dirfile (5), +.BR gd_open (3), +.BR gd_alias_target (3), +.BR gd_naliases (3) Added: trunk/getdata/man/gd_alter_affixes.3 =================================================================== --- trunk/getdata/man/gd_alter_affixes.3 (rev 0) +++ trunk/getdata/man/gd_alter_affixes.3 2012-03-03 03:54:58 UTC (rev 665) @@ -0,0 +1,112 @@ +.\" gd_alter_affixes.3. The gd_alter_affixes man page. +.\" +.\" Copyright (C) 2012 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_alter_affixes 3 "1 January 2012" "Version 0.8.0" "GETDATA" +.SH NAME +gd_alter_affixes \(em modify the field affixes of a fragments in a dirfile +.SH SYNOPSIS +.B #include <getdata.h> +.HP +.nh +.ad l +.BI "int gd_alter_affixes(DIRFILE *" dirfile ", int " fragment_index , +.BI "const char *" prefix ", const char *" suffix ); +.hy +.ad n +.SH DESCRIPTION +The +.BR gd_alter_affixes () +function sets the field prefix and suffix of fields defined in the format +specification fragment given by +.I fragment_index +to +.I prefix +and +.I suffix +in the dirfile(5) database specified by +.IR dirfile . + +The field prefix and suffix are appended to all field codes found in the +specified fragment. If the parent fragment to the modified fragment contains +field affixes themselves, they should be included in the affixes passed to +.BR gd_alter_affixes (). +See EXAMPLES below for further details. If +.I prefix +or +.I suffix +is NULL, the corresponding affix will be unchanged. To remove an affix, set it +to the parent fragment's corresponding affix, which may be the empty string +(""). + +It is not possible to set affixes on the root format file (i.e. +.I fragment_index +may not be zero). + +The +.I dirfile +argument must point to a valid DIRFILE object previously created by a call to +.BR gd_open (3). + +.SH RETURN VALUE +Upon successful completion, +.BR gd_alter_affixes () +returns zero. On error, it returns -1 and sets the dirfile error to a non-zero +error value. Possible error values are: +.TP 8 +.B GD_E_ACCMODE +The specified dirfile was opened read-only. +.TP +.B GD_E_ALLOC +The library was unable to allocate memory. +.TP +.B GD_E_BAD_CODE +The supplied +.I prefix +or +.I suffix +contained invalid characters. +.TP +.B GD_E_BAD_DIRFILE +The supplied dirfile was invalid. +.TP +.B GD_E_BAD_INDEX +The supplied index was out of range. +.TP +.B GD_E_DUPLICATE +The supplied affixes would result in one or more field codes duplicating an +existing field code. +.TP +.B GD_E_PROTECTED +The metadata of the given fragment's parent fragment was protected from +change. +.PP +The dirfile error may be retrieved by calling +.BR gd_error (3). +A descriptive error string for the last error encountered can be obtained from +a call to +.BR gd_error_string (3). +.SH EXAMPLES +Dealing with affixes of parent fragments is relatively straightforward. Say, +for instance, fragment #1 has a prefix "A" and a suffix "B" and fragment #2 is +included from fragment #1. In this case any prefix for fragment #2 must end +with "A" and any suffix for fragment #2 must begin with "B". +.SH SEE ALSO +.BR gd_open (3), +.BR gd_error (3), +.BR gd_error_string (3), +.BR gd_fragment_affixes (3), +.BR gd_include_affix (3), +.BR dirfile (5), +.BR dirfile-format (5) Modified: trunk/getdata/man/gd_alter_bit.3 =================================================================== --- trunk/getdata/man/gd_alter_bit.3 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/man/gd_alter_bit.3 2012-03-03 03:54:58 UTC (rev 665) @@ -1,6 +1,6 @@ .\" gd_alter_bit.3. The gd_alter_bit man page. .\" -.\" Copyright (C) 2008, 2009, 2010 D. V. Wiebe +.\" Copyright (C) 2008, 2009, 2010, 2012 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_alter_bit 3 "3 November 2010" "Version 0.7.0" "GETDATA" +.TH gd_alter_bit 3 "1 January 2012" "Version 0.8.0" "GETDATA" .SH NAME gd_alter_bit, gd_alter_carray, gd_alter_clincom, gd_alter_const, gd_alter_cpolynom, gd_alter_crecip, gd_alter_divide, gd_alter_lincom, @@ -71,6 +71,10 @@ .HP .BI "int gd_alter_sbit(DIRFILE *" dirfile ", const char *" field_code , .BI "const char *" in_field ", gd_bit_t " bitnum ", gd_bit_t " numbits ); +.HP +.BI "int gd_alter_window(DIRFILE *" dirfile ", const char *" field_code , +.BI "const char *" in_field ", const char *" check_field , +.BI "gd_windop_t " windop ", gd_triplet_t " threshold ); .hy .ad n .SH DESCRIPTION @@ -130,8 +134,7 @@ .BR gd_alter_cpolynom () take an array of length .I poly_ord -+ 1 -containing the polynomial co-efficients ++ 1 containing the polynomial co-efficients .RI ( a " or " ca ). Some field parameters have special values which indicate no change should be @@ -148,6 +151,10 @@ .IR data_type ", or " const_type are equal to .BR GD_NULL , +or if +.I windop +is +.BR GD_WINDOP_UNK , these parameters will not be modified. All field parameters introduced with this interface must contain literal Modified: trunk/getdata/man/gd_alter_endianness.3.in =================================================================== --- trunk/getdata/man/gd_alter_endianness.3.in 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/man/gd_alter_endianness.3.in 2012-03-03 03:54:58 UTC (rev 665) @@ -2,7 +2,7 @@ .\" .\" @configure_input@ .\" -.\" Copyright (C) 2008, 2010 D. V. Wiebe +.\" Copyright (C) 2008, 2010, 2012 D. V. Wiebe .\" .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .\" @@ -15,7 +15,7 @@ .\" Texts. A copy of the license is included in the `COPYING.DOC' file .\" as part of this distribution. .\" -.TH gd_alter_endianness 3 "21 October 2010" "Version 0.7.0" "GETDATA" +.TH gd_alter_endianness 3 "1 January 2012" "Version 0.8.0" "GETDATA" .SH NAME gd_alter_endianness \(em modify the byte sex of fields in a dirfile .SH SYNOPSIS @@ -99,6 +99,11 @@ .B GD_E_ALLOC The library was unable to allocate memory. .TP +.B GD_E_ARGUMENT +The supplied +.I byte_sex +was invalid. +.TP .B GD_E_BAD_DIRFILE The supplied dirfile was invalid. .TP Modified: trunk/getdata/man/gd_alter_protection.3 =================================================================== --- trunk/getdata/man/gd_alter_protection.3 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/man/gd_alter_protection.3 2012-03-03 03:54:58 UTC (rev 665) @@ -1,6 +1,6 @@ .\" gd_alter_protection.3. The gd_alter_protection man page. .\" -.\" Copyright (C) 2008, 2010 D. V. Wiebe +.\" Copyright (C) 2008, 2010, 2012 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_alter_protection 3 "21 July 2010" "Version 0.7.0" "GETDATA" +.TH gd_alter_protection 3 "1 January 2012" "Version 0.8.0" "GETDATA" .SH NAME gd_alter_protection \(em modify the protection level of a dirfile fragment .SH SYNOPSIS @@ -72,6 +72,11 @@ .B GD_E_ACCMODE The specified dirfile was opened read-only. .TP +.B GD_E_ARGUMENT +The supplied +.I protection_level +was invalid. +.TP .B GD_E_BAD_DIRFILE The supplied dirfile was invalid. .TP Modified: trunk/getdata/man/gd_cbopen.3 =================================================================== --- trunk/getdata/man/gd_cbopen.3 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/man/gd_cbopen.3 2012-03-03 03:54:58 UTC (rev 665) @@ -1,6 +1,6 @@ .\" gd_cbopen.3. The gd_cbopen man page. .\" -.\" Copyright (C) 2008, 2009, 2010, 2011 D. V. Wiebe +.\" Copyright (C) 2008, 2009, 2010, 2011, 2012 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_cbopen 3 "17 August 2011" "Version 0.8.0" "GETDATA" +.TH gd_cbopen 3 "1 January 2012" "Version 0.8.0" "GETDATA" .SH NAME gd_cbopen, gd_open \(em open or create a dirfile .SH SYNOPSIS @@ -283,12 +283,21 @@ .B GD_SLIM_ENCODED Specifies that raw data files are compressed using the slimlib library. .TP +.B GD_SIE_ENCODED +Specified that raw data files are sample-index encoded, similar to run-length +encoding, suitable for data that change rarely. +.TP .B GD_TEXT_ENCODED Specifies that raw data files are encoded as text files containing one data sample per line. .TP .B GD_UNENCODED Specifies that raw data files are not encoded, but written verbatim to disk. +.TP +.B GD_ZZIP_ENCODED +Specifies that raw data files are compressed using the DEFLATE algorithm. All +raw data files for a given fragment are collected together and stored in a PKZIP +archive called raw.zip. .SS Standards Compliance The latest Dirfile Standards Version which this release of GetData understands @@ -428,6 +437,9 @@ parameter will be one of the following symbols indicating the type of syntax error encountered: .TP +.B GD_E_FORMAT_ALIAS +The parent specified for a meta field was an alias. +.TP .B GD_E_FORMAT_BAD_LINE The line was indecipherable. Typically this means that the line contained neither a reserved word, nor a field type. @@ -465,6 +477,9 @@ .B GD_E_FORMAT_LOCATION The parent of a metafield was defined in another fragment. .TP +.B GD_E_FORMAT_META_META +An attempt was made to use a metafield as the parent to a new metafield. +.TP .B GD_E_FORMAT_METARAW An attempt was made to add a RAW metafield. .TP @@ -474,7 +489,7 @@ .B GD_E_FORMAT_N_TOK An insufficient number of tokens was found on the line. .TP -.B GD_E_FORMAT_NO_PARENT +.B GD_E_FORMAT_NO_FIELD The parent of a metafield was not found. .TP .B GD_E_FORMAT_NUMBITS @@ -494,6 +509,9 @@ .TP .B GD_E_FORMAT_UNTERM The last token of the line was unterminated. +.TP +.B GD_E_FORMAT_WINDOP +The operation in a WINDOW field was not recognised. .PP .IR pdata -> filename and Modified: trunk/getdata/man/gd_delete.3 =================================================================== --- trunk/getdata/man/gd_delete.3 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/man/gd_delete.3 2012-03-03 03:54:58 UTC (rev 665) @@ -1,6 +1,6 @@ .\" gd_delete.3. The gd_delete man page. .\" -.\" Copyright (C) 2008, 2009, 2010 D. V. Wiebe +.\" Copyright (C) 2008, 2009, 2010, 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 gd_delete 3 "3 November 2010" "Version 0.7.0" "GETDATA" +.TH gd_delete 3 "1 January 2012" "Version 0.8.0" "GETDATA" .SH NAME -gd_delete \(em remove a field from a dirfile +gd_delete, gd_delete_alias \(em remove an entry from a dirfile .SH SYNOPSIS .B #include <getdata.h> .HP @@ -23,6 +23,9 @@ .ad l .BI "int gd_delete(DIRFILE *" dirfile ", const char *" field_code , .BI "int " flags ); +.HP +.BI "int gd_delete_alias(DIRFILE *" dirfile ", const char *" alias_name , +.BI "unsigned int " flags ); .hy .ad n .SH DESCRIPTION @@ -37,6 +40,18 @@ should not contain a representation suffix. The +.BR gd_delete_alias () +function behaves similarly, but deletes the alias specified by +.I alias_name +instead. (This function is needed, since passing +.I alias_name +to +.BR gd_delete () +as +.I field_code +would have resulted in the field pointed to by the alias being deleted instead.) + +The .I flags argument influences how the deletion attempt occurs. It may be zero, for the default behaviour, or else one or more of the following flags, bitwise or'd @@ -63,9 +78,9 @@ in their field specifications with the value of the scalar field. .TP .B GD_DEL_FORCE -Delete the indicated field, even if it is used in the specification of other +Delete the indicated entry, even if it is used in the specification of other fields, either as a input for a derived vector field or as a scalar parameter in -a field specification. +a field specification, or if it has aliases pointing to it. .TP .B GD_DEL_META If the field to be deleted has metafields attached to it, attempt to delete Added: trunk/getdata/man/gd_fragment_affixes.3 =================================================================== --- trunk/getdata/man/gd_fragment_affixes.3 (rev 0) +++ trunk/getdata/man/gd_fragment_affixes.3 2012-03-03 03:54:58 UTC (rev 665) @@ -0,0 +1,86 @@ +.\" gd_fragment_affix.3. The gd_fragment_affix man page. +.\" +.\" Copyright (C) 2012 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_fragment_affix 3 "1 January 2012" "Version 0.8.0" "GETDATA" +.SH NAME +gd_fragment_affix \(em report the field affixes of a fragment of a dirfile database +.SH SYNOPSIS +.B #include <getdata.h> +.HP +.nh +.ad l +.BI "int gd_fragment_affix(DIRFILE *" dirfile ", int " fragment_index , +.BI "char **" prefix ", char **" suffix ); +.hy +.ad n +.SH DESCRIPTION +The +.BR gd_fragment_affix () +function queries a dirfile(5) database specified by +.I dirfile +and returns the field affixes for the fragment indexed by +.IR fragment_index . +The field prefix and suffix are appended to all field codes found in the +specified fragment. + +The +.I prefix +and +.I suffix +parameters point to memory locations in which store the addresses of the +returned strings. + +The +.I dirfile +argument must point to a valid DIRFILE object previously created by a call to +.BR gd_open (3). + +.SH RETURN VALUE +Upon successful completion, +.BR gd_fragment_affix () +returns zero. The prefix and suffix are reported in +.BR malloc (3)'d +buffers whose addresses are returned in +.BI * prefix +and +.BI * suffix\fR. +They should be deallocated by the caller when no longer needed by calling +.BR free (3). + +On error, -1 is returned and sets the dirfile error to a non-zero error value. +In this case, the values of +.BI * prefix +and +.BI * suffix +are unspecified, but will NOT be pointers to valid allocated memory. Possible +dirfile error values are: +.TP 8 +.B GD_E_BAD_DIRFILE +The supplied dirfile was invalid. +.TP +.B GD_E_BAD_INDEX +The supplied index was out of range. +.PP +The dirfile error may be retrieved by calling +.BR gd_error (3). +A descriptive error string for the last error encountered can be obtained from +a call to +.BR gd_error_string (3). +.SH SEE ALSO +.BR gd_alter_frameoffset (3), +.BR gd_include_affixes (3), +.BR gd_open (3), +.BR dirfile (5), +.BR dirfile-format (5) Modified: trunk/getdata/man/gd_fragment_index.3 =================================================================== --- trunk/getdata/man/gd_fragment_index.3 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/man/gd_fragment_index.3 2012-03-03 03:54:58 UTC (rev 665) @@ -1,6 +1,6 @@ .\" gd_fragment_index.3. The gd_fragment_index man page. .\" -.\" Copyright (C) 2008, 2009, 2010, 2011 D. V. Wiebe +.\" Copyright (C) 2008, 2009, 2010, 2011, 2012 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_fragment_index 3 "18 August 2011" "Version 0.8.0" "GETDATA" +.TH gd_fragment_index 3 "1 January 2012" "Version 0.8.0" "GETDATA" .SH NAME gd_fragment_index \(em retrieve the fragment containing a dirfile field .SH SYNOPSIS @@ -22,7 +22,7 @@ .nh .ad l .BI "int gd_fragment_index(const DIRFILE *" dirfile ", const char" -.BI * field_code ); +.BI * entry_name ); .hy .ad n .SH DESCRIPTION @@ -30,11 +30,16 @@ .BR gd_fragment_index () function queries a dirfile(5) database specified by .I dirfile -and returns the index number of the fragment defining the field specified by -.IR field_code . -If -.I field_code -contains a representation suffix, it will be ignored. +and returns the index number of the fragment defining the field or alias +specified by +.IR entry_name , +which may not contain a representation suffix. + +This is one of the few GetData functions which does not resolve aliases: +supplying the name of an alias as +.I entry_name +will return the index of the fragment containing the alias itself and not that +of its target. .SH RETURN VALUE Upon successful completion, .BR gd_fragment_index () @@ -47,17 +52,12 @@ The library was unable to allocate memory. .TP .B GD_E_BAD_CODE -The field specified by -.I field_code +The entry specified by +.I entry_name was not found in the database. .TP .B GD_E_BAD_DIRFILE The supplied dirfile was invalid. -.TP -.B GD_E_BAD_REPR -The representation suffix specified in -.I field_code -was not recognised. .PP The dirfile error may be retrieved by calling .BR gd_error (3). Added: trunk/getdata/man/gd_hidden.3 =================================================================== --- trunk/getdata/man/gd_hidden.3 (rev 0) +++ trunk/getdata/man/gd_hidden.3 2012-03-03 03:54:58 UTC (rev 665) @@ -0,0 +1,77 @@ +.\" gd_hidden.3. The gd_hidden man page. +.\" +.\" Copyright (C) 2012 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_hidden 3 "1 January 2012" "Version 0.8.0" "GETDATA" +.SH NAME +gd_hidden \(em retrieve the fragment containing a dirfile field +.SH SYNOPSIS +.B #include <getdata.h> +.HP +.nh +.ad l +.BI "int gd_hidden(const DIRFILE *" dirfile ", const char" +.BI * entry_name ); +.hy +.ad n +.SH DESCRIPTION +The +.BR gd_hidden () +function queries a dirfile(5) database specified by +.I dirfile +and indicates whether the field or alias called +.IR entry_name +is hidden or not. + +A hidden entry does not appear in the field lists returned by the functions +.BR gd_field_list (3), +.BR gd_field_list_by_type (3), +.BR gd_vectors (3), +.BR gd_constants (3), +and +.BR gd_strings (3). +These omissions are also reflected in the counts returned by the corresponding +field counting functions +.RB ( gd_nfields (3), +&c.). +.SH RETURN VALUE +Upon successful completion, +.BR gd_hidden () +returns one if the field or alias is hidden, or zero if the entry is not hidden. +On error it returns -1 and sets the dirfile error a non-zero error value. (As a +result, the caller checking simply whether the return value of this function is +non-zero is usually an error.) Possible error values are: +.TP 8 +.B GD_E_BAD_CODE +The field specified by +.I field_code +was not found in the database. +.TP +.B GD_E_BAD_DIRFILE +The supplied dirfile was invalid. +.PP +The dirfile error may be retrieved by calling +.BR gd_error (3). +A descriptive error string for the last error encountered can be obtained from +a call to +.BR gd_error_string (3). + +.SH SEE ALSO +.BR gd_entry (3), +.BR gd_field_list (3), +.BR gd_hide (3), +.BR gd_nfields (3), +.BR gd_open (3), +.BR gd_unhide (3), +.BR dirfile (5) Added: trunk/getdata/man/gd_hide.3 =================================================================== --- trunk/getdata/man/gd_hide.3 (rev 0) +++ trunk/getdata/man/gd_hide.3 2012-03-03 03:54:58 UTC (rev 665) @@ -0,0 +1,89 @@ +.\" gd_hide.3. The gd_hidden man page. +.\" +.\" Copyright (C) 2012 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_hide 3 "1 January 2012" "Version 0.8.0" "GETDATA" +.SH NAME +gd_hide, gd_unhide \(em hide or unhide a dirfile database entry +.SH SYNOPSIS +.B #include <getdata.h> +.HP +.nh +.ad l +.BI "int gd_hide(const DIRFILE *" dirfile ", const char" +.BI * entry_name ); +.HP +.BI "int gd_unhide(const DIRFILE *" dirfile ", const char" +.BI * entry_name ); +.hy +.ad n +.SH DESCRIPTION +The +.BR gd_hide () +function hides the field or alias called +.IR entry_name +in the dirfile(5) database specified by +.I dirfile +and indicates whether the field or alias called is hidden or not. Similarly, +the +.BR gd_unhide () +function unhides the specified entry. + +A hidden entry does not appear in the field lists returned by the functions +.BR gd_field_list (3), +.BR gd_field_list_by_type (3), +.BR gd_vectors (3), +.BR gd_constants (3), +and +.BR gd_strings (3). +These omissions are also reflected in the counts returned by the corresponding +field counting functions +.RB ( gd_nfields (3), +&c.). A hidden field is otherwise no different than an unhidden field. +.SH RETURN VALUE +Upon successful completion, +.BR gd_hide () +and +.BR gd_unhide () +return zero. On error they returns -1 and sets the dirfile error a non-zero +error value. Possible error values are: +.TP 8 +.B GD_E_ACCMODE +The specified dirfile was opened read-only. +.TP +.B GD_E_BAD_CODE +The field specified by +.I field_code +was not found in the database. +.TP +.B GD_E_BAD_DIRFILE +The supplied dirfile was invalid. +.TP +.B GD_E_PROTECTED +The metadata of the affected format specification fragments was protected from +change. +.PP +The dirfile error may be retrieved by calling +.BR gd_error (3). +A descriptive error string for the last error encountered can be obtained from +a call to +.BR gd_error_string (3). + +.SH SEE ALSO +.BR gd_entry (3), +.BR gd_field_list (3), +.BR gd_hidden (3), +.BR gd_nfields (3), +.BR gd_open (3), +.BR dirfile (5) Modified: trunk/getdata/man/gd_move.3 =================================================================== --- trunk/getdata/man/gd_move.3 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/man/gd_move.3 2012-03-03 03:54:58 UTC (rev 665) @@ -1,6 +1,6 @@ .\" gd_move.3. The gd_move man page. .\" -.\" Copyright (C) 2008, 2009, 2010 D. V. Wiebe +.\" Copyright (C) 2008, 2009, 2010, 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 gd_move 3 "21 July 2010" "Version 0.7.0" "GETDATA" +.TH gd_move 3 "1 January 2012" "Version 0.8.0" "GETDATA" .SH NAME -gd_move \(em move a dirfile field between format specification fragments +gd_move, gd_move_alias \(em move a dirfile entry between format specification fragments .SH SYNOPSIS .B #include <getdata.h> .HP @@ -23,6 +23,9 @@ .ad l .BI "int gd_move(DIRFILE *" dirfile ", const char" .BI * field_code ", int " new_fragment ", int " move_data ); +.HR +.BI "int gd_move_alias(DIRFILE *" dirfile ", const char" +.BI * alias_name ", int " new_fragment ); .hy .ad n .SH DESCRIPTION @@ -33,15 +36,28 @@ which should not have a representation suffix, defined in the dirfile specified by .IR dirfile -from it's current format specification fragment to the fragment index by +from it's current format specification fragment to the fragment indexed by .IR new_fragment . If the field is already defined in the fragment index by .IR new_fragment , this function does nothing. +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 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 non-zero, and +is one, and .I field_code specifies a .B RAW Added: trunk/getdata/man/gd_naliases.3 =================================================================== --- trunk/getdata/man/gd_naliases.3 (rev 0) +++ trunk/getdata/man/gd_naliases.3 2012-03-03 03:54:58 UTC (rev 665) @@ -0,0 +1,62 @@ +.\" gd_naliases.3. The gd_naliases man page. +.\" +.\" Copyright (C) 2012 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_naliases 3 "1 January 2012" "Version 0.8.0" "GETDATA" +.SH NAME +gd_naliases \(em report the number of aliases of a field in a dirfile +.SH SYNOPSIS +.B #include <getdata.h> +.HP +.nh +.ad l +.BI "unsigned int gd_naliases(DIRFILE *" dirfile ", const char *" field_code ); +.hy +.ad n +.SH DESCRIPTION +The +.BR gd_naliases () +function queries a dirfile(5) database specified by +.I dirfile +and returns the number of aliases of the field specified by +.IR field code . + +The +.I dirfile +argument must point to a valid DIRFILE object previously created by a call to +.BR gd_open (3). + +.SH RETURN VALUE +Upon successful completion, +.BR gd_naliases () +returns the number of vector fields in the dirfile. If successful, this count +will be at least one. On error, it returns zero and sets the dirfile error +to a non-zero error value. Possible error values are: +.TP 8 +.B GD_E_BAD_CODE +The supplied field code was not found in the database. +.TP +.B GD_E_BAD_DIRFILE +The supplied dirfile was invalid. +.PP +The dirfile error may be retrieved by calling +.BR gd_error (3). +A descriptive error string for the last error encountered can be obtained from +a call to +.BR gd_error_string (3). +.SH SEE ALSO +.BR dirfile (5), +.BR gd_open (3), +.BR gd_aliases (3), +.BR gd_alias_target (3) Modified: trunk/getdata/man/gd_rename.3 =================================================================== --- trunk/getdata/man/gd_rename.3 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/man/gd_rename.3 2012-03-03 03:54:58 UTC (rev 665) @@ -1,6 +1,6 @@ .\" gd_rename.3. The gd_rename man page. .\" -.\" Copyright (C) 2008, 2009, 2010, 2011 D. V. Wiebe +.\" Copyright (C) 2008, 2009, 2010, 2011, 2012 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 "19 August 2011" "Version 0.8.0" "GETDATA" +.TH gd_rename 3 "1 January 2012" "Version 0.8.0" "GETDATA" .SH NAME gd_rename \(em change the name of a dirfile field .SH SYNOPSIS @@ -22,7 +22,7 @@ .nh .ad l .BI "int gd_rename(DIRFILE *" dirfile ", const char" -.BI * old_code ", const char *" new_name ", int " move_data ); +.BI * old_code ", const char *" new_name ", unsigned " flags ); .hy .ad n .SH DESCRIPTION Modified: trunk/getdata/src/fragment.c =================================================================== --- trunk/getdata/src/fragment.c 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/src/fragment.c 2012-03-03 03:54:58 UTC (rev 665) @@ -211,6 +211,19 @@ return -1; } + if ((D->flags & GD_ACCMODE) == GD_RDONLY) { + _GD_SetError(D, GD_E_ACCMODE, 0, NULL, 0, NULL); + dreturn("%i", -1); + return -1; + } + + if (D->fragment[D->fragment[index].parent].protection & GD_PROTECT_FORMAT) { + _GD_SetError(D, GD_E_PROTECTED, GD_E_PROTECTED_FORMAT, NULL, 0, + D->fragment[D->fragment[index].parent].cname); + dreturn("%i", -1); + return -1; + } + /* affixes to keep */ if (!prefix) prefix = D->fragment[index].prefix; Modified: trunk/getdata/src/getdata.h.in =================================================================== --- trunk/getdata/src/getdata.h.in 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/src/getdata.h.in 2012-03-03 03:54:58 UTC (rev 665) @@ -440,6 +440,7 @@ #endif #define GD_PERMISSIVE 0x00004000 /* be permissive */ +#define GD_TRUNCSUB 0x00008000 /* truncate subdirfiles */ #define GD_ENCODING 0x0F000000 /* mask */ #define GD_AUTO_ENCODED 0x00000000 /* Encoding scheme unknown */ Modified: trunk/getdata/src/open.c =================================================================== --- trunk/getdata/src/open.c 2012-03-02 02:57:19 UTC (rev 664) +++ trunk/getdata/src/open.c 2012-03-03 03:54:58 UTC (rev 665) @@ -21,13 +21,135 @@ */ #include "internal.h" +/* crawl the directory, and delete everything */ +static int _GD_TruncDir(DIRFILE *D, int dirfd, const char *dirfile, int root) +{ + int format_trunc = 0; + DIR* dir; + struct dirent* lamb; + struct stat statbuf; + + dtrace("%p, %i, \"%s\", %i", D, dirfd, dirfile, root); + +#if defined(HAVE_FDOPENDIR) && !defined(GD_NO_DIR_OPEN) + /* only need to duplicate the fd of the root directory; otherwise this + * function will close the fd */ + if (root && (fd = dup(dirfd)) == -1) { + _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_DIR, dirfile, errno, NULL); + dreturn("%i", -1); + return -1; + } + dir = fdopendir(fd); +#else + dir = opendir(dirfile); +#endif + + if (dir == NULL) { + _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_DIR, dirfile, errno, NULL); + dreturn("%i", -1); + return -1; + } + + while ((lamb = readdir(dir)) != NULL) { + if (lamb->d_name[0] == '.' && lamb->d_name[1] == '\0') { + continue; /* skip current dir */ + } else if (lamb->d_name[0] == '.' && lamb->d_name[1] == '.' && + lamb->d_name[2] == '\0') + { + continue; /* skip parent dir */ + } else { + char *name = (char *)malloc(strlen(dirfile) + strlen(lamb->d_name) + 2); + sprintf(name, "%s%c%s", dirfile, GD_DIRSEP, lamb->d_name); + if ( +#if defined(HAVE_FSTATAT) && !defined(GD_NO_DIR_OPEN) + fstatat(dirfd, lamb->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) +#elif HAVE_LSTAT + lstat(name, &statbuf) +#else + stat(name, &statbuf) +#endif + ) + { + _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_STAT, name, errno, NULL); + free(name); + closedir(dir); + dreturn("%i", -1); + return -1; + } + free(name); + } + + /* check file type */ + switch (statbuf.st_mode & S_IFMT) { + case S_IFREG: + case S_IFBLK: + case S_IFIFO: + case S_IFCHR: + case S_IFLNK: + if (root && strcmp(lamb->d_name, "format") == 0) { + /* don't delete the format file; we'll truncate it later */ + format_trunc = 1; + } else if (gd_UnlinkAt(D, dirfd, lamb->d_name, 0)) { + char *name = (char *)malloc(strlen(dirfile) + strlen(lamb->d_name) + + 2); + sprintf(name, "%s%c%s", dirfile, GD_DIRSEP, lamb->d_name); + _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_UNLINK, name, errno, NULL); + free(name); + closedir(dir); + dreturn("%i", -1); + return -1; + } + break; + case S_IFDIR: + /* descend into subdir if requested */ + if (D->flags & GD_TRUNCSUB) { + int subdirfd; + char *subdir = (char *)malloc(strlen(dirfile) + strlen(lamb->d_name) + + 2); + sprintf(subdir, "%s%c%s", dirfile, GD_DIRSEP, lamb->d_name); +#ifdef GD_NO_DIR_OPEN + subdirfd = 0; /* unused */ +#else + if (( +#ifdef HAVE_OPENAT + subdirfd = openat(dirfd, lamb->d_name, O_RDONLY) +#else + subdirfd = open(subdir, O_RDONLY) +#endif + ) < 0) + { + _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_STAT, subdir, errno, NULL); + free(subdir); + dreturn("%i", -1); + return -1; + } +#endif + /* descend -- this will close subdirfd */ + _GD_TruncDir(D, subdirfd, subdir, 0); + free(subdir); + + /* delete */ +#ifdef HAVE_UNLINKAT___ + unlinkat(dirfd, lamb->d_name, /* AT_...? */); +#else + rmdir(subdir); +#endif + } + } + } + + closedir(dir); + dreturn("%i", format_trunc); + return format_trunc; +} + /* attempt to open or create a new dirfile - set error appropriately */ static FILE *_GD_CreateDirfile(DIRFILE *restrict D, int dirfd, int dir_error, char *restrict dirfile) { +#ifndef GD_NO_DIR_OPEN struct stat statbuf; - DIR* dir; - struct dirent* lamb; +#endif int fd = -1; int format_error = 0, format_trunc = 0; FILE* fp = NULL; @@ -103,7 +225,6 @@ * (specifically, we haven't bothered to see if the format file is parsable) * could be problematic if users use GD_TRUNC cavalierly. */ if (D->flags & GD_TRUNC && !format_error) { - /* This file isn't going to be around much longer */ close(fd); /* can't truncate a read-only dirfile */ @@ -114,64 +235,12 @@ return NULL; } -#ifdef HAVE_FDOPENDIR - /* crawl the directory, and delete everything */ - if ((fd = dup(dirfd)) == -1) { - _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_DIR, dirfile, errno, NULL); + format_trunc = _GD_TruncDir(D, dirfd, dirfile, 1); + if (format_trunc < 0) { free(dirfile); dreturn("%p", NULL); return NULL; } - dir = fdopendir(fd); -#else - dir = opendir(dirfile); -#endif - - if (dir == NULL) { - _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_DIR, dirfile, errno, NULL); - free(dirfile); - dreturn("%p", NULL); - return NULL; - } - - while ((lamb = readdir(dir)) != NULL) { - if (gd_StatAt(D, dirfd, lamb->d_name, &statbuf, AT_SYMLINK_NOFOLLOW)) { - char *name = (char *)malloc(strlen(dirfile) + strlen(lamb->d_name) + 2); - strcat(strcat(strcpy(name, dirfile), "/"), lamb->d_name); - - _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_STAT, name, errno, NULL); - free(dirfile); - free(name); - closedir(dir); - dreturn("%p", NULL); - return NULL; - } - - /* only delete regular files */ - if (S_ISREG(statbuf.st_mode) -#ifdef S_ISLNK - || S_ISLNK(statbuf.st_mode) -#endif - ) - { - /* don't delete the format file; we'll truncate it later */ - if (strcmp(lamb->d_name, "format") == 0) { - format_trunc = 1; - } else if (gd_UnlinkAt(D, dirfd, lamb->d_name, 0)) { - char *name = (char *)malloc(strlen(dirfile) + strlen(lamb->d_name) - + 2); - strcat(strcat(strcpy(name, dirfile), "/"), lamb->d_name); - _GD_SetError(D, GD_E_TRUNC, GD_E_TRUNC_UNLINK, name, errno, NULL); - free(dirfile); - free(name); - closedir(dir); - dreturn("%p", NULL); - return NULL; - } - } - } - - closedir(dir); } /* Create, if needed */ @@ -300,7 +369,7 @@ * so get the current directory, so that we're protected against the caller * using chdir. */ - + /* canonicalise the path */ dirfile = _GD_CanonicalPath(NULL, filedir); @@ -463,7 +532,7 @@ _GD_SetError(D, GD_E_BAD_REFERENCE, GD_E_REFERENCE_TYPE, NULL, 0, ref_name); else - D->reference_field = E; + D->reference_field = E; free(ref_name); } Property changes on: trunk/getdata/test ___________________________________________________________________ Modified: svn:ignore - Makefile Makefile.in *.o *.odirfile *.swp *.exe .deps .libs add add_affix add_alias add_bit add_bit_bitnum add_bit_bitsize add_bit_invalid add_bit_numbits 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_invalid add_lincom_nfields add_linterp add_linterp_invalid add_meta add_meta_alias add_mplex add_mplex_val add_multiply add_multiply_invalid add_phase add_phase_invalid add_polynom add_protect add_raw add_raw_include add_raw_invalid add_raw_spf add_raw_type add_rdonly add_recip add_resolv add_sbit add_scalar add_scalar_carray 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_list alias_list_alias alias_list_missing alias_num alias_num_alias alias_num_missing alias_target alias_target_alias alias_target_missing alter_bit_bitnum alter_bit_numbits alter_carray_len alter_carray_type alter_const alter_cpolynom alter_crecip alter_crecip89 alter_crecip_zero alter_divide alter_entry alter_entry_affix alter_entry_hidden alter_entry_recode alter_entry_scalar2a alter_entry_scalar2n alter_entry_scalar3 alter_entry_scalar4 alter_lincom_23 alter_lincom_32 alter_lincom_input alter_lincom_offset alter_lincom_slope alter_linterp alter_linterp_move alter_mplex alter_mspec alter_mspec_affix alter_multiply alter_phase alter_polynom_coeff alter_polynom_input alter_polynom_ord alter_raw_spf alter_raw_type alter_recip alter_recip_zero alter_spec alter_spec_affix alter_spec_meta alter_window ascii_add ascii_get ascii_get_get ascii_nframes ascii_put bof bof_lincom bof_phase bzip_get bzip_get_get bzip_move_from bzip_nframes bzip_put close close_bad close_discard close_null convert_complex128_complex64 convert_complex128_float64 convert_complex128_int64 convert_complex128_uint64 convert_complex64_complex128 convert_complex64_float64 convert_complex64_int64 convert_complex64_uint64 convert_float32_complex128 convert_float32_complex64 convert_float32_float64 convert_float32_int16 convert_float32_int32 convert_float32_int64 convert_float32_int8 convert_float32_uint16 convert_float32_uint32 convert_float32_uint64 convert_float32_uint8 convert_float64_complex128 convert_float64_complex64 convert_float64_float32 convert_float64_int16 convert_float64_int32 convert_float64_int64 convert_float64_int8 convert_float64_uint16 convert_float64_uint32 convert_float64_uint64 convert_float64_uint8 convert_int16_complex128 convert_int16_complex64 convert_int16_float32 convert_int16_float64 convert_int16_int32 convert_int16_int64 convert_int16_int8 convert_int16_uint16 convert_int16_uint32 convert_int16_uint64 convert_int16_uint8 convert_int32_complex128 convert_int32_complex64 convert_int32_float32 convert_int32_float64 convert_int32_int16 convert_int32_int64 convert_int32_int8 convert_int32_uint16 convert_int32_uint32 convert_int32_uint64 convert_int32_uint8 convert_int64_complex128 convert_int64_complex64 convert_int64_float32 convert_int64_float64 convert_int64_int16 convert_int64_int32 convert_int64_int8 convert_int64_uint16 convert_int64_uint32 convert_int64_uint64 convert_int64_uint8 convert_int8_complex128 convert_int8_complex64 convert_int8_float32 convert_int8_float64 convert_int8_int16 convert_int8_int32 convert_int8_int64 convert_int8_uint16 convert_int8_uint32 convert_int8_uint64 convert_int8_uint8 convert_uint16_complex128 convert_uint16_complex64 convert_uint16_float32 convert_uint16_float64 convert_uint16_int16 convert_uint16_int32 convert_uint16_int64 convert_uint16_int8 convert_uint16_uint32 convert... [truncated message content] |
From: <ket...@us...> - 2012-03-02 02:57:29
|
Revision: 664 http://getdata.svn.sourceforge.net/getdata/?rev=664&view=rev Author: ketiltrout Date: 2012-03-02 02:57:19 +0000 (Fri, 02 Mar 2012) Log Message: ----------- * gd_tokenise() (with bindings) * Allow adding meta fields using "parent/meta" vi gd_add[_<type>] * Don't indiscriminantly cast between data and code pointers in the F77 bindings. Modified Paths: -------------- trunk/getdata/ChangeLog trunk/getdata/bindings/cxx/dirfile.cpp trunk/getdata/bindings/cxx/getdata/dirfile.h trunk/getdata/bindings/cxx/test/big_test.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/f77/test/gdcopn.f trunk/getdata/bindings/idl/getdata.c trunk/getdata/bindings/idl/test/big_test.pro trunk/getdata/bindings/perl/GetData.xs trunk/getdata/bindings/perl/t/big_test.t trunk/getdata/bindings/python/pydirfile.c trunk/getdata/bindings/python/test/big_test.py trunk/getdata/doc/list.tests trunk/getdata/man/checkdirfile.1 trunk/getdata/man/dirfile2ascii.1 trunk/getdata/man/gd_add.3 trunk/getdata/man/gd_add_bit.3 trunk/getdata/man/gd_madd_bit.3 trunk/getdata/src/add.c trunk/getdata/src/errors.c trunk/getdata/src/getdata.h.in trunk/getdata/src/internal.h trunk/getdata/src/mod.c trunk/getdata/src/parse.c trunk/getdata/test/Makefile.am trunk/getdata/test/ascii_get.c trunk/getdata/test/ascii_get_get.c trunk/getdata/test/ascii_nframes.c trunk/getdata/test/ascii_put.c Added Paths: ----------- trunk/getdata/test/add_meta.c trunk/getdata/test/add_meta_alias.c Property Changed: ---------------- trunk/getdata/test/ Modified: trunk/getdata/ChangeLog =================================================================== --- trunk/getdata/ChangeLog 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/ChangeLog 2012-03-02 02:57:19 UTC (rev 664) @@ -1,3 +1,38 @@ +2012-03-02 D. V. Wiebe <ge...@ke...> svn:664 + * src/errors.c: Added GD_E_ARGUMENT:GD_E_ARG_NODATA. + * src/parse.c (_GD_Tokenise): Take number of columns to return. + * src/parse.c (gd_tokenise): Added. + * src/internal.h: Added _GD_DIRFILE->tok_pos. + + * src/parse.c (_GD_CheckParent): Destatickify, and modify for use by + _GD_Add. + * src/add.c (_GD_Add): Call _GD_CheckParent to automatically allow + parent/meta style metafield addition via gd_add[_<whatever>](). + + * bindings/python/pydirfile.c (gdpy_dirfile_tokenise) + bindings/cxx/dirfile.cpp (Dirfile::Tokenise) bindings/perl/GetData.xs + (tokenise) bindings/f77/getdata.f90.in (fgd_tokenise) + bindings/f77/fgetdata.c (GDTOKE) bindings/idl/getdata.c (gdidl_tokenise): + Added. + + * bindings/python/test/big_test.py bindings/cxx/test/big_test.cpp + bindings/perl/t/big_test.t bindings/f77/test/big_test.f + bindings/f77/test/big_test95.f90 bindings/idl/test/big_test.pro: Add test + #232. + + * bindings/f77/getdata.f90.in (fgd_fragment_affixes): Fix GDFRAF call. + + * bindings/f77/fgetdata.c (_GDF_SetDirfile _GDF_Callback GDCOPN GDCLBK): + Don't cast between data and code pointers. Encapsulate the F77 callback + function in a container. + * bindings/f77/fgetdata.c (GDNOCB): Added. + * bindings/f77/test/gdcopn.f: Add GDCLBK and GDNOCB tests. + + * test/ascii_get.c test/ascii_put.c test/ascii_get_get.c + test/ascii_nframes.c: Delete FOPEN_TEXT. + + * test/add_meta.c test/add_meta_alias.c: Added. + 2012-02-16 D. V. Wiebe <ge...@ke...> svn:658 * src/getdata.c (_GD_DoLincom): Get the correct SPFs. * test/get_lincom_spf.c: Added. Modified: trunk/getdata/bindings/cxx/dirfile.cpp =================================================================== --- trunk/getdata/bindings/cxx/dirfile.cpp 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/cxx/dirfile.cpp 2012-03-02 02:57:19 UTC (rev 664) @@ -515,3 +515,8 @@ { return gd_unhide(D, field_code); } + +char *Dirfile::Tokenise(const char *string) +{ + return gd_tokenise(D, string); +} Modified: trunk/getdata/bindings/cxx/getdata/dirfile.h =================================================================== --- trunk/getdata/bindings/cxx/getdata/dirfile.h 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/cxx/getdata/dirfile.h 2012-03-02 02:57:19 UTC (rev 664) @@ -247,6 +247,8 @@ off_t Tell(const char* field_code) const; + char *Tokenise(const char *string = NULL); + int UnHide(const char* field_code) const; int UnInclude(int fragment_index, int del = 0) const; Modified: trunk/getdata/bindings/cxx/test/big_test.cpp =================================================================== --- trunk/getdata/bindings/cxx/test/big_test.cpp 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/cxx/test/big_test.cpp 2012-03-02 02:57:19 UTC (rev 664) @@ -1630,12 +1630,22 @@ CHECK_INT2(231, 6, ent->CountMax(), 7); delete ent; + // 232: gd_tokenise + str = d->Tokenise("\"test1 test2\" test3\\ test4"); + CHECK_OK2(232, 1); + CHECK_STRING2(232, 2, str, "test1 test2"); + str = d->Tokenise(); + CHECK_OK2(232, 3); + CHECK_STRING2(232, 4, str, "test3 test4"); + + + // =================================================================== d->Discard(); delete d; Modified: trunk/getdata/bindings/f77/fgetdata.c =================================================================== --- trunk/getdata/bindings/f77/fgetdata.c 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/f77/fgetdata.c 2012-03-02 02:57:19 UTC (rev 664) @@ -39,6 +39,12 @@ static DIRFILE* f77dirfiles[GDF_N_DIRFILES]; static int f77dirfiles_initialised = 0; +/* casting data pointers to function pointers is prohibited in C. This + * container is used to get around that */ +static struct _GDF_callback_container { + _GDF_callback_t func; +} f77callbacks[GDF_N_DIRFILES]; + /* initialise the f77dirfiles array */ static void _GDF_InitDirfiles(void) { @@ -102,6 +108,7 @@ for (i = 1; i < GDF_N_DIRFILES; ++i) if (f77dirfiles[i] == NULL) { f77dirfiles[i] = D; + f77callbacks[i].func = NULL; dreturn("%i", i); return i; } @@ -182,17 +189,19 @@ /* callback wrapper */ static int _GDF_Callback(gd_parser_data_t* pdata, void* f77_callback) { + struct _GDF_callback_container *c = + (struct _GDF_callback_container*)f77_callback; + int unit; int r = GD_SYNTAX_ABORT; dtrace("%p, %p", pdata, f77_callback); - if (f77_callback != NULL) { + if (c != NULL && c->func != NULL) { unit = _GDF_SetDirfile((DIRFILE*)pdata->dirfile); - (*(void(*)(int*, const int*, const int*, char*, const int*, - const char*))f77_callback)(&r, &unit, &pdata->suberror, - pdata->line, &pdata->linenum, pdata->filename); + (c->func)(&r, &unit, &pdata->suberror, pdata->line, &pdata->linenum, + pdata->filename); pdata->line[GD_MAX_LINE_LENGTH - 1] = '\0'; @@ -2262,34 +2271,69 @@ /* gd_cbopen wrapper */ void F77_FUNC(gdcopn, GDCOPN) (int* dirfile, const char* dirfilename, - const int* dirfilename_l, const int* flags, const void* callback) + const int* dirfilename_l, const int* flags, const _GDF_callback_t callback) { + const struct _GDF_callback_container temp = { callback }; + DIRFILE *D; char *out; dtrace("%p, %p, %i, %x, %p", dirfile, dirfilename, *dirfilename_l, *flags, callback); out = (char *)malloc(*dirfilename_l + 1); + _GDF_CString(out, dirfilename, *dirfilename_l); - *dirfile = _GDF_SetDirfile(gd_cbopen(_GDF_CString(out, dirfilename, - *dirfilename_l), *flags, (callback == 0) ? NULL : _GDF_Callback, - (callback == 0) ? NULL : (void*)callback)); + D = gd_cbopen(out, *flags, _GDF_Callback, (void*)&temp); + *dirfile = _GDF_SetDirfile(D); + /* save the callback */ + f77callbacks[*dirfile].func = callback; + /* and tell getdata its new location */ + gd_parser_callback(D, _GDF_Callback, f77callbacks + *dirfile); + free(out); dreturn("%i", *dirfile); } /* gd_parser_callback wrapper */ -void F77_FUNC(gdclbk, GDCLBK) (const int* dirfile, const void* callback) +void F77_FUNC(gdclbk, GDCLBK) (const int* dirfile, + const _GDF_callback_t callback) { dtrace("%i, %p", *dirfile, callback); - gd_parser_callback(_GDF_GetDirfile(*dirfile), (callback == 0) ? NULL - : _GDF_Callback, (callback == 0) ? NULL : (void*)callback); + /* ensure *dirfile is sane */ + if (*dirfile < 0 || *dirfile >= GDF_N_DIRFILES) { + dreturnvoid(); + return; + } + /* we only have to modify GetData's callback pointer if f77callbacks is + * NULL for this dirfile (inidicating no previous callback); otherwise, just + * update the saved callback pointer */ + if (f77callbacks[*dirfile].func == NULL) { + f77callbacks[*dirfile].func = callback; + gd_parser_callback(_GDF_GetDirfile(*dirfile), _GDF_Callback, + f77callbacks + *dirfile); + } else + f77callbacks[*dirfile].func = callback; + dreturnvoid(); } +/* deregister a callback function (ie. gd_parser_callback(..., NULL) */ +void F77_FUNC(gdnocb, GDNOCB) (const int* dirfile) +{ + dtrace("%i", *dirfile); + + /* ensure *dirfile is sane */ + if (*dirfile >= 0 && *dirfile < GDF_N_DIRFILES) { + f77callbacks[*dirfile].func = NULL; + gd_parser_callback(_GDF_GetDirfile(*dirfile), NULL, NULL); + } + + dreturnvoid(); +} + /* gd_alter_bit wrapper */ void F77_FUNC(gdalbt, GDALBT) (const int* dirfile, const char* field_code, const int* field_code_l, const char* in_field, const int* in_field_l, @@ -3410,10 +3454,7 @@ targ = gd_alias_target(_GDF_GetDirfile(*dirfile), _GDF_CString(fc, field_code, *field_code_l)); - if (targ) - _GDF_FString(target, target_l, targ); - else - *target_l = 0; + _GDF_FString(target, target_l, targ); free(fc); @@ -3689,13 +3730,13 @@ const int* prefix_l, const char* suffix, const int* suffix_l, const int* flags) { - dtrace("%i, %p, %i, %i, %p, %i, %p, %i, %i", *dirfile, file, *file_l, - *fragment_index, prefix, *prefix_l, suffix, *suffix_l, *flags); - char* fi = (char *)malloc(*file_l + 1); char* px = (char *)malloc(*prefix_l + 1); char* sx = (char *)malloc(*suffix_l + 1); + dtrace("%i, %p, %i, %i, %p, %i, %p, %i, %i", *dirfile, file, *file_l, + *fragment_index, prefix, *prefix_l, suffix, *suffix_l, *flags); + gd_include_affix(_GDF_GetDirfile(*dirfile), _GDF_CString(fi, file, *file_l), *fragment_index, _GDF_CString(px, prefix, *prefix_l), _GDF_CString(sx, suffix, *suffix_l), *flags); @@ -3723,3 +3764,29 @@ dreturnvoid(); } + +void F77_FUNC(gdtoke, GDTOKE) (char *toke, int *toke_l, const int *dirfile, + const char *string, const int *string_l, const int *n) +{ + char *token, *st; + DIRFILE *D; + int i; + + dtrace("%p, %p, %i, %p, %i, %i", toke, toke_l, *dirfile, string, *string_l, + *n); + + D = _GDF_GetDirfile(*dirfile); + st = (char *)malloc(*string_l + 1); + _GDF_CString(st, string, *string_l); + + token = gd_tokenise(D, st); + for (i = 1; i < *n; ++i) { + free(token); + token = gd_tokenise(D, NULL); + } + + _GDF_FString(toke, toke_l, token); + free(token); + + dreturn("%i", *toke_l); +} Modified: trunk/getdata/bindings/f77/fgetdata.h =================================================================== --- trunk/getdata/bindings/f77/fgetdata.h 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/f77/fgetdata.h 2012-03-02 02:57:19 UTC (rev 664) @@ -44,6 +44,9 @@ #ifdef __cplusplus extern "C" { #endif +typedef void(*_GDF_callback_t)(int*, const int*, const int*, char*, const int*, + const char*); + /* Forward declarations to keep icc happy */ void F77_FUNC(gdopen, GDOPEN) (int* dirfile, const char* dirfilename, const int* dirfilename_l, const int* flags); @@ -304,9 +307,10 @@ void F77_FUNC(gddscd, GDDSCD) (const int* dirfile); void F77_FUNC(gdcopn, GDCOPN) (int* dirfile, const char* dirfilename, - const int* dirfilename_l, const int* flags, const void* callback); + const int* dirfilename_l, const int* flags, const _GDF_callback_t callback); -void F77_FUNC(gdclbk, GDCLBK) (const int* dirfile, const void* callback); +void F77_FUNC(gdclbk, GDCLBK) (const int* dirfile, + const _GDF_callback_t callback); void F77_FUNC(gdalbt, GDALBT) (const int* dirfile, const char* field_code, const int* field_code_l, const char* in_field, const int* in_field_l, @@ -662,6 +666,8 @@ void F77_FUNC(gdadal, GDADAL) (const int *dirfile, const char *field_code, const int *field_code_l, const char *target, const int *target_l, const int *fragment_index); + +void F77_FUNC(gdnocb, GDNOCB) (const int* dirfile); #ifdef __cplusplus } #endif Modified: trunk/getdata/bindings/f77/getdata.f.in =================================================================== --- trunk/getdata/bindings/f77/getdata.f.in 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/f77/getdata.f.in 2012-03-02 02:57:19 UTC (rev 664) @@ -308,6 +308,8 @@ EXTERNAL GDNMFT C Corresponding to gd_nmvectors(3) EXTERNAL GDNMVE +C Deregister a callback function (ie. gd_parser_callback(..., NULL)) + EXTERNAL GDNOCB C Corresponding to gd_native_type(3) EXTERNAL GDNTYP C Corresponding to gd_nvectors(3) Modified: trunk/getdata/bindings/f77/getdata.f90.in =================================================================== --- trunk/getdata/bindings/f77/getdata.f90.in 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/f77/getdata.f90.in 2012-03-02 02:57:19 UTC (rev 664) @@ -2734,13 +2734,13 @@ call gdsync(dirfile, TRIM(field_code), LEN_TRIM(field_code)) end subroutine -subroutine fgd_fragment_affixes (prefix, suffix, dirfile, fragment_index) +subroutine fgd_fragment_affixes (prefix, pl, suffix, sl, dirfile, & +fragment_index) character(len=*), intent(out) :: prefix, suffix integer, intent(in) :: dirfile, fragment_index - integer :: len1 = GD_FIELD_LEN - integer :: len2 = GD_FIELD_LEN + integer, intent(inout) :: pl, sl - call gdfraf(prefix, len1, suffix, len2, dirfile, fragment_index) + call gdfraf(prefix, pl, suffix, sl, dirfile, fragment_index) end subroutine subroutine fgd_add_mplex (dirfile, field_code, in_field, count_field, & @@ -2773,4 +2773,13 @@ count_max) end subroutine +subroutine fgd_tokenise (token, l, dirfile, string, n) + character (len=*), intent(out) :: token + integer, intent(inout) :: l + integer, intent(in) :: dirfile, n + character (len=*), intent(in) :: string + + call gdtoke(token, l, dirfile, TRIM(string), LEN_TRIM(string), n) +end subroutine + end module Modified: trunk/getdata/bindings/f77/test/big_test.f =================================================================== --- trunk/getdata/bindings/f77/test/big_test.f 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/f77/test/big_test.f 2012-03-02 02:57:19 UTC (rev 664) @@ -721,7 +721,7 @@ CALL CHKDBL(ne, 38, 1d0 * fl, -8.1d0) C 39: GDFRGN check - l = plen; + l = plen CALL GDFRGN(path, l, d, 0) CALL CHKEOK(ne, 39, d) @@ -2057,7 +2057,18 @@ CALL CHKST2(ne, 231, 6, fields(2), 'in4') CALL CHKIN2(ne, 231, 7, j, 7) +C 232: GDTOKE check + l = slen + CALL GDTOKE(str, l, d, '"test1 test2" test3\ test4 test5', 32, 1) + CALL CHKOK2(ne, 232, 1, d) + CALL CHKIN2(ne, 232, 2, l, slen) + CALL CHKST2(ne, 232, 3, str, 'test1 test2') + l = slen + CALL GDTOKE(str, l, d, '"test1 test2" test3\ test4 test5', 32, 2) + CALL CHKOK2(ne, 232, 4, d) + CALL CHKIN2(ne, 232, 5, l, slen) + CALL CHKST2(ne, 232, 6, str, 'test3 test4') @@ -2066,6 +2077,7 @@ + C =============================================================== C Cleanup CALL GDDSCD(d) Modified: trunk/getdata/bindings/f77/test/big_test95.f90 =================================================================== --- trunk/getdata/bindings/f77/test/big_test95.f90 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/f77/test/big_test95.f90 2012-03-02 02:57:19 UTC (rev 664) @@ -188,6 +188,7 @@ program big_test use getdata + implicit none include "test_getdata.f" character (len=*), parameter :: fildir = 'test95_dirfile' character (len=*), parameter :: frmat = 'test95_dirfile/format' @@ -627,8 +628,8 @@ cq(5) = dcmplx(5.5, 0.0) cq(6) = dcmplx(5.5, 0.0) DO i=1,3 - call check_dbl2(ne, 18, i * 2 - 1, ent%cm(i), cq(i * 2 - 1)) - call check_dbl2(ne, 18, i * 2, ent%cb(i), cq(i * 2)) + call check_cpx2(ne, 18, i * 2 - 1, ent%cm(i), cq(i * 2 - 1)) + call check_cpx2(ne, 18, i * 2, ent%cb(i), cq(i * 2)) end do ! 20: fgd_entry (polynom) check @@ -1736,13 +1737,13 @@ call check_ok(ne, 155, d) ! 156: fgd_invalid_dirfile check - m = fgd_invalid_dirfile() - call check_ok2(ne, 98, 1, m) + l = fgd_invalid_dirfile() + call check_ok2(ne, 98, 1, l) - n = fgd_nfragments(m) - call check_err2(ne, 98, 2, m, GD_E_BAD_DIRFILE) + n = fgd_nfragments(l) + call check_err2(ne, 98, 2, l, GD_E_BAD_DIRFILE) - call fgd_close(m) + call fgd_close(l) ! 157: fgd_dirfile_standards n = fgd_dirfile_standards(d, GD_VERSION_CURRENT) @@ -1789,7 +1790,7 @@ call check_ok(ne, 162, d) do i=1,2 - call check_int2(ne, 162, i, ci8(i), i + 2) + call check_int2(ne, 162, i, int(ci8(i)), i + 2) end do ! 163: gd_get_carray_slice (FLOAT32) @@ -2000,7 +2001,7 @@ call check_ok2(ne, 179, 3, d) do i=1,4 - call check_dbl2(ne, 179, i, 1d0 * cr4(i), 0.) + call check_dbl2(ne, 179, i, 1d0 * cr4(i), 0d0) end do ! 180: gd_madd_carray @@ -2018,7 +2019,7 @@ call check_ok2(ne, 180, 3, d) do i=1,4 - call check_dbl2(ne, 180, i, 1d0 * cr4(i), 0.) + call check_dbl2(ne, 180, i, 1d0 * cr4(i), 0d0) end do ! 181: gd_alter_carray @@ -2036,7 +2037,7 @@ call check_ok2(ne, 181, 3, d) do i=1,4 - call check_dbl2(ne, 181, i, 1d0 * cr4(i), 0.) + call check_dbl2(ne, 181, i, 1d0 * cr4(i), 0d0) end do ! 183: fgd_constants_i1 check @@ -2047,7 +2048,7 @@ call check_ok(ne, 183, d) do i = 1, n - call check_int2(ne, 183, i, int(ci1(i)), iq(i)) + call check_int2(ne, 183, i, int(ci1(i)), int(iq(i))) end do ! 184: fgd_constants_i2 check @@ -2056,7 +2057,7 @@ call check_ok(ne, 184, d) do i = 1, n - call check_int2(ne, 184, i, int(ci2(i)), iq(i)) + call check_int2(ne, 184, i, int(ci2(i)), int(iq(i))) end do ! 185: fgd_constants_i4 check @@ -2064,7 +2065,7 @@ call check_ok(ne, 185, d) do i = 1, n - call check_int2(ne, 185, i, ci4(i), iq(i)) + call check_int2(ne, 185, i, ci4(i), int(iq(i))) end do ! 186: fgd_constants_i8 check @@ -2072,7 +2073,7 @@ call check_ok(ne, 186, d) do i = 1, n - call check_int2(ne, 186, i, ci8(i), iq(i)) + call check_int2(ne, 186, i, int(ci8(i)), int(iq(i))) end do ! 187: fgd_constants_r4 check @@ -2120,7 +2121,7 @@ call check_ok(ne, 191, d) do i = 1, n - call check_int2(ne, 191, i, int(ci1(i)), iq(i)) + call check_int2(ne, 191, i, int(ci1(i)), int(iq(i))) end do ! 192: fgd_mconstants_i2 check @@ -2128,7 +2129,7 @@ call check_ok(ne, 192, d) do i = 1, n - call check_int2(ne, 192, i, int(ci2(i)), iq(i)) + call check_int2(ne, 192, i, int(ci2(i)), int(iq(i))) end do ! 193: fgd_mconstants_i4 check @@ -2136,7 +2137,7 @@ call check_ok(ne, 193, d) do i = 1, n - call check_int2(ne, 193, i, ci4(i), iq(i)) + call check_int2(ne, 193, i, ci4(i), int(iq(i))) end do ! 194: fgd_mconstants_i8 check @@ -2144,7 +2145,7 @@ call check_ok(ne, 194, d) do i = 1, n - call check_int2(ne, 194, i, ci8(i), iq(i)) + call check_int2(ne, 194, i, int(ci8(i)), int(iq(i))) end do ! 195: fgd_mconstants_r4 check @@ -2224,8 +2225,8 @@ call check_ok(ne, 203, d) call check_int2(ne, 203, 1, n, 280) - m = fgd_getdata_r8(d, 'data', GD_HERE, 0, 1, 0, cr8) - call check_int2(ne, 203, 2, m, 8) + n = fgd_getdata_r8(d, 'data', GD_HERE, 0, 1, 0, cr8) + call check_int2(ne, 203, 2, n, 8) do i=1,8 call check_dbl2(ne, 203, i, cr8(i), 16d0 + i) @@ -2419,19 +2420,27 @@ call check_int(ne, 225, n, -1) ! 226: fgd_fragment_affixes check - call fgd_fragment_affixes(fields(1), fields(2), d, 1) + l = flen + n = flen + call fgd_fragment_affixes(fields(1), l, fields(2), n, d, 1) call check_ok(ne, 226, d) - call check_str2(ne, 226, 1, fields(1), 'A') - call check_str2(ne, 226, 2, fields(2), 'Z') + call check_int2(ne, 226, 1, l, flen) + call check_str2(ne, 226, 2, fields(1), 'A') + call check_int2(ne, 226, 3, n, flen) + call check_str2(ne, 226, 4, fields(2), 'Z') ! 227: fgd_alter_affixes check call fgd_alter_affixes(d, 1, 'B', '') call check_ok2(ne, 227, 1, d) - call fgd_fragment_affixes(fields(1), fields(2), d, 1) + l = flen + n = flen + call fgd_fragment_affixes(fields(1), l, fields(2), n, d, 1) call check_ok2(ne, 227, 2, d) - call check_str2(ne, 227, 3, fields(1), 'B') - call check_str2(ne, 227, 3, fields(2), '') + call check_int2(ne, 226, 3, l, flen) + call check_str2(ne, 227, 4, fields(1), 'B') + call check_int2(ne, 226, 5, n, flen) + call check_str2(ne, 227, 6, fields(2), '') ! 228: fgd_entry (MPLEX) check n = fgd_entry(d, 'mplex', ent) @@ -2480,8 +2489,21 @@ call check_int2(ne, 231, 3, ent%count_val, 5) call check_str2(ne, 231, 4, ent%field(1), 'in3') call check_str2(ne, 231, 5, ent%field(2), 'in4') - call check_dbl2(ne, 231, 6, ent%count_max, 7) + call check_int2(ne, 231, 6, ent%count_max, 7) +! 232: fgd_tokenise check + l = slen + call fgd_tokenise(str, l, d, '"test1 test2" test3\ test4 test5', 1) + call check_ok2(ne, 232, 1, d) + call check_int2(ne, 232, 2, l, slen) + call check_str2(ne, 232, 3, str, 'test1 test2') + + l = slen + call fgd_tokenise(str, l, d, '"test1 test2" test3\ test4 test5', 2) + call check_ok2(ne, 232, 4, d) + call check_int2(ne, 232, 5, l, slen) + call check_str2(ne, 232, 6, str, 'test3 test4') + Modified: trunk/getdata/bindings/f77/test/gdcopn.f =================================================================== --- trunk/getdata/bindings/f77/test/gdcopn.f 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/f77/test/gdcopn.f 2012-03-02 02:57:19 UTC (rev 664) @@ -11,25 +11,38 @@ END SUBROUTINE + SUBROUTINE CALBK2(R, DUNIT, SUBERROR, LINE) + INTEGER R + +C An invalid response + R = 3333 + + END SUBROUTINE + PROGRAM GETTST + IMPLICIT NONE EXTERNAL CALBCK + EXTERNAL CALBK2 INCLUDE "getdata.f" CHARACTER*12 fildir PARAMETER (fildir = 'test_dirfile') CHARACTER*19 frmat PARAMETER (frmat = 'test_dirfile/format') + CHARACTER*20 frmat2 + PARAMETER (frmat2 = 'test_dirfile/format2') + CHARACTER*20 frmat3 + PARAMETER (frmat3 = 'test_dirfile/format3') CHARACTER*17 dat PARAMETER (dat = 'test_dirfile/data') - CHARACTER*15 frmdat1 - PARAMETER (frmdat1 = 'data RAW INT8 8') - CHARACTER*9 frmdat2 - PARAMETER (frmdat2 = 'bad line') INTEGER*1 datdat(80) - INTEGER*1 i; - INTEGER d; - INTEGER e; + INTEGER*1 i + INTEGER d + INTEGER e1, e2, e3, e4 + INTEGER r + r = 0 + CALL SYSTEM ( 'rm -rf ' // fildir ) CALL SYSTEM ( 'mkdir ' // fildir ) @@ -38,22 +51,61 @@ 20 CONTINUE OPEN(1, FILE=frmat, STATUS='NEW') - WRITE(1, *) frmdat1 - WRITE(1, *) frmdat2 + WRITE(1, *) "data RAW INT 8" + WRITE(1, *) "bad line" CLOSE(1, STATUS='KEEP') + OPEN(1, FILE=frmat2, STATUS='NEW') + WRITE(1, *) "bad line2" + CLOSE(1, STATUS='KEEP') + + OPEN(1, FILE=frmat3, STATUS='NEW') + WRITE(1, *) "bad line3" + CLOSE(1, STATUS='KEEP') + OPEN(1, FILE=dat, FORM='UNFORMATTED', ACCESS='DIRECT', RECL=80, +STATUS='NEW') WRITE (1,REC=1) datdat CLOSE(1, STATUS='KEEP') - CALL GDCOPN(d, fildir, 12, GD_RO, CALBCK) - CALL GDEROR(e, d) - CALL GDCLOS(d) + CALL GDCOPN(d, fildir, 12, GD_RW, CALBCK) + CALL GDEROR(e1, d) + CALL GDINCL(d, "format2", 7, 0, 0) + CALL GDEROR(e2, d) +C Change callback + CALL GDCLBK(d, CALBK2) + CALL GDINCL(d, "format3", 7, 0, 0) + CALL GDEROR(e3, d) + +C Delete callback + CALL GDNOCB(d) + CALL GDINCL(d, "format3", 7, 0, 0) + CALL GDEROR(e4, d) + CALL GDDSCD(d) + CALL SYSTEM ( 'rm -rf ' // fildir ) - IF (e .NE. GD_EOK) CALL EXIT(1) + IF (e1 .NE. GD_EOK) THEN + r = 1 + WRITE(*, 9001) 1, e1, GD_EOK + ENDIF + IF (e2 .NE. GD_EOK) THEN + r = 1 + WRITE(*, 9001) 2, e2, GD_EOK + ENDIF + IF (e3 .NE. GD_ECB) THEN + r = 1 + WRITE(*, 9001) 3, e3, GD_ECB + ENDIF + IF (e4 .NE. GD_EFO) THEN + r = 1 + WRITE(*, 9001) 3, e4, GD_EFO + ENDIF + IF (r .GT. 0) CALL ExIT(1) + + 9001 FORMAT('e[', i3, '] = ', i4, ', expected ', i4) + STOP END Modified: trunk/getdata/bindings/idl/getdata.c =================================================================== --- trunk/getdata/bindings/idl/getdata.c 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/idl/getdata.c 2012-03-02 02:57:19 UTC (rev 664) @@ -5539,9 +5539,54 @@ return r; } +/* @@DLM: F gdidl_tokenise GD_TOKENISE 1 1 KEYWORDS */ +IDL_VPTR gdidl_tokenise(int argc, IDL_VPTR argv[], char *argk) +{ + dtraceidl(); + const char *string = NULL; + char *token; + typedef struct { + IDL_KW_RESULT_FIRST_FIELD; + GDIDL_KW_RESULT_ERROR; + IDL_STRING string; + int string_x; + } KW_RESULT; + KW_RESULT kw; + GDIDL_KW_INIT_ERROR; + kw.string_x = 0; + static IDL_KW_PAR kw_pars[] = { + GDIDL_KW_PAR_ERROR, + GDIDL_KW_PAR_ESTRING, + { "STRING", IDL_TYP_STRING, 1, 0, IDL_KW_OFFSETOF(string_x), + IDL_KW_OFFSETOF(string) }, + { NULL } + }; + + IDL_KWProcessByOffset(argc, argv, argk, kw_pars, NULL, 1, &kw); + + DIRFILE* D = gdidl_get_dirfile(IDL_LongScalar(argv[0])); + + if (kw.string_x) + string = IDL_STRING_STR(&kw.string); + + token = gd_tokenise(D, string); + + GDIDL_SET_ERROR(D); + + IDL_KW_FREE; + + IDL_VPTR r = IDL_StrToSTRING(token); + free(token); + dreturn("%p", r); + return r; +} + + + + /**** Module initialisation ****/ /* These are defined in the automatically generated sublist.c */ Modified: trunk/getdata/bindings/idl/test/big_test.pro =================================================================== --- trunk/getdata/bindings/idl/test/big_test.pro 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/idl/test/big_test.pro 2012-03-02 02:57:19 UTC (rev 664) @@ -1332,6 +1332,15 @@ nume += check_simple2(231, 4, n.in_fields, [ 'in3', 'in4' ]) nume += check_simple2(231, 5, n.count_max, 7) +; 232: gd_tokenise check +str = gd_tokenise(d, STRING='"test1 test2" test3\ test4') +nume += check_ok2(232, 1 ,d) +nume += check_simple2(232, 2, str, "test1 test2") + +str = gd_tokenise(d) +nume += check_ok2(232, 3 ,d) +nume += check_simple2(232, 4, str, "test3 test4") + Modified: trunk/getdata/bindings/perl/GetData.xs =================================================================== --- trunk/getdata/bindings/perl/GetData.xs 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/perl/GetData.xs 2012-03-02 02:57:19 UTC (rev 664) @@ -279,7 +279,7 @@ while (SvROK(sv)) sv = SvRV(sv); - if (SvTYPE(sv) != SVt_PVHV) + if (SvTYPE(sv) != SVt_PVHV) croak("%s::%s() - Entry must be hash", pkg, func); GDP_EHASH_FETCH_UV("field_type", field_type, gd_entype_t); @@ -435,7 +435,7 @@ case GD_UNKNOWN: ; } - + dreturnvoid(); } @@ -460,7 +460,7 @@ func); /* argument grokking goes thus (in order!): - * if d == undef, the remaining arguments are taken to be data + * if d == undef, the remaining arguments are taken to be data * if d == reference to an array, the array is taken to be data, and * remaining arguments ignored * if there is exactly one argument after d, d is taken as a type code @@ -487,7 +487,7 @@ if (din.arg_type == GDP_DATA_IN_LIST) { din.nsamp = items - idx; din.type = gdp_get_type(&ST(idx), pkg, func); - } else if (din.arg_type == GDP_DATA_IN_REF) { + } else if (din.arg_type == GDP_DATA_IN_REF) { if (SvTYPE((SV*)av) != SVt_PVAV) croak("%s::%s() - Expected array reference, but found some other " "type of object", pkg, func); @@ -812,7 +812,7 @@ AV *av = NULL; if (!sp) { - av = newAV(); + av = newAV(); av_extend(av, n - 1); } @@ -1699,7 +1699,7 @@ GetData::Dirfile::put_carray = 1 CODE: dtrace("%p, \"%s\", %p, ...[%li]", dirfile, field_code, d, (long)items - 3); - + din = gdp_convert_data(d, items, ax, 2, gdp_package, "put_carray"); RETVAL = gd_put_carray(dirfile, field_code, din.type, din.data_in); @@ -1727,7 +1727,7 @@ CODE: dtrace("%p, \"%s\", %lli, %p, ...[%li]", dirfile, field_code, (long long)start, d, (long)items - 4); - + din = gdp_convert_data(d, items, ax, 3, gdp_package, "put_carray"); RETVAL = gd_put_carray_slice(dirfile, field_code, start, din.nsamp, @@ -1757,7 +1757,7 @@ CODE: dtrace("%p, \"%s\", %03x, %i, %p, ...[%li]", dirfile, field_code, const_type, fragment_index, d, (long)items - 5); - + din = gdp_convert_data(d, items, ax, 4, gdp_package, "put_carray"); RETVAL = gd_add_carray(dirfile, field_code, const_type, din.nsamp, @@ -1787,7 +1787,7 @@ CODE: dtrace("%p, \"%s\", \"%s\", %03x, %p, ...[%li]", dirfile, parent, field_code, const_type, d, (long)items - 5); - + din = gdp_convert_data(d, items, ax, 4, gdp_package, "put_carray"); RETVAL = gd_madd_carray(dirfile, parent, field_code, const_type, din.nsamp, @@ -1989,5 +1989,29 @@ dreturnvoid(); +void +tokenise(dirfile, string) + DIRFILE * dirfile + const char * string + PREINIT: + int i; + char *token; + GDP_DIRFILE_ALIAS; + ALIAS: + GetData::Dirfile::tokenise = 1 + PPCODE: + dtrace("%p, \"%s\"", dirfile, string); + /* return an array of all the parsed tokens */ + for (token = gd_tokenise(dirfile, string); token; + token = gd_tokenise(dirfile, NULL)) + { + GDP_UNDEF_ON_ERROR(); + + GDP_PUSHpvz(token); + free(token); + } + + dreturnvoid(); + INCLUDE: simple_funcs.xs Modified: trunk/getdata/bindings/perl/t/big_test.t =================================================================== --- trunk/getdata/bindings/perl/t/big_test.t 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/perl/t/big_test.t 2012-03-02 02:57:19 UTC (rev 664) @@ -1,10 +1,10 @@ #!/usr/bin/perl -w # Copyright (C) 2011-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 @@ -22,7 +22,7 @@ use GetData; use Math::Complex; use strict; -use Test::More tests => 1260; +use Test::More tests => 1265; my $ne = 0; my ($s, @a, %h); @@ -461,7 +461,7 @@ CheckSArray2(30, 12, $h{'scalar'}, undef, undef, undef, undef, undef); CheckArray2(30, 13, $h{'scalar_ind'}, undef, undef, undef, undef, undef); -# 31: add_polynom +# 31: add_polynom $s = $_->add_polynom("new4", 3, "in1", [ 3.9, 4.8, 5.7, 6.6 ], 0); CheckOK2(31, 1); CheckNum2(31, 2, $s, 0); @@ -650,7 +650,7 @@ CheckSArray2(47, 12, $h{'scalar'}, undef, undef, undef, undef, undef); CheckArray2(47, 13, $h{'scalar_ind'}, undef, undef, undef, undef, undef); -# 48: madd_polynom +# 48: madd_polynom $s = $_->madd_polynom("data", "mnew3", 3, "in1", [ 3.9, 4.8, 5.7, 6.6 ]); CheckOK2(48, 1); CheckNum2(48, 2, $s, 0); @@ -760,7 +760,7 @@ field_type => $GetData::PHASE_ENTRY, fragment_index => 0, in_field => "data", - shift => 2 + shift => 2 }, "data"); CheckOK2(126,1); CheckNum2(126, 2, $s, 0); @@ -911,7 +911,7 @@ CheckSArray2(69, 12, $h{'scalar'}, undef, undef, undef, undef, undef); CheckArray2(69, 13, $h{'scalar_ind'}, undef, undef, undef, undef, undef); -# 71: alter_polynom +# 71: alter_polynom $s = $_->alter_polynom("new4", 4, undef, [ 1*i, 2*i, 3*i, 4*i, 5*i ]); CheckOK2(71, 1); CheckNum2(71, 2, $s, 0); @@ -1656,7 +1656,10 @@ CheckSArray2(231, 4, $h{"in_fields"}, 'in3', 'in4'); CheckNum2(231, 5, $h{"count_max"}, 7); - +# 232: gd_tokenise check +@a = $_->tokenise('"test1 test2" test3\ test4 test5'); +CheckOK(232); +CheckSArray(232, \@a, "test1 test2", "test3 test4", "test5"); @@ -1664,5 +1667,6 @@ + $d = $_ = undef; system "rm -rf dirfile"; Modified: trunk/getdata/bindings/python/pydirfile.c =================================================================== --- trunk/getdata/bindings/python/pydirfile.c 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/python/pydirfile.c 2012-03-02 02:57:19 UTC (rev 664) @@ -2408,6 +2408,31 @@ return Py_None; } +static PyObject *gdpy_dirfile_tokenise(struct gdpy_dirfile_t *self, + void *args, void *keys) +{ + dtrace("%p, %p, %p", self, args, keys); + + char *token; + char *keywords[] = { "string", NULL }; + const char *string = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, keys, "|s:pygetdata.dirfile.tokenise", + keywords, &string)) + { + dreturn("%p", NULL); + return NULL; + } + + token = gd_tokenise(self->D, string); + + PyObject* pyobj = PyString_FromString(token); + free(token); + + dreturn("%p", pyobj); + return pyobj; +} + static PyGetSetDef gdpy_dirfile_getset[] = { { "error", (getter)gdpy_dirfile_geterror, NULL, "The numerical error code encountered by the last call to the GetData\n" @@ -2700,7 +2725,6 @@ METH_VARARGS | METH_KEYWORDS, "mvector_list(parent)\n\n" "Retrieve a list of all vector type metafields (that is: BIT, DIVIDE,\n" - /* ------- handy ruler ---------------------------------------------| */ "LINCOM, LINTERP, MPLEX, MULTIPLY, PHASE, POLYNOM, RECIP, SBIT, and\n" "WINDOW metafields) for the parent field 'parent'. See\n" "gd_mvector_list(3)." @@ -2979,6 +3003,15 @@ "Adds a new alias called 'field_code' pointing to 'target' as a\n" "metalias under 'parent'. See gd_madd_alias(3)." }, + {"tokenise", (PyCFunction)gdpy_dirfile_tokenise, METH_VARARGS | METH_KEYWORDS, + "tokenise([string])\n\n" + /* ------- handy ruler ---------------------------------------------| */ + "If 'string' is given, runs the GetData tokeniser on 'string' and\n" + "returns the first token. If 'string' is not given, returns\n" + "subsequent tokens (one per call) of the last string that was\n" + "provided. Note: an error will result if the string being parsed\n" + "goes out of scope. See gd_tokenise(3)." + }, { NULL, NULL, 0, NULL } }; Modified: trunk/getdata/bindings/python/test/big_test.py =================================================================== --- trunk/getdata/bindings/python/test/big_test.py 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/bindings/python/test/big_test.py 2012-03-02 02:57:19 UTC (rev 664) @@ -1903,6 +1903,18 @@ CheckSimple2(231, 4, ent.in_fields, ( 'in3', 'in4' )) CheckSimple2(231, 5, ent.count_max, 7) +# 232: gd_tokenise check +try: + str = d.tokenise("\"test1 test2\" test3\ test4"); +except: + CheckOK2(232, 1) +CheckSimple2(232, 2, str, "test1 test2") + +try: + str = d.tokenise() +except: + CheckOK2(232, 3) +CheckSimple2(232, 4, str, "test3 test4") Modified: trunk/getdata/doc/list.tests =================================================================== --- trunk/getdata/doc/list.tests 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/doc/list.tests 2012-03-02 02:57:19 UTC (rev 664) @@ -243,3 +243,4 @@ 229 F9CIpP gd_add_mplex 230 F9CIpP gd_madd_mplex 231 F9CIpP gd_alter_mplex +232 F9CIpP gd_tokenise Modified: trunk/getdata/man/checkdirfile.1 =================================================================== --- trunk/getdata/man/checkdirfile.1 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/man/checkdirfile.1 2012-03-02 02:57:19 UTC (rev 664) @@ -1,6 +1,6 @@ .\" checkdirfile.1. The checkdirfile man page. .\" -.\" Copyright (C) 2010 D. V. Wiebe +.\" Copyright (C) 2010, 2012 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 checkdirfile 1 "22 November 2010" "Version 0.7.0" "GETDATA" +.TH checkdirfile 1 "21 February 2012" "Version 0.8.0" "GETDATA" .SH NAME checkdirfile \(em verify Dirfile database metadata .SH SYNOPSIS @@ -43,6 +43,25 @@ .B --version Show usage and version information and exit. +.SH AUTHOR + +checkdirfile was written by D. V. Wiebe. + +.SH REPORTING BUGS + +Please send reports of bugs to getdata\-d...@li... + +The GetData home page: <http://getdata.sourceforge.net/> + +.SH COPYRIGHT + +Copyright \(co 2010 D. V. Wiebe + +checkdirfile is licenced under the GNU LPGL version 2.1 or later. + +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. + .SH SEE ALSO .BR dirfile (5), .BR dirfile-format (5) Modified: trunk/getdata/man/dirfile2ascii.1 =================================================================== --- trunk/getdata/man/dirfile2ascii.1 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/man/dirfile2ascii.1 2012-03-02 02:57:19 UTC (rev 664) @@ -1,6 +1,6 @@ .\" dirfile2ascii.1. The dirfile2ascii man page. .\" -.\" Copyright (C) 2010 D. V. Wiebe +.\" Copyright (C) 2010, 2012 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 dirfile2ascii 1 "30 November 2010" "Version 0.7.1" "GETDATA" +.TH dirfile2ascii 1 "21 February 2012" "Version 0.8.0" "GETDATA" .SH NAME dirfile2ascii \(em output dirfile database vectors as ASCII text .SH SYNOPSIS @@ -129,7 +129,6 @@ No native support for printing complex data is provided. This may be worked around by using dirfile(5) representation suffixes. For example, the command .IP -$ .B dirfile2ascii .I DIRFILE .IB FIELD .r @@ -139,6 +138,26 @@ .I FIELD in the first and second columns, respectively. +.SH AUTHOR + +dirfile2ascii was written by Matthew Truch and D. V. Wiebe. + +.SH REPORTING BUGS + +Please send reports of bugs to getdata\-d...@li... + +The GetData home page: <http://getdata.sourceforge.net/> + +.SH COPYRIGHT + +Copyright \(co 2010 Matthew Truch. + +dirfile2ascii is licenced under the GNU LPGL version 2.1 or later. + +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. + .SH SEE ALSO +.BR defile (1), .BR dirfile (5), .BR printf (3) Modified: trunk/getdata/man/gd_add.3 =================================================================== --- trunk/getdata/man/gd_add.3 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/man/gd_add.3 2012-03-02 02:57:19 UTC (rev 664) @@ -1,6 +1,6 @@ .\" gd_add.3. The gd_add man page. .\" -.\" Copyright (C) 2008, 2009, 2010 D. V. Wiebe +.\" Copyright (C) 2008, 2009, 2010, 2012 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_add 3 "30 November 2010" "Version 0.7.1" "GETDATA" +.TH gd_add 3 "1 March 2012" "Version 0.8.0" "GETDATA" .SH NAME gd_add, gd_madd \(em add a field to a dirfile .SH SYNOPSIS @@ -30,7 +30,7 @@ .SH DESCRIPTION The .BR gd_add () -function adds the field described by +function adds the field described by .I entry to the dirfile specified by .IR dirfile . @@ -58,16 +58,22 @@ .B STRING field, the field data will be set to the empty string. -When adding a metafield, the +A metafield may be added either by calling +.BR gd_madd () +with .IR entry -> field -member should contain just the metafield's name, not the fully formed +containing only the metafield's name, or else by calling +.BR gd_add () +with the fully formed .IB <parent-field> / <meta-field> -field code. Also, -.BR gd_madd () -ignores the value of -.IR entry -> fragment_index , -and instead adds the new meta field to the same format specification fragment in -which the parent field is defined. +field code in +.IR entry -> field . +Regardless of which interface is used, when adding a metafield the value of +.IR entry -> fragment_index +is ignored and GetData will add the new metafield to the same format +specification fragment in which the parent field is defined. If the specified +parent field name is an alias, the canonical name of the field will be +substituted. Fields added with this interface may contain either literal parameters or parameters based on scalar fields. If an element of the @@ -128,7 +134,7 @@ .IR entry -> const_type parameter provided with a .B CONST -or +or .B CARRAY entry, was invalid. .TP @@ -140,7 +146,7 @@ entry was greater than GD_MAX_CARRAY_LENGTH. .TP .B GD_E_DUPLICATE -The field name provided in +The field name provided in .IR entry -> field duplicated that of an already existing field. .TP Modified: trunk/getdata/man/gd_add_bit.3 =================================================================== --- trunk/getdata/man/gd_add_bit.3 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/man/gd_add_bit.3 2012-03-02 02:57:19 UTC (rev 664) @@ -1,6 +1,6 @@ .\" gd_add_bit.3. The gd_add_bit man page. .\" -.\" Copyright (C) 2008, 2009, 2010 D. V. Wiebe +.\" Copyright (C) 2008, 2009, 2010, 2012 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_add_bit 3 "3 November 2010" "Version 0.7.0" "GETDATA" +.TH gd_add_bit 3 "1 March 2012" "Version 0. .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, @@ -146,7 +146,7 @@ .IR value . For .BR gd_add_const () -and +and .BR gd_add_carray (), the .I const_type @@ -163,6 +163,21 @@ .B gd_spf_t type is an unsigned 16-bit integer type. +A metafield may be added to the dirfile either by calling these functions with +.I field_name +containing the fully formed +.IB <parent-field> / <meta-field> +field code, or else by using the corresponding +.BR gd_madd_ ...() +function (see +.BR gd_madd_bit (3), +&c.) When adding a metafield with these functions, +.I fragment_index +is ignored and GetData will add the new metafield to the same format +specification fragment in which the parent field is defined. If the specified +parent field name is an alias, the canonical name of the field will be +substituted. + All fields added with this interface must contain literal parameters. Fields with scalar fields as parameters cannot be added with these functions. Those fields must be added with @@ -173,13 +188,13 @@ See .B NOTES below for information on using -.BR gd_add_clincom (),\~ gd_add_carray (), -and -.BR gd_add_cpolynom () +.BR gd_add_clincom (),\~ gd_add_cpolynom (), +and +.BR gd_add_crecip () in the C89 GetData API. .SH RETURN VALUE -On success, any of these functions returns zero. On error, -1 is returned and +On success, any of these functions returns zero. On error, -1 is returned and the dirfile error is set to a non-zero error value. Possible error values are: .TP 8 .B GD_E_ACCMODE Modified: trunk/getdata/man/gd_madd_bit.3 =================================================================== --- trunk/getdata/man/gd_madd_bit.3 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/man/gd_madd_bit.3 2012-03-02 02:57:19 UTC (rev 664) @@ -1,6 +1,6 @@ .\" gd_madd_bit.3. The gd_madd_bit man page. .\" -.\" Copyright (C) 2008, 2009, 2010 D. V. Wiebe +.\" Copyright (C) 2008, 2009, 2010, 2012 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_madd_bit 3 "3 November 2010" "Version 0.7.0" "GETDATA" +.TH gd_madd_bit 3 "1 March 2012" "Version 0.8.0" "GETDATA" .SH NAME gd_madd_bit, gd_madd_carray, gd_madd_clincom, gd_madd_const, gd_madd_cpolynom, gd_madd_crecip, gd_madd_divide, gd_madd_lincom, gd_madd_linterp, @@ -167,13 +167,16 @@ .BR gd_madd (3) or .BR gd_madd_spec (3). +See +.BR gd_add_bit (3), +&c. for an alternate way of adding metafields with explicit parameters. See .B NOTES below for information on using -.BR gd_madd_clincom () +.BR gd_madd_clincom "(), " gd_madd_cpolynom (), and -.BR gd_madd_cpolynom () +.BR gd_madd_crecip () in the C89 GetData API. .SH RETURN VALUE Modified: trunk/getdata/src/add.c =================================================================== --- trunk/getdata/src/add.c 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/src/add.c 2012-03-02 02:57:19 UTC (rev 664) @@ -79,21 +79,56 @@ return NULL; } + /* make name */ offset = strlen(parent) + 1; temp_buffer = (char *)_GD_Malloc(D, offset + strlen(entry->field) + 1); - if (temp_buffer) { - strcpy(temp_buffer, parent); - temp_buffer[offset - 1] = '/'; - strcpy(temp_buffer + offset, entry->field); + + if (temp_buffer == NULL) { + dreturn("%p", NULL); + return NULL; } - } else + + strcpy(temp_buffer, parent); + temp_buffer[offset - 1] = '/'; + strcpy(temp_buffer + offset, entry->field); + } else { + char *ptr; /* Apply prefix and suffix */ - temp_buffer = _GD_MungeFromFrag(D, NULL, entry->fragment_index, + temp_buffer = ptr = _GD_MungeFromFrag(D, NULL, entry->fragment_index, entry->field, &offset); - if (temp_buffer == NULL) { - dreturn("%p", NULL); - return NULL; + if (temp_buffer == NULL) { + dreturn("%p", NULL); + return NULL; + } + + /* look for a Barth-style meta field. We do this after mungification + * to ensure that the parent field ends up with the right prefix and + * suffix */ + P = _GD_CheckParent(D, &ptr, -1, 0); + + if (D->error) { + free(temp_buffer); + dreturn("%p", NULL); + return NULL; + } + + if (P) { + /* make the new name -- this may be different because P may have been + * dealiased */ + offset = strlen(P->field) + 1; + char *temp2 = _GD_Malloc(D, offset + strlen(ptr) + 1); + if (temp2 == NULL) { + free(temp_buffer); + dreturn("%p", NULL); + return NULL; + } + + dwatch("%s", ptr); + sprintf(temp2, "%s/%s", P->field, ptr); + free(temp_buffer); + temp_buffer = temp2; + } } /* check for duplicate field */ @@ -161,7 +196,7 @@ } /* Set meta indices */ - if (parent != NULL) + if (P != NULL) E->e->n_meta = -1; /* Hidden */ @@ -173,7 +208,7 @@ { case GD_RAW_ENTRY: /* no METARAW fields allowed */ - if (parent != NULL) { + if (P != NULL) { _GD_SetError(D, GD_E_BAD_ENTRY, GD_E_ENTRY_METARAW, NULL, entry->field_type, NULL); break; @@ -549,7 +584,7 @@ } /* start parsing */ - n_cols = _GD_Tokenise(D, line, &outstring, &tok_pos, in_cols, + n_cols = _GD_Tokenise(D, line, &outstring, &tok_pos, MAX_IN_COLS, in_cols, "dirfile_madd_spec()", 0, D->standards, D->flags & GD_PERMISSIVE); /* Directive parsing is skipped -- The Field Spec parser will add the field */ @@ -614,7 +649,7 @@ _GD_ClearError(D); /* start parsing */ - n_cols = _GD_Tokenise(D, line, &outstring, &tok_pos, in_cols, + n_cols = _GD_Tokenise(D, line, &outstring, &tok_pos, MAX_IN_COLS, in_cols, "dirfile_add_spec()", 0, D->standards, D->flags & GD_PERMISSIVE); /* Directive parsing is skipped -- The Field Spec parser will add the field */ Modified: trunk/getdata/src/errors.c =================================================================== --- trunk/getdata/src/errors.c 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/src/errors.c 2012-03-02 02:57:19 UTC (rev 664) @@ -177,6 +177,7 @@ { GD_E_ARGUMENT, GD_E_ARG_ENDIANNESS, "Invalid endianness specified", 0 }, { GD_E_ARGUMENT, GD_E_ARG_PROTECTION, "Invalid protection level specified", 0 }, + { GD_E_ARGUMENT, GD_E_ARG_NODATA, "No data", 0 }, { GD_E_ARGUMENT, 0, "Bad argument", 0 }, /* GD_E_CALLBACK: 3 = response */ { GD_E_CALLBACK, 0, "Unrecognised response from callback function: {3}", 0 }, Modified: trunk/getdata/src/getdata.h.in =================================================================== --- trunk/getdata/src/getdata.h.in 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/src/getdata.h.in 2012-03-02 02:57:19 UTC (rev 664) @@ -869,6 +869,9 @@ extern const char **gd_strings(DIRFILE *dirfile) gd_nothrow gd_nonnull ((1)); +extern char *gd_tokenise(DIRFILE *D, const char *string) gd_nothrow +gd_nonnull ((1)); + extern int gd_unhide(DIRFILE *dirfile, const char *field_code) gd_nothrow gd_nonnull ((1,2)); Modified: trunk/getdata/src/internal.h =================================================================== --- trunk/getdata/src/internal.h 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/src/internal.h 2012-03-02 02:57:19 UTC (rev 664) @@ -679,6 +679,7 @@ #define GD_E_ARG_WHENCE 1 #define GD_E_ARG_ENDIANNESS 2 #define GD_E_ARG_PROTECTION 3 +#define GD_E_ARG_NODATA 4 #define GD_FILE_READ 0x1 #define GD_FILE_WRITE 0x2 @@ -901,6 +902,9 @@ int standards; int n_error; + /* for the public tokeniser */ + const char *tok_pos; + /* field counts */ unsigned int n_entries; unsigned int n_hidden; @@ -958,6 +962,8 @@ int _GD_CalculateEntry(DIRFILE *restrict, gd_entry_t *restrict, int); char *_GD_CanonicalPath(const char *restrict, const char *restrict); +gd_entry_t *_GD_CheckParent(DIRFILE *restrict D, char **restrict name, int me, + int linenum); void _GD_CInvertData(DIRFILE *restrict, void *restrict, gd_type_t return_type, GD_DCOMPLEXA(dividend), size_t); @@ -1064,8 +1070,8 @@ char *_GD_Strdup(DIRFILE *restrict, const char *restrict); int _GD_Supports(DIRFILE *, const gd_entry_t*, unsigned int funcs); int _GD_Tokenise(DIRFILE *restrict, const char *restrict, char **, - const char **, char **, const char *restrict, int linenum, int standards, - int pedantic); + const char **, int, char **, const char *restrict, int linenum, + int standards, int pedantic); void _GD_UpdateAliases(DIRFILE*); int _GD_ValidateField(const char*, int, int, int, int*); off64_t _GD_WriteSeek(DIRFILE *restrict, gd_entry_t *restrict, Modified: trunk/getdata/src/mod.c =================================================================== --- trunk/getdata/src/mod.c 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/src/mod.c 2012-03-02 02:57:19 UTC (rev 664) @@ -1640,7 +1640,7 @@ standards = D->standards; /* start parsing */ - n_cols = _GD_Tokenise(D, line, &outstring, &tok_pos, in_cols, + n_cols = _GD_Tokenise(D, line, &outstring, &tok_pos, MAX_IN_COLS, in_cols, "dirfile_alter_spec()", 0, standards, D->flags & GD_PERMISSIVE); if (D->error) { @@ -1740,7 +1740,7 @@ standards = D->standards; /* start parsing */ - n_cols = _GD_Tokenise(D, line, &outstring, &tok_pos, in_cols, + n_cols = _GD_Tokenise(D, line, &outstring, &tok_pos, MAX_IN_COLS, in_cols, "dirfile_malter_spec()", 0, standards, D->flags & GD_PERMISSIVE); if (!D->error) { Modified: trunk/getdata/src/parse.c =================================================================== --- trunk/getdata/src/parse.c 2012-02-21 01:23:45 UTC (rev 663) +++ trunk/getdata/src/parse.c 2012-03-02 02:57:19 UTC (rev 664) @@ -1313,8 +1313,8 @@ /* get more tokens */ free(*outstring); - n_cols = _GD_Tokenise(D, tok_pos, outstring, &tok_pos, in_cols, format_file, - line, standards, pedantic); + n_cols = _GD_Tokenise(D, tok_pos, outstring, &tok_pos, MAX_IN_COLS, in_cols, + format_file, line, standards, pedantic); if (n_cols == 0 || D->error) break; first = 0; @@ -1422,10 +1422,12 @@ } /* _GD_CheckParent: look for a slashed field name and, if found, see if the - * parent exists in the current fragment. Returns parent entry on success. + * parent exists in the current fragment. Returns parent entry on success, + * and points *name to the metaname part. me == -1 implies we're not in the + * parser, but called from _GD_Add. */ -static gd_entry_t *_GD_CheckParent(DIRFILE *restrict D, char **restrict name, - int me, int linenum) +gd_entry_t *_GD_CheckParent(DIRFILE *restrict D, char **restrict name, int me, + int linenum) { int dummy; char *cptr, *munged_code; @@ -1436,29 +1438,45 @@ for (cptr = *name + 1; *cptr != '\0'; ++cptr) if (*cptr == '/') { *cptr = '\0'; - munged_code = _GD_MungeFromFrag(D, NULL, me, *name, &dummy); + if (me == -1) + munged_code = strdup(*name); + else + munged_code = _GD_MungeFromFrag(D, NULL, me, *name, &dummy); if (munged_code) { P = _GD_FindField(D, munged_code, D->entry, D->n_entries, 0, NULL); free(munged_code); } - if (P == NULL) + if (P == NULL) { + if (me == -1) { + *cptr = '/'; /* undo field munging; _GD_Add will conclude this is + a field with an illegal '/' */ + dreturn("%p", NULL); + return NULL; + } _GD_SetError(D, GD_E_FORMAT, GD_E_FORMAT_NO_FIELD, D->fragment[me].cname, linenum, *name); - else if (P->field_type == GD_ALIAS_ENTRY) - _GD_SetError(D, GD_E_FORMAT, GD_E_FORMAT_ALIAS, D->fragment[me].cname, - linenum, *name); - else if (P->fragment_index != me) + } else if (P->field_type == GD_ALIAS_ENTRY) { + if (me == -1) + P = P->e->entry[0]; /* just de-alias */ + else + _GD_SetError(D, GD_E_FORMAT, GD_E_FORMAT_ALIAS, D->fragment[me].cname, + linenum, *name); + } else if (P->fragment_index != me && me != -1) _GD_SetError(D, GD_E_FORMAT, GD_E_FORMAT_LOCATION, D->fragment[me].cname, linenum, *name); - else { - /* point name to the metafield name */ - *name = cptr + 1; + + if (D->error) { + dreturn("%p", NULL); + return NULL; } + + /* point name to the metafield name */ + *name = cptr + 1; break; } - dreturn("%p", D->error ? NULL : P); - return D->error ? NULL : P; + dreturn("%p", P); + return P; } /* _GD_ParseFieldSpec: Parse a format file line fragment containing a field @@ -1649,7 +1667,7 @@ #define ACC_MODE_HEX 2 #define ACC_MODE_UTF8 3 int _GD_Tokenise(DIRFILE *restrict D, const char *restrict instring, - char **outstring, const char **pos, char **in_cols, + char **outstring, const char **pos, int tok_want, char **in_cols, const char *restrict format_file, int linenum, int standards, int pedantic) { const char* ip; @@ -1662,8 +1680,9 @@ int n_acc = 0; int acc_mode = ACC_MODE_NONE; - dtrace("%p, \"%s\", %p, %p, %p, \"%s\", %i, %i, %i", D, instring, outstring, - pos, in_cols, format_file, linenum, standards, pedantic); + dtrace("%p, \"%s\", %p, %p, %i, %p, \"%s\", %i, %i, %i", D, instring, + outstring, pos, tok_want, in_cols, format_file, linenum, standards, + pedantic); op = *outstring = _GD_Strdup(D, instring); if (op == NULL) { @@ -1676,7 +1695,7 @@ for (ip = instring; *ip != '\0'; ++ip) { if (escaped_char) { if (ws) { - if (n_cols >= MAX_IN_COLS) + if (n_cols >= tok_want) break; /* Ignore trailing data on the line */ in_cols[n_cols++] = op; ws = 0; @@ -1807,7 +1826,7 @@ else if (*ip == '"' && (!pedantic || standards >= 6)) { if ((quotated = !quotated)) { if (ws) { - if (n_cols >= MAX_IN_COLS) + if (n_cols >= tok_want) break; /* Ignore trailing data on the line */ in_cols[n_cols++] = op; ws = 0; @@ -1825,7 +1844,7 @@ break; } else { if (ws) { - if (n_cols >= MAX_IN_COLS) + if (n_cols >= tok_want) break; /* Ignore trailing data on the line */ in_cols[n_cols++] = op; ws = 0; @@ -2265,8 +2284,9 @@ /* start parsing */ while (rescan || (instring = _GD_GetLine(fp, &n, &linenum))) { rescan = 0; - n_cols = _GD_Tokenise(D, instring, &outstring, &tok_pos, in_cols, - D->fragment[me].cname, linenum, *standards, *flags & GD_PEDANTIC); + n_cols = _GD_Tokenise(D, instring, &outstring, &tok_pos, MAX_IN_COLS, + in_cols, D->fragment[me].cname, linenum, *standards, + *flags & GD_PEDANTIC); if (n_cols == 0) {/* a blank line */ free(outstring); @@ -2370,5 +2390,45 @@ dreturn("%p", ref_name); return ref_name; } + +/* public access to the GetData tokeniser */ +char *gd_tokenise(DIRFILE *D, const char *string) gd_nothrow +{ + char *outstring, *in_col; + int n_cols; + + dtrace("%p, \"%s\"", D, string); + + if (D->flags & GD_INVALID) { + _GD_SetError(D, GD_E_BAD_DIRFILE, 0, NULL, 0, NULL); + dreturn("%p", NULL); + return NULL; + } + + _GD_ClearError(D); + + if (string) + D->tok_pos = string; + else if (D->tok_pos == NULL) { + _GD_SetError(D, GD_E_ARGUMENT, GD_E_ARG_NODATA, NULL, 0, NULL); + dreturn("%p", NULL); + return NULL; + } + + /* tokenise! */ + n_cols = _GD_Tokenise(D, D->tok_pos, &outstring, &D->tok_pos, 1, &in_col, + "gd_tokenise()", 0, D->standards, D->flags & GD_PERMISSIVE); + + if (D->error || n_cols < 1) { + D->tok_pos = NULL; + free(outstring); + outstring = NULL; + } + + /* in_col invariably points to outstring, so just let the caller worry about + * cleaning up. Ha! */ + dreturn("\"%s\"", outstring); + return outstring; +} /* vim: ts=2 sw=2 et tw=80 */ Property changes on: trunk/getdata/test ___________________________________________________________________ Modified: svn:ignore - Makefile Makefile.in *.o *.odirfile *.swp *.exe .deps .libs add add_affix add_alias add_bit add_bit_bitnum add_bit_bitsize add_bit_invalid add_bit_numbits 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_invalid add_lincom_nfields add_linterp add_linterp_invalid add_mplex add_mplex_val add_multiply add_multiply_invalid add_phase add_phase_invalid add_polynom add_protect add_raw add_raw_include add_raw_invalid add_raw_spf add_raw_type add_rdonly add_recip add_resolv add_sbit add_scalar add_scalar_carray 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_list alias_list_alias alias_list_missing alias_num alias_num_alias alias_num_missing alias_target alias_target_alias alias_target_missing alter_bit_bitnum alter_bit_numbits alter_carray_len alter_carray_type alter_const alter_cpolynom alter_crecip alter_crecip89 alter_crecip_zero alter_divide alter_entry alter_entry_affix alter_entry_hidden alter_entry_recode alter_entry_scalar2a alter_entry_scalar2n alter_entry_scalar3 alter_entry_scalar4 alter_lincom_23 alter_lincom_32 alter_lincom_input alter_lincom_offset alter_lincom_slope alter_linterp alter_linterp_move alter_mplex alter_mspec alter_mspec_affix alter_multiply alter_phase alter_polynom_coeff alter_polynom_input alter_polynom_ord alter_raw_spf alter_raw_type alter_recip alter_recip_zero alter_spec alter_spec_affix alter_spec_meta alter_window ascii_add asci... [truncated message content] |
From: <ket...@us...> - 2012-02-21 01:23:52
|
Revision: 663 http://getdata.svn.sourceforge.net/getdata/?rev=663&view=rev Author: ketiltrout Date: 2012-02-21 01:23:45 +0000 (Tue, 21 Feb 2012) Log Message: ----------- Input description Modified Paths: -------------- trunk/defile/bin/cli.c trunk/defile/input/ascii.c trunk/defile/input/dirfile.c trunk/defile/lib/defile.h Modified: trunk/defile/bin/cli.c =================================================================== --- trunk/defile/bin/cli.c 2012-02-20 22:35:37 UTC (rev 662) +++ trunk/defile/bin/cli.c 2012-02-21 01:23:45 UTC (rev 663) @@ -153,8 +153,12 @@ fprintf(stream, " v%s", fwk->version); if (fwk->copyright) fprintf(stream, " %s", fwk->copyright); - if (path) + if (path) { + if (fwk->description) + fprintf(stream, "\n%s [type: %s]", prefix ? prefix : "", + fwk->description); fprintf(stream, "\n%s [path: %s]", prefix ? prefix : "", path); + } putc('\n', stream); } Modified: trunk/defile/input/ascii.c =================================================================== --- trunk/defile/input/ascii.c 2012-02-20 22:35:37 UTC (rev 662) +++ trunk/defile/input/ascii.c 2012-02-21 01:23:45 UTC (rev 663) @@ -39,6 +39,7 @@ #define ASCII_COPYRIGHT "Copyright (C) 2012 D. V. Wiebe" #define ASCII_CONTACT \ "Please send reports of bugs and other communication to:\n " PACKAGE_BUGREPORT +#define ASCII_DESCRIPTION "ASCII tabular data" /* the probe function: given the name of the input, returns non-zero if this * module is willing to attempt to decode it */ @@ -343,6 +344,7 @@ .licence = DF_LICENCE_SAME, .contact = ASCII_CONTACT, .copyright = ASCII_COPYRIGHT, + .description = ASCII_DESCRIPTION, .name = "ascii", .version = PACKAGE_VERSION, .preamble = NULL, Modified: trunk/defile/input/dirfile.c =================================================================== --- trunk/defile/input/dirfile.c 2012-02-20 22:35:37 UTC (rev 662) +++ trunk/defile/input/dirfile.c 2012-02-21 01:23:45 UTC (rev 663) @@ -32,6 +32,7 @@ #define DIRFILE_COPYRIGHT "Copyright (C) 2012 D. V. Wiebe" #define DIRFILE_CONTACT \ "Please send reports of bugs and other communication to:\n " PACKAGE_BUGREPORT +#define DIRFILE_DESCRIPTION "dirfile databases" #define CHUNK_SIZE 65535 /* in bytes, the largest amount of data we're willing to read in one go */ @@ -338,6 +339,7 @@ .licence = DF_LICENCE_SAME, .contact = DIRFILE_CONTACT, .copyright = DIRFILE_COPYRIGHT, + .description = DIRFILE_DESCRIPTION, .name = "dirfile", .version = PACKAGE_VERSION, .preamble = NULL, Modified: trunk/defile/lib/defile.h =================================================================== --- trunk/defile/lib/defile.h 2012-02-20 22:35:37 UTC (rev 662) +++ trunk/defile/lib/defile.h 2012-02-21 01:23:45 UTC (rev 663) @@ -88,7 +88,7 @@ }; /* The input plugin description */ -#define DF_LICENCE_OTHER 0 +#define DF_LICENCE_OTHER 0 /* no automatic licence boilerplate */ #define DF_LICENCE_SAME 1 /* the same license as defile (whatver that is) */ #define DF_LICENCE_GPL 2 /* GPL v2+ */ #define DF_LICENCE_LGPL 3 /* LGPL v2.1+ */ @@ -98,6 +98,7 @@ const char *version; /* the version string for the plugin */ const char *copyright; /* the copyright notice for the plugin */ const char *contact; /* a contact (and perhaps licence) notice */ + const char *description; /* description of the file format read */ const char *preamble; /* the --help preamble */ const char *postamble; /* the --help postamble */ const struct df_optdef *opts; /* the plugin command-line options */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-02-20 22:35:43
|
Revision: 662 http://getdata.svn.sourceforge.net/getdata/?rev=662&view=rev Author: ketiltrout Date: 2012-02-20 22:35:37 +0000 (Mon, 20 Feb 2012) Log Message: ----------- svn:ignore Property Changed: ---------------- trunk/defile/ trunk/defile/bin/ trunk/defile/input/ trunk/defile/lib/ trunk/defile/m4/ trunk/defile/test/ Property changes on: trunk/defile ___________________________________________________________________ Added: svn:ignore + Makefile Makefile.in aclocal.m4 autom4te.cache config.guess config.log config.lt config.status config.sub configure depcomp install-sh libtool ltmain.sh missing Property changes on: trunk/defile/bin ___________________________________________________________________ Added: svn:ignore + .deps Makefile Makefile.in defile Property changes on: trunk/defile/input ___________________________________________________________________ Added: svn:ignore + .deps Makefile Makefile.in Property changes on: trunk/defile/lib ___________________________________________________________________ Added: svn:ignore + .deps Makefile Makefile.in config.h config.h.in stamp-h1 Property changes on: trunk/defile/m4 ___________________________________________________________________ Added: svn:ignore + libtool.m4 ltoptions.m4 ltsugar.m4 ltversion.m4 lt~obsolete.m4 Property changes on: trunk/defile/test ___________________________________________________________________ Added: svn:ignore + .deps Makefile Makefile.in madedata makedata This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ket...@us...> - 2012-02-20 19:08:33
|
Revision: 661 http://getdata.svn.sourceforge.net/getdata/?rev=661&view=rev Author: ketiltrout Date: 2012-02-20 19:08:21 +0000 (Mon, 20 Feb 2012) Log Message: ----------- Defile. Added Paths: ----------- trunk/defile/ trunk/defile/COPYING trunk/defile/Makefile.am trunk/defile/bin/ trunk/defile/bin/Makefile.am trunk/defile/bin/cli.c trunk/defile/bin/rc.c trunk/defile/bin/rc.h trunk/defile/configure.ac trunk/defile/input/ trunk/defile/input/Makefile.am trunk/defile/input/ascii.c trunk/defile/input/dirfile.c trunk/defile/lib/ trunk/defile/lib/Makefile.am trunk/defile/lib/defile.h trunk/defile/lib/internal.h trunk/defile/lib/libdefile.c trunk/defile/m4/ trunk/defile/test/ trunk/defile/test/Makefile.am trunk/defile/test/make.c trunk/defile/test/make.h Added: trunk/defile/COPYING =================================================================== --- trunk/defile/COPYING (rev 0) +++ trunk/defile/COPYING 2012-02-20 19:08:21 UTC (rev 661) @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. Added: trunk/defile/Makefile.am =================================================================== --- trunk/defile/Makefile.am (rev 0) +++ trunk/defile/Makefile.am 2012-02-20 19:08:21 UTC (rev 661) @@ -0,0 +1,25 @@ +# (C) 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 +# +AUTOMAKE_OPTIONS = foreign dist-bzip2 check-news 1.10 + +ACLOCAL_AMFLAGS = -I m4 + +SUBDIRS = lib bin input test Added: trunk/defile/bin/Makefile.am =================================================================== --- trunk/defile/bin/Makefile.am (rev 0) +++ trunk/defile/bin/Makefile.am 2012-02-20 19:08:21 UTC (rev 661) @@ -0,0 +1,28 @@ +# (C) 2012 D. V. Wiebe +# +########################################################################## +# +# This file is part of Defile. +# +# Defile is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Defile 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 General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with Defile; if not, write to the Free Software Foundation, Inc., +# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +AUTOMAKE_OPTIONS = foreign + +bin_PROGRAMS = defile +AM_CPPFLAGS = -I../lib ${GETDATA_CFLAGS} \ + -DDEFILE_MODULEDIR="\"${moduledir}\"" ${LTDLINCL} +AM_CFLAGS = -Wall +defile_SOURCES = cli.c rc.c rc.h +defile_LDADD = ../lib/libdefile.la -lltdl Added: trunk/defile/bin/cli.c =================================================================== --- trunk/defile/bin/cli.c (rev 0) +++ trunk/defile/bin/cli.c 2012-02-20 19:08:21 UTC (rev 661) @@ -0,0 +1,1180 @@ +/* (C) 2012 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of Defile. + * + * Defile is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Defile 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with Defile; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "internal.h" + +#include <signal.h> +#include <stdlib.h> +#include <stdio.h> +#include <syslog.h> +#include <unistd.h> +#include <stdarg.h> +#include <sys/select.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/wait.h> + +#ifdef HAVE_LIBGEN_H +#include <libgen.h> +#endif + +/* include libgen first to get the right basename(3) under GNU */ +#include <string.h> + +#ifdef HAVE_PTHREAD_H +#include <pthread.h> +#endif + +#define DF_BUFLEN 3000 + +#include "rc.h" + +#define DEFILE_COPYRIGHT "Copyright (C) 2012 D. V. Wiebe" + +#define DEFILE_CONTACT \ +"Please send reports of bugs and other communication to:\n" \ +" " PACKAGE_BUGREPORT "\n\n" \ +"** NB: Contact and licensing information for input plugins accessible " \ +"through\n this interface may be different than those of Defile " \ +"itself. For such\n information, execute:\n\n" \ +" %s -t <input_type> -- --version" + +#define DEFILE_USAGE_PREAMBLE "Usage:\n" \ + " %s [DEFILE_OPTION]... [INPUT] [ -- [INPUT_OPTION]... ]\n\n" \ +"Defile converts data in various formats from INPUT into a dirfile.\n\n" \ +"The defile command line consists of a list of defile options (listed " \ +"below),\noptionally followed by a list of input-specific options. " \ +"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 " \ +"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 " \ +"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 " \ +"vary with\ninput format, execute:\n\n" \ +" %s -t <input_type> -- --help\n" + +#define SETSTATE(x,y,a,b,c) case DF_WOPT_ ## x: a; b; break; +#define SETSIMPLE(x,y,a,b,c) SETSTATE(x,y,df-> y = a,b,c) +#define SETBIT(x,y,b) SETSTATE(x,y,df-> y |= (b),,"%i") +#define CLRBIT(x,y,b) SETSTATE(x,y,df-> y &= ~(b),,"%i") +#define SETSTRING(x,y) SETSIMPLE(x,y,config->argument,\ + config->argument=NULL,"%s") +#define CLRSTRING(x,y) SETSTATE(x,y,free(df-> y),df ->y = NULL,"%s") +#define SETFLOAT(x,y) SETSIMPLE(x,y,atof(config->argument),,"%g") +#define SETLFLOAT(x,y,b) SETSIMPLE(x,y,b,,"%g" ) +#define SETINT(x,y) SETSIMPLE(x,y,strol(config->argument, NULL, 0),,"%i") +#define SETLINT(x,y,b) SETSIMPLE(x,y,b,,"%i" ) +#define SETULONG(x,y) SETSIMPLE(x,y,strtoul(config->argument, NULL, 0),,\ + "%lu") + +static void DF_SignalHandler(int sig) +{ + if (!df->quiet) + switch (sig) { + case SIGHUP: + puts("Aborting due to hang up"); + break; + case SIGINT: + puts("Aborting due to interruption"); + break; + case SIGTERM: + puts("Aborting due to unexpected termination"); + break; + } + + df->input_state = DF_ST_ABORT; + df->output_state = DF_ST_ABORT; +} + +static void *DF_Embiggen(void *old, size_t size) +{ + void *new; + + new = realloc(old, size); + + if (new == NULL) { + perror("realloc"); + exit(1); + } + + return new; +} + +static int DF_ValidType(const char *type, size_t len) +{ + const char *ptr; + + if (len < 1 || len >= DF_TYPE_MAXLEN) + return 0; + + for (ptr = type; *ptr; ++ptr) + if (!(*ptr == '-' || *ptr == '_' || (*ptr >= '0' && *ptr <= '9') || + (*ptr >= 'A' && *ptr <= 'Z') || (*ptr >= 'a' && *ptr <= 'z'))) + { + return 0; + } + + return 1; +} + +static void DF_InputBanner(FILE *stream, const char* prefix, + const struct df_input_framework *fwk, const char *path) +{ + if (prefix) + fprintf(stream, "%s* %s:", prefix, fwk->name); + else + fprintf(stream, "defile-%s input plugin", fwk->name); + if (fwk->version) + fprintf(stream, " v%s", fwk->version); + if (fwk->copyright) + fprintf(stream, " %s", fwk->copyright); + if (path) + fprintf(stream, "\n%s [path: %s]", prefix ? prefix : "", path); + putc('\n', stream); +} + +static int DF_GetFramework(const char *libpath, const char *type, + const struct df_input_framework **fwk, lt_dlhandle *lib) +{ + const size_t len = strlen(type); + char sym[DF_TYPE_MAXLEN + 11]; + + /* make sure the type is sane */ + if (!DF_ValidType(type, len)) + return -1; + + *lib = lt_dlopenext(libpath); + + if (*lib == NULL) + return 3; + + /* find the framework */ + strcpy(sym, type); + strcpy(sym + len, "_framework"); + + *fwk = (const struct df_input_framework *)lt_dlsym(*lib, sym); + if (*fwk == NULL) { + lt_dlclose(*lib); + return 2; + } + + /* data sanity checks */ + if ((*fwk)->entry == NULL || (*fwk)->name == NULL || + strcmp((*fwk)->name, type)) + { + lt_dlclose(*lib); + return 1; + } + + return 0; +} + +struct df_fwk_list { + const char *t; + const char *i; + + int n; + char **p; + const struct df_input_framework **l; + lt_dlhandle *h; + + int r; + char *f; +}; + +/* lt_dlforeachfile callback */ +static int DF_LTDLSearchFunc(const char *filename, void *data) +{ + lt_dlhandle lib; + const struct df_input_framework *fwk = NULL; + char *path, *base, *type; + int i, have, result = 3; + + struct df_fwk_list *l = (struct df_fwk_list*)data; + + /* extract the filename part -- basename may modify its argument, so copy + * it first */ + if ((path = strdup(filename)) == NULL) { + perror("strdup"); + exit(1); + } + base = basename(path); + + /* ensure it is of the form "[stuff]defile-<type>" */ + type = strstr(base, "defile-"); + if (type) { + type += sizeof("defile-") - 1; + + /* check if it's the right type, if necessary */ + if ((l->t == NULL) || strcmp(l->t, type) == 0) { + /* try to retrieve the framework */ + result = DF_GetFramework(filename, type, &fwk, &lib); + } + } + free(path); + + /* if we have an input name, probe this plugin to see if it wants it */ + if (result == 0 && l->i) { + if (fwk->probe && (*fwk->probe)(l->i)) + result = 0; + else { + result = 4; + lt_dlclose(lib); + } + } + + /* success, add it to the list */ + if (result == 0) { + /* discard things we've already seen */ + have = 0; + for (i = 0; i < l->n; ++i) + if (strcmp(l->l[i]->name, type) == 0) { + have = 1; + } + + if (!have) { + l->r = 0; + + l->l = (const struct df_input_framework **)DF_Embiggen(l->l, + sizeof(const struct df_input_framework*) * (l->n + 1)); + l->l[l->n] = fwk; + + l->p = (char **)DF_Embiggen(l->p, sizeof(char*) * (l->n + 1)); + if ((l->p[l->n] = strdup(filename)) == NULL) { + perror("strdup"); + exit(1); + } + + l->h = (lt_dlhandle*)DF_Embiggen(l->h, sizeof(lt_dlhandle) * (l->n + 1)); + l->h[l->n] = lib; + + l->f = l->p[l->n]; + l->n++; + + /* stop searching if we're not compiling a list */ + if (l->t) + return 1; + } else + lt_dlclose(lib); + } else if (result < l->r) { + l->r = result; + free(l->f); + if ((l->f = strdup(filename)) == NULL) { + perror("strdup"); + exit(1); + } + } + + /* return zero to continue searching */ + return 0; +} + +/* use ltdl to find an input plugin. We might know the name of the type we're + * looking for (type); alternately, we may know the name of the input file + * (input), and want to probe anything we find; if we have neither, we'll end + * up with a list of all of them. */ +static void DF_FindInputPlugin(int print, const char *type, const char *input, + struct df_fwk_list *l) +{ + int i; + const char *dlp = getenv("DEFILE_LIBRARY_PATH"); + + memset(l, 0, sizeof(struct df_fwk_list)); + l->i = input; + l->t = type; + l->r = 3; + + /* run through the search path looking for candidate libraries */ + if (dlp) + lt_dlforeachfile(dlp, DF_LTDLSearchFunc, l); + + /* the default plugin dir if the above didn't work; or if we're compiling a + * list */ + if ((type == NULL && input == NULL) || l->r != 0) + lt_dlforeachfile(DEFILE_MODULEDIR, DF_LTDLSearchFunc, l); + + if (print) { + for (i = 0; i < l->n; ++i) { + DF_InputBanner(stdout, "", l->l[i], l->p[i]); + free(l->p[i]); + } + + free(l->l); + free(l->p); + free(l->h); + } +} + +static const struct df_input_framework *DF_ResolveInput(const char *type) +{ + struct df_fwk_list l; + const struct df_input_framework *fwk = NULL; + + /* find the input library */ + DF_FindInputPlugin(0, type, NULL, &l); + free(l.p); + + if (l.l) { + fwk = l.l[0]; + df->inhandle = l.h[0]; + } + free(l.l); + free(l.h); + + if (l.r) { + if (l.r == 3) + fprintf(stderr, "Unable to find input plugin defile-%s.\n", type); + else if (l.r == 2) + fprintf(stderr, "No such symbol '%s_framework' in %s.\n", type, l.f); + else if (l.r == 1) + fprintf(stderr, + "Malformed data provided by symbol '%s_framework' in %s\n", type, + l.f); + else if (l.r == -1) + fprintf(stderr, "Illegal type: %s\n", type); + exit(1); + } + + free(l.f); + return fwk; +} + +static const struct df_input_framework *DF_AutoType(const char *input, + char** type) +{ + int i; + struct df_fwk_list l; + const struct df_input_framework *fwk = NULL; + + if (input == NULL) { + fprintf(stderr, "defile: error: no input specified.\n"); + exit(1); + } + + /* Gather a list of available input plugins, probing each one */ + DF_FindInputPlugin(0, NULL, input, &l); + + if (l.r) { + /* no one claimed the input */ + fprintf(stderr, "defile: error: automatic type detection failed.\n"); + exit(1); + } else if (l.n > 1) { + /* multiple claimants */ + fprintf(stderr, "defile: error: multiple input types possible:\n"); + for (i = 0; i < l.n; ++i) + DF_InputBanner(stderr, " ", l.l[i], l.p[i]); + exit(1); + } + + df->inhandle = l.h[0]; + fwk = l.l[0]; + free(l.f); + free(l.l); + free(l.h); + free(l.p); + + return fwk; +} + +static int DF_InputOpt(struct df_config *rc, const struct df_rc_config *config, + struct df_rc_data *rcd) +{ + static int mode = 0; + int value = config->value; + + /* after a second -- */ + if (mode == 1) + value = DF_RC_RAW_ARG; + + switch (value) { + case DF_RC_NO_MATCH: + DF_ConfigError(DF_CERR_FATAL, config, rcd, "Indecipherable input `%s'", + config->argument); + break; + case DF_RC_MODE_SW: + mode = 1; + break; + case DF_RC_RAW_ARG: + value = 0; + /* fallthrough */ + default: + rc->value = (int*)DF_Embiggen(rc->value, sizeof(int) * + (rc->n_config + 1)); + + rc->arg = (const char **)DF_Embiggen(rc->arg, + sizeof(const char *) * (rc->n_config + 1)); + + rc->value[rc->n_config] = value; + rc->arg[rc->n_config++] = config->argument; + } + + 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)); + } + } + + return 0; +} + +static int DF_FileToOFL(const char *name, int incl) +{ + abort(); + + return 0; +} + +enum { + DF_WOPT_ADD = 1, + DF_WOPT_ADDFROM, + DF_WOPT_ASYNC, + DF_WOPT_AUTOTYPE, + DF_WOPT_BHEAD, + DF_WOPT_BLEN, + DF_WOPT_CLOBBER, + DF_WOPT_DEL, + DF_WOPT_DELFROM, + DF_WOPT_DIR, + DF_WOPT_GZIP, + DF_WOPT_INPUT, + DF_WOPT_LIBDIR, + DF_WOPT_LIST, + DF_WOPT_NOCLOBBER, + DF_WOPT_OFLCLR, + DF_WOPT_OUTPUT, + DF_WOPT_PERSIST, + DF_WOPT_QUIET, + DF_WOPT_SYNC, + DF_WOPT_TERMEOF, + DF_WOPT_VERBOSE, + DF_WOPT_TYPE, +}; + +static int DF_OutputOpt(df_defiler df, struct df_rc_config *config, + struct df_rc_data *rcd) +{ + int i; + struct df_fwk_list l; + + if (df->mode_switch == 1) { + char **ptr = realloc(df->iargv, sizeof(char*) * ++df->iargc); + if (ptr == NULL) { + perror("malloc"); + return 1; + } + df->iargv = ptr; + + /* steal the argument */ + df->iargv[df->iargc - 1] = config->argument; + config->argument = NULL; + } else + switch (config->value) { + case DF_RC_NO_MATCH: + DF_ConfigError(DF_CERR_FATAL, config, rcd, "Indecipherable input `%s'", + config->argument); + break; + case DF_RC_RAW_ARG: + if (df->input == NULL) { + df->input = config->argument; + config->argument = NULL; + } else + DF_ConfigError(DF_CERR_FATAL, config, rcd, + "Unexpected bare word `%s'", config->argument); + break; + case DF_RC_MODE_SW: + df->mode_switch = 1; + break; + case DF_WOPT_ADD: /* -f */ + DF_UpdateOFL(config->argument, 1); + break; + case DF_WOPT_DEL: /* +f */ + DF_UpdateOFL(config->argument, 0); + break; + case DF_WOPT_ADDFROM: /* -F */ + DF_FileToOFL(config->argument, 1); + break; + case DF_WOPT_DELFROM: /* +F */ + DF_FileToOFL(config->argument, 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; + break; + case DF_WOPT_INPUT: /* -i */ + if (df->input == NULL) { + df->input = config->argument; + config->argument = NULL; + } else + DF_ConfigError(DF_CERR_FATAL, config, rcd, + "Too many inputs specified"); + break; + case DF_WOPT_LIBDIR: /* --lib-dir */ + printf("%s\n", DEFILE_MODULEDIR); + return 0; + case DF_WOPT_LIST: /* --list-types */ + DF_FindInputPlugin(1, NULL, NULL, &l); + return 0; + + + SETULONG(BHEAD, bufhead); + SETULONG(BLEN, buflen); + + SETLINT(CLOBBER, clobber, 1); + SETLINT(NOCLOBBER, clobber, 0); + + SETSTRING(DIR, dir); + SETSTRING(OUTPUT, output); + + SETBIT(PERSIST, config.mode_flags, DF_MODE_PERSIST); + CLRBIT(TERMEOF, config.mode_flags, DF_MODE_PERSIST); + + SETLINT(QUIET, quiet, 1); + SETLINT(VERBOSE, quiet, 0); + + SETBIT(ASYNC, config.mode_flags, DF_MODE_ASYNC); + CLRBIT(SYNC, config.mode_flags, DF_MODE_ASYNC); + + SETSTRING(TYPE, type); + CLRSTRING(AUTOTYPE, type); + } + + return -1; +} + +static char *DF_OutputName(const char *dir, const char *output, + const char *input) +{ + char *ptr; + + if (dir == NULL) { + if (output == NULL) { + fprintf(stderr, "defile: error: no output location specified.\n"); + return NULL; + } else + ptr = strdup(output); + } else if (output == NULL) { + char *ptr2, *ptr3; + ptr2 = strdup(input); + ptr3 = basename(ptr2); + ptr = malloc(strlen(dir) + strlen(ptr3) + 2); + strcat(strcat(strcpy(ptr, dir), "/"), ptr3); + free(ptr2); + } else if (output[0] == '/') { + ptr = strdup(output); + } else { + ptr = malloc(strlen(dir) + strlen(output) + 2); + strcat(strcat(strcpy(ptr, dir), "/"), output); + } + + return ptr; +} + +static void DF_OutputFini(int delete) +{ + gd_close(df->D); + + if (delete) { + pid_t pid = fork(); + if (pid > 0) + waitpid(pid, NULL, 0); + else if (pid == 0) { + execl(PATH_RM, PATH_RM, "-rf", df->output, (char*)NULL); + exit(1); + } + } + free(df->output); +} + +static void DF_CreateOutput(unsigned long flags) +{ + df->flags = flags; + + df->D = gd_open(df->dirfile, GD_RDWR | GD_CREAT | ((flags & DF_CLOBBER) ? + GD_TRUNC : GD_EXCL) | GD_VERBOSE); + + if (gd_error(df->D)) { + char *err = gd_error_string(df->D, NULL, 0); + fprintf(stderr, "defile: getdata error: %s\n", err); + free(err); + DF_OutputFini(0); + exit(1); + } +} + +/* check thread status; returns zero when we're done */ +static int DF_ThreadCheck(df_defiler df) +{ + /* error */ + if (df->input_state < 0 || df->output_state < 0) + return 0; + + /* done */ + if (df->input_state == DF_ST_DONE && df->output_state == DF_ST_DONE) + return 0; + + /* still going */ + return 1; +} + +/* wait while the input does something */ +static inline void DF_WaitWhileInputState(int state) +{ + while (df->input_state == state) + usleep(10000); +} + +/* output thread */ +static void *DF_OutputThread(void) +{ + int i, j, last_pass = 0; + size_t nwrote; + struct df_raw *r; + unsigned long in, out, nf; + + /* wait for the input to initialise */ + DF_WaitWhileInputState(DF_ST_STARTUP); + + /* initialise the output */ + df->dirfile = DF_OutputName(df->dir, df->output, df->input); + if (!df->dirfile) + exit(1); + + DF_CreateOutput(df->clobber ? DF_CLOBBER : 0); + + /* signal we're ready for metadata */ + df->output_state = DF_ST_BUILDING; + + /* wait for the input to build the dirfile */ + DF_WaitWhileInputState(DF_ST_BUILDING); + + /* write metadata to disk */ + gd_metaflush(df->D); + + /* signal we're ready to for data */ + df->output_state = DF_ST_RUNNING; + + /* loop through raws, writing ones that have full buffer heads */ + while (!last_pass) { + if (df->input_state != DF_ST_RUNNING) + last_pass = 1; + + for (i = 0; i < df->nraw; ++i) { + r = df->raw + i; + in = r->in; + out = r->out; + nf = (in == out) ? df->buflen - 1 : + ((in + r->buflen - out) % r->buflen) / r->framesize - 1; + + if (nf == 0 || (!last_pass && nf <= df->bufhead)) + continue; + + /* in synchronous mode, the reference field is special: we only write + * frames to it if all other fields have those frames committed */ + if (i == df->ref_ind && !(df->config.mode_flags & DF_MODE_ASYNC)) { + /* adjust for shorter sticks */ + for (j = 0; j < df->nraw; ++j) + if (j != df->ref_ind) + if (nf > df->raw[j].ahead) + nf = df->raw[j].ahead; + + /* check again */ + if (nf == 0 || (!last_pass && nf <= df->bufhead)) + continue; + } + + /* point the local output pointer to the next datum to write */ + out = (out + r->framesize) % r->buflen; + + if (out + nf * r->framesize > r->buflen) { + size_t partial = (r->buflen - out) / r->framesize; + nwrote = gd_putdata(df->D, r->name, GD_HERE, 0, partial, 0, r->type, + r->b + out); + + if (!gd_error(df->D) && nwrote == partial * r->spf) + nwrote += gd_putdata(df->D, r->name, GD_HERE, 0, nf - partial, 0, + r->type, r->b); + } else + nwrote = gd_putdata(df->D, r->name, GD_HERE, 0, nf, 0, r->type, + r->b + out); + + /* bail on error */ + if (gd_error(df->D)) { + df->output_state = DF_ST_ERROR; + exit(1); + } + + if (nwrote > 0) + last_pass = 0; + + /* update ahead counts */ + nf = nwrote / r->spf; + if (i == df->ref_ind) { + for (j = 0; j < df->nraw; ++j) + if (j != df->ref_ind) /* XXX */ + df->raw[j].ahead -= nf; + } else + r->ahead += nwrote / r->spf; + + /* update write pointer */ + r->out = (r->out + nwrote * GD_SIZE(r->type)) % r->buflen; + + /* update write counts */ + df->wpartial += nwrote * GD_SIZE(r->type); + while (df->wpartial >= df->wframesize) { + df->nwrote++; + df->wpartial -= df->wframesize; + } + } + usleep(10000); + } + + /* finished */ + gd_close(df->D); + + /* done */ + df->output_state = DF_ST_DONE; + return NULL; +} + +/* input thread container. */ +static void *DF_InputThread(void) +{ + int status; + + /* Execute the input and wait for it to finish */ + status = df->input_framework->entry(&df->config); + + /* report status */ + df->input_state = status ? DF_ST_ERROR : DF_ST_DONE; + + /* done */ + return NULL; +} + +/* print the rate information */ +#define RATE_TC (120.) /* rate IIR characteristic time (in seconds) */ +static double DF_PrintRate(struct timeval *then, double rate) +{ + static unsigned long long lw = 0; + static int init = 2; + + double delta, drate; + unsigned long long nf; + const unsigned long long nw = df->nwrote; + const unsigned long long nr = df->nread; + char si; + struct timezone tz; + struct timeval now; + + if (df->quiet) + return rate; + + gettimeofday(&now, &tz); + nf = nw - lw; + lw = nw; + delta = (now.tv_sec - then->tv_sec) + (now.tv_usec - then->tv_usec) / 1e6; + *then = now; + if (init) { + if (rate < 0) { + rate = nf / delta; + } else { + if (init == 2) + df->tc = RATE_TC; + + if (nf > 0) + init = 0; + } + + if (init == 2) + init = 1; + } else { + rate = nf / df->tc + rate * (1 - delta / df->tc); + + if (df->tc < RATE_TC) { + df->tc += delta / 2; + if (df->tc > RATE_TC) + df->tc = RATE_TC; + } + } + + drate = rate; + + /* SI prefix */ + if (drate >= 1e9) { + drate /= 1e9; + si = 'G'; + } else if (drate >= 1e6) { + drate /= 1e6; + si = 'M'; + } else if (drate >= 1e3) { + drate /= 1e3; + si = 'k'; + } else if (drate >= 1) { + si = ' '; + } else { /* underflows at 0.0005 mHz = 1 frame every 23 days */ + drate *= 1e3; + si = 'm'; + } + if (df->nframes > 0) + printf("R:[%llu(%llu) of %llu] W:[%llu(%llu)] %.*f %cHz \r", nr, + (unsigned long long)df->rpartial, df->nframes, nw, + (unsigned long long)df->wpartial, + (drate >= 100) ? 1 : (drate >= 10) ? 2 : 3, drate, si); + else + printf("R:[%llu] W:[%llu] %.*f %cHz \r", nr, nw, + (drate >= 100) ? 1 : (drate >= 10) ? 2 : 3, drate, si); + fflush(stdout); + + return rate; +} + +static void DF_ShutdownLTDL(void) +{ + lt_dlclose(df->inhandle); + lt_dlexit(); +} + +static void DF_Delete(void) +{ + int i; + + for (i = 0; i < df->nofl; ++i) + free(df->ofl[i]); + free(df->ofl); + + for (i = 1; i < df->iargc; ++i) + free(df->iargv[i]); + free(df->iargv); + + for (i = 0; i < df->nraw; ++i) { + free(df->raw[i].name); + free(df->raw[i].b); + } + free(df->raw); + + for (i = 0; i < df->nfd; ++i) + free(df->fd[i].field); + free(df->fd); + + free(df->input); + free(df->output); + free(df->dirfile); + free(df->dir); + free(df->type); +} + +int main(int argc, char **argv) +{ + pthread_t input_thread, output_thread; + + /* rate stuff */ + double rate; + struct timeval then; + struct timezone tz; + + sigset_t signals; + struct sigaction action; + + const struct df_optdef options[] = { + { DF_WOPT_ASYNC, DF_OPT_NO_ARG, 'a', "asyncrhonous", "Asynchronous", 0, + NULL, + "allow field in the output dirfile to be written to disk independantly " + "of each other; for some input types, this can greatly increase the " + "efficiency of the conversion" + }, + { DF_WOPT_SYNC, DF_OPT_NO_ARG, 'a', "synchronous", "Synchronous", + DF_OPT_PLUS, NULL, + "ensure that the output dirfile's reference field never has more data " + "any other raw field (the default behaviour)" + }, + { DF_WOPT_CLOBBER, DF_OPT_NO_ARG, 0, "clobber", "Clobber", 0, NULL, + "if the output dirfile already exists, overwrite it; this will delete " + "every regular file in the target directory; use with caution" + }, + { DF_WOPT_NOCLOBBER, DF_OPT_NO_ARG, 0, "no-clobber", "NoClobber", 0, NULL, + "don't overwrite an existing dirfile (the default behaviour)" + }, + { DF_WOPT_DIR, DF_OPT_ARG_RQ, 'd', "directory", "Directory", DF_OPT_EXPAND, + "DIR", + "if -o is not specified, create the output dirfile as a subdirectory " + "under DIR, with a name based on the name of the input file; if -o is " + "used, but does not specify an absolute path, create the specified " + "output dirfile under DIR; if -o specifies an absolute path, this " + "option is ignored" + }, + { DF_WOPT_ADD, DF_OPT_ARG_RQ, 'f', "include", "WriteField", 0, "FIELD", + "add FIELD to the output field list; this option may be given multiple " + "times to build up a list of fields to include, and may be used in " + "conjunction with -F; however, mixing -[fF] with +[fF] may not work as " + "expected; inserting --reset-field-list before switching from -[fF] to " + "+[fF] is recommended" + }, + { DF_WOPT_DEL, DF_OPT_ARG_RQ, 'f', "exclude", "IgnoreField", DF_OPT_PLUS, + "FIELD", + "remove FIELD from the output field list; this option may be given " + "multiple times to build up a list of fields to exclude, and may be " + "used in conjunction with +F; however, mixing +[fF] with -[fF] may not " + "work as expected; inserting --reset-field-list before switching from " + "+[fF] to -[fF] is recommended" + }, + { DF_WOPT_ADDFROM, DF_OPT_ARG_RQ, 'F', "include-from", "WriteAllFrom", + DF_OPT_EXPAND, "FILE", + "add all fields given in FILE (one field name per line) to the output " + "field list; this option may be given multiple times; see -f for " + "caveats concerning combinding this option with +f or +F" + }, + { DF_WOPT_DELFROM, DF_OPT_ARG_RQ, 'F', "exclude-from", "IgnoreAllFrom", + DF_OPT_PLUS | DF_OPT_EXPAND, "FILE", + "remove all fields given in FILE (one field name per line) from the " + "output field list; this option may be given multiple times; see +f " + "for caveats concerning combinding this option with -f or -F" + }, + { DF_WOPT_BHEAD, DF_OPT_ARG_RQ, 'h', "buf-head", "BufferHead", 0, "N", + "set the length of the output buffer head to N frames; defile waits for " + "the buffer head to fill up before writing the accumulated buffer to " + "disk; the default value is zero, meaning data are written as soon as " + "possible; setting this to a non-zero number may improve performance, " + "at the cost of latency and memory usage; see also -l below" + }, + { DF_WOPT_INPUT, DF_OPT_ARG_RQ, 'i', "input", "Input", 0, "PATH", + "read input data from PATH; typically the input PATH can be specified as " + "a bare argument, without the need for -i; this option is provided " + "only for use in situations where PATH begins with - or + (and would, " + "therefore, be mistaken for an option)" + }, + { DF_WOPT_BLEN, DF_OPT_ARG_RQ, 'l', "buf-len", "BufferLen", 0, "N", + "set the length of the output buffer to N frames; the default value " + "is " DF_STRINGIFY(DF_BUFLEN) " frames; decreasing this will reduce " + "memory usage at the expense of performance; if this is smaller than " + "the buffer header (see -h above), the output buffer will be expanded " + "to accommodate it" + }, + { DF_WOPT_LIBDIR, DF_OPT_NO_ARG, 0, "lib-dir", NULL, 0, NULL, + "print the default input plugin path and exit" + }, + { DF_WOPT_LIST, DF_OPT_NO_ARG, 0, "list-types", NULL, 0, NULL, + "print a list of available input plugins and exit" + }, + { DF_WOPT_OFLCLR, DF_OPT_NO_ARG, 0, "reset-field-list", "ResetFieldList", 0, + NULL, + "ignore all previous options which modifiy the ouput field list (-f, +f, " + "-F, +F); this is typically not needed, but can be used if the current " + "contents of the output field list is unknown" + }, + { DF_WOPT_OUTPUT, DF_OPT_ARG_RQ, 'o', "output", "Output", DF_OPT_EXPAND, + "PATH", "write data to a dirfile called PATH; if PATH is relative, it is " + "created relative the current directory, unless -d is also specified" + }, + { DF_WOPT_PERSIST, DF_OPT_NO_ARG, 'p', "persistent", "Persistent", 0, NULL, + "upon reaching the end of the input, do not exit, but monitor the input " + "for additional data, and keep writing to the output as new data " + "appears; implies -s" + }, + { DF_WOPT_TERMEOF, DF_OPT_NO_ARG, 'p', "terminate-on-eof", "TerminateOnEOF", + DF_OPT_PLUS, NULL, + "finalise the output and exit upon reaching the end of the input (the " + "default behaviour)" + }, + { DF_WOPT_QUIET, DF_OPT_NO_ARG, 'q', "quiet", "Quiet", 0, NULL, + "be less verbose" + }, + { DF_WOPT_VERBOSE, DF_OPT_NO_ARG, 'q', "verbose", "Verbose", DF_OPT_PLUS, + NULL, "be normally verbose" + }, + { DF_WOPT_TYPE, DF_OPT_ARG_RQ, 't', "type", "InputType", 0, "TYPE", + "use TYPE as the input data type" + }, + { DF_WOPT_AUTOTYPE, DF_OPT_NO_ARG, 't', "autotype", "AutoType", DF_OPT_PLUS, + NULL, "attempt to automatically determine the data type of the input" + }, + { DF_WOPT_GZIP, DF_OPT_NO_ARG, 'z', "gzip", "GZip", 0, NULL, + "gzip compress the output raw data" + }, + { DF_OPT_ENDOPT } + }; + + struct df_rc_data rcd = { + .contact = DEFILE_CONTACT, + .copyright = DEFILE_COPYRIGHT, + .default_config = "defilerc", + .flags = DF_RC_FLAG_NMSB, + .licence = DF_LICENCE_GPL, + .name = NULL, + .options = options, + .parser = (df_parser_func_t)DF_OutputOpt, + .usage_preamble = DEFILE_USAGE_PREAMBLE, + .usage_postamble = NULL, + .version = PACKAGE_VERSION + }; + + /* clean up the defile object at exit */ + atexit(DF_Delete); + + df->iargv = malloc(sizeof(char*)); + df->iargv[0] = argv[0]; + df->iargc = 1; + df->buflen = DF_BUFLEN; + + /* initialise LTDL and register its cleanup function */ + lt_dlinit(); + atexit(DF_ShutdownLTDL); + + DF_Parse(argc, argv, &rcd, df); + + /* sanitise */ + if (df->buflen < df->bufhead) + df->buflen = df->bufhead; + + if (!df->quiet) + puts(PACKAGE_STRING " " DEFILE_COPYRIGHT); + + /* No input type specified, try looping through a list of them */ + if (df->type == NULL) + df->input_framework = DF_AutoType(df->input, &df->type); + else /* Load the input plugin */ + df->input_framework = DF_ResolveInput(df->type); + + if (!df->quiet) + DF_InputBanner(stdout, NULL, df->input_framework, NULL); + putchar('\n'); + + /* parse input options */ + memset(&rcd, 0, sizeof(rcd)); + rcd.contact = df->input_framework->contact; + rcd.copyright = df->input_framework->copyright; + rcd.default_config = NULL; + rcd.flags = 0, + rcd.licence = df->input_framework->licence; + rcd.name = df->type; + rcd.options = df->input_framework->opts; + rcd.parser = (df_parser_func_t)DF_InputOpt; + rcd.usage_preamble = df->input_framework->preamble; + rcd.usage_postamble = df->input_framework->postamble; + rcd.version = df->input_framework->version ? df->input_framework->version : + "(unknown)"; + + /* parse the input options */ + DF_Parse(df->iargc, df->iargv, &rcd, &df->config); + + if (df->input == NULL) { + fprintf(stderr, "defile: error: no input specified.\n"); + exit(1); + } + + /* set up signal masks and handlers */ + sigemptyset(&signals); + sigaddset(&signals, SIGHUP); + sigaddset(&signals, SIGINT); + sigaddset(&signals, SIGTERM); + + action.sa_handler = DF_SignalHandler; + action.sa_mask = signals; + sigaction(SIGHUP, &action, NULL); + sigaction(SIGTERM, &action, NULL); + sigaction(SIGINT, &action, NULL); + + /* block signals */ + pthread_sigmask(SIG_BLOCK, &signals, NULL); + + /* start the threads */ + df->input_state = DF_ST_STARTUP; + if (pthread_create(&input_thread, NULL, (void*(*)(void*))DF_InputThread, + NULL)) + { + perror("pthread_create"); + exit(1); + } + + /* start the output thread */ + df->output_state = DF_ST_STARTUP; + if (pthread_create(&output_thread, NULL, (void*(*)(void*))DF_OutputThread, + NULL)) + { + perror("pthread_create"); + exit(1); + } + + /* unblock signals */ + pthread_sigmask(SIG_UNBLOCK, &signals, NULL); + + /* wait until the initialisation is done */ + DF_WaitWhileInputState(DF_ST_STARTUP); + DF_WaitWhileInputState(DF_ST_BUILDING); + + /* record our "start" time */ + gettimeofday(&then, &tz); + rate = df->rate; + + /* status loop */ + df->tc = 1.; + while (DF_ThreadCheck(df)) { + /* print the status line, if necessary */ + rate = DF_PrintRate(&then, rate); + usleep(500000); /* ~2Hz refresh rate */ + } + + DF_PrintRate(&then, rate); + if (!df->quiet) + putchar('\n'); + + pthread_join(input_thread, NULL); + pthread_join(output_thread, NULL); + + return 0; +} Added: trunk/defile/bin/rc.c =================================================================== --- trunk/defile/bin/rc.c (rev 0) +++ trunk/defile/bin/rc.c 2012-02-20 19:08:21 UTC (rev 661) @@ -0,0 +1,761 @@ +/* (C) 2005, 2006, 2007, 2012 D. V. Wiebe + * + *************************************************************************** + * + * This file is part of Defile. + * + * Defile is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Defile 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 Defile; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "internal.h" +#include "rc.h" + +#include <errno.h> +#include <libgen.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <stdarg.h> +#include <ctype.h> + +#define SHIFT_OFF 0x0 +#define SHIFT_ON 0x1 +#define SHIFT_NEXT 0x2 +#define SHIFT_THIS 0x4 + +#define SAME_BOILERPLATE \ + "\nThis program comes with NO WARRANTY, not even for MERCHANTABILITY or " \ +"FITNESS\nFOR A PARTICULAR PURPOSE. You may redistribute it under the " \ +"same terms as defile\nitself. For details, execute:\n\n" \ +" %s --version\n" + +#define GPL_BOILERPLATE \ + "\nThis program comes with NO WARRANTY, not even for MERCHANTABILITY or " \ +"FITNESS\nFOR A PARTICULAR PURPOSE. You may redistribute it under the " \ +"terms of the GNU\nGeneral Public License, either version 2 of the " \ +"License, or (at your option)\nany later version.\n\nYou should have " \ +"received a copy of the GNU General Public License along with\n" \ +"this program; if not, write to the Free Software Foundation, Inc.,\n" \ +"51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA" + +#define LGPL_BOILERPLATE \ + "\nThis program comes with NO WARRANTY, not even for MERCHANTABILITY or " \ +"FITNESS\nFOR A PARTICULAR PURPOSE. You may redistribute it under the " \ +"terms of the GNU\nLesser General Public License, either version 2.1 of the " \ +"License, or (at your\noption) any later version.\n\nYou should have " \ +"received a copy of the GNU General Public License along with\n" \ +"this program; if not, write to the Free Software Foundation, Inc.,\n" \ +"51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA" + +static const struct df_optdef df_no_opts[] = { + { DF_OPT_ENDOPT } +}; + +struct shortarg_s { + int option; + int position; +}; + +static void DF_ReadConfigFile(const char* name, int skip_ok, const char* label, + struct df_rc_data *rcd); + +#ifdef DF_DEBUG +#define logprintf printf +#else +#define logprintf(...) +#endif + +#define DF_OPT_WIDTH 26 +#define DF_TTY_WIDTH 80 + +static void DF_OptUsage(const struct df_optdef *opt, char shift_char) +{ + const char *u; + int pos = 7; + char sopt[5] = " "; + + /* short option */ + if (opt->sopt) { + sopt[0] = (opt->flags & DF_OPT_PLUS) ? '+' : '-'; + if (opt->flags & DF_OPT_SHIFT) { + sopt[1] = shift_char; + sopt[2] = opt->sopt; + sopt[3] = ','; + } else { + sopt[1] = opt->sopt; + sopt[2] = ','; + sopt[3] = ' '; + } + } + printf(" %s ", sopt); + + /* long option */ + if (opt->lopt) { + pos += printf("--%s", opt->lopt); + if (opt->type == DF_OPT_ARG_RQ) + pos += printf("=%s", opt->argname ? opt->argname : "ARG"); + else if (opt->type == DF_OPT_ARG_OP) + pos += printf("[=%s]", opt->argname ? opt->argname : "ARG"); + } + if (pos > DF_OPT_WIDTH) { + putchar('\n'); + pos = 0; + } + for (; pos <= DF_OPT_WIDTH; ++pos) + putchar(' '); + + /* usage */ + u = (opt->usage && *opt->usage) ? opt->usage + : "no help is available for this option"; + + /* strip leading whitespace */ + while (isspace(*u)) + u++; + + /* output usage */ + for (;;) { + const char *sw, *ew; + /* find the ne... [truncated message content] |