summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>2014-08-29 12:48:08 +0300
committerSamuel Ortiz <sameo@linux.intel.com>2014-09-08 00:40:51 +0200
commitb2cff5c69296fc59a92eb48f8379c2acb095d914 (patch)
treefb1856b97ccc21ebd9d3417dc083d8db3075d2c6
parent7c8baf0f372c833c8d2a24020ac8c35705639ed4 (diff)
downloadneardal-b2cff5c69296fc59a92eb48f8379c2acb095d914.tar.gz
neardal-b2cff5c69296fc59a92eb48f8379c2acb095d914.tar.bz2
neardal-b2cff5c69296fc59a92eb48f8379c2acb095d914.zip
Simplify command line parameter logic.
-rw-r--r--ncl/ncl.c64
1 files changed, 22 insertions, 42 deletions
diff --git a/ncl/ncl.c b/ncl/ncl.c
index 234a269..c4950c8 100644
--- a/ncl/ncl.c
+++ b/ncl/ncl.c
@@ -308,51 +308,31 @@ int main(int argc, char *argv[])
return NCLERR_INIT;
}
- /* Do we have a command line in parameters list ? */
- if (scriptFileStr == NULL) {
- /* No, test application executed without a command line in
- parameter. Do we have a command in parameters list ? */
- if (execCmdLineStr == NULL) {
- keep_running:
- /* No, test application executed without a command
- line in parameter */
- gNclCtx.channel = g_io_channel_unix_new(STDIN_FILENO);
- gNclCtx.tag = g_io_add_watch(gNclCtx.channel, G_IO_IN,
+ if (!scriptFileStr && !execCmdLineStr)
+ opt_keep_running = TRUE;
+
+ if (scriptFileStr)
+ ncl_prv_parse_script_file(scriptFileStr);
+
+ if (execCmdLineStr) {
+ gNclCtx.errOnExit = ncl_exec(execCmdLineStr);
+ while (g_main_context_pending(NULL))
+ g_main_context_iteration(NULL, FALSE);
+ }
+
+ if (opt_keep_running) {
+ gNclCtx.channel = g_io_channel_unix_new(STDIN_FILENO);
+ gNclCtx.tag = g_io_add_watch(gNclCtx.channel, G_IO_IN,
(GIOFunc) ncl_prv_kbinput_cb, &gNclCtx);
- g_io_channel_unref(gNclCtx.channel);
- /* Invoking 'help' command to display commands line
- * list */
+ g_io_channel_unref(gNclCtx.channel);
+
+ if (!scriptFileStr && !execCmdLineStr)
ncl_exec(LISTCMD_NAME);
- rl_callback_handler_install(NCL_PROMPT, ncl_parse_line);
- /* Launch main-loop */
- g_main_loop_run(gNclCtx.main_loop);
- } else {
- int eventsCount = 0;
-
- /* Yes, test application executed with a command line
- * in parameter */
- NCL_CMD_PRINTF("Executing command ('%s')...\n",
- execCmdLineStr);
- gNclCtx.errOnExit = ncl_exec(execCmdLineStr);
-
- NCL_CMD_PRINT(
- "Command executed('%s'), processing events...",
- execCmdLineStr);
- do {
- NCL_CMD_PRINT("*");
- eventsCount++;
- } while (g_main_context_iteration(NULL, false) == true);
- NCL_CMD_PRINT("\n");
- NCL_CMD_PRINTF("All events have been processed (%d).\n",
- eventsCount);
- g_free(execCmdLineStr);
- execCmdLineStr = NULL;
- if (opt_keep_running)
- goto keep_running;
- }
- } else
- ncl_prv_parse_script_file(scriptFileStr);
+ rl_callback_handler_install(NCL_PROMPT, ncl_parse_line);
+
+ g_main_loop_run(gNclCtx.main_loop);
+ }
err = gNclCtx.errOnExit;