File: boot.c

package info (click to toggle)
gnumeric 1.12.57-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 111,496 kB
  • sloc: ansic: 296,601; xml: 56,363; perl: 6,615; sh: 5,288; makefile: 2,981; yacc: 1,341; python: 389
file content (113 lines) | stat: -rw-r--r-- 2,621 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
 * boot.c: Lotus 123 support for Gnumeric
 *
 * Authors:
 *    See: README
 *    Michael Meeks <mmeeks@gnu.org>
 *    Morten Welinder (terra@gnome.org)
 **/
#include <gnumeric-config.h>
#include <glib/gi18n-lib.h>
#include <gnumeric.h>
#include "lotus.h"
#include "lotus-formula.h"
#include "lotus-types.h"

#include <goffice/goffice.h>
#include <workbook-view.h>
#include <gnm-plugin.h>
#include <gutils.h>

#include <gsf/gsf-input.h>
#include <gsf/gsf-utils.h>

GNM_PLUGIN_MODULE_HEADER;

G_MODULE_EXPORT gboolean lotus_file_probe (GOFileOpener const *fo, GsfInput *input,
                           GOFileProbeLevel pl);
G_MODULE_EXPORT void     lotus_file_open (GOFileOpener const *fo, GOIOContext *io_context,
                          WorkbookView *wb_view, GsfInput *input);


gboolean
lotus_file_probe (GOFileOpener const *fo, GsfInput *input, GOFileProbeLevel pl)
{
	char const *h = NULL;
	int len;
	LotusVersion version;

	if (!gsf_input_seek (input, 0, G_SEEK_SET))
		h = gsf_input_read (input, 6, NULL);

	if (h == NULL ||
	    (GSF_LE_GET_GUINT16 (h + 0) != LOTUS_BOF &&
		GSF_LE_GET_GUINT16 (h + 0) != WORKS_BOF))
		return FALSE;

	len = GSF_LE_GET_GUINT16 (h + 2);
	if (len < 2)
		return FALSE;

	version = GSF_LE_GET_GUINT16 (h + 4);
	switch (version) {
	case LOTUS_VERSION_ORIG_123:
	case LOTUS_VERSION_SYMPHONY:
	case LOTUS_VERSION_SYMPHONY2:
		return len == 2;

	case LOTUS_VERSION_123V4: /* Barely and crudely handled.  */
	case LOTUS_VERSION_123V6:
	case LOTUS_VERSION_123V7:
	case LOTUS_VERSION_123SS98:
		return len >= 19;

	default:
		return FALSE;
	}
}

void
lotus_file_open (GOFileOpener const *fo, GOIOContext *io_context,
                 WorkbookView *wb_view, GsfInput *input)
{
	LotusState state;

	state.input	 = input;
	state.io_context = io_context;
	state.wbv	 = wb_view;
	state.wb	 = wb_view_get_workbook (wb_view);
	state.sheet	 = NULL;
	state.sheet_area_error = FALSE;
	state.style_pool = NULL;
	state.fonts      = NULL;
	state.works_conv = (GIConv)(-1);

	if (!lotus_read (&state))
		go_io_error_string (io_context,
			_("Error while reading lotus workbook."));

	if (state.style_pool)
		g_hash_table_destroy (state.style_pool);
	if (state.fonts)
		g_hash_table_destroy (state.fonts);
	if (state.works_conv != (GIConv)(-1))
		gsf_iconv_close (state.works_conv);
}



G_MODULE_EXPORT void
go_plugin_init (G_GNUC_UNUSED GOPlugin *plugin,
		G_GNUC_UNUSED GOCmdContext *cc)
{
	lmbcs_init ();
	lotus_formula_init ();
}

G_MODULE_EXPORT void
go_plugin_shutdown (G_GNUC_UNUSED GOPlugin *plugin,
		    G_GNUC_UNUSED GOCmdContext *cc)
{
	lotus_formula_shutdown ();
	lmbcs_shutdown ();
}