code: def main():
      """
      Run ftfy as a command-line utility.
      """
      import argparse
  
      parser = argparse.ArgumentParser(
          description="ftfy (fixes text for you), version %s"
          % __version__
      )
      parser.add_argument(
          "filename",
          default="-",
          nargs="?",
          help="The file whose Unicode is to be fixed. Defaults "
          "to -, meaning standard input.",
      )
      parser.add_argument(
          "-o",
          "--output",
          type=str,
          default="-",
          help="The file to output to. Defaults to -, meaning "
          "standard output.",
      )
      parser.add_argument(
          "-g",
          "--guess",
          action="store_true",
          help="Ask ftfy to guess the encoding of your input. "
          "This is risky. Overrides -e.",
      )
      parser.add_argument(
          "-e",
          "--encoding",
          type=str,
          default="utf-8",
          help="The encoding of the input. Defaults to UTF-8.",
      )
      parser.add_argument(
          "-n",
          "--normalization",
          type=str,
          default="NFC",
          help="The normalization of Unicode to apply. "
          'Defaults to NFC. Can be "none".',
      )
      parser.add_argument(
          "--preserve-entities",
          action="store_true",
          help="Leave HTML entities as they are. The default "
          "is to decode them, as long as no HTML tags "
          "have appeared in the file.",
      )
  
      args = parser.parse_args()
  
      encoding = args.encoding
      if args.guess:
          encoding = None
  
      if args.filename == "-":
          # Get a standard input stream made of bytes, so we can decode it as
          # whatever encoding is necessary.
          file = sys.stdin.buffer
      else:
          file = open(args.filename, "rb")
  
      if args.output == "-":
          outfile = sys.stdout
      else:
          if os.path.realpath(args.output) == os.path.realpath(
              args.filename
          ):
              sys.stderr.write(SAME_FILE_ERROR_TEXT)
              sys.exit(1)
          outfile = open(args.output, "w", encoding="utf-8")
  
      normalization = args.normalization
      if normalization.lower() == "none":
          normalization = None
  
      unescape_html: str | bool
      if args.preserve_entities:
          unescape_html = False
      else:
          unescape_html = "auto"
  
      config = TextFixerConfig(
          unescape_html=unescape_html, normalization=normalization
      )
  
      try:
          for line in fix_file(file, encoding=encoding, config=config):
              try:
                  outfile.write(line)
              except UnicodeEncodeError:
                  if sys.platform == "win32":
                      sys.stderr.write(ENCODE_ERROR_TEXT_WINDOWS)
                  else:
                      sys.stderr.write(ENCODE_ERROR_TEXT_UNIX)
                  sys.exit(1)
      except UnicodeDecodeError as err:
          sys.stderr.write(DECODE_ERROR_TEXT % (encoding, err))
          sys.exit(1)
  
imports: import os
  import sys
  from ftfy import __version__, fix_file, TextFixerConfig
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types