commit 5c89f96ba73a3eba9b1226866dfaefc556a0f409
parent cc98b2e8c9fea3b9f0d62232b80a8fd558e1d3f7
Author: nibo <nibo@relim.de>
Date: Sun, 26 Jan 2025 13:20:13 +0100
Fix: Remove last empty pdf page
Diffstat:
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/lorid.c b/lorid.c
@@ -24,9 +24,7 @@ main(int argc, char *argv[])
const char *chordpro_filepath = NULL;
char *config_filepath = NULL;
char *output = NULL;
- struct ChoSong **all_songs = NULL;
- struct ChoSong **songs = NULL;
- struct ChoSong **begin;
+ struct ChoSong **so, **all_songs = NULL, **songs = NULL;
int s = 0;
FILE *fp;
while ((o = getopt_long(argc, argv, "pc:o:Vvh", long_options, &option_index)) != -1) {
@@ -93,15 +91,12 @@ main(int argc, char *argv[])
LOG_DEBUG("cho_songs_parse failed.");
return 1;
}
- begin = songs;
fclose(fp);
- while (*songs) {
+ for (so = songs; *so; s++, so++) {
all_songs = erealloc(all_songs, (s+1) * sizeof(struct ChoSong *));
- all_songs[s] = *songs;
- s++;
- songs++;
+ all_songs[s] = *so;
}
- free(begin);
+ free(songs);
}
all_songs = erealloc(all_songs, (s+1) * sizeof(struct ChoSong *));
all_songs[s] = NULL;
diff --git a/out_pdf.c b/out_pdf.c
@@ -2556,9 +2556,14 @@ pdf_content_create(
(*imgs)[ctx.image] = NULL;
*diagrams = erealloc(*diagrams, (ctx.diagram+1) * sizeof(struct ChordDiagram *));
(*diagrams)[ctx.diagram] = NULL;
- ctx.page++;
- ctx.content->pages = erealloc(ctx.content->pages, (ctx.page+1) * sizeof(struct PDFPage *));
- ctx.content->pages[ctx.page] = NULL;
+ if (start_song_on_new_page) {
+ pdf_page_free(ctx.content->pages[ctx.page]);
+ ctx.content->pages[ctx.page] = NULL;
+ } else {
+ ctx.page++;
+ ctx.content->pages = erealloc(ctx.content->pages, (ctx.page+1) * sizeof(struct PDFPage *));
+ ctx.content->pages[ctx.page] = NULL;
+ }
ctx.content->toc = erealloc(ctx.content->toc, (ctx.toc_entry+1) * sizeof(struct TocEntry *));
ctx.content->toc[ctx.toc_entry] = NULL;
*out = ctx.content;