Logo Search packages:      
Sourcecode: eresi version File versions  Download package

int revm_object_set ( revmexpr_t e1,
revmexpr_t e2 
)

Copy a simply typed object into another one.

Parameters:
o1 Destination object
o2 Source object
Returns:
Success:0 Error:-1

Definition at line 435 of file atomic.c.

References ASPECT_TYPE_BYTE, ASPECT_TYPE_CADDR, ASPECT_TYPE_DADDR, ASPECT_TYPE_HASH, ASPECT_TYPE_INT, ASPECT_TYPE_LIST, ASPECT_TYPE_LONG, ASPECT_TYPE_SHORT, ASPECT_TYPE_STR, s_revm_object::contype, s_revm_object::get_name, s_revm_object::get_obj, s_revm_object::hname, s_revm_object::immed, s_revm_object::immed_val, s_type::isptr, s_revm_object::kname, s_revm_object::otype, s_revm_object::parent, s_revm_object::root, s_revm_object::set_name, s_revm_object::set_obj, s_revm_object::size, s_type::type, and s_revm_expr::value.

{
  revmobj_t       *o1;
  revmobj_t       *o2;
  char                  *str;
  eresi_Addr            val64;
  u_int                 val32;
  u_char                val8;
  u_short               val16;
  hash_t          *hash;
  list_t          *list;

  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);
  o1 = e1->value;
  o2 = e2->value;

  /* Do the real assignation */
  switch (o1->otype->type)
    {
    case ASPECT_TYPE_STR:
      str = (o2->immed ? o2->immed_val.str : o2->get_name(o2->root, o2->parent));
      if (o1->immed)
        {
          o1->immed_val.str = strdup(str);
          o1->size = o2->size;
        }
      else if (o1->hname && (o1->kname || o2->kname))
      {
        if (o1->contype == CONT_HASH)
          revm_hash_set(o1->hname, o1->kname ? o1->kname : o2->kname, str,
                  ASPECT_TYPE_STR);
        else if (o1->contype == CONT_LIST)
          revm_elist_set(o1->hname, o1->kname ? o1->kname : o2->kname, str,
                  ASPECT_TYPE_STR);
      }
      else if (o1->parent == str || !o1->parent)
      o1->parent = (str ? strdup(str) : NULL);
      else if (o1->set_name(o1->root, o1->parent, str) < 0)
      {
        XFREE(__FILE__, __FUNCTION__, __LINE__, str);
        PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                   "Unable to set string variable", -1);
      }
      break;

    case ASPECT_TYPE_BYTE:
      if (o1->otype->isptr)
      goto ptrcopy;
      val8 = (o2->immed ? o2->immed_val.byte : o2->get_obj(o2->parent));
      if (o1->immed)
        o1->immed_val.byte = val8;
      else if (o1->hname && (o1->kname || o2->kname))
      {
        if (o1->contype == CONT_HASH)
          revm_hash_set(o1->hname, o1->kname ? o1->kname : o2->kname, 
                  (void *) (eresi_Addr) val8, ASPECT_TYPE_BYTE);
        else if (o1->contype == CONT_LIST)
          revm_elist_set(o1->hname, o1->kname ? o1->kname : o2->kname, str,
                  ASPECT_TYPE_STR);
      }
      else if (o1->set_obj(o1->parent, val8) < 0)
      PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                 "Unable to set byte variable", -1);
      break;

    case ASPECT_TYPE_SHORT:
      val16 = (o2->immed ? o2->immed_val.half : o2->get_obj(o2->parent));
      if (o1->immed)
      o1->immed_val.half = val16;
      else if (o1->hname && (o1->kname || o2->kname))
      {
        if (o1->contype == CONT_HASH)
          revm_hash_set(o1->hname, o1->kname ? o1->kname : o2->kname, 
                  (void *) (eresi_Addr) val16, ASPECT_TYPE_SHORT);
        else if (o1->contype == CONT_LIST)
          revm_elist_set(o1->hname, o1->kname ? o1->kname : o2->kname, 
                  (void *) (eresi_Addr) val16, ASPECT_TYPE_SHORT);
          
      }
      else if (o1->set_obj(o1->parent, val16) < 0)
      PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                 "Unable to set short variable", -1);
      break;

    case ASPECT_TYPE_INT:
    intcopy:
      val32 = (o2->immed ? o2->immed_val.word : o2->get_obj(o2->parent));
      if (o1->immed)
      o1->immed_val.word = val32;
      else if (o1->hname && (o1->kname || o2->kname))
      {
        if (o1->contype == CONT_HASH)
          revm_hash_set(o1->hname, o1->kname ? o1->kname : o2->kname, 
                  (void *) (eresi_Addr) val32, ASPECT_TYPE_INT);
        else if (o1->contype == CONT_LIST)
          revm_elist_set(o1->hname, o1->kname ? o1->kname : o2->kname, 
                  (void *) (eresi_Addr) val32, ASPECT_TYPE_INT);

      }
      else if (o1->set_obj(o1->parent, val32) < 0)
      PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                 "Unable to set integer variable", -1);
      break;

    case ASPECT_TYPE_LONG:
      if (sizeof(u_long) == 4)
      goto intcopy;
    case ASPECT_TYPE_CADDR:
    case ASPECT_TYPE_DADDR:
    ptrcopy:
      val64 = (o2->immed ? o2->immed_val.ent : o2->get_obj(o2->parent));
      if (o1->immed)
      o1->immed_val.ent = val64;
      else if (o1->hname && (o1->kname || o2->kname))
      {
        if (o1->contype == CONT_HASH)
          revm_hash_set(o1->hname, o1->kname ? o1->kname : o2->kname, 
                    (void *) val64, o1->otype->type);
        else if (o1->contype == CONT_LIST)
          revm_elist_set(o1->hname, o1->kname ? o1->kname : o2->kname, 
                    (void *) val64, o1->otype->type);
        
      }
      else if (o1->set_obj(o1->parent, val64) < 0)
      PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                 "Unable to set long variable", -1);
      break;

    case ASPECT_TYPE_HASH:
      hash = (hash_t *) o2->get_obj(o2->parent);
      if (!o1->otype->isptr)
      {
        if (revm_hash_set(NULL, o1->hname, (void *) hash, o1->otype->type))
          PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                   "Unable to set hash table variable", -1);
        PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
      }
      o1->immed = 1;
      goto ptrcopy;
    case ASPECT_TYPE_LIST:
      list = (list_t *) o2->get_obj(o2->parent);
      if (!o1->otype->isptr)
      {
        if (revm_elist_set(NULL, o1->hname, (void *) list, o1->otype->type))
          PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__, 
                   "Unable to set list variable", -1);
        PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
      }
      o1->immed = 1;
      goto ptrcopy;
    default:
      *o1 = *o2;
    }

  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 0);
}


Generated by  Doxygen 1.6.0   Back to index