Scan code

Posted by Lumpei on Wed 03 Mar 2004 11:29 PM — 2 posts, 12,418 views.

#0
Greetings, All!

First of all, I am a complete neophyte to all this but very excited about hosting my own mud.

I am running the w32 version of Rom 2.4 on XP, and i am interested in learning how to add code now. i just downloaded Erwin Andreasen's code for 'scan' and, well, i haven't the faintest idea of how to implement it. The hypercube faq mentions running a patch command, to which i reply, 'huh?'

Oh, i also compiled this and am running it on cygwin.

So, please pardon how green I am and if anyone has info to help me, that would be great! I am not interested in writing my own code (yet), just learning how to patch it.

Peace, y'all!

Lumpei
Australia Forum Administrator #1
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.