Browse Source

Add --check option to clish. To check config files

git-svn-id: https://klish.googlecode.com/svn/trunk@519 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
7266c16269
2 changed files with 19 additions and 5 deletions
  1. 8 1
      bin/clish.cpp
  2. 11 4
      clish/shell/shell_tinyrl.c

+ 8 - 1
bin/clish.cpp

@@ -72,7 +72,7 @@ int main(int argc, char **argv)
 	struct sigaction sigpipe_act;
 	struct sigaction sigpipe_act;
 	sigset_t sigpipe_set;
 	sigset_t sigpipe_set;
 
 
-	static const char *shortopts = "hvs:ledx:w:i:bqu8o";
+	static const char *shortopts = "hvs:ledx:w:i:bqu8ok";
 #ifdef HAVE_GETOPT_H
 #ifdef HAVE_GETOPT_H
 	static const struct option longopts[] = {
 	static const struct option longopts[] = {
 		{"help",	0, NULL, 'h'},
 		{"help",	0, NULL, 'h'},
@@ -89,6 +89,7 @@ int main(int argc, char **argv)
 		{"utf8",	0, NULL, 'u'},
 		{"utf8",	0, NULL, 'u'},
 		{"8bit",	0, NULL, '8'},
 		{"8bit",	0, NULL, '8'},
 		{"log",		0, NULL, 'o'},
 		{"log",		0, NULL, 'o'},
+		{"check",	0, NULL, 'k'},
 		{NULL,		0, NULL, 0}
 		{NULL,		0, NULL, 0}
 	};
 	};
 #endif
 #endif
@@ -154,6 +155,11 @@ int main(int argc, char **argv)
 		case 'i':
 		case 'i':
 			viewid = optarg;
 			viewid = optarg;
 			break;
 			break;
+		case 'k':
+			lockless = BOOL_TRUE;
+			my_hooks.script_fn = clish_dryrun_callback;
+			my_hooks.config_fn = NULL;
+			break;
 		case 'h':
 		case 'h':
 			help(0, argv[0]);
 			help(0, argv[0]);
 			exit(0);
 			exit(0);
@@ -282,6 +288,7 @@ static void help(int status, const char *argv0)
 		printf("\t-u, --utf8\tForce UTF-8 encoding.\n");
 		printf("\t-u, --utf8\tForce UTF-8 encoding.\n");
 		printf("\t-8, --8bit\tForce 8-bit encoding.\n");
 		printf("\t-8, --8bit\tForce 8-bit encoding.\n");
 		printf("\t-o, --log\tEnable command logging to syslog's local0.\n");
 		printf("\t-o, --log\tEnable command logging to syslog's local0.\n");
+		printf("\t-k, --check\tCheck input files for syntax errors only.\n");
 	}
 	}
 }
 }
 
 

+ 11 - 4
clish/shell/shell_tinyrl.c

@@ -254,22 +254,29 @@ static bool_t clish_shell_tinyrl_key_enter(tinyrl_t *this, int key)
 		/* we've got a command so check the syntax */
 		/* we've got a command so check the syntax */
 		arg_status = clish_shell_parse(context->shell,
 		arg_status = clish_shell_parse(context->shell,
 			line, &context->cmd, &context->pargv);
 			line, &context->cmd, &context->pargv);
+		if (CLISH_LINE_OK != arg_status) {
+			fprintf(stderr, "Syntax error on line \"%s\":\n",
+				line);
+		}
 		switch (arg_status) {
 		switch (arg_status) {
 		case CLISH_LINE_OK:
 		case CLISH_LINE_OK:
 			tinyrl_done(this);
 			tinyrl_done(this);
 			result = BOOL_TRUE;
 			result = BOOL_TRUE;
 			break;
 			break;
 		case CLISH_BAD_HISTORY:
 		case CLISH_BAD_HISTORY:
-			fprintf(stderr, "Error: Bad history entry.\n");
+			fprintf(stderr, "Bad history entry.\n");
 			break;
 			break;
 		case CLISH_BAD_CMD:
 		case CLISH_BAD_CMD:
-			fprintf(stderr, "Error: Illegal command line.\n");
+			fprintf(stderr, "Illegal command line.\n");
 			break;
 			break;
 		case CLISH_BAD_PARAM:
 		case CLISH_BAD_PARAM:
-			fprintf(stderr, "Error: Illegal parameter.\n");
+			fprintf(stderr, "Illegal parameter.\n");
 			break;
 			break;
 		case CLISH_LINE_PARTIAL:
 		case CLISH_LINE_PARTIAL:
-			fprintf(stderr, "Error: The command is not completed.\n");
+			fprintf(stderr, "The command is not completed.\n");
+			break;
+		default:
+			fprintf(stderr, "Unknown problem.\n");
 			break;
 			break;
 		}
 		}
 		if (CLISH_LINE_OK != arg_status)
 		if (CLISH_LINE_OK != arg_status)