int main()

in src/apps/miscapps/h3ToHier.c [61:122]


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

    Arg helpArg = ARG_HELP;
    Arg resArg = {.names = {"-r", "--resolution"},
                  .scanFormat = "%d",
                  .valueName = "res",
                  .value = &res,
                  .required = true,
                  .helpText = "Resolution, 0-15 inclusive."};
    Arg parentArg = {
        .names = {"-p", "--parent"},
        .scanFormat = "%" PRIx64,
        .valueName = "parent",
        .value = &parentIndex,
        .helpText = "Print only indexes descendent from this index."};

    Arg *args[] = {&helpArg, &resArg, &parentArg};
    const int numArgs = 3;
    const char *helpText = "Print all indexes at the specified resolution";

    if (parseArgs(argc, argv, numArgs, args, &helpArg, helpText)) {
        return helpArg.found ? 0 : 1;
    }

    if (res > MAX_H3_RES) {
        printHelp(stderr, argv[0], helpText, numArgs, args,
                  "Resolution exceeds maximum resolution.", NULL);
        return 1;
    }

    if (parentArg.found && !H3_EXPORT(h3IsValid)(parentIndex)) {
        printHelp(stderr, argv[0], helpText, numArgs, args,
                  "Parent index is invalid.", NULL);
        return 1;
    }

    if (parentArg.found) {
        // parent is the same or higher resolution than the target.
        if (res <= H3_GET_RESOLUTION(parentIndex)) {
            h3Println(parentIndex);
        } else {
            int rootRes = H3_GET_RESOLUTION(parentIndex);
            H3_SET_RESOLUTION(parentIndex, res);
            recursiveH3IndexToHier(parentIndex, rootRes + 1);
        }
    } else {
        // Generate all
        for (int bc = 0; bc < NUM_BASE_CELLS; bc++) {
            H3Index rootCell = H3_INIT;
            H3_SET_MODE(rootCell, H3_HEXAGON_MODE);
            H3_SET_BASE_CELL(rootCell, bc);
            if (res == 0) {
                h3Println(rootCell);
            } else {
                H3_SET_RESOLUTION(rootCell, res);
                recursiveH3IndexToHier(rootCell, 1);
            }
        }
    }
}