diff options
author | Simon Josefsson <simon@josefsson.org> | 2009-06-08 14:14:37 +0200 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2009-06-08 14:14:37 +0200 |
commit | 9108b01369dd755ba6a1606bfeb408507a5b6d95 (patch) | |
tree | 8d36459d56bbdcd14dbedf49956a816bfe1dd3d8 /src | |
parent | 39cde3c5c692a7593e7a54f741833271c10d3e77 (diff) | |
download | libtasn1-9108b01369dd755ba6a1606bfeb408507a5b6d95.tar.gz |
Improve --help and --version outputs.
Diffstat (limited to 'src')
-rw-r--r-- | src/asn1Coding.c | 90 | ||||
-rw-r--r-- | src/asn1Decoding.c | 91 | ||||
-rw-r--r-- | src/asn1Parser.c | 73 |
3 files changed, 115 insertions, 139 deletions
diff --git a/src/asn1Coding.c b/src/asn1Coding.c index 3012927..476f374 100644 --- a/src/asn1Coding.c +++ b/src/asn1Coding.c @@ -1,4 +1,4 @@ -/* +/* 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 * @@ -19,13 +19,6 @@ * */ - -/*****************************************************/ -/* File: asn1Coding.c */ -/* Description: program to generate a DER coding */ -/* of an ASN1 definition. */ -/*****************************************************/ - #include <config.h> #include <stdio.h> @@ -39,17 +32,38 @@ #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 @@ -74,8 +88,6 @@ readAssignment (FILE * file, char *varName, char *value) return ASSIGNMENT_SUCCESS; } - - static void createFileName (char *inputFileName, char **outputFileName) { @@ -108,11 +120,6 @@ createFileName (char *inputFileName, char **outputFileName) return; } - -/********************************************************/ -/* Function : main */ -/* Description: */ -/********************************************************/ int main (int argc, char *argv[]) { @@ -157,10 +164,8 @@ 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, @@ -176,13 +181,11 @@ main (int argc, char *argv[]) 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, @@ -191,26 +194,11 @@ main (int argc, char *argv[]) } } - 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); diff --git a/src/asn1Decoding.c b/src/asn1Decoding.c index 3fd9c67..93c61f5 100644 --- a/src/asn1Decoding.c +++ b/src/asn1Decoding.c @@ -1,4 +1,4 @@ -/* +/* 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 * @@ -19,13 +19,6 @@ * */ - -/*****************************************************/ -/* File: asn1Deoding.c */ -/* Description: program to generate an ASN1 type from*/ -/* a DER coding. */ -/*****************************************************/ - #include <config.h> #include <stdio.h> @@ -40,20 +33,37 @@ #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[]) { @@ -93,8 +103,7 @@ 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, @@ -108,9 +117,7 @@ main (int argc, char *argv[]) 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, @@ -119,33 +126,11 @@ main (int argc, char *argv[]) } } - 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); diff --git a/src/asn1Parser.c b/src/asn1Parser.c index 8a09209..8152617 100644 --- a/src/asn1Parser.c +++ b/src/asn1Parser.c @@ -1,4 +1,4 @@ -/* +/* asn1Parser.c -- program to parse a file with ASN1 definitions * Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation * Copyright (C) 2002 Fabio Fiorina * @@ -19,13 +19,6 @@ * */ - -/*****************************************************/ -/* File: asn1Parser.c */ -/* Description: program to parse a file with ASN1 */ -/* definitions. */ -/*****************************************************/ - #include <config.h> #include <stdio.h> @@ -39,23 +32,40 @@ #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[]) { @@ -99,11 +109,9 @@ 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, @@ -127,11 +135,9 @@ main (int argc, char *argv[]) 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, @@ -143,12 +149,9 @@ main (int argc, char *argv[]) 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 { |