Permalink
Browse files

o Print out config file name while spotting a problem

  in the config.
  • Loading branch information...
1 parent 1118ad9 commit 562b4936691b986c78a401cae0f46c0698952643 @hzeller committed Sep 15, 2012
Showing with 42 additions and 29 deletions.
  1. +1 −1 status-server.cc
  2. +31 −23 zita-config.cc
  3. +2 −1 zita-config.h
  4. +8 −4 zita-fconfig.cc
View
@@ -161,7 +161,7 @@ void StatusServer::CreatePage(const char **buffer, size_t *size) {
std::vector<HandlerStats> stat_list;
filesystem_->handler_cache()->GetStats(&stat_list);
- // Get statistics of active files.
+ // Get statistics of active files to add to the existing ones.
double active_music_seen = 0.0;
double active_filtered = 0.0;
for (size_t i = 0; i < stat_list.size(); ++i) {
View
@@ -75,7 +75,7 @@ static int readfile (ZitaConfig *cfg,
k -= delay;
delay = 0;
offset += k;
- fprintf (stderr, "Line %d: First %d frames removed by latency compensation.\n", lnum, k);
+ fprintf (stderr, "%s:%d: First %d frames removed by latency compensation.\n", cfg->config_file, lnum, k);
}
}
err = check_inout (cfg, ip1, op1);
@@ -91,35 +91,38 @@ static int readfile (ZitaConfig *cfg,
if (audio.open_read (path))
{
- fprintf (stderr, "Line %d: Unable to open '%s'.\n", lnum, path);
+ fprintf (stderr, "%s:%d: Unable to open '%s'.\n", cfg->config_file,
+ lnum, path);
return ERR_OTHER;
}
if (audio.rate () != (int) cfg->fsamp)
{
- fprintf (stderr, "Line %d: Sample rate (%d) of '%s' does not match.\n",
- lnum, audio.rate (), path);
+ fprintf (stderr, "%s:%d: Sample rate (%d) of '%s' does not match.\n",
+ cfg->config_file, lnum, audio.rate (), path);
}
nchan = audio.chan ();
nfram = audio.size ();
if ((ichan < 1) || (ichan > nchan))
{
- fprintf (stderr, "Line %d: Channel not available.\n", lnum);
+ fprintf (stderr, "%s:%d: Channel not available.\n",
+ cfg->config_file, lnum);
audio.close ();
return ERR_OTHER;
}
if (offset && audio.seek (offset))
{
- fprintf (stderr, "Line %d: Can't seek to offset.\n", lnum);
+ fprintf (stderr, "%s:%d: Can't seek to offset.\n",
+ cfg->config_file, lnum);
audio.close ();
return ERR_OTHER;
}
if (! length) length = nfram - offset;
if (length > cfg->size - delay)
{
length = cfg->size - delay;
- fprintf (stderr, "Line %d: Data truncated.\n", lnum);
+ fprintf (stderr, "%s:%d: Data truncated.\n", cfg->config_file, lnum);
}
try
@@ -138,7 +141,8 @@ static int readfile (ZitaConfig *cfg,
nfram = audio.read (buff, nfram);
if (nfram < 0)
{
- fprintf (stderr, "Line %d: Error reading file.\n", lnum);
+ fprintf (stderr, "%s:%d: Error reading file.\n",
+ cfg->config_file, lnum);
audio.close ();
delete[] buff;
return ERR_OTHER;
@@ -179,7 +183,8 @@ static int impdirac (ZitaConfig *cfg, const char *line, int lnum)
k = cfg->latency;
if (delay < k)
{
- fprintf (stderr, "Line %d: Dirac pulse removed: delay < latency.\n", lnum);
+ fprintf (stderr, "%s:%d: Dirac pulse removed: delay < latency.\n",
+ cfg->config_file, lnum);
return 0;
}
delay -= k;
@@ -217,7 +222,7 @@ static int imphilbert (ZitaConfig *cfg, const char *line, int lnum)
k = cfg->latency;
if (delay < k + length / 2)
{
- fprintf (stderr, "Line %d: Hilbert impulse removed: delay < latency + lenght / 2.\n", lnum);
+ fprintf (stderr, "%s:%d: Hilbert impulse removed: delay < latency + lenght / 2.\n", cfg->config_file, lnum);
return 0;
}
delay -= k + length / 2;
@@ -265,24 +270,27 @@ static int impcopy (ZitaConfig *cfg, const char *line, int lnum)
}
-int config (ZitaConfig *cfg, const char *config)
+int config (ZitaConfig *cfg, const char *config_file)
{
FILE *F;
int stat, lnum;
char line [1024];
char cdir [1024];
char *p, *q;
- if (! (F = fopen (config, "r")))
+ if (! (F = fopen (config_file, "r")))
{
- fprintf (stderr, "Can't open '%s' for reading\n", config);
+ fprintf (stderr, "Can't open '%s' for reading\n", config_file);
return -1;
}
- char *config_name_copy = strdup(config);
+ // dirname() modifies the input
+ char *config_name_copy = strdup(config_file);
strcpy (cdir, dirname(config_name_copy));
free(config_name_copy);
+ // Remember this for error output.
+ cfg->config_file = config_file;
stat = 0;
lnum = 0;
@@ -321,29 +329,29 @@ int config (ZitaConfig *cfg, const char *config)
if (stat == ERR_OTHER) stat = 0;
if (stat)
{
- fprintf (stderr, "Line %d: ", lnum);
+ fprintf (stderr, "%s:%d: ", config_file, lnum);
switch (stat)
{
case ERR_SYNTAX:
- fprintf (stderr, "Syntax error.\n");
- break;
+ fprintf (stderr, "Syntax error.\n");
+ break;
case ERR_PARAM:
- fprintf (stderr, "Bad or missing parameters.\n");
+ fprintf (stderr, "Bad or missing parameters.\n");
break;
case ERR_ALLOC:
- fprintf (stderr, "Out of memory.\n");
+ fprintf (stderr, "Out of memory.\n");
break;
case ERR_CANTCD:
- fprintf (stderr, "Can't change directory to '%s'.\n", cdir);
+ fprintf (stderr, "Can't change directory to '%s'.\n", cdir);
break;
case ERR_COMMAND:
- fprintf (stderr, "Unknown command.\n");
+ fprintf (stderr, "Unknown command.\n");
break;
case ERR_NOCONV:
- fprintf (stderr, "No convolver yet defined.\n");
+ fprintf (stderr, "No convolver yet defined.\n");
break;
case ERR_IONUM:
- fprintf (stderr, "Bad input or output number.\n");
+ fprintf (stderr, "Bad input or output number.\n");
break;
default:
fprintf (stderr, "Unknown error.\n");
View
@@ -35,12 +35,13 @@ struct ZitaConfig {
unsigned int ninp;
unsigned int nout;
unsigned int size;
+ const char *config_file;
};
enum { NOERR, ERR_OTHER, ERR_SYNTAX, ERR_PARAM, ERR_ALLOC, ERR_CANTCD, ERR_COMMAND, ERR_NOCONV, ERR_IONUM };
-extern int config (ZitaConfig *cfg, const char *config);
+extern int config (ZitaConfig *cfg, const char *config_file);
extern int convnew (ZitaConfig *cfg, const char *line, int lnum);
extern int inpname (ZitaConfig *cfg, const char *line);
extern int outname (ZitaConfig *cfg, const char *line);
View
@@ -38,22 +38,26 @@ int convnew (ZitaConfig *cfg, const char *line, int lnum)
if ((cfg->ninp == 0) || (cfg->ninp > Convproc::MAXINP))
{
- fprintf (stderr, "Line %d: Number of inputs (%d) is out of range.\n", lnum, cfg->ninp);
+ fprintf (stderr, "%s:%d: Number of inputs (%d) is out of range.\n",
+ cfg->config_file, lnum, cfg->ninp);
return ERR_OTHER;
}
if ((cfg->nout == 0) || (cfg->nout > Convproc::MAXOUT))
{
- fprintf (stderr, "Line %d: Number of outputs (%d) is out of range.\n", lnum, cfg->nout);
+ fprintf (stderr, "%s:%d: Number of outputs (%d) is out of range.\n",
+ cfg->config_file, lnum, cfg->nout);
return ERR_OTHER;
}
if (cfg->size > MAXSIZE)
{
- fprintf (stderr, "Line %d: Convolver size (%d) is out of range.\n", lnum, cfg->size);
+ fprintf (stderr, "%s:%d: Convolver size (%d) is out of range.\n",
+ cfg->config_file, lnum, cfg->size);
return ERR_OTHER;
}
if ((dens < 0.0f) || (dens > 1.0f))
{
- fprintf (stderr, "Line %d: Density parameter is out of range.\n", lnum);
+ fprintf (stderr, "%s:%d: Density parameter is out of range.\n",
+ cfg->config_file, lnum);
return ERR_OTHER;
}

0 comments on commit 562b493

Please sign in to comment.