[Include] strlib - String functions!
#41

This include is crashing my compiler. I have no idea why.
Reply
#42

What other includes do you use?
Reply
#43

Quote:
Originally Posted by Slice
Посмотреть сообщение
What other includes do you use?
I also tried to include strlib in bare gamemode and it also crash the compiler. In my gamemode i use: y_ini, foreach, sscanf2, rcmd, lookup, gvar, mselection, filemanager.
Reply
#44

In which order did you include them? Copy & paste the #include stuff.
Reply
#45

Quote:
Originally Posted by Slice
Посмотреть сообщение
In which order did you include them? Copy & paste the #include stuff.
pawn Код:
#include <a_samp>
#include <a_mysql>
#include <a_http>

#include <y_ini>
#include <foreach>
#include <sscanf2>
#include <rcmd>
#include <lookup>
#include <gvar>
#include <mselection>
#include <filemanager>
#include <strlib>
Here are problem details:
Код:
Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	pawncc.exe
  Application Version:	3.2.3664.0
  Application Timestamp:	4655bfe0
  Fault Module Name:	PAWNC.dll
  Fault Module Version: 	3.2.3664.0
  Fault Module Timestamp:	4655bfdf
  Exception Code:	c0000005
  Exception Offset: 	000119ec
  OS Version:	6.1.7601.2.1.0.256.1
  Locale ID: 	1045
  Additional Information 1: 	0a9e
  Additional Information 2: 	0a9e372d3b4ad19135b953a78882e789
  Additional Information 3: 	0a9e
  Additional Information 4: 	0a9e372d3b4ad19135b953a78882e789
Reply
#46

Try including strlib first
Reply
#47

Quote:
Originally Posted by Slice
Посмотреть сообщение
Try including strlib first
Did it, still crashing. Also wierd thing: when i paste this at the end of gamemode:
pawn Код:
#if !defined STRLIB_USE_FORMATEX
    #if defined __fmt_funcinc
        #if !defined FormatSpecifier
            #error Please include formatex before strlib.
        #endif

        #define STRLIB_USE_FORMATEX  true
    #else
        #define STRLIB_USE_FORMATEX  false
    #endif
#endif

stock sprintf(const fmat[], {Float, _}:...) {
    static output[200], frm_header[3], heap;

    const output_size = sizeof(output);

    if (ispacked(fmat)) {
        heap = CopyArgumentToHeap(0);
    } else {
        heap = 0;
    }{}

    // Store current frame header
    #emit LCTRL      5
    #emit CONST.alt  frm_header
    #emit MOVS       12

    // Change the stack pointer to FRM + 12
    #emit ADD.C    12 // pri is FRM (see above)
    #emit SCTRL    4

    // Push sizeof(output)
    #emit PUSH.C      output_size

    // Push output
    #emit PUSH.C      output

    // Push the argument count
    #emit LOAD.S.pri  8
    #emit ADD.C       8
    #emit PUSH.pri

    #if !STRLIB_USE_FORMATEX
        const formatex = 0; // Dummy used to avoid "unknown symbol" error

        goto do_sysreq;
    #endif

    // Call formatex (unless this was skipped above)
    #emit LCTRL       6
    #emit ADD.C       36
    #emit PUSH.pri
    #emit CONST.pri   formatex
    #emit SCTRL       6

    #if !STRLIB_USE_FORMATEX
        do_sysreq:
    #endif

    // Call format (unless formatex was called, in which case this is skipped)
    #emit SYSREQ.C    format

    // Restore the stack pointer to FRM
    #emit LCTRL       5
    #emit SCTRL       4

    // Copy back the frame header
    #emit MOVE.alt
    #emit CONST.pri   frm_header
    #emit MOVS        12

    // Restore heap if needed
    if (heap) {
        RestoreHeapToAddress(heap);
    }{}

    // IMPORTANT: Fix compiler bug (returning strings in variadic functions)
    #emit LOAD.S.pri  8
    #emit ADD.C       12
    #emit MOVE.alt
    #emit LCTRL       5
    #emit ADD
    #emit LOAD.I
    #emit STOR.S.pri  20 // 16 + (static_args * 4)

    return output;

    // It is actually used, just not by its symbol name
    #pragma unused fmat
}

