+Sun Apr 16 15:58:56 2006 Ben Pfaff <blp@gnu.org>
+
+ Continue reforming error message support. In this phase, we get
+ rid of VM() and the other msg() support for "verbosity", replacing
+ it by a new function verbose_msg().
+
+ * message.c: (verbose_msg) New function.
+ (err_vmsg) Remove support for verbosity levels.
+
Sun Apr 16 11:46:51 2006 Ben Pfaff <blp@gnu.org>
Start reforming error message support. In this phase, we get rid
+Sun Apr 16 16:05:28 2006 Ben Pfaff <blp@gnu.org>
+
+ Continue reforming error message support. In this phase, we get
+ rid of VM() and the other msg() support for "verbosity", replacing
+ it by a new function verbose_msg().
+
+ * filename.c: (fn_search_path) Rewrite for cleaner code. Also,
+ get rid of non-Unixlike version of the code, which has probably
+ never been tested.
+ (fn_prepend_dir) Removed (dead code).
+
+ * filename.h: (macro DIR_SEPARATOR_STRING) New.
+ (macro PATH_SEPARATOR_STRING) New.
+
Sat Apr 15 19:53:19 2006 Ben Pfaff <blp@gnu.org>
* sfm-private.h: Get rid of #defines after #error, which makes no
Returns the malloc'd full name of the first file found, or NULL if
none is found.
- If PREPEND is non-NULL, then it is prepended to each filename;
- i.e., it looks like PREPEND/PATH_COMPONENT/NAME. This is not done
+ If PREFIX is non-NULL, then it is prefixed to each filename;
+ i.e., it looks like PREFIX/PATH_COMPONENT/NAME. This is not done
with absolute directories in the path. */
-#if defined (unix) || defined (__MSDOS__) || defined (__WIN32__)
char *
-fn_search_path (const char *basename, const char *path, const char *prepend)
+fn_search_path (const char *base_name, const char *path_, const char *prefix)
{
- char *subst_path;
- struct string filename;
- const char *bp;
+ struct string path;
+ struct string dir = DS_INITIALIZER;
+ struct string file = DS_INITIALIZER;
+ char *tmp_str;
+ size_t save_idx = 0;
- if (fn_absolute_p (basename))
- return fn_tilde_expand (basename);
-
- {
- struct string temp;
- ds_create(&temp, path);
-
- fn_interp_vars(&temp, fn_getenv);
+ if (fn_absolute_p (base_name))
+ return fn_tilde_expand (base_name);
- bp = subst_path = fn_tilde_expand (ds_c_str(&temp));
+ /* Interpolate environment variables and do tilde-expansion. */
+ ds_create (&path, path_);
+ fn_interp_vars (&path, fn_getenv);
- ds_destroy(&temp);
- }
+ tmp_str = fn_tilde_expand (ds_c_str (&path));
+ ds_assign_c_str (&path, tmp_str);
+ free (tmp_str);
- msg (VM (4), _("Searching for `%s'..."), basename);
- ds_init (&filename, 64);
-
- for (;;)
+ verbose_msg (2, _("searching for \"%s\" in path \"%s\""),
+ base_name, ds_c_str (&path));
+ while (ds_separate (&path, &dir, PATH_DELIMITER_STRING, &save_idx))
{
- const char *ep;
- if (0 == *bp)
- {
- msg (VM (4), _("Search unsuccessful!"));
- ds_destroy (&filename);
- free (subst_path);
- return NULL;
- }
-
- for (ep = bp; *ep && *ep != PATH_DELIMITER; ep++)
- ;
-
- /* Paste together PREPEND/PATH/BASENAME. */
- ds_clear (&filename);
- if (prepend && !fn_absolute_p (bp))
+ /* Construct file name. */
+ ds_clear (&file);
+ if (prefix != NULL && !fn_absolute_p (ds_c_str (&dir)))
{
- ds_puts (&filename, prepend);
- ds_putc (&filename, DIR_SEPARATOR);
- }
- ds_concat (&filename, bp, ep - bp);
- if (ep - bp
- && ds_c_str (&filename)[ds_length (&filename) - 1] != DIR_SEPARATOR)
- ds_putc (&filename, DIR_SEPARATOR);
- ds_puts (&filename, basename);
-
- msg (VM (5), " - %s", ds_c_str (&filename));
- if (fn_exists_p (ds_c_str (&filename)))
- {
- msg (VM (4), _("Found `%s'."), ds_c_str (&filename));
- free (subst_path);
- return ds_c_str (&filename);
+ ds_puts (&file, prefix);
+ ds_putc (&file, DIR_SEPARATOR);
}
+ ds_puts (&file, ds_c_str (&dir));
+ if (ds_length (&dir) && ds_last (&file) != DIR_SEPARATOR)
+ ds_putc (&file, DIR_SEPARATOR);
+ ds_puts (&file, base_name);
- if (0 == *ep)
+ /* Check whether file exists. */
+ if (fn_exists_p (ds_c_str (&file)))
{
- msg (VM (4), _("Search unsuccessful!"));
- free (subst_path);
- ds_destroy (&filename);
- return NULL;
+ verbose_msg (2, _("...found \"%s\""), ds_c_str (&file));
+ ds_destroy (&path);
+ ds_destroy (&dir);
+ return ds_c_str (&file);
}
- bp = ep + 1;
- }
-}
-#else /* not unix, msdog, lose32 */
-char *
-fn_search_path (const char *basename, const char *path, const char *prepend)
-{
- size_t size = strlen (path) + 1 + strlen (basename) + 1;
- char *string;
- char *cp;
-
- if (prepend)
- size += strlen (prepend) + 1;
- string = xmalloc (size);
-
- cp = string;
- if (prepend)
- {
- cp = stpcpy (cp, prepend);
- *cp++ = DIR_SEPARATOR;
}
- cp = stpcpy (cp, path);
- *cp++ = DIR_SEPARATOR;
- strcpy (cp, basename);
-
- return string;
-}
-#endif /* not unix, msdog, lose32 */
-/* Prepends directory DIR to filename FILE and returns a malloc()'d
- copy of it. */
-char *
-fn_prepend_dir (const char *file, const char *dir)
-{
- char *temp;
- char *cp;
-
- if (fn_absolute_p (file))
- return xstrdup (file);
-
- temp = xmalloc (strlen (file) + 1 + strlen (dir) + 1);
- cp = stpcpy (temp, dir);
- if (cp != temp && cp[-1] != DIR_SEPARATOR)
- *cp++ = DIR_SEPARATOR;
- cp = stpcpy (cp, file);
-
- return temp;
+ /* Failure. */
+ verbose_msg (2, _("...not found"));
+ ds_destroy (&path);
+ ds_destroy (&dir);
+ ds_destroy (&file);
+ return NULL;
}
/* fn_normalize(): This very OS-dependent routine canonicalizes
#ifndef __MSDOS__
#define DIR_SEPARATOR '/'
#define PATH_DELIMITER ':'
+#define DIR_SEPARATOR_STRING "/"
+#define PATH_DELIMITER_STRING ":"
#else
#define DIR_SEPARATOR '\\'
#define PATH_DELIMITER ';'
+#define DIR_SEPARATOR_STRING "\\"
+#define PATH_DELIMITER_STRING ";"
#endif
/* Search path for configuration files. */
void fn_interp_vars (struct string *target,
const char *(*getenv) (const char *));
char *fn_tilde_expand (const char *fn);
-char *fn_search_path (const char *basename, const char *path,
- const char *prepend);
-char *fn_prepend_dir (const char *filename, const char *directory);
+char *fn_search_path (const char *base_name, const char *path,
+ const char *prefix);
char *fn_normalize (const char *fn);
char *fn_dirname (const char *fn);
char *fn_basename (const char *fn);
/* Open file, if not yet opened. */
if (s->u.syntax_file == NULL)
{
- msg (VM (1), _("%s: Opening as syntax file."), s->fn);
+ verbose_msg (1, _("opening \"%s\" as syntax file"), s->fn);
s->u.syntax_file = fn_open (s->fn, "r");
if (s->u.syntax_file == NULL)
+Sun Apr 16 16:05:43 2006 Ben Pfaff <blp@gnu.org>
+
+ Continue reforming error message support. In this phase, we get
+ rid of VM() and the other msg() support for "verbosity", replacing
+ it by a new function verbose_msg().
+
+ * message.h: (enum ERR_CLASS_COUNT) Renamed ERR_CLASS_CNT.
+ (enum ERR_CLASS_MASK) Removed.
+ (enum ERR_VERBOSITY_SHIFT) Removed.
+ (enum ERR_VERBOSITY_MASK) Removed.
+ (macro VM) Removed.
+
Sun Apr 16 11:48:07 2006 Ben Pfaff <blp@gnu.org>
Start reforming error message support. In this phase, we get rid
SE, SW, SM, /* Script error/warning/message. */
DE, DW, /* Data-file error/warning. */
ME, MW, MM, /* General error/warning/message. */
- ERR_CLASS_COUNT, /* Number of message classes. */
- ERR_CLASS_MASK = 0xf, /* Bitmask for class. */
- ERR_VERBOSITY_SHIFT = 4, /* Shift count for verbosity. */
- ERR_VERBOSITY_MASK = 0xf /* Bitmask for verbosity. */
+ MSG_CLASS_CNT,
};
-/* If passed to msg() as CLASS, the return value will cause the message
- to be displayed only if `verbosity' is at least LEVEL. */
-#define VM(LEVEL) (MM | ((LEVEL) << ERR_VERBOSITY_SHIFT))
-
/* A file location. */
struct file_locator
{
void tmsg (int class, const char *title, const char *format, ...)
PRINTF_FORMAT (3, 4);
+void verbose_msg (int level, const char *format, ...)
+ PRINTF_FORMAT (2, 3);
+
/* File-locator stack. */
void err_push_file_locator (const struct file_locator *);
void err_pop_file_locator (const struct file_locator *);
#include <data/settings.h>
#include <ui/terminal/read-line.h>
#include <libpspp/version.h>
+#include "progname.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
va_end (args);
}
+/* Writes MESSAGE formatted with printf, to stderr, if the
+ verbosity level is at least LEVEL. */
+void
+verbose_msg (int level, const char *format, ...)
+{
+ if (err_verbosity >= level)
+ {
+ va_list args;
+
+ va_start (args, format);
+ fprintf (stderr, "%s: ", program_name);
+ vfprintf (stderr, format, args);
+ putc ('\n', stderr);
+ va_end (args);
+ }
+}
+
/* Checks whether we've had so many errors that it's time to quit
processing this syntax file. */
void
const char *banner; /* Banner. */
};
- static const struct error_class error_classes[ERR_CLASS_COUNT] =
+ static const struct error_class error_classes[MSG_CLASS_CNT] =
{
{3, &err_error_count, N_("error")}, /* SE */
{3, &err_warning_count, N_("warning")}, /* SW */
};
struct string msg;
- int class;
- /* Check verbosity level. */
- class = e->class;
- if (((class >> ERR_VERBOSITY_SHIFT) & ERR_VERBOSITY_MASK) > err_verbosity)
- return;
- class &= ERR_CLASS_MASK;
-
- assert (class >= 0 && class < ERR_CLASS_COUNT);
+ assert (e->class >= 0 && e->class < MSG_CLASS_CNT);
assert (format != NULL);
ds_init (&msg, 64);
- if (e->where.filename && (error_classes[class].flags & ERR_WITH_FILE))
+ if (e->where.filename && (error_classes[e->class].flags & ERR_WITH_FILE))
{
ds_printf (&msg, "%s:", e->where.filename);
if (e->where.line_number != -1)
ds_putc (&msg, ' ');
}
- ds_printf (&msg, "%s: ", gettext (error_classes[class].banner));
+ ds_printf (&msg, "%s: ", gettext (error_classes[e->class].banner));
{
- int *count = error_classes[class].count;
+ int *count = error_classes[e->class].count;
if (count)
(*count)++;
}
- if (command_name != NULL && (error_classes[class].flags & ERR_IN_PROCEDURE))
+ if (command_name != NULL
+ && (error_classes[e->class].flags & ERR_IN_PROCEDURE))
ds_printf (&msg, "%s: ", command_name);
if (e->title)
if (init_fn == NULL)
{
error (0, 0, _("cannot find output initialization file "
- "(use `-vvvvv' to view search path)"));
+ "(use `-vv' to view search path)"));
goto exit;
}
+Sun Apr 16 16:06:54 2006 Ben Pfaff <blp@gnu.org>
+
+ Continue reforming error message support. In this phase, we get
+ rid of VM() and the other msg() support for "verbosity", replacing
+ it by a new function verbose_msg().
+
+ * message-dialog.c: (verbose_msg) New function.
+ (err_cond_fail) Removed (dead code).
+ (err_failure) Removed (dead code).
+
Sun Apr 16 11:53:25 2006 Ben Pfaff <blp@gnu.org>
Start reforming error message support. In this phase, we get rid
#include <config.h>
#include <libpspp/message.h>
#include "message-dialog.h"
+#include "progname.h"
#include <gtk/gtk.h>
msg(ME, "Assertion failed: %s:%d; (%s)\n",file,line,expr);
}
-/* The GUI is always interactive.
- So this function does nothing */
-void
-err_cond_fail(void)
-{
-}
-
-
+/* Writes MESSAGE formatted with printf, to stderr, if the
+ verbosity level is at least LEVEL. */
void
-err_failure(void)
+verbose_msg (int level, const char *format, ...)
{
- msg(ME, _("Terminating NOW due to fatal error"));
- gtk_main_quit();
+ /* Do nothing for now. */
}
-
/* FIXME: This is a stub .
* A temporary workaround until getl.c is rearranged
*/