Continue reforming error message support. In this phase, we get rid
authorBen Pfaff <blp@gnu.org>
Sun, 16 Apr 2006 23:08:02 +0000 (23:08 +0000)
committerBen Pfaff <blp@gnu.org>
Sun, 16 Apr 2006 23:08:02 +0000 (23:08 +0000)
of VM() and the other msg() support for "verbosity", replacing it by a
new function verbose_msg().

src/ChangeLog
src/data/ChangeLog
src/data/filename.c
src/data/filename.h
src/language/line-buffer.c
src/libpspp/ChangeLog
src/libpspp/message.h
src/message.c
src/output/output.c
src/ui/gui/ChangeLog
src/ui/gui/message-dialog.c

index 80a60331ffbfe6ef3e3b27716bc6a5399e2d32d1..36ae08da3a295eca31bdb8aa8539f1b053e8a3b0 100644 (file)
@@ -1,3 +1,12 @@
+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 11:46:51 2006  Ben Pfaff  <blp@gnu.org>
 
        Start reforming error message support.  In this phase, we get rid
index cefd144705d92b0c5c021e23505f26bc3cd0441d..009104b03b4fffae1c4018b5f956ee5c8ecf6c81 100644 (file)
@@ -1,3 +1,17 @@
+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
 Sat Apr 15 19:53:19 2006  Ben Pfaff  <blp@gnu.org>
 
        * sfm-private.h: Get rid of #defines after #error, which makes no
index cbfc04ceab3ebf351477708d09048c4108b2e42b..c015bda0ff6a16379279be9020e555b90a3589ec 100644 (file)
@@ -223,123 +223,61 @@ fn_tilde_expand (const char *input)
    Returns the malloc'd full name of the first file found, or NULL if
    none is found.
 
    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. */
    with absolute directories in the path. */
-#if defined (unix) || defined (__MSDOS__) || defined (__WIN32__)
 char *
 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
 }
 
 /* fn_normalize(): This very OS-dependent routine canonicalizes
index e7df800caa405b13f49287a12637c70cceaf3002..8013313876c830631452909532c958e54f0bfeb3 100644 (file)
 #ifndef __MSDOS__
 #define DIR_SEPARATOR '/'
 #define PATH_DELIMITER ':'
 #ifndef __MSDOS__
 #define DIR_SEPARATOR '/'
 #define PATH_DELIMITER ':'
+#define DIR_SEPARATOR_STRING "/"
+#define PATH_DELIMITER_STRING ":"
 #else
 #define DIR_SEPARATOR '\\'
 #define PATH_DELIMITER ';'
 #else
 #define DIR_SEPARATOR '\\'
 #define PATH_DELIMITER ';'
+#define DIR_SEPARATOR_STRING "\\"
+#define PATH_DELIMITER_STRING ";"
 #endif
 
 /* Search path for configuration files. */
 #endif
 
 /* Search path for configuration files. */
@@ -40,9 +44,8 @@ struct string;
 void fn_interp_vars (struct string *target, 
                        const char *(*getenv) (const char *));
 char *fn_tilde_expand (const char *fn);
 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);
 char *fn_normalize (const char *fn);
 char *fn_dirname (const char *fn);
 char *fn_basename (const char *fn);
