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

int revm_type_print ( char *  type,
char  mode 
)

Print a specific type

Parameters:
type 
mode 
Returns:

Definition at line 73 of file typing.c.

References ASPECT_TYPE_RAW, buf, s_type::childs, s_type::dimnbr, s_type::elemnbr, s_type::fieldname, s_type::isptr, s_type::name, s_type::next, s_type::off, revm_output(), s_type::size, and s_type::type.

Referenced by revm_type_print_regex(), and revm_type_prints().

{
  aspectype_t     *cur;
  aspectype_t     *child;
  char            buf[BUFSIZ];
  char            prefix[128];
  int       len;
  char            *size;
  char            offset[128];
  int       idx;
  int       sz;
  char            *pad;

  PROFILER_IN(__FILE__, __FUNCTION__, __LINE__);

  cur = hash_get(&types_hash, type);
  if (!cur)
    PROFILER_ERR(__FILE__, __FUNCTION__, __LINE__,
                  "Unknown type", 0);

  /* Set up things */
  revm_endline();

  /* Setup first part of the line */
  snprintf(prefix, sizeof(prefix), "%s%s%s", 
         revm_colorfieldstr("{"),
         revm_colornumber("%u", cur->size),
         revm_colorfieldstr("}"));
  len = snprintf(buf, sizeof(buf), "  %s %s %-20s %s %-10s",
             revm_colornumber("id:%-10u", cur->type),
             revm_colorfieldstr("Type"),
             revm_colortypestr_fmt("%-20s", type), 
             revm_colorfieldstr("size"),
             prefix);
  size = alloca(20);

  /* If the type is a structure */
  if (cur->childs)
    {
      len += snprintf(buf + len, sizeof(buf) - len, "%s",
                  revm_colorfieldstr(" = {"));
      
      /* Prepare the padding after each field name */
      sz = len - revm_color_size(buf) - 16; /* -16 is dirty: some bug in colors */
      pad = alloca(sz + 1);
      memset(pad, ' ', sz);
      pad[sz] = 0x00;

      /* For each child field type */
      for (child = cur->childs; child; child = child->next)
      {
        
        /* Compute the size field */
        if (child->type == ASPECT_TYPE_RAW)
          snprintf(size, sizeof(size), "%s%s%s", 
                 revm_colorfieldstr("["), 
                 revm_colornumber("%u", child->size), 
                 revm_colorfieldstr("]"));
        else if (child->dimnbr && child->elemnbr)
          {
            for (sz = idx = 0; idx < child->dimnbr; idx++)
            sz += 20;
            size = alloca(sz);
            for (sz = idx = 0; idx < child->dimnbr; idx++)
            sz += sprintf(size + sz, "%s%s%s", 
                        revm_colorfieldstr("["),
                        revm_colornumber("%u", child->elemnbr[idx]),
                        revm_colorfieldstr("]"));
          }
        else
          *size = 0x00;

        /* Format the whole thing */
        if (mode)
          *offset = 0x00;
        else
          snprintf(offset, sizeof(offset), "%s%s", 
                 revm_colornumber("%u", child->off),
                 revm_colorfieldstr(":"));
        len += snprintf(buf + len, sizeof(buf) - len, 
                    "%s%s%s%s%s%s%s", 
                    offset, 
                    revm_colorstr(child->fieldname),
                    revm_colorfieldstr(":"),
                    revm_colortypestr((child->isptr ? "*" : "")), 
                    revm_colortypestr(child->name), 
                    size,
                    revm_colorfieldstr((child->next ? ",\n" : "}\n\n")));
        
        /* Print field and next padding */
        revm_output(buf);
        revm_endline();
        if (child->next)
          revm_output(pad);
        *buf = 0x00;
        len = 0;
      }
    }

  /* Print non-structures types */
  else
    {
      revm_output(buf);
      revm_output("\n");
    }

  /* Return success */
  PROFILER_ROUT(__FILE__, __FUNCTION__, __LINE__, 1);
}


Generated by  Doxygen 1.6.0   Back to index