Recent Posts

Pages: [1] 2 3 ... 10
1
Thank you again.
2
From Bcx Help:

LOCAL quoted literal string initialized declarations inside a SUB or FUNCTION can be made. This will not work for GLOBAL strings. Neither will it work for dynamic strings that are created using any of the memory allocation functions: malloc/calloc/realloc. String functions and concatentations are not allowed -- only plain quoted string literals will work, like in the examples below:


 $BCXVERSION "7.7.2"
 
 CALL OnlyInProcedures()
 
 SUB OnlyInProcedures()
   DIM A$     = "This is handy!"
   DIM RAW B$ = "This is too!"
   LOCAL C$   = "This also works!"

 
   PRINT A$
   PRINT B$
   PRINT C$
END SUB

Result:

 This is handy!
 This is too!
 This also works!

=======================================

So, as this pertains to your problem, you must do this:


' REM Demonstration of character extracting functions
' REM \CHAP1\CH1_4.BAS

CLS
DIM V$
V$ = "OneTwoThree"

PRINT LEFT$(V$, 3)
PRINT MID$(V$, 4, 3)
PRINT RIGHT$(V$, 5)

PAUSE

END
3
Here is Chapter 1 example 4

Code: [Select]
'REM Demonstration of character extracting functions
'REM \CHAP1\CH1_4.BAS
 
CLS
DIM V$ = "OneTwoThree"
PRINT LEFT$(V$, 3)
PRINT MID$(V$, 4, 3)
PRINT RIGHT$(V$, 5)

PAUSE

END

I get the following errors

