From: Ben Pfaff Date: Sun, 19 Sep 2010 18:04:41 +0000 (-0700) Subject: message: Consistently initialize locator; use 0 for "no line number". X-Git-Tag: v0.7.6~187 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=638a86001fe7a237bd6c19a181d796305290d72a;p=pspp-builds.git message: Consistently initialize locator; use 0 for "no line number". 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. --- diff --git a/src/data/data-in.c b/src/data/data-in.c index cd512268..480d335a 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 1ab3b9c2..d7cc544f 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 17fc3182..2d707e99 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 3860b898..4f3c1c14 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 43d2a56f..9db6c3ae 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 4ba8a8f7..e0f9bf17 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 bdd27a5e..6cdf6e87 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. */