#############################################################  -*- c -*-
## generic include for XXX. Do not use directly.
##
## $Id: generic-ctx-get.m2i,v 1.10.2.1 2005/07/25 23:13:52 rstory Exp $
########################################################################
@if $m2c_mark_boundary == 1@
/** START code generated by $RCSfile: generic-ctx-get.m2i,v $ $Revision: 1.10.2.1 $ */
@end@
########################################################################
##/*
## This include will generate the code needed to assign data from
## a generated data context to a parameter reference.
##
## EXAMPLE (prototype generated elsewhere)
## int
## ifName_get(ifXTable_ctx * ctx, char **ifName_ptr_ptr,
##            size_t * ifName_len_ptr) {
##
## 
## m2c_node_lh :   temp_ifName / (*ifName_ptr_ptr)
## m2c_node_lhs:   temp_ifName_len / (*ifName_len_ptr);
## m2c_ctx_rh  :   ctx->data.
## node        :  ifName
##
##    if (temp_ifName_len < ctx->data.ifName_len) {
##        temp_ifName = malloc(ctx->data.ifName_len);
##    }
##    temp_ifName_len = ctx->data.ifName_len;
##    memcpy(temp_ifName, ctx->data.ifName, temp_ifName_len);
##*/
@if "$m2c_data_context" ne "generated"@
    /** WARNING: this code might not work for $m2c_data_context */
@end@
@if $m2c_node_needlength == 1@
    /*
     * make sure there is enough space for $node data
     */
    if ((NULL == $m2c_ctx_lh) ||
        ($m2c_ctx_lhs < ($m2c_ctx_rhs * sizeof(${m2c_ctx_lh}[0])))) {
@   if $m2c_node_realloc == 0@
        snmp_log(LOG_ERR,"not enough space for value\n");
        return MFD_ERROR;
@   else@
        /*
         * allocate space for $node data
         */
@      if $m2c_node_realloc == 1@
        $m2c_ctx_lh = realloc($m2c_ctx_lh, $m2c_ctx_rhs * sizeof(${m2c_ctx_lh}[0]));
@      else@
        $m2c_ctx_lh = malloc($m2c_ctx_rhs * sizeof(${m2c_ctx_lh}[0]));
@      end@
        if(NULL == $m2c_ctx_lh) {
            snmp_log(LOG_ERR,"could not allocate memory\n");
            return MFD_ERROR;
        }
@   end@
    }
    $m2c_ctx_lhs = $m2c_ctx_rhs * sizeof(${m2c_ctx_lh}[0]);
    memcpy( $m2c_ctx_lh, $m2c_ctx_rh, $m2c_ctx_lhs );
@else@
@   if $node.decl =~ /U64/i@ #              ASN_COUNTER64
    ${m2c_ctx_lh}.high = ${m2c_ctx_rh}.high;
    ${m2c_ctx_lh}.low = ${m2c_ctx_rh}.low;
@   else@
    $m2c_ctx_lh = $m2c_ctx_rh;
@   end@
@end@ # length
##
########################################################################
@if $m2c_mark_boundary == 1@
/** END code generated by $RCSfile: generic-ctx-get.m2i,v $ $Revision: 1.10.2.1 $ */
@end@
