1
0
mirror of https://github.com/mpv-player/mpv synced 2025-04-20 22:26:30 +00:00

cosmetics: parser-cfg.c: reformat

This commit is contained in:
Uoti Urpala 2011-07-27 21:11:10 +03:00
parent 507fa7e2c2
commit d8374376c0

View File

@ -16,14 +16,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
/// \defgroup ConfigParsers Config parsers
///
/// The \ref ConfigParsers make use of the \ref Config to setup the config variables,
/// the command line parsers also build the playlist.
///@{
/// \file
#include "config.h" #include "config.h"
#include <stdio.h> #include <stdio.h>
@ -31,10 +23,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <ctype.h> #include <ctype.h>
#ifdef MP_DEBUG
#include <assert.h> #include <assert.h>
#endif
#include "parser-cfg.h" #include "parser-cfg.h"
#include "mp_msg.h" #include "mp_msg.h"
@ -52,9 +41,9 @@ static int recursion_depth = 0;
* \param conffile Path to the config file. * \param conffile Path to the config file.
* \return 1 on sucess, -1 on error. * \return 1 on sucess, -1 on error.
*/ */
int m_config_parse_config_file(m_config_t* config, const char *conffile) int m_config_parse_config_file(m_config_t *config, const char *conffile)
{ {
#define PRINT_LINENUM mp_msg(MSGT_CFGPARSER,MSGL_V,"%s(%d): ", conffile, line_num) #define PRINT_LINENUM mp_msg(MSGT_CFGPARSER, MSGL_V, "%s(%d): ", conffile, line_num)
#define MAX_LINE_LEN 10000 #define MAX_LINE_LEN 10000
#define MAX_OPT_LEN 1000 #define MAX_OPT_LEN 1000
#define MAX_PARAM_LEN 1500 #define MAX_PARAM_LEN 1500
@ -71,16 +60,13 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
int ret = 1; int ret = 1;
int errors = 0; int errors = 0;
int prev_mode = config->mode; int prev_mode = config->mode;
m_profile_t* profile = NULL; m_profile_t *profile = NULL;
#ifdef MP_DEBUG mp_msg(MSGT_CFGPARSER, MSGL_V, "Reading config file %s", conffile);
assert(config != NULL);
// assert(conf_list != NULL);
#endif
mp_msg(MSGT_CFGPARSER,MSGL_V,"Reading config file %s", conffile);
if (recursion_depth > MAX_RECURSION_DEPTH) { if (recursion_depth > MAX_RECURSION_DEPTH) {
mp_msg(MSGT_CFGPARSER,MSGL_ERR,": too deep 'include'. check your configfiles\n"); mp_msg(MSGT_CFGPARSER, MSGL_ERR,
": too deep 'include'. check your configfiles\n");
ret = -1; ret = -1;
goto out; goto out;
} else } else
@ -88,15 +74,16 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
config->mode = M_CONFIG_FILE; config->mode = M_CONFIG_FILE;
if ((line = malloc(MAX_LINE_LEN + 1)) == NULL) { if ((line = malloc(MAX_LINE_LEN + 1)) == NULL) {
mp_msg(MSGT_CFGPARSER,MSGL_FATAL,"\ncan't get memory for 'line': %s", strerror(errno)); mp_msg(MSGT_CFGPARSER, MSGL_FATAL,
"\ncan't get memory for 'line': %s", strerror(errno));
ret = -1; ret = -1;
goto out; goto out;
} else } else
mp_msg(MSGT_CFGPARSER,MSGL_V,"\n"); mp_msg(MSGT_CFGPARSER, MSGL_V, "\n");
if ((fp = fopen(conffile, "r")) == NULL) { if ((fp = fopen(conffile, "r")) == NULL) {
mp_msg(MSGT_CFGPARSER,MSGL_V,": %s\n", strerror(errno)); mp_msg(MSGT_CFGPARSER, MSGL_V, ": %s\n", strerror(errno));
free(line); free(line);
ret = 0; ret = 0;
goto out; goto out;
@ -104,7 +91,7 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
while (fgets(line, MAX_LINE_LEN, fp)) { while (fgets(line, MAX_LINE_LEN, fp)) {
if (errors >= 16) { if (errors >= 16) {
mp_msg(MSGT_CFGPARSER,MSGL_FATAL,"too many errors\n"); mp_msg(MSGT_CFGPARSER, MSGL_FATAL, "too many errors\n");
goto out; goto out;
} }
@ -127,7 +114,8 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
opt[opt_pos++] = line[line_pos++]; opt[opt_pos++] = line[line_pos++];
if (opt_pos >= MAX_OPT_LEN) { if (opt_pos >= MAX_OPT_LEN) {
PRINT_LINENUM; PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER,MSGL_ERR,"too long option at line %d\n",line_num); mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"too long option at line %d\n", line_num);
errors++; errors++;
ret = -1; ret = -1;
goto nextline; goto nextline;
@ -135,7 +123,8 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
} }
if (opt_pos == 0) { if (opt_pos == 0) {
PRINT_LINENUM; PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER,MSGL_ERR,"parse error at line %d\n",line_num); mp_msg(MSGT_CFGPARSER, MSGL_ERR, "parse error at line %d\n",
line_num);
ret = -1; ret = -1;
errors++; errors++;
continue; continue;
@ -143,10 +132,10 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
opt[opt_pos] = '\0'; opt[opt_pos] = '\0';
/* Profile declaration */ /* Profile declaration */
if(opt_pos > 2 && opt[0] == '[' && opt[opt_pos-1] == ']') { if (opt_pos > 2 && opt[0] == '[' && opt[opt_pos - 1] == ']') {
opt[opt_pos-1] = '\0'; opt[opt_pos - 1] = '\0';
if(strcmp(opt+1,"default")) if (strcmp(opt + 1, "default"))
profile = m_config_add_profile(config,opt+1); profile = m_config_add_profile(config, opt + 1);
else else
profile = NULL; profile = NULL;
continue; continue;
@ -154,7 +143,7 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
#ifdef MP_DEBUG #ifdef MP_DEBUG
PRINT_LINENUM; PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER,MSGL_V,"option: %s\n", opt); mp_msg(MSGT_CFGPARSER, MSGL_V, "option: %s\n", opt);
#endif #endif
/* skip whitespaces */ /* skip whitespaces */
@ -164,7 +153,8 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
/* check '=' */ /* check '=' */
if (line[line_pos++] != '=') { if (line[line_pos++] != '=') {
PRINT_LINENUM; PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER,MSGL_ERR,"Option %s needs a parameter at line %d\n",opt,line_num); mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"Option %s needs a parameter at line %d\n", opt, line_num);
ret = -1; ret = -1;
errors++; errors++;
continue; continue;
@ -182,7 +172,9 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
param[param_pos++] = line[line_pos++]; param[param_pos++] = line[line_pos++];
if (param_pos >= MAX_PARAM_LEN) { if (param_pos >= MAX_PARAM_LEN) {
PRINT_LINENUM; PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER,MSGL_ERR,"Option %s has a too long parameter at line %d\n",opt,line_num); mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"Option %s has a too long parameter at line %d\n",
opt, line_num);
ret = -1; ret = -1;
errors++; errors++;
goto nextline; goto nextline;
@ -190,12 +182,13 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
} }
line_pos++; /* skip the closing " or ' */ line_pos++; /* skip the closing " or ' */
} else { } else {
for (param_pos = 0; isprint(line[line_pos]) && !isspace(line[line_pos]) for (param_pos = 0; isprint(line[line_pos])
&& !isspace(line[line_pos])
&& line[line_pos] != '#'; /* NOTHING */) { && line[line_pos] != '#'; /* NOTHING */) {
param[param_pos++] = line[line_pos++]; param[param_pos++] = line[line_pos++];
if (param_pos >= MAX_PARAM_LEN) { if (param_pos >= MAX_PARAM_LEN) {
PRINT_LINENUM; PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER,MSGL_ERR,"too long parameter\n"); mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too long parameter\n");
ret = -1; ret = -1;
errors++; errors++;
goto nextline; goto nextline;
@ -207,7 +200,8 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
/* did we read a parameter? */ /* did we read a parameter? */
if (param_pos == 0) { if (param_pos == 0) {
PRINT_LINENUM; PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER,MSGL_ERR,"Option %s needs a parameter at line %d\n",opt,line_num); mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"Option %s needs a parameter at line %d\n", opt, line_num);
ret = -1; ret = -1;
errors++; errors++;
continue; continue;
@ -215,7 +209,7 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
#ifdef MP_DEBUG #ifdef MP_DEBUG
PRINT_LINENUM; PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER,MSGL_V,"parameter: %s\n", param); mp_msg(MSGT_CFGPARSER, MSGL_V, "parameter: %s\n", param);
#endif #endif
/* now, check if we have some more chars on the line */ /* now, check if we have some more chars on the line */
@ -226,25 +220,31 @@ int m_config_parse_config_file(m_config_t* config, const char *conffile)
/* EOL / comment */ /* EOL / comment */
if (line[line_pos] != '\0' && line[line_pos] != '#') { if (line[line_pos] != '\0' && line[line_pos] != '#') {
PRINT_LINENUM; PRINT_LINENUM;
mp_msg(MSGT_CFGPARSER,MSGL_WARN,"extra characters on line %d: %s\n",line_num, line+line_pos); mp_msg(MSGT_CFGPARSER, MSGL_WARN,
"extra characters on line %d: %s\n",
line_num, line + line_pos);
ret = -1; ret = -1;
} }
if(profile) { if (profile) {
if(!strcmp(opt,"profile-desc")) if (!strcmp(opt, "profile-desc"))
m_profile_set_desc(profile,param), tmp = 1; m_profile_set_desc(profile, param), tmp = 1;
else else
tmp = m_config_set_profile_option(config,profile, tmp = m_config_set_profile_option(config, profile,
opt,param); opt, param);
} else } else
tmp = m_config_set_option(config, opt, param, false); tmp = m_config_set_option(config, opt, param, false);
if (tmp < 0) { if (tmp < 0) {
PRINT_LINENUM; PRINT_LINENUM;
if(tmp == M_OPT_UNKNOWN) { if (tmp == M_OPT_UNKNOWN) {
mp_msg(MSGT_CFGPARSER,MSGL_WARN,"Warning unknown option %s at line %d\n", opt,line_num); mp_msg(MSGT_CFGPARSER, MSGL_WARN,
"Warning unknown option %s at line %d\n",
opt, line_num);
continue; continue;
} }
mp_msg(MSGT_CFGPARSER,MSGL_ERR,"Error parsing option %s=%s at line %d\n",opt,param,line_num); mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"Error parsing option %s=%s at line %d\n",
opt, param, line_num);
ret = -1; ret = -1;
errors++; errors++;
continue; continue;