📄 funchand.cpp
字号:
}
if (node->status != NULL)
{
delete [] node->status;
node->status = NULL;
}
if (node->description != NULL)
{
delete [] node->description;
node->description = NULL;
}
if (node->OID != NULL)
{
delete [] node->OID;
node->OID = NULL;
}
if (node->value != NULL)
{
delete [] node->value;
node->value = NULL;
}
node->asn1syntax = (char)0;
strcpy(node->timestamp,"");
node->name = NULL;
node->minVal = (long)0;
node->maxVal = (long)0;
node->minUnsigned = (unsigned long)0;
node->maxUnsigned = (unsigned long)0;
ret_node->ival = GetNodeInfo(arglist->sval,node);
ret_node->next = NULL;
ret_node->arg_type = SY_INT_TYPE;
return(ret_node);
}
struct ARGUMENT *fh_getNodeObjects(struct ARGUMENT *arglist, char **olp)
{
struct ARGUMENT *ret_node;
char *temp, *ptr;
int i;
ret_node = (struct ARGUMENT *)safe_alloc(1,sizeof(struct ARGUMENT));
(*olp) = NULL;
GetNodeObjects(arglist->sval, olp);
temp = (char *)safe_alloc(strlen(*olp)+1,sizeof(char));
strcpy(temp, *olp);
i = 0;
ptr = temp;
while(ptr != NULL)
{
if(strchr(ptr,'\n'))
ptr = strchr(ptr,'\n') + 1;
else
ptr = NULL;
i++;
}
ret_node->next = NULL;
ret_node->arg_type = SY_INT_TYPE;
ret_node->ival = i;
return(ret_node);
}
struct ARGUMENT *fh_getInstance(struct ARGUMENT *arglist, char **olp)
{
//This function will return an object name from the list
//returned from getNodeObjects. The first and only argument
//to this function will be the object index to be returned.
struct ARGUMENT *ret_node;
int i;
char *ptr, *temp;
ret_node = (struct ARGUMENT *)safe_alloc(1,sizeof(struct ARGUMENT));
ptr = *olp;
i = 0;
while(i < arglist->ival && ptr != NULL)
{
if(strchr(ptr,'\n'))
ptr = strchr(ptr,'\n') + 1;
else
ptr = NULL;
i++;
}
if(ptr != NULL)
{
temp = (char *)safe_alloc(strlen(ptr)+1,sizeof(char));
strcpy(temp,ptr);
strtok(temp,"\n");
ret_node->sval = (char *)safe_alloc(strlen(temp)+1,sizeof(char));
strcpy(ret_node->sval,temp);
safe_free(temp);
}
else
{
ret_node->sval = (char *)safe_alloc(1,sizeof(char));
strcpy(ret_node->sval,"");
}
ret_node->arg_type = SY_STRING_TYPE;
ret_node->next = NULL;
return(ret_node);
}
struct ARGUMENT *fh_getNextInstance(struct ARGUMENT *arglist)
{
struct ARGUMENT *ret_node;
char *instance;
int err;
ret_node = (struct ARGUMENT *)safe_alloc(1,sizeof(struct ARGUMENT));
err = GetNextInstance(arglist->sval, &instance);
if(err == 0)
{
ret_node->sval = (char *)safe_alloc(strlen(instance)+1,sizeof(char));
strcpy(ret_node->sval,instance);
delete instance;
}
else
{
ret_node->sval = (char *)safe_alloc(2,sizeof(char));
strcpy(ret_node->sval,"");
}
ret_node->arg_type = SY_STRING_TYPE;
ret_node->next = NULL;
return(ret_node);
}
void read_input_file(struct SYTAB *st)
{
char *ifname;
FILE *ifp;
char *curr_line;
char *curr_id;
char *curr_val;
char *tempstr;
char *ptr;
int invar_type;
int invar_index;
int i;
char ch;
//open input file
i = symbol_table_lookup(st,"infile");
ifname = (char *)safe_alloc(get_symbol_offset_value(st,i) + 1,
sizeof(char));
strcpy(ifname,get_symbol_string_value(st,i));
ifp = fopen(ifname,"rt");
//read one line at a time
//input file will follow this format:
//<variable name> : <value>
//following is an example for int i, float f, and string s.
//i : 5
//f : 67.32
//s : "hello world!"
//strings must be delimited by double quotes.
//strings may contain escape sequence characters such as,
//s : "hello \"terra\" firma!"
while(! feof(ifp))
{
curr_line = (char *)safe_alloc(1024,sizeof(char));
//consume leading whitespace
ch = (char)getc(ifp);
while( !feof(ifp) && (ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r'))
ch = (char)getc(ifp);
ungetc(ch,ifp);
fgets(curr_line,1023,ifp);
//consume trailing whitespace
ch = (char)getc(ifp);
while( !feof(ifp) && (ch == ' ' || ch == '\n' || ch == '\t' || ch == '\r'))
ch = (char)getc(ifp);
ungetc(ch,ifp);
//grab identifier name
ptr = strtok(curr_line,":");
curr_id = (char *)safe_alloc(strlen(ptr) +1,sizeof(char));
strcpy(curr_id,ptr);
//grab value
ptr = strtok(NULL,":");
curr_val = (char *)safe_alloc(strlen(ptr) +1,sizeof(char));
strcpy(curr_val,ptr);
safe_free(curr_line);
trim(&curr_id);
trim(&curr_val);
invar_index = symbol_table_lookup(st,curr_id);
invar_type = get_symbol_type(st,invar_index);
if(get_invar(st,invar_index)==1)
{
if(invar_type == SY_INT_TYPE)
{
set_value_in_st(st,invar_index,atol(curr_val),0.0,"",0);
}
if(invar_type == SY_FLOAT_TYPE)
{
set_value_in_st(st,invar_index,0,(float)atof(curr_val),"",0);
}
if(invar_type == SY_STRING_TYPE)
{
//strip first and last quotes off of string
tempstr = &(curr_val[1]);
curr_val[strlen(curr_val) -1] = '\0';
realloc_string_size(st,invar_index,strlen(tempstr)+1);
set_value_in_st(st,invar_index,0,0.0,
tempstr,0);
}
}
safe_free(curr_val);
safe_free(curr_id);
}
fclose(ifp);
safe_free(ifname);
return;
}
struct ARGUMENT *fh_getNodeName(struct nodeInfo *node)
{
struct ARGUMENT *ret_node;
ret_node = (struct ARGUMENT *)safe_alloc(1,sizeof(struct ARGUMENT));
ret_node->sval = (char *)safe_alloc(strlen(node->name)+1,sizeof(char));
if(node->name != NULL)
{
ret_node->sval = (char *)safe_alloc(strlen(node->name)+1,sizeof(char));
strcpy(ret_node->sval,node->name);
}
else
{
ret_node->sval = (char *)safe_alloc(1,sizeof(char));
strcpy(ret_node->sval,"");
}
ret_node->arg_type = SY_STRING_TYPE;
ret_node->next = NULL;
return(ret_node);
}
struct ARGUMENT *fh_getNodeSyntax(struct nodeInfo *node)
{
struct ARGUMENT *ret_node;
ret_node = (struct ARGUMENT *)safe_alloc(1,sizeof(struct ARGUMENT));
if(node->syntax != NULL)
{
ret_node->sval = (char *)safe_alloc(strlen(node->syntax)+1,sizeof(char));
strcpy(ret_node->sval,node->syntax);
}
else
{
ret_node->sval = (char *)safe_alloc(1,sizeof(char));
strcpy(ret_node->sval,"");
}
ret_node->arg_type = SY_STRING_TYPE;
ret_node->next = NULL;
return(ret_node);
}
struct ARGUMENT *fh_getNodeAccess(struct nodeInfo *node)
{
struct ARGUMENT *ret_node;
ret_node = (struct ARGUMENT *)safe_alloc(1,sizeof(struct ARGUMENT));
if(node->access != NULL)
{
ret_node->sval = (char *)safe_alloc(strlen(node->access)+1,sizeof(char));
strcpy(ret_node->sval,node->access);
}
else
{
ret_node->sval = (char *)safe_alloc(1,sizeof(char));
strcpy(ret_node->sval,"");
}
ret_node->arg_type = SY_STRING_TYPE;
ret_node->next = NULL;
return(ret_node);
}
struct ARGUMENT *fh_getNodeStatus(struct nodeInfo *node)
{
struct ARGUMENT *ret_node;
ret_node = (struct ARGUMENT *)safe_alloc(1,sizeof(struct ARGUMENT));
if(node->status != NULL)
{
ret_node->sval = (char *)safe_alloc(strlen(node->status)+1,sizeof(char));
strcpy(ret_node->sval,node->status);
}
else
{
ret_node->sval = (char *)safe_alloc(1,sizeof(char));
strcpy(ret_node->sval,"");
}
ret_node->arg_type = SY_STRING_TYPE;
ret_node->next = NULL;
return(ret_node);
}
struct ARGUMENT *fh_getNodeDescription(struct nodeInfo *node)
{
struct ARGUMENT *ret_node;
ret_node = (struct ARGUMENT *)safe_alloc(1,sizeof(struct ARGUMENT));
if(node->description != NULL)
{
ret_node->sval = (char *)safe_alloc(strlen(node->description)+1,sizeof(char));
strcpy(ret_node->sval,node->description);
}
else
{
ret_node->sval = (char *)safe_alloc(1,sizeof(char));
strcpy(ret_node->sval,"");
}
ret_node->arg_type = SY_STRING_TYPE;
ret_node->next = NULL;
return(ret_node);
}
struct ARGUMENT *fh_getNodeOID(struct nodeInfo *node)
{
struct ARGUMENT *ret_node;
ret_node = (struct ARGUMENT *)safe_alloc(1,sizeof(struct ARGUMENT));
if(node->OID != NULL)
{
ret_node->sval = (char *)safe_alloc(strlen(node->OID)+1,sizeof(char));
strcpy(ret_node->sval,node->OID);
}
else
{
ret_node->sval = (char *)safe_alloc(1,sizeof(char));
strcpy(ret_node->sval,"");
}
ret_node->arg_type = SY_STRING_TYPE;
ret_node->next = NULL;
return(ret_node);
}
struct ARGUMENT *fh_getNodeMin(struct nodeInfo *node)
{
struct ARGUMENT *ret_node;
ret_node = (struct ARGUMENT *)safe_alloc(1,sizeof(struct ARGUMENT));
if(node->minVal == 0)
ret_node->ival = (long)node->minUnsigned;
else
ret_node->ival = node->minVal;
ret_node->arg_type = SY_INT_TYPE;
ret_node->next = NULL;
return(ret_node);
}
struct ARGUMENT *fh_getNodeMax(struct nodeInfo *node)
{
struct ARGUMENT *ret_node;
ret_node = (struct ARGUMENT *)safe_alloc(1,sizeof(struct ARGUMENT));
if(node->maxVal == 0)
ret_node->ival = (long)node->maxUnsigned;
else
ret_node->ival = node->maxVal;
ret_node->arg_type = SY_INT_TYPE;
ret_node->next = NULL;
return(ret_node);
}
struct ARGUMENT *fh_getNodeValue(struct nodeInfo *node)
{
struct ARGUMENT *ret_node;
ret_node = (struct ARGUMENT *)safe_alloc(1,sizeof(struct ARGUMENT));
if(node->value != NULL)
ret_node->ival = atol((char *)(node->value));
else
ret_node->ival = 0;
ret_node->arg_type = SY_INT_TYPE;
ret_node->next = NULL;
return(ret_node);
}
struct ARGUMENT *fh_getNodeTimestamp(struct nodeInfo *node)
{
struct ARGUMENT *ret_node;
ret_node = (struct ARGUMENT *)safe_alloc(1,sizeof(struct ARGUMENT));
if(node->timestamp != NULL)
{
ret_node->sval = (char *)safe_alloc(strlen(node->timestamp)+1,sizeof(char));
strcpy(ret_node->sval, node->timestamp);
}
else
{
ret_node->sval = (char *)safe_alloc(1,sizeof(char));
strcpy(ret_node->sval,"");
}
ret_node->arg_type = SY_STRING_TYPE;
ret_node->next = NULL;
return(ret_node);
}
struct ARGUMENT *fh_setNodeAsn1Syntax(struct ARGUMENT *arglist, struct nodeInfo *node)
{
node->asn1syntax = (char)arglist->ival;
return(NULL);
}
struct ARGUMENT *fh_setField_pdu(struct ARGUMENT *arglist, struct mystruct *send)
{
safe_free(send->pdu);
send->pdu = (char *)safe_alloc(strlen(arglist->sval)+1,sizeof(char));
strcpy(send->pdu,arglist->sval);
return(NULL);
}
struct ARGUMENT *fh_setField_classtype(struct ARGUMENT *arglist, struct mystruct *send)
{
safe_free(send->classtype);
send->classtype = (char *)safe_alloc(strlen(arglist->sval)+1,sizeof(char));
strcpy(send->classtype,arglist->sval);
return(NULL);
}
struct ARGUMENT *fh_setField_community(struct ARGUMENT *arglist, struct mystruct *send)
{
safe_free(send->community);
send->community = (char *)safe_alloc(strlen(arglist->sval)+1,sizeof(char));
strcpy(send->community,arglist->sval);
return(NULL);
}
struct ARGUMENT *fh_setField_AddressDrop(struct ARGUMENT *arglist, struct mystruct *send)
{
send->AddressDrop = arglist->ival;
return(NULL);
}
struct ARGUMENT *fh_setField_GroupAddress(struct ARGUMENT *arglist, struct mystruct *send)
{
send->GroupAddress = arglist->ival;
return(NULL);
}
struct ARGUMENT *fh_setField_SizeOfTheArray(struct ARGUMENT *arglist, struct mystruct *send)
{
send->SizeOfTheArray = arglist->ival;
return(NULL);
}
struct ARGUMENT *fh_setField_arraylist(struct ARGUMENT *arglist, struct mystruct *send)
{
int i;
i = arglist->next->ival;
safe_free(send->arraylist[i -1]);
send->arraylist[i -1] = (char *)safe_alloc(strlen(arglist->sval)+1,sizeof(char));
strcpy(send->arraylist[i -1],arglist->sval);
return(NULL);
}
struct ARGUMENT *fh_setField_valuelist(struct ARGUMENT *arglist, struct mystruct *send)
{
int i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -