Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / xlate.cpp
index 43f232facdfa1b96728257030b1af6b083b0a9c0..7c81461f18708441acf1360b0fad035cebe5f679 100644 (file)
 
 #include "hackblock.h"
 
-typedef struct {
-    char *filebase;
-    char *res;
-    char *atom;
-    char *replace;
+typedef struct
+{
+    char* filebase;
+    char* res;
+    char* atom;
+    char* replace;
 } t_xlate_atom;
 
-static void get_xlatoms(const std::string &filename, FILE *fp,
-                        int *nptr, t_xlate_atom **xlptr)
+static void get_xlatoms(const std::string& filename, FILE* fp, int* nptr, t_xlate_atom** xlptr)
 {
     char          filebase[STRLEN];
     char          line[STRLEN];
     char          abuf[1024], rbuf[1024], repbuf[1024], dumbuf[1024];
-    char         *_ptr;
+    char*         _ptr;
     int           n, na, idum;
-    t_xlate_atom *xl;
+    t_xlate_atomxl;
 
     fflib_filename_base(filename.c_str(), filebase, STRLEN);
 
@@ -90,10 +90,11 @@ static void get_xlatoms(const std::string &filename, FILE *fp,
         }
         if (na != 3)
         {
-            gmx_fatal(FARGS, "Expected a residue name and two atom names in file '%s', not '%s'", filename.c_str(), line);
+            gmx_fatal(FARGS, "Expected a residue name and two atom names in file '%s', not '%s'",
+                      filename.c_str(), line);
         }
 
-        srenew(xl, n+1);
+        srenew(xl, n + 1);
         xl[n].filebase = gmx_strdup(filebase);
 
         /* Use wildcards... */
@@ -121,7 +122,7 @@ static void get_xlatoms(const std::string &filename, FILE *fp,
     *xlptr = xl;
 }
 
-static void done_xlatom(int nxlate, t_xlate_atom *xlatom)
+static void done_xlatom(int nxlate, t_xlate_atomxlatom)
 {
     int i;
 
@@ -138,13 +139,18 @@ static void done_xlatom(int nxlate, t_xlate_atom *xlatom)
     sfree(xlatom);
 }
 
-void rename_atoms(const char* xlfile, const char *ffdir,
-                  t_atoms *atoms, t_symtab *symtab, gmx::ArrayRef<const PreprocessResidue> localPpResidue,
-                  bool bResname, ResidueType *rt, bool bReorderNum,
-                  bool bVerbose)
+void rename_atoms(const char*                            xlfile,
+                  const char*                            ffdir,
+                  t_atoms*                               atoms,
+                  t_symtab*                              symtab,
+                  gmx::ArrayRef<const PreprocessResidue> localPpResidue,
+                  bool                                   bResname,
+                  ResidueType*                           rt,
+                  bool                                   bReorderNum,
+                  bool                                   bVerbose)
 {
     int           nxlate, a, i, resind;
-    t_xlate_atom *xlatom;
+    t_xlate_atomxlatom;
     char          c, *rnm, atombuf[32];
     bool          bReorderedNum, bRenamed, bMatch;
     bool          bStartTerm, bEndTerm;
@@ -159,9 +165,9 @@ void rename_atoms(const char* xlfile, const char *ffdir,
     else
     {
         std::vector<std::string> fns = fflib_search_file_end(ffdir, ".arn", FALSE);
-        for (const auto &filename : fns)
+        for (const autofilename : fns)
         {
-            FILE * fp = fflib_open(filename);
+            FILE* fp = fflib_open(filename);
             get_xlatoms(filename, fp, &nxlate, &xlatom);
             gmx_ffclose(fp);
         }
@@ -171,8 +177,9 @@ void rename_atoms(const char* xlfile, const char *ffdir,
     {
         resind = atoms->atom[a].resind;
 
-        bStartTerm = (resind == 0) || atoms->resinfo[resind].chainnum != atoms->resinfo[resind-1].chainnum;
-        bEndTerm   = (resind >= atoms->nres-1) || atoms->resinfo[resind].chainnum != atoms->resinfo[resind+1].chainnum;
+        bStartTerm = (resind == 0) || atoms->resinfo[resind].chainnum != atoms->resinfo[resind - 1].chainnum;
+        bEndTerm = (resind >= atoms->nres - 1)
+                   || atoms->resinfo[resind].chainnum != atoms->resinfo[resind + 1].chainnum;
 
         if (bResname)
         {
@@ -190,9 +197,9 @@ void rename_atoms(const char* xlfile, const char *ffdir,
             if (isdigit(atombuf[0]))
             {
                 c = atombuf[0];
-                for (i = 0; (static_cast<size_t>(i) < strlen(atombuf)-1); i++)
+                for (i = 0; (static_cast<size_t>(i) < strlen(atombuf) - 1); i++)
                 {
-                    atombuf[i] = atombuf[i+1];
+                    atombuf[i] = atombuf[i + 1];
                 }
                 atombuf[i]    = c;
                 bReorderedNum = TRUE;
@@ -202,27 +209,26 @@ void rename_atoms(const char* xlfile, const char *ffdir,
         for (i = 0; (i < nxlate) && !bRenamed; i++)
         {
             /* Check if the base file name of the rtp and arn entry match */
-            if (localPpResidue.empty() ||
-                gmx::equalCaseInsensitive(localPpResidue[resind].filebase, xlatom[i].filebase))
+            if (localPpResidue.empty()
+                || gmx::equalCaseInsensitive(localPpResidue[resind].filebase, xlatom[i].filebase))
             {
                 /* Match the residue name */
-                bMatch = (xlatom[i].res == nullptr ||
-                          (gmx_strcasecmp("protein-nterm", xlatom[i].res) == 0 &&
-                           rt->namedResidueHasType(rnm, "Protein") && bStartTerm) ||
-                          (gmx_strcasecmp("protein-cterm", xlatom[i].res) == 0 &&
-                           rt->namedResidueHasType(rnm, "Protein") && bEndTerm) ||
-                          (gmx_strcasecmp("protein", xlatom[i].res) == 0 &&
-                           rt->namedResidueHasType(rnm, "Protein")) ||
-                          (gmx_strcasecmp("DNA", xlatom[i].res) == 0 &&
-                           rt->namedResidueHasType(rnm, "DNA")) ||
-                          (gmx_strcasecmp("RNA", xlatom[i].res) == 0 &&
-                           rt->namedResidueHasType(rnm, "RNA")));
+                bMatch = (xlatom[i].res == nullptr
+                          || (gmx_strcasecmp("protein-nterm", xlatom[i].res) == 0
+                              && rt->namedResidueHasType(rnm, "Protein") && bStartTerm)
+                          || (gmx_strcasecmp("protein-cterm", xlatom[i].res) == 0
+                              && rt->namedResidueHasType(rnm, "Protein") && bEndTerm)
+                          || (gmx_strcasecmp("protein", xlatom[i].res) == 0
+                              && rt->namedResidueHasType(rnm, "Protein"))
+                          || (gmx_strcasecmp("DNA", xlatom[i].res) == 0
+                              && rt->namedResidueHasType(rnm, "DNA"))
+                          || (gmx_strcasecmp("RNA", xlatom[i].res) == 0
+                              && rt->namedResidueHasType(rnm, "RNA")));
                 if (!bMatch)
                 {
-                    const char *ptr0 = rnm;
-                    const char *ptr1 = xlatom[i].res;
-                    while (ptr0[0] != '\0' && ptr1[0] != '\0' &&
-                           (ptr0[0] == ptr1[0] || ptr1[0] == '?'))
+                    const char* ptr0 = rnm;
+                    const char* ptr1 = xlatom[i].res;
+                    while (ptr0[0] != '\0' && ptr1[0] != '\0' && (ptr0[0] == ptr1[0] || ptr1[0] == '?'))
                     {
                         ptr0++;
                         ptr1++;
@@ -235,14 +241,11 @@ void rename_atoms(const char* xlfile, const char *ffdir,
                     /* Don't free the old atomname,
                      * since it might be in the symtab.
                      */
-                    const char *ptr0 = xlatom[i].replace;
+                    const charptr0 = xlatom[i].replace;
                     if (bVerbose)
                     {
-                        printf("Renaming atom '%s' in residue %d %s to '%s'\n",
-                               *atoms->atomname[a],
-                               atoms->resinfo[resind].nr,
-                               *atoms->resinfo[resind].name,
-                               ptr0);
+                        printf("Renaming atom '%s' in residue %d %s to '%s'\n", *atoms->atomname[a],
+                               atoms->resinfo[resind].nr, *atoms->resinfo[resind].name, ptr0);
                     }
                     atoms->atomname[a] = put_symtab(symtab, ptr0);
                     bRenamed           = TRUE;