X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fset.q;h=120606fb66eddc3822a1f370fda4f5c9c42778fe;hb=d043fde2b737897e3372670afc47eb648c17624b;hp=2d1a1699c0b451421a7ea91db04dbda6bff93364;hpb=205ac3afa4c2b19c85819d8695abf3975bb11807;p=pspp-builds.git diff --git a/src/set.q b/src/set.q index 2d1a1699..120606fb 100644 --- a/src/set.q +++ b/src/set.q @@ -64,6 +64,7 @@ #include #include #include +#include #include "alloc.h" #include "command.h" #include "lexer.h" @@ -74,7 +75,6 @@ #include "var.h" #include "format.h" #include "copyleft.h" -#include "random.h" #include "signal.h" @@ -106,8 +106,7 @@ static int set_listing=1; 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; @@ -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 void set_rng (unsigned long); +static unsigned long random_seed (void); + /* (specification) "SET" (stc_): automenu=automenu:on/off; @@ -158,7 +160,7 @@ static int set_ccx (const char *cc_string, struct set_cust_currency * cc, listing=custom; log=custom; lowres=lores:auto/on/off; - lpi=integer "x>0" "% must be greater than 0"; + lpi=integer "x>0" "%s must be greater than 0"; menus=menus:standard/extended; messages=messages:on/off/terminal/listing/both/none; mexpand=mexp: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) { - msg(MM, "%ld",set_seed); return 0; } @@ -595,7 +596,7 @@ stc_custom_pager (struct cmd_set *cmd UNUSED) return 0; if (set_pager) free (set_pager); - set_pager = xstrdup (ds_value (&tokstr)); + set_pager = xstrdup (ds_c_str (&tokstr)); lex_get (); } return 1; @@ -704,15 +705,14 @@ stc_custom_seed (struct cmd_set *cmd UNUSED) { 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; } @@ -776,7 +776,7 @@ stc_custom_journal (struct cmd_set *cmd UNUSED) set_journaling = 0; if (token == T_STRING) { - set_journal = xstrdup (ds_value (&tokstr)); + set_journal = xstrdup (ds_c_str (&tokstr)); lex_get (); } return 1; @@ -985,11 +985,8 @@ set_viewport(int sig_num UNUSED) static char term_buffer[16384]; #endif - /* Workable defaults before we determine the real terminal size. */ - set_viewwidth = 79; - set_viewlength = 24; - - + set_viewwidth = -1; + set_viewlength = -1; #if __DJGPP__ || __BORLANDC__ { @@ -1007,7 +1004,7 @@ set_viewport(int sig_num UNUSED) /* This code stolen from termcap.info, though modified. */ termtype = getenv ("TERM"); if (!termtype) - msg (FE, _("Specify a terminal type with `setenv TERM '.")); + msg (FE, _("Specify a terminal type with the TERM environment variable.")); success = tgetent (term_buffer, termtype); if (success <= 0) @@ -1019,27 +1016,57 @@ set_viewport(int sig_num UNUSED) } else { - set_viewlength = tgetnum ("li"); - set_viewwidth = tgetnum ("co") - 1; + /* NOTE: Do not rely upon tgetnum returning -1 if the value is + not available. It's supposed to do it, but not all platforms + do (eg Cygwin) . + */ + if ( -1 != tgetnum("li")) + set_viewlength = tgetnum ("li"); + + if ( -1 != tgetnum("co")) + set_viewwidth = tgetnum ("co") - 1; } } -#else - { - char *s; +#endif /* HAVE_LIBTERMCAP */ /* Try the environment variables */ - s = getenv("COLUMNS"); - if ( s ) set_viewwidth = atoi(s); + if ( -1 == set_viewwidth ) + { + char *s = getenv("COLUMNS"); + if ( s ) set_viewwidth = atoi(s); + } + + if ( -1 == set_viewwidth ) + { + char *s = getenv("LINES"); + if ( s ) set_viewlength = atoi(s); + } - s = getenv("LINES"); - if ( s ) set_viewlength = atoi(s); - } -#endif /* !HAVE_LIBTERMCAP */ + + /* Last resort. Use hard coded values */ + if ( 0 > set_viewwidth ) set_viewwidth = 79; + if ( 0 > set_viewlength ) set_viewlength = 24; } /* 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) { @@ -1052,8 +1079,8 @@ 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; @@ -1069,10 +1096,10 @@ init_settings(void) 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 @@ -1200,13 +1227,13 @@ get_undefined(void) 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 @@ -1224,7 +1251,7 @@ get_printback(void) int get_mxloops(void) { - return cmd.n_mxloops; + return cmd.n_mxloops[0]; } int @@ -1249,7 +1276,7 @@ get_endcmd(void) size_t get_max_workspace(void) { - return cmd.n_workspace; + return cmd.n_workspace[0]; } double @@ -1302,24 +1329,76 @@ get_pager(void) 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; + if (rng == NULL) + set_rng (random_seed ()); + return rng; +} - *seed = set_seed ; +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); +} - if ( seed_flag ) - result = 1; - - seed_flag = 0; +static unsigned long +random_seed (void) +{ + return time (0); +} - return result; - +static int global_algorithm = ENHANCED; +static int cmd_algorithm = ENHANCED; +static int *algorithm = &global_algorithm; + +static int syntax = ENHANCED; + +/* Set the algorithm option globally */ +void +set_algorithm(int x) +{ + global_algorithm = x; +} + +/* Set the algorithm option for this command only */ +void +set_cmd_algorithm(int x) +{ + cmd_algorithm = x; + algorithm = &cmd_algorithm; +} + +/* Unset the algorithm option for this command */ +void +unset_cmd_algorithm(void) +{ + algorithm = &global_algorithm; +} + +/* Return the current algorithm setting */ +int +get_algorithm(void) +{ + return *algorithm; +} + +/* Set the syntax option */ +void +set_syntax(int x) +{ + syntax = x; +} + +/* Get the current syntax setting */ +int +get_syntax(void) +{ + return syntax; }