Author Topic: BCX 7.5.1 CONTAINEDIN  (Read 37 times)

Robert

  • Sr. Member
  • ****
  • Posts: 383
    • View Profile
BCX 7.5.1 CONTAINEDIN
« on: July 23, 2020, 09:51:31 AM »
Compiling CONTAINEDIN code below with Microsoft compiler errors

Code: [Select]

Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29109 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

snip.cpp
I:\t\snip.cpp(340): error C2664: 'int containedin(LPCTSTR,const char **,int)': cannot convert argument 2 from 'char *[14]' to 'const char **'
I:\t\snip.cpp(340): note: Conversion loses qualifiers
I:\t\snip.cpp(278): note: see declaration of 'containedin'
I:\t\snip.cpp(344): error C2664: 'int containedin(LPCTSTR,const char **,int)': cannot convert argument 2 from 'char *[14]' to 'const char **'
I:\t\snip.cpp(344): note: Conversion loses qualifiers
I:\t\snip.cpp(278): note: see declaration of 'containedin'
I:\t\snip.cpp(364): error C2664: 'int containedin(LPCTSTR,const char **,int)': cannot convert argument 2 from 'char *[14]' to 'const char **'
I:\t\snip.cpp(364): note: Conversion loses qualifiers
I:\t\snip.cpp(278): note: see declaration of 'containedin'
I:\t\snip.cpp(368): error C2664: 'int containedin(LPCTSTR,const char **,int)': cannot convert argument 2 from 'char *[14]' to 'const char **'
I:\t\snip.cpp(368): note: Conversion loses qualifiers
I:\t\snip.cpp(278): note: see declaration of 'containedin'
Linking ................
Microsoft (R) Incremental Linker Version 14.27.29109.0
Copyright (C) Microsoft Corporation.  All rights reserved.

LINK : fatal error LNK1181: cannot open input file 'I:\t\snip.obj'
Finished!


Pelles C errors

Code: [Select]

Setting 64-bit environment for Pelles C...
Compiling "snip.c"..........
snip.c(336): error #2140: Type error in argument 2 to 'containedin'; expected 'PZPCSTR (aka const char * *)' but found 'char * *'.
snip.c(340): error #2140: Type error in argument 2 to 'containedin'; expected 'PZPCSTR (aka const char * *)' but found 'char * *'.
snip.c(360): error #2140: Type error in argument 2 to 'containedin'; expected 'PZPCSTR (aka const char * *)' but found 'char * *'.
snip.c(364): error #2140: Type error in argument 2 to 'containedin'; expected 'PZPCSTR (aka const char * *)' but found 'char * *'.
Linking ................
POLINK: fatal error: File not found: 'snip.obj'.



Code: [Select]

 SET CN[] AS CHAR PTR
   "&",
   ",",
   ":",
   "+",
   "-",
   "*",
   "/",
   "^",
   ";",
   "=",
   "<",
   ">",
   "THEN",
   ""
 END SET
 
 DIM c1, c2
 DIM i
 DIM x
 DIM y
 DIM Stk$[128]
 DIM Ndx
 DIM A$
 
 A$ = "if x = 1 then y = y + 1 : if y > 10 THEN y = 0"
 PRINT A$
 CALL TinyParse(A$, " ")
 
 c1 = 0
 c2 = 0
 FOR i = 0 TO Ndx
   x = CONTAINEDIN(Stk$[i], CN, 1)
   IF x <> -1 THEN
     PRINT "Token "; i; " in A$ "; Stk$[i]; " ";
     y = CONTAINEDIN(Stk$[i], CN)
     IF y <> -1 THEN
       PRINT " exact match"
       c2++
     ELSE
       PRINT " match with case difference"
     END IF
     c1++
   END IF
 NEXT
 PRINT "A total of"; c1; " tokens, regardless of case, in CN[] where found in A$,"; c2; " were exact matches"
 PAUSE
 c1 = 0
 c2 = 0
 FOR i = 0 TO Ndx
   x = CONTAINEDIN(Stk$[i], CN, 3)
   IF x <> -1 THEN
     PRINT "the"; i; "th token in A$ "; Stk$[i]; " ";
     y = CONTAINEDIN(Stk$[i], CN, 2)
     IF y <> -1 THEN
       PRINT " exact match of the"; y; "th token in CN[] "; CN$[y]
       c2++
     ELSE
       PRINT " match with case difference of the"; x; "th token in CN[] "; CN$[x]
     END IF
     c1++
   END IF
 NEXT
 
 PAUSE
 
 SUB TinyParse(A$, Delim$)
   DIM RAW TB$
   DIM RAW Sep
   DIM STATIC ii
   Ndx = 0
   TB$ = ""
   Sep = INCHR(A$, Delim$)
   IF Sep > 0 THEN
     IF Sep > 1 THEN
       TB$ = LEFT$(A$, Sep - 1)
       Stk$[ii] = TB$
       ii++
     END IF
     A$ = MID$(A$, Sep + 1)
     TinyParse(A$, Delim$)
   ELSE
     Stk$[ii] = A$
     Stk$[ii+1] = ""
     Ndx = ii
     ii = 0
   END IF
 END SUB



Robert

  • Sr. Member
  • ****
  • Posts: 383
    • View Profile
Re: BCX 7.5.1 CONTAINEDIN
« Reply #1 on: July 23, 2020, 10:58:46 AM »
Compiling CONTAINEDIN code below with Microsoft compiler errors

