pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] pspp/src ChangeLog Makefile.am error.c format.c...


From: John Darrington
Subject: [Pspp-cvs] pspp/src ChangeLog Makefile.am error.c format.c...
Date: Mon, 19 Dec 2005 06:42:32 +0000

CVSROOT:        /cvsroot/pspp
Module name:    pspp
Branch:         
Changes by:     John Darrington <address@hidden>        05/12/19 06:42:32

Modified files:
        src            : ChangeLog Makefile.am error.c format.c getl.c 
                         getl.h main.c settings.c settings.h 
Added files:
        src            : readln.c readln.h 

Log message:
        Separated getl.c into getl.c and readln.c

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/ChangeLog.diff?tr1=1.254&tr2=1.255&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/Makefile.am.diff?tr1=1.60&tr2=1.61&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/error.c.diff?tr1=1.19&tr2=1.20&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/format.c.diff?tr1=1.18&tr2=1.19&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/getl.c.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/getl.h.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/main.c.diff?tr1=1.19&tr2=1.20&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/readln.c?rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/readln.h?rev=1.1
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/settings.c.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/settings.h.diff?tr1=1.12&tr2=1.13&r1=text&r2=text

Patches:
Index: pspp/src/ChangeLog
diff -u pspp/src/ChangeLog:1.254 pspp/src/ChangeLog:1.255
--- pspp/src/ChangeLog:1.254    Fri Dec 16 01:14:39 2005
+++ pspp/src/ChangeLog  Mon Dec 19 06:42:32 2005
@@ -1,3 +1,9 @@
+Mon Dec 19 14:01:56 WST 2005 John Darrington <address@hidden>
+
+       * format.c: Additional error checking.
+       * getl.[ch]: Separated into getl.c and readln.c
+       * settings.[ch]: Made CC_CNT public
+
 Fri Dec 16 09:11:48 WST 2005 John Darrington <address@hidden>
 
        * examine.q: Fixed buglet when cleaning up at end of procedure.
Index: pspp/src/Makefile.am
diff -u pspp/src/Makefile.am:1.60 pspp/src/Makefile.am:1.61
--- pspp/src/Makefile.am:1.60   Wed Dec 14 06:59:06 2005
+++ pspp/src/Makefile.am        Mon Dec 19 06:42:32 2005
@@ -190,6 +190,8 @@
        random.h                                \
        range-prs.c                             \
        range-prs.h                             \
+       readln.c                                \
+       readln.h                                \
        recode.c                                \
        rename-vars.c                           \
        repeat.c                                \
Index: pspp/src/error.c
diff -u pspp/src/error.c:1.19 pspp/src/error.c:1.20
--- pspp/src/error.c:1.19       Wed Dec 14 06:59:06 2005
+++ pspp/src/error.c    Mon Dec 19 06:42:32 2005
@@ -201,7 +201,11 @@
 void
 err_done (void) 
 {
-  free (file_loc);
+  lex_done();
+  getl_uninitialize ();
+  readln_uninitialize();
+
+  free(file_loc);
   file_loc = NULL;
   nfile_loc = mfile_loc = 0;
 }