Code: [Select]
BCX BASIC to C/C++ Translator (c) 1999-2024 by Kevin Diggins
Version 8.0.8 (12/27/2023) Compiled using MS Visual C++ for 64-bit Windows Systems
[Lines In: 13] [Lines Out: 346] [Statements: 8] [Time: 0.02 Sec's]
BCX translated [Ch1_4_Bcx.Bas] to [Ch1_4_Bcx.C] for a C Compiler
**************************************************************************
Pelles C is compiling [ "C:\BCX\REVQB\CHAP1\CH1_4_BCX".c ] as a 64-bit CONSOLE application.
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(248): warning #2099: Missing type specifier; assuming 'int'.
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(248): warning #2095: Missing type specifier for parameter 2; assuming 'int'.
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(248): error #2001: Syntax error: expected ')' but found 'string constant'.
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(248): error #2119: Redeclaration of 'strcpy', previously declared at C:\PellesC\Include\intrin.h(89).
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(291): error #2140: Type error in argument 1 to 'strcpy'; expected 'char' but found 'char *'.
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(291): error #2140: Type error in argument 2 to 'strcpy'; expected 'int' but found 'const char *'.
C:\BCX\REVQB\CHAP1\CH1_4_BCX.c(291): error #2060: Invalid return type; expected 'char *' but found 'int'.
POLINK: fatal error: File not found: 'C:\BCX\REVQB\CHAP1\CH1_4_BCX.obj'.

I'd try to solve this myself but I've looked at the help file and there arent any examples for LEFT$. There is one example fro MID$ and I've not looked at RIGHT$. Being full of a cold doesn't help. Thanks.
4
Tips & Tricks / Re: SLRE: Super Light Regular Expression library
« Last post by airr on May 17, 2024, 10:04:42 PM »
Thanks for the updated file, MrB!

AIR.
5
Tips & Tricks / Re: SLRE: Super Light Regular Expression library
« Last post by MrBcx on May 17, 2024, 08:57:25 PM »
That is a stunningly useful piece of code!

However ... it shuts down a moment after it starts up when compiled with MSVC2022.  I haven't dug deeper yet.

On the plus side, it compiles and runs fine using Pelles, Lcc-Win32, Mingw (NuWen), and Clang.

The attached file is a modified version of dl2str.inc

It has a bit more error checking but more importantly, compiles and runs correctly using
Pelles, Lcc-Win32, Mingw (Nuwen), Clang, MSVC (msvcrt and ucrt)


Thanks
6
Tips & Tricks / Redirect Console Output and extract info with Posix Regex
« Last post by airr on May 17, 2024, 04:56:10 PM »
NOTE: This will probably require changes for non Pelles builds.

Currently, the BC.exe file doesn't include version information via a Manifest, so I worked out a different way to get the current version of the file.

This redirects the output of the 'bc.exe -v' invocation directly to a variable, and then extracts the version number using Posix Regex.

You'll need to point the bcx variable below to where you have BCX installed.

Code: [Select]
#include <regex.h>

Dim As File commandOutput
Dim As String buffer, version, bcx
Dim As regex_t regex
Dim As regmatch_t pmatch[bcxstrsize]
Dim As Integer ret, length

bcx = "c:\Users\riveraa\Apps\BCX\BC.exe"

commandOutput = popen( bcx & " -v", "r" )

ret = regcomp( &regex, "([0-9]+\.[0-9]+\.[0-9]+)", REG_ICASE Or REG_EXTENDED )

Get$ commandOutput, buffer, bcxstrsize

ret = regexec( &regex, buffer, bcxstrsize, pmatch, 0 )

length = ( pmatch[1].rm_eo - pmatch[1].rm_so ) + 1
version = Mid$( buffer, pmatch[1].rm_so, length )

Print crlf$,"Captured Version: ", Trim$( version )

regfree(&regex)
pclose( commandOutput )
Pause

7
Tips & Tricks / Re: SLRE: Super Light Regular Expression library
« Last post by MrBcx on May 17, 2024, 08:19:46 AM »

Going back to the Cesanta version for a sec:
 
AIR.

That is a stunningly useful piece of code!

However ... it shuts down a moment after it starts up when compiled with MSVC2022.  I haven't dug deeper yet.

On the plus side, it compiles and runs fine using Pelles, Lcc-Win32, Mingw (NuWen), and Clang.

8
Tips & Tricks / Re: SLRE: Super Light Regular Expression library
« Last post by airr on May 17, 2024, 12:35:59 AM »
Going back to the Cesanta version for a sec:

Code: [Select]
#include "slre.c"
$Include "dl2str.inc"

$Typedef struct slre_cap slre_cap

Dim As Integer a, b
Dim buffer$[BCXSTRSIZE*5]
Dim bcxList$*65535
Dim bcxName$[20]

Dim As slre_cap cap[BCXSTRSIZE]

DownloadToStr(&bcxList$, "https://bcxbasiccoders.com/archives/YahooGroups/Bcx_Files_New")

If bcxList$ > "" Then
    b = Split(buffer$, bcxList$, Lf$)
    For Integer i = 0 To b-1
        If slre_match("archives.+(Bcx8\d+\.zip)>.+", buffer$[i], Len(buffer$[i]), cap, BCXSTRSIZE, 1) > 0 Then
            bcxName$[a] = Left$(cap[0].ptr$, cap[0].len)
            a++
        End If
    Next
End If

Qsort bcxName$, a, Descending

Print "Latest BCX Filename: ", bcxName$[0]

Pause


AIR.
9
Bug Reports / Re: What does "LOCAL" mean, exactly?
« Last post by MrBcx on May 16, 2024, 05:58:29 PM »
I would also suggest adding a bit of free advice:

"It is strongly suggested to gather up all your declarations and place them at the beginning of your
sub or function.  This is to avoid any 'scope' issues."

Or something to similar effect.

cheers, mru

mr_unreliable,

That advice will go over like a lead balloon for many, including me.  There's nothing inherently wrong or dangerous
with your strategy.  In fact, I've personally used it many times.  I don't believe that advice belongs in the help file.

Be aware that many programs are written where local, scoped variables get allocated and deallocated
inside various blocks like IF-THEN statements, SELECT CASE structures, and every kind of loop.  This can be seen
throughout the source code for the BCX Translator itself and numerous apps written for it. 
 
Scope is something to be learned, not feared.
10
Bug Reports / Re: Casting off.....
« Last post by MrBcx on May 16, 2024, 05:36:14 PM »
Hi Kevin,

Thanks. Kindly, could you integrate the KAST macro to the BCX translator?

Yes -- it has already been added to the forthcoming BCX 8.0.9

Pages: [1] 2 3 ... 10