Exemplo n.º 1
0
void show_stats_t(int y, int x, char *header, stats_t *data, char abbreviate)
{
	if (data -> valid)
	{
		char *cur_str = format_value(data -> cur, 6, 2, abbreviate);
		char *min_str = format_value(data -> min, 6, 2, abbreviate);
		char *avg_str = format_value(data -> avg / (double)data -> n, 6, 2, abbreviate);
		char *max_str = format_value(data -> max, 6, 2, abbreviate);
		char *sd_str  = format_value(calc_sd(data), 6, 2, abbreviate);

		myprintloc(w_stats, y, x, "%s: %s %s %s %s %s", header,
			data -> cur_valid ? cur_str : gettext("   n/a"),
			min_str, avg_str, max_str, sd_str);

		free(sd_str);
		free(max_str);
		free(avg_str);
		free(min_str);
		free(cur_str);
	}
	else
	{
		myprintloc(w_stats, y, x, gettext("%s:    n/a"), header);
	}
}
static char const *
xlsx_write_pivot_cache_definition (XLSXWriteState *state, GsfOutfile *wb_part,
				   GODataCache const *cache, unsigned int cache_def_num)
{
	GsfXMLOut *xml;
	int i, n;
	char const *record_id;
	char *name = g_strdup_printf ("pivotCacheDefinition%u.xml", cache_def_num);
	GsfOutput *cache_def_part = gsf_outfile_new_child_full (state->pivotCache.dir, name, FALSE,
		"content-type", "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml",
		NULL);
	char const *cache_def_id = gsf_outfile_open_pkg_relate (GSF_OUTFILE_OPEN_PKG (cache_def_part),
		GSF_OUTFILE_OPEN_PKG (wb_part),
		"http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition");

	record_id = xlsx_write_pivot_cache_records (state, cache, cache_def_part, cache_def_num);

	xml = gsf_xml_out_new (cache_def_part);

	gsf_xml_out_start_element (xml, "pivotCacheDefinition");
	gsf_xml_out_add_cstr_unchecked (xml, "xmlns", ns_ss);
	gsf_xml_out_add_cstr_unchecked (xml, "xmlns:r", ns_rel);

	gsf_xml_out_add_cstr (xml, "r:id", record_id);
	if (cache->refreshed_by) gsf_xml_out_add_cstr (xml, "refreshedBy", cache->refreshed_by);
	if (cache->refreshed_on) {
		if (state->version == ECMA_376_2006)
			gsf_xml_out_add_float (xml, "refreshedDate", 
					       go_val_as_float (cache->refreshed_on), -1);
		else {
			GOFormat const *format = go_format_new_from_XL ("yyyy-mm-dd\"T\"hh:mm:ss");
			gchar *date = format_value (format, cache->refreshed_on, NULL, -1, NULL);
			gsf_xml_out_add_cstr_unchecked (xml, "refreshedDateIso", date);
			g_free (date);
			go_format_unref (format);
		}		
	}
	gsf_xml_out_add_int (xml, "createdVersion",	cache->XL_created_ver);
	gsf_xml_out_add_int (xml, "refreshedVersion",	cache->XL_refresh_ver);
	gsf_xml_out_add_uint (xml, "recordCount",	go_data_cache_num_items  (cache));
	xlsx_add_bool (xml, "upgradeOnRefresh", cache->refresh_upgrades);
	xlsx_write_pivot_cache_source (state, xml, cache);

	gsf_xml_out_start_element (xml, "cacheFields");
	n = go_data_cache_num_fields (cache);
	gsf_xml_out_add_uint (xml, "count", n);
	for (i = 0 ; i < n ; i++)
		xlsx_write_pivot_cache_field (state, xml, go_data_cache_get_field (cache, i));
	gsf_xml_out_end_element (xml); /* </cacheFields> */

	gsf_xml_out_end_element (xml); /* </pivotCacheDefinition> */

	g_object_unref (xml);
	gsf_output_close (cache_def_part);
	g_object_unref (cache_def_part);
	g_free (name);

	return cache_def_id;
}
Exemplo n.º 3
0
static GnmValue *
cb_collect_unique (GnmValueIter const *iter, UniqueCollection *uc)
{
	GOFormat const *fmt = (NULL != iter->cell_iter)
		? gnm_cell_get_format (iter->cell_iter->cell) : NULL;
	g_hash_table_replace (uc->hash,
		value_dup (iter->v),
		format_value (fmt, iter->v, -1, uc->date_conv));
	return NULL;
}
static void
xlsx_write_date (XLSXWriteState *state, GsfXMLOut *xml,
		 char const *id, gnm_float v)
{
	GOVal *tmp = go_val_new_float (v);
	char *d = format_value (state->date_fmt, tmp, NULL, -1, workbook_date_conv (state->base.wb));
	gsf_xml_out_add_cstr_unchecked (xml, id, d);
	g_free (d);
	go_val_free (tmp);
}
Exemplo n.º 5
0
static char *
try_auto_date (GnmValue *value, const GOFormat *format,
	       GODateConventions const *date_conv)
{
	gnm_float v, vr, vs;
	GOFormat *actual;
	char *res;
	gboolean needs_date, needs_time, needs_frac_sec;
	gboolean is_date;
	int is_time;
	GString *xlfmt;
	GDate date;

	format = gnm_format_specialize (format, value);
	is_date = go_format_is_date (format) > 0;
	is_time = go_format_is_time (format);

	if (!is_date && is_time <= 0)
		return NULL;

	/* We don't want to coerce strings.  */
	if (!VALUE_IS_FLOAT (value))
		return NULL;

	/* Verify that the date is valid.  */
	if (!datetime_value_to_g (&date, value, date_conv))
		return NULL;

	v = value_get_as_float (value);
	vr = gnm_fake_round (v);
	vs = (24 * 60 * 60) * gnm_abs (v - vr);

	needs_date = is_time < 2 && (is_date || gnm_abs (v) >= 1);
	needs_time = is_time > 0 || gnm_abs (v - vr) > 1e-9;
	needs_frac_sec = needs_time && gnm_abs (vs - gnm_fake_round (vs)) >= 0.5e-3;

	xlfmt = g_string_new (NULL);
	if (needs_date) g_string_append (xlfmt, "yyyy/mm/dd");
	if (needs_time) {
		if (needs_date)
			g_string_append_c (xlfmt, ' ');
		if (is_time == 2)
			g_string_append (xlfmt, "[h]:mm:ss");
		else
			g_string_append (xlfmt, "hh:mm:ss");
		if (needs_frac_sec)
			g_string_append (xlfmt, ".000");
	}
	actual = go_format_new_from_XL (xlfmt->str);
	g_string_free (xlfmt, TRUE);
	res = format_value (actual, value, -1, date_conv);
	go_format_unref (actual);

	return res;
}
Exemplo n.º 6
0
/*
 * write_row:
 *
 * @output: the stream
 * @sheet: the gnumeric sheet
 * @row: the row number
 *
 */