Index: pspp/src/format.c
diff -u pspp/src/format.c:1.18 pspp/src/format.c:1.19
--- pspp/src/format.c:1.18      Wed Oct 26 00:50:44 2005
+++ pspp/src/format.c   Mon Dec 19 06:42:32 2005
@@ -64,8 +64,19 @@
 static bool
 check_common_specifier (const struct fmt_spec *spec, bool emit_error)
 {
-  struct fmt_desc *f = &formats[spec->type];
-  char *str = fmt_to_string (spec);
+  struct fmt_desc *f ; 
+  char *str;
+
+  if ( spec->type > FMT_NUMBER_OF_FORMATS ) 
+    {
+      if (emit_error)
+        msg (SE, _("Format specifies a bad type (%d)"), spec->type);
+      
+      return false;
+    }
+
+  f = &formats[spec->type];
+  str = fmt_to_string (spec);
 
   if ((f->cat & FCAT_EVEN_WIDTH) && spec->w % 2)
     {
@@ -92,11 +103,16 @@
 int
 check_input_specifier (const struct fmt_spec *spec, int emit_error)
 {
-  struct fmt_desc *f = &formats[spec->type];
-  char *str = fmt_to_string (spec);
+  struct fmt_desc *f ;
+  char *str ;
 
   if (!check_common_specifier (spec, emit_error))
     return false;
+
+  f = &formats[spec->type];
+  str = fmt_to_string (spec);
+
+
   if (spec->type == FMT_X)
     return 1;
   if (f->cat & FCAT_OUTPUT_ONLY)
@@ -131,11 +147,15 @@
 int
 check_output_specifier (const struct fmt_spec *spec, int emit_error)
 {
-  struct fmt_desc *f = &formats[spec->type];
-  char *str = fmt_to_string (spec);
+  struct fmt_desc *f;
+  char *str ; 
 
   if (!check_common_specifier (spec, emit_error))
     return false;
+
+  f = &formats[spec->type];
+  str = fmt_to_string (spec);
+
   if (spec->type == FMT_X)
     return 1;
   if (spec->w < f->Omin_w || spec->w > f->Omax_w)
Index: pspp/src/getl.c
diff -u pspp/src/getl.c:1.2 pspp/src/getl.c:1.3
--- pspp/src/getl.c:1.2 Sun Dec 11 02:48:45 2005
+++ pspp/src/getl.c     Mon Dec 19 06:42:32 2005
@@ -38,36 +38,6 @@
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
-/* Global variables. */
-struct string getl_buf;
-struct getl_script *getl_head;
-struct getl_script *getl_tail;
-int getl_interactive;
-int getl_welcomed;
-int getl_mode;
-int getl_prompt;
-
-#if HAVE_LIBREADLINE
-#include <readline/readline.h>
-#endif
-
-#if HAVE_LIBHISTORY
-static char *history_file;
-
-#if HAVE_READLINE_HISTORY_H
-#include <readline/history.h>
-#else /* no readline/history.h */
-extern void add_history (char *);
-extern void using_history (void);
-extern int read_history (char *);
-extern void stifle_history (int);
-extern int write_history (char *);
-#endif /* no readline/history.h */
-#endif /* -lhistory */
-
-
-extern struct cmd_set cmd;
-
 static struct string getl_include_path;
 
 /* Number of levels of DO REPEAT structures we're nested inside.  If
@@ -75,7 +45,8 @@
    performed. */
 static int DO_REPEAT_level;
 
-static int read_console (void);
+struct string getl_buf;
+
 
 /* Initialize getl. */
 void
@@ -84,9 +55,6 @@
   ds_create (&getl_include_path,
             fn_getenv_default ("STAT_INCLUDE_PATH", include_path));
   ds_init (&getl_buf, 256);
-#if HAVE_LIBREADLINE 
-  rl_completion_entry_function = pspp_completion_function;
-#endif
 }
 
 /* Close getl. */
@@ -94,14 +62,15 @@
 getl_uninitialize (void)
 {
   getl_close_all();
-#if HAVE_LIBHISTORY && defined (unix)
-  if (history_file)
-    write_history (history_file);
-#endif
   ds_destroy (&getl_buf);
   ds_destroy (&getl_include_path);
 }
 
+
+struct getl_script *getl_head;
+struct getl_script *getl_tail;
+
+
 /* Returns a string that represents the directory that the syntax file
    currently being read resides in.  If there is no syntax file then
    returns the OS current working directory.  Return value must be
@@ -227,7 +196,6 @@
 void
 getl_add_DO_REPEAT_file (struct getl_script *file)
 {
-  /* getl_head == NULL can't happen. */
   assert (getl_head);
 
   DO_REPEAT_level++;
@@ -242,28 +210,11 @@
   file->f = NULL;
 }
 
-/* Display a welcoming message. */
-static void
-welcome (void)
-{
-  getl_welcomed = 1;
-  fputs ("PSPP is free software and you are welcome to distribute copies of "
-        "it\nunder certain conditions; type \"show copying.\" to see the "
-        "conditions.\nThere is ABSOLUTELY NO WARRANTY for PSPP; type \"show "
-        "warranty.\" for details.\n", stdout);
-  puts (stat_version);
-}
-
-/* Reads a single line from the user's terminal. */
-
-/* From repeat.c. */
-extern void perform_DO_REPEAT_substitutions (void);
-  
 /* Reads a single line from the line buffer associated with getl_head.
    Returns 1 if a line was successfully read or 0 if no more lines are
    available. */
-static int
-handle_line_buffer (void)
+int
+getl_handle_line_buffer (void)
 {
   struct getl_script *s = getl_head;
 
@@ -297,84 +248,6 @@
   return 1;
 }
 
-/* Reads a single line into getl_buf from the list of files.  Will not
-   read from the eof of one file to the beginning of another unless
-   the options field on the new file's getl_script is nonzero.  Return
-   zero on eof. */
-int
-getl_read_line (void)
-{
-  getl_mode = GETL_MODE_BATCH;
-  
-  while (getl_head)
-    {
-      struct getl_script *s = getl_head;
-
-      ds_clear (&getl_buf);
-      if (s->separate)
-       return 0;
-
-      if (s->first_line)
-       {
-         if (!handle_line_buffer ())
-           {
-             getl_close_file ();
-             continue;
-           }
-         perform_DO_REPEAT_substitutions ();
-         if (getl_head->print)
-           tab_output_text (TAB_LEFT | TAT_FIX | TAT_PRINTF, "+%s",
-                            ds_c_str (&getl_buf));
-         return 1;
-       }
-      
-      if (s->f == NULL)
-       {
-         msg (VM (1), _("%s: Opening as syntax file."), s->fn);
-         s->f = fn_open (s->fn, "r");
-
-         if (s->f == NULL)
-           {
-             msg (ME, _("Opening `%s': %s."), s->fn, strerror (errno));
-             getl_close_file ();
-             continue;
-           }
-       }
-
-      if (!ds_gets (&getl_buf, s->f))
-       {
-         if (ferror (s->f))
-           msg (ME, _("Reading `%s': %s."), s->fn, strerror (errno));
-         getl_close_file ();
-         continue;
-       }
-      if (ds_length (&getl_buf) > 0 && ds_end (&getl_buf)[-1] == '\n')
-       ds_truncate (&getl_buf, ds_length (&getl_buf) - 1);
-
-      if (get_echo())
-       tab_output_text (TAB_LEFT | TAT_FIX, ds_c_str (&getl_buf));
-
-      getl_head->ln++;
-
-      /* Allows shebang invocation: `#! /usr/local/bin/pspp'. */
-      if (ds_c_str (&getl_buf)[0] == '#'
-         && ds_c_str (&getl_buf)[1] == '!')
-       continue;
-
-      return 1;
-    }
-
-  if (getl_interactive == 0)
-    return 0;
-
-  getl_mode = GETL_MODE_INTERACTIVE;
-  
-  if (getl_welcomed == 0)
-    welcome ();
-
-  return read_console ();
-}
-
 /* Closes the current file, whether it be a main file or included
    file, then moves getl_head to the next file in the chain. */
 void
@@ -420,90 +293,6 @@
   free (s);
 }
 
-/* PORTME: Adapt to your local system's idea of the terminal. */
-#if HAVE_LIBREADLINE
-
-#if HAVE_READLINE_READLINE_H
-#include <readline/readline.h>
-#else /* no readline/readline.h */
-extern char *readline (char *);
-#endif /* no readline/readline.h */
-
-static int
-read_console (void)
-{
-  char *line;
-  const char *prompt;
-
-  err_error_count = err_warning_count = 0;
-  err_already_flagged = 0;
-
-#if HAVE_LIBHISTORY
-  if (!history_file)
-    {
-#ifdef unix
-      history_file = tilde_expand (HISTORY_FILE);
-#endif
-      using_history ();
-      read_history (history_file);
-      stifle_history (MAX_HISTORY);
-    }
-#endif /* -lhistory */
-
-  switch (getl_prompt)
-    {
-    case GETL_PRPT_STANDARD:
-      prompt = get_prompt ();
-      break;
-
-    case GETL_PRPT_CONTINUATION:
-      prompt = get_cprompt ();
-      break;
-
-    case GETL_PRPT_DATA:
-      prompt = get_dprompt ();
-      break;
-
-    default:
-      assert (0);
-      abort ();
-    }
-
-  line = readline (prompt);
-  if (!line)
-    return 0;
-
-#if HAVE_LIBHISTORY
-  if (*line)
-    add_history (line);
-#endif
-
-  ds_clear (&getl_buf);
-  ds_puts (&getl_buf, line);
-
-  free (line);
-
-  return 1;
-}
-#else /* no -lreadline */
-static int
-read_console (void)
-{
-  err_error_count = err_warning_count = 0;
-  err_already_flagged = 0;
-
-  fputs (getl_prompt ? get_cprompt() : get_prompt(), stdout);
-  ds_clear (&getl_buf);
-  if (ds_gets (&getl_buf, stdin))
-    return 1;
-
-  if (ferror (stdin))
-    msg (FE, "stdin: fgets(): %s.", strerror (errno));
-
-  return 0;
-}
-#endif /* no -lreadline */
-
 /* Closes all files. */
 void
 getl_close_all (void)
@@ -512,22 +301,21 @@
     getl_close_file ();
 }
 
