Skip to content
suit Artifact [71181dffe4]
Login

Artifact [71181dffe4]

Artifact 71181dffe40fc1fbcb9dd359189a15fb57455815704af84aca55039f1cd972d0:


#include "bench.h"
#include "conf.h"
#include "platform.h"
#include "stamp.h"

#include <errno.h>
#include <string.h>
#include <unistd.h>

static Conf conf;

static int usage(void)
{
    say(STDERR_FILENO, "usage: suit check FILE\n"
        "       suit stamp PATH...\n"
        "       suit run\n"
        "       suit bench [-n N] [-e EMPTY_PROGRAM] [-t MICROSECONDS] [-m KIB]\n");
    return 2;
}

static int cmd_check(const char *path)
{
    ConfError err;
    if (!conf_load(&conf, path, &err)) {
        say(STDERR_FILENO, "%s:%d: %s\n", path, err.line, err.msg);
        return 2;
    }
    if (!conf_dump(&conf, STDOUT_FILENO)) {
        say(STDERR_FILENO, "suit: cannot write the dump: %s\n", strerror(errno));
        return 1;
    }
    return 0;
}

int main(int argc, char **argv)
{
    if (argc < 2) return usage();
    const char *cmd = argv[1];
    if (strcmp(cmd, "run") == 0) return argc == 2 ? stamp_run() : usage();
    if (strcmp(cmd, "check") == 0) return argc == 3 ? cmd_check(argv[2]) : usage();
    if (strcmp(cmd, "stamp") == 0) return argc >= 3 ? stamp_write(argc - 2, argv + 2) : usage();
    if (strcmp(cmd, "bench") == 0) return bench_main(argc - 2, argv + 2);
    return usage();
}