/** * gsf_init : * * Initializes the GSF library **/ void gsf_init (void) { static gboolean libgsf_initialized = FALSE; if (libgsf_initialized) return; #ifdef ENABLE_NLS #ifdef G_OS_WIN32 { char *pkg_dir = g_win32_get_package_installation_directory_of_module (gsf_dll_hmodule); gchar *locale_dir = g_build_filename (pkg_dir, "lib/locale", NULL); bindtextdomain (GETTEXT_PACKAGE, locale_dir); g_free (locale_dir); g_free (pkg_dir); } #else bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); #endif bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); #endif g_type_init (); #ifndef HAVE_G_BASE64_ENCODE base64_init (); #endif #ifdef _GSF_GTYPE_THREADING_FIXED if (NULL == static_type_module) { static_type_module = g_object_new (gsf_dummy_type_module_get_type(), NULL); g_assert (static_type_module != NULL); g_type_module_use (static_type_module); g_type_module_set_name (static_type_module, "libgsf-builtin"); } #else gsf_init_dynamic (NULL); #endif { /* Little-endian representation of M_PI. */ static guint8 pibytes[8] = { 0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40 }; /* * If this fails, see * http://bugzilla.gnome.org/show_bug.cgi?id=350973 */ double pi = gsf_le_get_double (pibytes); if (!(pi > 3.14 && pi < 3.15)) g_error ("Compilation trouble with endianess."); } }
static void qpro_parse_formula (QProReadState *state, int col, int row, guint8 const *data, guint8 const *end) { guint16 magic, ref_offset; #if 0 int flags = GSF_LE_GET_GUINT16 (data + 8); int length = GSF_LE_GET_GUINT16 (data + 10); #endif GnmValue *val; GSList *stack = NULL; GnmExprTop const *texpr = NULL; guint8 const *refs, *fmla; #ifdef DEBUG_MISSING dump_missing_functions (); #endif Q_CHECK_CONDITION (end - data >= 14); magic = GSF_LE_GET_GUINT16 (data + 6) & 0x7ff8; ref_offset = GSF_LE_GET_GUINT16 (data + 12); fmla = data + 14; refs = fmla + ref_offset; Q_CHECK_CONDITION (refs <= end); #if 0 puts (cell_coord_name (col, row)); gsf_mem_dump (data, 14); gsf_mem_dump (fmla, refs-fmla); gsf_mem_dump (refs, end-refs); #endif while (fmla < refs && *fmla != QPRO_OP_EOF) { QProOperators op = *fmla++; GnmExpr const *expr = NULL; #if 0 g_print ("Operator %d.\n", op); #endif switch (op) { case QPRO_OP_CONST_FLOAT: Q_CHECK_CONDITION (refs - fmla >= 8); expr = gnm_expr_new_constant (value_new_float ( gsf_le_get_double (fmla))); fmla += 8; break; case QPRO_OP_CELLREF: { GnmCellRef ref; guint16 tmp; Q_CHECK_CONDITION (end - refs >= 6); tmp = GSF_LE_GET_GUINT16 (refs + 4); ref.sheet = NULL; ref.col = *((gint8 *)(refs + 2)); ref.col_relative = (tmp & 0x4000) ? TRUE : FALSE; ref.row_relative = (tmp & 0x2000) ? TRUE : FALSE; if (ref.row_relative) ref.row = (int)(((gint16)((tmp & 0x1fff) << 3)) >> 3); else ref.row = tmp & 0x1fff; expr = gnm_expr_new_cellref (&ref); refs += 6; break; } case QPRO_OP_RANGEREF: { GnmCellRef a, b; guint16 tmp; Q_CHECK_CONDITION (end - refs >= 10); tmp = GSF_LE_GET_GUINT16 (refs + 4); a.sheet = NULL; a.col = *((gint8 *)(refs + 2)); a.col_relative = (tmp & 0x4000) ? TRUE : FALSE; a.row_relative = (tmp & 0x2000) ? TRUE : FALSE; if (a.row_relative) a.row = (int)(((gint16)((tmp & 0x1fff) << 3)) >> 3); else a.row = tmp & 0x1fff; tmp = GSF_LE_GET_GUINT16 (refs + 8); b.sheet = NULL; b.col = *((gint8 *)(refs + 6)); b.col_relative = (tmp & 0x4000) ? TRUE : FALSE; b.row_relative = (tmp & 0x2000) ? TRUE : FALSE; if (b.row_relative) b.row = (int)(((gint16)((tmp & 0x1fff) << 3)) >> 3); else b.row = tmp & 0x1fff; expr = gnm_expr_new_constant ( value_new_cellrange_unsafe (&a, &b)); refs += 10; break; }