From 03855144217a8ce94398eb9199f96f2700c2bce0 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Mon, 20 Apr 2020 17:48:12 +0200 Subject: [PATCH] Working --- inc/lektor/macro.h | 6 ++++++ src/mkv/write.c | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/inc/lektor/macro.h b/inc/lektor/macro.h index 712ae9f9..468f1de0 100644 --- a/inc/lektor/macro.h +++ b/inc/lektor/macro.h @@ -55,6 +55,12 @@ fprintf(stderr, " ! %s: %s\n", __func__, msg); \ return ret; \ } +#define GOTO_IF(cond, msg, label) \ + if (cond) { \ + fprintf(stderr, " ! %s: %s\n", __func__, msg); \ + goto label; \ + } +#define GOTO_UNLESS(cond, msg, label) GOTO_IF(!(cond), msg, ret) #define RETURN_UNLESS(cond, msg, ret) RETURN_IF(!(cond), msg, ret) #define NOTHING /* Usefull to return nothing. */ diff --git a/src/mkv/write.c b/src/mkv/write.c index b3bad2e9..b712d838 100644 --- a/src/mkv/write.c +++ b/src/mkv/write.c @@ -152,16 +152,20 @@ metadata_from_path(char *const mkvfile, struct kara_metadata *meta) "(jp|fr|en|ru|sp|it|ch|latin|multi|undefined)/(.+)/" "(.+) - (OP|ED|IS|AMV|VOCA|PV|MV|LIVE)([[:digit:]]*) - (.+)\\.mkv$"; - RETURN_IF(regcomp(®ex, rgx, REG_EXTENDED), "Failed to compile regex", false); - + GOTO_IF(regcomp(®ex, rgx, REG_EXTENDED), "Failed to compile regex", error); memset(meta, 0, sizeof(struct kara_metadata)); memset(msgbuf, 0, LEKTOR_TAG_MAX * sizeof(char)); reti = regexec(®ex, mkvfile, nmatch, pmatch, 0); - if (!reti) { /* Match */ - exit(100); + memcpy(meta->category, mkvfile + pmatch[2].rm_so, pmatch[2].rm_eo - pmatch[2].rm_so); + memcpy(meta->language, mkvfile + pmatch[3].rm_so, pmatch[3].rm_eo - pmatch[3].rm_so); + memcpy(meta->author_name, mkvfile + pmatch[4].rm_so, pmatch[4].rm_eo - pmatch[4].rm_so); + memcpy(meta->source_name, mkvfile + pmatch[5].rm_so, pmatch[5].rm_eo - pmatch[5].rm_so); + memcpy(meta->song_type, mkvfile + pmatch[6].rm_so, pmatch[6].rm_eo - pmatch[6].rm_so); + memcpy(msgbuf, mkvfile + pmatch[7].rm_so, pmatch[7].rm_eo - pmatch[7].rm_so); + memcpy(meta->song_name, mkvfile + pmatch[8].rm_so, pmatch[8].rm_eo - pmatch[8].rm_so); } else if (REG_NOMATCH == reti) { fprintf(stderr, "No match for: %s\n", mkvfile); goto error; @@ -171,6 +175,12 @@ metadata_from_path(char *const mkvfile, struct kara_metadata *meta) goto error; } + if (msgbuf[0] != '\0') { + meta->song_number = atoi(msgbuf); /* TODO: Use strtol */ + meta->song_number = MAX(1, meta->song_number); + } else + meta->song_number = 1; + sta = true; error: regfree(®ex); -- GitLab