pspp-cvs
[Top][All Lists]
Advanced

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

[Pspp-cvs] pspp/src language/ChangeLog language/command.c ...


From: Ben Pfaff
Subject: [Pspp-cvs] pspp/src language/ChangeLog language/command.c ...
Date: Wed, 28 Jun 2006 05:49:04 +0000

CVSROOT:        /cvsroot/pspp
Module name:    pspp
Changes by:     Ben Pfaff <blp> 06/06/28 05:49:04

Modified files:
        src/language   : ChangeLog command.c command.h line-buffer.c 
                         line-buffer.h 
        src/language/data-io: ChangeLog inpt-pgm.c 
        src/ui/terminal: ChangeLog main.c read-line.c read-line.h 

Log message:
        Fix regression in command name completion reported by John Darrington.
        Now completion is again state-dependent and occurs only on the first
        line of a command.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/ChangeLog?cvsroot=pspp&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/command.c?cvsroot=pspp&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/command.h?cvsroot=pspp&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/line-buffer.c?cvsroot=pspp&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/line-buffer.h?cvsroot=pspp&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/data-io/ChangeLog?cvsroot=pspp&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/pspp/src/language/data-io/inpt-pgm.c?cvsroot=pspp&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/pspp/src/ui/terminal/ChangeLog?cvsroot=pspp&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/pspp/src/ui/terminal/main.c?cvsroot=pspp&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/pspp/src/ui/terminal/read-line.c?cvsroot=pspp&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/pspp/src/ui/terminal/read-line.h?cvsroot=pspp&r1=1.2&r2=1.3

