Example #1
0
static void add_tree_model(GtkTreeStore *tree_model, GtkTreeIter*parent, const std::list<StarDictPluginInfo> &infolist)
{
	plugininfo_ParseUserData Data;
	GMarkupParser parser;
	parser.start_element = plugininfo_parse_start_element;
	parser.end_element = plugininfo_parse_end_element;
	parser.text = plugininfo_parse_text;
	parser.passthrough = NULL;
	parser.error = NULL;
	GtkTreeIter iter;
	for (std::list<StarDictPluginInfo>::const_iterator i = infolist.begin(); i != infolist.end(); ++i) {
		Data.info_str = NULL;
		Data.detail_str = NULL;
		Data.filename = i->filename;
		GMarkupParseContext* context = g_markup_parse_context_new(&parser, (GMarkupParseFlags)0, &Data, NULL);
		g_markup_parse_context_parse(context, i->info_xml.c_str(), -1, NULL);
		g_markup_parse_context_end_parse(context, NULL);
		g_markup_parse_context_free(context);
		gtk_tree_store_append(tree_model, &iter, parent);
		bool loaded = gpAppFrame->oStarDictPlugins->get_loaded(i->filename.c_str());
		gtk_tree_store_set(tree_model, &iter, 0, true, 1, loaded, 2, Data.info_str, 3, Data.detail_str, 4, i->filename.c_str(), 5, i->plugin_type, 6, i->can_configure, -1);
		g_free(Data.info_str);
		g_free(Data.detail_str);
	}
}
Example #2
0
/* CURRENT - grisu xml parsing (1) file lists & 2) job description) */
gpointer grisu_xml_parse(const gchar *xml_text)
{
GMarkupParser xml_parser;
GMarkupParseContext *xml_context;
GError *error;
GSList *file_list=NULL;

xml_parser.start_element = &grisu_xml_start;
xml_parser.end_element = &grisu_xml_end;
xml_parser.text = &grisu_xml_text;
xml_parser.passthrough = NULL;
xml_parser.error = NULL;

xml_context = g_markup_parse_context_new(&xml_parser, 0, &file_list, NULL);

if (!g_markup_parse_context_parse(xml_context, xml_text, strlen(xml_text), &error))
    printf("grisu_xml_parse() : parsing error.\n");

/* cleanup */
if (!g_markup_parse_context_end_parse(xml_context, &error))
  printf("grisu_xml_parse() : errors occurred processing xml.\n");

g_markup_parse_context_free(xml_context);

return(file_list);
}
Example #3
0
gboolean
gom_signal_init (GError **error)
{
    gboolean ret;
    char *api;
    gsize apilen;
    GMarkupParseContext *cx;
    SignalParserData data = { NULL };

    if (!g_file_get_contents ("gtk-api.raw", &api, &apilen, &error)) {
        return FALSE;
    }
    
    signals = g_hash_table_new_full (g_int_hash, g_int_equal, NULL, free_node);

    cx = g_markup_parse_context_new (&signal_parser, 0, &data, NULL);
    ret = g_markup_parse_context_parse (cx, script, scriptlen, &error);
    if (ret) {
        ret = g_markup_parse_context_end_parse (cx, &error);
    }

    free_node (data.signal);

    g_markup_parse_context_free (cx);

    return ret;
}
Example #4
0
dle_t *
amxml_parse_node_CHAR(
    char *txt,
    char **errmsg)
{
    amgxml_t             amgxml = {NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
    GMarkupParser        parser = {&amstart_element, &amend_element, &amtext,
				   NULL, NULL};
    GMarkupParseFlags    flags = 0;
    GMarkupParseContext *context;
    GError		*gerror = NULL;

    (void)errmsg;

    context = g_markup_parse_context_new(&parser, flags, &amgxml, NULL);

    g_markup_parse_context_parse(context, txt, strlen(txt), &gerror);
    if (!gerror)
	g_markup_parse_context_end_parse(context, &gerror);
    g_markup_parse_context_free(context);
    if (gerror) {
	if (errmsg)
	    *errmsg = stralloc(gerror->message);
	g_error_free(gerror);
    }
    return amgxml.dles;
	
}
Example #5
0
GValue*
ghb_resource_parse(const gchar *buf, gssize len)
{
	GMarkupParseContext *ctx;
	GMarkupParser parser;
	parse_data_t pd;
	GError *err = NULL;

	pd.stack = g_queue_new();
	pd.tag_stack = g_queue_new();
	pd.key = NULL;
	pd.value = NULL;
	pd.plist = ghb_dict_value_new();
	g_queue_push_head(pd.stack, pd.plist);
	pd.closed_top = FALSE;

	parser.start_element = start_element;
	parser.end_element = end_element;
	parser.text = text_data;
	parser.passthrough = passthrough;
	parser.error = parse_error;
	ctx = g_markup_parse_context_new(&parser, 0, &pd, destroy_notify);

	g_markup_parse_context_parse(ctx, buf, len, &err);
	g_markup_parse_context_end_parse(ctx, &err);
	g_markup_parse_context_free(ctx);
	g_queue_free(pd.stack);
	g_queue_free(pd.tag_stack);
	return pd.plist;
}
Example #6
0
dle_t *
amxml_parse_node_FILE(
    FILE *file,
    char **errmsg)
{
    amgxml_t             amgxml = {NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
    GMarkupParser        parser = {&amstart_element, &amend_element, &amtext,
				   NULL, NULL};
    GMarkupParseFlags    flags = 0;
    GMarkupParseContext *context;
    GError		*gerror = NULL;
    char                *line;

    (void)errmsg;

    context = g_markup_parse_context_new(&parser, flags, &amgxml, NULL);

    while ((line = agets(file)) != NULL && !gerror) {
	g_markup_parse_context_parse(context, line, strlen(line), &gerror);
	amfree(line);
    }
    if (!gerror)
	g_markup_parse_context_end_parse(context, &gerror);
    g_markup_parse_context_free(context);
    if (gerror) {
	if (errmsg)
	    *errmsg = stralloc(gerror->message);
	g_error_free(gerror);
    }
    return amgxml.dles;
}
static DeskmenuObject
*deskmenu_parse_file (gchar *filename)
{
	GError *error = NULL;
	DeskmenuObject *dm_object = deskmenu_object_init();
	GMarkupParseContext *context = g_markup_parse_context_new (&parser,
		0, dm_object, NULL);

	gchar *text;
	gsize length;

	g_file_get_contents (filename, &text, &length, NULL); //cache already handled file existence check

	if (!g_markup_parse_context_parse (context, text, strlen(text), &error)
		|| !g_markup_parse_context_end_parse (context, &error))
	{
		g_printerr ("Parse failed with message: %s \n", error->message);
		g_error_free (error);
		exit (1);
	}

	g_free(text); //free the joined array
	g_markup_parse_context_free (context); //free the parser

	gtk_widget_show_all (dm_object->menu);
	return dm_object;
}
Example #8
0
/********************************
* EntityCompiler_ScanErrors
* compiles entity file
@ string_inputfile
@ logwidget:  TextView Widget to output errors to.
@ textwidget: TextView Widget to mark with errors.
*/
gboolean EntityCompiler_ScanErrors( gchar * compiler_output, GtkWidget * logwidget, GtkWidget * textwidget )
{

	EntityErrorInfo eeinfo;
	GMarkupParseContext * ctx;

	eeinfo.filename = NULL;
	eeinfo.log = logwidget;
	eeinfo.text = textwidget;
	eeinfo.error = FALSE;


	GError  * err = NULL;
	ctx = g_markup_parse_context_new( &entity_error_parser, (GMarkupParseFlags)0, &eeinfo, NULL );
	g_markup_parse_context_parse( ctx, compiler_output, -1, &err );
	if ( err == NULL )
	{
		g_markup_parse_context_end_parse( ctx, &err );
	}
	g_markup_parse_context_free( ctx );
	if ( err != NULL )
	{
		eeinfo.error = TRUE;
		Logger_FormattedLog( eeinfo.log, LOG_ERROR, "Entity Unknown Error:\n%s\n\n%s\n", err->message, compiler_output);
		g_clear_error(&err);
	}
	return eeinfo.error;

}
Example #9
0
static gboolean
parse (GMarkupParseContext *pcontext,
       GInputStream        *input,
       GError             **error)
{
    gchar buffer[BUFSIZE];

    while (1) {
        gssize nread = g_input_stream_read (input,
                                            buffer,
                                            sizeof (buffer),
                                            NULL,
                                            error);
        if (nread < 0)
            return FALSE;

        if (nread == 0)
            break;

        if (!g_markup_parse_context_parse (pcontext, buffer, nread, error))
            return FALSE;
    }

    return g_markup_parse_context_end_parse (pcontext, error);
}
/* prefs_load_xml_from:
 *	creates GMarkupParserContext for parsing the prefs
 */
static void
prefs_load_xml_from(const gchar * prefs_filename, FILE * prefs_f)
{
	GMarkupParser parser;
	GMarkupParseContext * context;
	gchar * buf;
	gsize buf_bytes;
	GError * error = NULL;
	struct prefs_parser_state * state;

	parser.start_element = prefs_load_xml_start_element;
	parser.end_element = prefs_load_xml_end_element;
	parser.text = prefs_load_xml_text;
	parser.passthrough = NULL;
	parser.error = NULL;

	state = g_new(struct prefs_parser_state, 1);
	state->tag = PREFS_TAG_NO_TAG;
	state->pref_name = g_string_new(NULL);

	context = g_markup_parse_context_new(
		&parser, 0, (gpointer)state,
		(GDestroyNotify)prefs_free_parser_state);

	buf = g_malloc(4096);

	while(!feof(prefs_f)) {
		buf_bytes = fread(buf, 1, 4096, prefs_f);
		if(buf_bytes < 4096 && ferror(prefs_f)) {
			log_ferror(_(LOG_PREFS),
				g_strdup_printf(_("Error while reading "
						"configuration file \"%s\": %s"),
					prefs_filename, strerror(errno)));

			goto bail_out;
		}

		if(buf_bytes)
			if(g_markup_parse_context_parse(context, buf, buf_bytes, &error)==FALSE)
				goto parse_error;
	}

	if(g_markup_parse_context_end_parse(context, &error)==TRUE) {
		/* parse ok */
		goto bail_out;
	}

parse_error:
	log_ferror(_(LOG_PREFS),
		g_strdup_printf(_("Error parsing configuration from \"%s\": %s"),
			prefs_filename, error->message));

	g_error_free(error);

bail_out:
	g_free(buf);
	g_markup_parse_context_free(context);

}
static GMarkupParseContext *
create_parser_context (GESBaseXmlFormatter * self, const gchar * uri,
    GError ** error)
{
  gsize xmlsize;
  GFile *file = NULL;
  gchar *xmlcontent = NULL;
  GMarkupParseContext *parsecontext = NULL;
  GESBaseXmlFormatterClass *self_class =
      GES_BASE_XML_FORMATTER_GET_CLASS (self);

  GError *err = NULL;

  GST_DEBUG_OBJECT (self, "loading xml from %s", uri);

  file = g_file_new_for_uri (uri);

  /* TODO Handle GCancellable */
  if (!g_file_query_exists (file, NULL)) {
    err = g_error_new (GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED,
        "Invalid URI: \"%s\"", uri);
    goto failed;
  }

  if (!g_file_load_contents (file, NULL, &xmlcontent, &xmlsize, NULL, &err))
    goto failed;

  if (g_strcmp0 (xmlcontent, "") == 0)
    goto failed;

  parsecontext = g_markup_parse_context_new (&self_class->content_parser,
      G_MARKUP_TREAT_CDATA_AS_TEXT, self, NULL);

  if (g_markup_parse_context_parse (parsecontext, xmlcontent, xmlsize,
          &err) == FALSE)
    goto failed;

  if (!g_markup_parse_context_end_parse (parsecontext, &err))
    goto failed;


done:
  g_free (xmlcontent);
  g_object_unref (file);

  return parsecontext;

failed:
  GST_WARNING ("failed to load contents from \"%s\"", uri);
  g_propagate_error (error, err);

  if (parsecontext) {
    g_markup_parse_context_free (parsecontext);
    parsecontext = NULL;
  }

  goto done;
}
Example #12
0
/**********************************************************************
 * errlog2event_hash_init:
 * @custom_handle: Plugin's data pointer.
 * 
 * Initializes the Error Log to event translation hash table.
 *
 * Returns:
 * SA_OK - Normal operation.
 * SA_ERR_HPI_OUT_OF_SPACE - No memory to allocate hash table structures.
 * SA_ERR_HPI_INVALID_PARAMS - @custom_handle NULL
 **********************************************************************/
SaErrorT errlog2event_hash_init(struct snmp_bc_hnd *custom_handle) {
        GMarkupParser parser;
        GMarkupParseContext *pcontext;
        gboolean rc;
        GError *err = NULL;
	struct errlog2event_hash_info user_data;

	if (!custom_handle) {
		dbg("Invalid parameter.");
		return(SA_ERR_HPI_INVALID_PARAMS);
	}

	/* Initialize hash table */
	errlog2event_hash = g_hash_table_new(g_str_hash, g_str_equal);
	if (errlog2event_hash == NULL) {
		dbg("No memory.");
		return(SA_ERR_HPI_OUT_OF_SPACE);
	}
	
	/* Initialize user data used in parsing XML events */
	user_data.platform = custom_handle->platform;
	user_data.hashtable = errlog2event_hash;

        /* Initialize XML parser */
        memset(&parser, 0, sizeof(parser));
        parser.start_element = event_start_element;
        pcontext = g_markup_parse_context_new(&parser, 0, &user_data, NULL);
        if (pcontext == NULL) {
		dbg("No memory.");
		return(SA_ERR_HPI_OUT_OF_SPACE);
        }

        /* Parse XML events */
        rc = g_markup_parse_context_parse(pcontext,
                                          (const gchar *)eventxml,
                                          (gssize)strlen(eventxml), &err);
        if (rc == FALSE || err != NULL) {
                if (err != NULL) {
                        dbg("Parse error=%s.", err->message);
                        g_error_free(err);
                }
                else {
                        dbg("Unknown XML parse error.");
                }
                g_markup_parse_context_free(pcontext);
                return(SA_ERR_HPI_INTERNAL_ERROR);
        }
        g_markup_parse_context_end_parse(pcontext, &err);
        g_markup_parse_context_free(pcontext);

        /* Make sure there are elements in the hash table */
        if (g_hash_table_size(errlog2event_hash) == 0) {
                dbg("Hash table is empty.");
                return(SA_ERR_HPI_INTERNAL_ERROR);
        }

	return(SA_OK);
}
Example #13
0
gboolean
xml_parser_end_parse (XMLParser  *parser,
                      GError  **error)
{
  g_return_val_if_fail (parser != NULL, FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  return g_markup_parse_context_end_parse (parser->context, error);
}
Example #14
0
static int
test_file (const gchar *filename)
{
    gchar *contents;
    gsize  length;
    GError *error;
    GMarkupParseContext *context;

    error = NULL;
    if (!g_file_get_contents (filename,
                              &contents,
                              &length,
                              &error))
    {
        fprintf (stderr, "%s\n", error->message);
        g_error_free (error);
        return 1;
    }

    context = g_markup_parse_context_new (&parser, 0, NULL, NULL);

    if (!g_markup_parse_context_parse (context, contents, length, NULL))
    {
        g_markup_parse_context_free (context);
        return 1;
    }

    if (!g_markup_parse_context_end_parse (context, NULL))
    {
        g_markup_parse_context_free (context);
        return 1;
    }

    g_markup_parse_context_free (context);

    /* A byte at a time */
    if (test_in_chunks (contents, length, 1) != 0)
        return 1;

    /* 2 bytes */
    if (test_in_chunks (contents, length, 2) != 0)
        return 1;

    /*5 bytes */
    if (test_in_chunks (contents, length, 5) != 0)
        return 1;

    /* 12 bytes */
    if (test_in_chunks (contents, length, 12) != 0)
        return 1;

    /* 1024 bytes */
    if (test_in_chunks (contents, length, 1024) != 0)
        return 1;

    return 0;
}
Example #15
0
static gboolean android_apndb_parse(const GMarkupParser *parser,
					gpointer userdata,
					GError **error)
{
	struct stat st;
	char *db;
	int fd;
	GMarkupParseContext *context;
	gboolean ret;
	const char *apndb_path;

	if ((apndb_path = getenv("OFONO_APNDB_PATH")) == NULL)
		apndb_path = ANDROID_APN_DATABASE;

	fd = open(apndb_path, O_RDONLY);
	if (fd < 0) {
		g_set_error(error, G_FILE_ERROR,
				g_file_error_from_errno(errno),
				"open(%s) failed: %s", apndb_path,
				g_strerror(errno));
		return FALSE;
	}

	if (fstat(fd, &st) < 0) {
		close(fd);
		g_set_error(error, G_FILE_ERROR,
				g_file_error_from_errno(errno),
				"fstat(%s) failed: %s", apndb_path,
				g_strerror(errno));
		return FALSE;
	}

	db = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
	if (db == MAP_FAILED) {
		close(fd);
		g_set_error(error, G_FILE_ERROR,
				g_file_error_from_errno(errno),
				"mmap(%s) failed: %s", apndb_path,
				g_strerror(errno));
		return FALSE;
	}

	context = g_markup_parse_context_new(parser,
						G_MARKUP_TREAT_CDATA_AS_TEXT,
						userdata, NULL);

	ret = g_markup_parse_context_parse(context, db, st.st_size, error);

	if (ret == TRUE)
		g_markup_parse_context_end_parse(context, error);

	munmap(db, st.st_size);
	close(fd);
	g_markup_parse_context_free(context);

	return ret;
}
Example #16
0
XMLNode *
ibus_xml_parse_file (const gchar *filename)
{
    gboolean retval;
    GError *error = NULL;
    FILE *pf = fopen (filename, "r");

    if (pf == NULL) {
        return NULL;
    }

    GMarkupParseContext *context;
    XMLNode *node;

    const static GMarkupParser root_parser = {
        _start_root_element_cb,
        _end_element_cb,
        _text_cb,
        0,
        0,
    };

    do {
        context = g_markup_parse_context_new (&root_parser, 0, &node, 0);

        while (!feof (pf)) {
            gchar buf[1024];
            gssize len = 0;

            len = fread (buf, 1, sizeof (buf), pf);
            retval = g_markup_parse_context_parse (context, buf, len, &error);

            if (!retval)
                break;
        }
        fclose (pf);

        if (!retval)
            break;

        retval = g_markup_parse_context_end_parse (context, &error);
        if (!retval)
            break;

        g_markup_parse_context_free (context);

        return node;
    } while (0);

    g_warning ("Parse %s failed: %s", filename, error->message);
    g_error_free (error);
    g_markup_parse_context_free (context);
    return NULL;
}
Example #17
0
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;
}
Example #18
0
/**
 * xmp_parse_context_end_parse:
 * @context: a #XMPParseContext
 * @error: return location for a #GError
 *
 * Signals to the #XMPParseContext that all data has been fed into the
 * parse context with xmp_parse_context_parse().  This function
 * reports an error if the document did not contain any XMP packet or
 * if the document isn't complete, for example if elements are still
 * open.
 *
 * Return value: %TRUE on success, %FALSE if an error was set
 **/
gboolean
xmp_parse_context_end_parse (XMPParseContext  *context,
                             GError          **error)
{
  g_return_val_if_fail (context != NULL, FALSE);
  g_return_val_if_fail (context->state != STATE_ERROR, FALSE);

  if (context->state == STATE_START)
    parse_error (context, error, XMP_ERROR_NO_XPACKET, NULL);

  return g_markup_parse_context_end_parse (context->markup_context, error);
}
Example #19
0
/**
 * Function reading an XML file specifying a country.
 * The variable #country gets freed and overwritten afterwards.
 * @param lg_commentary_name name of the xml file (e.g. 'lg_commentary_england.xml')
 * to be read. Full path is not necessary, if the file is located in
 * one of the suppport directories; neither are the prefix 'lg_commentary_'
 * or the suffix '.xml'.
 */
void
xml_lg_commentary_read(const gchar *commentary_file)
{
#ifdef DEBUG
    printf("xml_lg_commentary_read\n");
#endif

    GMarkupParser parser = {xml_lg_commentary_read_start_element,
			    xml_lg_commentary_read_end_element,
			    xml_lg_commentary_read_text, NULL, NULL};
    GMarkupParseContext *context;
    gchar *file_contents;
    gsize length;
    GError *error = NULL;

    context = 
	g_markup_parse_context_new(&parser, 0, NULL, NULL);

    if(!g_file_get_contents(commentary_file, &file_contents, &length, &error))
    {
	debug_print_message("xml_lg_commentary_read: error reading file %s\n", commentary_file);
	if(g_str_has_suffix(commentary_file, "lg_commentary_en.xml"))
	    misc_print_error(&error, TRUE);
	else
	{
	    misc_print_error(&error, FALSE);
	    lg_commentary_load_commentary_file("lg_commentary_en.xml", TRUE);
	}
	return;
    }

    free_lg_commentary(TRUE);

    if(g_markup_parse_context_parse(context, file_contents, length, &error))
    {
	g_markup_parse_context_end_parse(context, NULL);	
	g_markup_parse_context_free(context);
	g_free(file_contents);
    }
    else
    {
	debug_print_message("xml_lg_commentary_read: error parsing file %s\n", commentary_file);
	if(g_str_has_suffix(commentary_file, "lg_commentary_en.xml"))
	    misc_print_error(&error, TRUE);
	else
	{
	    misc_print_error(&error, FALSE);
	    lg_commentary_load_commentary_file("lg_commentary_en.xml", TRUE);
	}
	return;
    }
}
void parse_definition(gchar *p, ParseUserData *Data)
{
	GMarkupParser parser;
        parser.start_element = func_parse_start_element;
        parser.end_element = NULL;
        parser.text = NULL;
        parser.passthrough = func_parse_passthrough;
        parser.error = func_parse_error;
        GMarkupParseContext* context = g_markup_parse_context_new(&parser, (GMarkupParseFlags)0, Data, NULL);
        g_markup_parse_context_parse(context, p, strlen(p), NULL);
        g_markup_parse_context_end_parse(context, NULL);
        g_markup_parse_context_free(context);
}
Example #21
0
static void
parse_into_text_tables (const gchar *directory,
                        GHashTable  *summaries,
                        GHashTable  *descriptions)
{
  GMarkupParser parser = { start_element, end_element, text };
  TextTableParseInfo info = { summaries, descriptions };
  const gchar *basename;
  GDir *dir;

  dir = g_dir_open (directory, 0, NULL);
  while ((basename = g_dir_read_name (dir)))
    {
      gchar *filename;
      gchar *contents;
      gsize size;

      filename = g_build_filename (directory, basename, NULL);
      if (g_file_get_contents (filename, &contents, &size, NULL))
        {
          GMarkupParseContext *context;

          context = g_markup_parse_context_new (&parser, G_MARKUP_TREAT_CDATA_AS_TEXT, &info, NULL);
          /* Ignore errors here, this is best effort only. */
          if (g_markup_parse_context_parse (context, contents, size, NULL))
            (void) g_markup_parse_context_end_parse (context, NULL);
          g_markup_parse_context_free (context);

          /* Clean up dangling stuff in case there was an error. */
          g_slist_free_full (info.gettext_domain, g_free);
          g_slist_free_full (info.schema_id, g_free);
          g_slist_free_full (info.key_name, g_free);

          info.gettext_domain = NULL;
          info.schema_id = NULL;
          info.key_name = NULL;

          if (info.string)
            {
              g_string_free (info.string, TRUE);
              info.string = NULL;
            }

          g_free (contents);
        }

      g_free (filename);
    }
  
  g_dir_close (dir);
}
Example #22
0
AppConfigInfo *
domain_test (char *text)
{
	AppConfigInfo *app_config = g_new0 (AppConfigInfo, 1);
	GMarkupParseContext *context;
	
        context = g_markup_parse_context_new (&mono_parser, 0, app_config, NULL);
        if (g_markup_parse_context_parse (context, text, strlen (text), NULL)) {
                g_markup_parse_context_end_parse (context, NULL);
        }
        g_markup_parse_context_free (context);

	return app_config;
}
Example #23
0
static void
mono_config_parse_xml_with_context (ParseState *state, const char *text, gsize len)
{
	GMarkupParseContext *context;

	if (!inited)
		mono_config_init ();

	context = g_markup_parse_context_new (&mono_parser, 0, state, NULL);
	if (g_markup_parse_context_parse (context, text, len, NULL)) {
		g_markup_parse_context_end_parse (context, NULL);
	}
	g_markup_parse_context_free (context);
}
Example #24
0
car_t *
carRead(char *file, GError **err)
{
	char *content;
	int flen;
	GMarkupParseContext *context;
	GMarkupParser parser;
	xmlcar_t *xc = g_new0(xmlcar_t,1);
	car_t *r;
	xc->car = carNew();
	g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
	
	parser.start_element = xmlcar_start;
	parser.end_element = xmlcar_end;
	parser.text = NULL;
	parser.passthrough = NULL;
	parser.error = xmlcar_error;
	
	if (!g_file_get_contents(file, &content, &flen, err))
		goto err;
	
	context = g_markup_parse_context_new(&parser, 0, xc, NULL);
	
	if (!g_markup_parse_context_parse(context, content, flen, err))
		goto err;

	if (!g_markup_parse_context_end_parse(context, err))
		goto err;

	g_free(content);
	r = xc->car;
	g_free(xc);
	

	if (carCheck(r))
	{
		carCountHP(r);
		carCountWheelTorques(r);
		carCountTimeline(r);
	}
	
	return r;

err:
	g_free(content);
	carFree(xc->car);
	g_free(xc);
	return NULL;
}
Example #25
0
/** Fill the name list with names from the
    given names file.
    @param sid The sid of the names file we read.
    @param namelist The name list we fill. */
void
xml_name_read(const gchar *sid, NameList *namelist)
{
#ifdef DEBUG
    printf("xml_name_read\n");
#endif

    gchar *file_name = NULL;
    GMarkupParser parser = {xml_name_read_start_element,
			    xml_name_read_end_element,
			    xml_name_read_text, NULL, NULL};
    GMarkupParseContext *context;
    gchar *file_contents;
    gsize length;
    GError *error = NULL;
    gchar buf[SMALL];

    sprintf(buf, "player_names_%s.xml", sid);
    file_name = file_find_support_file(buf, TRUE);

    context = 
	g_markup_parse_context_new(&parser, 0, NULL, NULL);

    if(!g_file_get_contents(file_name, &file_contents, &length, &error))
    {
	debug_print_message("xml_name_read: error reading file %s\n", file_name);
	misc_print_error(&error, TRUE);
	return;
    }

    free_name_list(namelist, TRUE);
    misc_string_assign(&namelist->sid, sid);

    nlist = namelist;

    if(g_markup_parse_context_parse(context, file_contents, length, &error))
    {
	g_markup_parse_context_end_parse(context, NULL);	
	g_markup_parse_context_free(context);
	g_free(file_contents);
    }
    else
    {
	g_critical("xml_name_read: error parsing file %s\n", buf);
	misc_print_error(&error, TRUE);
    }

    g_free(file_name);
}
Example #26
0
static gboolean
pdbtool_merge_file(const gchar *filename, GString *merged)
{
  GMarkupParseContext *parse_ctx = NULL;
  PdbToolMergeState state;
  GError *error = NULL;
  gboolean success = TRUE;
  gchar *buff = NULL;
  gsize buff_len;

  if (!g_file_get_contents(filename, &buff, &buff_len, &error))
    {
      fprintf(stderr, "Error reading pattern database file; filename='%s', error='%s'\n",
            filename, error ? error->message : "Unknown error");
      success = FALSE;
      goto error;
    }

  state.version = 0;
  state.merged = merged;
  state.in_rule = FALSE;

  parse_ctx = g_markup_parse_context_new(&pdbtool_merge_parser, 0, &state, NULL);
  if (!g_markup_parse_context_parse(parse_ctx, buff, buff_len, &error))
    {
      fprintf(stderr, "Error parsing pattern database file; filename='%s', error='%s'\n",
            filename, error ? error->message : "Unknown error");
      success = FALSE;
      goto error;
    }

  if (!g_markup_parse_context_end_parse(parse_ctx, &error))
    {
      fprintf(stderr, "Error parsing pattern database file; filename='%s', error='%s'\n",
            filename, error ? error->message : "Unknown error");
      success = FALSE;
      goto error;
    }

error:
  if (buff)
    g_free(buff);

  if (parse_ctx)
    g_markup_parse_context_free(parse_ctx);

  return success;
}
gint
grg_load_prefs (void)
{
	guchar *path, *content, active_opt = 0;
	gint fd, end;
	GMarkupParser *context =
		(GMarkupParser *) grg_malloc (sizeof (GMarkupParser));
	GMarkupParseContext *parser;
	GError *err = NULL;

	path = g_build_filename (g_get_home_dir (), ".gringotts.conf", NULL);
	fd = open (path, O_RDONLY);
	g_free (path);

	if (fd < 3)
	{
		close (fd);
		return GRG_PREFS_IO_ERROR;
	}

	end = lseek (fd, 0, SEEK_END);
	lseek (fd, 0, SEEK_SET);

	context->start_element = introduce_pref;
	context->end_element = NULL;
	context->text = collect_pref;
	context->passthrough = NULL;
	context->error = NULL;

	parser = g_markup_parse_context_new (context, 0, &active_opt, NULL);

	content = (gchar *) mmap (NULL, end, PROT_READ, MAP_PRIVATE, fd, 0);

	g_markup_parse_context_parse (parser, content, end, &err);
	if (!err)
		g_markup_parse_context_end_parse (parser, &err);

	g_markup_parse_context_free (parser);
	if (err)
		g_error_free (err);
	g_free (context);

	munmap (content, end);
	close (fd);

	return GRG_OK;
}
Example #28
0
gboolean
gimp_text_buffer_deserialize (GtkTextBuffer *register_buffer,
                              GtkTextBuffer *content_buffer,
                              GtkTextIter   *iter,
                              const guint8  *text,
                              gsize          length,
                              gboolean       create_tags,
                              gpointer       user_data,
                              GError       **error)
{
  GMarkupParseContext *context;
  ParseInfo            info;
  gboolean             retval = FALSE;

  static const GMarkupParser markup_parser =
  {
    start_element_handler,
    end_element_handler,
    text_handler,
    NULL,
    NULL
  };

  parse_info_init (&info, register_buffer, content_buffer);

  context = g_markup_parse_context_new (&markup_parser, 0, &info, NULL);

  if (! g_markup_parse_context_parse (context,
                                      (const gchar *) text,
                                      length,
                                      error))
    goto out;

  if (! g_markup_parse_context_end_parse (context, error))
    goto out;

  retval = TRUE;

  insert_text (&info, iter);

 out:
  parse_info_free (&info);

  g_markup_parse_context_free (context);

  return retval;
}
void
grg_recent_dox_init (void)
{
	guchar *path, *content;
	int fd, end;
	GMarkupParser *context =
		(GMarkupParser *) grg_malloc (sizeof (GMarkupParser));
	GMarkupParseContext *parser;
	GError *err = NULL;

	path = g_build_filename (g_get_home_dir (), ".gringotts.recent",
				 NULL);
	fd = open (path, O_RDONLY);
	g_free (path);

	if (fd < 3)
	{
		close (fd);
		return;
	}

	end = lseek (fd, 0, SEEK_END);
	lseek (fd, 0, SEEK_SET);

	context->start_element = NULL;
	context->end_element = NULL;
	context->text = gather_paths;
	context->passthrough = NULL;
	context->error = NULL;

	parser = g_markup_parse_context_new (context, 0, NULL, NULL);

	content = (gchar *) mmap (NULL, end, PROT_READ, MAP_PRIVATE, fd, 0);

	g_markup_parse_context_parse (parser, content, end, &err);
	if (!err)
		g_markup_parse_context_end_parse (parser, &err);

	g_markup_parse_context_free (parser);
	if (err)
		g_error_free (err);
	g_free (context);

	munmap (content, end);
	close (fd);
}
Example #30
0
gint read_xml_frame(FILE *fp, struct model_pak *model)
{
gchar *line;
GMarkupParser xml_parser;
GMarkupParseContext *xml_context;

xml_system_table = g_hash_table_new_full(&g_str_hash, &hash_strcmp, &g_free, NULL);

/* TODO - think more about this... */
xml_model = model;

/* setup context parse (ie callbacks) */
xml_parser.start_element = &xml_start_element;
xml_parser.end_element = &xml_end_element;
xml_parser.text = &xml_parse_text;
xml_parser.passthrough = NULL;
xml_parser.error = NULL;
xml_context = g_markup_parse_context_new(&xml_parser, 0, model, NULL);

/* read in blocks (lines) of text */
line = file_read_line(fp);
while (line)
  {
/* parse the line */
  if (!g_markup_parse_context_parse(xml_context, line, strlen(line), NULL))
    {
    printf("read_xml() : parsing error.\n");
    g_free(line);
    g_markup_parse_context_free(xml_context);
    g_hash_table_destroy(xml_system_table);
    return(1);
    }

  g_free(line);
  line = file_read_line(fp);
  }

/* cleanup */
if (!g_markup_parse_context_end_parse(xml_context, NULL))
  printf("read_xml() : errors occurred reading file.\n");

g_markup_parse_context_free(xml_context);
g_hash_table_destroy(xml_system_table);

return(0);
}