File src/config.cpp changed (mode: 100644) (index b337b8e..9dd1e49) |
... |
... |
bool Configurator::readline(string buffer) |
682 |
682 |
return true; |
return true; |
683 |
683 |
} |
} |
684 |
684 |
|
|
|
685 |
|
/* |
|
686 |
|
* Load all configuration files |
|
687 |
|
*/ |
|
688 |
|
bool Configurator::loadconfigs() |
|
689 |
|
{ |
|
690 |
|
string str; |
|
691 |
|
|
|
692 |
|
char * homedir; |
|
693 |
|
char * xdgconfighome; |
|
694 |
|
char * xdgconfigdirs; |
|
695 |
|
string next; |
|
696 |
|
vector<string> configfiles; |
|
697 |
|
|
|
698 |
|
homedir = getenv("HOME"); |
|
699 |
|
xdgconfighome = getenv("XDG_CONFIG_HOME"); |
|
700 |
|
xdgconfigdirs = getenv("XDG_CONFIG_DIRS"); |
|
701 |
|
|
|
702 |
|
/* Make a list of possible configuration files */ |
|
703 |
|
// commandline argument |
|
704 |
|
if (pms->options->get_string("configfile").length() > 0) |
|
705 |
|
configfiles.push_back(pms->options->get_string("configfile")); |
|
706 |
|
|
|
707 |
|
// XDG config home (usually $HOME/.config) |
|
708 |
|
if (xdgconfighome == NULL || strlen(xdgconfighome) == 0) |
|
709 |
|
{ |
|
710 |
|
if (homedir != NULL && strlen(homedir) > 0) |
|
711 |
|
{ |
|
712 |
|
str = homedir; |
|
713 |
|
configfiles.push_back(str + "/.config/pms/rc"); |
|
714 |
|
} |
|
715 |
|
} |
|
716 |
|
else |
|
717 |
|
{ |
|
718 |
|
str = xdgconfighome; |
|
719 |
|
configfiles.push_back(str + "/pms/rc"); |
|
720 |
|
} |
|
721 |
|
// XDG config dirs (colon-separated priority list, defaults to just /etc/xdg) |
|
722 |
|
if (xdgconfigdirs == NULL || strlen(xdgconfigdirs) == 0) |
|
723 |
|
{ |
|
724 |
|
configfiles.push_back("/usr/local/etc/xdg/pms/rc"); |
|
725 |
|
configfiles.push_back("/etc/xdg/pms/rc"); |
|
726 |
|
} |
|
727 |
|
else |
|
728 |
|
{ |
|
729 |
|
next = ""; |
|
730 |
|
str = xdgconfigdirs; |
|
731 |
|
for (string::const_iterator it = str.begin(); it != str.end(); it++) |
|
732 |
|
{ |
|
733 |
|
if (*it == ':') |
|
734 |
|
{ |
|
735 |
|
if (next.length() > 0) |
|
736 |
|
{ |
|
737 |
|
configfiles.push_back(next + "/pms/rc"); |
|
738 |
|
next = ""; |
|
739 |
|
} |
|
740 |
|
} |
|
741 |
|
else |
|
742 |
|
next += *it; |
|
743 |
|
} |
|
744 |
|
if (next.length() > 0) |
|
745 |
|
configfiles.push_back(next + "/pms/rc"); |
|
746 |
|
} |
|
747 |
|
|
|
748 |
|
/* Load configuration files in reverse order */ |
|
749 |
|
for (int i = configfiles.size() - 1; i >= 0; i--) |
|
750 |
|
{ |
|
751 |
|
if (!source(configfiles[i])) |
|
752 |
|
{ |
|
753 |
|
if (pms->msg->code != CERR_NO_FILE) |
|
754 |
|
{ |
|
755 |
|
pms->log(MSG_CONSOLE, 0, _("\nConfiguration error in file %s:\n%s\n"), configfiles[i].c_str(), pms->msg->str.c_str()); |
|
756 |
|
return false; |
|
757 |
|
} |
|
758 |
|
pms->log(MSG_CONSOLE, 0, _("Didn't find configuration file %s\n"), configfiles[i].c_str()); |
|
759 |
|
} |
|
760 |
|
} |
|
761 |
|
|
|
762 |
|
return true; |
|
763 |
|
} |
|
764 |
|
|
685 |
765 |
/* |
/* |
686 |
766 |
* Set a color pair for a field |
* Set a color pair for a field |
687 |
767 |
*/ |
*/ |
File src/pms.cpp changed (mode: 100644) (index b8c610c..219d8f7) |
... |
... |
int Pms::init() |
355 |
355 |
vector<string> * tok; |
vector<string> * tok; |
356 |
356 |
|
|
357 |
357 |
int exitcode = PMS_EXIT_SUCCESS; |
int exitcode = PMS_EXIT_SUCCESS; |
358 |
|
char * homedir; |
|
359 |
358 |
char * host; |
char * host; |
360 |
359 |
char * port; |
char * port; |
361 |
360 |
char * password; |
char * password; |
362 |
361 |
const char * charset = NULL; |
const char * charset = NULL; |
363 |
|
char * xdgconfighome; |
|
364 |
|
char * xdgconfigdirs; |
|
365 |
|
string next; |
|
366 |
|
vector<string> configfiles; |
|
367 |
362 |
|
|
368 |
363 |
/* Internal pointers */ |
/* Internal pointers */ |
369 |
364 |
msg = new Message(); |
msg = new Message(); |
|
... |
... |
int Pms::init() |
383 |
378 |
printf("%s v%s\n%s\n", PMS_NAME, PACKAGE_VERSION, PMS_COPYRIGHT); |
printf("%s v%s\n%s\n", PMS_NAME, PACKAGE_VERSION, PMS_COPYRIGHT); |
384 |
379 |
|
|
385 |
380 |
/* Read important environment variables */ |
/* Read important environment variables */ |
386 |
|
homedir = getenv("HOME"); |
|
387 |
381 |
host = getenv("MPD_HOST"); |
host = getenv("MPD_HOST"); |
388 |
382 |
port = getenv("MPD_PORT"); |
port = getenv("MPD_PORT"); |
389 |
383 |
password = getenv("MPD_PASSWORD"); |
password = getenv("MPD_PASSWORD"); |
390 |
|
xdgconfighome = getenv("XDG_CONFIG_HOME"); |
|
391 |
|
xdgconfigdirs = getenv("XDG_CONFIG_DIRS"); |
|
392 |
384 |
|
|
393 |
385 |
/* Set up field types */ |
/* Set up field types */ |
394 |
386 |
fieldtypes = new Fieldtypes(); |
fieldtypes = new Fieldtypes(); |
|
... |
... |
int Pms::init() |
453 |
445 |
return PMS_EXIT_BADARGS; |
return PMS_EXIT_BADARGS; |
454 |
446 |
} |
} |
455 |
447 |
|
|
456 |
|
/* Make a list of possible configuration files */ |
|
457 |
|
// commandline argument |
|
458 |
|
if (options->get_string("configfile").length() > 0) |
|
459 |
|
configfiles.push_back(options->get_string("configfile")); |
|
460 |
|
|
|
461 |
|
// XDG config home (usually $HOME/.config) |
|
462 |
|
if (xdgconfighome == NULL || strlen(xdgconfighome) == 0) |
|
463 |
|
{ |
|
464 |
|
if (homedir != NULL && strlen(homedir) > 0) |
|
465 |
|
{ |
|
466 |
|
str = homedir; |
|
467 |
|
configfiles.push_back(str + "/.config/pms/rc"); |
|
468 |
|
} |
|
469 |
|
} |
|
470 |
|
else |
|
471 |
|
{ |
|
472 |
|
str = xdgconfighome; |
|
473 |
|
configfiles.push_back(str + "/pms/rc"); |
|
474 |
|
} |
|
475 |
|
// XDG config dirs (colon-separated priority list, defaults to just /etc/xdg) |
|
476 |
|
if (xdgconfigdirs == NULL || strlen(xdgconfigdirs) == 0) |
|
477 |
|
{ |
|
478 |
|
configfiles.push_back("/usr/local/etc/xdg/pms/rc"); |
|
479 |
|
configfiles.push_back("/etc/xdg/pms/rc"); |
|
480 |
|
} |
|
481 |
|
else |
|
482 |
|
{ |
|
483 |
|
next = ""; |
|
484 |
|
str = xdgconfigdirs; |
|
485 |
|
for (string::const_iterator it = str.begin(); it != str.end(); it++) |
|
486 |
|
{ |
|
487 |
|
if (*it == ':') |
|
488 |
|
{ |
|
489 |
|
if (next.length() > 0) |
|
490 |
|
{ |
|
491 |
|
configfiles.push_back(next + "/pms/rc"); |
|
492 |
|
next = ""; |
|
493 |
|
} |
|
494 |
|
} |
|
495 |
|
else |
|
496 |
|
next += *it; |
|
497 |
|
} |
|
498 |
|
if (next.length() > 0) |
|
499 |
|
configfiles.push_back(next + "/pms/rc"); |
|
500 |
|
} |
|
501 |
|
|
|
502 |
|
/* Load configuration files in reverse order */ |
|
503 |
|
for (int i = configfiles.size() - 1; i >= 0; i--) |
|
504 |
|
{ |
|
505 |
|
if (!config->source(configfiles[i])) |
|
506 |
|
{ |
|
507 |
|
if (msg->code != CERR_NO_FILE) |
|
508 |
|
{ |
|
509 |
|
pms->log(MSG_CONSOLE, 0, _("\nConfiguration error in file %s:\n%s\n"), configfiles[i].c_str(), msg->str.c_str()); |
|
510 |
|
return PMS_EXIT_CONFIGERR; |
|
511 |
|
} |
|
512 |
|
pms->log(MSG_CONSOLE, 0, _("Didn't find configuration file %s\n"), configfiles[i].c_str()); |
|
513 |
|
} |
|
514 |
|
} |
|
|
448 |
|
if (!config->loadconfigs()) |
|
449 |
|
return PMS_EXIT_CONFIGERR; |
515 |
450 |
|
|
516 |
451 |
/* Seed random number generator */ |
/* Seed random number generator */ |
517 |
452 |
srand(time(NULL)); |
srand(time(NULL)); |