Improve --help output. Assume getopt_long, since gnulib provides it.
authorSimon Josefsson <simon@josefsson.org>
Thu, 19 Oct 2006 14:46:24 +0000 (14:46 +0000)
committerSimon Josefsson <simon@josefsson.org>
Thu, 19 Oct 2006 14:46:24 +0000 (14:46 +0000)
src/asn1Coding.c
src/asn1Decoding.c
src/asn1Parser.c

index 80d4525..91f5325 100644 (file)
 
 #include <stdio.h>
 #include <string.h>
-#include <libtasn1.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <getopt.h>
+
+#include <libtasn1.h>
 
 #include <progname.h>
 #include <version-etc.h>
 
-#ifdef HAVE_GETOPT_H
-  #include <getopt.h>
-#endif
-
-char help_man[] =
-  "Usage: asn1Coding [options] <file1> <file2>\n"
+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"
-  "asn1Coding generates a DER encoding from FILE1\n"
-  "with ASN1 definitions and FILE2 with assignments.\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"
-#ifdef HAVE_GETOPT_LONG
-  "Operation modes:\n"
-  "  -h, --help    shows this message and exit.\n"
-  "  -v, --version shows version information and exit.\n"
-  "  -c, --check   checks the syntax only.\n"
-  "\n"
-  "Output:\n"
-  "  -o <file>, --output <file>  output file.\n"
-#else
-  "Operation modes:\n"
-  "  -h    shows this message and exit.\n"
-  "  -v    shows version information and exit.\n"
-  "  -c    checks the syntax only.\n"
-  "\n"
-  "Output:\n"
-  "  -o <file>  output file.\n"
-#endif
   "Report bugs to <" PACKAGE_BUGREPORT ">.";
 
 #define ASSIGNMENT_SUCCESS 1
@@ -125,8 +111,6 @@ void createFileName(char *inputFileName, char **outputFileName)
 int
 main(int argc,char *argv[])
 {
-
-#ifdef HAVE_GETOPT_LONG
   static struct option long_options[] =
   {
     {"help",    no_argument,       0, 'h'},
@@ -136,8 +120,6 @@ main(int argc,char *argv[])
     {0, 0, 0, 0}
   };
   int option_index=0;
-#endif
-
  int option_result;
  char *outputFileName=NULL;
  char *inputFileAsnName=NULL;
@@ -161,11 +143,7 @@ main(int argc,char *argv[])
 
  while(1){
 
-#ifdef HAVE_GETOPT_LONG
    option_result=getopt_long(argc,argv,"hvco:",long_options,&option_index);
-#else
-   option_result=getopt(argc,argv,"hvco:");
-#endif
 
    if(option_result == -1) break;
 
index c948f98..a3db3fe 100644 (file)
 
 #include <stdio.h>
 #include <string.h>
-#include <libtasn1.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <getopt.h>
+
+#include <libtasn1.h>
 
 #include <progname.h>
 #include <version-etc.h>
 
-#ifdef HAVE_GETOPT_H
-  #include <getopt.h>
-#endif
-
-char help_man[] =
-  "asn1Decoding generates an ASN1 type from FILE1\n"
-  "with ASN1 definitions and FILE2 with a DER encoding.\n"
+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"
-  "Usage: asn1Decoding [options] <file1> <file2> <type>\n"
-  " <file1> file with ASN1 definitions.\n"
-  " <file2> file with a DER coding.\n"
-  " <type>  ASN1 type name\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"
-#ifdef HAVE_GETOPT_LONG
-  "Operation modes:\n"
-  "  -h, --help    shows this message and exit.\n"
-  "  -v, --version shows version information and exit.\n"
-  "  -c, --check   checks the syntax only.\n"
-#else
-  "Operation modes:\n"
-  "  -h    shows this message and exit.\n"
-  "  -v    shows version information and exit.\n"
-  "  -c    checks the syntax only.\n"
-#endif
   "Report bugs to <" PACKAGE_BUGREPORT ">.";
 
 /********************************************************/
@@ -71,8 +58,6 @@ char help_man[] =
 int
 main(int argc,char *argv[])
 {
-
-#ifdef HAVE_GETOPT_LONG
   static struct option long_options[] =
   {
     {"help",    no_argument,       0, 'h'},
@@ -81,8 +66,6 @@ main(int argc,char *argv[])
     {0, 0, 0, 0}
   };
  int option_index = 0;
-#endif
-
  int option_result;
  char *inputFileAsnName=NULL;
  char *inputFileDerName=NULL; 
@@ -103,11 +86,7 @@ main(int argc,char *argv[])
 
  while(1){
 
-#ifdef HAVE_GETOPT_LONG
    option_result=getopt_long(argc,argv,"hvc",long_options,&option_index);
-#else
-   option_result=getopt(argc,argv,"hvc");
-#endif
 
    if(option_result == -1) break;
 
index 6d111f0..ce8d609 100644 (file)
 
 #include <stdio.h>
 #include <string.h>
-#include <libtasn1.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <getopt.h>
+
+#include <libtasn1.h>
 
 #include <progname.h>
 #include <version-etc.h>
 
-#ifdef HAVE_GETOPT_H
-  #include <getopt.h>
-#endif
-
-char help_man[] =
-  "Usage: asn1Parser [options] FILE\n"
-  "asn1Parser reads FILE with ASN1 definitions and\n"
-  "generates a C array to use with libtasn1 functions.\n"
+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"
-#ifdef HAVE_GETOPT_LONG
-  "Operation modes:\n"
-  "  -h, --help    shows this message and exit\n"
-  "  -v, --version shows version information and exit.\n"
-  "  -c, --check   checks the syntax only.\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"
-  "Output:\n"
-  "  -o <file>, --output <file>  output file\n"
-  "  -n <name>, --name <name>    array name\n"
-#else
-  "Operation modes:\n"
-  "  -h    shows this message and exit\n"
-  "  -v    shows version information and exit.\n"
-  "  -c    checks the syntax only.\n"
-  "\n"
-  "Output:\n"
-  "  -o <file>  output file\n"
-  "  -n <name>  array name\n"
-#endif
   "Report bugs to <" PACKAGE_BUGREPORT ">.";
 
 /********************************************************/
@@ -75,8 +61,6 @@ char help_man[] =
 int
 main(int argc,char *argv[])
 {
-
-#ifdef HAVE_GETOPT_LONG
   static struct option long_options[] =
   {
     {"help",    no_argument,       0, 'h'},
@@ -87,8 +71,6 @@ main(int argc,char *argv[])
     {0, 0, 0, 0}
   };
   int option_index = 0;
-#endif
-
  int option_result;
  char *outputFileName=NULL;
  char *inputFileName=NULL;
@@ -104,21 +86,15 @@ main(int argc,char *argv[])
 
  while(1){
 
-#ifdef HAVE_GETOPT_LONG
    option_result=getopt_long(argc,argv,"hvco:n:",long_options,&option_index);
-#else
-   option_result=getopt(argc,argv,"hvco:n:");
-#endif
 
    if(option_result == -1) break;
 
    switch(option_result){
    case 0:
-#ifdef HAVE_GETOPT_LONG
      printf("option %s",long_options[option_index].name);
      if(optarg) printf(" with arg %s",optarg);
      printf("\n");
-#endif
      break;
    case 'h':  /* HELP */
      printf("%s\n",help_man);