zactor_t* graylog_forwarder_parser_new(zconfig_t *config, size_t id) { parser_state_t *state = parser_state_new(config, id); return zactor_new(parser, state); }
static gboolean file_parse (gchar *filename, GtkSourceLanguage *language, GtkSourceContextData *ctx_data, GHashTable *defined_regexes, GHashTable *styles, GHashTable *loaded_lang_ids, GQueue *replacements, GError **error) { ParserState *parser_state; xmlTextReader *reader = NULL; int fd = -1; GError *tmp_error = NULL; GtkSourceLanguageManager *lm; const gchar *rng_lang_schema; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); DEBUG (g_message ("loading file '%s'", filename)); /* * Use fd instead of filename so that it's utf8 safe on w32. */ fd = g_open (filename, O_RDONLY, 0); if (fd != -1) reader = xmlReaderForFd (fd, filename, NULL, 0); if (reader == NULL) { g_set_error (&tmp_error, PARSER_ERROR, PARSER_ERROR_CANNOT_OPEN, "unable to open the file"); goto error; } lm = _gtk_source_language_get_language_manager (language); rng_lang_schema = _gtk_source_language_manager_get_rng_file (lm); if (rng_lang_schema == NULL) { g_set_error (&tmp_error, PARSER_ERROR, PARSER_ERROR_CANNOT_VALIDATE, "could not find the RelaxNG schema file"); goto error; } if (xmlTextReaderRelaxNGValidate (reader, rng_lang_schema)) { g_set_error (&tmp_error, PARSER_ERROR, PARSER_ERROR_CANNOT_VALIDATE, "unable to load the RelaxNG schema '%s'", rng_lang_schema); goto error; } parser_state = parser_state_new (language, ctx_data, defined_regexes, styles, replacements, reader, filename, loaded_lang_ids); xmlTextReaderSetStructuredErrorHandler (reader, (xmlStructuredErrorFunc) text_reader_structured_error_func, parser_state); while ((parser_state->error == NULL) && (1 == xmlTextReaderRead (parser_state->reader))) { int type; /* FIXME: does xmlTextReaderRead already do it? */ xmlTextReaderIsValid (parser_state->reader); if (parser_state->error != NULL) break; type = xmlTextReaderNodeType (parser_state->reader); switch (type) { case XML_READER_TYPE_ELEMENT: element_start (parser_state); break; case XML_READER_TYPE_END_ELEMENT: element_end (parser_state); break; } } if (parser_state->error != NULL) { g_propagate_error (&tmp_error, parser_state->error); parser_state->error = NULL; } parser_state_destroy (parser_state); if (tmp_error != NULL) goto error; close (fd); return TRUE; error: if (fd != -1) close (fd); g_propagate_error (error, tmp_error); return FALSE; }