You are looking at historical revision 21877 of this page. It may differ significantly from its current revision.
Output text diff scripts in different formats.
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.
Procedures[procedure] textdiff:: TEXT1 TEXT2 [CONTEXT] -> (HUNK ... )
text diff procedure;
- TEXT1 and TEXT2 are two SRFI-43 vectors that contain strings;
- CONTEXT is an optional number of context lines to be provided with each operation in the diff script See the documentation for the npdiff egg for a detailed description of the HUNK data type.
returns a hunk formatter procedure of the specified types; the following formats are supported:
|'normal||normal diff format|
|'rcs||rcs(1) diff script|
|'context||context diff format|
Each hunk formatter procedure is of the form LAMBDA OUT-PORT HUNK-LIST, except for the context formatter, which is of the form LAMBDA OUT-PORT HUNK-LIST FNAME1 TSTAMP1 FNAME2 TSTAMP2, where the timestamp and filename arguments are strings. Please see the diff(1) manual for a detailed description of each format.[procedure] textdiff->sexp:: (HUNK ... ) -> (SEXP ...)
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)))))
About this egg
- Fixed merging of remove/change hunks in context diff routine [bug reported by Daishi Kato]
- Bug fixes in context format handling and improved test cases
- Adjusted paths of test files in unit tests
- Documentation converted to wiki format
- Some improvements to the test suite
- Ported to Chicken 4
- Build script updated for better cross-platform compatibility
- eggdoc documentation fix
- License upgrade to GPL v3
- Added license text to source files
- Added procedure textdiff->sexp [thanks to Felix for the suggestion]
- Initial release
Copyright 2007-2010 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/>.