static void
write_row (GsfOutput *output, Sheet *sheet, gint row, GnmRange *range)
{
    char const *text = NULL;
    char *formatted_string = NULL;
    GnmCell *cell;
    GnmStyle const *style;

    GODateConventions const *date_conv = sheet->workbook ? workbook_date_conv (sheet->workbook) : NULL;


    gint col;
    for (col = range->start.col; col <= range->end.col; col++) {
        GnmRange const *merge_range;
        GnmCellPos pos;
        pos.col = col;
        pos.row = row;
        merge_range = gnm_sheet_merge_contains_pos  (sheet, &pos);
        if (merge_range != NULL) {
            /* If cell is inside a merged region, we use the
               corner cell of the merged region: */
            cell = sheet_cell_get (sheet, merge_range->start.col, merge_range->start.row);
        } else {
            cell = sheet_cell_get (sheet, col, row);
        }

        if (cell != NULL && cell->value) {
            text = value_peek_string (cell->value);
            pwcsv_print_encoded (output, text);

            style = sheet_style_get (sheet, col, row);
            GOFormat const *format = gnm_style_get_format (style);
            // set col_width to 16-something. This works around gnumeric quirk
            // where, in wider cells, it formats 9,3 as 9,300000000000001
            formatted_string = format_value (format, cell->value, 16, date_conv);
            pwcsv_print_encoded (output, formatted_string);
            html_write_cell_content (output, cell, style, formatted_string);

            g_free (formatted_string);

            /* Without this, we're accumulating lots of heap memory
               on big spreadsheets. */
            gnm_cell_unrender(cell);
        } else {
            gsf_output_puts (output, ",,,");
        }
	}

    gsf_output_puts (output, "\n");
}
Exemplo n.º 7
0
EnumMapper::EnumMapper(const EnumAssoc* m, bool ignore_case)
{
    if (!m)
        return;
    while (m->name) {
        std::string name = m->name;
        if (!val2name.insert(std::pair<int, std::string>(m->value, name)).second)
            throw std::runtime_error("Multiple names for value "+format_value(m->value));
        if (!name2val.insert(std::pair<std::string, int>(ignore_case ? ascii_tolower(name) : name,
                                                         m->value)).second)
            throw std::runtime_error("Multiple values for name '"+name+"'");
        ++m;
    }
}
Exemplo n.º 8
0
static void
compute_slider(Slider s, int *ny, int *vx, int *vy, int *lx, int *ly, int *sx, int *sy, int *hx, int *hy)
{ int hv = (s->show_value == ON ? valInt(getHeightFont(s->value_font)) : 0);
  int hl, hm;

  compute_label_slider(s, vx, &hl);
  hm = max(hl, max(hv, SLIDER_HEIGHT));

  *ny = (hm - hl) / 2;
  *sy = (hm - SLIDER_HEIGHT) / 2;
  *vy = *ly = *hy = (hm - hv) / 2;

  if ( s->show_value == ON )
  { int shw, slw, sh, cw = 4, tw;
    char buf[100];
    string str;

    buf[0] = '[';
    format_value(s, &buf[1], s->high);
    strcat(buf, "]");
    str_set_ascii(&str, buf);
    str_size(&str, s->value_font, &shw, &sh);
    format_value(s, buf, s->low);
    str_set_ascii(&str, buf);
    str_size(&str, s->value_font, &slw, &sh);
    if ( convert_value(s->low) < 0.0 &&
	 (tw = (c_width('-', s->value_font) + slw)) > shw )
      shw = tw;

    *lx = *vx + shw + cw;
    *sx = *lx + slw + cw;
    *hx = *sx + valInt(s->width) + cw;
  } else
  { *lx = *sx = *vx;
    *hx = *sx + valInt(s->width);
  }
}
/*
 *
 * DO * NOT * COMPILE * DIRECTLY *
 * DO * NOT * COMPILE * DIRECTLY *
 * DO * NOT * COMPILE * DIRECTLY *
 *
 * included via xlsx-write.c
 **/
