commit 20e97fb27e648467ee57e6c5beec23daeee0147a
parent 4b82b459c5024c4456fd2cb1ae15ce6362176f26
Author: nibo <nibo@relim.de>
Date: Sun, 5 Jan 2025 17:40:59 +0100
Add -v/--verbose argument
Don't show info logs by default.
Showing the version is now done with -V/--version.
Diffstat:
6 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/chordpro.c b/chordpro.c
@@ -135,6 +135,7 @@ static const char *chord_extensions_minor[] = {
NULL
};
+static bool g_show_info_logs = false;
static enum SongFragmentType g_current_ftype = SF_TEXT;
static enum SongFragmentType g_prev_ftype = SF_TEXT;
static struct Config *g_config = NULL;
@@ -248,10 +249,19 @@ cho_debug_chord_print(struct ChoChord *chord)
#endif /* DEBUG */
+void
+cho_log_enable_info_logs(void)
+{
+ g_show_info_logs = true;
+}
+
#if COLOR == 1
static void
cho_log(enum LogLevel level, const char *msg, ...)
{
+ if (level == LOG_INFO && !g_show_info_logs) {
+ return;
+ }
va_list va;
va_start(va, msg);
const char *log_level;
@@ -303,6 +313,9 @@ cho_log(enum LogLevel level, const char *msg, ...)
static void
cho_log(enum LogLevel level, const char *msg, ...)
{
+ if (level == LOG_INFO && !g_show_info_logs) {
+ return;
+ }
va_list va;
va_start(va, msg);
const char *log_level;
diff --git a/chordpro.h b/chordpro.h
@@ -321,6 +321,7 @@ struct Tag {
bool is_closed;
};
+void cho_log_enable_info_logs(void);
struct ChoSong **cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config);
int cho_song_count(struct ChoSong **songs);
diff --git a/lorid.c b/lorid.c
@@ -15,7 +15,8 @@ main(int argc, char *argv[])
{ "print-default-config", no_argument, 0, 'p' },
{ "config", required_argument, 0, 'c' },
{ "output", required_argument, 0, 'o' },
- { "version", no_argument, 0, 'v' },
+ { "verbose", no_argument, 0, 'v' },
+ { "version", no_argument, 0, 'V' },
{ "help", no_argument, 0, 'h' },
{ 0, 0, 0, 0 }
};
@@ -28,7 +29,7 @@ main(int argc, char *argv[])
struct ChoSong **begin;
int s = 0;
FILE *fp;
- while ((o = getopt_long(argc, argv, "pc:o:vh", long_options, &option_index)) != -1) {
+ while ((o = getopt_long(argc, argv, "pc:o:Vvh", long_options, &option_index)) != -1) {
switch(o) {
case 'p':
config_print_default();
@@ -41,9 +42,13 @@ main(int argc, char *argv[])
output = erealloc(output, (strlen(optarg)+1) * sizeof(char));
strcpy(output, optarg);
break;
- case 'v':
+ case 'V':
printf(VERSION"\n");
return 0;
+ case 'v':
+ cho_log_enable_info_logs();
+ util_log_enable_info_logs();
+ break;
case 'h':
return system("man lorid");
}
diff --git a/out_pdf.c b/out_pdf.c
@@ -349,6 +349,7 @@ pdf_load_fonts(struct Font **needed_fonts, struct Config *config)
LOG_DEBUG("pdfioFileCreateFontObjFromFile failed.");
return false;
}
+ util_log(LOG_INFO, "Loaded font from '%s'.", (*f)->name);
objs_add_obj(&g_fonts, fnt);
} else
if ((name = is_base_font(*f))) {
@@ -363,7 +364,6 @@ pdf_load_fonts(struct Font **needed_fonts, struct Config *config)
} else {
fontpath = fontpath_find(*f, FT_TTF);
if (fontpath) {
- util_log(LOG_INFO, "Loading font from '%s'.", fontpath);
fnt = obj_new();
fnt->name = fnt_name_create(*f);
fnt->value = pdfioFileCreateFontObjFromFile(g_pdf_file, fontpath, true);
@@ -371,12 +371,12 @@ pdf_load_fonts(struct Font **needed_fonts, struct Config *config)
LOG_DEBUG("pdfioFileCreateFontObjFromFile failed.");
return false;
}
+ util_log(LOG_INFO, "Loaded font from '%s'.", fontpath);
objs_add_obj(&g_fonts, fnt);
free(fontpath);
} else {
fontpath = fontpath_find(*f, FT_OTF);
if (fontpath) {
- util_log(LOG_INFO, "Loading font from '%s'.", fontpath);
fnt = obj_new();
fnt->name = fnt_name_create(*f);
fnt->value = pdfioFileCreateFontObjFromFile(g_pdf_file, fontpath, true);
@@ -384,6 +384,7 @@ pdf_load_fonts(struct Font **needed_fonts, struct Config *config)
LOG_DEBUG("pdfioFileCreateFontObjFromFile failed.");
return false;
}
+ util_log(LOG_INFO, "Loaded font from '%s'.", fontpath);
objs_add_obj(&g_fonts, fnt);
free(fontpath);
} else {
@@ -962,12 +963,12 @@ pdf_load_images(struct Obj ***images, pdfio_file_t *file, struct ChoSong **songs
} else {
image_filepath = (char *)&filepath;
}
- util_log(LOG_INFO, "Loading image from '%s'.", image_filepath);
(*images)[i]->value = pdfioFileCreateImageObjFromFile(file, image_filepath, true);
if (!(*images)[i]->value) {
LOG_DEBUG("pdfioFileCreateImageObjFromFile failed.");
return false;
}
+ util_log(LOG_INFO, "Loaded image from '%s'.", image_filepath);
(*images)[i+1] = NULL;
}
free(name);
diff --git a/util.c b/util.c
@@ -10,6 +10,14 @@
#include <limits.h>
#include "util.h"
+static bool g_show_info_logs = false;
+
+void
+util_log_enable_info_logs(void)
+{
+ g_show_info_logs = true;
+}
+
void *
emalloc(size_t size)
{
@@ -35,6 +43,9 @@ erealloc(void *ptr, size_t size)
void
util_log(enum LogLevel level, const char *msg, ...)
{
+ if (level == LOG_INFO && !g_show_info_logs) {
+ return;
+ }
#if COLOR == 1
const char *log_level = "";
const char *color = "";
diff --git a/util.h b/util.h
@@ -38,6 +38,8 @@ struct Size {
double d;
};
+void util_log_enable_info_logs(void);
+
void *emalloc(size_t size);
void *erealloc(void *ptr, size_t size);
void util_log(enum LogLevel level, const char *msg, ...);