#include <config.h>
#endif
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include "sysstuff.h"
-#include "typedefs.h"
-#include "smalloc.h"
-#include "string2.h"
-#include "gmx_fatal.h"
+
#include "futil.h"
-#include "xdrf.h"
+#include "gmx_fatal.h"
#include "macros.h"
-
-#include "gromacs/legacyheaders/thread_mpi/threads.h"
-
-/* NOTE: this was a cesspool of thread-unsafe code, has now been
- properly proteced by mutexes (hopefully). */
+#include "smalloc.h"
+#include "string2.h"
+#include "types/simple.h"
+#include "types/commrec.h"
/* XDR should be available on all platforms now,
* but we keep the possibility of turning it off...
{ eftASC, "", "rundir", NULL, "Run directory" }
};
-static char *default_file_name = NULL;
-
-static tMPI_Thread_mutex_t filenm_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
-
#define NZEXT 2
static const char *z_ext[NZEXT] =
{ ".gz", ".Z" };
-void set_default_file_name(const char *name)
-{
- tMPI_Thread_mutex_lock(&filenm_mutex);
- default_file_name = strdup(name);
- tMPI_Thread_mutex_unlock(&filenm_mutex);
-}
-
const char *ftp2ext(int ftp)
{
if ((0 <= ftp) && (ftp < efNR))
const char *ftp2defnm(int ftp)
{
- const char *buf = NULL;
-
- tMPI_Thread_mutex_lock(&filenm_mutex);
-
- if (default_file_name)
+ if ((0 <= ftp) && (ftp < efNR))
{
- buf = default_file_name;
+ return deffile[ftp].defnm;
}
else
{
- if ((0 <= ftp) && (ftp < efNR))
- {
- buf = deffile[ftp].defnm;
- }
+ return NULL;
}
-
- tMPI_Thread_mutex_unlock(&filenm_mutex);
-
- return buf;
}
static void check_opts(int nf, t_filenm fnm[])
fnm->nfiles++;
}
-static void set_grpfnm(t_filenm *fnm, const char *name, gmx_bool bCanNotOverride)
+static void set_grpfnm(t_filenm *fnm, const char *name, const char *deffnm)
{
char buf[256], buf2[256];
int i, type;
}
bValidExt = FALSE;
- if (name && (bCanNotOverride || (default_file_name == NULL)))
+ if (name && deffnm == NULL)
{
strcpy(buf, name);
/* First check whether we have a valid filename already */
}
}
}
+ else if (deffnm != NULL)
+ {
+ strcpy(buf, deffnm);
+ }
else
{
/* No name given, set the default name */
add_filenm(fnm, buf);
}
-static void set_filenm(t_filenm *fnm, const char *name, gmx_bool bCanNotOverride,
+static void set_filenm(t_filenm *fnm, const char *name, const char *deffnm,
gmx_bool bReadNode)
{
/* Set the default filename, extension and option for those fields that
if (deffile[fnm->ftp].ntps)
{
- set_grpfnm(fnm, name ? buf : NULL, bCanNotOverride);
+ set_grpfnm(fnm, name ? buf : NULL, deffnm);
}
else
{
- if ((name == NULL) || !(bCanNotOverride || (default_file_name == NULL)))
+ if (name == NULL || deffnm != NULL)
{
- const char *defnm = ftp2defnm(fnm->ftp);
- strcpy(buf, defnm);
+ if (deffnm != NULL)
+ {
+ strcpy(buf, deffnm);
+ }
+ else
+ {
+ strcpy(buf, ftp2defnm(fnm->ftp));
+ }
}
set_extension(buf, fnm->ftp);
}
}
-static void set_filenms(int nf, t_filenm fnm[], gmx_bool bReadNode)
+static void set_filenms(int nf, t_filenm fnm[], const char *deffnm, gmx_bool bReadNode)
{
int i;
{
if (!IS_SET(fnm[i]))
{
- set_filenm(&(fnm[i]), fnm[i].fn, FALSE, bReadNode);
+ set_filenm(&(fnm[i]), fnm[i].fn, deffnm, bReadNode);
}
}
}
void parse_file_args(int *argc, char *argv[], int nf, t_filenm fnm[],
- gmx_bool bKeep, gmx_bool bReadNode)
+ const char *deffnm, gmx_bool bKeep, gmx_bool bReadNode)
{
int i, j;
gmx_bool *bRemove;
/* check if we are out of arguments for this option */
if ((i >= *argc) || (argv[i][0] == '-'))
{
- set_filenm(&fnm[j], fnm[j].fn, FALSE, bReadNode);
+ set_filenm(&fnm[j], fnm[j].fn, deffnm, bReadNode);
}
/* sweep up all file arguments for this option */
while ((i < *argc) && (argv[i][0] != '-'))
{
- set_filenm(&fnm[j], argv[i], TRUE, bReadNode);
+ set_filenm(&fnm[j], argv[i], NULL, bReadNode);
bRemove[i] = TRUE;
i++;
/* only repeat for 'multiple' file options: */
sfree(bRemove);
}
- set_filenms(nf, fnm, bReadNode);
+ set_filenms(nf, fnm, deffnm, bReadNode);
}
#ifndef GMX_FILEIO_FILENM_H
#define GMX_FILEIO_FILENM_H
-#include "futil.h"
+#include "../legacyheaders/types/simple.h"
+#include "../legacyheaders/types/commrec.h"
#ifdef __cplusplus
extern "C" {
#define ffWRMULT (ffWRITE | ffMULT)
#define ffOPTWRMULT (ffWRMULT | ffOPT)
-void set_default_file_name(const char *name);
-/* Set the default file name for all file types to name */
-
const char *ftp2ext(int ftp);
/* Return extension for filetype */
/* Return Binary or ASCII depending on file type */
void parse_file_args(int *argc, char *argv[], int nf, t_filenm fnm[],
- gmx_bool bKeep, gmx_bool bReadNode);
+ const char *deffnm, gmx_bool bKeep, gmx_bool bReadNode);
/* Parse command line for file names. When bKeep is set args are
* not removed from argv. */