Browse Source

Fix unneeded crlf while reading commands from stream. Issue #50.

git-svn-id: https://klish.googlecode.com/svn/trunk@328 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 14 years ago
parent
commit
4b7fdc4d58
3 changed files with 17 additions and 13 deletions
  1. 0 1
      clish/shell/shell_spawn.c
  2. 1 1
      clish/shell/shell_tinyrl.c
  3. 16 11
      tinyrl/tinyrl.c

+ 0 - 1
clish/shell/shell_spawn.c

@@ -151,7 +151,6 @@ static bool_t _loop(clish_shell_t * this, bool_t is_thread)
 				pthread_testcancel();
 				pthread_testcancel();
 		}
 		}
 	}
 	}
-
 	return BOOL_TRUE;
 	return BOOL_TRUE;
 }
 }
 
 

+ 1 - 1
clish/shell/shell_tinyrl.c

@@ -378,7 +378,7 @@ bool_t clish_shell_line(clish_shell_t * this, const char *prompt,
 			line = tinyrl_readline(this->tinyrl, prompt, &context);
 			line = tinyrl_readline(this->tinyrl, prompt, &context);
 		if (NULL != line) {
 		if (NULL != line) {
 			tinyrl_history_t *history =
 			tinyrl_history_t *history =
-			    tinyrl__get_history(this->tinyrl);
+				tinyrl__get_history(this->tinyrl);
 
 
 			if (tinyrl__get_isatty(this->tinyrl)) {
 			if (tinyrl__get_isatty(this->tinyrl)) {
 				/* deal with the history list */
 				/* deal with the history list */

+ 16 - 11
tinyrl/tinyrl.c

@@ -700,6 +700,7 @@ internal_readline(tinyrl_t   *this,
                 const char *str)
                 const char *str)
 {
 {
     FILE *istream = tinyrl_vt100__get_istream(this->term);
     FILE *istream = tinyrl_vt100__get_istream(this->term);
+    int crlf = 1; /* Enable crlf if result is NULL */
 
 
     /* initialise for reading a line */
     /* initialise for reading a line */
     this->done             = BOOL_FALSE;
     this->done             = BOOL_FALSE;
@@ -712,7 +713,6 @@ internal_readline(tinyrl_t   *this,
     this->prompt_size      = strlen(prompt);
     this->prompt_size      = strlen(prompt);
     this->context          = context;
     this->context          = context;
 
 
-
     if((BOOL_TRUE == this->isatty) && (!str))
     if((BOOL_TRUE == this->isatty) && (!str))
     {        
     {        
         /* set the terminal into raw input mode */
         /* set the terminal into raw input mode */
@@ -782,6 +782,12 @@ internal_readline(tinyrl_t   *this,
                 s = internal_insertline(this, buffer);
                 s = internal_insertline(this, buffer);
                 len = strlen(buffer) + 1; /* account for the '\0' */
                 len = strlen(buffer) + 1; /* account for the '\0' */
             }
             }
+            if (s == NULL || (this->line[0] == '\0' && feof(istream)))
+            {
+                 /* time to finish the session */
+                this->line = NULL;
+                crlf = 0;
+            }
         }
         }
 
 
         /*
         /*
@@ -789,15 +795,13 @@ internal_readline(tinyrl_t   *this,
          * This is a measure to stop potential task spin on encountering an
          * This is a measure to stop potential task spin on encountering an
          * error from fgets.
          * error from fgets.
          */
          */
-        if( s == NULL || (this->line[0] == '\0' && feof(istream)) )
-        {
-            /* time to finish the session */
-            this->line = NULL;
-        }
-        else
+        if (this->line)
         {
         {
-            /* call the handler for the newline key */
-            if(BOOL_FALSE == this->handlers[KEY_LF](this,KEY_LF))
+            if (this->line[0] == '\0')
+            {
+                tinyrl_reset_line_state(this);
+            }  /* call the handler for the newline key */
+            else if(BOOL_FALSE == this->handlers[KEY_LF](this,KEY_LF))
             {
             {
                 /* an issue has occured */
                 /* an issue has occured */
                 tinyrl_ding(this);
                 tinyrl_ding(this);
@@ -818,11 +822,12 @@ internal_readline(tinyrl_t   *this,
         /* free our internal buffer */
         /* free our internal buffer */
         free(this->buffer);
         free(this->buffer);
         this->buffer = NULL;
         this->buffer = NULL;
-    
-        if((NULL == result) || '\0' == *result)
+
+        if(crlf && ((NULL == result) || ('\0' == *result)))
         {
         {
             /* make sure we're not left on a prompt line */
             /* make sure we're not left on a prompt line */
             tinyrl_crlf(this);
             tinyrl_crlf(this);
+
         }
         }
         return result;
         return result;
     }
     }