[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  stripclr snippet

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: stripclr snippet
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Mon 05 Sep 2005 08:36 PM (UTC)  quote  ]
Message
Zeno: I would personally get the length of the string at the beginning and use that as a reference, e.g. i < len. You have to be very careful when you do things like i++.

It has while str\[i\] == &, i+=2. But, what if the last character is &? You'll end up stepping right over the end of the string ... including the \0 at the end of it.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by halkeye   Canada  (28 posts)  [Biography] bio
Date Mon 05 Sep 2005 07:50 AM (UTC)  quote  ]
Message
Sorry ^^

That was really old code, i write better stuff now :)

Gavin
Dark Warriors - Coder
http://darkwars.wolfpaw.net
telnet://darkwars.wolfpaw.net:4848
[Go to top] top

Posted by Zeno   USA  (2,867 posts)  [Biography] bio   Moderator
Date Mon 05 Sep 2005 07:35 AM (UTC)  quote  ]
Message
Ah yes that explains it, I understand why it crashed now. How would I check it? Something like:
if (text[i++] != '\0')

Should do it?

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Mon 05 Sep 2005 07:31 AM (UTC)  quote  ]
Message
Looks like it barfs when the '&' is at the end of the string and doesn't have a color code following it. The snippet doesn't check for edge cases, which is a big nono. Fixing it is a relatively simple matter of making sure that as you traverse the string, you don't stop over the bounds.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Zeno   USA  (2,867 posts)  [Biography] bio   Moderator
Date Mon 05 Sep 2005 03:48 AM (UTC)  quote  ]
Message
Ugh, I just had a crash with this snippet.
#0  0x008a7402 in __kernel_vsyscall ()
#1  0x00979118 in raise () from /lib/libc.so.6
#2  0x0097a888 in abort () from /lib/libc.so.6
#3  0x009ae22a in __libc_message () from /lib/libc.so.6
#4  0x009b6045 in _int_realloc () from /lib/libc.so.6
#5  0x009b6a30 in realloc () from /lib/libc.so.6
#6  0x080c33bb in stripclr (text=0xbffc5349 "ok ^.^&") at comm.c:4929
#7  0x0804a29f in talk_channel (ch=0x9ca52d8, argument=0xbffc5349 "ok ^.^&", channel=2048, verb=0x81c6563 "clantalk")
    at act_comm.c:425
#8  0x0804b1f4 in do_clantalk (ch=0x9ca52d8, argument=0xbffc5349 "ok ^.^&") at act_comm.c:740
#9  0x080e9ea1 in interpret (ch=0x9ca52d8, argument=0xbffc5349 "ok ^.^&") at interp.c:585
#10 0x080bcb46 in game_loop () at comm.c:1226
#11 0x080bbee7 in main (argc=2, argv=0xbffc68a4) at comm.c:590

frame 6:
(gdb) info local
buf = 0x9f06c68 "ok ^.^ me and take me to the fire u dork"
done = "ok ^.^ me and take me to the fire u dork\000k\000rth\000eak in front of such beauty\000and over the glass to hear him\000third <if any> then I will start placing my rooms/links/names/desc and such", '\0' <repeats 1866 times>
i = 42
j = 40

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Asean Novari   USA  (82 posts)  [Biography] bio
Date Sat 05 Mar 2005 01:22 AM (UTC)  quote  ]
Message
Thanks for that website Greven... works great..



[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Fri 04 Mar 2005 11:18 PM (UTC)  quote  ]

Amended on Fri 04 Mar 2005 11:20 PM (UTC) by Greven

Message
Well, in SWR, for example, on of the problems was when people put colored names to items with the engineering skills. A fix is to do this in do_makecontainer

if ( obj->name )
    STRFREE(obj->name);
obj->name = STRALLOC(stripclr(arg1) );

Now, don't quote me on the exact argument variables since I'm at work, but thats basically how its used.

BTW, Gavin codes on the same mud as me, so I'll let him know and, if possible, see if he can get it updated for gendi's site.


However, I suggest you take a look at this:

http://www.swreality.net/color.htm

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Zeno   USA  (2,867 posts)  [Biography] bio   Moderator
Date Fri 04 Mar 2005 10:33 PM (UTC)  quote  ]
Message
How are you making the object? If you're using colors in the name field, you shouldn't. The name field on objects are the keywords for the object. If you want to use color, use it with the short and long desc. As for the function, something like this can be done:
stripclr( buf );

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Asean Novari   USA  (82 posts)  [Biography] bio
Date Fri 04 Mar 2005 10:17 PM (UTC)  quote  ]
Message
Ok thanks Zeno doing that made it compile without any errors.. but now how do i use it?...

I make an item with color codes in it but it also puts those
color codes in the name where they shouldnt be.. Otherwise
you have to enter the color codes with the name of the item
when you try to do anything with it..



[Go to top] top

Posted by Zeno   USA  (2,867 posts)  [Biography] bio   Moderator
Date Fri 04 Mar 2005 09:51 PM (UTC)  quote  ]
Message
Just add the function at the bottom of any file. Add this at the top of the file:
#include <ctype.h>

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Asean Novari   USA  (82 posts)  [Biography] bio
Date Fri 04 Mar 2005 09:38 PM (UTC)  quote  ]
Message
I have given up with placing it anywhere else other than
Color.c as the other locations give too many errors that I do
not wish to deal with.

Administrator@Home ~/swr1fuss/src
$ make
make -s swreality
  Compiling o/color.o....
color.c: In function `stripclr':
color.c:1454: warning: implicit declaration of function `isspace'
make[1]: *** [o/color.o] Error 1
make: *** [all] Error 2

*snippet placed at end of color.c*

Any help with getting rid of this error would be greatly appreciated..



[Go to top] top

Posted by Zeno   USA  (2,867 posts)  [Biography] bio   Moderator
Date Fri 04 Mar 2005 07:46 PM (UTC)  quote  ]
Message
This'll support Smaug too right? I don't see any SWR specific functions. I've been meaning to make a strclr function.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Fri 04 Mar 2005 07:23 PM (UTC)  quote  ]
Message
If that was the whole file you pasted then you are missing a few things. The include to mud.h is one of them, though it may not be important. Secondly you need:

#include <stdio.h>

As I believe that it is not included in mud.h and it will give you errors such as what you posted. Try throwing that into the top and see how things go.


~Nick Cash
http://www.nick-cash.com
[Go to top] top

Posted by Asean Novari   USA  (82 posts)  [Biography] bio
Date Fri 04 Mar 2005 07:16 PM (UTC)  quote  ]

Amended on Fri 04 Mar 2005 09:39 PM (UTC) by Asean Novari

Message
Where in comm.c do i stick it?.. I put it in in more or less
a random spot in between functions and when i try to make i
get over 4k redundancy warnings for ALL of the different
commands in the game and on top of that i also get alot of
errors..



[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Fri 04 Mar 2005 05:09 PM (UTC)  quote  ]
Message
Interesting random note regarding Firefox and code tags. As I read this thread, the first code block was normal, second small, third normal. As I reply to it, the first and second are small and the third is normal. Very, very weird...

As for the problem, the simplest is to just stick it into comm.c if you don't want to figure out and fix the mistakes.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


4,454 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]