system/cle: Make it work without CONFIG_FILE_STREAM
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
c8439368ac
commit
58586f86e3
@ -53,7 +53,7 @@ extern "C"
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cle
|
||||
* Name: cle/cle_fd
|
||||
*
|
||||
* Description:
|
||||
* EMACS-like command line editor. This is actually more like readline
|
||||
@ -61,8 +61,13 @@ extern "C"
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int cle_fd(FAR char *line, FAR const char *prompt, uint16_t linelen,
|
||||
int infd, int outfd);
|
||||
|
||||
#ifdef CONFIG_FILE_STREAM
|
||||
int cle(FAR char *line, FAR const char *prompt, uint16_t linelen,
|
||||
FAR FILE *instream, FAR FILE *outstream);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
|
@ -142,8 +142,8 @@ struct cle_s
|
||||
uint16_t coloffs; /* Left cursor offset */
|
||||
uint16_t linelen; /* Size of the line buffer */
|
||||
uint16_t nchars; /* Size of data in the line buffer */
|
||||
FAR FILE *ins; /* Input file stream */
|
||||
FAR FILE *outs; /* Output file stream */
|
||||
int infd; /* Input file handle */
|
||||
int outfd; /* Output file handle */
|
||||
FAR char *line; /* Line buffer */
|
||||
FAR const char *prompt; /* Prompt, in case we have to re-print it */
|
||||
};
|
||||
@ -257,7 +257,6 @@ static void cle_write(FAR struct cle_s *priv, FAR const char *buffer,
|
||||
uint16_t buflen)
|
||||
{
|
||||
ssize_t nwritten;
|
||||
uint16_t nremaining = buflen;
|
||||
|
||||
/* Loop until all bytes have been successfully written (or until a
|
||||
* unrecoverable error is encountered)
|
||||
@ -267,7 +266,7 @@ static void cle_write(FAR struct cle_s *priv, FAR const char *buffer,
|
||||
{
|
||||
/* Put the next gulp */
|
||||
|
||||
nwritten = fwrite(buffer, sizeof(char), buflen, priv->outs);
|
||||
nwritten = write(priv->outfd, buffer, buflen);
|
||||
|
||||
/* Handle write errors. write() should neve return 0. */
|
||||
|
||||
@ -291,12 +290,11 @@ static void cle_write(FAR struct cle_s *priv, FAR const char *buffer,
|
||||
|
||||
else
|
||||
{
|
||||
nremaining -= nwritten;
|
||||
buffer += nwritten;
|
||||
buflen -= nwritten;
|
||||
}
|
||||
}
|
||||
while (nremaining > 0);
|
||||
|
||||
fflush(priv->outs);
|
||||
while (buflen > 0);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -333,7 +331,7 @@ static int cle_getch(FAR struct cle_s *priv)
|
||||
{
|
||||
/* Read one character from the incoming stream */
|
||||
|
||||
nread = fread (&buffer, sizeof(char), 1, priv->ins);
|
||||
nread = read(priv->infd, &buffer, 1);
|
||||
|
||||
/* Check for error or end-of-file. */
|
||||
|
||||
@ -1135,7 +1133,7 @@ static int cle_editloop(FAR struct cle_s *priv)
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cle
|
||||
* Name: cle/cle_fd
|
||||
*
|
||||
* Description:
|
||||
* EMACS-like command line editor. This is actually more like readline
|
||||
@ -1143,8 +1141,8 @@ static int cle_editloop(FAR struct cle_s *priv)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int cle(FAR char *line, const char *prompt, uint16_t linelen,
|
||||
FILE *instream, FILE *outstream)
|
||||
int cle_fd(FAR char *line, FAR const char *prompt, uint16_t linelen,
|
||||
int infd, int outfd)
|
||||
{
|
||||
FAR struct cle_s priv;
|
||||
uint16_t column;
|
||||
@ -1157,8 +1155,8 @@ int cle(FAR char *line, const char *prompt, uint16_t linelen,
|
||||
priv.linelen = linelen;
|
||||
priv.line = line;
|
||||
|
||||
priv.ins = instream;
|
||||
priv.outs = outstream;
|
||||
priv.infd = infd;
|
||||
priv.outfd = outfd;
|
||||
|
||||
/* Store the prompt in case we need to re-print it */
|
||||
|
||||
@ -1225,3 +1223,11 @@ int cle(FAR char *line, const char *prompt, uint16_t linelen,
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FILE_STREAM
|
||||
int cle(FAR char *line, FAR const char *prompt, uint16_t linelen,
|
||||
FAR FILE *instream, FAR FILE *outstream)
|
||||
{
|
||||
return cle_fd(line, prompt, linelen, instream->fs_fd, outstream->fs_fd);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user