Skip to content

Commit

Permalink
- Added support for help("topic")
Browse files Browse the repository at this point in the history
- Added help-text for topic "simulation", which outputs the simulation helptext


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15176 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 14, 2013
1 parent c052b64 commit b82a4f3
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 206 deletions.
3 changes: 2 additions & 1 deletion Compiler/FrontEnd/ModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ external "builtin";
annotation(preferredView="text");
end loadFile;

function loadString "Parses the data and merges the resulting AST with the
function loadString "Parses the data and merges the resulting AST with ithe
loaded AST.
If a filename is given, it is used to provide error-messages as if the string
was read in binary format from a file with the same name.
Expand Down Expand Up @@ -1019,6 +1019,7 @@ annotation(preferredView="text");
end saveAll;

function help "display the OpenModelica help text."
input String topic := "";
output String helpText;
external "builtin";
end help;
Expand Down
8 changes: 7 additions & 1 deletion Compiler/Script/CevalScript.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1947,12 +1947,18 @@ algorithm
then
(cache,Values.BOOL(true),st);

case (cache,env,"help",{},st as Interactive.SYMBOLTABLE(ast=p),_)
case (cache,env,"help",{Values.STRING("")},st as Interactive.SYMBOLTABLE(ast=p),_)
equation
str = Flags.printUsage();
then
(cache,Values.STRING(str),st);

case (cache,env,"help",{Values.STRING(str)},st as Interactive.SYMBOLTABLE(ast=p),_)
equation
str = Flags.printHelp({str});
then
(cache,Values.STRING(str),st);

case (cache,env,"saveModel",{Values.STRING(name),Values.CODE(Absyn.C_TYPENAME(classpath))},
(st as Interactive.SYMBOLTABLE(ast = p)),_)
equation
Expand Down
82 changes: 38 additions & 44 deletions Compiler/Util/Flags.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ algorithm
equation
values = List.map(inValues, System.tolower);
System.gettextInit(Util.if_(getConfigString(RUNNING_TESTSUITE) ==& "","C",getConfigString(LOCALE_FLAG)));
printHelp(values);
print(printHelp(values));
setConfigBool(HELP, true);
then
();
Expand Down Expand Up @@ -1572,75 +1572,67 @@ end getConfigEnum;
// Used by the print functions below to indent descriptions.
protected constant String descriptionIndent = " ";

protected function printHelp
public function printHelp
"Prints out help for the given list of topics."
input list<String> inTopics;
output String help;
algorithm
_ := matchcontinue (inTopics)
help := match (inTopics)
local
Util.TranslatableContent desc;
list<String> debug_flags, rest_topics;
String str,name;
list<String> debug_flags, rest_topics, strs;
String str,name,str1,str2,str3,str4,str5,str6,str7,str8;
ConfigFlag config_flag;

case {}
case {} then printUsage();

case {"simulation"}
equation
print(printUsage());
then
();
help = System.gettext("The simulation executable takes the following flags:\n") +& System.getSimulationHelpText(true);
then help;

case {"debug"}
equation
print(System.gettext("The debug flag takes a comma-separated list of flags which are used by the\ncompiler for debugging. Flags prefixed with - will be disabled.\n"));
print(System.gettext("The available flags are:\n\n"));
debug_flags = List.map(allDebugFlags, printDebugFlag);
str = stringAppendList(debug_flags);
print(str);
then
();
str1 = System.gettext("The debug flag takes a comma-separated list of flags which are used by the\ncompiler for debugging. Flags prefixed with - will be disabled.\n");
str2 = System.gettext("The available flags are:\n\n");
strs = List.map(allDebugFlags, printDebugFlag);
help = stringAppendList(str1 :: str2 :: strs);
then help;

case {"optmodules"}
equation
/* 80-char wrapped lines */
print(System.gettext("The +preOptModules flag sets the optimization modules which are used before the\nmatching and index reduction in the back end. These modules are specified as a\ncomma-separated list, where the valid modules are:\n\n"));
print(printFlagValidOptionsDesc(PRE_OPT_MODULES));
/* 80-char wrapped lines */
print(System.gettext("\nThe +matchingAlgorithm sets the method that is used for the matching algorithm,\nafter the pre optimization modules. Valid options are:\n\n"));
print(printFlagValidOptionsDesc(MATCHING_ALGORITHM));
print(System.gettext("\nThe +indexReductionMethod sets the method that is used for the index reduction,\nafter the pre optimization modules. Valid options are:\n\n"));
print(printFlagValidOptionsDesc(INDEX_REDUCTION_METHOD));
print(System.gettext("\nThe +postOptModules then sets the optimization modules which are used after the\nindex reduction, specified as a comma-separated list. The valid modules are:\n\n"));
print(printFlagValidOptionsDesc(POST_OPT_MODULES));
print("\n");
then
();
str1 = System.gettext("The +preOptModules flag sets the optimization modules which are used before the\nmatching and index reduction in the back end. These modules are specified as a\ncomma-separated list, where the valid modules are:\n\n");
str2 = printFlagValidOptionsDesc(PRE_OPT_MODULES);
str3 = System.gettext("\nThe +matchingAlgorithm sets the method that is used for the matching algorithm,\nafter the pre optimization modules. Valid options are:\n\n");
str4 = printFlagValidOptionsDesc(MATCHING_ALGORITHM);
str5 = System.gettext("\nThe +indexReductionMethod sets the method that is used for the index reduction,\nafter the pre optimization modules. Valid options are:\n\n");
str6 = printFlagValidOptionsDesc(INDEX_REDUCTION_METHOD);
str7 = System.gettext("\nThe +postOptModules then sets the optimization modules which are used after the\nindex reduction, specified as a comma-separated list. The valid modules are:\n\n");
str8 = printFlagValidOptionsDesc(POST_OPT_MODULES);
help = stringAppendList({str1,str2,str3,str4,str5,str6,str7,str8,"\n"});
then help;

case {str}
equation
(config_flag as CONFIG_FLAG(name=name,description=desc)) = List.getMemberOnTrue(str, allConfigFlags, matchConfigFlag);
str = Util.translateContent(desc);
str = " +" +& name +& " " +& str +& "\n";
str = stringAppendList(Util.stringWrap(str, 80, descriptionIndent));
print(str);
print("\n");
print(printFlagValidOptionsDesc(config_flag));
then ();
str2 = printFlagValidOptionsDesc(config_flag);
help = stringAppendList({str,"\n",str2});
then help;

case {str}
equation
print("I'm sorry, I don't know what " +& str +& " is.\n");
then
fail();
then "I'm sorry, I don't know what " +& str +& " is.\n";

case (str :: (rest_topics as _::_))
equation
printHelp({str});
print("\n");
printHelp(rest_topics);
then
();
str = printHelp({str}) +& "\n";
help = printHelp(rest_topics);
then str +& help;

end matchcontinue;
end match;
end printHelp;

