cmd line args -exit cmd_file (flush -x, -f)

This commit is contained in:
James Cherry 2019-06-14 16:53:03 -07:00
parent 154dcf0042
commit c66da2935f
6 changed files with 71 additions and 36 deletions

View File

@ -16,7 +16,7 @@
cmake_minimum_required (VERSION 3.9) cmake_minimum_required (VERSION 3.9)
project(STA VERSION 2.0.15) project(STA VERSION 2.0.16)
set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)

View File

@ -37,7 +37,7 @@ extern const char *tcl_inits[];
int int
main(int argc, main(int argc,
char **argv) char *argv[])
{ {
if (argc == 2 && stringEq(argv[1], "-help")) { if (argc == 2 && stringEq(argv[1], "-help")) {
showUseage(argv[0]); showUseage(argv[0]);

View File

@ -37,7 +37,7 @@ static const char *init_filename = "[file join $env(HOME) .sta]";
void void
staMain(Sta *sta, staMain(Sta *sta,
int argc, int argc,
char **argv, char *argv[],
SwigInitFunc swig_init, SwigInitFunc swig_init,
const char *tcl_inits[]) const char *tcl_inits[])
{ {
@ -82,7 +82,7 @@ parseThreadsArg(int argc,
// Set globals to pass to staTclAppInit. // Set globals to pass to staTclAppInit.
void void
staSetupAppInit(int argc, staSetupAppInit(int argc,
char **argv, char *argv[],
SwigInitFunc swig_init, SwigInitFunc swig_init,
const char *tcl_inits[]) const char *tcl_inits[])
{ {
@ -121,43 +121,65 @@ staTclAppInit(Tcl_Interp *interp)
if (!findCmdLineFlag(argc, argv, "-no_init")) if (!findCmdLineFlag(argc, argv, "-no_init"))
sourceTclFile(init_filename, true, true, interp); sourceTclFile(init_filename, true, true, interp);
// "-x cmd" is evaled before -f file is sourced. bool exit_after_cmd_file = findCmdLineFlag(argc, argv, "-exit");
char *cmd = findCmdLineKey(argc, argv, "-x");
if (cmd)
Tcl_Eval(interp, cmd);
// "-f cmd_file" is evaled as "source -echo -verbose file".
char *file = findCmdLineKey(argc, argv, "-f");
if (file)
sourceTclFile(file, true, true, interp);
if (argc > 2 ||
(argc > 1 && argv[1][0] == '-'))
showUseage(argv[0]);
else {
if (argc == 2) {
char *cmd_file = argv[1];
if (cmd_file) {
sourceTclFile(cmd_file, false, false, interp);
if (exit_after_cmd_file)
exit(EXIT_SUCCESS);
}
}
}
return TCL_OK; return TCL_OK;
} }
bool bool
findCmdLineFlag(int argc, findCmdLineFlag(int &argc,
char **argv, char *argv[],
const char *flag) const char *flag)
{ {
for (int argi = 1; argi < argc; argi++) { bool found = false;
char *arg = argv[argi]; int j = 1;
if (stringEq(arg, flag)) int argc1 = argc;
return true; for (int i = 1; i < argc1; i++) {
char *arg = argv[i];
if (stringEq(arg, flag)) {
found = true;
// remove flag from argv.
argc--;
}
else
argv[j++] = argv[i];
} }
return false; return found;
} }
char * char *
findCmdLineKey(int argc, findCmdLineKey(int &argc,
char **argv, char *argv[],
const char *key) const char *key)
{ {
for (int argi = 1; argi < argc; argi++) { char *value = nullptr;
char *arg = argv[argi]; int j = 1;
if (stringEq(arg, key) && argi + 1 < argc) int argc1 = argc;
return argv[argi + 1]; for (int i = 1; i < argc1; i++) {
char *arg = argv[i];
if (stringEq(arg, key) && i + 1 < argc) {
value = argv[i + 1];
// remove key and value from argv.
i++;
argc -= 2;
}
else
argv[j++] = argv[i];
} }
return nullptr; return value;
} }
// Use overridden version of source to echo cmds and results. // Use overridden version of source to echo cmds and results.
@ -210,14 +232,14 @@ evalTclInit(Tcl_Interp *interp,
void void
showUseage(char *prog) showUseage(char *prog)
{ {
printf("Usage: %s [-help] [-version] [-no_init] [-f cmd_file]\n", prog); printf("Usage: %s [-help] [-version] [-no_init] [-exit] cmd_file\n", prog);
printf(" -help show help and exit\n"); printf(" -help show help and exit\n");
printf(" -version show version and exit\n"); printf(" -version show version and exit\n");
printf(" -no_init do not read .sta init file\n"); printf(" -no_init do not read .sta init file\n");
printf(" -x cmd evaluate cmd\n");
printf(" -f cmd_file source cmd_file\n");
printf(" -threads count|max use count threads\n"); printf(" -threads count|max use count threads\n");
printf(" -no_splash do not show the license splash at startup\n"); printf(" -no_splash do not show the license splash at startup\n");
printf(" -exit exit after reading cmd_file\n");
printf(" cmd_file source cmd_file\n");
} }
} // namespace } // namespace

View File

@ -29,14 +29,14 @@ typedef int (*SwigInitFunc)(Tcl_Interp *);
void void
staMain(Sta *sta, staMain(Sta *sta,
int argc, int argc,
char **argv, char *argv[],
SwigInitFunc swig_init, SwigInitFunc swig_init,
const char *tcl_inits[]); const char *tcl_inits[]);
// Set arguments passed to staTclAppInit inside the tcl interpreter. // Set arguments passed to staTclAppInit inside the tcl interpreter.
void void
staSetupAppInit(int argc, staSetupAppInit(int argc,
char **argv, char *argv[],
SwigInitFunc swig_init, SwigInitFunc swig_init,
const char *tcl_inits[]); const char *tcl_inits[]);
@ -53,12 +53,12 @@ evalTclInit(Tcl_Interp *interp,
const char *inits[]); const char *inits[]);
bool bool
findCmdLineFlag(int argc, findCmdLineFlag(int &argc,
char **argv, char *argv[],
const char *flag); const char *flag);
char * char *
findCmdLineKey(int argc, findCmdLineKey(int &argc,
char **argv, char *argv[],
const char *key); const char *key);
void void

View File

@ -6,6 +6,19 @@ This file summarizes user visible changes for each release.
Release 2.0.0 2018/09/28 Release 2.0.0 2018/09/28
------------------------- -------------------------
The command line options have changed to the following:
-help show help and exit
-version show version and exit
-no_init do not read .sta init file
-threads count|max use count threads
-no_splash do not show the license splash at startup
-exit exit after reading cmd_file
cmd_file source cmd_file
....
Builds using Autotools/configure are no longer supported. Builds using Autotools/configure are no longer supported.
Use CMake as documented in README.mb. Use CMake as documented in README.mb.

Binary file not shown.