[Include] strlib - String functions!
#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


Messages In This Thread
strlib - String functions! - by Slice - 25.07.2012, 15:09
Re: strlib - String functions! - by FireCat - 25.07.2012, 15:42
Re: strlib - String functions! - by Glint - 25.07.2012, 15:43
Re: strlib - String functions! - by Kar - 25.07.2012, 15:43
Re: strlib - String functions! - by IstuntmanI - 25.07.2012, 18:24
Re: strlib - String functions! - by Lorenc_ - 27.07.2012, 00:41
Re: strlib - String functions! - by noobre - 28.07.2012, 16:35
Re: strlib - String functions! - by Ronaldo_raul™ - 28.07.2012, 17:07
AW: strlib - String functions! - by FufLa - 28.07.2012, 17:16
Re: strlib - String functions! - by [MM]RoXoR[FS] - 30.07.2012, 13:49
Re: strlib - String functions! - by Slice - 30.07.2012, 13:54
Re: strlib - String functions! - by Ronaldo_raul™ - 31.07.2012, 14:49
Re: strlib - String functions! - by Slice - 31.07.2012, 15:11
Re: strlib - String functions! - by Ronaldo_raul™ - 31.07.2012, 15:42
Re: strlib - String functions! - by Niko_boy - 31.07.2012, 16:45
Re: strlib - String functions! - by [KHK]Khalid - 01.08.2012, 10:59
Re: strlib - String functions! - by Slice - 01.08.2012, 11:06
Re: strlib - String functions! - by Amit_B - 01.08.2012, 21:56
Re: strlib - String functions! - by [MM]RoXoR[FS] - 03.08.2012, 09:51
Re: strlib - String functions! - by [MM]RoXoR[FS] - 03.08.2012, 10:15
Re: strlib - String functions! - by Slice - 03.08.2012, 10:43
Re: strlib - String functions! - by Ronaldo_raul™ - 03.08.2012, 11:23
Re: strlib - String functions! - by [MM]RoXoR[FS] - 03.08.2012, 12:53
Re: strlib - String functions! - by [MM]RoXoR[FS] - 03.08.2012, 13:17
Re: strlib - String functions! - by Slice - 03.08.2012, 14:06
Re: strlib - String functions! - by [MM]RoXoR[FS] - 03.08.2012, 15:23
Re: strlib - String functions! - by Bakr - 03.08.2012, 15:42
Re: strlib - String functions! - by Slice - 04.08.2012, 11:46
Re: strlib - String functions! - by milanosie - 08.08.2012, 16:55
Re: strlib - String functions! - by Slice - 08.08.2012, 18:27
Re: strlib - String functions! - by ReVo_ - 08.08.2012, 19:05
Re: strlib - String functions! - by Slice - 09.08.2012, 06:42
Re: strlib - String functions! - by ReVo_ - 09.08.2012, 12:16
Re: strlib - String functions! - by Ballu Miaa - 24.08.2012, 05:01
Re: strlib - String functions! - by MicroD - 24.08.2012, 06:23
Re: strlib - String functions! - by Drake1994 - 27.08.2012, 14:10
Re: strlib - String functions! - by Slice - 30.08.2012, 08:10
Re: strlib - String functions! - by florinadrian96 - 29.05.2013, 13:23
Re: strlib - String functions! - by VeNuZ_ - 21.06.2013, 08:13
Re: strlib - String functions! - by Slice - 21.06.2013, 09:58
Re: strlib - String functions! - by QuaTTrO - 30.09.2013, 15:04
Re: strlib - String functions! - by Slice - 30.09.2013, 15:05
Re: strlib - String functions! - by QuaTTrO - 30.09.2013, 15:10
Re: strlib - String functions! - by Slice - 30.09.2013, 18:47
Re: strlib - String functions! - by QuaTTrO - 01.10.2013, 09:51
Re: strlib - String functions! - by Slice - 01.10.2013, 10:09
Re: strlib - String functions! - by QuaTTrO - 01.10.2013, 10:23
Re: strlib - String functions! - by iZN - 01.10.2013, 16:17
Re: strlib - String functions! - by raider19rus - 05.10.2013, 15:01
Re: strlib - String functions! - by Whitetiger - 21.11.2013, 22:39
Re: strlib - String functions! - by Emmet_ - 21.11.2013, 22:47
Re: strlib - String functions! - by Whitetiger - 22.11.2013, 01:56
Re: strlib - String functions! - by JaKe Elite - 05.12.2014, 09:43
Re: strlib - String functions! - by RedFusion - 08.12.2014, 10:52
Re: strlib - String functions! - by RedFusion - 08.12.2014, 20:54
Re: strlib - String functions! - by 123eee123 - 03.07.2015, 12:05
Re: strlib - String functions! - by Cyber123 - 12.07.2015, 18:20
Re: strlib - String functions! - by MerryDeer - 13.11.2016, 21:16
Re: strlib - String functions! - by YamanSetOG - 23.08.2017, 11:59

Forum Jump:


Users browsing this thread: 14 Guest(s)