X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fsession.c;h=a308ec1f624befa7c8e302c656944274bd82cc0d;hb=6bf4567d7fcf5f0fa5805c4de24c13c2a7cfbbc9;hp=24c22b24ed3001285b84cb9427f76fbb93eb4e48;hpb=e195fccfab97205acb29f90fd1168488d49f1573;p=pspp diff --git a/src/data/session.c b/src/data/session.c index 24c22b24ed..a308ec1f62 100644 --- a/src/data/session.c +++ b/src/data/session.c @@ -1,5 +1,5 @@ /* 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 @@ -35,6 +35,7 @@ struct session 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 *, @@ -49,6 +50,7 @@ session_create (void) hmapx_init (&s->datasets); s->active = NULL; s->syntax_encoding = xstrdup ("Auto"); + s->n_dataset_names = 0; return s; } @@ -164,6 +166,25 @@ session_get_dataset_by_seqno (const struct session *s, unsigned int seqno) 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); + } +} static struct hmapx_node * session_lookup_dataset__ (const struct session *s_, const char *name)