Example #1
0
be_argument::be_argument
(
   AST_Argument::Direction d,
   AST_Type *ft,
   UTL_ScopedName *n,
   const UTL_Pragmas &p
)
:
   AST_Decl (AST_Decl::NT_argument, n, p),
   AST_Field (AST_Decl::NT_argument, ft, n, p),
   AST_Argument (d, ft, n, p),
   m_beType (0),
   m_direction (d)
{
   AST_Type * at = field_type();
   be_Type * bt;

   if (at && (bt = (be_Type*)at->narrow((long) & be_Type::type_id)))
   {
      const char * typeName = bt->TypeName ();
      if (typeName && strcmp (typeName, "DDS::Any") == 0)
      {
         BE_Globals::inc_any = pbtrue;
      }
   }
}
void fields (tree t)
{
  tree field;
  for (field = TYPE_FIELDS (t) ; field ; field = TREE_CHAIN (field)) {
    //    fprintf(stderr, "%s: member %s\n", "test1", tree_code_name[TREE_CODE(field)]);
    fprintf( code_outputfile,"\tfield(\n");
    name(field);
    tree type = TREE_TYPE (field);
    if (type) {
      field_type(type);
    }
      //DECL_FIELD_CONTEXT
    //   In a FIELD_DECL node, it means that the programmer is permitted to   construct the address of this field.  This is used for aliasing   purposes: see record_component_aliases.
    field_CONSTRUCTOR_BITFIELD_P(t);
    field_DECL_BIT_FIELD(t);
    field_DECL_BIT_FIELD_TYPE(t);
    field_DECL_FCONTEXT(t);
    field_DECL_FIELD_BIT_OFFSET(t);
    field_DECL_FIELD_OFFSET(t);
    field_DECL_INITIAL(t); // enum value
    field_DECL_MODE(t);
    field_DECL_NONADDRESSABLE_P(t);
    field_DECL_OFFSET_ALIGN(t);
    field_DECL_PACKED(t);
    field_DECL_QUALIFIER(t);
    field_DECL_UNSIGNED(t);
    field_DECL_VIRTUAL_P(t); // vtable
    field_TREE_ADDRESSABLE(t);
    field_TREE_READONLY(t);
    fprintf( code_outputfile,"\t0),/*field*/\n");
  }
}// fields
Example #3
0
/*
 * Pretty print single event fields.
 */
static void print_event_field(struct lttng_event_field *field)
{
	if (!field->field_name[0]) {
		return;
	}
	MSG("%sfield: %s (%s)%s", indent8, field->field_name,
		field_type(field), field->nowrite ? " [no write]" : "");
}
Example #4
0
void be_argument::Initialize ()
{
   AST_Type * at = field_type();
   be_Type * bt;

   if (at && (bt = (be_Type*)at->narrow((long) & be_Type::type_id)))
   {
      bt->Initialize ();
   }
}
Example #5
0
be_attribute::be_attribute
(
   idl_bool ro,
   AST_Type *ft,
   UTL_ScopedName *n,
   const UTL_Pragmas &p
)
:
   AST_Decl (AST_Decl::NT_attr, n, p),
   AST_Field (AST_Decl::NT_attr, ft, n, p),
   AST_Attribute (ro, ft, n, p),
   fieldType (0),
   m_getDispatchDone (FALSE),
   m_setDispatchDone (FALSE)
{
   assert(field_type());

   isAtModuleScope(pbfalse);

   if (field_type())
   {
      fieldType =
         (be_DispatchableType*)field_type()->narrow((long) & be_Type::type_id);
      assert(fieldType);
      const char * typeName = fieldType->TypeName ();
      if (typeName && strcmp (typeName, "DDS::Any") == 0)
      {
         BE_Globals::inc_any = pbtrue;
      }
   }
   else
   {
      DDSError((DDS_StdString)"unknown field type for attribute " + LocalName());
   }

   enclosingScope = be_Type::EnclosingScopeString(this);
   setOpKey = (DDS_StdString) "_set_" + LocalName();
   getOpKey = (DDS_StdString) "_get_" + LocalName();
}
Example #6
0
InputParameters
validParams<ElementUOIC>()
{
  InputParameters params = validParams<InitialCondition>();
  params.addRequiredParam<UserObjectName>("element_user_object",
                                          "The ElementUOProvider to be coupled into this IC");

  params.addParam<std::string>("field_name",
                               "The field name to retrieve from the ElementUOProvider");

  MooseEnum field_type("long Real", "long");
  params.addParam<MooseEnum>("field_type", field_type, "The type of field to retrieve");

  return params;
}
Example #7
0
const DDS_StdString&
be_argument::Signature(const DDS_StdString& className)
{
   be_Type * btype = be_Type::_narrow(field_type());

   assert(btype);

   if (btype)
   {
      btype->Initialize();

      VarType paramdir = MakeVarType(direction());
      m_signature = btype->MakeSignature(paramdir, className);
   }

   return m_signature;
}
Example #8
0
static void
show_current_field(WINDOW *win, FORM * form)
{
    FIELD *field;
    FIELDTYPE *type;
    char *buffer;
    int nbuf;
    int field_rows, field_cols, field_max;
    int currow, curcol;

    if (has_colors()) {
	wbkgd(win, (chtype) COLOR_PAIR(1));
    }
    werase(win);
    form_getyx(form, currow, curcol);
    wprintw(win, "Cursor: %d,%d", currow, curcol);
    if (data_ahead(form))
	waddstr(win, " ahead");
    if (data_behind(form))
	waddstr(win, " behind");
    waddch(win, '\n');
    if ((field = current_field(form)) != 0) {
	wprintw(win, "Page %d%s, Field %d/%d%s:",
		form_page(form),
		new_page(field) ? "*" : "",
		field_index(field), field_count(form),
		field_arg(field) ? "(arg)" : "");
	if ((type = field_type(field)) != 0) {
	    if (type == TYPE_ALNUM)
		waddstr(win, "ALNUM");
	    else if (type == TYPE_ALPHA)
		waddstr(win, "ALPHA");
	    else if (type == TYPE_ENUM)
		waddstr(win, "ENUM");
	    else if (type == TYPE_INTEGER)
		waddstr(win, "INTEGER");
#ifdef NCURSES_VERSION
	    else if (type == TYPE_IPV4)
		waddstr(win, "IPV4");
#endif
	    else if (type == TYPE_NUMERIC)
		waddstr(win, "NUMERIC");
	    else if (type == TYPE_REGEXP)
		waddstr(win, "REGEXP");
	    else
		waddstr(win, "other");
	}

	if ((unsigned) field_opts(field) & O_EDIT)
	    waddstr(win, " editable");
	else
	    waddstr(win, " readonly");

	if (field_status(field))
	    waddstr(win, " modified");

	if (dynamic_field_info(field, &field_rows, &field_cols, &field_max)
	    != ERR) {
	    wprintw(win, " size %dx%d (max %d)",
		    field_rows, field_cols, field_max);
	}

	waddch(win, ' ');
	(void) wattrset(win, (int) field_fore(field));
	waddstr(win, "fore");
	wattroff(win, (int) field_fore(field));

	waddch(win, '/');

	(void) wattrset(win, (int) field_back(field));
	waddstr(win, "back");
	wattroff(win, (int) field_back(field));

	wprintw(win, ", pad '%c'",
		field_pad(field));

	waddstr(win, "\n");
	for (nbuf = 0; nbuf <= 2; ++nbuf) {
	    if ((buffer = field_buffer(field, nbuf)) != 0) {
		wprintw(win, "buffer %d:", nbuf);
		(void) wattrset(win, A_REVERSE);
		waddstr(win, buffer);
		wattroff(win, A_REVERSE);
		waddstr(win, "\n");
	    }
	}
    }
    wrefresh(win);
}
Example #9
0
/**
 * Builds a report from database.
 */
