((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/patch" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (tags "egg")) (section 2 "patch" (toc) (p "Simple source patch utility.")) (section 2 "Documentation" (p "This is a simple source patch utility to enable production and application of patches to source files on any platform that supports Chicken.") (p "The procedure " (tt "make-patch") " takes a GNU-style diff file on " (tt "(current-input-port)") " and produces a corresponding s-expression that can be used by the procedure " (tt "apply-patch") ".") (p "In its turn, the " (tt "apply-patch") " procedure takes a patch definition and applies it to the input stream on " (tt "(current-input-port)") ", writing the result to " (tt "(current-output-port)") ".") (p "The procedure " (tt "reverse-patch") " transforms a patch definition into its reverse, so that the original patch can be undone.") (p "It is recommended that make-patch be used to produce patches for distribution.  These patches can then be interpreted and applied by the apply-patch procedure, which has no machine or system dependencies beyond the posix package.  The third example above also illustrates operation similar to the Larry Wall/Paul Eggert " (tt "patch") " program, accepting as input a patch in the form of raw GNU diff file output.") (section 3 "S-expression format" (p "The patch definition is composed of a list of forms of the following format:") (pre "([c|a|d] start-line finish-line new-start-line new-finish-line (lines to be deleted) (lines to be inserted))") (p "The forms " (tt "c") ", " (tt "a") " and " (tt "d") " correspond to the change, append and delete commands in default GNU diff output.  Where one of the line number parameters is omitted in the diff file, this is translated to " (tt "#f") " in the corresponding form in the patch definition.  The lists " (tt "lines to be deleted") " and " (tt "lines to be inserted") " are ordered lists of strings.") (p "Reversing the patch is a straightforward swap: swap the " (tt "a") " and " (tt "d") " commands, swap the " (tt "start-line, finish-line") " pair with " (tt "new-start-line") " and " (tt "new-finish-line") ", and swap the " (tt "lines to be deleted") " and " (tt "lines to be inserted") " lists.")) (section 3 "Procedures" (def (sig (procedure "(make-patch)" (id make-patch))) (p "Read GNU diff output on " (tt "(current-input-port)") " and return a patch definition.")) (def (sig (procedure "(apply-patch PATCH-DEFINITION)" (id apply-patch))) (p "Apply a patch definition to the text stream on " (tt "(standard-input-port)") " and write the result to " (tt "(current-output-port)") ".") (dl (dt (tt "PATCH-DEFINITION")) (dd "A patch definition produced by " (tt "make-patch")))) (def (sig (procedure "(reverse-patch PATCH-DEFINITION)" (id reverse-patch))) (p "Produce a patch definition that undoes the patch definition given.")))) (section 2 "Examples" (pre "; To write a patch from GNU diff output on (current-input-port):\n(use patch)\n(write (make-patch))(newline)\n\n; To apply a patch in a filename argument to (current-input-port)\n; and write the result to (current-output-port):\n(use patch)\n(apply-patch (with-input-from-file (cadr (argv)) read))\n\n; To apply a patch in a GNU diff file in a filename argument\n(use patch)\n(apply-patch (with-input-from-file (cadr (argv)) make-patch))\n\n; To undo a patch in a filename argument, reading the result of applying\n; the patch on (current-input-port) and writing the restored original to\n; (current-output-port)\n(use patch)\n(apply-patch (reverse-patch (with-input-from-file (cadr (argv)) read)))")) (section 2 "Bugs and limitations" (p "This simple utility cannot handle files that have no line terminator at the end of the last line.  " (tt "make-patch") " will barf on the diff input in such cases.  It shouldn't be too difficult to write a special case for this, but an absent line terminator in a text file is usually an error or an oversight, so a conscious decision has been made not to cater for it.  Feel free to fix this bug.") (p "No effort has been made to duplicate the extreme versatility of the Wall/Eggert patch utility.  In particular, any noise in the raw diff input will cause make-patch to barf.")) (section 2 "About this egg" (section 3 "Author" (p (int-link "/users/tony sidaway" "Tony Sidaway"))) (section 3 "Version history" (dl (dt "1.14") (dd "Fix for botched conversion to regex egg [Ivan Raikov]") (dt "1.13") (dd "Added regex as a dependency; ported eggdoc documentation to wiki format [Ivan Raikov] ") (dt "0.12") (dd "Ported to Chicken 4 [Ivan Raikov]") (dt "0.11") (dd "Bug 308: does not require '(needs posix)'") (dt "0.1") (dd "Initial release"))) (section 3 "License" (pre "Copyright (c) Tony Sidaway <tonysidaway@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\nBE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\nACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE."))))