DO REPEAT: Improve error messages and coding style.
[pspp] / src / language / lexer / lexer.c
index cdfc84836085377fd006518301491eed087269d3..a2a0da9713c8f044398af94c0cb5c94580a095a7 100644 (file)
@@ -519,18 +519,22 @@ void
 void
 lex_error_expecting_valist (struct lexer *lexer, va_list args)
 {
-  enum { MAX_OPTIONS = 9 };
-  const char *options[MAX_OPTIONS];
-  int n = 0;
-  while (n < MAX_OPTIONS)
+  const char **options = NULL;
+  size_t allocated = 0;
+  size_t n = 0;
+
+  for (;;)
     {
       const char *option = va_arg (args, const char *);
       if (!option)
         break;
 
+      if (n >= allocated)
+        options = x2nrealloc (options, &allocated, sizeof *options);
       options[n++] = option;
     }
   lex_error_expecting_array (lexer, options, n);
+  free (options);
 }
 
 void
@@ -1866,9 +1870,11 @@ void
 lex_discard_noninteractive (struct lexer *lexer)
 {
   struct lex_source *src = lex_source__ (lexer);
-
   if (src != NULL)
     {
+      if (src->reader->error == LEX_ERROR_IGNORE)
+        return;
+
       lex_stage_clear (&src->pp);
       lex_stage_clear (&src->merge);
       lex_source_clear_parse (src);
@@ -1923,6 +1929,12 @@ lex_source__ (const struct lexer *lexer)
           : ll_data (ll_head (&lexer->sources), struct lex_source, ll));
 }
 
+const struct lex_source *
+lex_source (const struct lexer *lexer)
+{
+  return lex_source__ (lexer);
+}
+
 /* Returns the text of the syntax in SRC for tokens with offsets OFS0 through
    OFS1 in the current command, inclusive.  (For example, if OFS0 and OFS1 are
    both zero, this requests the syntax for the first token in the current
@@ -2590,9 +2602,7 @@ lex_reader_for_substring_nocopy (struct substring s, const char *encoding)
 struct lex_reader *
 lex_reader_for_string (const char *s, const char *encoding)
 {
-  struct substring ss;
-  ss_alloc_substring (&ss, ss_cstr (s));
-  return lex_reader_for_substring_nocopy (ss, encoding);
+  return lex_reader_for_substring_nocopy (ss_clone (ss_cstr (s)), encoding);
 }
 
 /* Formats FORMAT as a printf()-like format string and creates and returns a