The format-textdiff library defines the textdiff procedure, which produces a diff script for two SRFI-43 vectors that contain strings, and it provides a formatting procedure that can output the text diff hunks in several formats commonly supported by the Unix diff(1) tool.
text diff procedure;
returns a hunk formatter procedure of the specified types; the following formats are supported:
| 'ed | ed(1) script |
| 'normal | normal diff format |
| 'rcs | rcs(1) diff script |
| 'context | context diff format |
converts a list of hunks to a list of s-expressions suitable for input to the apply-patch procedure of the patch egg.
(require-extension npdiff)
(require-extension format-textdiff)
(define t1 (open-input-file "file0"))
(define text1 (read-lines t1))
(define t2 (open-input-file "file1"))
(define text2 (read-lines t2))
(define hunks (textdiff text1 text2 3))
(define format make-format-textdiff)
((format 'ed) (current-output-port) hunks)
((format 'normal) (current-output-port) hunks)
((format 'rcs) (current-output-port) hunks)
((format 'context) (current-output-port) hunks
"file0" "Sun Jun 3 18:28:06 2007"
"file1" "Sun Jun 3 18:28:06 2007")
(require-extension patch)
(define sexp (textdiff->sexp hunks))
(with-input-from-port (open-input-file "file0")
(lambda () (with-output-to-port (open-output-file "file1.new")
(lambda () (apply-patch sexp)))))Copyright 2007 Ivan Raikov. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A full copy of the GPL license can be found at <http://www.gnu.org/licenses/>.