Blame gettext-tools/libgettextpo/markup.h

Packit Bot 06c835
/* markup.h -- simple XML-like string parser
Packit Bot 06c835
   Copyright (C) 2015 Free Software Foundation, Inc.
Packit Bot 06c835
Packit Bot 06c835
   This file is not part of the GNU gettext program, but is used with
Packit Bot 06c835
   GNU gettext.
Packit Bot 06c835
Packit Bot 06c835
   This is a stripped down version of GLib's gmarkup.h.  The original
Packit Bot 06c835
   copyright notice is as follows:
Packit Bot 06c835
 */
Packit Bot 06c835
Packit Bot 06c835
/* gmarkup.h - Simple XML-like string parser/writer
Packit Bot 06c835
 *
Packit Bot 06c835
 *  Copyright 2000 Red Hat, Inc.
Packit Bot 06c835
 *
Packit Bot 06c835
 * GLib is free software; you can redistribute it and/or modify it
Packit Bot 06c835
 * under the terms of the GNU General Public License as
Packit Bot 06c835
 * published by the Free Software Foundation; either version 3 of the
Packit Bot 06c835
 * License, or (at your option) any later version.
Packit Bot 06c835
 *
Packit Bot 06c835
 * GLib is distributed in the hope that it will be useful,
Packit Bot 06c835
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot 06c835
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Bot 06c835
 * General Public License for more details.
Packit Bot 06c835
 *
Packit Bot 06c835
 * You should have received a copy of the GNU General Public
Packit Bot 06c835
 * License along with GLib; see the file COPYING.LIB.  If not,
Packit Bot 06c835
 * see <http://www.gnu.org/licenses/>.
Packit Bot 06c835
 */