Patches:
Index: language/ChangeLog
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/ChangeLog,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- language/ChangeLog  6 May 2006 20:27:23 -0000       1.7
+++ language/ChangeLog  28 Jun 2006 05:49:03 -0000      1.8
@@ -1,3 +1,30 @@
+Tue Jun 27 22:36:38 2006  Ben Pfaff  <address@hidden>
+
+       Fix regression in command name completion reported by John
+       Darrington.  Now completion is again state-dependent and occurs
+       only on the first line of a command.
+       
+       * command.c (do_parse_command): Move reading the first token of
+       the command here, from execute_command and cmd_input_program.
+       Call set_completion_state and getl_set_prompt_style here.
+       (do_parse_command) Use in_correct_state instead of
+       verify_valid_command.
+       (verify_valid_command) Break into two new functions,
+       in_correct_state and report_state_mismatch.
+       (set_completion_state) New function.
+       (cmd_complete) New function.
+       [HAVE_READLINE] (pspp_attempted_completion_function) Removed.
+       [HAVE_READLINE] (command_generator) Removed.
+
+       * line-buffer.c: (struct getl_source) Change `interactive' member
+       signature to take enum getl_prompt_style instead of const char *.
+       (create_interactive_source) Ditto, for parameter type.
+       (getl_append_interactive) Ditto.
+       (read_line_from_source) Pass get_prompt_style() to interactive
+       function instead of get_prompt().
+       (get_prompt) Removed.
+       (get_prompt_style) New function.
+       
 Sat May  6 13:25:25 2006  Ben Pfaff  <address@hidden>
 
        Continue reforming procedure execution.  In this phase, remove

Index: language/command.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/command.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- language/command.c  9 Jun 2006 22:51:23 -0000       1.11
+++ language/command.c  28 Jun 2006 05:49:03 -0000      1.12
@@ -32,6 +32,7 @@
 #include <data/settings.h>
 #include <data/variable.h>
 #include <language/lexer/lexer.h>
+#include <language/line-buffer.h>
 #include <libpspp/alloc.h>
 #include <libpspp/compiler.h>
 #include <libpspp/message.h>
@@ -120,8 +121,10 @@
 
 static const size_t command_cnt = sizeof commands / sizeof *commands;
 
-static bool verify_valid_command (const struct command *, enum cmd_state);
+static bool in_correct_state (const struct command *, enum cmd_state);
+static bool report_state_mismatch (const struct command *, enum cmd_state);
 static const struct command *find_command (const char *name);
+static void set_completion_state (enum cmd_state); 
 
 /* Command parser. */
 
@@ -156,9 +159,18 @@
   const struct command *command;
   enum cmd_result result;
 
+  /* Read the command's first token. */
+  getl_set_prompt_style (GETL_PROMPT_FIRST);
+  set_completion_state (state);
+  lex_get ();
+  if (token == T_STOP)
+    return CMD_EOF;
+  else if (token == '.') 
+    {
   /* Null commands can result from extra empty lines. */
-  if (token == '.')
     return CMD_SUCCESS;
+    }
+  getl_set_prompt_style (GETL_PROMPT_LATER);
 
   /* Parse the command name. */
   command = parse_command_name ();
@@ -177,8 +189,11 @@
            command->name);
        return CMD_FAILURE;
     }
-  else if (!verify_valid_command (command, state))
+  else if (!in_correct_state (command, state)) 
+    {
+      report_state_mismatch (command, state);
     return CMD_FAILURE;
+    }
 
   /* Execute command. */
   msg_set_command_name (command->name);
@@ -539,19 +554,23 @@
 }
 
 /* Returns true if COMMAND is allowed in STATE,
-   false otherwise.
-   If COMMAND is not allowed, emits an appropriate error
-   message. */
+   false otherwise. */
 static bool
-verify_valid_command (const struct command *command, enum cmd_state state)
+in_correct_state (const struct command *command, enum cmd_state state) 
 {
-  if ((state == CMD_STATE_INITIAL && command->states & S_INITIAL)
+  return ((state == CMD_STATE_INITIAL && command->states & S_INITIAL)
       || (state == CMD_STATE_DATA && command->states & S_DATA)
       || (state == CMD_STATE_INPUT_PROGRAM
           && command->states & S_INPUT_PROGRAM)
-      || (state == CMD_STATE_FILE_TYPE && command->states & S_FILE_TYPE))
-    return true;
+          || (state == CMD_STATE_FILE_TYPE && command->states & S_FILE_TYPE));
+}
 
+/* Emits an appropriate error message for trying to invoke
+   COMMAND in STATE. */
+static bool
+report_state_mismatch (const struct command *command, enum cmd_state state)
+{
+  assert (!in_correct_state (command, state));
   if (state == CMD_STATE_INITIAL || state == CMD_STATE_DATA)
     {
       const char *allowed[3];
@@ -589,51 +608,36 @@
   return false;
 }
 
-/* Readline command name completion. */
+/* Command name completion. */
 
-#if HAVE_READLINE
-static char *command_generator (const char *text, int state);
+static enum cmd_state completion_state = CMD_STATE_INITIAL;
 
-/* Returns a set of completions for TEXT.
-   This is of the proper form for assigning to
-   rl_attempted_completion_function. */
-char **
-pspp_attempted_completion_function (const char *text,
-                                    int start, int end UNUSED)
+static void
+set_completion_state (enum cmd_state state) 
 {
-  if (start == 0) 
-    {
-      /* Complete command name at start of line. */
-      return rl_completion_matches (text, command_generator); 
-    }
-  else 
-    {
-      /* Otherwise don't do any completion. */
-      rl_attempted_completion_over = 1;
-      return NULL; 
-    }
+  completion_state = state;
 }
 
-/* If STATE is 0, returns the first command name matching TEXT.
-   Otherwise, returns the next command name matching TEXT.
-   Returns a null pointer when no matches are left. */
-static char *
-command_generator (const char *text, int state) 
-{
-  static const struct command *cmd;
-  
-  if (!state)
-    cmd = commands;
-
-  for (; cmd < commands + command_cnt; cmd++) 
-    if (!memcasecmp (cmd->name, text, strlen (text))
-        && (!(cmd->flags & F_TESTING) || get_testing_mode ())
-        && (!(cmd->flags & F_ENHANCED) || get_syntax () == ENHANCED))
-      return xstrdup (cmd++->name);
+/* Returns the next possible completion of a command name that
+   begins with PREFIX, in the current command state, or a null
+   pointer if no completions remain.
+   Before calling the first time, set *CMD to a null pointer. */
+const char *
+cmd_complete (const char *prefix, const struct command **cmd)
+{
+  if (*cmd == NULL)
+    *cmd = commands;
+
+  for (; *cmd < commands + command_cnt; (*cmd)++) 
+    if (!memcasecmp ((*cmd)->name, prefix, strlen (prefix))
+        && (!((*cmd)->flags & F_TESTING) || get_testing_mode ())
+        && (!((*cmd)->flags & F_ENHANCED) || get_syntax () == ENHANCED)
+        && ((*cmd)->function != NULL)
+        && in_correct_state (*cmd, completion_state))
+      return (*cmd)++->name;
 
   return NULL;
 }
-#endif /* HAVE_READLINE */
 
 /* Simple commands. */
 

Index: language/command.h
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/command.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- language/command.h  2 May 2006 01:29:06 -0000       1.4
+++ language/command.h  28 Jun 2006 05:49:03 -0000      1.5
@@ -54,12 +54,11 @@
     CMD_STATE_FILE_TYPE         /* Inside FILE TYPE. */
   };
 
-#if HAVE_READLINE
-char **pspp_attempted_completion_function (const char *, int start, int end);
-#endif
-
 enum cmd_result cmd_parse (enum cmd_state);
 
+struct command;
+const char *cmd_complete (const char *, const struct command **);
+
 /* Prototype all the command functions. */
 #define DEF_CMD(STATES, FLAGS, NAME, FUNCTION) int FUNCTION (void);
 #define UNIMPL_CMD(NAME, DESCRIPTION)

Index: language/line-buffer.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/line-buffer.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- language/line-buffer.c      9 Jun 2006 22:51:23 -0000       1.12
+++ language/line-buffer.c      28 Jun 2006 05:49:03 -0000      1.13
@@ -85,7 +85,7 @@
         function;
 
         /* INTERACTIVE. */
-        bool (*interactive) (struct string *line, const char *prompt);
+        bool (*interactive) (struct string *line, enum getl_prompt_style);
       }
     u;
 
@@ -103,7 +103,7 @@
 
 static void init_prompts (void);
 static void uninit_prompts (void);
-static const char *get_prompt (void);
+static enum getl_prompt_style get_prompt_style (void);
 
 /* Initialize getl. */
 void
@@ -214,7 +214,7 @@
 /* Creates an interactive source with the given FUNCTION. */
 static struct getl_source *
 create_interactive_source (bool (*function) (struct string *line,
-                                             const char *prompt)) 
+                                             enum getl_prompt_style)) 
 {
   struct getl_source *s = xmalloc (sizeof *s);
   s->fn = NULL;
@@ -297,7 +297,7 @@
    obtained or false at end of file. */
 void
 getl_append_interactive (bool (*function) (struct string *line,
-                                           const char *prompt)) 
+                                           enum getl_prompt_style)) 
 {
   append_source (create_interactive_source (function));
 }
@@ -489,7 +489,7 @@
     case FUNCTION:
       return s->u.function.read (line, &s->fn, &s->ln, s->u.function.aux);
     case INTERACTIVE:
-      return s->u.interactive (line, get_prompt ());
+      return s->u.interactive (line, get_prompt_style ());
     }
 
   abort ();
@@ -589,8 +589,8 @@
 }
 
 /* Returns the current prompt. */
-static const char *
-get_prompt (void) 
+static enum getl_prompt_style
+get_prompt_style (void) 
 {
-  return prompts[current_style];
+  return current_style;
 }

Index: language/line-buffer.h
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/line-buffer.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- language/line-buffer.h      15 Mar 2006 03:29:10 -0000      1.2
+++ language/line-buffer.h      28 Jun 2006 05:49:03 -0000      1.3
@@ -23,6 +23,14 @@
 #include <stdbool.h>
 #include <libpspp/str.h>
 
+enum getl_prompt_style
+  {
+    GETL_PROMPT_FIRST,         /* First line of command. */
+    GETL_PROMPT_LATER,          /* Second or later line of command. */
+    GETL_PROMPT_DATA,          /* Between BEGIN DATA and END DATA. */
+    GETL_PROMPT_CNT
+  };
+
 /* Current line.  This line may be modified by modules other than
    getl.c, and by lexer.c in particular.  (Ugh.) */
 extern struct string getl_buf;
@@ -43,7 +51,7 @@
                             void (*close) (void *aux),
                             void *aux);
 void getl_append_interactive (bool (*function) (struct string *line,
-                                                const char *prompt));
+                                                enum getl_prompt_style));
 void getl_abort_noninteractive (void);
 bool getl_is_interactive (void);
 
@@ -51,16 +59,6 @@
 
 void getl_location (const char **, int *);
 
-/* Prompting. */
-
-enum getl_prompt_style
-  {
-    GETL_PROMPT_FIRST,         /* First line of command. */
-    GETL_PROMPT_LATER,           /* Second or later line of command. */
-    GETL_PROMPT_DATA,          /* Between BEGIN DATA and END DATA. */
-    GETL_PROMPT_CNT
-  };
-
 const char *getl_get_prompt (enum getl_prompt_style);
 void getl_set_prompt (enum getl_prompt_style, const char *);
 void getl_set_prompt_style (enum getl_prompt_style);

Index: language/data-io/ChangeLog
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/data-io/ChangeLog,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- language/data-io/ChangeLog  9 Jun 2006 22:51:24 -0000       1.21
+++ language/data-io/ChangeLog  28 Jun 2006 05:49:03 -0000      1.22
@@ -1,3 +1,12 @@
+Tue Jun 27 22:44:28 2006  Ben Pfaff  <address@hidden>
+
+       Fix regression in command name completion reported by John
+       Darrington.  Now completion is again state-dependent and occurs
+       only on the first line of a command.
+       
+       * inpt-pgm.c: (cmd_input_program) Reading of first token in
+       command moved into cmd_parse.
+
 Fri Jun  9 13:56:00 2006  Ben Pfaff  <address@hidden>
 
        Reform string library.

Index: language/data-io/inpt-pgm.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/language/data-io/inpt-pgm.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- language/data-io/inpt-pgm.c 5 May 2006 04:53:12 -0000       1.10
+++ language/data-io/inpt-pgm.c 28 Jun 2006 05:49:03 -0000      1.11
@@ -119,9 +119,7 @@
   inside_input_program = true;
   for (;;) 
     {
-      enum cmd_result result;
-      lex_get ();
-      result = cmd_parse (CMD_STATE_INPUT_PROGRAM);
+      enum cmd_result result = cmd_parse (CMD_STATE_INPUT_PROGRAM);
       if (result == CMD_END_INPUT_PROGRAM)
         break;
       else if (result == CMD_END_CASE) 

Index: ui/terminal/ChangeLog
===================================================================
RCS file: /cvsroot/pspp/pspp/src/ui/terminal/ChangeLog,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- ui/terminal/ChangeLog       27 Jun 2006 15:23:30 -0000      1.11
+++ ui/terminal/ChangeLog       28 Jun 2006 05:49:03 -0000      1.12
@@ -1,3 +1,22 @@
+Tue Jun 27 22:44:56 2006  Ben Pfaff  <address@hidden>
+
+       Fix regression in command name completion reported by John
+       Darrington.  Now completion is again state-dependent and occurs
+       only on the first line of a command.
+       
+       * main.c (main): Reading of first token in command moved into
+       cmd_parse.
+       (execute_command) Removed.
+
+       * read-line.c: [HAVE_READLINE] (readln_initialize) Postpone
+       setting rl_attempted_completion_function until readln_read.
+       [HAVE_READLINE] (readln_read) Change param from const char * to
+       enum getl_prompt_style.  Set rl_attempted_completion_function
+       based on style.
+       [HAVE_READLINE] (complete_command_name) New function.
+       [HAVE_READLINE] (dont_complete) New function.
+       [HAVE_READLINE] (command_generator) New function.
+
 Tue Jun 27 08:23:07 2006  Ben Pfaff  <address@hidden>
 
        * automake.mk (src_ui_terminal_pspp_LDADD): Add $(LIBICONV).

Index: ui/terminal/main.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/ui/terminal/main.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- ui/terminal/main.c  5 May 2006 04:53:13 -0000       1.12
+++ ui/terminal/main.c  28 Jun 2006 05:49:03 -0000      1.13
@@ -62,7 +62,6 @@
 
 static void i18n_init (void);
 static void fpu_init (void);
-static int execute_command (void);
 static void terminate (bool success) NO_RETURN;
 
 /* If a segfault happens, issue a message to that effect and halt */
@@ -102,7 +101,8 @@
 
       for (;;)
         {
-          int result = execute_command ();
+          int result = cmd_parse (proc_has_source ()
+                                  ? CMD_STATE_DATA : CMD_STATE_INITIAL);
           if (result == CMD_EOF || result == CMD_FINISH)
             break;
           if (result == CMD_CASCADING_FAILURE && !getl_is_interactive ())
@@ -119,25 +119,6 @@
   terminate (!any_errors ());
 }
 
-/* Parses a command and returns the result. */
-static int
-execute_command (void)
-{
-  /* Read the command's first token.  
-     The first token is part of the first line of the command. */
-  getl_set_prompt_style (GETL_PROMPT_FIRST);
-  lex_get ();
-  if (token == T_STOP)
-    return CMD_EOF;
-
-  /* Parse the command.
-     Any lines read after the first token must be continuation
-     lines. */
-  getl_set_prompt_style (GETL_PROMPT_LATER);
-  return cmd_parse (proc_has_source ()
-                    ? CMD_STATE_DATA : CMD_STATE_INITIAL);
-}
-
 static void
 i18n_init (void) 
 {

Index: ui/terminal/read-line.c
===================================================================
RCS file: /cvsroot/pspp/pspp/src/ui/terminal/read-line.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- ui/terminal/read-line.c     9 Jun 2006 22:51:24 -0000       1.7
+++ ui/terminal/read-line.c     28 Jun 2006 05:49:03 -0000      1.8
@@ -37,15 +37,19 @@
 #include <libpspp/version.h>
 #include <output/table.h>
 
+#include "xalloc.h"
+
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
-
 #if HAVE_READLINE
 #include <readline/readline.h>
 #include <readline/history.h>
 
 static char *history_file;
+
+static char **complete_command_name (const char *, int, int);
+static char **dont_complete (const char *, int, int);
 #endif /* HAVE_READLINE */
 
 static bool initialised = false;
@@ -58,7 +62,6 @@
 
 #if HAVE_READLINE
   rl_basic_word_break_characters = "\n";
-  rl_attempted_completion_function = pspp_attempted_completion_function;
 #ifdef unix
   if (history_file == NULL)
     {
@@ -113,19 +116,23 @@
    Returns true if successful, false at end of file.
    Suitable for passing to getl_append_interactive(). */
 bool
-readln_read (struct string *line, const char *prompt)
+readln_read (struct string *line, enum getl_prompt_style style)
 {
+  const char *prompt = getl_get_prompt (style);
 #if HAVE_READLINE
   char *string;
 #endif
   
-  assert(initialised);
+  assert (initialised);
 
   reset_msg_count ();
 
   welcome ();
 
 #if HAVE_READLINE
+  rl_attempted_completion_function = (style == GETL_PROMPT_FIRST
+                                      ? complete_command_name
+                                      : dont_complete);
   string = readline (prompt);
   if (string == NULL)
     return false;
@@ -149,3 +156,49 @@
     return false;
 #endif
 }
+
+#ifdef HAVE_READLINE
+static char *command_generator (const char *text, int state);
+
+/* Returns a set of command name completions for TEXT.
+   This is of the proper form for assigning to
+   rl_attempted_completion_function. */
+static char **
+complete_command_name (const char *text, int start, int end UNUSED)
+{
+  if (start == 0) 
+    {
+      /* Complete command name at start of line. */
+      return rl_completion_matches (text, command_generator); 
+    }
+  else 
+    {
+      /* Otherwise don't do any completion. */
+      rl_attempted_completion_over = 1;
+      return NULL; 
+    }
+}
+
+/* Do not do any completion for TEXT. */
+static char **
+dont_complete (const char *text UNUSED, int start UNUSED, int end UNUSED)
+{
+  rl_attempted_completion_over = 1;
+  return NULL; 
+}
+
+/* If STATE is 0, returns the first command name matching TEXT.
+   Otherwise, returns the next command name matching TEXT.
+   Returns a null pointer when no matches are left. */
+static char *
+command_generator (const char *text, int state) 
+{ 
+  static const struct command *cmd;
+  const char *name;
+
+  if (state == 0)
+    cmd = NULL;
+  name = cmd_complete (text, &cmd);
+  return name ? xstrdup (name) : NULL;
+}
+#endif /* HAVE_READLINE */

Index: ui/terminal/read-line.h
===================================================================
RCS file: /cvsroot/pspp/pspp/src/ui/terminal/read-line.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- ui/terminal/read-line.h     15 Mar 2006 03:29:11 -0000      1.2
+++ ui/terminal/read-line.h     28 Jun 2006 05:49:03 -0000      1.3
@@ -21,10 +21,11 @@
 #define READLN_H
 
 #include <libpspp/str.h>
+#include <language/line-buffer.h>
 
 void readln_initialize (void);
 void readln_uninitialize (void);
-bool readln_read (struct string *line, const char *prompt);
+bool readln_read (struct string *line, enum getl_prompt_style);
 
 #endif /* READLN_H */
 




reply via email to

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