-/* Sets the options flag of the current script to 0, thus allowing it
-   to be read in.  Returns nonzero if this action was taken, zero
-   otherwise. */
-int
-getl_perform_delayed_reset (void)
+bool
+getl_is_separate(void)
 {
-  if (getl_head && getl_head->separate)
-    {
-      getl_head->separate = 0;
-      discard_variables ();
-      lex_reset_eof ();
-      return 1;
-    }
-  return 0;
+  return (getl_head && getl_head->separate);
+}
+
+void
+getl_set_separate(bool sep)
+{
+  assert (getl_head);
+
+  getl_head->separate = sep ;
 }
 
+
 /* Puts the current file and line number in *FN and *LN, respectively,
    or NULL and -1 if none. */
 void
@@ -538,3 +326,10 @@
   if (ln != NULL)
     *ln = getl_head ? getl_head->ln : -1;
 }
+
+bool 
+getl_reading_script (void)
+{
+  return (getl_head != NULL);
+}
+
Index: pspp/src/getl.h
diff -u pspp/src/getl.h:1.1 pspp/src/getl.h:1.2
--- pspp/src/getl.h:1.1 Sun Jul 31 21:42:46 2005
+++ pspp/src/getl.h     Mon Dec 19 06:42:32 2005
@@ -20,6 +20,7 @@
 #if !getl_h
 #define getl_h 1
 
