$ONEXIT

Started by jcfuller, January 27, 2020, 06:57:07 AM

Previous topic - Next topic

jcfuller

Kevin,
  A small issue with $ONEXIT.
I use it in all my code to run my compile batch files.
It works and every thing compiles fine but the last line seems out of place?
James


$ONEXIT "NUWENGPP.BAT $FILE$ con"

bc "C:\BcxRadAsm3\RadAsm\Bcx\Projects\test01\test01"

BCX BASIC to C/C++ Translator (c) 1999 by Kevin Diggins
Version 7.4.0 (2020/01/19)
[Lines In: 34] [Lines Out: 446] [Statements: 14] [Time: 0.04 sec's]
BCX translated C:\BcxRadAsm3\RadAsm\Bcx\Projects\test01\test01.bas to C:\BcxRadAsm3\RadAsm\Bcx\Projects\test01\test01.cpp For a C++ Compiler

Shelling Out To:NUWENGPP.BAT C:\BcxRadAsm3\RadAsm\Bcx\Projects\test01\test01 con
Compiling "test01.cpp" to a  64bit "Windows Console App" Using NUWEN Distro
test01.cpp: In function 'int scan(char*, char*, ...)':test01.cpp:359:21: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]  359 |   d = Split(A,input,",");      |                     ^~~test01.cpp: In function 'int main(int, char**)':test01.cpp:465:30: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]  465 | ScanError = scan(InputBuffer,"%d",&K);      |                              ^~~~Finished!
Can't open file C:\BcxRadAsm3\RadAsm\Bcx\Projects\test01\test01





MrBcx

James - if you email me your batch file and test01, I'll take a look. 


MrBcx

That was tricky but I believe I found the cause and, more importantly, the fix.

At the bottom of SUB PostProcess,  add the three (3) new lines of code (in bold) shown below:
  DIM szSave$
  szSave$ = FileOut$

.
.
.
  FileOut$  = szSave$
END SUB ' PostProcess


  '**************************
  DIM szSave$
  szSave$ = FileOut$
   
  FOR INTEGER A = 1 TO XitCount
    FileOut$ = EXTRACT$(FileOut$,".")
    Cmd$ = REMOVE$(Xit$[A],DQ$)
    IREPLACE "$FILE$" WITH OutfileClone$ IN Cmd$
    IREPLACE "$PELLES$\\" WITH PELLESPATH$ IN Cmd$
    IREPLACE "$PELLES$"   WITH PELLESPATH$ IN Cmd$
    IREPLACE "$LCC$\\" WITH LCCPATH$ IN Cmd$
    IREPLACE "$LCC$"   WITH LCCPATH$ IN Cmd$
    IREPLACE "$BCX$\\" WITH BCXPATH$ IN Cmd$
    IREPLACE "$BCX$"   WITH BCXPATH$ IN Cmd$
    REPLACE "\\\\" WITH "\\" IN Cmd$
    REPLACE DDQ$ WITH DQ$ IN Cmd$
    PRINT "Shelling Out To:", Cmd$
    SHELL Cmd$   
  NEXT
  FileOut$  = szSave$
END SUB ' PostProcess

jcfuller

Kevin,
  After I set up a bcx compile folder I compiled with Pelles C 32 and it ran fine.
BUT when I did a compile setup similar to my bc9 using TDM g++ I relived the HORRORS of:
warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
I experienced when I first started bc9. :)
I bit the bullet and removed every single warning in bc9. Are you up to the task :)

James

MrBcx

Being up to the task and being committed to the task are two different things.

I'd have to say that there is about a 0.1% likelihood that I'll spend any time on such an endeavor.

My attitude about warnings is that they mean nothing until they mean something.

jcfuller

Quote from: MrBcx on January 27, 2020, 05:04:50 PM
Being up to the task and being committed to the task are two different things.

I'd have to say that there is about a 0.1% likelihood that I'll spend any time on such an endeavor.

My attitude about warnings is that they mean nothing until they mean something.


Kevin,
I thought I would give a go at fixing the warning:
ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
when it dawned on me I really don't care when compiling Bcx. I can use -Wno-write-strings.
But I don't want MY translated code to spout them from the runtime code produced by Bcx.
I thought I might have better luck dumping the rtl and focus on converting those functions and it would be easier to update those in the Bcx source itself.

Alas I could not get bc -l to work??

James

Robert

Quote from: jcfuller on February 04, 2020, 01:16:55 PM

Alas I could not get bc -l to work??

James

Hi James:

bc -l works for me with BCX 7.4.1.

Note well, the rtlib and other folders are created in the root directory of the drive from which "bc -l" is invoked.

I invoked bc -l from C:dev\ and the rtlib and other folders were created in C:\

jcfuller

Thanks Robert. Found them
James

MrBcx

I don't know whether this will interest you but I'll offer it.

I wrote a tool to help me analyze BCX by breaking out the key components.


Rather than bore you with the details of my tool, I am attaching the output as a zip file for your examination.