static void
xlsx_write_pivot_val (XLSXWriteState *state, GsfXMLOut *xml,
		      GOVal const *v)
{
	switch (v->type) {
	case VALUE_CELLRANGE:
	case VALUE_ARRAY:
		g_warning ("REMOVE THIS CODE WHEN WE MOVE TO GOFFICE");
		break;

	case VALUE_EMPTY:
		gsf_xml_out_simple_element (xml, "m", NULL);
		break;

	case VALUE_BOOLEAN:
		gsf_xml_out_start_element (xml, "b");
		xlsx_add_bool (xml, "v", v->v_bool.val);
		gsf_xml_out_end_element (xml);
		break;

	case VALUE_FLOAT: {
		GOFormat const *fmt = go_val_get_fmt (v);
		if (NULL != fmt && go_format_is_date (fmt)) {
			char *d = format_value (state->date_fmt, v, NULL, -1, workbook_date_conv (state->base.wb));
			gsf_xml_out_start_element (xml, "d");
			gsf_xml_out_add_cstr_unchecked (xml, "v", d);
			gsf_xml_out_end_element (xml);
		} else {
			gsf_xml_out_start_element (xml, "n");
			gsf_xml_out_add_float (xml, "v", v->v_float.val, -1);
			gsf_xml_out_end_element (xml);
		}
		break;
	}

	case VALUE_ERROR :
		gsf_xml_out_start_element (xml, "e");
		gsf_xml_out_add_cstr (xml, "v", v->v_err.mesg->str);
		gsf_xml_out_end_element (xml);
		break;

	case VALUE_STRING :
		gsf_xml_out_start_element (xml, "s");
		gsf_xml_out_add_cstr (xml, "v", v->v_str.val->str);
		gsf_xml_out_end_element (xml);
		break;
	}
}
Exemplo n.º 10
0
static void
print_rusage(struct kinfo_proc *kipp)
{
	long *lp;
	unsigned int i;
	char *field, *threadid;

	print_prefix(kipp);
	xo_emit("{d:resource/%-14s} {d:usage/%29s}{P:   }\n", "user time",
	    format_time(&kipp->ki_rusage.ru_utime));
	print_prefix(kipp);
	xo_emit("{d:resource/%-14s} {d:usage/%29s}{P:   }\n", "system time",
	    format_time(&kipp->ki_rusage.ru_stime));

	if (Hflag) {
		asprintf(&threadid, "%d", kipp->ki_tid);
		if (threadid == NULL)
			xo_errc(1, ENOMEM,
			    "Failed to allocate memory in print_rusage()");
		xo_open_container(threadid);
		xo_emit("{e:thread_id/%d}", kipp->ki_tid);
	} else {
		xo_emit("{e:process_id/%d}", kipp->ki_pid);
		xo_emit("{e:command/%s}", kipp->ki_comm);
	}
	xo_emit("{e:user time/%s}", format_time(&kipp->ki_rusage.ru_utime));
	xo_emit("{e:system time/%s}", format_time(&kipp->ki_rusage.ru_stime));

	lp = &kipp->ki_rusage.ru_maxrss;
	for (i = 0; i < nitems(rusage_info); i++) {
		print_prefix(kipp);
		asprintf(&field, "{e:%s/%%D}", rusage_info[i].ri_name);
		if (field == NULL)
			xo_errc(1, ENOMEM,
			    "Failed to allocate memory in print_rusage()");
		xo_emit(field, *lp);
		free(field);
		xo_emit("{d:resource/%-32s} {d:usage/%14s}\n",
		    rusage_info[i].ri_name,
		    format_value(*lp, rusage_info[i].ri_humanize,
		    rusage_info[i].ri_scale));
		lp++;
	}
	if (Hflag) {
		xo_close_container(threadid);
		free(threadid);
	}
}
Exemplo n.º 11
0
static GnmValue *
cb_collect_content (GnmCellIter const *iter, UniqueCollection *uc)
{
	GnmCell const *cell = (iter->pp.sheet == uc->src_sheet) ? iter->cell
		: sheet_cell_get (uc->src_sheet,
			iter->pp.eval.col, iter->pp.eval.row);

	if (gnm_cell_is_blank (cell))
		uc->has_blank = TRUE;
	else {
		GOFormat const *fmt = gnm_cell_get_format (cell);
		GnmValue const *v   = cell->value;
		g_hash_table_replace (uc->hash,
			value_dup (v),
			format_value (fmt, v, -1, uc->date_conv));
	}

	return NULL;
}
Exemplo n.º 12
0
static char *
try_auto_float (GnmValue *value, const GOFormat *format,
	       GODateConventions const *date_conv)
{
	gboolean is_date;
	int is_time;

	if (!VALUE_IS_FLOAT (value))
		return NULL;

	format = gnm_format_specialize (format, value);
	is_date = go_format_is_date (format) > 0;
	is_time = go_format_is_time (format);

	if (is_date || is_time > 0)
		return NULL;

	return format_value (go_format_general (), value, -1, date_conv);
}
Exemplo n.º 13
0
int main(int argc, char *argv[])
{
  char *typearg;
  char *valarg;
  struct t_value value;
  int type = -1;
  int i;
  
  if (argc < 3) {
    fprintf(stderr, "Usage: format_value TYPE VALUE\n");
    exit(2);
  }
  
  typearg = argv[1];
  for (i=0; i < value_types_len; i++) {
    if (strcmp(typearg, value_types[i]) == 0) {
      type = i;
      break;
    }
  }
  
  if (type < 0) {
    fprintf(stderr, "Unknown type: %s\n", typearg);
    exit(2);
  }
  
  valarg = argv[2];
  value_init(&value, type);
  if (type == VAL_INT) {
    value.intval = atoi(valarg);
  }
  else if (type == VAL_STRING) {
    value.stringval = valarg;
    value.len = strlen(valarg);
  }
  else {
    fprintf(stderr, "format_value does not support VAL_%s\n", typearg);
    exit(2);
  }
  printf("value: %s\n", format_value(&value));
  
  exit(0);
}
Exemplo n.º 14
0
/*
 * Figure out whether the format engine in goffice allows negative values
 * or (as XL) considers them errors.
 */
