settings: Make viewwidth, viewlength "int"s instead of pointers.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Aug 2010 18:37:19 +0000 (11:37 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Aug 2010 21:57:56 +0000 (14:57 -0700)
I don't recall exactly why these were pointers any longer, but it doesn't
seem to be necessary any longer.  It is more straightforward if they are
just stored in the same way as the other settings.

src/data/settings.c
src/data/settings.h
src/ui/gui/psppire.c
src/ui/terminal/main.c
src/ui/terminal/terminal.c

index b98a1351ac0eee0855222b9c341c1f04ec0da54f..a5fbfdecbda658eed3b16e94be686c62423cd485 100644 (file)
@@ -49,8 +49,8 @@ struct settings
   /* Format of reals in output (SET WRB). */
   enum float_format output_float_format;
 
-  int *viewlength;
-  int *viewwidth;
+  int viewlength;
+  int viewwidth;
   bool safer_mode;
   bool include;
   int epoch;
@@ -83,8 +83,8 @@ static struct settings the_settings = {
   FLOAT_NATIVE_DOUBLE,          /* input_float_format */
   INTEGER_NATIVE,               /* output_integer_format */
   FLOAT_NATIVE_DOUBLE,          /* output_float_format */
-  NULL,                         /* viewlength */
-  NULL,                         /* viewwidth */
+  24,                           /* viewlength */
+  79,                           /* viewwidth */
   false,                        /* safer_mode */
   true,                         /* include */
   -1,                           /* epoch */
@@ -121,12 +121,9 @@ static struct settings the_settings = {
    SETTINGS_DEVICE_LISTING | SETTINGS_DEVICE_TERMINAL}
 };
 
-static void init_viewport ( int *, int *);
-
 void
-settings_init (int *width, int *length)
+settings_init (void)
 {
-  init_viewport (width, length);
   settings_set_epoch (-1);
   the_settings.styles = fmt_settings_create ();
 
@@ -203,35 +200,28 @@ settings_set_output_float_format ( enum float_format float_format)
 int
 settings_get_viewlength (void)
 {
-  return *the_settings.viewlength;
+  return the_settings.viewlength;
 }
 
 /* Sets the view length. */
 void
 settings_set_viewlength ( int viewlength_)
 {
-  *the_settings.viewlength = viewlength_;
+  the_settings.viewlength = viewlength_;
 }
 
 /* Screen width. */
 int
 settings_get_viewwidth(void)
 {
-  return *the_settings.viewwidth;
+  return the_settings.viewwidth;
 }
 
 /* Sets the screen width. */
 void
 settings_set_viewwidth ( int viewwidth_)
 {
-  *the_settings.viewwidth = viewwidth_;
-}
-
-static void
-init_viewport ( int  *width, int *length)
-{
-  the_settings.viewwidth = width;
-  the_settings.viewlength = length;
+  the_settings.viewwidth = viewwidth_;
 }
 
 /* Whether PSPP can erase and overwrite files. */
index 7dcb0e34a479c2d5bf18cd431cd810e626decc6f..27ba0cee1a9d1267220bfcd013f6676bbac90b3f 100644 (file)
@@ -28,7 +28,7 @@
 struct caseproto;
 struct settings;
 
-void settings_init (int *, int *);
+void settings_init (void);
 void settings_done (void);
 
 enum float_format settings_get_input_float_format (void);
index d75bff359b1d33aac4b0d8f177a259e47d014903..089208148defdebb240659e85a85dfa12605ed9e 100644 (file)
@@ -96,7 +96,7 @@ initialize (struct source_stream *ss, const char *data_file)
   preregister_widgets ();
 
   gsl_set_error_handler_off ();
-  settings_init (&viewer_width, &viewer_length);
+  settings_init ();
   fh_init ();
 
   the_dataset = create_dataset ();
index 02be4f78c0e777f1e93df1719fc7fc0ed48f13f2..94b21a55742855a05974afae7d0c41d0cf30c392 100644 (file)
@@ -79,7 +79,6 @@ static struct source_stream *the_source_stream ;
 int
 main (int argc, char **argv)
 {
-  int *view_width_p, *view_length_p;
   struct terminal_opts *terminal_opts;
   struct argv_parser *parser;
 
@@ -98,8 +97,8 @@ main (int argc, char **argv)
   the_source_stream = create_source_stream ();
   prompt_init ();
   readln_initialize ();
-  terminal_init (&view_width_p, &view_length_p);
-  settings_init (view_width_p, view_length_p);
+  settings_init ();
+  terminal_check_size ();
   random_init ();
 
   the_dataset = create_dataset ();
index 7360b892ca7c6051a200798da7179f21590aaffd..f387c5112a86efc9b950c2e73aaf6d35431afb23 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2007, 2010 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
 
 #include <config.h>
 
-#include <ui/terminal/terminal.h>
+#include "ui/terminal/terminal.h"
 
 #include <stdbool.h>
 #include <stdlib.h>
 
-#include <libpspp/compiler.h>
+#include "data/settings.h"
+#include "libpspp/compiler.h"
 
-#include "error.h"
+#include "gl/error.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
-static int view_width = -1;
-static int view_length = -1;
-
-/* Initializes the terminal interface by determining the size of
-   the user's terminal.  Stores a pointer to the size variables
-   in *VIEW_WIDTH_P and *VIEW_LENGTH_P. */
-void
-terminal_init (int **view_width_p, int **view_length_p)
-{
-  *view_width_p = &view_width;
-  *view_length_p = &view_length;
-  terminal_check_size ();
-}
-
 /* Code that interfaces to ncurses.  This must be at the very end
    of this file because curses.h redefines "bool" on some systems
    (e.g. OpenBSD), causing declaration mismatches with functions
@@ -56,6 +43,9 @@ terminal_init (int **view_width_p, int **view_length_p)
 void
 terminal_check_size (void)
 {
+  int view_width = 0;
+  int view_length = 0;
+
 #if LIBNCURSES_USABLE
   if (getenv ("TERM") != NULL)
     {
@@ -74,19 +64,13 @@ terminal_check_size (void)
     }
 #endif
 
-  if (view_width <= 0)
-    {
-      if (getenv ("COLUMNS") != NULL)
-        view_width = atoi (getenv ("COLUMNS"));
-      if (view_width <= 0)
-        view_width = 79;
-    }
+  if (view_width <= 0 && getenv ("COLUMNS") != NULL)
+    view_width = atoi (getenv ("COLUMNS"));
+  if (view_width > 0)
+    settings_set_viewwidth (view_width);
 
-  if (view_length <= 0)
-    {
-      if (getenv ("LINES") != NULL)
-        view_length = atoi (getenv ("LINES"));
-      if (view_length <= 0)
-        view_length = 24;
-    }
+  if (view_length <= 0 && getenv ("LINES") != NULL)
+    view_length = atoi (getenv ("LINES"));
+  if (view_length > 0)
+    settings_set_viewlength (view_length);
 }