public function printUsage
Expand All @@ -1649,12 +1641,13 @@ public function printUsage
algorithm
Print.clearBuf();
Print.printBuf("OpenModelica Compiler "); Print.printBuf(Settings.getVersionNr()); Print.printBuf("\n");
Print.printBuf(System.gettext("Copyright © 2012 Open Source Modelica Consortium (OSMC)\n"));
Print.printBuf(System.gettext("Copyright © 2013 Open Source Modelica Consortium (OSMC)\n"));
Print.printBuf(System.gettext("Distributed under OMSC-PL and GPL, see www.openmodelica.org\n\n"));
//Print.printBuf("Please check the System Guide for full information about flags.\n");
Print.printBuf(System.gettext("Usage: omc [-runtimeOptions +omcOptions] (Model.mo | Script.mos) [Libraries | .mo-files] \n* Libraries: Fully qualified names of libraries to load before processing Model or Script.\n The libraries should be separated by spaces: Lib1 Lib2 ... LibN.\n* runtimeOptions: call omc -help to see runtime options\n"));
Print.printBuf(System.gettext("\n* +omcOptions:\n"));
Print.printBuf(printAllConfigFlags()); Print.printBuf("\n");
Print.printBuf(printAllConfigFlags());
Print.printBuf(System.gettext("For more details on a specific topic, use +help=topic or help(\"topic\")\n\n"));
Print.printBuf(System.gettext("* Examples:\n"));
Print.printBuf(System.gettext(" omc Model.mo will produce flattened Model on standard output\n"));
Print.printBuf(System.gettext(" omc +s Model.mo will produce simulation code for the model:\n"));
Expand All @@ -1669,6 +1662,7 @@ algorithm
Print.printBuf(System.gettext(" *.mo (Modelica files) \n"));
//Print.printBuf("\t*.mof (Flat Modelica files) \n");
Print.printBuf(System.gettext(" *.mos (Modelica Script files)\n\n"));
Print.printBuf(System.gettext("For available simulation flags, use +help=simulation\n\n"));
Print.printBuf(System.gettext("Documentation is available in the built-in package OpenModelica.Scripting or\nonline <https://build.openmodelica.org/Documentation/OpenModelica.Scripting.html>\n"));
usage := Print.getString();
Print.clearBuf();
Expand Down
6 changes: 6 additions & 0 deletions Compiler/Util/System.mo
Original file line number Diff line number Diff line change
Expand Up @@ -986,4 +986,10 @@ public function realpath
external "C" fullpath = System_realpath(path) annotation(Library = {"omcruntime"});
end realpath;

public function getSimulationHelpText
input Boolean detailed;
output String text;
external "C" text = System_getSimulationHelpText(detailed) annotation(Library = {"omcruntime"});
end getSimulationHelpText;

end System;
7 changes: 6 additions & 1 deletion Compiler/runtime/System_rml.c
Original file line number Diff line number Diff line change
Expand Up @@ -2150,4 +2150,9 @@ RML_BEGIN_LABEL(System__realpath)
}
RML_END_LABEL


RML_BEGIN_LABEL(System__getSimulationHelpText)
{
rmlA0 = mk_scon(System_getSimulationHelpText(RML_UNTAGFIXNUM(rmlA0)));
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
23 changes: 23 additions & 0 deletions Compiler/runtime/systemimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,30 @@ char *realpath(const char *path, char resolved_path[PATH_MAX])
}
#endif

#include "simulation_options.h"

char* System_getSimulationHelpText(int detailed)
{
static char buf[8192];
int i;
char **desc = detailed ? FLAG_DETAILED_DESC : FLAG_DESC;
char *cur = buf;
*cur = 0;
for(i=1; i<FLAG_MAX; ++i)
{
if (FLAG_TYPE[i] == FLAG_TYPE_FLAG) {
cur += snprintf(cur, 8191-(buf-cur), "<-%s>\n %s\n", FLAG_NAME[i], desc[i]);
} else if (FLAG_TYPE[i] == FLAG_TYPE_OPTION) {
cur += snprintf(cur, 8191-(buf-cur), "<-%s=value>\n %s\n", FLAG_NAME[i], desc[i]);
} else if (FLAG_TYPE[i] == FLAG_TYPE_FLAG_VALUE) {
cur += snprintf(cur, 8191-(buf-cur), "<-%s value>\n %s\n", FLAG_NAME[i], desc[i]);
} else {
cur += snprintf(cur, 8191-(buf-cur), "[unknown flag-type] <-%s>\n", FLAG_NAME[i]);
}
}
*cur = 0;
return buf;
}

#ifdef __cplusplus
}
Expand Down
112 changes: 0 additions & 112 deletions SimulationRuntime/c/simulation/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,118 +35,6 @@

using namespace std;