Code: [Select]

Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29109 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

snip.cpp
I:\t\snip.cpp(340): error C2664: 'int containedin(LPCTSTR,const char **,int)': cannot convert argument 2 from 'char *[14]' to 'const char **'
I:\t\snip.cpp(340): note: Conversion loses qualifiers
I:\t\snip.cpp(278): note: see declaration of 'containedin'
I:\t\snip.cpp(344): error C2664: 'int containedin(LPCTSTR,const char **,int)': cannot convert argument 2 from 'char *[14]' to 'const char **'
I:\t\snip.cpp(344): note: Conversion loses qualifiers
I:\t\snip.cpp(278): note: see declaration of 'containedin'
I:\t\snip.cpp(364): error C2664: 'int containedin(LPCTSTR,const char **,int)': cannot convert argument 2 from 'char *[14]' to 'const char **'
I:\t\snip.cpp(364): note: Conversion loses qualifiers
I:\t\snip.cpp(278): note: see declaration of 'containedin'
I:\t\snip.cpp(368): error C2664: 'int containedin(LPCTSTR,const char **,int)': cannot convert argument 2 from 'char *[14]' to 'const char **'
I:\t\snip.cpp(368): note: Conversion loses qualifiers
I:\t\snip.cpp(278): note: see declaration of 'containedin'
Linking ................
Microsoft (R) Incremental Linker Version 14.27.29109.0
Copyright (C) Microsoft Corporation.  All rights reserved.

LINK : fatal error LNK1181: cannot open input file 'I:\t\snip.obj'
Finished!


Pelles C errors

Code: [Select]

Setting 64-bit environment for Pelles C...
Compiling "snip.c"..........
snip.c(336): error #2140: Type error in argument 2 to 'containedin'; expected 'PZPCSTR (aka const char * *)' but found 'char * *'.
snip.c(340): error #2140: Type error in argument 2 to 'containedin'; expected 'PZPCSTR (aka const char * *)' but found 'char * *'.
snip.c(360): error #2140: Type error in argument 2 to 'containedin'; expected 'PZPCSTR (aka const char * *)' but found 'char * *'.
snip.c(364): error #2140: Type error in argument 2 to 'containedin'; expected 'PZPCSTR (aka const char * *)' but found 'char * *'.
Linking ................
POLINK: fatal error: File not found: 'snip.obj'.



Code: [Select]

 SET CN[] AS CHAR PTR
   "&",
   ",",
   ":",
   "+",
   "-",
   "*",
   "/",
   "^",
   ";",
   "=",
   "<",
   ">",
   "THEN",
   ""
 END SET
 
 DIM c1, c2
 DIM i
 DIM x
 DIM y
 DIM Stk$[128]
 DIM Ndx
 DIM A$
 
 A$ = "if x = 1 then y = y + 1 : if y > 10 THEN y = 0"
 PRINT A$
 CALL TinyParse(A$, " ")
 
 c1 = 0
 c2 = 0
 FOR i = 0 TO Ndx
   x = CONTAINEDIN(Stk$[i], CN, 1)
   IF x <> -1 THEN
     PRINT "Token "; i; " in A$ "; Stk$[i]; " ";
     y = CONTAINEDIN(Stk$[i], CN)
     IF y <> -1 THEN
       PRINT " exact match"
       c2++
     ELSE
       PRINT " match with case difference"
     END IF
     c1++
   END IF
 NEXT
 PRINT "A total of"; c1; " tokens, regardless of case, in CN[] where found in A$,"; c2; " were exact matches"
 PAUSE
 c1 = 0
 c2 = 0
 FOR i = 0 TO Ndx
   x = CONTAINEDIN(Stk$[i], CN, 3)
   IF x <> -1 THEN
     PRINT "the"; i; "th token in A$ "; Stk$[i]; " ";
     y = CONTAINEDIN(Stk$[i], CN, 2)
     IF y <> -1 THEN
       PRINT " exact match of the"; y; "th token in CN[] "; CN$[y]
       c2++
     ELSE
       PRINT " match with case difference of the"; x; "th token in CN[] "; CN$[x]
     END IF
     c1++
   END IF
 NEXT
 
 PAUSE
 
 SUB TinyParse(A$, Delim$)
   DIM RAW TB$
   DIM RAW Sep
   DIM STATIC ii
   Ndx = 0
   TB$ = ""
   Sep = INCHR(A$, Delim$)
   IF Sep > 0 THEN
     IF Sep > 1 THEN
       TB$ = LEFT$(A$, Sep - 1)
       Stk$[ii] = TB$
       ii++
     END IF
     A$ = MID$(A$, Sep + 1)
     TinyParse(A$, Delim$)
   ELSE
     Stk$[ii] = A$
     Stk$[ii+1] = ""
     Ndx = ii
     ii = 0
   END IF
 END SUB



Demo compiles and runs as expected with array SET line in example changed from

Code: [Select]

SET CN[] AS CHAR PTR


to

Code: [Select]

SET CN[] AS CONST CHAR PTR



MrBcx

  • Administrator
  • Sr. Member
  • *****
  • Posts: 434
    • View Profile
Re: BCX 7.5.1 CONTAINEDIN
« Reply #2 on: July 23, 2020, 12:39:31 PM »
Thanks Robert --

I've reverted containedin, tested the sample in the Helpfile, and all is well again.

Containedin and several other builtin functions can be looked at again in the future, if there's a demand to bend them to the will of the C++ gods.