X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fmessage.h;h=9dae1e40ac98396fcfa3d834a17c2346e21c68d0;hb=7102dc8607b7e6e25bdb9806f508dce71fe76ce4;hp=7505f7b0809641a71cf19322f5a59db1df13bda1;hpb=2322678e8fddbbf158b01b2720db2636404bba3b;p=pspp diff --git a/src/libpspp/message.h b/src/libpspp/message.h index 7505f7b080..9dae1e40ac 100644 --- a/src/libpspp/message.h +++ b/src/libpspp/message.h @@ -25,33 +25,61 @@ #include "compiler.h" /* Message classes. */ -enum +enum msg_class { - SE, SW, SM, /* Script error/warning/message. */ - IE, IS, /* Installation error/script error. */ - 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. */ + ME, MW, MN, /* General error/warning/note. */ + SE, SW, SN, /* Script error/warning/note. */ + DE, DW, DN, /* Data-file error/note. */ + 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)) +/* What kind of message is this? */ +enum msg_category + { + MSG_GENERAL, /* General info. */ + MSG_SYNTAX, /* Messages that relate to syntax files. */ + MSG_DATA /* Messages that relate to data files. */ + }; + +/* How important a condition is it? */ +enum msg_severity + { + MSG_ERROR, + MSG_WARNING, + MSG_NOTE + }; + +static inline enum msg_category +msg_class_to_category (enum msg_class class) +{ + return class / 3; +} + +static inline enum msg_severity +msg_class_to_severity (enum msg_class class) +{ + return class % 3; +} + +static inline enum msg_class +msg_class_from_category_and_severity (enum msg_category category, + enum msg_severity severity) +{ + return category * 3 + severity; +} /* A file location. */ struct file_locator { - const char *filename; /* Filename. */ + const char *file_name; /* File name. */ int line_number; /* Line number. */ }; /* An error message. */ struct error { - int class; /* One of the classes above. */ + enum msg_category category; /* Message category. */ + enum msg_severity severity; /* Message severity. */ struct file_locator where; /* File location, or (NULL, -1). */ const char *title; /* Special text inserted if not null. */ }; @@ -69,11 +97,14 @@ extern int err_already_flagged; extern int err_verbosity; /* Functions. */ -void msg (int class, const char *format, ...) +void msg (enum msg_class, const char *format, ...) PRINTF_FORMAT (2, 3); -void tmsg (int class, const char *title, const char *format, ...) +void tmsg (enum msg_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 *);