index 45d265ddcac1681fa9d33a972b560668ea6c434c..d218f7cb1dd5957840e742390c28375307032bf9 100644 (file)
@@ -438,7 +438,7 @@ read_syntax_file (struct string *line, struct getl_source *s)
   /* Open file, if not yet opened. */
   if (s->u.syntax_file == NULL)
     {
   /* 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)
       s->u.syntax_file = fn_open (s->fn, "r");
 
       if (s->u.syntax_file == NULL)
index 45c54dfc0873f816fb6d57033c55a238d927b79b..d87a2b6ad908a0fa30066a5595d726de34b4292e 100644 (file)
@@ -1,3 +1,15 @@
+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
 Sun Apr 16 11:48:07 2006  Ben Pfaff  <blp@gnu.org>
 
        Start reforming error message support.  In this phase, we get rid
index f906458524ac3bc867ffcf5eee7060401f81943c..4c73b3e105c77c8a29329a85ce00f3d3b04cab76 100644 (file)
@@ -30,16 +30,9 @@ enum
     SE, SW, SM,                        /* Script error/warning/message. */
     DE, DW,                    /* Data-file error/warning. */
     ME, MW, MM,                        /* General error/warning/message. */
     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
   {
 /* A file location.  */
 struct file_locator
   {
@@ -73,6 +66,9 @@ void msg (int class, const char *format, ...)
 void tmsg (int class, const char *title, const char *format, ...)
      PRINTF_FORMAT (3, 4);
 
 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 *);
 /* File-locator stack. */
 void err_push_file_locator (const struct file_locator *);
 void err_pop_file_locator (const struct file_locator *);
index 2e7a003bf35a49bcdb0d94c2bc329f70b4d551f3..c48b08e8b133b0acf029833a0522998b5bbdffee 100644 (file)
@@ -30,6 +30,7 @@
 #include <data/settings.h>
 #include <ui/terminal/read-line.h>
 #include <libpspp/version.h>
 #include <data/settings.h>
 #include <ui/terminal/read-line.h>
 #include <libpspp/version.h>
+#include "progname.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -80,6 +81,23 @@ msg (int class, const char *format, ...)
   va_end (args);
 }
 
   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
 /* Checks whether we've had so many errors that it's time to quit
    processing this syntax file. */
 void
@@ -138,7 +156,7 @@ err_vmsg (const struct error *e, const char *format, va_list args)
       const char *banner;      /* Banner. */
     };
 
       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 */
     {
       {3, &err_error_count, N_("error")},      /* SE */
       {3, &err_warning_count, N_("warning")},  /* SW */
@@ -153,19 +171,12 @@ err_vmsg (const struct error *e, const char *format, va_list args)
     };
 
   struct string msg;
     };
 
   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);
   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_printf (&msg, "%s:", e->where.filename);
       if (e->where.line_number != -1)
@@ -173,15 +184,16 @@ err_vmsg (const struct error *e, const char *format, va_list args)
       ds_putc (&msg, ' ');
     }
 
       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 (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)
     ds_printf (&msg, "%s: ", command_name);
 
   if (e->title)
index e1f6e3f9d4c98ec3fa2d1f0a8588da5911e93cca..349b5d3c3212b386f978d8dd6318dece52c33a07 100644 (file)
@@ -291,7 +291,7 @@ outp_read_devices (void)
   if (init_fn == NULL)
     {
       error (0, 0, _("cannot find output initialization file "
   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;
     }
 
       goto exit;
     }
 
index f0c95e511aa659a40a028340731fc94c57f7fd5f..f55f6eb0a35ab35c3037c8ab30edc56b0a73c186 100644 (file)
@@ -1,3 +1,13 @@
+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
 Sun Apr 16 11:53:25 2006  Ben Pfaff  <blp@gnu.org>
 
        Start reforming error message support.  In this phase, we get rid
index 01eb8ce509409219622a8039b9b90d596c7cb1e9..73e147d6c0520236a5a01252863c2928446eb6b5 100644 (file)
@@ -26,6 +26,7 @@
 #include <config.h>
 #include <libpspp/message.h>
 #include "message-dialog.h"
 #include <config.h>
 #include <libpspp/message.h>
 #include "message-dialog.h"
+#include "progname.h"
 
 
 #include <gtk/gtk.h>
 
 
 #include <gtk/gtk.h>
@@ -134,22 +135,14 @@ err_assert_fail(const char *expr, const char *file, int line)
   msg(ME, "Assertion failed: %s:%d; (%s)\n",file,line,expr);
 }
 
   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
 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
  */
 /* FIXME: This is a stub .
  * A temporary workaround until getl.c is rearranged
  */