strncat(buf, &ch, 1);
strncpy(buf, &ch, 1);
GenerateIDIFromOpt(Str255 idiName, long dirID, short vRefNum, FSSpec *idiSpec){	Boolean bSuccess = true;	OSErr 	err;	short	refNum, instChoice;	long 	count, compsDone, i, j, k, len;	char 	ch, siteDomain[255];	Ptr 	buf, keybuf, fnum;	Str255	pkeybuf;	FSSpec	fsExists;	StringPtr	pcurrArchive = 0;		err = FSMakeFSSpec(vRefNum, dirID, idiName, idiSpec);	if ((err != noErr) && (err != fnfErr))	{		ErrorHandler(err);		return false;	}	err = FSpCreate(idiSpec, 'NSCP', 'TEXT', smSystemScript);	if ( (err != noErr) && (err != dupFNErr))	{		ErrorHandler(err);		return false;	}	ERR_CHECK_RET(FSpOpenDF(idiSpec, fsRdWrPerm, &refNum), false);		// setup buffer to at least 8K	buf = NULL;	buf = NewPtrClear(kGenIDIFileSize);	if (!buf)	{		ErrorHandler(eMem);		return false;	}	compsDone = 0;	instChoice = gControls->opt->instChoice-1;		// loop through 0 to kMaxComponents	for(i=0; i<kMaxComponents; i++)	{		// general test: if component in setup type		if ( (gControls->cfg->st[instChoice].comp[i] == kInSetupType) &&			 (compsDone < gControls->cfg->st[instChoice].numComps) )		{ 			// if custom and selected, or not custom setup type			// add file to buffer			if ( ((instChoice == gControls->cfg->numSetupTypes-1) && 				  (gControls->cfg->comp[i].selected == true)) ||				 (instChoice < gControls->cfg->numSetupTypes-1) )			{// XXX shouldn't this be #if MOZILLA == 1				// verify that file does not exist already				HLock(gControls->cfg->comp[i].archive);				pcurrArchive = CToPascal(*gControls->cfg->comp[i].archive);				HUnlock(gControls->cfg->comp[i].archive);								err = FSMakeFSSpec(vRefNum, dirID, pcurrArchive, &fsExists);								// if file doesn't exist				if (err == fnfErr)				{// XXX shouldn't this be #endif /* MOZILLA == 1 */                        					// get file number 					fnum = ltoa(compsDone);									// construct through concatenation [File<num>]\r					GetIndString(pkeybuf, rIDIKeys, sFile);					keybuf = PascalToC(pkeybuf);					ch = '[';					strncat(buf, &ch, 1);					strncat(buf, keybuf, strlen(keybuf));					strncat(buf, fnum, strlen(fnum));					DisposePtr(keybuf);									keybuf = NewPtrClear(3);					keybuf = "]\r";					strncat(buf, keybuf, strlen(keybuf));					if (keybuf)						DisposePtr(keybuf);					// write out \tdesc=					GetIndString(pkeybuf, rIDIKeys, sDesc);					keybuf = PascalToC(pkeybuf);					ch = '\t';													strncat(buf, &ch, 1);					// \t					strncat(buf, keybuf, strlen(keybuf));	// \tdesc					ch = '=';								// \tdesc=					strncat(buf, &ch, 1);					if (keybuf)						DisposePtr(keybuf);									// write out gControls->cfg->comp[i].shortDesc\r					HLock(gControls->cfg->comp[i].shortDesc);					strncat(buf, *gControls->cfg->comp[i].shortDesc, strlen(*gControls->cfg->comp[i].shortDesc));									HUnlock(gControls->cfg->comp[i].shortDesc);					ch = '\r';					strncat(buf, &ch, 1);								// if [Site Selector] sections exists					if (gControls->cfg->numSites > 0)					{						memset(siteDomain, 0 , 255);												// get domain of selected site						HLock(gControls->cfg->site[gControls->opt->siteChoice-1].domain);						len = strlen(*(gControls->cfg->site[gControls->opt->siteChoice-1].domain));						strncpy(siteDomain, *(gControls->cfg->site[gControls->opt->siteChoice-1].domain),								(len < 255) ? len : 255);						HUnlock(gControls->cfg->site[gControls->opt->siteChoice-1].domain);		    					// iterate over gControls->cfg->comp[i].numURLs    					for (j=0; j<gControls->cfg->comp[i].numURLs; j++)    					{    						// write out \tnumURLs+1= from STR# resource    						GetIndString(pkeybuf, rIndices, j+2); // j+2 since 1-based idx, not 0-based    						keybuf = PascalToC(pkeybuf);    						ch = '\t';    						strncat(buf, &ch, 1);					// \t    						strncat(buf, keybuf, strlen(keybuf));	// \t<n>    						ch = '=';    						strncat(buf, &ch, 1);					// \t<n>=    						if (keybuf)    							DisposePtr(keybuf);    							    						// use selected DomainX to replace Domain0 in curr ComponentX section    						strncat(buf, siteDomain, strlen(siteDomain));    						// tack on server path for this index    						HLock(gControls->cfg->comp[i].serverPath[j]);    						strncat(buf, *gControls->cfg->comp[i].serverPath[j], strlen(*gControls->cfg->comp[i].serverPath[j]));    						HUnlock(gControls->cfg->comp[i].serverPath[j]);						    						    						// tack on 'archive\r'    						HLock(gControls->cfg->comp[i].archive);    						strncat(buf, *gControls->cfg->comp[i].archive, strlen(*gControls->cfg->comp[i].archive));    						HUnlock(gControls->cfg->comp[i].archive);    						ch = '\r';    						strncat(buf, &ch, 1);    					}                    }                                        // now tack on failovers from ComponentX section                    for (k=0; k<gControls->cfg->comp[i].numURLs; k++)					{						// write out \tnumURLs+1= from STR# resource						GetIndString(pkeybuf, rIndices, k+j+2); // j+2 since 1-based idx, not 0-based						keybuf = PascalToC(pkeybuf);						ch = '\t';						strncat(buf, &ch, 1);					// \t						strncat(buf, keybuf, strlen(keybuf));	// \t<n>						ch = '=';						strncat(buf, &ch, 1);					// \t<n>=						if (keybuf)							DisposePtr(keybuf);													// get domain for this index						HLock(gControls->cfg->comp[i].domain[k]);						strncat(buf, *gControls->cfg->comp[i].domain[k], strlen(*gControls->cfg->comp[i].domain[k]));						HUnlock(gControls->cfg->comp[i].domain[k]);						// tack on server path for this index						HLock(gControls->cfg->comp[i].serverPath[k]);						strncat(buf, *gControls->cfg->comp[i].serverPath[k], strlen(*gControls->cfg->comp[i].serverPath[k]));						HUnlock(gControls->cfg->comp[i].serverPath[k]);																		// tack on 'archive\r'						HLock(gControls->cfg->comp[i].archive);						strncat(buf, *gControls->cfg->comp[i].archive, strlen(*gControls->cfg->comp[i].archive));						HUnlock(gControls->cfg->comp[i].archive);						ch = '\r';						strncat(buf, &ch, 1);					}					if (fnum)						free(fnum);					compsDone++;// XXX shouldn't this be #if MOZILLA == 1				}// XXX shouldn't this be #endif /* MOZILLA == 1 */			}		}		else if (compsDone >= gControls->cfg->st[instChoice].numComps)			break;  	}					// terminate by entering Netscape Install section	GetIndString(pkeybuf, rIDIKeys, sNSInstall);	keybuf = PascalToC(pkeybuf);	ch = '[';	strncat(buf, &ch, 1);					// [	strncat(buf, keybuf, strlen(keybuf));	// [Netscape Install	if (keybuf)		DisposePtr(keybuf);		keybuf = NewPtrClear(2);	keybuf = "]\r";					strncat(buf, keybuf, strlen(keybuf));	// [Netscape Install]\r	if (keybuf)		DisposePtr(keybuf);		// write out \tcore_file=<filename>\r	AddKeyToIDI( sCoreFile, gControls->cfg->coreFile, buf );		// write out \tcore_dir=<dirname>\r	AddKeyToIDI( sCoreDir, gControls->cfg->coreDir, buf );		// write out \tno_ads=<boolean>\r	AddKeyToIDI( sNoAds, gControls->cfg->noAds, buf );		// write out \tsilent=<boolean>\r	AddKeyToIDI( sSilent, gControls->cfg->silent, buf );		// write out \texecution=<boolean>\r	AddKeyToIDI( sExecution, gControls->cfg->execution, buf );		// write out \tconfirm_install=<boolean>	AddKeyToIDI( sConfirmInstall, gControls->cfg->confirmInstall, buf );		// write buf to disk	count = strlen(buf);	ERR_CHECK_RET(FSWrite(refNum, &count, buf), false);		// close file	ERR_CHECK_RET(FSClose(refNum), false)		if (buf)		DisposePtr(buf);	return bSuccess;}