ARSperl
view release on metacpan or search on metacpan
supportrev.c view on Meta::CPAN
else
d->option = AR_DISPLAY_OPT_VISIBLE;
} else
rv += rv2;
/*
* "labelLocation" will be either "Left" or "Top" default: Left
*/
if ((rv2 = strcpyHVal(h, "labelLocation", buf, sizeof(buf)-1)) == 0) {
if (strncasecmp(buf, "Top", sizeof(buf)) == 0)
d->labelLocation = AR_DISPLAY_LABEL_TOP;
else
d->labelLocation = AR_DISPLAY_LABEL_LEFT;
} else
rv += rv2;
/*
* "type" will be one of: NONE, TEXT, NUMTEXT, CHECKBOX, CHOICE,
* BUTTON default: NONE
*/
if ((rv2 = strcpyHVal(h, "type", buf, sizeof(buf)-1)) == 0) {
if (strncasecmp(buf, "TEXT", sizeof(buf)) == 0)
d->type = AR_DISPLAY_TYPE_TEXT;
else if (strncasecmp(buf, "NUMTEXT", sizeof(buf)) == 0)
d->type = AR_DISPLAY_TYPE_NUMTEXT;
else if (strncasecmp(buf, "CHECKBOX", sizeof(buf)) == 0)
d->type = AR_DISPLAY_TYPE_CHECKBOX;
else if (strncasecmp(buf, "CHOICE", sizeof(buf)) == 0)
d->type = AR_DISPLAY_TYPE_CHOICE;
else if (strncasecmp(buf, "BUTTON", sizeof(buf)) == 0)
d->type = AR_DISPLAY_TYPE_BUTTON;
else
d->type = AR_DISPLAY_TYPE_NONE;
} else
rv += rv2;
return rv;
}
/* ROUTINE
* rev_ARInternalIdList(hv, key, idliststruct)
*
* DESCRIPTION
* given a hash, a key and an empty idliststruct,
* pull out the hash value and populate the structure.
*
* RETURNS
* 0 on success
* -1 on failure
* -2 on warning
*/
int
rev_ARInternalIdList(ARControlStruct * ctrl, HV * h, char *k, ARInternalIdList * il)
{
if (!il || !h || !k) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARInternalIdList: required param is NULL");
return -1;
}
if (SvTYPE((SV *) h) == SVt_PVHV) {
if (hv_exists(h, k, strlen(k) )) {
SV **val = hv_fetch(h, k, strlen(k) , 0);
if (val && *val) {
/* hash value should be an array reference */
if (SvTYPE(SvRV(*val)) == SVt_PVAV) {
AV *ar = (AV *) SvRV((SV *) * val);
int i;
/*
* allocate space for display
* structure list
*/
il->numItems = av_len(ar) + 1;
if (il->numItems == 0)
return 0; /* nothing to do */
il->internalIdList = MALLOCNN(sizeof(ARInternalId) * il->numItems);
/*
* iterate over the array, grabbing
* each integer out of it and placing
* into the idlist.
*/
for (i = 0; i <= av_len(ar); i++) {
SV **aval = av_fetch(ar, i, 0);
if (aval && *aval && SvIOK(*aval)) {
il->internalIdList[i] = SvIV(*aval);
} else {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARInternalIdList: array value is not an integer.");
return -1;
}
}
return 0;
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARInternalIdList: hash value is not an array reference");
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARInternalIdList: hv_fetch returned null");
return -2;
}
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARInternalIdList: key doesn't exist");
return -2;
}
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARInternalIdList: first argument is not a hash");
return -1;
}
/* ROUTINE
supportrev.c view on Meta::CPAN
else if (hv_exists(h, "field", strlen("field") )) {
m->assignType = AR_ASSIGN_TYPE_FIELD;
m->u.field = MALLOCNN(sizeof(ARAssignFieldStruct));
rv += rev_ARAssignFieldStruct(ctrl, h, "field", m->u.field);
} else if (hv_exists(h, "arith", strlen("arith") )) {
m->assignType = AR_ASSIGN_TYPE_ARITH;
m->u.arithOp = MALLOCNN(sizeof(ARArithOpAssignStruct));
rv += rev_ARArithOpAssignStruct(ctrl, h, "arith", m->u.arithOp);
} else if (hv_exists(h, "function", strlen("function") )) {
m->assignType = AR_ASSIGN_TYPE_FUNCTION;
m->u.function = MALLOCNN(sizeof(ARFunctionAssignStruct));
rv += rev_ARFunctionAssignStruct(ctrl, h, "function", m->u.function);
}
#if AR_EXPORT_VERSION >= 3
else if (hv_exists(h, "sql", strlen("sql") )) {
m->assignType = AR_ASSIGN_TYPE_SQL;
m->u.sql = (ARAssignSQLStruct*) MALLOCNN(sizeof(ARAssignSQLStruct));
rv += rev_ARAssignSQLStruct(ctrl, h, "sql", m->u.sql);
}
#endif
else if (hv_exists(h, "none", strlen("none") )) {
m->assignType = AR_ASSIGN_TYPE_NONE;
} else {
rv = -1;
}
return rv;
}
#if AR_EXPORT_VERSION >= 3
int
rev_ARAssignSQLStruct(ARControlStruct * ctrl, HV * h, char *k, ARAssignSQLStruct * s)
{
SV **h_sv = hv_fetch(h, k, strlen(k) , 0);
SV **svp;
HV *hr;
int rv = 0;
/* STRLEN len; */
/* dereference the hash key and extract it */
if (SvROK(*h_sv) && SvTYPE(SvRV(*h_sv)) == SVt_PVHV) {
hr = (HV *) SvRV(*h_sv);
} else {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARAssignSQLStruct: hash key 'sql' doesn't contain a hash reference.");
return -1;
}
/* make sure the hash contains the keys we need */
if (!(hv_exists(hr, "server", 6) &&
hv_exists(hr, "sqlCommand", 10) &&
hv_exists(hr, "valueIndex", 10) &&
hv_exists(hr, "noMatchOption", 13) &&
hv_exists(hr, "multiMatchOption", 16))) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARAssignSQLStruct: required hash key not found");
return -1;
}
/* copy the key values into the buffer */
rv += strcpyHVal(hr, "server", s->server, AR_MAX_SERVER_SIZE);
/*
svp = hv_fetch(hr, "sqlCommand", strlen("sqlCommand") , 0);
SvPV(*svp, len);
*/
rv += strmakHVal( hr, "sqlCommand", &(s->sqlCommand) );
rv += uintcpyHVal(hr, "valueIndex", &(s->valueIndex));
svp = hv_fetch(hr, "noMatchOption", strlen("noMatchOption") , 0);
if (svp && *svp) {
char *c = SvPV(*svp, PL_na);
if (rev_ARAssignFieldStructStr2NMO(ctrl, c, &(s->noMatchOption)) != 0) {
s->noMatchOption = AR_NO_MATCH_ERROR;
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARAssignSQLStruct: unknown noMatchOption string:");
ARError_add(AR_RETURN_WARNING, AP_ERR_CONTINUE,
c);
}
}
svp = hv_fetch(hr, "multiMatchOption", strlen("multiMatchOption") , 0);
if (svp && *svp) {
char *c = SvPV(*svp, PL_na);
if (rev_ARAssignFieldStructStr2MMO(ctrl, c, &(s->multiMatchOption)) != 0) {
s->multiMatchOption = AR_MULTI_MATCH_ERROR;
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARAssignSQLStruct: unknown multiMatchOption string:");
ARError_add(AR_RETURN_WARNING, AP_ERR_CONTINUE,
c);
}
}
return rv;
}
#endif /* ARS 3.x */
/* ROUTINE
* rev_ARValueStruct(hash, value-key, type-key, valueStruct)
*
* DESCRIPTION
* given a hash that contains a key that points to a list of values
* and a key that contains a value and another key that describes
* the (ars) datatype of that value, populate the given valueStruct.
*
* RETURNS
* 0 on success
* -1 on failure
* -2 on warning
*/
int
rev_ARValueStruct(ARControlStruct * ctrl, HV * h, char *k, char *t, ARValueStruct * m)
{
SV **val, **type;
if (!m || !h || !k || !t) {
supportrev.c view on Meta::CPAN
char *byteString = SvPV(*vv, PL_na);
int byteLen = SvCUR(*vv);
b->numItems = byteLen;
b->bytes = MALLOCNN(byteLen + 1); /* don't want FreeAR.. to whack us */
copymem(b->bytes, byteString, byteLen);
return 0;
} else {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARImageDataStruct: hash value is not a defined scalar for key:");
ARError_add(AR_RETURN_ERROR, AP_ERR_CONTINUE,
k ? k : "[key null]");
}
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARImageDataStruct: hash key doesn't exist:");
ARError_add(AR_RETURN_WARNING, AP_ERR_CONTINUE,
k ? k : "[key null]");
return -2;
}
return -1;
}
#endif
#if AR_EXPORT_VERSION >= 3
int
rev_ARByteList(ARControlStruct * ctrl, HV * h, char *k, ARByteList * b)
{
if (!h || !k || !b) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARByteList: invalid (NULL) parameter");
return -1;
}
if (hv_exists(h, k, strlen(k) )) {
SV **hr = hv_fetch(h, k, strlen(k) , 0);
if (hr && *hr && SvROK(*hr) && (SvTYPE(SvRV(*hr)) == SVt_PVHV)) {
HV *h2 = (HV *) SvRV(*hr);
if ( hv_exists(h2, "type", strlen("type")) && hv_exists(h2, "value", strlen("value")) ) {
SV **tv = hv_fetch(h2, "type", strlen("type") , 0);
SV **vv = hv_fetch(h2, "value", strlen("value") , 0);
/* we are expecting two PV's */
if (SvPOK(*tv) && SvPOK(*vv)) {
char *typeString = SvPV(*tv, PL_na); /* SvPV is a macro */
char *byteString = SvPV(*vv, PL_na);
int byteLen = SvCUR(*vv);
if (rev_ARByteListStr2Type(ctrl, typeString, &(b->type)) == -1)
return -1;
b->numItems = byteLen;
b->bytes = MALLOCNN(byteLen + 1); /* don't want FreeAR..
* to whack us */
copymem(b->bytes, byteString, byteLen);
return 0;
}
} else {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARByteList: required keys (type and value) not found in inner hash.");
}
} else {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARByteList: hash value is not hash ref for key:");
ARError_add(AR_RETURN_ERROR, AP_ERR_CONTINUE,
k ? k : "[key null]");
printf( "SvTYPE = %d\n", SvTYPE(*hr) );
}
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARByteList: hash key doesn't exist:");
ARError_add(AR_RETURN_WARNING, AP_ERR_CONTINUE,
k ? k : "[key null]");
return -2;
}
return -1;
}
static int
#if AR_CURRENT_API_VERSION >= 14
rev_ARByteListStr2Type(ARControlStruct * ctrl, char *ts, ARULong32 *tv)
#else
rev_ARByteListStr2Type(ARControlStruct * ctrl, char *ts, unsigned long *tv)
#endif
{
int i = 0;
if (ts && *ts && tv) {
for (i = 0; ByteListTypeMap[i].number != TYPEMAP_LAST; i++)
if (strncasecmp(ts, ByteListTypeMap[i].name, strlen(ByteListTypeMap[i].name) ) == 0)
break;
if (ByteListTypeMap[i].number != TYPEMAP_LAST) {
*tv = ByteListTypeMap[i].number;
return 0;
}
}
return -1;
}
int
rev_ARCoordList(ARControlStruct * ctrl, HV * h, char *k, ARCoordList * m)
{
SV **val;
int i;
if (!m) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARCoordList: FieldAssignList param is NULL");
return -1;
}
if (SvTYPE((SV *) h) == SVt_PVHV) {
if (hv_exists(h, k, strlen(k) )) {
val = hv_fetch(h, k, strlen(k) , 0);
if (val && *val) {
/* hash value should be an array reference */
if (SvTYPE(SvRV(*val)) == SVt_PVAV) {
AV *ar = (AV *) SvRV((SV *) * val);
supportrev.c view on Meta::CPAN
int
rev_ARAssignFieldStruct(ARControlStruct * ctrl, HV * h, char *k, ARAssignFieldStruct * m)
{
if (!m || !h || !k) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARAssignFieldStruct: invalid (NULL) parameter");
return -1;
}
if (SvTYPE((SV *) h) == SVt_PVHV) {
if (hv_exists(h, k, strlen(k) )) {
SV **val = hv_fetch(h, k, strlen(k) , 0);
if (val && *val) {
/* hash value should be a hash reference */
if (SvTYPE(SvRV(*val)) == SVt_PVHV) {
HV *h2 = (HV *) SvRV((SV *) * val);
/*
* extract vals from hash ref and
* populate structure
*/
return rev_ARAssignFieldStruct_helper(ctrl, h2, m);
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARAssignFieldStruct: hash value is not a hash reference");
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARAssignFieldStruct: hv_fetch returned null");
return -2;
}
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARAssignFieldStruct: key doesn't exist");
return -2;
}
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARAssignFieldStruct: first argument is not a hash");
return -1;
}
static int
rev_ARAssignFieldStruct_helper(ARControlStruct * ctrl, HV * h, ARAssignFieldStruct * m)
{
ARQualifierStruct *qp;
SV **qpsv, **svp;
if (!(hv_exists(h, "server", 6) &&
hv_exists(h, "schema", 6) &&
hv_exists(h, "qualifier", 9) &&
#if AR_EXPORT_VERSION >= 3
hv_exists(h, "noMatchOption", 13) &&
hv_exists(h, "multiMatchOption", 16) &&
#endif
(hv_exists(h, "fieldId", 7) ||
hv_exists(h, "currencyField", 13) ||
hv_exists(h, "statHistory", 11) ))
) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARAssignFieldStruct_helper: required hash key not found");
return -1;
}
strcpyHVal(h, "server", m->server, AR_MAX_SERVER_SIZE);
strcpyHVal(h, "schema", m->schema, AR_MAX_NAME_SIZE);
if (hv_exists(h, "fieldId", 7)) {
m->tag = AR_FIELD;
if (ulongcpyHVal(h, "fieldId", &(m->u.fieldId)) != 0)
return -1;
} else if (hv_exists(h, "statHistory", 11)) {
m->tag = AR_STAT_HISTORY;
if (rev_ARStatHistoryValue(ctrl, h, "statHistory", &(m->u.statHistory)) != 0)
return -1;
#if AR_EXPORT_VERSION >= 7L
} else if (hv_exists(h, "currencyField", 13)) {
m->tag = AR_CURRENCY_FLD;
m->u.currencyField = MALLOCNN(sizeof(ARCurrencyPartStruct));
if (rev_ARCurrencyPartStruct(ctrl, h, "currencyField", m->u.currencyField) != 0)
return -1;
#endif
}else{
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARAssignFieldStruct_helper: invalid assign type");
return -1;
}
#if AR_EXPORT_VERSION >= 3
svp = hv_fetch(h, "noMatchOption", strlen("noMatchOption") , 0);
if (svp && *svp) {
char *c = SvPV(*svp, PL_na);
if (rev_ARAssignFieldStructStr2NMO(ctrl, c, &(m->noMatchOption)) != 0)
m->noMatchOption = AR_NO_MATCH_ERROR;
}
svp = hv_fetch(h, "multiMatchOption", strlen("multiMatchOption") , 0);
if (svp && *svp) {
char *c = SvPV(*svp, PL_na);
if (rev_ARAssignFieldStructStr2MMO(ctrl, c, &(m->multiMatchOption)) != 0)
m->multiMatchOption = AR_MULTI_MATCH_ERROR;
}
#endif
/*
* extract and duplicate the qualifier struct. if we don't duplicate
* it and simply reference it, FreeARyaddayadda() will free what the
* reference points to and this could lead to badness if the user
* tries to access the qual struct later on.
*/
qpsv = hv_fetch(h, "qualifier", strlen("qualifier") , 0);
if (qpsv && *qpsv && SvROK(*qpsv)) {
if (sv_derived_from(*qpsv, "ARQualifierStructPtr")) {
qp = (ARQualifierStruct *) SvIV((SV *) SvRV(*qpsv));
if (dup_qualifier2(ctrl, qp, &(m->qualifier), 0) != (ARQualifierStruct *) NULL) {
return 0;
}else{
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARAssignFieldStruct_helper: dup_qualifier2() failed");
return -1;
}
supportrev.c view on Meta::CPAN
/* ROUTINE
* rev_ARStatHistoryValue(hash, key, stathistvaluestruct)
*
* DESCRIPTION
* given a hash/key that contains a ref to a status history hash structure,
* extract the info from the hash ref and populate the give stathist struct.
*
* RETURNS
* 0 on success
* -1 on failure
* -2 on warning
*/
int
rev_ARStatHistoryValue(ARControlStruct * ctrl, HV * h, char *k, ARStatHistoryValue * s)
{
if (!s || !h || !k) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARStatHistoryValue: invalid (NULL) parameter");
return -1;
}
if (SvTYPE((SV *) h) == SVt_PVHV) {
if (hv_exists(h, k, strlen(k) )) {
SV **val = hv_fetch(h, k, strlen(k) , 0);
if (val && *val) {
/* hash value should be a hash reference */
if (SvTYPE(SvRV(*val)) == SVt_PVHV) {
HV *h2 = (HV *) SvRV((SV *) * val);
/*
* extract vals from hash ref and
* populate structure
*/
return rev_ARStatHistoryValue_helper(ctrl, h2, s);
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARStatHistoryValue: hash value is not a hash reference");
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARStatHistoryValue: hv_fetch returned null");
return -2;
}
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARStatHistoryValue: key doesn't exist");
return -2;
}
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARStatHistoryValue: first argument is not a hash");
return -1;
}
static int
rev_ARStatHistoryValue_helper(ARControlStruct * ctrl, HV * h, ARStatHistoryValue * s)
{
if (!(hv_exists(h, "userOrTime", 10) && hv_exists(h, "enumVal", 7))) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARAssignFieldStruct_helper: required hash key not found");
return -1;
}
if (ulongcpyHVal(h, "enumVal", &(s->enumVal)) != 0)
return -1;
if (uintcpyHVal(h, "userOrTime", &(s->userOrTime)) != 0)
return -1;
return 0;
}
/* ROUTINE
* rev_ARArithOpAssignStruct(hash, key, arithopstruct)
*
* DESCRIPTION
* this routine will populate the arithopstruct with the information
* contained in the hash ref that is the value of the hash/key given.
*
* RETURNS
* 0 on success
* -1 on failure
* -2 on warning
*/
int
rev_ARArithOpAssignStruct(ARControlStruct * ctrl,
HV * h, char *k, ARArithOpAssignStruct * s)
{
if (!s || !h || !k) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARArithOpAssignStruct: invalid (NULL) parameter");
return -1;
}
if (SvTYPE((SV *) h) == SVt_PVHV) {
if (hv_exists(h, k, strlen(k) )) {
SV **val = hv_fetch(h, k, strlen(k) , 0);
if (val && *val) {
/* hash value should be a hash reference */
if (SvTYPE(SvRV(*val)) == SVt_PVHV) {
HV *h2 = (HV *) SvRV((SV *) * val);
/*
* extract vals from hash ref and
* populate structure
*/
return rev_ARArithOpAssignStruct_helper(ctrl, h2, s);
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARArithOpAssignStruct: hash value is not a hash reference");
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARArithOpAssignStruct: hv_fetch returned null");
return -2;
}
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARArithOpAssignStruct: key doesn't exist");
return -2;
}
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARArithOpAssignStruct: first argument is not a hash");
return -1;
}
static int
rev_ARArithOpAssignStruct_helper(ARControlStruct * ctrl,
HV * h, ARArithOpAssignStruct * s)
{
SV **svp;
if (!hv_exists(h, "oper", 4)) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARArithOpAssignStruct_helper: hash does not contain required key 'oper'.");
return -1;
}
/* decode the operation type */
svp = hv_fetch(h, "oper", strlen("oper") , 0);
if (svp && *svp) {
char *c = SvPV(*svp, PL_na);
if (rev_ARArithOpAssignStructStr2OP(ctrl, c, &(s->operation)) != 0)
return -1;
}
/*
* if oper is 'negate' then we only are interested in the 'left'
* side. else we expect to get both side. call rev_ARAssignStruct()
* to fill it the structure.
*/
if( s->operation == AR_ARITH_OP_SUBTRACT && ! hv_exists(h,"left",4) ){
s->operation = AR_ARITH_OP_NEGATE;
}
if (s->operation == AR_ARITH_OP_NEGATE) {
if (hv_exists(h, "right", 5))
return rev_ARAssignStruct(ctrl, h, "right", &(s->operandRight));
else {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARArithOpAssignStructStr2OP: operation 'negate' ('-') requires 'left' key.");
return -1;
}
}
/* other operations require both left and right */
if (!(hv_exists(h, "left", 4) && hv_exists(h, "right", 5))) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARArithOpAssignStruct_helper: 'left' AND 'right' keys are required.");
return -1;
}
if (rev_ARAssignStruct(ctrl, h, "left", &(s->operandLeft)) == -1)
return -1;
return rev_ARAssignStruct(ctrl, h, "right", &(s->operandRight));
}
static int
rev_ARArithOpAssignStructStr2OP(ARControlStruct * ctrl, char *c, unsigned int *o)
{
int i;
for (i = 0; ArithOpMap[i].number != TYPEMAP_LAST; i++)
if (strcasecmp(ArithOpMap[i].name, c) == 0)
break;
if (ArithOpMap[i].number == TYPEMAP_LAST) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARArithOpAssignStructStr2OP: unknown operation word:");
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL, c);
return -1;
}
*o = ArithOpMap[i].number;
return 0;
}
/* ROUTINE
* rev_ARFunctionAssignStruct(hash, key, functionassignstruct)
*
* DESCRIPTION
* unpack the function assign perl structure from the hash/key pair
* (it will be a hash ref) and populate the functionassignstruct
*
* RETURNS
* 0 on success
* -1 on failure
* -2 on warning
*/
int
rev_ARFunctionAssignStruct(ARControlStruct * ctrl,
HV * h, char *k, ARFunctionAssignStruct * s)
{
if (!s || !h || !k) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARFunctionAssignStruct: invalid (NULL) parameter");
return -1;
}
if (SvTYPE((SV *) h) == SVt_PVHV) {
if (hv_exists(h, k, strlen(k) )) {
SV **val = hv_fetch(h, k, strlen(k) , 0);
if (val && *val) {
/* hash value should be an array reference */
if (SvTYPE(SvRV(*val)) == SVt_PVAV) {
AV *a = (AV *) SvRV((SV *) * val);
SV **aval;
int i;
if (av_len(a) < 0) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
supportrev.c view on Meta::CPAN
m->numItems = av_len(a) + 1;
if (m->numItems == 0)
return 0; /* nothing to do */
m->props = (ARPropStruct *) MALLOCNN(sizeof(ARPropStruct) * m->numItems);
/*
* iterate over the array, grabbing
* each hash reference out of it and
* passing that to a helper routine
* to fill in the Prop structure.
*/
for (i = 0; i <= av_len(a); i++) {
SV **av_hv = av_fetch(a, i, 0);
if (av_hv && *av_hv && (SvTYPE(SvRV(*av_hv)) == SVt_PVHV)) {
if (rev_ARPropList_helper(ctrl, (HV *) SvRV(*av_hv), m, i) != 0)
return -1;
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARPropList: inner array value is not a hash reference");
}
return 0;
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARPropList: hash value is not an array reference");
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARPropList: hv_fetch returned null");
return -2;
}
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARPropList: key doesn't exist");
return -2;
}
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARPropList: first argument is not a hash");
return -1;
}
static int
rev_ARPropList_helper(ARControlStruct * ctrl, HV * h, ARPropList * m, int idx)
{
int rv = 0;
if (hv_exists(h, "prop", strlen("prop") ) &&
hv_exists(h, "value", strlen("value") ) &&
hv_exists(h, "valueType", strlen("valueType") )) {
rv += ulongcpyHVal(h, "prop", &(m->props[idx].prop));
rv += rev_ARValueStruct(ctrl, h, "value", "valueType",
&(m->props[idx].value));
return rv;
}
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARPropList_helper: required hash keys not present (prop, value, valueType).");
return -1;
}
#endif /* 3.x */
int
rev_ARActiveLinkMacroStruct(ARControlStruct * ctrl,
HV * h, char *k, ARActiveLinkMacroStruct * m)
{
if (!m || !h || !k) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARActiveLinkMacroStruct: invalid (NULL) parameter");
return -1;
}
if (SvTYPE((SV *) h) == SVt_PVHV) {
if (hv_exists(h, k, strlen(k) )) {
SV **val = hv_fetch(h, k, strlen(k) , 0);
if (val && *val) {
/* hash value should be a hash reference */
if (SvTYPE(SvRV(*val)) == SVt_PVHV) {
HV *a = (HV *) SvRV((SV *) * val);
return rev_ARActiveLinkMacroStruct_helper(ctrl, a, m);
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARActiveLinkMacroStruct: hash value is not a hash reference");
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARActiveLinkMacroStruct: hv_fetch returned null");
return -2;
}
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARActiveLinkMacroStruct: key doesn't exist");
return -2;
}
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARActiveLinkMacroStruct: first argument is not a hash");
return -1;
}
static int
rev_ARActiveLinkMacroStruct_helper(ARControlStruct * ctrl,
HV * h, ARActiveLinkMacroStruct * m)
{
int rv = 0;
if (hv_exists(h, "macroParms", strlen("macroParms") ) &&
hv_exists(h, "macroText", strlen("macroText") ) &&
hv_exists(h, "macroName", strlen("macroName") )) {
rv += strcpyHVal(h, "macroName", m->macroName, AR_MAX_NAME_SIZE);
rv += strmakHVal(h, "macroText", &(m->macroText));
rv += rev_ARMacroParmList(ctrl, h, "macroParms", &(m->macroParms));
return 0;
}
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARActiveLinkMacroStruct_helper: required keys not present in hash (macroParms, macroText, macroName)");
return -1;
}
int
rev_ARMacroParmList(ARControlStruct * ctrl, HV * h, char *k, ARMacroParmList * m)
{
if (!h || !k || !*k || !m) {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARMacroParmList: invalid parameter(s).");
return -1;
}
if (SvTYPE((SV *) h) == SVt_PVHV) {
if (hv_exists(h, k, strlen(k) )) {
SV **val = hv_fetch(h, k, strlen(k) , 0);
if (val && *val) {
/* hash value should be a hash reference */
if (SvTYPE(SvRV(*val)) == SVt_PVHV) {
HV *a = (HV *) SvRV((SV *) * val);
int rv = 0, i, i2;
SV *hval;
char *hkey;
I32 klen;
/*
* the hash's keys are the names of
* the macroparm and the values are
* the value of the macroparm. both
* are pv's. so iterate over every
* key in the hash and populate the
* parms list with them.
*/
(void) hv_iterinit(a);
for (i = 0; hv_iternext(a) != (HE *) NULL; i++);
m->numItems = i;
m->parms = (ARMacroParmStruct *) MALLOCNN(sizeof(ARMacroParmStruct)
* m->numItems);
(void) hv_iterinit(a);
i2 = 0;
while ((hval = hv_iternextsv(a, &hkey, &klen))) {
if (hval && SvPOK(hval)) {
char *vv = SvPV(hval, PL_na);
int vl = SvCUR(hval);
if (i2 <= i) {
(void) strncpy(m->parms[i2].name, hkey, sizeof(ARNameType));
/* (void) copymem(m->parms[i2].value, vv, vl); */
m->parms[i2].value = strdup( vv );
i2++;
} else {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARMacroParmList: oops! more parms than i thought!");
return -1;
}
} else {
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL, "rev_ARMacroParmList: value for macro param is not a string. macro param name:");
ARError_add(AR_RETURN_ERROR, AP_ERR_CONTINUE, hkey);
rv = -1;
( run in 1.762 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )