xaizek / pms (License: GPLv3+) (since 2018-12-07)
Older version of Practical Music Search written in C++.
Commit 2481126718d3bb2c5c164a8b35af62ca75eec9db

fixed :rehash problem introduced in 0697558f08ee
Author: Bart Nagel
Author date (UTC): 2010-05-13 12:53
Committer name: Bart Nagel
Committer date (UTC): 2010-05-13 12:53
Parent(s): 358facdba850caf955b6f7fc08291c8d860273fe
Signing key:
Tree: 98feb82f0b158f11beecabfdd28c8e63459f3a26
File Lines added Lines deleted
src/action.cpp 2 2
src/config.cpp 80 0
src/config.h 1 0
src/pms.cpp 2 67
File src/action.cpp changed (mode: 100644) (index 20c1100..58d5901)
... ... long Interface::redraw()
327 327 long Interface::rehash() long Interface::rehash()
328 328 { {
329 329 pms->options->reset(); pms->options->reset();
330 msg->code = source(pms->options->get_string("configfile"));
330 msg->code = pms->config->loadconfigs();
331 331
332 332 if (msg->code == 0) if (msg->code == 0)
333 pms->log(MSG_STATUS, STOK, _("Reloaded configuration file."));
333 pms->log(MSG_STATUS, STOK, _("Reloaded configuration files."));
334 334
335 335 return msg->code; return msg->code;
336 336 } }
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/config.h changed (mode: 100644) (index 0f063d4..946f3ff)
... ... public:
124 124 /* Public members */ /* Public members */
125 125 bool source(string); bool source(string);
126 126 bool readline(string); bool readline(string);
127 bool loadconfigs();
127 128 }; };
128 129
129 130 #endif #endif
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));
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/pms

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/pms

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master