Exemplo n.º 1
0
int 
main ()
{
  gdouble d;
  char buffer[G_ASCII_DTOSTR_BUF_SIZE];

  test_string ("123.123", 123.123);
  test_string ("123.123e2", 123.123e2);
  test_string ("123.123e-2", 123.123e-2);
  test_string ("-123.123", -123.123);
  test_string ("-123.123e2", -123.123e2);
  test_string ("-123.123e-2", -123.123e-2);
  
  d = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
  g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));

  d = -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
  g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
  
  d = pow (2.0, -1024.1);
  g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
  
  d = -pow (2.0, -1024.1);
  g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
  

  return 0;
}
Exemplo n.º 2
0
Arquivo: .c Projeto: pigay/vsg
/**
 * vsg_quaternion@t@_write:
 * @quat: a #VsgQuaternion@t@
 * @file: a @FILE
 *
 * Writes @quat in @file. 
 */
void vsg_quaternion@t@_write (const VsgQuaternion@t@ *quat,
                              FILE *file)
{
  gchar bufx[G_ASCII_DTOSTR_BUF_SIZE];
  gchar *x;
  gchar bufy[G_ASCII_DTOSTR_BUF_SIZE];
  gchar *y;
  gchar bufz[G_ASCII_DTOSTR_BUF_SIZE];
  gchar *z;
  gchar bufw[G_ASCII_DTOSTR_BUF_SIZE];
  gchar *w;

  g_return_if_fail (quat != NULL);
  g_return_if_fail (file != NULL);

/*   fprintf (file, "[%@tcode@,%@tcode@,%@tcode@,%@tcode@]", */
/*            quat->x, */
/*            quat->y, */
/*            quat->z, */
/*            quat->w); */

  /* avoid locale problems */
  x = g_ascii_dtostr (bufx, G_ASCII_DTOSTR_BUF_SIZE, quat->x);
  y = g_ascii_dtostr (bufy, G_ASCII_DTOSTR_BUF_SIZE, quat->y);
  z = g_ascii_dtostr (bufz, G_ASCII_DTOSTR_BUF_SIZE, quat->z);
  w = g_ascii_dtostr (bufw, G_ASCII_DTOSTR_BUF_SIZE, quat->w);
  fprintf(file, "[%s,%s,%s,%s]", x, y, z, w);
}
Exemplo n.º 3
0
static void datasource_osm_get_process_options ( datasource_osm_widgets_t *widgets, ProcessOptions *po, DownloadFileOptions *options, const gchar *notused1, const gchar *notused2)
{
  int page = 0;
  gdouble min_lat, max_lat, min_lon, max_lon;
  gchar sminlon[G_ASCII_DTOSTR_BUF_SIZE];
  gchar smaxlon[G_ASCII_DTOSTR_BUF_SIZE];
  gchar sminlat[G_ASCII_DTOSTR_BUF_SIZE];
  gchar smaxlat[G_ASCII_DTOSTR_BUF_SIZE];

  /* get Viewport bounding box */
  vik_viewport_get_min_max_lat_lon ( widgets->vvp, &min_lat, &max_lat, &min_lon, &max_lon );

  /* Convert as LANG=C double representation */
  g_ascii_dtostr (sminlon, G_ASCII_DTOSTR_BUF_SIZE, min_lon);
  g_ascii_dtostr (smaxlon, G_ASCII_DTOSTR_BUF_SIZE, max_lon);
  g_ascii_dtostr (sminlat, G_ASCII_DTOSTR_BUF_SIZE, min_lat);
  g_ascii_dtostr (smaxlat, G_ASCII_DTOSTR_BUF_SIZE, max_lat);

  /* Retrieve the specified page number */
  last_page_number = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->page_number));
  page = last_page_number;

  // NB Download is of GPX type
  po->url = g_strdup_printf( DOWNLOAD_URL_FMT, sminlon, sminlat, smaxlon, smaxlat, page );
  options = NULL; // i.e. use the default download settings
}
Exemplo n.º 4
0
static void datasource_osm_get_cmd_string ( datasource_osm_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options )
{
  int page = 0;
  gdouble min_lat, max_lat, min_lon, max_lon;
  gchar sminlon[G_ASCII_DTOSTR_BUF_SIZE];
  gchar smaxlon[G_ASCII_DTOSTR_BUF_SIZE];
  gchar sminlat[G_ASCII_DTOSTR_BUF_SIZE];
  gchar smaxlat[G_ASCII_DTOSTR_BUF_SIZE];

  /* get Viewport bounding box */
  vik_viewport_get_min_max_lat_lon ( widgets->vvp, &min_lat, &max_lat, &min_lon, &max_lon );

  /* Convert as LANG=C double representation */
  g_ascii_dtostr (sminlon, G_ASCII_DTOSTR_BUF_SIZE, min_lon);
  g_ascii_dtostr (smaxlon, G_ASCII_DTOSTR_BUF_SIZE, max_lon);
  g_ascii_dtostr (sminlat, G_ASCII_DTOSTR_BUF_SIZE, min_lat);
  g_ascii_dtostr (smaxlat, G_ASCII_DTOSTR_BUF_SIZE, max_lat);

  /* Retrieve the specified page number */
  last_page_number = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->page_number));
  page = last_page_number;

  *cmd = g_strdup_printf( DOWNLOAD_URL_FMT, sminlon, sminlat, smaxlon, smaxlat, page );
  *input_file_type = NULL;
  options = NULL;
}
Exemplo n.º 5
0
static gchar *
_get_uri( VikMapSourceDefault *self, MapCoord *src )
{
	g_return_val_if_fail (VIK_IS_WMSC_MAP_SOURCE(self), NULL);
	
    VikWmscMapSourcePrivate *priv = VIK_WMSC_MAP_SOURCE_PRIVATE(self);
	gdouble socalled_mpp;
	if (src->scale >= 0)
		socalled_mpp = VIK_GZ(src->scale);
	else
		socalled_mpp = 1.0/VIK_GZ(-src->scale);
	gdouble minx = (gdouble)src->x * 180 / VIK_GZ(17) * socalled_mpp * 2 - 180;
	gdouble maxx = (gdouble)(src->x + 1) * 180 / VIK_GZ(17) * socalled_mpp * 2 - 180;
	/* We should restore logic of viking:
     * tile index on Y axis follow a screen logic (top -> down)
     */
	gdouble miny = -((gdouble)(src->y + 1) * 180 / VIK_GZ(17) * socalled_mpp * 2 - 90);
	gdouble maxy = -((gdouble)(src->y) * 180 / VIK_GZ(17) * socalled_mpp * 2 - 90);
	
	gchar sminx[G_ASCII_DTOSTR_BUF_SIZE];
	gchar smaxx[G_ASCII_DTOSTR_BUF_SIZE];
	gchar sminy[G_ASCII_DTOSTR_BUF_SIZE];
	gchar smaxy[G_ASCII_DTOSTR_BUF_SIZE];

	g_ascii_dtostr (sminx, G_ASCII_DTOSTR_BUF_SIZE, minx);
	g_ascii_dtostr (smaxx, G_ASCII_DTOSTR_BUF_SIZE, maxx);
	g_ascii_dtostr (sminy, G_ASCII_DTOSTR_BUF_SIZE, miny);
	g_ascii_dtostr (smaxy, G_ASCII_DTOSTR_BUF_SIZE, maxy);

	gchar *uri = g_strdup_printf (priv->url, sminx, sminy, smaxx, smaxy);
	
	return uri;
} 
Exemplo n.º 6
0
static gchar*
asc_format_header(GwyContainer *data, GwyDataField *dfield,
                  gboolean *zunit_is_nm)
{
    static const gchar asc_header_template[] =
        "# File Format = ASCII\n"
        "# Created by Gwyddion %s\n"
        "# Original file: %s\n"
        "# x-pixels = %u\n"
        "# y-pixels = %u\n"
        "# x-length = %s\n"
        "# y-length = %s\n"
        "# x-offset = %s\n"
        "# y-offset = %s\n"
        "# Bit2nm = 1.0\n"
        "%s"
        "# Start of Data:\n";

    GwySIUnit *zunit;
    gchar *header, *zunit_str, *zunit_line;
    gchar xreal_str[G_ASCII_DTOSTR_BUF_SIZE],
          yreal_str[G_ASCII_DTOSTR_BUF_SIZE],
          xoff_str[G_ASCII_DTOSTR_BUF_SIZE],
          yoff_str[G_ASCII_DTOSTR_BUF_SIZE];
    const guchar *filename = "NONE";
    gdouble xreal, yreal, xoff, yoff;

    /* XXX: Gwyddion can have lateral dimensions as whatever we want.  But
     * who knows about the SPIP ASC format... */
    xreal = gwy_data_field_get_xreal(dfield)/Nanometer;
    yreal = gwy_data_field_get_yreal(dfield)/Nanometer;
    xoff = gwy_data_field_get_xoffset(dfield)/Nanometer;
    yoff = gwy_data_field_get_yoffset(dfield)/Nanometer;
    zunit = gwy_data_field_get_si_unit_z(dfield);

    g_ascii_dtostr(xreal_str, G_ASCII_DTOSTR_BUF_SIZE, xreal);
    g_ascii_dtostr(yreal_str, G_ASCII_DTOSTR_BUF_SIZE, yreal);
    g_ascii_dtostr(xoff_str, G_ASCII_DTOSTR_BUF_SIZE, xoff);
    g_ascii_dtostr(yoff_str, G_ASCII_DTOSTR_BUF_SIZE, yoff);
    zunit_str = gwy_si_unit_get_string(zunit, GWY_SI_UNIT_FORMAT_PLAIN);
    if ((*zunit_is_nm = gwy_strequal(zunit_str, "m")))
        zunit_line = g_strdup("");
    else
        zunit_line = g_strdup_printf("# z-unit = %s\n", zunit_str);

    gwy_container_gis_string_by_name(data, "/filename", &filename);

    header = g_strdup_printf(asc_header_template,
                             gwy_version_string(), filename,
                             gwy_data_field_get_xres(dfield),
                             gwy_data_field_get_yres(dfield),
                             xreal_str, yreal_str, xoff_str, yoff_str,
                             zunit_line);

    g_free(zunit_str);
    g_free(zunit_line);

    return header;
}
Exemplo n.º 7
0
static void
save_range(G_GNUC_UNUSED gpointer key, gpointer data, gpointer user_data)
{
    RangeRecord *rr = (RangeRecord*)data;
    FILE *fh = user_data;
    gchar buf_lower[G_ASCII_DTOSTR_BUF_SIZE];
    gchar buf_upper[G_ASCII_DTOSTR_BUF_SIZE];

    g_ascii_dtostr(buf_lower, G_ASCII_DTOSTR_BUF_SIZE, rr->lower);
    g_ascii_dtostr(buf_upper, G_ASCII_DTOSTR_BUF_SIZE, rr->upper);
    fprintf(fh, "%s %s %s\n", buf_lower, buf_upper, rr->quantity);
}
Exemplo n.º 8
0
G_MODULE_EXPORT
gboolean on_menu_quit_activate(void)
{
  gint wx = 0, wy = 0, width = 0, height = 0;
  gchar buf[16];
  int i = 0;
  gint length = g_list_length(gummi->tabmanager->tabs);

  motion_pause_compile_thread(gummi->motion);
  for (i = 0; i < length; i++) {
    gtk_notebook_set_current_page(gui->tabmanagergui->notebook, i);
    tabmanager_set_active_tab(i);

    gint ret = check_for_save(g_active_editor);
    if (GTK_RESPONSE_YES == ret) {
      gui_save_file(g_active_tab, FALSE);
    }
    else if (GTK_RESPONSE_CANCEL == ret || GTK_RESPONSE_DELETE_EVENT == ret) {
      motion_resume_compile_thread(gummi->motion);
      return TRUE;
    }
  }

  /* Stop compile thread */
  if (length > 0) motion_stop_compile_thread(gummi->motion);

  gboolean is_maximized;
  g_object_get(gui->mainwindow, "is-maximized", &is_maximized, NULL);

  if (!is_maximized) {
    gtk_window_get_size(gui->mainwindow, &width, &height);
    gtk_window_get_position(gui->mainwindow, &wx, &wy);

    config_begin();
    config_set_value("mainwindow_x", g_ascii_dtostr(buf, 16, (double)wx));
    config_set_value("mainwindow_y", g_ascii_dtostr(buf, 16, (double)wy));
    config_set_value("mainwindow_w", g_ascii_dtostr(buf, 16, (double)width));
    config_set_value("mainwindow_h", g_ascii_dtostr(buf, 16, (double)height));
    config_commit();
  }

  gtk_main_quit();

  for (i = 0; i < length; i++)
    editor_destroy(GU_TAB_CONTEXT(g_list_nth_data
                                  (gummi->tabmanager->tabs, i))->editor);

  printf("   ___ \n"
         "  {o,o}    Thanks for using Gummi!\n"
         "  |)__)    I welcome your feedback at:\n"
         "  -\"-\"-    http://gummi.midnightcoding.org\n\n");
  return FALSE;
}
Exemplo n.º 9
0
static void serialize (QCADDesignObject *obj, FILE *fp)
  {
  char pszDouble[G_ASCII_DTOSTR_BUF_SIZE] = "" ;
  QCADRectangleElectrode *rc_electrode = QCAD_RECTANGLE_ELECTRODE (obj) ;

  fprintf (fp, "[TYPE:" QCAD_TYPE_STRING_RECTANGLE_ELECTRODE "]\n") ;
  QCAD_DESIGN_OBJECT_CLASS (g_type_class_peek (g_type_parent (QCAD_TYPE_RECTANGLE_ELECTRODE)))->serialize (obj, fp) ;
  fprintf (fp, "angle=%s\n", g_ascii_dtostr (pszDouble, G_ASCII_DTOSTR_BUF_SIZE, rc_electrode->angle)) ;
  fprintf (fp, "n_x_divisions=%d\n", rc_electrode->n_x_divisions) ;
  fprintf (fp, "n_y_divisions=%d\n", rc_electrode->n_y_divisions) ;
  fprintf (fp, "cxWorld=%s\n", g_ascii_dtostr (pszDouble, G_ASCII_DTOSTR_BUF_SIZE, rc_electrode->cxWorld)) ;
  fprintf (fp, "cyWorld=%s\n", g_ascii_dtostr (pszDouble, G_ASCII_DTOSTR_BUF_SIZE, rc_electrode->cyWorld)) ;
  fprintf (fp, "[#TYPE:" QCAD_TYPE_STRING_RECTANGLE_ELECTRODE "]\n") ;
  }
