summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
blob: 5fafaf82bc7f207532c1c04fb2a9ffa7bbd6f88e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include "game.hpp"
#include "diargs.hpp"

#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>

void
printusage(int err)
{
    std::cout << "systemviewer " << VERSION << std::endl << 
        "Usage: systemviewer [OPTION]... [FILE]" << std::endl << 
        "With no FILE, FILE is assumed to be data/sol.csv" << std::endl <<
        "-h --help : print this message" << std::endl;

    std::exit(err);
}

int
main(int argc, char **argv)
{
    std::string system = "dat/sol.csv";
    bool helpflag;

    diargs::ArgsPair args{argc, argv};
    diargs::ArgumentList arglist(
        diargs::OrderedArgument<std::string>(system),
        diargs::ToggleArgument<bool>("help", 'h', helpflag, true)
            );
    diargs::ArgumentParser(printusage, arglist, args);

    if(helpflag) printusage(0);

    struct winsize w;
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
    fcntl(STDIN_FILENO, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);

    Game::setup(w.ws_col, w.ws_row, system);

    while(Game::running()) {
        Game::turn();
    }

    Game::cleanup();
    return 0;
}