Browse Source

Use SHELL_STATE_... as retval

git-svn-id: https://klish.googlecode.com/svn/trunk@516 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
2d095968a5
2 changed files with 14 additions and 25 deletions
  1. 10 8
      clish/shell.h
  2. 4 17
      clish/shell/shell_spawn.c

+ 10 - 8
clish/shell.h

@@ -38,14 +38,16 @@ struct clish_context_s {
 typedef struct clish_context_s clish_context_t;
 
 typedef enum {
-	SHELL_STATE_INITIALISING,
-	SHELL_STATE_OK,
-	SHELL_STATE_HELPING,
-	SHELL_STATE_SCRIPT_ERROR,/* Script execution error */
-	SHELL_STATE_EOF, /* EOF of input stream */
-	SHELL_STATE_SYNTAX_ERROR, /* Illegal line entered */
-	SHELL_STATE_SYSTEM_ERROR, /* Some internal system error */
-	SHELL_STATE_CLOSING
+	SHELL_STATE_OK = 0,
+	SHELL_STATE_UNKNOWN = 1,
+	SHELL_STATE_IO_ERROR = 2,
+	SHELL_STATE_SCRIPT_ERROR = 3,/* Script execution error */
+	SHELL_STATE_SYNTAX_ERROR = 4, /* Illegal line entered */
+	SHELL_STATE_SYSTEM_ERROR = 5, /* Some internal system error */
+	SHELL_STATE_INITIALISING = 6,
+	SHELL_STATE_HELPING = 7,
+	SHELL_STATE_EOF = 8, /* EOF of input stream */
+	SHELL_STATE_CLOSING = 9
 } clish_shell_state_t;
 
 typedef enum {

+ 4 - 17
clish/shell/shell_spawn.c

@@ -97,23 +97,15 @@ void clish_shell_load_scheme(clish_shell_t * this, const char *xml_path)
 #endif
 }
 
-enum {
-	RETVAL_OK = 0, /* OK */
-	RETVAL_UNKNOWN = 1, /* Unknown error */
-	RETVAL_NOSTDIN = 2, /* No stdin found */
-	RETVAL_SCRIPT = 3, /* Script execution error */
-	RETVAL_SYNTAX = 4 /* Syntax error */
-};
-
 /*-------------------------------------------------------- */
 static int _loop(clish_shell_t * this, bool_t is_thread)
 {
 	int running = 0;
-	int retval = RETVAL_OK;
+	int retval = SHELL_STATE_OK;
 
 	assert(this);
 	if (!tinyrl__get_istream(this->tinyrl))
-		return RETVAL_NOSTDIN;
+		return SHELL_STATE_IO_ERROR;
 	/* Check the shell isn't closing down */
 	if (this && (SHELL_STATE_CLOSING == this->state))
 		return retval;
@@ -122,7 +114,7 @@ static int _loop(clish_shell_t * this, bool_t is_thread)
 		pthread_testcancel();
 	/* Loop reading and executing lines until the user quits */
 	while (!running) {
-		retval = RETVAL_OK;
+		retval = SHELL_STATE_OK;
 		/* Get input from the stream */
 		running = clish_shell_readline(this, NULL);
 		if (running) {
@@ -133,13 +125,8 @@ static int _loop(clish_shell_t * this, bool_t is_thread)
 				if (tinyrl__get_isatty(this->tinyrl) ||
 					!this->current_file->stop_on_error)
 					running = 0;
-				if (SHELL_STATE_SCRIPT_ERROR == this->state)
-					retval = RETVAL_SCRIPT;
-				else
-					retval = RETVAL_SYNTAX;
-				break;
+				retval = this->state;
 			default:
-					retval = RETVAL_UNKNOWN;
 				break;
 			}
 		}