Ejemplo n.º 1
0
gboolean
psiconv_read_header (GsfInput *input)
{
	gboolean res = FALSE;
	psiconv_buffer buf = NULL;
	psiconv_config config;

	if ((config = psiconv_config_default()) == NULL)
		goto out;
	config->verbosity = PSICONV_VERB_FATAL;
	psiconv_config_read(NULL,&config);

	if ((buf = psiconv_stream_to_buffer (input, 1024)) == NULL)
		goto out;

	if (psiconv_file_type(config, buf,NULL,NULL) == psiconv_sheet_file)
		res = TRUE;

out:
	if (config)
		psiconv_config_free(config);
	if (buf)
		psiconv_buffer_free(buf);
	return res;
}
Ejemplo n.º 2
0
/*!
 * Check whether this is a Psion file of the given type
 *
 * This is used by the recognizeContents methods of the Word and TextEd
 * sniffers.
 * \return Psion files have strong magic, so we either return 
 * UT_CONFIDENCE_PERFECT or UT_CONFIDENCE_ZILCH.
 */
UT_Confidence_t IE_Imp_Psion_Sniffer::checkContents(const char * szBuf,
												UT_uint32 iNumbytes,
												psiconv_file_type_t filetype)
{
	UT_uint32 i;
	psiconv_config config;
	psiconv_buffer pl;
	psiconv_file_type_t filetype_detected;

	// Prepare a new psiconv_config object
	config = psiconv_config_default();
	if (!config)
		goto ERROR1;
	config->error_handler = &psion_error_handler;
	psiconv_config_read(NULL,&config);
	// It is likely detection will fail, so keep it silent.
	config->verbosity = PSICONV_VERB_FATAL;

	// Copy the file data into a psiconv_buffer.
	pl = psiconv_buffer_new();
	if (!pl)
		goto ERROR2;
	for (i=0; i < iNumbytes; i++)
		if ((psiconv_buffer_add(pl,szBuf[i]))) {
				goto ERROR3;
		}

	// Check whether this is a Psion file.
	filetype_detected = psiconv_file_type(config,pl,NULL,NULL);
	psiconv_buffer_free(pl);
	psiconv_config_free(config);
	if (filetype == filetype_detected)
		return UT_CONFIDENCE_PERFECT;
	else
		return UT_CONFIDENCE_ZILCH;

ERROR3:
	psiconv_buffer_free(pl);
ERROR2:
	psiconv_config_free(config);
ERROR1:
	return UT_CONFIDENCE_ZILCH;
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
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);
}