Remove unnecessary config.h includes
[alexxy/gromacs.git] / src / gromacs / gmxpreprocess / gmxcpp.c
index cb93732416369cbed11deffd72dc43c26b658540..81795e98054c763b97a2eb8eda83a77ca965ef52 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2013,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.
@@ -34,9 +34,7 @@
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
 
 #include <sys/types.h>
 #include <stdio.h>
 #include <limits.h>
 #include <ctype.h>
 
-#include "string2.h"
-#include "smalloc.h"
-#include "gromacs/fileio/futil.h"
-#include "macros.h"
-#include "gmx_fatal.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/futil.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/utility/fatalerror.h"
 #include "gmxcpp.h"
 
 typedef struct {
@@ -169,10 +167,22 @@ static void add_include(const char *include)
     {
         nincl++;
         srenew(incl, nincl);
-        incl[nincl-1] = strdup(include);
+        incl[nincl-1] = gmx_strdup(include);
     }
 }
 
+static void done_includes()
+{
+    int i;
+    for (i = 0; (i < nincl); i++)
+    {
+        sfree(incl[i]);
+    }
+    sfree(incl);
+    incl  = NULL;
+    nincl = 0;
+}
+
 static void add_define(const char *name, const char *value)
 {
     int  i;
@@ -189,7 +199,7 @@ static void add_define(const char *name, const char *value)
         ndef++;
         srenew(defs, ndef);
         i            = ndef - 1;
-        defs[i].name = strdup(name);
+        defs[i].name = gmx_strdup(name);
     }
     else if (defs[i].def)
     {
@@ -201,7 +211,7 @@ static void add_define(const char *name, const char *value)
     }
     if (value && strlen(value) > 0)
     {
-        defs[i].def  = strdup(value);
+        defs[i].def  = gmx_strdup(value);
     }
     else
     {
@@ -209,6 +219,19 @@ static void add_define(const char *name, const char *value)
     }
 }
 
+static void done_defines()
+{
+    int i;
+    for (i = 0; (i < ndef); i++)
+    {
+        sfree(defs[i].name);
+        sfree(defs[i].def);
+    }
+    sfree(defs);
+    defs = NULL;
+    ndef = 0;
+}
+
 /* Open the file to be processed. The handle variable holds internal
    info for the cpp emulator. Return integer status */
 int cpp_open_file(const char *filenm, gmx_cpp_t *handle, char **cppopts)
@@ -259,7 +282,7 @@ int cpp_open_file(const char *filenm, gmx_cpp_t *handle, char **cppopts)
     /* Find the file. First check whether it is in the current directory. */
     if (gmx_fexist(filenm))
     {
-        cpp->fn = strdup(filenm);
+        cpp->fn = gmx_strdup(filenm);
     }
     else
     {
@@ -309,7 +332,7 @@ int cpp_open_file(const char *filenm, gmx_cpp_t *handle, char **cppopts)
     {
         cpp->path = cpp->fn;
         *ptr      = '\0';
-        cpp->fn   = strdup(ptr+1);
+        cpp->fn   = gmx_strdup(ptr+1);
         snew(cpp->cwd, STRLEN);
 
         gmx_getcwd(cpp->cwd, STRLEN);
@@ -750,6 +773,12 @@ int cpp_close_file(gmx_cpp_t *handlep)
     return eCPP_OK;
 }
 
+void cpp_done()
+{
+    done_includes();
+    done_defines();
+}
+
 /* Return a string containing the error message coresponding to status
    variable */
 char *cpp_error(gmx_cpp_t *handlep, int status)
@@ -778,5 +807,5 @@ char *cpp_error(gmx_cpp_t *handlep, int status)
             (handle) ? handle->line_nr : -1,
             handle->line ? handle->line : "");
 
-    return strdup(buf);
+    return gmx_strdup(buf);
 }