Ethereal-dev: [Ethereal-dev] Patch: value_string convenience macros

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "Peter J. Creath" <peter-ethereal@xxxxxxxxxx>
Date: Thu, 19 Feb 2004 12:58:41 -0500
Since my bitfield_string patch (which sloppily included this) didn't get checked in, I figured I'd go piece by piece and do it properly, especially since my patches were based on 0.10.0a, rather than the current CVS.

The patch attached adds the VS_DEF(x) and VS_END macros. They let you define value_string arrays in a somewhat more convenient fashion when dealing with enums:

(e.g., for an enum of STAT_A=0, STAT_B=2, STAT_N=16:)

const value_string my_vals[] = {
	VS_DEF(STAT_A),
	VS_DEF(STAT_B),
	VS_DEF(STAT_N),
	VS_END
};

This saves a huge amount of typing (and mistakes) for long enum lists. Just with the three entries above, you'd normally have to type:

const value_string my_vals[] = {
	{ STAT_A, "STAT_A" },
	{ STAT_B, "STAT_B" },
	{ STAT_N, "STAT_N" },
	{ 0, NULL }
};

You might at first think that typing 'VS_DEF()' isn't much easier than '{ , "" }', but it's something constant you can cut-and-paste. Using the usual the constant/string pair, you'd have to manually type each constant twice. It was a pain with a 50-element enum.

	-P

Attachment: %value_string.patch
Description: application/applefile

Attachment: value_string.patch
Description: Binary data