int main()

in src/apps/filters/kRing.c [59:106]


int main(int argc, char* argv[]) {
    int k = 0;
    H3Index origin = 0;

    Arg helpArg = ARG_HELP;
    Arg kArg = {.names = {"-k", NULL},
                .required = true,
                .scanFormat = "%d",
                .valueName = "k",
                .value = &k,
                .helpText = "Radius in hexagons."};
    Arg printDistancesArg = {
        .names = {"-d", "--print-distances"},
        .helpText = "Print distance from origin after each index."};
    Arg originArg = {
        .names = {"-o", "--origin"},
        .scanFormat = "%" PRIx64,
        .valueName = "origin",
        .value = &origin,
        .helpText =
            "Origin, or not specified to read origins from standard input."};

    Arg* args[] = {&helpArg, &kArg, &printDistancesArg, &originArg};

    if (parseArgs(argc, argv, 4, args, &helpArg,
                  "Print indexes k distance away from the origin")) {
        return helpArg.found ? 0 : 1;
    }

    if (originArg.found) {
        doCell(origin, k, printDistancesArg.found);
    } else {
        // process the indexes on stdin
        char buff[BUFF_SIZE];
        while (1) {
            // get an index from stdin
            if (!fgets(buff, BUFF_SIZE, stdin)) {
                if (feof(stdin))
                    break;
                else
                    error("reading H3 index from stdin");
            }

            H3Index h3 = H3_EXPORT(stringToH3)(buff);
            doCell(h3, k, printDistancesArg.found);
        }
    }
}