apps/system/vi/vi.c: Do not print error if the file does not exist.

This commit is contained in:
anchao 2018-11-07 11:43:04 -06:00 committed by Gregory Nutt
parent 4804d74c61
commit 42ce384259

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* apps/system/vi/vi.c * apps/system/vi/vi.c
* *
* Copyright (C) 2014 Gregory Nutt. All rights reserved. * Copyright (C) 2014, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -142,6 +142,11 @@
#define CMD_FILE_MASK (CMD_READ | CMD_WRITE) #define CMD_FILE_MASK (CMD_READ | CMD_WRITE)
#define USES_FILE(a) (((uint8_t)(a) & CMD_FILE_MASK) != 0) #define USES_FILE(a) (((uint8_t)(a) & CMD_FILE_MASK) != 0)
/* Output */
#define vi_error(vi, fmt, ...) vi_printf(vi, "ERROR: ", fmt, ##__VA_ARGS__)
#define vi_message(vi, fmt, ...) vi_printf(vi, NULL, fmt, ##__VA_ARGS__)
/* Debug */ /* Debug */
#ifndef CONFIG_SYSTEM_VI_DEBUGLEVEL #ifndef CONFIG_SYSTEM_VI_DEBUGLEVEL
@ -320,9 +325,10 @@ static void vi_clrtoeol(FAR struct vi_s *vi);
static void vi_clrscreen(FAR struct vi_s *vi); static void vi_clrscreen(FAR struct vi_s *vi);
#endif #endif
/* Error display */ /* Final Line display */
static void vi_error(FAR struct vi_s *vi, FAR const char *fmt, ...); static void vi_printf(FAR struct vi_s *vi, FAR const char *prefix,
FAR const char *fmt, ...);
/* Line positioning */ /* Line positioning */
@ -807,14 +813,15 @@ static void vi_scrolldown(FAR struct vi_s *vi, uint16_t nlines)
} }
/**************************************************************************** /****************************************************************************
* Name: vi_error * Name: vi_printf
* *
* Description: * Description:
* Show a highlighted error message at the final line of the display. * Show a highlighted message at the final line of the display.
* *
****************************************************************************/ ****************************************************************************/
static void vi_error(FAR struct vi_s *vi, FAR const char *fmt, ...) static void vi_printf(FAR struct vi_s *vi, FAR const char *prefix,
FAR const char *fmt, ...)
{ {
struct vi_pos_s cursor; struct vi_pos_s cursor;
va_list ap; va_list ap;
@ -830,9 +837,9 @@ static void vi_error(FAR struct vi_s *vi, FAR const char *fmt, ...)
vi_setcursor(vi, vi->display.row - 1, 0); vi_setcursor(vi, vi->display.row - 1, 0);
vi_reverseon(vi); vi_reverseon(vi);
/* Expand the error message in the scratch buffer */ /* Expand the prefix message in the scratch buffer */
len = snprintf(vi->scratch, SCRATCH_BUFSIZE, "ERROR: "); len = prefix ? snprintf(vi->scratch, SCRATCH_BUFSIZE, prefix) : 0;
va_start(ap, fmt); va_start(ap, fmt);
len += vsnprintf(vi->scratch + len, SCRATCH_BUFSIZE - len, fmt, ap); len += vsnprintf(vi->scratch + len, SCRATCH_BUFSIZE - len, fmt, ap);
@ -1144,7 +1151,7 @@ static bool vi_insertfile(FAR struct vi_s *vi, off_t pos,
result = stat(filename, &buf); result = stat(filename, &buf);
if (result < 0) if (result < 0)
{ {
vi_error(vi, g_fmtcmdfail, "stat", errno); vi_message(vi, "\"%s\" [New File]\n", filename);
return false; return false;
} }