gboolean
gnm_datetime_allow_negative (void)
{
	static int allow = -1;

	if (allow == -1) {
		GOFormat *fmt = go_format_new_from_XL ("yyyy-mm-dd");
		GnmValue *v = value_new_int (-42);
		GODateConventions const *conv =
			go_date_conv_from_str ("Lotus:1900");
		char *text = format_value (fmt, v, NULL, -1, conv);

		allow = (strcmp (text, "1899-11-19") == 0);

		value_release (v);
		go_format_unref (fmt);
		g_free (text);
	}

	return (gboolean)allow;
}
Exemplo n.º 15
0
static void
print_rusage(struct kinfo_proc *kipp)
{
	long *lp;
	unsigned int i;

	print_prefix(kipp);
	printf("%-14s %32s\n", "user time",
	    format_time(&kipp->ki_rusage.ru_utime));
	print_prefix(kipp);
	printf("%-14s %32s\n", "system time",
	    format_time(&kipp->ki_rusage.ru_stime));
	lp = &kipp->ki_rusage.ru_maxrss;
	for (i = 0; i < nitems(rusage_info); i++) {
		print_prefix(kipp);
		printf("%-32s %14s\n", rusage_info[i].ri_name,
		    format_value(*lp, rusage_info[i].ri_humanize,
			rusage_info[i].ri_scale));
		lp++;
	}
}
Exemplo n.º 16
0
static GnmValue *
cb_get_content (GnmCellIter const *iter, GsfOutput *buf)
{
	GnmCell *cell;

	if (NULL != (cell = iter->cell)) {
		char *tmp;
		if (gnm_cell_has_expr (cell))
			tmp = gnm_expr_top_as_string (cell->base.texpr,
				&iter->pp, iter->pp.sheet->convs);
		else if (VALUE_FMT (cell->value) != NULL)
			tmp = format_value (NULL, cell->value, -1,
				workbook_date_conv (iter->pp.wb));
		else
			tmp = value_get_as_string (cell->value);

		gsf_output_write (buf, strlen (tmp), tmp);
		g_free (tmp);
	}
	gsf_output_write (buf, 1, "\n");

	return NULL;
}
Exemplo n.º 17
0
GString *
format_ipv (guint id, guint pos, guint val)
{
    GString *buf = g_string_sized_new(1);
    GString *vec_buf = g_string_sized_new(1);
    XmlSettings *xml = get_xml_settings(id, pos);
    GString *val_buf;

    if (!xml) {
        g_warning("Failed to find xml settings for position %d id %d.",
                   id, pos);
        g_string_printf(buf, "%s", "error");
        return buf;
    }
    val_buf = format_value(xml, val);

    g_string_printf(vec_buf, "(%d, %d, %d)", pos, id, val);
    g_string_printf(buf, "%-16s %s: %s: %s",
                          vec_buf->str,
                          get_position(pos), xml->label, val_buf->str);
    g_string_free(vec_buf, TRUE);
    g_string_free(val_buf, TRUE);
    return buf;
}
Exemplo n.º 18
0
/**
 * cb_dialog_apply_clicked:
 * @button:
 * @state:
 *
 * Close (destroy) the dialog
 **/
