742 map<string, string> macros;
743 vector<int> errorLineNumbers;
744 vector<string> errorCommands;
749 handleCommandLineArguments(argc, argv, opt);
751 if (opt.getArgc() != 0) {
752 return processCommand(madeEasy, opt);
756 bool echoCommand = opt.getFlag(
"echocommand") || opt.getFlag(
"test");
757 bool echoExpand = opt.getFlag(
"echoexpand") || opt.getFlag(
"test");
758 bool noPrompt = opt.getFlag(
"noprompt") || opt.getFlag(
"test");
763 cout <<
"\nopentxs> ";
781 if (cmd ==
"quit" || cmd ==
"exit") {
787 if (cmd.size() == 0 || cmd[0] ==
'#') {
791 string originalCmd = cmd;
810 size_t nameLength = 1;
811 while (nameLength < cmd.length() &&
812 (isalnum(cmd[nameLength]) || cmd[nameLength] ==
'_')) {
815 string macroName = cmd.substr(0, nameLength);
818 size_t i = nameLength;
819 while (i < cmd.length() && isspace(cmd[i])) {
823 if (i == cmd.length() || cmd[i] !=
'=') {
824 otOut <<
"\n\n***ERROR***\n"
825 "Expected macro definition of the form: "
826 "$macroName = macroValue\n"
827 "Command was: " << cmd;
832 string macroValue = cmd.substr(i + 1);
833 macros[macroName] = trim(macroValue);
842 for (
size_t macro = cmd.find_first_of(
"$"); macro != string::npos;
843 macro = cmd.find_first_of(
"$", macro + 1)) {
845 if (macro > 0 && cmd[macro - 1] ==
'\\') {
850 size_t macroEnd = macro + 1;
851 while (macroEnd < cmd.length() &&
852 (isalnum(cmd[macroEnd]) || cmd[macroEnd] ==
'_')) {
857 string macroName = cmd.substr(macro, macroEnd - macro);
858 auto found = macros.find(macroName);
859 if (found == macros.end()) {
860 otOut <<
"\n\n***ERROR***\n"
861 "Macro expansion failed.\n"
862 "Unknown macro: " << macroName
864 "Command was: " << cmd;
869 string& macroValue = found->second;
873 if (expansions > 100) {
874 otOut <<
"\n\n***ERROR***\n"
875 "Macro expansion failed.\n"
876 "Too many expansions at macro: " << macroName
878 "Command was: " << cmd;
883 if (cmd.length() + macroValue.length() > 10000) {
884 otOut <<
"\n\n***ERROR***\n"
885 "Macro expansion failed.\n"
886 "Command length exceeded at macro: " << macroName
888 "Macro value is: " << macroValue
890 "Command was: " << cmd;
896 cmd = cmd.substr(0, macro) + macroValue + cmd.substr(macroEnd);
899 if (echoExpand && cmd != originalCmd) {
900 otOut << cmd << endl;
904 if (expansions > 99) {
910 bool expectFailure = cmd[0] ==
'!';
921 vector<string> arguments;
924 arguments.push_back(argv[0]);
927 char* buf =
new char[cmd.length() + 1];
931 size_t i = expectFailure ? 1 : 0;
932 while (i < cmd.length()) {
934 while (i < cmd.length() && isspace(cmd[i])) {
937 if (i == cmd.length()) {
948 while (i < cmd.length() && !isspace(cmd[i])) {
950 if (cmd[i] !=
'\\') {
959 *arg++ = i < cmd.length() ? cmd[i++] :
'\\';
964 arguments.push_back(start);
974 while (i < cmd.length() && cmd[i] !=
'"') {
976 if (cmd[i] !=
'\\') {
985 *arg++ = i < cmd.length() ? cmd[i++] :
'\\';
990 arguments.push_back(start);
997 int newArgc = arguments.size();
998 char** newArgv =
new char* [newArgc];
999 for (
int i = 0; i < newArgc; i++) {
1000 newArgv[i] =
const_cast<char*
>(arguments[i].c_str());
1005 handleCommandLineArguments(newArgc, newArgv, opt);
1008 if (expectFailure != (0 != processCommand(madeEasy, opt))) {
1009 errorLineNumbers.push_back(lineNumber);
1010 errorCommands.push_back(originalCmd);
1011 otOut <<
"\n\n***ERROR***\n"
1012 << (expectFailure ?
"Expected command to fail.\nSucceeding"
1013 :
"Failed") <<
" command was: " << cmd;
1023 int failed = errorLineNumbers.size();
1024 cout <<
"\n\n" << processed <<
" commands were processed.\n" << failed
1025 <<
" commands failed.\n" << endl;
1027 if (opt.getFlag(
"errorList") || opt.getFlag(
"test")) {
1028 for (
size_t i = 0; i < errorLineNumbers.size(); i++) {
1029 cout <<
"\nFailed line " << errorLineNumbers[i] <<
": "
1030 << errorCommands[i] << endl;
1034 return failed == 0 ? 0 : -1;
OTLOG_IMPORT OTLogStream otOut
EXPORT bool LoadWallet() const
static EXPORT OT_API * OTAPI()