+#include <stdbool.h>
 #include <stdio.h>
 
 /* Defines a list of lines used by DO REPEAT. */
@@ -88,7 +89,8 @@
 
 /* Are we reading a script? Are we interactive? */
 #define getl_am_interactive (getl_head == NULL)
-#define getl_reading_script (getl_head != NULL)
+
+bool getl_reading_script (void);
 
 /* Current line.  This line may be modified by modules other than
    getl.c, and by lexer.c in particular. */
@@ -113,5 +115,11 @@
 void getl_add_DO_REPEAT_file (struct getl_script *);
 void getl_add_virtual_file (struct getl_script *);
 void getl_location (const char **, int *);
+int getl_handle_line_buffer (void);
+
+bool getl_is_separate(void);
+
+void getl_set_separate(bool sep);
+
 
 #endif /* getl_h */
Index: pspp/src/main.c
diff -u pspp/src/main.c:1.19 pspp/src/main.c:1.20
--- pspp/src/main.c:1.19        Wed Dec 14 06:59:06 2005
+++ pspp/src/main.c     Mon Dec 19 06:42:32 2005
@@ -34,6 +34,7 @@
 #include "output.h"
 #include "progname.h"
 #include "random.h"
+#include "readln.h"
 #include "settings.h"
 #include "var.h"
 #include "version.h"
@@ -92,6 +93,7 @@
   fn_init ();
   fh_init ();
   getl_initialize ();
+  readln_initialize ();
   settings_init ();
   random_init ();
 
@@ -155,7 +157,16 @@
       if (token != T_STOP)
        break;
 
-      if (!getl_perform_delayed_reset ())
+      /* Sets the options flag of the current script to 0, thus allowing it
+        to be read in.  Returns nonzero if this action was taken, zero
+        otherwise. */
+      if (getl_head && getl_head->separate)
+       {
+         getl_head->separate = 0;
+         discard_variables ();
+         lex_reset_eof ();
+       }
+      else
        terminate (err_error_count == 0);
     }
 
Index: pspp/src/settings.c
diff -u pspp/src/settings.c:1.3 pspp/src/settings.c:1.4
--- pspp/src/settings.c:1.3     Wed Dec 14 06:59:06 2005
+++ pspp/src/settings.c Mon Dec 19 06:42:32 2005
@@ -67,7 +67,6 @@
 
 static struct fmt_spec default_format = {FMT_F, 8, 2};
 
-#define CC_CNT 5
 #define CC_INITIALIZER {"-", "", "", "", '.', ','}
 static struct custom_currency cc[CC_CNT] = 
   {
Index: pspp/src/settings.h
diff -u pspp/src/settings.h:1.12 pspp/src/settings.h:1.13
--- pspp/src/settings.h:1.12    Wed Dec 14 06:59:06 2005
+++ pspp/src/settings.h Mon Dec 19 06:42:32 2005
@@ -101,6 +101,9 @@
 const struct fmt_spec *get_format (void);
 void set_format (const struct fmt_spec *);
 
+/* Maximum number of custom currency specifications */
+#define CC_CNT 5
+
 /* One custom currency specification. */
 #define CC_WIDTH 16
 struct custom_currency




reply via email to

[Prev in Thread] Current Thread [Next in Thread]