add support for and apply clang-format to lammps-shell code

This commit is contained in:
Axel Kohlmeyer
2021-11-04 15:55:28 -04:00
parent 2cd862e4a2
commit 1a940e052e
2 changed files with 16 additions and 20 deletions

View File

@ -0,0 +1 @@
../../unittest/.clang-format

View File

@ -10,8 +10,8 @@
#include "utils.h"
#include <cstring>
#include <iostream>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
@ -342,14 +342,13 @@ static char *plugin_generator(const char *text, int state)
{
const char *subcmd[] = {"load", "unload", "list", "clear", nullptr};
const char *sub;
static std::size_t idx=0, len;
static std::size_t idx = 0, len;
if (!state) idx = 0;
len = strlen(text);
while ((sub = subcmd[idx]) != nullptr) {
++idx;
if (strncmp(text,sub,len) == 0)
return dupstring(sub);
if (strncmp(text, sub, len) == 0) return dupstring(sub);
}
return nullptr;
}
@ -358,13 +357,12 @@ static char *plugin_style_generator(const char *text, int state)
{
const char *styles[] = {"pair", "fix", "command", nullptr};
const char *s;
static std::size_t idx=0, len;
static std::size_t idx = 0, len;
if (!state) idx = 0;
len = strlen(text);
while ((s = styles[idx]) != nullptr) {
++idx;
if (strncmp(text,s,len) == 0)
return dupstring(s);
if (strncmp(text, s, len) == 0) return dupstring(s);
}
return nullptr;
}
@ -384,8 +382,7 @@ static char *plugin_name_generator(const char *text, int state)
lammps_plugin_name(idx, style, name, BUFLEN);
++idx;
if (words[2] == style) {
if (strncmp(name, words[3].c_str(), len) == 0)
return dupstring(name);
if (strncmp(name, words[3].c_str(), len) == 0) return dupstring(name);
}
}
return nullptr;
@ -527,9 +524,7 @@ static char **cmd_completion(const char *text, int start, int)
} else if (words.size() == 2) { // expand third word
// these commands have a group name as 3rd word
if ((words[0] == "fix")
|| (words[0] == "compute")
|| (words[0] == "dump")) {
if ((words[0] == "fix") || (words[0] == "compute") || (words[0] == "dump")) {
matches = rl_completion_matches(text, group_generator);
} else if (words[0] == "region") {
matches = rl_completion_matches(text, region_generator);
@ -736,7 +731,7 @@ int main(int argc, char **argv)
// switch to the user's documents directory.
auto curdir = platform::current_directory();
if (utils::strmatch(curdir,"[Ss]ystem32")) {
if (utils::strmatch(curdir, "[Ss]ystem32")) {
std::string docdir = getenv("HOMEDRIVE");
docdir += getenv("HOMEPATH");
docdir += "\\Documents";