summaryrefslogtreecommitdiff
path: root/core/rdar.c
blob: ff5022fc172ca0ea4f6641157bd05ffef523d2a6 (plain)
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
/*
 * Copyright (c) 2026, Chloe M.
 * Provided under the BSD-3 clause.
 */

#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>

/* Version conversion macros */
#define VERSION_U16(MAJOR, MINOR)   \
    (((MINOR) << 8) | (MAJOR))
#define VERSION_MAJOR(VERSION)      \
    ((VERSION) & 0xFF)
#define VERSION_MINOR(VERSION)      \
    (((VERSION) >> 8) & 0xFF)

/*
 * Software version
 *
 * XXX: We encode it as a U16 so that we may bundle it
 *      with the file data as binary.
 */
#define RDAR_VERSION VERSION_U16(1, 0)  /* v1.0 */

static void
help(void)
{
    printf("usage: ./rdar <... flags>\n");
    printf("[-h]    Display this help menu\n");
    printf("[-v]    Display the program version\n");
}

static void
version(void)
{
    uint16_t Major, Minor;

    Major = VERSION_MAJOR(RDAR_VERSION);
    Minor = VERSION_MINOR(RDAR_VERSION);
    printf("Version v%d.%d\n", Major, Minor);
}

int
main(int argc, char **argv)
{
    int opt;

    if (argc < 2) {
        printf("fatal: too few arguments\n");
        help();
        return -1;
    }

    while ((opt = getopt(argc, argv, "hv")) != -1) {
        switch (opt) {
        case 'h':
            help();
            return -1;
        case 'v':
            version();
            return -1;
        }
    }
}