parse: Refactor grammar, make it more consistent and fix conflicts
[platform/upstream/gstreamer.git] / gst / parse / types.h
1 #ifndef __GST_PARSE_TYPES_H__
2 #define __GST_PARSE_TYPES_H__
3
4 #include <glib-object.h>
5 #include "../gstelement.h"
6 #include "../gstparse.h"
7
8 typedef struct {
9   GstElement *element;
10   gchar *name;
11   GSList *pads;
12 } reference_t;
13
14 typedef struct {
15   reference_t src;
16   reference_t sink;
17   GstCaps *caps;
18 } link_t;
19
20 typedef struct {
21   GSList *elements;
22   reference_t first;
23   reference_t last;
24   //link_t *front;
25   //link_t *back;
26 } chain_t;
27
28 typedef struct _graph_t graph_t;
29 struct _graph_t {
30   chain_t *chain; /* links are supposed to be done now */
31   GSList *links;
32   GError **error;
33   GstParseContext *ctx; /* may be NULL */
34   GstParseFlags flags;
35 };
36
37
38 /*
39  * Memory checking. Should probably be done with gsttrace stuff, but that
40  * doesn't really work.
41  * This is not safe from reentrance issues, but that doesn't matter as long as
42  * we lock a mutex before parsing anyway.
43  */
44 //#ifdef GST_DEBUG_ENABLED
45 #  define __GST_PARSE_TRACE
46 //#endif
47
48 #ifdef __GST_PARSE_TRACE
49 G_GNUC_INTERNAL  gchar  *__gst_parse_strdup (gchar *org);
50 G_GNUC_INTERNAL  void   __gst_parse_strfree (gchar *str);
51 G_GNUC_INTERNAL  link_t *__gst_parse_link_new (void);
52 G_GNUC_INTERNAL  void   __gst_parse_link_free (link_t *data);
53 G_GNUC_INTERNAL  chain_t *__gst_parse_chain_new (void);
54 G_GNUC_INTERNAL  void   __gst_parse_chain_free (chain_t *data);
55 #  define gst_parse_strdup __gst_parse_strdup
56 #  define gst_parse_strfree __gst_parse_strfree
57 #  define gst_parse_link_new __gst_parse_link_new
58 #  define gst_parse_link_free __gst_parse_link_free
59 #  define gst_parse_chain_new __gst_parse_chain_new
60 #  define gst_parse_chain_free __gst_parse_chain_free
61 #else /* __GST_PARSE_TRACE */
62 #  define gst_parse_strdup g_strdup
63 #  define gst_parse_strfree g_free
64 #  define gst_parse_link_new() g_new0 (link_t, 1)
65 #  define gst_parse_link_free g_free
66 #  define gst_parse_chain_new() g_new0 (chain_t, 1)
67 #  define gst_parse_chain_free g_free
68 #endif /* __GST_PARSE_TRACE */
69
70 static inline void
71 gst_parse_unescape (gchar *str)
72 {
73   gchar *walk;
74   gboolean in_quotes;
75
76   g_return_if_fail (str != NULL);
77
78   walk = str;
79   in_quotes = FALSE;
80
81   GST_DEBUG ("unescaping %s", str);
82
83   while (*walk) {
84     if (*walk == '\\' && !in_quotes) {
85       walk++;
86       /* make sure we don't read beyond the end of the string */
87       if (*walk == '\0')
88         break;
89     } else if (*walk == '"' && (!in_quotes || (in_quotes
90                 && (*(walk - 1) != '\\')))) {
91       /* don't unescape inside quotes and don't switch
92        * state with escaped quoted inside quotes */
93       in_quotes = !in_quotes;
94     }
95     *str = *walk;
96     str++;
97     walk++;
98   }
99   *str = '\0';
100 }
101
102 G_GNUC_INTERNAL GstElement *priv_gst_parse_launch (const gchar      * str,
103                                                    GError          ** err,
104                                                    GstParseContext  * ctx,
105                                                    GstParseFlags      flags);
106
107 #endif /* __GST_PARSE_TYPES_H__ */