ARSperl
view release on metacpan or search on metacpan
supportrev.c view on Meta::CPAN
#define __supportrev_c_
#include "support.h"
#include "supportrev.h"
#include "supportrev_generated.h"
#if defined(ARSPERL_UNDEF_MALLOC) && defined(malloc)
#undef malloc
#undef calloc
#undef realloc
#undef free
#endif
/*
* forward declarations
*/
static int
rev_ARActiveLinkActionList_helper(ARControlStruct * ctrl, HV * h,
ARActiveLinkActionList * al,
int idx);
static int
rev_ARDisplayStruct_helper(ARControlStruct * ctrl,
HV * h, char *k, ARDisplayStruct * d);
static int
rev_ARValueStructStr2Type(ARControlStruct * ctrl,
char *type, unsigned int *n);
static int
rev_ARValueStructKW2KN(ARControlStruct * ctrl,
char *keyword, unsigned int *n);
static int
rev_ARValueStructDiary(ARControlStruct * ctrl,
HV * h, char *k, char **d);
static int
rev_ARAssignFieldStruct_helper(ARControlStruct * ctrl,
HV * h, ARAssignFieldStruct * m);
static int
rev_ARAssignFieldStructStr2NMO(ARControlStruct * ctrl,
char *s, unsigned int *nmo);
static int
rev_ARAssignFieldStructStr2MMO(ARControlStruct * ctrl,
char *s, unsigned int *mmo);
static int
rev_ARStatHistoryValue_helper(ARControlStruct * ctrl,
HV * h, ARStatHistoryValue * s);
static int
rev_ARArithOpAssignStruct_helper(ARControlStruct * ctrl,
HV * h, ARArithOpAssignStruct * s);
static int
rev_ARArithOpAssignStructStr2OP(ARControlStruct * ctrl,
char *c, unsigned int *o);
static int
rev_ARFunctionAssignStructStr2FCODE(ARControlStruct * ctrl,
char *c, unsigned int *o);
static int
rev_ARAssignStruct_helper(ARControlStruct * ctrl,
HV * h, ARAssignStruct * m);
static int
rev_ARActiveLinkMacroStruct_helper(ARControlStruct * ctrl, HV * h,
ARActiveLinkMacroStruct * m);
static int
rev_ARAssignList_helper(ARControlStruct * ctrl,
HV * h, ARFieldAssignList * m, int i);
#if AR_EXPORT_VERSION >= 3
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
static int
rev_ARCoordList_helper(ARControlStruct * ctrl,
HV * h, ARCoordList * m, int idx);
static int
rev_ARPropList_helper(ARControlStruct * ctrl,
HV * h, ARPropList * m, int idx);
#endif
/* ROUTINE
* revTypeName(TypeMapStruct *tms, char *type)
*
* DESCRIPTION
* given a typemapstruct and a string, return the
* enumeration value if string exists in struct.
*
* RETURNS
* >=0 on success
* TYPEMAP_LAST on failure
*/
unsigned int
revTypeName(TypeMapStruct *t, char *type)
{
if(type && *type && t) {
int i = 0;
while((t[i].number != TYPEMAP_LAST) && strcmp(t[i].name, type))
i++;
return t[i].number;
}
return TYPEMAP_LAST;
}
/* ROUTINE
* strcpyHVal(hash, key, buffer, bufferLen - 1)
*
* DESCRIPTION
* given a hash (HV *), a key, a pre-allocated buffer and
* the length of that buffer, retrieve the value from the hash
* (assuming it is a string value [PV]) and place it in the buffer.
*
* NOTES
* The value of hash is truncate at len bytes if it exceeds len.
* buffer, once filled in, will be null terminated. Thus the
* bufferLen should be the real length minus 1, because the
supportrev.c view on Meta::CPAN
/*
* iterate over the array, grabbing
* each hash reference out of it and
* passing that to a helper routine
* to fill in the ActionList
* structure. one action per array
* item.
*/
for (i = 0; i <= av_len(ar); i++) {
SV **av_hv = av_fetch(ar, i, 0);
if (av_hv && *av_hv && (SvTYPE(SvRV(*av_hv)) == SVt_PVHV)) {
if (rev_ARActiveLinkActionList_helper(ctrl,
(HV *) SvRV(*av_hv), al, i) != 0)
return -1;
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARActiveLinkActionList: inner array value is not a hash reference");
}
return 0;
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARActiveLinkActionList: hash value is not an array reference");
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARActiveLinkActionList: hv_fetch returned null");
return -2;
}
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARActiveLinkActionList: key doesn't exist");
return -2;
}
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARActiveLinkActionList: first argument is not a hash");
return -1;
}
/* helper routine to above routine. does the actual data copying once
* main routine has verified that everything is OK.
*/
static int
rev_ARActiveLinkActionList_helper(ARControlStruct * ctrl, HV * h, ARActiveLinkActionList * al, int idx)
{
int rv = 0;
/*
* test each has value in turn, first one that is defined, copy in
* and return. DDE: not implemented.
*/
if (hv_exists(h, "process", strlen("process") )) {
al->actionList[idx].action = AR_ACTIVE_LINK_ACTION_PROCESS;
rv += strmakHVal(h, "process", &(al->actionList[idx].u.process));
} else if (hv_exists(h, "macro", strlen("macro") )) {
al->actionList[idx].action = AR_ACTIVE_LINK_ACTION_MACRO;
rv += rev_ARActiveLinkMacroStruct(ctrl, h, "macro",
&(al->actionList[idx].u.macro));
} else if (hv_exists(h, "assign_fields", strlen("assign_fields") )) {
al->actionList[idx].action = AR_ACTIVE_LINK_ACTION_FIELDS;
#if AR_EXPORT_VERSION >= 8L
rv += rev_ARSetFieldsActionStruct(ctrl, h, "assign_fields",
&(al->actionList[idx].u.setFields));
#else
rv += rev_ARFieldAssignList(ctrl, h, "assign_fields",
&(al->actionList[idx].u.fieldList));
#endif
} else if (hv_exists(h, "message", strlen("message") )) {
al->actionList[idx].action = AR_ACTIVE_LINK_ACTION_MESSAGE;
#if AR_EXPORT_VERSION >= 4
rv += rev_ARMessageStruct(ctrl, h, "message",
&(al->actionList[idx].u.message));
#else
rv += rev_ARStatusStruct(ctrl, h, "message",
&(al->actionList[idx].u.message));
#endif
} else if (hv_exists(h, "characteristics", strlen("characteristics") )) {
al->actionList[idx].action = AR_ACTIVE_LINK_ACTION_SET_CHAR;
rv += rev_ARFieldCharacteristics(ctrl, h, "characteristics",
&(al->actionList[idx].u.characteristics));
} else if (hv_exists(h, "fieldp", strlen("fieldp") )) {
al->actionList[idx].action = AR_ACTIVE_LINK_ACTION_FIELDP;
#if AR_EXPORT_VERSION >= 8L
rv += rev_ARPushFieldsActionStruct(ctrl, h, "fieldp",
&(al->actionList[idx].u.pushFields));
#else
rv += rev_ARPushFieldsList(ctrl, h, "fieldp",
&(al->actionList[idx].u.pushFieldsList));
#endif
} else if (hv_exists(h, "openDlg", strlen("openDlg") )) {
al->actionList[idx].action = AR_ACTIVE_LINK_ACTION_OPENDLG;
rv += rev_AROpenDlgStruct(ctrl, h, "openDlg",
&(al->actionList[idx].u.openDlg));
} else if (hv_exists(h, "closeWnd", strlen("closeWnd") )) {
al->actionList[idx].action = AR_ACTIVE_LINK_ACTION_CLOSEWND;
rv += rev_ARCloseWndStruct(ctrl, h, "closeWnd",
&(al->actionList[idx].u.closeWnd));
} else if (hv_exists(h, "commitChanges", strlen("commitChanges") )) {
al->actionList[idx].action = AR_ACTIVE_LINK_ACTION_COMMITC;
rv += rev_ARCommitChangesStruct(ctrl, h, "commitChanges",
&(al->actionList[idx].u.commitChanges));
} else if (hv_exists(h, "callGuide", strlen("callGuide") )) {
al->actionList[idx].action = AR_ACTIVE_LINK_ACTION_CALLGUIDE;
rv += rev_ARCallGuideStruct(ctrl, h, "callGuide",
&(al->actionList[idx].u.callGuide));
} else if (hv_exists(h, "exitGuide", strlen("exitGuide") )) {
al->actionList[idx].action = AR_ACTIVE_LINK_ACTION_EXITGUIDE;
rv += rev_ARExitGuideStruct(ctrl, h, "exitGuide",
&(al->actionList[idx].u.exitGuide));
} else if (hv_exists(h, "gotoGuideLabel", strlen("gotoGuideLabel") )) {
supportrev.c view on Meta::CPAN
/*
* 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;
}
}
return rv;
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARMacroParmList: hash value is not a hash reference");
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARMacroParmList: hv_fetch returned null");
return -2;
}
} else {
ARError_add(AR_RETURN_WARNING, AP_ERR_GENERAL,
"rev_ARMacroParmList: key doesn't exist");
return -2;
}
} else
ARError_add(AR_RETURN_ERROR, AP_ERR_GENERAL,
"rev_ARMacroParmList: first argument is not a hash");
return -1;
}
#if defined(_WIN32) && !defined(__GNUC__)
/* roll our own strcasecmp and strncasecmp for Win */
int
strcasecmp(char *s1, char *s2)
{
char *p1, *p2;
char c1, c2;
p1 = s1;
p2 = s2;
while ((*p1 != '\0') && (*p2 != '\0')) {
c1 = tolower(*p1);
c2 = tolower(*p2);
if ((c1 - c2) == 0) {
p2++;
p1++;
} else {
return (c1 - c2);
}
}
return *p1 - *p2;
}
int
strncasecmp(char *s1, char *s2, size_t n)
{
char *p1, *p2;
char c1, c2;
size_t i = 0;
p1 = s1;
p2 = s2;
while ((*p1 != '\0') && (*p2 != '\0') && (i <= n)) {
c1 = tolower(*p1);
c2 = tolower(*p2);
if ((c1 - c2) == 0) {
p2++;
p1++;
} else {
return (c1 - c2);
}
i++;
}
return (i == n)? 0 : *p1 - *p2;
}
char*
arsperl_strdup( char *s1 ){
char *p1;
int len = strlen( s1 );
p1 = MALLOCNN( len + 1 );
strncpy( p1, s1, len );
/* p1[len] = '\0'; */
return p1;
}
( run in 1.248 second using v1.01-cache-2.11-cpan-d8267643d1d )