OSDN Git Service

Rationalise implementation and usage of --all-related option.
[mingw/mingw-get.git] / src / clistub.c
index 38afe6a..6d5ff62 100644 (file)
@@ -4,7 +4,7 @@
  * $Id$
  *
  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
- * Copyright (C) 2009, 2010, 2011, MinGW Project
+ * Copyright (C) 2009, 2010, 2011, 2012, MinGW Project
  *
  *
  * Initiation stub for command line invocation of mingw-get
@@ -169,31 +169,69 @@ static const char *help_text =
 "  mingw-get [OPTIONS] {show | list} [package-spec ...]\n\n"
 
 "Options:\n"
-"  --help, -h      Show this help text\n"
-"  --version, -V   Show version and licence information\n"
-"  --verbose, -v   Increase verbosity of diagnostic or\n"
-"                  progress reporting output; repeat up\n"
-"                  to three times for maximum verbosity\n"
-"  --verbose=N     Set verbosity level to N; (0 <= N <= 3)\n"
+"  --help, -h        Show this help text\n"
+"\n"
+"  --version, -V     Show version and licence information\n"
+"\n"
+"  --verbose, -v     Increase verbosity of diagnostic or\n"
+"                    progress reporting output; repeat up\n"
+"                    to three times for maximum verbosity\n"
+"  --verbose=N       Set verbosity level to N; (0 <= N <= 3)\n"
+"\n"
 
 /* The "--trace" option is available only when dynamic tracing
  * debugging support is compiled in; don't advertise it otherwise.
  */
 #if DEBUG_ENABLED( DEBUG_TRACE_DYNAMIC )
-"  --trace=N       Enable tracing feature N; (debugging aid)\n"
+"  --trace=N         Enable tracing feature N; (debugging aid)\n"
+"\n"
 #endif
+
+/* The following are always available...
+ */
+"  --reinstall       When performing an install or upgrade\n"
+"                    operation, reinstall any named package\n"
+"                    for which the most recent release is\n"
+"                    already installed\n"
+"\n"
+"  --recursive       Extend the scope of \"install --reinstall\"\n"
+"                    or of \"upgrade\", such that the operation\n"
+"                    is applied recursively to all prerequisites\n"
+"                    of all packages named on the command line\n"
+"\n"
+"  --download-only   Download the package archive files which\n"
+"                    would be required to complete the specified\n"
+"                    install, upgrade, or source operation, but\n"
+"                    do not unpack them, or otherwise proceed\n"
+"                    to complete the operation\n"
+"\n"
+"  --print-uris      Display the repository URIs from which\n"
+"                    package archive files would be retrieved\n"
+"                    prior to performing the specified install,\n"
+"                    upgrade, or source operation, but do not\n"
+"                    download any package file, or otherwise\n"
+"                    proceed with the operation\n"
+"\n"
+"  --all-related     When performing source or licence operations,\n"
+"                    causes mingw-get to retrieve, and optionally to\n"
+"                    unpack the source or licence archives for all\n"
+"                    runtime prerequisites of, and in addition to,\n"
+"                    the nominated package\n"
 "\n"
 "Actions:\n"
-"  update          Update local copy of repository catalogues\n"
-"  list, show      List and show details of available packages\n"
-"  install         Install new packages\n"
-"  upgrade         Upgrade previously installed packages\n"
-"  remove          Remove previously installed packages\n\n"
+"  update            Update local copy of repository catalogues\n"
+"  list, show        List and show details of available packages\n"
+"  source            Download and optionally unpack package sources\n"
+"  licence           Download and optionally unpack licence packages,\n"
+"                    handling them as if they are source packages\n"
+"  install           Install new packages\n"
+"  upgrade           Upgrade previously installed packages\n"
+"  remove            Remove previously installed packages\n\n"
 
 "Package Specifications:\n"
 "  [subsystem-]name[-component]:\n"
-"  msys-bash-doc   The 'doc' component of the bash package for MSYS\n"
-"  mingw32-gdb     All components of the gdb package for MinGW\n\n"
+"  msys-bash-doc     The 'doc' component of the bash package for MSYS\n"
+"  mingw32-gdb       All components of the gdb package for MinGW\n\n"
 
 "Use 'mingw-get list' to identify possible package names\n"
 "and the components associated with each.\n\n";
