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é GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Kubat
lektor
Validations
8c0ac8a1
Vérifiée
Valider
8c0ac8a1
rédigé
1 mai 2020
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
WIP: Writing an ini parser
parent
f0615d2f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion
!70
Resolve "Drop inih"
Modifications
3
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
inc/lektor/common.h
+5
-4
5 ajouts, 4 suppressions
inc/lektor/common.h
src/config.c
+68
-10
68 ajouts, 10 suppressions
src/config.c
src/ini/ini.c
+0
-49
0 ajout, 49 suppressions
src/ini/ini.c
avec
73 ajouts
et
63 suppressions
inc/lektor/common.h
+
5
−
4
Voir le fichier @
8c0ac8a1
...
...
@@ -7,6 +7,7 @@
/* Defines */
#define INI_MAX_LINE_LEN 1024
#define URL_MAX_LEN 1024
#define DEFAULT_URL "https://kurisu.iiens.net"
#define GET_ID_JSON DEFAULT_URL "/api_karas.php?id=%ld"
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/config.c
+
68
−
10
Voir le fichier @
8c0ac8a1
#define _POSIX_C_SOURCE 200809L
#include
<common/common.h>
#include
<lektor/common.h>
#include
<lektor/config.h>
#include
<lektor/database.h>
#include
<ini/ini.h>
#include
<stdlib.h>
#include
<errno.h>
#include
<string.h>
...
...
@@ -14,6 +14,71 @@
#include
<sys/types.h>
#include
<sys/stat.h>
#include
<limits.h>
#include
<ctype.h>
typedef
int
(
*
ini_handler
)(
volatile
sqlite3
*
db
,
const
char
*
section
,
const
char
*
name
,
const
char
*
value
);
static
inline
char
*
strip
(
char
*
s
)
{
char
*
p
=
s
+
strlen
(
s
);
while
(
p
>
s
&&
isspace
(
*
(
--
p
)))
*
p
=
0
;
return
s
;
}
static
inline
char
*
skip
(
char
*
s
)
{
while
(
*
s
&&
isspace
(
*
s
))
s
++
;
return
s
;
}
static
inline
int
ini_parse
(
const
char
*
path
,
ini_handler
handle
,
volatile
sqlite3
*
db
)
{
char
line
[
INI_MAX_LINE_LEN
],
*
start
,
*
end
,
*
name
,
*
value
;
int
error
=
1
,
linenum
=
0
;
FILE
*
file
=
fopen
(
path
,
"r"
);
if
(
!
file
)
{
LOG_ERROR_SCT
(
"PARSER"
,
"Failed to open config file '%s'"
,
path
);
return
1
;
}
/* Parse the file */
while
(
NULL
!=
fgets
(
line
,
INI_MAX_LINE_LEN
,
file
))
{
++
linenum
;
start
=
skip
(
strip
(
line
));
/* Skip comments */
if
(
strspn
(
start
,
";#"
))
continue
;
/* Handle sections */
else
if
(
start
[
0
]
==
'['
)
{
end
=
&
start
[
1
+
strcspn
(
start
+
1
,
"]"
)];
if
(
end
[
0
]
==
']'
)
{
}
else
{
LOG_ERROR_SCT
(
"PARSER"
,
"Invalid section name at line '%d'"
,
linenum
);
}
}
/* Handle others */
else
if
(
start
[
0
])
{
}
}
/* End of the function */
error
=
0
;
error:
fclose
(
file
);
if
(
error
)
LOG_ERROR_SCT
(
"PARSER"
,
"An error occured while parsing the file '%s'"
,
path
);
return
error
;
}
int
load_so
(
const
char
*
const
mod_path
,
const
char
*
const
mod_init
,
void
*
mod
)
...
...
@@ -67,7 +132,6 @@ validate_conf(volatile sqlite3 *db)
}
CHK_OPTION
(
"externals"
,
"mkvpropedit"
);
CHK_OPTION
(
"externals"
,
"sqlite3"
);
CHK_OPTION
(
"server"
,
"host"
);
CHK_OPTION
(
"server"
,
"port"
);
...
...
@@ -87,14 +151,8 @@ validate_conf(volatile sqlite3 *db)
}
static
int
#if INI_HANDLER_LINENO
handler
(
void
*
user
,
const
char
*
section
,
const
char
*
name
,
const
char
*
value
,
int
lineno
)
{
UNUSED
(
lineno
);
#else
handler
(
void
*
user
,
const
char
*
section
,
const
char
*
name
,
const
char
*
value
)
handler
(
volatile
sqlite3
*
user
,
const
char
*
section
,
const
char
*
name
,
const
char
*
value
)
{
#endif
RETURN_UNLESS
(
section
&&
name
&&
value
,
"I can't complete the database with incomplete lines"
,
1
);
RETURN_UNLESS
(
database_config_set
(
user
,
section
,
name
,
value
),
"Failed to update the database"
,
0
);
return
1
;
...
...
@@ -166,7 +224,7 @@ found:
int
config_new
(
volatile
sqlite3
*
db
,
const
char
*
conf
)
{
if
(
ini_parse
(
conf
,
handler
,
(
void
*
)
db
))
{
if
(
ini_parse
(
conf
,
handler
,
db
))
{
LOG_ERROR
(
"Failed to parse file %s"
,
conf
);
return
1
;
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/ini/ini.c
+
0
−
49
Voir le fichier @
8c0ac8a1
...
...
@@ -110,48 +110,14 @@ ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
/* Scan through stream line by line */
while
(
reader
(
line
,
(
int
)
max_line
,
stream
)
!=
NULL
)
{
#if INI_ALLOW_REALLOC && !INI_USE_STACK
offset
=
strlen
(
line
);
while
(
offset
==
max_line
-
1
&&
line
[
offset
-
1
]
!=
'\n'
)
{
max_line
*=
2
;
if
(
max_line
>
INI_MAX_LINE
)
max_line
=
INI_MAX_LINE
;
new_line
=
realloc
(
line
,
max_line
);
if
(
!
new_line
)
{
free
(
line
);
return
-
2
;
}
line
=
new_line
;
if
(
reader
(
line
+
offset
,
(
int
)(
max_line
-
offset
),
stream
)
==
NULL
)
break
;
if
(
max_line
>=
INI_MAX_LINE
)
break
;
offset
+=
strlen
(
line
+
offset
);
}
#endif
lineno
++
;
start
=
line
;
#if INI_ALLOW_BOM
if
(
lineno
==
1
&&
(
unsigned
char
)
start
[
0
]
==
0xEF
&&
(
unsigned
char
)
start
[
1
]
==
0xBB
&&
(
unsigned
char
)
start
[
2
]
==
0xBF
)
start
+=
3
;
#endif
start
=
lskip
(
rstrip
(
start
));
if
(
strchr
(
INI_START_COMMENT_PREFIXES
,
*
start
))
{
/* Start-of-line comment */
}
#if INI_ALLOW_MULTILINE
else
if
(
*
prev_name
&&
*
start
&&
start
>
line
)
{
/* Non-blank line with leading whitespace, treat as continuation
of previous name's value (as per Python configparser). */
if
(
!
HANDLER
(
user
,
section
,
prev_name
,
start
)
&&
!
error
)
error
=
lineno
;
}
#endif
else
if
(
*
start
==
'['
)
{
/* A "[section]" line */
end
=
find_chars_or_comment
(
start
+
1
,
"]"
);
...
...
@@ -159,10 +125,6 @@ ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
*
end
=
'\0'
;
strncpy0
(
section
,
start
+
1
,
sizeof
(
section
));
*
prev_name
=
'\0'
;
#if INI_CALL_HANDLER_ON_NEW_SECTION
if
(
!
HANDLER
(
user
,
section
,
NULL
,
NULL
)
&&
!
error
)
error
=
lineno
;
#endif
}
else
if
(
!
error
)
{
/* No ']' found on section line */
error
=
lineno
;
...
...
@@ -188,14 +150,7 @@ ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
error
=
lineno
;
}
else
if
(
!
error
)
{
/* No '=' or ':' found on name[=:]value line */
#if INI_ALLOW_NO_VALUE
*
end
=
'\0'
;
name
=
rstrip
(
start
);
if
(
!
HANDLER
(
user
,
section
,
name
,
NULL
)
&&
!
error
)
error
=
lineno
;
#else
error
=
lineno
;
#endif
}
}
...
...
@@ -205,10 +160,6 @@ ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
#endif
}
#if !INI_USE_STACK
free
(
line
);
#endif
return
error
;
}
...
...
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