Exemple #1
0
static void
gnm_glpk_child_exit (GnmSubSolver *subsol, gboolean normal, int code,
		     GnmGlpk *lp)
{
	GnmSolver *sol = GNM_SOLVER (subsol);

	if (sol->status != GNM_SOLVER_STATUS_RUNNING)
		return;

	if (normal) {
		switch (code) {
		case 0: {
			GnmLocale *locale = gnm_push_C_locale ();
			gnm_glpk_read_solution (lp);
			gnm_pop_C_locale (locale);
			break;
		}
		default:
			break;
		}
	}

	if (sol->status == GNM_SOLVER_STATUS_RUNNING)
		gnm_solver_set_status (sol, GNM_SOLVER_STATUS_ERROR);
}
Exemple #2
0
void
sylk_file_open (GOFileOpener const *fo,
		GOIOContext	*io_context,
                WorkbookView	*wb_view,
		GsfInput	*input)
{
	SylkReader state;
	char const *input_name;
	char *name = NULL;
	int i;
	GnmLocale *locale;

	memset (&state, 0, sizeof (state));
	state.io_context = io_context;
	state.input	 = (GsfInputTextline *) gsf_input_textline_new (input);
	state.converter  = g_iconv_open ("UTF-8", "ISO-8859-1");
	state.finished	 = FALSE;
	state.line_no	 = 0;

	state.pp.wb = wb_view_get_workbook (wb_view);

	if (NULL == (input_name = gsf_input_name (input)) ||
	    NULL == (name = g_path_get_basename (input_name)) ||
	    '\0' == *name) {
		g_free (name);
		name = g_strdup ("Sheet");
	}

	state.pp.sheet = sheet_new (state.pp.wb, name, 256, 65536);
	workbook_sheet_attach (state.pp.wb, state.pp.sheet);
	g_free (name);

	state.pp.eval.col = state.pp.eval.row = 1;
	state.convs = gnm_conventions_xls_r1c1;

	state.formats	= g_ptr_array_new ();
	state.fonts	= g_ptr_array_new ();

	locale = gnm_push_C_locale ();
	sylk_parse_sheet (&state);
	gnm_pop_C_locale (locale);
	workbook_set_saveinfo (state.pp.wb, GO_FILE_FL_AUTO,
		go_file_saver_for_id ("Gnumeric_sylk:sylk"));

	for (i = state.fonts->len ; i-- > 0 ; )
		gnm_style_unref (g_ptr_array_index (state.fonts, i));
	g_ptr_array_free (state.fonts, TRUE);

	for (i = state.formats->len ; i-- > 0 ; )
		go_format_unref (g_ptr_array_index (state.formats, i));
	g_ptr_array_free (state.formats, TRUE);

	gsf_iconv_close (state.converter);
	g_object_unref (G_OBJECT (state.input));
}
Exemple #3
0
static void
dif_parse_sheet (DifInputContext *ctxt)
{
	GnmLocale *locale = gnm_push_C_locale ();

	if (!dif_parse_header (ctxt)) {
		go_io_error_info_set (ctxt->io_context, go_error_info_new_printf (
		_("Unexpected end of file at line %d while reading header."),
		ctxt->line_no));
	} else if (!dif_parse_data(ctxt)) {
		go_io_error_info_set (ctxt->io_context, go_error_info_new_printf (
		_("Unexpected end of file at line %d while reading data."),
		ctxt->line_no));
	}

	gnm_pop_C_locale (locale);
}
Exemple #4
0
void
glpk_file_save (GOFileSaver const *fs, GOIOContext *io_context,
                WorkbookView const *wb_view, GsfOutput *output)
{
    GError *err = NULL;
    GString *prg;
    GnmLocale *locale;
    GnmSolver *sol = NULL;
    GnmSubSolver *ssol = g_object_get_data (G_OBJECT (fs), "solver");

    if (!ssol) {
        // Create a temporary solver just functional enough to
        // write the program
        Sheet *sheet = wb_view_cur_sheet (wb_view);
        sol = glpk_solver_create (sheet->solver_parameters);
        ssol = GNM_SUB_SOLVER (sol);
    }

    go_io_progress_message (io_context,
                            _("Writing glpk file..."));

    locale = gnm_push_C_locale ();
    prg = glpk_create_program (ssol, io_context, &err);
    gnm_pop_C_locale (locale);

    gnm_app_recalc ();

    if (!prg) {
        go_cmd_context_error_import (GO_CMD_CONTEXT (io_context),
                                     err ? err->message : "?");
        goto fail;
    }

    gsf_output_write (output, prg->len, prg->str);
    g_string_free (prg, TRUE);

fail:
    go_io_progress_unset (io_context);
    if (err)
        g_error_free (err);

    if (sol)
        g_object_unref (sol);
}
Exemple #5
0
/**
 * gnm_ft_new_from_file:
 * @context:
 * @filename: The filename to load from
 *
 * Create a new GnmFT and load a template file
 * into it.
 *
 * Return value: (transfer full): a new GnmFT (or NULL on error)
 **/
