• Welcome to Theos PowerBasic Museum 2017.

Recent posts

#61
Discussion / Re: REPLACE
Last post by Patrice Terrier - May 23, 2017, 03:35:53 PM
Thank you!

However i couldn't get this replace code to work by me

WCHAR* _tcsstr_(WCHAR* String, WCHAR* Pattern) {
    int   mi = -1;
    while(Pattern[++mi]) {
        if(String[mi] == 0) return 0;
        if(String[mi] != Pattern[mi])
        {
            String++;
            mi = -1;
        }
    }
    return String;
}

#ifndef BCXTmpStrSize
#define BCXTmpStrSize  2048
#endif
WCHAR *BCX_TmpStr (size_t Bites, size_t  iPad, int iAlloc)
{
    static int   StrCnt;
    static WCHAR *StrFunc[BCXTmpStrSize];
    StrCnt = (StrCnt + 1) & (BCXTmpStrSize - 1);
    if(StrFunc[StrCnt]) {
        free (StrFunc[StrCnt]);
        StrFunc[StrCnt] = NULL;
    }
#if defined BCX_MAX_VAR_SIZE
    if(Bites * sizeof(_TCHAR) > BCX_MAX_VAR_SIZE)
    {
        _tprintf(_T("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\n"), (int)(Bites * sizeof(_TCHAR)), BCX_MAX_VAR_SIZE);
        abort();
    }
#endif
    if(iAlloc) StrFunc[StrCnt] = (WCHAR*)calloc(Bites + iPad + 1, sizeof(WCHAR));
    return StrFunc[StrCnt];
}


WCHAR *replace (const WCHAR *src, const WCHAR *pat, const WCHAR *rep)
{
    size_t patsz, repsz, tmpsz, delta;
    WCHAR *strtmp, *p, *q, *r;
    if (!pat || !*pat)
    {
        strtmp = BCX_TmpStr(wcslen(src), 1, 1);
        if (!strtmp) return NULL;
        return wcscpy(strtmp, src);
    }
    repsz = wcslen(rep);
    patsz = wcslen(pat);
    for (tmpsz = 0, p = (WCHAR*)src; (q = _tcsstr_(p, (WCHAR*)pat)) != 0; p = q + patsz)
        tmpsz += (size_t) (q - p) + repsz;
    tmpsz += wcslen(p);
    strtmp = BCX_TmpStr(tmpsz, 1, 1);
    if (!strtmp) return NULL;
    for (r = strtmp, p = (WCHAR*)src; (q = _tcsstr_(p, (WCHAR*)pat)) != 0; p = q + patsz)
    {
        delta = (size_t) (q - p);
        CopyMemory(r, p, delta);
        r += delta;
        wcscpy(r, rep);
        r += repsz;
    }
    wcscpy(r, p);
    return strtmp;
}
#62
Discussion / Re: REPLACE
Last post by James C. Fuller - May 23, 2017, 12:26:15 PM
Patrice,
  This is  bc9Basic's REPLACE x WITH y IN z implementation code

$CPP
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER_VC.TXT"
$ONEXIT "TCLIB.BAT $FILE$"         
'==============================================================================
Dim a$
a$ = "I Want To Go Here And Here And Here And Here And Here!"
REPLACE "Here"  With  "There" In a$
PRINT a$
Pause
'==============================================================================


produces this c++ code.
Remember the process I use with bc9Basic is all code is ansi, but is then run through the ULEX
utility to produce unicode.

// *********************************************************************
//  Created with bc9Basic - BASIC To C/C++ Translator (V) 9.2.7.0 (2017/03/31)
//       The bc9Basic translator (bc9.exe) was compiled with
//                           g++ (tdm64-1) 5.1.0
// ----------------------------------------------------------------------
//                 BCX (c) 1999 - 2009 by Kevin Diggins
// *********************************************************************
//              Translated for compiling with the
//           Microsoft (R) C/C++ Optimizing Compiler
//                           On MS Windows
//                    Using TCLib by Fred Harris
// *********************************************************************
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#define _X(y) y
#include <windows.h>
#define   x64
#include "TCLib\stdio.h"
#include "TCLib\string.h"
#include "TCLib\stdlib.h"
#include "TCLib\memory.h"
#include "TCLib\malloc.h"
#include "TCLib\math.h"
#include "TCLib\tchar.h"
#include "TCLib\Strings.cpp"
typedef String fstring;
FILE* stdin;
FILE* stdout;
FILE* stderr;
//<---UNICODE AWARE
#define SFMT (const char*)"%s\r\n"
//>---UNICODE AWARE

// NO HEADERS START
#ifndef _WINDOWS_
//<---UNICODE AWARE
typedef _TCHAR *PCHAR, *LPCH, *PCH, *NPSTR, *LPSTR, *PSTR;
typedef unsigned long DWORD, *PDWORD, *LPDWORD;
typedef unsigned int UINT;
//>---UNICODE AWARE
#endif
// NO HEADERS END

// ***************************************************
// Compiler Defines
// ***************************************************