Exemplo n.º 10
0
void
arv_gc_property_node_set_double (ArvGcPropertyNode *node, double v_double, GError **error)
{
	ArvDomNode *pvalue_node;

	g_return_if_fail (ARV_IS_GC_PROPERTY_NODE (node));
	g_return_if_fail (error == NULL || *error == NULL);

	pvalue_node = _get_pvalue_node (node);
	if (pvalue_node == NULL) {
		char buffer[G_ASCII_DTOSTR_BUF_SIZE];

		g_ascii_dtostr (buffer, G_ASCII_DTOSTR_BUF_SIZE, v_double);
		_set_value_data (node, buffer);
		return ;
	}

	if (ARV_IS_GC_FLOAT (pvalue_node)) {
		GError *local_error = NULL;

		arv_gc_float_set_value (ARV_GC_FLOAT (pvalue_node), v_double, &local_error);

		if (local_error != NULL)
			g_propagate_error (error, local_error);

		return;
	}

	arv_warning_genicam ("[GcPropertyNode::set_double] Invalid linked node '%s'",
			     arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (pvalue_node)));
}
Exemplo n.º 11
0
/* (de)serialize functions */
static gchar *
serialize_exif_gps_coordinate (const GValue * value, gchar pos, gchar neg)
{
  gdouble num;
  gchar c;
  gint integer;
  gchar fraction[G_ASCII_DTOSTR_BUF_SIZE];

  g_return_val_if_fail (G_VALUE_TYPE (value) == G_TYPE_DOUBLE, NULL);

  num = g_value_get_double (value);
  if (num < 0) {
    c = neg;
    num *= -1;
  } else {
    c = pos;
  }
  integer = (gint) num;

  g_ascii_dtostr (fraction, sizeof (fraction), (num - integer) * 60);

  /* FIXME review GPSCoordinate serialization spec for the .mm or ,ss
   * decision. Couldn't understand it clearly */
  return g_strdup_printf ("%d,%s%c", integer, fraction, c);
}
static void
string_append_dtostr (GString * string, gdouble value, guint precision)
{
  gchar dstrbuf[G_ASCII_DTOSTR_BUF_SIZE] = { 0, };
  gchar *dot;
  guint len;

  precision++;

  if (value != 0.0)
    value += 4.9 * pow (10.0, precision * -1.0);

  g_ascii_dtostr (dstrbuf, G_ASCII_DTOSTR_BUF_SIZE, value);

  dot = strchr (dstrbuf, '.');

  if (dot == NULL)
    goto done;

  for (; *dot != '.' && *dot != '0'; dot++);

  if ((dot - dstrbuf) + precision < G_ASCII_DTOSTR_BUF_SIZE)
    dot[precision] = 0;

  len = strlen (dstrbuf);
  while (dstrbuf[len - 1] == '0')
    dstrbuf[--len] = 0;
  if (dstrbuf[len - 1] == '.')
    dstrbuf[--len] = 0;

done:

  g_string_append (string, dstrbuf);
}
Exemplo n.º 13
0
static void
gtk_css_value_number_print (const GtkCssValue *number,
                            GString           *string)
{
  char buf[G_ASCII_DTOSTR_BUF_SIZE];

  const char *names[] = {
    /* [GTK_CSS_NUMBER] = */ "",
    /* [GTK_CSS_PERCENT] = */ "%",
    /* [GTK_CSS_PX] = */ "px",
    /* [GTK_CSS_PT] = */ "pt",
    /* [GTK_CSS_EM] = */ "em",
    /* [GTK_CSS_EX] = */ "ex",
    /* [GTK_CSS_PC] = */ "pc",
    /* [GTK_CSS_IN] = */ "in",
    /* [GTK_CSS_CM] = */ "cm",
    /* [GTK_CSS_MM] = */ "mm",
    /* [GTK_CSS_RAD] = */ "rad",
    /* [GTK_CSS_DEG] = */ "deg",
    /* [GTK_CSS_GRAD] = */ "grad",
    /* [GTK_CSS_TURN] = */ "turn",
    /* [GTK_CSS_S] = */ "s",
    /* [GTK_CSS_MS] = */ "ms",
  };

  g_ascii_dtostr (buf, sizeof (buf), number->value);
  g_string_append (string, buf);
  if (number->value != 0.0)
    g_string_append (string, names[number->unit]);
}
Exemplo n.º 14
0
static void
menu_settings_clicked(GtkMenuItem *menuitem, gpointer data)
{
	GtkBuilder *builder;
	GtkWidget  *window;
	GError     *error = NULL;
	gchar  buf[1024];

	builder = gtk_builder_new();
	if( ! gtk_builder_add_from_file( builder, config->settings_dialog, &error ) )
	{
		g_warning( "%s", error->message );
		g_free( error );
		return;
	}

	window = GTK_WIDGET( gtk_builder_get_object( builder, "dialog1" ) );

	GtkWidget *btnCancel = GTK_WIDGET(gtk_builder_get_object (builder, "btnCancel"));
	g_signal_connect_swapped (btnCancel, "clicked", G_CALLBACK (gtk_widget_destroy), window);

	GtkWidget *btnSave = GTK_WIDGET(gtk_builder_get_object (builder, "btnSave"));
	g_signal_connect_swapped (btnSave, "clicked", G_CALLBACK (on_btnSave_clicked), window);

	txtServerPort = GTK_WIDGET(gtk_builder_get_object (builder, "txtServerPort"));
	gtk_entry_set_text(GTK_ENTRY(txtServerPort), settings->server_port);

	txtUpdateInterval = GTK_WIDGET(gtk_builder_get_object (builder, "txtUpdateInterval"));
	g_ascii_dtostr(buf, sizeof (buf), settings->update_interval);
	gtk_entry_set_text(GTK_ENTRY(txtUpdateInterval), buf);

	g_object_unref( G_OBJECT( builder ) );
	gtk_widget_show( window );
}
Exemplo n.º 15
0
/** \brief  Return the value as a string */
void
ParamFloat::string (std::string &string)
{
    char startstring[G_ASCII_DTOSTR_BUF_SIZE];
    g_ascii_dtostr(startstring, G_ASCII_DTOSTR_BUF_SIZE, _value);
    string += startstring;
    return;
}
Exemplo n.º 16
0
/**
 * vsg_vector2@t@_write:
 * @vec: a #VsgVector2@t@
 * @file: a #FILE pointer
 *
 * Writes @vec coordinates to @file.
 */
