summaryrefslogtreecommitdiff
path: root/apps/nshlib/nsh_consolemain.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-29 22:11:04 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-29 22:11:04 +0000
commit7b78d906d966d2c2b266bce9c1c0c8fef19c3103 (patch)
treede34ca63f68a004de6c9d864ef380a56b870e84a /apps/nshlib/nsh_consolemain.c
parentf5308beae0c268fa2b27e3a524e76afe871b6234 (diff)
downloadnuttx-7b78d906d966d2c2b266bce9c1c0c8fef19c3103.tar.gz
nuttx-7b78d906d966d2c2b266bce9c1c0c8fef19c3103.tar.bz2
nuttx-7b78d906d966d2c2b266bce9c1c0c8fef19c3103.zip
Add support for a login script (in addition to the init script); Add logic so that a USB console session can connect and reconnect to the USB serial device
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5582 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/nshlib/nsh_consolemain.c')
-rw-r--r--apps/nshlib/nsh_consolemain.c88
1 files changed, 25 insertions, 63 deletions
diff --git a/apps/nshlib/nsh_consolemain.c b/apps/nshlib/nsh_consolemain.c
index f05447a64..8be44f7aa 100644
--- a/apps/nshlib/nsh_consolemain.c
+++ b/apps/nshlib/nsh_consolemain.c
@@ -1,7 +1,7 @@
/****************************************************************************
* apps/nshlib/nsh_consolemain.c
*
- * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,8 @@
#include "nsh.h"
#include "nsh_console.h"
+#ifndef HAVE_USB_CONSOLE
+
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -76,21 +78,25 @@
****************************************************************************/
/****************************************************************************
- * Name: nsh_consolemain
+ * Name: nsh_consolemain (Normal character device version)
*
* Description:
* This interfaces maybe to called or started with task_start to start a
- * single an NSH instance that operates on stdin and stdout (/dev/console).
- * This function does not return.
+ * single an NSH instance that operates on stdin and stdout. This
+ * function does not normally return (see below).
*
+ * This version of nsh_consolmain handles generic /dev/console character
+ * devices (see nsh_usbdev.c for another version for special USB console
+ * devices).
+ *
* Input Parameters:
- * Standard task start-up arguements. These are not used. argc may be
+ * Standard task start-up arguments. These are not used. argc may be
* zero and argv may be NULL.
*
* Returned Values:
* This function does not normally return. exit() is usually called to
* terminate the NSH session. This function will return in the event of
- * an error. In that case, a nonzero value is returned (1).
+ * an error. In that case, a nonzero value is returned (EXIT_FAILURE=1).
*
****************************************************************************/
@@ -101,70 +107,26 @@ int nsh_consolemain(int argc, char *argv[])
DEBUGASSERT(pstate);
- /* If we are using a USB serial console, then we will have to wait for the
- * USB to be connected to the host.
- */
-
-#ifdef HAVE_USB_CONSOLE
- ret = nsh_usbconsole();
- DEBUGASSERT(ret == OK);
-#endif
-
- /* Present a greeting */
-
- fputs(g_nshgreeting, pstate->cn_outstream);
- fflush(pstate->cn_outstream);
-
- /* Execute the startup script */
+ /* Execute the start-up script */
#ifdef CONFIG_NSH_ROMFSETC
- (void)nsh_script(&pstate->cn_vtbl, "init", NSH_INITPATH);
+ (void)nsh_initscript(&pstate->cn_vtbl);
#endif
- /* Then enter the command line parsing loop */
-
- for (;;)
- {
- /* For the case of debugging the USB console... dump collected USB trace data */
+ /* Initialize any USB tracing options that were requested */
- nsh_usbtrace();
-
- /* Display the prompt string */
-
- fputs(g_nshprompt, pstate->cn_outstream);
- fflush(pstate->cn_outstream);
-
- /* Get the next line of input */
-
- ret = readline(pstate->cn_line, CONFIG_NSH_LINELEN,
- INSTREAM(pstate), OUTSTREAM(pstate));
- if (ret > 0)
- {
- /* Parse process the command */
-
- (void)nsh_parse(&pstate->cn_vtbl, pstate->cn_line);
- fflush(pstate->cn_outstream);
- }
+#ifdef CONFIG_NSH_USBDEV_TRACE
+ usbtrace_enable(TRACE_BITSET);
+#endif
- /* Readline normally returns the number of characters read,
- * but will return 0 on end of file or a negative value
- * if an error occurs. Either will cause the session to
- * terminate.
- */
+ /* Execute the session */
- else
- {
- fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_consolemain",
- "readline", NSH_ERRNO_OF(-ret));
- nsh_exit(&pstate->cn_vtbl, 1);
- }
- }
+ ret = nsh_session(pstate);
- /* Clean up. We do not get here, but this is necessary to keep some
- * compilers happy. But others will complain that this code is not
- * reachable.
- */
+ /* Exit upon return */
- nsh_exit(&pstate->cn_vtbl, 0);
- return OK;
+ nsh_exit(&pstate->cn_vtbl, ret);
+ return ret;
}
+
+#endif /* !HAVE_USB_CONSOLE */