static void
cb_dialog_apply_clicked (G_GNUC_UNUSED GtkWidget *button,
			 GoalSeekState *state)
{
	char *status_str;
	GoalSeekStatus status;
	GnmValue *target;
	GnmRangeRef const *r;
	GOFormat *format;

	if (state->warning_dialog != NULL)
		gtk_widget_destroy (state->warning_dialog);

	/* set up source */
	target = gnm_expr_entry_parse_as_value (state->set_cell_entry,
						state->sheet);
	if (target == NULL) {
		go_gtk_notice_nonmodal_dialog (GTK_WINDOW(state->dialog),
					  &(state->warning_dialog),
					  GTK_MESSAGE_ERROR,
					  _("You should introduce a valid cell "
					    "name in 'Set Cell:'!"));
		gnm_expr_entry_grab_focus (state->set_cell_entry, TRUE);
		return;
	}
	r = &target->v_range.cell;
	state->set_cell = sheet_cell_get (r->a.sheet, r->a.col, r->a.row);
	value_release (target);
	if (state->set_cell == NULL || !gnm_cell_has_expr (state->set_cell)) {
		go_gtk_notice_nonmodal_dialog (GTK_WINDOW(state->dialog),
					  &(state->warning_dialog),
					  GTK_MESSAGE_ERROR,
					  _("The cell named in 'Set Cell:' "
					    "must contain a formula!"));
		gnm_expr_entry_grab_focus (state->set_cell_entry, TRUE);
		return;
	}

	/* set up source */
	target = gnm_expr_entry_parse_as_value (state->change_cell_entry,
						state->sheet);
	if (target == NULL) {
		go_gtk_notice_nonmodal_dialog (GTK_WINDOW(state->dialog),
					  &(state->warning_dialog),
					  GTK_MESSAGE_ERROR,
					  _("You should introduce a valid cell "
					    "name in 'By Changing Cell:'!"));
		gnm_expr_entry_grab_focus (state->change_cell_entry, TRUE);
		return;
	}

	r = &target->v_range.cell;
	state->change_cell = sheet_cell_fetch (r->a.sheet, r->a.col, r->a.row);
	value_release (target);
	if (gnm_cell_has_expr (state->change_cell)) {
		go_gtk_notice_nonmodal_dialog (GTK_WINDOW(state->dialog),
					  &(state->warning_dialog),
					  GTK_MESSAGE_ERROR,
					  _("The cell named in 'By changing cell' "
					    "must not contain a formula."));
		gnm_expr_entry_grab_focus (state->change_cell_entry, TRUE);
		return;
	}


	format = gnm_style_get_format (gnm_cell_get_style (state->set_cell));
	if (entry_to_float_with_format (GTK_ENTRY(state->to_value_entry),
					&state->target_value, TRUE, format)){
		go_gtk_notice_nonmodal_dialog (GTK_WINDOW(state->dialog),
					  &(state->warning_dialog),
					  GTK_MESSAGE_ERROR,
					  _("The value given in 'To Value:' "
					    "is not valid."));
		focus_on_entry (GTK_ENTRY(state->to_value_entry));
		return;
	}

	format = gnm_style_get_format (gnm_cell_get_style (state->change_cell));
	if (entry_to_float_with_format (GTK_ENTRY(state->at_least_entry),
					 &state->xmin, TRUE, format)) {
		state->xmin = -max_range_val;
		gtk_entry_set_text (GTK_ENTRY (state->at_least_entry), "");
	}

	if (entry_to_float_with_format (GTK_ENTRY(state->at_most_entry), &state->xmax,
					TRUE, format)) {
		state->xmax = +max_range_val;
		gtk_entry_set_text (GTK_ENTRY (state->at_most_entry), "");
	}

	if ((state->old_cell != NULL) && (state->old_value != NULL)) {
		sheet_cell_set_value (state->old_cell, state->old_value);
		workbook_recalc (state->wb);
		state->old_value = NULL;
	}
	state->old_cell = state->change_cell;
	state->old_value = value_dup (state->change_cell->value);

	status = gnumeric_goal_seek (state);

	switch (status) {
	case GOAL_SEEK_OK: {
		const char *actual_str;
		const char *solution_str;
		GOFormat *format = go_format_general ();
		GnmValue *error_value = value_new_float (state->target_value -
						      value_get_as_float (state->set_cell->value));
		char *target_str = format_value (format, error_value, NULL, -1,
						 workbook_date_conv (state->wb));
		gtk_label_set_text (GTK_LABEL (state->target_value_label), target_str);
		g_free (target_str);
		value_release (error_value);

		status_str =
			g_strdup_printf (_("Goal seeking with cell %s found a solution."),
					 cell_name (state->set_cell));
		gtk_label_set_text (GTK_LABEL (state->result_label), status_str);
		g_free (status_str);

		/* FIXME?  Do a format?  */
		actual_str = state->set_cell->value
			? value_peek_string (state->set_cell->value)
			: "";
		gtk_label_set_text (GTK_LABEL (state->current_value_label), actual_str);

		solution_str = state->change_cell->value
			? value_peek_string (state->change_cell->value)
			: "";
		gtk_label_set_text (GTK_LABEL (state->solution_label), solution_str);

		break;
	}

	default:
		status_str =
			g_strdup_printf (_("Goal seeking with cell %s did not find a solution."),
					 cell_name (state->set_cell));
		gtk_label_set_text (GTK_LABEL (state->result_label), status_str);
		g_free (status_str);
		gtk_label_set_text (GTK_LABEL (state->current_value_label), "");
		gtk_label_set_text (GTK_LABEL (state->solution_label), "");
		gtk_label_set_text (GTK_LABEL (state->target_value_label), "");
		break;
	}
	state->cancelled = FALSE;

	gtk_widget_show (state->result_table);
	return;
}
Exemplo n.º 19
0
Arquivo: exec.c Projeto: moxley/parse1
struct t_value * exec_i_fcall(struct t_exec *exec, struct t_icode *fcall)
{
  struct list a, args;
  int i;
  struct t_value *ret = &nullvalue;
  struct t_func * func;
  struct t_value *opnd;
  struct item *item;
  int current_addr;
  int offset;

