| Message |
Minor changes to code are often distributed as "diff" files, which are made by comparing a piece of code before a change to one afterwards.
For example, if I add a line to a file, delete one, and change one, and then do this:
diff fight.c.orig fight.c
I get something like this:
182d181
< ch->fearing->who = victim;
228a228
> // added a comment here
264c264
< do_shout( ch, "Thoric says, 'Prepare for the worst!'" );
---
> do_shout( ch, "Nick says, 'Prepare for the worst!'" );
This is showing that:
- I deleted line 182
- I added something at line 228
- I changed something on line 264
It is a bit easier to see if you do a "context diff" which shows the context of the change:
diff -c fight.c.orig fight.c
*** fight.c.orig 2004-03-04 10:55:00.000000000 +1100
--- fight.c 2004-03-04 10:55:27.000000000 +1100
***************
*** 179,185 ****
CREATE( ch->fearing, HHF_DATA, 1 );
ch->fearing->name = QUICKLINK( victim->name );
- ch->fearing->who = victim;
return;
}
--- 179,184 ----
***************
*** 226,231 ****
--- 225,231 ----
*/
void violence_update( void )
{
+ // added a comment here
char buf[MAX_STRING_LENGTH];
CHAR_DATA *ch;
CHAR_DATA *lst_ch;
***************
*** 261,267 ****
bug( "Short-cutting here", 0 );
ch->prev = NULL;
gch_prev = NULL;
! do_shout( ch, "Thoric says, 'Prepare for the worst!'" );
}
/*
--- 261,267 ----
bug( "Short-cutting here", 0 );
ch->prev = NULL;
gch_prev = NULL;
! do_shout( ch, "Nick says, 'Prepare for the worst!'" );
}
/*
Now you can see the "before" and "after" (in bold). The "+" means "add a line", the "-" means "subtract a line", and the "!" means "change this line".
To use a patch file (diff file) you simply navigate to the directory where your file is (or maybe the parent directory, read the instructions if any), and then type:
patch < diff-file
This runs the patch program, feeding the diffs to it, which it then incorporates into your source.
The nice thing about context diffs is that even if you have added code of your own, it uses the context to try to find the right spot, even if the right spot is now 20 lines further on, or further back. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|