*
* 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.
* 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 {
{
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;
ndef++;
srenew(defs, ndef);
i = ndef - 1;
- defs[i].name = strdup(name);
+ defs[i].name = gmx_strdup(name);
}
else if (defs[i].def)
{
}
if (value && strlen(value) > 0)
{
- defs[i].def = strdup(value);
+ defs[i].def = gmx_strdup(value);
}
else
{
}
}
+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)
/* 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
{
{
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);
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)
(handle) ? handle->line_nr : -1,
handle->line ? handle->line : "");
- return strdup(buf);
+ return gmx_strdup(buf);
}