summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authormazhiyuan <[email protected]>2021-12-23 15:36:36 +0800
committerBernard Xiong <[email protected]>2021-12-24 05:53:28 +0800
commita2561a41b9a8c59b32812ecb633600298394cbf6 (patch)
treec9e991e4cc4155b6a2261053f0b4f685f473f740 /components
parentbcdfa35f867c651825c4f50f1c0fc7beb143a5a2 (diff)
fix cmd: tail
Diffstat (limited to 'components')
-rw-r--r--components/finsh/msh_file.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/components/finsh/msh_file.c b/components/finsh/msh_file.c
index 9dcb820c44..2b359fb4bc 100644
--- a/components/finsh/msh_file.c
+++ b/components/finsh/msh_file.c
@@ -612,7 +612,7 @@ static int cmd_tail(int argc, char **argv)
rt_uint32_t target_line = 0;
rt_uint32_t current_line = 0;
rt_uint32_t required_lines = 0;
- rt_uint32_t after_xxx_line = 0;
+ rt_uint32_t start_line = 0;
if (argc < 2)
{
@@ -632,7 +632,7 @@ static int cmd_tail(int argc, char **argv)
}
else
{
- after_xxx_line = atoi(&argv[2][1]); /* eg: +100, to get the 100 */
+ start_line = atoi(&argv[2][1]); /* eg: +100, to get the 100 */
}
file_name = argv[3];
}
@@ -651,6 +651,10 @@ static int cmd_tail(int argc, char **argv)
while ((read(fd, &c, sizeof(char))) > 0)
{
+ if(total_lines == 0)
+ {
+ total_lines++;
+ }
if (c == '\n')
{
total_lines++;
@@ -659,11 +663,11 @@ static int cmd_tail(int argc, char **argv)
rt_kprintf("\nTotal Number of lines:%d\n", total_lines);
- if (after_xxx_line != 0)
+ if (start_line != 0)
{
- if (total_lines > after_xxx_line)
+ if (total_lines >= start_line)
{
- required_lines = total_lines - after_xxx_line;
+ required_lines = total_lines - start_line + 1;
}
else
{
@@ -686,13 +690,13 @@ static int cmd_tail(int argc, char **argv)
while ((read(fd, &c, sizeof(char))) > 0)
{
- if (c == '\n')
+ if (current_line >= target_line)
{
- current_line++;
+ rt_kprintf("%c", c);
}
- if (current_line > target_line)
+ if (c == '\n')
{
- rt_kprintf("%c", c);
+ current_line++;
}
}
rt_kprintf("\n");