// C++
#if defined( __cplusplus )
#define overloaded
#define C_EXPORT EXTERN_C __declspec(dllexport)
#define C_IMPORT EXTERN_C __declspec(dllimport)
#define BEGIN_EXTERN_C        extern _T("C") {
#define END_EXTERN_C        }
#else
#define C_EXPORT __declspec(dllexport)
#define C_IMPORT __declspec(dllimport)
#endif


// Microsoft VC++
#ifndef DECLSPEC_UUID
#if (_MSC_VER >= 1100) && defined ( __cplusplus )
#define DECLSPEC_UUID(x)    __declspec(uuid(x))
#else
#define DECLSPEC_UUID(x)
#endif
#endif

// ***************************************************
// Compiler Defines
// ***************************************************
#ifndef __cplusplus
#error A C++ compiler is required
#endif

// *************************************************
//        User's GLOBAL ENUM blocks
// *************************************************

// *************************************************
//            System Defined Constants
// *************************************************

typedef const _TCHAR* ccptr;
#define CCPTR const _TCHAR*
#define cfree free
//<---UNICODE AWARE
typedef char _char;
#define _strlen strlen
//>---UNICODE AWARE
#define EQU ==
#define NOT_USED(x) if(x);
#define CTLHNDL(id) GetDlgItem(hWnd,id)
_TCHAR   *g_cptr_;  // dummy var for not used returns
unsigned int  g_dum1_;  // dummy var for not used returns
int g_dum_int;        // dummy int var for not used returns
#define cSizeOfDefaultString 2048

// *************************************************
//            User Defined Constants
// *************************************************


// *************************************************
//               Standard Prototypes
// *************************************************

_TCHAR*   BCX_TmpStr(size_t, size_t = 0, int = 1);
_TCHAR*   replace (const _TCHAR*, const _TCHAR*, const _TCHAR*);
_TCHAR    *_tcsstr_(_TCHAR*, _TCHAR*);
void    Pause (void);

// *************************************************
//                System Variables
// *************************************************

// *************************************************
//          User Defined Types, Unions and Classes
// *************************************************


// *************************************************
//            User Global Variables
// *************************************************

static _TCHAR    a[cSizeOfDefaultString];


// *************************************************
//            User Global Initialized Arrays
// *************************************************



// *************************************************
//                 Runtime Functions
// *************************************************

#ifndef BCXTmpStrSize
#define BCXTmpStrSize  2048
#endif
_TCHAR *BCX_TmpStr (size_t Bites, size_t  iPad, int iAlloc)
{
    static int   StrCnt;
    static _TCHAR *StrFunc[BCXTmpStrSize];
    StrCnt = (StrCnt + 1) & (BCXTmpStrSize - 1);
    if(StrFunc[StrCnt]) {
        free (StrFunc[StrCnt]);
        StrFunc[StrCnt] = NULL;
    }
#if defined BCX_MAX_VAR_SIZE
    if(Bites * sizeof(_TCHAR) > BCX_MAX_VAR_SIZE)
    {
        _tprintf(_T("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\n"), (int)(Bites * sizeof(_TCHAR)), BCX_MAX_VAR_SIZE);
        abort();
    }
#endif
    if(iAlloc) StrFunc[StrCnt] = (_TCHAR*)calloc(Bites + iPad + 1, sizeof(_TCHAR));
    return StrFunc[StrCnt];
}


_TCHAR *replace (const _TCHAR *src, const _TCHAR *pat, const _TCHAR *rep)
{
    size_t patsz, repsz, tmpsz, delta;
    _TCHAR *strtmp, *p, *q, *r;
    if (!pat || !*pat)
    {
        strtmp = BCX_TmpStr(_tcslen(src), 1, 1);
        if (!strtmp) return NULL;
        return _tcscpy(strtmp, src);
    }
    repsz = _tcslen(rep);
    patsz = _tcslen(pat);
    for (tmpsz = 0, p = (_TCHAR*)src; (q = _tcsstr_(p, (_TCHAR*)pat)) != 0; p = q + patsz)
        tmpsz += (size_t) (q - p) + repsz;
    tmpsz += _tcslen(p);
    strtmp = BCX_TmpStr(tmpsz, 1, 1);
    if (!strtmp) return NULL;
    for (r = strtmp, p = (_TCHAR*)src; (q = _tcsstr_(p, (_TCHAR*)pat)) != 0; p = q + patsz)
    {
        delta = (size_t) (q - p);
        wmemcpy(r, p, delta);
        r += delta;
        _tcscpy(r, rep);
        r += repsz;
    }
    _tcscpy(r, p);
    return strtmp;
}


void Pause(void)
{
    _tprintf(_T("\n%ls\n"), _T("Press any key to continue..."));
    _getwch();
}


_TCHAR *_tcsstr_(_TCHAR *String, _TCHAR *Pattern)
{
    int   mi = -1;
    while(Pattern[++mi])
    {
        if(String[mi] == 0) return 0;
        if(String[mi] != Pattern[mi])
        {
            String++;
            mi = -1;
        }
    }
    return String;
}



// *************************************************
//       User Subs, Functions and Class Methods
// *************************************************

// *************************************************
//                  Main Program
// *************************************************