const char *FLAG_NAME[FLAG_MAX] = {
"LOG_UNKNOWN",

/* FLAG_CPU */ "cpu",
/* FLAG_F */ "f",
/* FLAG_HELP */ "help",
/* FLAG_IIF */ "iif",
/* FLAG_IIM */ "iim",
/* FLAG_IIT */ "iit",
/* FLAG_ILS */ "ils",
/* FLAG_INTERACTIVE */ "interactive",
/* FLAG_IOM */ "iom",
/* FLAG_JAC */ "jac",
/* FLAG_L */ "l",
/* FLAG_LV */ "lv",
/* FLAG_MEASURETIMEPLOTFORMAT */ "measureTimePlotFormat",
/* FLAG_NLS */ "nls",
/* FLAG_NOEMIT */ "noemit",
/* FLAG_NUMJAC */ "numjac",
/* FLAG_OUTPUT */ "output",
/* FLAG_OVERRIDE */ "override",
/* FLAG_OVERRIDE_FILE */ "overrideFile",
/* FLAG_PORT */ "port",
/* FLAG_R */ "r",
/* FLAG_S */ "s",
/* FLAG_W */ "w"
};

const char *FLAG_DESC[FLAG_MAX] = {
"unknown",

/* FLAG_CPU */ "dumps the cpu-time into the results-file",
/* FLAG_F */ "value specifies a new setup XML file to the generated simulation code",
/* FLAG_HELP */ "get deteiled information the specifies the command-line flag",
/* FLAG_IIF */ "value specifies an external file for the initialization of the model",
/* FLAG_IIM */ "value specifies the initialization method",
/* FLAG_IIT */ "[double] value specifies a time for the initialization of the model",
/* FLAG_ILS */ "[int] value specifies the number of steps for the global homotopy method (required: -iim=numeric -iom=nelder_mead_ex)",
/* FLAG_INTERACTIVE */ "specify interactive simulation",
/* FLAG_IOM */ "value specifies the initialization optimization method",
/* FLAG_JAC */ "specify jacobian",
/* FLAG_L */ "value specifies a time where the linearization of the model should be performed",
/* FLAG_LV */ "[string list] value specifies the logging level",
/* FLAG_MEASURETIMEPLOTFORMAT */ "value specifies the output format of the measure time functionality",
/* FLAG_NLS */ "value specifies the nonlinear solver",
/* FLAG_NOEMIT */ "do not emit any results to the result file",
/* FLAG_NUMJAC */ "specify numerical jacobian",
/* FLAG_OUTPUT */ "output the variables a, b and c at the end of the simulation to the standard output",
/* FLAG_OVERRIDE */ "override the variables or the simulation settings in the XML setup file",
/* FLAG_OVERRIDE_FILE */ "will override the variables or the simulation settings in the XML setup file with the values from the file",
/* FLAG_PORT */ "value specifies interactive simulation port",
/* FLAG_R */ "value specifies a new result file than the default Model_res.mat",
/* FLAG_S */ "value specifies the solver",
/* FLAG_W */ "shows all warnings even if a related log-stream is inactive"
};

