mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-18 08:52:01 +08:00
Fixing coding style issues for rest of nshlib directory - except for the false +ve nsh_timcmds.c
This commit is contained in:

committed by
Alin Jerpelea

parent
0f4ad7dc5f
commit
3b884cfb87
@@ -60,36 +60,36 @@
|
|||||||
|
|
||||||
static int slash_notation(FAR char *arg)
|
static int slash_notation(FAR char *arg)
|
||||||
{
|
{
|
||||||
FAR char *sptr;
|
FAR char *sptr;
|
||||||
FAR char *ptr;
|
FAR char *ptr;
|
||||||
|
|
||||||
/* If an address contains a /, then the netmask is imply by the following
|
/* If an address contains a /, then the netmask is imply by the following
|
||||||
* numeric value.
|
* numeric value.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sptr = strchr(arg, '/');
|
sptr = strchr(arg, '/');
|
||||||
if (sptr != NULL)
|
if (sptr != NULL)
|
||||||
{
|
{
|
||||||
/* Make sure that everything following the slash is a decimal digit. */
|
/* Make sure that everything following the slash is a decimal digit. */
|
||||||
|
|
||||||
ptr = sptr + 1;
|
ptr = sptr + 1;
|
||||||
while (isdigit(*ptr))
|
while (isdigit(*ptr))
|
||||||
{
|
{
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* There should be nothing be digits after the slash and up to the
|
/* There should be nothing be digits after the slash and up to the
|
||||||
* NULL terminator.
|
* NULL terminator.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (*ptr == '\0')
|
if (*ptr == '\0')
|
||||||
{
|
{
|
||||||
*sptr++ = '\0';
|
*sptr++ = '\0';
|
||||||
return atoi(sptr);
|
return atoi(sptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -191,30 +191,30 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv4
|
#ifdef CONFIG_NET_IPv4
|
||||||
if (family == PF_INET)
|
if (family == PF_INET)
|
||||||
{
|
{
|
||||||
ret = netlib_set_dripv4addr(argv[3], &inaddr.ipv4);
|
ret = netlib_set_dripv4addr(argv[3], &inaddr.ipv4);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
nsh_error(vtbl, g_fmtcmdfailed, argv[0]);
|
nsh_error(vtbl, g_fmtcmdfailed, argv[0]);
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
if (family == PF_INET6)
|
if (family == PF_INET6)
|
||||||
{
|
{
|
||||||
ret = netlib_set_dripv6addr(argv[3], &inaddr.ipv6);
|
ret = netlib_set_dripv6addr(argv[3], &inaddr.ipv6);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
nsh_error(vtbl, g_fmtcmdfailed, argv[0]);
|
nsh_error(vtbl, g_fmtcmdfailed, argv[0]);
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if slash notation is used with the target address */
|
/* Check if slash notation is used with the target address */
|
||||||
@@ -291,7 +291,7 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Convert the netmask IP address string into its binary form */
|
/* Convert the netmask IP address string into its binary form */
|
||||||
|
|
||||||
if (shift >= 0)
|
if (shift >= 0)
|
||||||
{
|
{
|
||||||
@@ -355,6 +355,7 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rtrndx = 2;
|
rtrndx = 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -369,7 +370,7 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rtrndx = 3;
|
rtrndx = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Format the netmask sockaddr instance */
|
/* Format the netmask sockaddr instance */
|
||||||
|
|
||||||
@@ -396,7 +397,7 @@ int cmd_addroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Convert the router IP address string into its binary form */
|
/* Convert the router IP address string into its binary form */
|
||||||
|
|
||||||
ret = inet_pton(family, argv[rtrndx], &inaddr);
|
ret = inet_pton(family, argv[rtrndx], &inaddr);
|
||||||
if (ret != 1)
|
if (ret != 1)
|
||||||
@@ -571,7 +572,7 @@ int cmd_delroute(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Convert the netmask IP address string into its binary form */
|
/* Convert the netmask IP address string into its binary form */
|
||||||
|
|
||||||
if (shift >= 0)
|
if (shift >= 0)
|
||||||
{
|
{
|
||||||
|
@@ -341,7 +341,8 @@ int cmd_reboot(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
|
#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
|
||||||
int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||||
{
|
{
|
||||||
int fd, cmd;
|
int fd;
|
||||||
|
int cmd;
|
||||||
|
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
{
|
{
|
||||||
|
@@ -70,7 +70,8 @@
|
|||||||
* Name: nsh_telnetecho
|
* Name: nsh_telnetecho
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void nsh_telnetecho(FAR struct console_stdio_s *pstate, uint8_t is_use)
|
static void nsh_telnetecho(FAR struct console_stdio_s *pstate,
|
||||||
|
uint8_t is_use)
|
||||||
{
|
{
|
||||||
uint8_t optbuf[4];
|
uint8_t optbuf[4];
|
||||||
optbuf[0] = TELNET_IAC;
|
optbuf[0] = TELNET_IAC;
|
||||||
@@ -193,7 +194,8 @@ int nsh_telnetlogin(FAR struct console_stdio_s *pstate)
|
|||||||
fflush(pstate->cn_outstream);
|
fflush(pstate->cn_outstream);
|
||||||
|
|
||||||
username[0] = '\0';
|
username[0] = '\0';
|
||||||
if (fgets(pstate->cn_line, CONFIG_NSH_LINELEN, INSTREAM(pstate)) != NULL)
|
if (fgets(pstate->cn_line, CONFIG_NSH_LINELEN,
|
||||||
|
INSTREAM(pstate)) != NULL)
|
||||||
{
|
{
|
||||||
/* Parse out the username */
|
/* Parse out the username */
|
||||||
|
|
||||||
@@ -207,7 +209,8 @@ int nsh_telnetlogin(FAR struct console_stdio_s *pstate)
|
|||||||
nsh_telnetecho(pstate, TELNET_NOTUSE_ECHO);
|
nsh_telnetecho(pstate, TELNET_NOTUSE_ECHO);
|
||||||
|
|
||||||
password[0] = '\0';
|
password[0] = '\0';
|
||||||
if (fgets(pstate->cn_line, CONFIG_NSH_LINELEN, INSTREAM(pstate)) != NULL)
|
if (fgets(pstate->cn_line, CONFIG_NSH_LINELEN,
|
||||||
|
INSTREAM(pstate)) != NULL)
|
||||||
{
|
{
|
||||||
/* Parse out the password */
|
/* Parse out the password */
|
||||||
|
|
||||||
@@ -218,7 +221,8 @@ int nsh_telnetlogin(FAR struct console_stdio_s *pstate)
|
|||||||
#if defined(CONFIG_NSH_LOGIN_PASSWD)
|
#if defined(CONFIG_NSH_LOGIN_PASSWD)
|
||||||
if (PASSWORD_VERIFY_MATCH(passwd_verify(username, password)))
|
if (PASSWORD_VERIFY_MATCH(passwd_verify(username, password)))
|
||||||
#elif defined(CONFIG_NSH_LOGIN_PLATFORM)
|
#elif defined(CONFIG_NSH_LOGIN_PLATFORM)
|
||||||
if (PASSWORD_VERIFY_MATCH(platform_user_verify(username, password)))
|
if (PASSWORD_VERIFY_MATCH(platform_user_verify(username,
|
||||||
|
password)))
|
||||||
#elif defined(CONFIG_NSH_LOGIN_FIXED)
|
#elif defined(CONFIG_NSH_LOGIN_FIXED)
|
||||||
if (strcmp(password, CONFIG_NSH_LOGIN_PASSWORD) == 0 &&
|
if (strcmp(password, CONFIG_NSH_LOGIN_PASSWORD) == 0 &&
|
||||||
strcmp(username, CONFIG_NSH_LOGIN_USERNAME) == 0)
|
strcmp(username, CONFIG_NSH_LOGIN_USERNAME) == 0)
|
||||||
|
@@ -219,7 +219,7 @@ static inline int unaryexpression(FAR struct nsh_vtbl_s *vtbl, char **argv)
|
|||||||
fullpath = nsh_getfullpath(vtbl, argv[1]);
|
fullpath = nsh_getfullpath(vtbl, argv[1]);
|
||||||
if (!fullpath)
|
if (!fullpath)
|
||||||
{
|
{
|
||||||
return TEST_FALSE;
|
return TEST_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = stat(fullpath, &buf);
|
ret = stat(fullpath, &buf);
|
||||||
@@ -227,11 +227,11 @@ static inline int unaryexpression(FAR struct nsh_vtbl_s *vtbl, char **argv)
|
|||||||
|
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
/* The file does not exist (or another error occurred) -- return
|
/* The file does not exist (or another error occurred) -- return
|
||||||
* FALSE.
|
* FALSE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return TEST_FALSE;
|
return TEST_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -b FILE */
|
/* -b FILE */
|
||||||
@@ -285,7 +285,7 @@ static inline int unaryexpression(FAR struct nsh_vtbl_s *vtbl, char **argv)
|
|||||||
{
|
{
|
||||||
/* Return true if the file is readable */
|
/* Return true if the file is readable */
|
||||||
|
|
||||||
return (buf.st_mode & (S_IRUSR|S_IRGRP|S_IROTH)) != 0 ?
|
return (buf.st_mode & (S_IRUSR | S_IRGRP | S_IROTH)) != 0 ?
|
||||||
TEST_TRUE : TEST_FALSE;
|
TEST_TRUE : TEST_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,7 +304,7 @@ static inline int unaryexpression(FAR struct nsh_vtbl_s *vtbl, char **argv)
|
|||||||
{
|
{
|
||||||
/* Return true if the file is write-able */
|
/* Return true if the file is write-able */
|
||||||
|
|
||||||
return (buf.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) != 0 ?
|
return (buf.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0 ?
|
||||||
TEST_TRUE : TEST_FALSE;
|
TEST_TRUE : TEST_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,7 +331,7 @@ static int expression(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
goto errout_syntax;
|
goto errout_syntax;
|
||||||
}
|
}
|
||||||
|
|
||||||
return expression(vtbl, argc-1, &argv[1]) == TEST_TRUE ?
|
return expression(vtbl, argc - 1, &argv[1]) == TEST_TRUE ?
|
||||||
TEST_FALSE : TEST_TRUE;
|
TEST_FALSE : TEST_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,37 +374,37 @@ static int expression(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|||||||
{
|
{
|
||||||
/* EXPRESSION -a EXPRESSION */
|
/* EXPRESSION -a EXPRESSION */
|
||||||
|
|
||||||
if (strcmp(argv[i], "-a") == 0)
|
if (strcmp(argv[i], "-a") == 0)
|
||||||
{
|
{
|
||||||
if (value != TEST_TRUE)
|
if (value != TEST_TRUE)
|
||||||
{
|
{
|
||||||
return TEST_FALSE;
|
return TEST_FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
return expression(vtbl, argc-i, &argv[i]);
|
return expression(vtbl, argc - i, &argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EXPRESSION -o EXPRESSION */
|
/* EXPRESSION -o EXPRESSION */
|
||||||
|
|
||||||
else if (strcmp(argv[i], "-o") == 0)
|
else if (strcmp(argv[i], "-o") == 0)
|
||||||
{
|
{
|
||||||
if (value == TEST_TRUE)
|
if (value == TEST_TRUE)
|
||||||
{
|
{
|
||||||
return TEST_TRUE;
|
return TEST_TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
return expression(vtbl, argc-i, &argv[i]);
|
return expression(vtbl, argc - i, &argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
goto errout_syntax;
|
goto errout_syntax;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
@@ -424,7 +424,7 @@ errout_syntax:
|
|||||||
|
|
||||||
int cmd_test(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
int cmd_test(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||||
{
|
{
|
||||||
return expression(vtbl, argc-1, &argv[1]);
|
return expression(vtbl, argc - 1, &argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@@ -204,7 +204,7 @@ int nsh_removevar(FAR struct console_stdio_s *pstate, FAR char *pair)
|
|||||||
* Name: nsh_getvar
|
* Name: nsh_getvar
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
FAR char *nsh_getvar(FAR struct nsh_vtbl_s *vtbl,FAR const char *name)
|
FAR char *nsh_getvar(FAR struct nsh_vtbl_s *vtbl, FAR const char *name)
|
||||||
{
|
{
|
||||||
FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl;
|
FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl;
|
||||||
FAR char *pair;
|
FAR char *pair;
|
||||||
@@ -258,8 +258,8 @@ int nsh_setvar(FAR struct nsh_vtbl_s *vtbl, FAR const char *name,
|
|||||||
nsh_removevar(pstate, pair);
|
nsh_removevar(pstate, pair);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the size of the new name=value string. The +2 is for the '=' and for
|
/* Get the size of the new name=value string. The +2 is for the '=' and
|
||||||
* null terminator
|
* for null terminator
|
||||||
*/
|
*/
|
||||||
|
|
||||||
varlen = strlen(name) + strlen(value) + 2;
|
varlen = strlen(name) + strlen(value) + 2;
|
||||||
|
Reference in New Issue
Block a user