summaryrefslogtreecommitdiff
path: root/src/parse/mq.c
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2018-04-22 11:34:12 +0100
committerMichael Drake <michael.drake@codethink.co.uk>2019-03-10 13:42:03 +0000
commit7c38f6c3ce7622ae2e12589a70579b440992efcb (patch)
treeae2acd48555347a3455fcc9a988b65548230c877 /src/parse/mq.c
parent819a78a0eb742c04ec3fdfeaeba97ad4962c8eaa (diff)
downloadlibcss-7c38f6c3ce7622ae2e12589a70579b440992efcb.tar.gz
libcss-7c38f6c3ce7622ae2e12589a70579b440992efcb.tar.bz2
Media Queries: Add destruction functions.
Diffstat (limited to 'src/parse/mq.c')
-rw-r--r--src/parse/mq.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/parse/mq.c b/src/parse/mq.c
index 6692651..1fa66d6 100644
--- a/src/parse/mq.c
+++ b/src/parse/mq.c
@@ -17,6 +17,63 @@
#include "parse/properties/utils.h"
#include "utils/utils.h"
+static void css_mq_feature_destroy(css_mq_feature *feature)
+{
+ if (feature != NULL) {
+ lwc_string_unref(feature->name);
+ free(feature);
+ }
+}
+
+static void css__mq_cond_or_feature_destroy(
+ css_mq_cond_or_feature *cond_or_feature);
+
+static void css__mq_cond_parts_destroy(css_mq_cond_parts *cond_parts)
+{
+ if (cond_parts != NULL) {
+ for (uint32_t i = 0; i < cond_parts->nparts; i++) {
+ css__mq_cond_or_feature_destroy(cond_parts->parts[i]);
+ }
+ free(cond_parts);
+ }
+}
+
+static void css__mq_cond_destroy(css_mq_cond *cond)
+{
+ if (cond != NULL) {
+ css__mq_cond_parts_destroy(cond->parts);
+ free(cond);
+ }
+}
+
+static void css__mq_cond_or_feature_destroy(
+ css_mq_cond_or_feature *cond_or_feature)
+{
+ if (cond_or_feature != NULL) {
+ switch (cond_or_feature->type) {
+ case CSS_MQ_FEATURE:
+ css_mq_feature_destroy(cond_or_feature->data.feat);
+ break;
+ case CSS_MQ_COND:
+ css__mq_cond_destroy(cond_or_feature->data.cond);
+ break;
+ }
+ free(cond_or_feature);
+ }
+}
+
+void css__mq_query_destroy(css_mq_query *media)
+{
+ while (media != NULL) {
+ css_mq_query *next = media->next;
+
+ css__mq_cond_destroy(media->cond);
+ free(media);
+
+ media = next;
+ }
+}
+
static css_error mq_parse_condition(css_language *c,
const parserutils_vector *vector, int *ctx,
bool permit_or, css_mq_cond **cond);