validate.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2003-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
static const char validate_usage[] =
"[+PLUGIN?\findex\f]"
"[+DESCRIPTION?The validate query validates the constraints of the"
" \afield\a operands. If no operands are specified then all"
" fields with constraints or maps are validated. A warning is"
" printed if there are no fields with constraints or maps.]"
"[d:discard?Discard records containing invalid fields.]"
"[l:list?List the field constraints and exit.]"
"[s:summary?Print a summary after all records have been read.]"
"[r:repair?Repair invalid fields if possible.]"
"[v:verbose?Warn about each invalid field and the action taken.]"
"\n"
"\n[ field ... ]\n"
"\n"
;
#include <dsslib.h>
#include <ast_float.h>
struct Field_s
{
};
struct Invalid_s
{
};
struct State_s
{
unsigned char discard;
unsigned char summary;
unsigned char verbose;
};
extern Dsslib_t dss_lib_validate;
static void
{
{
if (((n >= 0) ? n : -n) < 1)
n = 0;
else if (n > FLTMAX_INTMAX_MAX)
n = FLTMAX_INTMAX_MAX;
else if (n < FLTMAX_INTMAX_MIN)
n = FLTMAX_INTMAX_MIN;
}
else if (n == 0 || ((n >= 0) ? n : -n) >= 1 && n >= FLTMAX_INTMAX_MIN && n <= FLTMAX_UINTMAX_MAX && n == (Cxinteger_t)n)
else
}
static int
{
int r;
{
{
{
r = -1;
r = 1;
}
}
r = -1;
r = 1;
}
return r;
}
static int
{
char* s;
int all;
int list;
{
if (vm)
return -1;
}
list = 0;
for (;;)
{
{
case 'd':
continue;
case 'l':
list = 1;
continue;
case 'r':
{
return -1;
}
continue;
case 's':
continue;
case 'v':
continue;
case '?':
else
return -1;
continue;
case ':':
else
return -1;
continue;
}
break;
}
goto bad;
variable = 0;
do
{
if (all)
{
break;
}
goto bad;
{
{
goto bad;
}
else
}
if (list)
{
{
{
if (constraint->name)
if (constraint->constraintf)
{
if (constraint->def)
if (constraint->min)
if (constraint->max)
}
sfprintf(expr->op, " default=\"%-.*s\"", constraint->def->string.size, constraint->def->string.data);
if (constraint->expression)
if (constraint->pattern)
}
}
goto bad;
}
{
goto bad;
}
{
{
goto bad;
}
}
return 0;
bad:
return -1;
}
static int
{
register Cxconstraint_t*constraint;
Cxoperand_t o;
size_t n;
{
return -1;
{
{
{
(*disc->errorf)(NiL, disc, 1, "%s%s: %-.*s: unknown map name", cxlocation(cx, data), field->variable->name, o.value.string.size, o.value.string.data);
goto invalid;
}
}
{
{
(*disc->errorf)(NiL, disc, 1, "%s%s: %I*d: unknown map value", cxlocation(cx, data), field->variable->name, sizeof(Cxinteger_t), (Cxinteger_t)o.value.number);
goto invalid;
}
}
}
{
if (constraint->constraintf)
;
{
{
(*disc->errorf)(NiL, disc, 1, "%s%s: %1.15Lg violates min constraint %1.15Lg", cxlocation(cx, data), field->variable->name, o.value.number, constraint->min->number);
goto invalid;
}
{
(*disc->errorf)(NiL, disc, 1, "%s%s: %1.15Lg violates max constraint %1.15Lg", cxlocation(cx, data), field->variable->name, o.value.number, constraint->max->number);
goto invalid;
}
}
if (constraint->expression)
;
if (constraint->pattern)
;
}
continue;
{
{
{
return -1;
}
if (n)
{
}
}
}
{
return -1;
}
{
return 0;
}
else
}
return 1;
}
static int
{
int heading;
{
heading = 1;
{
heading = 0;
{
sfprintf(expr->op, "%16s %11I*u %*.*s\n", ip->variable->name, sizeof(ip->count), ip->count, val.value.string.size, val.value.string.size, val.value.string.data);
}
}
if (!heading)
{
heading = 1;
}
{
if (heading)
{
heading = 0;
}
sfprintf(expr->op, "%16s %11I*u %11I*u %11I*u\n", field->variable->name, sizeof(field->invalid), field->invalid, sizeof(field->discarded), field->discarded, sizeof(field->repaired), field->repaired);
}
}
return 0;
}
{
{
"validate",
"validate field value constraints",
CXH,
0,
},
{0}
};
{
"validate",
"validate query"
"[-1lms5P?\n@(#)$Id: dss validate query (AT&T Research) 2003-04-05 $\n]"
CXH,
0,
0,
0,
0,
0,
0,
&queries[0]
};