code: def makeunicodename(unicode, trace):
      from dawg import build_compression_dawg
  
      FILE = "Modules/unicodename_db.h"
  
      print("--- Preparing", FILE, "...")
  
      # unicode name hash table
  
      # extract names
      data = []
      for char in unicode.chars:
          record = unicode.table[char]
          if record:
              name = record.name.strip()
              if name and name[0] != "<":
                  data.append((name, char))
  
      print("--- Writing", FILE, "...")
  
      with open(FILE, "w") as fp:
          fprint = partial(print, file=fp)
  
          fprint(
              "/* this file was generated by %s %s */"
              % (SCRIPT, VERSION)
          )
          fprint()
          fprint("#define NAME_MAXLEN", 256)
          assert max(len(x) for x in data) < 256
          fprint()
  
          fprint("/* name->code dictionary */")
          packed_dawg, pos_to_codepoint = build_compression_dawg(data)
          notfound = len(pos_to_codepoint)
          inverse_list = [notfound] * len(unicode.chars)
          for pos, codepoint in enumerate(pos_to_codepoint):
              inverse_list[codepoint] = pos
          Array("packed_name_dawg", list(packed_dawg)).dump(fp, trace)
          Array("dawg_pos_to_codepoint", pos_to_codepoint).dump(
              fp, trace
          )
          index1, index2, shift = splitbins(inverse_list, trace)
          fprint("#define DAWG_CODEPOINT_TO_POS_SHIFT", shift)
          fprint("#define DAWG_CODEPOINT_TO_POS_NOTFOUND", notfound)
          Array("dawg_codepoint_to_pos_index1", index1).dump(fp, trace)
          Array("dawg_codepoint_to_pos_index2", index2).dump(fp, trace)
  
          fprint()
          fprint(
              "static const unsigned int aliases_start = %#x;"
              % NAME_ALIASES_START
          )
          fprint(
              "static const unsigned int aliases_end = %#x;"
              % (NAME_ALIASES_START + len(unicode.aliases))
          )
  
          fprint("static const unsigned int name_aliases[] = {")
          for name, codepoint in unicode.aliases:
              fprint("    0x%04X," % codepoint)
          fprint("};")
  
          # In Unicode 6.0.0, the sequences contain at most 4 BMP chars,
          # so we are using Py_UCS2 seq[4].  This needs to be updated if longer
          # sequences or sequences with non-BMP chars are added.
          # unicodedata_lookup should be adapted too.
          fprint(
              dedent(
                  """
              typedef struct NamedSequence {
                  int seqlen;
                  Py_UCS2 seq[4];
              } named_sequence;
              """
              )
          )
  
          fprint(
              "static const unsigned int named_sequences_start = %#x;"
              % NAMED_SEQUENCES_START
          )
          fprint(
              "static const unsigned int named_sequences_end = %#x;"
              % (NAMED_SEQUENCES_START + len(unicode.named_sequences))
          )
  
          fprint("static const named_sequence named_sequences[] = {")
          for name, sequence in unicode.named_sequences:
              seq_str = ", ".join("0x%04X" % cp for cp in sequence)
              fprint("    {%d, {%s}}," % (len(sequence), seq_str))
          fprint("};")
  
imports: import dataclasses
  import os
  import sys
  import zipfile
  from functools import partial
  from textwrap import dedent
  from typing import Iterator, List, Optional, Set, Tuple
label_desc: Use image node_id 4 for calling a global function with example usage: makeunicodename(unicode, trace) without return types