gControls->cfg->comp[i].numURLs = 0; for (j=0; j<kMaxURLPerComp; j++) {  GetIndString(pkey, rParseKeys, sDomain); currKeyBuf = PascalToC(pkey); currKey = NewPtrClear(strlen(currKeyBuf)+3); strncpy(currKey, currKeyBuf, strlen(currKeyBuf)); gControls->cfg->comp[i].domain[j] = NewHandleClear(kValueMaxLen);  GetIndString(pidx, rIndices, j+1); idxCh = PascalToC(pidx); strncat(currKey, idxCh, 1); DisposePtr(idxCh); strncat(currKey, eof, 1);   FillKeyValueUsingName(currSName, currKey, gControls->cfg->comp[i].domain[j], cfgText);  if (currKey) DisposePtr(currKey); if (currKeyBuf) DisposePtr(currKeyBuf);   GetIndString(pkey, rParseKeys, sServerPath); currKeyBuf = PascalToC(pkey); currKey = NewPtrClear(strlen(currKeyBuf)+3); strncpy(currKey, currKeyBuf, strlen(currKeyBuf)); gControls->cfg->comp[i].serverPath[j] = NewHandleClear(kValueMaxLen);  GetIndString(pidx, rIndices, j+1); idxCh = PascalToC(pidx); strncat(currKey, idxCh, 1); DisposePtr(idxCh); strncat(currKey, eof, 1);  if (!FillKeyValueUsingName(currSName, currKey, gControls->cfg->comp[i].serverPath[j], cfgText)) { if (currKey) DisposePtr(currKey); if (currKeyBuf) DisposePtr(currKeyBuf); break; } gControls->cfg->comp[i].numURLs++; if (currKey) DisposePtr(currKey); if (currKeyBuf) DisposePtr(currKeyBuf); }
PopulateCompWinKeys(char *cfgText){	OSErr 		err = noErr;	int			i, j, hunVal, tenVal, unitVal;	Ptr			currSNameBuf, currSName, currKeyBuf, currKey, idxCh;	Str255		pSName, pkey, pidx;	char		eof[1];	char 		*currDepNum;	long		randomPercent;	Boolean		bRandomSet;		eof[0] = 0;		/* ComponentsWin: components and their descriptions, and other properties */	gControls->cfg->selCompMsg = NewHandleClear(kValueMaxLen);	FillKeyValueUsingResID(sCompDlg, sMsg0, gControls->cfg->selCompMsg, cfgText);		/* AdditionsWin: additional components */	gControls->cfg->selAddMsg = NewHandleClear(kValueMaxLen);	FillKeyValueUsingResID(sAddDlg, sMsg0, gControls->cfg->selAddMsg, cfgText);	gControls->cfg->bAdditionsExist = false;		gControls->cfg->numComps = 0;	for (i=0; i<kMaxComponents; i++)	{		GetIndString(pSName, rParseKeys, sComponent);				currSNameBuf = PascalToC(pSName);		currSName = NewPtrClear(kSNameMaxLen);		strncpy(currSName, currSNameBuf, strlen(currSNameBuf));				if(i>99) // concat 100's digit 		{			hunVal = i/100;			GetIndString(pidx, rIndices, hunVal+1);			idxCh = PascalToC(pidx);			strncat(currSName, idxCh, 1);			DisposePtr(idxCh);		}		else			hunVal = 0;				if(i>9)	// concat 10's digit 		{			tenVal = (i - (hunVal*100))/10;			GetIndString(pidx, rIndices, tenVal+1);			idxCh = PascalToC(pidx);			strncat(currSName, idxCh, 1);			DisposePtr(idxCh);		}		else			tenVal = 0;			unitVal = i - (hunVal*100) - (tenVal*10);		GetIndString(pidx, rIndices, unitVal+1);		idxCh = PascalToC(pidx);		strncat(currSName, idxCh, 1);		DisposePtr(idxCh);		strncat(currSName, eof, 1);				/* short description */		GetIndString(pkey, rParseKeys, sDescShort);		currKey = PascalToC(pkey);		gControls->cfg->comp[i].shortDesc = NewHandleClear(kValueMaxLen);		if (!FillKeyValueUsingName(currSName, currKey, gControls->cfg->comp[i].shortDesc, cfgText))		{			DisposePtr(currKey);			break; // no more Components		}		DisposePtr(currKey);				/* long description */		GetIndString(pkey, rParseKeys, sDescLong);		currKey = PascalToC(pkey);		gControls->cfg->comp[i].longDesc = NewHandleClear(kValueMaxLen);		FillKeyValueUsingName(currSName, currKey, gControls->cfg->comp[i].longDesc, cfgText);		DisposePtr(currKey);				/* archive */		GetIndString(pkey, rParseKeys, sArchive);		currKey = PascalToC(pkey);		gControls->cfg->comp[i].archive = NewHandleClear(kArchiveMaxLen);		FillKeyValueUsingName(currSName, currKey, gControls->cfg->comp[i].archive, cfgText);		DisposePtr(currKey);				/* install size */		GetIndString(pkey, rParseKeys, sInstSize);		currKey = PascalToC(pkey);		Handle sizeH = NewHandleClear(4); // long is four bytes		FillKeyValueUsingName(currSName, currKey, sizeH, cfgText);		HLock(sizeH);		gControls->cfg->comp[i].size = atol(*sizeH);		HUnlock(sizeH);		DisposeHandle(sizeH);		DisposePtr(currKey);				/* random install percentage */		GetIndString(pkey, rParseKeys, sRandomInstall);		currKey = PascalToC(pkey);		Handle randomH = NewHandleClear(4);		if (FillKeyValueUsingName(currSName, currKey, randomH, cfgText))		{			bRandomSet = true;			HLock(randomH);			randomPercent = atol(*randomH);			HUnlock(randomH);						if (randomPercent != 0) /* idiot proof for those giving 0 as the rand percent */			{				if (RandomSelect(randomPercent))				{					gControls->cfg->comp[i].selected = true;					gControls->cfg->comp[i].refcnt = 1;				}				else				{					gControls->cfg->comp[i].selected = false;					gControls->cfg->comp[i].refcnt = 0;				}			}			else				bRandomSet = false;		}		else			bRandomSet = false;		if (randomH)			DisposeHandle(randomH);		if (currKey)			DisposePtr(currKey);				/* attributes (SELECTED|INVISIBLE|LAUNCHAPP|ADDITIONAL) */		GetIndString(pkey, rParseKeys, sAttributes);		currKey = PascalToC(pkey);		Handle attrValH = NewHandleClear(255);		if (FillKeyValueUsingName(currSName, currKey, attrValH, cfgText))		{			HLock(attrValH);					char *attrType = NULL;			GetIndString(pkey, rParseKeys, sSELECTED);			attrType = PascalToC(pkey);			if (!bRandomSet) /* when random key specified then selected attr is overriden */			{				if (NULL != strstr(*attrValH, attrType))				{					gControls->cfg->comp[i].selected = true;					gControls->cfg->comp[i].refcnt = 1;				}				else				{					gControls->cfg->comp[i].selected = false;					gControls->cfg->comp[i].refcnt = 0;				}			}			if (attrType)				DisposePtr(attrType);					GetIndString(pkey, rParseKeys, sINVISIBLE);			attrType = PascalToC(pkey);			if (NULL != strstr(*attrValH, attrType))				gControls->cfg->comp[i].invisible = true;			else				gControls->cfg->comp[i].invisible = false;			if (attrType)				DisposePtr(attrType);							GetIndString(pkey, rParseKeys, sLAUNCHAPP);			attrType = PascalToC(pkey);			if (NULL != strstr(*attrValH, attrType))				gControls->cfg->comp[i].launchapp = true;			else				gControls->cfg->comp[i].launchapp = false;			if (attrType)				DisposePtr(attrType);						GetIndString(pkey, rParseKeys, sADDITIONAL);			attrType = PascalToC(pkey);			if (NULL != strstr(*attrValH, attrType))			{				gControls->cfg->comp[i].additional = true;				gControls->cfg->bAdditionsExist = true; /* doesn't matter if set multiple times */			}			else				gControls->cfg->comp[i].additional = false;			if (attrType)				DisposePtr(attrType);								HUnlock(attrValH);		}		if (attrValH)			DisposeHandle(attrValH);					/* initialize to not highlighted */		gControls->cfg->comp[i].highlighted = false;				/* URLs for redundancy/retry/failover */		gControls->cfg->comp[i].numURLs = 0;		for (j=0; j<kMaxURLPerComp; j++)		{			// first get domain			GetIndString(pkey, rParseKeys, sDomain);			currKeyBuf = PascalToC(pkey);			currKey = NewPtrClear(strlen(currKeyBuf)+3); // tens, unit, null termination			strncpy(currKey, currKeyBuf, strlen(currKeyBuf));			gControls->cfg->comp[i].domain[j] = NewHandleClear(kValueMaxLen);						GetIndString(pidx, rIndices, j+1);			idxCh = PascalToC(pidx);			strncat(currKey, idxCh, 1);			DisposePtr(idxCh);			strncat(currKey, eof, 1);						// don't break if this fails since there may be more Server Paths thatn Domains			FillKeyValueUsingName(currSName, currKey, gControls->cfg->comp[i].domain[j], cfgText);			if (currKey)				DisposePtr(currKey);			if (currKeyBuf)				DisposePtr(currKeyBuf);							// then get server paths			GetIndString(pkey, rParseKeys, sServerPath);			currKeyBuf = PascalToC(pkey);			currKey = NewPtrClear(strlen(currKeyBuf)+3); // tens, unit, null termination			strncpy(currKey, currKeyBuf, strlen(currKeyBuf));			gControls->cfg->comp[i].serverPath[j] = NewHandleClear(kValueMaxLen);						GetIndString(pidx, rIndices, j+1);			idxCh = PascalToC(pidx);			strncat(currKey, idxCh, 1);			DisposePtr(idxCh);			strncat(currKey, eof, 1);						if (!FillKeyValueUsingName(currSName, currKey, gControls->cfg->comp[i].serverPath[j], cfgText))			{				if (currKey)					DisposePtr(currKey);				if (currKeyBuf)					DisposePtr(currKeyBuf);				break;			}			gControls->cfg->comp[i].numURLs++;			if (currKey)				DisposePtr(currKey);			if (currKeyBuf)				DisposePtr(currKeyBuf);		}				/* dependees for other components */		gControls->cfg->comp[i].numDeps = 0;		GetIndString(pkey, rParseKeys, sDependee);		currKeyBuf = PascalToC(pkey);		for (j=0; j<kMaxComponents; j++)		{			// currKey = "Dependee<j>"			currDepNum = ltoa(j);			currKey = NewPtrClear(strlen(currKeyBuf) + strlen(currDepNum) + 1);			strcpy(currKey, currKeyBuf);			strcat(currKey, currDepNum);			gControls->cfg->comp[i].depName[j] = NewHandleClear(kValueMaxLen);			if (!FillKeyValueUsingName(currSName, currKey, gControls->cfg->comp[i].depName[j], cfgText))			{				if (currKey)					DisposePtr(currKey);				if (currDepNum)					free(currDepNum);				break;			}						gControls->cfg->comp[i].numDeps++;			if (currKey)				DisposePtr(currKey);			if (currDepNum)				free(currDepNum);		}		if (currKeyBuf)			DisposePtr(currKeyBuf);	}	gControls->cfg->numComps = i;		return err;}