You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/11/29 13:18:38 UTC

[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on a change in pull request #892: Make readline/cle work without CONFIG_FILE_STREAM

xiaoxiang781216 commented on a change in pull request #892:
URL: https://github.com/apache/incubator-nuttx-apps/pull/892#discussion_r758352150



##########
File path: system/readline/readline.c
##########
@@ -177,52 +36,20 @@ static void readline_write(FAR struct rl_common_s *vtbl,
 /****************************************************************************
  * Name: readline
  *
- *   readline() reads in at most one less than 'buflen' characters from
- *   'instream' and stores them into the buffer pointed to by 'buf'.
- *   Characters are echoed on 'outstream'.  Reading stops after an EOF or a
- *   newline.  If a newline is read, it is stored into the buffer.  A null
- *   terminator is stored after the last character in the buffer.
- *
- *   This version of realine assumes that we are reading and writing to
- *   a VT100 console.  This will not work well if 'instream' or 'outstream'
- *   corresponds to a raw byte steam.
- *
- *   This function is inspired by the GNU readline but is an entirely
- *   different creature.
- *
- * Input Parameters:
- *   buf       - The user allocated buffer to be filled.
- *   buflen    - the size of the buffer.
- *   instream  - The stream to read characters from
- *   outstream - The stream to each characters to.
- *
- * Returned values:
- *   On success, the (positive) number of bytes transferred is returned.
- *   EOF is returned to indicate either an end of file condition or a
- *   failure.
+ *   readline() is same as readline_fd() but accept the file stream instead
+ *   of file handle.
  *
  ****************************************************************************/
 
+#ifdef CONFIG_FILE_STREAM
 ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream)
 {
-  struct readline_s vtbl;
-
   /* Sanity checks */
 
   DEBUGASSERT(instream && outstream);
 
-  /* Set up the vtbl structure */
-
-  vtbl.vtbl.rl_getc  = readline_getc;
-  vtbl.infd          = instream->fs_fd;
+  /* Let readline_fd do the work */
 
-#ifdef CONFIG_READLINE_ECHO
-  vtbl.vtbl.rl_putc  = readline_putc;
-  vtbl.vtbl.rl_write = readline_write;
-  vtbl.outfd         = outstream->fs_fd;
-#endif
-
-  /* The let the common readline logic do the work */
-
-  return readline_common(&vtbl.vtbl, buf, buflen);
+  return readline_fd(buf, buflen, instream->fs_fd, outstream->fs_fd);
 }
+#endif

Review comment:
       Yes, after this patch get merged, I will make nsh work without CONFIG_FILE_STREAM to save the code space.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org