SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 18/05/2013, 09:31 AM   #11
Emmet_
Guest
 
Posts: n/a
Default Re: AW: Re: "stringh.inc": Implementing useful functions from C's "string.h"

Quote:
Originally Posted by Aeonosphere View Post
READ: "a couple of them are just to help people who prefer to program as close to C or C++ as possible."
Obviously you've never used C/C++ before. Besides, as I said, that was in error, I made this at 3AM last night. Just finalising the changes now.
Shit, my bad. I didn't read the post lol

By the way...

pawn Code:
#define chrtolower(%1) \
        (((%1) > 0x40 && (%1) <= 0x5A) ? ((%1) | 0x20) : (%1))
That macro is useless because there's a function included with one of the SA-MP includes by default: tolower (works the same way).
  Reply With Quote
Old 18/05/2013, 09:34 AM   #12
Aeonosphere
Little Clucker
 
Join Date: May 2013
Posts: 17
Reputation: 5
Default Re: AW: Re: "stringh.inc": Implementing useful functions from C's "string.h"

Quote:
Originally Posted by Emmet_ View Post
Shit, my bad. I didn't read the post lol

By the way...

pawn Code:
#define chrtolower(%1) \
        (((%1) > 0x40 && (%1) <= 0x5A) ? ((%1) | 0x20) : (%1))
That macro is useless because there's a function included with one of the SA-MP includes by default: tolower (works the same way).
No problem. I realised about that, I've already removed it, just trying to update a couple of things.
Aeonosphere is offline   Reply With Quote
Old 18/05/2013, 09:46 AM   #13
Aeonosphere
Little Clucker
 
Join Date: May 2013
Posts: 17
Reputation: 5
Default Re: "stringh.inc": Implementing useful functions from C's "string.h"

UPDATED. Check the first post. All the stuff from being tired is fixed. As far as I know in the PAWN pre-processor, you can declare new variables. If that doesn't work, or there's any other bugs, tell me and I'll fix 'em.
Aeonosphere is offline   Reply With Quote
Old 18/05/2013, 11:04 AM   #14
BigETI
High-roller
 
BigETI's Avatar
 
Join Date: Mar 2010
Location: Germany
Posts: 1,051
Reputation: 345
Default AW: "stringh.inc": Implementing useful functions from C's "string.h"

You cannot simply do something like for example
pawn Code:
#define strncpy(%0,%1,%2,%3) \
                        new cchar[] \
                        ;strmid(char,%1,0,((%2)-1)) \
                        ;strdel(char,%2,strlen(char)) \
                        ;strcat((%0[0] = '\0', %0),char,%3)
since macros are basicly text replacements and, if you try to use such macro twice in your script
pawn Code:
public someCallback()
{
    new some_array[4], some_array_2[4];
    strncpy(some_array, "foo", 2, sizeof some_array); // not the same "sizeof" we know from C/C++
    strncpy(some_array_2, "bar", 2, sizeof some_array_2);
}
becomes
pawn Code:
public someCallback()
{
    new some_array[4], some_array_2[4];
    new cchar[];
    strmid(char, "foo",0,(( 2)-1));
    strdel(char, 2,strlen(char));
    strcat((some_array[0] = '\0', some_array),char, sizeof some_array);
    new cchar[];
    strmid(char, "bar",0,(( 2)-1));
    strdel(char, 2,strlen(char));
    strcat((some_array_2[0] = '\0', some_array_2),char, sizeof some_array_2);
}
will give you compiling errors, like that you've not declared the size of a "cchar" array and redeclaration of a "cchar" array.
BigETI is offline   Reply With Quote
Old 18/05/2013, 12:10 PM   #15
Aeonosphere
Little Clucker
 
Join Date: May 2013
Posts: 17
Reputation: 5
Default Re: AW: "stringh.inc": Implementing useful functions from C's "string.h"

