The Dawn Of Time
The Official Forums for the Dawn Of Time Mud Codebase
 
Log in Register FAQ Memberlist Search The Dawn Of Time Forum Index Goto the Official Dawn Website

Grep, a walkthrough on searching

 
Post new topic   Reply to topic    The Dawn Of Time Forum Index » Helpfiles
View previous topic :: View next topic  
Author Message
Archiel
Moderator


Joined: 05 Feb 2003
Posts: 386
Location: Minnesota, USA

PostPosted: Wed Jan 28, 2004 6:14 am    Post subject: Grep, a walkthrough on searching Reply with quote

Hey everyone,
I'm just writing a short file on using grep. Grep is a command line utility hopefully found in every distribution of *nix. It will forever be your best friend. With this tool, you can search through many files at a time for phrases and more.

Let's say your playing your mud and you cast create rose:
Dawn Output:
You create a beautiful red rose.


Not to shabby.. but what if you want it to say something cooler... like You draw power from the air and a beautiful red rose materializes.
Definately better. Now... where the heck is the spell create rose? I sure don't know.

So, just wander over to your shell, cd into your dawn directory, then cd src. Now you'll be in a directory with a whole mess of .cpp and .h files. (check by typing ls if you don't believe me)

Now, we're here because we figured the spells got to be in the code somewhere. Now type:
Code:

grep "You create a beautiful red rose." *

This tells the computer to grep (do a search) for the string that is in quotes in all files. The * matches everything, hence all files. You could check just the files that end in .cpp by doing
Code:

grep "You create a beautiful red rose." *.cpp

Or even the files that start with a d and end in .cpp: d*.cpp But anyway you should see:
Code:

[Yourname@yourhost src]$ grep "You create a beautiful red rose." *
magic.cpp:              ch->println( "You create a beautiful red rose." );
[Yourname@ yourhost src]$

Cool, it's in magic.cpp and it even tells you the whole line, so you can see if it's the right thing. So, edit that file with your favorite editor.
If you don't have a favorite, type pico magic.cpp
Then search by typing (if you use pico) Control-W and type beautiful red rose, or something...

The associated code is:
Code:

/**************************************************************************/
SPRESULT spell_create_rose( int , int , char_data *ch, void *,int  )
{
        OBJ_DATA *rose;
        if (get_obj_index(OBJ_VNUM_ROSE)) {
                rose = create_object(get_obj_index(OBJ_VNUM_ROSE));
                act("$n has created a beautiful red rose.",ch,rose,NULL,TO_ROOM);
                ch->println( "You create a beautiful red rose." );
                obj_to_char(rose,ch);
        }else{
        ch->println( "BUG: No available rose object in spell_create_rose - please report!" );
                return NO_MANA;
        }

        return FULL_MANA;
}


There's actually two lines you could change here:
act("$n has created a beautiful red rose.",ch,rose,NULL,TO_ROOM);
ch->println( "You create a beautiful red rose." );

The $n will be replaced with the character's name, hence the ch after the text. Change it to something else.

Now, exit your editor after saving, and type make. When you hotreboot or restart your mud, you'll see the new spell!

All thanks to the power of grep! I hope this was helpful. It's great to see what you need to change when your adding a skill. When I added fishing to our mud, I just did grep forage * and duplicated every time i saw forage and changed it to fishing. It's a good start.

Archiel
Realms of Aloreth


Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
grimnard



Joined: 28 Jul 2003
Posts: 189
Location: Ohio, USA

PostPosted: Wed Jan 28, 2004 8:59 am    Post subject: Reply with quote

very helpful post(i dont use grep i have all my code on my computer and use serch for it) but im sure there are many people that have wondered how to do it

also on a side note cause i dont have MSVC++(cant afford it) i went out looking for something to help code in and this is not exactly a great program but it has some nice features for codeing and its totally free its
microsoft eMbedded Visual C++ v4.0 i find it nifty help with making sure i close all my brackets and a few toehr things you can get it here(also has a grep type feature for serching your files)[url]
http://www.microsoft.com/downloads/release.asp?ReleaseID=37662&area=search&ordinal=3[/url]

thanks for the help

grimnard



_________________
See you all on the flip side...
Back to top
View user's profile Send private message
Archiel
Moderator


Joined: 05 Feb 2003
Posts: 386
Location: Minnesota, USA

PostPosted: Wed Jan 28, 2004 12:06 pm    Post subject: Reply with quote

Ah yeah.

I have Mac OS on my computer, so I use grep all the time since it's built in. Windows people and cygwin users will have to go with somethink like what Grimanrd mentioned.

To edit text I use the free software, BBEdit Lite 6.1. Unfortunately, when they moved to version 7, they stopped offering a free version and only a 30 day demo. I guess version 7 has FTP/SFTP and CVS support and all kinds of great stuff. It's probably not 179.99 USD great.... Good luck finding an archive of the free versions...

OS X comes with an integrated developers environment (IDE) for C++ too, but i don't use that. It's editor should be pretty good.


Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Kewlage



Joined: 18 Feb 2004
Posts: 52
Location: Albuquerque, NM

PostPosted: Wed Feb 18, 2004 5:06 pm    Post subject: re:grep Reply with quote

a couple other handy things about grep...

-i means to ignore case, otherwise, the search will be case sensitive...
-n means to show line numbers of the results...

example
grep -i "a red rose" *.cpp *.h
this will find "A Red Rose" or "a rEd rOSE" (etc) within all of the cpp (code files) and h files (header files)

grep -n "a red rose" *
this will find only "a red rose" (not "A Red Rose" etc), within any file in that directory, and it will return the line number of the hit

grep -in "a red rose" *.cpp
this will find any version of "a red rose", no matter the capitalization, within only the code files, and also return the line numbers of the hits.

hope this helps
--Kewlage



_________________
Stalk lithely and wary the big thicket.

Founder: AnomicMUD (in beta)
telnet://anomic.slayn.net:7777
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Sarolite



Joined: 31 Jan 2003
Posts: 149
Location: California, USA

PostPosted: Thu Feb 19, 2004 10:23 am    Post subject: Reply with quote

Had read this post before without looking at names. Just realized the author now. Archiel, you're awesome! Smile


Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    The Dawn Of Time Forum Index » Helpfiles All times are GMT + 13 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001-2005 phpBB Group
Theme created by Vjacheslav Trushkin