void vsg_vector2@t@_write(const VsgVector2@t@ *vec, FILE *file)
{
  gchar bufx[G_ASCII_DTOSTR_BUF_SIZE];
  gchar *x;
  gchar bufy[G_ASCII_DTOSTR_BUF_SIZE];
  gchar *y;

  g_return_if_fail(vec != NULL);
  g_return_if_fail(file != NULL);

  /* fprintf(file, "[%@tcode@,%@tcode@]", vec->x, vec->y); */

  /* avoid locale problems */
  x = g_ascii_dtostr (bufx, G_ASCII_DTOSTR_BUF_SIZE, vec->x);
  y = g_ascii_dtostr (bufy, G_ASCII_DTOSTR_BUF_SIZE, vec->y);
  fprintf(file, "[%s,%s]", x, y);
}
Exemplo n.º 17
0
/* This must be wrapped in push_c_locale on the caller */
static void
print_ascore (struct ascore_t *ascore, FILE * outfile)
{
	char buf[G_ASCII_DTOSTR_BUF_SIZE];
	/* make sure we write values to files in a consistent manner */
	fprintf (outfile, "%s %ld %s\n", g_ascii_dtostr (buf, sizeof (buf), ascore->score),
		 (long int) ascore->scoretime, ascore->username);
}
Exemplo n.º 18
0
static void serialize (QCADDesignObject *obj, FILE *fp)
  {
  QCADClockingLayer *clocking_layer = NULL ;
  char pszDouble[G_ASCII_DTOSTR_BUF_SIZE] = "" ;

  if (NULL == obj) return ;

  clocking_layer = QCAD_CLOCKING_LAYER (obj) ;

  fprintf (fp, "[TYPE:" QCAD_TYPE_STRING_CLOCKING_LAYER "]\n") ;
  QCAD_DESIGN_OBJECT_CLASS (g_type_class_peek (g_type_parent (QCAD_TYPE_CLOCKING_LAYER)))->serialize (obj, fp) ;
  fprintf (fp, "bDrawPotential=%s\n", clocking_layer->bDrawPotential ? "TRUE" : "FALSE") ;
  fprintf (fp, "z_to_draw=%s\n", g_ascii_dtostr (pszDouble, G_ASCII_DTOSTR_BUF_SIZE, clocking_layer->z_to_draw)) ;
  fprintf (fp, "tile_size=%d\n", clocking_layer->tile_size) ;
  fprintf (fp, "time_coord=%s\n", g_ascii_dtostr (pszDouble, G_ASCII_DTOSTR_BUF_SIZE, clocking_layer->time_coord)) ;
  fprintf (fp, "[#TYPE:" QCAD_TYPE_STRING_CLOCKING_LAYER "]\n") ;
  }
