summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/rltiles/tool/main.cc
blob: efca4582a83c375fa6fdfbe46985f64f5b2f2cbc (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include "tile_list_processor.h"

#ifdef USE_TILE
  #include <SDL_main.h>
#endif

static void _usage(const char *fname)
{
    fprintf(stderr, "Usage: %s [-i] [-c] (tile_list.txt)\n", fname);
}

int main(int argc, char **argv)
{
    int arg = 1;
    bool image = false;
    bool code  = false;
    for (; arg < argc; arg++)
    {
        if (argv[arg][0] != '-')
        {
            if (arg == argc - 1)
                break;
            _usage(argv[0]);
            return -1;
        }
        switch (argv[arg][1])
        {
        case 'i':
            image = true;
            break;
        case 'c':
            code = true;
            break;
        default:
            _usage(argv[0]);
            return -1;
            break;
        }
    }

    if (arg >= argc)
    {
        _usage(argv[0]);
        return -1;
    }

    if (!image && !code)
        image = code = true; // Backwards compatibility.

    tile_list_processor proc;

    if (!proc.process_list(argv[arg]))
    {
        fprintf(stderr, "Error: failed to process '%s'\n", argv[1]);
        return -2;
    }

    if (!proc.write_data(image, code))
    {
        fprintf(stderr, "Error: failed to write data for '%s'\n", argv[1]);
        return -3;
    }

    return 0;
}