Esempio n. 1
0
int xdl_patch(mmfile_t *mf, mmfile_t *mfp, int mode, xdemitcb_t *ecb,
	      xdemitcb_t *rjecb) {
	int hkres;
	long hkpos, ibase;
	recfile_t rff;
	patch_t pch;
	patchstats_t ps;

	if (xdl_init_recfile(mf, &rff) < 0) {

		return -1;
	}
	if (xdl_init_patch(mfp, &pch) < 0) {

		xdl_free_recfile(&rff);
		return -1;
	}

	ps.adds = ps.dels = 0;
	ibase = 0;
	if ((hkres = xdl_first_hunk(&pch)) > 0) {
		do {
			if (xdl_find_hunk(&rff, ibase, &pch, mode, &hkpos)) {
				if (xdl_apply_hunk(&rff, hkpos, &pch, mode,
						   &ibase, ecb, &ps) < 0) {

					xdl_free_patch(&pch);
					xdl_free_recfile(&rff);
					return -1;
				}
			} else {
				if (xdl_reject_hunk(&rff, &pch, mode, rjecb, &ps) < 0) {

					xdl_free_patch(&pch);
					xdl_free_recfile(&rff);
					return -1;
				}
			}
		} while ((hkres = xdl_next_hunk(&pch)) > 0);
	}
	if (hkres < 0) {

		xdl_free_patch(&pch);
		xdl_free_recfile(&rff);
		return -1;
	}

	if (xdl_flush_section(&rff, ibase, rff.nrec - 1, ecb) < 0) {

		xdl_free_patch(&pch);
		xdl_free_recfile(&rff);
		return -1;
	}

	xdl_free_patch(&pch);
	xdl_free_recfile(&rff);

	return 0;
}
Esempio n. 2
0
int xdl_patch(mmfile_t *mf, mmfile_t *mfp, int mode, xdemitcb_t *ecb,
	      xdemitcb_t *rjecb) {
	/* int hkres, exact; */
	int hkres;
	/* long hkpos, ibase; */
	long ibase;
	recfile_t rff;
	patch_t pch;

	if (xdl_init_recfile(mf, 0, &rff) < 0) {

		return -1;
	}
	if (xdl_init_patch(mfp, mode & ~XDL_PATCH_MODEMASK, &pch) < 0) {

		xdl_free_recfile(&rff);
		return -1;
	}
	mode &= XDL_PATCH_MODEMASK;
	ibase = 0;
	if ((hkres = xdl_first_hunk(&pch)) > 0) {
		do {
			if (xdl_process_hunk(&rff, &pch, &ibase, mode,
					     ecb, rjecb) < 0) {
				xdl_free_patch(&pch);
				xdl_free_recfile(&rff);
				return -1;
			}
		} while ((hkres = xdl_next_hunk(&pch)) > 0);
	}
	if (hkres < 0) {

		xdl_free_patch(&pch);
		xdl_free_recfile(&rff);
		return -1;
	}
	if (xdl_flush_section(&rff, ibase, rff.nrec - 1, ecb) < 0) {

		xdl_free_patch(&pch);
		xdl_free_recfile(&rff);
		return -1;
	}
	xdl_free_patch(&pch);
	xdl_free_recfile(&rff);

	return pch.fuzzies;
}