struct lmgr_report_t *ListMgr_Report(lmgr_t *p_mgr,
                                     const report_field_descr_t *
                                     report_desc_array,
                                     unsigned int report_descr_count,
                                     const profile_field_descr_t *
                                     profile_descr,
                                     const lmgr_filter_t *p_filter,
                                     const lmgr_iter_opt_t *p_opt)
{
    unsigned int i;
    char attrname[128];
    lmgr_report_t *p_report;
    int rc;
    table_enum query_tab;
    /* supported report fields: ENTRIES, ANNEX_INFO or ACCT */
    bool use_acct_table = false;
    lmgr_iter_opt_t opt = { 0 };
    unsigned int profile_len = 0;
    unsigned int ratio = 0;
    struct field_count fcnt = { 0 };
    GString *req = NULL;
    GString *fields = NULL;
    GString *where = NULL;
    GString *having = NULL;
    GString *group_by = NULL;
    GString *order_by = NULL;
    GString *filter_name = NULL;

    /* check profile argument and increase output array if needed */
    if (profile_descr != NULL) {
        if (profile_descr->attr_index != ATTR_INDEX_size) {
            DisplayLog(LVL_CRIT, LISTMGR_TAG,
                       "Profile on attribute '%s' (index=%u) is not supported",
                       field_name(profile_descr->attr_index),
                       profile_descr->attr_index);
            return NULL;
        }
        profile_len = SZ_PROFIL_COUNT;
        if (profile_descr->range_ratio_len > 0)
            ratio = 1;
    }

    /* allocate a new report structure */
    p_report = (lmgr_report_t *) MemAlloc(sizeof(lmgr_report_t));
    if (!p_report)
        return NULL;

    p_report->p_mgr = p_mgr;

    p_report->result = (struct result *)MemCalloc(report_descr_count
                                                  + profile_len + ratio,
                                                  sizeof(struct result));
    if (!p_report->result)
        goto free_report;

    p_report->result_count = report_descr_count + profile_len + ratio;
    p_report->profile_count = profile_len;
    p_report->ratio_count = ratio;
    if (profile_descr != NULL)
        p_report->profile_attr = ATTR_INDEX_size;

    /* initially, no char * tab allocated */
    p_report->str_tab = NULL;

    if (p_opt)
        opt = *p_opt;

    fields = g_string_new(NULL);
    group_by = g_string_new(NULL);
    order_by = g_string_new(NULL);
    having = g_string_new(NULL);
    where = g_string_new(NULL);

    if (full_acct(report_desc_array, report_descr_count, p_filter)
        && !opt.force_no_acct) {
        listmgr_optimizedstat(p_report, p_mgr, report_descr_count,
                              report_desc_array, profile_descr, fields,
                              group_by, order_by, having, where);
        use_acct_table = true;
    } else {    /* not only ACCT table */

        /* sorting by ratio first */
        if (profile_descr && profile_descr->range_ratio_len > 0) {
            if (profile_descr->attr_index == ATTR_INDEX_size) {
                coma_if_needed(order_by);
                if (profile_descr->range_ratio_sort == SORT_ASC)
                    g_string_append(order_by, "sizeratio ASC");
                else
                    g_string_append(order_by, "sizeratio DESC");
            }
        }

        for (i = 0; i < report_descr_count; i++) {
            /* no field for count or distinct count */
            if (report_desc_array[i].report_type != REPORT_COUNT &&
                report_desc_array[i].report_type != REPORT_COUNT_DISTINCT) {
                /* in what table is this field ? */
                if (is_main_field(report_desc_array[i].attr_index))
                    fcnt.nb_main++;
                else if (is_annex_field(report_desc_array[i].attr_index))
                    fcnt.nb_annex++;
                else {
                    /* Not supported yet */
                    DisplayLog(LVL_CRIT, LISTMGR_TAG,
                               "Error: report on attribute '%s' (index=%u) is not supported (report item #%u).",
                               field_name(report_desc_array[i].attr_index),
                               report_desc_array[i].attr_index, i);
                    rc = DB_NOT_SUPPORTED;
                    goto free_str;
                }
            }

            sprintf(attrname, "attr%u", i);

            /* what kind of stat on this field ? */
            switch (report_desc_array[i].report_type) {
            case REPORT_MIN:
                coma_if_needed(fields);
                g_string_append_printf(fields, "MIN(%s) as %s",
                                       field_str(report_desc_array[i].
                                                 attr_index), attrname);
                p_report->result[i].type =
                    field_type(report_desc_array[i].attr_index);
                break;

            case REPORT_MAX:
                coma_if_needed(fields);
                g_string_append_printf(fields, "MAX(%s) as %s",
                                       field_str(report_desc_array[i].
                                                 attr_index), attrname);
                p_report->result[i].type =
                    field_type(report_desc_array[i].attr_index);
                break;

            case REPORT_AVG:
                coma_if_needed(fields);
                g_string_append_printf(fields, "ROUND(AVG(%s)) as %s",
                                       field_str(report_desc_array[i].
                                                 attr_index), attrname);
                p_report->result[i].type =
                    field_type(report_desc_array[i].attr_index);
                break;

            case REPORT_SUM:
                coma_if_needed(fields);
                g_string_append_printf(fields, "SUM(%s) as %s",
                                       field_str(report_desc_array[i].
                                                 attr_index), attrname);
                p_report->result[i].type =
                    field_type(report_desc_array[i].attr_index);
                break;

            case REPORT_COUNT:
                coma_if_needed(fields);
                g_string_append_printf(fields, "COUNT(*) as %s", attrname);
                p_report->result[i].type = DB_BIGUINT;
                break;

            case REPORT_COUNT_DISTINCT:
                coma_if_needed(fields);
                g_string_append_printf(fields, "COUNT(DISTINCT(%s)) as %s",
                                       field_str(report_desc_array[i].
                                                 attr_index), attrname);
                p_report->result[i].type = DB_BIGUINT;
                break;

            case REPORT_GROUP_BY:
                coma_if_needed(fields);
                g_string_append_printf(fields, "%s as %s",
                                       field_str(report_desc_array[i].
                                                 attr_index), attrname);
                coma_if_needed(group_by);
                g_string_append(group_by, attrname);
                p_report->result[i].type =
                    field_type(report_desc_array[i].attr_index);
                break;
            }

            /* is this field sorted ? */
            append_sort_order(order_by, attrname,
                              report_desc_array[i].sort_flag);

            /* is this field filtered ? */
            listmgr_fieldfilter(p_report, p_mgr, report_desc_array, attrname,
                                having, where, i);

            p_report->result[i].flags =
                field_flag(report_desc_array[i].attr_index);
        }

        /* generate size profile */
        if (profile_descr != NULL) {
            if (profile_descr->attr_index == ATTR_INDEX_size) {
                coma_if_needed(fields);
                g_string_append(fields, "SUM(size=0)");

                for (i = 1; i < SZ_PROFIL_COUNT - 1; i++)
                    g_string_append_printf(fields,
                                           ",SUM(" SZRANGE_FUNC "(size)=%u)",
                                           i - 1);

                g_string_append_printf(fields,
                                       ",SUM(" SZRANGE_FUNC "(size)>=%u)",
                                       SZ_PROFIL_COUNT - 1);

                for (i = 0; i < SZ_PROFIL_COUNT; i++)
                    p_report->result[i + report_descr_count].type = DB_BIGUINT;

                if (profile_descr->range_ratio_len > 0) {
                    /* add ratio field and sort it */
                    coma_if_needed(fields);
                    g_string_append_printf(fields, "SUM(size>=%llu",
                                           SZ_MIN_BY_INDEX(profile_descr->
                                                           range_ratio_start));

                    /* is the last range = 1T->inf ? */
                    if (profile_descr->range_ratio_start +
                        profile_descr->range_ratio_len >= SZ_PROFIL_COUNT)
                        g_string_append(fields, ")");
                    else
                        g_string_append_printf(fields, " and size<%llu)",
                            SZ_MIN_BY_INDEX(profile_descr->range_ratio_start
                                            + profile_descr->range_ratio_len));

                    g_string_append(fields, "/COUNT(*) as sizeratio");
                }
            }
        }
    }

    /* process filter */
    if (!(no_filter(p_filter))) {
        if (full_acct(report_desc_array, report_descr_count, p_filter)
            && !opt.force_no_acct) {
            int filter_acct;

            /* filter on acct fields only */
            filter_acct = filter2str(p_mgr, where, p_filter, T_ACCT,
                               (!GSTRING_EMPTY(where) ? AOF_LEADING_SEP : 0)
                               | AOF_PREFIX);
            if (filter_acct > 0)
                use_acct_table = true;
        } else {
            /* process NAMES filters apart, as with must then join with
             * DISTINCT(id) */
            filter_where(p_mgr, p_filter, &fcnt, where,
                         (!GSTRING_EMPTY(where) ? AOF_LEADING_SEP : 0)
                         | AOF_SKIP_NAME);

            filter_name = g_string_new(NULL);
            fcnt.nb_names =
                filter2str(p_mgr, filter_name, p_filter, T_DNAMES, 0);
        }
    }

    /* start building the whole request */
    req = g_string_new("SELECT ");
    g_string_append_printf(req, "%s FROM ", fields->str);

    /* FROM clause */
    if (use_acct_table) {
        g_string_append(req, ACCT_TABLE);
        query_tab = T_ACCT;
    } else {
        bool distinct;

        filter_from(p_mgr, &fcnt, req, &query_tab, &distinct, AOF_SKIP_NAME);

        if (filter_name != NULL && !GSTRING_EMPTY(filter_name)) {
            g_string_append_printf(req, " INNER JOIN (SELECT DISTINCT(id)"
                                   " FROM " DNAMES_TABLE " WHERE %s) N"
                                   " ON %s.id=N.id", filter_name->str,
                                   table2name(query_tab));
            /* FIXME: what if NAMES is the query tab? */
        }
        /* FIXME: do the same for stripe items */
    }

    /* Build the request */
    if (!GSTRING_EMPTY(where))
        g_string_append_printf(req, " WHERE %s", where->str);

    if (!GSTRING_EMPTY(group_by))
        g_string_append_printf(req, " GROUP BY %s", group_by->str);

    if (!GSTRING_EMPTY(having))
        g_string_append_printf(req, " HAVING %s", having->str);

    if (!GSTRING_EMPTY(order_by))
        g_string_append_printf(req, " ORDER BY %s", order_by->str);

    /* iterator opt */
    if (opt.list_count_max > 0)
        g_string_append_printf(req, " LIMIT %u", opt.list_count_max);

 retry:
    /* execute request (expect that ACCT table does not exists) */
    if (use_acct_table)
        rc = db_exec_sql_quiet(&p_mgr->conn, req->str,
                               &p_report->select_result);
    else
        rc = db_exec_sql(&p_mgr->conn, req->str, &p_report->select_result);

    if (lmgr_delayed_retry(p_mgr, rc))
        goto retry;

    /* if the ACCT table does exist, switch to standard mode */
    if (use_acct_table && (rc == DB_NOT_EXISTS)) {
        lmgr_iter_opt_t new_opt;

        if (p_opt != NULL)
            new_opt = *p_opt;
        else
            new_opt.list_count_max = 0;

        new_opt.force_no_acct = true;

        DisplayLog(LVL_EVENT, LISTMGR_TAG,
                   "No accounting info: switching to standard query mode");

        g_string_free(req, TRUE);
        g_string_free(fields, TRUE);
        g_string_free(group_by, TRUE);
        g_string_free(order_by, TRUE);
        g_string_free(having, TRUE);
        g_string_free(where, TRUE);
        if (filter_name != NULL)
            g_string_free(filter_name, TRUE);

        return ListMgr_Report(p_mgr, report_desc_array, report_descr_count,
                              profile_descr, p_filter, &new_opt);
    }

 free_str:
    /* these are always allocated */
    g_string_free(fields, TRUE);
    g_string_free(group_by, TRUE);
    g_string_free(order_by, TRUE);
    g_string_free(having, TRUE);
    g_string_free(where, TRUE);
    /* these may not be allocated */
    if (req != NULL)
        g_string_free(req, TRUE);
    if (filter_name != NULL)
        g_string_free(filter_name, TRUE);

    if (rc == DB_SUCCESS)
        return p_report;

/* error */
    MemFree(p_report->result);

 free_report:
    MemFree(p_report);
    return NULL;
}   /* ListMgr_Report */
Example #10
0
static void listmgr_optimizedstat(lmgr_report_t *p_report, lmgr_t *p_mgr,
                                  unsigned int report_descr_count,
                                  const report_field_descr_t *
                                  report_desc_array,
                                  const profile_field_descr_t *profile_descr,
                                  GString *fields, GString *group_by,
                                  GString *order_by, GString *having,
                                  GString *where)
{
    int i;

    /* sorting by ratio first */
    if (profile_descr && profile_descr->range_ratio_len > 0) {
        if (profile_descr->attr_index == ATTR_INDEX_size)
            append_sort_order(order_by, "sizeratio",
                              profile_descr->range_ratio_sort);
    }

    for (i = 0; i < report_descr_count; i++) {
        char attrname[128];

        snprintf(attrname, sizeof(attrname), "attr%u", i);

        if ((report_desc_array[i].report_type == REPORT_COUNT)
            || is_acct_pk(report_desc_array[i].attr_index)
            || is_acct_field(report_desc_array[i].attr_index)) {
            switch (report_desc_array[i].report_type) {
            case REPORT_MIN:
            case REPORT_MAX:
                coma_if_needed(fields);
                g_string_append_printf(fields, "NULL as %s", attrname);
                p_report->result[i].type = DB_TEXT;
                break;

            case REPORT_AVG:
                coma_if_needed(fields);
                g_string_append_printf(fields,
                                       "ROUND(SUM(%s)/SUM(" ACCT_FIELD_COUNT
                                       ")) as %s",
                                       field_str(report_desc_array[i].
                                                 attr_index), attrname);
                p_report->result[i].type =
                    field_type(report_desc_array[i].attr_index);
                break;

            case REPORT_SUM:
                coma_if_needed(fields);
                g_string_append_printf(fields, "SUM(%s) as %s",
                                       field_str(report_desc_array[i].
                                                 attr_index), attrname);
                p_report->result[i].type =
                    field_type(report_desc_array[i].attr_index);
                break;

            case REPORT_COUNT:
                coma_if_needed(fields);
                g_string_append_printf(fields,
                                       "SUM(" ACCT_FIELD_COUNT ") as %s",
                                       attrname);
                p_report->result[i].type = DB_BIGUINT;
                break;

            case REPORT_COUNT_DISTINCT:
                coma_if_needed(fields);
                g_string_append_printf(fields, "COUNT(DISTINCT(%s)) as %s",
                                       field_str(report_desc_array[i].
                                                 attr_index), attrname);
                p_report->result[i].type = DB_BIGUINT;
                break;

            case REPORT_GROUP_BY:
                coma_if_needed(fields);
                g_string_append_printf(fields, "%s as %s",
                                       field_str(report_desc_array[i].
                                                 attr_index), attrname);
                coma_if_needed(group_by);
                g_string_append(group_by, attrname);
                p_report->result[i].type =
                    field_type(report_desc_array[i].attr_index);
                break;
            }

            /* is this field sorted ? */
            append_sort_order(order_by, attrname,
                              report_desc_array[i].sort_flag);
        } else {
            coma_if_needed(fields);
            g_string_append_printf(fields, "NULL as %s", attrname);
            p_report->result[i].type = DB_TEXT;
        }

        listmgr_fieldfilter(p_report, p_mgr, report_desc_array, attrname,
                            having, where, i);

        p_report->result[i].flags = field_flag(report_desc_array[i].attr_index);
    }

    if (profile_descr) {
        /* XXX only size profile in managed for now */
        if (profile_descr->attr_index == ATTR_INDEX_size) {
            for (i = 0; i < SZ_PROFIL_COUNT; i++) {
                coma_if_needed(fields);
                g_string_append_printf(fields, "SUM(%s)", sz_field[i]);
                /* count */
                p_report->result[i + report_descr_count].type = DB_BIGUINT;
            }

            if (profile_descr->range_ratio_len > 0) {
                /* add ratio field and sort it */
                coma_if_needed(fields);
                /* case i == 0 */
                g_string_append_printf(fields, "SUM(%s",
                                       sz_field[profile_descr->
                                                range_ratio_start]);
                for (i = 1; i < profile_descr->range_ratio_len; i++) {
                    g_string_append_printf(fields, "+%s",
                                           sz_field[profile_descr->
                                                    range_ratio_start + i]);
                }
                g_string_append(fields,
                                ")/SUM(" ACCT_FIELD_COUNT ") as sizeratio");
            }
        }
    }
}
Example #11
0
int main()
{
	int ch, done;
	ITEM *cur;
	
	/* coreboot data structures */
	lib_get_sysinfo();

	struct cb_cmos_option_table *opttbl = get_system_option_table();

	if (opttbl == NULL) {
		printf("Could not find coreboot option table\n");
		halt();
	}

	/* display initialization */
	initscr();
	keypad(stdscr, TRUE);
	cbreak();
	noecho();
	start_color();
	leaveok(stdscr, TRUE);
	curs_set(1);

	erase();
	box(stdscr, 0, 0);
	mvaddstr(0, 2, "coreboot configuration utility");

	/* prep CMOS layout into libcurses data structures */
	
	/* determine number of options, and maximum option name length */
	int numopts=0;
	int maxlength=0;
	struct cb_cmos_entries *option = first_cmos_entry(opttbl);
	while (option) {
		if ((option->config != 'r') && (strcmp("check_sum", option->name) != 0)) {
			maxlength = max(maxlength, strlen(option->name));
			numopts++;
		}
		option = next_cmos_entry(option);
	}
	if (numopts == 0) {
		printf("NO CMOS OPTIONS FOUND. EXITING!!!");
		return 1;
	}
	FIELD **fields = malloc(sizeof(FIELD*)*(2*numopts+1));
	int i;

	/* walk over options, fetch details */
	option = first_cmos_entry(opttbl);
	for (i=0;i<numopts;i++) {
		while ((option->config == 'r') || (strcmp("check_sum", option->name) == 0)) {
			option = next_cmos_entry(option);
		}
		fields[2*i] = new_field(1, strlen(option->name), i*2, 1, 0, 0);
		set_field_buffer(fields[2*i], 0, option->name);
		field_opts_off(fields[2*i], O_ACTIVE);

		fields[2*i+1] = new_field(1, 40, i*2, maxlength+2, 0, 0);
		char *buf = NULL;
		int fail = get_option_as_string(use_nvram, opttbl, &buf, option->name);
		switch (option->config) {
		case 'h': {
			set_field_type(fields[2*i+1], TYPE_INTEGER, 0, 0, (1<<option->length)-1);
			field_opts_on(fields[2*i+1], O_BLANK);
			break;
			  }
		case 's': {
			set_max_field(fields[2*i+1], option->length/8);
			field_opts_off(fields[2*i+1], O_STATIC);
			break;
			  }
		case 'e': {
			int numvals = 0;
			struct cb_cmos_enums *cmos_enum = first_cmos_enum_of_id(opttbl, option->config_id);

			/* if invalid data in CMOS, set buf to first enum */
			if (fail && cmos_enum) {
				buf = cmos_enum->text;
			}

			while (cmos_enum) {
				numvals++;
				cmos_enum = next_cmos_enum_of_id(cmos_enum, option->config_id);
			}

			char **values = malloc(sizeof(char*)*numvals + 1);
			int cnt = 0;

			cmos_enum = first_cmos_enum_of_id(opttbl, option->config_id);
			while (cmos_enum) {
				values[cnt] = cmos_enum->text;
				cnt++;
				cmos_enum = next_cmos_enum_of_id(cmos_enum, option->config_id);
			}
			values[cnt] = NULL;
			field_opts_off(fields[2*i+1], O_EDIT);
			set_field_type(fields[2*i+1], TYPE_ENUM, values, 1, 1);
			free(values); // copied by set_field_type
			break;
			  }
		default:
			  break;
		}
		if (buf) set_field_buffer(fields[2*i+1], 0, buf);
#if HOSTED
// underline is non-trivial on VGA text
		set_field_back(fields[2*i+1], A_UNDERLINE);
#endif
		field_opts_off(fields[2*i+1], O_BLANK | O_AUTOSKIP | O_NULLOK);

		option = next_cmos_entry(option);
	}
	fields[2*numopts]=NULL;

	FORM *form = new_form(fields);
	int numlines = min(numopts*2, 16);
	WINDOW *w = newwin(numlines+2, 70, 2, 1);
	WINDOW *inner_w = newpad(numopts*2, 68);
	box(w, 0, 0);
	mvwaddstr(w, 0, 2, "Press F1 when done");
	set_form_win(form, w);
	set_form_sub(form, inner_w);
	post_form(form);

	done = 0;
	while(!done) {
		ch=getch();
		if (ch == ERR) continue;
		switch (ch) {
		case KEY_DOWN:
			form_driver(form, REQ_NEXT_FIELD);
			break;
		case KEY_UP:
			form_driver(form, REQ_PREV_FIELD);
			break;
		case KEY_LEFT:
			if (field_type(current_field(form)) == TYPE_ENUM) {
				form_driver(form, REQ_PREV_CHOICE);
			} else {
				form_driver(form, REQ_LEFT_CHAR);
			}
			break;
		case KEY_RIGHT:
			if (field_type(current_field(form)) == TYPE_ENUM) {
				form_driver(form, REQ_NEXT_CHOICE);
			} else {
				form_driver(form, REQ_RIGHT_CHAR);
			}
			break;
		case KEY_BACKSPACE:
		case '\b':
			form_driver(form, REQ_DEL_PREV);
			break;
		case KEY_DC:
			form_driver(form, REQ_DEL_CHAR);
			break;
		case KEY_F(1):
			done=1;
			break;
		default:
			form_driver(form, ch);
			break;
		}
		render_form(form);
	}

	for (i = 0; i < numopts; i++) {
		char *name = field_buffer(fields[2*i], 0);
		char *value = field_buffer(fields[2*i+1], 0);
		char *ptr;
		for (ptr = value + strlen (value) - 1;
		     ptr >= value && *ptr == ' '; ptr--);
		ptr[1] = '\0';
		set_option_from_string(use_nvram, opttbl, value, name);
	}

	unpost_form(form);
	free_form(form);
	touchwin(stdscr);
	refresh();

	endwin();
	/* TODO: reboot */
	halt();
}
Example #12
0
/**
 * Builds a report from database.
 */
