cat accepts multiple files
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@836 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
2d4f0c6f53
commit
7ccda13225
@ -416,4 +416,5 @@
|
|||||||
* NSH now supports if-then[-else]-fi construct
|
* NSH now supports if-then[-else]-fi construct
|
||||||
* NSH now supports comments beginning with '#'
|
* NSH now supports comments beginning with '#'
|
||||||
* NSH now supports commands to inspect and modify memory
|
* NSH now supports commands to inspect and modify memory
|
||||||
|
* NSH cat command now supports multiple files on command line
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<tr align="center" bgcolor="#e4e4e4">
|
<tr align="center" bgcolor="#e4e4e4">
|
||||||
<td>
|
<td>
|
||||||
<h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1>
|
<h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1>
|
||||||
<p>Last Updated: August 19, 2008</p>
|
<p>Last Updated: August 21, 2008</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@ -1050,6 +1050,7 @@ nuttx-0.3.13 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
|||||||
* NSH now supports if-then[-else]-fi construct
|
* NSH now supports if-then[-else]-fi construct
|
||||||
* NSH now supports comments beginning with '#'
|
* NSH now supports comments beginning with '#'
|
||||||
* NSH now supports commands to inspect and modify memory
|
* NSH now supports commands to inspect and modify memory
|
||||||
|
* NSH cat command now supports multiple files on command line
|
||||||
|
|
||||||
pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
|
||||||
|
@ -375,72 +375,82 @@ static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, struct
|
|||||||
int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||||
{
|
{
|
||||||
char buffer[IOBUFFERSIZE];
|
char buffer[IOBUFFERSIZE];
|
||||||
int ret = ERROR;
|
int fd;
|
||||||
|
int i;
|
||||||
|
int ret = OK;
|
||||||
|
|
||||||
/* Open the file for reading */
|
/* Loop for each file name on the command line */
|
||||||
|
|
||||||
int fd = open(argv[1], O_RDONLY);
|
for (i = 1; i < argc && ret == OK; i++)
|
||||||
if (fd < 0)
|
|
||||||
{
|
{
|
||||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
|
/* Open the file for reading */
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* And just dump it byte for byte into stdout */
|
fd = open(argv[1], O_RDONLY);
|
||||||
|
if (fd < 0)
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
int nbytesread = read(fd, buffer, IOBUFFERSIZE);
|
|
||||||
|
|
||||||
/* Check for read errors */
|
|
||||||
|
|
||||||
if (nbytesread < 0)
|
|
||||||
{
|
{
|
||||||
/* EINTR is not an error */
|
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
|
||||||
|
ret = ERROR;
|
||||||
if (errno != EINTR)
|
|
||||||
{
|
|
||||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
/* Check for data successfully read */
|
|
||||||
|
|
||||||
else if (nbytesread > 0)
|
|
||||||
{
|
{
|
||||||
int nbyteswritten = 0;
|
/* And just dump it byte for byte into stdout */
|
||||||
|
|
||||||
while (nbyteswritten < nbytesread)
|
for (;;)
|
||||||
{
|
{
|
||||||
int n = write(1, buffer, nbytesread);
|
int nbytesread = read(fd, buffer, IOBUFFERSIZE);
|
||||||
if (n < 0)
|
|
||||||
|
/* Check for read errors */
|
||||||
|
|
||||||
|
if (nbytesread < 0)
|
||||||
{
|
{
|
||||||
/* EINTR is not an error */
|
/* EINTR is not an error */
|
||||||
|
|
||||||
if (errno != EINTR)
|
if (errno != EINTR)
|
||||||
{
|
{
|
||||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "write", NSH_ERRNO);
|
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
|
||||||
|
ret = ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check for data successfully read */
|
||||||
|
|
||||||
|
else if (nbytesread > 0)
|
||||||
|
{
|
||||||
|
int nbyteswritten = 0;
|
||||||
|
|
||||||
|
while (nbyteswritten < nbytesread)
|
||||||
|
{
|
||||||
|
int n = write(1, buffer, nbytesread);
|
||||||
|
if (n < 0)
|
||||||
|
{
|
||||||
|
/* EINTR is not an error */
|
||||||
|
|
||||||
|
if (errno != EINTR)
|
||||||
|
{
|
||||||
|
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "write", NSH_ERRNO);
|
||||||
|
ret = ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nbyteswritten += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, it is the end of file */
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nbyteswritten += n;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Otherwise, it is the end of file */
|
(void)close(fd);
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = OK;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)close(fd);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -90,7 +90,7 @@ static const char g_failure[] = "1";
|
|||||||
static const struct cmdmap_s g_cmdmap[] =
|
static const struct cmdmap_s g_cmdmap[] =
|
||||||
{
|
{
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
{ "cat", cmd_cat, 2, 2, "<path>" },
|
{ "cat", cmd_cat, 2, NSH_MAX_ARGUMENTS, "<path> [<path> [<path> ...]]" },
|
||||||
{ "cp", cmd_cp, 3, 3, "<source-path> <dest-path>" },
|
{ "cp", cmd_cp, 3, 3, "<source-path> <dest-path>" },
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONFIG_DISABLE_ENVIRON
|
#ifndef CONFIG_DISABLE_ENVIRON
|
||||||
@ -659,7 +659,8 @@ static inline int nsh_nice(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, FAR ch
|
|||||||
{
|
{
|
||||||
char *endptr;
|
char *endptr;
|
||||||
vtbl->np.np_nice = (int)strtol(val, &endptr, 0);
|
vtbl->np.np_nice = (int)strtol(val, &endptr, 0);
|
||||||
if (vtbl->np.np_nice > 19 || vtbl->np.np_nice < -20 || endptr == val || *endptr != '\0')
|
if (vtbl->np.np_nice > 19 || vtbl->np.np_nice < -20 ||
|
||||||
|
endptr == val || *endptr != '\0')
|
||||||
{
|
{
|
||||||
nsh_output(vtbl, g_fmtarginvalid, "nice");
|
nsh_output(vtbl, g_fmtarginvalid, "nice");
|
||||||
return ERROR;
|
return ERROR;
|
||||||
|
Loading…
Reference in New Issue
Block a user