You are looking at historical revision 20180 of this page. It may differ significantly from its current revision.

format-textdiff

Output text diff scripts in different formats.

Usage

(require-extension format-textdiff)

Documentation

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;

[procedure] make-format-textdiff:: TYPE -> FORMAT-PROC

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

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.

Examples

(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

Author

Ivan Raikov

Version history

1.8
Documentation converted to wiki format
1.7
Some improvements to the test suite
1.6
Ported to Chicken 4
1.5
Build script updated for better cross-platform compatibility
1.4
eggdoc documentation fix
1.3
License upgrade to GPL v3
1.2
Added license text to source files
1.1
Added procedure textdiff->sexp [thanks to Felix for the suggestion]
1.0
Initial release

License

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/>.