GnmFT *
gnm_ft_new_from_file (char const *filename, GOCmdContext *cc)
{
	GnmFT *ft = NULL;
	GsfXMLInDoc *doc = NULL;
	GnmLocale *locale;
	gboolean ok = FALSE;
	GsfInput *input = NULL;

	g_return_val_if_fail (filename != NULL, NULL);

	input = gsf_input_stdio_new (filename, NULL);
	if (!input) {
		go_cmd_context_error_import
			(cc,
			 _("Error while opening autoformat template"));
		goto done;
	}

	doc = gsf_xml_in_doc_new (template_dtd, template_ns);
	if (doc == NULL)
		goto done;
	gsf_xml_in_doc_set_unknown_handler (doc, &template_sax_unknown);

	ft = gnm_ft_new ();
	ft->filename = g_strdup (filename);

	locale = gnm_push_C_locale ();
	ok = gsf_xml_in_doc_parse (doc, input, ft);
	gnm_pop_C_locale (locale);

 done:
	if (input) g_object_unref (input);
	if (doc) gsf_xml_in_doc_free (doc);

	if (ft && !ok) {
		gnm_ft_free (ft);
		ft = NULL;
	}

	return ft;
}
Exemple #6
0
void
sylk_file_save (GOFileSaver const *fs, GOIOContext *io_context,
		gconstpointer wb_view, GsfOutput *output)
{
	GnmLocale *locale;
	SylkWriter state;

	state.wb     = wb_view_get_workbook (wb_view);
	state.sheet  = wb_view_cur_sheet (wb_view);
	state.output = output;
	state.convs  = sylk_conventions_new ();

	if (NULL == state.sheet) {
		go_io_error_string (io_context, _("Cannot get default sheet."));
		return;
	}

	locale = gnm_push_C_locale ();
	gsf_output_puts (output, "ID;PGnumeric;N;E\r\n");
	sylk_write_sheet (&state);
	gsf_output_puts (output, "E\r\n");
	gnm_pop_C_locale (locale);
	gnm_conventions_unref (state.convs);
}
Exemple #7
0
/*
 * Write _current_ sheet of the workbook to a DIF format file
 */
void
dif_file_save (GOFileSaver const *fs, GOIOContext *io_context,
               WorkbookView const *wbv, GsfOutput *out)
{
	GnmLocale *locale;
	Sheet *sheet;
	GnmRange r;
	gint row, col;
	gboolean ok = TRUE;

	sheet = wb_view_cur_sheet (wbv);
	if (sheet == NULL) {
		go_io_error_string (io_context, _("Cannot get default sheet."));
		return;
	}

	r = sheet_get_extent (sheet, FALSE, TRUE);

	/* Write out the standard headers */
	gsf_output_puts   (out, "TABLE\n"   "0,1\n" "\"GNUMERIC\"\n");
	gsf_output_printf (out, "VECTORS\n" "0,%d\n" "\"\"\n", r.end.col+1);
	gsf_output_printf (out, "TUPLES\n"  "0,%d\n" "\"\"\n", r.end.row+1);
	gsf_output_puts   (out, "DATA\n"    "0,0\n"  "\"\"\n");

	locale = gnm_push_C_locale ();

	/* Process all cells */
	for (row = r.start.row; ok && row <= r.end.row; row++) {
		gsf_output_puts (out, "-1,0\n" "BOT\n");
		for (col = r.start.col; col <= r.end.col; col++) {
			GnmCell *cell = sheet_cell_get (sheet, col, row);
			if (gnm_cell_is_empty (cell)) {
				gsf_output_puts(out, "1,0\n" "\"\"\n");
			} else if (VALUE_IS_BOOLEAN (cell->value)) {
				if (value_get_as_checked_bool (cell->value))
					gsf_output_puts(out, "0,1\n" "TRUE\n");
				else
					gsf_output_puts(out, "0,0\n" "FALSE\n");
			} else if (VALUE_IS_ERROR (cell->value)) {
				if (value_error_classify (cell->value) == GNM_ERROR_NA)
					gsf_output_puts(out, "0,0\n" "NA\n");
				else
					gsf_output_puts(out, "0,0\n" "ERROR\n");
			} else if (VALUE_IS_FLOAT (cell->value))
				gsf_output_printf (out, "0,%" GNM_FORMAT_g "\n" "V\n",
					value_get_as_float (cell->value));
			else {
				gchar *str = gnm_cell_get_rendered_text (cell);
				ok = gsf_output_printf (out,
							 "1,0\n" "\"%s\"\n",
							 str);
				g_free (str);
			}
		}
	}

	gsf_output_puts (out, "-1,0\n" "EOD\n");

	gnm_pop_C_locale (locale);

	if (!ok)
		go_io_error_string (io_context, _("Error while saving DIF file."));
}