summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-05-05 23:16:52 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2014-05-11 19:55:57 +0200
commit5b89e6618f023b46be1dc91ba4eab46e78bc7121 (patch)
treebebd6b73096eadb0a89c8412c70e2669566296cd
parentdc869e70acaadb7ef2d96101fe8e938d53f18e65 (diff)
downloadrockbox-5b89e6618f023b46be1dc91ba4eab46e78bc7121.zip
rockbox-5b89e6618f023b46be1dc91ba4eab46e78bc7121.tar.gz
rockbox-5b89e6618f023b46be1dc91ba4eab46e78bc7121.tar.bz2
rockbox-5b89e6618f023b46be1dc91ba4eab46e78bc7121.tar.xz
hwstub: hwstub_shell can now run files/cmd provides on command line
Change-Id: Id5cb3bee52b39e2ddec95c646ca9b4a3334bdf92
-rw-r--r--utils/hwstub/tools/hwstub_shell.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp
index 082e15a..d0fcdfa 100644
--- a/utils/hwstub/tools/hwstub_shell.cpp
+++ b/utils/hwstub/tools/hwstub_shell.cpp
@@ -682,15 +682,22 @@ void usage(void)
printf("\n");
printf("usage: hwstub_tool [options] <soc desc files>\n");
printf("options:\n");
- printf(" --help/-?\tDisplay this help\n");
- printf(" --quiet/-q\tQuiet non-command messages\n");
- printf(" -i <init>\tSet lua init file (default is init.lua)\n");
+ printf(" --help/-? Display this help\n");
+ printf(" --quiet/-q Quiet non-command messages\n");
+ printf(" -i <init> Set lua init file (default is init.lua)\n");
+ printf(" -e <cmd> Execute <cmd> at startup\n");
+ printf(" -f <file> Execute <file> at startup\n");
+ printf("Relative order of -e and -f commands are preserved.\n");
+ printf("They are executed after init file.\n");
exit(1);
}
+enum exec_type { exec_cmd, exec_file };
+
int main(int argc, char **argv)
{
const char *lua_init = "init.lua";
+ std::vector< std::pair< exec_type, std::string > > startup_cmds;
// parse command line
while(1)
{
@@ -701,7 +708,7 @@ int main(int argc, char **argv)
{0, 0, 0, 0}
};
- int c = getopt_long(argc, argv, "?qi:", long_options, NULL);
+ int c = getopt_long(argc, argv, "?qi:e:f:", long_options, NULL);
if(c == -1)
break;
switch(c)
@@ -717,6 +724,12 @@ int main(int argc, char **argv)
case 'i':
lua_init = optarg;
break;
+ case 'e':
+ startup_cmds.push_back(std::make_pair(exec_cmd, std::string(optarg)));
+ break;
+ case 'f':
+ startup_cmds.push_back(std::make_pair(exec_file, std::string(optarg)));
+ break;
default:
abort();
}
@@ -843,6 +856,20 @@ int main(int argc, char **argv)
if(!g_quiet)
printf("Starting interactive lua session. Type 'help()' to get some help\n");
+ /** run startup commands */
+ for(size_t i = 0; i < startup_cmds.size(); i++)
+ {
+ bool ret = false;
+ if(!g_quiet)
+ printf("Running '%s'...\n", startup_cmds[i].second.c_str());
+ if(startup_cmds[i].first == exec_file)
+ ret = luaL_dofile(g_lua, startup_cmds[i].second.c_str());
+ else if(startup_cmds[i].first == exec_cmd)
+ ret = luaL_dostring(g_lua, startup_cmds[i].second.c_str());
+ if(ret)
+ printf("error: %s\n", lua_tostring(g_lua, -1));
+ }
+
// use readline to provide some history and completion
rl_bind_key('\t', rl_complete);
while(!g_exit)