If you translate Bc_(1)_NEW_BUILD.Bas and compile, you will have recreated the BCX translator.
That's not the point ...
The point is that successfully compiling all the parts gives confidence in BINK's disassembly.


C:\Temp\BCX_By_The_Numbers>bink bc.bas
Opening Bc.Bas
Reading Bc.Bas
Closing Bc.Bas

Creating Bc_(1)_NEW_BUILD.BAS

Found  152 SUBS
Found  140 FUNCTIONS
Found  13 ENUMS
Found  11 SETS
Found  15 TYPES
Found  92 CONSTANTS
Found  595 GLOBALS

jcfuller

Kevin,
   With such a  tools search capability why can't you tweak it to change all the char* to const char* in the runtime functions output in bc.bas itself?

James


MrBcx

James ... give me a before and after example of what you're talking about.


jcfuller

Kevin,
  I believe this all you need to eliminate all the warnings when you compile as c++ source.

James



Before:

    IF Use_Str_Cmp THEN
      FPRINT FP_WRITE, "int     str_cmp(char*, char*);"
    END IF

............

  IF Use_Str_Cmp THEN
    IF Use_Library THEN FPRINT FP_WRITE, "// BCXRTLIB: str_cmp"
    FPRINT FP_WRITE, "int str_cmp (char *a, char *b)"
    FPRINT FP_WRITE, "{"
    FPRINT FP_WRITE, "  int counter=0;"
    FPRINT FP_WRITE, "  for(;;)"
    FPRINT FP_WRITE, "   {"
    FPRINT FP_WRITE, "    if((a[counter]^b[counter]))"
    FPRINT FP_WRITE, "     {"
    FPRINT FP_WRITE, "      if((UINT) a[counter]>= (UINT) b[counter])"
    FPRINT FP_WRITE, "      return  1;"
    FPRINT FP_WRITE, "      return -1;"
    FPRINT FP_WRITE, "     }"
    FPRINT FP_WRITE, "    if(!a[counter]) return 0;"
    FPRINT FP_WRITE, "    counter++;"
    FPRINT FP_WRITE, "   }"
    FPRINT FP_WRITE, sENDBCXRTLIB$
  END IF



After

    IF Use_Str_Cmp THEN
      FPRINT FP_WRITE, "int     str_cmp(const char*, const char*);"
    END IF
................................

  IF Use_Str_Cmp THEN
    IF Use_Library THEN FPRINT FP_WRITE, "// BCXRTLIB: str_cmp"
    FPRINT FP_WRITE, "int str_cmp (const char *a, const char *b)"
    FPRINT FP_WRITE, "{"
    FPRINT FP_WRITE, "  int counter=0;"
    FPRINT FP_WRITE, "  for(;;)"
    FPRINT FP_WRITE, "   {"
    FPRINT FP_WRITE, "    if((a[counter]^b[counter]))"
    FPRINT FP_WRITE, "     {"
    FPRINT FP_WRITE, "      if((UINT) a[counter]>= (UINT) b[counter])"
    FPRINT FP_WRITE, "      return  1;"
    FPRINT FP_WRITE, "      return -1;"
    FPRINT FP_WRITE, "     }"
    FPRINT FP_WRITE, "    if(!a[counter]) return 0;"
    FPRINT FP_WRITE, "    counter++;"
    FPRINT FP_WRITE, "   }"
    FPRINT FP_WRITE, sENDBCXRTLIB$
  END IF

MrBcx

So ... only the arguments need to be updated ?

