📄 pgpoptionlist.c
字号:
PGPUInt32 optionIndex;
if((sourceOptionList->flags & kPGPOptionListFlag_PersistentList)
!= 0)
{
/* Create a non-persistent copy of the source list */
sourceOptionList = pgpCopyOptionList(
sourceOptionList );
err = pgpGetOptionListError( sourceOptionList );
}
if( IsntPGPError( err ) )
{
for( optionIndex = 0;
optionIndex < sourceOptionList->numOptions;
++optionIndex )
{
PGPOption *curSourceOption;
curSourceOption = &sourceOptionList->options[optionIndex];
err = pgpAddOptionToPGPOptionList( destOptionList,
curSourceOption );
if( IsntPGPError( err ) )
{
/*
** We have "moved" the option to the destination list.
** At this point we need to clear the option in the
** source list so that allocated resources are not
** disposed when the list is freed. Those resources
** are now owned by the destination list.
*/
pgpClearMemory( curSourceOption,
sizeof(*curSourceOption));
}
else
{
break;
}
}
}
}
}
pgpFreeOptionListInternal( sourceOptionList, FALSE );
pgpSetOptionListError( destOptionList, err );
return( err );
}
/*____________________________________________________________________________
Compose a new option list which is built from one or more component lists.
The component lists are deleted.
____________________________________________________________________________*/
PGPError
pgpAppendOptionListArgs(
PGPOptionListRef optionList,
PGPOptionListRef firstOption,
va_list remainingOptions)
{
PGPError err;
PGPOptionListRef curOptionList;
/* Initialize err to the initial state of the list */
err = pgpGetOptionListError( optionList );
/* Always process all arguments even though the list may already be
in error. We do this because we may need to dispose of an input */
curOptionList = firstOption;
while( curOptionList != kPGPEndOfArgsOptionListRef )
{
if( curOptionList != kPGPNullOptionListRef )
{
pgpAssert( pgpOptionListIsValid( curOptionList ) );
if( pgpOptionListIsValid( curOptionList ) )
{
PGPBoolean freeCurOptionList = TRUE;
if( IsntPGPError( err ) )
{
err = pgpGetOptionListError( curOptionList );
if( IsntPGPError( err ) )
{
err = pgpMergeOptionLists(
curOptionList,
optionList );
freeCurOptionList = FALSE;
}
}
if( freeCurOptionList )
{
pgpFreeOptionListInternal( curOptionList, FALSE );
}
}
else if( IsntPGPError( err ) )
{
err = kPGPError_BadParams;
}
}
curOptionList = va_arg( remainingOptions, PGPOptionListRef );
}
pgpSetOptionListError( optionList, err );
return( err );
}
/*____________________________________________________________________________
Compose a new option list which is built from one or more component lists.
The component lists are deleted.
____________________________________________________________________________*/
PGPError
pgpFreeVarArgOptionList(
PGPOptionListRef firstOption,
va_list args)
{
PGPError err = kPGPError_NoErr;
PGPOptionListRef curOptionList;
/* Always process all arguments even though the list may already be
in error. We do this because we may need to dispose of an input */
curOptionList = firstOption;
while( curOptionList != kPGPEndOfArgsOptionListRef )
{
if( curOptionList != kPGPNullOptionListRef )
{
pgpAssert( pgpOptionListIsValid( curOptionList ) );
if( pgpOptionListIsValid( curOptionList ) )
{
pgpFreeOptionListInternal( curOptionList, FALSE );
}
else if( IsntPGPError( err ) )
{
if ( IsntPGPError( err ) )
err = kPGPError_BadParams;
}
}
curOptionList = va_arg( args, PGPOptionListRef );
}
return( err );
}
/*____________________________________________________________________________
Compose a new option list which is built from one or more component lists.
The component lists are deleted.
____________________________________________________________________________*/
PGPOptionListRef
pgpBuildOptionListArgs(
PGPContextRef context,
PGPBoolean createPersistentList,
PGPOptionListRef firstOption,
va_list remainingOptions)
{
PGPOptionListRef newOptionList;
/* Note that pgpNewOptionList can never return NULL */
newOptionList = pgpNewOptionList( context, createPersistentList );
pgpAppendOptionListArgs( newOptionList, firstOption, remainingOptions );
return( newOptionList );
}
/*____________________________________________________________________________
Find the first occurrence of an option in a list and return its value
and how many options exist of that type.
____________________________________________________________________________*/
PGPError
pgpGetIndexedOptionType(
PGPOptionListRef optionList,
PGPOptionType optionType,
PGPUInt32 searchIndex,
PGPBoolean markAsRecognized,
PGPOption *optionData,
PGPUInt32 *numFoundOptions)
{
PGPUInt32 optionIndex;
PGPError err;
PGPUInt32 foundOptions;
PGPOption *curOption;
if( IsntNull( numFoundOptions ) )
*numFoundOptions = 0;
PGPValidateParam( pgpOptionListIsValid( optionList ) );
foundOptions = 0;
err = kPGPError_OptionNotFound;
curOption = optionList->options;
for(optionIndex = 0; optionIndex < optionList->numOptions; optionIndex++)
{
if( curOption->type == optionType )
{
if( foundOptions == searchIndex )
{
if( IsntNull( optionData ) )
{
pgpAssertAddrValid( optionData, PGPOption );
if( markAsRecognized )
{
curOption->flags |= kPGPOptionFlag_Recognized;
}
*optionData = *curOption;
}
err = kPGPError_NoErr;
}
++foundOptions;
}
++curOption;
}
if( IsntNull( numFoundOptions ) )
{
pgpAssertAddrValid( numFoundOptions, PGPUInt32 );
*numFoundOptions = foundOptions;
}
return( err );
}
/*____________________________________________________________________________
Get the Nth option in a list and return its value. Returns
kPGPError_OptionNotFound if the index is out of range
____________________________________________________________________________*/
PGPError
pgpGetIndexedOption(
PGPOptionListRef optionList,
PGPUInt32 searchIndex,
PGPBoolean markAsRecognized,
PGPOption *optionData)
{
PGPError err = kPGPError_NoErr;
PGPValidateParam( pgpOptionListIsValid( optionList ) );
if( searchIndex < optionList->numOptions )
{
if( markAsRecognized )
{
optionList->options[searchIndex].flags |=
kPGPOptionFlag_Recognized;
}
*optionData = optionList->options[searchIndex];
}
else
{
err = kPGPError_OptionNotFound;
}
return( err );
}
/*____________________________________________________________________________
Test an option list and make sure all options are in the given set.
The option set is an array of option numbers. Returns kPGPError_BadParams
if an option is not in the set.
____________________________________________________________________________*/
PGPError
pgpCheckOptionsInSet(
PGPOptionListRef optionList,
PGPOptionType const *optionSet,
PGPUInt32 optionSetSize)
{
PGPUInt32 optionIndex;
PGPUInt32 setIndex;
PGPError err = kPGPError_NoErr;
PGPValidateParam( pgpOptionListIsValid( optionList ) );
for( optionIndex = 0; optionIndex < optionList->numOptions; optionIndex++)
{
PGPOptionType type;
type = optionList->options[optionIndex].type;
for( setIndex = 0; setIndex < optionSetSize; setIndex++ )
{
if (type == optionSet[setIndex])
break;
}
/* didn't find option in the list */
if( setIndex == optionSetSize )
{
pgpDebugFmtMsg(( pgpaFmtPrefix,
"Error: Illegal PGPO option #%ld",
(long)type ));
err = kPGPError_BadParams;
break;
}
}
return err;
}
PGPError
pgpAddJobOptionsArgs(
PGPJobRef job,
PGPOptionListRef firstOption,
va_list remainingOptions)
{
PGPError error;
PGPOptionListRef optionList;
pgpAssert( IsntNull( job ) );
optionList = pgpBuildOptionListArgs( job->context,
FALSE, firstOption, remainingOptions );
error = pgpGetOptionListError( optionList );
if( IsntPGPError( error ) )
{
job->newOptionList = optionList;
}
return( error );
}
PGPOptionListRef
pgpNewOneOptionList(
PGPContextRef context,
const PGPOption * option)
{
PGPOptionListRef optionList;
pgpAssertAddrValid( option, PGPOption );
optionList = pgpNewOptionList( context, FALSE );
if( IsntPGPError( pgpGetOptionListError( optionList ) ) )
{
(void) pgpAddOptionToPGPOptionList( optionList, option );
}
return( optionList );
}
/* Read an option, marking it read, and only allow one instance of it */
PGPError
pgpSearchOptionSingle(
PGPOptionListRef optionList,
PGPOptionType optionType,
PGPOption *optionData)
{
PGPUInt32 numFound;
PGPError err = kPGPError_NoErr;
pgpa( pgpaAddrValid( optionData, PGPOption ) );
optionData->type = kPGPOptionType_InvalidOption;
numFound = 0;
if( IsntNull( optionList ) ) {
if( IsPGPError( err = pgpGetIndexedOptionType( optionList,
optionType, 0, TRUE, optionData, &numFound ) ) ) {
if (err != kPGPError_OptionNotFound)
return err;
err = kPGPError_NoErr;
}
}
if( numFound > 1 ) {
err = kPGPError_RedundantOptions;
}
if ( numFound < 1 ) {
optionData->type = kPGPOptionType_InvalidOption;
}
return err;
}
/* Read the nth (searchIndex'th) instance of an option, marking it read */
PGPError
pgpSearchOption(
PGPOptionListRef optionList,
PGPOptionType optionType,
PGPUInt32 searchIndex,
PGPOption *optionData
)
{
PGPUInt32 numFound;
PGPError err = kPGPError_NoErr;
pgpa( pgpaAddrValid( optionData, PGPOption ) );
optionData->type = kPGPOptionType_InvalidOption;
numFound = 0;
if( IsntNull( optionList ) ) {
if( IsPGPError( err = pgpGetIndexedOptionType( optionList,
optionType, searchIndex, TRUE, optionData, &numFound ) ) ) {
if (err != kPGPError_OptionNotFound)
return err;
err = kPGPError_NoErr;
}
}
if( searchIndex >= numFound ) {
optionData->type = kPGPOptionType_InvalidOption;
}
return err;
}
/* Find an option and return its arguments if any.
*
* Takes a parameter string consisting of "%d%p%t" values, where %d means
* a 32-bit scalar, %p means a pointer, and %t means a timeinterval.
* These are packed in a special way in the optionlist code, which this
* routine has to know about. A special case is "%p%l", meaning a pointer
* and length pair.
* If the first two characters are %b then we return a boolean telling whether
* the option was found.
* If the fMandatory flag is set, returns an error if the option doesn't
* exist.
*/
PGPError
pgpFindOptionArgs(
PGPOptionListRef optionList,
PGPOptionType optionType,
PGPBoolean fMandatory,
const char *str,
...
)
{
va_list args;
PGPOption op;
PGPInt32 *ptrInt32;
void **ptrPtr;
PGPTime *ptrTime;
PGPTimeInterval *ptrTimeInterval;
PGPSize *ptrSize;
PGPBoolean *ptrBool;
PFLFileSpecRef *ptrFileSpec;
PGPByte *ptr;
PGPError err = kPGPError_NoErr;
pgpa( pgpaAddrValid( str, char ) );
if( IsPGPError( err = pgpSearchOptionSingle( optionList,
optionType, &op ) ) )
goto error;
va_start( args, str );
/* Handle %b */
if( str[0] == '%' && str[1] == 'b' ) {
ptrBool = va_arg( args, PGPBoolean * );
*ptrBool = IsOp( op );
str += 2;
}
/* Handle other options */
if( IsOp( op ) ) {
if( strlen( str ) == 2 ) {
/* Single options get stored in simple form */
if (str[0] != '%') {
err = kPGPError_BadParams;
goto error;
}
switch( str[1] ) {
case 'd':
ptrInt32 = va_arg( args, PGPInt32 * );
*ptrInt32 = op.value.asInt;
break;
case 'p':
ptrPtr = va_arg( args, void ** );
*ptrPtr = op.value.asPtr;
break;
case 't':
ptrTimeInterval = va_arg( args, PGPTimeInterval * );
*ptrTimeInterval = op.value.asInterval;
break;
case 'T':
ptrTime = va_arg( args, PGPTime * );
*ptrTime = op.value.asTime;
break;
case 'f':
ptrFileSpec = va_arg( args, PFLFileSpecRef * );
*ptrFileSpec = op.value.asFileRef;
break;
default:
err = kPGPError_BadParams;
goto error;
}
va_end( args );
} else if( strcmp( str, "%p%l" ) == 0 ) {
/* Special case, still uses simple form */
ptrPtr = va_arg( args, void ** );
*ptrPtr = op.value.asPtr;
ptrSize = va_arg( args, PGPSize * );
*ptrSize = op.valueSize;
va_end( args );
} else {
/* Get data out of second-order block */
ptr = ( PGPByte * ) op.value.asPtr;
while( *str++ == '%' ) {
switch( *str++ ) {
case 'd':
ptrInt32 = va_arg( args, PGPInt32 * );
*ptrInt32 = *( ( PGPInt32 * ) ptr );
ptr += sizeof( PGPInt32 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -