cho2txt

Extract lyrics from chordpro files
git clone git://git.relim.de/cho2txt.git
Log | Files | Refs | README | LICENSE

commit a288580c12af24bd50cba654ebefd5dcac8f1349
parent a266ccfbacd803c0e0358b1494af5778586e1b8e
Author: nibo <kroekerrobin@gmail.com>
Date:   Tue, 27 Jun 2023 16:09:56 +0200

Remove unnecessary line breaks

Diffstat:
MMakefile | 4++--
Mcho2txt | 0
Mcho2txt.c | 31++++++++++++++++++++++++++-----
3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile @@ -7,10 +7,10 @@ clean: rm cho2txt install: all mkdir -p "$(PREFIX)/bin" - cp -f snd "$(PREFIX)/bin" + cp -f cho2txt "$(PREFIX)/bin" chmod 755 "$(PREFIX)/bin/cho2txt" mkdir -p "$(MANPREFIX)/man1" - cp -f snd.1 "$(MANPREFIX)/man1/cho2txt.1" + cp -f cho2txt.1 "$(MANPREFIX)/man1/cho2txt.1" chmod 644 "$(MANPREFIX)/man1/cho2txt.1" uninstall: rm "$(PREFIX)/bin/cho2txt" diff --git a/cho2txt b/cho2txt Binary files differ. diff --git a/cho2txt.c b/cho2txt.c @@ -11,6 +11,7 @@ char *extractLyrics(int fd) int i = 0; char buf; bool isLyrics = true; + bool isBracket = false; while (1) { if (read(fd, &buf, 1) == 1) @@ -21,14 +22,22 @@ char *extractLyrics(int fd) isLyrics = false; if (isLyrics) { + if (buf == '\n' && isBracket) + { + isBracket = false; + continue; + } text[i] = buf; i++; text = realloc(text, (i+1) * sizeof(char)); } - if (buf == '}') - isLyrics = true; - if (buf == ']') + if (buf == '}' || buf == ']') + { isLyrics = true; + isBracket = true; + } + else + isBracket = false; } else break; @@ -44,14 +53,26 @@ char *trimText(char *text) int end = 0; for (int i=0; i<strlen(text); i++) { - if (text[i] == ' ' || text[i] == '\n' || text[i] == '\t') + if + ( + text[i] == ' ' || + text[i] == '\n' || + text[i] == '\t' || + text[i] == '\r' + ) begin++; else break; } for (int i=strlen(text)-1; i>=0; i--) { - if (text[i] == ' ' || text[i] == '\n' || text[i] == '\t') + if + ( + text[i] == ' '|| + text[i] == '\n' || + text[i] == '\t' || + text[i] == '\r' + ) end++; else break;