I concluded after reading this ( https://stackoverflow.com/questions/9834067/difference-between-char-and-const-char   )
that functions returning "char *" would also need to be updated.  And GLOBAL variables defined as "char *" would need to be updated.

Why be concerned that function arguments might get hijacked by n'er-do-wells but not concerned that functions or variables are equally vulnerable?


This is as clear as mud to me.

jcfuller

Kevin,
  I misspoke on the warnings.  My concern is with the rt functions not the bc translator itself at this point. I bit the bullet and eliminated all the warnings in bc9 but it was not easy. It came from compiling over and over until I got no more warnings.

If you want to completely update bc this type will also need to be updated.
As will other items I do not remember.

James


SET atVARIANTVALUENAMES[] AS tagVVN
  {"bVal"      , vt_BYTE           , 0},
  {"bool"      , vt__VARIANT_BOOL  , 0},
  {"boolVal"   , vt_VARIANT_BOOL   , 0},
  {"bstrVal"   , vt_BSTR           , 0},
  {"byref"     , vt_PVOID          , 0},
  {"cVal"      , vt_CHAR           , 0},
  {"cyVal"     , vt_CY             , 0},
  {"date"      , vt_DATE           , 0},
  {"dblVal"    , vt_DOUBLE         , 0},
  {"fltVal"    , vt_FLOAT          , 0},
  {"iVal"      , vt_SHORT          , 0},
  {"intVal"    , vt_INT            , 0},
  {"lVal"      , vt_LONG           , 0},
  {"llVal"     , vt_LLONG          , 0},
  {"parray"    , vt_SAFEARRAY      , 1},
  {"pbVal"     , vt_BYTE           , 1},
  {"pbool"     , vt__VARIANT_BOOL  , 1},
  {"pboolVal"  , vt_VARIANT_BOOL   , 1},
  {"pbstrVal"  , vt_BSTR           , 1},
  {"pcVal"     , vt_CHAR           , 1},
  {"pcyVal"    , vt_CY             , 1},
  {"pdate"     , vt_DATE           , 1},
  {"pdblVal"   , vt_DOUBLE         , 1},
  {"pdecVal"   , vt_DECIMAL        , 1},
  {"pdispVal"  , vt_IDispatch      , 1},
  {"pfltVal"   , vt_FLOAT          , 1},
  {"piVal"     , vt_SHORT          , 1},
  {"pintVal"   , vt_INT            , 1},
  {"plVal"     , vt_LONG           , 1},
  {"pllVal"    , vt_LLONG          , 1},
  {"pparray"   , vt_SAFEARRAY      , 2},
  {"ppdispVal" , vt_IDispatch      , 2},
  {"ppunkVal"  , vt_IUnknown       , 2},
  {"pscode"    , vt_SCODE          , 1},
  {"puiVal"    , vt_USHORT         , 1},
  {"pulVal"    , vt_ULONG          , 1},
  {"pullVal"   , vt_ULONGLONG      , 1},
  {"punkVal"   , vt_IUnknown       , 1},
  {"pvarVal"   , vt_VARIANT        , 1},
  {"scode"     , vt_SCODE          , 0},
  {"uiVal"     , vt_USHORT         , 0},
  {"uintVal"   , vt_UINT           , 0},
  {"ulVal"     , vt_ULONG          , 0},
  {"ullVal"    , vt_ULONGLONG      , 0},
  {NULL        , 0                 , 0}
END SET



to


SET atVARIANTVALUENAMES[] AS tagVVN
  {(char*)"bVal"     , vt_BYTE         , 0},
  {(char*)"bool"     , vt__VARIANT_BOOL, 0},
  {(char*)"boolVal"  , vt_VARIANT_BOOL , 0},
  {(char*)"bstrVal"  , vt_BSTR         , 0},
  {(char*)"byref"    , vt_PVOID        , 0},
  {(char*)"cVal"     , vt_CHAR         , 0},
  {(char*)"cyVal"    , vt_CY           , 0},
  {(char*)"date"     , vt_DATE         , 0},
  {(char*)"dblVal"   , vt_DOUBLE       , 0},
  {(char*)"fltVal"   , vt_FLOAT        , 0},
  {(char*)"iVal"     , vt_SHORT        , 0},
  {(char*)"intVal"   , vt_INT          , 0},
  {(char*)"lVal"     , vt_LONG         , 0},
  {(char*)"llVal"    , vt_LLONG        , 0},
  {(char*)"parray"   , vt_SAFEARRAY    , 1},
  {(char*)"pbVal"    , vt_BYTE         , 1},
  {(char*)"pbool"    , vt__VARIANT_BOOL, 1},
  {(char*)"pboolVal" , vt_VARIANT_BOOL , 1},
  {(char*)"pbstrVal" , vt_BSTR         , 1},
  {(char*)"pcVal"    , vt_CHAR         , 1},
  {(char*)"pcyVal"   , vt_CY           , 1},
  {(char*)"pdate"    , vt_DATE         , 1},
  {(char*)"pdblVal"  , vt_DOUBLE       , 1},
  {(char*)"pdecVal"  , vt_DECIMAL      , 1},
  {(char*)"pdispVal" , vt_IDispatch    , 1},
  {(char*)"pfltVal"  , vt_FLOAT        , 1},
  {(char*)"piVal"    , vt_SHORT        , 1},
  {(char*)"pintVal"  , vt_INT          , 1},
  {(char*)"plVal"    , vt_LONG         , 1},
  {(char*)"pllVal"   , vt_LLONG        , 1},
  {(char*)"pparray"  , vt_SAFEARRAY    , 2},
  {(char*)"ppdispVal", vt_IDispatch    , 2},
  {(char*)"ppunkVal" , vt_IUnknown     , 2},
  {(char*)"pscode"   , vt_SCODE        , 1},
  {(char*)"puiVal"   , vt_USHORT       , 1},
  {(char*)"pulVal"   , vt_ULONG        , 1},
  {(char*)"pullVal"  , vt_ULONGLONG    , 1},
  {(char*)"punkVal"  , vt_IUnknown     , 1},
  {(char*)"pvarVal"  , vt_VARIANT      , 1},
  {(char*)"scode"    , vt_SCODE        , 0},
  {(char*)"uiVal"    , vt_USHORT       , 0},
  {(char*)"uintVal"  , vt_UINT         , 0},
  {(char*)"ulVal"    , vt_ULONG        , 0},
  {(char*)"ullVal"   , vt_ULONGLONG    , 0},
  {NULL       ,0                , 0}
END SET


jcfuller

#14
Kevin,
  Followup: When I compile bcx with the same TDM compiler I us with bc9 using -Wno-write-strings there are no warnings.
Attached is the without.

James