Exemplo n.º 19
0
static int 
write_double( FILE *fp, double d )
{
	char buf[G_ASCII_DTOSTR_BUF_SIZE];

	fprintf( fp, "%s", g_ascii_dtostr( buf, sizeof( buf ), d ) );

	return( 0 );
}
Exemplo n.º 20
0
static char *
float_value_to_string (const GValue *value)
{
  char buf[G_ASCII_DTOSTR_BUF_SIZE];

  g_ascii_dtostr (buf, sizeof (buf), g_value_get_float (value));

  return g_strdup (buf);
}
char *
mdm_settings_parse_double_as_value (gdouble doubleval)
{
        char result[G_ASCII_DTOSTR_BUF_SIZE];

        g_ascii_dtostr (result, sizeof (result), doubleval);

        return g_strdup (result);
}
Exemplo n.º 22
0
G_MODULE_EXPORT
void on_autosave_value_changed(GtkWidget* widget, void* user)
{
  gint newval = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
  gchar buf[16];

  config_set_value("autosave_timer", g_ascii_dtostr(buf, 16, (double)newval));
  iofunctions_reset_autosave(g_active_editor->filename);
}
Exemplo n.º 23
0
G_MODULE_EXPORT
void on_compile_value_changed(GtkWidget* widget, void* user)
{
  gint newval = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widget));
  gchar buf[16];

  config_set_value("compile_timer", g_ascii_dtostr(buf, 16, (double)newval));
  previewgui_reset(gui->previewgui);
}
Exemplo n.º 24
0
static void
string_append_double (GString *string,
                      double   d)
{
  char buf[G_ASCII_DTOSTR_BUF_SIZE];

  g_ascii_dtostr (buf, sizeof (buf), d);
  g_string_append (string, buf);
}
Exemplo n.º 25
0
static void
mpp_xml_set_float (xmlNodePtr node, const gchar *prop, gfloat value)
{
	gchar  buf[128];
	gchar *str;

	str = g_ascii_dtostr (buf, sizeof(buf) - 1, value);
	xmlSetProp (node, prop, str);
}
Exemplo n.º 26
0
void
inf_xml_util_set_attribute_double(xmlNodePtr xml,
                                  const gchar* attribute,
                                  gdouble value)
{
  char buffer[G_ASCII_DTOSTR_BUF_SIZE];
  g_ascii_dtostr(buffer, G_ASCII_DTOSTR_BUF_SIZE, value);
  xmlSetProp(xml, (const xmlChar*)attribute, (const xmlChar*)buffer);
}
Exemplo n.º 27
0
static void
gog_chart_get_property (GObject *obj, guint param_id,
			GValue *value, GParamSpec *pspec)
{
	GogChart *chart = GOG_CHART (obj);
	GString *string;
	char buffer[G_ASCII_DTOSTR_BUF_SIZE];

	switch (param_id) {
	case CHART_PROP_CARDINALITY_VALID:
		g_value_set_boolean (value, chart->cardinality_valid);
		break;
	case CHART_PROP_PLOT_AREA:
		string = g_string_new ("");
		g_string_append (string, g_ascii_dtostr (buffer, sizeof (buffer), chart->plot_area.x));
		g_string_append_c (string, ' ');
		g_string_append (string, g_ascii_dtostr (buffer, sizeof (buffer), chart->plot_area.y));
		g_string_append_c (string, ' ');
		g_string_append (string, g_ascii_dtostr (buffer, sizeof (buffer), chart->plot_area.w));
		g_string_append_c (string, ' ');
		g_string_append (string, g_ascii_dtostr (buffer, sizeof (buffer), chart->plot_area.h));
		g_value_set_string (value, string->str);
		g_string_free (string, TRUE);
		break;
	case CHART_PROP_PLOT_AREA_IS_MANUAL:
		g_value_set_boolean (value, chart->is_plot_area_manual);
		break;
	case CHART_PROP_X_POS:
		g_value_set_int (value, chart->x_pos);
		break;
	case CHART_PROP_Y_POS:
		g_value_set_int (value, chart->y_pos);
		break;
	case CHART_PROP_COLUMNS:
		g_value_set_int (value, chart->cols);
		break;
	case CHART_PROP_ROWS:
		g_value_set_int (value, chart->rows);
		break;

	default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
		 break;
	}
}
Exemplo n.º 28
0
gboolean
games_scores_backend_set_scores (GamesScoresBackend * self, GList * list)
{
  GList *s;
  GamesScore *d;
  gchar *buffer;
  gint output_length = 0;
  gchar dtostrbuf[G_ASCII_DTOSTR_BUF_SIZE];

  if (!games_scores_backend_get_lock (self))
    return FALSE;

  self->priv->scores_list = list;

  s = list;
  while (s != NULL) {
    gdouble rscore;
    guint64 rtime;

    d = (GamesScore *) s->data;
    rscore = 0.0;
    switch (self->priv->style) {
    case GAMES_SCORES_STYLE_PLAIN_DESCENDING:
    case GAMES_SCORES_STYLE_PLAIN_ASCENDING:
      rscore = games_score_get_value_as_plain (d);
      break;
    case GAMES_SCORES_STYLE_TIME_DESCENDING:
    case GAMES_SCORES_STYLE_TIME_ASCENDING:
      rscore = games_score_get_value_as_time (d);
      break;
    default:
      g_assert_not_reached ();
    }
    rtime = games_score_get_time (d);

    buffer = g_strdup_printf ("%s %"G_GUINT64_FORMAT"\n",
                              g_ascii_dtostr (dtostrbuf, sizeof (dtostrbuf),
                                              rscore), rtime);
    write (self->priv->fd, buffer, strlen (buffer));
    output_length += strlen (buffer);
    /* Ignore any errors and blunder on. */
    g_free (buffer);

    s = g_list_next (s);
  }

  /* Remove any content in the file that hasn't yet been overwritten. */
  ftruncate (self->priv->fd, output_length--);

  /* Update the timestamp so we don't reread the scores unnecessarily. */
  self->priv->timestamp = time (NULL);

  games_scores_backend_release_lock (self);

  return TRUE;
}
Exemplo n.º 29
0
static char*
string_value_from_variant(DBusMessageIter *variant_iter,
                          const char      *value_signature)
{
    char *value;
    
    value = NULL;
    switch (*value_signature) {
    case DBUS_TYPE_STRING:
        {
            /* note we do NOT json-escape a single string, only strings in an array */
            const char *v_STRING;
            dbus_message_iter_get_basic(variant_iter, &v_STRING);
            value = g_strdup(v_STRING);
        }
        break;
    case DBUS_TYPE_INT32:
        {
            dbus_int32_t v_INT32;
            dbus_message_iter_get_basic(variant_iter, &v_INT32);
            value = g_strdup_printf("%d", v_INT32);
        }
        break;
    case DBUS_TYPE_BOOLEAN:
        {
            dbus_bool_t v_BOOLEAN;
            dbus_message_iter_get_basic(variant_iter, &v_BOOLEAN);
            value = g_strdup_printf("%s", v_BOOLEAN ? "true" : "false");
        }
        break;
    case DBUS_TYPE_DOUBLE:
        {
            double v_DOUBLE;
            char buf[G_ASCII_DTOSTR_BUF_SIZE];
            dbus_message_iter_get_basic(variant_iter, &v_DOUBLE);
            g_ascii_dtostr(buf, G_ASCII_DTOSTR_BUF_SIZE, v_DOUBLE);
            value = g_strdup(buf);
        }
        break;
    case DBUS_TYPE_ARRAY:
        {
            DBusMessageIter array_iter;
            
            dbus_message_iter_recurse(variant_iter, &array_iter);
            value = string_value_from_array(&array_iter, *(value_signature + 1));
        }
        break;
    default:
        /* since we already validated the signature, should not happen */
        g_assert_not_reached();
        break;
    }

    return value;
}
Exemplo n.º 30
0
/* Get forecast into newly alloc'ed string */
gboolean
iwin_start_open (GWeatherInfo *info)
{
    GWeatherInfoPrivate *priv;
    gchar *url;
    WeatherLocation *loc;
    SoupMessage *msg;

    g_assert (info != NULL);

    priv = info->priv;
    loc = &priv->location;

    /* No zone (or -) means no weather information from national offices.
       We don't actually use zone, but it's a good indicator of a US location.
       (@ and : prefixes were used in the past for Australia and UK) */
    if (!loc->zone || loc->zone[0] == '-' || loc->zone[0] == '@' || loc->zone[0] == ':')
        return FALSE;

    if (!loc->latlon_valid)
	return FALSE;

    /* see the description here: http://www.weather.gov/forecasts/xml/ */
    struct tm tm;
    time_t now;
    gchar latstr[G_ASCII_DTOSTR_BUF_SIZE], lonstr[G_ASCII_DTOSTR_BUF_SIZE];

    now = time (NULL);
    localtime_r (&now, &tm);

    g_ascii_dtostr (latstr, sizeof(latstr), RADIANS_TO_DEGREES (loc->latitude));
    g_ascii_dtostr (lonstr, sizeof(lonstr), RADIANS_TO_DEGREES (loc->longitude));
    url = g_strdup_printf ("http://www.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?&lat=%s&lon=%s&format=24+hourly&startDate=%04d-%02d-%02d&numDays=7",
			   latstr, lonstr, 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday);
    msg = soup_message_new ("GET", url);
    _gweather_info_begin_request (info, msg);
    soup_session_queue_message (priv->session, msg, iwin_finish, info);

    g_free (url);

    return TRUE;
}