2012-02-02 20:42:55 +01:00
|
|
|
/****************************************************************************
|
2013-09-30 19:34:04 +02:00
|
|
|
* apps/nshlib/nsh_console.c
|
2012-02-02 20:42:55 +01:00
|
|
|
*
|
2015-09-08 01:09:11 +02:00
|
|
|
* Copyright (C) 2007-2009, 2011-2013, 2015 Gregory Nutt. All rights reserved.
|
2012-02-02 20:42:55 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-01-24 16:49:17 +01:00
|
|
|
#include <stdarg.h>
|
2012-02-02 20:42:55 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include "nsh.h"
|
|
|
|
#include "nsh_console.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-30 19:34:04 +02:00
|
|
|
#if CONFIG_NFILE_STREAMS > 0
|
2012-02-02 20:42:55 +01:00
|
|
|
struct serialsave_s
|
|
|
|
{
|
|
|
|
int cn_outfd; /* Re-directed output file descriptor */
|
|
|
|
FILE *cn_outstream; /* Re-directed output stream */
|
|
|
|
};
|
2013-09-30 19:34:04 +02:00
|
|
|
#endif
|
2012-02-02 20:42:55 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLEBG
|
|
|
|
static FAR struct nsh_vtbl_s *nsh_consoleclone(FAR struct nsh_vtbl_s *vtbl);
|
|
|
|
#endif
|
|
|
|
static void nsh_consolerelease(FAR struct nsh_vtbl_s *vtbl);
|
2012-10-12 18:59:17 +02:00
|
|
|
static ssize_t nsh_consolewrite(FAR struct nsh_vtbl_s *vtbl,
|
|
|
|
FAR const void *buffer, size_t nbytes);
|
|
|
|
static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl,
|
2016-01-17 14:53:52 +01:00
|
|
|
FAR const char *fmt, ...);
|
2012-02-02 20:42:55 +01:00
|
|
|
static FAR char *nsh_consolelinebuffer(FAR struct nsh_vtbl_s *vtbl);
|
2013-09-30 19:34:04 +02:00
|
|
|
|
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
2012-10-12 18:59:17 +02:00
|
|
|
static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd,
|
|
|
|
FAR uint8_t *save);
|
|
|
|
static void nsh_consoleundirect(FAR struct nsh_vtbl_s *vtbl,
|
|
|
|
FAR uint8_t *save);
|
2013-09-30 19:34:04 +02:00
|
|
|
#endif
|
|
|
|
|
2012-10-12 18:59:17 +02:00
|
|
|
static void nsh_consoleexit(FAR struct nsh_vtbl_s *vtbl, int exitstatus)
|
|
|
|
noreturn_function;
|
2012-02-02 20:42:55 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_openifnotopen
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-30 19:34:04 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
2012-02-02 20:42:55 +01:00
|
|
|
static int nsh_openifnotopen(struct console_stdio_s *pstate)
|
|
|
|
{
|
|
|
|
/* The stream is open in a lazy fashion. This is done because the file
|
|
|
|
* descriptor may be opened on a different task than the stream.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!pstate->cn_outstream)
|
|
|
|
{
|
|
|
|
pstate->cn_outstream = fdopen(pstate->cn_outfd, "w");
|
|
|
|
if (!pstate->cn_outstream)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
}
|
2013-09-30 19:34:04 +02:00
|
|
|
|
2012-02-02 20:42:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2013-09-30 19:34:04 +02:00
|
|
|
#endif
|
2012-02-02 20:42:55 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_closeifnotclosed
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Close the output stream if it is not the standard output stream.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-30 19:34:04 +02:00
|
|
|
#if CONFIG_NFILE_STREAMS > 0
|
2012-02-02 20:42:55 +01:00
|
|
|
static void nsh_closeifnotclosed(struct console_stdio_s *pstate)
|
|
|
|
{
|
|
|
|
if (pstate->cn_outstream == OUTSTREAM(pstate))
|
|
|
|
{
|
|
|
|
fflush(OUTSTREAM(pstate));
|
|
|
|
pstate->cn_outfd = OUTFD(pstate);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pstate->cn_outstream)
|
|
|
|
{
|
|
|
|
fflush(pstate->cn_outstream);
|
|
|
|
fclose(pstate->cn_outstream);
|
|
|
|
}
|
|
|
|
else if (pstate->cn_outfd >= 0 && pstate->cn_outfd != OUTFD(pstate))
|
|
|
|
{
|
|
|
|
close(pstate->cn_outfd);
|
|
|
|
}
|
|
|
|
|
|
|
|
pstate->cn_outfd = -1;
|
|
|
|
pstate->cn_outstream = NULL;
|
|
|
|
}
|
|
|
|
}
|
2013-09-30 19:34:04 +02:00
|
|
|
#endif
|
2012-02-02 20:42:55 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_consolewrite
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* write a buffer to the remote shell window.
|
|
|
|
*
|
|
|
|
* Currently only used by cat.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-01-17 14:41:51 +01:00
|
|
|
static ssize_t nsh_consolewrite(FAR struct nsh_vtbl_s *vtbl,
|
|
|
|
FAR const void *buffer, size_t nbytes)
|
2012-02-02 20:42:55 +01:00
|
|
|
{
|
2013-10-01 20:10:09 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
2012-02-02 20:42:55 +01:00
|
|
|
FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
/* The stream is open in a lazy fashion. This is done because the file
|
|
|
|
* descriptor may be opened on a different task than the stream. The
|
|
|
|
* actual open will then occur with the first output from the new task.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (nsh_openifnotopen(pstate) != 0)
|
|
|
|
{
|
|
|
|
return (ssize_t)ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the data to the output stream */
|
|
|
|
|
|
|
|
ret = fwrite(buffer, 1, nbytes, pstate->cn_outstream);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-16 20:12:34 +02:00
|
|
|
_err("ERROR: [%d] Failed to send buffer: %d\n",
|
2016-06-14 22:18:07 +02:00
|
|
|
pstate->cn_outfd, errno);
|
2012-02-02 20:42:55 +01:00
|
|
|
}
|
|
|
|
return ret;
|
2013-09-30 19:34:04 +02:00
|
|
|
#else
|
2013-10-01 19:52:35 +02:00
|
|
|
/* REVISIT: buffer may not be NUL-terminated */
|
|
|
|
|
2013-09-30 19:34:04 +02:00
|
|
|
printf("%s", buffer);
|
|
|
|
return nbytes;
|
|
|
|
#endif
|
2012-02-02 20:42:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_consoleoutput
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Print a string to the currently selected stream.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-01-24 16:49:17 +01:00
|
|
|
static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl,
|
2016-01-17 14:53:52 +01:00
|
|
|
FAR const char *fmt, ...)
|
2012-02-02 20:42:55 +01:00
|
|
|
{
|
2013-09-30 19:34:04 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
2012-02-02 20:42:55 +01:00
|
|
|
FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl;
|
|
|
|
va_list ap;
|
2013-09-30 19:34:04 +02:00
|
|
|
int ret;
|
2012-02-02 20:42:55 +01:00
|
|
|
|
|
|
|
/* The stream is open in a lazy fashion. This is done because the file
|
|
|
|
* descriptor may be opened on a different task than the stream. The
|
|
|
|
* actual open will then occur with the first output from the new task.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (nsh_openifnotopen(pstate) != 0)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
2013-09-30 19:34:04 +02:00
|
|
|
|
2012-02-02 20:42:55 +01:00
|
|
|
va_start(ap, fmt);
|
|
|
|
ret = vfprintf(pstate->cn_outstream, fmt, ap);
|
|
|
|
va_end(ap);
|
2013-09-30 19:34:04 +02:00
|
|
|
|
2012-02-02 20:42:55 +01:00
|
|
|
return ret;
|
2013-09-30 19:34:04 +02:00
|
|
|
#else
|
2013-10-01 19:52:35 +02:00
|
|
|
va_list ap;
|
|
|
|
char *str;
|
|
|
|
|
2015-09-08 01:09:11 +02:00
|
|
|
/* Use vasprintf() to allocate a buffer and fill it with the formatted
|
2013-10-01 19:52:35 +02:00
|
|
|
* data
|
|
|
|
*/
|
2013-09-30 19:34:04 +02:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2013-10-01 19:52:35 +02:00
|
|
|
str = NULL;
|
2015-09-08 01:09:11 +02:00
|
|
|
(void)vasprintf(&str, fmt, ap);
|
2013-10-01 19:52:35 +02:00
|
|
|
|
|
|
|
/* Was a string allocated? */
|
2013-09-30 19:34:04 +02:00
|
|
|
|
2013-10-01 19:52:35 +02:00
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
/* Yes.. Print then free the allocated string */
|
|
|
|
|
|
|
|
printf("%s", str);
|
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
return 0;
|
2013-09-30 19:34:04 +02:00
|
|
|
#endif
|
2012-02-02 20:42:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_consolelinebuffer
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return a reference to the current line buffer
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static FAR char *nsh_consolelinebuffer(FAR struct nsh_vtbl_s *vtbl)
|
|
|
|
{
|
|
|
|
FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl;
|
|
|
|
return pstate->cn_line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_consoleclone
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Make an independent copy of the vtbl
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLEBG
|
|
|
|
static FAR struct nsh_vtbl_s *nsh_consoleclone(FAR struct nsh_vtbl_s *vtbl)
|
|
|
|
{
|
|
|
|
FAR struct console_stdio_s *pclone = nsh_newconsole();
|
|
|
|
return &pclone->cn_vtbl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_consolerelease
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Release the cloned instance
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void nsh_consolerelease(FAR struct nsh_vtbl_s *vtbl)
|
|
|
|
{
|
|
|
|
FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl;
|
|
|
|
|
2013-09-30 19:34:04 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
2012-02-02 20:42:55 +01:00
|
|
|
/* Close the output stream */
|
|
|
|
|
|
|
|
nsh_closeifnotclosed(pstate);
|
|
|
|
|
|
|
|
/* Close the console stream */
|
|
|
|
|
2014-05-05 16:52:02 +02:00
|
|
|
#ifdef CONFIG_NSH_ALTCONDEV
|
2012-02-02 20:42:55 +01:00
|
|
|
(void)fclose(pstate->cn_constream);
|
2013-09-30 19:34:04 +02:00
|
|
|
#endif
|
2012-02-02 20:42:55 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Then release the vtable container */
|
|
|
|
|
|
|
|
free(pstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_consoleredirect
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set up for redirected output. This function is called from nsh_parse()
|
|
|
|
* in two different contexts:
|
|
|
|
*
|
|
|
|
* 1) Redirected background commands of the form: command > xyz.text &
|
|
|
|
*
|
|
|
|
* In this case:
|
|
|
|
* - vtbl: A newly allocated and initialized instance created by
|
|
|
|
* nsh_consoleclone,
|
|
|
|
* - fd:- The file descriptor of the redirected output
|
|
|
|
* - save: NULL
|
|
|
|
*
|
|
|
|
* nsh_consolerelease() will perform the clean-up when the clone is
|
|
|
|
* destroyed.
|
2013-09-30 19:34:04 +02:00
|
|
|
*
|
2012-02-02 20:42:55 +01:00
|
|
|
* 2) Redirected foreground commands of the form: command > xyz.txt
|
|
|
|
*
|
|
|
|
* In this case:
|
|
|
|
* - vtbl: The current state structure,
|
|
|
|
* - fd: The file descriptor of the redirected output
|
|
|
|
* - save: Where to save the re-directed registers.
|
|
|
|
*
|
|
|
|
* nsh_consoleundirect() will perform the clean-up after the redirected
|
|
|
|
* command completes.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-30 19:34:04 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
2012-02-02 20:42:55 +01:00
|
|
|
static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd, FAR uint8_t *save)
|
|
|
|
{
|
2013-09-30 19:34:04 +02:00
|
|
|
FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl;
|
2012-02-02 20:42:55 +01:00
|
|
|
FAR struct serialsave_s *ssave = (FAR struct serialsave_s *)save;
|
|
|
|
|
|
|
|
/* Case 1: Redirected foreground commands */
|
|
|
|
|
|
|
|
if (ssave)
|
|
|
|
{
|
|
|
|
/* pstate->cn_outstream and cn_outfd refer refer to the
|
|
|
|
* currently opened output stream. If the output stream is open, flush
|
|
|
|
* any pending output.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (pstate->cn_outstream)
|
|
|
|
{
|
2013-09-30 19:34:04 +02:00
|
|
|
fflush(pstate->cn_outstream);
|
2012-02-02 20:42:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the current fd and stream values. These will be restored
|
|
|
|
* when nsh_consoleundirect() is called.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ssave->cn_outfd = pstate->cn_outfd;
|
|
|
|
ssave->cn_outstream = pstate->cn_outstream;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* nsh_consoleclone() set pstate->cn_outfd and cn_outstream to refer
|
|
|
|
* to standard out. We just want to leave these alone and overwrite
|
|
|
|
* them with the fd for the re-directed stream.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/* In either case, set the fd of the new, re-directed output and nullify
|
|
|
|
* the output stream (it will be fdopen'ed if it is used).
|
|
|
|
*/
|
|
|
|
|
|
|
|
pstate->cn_outfd = fd;
|
|
|
|
pstate->cn_outstream = NULL;
|
|
|
|
}
|
2013-09-30 19:34:04 +02:00
|
|
|
#endif
|
2012-02-02 20:42:55 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_consoleundirect
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set up for redirected output
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-30 19:34:04 +02:00
|
|
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
2012-02-02 20:42:55 +01:00
|
|
|
static void nsh_consoleundirect(FAR struct nsh_vtbl_s *vtbl, FAR uint8_t *save)
|
|
|
|
{
|
|
|
|
FAR struct console_stdio_s *pstate = (FAR struct console_stdio_s *)vtbl;
|
|
|
|
FAR struct serialsave_s *ssave = (FAR struct serialsave_s *)save;
|
|
|
|
|
|
|
|
nsh_closeifnotclosed(pstate);
|
|
|
|
pstate->cn_outfd = ssave->cn_outfd;
|
|
|
|
pstate->cn_outstream = ssave->cn_outstream;
|
|
|
|
}
|
2013-09-30 19:34:04 +02:00
|
|
|
#endif
|
2012-02-02 20:42:55 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_consoleexit
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Exit the shell task
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void nsh_consoleexit(FAR struct nsh_vtbl_s *vtbl, int exitstatus)
|
|
|
|
{
|
|
|
|
/* Destroy ourself then exit with the provided status */
|
|
|
|
|
|
|
|
nsh_consolerelease(vtbl);
|
|
|
|
exit(exitstatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_newconsole
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR struct console_stdio_s *nsh_newconsole(void)
|
|
|
|
{
|
2016-01-17 14:41:51 +01:00
|
|
|
FAR struct console_stdio_s *pstate =
|
|
|
|
(FAR struct console_stdio_s *)zalloc(sizeof(struct console_stdio_s));
|
|
|
|
|
2012-02-02 20:42:55 +01:00
|
|
|
if (pstate)
|
|
|
|
{
|
|
|
|
/* Initialize the call table */
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLEBG
|
|
|
|
pstate->cn_vtbl.clone = nsh_consoleclone;
|
|
|
|
pstate->cn_vtbl.release = nsh_consolerelease;
|
|
|
|
#endif
|
|
|
|
pstate->cn_vtbl.write = nsh_consolewrite;
|
|
|
|
pstate->cn_vtbl.output = nsh_consoleoutput;
|
|
|
|
pstate->cn_vtbl.linebuffer = nsh_consolelinebuffer;
|
2013-09-30 19:34:04 +02:00
|
|
|
pstate->cn_vtbl.exit = nsh_consoleexit;
|
|
|
|
|
|
|
|
#if CONFIG_NFILE_STREAMS > 0
|
2012-02-02 20:42:55 +01:00
|
|
|
pstate->cn_vtbl.redirect = nsh_consoleredirect;
|
|
|
|
pstate->cn_vtbl.undirect = nsh_consoleundirect;
|
|
|
|
|
|
|
|
/* (Re-) open the console input device */
|
|
|
|
|
2014-05-05 16:52:02 +02:00
|
|
|
#ifdef CONFIG_NSH_ALTCONDEV
|
2012-02-02 20:42:55 +01:00
|
|
|
pstate->cn_confd = open(CONFIG_NSH_CONDEV, O_RDWR);
|
|
|
|
if (pstate->cn_confd < 0)
|
|
|
|
{
|
|
|
|
free(pstate);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a standard C stream on the console device */
|
|
|
|
|
|
|
|
pstate->cn_constream = fdopen(pstate->cn_confd, "r+");
|
|
|
|
if (!pstate->cn_constream)
|
|
|
|
{
|
|
|
|
close(pstate->cn_confd);
|
|
|
|
free(pstate);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Initialize the output stream */
|
|
|
|
|
|
|
|
pstate->cn_outfd = OUTFD(pstate);
|
|
|
|
pstate->cn_outstream = OUTSTREAM(pstate);
|
2013-09-30 19:34:04 +02:00
|
|
|
#endif
|
2012-02-02 20:42:55 +01:00
|
|
|
}
|
2014-09-13 01:09:18 +02:00
|
|
|
|
2012-02-02 20:42:55 +01:00
|
|
|
return pstate;
|
|
|
|
}
|