示例#1
0
文件: edit.c 项目: ISLEcode/kornshell
/*
 * Run an editor on the file at "fp" of "size" bytes,
 * and return a new file pointer.
 * Signals must be handled by the caller.
 * "Type" is 'e' for state.var.editor, 'v' for state.var.visual.
 */
FILE*
run_editor(register FILE* fp, off_t size, struct header* hp, int type, int readonly)
{
	FILE*		ep;
	time_t		modtime;
	int		lc;
	int		err;
	char*		edit;
	unsigned long	editheaders = 0;
	struct parse	pp;

	/*
	 * Create and copy to the temporary file.
	 */
	if (!(ep = fileopen(state.tmp.edit, "EMw")))
		goto ret1;
	if (size) {
		if (size < 0)
			size = 0;
		if (hp && state.var.editheaders) {
			editheaders = GEDIT|GRULE;
			headout(ep, hp, editheaders|GNL);
		}
		if (filecopy(NiL, fp, state.tmp.edit, ep, NiL, size, NiL, NiL, 0))
			goto ret2;
	}
	modtime = state.openstat.st_mtime;
	fileclose(ep);
	ep = 0;
	/*
	 * Edit the file.
	 */
	edit = type == 'e' ? state.var.editor : state.var.visual;
	err = run_command(edit, 0, -1, -1, state.tmp.edit, NiL, NiL) < 0;
	/*
	 * If in readonly mode or file unchanged, clean up and return.
	 */
	if (readonly)
		goto ret2;
	if (stat(state.tmp.edit, &state.openstat) < 0)
		goto ret1;
	if (modtime == state.openstat.st_mtime)
		goto ret2;
	if (err)
		note(0, "%s did not exit normally but did do some changes -- you may want to re-edit", edit);
	/*
	 * Now, switch to the temporary file.
	 */
	if (!(ep = fileopen(state.tmp.edit, "Ea+")))
		goto ret2;
	if (editheaders && headset(&pp, NiL, ep, hp, NiL, editheaders|GTO|GMETOO)) {
		while (headget(&pp));
		remove(state.tmp.edit);
		if (!(ep = fileopen(state.tmp.edit, "EMa+")))
			goto ret1;
		filecopy(NiL, pp.fp, state.tmp.edit, ep, NiL, (off_t)0, NiL, NiL, 0);
		fileclose(pp.fp);
	}
	/*
	 * Ensure that the tempEdit file ends with two newlines.
	 *
	 * XXX
	 * Probably ought to have a `From' line, as well.
	 *
	 * XXX
	 * If the file is only a single byte long, the seek is going to
	 * fail, but I'm not sure we care.  In the case of any error, we
	 * pass back the file descriptor -- if we fail because the disk
	 * is too full, reads should continue to work and I see no reason
	 * to discard the user's work.
	 */
	if (fseek(ep, (off_t)-2, SEEK_END) < 0)
		return ep;
	lc = getc(ep) == '\n' ? 1 : 0;
	if (getc(ep) == '\n')
		++lc;
	else
		lc = 0;

	switch (lc) {
	case 0:
		if (putc('\n', ep) == EOF)
			break;
		/* FALLTHROUGH */
	case 1:
		putc('\n', ep);
		/* FALLTHROUGH */
	case 2:
		break;
	default:
		abort();
		break;
	}
	/*
	 * XXX: fflush() is necessary, so future stat(2) succeeds.
	 */
	fflush(ep);
	remove(state.tmp.edit);
	return ep;

 ret1:	note(SYSTEM, "%s", state.tmp.edit);
 ret2:	remove(state.tmp.edit);
	if (ep)
		fileclose(ep);
	return 0;
}
/**
Reconfigure from remote headset with valid configuration
*/
TVerdict CTestStep_MMF_A2DPBLUETOOTH_U_0231::DoTestStepL( void )
	{
	TVerdict verdict = EPass;
	TRequestStatus* status = &(iAsyncTestStepNotifier->RequestStatus());
	TAvdtpMediaTransportCapabilities* mediaTransportCaps = NULL;
	TSBCCodecCapabilities* SBCCodecCaps = NULL;
	
	iA2dpBTHeadsetAudioInterface->OpenDevice(*status);
	iAsyncTestStepNotifier->HandleAsyncRequest();
	if (iError != KErrNone)
		{
		INFO_PRINTF2(_L("Open error %d" ), iError);
		verdict = EInconclusive;
		}
	else
		{
		//now try to perform a valid reconfiguration
		MGavdpUser* gavdpUser = iA2dpBTHeadsetAudioInterface->TEST_MGavdpUser();
		//these TSEIDs should come from the iA2dpBTHeadsetAudioInterface
		//but this would need another TEST function to get them
		//the SEIDs below work ok on CSR and blueant but mght not work 
		//on all headsets
		TSEID symbianDevice(1,ETrue);
		TSEID headset(2,EFalse);
		iError = gavdpUser->GAVDP_SuspendIndication(symbianDevice);
		iTimer->StopAfter(TTimeIntervalMicroSeconds32(KTimeForEventsToRegister));//try 500mS
		CActiveScheduler::Current()->Start();
		if (iError != KErrNone)
			{
			INFO_PRINTF2(_L("error %d" ), iError);
			verdict = EFail;
			}
		else
			{
			//now send a valid configuration
			gavdpUser->GAVDP_ConfigurationStartIndication(symbianDevice, headset);
			iTimer->StopAfter(TTimeIntervalMicroSeconds32(KTimeForEventsToRegister));//try 500mS
			CActiveScheduler::Current()->Start();
			if (iError != KErrNone)
				{
				INFO_PRINTF2(_L("error on GAVDP_ConfigurationStartIndication %d" ), iError);
				verdict = EFail;
				}
			
			mediaTransportCaps = new TAvdtpMediaTransportCapabilities();
			iError = gavdpUser->GAVDP_ConfigurationIndication(mediaTransportCaps);
			if (iError != KErrNone)
				{
				INFO_PRINTF1(_L("error on valid transport config "));
				verdict = EFail;
				}
			SBCCodecCaps = new TSBCCodecCapabilities();
			SBCCodecCaps->SetSamplingFrequencies(E32kHz);
			SBCCodecCaps->SetChannelModes(EMono);
			SBCCodecCaps->SetBlockLengths(EBlockLenEight);
			SBCCodecCaps->SetSubbands(EEightSubbands);
			SBCCodecCaps->SetAllocationMethods(ELoudness);
			SBCCodecCaps->SetMinBitpoolValue(30);
			SBCCodecCaps->SetMaxBitpoolValue(44);
			iError = gavdpUser->GAVDP_ConfigurationIndication(SBCCodecCaps);
			if (iError != KErrNone)
				{
				INFO_PRINTF2(_L("error on codec GAVDP_ConfigurationIndication %d" ), iError);
				verdict = EFail;
				}
			iTimer->StopAfter(TTimeIntervalMicroSeconds32(KTimeForEventsToRegister));//try 500mS
			CActiveScheduler::Current()->Start();
			iError = gavdpUser->GAVDP_ConfigurationEndIndication();
			iTimer->StopAfter(TTimeIntervalMicroSeconds32(KTimeForEventsToRegister));//try 500mS
			CActiveScheduler::Current()->Start();
			iError = gavdpUser->GAVDP_StartIndication(symbianDevice);
			iTimer->StopAfter(TTimeIntervalMicroSeconds32(KTimeForEventsToRegister));//try 500mS
			CActiveScheduler::Current()->Start();
			if (iError != KErrNone)
				{
				INFO_PRINTF2(_L("error on GAVDP_StartIndication is %d" ), iError);
				verdict = EFail;
				}
			}
		}
	return verdict;
	}