diff options
-rw-r--r-- | utils/hwstub/tools/hwstub_shell.cpp | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/utils/hwstub/tools/hwstub_shell.cpp b/utils/hwstub/tools/hwstub_shell.cpp index 082e15aa59..d0fcdfabc2 100644 --- a/utils/hwstub/tools/hwstub_shell.cpp +++ b/utils/hwstub/tools/hwstub_shell.cpp | |||
@@ -682,15 +682,22 @@ void usage(void) | |||
682 | printf("\n"); | 682 | printf("\n"); |
683 | printf("usage: hwstub_tool [options] <soc desc files>\n"); | 683 | printf("usage: hwstub_tool [options] <soc desc files>\n"); |
684 | printf("options:\n"); | 684 | printf("options:\n"); |
685 | printf(" --help/-?\tDisplay this help\n"); | 685 | printf(" --help/-? Display this help\n"); |
686 | printf(" --quiet/-q\tQuiet non-command messages\n"); | 686 | printf(" --quiet/-q Quiet non-command messages\n"); |
687 | printf(" -i <init>\tSet lua init file (default is init.lua)\n"); | 687 | printf(" -i <init> Set lua init file (default is init.lua)\n"); |
688 | printf(" -e <cmd> Execute <cmd> at startup\n"); | ||
689 | printf(" -f <file> Execute <file> at startup\n"); | ||
690 | printf("Relative order of -e and -f commands are preserved.\n"); | ||
691 | printf("They are executed after init file.\n"); | ||
688 | exit(1); | 692 | exit(1); |
689 | } | 693 | } |
690 | 694 | ||
695 | enum exec_type { exec_cmd, exec_file }; | ||
696 | |||
691 | int main(int argc, char **argv) | 697 | int main(int argc, char **argv) |
692 | { | 698 | { |
693 | const char *lua_init = "init.lua"; | 699 | const char *lua_init = "init.lua"; |
700 | std::vector< std::pair< exec_type, std::string > > startup_cmds; | ||
694 | // parse command line | 701 | // parse command line |
695 | while(1) | 702 | while(1) |
696 | { | 703 | { |
@@ -701,7 +708,7 @@ int main(int argc, char **argv) | |||
701 | {0, 0, 0, 0} | 708 | {0, 0, 0, 0} |
702 | }; | 709 | }; |
703 | 710 | ||
704 | int c = getopt_long(argc, argv, "?qi:", long_options, NULL); | 711 | int c = getopt_long(argc, argv, "?qi:e:f:", long_options, NULL); |
705 | if(c == -1) | 712 | if(c == -1) |
706 | break; | 713 | break; |
707 | switch(c) | 714 | switch(c) |
@@ -717,6 +724,12 @@ int main(int argc, char **argv) | |||
717 | case 'i': | 724 | case 'i': |
718 | lua_init = optarg; | 725 | lua_init = optarg; |
719 | break; | 726 | break; |
727 | case 'e': | ||
728 | startup_cmds.push_back(std::make_pair(exec_cmd, std::string(optarg))); | ||
729 | break; | ||
730 | case 'f': | ||
731 | startup_cmds.push_back(std::make_pair(exec_file, std::string(optarg))); | ||
732 | break; | ||
720 | default: | 733 | default: |
721 | abort(); | 734 | abort(); |
722 | } | 735 | } |
@@ -843,6 +856,20 @@ int main(int argc, char **argv) | |||
843 | if(!g_quiet) | 856 | if(!g_quiet) |
844 | printf("Starting interactive lua session. Type 'help()' to get some help\n"); | 857 | printf("Starting interactive lua session. Type 'help()' to get some help\n"); |
845 | 858 | ||
859 | /** run startup commands */ | ||
860 | for(size_t i = 0; i < startup_cmds.size(); i++) | ||
861 | { | ||
862 | bool ret = false; | ||
863 | if(!g_quiet) | ||
864 | printf("Running '%s'...\n", startup_cmds[i].second.c_str()); | ||
865 | if(startup_cmds[i].first == exec_file) | ||
866 | ret = luaL_dofile(g_lua, startup_cmds[i].second.c_str()); | ||
867 | else if(startup_cmds[i].first == exec_cmd) | ||
868 | ret = luaL_dostring(g_lua, startup_cmds[i].second.c_str()); | ||
869 | if(ret) | ||
870 | printf("error: %s\n", lua_tostring(g_lua, -1)); | ||
871 | } | ||
872 | |||
846 | // use readline to provide some history and completion | 873 | // use readline to provide some history and completion |
847 | rl_bind_key('\t', rl_complete); | 874 | rl_bind_key('\t', rl_complete); |
848 | while(!g_exit) | 875 | while(!g_exit) |