From: Ben Pfaff Date: Sun, 16 Apr 2006 23:08:02 +0000 (+0000) Subject: Continue reforming error message support. In this phase, we get rid X-Git-Tag: v0.6.0~981 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8dd3a226c9b963314bbe6a2ed2cf74714072c77;p=pspp-builds.git 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(). --- diff --git a/src/ChangeLog b/src/ChangeLog index 80a60331..36ae08da 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +Sun Apr 16 15:58:56 2006 Ben Pfaff + + 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 Start reforming error message support. In this phase, we get rid diff --git a/src/data/ChangeLog b/src/data/ChangeLog index cefd1447..009104b0 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,17 @@ +Sun Apr 16 16:05:28 2006 Ben Pfaff + + 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 * sfm-private.h: Get rid of #defines after #error, which makes no diff --git a/src/data/filename.c b/src/data/filename.c index cbfc04ce..c015bda0 100644 --- a/src/data/filename.c +++ b/src/data/filename.c @@ -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. - 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 diff --git a/src/data/filename.h b/src/data/filename.h index e7df800c..80133138 100644 --- a/src/data/filename.h +++ b/src/data/filename.h @@ -26,9 +26,13 @@ #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. */ @@ -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); -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); diff --git a/src/language/line-buffer.c b/src/language/line-buffer.c index 45d265dd..d218f7cb 100644 --- a/src/language/line-buffer.c +++ b/src/language/line-buffer.c @@ -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) { - 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) diff --git a/src/libpspp/ChangeLog b/src/libpspp/ChangeLog index 45c54dfc..d87a2b6a 100644 --- a/src/libpspp/ChangeLog +++ b/src/libpspp/ChangeLog @@ -1,3 +1,15 @@ +Sun Apr 16 16:05:43 2006 Ben Pfaff + + 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 Start reforming error message support. In this phase, we get rid diff --git a/src/libpspp/message.h b/src/libpspp/message.h index f9064585..4c73b3e1 100644 --- a/src/libpspp/message.h +++ b/src/libpspp/message.h @@ -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. */ - 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 { @@ -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 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 *); diff --git a/src/message.c b/src/message.c index 2e7a003b..c48b08e8 100644 --- a/src/message.c +++ b/src/message.c @@ -30,6 +30,7 @@ #include #include #include +#include "progname.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -80,6 +81,23 @@ msg (int class, const char *format, ...) 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 @@ -138,7 +156,7 @@ err_vmsg (const struct error *e, const char *format, va_list args) 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 */ @@ -153,19 +171,12 @@ err_vmsg (const struct error *e, const char *format, va_list args) }; 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) @@ -173,15 +184,16 @@ err_vmsg (const struct error *e, const char *format, va_list args) 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) diff --git a/src/output/output.c b/src/output/output.c index e1f6e3f9..349b5d3c 100644 --- a/src/output/output.c +++ b/src/output/output.c @@ -291,7 +291,7 @@ outp_read_devices (void) 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; } diff --git a/src/ui/gui/ChangeLog b/src/ui/gui/ChangeLog index f0c95e51..f55f6eb0 100644 --- a/src/ui/gui/ChangeLog +++ b/src/ui/gui/ChangeLog @@ -1,3 +1,13 @@ +Sun Apr 16 16:06:54 2006 Ben Pfaff + + 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 Start reforming error message support. In this phase, we get rid diff --git a/src/ui/gui/message-dialog.c b/src/ui/gui/message-dialog.c index 01eb8ce5..73e147d6 100644 --- a/src/ui/gui/message-dialog.c +++ b/src/ui/gui/message-dialog.c @@ -26,6 +26,7 @@ #include #include #include "message-dialog.h" +#include "progname.h" #include @@ -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); } -/* 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 */