diff --git a/src/input.cpp b/src/input.cpp index b8f4641d40..4a3b470532 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -749,77 +749,78 @@ int Input::execute_command() { int flag = 1; - if (!strcmp(command,"clear")) clear(); - else if (!strcmp(command,"echo")) echo(); - else if (!strcmp(command,"if")) ifthenelse(); - else if (!strcmp(command,"include")) include(); - else if (!strcmp(command,"jump")) jump(); - else if (!strcmp(command,"label")) label(); - else if (!strcmp(command,"log")) log(); - else if (!strcmp(command,"next")) next_command(); - else if (!strcmp(command,"partition")) partition(); - else if (!strcmp(command,"print")) print(); - else if (!strcmp(command,"python")) python(); - else if (!strcmp(command,"quit")) quit(); - else if (!strcmp(command,"shell")) shell(); - else if (!strcmp(command,"variable")) variable_command(); + std::string mycmd = command; + if (mycmd == "clear") clear(); + else if (mycmd == "echo") echo(); + else if (mycmd == "if") ifthenelse(); + else if (mycmd == "include") include(); + else if (mycmd == "jump") jump(); + else if (mycmd == "label") label(); + else if (mycmd == "log") log(); + else if (mycmd == "next") next_command(); + else if (mycmd == "partition") partition(); + else if (mycmd == "print") print(); + else if (mycmd == "python") python(); + else if (mycmd == "quit") quit(); + else if (mycmd == "shell") shell(); + else if (mycmd == "variable") variable_command(); - else if (!strcmp(command,"angle_coeff")) angle_coeff(); - else if (!strcmp(command,"angle_style")) angle_style(); - else if (!strcmp(command,"atom_modify")) atom_modify(); - else if (!strcmp(command,"atom_style")) atom_style(); - else if (!strcmp(command,"bond_coeff")) bond_coeff(); - else if (!strcmp(command,"bond_style")) bond_style(); - else if (!strcmp(command,"bond_write")) bond_write(); - else if (!strcmp(command,"boundary")) boundary(); - else if (!strcmp(command,"box")) box(); - else if (!strcmp(command,"comm_modify")) comm_modify(); - else if (!strcmp(command,"comm_style")) comm_style(); - else if (!strcmp(command,"compute")) compute(); - else if (!strcmp(command,"compute_modify")) compute_modify(); - else if (!strcmp(command,"dielectric")) dielectric(); - else if (!strcmp(command,"dihedral_coeff")) dihedral_coeff(); - else if (!strcmp(command,"dihedral_style")) dihedral_style(); - else if (!strcmp(command,"dimension")) dimension(); - else if (!strcmp(command,"dump")) dump(); - else if (!strcmp(command,"dump_modify")) dump_modify(); - else if (!strcmp(command,"fix")) fix(); - else if (!strcmp(command,"fix_modify")) fix_modify(); - else if (!strcmp(command,"group")) group_command(); - else if (!strcmp(command,"improper_coeff")) improper_coeff(); - else if (!strcmp(command,"improper_style")) improper_style(); - else if (!strcmp(command,"kspace_modify")) kspace_modify(); - else if (!strcmp(command,"kspace_style")) kspace_style(); - else if (!strcmp(command,"labelmap")) labelmap(); - else if (!strcmp(command,"lattice")) lattice(); - else if (!strcmp(command,"mass")) mass(); - else if (!strcmp(command,"min_modify")) min_modify(); - else if (!strcmp(command,"min_style")) min_style(); - else if (!strcmp(command,"molecule")) molecule(); - else if (!strcmp(command,"neigh_modify")) neigh_modify(); - else if (!strcmp(command,"neighbor")) neighbor_command(); - else if (!strcmp(command,"newton")) newton(); - else if (!strcmp(command,"package")) package(); - else if (!strcmp(command,"pair_coeff")) pair_coeff(); - else if (!strcmp(command,"pair_modify")) pair_modify(); - else if (!strcmp(command,"pair_style")) pair_style(); - else if (!strcmp(command,"pair_write")) pair_write(); - else if (!strcmp(command,"processors")) processors(); - else if (!strcmp(command,"region")) region(); - else if (!strcmp(command,"reset_timestep")) reset_timestep(); - else if (!strcmp(command,"restart")) restart(); - else if (!strcmp(command,"run_style")) run_style(); - else if (!strcmp(command,"special_bonds")) special_bonds(); - else if (!strcmp(command,"suffix")) suffix(); - else if (!strcmp(command,"thermo")) thermo(); - else if (!strcmp(command,"thermo_modify")) thermo_modify(); - else if (!strcmp(command,"thermo_style")) thermo_style(); - else if (!strcmp(command,"timestep")) timestep(); - else if (!strcmp(command,"timer")) timer_command(); - else if (!strcmp(command,"uncompute")) uncompute(); - else if (!strcmp(command,"undump")) undump(); - else if (!strcmp(command,"unfix")) unfix(); - else if (!strcmp(command,"units")) units(); + else if (mycmd == "angle_coeff") angle_coeff(); + else if (mycmd == "angle_style") angle_style(); + else if (mycmd == "atom_modify") atom_modify(); + else if (mycmd == "atom_style") atom_style(); + else if (mycmd == "bond_coeff") bond_coeff(); + else if (mycmd == "bond_style") bond_style(); + else if (mycmd == "bond_write") bond_write(); + else if (mycmd == "boundary") boundary(); + else if (mycmd == "box") box(); + else if (mycmd == "comm_modify") comm_modify(); + else if (mycmd == "comm_style") comm_style(); + else if (mycmd == "compute") compute(); + else if (mycmd == "compute_modify") compute_modify(); + else if (mycmd == "dielectric") dielectric(); + else if (mycmd == "dihedral_coeff") dihedral_coeff(); + else if (mycmd == "dihedral_style") dihedral_style(); + else if (mycmd == "dimension") dimension(); + else if (mycmd == "dump") dump(); + else if (mycmd == "dump_modify") dump_modify(); + else if (mycmd == "fix") fix(); + else if (mycmd == "fix_modify") fix_modify(); + else if (mycmd == "group") group_command(); + else if (mycmd == "improper_coeff") improper_coeff(); + else if (mycmd == "improper_style") improper_style(); + else if (mycmd == "kspace_modify") kspace_modify(); + else if (mycmd == "kspace_style") kspace_style(); + else if (mycmd == "labelmap") labelmap(); + else if (mycmd == "lattice") lattice(); + else if (mycmd == "mass") mass(); + else if (mycmd == "min_modify") min_modify(); + else if (mycmd == "min_style") min_style(); + else if (mycmd == "molecule") molecule(); + else if (mycmd == "neigh_modify") neigh_modify(); + else if (mycmd == "neighbor") neighbor_command(); + else if (mycmd == "newton") newton(); + else if (mycmd == "package") package(); + else if (mycmd == "pair_coeff") pair_coeff(); + else if (mycmd == "pair_modify") pair_modify(); + else if (mycmd == "pair_style") pair_style(); + else if (mycmd == "pair_write") pair_write(); + else if (mycmd == "processors") processors(); + else if (mycmd == "region") region(); + else if (mycmd == "reset_timestep") reset_timestep(); + else if (mycmd == "restart") restart(); + else if (mycmd == "run_style") run_style(); + else if (mycmd == "special_bonds") special_bonds(); + else if (mycmd == "suffix") suffix(); + else if (mycmd == "thermo") thermo(); + else if (mycmd == "thermo_modify") thermo_modify(); + else if (mycmd == "thermo_style") thermo_style(); + else if (mycmd == "timestep") timestep(); + else if (mycmd == "timer") timer_command(); + else if (mycmd == "uncompute") uncompute(); + else if (mycmd == "undump") undump(); + else if (mycmd == "unfix") unfix(); + else if (mycmd == "units") units(); else flag = 0; @@ -830,13 +831,12 @@ int Input::execute_command() // process "meta-commands", i.e. commands that may have sub-commands // they return 1 if there was a match and 0 if not - if (!strcmp(command,"reset")) flag = reset(); + if (mycmd == "reset") flag = meta(mycmd); if (flag) return 0; // invoke commands added via style_command.h // try suffixed version first - std::string mycmd = command; if (lmp->suffix_enable && lmp->non_pair_suffix()) { mycmd = command + std::string("/") + lmp->non_pair_suffix(); if (command_map->find(mycmd) == command_map->end()) { @@ -1997,13 +1997,13 @@ void Input::units() /* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - one function for each meta command + function for meta commands ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */ -int Input::reset() +int Input::meta(const std::string &prefix) { - auto mycmd = fmt::format("reset_{}", arg[0]); + auto mycmd = fmt::format("{}_{}", prefix, arg[0]); if (command_map->find(mycmd) != command_map->end()) { CommandCreator &command_creator = (*command_map)[mycmd]; Command *cmd = command_creator(lmp); diff --git a/src/input.h b/src/input.h index ab19f544dc..23007e5fed 100644 --- a/src/input.h +++ b/src/input.h @@ -70,6 +70,8 @@ class Input : protected Pointers { void reallocate(char *&, int &, int); // reallocate a char string int execute_command(); // execute a single command + int meta(const std::string &); // process meta-commands + void clear(); // input script commands void echo(); void ifthenelse(); @@ -142,8 +144,6 @@ class Input : protected Pointers { void undump(); void unfix(); void units(); - - int reset(); // meta-commands }; } // namespace LAMMPS_NS #endif