Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / utility / cstringutil.c
index 8ca310c1b7499e0e33e296b2fa6a3b95773593f0..bb0c250776f07540bef543c0404b5b973b1e1aeb 100644 (file)
  * the research papers on the package. Check out http://www.gromacs.org.
  */
 /* This file is completely threadsafe - keep it that way! */
-#include "cstringutil.h"
+#include "gmxpre.h"
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "cstringutil.h"
 
 #include <assert.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <time.h>
-
-#include <sys/types.h>
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#ifdef HAVE_PWD_H
-#include <pwd.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
 
-#include "gromacs/legacyheaders/types/simple.h"
-#include "gromacs/legacyheaders/gmx_fatal.h"
-#include "gromacs/legacyheaders/main.h"
-
-#include "gromacs/fileio/futil.h"
+#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/sysinfo.h"
 
 int continuing(char *s)
 {
@@ -87,10 +72,6 @@ int continuing(char *s)
 
 
 char *fgets2(char *line, int n, FILE *stream)
-/* This routine reads a string from stream of max length n, including \0
- * and zero terminated, without newlines
- * line should be long enough (>= n)
- */
 {
     char *c;
     if (fgets(line, n, stream) == NULL)
@@ -194,71 +175,28 @@ void trim (char *str)
     rtrim (str);
 }
 
-char *
-gmx_ctime_r(const time_t *clock, char *buf, int n)
-{
-#ifdef _MSC_VER
-    /* Windows */
-    ctime_s( buf, n, clock );
-#elif defined(GMX_NATIVE_WINDOWS)
-    char *tmpbuf = ctime( clock );
-    strncpy(buf, tmpbuf, n-1);
-    buf[n-1] = '\0';
-#elif (defined(__sun))
-    /*Solaris*/
-    ctime_r(clock, buf, n);
-#else
-    char tmpbuf[STRLEN];
-    ctime_r(clock, tmpbuf);
-    strncpy(buf, tmpbuf, n-1);
-    buf[n-1] = '\0';
-#endif
-    return buf;
-}
-
-void nice_header (FILE *out, const char *fn)
+void nice_header(FILE *out, const char *fn)
 {
-    const char    *unk = "onbekend";
-    time_t         clock;
-    const char    *user = unk;
-    int            gh;
-#ifdef HAVE_PWD_H
-    uid_t          uid;
-#else
     int            uid;
-#endif
-    char           buf[256] = "";
+    char           userbuf[256];
+    char           hostbuf[256];
     char           timebuf[STRLEN];
-#ifdef HAVE_PWD_H
-    struct passwd *pw;
-#endif
 
     /* Print a nice header above the file */
-    time(&clock);
-    fprintf (out, "%c\n", COMMENTSIGN);
-    fprintf (out, "%c\tFile '%s' was generated\n", COMMENTSIGN, fn ? fn : unk);
-
-#ifdef HAVE_PWD_H
-    uid  = getuid();
-    pw   = getpwuid(uid);
-    gh   = gmx_gethostname(buf, 255);
-    /* pw returns null on error (e.g. compute nodes lack /etc/passwd) */
-    user = pw ? pw->pw_name : unk;
-#else
-    uid = 0;
-    gh  = -1;
-#endif
-
-    gmx_ctime_r(&clock, timebuf, STRLEN);
-    fprintf (out, "%c\tBy user: %s (%d)\n", COMMENTSIGN,
-             user ? user : unk, (int) uid);
-    fprintf(out, "%c\tOn host: %s\n", COMMENTSIGN, (gh == 0) ? buf : unk);
-
-    fprintf (out, "%c\tAt date: %s", COMMENTSIGN, timebuf);
-    fprintf (out, "%c\n", COMMENTSIGN);
+    fprintf(out, "%c\n", COMMENTSIGN);
+    fprintf(out, "%c\tFile '%s' was generated\n", COMMENTSIGN, fn ? fn : "unknown");
+
+    uid  = gmx_getuid();
+    gmx_getusername(userbuf, 256);
+    gmx_gethostname(hostbuf, 256);
+    gmx_format_current_time(timebuf, STRLEN);
+
+    fprintf(out, "%c\tBy user: %s (%d)\n", COMMENTSIGN, userbuf, uid);
+    fprintf(out, "%c\tOn host: %s\n", COMMENTSIGN, hostbuf);
+    fprintf(out, "%c\tAt date: %s\n", COMMENTSIGN, timebuf);
+    fprintf(out, "%c\n", COMMENTSIGN);
 }
 
-
 int gmx_strcasecmp_min(const char *str1, const char *str2)
 {
     char ch1, ch2;
@@ -593,6 +531,12 @@ str_to_int64_t(const char *str, char **endptr)
 #endif
 }
 
+char *gmx_step_str(gmx_int64_t i, char *buf)
+{
+    sprintf(buf, "%"GMX_PRId64, i);
+    return buf;
+}
+
 void parse_digits_from_plain_string(const char *digitstring, int *ndigits, int **digitlist)
 {
     int i;