[Top][All Lists]
[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
- [pre-lexer 19/21] data-in: Rewrite logic for recoding input, and get rid of src_enc member., (continued)
- [pre-lexer 19/21] data-in: Rewrite logic for recoding input, and get rid of src_enc member., Ben Pfaff, 2010/09/24
- [pre-lexer 03/21] i18n: New function recode_substring_pool()., Ben Pfaff, 2010/09/24
- [pre-lexer 11/21] lexer: Use lex_is_string() more consistently., Ben Pfaff, 2010/09/24
- [pre-lexer 04/21] syntax-string-source: Fix format string problems., Ben Pfaff, 2010/09/24
- [pre-lexer 08/21] Make translation easier., Ben Pfaff, 2010/09/24
- [pre-lexer 14/21] command: Add specific DATASET unimplemented commands., Ben Pfaff, 2010/09/24
- [pre-lexer 12/21] command: Remove INSERT from list of unimplemented commands., Ben Pfaff, 2010/09/24
- [pre-lexer 20/21] data-in: Make data_in() parameters more uniform., Ben Pfaff, 2010/09/24
- [pre-lexer 02/21] i18n: Use UTF8 macro instead of "UTF8" literal string., Ben Pfaff, 2010/09/24
- [pre-lexer 09/21] lexer: Improve translatability of lex_error()., Ben Pfaff, 2010/09/24
- [pre-lexer 15/21] message: Consistently initialize locator; use 0 for "no line number".,
Ben Pfaff <=
- [pre-lexer 06/21] AGGREGATE: Simplify code., Ben Pfaff, 2010/09/24
- [pre-lexer 17/21] calendar: Use sensible error reporting in calendar_gregorian_to_offset()., Ben Pfaff, 2010/09/24
- [pre-lexer 16/21] message: Add column range to struct msg_locator., Ben Pfaff, 2010/09/24
- [pre-lexer 05/21] PERMISSIONS: Add missing check for string token., Ben Pfaff, 2010/09/24
- [pre-lexer 10/21] lexer: Remove DUMP_TOKENS debugging feature., Ben Pfaff, 2010/09/24
- [pre-lexer 18/21] data-in: Eliminate "implied_decimals" parameter from data_in()., Ben Pfaff, 2010/09/24
- [pre-lexer 21/21] data-in: Get rid of first_column, last_column arguments., Ben Pfaff, 2010/09/24
- [pre-lexer 07/21] HOST: Use more modern syntax., Ben Pfaff, 2010/09/24
- Re: [pre-lexer 00/21] preparation for work on lexer, John Darrington, 2010/09/24