示例#1
0
/*!
 * Import a file with the given filename from disk.
 */
UT_Error IE_Imp_Psion::_loadFile(GsfInput * fp)
{
	int res;
	psiconv_file psionfile;
	UT_Error err = UT_IE_NOMEMORY;
	psiconv_buffer buf;
	psiconv_config config;

	// Read the file contents into a new psiconv_buffer
	if (!(buf = psiconv_buffer_new())) 
		goto ERROR1;

	psiconv_u8 ch;
	while(gsf_input_read(fp, 1, (guint8*)&ch)) {
		if(psiconv_buffer_add(buf, ch))
			goto ERROR3;
	}

	// Prepare a new psiconv_config object
	config = psiconv_config_default();
	if (!config)
		goto ERROR3;
	config->error_handler = psion_error_handler;
	psiconv_config_read(NULL,&config);

	// Try to parse the file contents into psiconv internal data structures
	res = psiconv_parse(config,buf,&psionfile);

	// Tidy up
	g_object_unref(G_OBJECT(fp));
	psiconv_config_free(config);
	psiconv_buffer_free(buf);

	// Check whether this was a parsable Psion document
	if (res) {
		if (res == PSICONV_E_NOMEM)
			return UT_IE_NOMEMORY;
		else
			return UT_IE_BOGUSDOCUMENT;
	}

	// Translate the file into an AbiWord document
	return parseFile(psionfile);

ERROR3:
	psiconv_buffer_free(buf);
ERROR1:
	return err;
}
示例#2
0
void
psiconv_read (GOIOContext *io_context, Workbook *wb, GsfInput *input)
{
	psiconv_buffer buf ;
	psiconv_config config   = NULL;
	psiconv_file   psi_file = NULL;

	if ((buf = psiconv_stream_to_buffer (input, -1)) == NULL) {
		go_io_error_info_set (io_context,
		                            go_error_info_new_str(_("Error while reading psiconv file.")));
		goto out;
	}

	if ((config = psiconv_config_default()) == NULL)
		goto out;
	config->verbosity = PSICONV_VERB_ERROR;
	psiconv_config_read(NULL,&config);
	if (psiconv_parse(config, buf, &psi_file) != 0) {
		psi_file = NULL;
		go_io_error_info_set (io_context,
		                            go_error_info_new_str(_("Error while parsing Psion file.")));
		goto out;
	}

	if (psi_file->type == psiconv_sheet_file)
		add_sheetfile(wb,psi_file->file);
	else
		go_io_error_info_set (io_context,
		                            go_error_info_new_str(_("This Psion file is not a Sheet file.")));


out:
	if (config)
		psiconv_config_free(config);
	if (buf)
		psiconv_buffer_free(buf);
	if (psi_file)
		psiconv_free_file(psi_file);
}