#include <cstring>
#include <algorithm>
+#include <array>
+#include <vector>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
#include "gromacs/topology/index.h"
#include "gromacs/topology/mtop_util.h"
#include "gromacs/topology/topology.h"
+#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/arraysize.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/fatalerror.h"
#define NAME_LEN 1024
static const int NOTSET = -92637;
+// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static gmx_bool bCase = FALSE;
static int or_groups(int nr1, const int* at1, int nr2, const int* at2, int* nr, int* at)
return (c != '\0' && std::strchr(spec, c) == nullptr);
}
-static int parse_names(char** string, int* n_names, char** names)
+static int parse_names(char** string, int* n_names, gmx::ArrayRef<char*> names)
{
int i;
return *n_names;
}
-static gmx_bool parse_int_char(char** string, int* nr, char* c)
+static gmx_bool parse_int_char(char** string, int* nr, unsigned char* c)
{
char* orig;
gmx_bool bRet;
static gmx_bool parse_int(char** string, int* nr)
{
- char * orig, c;
- gmx_bool bRet;
+ char* orig;
+ unsigned char c;
+ gmx_bool bRet;
orig = *string;
bRet = parse_int_char(string, nr, &c);
return *nr;
}
-static int select_residuenumbers(char** string, const t_atoms* atoms, int n1, char c, int* nr, int* index, char* gname)
+static int
+select_residuenumbers(char** string, const t_atoms* atoms, int n1, unsigned char c, int* nr, int* index, char* gname)
{
char buf[STRLEN];
int i, j, up;
return *nr;
}
-static int select_residueindices(char** string, const t_atoms* atoms, int n1, char c, int* nr, int* index, char* gname)
+static int
+select_residueindices(char** string, const t_atoms* atoms, int n1, unsigned char c, int* nr, int* index, char* gname)
{
/*this should be similar to select_residuenumbers except select by index (sequential numbering in file)*/
/*resind+1 for 1-indexing*/
return matches;
}
-static int select_chainnames(const t_atoms* atoms, int n_names, char** names, int* nr, int* index)
+static int select_chainnames(const t_atoms* atoms, int n_names, gmx::ArrayRef<char*> names, int* nr, int* index)
{
char name[2];
int j;
return *nr;
}
-static int select_atomnames(const t_atoms* atoms, int n_names, char** names, int* nr, int* index, gmx_bool bType)
+static int select_atomnames(const t_atoms* atoms, int n_names, gmx::ArrayRef<char*> names, int* nr, int* index, gmx_bool bType)
{
char* name;
int j;
return *nr;
}
-static int select_residuenames(const t_atoms* atoms, int n_names, char** names, int* nr, int* index)
+static int select_residuenames(const t_atoms* atoms, int n_names, gmx::ArrayRef<char*> names, int* nr, int* index)
{
char* name;
int j;
}
}
-static void make_gname(int n, char** names, char* gname)
+static void make_gname(int n, gmx::ArrayRef<char*> names, char* gname)
{
int i;
}
}
-static gmx_bool parse_entry(char** string,
- int natoms,
- const t_atoms* atoms,
- t_blocka* block,
- char*** gn,
- int* nr,
- int* index,
- char* gname)
+static gmx_bool parse_entry(char** string,
+ int natoms,
+ const t_atoms* atoms,
+ t_blocka* block,
+ char*** gn,
+ int* nr,
+ int* index,
+ char* gname,
+ gmx::ArrayRef<char*> entryNames)
{
- static char ** names, *ostring;
- static gmx_bool bFirst = TRUE;
- int j, n_names, sel_nr1;
- int i, nr1, *index1;
- char c;
- gmx_bool bRet, bCompl;
-
- if (bFirst)
- {
- bFirst = FALSE;
- snew(names, MAXNAMES);
- for (i = 0; i < MAXNAMES; i++)
- {
- snew(names[i], NAME_LEN + 1);
- }
- }
+ char* ostring;
+ int j, n_names, sel_nr1;
+ int i, nr1, *index1;
+ unsigned char c;
+ gmx_bool bRet, bCompl;
bRet = FALSE;
sel_nr1 = NOTSET;
{
bRet = (select_atomnumbers(string, atoms, sel_nr1, nr, index, gname) != 0);
}
- else if (parse_names(string, &n_names, names))
+ else if (parse_names(string, &n_names, entryNames))
{
- bRet = (select_atomnames(atoms, n_names, names, nr, index, FALSE) != 0);
- make_gname(n_names, names, gname);
+ bRet = (select_atomnames(atoms, n_names, entryNames, nr, index, FALSE) != 0);
+ make_gname(n_names, entryNames, gname);
}
}
}
else if ((*string)[0] == 't')
{
(*string)++;
- if (check_have_atoms(atoms, ostring) && parse_names(string, &n_names, names))
+ if (check_have_atoms(atoms, ostring) && parse_names(string, &n_names, entryNames))
{
if (!(atoms->haveType))
{
}
else
{
- bRet = (select_atomnames(atoms, n_names, names, nr, index, TRUE) != 0);
- make_gname(n_names, names, gname);
+ bRet = (select_atomnames(atoms, n_names, entryNames, nr, index, TRUE) != 0);
+ make_gname(n_names, entryNames, gname);
}
}
}
{
bRet = (select_residuenumbers(string, atoms, sel_nr1, c, nr, index, gname) != 0);
}
- else if (parse_names(string, &n_names, names))
+ else if (parse_names(string, &n_names, entryNames))
{
- bRet = (select_residuenames(atoms, n_names, names, nr, index) != 0);
- make_gname(n_names, names, gname);
+ bRet = (select_residuenames(atoms, n_names, entryNames, nr, index) != 0);
+ make_gname(n_names, entryNames, gname);
}
}
}
else if (std::strncmp(*string, "chain", 5) == 0)
{
(*string) += 5;
- if (check_have_atoms(atoms, ostring) && parse_names(string, &n_names, names))
+ if (check_have_atoms(atoms, ostring) && parse_names(string, &n_names, entryNames))
{
- bRet = (select_chainnames(atoms, n_names, names, nr, index) != 0);
- sprintf(gname, "ch%s", names[0]);
+ bRet = (select_chainnames(atoms, n_names, entryNames, nr, index) != 0);
+ sprintf(gname, "ch%s", entryNames[0]);
for (i = 1; i < n_names; i++)
{
- std::strcat(gname, names[i]);
+ std::strcat(gname, entryNames[i]);
}
}
}
static void edit_index(int natoms, const t_atoms* atoms, const rvec* x, t_blocka* block, char*** gn, gmx_bool bVerbose)
{
- static char ** atnames, *ostring;
- static gmx_bool bFirst = TRUE;
- char inp_string[STRLEN], *string;
- char gname[STRLEN * 3], gname1[STRLEN], gname2[STRLEN];
- int i, i0, i1, sel_nr, sel_nr2, newgroup;
- int nr, nr1, nr2, *index, *index1, *index2;
- gmx_bool bAnd, bOr, bPrintOnce;
-
- if (bFirst)
- {
- bFirst = FALSE;
- snew(atnames, MAXNAMES);
- for (i = 0; i < MAXNAMES; i++)
- {
- snew(atnames[i], NAME_LEN + 1);
- }
- }
+ char* ostring;
+ char inp_string[STRLEN], *string;
+ char gname[STRLEN * 3], gname1[STRLEN], gname2[STRLEN];
+ int i, i0, i1, sel_nr, sel_nr2, newgroup;
+ int nr, nr1, nr2, *index, *index1, *index2;
+ gmx_bool bAnd, bOr, bPrintOnce;
string = nullptr;
newgroup = NOTSET;
bPrintOnce = TRUE;
+ std::array<char*, MAXNAMES> entryNames;
+ for (auto& name : entryNames)
+ {
+ snew(name, NAME_LEN + 1);
+ }
+
do
{
gname1[0] = '\0';
else if (string[0] != 'q')
{
nr2 = -1;
- if (parse_entry(&string, natoms, atoms, block, gn, &nr, index, gname))
+ if (parse_entry(&string, natoms, atoms, block, gn, &nr, index, gname, entryNames))
{
do
{
index1[i] = index[i];
}
std::strcpy(gname1, gname);
- if (parse_entry(&string, natoms, atoms, block, gn, &nr2, index2, gname2))
+ if (parse_entry(&string, natoms, atoms, block, gn, &nr2, index2, gname2, entryNames))
{
if (bOr)
{
}
} while (string[0] != 'q');
+ for (auto& name : entryNames)
+ {
+ sfree(name);
+ }
sfree(index);
sfree(index1);
sfree(index2);
natoms = block2natoms(block);
printf("Counted atom numbers up to %d in index file\n", natoms);
}
-
edit_index(natoms, &atoms, x, block, &gnames, bVerbose);
write_index(ndxoutfile, block, gnames, bDuplicate, natoms);
--- /dev/null
+# List of rationales for check suppressions (where known).
+# This have to precede the list because inline comments are not
+# supported by clang-tidy.
+#
+# -cppcoreguidelines-non-private-member-variables-in-classes,
+# -misc-non-private-member-variables-in-classes,
+# We intend a gradual transition to conform to this guideline, but it
+# is not practical to implement yet.
+#
+# -readability-isolate-declaration,
+# Declarations like "int a, b;" are readable. Some forms are not, and
+# those might reasonably be suggested against during code review.
+#
+# -cppcoreguidelines-avoid-c-arrays,
+# C arrays are still necessary in many places with legacy code
+#
+# -cppcoreguidelines-avoid-magic-numbers,
+# -readability-magic-numbers,
+# We have many legitimate use cases for magic numbers
+#
+# -cppcoreguidelines-macro-usage,
+# We do use too many macros, and we should fix many of them, but there
+# is no reasonable way to suppress the check e.g. in src/config.h and
+# configuring the build is a major legitimate use of macros.
+#
+# -cppcoreguidelines-narrowing-conversions,
+# -bugprone-narrowing-conversions
+# We have many cases where int is converted to float and we don't care
+# enough about such potential loss of precision to use explicit casts
+# in large numbers of places.
+#
+# -google-readability-avoid-underscore-in-googletest-name
+# We need to use underscores for readability for our legacy types
+# and command-line parameter names
+#
+# -misc-no-recursion
+# We have way too many functions and methods relying on recursion
+#
+# -cppcoreguidelines-avoid-non-const-global-variables
+# There are quite a lot of static variables in the test code that
+# can not be replaced.
+#
+# -modernize-avoid-bind
+# Some code needs to use std::bind and can't be modernized quickly.
+Checks: clang-diagnostic-*,-clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy,
+ bugprone-*,misc-*,readability-*,performance-*,mpi-*,
+ -readability-inconsistent-declaration-parameter-name,
+ -readability-function-size,-readability-else-after-return,
+ modernize-use-nullptr,modernize-use-emplace,
+ modernize-make-unique,modernize-make-shared,
+ modernize-avoid-bind,
+ modernize-use-override,
+ modernize-redundant-void-arg,modernize-use-bool-literals,
+ cppcoreguidelines-*,-cppcoreguidelines-pro-*,-cppcoreguidelines-owning-memory,
+ -cppcoreguidelines-no-malloc,-cppcoreguidelines-special-member-functions,
+ -cppcoreguidelines-avoid-goto,
+ google-*,-google-build-using-namespace,-google-explicit-constructor,
+ -google-readability-function-size,-google-readability-todo,-google-runtime-int,
+ -cppcoreguidelines-non-private-member-variables-in-classes,
+ -misc-non-private-member-variables-in-classes,
+ -readability-isolate-declaration,
+ -cppcoreguidelines-avoid-c-arrays,
+ -cppcoreguidelines-avoid-magic-numbers,
+ -readability-magic-numbers,
+ -cppcoreguidelines-macro-usage,
+ -cppcoreguidelines-narrowing-conversions,
+ -bugprone-narrowing-conversions,
+ -google-readability-avoid-underscore-in-googletest-name,
+ -cppcoreguidelines-init-variables,
+ -misc-no-recursion,
+ -cppcoreguidelines-avoid-non-const-global-variables,
+ -modernize-avoid-bind
+HeaderFilterRegex: .*
+CheckOptions:
+ - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
+ value: 1
+ - key: modernize-make-unique.IncludeStyle
+ value: google
+ - key: modernize-make-shared.IncludeStyle
+ value: google
+ - key: readability-implicit-bool-conversion.AllowIntegerConditions
+ value: 1
+ - key: readability-implicit-bool-conversion.AllowPointerConditions
+ value: 1
+ - key: bugprone-dangling-handle.HandleClasses
+ value: std::basic_string_view; nonstd::sv_lite::basic_string_view
+# Permit passing shard pointers by value for sink parameters
+ - key: performance-unnecessary-copy-initialization.AllowedTypes
+ value: shared_ptr
+ - key: performance-unnecessary-value-param.AllowedTypes
+ value: shared_ptr
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
const char* fit[efNR + 1] = { nullptr, "none", "rot+trans", "rotxy+transxy",
"translation", "transxy", "progressive", nullptr };
- static gmx_bool bSeparate = FALSE, bVels = TRUE, bForce = FALSE, bCONECT = FALSE;
- static gmx_bool bCenter = FALSE;
- static int skip_nr = 1, ndec = 3, nzero = 0;
- static real tzero = 0, delta_t = 0, timestep = 0, ttrunc = -1, tdump = -1, split_t = 0;
- static rvec newbox = { 0, 0, 0 }, shift = { 0, 0, 0 }, trans = { 0, 0, 0 };
- static char* exec_command = nullptr;
- static real dropunder = 0, dropover = 0;
- static gmx_bool bRound = FALSE;
+ gmx_bool bSeparate = FALSE, bVels = TRUE, bForce = FALSE, bCONECT = FALSE;
+ gmx_bool bCenter = FALSE;
+ int skip_nr = 1, ndec = 3, nzero = 0;
+ real tzero = 0, delta_t = 0, timestep = 0, ttrunc = -1, tdump = -1, split_t = 0;
+ rvec newbox = { 0, 0, 0 }, shift = { 0, 0, 0 }, trans = { 0, 0, 0 };
+ char* exec_command = nullptr;
+ real dropunder = 0, dropover = 0;
+ gmx_bool bRound = FALSE;
t_pargs pa[] = {
{ "-skip", FALSE, etINT, { &skip_nr }, "Only write every nr-th frame" },