+2011-05-29 Keith Marshall <keithmarshall@users.sourceforge.net>
+
+ Implement user selection of traceable features at run-time.
+
+ * src.pkgopts.h (OPTION_VERBOSE_MAX): New macro; define it.
+
+ * src/debug.h (DEBUG_ENABLED): New macro; define it.
+ (DEBUG_REQUEST, DEBUG_REQUEST_FLAGS, DEBUG_TRACE_DYNAMIC): Likewise.
+
+ * src/clistub.c (main) [--trace]: Don't make it available unless...
+ [DEBUG_ENABLED(DEBUG_TRACE_DYNAMIC)]: ...this is set (at compile-time).
+ [--verbose]: Limit to OPTION_VERBOSE_MAX, using...
+ (atmost): ...this new macro; define it.
+ (options): Declare `-v' as both long and short form, pending bug fix
+ in MinGW's getopt_long_only() implementation.
+
+ * src/pkginet.cpp (pkgInternetAgent::OpenURL): Use DEBUG_REQUEST.
+ (pkgInternetLzmaStreamingAgent::TransferData): Likewise.
+ (pkgInternetStreamingAgent::TransferData): Likewise.
+ (pkgInternetStreamingAgent::Get): Likewise.
+
+ * src/pkgunst.cpp (pkgActionItem::SetAuthorities): Use DEBUG_REQUEST.
+ (pkg_rmdir, pkg_unlink): Likewise.
+
+ * src/sysroot.cpp (pkgXmlDocument::LoadSystemMap): Use DEBUG_REQUEST.
+
2011-05-21 Keith Marshall <keithmarshall@users.sourceforge.net>
Implement protocol for processing global program options.
#define _WIN32_WINNT 0x500
#define WIN32_LEAN_AND_MEAN
+#include "debug.h"
+
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
static const char *help_text =
"Manage MinGW and MSYS installations (command line user interface).\n\n"
+
"Usage:\n"
" mingw-get [OPTIONS] ACTION [package-spec ...]\n\n"
+
" mingw-get update\n"
" mingw-get [OPTIONS] {install | upgrade | remove} package-spec ...\n"
" 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"
" progress reporting output; repeat up\n"
" to three times for maximum verbosity\n"
" --verbose=N Set verbosity level to N; (0 <= N <= 3)\n"
-#if DEBUGLEVEL & DEBUG_TRACE_DYNAMIC
+
+/* 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"
#endif
"\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"
+
"Use 'mingw-get list' to identify possible package names\n"
"and the components associated with each.\n\n";
return result;
}
-#define minval( a, b ) ((a) < (b)) ? (a) : (b)
+#define atmost( lim, val ) ((lim) < (val)) ? (lim) : (val)
int main( int argc, char **argv )
{
int optref;
struct option options[] =
{
- /* Option Name Argument Category Store To Return Value
+ /* 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
* -------------- ------------------ -------- --------------
*/
{ "v", no_argument, NULL, 'v' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
- { "trace", required_argument, &optref, OPTION_TRACE },
{ "verbose", optional_argument, NULL, OPTION_VERBOSE },
+# 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 },
+# endif
+
/* This list must be terminated by a null definition...
*/
{ NULL, 0, NULL, 0 }
*/
parsed_options.flags[opt].numeric = 0;
- while( (opt = getopt_long_only( argc, argv, "Vh", options, &offset )) != -1 )
+ while( (opt = getopt_long_only( argc, argv, "vVh", options, &offset )) != -1 )
/*
* Parse any user specified options from the command line...
*/
{
/* This is the case where an explicit level was specified...
*/
- unsigned verbosity = xatoi( optarg );
- parsed_options.flags[OPTION_FLAGS].numeric &= ~OPTION_VERBOSE;
- parsed_options.flags[OPTION_FLAGS].numeric |= minval( verbosity, 3 );
+ parsed_options.flags[OPTION_FLAGS].numeric =
+ (parsed_options.flags[OPTION_FLAGS].numeric & ~OPTION_VERBOSE)
+ | atmost( OPTION_VERBOSE_MAX, xatoi( optarg ));
break;
}
* to selectively enable compilation of (any specific class of)
* debug specific code.
*/
+# define DEBUG_ENABLED(FEATURE) (DEBUGLEVEL & (FEATURE))
+
+# define DEBUG_TRACE_DYNAMIC 0x0001
+
+# if DEBUG_ENABLED( DEBUG_TRACE_DYNAMIC )
+ /* When compiled with dynamic tracing enabled, we allow the user
+ * to choose which features are to be traced, by specification of
+ * the "--trace=FEATURES" command line option; however the features
+ * which may be selected are restricted to an explicit subset which
+ * has been specified at compile time.
+ */
+# include "pkgopts.h"
+
+# define DEBUG_REQUEST_FLAGS pkgOptions()->GetValue( OPTION_DEBUGLEVEL )
+# define DEBUG_REQUEST(OPTION) (DEBUG_ENABLED( OPTION ) & DEBUG_REQUEST_FLAGS)
+
+# else /* ! DEBUG_TRACE_DYNAMIC */
+ /* Without dynamic tracing enabled, only those features selected
+ * at compile time may be traced, and all unconditionally.
+ */
+# define DEBUG_REQUEST(OPTION) (DEBUGLEVEL & (OPTION))
+# endif
+
# define DEBUG_TRACE_INIT 0x0010
# define DEBUG_TRACE_TRANSACTIONS 0x0020
# define DEBUG_SUPPRESS_INSTALLATION 0x0040
*/
dmh_notify( DMH_ERROR, "%s:cannot open URL\n", URL );
- else DEBUG_INVOKE_IF( DEBUGLEVEL & DEBUG_TRACE_INTERNET_REQUESTS,
+ else DEBUG_INVOKE_IF( DEBUG_REQUEST( DEBUG_TRACE_INTERNET_REQUESTS ),
dmh_printf( "%s\nConnecting ... failed(status=%u); retrying...\n",
- URL, GetLastError() )
+ URL, GetLastError() )
);
}
else
/* Other failure modes may not be so readily recoverable;
* with little hope of success, retry anyway.
*/
- DEBUG_INVOKE_IF( DEBUGLEVEL & DEBUG_TRACE_INTERNET_REQUESTS,
+ DEBUG_INVOKE_IF( DEBUG_REQUEST( DEBUG_TRACE_INTERNET_REQUESTS ),
dmh_printf( "%s: abnormal request status = %u; retrying...\n",
URL, ResourceStatus
- )
- );
+ ));
if( HttpSendRequest( ResourceHandle, NULL, 0, 0, 0 ) )
ResourceStatus = QueryStatus( ResourceHandle );
}
} while( dl_status && (count > 0) );
DEBUG_INVOKE_IF(
- (DEBUGLEVEL & DEBUG_TRACE_INTERNET_REQUESTS) && (dl_status == 0),
+ DEBUG_REQUEST( DEBUG_TRACE_INTERNET_REQUESTS ) && (dl_status == 0),
dmh_printf( "\nInternetReadFile:download error:%d\n", GetLastError() )
);
return dl_status;
dl_meter = &download_meter;
dl_status = TransferData( fd );
}
- else DEBUG_INVOKE_IF( DEBUGLEVEL & DEBUG_TRACE_INTERNET_REQUESTS,
+ else DEBUG_INVOKE_IF( DEBUG_REQUEST( DEBUG_TRACE_INTERNET_REQUESTS ),
dmh_printf( "OpenURL:error:%d\n", GetLastError() )
);
} while( dl_status && (count > 0) );
DEBUG_INVOKE_IF(
- (DEBUGLEVEL & DEBUG_TRACE_INTERNET_REQUESTS) && (dl_status == 0),
+ DEBUG_REQUEST( DEBUG_TRACE_INTERNET_REQUESTS ) && (dl_status == 0),
dmh_printf( "\nInternetReadFile:download error:%d\n", GetLastError() )
);
return dl_status;
/* Options controlled by bit-mapped flags within OPTION_FLAGS...
*/
#define OPTION_VERBOSE (0x00000003)
+#define OPTION_VERBOSE_MAX (0x00000003)
#if __cplusplus
/*
* package which has been identified as "installed"...
*/
const char *tarname = ref->GetPropVal( tarname_key, value_unknown );
- DEBUG_INVOKE_IF( DEBUGLEVEL & DEBUG_TRACE_INIT,
+ DEBUG_INVOKE_IF( DEBUG_REQUEST( DEBUG_TRACE_INIT ),
dmh_printf( "%s: selected for %s\n",
(tarname = ref->GetPropVal( tarname_key, value_unknown )),
(current->flags & ACTION_INSTALL) ? "upgrade" : "removal"
{
/* ...and then, having confirmed its validity...
*/
- DEBUG_INVOKE_IF( DEBUGLEVEL & DEBUG_TRACE_INIT,
+ DEBUG_INVOKE_IF( DEBUG_REQUEST( DEBUG_TRACE_INIT ),
dmh_printf( "%s: marked for %s\n",
ref->GetPropVal( tarname_key, value_unknown ),
(current->flags & ACTION_INSTALL) ? "upgrade" : "removal"
char fullpath[ mkpath( NULL, sysroot, pathname, NULL ) ];
mkpath( fullpath, sysroot, pathname, NULL );
- DEBUG_INVOKE_IF( DEBUGLEVEL & DEBUG_TRACE_TRANSACTIONS,
+ DEBUG_INVOKE_IF( DEBUG_REQUEST( DEBUG_TRACE_TRANSACTIONS ),
dmh_printf( " %s: rmdir\n", fullpath )
);
char filepath[ mkpath( NULL, sysroot, pathname, NULL ) ];
mkpath( filepath, sysroot, pathname, NULL );
- DEBUG_INVOKE_IF( DEBUGLEVEL & DEBUG_TRACE_TRANSACTIONS,
+ DEBUG_INVOKE_IF( DEBUG_REQUEST( DEBUG_TRACE_TRANSACTIONS ),
dmh_printf( " %s: unlink file\n", filepath )
);
* $Id$
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
- * Copyright (C) 2010, MinGW Project
+ * Copyright (C) 2010, 2011, MinGW Project
*
*
* Implementation of the system map loader, sysroot management and
/* This system map is a candidate for loading;
* process all of its subsystem specific sysroot declarations...
*/
-# if DEBUGLEVEL & DEBUG_TRACE_INIT
- fprintf( stderr, "Load system map: id = %s\n", id );
-# endif
+ DEBUG_INVOKE_IF( DEBUG_REQUEST( DEBUG_TRACE_INIT ),
+ dmh_printf( "Load system map: id = %s\n", id )
+ );
pkgXmlNode *subsystem = sysmap->FindFirstAssociate( sysroot_key );
while( subsystem != NULL )
{
&& ! samepath( path, sysroot->GetPropVal( pathname_key, NULL )) )
sysroot = sysroot->FindNextAssociate( sysroot_key );
-# if DEBUGLEVEL & DEBUG_TRACE_INIT
- fprintf( stderr, "Bind subsystem %s: sysroot = %s\n",
+ DEBUG_INVOKE_IF( DEBUG_REQUEST( DEBUG_TRACE_INIT ),
+ dmh_printf( "Bind subsystem %s: sysroot = %s\n",
subsystem->GetPropVal( subsystem_key, "<unknown>" ), path
- );
-# endif
+ ));
if( sysroot == NULL )
{