aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/narrative_window.c1
-rw-r--r--src/presentation.c89
-rw-r--r--src/presentation.h1
-rw-r--r--src/utils.c89
-rw-r--r--src/utils.h2
5 files changed, 91 insertions, 91 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c
index 8da1c62..312763d 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -39,6 +39,7 @@
#include "testcard.h"
#include "pr_clock.h"
#include "print.h"
+#include "utils.h"
struct _narrative_window
diff --git a/src/presentation.c b/src/presentation.c
index 3ec00e3..1c822c4 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -149,61 +149,6 @@ int save_presentation(struct presentation *p, const char *filename)
}
-static char *fgets_long(FILE *fh, size_t *lp)
-{
- char *line;
- size_t la;
- size_t l = 0;
-
- la = 1024;
- line = malloc(la);
- if ( line == NULL ) return NULL;
-
- do {
-
- int r;
-
- r = fgetc(fh);
- if ( r == EOF ) {
- if ( l == 0 ) {
- free(line);
- *lp = 0;
- return NULL;
- } else {
- line[l++] = '\0';
- *lp = l;
- return line;
- }
- }
-
- line[l++] = r;
-
- if ( r == '\n' ) {
- line[l++] = '\0';
- *lp = l;
- return line;
- }
-
- if ( l == la ) {
-
- char *ln;
-
- la += 1024;
- ln = realloc(line, la);
- if ( ln == NULL ) {
- free(line);
- *lp = 0;
- return NULL;
- }
-
- line = ln;
-
- }
-
- } while ( 1 );
-}
-
-
int slide_number(struct presentation *p, SCBlock *sl)
{
SCBlock *bl = p->scblocks;
@@ -313,40 +258,6 @@ SCBlock *prev_slide(struct presentation *p, SCBlock *sl)
}
-char *load_everything(const char *filename)
-{
- FILE *fh;
- size_t el = 1;
- char *everything = strdup("");
-
- fh = fopen(filename, "r");
- if ( fh == NULL ) return NULL;
-
- while ( !feof(fh) ) {
-
- size_t len = 0;
- char *line = fgets_long(fh, &len);
-
- if ( line != NULL ) {
-
- everything = realloc(everything, el+len);
- if ( everything == NULL ) {
- fprintf(stderr, "Failed to allocate memory\n");
- return NULL;
- }
- el += len;
-
- strcat(everything, line);
- }
-
- }
-
- fclose(fh);
-
- return everything;
-}
-
-
int replace_stylesheet(struct presentation *p, SCBlock *ss)
{
/* Create style sheet from union of old and new,
diff --git a/src/presentation.h b/src/presentation.h
index 279c4bd..24c6110 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -69,7 +69,6 @@ struct presentation
extern struct presentation *new_presentation(const char *imagestore);
-extern char *load_everything(const char *filename);
extern SCBlock *find_stylesheet(SCBlock *bl);
extern int replace_stylesheet(struct presentation *p, SCBlock *ss);
extern void free_presentation(struct presentation *p);
diff --git a/src/utils.c b/src/utils.c
index 17f9665..0191d18 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -26,6 +26,8 @@
#endif
#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
void chomp(char *s)
{
@@ -50,3 +52,90 @@ int safe_strcmp(const char *a, const char *b)
}
+static char *fgets_long(FILE *fh, size_t *lp)
+{
+ char *line;
+ size_t la;
+ size_t l = 0;
+
+ la = 1024;
+ line = malloc(la);
+ if ( line == NULL ) return NULL;
+
+ do {
+
+ int r;
+
+ r = fgetc(fh);
+ if ( r == EOF ) {
+ if ( l == 0 ) {
+ free(line);
+ *lp = 0;
+ return NULL;
+ } else {
+ line[l++] = '\0';
+ *lp = l;
+ return line;
+ }
+ }
+
+ line[l++] = r;
+
+ if ( r == '\n' ) {
+ line[l++] = '\0';
+ *lp = l;
+ return line;
+ }
+
+ if ( l == la ) {
+
+ char *ln;
+
+ la += 1024;
+ ln = realloc(line, la);
+ if ( ln == NULL ) {
+ free(line);
+ *lp = 0;
+ return NULL;
+ }
+
+ line = ln;
+
+ }
+
+ } while ( 1 );
+}
+
+
+char *load_everything(const char *filename)
+{
+ FILE *fh;
+ size_t el = 1;
+ char *everything = strdup("");
+
+ fh = fopen(filename, "r");
+ if ( fh == NULL ) return NULL;
+
+ while ( !feof(fh) ) {
+
+ size_t len = 0;
+ char *line = fgets_long(fh, &len);
+
+ if ( line != NULL ) {
+
+ everything = realloc(everything, el+len);
+ if ( everything == NULL ) {
+ fprintf(stderr, "Failed to allocate memory\n");
+ return NULL;
+ }
+ el += len;
+
+ strcat(everything, line);
+ }
+
+ }
+
+ fclose(fh);
+
+ return everything;
+}
diff --git a/src/utils.h b/src/utils.h
index 11351fb..99701e3 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -30,6 +30,6 @@
extern void chomp(char *s);
extern int safe_strcmp(const char *a, const char *b);
-
+extern char *load_everything(const char *filename);
#endif /* UTILS_H */