projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed a bug which caused a crash when reading non-existent files.
[pspp]
/
src
/
set.q
diff --git
a/src/set.q
b/src/set.q
index 4c2d66a3a1d6b450b99837313f602ab34b0ab35f..620961b59ca46415e50647625aa76feed43ca0b5 100644
(file)
--- a/
src/set.q
+++ b/
src/set.q
@@
-64,6
+64,7
@@
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
+#include <time.h>
#include "alloc.h"
#include "command.h"
#include "lexer.h"
#include "alloc.h"
#include "command.h"
#include "lexer.h"
@@
-74,7
+75,6
@@
#include "var.h"
#include "format.h"
#include "copyleft.h"
#include "var.h"
#include "format.h"
#include "copyleft.h"
-#include "random.h"
#include "signal.h"
#include "signal.h"
@@
-106,8
+106,7
@@
static int set_listing=1;
static char *set_pager=0;
#endif /* !USE_INTERNAL_PAGER */
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 long_view=0;
int set_testing_mode=0;
@@
-122,6
+121,9
@@
static void set_routing (int q, int *setting);
static int set_ccx (const char *cc_string, struct set_cust_currency * cc,
int cc_name);
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;
/* (specification)
"SET" (stc_):
automenu=automenu:on/off;
@@
-301,7
+303,6
@@
aux_stc_custom_results(struct cmd_set *cmd UNUSED)
static int
aux_stc_custom_seed(struct cmd_set *cmd UNUSED)
{
static int
aux_stc_custom_seed(struct cmd_set *cmd UNUSED)
{
- msg(MM, "%ld",set_seed);
return 0;
}
return 0;
}
@@
-704,15
+705,14
@@
stc_custom_seed (struct cmd_set *cmd UNUSED)
{
lex_match ('=');
if (lex_match_id ("RANDOM"))
{
lex_match ('=');
if (lex_match_id ("RANDOM"))
- set_
seed = random_seed(
);
+ set_
rng (random_seed ()
);
else
{
if (!lex_force_num ())
return 0;
else
{
if (!lex_force_num ())
return 0;
- set_
seed = tokval
;
+ set_
rng (tokval)
;
lex_get ();
}
lex_get ();
}
- seed_flag = 1;
return 1;
}
return 1;
}
@@
-1051,6
+1051,22
@@
set_viewport(int sig_num UNUSED)
/* Public functions */
/* 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)
{
void
init_settings(void)
{
@@
-1088,10
+1104,18
@@
init_settings(void)
#if !USE_INTERNAL_PAGER
{
#if !USE_INTERNAL_PAGER
{
- c
har *pager
;
+ c
onst char *pager = getenv ("STAT_PAGER")
;
- pager = getenv ("STAT_PAGER");
- if (!pager) set_pager = getenv ("PAGER");
+ if (!pager)
+ {
+ const char *p = getenv ("PAGER");
+
+ if ( p != NULL )
+ set_pager = xstrdup (p);
+ else
+ set_pager = 0;
+ }
+
if (pager)
set_pager = xstrdup (pager);
if (pager)
set_pager = xstrdup (pager);
@@
-1313,26
+1337,28
@@
get_pager(void)
return set_pager;
}
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;
static int global_algorithm = ENHANCED;
static int cmd_algorithm = ENHANCED;