Skip to content
Extraits de code Groupes Projets
Vérifiée Valider bdc0db1a rédigé par Kubat's avatar Kubat
Parcourir les fichiers

WIP: Removes PCRE, prepare for POSIX regex, NOT WORKING

parent 89ed2e9a
Branches
Étiquettes
1 requête de fusion!63Resolve "Drop libpcre dependency"
Ce commit fait partie de la requête de fusion !63. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
...@@ -53,7 +53,6 @@ includes = include_directories('inc') ...@@ -53,7 +53,6 @@ includes = include_directories('inc')
# Server # Server
core_deps = [ dependency('sqlite3', version : '>= 3.31.0') core_deps = [ dependency('sqlite3', version : '>= 3.31.0')
, dependency('libpcre')
, dependency('libcurl') , dependency('libcurl')
, dependency('json-c') , dependency('json-c')
, dependency('threads', required : true) , dependency('threads', required : true)
......
#define _POSIX_C_SOURCE 200809L #define _POSIX_C_SOURCE 200809L
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include <lektor/macro.h>
#include <lektor/defines.h>
#include <lektor/mkv.h> #include <lektor/mkv.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
...@@ -16,8 +18,6 @@ ...@@ -16,8 +18,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <regex.h> #include <regex.h>
#include <pcre.h>
static const char *METADATA_TEMPLATE = static const char *METADATA_TEMPLATE =
" <?xml version=\"1.0\" encoding=\"UTF-8\"?> " " <?xml version=\"1.0\" encoding=\"UTF-8\"?> "
" <Tags> " " <Tags> "
...@@ -141,88 +141,39 @@ error: ...@@ -141,88 +141,39 @@ error:
static bool static bool
metadata_from_path(char *const mkvfile, struct kara_metadata *meta) metadata_from_path(char *const mkvfile, struct kara_metadata *meta)
{ {
pcre *regex = NULL; regex_t regex;
pcre_extra *pcre_extra = NULL; const size_t nmatch = 10;
bool sta = false; regmatch_t pmatch[nmatch];
const int sub_str_vec_len = 30; int reti, sta = false;
int pcre_error_offset, pcre_exec_ret, sub_str_vec[sub_str_vec_len], i, num; char msgbuf[LEKTOR_TAG_MAX];
char num_str[LEKTOR_TAG_MAX];
const char *substr;
char *copy_to;
static const char *rgx = static const char *rgx =
"^\\/(?:.+)\\/(vo|va|amv|cdg|autres|vocaloid)\\/" "^\\/(?:.+)\\/(vo|va|amv|cdg|autres|vocaloid)\\/"
"(jp|fr|en|ru|sp|it|ch|latin|multi|undefined)\\/(.+)\\/" "(jp|fr|en|ru|sp|it|ch|latin|multi|undefined)\\/(.+)\\/"
"(.+) - (OP|ED|IS|AMV|VOCA|PV|MV|LIVE)(\\d*) - (.+)\\.mkv$"; "(.+) - (OP|ED|IS|AMV|VOCA|PV|MV|LIVE)(\\d*) - (.+)\\.mkv$";
const char *pcre_error_str = NULL;
if ((regex = pcre_compile(rgx, 0, &pcre_error_str, &pcre_error_offset, NULL)) == NULL) {
fprintf(stderr, " ! metadata_from_path: failed to compile regex\n");
return false;
}
pcre_extra = pcre_study(regex, 0, &pcre_error_str); RETURN_IF(regcomp(&regex, rgx, REG_EXTENDED), "Failed to compile regex", false);
if (pcre_error_str != NULL) {
fprintf(stderr, " ! metadata_from_path: failed to study regex: %s\n", pcre_error_str);
goto error;
}
memset(meta, 0, sizeof(struct kara_metadata)); memset(meta, 0, sizeof(struct kara_metadata));
memset(num_str, 0, LEKTOR_TAG_MAX * sizeof(char)); memset(msgbuf, 0, LEKTOR_TAG_MAX * sizeof(char));
pcre_exec_ret = pcre_exec(regex, pcre_extra, mkvfile, strlen(mkvfile), 0, 0,
sub_str_vec, sub_str_vec_len);
if (pcre_exec_ret < 0) { reti = regexec(&regex, mkvfile, nmatch, pmatch, 0);
fprintf(stderr, " ! metadata_from_path: PCRE error\n");
goto error;
}
if (pcre_exec_ret == 0) { if (!reti) {
// To much -> error in our case // /* Match */
fprintf(stderr, " ! metadata_from_path: To much matches found for file: %s\n", mkvfile); exit(100);
} else if (REG_NOMATCH == reti) {
fprintf(stderr, "No match for: %s\n", mkvfile);
goto error; goto error;
} } else {
regerror(reti, &regex, msgbuf, sizeof(msgbuf));
for (i = 1; i < pcre_exec_ret; ++i) { fprintf(stderr, "Failed to execute regex: %s\n", msgbuf);
pcre_get_substring(mkvfile, sub_str_vec, pcre_exec_ret, i, &substr);
if (i == 1)
copy_to = meta->song_type;
else if (i == 2)
copy_to = meta->language;
else if (i == 3)
copy_to = meta->author_name;
else if (i == 4)
copy_to = meta->source_name;
else if (i == 5)
copy_to = meta->category;
else if (i == 6)
copy_to = num_str;
else if (i == 7)
copy_to = meta->song_name;
else {
pcre_free_substring(substr);
goto error; goto error;
} }
snprintf(copy_to, LEKTOR_TAG_MAX, "%s", substr);
pcre_free_substring(substr);
}
meta->song_number = ((num = atoi(num_str)) <= 0) ? 1 : num;
sta = true; sta = true;
error: error:
pcre_free(regex); regfree(&regex);
if (pcre_extra != NULL) {
#ifdef PCRE_CONFIG_JIT
pcre_free_study(pcre_extra);
#else
pcre_free(pcre_extra);
#endif
}
return sta; return sta;
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter