added support for interupting slides line by line, #45, #75
[smdp.git] / src / markdown.c
1 /*
2  * An implementation of markdown objects.
3  * Copyright (C) 2014 Michael Goehler
4  *
5  * This file is part of mdp.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include "markdown.h"
26
27 line_t *new_line() {
28     line_t *x = malloc(sizeof(line_t));
29     x->text = NULL;
30     x->prev = x->next = NULL;
31     x->bits = x->length = x->offset = 0;
32     return x;
33 }
34
35 line_t *next_line(line_t *prev) {
36     line_t *x = new_line();
37     x->prev = prev;
38     prev->next = x;
39     return x;
40 }
41
42 slide_t *new_slide() {
43     slide_t *x = malloc(sizeof(slide_t));
44     x->line = NULL;
45     x->prev = x->next = NULL;
46     x->lines = x->stop = 0;
47     return x;
48 }
49
50 slide_t *next_slide(slide_t *prev) {
51     slide_t *x = new_slide();
52     x->prev = prev;
53     prev->next = x;
54     return x;
55 }
56
57 deck_t *new_deck() {
58     deck_t *x = malloc(sizeof(deck_t));
59     x->header = NULL;
60     x->slide = new_slide();
61     x->slides = x->headers = 0;
62     return x;
63 }
64
65 void free_line(line_t *line) {
66     line_t *next;
67     while (line) {
68         next = line->next;
69         if(line->text)
70             (line->text->delete)(line->text);
71         free(line);
72         line = next;
73     }
74 }
75
76 void free_deck(deck_t *deck) {
77     slide_t *slide, *next;
78     if (deck == NULL)
79         return;
80     slide = deck->slide;
81     while (slide) {
82         free_line(slide->line);
83         next = slide->next;
84         free(slide);
85         slide = next;
86     }
87     free_line(deck->header);
88     free(deck);
89 }