Beispiel #1
0
static void SortAndMakeUserFontNameList( void )
{
    UInt16        i;
    DBEntryType*  dbListEntry;
    DBEntryType** userFontArray;

    currentUserFontNumber = NO_SUCH_USER_FONT;
    ClearUserFontNameList();
    if ( userFontDBList == NULL )
        return;

    numberOfUserFonts = ListSize( userFontDBList );
    if ( numberOfUserFonts == 0 )
        return;

    userFontArray   = SafeMemPtrNew( numberOfUserFonts * sizeof( DBEntryType* ) );
    userFontNames   = SafeMemPtrNew( numberOfUserFonts * sizeof( Char* ) );
    dbListEntry     = ListFirst( userFontDBList );
    for ( i = 0; i < numberOfUserFonts ; i++ ) {
        userFontArray[ i ] = dbListEntry;
        dbListEntry        = ListNext( userFontDBList, dbListEntry );
    }
    SysQSort( userFontArray, numberOfUserFonts, sizeof( DBEntryType* ),
        DBEntryCompare, 0 );
    ListDelete( userFontDBList );
    userFontDBList = ListCreate();
    for ( i = 0 ; i < numberOfUserFonts ; i++ ) {
        ListAppend( userFontDBList, userFontArray[ i ] );
        userFontNames[ i ] = userFontArray[ i ]->name;
    }
    SafeMemPtrFree( userFontArray );
}
Beispiel #2
0
/***********************************************************************
 *
 * FUNCTION:    PrvCreateTimeZoneArray
 *
 * DESCRIPTION: Create the array of time zone entries from our string
 *		list, gtm offset list, and country list resources. Sort based on
 *		time zone name.
 *
 *	DOLATER kwk - we could save the time zone array we're creating here
 *		in memory, to avoid the performance hit of creating the array.
 *		On the other hand, then the list of names would need to stay
 *		locked down, unless we also copy those into the memory buffer,
 *		which means another 700+ bytes.
 *
 * PARAMETERS:
 *		timeZoneNames	<->	Ptr to returned handle to list of names.
 *		numTimeZones	<->	Ptr to count of number of time zones.
 *
 * RETURNED:
 *		Ptr to allocated array of time zone entry records.
 *
 * HISTORY:
 *		07/31/00	kwk	Created by Ken Krugler.
 *		08/23/00	kwk	Fixed bug where release ROMs caused ErrNonFatalDisplayIf
 *							to become a no-op, and thus the country and time zone
 *							offset list ptrs weren't skipping the count word.
 *
 ***********************************************************************/
static TimeZoneEntryType* PrvCreateTimeZoneArray(MemHandle* timeZoneNames, UInt16* numTimeZones)
{
	const Char* tzNamesP;
	TimeZoneEntryType* tzEntries;
	MemHandle offsetsH;
	MemHandle countriesH;
	UInt16* resP;
	Int16* gmtOffsetsP;
	UInt16* countriesP;
	UInt16 i;
	
	// Specify the number of items in the list, based on total # of items
	// in our time zone name list resource.
	*timeZoneNames = DmGetResource(strListRscType, TimeZoneNamesStringList);
	ErrNonFatalDisplayIf(*timeZoneNames == NULL, "No time zone names");
	tzNamesP = (const Char*)MemHandleLock(*timeZoneNames);
	
	// Skip over prefix string, then get the entry count.
	tzNamesP += StrLen(tzNamesP) + 1;
	*numTimeZones = *tzNamesP++;
	*numTimeZones = (*numTimeZones << 8) +  *tzNamesP++;
	
	// Allocate the array of time zone records.
	tzEntries = (TimeZoneEntryType*)MemPtrNew(*numTimeZones * sizeof(TimeZoneEntryType));
	ErrFatalDisplayIf(tzEntries == NULL, "Out of memory");
	
	// Find and lock down the gtm offset and country integer lists.
	offsetsH = DmGetResource(wrdListRscType, TimeZoneGMTOffsetsList);
	ErrNonFatalDisplayIf(offsetsH == NULL, "No time zone offsets");
	resP = (UInt16*)MemHandleLock(offsetsH);
	ErrNonFatalDisplayIf(*resP != *numTimeZones, "GMT offset count != name count");
	
	// Skip count at start of list.
	gmtOffsetsP = (Int16*)resP + 1;
	
	countriesH = DmGetResource(wrdListRscType, TimeZoneCountriesList);
	ErrNonFatalDisplayIf(countriesH == NULL, "No time zone countries");
	resP = (UInt16*)MemHandleLock(countriesH);
	ErrNonFatalDisplayIf(*resP != *numTimeZones, "Time zone country count != name count");
	
	// Skip count at start of list.
	countriesP = resP + 1;
	
	// Now loop to fill in all of the records.
	for (i = 0; i < *numTimeZones; i++)
	{
		tzEntries[i].tzName = tzNamesP;
		tzNamesP += StrLen(tzNamesP) + 1;
		tzEntries[i].tzOffset = gmtOffsetsP[i];
		tzEntries[i].tzCountry = (CountryType)countriesP[i];
	}
	
	MemHandleUnlock(offsetsH);
	MemHandleUnlock(countriesH);
	
	// Now sort the list, based on the time zone name.
	SysQSort(tzEntries, *numTimeZones, sizeof(TimeZoneEntryType), PrvCompareTimeZoneEntries, 0);
	
	return(tzEntries);
} // PrvCreateTimeZoneArray