Exemple #1
0
int
main (int argc, char *argv[])
{
  int i = 1;
  int listmode = 0;
  const char *source_sym;
  const char *error_sym;
  gpg_error_t err;

#ifndef GPG_ERR_INITIALIZED
  gpg_err_init ();
#endif

  i18n_init ();


  if (argc == 1)
    {
      fprintf (stderr, _("Usage: %s GPG-ERROR [...]\n"), 
               strrchr (argv[0],'/')? (strrchr (argv[0], '/')+1): argv[0]);
      exit (1);
    }
  else if (argc == 2 && !strcmp (argv[1], "--version"))
    {
      fputs ("gpg-error (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stdout);
      exit (0);
    }
  else if (argc == 2 && !strcmp (argv[1], "--list"))
    {
      listmode = 1;
    }


  if (listmode)
    {
      for (i=0; i <  GPG_ERR_SOURCE_DIM; i++)
        {
          /* We use error code 1 because gpg_err_make requires a
             non-zero error code. */
          err = gpg_err_make (i, 1);
          err -= 1;
	  source_sym = gpg_strsource_sym (err);
          if (source_sym)
            printf ("%u = (%u, -) = (%s, -) = (%s, -)\n",
                    err, gpg_err_source (err),
                    source_sym, gpg_strsource (err));
        }
      for (i=0; i <  GPG_ERR_CODE_DIM; i++)
        {
          err = gpg_err_make (GPG_ERR_SOURCE_UNKNOWN, i);
	  error_sym = gpg_strerror_sym (err);
          if (error_sym)
            printf ("%u = (-, %u) = (-, %s) = (-, %s)\n",
                    err, gpg_err_code (err),
                    error_sym, gpg_strerror (err));
        }

      i = argc;  /* Don't run the usual stuff.  */
    }
  while (i < argc)
    {
      if (get_err_from_number (argv[i], &err)
	  || get_err_from_symbol (argv[i], &err)
	  || get_err_from_str (argv[i], &err))
	{
	  source_sym = gpg_strsource_sym (err);
	  error_sym = gpg_strerror_sym (err);
	  
	  printf ("%u = (%u, %u) = (%s, %s) = (%s, %s)\n",
		  err, gpg_err_source (err), gpg_err_code (err),
		  source_sym ? source_sym : "-", error_sym ? error_sym : "-",
		  gpg_strsource (err), gpg_strerror (err));
	}
      else
	fprintf (stderr, _("%s: warning: could not recognize %s\n"),
		 argv[0], argv[i]);
      i++;
    }

  exit (0);
}
Exemple #2
0
int
main (int argc, char *argv[])
{
  int i = 1;
  int listmode = 0;
  const char *source_sym;
  const char *error_sym;
  gpg_error_t err;

  gpgrt_init ();
  i18n_init ();

  if (argc == 1)
    {
      fprintf (stderr, _("Usage: %s GPG-ERROR [...]\n"),
               strrchr (argv[0],'/')? (strrchr (argv[0], '/')+1): argv[0]);
      exit (1);
    }
  else if (argc == 2 && !strcmp (argv[1], "--version"))
    {
      fputs ("gpg-error (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stdout);
      exit (0);
    }
  else if (argc == 2 && !strcmp (argv[1], "--help"))
    {
      fputs ("gpg-error (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stdout);
      fputs ("Options:\n"
             "  --version      Print version\n"
             "  --lib-version  Print library version\n"
             "  --help         Print this help\n"
             "  --list         Print all error codes\n"
             "  --defines      Print all error codes as #define lines\n"
             , stdout);
      exit (0);
    }
  else if (argc == 2 && !strcmp (argv[1], "--lib-version"))
    {
      printf ("Version from header: %s (0x%06x)\n",
              GPG_ERROR_VERSION, GPG_ERROR_VERSION_NUMBER);
      printf ("Version from binary: %s\n", gpg_error_check_version (NULL));
      printf ("Copyright blurb ...:%s\n", gpg_error_check_version ("\x01\x01"));
      exit (0);
    }
  else if (argc == 2 && !strcmp (argv[1], "--list"))
    {
      listmode = 1;
    }
  else if (argc == 2 && !strcmp (argv[1], "--defines"))
    {
      listmode = 2;
    }


  if (listmode == 1)
    {
      for (i=0; i <  GPG_ERR_SOURCE_DIM; i++)
        {
          /* We use error code 1 because gpg_err_make requires a
             non-zero error code. */
          err = gpg_err_make (i, 1);
          err -= 1;
	  source_sym = gpg_strsource_sym (err);
          if (source_sym)
            printf ("%u = (%u, -) = (%s, -) = (%s, -)\n",
                    err, gpg_err_source (err),
                    source_sym, gpg_strsource (err));
        }
      for (i=0; i <  GPG_ERR_CODE_DIM; i++)
        {
          err = gpg_err_make (GPG_ERR_SOURCE_UNKNOWN, i);
	  error_sym = gpg_strerror_sym (err);
          if (error_sym)
            printf ("%u = (-, %u) = (-, %s) = (-, %s)\n",
                    err, gpg_err_code (err),
                    error_sym, gpg_strerror (err));
        }
    }
  else if (listmode == 2)
    {
      int n, nmax;

      for (i=0, nmax=0; i <  GPG_ERR_SOURCE_DIM; i++)
        {
          err = gpg_err_make (i, 1);
	  source_sym = gpg_strsource_sym (err);
          if (source_sym)
            {
              n = strlen (source_sym);
              if (n > nmax)
                nmax = n;
            }
        }
      for (i=0; i <  GPG_ERR_SOURCE_DIM; i++)
        {
          err = gpg_err_make (i, 1);
	  source_sym = gpg_strsource_sym (err);
          if (source_sym)
            printf ("#define %-*s %3u\n", nmax,source_sym,gpg_err_source (err));
        }


      for (i=0, nmax = 0; i <  GPG_ERR_CODE_DIM; i++)
        {
          err = gpg_err_make (GPG_ERR_SOURCE_UNKNOWN, i);
	  error_sym = gpg_strerror_sym (err);
          if (error_sym)
            {
              n = strlen (error_sym);
              if (n > nmax)
                nmax = n;
            }
        }
      for (i=0; i <  GPG_ERR_CODE_DIM; i++)
        {
          err = gpg_err_make (GPG_ERR_SOURCE_UNKNOWN, i);
	  error_sym = gpg_strerror_sym (err);
          if (error_sym)
            printf ("#define %-*s %5u\n", nmax, error_sym, gpg_err_code (err));
        }
    }
  else /* Standard mode.  */
    {
      while (i < argc)
        {
          if (get_err_from_number (argv[i], &err)
              || get_err_from_symbol (argv[i], &err)
              || get_err_from_str (argv[i], &err))
            {
              source_sym = gpg_strsource_sym (err);
              error_sym = gpg_strerror_sym (err);

              printf ("%u = (%u, %u) = (%s, %s) = (%s, %s)\n",
                      err, gpg_err_source (err), gpg_err_code (err),
                      source_sym ? source_sym : "-", error_sym ? error_sym:"-",
                      gpg_strsource (err), gpg_strerror (err));
            }
          else
            fprintf (stderr, _("%s: warning: could not recognize %s\n"),
                     argv[0], argv[i]);
          i++;
        }
    }

  exit (0);
}