How to diff and patch.

diff original-file corrected-file > patch-file
patch original-file patch-file -o output-file

In this example, the result is that "corrected-file" and "output-file" have the same content.

Bonus: here is a way to patch a file from a self-contained shell script:

# Fix: lauxlib.c:577:4: warning: this ‘while’ clause does not guard...
# The intention appears to be to consume input until LUA_SIGNATURE[0]
# is found.
DIFF=$(
cat << 'FFID'
577c577
<    while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
---
>     while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) {;}
FFID
)
echo "$DIFF" | patch -i - lua5.1/src/lauxlib.c

It uses what is called a 'here document'. I save it to a variable for my convenience and then pipe it to "patch". The option "-i -" makes patch read the patch file from stdin.

Here is how to diff and patch an entire directory tree:

diff -ruN original-dir corrected-dir > patch-file
# make sure that the current working directory contains the original-dir,
#then:
patch -s -p0 < patch-file

So, yeah, I did this and it changed my life.