*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, 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.
#include "xvgr.h"
-#include "config.h"
-
-#include <ctype.h>
-#include <string.h>
-#include <time.h>
-
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
+#include <cctype>
+#include <cstring>
#include "gromacs/fileio/gmxfio.h"
#include "gromacs/legacyheaders/copyrite.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
#include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/sysinfo.h"
gmx_bool output_env_get_print_xvgr_codes(const output_env_t oenv)
{
break;
}
g++;
- b = strlen(buf);
+ b = std::strlen(buf);
}
else
{
/* Check for special symbol */
i = 0;
while (sym[i] != NULL &&
- gmx_strncasecmp(sym[i], gmx+g, strlen(sym[i])) != 0)
+ gmx_strncasecmp(sym[i], gmx+g, std::strlen(sym[i])) != 0)
{
i++;
}
if (sym[i] != NULL)
{
c = symc[i];
- if (isupper(gmx[g]))
+ if (std::isupper(gmx[g]))
{
- c = toupper(c);
+ c = std::toupper(c);
}
switch (xvgf)
{
sprintf(buf+b, "%s%c%s", "\\8", c, "\\4");
break;
default:
- strncat(buf+b, gmx+g, strlen(sym[i]));
- b += strlen(sym[i]);
- if (gmx[g+strlen(sym[i])] != ' ')
+ std::strncat(buf+b, gmx+g, std::strlen(sym[i]));
+ b += std::strlen(sym[i]);
+ if (gmx[g+std::strlen(sym[i])] != ' ')
{
buf[b++] = ' ';
}
buf[b] = '\0';
break;
}
- g += strlen(sym[i]);
- b = strlen(buf);
+ g += std::strlen(sym[i]);
+ b = std::strlen(buf);
}
else
{
const output_env_t oenv)
{
char pukestr[100], buf[STRLEN];
- time_t t;
if (output_env_get_print_xvgr_codes(oenv))
{
- time(&t);
- gmx_ctime_r(&t, buf, STRLEN);
+ gmx_format_current_time(buf, STRLEN);
fprintf(fp, "# This file was created %s", buf);
try
{
curp += len_remaining-1; /* overwrite the nul char in next iteration */
len_remaining = 1;
}
- while ((strchr(*ptr, '\n') == NULL) && (!feof(fp)));
+ while ((std::strchr(*ptr, '\n') == NULL) && (!feof(fp)));
if (*len + STRLEN >= maxlen)
{
}
{
/* now remove newline */
- int slen = strlen(*ptr);
+ int slen = std::strlen(*ptr);
if ((*ptr)[slen-1] == '\n')
{
(*ptr)[slen-1] = '\0';
static int wordcount(char *ptr)
{
- int i, n, is[2];
+ int i, n = 0, is[2];
int cur = 0;
#define prev (1-cur)
- if (strlen(ptr) == 0)
- {
- return 0;
- }
- /* fprintf(stderr,"ptr='%s'\n",ptr); */
- n = 1;
- for (i = 0; (ptr[i] != '\0'); i++)
+ if (NULL != ptr)
{
- is[cur] = isspace(ptr[i]);
- if ((i > 0) && (is[cur] && !is[prev]))
+ for (i = 0; (ptr[i] != '\0'); i++)
{
- n++;
+ is[cur] = std::isspace(ptr[i]);
+ if ((0 == i) && !is[cur])
+ {
+ n++;
+ }
+ else if ((i > 0) && (!is[cur] && is[prev]))
+ {
+ n++;
+ }
+ cur = prev;
}
- cur = prev;
}
return n;
}
const char *ptr0, *ptr1;
char *str;
- ptr0 = strchr(line, '"');
+ ptr0 = std::strchr(line, '"');
if (ptr0 != NULL)
{
ptr0++;
- ptr1 = strchr(ptr0, '"');
+ ptr1 = std::strchr(ptr0, '"');
if (ptr1 != NULL)
{
str = gmx_strdup(ptr0);
ptr++;
trim(ptr);
set = -1;
- if (strncmp(ptr, "subtitle", 8) == 0)
+ if (std::strncmp(ptr, "subtitle", 8) == 0)
{
ptr += 8;
if (subtitle != NULL)
*subtitle = read_xvgr_string(ptr);
}
}
- else if (strncmp(ptr, "legend string", 13) == 0)
+ else if (std::strncmp(ptr, "legend string", 13) == 0)
{
ptr += 13;
sscanf(ptr, "%d%n", &set, &nchar);
sscanf(ptr, "%d%n", &set, &nchar);
ptr += nchar;
trim(ptr);
- if (strncmp(ptr, "legend", 6) == 0)
+ if (std::strncmp(ptr, "legend", 6) == 0)
{
ptr += 6;
}
/* fprintf(stderr,"ptr='%s'\n",ptr);*/
for (k = 0; (k < nny); k++)
{
- strcpy(fmt, base);
- strcat(fmt, "%lf");
+ std::strcpy(fmt, base);
+ std::strcat(fmt, "%lf");
rval = sscanf(ptr, fmt, &lf);
/* fprintf(stderr,"rval = %d\n",rval);*/
if ((rval == EOF) || (rval == 0))
yy[k][nx] = lf;
srenew(fmt, 3*(nny+1)+1);
srenew(base, 3*nny+1);
- strcat(base, "%*s");
+ std::strcat(base, "%*s");
}
if (k != nny)
{
*y = yy;
sfree(tmpbuf);
+ sfree(base);
+ sfree(fmt);
if (legend_nalloc > 0)
{