Message Mgmt Utility

Discussion in 'C Programming' started by Tennis, Jan 7, 2005.

  1. Tennis

    Tennis Guest

    Hi,

    Does anyone know of a utility that automatically manages the message
    format, labeling and numbering of messages during collaborative program
    development?

    In the example below, the values "foo-001", "foo-002" would be
    auto-generated and managed by the utility:

    if ( problem == FILE_IO) {
    printf("foo-001 File IO failed\n");
    }

    if ( problem == FILE_MISSING) {
    printf("foo-002 File missing!\n");
    }

    The object, of course, is to keep the programmer from manually creating
    and managing the values.

    TIA,
    -Tennis
    Tennis, Jan 7, 2005
    #1
    1. Advertising

  2. Tennis wrote:
    > Hi,
    >
    > Does anyone know of a utility that automatically manages the message
    > format, labeling and numbering of messages during collaborative program
    > development?
    >
    > In the example below, the values "foo-001", "foo-002" would be
    > auto-generated and managed by the utility:
    >
    > if ( problem == FILE_IO) {
    > printf("foo-001 File IO failed\n");
    > }
    >
    > if ( problem == FILE_MISSING) {
    > printf("foo-002 File missing!\n");
    > }
    >
    > The object, of course, is to keep the programmer from manually creating
    > and managing the values.


    In C, you may want to consider the __FILE__ and __LINE__ macros.
    Quoting the gcc documentation:

    __FILE__ and __LINE__ are useful in generating an error message to
    report an inconsistency detected by the program; the message can
    state the source line at which the inconsistency was detected.
    For example,


    fprintf (stderr, "Internal error: "
    "negative string length "
    "%d at %s, line %d.",
    length, __FILE__, __LINE__);

    Allin Cottrell
    Allin Cottrell, Jan 8, 2005
    #2
    1. Advertising

  3. Tennis

    Thad Smith Guest

    Tennis wrote:

    > Does anyone know of a utility that automatically manages the message
    > format, labeling and numbering of messages during collaborative program
    > development?
    >
    > In the example below, the values "foo-001", "foo-002" would be
    > auto-generated and managed by the utility:
    >
    > if ( problem == FILE_IO) {
    > printf("foo-001 File IO failed\n");
    > }
    >
    > if ( problem == FILE_MISSING) {
    > printf("foo-002 File missing!\n");
    > }
    >
    > The object, of course, is to keep the programmer from manually creating
    > and managing the values.


    Depending on what you need, you may be able to use fairly
    straight-forward C coding:

    problist.h"
    PROB(FILE_IO, "File IO Failed"),
    PROB(FILE_MISSING, "File missing!"),
    ....

    code.c:
    /* Assign error numbers to list */
    #define PROB(name,str) name
    enum {
    NOPROB = 0, /* first error will be 1 */
    #include "problist.h"
    NPROBS
    };

    /* Store problem strings */
    #undef PROB
    #define PROB(name,str) str
    const char * const errmsg[] = {
    "OK",
    #include "problist.h"
    };

    ....
    problem = FILE_IO;
    ...
    if (problem) {
    printf ("foo-%3d - %s\n", problem, errmsg[problem]);
    }

    You probably want to change some details, but the gist is that one file,
    problist.h here, contains a list of problem identifiers and strings.
    The compiler assigns increasing error codes and stores the strings in a
    table.

    You could also write a simple program, using the same header, to
    generate a list of error codes and strings.

    Thad
    Thad Smith, Jan 8, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Krishnan

    ASP .Net pages - instance mgmt

    Krishnan, Apr 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    272
    Krishnan
    Apr 5, 2004
  2. =?Utf-8?B?QVZM?=

    state mgmt issue

    =?Utf-8?B?QVZM?=, Feb 13, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    316
    Steve C. Orr [MVP, MCSD]
    Feb 13, 2006
  3. Fastau B

    session mgmt - redirection

    Fastau B, Mar 19, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    389
    Fastau B
    Mar 20, 2006
  4. Karthik D
    Replies:
    3
    Views:
    705
    Karthik D
    Jul 2, 2003
  5. richard

    memory mgmt problem

    richard, Sep 1, 2003, in forum: C Programming
    Replies:
    12
    Views:
    545
    richard
    Sep 2, 2003
Loading...

Share This Page