Definition: | string res = decode_flags(sequence FlagSet, atom v, string sep="+") |
Description: |
Create a human readable string for a bit field.
FlagSet: a table of {flag,text} pairs. v: the value to be deciphered. sep: a separator, default "+". Returns a string representing the bit settings of v. |
Comments: |
This is useful anywhere you have a bitmap field and want to show a human-readable version. Further examples can be found in demo\arwendemo\filedump.exw Obviously each application must define it’s own FlagSet(s). The order of FlagSet determines the order things appear in the result. If a description begins with '-', the separator(optional p3) is omitted. A decription(s) of "" can be used to ignore/suppress specific bit settings. The first entry in FlagSet can be eg {0,"closed"} to specify the "no bits set" meaning. Any bits not recognised are returned as a hex value at the start. |
Example 1: |
-- (these "FILE_ATTRIBUTE_XXX" flags can be found in demo\arwen\constants.e) constant FileFlagSet = {{FILE_ATTRIBUTE_READONLY, "R"}, {FILE_ATTRIBUTE_SYSTEM, "S"}, {FILE_ATTRIBUTE_HIDDEN, "H"}, {FILE_ATTRIBUTE_DIRECTORY, "D"}} ? decode_flags(FileFlagSet,#17,"") -- "RSHD" |
Example 2: |
constant FileFlagSet = {{FILE_ATTRIBUTE_READONLY, "Read"}, {FILE_ATTRIBUTE_SYSTEM, "System"}, {FILE_ATTRIBUTE_HIDDEN, "Hidden"}, {FILE_ATTRIBUTE_DIRECTORY, "Directory"}} ? decode_flags(FileFlagSet,#17) -- "Read+System+Hidden+Directory" |