struct lmgr_report_t *ListMgr_Report( lmgr_t * p_mgr,
                                      const report_field_descr_t * report_desc_array,
                                      unsigned int report_descr_count,
                                      const profile_field_descr_t * profile_descr,
                                      const lmgr_filter_t * p_filter,
                                      const lmgr_iter_opt_t * p_opt )
{
    unsigned int   i;

    /* A query consists of 5 parts:
     *  - List of fields to be selected
     *  - FROM clause with joins
     *  - WHERE clause (filters)
     *  - GROUP BY clause
     *  - ORBER BY clause
     */
    char           fields[1024] = "";
    char           from[512] = "";
    char           where[2048] = "";
    char           having[2048] = "";
    char           group_by[512] = "";
    char           order_by[512] = "";
    char           query[4096] = "";

    /* filters on NAMES or STRIPE_ITEMS
     * must be managed differently, as they
     * can create duplicates (non uniq id) */
    char           name_filter_str[1024] = "";
    char           stripe_filter_str[1024] = "";

    char          *curr_field = fields;
    char          *curr_group_by = group_by;
    char          *curr_sort = order_by;
    char          *curr_query = query;
    char          *curr_where = where;
    char          *curr_having = having;

    char           attrname[128];
    char           attrstring[1024];

    lmgr_report_t *p_report;
    int            rc;

    table_enum     query_tab;
    /* supported report fields: ENTRIES, ANNEX_INFO or ACCT */
    int            main_table_flag = FALSE;
    int            annex_table_flag = FALSE;
    int            acct_table_flag = FALSE;
    int            filter_main = 0;
    int            filter_annex = 0;
    int            filter_stripe_info = 0;
    int            filter_stripe_items = 0;
    int            filter_names = 0;
    int            filter_acct = 0;
    int            full_acct = TRUE;
    lmgr_iter_opt_t opt = {0};
    unsigned int   profile_len = 0;
    unsigned int   ratio = 0;

    /* check profile argument and increase output array if needed */
    if (profile_descr != NULL)
    {
        if (profile_descr->attr_index != ATTR_INDEX_size)
        {
            DisplayLog(LVL_CRIT, LISTMGR_TAG, "Profile on attribute #%u is not supported",
                       profile_descr->attr_index);
            return NULL;
        }
        profile_len = SZ_PROFIL_COUNT;
        if (profile_descr->range_ratio_len > 0)
            ratio = 1;
    }

    /* allocate a new report structure */
    p_report = ( lmgr_report_t * ) MemAlloc( sizeof( lmgr_report_t ) );
    if ( !p_report )
        return NULL;

    p_report->p_mgr = p_mgr;

    p_report->result_type_array =
        ( db_type_t * ) MemCalloc( report_descr_count + profile_len + ratio,
                                   sizeof( db_type_t ) );
    if ( !p_report->result_type_array )
        goto free_report;

    p_report->result_count = report_descr_count + profile_len + ratio;
    p_report->profile_count = profile_len;
    p_report->ratio_count = ratio;
    if (profile_descr != NULL)
        p_report->profile_attr = ATTR_INDEX_size;

    /* initialy, no char * tab allocated */
    p_report->str_tab = NULL;

    if (p_opt)
        opt = *p_opt;

    for ( i = 0; i < report_descr_count; i++ )
    {
        if ( ( report_desc_array[i].report_type != REPORT_COUNT ) &&
#ifdef ATTR_INDEX_dircount
                report_desc_array[i].attr_index != ATTR_INDEX_dircount &&
#endif
                !is_acct_field( report_desc_array[i].attr_index ) &&
                !is_acct_pk( report_desc_array[i].attr_index ) )
            full_acct = FALSE;
    }
    if ( p_filter )
    {
        if ( p_filter->filter_type == FILTER_SIMPLE )
        {
            for ( i = 0; i < p_filter->filter_simple.filter_count; i++ )
            {
                if ( !is_acct_pk( p_filter->filter_simple.filter_index[i] ) &&
                        !is_acct_field( p_filter->filter_simple.filter_index[i] ) )
                    full_acct = FALSE;
            }
        }
    }

    if ( full_acct && !opt.force_no_acct )
    {
        listmgr_optimizedstat( p_report, p_mgr, report_descr_count, report_desc_array,
                               profile_descr,
                               fields, &curr_field, group_by, &curr_group_by, order_by, &curr_sort,
                               having, &curr_having, where, &curr_where);
        acct_table_flag = TRUE;
    }
    else /* not only ACCT table */
    {
        /* sorting by ratio first */
        if (profile_descr && profile_descr->range_ratio_len > 0)
        {
            if ( profile_descr->attr_index == ATTR_INDEX_size )
            {
                if (profile_descr->range_ratio_sort == SORT_ASC)
                    add_string( order_by, curr_sort, "sizeratio ASC");
                else
                    add_string( order_by, curr_sort, "sizeratio DESC");
            }
        }

        for ( i = 0; i < report_descr_count; i++ )
        {
            /* no field for count or distinct count */
            if ( report_desc_array[i].report_type != REPORT_COUNT &&
                 report_desc_array[i].report_type != REPORT_COUNT_DISTINCT )
            {
                /* in what table is this field ? */
                if ( is_main_field( report_desc_array[i].attr_index ) )
                    main_table_flag = TRUE;
                else if ( is_annex_field( report_desc_array[i].attr_index ) )
                    annex_table_flag = TRUE;
                else
                {
                    /* Not supported yet */
                    DisplayLog( LVL_CRIT, LISTMGR_TAG,
                                "Error: report on attribute #%u is not supported (report item #%u).",
                                report_desc_array[i].attr_index, i );
                    goto free_field_tab;
                }
            }

            sprintf( attrname, "attr%u", i );

            /* what kind of stat on this field ? */
            switch ( report_desc_array[i].report_type )
            {
            case REPORT_MIN:
                sprintf( attrstring, "MIN( %s ) as %s",
                         field_str( report_desc_array[i].attr_index ), attrname );
                add_string( fields, curr_field, attrstring );
                p_report->result_type_array[i] = field_type( report_desc_array[i].attr_index );
                break;
            case REPORT_MAX:
                sprintf( attrstring, "MAX( %s ) as %s",
                         field_str( report_desc_array[i].attr_index ), attrname );
                add_string( fields, curr_field, attrstring );
                p_report->result_type_array[i] = field_type( report_desc_array[i].attr_index );
                break;
            case REPORT_AVG:
                sprintf( attrstring, "ROUND(AVG( %s )) as %s",
                         field_str( report_desc_array[i].attr_index ), attrname );
                add_string( fields, curr_field, attrstring );
                p_report->result_type_array[i] = field_type( report_desc_array[i].attr_index );
                break;
            case REPORT_SUM:
                sprintf( attrstring, "SUM( %s ) as %s",
                         field_str( report_desc_array[i].attr_index ), attrname );
                add_string( fields, curr_field, attrstring );
                p_report->result_type_array[i] = field_type( report_desc_array[i].attr_index );
                break;
            case REPORT_COUNT:
                sprintf( attrstring, "COUNT(*) as %s", attrname );
                add_string( fields, curr_field, attrstring );
                p_report->result_type_array[i] = DB_BIGUINT;
                break;
            case REPORT_COUNT_DISTINCT:
                sprintf( attrstring, "COUNT(DISTINCT(%s)) as %s",
                field_str( report_desc_array[i].attr_index ), attrname );
                add_string( fields, curr_field, attrstring );
                p_report->result_type_array[i] = DB_BIGUINT;
                break;
            case REPORT_GROUP_BY:
                sprintf( attrstring, "%s as %s", field_str( report_desc_array[i].attr_index ),
                         attrname );
                add_string( fields, curr_field, attrstring );
                add_string( group_by, curr_group_by, attrname );
                p_report->result_type_array[i] = field_type( report_desc_array[i].attr_index );
                break;
            }

            /* is this field sorted ? */

            if ( report_desc_array[i].sort_flag == SORT_ASC )
            {
                sprintf( attrstring, "%s ASC", attrname );
                add_string( order_by, curr_sort, attrstring );
            }
            else if ( report_desc_array[i].sort_flag == SORT_DESC )
            {
                sprintf( attrstring, "%s DESC", attrname );
                add_string( order_by, curr_sort, attrstring );
            }

            /* is this field filtered ? */
            listmgr_fieldfilter( p_report, p_mgr, report_desc_array, attrstring, attrname,
                                having, &curr_having, where, &curr_where, i );
        }

        /* generate size profile */
        if (profile_descr != NULL)
        {
            if (profile_descr->attr_index == ATTR_INDEX_size)
            {
                add_string( fields, curr_field, "SUM(size=0)" );
                for (i=1; i < SZ_PROFIL_COUNT-1; i++)
                    curr_field += sprintf(curr_field, ",SUM("ACCT_SZ_VAL("size")"=%u)", i-1);
                curr_field += sprintf(curr_field, ",SUM("ACCT_SZ_VAL("size")">=%u)", i-1);

                for (i=0; i<SZ_PROFIL_COUNT; i++)
                    p_report->result_type_array[i+report_descr_count] = DB_BIGUINT;

                if (profile_descr->range_ratio_len > 0)
                {
                    /* add ratio field and sort it */
                    attrstring[0] = '\0';
                    char *curr_attr = attrstring;

                    curr_attr += sprintf(curr_attr, "SUM(size>=%Lu",
                                         SZ_MIN_BY_INDEX(profile_descr->range_ratio_start));

                    /* is the last range = 1T->inf ? */
                    if (profile_descr->range_ratio_start + profile_descr->range_ratio_len >= SZ_PROFIL_COUNT)
                        curr_attr += sprintf(curr_attr, ")");
                    else
                        curr_attr += sprintf(curr_attr, " and size<%Lu)",
                                         SZ_MIN_BY_INDEX(profile_descr->range_ratio_start+profile_descr->range_ratio_len));

                    curr_attr += sprintf(curr_attr, "/COUNT(*) as sizeratio");
                    add_string( fields, curr_field, attrstring );
                }
            }
        }

    }
    /* filter */

    if ( p_filter )
    {
        if ( ( full_acct && !opt.force_no_acct ) )
        {
            filter_acct = filter2str( p_mgr, curr_where, p_filter, T_ACCT,
                                      ( where != curr_where ), TRUE );
            curr_where += strlen( curr_where );
            if ( filter_acct )
                acct_table_flag =TRUE;
        }
        else
        {
            /* filter on main table? */
            filter_main = filter2str( p_mgr, curr_where, p_filter, T_MAIN,
                                      ( where != curr_where ), TRUE );
            curr_where += strlen( curr_where );

            if ( filter_main )
                main_table_flag = TRUE;

            /* filter on annex table? */
            if ( annex_table )
            {
                filter_annex = filter2str( p_mgr, curr_where, p_filter, T_ANNEX,
                                           (where != curr_where), TRUE );
                curr_where += strlen( curr_where );

                if ( filter_annex )
                    annex_table_flag = TRUE;
            }

            filter_stripe_info =
                filter2str( p_mgr, curr_where, p_filter, T_STRIPE_INFO,
                            (where != curr_where), TRUE );
            curr_where += strlen( curr_where );

           /*  filter on names table is particular as this may duplicate
             * entries when computing the report (multiple hardlinks) */
            filter_names = filter2str(p_mgr, name_filter_str, p_filter, T_DNAMES,
                                      FALSE, FALSE );

           /*  filter on stripe items table is particular as this may duplicate
             * entries when computing the report (multiple stripes) */
            filter_stripe_items = filter2str(p_mgr, stripe_filter_str, p_filter,
                                             T_STRIPE_ITEMS, FALSE, FALSE);
        }
    }

    /* FROM clause */

    if ( acct_table_flag )
    {
        strcpy( from, ACCT_TABLE );
        query_tab = T_ACCT;
    }
    else
    {
        const char * first_table = NULL;
        char * curr_from = from;
        if ( main_table_flag ) {
            strcpy(from, MAIN_TABLE);
            curr_from = from + strlen(from);
            first_table = MAIN_TABLE;
            query_tab = T_MAIN;
        }

        if ( annex_table_flag )
        {
            if (first_table)
                curr_from += sprintf(curr_from, " LEFT JOIN "ANNEX_TABLE" ON %s.id="ANNEX_TABLE".id",
                                     first_table);
            else
            {
                strcpy(from, ANNEX_TABLE);
                curr_from = from + strlen(from);
                first_table = ANNEX_TABLE;
                query_tab = T_ANNEX;
            }
        }
        if ( filter_stripe_info )
        {
            if (first_table)
                curr_from += sprintf(curr_from, " INNER JOIN "STRIPE_INFO_TABLE" ON %s.id="STRIPE_INFO_TABLE".id",
                                     first_table);
            else
            {
                strcpy(from, STRIPE_INFO_TABLE);
                curr_from = from + strlen(from);
                first_table = STRIPE_INFO_TABLE;
                query_tab = T_STRIPE_INFO;
            }
        }
        if (filter_names)
        {
            if (first_table)
                curr_from += sprintf(curr_from," INNER JOIN (SELECT DISTINCT(id)"
                                     " FROM "DNAMES_TABLE" WHERE %s) N"
                                     " ON %s.id=N.id", name_filter_str,
                                     first_table);
            else
            {
                DisplayLog(LVL_CRIT, LISTMGR_TAG, "Unexpected case: "DNAMES_TABLE
                           " table can't be the query table in %s()", __func__);
                goto free_field_tab;
            }
        }

        if (filter_stripe_items)
        {
            if (first_table)
                curr_from += sprintf(curr_from, " INNER JOIN (SELECT DISTINCT(id)"
                                     " FROM "STRIPE_ITEMS_TABLE" WHERE %s) SI"
                                     " ON %s.id=SI.id", stripe_filter_str,
                                     first_table);
            else
            {
                strcpy(from, STRIPE_ITEMS_TABLE);
                curr_from = from + strlen(from);
                strcpy(curr_where, stripe_filter_str);
                curr_where += strlen(curr_where);
                first_table = STRIPE_ITEMS_TABLE;
                query_tab = T_STRIPE_ITEMS;
                /* XXX the caller is supposed to select DISTINCT(id) in this case */
            }
        }
    }

    /* Build the request */

    curr_query += sprintf( query, "SELECT %s FROM %s", fields, from );

    if ( where[0] )
    {
        curr_query += sprintf( curr_query, " WHERE %s", where );
    }

    if ( group_by[0] )
    {
        curr_query += sprintf( curr_query, " GROUP BY %s", group_by );
    }

    if ( having[0] )
    {
        curr_query += sprintf( curr_query, " HAVING %s", having );
    }


    if ( order_by[0] )
    {
        curr_query += sprintf( curr_query, " ORDER BY %s", order_by );
    }

    /* iterator opt */
    if ( opt.list_count_max > 0 )
    {
        curr_query += sprintf( curr_query, " LIMIT %u", opt.list_count_max );
    }


#ifdef _DEBUG_DB
    printf( "Report is specified by: %s\n", query );
#endif

retry:
    /* execute request (expect that ACCT table does not exists) */
    if (acct_table_flag)
        rc = db_exec_sql_quiet( &p_mgr->conn, query, &p_report->select_result );
    else
        rc = db_exec_sql( &p_mgr->conn, query, &p_report->select_result );

    if (lmgr_delayed_retry(p_mgr, rc))
        goto retry;

    /* if the ACCT table does exist, switch to standard mode */
    if ( acct_table_flag && (rc == DB_NOT_EXISTS))
    {
        lmgr_iter_opt_t new_opt;
        if (p_opt != NULL)
            new_opt = *p_opt;
        else
            new_opt.list_count_max = 0;

        new_opt.force_no_acct = TRUE;

        DisplayLog( LVL_EVENT, LISTMGR_TAG, "No accounting info: switching to standard query mode" );

        return ListMgr_Report( p_mgr, report_desc_array, report_descr_count,
                               profile_descr,
                               p_filter, &new_opt );
    }

    if ( rc )
        goto free_field_tab;
    else
        return p_report;

/* error handlers */
  free_field_tab:
    MemFree( p_report->result_type_array );
  free_report:
    MemFree( p_report );
    return NULL;

}                               /* ListMgr_Report */
Example #13
0
static void listmgr_optimizedstat( lmgr_report_t *p_report, lmgr_t * p_mgr,
                                    unsigned int report_descr_count,
                                    const report_field_descr_t *report_desc_array,
                                    const profile_field_descr_t * profile_descr,
                                    char *fields, char **curr_field,
                                    char *group_by, char **curr_group_by,
                                    char *order_by, char **curr_sort,
                                    char *having, char **curr_having,
                                    char *where, char **curr_where )
{
    char           attrstring[1024];
    int            i;
    char           attrname[128];

    /* sorting by ratio first */
    if (profile_descr && profile_descr->range_ratio_len > 0)
    {
        if ( profile_descr->attr_index == ATTR_INDEX_size )
        {
            if (profile_descr->range_ratio_sort == SORT_ASC)
                add_string( order_by, *curr_sort, "sizeratio ASC");
            else
                add_string( order_by, *curr_sort, "sizeratio DESC");
        }
    }

    for ( i = 0; i < report_descr_count; i++ )
    {
        sprintf( attrname, "attr%u", i );
        if( is_acct_pk( report_desc_array[i].attr_index ) || is_acct_field( report_desc_array[i].attr_index )
                            || report_desc_array[i].report_type == REPORT_COUNT )
        {
            switch ( report_desc_array[i].report_type )
            {
            case REPORT_MIN:
                sprintf( attrstring, "NULL as %s", attrname );
                add_string( fields, *curr_field, attrstring );
                p_report->result_type_array[i] = DB_TEXT;
                break;
            case REPORT_MAX:
                sprintf( attrstring, "NULL as %s", attrname );
                add_string( fields, *curr_field, attrstring );
                p_report->result_type_array[i] = DB_TEXT;
                break;
            case REPORT_AVG:
                sprintf( attrstring, "ROUND(SUM(%s)/SUM(" ACCT_FIELD_COUNT ")) as %s",
                         field_str( report_desc_array[i].attr_index ), attrname );
                add_string( fields, *curr_field, attrstring );
                p_report->result_type_array[i] = field_type( report_desc_array[i].attr_index );
                break;
            case REPORT_SUM:
                sprintf( attrstring, "SUM(%s) as %s",
                         field_str( report_desc_array[i].attr_index ), attrname );
                add_string( fields, *curr_field, attrstring );
                p_report->result_type_array[i] = field_type( report_desc_array[i].attr_index );
                break;
            case REPORT_COUNT:
                sprintf( attrstring, "SUM(" ACCT_FIELD_COUNT ") as %s", attrname );
                add_string( fields, *curr_field, attrstring );
                p_report->result_type_array[i] = DB_BIGUINT;
                break;
            case REPORT_COUNT_DISTINCT:
                sprintf(attrstring, "COUNT(DISTINCT(%s)) as %s",
                        field_str( report_desc_array[i].attr_index ), attrname);
                add_string( fields, *curr_field, attrstring );
                p_report->result_type_array[i] = DB_BIGUINT;
                break;
            case REPORT_GROUP_BY:
                sprintf( attrstring, "%s as %s", field_str( report_desc_array[i].attr_index ),
                         attrname );
                add_string( fields, *curr_field, attrstring );
                add_string( group_by, *curr_group_by, attrname );
                p_report->result_type_array[i] = field_type( report_desc_array[i].attr_index );
                break;
            }

            /* is this field sorted ? */

            if ( report_desc_array[i].sort_flag == SORT_ASC )
            {
                sprintf( attrstring, "%s ASC", attrname );
                add_string( order_by, *curr_sort, attrstring );
            }
            else if ( report_desc_array[i].sort_flag == SORT_DESC )
            {
                sprintf( attrstring, "%s DESC", attrname );
                add_string( order_by, *curr_sort, attrstring );
            }
        }
        else
        {
            sprintf( attrstring, "NULL as %s", attrname );
            add_string( fields, *curr_field, attrstring );
            p_report->result_type_array[i] = DB_TEXT;
        }
        listmgr_fieldfilter( p_report, p_mgr, report_desc_array, attrstring, attrname,
                            having, curr_having, where, curr_where, i );
    }
    if (profile_descr)
    {
        /* XXX only size profile in managed for now */
        if (profile_descr->attr_index == ATTR_INDEX_size)
        {
            for (i = 0; i < SZ_PROFIL_COUNT; i++)
            {
                (*curr_field) += sprintf(*curr_field, "%sSUM(%s)", (fields==(*curr_field))?"":",",
                                         sz_field[i]);
                p_report->result_type_array[i+report_descr_count] = DB_BIGUINT; /* count */
            }

            if (profile_descr->range_ratio_len > 0)
            {
                /* add ratio field and sort it */
                attrstring[0] = '\0';
                char *curr_attr = attrstring;
                for (i = 0; i < profile_descr->range_ratio_len; i++)
                {
                    if (attrstring != curr_attr)
                        curr_attr += sprintf(curr_attr, "+%s",
                                        sz_field[profile_descr->range_ratio_start + i]);
                    else
                        curr_attr += sprintf(curr_attr, "SUM(%s",
                                        sz_field[profile_descr->range_ratio_start + i]);
                }
                curr_attr += sprintf(curr_attr, ")/SUM("ACCT_FIELD_COUNT") as sizeratio");
                add_string( fields, *curr_field, attrstring );
            }
        }
    }

}