The MinGW.org Installation Manager Tool
修訂 | f3a84d2203e0d164fe3148753c487420a15d7722 (tree) |
---|---|
時間 | 2020-06-22 19:44:57 |
作者 | Keith Marshall <keith@user...> |
Commiter | Keith Marshall |
Support options interpretation from an unborn options object.
@@ -1,3 +1,18 @@ | ||
1 | +2020-06-22 Keith Marshall <keith@users.osdn.me> | |
2 | + | |
3 | + Support options interpretation from an unborn options object. | |
4 | + | |
5 | + * src/pkgopts.h (pkgOpts::Test, pkgOpts::IsSet, pkgOpts::GetValue) | |
6 | + (pkgOpts::GetString, pkgOpts::SetFlags): Delegate then to static class | |
7 | + methods, with inline wrappers passing "this" pointer explicitly. | |
8 | + | |
9 | + * src/pkgopts.cpp (pkgOpts::Test, pkgOpts::IsSet, pkgOpts::GetValue) | |
10 | + (pkgOpts::GetString, pkgOpts::SetFlags): Implement the static methods. | |
11 | + (pkgPreferenceEvaluator::PresetScriptHook) [! pkgOptions()]: Do not | |
12 | + evaluate pkgOptions()->IsSet(); assume that it would implicitly return | |
13 | + false, thus suppressing all dependent processing, including subsequent | |
14 | + evaluation of pkgOptions()->GetString(). | |
15 | + | |
1 | 16 | 2020-06-21 Keith Marshall <keith@users.osdn.me> |
2 | 17 | |
3 | 18 | Declare functions as void when return value is immaterial. |
@@ -3,8 +3,8 @@ | ||
3 | 3 | * |
4 | 4 | * $Id$ |
5 | 5 | * |
6 | - * Written by Keith Marshall <keithmarshall@users.sourceforge.net> | |
7 | - * Copyright (C) 2012, 2013, MinGW.org Project | |
6 | + * Written by Keith Marshall <keith@users.osdn.me> | |
7 | + * Copyright (C) 2012, 2013, 2020, MinGW.org Project | |
8 | 8 | * |
9 | 9 | * |
10 | 10 | * Implementation of XML interpreter for configuation of preferences. |
@@ -231,7 +231,8 @@ void pkgPreferenceEvaluator::PresetScriptHook( int index, const char *key, ... ) | ||
231 | 231 | * and initialise associated environment variable hooks, such |
232 | 232 | * that they override XML preference settings. |
233 | 233 | */ |
234 | - if( pkgOptions()->IsSet( index ) && (key != NULL) && (*key != '\0') ) | |
234 | + pkgOpts *options = pkgOptions(); | |
235 | + if( options && options->IsSet( index ) && (key != NULL) && (*key != '\0') ) | |
235 | 236 | { |
236 | 237 | /* The indexed command line option has been specified, and |
237 | 238 | * it is associated with a viable environment variable name; |
@@ -241,7 +242,7 @@ void pkgPreferenceEvaluator::PresetScriptHook( int index, const char *key, ... ) | ||
241 | 242 | va_list argv; |
242 | 243 | va_start( argv, key ); |
243 | 244 | const char *value = va_arg( argv, const char * ); |
244 | - const char *preset = pkgOptions()->GetString( index ); | |
245 | + const char *preset = options->GetString( index ); | |
245 | 246 | if( (value = SetOptions( SetName( value ), argv, preset )) != NULL ) |
246 | 247 | { |
247 | 248 | /* ...initialise the environment variable accordingly, |
@@ -378,4 +379,51 @@ void pkgXmlDocument::EstablishPreferences( const char *client ) | ||
378 | 379 | } |
379 | 380 | } |
380 | 381 | |
382 | +unsigned pkgOpts::IsSet( pkgOpts *ref, int index ) | |
383 | +{ | |
384 | + return ref | |
385 | + ? ref->flags[OPTION_ASSIGNED_FLAGS].numeric & OPTION_ASSIGNED(index) | |
386 | + : 0; | |
387 | +} | |
388 | + | |
389 | +unsigned pkgOpts::Test( pkgOpts *ref, unsigned mask, int index ) | |
390 | +{ | |
391 | + /* Test the state of specified bits within | |
392 | + * a bit-mapped numeric data (flags) entry. | |
393 | + */ | |
394 | + return ref ? ref->flags[index].numeric & mask : 0; | |
395 | +} | |
396 | + | |
397 | +unsigned pkgOpts::GetValue( pkgOpts *ref, int index ) | |
398 | +{ | |
399 | + /* Retrieve the value of a numeric data entry. | |
400 | + */ | |
401 | + return ref ? ref->flags[index & 0xFFF].numeric : 0; | |
402 | +} | |
403 | + | |
404 | +const char *pkgOpts::GetString( pkgOpts *ref, int index ) | |
405 | +{ | |
406 | + /* Retrieve a pointer to a string data entry. | |
407 | + */ | |
408 | + return ref ? ref->flags[index & 0xFFF].string : NULL; | |
409 | +} | |
410 | + | |
411 | +void pkgOpts::SetFlags( pkgOpts *ref, unsigned value ) | |
412 | +{ | |
413 | + /* This is a mask and store operation, to set a specified | |
414 | + * bit-field within the first pair of flags slots; it mimics | |
415 | + * the options setting operation performed in the CLI start-up | |
416 | + * code, where the input value represents a 12-bit flag code, | |
417 | + * packaged with a 12-bit combining mask, and an alignment | |
418 | + * shift count between 0 and 52, in 4-bit increments. | |
419 | + */ | |
420 | + if( ref ) | |
421 | + { unsigned shift; | |
422 | + if( (shift = (value & OPTION_SHIFT_MASK) >> 22) < 53 ) | |
423 | + { *(uint64_t *)(ref->flags) &= ~((uint64_t)((value & 0xfff000) >> 12) << shift); | |
424 | + *(uint64_t *)(ref->flags) |= (uint64_t)(value) << shift; | |
425 | + } | |
426 | + } | |
427 | +} | |
428 | + | |
381 | 429 | /* $RCSfile$: end of file */ |
@@ -1,11 +1,10 @@ | ||
1 | -#ifndef PKGOPTS_H | |
2 | 1 | /* |
3 | 2 | * pkgopts.h |
4 | 3 | * |
5 | 4 | * $Id$ |
6 | 5 | * |
7 | - * Written by Keith Marshall <keithmarshall@users.sourceforge.net> | |
8 | - * Copyright (C) 2011, 2012, MinGW Project | |
6 | + * Written by Keith Marshall <keith@users.osdn.me> | |
7 | + * Copyright (C) 2011, 2012, 2020, MinGW Project | |
9 | 8 | * |
10 | 9 | * |
11 | 10 | * Public declarations of the data structures, values and functions |
@@ -26,6 +25,7 @@ | ||
26 | 25 | * arising from the use of this software. |
27 | 26 | * |
28 | 27 | */ |
28 | +#ifndef PKGOPTS_H | |
29 | 29 | #define PKGOPTS_H 1 |
30 | 30 | |
31 | 31 | #include <stdint.h> /* required for uint64_t typedef */ |
@@ -126,48 +126,20 @@ class pkgOpts : protected pkgopts | ||
126 | 126 | /* A derived "convenience" class, associating a collection |
127 | 127 | * of utility methods with the pkgopts structure. |
128 | 128 | */ |
129 | + private: | |
130 | + static unsigned IsSet( pkgOpts *, int ); | |
131 | + static unsigned GetValue( pkgOpts *, int ); | |
132 | + static const char *GetString( pkgOpts *, int ); | |
133 | + static unsigned Test( pkgOpts *, unsigned, int ); | |
134 | + static void SetFlags( pkgOpts *, unsigned ); | |
135 | + | |
129 | 136 | public: |
130 | - inline unsigned IsSet( int index ) | |
131 | - { | |
132 | - return this | |
133 | - ? flags[OPTION_ASSIGNED_FLAGS].numeric & OPTION_ASSIGNED(index) | |
134 | - : 0; | |
135 | - } | |
136 | - inline unsigned GetValue( int index ) | |
137 | - { | |
138 | - /* Retrieve the value of a numeric data entry. | |
139 | - */ | |
140 | - return this ? (flags[index & 0xFFF].numeric) : 0; | |
141 | - } | |
142 | - inline const char *GetString( int index ) | |
143 | - { | |
144 | - /* Retrieve a pointer to a string data entry. | |
145 | - */ | |
146 | - return this ? (flags[index & 0xFFF].string) : NULL; | |
147 | - } | |
137 | + inline unsigned IsSet( int index ){ return IsSet( this, index ); } | |
138 | + inline unsigned GetValue( int index ){ return GetValue( this, index ); } | |
139 | + inline const char *GetString( int index ){ return GetString( this, index ); } | |
140 | + inline void SetFlags( unsigned value ){ SetFlags( this, value ); } | |
148 | 141 | inline unsigned Test( unsigned mask, int index = OPTION_FLAGS ) |
149 | - { | |
150 | - /* Test the state of specified bits within | |
151 | - * a bit-mapped numeric data (flags) entry. | |
152 | - */ | |
153 | - return this ? (flags[index].numeric & mask) : 0; | |
154 | - } | |
155 | - inline void SetFlags( unsigned value ) | |
156 | - { | |
157 | - /* This is a mask and store operation, to set a specified | |
158 | - * bit-field within the first pair of flags slots; it mimics | |
159 | - * the options setting operation performed in the CLI start-up | |
160 | - * code, where the input value represents a 12-bit flag code, | |
161 | - * packaged with a 12-bit combining mask, and an alignment | |
162 | - * shift count between 0 and 52, in 4-bit increments. | |
163 | - */ | |
164 | - unsigned shift; | |
165 | - if( (shift = (value & OPTION_SHIFT_MASK) >> 22) < 53 ) | |
166 | - { | |
167 | - *(uint64_t *)(flags) &= ~((uint64_t)((value & 0xfff000) >> 12) << shift); | |
168 | - *(uint64_t *)(flags) |= (uint64_t)(value) << shift; | |
169 | - } | |
170 | - } | |
142 | + { return Test( this, mask, index ); } | |
171 | 143 | }; |
172 | 144 | |
173 | 145 | /* Access modes for the following global options accessor function. |