Exemplo n.º 1
0
	Exec_stat exec(MCExecPoint& ep)
	{
		bool t_success;
		t_success = true;

		char *t_old_filename;
		t_old_filename = nil;
		if (t_success && m_old_file -> eval(ep) == ES_NORMAL)
			t_old_filename = ep . getsvalue() . clone();
		else
			t_success = false;

		char *t_new_filename;
		t_new_filename = nil;
		if (t_success && m_new_file -> eval(ep) == ES_NORMAL)
			t_new_filename = ep . getsvalue() . clone();
		else
			t_success = false;

		char *t_patch_filename;
		t_patch_filename = nil;
		if (t_success && m_patch_file -> eval(ep) == ES_NORMAL)
			t_patch_filename = ep . getsvalue() . clone();
		else
			t_success = false;

		IO_handle t_old_handle;
		t_old_handle = nil;
		if (t_success)
		{
			t_old_handle = MCS_open(t_old_filename, IO_READ_MODE, False, False, 0);
			if (t_old_handle == nil)
				t_success = false;
		}

		IO_handle t_new_handle;
		t_new_handle = nil;
		if (t_success)
		{
			t_new_handle = MCS_open(t_new_filename, IO_READ_MODE, False, False, 0);
			if (t_new_handle == nil)
				t_success = false;
		}

		IO_handle t_patch_handle;
		t_patch_handle = nil;
		if (t_success)
		{
			t_patch_handle = MCS_open(t_patch_filename, IO_WRITE_MODE, False, False, 0);
			if (t_patch_handle == nil)
				t_success = false;
		}

		if (t_success)
		{
			InputStream t_new_stream, t_old_stream;
			OutputStream t_patch_stream;
			t_new_stream . handle = t_new_handle;
			t_old_stream . handle = t_old_handle;
			t_patch_stream . handle = t_patch_handle;
			t_success = MCBsDiffBuild(&t_old_stream, &t_new_stream, &t_patch_stream);
		}

		if (t_success)
			MCresult -> clear();
		else
			MCresult -> sets("patch building failed");

		if (t_patch_handle != nil)
			MCS_close(t_patch_handle);
		if (t_new_handle != nil)
			MCS_close(t_new_handle);
		if (t_old_handle != nil)
			MCS_close(t_old_handle);

		delete t_patch_filename;
		delete t_new_filename;
		delete t_old_filename;
		
		return ES_NORMAL;
	}
Exemplo n.º 2
0
    void exec_ctxt(MCExecContext &ctxt)
    {
		bool t_success;
		t_success = true;

		MCAutoStringRef t_old_filename;
        if (!ctxt . EvalExprAsStringRef(m_old_file, EE_INTERNAL_BSDIFF_BADOLD, &t_old_filename))
            return;

		MCAutoStringRef t_new_filename;
        if (!ctxt . EvalExprAsStringRef(m_new_file, EE_INTERNAL_BSDIFF_BADNEW, &t_new_filename))
            return;

		MCAutoStringRef t_patch_filename;
        if (!ctxt . EvalExprAsStringRef(m_patch_file, EE_INTERNAL_BSDIFF_BADPATCH, &t_patch_filename))
            return;

		IO_handle t_old_handle;
		t_old_handle = nil;
		if (t_success)
		{
			t_old_handle = MCS_open(*t_old_filename, kMCOpenFileModeRead, False, False, 0);
			if (t_old_handle == nil)
				t_success = false;
		}

		IO_handle t_new_handle;
		t_new_handle = nil;
		if (t_success)
		{
			t_new_handle = MCS_open(*t_new_filename, kMCOpenFileModeRead, False, False, 0);
			if (t_new_handle == nil)
				t_success = false;
		}

		IO_handle t_patch_handle;
		t_patch_handle = nil;
		if (t_success)
		{
			t_patch_handle = MCS_open(*t_patch_filename, kMCOpenFileModeWrite, False, False, 0);
			if (t_patch_handle == nil)
				t_success = false;
		}

		if (t_success)
		{
			InputStream t_new_stream, t_old_stream;
			OutputStream t_patch_stream;
			t_new_stream . handle = t_new_handle;
			t_old_stream . handle = t_old_handle;
			t_patch_stream . handle = t_patch_handle;
			t_success = MCBsDiffBuild(&t_old_stream, &t_new_stream, &t_patch_stream);
		}

		if (t_success)
            ctxt . SetTheResultToEmpty();
		else
            ctxt . SetTheResultToCString("patch building failed");

		if (t_patch_handle != nil)
			MCS_close(t_patch_handle);
		if (t_new_handle != nil)
			MCS_close(t_new_handle);
		if (t_old_handle != nil)
            MCS_close(t_old_handle);
	}