-/*
+/* asn1Coding.c --- program to generate a DER coding of an ASN1 definition.
* Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation
* Copyright (C) 2002 Fabio Fiorina
*
*
*/
-
-/*****************************************************/
-/* File: asn1Coding.c */
-/* Description: program to generate a DER coding */
-/* of an ASN1 definition. */
-/*****************************************************/
-
#include <config.h>
#include <stdio.h>
#include <progname.h>
#include <version-etc.h>
-static const char help_man[] =
- "Usage: asn1Coding [OPTION] DEFINITIONS ASSIGNMENTS\n"
- "asn1Coding generates a DER encoding of ASN.1 DEFINITIONS file\n"
- "and ASSIGNMENTS file with value assignments.\n"
- "\n"
- "Mandatory arguments to long options are mandatory for short options too.\n"
- " -c, --check checks the syntax only\n"
- " -o, --output FILE output file\n"
- " -h, --help display this help and exit\n"
- " -v, --version output version information and exit.\n"
- "\n" "Report bugs to <" PACKAGE_BUGREPORT ">.";
+/* This feature is available in gcc versions 2.5 and later. */
+#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
+# define ATTR_NO_RETRUN
+#else
+# define ATTR_NO_RETRUN __attribute__ ((__noreturn__))
+#endif
+
+ATTR_NO_RETRUN
+static void
+usage (int status)
+{
+ if (status != EXIT_SUCCESS)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION] DEFINITIONS ASSIGNMENTS\n", program_name);
+ printf ("\
+Generates a DER encoding of ASN.1 DEFINITIONS file\n\
+and ASSIGNMENTS file with value assignments.\n\
+\n");
+ printf ("\
+Mandatory arguments to long options are mandatory for short options too.\n\
+ -c, --check checks the syntax only\n\
+ -o, --output FILE output file\n\
+ -h, --help display this help and exit\n\
+ -v, --version output version information and exit\n");
+ emit_bug_reporting_address ();
+ }
+ exit (status);
+}
#define ASSIGNMENT_SUCCESS 1
#define ASSIGNMENT_ERROR 2
return ASSIGNMENT_SUCCESS;
}
-
-
static void
createFileName (char *inputFileName, char **outputFileName)
{
return;
}
-
-/********************************************************/
-/* Function : main */
-/* Description: */
-/********************************************************/
int
main (int argc, char *argv[])
{
switch (option_result)
{
case 'h': /* HELP */
- printf ("%s\n", help_man);
-
free (outputFileName);
- exit (0);
+ usage (EXIT_SUCCESS);
break;
case 'v': /* VERSION */
version_etc (stdout, program_name, PACKAGE, VERSION,
strcpy (outputFileName, optarg);
break;
case '?': /* UNKNOW OPTION */
+ free (outputFileName);
fprintf (stderr,
"asn1Coding: option '%s' not recognized or without argument.\n\n",
argv[optind - 1]);
- printf ("%s\n", help_man);
-
- free (outputFileName);
- exit (1);
+ usage (EXIT_FAILURE);
break;
default:
fprintf (stderr,
}
}
- if (optind == argc)
- {
- fprintf (stderr,
- "asn1Coding: input file with ASN1 definitions missing.\n");
- fprintf (stderr,
- " input file with assignments missing.\n\n");
- printf ("%s\n", help_man);
-
- free (outputFileName);
- exit (1);
- }
-
- if (optind == argc - 1)
+ if (optind == argc || optind == argc -1)
{
- fprintf (stderr,
- "asn1Coding: input file with assignments missing.\n\n");
- printf ("%s\n", help_man);
-
free (outputFileName);
- exit (1);
+ fprintf (stderr, "asn1Coding: input files missing\n");
+ usage (EXIT_FAILURE);
}
inputFileAsnName = (char *) malloc (strlen (argv[optind]) + 1);
-/*
+/* asn1Decoding.c --- program to generate an ASN1 type from a DER coding.
* Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation
* Copyright (C) 2002 Fabio Fiorina
*
*
*/
-
-/*****************************************************/
-/* File: asn1Deoding.c */
-/* Description: program to generate an ASN1 type from*/
-/* a DER coding. */
-/*****************************************************/
-
#include <config.h>
#include <stdio.h>
#include <version-etc.h>
#include <read-file.h>
-static const char help_man[] =
- "Usage: asn1Decoding [OPTION] DEFINITIONS ENCODED ASN1TYPE\n"
- "asn1Decoding decodes DER data in ENCODED file, for the ASN1TYPE element\n"
- "described in ASN.1 DEFINITIONS file, and print decoded structures.\n"
- "\n"
- " -c, --check checks the syntax only\n"
- " -h, --help display this help and exit\n"
- " -v, --version output version information and exit.\n"
- "\n" "Report bugs to <" PACKAGE_BUGREPORT ">.";
-
-/********************************************************/
-/* Function : main */
-/* Description: */
-/********************************************************/
+/* This feature is available in gcc versions 2.5 and later. */
+#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
+# define ATTR_NO_RETRUN
+#else
+# define ATTR_NO_RETRUN __attribute__ ((__noreturn__))
+#endif
+
+ATTR_NO_RETRUN
+static void
+usage (int status)
+{
+ if (status != EXIT_SUCCESS)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION] DEFINITIONS ENCODED ASN1TYPE\n", program_name);
+ printf ("\
+Decodes DER data in ENCODED file, for the ASN1TYPE element\n\
+described in ASN.1 DEFINITIONS file, and print decoded structures.\n\
+\n");
+ printf ("\
+ -c, --check checks the syntax only\n\
+ -h, --help display this help and exit\n\
+ -v, --version output version information and exit\n");
+ emit_bug_reporting_address ();
+ }
+ exit (status);
+}
+
int
main (int argc, char *argv[])
{
switch (option_result)
{
case 'h': /* HELP */
- printf ("%s\n", help_man);
- exit (0);
+ usage (EXIT_SUCCESS);
break;
case 'v': /* VERSION */
version_etc (stdout, program_name, PACKAGE, VERSION,
fprintf (stderr,
"asn1Decoding: option '%s' not recognized or without argument.\n\n",
argv[optind - 1]);
- printf ("%s\n", help_man);
-
- exit (1);
+ usage (EXIT_FAILURE);
break;
default:
fprintf (stderr,
}
}
- if (optind == argc)
- {
- fprintf (stderr,
- "asn1Decoding: input file with ASN1 definitions missing.\n");
- fprintf (stderr, " input file with DER coding missing.\n");
- fprintf (stderr, " ASN1 type name missing.\n\n");
- printf ("%s\n", help_man);
-
- exit (1);
- }
-
- if (optind == argc - 1)
+ if (optind == argc || optind == argc - 1 || optind == argc - 2)
{
- fprintf (stderr,
- "asn1Decoding: input file with DER coding missing.\n\n");
- fprintf (stderr, " ASN1 type name missing.\n\n");
- printf ("%s\n", help_man);
-
- exit (1);
- }
-
- if (optind == argc - 2)
- {
- fprintf (stderr, "asn1Decoding: ASN1 type name missing.\n\n");
- printf ("%s\n", help_man);
-
- exit (1);
+ fprintf (stderr, "asn1Decoding: input files or ASN.1 type "
+ "name missing\n");
+ usage (EXIT_FAILURE);
}
inputFileAsnName = (char *) malloc (strlen (argv[optind]) + 1);
-/*
+/* asn1Parser.c -- program to parse a file with ASN1 definitions
* Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation
* Copyright (C) 2002 Fabio Fiorina
*
*
*/
-
-/*****************************************************/
-/* File: asn1Parser.c */
-/* Description: program to parse a file with ASN1 */
-/* definitions. */
-/*****************************************************/
-
#include <config.h>
#include <stdio.h>
#include <progname.h>
#include <version-etc.h>
-static const char help_man[] =
- "Usage: asn1Parser [OPTION] FILE\n"
- "Read FILE with ASN.1 definitions and generate\n"
- "a C array that is used with libtasn1 functions.\n"
- "\n"
- "Mandatory arguments to long options are mandatory for short options too.\n"
- " -c, --check checks the syntax only\n"
- " -o, --output FILE output file\n"
- " -n, --name NAME array name\n"
- " -h, --help display this help and exit\n"
- " -v, --version output version information and exit.\n"
- "\n" "Report bugs to <" PACKAGE_BUGREPORT ">.";
-
-/********************************************************/
-/* Function : main */
-/* Description: */
-/********************************************************/
+/* This feature is available in gcc versions 2.5 and later. */
+#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
+# define ATTR_NO_RETRUN
+#else
+# define ATTR_NO_RETRUN __attribute__ ((__noreturn__))
+#endif
+
+ATTR_NO_RETRUN
+static void
+usage (int status)
+{
+ if (status != EXIT_SUCCESS)
+ fprintf (stderr, "Try `%s --help' for more information.\n",
+ program_name);
+ else
+ {
+ printf ("\
+Usage: %s [OPTION] FILE\n", program_name);
+ printf ("\
+Read FILE with ASN.1 definitions and generate\n\
+a C array that is used with libtasn1 functions.\n\
+\n");
+ printf ("\
+Mandatory arguments to long options are mandatory for short options too.\n\
+ -c, --check checks the syntax only\n\
+ -o, --output FILE output file\n\
+ -n, --name NAME array name\n\
+ -h, --help display this help and exit\n\
+ -v, --version output version information and exit\n");
+ emit_bug_reporting_address ();
+ }
+ exit (status);
+}
+
int
main (int argc, char *argv[])
{
printf ("\n");
break;
case 'h': /* HELP */
- printf ("%s\n", help_man);
-
free (outputFileName);
free (vectorName);
- exit (0);
+ usage (EXIT_SUCCESS);
break;
case 'v': /* VERSION */
version_etc (stdout, program_name, PACKAGE, VERSION,
fprintf (stderr,
"asn1Parser: option '%s' not recognized or without argument.\n\n",
argv[optind - 1]);
- printf ("%s\n", help_man);
-
free (outputFileName);
free (vectorName);
- exit (1);
+ usage (EXIT_FAILURE);
break;
default:
fprintf (stderr,
if (optind == argc)
{
- fprintf (stderr, "asn1Parser: input file name missing.\n\n");
- printf ("%s\n", help_man);
-
free (outputFileName);
free (vectorName);
- exit (1);
+ usage (EXIT_SUCCESS);
}
else
{