Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / selection / scanner_internal.cpp
index 1c5067186303a604649ce710f4f5dc27c821c813..f13031fd1a4e3abe373d96630217292775a97794 100644 (file)
@@ -1,32 +1,36 @@
 /*
+ * This file is part of the GROMACS molecular simulation package.
  *
- *                This source code is part of
+ * Copyright (c) 2009,2010,2011,2012,2014, 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.
  *
- *                 G   R   O   M   A   C   S
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
  *
- *          GROningen MAchine for Chemical Simulations
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
  *
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
  *
  * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
 /*! \internal \file
  * \brief Helper functions for the selection tokenizer.
@@ -34,7 +38,7 @@
  * This file implements the functions in the headers scanner.h and
  * scanner_internal.h.
  *
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_selection
  */
 /*! \cond
  * \ingroup module_selection
  * \endcond
  */
+#include "gmxpre.h"
+
+#include "scanner_internal.h"
+
 #include <stdlib.h>
 #include <string.h>
 
 #include <string>
 
-#include "gromacs/legacyheaders/typedefs.h"
-#include "gromacs/legacyheaders/smalloc.h"
-#include "gromacs/legacyheaders/string2.h"
-
+#include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/messagestringcollector.h"
+#include "gromacs/utility/smalloc.h"
 #include "gromacs/utility/stringutil.h"
 
+#include "parser.h"
 #include "parsetree.h"
+#include "scanner.h"
 #include "selectioncollection-impl.h"
 #include "selelem.h"
 #include "selmethod.h"
 #include "symrec.h"
 
-#include "parser.h"
-#include "scanner.h"
-#include "scanner_internal.h"
-
-//! Step in which the allocated memory for pretty-printed input is incremented.
+/*! \brief
+ * Step in which the allocated memory for pretty-printed input is incremented.
+ */
 #define STRSTORE_ALLOCSTEP 1000
 
 /* These are defined as macros in the generated scanner_flex.h.
@@ -90,7 +96,7 @@ init_param_token(YYSTYPE *yylval, gmx_ana_selparam_t *param, bool bBoolNo)
     if (bBoolNo)
     {
         GMX_RELEASE_ASSERT(param->name != NULL,
-                "bBoolNo should only be set for a parameters with a name");
+                           "bBoolNo should only be set for a parameters with a name");
         snew(yylval->str, strlen(param->name) + 3);
         yylval->str[0] = 'n';
         yylval->str[1] = 'o';
@@ -98,7 +104,7 @@ init_param_token(YYSTYPE *yylval, gmx_ana_selparam_t *param, bool bBoolNo)
     }
     else
     {
-        yylval->str = param->name ? strdup(param->name) : NULL;
+        yylval->str = param->name ? gmx_strdup(param->name) : NULL;
     }
     return PARAM;
 }
@@ -180,7 +186,7 @@ _gmx_sel_lexer_process_pending(YYSTYPE *yylval, gmx_sel_lexer_t *state)
 {
     if (state->nextparam)
     {
-        gmx_ana_selparam_t *param = state->nextparam;
+        gmx_ana_selparam_t *param   = state->nextparam;
         bool                bBoolNo = state->bBoolNo;
 
         if (state->neom > 0)
@@ -214,9 +220,9 @@ _gmx_sel_lexer_process_identifier(YYSTYPE *yylval, char *yytext, size_t yyleng,
     /* Check if the identifier matches with a parameter name */
     if (state->msp >= 0)
     {
-        gmx_ana_selparam_t *param = NULL;
+        gmx_ana_selparam_t *param   = NULL;
         bool                bBoolNo = false;
-        int                 sp = state->msp;
+        int                 sp      = state->msp;
         while (!param && sp >= 0)
         {
             int             i;
@@ -238,7 +244,7 @@ _gmx_sel_lexer_process_identifier(YYSTYPE *yylval, char *yytext, size_t yyleng,
                     && yyleng > 2 && yytext[0] == 'n' && yytext[1] == 'o'
                     && !strncmp(state->mstack[sp]->param[i].name, yytext+2, yyleng-2))
                 {
-                    param = &state->mstack[sp]->param[i];
+                    param   = &state->mstack[sp]->param[i];
                     bBoolNo = true;
                     break;
                 }
@@ -256,7 +262,7 @@ _gmx_sel_lexer_process_identifier(YYSTYPE *yylval, char *yytext, size_t yyleng,
             }
             if (sp < state->msp)
             {
-                state->neom = state->msp - sp - 1;
+                state->neom      = state->msp - sp - 1;
                 state->nextparam = param;
                 state->bBoolNo   = bBoolNo;
                 return END_OF_METHOD;
@@ -282,8 +288,8 @@ _gmx_sel_lexer_process_identifier(YYSTYPE *yylval, char *yytext, size_t yyleng,
     if (symtype == gmx::SelectionParserSymbol::ReservedSymbol)
     {
         GMX_THROW(gmx::InternalError(gmx::formatString(
-                        "Mismatch between tokenizer and reserved symbol table (for '%s')",
-                        symbol->name().c_str())));
+                                             "Mismatch between tokenizer and reserved symbol table (for '%s')",
+                                             symbol->name().c_str())));
     }
     /* For variable symbols, return the type of the variable value */
     if (symtype == gmx::SelectionParserSymbol::VariableSymbol)
@@ -318,8 +324,7 @@ _gmx_sel_lexer_process_identifier(YYSTYPE *yylval, char *yytext, size_t yyleng,
                 GMX_THROW(gmx::InternalError("Unsupported variable type"));
                 return INVALID;
         }
-        delete yylval->sel;
-        return INVALID; /* Should not be reached. */
+        /* This position should not be reached. */
     }
     /* For method symbols, return the correct type */
     if (symtype == gmx::SelectionParserSymbol::MethodSymbol)
@@ -331,8 +336,8 @@ _gmx_sel_lexer_process_identifier(YYSTYPE *yylval, char *yytext, size_t yyleng,
      * some additional handling. */
     if (symtype == gmx::SelectionParserSymbol::PositionSymbol)
     {
-        state->bMatchOf = true;
-        yylval->str strdup(symbol->name().c_str());
+        state->bMatchOf    = true;
+        yylval->str        = gmx_strdup(symbol->name().c_str());
         state->prev_pos_kw = 2;
         return KEYWORD_POS;
     }
@@ -364,7 +369,7 @@ _gmx_sel_lexer_add_token(const char *str, int len, gmx_sel_lexer_t *state)
     }
     /* Append the token to the stored string */
     strncpy(state->pselstr + state->pslen, str, len);
-    state->pslen += len;
+    state->pslen                += len;
     state->pselstr[state->pslen] = 0;
 }
 
@@ -427,7 +432,7 @@ _gmx_sel_free_lexer(yyscan_t scanner)
 }
 
 void
-_gmx_sel_set_lexer_error_reporter(yyscan_t scanner,
+_gmx_sel_set_lexer_error_reporter(yyscan_t                     scanner,
                                   gmx::MessageStringCollector *errors)
 {
     gmx_sel_lexer_t *state = _gmx_sel_yyget_extra(scanner);
@@ -435,7 +440,7 @@ _gmx_sel_set_lexer_error_reporter(yyscan_t scanner,
 }
 
 void
-_gmx_sel_lexer_set_exception(yyscan_t scanner,
+_gmx_sel_lexer_set_exception(yyscan_t                    scanner,
                              const boost::exception_ptr &ex)
 {
     gmx_sel_lexer_t *state = _gmx_sel_yyget_extra(scanner);