static stock CopyArgumentToHeap(arg, bool:pack = false, const argptr[] = "") {
    new arg_address, address;

    #emit LOAD.S.pri  0
    #emit ADD.C       12
    #emit LOAD.S.alt  arg
    #emit SHL.C.alt   2
    #emit ADD
    #emit LOAD.I
    #emit STOR.S.pri  arg_address
    #emit STOR.S.pri  argptr

    if (pack) {
        new bytes = ((strlen(argptr) + 1 + 3) / 4) * 4;

        #emit LCTRL       2
        #emit STOR.S.pri  address
        #emit LOAD.S.alt  bytes
        #emit ADD
        #emit SCTRL       2

        //strpack(dest[], const source[], maxlength = sizeof dest)
        #emit LOAD.S.pri  bytes
        #emit SHR.C.pri   2
        #emit PUSH.pri

        #emit PUSH.S      arg_address
        #emit PUSH.S      address

        #emit PUSH.C      12

        #emit SYSREQ.C    strpack
        #emit STACK       16
    } else {
        new bytes = (strlen(argptr) + 1) * 4;

        #emit LCTRL       2
        #emit STOR.S.pri  address
        #emit LOAD.S.alt  bytes
        #emit ADD
        #emit SCTRL       2

        //strunpack(dest[], const source[], maxlength = sizeof dest)
        #emit LOAD.S.pri  bytes
        #emit SHR.C.pri   2
        #emit PUSH.pri

        #emit PUSH.S      arg_address
        #emit PUSH.S      address

        #emit PUSH.C      12

        #emit SYSREQ.C    strunpack
        #emit STACK       16
    }

    #emit LOAD.S.pri  0
    #emit ADD.C       12
    #emit LOAD.S.alt  arg
    #emit SHL.C.alt   2
    #emit ADD
    #emit MOVE.alt
    #emit LOAD.S.pri  address
    #emit STOR.I

    return address;
}

static stock RestoreHeapToAddress(address) {
    #emit LOAD.S.pri  address
    #emit SCTRL       2
}
The compiler don't crash and the sprintf function is working fine. Also tried to include strlib at the end of gamemode but i didnt worked.


EDIT: redownloaded whole include again, and it's working! Thank you Slice for this include and help
Reply
#48

Great work Slice.
Reply
#49

Nice job. Thanks!
Reply
#50

str_pad like it is in PHP would be so helpful, and nice in this library
Reply
#51

Gonna use this for my GM, thanks!

I got a shitload of awesome string functions somewhere on my PC that I made like 3 months ago, I'll find and optimize them and then Emmet shall contribute.

Quote:
Originally Posted by Whitetiger
Посмотреть сообщение
str_pad like it is in PHP would be so helpful, and nice in this library
I think there is already.

EDIT: I didn't see it. I'm very sure I used strlib a while back and there was a string padding function. Weird.. lol

EDIT 2: Yeah, there is in the script, strpad. Not documented on the first page though.
Reply
#52

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
Yeah, there is in the script, strpad. Not documented on the first page though.
shit, didn't notice, thanks!
Reply
#53

I love it, Sweet and useful, Thanks bud.
Reply
#54

I just made this IP String to IP Bytes Function with this string library.
pawn Код:
GetIPBytes(const ip_input[], ip_output[])
{
    new octet_string[4][4],
        octet_count = strexplode(octet_string, ip_input, ".");
    for(new i; i < octet_count; i ++)
        ip_output{i} = strval(octet_string[i]);
    return octet_count;
}
Example Usage:
pawn Код:
#include <a_samp>
#include <strlib>

new bool: g_PlayerAdmin [MAX_PLAYERS char];

public OnPlayerConnect(playerid)
{
    new ip_string[16],
        ip_bytes[4 char];

    GetPlayerIp(playerid, ip_string, sizeof ip_string);
    GetIPBytes(ip_string, ip_bytes);
    g_PlayerAdmin{playerid} = (ip_bytes{0} == 127 && ip_bytes{1} == 0 && ip_bytes{2} == 0 && ip_bytes{3} == 1) ? (true) : (false);
}
Reply
#55

edit: doublepost
Reply
#56

Nice
Reply
#57

Is this better then string.inc ??
Reply
#58

how with euro sign?
Reply
#59

How to download it? i cant download
Reply


Forum Jump:


Users browsing this thread: 8 Guest(s)