int _tmain(int argc, _TCHAR *argv[])
{
    _tcscpy(a, _T("I Want To Go Here And Here And Here And Here And Here!"));
    _tcscpy(a, replace(a, _T("Here"), _T("There")));
    _tprintf(_T("%ls\n"), a);
    Pause();
    return 0;   /* End of _tmain program */
}


James
#63
Discussion / REPLACE
Last post by Patrice Terrier - May 23, 2017, 09:32:04 AM
James

Do you have a BC9 example showing how the PB's REPLACE statement is translated to WCHAR ?
#64
Of The Bay / Of The Bay (version 3.00)
Last post by Patrice Terrier - May 09, 2017, 07:05:44 PM
Of The Bay version 3.00

is available from this link:
http://www.objreader.com/index.php?topic=95.msg659#msg659


New in this version:

- The CPU footprint is now very low.
- Support for .URL short cut.
- Code clean up, and optimization.

...
#65
Addon tools for PB / Re: zTrace 1.52 (debugging uti...
Last post by Patrice Terrier - May 03, 2017, 08:12:24 PM
Emil

zTrace is totaly independent from the compiler, it is a standalone DLL.
It has been inspired by the WinDev Trace API.

...
#66
Addon tools for PB / Re: zTrace 1.52 (debugging uti...
Last post by Patrice Terrier - May 03, 2017, 02:13:53 PM
No, it is not, you just have to remember to uncheck the menu option, once you are done, if you don't want it for the next session.

Or feel free to customize the source code to match your preference ;)

...
#67
Addon tools for PB / Re: zTrace 1.52 (debugging uti...
Last post by James C. Fuller - May 03, 2017, 11:56:07 AM
Patrice,
  I reverted back to an older version.
The debug.txt output was persistent once set and I often parse the output so I don't want a BOM.

James
#68
Addon tools for PB / Re: zTrace 1.52 (debugging uti...
Last post by Patrice Terrier - May 03, 2017, 10:18:35 AM
George--

Thank you.

The current version of zTrace is able to write to zdebug.txt directly from the contextual popup menu.

PBwin 10, now doesn't compile unused code anymore.
Thus using explicit linking rather than implicit is another solution,
and this is what i am using with the 64-bit version (explicit call is the same for PB) :

long zTrace(IN WCHAR* sPtr) {
    long nRet = 0;
    static HMODULE hDll;
    if (hDll == 0) {
        if (sizeof(LONG_PTR) == 8) {
            hDll = LoadLibrary(L"zTrace64");
        }
        else {
            hDll = LoadLibrary(L"zTrace32");
        }
    }
    if (hDll) {
        long_proc(WCHAR*);
        static zProc hProc;
        if (hProc == 0) { hProc = (zProc)GetProcAddress(hDll, "zTrace"); }
        if (hProc) { nRet = hProc(sPtr); }
    }
    return nRet;
}


The C++ 64-bit DLL version is only 11 Kb in size, it can create ANSI or UNICODE debug file.
In case of ANSI, a UTF-8 BOM header is now being used
this version can be downloaded from www.codeproject.com or from my private forum www.objreader.com
https://www.codeproject.com/Articles/1183063/zTrace-for-bit-only

#69
Addon tools for PB / Re: zTrace 1.52 (debugging uti...
Last post by George Bleck - May 02, 2017, 10:05:08 PM
I absolutely love having zTrace in my toolbox and wanted to give back a slight "helper" that I use with it.

#IF NOT %DEF( %zTrace )
    %zTrace = 0
#ENDIF

#IF %zTrace = 0
    MACRO zTrace = #UTILITY
    MACRO zDebug = #UTILITY
#ELSE
    DECLARE FUNCTION zTraceX LIB "zTrace.DLL" ALIAS "zTrace" ( zMessage AS ASCIIZ ) AS LONG
    DECLARE FUNCTION zDebugX LIB "zTrace.DLL" ALIAS "zDebug" ( zMessage AS ASCIIZ ) AS LONG
    #IF %zTrace > 0
        MACRO zTrace = zTraceX
        MACRO zDebug = zDebugX
    #ELSE
        MACRO zTrace = zDebugX
        MACRO zDebug = zDebugX
    #ENDIF
#ENDIF


This slight mod allows you to leave zTrace code in and never have to remove it.  PLUS it adds some flexibility to the output path.


       
  • If %zTrace is defined as a positive number, zTrace and zDebug work exactly as expected.
  • If %zTrace is defined as a negative number, zTrace and zDebug both act like zDebug and send to zDebug.txt (allows you to easily switch to "silent" debugging).
  • If %zTrace is 0, not defined,  or REM'd out, then all zTrace/zDebug lines are compiled as #UTILITY commands, in other words, they are ignored by the compiler.
This allows you to easily include copious real-time logging in your code as well as switch the output (or remove logging completely) with a single constant change.
#70
Windows API Programming / Re: Old program - SE_Engine
Last post by Zlatko Vid - April 28, 2017, 07:40:59 PM
Hi Vega
Yes now work...
so i will study this more..but some things loks overcomplicated without reason.
anyway...thanks again :)