aboutsummaryrefslogtreecommitdiff
path: root/src/presentation.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2015-12-26 22:56:22 +0100
committerThomas White <taw@bitwiz.org.uk>2015-12-26 23:18:09 +0100
commit057ddb969f7ed42b329b87bd8a9bdebbc649427d (patch)
tree44a94b873b14abf59197ef3dd7211d438cf6c72b /src/presentation.c
parent55a8c269d2e77f798f9ca55d7a4afb7a9f98a701 (diff)
Remove "struct slide" and the slide list
Diffstat (limited to 'src/presentation.c')
-rw-r--r--src/presentation.c252
1 files changed, 116 insertions, 136 deletions
diff --git a/src/presentation.c b/src/presentation.c
index a51762f..da9b8c0 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -43,13 +43,8 @@
void free_presentation(struct presentation *p)
{
- int i;
int final = 0;
- for ( i=0; i<p->num_slides; i++ ) {
- free_slide(p->slides[i]);
- }
-
/* FIXME: Loads of stuff leaks here */
free(p->filename);
imagestore_destroy(p->is);
@@ -61,94 +56,6 @@ void free_presentation(struct presentation *p)
}
-/* "pos" is the index that the caller would like this slide to have */
-int insert_slide(struct presentation *p, struct slide *new, int pos)
-{
- struct slide **try;
- int i;
-
- try = realloc(p->slides, (1+p->num_slides)*sizeof(struct slide *));
- if ( try == NULL ) {
- free(new);
- return 1;
- }
- p->slides = try;
- p->completely_empty = 0;
-
- if ( p->num_slides > 0 ) {
- int j = pos;
- if ( j == 0 ) j = 1;
- for ( i=p->num_slides; i>=j; i-- ) {
- p->slides[i] = p->slides[i-1];
- }
- }
-
- p->slides[pos] = new;
- p->num_slides++;
-
- new->parent = p;
-
- return 0;
-}
-
-
-static void delete_slide_index(struct presentation *p, int pos)
-{
- int i;
-
- for ( i=pos; i<p->num_slides-1; i++ ) {
- p->slides[i] = p->slides[i+1];
- }
-
- p->num_slides--;
-
- /* Don't bother to resize the array */
-}
-
-
-void delete_slide(struct presentation *p, struct slide *s)
-{
- int idx;
-
- idx = slide_number(p, s);
- delete_slide_index(p, idx);
-
- free_slide(s);
-}
-
-
-struct slide *new_slide()
-{
- struct slide *new;
-
- new = calloc(1, sizeof(struct slide));
- if ( new == NULL ) return NULL;
-
- new->scblocks = NULL;
- new->notes = NULL;
-
- return new;
-}
-
-
-void free_slide(struct slide *s)
-{
- free(s);
-}
-
-
-struct slide *add_slide(struct presentation *p, int pos)
-{
- struct slide *s = new_slide();
- if ( insert_slide(p, s, pos) ) {
- free_slide(s);
- return NULL;
- }
-
- return s;
-}
-
-
static char *safe_basename(const char *in)
{
int i;
@@ -193,18 +100,6 @@ char *get_titlebar_string(struct presentation *p)
}
-int slide_number(struct presentation *p, struct slide *s)
-{
- int i;
-
- for ( i=0; i<p->num_slides; i++ ) {
- if ( p->slides[i] == s ) return i;
- }
-
- return p->num_slides;
-}
-
-
struct presentation *new_presentation()
{
struct presentation *new;
@@ -218,10 +113,6 @@ struct presentation *new_presentation()
new->slide_width = 1024.0;
new->slide_height = 768.0;
- new->num_slides = 0;
- new->slides = NULL;
- add_slide(new, 0);
-
new->completely_empty = 1;
new->stylesheet = NULL;
new->is = imagestore_new();
@@ -307,18 +198,132 @@ static char *fgets_long(FILE *fh, size_t *lp)
}
+static int safe_strcmp(const char *a, const char *b)
+{
+ if ( a == NULL ) return 1;
+ if ( b == NULL ) return 1;
+ return strcmp(a, b);
+}
+
+
+int slide_number(struct presentation *p, SCBlock *sl)
+{
+ SCBlock *bl = p->scblocks;
+ int n = 0;
+
+ while ( bl != NULL ) {
+ if ( safe_strcmp(sc_block_name(bl), "slide") == 0 ) {
+ n++;
+ if ( sc_block_child(bl) == sl ) return n;
+ }
+ bl = sc_block_next(bl);
+ }
+
+ return 0;
+}
+
+
+int num_slides(struct presentation *p)
+{
+ SCBlock *bl = p->scblocks;
+ int n = 0;
+
+ while ( bl != NULL ) {
+ if ( safe_strcmp(sc_block_name(bl), "slide") == 0 ) {
+ n++;
+ }
+ bl = sc_block_next(bl);
+ }
+
+ return n;
+}
+
+
+SCBlock *first_slide(struct presentation *p)
+{
+ SCBlock *bl = p->scblocks;
+
+ while ( bl != NULL ) {
+ if ( safe_strcmp(sc_block_name(bl), "slide") == 0 ) {
+ return bl;
+ }
+ bl = sc_block_next(bl);
+ }
+
+ fprintf(stderr, "Couldn't find first slide!\n");
+ return NULL;
+}
+
+
+SCBlock *last_slide(struct presentation *p)
+{
+ SCBlock *bl = p->scblocks;
+ SCBlock *l = NULL;
+
+ while ( bl != NULL ) {
+ if ( safe_strcmp(sc_block_name(bl), "slide") == 0 ) {
+ l = bl;
+ }
+ bl = sc_block_next(bl);
+ }
+
+ if ( l == NULL ) {
+ fprintf(stderr, "Couldn't find last slide!\n");
+ }
+ return l;
+}
+
+
+SCBlock *next_slide(struct presentation *p, SCBlock *sl)
+{
+ SCBlock *bl = p->scblocks;
+ int found = 0;
+
+ while ( bl != NULL ) {
+ if ( safe_strcmp(sc_block_name(bl), "slide") == 0 ) {
+ if ( found ) return bl;
+ if ( bl == sl ) {
+ found = 1;
+ }
+ }
+ bl = sc_block_next(bl);
+ }
+
+ fprintf(stderr, "Couldn't find next slide!\n");
+ return NULL;
+}
+
+
+SCBlock *prev_slide(struct presentation *p, SCBlock *sl)
+{
+ SCBlock *bl = p->scblocks;
+ SCBlock *l = NULL;
+
+ while ( bl != NULL ) {
+ if ( safe_strcmp(sc_block_name(bl), "slide") == 0 ) {
+ if ( bl == sl ) return l;
+ l = bl;
+ }
+ bl = sc_block_next(bl);
+ }
+
+ if ( l == NULL ) {
+ fprintf(stderr, "Couldn't find previous slide!\n");
+ }
+ return NULL;
+}
+
+
int load_presentation(struct presentation *p, const char *filename)
{
FILE *fh;
int r = 0;
char *everything;
size_t el = 1;
- SCBlock *block;
everything = strdup("");
assert(p->completely_empty);
- delete_slide(p, p->slides[0]);
fh = fopen(filename, "r");
if ( fh == NULL ) return 1;
@@ -360,31 +365,6 @@ int load_presentation(struct presentation *p, const char *filename)
find_stylesheet(p);
- block = p->scblocks;
- while ( block != NULL ) {
-
- const char *n = sc_block_name(block);
-
- if ( n == NULL ) goto next;
-
- if ( strcmp(n, "slide") == 0 ) {
-
- struct slide *s = add_slide(p, p->num_slides);
-
- if ( s != NULL ) {
-
- s->scblocks = sc_block_child(block);
- attach_notes(s);
-
- }
-
- }
-
-next:
- block = sc_block_next(block);
-
- }
-
assert(p->filename == NULL);
p->filename = strdup(filename);
update_titlebar(p);