/* PSPP - a program for statistical analysis.
- Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
struct hmapx datasets;
struct dataset *active;
char *syntax_encoding; /* Default encoding for syntax files. */
+ unsigned int n_dataset_names; /* For session_generate_dataset_name(). */
};
static struct hmapx_node *session_lookup_dataset__ (const struct session *,
hmapx_init (&s->datasets);
s->active = NULL;
s->syntax_encoding = xstrdup ("Auto");
+ s->n_dataset_names = 0;
return s;
}
return ds;
return NULL;
}
+
+/* Returns an identifier that is is not currently in use as a dataset name.
+ The caller must free the returned identifier, with free(). */
+char *
+session_generate_dataset_name (struct session *s)
+{
+ for (;;)
+ {
+ char *name;
+
+ s->n_dataset_names++;
+ assert(s->n_dataset_names != 0);
+
+ name = xasprintf ("DataSet%u", s->n_dataset_names);
+ if (!session_lookup_dataset (s, name))
+ return name;
+ free (name);
+ }
+}
\f
static struct hmapx_node *
session_lookup_dataset__ (const struct session *s_, const char *name)
/* PSPP - a program for statistical analysis.
- Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
struct dataset *session_get_dataset_by_seqno (const struct session *,
unsigned int seqno);
+char *session_generate_dataset_name (struct session *);
+
#endif /* session.h */
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation
+ Copyright (C) 2007, 2009, 2010, 2011, 2012 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
return psppire_data_store_get_reader (data_store);
}
+/* Ensures that dataset DS has a name, because some parts of the GUI insist
+ upon this. */
+static void
+name_dataset_cb (struct dataset *ds, void *aux UNUSED)
+{
+ if (dataset_name (ds)[0] == '\0')
+ {
+ struct session *session = dataset_session (ds);
+ char *dataset_name = session_generate_dataset_name (session);
+ dataset_set_name (ds, dataset_name);
+ free (dataset_name);
+ }
+}
+
static void
new_pdw_cb (struct dataset *ds, void *aux UNUSED)
{
break;
}
+ session_for_each_dataset (the_session, name_dataset_cb, NULL);
+
ll_for_each_safe (pdw, next_pdw, PsppireDataWindow, ll, &all_data_windows)
{
struct dataset *ds;
if (ds == NULL)
{
- static int n_datasets;
- char *dataset_name;
-
- dataset_name = xasprintf ("DataSet%d", ++n_datasets);
+ char *dataset_name = session_generate_dataset_name (the_session);
ds = dataset_create (the_session, dataset_name);
free (dataset_name);
}