@@ -355,28 +393,25 @@ int main( int argc, char **argv )
     int optref;
     struct option options[] =
     {
-      /* FIXME: There is a bug in MinGW's library implementation of the
-       * getopt_long_only() function, which prevents it from correctly
-       * identifying "-v" when intended as a short form option, in the
-       * presence of "-verbose" vs. "-version" ambiguity.
-       *
-       * Until this bug has been fixed, we must explicitly declare "-v"
-       * both here, as a long form option, and as a short form option in
-       * the subsequent getopts_long_only() function call.
-       *
-       * Option Name      Argument Category    Store To   Return Value
-       * --------------   ------------------   --------   --------------
+      /* Option Name      Argument Category    Store To   Return Value
+       * --------------   ------------------   --------   ------------------
        */
-      { "v",              no_argument,         NULL,      'v'            },
-      { "version",        no_argument,         NULL,      'V'            },
-      { "help",           no_argument,         NULL,      'h'            },
-      { "verbose",        optional_argument,   NULL,      OPTION_VERBOSE },
+      { "version",        no_argument,         NULL,      'V'                },
+      { "help",           no_argument,         NULL,      'h'                },
+      { "verbose",        optional_argument,   NULL,      OPTION_VERBOSE     },
+
+      { "recursive",      no_argument,         &optref,   OPTION_RECURSIVE   },
+      { "reinstall",      no_argument,         &optref,   OPTION_REINSTALL   },
+      { "download-only",  no_argument,         &optref,   OPTION_DNLOAD_ONLY },
+      { "print-uris",     no_argument,         &optref,   OPTION_PRINT_URIS  },
+
+      { "all-related",    no_argument,         &optref,   OPTION_ALL_RELATED },
 
 #     if DEBUG_ENABLED( DEBUG_TRACE_DYNAMIC )
        /* The "--trace" option is supported only when dynamic tracing
         * debugging support has been compiled in.
         */
-      { "trace",          required_argument,   &optref,   OPTION_TRACE   },
+      { "trace",          required_argument,   &optref,   OPTION_TRACE       },
 #     endif
 
       /* This list must be terminated by a null definition...
@@ -434,20 +469,52 @@ int main( int argc, char **argv )
            ++parsed_options.flags[OPTION_FLAGS].numeric;
          break;
 
-       case 0:
+       case OPTION_GENERIC:
          switch( optref & OPTION_STORAGE_CLASS )
          {
+           /* This represents a generic option specification,
+            * allowing for storage of a option argument of the
+            * specified class into a specified option slot...
+            */
+           unsigned shift;
+
            case OPTION_STORE_STRING:
+             /* This is a simple store of a option argument
+              * which represents a character string.
+              */
              parsed_options.flags[optref & 0xfff].string = optarg;
              break;
 
            case OPTION_STORE_NUMBER:
+             /* This is also a simple store of the argument value,
+              * in this case interpreted as a number.
+              */
              parsed_options.flags[optref & 0xfff].numeric = xatoi( optarg );
              break;
 
            case OPTION_MERGE_NUMBER:
+             /* In this case, we combine the value of the argument,
+              * again interpreted as a number, with the original value
+              * stored in the option slot, forming the bitwise logical
+              * .OR. of the pair of values.
+              */
              parsed_options.flags[optref & 0xfff].numeric |= xatoi( optarg );
              break;
+
+           default:
+             /* This is a mask and store operation for a specified
+              * bit-field within the first pair of flags slots; in
+              * this case, the optref value itself specifies a 12-bit
+              * value, a 12-bit combining mask, and an alignment shift
+              * count between 0 and 52, in 4-bit increments.
+              */
+             if( (shift = (optref & OPTION_SHIFT_MASK) >> 22) < 53 )
+             {
+               uint64_t value = optref & 0xfff;
+               uint64_t mask = (optref & 0xfff000) >> 12;
+               *(uint64_t *)(parsed_options.flags) &= ~(mask << shift);
+               *(uint64_t *)(parsed_options.flags) |= value << shift;
+             }
          }
          break;