2005-06-22 18:20:32 +00:00
|
|
|
/*
|
2005-10-13 14:08:18 +00:00
|
|
|
* moomarkup.h
|
2005-06-22 18:20:32 +00:00
|
|
|
*
|
2010-12-21 20:15:45 -08:00
|
|
|
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
2005-06-22 18:20:32 +00:00
|
|
|
*
|
2008-09-05 17:20:50 -05:00
|
|
|
* This file is part of medit. medit is free software; you can
|
|
|
|
* redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2.1 of the License,
|
|
|
|
* or (at your option) any later version.
|
2005-06-22 18:20:32 +00:00
|
|
|
*
|
2008-09-05 17:20:50 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
2005-06-22 18:20:32 +00:00
|
|
|
*/
|
|
|
|
|
2007-04-12 10:31:28 -05:00
|
|
|
#ifndef MOO_MARKUP_H
|
|
|
|
#define MOO_MARKUP_H
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2010-11-23 21:54:39 -08:00
|
|
|
#include <mooutils/moofilewriter.h>
|
2005-06-22 18:20:32 +00:00
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
MOO_MARKUP_DOC_NODE,
|
|
|
|
MOO_MARKUP_ELEMENT_NODE,
|
|
|
|
MOO_MARKUP_TEXT_NODE,
|
|
|
|
MOO_MARKUP_COMMENT_NODE
|
|
|
|
} MooMarkupNodeType;
|
|
|
|
|
2010-11-07 01:48:11 -08:00
|
|
|
typedef struct MooMarkupNode MooMarkupNode;
|
|
|
|
typedef struct MooMarkupDoc MooMarkupDoc;
|
|
|
|
typedef struct MooMarkupElement MooMarkupElement;
|
|
|
|
typedef struct MooMarkupText MooMarkupText;
|
|
|
|
typedef struct MooMarkupText MooMarkupComment;
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2008-08-31 14:53:51 -05:00
|
|
|
typedef void (*MooMarkupStartElementFunc) (GMarkupParseContext *context,
|
|
|
|
const gchar *element_name,
|
|
|
|
const gchar **attribute_names,
|
|
|
|
const gchar **attribute_values,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error);
|
|
|
|
typedef void (*MooMarkupEndElementFunc) (GMarkupParseContext *context,
|
|
|
|
const gchar *element_name,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error);
|
|
|
|
typedef void (*MooMarkupTextFunc) (GMarkupParseContext *context,
|
|
|
|
const gchar *text,
|
|
|
|
gsize text_len,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error);
|
|
|
|
typedef void (*MooMarkupPassthroughFunc) (GMarkupParseContext *context,
|
|
|
|
const gchar *passthrough_text,
|
|
|
|
gsize text_len,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error);
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2007-06-15 17:26:54 -05:00
|
|
|
#if 0 && defined(ENABLE_DEBUG)
|
2005-11-01 18:20:56 +00:00
|
|
|
#define MOO_MARKUP_NODE(n) (MOO_MARKUP_NODE_CHECK_CAST(n))
|
|
|
|
#define MOO_MARKUP_DOC(n) (MOO_MARKUP_DOC_CHECK_CAST(n))
|
|
|
|
#define MOO_MARKUP_ELEMENT(n) (MOO_MARKUP_ELEMENT_CHECK_CAST(n))
|
|
|
|
#define MOO_MARKUP_TEXT(n) (MOO_MARKUP_TEXT_CHECK_CAST(n))
|
|
|
|
#define MOO_MARKUP_COMMENT(n) (MOO_MARKUP_COMMENT_CHECK_CAST(n))
|
2007-06-15 17:26:54 -05:00
|
|
|
#else /* ENABLE_DEBUG */
|
|
|
|
#define MOO_MARKUP_NODE(n) ((MooMarkupNode*)n)
|
|
|
|
#define MOO_MARKUP_DOC(n) ((MooMarkupDoc*)(n))
|
|
|
|
#define MOO_MARKUP_ELEMENT(n) ((MooMarkupElement*)(n))
|
|
|
|
#define MOO_MARKUP_TEXT(n) ((MooMarkupText*)(n))
|
|
|
|
#define MOO_MARKUP_COMMENT(n) ((MooMarkupComment*)(n))
|
2005-06-22 18:20:32 +00:00
|
|
|
#endif /* ENABLE_DEBUG */
|
2005-11-01 18:20:56 +00:00
|
|
|
|
2005-06-22 18:20:32 +00:00
|
|
|
#define MOO_MARKUP_IS_DOC(n) ((n) != NULL && MOO_MARKUP_NODE(n)->type == MOO_MARKUP_DOC_NODE)
|
|
|
|
#define MOO_MARKUP_IS_ELEMENT(n) ((n) != NULL && MOO_MARKUP_NODE(n)->type == MOO_MARKUP_ELEMENT_NODE)
|
|
|
|
#define MOO_MARKUP_IS_TEXT(n) ((n) != NULL && MOO_MARKUP_NODE(n)->type == MOO_MARKUP_TEXT_NODE)
|
|
|
|
#define MOO_MARKUP_IS_COMMENT(n) ((n) != NULL && MOO_MARKUP_NODE(n)->type == MOO_MARKUP_COMMENT_NODE)
|
|
|
|
|
|
|
|
|
2010-11-07 01:48:11 -08:00
|
|
|
struct MooMarkupNode {
|
2005-06-22 18:20:32 +00:00
|
|
|
MooMarkupNodeType type; /* type of the node */
|
|
|
|
char *name; /* the name of the node */
|
|
|
|
MooMarkupNode *children; /* parent->childs link */
|
|
|
|
MooMarkupNode *last; /* last child link */
|
|
|
|
MooMarkupNode *parent; /* child->parent link */
|
|
|
|
MooMarkupNode *next; /* next sibling link */
|
|
|
|
MooMarkupNode *prev; /* previous sibling link */
|
|
|
|
MooMarkupDoc *doc; /* the containing document */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-11-07 01:48:11 -08:00
|
|
|
struct MooMarkupDoc {
|
2005-06-22 18:20:32 +00:00
|
|
|
MooMarkupNodeType type; /* MOO_MARKUP_DOC_NODE */
|
|
|
|
char *name; /* name/filename/URI of the document */
|
|
|
|
MooMarkupNode *children; /* the document tree */
|
|
|
|
MooMarkupNode *last; /* last child link */
|
|
|
|
MooMarkupNode *parent; /* child->parent link */
|
|
|
|
MooMarkupNode *next; /* NULL */
|
|
|
|
MooMarkupNode *prev; /* NULL */
|
|
|
|
MooMarkupDoc *doc; /* self */
|
2007-06-15 17:26:54 -05:00
|
|
|
|
2005-06-22 18:20:32 +00:00
|
|
|
guint ref_count;
|
2006-11-15 01:29:32 -06:00
|
|
|
guint modified : 1;
|
|
|
|
guint track_modified : 1;
|
2005-06-22 18:20:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-11-07 01:48:11 -08:00
|
|
|
struct MooMarkupElement {
|
2005-06-22 18:20:32 +00:00
|
|
|
MooMarkupNodeType type; /* MOO_MARKUP_ELEMENT_NODE */
|
|
|
|
char *name; /* name */
|
|
|
|
MooMarkupNode *children; /* content */
|
|
|
|
MooMarkupNode *last; /* last child link */
|
|
|
|
MooMarkupNode *parent; /* child->parent link */
|
|
|
|
MooMarkupNode *next; /* next sibling */
|
|
|
|
MooMarkupNode *prev; /* previous sibling */
|
|
|
|
MooMarkupDoc *doc; /* containing document */
|
|
|
|
|
|
|
|
char *content; /* text content of the node */
|
|
|
|
char **attr_names;/* NULL-terminated list of attribute names */
|
|
|
|
char **attr_vals; /* NULL-terminated list of attribute values */
|
|
|
|
guint n_attrs;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-11-07 01:48:11 -08:00
|
|
|
struct MooMarkupText {
|
2005-06-22 18:20:32 +00:00
|
|
|
MooMarkupNodeType type; /* MOO_MARKUP_TEXT_NODE */
|
|
|
|
char *name; /* "TEXT" */
|
|
|
|
MooMarkupNode *children; /* NULL */
|
|
|
|
MooMarkupNode *last; /* NULL */
|
|
|
|
MooMarkupNode *parent; /* child->parent link */
|
|
|
|
MooMarkupNode *next; /* next sibling link */
|
|
|
|
MooMarkupNode *prev; /* previous sibling link */
|
|
|
|
MooMarkupDoc *doc; /* the containing document */
|
|
|
|
|
|
|
|
char *text; /* 0-terminated content of the node */
|
2015-07-11 14:32:02 -07:00
|
|
|
gsize size; /* strlen (text) */
|
2005-06-22 18:20:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-08-31 14:53:51 -05:00
|
|
|
GType moo_markup_doc_get_type (void) G_GNUC_CONST;
|
2005-09-05 04:24:21 +00:00
|
|
|
|
2008-08-31 14:53:51 -05:00
|
|
|
MooMarkupNode *MOO_MARKUP_NODE_CHECK_CAST (gpointer node);
|
|
|
|
MooMarkupDoc *MOO_MARKUP_DOC_CHECK_CAST (gpointer node);
|
|
|
|
MooMarkupElement *MOO_MARKUP_ELEMENT_CHECK_CAST (gpointer node);
|
|
|
|
MooMarkupText *MOO_MARKUP_TEXT_CHECK_CAST (gpointer node);
|
|
|
|
MooMarkupComment *MOO_MARKUP_COMMENT_CHECK_CAST (gpointer node);
|
2005-11-01 18:20:56 +00:00
|
|
|
|
2005-09-05 04:24:21 +00:00
|
|
|
MooMarkupDoc *moo_markup_doc_new (const char *name);
|
|
|
|
|
|
|
|
MooMarkupDoc *moo_markup_parse_file (const char *filename,
|
|
|
|
GError **error);
|
|
|
|
MooMarkupDoc *moo_markup_parse_memory (const char *buffer,
|
2015-07-12 23:23:14 -07:00
|
|
|
gssize size,
|
2005-09-05 04:24:21 +00:00
|
|
|
GError **error);
|
2008-02-20 18:45:20 -06:00
|
|
|
gboolean moo_markup_write_pretty (MooMarkupDoc *doc,
|
|
|
|
MooFileWriter *writer,
|
2007-06-24 12:18:39 -05:00
|
|
|
guint indent);
|
2005-09-05 04:24:21 +00:00
|
|
|
char *moo_markup_node_get_string (MooMarkupNode *node);
|
|
|
|
|
|
|
|
MooMarkupDoc *moo_markup_doc_ref (MooMarkupDoc *doc);
|
|
|
|
void moo_markup_doc_unref (MooMarkupDoc *doc);
|
|
|
|
|
2005-09-10 14:41:16 +00:00
|
|
|
MooMarkupNode *moo_markup_get_root_element (MooMarkupDoc *doc,
|
2005-09-05 04:24:21 +00:00
|
|
|
const char *name);
|
|
|
|
|
2005-09-10 14:41:16 +00:00
|
|
|
MooMarkupNode *moo_markup_get_element (MooMarkupNode *node,
|
2005-09-05 04:24:21 +00:00
|
|
|
const char *path);
|
|
|
|
|
2005-09-10 14:41:16 +00:00
|
|
|
const char *moo_markup_get_prop (MooMarkupNode *node,
|
2005-09-05 04:24:21 +00:00
|
|
|
const char *prop_name);
|
2005-09-10 14:41:16 +00:00
|
|
|
void moo_markup_set_prop (MooMarkupNode *node,
|
2005-09-05 04:24:21 +00:00
|
|
|
const char *prop_name,
|
|
|
|
const char *val);
|
2005-10-13 14:08:18 +00:00
|
|
|
|
2008-11-06 22:33:06 -06:00
|
|
|
int moo_markup_int_prop (MooMarkupNode *node,
|
2005-10-13 14:08:18 +00:00
|
|
|
const char *prop_name,
|
|
|
|
int default_val);
|
2008-11-06 22:33:06 -06:00
|
|
|
guint moo_markup_uint_prop (MooMarkupNode *node,
|
2005-10-13 14:08:18 +00:00
|
|
|
const char *prop_name,
|
2008-11-06 22:33:06 -06:00
|
|
|
guint default_val);
|
|
|
|
gboolean moo_markup_bool_prop (MooMarkupNode *node,
|
2005-10-13 14:08:18 +00:00
|
|
|
const char *prop_name,
|
|
|
|
gboolean default_val);
|
|
|
|
void moo_markup_set_bool_prop (MooMarkupNode *node,
|
|
|
|
const char *prop_name,
|
|
|
|
gboolean val);
|
|
|
|
|
|
|
|
|
2005-09-10 14:41:16 +00:00
|
|
|
void moo_markup_set_content (MooMarkupNode *node,
|
2005-09-05 04:24:21 +00:00
|
|
|
const char *text);
|
2005-09-10 14:41:16 +00:00
|
|
|
const char *moo_markup_get_content (MooMarkupNode *node);
|
2005-09-05 04:24:21 +00:00
|
|
|
|
|
|
|
char *moo_markup_element_get_path (MooMarkupElement *node);
|
|
|
|
|
|
|
|
void moo_markup_delete_node (MooMarkupNode *node);
|
|
|
|
|
2005-09-10 14:41:16 +00:00
|
|
|
MooMarkupNode *moo_markup_create_root_element (MooMarkupDoc *doc,
|
2005-09-05 04:24:21 +00:00
|
|
|
const char *name);
|
2005-09-10 14:41:16 +00:00
|
|
|
MooMarkupNode *moo_markup_create_element (MooMarkupNode *parent,
|
2005-09-05 04:24:21 +00:00
|
|
|
const char *path);
|
2005-09-08 17:08:31 +00:00
|
|
|
|
2005-09-10 14:41:16 +00:00
|
|
|
MooMarkupNode *moo_markup_create_text_element (MooMarkupNode *parent,
|
2005-09-05 04:24:21 +00:00
|
|
|
const char *path,
|
|
|
|
const char *content);
|
2005-07-28 19:25:10 +00:00
|
|
|
|
2008-08-31 14:53:51 -05:00
|
|
|
gboolean moo_parse_markup_file (const char *filename,
|
|
|
|
const GMarkupParser *parser,
|
|
|
|
gpointer data,
|
|
|
|
GError **error);
|
|
|
|
|
2006-11-15 01:29:32 -06:00
|
|
|
void _moo_markup_set_modified (MooMarkupDoc *doc,
|
|
|
|
gboolean modified);
|
|
|
|
void _moo_markup_set_track_modified (MooMarkupDoc *doc,
|
|
|
|
gboolean track);
|
|
|
|
gboolean _moo_markup_get_modified (MooMarkupDoc *doc);
|
|
|
|
|
2005-06-22 18:20:32 +00:00
|
|
|
G_END_DECLS
|
|
|
|
|
2007-04-12 10:31:28 -05:00
|
|
|
#endif /* MOO_MARKUP_H */
|