Quote:
Originally Posted by BigETI View Post
<snip>
I see. I think I sorted this problem out. This one is better off as a public function. Updated (v0.5) in the first post.

Last edited by Aeonosphere; 18/05/2013 at 01:05 PM.
Aeonosphere is offline   Reply With Quote
Old 18/05/2013, 03:50 PM   #16
BigETI
High-roller
 
BigETI's Avatar
 
Join Date: Mar 2010
Location: Germany
Posts: 1,051
Reputation: 345
Default AW: "stringh.inc": Implementing useful functions from C's "string.h"

Atleast nice effort, but you are allowed to use my "just from scratch recreated" include http://pastebin.com/DMid5gRQ freely, which includes much more functions (macros and stocks), also they almost behave like the ones used for C/C++.
  • __strcat_ as strcat
  • strncat
  • strchr
  • strrchr
  • __strcmp_ as strcmp
  • strncmp
  • strcasecmp
  • strncasecmp
  • strcpy
  • strncpy
  • strpbrk
  • strspn
  • strcspn
  • strstr
  • strcasestr
BigETI is offline   Reply With Quote
Old 18/05/2013, 09:04 PM   #17
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,316
Reputation: 3191
Default Re: "stringh.inc": Implementing useful functions from C's "string.h"

Both those includes have versions of strcpy which look something like the standard strcpy macro used on the forums (leading me to believe you are lying when you say there are no credits), but both broken in some way.
Y_Less is offline   Reply With Quote
Old 18/05/2013, 09:06 PM   #18
BigETI
High-roller
 
BigETI's Avatar
 
Join Date: Mar 2010
Location: Germany
Posts: 1,051
Reputation: 345
Default AW: Re: "stringh.inc": Implementing useful functions from C's "string.h"

Quote:
Originally Posted by Y_Less View Post
Both those includes have versions of strcpy which look something like the standard strcpy macro used on the forums (leading me to believe you are lying when you say there are no credits), but both broken in some way.
I would really like to see the one who made a PAWN version of strcpy before us.
BigETI is offline   Reply With Quote
Old 18/05/2013, 09:13 PM   #19
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,316
Reputation: 3191
Default Re: "stringh.inc": Implementing useful functions from C's "string.h"

OK, how about this post from 2008, with Simon's strcpy added some time in the next few years (probably 2010):

http://forum.sa-mp.com/showthread.php?t=57018

Funny how Simon's is IDENTICAL to the one in the first post, yet there are "no credits required".

And the improved version that has been in y_utils since 08/09/10:

pawn Code:
/**--------------------------------------------------------------------------**\
<summary>strcpy</summary>
<param name="dest">Destination string.</param>
<param name="src">Source string.</param>
<param name="len">(Implicit) maximum length of the destination.</param>
<returns>
    -
</returns>
<remarks>
    -
</remarks>
\**--------------------------------------------------------------------------**/


#define strcpy(%0,%1) \
    strcat((%0[0] = '\0', %0), %1)

That "before" you enough?
Y_Less is offline   Reply With Quote
Old 18/05/2013, 09:23 PM   #20
BigETI
High-roller
 
BigETI's Avatar
 
Join Date: Mar 2010
Location: Germany
Posts: 1,051
Reputation: 345
Default AW: "stringh.inc": Implementing useful functions from C's "string.h"

I just showed an improved version of the main topic's include. I had really no idea who originally made this strcpy macro.
That's why I used to say "both", since I had no idea it exists now for some years. Nice found Y_Less!
BigETI is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error 001: expected token: "-string end-", but found "-identifier-" iGetty Scripting Help 4 15/05/2012 06:39 PM
5 Dialog errors - Input line too long, undefined symbol "t","is" and "only" Deal-or-die Scripting Help 6 01/05/2012 01:08 PM
error 001: expected token: "-string end-", but found "-identifier-" Any Ideas? Jack_Rocker Scripting Help 5 04/11/2011 02:03 PM


All times are GMT. The time now is 06:31 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.