const char *FLAG_DETAILED_DESC[FLAG_MAX] = {
"unknown",

/* FLAG_CPU */ " - dumps the cpu-time into the result-file\n - $cpuTime is the variable name inside the result-file",
/* FLAG_F */ "value specifies a new setup XML file to the generated simulation code",
/* FLAG_HELP */ "get deteiled information the specifies the command-line flag\n e.g. -help=f prints detaild information for command-line flag f",
/* FLAG_IIF */ "value specifies an external file for the initialization of the model",
/* FLAG_IIM */ "value specifies the initialization method\n none\n numeric\n symbolic",
/* FLAG_IIT */ "value specifies a time for the initialization of the model",
/* FLAG_ILS */ "value specifies the number of steps for the global homotopy method (required: -iim=numeric -iom=nelder_mead_ex)",
/* FLAG_INTERACTIVE */ "specify interactive simulation",
/* FLAG_IOM */ "value specifies the initialization optimization method\n nelder_mead_ex\n nelder_mead_ex2\n simplex\n newuoa",
/* FLAG_JAC */ "specify jacobian",
/* FLAG_L */ "value specifies a time where the linearization of the model should be performed",
/* FLAG_LV */ "value specifies the logging level",
/* FLAG_MEASURETIMEPLOTFORMAT */ "value specifies the output format of the measure time functionality\n svg\n jpg\n ps\n gif\n ...",
/* FLAG_NLS */ "value specifies the nonlinear solver",
/* FLAG_NOEMIT */ "do not emit any results to the result file",
/* FLAG_NUMJAC */ "specify numerical jacobian",
/* FLAG_OUTPUT */ "output the variables a, b and c at the end of the simulation to the standard output\n time = value, a = value, b = value, c = value",
/* FLAG_OVERRIDE */ "override the variables or the simulation settings in the XML setup file\n e.g. var1=start1,var2=start2,par3=start3,startTime=val1,stopTime=val2,stepSize=val3,\n tolerance=val4,solver=\"see -s\",outputFormat=\"mat|plt|csv|empty\",variableFilter=\"filter\"",
/* FLAG_OVERRIDE_FILE */ "will override the variables or the simulation settings in the XML setup file with the values from the file\n note that: -overrideFile CANNOT be used with -override\n use when variables for -override are too many and do not fit in command line size\n overrideFileName contains lines of the form: var1=start1",
/* FLAG_PORT */ "value specifies interactive simulation port",
/* FLAG_R */ "value specifies a new result file than the default Model_res.mat",
/* FLAG_S */ "value specifies the solver\n dassl\n euler\n rungekutta\n inline-euler\n inline-rungekutta\n dasslwort\n dasslSymJac\n dasslNumJac\n dasslColorSymJac\n dasslInternalNumJac\n qss",
/* FLAG_W */ "shows all warnings even if a related log-stream is inactive"
};

const int FLAG_TYPE[FLAG_MAX] = {
FLAG_TYPE_UNKNOWN,

/* FLAG_CPU */ FLAG_TYPE_FLAG,
/* FLAG_F */ FLAG_TYPE_OPTION,
/* FLAG_HELP */ FLAG_TYPE_OPTION,
/* FLAG_IIF */ FLAG_TYPE_OPTION,
/* FLAG_IIM */ FLAG_TYPE_OPTION,
/* FLAG_IIT */ FLAG_TYPE_OPTION,
/* FLAG_ILS */ FLAG_TYPE_OPTION,
/* FLAG_INTERACTIVE */ FLAG_TYPE_FLAG,
/* FLAG_IOM */ FLAG_TYPE_OPTION,
/* FLAG_JAC */ FLAG_TYPE_FLAG,
/* FLAG_L */ FLAG_TYPE_OPTION,
/* FLAG_LV */ FLAG_TYPE_OPTION,
/* FLAG_MEASURETIMEPLOTFORMAT */ FLAG_TYPE_OPTION,
/* FLAG_NLS */ FLAG_TYPE_OPTION,
/* FLAG_NOEMIT */ FLAG_TYPE_FLAG,
/* FLAG_NUMJAC */ FLAG_TYPE_FLAG,
/* FLAG_OUTPUT */ FLAG_TYPE_FLAG_VALUE,
/* FLAG_OVERRIDE */ FLAG_TYPE_FLAG_VALUE,
/* FLAG_OVERRIDE_FILE */ FLAG_TYPE_FLAG_VALUE,
/* FLAG_PORT */ FLAG_TYPE_OPTION,
/* FLAG_R */ FLAG_TYPE_OPTION,
/* FLAG_S */ FLAG_TYPE_OPTION,
/* FLAG_W */ FLAG_TYPE_FLAG
};

int checkCommandLineArguments(int argc, char **argv)
{
for(int i=1; i<argc; ++i)
Expand Down

0 comments on commit b82a4f3

Please sign in to comment.