From a998c733626121f72fcbfc037d90edd938b1e002 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 31 Mar 2024 20:24:07 +0400 Subject: [PATCH] command -> mode. --- src/main.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main.c b/src/main.c index 99f7011..84702e7 100644 --- a/src/main.c +++ b/src/main.c @@ -27,7 +27,7 @@ struct options { const char *addressbook_path; const char *key_path; bool is_alias_passed; - char command; + char mode; }; int parse_argv(int argc, const char **argv, struct options *opts); @@ -72,7 +72,7 @@ int main(int argc, const char **argv) { fclose(addrbook_file); } - if (opts.command == 'c' && opts.is_alias_passed) { + if (opts.mode == 'c' && opts.is_alias_passed) { addrbook_entry_t *aec = addrbook_get_by_alias(&ab, opts.addr); if (aec == NULL) { fprintf(stderr, "An alias \"%s\" is not in an addressbook!\n", opts.addr); @@ -128,13 +128,13 @@ int main(int argc, const char **argv) { fclose(skey_file); } - (opts.command == 'c') ? + (opts.mode == 'c') ? (result = net_client_init(&n, opts.addr, opts.port)) : (result = net_server_init(&n, opts.addr , opts.port)); if (result != 0) goto cleanup; - (opts.command == 'c') ? + (opts.mode == 'c') ? (result = client_handshake(&n, &s, &ok, &rk)) : (result = server_handshake(&n, &s, &ok, &rk)); if (result != 0) @@ -152,19 +152,19 @@ int main(int argc, const char **argv) { // audio_init_default(&aud, CHANNELS, SAMPLE_RATE, FRAMES_PER_BUFFFER); - // (opts.command == 'c') ? + // (opts.mode == 'c') ? // (audio_stream_input_toggle(&aud)) // : (audio_stream_output_toggle(&aud)); // for (size_t i = 0; i < (20 * SAMPLE_RATE)/FRAMES_PER_BUFFFER; ++i) { - // if (opts.command == 'c') { + // if (opts.mode == 'c') { // audio_read(&aud, aud_buf, AUDIO_BUF_SIZE); // } else { // // // } // } - // (opts.command == 'c') ? + // (opts.mode == 'c') ? // (audio_stream_input_toggle(&aud)) // : (audio_stream_output_toggle(&aud)); @@ -281,7 +281,7 @@ int server_handshake(net_t *const n, crypt_session_t *const s, crypt_key_t *cons int parse_argv(int argc, const char **argv, struct options *opts) { if (argc == 1) return -1; - int command_arg_num = 0; + int mode_arg_num = 0; for (int i = 1; i < argc; ++i) { if (argv[i][0] == '-') { @@ -306,17 +306,17 @@ int parse_argv(int argc, const char **argv, struct options *opts) { default: return -1; } } else { - if (opts->command == 'c' || opts->command == 's') { - if (command_arg_num == 0) + if (opts->mode == 'c' || opts->mode == 's') { + if (mode_arg_num == 0) opts->addr = argv[i]; - else if (command_arg_num == 1) + else if (mode_arg_num == 1) opts->port = argv[i]; - ++command_arg_num; + ++mode_arg_num; } else { switch (argv[i][0]) { case 'c': case 's': - opts->command = argv[i][0]; + opts->mode = argv[i][0]; break; default: return -1; } @@ -330,10 +330,10 @@ int parse_argv(int argc, const char **argv, struct options *opts) { r = inet_pton(AF_INET6, opts->addr, &test); opts->is_alias_passed = r == 0; - if (opts->command == 's' && opts->is_alias_passed) + if (opts->mode == 's' && opts->is_alias_passed) return -1; - if (opts->command == '\0' || opts->addr[0] == '\0' + if (opts->mode == '\0' || opts->addr[0] == '\0' || (!opts->is_alias_passed && opts->port == NULL)) return -1;