From f71247279d73083699670a7a7d80e493c1dde157 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Thu, 17 Nov 2022 17:20:58 -0800 Subject: [PATCH] execute subcommands We will use this for nostril-query --- nostril.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nostril.c b/nostril.c index 0c28d5a..a47a208 100644 --- a/nostril.c +++ b/nostril.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "secp256k1.h" #include "secp256k1_ecdh.h" @@ -716,6 +717,17 @@ static int make_encrypted_dm(secp256k1_context *ctx, struct key *key, return 1; } +static void try_subcommand(int argc, const char *argv[]) +{ + static char buf[128] = {0}; + const char *sub = argv[1]; + if (strlen(sub) >= 1 && sub[0] != '-') { + snprintf(buf, sizeof(buf)-1, "nostril-%s", sub); + execvp(buf, (char * const *)argv+1); + } +} + + int main(int argc, const char *argv[]) { struct args args = {0}; @@ -729,6 +741,8 @@ int main(int argc, const char *argv[]) if (!init_secp_context(&ctx)) return 2; + try_subcommand(argc, argv); + if (!parse_args(argc, argv, &args, &ev)) { usage(); return 10;