104 text = str(fid).zfill(8)
107 group, area, section, number = int(text[0]), text[1:4], int(text[4]), int(text[5:8])
108 if group
not in groups
or area
not in areas:
112 + areas[area] * 0x500
114 + (number - number % 32) // 8
116 return off, 0x80000000 >> (number % 32)
148 ap = argparse.ArgumentParser(
149 description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
151 ap.add_argument(
"-o",
"--out", default=OUT)
152 args = ap.parse_args()
155 if not groups
or not areas:
156 sys.exit(f
"no addressing tables in {ADDRESSING}")
158 table = collections.defaultdict(list)
159 skipped_index = skipped_area = excluded = 0
160 with open(KNOWN, encoding=
"utf-8-sig")
as f:
161 for row
in csv.DictReader(f):
162 raw = (row.get(
"flag_id")
or "").strip()
163 if not raw.isdigit():
169 at =
address(fid, groups, areas)
173 cat = (row.get(
"category")
or "Other").strip()
or "Other"
174 if cat
in EXCLUDE_CATEGORIES:
177 table[cat].append([at[0], at[1],
clean(row.get(
"name")
or "", fid, cat)])
179 order = {c: i
for i, c
in enumerate(CATEGORY_ORDER)}
180 out = collections.OrderedDict()
181 for cat
in sorted(table, key=
lambda c: (order.get(c, len(order)), c)):
182 out[cat] = sorted(table[cat], key=
lambda r: (r[0], -r[1]))
184 with open(args.out,
"w", encoding=
"utf-8")
as f:
185 json.dump(out, f, ensure_ascii=
False, indent=1)
187 total = sum(len(v)
for v
in out.values())
188 print(f
"wrote {args.out}: {total} flags in {len(out)} categories")
189 for cat, rows
in out.items():
190 print(f
" {len(rows):3} {cat}")
193 f
" dropped {excluded} in {', '.join(sorted(EXCLUDE_CATEGORIES))} "
194 f
"(transient — see EXCLUDE_CATEGORIES)"
197 print(f
" skipped {skipped_index} enum indices (not event flags)")
199 print(f
" skipped {skipped_area} with an unmapped group/area")