static gboolean x3p_parse_main(unzFile *zipfile, X3PFile *x3pfile, GError **error) { GMarkupParser parser = { &x3p_start_element, &x3p_end_element, &x3p_text, NULL, NULL, }; GMarkupParseContext *context = NULL; guchar *content = NULL, *s; gboolean ok = FALSE; gwy_debug("calling unzLocateFile() to find main.xml"); if (unzLocateFile(zipfile, "main.xml", 1) != UNZ_OK) { g_set_error(error, GWY_MODULE_FILE_ERROR, GWY_MODULE_FILE_ERROR_IO, _("File %s is missing in the zip file."), "main.xml"); return FALSE; } if (!(content = x3p_get_file_content(zipfile, NULL, error))) return FALSE; gwy_strkill(content, "\r"); s = content; /* Not seen in the wild but the XML people tend to use BOM in UTF-8... */ if (g_str_has_prefix(s, BLOODY_UTF8_BOM)) s += strlen(BLOODY_UTF8_BOM); if (!x3pfile->path) x3pfile->path = g_string_new(NULL); if (!x3pfile->hash) x3pfile->hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); context = g_markup_parse_context_new(&parser, 0, x3pfile, NULL); if (!g_markup_parse_context_parse(context, s, -1, error)) goto fail; if (!g_markup_parse_context_end_parse(context, error)) goto fail; ok = TRUE; fail: if (context) g_markup_parse_context_free(context); g_free(content); return ok; }
/** * gwy_app_recent_file_list_load: * @filename: Name of file containing list of recently open files. * * Loads list of recently open files from @filename. * * Cannot be called more than once (at least not without doing * gwy_app_recent_file_list_free() first). Must be called before any other * document history function can be used, even if on a nonexistent file: * use %NULL as @filename in that case. * * Returns: %TRUE if the file was read successfully, %FALSE otherwise. **/ gboolean gwy_app_recent_file_list_load(const gchar *filename) { GtkTreeIter iter; GError *err = NULL; gchar *buffer = NULL; gsize size = 0; gchar **files; guint n, nrecent; gwy_app_recent_file_create_dirs(); g_return_val_if_fail(gcontrols.store == NULL, FALSE); gcontrols.store = gtk_list_store_new(1, G_TYPE_POINTER); if (!filename) return TRUE; if (!g_file_get_contents(filename, &buffer, &size, &err)) { g_clear_error(&err); return FALSE; } #ifdef G_OS_WIN32 gwy_strkill(buffer, "\r"); #endif files = g_strsplit(buffer, "\n", 0); g_free(buffer); if (!files) return TRUE; nrecent = _gwy_app_get_n_recent_files(); for (n = 0; files[n]; n++) { if (*files[n]) { GwyRecentFile *rf; gwy_debug("%s", files[n]); rf = gwy_app_recent_file_new(gwy_canonicalize_path(files[n]), NULL); gtk_list_store_insert_with_values(gcontrols.store, &iter, G_MAXINT, FILELIST_RAW, rf, -1); if (n < nrecent) { gcontrols.recent_file_list = g_list_append(gcontrols.recent_file_list, rf->file_utf8); } } g_free(files[n]); } g_free(files); return TRUE; }
/** * gwy_graph_func_register: * @modname: Module identifier (name). * @func_info: Data graphing function info. * * Registeres a data graphing function. * * To keep compatibility with old versions @func_info should not be an * automatic variable. However, since 1.6 it keeps a copy of @func_info. * * Returns: %TRUE on success, %FALSE on failure. **/ gboolean gwy_graph_func_register(const gchar *modname, GwyGraphFuncInfo *func_info) { _GwyModuleInfoInternal *iinfo; GraphFuncInfo *gfinfo; gchar *canon_name; gwy_debug(""); gwy_debug("name = %s, menu path = %s, func = %p", func_info->name, func_info->menu_path, func_info->graph); if (!graph_funcs) { gwy_debug("Initializing..."); graph_funcs = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, gwy_graph_func_info_free); } iinfo = gwy_module_get_module_info(modname); g_return_val_if_fail(iinfo, FALSE); g_return_val_if_fail(func_info->graph, FALSE); g_return_val_if_fail(func_info->name, FALSE); if (g_hash_table_lookup(graph_funcs, func_info->name)) { g_warning("Duplicate function %s, keeping only first", func_info->name); return FALSE; } gfinfo = g_new0(GraphFuncInfo, 1); gfinfo->info = *func_info; gfinfo->info.name = g_strdup(func_info->name); gfinfo->info.menu_path = g_strdup(func_info->menu_path); gfinfo->menu_path_translated = _(func_info->menu_path); gfinfo->menu_path_factory = gwy_strkill(g_strdup(gfinfo->menu_path_translated), "_"); g_hash_table_insert(graph_funcs, (gpointer)gfinfo->info.name, gfinfo); canon_name = g_strconcat(GWY_MODULE_PREFIX_GRAPH, gfinfo->info.name, NULL); iinfo->funcs = g_slist_append(iinfo->funcs, canon_name); if (func_register_callback) func_register_callback(canon_name); return TRUE; }
static GwySpectra* rhkspm32_read_spectra(RHKPage *rhkpage) { guint i, j; gdouble *data; GwySIUnit *siunit = NULL; GwyDataLine *dline; GwySpectra *spectra = NULL; GPtrArray *spectrum = NULL; // i'm leaving this alone, though it probably doesn't make sense, // and i should just create graphs straight away - but in case of // future use, i'll just convert the data later to graphs // xres stores number of data points per spectra, // yres stores the number of spectra // reading data gwy_debug("rhk-spm32: %d spectra in this page\n", rhkpage->yres); for (i = 0; i < rhkpage->yres; i++) { dline = gwy_data_line_new(rhkpage->xres, rhkpage->x.scale, FALSE); gwy_data_line_set_offset(dline, (rhkpage->x.offset)); data = gwy_data_line_get_data(dline); // store line data in physical units - which are the z values, not y if ((rhkpage->data_type) == RHK_DATA_INT16) { const guint16 *p = (const guint16*)(rhkpage->buffer + rhkpage->data_offset); for (j = 0; j < rhkpage->xres; j++) { data[j] = GINT16_FROM_LE(p[i*(rhkpage->xres) + j]) *(rhkpage->z.scale)+(rhkpage->z.offset); } } else if ((rhkpage->data_type) == RHK_DATA_SINGLE) { const guchar *p = (const guchar*)(rhkpage->buffer + rhkpage->data_offset); for (j = 0; j < rhkpage->xres; j++) { data[j] = gwy_get_gfloat_le(&p)*rhkpage->z.scale + rhkpage->z.offset; } } siunit = gwy_si_unit_new(rhkpage->x.units); gwy_data_line_set_si_unit_x(dline, siunit); g_object_unref(siunit); // the y units (and data) for a 1D graph are stored in Z in the rhk // spm32 format! /* Fix "/\xfbHz" to "/Hz". * XXX: It might be still wrong as the strange character might mean * sqrt. */ if (g_str_has_suffix(rhkpage->z.units, "/\xfbHz")) { gchar *s = gwy_strkill(g_strdup(rhkpage->z.units), "\xfb"); siunit = gwy_si_unit_new(s); g_free(s); } else siunit = gwy_si_unit_new(rhkpage->z.units); gwy_data_line_set_si_unit_y(dline, siunit); g_object_unref(siunit); if (!spectrum) spectrum = g_ptr_array_sized_new(rhkpage->yres); g_ptr_array_add(spectrum, dline); } gwy_debug("rhk-spm32: finished parsing sps data\n"); spectra = gwy_spectra_new(); for (i = 0; i < rhkpage->yres; i++) { dline = g_ptr_array_index(spectrum, i); // since RHK spm32 does not record where it took the spectra, // i'm setting these to zero gwy_spectra_add_spectrum(spectra, dline, 0, 0); g_object_unref(dline); } gwy_spectra_set_title(spectra, rhkpage->label); if (spectrum) g_ptr_array_free(spectrum, TRUE); return spectra; }