You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2022/11/07 06:24:16 UTC
[incubator-nuttx-apps] 02/03: system/telnet: Fix the style warning
This is an automated email from the ASF dual-hosted git repository.
masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 12863fbd521966d196b75898ba870bf7d024bc3a
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Oct 19 00:46:17 2022 +0800
system/telnet: Fix the style warning
and remove the unused code
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
examples/nxterm/nxterm_main.c | 10 ----------
examples/telnetd/telnetd.c | 11 ++++++-----
nshlib/nsh.h | 2 --
system/nsh/nsh_main.c | 10 ----------
system/telnet/telnet_client.c | 33 ++++++++++++++++++++++++---------
5 files changed, 30 insertions(+), 36 deletions(-)
diff --git a/examples/nxterm/nxterm_main.c b/examples/nxterm/nxterm_main.c
index 8555980c5..b3c736ea8 100644
--- a/examples/nxterm/nxterm_main.c
+++ b/examples/nxterm/nxterm_main.c
@@ -53,16 +53,6 @@
#include "nxterm_internal.h"
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* The NSH telnet console requires networking support (and TCP/IP) */
-
-#ifndef CONFIG_NET
-# undef CONFIG_NSH_TELNET
-#endif
-
/****************************************************************************
* Public Data
****************************************************************************/
diff --git a/examples/telnetd/telnetd.c b/examples/telnetd/telnetd.c
index 9bbc00683..e51af2d79 100644
--- a/examples/telnetd/telnetd.c
+++ b/examples/telnetd/telnetd.c
@@ -76,7 +76,7 @@ static void telnetd_parse(FAR char *line, int len);
* Private Data
****************************************************************************/
-static struct ptentry_s g_parsetab[] =
+static const struct ptentry_s g_parsetab[] =
{
{"help", telnetd_help},
{"exit", telnetd_quit},
@@ -127,7 +127,7 @@ static void telnetd_quit(int argc, char **argv)
static void telnetd_parse(FAR char *line, int len)
{
- struct ptentry_s *entry;
+ FAR const struct ptentry_s *entry;
FAR char *cmd;
FAR char *saveptr;
@@ -140,7 +140,8 @@ static void telnetd_parse(FAR char *line, int len)
for (entry = g_parsetab; entry->commandstr != NULL; entry++)
{
- if (strncmp(entry->commandstr, cmd, strlen(entry->commandstr)) == 0)
+ if (strncmp(entry->commandstr, cmd,
+ strlen(entry->commandstr)) == 0)
{
break;
}
@@ -161,7 +162,7 @@ int telnetd_session(int argc, char *argv[])
printf("uIP command shell -- NuttX style\n");
printf("Type '?' and return for help\n");
- for (;;)
+ for (; ; )
{
printf(SHELL_PROMPT);
fflush(stdout);
@@ -188,7 +189,7 @@ static void telnetd_netinit(void)
uint8_t mac[IFHWADDRLEN];
#endif
-/* Many embedded network interfaces must have a software assigned MAC */
+ /* Many embedded network interfaces must have a software assigned MAC */
#ifdef CONFIG_EXAMPLES_TELNETD_NOMAC
mac[0] = 0x00;
diff --git a/nshlib/nsh.h b/nshlib/nsh.h
index 3d8c87f46..494887542 100644
--- a/nshlib/nsh.h
+++ b/nshlib/nsh.h
@@ -56,9 +56,7 @@
#endif
#ifndef CONFIG_FILE_STREAM
-# undef CONFIG_NSH_TELNET
# undef CONFIG_NSH_FILE_APPS
-# undef CONFIG_NSH_TELNET
# undef CONFIG_NSH_CMDPARMS
#endif
diff --git a/system/nsh/nsh_main.c b/system/nsh/nsh_main.c
index ebf27d46c..f4f8ab91d 100644
--- a/system/nsh/nsh_main.c
+++ b/system/nsh/nsh_main.c
@@ -33,16 +33,6 @@
#include "nshlib/nshlib.h"
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* The NSH telnet console requires networking support (and TCP/IP) */
-
-#ifndef CONFIG_NET
-# undef CONFIG_NSH_TELNET
-#endif
-
/****************************************************************************
* Public Functions
****************************************************************************/
diff --git a/system/telnet/telnet_client.c b/system/telnet/telnet_client.c
index eed0675c8..4ac2622d0 100644
--- a/system/telnet/telnet_client.c
+++ b/system/telnet/telnet_client.c
@@ -115,13 +115,17 @@ static const struct telnet_telopt_s g_telopts[] =
static void send_local_input(char *buffer, int size)
{
- static char crlf[] = { '\r', '\n' };
+ static char crlf[] =
+ {
+ '\r', '\n'
+ };
+
int i;
for (i = 0; i != size; ++i)
{
- /* If we got a CR or LF, replace with CRLF NOTE that usually you'd get a
- * CR in UNIX, but in raw mode we get LF instead (not sure why).
+ /* If we got a CR or LF, replace with CRLF NOTE that usually you'd get
+ * a CR in UNIX, but in raw mode we get LF instead (not sure why).
*/
if (buffer[i] == '\r' || buffer[i] == '\n')
@@ -165,6 +169,7 @@ static void telnet_ev_send(int sock, const char *buffer, size_t size)
{
fprintf(stderr, "send() unexpectedly returned 0\n");
}
+
telnet_free(g_telnet);
exit(1);
}
@@ -199,6 +204,7 @@ static void _event_handler(struct telnet_s *telnet,
/* Request to enable remote feature (or receipt) */
case TELNET_EV_WILL:
+
/* We'll agree to turn off our echo if server wants us to stop */
if (ev->neg.telopt == TELNET_TELOPT_ECHO)
@@ -230,6 +236,7 @@ static void _event_handler(struct telnet_s *telnet,
/* Respond to TTYPE commands */
case TELNET_EV_TTYPE:
+
/* Respond with our terminal type, if requested */
if (ev->ttype.cmd == TELNET_TTYPE_SEND)
@@ -251,6 +258,7 @@ static void _event_handler(struct telnet_s *telnet,
exit(1);
default:
+
/* Ignore */
break;
@@ -262,10 +270,13 @@ static void show_usage(const char *progname, int exitcode)
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\t%s <server-IP-addr> [<port>]\n", progname);
fprintf(stderr, "Where:\n");
- fprintf(stderr, "\t<server-IP-addr> is the address of the Telnet server. Either\n");
+ fprintf(stderr,
+ "\t<server-IP-addr> is the address of the Telnet server. Either\n");
fprintf(stderr, "\t\tIPv4 form: ddd.ddd.ddd.ddd\n");
- fprintf(stderr, "\t\tIPv6 form: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx\n");
- fprintf(stderr, "\t<port> is the (optional) listening port of the Telnet server.\n");
+ fprintf(stderr,
+ "\t\tIPv6 form: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx\n");
+ fprintf(stderr,
+ "\t<port> is the (optional) listening port of the Telnet server.\n");
fprintf(stderr, "\t\tDefault: %u\n", DEFAULT_PORT);
exit(exitcode);
}
@@ -286,7 +297,9 @@ int main(int argc, FAR char *argv[])
#ifdef CONFIG_NET_IPv4
struct sockaddr_in ipv4;
#endif
- } server;
+ }
+
+ server;
union
{
#ifdef CONFIG_NET_IPv6
@@ -295,7 +308,9 @@ int main(int argc, FAR char *argv[])
#ifdef CONFIG_NET_IPv4
struct sockaddr_in ipv4;
#endif
- } local;
+ }
+
+ local;
struct pollfd pfd[2];
sa_family_t family;
uint16_t addrlen;
@@ -364,7 +379,7 @@ int main(int argc, FAR char *argv[])
/* Create server socket */
sock = socket(family, SOCK_STREAM, 0);
- if (sock < 0)
+ if (sock < 0)
{
fprintf(stderr, "socket() failed: %d\n", errno);
return 1;