  debug(3, "%s(): Stack size at line %d: %d\n", __FUNCTION__, __LINE__, exec->stack.size);
  debug(3, "%s(): Top of stack at line %d: %s\n", __FUNCTION__, __LINE__, format_value(list_last(&exec->stack)));

  func = exec_funcbyname(exec, fcall->operand->name);
  if (!func) {
    fprintf(stderr, "Error: Function %s() is not defined, on Line %d.\n", fcall->operand->name, fcall->token->row+1);
    return NULL;
  }

  /* Prepare the arguments */
  list_init(&a);
  list_init(&args);
  for (i=0; i < fcall->operand->argc; i++) {
    list_push(&a, list_pop(&exec->stack));
  }
  for (i=0; i < fcall->operand->argc; i++) {
    list_push(&args, list_pop(&a));
  }

  if (func->invoke) {
    DBG(2, "Calling C function");
    ret = calloc(1, sizeof(struct t_value));
    list_push(&exec->values, ret);
    if (func->invoke(func, &args, ret) < 0) {
      fprintf(stderr, "(TODO) Error in native function: %s()\n", func->name);
      return NULL;
    }
    list_push(&exec->stack, ret);
  }
  else {
    DBG(2, "Calling local function");

    // Calculate the offset
    offset = 0;
    item = exec->parser.output.first;
    printf("func start: %d\n", func->start);
    current_addr = 0;
    while (item != exec->current) {
      item = item->next;
      current_addr++;
      if (item == exec->current) {
        printf("Found current\n");
      }
    }
    offset = (func->start + 1) - current_addr;

    opnd = create_num_from_int(offset);
    list_push(&exec->stack, opnd);
    exec_i_jst(exec, NULL);
  }
  
  return ret;
}
Exemplo n.º 20
0
string format_value(const DistributedType *dtype, const string &packed)
{
    ostringstream ss;
    format_value(dtype, packed, ss);
    return ss.str();
}
Exemplo n.º 21
0
		void base_node_state::on_list(clsm::ev_cmd< list_cmd > const& cmd)
		{
			auto const& editor = context< paramtree_editor >();
			auto acc = editor.acc;

			qualified_path path;
			param_tree::param_data pd;
			if(cmd.nav)
			{
				path = nav_cmd_path(*cmd.nav);
				if(!path)
				{
					return;// todo: false;
				}
				pd = acc.find_param(path);
			}
			else
			{
				path = acc.where();
				pd = acc.param_here();
			}

			auto node = acc.node_at(path);

			unsigned int depth = 0;
			unsigned int max_depth = cmd.depth ? cmd.depth->value : 1u;
			unsigned int indent = 0;

			auto pre_op = [&](param_tree::tree_t::node_descriptor n)
			{
				if(depth <= max_depth)
				{
					auto& pt = editor.ptree;
					auto& tree = pt.tree();

					std::stringstream output;

					for(unsigned int i = 0; i < indent; ++i)
					{
						output << " ";
					}

					auto sibling_idx = tree.position_in_siblings(n);
					if(depth == 1)
					{
						// Index immediate children
						output << (sibling_idx + 1) << ". ";

						indent += 3;
					}

					output << tree[n].name;

					auto in = tree.in_edge(n).first;
					if(tree[in].repeat_idx)
					{
						output << " /" << (sibling_idx + 1);
					}

					output << ": ";
					if(is_leaf_type(tree[n].type))
					{
						output << format_value(*tree[n].value);
					}

					if(cmd.type_info)
					{
						output << " ";
						output << format_type_info(tree[n]);
						output << " ";
						auto path = pt.node_qpath(n);
						auto acc_copy = acc;
						acc_copy.move_to(path);
						output << format_constraints((*editor.provider)[path.unindexed()](acc_copy));
					}

					editor.output(output.str());
				}
				++depth;
				indent += 2;
			};

			auto post_op = [&](param_tree::tree_t::node_descriptor n)
			{
				--depth;
				indent -= 2;
				if(depth == 1)
				{
					indent -= 3;
				}
			};

			wb::gtree::depth_first_traversal(
				editor.ptree.tree(),
				node,
				pre_op,
				wb::gtree::null_op{},
				post_op
				);
		}