Packit Bot 06c835
Packit Bot 06c835
#ifndef __MARKUP_H__
Packit Bot 06c835
#define __MARKUP_H__ 1
Packit Bot 06c835
Packit Bot 06c835
#ifdef __cplusplus
Packit Bot 06c835
extern "C" {
Packit Bot 06c835
#endif
Packit Bot 06c835
Packit Bot 06c835
#include <stdbool.h>
Packit Bot 06c835
#include <stddef.h>
Packit Bot 06c835
#include <sys/types.h>
Packit Bot 06c835
Packit Bot 06c835
/**
Packit Bot 06c835
 * markup_parse_flags_ty:
Packit Bot 06c835
 * @MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG: flag you should not use
Packit Bot 06c835
 * @MARKUP_TREAT_CDATA_AS_TEXT: When this flag is set, CDATA marked
Packit Bot 06c835
 *     sections are not passed literally to the @passthrough function of
Packit Bot 06c835
 *     the parser. Instead, the content of the section (without the
Packit Bot 06c835
 *     ``) is
Packit Bot 06c835
 *     passed to the @text function. This flag was added in GLib 2.12
Packit Bot 06c835
 * @MARKUP_PREFIX_ERROR_POSITION: Normally errors caught by GMarkup
Packit Bot 06c835
 *     itself have line/column information prefixed to them to let the
Packit Bot 06c835
 *     caller know the location of the error. When this flag is set the
Packit Bot 06c835
 *     location information is also prefixed to errors generated by the
Packit Bot 06c835
 *     #GMarkupParser implementation functions
Packit Bot 06c835
 * @MARKUP_IGNORE_QUALIFIED: Ignore (don't report) qualified
Packit Bot 06c835
 *     attributes and tags, along with their contents.  A qualified
Packit Bot 06c835
 *     attribute or tag is one that contains ':' in its name (ie: is in
Packit Bot 06c835
 *     another namespace).  Since: 2.40.
Packit Bot 06c835
 *
Packit Bot 06c835
 * Flags that affect the behaviour of the parser.
Packit Bot 06c835
 */
Packit Bot 06c835
typedef enum
Packit Bot 06c835
  {
Packit Bot 06c835
    MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
Packit Bot 06c835
    MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1,
Packit Bot 06c835
    MARKUP_PREFIX_ERROR_POSITION = 1 << 2,
Packit Bot 06c835
    MARKUP_IGNORE_QUALIFIED = 1 << 3
Packit Bot 06c835
  } markup_parse_flags_ty;
Packit Bot 06c835
Packit Bot 06c835
/**
Packit Bot 06c835
 * markup_parse_context_ty:
Packit Bot 06c835
 *
Packit Bot 06c835
 * A parse context is used to parse a stream of bytes that
Packit Bot 06c835
 * you expect to contain marked-up text.
Packit Bot 06c835
 *
Packit Bot 06c835
 * See markup_parse_context_new(), #markup_parser_ty, and so
Packit Bot 06c835
 * on for more details.
Packit Bot 06c835
 */
Packit Bot 06c835
typedef struct _markup_parse_context_ty markup_parse_context_ty;
Packit Bot 06c835
typedef struct _markup_parser_ty markup_parser_ty;
Packit Bot 06c835
Packit Bot 06c835
/**
Packit Bot 06c835
 * markup_parser_ty:
Packit Bot 06c835
 * @start_element: Callback to invoke when the opening tag of an element
Packit Bot 06c835
 *     is seen. The callback's @attribute_names and @attribute_values parameters
Packit Bot 06c835
 *     are %NULL-terminated.
Packit Bot 06c835
 * @end_element: Callback to invoke when the closing tag of an element
Packit Bot 06c835
 *     is seen. Note that this is also called for empty tags like
Packit Bot 06c835
 *     `<empty/>`.
Packit Bot 06c835
 * @text: Callback to invoke when some text is seen (text is always
Packit Bot 06c835
 *     inside an element). Note that the text of an element may be spread
Packit Bot 06c835
 *     over multiple calls of this function. If the
Packit Bot 06c835
 *     %MARKUP_TREAT_CDATA_AS_TEXT flag is set, this function is also
Packit Bot 06c835
 *     called for the content of CDATA marked sections.
Packit Bot 06c835
 * @passthrough: Callback to invoke for comments, processing instructions
Packit Bot 06c835
 *     and doctype declarations; if you're re-writing the parsed document,
Packit Bot 06c835
 *     write the passthrough text back out in the same position. If the
Packit Bot 06c835
 *     %MARKUP_TREAT_CDATA_AS_TEXT flag is not set, this function is also
Packit Bot 06c835
 *     called for CDATA marked sections.
Packit Bot 06c835
 * @error: Callback to invoke when an error occurs.
Packit Bot 06c835
 *
Packit Bot 06c835
 * Any of the fields in #markup_parser_ty can be %NULL, in which case they
Packit Bot 06c835
 * will be ignored. Except for the @error function, any of these callbacks
Packit Bot 06c835
 * can set an error; in particular the %MARKUP_ERROR_UNKNOWN_ELEMENT,
Packit Bot 06c835
 * %MARKUP_ERROR_UNKNOWN_ATTRIBUTE, and %MARKUP_ERROR_INVALID_CONTENT
Packit Bot 06c835
 * errors are intended to be set from these callbacks. If you set an error
Packit Bot 06c835
 * from a callback, markup_parse_context_parse() will report that error
Packit Bot 06c835
 * back to its caller.
Packit Bot 06c835
 */
Packit Bot 06c835
struct _markup_parser_ty
Packit Bot 06c835
{
Packit Bot 06c835
  /* Called for open tags <foo bar="baz"> */
Packit Bot 06c835
  bool (*start_element) (markup_parse_context_ty *context,
Packit Bot 06c835
                         const char *element_name,
Packit Bot 06c835
                         const char **attribute_names,
Packit Bot 06c835
                         const char **attribute_values,
Packit Bot 06c835
                         void *user_data);
Packit Bot 06c835
Packit Bot 06c835
  /* Called for close tags </foo> */
Packit Bot 06c835
  bool (*end_element) (markup_parse_context_ty *context,
Packit Bot 06c835
                       const char *element_name,
Packit Bot 06c835
                       void *user_data);
Packit Bot 06c835
Packit Bot 06c835
  /* Called for character data */
Packit Bot 06c835
  /* text is not nul-terminated */
Packit Bot 06c835
  bool (*text) (markup_parse_context_ty *context,
Packit Bot 06c835
                const char *text,
Packit Bot 06c835
                size_t text_len,
Packit Bot 06c835
                void *user_data);
Packit Bot 06c835
Packit Bot 06c835
  /* Called for strings that should be re-saved verbatim in this same
Packit Bot 06c835
   * position, but are not otherwise interpretable.  At the moment
Packit Bot 06c835
   * this includes comments and processing instructions.
Packit Bot 06c835
   */
Packit Bot 06c835
  /* text is not nul-terminated. */
Packit Bot 06c835
  bool (*passthrough) (markup_parse_context_ty *context,
Packit Bot 06c835
                       const char *passthrough_text,
Packit Bot 06c835
                       size_t text_len,
Packit Bot 06c835
                       void *user_data);
Packit Bot 06c835
Packit Bot 06c835
  /* Called on error, including one set by other
Packit Bot 06c835
   * methods in the vtable. The GError should not be freed.
Packit Bot 06c835
   */
Packit Bot 06c835
  void (*error) (markup_parse_context_ty *context,
Packit Bot 06c835
                 const char *error_text,
Packit Bot 06c835
                 void *user_data);
Packit Bot 06c835
};
Packit Bot 06c835
Packit Bot 06c835
extern markup_parse_context_ty *
Packit Bot 06c835
       markup_parse_context_new (const markup_parser_ty *parser,
Packit Bot 06c835
                                 markup_parse_flags_ty flags,
Packit Bot 06c835
                                 void *user_data);
Packit Bot 06c835
extern void markup_parse_context_free (markup_parse_context_ty *context);
Packit Bot 06c835
extern bool markup_parse_context_parse (markup_parse_context_ty *context,
Packit Bot 06c835
                                        const char *text,
Packit Bot 06c835
                                        ssize_t text_len);
Packit Bot 06c835
extern bool markup_parse_context_end_parse (markup_parse_context_ty *context);
Packit Bot 06c835
extern const char *
Packit Bot 06c835
       markup_parse_context_get_error (markup_parse_context_ty *context);
Packit Bot 06c835
Packit Bot 06c835
#ifdef __cplusplus
Packit Bot 06c835
}
Packit Bot 06c835
#endif
Packit Bot 06c835
Packit Bot 06c835
#endif /* __MARKUP_H__ */