Message Mgmt Utility

T

Tennis

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
 
A

Allin Cottrell

Tennis said:
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
 
T

Thad Smith

Tennis said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top