Without objection, I will add this to the Util/ directory in the distribution. It does require the named references patches and the zsh/param/private module. This script takes as arguments a name representing one of the sets of bitflag (or similar) values that are #defined in Src/zsh.h, followed by an integer or a pattern, and prints out the corresponding definition if it can. This has been really helpful for me when using gdb to examine structures that contain bitflags. I extended it beyond the two or three that I regularly found myself using and tried to make the output as useful as possible, i.e., to match the format used in the #define. For flags defined by bit-shifting it also displays the integer value. Example: % Util/printdefines paramflags 50331648 50331648 PM_UNSET|PM_REMOVABLE % Util/printdefines scanparamflags '*MATCH*' SCANPM_MATCHKEY 1<<3 8 SCANPM_MATCHVAL 1<<4 16 SCANPM_MATCHMANY 1<<5 32 SCANPM_KEYMATCH 1<<7 128 If the only argument is a name, all the flags for that name are displayed. % Util/printdefines lexflags LEXFLAGS_ACTIVE 16#01 LEXFLAGS_ZLE 16#02 LEXFLAGS_COMMENTS_KEEP 16#04 LEXFLAGS_COMMENTS_STRIP 16#08 LEXFLAGS_NEWLINE 16#10 If the only argument is a pattern, every set of flags available is searched for a match. % Util/printdefines '(#i)S*G' --- scanparamflags --- SCANPM_ASSIGNING 1<<6 64 SCANPM_CHECKING 1<<10 1024 --- chartokens --- String 85 --- substmodifiers --- SUB_LONG 16#2 (This doesn't work for numbers.) With no arguments, displays a usage message including the names of all the sets of #defines that can be used as the first argument. Although I initially generated the tables mostly programmatically, I haven't come up with any way to keep them up to date if zsh.h changes. Bug reports welcome, I've used it for a while with some of the tables but not all.
Attachment:
printdefines
Description: Binary data