docs: def main(args=None, prog=None):
      """Generates a C header file"""
      args = args if args is not None else sys.argv[1:]
      prog = prog if prog is not None else sys.argv[0]
      # Prevent broken pipe exception from being raised.
      signal.signal(signal.SIGPIPE, signal.SIG_DFL)
      stdin = sys.stdin.buffer if hasattr(sys.stdin, 'buffer') else sys.stdin
      p = argparse.ArgumentParser(prog=prog)
      p.add_argument('-o', '--output', metavar='PATH',
                     type=argparse.FileType('w'), default=sys.stdout,
                     help='Write output to PATH')
      p.add_argument('--api', help='Match API', default=None)
      p.add_argument('--profile', help='Match profile', default=None)
      p.add_argument('--support', default=None,
                     help='Match extension support string')
      g = p.add_mutually_exclusive_group()
      g.add_argument('--list-apis', action='store_true', dest='list_apis',
                     help='List apis in registry', default=False)
      g.add_argument('--list-profiles', action='store_true', default=False,
                     dest='list_profiles', help='List profiles in registry')
      g.add_argument('--list-supports', action='store_true',
                     dest='list_supports', default=False,
                     help='List extension support strings')
      p.add_argument('registry', type=argparse.FileType('rb'), nargs='?',
                     default=stdin, help='Registry path')
      args = p.parse_args(args)
      o = args.output
      try:
          registry = load(args.registry)
          if args.list_apis:
              for x in sorted(registry.get_apis()):
                  print(x, file=o)
              return 0
          elif args.list_profiles:
              for x in sorted(registry.get_profiles()):
                  print(x, file=o)
              return 0
          elif args.list_supports:
              for x in sorted(registry.get_supports()):
                  print(x, file=o)
              return 0
          apis = group_apis(registry, None, None, args.api, args.profile,
                            args.support)
          for api in apis:
              print('#ifndef', api.name, file=o)
              print('#define', api.name, file=o)
              print(api.text, file=o)
              print('#endif', file=o)
              print('', file=o)
      except:
          e = sys.exc_info()[1]
          print(prog, ': error: ', e, sep='', file=sys.stderr)
          return 1
      return 0