FC Updates from BitShares and myself #21

Closed
nathanielhourt wants to merge 687 commits from dapp-support into latest-fc
Showing only changes of commit 628548ca02 - Show all commits

View file

@ -114,57 +114,75 @@ void cli::run()
/**** /****
* @brief loop through list of commands, attempting to find a match * @brief loop through list of commands, attempting to find a match
* @param token what the user typed * @param token what the user typed
* @param match * @param match sets to 1 if only 1 match was found
* @returns the full name of the command or NULL if no matches found * @returns the remaining letters of the name of the command or NULL if 1 match not found
*/ */
static char *my_rl_complete(char *token, int *match) static char *my_rl_complete(char *token, int *match)
{ {
int matchlen = 0; bool have_one = false;
int count = 0; std::string method_name;
const char* method_name;
auto& cmd = cli_commands(); auto& cmd = cli_commands();
int partlen = strlen (token); /* Part of token */ int partlen = strlen (token); /* Part of token */
for (auto it : cmd) {
if (!strncmp (it.c_str(), token, partlen)) {
method_name = it.c_str();
matchlen = partlen;
count ++;
}
}
if (count == 1) { for (const std::string& it : cmd)
*match = 1; {
return strdup (method_name + matchlen); if (it.compare(0, partlen, token) == 0)
} {
if (have_one) {
// we can only have 1, but we found a second
return NULL;
}
else
{
method_name = it;
have_one = true;
}
}
}
return NULL; if (have_one)
{
*match = 1;
method_name += " ";
return strdup (method_name.c_str() + partlen);
}
return NULL;
} }
/*** /***
* @brief return an array of matching commands * @brief return an array of matching commands
* @param token the incoming text * @param token the incoming text
* @param av the resultant array of possible matches * @param array the resultant array of possible matches
* @returns the number of matches * @returns the number of matches
*/ */
static int cli_completion(char *token, char ***av) static int cli_completion(char *token, char ***array)
{ {
int num, total = 0; auto& cmd = cli_commands();
char **copy; int num_commands = cmd.size();
auto& cmd = cli_commands(); char **copy = (char **) malloc (num_commands * sizeof(char *));
num = cmd.size(); if (copy == NULL)
{
// possible out of memory
return 0;
}
int total_matches = 0;
copy = (char **) malloc (num * sizeof(char *)); int partlen = strlen(token);
for (auto it : cmd) {
if (!strncmp (it.c_str(), token, strlen (token))) {
copy[total] = strdup ( it.c_str() );
total ++;
}
}
*av = copy;
return total; for (const std::string& it : cmd)
{
if ( it.compare(0, partlen, token) == 0)
{
copy[total_matches] = strdup ( it.c_str() );
++total_matches;
}
}
*array = copy;
return total_matches;
} }
/*** /***
@ -198,9 +216,17 @@ void cli::getline( const fc::string& prompt, fc::string& line)
line_read = readline(prompt.c_str()); line_read = readline(prompt.c_str());
if( line_read == nullptr ) if( line_read == nullptr )
FC_THROW_EXCEPTION( fc::eof_exception, "" ); FC_THROW_EXCEPTION( fc::eof_exception, "" );
if( *line_read )
add_history(line_read);
line = line_read; line = line_read;
try
{
if (*line_read)
add_history(line_read);
}
catch(...)
{
free(line_read);
throw;
}
free(line_read); free(line_read);
}).wait(); }).wait();
} }