main (int argc, char **argv)
{
  int last_argc = -1;

  if (argc)
    {
      argc--; argv++;
    }
  while (argc && last_argc != argc )
    {
      last_argc = argc;
      if (!strcmp (*argv, "--"))
        {
          argc--; argv++;
          break;
        }
      else if (!strcmp (*argv, "--version"))
        {
          fputs (PGM " ("GNUPG_NAME") " PACKAGE_VERSION "\n", stdout);
          exit (0);
        }
      else if (!strcmp (*argv, "--help"))
        {
          puts ("Usage: " PGM " [BUS:DEV]\n"
                "Parse the output of usbmod assuming it is CCID compliant.\n\n"
                "  --skip-escape  do not show escape packets\n"
                "  --sniffusb     Assume output from Sniffusb.exe\n"
                "  --verbose      enable extra informational output\n"
                "  --debug        enable additional debug output\n"
                "  --help         display this help and exit\n\n"
                "Report bugs to " PACKAGE_BUGREPORT ".");
          exit (0);
        }
      else if (!strcmp (*argv, "--verbose"))
        {
          verbose = 1;
          argc--; argv++;
        }
      else if (!strcmp (*argv, "--debug"))
        {
          verbose = debug = 1;
          argc--; argv++;
        }
      else if (!strcmp (*argv, "--skip-escape"))
        {
          skip_escape = 1;
          argc--; argv++;
        }
      else if (!strcmp (*argv, "--sniffusb"))
        {
          sniffusb = 1;
          argc--; argv++;
        }
    }

  if (argc && sniffusb)
    die ("no arguments expected when using --sniffusb\n");
  else if (argc > 1)
    die ("usage: " PGM " [BUS:DEV]  (try --help for more information)\n");

  if (argc == 1)
    {
      const char *s = strchr (argv[0], ':');

      usb_bus = atoi (argv[0]);
      if (s)
        usb_dev =  atoi (s+1);
      if (usb_bus < 1 || usb_bus > 999 || usb_dev < 1 || usb_dev > 999)
        die ("invalid bus:dev specified");
    }


  signal (SIGPIPE, SIG_IGN);

  parse_input (stdin);

  return any_error? 1:0;
}
main (int argc, char **argv)
{
  int last_argc = -1;

  if (argc)
    {
      argc--; argv++;
    }
  while (argc && last_argc != argc )
    {
      last_argc = argc;
      if (!strcmp (*argv, "--"))
        {
          argc--; argv++;
          break;
        }
      else if (!strcmp (*argv, "--version"))
        {
          fputs (PGM " ("GNUPG_NAME") " PACKAGE_VERSION "\n", stdout);
          exit (0);
        }
      else if (!strcmp (*argv, "--help"))
        {
          puts ("Usage: " PGM " [BUS:DEV]\n"
                "Parse the output of usbmod assuming it is CCID compliant.\n\n"
                "  --skip-escape  do not show escape packets\n"
                "  --sniffusb     Assume output from Sniffusb.exe\n"
                "  --verbose      enable extra informational output\n"
                "  --debug        enable additional debug output\n"
                "  --help         display this help and exit\n\n"
                "Report bugs to " PACKAGE_BUGREPORT ".");
          exit (0);
        }
      else if (!strcmp (*argv, "--verbose"))
        {
          verbose = 1;
          argc--; argv++;
        }
      else if (!strcmp (*argv, "--debug"))
        {
          verbose = debug = 1;
          argc--; argv++;
        }
      else if (!strcmp (*argv, "--skip-escape"))
        {
          skip_escape = 1;
          argc--; argv++;
        }
      else if (!strcmp (*argv, "--sniffusb"))
        {
          sniffusb = 1;
          argc--; argv++;
        }
    }

  if (argc && sniffusb)
    die ("no arguments expected when using --sniffusb\n");
  else if (argc > 1)
    die ("usage: " PGM " [BUS:DEV]  (try --help for more information)\n");

  if (argc == 1)
    {
      const char *s = strchr (argv[0], ':');

      usb_bus = atoi (argv[0]);
      if (s)
        usb_dev =  atoi (s+1);
      if (usb_bus < 1 || usb_bus > 999 || usb_dev < 1 || usb_dev > 999)
        die ("invalid bus:dev specified");
    }


  signal (SIGPIPE, SIG_IGN);

  parse_input (stdin);

  return any_error? 1:0;
}