chickadee » format-textdiff

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

format-textdiff

Output text diff scripts in different formats.

Usage

(require-extension format-textdiff)

Documentation

This library defines the textdiff procedure, which produces a diff script for two SRFI-43 vectors containing strings, and provides a formatting procedure for several formats commonly supported by diff(1).

Procedures

textdiff:procedure

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 npdiff library documentation for a detailed description of the HUNK data type.

make-format-textdiff: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

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.

textdiff->sexp:procedure

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.14
Ensure proper test script exit status
1.13
Fixed merging of remove/change hunks in context diff routine [bug reported by Daishi Kato]
1.11
Bug fixes in context format handling and improved test cases
1.9
Adjusted paths of test files in unit tests
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-2011 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/>.

Contents »