diff options
author | Thomas White <taw@physics.org> | 2018-03-19 20:50:37 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2018-03-19 21:00:42 +0100 |
commit | c3e4233c1baafda1573ae53aff424355b0a1dfae (patch) | |
tree | e95e273070beada73972d9361625e771dae0bbc7 /src/presentation.c | |
parent | 496475f45fbae3db0e899aaf23a769f6c7860c4a (diff) |
Move load_everything() to utils
Diffstat (limited to 'src/presentation.c')
-rw-r--r-- | src/presentation.c | 89 |
1 files changed, 0 insertions, 89 deletions
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, |