[Getdata-commits] SF.net SVN: getdata:[749] trunk/getdata
Scientific Database Format
Brought to you by:
ketiltrout
|
From: <ket...@us...> - 2012-07-26 00:18:00
|
Revision: 749
http://getdata.svn.sourceforge.net/getdata/?rev=749&view=rev
Author: ketiltrout
Date: 2012-07-26 00:17:51 +0000 (Thu, 26 Jul 2012)
Log Message:
-----------
Automake affix bookkeeping when reading metadata.
Modified Paths:
--------------
trunk/getdata/ChangeLog
trunk/getdata/NEWS
trunk/getdata/bindings/perl/GetData.xs
trunk/getdata/man/gd_include_affix.3
trunk/getdata/src/add.c
trunk/getdata/src/common.c
trunk/getdata/src/entry.c
trunk/getdata/src/flush.c
trunk/getdata/src/fragment.c
trunk/getdata/src/internal.h
trunk/getdata/src/mod.c
trunk/getdata/src/move.c
trunk/getdata/src/name.c
trunk/getdata/src/parse.c
trunk/getdata/test/Makefile.am
trunk/getdata/test/add_affix.c
trunk/getdata/test/add_string_affix.c
trunk/getdata/test/madd_affix.c
Added Paths:
-----------
trunk/getdata/test/add_alias_affix.c
trunk/getdata/test/add_lincom_affix.c
trunk/getdata/test/add_spec_affix.c
trunk/getdata/test/alter_lincom_affix.c
trunk/getdata/test/alter_scalar_affix.c
trunk/getdata/test/get_affix.c
trunk/getdata/test/madd_alias_affix.c
Property Changed:
----------------
trunk/getdata/test/
Modified: trunk/getdata/ChangeLog
===================================================================
--- trunk/getdata/ChangeLog 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/ChangeLog 2012-07-26 00:17:51 UTC (rev 749)
@@ -1,3 +1,33 @@
+2012-07-26 D. V. Wiebe <ge...@ke...> svn:749
+ * src/parse.c (_GD_SetScalar _GD_ParseLincom _GD_ParseLinterp
+ _GD_ParseMultiply _GD_ParseRecip _GD_ParseWindow _GD_ParseMplex
+ _GD_ParseDivide _GD_ParseBit _GD_ParsePhase _GD_ParsePolynom
+ _GD_ParseAlias): Store munged input fields.
+ * src/entry.c (_GD_GetScalar) src/common.c (_GD_BadInput) src/parse.c
+ (_GD_ResolveAlias): Don't (re-)munge field codes.
+
+ * src/name.c (_GD_MungeCode): Take an additional parameter, err_ok,
+ indicating whether missing affixes indicate an internal error or not.
+
+ * src/mod.c (_GD_AlterInField) src/name.c (_GD_CheckCodeAffixes): Added.
+ * src/mod.c (_GD_AlterScalar) src/add.c (_GD_FixName _GD_Add _GD_AddAlias):
+ Call _GD_CheckCodeAffixes.
+ * src/mod.c (_GD_Change): Call _GD_AlterInField to modify in_fields.
+
+ * src/flush.c (_GD_WriteFieldCode): Added.
+ * src/flush.c (_GD_PadField _GD_WriteConst _GD_FieldSpec): Call
+ _GD_WriteFieldCode.
+
+ * test/get_affix.c test/add_alias_affix.c test/add_alias_affix.c
+ test/add_spec_affix.c test/madd_alias_affix.c test/alter_lincom_affix.c
+ test/add_lincom_affix.c test/alter_scalar_affix.c: Added.
+
+ * test/add_string_affix.c test/madd_affix.c test/add_affix.c: Update for new
+ affix semantics.
+
+ * src/mod.c (gd_alter_entry) src/add.c (gd_madd_alias): Clear error when
+ starting.
+
2012-07-12 D. V. Wiebe <ge...@ke...> svn:743
* bindings/f77/fgetdata.c (GDALLC): Delete unnecessary malloc.
* src/fragment.c (_GD_CheckAffixes): Free subaffixes on error.
Modified: trunk/getdata/NEWS
===================================================================
--- trunk/getdata/NEWS 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/NEWS 2012-07-26 00:17:51 UTC (rev 749)
@@ -1,6 +1,41 @@
+New in version 0.8.1:
+
+ Library Changes:
+
+ * BUG FIX: A segfault when negotiating symbolic links in file paths, typically
+ manifesting in gd_open calls, has been fixed.
+
+ * BUG FIX: gd_strtok now saves a copy of the string passed to it, as the
+ documentation suggests it should. Previously it cached the pointer itself.
+
+ * BUG FIX: A number of minor memory leaks, mostly occurring when the library
+ encounters an error, have been fixed.
+
+ * WIN32 BUG FIX: On Windows, the parser can now properly handle hexadecimal
+ floating point.
+
+ API Changes:
+
+ * How the API deals with field code affixes has changed. Input vector and
+ scalar fields are reported by gd_entry(), &c. now include their prefix and
+ suffix, if any, which should remove the need to do manual affix bookkeeping
+ when reading metadata. The other side to this change is that when modifying
+ metdata (gd_add(), gd_alter_entry(), &c.), supplied field codes must also
+ contain the appropriate suffixes.
+
+ * BUG FIX: gd_alter_entry() and gd_madd_alias() weren't clearing the Dirfile
+ error before operation, resulting in them failing erroneously in certain
+ situations.
+
+ Bindings Changes:
+
+ * F77 BUG FIX: A memory leak has been fixed in GDALLC.
+
+|==============================================================================|
+
New in version 0.8.0:
- Dirfile Changes
+ Dirfile Changes:
* Dirfile Standards Version 9 has been released. It adds two new field
types: MPLEX, which allows multiplexing multiple low-rate channels in
Modified: trunk/getdata/bindings/perl/GetData.xs
===================================================================
--- trunk/getdata/bindings/perl/GetData.xs 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/bindings/perl/GetData.xs 2012-07-26 00:17:51 UTC (rev 749)
@@ -1126,7 +1126,6 @@
GDP_PUSHuv(E.field_type);
GDP_PUSHpvn("fragment_index");
GDP_PUSHuv(E.fragment_index);
- dwatch("%i", E.field_type);
switch (E.field_type) {
case GD_BIT_ENTRY:
case GD_SBIT_ENTRY:
Modified: trunk/getdata/man/gd_include_affix.3
===================================================================
--- trunk/getdata/man/gd_include_affix.3 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/man/gd_include_affix.3 2012-07-26 00:17:51 UTC (rev 749)
@@ -23,7 +23,7 @@
.nh
.ad l
.BI "int gd_include_affix(DIRFILE *" dirfile ", const char *" include_file ,
-.BI "int " parent_fragment ", const char *" prefix , "const char *" suffix ,
+.BI "int " parent_fragment ", const char *" prefix ", const char *" suffix ,
.BI "unsigned long " flags );
.HP
.BI "int gd_include(DIRFILE *" dirfile ", const char *" include_file ,
Modified: trunk/getdata/src/add.c
===================================================================
--- trunk/getdata/src/add.c 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/src/add.c 2012-07-26 00:17:51 UTC (rev 749)
@@ -45,8 +45,13 @@
dtrace("%p, %p, \"%s\", %i, %p", D, buffer, name, frag, offset);
- /* Apply prefix and suffix */
- *buffer = ptr = _GD_MungeFromFrag(D, NULL, frag, name, offset);
+ /* Check prefix and suffix */
+ if (_GD_CheckCodeAffixes(D, NULL, name, frag)) {
+ dreturn("%p", NULL);
+ return NULL;
+ }
+
+ *buffer = ptr = _GD_Strdup(D, name);
if (ptr == NULL) {
free(ptr);
@@ -78,7 +83,8 @@
sprintf(temp2, "%s/%s", P->field, ptr);
free(*buffer);
*buffer = temp2;
- }
+ } else
+ *offset = 0;
dreturn("%p (\"%s\", %i)", P, *buffer, *offset);
return P;
@@ -148,8 +154,8 @@
temp_buffer[offset - 1] = '/';
strcpy(temp_buffer + offset, entry->field);
} else {
- /* this will munge the name and take care of detecting Barth-style metafield
- * definitions */
+ /* this will check for affixes and take care of detecting Barth-style
+ * metafield definitions */
P = _GD_FixName(D, &temp_buffer, entry->field, entry->fragment_index,
&offset);
@@ -275,6 +281,18 @@
if (E->EN(lincom,n_fields) < 1 || E->EN(lincom,n_fields) > GD_MAX_LINCOM)
_GD_SetError(D, GD_E_BAD_ENTRY, GD_E_ENTRY_NFIELDS, NULL,
E->EN(lincom,n_fields), NULL);
+
+ for (i = 0; i < E->EN(lincom,n_fields); ++i) {
+ _GD_CheckCodeAffixes(D, NULL, entry->in_fields[i],
+ entry->fragment_index);
+ _GD_CheckCodeAffixes(D, NULL, entry->scalar[i], entry->fragment_index);
+ _GD_CheckCodeAffixes(D, NULL, entry->scalar[i + GD_MAX_LINCOM],
+ entry->fragment_index);
+ }
+
+ if (D->error)
+ break;
+
else {
if (entry->comp_scal) {
int cs = 0;
@@ -310,15 +328,34 @@
case GD_LINTERP_ENTRY:
E->e->u.linterp.table_len = -1;
+ if (_GD_CheckCodeAffixes(D, NULL, entry->in_fields[0],
+ entry->fragment_index))
+ {
+ break;
+ }
+
E->in_fields[0] = _GD_Strdup(D, entry->in_fields[0]);
E->EN(linterp,table) = _GD_Strdup(D, entry->EN(linterp,table));
break;
case GD_MULTIPLY_ENTRY:
case GD_DIVIDE_ENTRY:
+ if (_GD_CheckCodeAffixes(D, NULL, entry->in_fields[0],
+ entry->fragment_index) || _GD_CheckCodeAffixes(D, NULL,
+ entry->in_fields[1], entry->fragment_index))
+ {
+ break;
+ }
+
E->in_fields[0] = _GD_Strdup(D, entry->in_fields[0]);
E->in_fields[1] = _GD_Strdup(D, entry->in_fields[1]);
break;
case GD_RECIP_ENTRY:
+ if (_GD_CheckCodeAffixes(D, NULL, entry->in_fields[0],
+ entry->fragment_index))
+ {
+ break;
+ }
+
E->in_fields[0] = _GD_Strdup(D, entry->in_fields[0]);
copy_scalar[0] = 1;
@@ -337,6 +374,12 @@
E->EN(bit,numbits) = entry->EN(bit,numbits);
E->EN(bit,bitnum) = entry->EN(bit,bitnum);
+ if (_GD_CheckCodeAffixes(D, NULL, entry->in_fields[0],
+ entry->fragment_index))
+ {
+ break;
+ }
+
E->in_fields[0] = _GD_Strdup(D, entry->in_fields[0]);
if (E->EN(bit,numbits) < 1)
_GD_SetError(D, GD_E_BAD_ENTRY, GD_E_ENTRY_NUMBITS, NULL,
@@ -352,6 +395,12 @@
case GD_PHASE_ENTRY:
E->EN(phase,shift) = entry->EN(phase,shift);
+ if (_GD_CheckCodeAffixes(D, NULL, entry->in_fields[0],
+ entry->fragment_index))
+ {
+ break;
+ }
+
E->in_fields[0] = _GD_Strdup(D, entry->in_fields[0]);
copy_scalar[0] = 1;
break;
@@ -359,6 +408,13 @@
E->EN(window,windop) = entry->EN(window,windop);
E->EN(window,threshold) = entry->EN(window,threshold);
+ if (_GD_CheckCodeAffixes(D, NULL, entry->in_fields[0],
+ entry->fragment_index) || _GD_CheckCodeAffixes(D, NULL,
+ entry->in_fields[1], entry->fragment_index))
+ {
+ break;
+ }
+
E->in_fields[0] = _GD_Strdup(D, entry->in_fields[0]);
E->in_fields[1] = _GD_Strdup(D, entry->in_fields[1]);
if (_GD_BadWindop(E->EN(window,windop)))
@@ -369,6 +425,14 @@
case GD_MPLEX_ENTRY:
E->EN(mplex,count_val) = entry->EN(mplex,count_val);
E->EN(mplex,count_max) = entry->EN(mplex,count_max);
+
+ if (_GD_CheckCodeAffixes(D, NULL, entry->in_fields[0],
+ entry->fragment_index) || _GD_CheckCodeAffixes(D, NULL,
+ entry->in_fields[1], entry->fragment_index))
+ {
+ break;
+ }
+
E->in_fields[0] = _GD_Strdup(D, entry->in_fields[0]);
E->in_fields[1] = _GD_Strdup(D, entry->in_fields[1]);
E->e->u.mplex.type = GD_NULL;
@@ -430,29 +494,36 @@
{
_GD_SetError(D, GD_E_BAD_ENTRY, GD_E_ENTRY_NFIELDS, NULL,
E->EN(polynom,poly_ord), NULL);
+ } else {
+ _GD_CheckCodeAffixes(D, NULL, entry->in_fields[0],
+ entry->fragment_index);
+ _GD_CheckCodeAffixes(D, NULL, entry->in_fields[1],
+ entry->fragment_index);
}
- else {
- if (entry->comp_scal) {
- int cs = 0;
- memcpy(E->EN(polynom,ca), entry->EN(polynom,ca), sizeof(double) * 2 *
- (E->EN(polynom,poly_ord) + 1));
- for (i = 0; i <= E->EN(polynom,poly_ord); ++i) {
- E->EN(polynom,a)[i] = creal(E->EN(polynom,ca)[i]);
- if (cimag(E->EN(polynom,ca)[i]))
- cs = 1;
- }
- E->comp_scal = cs;
- } else {
- memcpy(E->EN(polynom,a), entry->EN(polynom,a), sizeof(double) *
- (E->EN(polynom,poly_ord) + 1));
- for (i = 0; i <= E->EN(polynom,poly_ord); ++i)
- _gd_r2c(E->EN(polynom,ca)[i], E->EN(polynom,a)[i]);
- E->comp_scal = 0;
+
+ if (D->error)
+ break;
+
+ if (entry->comp_scal) {
+ int cs = 0;
+ memcpy(E->EN(polynom,ca), entry->EN(polynom,ca), sizeof(double) * 2 *
+ (E->EN(polynom,poly_ord) + 1));
+ for (i = 0; i <= E->EN(polynom,poly_ord); ++i) {
+ E->EN(polynom,a)[i] = creal(E->EN(polynom,ca)[i]);
+ if (cimag(E->EN(polynom,ca)[i]))
+ cs = 1;
}
-
- E->in_fields[0] = _GD_Strdup(D, entry->in_fields[0]);
+ E->comp_scal = cs;
+ } else {
+ memcpy(E->EN(polynom,a), entry->EN(polynom,a), sizeof(double) *
+ (E->EN(polynom,poly_ord) + 1));
+ for (i = 0; i <= E->EN(polynom,poly_ord); ++i)
+ _gd_r2c(E->EN(polynom,ca)[i], E->EN(polynom,a)[i]);
+ E->comp_scal = 0;
}
+ E->in_fields[0] = _GD_Strdup(D, entry->in_fields[0]);
+
for (i = 0; i < E->EN(polynom,poly_ord); ++i)
copy_scalar[i] = 1;
break;
@@ -468,6 +539,11 @@
if (!copy_scalar[i] || entry->scalar[i] == NULL)
E->scalar[i] = NULL;
else {
+ if (_GD_CheckCodeAffixes(D, NULL, entry->scalar[i],
+ entry->fragment_index))
+ {
+ break;
+ }
E->scalar[i] = _GD_Strdup(D, entry->scalar[i]);
E->scalar_ind[i] = entry->scalar_ind[i];
}
@@ -1195,7 +1271,7 @@
/* add a MPLEX entry */
int gd_add_mplex(DIRFILE *D, const char *field_code, const char *in_field,
const char *count_field, int count_val, int count_max, int fragment_index)
-gd_nothrow
+ gd_nothrow
{
gd_entry_t E;
int error;
@@ -1337,7 +1413,7 @@
/* add a META LINCOM entry */
int gd_madd_lincom(DIRFILE* D, const char* parent, const char* field_code,
int n_fields, const char** in_fields, const double* m, const double* b)
-gd_nothrow
+ gd_nothrow
{
int i, error;
gd_entry_t L;
@@ -1792,7 +1868,7 @@
/* add a META MPLEX entry */
int gd_madd_mplex(DIRFILE *D, const char *parent, const char *field_code,
const char *in_field, const char *count_field, int count_val, int count_max)
-gd_nothrow
+ gd_nothrow
{
int error;
gd_entry_t E;
@@ -1919,9 +1995,9 @@
{
unsigned u;
int offset;
- char *munged_code;
+ char *munged_code = NULL;
void *ptr;
- gd_entry_t *E, *P = NULL;
+ gd_entry_t *E = NULL, *P = NULL;
dtrace("%p, \"%s\", \"%s\", \"%s\", %i", D, parent, field_code, target,
fragment_index);
@@ -1948,16 +2024,14 @@
P = _GD_FindField(D, parent, D->entry, D->n_entries, 1, NULL);
if (P == NULL) {
_GD_SetError(D, GD_E_BAD_CODE, GD_E_CODE_MISSING, NULL, 0, parent);
- dreturn("%i", -1);
- return -1;
+ goto add_alias_error;
}
fragment_index = P->fragment_index;
/* make sure it's not a meta field already */
if (P->e->n_meta == -1) {
_GD_SetError(D, GD_E_BAD_CODE, GD_E_CODE_INVALID, NULL, 0, parent);
- dreturn("%i", -1);
- return -1;
+ goto add_alias_error;
}
offset = strlen(parent) + 1;
@@ -1968,15 +2042,12 @@
strcpy(munged_code + offset, field_code);
}
} else
- /* this will munge the name and take care of detecting Barth-style metafield
- * definitions */
+ /* this will check for affixes and take care of detecting Barth-style
+ * metafield definitions */
P = _GD_FixName(D, &munged_code, field_code, fragment_index, &offset);
- if (D->error) {
- free(munged_code);
- dreturn("%i", -1);
- return -1;
- }
+ if (D->error)
+ goto add_alias_error;
/* check alias name */
if (munged_code && _GD_ValidateField(munged_code + offset, D->standards, 1, 0,
@@ -1985,35 +2056,28 @@
_GD_SetError(D, GD_E_BAD_CODE, GD_E_CODE_INVALID, NULL, 0, field_code);
} else if (_GD_FindField(D, munged_code, D->entry, D->n_entries, 1, &u))
_GD_SetError(D, GD_E_DUPLICATE, 0, NULL, 0, munged_code);
+ else
+ _GD_CheckCodeAffixes(D, NULL, target, fragment_index); /* check target */
- if (D->error) {
- free(munged_code);
- dreturn("%i", -1);
- return -1;
- }
+ if (D->error)
+ goto add_alias_error;
ptr = _GD_Realloc(D, D->entry, (D->n_entries + 1) * sizeof(gd_entry_t*));
- if (ptr == NULL) {
- free(munged_code);
- dreturn("%i", -1);
- return -1;
- }
+ if (ptr == NULL)
+ goto add_alias_error;
D->entry = (gd_entry_t **)ptr;
/* create and store */
E = (gd_entry_t *)_GD_Malloc(D, sizeof(gd_entry_t));
- if (E == NULL) {
- dreturn("%i", -1);
- return -1;
- }
+ if (E == NULL)
+ goto add_alias_error;
+
memset(E, 0, sizeof(gd_entry_t));
E->e = (struct _gd_private_entry *)_GD_Malloc(D,
sizeof(struct _gd_private_entry));
- if (E->e == NULL) {
- free(E);
- dreturn("%i", -1);
- return -1;
- }
+ if (E->e == NULL)
+ goto add_alias_error;
+
memset(E->e, 0, sizeof(struct _gd_private_entry));
E->field = munged_code;
@@ -2023,6 +2087,7 @@
E->e->calculated = 1;
if (D->error) {
+ _GD_FreeE(D, E, 1);
dreturn("%i", -1);
return -1;
}
@@ -2042,12 +2107,17 @@
D->entry_list_validity = 0;
}
-
/* Update aliases */
_GD_UpdateAliases(D, 0);
dreturn("%i", 0);
return 0;
+
+add_alias_error:
+ free(E);
+ free(munged_code);
+ dreturn("%i", -1);
+ return -1;
}
int gd_add_alias(DIRFILE *D, const char *alias_name, const char *target_code,
@@ -2078,6 +2148,8 @@
dtrace("%p, \"%s\", \"%s\", \"%s\"", D, parent, alias_name, target_code);
+ _GD_ClearError(D);
+
ret = _GD_AddAlias(D, parent, alias_name, target_code, 0);
dreturn("%i", ret);
Modified: trunk/getdata/src/common.c
===================================================================
--- trunk/getdata/src/common.c 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/src/common.c 2012-07-26 00:17:51 UTC (rev 749)
@@ -854,28 +854,21 @@
/* Ensure that an input field has been identified (with error checking) */
int _GD_BadInput(DIRFILE *D, const gd_entry_t *E, int i, int err)
{
- char *code, *munged_code;
- int offset;
+ char *code;
dtrace("%p, %p, %i, %i", D, E, i, err);
if (E->e->entry[i] == NULL) {
- munged_code = _GD_MungeFromFrag(D, NULL, E->fragment_index, E->in_fields[i],
- &offset);
- if (munged_code)
- E->e->entry[i] = _GD_FindFieldAndRepr(D, munged_code, &code,
- &E->e->repr[i], NULL, 1, err);
+ E->e->entry[i] = _GD_FindFieldAndRepr(D, E->in_fields[i], &code,
+ &E->e->repr[i], NULL, 1, err);
if (E->e->entry[i] == NULL) {
- free(munged_code);
dreturn("%i", 1);
return 1;
}
- if (code != munged_code)
+ if (code != E->in_fields[i])
free(code);
-
- free(munged_code);
}
/* scalar entries not allowed */
Modified: trunk/getdata/src/entry.c
===================================================================
--- trunk/getdata/src/entry.c 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/src/entry.c 2012-07-26 00:17:51 UTC (rev 749)
@@ -145,21 +145,17 @@
{
void *ptr = NULL;
gd_entry_t* C = NULL;
- int repr, offset;
- char* field_code, *munged_code;
+ int repr;
+ char* field_code;
const char* scalar = E->scalar[i];
int index = E->scalar_ind[i];
dtrace("%p, %p, %i, %i, %p, %i", D, E, i, type, data, err);
if (scalar != NULL) {
- munged_code = _GD_MungeFromFrag(D, NULL, E->fragment_index, scalar,
- &offset);
- if (munged_code)
- C = _GD_FindFieldAndRepr(D, munged_code, &field_code, &repr, NULL, 0, 1);
+ C = _GD_FindFieldAndRepr(D, scalar, &field_code, &repr, NULL, 0, 1);
if (D->error) {
- free(munged_code);
dreturnvoid();
return;
}
@@ -194,10 +190,8 @@
}
}
- if (field_code != munged_code)
+ if (field_code != scalar)
free(field_code);
-
- free(munged_code);
}
dreturnvoid();
Modified: trunk/getdata/src/flush.c
===================================================================
--- trunk/getdata/src/flush.c 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/src/flush.c 2012-07-26 00:17:51 UTC (rev 749)
@@ -268,25 +268,43 @@
return len;
}
-static void _GD_PadField(DIRFILE *D, FILE* stream, const char *prefix,
- const char *suffix, const char* in, size_t len, int permissive,
- int standards)
+/* write a field code, taking care of stripping off affixes; returns the length
+ * written */
+static size_t _GD_WriteFieldCode(DIRFILE *D, FILE *stream, int me,
+ const char *code, int permissive, int standards)
{
- size_t i;
int dummy;
+ size_t len;
char *ptr;
- dtrace("%p, %p, \"%s\", \"%s\", \"%s\", %" PRNsize_t ", %i, %i", D, stream,
- prefix, suffix, in, len, permissive, standards);
+ dtrace("%p, %p, %i, \"%s\", %i, %i", D, stream, me, code, permissive,
+ standards);
- ptr = _GD_MungeCode(D, NULL, prefix, suffix, NULL, NULL, in, &dummy);
+ ptr = _GD_MungeCode(D, NULL, D->fragment[me].prefix, D->fragment[me].suffix,
+ NULL, NULL, code, &dummy, 0);
- for (i = _GD_StringEscapeise(stream, ptr, 0, permissive, standards); i < len;
- ++i)
+ len = _GD_StringEscapeise(stream, ptr, 0, permissive, standards);
+
+ free(ptr);
+
+ dreturn("%" PRNsize_t, len);
+ return len;
+}
+
+/* write a field, padding to the specified length */
+static void _GD_PadField(DIRFILE *D, FILE *stream, int me, const char *in,
+ size_t len, int permissive, int standards)
+{
+ size_t i;
+
+ dtrace("%p, %p, %i, \"%s\", %" PRNsize_t ", %i, %i", D, stream, me, in, len,
+ permissive, standards);
+
+ for (i = _GD_WriteFieldCode(D, stream, me, in, permissive, standards);
+ i < len; ++i)
{
fputc(' ', stream);
}
- free(ptr);
dreturnvoid();
}
@@ -296,19 +314,15 @@
int type, const void* value, const char* scalar, int index,
const char* postamble)
{
- int dummy;
dtrace("%p, %p, %i, %i, 0x%X, %p, \"%s\", %i, \"%s\"", D, stream, me,
permissive, type, value, scalar, index, postamble);
if (scalar != NULL) {
- char *ptr = _GD_MungeCode(D, NULL, D->fragment[me].prefix,
- D->fragment[me].suffix, NULL, NULL, scalar, &dummy);
- _GD_StringEscapeise(stream, ptr, 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, scalar, permissive, D->standards);
if (index == -1)
fprintf(stream, "%s", postamble);
else
fprintf(stream, "<%i>%s", index, postamble);
- free(ptr);
}
else if (type == GD_UINT64)
fprintf(stream, "%" PRIu64 "%s", *(uint64_t *)value, postamble);
@@ -353,11 +367,9 @@
/* aliases */
if (E->field_type == GD_ALIAS_ENTRY) {
fputs("/ALIAS ", stream);
- _GD_PadField(D, stream, D->fragment[me].prefix, D->fragment[me].suffix,
- E->field, 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->field, permissive, D->standards);
fputc(' ', stream);
- _GD_PadField(D, stream, D->fragment[me].prefix, D->fragment[me].suffix,
- E->e->entry[1] ? E->e->entry[1]->field : E->in_fields[0], 0, permissive,
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive,
D->standards);
fputc('\n', stream);
dreturnvoid();
@@ -375,8 +387,7 @@
}
/* field name */
- _GD_PadField(D, stream, D->fragment[me].prefix, D->fragment[me].suffix, ptr,
- max_len, permissive, D->standards);
+ _GD_PadField(D, stream, me, ptr, max_len, permissive, D->standards);
switch(E->field_type) {
case GD_RAW_ENTRY:
@@ -391,7 +402,7 @@
E->EN(lincom,n_fields));
for (i = 0; i < E->EN(lincom,n_fields); ++i) {
fputc(' ', stream);
- _GD_StringEscapeise(stream, E->in_fields[i], 0, permissive,
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[i], permissive,
D->standards);
fputc(' ', stream);
if (E->comp_scal) {
@@ -412,7 +423,8 @@
break;
case GD_LINTERP_ENTRY:
fprintf(stream, " LINTERP%s ", pretty ? " " : "");
- _GD_StringEscapeise(stream, E->in_fields[0], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive,
+ D->standards);
fputc(' ', stream);
_GD_StringEscapeise(stream, E->EN(linterp,table), 0, permissive,
D->standards);
@@ -420,7 +432,8 @@
break;
case GD_BIT_ENTRY:
fprintf(stream, " BIT%s ", pretty ? " " : "");
- _GD_StringEscapeise(stream, E->in_fields[0], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive,
+ D->standards);
fputc(' ', stream);
_GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, &E->EN(bit,bitnum),
E->scalar[0], E->scalar_ind[0], " ");
@@ -429,35 +442,42 @@
break;
case GD_DIVIDE_ENTRY:
fprintf(stream, " DIVIDE%s ", pretty ? " " : "");
- _GD_StringEscapeise(stream, E->in_fields[0], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive,
+ D->standards);
fputc(' ', stream);
- _GD_StringEscapeise(stream, E->in_fields[1], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive,
+ D->standards);
fputc('\n', stream);
break;
case GD_RECIP_ENTRY:
fprintf(stream, " RECIP%s ", pretty ? " " : "");
- _GD_StringEscapeise(stream, E->in_fields[0], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive,
+ D->standards);
fputc(' ', stream);
_GD_WriteConst(D, stream, me, permissive, GD_COMPLEX128,
&E->EN(recip,cdividend), E->scalar[0], E->scalar_ind[0], "\n");
break;
case GD_MULTIPLY_ENTRY:
fputs(" MULTIPLY ", stream);
- _GD_StringEscapeise(stream, E->in_fields[0], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive,
+ D->standards);
fputc(' ', stream);
- _GD_StringEscapeise(stream, E->in_fields[1], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive,
+ D->standards);
fputc('\n', stream);
break;
case GD_PHASE_ENTRY:
fprintf(stream, " PHASE%s ", pretty ? " " : "");
- _GD_StringEscapeise(stream, E->in_fields[0], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive,
+ D->standards);
fputc(' ', stream);
_GD_WriteConst(D, stream, me, permissive, GD_INT64, &E->EN(phase,shift),
E->scalar[0], E->scalar_ind[0], "\n");
break;
case GD_POLYNOM_ENTRY:
fprintf(stream, " POLYNOM%s ", pretty ? " " : "");
- _GD_StringEscapeise(stream, E->in_fields[0], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive,
+ D->standards);
fputc(' ', stream);
for (i = 0; i <= E->EN(polynom,poly_ord); ++i)
if (E->comp_scal)
@@ -471,7 +491,8 @@
break;
case GD_SBIT_ENTRY:
fprintf(stream, " SBIT%s ", pretty ? " " : "");
- _GD_StringEscapeise(stream, E->in_fields[0], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive,
+ D->standards);
fputc(' ', stream);
_GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE, &E->EN(bit,bitnum),
E->scalar[0], E->scalar_ind[0], " ");
@@ -480,9 +501,11 @@
break;
case GD_WINDOW_ENTRY:
fprintf(stream, " WINDOW%s ", pretty ? " " : "");
- _GD_StringEscapeise(stream, E->in_fields[0], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive,
+ D->standards);
fputc(' ', stream);
- _GD_StringEscapeise(stream, E->in_fields[1], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive,
+ D->standards);
fprintf(stream, " %s ", _GD_WindopName(D, E->EN(window,windop)));
switch (E->EN(window,windop)) {
case GD_WINDOP_EQ:
@@ -503,9 +526,11 @@
break;
case GD_MPLEX_ENTRY:
fprintf(stream, " MPLEX%s ", pretty ? " " : "");
- _GD_StringEscapeise(stream, E->in_fields[0], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[0], permissive,
+ D->standards);
fputc(' ', stream);
- _GD_StringEscapeise(stream, E->in_fields[1], 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->in_fields[1], permissive,
+ D->standards);
fputc(' ', stream);
_GD_WriteConst(D, stream, me, permissive, GD_INT_TYPE,
&E->EN(mplex,count_val), E->scalar[0], E->scalar_ind[0], "");
@@ -561,8 +586,7 @@
if (!D->error && E->hidden && (permissive || D->standards >= 9)) {
fputs("/HIDDEN ", stream);
- _GD_PadField(D, stream, D->fragment[me].prefix, D->fragment[me].suffix,
- E->field, 0, permissive, D->standards);
+ _GD_WriteFieldCode(D, stream, me, E->field, permissive, D->standards);
fputc('\n', stream);
}
@@ -730,9 +754,9 @@
for (j = 0; j < D->n_fragment; ++j)
if (D->fragment[j].parent == i) {
char *prefix = _GD_MungeCode(D, NULL, D->fragment[i].prefix, NULL, NULL,
- NULL, D->fragment[j].prefix, &dummy);
+ NULL, D->fragment[j].prefix, &dummy, 0);
char *suffix = _GD_MungeCode(D, NULL, NULL, D->fragment[i].suffix, NULL,
- NULL, D->fragment[j].suffix, &dummy);
+ NULL, D->fragment[j].suffix, &dummy, 0);
fprintf(stream, "%sINCLUDE ", (D->standards >= 5) ? "/" : "");
_GD_StringEscapeise(stream, D->fragment[j].ename, 0, permissive,
Modified: trunk/getdata/src/fragment.c
===================================================================
--- trunk/getdata/src/fragment.c 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/src/fragment.c 2012-07-26 00:17:51 UTC (rev 749)
@@ -110,9 +110,9 @@
for (j = 0; j < D->n_fragment; ++j)
if (D->fragment[j].parent == i) {
char *subprefix = _GD_MungeCode(D, NULL, D->fragment[i].prefix, NULL,
- prefix, NULL, D->fragment[j].prefix, &dummy);
+ prefix, NULL, D->fragment[j].prefix, &dummy, 1);
char *subsuffix = _GD_MungeCode(D, NULL, NULL, D->fragment[i].suffix,
- NULL, suffix, D->fragment[j].suffix, &dummy);
+ NULL, suffix, D->fragment[j].suffix, &dummy, 1);
if (D->error) {
free(subprefix);
dreturn("%p (%i)", new_codes, *n);
@@ -138,7 +138,8 @@
new_codes = ptr;
/* remunge the code */
new_codes[nn - 1] = _GD_MungeCode(D, NULL, D->fragment[i].prefix,
- D->fragment[i].suffix, prefix, suffix, D->entry[u]->field, &dummy);
+ D->fragment[i].suffix, prefix, suffix, D->entry[u]->field, &dummy,
+ 0);
/* look for a duplicate and validate */
if (new_codes[nn - 1] && _GD_FindField(D, new_codes[nn - 1], D->entry,
Modified: trunk/getdata/src/internal.h
===================================================================
--- trunk/getdata/src/internal.h 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/src/internal.h 2012-07-26 00:17:51 UTC (rev 749)
@@ -1027,6 +1027,8 @@
char *_GD_CanonicalPath(const char *restrict, const char *restrict);
gd_entry_t *_GD_CheckParent(DIRFILE *restrict D, char **restrict name, int me,
int linenum);
+int _GD_CheckCodeAffixes(DIRFILE *D, const gd_entry_t *P,
+ const char *field_code, int fragment);
void _GD_CInvertData(DIRFILE *restrict, void *restrict, gd_type_t return_type,
GD_DCOMPLEXA(dividend), size_t);
@@ -1101,7 +1103,7 @@
unsigned long int, off64_t, int, int, char *restrict);
char *_GD_MungeCode(DIRFILE *restrict, const gd_entry_t *restrict,
const char *restrict, const char *restrict, const char *restrict,
- const char *restrict, const char *restrict, int *restrict);
+ const char *restrict, const char *restrict, int *restrict, int);
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);
Modified: trunk/getdata/src/mod.c
===================================================================
--- trunk/getdata/src/mod.c 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/src/mod.c 2012-07-26 00:17:51 UTC (rev 749)
@@ -39,13 +39,13 @@
*/
static int _GD_AlterScalar(DIRFILE* D, int alter_literal, gd_type_t type,
void *lout, const void *lin, char **sout, int *iout, const char *sin,
- int iin, int calculated)
+ int iin, int calculated, int fragment_index)
{
int r = 0;
int set_lout = 0;
- dtrace("%p, %i, 0x%X, %p, %p, %p, %p, %p, %i, %i", D, alter_literal, type,
- lout, lin, sout, iout, sin, iin, calculated);
+ dtrace("%p, %i, 0x%X, %p, %p, %p, %p, %p, %i, %i, %i", D, alter_literal, type,
+ lout, lin, sout, iout, sin, iin, calculated, fragment_index);
if (sin == NULL) {
if (*sout != NULL) {
@@ -79,9 +79,11 @@
/* 2: set a new CONST field from sout; if this is a RAW field, and we've
* been asked to move the raw file, _GD_Change is going to need to
* recalculate the entry; no need to change lout: it's ignored. */
- r = GD_AS_FREE_SCALAR | GD_AS_NEED_RECALC | GD_AS_MODIFIED;
- *sout = _GD_Strdup(D, sin);
- *iout = iin;
+ if (!_GD_CheckCodeAffixes(D, NULL, sin, fragment_index)) {
+ r = GD_AS_FREE_SCALAR | GD_AS_NEED_RECALC | GD_AS_MODIFIED;
+ *sout = _GD_Strdup(D, sin);
+ *iout = iin;
+ }
}
if (!D->error && set_lout) {
@@ -187,6 +189,29 @@
dreturnvoid();
}
+/* returns -1 on error, 1 if modified, 0 if no change */
+static int _GD_AlterInField(DIRFILE *D, int i, char **Q, char *const *N,
+ char *const *E, int fragment_index, int force)
+{
+ dtrace("%p, %i, %p, %p, %p, %i, %i", D, i, Q, N, E, fragment_index, force);
+
+ if (force || (N[i] != NULL && strcmp(E[i], N[i]))) {
+ if (_GD_CheckCodeAffixes(D, NULL, N[i], fragment_index)) {
+ dreturn("%i", -1);
+ return -1;
+ } else if ((Q[i] = _GD_Strdup(D, N[i])) == NULL) {
+ dreturn("%i", -1);
+ return -1;
+ }
+
+ dreturn("%i", 1);
+ return 1;
+ }
+
+ dreturn("%i", 0);
+ return 0;
+}
+
/* N is the new entry, supplied by the user
* E is the old entry, stored in the database
* Q is our workspace; in the end, Q is a sanitised N which replaces E */
@@ -233,7 +258,7 @@
case GD_RAW_ENTRY:
j = _GD_AlterScalar(D, N->EN(raw,spf) && N->EN(raw,spf) != E->EN(raw,spf),
GD_UINT16, &Q.EN(raw,spf), &N->EN(raw,spf), Q.scalar, Q.scalar_ind,
- N->scalar[0], N->scalar_ind[0], E->e->calculated);
+ N->scalar[0], N->scalar_ind[0], E->e->calculated, E->fragment_index);
if (j & GD_AS_ERROR)
break;
@@ -406,29 +431,30 @@
Q.comp_scal = 0;
for (i = 0; i < Q.EN(lincom,n_fields); ++i) {
- if (flags & 0x1)
- if (E->EN(lincom,n_fields) <= i || (N->in_fields[i] != NULL &&
- strcmp(E->in_fields[i], N->in_fields[i])))
- {
- if ((Q.in_fields[i] = _GD_Strdup(D, N->in_fields[i])) == NULL)
- break;
-
+ if (flags & 0x1) {
+ j = _GD_AlterInField(D, i, Q.in_fields, N->in_fields, E->in_fields,
+ E->fragment_index, E->EN(lincom,n_fields) <= i);
+ if (j < 0)
+ break;
+ else if (j) {
modified = 1;
field_free |= 1 << i;
}
+ }
if (flags & 0x2) {
if (N->comp_scal) {
j = _GD_AlterScalar(D, !_gd_ccmpc(E->EN(lincom,cm)[i],
N->EN(lincom,cm)[i]), GD_COMPLEX128, Q.EN(lincom,cm) + i,
N->EN(lincom,cm) + i, Q.scalar + i, Q.scalar_ind + i,
- N->scalar[i], N->scalar_ind[i], E->e->calculated);
+ N->scalar[i], N->scalar_ind[i], E->e->calculated,
+ E->fragment_index);
Q.EN(lincom,m)[i] = creal(Q.EN(lincom,cm)[i]);
} else {
j = _GD_AlterScalar(D, E->EN(lincom,m)[i] != N->EN(lincom,m)[i],
GD_FLOAT64, Q.EN(lincom,m) + i, N->EN(lincom,m) + i,
Q.scalar + i, Q.scalar_ind + i, N->scalar[i], N->scalar_ind[i],
- E->e->calculated);
+ E->e->calculated, E->fragment_index);
_gd_r2c(Q.EN(lincom,cm)[i], Q.EN(lincom,m)[i]);
}
@@ -448,14 +474,15 @@
N->EN(lincom,cb)[i]), GD_COMPLEX128, Q.EN(lincom,cb) + i,
N->EN(lincom,cb) + i, Q.scalar + i + GD_MAX_LINCOM,
Q.scalar_ind + i + GD_MAX_LINCOM, N->scalar[i + GD_MAX_LINCOM],
- N->scalar_ind[i + GD_MAX_LINCOM], E->e->calculated);
+ N->scalar_ind[i + GD_MAX_LINCOM], E->e->calculated,
+ E->fragment_index);
Q.EN(lincom,b)[i] = creal(Q.EN(lincom,cb)[i]);
} else {
j = _GD_AlterScalar(D, E->EN(lincom,b)[i] != N->EN(lincom,b)[i],
GD_FLOAT64, Q.EN(lincom,b) + i, N->EN(lincom,b) + i,
Q.scalar + i + GD_MAX_LINCOM, Q.scalar_ind + i + GD_MAX_LINCOM,
N->scalar[i + GD_MAX_LINCOM], N->scalar_ind[i + GD_MAX_LINCOM],
- E->e->calculated);
+ E->e->calculated, E->fragment_index);
_gd_r2c(Q.EN(lincom,cb)[i], Q.EN(lincom,b)[i]);
}
@@ -477,10 +504,11 @@
modified = 1;
break;
case GD_LINTERP_ENTRY:
- if (N->in_fields[0] != NULL && strcmp(E->in_fields[0], N->in_fields[0])) {
- if ((Q.in_fields[0] = _GD_Strdup(D, N->in_fields[0])) == NULL)
- break;
-
+ j = _GD_AlterInField(D, 0, Q.in_fields, N->in_fields, E->in_fields,
+ E->fragment_index, 0);
+ if (j < 0)
+ break;
+ else if (j) {
modified = 1;
field_free = 1;
}
@@ -524,7 +552,7 @@
j = _GD_AlterScalar(D, N->EN(bit,numbits) >= 1 && E->EN(bit,numbits) !=
N->EN(bit,numbits), GD_INT_TYPE, &Q.EN(bit,numbits),
&N->EN(bit,numbits), Q.scalar + 1, Q.scalar_ind + 1, N->scalar[1],
- N->scalar_ind[1], E->e->calculated);
+ N->scalar_ind[1], E->e->calculated, E->fragment_index);
if (j & GD_AS_ERROR)
break;
@@ -538,7 +566,7 @@
j = _GD_AlterScalar(D, N->EN(bit,bitnum) >= 0 && E->EN(bit,bitnum) !=
N->EN(bit,bitnum), GD_INT_TYPE, &Q.EN(bit,bitnum), &N->EN(bit,bitnum),
Q.scalar, Q.scalar_ind, N->scalar[0], N->scalar_ind[0],
- E->e->calculated);
+ E->e->calculated, E->fragment_index);
if (j & GD_AS_ERROR)
break;
@@ -549,10 +577,11 @@
if (j & GD_AS_MODIFIED)
modified = 1;
- if (N->in_fields[0] != NULL && strcmp(E->in_fields[0], N->in_fields[0])) {
- if ((Q.in_fields[0] = _GD_Strdup(D, N->in_fields[0])) == NULL)
- break;
-
+ j = _GD_AlterInField(D, 0, Q.in_fields, N->in_fields, E->in_fields,
+ E->fragment_index, 0);
+ if (j < 0)
+ break;
+ else if (j) {
modified = 1;
field_free = 1;
}
@@ -560,28 +589,31 @@
break;
case GD_MULTIPLY_ENTRY:
case GD_DIVIDE_ENTRY:
- if (N->in_fields[0] != NULL && strcmp(E->in_fields[0], N->in_fields[0])) {
- if ((Q.in_fields[0] = _GD_Strdup(D, N->in_fields[0])) == NULL)
- break;
-
+ j = _GD_AlterInField(D, 0, Q.in_fields, N->in_fields, E->in_fields,
+ E->fragment_index, 0);
+ if (j < 0)
+ break;
+ else if (j) {
modified = 1;
field_free = 1;
}
- if (N->in_fields[1] != NULL && strcmp(E->in_fields[1], N->in_fields[1])) {
- if ((Q.in_fields[1] = _GD_Strdup(D, N->in_fields[1])) == NULL)
- break;
-
+ j = _GD_AlterInField(D, 1, Q.in_fields, N->in_fields, E->in_fields,
+ E->fragment_index, 0);
+ if (j < 0)
+ break;
+ else if (j) {
modified = 1;
field_free |= 2;
}
break;
case GD_RECIP_ENTRY:
- if (N->in_fields[0] != NULL && strcmp(E->in_fields[0], N->in_fields[0])) {
- if ((Q.in_fields[0] = _GD_Strdup(D, N->in_fields[0])) == NULL)
- break;
-
+ j = _GD_AlterInField(D, 0, Q.in_fields, N->in_fields, E->in_fields,
+ E->fragment_index, 0);
+ if (j < 0)
+ break;
+ else if (j) {
modified = 1;
field_free = 1;
}
@@ -589,10 +621,10 @@
Q.comp_scal = 0;
if (N->comp_scal) {
j = _GD_AlterScalar(D, cabs(N->EN(recip,cdividend)) != 0 &&
- !_gd_ccmpc(E->EN(recip,cdividend), N->EN(recip,cdividend)),
- GD_COMPLEX128, &Q.EN(recip,cdividend), &(N->EN(recip,cdividend)),
- Q.scalar, Q.scalar_ind, N->scalar[0], N->scalar_ind[0],
- E->e->calculated);
+ !_gd_ccmpc(E->EN(recip,cdividend), N->EN(recip,cdividend)),
+ GD_COMPLEX128, &Q.EN(recip,cdividend), &(N->EN(recip,cdividend)),
+ Q.scalar, Q.scalar_ind, N->scalar[0], N->scalar_ind[0],
+ E->e->calculated, E->fragment_index);
Q.EN(recip,dividend) = creal(Q.EN(recip,cdividend));
if (cimag(Q.EN(recip,cdividend)) != 0)
Q.comp_scal = 1;
@@ -600,7 +632,8 @@
j = _GD_AlterScalar(D, N->EN(recip,dividend) != 0 &&
E->EN(recip,dividend) != N->EN(recip,dividend), GD_FLOAT64,
&Q.EN(recip,dividend), &(N->EN(recip,dividend)), Q.scalar,
- Q.scalar_ind, N->scalar[0], N->scalar_ind[0], E->e->calculated);
+ Q.scalar_ind, N->scalar[0], N->scalar_ind[0], E->e->calculated,
+ E->fragment_index);
_gd_r2c(Q.EN(recip,cdividend), Q.EN(recip,dividend));
}
@@ -620,7 +653,7 @@
case GD_PHASE_ENTRY:
j = _GD_AlterScalar(D, E->EN(phase,shift) != N->EN(phase,shift), GD_INT64,
&Q.EN(phase,shift), &N->EN(phase,shift), Q.scalar, Q.scalar_ind,
- N->scalar[0], N->scalar_ind[0], E->e->calculated);
+ N->scalar[0], N->scalar_ind[0], E->e->calculated, E->fragment_index);
if (j & GD_AS_ERROR)
break;
@@ -631,20 +664,22 @@
if (j & GD_AS_MODIFIED)
modified = 1;
- if (N->in_fields[0] != NULL && strcmp(E->in_fields[0], N->in_fields[0])) {
- if ((Q.in_fields[0] = _GD_Strdup(D, N->in_fields[0])) == NULL)
- break;
-
+ j = _GD_AlterInField(D, 0, Q.in_fields, N->in_fields, E->in_fields,
+ E->fragment_index, 0);
+ if (j < 0)
+ break;
+ else if (j) {
modified = 1;
field_free = 1;
}
break;
case GD_POLYNOM_ENTRY:
- if (N->in_fields[0] != NULL && strcmp(E->in_fields[0], N->in_fields[0])) {
- if ((Q.in_fields[0] = _GD_Strdup(D, N->in_fields[0])) == NULL)
- break;
-
+ j = _GD_AlterInField(D, 0, Q.in_fields, N->in_fields, E->in_fields,
+ E->fragment_index, 0);
+ if (j < 0)
+ break;
+ else if (j) {
modified = 1;
field_free = 1;
}
@@ -662,13 +697,14 @@
j = _GD_AlterScalar(D, !_gd_ccmpc(E->EN(polynom,ca)[i],
N->EN(polynom,ca)[i]), GD_COMPLEX128, Q.EN(polynom,ca) + i,
N->EN(polynom,ca) + i, Q.scalar + i, Q.scalar_ind + i,
- N->scalar[i], N->scalar_ind[i], E->e->calculated);
+ N->scalar[i], N->scalar_ind[i], E->e->calculated,
+ E->fragment_index);
Q.EN(polynom,a)[i] = creal(Q.EN(polynom,ca)[i]);
} else {
j = _GD_AlterScalar(D, E->EN(polynom,a)[i] != N->EN(polynom,a)[i],
GD_FLOAT64, Q.EN(polynom,a) + i, N->EN(polynom,a) + i,
Q.scalar + i, Q.scalar_ind + i, N->scalar[i], N->scalar_ind[i],
- E->e->calculated);
+ E->e->calculated, E->fragment_index);
_gd_r2c(Q.EN(polynom,ca)[i], Q.EN(polynom,a)[i]);
}
@@ -703,20 +739,20 @@
j = _GD_AlterScalar(D, E->EN(window,threshold.i) !=
N->EN(window,threshold.i), GD_INT64, &Q.EN(window,threshold.i),
&N->EN(window,threshold.i), Q.scalar, Q.scalar_ind, N->scalar[0],
- N->scalar_ind[0], E->e->calculated);
+ N->scalar_ind[0], E->e->calculated, E->fragment_index);
break;
case GD_WINDOP_SET:
case GD_WINDOP_CLR:
j = _GD_AlterScalar(D, E->EN(window,threshold.u) !=
N->EN(window,threshold.u), GD_UINT64, &Q.EN(window,threshold.u),
&N->EN(window,threshold.u), Q.scalar, Q.scalar_ind, N->scalar[0],
- N->scalar_ind[0], E->e->calculated);
+ N->scalar_ind[0], E->e->calculated, E->fragment_index);
break;
default:
j = _GD_AlterScalar(D, E->EN(window,threshold.r) !=
N->EN(window,threshold.r), GD_FLOAT64, &Q.EN(window,threshold.r),
&N->EN(window,threshold.r), Q.scalar, Q.scalar_ind, N->scalar[0],
- N->scalar_ind[0], E->e->calculated);
+ N->scalar_ind[0], E->e->calculated, E->fragment_index);
break;
}
@@ -729,18 +765,20 @@
if (j & GD_AS_MODIFIED)
modified = 1;
- if (N->in_fields[0] != NULL && strcmp(E->in_fields[0], N->in_fields[0])) {
- if ((Q.in_fields[0] = _GD_Strdup(D, N->in_fields[0])) == NULL)
- break;
-
+ j = _GD_AlterInField(D, 0, Q.in_fields, N->in_fields, E->in_fields,
+ E->fragment_index, 0);
+ if (j < 0)
+ break;
+ else if (j) {
modified = 1;
field_free |= 1;
}
- if (N->in_fields[1] != NULL && strcmp(E->in_fields[1], N->in_fields[1])) {
- if ((Q.in_fields[1] = _GD_Strdup(D, N->in_fields[1])) == NULL)
- break;
-
+ j = _GD_AlterInField(D, 1, Q.in_fields, N->in_fields, E->in_fields,
+ E->fragment_index, 0);
+ if (j < 0)
+ break;
+ else if (j) {
modified = 1;
field_free |= 2;
}
@@ -750,7 +788,8 @@
j = _GD_AlterScalar(D, N->EN(mplex,count_max) != -1 &&
E->EN(mplex,count_max) != N->EN(mplex,count_max), GD_INT_TYPE,
&Q.EN(mplex,count_max), &N->EN(mplex,count_max), Q.scalar,
- Q.scalar_ind, N->scalar[0], N->scalar_ind[0], E->e->calculated);
+ Q.scalar_ind, N->scalar[0], N->scalar_ind[0], E->e->calculated,
+ E->fragment_index);
if (j & GD_AS_ERROR)
break;
@@ -764,7 +803,8 @@
j = _GD_AlterScalar(D, N->EN(mplex,count_val) != -1 &&
E->EN(mplex,count_val) != N->EN(mplex,count_val), GD_INT_TYPE,
&Q.EN(mplex,count_val), &N->EN(mplex,count_val), Q.scalar,
- Q.scalar_ind, N->scalar[1], N->scalar_ind[1], E->e->calculated);
+ Q.scalar_ind, N->scalar[1], N->scalar_ind[1], E->e->calculated,
+ E->fragment_index);
if (j & GD_AS_ERROR)
break;
@@ -775,18 +815,20 @@
if (j & GD_AS_MODIFIED)
modified = 1;
- if (N->in_fields[0] != NULL && strcmp(E->in_fields[0], N->in_fields[0])) {
- if ((Q.in_fields[0] = _GD_Strdup(D, N->in_fields[0])) == NULL)
- break;
-
+ j = _GD_AlterInField(D, 0, Q.in_fields, N->in_fields, E->in_fields,
+ E->fragment_index, 0);
+ if (j < 0)
+ break;
+ else if (j) {
modified = 1;
field_free |= 1;
}
- if (N->in_fields[1] != NULL && strcmp(E->in_fields[1], N->in_fields[1])) {
- if ((Q.in_fields[1] = _GD_Strdup(D, N->in_fields[1])) == NULL)
- break;
-
+ j = _GD_AlterInField(D, 1, Q.in_fields, N->in_fields, E->in_fields,
+ E->fragment_index, 0);
+ if (j < 0)
+ break;
+ else if (j) {
modified = 1;
field_free |= 2;
}
@@ -945,6 +987,8 @@
return -1;
}
+ _GD_ClearError(D);
+
/* To ensure .e is NULLed */
memcpy(&N, entry, sizeof(gd_entry_t));
N.e = NULL;
@@ -1553,7 +1597,7 @@
int gd_alter_window(DIRFILE* D, const char *field_code, const char *in_field,
const char *check_field, gd_windop_t windop, gd_triplet_t threshold)
-gd_nothrow
+ gd_nothrow
{
int ret;
gd_entry_t N;
@@ -1585,7 +1629,7 @@
int gd_alter_mplex(DIRFILE* D, const char *field_code, const char *in_field,
const char *count_field, int count_val, int count_max)
-gd_nothrow
+ gd_nothrow
{
int ret;
gd_entry_t N;
Modified: trunk/getdata/src/move.c
===================================================================
--- trunk/getdata/src/move.c 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/src/move.c 2012-07-26 00:17:51 UTC (rev 749)
@@ -339,7 +339,7 @@
/* Compose the field's new name */
new_filebase = _GD_MungeCode(D, NULL, D->fragment[E->fragment_index].prefix,
- D->fragment[E->fragment_index].suffix, NULL, NULL, E->field, &dummy);
+ D->fragment[E->fragment_index].suffix, NULL, NULL, E->field, &dummy, 0);
if (!new_filebase) {
_GD_InternalError(D); /* the prefix/suffix wasn't found */
Modified: trunk/getdata/src/name.c
===================================================================
--- trunk/getdata/src/name.c 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/src/name.c 2012-07-26 00:17:51 UTC (rev 749)
@@ -23,14 +23,14 @@
/* add/remove/modify the prefix and suffix from a field code */
char *_GD_MungeCode(DIRFILE *D, const gd_entry_t *P, const char *old_prefix,
const char *old_suffix, const char *new_prefix, const char *new_suffix,
- const char *code, int *offset)
+ const char *code, int *offset, int err_ok)
{
size_t len, oplen = 0, oslen = 0, nplen = 0, nslen = 0, plen = 0, mlen = 0;
const char *ptr, *slash;
char *new_code;
- dtrace("%p, %p, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", %p", D, P, old_prefix,
- old_suffix, new_prefix, new_suffix, code, offset);
+ dtrace("%p, %p, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", %p, %i", D, P,
+ old_prefix, old_suffix, new_prefix, new_suffix, code, offset, err_ok);
if (code == NULL) {
dreturn("%p", NULL);
@@ -44,7 +44,10 @@
oplen = strlen(old_prefix);
if (strncmp(old_prefix, code, oplen)) {
/* prefix missing */
- _GD_SetError(D, GD_E_BAD_CODE, GD_E_CODE_INVALID, NULL, 0, code);
+ if (err_ok)
+ _GD_SetError(D, GD_E_BAD_CODE, GD_E_CODE_INVALID, NULL, 0, code);
+ else
+ _GD_InternalError(D);
dreturn("%p", NULL);
return NULL;
}
@@ -67,7 +70,10 @@
oslen = strlen(old_suffix);
if (strncmp(old_suffix, ptr + len - oslen, oslen)) {
/* suffix missing */
- _GD_SetError(D, GD_E_BAD_CODE, GD_E_CODE_INVALID, NULL, 0, code);
+ if (err_ok)
+ _GD_SetError(D, GD_E_BAD_CODE, GD_E_CODE_INVALID, NULL, 0, code);
+ else
+ _GD_InternalError(D);
dreturn("%p", NULL);
return NULL;
}
@@ -117,7 +123,7 @@
return new_code;
}
-/* Munge a field code or field name using the prefix and suffix of the current
+/* Munge a field code or field name using the prefix and suffix of the given
* fragment. Returns a newly malloc'd munged code, or NULL on error */
char *_GD_MungeFromFrag(DIRFILE *D, const gd_entry_t *P, int me,
const char *code, int *offset)
@@ -126,12 +132,32 @@
dtrace("%p, %p, %i, \"%s\", %p", D, P, me, code, offset);
new_code = _GD_MungeCode(D, P, NULL, NULL, D->fragment[me].prefix,
- D->fragment[me].suffix, code, offset);
+ D->fragment[me].suffix, code, offset, 1);
dreturn("\"%s\"", new_code);
return new_code;
}
+/* Return non-zero if the a field codes doesn't contain the correct affixes. */
+int _GD_CheckCodeAffixes(DIRFILE *D, const gd_entry_t *P,
+ const char *field_code, int fragment)
+{
+ int dummy;
+
+ dtrace("%p, %p, \"%s\", %i", D, P, field_code, fragment);
+
+ if (field_code == NULL) {
+ dreturn("%i", 0);
+ return 0;
+ }
+
+ free(_GD_MungeCode(D, P, D->fragment[fragment].prefix,
+ D->fragment[fragment].suffix, NULL, NULL, field_code, &dummy, 1));
+
+ dreturn("%i", D->error);
+ return D->error;
+}
+
/* Check for a valid field name -- returns 1 on error */
int _GD_ValidateField(const char* field_code, int standards, int strict,
int affix, int* is_dot)
@@ -459,7 +485,7 @@
} else {
/* Verify prefix and suffix */
name = _GD_MungeCode(D, NULL, D->fragment[E->fragment_index].prefix,
- D->fragment[E->fragment_index].suffix, NULL, NULL, new_name, &dummy);
+ D->fragment[E->fragment_index].suffix, NULL, NULL, new_name, &dummy, 1);
if (name == NULL || name[0] == '\0') {
_GD_SetError(D, GD_E_BAD_CODE, GD_E_CODE_INVALID, NULL, 0, new_name);
dreturn("%i", -1);
Modified: trunk/getdata/src/parse.c
===================================================================
--- trunk/getdata/src/parse.c 2012-07-21 09:03:26 UTC (rev 748)
+++ trunk/getdata/src/parse.c 2012-07-26 00:17:51 UTC (rev 749)
@@ -113,11 +113,13 @@
/* Returns a newly malloc'd string containing the scalar field name, or NULL on
* numeric literal or error */
static char *_GD_SetScalar(DIRFILE *restrict D, const char *restrict token,
- void *restrict data, int type, const char *restrict format_file, int line,
- int *restrict index, int *restrict comp_scal, int standards, int pedantic)
+ void *restrict data, int type, int me, const char *restrict format_file,
+ int line, int *restrict index, int *restrict comp_scal, int standards,
+ int pedantic)
{
char *ptr = NULL;
char *lt;
+ int dummy;
dtrace("%p, \"%s\", %p, 0x%X, \"%s\", %i, %p, %p, %i, %i", D, token, data,
type, format_file, line, index, comp_scal, standards, pedantic);
@@ -186,7 +188,7 @@
/* there were trailing characters in the long long int */
if (*ptr != '\0') {
- ptr = _GD_Strdup(D, token);
+ ptr = _GD_MungeFromFrag(D, NULL, me, token, &dummy);
if (D->error) {
dreturn("%p", NULL);
return NULL;
@@ -211,7 +213,7 @@
/* there were trailing characters in the unsigned long long int */
if (*ptr != '\0') {
- ptr = _GD_Strdup(D, token);
+ ptr = _GD_MungeFromFrag(D, NULL, me, token, &dummy);
if (D->error) {
dreturn("%p", NULL);
return NULL;
@@ -314,7 +316,7 @@
_GD_SetError(D, GD_E_FORMAT, GD_E_FORMAT_BAD_TYPE, format_file, line,
in_cols[2]);
else if ((E->scalar[0] = _GD_SetScalar(D, in_cols[3], &E->EN(raw,spf),
- GD_UINT16, format_file, line, E->scalar_ind, NULL, standards,
+ GD_UINT16, me, format_file, line, E->scalar_ind, NULL, standards,
pedantic)) == NULL)
{
E->e->calculated = 1;
@@ -407,13 +409,14 @@
_GD_SetError(D, GD_E_FORMAT, GD_E_FORMAT_N_TOK, format_file, line, NULL);
else
for (i = 0; i < E->EN(lincom,n_fields); i++) {
- E->in_fields[i] = _GD_Strdup(D, in_cols[i * 3 + 3]);
+ E->in_fields[i] = _GD_MungeFromFrag(D, NULL, me, in_cols[i * 3 + 3],
+ &offset);
E->scalar[i] = _GD_SetScalar(D, in_cols[i * 3 + 4], &E->EN(lincom,cm)[i],
- GD_COMPLEX128, format_file, line, E->scalar_ind + i, &E->comp_scal,
- standards, pedantic);
+ GD_COMPLEX128, me, format_file, line, E->scalar_ind + i,
+ &E->comp_scal, standards, pedantic);
E->EN(lincom,m)[i] = creal(E->EN(lincom,cm)[i]);
E->scalar[i + GD_MAX_LINCOM] = _GD_SetScalar(D, in_cols[i * 3 + 5],
- &E->EN(lincom,cb)[i], GD_COMPLEX128, format_file, line,
+ &E->EN(lincom,cb)[i], GD_COMPLEX128, me, format_file, line,
E->scalar_ind + i + GD_MAX_LINCOM, &E->comp_scal, standards,
pedantic);
E->EN(lincom,b)[i] = creal(E->EN(lincom,cb)[i]);
@@ -483,7 +486,7 @@
return NULL;
}
- E->in_fields[0] = _GD_Strdup(D, in_cols[2]);
+ E->in_fields[0] = _GD_MungeFromFrag(D, NULL, me, in_cols[2], &offset);
E->e->u.linterp.table_len = -1; /* linterp file not read yet */
E->EN(linterp,table) = _GD_Strdup(D, in_cols[3]);
@@ -548,8 +551,8 @@
return NULL;
}
- E->in_fields[0] = _GD_Strdup(D, in_cols[2]);
- E->in_fields[1] = _GD_Strdup(D, in_cols[3]);
+ E->in_fields[0] = _GD_MungeFromFrag(D, NULL, me, in_cols[2], &offset);
+ E->in_fields[1] = _GD_MungeFromFrag(D, NULL, me, in_cols[3], &offset);
if (D->error) {
_GD_FreeE(D, E, 1);
@@ -611,11 +614,11 @@
return NULL;
}
- E->in_fields[0] = _GD_Strdup(D, in_cols[2]);
+ E->in_fields[0] = _GD_MungeFromFrag(D, NULL, me, in_cols[2], &offset);
E->scalar[0] = _GD_SetScalar(D, in_cols[3], &E->EN(recip,cdividend),
- GD_COMPLEX128, format_file, line, E->scalar_ind, &E->comp_scal, standards,
- pedantic);
+ GD_COMPLEX128, me, format_file, line, E->scalar_ind, &E->comp_scal,
+ standards, pedantic);
E->EN(recip,dividend) = creal(E->EN(recip,cdividend));
E->comp_scal = (cimag(E->EN(recip,cdividend)) == 0) ? 0 : 1;
@@ -676,8 +679,8 @@
return NULL;
}
- E->in_fields[0] = _GD_Strdup(D, in_cols[2]);
- E->in_fields[1] = _GD_Strdup(D, in_cols[3]);
+ E->in_fields[0] = _GD_MungeFromFrag(D, NULL, me, in_cols[2], &offset);
+ E->in_fields[1] = _GD_MungeFromFrag(D, NULL, me, in_cols[3], &offset);
E->EN(window,windop) = _GD_WindOp(in_cols[4]);
if (E->EN(window,windop) == GD_WINDOP_UNK) {
@@ -692,18 +695,18 @@
case GD_WINDOP_EQ:
case GD_WINDOP_NE:
E->scalar[0] = _GD_SetScalar(D, in_cols[5], &E->EN(window,threshold.i),
- GD_INT64, format_file, line, E->scalar_ind, NULL, standards,
+ GD_INT64, me, format_file, line, E->scalar_ind, NULL, standards,
pedantic);
break;
case GD_WINDOP_SET:
case GD_WINDOP_CLR:
E->scalar[0] = _GD_SetScalar(D, in_cols[5], &E->EN(window,threshold.u),
- GD_UINT64, format_file, line, E->scalar_ind, NULL, standards,
+ GD_UINT64, me, format_file, line, E->scalar_ind, NULL, standards,
pedantic);
break;
default:
E->scalar[0] = _GD_SetScalar(D, in_cols[5], &E->EN(window,threshold.r),
- GD_FLOAT64, format_file, line, E->scalar_ind, NULL, standards,
+ GD_FLOAT64, me, format_file, line, E->scalar_ind, NULL, standards,
pedantic);
break;
}
@@ -765,16 +768,17 @@
return NULL;
}
- E->in_fields[0] = _GD_Strdup(D, in_cols[2]);
- E->in_fields[1] = _GD_Strdup(D, in_cols[3]);
+ E->in_fields[0] = _GD_MungeFromFrag(D, NULL, me, in_cols[2], &offset);
+ E->in_fields[1] = _GD_MungeFromFrag(D, NULL, me, in_cols[3], &offset);
E->scalar[0] = _GD_SetScalar(D, in_cols[4], &E->EN(mplex,count_val),
- GD_UINT16, format_file, line, E->scalar_ind, NULL, standards, pedantic);
+ GD_UINT16, me, format_file, line, E->scalar_ind, NULL, standards,
+ pedantic);
/* the count max, if present */
if (n_cols > 5) {
E->scalar[1] = _GD_SetScalar(D, in_cols[5], &E->EN(mplex,count_max),
- GD_UINT16, format_file, line, E->scalar_ind + 1, NULL, standards,
+ GD_UINT16, me, format_file, line, E->scalar_ind + 1, NULL, standards,
pedantic);
if (E->EN(mplex,count_max) < 0)
_GD_SetError(D, GD_E_FORMAT, GD_E_FORMAT_MPLEXVAL, format_file, line,
@@ -850,8 +854,8 @@
return NULL;
}
- E->in_fields[0] = _GD_Strdup(D, in_cols[2]);
- E->in_fields[1] = _GD_Strdup(D, in_cols[3]);
+ E->in_fields[0] = _GD_MungeFromFrag(D, NULL, me, in_cols[2], &offset);
+ E->in_fields[1] = _GD_MungeFromFrag(D, NULL, me, in_cols[3], &offset);
if (D->error) {
_GD_FreeE(D, E, 1);
@@ -915,13 +919,13 @@
return NULL;
}
- E->in_fields[0] = _GD_Strdup(D, in_cols[2]);
+ E->in_fields[0] = _GD_MungeFromFrag(D, NULL, me, in_cols[2], &offset);
E->scalar[0] = _GD_SetScalar(D, in_cols[3], &E->EN(bit,bitnum), GD_INT_TYPE,
- format_file, line, E->scalar_ind, NULL, standards, pedantic);
+ me, format_file, line, E->scalar_ind, NULL, standards, pedantic);
if (n_cols > 4)
E->scalar[1] = _GD_SetScalar(D, in_cols[4], &E->EN(bit,numbits),
- GD_INT_TYPE, format_file, line, E->scalar_ind + 1, NULL, standards,
+ GD_INT_TYPE, me, format_file, line, E->scalar_ind + 1, NULL, standards,
pedantic);
else
E->EN(bit,numbits) = 1;
@@ -995,10 +999,10 @@
return NULL;
}
- E->in_fields[0] = _GD_Strdup(D, in_cols[2]); /* field */
+ E->in_fields[0] = _GD_MungeFromFrag(D, NULL, me, in_cols[2], &offset);
if ((E->scalar[0] = _GD_SetScalar(D, in_cols[3], &E->EN(phase,shift),
- GD_INT64, format_file, line, E->scalar_ind, NULL, standards,
+ GD_INT64, me, format_file, line, E->scalar_ind, NULL, standards,
pedantic)) == NULL)
{
E->e->calculated = 1;
@@ -1068,11 +1072,11 @@
E->e->calculated = 1;
- E->in_fields[0] = _GD_Strdup(D, in_cols[2]);
+ E->in_fields[0] =...
[truncated message content] |