pspp-dev
[Top][All Lists]
Advanced

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

[pre-lexer 15/21] message: Consistently initialize locator; use 0 for "n


From: Ben Pfaff
Subject: [pre-lexer 15/21] message: Consistently initialize locator; use 0 for "no line number".
Date: Thu, 23 Sep 2010 21:20:51 -0700

A few of the callers of msg_emit() did not initialize the "where" member
of the struct msg, because they expect that msg_emit() will do it for them.
This is currently correct, but I intend to soon introduce the ability for
msg_emit()'s caller to specify a location.  With that change, it will be
important for the caller to initialize this member, so this commit makes
sure of that.

At the same time, some callers were using -1 as the default value that
means "no line number" and others were using 0.  This commit standardizes
on the latter.
---
 src/data/data-in.c                  |    2 +-
 src/language/control/repeat.c       |    6 +++---
 src/language/expressions/helpers.c  |    2 ++
 src/language/syntax-string-source.c |    2 +-
 src/libpspp/getl.c                  |    8 ++++----
 src/libpspp/message.c               |    8 +++++---
 src/libpspp/message.h               |    6 +++---
 7 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/src/data/data-in.c b/src/data/data-in.c
index cd51226..480d335 100644
--- a/src/data/data-in.c
+++ b/src/data/data-in.c
@@ -1203,7 +1203,7 @@ vdata_warning (const struct data_in *i, const char 
*format, va_list args)
   m.severity = MSG_S_WARNING;
   m.text = ds_cstr (&text);
   m.where.file_name = NULL;
-  m.where.line_number = -1;
+  m.where.line_number = 0;
 
   msg_emit (&m);
 }
diff --git a/src/language/control/repeat.c b/src/language/control/repeat.c
index 1ab3b9c..d7cc544 100644
--- a/src/language/control/repeat.c
+++ b/src/language/control/repeat.c
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2007, 2009 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2007, 2009, 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
@@ -618,10 +618,10 @@ do_repeat_name (const struct getl_interface *interface)
 }
 
 /* Returns the line number in the source file from which the
-   previous line was originally obtained, or -1 if none. */
+   previous line was originally obtained, or 0 if none. */
 static int
 do_repeat_location (const struct getl_interface *interface)
 {
   struct repeat_line *line = current_line (interface);
-  return line ? line->line_number : -1;
+  return line ? line->line_number : 0;
 }
diff --git a/src/language/expressions/helpers.c 
b/src/language/expressions/helpers.c
index 17fc318..2d707e9 100644
--- a/src/language/expressions/helpers.c
+++ b/src/language/expressions/helpers.c
@@ -34,6 +34,8 @@ expr_error (void *aux UNUSED, const char *format, ...)
   m.severity = MSG_S_ERROR;
   va_start (args, format);
   m.text = xvasprintf (format, args);
+  m.where.file_name = NULL;
+  m.where.line_number = 0;
   va_end (args);
 
   msg_emit (&m);
diff --git a/src/language/syntax-string-source.c 
b/src/language/syntax-string-source.c
index 3860b89..4f3c1c1 100644
--- a/src/language/syntax-string-source.c
+++ b/src/language/syntax-string-source.c
@@ -54,7 +54,7 @@ name (const struct getl_interface *i UNUSED)
 static int
 location (const struct getl_interface *i UNUSED)
 {
-  return -1;
+  return 0;
 }
 
 
diff --git a/src/libpspp/getl.c b/src/libpspp/getl.c
index 43d2a56..9db6c3a 100644
--- a/src/libpspp/getl.c
+++ b/src/libpspp/getl.c
@@ -212,18 +212,18 @@ getl_source_name (const struct source_stream *ss)
   return s->interface->name (s->interface);
 }
 
-/* Returns the location within the current source, or -1 if there is
-   no current source */
+/* Returns the line number within the current source, or 0 if there is no
+   current source. */
 int
 getl_source_location (const struct source_stream *ss)
 {
   const struct getl_source *s = current_source (ss);
 
   if ( ll_is_empty (&ss->sources) )
-    return -1;
+    return 0;
 
   if ( !s->interface->location )
-    return -1;
+    return 0;
 
   return s->interface->location (s->interface);
 }
diff --git a/src/libpspp/message.c b/src/libpspp/message.c
index 4ba8a8f..e0f9bf1 100644
--- a/src/libpspp/message.c
+++ b/src/libpspp/message.c
@@ -57,6 +57,8 @@ msg (enum msg_class class, const char *format, ...)
   m.severity = msg_class_to_severity (class);
   va_start (args, format);
   m.text = xvasprintf (format, args);
+  m.where.file_name = NULL;
+  m.where.line_number = 0;
   va_end (args);
 
   msg_emit (&m);
@@ -118,7 +120,7 @@ msg_to_string (const struct msg *m, const char 
*command_name)
     {
       if (m->where.file_name)
         ds_put_format (&s, "%s:", m->where.file_name);
-      if (m->where.line_number != -1)
+      if (m->where.line_number > 0)
         ds_put_format (&s, "%d:", m->where.line_number);
       ds_put_char (&s, ' ');
     }
@@ -199,7 +201,7 @@ submit_note (char *s)
   m.category = MSG_C_GENERAL;
   m.severity = MSG_S_NOTE;
   m.where.file_name = NULL;
-  m.where.line_number = -1;
+  m.where.line_number = 0;
   m.text = s;
   msg_handler (&m);
   free (s);
@@ -258,7 +260,7 @@ msg_emit (struct msg *m)
   else
     {
       m->where.file_name = NULL;
-      m->where.line_number = -1;
+      m->where.line_number = 0;
     }
 
   if (!messages_disabled)
diff --git a/src/libpspp/message.h b/src/libpspp/message.h
index bdd27a5..6cdf6e8 100644
--- a/src/libpspp/message.h
+++ b/src/libpspp/message.h
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 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
@@ -70,8 +70,8 @@ msg_class_from_category_and_severity (enum msg_category 
category,
 /* A file location.  */
 struct msg_locator
   {
-    char *file_name;           /* File name. */
-    int line_number;            /* Line number. */
+    char *file_name;           /* File name (NULL if none). */
+    int line_number;           /* Line number (0 if none). */
   };
 
 /* A message. */
-- 
1.7.1




reply via email to

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