2012-02-02 20:42:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/nshlib/nsh_console.h
|
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2012-02-02 20:42:55 +01:00
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-02-02 20:42:55 +01:00
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2012-02-02 20:42:55 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __APPS_NSHLIB_NSH_CONSOLE_H
|
|
|
|
#define __APPS_NSHLIB_NSH_CONSOLE_H
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2023-02-22 17:19:59 +01:00
|
|
|
#include <nuttx/queue.h>
|
|
|
|
|
2012-02-02 20:42:55 +01:00
|
|
|
/****************************************************************************
|
2014-05-05 16:52:02 +02:00
|
|
|
* Pre-processor Definitions
|
2012-02-02 20:42:55 +01:00
|
|
|
****************************************************************************/
|
2020-08-17 12:28:50 +02:00
|
|
|
|
2012-02-02 20:42:55 +01:00
|
|
|
/* Method access macros */
|
|
|
|
|
2024-08-06 23:29:50 +02:00
|
|
|
#define nsh_clone(v) (v)->clone(v)
|
|
|
|
#define nsh_release(v) (v)->release(v)
|
|
|
|
#define nsh_write(v,b,n) (v)->write(v,b,n)
|
2024-08-06 23:52:34 +02:00
|
|
|
#define nsh_read(v,b,n) (v)->read(v,b,n)
|
2024-08-06 23:29:50 +02:00
|
|
|
#define nsh_ioctl(v,c,a) (v)->ioctl(v,c,a)
|
|
|
|
#define nsh_linebuffer(v) (v)->linebuffer(v)
|
|
|
|
#define nsh_redirect(v,fi,fo,s) (v)->redirect(v,fi,fo,s)
|
|
|
|
#define nsh_undirect(v,s) (v)->undirect(v,s)
|
|
|
|
#define nsh_exit(v,s) (v)->exit(v,s)
|
2012-02-02 20:42:55 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_CPP_HAVE_VARARGS
|
2024-08-06 23:29:50 +02:00
|
|
|
# define nsh_error(v, ...) (v)->error(v, ##__VA_ARGS__)
|
|
|
|
# define nsh_output(v, ...) (v)->output(v, ##__VA_ARGS__)
|
2023-08-24 12:26:20 +02:00
|
|
|
# define nsh_none(v, ...) \
|
|
|
|
do { if (0) nsh_output_none(v, ##__VA_ARGS__); } while (0)
|
2012-02-02 20:42:55 +01:00
|
|
|
#else
|
2023-08-24 12:26:20 +02:00
|
|
|
# define nsh_error vtbl->error
|
|
|
|
# define nsh_output vtbl->output
|
|
|
|
# define nsh_none (void)
|
2012-02-02 20:42:55 +01:00
|
|
|
#endif
|
|
|
|
|
2023-06-08 13:37:31 +02:00
|
|
|
#ifdef CONFIG_NSH_DISABLE_ERROR_PRINT
|
|
|
|
# undef nsh_error
|
2023-08-24 12:26:20 +02:00
|
|
|
# define nsh_error nsh_none
|
2023-06-08 13:37:31 +02:00
|
|
|
#endif
|
|
|
|
|
2020-08-17 12:28:50 +02:00
|
|
|
/* Size of info to be saved in call to nsh_redirect
|
|
|
|
* See struct serialsave_s in nsh_console.c
|
|
|
|
*/
|
2012-02-02 20:42:55 +01:00
|
|
|
|
2023-02-21 23:08:13 +01:00
|
|
|
#define SAVE_SIZE (2 * sizeof(int))
|
2012-02-02 20:42:55 +01:00
|
|
|
|
|
|
|
/* Are we using the NuttX console for I/O? Or some other character device? */
|
|
|
|
|
2023-02-10 10:50:46 +01:00
|
|
|
#ifdef CONFIG_NSH_ALTCONDEV
|
2014-05-05 16:52:02 +02:00
|
|
|
|
2023-02-10 10:50:46 +01:00
|
|
|
# if !defined(CONFIG_NSH_ALTSTDIN) && !defined(CONFIG_NSH_ALTSTDOUT) && \
|
|
|
|
!defined(CONFIG_NSH_ALTSTDERR)
|
|
|
|
# error CONFIG_NSH_ALTCONDEV selected but CONFIG_NSH_ALTSTDxxx not provided
|
2013-09-30 19:34:04 +02:00
|
|
|
# endif
|
2023-02-10 10:50:46 +01:00
|
|
|
|
|
|
|
# define INFD(p) ((p)->cn_confd)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2024-08-06 23:29:50 +02:00
|
|
|
# define INFD(p) ((p)->cn_infd)
|
2023-02-10 10:50:46 +01:00
|
|
|
|
2012-02-02 20:42:55 +01:00
|
|
|
#endif
|
|
|
|
|
2023-02-10 10:50:46 +01:00
|
|
|
# define OUTFD(p) ((p)->cn_outfd)
|
|
|
|
# define ERRFD(p) ((p)->cn_errfd)
|
|
|
|
|
2012-02-02 20:42:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
2020-08-17 12:28:50 +02:00
|
|
|
|
2012-02-02 20:42:55 +01:00
|
|
|
/* This describes a generic console front-end */
|
|
|
|
|
|
|
|
struct nsh_vtbl_s
|
|
|
|
{
|
|
|
|
/* This function pointers are "hooks" into the front end logic to
|
|
|
|
* handle things like output of command results, redirection, etc.
|
|
|
|
* -- all of which must be done in a way that is unique to the nature
|
|
|
|
* of the front end.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLEBG
|
|
|
|
FAR struct nsh_vtbl_s *(*clone)(FAR struct nsh_vtbl_s *vtbl);
|
|
|
|
void (*addref)(FAR struct nsh_vtbl_s *vtbl);
|
|
|
|
#endif
|
2021-05-06 16:28:05 +02:00
|
|
|
void (*release)(FAR struct nsh_vtbl_s *vtbl);
|
2016-01-05 23:38:50 +01:00
|
|
|
ssize_t (*write)(FAR struct nsh_vtbl_s *vtbl, FAR const void *buffer,
|
|
|
|
size_t nbytes);
|
2024-08-06 23:52:34 +02:00
|
|
|
ssize_t (*read)(FAR struct nsh_vtbl_s *vtbl, FAR void *buffer,
|
|
|
|
size_t nbytes);
|
2023-02-22 06:13:45 +01:00
|
|
|
int (*ioctl)(FAR struct nsh_vtbl_s *vtbl, int cmd, unsigned long arg);
|
2023-06-08 13:37:31 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT
|
2022-07-17 08:05:23 +02:00
|
|
|
int (*error)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...)
|
2022-12-12 20:06:32 +01:00
|
|
|
printf_like(2, 3);
|
2023-06-08 13:37:31 +02:00
|
|
|
#endif
|
2022-07-17 08:05:23 +02:00
|
|
|
int (*output)(FAR struct nsh_vtbl_s *vtbl, FAR const char *fmt, ...)
|
2022-12-12 20:06:32 +01:00
|
|
|
printf_like(2, 3);
|
2012-02-02 20:42:55 +01:00
|
|
|
FAR char *(*linebuffer)(FAR struct nsh_vtbl_s *vtbl);
|
2024-08-06 23:29:50 +02:00
|
|
|
void (*redirect)(FAR struct nsh_vtbl_s *vtbl, int fd_in, int fd_out,
|
|
|
|
FAR uint8_t *save);
|
2012-02-02 20:42:55 +01:00
|
|
|
void (*undirect)(FAR struct nsh_vtbl_s *vtbl, FAR uint8_t *save);
|
2020-08-17 12:28:50 +02:00
|
|
|
void (*exit)(FAR struct nsh_vtbl_s *vtbl, int status) noreturn_function;
|
2012-02-02 20:42:55 +01:00
|
|
|
|
2015-11-28 18:13:47 +01:00
|
|
|
#ifdef NSH_HAVE_IOBUFFER
|
2020-08-17 12:28:50 +02:00
|
|
|
/* Common buffer for file I/O. */
|
2015-11-28 18:13:47 +01:00
|
|
|
|
|
|
|
char iobuffer[IOBUFFERSIZE];
|
|
|
|
#endif
|
|
|
|
|
2023-02-22 17:19:59 +01:00
|
|
|
#ifdef CONFIG_NSH_ALIAS
|
|
|
|
/* Shell alias support */
|
|
|
|
|
|
|
|
struct nsh_alias_s atab[CONFIG_NSH_ALIAS_MAX_AMOUNT];
|
|
|
|
struct sq_queue_s alist;
|
|
|
|
struct sq_queue_s afreelist;
|
|
|
|
#endif
|
|
|
|
|
2012-02-02 20:42:55 +01:00
|
|
|
/* Parser state data */
|
|
|
|
|
|
|
|
struct nsh_parser_s np;
|
2021-06-17 16:59:42 +02:00
|
|
|
|
|
|
|
/* Ctrl tty or not */
|
|
|
|
|
|
|
|
bool isctty;
|
2012-02-02 20:42:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* This structure describes a console front-end that is based on stdin and
|
|
|
|
* stdout (which is all of the supported console types at the time being).
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct console_stdio_s
|
|
|
|
{
|
|
|
|
/* NSH front-end call table */
|
|
|
|
|
|
|
|
struct nsh_vtbl_s cn_vtbl;
|
|
|
|
|
|
|
|
/* NSH input/output streams */
|
|
|
|
|
2014-05-05 16:52:02 +02:00
|
|
|
#ifdef CONFIG_NSH_ALTCONDEV
|
2022-10-08 10:31:21 +02:00
|
|
|
int cn_confd; /* Console I/O file descriptor */
|
2012-02-02 20:42:55 +01:00
|
|
|
#endif
|
2024-08-06 23:29:50 +02:00
|
|
|
int cn_infd; /* Input file descriptor (possibly redirected) */
|
2022-10-08 10:31:21 +02:00
|
|
|
int cn_outfd; /* Output file descriptor (possibly redirected) */
|
|
|
|
int cn_errfd; /* Error Output file descriptor (possibly redirected) */
|
2012-02-02 20:42:55 +01:00
|
|
|
|
2018-10-01 21:30:25 +02:00
|
|
|
#ifdef CONFIG_NSH_VARS
|
|
|
|
/* Allocation and size of NSH variables */
|
|
|
|
|
|
|
|
FAR char *varp;
|
|
|
|
size_t varsz;
|
|
|
|
#endif
|
|
|
|
|
2012-02-02 20:42:55 +01:00
|
|
|
/* Line input buffer */
|
|
|
|
|
|
|
|
char cn_line[CONFIG_NSH_LINELEN];
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-08-24 12:26:20 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Inline functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_CPP_HAVE_VARARGS
|
|
|
|
/* Can be used to suppress any nsh output */
|
|
|
|
|
|
|
|
static inline void nsh_output_none(FAR struct nsh_vtbl_s *vtbl, ...)
|
|
|
|
{
|
|
|
|
UNUSED(vtbl);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-02 20:42:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Defined in nsh_console.c *************************************************/
|
|
|
|
|
2021-06-17 16:59:42 +02:00
|
|
|
FAR struct console_stdio_s *nsh_newconsole(bool isctty);
|
2012-02-02 20:42:55 +01:00
|
|
|
|
|
|
|
#endif /* __APPS_NSHLIB_NSH_CONSOLE_H */
|