diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-02-01 19:47:12 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-02-01 19:47:12 +0000 |
commit | 37259910ba73b71e4c32e5913e4d44c245c4502d (patch) | |
tree | 9b5b0a7b3d6180141c3f9d959b6c04647e4a6810 | |
parent | 6d35541209058b86bda7b34e47fa28c8c959d365 (diff) | |
download | nuttx-37259910ba73b71e4c32e5913e4d44c245c4502d.tar.gz nuttx-37259910ba73b71e4c32e5913e4d44c245c4502d.tar.bz2 nuttx-37259910ba73b71e4c32e5913e4d44c245c4502d.zip |
Use realine instead of fgets in several other places
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4357 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | apps/examples/README.txt | 37 | ||||
-rw-r--r-- | apps/examples/ftpc/ftpc_main.c | 37 | ||||
-rw-r--r-- | apps/examples/usbterm/usbterm_main.c | 29 | ||||
-rw-r--r-- | apps/nshlib/README.txt | 8 | ||||
-rw-r--r-- | apps/nshlib/nsh_serial.c | 2 |
5 files changed, 103 insertions, 10 deletions
diff --git a/apps/examples/README.txt b/apps/examples/README.txt index b14d19b84..a8af257d7 100644 --- a/apps/examples/README.txt +++ b/apps/examples/README.txt @@ -244,9 +244,20 @@ examples/ftpc where xx.xx.xx.xx is the IP address of the FTP server and pp is an optional port number. - NOTE: The ftpc task uses the system console for input/output. It will - not work from NSH over a telnet NSH connection (Well, it will work you - just won't be able to access the command line). + NOTE: By default, FTPC uses readline to get data from stdin. So your + appconfig file must have the following build path: + + CONFIGURED_APPS += system/readline + + NOTE: If you use the ftpc task over a telnet NSH connection, then you + should set the following configuration item: + + CONFIG_EXAMPLES_FTPC_FGETS=y + + By default, the FTPC client will use readline() to get characters from + the console. Readline includes and command-line editor and echos + characters received in stdin back through stdout. Neither of these + behaviors are desire-able if Telnet is used. You may also want to define the following in your configuration file. Otherwise, you will have not feeback about what is going on: @@ -393,6 +404,11 @@ examples/nsh CONFIGURED_APPS += nshlib + NOTE: If the NSH serial console is used, then following is also + required to build the readline() library: + + CONFIGURED_APPS += system/readline + And if networking is included: CONFIGURED_APPS += uiplib @@ -1257,6 +1273,21 @@ examples/usbterm CONFIG_EXAMPLES_USBTERM_TRACEINTERRUPTS Show interrupt-related events. + NOTE: By default, USBterm uses readline to get data from stdin. So your + appconfig file must have the following build path: + + CONFIGURED_APPS += system/readline + + NOTE: If you use the USBterm task over a telnet NSH connection, then you + should set the following configuration item: + + CONFIG_EXAMPLES_USBTERM_FGETS=y + + By default, the USBterm client will use readline() to get characters from + the console. Readline includes and command-line editor and echos + characters received in stdin back through stdout. Neither of these + behaviors are desire-able if Telnet is used. + Error results are always shown in the trace output Other relevant configuration options: CONFIG_CDCACM selected by the diff --git a/apps/examples/ftpc/ftpc_main.c b/apps/examples/ftpc/ftpc_main.c index 7a1cb50f7..9093b0c10 100644 --- a/apps/examples/ftpc/ftpc_main.c +++ b/apps/examples/ftpc/ftpc_main.c @@ -1,8 +1,8 @@ /**************************************************************************** * examples/ftpc/ftpc_main.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * 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 @@ -41,10 +41,13 @@ #include <stdlib.h> #include <unistd.h> #include <string.h> +#include <errno.h> #include <arpa/inet.h> #include <apps/ftpc.h> +#include <apps/readline.h> + #include "ftpc.h" /**************************************************************************** @@ -357,6 +360,9 @@ int ftpc_main(int argc, char **argv, char **envp) struct ftpc_connect_s connect = {{0}, 0}; SESSION handle; FAR char *ptr; +#ifndef CONFIG_EXAMPLES_FTPC_FGETS + int ret; +#endif if (argc != 2) { @@ -413,9 +419,32 @@ int ftpc_main(int argc, char **argv, char **envp) /* Get the next line of input */ - if (fgets(g_line, CONFIG_FTPC_LINELEN, stdin)) +#ifdef CONFIG_EXAMPLES_FTPC_FGETS + /* fgets returns NULL on end-of-file or any I/O error */ + + if (fgets(g_line, CONFIG_FTPC_LINELEN, stdin) == NULL) + { + printf("ERROR: fgets failed: %d\n", errno); + return 1; + } +#else + ret = readline(g_line, CONFIG_FTPC_LINELEN, stdin, stdout); + + /* 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. + */ + + if (ret <= 0) + { + printf("ERROR: readline failed: %d\n", ret); + return 1; + } +#endif + else { - /* Parse process the command */ + /* Parse and process the command */ (void)ftpc_parse(handle, g_line); FFLUSH(); diff --git a/apps/examples/usbterm/usbterm_main.c b/apps/examples/usbterm/usbterm_main.c index d51101dd7..066c6f548 100644 --- a/apps/examples/usbterm/usbterm_main.c +++ b/apps/examples/usbterm/usbterm_main.c @@ -50,6 +50,8 @@ #include <errno.h> #include <debug.h> +#include <apps/readline.h> + #include <nuttx/usb/usbdev.h> #include <nuttx/usb/usbdev_trace.h> @@ -297,9 +299,32 @@ int MAIN_NAME(int argc, char *argv[]) fputs("usbterm> ", stdout); fflush(stdout); - /* Get the next line of input from stdin */ + /* Get the next line of input */ + +#ifdef CONFIG_EXAMPLES_USBTERM_FGETS + /* fgets returns NULL on end-of-file or any I/O error */ + + if (fgets(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin) == NULL) + { + printf("ERROR: fgets failed: %d\n", errno); + return 1; + } +#else + ret = readline(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin, stdout); + + /* 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. + */ - if (fgets(g_usbterm.outbuffer, CONFIG_EXAMPLES_USBTERM_BUFLEN, stdin)) + if (ret <= 0) + { + printf("ERROR: readline failed: %d\n", ret); + return 1; + } +#endif + else { /* Send the line of input via USB */ diff --git a/apps/nshlib/README.txt b/apps/nshlib/README.txt index fad1ac104..fbdf9178a 100644 --- a/apps/nshlib/README.txt +++ b/apps/nshlib/README.txt @@ -1047,3 +1047,11 @@ Common Problems Make sure that the polled console is disabled in the OS configuration file, .config. That file should have CONFIG_DEV_LOWCONSOLE=n for NSH over serial. + + Problem: + The function 'readline' is undefined. + Usual Cause: + The following is missing from your appconfig file: + + CONFIGURED_APPS += system/readline + diff --git a/apps/nshlib/nsh_serial.c b/apps/nshlib/nsh_serial.c index 72004dd7f..57cb1b1c1 100644 --- a/apps/nshlib/nsh_serial.c +++ b/apps/nshlib/nsh_serial.c @@ -525,7 +525,7 @@ int nsh_consolemain(int argc, char *argv[]) else { - fprintf(pstate->ss_outstream, g_fmtcmdfailed, "readline", NSH_ERRNO); + fprintf(pstate->ss_outstream, g_fmtcmdfailed, "readline", NSH_ERRNO_OF(-ret)); return 1; } } |