Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
lektor
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Kubat
lektor
Validations
602a8525
Valider
602a8525
rédigé
5 years ago
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Plain Diff
Merge branch 'drop-pcre' into 'master'
Resolve "Drop libpcre dependency" Closes
#32
See merge request
!63
parents
5974e1ba
d09f91b0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion
!63
Resolve "Drop libpcre dependency"
Modifications
4
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
4 fichiers modifiés
inc/lektor/macro.h
+14
-0
14 ajouts, 0 suppression
inc/lektor/macro.h
meson.build
+0
-1
0 ajout, 1 suppression
meson.build
src/main/lktadm.c
+20
-11
20 ajouts, 11 suppressions
src/main/lktadm.c
src/mkv/write.c
+37
-71
37 ajouts, 71 suppressions
src/mkv/write.c
avec
71 ajouts
et
83 suppressions
inc/lektor/macro.h
+
14
−
0
Voir le fichier @
602a8525
...
@@ -55,6 +55,20 @@
...
@@ -55,6 +55,20 @@
fprintf(stderr, " ! %s: %s\n", __func__, msg); \
fprintf(stderr, " ! %s: %s\n", __func__, msg); \
return ret; \
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 RETURN_UNLESS(cond, msg, ret) RETURN_IF(!(cond), msg, ret)
#define NOTHING
/* Usefull to return nothing. */
#define NOTHING
/* Usefull to return nothing. */
#define STRTOL(ret, str, endptr, err_flag) \
{ \
err_flag = 0; \
errno = 0; \
ret = str == NULL ? 0 : strtol(str, &(endptr), 0); \
err_flag = errno != 0 || endptr == str; \
}
Ce diff est replié.
Cliquez pour l'agrandir.
meson.build
+
0
−
1
Voir le fichier @
602a8525
...
@@ -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
)
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/main/lktadm.c
+
20
−
11
Voir le fichier @
602a8525
...
@@ -66,16 +66,23 @@ open_db(void)
...
@@ -66,16 +66,23 @@ open_db(void)
noreturn
void
noreturn
void
help
(
void
)
help
(
void
)
{
{
printf
(
"Usage for lktadm:
\n\n
"
static
const
char
*
help__
=
" --init: init metadata for all the database according to the root of
\n
"
"USAGE lktadm <COMMAND> [ARGS [...]]:
\n
"
" the root of the base
\n\n
"
"
\n
"
" --file <file.mkv, ...>: set automatically metadata for the file file.mkv
\n\n
"
"COMMANDS:
\n
"
" --prompt-file <file.mkv, ...>: prompt metadata to put for the file file.mkv
\n\n
"
" init the init sub command
\n
"
" --populate-all: populate the database with whate is found in the fs
\n\n
"
" get <id> get the metadata of a kara from kurisu
\n
"
" --cat <file.mkv, ...>: print the metadata of files
\n\n
"
" download <id> <path> download
\n
"
" --get-id <id>: print metadata from kurisu with an id
\n\n
"
" cat <path> display the metadata of a mkv file
\n
"
" --down-id <id> <path>: download a kara from kurisu to a path
\n\n
"
" conf prints the default config file to stdout
\n
"
" --default-conf: output to stdout the default configuration file
\n\n
"
);
"
\n
"
"INIT COMMANDS:
\n
"
" database write the default empty database
\n
"
" popualte populate the database from the filesystem
\n
"
" metadata write metadata to mkv files on the disk using theirs path
\n
"
" file <path> init the metadata for a single file by its path
\n
"
"
\n
"
;
write
(
1
,
help__
,
strlen
(
help__
));
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
}
}
...
@@ -131,6 +138,7 @@ init_populate__(struct lkt_cmd_args *args)
...
@@ -131,6 +138,7 @@ init_populate__(struct lkt_cmd_args *args)
noreturn
void
noreturn
void
init_file__
(
struct
lkt_cmd_args
*
args
)
init_file__
(
struct
lkt_cmd_args
*
args
)
{
{
open_db
();
int
i
;
int
i
;
for
(
i
=
0
;
i
<
args
->
argc
;
++
i
)
for
(
i
=
0
;
i
<
args
->
argc
;
++
i
)
metadata_set_file
((
char
*
)
args
->
argv
[
i
],
mkvpropedit
);
metadata_set_file
((
char
*
)
args
->
argv
[
i
],
mkvpropedit
);
...
@@ -272,6 +280,7 @@ static struct lkt_cmd_opt options_init[] = {
...
@@ -272,6 +280,7 @@ static struct lkt_cmd_opt options_init[] = {
{
.
name
=
"database"
,
.
call
=
init_database__
},
{
.
name
=
"database"
,
.
call
=
init_database__
},
{
.
name
=
"populate"
,
.
call
=
init_populate__
},
{
.
name
=
"populate"
,
.
call
=
init_populate__
},
{
.
name
=
"metadata"
,
.
call
=
init_metadata__
},
{
.
name
=
"metadata"
,
.
call
=
init_metadata__
},
{
.
name
=
"file"
,
.
call
=
init_file__
},
LKT_OPT_NULL
,
LKT_OPT_NULL
,
};
};
...
@@ -293,5 +302,5 @@ static struct lkt_cmd_opt options[] = {
...
@@ -293,5 +302,5 @@ static struct lkt_cmd_opt options[] = {
int
int
main
(
int
argc
,
const
char
**
argv
)
main
(
int
argc
,
const
char
**
argv
)
{
{
lkt_cmd_parse
(
options
,
argc
,
argv
,
help
);
lkt_cmd_parse
(
options
,
argc
-
1
,
argv
+
1
,
help
);
}
}
Ce diff est replié.
Cliquez pour l'agrandir.
src/mkv/write.c
+
37
−
71
Voir le fichier @
602a8525
#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
<pcre.h>
#include
<stdbool.h>
#include
<stdbool.h>
#include
<stdio.h>
#include
<stdio.h>
#include
<unistd.h>
#include
<unistd.h>
...
@@ -14,6 +15,8 @@
...
@@ -14,6 +15,8 @@
#include
<fcntl.h>
#include
<fcntl.h>
#include
<sys/stat.h>
#include
<sys/stat.h>
#include
<sys/wait.h>
#include
<sys/wait.h>
#include
<sys/types.h>
#include
<regex.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
\"
?> "
...
@@ -138,88 +141,51 @@ error:
...
@@ -138,88 +141,51 @@ 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
;
static
regex_t
regex
;
pcre_extra
*
pcre_extra
=
NULL
;
static
int
regex_init
=
0
;
bool
sta
=
false
;
const
size_t
nmatch
=
10
;
const
int
sub_str_vec_len
=
30
;
regmatch_t
pmatch
[
nmatch
];
int
pcre_error_offset
,
pcre_exec_ret
,
sub_str_vec
[
sub_str_vec_len
],
i
,
num
;
int
reti
,
sta
=
false
;
char
num_str
[
LEKTOR_TAG_MAX
];
char
msgbuf
[
LEKTOR_TAG_MAX
];
const
char
*
substr
;
char
*
endptr
;
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)([[:digit:]]*) - (.+)
\\
.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
);
if
(
!
regex_init
)
GOTO_IF
(
regcomp
(
&
regex
,
rgx
,
REG_EXTENDED
),
"Failed to compile regex"
,
error
);
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
);
reti
=
regexec
(
&
regex
,
mkvfile
,
nmatch
,
pmatch
,
0
);
if
(
!
reti
)
{
if
(
pcre_exec_ret
<
0
)
{
/* Match */
fprintf
(
stderr
,
" ! metadata_from_path: PCRE error
\n
"
);
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
;
goto
error
;
}
}
else
{
regerror
(
reti
,
&
regex
,
msgbuf
,
sizeof
(
msgbuf
));
if
(
pcre_exec_ret
==
0
)
{
fprintf
(
stderr
,
"Failed to execute regex: %s
\n
"
,
msgbuf
);
// To much -> error in our case //
fprintf
(
stderr
,
" ! metadata_from_path: To much matches found for file: %s
\n
"
,
mkvfile
);
goto
error
;
goto
error
;
}
}
for
(
i
=
1
;
i
<
pcre_exec_ret
;
++
i
)
{
STRTOL
(
meta
->
song_number
,
msgbuf
,
endptr
,
reti
);
pcre_get_substring
(
mkvfile
,
sub_str_vec
,
pcre_exec_ret
,
i
,
&
substr
);
if
(
reti
||
meta
->
song_number
<=
0
)
meta
->
song_number
=
1
;
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
;
}
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
;
}
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter