#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
+#include <time.h>
#include "alloc.h"
#include "command.h"
#include "lexer.h"
#include "var.h"
#include "format.h"
#include "copyleft.h"
-#include "random.h"
#include "signal.h"
static char *set_pager=0;
#endif /* !USE_INTERNAL_PAGER */
-static unsigned long set_seed;
-static int seed_flag=0;
+static gsl_rng *rng;
static int long_view=0;
int set_testing_mode=0;
static int set_ccx (const char *cc_string, struct set_cust_currency * cc,
int cc_name);
+static void set_rng (unsigned long);
+static unsigned long random_seed (void);
+
/* (specification)
"SET" (stc_):
automenu=automenu:on/off;
static int
aux_stc_custom_seed(struct cmd_set *cmd UNUSED)
{
- msg(MM, "%ld",set_seed);
return 0;
}
{
lex_match ('=');
if (lex_match_id ("RANDOM"))
- set_seed = random_seed();
+ set_rng (random_seed ());
else
{
if (!lex_force_num ())
return 0;
- set_seed = tokval;
+ set_rng (tokval);
lex_get ();
}
- seed_flag = 1;
return 1;
}
/* Public functions */
+void
+done_settings(void)
+{
+ if ( rng )
+ gsl_rng_free (rng);
+ free (set_pager);
+ free (set_journal);
+
+ free (cmd.s_endcmd);
+ free (cmd.s_prompt);
+ free (cmd.s_cprompt);
+ free (cmd.s_dprompt);
+}
+
+
+
void
init_settings(void)
{
cmd.safe = STC_OFF;
cmd.dec = STC_DOT;
- cmd.n_cpi = 6;
- cmd.n_lpi = 10;
+ cmd.n_cpi[0] = 6;
+ cmd.n_lpi[0] = 10;
cmd.echo = STC_OFF;
cmd.more = STC_ON;
cmd.headers = STC_YES;
set_journal = xstrdup ("pspp.jnl");
set_journaling = 1;
- cmd.n_mxwarns = 100;
- cmd.n_mxerrs = 100;
- cmd.n_mxloops = 1;
- cmd.n_workspace = 4L * 1024 * 1024;
+ cmd.n_mxwarns[0] = 100;
+ cmd.n_mxerrs[0] = 100;
+ cmd.n_mxloops[0] = 1;
+ cmd.n_workspace[0] = 4L * 1024 * 1024;
#if !USE_INTERNAL_PAGER
{
- char *pager;
+ const char *pager = getenv ("STAT_PAGER");
- pager = getenv ("STAT_PAGER");
- if (!pager) set_pager = getenv ("PAGER");
+ if (!pager)
+ set_pager = xstrdup (getenv ("PAGER") );
if (pager)
set_pager = xstrdup (pager);
int
get_mxwarns(void)
{
- return cmd.n_mxwarns;
+ return cmd.n_mxwarns[0];
}
int
get_mxerrs(void)
{
- return cmd.n_mxerrs;
+ return cmd.n_mxerrs[0];
}
int
int
get_mxloops(void)
{
- return cmd.n_mxloops;
+ return cmd.n_mxloops[0];
}
int
size_t
get_max_workspace(void)
{
- return cmd.n_workspace;
+ return cmd.n_workspace[0];
}
double
return set_pager;
}
-/* Return 1 if the seed has been set since the last time this function
- was called.
- Fill the value pointed to by seed with the seed .
-*/
-int
-seed_is_set(unsigned long *seed)
+gsl_rng *
+get_rng (void)
{
- int result = 0;
-
- *seed = set_seed ;
-
- if ( seed_flag )
- result = 1;
-
- seed_flag = 0;
+ if (rng == NULL)
+ set_rng (random_seed ());
+ return rng;
+}
- return result;
-
+static void
+set_rng (unsigned long seed)
+{
+ rng = gsl_rng_alloc (gsl_rng_mt19937);
+ if (rng == NULL)
+ out_of_memory ();
+ gsl_rng_set (rng, seed);
}
+static unsigned long
+random_seed (void)
+{
+ return time (0);
+}
static int global_algorithm = ENHANCED;
static int cmd_algorithm = ENHANCED;