mirror of https://github.com/nirenjan/libx52.git
refactor(x52ctl): Break out interactive mode
SonarQube keeps complaining about issues with cognitive complexity and bad practices, this commit addresses those commits.pull/64/head
parent
cdb00739ca
commit
273ed22f8e
|
|
@ -89,15 +89,53 @@ static int send_command(int sock_fd, int argc, char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void interactive_mode(int sock_fd)
|
||||||
|
{
|
||||||
|
bool keep_running = true;
|
||||||
|
char buffer[1024];
|
||||||
|
|
||||||
|
fputs("> ", stdout);
|
||||||
|
while (keep_running && fgets(buffer, sizeof(buffer), stdin) != NULL) {
|
||||||
|
int sargc;
|
||||||
|
char *sargv[512] = { 0 };
|
||||||
|
int pos;
|
||||||
|
|
||||||
|
if (strcasecmp(buffer, "quit\n") == 0) {
|
||||||
|
keep_running = false;
|
||||||
|
} else {
|
||||||
|
/* Break the buffer into argc/argv */
|
||||||
|
sargc = 0;
|
||||||
|
pos = 0;
|
||||||
|
while (buffer[pos]) {
|
||||||
|
if (isspace(buffer[pos])) {
|
||||||
|
buffer[pos] = '\0';
|
||||||
|
pos++;
|
||||||
|
} else {
|
||||||
|
sargv[sargc] = &buffer[pos];
|
||||||
|
sargc++;
|
||||||
|
for (; buffer[pos] && !isspace(buffer[pos]); pos++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (send_command(sock_fd, sargc, sargv)) {
|
||||||
|
keep_running = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keep_running) {
|
||||||
|
fputs("\n> ", stdout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
bool interactive = false;
|
bool interactive = false;
|
||||||
char *socket_path = NULL;
|
const char *socket_path = NULL;
|
||||||
int opt;
|
int opt;
|
||||||
int sock_fd;
|
int sock_fd;
|
||||||
int rc = EXIT_SUCCESS;
|
int rc = EXIT_SUCCESS;
|
||||||
|
|
||||||
char buffer[1024];
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse command line arguments
|
* Parse command line arguments
|
||||||
|
|
@ -142,38 +180,7 @@ int main(int argc, char **argv)
|
||||||
_("Running in interactive mode, ignoring extra arguments\n"));
|
_("Running in interactive mode, ignoring extra arguments\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
fputs("> ", stdout);
|
interactive_mode(sock_fd);
|
||||||
while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
|
|
||||||
int sargc;
|
|
||||||
char *sargv[512] = { 0 };
|
|
||||||
int pos;
|
|
||||||
|
|
||||||
if (strcasecmp(buffer, "quit\n") == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Break the buffer into argc/argv */
|
|
||||||
sargc = 0;
|
|
||||||
pos = 0;
|
|
||||||
while (buffer[pos]) {
|
|
||||||
if (isspace(buffer[pos])) {
|
|
||||||
buffer[pos] = '\0';
|
|
||||||
pos++;
|
|
||||||
} else {
|
|
||||||
sargv[sargc] = &buffer[pos];
|
|
||||||
sargc++;
|
|
||||||
for (; buffer[pos] && !isspace(buffer[pos]); pos++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (send_command(sock_fd, sargc, sargv)) {
|
|
||||||
rc = EXIT_FAILURE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fputs("\n> ", stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (send_command(sock_fd, argc - optind, &argv[optind])) {
|
if (send_command(sock_fd, argc - optind, &argv[optind])) {
|
||||||
rc = EXIT_FAILURE;
|
rc = EXIT_FAILURE;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: libx52 0.3.3\n"
|
"Project-Id-Version: libx52 0.3.3\n"
|
||||||
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
|
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
|
||||||
"POT-Creation-Date: 2026-03-12 12:28-0700\n"
|
"POT-Creation-Date: 2026-03-16 23:07-0700\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
|
@ -951,7 +951,7 @@ msgstr ""
|
||||||
msgid "Argument length too long\n"
|
msgid "Argument length too long\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: daemon/x52ctl.c:142
|
#: daemon/x52ctl.c:180
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Running in interactive mode, ignoring extra arguments\n"
|
msgid "Running in interactive mode, ignoring extra arguments\n"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: libx52 0.2.3\n"
|
"Project-Id-Version: libx52 0.2.3\n"
|
||||||
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
|
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
|
||||||
"POT-Creation-Date: 2026-03-12 12:28-0700\n"
|
"POT-Creation-Date: 2026-03-16 23:07-0700\n"
|
||||||
"PO-Revision-Date: 2023-01-04 08:40-0800\n"
|
"PO-Revision-Date: 2023-01-04 08:40-0800\n"
|
||||||
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
|
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
|
||||||
"Language-Team: Dummy Language for testing i18n\n"
|
"Language-Team: Dummy Language for testing i18n\n"
|
||||||
|
|
@ -1004,7 +1004,7 @@ msgstr "Usageay: %s [-i] [-s ocketsay-athpay] [ommandcay]\n"
|
||||||
msgid "Argument length too long\n"
|
msgid "Argument length too long\n"
|
||||||
msgstr "Argumentay engthlay ootay onglay\n"
|
msgstr "Argumentay engthlay ootay onglay\n"
|
||||||
|
|
||||||
#: daemon/x52ctl.c:142
|
#: daemon/x52ctl.c:180
|
||||||
#, c-format
|
#, c-format
|
||||||
msgid "Running in interactive mode, ignoring extra arguments\n"
|
msgid "Running in interactive mode, ignoring extra arguments\n"
|
||||||
msgstr "Unningray inay interactiveay odemay, ignoringay extraay argumentsay\n"
|
msgstr "Unningray inay interactiveay odemay, ignoringay extraay argumentsay\n"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue