Skip to content

Commit

Permalink
Added argument for alternate pcurses.conf location
Browse files Browse the repository at this point in the history
  • Loading branch information
UffeJakobsen authored and schuay committed Mar 15, 2014
1 parent c9f19fe commit d8892e9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/config.h
Expand Up @@ -37,6 +37,9 @@ class Config
std::string getpcursesconffile() const {
return pcursesconffile;
}
void setpcursesconffile(const std::string &s) {
pcursesconffile = s;
}
std::string getrootdir() const {
return rootdir;
}
Expand Down
11 changes: 8 additions & 3 deletions src/main.cpp
Expand Up @@ -22,19 +22,24 @@
#include "pcursesexception.h"
#include "program.h"

static char *opt_conf_file = nullptr;

void parseargs(int argc, char *argv[])
{
int opt;

while ((opt = getopt(argc, argv, "hv")) != -1) {
while ((opt = getopt(argc, argv, "hvf:")) != -1) {
switch (opt) {
case 'f':
opt_conf_file = optarg;
break;
case 'v':
fprintf(stdout, "%s %d\n", APPLICATION_NAME, VERSION);
exit(EXIT_SUCCESS);
break;
case 'h':
default:
fprintf(stderr, "Usage: %s [-h] [-v]\n", APPLICATION_NAME);
fprintf(stderr, "Usage: %s [-h] [-v] [-f CONF_FILE]\n", APPLICATION_NAME);
exit(EXIT_FAILURE);
}
}
Expand All @@ -49,7 +54,7 @@ int main(int argc, char *argv[])
Program *p = new Program();

try {
p->init();
p->init(opt_conf_file);
p->mainloop();
} catch (PcursesException e) {
err = e.getmessage();
Expand Down
6 changes: 5 additions & 1 deletion src/program.cpp
Expand Up @@ -109,8 +109,12 @@ void Program::init_misc()
execmacro("startup");
}

void Program::init()
void Program::init(const char *conf_file)
{
if (conf_file != nullptr) {
conf.setpcursesconffile(conf_file);
}

loadpkgs();

CursesUi::ui().enable_curses(&filteredpackages, &opqueue);
Expand Down
2 changes: 1 addition & 1 deletion src/program.h
Expand Up @@ -30,7 +30,7 @@ class Program
Program();
~Program();

void init();
void init(const char *conf_file = NULL);
void mainloop();

private:
Expand Down

0 comments on commit d8892e9

Please sign in to comment.