Exemplo n.º 22
0
static void format_northing(double north, char *buf, int projection)
{
    format_value(G_format_northing, north, buf, projection);
}
Exemplo n.º 23
0
void update_stats(stats_t *resolve, stats_t *connect, stats_t *request, stats_t *total, stats_t *ssl_setup, int n_ok, int n_fail, const char *last_connect_str, const char *fp, char use_tfo, char dg, stats_t *st_to, stats_t *tcp_rtt_stats, int re_tx, int pmtu, int tos, stats_t *close_st, stats_t *t_write, int n_cookies, char abbreviate, stats_t *stats_header_size)
{
	double k = 0.0;
	char force_redraw = 0;
	struct pollfd p = { 0, POLLIN, 0 };

	werase(w_stats);

	if (n_ok)
	{
		char buffer[4096] = { 0 }, *scc_str = NULL, *kalman_str = NULL;
		int buflen = 0;

		myprintloc(w_stats, 0, 0, "         %6s %6s %6s %6s %6s", gettext("latest"), gettext("min"), gettext("avg"), gettext("max"), gettext("sd"));
		show_stats_t(1, 0, gettext("resolve"), resolve,   abbreviate);
		show_stats_t(2, 0, gettext("connect"), connect,   abbreviate);
		show_stats_t(3, 0, gettext("ssl    "), ssl_setup, abbreviate);
		show_stats_t(4, 0, gettext("send   "), t_write,   abbreviate);
		show_stats_t(5, 0, gettext("request"), request,   abbreviate);
		show_stats_t(6, 0, gettext("close  "), close_st,  abbreviate);
		show_stats_t(7, 0, gettext("total  "), total,     abbreviate);

		scc_str    = format_value(get_cur_scc(), 5, 3, abbreviate);
		kalman_str = format_value(kalman_do(total -> cur), 5, 3, abbreviate);
		myprintloc(w_stats, 8, 0, gettext("ok: %3d, fail: %3d%s, scc: %s, kalman: %s"), n_ok, n_fail, use_tfo ? gettext(", with TFO") : "", scc_str, kalman_str);
		free(kalman_str);
		free(scc_str);

		if (max_x >= 44 * 2 + 1)
		{
			double trend = calc_trend();
			char trend_dir = ' ';

			myprintloc(w_stats, 0, 45, "         %6s %6s %6s %6s %6s", gettext("cur"), gettext("min"), gettext("avg"), gettext("max"), gettext("sd"));
			show_stats_t(1, 45, gettext("t offst"), st_to, abbreviate);

#if defined(linux) || defined(__FreeBSD__)
			show_stats_t(2, 45, gettext("tcp rtt"), tcp_rtt_stats, abbreviate);
#endif
			show_stats_t(3, 45, gettext("headers"), stats_header_size, abbreviate);

			if (trend < 0)
				trend_dir = '-';
			else if (trend > 0)
				trend_dir = '+';

			myprintloc(w_stats, 8, 48, gettext("# cookies: %d"), n_cookies);

#ifdef linux
			myprintloc(w_stats, 9, 48, gettext("trend: %c%6.2f%%, re-tx: %2d, pmtu: %5d, TOS: %02x"), trend_dir, fabs(trend), re_tx, pmtu, tos);
#else
			myprintloc(w_stats, 9, 48, gettext("trend: %c%6.2f%%, TOS: %02x"), trend_dir, fabs(trend), tos);
#endif
		}

		buflen = snprintf(buffer, sizeof buffer, gettext("HTTP rc: %s, SSL fp: %s"), last_connect_str, fp ? fp : gettext("n/a"));

		if (buflen <= max_x)
			myprintloc(w_stats, 9, 0, "%s", buffer);
		else
		{
			static char prev_sf[48] = { 0 };

			myprintloc(w_stats, 9, 0, gettext("http result code: %s"), last_connect_str);

			if (fp && strcmp(prev_sf, fp))
			{
				slow_log(gettext("\nSSL fingerprint: %s"), fp);

				memcpy(prev_sf, fp, 47);
			}
		}
	}

	memmove(&history[1], &history[0], (history_n - 1) * sizeof(double));
	memmove(&history_set[1], &history_set[0], (history_n - 1) * sizeof(char));

	history[0]= total -> cur;
	history_set[0] = 1;

	if (poll(&p, 1, 0) == 1 && p.revents == POLLIN)
	{
		int c = getch();

		if (c == 12) /* ^L */
			force_redraw = 1;

		if (c == 'H')
			pause_graphs = !pause_graphs;

		if (c == 'q')
			stop = 1;
	}

	if (dg && !pause_graphs)
	{
		draw_graph(k);
#ifdef FW
		draw_fft();
#endif
	}

	wnoutrefresh(w_stats);

	if (win_resize || force_redraw)
		recreate_terminal();
}
Exemplo n.º 24
0
static status
RedrawAreaSlider(Slider s, Area a)
{ int x, y, w, h;
  int ny, vx, vy, lx, ly, sx, sy, hx, hy;
  int vv;
  int bw = (s->look == NAME_x ? BAR_WIDTH : OL_BOX_WIDTH);
  float lv = convert_value(s->low);
  float hv = convert_value(s->high);
  float dv = convert_value(s->displayed_value);
  int lflags = (s->active == ON ? 0 : LABEL_INACTIVE);

  if ( dv < lv )
    dv = lv;
  else if ( dv > hv )
    dv = hv;

  if ( hv > lv )
    vv = rfloat(((float) (valInt(s->width) - bw) * (dv - lv)) / (hv - lv));
  else
    vv = 0;

  initialiseDeviceGraphical(s, &x, &y, &w, &h);
  NormaliseArea(x, y, w, h);
  r_thickness(valInt(s->pen));
  r_dash(s->texture);

  compute_slider(s, &ny, &vx, &vy, &lx, &ly, &sx, &sy, &hx, &hy);
  r_clear(x, y, w, h);

  if ( s->show_label == ON )
  { int ex = valInt(getExFont(s->label_font));

    RedrawLabelDialogItem(s,
			  accelerator_code(s->accelerator),
			  x, y+ny, vx-ex, 0,
			  s->label_format, NAME_top,
			  lflags);
  }

  if ( s->look == NAME_motif )
  { int by = y+sy+(SLIDER_HEIGHT-OL_BAR_HEIGHT)/2;
    int ex  = x + sx + valInt(s->width);
    Elevation z = getClassVariableValueObject(s, NAME_elevation);

    r_3d_box(x+sx, by, vv, OL_BAR_HEIGHT, 0, z, FALSE);
    r_3d_box(x+sx+vv+bw, by, ex-(x+sx+vv+bw), OL_BAR_HEIGHT, 0, z, FALSE);
    r_3d_box(x+sx+vv, y+sy, bw, SLIDER_HEIGHT, 0, z, TRUE);
  } else if ( s->look == NAME_openLook )
  { int by = y+sy+(SLIDER_HEIGHT-OL_BAR_HEIGHT)/2;
    int ly2 = by+OL_BAR_HEIGHT-1;
    int ex  = x + sx + valInt(s->width);

    r_fill(x+sx, by+1, 1, OL_BAR_HEIGHT-2, BLACK_IMAGE);
    r_fill(x+sx+1, by, vv-2, OL_BAR_HEIGHT, BLACK_IMAGE);
    r_line(x+sx+1+vv+bw, by, ex-2, by);
    r_line(x+sx+1+vv+bw, ly2, ex-2, ly2);
    r_line(ex-1, by+1, ex-1, ly2-1);
    r_shadow_box(x+sx+vv, y+sy, bw, SLIDER_HEIGHT, 0, 1, NIL);
  } else
  { r_fill(x+sx, y+sy, vv, SLIDER_HEIGHT, GREY50_IMAGE);
    r_box(x+sx, y+sy, valInt(s->width), SLIDER_HEIGHT, 0, NIL);
    r_fill(x+sx+vv, y+sy, bw, SLIDER_HEIGHT, BLACK_IMAGE);
  }

  if ( s->show_value == ON )
  { char buf[100];
    string str;

    buf[0] = '[';
    format_value(s, &buf[1], s->displayed_value);
    strcat(buf, "]");
    str_set_ascii(&str, buf);
    str_label(&str, 0, s->value_font,
	      x+vx, y+vy, 0, 0, NAME_left, NAME_top, lflags);
    format_value(s, buf, s->low);
    str_set_ascii(&str, buf);
    str_label(&str, 0, s->value_font,
	      x+lx, y+ly, 0, 0, NAME_left, NAME_top, lflags);
    format_value(s, buf, s->high);
    str_set_ascii(&str, buf);
    str_label(&str, 0, s->value_font,
	      x+hx, y+hy, 0, 0, NAME_left, NAME_top, lflags);
  }

  return RedrawAreaGraphical(s, a);
}
Exemplo n.º 25
0
static void format_resolution(double res, char *buf, int projection)
{
    format_value(G_format_resolution, res, buf, projection);
}
Exemplo n.º 26
0
static void format_easting(double east, char *buf, int projection)
{
    format_value(G_format_easting, east, buf, projection);
}