From cd1708fb0f097eb5d23ccc2ff46c9984a25b514e Mon Sep 17 00:00:00 2001 From: AIR Date: Thu, 28 Jul 2022 14:29:51 -0400 Subject: [PATCH] Initial Code Commit --- mbc4.bas | 11546 ++++++++++++++++++++++++ mbc4.cc | 20603 +++++++++++++++++++++++++++++++++++++++++++ runtime.bas | 2357 +++++ std_macros.bas | 106 + std_prototypes.bas | 491 ++ 5 files changed, 35103 insertions(+) create mode 100644 mbc4.bas create mode 100644 mbc4.cc create mode 100644 runtime.bas create mode 100644 std_macros.bas create mode 100644 std_prototypes.bas diff --git a/mbc4.bas b/mbc4.bas new file mode 100644 index 0000000..358a677 --- /dev/null +++ b/mbc4.bas @@ -0,0 +1,11546 @@ +'****************************************************************************** +'****************************************************************************** +' BCX Universal - The Cross Platform Basic To C/C++ Translator Version 2.0d +'****************************************************************************** +' (c) 1999 - 2009 Kevin Diggins +'****************************************************************************** + +'******************************** +'** OSX 10.5+ UNIVERSAL BINARY ** +'******************************** +'$OSX + +'***************** +'** GTK Support ** +'***************** +'$GTK + +'***************** +'** GLIB Support * +'***************** +'$GLIB + +'**************************** +'** WX WIDGETS GUI SUPPORT ** +'**************************** +'$WX + +'******************************** +'** WX WIDGETS CONSOLE SUPPORT ** +'******************************** +'$WXC + +'*********************** +'** Apple IOS SUPPORT ** +'*********************** +'$IOS + +'********************************** +'** AUTO BUILD TRANSLATOR BINARY ** +'********************************** +$EXECON + + +'********************** +'** STRIP EXECUTABLE ** +'********************** +' $EXESTRIP + + +' +CONST Version$ = "4.0-Beta3 (2018/12/09)" 'BCX version number and date (YYYY/MM/DD) +'******************************************************************************* +' +'BCX is distributed under the terms of the GNU General Public License Ver.(2). +'The complete source code that is PRODUCED BY BCX is subject to a License +'Exception to the GPL, which allows you to produce commercial applications. +' +'****************************************************************************** +' BCX LICENSE EXCEPTION +'****************************************************************************** +' +'As a special exception, the BCX license gives permission for additional uses +'of the text contained in its release of BCX. The exception is that, if you use +'BCX to create source code that will link the BCX libraries with other files to +'produce an executable, this does not by itself cause the resulting executable +'to be covered by the GNU GPL. Your use of that executable is in no way +'restricted on account of using BCX to produce source code that will link the +'BCX library code into it. +' +'This exception does not invalidate any other reasons why the executable file +'might be covered by the GNU General Public License. This exception applies +'only to the code released with this BCX explicit exception. If you add or copy +'code from other sources, as the General Public License permits, the above +'exception does not apply to the code that you add in this way. +' +'To avoid misleading anyone as to the status of such modified files, you must +'delete this exception notice from them. If you write modifications of your +'own for BCX, it is your choice whether to permit this exception to apply to +'your modifications. +'This program is distributed in the hope that it will be useful, but WITHOUT +'ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS +'FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +' +' You should have received a copy of the GNU General Public License along with +' this program; if not, write to the Free Software Foundation, Inc., +'59 Temple Place - Suite 330, Boston, MA 02111-1307, USA or visit +'http://www.gnu.org/copyleft/gpl.html#SEC1 + +$COMMENT - Comment section added 10/20/2004 05:00AM by Vic McClung +******************************************************************************* +Developer Guidelines +******************************************************************************* +Code should be written in BCX Basic. If it can not be written in BCX Basic for +some reason or results in code that seems too inefficient then this may be a +cue that a new Basic function is needed. +* All KEYWORDS should be capitalized +* Use two space indentation +* Use spaces not tabs +* Record all notes in reverse chronological order +* And most importantly....Have fun! +****************************************************************************************** +This section is used to communicate to-do 's, changes, ideas, suggestions, etc. +****************************************************************************************** +------------------------------------------- +2018-12-12 Armando Rivera + * Changed BcxRegEx function to REGMATCH + * Changed BcxRegEx keyword to REGMATCH + * Added $MODULE as alias to $INCLUDE to support external modules. ** MUST BE AT TOP OF MAIN SOURCE FILE ** + * Added $LDFLAGS directive to support external modules +------------------------------------------- +------------------------------------------- +2016-02-15 Armando Rivera +------------------------------------------- + * Changed default string size to 65K from + 2k, which was limiting. + * Updated output of PRINT command, eliminating + leading spaces from numbers. +------------------------------------------- +2015-07-03 Armando Rivera +------------------------------------------- + * Changed $OSX flag to use Cocoa instead of Carbon in MacOS + This is in preparation of the new custom libcocoa library + that I'm currently creating that will allow mbc + to create 64bit GUI applications in OSX +------------------------------------------- +2013-06-26 Armando Rivera +------------------------------------------- + * Added BcxRegex keyword, based on Posix Regex in Libc + * Broke up main source file into files containing Runtime, Declarations, etc. + * Added BYTE type + +------------------------------------------- +2013-06-17 Armando Rivera +------------------------------------------- + * Tweaked HEX$ so that it will emit 2-digit hex numbers + * Added PUCHAR (unsigned char*) typedef +------------------------------------------- +2011-03-11 Armando Rivera +------------------------------------------- + * Added Wayne's suggestion to support Reference Variables as return types. + +------------------------------------------- +2011-03-10 Armando Rivera +------------------------------------------- + * Ported $PROJECT directive from ConsoleBC. This doesn't emit the RTL yet, but it's a start. + It's the first step towards re-writing the RT code to leverage CPP/WX. + + * Fixed bug where BCX_TmpStr sometimes wasn't emitted when returning a string from a function + + * Added Named Enum support. Syntax: + myenum AS ENUM + … + END ENUM + + This required moving the Enum emit code to before the User Prototype emit code + to allow passing the named enum to user defined functions. + +------------------------------------------- +2011-01-23 Armando Rivera +------------------------------------------- + * Initial Beta1 Release + + * Fixed bug in INPUT statement to remove trailing newlines (James Fuller) + + * Removed COLOR statements to avoid terminal output issues with redirected + translator output (James Fuller) + + * Added CONST keyword when declaring variables (Global, Local, and as Function/Sub parameters) + At the moment, this is experimental (meaning I haven't fully tested it) but it seems to work + + * Added PRIVATE keyword for CPP classes +------------------------------------------- +2010/12/21 Armando Rivera +------------------------------------------- + * Cleaned up code emission so that unneeded defines/global vars are not emitted + + * Added new $IOS directive, which is MAC ONLY, to compile source for iDevices (iPhone/iTouch/AppleTV2) + At this point in time, running binaries built this way requires a jailbroken iDevice. + This is experimental, and for console apps only for now. + A simple console example is in the Examples/IOS folder +------------------------------------------- +2010/12/11 Armando Rivera +------------------------------------------- + * Add new Socket keywords: BcxSocket, BcxSocketSend, BcxSocketRead, and BcxSocketClose + See the BcxSocket.bas demo in the Examples/Socket folder for info. + + * Added kbhit() , which doesn't exist outside of Windows + This is a custom sub which emulates what kbhit() does + + * Changed the conditional emission of term.h to only be emitted when + Use_Keypress is TRUE (InKey) + +------------------------------------------- +2010/12/01 Armando Rivera +------------------------------------------- + * Changed wxApp emission to use BCXPLITHPATH$, per James Fuller's suggestion. + + * Added support for Abstract Classes (gcc doesn't have the INTERFACE keyword) + + Example: + Class MyAbstractClass + public + + virtual sub Proc1() = 0 + Virtual sub Proc2()=0 + virtual function Proc3(a$,b$) as integer = 0 + + End Class +------------------------------------------- +2010/11/30 Armando Rivera +------------------------------------------- + * Removed $CLASS/$ENDCLASS $NAMESPACE/$ENDNAMESPACE + Using either will emit a message stating that they have been replaced. + + * Addded NAMESPACE / END NAMESPACE + This allows creating methods within the NAMESPACE like so: + + $CPP + $NOMAIN + $EXECON + '============================================================================== + NAMESPACE Dlg_01 + Sub DoIt() + Print "Dlg_01" + End Sub + + Function GetString$(A$) as string + function = "The String you Passed Was: " + enc$(A$) + end function + END NAMESPACE + '============================================================================== + Function main(argc as INTEGER, argv as PCHAR ptr) as INTEGER + Print "James" + Dlg_01::DoIt() + print Dlg_01::GetString$("Hello, World!") + End Function + + * If using $WX, the #define for Clear() will not be emitted due to conflict + with Classes that have that method defined + + * Made the inclusion of "term.h" conditional based on whether $WX/$WXC + is used. "term.h" is required for the implementation of + the PAUSE keyword in CONSOLE apps. + +------------------------------------------- +2010/11/25 Armando Rivera +------------------------------------------- + * Changed code so that in $CPP mode, the case of the emitted + .cpp filename is preserved (James Fuller bug report) + +------------------------------------------- +2010/11/24 Armando Rivera +------------------------------------------- + * Minor change in StripCode() to correct + possible overflow issue under 64bit Linux (James Fuller bug report) + + * Added $WXC Directive to support WX Console-Based Apps + Using this switch, neither a wxApp or the IMPLEMENT_APP() macro are + auto added to the translated source (James Fuller request) +------------------------------------------- +2010/11/20 Armando Rivera +------------------------------------------- + * Changed $DLL directive so that it would generate *nix Shared Libraries. + * Added $DLL support to $EXECON + * Added required flags to LD_FLAGS$ for creating *nix Shared Libraries + Example: + $dll + $execon + + function printdemo() export + print "This was called from a Dynamic Library" + end function + + Note that this is currently only useful for creating shared libraries + for **OTHER** languages; it won't work with MBC created apps because of + duplicate naming conflicts. + +------------------------------------------- +2010/11/18 Armando Rivera +------------------------------------------- + * Removed "-Os" compiler optimization flag from $EXECON for fastest tranlator compliation + during Alpha testing stage. + + This will be re-added when translator is not longer in Alpha status + + * Added USE_CTOR global as flag for supporting Constructor/Destructor syntax + + * Added "USING" keyword for CONSTRUCTOR/DESTRUCTOR methods. It is used like this: + + CONSTRUCTOR MainWin::MainWin(title as wxString, winStyle as long) USING wxFrame( 0, -1, title, wxPoint(50,50), wxSize(490,296), winStyle ) + + Which will emit: + + MainWin::MainWin (wxString title, long winStyle) + : wxFrame( 0, -1, title, wxPoint(50,50), wxSize(490,296), winStyle ) + { + + * Added code to extract and emit derived class methods + +------------------------------------------- +2010/11/17 Armando Rivera +------------------------------------------- + * Added new CLASS / END CLASS / PUBLIC / PROTECTED / CONSTRUCTOR / DESTRUCTOR keywords. + These additions flesh out Basic-Like C++ CLASS support, superceding $CLASS/$ENDCLASS, + and now allows syntax like the following: + + $CPP + $NOMAIN + $execon + + class MyClass + + protected + first as string + secnd$ + third% + + public + type ATest + a as PCHAR + b as long + c as single + d as float + end type + + Constructor MyClass(a$, b) + Destructor MyClass() + end class + + FUNCTION main(argc as INTEGER, argv as PCHAR ptr) as INTEGER + RAW theClass as MyClass PTR + + theClass = new MyClass("Hello", 12) + + print (char*)theClass->ATest.a + print theClass->ATest.b + END FUNCTION + + Constructor MyClass::MyClass(a$,b) + ATest.a = a$ + ATest.b = b + END Constructor + ' + Destructor MyClass::~MyClass() + + END Destructor + +------------------------------------------- +2010/11/12 Armando Rivera +------------------------------------------- + * Added code that (mostly) eliminates the need for a trailing ";" in $class/$endclass + + * Added code to allow the use of "SUB" in $class/$endclass. It just substitutes "void" for "sub" + at this point. + + * Fixed "THIS" keyword code so that it emits a lowercase "this". Linux/OSX aren't affected + by this breaking COM statements. :-P Thanks to JCFULLER for the tip! + + * For $CPP mode, added typedefs for std::string (CSTRING) and std::fstream (CFILE) + These are direct replacements for STRING and FILE, and allows the full use of each + C++ object/class. + + So instead of "dim mystring as string", for example, you would do "dim mystring as CSTRING". + You would then have access to all of std::string's methods like .replace, .substr, .compare, etc. + + I'm considering doing the same with the other toolkit directives ($OSX, $GTK, etc) but we'll see... + + * Added "inherits" in $CPP mode so that subclassing can be done like so: + + $class MyClass inherits AnotherClass + + * For $WX mode, added code to automatically emit the required derived wxApp class. + Note that it will be named the same as your sourcefile (minus the extension), and you MUST provide + a "FUNCTION ::OnInit() as bool" for it: + + FUNCTION TestApp::OnInit() as bool + + END FUNCTION + + * For $WX mode, made "$NOMAIN" the default, so no need to pass that directive + + * Colorized some of the compiler output text. Just because I can. + + * Back-ported Wayne's changes to "WITH" to allow the use of "->" syntax + + * TODO: + Finish off the $class/$endclass code to allow full basic syntax for method and variable + declarations. + + Remove ALL remaining WIN32 related code and ifdefs. + No need for that stuff under Linux/OSX, the Windows version of BCX can handle all + of the Windows stuff one might need. + + Other stuff I can't remember right now….. +------------------------------------------- +2010/03/31 Armando Rivera +Beginning with this version of the console compiler, +the goal is to have a 100% unified code-base, because +I'm fracking tired of trying to maintain separate builds +for different Operating Systems. +------------------------------------------- + + * Added $OSX, $GTK¸$GLIB and $WX Directives + (Use_Osx, Use_Wx, Use_Gtk, Use_Glib and LD_FLAGS$ Globals added) + + $OSX will automatically enable Carbon GUI support, and if $EXECON is invoked + will also build a Universal Binary with 32bit and 64bit support + + $GTK will automatically enable GTK/GLIB support, and if $EXECON is invoked + will build the executable linking in libgtk and it's support libraries. + + $GLIB will automatically enable >GLIB ONLY< support, and if $EXECON is invoked + will build the executable linking in libglib and it's support libraries. + + $WX will automatically enable wxWidgets with $CPP set to "TRUE", and if $EXECON + is invoked will build the executable linking in libwx and it's support libraries + + This is, in part, in preparation for moving the GTK support from the core of the + LinuxBC translator to an external library which will be linked in as required. This + will GREATLY simplify maintenence of the translator core once the lib is ready. + + * Changed alls instances of byte* to UCHAR* in SWAP() Function + + * Added internal return values for PUT/GET to get rid of ALL compiler warnings. + + * Updated runtime functions calling PUT()/GET()/fread()/fwrite so that they + will not trigger compiler warnings + + * Reworked the way functions declared using C_DECLARE with the LIB and ALIAS keywords + are emitted. This is so that you can dynamically load functions from a shared + library at runtime via dlopen/dlsym. + + The syntax is: + C_DECLARE FUNCTION LIB ALIAS ) AS + + For example: + C_DECLARE FUNCTION b64encode LIB "libglib-2.0.so" ALIAS "g_base64_encode" (txt AS char*, length AS integer) AS string + C_DECLARE FUNCTION g_base64_decode LIB "libglib-2.0.so" ALIAS "g_base64_decode" (txt AS char*, length AS INTEGER PTR) AS string + + NOTE that the ALIAS is the actual name of the function you want to call from the shared library. + This is so you avoid redeclaration errors if you attempt to link to a library (libm is a good example) + that is already compile-time linked with g++. + + NOTE 2: There is currently no checking whether the function was loaded without error. It is on the TODO list. + + * Changed compiler invocation to include -Wformat and -D_FORTIFY_SOURCE=2 (Ubuntu Standard) + + * Fixed User Include File handling in order to support mixed case filenames + + * Updated the CURDIR$, TEMPDIR$, AND SHELL code to eliminate warnings emitted when compiling on + a system that has "_FORTIFY_SOURCE=2" enabled by default in GCC/G++ (Ubuntu) + + * Fixed a potential overflow problem with LINE INPUT that would also cause G++ to emit + warnings as above. + + *Re-coded the $RESOURCE directive and the GETRESOURCE$ function to allow + linking of Resources under Linux/Unix. Using $RESOURCE generates a #define + allowing you to reference the embedded resource using an arbitrary IDENTIFIER. + + For example: + + DIRECTIVE FILE IDENTIFIER + ------------------------------- + $RESOURCE "file.txt" "myres" + + + Note that you reference the resource using the identifier you passed as the + SECOND parameter to the $RESOURCE directive, minus the quotes. + + "file.txt" above can be any arbitrary file on one's system + + At the moment, the resource is returned as a string with the GETRESOURCE$ function. + ***************************************************************************************************** + ** YOU WILL HAVE TO ENSURE THAT A BUFFER WITH ENOUGH SPACE TO HOLD THE RESOURCE HAS BEEN ALLOCATED ** + ***************************************************************************************************** + To aid in this, a constant is automatically created with the size of the resource. It will have the + name you specified as the second parameter to $RESOURCE, with _SIZE appended. + Using the example above, the constant would be defined as: myres_SIZE + + + You should be able to manually cast the reference *itself* to what you require, since it is + merely a pointer to the location of the resource itself. + + The resource will be converted to an object file, named using the filename provided with ".o" apppended. + "file.txt" will be converted to "file.txt.o" in the above example, which can then be linked + to the final executable via $EXECON "file.txt.o" or $EXEGUI "file.txt.o" + + * Tweaked $GUI directive and GUI keyword so that one can use the directive without + having all of the support for BCX_* form objects automatically added to one's app. + + This is usefull when using GtkBuilder or Glade to build the user interface. + +------------------------------------------- +2010-01-17 Armando Rivera +------------------------------------------- + modified the $CLASS/$ENDCLASS directives to allow creation and inheritance of C++ Classes + + modified the Function/Sub prototype emitter so that it would not emit prototypes + for C++ Class Methods, which are supposed to be prototyped within the Class itself + + made the inclusion of conditional based on whether UseCPP is true/false + it will not be included if UseCpp is "true" because some C++ toolkits (wxWidgets) + throw a "redefined" error when it's included + +------------------------------------------- +2010-01-15 Armando Rivera +------------------------------------------- + per wmhalsdorf's recommendation, modified SplitLines and Emit procs to support + C++ Method syntax (CLASSNAME::METHOD) [see Yahoo group Message #40282] + +------------------------------------------- +2010-01-10 Armando Rivera +------------------------------------------- + changed $CPP directive to output lowercase filenames + +------------------------------------------- +2009-10-18 Armando Rivera +------------------------------------------- + added Carbon.h as a default include, to support Carbon/CoreFoundation calls + added Carbon framework to $execon section + removed TRUE and FALSE defines, which are now provided by Carbon.h + changed Handle$ to Handl$ to resolve conflict with Carbon.h + +------------------------------------------- +2009-10-13 Armando Rivera +------------------------------------------- + added typedef for "byte" type (typedef unsigned char byte;) + +$COMMENT ================== END OF COMMENT SECTION ============================ + +CONST __BCX__ = 1 ' define BCX so we know we are in bc.bas +$NOMAIN +$GENFREE +$IPRINT_OFF +$NOINI +$TURBO +$HEADER +typedef long (*CPP_FARPROC)(char *); +$HEADER +ENUM + vt_UNKNOWN ' Not a Variable + vt_STRLIT ' "Quoted String Literal" + vt_INTEGER ' Integer% + vt_SINGLE ' Single! + vt_DOUBLE ' Double# + vt_LDOUBLE ' Long Double¦ + VT_LLONG ' Long Long + vt_STRVAR ' StringVariable$ + vt_DECFUNC ' Translated Decimal Func: Strlen,Asin + vt_NUMBER ' A Pure Literal Number + vt_FILEPTR ' @ FILE* + vt_UDT ' User ( or Windows ) Defined Type + vt_STRUCT ' Structures + vt_UNION ' Unions + vt_BOOL + vt_CHAR + vt_LPSTRPTR + vt_PCHAR + vt_CHARPTR + vt_VOID + vt_LONG + vt_DWORD + vt_FARPROC + vt_LPBYTE + vt_LRESULT + vt_BYTE + vt_SHORT + vt_USHORT + vt_UINT + vt_ULONG + vt_HWND + vt_HDC + vt_COLORREF + vt_HANDLE + vt_HINSTANCE + vt_WNDCLASSEX + vt_HFONT + vt_VARIANT +END ENUM +'********************************* +CONST vt_VarMin = 2 +CONST vt_VarMax = vt_VARIANT +'********************************* +ENUM + mt_ProcessSetCommand + mt_FuncSubDecC_Dec + mt_FuncSubDecC_Dec2 + mt_Opts + mt_Opts2 + mt_Opts3 + mt_OverLoad + mt_OverLoad2 + mt_FuncSubx1 + mt_FuncSubx2 +END ENUM +CONST fprintf = ReDirectFPrint +'****************************** +' User Defined Type Support +'****************************** +CONST MaxElements = 128 +CONST MaxTypes = 512 +CONST MaxLocalVars = 512 +CONST MaxGlobalVars = 4096 'max size 233000 +'****************************** +' Library Support +'****************************** +CONST MaxLib = 64 ' max no of libraries +'*********************** +' Bracket Handling +'*********************** +CONST c_SglQt = 39 +CONST c_DblQt = 34 +CONST c_LPar = 40 +CONST c_RPar = 41 +CONST c_Komma = 44 +CONST c_LtBkt = 91 +CONST c_RtBkt = 93 +'************************************************************** +' Runtime Library support +' These are used to keep Modifiers of BCX source code +' from accidently changing certain output lines of +' code that are used by the $PROJECT/Library code +'************************************************************** +CONST BCX_STR_RUNTIME = "Runtime Functions" +CONST BCX_STR_MAIN_PROG = "Main Program" +CONST BCX_STR_SYS_VARS = "System Variables" +CONST BCX_STR_STD_MACROS = "Standard Macros" +CONST BCX_STR_STD_PROTOS = "Standard Prototypes" +CONST BCX_STR_USR_PROCS = "User Subs and Functions" +CONST BCX_STR_USR_VARS = "User Global Variables" +CONST BCX_STR_USR_PROTOS = "User Prototypes" +CONST BCX_STR_USR_CONST = "User Defined Constants" +CONST BCX_STR_USR_TYPES = "User Defined Types, Classes (CPP Mode), And Unions" +'************************************************************** +TYPE functionParse + NumArgs + CommaPos[128] +END TYPE +'************************************************************** +' These need to always stay in sync +'************************************************************** +CONST VarTypes$ = "%$#!@¦" +SET VarTypeLookup[] AS CHAR PTR + "int", "int", "char *", "double", "float", "FILE *", "long double" +END SET +'************************************************************** +TYPE ARGTYPE + Arg$ + ArgType +END TYPE + +TYPE ProtoStore + Prototype$[2048] AS CHAR + Condition$[512] AS CHAR + CondLevel AS INTEGER +END TYPE + +TYPE Element + ElementType AS INTEGER + ElementID AS INTEGER + ElementDynaPtr AS INTEGER + ElementName$[64] AS CHAR +END TYPE + +TYPE UserTypeDefs + TypeofDef AS INTEGER + EleCnt AS INTEGER + Elements[MaxElements] AS Element + VarName$[64] AS CHAR +END TYPE + +TYPE VarInfo + VarLine AS INTEGER + VarType AS INTEGER + VarDef AS INTEGER + VarPntr AS INTEGER + VarSF AS INTEGER + VarExtn AS INTEGER + VarCondLevel AS INTEGER + VarEmitFlag AS INTEGER + VarConstant AS INTEGER + VarName$[64] AS CHAR + VarDim$[128] AS CHAR + VarModule[300] AS CHAR + VarCondDef[128] AS CHAR +END TYPE + +TYPE VARCODE + VarNo AS INTEGER + Method AS INTEGER + IsPtrFlag AS INTEGER + Header$ + Proto$ + Functype$ + StaticOut$ + Token$ + AsToken$ +END TYPE + +'************************************************************************* +' GLOBAL VARIABLES +'************************************************************************* +GLOBAL NoRT +GLOBAL ByrefVars$[1024] +GLOBAL ByrefCnt +GLOBAL CurLine$ +GLOBAL gLinesWritten +GLOBAL LoopLocalVar[256] +GLOBAL LoopLocalCnt +GLOBAL GlobalVarCnt +GLOBAL BaseTypeDefsCnt[16] +GLOBAL TypeDefsCnt +GLOBAL LocalVarCnt +GLOBAL LocalDynArrCount ' Local Dynamic String Array Stack Counter +GLOBAL LocalDynaCnt ' Queue Stack Counter +GLOBAL GlobalDynaCnt +GLOBAL Modules$[256] ' array of source filenames +GLOBAL ModuleNdx ' index of source files +GLOBAL ModuleLineNos[256] ' line no in source files, uses ModuleNdx also +GLOBAL FPtrNdx ' Controls $Include Files +GLOBAL FPtr [256] AS FILE ' Controls $Include Files +GLOBAL Stk$ [4096] ' Parse array +GLOBAL ProtoType [1024] AS ProtoStore ' C prototype declarations of user func's +GLOBAL SrcStk$ [128] ' used in parsing single line if-THEN-else +GLOBAL SplitStk$ [128] ' used in parsing ":" separated lines +GLOBAL SplitCnt +GLOBAL SplitCur +GLOBAL SrcTmp$ ' used for storing string to use as parameter to Parse() +GLOBAL CaseStk$ [256] ' Stack For Nested "Select Case" variable +GLOBAL CaseElseFlag [256] ' Set if Select Case contains a Case Else +GLOBAL Entry$ [256] ' Controls the $OnEntry +GLOBAL Xit$ [256] ' Controls the $OnExit +GLOBAL LocalDynArrName$ [256] ' Queues LOCAL dynamic string arrays +GLOBAL GlobalDynaStr$ [256] +GLOBAL DynaStr$ [256] ' Queues Dynamic strings in SUBS/FUNCTIONS +GLOBAL StartSub$ [32] ' user's startup code subs +GLOBAL StartNdx ' index for StartSub$ +GLOBAL ExitSub$ [32] ' user's exit code subs +GLOBAL ExitNdx ' index for ExitSub$ +GLOBAL Library$ [MaxLib] ' stores libraries to used +GLOBAL GlobalVarHash[MaxGlobalVars] +GLOBAL GlobalVars[MaxGlobalVars] AS VarInfo ' Holds global variables +GLOBAL LocalVars[MaxLocalVars] AS VarInfo ' Holds local variables +GLOBAL TypeDefs [MaxTypes] AS UserTypeDefs ' Holds typedefs +GLOBAL VarCode AS VARCODE +GLOBAL UmQt 'Handles quoted lines split with a contination _ +GLOBAL LD_FLAGS$ ' Holds Linker Flags for GUI Toolkits/OS (GTK, OSX, WXWIDGETS) +'************************************************************************************************ +GLOBAL Accelerator$ +GLOBAL CallType$ ' Calling convention cdecl, stdcall ... +GLOBAL CaseFlag +GLOBAL CaseVar$ +GLOBAL Cmd$ +GLOBAL Compiler$ +GLOBAL CmdLineConst$ +GLOBAL CmdLineFileOut$ +GLOBAL CurrentFuncType +GLOBAL DimType$ +GLOBAL DllDecl$ [800][512] AS CHAR +GLOBAL DllCnt +GLOBAL Loadlibs$ [128][512] AS CHAR +GLOBAL LoadLibsCnt +GLOBAL Elapsed AS SINGLE +GLOBAL EndOfProgram +GLOBAL EntryCnt +GLOBAL ErrFile +GLOBAL szFile$ +GLOBAL Filnam$ +GLOBAL ForceMainToFunc +GLOBAL Funcname$ +GLOBAL Handl$ +GLOBAL HFileCnt +GLOBAL HFiles$[128] +GLOBAL HFile$ +GLOBAL InConditional +GLOBAL InIfDef$ +GLOBAL Indent +GLOBAL InFunc +GLOBAL InMain +GLOBAL IsCallBack +GLOBAL TurboSize +GLOBAL UseCProto +GLOBAL InTypeDef +GLOBAL IsAuto +GLOBAL NoTypeDeclare +GLOBAL IsDim +GLOBAL IsExported +GLOBAL IsRegister +GLOBAL IsStatic +GLOBAL IsStdFunc +GLOBAL IsLocal +GLOBAL IsRaw +GLOBAL IsApple +GLOBAL KillCFile +GLOBAL Keyword1$ +GLOBAL LastCmd +GLOBAL LinesRead +GLOBAL Linker$ +GLOBAL Lookup$ +GLOBAL MakeDLL +GLOBAL Ndx +GLOBAL NoMain +GLOBAL NoDllMain +GLOBAL OkayToSend +GLOBAL Op$ +GLOBAL OptionBase +GLOBAL OutfileClone$ +GLOBAL PassOne +GLOBAL ProtoCnt +GLOBAL Pusher +GLOBAL Quiet ' no output to screen, for use with BCX Builder +GLOBAL ReDirect +GLOBAL SaveOutfileNum AS FILE +GLOBAL Scoot$ +GLOBAL ShowStatus +GLOBAL SrcCnt +GLOBAL SrcFlag +GLOBAL TrcFlag +GLOBAL TestForBcxIni +GLOBAL FileIn$ +GLOBAL FileOut$ +GLOBAL FileErr$ +GLOBAL T$ +GLOBAL Test +GLOBAL Statements +GLOBAL TestState +GLOBAL Tipe$ +GLOBAL TranslateSlash +GLOBAL TypeName$[16] +GLOBAL UseCpp +GLOBAL UseFlag '= true +'/** 2010/11/30 Added to support NameSpace - AIR 88/ +GLOBAL InNameSpace +'/***** 2010-12-01 Added to support Abstract Classes -AIR *****/ +GLOBAL Use_Virtual +GLOBAL vproc$ + +GLOBAL UseStdCall +GLOBAL UseLCaseTbl +GLOBAL Var$ +GLOBAL XitCount +GLOBAL Z$ +GLOBAL ConstLastDef$ +'********************** +GLOBAL Use_AnsiToWide +GLOBAL Use_Asc +GLOBAL Use_AppExeName +GLOBAL Use_AppExePath +GLOBAL Use_Boolstr +GLOBAL Use_Bor +GLOBAL Use_Band +GLOBAL Use_Bnot +GLOBAL Use_BcxSplitPath +GLOBAL Use_Bin +GLOBAL Use_Bin2dec +GLOBAL Use_Osx ' Used for OSX build - AIR +GLOBAL Use_Cvd +GLOBAL Use_Cvld +GLOBAL Use_Cvi +GLOBAL Use_Cvl +GLOBAL Use_Cvs +GLOBAL Use_Chr +GLOBAL Use_Cdbl +GLOBAL Use_Cldbl +GLOBAL Use_Csng +GLOBAL Use_Clear +GLOBAL Use_Cbool +GLOBAL Use_Cint +GLOBAL Use_Clng +GLOBAL Use_Cls +GLOBAL Use_Color +GLOBAL Use_Command +GLOBAL Use_ContainedIn +GLOBAL Use_Console +GLOBAL Use_CopyFile +GLOBAL Use_Static +GLOBAL Use_Crlf +GLOBAL Use_Curdir +GLOBAL Use_Del +GLOBAL Use_Download +GLOBAL Use_Dynacall +GLOBAL Use_DynamicA +GLOBAL Use_Embed +GLOBAL Use_Enclose +GLOBAL Use_Environ +GLOBAL Use_EnumFile +GLOBAL Use_Eof +GLOBAL Use_Exist +GLOBAL Use_ExitCode +GLOBAL Use_Extract +GLOBAL Use_LoadFile +GLOBAL Use_FillArray +GLOBAL Use_Findfirst +GLOBAL Use_Findnext +GLOBAL Use_FindInType +GLOBAL Use_Fint +GLOBAL Use_Fix +GLOBAL Use_FileLocked +GLOBAL Use_Frac +GLOBAL Use_Fracl +GLOBAL Use_Freefile +GLOBAL Use_Get +GLOBAL Use_GetCh +GLOBAL Use_GenFree +GLOBAL Use_Gosub +GLOBAL Use_Gtk ' GTK SUPPORT - AIR +GLOBAL Use_Glib ' GLIB SUPPORT - AIR +GLOBAL Use_Hex +GLOBAL Use_Hex2Dec +GLOBAL Use_Iif +GLOBAL Use_Imod +GLOBAL Use_Inkey +GLOBAL Use_InkeyD +GLOBAL Use_Ins +GLOBAL Use_Instr +GLOBAL Use_Inchr +GLOBAL Use_Isptr +GLOBAL Use_iReplace +GLOBAL Use_IRemove +GLOBAL Use_Instrrev +GLOBAL Use_Join +GLOBAL Use_Keypress +GLOBAL Use_Lcase +GLOBAL Use_Ldouble +GLOBAL Use_Left +GLOBAL Use_Like +GLOBAL Use_Lineinput +GLOBAL Use_Loc +GLOBAL Use_Locate +GLOBAL Use_Lof +GLOBAL Use_Lpad +GLOBAL Use_Ltrim +GLOBAL Use_Mcase +GLOBAL Use_Mid +GLOBAL Use_Midstr +GLOBAL Use_Mkd +GLOBAL Use_Mkld +GLOBAL Use_Mki +GLOBAL Use_Mkl +GLOBAL Use_Mks +GLOBAL Use_Min +GLOBAL Use_Max +GLOBAL Use_Now +GLOBAL Use_Numqsortdint +GLOBAL Use_Numqsortaint +GLOBAL Use_Numqsortdfloat +GLOBAL Use_Numqsortafloat +GLOBAL Use_Numqsortddouble +GLOBAL Use_Numqsortadouble +GLOBAL Use_Idxqsort +GLOBAL Use_IdxqsortSt +GLOBAL Use_PtrqsortSt +GLOBAL Use_Oct +GLOBAL Use_Overloaded +GLOBAL Use_OSVersion +GLOBAL Use_Pause +GLOBAL Use_PeekStr +GLOBAL Use_Put +GLOBAL Use_QBColor +GLOBAL Use_Randomize +GLOBAL Use_Rec +GLOBAL Use_RecCount +GLOBAL Use_Remain +GLOBAL Use_Remove +GLOBAL Use_Repeat +GLOBAL Use_Replace +GLOBAL Use_Reverse +GLOBAL Use_Right +GLOBAL Use_Rpad +GLOBAL Use_Rnd +GLOBAL Use_Exp +GLOBAL Use_Retain +GLOBAL Use_Round +GLOBAL Use_Rtrim +GLOBAL Use_Run +GLOBAL Use_Scan +GLOBAL Use_Inputbuffer +GLOBAL Use_SearchPath +GLOBAL Use_StrUpLow +GLOBAL Use_Shell + +'$HEADER +'static int Use_Shell; +'$HEADER + +GLOBAL Use_Sgn +GLOBAL Use_SingleFile +GLOBAL Use_Space +GLOBAL Use_Split +GLOBAL Use_DSplit +GLOBAL Use_StartupCode +GLOBAL Use_Stristr +GLOBAL Use_StrStr +GLOBAL Use_Str +GLOBAL Use_Strl +GLOBAL Use_Str_Cmp +GLOBAL Use_Strim +GLOBAL Use_String +GLOBAL Use_Strptr +GLOBAL Use_Strqsorta +GLOBAL Use_Strqsortd +GLOBAL Use_Strtoken +GLOBAL Use_DynStrqsorta +GLOBAL Use_DynStrqsortd +GLOBAL Use_Swap +GLOBAL Use_Sysdir +GLOBAL Use_SysStr +GLOBAL Use_sziif +GLOBAL Use_Tally +GLOBAL Use_Tempdir +GLOBAL Use_TempFileName +GLOBAL Use_Threads +GLOBAL Use_Time +GLOBAL Use_Timer +GLOBAL Use_Trim +GLOBAL Use_Turbo +GLOBAL Use_Ubound +GLOBAL Use_Ucase +GLOBAL Use_Using +GLOBAL Use_VChr +GLOBAL Use_Verify +GLOBAL Use_Val +GLOBAL Use_Vall +GLOBAL Use_WideToAnsi +GLOBAL Use_Wx ' WxWidgets GUI Support -AIR +GLOBAL Use_WxC '/***** 2010-11-24 WxWidgets CONSOLE ONLY support -AIR *****/ +GLOBAL Use_Ctor '/***** 2010-11-17 Added to support Constructor/Destructor Method Syntax - AIR *****/ +GLOBAL Use_Instat '/***** 2010-12-08 Added to support INSTAT keyword - AIR *****/ +GLOBAL Use_Socket '/***** 2010-12-10 Added to support Sockets -AIR *****/ +GLOBAL Use_IOS '/***** 2010-12-17 Added to support IOS -AIR *****/ +GLOBAL Use_RegEx '/***** 2013-06-26 New REGEX Keywords -AIR *****/ +'********************* +'GLOBAL S1$ ' "%s" +'GLOBAL S2$ ' "%s%s" + + +'GLOBAL U1$ + +'******************************** +' PB Compatible String Constants +'******************************** + +GLOBAL Use_BEL +GLOBAL Use_BS +GLOBAL Use_CR +GLOBAL Use_DDQ +GLOBAL Use_DQ +GLOBAL Use_EOF +GLOBAL Use_ESC +GLOBAL Use_FF +GLOBAL Use_LF +GLOBAL Use_NUL +GLOBAL Use_SPC +GLOBAL Use_TAB +GLOBAL Use_VT + +'********************* +'************************************************************** +GLOBAL prcFile$ ' translated subs and functions +GLOBAL udtFile$ ' translated User Defined Types +GLOBAL datFile$ ' translated DATA statements +GLOBAL cstFile$ ' translated CONSTants +GLOBAL ovrFile$ ' translated overloaded subs and functions +GLOBAL hdrFile$ ' user specified .h directives +GLOBAL setFile$ ' translated GLOBAL set statements +GLOBAL enuFile$ ' user GLOBAL enum blocks + +SET VarConst[2][8] AS CHAR + "", + "const " +END SET + +SET VarStorage[6][18] AS CHAR + "static ", + "extern ", + "", + "static volatile ", + "extern volatile ", + "volatile " +END SET +'************************************************************************* +' CODE BEGINS +'************************************************************************* +FUNCTION main(ARGC AS INTEGER, ARGV AS PCHAR PTR) + GLOBAL szTmp$ * 1048576 'This is a problem, cannot exceed 2047+1 or bad things *WILL* happen. + GLOBAL Src$ * 1048576 'This is a problem, cannot exceed 2047+1 or bad things *WILL* happen. + GLOBAL AbortSrc$ * 1048576 'This must be at least the size of Src$ + GLOBAL WarnMsg$ * 32767 'This must be MORE than the size of Src$ + GLOBAL RmLibs$ * 32767 ' libraries to remove + LOCAL bitz as INTEGER ' is OS 32/64 bit + ProtoCnt = 0 ' Prototypes counter + TranslateSlash = TRUE ' Default TO changing "\" TO "\\" + OkayToSend = TRUE + Use_SingleFile = TRUE + Use_StartupCode = FALSE + StartNdx = 0 + Use_ExitCode = FALSE + ExitNdx = 0 + HFile$ = "" + CmdLineFileOut$ = "" + RmLibs$ = "" + InMain = TRUE + TestState = FALSE + CmdLineConst$ = "" + '/***** 64BIT Check -AIR *****/ + bitz=SIZEOF(long)*8 + + '************************************************************************** + ' $IF __APPLE__ + ' Use_Carbon = TRUE + ' SPRINT LD_FLAGS$, "-framework Carbon" + '' LD_FLAGS = "-framework Carbon" + ' $ENDIF + + IF COMMAND$ = "" THEN + !#if defined (__APPLE__) + PRINT "MBC4: Ported to Mac OSX by Armando Rivera (c) 2009-2018" + !#else + PRINT "MBC4: Based on Linux BCX by Mike Henning (c) 2009" + PRINT "(c) 2009-2018 Armando Rivera with additional code (c) 2009 John Jacques",LF$ + !#endif + + PRINT "Version ", Version$, " Compiled with "; + $IF __BCPLUSPLUS__ + PRINT "Borland C++" + $ELSEIF __BORLANDC__ + PRINT "Borland C" + $ELSEIF __POCC__ + PRINT "Pelles C" + $ELSEIF __GNUG__ + PRINT "GNU G++" + $ELSE + PRINT "Unknown" + $ENDIF + + + '/***** 64BIT Check -AIR *****/ + IF bitz=64 THEN + PRINT + PRINT "********************" + PRINT "** 64 BIT VERSION **" + PRINT "********************",LF$ + END IF + + PRINT " Usage: ";APPEXENAME$;" infile [.bas] [options]" + PRINT " [-c] Generate C++ Compatible code" + PRINT " [-d] DEFINE a constant ... ex. ";APPEXENAME$;" MyFile -D:MyConst[=SomeValue]" + PRINT " [-e] Write ERRORS to BCX.ERR file" + PRINT " [-f] Output FILENAME... ex. ";APPEXENAME$;" MyFile -f:/MyFiles/MyFile.c" + PRINT " [-k] KILL the generated BCX generated 'C' file" + PRINT " [-o] OUTPUT a copy of the generated C file to STDOUT" + PRINT " [-q] QUIET - No output to screen during translation" + PRINT " [-s] Show STATUS of translation by line number" + PRINT " [-w] Enable WARNINGS during translation" + PRINT " [-t] TURBO Mode ON w/optional size ... ex. ";APPEXENAME$;" MyFile -t[:1024]" + PRINT " [-u] Turn UNICODE Support ON" + CALL FREEGLOBALS + END + END IF + Quiet = FALSE + FOR INTEGER i = 2 TO ARGC-1 + IF INSTR(LCASE$(ARGV$[i]),"-f") THEN CmdLineFileOut$ = MID$(ARGV$[i],4) + IF INSTR(LCASE$(ARGV$[i]),"-d") THEN CmdLineConst$ = CmdLineConst$ + MID$(ARGV$[i],4) + CHR$(1) + IF LCASE$(ARGV$[i]) = "-c" THEN UseCpp = TRUE + IF LCASE$(ARGV$[i]) = "-e" THEN ErrFile = TRUE + IF LCASE$(ARGV$[i]) = "-q" THEN Quiet = TRUE + IF LCASE$(ARGV$[i]) = "-k" THEN KillCFile = TRUE + IF LCASE$(ARGV$[i]) = "-o" THEN ReDirect = TRUE + IF LCASE$(ARGV$[i]) = "-s" THEN ShowStatus = TRUE + IF LCASE$(ARGV$[i]) = "-w" THEN TestState = TRUE + IF INSTR(LCASE$(ARGV$[i]),"-t") THEN + Use_Turbo = TRUE + TurboSize = VAL(MID$(ARGV$[i],4)) + IF TurboSize <> 0 THEN + IF (TurboSize & (TurboSize-1)) <> 0 THEN + TurboSize = 512 + Warning("Invalid $Turbo size - defaulting to 512") + END IF + ELSE + TurboSize = 512 + END IF + END IF + NEXT + '****************************** [ Announce Program ] ******************************** + IF ShowStatus THEN CLS + IF NOT Quiet THEN + CLS + + PRINT "MBC Version ", Version$ + !#if defined (__APPLE__) + IsApple = TRUE + PRINT "MBC4: Ported to Mac OSX by Armando Rivera (c) 2009-2018",LF$ + !#else + PRINT "MBC4: Based on Linux BCX by Mike Henning (c) 2009" + PRINT "(c) 2009-2018 Armando Rivera with additional code (c) 2009 John Jacques",LF$ + !#endif + + + '/***** 64BIT Check -AIR *****/ + IF bitz=64 THEN + PRINT + PRINT "********************" + PRINT "** 64 BIT VERSION **" + PRINT "********************",LF$ + END IF + END IF + '************************************************************************************ + IF INCHR(COMMAND$(1),".") THEN 'Is there a period in the filename? + Cmd$ = COMMAND$(1) ' yes, allow ANY extension + ELSE 'no period in filename + IF EXIST(COMMAND$(1) + ".bas") THEN ' check for .bas + Cmd$ = COMMAND$(1) + ".bas" + ELSEIF EXIST(COMMAND$(1) + ".BAS") THEN ' check for .BAS + Cmd$ = COMMAND$(1) + ".BAS" + END IF + END IF + IF NOT EXIST (Cmd$) THEN + PRINT + PRINT "FILE NOT FOUND: ",COMMAND$(1) + CALL FREEGLOBALS 'file not found, exit gracefully + END + END IF + + FileIn$ = Cmd + IF CmdLineFileOut$ = "" THEN + '/***** 2018-12-09 Changed default output extension to ".cc" -AIR *****/ + FileOut$ = LEFT$(Cmd$, INSTRREV(Cmd$,".",0)-1) + ".cc" + ELSE + FileOut$ = CmdLineFileOut$ + END IF + FileErr$ = LEFT$(Cmd$, INSTRREV(Cmd$,".",0)-1) + ".ERR" + IF EXIST(FileErr$) THEN + KILL FileErr$ + END IF + '******************************************************* + prcFile$ = TEMPFILENAME$(TEMPDIR$,"prc") + udtFile$ = TEMPFILENAME$(TEMPDIR$,"udt") + datFile$ = TEMPFILENAME$(TEMPDIR$,"dat") + cstFile$ = TEMPFILENAME$(TEMPDIR$,"cst") + ovrFile$ = TEMPFILENAME$(TEMPDIR$,"ovr") + hdrFile$ = TEMPFILENAME$(TEMPDIR$,"hdr") + setFile$ = TEMPFILENAME$(TEMPDIR$,"set") + 'resFile$ = TEMPFILENAME$(TEMPDIR$,"res") + enuFile$ = TEMPFILENAME$(TEMPDIR$,"enu") + '************************************************************************** + OPEN FileIn$ FOR INPUT AS SourceFile + OPEN FileOut$ FOR OUTPUT AS FP2 ' THE FINAL C FILE <<<<<<<< + '************************************************************************** + Outfile = FP2 ' Outfile = FP3 when in a SUB or FUNCTION + '************************************************************************** + OPEN prcFile$ FOR OUTPUT AS FP3 ' Temp File FOR Storing User Functions + OPEN udtFile$ FOR OUTPUT AS FP4 ' Temp File FOR Storing User Def Types + OPEN datFile$ FOR OUTPUT AS FP5 ' Temp File FOR Storing User "Data" + OPEN cstFile$ FOR OUTPUT AS FP6 ' Temp File FOR Storing User CONST + OPEN hdrFile$ FOR OUTPUT AS FP7 ' Temp File FOR Storing User .H files + OPEN ovrFile$ FOR OUTPUT AS FP8 ' Temp File FOR Storing overloaded funcs + OPEN setFile$ FOR OUTPUT AS FP9 ' Temp File FOR Storing GLOBAL SET Vars + 'OPEN resFile$ FOR OUTPUT AS FP10 ' Temp File FOR Storing User .rc files + OPEN enuFile$ FOR OUTPUT AS FP11 ' Temp File FOR Storing User global enums + '************************************************************************* + ModuleNdx = 1 + Modules$[ModuleNdx] = FileIn$ ' store the current module name + ModuleLineNos[ModuleNdx] = 0 + '************************************************************************** + CALL EmitProlog + CALL ClearIfThenStacks + CALL EmitCmdLineConst + CALL AddGlobal("G_argv",vt_PCHAR, 0,"",1,0,0,0) + CALL AddGlobal("G_argc",vt_INTEGER, 0,"",0,0,0,0) + '***************** + ' The Main LOOP + '***************** + ReadSrcLine: + '***************** + WHILE NOT EOF(SourceFile) OR SplitCnt + IF SplitCnt = 0 THEN 'Process separated lines before + LINE INPUT SourceFile,Src$ 'getting next line from file. + ModuleLineNos[ModuleNdx]++ + CALL StripCode(Src$) 'Remove spaces, tabs, comments + IF *Src = 0 THEN ITERATE + IF JoinLines(Src$) = 1 THEN ITERATE 'Join continuation lines " _" + IF INCHR(Src$,"[") THEN CALL BracketHandler(Src$,0) 'Fix Brackets + IF SplitLines(Src$) THEN Src$ = SplitStk$[++SplitCur] 'Split statements separated by + ELSE 'colons and single line if/then + Src$ = SplitStk$[++SplitCur] + END IF + IF SplitCur = SplitCnt THEN SplitCur = SplitCnt = 0 + IF *Src = 0 THEN ITERATE + AbortSrc$ = Src$ + '*************************************************************************** + ' ReProcess: ' label added for use with BCX User-Defined PreProcessor + ' so line could be changed and be run back thru BCX from start + '*************************************************************************** + IF TrcFlag AND InFunc THEN + IF NOT iMatchLft(Src$,"$trace") THEN + IF NOT iMatchLft(Src$,"end ") AND INSTR(Src$,"FUNCTION",0,1) = 0 THEN + FPRINT Outfile,"// [", TRIM$(Modules$[ModuleNdx]), " - ", TRIM$(STR$(ModuleLineNos[ModuleNdx])), "] ", Src$ + Z$ = TRIM$(Modules$[ModuleNdx]) + Z$ = REPLACE$(Z$,"\\","\\\\") + Z$ = " " + Z$ + " - " + STR$(ModuleLineNos[ModuleNdx]) + " \\n" + Z$ = "printf(" + ENC$(Z$) + ");" + FPRINT Outfile,Z$ + END IF + END IF + END IF + '****************************** + IF SrcFlag THEN + IF NOT iMatchLft(Src$,"$sourc") AND *Src <> 33 THEN '33 = ! + FPRINT Outfile,"// [", TRIM$(Modules$[ModuleNdx]), " - ", TRIM$(STR$(ModuleLineNos[ModuleNdx])), "] ", Src$ + END IF + END IF + '****************************** + IF ShowStatus THEN + LOCATE 2,1,0 + PRINT "Processing Module: ", TRIM$(Modules$[ModuleNdx]), " - Line:", ModuleLineNos[ModuleNdx] + END IF + '****************************** + IF Src[0] = 33 THEN 'Test for ! symbol -- inline C + Src[0] = 32 + FPRINT Outfile,Src$ + Src$ = "" + END IF + '****************************** + IF *Src$ = 0 THEN ITERATE + DIM RAW di + di = Directives() + IF di = 0 THEN GOTO ReadNextLine + IF di = 1 THEN GOTO ReadSrcLine + IF iMatchLft(Src$,"set ") THEN + CALL ProcessSetCommand(0) + END IF + IF iMatchLft(Src$,"sharedset ") THEN + CALL ProcessSetCommand(1) + END IF + PassOne = TRUE + '**************** + ' CallParse: + '**************** + CALL CheckParQuotes + IF SpecialCaseHandler(Src$) THEN ITERATE + CALL Parse(Src$) + PassOne = FALSE + IF Ndx THEN + CALL Emit + END IF + '**************** + ReadNextLine: + '**************** + WEND + '*************************************************** + ' END OF MAIN LOOP -- All Source code has been read + '*************************************************** + ' everything from here below must be stopped from + ' executing more than once + IF CmdLineConst$ > "" THEN + Src$ = "CONST " + CmdLineConst$ + CALL Parse (Src$) + CALL Emit + CmdLineConst$ = "" + END IF + IF TestForBcxIni = FALSE THEN + TestForBcxIni = TRUE + szFile$ = CURDIR$ + "\\bcx.ini" + IF NOT EXIST(szFile$) THEN + szFile$ = APPEXEPATH$ + "bcx.ini" + END IF + IF EXIST(szFile$) THEN + CALL PushFileIO + OPEN szFile$ FOR INPUT AS SourceFile + Modules$[++ModuleNdx] = szFile$ + ModuleLineNos[ModuleNdx] = 0 + GOTO ReadSrcLine + END IF + END IF + + + FLUSH (Outfile) '************************************* + IF FPtrNdx THEN ' Pop out the $Include File Handles + CALL PopFileIO ' and close them in sequence until + GOTO ReadSrcLine ' we end up back in the main file + END IF '************************************* + + + IF Use_GenFree AND GlobalDynaCnt THEN + CALL MakeFreeGlobals + END IF + CALL ExportInternalConst + CALL EmitEpilog + CALL CloseAll + CALL AddProtos + CALL DeclareVariables + CALL AddFuncs + CALL CloseAll + '*************************** + ' Final Disk Gymnastics + '*************************** + IF UseCpp AND CmdLineFileOut$ = "" THEN + szTmp$ = EXTRACT$(FileOut$,".") + ".cpp" + KILL szTmp$ + RENAME FileOut$, szTmp$ + FileOut$ = szTmp$ + END IF + '/***** 2015-07-03 Added to support OSX Cocoa -AIR *****/ + IF Use_Osx AND CmdLineFileOut$ = "" THEN + szTmp$ = EXTRACT$(FileOut$,".") + ".mm" + KILL szTmp$ + RENAME FileOut$, szTmp$ + FileOut$ = szTmp$ + END IF + + OPEN FileOut$ FOR INPUT AS FP1 + OPEN hdrFile$ FOR INPUT AS FP2 + OPEN "$temp$" FOR OUTPUT AS FP3 + GLOBAL DoCountLines + DoCountLines = TRUE + FPRINT FP3,"// *********************************************************************" + FPRINT FP3,"// Created with MBC (V) ", Version$, "Ported to OSX by Armando Rivera" + FPRINT FP3,"// Ported from BCX32 BASIC To C/C++ Translator (V) 5.12" + FPRINT FP3,"// BCX (c) 1999 - 2018 by Kevin Diggins" + FPRINT FP3,"// LinuxBC (c) 2009 by Mike Henning " + FPRINT FP3,"// MBC (c) 2009 - 2018 by Armando Rivera" + FPRINT FP3,"// *********************************************************************" + FPRINT FP3,"// Translated for compiling with the g++ Compiler" + IF UseCpp THEN + FPRINT FP3,"// g++ -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$.cpp -ldl -o $FILE$" + ELSE + '/***** 2018-12-09 Changed default output extension to ".cc" -AIR *****/ + FPRINT FP3,"// g++ -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$.cc -ldl -o $FILE$" + END IF + FPRINT FP3,"// *********************************************************************" + +IF NoRT=FALSE THEN + + '********* CARBON OSX SUPPORT ********* + IF Use_Osx THEN + FPRINT FP3,"#import " + END IF + '************************************** + + '********* WX WIDGETS SUPPORT ********* + /***** 2010-11-24 Added WxC FOR WX CONSOLE Apps -AIR *****/ + IF Use_Wx OR Use_WxC THEN + FPRINT FP3,"// WXWIDGETS HEADER FILES //" + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"// ******************* //" + FPRINT FP3,"" + END IF + '************************************** + + '*********** GTK SUPPORT *********** + IF Use_Gtk THEN + FPRINT FP3,"#include " + END IF + '************************************** + + '*********** GLIB SUPPORT ********** + IF Use_Glib THEN + FPRINT FP3,"#include " + END IF + '************************************** + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + !#if defined (__APPLE__) + FPRINT FP3,"#include " + !#endif + + IF UseCpp THEN + FPRINT FP3,"#include " + FPRINT FP3,"#include " + END IF + + '/***** 2010-12-08 Added to support INSTAT Keyword-AIR *****/ + IF Use_Instat THEN + Use_Keypress = true + FPRINT FP3,"#include " + END IF + + '/***** 2010-12-08 Changed to fix minor issue -AIR *****/ + IF Use_Keypress THEN + FPRINT FP3,"#include " + END IF + + '/***** 2010-12-10 Added to support Sockets -AIR *****/ + if Use_Socket then + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + FPRINT FP3,"#include " + end if + + '/***** 2013-06-26 New REGEX supprt -AIR *****/ + IF Use_RegEx then + FPRINT FP3,"#include " + END IF + + FPRINT FP3,"" + + + CALL EmitCompilerDefines + END IF 'NoRT + WHILE NOT EOF(FP2) + LINE INPUT FP2,Z$ ' Read from BCX.HDR + FPRINT FP3,Z$ ' Write to $temp$ + WEND + DIM RAW Lastlyne$ + Lastlyne$ = "" + WHILE NOT EOF(FP1) + STATIC bMainOut = 0 + LINE INPUT FP1,Z$ ' Read from "C" FileOut$ + IF iMatchLft(Lastlyne$, "#if") THEN + IF iMatchLft(Z$, "#endif") THEN + Lastlyne$ = "" + ITERATE + ELSE + FPRINT FP3, Lastlyne$ + END IF + END IF + Lastlyne$ = Z$ + IF iMatchLft(Lastlyne$, "#if") THEN ITERATE + FPRINT FP3,Z$ ' Write to $temp$ + IF bMainOut THEN ITERATE + IF LEFT$(LTRIM$(Z$),8) = "int main" THEN + WHILE TRIM$(Z$) <> "{" + LINE INPUT FP1,Z$ + FPRINT FP3,Z$ + WEND + IF Use_StartupCode THEN + FPRINT FP3,Scoot$,"int BCX_SUCode = BCX_StartupCode_(); // execute user's startup code" + END IF + IF Use_ExitCode THEN + FPRINT FP3,Scoot$,"int BCX_EXCode = BCX_ExitCode_(); // Prepare for user's exit code" + END IF + bMainOut++ + END IF + WEND + DoCountLines = FALSE + CALL CloseAll + KILL hdrFile$ + KILL FileOut$ + '*************************************************************** + RENAME "$temp$", FileOut$ ' This is our FINAL "C" File + '*************************************************************** + '******************************* + IF ShowStatus THEN LOCATE 2,1,1 + '******************************* + IF NOT Quiet THEN + INCR LinesRead, ModuleLineNos[1] + Elapsed! = ROUND((float)clock()/(float)CLOCKS_PER_SEC,2) + PRINT "[Lines In:" ; LinesRead ; "] [Lines Out:" ; gLinesWritten ; "] "; + PRINT "[Statements:" ; Statements ; "] [Time:" ; Elapsed! ; " sec's]" + Z$ = "BCX translated " + REMOVE$(FileIn$," ") + " to " + REMOVE$(FileOut$," ") + PRINT Z$ + END IF + CALL PostProcess + IF WarnMsg$ > "" THEN + PRINT "Warnings! :", CRLF$, WarnMsg$ + END IF + IF KillCFile THEN KILL FileOut$ ' -k switch issued ? + CALL FREEGLOBALS +END FUNCTION ' Function main (END of BCX Translator) +SUB EmitCmdLineConst() + IF CmdLineConst$ > "" THEN + RAW Ftmp AS FILE + FPRINT FP7, "" + FPRINT FP7, "// ***************************************************" + FPRINT FP7, "// Commandline Defines" + FPRINT FP7, "// ***************************************************" + FPRINT FP7, "" + ' Save FILE Ptr to SourceFile + Ftmp = FP6 + ' Direct output to HeaderFile + FP6 = FP7 + FOR INTEGER i = 1 TO TALLY( CmdLineConst$, CHR$(1) ) + Src$ = STRTOKEN$( CmdLineConst$, CHR$(1), i ) + IF Src$ = "" THEN EXIT + Src$ = "CONST " + Src$ ' CmdLineConst$ + CALL Parse (Src$) + CALL Emit + NEXT + CmdLineConst$ = "" + ' Restore Ptr to SourceFile + FP6 = Ftmp + FPRINT FP7, "" + END IF +END SUB 'EmitCmdLineConst +SUB EmitCompilerDefines() + FPRINT FP3,"" + FPRINT FP3,"// ***************************************************" + FPRINT FP3,"// Compiler Defines" + FPRINT FP3,"// ***************************************************" + + FPRINT FP3," #define C_EXPORT extern ", ENC$("C") + FPRINT FP3," #define C_IMPORT extern ", ENC$("C") + FPRINT FP3,"" + FPRINT FP3,"#ifndef stat" + FPRINT FP3," #define lstat stat" + FPRINT FP3,"#endif" + FPRINT FP3,"#ifndef _fcloseall" + FPRINT FP3," #define _fcloseall _fcloseall" + FPRINT FP3,"#endif" + FPRINT FP3,"#ifndef HWND" + FPRINT FP3," #define HWND GHWND" + FPRINT FP3,"#endif" + FPRINT FP3,"#ifndef MAX_PATH" + FPRINT FP3," #define MAX_PATH 2048" + FPRINT FP3,"#endif" + FPRINT FP3,"#ifndef CALLBACK" + FPRINT FP3," #define CALLBACK" + FPRINT FP3,"#endif" + FPRINT FP3,"typedef unsigned int HINSTANCE;" + 'FPRINT FP3, typedef const char CCHAR;" + FPRINT FP3,"typedef void* LPVOID;" + FPRINT FP3,"typedef char* PCHAR;" + FPRINT FP3,"typedef unsigned char BYTE;" + FPRINT FP3,"typedef unsigned int UINT;" + FPRINT FP3,"typedef unsigned char UCHAR;" + FPRINT FP3,"typedef unsigned char* PUCHAR;" + FPRINT FP3,"typedef unsigned long ULONG;" + FPRINT FP3,"typedef unsigned long* ULONG_PTR;" + FPRINT FP3,"typedef unsigned long DWORD;" + FPRINT FP3,"" + FPRINT FP3,"#ifndef TRUE" + FPRINT FP3," #define TRUE 1" + FPRINT FP3,"#endif" + FPRINT FP3,"" + FPRINT FP3,"#ifndef FALSE" + FPRINT FP3," #define FALSE 0" + FPRINT FP3,"#endif" + IF NOT Use_Osx THEN + FPRINT FP3,"#define BOOL bool" + END IF + FPRINT FP3,"" + IF UseCpp THEN + FPRINT FP3,"#define println(a) (std::cout << a << std::endl)" + 'FPRINT FP3,"#define stdstring std::string" + 'FPRINT FP3,"#define stdfile std::fstream" + FPRINT FP3," typedef std::string CSTRING;" + FPRINT FP3," typedef std::fstream CFILE;" + END IF + +END SUB 'EmitCompilerDefines + +SUB MakeFreeGlobals + Src$ = "SUB FreeGlobals" + PassOne = 1 + CALL Parse(Src$) + CALL Emit + WHILE GlobalDynaCnt + FPRINT Outfile," ", GlobalDynaStr$[GlobalDynaCnt] + GlobalDynaCnt-- + WEND + Src$ = "END SUB" + PassOne = 1 + CALL Parse(Src$) + CALL Emit +END SUB ' MakeFreeGlobals +SUB ProcessSetCommand(GS) + DIM RAW i, ii, j, SetString=0 + DIM RAW CVar$ + DIM RAW vt + LOCAL SaveFP AS FILE + SaveFP = Outfile + IF NOT InFunc THEN Outfile = FP9 ' Global context + IF INCHR(Src$,"$") AND TALLY(Src$,"[") >1 THEN + Src$ = STRIM$(Src$) + IREMOVE "as string" FROM Src$ + IREMOVE "as char" FROM Src$ + CONCAT(Src$," AS char") + END IF + CONCAT(Src$,"=") + PassOne = 1 + CALL Parse(Src$) + Tipe$ = "" + FOR i = 1 TO Ndx + IF iMatchWrd(Stk$[i],"as") THEN + Tipe$ = Stk$[i+1] + Stk$[i] = "" + Stk$[i+1] = "" + EXIT FOR + END IF + NEXT + IF Tipe$ = "" THEN + szTmp$ = Stk$[2] + SetString = DataType(Stk$[2]) + j = SetString + VarCode.Method% = mt_ProcessSetCommand + VarCode.Token$ = szTmp$ + VarCode.VarNo% = j + CALL GetVarCode(&VarCode) + IF GS THEN + FPRINT Outfile,Scoot$,REMOVE$(VarCode.StaticOut$,"static "); + ELSE + FPRINT Outfile,Scoot$,VarCode.StaticOut$; + END IF + DIM RAW lszTmp as string + lszTmp$ = "" + CVar$ = Clean$(Stk$[2]) + CALL ValidVar(CVar$) + vt = DataType(Stk$[2]) + FOR i = 3 TO Ndx + CONCAT (lszTmp$, Stk$[i]) + NEXT + IF vt = vt_STRVAR AND lszTmp$ <> "" THEN + CONCAT (lszTmp$, "[65535]") + END IF + IF NOT InFunc THEN + CALL AddGlobal(CVar$, vt, 0,lszTmp$,0,0,0,1) + ELSE + CALL AddLocal(CVar$, vt, 0,lszTmp$,0,0,1) + END IF + ELSE + CVar$ = Clean$(Stk$[2]) + IF GS THEN + FPRINT Outfile,Scoot$ ; Tipe$;" ";CVar$; + ELSE + FPRINT Outfile,Scoot$ ; "static ";Tipe$;" ";CVar$; + END IF + DIM RAW DimType$ + DIM RAW IsPointer + DIM RAW id + DimType$ = REMOVE$(Tipe$,"*") ' *mh - 3/9/09 + GetTypeInfo(Tipe$, &IsPointer, &id, &vt) + IF vt = vt_STRVAR THEN + CONCAT(DimType$, "[65535]") + END IF + IF NOT InFunc THEN + CALL AddGlobal(CVar$, vt, id, DimType$,IsPointer,0,0,1) + ELSE + CALL AddLocal(CVar$, vt, id, DimType$,IsPointer,0,1) + END IF + END IF + i = 2 + j = 0 + DO + i++ + IF Stk$[i]= "=" THEN j = 1 + IF SetString = vt_STRVAR AND j = 1 THEN + FPRINT Outfile,"[65535]="; + ELSE + FPRINT Outfile,Stk$[i]; + END IF + IF Stk$[i]= "=" THEN EXIT LOOP + IF i = Ndx THEN EXIT LOOP + LOOP + FPRINT Outfile,"" + FPRINT Outfile,"{" + WHILE NOT EOF(SourceFile) + LINE INPUT SourceFile,Src$ + ModuleLineNos[ModuleNdx]++ + CALL StripCode(Src$) + IF JoinLines(Src$) = 1 THEN ITERATE + PassOne = TRUE + CALL XParse(Src$) + PassOne = FALSE + CALL TokenSubstitutions + IF iMatchLft(Src$,"end ") THEN EXIT LOOP + IF LEN (Src$) THEN + FPRINT Outfile," "; + FOR ii = 1 TO Ndx + FPRINT Outfile, Clean$(Stk$[ii]); + NEXT ii + FPRINT Outfile,"" + END IF + WEND + FPRINT Outfile,"};\n" + Src$ = "" + Outfile = SaveFP +END SUB 'ProcessSetCommand + + +FUNCTION Directives + DIM RAW lszTmp$, i + DIM RAW COutputFile$ + ' = # = $ + IF *Src = 35 OR *Src = 36 THEN + Z$ = RTRIM$(LCASE$(LEFT$(Src$,6))) + '****************************** + SELECT CASE Z$ + '**************************** + CASE "$proje" + '**************************** + NoRT=TRUE + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$accel" + '**************************** + CALL XParse(Src$) + Accelerator$ = REMOVE$(Stk$[2],DQ$) + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$bcxve" + '**************************** + Src$ = TRIM$(MID$(Src$,12)) + REMOVE DQ$ FROM Src$ + IF LCASE$(Version$) < LCASE$(Src$) THEN + Abort (CRLF$ + "Your Translator needs updating." + CRLF$ + _ + "This program " + ENC$(Modules$[ModuleNdx]) + " requires BCX Version: " + Src$ + " or later." + CRLF$ + CRLF$) + ELSE + PRINT "" + PRINT "Program written for BCX Version ", Src$ + PRINT "" + END IF + EXIT FUNCTION + '**************************** + CASE "$compi" + '**************************** + PassOne = 1 + CALL XParse(Src$) + PassOne = 0 + Compiler$ = Stk$[2] + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$execo" + '**************************** + LOCAL SrcExt$ + PassOne = 1 + CALL XParse(Src$) + PassOne = 0 + XitCount++ + + IF UseCpp THEN + SrcExt$=".cpp" + '/***** 2015-07-03 Added to support OSX Cocoa -AIR *****/ + ELSEIF Use_Osx THEN + SrcExt$=".mm" + ELSE + '/***** 2018-12-09 Changed default output extension to ".cc" -AIR *****/ + SrcExt$=".cc" + END IF + + IF MakeDLL THEN + Xit$[XitCount]= "g++ -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$" + SrcExt$ + " -ldl " + LD_FLAGS$ + SPC$ + Stk$[2] + " -o lib$FILE$.so" + SrcExt$ = "" + Src$ = "" + EXIT FUNCTION + END IF + + '/***** 2010-12-17 Added to support IOS -AIR *****/ + IF Use_IOS THEN + LOCAL IOS_COMPILER$ + IOS_COMPILER$ = "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++" + + IF LEN(Stk$[2])>0 THEN + Xit$[XitCount]= IOS_COMPILER$ & " -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$" + SrcExt$ + " -ldl " + LD_FLAGS$ + SPC$ + Stk$[2] + " -o $FILE$" + ELSE + Xit$[XitCount]= IOS_COMPILER$ & " -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$" + SrcExt$ + " -ldl " + LD_FLAGS$ + " -o $FILE$" + END IF + SrcExt$ = "" + Src$ = "" + EXIT FUNCTION + END IF + + IF LEN(Stk$[2])>0 THEN + Xit$[XitCount]= "g++ -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$" + SrcExt$ + " -ldl " + LD_FLAGS$ + SPC$ + Stk$[2] + " -o $FILE$" + ELSE + Xit$[XitCount]= "g++ -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$" + SrcExt$ + " -ldl " + LD_FLAGS$ + " -o $FILE$" + END IF + SrcExt$ = "" + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$exest" + '**************************** + PassOne = 1 + CALL XParse(Src$) + PassOne = 0 + XitCount++ + IF IsApple then + Xit$[XitCount]= "strip $FILE$" + ELSE + Xit$[XitCount]= "strip -s -R .comment -R .note -R .note.ABI-tag $FILE$" + END IF + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$genfr" + '**************************** + Use_GenFree = TRUE + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$osx" + Use_Osx = TRUE + '/***** 2015-07-03 Changed Carbon to Cocoa, added Objc flag -AIR *****/ + '/***** 2018-12-12 Added ARC flag -AIR *****/ + LD_FLAGS$ = JOIN$(2, LD_FLAGS$," -fobjc-arc -framework Cocoa") + EXIT FUNCTION + + '/***** 2010-12-17 Added to support IOS -AIR *****/ + CASE "$ios" + !#if !defined __APPLE__ + Abort(CRLF$+"The $IOS Directive REQUIRES an Apple OSX Operating System"+CRLF$) + !#endif + Use_IOS = TRUE + PassOne = 1 + CALL XParse(Src$) + PassOne = 0 + + LD_FLAGS$ = JOIN$(2, LD_FLAGS$," -arch armv6 -arch armv7 -mthumb -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -framework Foundation -framework CoreFoundation") + + EXIT FUNCTION + + CASE "$gtk" + Use_Gtk = TRUE + LD_FLAGS$ = JOIN$(2, LD_FLAGS$," $(pkg-config --libs --cflags gtk+-2.0)") + EXIT FUNCTION + + '/***** 2018-12-12 Added to support passing ldflags -AIR *****/ + CASE "$ldfla" + LD_FLAGS$ = JOIN$(2, LD_FLAGS$, REMAIN$(Src$," ")) + EXIT FUNCTION + + '**************************** + /***** 2010-11-24 Added WxC FOR WX CONSOLE Apps -AIR *****/ + '**************************** + CASE "$wxc" + Use_WxC = UseCpp = NoMain = TRUE + LD_FLAGS$ = JOIN$(2, LD_FLAGS$, " $(wx-config --libs --cppflags)") + EXIT FUNCTION + '**************************** + CASE "$wx" + Use_Wx = UseCpp = NoMain = TRUE + LD_FLAGS$ = JOIN$(2, LD_FLAGS$, " $(wx-config --libs --cppflags)") + EXIT FUNCTION + '**************************** + CASE "$glib" + Use_Glib = TRUE + LD_FLAGS$ = JOIN$(2, LD_FLAGS$," $(pkg-config --libs --cflags glib-2.0)") + EXIT FUNCTION + '**************************** + CASE "$noini" + '**************************** + Src$ = "" + TestForBcxIni = TRUE + EXIT FUNCTION + '**************************** + CASE "$linke" + '**************************** + PassOne = 1 + CALL XParse(Src$) + PassOne = 0 + Linker$ = Stk$[2] + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$onexi" + '**************************** + PassOne = 1 + CALL XParse(Src$) + PassOne = 0 + XitCount++ + Xit$[XitCount]= Stk$[2] + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$onent" + '**************************** + PassOne = 1 + CALL XParse(Src$) + PassOne = 0 + EntryCnt++ + Entry$[EntryCnt]= Stk$[2] + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$pack","$pack(" + '**************************** + 'Src$ = EXTRACT$(Src$,"'") ' allow Basic comments + Src$ = MID$(Src$,6) + FPRINT FP4,"#pragma pack ",LTRIM$(Src$) + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$nodll" + '**************************** + NoDllMain = TRUE + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$pelle" + '**************************** + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$stdca" + '**************************** + UseStdCall = TRUE + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$iprin" + '**************************** + IF INSTR(LCASE$(Src$),"_on") THEN + TranslateSlash = TRUE + ELSE + TranslateSlash = FALSE + END IF + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$nomai" + '**************************** + NoMain = TRUE + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$test" + '**************************** + TestState = NOT TestState + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$typed" + '**************************** + FPRINT FP7,"typedef " + REMAIN$(Src$," "),";" + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$resou" + '**************************** + LOCAL resAlias$,resFile$ + Use_Embed = TRUE + PassOne = 1 + CALL XParse(Src$) + PassOne = 0 + EntryCnt++ + Entry$[EntryCnt]= "ld -r -b binary "+ Stk$[2] +" -o "+Stk$[2]+".o" + REPLACE "." WITH "_" IN Stk$[2] + resFile$=REMOVE$(Stk$[2],DQ$) + resAlias$=REMOVE$(Stk$[3],DQ$) + CALL AddGlobal("_binary_"+resFile$+"_start",vt_INTEGER, 0,"",0,0,1,0) + CALL AddGlobal("_binary_"+resFile$+"_size",vt_INTEGER, 0,"",0,0,1,0) + Src$="CONST " +resAlias$ + "= &_binary_"+resFile$+"_start" + CALL Parse(Src$) + CALL Emit + Src$="CONST " +resAlias$ + "_SIZE = (int)&_binary_"+resFile$+"_size" + CALL Parse(Src$) + CALL Emit + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$turbo" + '**************************** + Src$ = LTRIM$(MID$(Src$,7)) + IF *Src$ <> 0 THEN + TurboSize = VAL(Src$) + IF (TurboSize & (TurboSize-1)) <> 0 THEN + TurboSize = 512 + Warning("Invalid $Turbo size - defaulting to 512") + END IF + ELSE + TurboSize = 512 + END IF + Use_Turbo = TRUE + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$sourc" + '**************************** + SrcFlag = NOT SrcFlag + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$fssta" + '**************************** + Use_Static = NOT Use_Static + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$trace" + '**************************** + TrcFlag = NOT TrcFlag + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$inclu","$modul" + '**************************** + DIM RAW orgfileName$ + szFile$ = TRIM$(REMOVE$(MID$(Src$,9),DQ$)) + orgfileName$ = szFile$ + IF LEFT$(szFile$,1) = "<" THEN + szFile$ = MID$(szFile$, 2, LEN(szFile$)-2) + szFile$ = ENVIRON$("BCXLIB") + szFile$ + END IF + IF NOT EXIST(szFile$) THEN + szFile$ = BcxSplitPath$(szFile$, FNAME|FEXT) + szFile$ = BcxSplitPath$(FileIn$, FDRV|FPATH) + szFile$ + END IF + IF NOT EXIST(szFile$) THEN Abort("Unable to locate " + orgfileName$) + CALL PushFileIO + OPEN szFile$ FOR INPUT AS SourceFile + Modules$[++ModuleNdx] = szFile$ + ModuleLineNos[ModuleNdx] = 0 + FUNCTION = 1 + '**************************** + ' Beginning of Temporary Directives + ' in support of C++ Classes + '**************************** + CASE "$try" + '**************************** + FPRINT Outfile,"try {" + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$throw" + szTmp$ = MID$(Src$,8) + IF szTmp$ = "" THEN szTmp$ = ENC$("An Exception has occured!") + FPRINT Outfile,Scoot$,"throw " + szTmp$ + ";" + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$catch" + '**************************** + szTmp$ = MID$(Src$,8) + IF szTmp$ = "" THEN szTmp$ = "char *str" + FPRINT Outfile,"}" + FPRINT Outfile,"catch (" + szTmp$ + ")" ' catch (char *str) + FPRINT Outfile,"{" + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$endtr" + '**************************** + FPRINT Outfile,"}" + Src$ = "" + EXIT FUNCTION + '/** 2010/11/30 Added -AIR **/ + '**************************** + CASE "$endna" + '**************************** + InNameSpace-- + CALL BumpDown + FPRINT Outfile,Scoot$,"}" + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$names" + '**************************** + '// 2010/11/30 REMOVED $NAMESPACE + Abort("$NAMESPACE/$ENDNAMESPACE have been removed from this version. Use NAMESPACE / END NAMESPACE instead.") + '~ UseCpp = TRUE + '~ szTmp$ = MID$(Src$,INCHR(Src$," ")+1) + '~ FPRINT Outfile,"namespace " + LTRIM$(szTmp$) + '~ FPRINT Outfile,"{" + '~ '/** 2010/11/30 Added -AIR **/ + '~ InNameSpace++ + '~ CALL BumpUp + '~ Src$ = "" + '~ EXIT FUNCTION + '**************************** + CASE "$usena" + '**************************** + UseCpp = TRUE + szTmp$ = MID$(Src$, INCHR(Src$, " ") + 1) + IF RIGHT$(TRIM$(szTmp$),1) <> ";" THEN + FPRINT Outfile,"using namespace ", szTmp$, ";" + ELSE + FPRINT Outfile,"using namespace ", szTmp$ + END IF + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$class" + '**************************** + '/** 2010/11/30 REMOVED $CLASS KEYWORD/FUNCTIONALITY -AIR **/ + Abort("$CLASS has been removed from this version. Use CLASS instead.") + '~ LOCAL tmpSrc$ + '~ STATIC BeenHere + '~ UseCpp = TRUE + '~ szTmp$ = MID$(Src$, INCHR(Src$, " ") + 1) + '~ IF NOT BeenHere THEN + '~ BeenHere++ + '~ FPRINT FP4,"#ifndef __cplusplus" + '~ FPRINT FP4," #error A C++ compiler is required" + '~ FPRINT FP4,"#endif" + '~ FPRINT FP4,"" + '~ END IF + '~ '--------- BEGIN INSERT ---------------- + '~ IF INSTR(szTmp$,"inherits",0,1) THEN IREPLACE "inherits" WITH ": public" IN szTmp$ + '~ FPRINT FP4,"class ";szTmp$;" {" + '~ '--------- END INSERT ---------------- + '~ + '~ '************ + '~ WHILE NOT iMatchLft(Src$,"$endclass") + '~ IF EOF(SourceFile) THEN Abort ("$Class Without $EndClass") + '~ LINE INPUT SourceFile,Src$ + '~ tmpSrc$=TRIM$(Src$) + '~ ModuleLineNos[ModuleNdx]++ + '~ 'StripCode(Src$) + '~ '--------- BEGIN INSERT ---------------- + '~ IF iMatchLft(Src$,"$endclass") THEN + '~ FPRINT FP4,"};" + '~ '--------- END INSERT ---------------- + '~ EXIT LOOP + '~ END IF + '~ ' IF iMatchLft(tmpSrc$,"sub") THEN IREPLACE "sub" with "void" in Src$ + '~ ' IF iMatchLft(tmpSrc$,"public:") OR iMatchLft(tmpSrc$,"private:") OR iMatchLft(tmpSrc$,"DECLARE_EVENT_TABLE()") OR iMatchLft(tmpSrc$,"'") OR LEN(tmpSrc$)=0 THEN + '~ ' FPRINT FP4,Src$ + '~ ' ELSE + '~ ' FPRINT FP4,Src$;";" + '~ ' END IF + '~ WEND + '~ Src$ = "" + '~ tmpSrc$ = "" + EXIT FUNCTION + '**************************** + CASE "$inter" + '**************************** + STATIC BeenHere + UseCpp = TRUE + szTmp$ = REMAIN$(Src$, SPC$) + IF NOT BeenHere THEN + BeenHere++ + FPRINT FP4,"#ifndef __cplusplus" + FPRINT FP4," #error A C++ compiler is required" + FPRINT FP4,"#endif" + END IF + FPRINT FP4,"interface ";szTmp$;" {" '<-------------- + DO '//; changed/added by whatsup + IF EOF(SourceFile) THEN Abort ("$Interface Without $EndInterface") + LINE INPUT SourceFile,Src$ + ModuleLineNos[ModuleNdx]++ + 'StripCode(Src$) + IF iMatchLft(LTRIM$(Src$),"$endinterface") THEN + EXIT LOOP + END IF + FPRINT FP4,Src$ + LOOP + FPRINT FP4,"}";TRIM$(Src$ + 13);";" '<-------------- '//; changed/added by whatsup + '//;Src$ = "" + EXIT FUNCTION + '**************************** + ' END of Temporary Directives + ' in support of C++ Classes + '**************************** + CASE "$comme" + '**************************** + Src$ = "" + DO + IF EOF(SourceFile) THEN Abort ("Unbalanced $Comment") + LINE INPUT SourceFile,Src$ + ModuleLineNos[ModuleNdx]++ + CALL StripTabs + IF iMatchLft(LTRIM$(Src$),"$comment") THEN EXIT LOOP + FPRINT Outfile,"// ",Src$ + LOOP + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$ccode" + '**************************** + Src$ = "" + DO + IF EOF(SourceFile) THEN Abort ("Unbalanced $Ccode") + LINE INPUT SourceFile,Src$ + ModuleLineNos[ModuleNdx]++ + CALL StripTabs + IF iMatchLft(LTRIM$(Src$) ,"$ccode") THEN + IF SrcFlag THEN 'comments seem to interfere with C line continuations '\' + FPRINT Outfile,"// [", TRIM$(Modules$[ModuleNdx]), " - ", _ + TRIM$(STR$(ModuleLineNos[ModuleNdx])), "] End of $CCODE Block" + END IF + EXIT LOOP + END IF + FPRINT Outfile,RTRIM$(Src$) + LOOP + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$cprot" + '**************************** + FastLexer(Src$, SPC$, "!") + IF iMatchWrd(Stk$[2], "!") THEN + ProtoCnt++ + ProtoType[ProtoCnt].Prototype$ = REMAIN$(Src$, "!") + ProtoType[ProtoCnt].Condition$ = "" + ProtoType[ProtoCnt].CondLevel = 0 + ELSE + i = iMatchNQ(Src$, "function") + IF i = 0 THEN + i = iMatchNQ(Src$, "sub") + END IF + IF i THEN + Src$ = "c_declare " + MID$(Src$, i) + ELSE + i = iMatchNQ(Src$, "$cproto") + Src$ = "c_declare function " + MID$(Src$, i+7) + END IF + UseCProto = TRUE + FUNCTION = 2 + END IF + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$heade" + '**************************** + Src$ = "" + FPRINT FP7, "// ***************************************************" + FPRINT FP7, "" + DO + IF EOF(SourceFile) THEN Abort ("Unbalanced $Header") + LINE INPUT SourceFile,Src$ + ModuleLineNos[ModuleNdx]++ + CALL StripTabs + Src$ = TRIM$(Src$) + IF iMatchLft(Src$,"$heade") THEN EXIT LOOP + FPRINT FP7,Src$ + LOOP + Src$ = "" + FPRINT FP7, "" + EXIT FUNCTION + '**************************** + CASE "$asm" + '**************************** + IF NOT iMatchLft(Src$,"$asm") THEN + Abort ("Unknown metastatement: " + Src$) + END IF + Src$ = "" + DO + IF EOF(SourceFile) THEN Abort ("Unbalanced $Asm") + LINE INPUT SourceFile,Src$ + ModuleLineNos[ModuleNdx]++ + IF SrcFlag THEN + FPRINT Outfile,"// ",Src$ + END IF + CALL StripTabs + Src$ = TRIM$(Src$) + DIM meta_asm_loop + DIM meta_asm_comment_present AS bool + DIM Src_Len + Src_Len = LEN(Src$) + meta_asm_comment_present = FALSE + FOR meta_asm_loop = 0 TO Src_Len + '****************************************** + ' Extracts both the Basic Single Quote + ' and the Assembly Semicolon + '****************************************** + IF Src[meta_asm_loop] = 39 OR Src[meta_asm_loop] = 59 THEN + lszTmp$ = RIGHT$(Src$,Src_Len - meta_asm_loop - 1) + Src[meta_asm_loop] = 0 + meta_asm_comment_present = TRUE + EXIT LOOP + END IF + NEXT + Src$ = TRIM$(Src$) + IF iMatchLft(Src$,"$asm") THEN EXIT LOOP + REPLACE "$" WITH "0x" IN Src$ + IREPLACE "&h" WITH "0x" IN Src$ + IF Src$ <> "" THEN + Src$ = "_asm(" + ENC$(Src$) + CHR$(1) + IF meta_asm_comment_present THEN + Src$ = Src$ + TAB$ + "//" + lszTmp$ + END IF + SrcTmp$ = Src$ + FPRINT Outfile,"#if !defined( __POCC__ ) && !defined (__cplusplus )" + REPLACE CHR$(1) WITH ")" IN Src$ + FPRINT Outfile,Src$ + FPRINT Outfile,"#else" + REPLACE "_asm(" WITH "__asm{" IN SrcTmp$ + REPLACE CHR$(1) WITH "}" IN SrcTmp$ + FPRINT Outfile,REMOVE$(SrcTmp$,DQ$) + FPRINT Outfile,"#endif" + END IF + LOOP + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "#inclu" + '**************************** + '/***** 2010-11-18 Fixed this to always emit lowercase "#include" -AIR *****/ + Src$ = REMOVE$(LCASE$(Src$),"#include") + Src$ = TRIM$(Src$) + FPRINT FP7, "#include ",Src$ + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$libra" + '**************************** + 'Src$ = EXTRACT$(Src$,"'") ' allow comments + REPLACE "\\" WITH "\\\\" IN Src$ + Src$ = REMOVE$(LCASE$(Src$),"$library") + Src$ = TRIM$(Src$) + AddLibrary(Src$) + Src$ = "" + EXIT FUNCTION + '**************************** + CASE "$nolib" + '**************************** + 'Src$ = EXTRACT$(Src$,"'") ' allow comments + REPLACE "\\" WITH "\\\\" IN Src$ + Src$ = REMOVE$(LCASE$(Src$),"$nolibrary") + RemoveLibrary(Src$) + Src$ = "" + EXIT FUNCTION + END SELECT + END IF + FUNCTION = 2 +END FUNCTION ' Directives +FUNCTION SubVarType(TokenNum) + DIM RAW k, j = 0 + k = CheckLocal(Stk$[TokenNum], &j) + IF k = vt_CHAR THEN + IF *LocalVars[j].VarDim$ <> ASC("[") AND LocalVars[j].VarPntr = 0 THEN + k = vt_INTEGER + ENDIF + ELSEIF k = vt_UNKNOWN THEN + k = CheckGlobal(Stk$[TokenNum], &j) + IF k = vt_CHAR THEN + IF *GlobalVars[j].VarDim$ <> ASC("[") AND GlobalVars[j].VarPntr = 0 THEN + k = vt_INTEGER + ENDIF + ENDIF + END IF + j = ASC(RIGHT$(Stk$[TokenNum],1)) + SELECT CASE k + CASE vt_STRVAR, vt_CHAR + IF j <> 36 THEN + CONCAT (Stk$[TokenNum], "$") + END IF + CASE vt_INTEGER + IF j <> 37 THEN + CONCAT (Stk$[TokenNum], "%") + END IF + CASE vt_SINGLE + IF j <> 33 THEN + CONCAT (Stk$[TokenNum], "!") + END IF + CASE vt_DOUBLE + IF j <> 35 THEN + CONCAT (Stk$[TokenNum], "#") + END IF + CASE vt_LDOUBLE + IF j <> 166 THEN + CONCAT (Stk$[TokenNum], "¦") + END IF + END SELECT + FUNCTION = k +END FUNCTION ' SubVarType +FUNCTION PrintWriteFormat$(DoWrite) + DIM RAW Stak[128] AS ARGTYPE + DIM RAW Frmat$ + DIM RAW Arg$ + DIM RAW ZZ$ + DIM RAW Cast$ + DIM RAW NewLineFlag = 0 + DIM RAW Argcount = 0 + DIM RAW i = 0 + DIM RAW j = 0 + DIM RAW k = 0 + Frmat$ = "" + Arg$ = "" + ZZ$ = "" + IF Stk$[Ndx]= ";" THEN + NewLineFlag = TRUE + Ndx-- + END IF + IF Ndx = 1 THEN GOTO PrintWriteLabel + Stak[1].ArgType = -1 + j = 2 + WHILE j <= Ndx + IF Clean$(Stk$[j]) <> "BCX_DynaCall" THEN + i = SubVarType(j) + IF Stak[Argcount+1].ArgType = -1 THEN + IF i = vt_CHAR OR i = vt_STRVAR OR i = vt_INTEGER OR i = vt_SINGLE OR i = vt_DOUBLE OR i = vt_LDOUBLE THEN + Stak[Argcount+1].ArgType = i + END IF + END IF + IF Stk$[j] = "(" THEN + i = 0 + DO + IF Stk$[j] = "(" THEN i++ + IF Stk$[j] = ")" THEN i-- + CONCAT (Arg$,Stk$[j]) + j++ + LOOP UNTIL i <= 0 OR j >= Ndx + END IF + IF Stk$[j] = "[" THEN + i = 0 + DO + IF Stk$[j] = "[" THEN i++ + IF Stk$[j] = "]" THEN i-- + CONCAT (Arg$,Stk$[j]) + j++ + IF Stk$[j] = "[" AND i = 0 THEN ITERATE + LOOP UNTIL i <= 0 OR j >= Ndx + END IF + IF Stk$[j] = ";" OR Stk$[j] = "," OR Stk$[j] = "&" THEN + Argcount++ + Stak[Argcount].Arg$ = Arg$ + Stak[Argcount+1].ArgType = -1 + Arg$ = "" + j++ + ELSE + CONCAT (Arg$,Stk$[j]) + j++ + END IF + ELSE + CONCAT(Arg$,Stk$[j]) + j++ + END IF + WEND + Argcount++ + Stak[Argcount].Arg$ = Arg$ + Arg$ = "" + FOR i = 1 TO Argcount + j = Stak[i].ArgType + IF j = -1 THEN + ZZ$ = EXTRACT$(Stak[i].Arg$,"(") + j = DataType(ZZ$) + END IF + SELECT CASE j + CASE vt_STRLIT, vt_STRVAR, vt_CHAR + IF DoWrite THEN + Frmat$ = Frmat$ + "\\" + DQ$ + "%s" + "\\" + DQ$ + "," + ELSE + CONCAT (Frmat$,"%s") + END IF + IF LEFT$(ZZ$, 12) = "BCX_DynaCall" THEN + Arg$ = Arg$ + ",(char*)" + Stak[i].Arg$ + ELSE + Arg$ = Arg$ + "," + Stak[i].Arg$ + END IF + CASE vt_INTEGER, vt_DECFUNC + IF DoWrite THEN + Frmat$ = Frmat$ + "%d" + "," + ELSE + CONCAT (Frmat$,"%d") + END IF + Arg$ = Arg$ + ",(int)" + Stak[i].Arg$ + CASE vt_SINGLE + IF DoWrite THEN + Frmat$ = Frmat$ + "%.7G" + "," + ELSE + CONCAT (Frmat$,"%.7G") + END IF + Arg$ = Arg$ + ",(float)" + Stak[i].Arg$ + CASE vt_DOUBLE,vt_NUMBER + IF DoWrite THEN + Frmat$ = Frmat$ + "%.15G" + "," + ELSE + CONCAT (Frmat$,"%.15G") + END IF + Arg$ = Arg$ + ",(double)" + Stak[i].Arg$ + CASE vt_LDOUBLE + IF DoWrite THEN + Frmat$ = Frmat$ + "%.19LG" + "," + ELSE + CONCAT (Frmat$,"%.19LG") + END IF + Arg$ = Arg$ + ",(LDOUBLE)" + Stak[i].Arg$ + CASE ELSE + IF ASC(Stak[i].Arg$) = ASC("(") THEN + ZZ$ = "" + CONCAT(Arg$,",") + DO + k = INSTR(Stak[i].Arg$,")") + Cast$ = MID$(Stak[i].Arg$ ,1 ,k) + Stak[i].Arg$ = TRIM$(MID$(Stak[i].Arg$,k+1)) + IREPLACE "char*" WITH "char *" IN Cast$ + IREPLACE "integer" WITH "int" IN Cast$ + IREPLACE "single" WITH "float" IN Cast$ + IREPLACE "ldouble" WITH "LDOUBLE" IN Cast$ + IF ZZ$ = "" THEN + IF Cast$ = "(char *)" OR Cast$ = "(int)" OR Cast$ = "(float)" OR Cast$ = "(double)" OR Cast$ = "(LDOUBLE)" THEN + ZZ$ = Cast$ + ELSE + ZZ$ = "(double)" + Cast$ = ZZ$ + Cast$ + END IF + RemoveAll(ZZ$,"()") + IREPLACE "char *" WITH "%s" IN ZZ$ + IREPLACE "int" WITH "%d" IN ZZ$ + IREPLACE "float" WITH "%.7G" IN ZZ$ + IREPLACE "ldouble" WITH "%.19LG" IN ZZ$ + IREPLACE "double" WITH "%.15G" IN ZZ$ + END IF + CONCAT(Arg$,Cast$) + LOOP WHILE ASC(Stak[i].Arg$) = 40 + CONCAT(Arg$, Stak[i].Arg$) + CONCAT (Frmat$,ZZ$) + IF DoWrite THEN CONCAT (Frmat$,",") + ELSE + IF DoWrite THEN + Frmat$ = Frmat$ + "%G" + "," + ELSE + CONCAT (Frmat$,"%G") + Arg$ = Arg$ + ",(float)" + Stak[i].Arg$ + END IF + END IF + END SELECT + NEXT + IF DoWrite THEN Frmat$ = LEFT$(Frmat$,LEN(Frmat$)-1) + '********************* + PrintWriteLabel: + '********************* + IF NewLineFlag = 0 THEN + CONCAT (Frmat$,"\\n") + END IF + FUNCTION = "printf(" + ENC$(Frmat$) + Clean$(Arg$) + ");" +END FUNCTION ' PrintWriteFormat$ +SUB EmitInputCode + DIM RAW Argcount = 0 + DIM RAW VarCnt = 0 + DIM RAW i = 0 + DIM RAW j = 0 + DIM RAW l = 0 + DIM RAW Arg$ + DIM RAW Tmp$ + DIM RAW Frmat$ + DIM Stak$[128] + DIM RAW Y$ + DIM RAW ZZ$ + Use_Inputbuffer = TRUE + Use_Scan = TRUE + Use_Split = TRUE + Use_Remove = TRUE + Use_StrStr = TRUE + Use_Mid = TRUE + Use_Left = TRUE + Use_Instr = TRUE + Use_Stristr = TRUE + UseLCaseTbl = TRUE + UseFlag = TRUE + Use_Lineinput = TRUE + + Arg$ = "" + ZZ$ = "" + Frmat$ = "" + Tmp$ = DQ$ + "," + DQ$ + "," + DQ$ + " " + DQ$ + IF DataType(Stk$[2]) = vt_STRLIT THEN + FPRINT Outfile,Scoot$,"printf(" ; Clean$(Stk$[2]) ; ");" + END IF + IF DataType(Stk$[2]) = vt_STRLIT THEN + j = 4 + ELSE + j = 2 + END IF + l = j + WHILE j <= Ndx + IF j = l THEN + i = SubVarType(j) + END IF + IF Stk$[j] = "," THEN l = j + 1 + CONCAT(ZZ$, Stk$[j]) + j++ + WEND + FastLexer(ZZ$, "", ",") + j = 1 '0 + WHILE j <= Ndx + IF Stk$[j] = "," THEN + Argcount++ + Stak$[Argcount]= Arg$ + Arg$ = "" + j++ + ELSE + CONCAT (Arg$, Stk$[j]) + j++ + IF j < Ndx THEN + IF Stk$[j] = "[" THEN + i = 0 + DO + DoAgain: + IF Stk$[j] = "[" THEN i++ + IF Stk$[j] = "]" THEN i-- + CONCAT (Arg$,Stk$[j]) + j++ + IF Stk$[j] = "[" AND i = 0 THEN GOTO DoAgain + LOOP UNTIL i <= 0 OR j >= Ndx + END IF + END IF + END IF + WEND + Argcount++ + Stak$[Argcount] = Arg$ + Arg$ = "" + FOR i = 1 TO Argcount + Y$ = Stak$[i] + j = DataType(Y$) + SELECT CASE j + CASE vt_STRVAR + CONCAT (Frmat$,"%s") + Arg$ = Arg$ + "," + Clean$(Stak$[i]) + FPRINT Outfile,Scoot$, "*" + TRIM$(Clean$(Stak$[i])) + "=0;" + VarCnt++ + CASE vt_INTEGER + CONCAT (Frmat$,"%d") + Arg$ = Arg$ + ",&" + Clean$(Stak$[i]) + FPRINT Outfile,Scoot$, Clean$(Stak$[i]) + "=0;" + VarCnt++ + CASE vt_SINGLE + CONCAT (Frmat$,"%g") + Arg$ = Arg$ + ",&" + Clean$(Stak$[i]) + FPRINT Outfile,Scoot$, Clean$(Stak$[i]) + "=0;" + VarCnt++ + CASE vt_DOUBLE + CONCAT (Frmat$,"%lG") + Arg$ = Arg$ + ",&" + Clean$(Stak$[i]) + FPRINT Outfile,Scoot$, Clean$(Stak$[i]) + "=0;" + VarCnt++ + CASE vt_LDOUBLE + CONCAT (Frmat$,"%lG") + Arg$ = Arg$ + ",&" + Clean$(Stak$[i]) + FPRINT Outfile,Scoot$, Clean$(Stak$[i]) + "=0;" + VarCnt++ + CASE ELSE + CONCAT (Frmat$,"%d") + Arg$ = Arg$ + ",&" + Clean$(Stak$[i]) + FPRINT Outfile,Scoot$, Clean$(Stak$[i]) + "=0;" + VarCnt++ + END SELECT + NEXT + FPRINT Outfile,Scoot$, "AR_fgets_retval=fgets(InputBuffer,sizeof(InputBuffer),stdin);" + FPRINT Outfile,Scoot$, "InputBuffer[strlen(InputBuffer)-1]=0;" + FPRINT Outfile,Scoot$, "ScanError = scan(InputBuffer," + ENC$(Frmat$) + Arg$ + ");\n" + FPRINT Outfile,Scoot$, "*InputBuffer=0;" +END SUB ' EmitInputCode +SUB EmitFileInputCode + DIM RAW Argcount = 0 + DIM RAW VarCnt = 0 + DIM RAW i + DIM RAW j + DIM RAW Arg$ + DIM RAW Frmat$ + DIM RAW FHandle$ + DIM RAW Y$ + DIM RAW ZZ$ + DIM Stak$[128] + Arg$ = "" + Frmat$ = "" + ZZ$ = "" + FHandle$ = "" + Use_Inputbuffer = TRUE + Use_Scan = TRUE + Use_Split = TRUE + Use_Remove= TRUE + Use_StrStr= TRUE + Use_Mid = TRUE + Use_Left = TRUE + Use_Instr = TRUE + Use_Stristr = TRUE + UseLCaseTbl = TRUE + + i = 4 ' Extract the file handle + FOR j = 2 TO Ndx + IF *Stk$[j] = ASC(",") THEN i=j+1 : EXIT FOR + FHandle$ = FHandle$ + Stk$[j] + NEXT j + FOR j = i TO Ndx ' build the variable list + IF j = i THEN SubVarType(j) + IF Stk$[j] = "," THEN SubVarType(j+1) + CONCAT(ZZ$, Stk$[j]) + NEXT + FastLexer(ZZ$, "", ",") + j = 1 '0 + WHILE j <= Ndx + IF Stk$[j] = "," THEN + Argcount++ + Stak$[Argcount]= Arg$ + Arg$ = "" + j++ + ELSE + CONCAT (Arg$, Stk$[j]) + j++ + IF j < Ndx THEN + IF Stk$[j] = "[" THEN + i = 0 + DO + DoAgain: + IF Stk$[j] = "[" THEN i++ + IF Stk$[j] = "]" THEN i-- + CONCAT (Arg$,Stk$[j]) + j++ + IF Stk$[j] = "[" AND i = 0 THEN GOTO DoAgain + LOOP UNTIL i <= 0 OR j >= Ndx + END IF + END IF + END IF + WEND + Argcount++ + Stak$[Argcount] = Arg$ + Arg$ = "" + FOR i = 1 TO Argcount + Y$ = Stak$[i] + j = DataType(Y$) + SELECT CASE j + CASE vt_STRVAR + CONCAT (Frmat$, "%s") + Arg$ = Arg$ + "," + Clean$(Stak$[i]) + FPRINT Outfile,Scoot$, "*" + TRIM$(Clean$(Stak$[i])) + "=0;" + VarCnt++ + CASE vt_INTEGER + CONCAT (Frmat$, "%d") + Arg$ = Arg$ + ",&" + Clean$(Stak$[i]) + FPRINT Outfile,Scoot$, Clean$(Stak$[i]) + "=0;" + VarCnt++ + CASE vt_SINGLE + CONCAT (Frmat$, "%g") + Arg$ = Arg$ + ",&" + Clean$(Stak$[i]) + FPRINT Outfile,Scoot$, Clean$(Stak$[i]) + "=0;" + VarCnt++ + CASE vt_DOUBLE + CONCAT (Frmat$, "%lG") + Arg$ = Arg$ + ",&" + Clean$(Stak$[i]) + FPRINT Outfile,Scoot$, Clean$(Stak$[i]) + "=0;" + VarCnt++ + CASE vt_LDOUBLE + CONCAT (Frmat$, "%lG") + Arg$ = Arg$ + ",&" + Clean$(Stak$[i]) + FPRINT Outfile,Scoot$, Clean$(Stak$[i]) + "=0;" + VarCnt++ + CASE ELSE + CONCAT (Frmat$, "%d") + Arg$ = Arg$ + ",&" + Clean$(Stak$[i]) + FPRINT Outfile,Scoot$, Clean$(Stak$[i]) + "=0;" + VarCnt++ + END SELECT + NEXT + FPRINT Outfile,Scoot$, "AR_fgets_retval=fgets(InputBuffer,1048576," ; FHandle$ ; ");" + FPRINT Outfile,Scoot$, "if(InputBuffer[strlen(InputBuffer)-1]== 10)" + FPRINT Outfile,Scoot$, " InputBuffer[strlen(InputBuffer)-1]=0;" + FPRINT Outfile,Scoot$, "ScanError = scan(InputBuffer," + ENC$(Frmat$) + Arg$ + ");\n" + FPRINT Outfile,Scoot$, "*InputBuffer=0;" +END SUB ' EmitFileInputCode +SUB AddFuncs + DIM RAW ZZ$ + DIM RAW Last$ + Last$ = "" + CALL CloseAll + OPEN prcFile$ FOR INPUT AS FP1 + OPEN FileOut$ FOR APPEND AS Outfile + IF ProtoType[1].Prototype$ > "" THEN + FPRINT Outfile,"" + FPRINT Outfile,"// ************************************" + FPRINT Outfile,"// " + $BCX_STR_USR_PROCS + FPRINT Outfile,"// ************************************" + FPRINT Outfile,"\n" + END IF + WHILE NOT EOF(FP1) + LINE INPUT FP1,ZZ$ + '================== strip out dead callback code ====================== + IF INSTR(ZZ$,"DefWindowProc") THEN + IF INSTR(Last$,"return ") OR _ + INSTR(Last$,"CallWindowProc") OR _ + INSTR(Last$,"DefWindowProc") OR _ + INSTR(Last$,"DefMDIChildProc") OR _ + INSTR(Last$,"DefFrameProc") THEN + Last$ = "" + ITERATE + END IF + END IF + '====================================================================== + FPRINT Outfile,ZZ$ + IF LEFT$(ZZ$,2) <> "//" THEN + Last$ = ZZ$ + END IF + WEND + CALL CloseAll + KILL prcFile$ ' translated subs and functions + KILL udtFile$ ' translated User Defined Types + KILL datFile$ ' translated DATA statements + KILL cstFile$ ' translated CONSTants + KILL ovrFile$ ' translated overloaded subs and functions + KILL setFile$ ' translated KILL set statements + KILL enuFile$ ' translated GLOBAL enum blocks +END SUB ' AddFuncs +FUNCTION CheckLocal(ZZ$, BYREF varidx) + DIM RAW TT$ + IF LocalVarCnt THEN + TT$ = Clean$(ZZ$) + RemoveAll(TT$, " &*()", 1) + IF INSTR(TT$,"[") THEN TT$ = LEFT$(TT$,INSTR(TT$,"[")-1) + FOR INTEGER i = 1 TO LocalVarCnt + IF TT$ = LocalVars[i].VarName$ THEN + varidx = i + FUNCTION = LocalVars[i].VarType + END IF + NEXT + END IF + FUNCTION = vt_UNKNOWN +END FUNCTION ' CheckLocal +FUNCTION CheckGlobal(ZZ$, BYREF varidx) + DIM RAW hn + DIM RAW s + DIM RAW TT$ + TT$ = Clean$(ZZ$) + RemoveAll(TT$, " &*()", 1) + IF INSTR(TT$,"[") THEN TT$ = LEFT$(TT$,INSTR(TT$,"[")-1) + hn = HashNumber(TT$) + WHILE GlobalVarHash[hn] + s = GlobalVarHash[hn] + IF TT$ = GlobalVars[s].VarName$ THEN + varidx = s + FUNCTION = GlobalVars[s].VarType + END IF + hn = IMOD(hn + 1,MaxGlobalVars) + WEND + FUNCTION = vt_UNKNOWN +END FUNCTION ' CheckGlobal +FUNCTION CheckType(ZZ$) + DIM RAW Keyword$ + DIM RAW varid = 0 + DIM RAW i + Keyword$ = LCASE$(ZZ$) + SELECT CASE Keyword$ + CASE "int" + FUNCTION = vt_INTEGER + CASE "string" + FUNCTION = vt_STRVAR + CASE "char" + FUNCTION = vt_CHAR + CASE "pchar" + FUNCTION = vt_PCHAR + CASE "byte" + FUNCTION = vt_BYTE + CASE "double" + FUNCTION = vt_DOUBLE + CASE "ldouble" + FUNCTION = vt_LDOUBLE + CASE "file" + FUNCTION = vt_FILEPTR + CASE "float" + FUNCTION = vt_SINGLE + CASE "bool", "boolean" + FUNCTION = vt_BOOL + CASE "long" + FUNCTION = vt_LONG + CASE "dword" + FUNCTION = vt_DWORD + CASE "farproc" + FUNCTION = vt_FARPROC + CASE "void" + FUNCTION = vt_VOID + CASE "lpbyte" + FUNCTION = vt_LPBYTE + CASE "lresult" + FUNCTION = vt_LRESULT + CASE "short" + FUNCTION = vt_SHORT + CASE "ushort" + FUNCTION = vt_USHORT + CASE "uint" + FUNCTION = vt_UINT + CASE "ulong" + FUNCTION = vt_ULONG + CASE "colorref" + FUNCTION = vt_COLORREF + CASE "handle" + FUNCTION = vt_HANDLE + CASE "hdc" + FUNCTION = vt_HDC + CASE "variant" + FUNCTION = vt_VARIANT + END SELECT + i = CheckLocal(ZZ$, &varid) + IF i = vt_UNKNOWN THEN + i = DefsID(ZZ$) + IF i THEN FUNCTION = TypeDefs[i].TypeofDef + ELSE + FUNCTION = i + END IF + FUNCTION = CheckGlobal(ZZ$, &varid) +END FUNCTION ' CheckType +SUB ExportInternalConst + IF Use_FillArray THEN + Src$="CONST vt_INTEGER = 2" + PassOne = 1 + CALL Parse(Src$) + CALL Emit + Src$="CONST vt_SINGLE = 3" + PassOne = 1 + CALL Parse(Src$) + CALL Emit + Src$="CONST vt_DOUBLE = 4" + PassOne = 1 + CALL Parse(Src$) + CALL Emit + Src$="CONST vt_LDOUBLE = 5" + PassOne = 1 + CALL Parse(Src$) + CALL Emit + END IF +END SUB ' ExportInternalConst +FUNCTION RestrictedWords(ZZ$) + IF ZZ$ = "CmdLine" THEN FUNCTION = 1 + IF ZZ$ = "CmdShow" THEN FUNCTION = 1 + IF ZZ$ = "hInst" THEN FUNCTION = 1 + IF ZZ$ = "hPrev" THEN FUNCTION = 1 + IF ZZ$ = "hWnd" THEN FUNCTION = 1 + IF ZZ$ = "lParam" THEN FUNCTION = 1 + IF ZZ$ = "Msg" THEN FUNCTION = 1 + IF ZZ$ = "wParam" THEN FUNCTION = 1 + IF ZZ$ = "vt_INTEGER" THEN FUNCTION = 1 + IF ZZ$ = "vt_SINGLE" THEN FUNCTION = 1 + IF ZZ$ = "vt_DOUBLE" THEN FUNCTION = 1 + IF ZZ$ = "vt_LDOUBLE" THEN FUNCTION = 1 + FUNCTION = 0 +END FUNCTION ' RestrictedWords +FUNCTION DataType(ZZ$) + DIM RAW Keyword$ + DIM RAW i + IF ZZ[0] = 34 THEN + FUNCTION = vt_STRLIT + END IF + IF INCHR(ZZ$,"$") THEN + FUNCTION = vt_STRVAR + END IF + IF IsNumber(ZZ$) THEN + FUNCTION = vt_NUMBER + END IF + i = DefsID(ZZ$) + IF i THEN FUNCTION = TypeDefs[i].TypeofDef + '**************** + ' Functions + '**************** + Keyword$ = LCASE$(ZZ$) + IF Keyword$ = "strlen" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "instr" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "inchr" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "sizeof" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "tally" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "band" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "bor" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "lof" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "pos" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "qbcolor" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "split" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "dsplit" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "sgn" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "timer" THEN + FUNCTION = vt_SINGLE + END IF + IF Keyword$ = "keypress()" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "getattr" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "fix" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "instrrev" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "kbhit" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "exp" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "expl" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "sinh" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "cosh" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "tanh" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "asinh" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "acosh" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "atanh" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "round" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "val" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "vall" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "iif" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "bin2dec" THEN + FUNCTION = vt_INTEGER + END IF + IF Keyword$ = "hex2dec" THEN + FUNCTION = vt_INTEGER + END IF + IF Keyword$ = "rnd" THEN + FUNCTION = vt_SINGLE + END IF + IF Keyword$ = "frac" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "fracl" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "asin" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "asinl" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "hypot" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "hypotl" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "log" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "logl" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "log10" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "log10l" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "acos" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "acosl" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "atan" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "atanl" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "sin" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "sinl" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "cos" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "cosl" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "tan" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "tanl" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "pow" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "powl" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "sqrt" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "sqrtl" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "min" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "max" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "exist" THEN + FUNCTION = vt_DECFUNC + END IF + IF Keyword$ = "abs" THEN + FUNCTION = vt_DOUBLE + END IF + IF Keyword$ = "absl" THEN + FUNCTION = vt_LDOUBLE + END IF + IF Keyword$ = "freefile" THEN + FUNCTION = vt_FILEPTR + END IF + IF Keyword$ = "fint" THEN + FUNCTION = vt_INTEGER + END IF + IF INCHR(ZZ$,"%") THEN + FUNCTION = vt_INTEGER + END IF + IF INCHR(ZZ$,"!") THEN + FUNCTION = vt_SINGLE + END IF + IF INCHR(ZZ$,"#") THEN + FUNCTION = vt_DOUBLE + END IF + IF INCHR(ZZ$,"^") THEN + FUNCTION = vt_DOUBLE + END IF + IF INCHR(ZZ$,"¦") THEN + FUNCTION = vt_LDOUBLE + END IF + IF iMatchRgt(ZZ$,"@") THEN + FUNCTION = vt_FILEPTR + END IF + IF INCHR(ZZ$," ") THEN + FUNCTION = vt_UDT + END IF + IF isalpha(*ZZ$) THEN + FUNCTION = vt_INTEGER + END IF + FUNCTION = vt_UNKNOWN +END FUNCTION ' DataType +SUB CloseAll + !#if defined (__APPLE__) + CLOSE SourceFile + CLOSE FP2 + CLOSE FP3 + CLOSE FP4 + CLOSE FP5 + CLOSE FP6 + CLOSE FP7 + CLOSE FP8 + CLOSE FP9 + CLOSE FP10 + CLOSE FP11 + CLOSE Outfile + CLOSE FP1 + CLOSE ResIn + CLOSE ResOut + CLOSE UserResIn + CLOSE fpErr + CLOSE fpHFile + CLOSE FP68 + CLOSE fpdef + CLOSE SaveOutfileNum + !#else + CLOSE ' Flush and Close all open files + !#endif +END SUB ' CloseAll +FUNCTION Clean$(ZZ$) + DIM RAW Tmp$ + IF INCHR(ZZ$,"%") THEN + IF TRIM$(ZZ$) = "%" THEN FUNCTION = " % " + END IF + IF iMatchNQ(ZZ$,"!=") THEN FUNCTION = ZZ$ + Tmp$ = ZZ$ + RemoveAll(Tmp$,"%$#!@¦",1) '1 = ignore anything in quotes + FUNCTION = Tmp$ +END FUNCTION ' Clean$ +SUB RemoveAll OPTIONAL(Arg$, MatchChars$, qtflag=0) + DIM RAW C = Arg AS PCHAR + DIM RAW pmc AS PCHAR + WHILE *Arg + IF qtflag THEN + IF *Arg = 34 THEN + *(C++) = *Arg + WHILE *(++Arg) <> 34 + *(C++) = *Arg + IF *Arg = 0 THEN EXIT SUB + WEND + *(C++) = *(Arg++) + ITERATE + END IF + END IF + pmc = MatchChars + WHILE *pmc + IF *(pmc++) = *Arg THEN GOTO SKIP + WEND + *(C++) = *Arg + SKIP: + INCR Arg + WEND + *C = 0 +END SUB +SUB Warning OPTIONAL(ZZ$, WarnLvl=0) + LOCAL fErr AS FILE + IF WarnLvl THEN + WarnMsg$ = WarnMsg$ + " Line" + STR$(ModuleLineNos[ModuleNdx]) + " in Module: " + TRIM$(Modules$[ModuleNdx]) + " - " + ZZ$ + ELSE + WarnMsg$ = WarnMsg$ + ZZ$ + END IF + WarnMsg$ = WarnMsg$ + CRLF$ + IF ErrFile THEN + OPEN FileErr$ FOR APPEND AS fErr + FPRINT fErr, "WARNING ";ZZ$ + CLOSE fErr + END IF +END SUB ' Warnings +FUNCTION GetVarTypeName(i) AS PCHAR + DIM STATIC A$ + SELECT CASE i + CASE vt_INTEGER : A$ = "int" + CASE vt_STRVAR : A$ = "char *" + CASE vt_STRLIT : A$ = "STRLIT" + CASE vt_UNKNOWN : A$ = "UNKNOWN" + CASE vt_SINGLE : A$ = "float" + CASE vt_DOUBLE : A$ = "double" + CASE vt_LDOUBLE : A$ = "LDOUBLE" + CASE vt_DECFUNC : A$ = "DECFUNC" + CASE vt_NUMBER : A$ = "NUMBER" + CASE vt_FILEPTR : A$ = "FILE*" + CASE vt_UDT : A$ = "struct" + CASE vt_STRUCT : A$ = "struct" + CASE vt_UNION : A$ = "union" + CASE vt_BOOL : A$ = "bool" + CASE vt_CHAR : A$ = "char" + CASE vt_CHARPTR : A$ = "char" + CASE vt_PCHAR : A$ = "PCHAR" + CASE vt_VOID : A$ = "void" + + CASE vt_LONG : A$ = "long" + CASE vt_DWORD : A$ = "DWORD" + CASE vt_FARPROC : A$ = "FARPROC" + CASE vt_LPBYTE : A$ = "LPBYTE" + CASE vt_LRESULT : A$ = "LRESULT" + CASE vt_BYTE : A$ = "BYTE" + CASE vt_SHORT : A$ = "short" + CASE vt_USHORT : A$ = "USHORT" + CASE vt_COLORREF : A$ = "COLORREF" + CASE vt_UINT : A$ = "UINT" + CASE vt_ULONG : A$ = "ULONG" + CASE vt_HANDLE : A$ = "HANDLE" + CASE vt_HINSTANCE : A$ = "HINSTANCE" + CASE vt_HDC : A$ = "HDC" + CASE vt_VARIANT : A$ = "VARIANT" + CASE ELSE : A$ = "" + END SELECT + FUNCTION = A +END FUNCTION ' GetVarTypeName$ +FUNCTION HashNumber(HT$) + DIM RAW TT AS CHAR PTR + DIM RAW i = 0 AS ULONG + TT = HT + WHILE *TT + i <<= 1 + ! i ^= *TT; + TT++ + WEND + FUNCTION = IMOD(i,MaxGlobalVars) +END FUNCTION 'HashNumber +SUB AddLibrary( LibName$ ) + STATIC nTimes + LOCAL nLibNdx + DIM RAW TempLibName$ + TempLibName$ = LCASE$(LibName$) + IF NOT INCHR(TempLibName$,DQ$) AND NOT INCHR(TempLibName$,"<") THEN + TempLibName$ = ENC$(TempLibName$,60,62) + END IF + IF nTimes = 0 THEN + FOR INTEGER i = 0 TO MaxLib - 1 + Library$[i] = "" + NEXT + nTimes++ + Library$[0] = TempLibName$ + EXIT SUB + END IF + nLibNdx = 0 + WHILE Library$[nLibNdx] <> "" + IF Library$[nLibNdx] = TempLibName$ THEN EXIT SUB + INCR nLibNdx + WEND + IF nLibNdx < MaxLib - 1 THEN + Library$[nLibNdx] = TempLibName$ + END IF +END SUB ' AddLibrary +SUB RemoveLibrary( LibName$ ) + IF NOT INSTR( RmLibs$, LibName$, 1, 1 ) THEN + RmLibs$ = RmLibs$ + "," + LCASE$(LibName$) + END IF +END SUB ' RemoveLibrary +SUB EmitLibs() + STATIC nTimes + STATIC nCount + DIM RAW ltmp$ + IF nTimes > 0 THEN EXIT SUB + INCR nTimes + IF Library$[0] = "" THEN EXIT SUB + FPRINT FP7,"" + FPRINT FP7,"#ifndef LINUXBCX" + FPRINT FP7,"#if !defined( __LCC__ )" + FOR INTEGER i = 0 TO MaxLib - 1 + IF Library$[i] = "" AND nCount > 0 THEN + GOTO NEXTLIB + ELSEIF Library$[i] = "" THEN + GOTO NEXTLIB + END IF + ltmp$ = Library$[i] + RemoveAll(ltmp$,"<>" & DQ$) + IF INSTR( RmLibs$, ltmp$ ) THEN ITERATE ' skip libraries that have been removed + IF nCount = 0 THEN + INCR nCount + FPRINT FP7,"// *************************************************" + FPRINT FP7,"// Instruct Linker to Search Object/Import Libraries" + FPRINT FP7,"// *************************************************" + END IF + FPRINT FP7,"#pragma comment(lib,",ENC$(ltmp$), ")" + NEXT + NEXTLIB: + FPRINT FP7, "#else" + ' add lccwin32's default libraries to the remove library list so they won't be emitted + RmLibs$ = RmLibs$ + ",,,,,,,," + FOR INTEGER i = 0 TO MaxLib - 1 + IF Library$[i] = "" AND nCount > 0 THEN + FPRINT FP7,"// *************************************************" + FPRINT FP7,"// End of Object/Import Libraries To Search" + FPRINT FP7,"// *************************************************" + GOTO LIBEND + ELSEIF Library$[i] = "" THEN + GOTO LIBEND + END IF + IF INSTR( RmLibs$, Library$[i] ) THEN ITERATE ' skip libraries that have been removed + IF nCount = 0 THEN + INCR nCount + FPRINT FP7,"" + FPRINT FP7,"// *************************************************" + FPRINT FP7,"// Instruct Linker to Search Object/Import Libraries" + FPRINT FP7,"// *************************************************" + END IF + FPRINT FP7,"#pragma lib ",Library$[i] + NEXT + LIBEND: + FPRINT FP7,"#endif" + FPRINT FP7,"#endif // LINUXBCX not defined" +END SUB ' EmitLibs +SUB AddGlobal OPTIONAL(GlobalName$, GlobalType, GlobalDef, GlobalDim$, GlobalPtr, GlobalFS, GlobalExtn, iEmitted, iConst=0) + DIM RAW FirstVar$ + DIM RAW SecondVar$ + DIM RAW Warn$ + DIM RAW ss + DIM RAW s + IF RestrictedWords(GlobalName$) AND TestState THEN + Warn$ = "Restricted Word " + GlobalName$ + " on Line" + Warn$ = Warn$ + STR$(ModuleLineNos[ModuleNdx]) + " in Module: " + TRIM$(Modules$[ModuleNdx]) + CALL Warning(Warn$) + END IF + ss = HashNumber(GlobalName$) + WHILE GlobalVarHash[ss] + s = GlobalVarHash[ss] + IF GlobalName$ = GlobalVars[s].VarName$ THEN + IF InConditional = 0 OR (InConditional > 0 AND InIfDef$ = GlobalVars[s].VarCondDef$) THEN + IF GlobalVars[s].VarType <> GlobalType OR _ + GlobalDim$ <> GlobalVars[s].VarDim$ OR _ + GlobalVars[s].VarDef <> GlobalDef THEN + FirstVar$ = "Line" + STR$(ModuleLineNos[ModuleNdx]) + " in Module: " + TRIM$(Modules$[ModuleNdx]) + " : " + GlobalName$ + GlobalDim$ + " as " + GetVarTypeName$(GlobalType) + " " + TypeDefs[GlobalDef].VarName$ + SecondVar$ = "Line" + STR$(GlobalVars[s].VarLine) + " in Module: " + GlobalVars[s].VarModule + " : " + GlobalName$ + GlobalVars[s].VarDim$ + " as " + GetVarTypeName$(GlobalVars[s].VarType) + " " + TypeDefs[GlobalVars[s].VarDef].VarName$ + Warn$ = "Two Variables " + FirstVar$ + " previously defined at " + SecondVar$ + CALL Warning(Warn$) + END IF + EXIT SUB + END IF + END IF + ss = IMOD(ss + 1,MaxGlobalVars) + WEND + GlobalVarCnt++ + IF GlobalVarCnt = MaxGlobalVars THEN Abort("Maximum Global Variables reached.") + GlobalVars[GlobalVarCnt].VarName$ = GlobalName$ + GlobalVars[GlobalVarCnt].VarType = GlobalType + GlobalVars[GlobalVarCnt].VarDef = GlobalDef + GlobalVars[GlobalVarCnt].VarDim$ = GlobalDim$ + GlobalVars[GlobalVarCnt].VarLine = ModuleLineNos[ModuleNdx] + GlobalVars[GlobalVarCnt].VarPntr = GlobalPtr + GlobalVars[GlobalVarCnt].VarSF = GlobalFS + GlobalVars[GlobalVarCnt].VarEmitFlag = iEmitted + GlobalVars[GlobalVarCnt].VarModule$ = TRIM$(Modules$[ModuleNdx]) + GlobalVars[GlobalVarCnt].VarExtn = GlobalExtn + GlobalVars[GlobalVarCnt].VarCondLevel = InConditional + GlobalVars[GlobalVarCnt].VarConstant = iConst + GlobalVars[GlobalVarCnt].VarCondDef$ = InIfDef$ + GlobalVarHash[ss] = GlobalVarCnt +END SUB ' AddGlobal + + + + + +SUB AddLocal OPTIONAL(LocalName$, LocalType, LocalDef, LocalDim$, LocalPtr, LocalFS, iEmitted, iConst=0) + DIM RAW varid = 0 + DIM RAW FirstVar$ + DIM RAW SecondVar$ + DIM RAW Warn$ + DIM RAW s + IF LocalVarCnt AND TestState THEN + IF CheckGlobal(LocalName$, &varid) <> vt_UNKNOWN THEN + IF LocalDef THEN + FirstVar$ = "Line" + STR$(ModuleLineNos[ModuleNdx]) + " in Module: " + TRIM$(Modules$[ModuleNdx]) + " : " + LocalName$ + LocalDim$ + " as " + TypeDefs[LocalDef].VarName$ + ELSE + FirstVar$ = "Line" + STR$(ModuleLineNos[ModuleNdx]) + " in Module: " + TRIM$(Modules$[ModuleNdx]) + " : " + LocalName$ + LocalDim$ + " as " + GetVarTypeName$(LocalType) + END IF + IF GlobalVars[varid].VarDef THEN + SecondVar$ = "Line" + STR$(GlobalVars[varid].VarLine) + " in Module: " + GlobalVars[varid].VarModule + " : " + LocalName$ + GlobalVars[varid].VarDim$ + " as " + TypeDefs[GlobalVars[varid].VarDef].VarName$ + ELSE + SecondVar$ = "Line" + STR$(GlobalVars[varid].VarLine) + " in Module: " + GlobalVars[varid].VarModule + " : " + LocalName$ + GlobalVars[varid].VarDim$ + " as " + GetVarTypeName$(GlobalVars[varid].VarType) + END IF + Warn$ = "Local Variable " + FirstVar$ + CRLF$ + "Has Same Name as Global " + SecondVar$ + CALL Warning(Warn$) + END IF + FOR s = 1 TO LocalVarCnt + IF LocalName$ = LocalVars[s].VarName$ THEN + IF LocalVars[s].VarType <> LocalType OR LocalDim$ <> LocalVars[s].VarDim$ OR LocalVars[s].VarDef <> LocalDef THEN + FirstVar$ = "Line" + STR$(ModuleLineNos[ModuleNdx]) + " in Module: " + TRIM$(Modules$[ModuleNdx]) + " : " + LocalName$ + LocalDim$ + " as " + GetVarTypeName$(LocalType) + " " + TypeDefs[LocalDef].VarName$ + SecondVar$ = "Line" + STR$(LocalVars[s].VarLine) + " in Module: " + LocalVars[s].VarModule + " : " + LocalName$ + LocalVars[s].VarDim$ + " as " + GetVarTypeName$(LocalVars[s].VarType) + " " + TypeDefs[LocalVars[s].VarDef].VarName$ + Warn$ = "Two Variables " + FirstVar$ + " previously defined at " + SecondVar$ + CALL Warning(Warn$) + END IF + EXIT SUB + END IF + NEXT + END IF + LocalVarCnt++ + IF LocalVarCnt = MaxLocalVars THEN + Warn$ = "Maximum Local Variables reached." + Abort(Warn$) + END IF + LocalVars[LocalVarCnt].VarName$ = LocalName$ + LocalVars[LocalVarCnt].VarType = LocalType + LocalVars[LocalVarCnt].VarDef = LocalDef + LocalVars[LocalVarCnt].VarDim$ = LocalDim$ + LocalVars[LocalVarCnt].VarLine = ModuleLineNos[ModuleNdx] + LocalVars[LocalVarCnt].VarPntr = LocalPtr + LocalVars[LocalVarCnt].VarSF = LocalFS + LocalVars[LocalVarCnt].VarEmitFlag = iEmitted + LocalVars[LocalVarCnt].VarConstant = iConst + LocalVars[LocalVarCnt].VarModule$= TRIM$(Modules$[ModuleNdx]) +END SUB ' AddLocal +FUNCTION IsNumber(a$) + DIM RAW i = 0 + IF NOT *a THEN FUNCTION = FALSE ' Handle null arguments + WHILE a[i] ' While NOT null terminator + IF a[i]>47 AND a[i]<58 THEN ' Test for 0123456789 + i++ ' bump our index + ELSE + FUNCTION = FALSE ' a$ is not a number + END IF ' + WEND ' + FUNCTION = TRUE ' a$ is a number +END FUNCTION ' IsNumber +FUNCTION IsNumberEx(a$) + DIM RAW i = 0 + IF NOT *a THEN FUNCTION = FALSE ' Handle null arguments + WHILE a[i] ' While NOT null terminator + IF a[i]>44 AND a[i]<58 THEN ' Test FOR -+.0123456789 + i++ ' bump our index + ELSE + FUNCTION = FALSE ' a$ is not a number + END IF ' + WEND ' + FUNCTION = TRUE ' a$ is a number +END FUNCTION ' IsNumberEx +SUB StripTabs + DIM RAW i = 0 + WHILE Src[i] + IF Src[i] = 9 THEN Src[i] = 32 + i++ + WEND +END SUB ' StripTabs +SUB PushFileIO + FPtr[++FPtrNdx] = SourceFile +END SUB 'PushFileIO +SUB PopFileIO + IF FPtrNdx = 0 THEN EXIT SUB + CLOSE SourceFile + INCR LinesRead, ModuleLineNos[ModuleNdx--] + SourceFile = FPtr[FPtrNdx--] +END SUB 'PopFileIO +FUNCTION Inset(Mane$,Match$) + DIM RAW i = -1, j = -1 + WHILE Match[++i] + WHILE Mane[++j] + IF Match[i] = Mane[j] THEN FUNCTION = TRUE + WEND + j = -1 + WEND + FUNCTION = FALSE +END FUNCTION 'Inset +SUB CheckParQuotes + DIM RAW CountR=0 'Round bracket counter + DIM RAW CountS=0 'Square bracket counter + DIM RAW i=0 + DIM RAW DoCount = TRUE AS bool + WHILE Src[i] + IF Src[i]=34 THEN + DoCount = NOT DoCount + END IF + IF DoCount THEN + IF Src[i]=40 THEN + CountR++ + ELSEIF Src[i]=41 THEN + CountR-- + ELSEIF Src[i]=91 THEN + CountS++ + ELSEIF Src[i]=93 THEN + CountS-- + END IF + END IF + i++ + WEND + IF NOT DoCount THEN + Abort ("Unmatched Quotes") + ELSEIF CountS THEN + Abort ("Unmatched []") + ELSEIF CountR THEN + Abort ("Unmatched ()") + END IF +END SUB ' CheckParQuotes +SUB ClearIfThenStacks + FOR INTEGER i = 0 TO 127 + SrcStk$[i] = "" + NEXT + SrcCnt = 0 +END SUB ' ClearIfThenStacks +FUNCTION IsQuoted(ZZ$) + IF NOT iMatchLft(LTRIM$(ZZ$),DQ$) THEN EXIT FUNCTION + IF NOT iMatchRgt(RTRIM$(ZZ$),DQ$) THEN EXIT FUNCTION + FUNCTION = TRUE +END FUNCTION ' IsQuoted +SUB PostProcess + DIM RAW A + IF ReDirect = TRUE THEN + OPEN FileOut$ FOR INPUT AS FP1 + WHILE NOT EOF(FP1) + LINE INPUT FP1,Z$ + PRINT Z$ + WEND + CALL CloseAll + END IF + '************************** + OutfileClone$ = FileOut$ + FOR A = 1 TO EntryCnt + OutfileClone$ = EXTRACT$(OutfileClone$,".") + Cmd$ = REMOVE$(Entry$[A],DQ$) + REPLACE "\\\\" WITH "\\" IN Cmd$ + IREPLACE "$file$" WITH EXTRACT$(OutfileClone$,".") IN Cmd$ + PRINT "Shelling Out To: ", Cmd$ + SHELL Cmd$ + NEXT + IF Compiler$ > "" THEN + Compiler$ = TRIM$(REMOVE$(Compiler$,DQ$)) + IF INCHR(Compiler$, " ") THEN + Compiler$ = ENC$(EXTRACT$(Compiler$," ")) + " " + REMAIN$(Compiler$," ") + ELSE + Compiler$ = ENC$(Compiler$) + END IF + '/***** 2018-12-09 Changed default output extension to ".cc" -AIR *****/ + FileOut$ = EXTRACT$(FileOut$,".") + ".cc" + Compiler$ = Compiler$ + " " + FileOut$ + IREPLACE "$FILE$" WITH EXTRACT$(OutfileClone$,".") IN Compiler$ + REPLACE "\\\\" WITH "\\" IN Compiler$ + REPLACE DDQ$ WITH DQ$ IN Compiler$ + PRINT "Shelling Out To: ", Compiler$ + SHELL Compiler$ + END IF + '************************** + IF Linker$ > "" THEN + Linker$ = TRIM$(REMOVE$(Linker$,DQ$)) + IF INCHR(Linker$, " ") THEN + Linker$ = DQ$ + EXTRACT$(Linker$," ") + DQ$ + " " + REMAIN$(Linker$," ") + ELSE + Linker$ = ENC$(Linker$) + END IF + FileOut$ = EXTRACT$(FileOut$,".") + ".obj" + Linker$ = Linker$ + " " + FileOut$ + IREPLACE "$FILE$" WITH EXTRACT$(OutfileClone$,".") IN Linker$ + REPLACE "\\\\" WITH "\\" IN Linker$ + REPLACE DDQ$ WITH DQ$ IN Linker$ + PRINT "Shelling Out To:", Linker$ + SHELL Linker$ + END IF + '************************** + FOR A = 1 TO XitCount + FileOut$ = EXTRACT$(FileOut$,".") + Cmd$ = REMOVE$(Xit$[A],DQ$) + IREPLACE "$FILE$" WITH EXTRACT$(OutfileClone$,".") IN Cmd$ + REPLACE "\\\\" WITH "\\" IN Cmd$ + REPLACE DDQ$ WITH DQ$ IN Cmd$ + PRINT "Shelling Out To: ", Cmd$ + SHELL Cmd$ + NEXT +END SUB ' PostProcess +SUB XParse(Arg$) + DIM RAW lszTmp$ + DIM RAW j, i = 0, Gapflag = 0 + DIM RAW InIF = 0 + IF TRIM$(Arg$) = "" THEN + Ndx = 0 + EXIT SUB + END IF + '----------------------------------------------- + ' A temporary cure to allow the C '&&' operator + '----------------------------------------------- + i = iMatchNQ(Arg$, "&&") + WHILE i + Arg$ = DEL$(Arg$, i, 2) + Arg$ = INS$(Arg$, i, " and ") + i = iMatchNQ(Arg$, "&&") + WEND + '----------------------------------------------- + FastLexer(Arg$, SPC$, "=&()[]{}',+-*/<>?;.|:^") + '**************************************** + ' Pre Parse + '**************************************** + WHILE ++i < 17 + Stk$[i+Ndx] = "" + WEND + FOR i = 1 TO Ndx + Keyword1$ = LCASE$(Stk$[i]) + IF Keyword1[1] <> 0 THEN + SELECT CASE Keyword1$ + CASE "and" : Stk$[i] = "&&" + CASE "or" : Stk$[i] = "||" + CASE "not" : Stk$[i] = "!" + CASE "is" : Stk$[i] = "=" + CASE "xor" : Stk$[i] = "xor" + CASE "if","iif","iif$","case","elseif","while" + InIF = 1 + CASE "then" + InIF = 0 + CASE "byval" + Stk$[i] = "" + Gapflag = TRUE + CASE "byref" + IF NOT iMatchWrd(Stk$[1], "declare") AND _ + NOT iMatchWrd(Stk$[1], "c_declare") THEN + ByrefVars$[++ByrefCnt] = Stk$[i+1] + END IF + FOR j = i TO Ndx + IF Stk$[j+1] = "," OR Stk$[j+1] = ")" THEN + Stk$[j] = "PTR" + EXIT FOR + END IF + Stk$[j] = Stk$[j+1] + NEXT + CASE ELSE + IF PassOne THEN + IF Keyword1$ = ENC$(CHR$(92)) THEN + Stk$[i] = "chr$" + InsertTokens(i, 3, "(", "92", ")") + INCR i,3 + ELSEIF TranslateSlash THEN + REPLACE "\\" WITH "\\\\" IN Stk$[i] + END IF + END IF + END SELECT + '******************************************************************* + ' Allow logical 'OR/AND' to be used as 'binary BOR/BAND' + '******************************************************************* + IF NOT InIF THEN + IF Stk$[i] = "&&" THEN + Stk$[i] = "BAND" + ELSEIF Stk$[i] = "||" THEN + Stk$[i] = "BOR" + END IF + END IF + ELSE + SELECT CASE ASC(Keyword1$) + ' -------------------------------- + ' Connect (&)addressof operator. + ' -------------------------------- + CASE ASC("&") + IF i < 3 OR INCHR("+&,(=", Stk$[i-1]) THEN + Stk$[i+1] = " &" + Stk$[i+1] + Stk$[i] = "" : Gapflag=TRUE + END IF + CASE ASC("?") + Stk$[i] = "print" + CASE ASC("-") + IF ASC(Stk$[i+1]) = ASC(">") THEN + Stk$[i] = "->" & Stk$[i+2] + Stk$[++i] = "" : Stk$[++i] = "" + Gapflag=TRUE + END IF + CASE ASC(".") + IF IsNumber(Stk$[i-1]) THEN + Stk$[i] = Stk$[i-1] & "." + Stk$[i-1] = "" : Gapflag=TRUE + END IF + IF NOT INCHR( ",)=<>*/+-^" , Stk[i+1]) THEN + Stk$[i] = Stk$[i] & Stk$[i+1] + Stk$[++i] = "" : Gapflag=TRUE + END IF + END SELECT + END IF + NEXT i + IF Gapflag THEN + FOR i = 1 TO Ndx + IF NOT *Stk[i] THEN + j = i + 1 + WHILE NOT *Stk[j] AND (j < Ndx) + INCR j + WEND + IF NOT *Stk[j] THEN EXIT FOR + Stk$[i] = Stk$[j] : Stk$[j] = "" + END IF + NEXT i + Ndx = i-1 + END IF + ' ******************************************************************* + ' Special Case Handler: BYREF - BCX prepends * to BYREF'd Variables + ' ******************************************************************* + IF PassOne = 1 THEN + IF InFunc THEN ' Must be in a SUB or FUNCTION + FOR i = 1 TO Ndx + FOR j = 1 TO ByrefCnt + IF iMatchLft(Stk$[i], " &") THEN lszTmp$ = Stk$[i] + 2 ELSE lszTmp$ = Stk$[i] + IF Clean$(lszTmp$) = Clean$(ByrefVars[j]) THEN + IF i > 2 THEN + IF INCHR("+-^%*/|&<=>,", Stk$[i-2]) AND Stk$[i-1] = "*" THEN + Stk$[i-1] = "" + END IF + IF iMatchLft(Stk$[i], " &") THEN + Stk$[i] = Stk$[i] + 2 + EXIT FOR + END IF + ELSEIF i = 2 THEN + IF Stk$[i-1] = "*" THEN Stk$[i-1] = "" + END IF + Stk$[i] = "*" & Stk$[i] + IF Stk$[i-1] <> "(" OR Stk$[i+1] <> ")" THEN + Stk$[i] = ENC$(Stk$[i], ASC("("), ASC(")")) + END IF + EXIT FOR + END IF + NEXT + NEXT + END IF + END IF + ' ******************************************************************* + ' Special Case Handler: DIM BLAHBLAH[22][33] AS STATIC INTEGER + ' ******************************************************************* + IF iMatchWrd(Stk$[1],"dim") THEN + IF iMatchWrd(Stk$[Ndx-1],"static") THEN + Stk$[1] = "static" + Stk$[Ndx-1] = Stk$[Ndx] + Ndx-- + END IF + END IF + ' *************************************************************************** + ' Special Case Handler: In the contexts of UDT,s this handler transforms: + ' FUNCTION Foo (a as integer) AS INTEGER to: + ' DIM FUNCTION Foo (a as integer) AS INTEGER + ' + ' Change "as string" to "as char *" for UDTs and Declarations + ' *************************************************************************** + Keyword1$ = LCASE$(Stk$[1]) + IF InTypeDef THEN + IF Keyword1$ <> "end" AND Keyword1$ <> "dim" AND Keyword1$ <> "declare" AND Keyword1$ <> "type" AND Keyword1$ <> "union" THEN + InsertTokens(0, 1, "dim") + END IF + END IF + '****************************** + ' + '****************************** + IF NOT InTypeDef THEN + DIM RAW lsz$, Res = 1 + lsz$ = SPC$ & Keyword1$ & SPC$ + IF iMatchNQ(" dim , local , global , raw , static , shared , dynamic , auto , register , extern ", lsz$) THEN + Res = 1 + END IF + lsz$ = SPC$ & LCASE$(Stk$[2]) & SPC$ + IF iMatchNQ(" dim , local , global , raw , static , shared , dynamic , auto , register , extern ", lsz$) THEN + Res = 2 + END IF + IF Res > 0 THEN + i = Ndx + WHILE i > 1 AND Stk$[i] <> ")" + IF iMatchWrd(Stk$[i], "as") THEN + IF iMatchWrd(Stk$[i+1], "function") THEN + IF i+1 = Ndx THEN Stk$[i] = "" ' remove "as" + Stk$[i+1] = "" + InsertTokens(Res, 1, "function") + ELSEIF iMatchWrd(Stk$[i+1], "sub") THEN + IF i+1 = Ndx THEN Stk$[i] = "" ' remove "as" + Stk$[i+1] = "" + InsertTokens(Res, 1, "sub") + END IF + CALL RemEmptyTokens + EXIT WHILE + END IF + DECR i + WEND + END IF + END IF + IF InTypeDef OR iMatchWrd(Stk$[1], "declare") OR iMatchWrd(Stk$[1], "c_declare") THEN + IF iMatchWrd(Stk$[2],"sub") OR iMatchWrd(Stk$[2],"function") THEN + FOR INTEGER i = 2 TO Ndx + IF iMatchLft(Stk$[i],"as") AND iMatchWrd(Stk$[i+1],"string") THEN + IF *Stk$[i+2] <> ASC("*") THEN Stk$[i+1] = "char *" + END IF + NEXT + END IF + END IF +END SUB 'XParse +SUB TokenSubstitutions + '***************************** + ' Start Doing Text Substitutions + '***************************** + DIM RAW A + DIM RAW CompPtr + DIM RAW CompToken + DIM RAW Keyword$ + DIM RAW a, i, j, Tmp + '****************************************************************************************** + ' Following block added in 4.13 -- Dim XXX as string * 12345 + ' Works in UDT, GLOBALS, LOCALS, and RAW + '****************************************************************************************** + FOR i = 1 TO Ndx + IF iMatchWrd(Stk$[i],"as") THEN + IF iMatchWrd(Stk$[i+1],"string") THEN + IF Stk$[i+2] = "*" THEN + Stk$[i] = "[" + Stk$[i+1] = Stk$[i+3] + Stk$[i+2] = "]" + Stk$[i+3] = "as" + INCR Ndx + Stk$[Ndx] = "char" + EXIT FOR + END IF + END IF + END IF + NEXT + '****************************************************************************************** + FOR i = 1 TO Ndx + IF NOT InFunc THEN + IF iMatchWrd(Stk$[i],"global") THEN Stk$[i] = "dim" + END IF + NEXT + A = FALSE + FOR Tmp = 1 TO Ndx + IF *Stk[Tmp] = ASC("0") AND Stk[Tmp][1] <> ASC("x") AND Stk[Tmp][1] <> ASC("l") THEN + Stk$[Tmp] = LTRIM$(Stk$[Tmp],48) 'allow leading zero's in numbers + IF Stk$[Tmp] = "" THEN Stk$[Tmp] = "0" + END IF + IF iMatchWrd(Stk$[Tmp],"xor") THEN + Stk$[Tmp] = "^" + ELSEIF Stk$[Tmp] = "=" AND Stk$[Tmp+1]= ">" THEN + Stk$[Tmp] = ">" + Stk$[Tmp+1]= "=" + ELSEIF Stk$[Tmp] = "=" AND Stk$[Tmp+1]= "<" THEN + Stk$[Tmp] = "<" + Stk$[Tmp+1] = "=" + ELSEIF Stk$[Tmp] = "<" AND Stk$[Tmp+1]= ">" THEN + Stk$[Tmp] = "!=" + Stk$[Tmp+1] = "" + A = TRUE + ELSEIF Stk$[Tmp] = ">" AND Stk$[Tmp+1]= "<" THEN + Stk$[Tmp] = "!=" + Stk$[Tmp+1] = "" + A = TRUE + ELSEIF Stk$[Tmp]= "!" AND Stk$[Tmp+1]= "=" THEN + Stk$[Tmp]= "!=" + Stk$[Tmp+1] = "" + A = TRUE + END IF + NEXT + IF A = TRUE THEN CALL RemEmptyTokens + '************************************************************************* + ' needed when recursively calling parse() after <> has already translated + ' to != Otherwise, on pass 2, it emits as !== which is NOT desired. + '************************************************************************* + CompToken = 0 + FOR Tmp = 1 TO Ndx + A = CheckLocal(Stk$[Tmp], &i) + IF A = vt_UNKNOWN THEN A = CheckGlobal(Stk$[Tmp], &i) + IF A = vt_STRUCT OR A = vt_UDT OR A = vt_UNION THEN + CompToken = 1 + END IF + IF iMatchWrd(Stk$[Tmp],"int") AND Stk$[Tmp+1] = "(" THEN + Stk$[Tmp]= "fint" + ELSEIF iMatchWrd(Stk$[Tmp],"integer") THEN + Stk$[Tmp]= "int" + ELSEIF iMatchWrd(Stk$[Tmp],"fint") AND Stk$[Tmp+1]= ")" THEN + Stk$[Tmp]= "int" + END IF + NEXT + '***************************** + CompPtr = 0 + FOR Tmp = 1 TO Ndx + Keyword$ = LCASE$(Stk$[Tmp]) + a = INCHR("abcdefghijklmnopqrstuvwxyz", Keyword$) + SELECT CASE a + CASE 1 + SELECT CASE Keyword$ + CASE "abs" + Stk$[Tmp]= "abs" ' might need fabs + CASE "acos" + Stk$[Tmp]= "acos" + CASE "acosl" + Stk$[Tmp]= "acosl" + CASE "acosh" + Stk$[Tmp]= "acosh" + CASE "appexename$" + Stk$[Tmp] = "AppExeName$()" + Use_AppExeName = Use_BcxSplitPath = UseFlag = TRUE + CASE "appexepath$" + Stk$[Tmp] = "AppExePath$()" + IF Stk$[Tmp+1]= "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "" + Stk$[Tmp+2] = "" + END IF + Use_AppExePath = Use_BcxSplitPath = UseFlag = TRUE + CASE "ansitowide" + Stk$[Tmp] = "AnsiToWide" + Use_AnsiToWide = UseFlag = TRUE + CASE "argc" + Stk$[Tmp]= "argc" + CASE "argv" + Stk$[Tmp]= "argv" + CASE "argv$" + Stk$[Tmp]= "argv$" + CASE "asc" + i=0 + j=GetNumArgs(Tmp+2,&i) + IF *Stk[Tmp+2] = *DQ$ THEN + IF j > 0 OR *Stk[Tmp+3] <> ASC(")") THEN + Stk$[Tmp] = "asc" + Use_Asc = TRUE + ELSE + IF Stk$[Tmp+2] = DDQ$ THEN + Stk$[Tmp] = "0" + ELSE + Stk$[Tmp] = LTRIM$(STR$(ASC(Stk$[Tmp+2],1))) + END IF + Stk$[Tmp+1] = "" : Stk$[Tmp+2] = "" : Stk$[Tmp+3] = "" + END IF + ELSE + IF j > 0 THEN Stk$[i] = "+" + Stk$[Tmp] = "(UCHAR)*" + END IF + CASE "asin" + Stk$[Tmp]= "asin" + CASE "asinl" + Stk$[Tmp]= "asinl" + CASE "asinh" + Stk$[Tmp]= "asinh" + CASE "atanh" + Stk$[Tmp]= "atanh" + CASE "atn","atan" + Stk$[Tmp]= "atan" + CASE "atnl","atanl" + Stk$[Tmp]= "atanl" + CASE "auto" + IF iMatchWrd(Stk$[Tmp+1],"local") THEN + Stk$[Tmp] = "dim" : Stk$[Tmp+1] = "raw" + ELSE + Stk$[Tmp]= "auto" + END IF + END SELECT + CASE 2 + SELECT CASE Keyword$ + CASE "bcopy" + *Stk[1] = 0 + FOR i = Tmp+1 TO Ndx + IF iMatchWrd(Stk$[i],"to") THEN EXIT FOR + CONCAT(Stk$[1], Stk$[i]) 'Source + NEXT + *Stk[2] = 0 + FOR i = i+1 TO Ndx + CONCAT(Stk$[2], Stk$[i]) 'Destination + NEXT + Src$ = "memmove(&" + Stk$[2] + ",&" + Stk$[1] + ",sizeof(" + Stk$[2] + "))" + REMOVE "&*" FROM Src$ + Ndx = 0 + CALL XParse(Src$) + CASE "bel$" + Stk$[Tmp] = "BEL$" + Use_BEL = UseFlag = TRUE + CASE "bs$" + Stk$[Tmp] = "BS$" + Use_BS = UseFlag = TRUE + CASE "bool","boolean" + Stk$[Tmp]= "bool" + CASE "band" + Stk$[Tmp]= " BAND " + Use_Band = TRUE + CASE "bnot" + Stk$[Tmp] = " BNOT " + Use_Bnot = TRUE + ' ******************************************************************* + ' Special Case Handler: Maintain case sensitivity for this structure + ' ******************************************************************* + CASE "bcx_font" + Stk$[Tmp] = UCASE$(Stk$[Tmp]) + DIM RAW tmp$ + tmp$ = Clean$(UCASE$(Stk$[Tmp+1])) + SELECT CASE tmp$ + CASE ".NAME" : Stk$[Tmp+1] = ".lf.lfFaceName$" + CASE ".BOLD" : Stk$[Tmp+1] = ".lf.lfWeight" + CASE ".UNDERLINE" : Stk$[Tmp+1] = ".lf.lfUnderline" + CASE ".STRIKEOUT" : Stk$[Tmp+1] = ".lf.lfStrikeOut" + CASE ".ITALIC" : Stk$[Tmp+1] = ".lf.lfItalic" + CASE ".CHARSET" : Stk$[Tmp+1] = ".lf.lfCharSet" + CASE ".SIZE", ".RGB" : Stk$[Tmp+1] = tmp$ + CASE ELSE + Stk$[Tmp+1] = Clean$(Stk$[Tmp+1]) + END SELECT + CASE "bcxsplitpath$" + Stk$[Tmp] = "$$BcxSplitPath$" + Use_BcxSplitPath = UseFlag = TRUE + CASE "bcxpath$" + UseFlag = TRUE + Stk$[Tmp] = "BcxPath$()" + IF Stk$[Tmp+1]= "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "" + Stk$[Tmp+2] = "" + END IF + + CASE "bcxfont" + Stk$[Tmp] = "BcxFont" + + + + '/***** 2010-12-11 New Socket Keywords -AIR *****/ + case "bcxsocket" + Stk$[Tmp] = "BcxSocket" + Use_Socket = true + case "bcxsocketsend" + Stk$[Tmp] = "BcxSocketSend" + case "bcxsocketread" + Stk$[Tmp] = "BcxSocketRead" + case "bcxsocketclose" + Stk$[Tmp] = "BcxSocketClose" + + + CASE "bcx_thread", "bcx_threadwait", "bcx_threadsuspend","bcx_threadresume","bcx_threadkill","bcx_threadend" + Stk$[Tmp] = UCASE$(Stk$[Tmp]) + Use_Threads = TRUE + CASE "bin$" + Stk$[Tmp] = "$$Bin$" + Use_Bin = UseFlag = TRUE + CASE "bool$" + Stk$[Tmp] = "$$BoolStr$" + Use_Boolstr = UseFlag = TRUE + CASE "bin2dec" + Stk$[Tmp]= "Bin2Dec" + Use_Bin2dec = TRUE + CASE "boolean" + Stk$[Tmp]= "BOOLEAN" + CASE "bor" + Stk$[Tmp]= " BOR " + Use_Bor = TRUE + CASE "byte" + Stk$[Tmp]= "BYTE" + END SELECT + CASE 3 + SELECT CASE Keyword$ + CASE "containedin" + Stk$[Tmp] = "containedin" + Use_ContainedIn = TRUE + CASE "copyfile" + Use_CopyFile = TRUE + Use_Exist = Use_Lof = TRUE + CASE "cr$" + Stk$[Tmp] = "CR$" + Use_CR = UseFlag = TRUE + CASE "close#" + Stk$[Tmp] = "close" + CASE "close" + IF LEFT$(Stk$[Tmp+1],1)= "#" THEN + Stk$[Tmp+1] = MID$(Stk$[Tmp+1],2) + END IF + CASE "cvd" + Stk$[Tmp]="CVD" + Use_Cvd = TRUE + CASE "cvi" + Stk$[Tmp]="CVI" + Use_Cvi = TRUE + CASE "cvl" + Stk$[Tmp]="CVL" + Use_Cvl = TRUE + CASE "cvld" + Stk$[Tmp]="CVLD" + Use_Cvld = TRUE + CASE "cvs" + Stk$[Tmp]="CVS" + Use_Cvs = TRUE + CASE "concat" + Stk$[Tmp]= "strcat" + CASE "chr$" + Stk$[Tmp]= "$$chr$" + Use_Chr = UseFlag = TRUE + CASE "char" + Stk$[Tmp]= "char" + CASE "crlf$" + Stk$[Tmp] = "CRLF$" + Use_Crlf = UseFlag = TRUE + CASE "cbctl" + Stk$[Tmp]= "LOWORD(wParam)" + CASE "cbctlmsg" + Stk$[Tmp]= "HIWORD(wParam)" + CASE "cblparam" + Stk$[Tmp]= "lParam" + CASE "cbmsg" + Stk$[Tmp]= "Msg" + CASE "cbwparam" + Stk$[Tmp]= "wParam" + CASE "cdbl" + Stk$[Tmp]= "CDBL" + Use_Cdbl = TRUE + CASE "chdrive", "chdir" + Stk$[Tmp]= "chdir" + CASE "cint" + Stk$[Tmp]= "Cint" + Use_Cint = TRUE + CASE "cldbl" + Stk$[Tmp]= "CLDBL" + Use_Cldbl = TRUE + CASE "clng" + Stk$[Tmp]= "CLNG" + Use_Clng = TRUE + CASE "cls" + Stk$[Tmp]= "cls" + Use_Cls = Use_ESC = TRUE + CASE "color", "color_fg", "color_bg" + Stk$[Tmp] = LCASE$(Stk$[Tmp]) + Use_Color = Use_Console = TRUE + CASE "command$" + Use_Command = Use_SPC = UseFlag = TRUE + Stk$[Tmp]= "command$(-1)" + IF Stk$ [Tmp+1] = "(" THEN + Stk$ [Tmp]= "command$" + END IF + CASE "colorref" + Stk$[Tmp]= "COLORREF" + CASE "cos" + Stk$[Tmp]= "cos" + CASE "cosl" + Stk$[Tmp]= "cosl" + CASE "cosh" + Stk$[Tmp]= "cosh" + CASE "cbool" + Stk$[Tmp] = "CBOOL" + DIM fp AS functionParse, i, t, expos = 0 + IF SepFuncArgs(Tmp+1, &fp, TRUE) = 0 THEN Abort("No argument specified in CBOOL") + FOR i = fp.CommaPos[0] TO fp.CommaPos[1] + t = INCHR("!<>=", Stk$[i]) + IF t THEN + IF t < 4 THEN + IF Stk$[i+1] = "=" THEN + Stk$[i] = Stk$[i] + Stk$[i+1] + Stk$[i+1] = "" + ELSEIF t = 1 AND Stk$[i] <> "!=" THEN + ITERATE + END IF + ELSE + IF Stk$[i+1] <> "=" THEN Stk$[i] = "==" + END IF + expos = i + EXIT FOR + END IF + NEXT + t = DataType(Stk$[expos-1]) + IF t = vt_STRLIT OR t = vt_STRVAR THEN + IF expos THEN + Stk$[Tmp+1] = Stk$[Tmp+1] + "strcmp(" + Stk$[fp.CommaPos[1]] = ")" + Stk$[expos] + "0)" + Stk$[expos] = "," + Src$ = "" + FOR i = 1 TO Ndx + Src$ = Src$ + Stk$[i] + SPC$ + NEXT + FastLexer(Src$," ","(),") + END IF + END IF + CASE "csng" + Stk$[Tmp]= "CSNG" + Use_Csng = TRUE + + CASE "curdir$" + Stk$[Tmp]= "curdir$()" + IF Stk$[Tmp+1]= "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "" + Stk$[Tmp+2] = "" + END IF + Use_Curdir = UseFlag = TRUE + + CASE "currency" + Stk$[Tmp] = "CURRENCY" + CASE "c_declare" + CallType$ = "__attribute__((cdecl)) " + Stk$[Tmp]= "declare" + IF iMatchWrd(Stk$[4], "lib") THEN + NoTypeDeclare = FALSE + ELSE + NoTypeDeclare = TRUE + END IF + END SELECT + CASE 4 + SELECT CASE Keyword$ + CASE "declare" + CallType$ = "__attribute__((stdcall)) " + Stk$[Tmp]= "declare" + IF NOT iMatchWrd(Stk$[4], "lib") THEN + NoTypeDeclare = TRUE + ELSE + NoTypeDeclare = FALSE + END IF + CASE "dq$" + Stk$[Tmp] = "DQ$" + Use_DQ = UseFlag = TRUE + CASE "ddq$" + Stk$[Tmp] = "DDQ$" + Use_DDQ = UseFlag = TRUE + CASE "data$" + Stk$[Tmp]= "DATA$" + CASE "date$" + Stk$[Tmp] = "$$timef$(12)" + Use_Time = UseFlag = TRUE + CASE "delete" + IF UseCpp = FALSE THEN Abort( "'DELETE' can only be used with C++" ) + Stk$[Tmp]="delete " + CASE "del$" + Stk$[Tmp]= "del$" + Use_Del = UseFlag = TRUE + CASE "double" + Stk$[Tmp]= "double" + CASE "download" + Stk$[Tmp] = "Download" + Use_Download = Use_Dynacall = TRUE + CASE "dsplit" + Stk$[Tmp]= "DSplit" + Use_DSplit = TRUE + Use_Remove = TRUE + Use_StrStr = TRUE + Use_Mid = TRUE + Use_Left = TRUE + Use_Instr = TRUE + Use_Stristr = TRUE + UseLCaseTbl = TRUE + UseFlag = TRUE + CASE "dword" + Stk$[Tmp]= "DWORD" + END SELECT + CASE 5 + SELECT CASE Keyword$ + CASE "extern" + Stk$[Tmp] = "extern" + CASE "enc$" + Stk$[Tmp]= "$$enc$" + Use_Enclose = UseFlag = TRUE + CASE "extract$" + Stk$[Tmp]= "$$extract$" + Use_Extract = Use_StrStr = UseFlag = TRUE + CASE "eof$" + Stk$[Tmp] = "EF$" + Use_EOF = UseFlag = TRUE + CASE "eof" + Stk$[Tmp]= "EoF" + Use_Eof = UseFlag = TRUE + IF DataType(Stk$[Tmp + 2]) = vt_NUMBER THEN + Stk$[Tmp + 2] = "FP" + Stk$[Tmp + 2] + END IF + CASE "esc$" + Stk$[Tmp] = "ESC$" + Use_ESC = UseFlag = TRUE + CASE "enum" + '/***** 2011-03-09 Added support Named ENUMS -AIR *****/ + '/***** SYNTAX: blah as ENUM *****/ + IF Ndx = 1 OR iMatchWrd(Stk$[3],"enum") THEN + Use_EnumFile = TRUE + '****************************************************** + ' We're dealing with a ENUM - END ENUM block + '****************************************************** + DIM RAW EnumFlag = FALSE + FPRINT FP11,"" + '/***** 2011-03-09 Added support Named ENUMS -AIR *****/ + IF Ndx = 1 THEN + FPRINT FP11,"enum" + ELSE IF Ndx = 3 then + FPRINT FP11,"enum " + Stk$[1] + END IF + '/*****************************************************/ + FPRINT FP11," {" + + Src$ = "" + WHILE NOT iMatchLft(Src$,"end ") + IF EOF(SourceFile) THEN Abort ("Unbalanced ENUM") + LINE INPUT SourceFile,Src$ + ModuleLineNos[ModuleNdx]++ + CALL StripCode(Src$) + IF iMatchLft(Src$,"$comme") THEN + Directives() + ITERATE + END IF + Src$ = TRIM$(Src$) + IF Src$ = "" THEN ITERATE ' line starts with comment + IF LCASE$(LEFT$(Src$ + " ",4)) = "end " THEN + EXIT LOOP + ELSE + IF EnumFlag = FALSE THEN + EnumFlag = TRUE + ELSE + FPRINT FP11,"," + END IF + END IF + FPRINT FP11," ",RTRIM$(Src$); + WEND + Src$ = "" + Ndx = 0 + FPRINT FP11,"" + FPRINT FP11," };\n" + EXIT SUB + END IF + '************************************************************* + ' We're dealing with a smaller, single line ENUM statement + '************************************************************* + Stk$[1] = "enum {" + FOR j = 2 TO Ndx + CONCAT (Stk$[1], Stk$[j]) + NEXT + CONCAT (Stk$[1], "}") + Ndx = 1 + CASE "environ$" + Stk$[Tmp]= "Environ$" + Use_Environ = UseFlag = TRUE + + CASE "exist" + Stk$[Tmp]= "Exist" + Use_Exist = UseFlag = TRUE + CASE "exp" + Stk$[Tmp]= "Exp" + Use_Exp = TRUE + END SELECT + CASE 6 + SELECT CASE Keyword$ + CASE "freeglobals" + Stk$[Tmp] = "FreeGlobals" + CASE "ff$" + Stk$[Tmp] = "FF$" + Use_FF = UseFlag = TRUE + CASE "function" + IF Stk$[Tmp+1] = "=" THEN + IF Stk$[Tmp+2] = DDQ$ THEN Stk$[Tmp+2] = "NUL$" + Stk$[Tmp] = "functionreturn" + END IF + CASE "false" + Stk$[Tmp]= "FALSE" + CASE "file" + Stk$[Tmp]= "FILE" + CASE "findintype" + 'Convert this :FindInType(char *Token, Type.member, int c) + 'To this :FindInType(char *Token, Stptr + offsetof(Type,member), sizeof(Type), int c) + Stk$[Tmp]= "FindInType" + Use_FindInType = TRUE + DIM RAW StMem$, StName$, VarName$ + DIM fp AS functionParse + CALL SepFuncArgs(Tmp, &fp, TRUE) + StMem$ = REMAIN$(Clean$(GetArg$(2, &fp)),".") + VarName$ = EXTRACT$(Clean$(GetArg$(2, &fp)),".") + FOR j = fp.CommaPos[1] + 1 TO fp.CommaPos[2] - 1 + Stk$[j] = "" + NEXT + IF CheckLocal(VarName$,&i) <> vt_UNKNOWN THEN + StName$ = TypeDefs[LocalVars[i].VarDef].VarName$ + ELSEIF CheckGlobal(VarName$,&i) <> vt_UNKNOWN THEN + StName$ = TypeDefs[GlobalVars[i].VarDef].VarName$ + END IF + j = fp.CommaPos[1] + 1 + Stk$[j] = "(char*)" & VarName$ & " + offsetof(" & StName$ & "," & StMem$ & "), sizeof(" & StName$ & ")" + CASE "farproc" + Stk$[Tmp] = "FARPROC" + CASE "fillarray" + Stk$[Tmp] = "fillarray" + Use_FillArray = TRUE + CASE "findfirst$" + Stk$[Tmp]= "findfirst$" + j = GetNumArgs(Tmp+2) + IF j = 0 THEN Stk$[Ndx] = ", &FindData)" + Use_Findfirst = Use_Like = TRUE + Use_BcxSplitPath = TRUE + Use_Join = TRUE + UseFlag = TRUE + CASE "findnext$" + Stk$[Tmp]= "findnext$" + IF Stk$[Tmp+1]= "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "(&FindData" + ELSEIF Tmp = Ndx THEN + Ndx++ + Stk$[Ndx] = "(&FindData)" + END IF + Use_Findnext = Use_Like = UseFlag = TRUE + Use_Join = TRUE + CASE "fint" + Stk$[Tmp]= "FINT" + Use_Fint = TRUE + CASE "fix" + Stk$[Tmp]= "FIX" + Use_Fix = TRUE + CASE "filelocked" + Stk$[Tmp]= "FileLocked" + Use_FileLocked = TRUE + CASE "flush" + Stk$[Tmp]= "fflush" + CASE "frac" + Stk$[Tmp]= "FRAC" + Use_Frac = TRUE + CASE "fracl" + Stk$[Tmp]= "FRACL" + Use_Fracl = TRUE + CASE "freefile" + Stk$[Tmp]= "FreeFile()" + Use_Freefile = TRUE + END SELECT + CASE 7 + SELECT CASE Keyword$ + CASE "getprocaddress" + LOCAL GlobalName$, s, ss, tempA$ + GlobalName$ = Stk$[Tmp-2] + ss = HashNumber(GlobalName$) + WHILE GlobalVarHash[ss] + s = GlobalVarHash[ss] + IF GlobalName$ = GlobalVars[s].VarName$ THEN + tempA$ = TypeDefs[GlobalVars[s].VarDef].VarName$ + IF GlobalVars[s].VarPntr THEN + tempA$=tempA$+" *" + END IF + END IF + ss = IMOD(ss + 1,MaxGlobalVars) + WEND + IF tempA$ = "" THEN + LOCAL LocalName$ + LocalName$ = Stk$[Tmp-2] + IF LocalVarCnt THEN + FOR INTEGER i = 1 TO LocalVarCnt + IF LocalName$ = LocalVars[i].VarName$ THEN + tempA$ = TypeDefs[LocalVars[i].VarDef].VarName$ + IF LocalVars[i].VarPntr THEN + tempA$ = tempA$ + " *" + END IF + EXIT FOR + END IF + NEXT + END IF + END IF + IF tempA$ <> "" THEN + '~ Stk$[Tmp]= "(" + tempA$ + ")GetProcAddress" + Stk$[Tmp]= "(" + tempA$ + ")dlsym" + ELSE + '~ Stk$[Tmp]= "GetProcAddress" + Stk$[Tmp]= "dlsym" + END IF + + CASE "getattr" + Stk$[Tmp]= "GETATTR" + CASE "getbvalue" + Stk$[Tmp]= "GetBValue" + CASE "getc" + Stk$[Tmp]= "getc" + CASE "getgvalue" + Stk$[Tmp]= "GetGValue" + CASE "getrvalue" + Stk$[Tmp]= "GetRValue" + + CASE "getresource" + Stk$[Tmp] = "GetResource" + Use_Embed = TRUE + + END SELECT + CASE 8 + SELECT CASE Keyword$ + CASE "hiword" + Stk$[Tmp]= "HIWORD" + CASE "hex$" + Stk$[Tmp]= "hex$" + Use_Hex = UseFlag = TRUE + CASE "hex2dec" + Stk$[Tmp]= "Hex2Dec" + Use_Hex2Dec = UseLCaseTbl = TRUE + CASE "hibyte" + Stk$[Tmp]= "HIBYTE" + CASE "hide" + Stk$[Tmp]= "Hide" + CASE "hypot" + Stk$[Tmp]= "hypot" + END SELECT + CASE 9 + SELECT CASE Keyword$ + CASE "inherits" + Stk$[Tmp]="inherits" + CASE "instr" + Stk$[Tmp]= "instr_b" + Use_Instr = Use_StrStr = TRUE + Use_Stristr = UseLCaseTbl = TRUE + CASE "inchr" + Stk$[Tmp]= "inchr" + Use_Inchr = TRUE + CASE "imod" + Stk$[Tmp]= "imod" + Use_Imod = TRUE + CASE "iif" + Stk$[Tmp]= "iif" + Use_Iif = TRUE + FOR i = Tmp+1 TO Ndx + IF Stk$[i] = "=" THEN + IF Stk$[i-1] <> "<" AND Stk$[i-1] <> ">" THEN + Stk$[i] = "==" + END IF + END IF + NEXT + CASE "iif$" + Stk$[Tmp]= "sziif$" + Use_sziif = TRUE + FOR i = Tmp+1 TO Ndx + IF Stk$[i] = "=" THEN + IF Stk$[i-1] <> "<" AND Stk$[i-1] <> ">" THEN + Stk$[i] = "==" + END IF + END IF + NEXT + CASE "inkey" + Use_InkeyD = TRUE + Use_GetCh = TRUE + UseFlag = TRUE + Stk$[Tmp]= "inkeyd()" + IF Stk$[Tmp+1]= "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "" + Stk$[Tmp+2] = "" + END IF + CASE "inkey$" + Use_Inkey = TRUE + Use_GetCh = TRUE + UseFlag = TRUE + Stk$[Tmp]= "inkey$()" + IF Stk$[Tmp+1]= "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "" + Stk$[Tmp+2] = "" + END IF + CASE "ins$" + Stk$[Tmp]= "ins$" + Use_Ins = UseFlag = TRUE + CASE "instat" + Use_Instat = true + Stk$[Tmp]= "kbhit()" + CASE "instrrev" + Stk$[Tmp]= "InstrRev" + Use_Instrrev = TRUE + CASE "isptr" + Stk$[Tmp]= "IsPtr" + Use_Isptr = TRUE + CASE "ireplace$" + Stk$[Tmp]= "iReplace$" + Use_iReplace = Use_Stristr = UseFlag = TRUE + UseLCaseTbl = TRUE + CASE "iremove$" + Stk$[Tmp]= "IRemoveStr$" + Use_IRemove = UseFlag = TRUE + Use_Stristr = UseLCaseTbl = TRUE + CASE "iterate" + Stk$[Tmp]= "continue" + END SELECT + CASE 10 + SELECT CASE Keyword$ + CASE "join$" + Stk$[Tmp]= "$$join$" + Use_Join = UseFlag = TRUE + END SELECT + CASE 11 + SELECT CASE Keyword$ + CASE "keypress" + Stk$[Tmp] = "keypress()" + IF Stk$[Tmp+1] = "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "" + Stk$[Tmp+2] = "" + END IF + Use_Keypress = TRUE + Use_GetCh = TRUE + END SELECT + CASE 12 + SELECT CASE Keyword$ + CASE "loadfile$" + Stk$[Tmp]= "$$LoadFile$" + Use_LoadFile = Use_Get = UseFlag = TRUE + Use_Exist = Use_Lof = TRUE + CASE "lf$" + Stk$[Tmp] = "LF$" + Use_LF = UseFlag = TRUE + CASE "line" + IF iMatchWrd(Stk$[Tmp+1],"input") THEN + Use_Lineinput = TRUE + Stk$[Tmp] = "lineinput" + j = Tmp + 4 + Stk$[Tmp+1] = "" ' Extract the file handle + FOR i = Tmp+2 TO Ndx + IF *Stk$[i] = ASC(",") THEN j=i+1 : EXIT FOR + Stk$[Tmp+1] = Stk$[Tmp+1] + Stk$[i] + Stk$[i] = "" + NEXT j + FOR i = j TO Ndx + Stk$[Tmp+2]= Stk$[Tmp+2] & Stk$[i] + NEXT + END IF + CASE "lcase$" + Stk$[Tmp] = "$$lcase$" + Use_Lcase = TRUE + Use_StrUpLow = UseFlag = TRUE + CASE "ldouble" + Stk$[Tmp] = "LDOUBLE" + Use_Ldouble = UseFlag = TRUE + CASE "left$" + Stk$[Tmp]= "$$left$" + Use_Left = TRUE + UseFlag = TRUE + CASE "long" + Stk$[Tmp]= "long" + CASE "longlong" + Stk$[Tmp] = "LONGLONG" + CASE "lpbyte" + Stk$[Tmp] = "LPBYTE" + CASE "len" + Stk$[Tmp]= "strlen" + CASE "lprint" + Stk$[Tmp]= "lprint" + IF Tmp = Ndx THEN + Ndx++ + Stk$[Ndx] = ENC$ ("") ' Allow LPRINT with no args + END IF + CASE "lpad$" + Stk$[Tmp]= "$$lpad$" + Use_Lpad = UseFlag = TRUE + CASE "ltrim$" + Stk$[Tmp]= "$$ltrim$" + Use_Ltrim = UseFlag = TRUE + CASE "lof" + Stk$[Tmp]= "lof" + IF DataType(Stk$[Tmp + 2]) = vt_NUMBER THEN + Stk$[Tmp + 2] = "FP" + Stk$[Tmp + 2] + END IF + Use_Lof = TRUE + CASE "loadlibrary", "load_dll" + Stk$[Tmp]= "LoadLibrary" + CASE "like" + Stk$[Tmp] = "like" + Use_Like = TRUE + CASE "lobyte" + Stk$[Tmp]= "LOBYTE" + CASE "loc" + IF DataType(Stk$[Tmp + 2]) = vt_NUMBER THEN + Stk$[Tmp + 2] = "FP" + Stk$[Tmp + 2] + END IF + Stk$[Tmp] = "loc(" + Stk$[Tmp + 2] + "," + Stk$[Tmp + 2] + "len)" + Stk$[Tmp + 1] = "" + Stk$[Tmp + 2] = "" + Stk$[Tmp + 3] = "" + Use_Loc = TRUE + CASE "locate" + Use_Locate = TRUE + CASE "log" + Stk$[Tmp]= "log" + CASE "logl" + Stk$[Tmp]= "logl" + CASE "log10" + Stk$[Tmp]= "log10" + CASE "log10l" + Stk$[Tmp]= "log10l" + CASE "loword" + Stk$[Tmp]= "LOWORD" + CASE "lpstr" + Stk$[Tmp]= "PCHAR" + END SELECT + CASE 13 + SELECT CASE Keyword$ + CASE "mkd$" + IF Tmp > 2 THEN + IF INCHR(Stk$[Tmp-2],"$") AND *Stk$[Tmp-1] = ASC("=") THEN + Stk$[1] = "memcpy(" + Stk$[1] + Stk$[Tmp-1] = "," + Stk$[++Ndx] = ",9)" + END IF + END IF + Stk$[Tmp]="MKD" + Use_Mkd = UseFlag = TRUE + CASE "mki$" + IF Tmp > 2 THEN + IF INCHR(Stk$[Tmp-2],"$") AND *Stk$[Tmp-1] = ASC("=") THEN + Stk$[1] = "memcpy(" + Stk$[1] + Stk$[Tmp-1] = "," + Stk$[++Ndx] = ",3)" + END IF + END IF + Stk$[Tmp]="MKI" + Use_Mki = UseFlag = TRUE + CASE "mkl$" + IF Tmp > 2 THEN + IF INCHR(Stk$[Tmp-2],"$") AND *Stk$[Tmp-1] = ASC("=") THEN + Stk$[1] = "memcpy(" + Stk$[1] + Stk$[Tmp-1] = "," + Stk$[++Ndx] = ",5)" + END IF + END IF + Stk$[Tmp]="MKL" + Use_Mkl = UseFlag = TRUE + CASE "mkld$" + IF Tmp > 2 THEN + IF INCHR(Stk$[Tmp-2],"$") AND *Stk$[Tmp-1] = ASC("=") THEN + Stk$[1] = "memcpy(" + Stk$[1] + Stk$[Tmp-1] = "," + Stk$[++Ndx] = ",11)" + END IF + END IF + Stk$[Tmp]="MKLD" + Use_Mkld = UseFlag = TRUE + CASE "mks$" + IF Tmp > 2 THEN + IF INCHR(Stk$[Tmp-2],"$") AND *Stk$[Tmp-1] = ASC("=") THEN + Stk$[1] = "memcpy(" + Stk$[1] + Stk$[Tmp-1] = "," + Stk$[++Ndx] = ",5)" + END IF + END IF + Stk$[Tmp]="MKS" + Use_Mks = UseFlag = TRUE + CASE "mid$" + IF Tmp > 1 THEN + Stk$[Tmp]= "$$mid$" + Use_Mid = UseFlag = TRUE + ELSE + Stk$[Tmp]= "midstr" + Use_Midstr = UseFlag = TRUE + END IF + CASE "min" + Stk$[Tmp]= "_MIN_" + Use_Min = TRUE + CASE "main" + Stk$[Tmp]= "main" + CASE "makeintresource" + Stk$[Tmp]= "MAKEINTRESOURCE" + CASE "makelong" + Stk$[Tmp]= "MAKELONG" + CASE "makeword" + Stk$[Tmp]= "MAKEWORD" + CASE "max" + Stk$[Tmp]= "_MAX_" + Use_Max = TRUE + CASE "mcase$" + Stk$[Tmp] = "$$mcase$" + Use_Mcase = UseFlag = TRUE + Use_StrUpLow = TRUE + CASE "mkdir" + Stk$[Tmp]= "mkdir" + CASE "mod" + Stk$[Tmp]= "fmod" + END SELECT + CASE 14 + SELECT CASE Keyword$ + CASE "new" + IF iMatchWrd(Stk$[Tmp-1],"binary") THEN EXIT + IF UseCpp = FALSE THEN Abort( "'NEW' can only be used with C++" ) + Stk$[Tmp] = "new " + CASE "nul$" + Stk$[Tmp] = "NUL$" + Use_NUL = UseFlag = TRUE + CASE "null" + Stk$[Tmp]= "NULL" + CASE "now$" + Stk$[Tmp]= "now$()" + Use_Now = UseFlag = TRUE + END SELECT + CASE 15 + SELECT CASE Keyword$ + CASE "open" + FOR A = Tmp+1 TO Ndx + IF LEFT$(Stk$[A],1) = "#" THEN + Stk$[A] = MID$(Stk$[A],2) + EXIT FOR + END IF + NEXT + CASE "oct$" + Stk$[Tmp]= "oct$" + Use_Oct = UseFlag = TRUE + CASE "osversion" + Stk$[Tmp]= "OSVersion()" + IF Stk$[Tmp+1]= "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "" + Stk$[Tmp+2] = "" + END IF + Use_OSVersion = TRUE + END SELECT + CASE 16 + SELECT CASE Keyword$ + CASE "pause" + Stk$[Tmp] = "Pause()" + IF Stk$[Tmp+1] = "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "" + Stk$[Tmp+2] = "" + END IF + Use_Pause = Use_Keypress = TRUE + Use_GetCh = TRUE + CASE "preserve" + Stk$[Tmp] = "PRESERVE" + CASE "print#" + Stk$[Tmp] = "fprint" + CASE "print" + IF LEFT$(Stk$[Tmp+1],1)= "#" THEN + Stk$[Tmp] = "fprint" + Stk$[Tmp+1] = MID$(Stk$[Tmp+1],2) + END IF + CASE "ptr" + CompPtr = 1 + Stk$[Tmp-1] = Stk$[Tmp-1] + "*" + Stk$[Tmp]= "" + IF Tmp = Ndx THEN + Ndx-- + WHILE TALLY(Stk$[Ndx],"*") = LEN(Stk$[Ndx]) + Stk$[Ndx-1] = Stk$[Ndx-1] + Stk$[Ndx] + Stk$[Ndx] = "" + Ndx-- + WEND + ELSE + i = Tmp-1 + WHILE TALLY(Stk$[i],"*") = LEN(Stk$[i]) + Stk$[i-1] = Stk$[i-1] + Stk$[i] + Stk$[i] = "" + i-- + WEND + END IF + CASE "peek$" + Stk$[Tmp]= "$$peekstr$" + Use_PeekStr = UseFlag = TRUE + CASE "poke" + Stk$[Tmp]= "memmove" + CASE "pow" + Stk$[Tmp]= "pow" + CASE "powl" + Stk$[Tmp]= "powl" + CASE "private" + IF UseCpp THEN + Stk$[Tmp]= "private" + END IF + IF iMatchWrd(Stk$[Tmp+1],"const") THEN + Stk$[Tmp]= "enum " + Stk$[Tmp+1]= Stk$[Tmp+2] + "{" + Ndx++ + Stk$[Ndx]= "}" + END IF + + CASE "public" + IF UseCpp THEN + Stk$[Tmp]= "public" + END IF + + END SELECT + CASE 17 + SELECT CASE Keyword$ + CASE "qbcolor" + Stk$[Tmp]= "qbcolor" + Use_QBColor = TRUE + END SELECT + CASE 18 + SELECT CASE Keyword$ + '/***** 2012-12-12 New REGMATCH Keyword -AIR *****/ + CASE "regmatch" + Stk$[Tmp] = "regmatch" + ' print "REGMATCH FOUND" + Use_PeekStr = Use_RegEx = TRUE + CASE "rewind" + Stk$[Tmp]= "rewind" + IF DataType(Stk$[Tmp + 2]) = vt_NUMBER THEN + Stk$[Tmp + 2] = "FP" + Stk$[Tmp + 2] + END IF + CASE "remove$" + Stk$[Tmp]= "$$RemoveStr$" + Use_Remove = Use_StrStr = UseFlag = TRUE + CASE "replace$" + Stk$[Tmp]= "$$replace$" + Use_Replace = Use_StrStr = UseFlag = TRUE + CASE "right$" + Stk$[Tmp]= "$$right$" + Use_Right = UseFlag = TRUE + CASE "rename" + Stk$[Tmp]= "rename" + CASE "register" + Stk$[Tmp]= "register" + CASE "randomize" + Stk$[Tmp]= "randomize" + Use_Randomize = TRUE + Use_Rnd = TRUE + IF Ndx = 1 THEN + Use_Timer = TRUE + Stk$[1] ="randomize(timer())" + END IF + CASE "rec" + IF DataType(Stk$[Tmp + 2]) = vt_NUMBER THEN + Stk$[Tmp + 2] = "FP" + Stk$[Tmp + 2] + END IF + Stk$[Tmp] = "rec(" + Stk$[Tmp + 2] + "," + Stk$[Tmp + 2] + "len)" + Stk$[Tmp + 1] = "" + Stk$[Tmp + 2] = "" + Stk$[Tmp + 3] = "" + Use_Rec = TRUE + CASE "reccount" + DIM RAW length$ + IF DataType(Stk$[Tmp + 2]) = vt_NUMBER THEN + Stk$[Tmp + 2] = "FP" + Stk$[Tmp + 2] + END IF + Stk$[Tmp] = "reccount" + length$ = Stk$[Tmp + 2] + "len)" + FOR i = Tmp+1 TO Ndx + IF *Stk$[i] = ASC(")") THEN + Stk$[i] = "" + EXIT FOR + END IF + Stk$[Tmp] = Stk$[Tmp] + Stk$[i] + Stk$[i] = "" + NEXT i + Stk$[Tmp] = Stk$[Tmp] + "," + length$ + Use_RecCount = TRUE + CASE "reclen" + Stk$[Tmp] = "reclen" + CASE "record" + Stk$[Tmp] = "record" + CASE "remain$" + Stk$[Tmp]= "$$remain$" + Use_Remain = UseFlag = TRUE + CASE "retain$" + Stk$[Tmp]= "$$Retain$" + Use_Retain = UseFlag = TRUE + CASE "repeat$" + Stk$[Tmp]= "$$repeat$" + Use_Repeat = UseFlag = TRUE + CASE "reverse$" + Stk$[Tmp]= "$$reverse$" + Use_Reverse = UseFlag = TRUE + CASE "rgb" + Stk$[Tmp]= "RGB" + CASE "rmdir" + Stk$[Tmp]= "rmdir" + CASE "rnd" + Stk$[Tmp]= "rnd()" + IF Stk$[Tmp+1]= "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "" + Stk$[Tmp+2] = "" + END IF + Use_Rnd = TRUE + CASE "round" + Stk$[Tmp]= "Round" + Use_Round = TRUE + CASE "rpad$" + Stk$[Tmp]= "$$rpad$" + Use_Rpad = UseFlag = TRUE + CASE "rtrim$" + Stk$[Tmp]= "$$rtrim$" + Use_Rtrim = UseFlag = TRUE + CASE "run" + Stk$[Tmp]= "Run" + Use_Run = TRUE + END SELECT + CASE 19 + SELECT CASE Keyword$ + CASE "scanerror" + Stk$[Tmp] = "ScanError" + CASE "sprint" + Stk$[Tmp]= "sprint" + CASE "spc$" + Stk$[Tmp] = "SPC$" + Use_SPC = UseFlag = TRUE + CASE "str$" + Stk$[Tmp]= "$$str$" + Use_Str = UseFlag = TRUE + CASE "strl$" + Stk$[Tmp]= "$$strl$" + Use_Strl = UseFlag = TRUE + CASE "searchpath$" + Stk$[Tmp]= "$$SEARCHPATH$" + Use_SearchPath = UseFlag = TRUE + CASE "sizeof" + Stk$[Tmp]= "sizeof" + CASE "setattr" + Stk$[Tmp]= "SETATTR" + CASE "setwindowrtftext" + Stk$[Tmp] = "SetWindowRTFText" + CASE "sgn" + Stk$[Tmp]= "sgn" + Use_Sgn = TRUE + CASE "short" + Stk$[Tmp] = "short" + CASE "shell" + Use_Shell = TRUE + CASE "show" + Stk$[Tmp]= "Show" + CASE "sin" + Stk$[Tmp]= "sin" + CASE "sinl" + Stk$[Tmp]= "sinl" + CASE "single" + Stk$[Tmp]= "float" + CASE "sinh" + Stk$[Tmp]= "sinh" + CASE "sleep" + Stk$[Tmp]= "sleep" + CASE "space$" + Stk$[Tmp]= "$$space$" + Use_Space = UseFlag = TRUE + CASE "split" + Stk$[Tmp]= "Split" + Use_Split = UseFlag = TRUE + Use_Remove= TRUE + Use_StrStr= TRUE + Use_Mid = TRUE + Use_Left = TRUE + Use_Instr = TRUE + Use_Stristr = TRUE + UseLCaseTbl = TRUE + CASE "splitbarfg" + Stk$[Tmp]= "SplitBarFG" + CASE "splitbarbg" + Stk$[Tmp]= "SplitBarBG" + CASE "sqr","sqrt" + Stk$[Tmp]= "sqrt" + CASE "sqrl","sqrtl" + Stk$[Tmp]= "sqrtl" + CASE "strarray" + Stk$[Tmp]= "PCHAR*" + CASE "strim$" + Stk$[Tmp]= "$$strim$" + Use_Strim = UseFlag = TRUE + CASE "string" + Stk$[Tmp]= "string" + CASE "string$" + Stk$[Tmp]= "$$stringx$" + Use_String = UseFlag = TRUE + CASE "strptr" + Stk$[Tmp]= "STRPTR" + Use_Strptr = TRUE + CASE "strtoken$" + Stk$[Tmp]= "StrToken$" + Use_Strtoken = Use_Mid = Use_Left = Use_Extract = TRUE + Use_Instr =Use_Instrrev = Use_Stristr = Use_Tally = Use_Remove = TRUE + Use_StrStr = UseLCaseTbl = UseFlag = TRUE + CASE "swap" + Stk$[Tmp]= "swap" + Use_Swap = TRUE + CASE "sysdir$" + Stk$[Tmp]= "$$sysdir$()" + IF Stk$[Tmp+1]= "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "" + Stk$[Tmp+2] = "" + END IF + Use_Sysdir = UseFlag = TRUE + CASE "sysstr" + Stk$[Tmp] = "SysStr" + Use_SysStr = TRUE + END SELECT + CASE 20 + SELECT CASE Keyword$ + CASE "tab$" + Stk$[Tmp] = "TAB$" + Use_TAB = UseFlag = TRUE + CASE "true" + Stk$[Tmp]= "TRUE" + CASE "trim$" + Stk$[Tmp]= "$$trim$" + Use_Trim = UseFlag = TRUE + CASE "tally" + Stk$[Tmp]= "tally" + Use_Tally = UseLCaseTbl = Use_Stristr = Use_StrStr = TRUE + CASE "tan" + Stk$[Tmp]= "tan" + CASE "tanh" + Stk$[Tmp]= "tanh" + CASE "tanl" + Stk$[Tmp]= "tanl" + CASE "tempdir$" + Stk$[Tmp]= "$$tempdir$()" + IF Stk$[Tmp+1]= "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "" + Stk$[Tmp+2] = "" + END IF + Use_Tempdir = UseFlag = Use_Exist = TRUE + CASE "tempfilename$" + Stk$[Tmp] = "$$TempFileName$" + Use_TempFileName = UseFlag = TRUE + Use_Exist = Use_Rnd = TRUE + ' ********************************************************* + ' Special Case Handler: Substitute "This." with "This->" + ' ********************************************************* + CASE "this" + Stk$[Tmp] = "this" + IF *Stk[Tmp+1] = ASC(".") THEN + Stk$[Tmp+1] = "->" & MID$(Stk$[Tmp+1],2) + END IF + CASE "time$" + IF Stk$[Tmp+1] <> "(" THEN + Stk$[Tmp] = "$$timef$()" + ELSE + Stk$[Tmp] = "$$timef$" + END IF + IF Stk$[Tmp+1]= "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "" + Stk$[Tmp+2] = "" + END IF + Use_Time = UseFlag = TRUE + CASE "timer" + Stk$[Tmp]= "timer()" + IF Stk$[Tmp+1]= "(" AND Stk$[Tmp+2]= ")" THEN + Stk$[Tmp+1] = "" + Stk$[Tmp+2] = "" + END IF + Use_Timer = TRUE + END SELECT + CASE 21 + SELECT CASE Keyword$ + CASE "uint" + Stk$[Tmp]= "UINT" + CASE "ushort" + Stk$[Tmp] = "USHORT" + CASE "ulong" + Stk$[Tmp] = "ULONG" + CASE "ulonglong" + Stk$[Tmp] = "ULONGLONG" + CASE "ucase$" + Stk$[Tmp]= "$$ucase$" + Use_Ucase = UseFlag = TRUE + Use_StrUpLow = TRUE + CASE "ubound" + Stk$[Tmp]= "ubound" + Use_Ubound = TRUE + CASE "using$" + Stk$[Tmp] = "$$Using$" + Use_Using = UseFlag = TRUE + '/***** 2010-11-18 Added for new Constructor/Desctructor syntax -AIR *****/ + CASE "using" + Stk$[Tmp]= "using" + + END SELECT + CASE 22 + SELECT CASE Keyword$ + CASE "val" + Stk$[Tmp]= "VAL" + Use_Val = TRUE + CASE "vall" + Stk$[Tmp]= "VALL" + Use_Vall = TRUE + CASE "variant" + Stk$[Tmp]= "VARIANT" + CASE "varptr" + Stk$[Tmp]= "" + CASE "vchr$" + Stk$[Tmp] = "$$vchr$" + Use_VChr = UseFlag = TRUE + '/***** 2010-12-01 Added to support Abstract Classes -AIR *****/ + CASE "virtual" + Stk$[Tmp]="virtual" + Use_Virtual = TRUE + CASE "vt$" + Stk$[Tmp] = "VT$" + Use_VT = UseFlag = TRUE + CASE "verify" + Stk$[Tmp] = "Verify" + Use_Verify = Use_Mid = UseFlag = TRUE + END SELECT + CASE 23 + SELECT CASE Keyword$ + CASE "widetoansi$" + Stk$[Tmp] = "$$WideToAnsi$" + Use_WideToAnsi = UseFlag = TRUE + END SELECT + END SELECT + NEXT + IF CompPtr = 1 THEN CALL RemEmptyTokens + '************************************************************ + ' Moved the WITH/END WITH handling here from the Emit sub + ' The ill formed variables would cause conflict with the new + ' AsmUnKnown structs function. + '************************************************************ + IF WithCnt THEN + FOR i = 1 TO Ndx + 'IF LEFT$(Stk$[i],1) = "." AND NOT IsNumber(MID$(Stk$[i],2,1)) THEN + IF LEFT$(Stk$[i],2) = "->" OR (LEFT$(Stk$[i],1) = "." AND NOT IsNumber(MID$(Stk$[i],2,1))) THEN + IF WithVar$[WithCnt] = "this" THEN + Stk$[i] = "->" + MID$(Stk$[i],2) + END IF + IF i = 1 THEN + Stk$[i] = WithVar$[WithCnt] + Stk$[i] + ELSE + IF NOT IsReservedWord(Stk$[i-1]) THEN + IF NOT (isalpha(Stk[i-1][LEN(Stk$[i-1]-1)]) OR IsNumber(RIGHT$(Stk$[i-1],LEN(Stk$[i-1]-1)))) THEN + Stk$[i] = WithVar$[WithCnt] + Stk$[i] + END IF + ELSE + Stk$[i] = WithVar$[WithCnt] + Stk$[i] + END IF + END IF + WHILE (isalpha(*Stk[i+1]) OR *Stk[i+1] = ASC(".")) AND (i < Ndx) + INCR i + WEND + END IF + NEXT + END IF + '************************************************************ + ' handle programming style global and locals using same name + '************************************************************ + IF CompToken = 1 THEN + Keyword$ = LCASE$(Stk$[1]) + SELECT CASE Keyword$ + CASE "dim" : CompToken = 0 + CASE "local" : CompToken = 0 + CASE "global" : CompToken = 0 + CASE "static" : CompToken = 0 + CASE "shared" : CompToken = 0 + CASE "raw" : CompToken = 0 + CASE "dynamic" : CompToken = 0 + CASE "free" : CompToken = 0 + CASE "redim" : CompToken = 0 + CASE "sub" : CompToken = 0 + CASE "function" : CompToken = 0 + CASE "overloaded" : CompToken = 0 + CASE "public" : CompToken = 0 + CASE "declare" : CompToken = 0 + CASE "c_declare" : CompToken = 0 + CASE "auto" : CompToken = 0 + CASE "register" : CompToken = 0 + CASE "extern" : CompToken = 0 + CASE ELSE : CALL AsmUnknownStructs(1) + END SELECT + END IF +END SUB 'TokenSubstitutions +SUB JoinStrings( i, inif ) + '************************ + DIM RAW DoJoin = 0 + DIM RAW InBrace = 0 + DIM RAW OnlyPara = 0 + DIM RAW j = 0 + DIM RAW l = 0 + DIM RAW sj = i + DIM RAW t$ + DIM RAW vt + '************************ + WHILE i <= Ndx + t$ = LCASE$(Stk$[i]) + IF NOT j AND NOT OnlyPara AND NOT InBrace THEN + vt = DataType(t$) + IF vt = vt_STRVAR OR vt = vt_STRLIT THEN + sj = i + INCR i + ITERATE + END IF + END IF + SELECT CASE t$ + CASE "&" + IF OnlyPara THEN EXIT SELECT + vt = DataType(Stk$[i+1]) + IF vt <> vt_STRVAR AND vt <> vt_STRLIT THEN + vt = DataType(Stk$[i-1]) + END IF + IF vt = vt_STRVAR OR vt = vt_STRLIT THEN + j++ + Stk$[i] = "," + t$ = "" + END IF + CASE "[" + INCR InBrace + CASE "]" + DECR InBrace + CASE "(" + IF Stk$[i+1] <> "*" THEN + CALL JoinStrings(i+1, inif) + l = i-1 + WHILE Stk$[i] <> ")" + Stk$[l] = Stk$[l] + Stk$[i] + " " + Stk$[i] = "" + i++ + WEND + CONCAT(Stk$[l], Stk$[i]) + Stk$[i] = "" + END IF + CASE ")" + IF j THEN + Stk$[sj] = "join$(" + STR$(j+1) + "," + Stk$[sj] + j = sj + 1 + WHILE j < i + CONCAT(Stk$[sj], Stk$[j]) + Stk$[j] = "" + j++ + WEND + CONCAT(Stk$[sj], ")") + END IF + EXIT SUB + CASE "||" + Stk$[i] = " or " + DoJoin = TRUE + CASE "&&" + Stk$[i] = " and " + DoJoin = TRUE + CASE "then", "for" + DoJoin = TRUE + CASE "=" + IF NOT inif THEN + OnlyPara = TRUE + ELSE + DoJoin = TRUE + END IF + CASE "if", "elseif", "while" + inif = TRUE + sj = i + 1 + CASE "sprint", "lprint", "fprint", "fprintf", "print", "print#" + OnlyPara = TRUE + CASE ELSE + IF LEFT$(Stk$[i],2) = "]." OR LEFT$(Stk$[i],3) = "]->" THEN + DECR InBrace + END IF + END SELECT + IF (DoJoin OR INCHR(",+-*/^;:<>~|&", t$)) AND NOT OnlyPara AND NOT InBrace THEN + DoJoin = 0 + IF j THEN + Stk$[sj] = "join$(" + STR$(j+1) + "," + Stk$[sj] + j = sj + j++ + WHILE j < i + CONCAT(Stk$[sj], Stk$[j]) + Stk$[j] = "" + j++ + WEND + CONCAT(Stk$[sj], ")") + END IF + j = 0 + sj = i + 1 + END IF + INCR i + WEND + IF j THEN + Stk$[sj] = "join$(" + STR$(j+1) + "," + Stk$[sj] + j = sj + j++ + WHILE j <= i + CONCAT(Stk$[sj], Stk$[j]) + Stk$[j] = "" + j++ + WEND + CONCAT(Stk$[sj], ")") + END IF +END SUB ' JoinStrings +SUB Transforms() + '**************** + DIM RAW nBrace + DIM RAW CntMarker + DIM RAW IFCond + DIM RAW a + DIM RAW i + DIM RAW j + DIM RAW Keyword$ + DIM RAW lszTmp$ + '**************** + Keyword$ = "" + lszTmp$ = "" + IF Ndx = 3 AND NOT WithCnt THEN + IF Stk$[2] = "+" AND Stk$[3] = "+" THEN + FPRINT Outfile,Scoot$,Clean$(Stk$[1]);"++;" + Ndx = 0 + Statements++ + EXIT SUB + END IF + IF Stk$[2] = "-" AND Stk$[3] = "-" THEN + FPRINT Outfile,Scoot$,Clean$(Stk$[1]);"--;" + Ndx = 0 + Statements++ + EXIT SUB + END IF + IF Stk$[1] = "+" AND Stk$[2] = "+" THEN + FPRINT Outfile,Scoot$,"++";Clean$(Stk$[3]);";" + Ndx = 0 + Statements++ + EXIT SUB + END IF + IF Stk$[1] = "-" AND Stk$[2] = "-" THEN + FPRINT Outfile,Scoot$,"--";Clean$(Stk$[3]);";" + Ndx = 0 + Statements++ + EXIT SUB + END IF + END IF + Keyword$ = LCASE$(Stk$[1]) + a = INCHR("abcdefghijklmnopqrstuvwxyz$", Keyword$) + SELECT CASE a + CASE 3 + IF Keyword$ = "case" THEN + nBrace = 0 + CntMarker = 2 + j = 0 + FOR i = 2 TO Ndx + IF INCHR("([",Stk$[i]) THEN nBrace++ + IF INCHR(")]",Stk$[i]) THEN nBrace-- + IF Stk$[i] = "," THEN + IF nBrace=0 THEN CntMarker = i + 1 + END IF + IF iMatchWrd(Stk$[i],"to") THEN + j = 1 + Stk$[i] = " and <=" + Stk$[CntMarker] = ">=" + Stk$[CntMarker] + END IF + NEXT + IF j=1 THEN + Src$ = "" + FOR i = 1 TO Ndx + Src$ = Src$ + Stk$[i] + " " + NEXT + CALL XParse(Src$) + END IF + EXIT SUB + END IF + CASE 4 + '************************************************************************** + ' The following code introduces the following DLL declarations to BCX + '************************************************************************** + ' DECLARE FUNCTION Foo LIB "FOO.DLL" ALIAS "FooA" ( A$ ) + ' OR + ' DECLARE FUNCTION Foo LIB "FOO.DLL" ( A$ ) - Alias will default to "FOO" + ' [5.08.1102] Foo = (BCXFPROTx)GetProcAddress(H_FOO, "FooA"); + '************************************************************************** + IF Keyword$ = "declare" AND iMatchWrd(Stk$[4],"lib") THEN + DIM RAW alias$, i, idx=-1, AR_DllName$ + REMOVE DQ$ FROM Stk$[5] + FOR i = 0 TO LoadLibsCnt - 1 + IF Stk$[5] = Loadlibs$[i] THEN + idx = i + EXIT FOR + END IF + NEXT i + IF idx < 0 THEN + Loadlibs$[LoadLibsCnt] = Stk$[5] + INCR LoadLibsCnt + END IF + IF iMatchWrd(Stk$[6],"alias") THEN + alias$ = Stk$[7] + Stk$[6] = "" + Stk$[7] = "" + ELSE + alias$ = ENC$(Stk$[3]) + END IF + + INCR DllCnt + IF DllCnt > 799 THEN Abort("Maximum number of declarations exceded.") + + IF INCHR(Stk$[5],"-") THEN + AR_DllName$ = EXTRACT$(Stk$[5], "-") + ELSEIF INCHR(Stk$[5],".") THEN + AR_DllName$ = EXTRACT$(Stk$[5], ".") + END IF + + DllDecl$ [DllCnt] = "static BCXFPROT" + LTRIM$(STR$(DllCnt)) + SPC$ + Clean$(Stk$[3]) + "=(BCXFPROT" + LTRIM$(STR$(DllCnt)) + _ + ")dlsym(H_" + UCASE$(AR_DllName$) + ", " + alias$ + ");" + + Stk$[4] = "" + Stk$[5] = "" + EXIT SUB + END IF + CASE 7 + IF Keyword$ = "get$" THEN + Stk$[1] = "~get" + EXIT SUB + END IF + IF Keyword$ = "global" AND iMatchWrd(Stk$[2],"dynamic") THEN + Stk$[1] = "global" + EXIT SUB + END IF + CASE 9 + IF Keyword$ = "iremove" THEN + '*********************************************************** + ' Translate IREMOVE UCASE$("aaa") FROM LTRIM$(RTRIM$(A$)) + ' into A$ = IREMOVE$(LTRIM$(RTRIM$(A$)),UCASE$("aaa")) + '*********************************************************** + DIM RAW Mat$, Fat$ + Mat$ = "" : Fat$ = "" + FOR i = 2 TO Ndx + IF iMatchWrd(Stk$[i],"from") THEN + Stk$[i]= "" + EXIT FOR + END IF + NEXT + FOR j = 2 TO i + CONCAT(Mat$,Stk$[j]) ' build match string + NEXT + FOR j = i TO Ndx + CONCAT(Fat$,Stk$[j]) ' build fat source + NEXT + lszTmp$ = "=iremove$(" + Fat$ + "," + Mat$ + ")" + FastLexer(Fat$," ()","") + lszTmp$ = Stk$[Ndx] + lszTmp$ + CALL XParse(lszTmp$) + CALL TokenSubstitutions + CALL Emit + Ndx = 0 + EXIT SUB + END IF + IF Keyword$ = "ireplace" THEN + '********************************************************** + ' IREPLACE "this" WITH "that" IN A$ is transformed into + ' A$ = ireplace$ ( A$, "this", "that" ) + ' BCX 3.73 introduces CASE INSENSITIVE REPLACE + '********************************************************** + IF Ndx < 6 THEN Abort("Problem with IREPLACE statement") + DIM RAW W, I, VV$, RR$, WW$ + VV$ = "" : RR$ = "" : WW$ = "" + FOR W = 2 TO Ndx + IF iMatchWrd(Stk$[W],"with") THEN + Stk$[W]= "" + EXIT FOR + END IF + NEXT + FOR I = 2 TO Ndx + IF iMatchWrd(Stk$[I],"in") THEN + Stk$[I]= "" + EXIT FOR + END IF + NEXT + i = I+1 + FOR j = i TO Ndx + CONCAT (VV$,Stk$[j]) + NEXT + FOR j = 2 TO W + CONCAT (RR$,Stk$[j]) + NEXT + i = W+1 + FOR j = i TO I + CONCAT (WW$,Stk$[j]) + NEXT + lszTmp$ = "=ireplace$(" + VV$ + "," + RR$ + "," + WW$ + ")" + FastLexer(VV$," ()","") + lszTmp$ = Stk$[Ndx] + lszTmp$ + CALL XParse(lszTmp$) + CALL TokenSubstitutions + CALL Emit + Ndx = 0 + EXIT SUB + END IF + CASE 12 + IF Keyword$ = "local" AND iMatchWrd(Stk$[2],"dynamic") THEN + Stk$[1] = "dim" + EXIT SUB + END IF + CASE 16 + IF Keyword$ = "put$" THEN + Stk$[1] = "~put" + EXIT SUB + END IF + CASE 18 + IF Keyword$ = "remove" THEN + '*********************************************************** + ' Translate REMOVE UCASE$("aaa") FROM LTRIM$(RTRIM$(A$)) + ' into A$ = REMOVE$(LTRIM$(RTRIM$(A$)),UCASE$("aaa")) + '*********************************************************** + DIM RAW Mat$, Fat$ + Mat$ = "" + Fat$ = "" + FOR i = 2 TO Ndx + IF iMatchWrd(Stk$[i],"from") THEN + Stk$[i]= "" + EXIT FOR + END IF + NEXT + FOR j = 2 TO i + CONCAT(Mat$,Stk$[j]) ' build match string + NEXT + FOR j = i TO Ndx + CONCAT(Fat$,Stk$[j]) ' build fat source + NEXT + lszTmp$ = "=remove$(" + Fat$ + "," + Mat$ + ")" + FastLexer(Fat$," ()","") + lszTmp$ = Stk$[Ndx] + lszTmp$ + CALL XParse(lszTmp$) + CALL TokenSubstitutions + CALL Emit + Ndx = 0 + EXIT SUB + END IF + IF Keyword$ = "replace" THEN + '******************************************************* + ' REPLACE "this" WITH "that" IN A$ is transformed into + ' A$ = replace$ ( A$, "this", "that" ) + ' BCX 2.93 allows expressions and arrays to be used + '******************************************************* + IF Ndx < 6 THEN Abort("Problem with REPLACE statement") + DIM RAW W, I, VV$, RR$, WW$ + VV$ = "" + RR$ = "" + WW$ = "" + FOR W = 2 TO Ndx + IF iMatchWrd(Stk$[W],"with") THEN + Stk$[W]= "" + EXIT FOR + END IF + NEXT + FOR I = 2 TO Ndx + IF iMatchWrd(Stk$[I],"in") THEN + Stk$[I]= "" + EXIT FOR + END IF + NEXT + i = I+1 + FOR j = i TO Ndx + CONCAT (VV$,Stk$[j]) + NEXT + FOR j = 2 TO W + CONCAT (RR$,Stk$[j]) + NEXT + i = W+1 + FOR j = i TO I + CONCAT (WW$,Stk$[j]) + NEXT + lszTmp$ = "=replace$(" + VV$ + "," + RR$ + "," + WW$ + ")" + FastLexer(VV$," ()","") + lszTmp$ = Stk$[Ndx] + lszTmp$ + CALL XParse(lszTmp$) + CALL TokenSubstitutions + CALL Emit + Ndx = 0 + EXIT SUB + END IF + CASE 27 + SELECT CASE Keyword$ + '************************** + CASE "$ifndef" + Stk$[1] = "~ifndef" + InConditional++ + '************************** + CASE "$if","$ifdef" + Stk$[1] = "~if" + InConditional++ + '************************** + CASE "$else" + Stk$[1] = "~else" + '************************** + CASE "$elseif" + Stk$[1] = "~elseif" + '************************** + CASE "$endif" + Stk$[1] = "~endif" + InConditional-- + IF InConditional < 0 THEN 'simple check to see if to see if conditionals are balanced + Abort("To many $ENDIFs") + END IF + '************************** + CASE "$cpp" + Ndx = 0 + UseCpp = TRUE + '************************** + CASE "$CPP" + Ndx = 0 + UseCpp = TRUE + END SELECT + EXIT SUB + END SELECT + IFCond = 0 + FOR i = 1 TO Ndx + IF iMatchWrd(Stk$[i],"if") THEN IFCond = i + 1 + IF iMatchWrd(Stk$[i],"then") AND iMatchWrd(Stk$[i+1],"if") THEN + FOR j = i + 2 TO Ndx + IF iMatchWrd(Stk$[j],"else") THEN + EXIT FOR + END IF + NEXT + IF j > Ndx THEN ' safe to transform + FOR j = i TO IFCond + 1 STEP -1 + Stk$[j] = Stk$[j - 1] + NEXT + Stk$[IFCond] = "(" + i++ + Stk$[i] = ")" + i++ + FOR j = Ndx TO i STEP -1 + Stk$[j + 2] = Stk$[j] + NEXT + Ndx++ + Ndx++ + Stk$[i] = "&&" + i++ + Stk$[i] = "(" + i++ + FOR i = i TO Ndx + IF iMatchWrd(Stk$[i],"then") THEN + Ndx++ + FOR j = Ndx TO i STEP -1 + Stk$[j] = Stk$[j - 1] + NEXT + Stk$[i] = ")" + EXIT FOR + END IF + NEXT + i-- + ELSE + EXIT FOR + END IF + END IF + NEXT +END SUB ' Transforms +SUB Parse(Arg$) + '**************** + DIM RAW A, B + DIM RAW CommaCnt + DIM RAW Tmp + DIM RAW i + DIM RAW j + DIM RAW k + DIM RAW lszTmp$ + DIM RAW L_Stk_1$ + DIM RAW L_Stk_2$ + DIM RAW Var1$ + DIM RAW Plus2Amp = 0 + DIM RAW vt + '**************** + L_Stk_1$ = "" + L_Stk_2$ = "" + lszTmp$ = "" + Var1$ = "" + '**************** + CALL XParse(Arg$) + PassOne = 0 + IF NOT iMatchWrd(Stk$[1],"function") THEN + Plus2Amp = iMatchNQ(Arg$, "&") + FOR Tmp = 2 TO Ndx-1 + IF Stk$[Tmp] = "+" THEN + vt = DataType(Stk$[Tmp+1]) + IF vt = vt_STRVAR OR vt = vt_STRLIT THEN + Stk$[Tmp] = "&" + Plus2Amp = TRUE + ELSE + vt = DataType(Stk$[Tmp-1]) + IF vt = vt_STRVAR OR vt = vt_STRLIT THEN + Stk$[Tmp] = "&" + Plus2Amp = TRUE + END IF + END IF + END IF + NEXT + IF Plus2Amp > 0 THEN + Use_Join = UseFlag = TRUE + j = 0 + k = 0 + FOR Tmp = 1 TO Ndx-1 + A = CheckLocal(Stk$[Tmp], &i) + IF A = vt_UNKNOWN THEN A = CheckGlobal(Stk$[Tmp], &i) + IF A = vt_STRUCT OR A = vt_UDT OR A = vt_UNION THEN 'added vt_UNION 4.40 + j = 1 + END IF + IF Stk$[Tmp] = "&" THEN + A = DataType(Stk$[Tmp+1]) + IF A = vt_STRVAR OR A = vt_STRLIT THEN + k = 1 + ELSE + A = DataType(Stk$[Tmp-1]) + IF A = vt_STRVAR OR A = vt_STRLIT THEN + k = 1 + END IF + END IF + END IF + NEXT + IF k THEN + IF j THEN CALL AsmUnknownStructs(0) + CALL JoinStrings(1, 0) + Src$ = "" + FOR i = 1 TO Ndx + IF Stk[i][0] THEN + Src$ = Src$ + Stk$[i] + " " + END IF + NEXT + CALL XParse(Src$) + END IF + END IF + END IF + '*********************************************************** + 'Moved here by Mike H. Was being applied too early. + 'causing lines with multiple statements to not receive the + 'conversion. i.e. sp->lpVtbl->Release(sp) : sp = NULL + '*********************************************************** + IF UseCpp THEN + IF iMatchNQ(Src$,"->lpVtbl") THEN + FOR INTEGER i= 1 TO Ndx + IF iMatchRgt(Stk$[i],"->lpVtbl") THEN + Stk$[i] = EXTRACT$(Stk$[i],"->lpVtbl") + IF (Stk$[i+3] = Stk$[i-1] OR Stk$[i+3] = Stk$[i]) AND Stk$[i+3] <> ")" THEN + Stk$[i+3] = "" + IF Stk$[i+4] = "," THEN Stk$[i+4] = "" + END IF + END IF + NEXT + CALL RemEmptyTokens + END IF + END IF + '******************************************************************** + ' At this point we have a fresh set of Stk$[] values, totaling Ndx + ' Start handling some unique situations + '******************************************************************** + CALL TokenSubstitutions + IF Ndx = 0 THEN EXIT SUB + CALL Transforms + IF Ndx = 0 THEN EXIT SUB + '*********************************************************** + 'Modification to allow 2 names as function types + '*********************************************************** + IF iMatchWrd(Stk$[1],"function") THEN + IF iMatchWrd(Stk$[Ndx-2],"as") AND Stk$[Ndx] <> ")" THEN + IF NOT iMatchWrd(Stk$[Ndx],"export") AND NOT iMatchWrd(Stk$[Ndx],"stdcall") THEN + Stk$[Ndx-1] = Stk$[Ndx-1] + " " + Stk$[Ndx] + Ndx-- + END IF + END IF + END IF + '******************************************************************** + 'Modification to allow 2 names as argument types in sub or function + '******************************************************************** + IF iMatchWrd(Stk$[1],"function") OR iMatchWrd(Stk$[1],"sub") THEN + DIM RAW offset + DIM RAW LastBrk = Ndx - 2 + FOR i = Ndx TO 3 STEP -1 + IF Stk$[i] = ")" THEN + LastBrk = i + EXIT FOR + END IF + NEXT + FOR i = 3 TO LastBrk + offset = 2 + IF iMatchWrd(Stk$[i],"as") AND (i < LastBrk) AND Stk$[i + offset] <> "=" THEN + IF iMatchWrd(Stk$[i+1],"function") THEN offset = 3 + IF NOT INCHR(Stk$[i + offset],")") AND NOT INCHR(Stk$[i + offset],",") THEN + IF LEN(Stk$[i + offset]) <> 0 AND NOT iMatchWrd(Stk$[i + 3],"as") THEN + Stk$[i+offset-1] = Stk$[i+offset-1] + " " + Stk$[i+offset] + Stk$[i + offset] = "" + END IF + END IF + END IF + NEXT + END IF + '*********************************************************** + 'DynaCall Handler + IF NOT iMatchWrd(Stk$[1],"declare") THEN + FOR i = 1 TO Ndx + IF iMatchWrd(Stk$[i],"lib") THEN + IF Stk$[i-1] = "(" AND (DataType(Stk$[i+1]) = vt_STRLIT OR DataType(Stk$[i+1]) = vt_STRVAR) THEN + j = GetNumArgs(i+2) + lszTmp$ = "BCX_DynaCall" + IF NOT iMatchWrd(Stk$[1],"print") THEN 'print does its own casting + IF DataType(Stk$[i-2]) = vt_STRVAR OR DataType(Stk$[1]) = vt_STRVAR THEN + lszTmp$ = "(char*)" & lszTmp$ + END IF + END IF + Var1$ = RIGHT$(Stk$[i-2], 1) + IF INCHR ("!$#¦%", Var1$) THEN + CONCAT (lszTmp$, Var1$) + Stk$[i] = ENC$(LEFT$(Stk$[i-2], LEN(Stk$[i-2]) - 1)) + ELSE + Stk$[i] = ENC$(Stk$[i-2]) + END IF + Stk$[i-2] = lszTmp$ + FOR B = Ndx+3 TO i+3 STEP -1 + Stk$[B] = Stk$[B-3] + NEXT + Stk$[i+2] = Stk$[i+1] + Stk$[i+1] = "," + Stk$[i+3] = "," + Stk$[i+4] = LTRIM$(STR$(j)) + Stk$[i+5] = IIF$(j, ",", ")") + INCR Ndx, 3 + Use_Dynacall = TRUE + END IF + END IF + NEXT + END IF + '****************[ Exponentiation Operator Handler ]****************** + IF INCHR(Arg$,"^") THEN + DIM RAW lp = 0 + DIM RAW rp = 0 + Test = FALSE + FOR i = 1 TO Ndx + IF Stk$[i] = "^" THEN + Test = TRUE + IF Stk$[i+1] = "-" THEN + Ndx++ + FOR A = Ndx TO i+2 STEP -1 + Stk$[A] = Stk$[A-1] + NEXT + Stk$[i+1] = "(" + B = i+3 + IF Stk$[B] = "(" THEN + lp=0 + rp=0 + DO + IF Stk$[B] = "(" THEN lp++ + IF Stk$[B] = ")" THEN rp++ + B++ + LOOP UNTIL lp = rp + Ndx++ + j = B+1 + FOR A = Ndx TO j STEP -1 + Stk$[A] = Stk$[A-1] + NEXT + Stk$[B] = ")" + ELSE + B=i+4 + IF INCHR("[",Stk$[B]) THEN + DO + B++ + LOOP UNTIL INCHR("]",Stk$[B]) + Ndx++ + j = B+2 + FOR A = Ndx TO j STEP -1 + Stk$[A] = Stk$[A-1] + NEXT + Stk$[B+1] = ")" + ELSE + IF INCHR("(",Stk$[B]) THEN + DO + B++ + LOOP UNTIL INCHR(")",Stk$[B]) + Ndx++ + j = B+2 + FOR A = Ndx TO j STEP -1 + Stk$[A] = Stk$[A-1] + NEXT + Stk$[B+1] = ")" + ELSE + Ndx++ + j = B+1 + FOR A = Ndx TO j STEP -1 + Stk$[A] = Stk$[A-1] + NEXT + Stk$[B] = ")" + END IF + END IF + END IF + END IF + END IF + NEXT + IF Test THEN + FOR i = 1 TO Ndx + IF Stk$[i] = "^" THEN + A = i - 1 + B = 0 + WHILE Stk$[A] <> "=" + IF Stk$[A] = "]" THEN B++ + IF Stk$[A] = ")" THEN B++ + IF Stk$[A] = "[" THEN B-- + IF Stk$[A] = "(" THEN B-- + IF B = 0 THEN EXIT WHILE + A-- + WEND + IF Stk$[A] = "[" THEN A-- + IF Stk$[A] = "=" THEN A++ + IF Stk$[A] = "(" THEN + B = DataType(Stk$[A-1]) ' check if it's a function + IF NOT iMatchWrd(Stk$[A-1], "print") AND _ + (B = vt_INTEGER OR B = vt_SINGLE OR B = vt_DOUBLE) THEN + A-- + END IF + END IF + Arg$ = "pow(" + B = A - 1 + WHILE B > 0 + Arg$ = Stk$[B] + " " + Arg$ + " " + B-- + WEND + FOR B = A TO i - 1 + Arg$ = Arg$ + " " + Stk$[B] + NEXT + CONCAT (Arg$, ",") + A = i + 1 + B = DataType(Stk$[A]) + IF (Stk$[A + 1] = "(" OR Stk$[A + 1] = "[") AND _ + (B = vt_INTEGER OR B = vt_SINGLE OR B = vt_DOUBLE) THEN + A++ + END IF + B = 0 + WHILE A <= Ndx + IF Stk$[A] = "[" THEN B++ + IF Stk$[A] = "(" THEN B++ + IF Stk$[A] = "]" THEN B-- + IF Stk$[A] = ")" THEN B-- + IF NOT B THEN EXIT DO + A++ + WEND + FOR B = i + 1 TO A + Arg$ = Arg$ + " " + Stk$[B] + NEXT + CONCAT(Arg$,")") + A++ + WHILE A <= Ndx + Arg$ = Arg$ + " " + Stk$[A] + A++ + WEND + EXIT FOR + END IF + NEXT + CALL Parse(Arg$) + END IF + END IF + '***************************************************** + L_Stk_1$ = LCASE$(Stk$[1]) ' Performance Optimizer + L_Stk_2$ = LCASE$(Stk$[2]) ' Performance Optimizer + '***************************************************** + IF L_Stk_1$ = "$dll" THEN + MakeDLL = NoMain = TRUE + IF IsApple then + LD_FLAGS$ = "-fPIC -shared $FILE$.so" + ELSE + LD_FLAGS$ = "-fPIC -shared -Wl,-soname,$FILE$.so" + END IF + + Ndx = 0 + '~ IF L_Stk_2$ = "stdcall" THEN + '~ UseStdCall = TRUE + '~ END IF + '~ IF NoDllMain THEN + '~ EXIT SUB + '~ END IF + '~ FPRINT Outfile,"" + '~ FPRINT Outfile,"__declspec(dllexport) bool WINAPI DllMain (HINSTANCE hInst, DWORD Reason, LPVOID Reserved)" + '~ FPRINT Outfile,"{" + '~ FPRINT Outfile," switch (Reason)" + '~ FPRINT Outfile," {" + '~ FPRINT Outfile," case DLL_PROCESS_ATTACH:" + '~ FPRINT Outfile," BCX_hInstance = hInst;" + '~ FPRINT Outfile," break;" + '~ FPRINT Outfile," case DLL_PROCESS_DETACH:" + '~ FPRINT Outfile," break;" + '~ FPRINT Outfile," case DLL_THREAD_ATTACH:" + '~ FPRINT Outfile," break;" + '~ FPRINT Outfile," case DLL_THREAD_DETACH:" + '~ FPRINT Outfile," break;" + '~ FPRINT Outfile," }" + '~ FPRINT Outfile," return TRUE;" + '~ FPRINT Outfile,"}\n\n" + '~ Src$ = "GLOBAL BCX_hInstance AS HINSTANCE" + '~ Parse(Src$) + '~ Emit() + EXIT SUB + END IF + IsCallBack = 0 + '****************************** + IF iMatchWrd(Stk$[Ndx],"callback") THEN + IsCallBack = 1 + Ndx-- + END IF + '****************************** + IF L_Stk_1$ = "open" THEN + FOR A = 1 TO Ndx + IF iMatchWrd(Stk$[A],"binary") THEN + EXIT FOR + END IF + NEXT + IF A < Ndx THEN + A++ + Var1$ = LCASE$(Stk$[A]) + IF Var1$ = "new" THEN + Stk$[A-1]= "binarynew" + FOR i = A+1 TO Ndx + Stk$[i-1]= Stk$[i] + NEXT + Ndx-- + END IF + IF Var1$ = "append" THEN + Stk$[A-1]= "binaryappend" + FOR i = A+1 TO Ndx + Stk$[i-1]= Stk$[i] + NEXT + Ndx-- + END IF + IF Var1$ = "input" THEN + Stk$[A-1]= "binaryinput" + FOR i = A+1 TO Ndx + Stk$[i-1]= Stk$[i] + NEXT + Ndx-- + END IF + IF Var1$ = "output" THEN + Stk$[A-1]= "binaryoutput" + FOR i = A+1 TO Ndx + Stk$[i-1]= Stk$[i] + NEXT + Ndx-- + END IF + END IF + END IF + IF L_Stk_1$ = "option" AND L_Stk_2$ = "base" THEN + OptionBase = VAL(Stk$[3]) + Ndx = 0 + EXIT SUB + END IF + '****************************** + IF L_Stk_1$ = "dim" THEN + IF L_Stk_2$ = "shared" OR _ + L_Stk_2$ = "dynamic" OR _ + L_Stk_2$ = "raw" OR _ + L_Stk_2$ = "local" OR _ + L_Stk_2$ = "auto" OR _ + L_Stk_2$ = "register" OR _ + L_Stk_2$ = "static" THEN + Stk$[1] = L_Stk_2$ + L_Stk_1$ = L_Stk_2$ + FOR i = 3 TO Ndx + Stk$[i-1]= Stk$[i] + NEXT + Ndx-- + END IF + END IF + '****************************** + IF L_Stk_1$ = "public" THEN + IF L_Stk_2$ = "function" OR L_Stk_2$ = "sub" THEN + Stk$[1] = L_Stk_2$ + L_Stk_1$ = L_Stk_2$ + FOR i = 3 TO Ndx + Stk$[i-1] = Stk$[i] + NEXT + Ndx-- + END IF + END IF + '****************************** + ' creates a static function for use in $PROJECTs + IF L_Stk_1$ = "private" THEN + IF L_Stk_2$ = "function" OR L_Stk_2$ = "sub" THEN + Use_Static = TRUE + Stk$[1] = L_Stk_2$ + L_Stk_1$ = L_Stk_2$ + FOR i = 3 TO Ndx + Stk$[i-1] = Stk$[i] + NEXT + Ndx-- + END IF + END IF + '****************************** + IF L_Stk_1$ = "onexit" THEN + IF L_Stk_2$ = "sub" THEN + Use_ExitCode = TRUE + INCR ExitNdx + ExitSub$[ExitNdx] = Stk$[3] + Stk$[1] = L_Stk_2$ + L_Stk_1$ = L_Stk_2$ + FOR i = 3 TO Ndx + Stk$[i-1] = Stk$[i] + NEXT + Ndx-- + END IF + END IF + '****************************** + IF L_Stk_1$ = "onstart" THEN + IF L_Stk_2$ = "sub" THEN + Use_StartupCode = TRUE + INCR StartNdx + StartSub$[StartNdx] = Stk$[3] + Stk$[1] = L_Stk_2$ + L_Stk_1$ = L_Stk_2$ + FOR i = 3 TO Ndx + Stk$[i-1] = Stk$[i] + NEXT + Ndx-- + END IF + END IF + '****************************** + IF L_Stk_1$ = "overloaded" AND L_Stk_2$ = "function" THEN + Stk$[1] = "overloadedfunction" + L_Stk_1$ = "overloadedfunction" + FOR i = 3 TO Ndx + Stk$[i-1]= Stk$[i] + NEXT + Ndx-- + END IF + '****************************** + IF L_Stk_1$ = "overloadedfunction" AND Stk$[2] <> "=" THEN + OkayToSend = TRUE + END IF + '****************************** + IF L_Stk_1$ = "overloaded" AND L_Stk_2$ = "sub" THEN + Stk$[1]= "overloadedsub" + FOR i = 3 TO Ndx + Stk$[i-1] = Stk$[i] + NEXT + Ndx-- + END IF + '****************************** + IF L_Stk_1$ = "function" AND iMatchWrd(Stk[3],"optional") THEN + Stk$[1]= "optfunction" + L_Stk_1$ = "optfunction" + FOR i = 4 TO Ndx + Stk$[i-1]= Stk$[i] + NEXT + Ndx-- + END IF + '****************************** + IF L_Stk_1$ = "optfunction" AND Stk$[2] <> "=" THEN + OkayToSend = TRUE + END IF + '****************************** + IF L_Stk_1$ = "sub" AND iMatchWrd(Stk[3],"optional") THEN + L_Stk_1$ = "optsub" + Stk$[1]= "optsub" + FOR i = 4 TO Ndx + Stk$[i-1]= Stk$[i] + NEXT + Ndx-- + END IF + '****************************** + IF L_Stk_1$ = "end" AND Stk$[2] <> "=" THEN + Stk$[1]= L_Stk_1$ + L_Stk_2$ + Ndx = 1 + END IF + '****************************** + IF L_Stk_1$ = "function" AND Stk$[2] <> "=" THEN + OkayToSend = TRUE + END IF + '****************************** + IF L_Stk_1$ = "midstr" THEN + CommaCnt = 0 + FOR i = 1 TO Ndx + IF Stk$[i] = "," THEN + INCR CommaCnt + ELSEIF Stk$[i]= "=" THEN + IF CommaCnt < 2 THEN + Stk$[i] = "-1," + ELSE + Stk$[i]= "" + END IF + Stk$[i-1]= "," + Ndx++ + Stk$[Ndx]= ")" + EXIT FOR + END IF + NEXT + END IF + '****************************** + IF Stk$[2]= ":" THEN + IF Ndx = 2 THEN + Stk$[1]= UCASE$(Stk$[1]) + ":" 'preserve the GOTO labels + Ndx = 1 + EXIT SUB + END IF + END IF + '****************************** + IF L_Stk_1$ = "case" AND L_Stk_2$ = "else" THEN + Ndx = 1 + Stk$[1]= "caseelse" + END IF + '****************************** + FOR i = 1 TO Ndx + IF iMatchWrd(Stk$[i],"let") THEN + FOR j = i+1 TO Ndx + Stk$[j-1] = Stk$[j] + NEXT + Ndx-- + END IF + NEXT + '****************************** + IF Stk$[Ndx]= "*" THEN + Stk$[Ndx-1]= Stk$[Ndx-1] + "*" + Ndx-- + END IF + '****************************** + IF TestState = TRUE THEN + IF LastCmd = 0 THEN + IF Stk$[1] = "*" THEN + Z$ = Clean$(Stk$[2]) + ELSE + Z$ = Clean$(Stk$[1]) + END IF + IF LEFT$(Z$,1) = "*" THEN Z$ = MID$(Z$,2) + i = INCHR(Z$,".") + IF i = 0 THEN i = INSTR(Z$,"->") + IF i > 0 THEN + IF WithCnt THEN + Z$ = WithVar$[WithCnt] + ELSE + Z$ = LEFT$(Z$, i - 1) + END IF + END IF + IF INCHR(Z$,"[") THEN Z$ = EXTRACT$(Z$,"[") + IF CheckLocal(Z$, &j) = vt_UNKNOWN THEN + IF CheckGlobal(Z$, &j) = vt_UNKNOWN THEN + Z$ = LCASE$(Z$) + IF Stk$[2] = "=" AND Z$ <> "functionreturn" AND Z$ <> "bcx_retstr" AND Z$ <> "end" THEN + Warning("Assignment before Declaration in Line " + STR$(ModuleLineNos[ModuleNdx]) + " in Module: " + TRIM$(Modules$[ModuleNdx]) + ": " + Src$) + END IF + END IF + END IF + END IF + END IF +END SUB ' Parse +SUB FuncSubDecs1(s$) + '***************** + DIM RAW i, j + '***************** + IF iMatchWrd(Stk$[1], s$) THEN + IF DataType(Stk$[2]) = vt_STRVAR THEN + Abort("Invalid " + s$ + "name") + END IF + END IF + FOR i = 1 TO Ndx + IF Stk$[i]= "[" AND Stk$[i+1]= "]" THEN + IF iMatchWrd(Stk$[i+2],"as") THEN + Stk$[i+3] = Stk$[i+3] + "*" + ELSEIF Stk$[i+2] = "[" THEN + j = i-1 + WHILE i <= Ndx + IF iMatchWrd(Stk$[i],"as") THEN EXIT FOR + IF iMatchRgt(Stk$[j],"]") AND INCHR(",)=", Stk$[i]) THEN EXIT FOR + Stk$[j] = Stk$[j] + Stk$[i] + Stk$[i++] = "" + WEND + ITERATE + ELSE + IF DataType(Stk$[i-1]) = vt_STRVAR THEN + Stk$[i-1] = Stk$[i-1] + "[][65535]" + END IF + Stk$[i-1] = "*" + Stk$[i-1] + END IF + Stk$[i++] = "" : Stk$[i] = "" + END IF + NEXT + CALL RemEmptyTokens + IsExported = FALSE + IF iMatchWrd(Stk$[Ndx],"export") THEN + Ndx-- + IsExported = TRUE + IF UseStdCall THEN + CallType$ = "__attribute__((stdcall)) " + ELSE + CallType$ = "__attribute__((cdecl)) " + END IF + END IF +END SUB ' FuncSubDecs1 + +SUB RemEmptyTokens() + DIM RAW i, j + FOR i = 1 TO Ndx + IF NOT *Stk[i] THEN + j = i + WHILE NOT *Stk[j] AND (j < Ndx) + INCR j + WEND + IF NOT *Stk[j] THEN EXIT FOR + Stk$[i] = Stk$[j] + Stk$[j] = "" + END IF + NEXT i + Ndx = i-1 +END SUB +SUB FuncSubDecs2(s$, method) + IF iMatchWrd(Stk$[1], s$) THEN + IF iMatchWrd(Stk$[Ndx-1],"as") THEN + Abort("Attempted type assignment to " + s$) + END IF + VarCode.IsPtrFlag = 0 + CurrentFuncType = vt_VOID + ELSE + IF iMatchWrd(Stk$[Ndx-1],"as") THEN + CurrentFuncType = CheckType(Stk$[Ndx]) + VarCode.Token$ = Stk$[2] + VarCode.AsToken$ = Stk$[Ndx] + VarCode.IsPtrFlag = TALLY(Stk$[Ndx],"*") + Stk$[Ndx] = "" + Stk$[Ndx-1] = "" + Ndx-- + Ndx-- + ELSE + CurrentFuncType = DataType(Stk$[2]) + VarCode.Token$ = Stk$[2] + 'print Stk$[2] + VarCode.IsPtrFlag = TALLY(Stk$[2],"*") + VarCode.AsToken$ = "" + END IF + END IF + VarCode.Proto$ = " (" + VarCode.Header$ = " (" + VarCode.Functype$ = "" + VarCode.Method% = method + VarCode.VarNo% = CurrentFuncType + CALL GetVarCode(&VarCode) +END SUB ' FuncSubDecs2 + +SUB FuncSubDecs3(varcode AS VARCODE PTR) + IF *Stk[Ndx-1] = ASC(".") THEN ' Allow Functions | Subs WITH one OR + varcode->Header$ = varcode->Header$ + "..." ' more "." TO produce the "..." needed + END IF + varcode->Header$ = RTRIM$(varcode->Header$) + IF iMatchRgt(varcode->Header$, ",") THEN + MID$(varcode->Header$, LEN(varcode->Header$)) = ")" + ELSE + CONCAT(varcode->Header$, ")") + END IF + REPLACE "()" WITH "(void)" IN varcode->Header$ + varcode->Header$ = varcode->Functype$ + varcode->Token$ + varcode->Header$ + IF varcode->Method% = 2 THEN + IF *Stk[Ndx-1] = ASC(".") THEN ' Allow Functions | Subs with one OR + varcode->Proto$ = varcode->Proto$ + "..." ' FOR variable argument declarations + END IF + varcode->Proto$ = RTRIM$(varcode->Proto$) + IF iMatchRgt(varcode->Proto$, ",") THEN + MID$(varcode->Proto$, LEN(varcode->Proto$)) = ")" + ELSE + CONCAT(varcode->Proto$, ")") + END IF + REPLACE "()" WITH "(void)" IN varcode->Proto$ + varcode->Proto$ = varcode->Functype$ + varcode->Token$ + varcode->Proto$ + ";" + END IF + IF IsExported THEN + varcode->Proto$ = "C_EXPORT " + varcode->Proto$ + varcode->Header$ = "C_EXPORT " + varcode->Header$ + END IF +END SUB ' FuncSubDecs3 + +SUB AddTypeDefs(TypeName$, TDef) + TypeDefsCnt++ + IF TypeDefsCnt = MaxTypes THEN Abort("Exceeded TYPE Limits.") + TypeDefs[TypeDefsCnt].VarName$ = TypeName$ + TypeDefs[TypeDefsCnt].TypeofDef = TDef + TypeDefs[TypeDefsCnt].EleCnt = 0 +END SUB ' AddTypeDefs + +FUNCTION DefsID(ZZ$) + DIM RAW i + IF TypeDefsCnt > 0 THEN + FOR i = 1 TO TypeDefsCnt + IF ZZ$ = TypeDefs[i].VarName$ THEN + FUNCTION = i + END IF + NEXT + END IF + FUNCTION = 0 +END FUNCTION ' DefsID + +SUB GetTypeInfo(stk$, BYREF IsPointer, BYREF UdtIdx, BYREF vtCode) + DIM RAW Var1$ + IsPointer = TALLY(stk$,"*") + Var1$ = REMOVE$(stk$,"*") + ' if it's a CLASS then get the structure information added 2008/10/07 + IF RIGHT$(Var1$,6) = "_CLASS" THEN Var1$ = LEFT$(Var1$,LEN(Var1$)-6) + vtCode = CheckType(Var1$) + IF vtCode = vt_UNKNOWN THEN + CALL AddTypeDefs(Var1$, vt_UDT) 'windows def + vtCode = vt_UDT + END IF + UdtIdx = 0 + IF vtCode = vt_STRUCT OR vtCode = vt_UNION OR vtCode = vt_UDT THEN + UdtIdx = DefsID(Var1$) + END IF +END SUB ' GetTypeInfo + +SUB AddTypedefElement(WorkingTypeDefsCnt, ElType, EName$, EType$, EPtr) + DIM RAW TD AS UserTypeDefs PTR + TD = &(TypeDefs[WorkingTypeDefsCnt]) + IF TD->EleCnt = MaxElements THEN Abort("Exceeded TYPE Element Limits.") + TD->Elements[TD->EleCnt].ElementType = ElType + TD->Elements[TD->EleCnt].ElementDynaPtr = EPtr + IF ElType = vt_STRUCT OR ElType = vt_UNION OR ElType = vt_UDT THEN + TD->Elements[TD->EleCnt].ElementID = DefsID(EType$) + ELSE + TD->Elements[TD->EleCnt].ElementID = 0 + END IF + TD->Elements[TD->EleCnt].ElementName$ = EName$ + TD->EleCnt = 1 + TD->EleCnt +END SUB ' AddTypedefElement + +FUNCTION GetElement$(StartStk, BYREF vt, BYREF dms, id) + DIM RAW BC = 0, i, ZZ$ + FOR i = StartStk+1 TO Ndx + IF Stk$[i] = "[" THEN + INCR BC + ELSEIF Stk$[i] = "]" THEN + DECR BC + ELSEIF BC = 0 THEN + IF iMatchLft(Stk$[i], "->") OR *Stk$[i] = ASC(".") THEN + ZZ$ = Clean$(Stk$[i]) + RemoveAll(ZZ$, ".->(*)", 1) + vt = GetElementInfo(&id, &dms, ZZ$) + IF vt <> vt_STRUCT AND vt <> vt_UNION THEN EXIT FOR + END IF + END IF + NEXT + IF vt = vt_UDT OR vt = vt_UNION OR vt = vt_STRUCT THEN + ZZ$ = TypeDefs[id].VarName$ + ELSE + ZZ$ = GetVarTypeName(vt) + END IF + FUNCTION = ZZ$ +END FUNCTION + +FUNCTION GetElementInfo(BYREF DefID, BYREF EPtr, Elename$) + DIM RAW i, id + id = DefID + FOR i = 0 TO TypeDefs[id].EleCnt - 1 + IF Elename$ = TypeDefs[id].Elements[i].ElementName$ THEN + DefID = TypeDefs[id].Elements[i].ElementID + EPtr = TypeDefs[id].Elements[i].ElementDynaPtr + FUNCTION = TypeDefs[id].Elements[i].ElementType + END IF + NEXT + FUNCTION = 0 +END FUNCTION + +SUB HandleNonsense + DIM RAW i + FOR i = 1 TO Ndx ' tolerate nonsense like DIM A% as double + IF iMatchWrd(Stk$[i],"as") THEN Stk$[i - 1] = Clean$(Stk$[i - 1]) + IF OptionBase THEN ' This was the easiest way I could see to do this! + IF Stk$[i] = "[" THEN Stk$[i+1] = LTRIM$(STR$(OptionBase)) + "+" + Stk$[i+1] + END IF + NEXT +END SUB ' HandleNonsense +SUB ValidVar(v$) + DIM RAW ZZ$ + IF NOT isalpha(*v$) AND *v$ <> ASC("_") THEN + IF NOT iMatchLft(v$, "(*") THEN ' Allow byref format (*A).xxx + Abort("Invalid String Variable Name") + END IF + END IF + IF RestrictedWords(v$) AND TestState THEN + ZZ$ = "Variable " + v$ + " on line" + ZZ$ = ZZ$ + STR$(ModuleLineNos[ModuleNdx]) + " in Module: " + TRIM$(Modules$[ModuleNdx]) + " is a Restricted Word" + CALL Warning(ZZ$) + END IF +END SUB ' ValidVar + +SUB PointerFix + Stk$[Ndx-1] = Stk$[Ndx-1] + Stk$[Ndx] + Stk[Ndx][0] = 0 + Ndx-- + WHILE TALLY(Stk$[Ndx],"*") = LEN(Stk$[Ndx]) + Stk$[Ndx-1] = Stk$[Ndx-1] + Stk$[Ndx] + Stk[Ndx][0] = 0 + Ndx-- + WEND +END SUB ' PointerFix + +SUB DimDynaString(SVar$, DG, s) + DIM RAW A + DIM RAW DS$ + DS$ = "if(" + SVar$ + ")free(" + SVar$ + ");" + IF InFunc AND (IsLocal OR IsDim OR IsRaw OR IsAuto OR IsRegister) AND DG = 0 THEN + LocalDynaCnt++ + DynaStr$[LocalDynaCnt] = DS$ + IF IsAuto THEN + FPRINT Outfile,Scoot$ ;"char *";SVar$;";" + ELSEIF IsRegister THEN + FPRINT Outfile,Scoot$ ;"register char *";SVar$;";" + ELSE + FPRINT Outfile,Scoot$ ;"char *";SVar$;";" + END IF + CALL AddLocal(SVar$, vt_CHAR, 0,"",1,0,0) + ELSE + IF Use_GenFree THEN + GlobalDynaCnt++ + GlobalDynaStr$[GlobalDynaCnt] = DS$ + END IF + IF DG = 2 THEN + CALL AddGlobal(SVar$, vt_CHAR, 0,"",1,0,1,0) + ELSE + IF s THEN + CALL AddGlobal(SVar$, vt_CHAR, 0,"",1,0,2,0) + ELSE + CALL AddGlobal(SVar$, vt_CHAR, 0,"",1,0,0,0) + END IF + END IF + END IF + IF DG <> 2 THEN + FPRINT Outfile,Scoot$ ; SVar$ ; "=(char*)calloc(256+"; + FOR A = 4 TO Ndx + FPRINT Outfile,Clean$(Stk$[A]); + NEXT + FPRINT Outfile,",1);" + END IF +END SUB ' DimDynaString + +FUNCTION SubFuncTest + IF iMatchWrd(Stk$[2],"function") OR iMatchWrd(Stk$[2],"sub") THEN + FUNCTION = 1 + END IF + FUNCTION = 0 +END FUNCTION ' SubFuncTest + +FUNCTION DimSubFunc(IsDynamic) + '****************************** + DIM RAW i + DIM RAW lszTmp$ + DIM RAW StartPoint = 3 + DIM RAW Funptr = 0 + '****************************** + lszTmp$ = "" + IF iMatchWrd(Stk$[Ndx],"stdcall") THEN + CallType$ = "__attribute__((stdcall)) " + Ndx-- + IsStdFunc = TRUE + ELSE + CallType$ = "__attribute__((cdecl)) " ' Default calling convention + IsStdFunc = FALSE + END IF + GLOBAL SFPOINTER + DIM FP AS functionParse + '------------------------------------------------------ + ' Find start of function body ( ... ) + '------------------------------------------------------ + CALL SepFuncArgs(3, &FP, TRUE) + StartPoint = MAX(FP.CommaPos[0], 3) + IF NOT InTypeDef THEN + SFPOINTER = TRUE + '------------------------------------------------------ + ' Get intialized data " = xxx" or "= {xxx,xxx}" + '------------------------------------------------------ + IF FP.NumArgs = 0 THEN + i = MIN(FP.CommaPos[1]+1, Ndx) + ELSE + i = MIN(FP.CommaPos[FP.NumArgs]+1, Ndx) + END IF + IF Stk$[i] = "=" THEN + Stk$[i++] = "" + WHILE NOT iMatchWrd(Stk$[i], "as") AND i <= Ndx + lszTmp$ = lszTmp$ +Stk$[i] + Stk$[i++] = "" + WEND + RemoveAll(lszTmp$, "{}", 1) + IF lszTmp$ <> "" THEN CALL RemEmptyTokens + END IF + '------------------------------------------------------ + IF NOT InNameSpace THEN FPRINT FP4, MakeDecProto$(&FP), ";" + SFPOINTER = FALSE + Ndx = StartPoint + Stk$[2] = "" + IF lszTmp$ <> "" THEN + Stk$[Ndx++] = "=" + Stk$[Ndx++] = "{" + Stk$[Ndx++] = Clean$(lszTmp$) + Stk$[Ndx++] = "}" + END IF + Stk$[Ndx++] = "as" + Stk$[Ndx] = Clean$(Stk$[3]) + "_TYPE" + STRING$(Funptr, ASC("*")) + CALL RemEmptyTokens + FUNCTION = FALSE + ELSE + '/***** 2010-11-15 Added Constructor/Destructor - AIR *****/ + IF iMatchWrd(Stk$[2], "constructor") OR iMatchWrd(Stk$[2], "destructor") THEN + FPRINT Outfile, LF$, Scoot$, MakeDecProto$(&FP),";" + '/***** 2010-12-01 Added to support Abtract Classes - AIR *****/ + ELSEIF Use_Virtual THEN + FPRINT Outfile, Scoot$, "virtual ", MakeDecProto$(&FP), vproc$, ";" + Use_Virtual = FALSE + ELSE + FPRINT Outfile, Scoot$, MakeDecProto$(&FP), ";" + END IF + END IF + FUNCTION = TRUE +END FUNCTION ' DimSubFunc + +SUB Emit + '****************************** + DIM RAW HasStorage = 0 + DIM RAW A,B,i,j,Tmp + DIM RAW FuncRetnFlag + DIM RAW IsPointer = 0 + DIM RAW VType + DIM RAW id = 0 + DIM RAW k = 0 + DIM RAW vt = 0 + DIM RAW Arg$ + DIM RAW CVar$ + DIM RAW Keyword$ + DIM RAW lszTmp$ + DIM RAW Var1$ + DIM RAW ZZ$ + DIM RAW IsSubOrFuncPtr + DIM RAW dms + STATIC NoBreak + STATIC NoBreak2 + '****************************** + FuncRetnFlag = 0 + lszTmp$ = "" + ZZ$ = "" + '****************************** + '************************************* + ' Resets the break suppression flag if + ' any keyword follows other than these + '************************************* + Keyword$ = LCASE$(Stk$[1]) + IF NoBreak2 AND NOT iMatchLft(Keyword$,"case") AND NOT iMatchWrd(Keyword$,"endselect") THEN + NoBreak2 = 0 + END IF + '********************* + EmitAgain: + '********************* + IF Ndx = 0 THEN EXIT SUB + Statements++ + IF iMatchRgt(Stk$[1], ":") THEN 'This Must Be A Label + FPRINT Outfile,"" + FPRINT Outfile,UCASE$(Stk$[1]),";" + EXIT SUB + END IF + '--------- BEGIN INSERT ---------------- + FOR i = 1 TO Ndx + REPLACE CHR$(-15) WITH ":" IN Stk$[i] + NEXT + '--------- END INSERT ---------------- + IF (CurrentFuncType = vt_STRVAR) AND InFunc AND OkayToSend THEN + FPRINT Outfile,Scoot$,"char *BCX_RetStr={0};" + OkayToSend = 0 + END IF + '************************** + ' SingleLineIfReEntry: + '************************** + Lookup$ = LCASE$(Stk$[1]) + SELECT CASE Lookup$ + '******************************************************************** + CASE "fprint", "sprint" + '******************************************************************** + DIM RAW IsLprint = FALSE + DIM RAW IsSprint = FALSE + IF iMatchWrd(Stk$[1],"sprint") THEN + IsSprint = TRUE + END IF + IF IsNumber(Stk$[2]) THEN + Stk$[2] = "FP" + Stk$[2] + END IF + IF IsSprint THEN + Handl$ = Clean$(Stk$[2]) + ELSE + IF LCASE$(Stk$[2]) = "stderr" THEN + Handl$ = LCASE$(Stk$[2]) + ELSE + IF CheckLocal(Stk$[2], &i) = vt_UNKNOWN THEN + IF CheckGlobal(Stk$[2], &i) = vt_UNKNOWN THEN + CALL AddGlobal(Stk$[2], vt_FILEPTR, 0,"",0,0,0,0) + END IF + END IF + Handl$ = "" + FOR i = 2 TO Ndx + IF *Stk$[i] = ASC(",") OR *Stk$[i] = ASC(";") THEN + Stk$[i] = "" + EXIT FOR + END IF + Handl$ = Handl$ + Stk$[i] + Stk$[i] = "" + NEXT i + Handl$ = Handl$ + "@" + END IF + END IF + Stk$[2] = "" 'get rid of handle + Stk$[3] = "" 'get rid of the Comma + IF IsSprint THEN + ZZ$ = "s" + PrintWriteFormat$(0) + REMOVE "\\n" FROM ZZ$ + ELSE + ZZ$ = "f" + PrintWriteFormat$(0) + END IF + ZZ$ = LEFT$(ZZ$,8) + REMOVE$(Handl$,"@") + "," + MID$(ZZ$,9) + FPRINT Outfile,Scoot$, ZZ$ + '*********************** + CASE "end" + '*********************** + IF Ndx = 1 THEN + FPRINT Outfile,Scoot$,"fflush(stdout);" + FPRINT Outfile,Scoot$,"exit(0);" + EXIT SELECT + END IF + IF Stk$[2] = "=" THEN + FPRINT Outfile,Scoot$,"fflush(stdout);" + FPRINT Outfile,Scoot$,"exit("; + FOR Tmp = 3 TO Ndx + FPRINT Outfile,Clean$(Stk$[Tmp]); + NEXT + FPRINT Outfile,");" + EXIT SELECT + END IF + IF iMatchWrd(Stk$[2],"if") THEN + CALL BumpDown + FPRINT Outfile,Scoot$,"}" + CALL BumpDown + EXIT SELECT + END IF + '*********************** + CASE "endif" + '*********************** + CALL BumpDown + FPRINT Outfile,Scoot$,"}" + CALL BumpDown + '*********************** + CASE "if" + '*********************** + CALL EmitIfCond("if") + '*********************** + CASE "elseif" + '*********************** + CALL BumpDown + FPRINT Outfile,Scoot$,"}" + CALL BumpDown + CALL EmitIfCond("else if") + '****************************************************** + CASE "for" + '****************************************************** + DIM RAW FFlg = 0 + DIM RAW For1 = 0 + DIM RAW For2 = 0 + DIM RAW For3 = 0 + DIM RAW For4 = 0 + DIM RAW Reg$, xxx$, yyy$, zzz$, qqq$ + Reg$ = "" + xxx$ = "" + yyy$ = "" + zzz$ = "" + qqq$ = "" + '****************************************************** + FOR i = Ndx TO 1 STEP -1 + IF iMatchWrd(Stk$[i],"step") THEN + FFlg = TRUE + EXIT FOR + END IF + NEXT + IF NOT FFlg THEN + Ndx++ + Stk$[Ndx] = "step" + Ndx++ + Stk$[Ndx] = "1" + END IF + '****************************************************** + Test = FALSE + FOR i = 1 TO Ndx + IF Stk$[i]= "=" THEN Test = TRUE + NEXT + IF Test = FALSE THEN Abort("Missing =") + '****************************************************** + Test = FALSE + FOR i = 1 TO Ndx + IF iMatchWrd(Stk$[i],"to") THEN Test = TRUE + NEXT + IF Test = FALSE THEN Abort("Missing TO") + '****************************************************** + Reg$ = LCASE$(Stk$[2]) + SELECT CASE Reg$ + CASE "int","fint" + Reg$ = SPC$ + LoopLocalVar[LoopLocalCnt++] = 1 + FPRINT Outfile,Scoot$," {register int "; + CASE "single", "float" + Reg$ = SPC$ + LoopLocalVar[LoopLocalCnt++] = 1 + FPRINT Outfile,Scoot$," {float "; + CASE "double" + Reg$ = SPC$ + LoopLocalVar[LoopLocalCnt++] = 1 + FPRINT Outfile,Scoot$," {double "; + CASE "ldouble" + Reg$ = SPC$ + LoopLocalVar[LoopLocalCnt++] = 1 + FPRINT Outfile,Scoot$," {LDOUBLE "; + CASE ELSE + Reg$ = "" + LoopLocalVar[LoopLocalCnt++] = 0 + END SELECT + IF LEN(Reg$) THEN + FOR j = 3 TO Ndx + Stk$[j-1] = Stk$[j] + NEXT + Ndx-- + END IF + '****************************************************** + ' Every statement now conforms to the following: + ' FOR xxx = yyy TO zzz STEP qqq + '****************************************************** + FOR i = 2 TO Ndx + IF Stk$[i] = "=" THEN + For1 = i-1 'xxx spans from Stk$[2] to Stk$[For1] + EXIT FOR + END IF + NEXT + FOR i = For1+2 TO Ndx + IF iMatchWrd(Stk$[i],"to") THEN + For2 = i-1 'yyy spans from Stk$[For1+2] to Stk$[For2] + EXIT FOR + END IF + NEXT + FOR i = For2+2 TO Ndx + IF iMatchWrd(Stk$[i],"step") THEN + For3 = i-1 'zzz spans from Stk$[For2+2] to Stk$[For3] + EXIT FOR + END IF + NEXT + For4 = For3+2 'qqq spans from Stk$[For4] to Stk$[Ndx] + FOR i = 2 TO For1 + CONCAT(xxx$,Stk$[i]) + NEXT + FOR i = For1+2 TO For2 + CONCAT(yyy$,Stk$[i]) + NEXT + FOR i = For2+2 TO For3 + CONCAT(zzz$,Stk$[i]) + NEXT + FOR i = For4 TO Ndx + CONCAT(qqq$,Stk$[i]) + NEXT + xxx$ = Clean$(xxx$) + yyy$ = Clean$(yyy$) + zzz$ = Clean$(zzz$) + qqq$ = Clean$(qqq$) + IF Reg$ = SPC$ THEN FPRINT Outfile, xxx$, ";" + Reg$ = "" + IF IsNumberEx (qqq$) THEN + IF LEFT$(qqq$,1) = "-" THEN + FPRINT Outfile,Scoot$,"for(", Reg$, xxx$, "=", yyy$, "; ", xxx$, ">=" , zzz$, "; " , xxx$, "+=" , qqq$, ")" + ELSE + FPRINT Outfile,Scoot$,"for(", Reg$, xxx$, "=", yyy$, "; ", xxx$, "<=" , zzz$, "; " , xxx$, "+=" , qqq$, ")" + END IF + ELSE + FPRINT Outfile,Scoot$,"for(", Reg$, xxx$, "=", yyy$, "; ", qqq$, ">=0 ? ", xxx$, "<=" , zzz$, " : ", xxx$, ">=", zzz$, "; " , xxx$, "+=" , qqq$, ")" + END IF + CALL BumpUp + FPRINT Outfile,Scoot$,"{" + CALL BumpUp + '*********************** + CASE "next" + '*********************** + CALL BumpDown + FPRINT Outfile,Scoot$,"}" + IF LoopLocalVar[--LoopLocalCnt] THEN FPRINT Outfile,Scoot$,"}" + IF LoopLocalCnt < 0 THEN Abort ("Next without For") + CALL BumpDown + '*********************** + CASE "do" + '*********************** + FPRINT Outfile,Scoot$,"for(;;)" + CALL BumpUp + FPRINT Outfile,Scoot$,"{" + CALL BumpUp + '*********************** + CASE "loop" + '*********************** + CALL BumpDown + FPRINT Outfile,Scoot$,"}" + CALL BumpDown + '*********************** + CASE "caseelse" + '*********************** + CaseElseFlag[Pusher] = TRUE + IF CaseFlag THEN + IF NoBreak2 = 0 THEN + FPRINT Outfile,Scoot$,"break;" + END IF + CALL BumpDown + FPRINT Outfile,Scoot$,"}" + FPRINT Outfile,Scoot$,"// case else" + FPRINT Outfile,Scoot$,"{" + CALL BumpUp + END IF + '*********************** + CASE "endselect" + '*********************** + IF CaseFlag THEN + CALL BumpDown + FPRINT Outfile,Scoot$,"}" + END IF + CALL BumpDown + ' Only suppress this break if the Case block contains + ' a "CASE ELSE" and the last statement is a redirection. + IF CaseElseFlag[Pusher] = 0 OR NoBreak2 = 0 THEN + FPRINT Outfile,Scoot$,"break;" + END IF + CALL BumpDown + FPRINT Outfile,Scoot$,"}" + NoBreak2 = CaseElseFlag[Pusher] = 0 + CALL Pop(CaseVar$) + '*********************** + CASE "else" + '*********************** + CALL BumpDown + FPRINT Outfile,Scoot$,"}" + CALL BumpDown + FPRINT Outfile,Scoot$,"else" + CALL BumpUp + FPRINT Outfile,Scoot$,"{" + CALL BumpUp + ' ************** + CASE "case" + ' ************** + FOR i = 2 TO Ndx + IF Stk$[i] = "%" THEN Stk$[i] = " % " ' Added by MrBCX 3.36 + IF Stk$[i] = "!=" THEN Stk$[i] = "<>" + IF Stk$[i] = "!" AND Stk$[i+1] = "=" THEN + Stk$[i] = "<>" : Stk$[i+1] = "" + END IF + IF isalpha(Stk[i][0]) THEN + CONCAT(Stk$[i]," ") + END IF + NEXT + szTmp$ = "" + Test = FALSE + IF DataType(CaseVar$) = vt_STRVAR THEN Test = TRUE + i = 0 + FOR A = 2 TO Ndx + IF INCHR("([",Stk$[A]) THEN i++ + IF INCHR(")]",Stk$[A]) THEN i-- + IF i THEN + CONCAT(szTmp$, Stk$[A]) + ITERATE + END IF + IF Stk$[A] = "," THEN ' comma + IF NOT INCHR("<>=",Stk$[A+1]) THEN + szTmp$ = szTmp$ + " or " + CaseVar$ + "=" + ELSE + szTmp$ = szTmp$ + " or " + CaseVar$ + END IF + Stk$[A] = "" + ITERATE + END IF + IF Stk$[A] = "&&" THEN + szTmp$ = szTmp$ + " and " + CaseVar$ + Stk$[A]= "" + ELSEIF Stk$[A] = "||" THEN + szTmp$ = szTmp$ + " or " + CaseVar$ + Stk$[A]= "" + ELSE + CONCAT(szTmp$, Stk$[A]) + END IF + NEXT + IF CaseFlag = 0 THEN NoBreak = 0 + IF CaseFlag THEN + IF NoBreak = 0 THEN + IF NoBreak2 = 0 THEN FPRINT Outfile,Scoot$;"break;" + END IF + CALL BumpDown() + FPRINT Outfile,Scoot$;"}" + CALL BumpDown() + END IF + CaseFlag = TRUE + IF iMatchLft(CaseVar$," BAND ") THEN + NoBreak = 1 + Src$ = "IF " + szTmp$ + CaseVar$ + " Then " + ELSE + IF INCHR("<>=",szTmp$) AND NOT IsQuoted(szTmp$) THEN + Src$ = "IF " + CaseVar$ + szTmp$ + " Then " + ELSE + Src$ = "IF " + CaseVar$ + " = " + szTmp$ + " Then " + END IF + END IF + CALL Parse(Src$) + CALL Emit() + '*********************** + CASE "delay" + '*********************** + lszTmp$ = "" + FOR i = 2 TO Ndx ' Allow size to be an expression + CONCAT(lszTmp$, Clean$(Stk$[i])) + NEXT + FPRINT Outfile,Scoot$,"sleep(";lszTmp$;");" + '*********************** + CASE "qsortidx" + '*********************** + lszTmp$ = "" + Var$ = Clean$(Stk$[2]) 'index array + FOR i = 4 TO Ndx-4 'allow size to be an expression + CONCAT(lszTmp$, Stk$[i]) + NEXT + lszTmp$ = Clean$(lszTmp$) + FPRINT Outfile,Scoot$,"Key = ",Stk[Ndx],";" + IF Var$ <> "0" THEN + FPRINT Outfile,Scoot$,"int iDx;" + FPRINT Outfile,Scoot$,"for(iDx=0; iDx<",lszTmp$,"; iDx+=1) "; + FPRINT Outfile, Var$,"[iDx]=iDx;" + END IF + IF NOT INCHR(Stk$[Ndx-2],".") THEN 'Check if this is a struct sort + Use_Idxqsort = TRUE + FPRINT Outfile,Scoot$,"pppStr = ",Clean$(Stk[Ndx-2]),";" + FPRINT Outfile,Scoot$,"qsort(";Var$;",";lszTmp$;",sizeof(int),IdxCompare);" + ELSE + DIM RAW Stptr$, StMem$, StName$ + StMem$ = REMAIN$(Clean$(Stk$[Ndx-2]),".") + Stptr$ = EXTRACT$(Stk$[Ndx-2],".") + IF CheckLocal(Stptr,&i) <> vt_UNKNOWN THEN + StName$ = TypeDefs[LocalVars[i].VarDef].VarName$ + ELSEIF CheckGlobal(Stptr,&i) <> vt_UNKNOWN THEN + StName$ = TypeDefs[GlobalVars[i].VarDef].VarName$ + END IF + IF Var$ <> "0" THEN + Use_IdxqsortSt = TRUE + FPRINT Outfile,Scoot$,"cmp1 =(char*)(",Stptr$ ,") + offsetof(",StName$,",",StMem$,");" + FPRINT Outfile,Scoot$,"StructSize = sizeof(",StName$,");" + FPRINT Outfile,Scoot$,"qsort(",Var$;",",lszTmp$,",sizeof(int),IdxCompareSt);" + ELSE + Use_PtrqsortSt = TRUE + FPRINT Outfile,Scoot$,"OffSet = offsetof(",StName$,",",StMem$,");" + FPRINT Outfile,Scoot$,"qsort(",Stptr$;",",lszTmp$,",sizeof(",StName$,"),PtrCompareSt);" + END IF + END IF + '*********************** + CASE "qsort" + '*********************** + DIM RAW QST=0 + DIM RAW order=0 + IF iMatchWrd(Stk$[2],"dynamic") THEN + QST = TRUE + FOR j = 3 TO Ndx + Stk$ [j-1] = Stk$[j] + NEXT + Ndx-- + END IF + IF LCASE$(Stk$[Ndx])= "ascending" THEN + order = 2 + Ndx-- + Ndx-- + END IF + IF LCASE$(Stk$[Ndx])= "descending" THEN + order = 1 + Ndx-- + Ndx-- + END IF + IF order = 0 THEN order = 2 'default to ascending + lszTmp$ = "" + FOR i = 4 TO Ndx 'allow size to be an expression + CONCAT(lszTmp$, Stk$[i]) + NEXT + Var$ = Clean$(Stk$[2]) + vt = DataType(Stk$[2]) + IF vt <> vt_STRVAR AND vt <> vt_INTEGER AND vt <> vt_SINGLE AND vt <> vt_DOUBLE THEN + vt = CheckType(Stk$[2]) + END IF + FPRINT Outfile,Scoot$,"qsort(";Var$;",";Clean$(lszTmp$); + SELECT CASE vt + CASE vt_STRVAR + IF NOT QST THEN + IF order = 1 THEN + FPRINT Outfile,",sizeof(";Var$;"[0]),StrCompareD);" + Use_Strqsortd = TRUE + ELSE + FPRINT Outfile,",sizeof(";Var$;"[0]),StrCompareA);" + Use_Strqsorta = TRUE + END IF + ELSE + IF order = 1 THEN + FPRINT Outfile,",sizeof(";Var$;"[0]),DynStrCompareD);" + Use_DynStrqsortd = TRUE + ELSE + FPRINT Outfile,",sizeof(";Var$;"[0]),DynStrCompareA);" + Use_DynStrqsorta = TRUE + END IF + END IF + CASE vt_INTEGER + IF order = 1 THEN + FPRINT Outfile,",sizeof(int),NumCompareDint);" + Use_Numqsortdint = TRUE + ELSE + FPRINT Outfile,",sizeof(int),NumCompareAint);" + Use_Numqsortaint = TRUE + END IF + CASE vt_SINGLE + IF order = 1 THEN + FPRINT Outfile,",sizeof(float),NumCompareDfloat);" + Use_Numqsortdfloat = TRUE + ELSE + FPRINT Outfile,",sizeof(float),NumCompareAfloat);" + Use_Numqsortafloat = TRUE + END IF + CASE vt_DOUBLE + IF order = 1 THEN + FPRINT Outfile,",sizeof(double),NumCompareDdouble);" + Use_Numqsortddouble = TRUE + ELSE + FPRINT Outfile,",sizeof(double),NumCompareAdouble);" + Use_Numqsortadouble = TRUE + END IF + CASE ELSE + IF order = 1 THEN + FPRINT Outfile,",sizeof(int),NumCompareDint);" + Use_Numqsortdint = TRUE + ELSE + FPRINT Outfile,",sizeof(int),NumCompareAint);" + Use_Numqsortaint = TRUE + END IF + END SELECT + '*********************** + CASE "endprogram" + '*********************** + FPRINT Outfile," return 0; // End of main program" + FPRINT Outfile,"}\n\n" + EndOfProgram = 1 + '****************************** + ' Allow Conditional Compilation + '****************************** + '*********************** + CASE "~ifndef" + '*********************** + InIfDef$ = "#ifndef " + FOR i = 2 TO Ndx + InIfDef$ = InIfDef$ + Stk$[i] + " " + NEXT + InIfDef$ = TRIM$(InIfDef$) + IF InFunc OR InMain THEN + FPRINT Outfile,InIfDef$ + ELSE + FPRINT FP6,InIfDef$ + END IF + '*********************** + CASE "~if" + '*********************** + InIfDef$ = "#if defined " + FOR i = 2 TO Ndx + InIfDef$ = InIfDef$ + Stk$[i] + " " + NEXT + InIfDef$ = TRIM$(InIfDef$) + ConstLastDef$ = InIfDef$ + IF InFunc THEN + IF Outfile = FP3 THEN FPRINT Outfile,"// FP3" + IF Outfile = FP2 THEN FPRINT Outfile,"// FP2" + FPRINT Outfile,InIfDef$,"// OUTFILE" + InIfDef$ = "FP3" + ELSEIF InMain THEN + FPRINT Outfile, InIfDef$, "// --FP2--" + END IF + '*********************** + CASE "~else" + '*********************** + InIfDef$ = "#else" + ConstLastDef$ = InIfDef$ + IF InFunc OR InMain THEN + FPRINT Outfile,InIfDef$ + ELSE + FPRINT FP6,InIfDef$ + END IF + '*********************** + CASE "~elseif" + '*********************** + InIfDef$ = "#elif defined " + FOR i = 2 TO Ndx + InIfDef$ = InIfDef$ + Stk$[i] + " " + NEXT + InIfDef$ = TRIM$(InIfDef$) + ConstLastDef$ = InIfDef$ + IF InFunc OR InMain THEN + FPRINT Outfile, InIfDef$ + ELSE + FPRINT FP6, InIfDef$ + END IF + '*********************** + CASE "~endif" + '*********************** + IF InIfDef$ = "FP3" THEN + FPRINT FP3, "#endif // FP3" + ELSE 'elseif InMain THEN + FPRINT Outfile, "#endif // Main" + END IF + IF ConstLastDef$ = "FP6" THEN + FPRINT FP6, "#endif // FP6" + END IF + InIfDef$ = "#endif // other" + IF InConditional = 0 THEN + InIfDef$ = "" + ConstLastDef$ = "" + 'DidConsts = 0 + END IF + '*********************** + CASE "incr" + '*********************** + j=FALSE + FPRINT Outfile,Scoot$; + FOR i=2 TO Ndx + IF Stk$[i]="," THEN + FPRINT Outfile,"+=("; + j=TRUE + ELSE + FPRINT Outfile,Clean$(Stk$[i]); + END IF + NEXT + FPRINT Outfile,IIF$(j,");","++;") + '*********************** + CASE "decr" + '*********************** + j=FALSE + FPRINT Outfile,Scoot$; + FOR i=2 TO Ndx + IF Stk$[i]="," THEN + FPRINT Outfile,"-=("; + j=TRUE + ELSE + FPRINT Outfile,Clean$(Stk$[i]); + END IF + NEXT + FPRINT Outfile,IIF$(j,");","--;") + '*********************** + CASE "seek" + '*********************** + IF DataType(Stk$[2])= vt_NUMBER THEN + Stk$[2]= "FP" + Stk$[2] + END IF + IF CheckLocal(Stk$[2], &i) = vt_UNKNOWN THEN + CALL AddGlobal(Stk$[2], vt_FILEPTR, 0,"",0,0,0,0) + END IF + FPRINT Outfile,Scoot$,"fseek("; + FOR Tmp = 2 TO Ndx + FPRINT Outfile,Clean$(Stk$[Tmp]); + NEXT + FPRINT Outfile,",0);" + '*********************** + CASE "select" + '*********************** + CaseVar$ = "" + CaseFlag = 0 + FOR A = 3 TO Ndx + CONCAT(CaseVar$, Stk$[A]) + NEXT + CALL Push(CaseVar$) + FPRINT Outfile,Scoot$,"for(;;)" + FPRINT Outfile,Scoot$,"{" + CALL BumpUp + '*********************** + CASE "~get" + '*********************** + Use_Get = TRUE + IF DataType(Stk$[2])= vt_NUMBER THEN + Stk$[2]= "FP" + Stk$[2] + END IF + IF CheckLocal(Stk$[2], &i) = vt_UNKNOWN THEN + IF CheckGlobal(Stk$[2], &i) = vt_UNKNOWN THEN + CALL AddGlobal(Stk$[2], vt_FILEPTR, 0,"",0,0,0,0) + END IF + END IF + FPRINT Outfile,Scoot$,"GET("; + FOR Tmp = 2 TO Ndx + FPRINT Outfile,Clean$(Stk$[Tmp]); + NEXT + FPRINT Outfile,");" + '*********************** + CASE "~put" + '*********************** + Use_Put = TRUE + IF DataType(Stk$[2]) = vt_NUMBER THEN + Stk$[2]= "FP" + Stk$[2] + END IF + IF CheckLocal(Stk$[2], &i) = vt_UNKNOWN THEN + IF CheckGlobal(Stk$[2], &i) = vt_UNKNOWN THEN + CALL AddGlobal(Stk$[2], vt_FILEPTR, 0,"",0,0,0,0) + END IF + END IF + FPRINT Outfile,Scoot$,"PUT("; + FOR Tmp = 2 TO Ndx + FPRINT Outfile,Clean$(Stk$[Tmp]); + NEXT + FPRINT Outfile,");" + '*********************** + CASE "gosub" + '*********************** + Use_Gosub = TRUE + FPRINT Outfile,Scoot$,"if (setjmp(GosubStack[GosubNdx++])==0)"; + FPRINT Outfile," goto ";UCASE$(Stk$[2]);";" + '*********************** + CASE "return" + '*********************** + Use_Gosub = TRUE + FPRINT Outfile,Scoot$,"longjmp (GosubStack [--GosubNdx],1 );" + FPRINT Outfile,"" + '*********************** + CASE "data" + '*********************** + IF Stk$[Ndx] <> "," THEN + Stk$[Ndx+1] = "," + Ndx++ + END IF + FOR A = 2 TO Ndx + IF INCHR(Stk$[A],DQ$) = 0 AND Stk$[A] <> "," THEN + Stk$[A] = ENC$(Stk$[A]) ' Allow unquoted text + END IF + FPRINT FP5,Stk$[A]; + NEXT + FPRINT FP5,"" + + CASE "namespace" + UseCpp = TRUE + szTmp$ = MID$(Src$,INCHR(Src$," ")+1) + FPRINT Outfile,"namespace " + LTRIM$(szTmp$) + FPRINT Outfile,"{" + '/** 2010/11/30 Added -AIR **/ + InNameSpace++ + CALL BumpUp + + CASE "endnamespace" + InNameSpace-- + CALL BumpDown + FPRINT Outfile,Scoot$,"}" + + '/****** ADDED 2010-11-14 AIR *****/ + '*********************** + CASE "class" + '*********************** + IF InTypeDef = 0 THEN + SaveOutfileNum = Outfile + END IF + Outfile = FP4 + InTypeDef++ + TypeName$[InTypeDef] = Stk$[2] + + IF Stk$[3] = "inherits" THEN Stk$[3] = ": public " + Stk$[4] + CALL AddTypeDefs(TypeName$[InTypeDef],vt_STRUCT) + BaseTypeDefsCnt[InTypeDef] = TypeDefsCnt + IF InTypeDef = 1 THEN + FPRINT Outfile,"" + FPRINT Outfile,"class ";TypeName$[InTypeDef];Stk$[3];" {" + CALL BumpUp + END IF + + '/****** ADDED 2010-11-14 AIR *****/ + '*********************** + CASE "endclass" + '*********************** + CALL BumpDown + FPRINT Outfile,"};";LF$ + InTypeDef-- + + '*********************** + CASE "type" + '*********************** + IF InTypeDef = 0 THEN + SaveOutfileNum = Outfile + END IF + Outfile = FP4 + IF Ndx > 2 THEN + IF InTypeDef THEN + CALL Abort("Single line TYPE within type/union not supported") + END IF + FOR i = Ndx TO 1 STEP -1 + IF iMatchWrd(Stk$[i],"as") THEN + EXIT FOR + END IF + NEXT + IF NOT iMatchWrd(Stk$[i],"as") THEN + CALL Abort("Missing AS TYPE") + END IF + FPRINT Outfile,"typedef "; + j = i-1 + i++ + WHILE i <= Ndx + FPRINT Outfile,Stk$[i];" "; + i++ + WEND + FOR i = 2 TO j + FPRINT Outfile,Stk$[i]; + NEXT + FPRINT Outfile,";" + Outfile = SaveOutfileNum + ELSE + InTypeDef++ + TypeName$[InTypeDef] = Stk$[2] + CALL AddTypeDefs(TypeName$[InTypeDef],vt_STRUCT) + BaseTypeDefsCnt[InTypeDef] = TypeDefsCnt + IF InTypeDef = 1 THEN + FPRINT Outfile,"" + FPRINT Outfile,"typedef struct _";TypeName$[InTypeDef] + FPRINT Outfile,"{" + CALL BumpUp + ELSE + FPRINT Outfile,Scoot$;"struct" + FPRINT Outfile,Scoot$;"{" + CALL AddTypedefElement(BaseTypeDefsCnt[InTypeDef-1],vt_STRUCT,TypeName$[InTypeDef],TypeName$[InTypeDef], 0) + CALL BumpUp + END IF + END IF + '*********************** + CASE "endtype" + '*********************** + IF InTypeDef = 1 THEN + CALL BumpDown + FPRINT Outfile,"}";TypeName$[InTypeDef];", *";"LP";UCASE$(TypeName$[InTypeDef]); ";" + FPRINT Outfile,"" + Outfile = SaveOutfileNum + FPRINT FP6,Scoot$;"#define ",UCASE$(TypeName$[InTypeDef]),"_CLASS struct _",UCASE$(TypeName$[InTypeDef]),"*" + ELSE + CALL BumpDown + FPRINT Outfile,Scoot$;"} ";TypeName$[InTypeDef];";" + FPRINT Outfile,"" + END IF + InTypeDef-- + '*********************** + CASE "union" + '*********************** + IF InTypeDef = 0 THEN + SaveOutfileNum = Outfile + END IF + Outfile = FP4 + InTypeDef++ + TypeName$[InTypeDef] = Stk$[2] + CALL AddTypeDefs(TypeName$[InTypeDef],vt_UNION) + BaseTypeDefsCnt[InTypeDef] = TypeDefsCnt + IF InTypeDef = 1 THEN + FPRINT Outfile,"" + FPRINT Outfile,"typedef union " + FPRINT Outfile,"{" + CALL BumpUp + ELSE + FPRINT Outfile,Scoot$;"union" + FPRINT Outfile,Scoot$;"{" + CALL AddTypedefElement(BaseTypeDefsCnt[InTypeDef-1],vt_UNION,TypeName$[InTypeDef],TypeName$[InTypeDef], 0) + CALL BumpUp + END IF + '*********************** + CASE "endunion" + '*********************** + IF InTypeDef = 1 THEN + CALL BumpDown + FPRINT Outfile,"} ";TypeName$[InTypeDef];", *";"LP";UCASE$(TypeName$[InTypeDef]); ";" + FPRINT Outfile,"" + Outfile = SaveOutfileNum + ELSE + CALL BumpDown + FPRINT Outfile,Scoot$;"} ";TypeName$[InTypeDef];";" + FPRINT Outfile,"" + END IF + InTypeDef-- + '*********************** + CASE "with" + '*********************** + GLOBAL WithVar$[8] + GLOBAL WithCnt + WithCnt++ + IF WithCnt = 8 THEN Abort("[With] depth exceeded") + WithVar$[WithCnt] = "" + FOR i = 2 TO Ndx + CONCAT(WithVar$[WithCnt],Stk$[i]) + NEXT + '*********************** + CASE "endwith" + '*********************** + WithCnt-- + '*********************** + CASE "clear" + '*********************** + Use_Clear = TRUE + FPRINT Outfile, Scoot$, "Clear "; + IF Stk$[2]<> "(" THEN FPRINT Outfile,"("; + FOR i = 2 TO Ndx + FPRINT Outfile,Clean$(Stk$[i]); + NEXT + IF Stk$[2]<> "(" THEN FPRINT Outfile,")"; + FPRINT Outfile,";" + '*********************** + CASE "repeat" + '*********************** + lszTmp$ = "" + FOR i = 2 TO Ndx + CONCAT(lszTmp$, Stk$[i]) + NEXT + lszTmp$ = Clean$(lszTmp$) + CALL BumpUp + IF INCHR(Stk$[2],"-") THEN + IF LEFT$(lszTmp$,1) = "-" THEN lszTmp$ = MID$(lszTmp$,2) + FPRINT Outfile,Scoot$,"{register int BCX_REPEAT;" + FPRINT Outfile,Scoot$,"for(BCX_REPEAT=";lszTmp$;";BCX_REPEAT>=1;BCX_REPEAT--)" + FPRINT Outfile,Scoot$,"{" + ELSE + FPRINT Outfile,Scoot$,"{register int BCX_REPEAT;" + FPRINT Outfile,Scoot$,"for(BCX_REPEAT=1;BCX_REPEAT<=";lszTmp$;";BCX_REPEAT++)" + FPRINT Outfile,Scoot$,"{" + END IF + CALL BumpUp + '*********************** + CASE "endrepeat" + '*********************** + CALL BumpDown + FPRINT Outfile,Scoot$,"}" + FPRINT Outfile,Scoot$,"}" + CALL BumpDown + CASE "const" + '*********************** + DIM RAW Buffer$ + DIM RAW Sep$ + Buffer$ = "" + Sep$ = "" + Stk$[1] = "" + FOR i = 2 TO Ndx + IF Stk$[i] = "=" THEN + INCR i + EXIT FOR + ELSE + CONCAT(Stk$[1], Stk$[i]) + END IF + NEXT + Stk$[1] = "#define " + Clean$(Stk$[1]) + SPC$ + FOR i = i TO Ndx + IF isalpha(Stk[i][0]) OR (Stk[i][0] = ASC("_") AND _ + isalpha(Stk[i+1][0])) OR Stk[i+1][0] = ASC("_") THEN Sep$ = " " ELSE Sep$ = "" + IF NOT IsQuoted(Stk$[i]) THEN REMOVE "$" FROM Stk$[i] + Buffer$ = Buffer$ + Stk$[i] + Sep$ + NEXT + Buffer$ = Stk$[1] + Buffer$ + IF InConditional THEN + IF InFunc THEN + FPRINT Outfile,Buffer$ + ELSE + IF ConstLastDef$ <> "FP6" THEN + FPRINT FP6,InIfDef$,"// FP6" + ConstLastDef$ = "FP6" + END IF + FPRINT FP6,Buffer$ + END IF + ELSE + FPRINT FP6,Buffer$ + END IF + '*********************** + CASE "kill" + '*********************** + FPRINT Outfile,Scoot$,"remove ("; + FOR A = 2 TO Ndx + FPRINT Outfile,Clean$(TRIM$(Stk$[A])); + NEXT + FPRINT Outfile,");" + '*********************** + CASE "chdir", "_chdir", "rmdir", "_rmdir", "mkdir", "_mkdir" + '*********************** + FPRINT Outfile,Scoot$,Lookup$;" ("; + FOR A = 2 TO Ndx + FPRINT Outfile,Clean$(TRIM$(Stk$[A])); + NEXT + FPRINT Outfile,");" + '*********************** + CASE "free" + '*********************** + DIM RAW VI AS VarInfo PTR + A = 2 + IF iMatchWrd(Stk$[2], "dynamic") THEN A = 3 + IF Stk$[A] = "(" THEN + INCR A + DECR Ndx + END IF + CVar$ = Clean$(Stk$[A]) + vt = CheckLocal(CVar$, &id) + IF vt = vt_UNKNOWN THEN + vt = CheckGlobal(CVar$, &id) + IF vt = vt_UNKNOWN THEN + Abort("Can not REDIM " + CVar$ + " not previously dimensioned") + END IF + VI = &GlobalVars[id] + ELSE + VI = &LocalVars[id] + Warning("Local dynamic variables are automatically freed.", 1) + END IF + CVar$ = "" + FOR i = A TO Ndx + CVar$ = CVar$ + Stk$[i] + NEXT + CVar$ = Clean$(CVar$) + IF vt = vt_STRUCT OR vt = vt_UNION THEN + GetElement$(2, &vt, &dms, VI->VarDef) + IF vt <> vt_UNKNOWN AND dms > 0 THEN + Use_DynamicA = TRUE + FPRINT Outfile,Scoot$,"if (", CVar$; + FPRINT Outfile,") { DestroyArr((void **)", CVar$, ",", dms, ", 1); "; + FPRINT Outfile,CVar$ ; "=NULL; }" + EXIT SELECT + END IF + END IF + IF VI->VarPntr > 1 THEN + Use_DynamicA = TRUE + FPRINT Outfile,Scoot$,"if (" ; CVar$ ; + FPRINT Outfile,") { DestroyArr((void **)" + CVar$ + "," + STR$(VI->VarPntr) + ", 1); "; + FPRINT Outfile,CVar$ ; "=NULL; }" + ELSE + FPRINT Outfile,Scoot$,"free(", CVar$, "), ", CVar$, "=NULL;" + END IF + '************************************************************************* + CASE "midstr" + '************************************************************************* + Src$ = "" + FOR A = 1 TO Ndx + CONCAT(Src$,Clean$(Stk$[A])) + NEXT + FPRINT Outfile,Scoot$, TRIM$(Src$), ";" + '*********************** + CASE "swap" + '*********************** + RAW VI1 AS VarInfo PTR + RAW VI2 AS VarInfo PTR + RAW indx AS INTEGER + FPRINT Outfile,Scoot$,"swap ((BYTE*)&"; + FOR i = 2 TO Ndx + IF Stk$[i]= "," THEN EXIT FOR + FPRINT Outfile,Clean$(Stk$[i]); + NEXT + A = CheckLocal(Stk$[2], &indx) + IF A = vt_UNKNOWN THEN + A = CheckGlobal(Stk$[2], &indx) + IF A = vt_UNKNOWN THEN + Abort("Variable '"+Stk$[2]+"' in swap statement unknown") + END IF + VI1 = &GlobalVars[indx] + ELSE + VI1 = &LocalVars[indx] + END IF + IF RIGHT$(Stk$[i-1],1) <> "]" THEN + IF VI1->VarType = vt_CHAR AND VI1->VarPntr = 1 THEN FPRINT Outfile,"[0]"; + END IF + FPRINT Outfile,",(BYTE*)&"; + i++ + FOR j = i TO Ndx + FPRINT Outfile,Clean$(Stk$[j]); + NEXT + A = CheckLocal(Stk$[i], &indx) + IF A = vt_UNKNOWN THEN + A = CheckGlobal(Stk$[i], &indx) + IF A = vt_UNKNOWN THEN + Abort("Variable '"+Stk$[i]+"' in swap statement unknown") + END IF + VI2 = &GlobalVars[indx] + ELSE + VI2 = &LocalVars[indx] + END IF + IF RIGHT$(Stk$[j-1],1) <> "]" THEN + IF VI2->VarType = vt_CHAR AND VI2->VarPntr = 1 THEN FPRINT Outfile,"[0]"; + END IF + IF VI1->VarType <> VI2->VarType THEN + Warning("Possible size error in swap statement") + END IF + IF VI2->VarType = vt_STRVAR OR VI2->VarType = vt_CHAR THEN + FPRINT Outfile,",strlen("; + ELSE + FPRINT Outfile,",sizeof("; + END IF + FOR j = i TO Ndx + FPRINT Outfile,Clean$(Stk$[j]); + NEXT + FPRINT Outfile,"));" + '*********************** + CASE "rename" + '*********************** + FPRINT Outfile,Scoot$,"rename ("; + FOR A = 2 TO Ndx + FPRINT Outfile,Clean$(TRIM$(Stk$[A])); + NEXT + FPRINT Outfile,");" + '*********************** + CASE "copyfile" + '*********************** + FPRINT Outfile,Scoot$,"CopyFile "; + IF Stk$[2] <> "(" THEN FPRINT Outfile, "("; + FOR A = 2 TO Ndx + FPRINT Outfile,Clean$(TRIM$(Stk$[A])); + NEXT + IF Stk$[Ndx] <> ")" THEN + FPRINT Outfile, ");" + ELSE + FPRINT Outfile, ";" + END IF + '*********************** + CASE "shell" + '*********************** + IF Ndx > 2 THEN + FOR A = 3 TO Ndx + Stk$[2] = Stk$[2] + Stk$[A] + NEXT + END IF + ZZ$ = Stk$[2] + IF ZZ$ = "" THEN ZZ$ = DDQ$ + FPRINT Outfile,Scoot$ ; "Shell(" ; Clean$(ZZ$) ; ");" + + + '***************************************************************************** + CASE "lineinput" + ' LINEINPUT "prompt", A$ <<< Keyboard version 4.21 + '***************************************************************************** + ' Test for new keyboard version of LINE INPUT + i = DataType(Stk$[2]) + IF i = vt_STRLIT OR i = vt_STRVAR THEN + IF i <> vt_STRLIT THEN Stk$[2] = Clean$(Stk$[2]) + FPRINT Outfile,Scoot$,"printf(", ENC$("%s"), ",", Stk$[2], ");" + FPRINT Outfile,Scoot$,"AR_fgets_retval=fgets(", Clean$(Stk$[3]), ",2048-1,stdin);" + FPRINT Outfile,Scoot$,Clean$(Stk$[3]),"[strlen(",Clean$(Stk$[3]),")-1]=0;" + EXIT SELECT + END IF + ' ********************* Okay, we're dealing with a file ************************ + REMOVE "#" FROM Stk$[2] + IF DataType(Stk$[2]) = vt_NUMBER THEN + Stk$[2]= "FP" & Stk$[2] + END IF + Handl$ = EXTRACT$(Stk$[2], "[") + IF CheckLocal(Handl$, &i) = vt_UNKNOWN THEN + IF CheckGlobal(Handl$, &i) = vt_UNKNOWN THEN + CALL AddGlobal(Handl$, vt_FILEPTR, 0,"",0,0,0,0) + END IF + END IF + Var$ = Clean$(Stk$[3]) + Var1$ = "" + CVar$ = Var$ + IF INCHR( Var$, "[" ) AND INCHR( Var$, "]" ) THEN + IF INSTR( Var$, "[++" ) THEN + REPLACE "++" WITH "" IN CVar$ + END IF + IF INSTR( Var$, "[--" ) THEN + REPLACE "--" WITH "" IN CVar$ + END IF + IF INSTR( Var$, "++]" ) THEN + REPLACE "++" WITH "" IN CVar$ + Var1$ = MID$(Var$,INCHR(Var$,"[")+1) + Var1$ = EXTRACT$(Var1$,"]") + Var$ = CVar$ + END IF + IF INSTR( Var$, "--]" ) THEN + REPLACE "--" WITH "" IN CVar$ + Var1$ = MID$(Var$,INCHR(Var$,"[")+1) + Var1$ = EXTRACT$(Var1$,"]") + Var$ = CVar$ + END IF + END IF + FPRINT Outfile,Scoot$, Var$ ; "[0]=0;" + FPRINT Outfile,Scoot$, "AR_fgets_retval=fgets(" ; Var$ ; ",1048576,"; Clean$(Stk$[2]) ; ");" + FPRINT Outfile,Scoot$, "if(" ; CVar$ ; "[strlen(" ;CVar$ ; ")-1]==10)"; + FPRINT Outfile,CVar$ ; "[strlen(" ; CVar$ ; ")-1]=0;" + IF Var1$ <> "" THEN + FPRINT Outfile,Var1$ ; ";" + END IF + '************************************************************************* + CASE "open" + '************************************************************************* + FOR A = 1 TO Ndx + Keyword$ = LCASE$(Stk$[A]) + SELECT CASE Keyword$ + CASE "open" + Stk$[A] = "" + CASE "for" + Stk$[A] = "" + Filnam$ = "" + FOR j = 2 TO A-1 + CONCAT (Filnam$,Stk$[j]) + NEXT + Filnam$ = Clean$(Filnam$) + CASE "as" + Stk$[A] = "" + IF DataType(Stk$[A + 1]) = vt_NUMBER THEN + Stk$[A + 1] = "FP" + Stk$[A + 1] + END IF + IF CheckLocal(Stk$[A + 1], &i) = vt_UNKNOWN THEN + IF CheckGlobal(Stk$[A + 1], &i) = vt_UNKNOWN THEN + CALL AddGlobal(Stk$[A + 1], vt_FILEPTR, 0,"",0,0,0,0) + END IF + END IF + Var$ = "" + FOR j = A+1 TO Ndx + IF iMatchWrd(Stk$[j], "reclen") THEN EXIT FOR + CONCAT (Var$,Stk$[j]) + Stk$[j] = "" + NEXT + Handl$ = Var$ + "@" + CASE "network" + Use_Socket = TRUE + CASE "input" + Op$ = ENC$("r") + Stk$[A] = "" + CASE "output" + Op$ = ENC$("w") + Stk$[A] = "" + CASE "append" + Op$ = ENC$("a") + Stk$[A] = "" + CASE "binary" + Op$ = ENC$("rb+") + Stk$[A] = "" + CASE "binaryappend" + Op$ = ENC$("ab+") + Stk$[A] = "" + CASE "binarynew" + Op$ = ENC$("wb+") + Stk$[A] = "" + CASE "binaryinput" + Op$ = ENC$("rb") + Stk$[A] = "" + CASE "binaryoutput" + Op$ = ENC$("rb+") + Stk$[A] = "" + CASE "reclen" + IF Stk$[A+1] = "=" THEN + FOR j = A+2 TO Ndx + Stk$[j-1] = Stk$[j] + NEXT + Ndx-- + END IF + Var$ = EXTRACT$(Clean$(Handl$), "[") + "len" + IF CheckLocal(Var$, &i) = vt_UNKNOWN THEN + CALL AddGlobal(Var$, vt_INTEGER , 0,"",0,0,0,0) + ELSE + IF CheckLocal(Var$, &i) = vt_UNKNOWN THEN + CALL AddLocal(Var$, vt_INTEGER , 0,"",0,0,0) + Var$ = "int " + Var$ + END IF + END IF + i = CheckType(Stk$[A+1]) + ZZ$ = LCASE$(Stk$[A+1]) + IF i = vt_STRUCT OR i = vt_UNION OR ZZ$ = "int" OR ZZ$ = "double" OR ZZ$ = "float" THEN + FPRINT Outfile,Scoot$,Var$ + " = sizeof(";Stk$[A+1];");" + ELSE + FPRINT Outfile,Scoot$,Var$ + " = ";Clean$(Stk$[A+1]);";" + END IF + Stk$[A] = "" + Stk$[A + 1] = "" + END SELECT + NEXT + FPRINT Outfile,Scoot$,"if((";Clean$(Handl$);"=fopen(";Filnam$;",";Op$;"))==0)" + FPRINT Outfile,Scoot$," {" + lszTmp$ = ENC$("Can't open file %s\\n") + FPRINT Outfile,Scoot$," fprintf(stderr,";lszTmp$;",";Filnam$;");" + FPRINT Outfile,Scoot$," exit(1);" + FPRINT Outfile,Scoot$," }" + + '************************************************************************* + ' Statement RECORD [#] filenumber,recordnumber [,location in record] + ' Definition: Position the file pointer anywhere in a file. + ' filenumber Filenumber from 1 to 99 + ' record number RECORD number to point to. Default first record + ' location in record Optional location in RECORD. Default is Zero + ' RECORD fp1, 6[, 10] + '************************************************************************* + CASE "record" + DIM ffp AS functionParse + DIM RAW numargs = 0 + IF DataType(Stk$[2]) = vt_NUMBER THEN + Stk$[2]= "FP" + Stk$[2] + END IF + IF Ndx > 1 THEN numargs = SepFuncArgs(1, &ffp, FALSE) + IF numargs < 1 THEN Abort("Missing required arguments to RECORD") + IF numargs > 4 THEN Abort("Too many arguments to RECORD") + IF numargs = 3 THEN + FPRINT Outfile,Scoot$,"fseek("; GetArg$(1, &ffp); _ + ", ("; GetArg$(2, &ffp); " - 1) * ";Stk$[2];"len + ";GetArg$(3, &ffp);", SEEK_SET);" + ELSEIF numargs = 2 THEN + FPRINT Outfile,Scoot$,"fseek("; GetArg$(1, &ffp); _ + ", ("; GetArg$(2, &ffp); " - 1) * ";Stk$[2];"len, SEEK_SET);" + ELSE + FPRINT Outfile,Scoot$,"fseek("; GetArg$(1, &ffp); ", 0, SEEK_SET);" + END IF + '*********************** + CASE "fwrite" + '*********************** + IF DataType(Stk$[2]) = vt_NUMBER THEN + Stk$[2] = "FP" + Stk$[Ndx] + END IF + IF CheckLocal(Stk$[2], &i) = vt_UNKNOWN THEN + CALL AddGlobal(Stk$[2], vt_FILEPTR, 0,"",0,0,0,0) + END IF + Handl$ = "" + FOR j = 2 TO Ndx + IF iMatchWrd(Stk$[j], ",") OR iMatchWrd(Stk$[j], ";") THEN + Stk$[j] = "" 'get rid of the Comma + EXIT FOR + END IF + Handl$ = Handl$ + Stk$[j] + Stk$[j] = "" 'get rid of handle + NEXT j + Handl$ = Handl$ + "@" + ZZ$ = "f" + PrintWriteFormat$(1) + ZZ$ = LEFT$(ZZ$,8) + Clean$(Handl$) + "," + MID$(ZZ$,9) + FPRINT Outfile,Scoot$, ZZ$ + '*********************** + CASE "close" + '*********************** + IF Ndx = 1 THEN + FPRINT Outfile,Scoot$, "fcloseall();" + EXIT SELECT + END IF + IF DataType(Stk$[2]) = vt_NUMBER THEN + Stk$[2]= "FP" + Stk$[Ndx] + END IF + IF CheckLocal(Stk$[2], &i) = vt_UNKNOWN THEN + IF CheckGlobal(Stk$[2], &i) = vt_UNKNOWN THEN + CALL AddGlobal(Stk$[2], vt_FILEPTR, 0,"",0,0,0,0) + END IF + END IF + Handl$ = "" + FOR j = 2 TO Ndx + Handl$ = Handl$ + Stk$[j] + NEXT j + FPRINT Outfile,Scoot$,"if(",Handl$,")" + FPRINT Outfile,Scoot$," {" + FPRINT Outfile,Scoot$," fclose(";Handl$;");" + FPRINT Outfile,Scoot$," ";Handl$;"=NULL;" + FPRINT Outfile,Scoot$," }" + '*********************** + CASE "call" + '*********************** + lszTmp$ = "" + FOR Tmp = 2 TO Ndx + CONCAT(lszTmp$, Clean$(Stk$[Tmp])) + NEXT + IF NOT iMatchRgt(lszTmp$,")") THEN + CONCAT(lszTmp$, "()") + END IF + CONCAT(lszTmp$, ";") + FPRINT Outfile,Scoot$,lszTmp$ + '************************************************************************* + CASE "declare" + '************************************************************************* + DIM FP AS functionParse + DIM RAW TempProto$ + CALL FuncSubDecs1("sub") 'convert [] to pointer * and $[] to [][2048] + CALL SepFuncArgs(3, &FP, TRUE) + TempProto$ = MakeDecProto$(&FP) + IF NOT NoTypeDeclare THEN + FPRINT FP4, TempProto$, ";" + ELSE + ProtoCnt++ + ProtoType[ProtoCnt].Prototype$ = TempProto$ + ";" + END IF + '************************************************************************* + '/***** 2010-11-16 Added Constructor/Destructor - AIR *****/ + CASE "function", "sub", "constructor", "destructor" + '************************************************************************* + DIM CTOR_USE$, CTOR_SRC$, New_Ndx + IF Stk$[2] = "main" THEN + Stk$[1] = "function" + Stk$[2] = "main%" + ForceMainToFunc = TRUE + END IF + + '/***** 2010-11-17 Added to change constructor/destructor to sub -AIR *****/ + IF iMatchWrd(Stk$[1], "constructor") OR iMatchWrd(Stk$[1], "destructor") THEN + Stk$[1] = "sub" + '/***** 2010-11-18 this extracts the derived class method after "USING" keyword *****/ + '/***** and stuffs it into CTOR_USE$ variable - AIR *****/ + FOR INTEGER ct = 1 TO Ndx + IF Stk$[ct] = "using" THEN + New_Ndx = ct-1 '/*** SEE NEXT COMMENT!!! -AIR *****/ + FOR INTEGER ut = ct TO Ndx + CTOR_USE$ = CTOR_USE$ + Stk$[ut] + NEXT + END IF + NEXT + + + + IF LEN(CTOR_USE$) THEN + IREPLACE "using" WITH ":" IN CTOR_USE$ + '/***** 2010-11-18 Truncates current line so that everything AFTER "USING" keyword is NOT *****/ + '/***** processed by default FUNCTION/SUB parser! -AIR *****/ + Ndx = New_Ndx + '/*********************************************************************************************/ + END IF + Use_Ctor = TRUE + END IF + + CALL FuncSubDecs1("sub") + + IsStdFunc = FALSE + IF iMatchWrd(Stk$[Ndx],"stdcall") THEN + CallType$ = "__attribute__((stdcall)) " + Ndx-- + IsStdFunc = TRUE + END IF + InFunc = TRUE + InMain = FALSE + LocalVarCnt = 0 + '~ Outfile = FP3 + '/** 2010/11/30 Added -AIR **/ + IF InNameSpace THEN + Outfile = FP2 + ELSE + Outfile = FP3 + END IF + + CALL FuncSubDecs2("sub", mt_FuncSubDecC_Dec) + ' to compensate previous substitution errors not fixed + VarCode.Functype$ = LTRIM$(VarCode.Functype$) + + Funcname$ = Clean$(Stk$[2]) + IF IsExported OR IsStdFunc THEN + Funcname$ = CallType$ + Funcname$ + END IF + VarCode.Method% = mt_FuncSubDecC_Dec2 + A = 3 + WHILE A <= Ndx + IF Stk$[A+1] = "(" THEN ' sub/function ptr + FOR k = A+2 TO Ndx + IF Stk$[k] = ")" THEN + EXIT FOR + END IF + NEXT + + IF iMatchWrd(Stk$[k+2], "sub") THEN + j = vt_VOID + VarCode.AsToken$ = "void" + ELSEIF iMatchWrd(Stk$[k+2], "function") THEN + CALL GetTypeInfo(Stk$[k+3], &IsPointer, &i, &j) + VarCode.AsToken$ = Stk$[k+3] + END IF + VarCode.Token$ = Stk$[A] + VarCode.VarNo% = j + VarCode.IsPtrFlag = 1 + VarCode.Method% = mt_FuncSubx1 + CALL GetVarCode(&VarCode) + Var$ = Clean$(Stk$[A]) + + lszTmp$ = "" + A += 2 + WHILE A <= k + IF iMatchWrd(Stk$[A+1], "as") AND A < k THEN + Tmp = A + 2 + WHILE Stk$[Tmp] <> "," AND Stk$[Tmp] <> ")" + CALL GetTypeInfo(Stk$[Tmp], &IsPointer, &i, &j) + CALL AddLocal(Stk$[A], j, i, "", IsPointer,0,0) + VarCode.Token$ = Stk$[A] + VarCode.AsToken$ = Stk$[Tmp] + VarCode.VarNo% = j + VarCode.IsPtrFlag = 1 + VarCode.Method% = mt_FuncSubx2 + CALL GetVarCode(&VarCode) + Tmp++ + IF Stk$[Tmp] = "," THEN + CONCAT(VarCode.Proto$,",") + CONCAT(VarCode.Header$,",") + END IF + WEND + A = Tmp + ELSE + IF Stk$[A] <> "," AND Stk$[A] <> ")" THEN + IsPointer = TALLY((Stk$[A]), "*") + Var$ = REMOVE$(Stk$[A], "*") ' in case we used ptr + j = DataType(Var$) + IF j <> vt_UNKNOWN AND InFunc = TRUE AND Var[0] THEN + CALL AddLocal(Clean(Var$), j, 0, "", IsPointer,0,0) + END IF + VarCode.Token$ = Stk$[A] + VarCode.AsToken$ = "" + VarCode.VarNo% = j + VarCode.IsPtrFlag = IsPointer + VarCode.Method% = mt_FuncSubDecC_Dec2 + CALL GetVarCode(&VarCode) + END IF + END IF + A++ + WEND + A = k+3 + IF VarCode.Method% = mt_FuncSubDecC_Dec2 THEN + MID$(VarCode.Proto$,LEN(VarCode.Proto$)-1,1) = ")" + MID$(VarCode.Header$,LEN(VarCode.Header$)-1,1) = ")" + ELSE + CONCAT(VarCode.Proto$,")") + CONCAT(VarCode.Header$,")") + END IF + VarCode.Method% = mt_FuncSubDecC_Dec2 + ELSE + IF iMatchWrd(Stk$[A+1],"as") THEN + CALL GetTypeInfo(Stk$[A+2], &IsPointer, &i, &j) + Var$ = Clean$(Stk$[A]) + CALL AddLocal(Var$, j, i, "", IsPointer,0,0) + VarCode.Token$ = Stk$[A] + VarCode.AsToken$ = Stk$[A+2] + VarCode.VarNo% = j + VarCode.IsPtrFlag = IsPointer + CALL GetVarCode(&VarCode) + Stk$[A+1] = "" + Stk$[A+2] = "" + A+=2 + ELSE + IF INCHR("=", Stk$[A]) AND Stk$[A] <> "" THEN + CALL Abort("Illegal optional parameter found") + END IF + IF NOT INCHR(",().",Stk$[A]) AND Stk$[A] <> "" THEN + IsPointer = TALLY((Stk$[A]), "*") + Var$ = REMOVE$(Stk$[A], "*") ' in case we used ptr + j = DataType(Var$) + IF j <> vt_UNKNOWN AND Var[0] THEN + CALL AddLocal(Clean(Var$), j, 0, "", IsPointer,0,0) + END IF + VarCode.Token$ = Stk$[A] + VarCode.AsToken$ = "" + VarCode.VarNo% = j + VarCode.IsPtrFlag = IsPointer + CALL GetVarCode(&VarCode) + END IF + END IF + END IF + A++ + WEND + VarCode.Method% = 2 + VarCode.Token$ = Funcname$ + FuncSubDecs3(&VarCode) + IF iMatchLft(VarCode.Header$,"main(") THEN + VarCode.Header$ = "int main(int argc, char *argv[])" + VarCode.Proto$ = "int main(int argc, char *argv[]);" + CurrentFuncType = vt_INTEGER + END IF + IF Use_Static THEN + VarCode.Header$ = "static " + VarCode.Header$ + VarCode.Proto$ = "static " + VarCode.Proto$ + END IF + + '/** 2010/11/30 DON'T EMIT FUNCTION PROTOTYPE FOR NAMESPACE -AIR **/ + IF NOT InNameSpace THEN + ProtoCnt++ + ProtoType[ProtoCnt].Prototype$ = VarCode.Proto$ + END IF + + IF InIfDef$ = "FP3" THEN + IF ProtoCnt > 1 THEN + ProtoType[ProtoCnt].Condition$ = ProtoType[ProtoCnt-1].Condition$ + ELSE + ProtoType[ProtoCnt].Condition$ = "" + END IF + ELSE + ProtoType[ProtoCnt].Condition$ = InIfDef$ + END IF + ProtoType[ProtoCnt].CondLevel = InConditional + + IF *InIfDef$ THEN + IF InIfDef$ <> "FP3" THEN + FPRINT Outfile,InIfDef$ + PRINT InIfDef$ + END IF + END IF + + + + + '/***** 2010-11-17 Check if Constructor/Destructor, if so remove VOID from Method Sig -AIR *****/ + IF Use_Ctor THEN + REPLACE "void " WITH "" IN VarCode.Header$ + REPLACE "void" WITH "" IN VarCode.Header$ + '/***** 2010-11-18 Emit derived class methods via "USING" keyword if required -AIR *****/ + IF LEN (CTOR_USE$) THEN + FPRINT Outfile,VarCode.Header$ + FPRINT Outfile,Scoot$,CTOR_USE$ + ELSE + FPRINT Outfile,VarCode.Header$ + END IF + Use_Ctor = FALSE + '/** 2010/11/30 Added Wayne's fix for NAMESPACE -AIR **/ + ELSEIF InNameSpace THEN + 'FPRINT Outfile,Scoot$;VarCode.Header$ + RAW szCPP_SF1$ + szCPP_SF1$ = "" + IF iMatchLft(Lookup$,"public") THEN szCPP_SF1$ = "public: virtual " + FPRINT Outfile,Scoot$;szCPP_SF1$;VarCode.Header$ + ELSE + FPRINT Outfile,VarCode.Header$ + END IF + FPRINT Outfile,Scoot$,"{" + CALL BumpUp + '*********************************************** + CASE "optfunction", "optsub" + '*********************************************** + CALL FuncSubDecs1("optsub") + InFunc = TRUE + LocalVarCnt = 0 + Outfile = FP3 + + '/** Added -AIR **/ + IF InNameSpace THEN + Outfile = FP2 + ELSE + Outfile = FP3 + END IF + + CALL FuncSubDecs2("optsub", mt_Opts) + Funcname$ = Clean$(Stk$[2]) + VarCode.Method% = mt_Opts2 + A = 4 + WHILE A < Ndx + IF Stk$[A] = "" THEN A++ : ITERATE + IF Stk$[A] = "," THEN + VarCode.Method% = mt_Opts3 + VarCode.Token$ = Stk$[A] + CALL GetVarCode(&VarCode) + VarCode.Method% = mt_Opts2 + ELSEIF Stk$[A] = "=" THEN + VarCode.Method% = mt_Opts3 + IF Stk$[A + 1] = "-" THEN + VarCode.Token$ = Stk$[A] + Stk$[A + 1] + Stk$[A + 2] + Stk$[A + 1] = "" : Stk$[A + 2] = "" : A++ + ELSE + VarCode.Token$ = Stk$[A] + Stk$[A + 1] + Stk$[A + 1] = "" + END IF + IF iMatchWrd(Stk$[A+2],"as") THEN + Stk$[A + 2] = "" : Stk$[A + 3] = "" + END IF + VarCode.VarNo% = j + VarCode.IsPtrFlag = IsPointer + CALL GetVarCode(&VarCode) + VarCode.Method% = mt_Opts2 + ELSEIF iMatchWrd(Stk$[A+1],"as") THEN + CALL GetTypeInfo(Stk$[A+2], &IsPointer, &i, &j) + IF InFunc THEN + Var$ = Clean$(Stk$[A]) + CALL AddLocal(Var$, j, i, "", IsPointer,0,0) + END IF + VarCode.VarNo% = j + VarCode.Token$ = Stk$[A] + VarCode.AsToken$ = Stk$[A+2] + VarCode.IsPtrFlag = IsPointer + CALL GetVarCode(&VarCode) + Stk$[A+1]= "" : Stk$[A+2]= "" + ELSE + IsPointer = TALLY((Stk$[A]),"*") + Var$ = REMOVE$(Stk$[A],"*") ' in case we used ptr + j = DataType(Var$) + IF j <> vt_UNKNOWN THEN + CALL AddLocal(Clean(Var$),j,0,"",IsPointer,0,0) + END IF + VarCode.VarNo% = j + VarCode.Token$ = Stk$[A] + VarCode.AsToken$ = "" + VarCode.IsPtrFlag = IsPointer + CALL GetVarCode(&VarCode) + END IF + A++ + WEND + VarCode.Method% = 2 + VarCode.Token$ = Funcname$ + FuncSubDecs3(&VarCode) + IF Use_Static THEN + VarCode.Header$ = "static " + VarCode.Header$ + VarCode.Proto$ = "static " + VarCode.Proto$ + END IF + ProtoCnt++ + ProtoType[ProtoCnt].Prototype$ = VarCode.Proto$ + IF InIfDef$ = "FP3" THEN + ProtoType[ProtoCnt].Condition$ = "" + ELSE + ProtoType[ProtoCnt].Condition$ = InIfDef$ + END IF + ProtoType[ProtoCnt].CondLevel = InConditional + FPRINT Outfile,VarCode.Header$ + FPRINT Outfile,Scoot$,"{" + CALL BumpUp + '******************************************* + CASE "overloadedfunction", "overloadedsub" + '******************************************* + Use_Overloaded = TRUE + CALL FuncSubDecs1("overloadedsub") + InFunc = TRUE + InMain = FALSE + LocalVarCnt = 0 + Outfile = FP8 '<<----- writing TO BCX.OVR + CALL FuncSubDecs2("overloadedsub", mt_OverLoad) + Funcname$ = Clean$(Stk$[2]) + lszTmp$ = " overloaded " + Funcname$ + Funcname$ = lszTmp$ + VarCode.Method% = mt_OverLoad2 + FOR A = 3 TO Ndx + IF iMatchWrd(Stk$[A+1],"as") THEN + CALL GetTypeInfo(Stk$[A+2], &IsPointer, &i, &j) + Var$ = Clean$(Stk$[A]) + CALL AddLocal(Var$, j, i, "", IsPointer,0,0) + VarCode.AsToken$ = Stk$[A+2] + Stk$[A+1] = "" + Stk$[A+2] = "" + ELSE + Var$ = REMOVE$(Stk$[A],"*") ' in case we used ptr + j = DataType(Var$) + IF NOT INCHR(",().",Stk$[A]) AND Stk$[A] <> "" THEN + IsPointer = TALLY((Stk$[A]),"*") + IF j <> vt_UNKNOWN AND InFunc = TRUE AND Var[0] THEN + CALL AddLocal(Clean(Var$), j, 0, "", IsPointer,0,0) + END IF + END IF + VarCode.AsToken$ = "" + END IF + VarCode.VarNo% = j + VarCode.Token$ = Stk$[A] + CALL GetVarCode(&VarCode) + NEXT + VarCode.Method% = 1 + VarCode.Token$ = Funcname$ + FuncSubDecs3(&VarCode) + IF Use_Static THEN + VarCode.Header$ = "static " + VarCode.Header$ + END IF + FPRINT Outfile,VarCode.Header$ + FPRINT Outfile,Scoot$,"{" + CALL BumpUp + '******************************************************************* + CASE "functionreturn" + '******************************************************************* + IF CaseFlag THEN NoBreak2 = TRUE + lszTmp$ = "" + FOR A = 3 TO Ndx + lszTmp$ = lszTmp$ + Stk$[A] + " " + NEXT + IF CurrentFuncType = vt_STRVAR THEN + lszTmp$ = "BCX_RetStr$ = " + lszTmp$ + FuncRetnFlag = 1 '1 = return a string + UseFlag = TRUE + ELSE + FuncRetnFlag = 2 '2 = return a number + END IF + IF FuncRetnFlag = 2 THEN + '********************************* + ' Clean up dynamic strings + '********************************* + IF LocalDynaCnt <> 0 THEN + FOR j = 1 TO LocalDynaCnt + FPRINT Outfile,Scoot$,DynaStr$[j] + NEXT + END IF + '********************************* + ' Clean up dynamic strings arrays + '********************************* + IF LocalDynArrCount <> 0 THEN + FOR i = 1 TO LocalDynArrCount + FPRINT Outfile,Scoot$,LocalDynArrName$[i] + NEXT + END IF + '********************************* + FPRINT Outfile,Scoot$,"return "; + LastCmd = 2 + END IF + CALL Parse(lszTmp$) + LastCmd = 0 + GOTO EmitAgain + '******************************* + '/***** 2010-11-16 Added endconstructor/enddestructor - AIR *****/ + CASE "endfunction", "endsub", "endconstructor", "enddestructor" + '******************************* + IF iMatchWrd(Stk$[1],"endfunction") THEN + LocalDynaCnt = 0 + LocalDynArrCount = 0 + END IF + '/***** 2010-11-16 Added endconstructor/enddestructor - AIR *****/ + IF iMatchWrd(Stk$[1],"endsub") OR iMatchWrd(Stk$[1],"endconstructor") OR iMatchWrd(Stk$[1],"enddestructor") THEN + '************************** + ' Clean up dynamic strings + '************************** + IF LocalDynaCnt <> 0 THEN + FOR j = 1 TO LocalDynaCnt + FPRINT Outfile,Scoot$,DynaStr$[j] + NEXT + LocalDynaCnt = 0 + END IF + '********************************* + ' Clean up dynamic strings arrays + '********************************* + IF LocalDynArrCount <> 0 THEN + FOR i = 1 TO LocalDynArrCount + FPRINT Outfile,Scoot$,LocalDynArrName$[i] + NEXT + LocalDynArrCount = 0 + END IF + END IF + '********************************* + IF ForceMainToFunc = TRUE THEN + FPRINT Outfile,Scoot$,"return 0;" + ForceMainToFunc = FALSE + END IF + CALL BumpDown + '~ FPRINT Outfile,Scoot$,"}\n\n" + '~ CALL BumpDown + //** 2010/11/30 Added FOR NAMESPACE -AIR **/ + IF InNameSpace THEN + FPRINT FP2,Scoot$,"}\n" + ELSE + FPRINT Outfile,Scoot$,"}\n\n" + CALL BumpDown + END IF + + InFunc = FALSE + Use_Static = FALSE + IF Outfile = FP3 THEN + InIfDef$ = "FP3" + END IF + Outfile = FP2 + ByrefCnt = 0 + '*********************** + CASE "input" + '*********************** + CALL EmitInputCode + '*********************** + CASE "finput" + '*********************** + CALL EmitFileInputCode + '*********************** + CASE "dynamic" + '*********************** + DIM RAW w = 0 + DIM RAW SOF$ + CALL HandleNonsense + CVar$ = Clean$(Stk$[2]) + CALL ValidVar(CVar$) + IF Stk$[Ndx] = "*" THEN CALL PointerFix + IF Stk$[Ndx] = "&" THEN Stk$[Ndx--] = "" : CONCAT(Stk$[Ndx], "&") + ZZ$ = "" + IF iMatchWrd(Stk$[Ndx-1], "as") THEN + SOF$ = Stk$[Ndx] + GetTypeInfo(SOF$, &w, &id, &vt) + IF vt = vt_STRLIT OR vt = vt_DECFUNC OR vt = vt_NUMBER OR _ + (vt = vt_VOID AND INCHR(Stk$[Ndx], "*") = 0) THEN + Abort(SOF$ + " is not a valid type") + END IF + IF vt = vt_FILEPTR AND INCHR(SOF$, "*") = 0 THEN SOF$ = SOF$ + "*" + Ndx -= 2 + ELSE + vt = DataType(Stk$[2]) + id = 0 + SOF$ = GetVarTypeName$(vt) + END IF + Use_DynamicA = TRUE + FOR i = 3 TO Ndx + CONCAT(ZZ$, Stk$[i]) + NEXT + dms = TALLY(ZZ$,"][") + 1 + IF dms > 1 THEN REPLACE "][" WITH "," IN ZZ$ + ZZ$ = Clean$(ZZ$) + RemoveAll(ZZ$,"[]") + IF vt = vt_STRVAR THEN + vt = vt_CHAR + SOF$ = "char" + IF InTypeDef THEN + IF Stk$[3] <> "[" THEN + DECR dms + ELSE + vt = vt_CHARPTR + END IF + END IF + dms++ + CONCAT(ZZ$,",65535") + END IF + IF InTypeDef THEN + IF vt = vt_STRUCT THEN + FPRINT Outfile, Scoot$, "struct _", SOF$, " ", STRING$(dms,42), CVar$, ";" + ELSE + FPRINT Outfile, Scoot$, SOF$, " ", STRING$(dms,42), CVar$, ";" + END IF + CALL AddTypedefElement(BaseTypeDefsCnt[InTypeDef], vt, CVar$, SOF$, dms) + ELSEIF InFunc THEN + LocalDynArrCount++ + LocalDynArrName$ [LocalDynArrCount] = "if (" + CVar$ + ") { DestroyArr((void **)" + CVar$ + "," + STR$(dms) + ", 1); " + CVar$ + "=NULL; }" + FPRINT Outfile,Scoot$,SOF$;" ";STRING$(dms,42);CVar$;"=0;" + CALL AddLocal(CVar$, vt, id,"",dms,0,0) + ELSE + IF Use_GenFree THEN + GlobalDynaCnt++ + GlobalDynaStr$[GlobalDynaCnt] = "if (" + CVar$ + ") { DestroyArr((void **)" + CVar$ + "," + STR$(dms) + ", 1); " + CVar$ + "=NULL; }" + END IF + CALL AddGlobal(CVar$, vt, id,"",dms,0,0,0) + END IF + IF NOT InTypeDef THEN + FPRINT Outfile,Scoot$,CVar$ ; "= ("; SOF$ ;STRING$(dms,42);")CreateArr ("; CVar$ ; ",sizeof(";SOF$;"),0,";TRIM$(STR$(dms));"," ; ZZ$ ; ");" + END IF + '*********************** + CASE "redim" + '*********************** + 'REDIM b$ * 14 + 'REDIM PRESERVE b$ * 20 + 'REDIM a$[10] + 'REDIM PRESERVE a$[20] + '*********************** + DIM RAW IsPreserve + DIM RAW SOF$ + DIM RAW VI AS VarInfo PTR + DIM RAW vt1 = 0 + DIM RAW IsSplat = 0 + DIM RAW BC = 0 + DIM RAW StartPoint + DIM RAW AsPos = Ndx + CALL HandleNonsense + IsPreserve = iMatchWrd(Stk$[2], "preserve") + StartPoint = 2 + IsPreserve + vt1 = DataType(Stk$[StartPoint]) + CVar$ = Clean$(Stk$[StartPoint]) + IsSplat = iMatchWrd(Stk$[StartPoint + 1], "*") + CALL ValidVar(CVar$) + FOR i = Ndx TO 1 STEP -1 + IF iMatchWrd(Stk$[AsPos], "as") THEN + AsPos = i - 1 + EXIT FOR + END IF + NEXT + DIM RAW L = AsPos, SP = 0 + WHILE L > StartPoint + IF Stk$[L] = "[" THEN + DECR BC + ELSEIF Stk$[L] = "]" THEN + INCR BC + IF BC = 1 THEN DECR L : ITERATE + END IF + IF BC = 0 THEN + INCR SP + IF Stk$[L-1] <> "]" THEN EXIT WHILE + ZZ$ = "," + ZZ$ + ELSE + ZZ$ = Stk$[L] + ZZ$ + END IF + DECR L + WEND + 'get info + vt = CheckLocal(CVar$, &id) + IF vt = vt_UNKNOWN THEN + vt = CheckGlobal(CVar$, &id) + IF vt = vt_UNKNOWN THEN + Abort("Can not REDIM " + CVar$ + " not previously dimensioned") + END IF + VI = &GlobalVars[id] + ELSE + VI = &LocalVars[id] + END IF + dms = VI->VarPntr + IF vt = vt_STRUCT OR vt = vt_UDT OR vt = vt_UNION THEN 'added vt_UNION 4.40 + SOF$ = GetElement$( StartPoint, &vt, &dms, VI->VarDef) + i = Ndx + Ndx = L-1 + CALL AsmUnknownStructs(1) + Ndx = i + CALL RemEmptyTokens + CVar$ = Clean$(Stk$[StartPoint]) + IsSplat = iMatchWrd(Stk$[StartPoint + 1], "*") + ELSE + SOF$ = GetVarTypeName$(vt) + END IF + IF iMatchWrd(Stk$[Ndx-1], "as") THEN + IF SOF$ <> Stk$[Ndx] AND NOT iMatchWrd(Stk$[Ndx], "string") THEN + Abort("Can not change types for variable " + CVar$ + " previously defined as " + SOF$ + " on line" + STR$(VI->VarLine)) + END IF + IF iMatchWrd(Stk$[Ndx], "string") THEN + Ndx-- + Stk$[Ndx] = "[" + Stk$[++Ndx] = "65535" + Stk$[++Ndx] = "]" + ELSE + Ndx -= 2 + END IF + ELSE + IF (vt = vt_CHAR AND vt1 = vt_STRVAR AND IsSplat = 0) OR vt = vt_CHARPTR THEN + Ndx++ + Stk$[Ndx] = "[" + Stk$[++Ndx] = "65535" + Stk$[++Ndx] = "]" + END IF + END IF + IF Stk$[3 + IsPreserve] = "[" THEN + IF IsPreserve THEN + StartPoint = 4 + ELSE + FPRINT Outfile,Scoot$, "if (" + CVar$ + ") { DestroyArr((void **)" + CVar$ + "," + STR$(dms) + ", 1); " + CVar$ + "=NULL; }" + StartPoint = 3 + END IF + Use_DynamicA =TRUE + A = 0 + ZZ$ = "" + FOR i = StartPoint TO Ndx + IF Stk$[i] = "[" THEN + A++ + i++ + BC = 1 + WHILE BC > 0 + IF Stk$[i] = "[" THEN + BC++ + CONCAT(ZZ$, Stk$[i]) + ELSE + IF Stk$[i] = "]" THEN + BC-- + IF BC = 0 AND i < Ndx THEN + CONCAT(ZZ$, ",") + END IF + IF BC THEN + CONCAT(ZZ$, Stk$[i]) + END IF + ELSE + CONCAT(ZZ$, Stk$[i]) + END IF + END IF + i++ + WEND + i-- + END IF + NEXT + ZZ$ = Clean$(ZZ$) + IF vt = vt_STRLIT OR vt = vt_DECFUNC OR vt = vt_NUMBER OR _ + (vt = vt_VOID AND INCHR(Stk$[Ndx],"*") = 0) THEN + Abort(Stk$[Ndx] + " is not a valid type") + END IF + IF vt = vt_STRVAR THEN + SOF$ = "char" + A++ + CONCAT(ZZ$,",65535") + END IF + IF A <> dms THEN + Abort("Mismatch in dimensions for " + CVar$ + ", orignally " + STR$(dms) + " found " + STR$(A)) + END IF + FPRINT Outfile,Scoot$,CVar$ ; "= ("; SOF$ ;STRING$(dms,42);")CreateArr ("; CVar$ ; ",sizeof(";SOF$;"),";TRIM$(STR$(IsPreserve));",";dms;"," ; ZZ$ ; ");" + EXIT SELECT + END IF + IF Stk$[3]= "*" OR (IsPreserve AND Stk$[4]= "*") THEN ' DIM MySTRING$ * NumBytes + IF IsPreserve THEN + FPRINT Outfile,Scoot$ ; CVar$ ; "=(char*)realloc(";CVar$;",256+"; + i = 5 + ELSE + FPRINT Outfile,Scoot$ ; "free(" ; CVar$ ; ");" + FPRINT Outfile,Scoot$ ; CVar$ ; "=(char*)calloc(256+"; + i = 4 + END IF + FOR A = i TO Ndx + FPRINT Outfile,Clean$(Stk$[A]); + NEXT + IF IsPreserve THEN + FPRINT Outfile,");" + ELSE + FPRINT Outfile,",1);" + END IF + EXIT SELECT + END IF + Abort("Invalid REDIM statement") + + '********************************************************* + CASE "dim", "local", "raw", "static", "auto", "register" + '******************************************************** + ' DIM A$ * blah blah blah + ' DIM a%[1000] (integer) + ' DIM a![1000] (single) + ' DIM a#[1000] (double) + ' DIM a¦[1000] (long double) + ' DIM A$[1000] (string) + ' DIM r AS DATA_TYPE + ' DIM r[1][2]...[n] AS DATA_TYPE + ' DIM DYNAMIC A$[1000] + ' DIM a AS CONST CHAR PTR + '******************************************************** + DIM RAW w = 0 + DIM RAW UseStatic$ + DIM RAW IsVolatile = 0 + DIM RAW IV$ + + IsVolatile = iMatchWrd(Stk$[2],"volatile") + IF IsVolatile THEN + IV$ = "volatile " + ELSE + IV$ = "" + END IF + IsSubOrFuncPtr = SubFuncTest() + CALL HandleNonsense + IF Stk$[Ndx] = "*" THEN CALL PointerFix + IF Stk$[Ndx] = "&" THEN Stk$[Ndx--] = "" : CONCAT(Stk$[Ndx], "&") + IsRegister = IsAuto = IsDim = IsLocal = IsStatic = IsRaw = FALSE + Cmd$ = LCASE$(Stk$[1]) + + SELECT CASE Cmd$ + CASE "dim" : IsDim = TRUE + CASE "local" : IsLocal = TRUE + CASE "static" : IsStatic = TRUE + CASE "raw" : IsRaw = TRUE + CASE "auto" : IsAuto = TRUE + CASE "register" : IsRegister = TRUE + END SELECT + + '/***** 2010-11-15 Added support for public/protected/constructor/destructor in Classes -AIR + IF InTypeDef THEN + IF iMatchWrd(Stk$[2], "public") OR iMatchWrd(Stk$[2], "private") OR iMatchWrd(Stk$[2], "protected") THEN + FPRINT Outfile, LF$;LCASE$(Stk$[2]);":" + EXIT SELECT + ELSEIF iMatchWrd(Stk$[2], "constructor") OR iMatchWrd(Stk$[2], "destructor") THEN + 'ADD SUPPORT HERE FOR PARSING METHOD PARAMETERS + CALL DimSubFunc(0) + EXIT SELECT + '/***** 2010-12-01 -AIR *****/ + ELSEIF iMatchWrd(Stk$[2], "virtual") THEN + vproc$ = "" + IF iMatchWrd(Stk$[Ndx-1],"=") and iMatchWrd(Stk$[Ndx], "0") THEN + ' Store the "=0" + vproc$ = Stk$[Ndx-1] + Stk$[Ndx] + '~ change Ndx to strip off "=0" + Ndx = Ndx-2 + END IF + '~ STRIP OUT "VIRTUAL" AND LEFT SHIFT ENTIRE SOURCE + FOR integer act = 3 TO Ndx + Stk$[act-1] = Stk$[act] + NEXT + + Ndx-- + + CALL DimSubFunc(0) + + EXIT SELECT + END IF + END IF + '************************************************************************* + IF IsSubOrFuncPtr THEN + IF IsVolatile THEN Abort("volatile SUB/FUNCTION pointers not supported") + IF DimSubFunc(0) THEN EXIT SELECT + END IF + '************************************************************************* + CVar$ = Clean$(Stk$[2+IsVolatile]) + CALL ValidVar(CVar$) + VType = DataType(Stk$[2+IsVolatile]) + '*********************************************************************** + IF Stk$[3+IsVolatile] = "*" THEN ' DIM MySTRING$ * NumBytes + IF IsVolatile THEN Abort("volatile dynamic strings not supported") + CALL DimDynaString(CVar$, 0, 0) + EXIT SELECT + END IF + + RAW iASoffset = 0 + RAW sConst$ + RAW iIsConst + + IF iMatchWrd(Stk$[Ndx-1],"as") THEN iASoffset = Ndx-1 + IF iMatchWrd(Stk$[Ndx-2],"as") THEN iASoffset = Ndx-2 + + + IF iASoffset THEN + + iIsConst = 0 + sConst$ = "" + IF iASoffset = Ndx-2 THEN + IF iMatchWrd(Stk$[Ndx-1],"const") THEN + sConst$ = "const" + iIsConst = 1 + END IF + END IF + + Var1$ = CVar$ + IsPointer = TALLY(Stk$[Ndx],"*") + DimType$ = "" + lszTmp$ = "" + + FOR i = 2+IsVolatile TO iASoffset-1 + CONCAT(lszTmp$, Stk$[i]) + IF i > 2+IsVolatile THEN CONCAT(DimType$, Stk$[i]) + NEXT + Var$ = REMOVE$(Stk$[Ndx],"*") + GetTypeInfo(Var$, &w, &id, &vt) + IF vt = vt_STRVAR THEN + Stk$[Ndx] = "char" + Var$ = Stk$[Ndx] + CONCAT(DimType$, "[65535]") + CONCAT(lszTmp$, "[65535]") + END IF + IF InFunc OR InTypeDef THEN + IF IsRegister OR IsAuto THEN + IF IsRegister THEN + IF IsVolatile THEN Abort("Register volatile not supported") + IF vt = vt_FILEPTR THEN + FPRINT Outfile,Scoot$,"register FILE* "; + ELSE + FPRINT Outfile,Scoot$,"register ";sConst$;" ";Stk$[Ndx];" "; + END IF + ELSE + IF vt = vt_FILEPTR THEN + FPRINT Outfile,Scoot$,"auto ";IV$;" FILE* "; + ELSE + FPRINT Outfile,Scoot$,"auto ";IV$;" ";sConst$;" ";Stk$[Ndx];" "; + END IF + END IF + ELSE + IF IsRaw = TRUE THEN + IF vt = vt_FILEPTR THEN + FPRINT Outfile,Scoot$,"static ";IV$;" FILE* "; + ELSE + FPRINT Outfile,Scoot$,IV$;sConst$;" ";Stk$[Ndx];" "; + END IF + ELSE + IF InTypeDef THEN + UseStatic$ = "" + ELSE + UseStatic$ = "static " + END IF + IF vt = vt_STRUCT THEN + FPRINT Outfile,Scoot$,UseStatic$;IV$;sConst$;" ";"struct _" ; Stk$[Ndx]; " "; + ELSE + IF vt = vt_FILEPTR THEN + FPRINT Outfile,Scoot$,UseStatic$;IV$;"FILE *"; + ELSE + FPRINT Outfile,Scoot$,UseStatic$;IV$;sConst$;" ";Stk$[Ndx] ; " "; + END IF + END IF + IF InTypeDef THEN + CALL AddTypedefElement(BaseTypeDefsCnt[InTypeDef], vt, CVar$, Var$, 0) + END IF + END IF + END IF + + IF InFunc AND NOT InTypeDef THEN + CALL AddLocal(Var1$, vt, id, DimType$, IsPointer,0,0,iIsConst) + END IF + + FPRINT Outfile,Clean$(lszTmp$); ";" + IF NOT InTypeDef AND NOT IsStatic AND NOT IsRaw AND NOT IsRegister AND NOT IsVolatile THEN + T$ = Clean$(EXTRACT$(lszTmp$,"[")) + IF IsPointer THEN + FPRINT Outfile,Scoot$,"memset(&";T$;",0,sizeof(";Clean$(Var$) + " *";"));" + ELSE + FPRINT Outfile,Scoot$,"memset(&";T$;",0,sizeof(";T$;"));" + END IF + END IF + ELSE + IF IsVolatile THEN + CALL AddGlobal(Var1$, vt, id, DimType$,IsPointer,0,3,0,iIsConst) + ELSE + CALL AddGlobal(Var1$, vt, id, DimType$,IsPointer,0,0,0,iIsConst) + END IF + END IF + EXIT SELECT + END IF + '************************************************************************* + IF InFunc OR InTypeDef THEN + lszTmp$ = "" + IF iMatchWrd(Stk$[3+IsVolatile],"as") THEN + VType = CheckType(Stk$[4+IsVolatile]) + IF VType = vt_CHAR THEN + IF Stk$[5] = "*" THEN + lszTmp$ = "[" + Stk$[6+IsVolatile] + "]" + END IF + END IF + ELSE + FOR i = 3+IsVolatile TO Ndx + CONCAT (lszTmp$, Stk$[i]) + NEXT + lszTmp$ = LTRIM$(Clean$(lszTmp$)) + IF VType = vt_STRVAR THEN 'AND ((Stk$[3+IsVolatile] = "" AND InTypeDef) OR (NOT InTypeDef)) THEN + 'print lszTmp$ + IF lszTmp$ <> "[65535]" THEN CONCAT (lszTmp$, "[2048]") + 'print lszTmp$ + END IF + END IF + j = (NOT InTypeDef AND NOT IsStatic AND NOT IsRaw AND NOT IsRegister) + IF j THEN + T$ = Clean$(EXTRACT$(CVar$,"[")) + END IF + + SELECT CASE VType + CASE vt_STRVAR + IF IsRaw THEN + FPRINT Outfile,Scoot$;IV$;"char ";CVar$;lszTmp$;";" + ELSEIF IsAuto THEN + FPRINT Outfile,Scoot$;"auto ";IV$;"char ";CVar$;lszTmp$;";" + ELSEIF IsRegister THEN + IF IsVolatile THEN Abort("register volatile not supported") + FPRINT Outfile,Scoot$;"register char ";CVar$;lszTmp$;";" + ELSE + IF InTypeDef THEN + FPRINT Outfile,Scoot$;IV$;"char ";CVar$;lszTmp$;";" + ELSE + FPRINT Outfile,Scoot$;"static ";IV$;"char ";CVar$;lszTmp$;";" + END IF + END IF + + IF j AND NOT IsVolatile THEN + FPRINT Outfile,Scoot$;"memset(&";T$;",0,sizeof(";T$;"));" + END IF + + CASE vt_VarMin TO vt_VarMax + ZZ$ = GetVarTypeName$(VType) + ZZ$ = RPAD$(ZZ$, 7) + IF IsRaw THEN + FPRINT Outfile,Scoot$;IV$;ZZ$;" ";CVar$;lszTmp$;";" + ELSEIF IsAuto THEN + FPRINT Outfile,Scoot$;"auto ";IV$;ZZ$;" ";CVar$;lszTmp$;";" + ELSEIF IsRegister THEN + IF IsVolatile THEN Abort("Regester volatile not supported") + FPRINT Outfile,Scoot$;"register ";ZZ$;" ";CVar$;lszTmp$;";" + ELSE + IF InTypeDef THEN + FPRINT Outfile,Scoot$;IV$;ZZ$;" ";CVar$;lszTmp$;";" + ELSE + FPRINT Outfile,Scoot$;"static ";IV$;ZZ$;" ";CVar$;lszTmp$;";" + END IF + END IF + IF j AND NOT IsVolatile THEN + FPRINT Outfile,Scoot$;"memset(&";T$;",0,sizeof(";T$;"));" + END IF + END SELECT + + IF InFunc AND NOT InTypeDef THEN + CALL AddLocal(CVar$, VType, 0, lszTmp$,0,0,0) + END IF + IF InTypeDef THEN + CALL AddTypedefElement(BaseTypeDefsCnt[InTypeDef], VType, CVar$, Var$, 0) + END IF + EXIT SELECT + END IF + '************************************************************************ + lszTmp$ = "" ' if we get here, we're creating with a GLOBAL variable + '************************************************************************ + + FOR i = 3+IsVolatile TO Ndx + CONCAT (lszTmp$, Stk$[i]) + NEXT + IF VType = vt_STRVAR AND lszTmp$ <> "" THEN + CONCAT (lszTmp$, "[65535]") + END IF + IF IsVolatile THEN + CALL AddGlobal(CVar$, VType, 0,lszTmp$,0,0,3,0) + ELSE + CALL AddGlobal(CVar$, VType, 0,lszTmp$,0,0,0,0) + END IF + '*********************** + CASE "extern" + '*********************** + DIM RAW IsVolatile + IsSubOrFuncPtr = SubFuncTest() + CALL HandleNonsense + IsVolatile = iMatchWrd(Stk$[2],"volatile") + CVar$ = Clean$(Stk$[2+IsVolatile]) + CALL ValidVar(CVar$) + IF Stk$[Ndx] = "*" THEN CALL PointerFix + IF Stk$[Ndx] = "&" THEN Stk$[Ndx--] = "" : CONCAT(Stk$[Ndx], "&") + IF Stk$[3+IsVolatile] = "*" THEN + IF IsVolatile THEN Abort("volatile dynamic strings not supported") + CALL DimDynaString(CVar$, 2, 0) + EXIT SELECT + END IF + IF IsSubOrFuncPtr THEN + IF IsVolatile THEN Abort("volatile SUB/FUNCTION pointers not supported") + IF DimSubFunc(0) THEN EXIT SELECT + END IF + Var$ = Clean$(Stk$[2+IsVolatile]) + CALL ValidVar(Var$) + IsPointer = 0 + DimType$ = "" + IF iMatchWrd(Stk$[Ndx-1],"as") THEN + GetTypeInfo(Stk$[Ndx], &IsPointer, &id, &vt) + Stk$[Ndx] = REMOVE$(Stk$[Ndx],"*") + FOR i = 3+IsVolatile TO Ndx-2 + CONCAT (DimType$, Stk$[i]) + NEXT + ELSE + i = 3+IsVolatile + WHILE i <= Ndx + CONCAT(DimType$,Stk$[i]) + i++ + WEND + vt = DataType(Stk$[2+IsVolatile]) + id = 0 + END IF + IF vt = vt_STRVAR THEN ' AND DimType$ <> "" THEN + CONCAT (DimType$, "[65535]") + END IF + IF IsVolatile THEN + CALL AddGlobal(Var$, vt, id, DimType$, IsPointer,0,4,0) + ELSE + CALL AddGlobal(Var$, vt, id, DimType$, IsPointer,0,1,0) + END IF + '************************* + CASE "shared", "global" + '************************* + DIM RAW w = 0 + DIM RAW SOF$ + DIM RAW IsShared + DIM RAW IsVolatile + IsSubOrFuncPtr = SubFuncTest() + CALL HandleNonsense + IsVolatile = iMatchWrd(Stk$[2],"volatile") + CVar$ = Clean$(Stk$[2+IsVolatile]) + CALL ValidVar(CVar$) + IsShared = iMatchWrd(Stk$[1],"shared") + IF Stk$[Ndx] = "*" THEN CALL PointerFix + IF Stk$[Ndx] = "&" THEN Stk$[Ndx--] = "" : CONCAT(Stk$[Ndx], "&") + IF Stk$[3+IsVolatile] = "*" THEN + IF IsVolatile THEN Abort("volatile dynamic strings not supported") + CALL DimDynaString(CVar$, 1, IsShared) + EXIT SELECT + END IF + IF IsSubOrFuncPtr THEN + IF IsVolatile THEN Abort("volatile SUB/FUNCTION pointers not supported") + CALL DimSubFunc(0) + EXIT SELECT + END IF + IF iMatchWrd(Stk$[2],"dynamic") THEN + CVar$ = Clean$(Stk$[3]) + CALL ValidVar(CVar$) + IF iMatchWrd(Stk$[Ndx-1],"as") THEN + SOF$ = Stk$[Ndx] + GetTypeInfo(SOF$, &w, &id, &vt) + IF vt = vt_STRLIT OR _ + vt = vt_DECFUNC OR _ + vt = vt_NUMBER OR _ + (vt = vt_VOID AND INCHR(Stk$[Ndx],"*") = 0) THEN + Abort(Stk$[Ndx] + " is not a valid type") + END IF + Ndx -= 2 + ELSE + vt = DataType(Stk$[3]) + id = 0 + SOF$ = GetVarTypeName$(vt) + END IF + Use_DynamicA = TRUE + ZZ$ = "" + FOR i = 4 TO Ndx + CONCAT(ZZ$, Stk$[i]) + NEXT + dms = TALLY(ZZ$,"][") + 1 + IF dms > 1 THEN REPLACE "][" WITH "," IN ZZ$ + ZZ$ = Clean$(ZZ$) + RemoveAll(ZZ$,"[]") + IF vt = vt_STRVAR THEN + vt = vt_CHAR + SOF$ = "char" + dms++ + CONCAT(ZZ$,",65535") + END IF + IF Use_GenFree THEN + GlobalDynaCnt++ + GlobalDynaStr$[GlobalDynaCnt] = "if (" + CVar$ + ") { DestroyArr((void **)" + CVar$ + "," + STR$(dms) + ", 1); " + CVar$ + "=NULL; }" + END IF + CALL AddGlobal(CVar$, vt, id,"",dms,0,0,0) + FPRINT Outfile,Scoot$,CVar$ ; "= ("; SOF$ ;STRING$(dms,42);")CreateArr ("; CVar$ ; ",sizeof(";SOF$;"),0,";TRIM$(STR$(dms));"," ; ZZ$ ; ");" + EXIT SELECT + END IF + IsPointer = 0 + Var$ = Clean$(Stk$[2+IsVolatile]) + CALL ValidVar(Var$) + IF iMatchWrd(Stk$[Ndx-1],"as") THEN + IF INCHR(Stk$[Ndx],"*") THEN + IsPointer = TALLY(Stk$[Ndx],"*") + Stk$[Ndx] = REMOVE$(Stk$[Ndx],"*") + END IF + DimType$ = "" + FOR i = 3+IsVolatile TO Ndx-2 + CONCAT (DimType$, Stk$[i]) + NEXT + GetTypeInfo(Stk$[Ndx], &w, &id, &vt) + ELSE + DimType$ = "" + i = 3+IsVolatile + WHILE i <= Ndx + CONCAT(DimType$,Stk$[i]) + i++ + WEND + vt = DataType(Stk$[2+IsVolatile]) + id = 0 + END IF + IF vt = vt_STRVAR THEN + CONCAT (DimType$, "[65535]") + END IF + IF IsShared THEN + IF IsVolatile THEN + CALL AddGlobal(Var$, vt, id, DimType$, IsPointer,0,5,0) + ELSE + CALL AddGlobal(Var$, vt, id, DimType$, IsPointer,0,2,0) + END IF + ELSE + IF IsVolatile THEN + CALL AddGlobal(Var$, vt, id, DimType$, IsPointer,0,3,0) + ELSE + CALL AddGlobal(Var$, vt, id, DimType$, IsPointer,0,0,0) + END IF + END IF + '********************************************************************* + CASE "while" + CALL EmitIfCond("while") + '*********************** + CASE "wend", "endwhile" + '*********************** + CALL BumpDown + FPRINT Outfile,Scoot$,"}" + CALL BumpDown + '*********************** + CASE "exit" + '*********************** + IF CaseFlag THEN NoBreak2 = TRUE + IF iMatchWrd(Stk$[2],"sub") THEN + '************************* + ' Clean up dynamic strings + '************************* + IF LocalDynaCnt <> 0 THEN + FOR j = 1 TO LocalDynaCnt + FPRINT Outfile,Scoot$,DynaStr$[j] + NEXT + END IF + '********************************* + ' Clean up dynamic strings arrays + '********************************* + IF LocalDynArrCount <> 0 THEN + FOR i = 1 TO LocalDynArrCount + FPRINT Outfile,Scoot$, LocalDynArrName$[i] + NEXT + END IF + '********************************* + FPRINT Outfile,Scoot$,"return;" + EXIT SELECT + END IF + IF iMatchWrd(Stk$[2],"function") THEN + '************************* + ' Clean up dynamic strings + '************************* + IF LocalDynaCnt <> 0 THEN + FOR j = 1 TO LocalDynaCnt + FPRINT Outfile,Scoot$,DynaStr$[j] + NEXT + END IF + '********************************* + ' Clean up dynamic strings arrays + '********************************* + IF LocalDynArrCount <> 0 THEN + FOR i = 1 TO LocalDynArrCount + FPRINT Outfile,Scoot$, LocalDynArrName$[i] + NEXT + END IF + '********************************* + FPRINT Outfile,Scoot$,"return 0;" + ELSE + FPRINT Outfile,Scoot$,"break;" + END IF + '*********************** + CASE "goto" + '*********************** + IF CaseFlag THEN NoBreak2 = TRUE + FPRINT Outfile,Scoot$,"goto ";UCASE$(Stk$[2]);";" + '*********************** + CASE "print" + '*********************** + FPRINT Outfile,Scoot$, PrintWriteFormat$(0) + '*********************** + CASE "write" + '*********************** + FPRINT Outfile,Scoot$,PrintWriteFormat$(1) + '*********************** + CASE "run" + '*********************** + FPRINT Outfile,Scoot$,"Run ("; + FOR A = 2 TO Ndx + FPRINT Outfile,Clean$(Stk$[A]); + NEXT + FPRINT Outfile,Scoot$,");" + '*********************** + CASE "color" + '*********************** + FPRINT Outfile,Scoot$,"color ("; + FOR A = 2 TO Ndx + FPRINT Outfile,Clean$(Stk$[A]); + NEXT + FPRINT Outfile,");" + '*********************** + CASE "locate" + '*********************** + FPRINT Outfile,Scoot$,"locate ("; + FOR A = 2 TO Ndx + FPRINT Outfile,Clean$(Stk$[A]); + NEXT + FPRINT Outfile,");" + '*********************** + CASE "cls" + '*********************** + FPRINT Outfile,Scoot$,"cls();" + '********************************************************************** + CASE ELSE + '********************************************************************** + ' "=" We MUST be processing an assignment statement if we get here! + ' or perhaps calling a SUB without using the CALL keyword + '********************************************************************** + FOR B = 1 TO Ndx + IF Stk$[B]= "=" THEN EXIT FOR + NEXT + '************************************************************************* + 'There's no "=" so we're either calling a SUB or this is a FUNCTION RETURN + '************************************************************************* + IF B-1 = Ndx THEN + lszTmp$ = "" + FOR Tmp = 1 TO Ndx + CONCAT(lszTmp$, Clean$(Stk$[Tmp])) + NEXT + CONCAT(lszTmp$, ";") + IF FuncRetnFlag = 2 THEN + FPRINT Outfile,lszTmp$ + ELSE + FPRINT Outfile,Scoot$,lszTmp$ + END IF + IF FuncRetnFlag = 2 THEN + FuncRetnFlag = 0 + Stk$[1] = "" + EXIT SUB + END IF + EXIT SELECT + END IF + '************************************************************************* + ' It can only be one thing now -- a normal assignment statement + '************************************************************************* + FOR i = 2 TO B-1 + CONCAT(Stk$[1], Stk$[i]) ' IF present, build the Array Variable + NEXT + A = INCHR(Stk$[1], "*") + IF A THEN + IF NOT ( INCHR(Stk$[1], "$") AND A > 1 ) THEN 'Exclude strings BYREF + RemoveAll(Stk$[1], "$") + GOTO ProcessNumeric + END IF + END IF + '************************************************************************* + ' 'processing a string equation + '************************************************************************* + LOCAL strtest, varid, vi AS VarInfo PTR, vr$, brcnt + strtest = DataType(Stk$[1]) + IF strtest = vt_INTEGER THEN + brcnt = TALLY(Stk$[1], "[") + vr$ = EXTRACT$(Stk$[1], "[") + strtest = CheckLocal(vr$, &varid) + IF strtest = vt_UNKNOWN THEN + strtest = CheckGlobal(vr$, &varid) + vi = &(GlobalVars[varid]) + ELSE + vi = &(LocalVars[varid]) + END IF + IF strtest = vt_CHAR THEN + strtest = vt_STRVAR + END IF + IF strtest = vt_STRVAR THEN + IF vi->VarPntr <> 0 THEN + ' string pointer + GOTO ProcessNumeric + END IF + IF TALLY(vi->VarDim,"[") = brcnt THEN + ' the character within string + GOTO ProcessNumeric + END IF + IF TALLY(vi->VarDim,"[") <> brcnt+1 THEN + ' string pointer + GOTO ProcessNumeric + END IF + END IF + END IF + IF strtest = vt_STRVAR THEN + '************************************************************************* + IF B+1 = Ndx THEN + IF Stk$[Ndx] = DDQ$ THEN + FPRINT Outfile,Scoot$,"*",Clean$(Stk$[1]),"=0;" + GOTO StringExit + END IF + END IF + ' [ Speed up No. 1 ] **************************************************** + IF Ndx = 3 THEN + Stk$[1]=Clean$(Stk$[1]) + Stk$[3]=Clean$(Stk$[3]) + IF Stk$[1] = "BCX_RetStr" THEN + FPRINT Outfile,Scoot$,"BCX_RetStr=BCX_TmpStr(strlen(" ; Stk$[3] ; "));" + END IF + FPRINT Outfile,Scoot$,"strcpy(", Stk$[1], ",", Stk$[3], ");" + GOTO StringExit + END IF + '*********************** + Arg$ = "" + lszTmp$ = "" + j=k=0 + '*********************** + IF iMatchLft(Stk$[3],"$$") THEN HasStorage = TRUE + Var$ = Clean$(Stk$[1]) + IF Clean$(Stk$[B+1]) = Var$ THEN + k = TRUE + END IF + FOR A = B+1 TO Ndx ' B marks the position of the "=" char + IF Stk$[A]= "&" AND Stk$[A-1] <> "," AND Stk$[A-1] <> "(" THEN + INCR j + Arg$ = Arg$ + lszTmp$ + lszTmp$ = "," + ELSE + CONCAT(lszTmp$, Clean$(Stk$[A])) + END IF + NEXT + IF *lszTmp <> 0 AND lszTmp$ <> "," THEN + Arg$ = Arg$ + lszTmp$ + END IF + '************************************************************************* + ' Rules + '************************************************************************* + ' IF j = 0 & K = ANY THEN use strcpy + ' IF j = 1 & K = TRUE THEN use strcat + ' All else THEN use join + '************************************************************************* + RemoveAll(Var$, SPC$) 'Added this during the beta testing + '*** needs to be checked out still *** + 'stk[++i] is getting here as stk [ + + i ] + IF j = 0 THEN + IF Var$ = "BCX_RetStr" THEN + IF HasStorage THEN + FPRINT Outfile,Scoot$,"BCX_RetStr=", Arg$, ";" + GOTO StringExit + ELSE + FPRINT Outfile,Scoot$,"BCX_RetStr=BCX_TmpStr(strlen(" , Arg$ , "));" + END IF + END IF + FPRINT Outfile,Scoot$,"strcpy(", Var$ , "," , Arg$, ");" + GOTO StringExit + END IF + 'If we make it here then we should have 2 or more expressions + IF k = TRUE AND j = 1 THEN + FPRINT Outfile,Scoot$,"strcat(", Arg$ , ");" + GOTO StringExit + END IF + lszTmp$ = LTRIM$(STR$(++j)) + Use_Join = TRUE + IF Var$ = "BCX_RetStr" THEN + FPRINT Outfile,Scoot$,"BCX_RetStr=join(" , lszTmp$ , "," , Arg$, ");" + ELSE + FPRINT Outfile,Scoot$,"strcpy(",Var$, ", join(" , lszTmp$ , "," , Arg$, "));" + END IF + StringExit: + EXIT SELECT + '*********************** + ELSE + '*********************** + ProcessNumeric: + '*********************** + FOR i = 2 TO B + Stk$[i] = "" + NEXT + Stk$[B]= "=" 'This is necessary + ' change x = x ? c to x ?= c + IF Stk$[B + 1] = Stk$[1] AND Ndx = 5 THEN + IF Inset(Stk$[B + 2], "+-*/") AND Stk$[B + 3] <> ">" THEN + Stk$[B] = Stk$[B + 2] + Stk$[B] + Stk$[B + 1] = "" + Stk$[B + 2] = "" + END IF + END IF + FPRINT Outfile,Scoot$,Clean$(Stk$[1]); + FOR A = 2 TO Ndx + IF Stk$[A] = "!" THEN + FPRINT Outfile,"!"; + ELSE + FPRINT Outfile,Clean$(Stk$[A]); + END IF + NEXT + FPRINT Outfile,";" + END IF + END SELECT + IF FuncRetnFlag = 1 THEN + IF LocalDynaCnt <> 0 THEN + FOR j = 1 TO LocalDynaCnt + FPRINT Outfile,Scoot$,DynaStr$[j] + NEXT + END IF + '****************************************************************** + FPRINT Outfile,Scoot$,"return BCX_RetStr;" ' $ FUNCTION Return + '****************************************************************** + END IF +END SUB ' Emit +SUB Abort(Z$) + DIM RAW i = 0 + DIM RAW j = 0 + DIM RAW k = 0 + DIM RAW varnum = 0 + DIM RAW t$ + DIM RAW frmt$ + WarnMsg$ = "" + IF LEFT$(AbortSrc$,11) = "$BCXVERSION" THEN + CONCAT(WarnMsg$,Z$) + ELSE + WarnMsg$ = WarnMsg$ + Z$ + " at line" + STR$(ModuleLineNos[ModuleNdx]) + " in Module: " + TRIM$(Modules$[ModuleNdx]) + CRLF$ + WarnMsg$ = WarnMsg$ + "Original line" + CRLF$ + WarnMsg$ = WarnMsg$ + AbortSrc$ + CRLF$ + WarnMsg$ = WarnMsg$ + "==============" + CRLF$ + WarnMsg$ = WarnMsg$ + "Current Tokens" + CRLF$ + WarnMsg$ = WarnMsg$ + "==============" + CRLF$ + FOR k = 1 TO Ndx + j = LEN(Stk$[k]) + IF j < 40 THEN + j = 40 - j + ELSE + j = 8 - IMOD(j,8) + END IF + frmt$ = LPAD$(STR$(k),3) + WarnMsg$ = WarnMsg$ + frmt$ + " " + Stk$[k] + STRING$(j,32) + CRLF$ + t$ = Clean$(Stk$[k]) + i = CheckLocal(t$, &varnum) + IF i <> vt_UNKNOWN THEN + WarnMsg$ = WarnMsg$ + "is a LOCAL defined at line" + STR$(LocalVars[varnum].VarLine) + WarnMsg$ = WarnMsg$ + " in Module: " + LocalVars[varnum].VarModule + CRLF$ + ELSE + i = CheckGlobal(t$, &varnum) + IF i <> vt_UNKNOWN THEN + WarnMsg$ = WarnMsg$ + "is a GLOBAL defined at line" + STR$(GlobalVars[varnum].VarLine) + WarnMsg$ = WarnMsg$ + " in Module: " + GlobalVars[varnum].VarModule + CRLF$ + WarnMsg$ = WarnMsg$ + " " + Stk$[k] & GlobalVars[varnum].VarDim$ + " as " + IF GlobalVars[varnum].VarDef THEN + WarnMsg$ = WarnMsg$ + TRIM$(TypeDefs[GlobalVars[varnum].VarDef].VarName$) + CRLF$ + ELSE + WarnMsg$ = WarnMsg$ + TRIM$(GetVarTypeName$(GlobalVars[varnum].VarType)) + CRLF$ + END IF + ELSE + IF Stk[k][0] = 34 THEN + WarnMsg$ = WarnMsg$ + "is a STRING LITERAL" + CRLF$ + END IF + END IF + END IF + NEXT + WarnMsg$ = WarnMsg$ + "===============" + CRLF$ + WarnMsg$ = WarnMsg$ + "Original Tokens" + CRLF$ + WarnMsg$ = WarnMsg$ + "===============" + CRLF$ + CALL XParse(AbortSrc$) + FOR k = 1 TO Ndx + j = LEN(Stk$[k]) + IF j < 40 THEN + j = 40 - j + ELSE + j = 8 - IMOD(j,8) + END IF + frmt$ = LPAD$(STR$(k),3) + WarnMsg$ = WarnMsg$ + frmt$ + " " + Stk$[k] + STRING$(j,32) + CRLF$ + t$ = Clean$(Stk$[k]) + i = CheckLocal(t$, &varnum) + IF i <> vt_UNKNOWN THEN + WarnMsg$ = WarnMsg$ + "is a LOCAL defined at line" + STR$(LocalVars[varnum].VarLine) + WarnMsg$ = WarnMsg$ + " in Module: " + LocalVars[varnum].VarModule + CRLF$ + ELSE + i = CheckGlobal(t$, &varnum) + IF i <> vt_UNKNOWN THEN + WarnMsg$ = WarnMsg$ + "is a GLOBAL defined at line" + STR$(GlobalVars[varnum].VarLine) + WarnMsg$ = WarnMsg$ + " in Module: " + GlobalVars[varnum].VarModule + CRLF$ + WarnMsg$ = WarnMsg$ + " " + Stk$[k] & GlobalVars[varnum].VarDim$ + " as " + IF GlobalVars[varnum].VarDef THEN + WarnMsg$ = WarnMsg$ + TypeDefs[GlobalVars[varnum].VarDef].VarName$ + CRLF$ + ELSE + WarnMsg$ = WarnMsg$ + GetVarTypeName$(GlobalVars[varnum].VarType) + CRLF$ + END IF + ELSE + IF Stk[k][0] = 34 THEN + WarnMsg$ = WarnMsg$ + "is a string literal" + CRLF$ + END IF + END IF + END IF + NEXT + END IF + WarnMsg$ = WarnMsg$ + CRLF$ + CALL CloseAll + KILL ovrFile$ + KILL FileOut$ + KILL prcFile$ + KILL udtFile$ + KILL hdrFile$ + KILL cstFile$ + KILL datFile$ + KILL setFile$ + KILL enuFile$ + 'KILL resFile$ + KILL "$t$e$m$p" + IF ErrFile THEN + OPEN FileErr$ FOR APPEND AS fpErr + FPRINT fpErr, Z$ ; " at line" ; ModuleLineNos[ModuleNdx] ; " in Module: "; TRIM$(Modules$[ModuleNdx]) 'LinesRead + CLOSE fpErr + END IF + PRINT "Error!",CRLF$, FileIn$,CRLF$, WarnMsg$ + CALL FREEGLOBALS + END = 1 +END SUB ' Abort +SUB BumpDown + Indent-- + Indent-- + IF Indent<0 THEN Indent = 0 + Scoot$ = SPACE$(Indent) +END SUB ' BumpDown +SUB BumpUp + IF Indent<0 THEN Indent = 0 + Indent++ + Indent++ + Scoot$ = SPACE$(Indent) +END SUB ' BumpUp +FUNCTION BraceCount( Arg$ ) + DIM RAW p AS CHAR PTR + DIM RAW braces + p = Arg$ + braces = 0 + WHILE *p + IF *p = c_DblQt THEN + p++ + WHILE *p <> c_DblQt + IF *p = 0 THEN FUNCTION = braces + p++ + WEND + END IF + IF *p = ASC("}") THEN braces-- + IF *p = ASC("{") THEN braces++ + p++ + WEND + FUNCTION = braces +END FUNCTION ' BraceCount +FUNCTION BracketHandler(Src$,l) AS CHAR PTR + DIM RAW s AS CHAR PTR + s = Src$ + SELECT CASE l + CASE 0 + DO + IF *s = 0 THEN EXIT LOOP + IF *s = c_DblQt THEN + s++ + WHILE *s <> c_DblQt + IF *s = 0 THEN EXIT LOOP + s++ + WEND + END IF + IF *s = c_LtBkt THEN + s++ + s = BracketHandler(s,1) + END IF + IF *s = c_LPar THEN + s++ + s = BracketHandler(s,2) + END IF + s++ + LOOP + CASE 1 + WHILE *s <> c_RtBkt + IF *s = c_DblQt THEN + s++ + WHILE *s <> c_DblQt + IF *s = 0 THEN EXIT LOOP + s++ + WEND + END IF + IF *s = c_LtBkt THEN + s++ + s = BracketHandler(s, 1) + END IF + IF *s = c_LPar THEN + s++ + s = BracketHandler(s, 2) + END IF + IF *s = c_Komma THEN *s = 1 + IF *s = 0 THEN EXIT LOOP + s++ + WEND + CASE 2 + WHILE *s <> c_RPar + IF *s = c_DblQt THEN + s++ + WHILE *s <> c_DblQt + IF *s = 0 THEN EXIT LOOP + s++ + WEND + END IF + IF *s = c_LtBkt THEN + s++ + s = BracketHandler(s, 1) + END IF + IF *s = c_LPar THEN + s++ + s = BracketHandler(s, 2) + END IF + IF *s = 0 THEN EXIT LOOP + s++ + WEND + END SELECT + IF l = 0 THEN + REPLACE CHR$(1) WITH "][" IN Src$ + FUNCTION = Src + END IF + FUNCTION = s +END FUNCTION ' BracketHandler +SUB Push(Z$) + CaseStk$[++Pusher]= Z$ +END SUB +SUB Pop(Z$) + Z$ = CaseStk$[--Pusher] +END SUB ' Pop +SUB EmitEpilog + IF NoMain + EndOfProgram = 0 THEN + FPRINT Outfile,"return 0; // End of main program" + CALL BumpDown + FPRINT Outfile,"}" + FLUSH(Outfile) + END IF +END SUB ' EmitEpilog +SUB EmitProlog + FPRINT Outfile,"" + FPRINT Outfile,"int main(int argc, char *argv[])" + '***************************************************************************** + ' int main is conditionally removed later IN SUB AddProtos + '***************************************************************************** + FLUSH (Outfile) +END SUB ' EmitProlog +SUB DeclareVariables + DIM RAW i + DIM RAW A + DIM RAW P$ + 'DIM RAW VAR$ + DIM RAW VarName$ + DIM RAW VarDim$ + DIM RAW Storage$ + OPEN FileOut$ FOR INPUT AS FP1 + OPEN "$t$e$m$p" FOR OUTPUT AS Outfile + OPEN cstFile$ FOR INPUT AS FP3 + IF LOF(cstFile$) > 0 THEN + FPRINT Outfile,"" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// " + $BCX_STR_USR_CONST + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"" + END IF + WHILE NOT EOF(FP3) + LINE INPUT FP3,Z$ + FPRINT Outfile,LTRIM$(Z$) + WEND + CLOSE FP3 + + '/***** 2011-03-10 Moved ENUM Emmission so that Named Enums can be used with User Prototypes / Classes -AIR *****/ + IF Use_EnumFile THEN + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// User's GLOBAL ENUM blocks" + FPRINT Outfile,"// *************************************************" + OPEN enuFile$ FOR INPUT AS FP8 + WHILE NOT EOF(FP8) + LINE INPUT FP8,Z$ + FPRINT Outfile,Z$ + WEND + CLOSE FP8 + FPRINT Outfile,"" + END IF + + OPEN udtFile$ FOR INPUT AS FP3 + IF LOF(udtFile$) > 0 THEN + FPRINT Outfile,"" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// " + $BCX_STR_USR_TYPES + FPRINT Outfile,"// *************************************************" + WHILE NOT EOF(FP3) + LINE INPUT FP3,Z$ + FPRINT Outfile,Scoot$,Z$ + WEND + END IF + CLOSE FP3 + IF HFileCnt > 0 THEN + FPRINT Outfile,"" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// User Include Files" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"" + A = 0 + WHILE A < HFileCnt + FPRINT Outfile,HFiles$[A] + A++ + WEND + FPRINT Outfile,"#include " + END IF + IF Use_SingleFile = TRUE THEN + FPRINT Outfile,"" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// "+$BCX_STR_SYS_VARS + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"" + + IF Use_RegEx THEN + FPRINT Outfile,"typedef struct _REGEX" + FPRINT Outfile,"{" + FPRINT Outfile," int count;" + FPRINT Outfile," regmatch_t matches[1024];" + FPRINT Outfile," PCHAR results[1024];" + FPRINT Outfile,"}REGEX, *LPREGEX;\n" + END IF + + IF Use_Time THEN + FPRINT Outfile,"enum TIME_OPTIONS" + FPRINT Outfile,"{" + FPRINT Outfile," TIME," + FPRINT Outfile," HOUR," + FPRINT Outfile," MINUTE," + FPRINT Outfile," SECOND," + FPRINT Outfile," APM," + FPRINT Outfile," YEAR," + FPRINT Outfile," MONTH," + FPRINT Outfile," DAY," + FPRINT Outfile," DAYNAME," + FPRINT Outfile," WEEKDAY," + FPRINT Outfile," YEARDAY," + FPRINT Outfile," WEEKNUMBER," + FPRINT Outfile," DATE," + FPRINT Outfile," FULLDATE" + FPRINT Outfile," };\n" + + END IF + + IF Use_Findfirst OR Use_Findnext THEN + FPRINT Outfile,"typedef struct _FILE_FIND_DATA" + FPRINT Outfile,"{" + FPRINT Outfile," DWORD dwFileAttributes;" + FPRINT Outfile," DWORD ftCreationTime;" + FPRINT Outfile," DWORD ftLastAccessTime;" + FPRINT Outfile," DWORD ftLastWriteTime;" + FPRINT Outfile," DWORD nFileSizeHigh;" + FPRINT Outfile," DWORD nFileSizeLow;" + FPRINT Outfile," char cFileSpec[MAX_PATH];" + FPRINT Outfile," char cFileName[MAX_PATH];" + FPRINT Outfile," char path[MAX_PATH];" + FPRINT Outfile," DIR *FileHandle;" + FPRINT Outfile,"}FILE_FIND_DATA, *LPFILE_FIND_DATA;\n" + END IF + IF Use_Ldouble THEN + FPRINT Outfile,"#define LDOUBLE long double" + END IF + IF Use_Idxqsort THEN + FPRINT Outfile,"char*** pppStr;" + END IF + IF Use_Idxqsort OR Use_IdxqsortSt OR Use_PtrqsortSt THEN + FPRINT Outfile,"int Key;" + END IF + IF Use_IdxqsortSt THEN + FPRINT Outfile,"char* cmp1;" + FPRINT Outfile,"int StructSize;" + END IF + IF Use_PtrqsortSt THEN + FPRINT Outfile,"int OffSet;" + END IF + '******************************** + ' PB Compatible String Constants + '******************************** + IF Use_NUL THEN + FPRINT Outfile,"char NUL [1]={0}; // Null" + END IF + + IF Use_BEL THEN + FPRINT Outfile,"char BEL [2]={7,0}; // Bell" + END IF + + IF Use_BS THEN + FPRINT Outfile,"char BS [2]={8,0}; // Back Space" + END IF + + IF Use_TAB THEN + FPRINT Outfile,"char TAB [2]={9,0}; // Horz Tab" + END IF + + IF Use_LF THEN + FPRINT Outfile,"char LF [2]={10,0}; // Line Feed" + END IF + + IF Use_VT THEN + FPRINT Outfile,"char VT [2]={11,0}; // Vert Tab" + END IF + + IF Use_FF THEN + FPRINT Outfile,"char FF [2]={12,0}; // Form Feed" + END IF + + IF Use_CR THEN + FPRINT Outfile,"char CR [2]={13,0}; // Carr Rtn" + END IF + + IF Use_EOF THEN + FPRINT Outfile,"char EF [2]={26,0}; // End-of-File" + END IF + + IF Use_ESC THEN + FPRINT Outfile,"char ESC [2]={27,0}; // Escape" + END IF + + IF Use_SPC THEN + FPRINT Outfile,"char SPC [2]={32,0}; // Space" + END IF + + IF Use_DQ THEN + FPRINT Outfile,"char DQ [2]={34,0}; // Double-Quote" + END IF + + IF Use_DDQ THEN + FPRINT Outfile,"char DDQ [3]={34,34,0}; // Double-Double-Quote" + END IF + + IF Use_Crlf THEN + FPRINT Outfile,"char CRLF[3]={13,10,0}; // Carr Rtn & Line Feed" + END IF + + '******************************** + + IF Use_Console THEN + FPRINT Outfile,"int color_fg = 7;" + FPRINT Outfile,"int color_bg = 0;" + END IF + + IF Use_Lineinput THEN + FPRINT Outfile,"char *AR_fgets_retval;" + END IF + + IF Use_Scan THEN + FPRINT Outfile,"int ScanError;" + END IF + + IF Use_Inputbuffer = TRUE THEN + FPRINT Outfile,"char InputBuffer[1048576];" + END IF + + IF Use_Findfirst OR Use_Findnext THEN + FPRINT Outfile,"FILE_FIND_DATA FindData;" + END IF + IF Use_Gosub THEN + FPRINT Outfile,"jmp_buf GosubStack[32];" + FPRINT Outfile,"int GosubNdx;" + END IF + IF Use_Dynacall THEN + FPRINT Outfile,"HINSTANCE BCX_DllStore[256];" + END IF + + '/***** 2013-06-26 New REGEX Keyword -AIR *****/ + + + END IF + IF GlobalVarCnt THEN + FPRINT Outfile,"" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// " + $BCX_STR_USR_VARS + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"" + END IF + + '************************************* + 'First we declare the simple Variables + '************************************* + FOR i = 1 TO GlobalVarCnt + IF GlobalVars[i].VarEmitFlag THEN ITERATE + IF "" = GlobalVars[i].VarDim$ AND GlobalVars[i].VarCondLevel = 0 THEN + P$ = "" + IF GlobalVars[i].VarPntr THEN P$ = STRING$(GlobalVars[i].VarPntr,42) + A = GlobalVars[i].VarType + IF GlobalVars[i].VarSF THEN + VarName$ = "(*" + GlobalVars[i].VarName$ + ")" + ELSE + VarName$ = GlobalVars[i].VarName$ + END IF + Storage$ = VarStorage$[GlobalVars[i].VarExtn] & VarConst$[GlobalVars[i].VarConstant] + VarDim$ = GlobalVars[i].VarDim$ + CALL PrintGlobal(A, i, Storage$, P$, VarName$, VarDim$) + END IF + NEXT + ' Next, we declare the Arrays + FOR i = 1 TO GlobalVarCnt + IF GlobalVars[i].VarEmitFlag THEN ITERATE + IF "" <> GlobalVars[i].VarDim$ AND GlobalVars[i].VarCondLevel = 0 THEN + IF INSTR(GlobalVars[i].VarDim,"{") = 0 THEN ' do uninitialized global arrays + P$ = "" + IF GlobalVars[i].VarPntr THEN P$ = STRING$(GlobalVars[i].VarPntr,42) + A = GlobalVars[i].VarType + IF GlobalVars[i].VarSF THEN + VarName$ = "(*" + GlobalVars[i].VarName$ + EXTRACT$(GlobalVars[i].VarDim,"(") + ")" + VarDim$ = MID$(GlobalVars[i].VarDim, INSTR(GlobalVars[i].VarDim,"(")) + ELSE + VarName$ = GlobalVars[i].VarName$ + VarDim$ = GlobalVars[i].VarDim$ + END IF + Storage$ = VarStorage$[GlobalVars[i].VarExtn] & VarConst$[GlobalVars[i].VarConstant] + CALL PrintGlobal(A, i, Storage$, P$, VarName$, VarDim$) + END IF + END IF + NEXT + DIM RAW LastDef$ + DIM RAW LastLevel + LastDef$ = "" + LastLevel = 1 + FOR i = 1 TO GlobalVarCnt + IF GlobalVars[i].VarEmitFlag THEN ITERATE + IF GlobalVars[i].VarCondLevel THEN + IF LastDef$ = "" THEN + LastDef$ = GlobalVars[i].VarCondDef$ + LastLevel = GlobalVars[i].VarCondLevel + FPRINT Outfile,LastDef$ + END IF + IF LastDef$ <> GlobalVars[i].VarCondDef$ THEN + IF GlobalVars[i].VarCondDef$ = "#else" THEN + WHILE LastLevel > GlobalVars[i].VarCondLevel + FPRINT Outfile,"#endif" + LastLevel-- + WEND + FPRINT Outfile,"#else" + LastDef$ = GlobalVars[i].VarCondDef$ + ELSE + WHILE LastLevel => GlobalVars[i].VarCondLevel + FPRINT Outfile,"#endif" + LastLevel-- + WEND + LastDef$ = GlobalVars[i].VarCondDef$ + LastLevel = GlobalVars[i].VarCondLevel + FPRINT Outfile,LastDef$ + END IF + END IF + P$ = "" + IF GlobalVars[i].VarPntr THEN P$ = STRING$(GlobalVars[i].VarPntr,42) + A = GlobalVars[i].VarType + IF GlobalVars[i].VarSF THEN + VarName$ = "(*" + GlobalVars[i].VarName$ + ")" + ELSE + VarName$ = GlobalVars[i].VarName$ + END IF + VarDim$ = GlobalVars[i].VarDim + Storage$ = VarStorage$[GlobalVars[i].VarExtn] & VarConst$[GlobalVars[i].VarConstant] + CALL PrintGlobal(A, i, Storage$, P$, VarName$, VarDim$) + END IF + NEXT + IF *LastDef$ THEN + WHILE LastLevel + FPRINT Outfile,"#endif" + LastLevel-- + WEND + END IF + FPRINT Outfile,"" + + + + '************************************* + 'Add Declared Dll variables + '************************************* + ' FPRINT Outfile, "// ****************************************" + ' FPRINT Outfile, "" + IF DllCnt THEN + DIM RAW i, AR_DllName$ + + FPRINT Outfile, "" + FPRINT Outfile, "// **********[ DLL Declarations ]**********" + FPRINT Outfile, "" + + ''------------------------------------------------------------------------ + '' Emit LoadLibrary assignments + '' HMODULE H_DLLNAME = LoadLibrary("DLLNAME.DLL"); + '' Todo: Add a check for H_DLLNAME = NULL in case of failure to load the DLL. + ''------------------------------------------------------------------------ + FOR i = 0 TO LoadLibsCnt - 1 + IF INCHR(Loadlibs$[i],"-") THEN + AR_DllName$ = EXTRACT$(Loadlibs$[i],"-") + ELSEIF INCHR(Loadlibs$[i],".") THEN + AR_DllName$ = EXTRACT$(Loadlibs$[i],".") + END IF + '~ FPRINT Outfile, "void *H_", UCASE$(EXTRACT$(Loadlibs$[i], ".")), " = dlopen(", ENC$(Loadlibs$[i]), ", RTLD_LAZY);" + FPRINT Outfile, "void *H_", UCASE$(AR_DllName$), " = dlopen(", ENC$(Loadlibs$[i]), ", RTLD_LAZY);" + NEXT i + + FOR i = 1 TO DllCnt + FPRINT Outfile, DllDecl$[i] ' Emit the users DLL Declarations + NEXT + + FPRINT Outfile, "" + FPRINT Outfile, "// ****************************************" + FPRINT Outfile, "" + END IF + + '******************************** + ' Read In The Data Statement File + '******************************** + OPEN datFile$ FOR INPUT AS FP5 + IF LOF(datFile$) > 0 THEN + FPRINT Outfile,"" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// User Data Statements" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"" + FPRINT Outfile,"char * DATA [] =" + FPRINT Outfile,"{" + WHILE NOT EOF(FP5) + LINE INPUT FP5,Z$ + FPRINT Outfile,Z$ + WEND + FPRINT Outfile,"};" + END IF + CLOSE FP5 + WHILE NOT EOF(FP1) + LINE INPUT FP1,Z$ + FPRINT Outfile,Z$ + WEND + CALL CloseAll + KILL FileOut$ + RENAME "$t$e$m$p", FileOut$ +END SUB 'DeclareVariables +FUNCTION GetNumArgs OPTIONAL(Strt, NdxPos AS INTEGER PTR=NULL) + DIM RAW CountR = 0 '() counter + DIM RAW CountS = 0 '[] counter + DIM RAW i 'loop counter + DIM RAW j = 0 'comma counter + DIM RAW k = 1 'function end flag + FOR i = Strt TO Ndx + IF Stk$[i] = "(" THEN + CountR++ + k++ + ELSEIF Stk$[i] = ")" THEN + CountR-- + k-- + IF k = 0 THEN EXIT FOR + ELSEIF Stk$[i] = "[" THEN + CountS++ + ELSEIF Stk$[i] = "]" THEN + CountS-- + ELSEIF Stk$[i] = "," AND CountR = 0 AND CountS = 0 THEN + j++ + IF NdxPos THEN *NdxPos = i + END IF + NEXT + FUNCTION = j 'No. of commas = No. of args +END FUNCTION ' GetNumArgs +SUB GetVarCode(varcode AS VARCODE PTR) + DIM RAW CB$, PT$, PTH$, VAR$, vn, RF$ + IF varcode->Method% = mt_Opts3 THEN + varcode->Proto$ = varcode->Proto$ + varcode->Token$ + IF varcode->Token$ = "," THEN + varcode->Header$ = varcode->Header$ + varcode->Token$ + END IF + EXIT SUB + END IF + IF varcode->Method% = mt_FuncSubx1 THEN + varcode->Proto$ = varcode->Proto$ + varcode->AsToken$ + "(*)(" + varcode->Header$ = varcode->Header$ + varcode->AsToken$ + " (*" + varcode->Token$ + ")(" + EXIT SUB + END IF + IF varcode->Method% = mt_FuncSubx2 THEN + varcode->Proto$ = varcode->Proto$ + varcode->AsToken$ + varcode->Header$ = varcode->Header$ + varcode->AsToken$ + " " + varcode->Token$ + EXIT SUB + END IF + IF IsCallBack THEN + CB$ = "CALLBACK " + ELSE + CB$ = "" + END IF + IF INCHR(varcode->Token$,"*") OR INCHR(varcode->AsToken$,"*") OR varcode->IsPtrFlag THEN + RemoveAll(varcode->Token$, "*") + RemoveAll(varcode->AsToken$, "*") + PT$ = STRING$(varcode->IsPtrFlag, ASC("*")) + " " + PTH$ = PT$ + ELSE + PTH$ = " " + PT$ = "" + END IF + IF INCHR(varcode->Token$,"&") THEN + RF$ = " &" + ELSE + RF$ = "" + END IF + vn = varcode->VarNo% + VAR$ = GetVarTypeName$(vn) + SELECT CASE vn + '************************************************************************ + CASE vt_STRVAR + '************************************************************************ + SELECT CASE varcode->Method% + CASE mt_ProcessSetCommand + varcode->StaticOut$ = "static char " + Clean$(varcode->Token$) + CASE mt_FuncSubDecC_Dec + varcode->Functype$ = "char * " + CB$ + CASE mt_FuncSubDecC_Dec2 + IF NOT INCHR(varcode->Token$, "[") THEN + varcode->Header$ = varcode->Header$ + "char *" + Clean$(varcode->Token$) + ", " + varcode->Proto$ = varcode->Proto$ + "char *, " + ELSE + varcode->Header$ = varcode->Header$ + "char " + REMOVE$(Clean$(varcode->Token$), "*") + ", " + varcode->Proto$ = varcode->Proto$ + "char [][65535], " + END IF + CASE mt_Opts + varcode->Functype$ = "char *" + CASE mt_Opts2 + varcode->Header$ = varcode->Header$ + "char * " + Clean$(varcode->Token$) + varcode->Proto$ = varcode->Proto$ + "char* " + CASE mt_OverLoad + varcode->Functype$ = "char *" + CASE mt_OverLoad2 + varcode->Header$ = varcode->Header$ + "char *" + Clean$(varcode->Token$) + ", " + END SELECT + '************************************************************************ + CASE vt_BOOL,vt_BYTE,vt_COLORREF,vt_DOUBLE,vt_DWORD,vt_FARPROC,vt_HDC, _ + vt_HANDLE,vt_HINSTANCE,vt_HWND,vt_INTEGER,vt_LONG,vt_LPBYTE,vt_LRESULT, _ + vt_SHORT,vt_SINGLE,vt_UINT,vt_ULONG,vt_USHORT,vt_VARIANT,vt_VOID,vt_LDOUBLE + '************************************************************************ + SELECT CASE varcode->Method% + CASE mt_ProcessSetCommand + varcode->StaticOut$ = "static " + VAR$ + " " + Clean$(varcode->Token$) + CASE mt_FuncSubDecC_Dec + varcode->Functype$ = VAR$ + PTH$ + CB$ + CASE mt_FuncSubDecC_Dec2 + varcode->Header$ = varcode->Header$ + VAR$ + PTH$ + Clean$(varcode->Token$) + ", " + varcode->Proto$ = varcode->Proto$ + VAR$ + RF$ + PT$ + ", " + CASE mt_Opts + varcode->Functype$ = VAR$ + PTH$ + CASE mt_Opts2 + varcode->Header$ = varcode->Header$ + VAR$ + PTH$ + Clean$(varcode->Token$) + varcode->Proto$ = varcode->Proto$ + VAR$ + RF$ + PT$ + CASE mt_OverLoad + varcode->Functype$ = VAR$ + " " + CASE mt_OverLoad2 + varcode->Header$ = varcode->Header$ + VAR$ + PTH$ + Clean$(varcode->Token$) + ", " + END SELECT + '************************************************************************ + CASE vt_FILEPTR, vt_CHAR + '************************************************************************ + SELECT CASE varcode->Method% + CASE mt_FuncSubDecC_Dec + varcode->Functype$ = VAR$ + PTH$ + CB$ + CASE mt_FuncSubDecC_Dec2 + varcode->Header$ = varcode->Header$ + VAR$ + PTH$ + Clean$(varcode->Token$) + ", " + varcode->Proto$ = varcode->Proto$ + VAR$ + PT$ + ", " + CASE mt_Opts + varcode->Functype$ = VAR$ + PTH$ + CASE mt_Opts2 + varcode->Header$ = varcode->Header$ + VAR$ + PTH$ + Clean$(varcode->Token$) + varcode->Proto$ = varcode->Proto$ + VAR$ + PT$ + CASE mt_OverLoad + varcode->Functype$ = VAR$ + " " + CASE mt_OverLoad2 + varcode->Header$ = varcode->Header$ + VAR$ + PTH$ + Clean$(varcode->Token$) + ", " + END SELECT + '************************************************************************ + CASE vt_UDT, vt_STRUCT, vt_UNION + '************************************************************************ + SELECT CASE varcode->Method% + CASE mt_ProcessSetCommand + IF vn = vt_UNION THEN + varcode->StaticOut$ = "static union " + Clean$(varcode->Token$) + ELSE + varcode->StaticOut$ = "static struct _" + Clean$(varcode->Token$) + " " + END IF + CASE mt_FuncSubDecC_Dec + varcode->Functype$ = varcode->AsToken$ + PTH$ + CB$ + CASE mt_FuncSubDecC_Dec2 + varcode->Header$ = varcode->Header$ + varcode->AsToken$ + PTH$ + Clean$(varcode->Token$) + ", " + varcode->Proto$ = varcode->Proto$ + varcode->AsToken$ + RF$ + PT$ + ", " + CASE mt_Opts + varcode->Functype$ = varcode->AsToken$ + PTH$ + CASE mt_Opts2 + varcode->Header$ = varcode->Header$ + Clean$(varcode->AsToken$) + PTH$ + " " + Clean$(varcode->Token$) + varcode->Proto$ = varcode->Proto$ + Clean$(varcode->AsToken$) + RF$ + PT$ + CASE mt_OverLoad + varcode->Functype$ = VAR$ + " " + CASE mt_OverLoad2 + varcode->Header$ = varcode->Header$ + varcode->AsToken$ + PTH$ + Clean$(varcode->Token$) + ", " + END SELECT + '************************************************************************ + CASE ELSE + '************************************************************************ + SELECT CASE varcode->Method% + CASE mt_FuncSubDecC_Dec + varcode->Functype$ = varcode->AsToken$ + PTH$ + CB$ + CASE mt_FuncSubDecC_Dec2 + varcode->Header$ = varcode->Header$ + varcode->AsToken$ + PTH$ + Clean$(varcode->Token$) + ", " + varcode->Proto$ = varcode->Proto$ + varcode->AsToken$ + RF$ + PT$ + ", " + CASE mt_Opts + varcode->Functype$ = varcode->AsToken$ + PTH$ + CASE mt_Opts2 + varcode->Header$ = varcode->Header$ + Clean$(varcode->AsToken$) + " " + Clean$(varcode->Token$) + varcode->Proto$ = varcode->Proto$ + Clean$(varcode->AsToken$) + END SELECT + END SELECT +END SUB ' GetVarCode +SUB AddProtos + DIM RAW SaveMain$ + DIM RAW ZZ$ + DIM RAW A + SaveMain$ = "" + OPEN FileOut$ FOR INPUT AS FP1 + OPEN "$t$e$m$p" FOR OUTPUT AS Outfile + WHILE NOT EOF(FP1) + LINE INPUT FP1,ZZ$ + IF INSTR(ZZ$,"int main") THEN + SaveMain$ = ZZ$ + EXIT LOOP + END IF + FPRINT Outfile, ZZ$ + WEND + +$INCLUDE "std_macros.bas" + + FPRINT Outfile,"" + +$INCLUDE "std_prototypes.bas" + + IF ProtoCnt THEN + FPRINT Outfile,"" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// " + $BCX_STR_USR_PROTOS + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"" + DIM RAW LastDef$ + DIM RAW LastLevel + LastDef$ = "" + LastLevel = 1 + FOR A = 1 TO ProtoCnt + IF LastDef$ = "" THEN + LastDef$ = ProtoType[A].Condition$ + LastLevel = ProtoType[A].CondLevel + IF Use_SingleFile = FALSE THEN + IF LastDef$ > "" THEN FPRINT fpHFile, LastDef$ + END IF + IF LastDef$ > "" THEN FPRINT Outfile, LastDef$ + END IF + IF LastDef$ <> ProtoType[A].Condition$ THEN + IF ProtoType[A].Condition$ = "#else" THEN + WHILE LastLevel > ProtoType[A].CondLevel + IF Use_SingleFile = FALSE THEN + FPRINT fpHFile, "#endif" + END IF + FPRINT Outfile,"#endif" + LastLevel-- + WEND + IF Use_SingleFile = FALSE THEN + FPRINT fpHFile, "#else" + END IF + FPRINT Outfile,"#else" + LastDef$ = ProtoType[A].Condition$ + LastLevel = ProtoType[A].CondLevel + ELSE + WHILE LastLevel > ProtoType[A].CondLevel + IF Use_SingleFile = FALSE THEN + FPRINT fpHFile, "#endif" + END IF + FPRINT Outfile,"#endif" + LastLevel-- + WEND + LastDef$ = ProtoType[A].Condition$ + LastLevel = ProtoType[A].CondLevel + IF Use_SingleFile = FALSE THEN + IF LastDef$ > "" THEN FPRINT fpHFile, LastDef$ + END IF + IF LastDef$ > "" THEN FPRINT Outfile, LastDef$ + END IF + END IF + IF UseStdCall AND UseCpp THEN + IF LEFT$(ProtoType[A].Prototype$, 9) = "C_EXPORT " THEN + EmitExportDef(ProtoType[A].Prototype$) + END IF + END IF + T$ = EXTRACT$(ProtoType[A].Prototype$, SPC$) + T$ = RPAD$(T$, 7) + SPC$ + ProtoType[A].Prototype$ = T$ + REMAIN$(ProtoType[A].Prototype$, SPC$) + IF Use_SingleFile = FALSE THEN + FPRINT fpHFile, ProtoType[A].Prototype$ + END IF + IF UseCpp=False AND NOT INSTR(ProtoType[A].Prototype$,"::") THEN + FPRINT Outfile,ProtoType[A].Prototype$ + END IF + 'print ProtoType[A].Prototype$ + NEXT A 'ProtoCnt + IF *LastDef$ THEN + WHILE LastLevel > 0 + IF Use_SingleFile = FALSE THEN + FPRINT fpHFile, "#endif" + END IF + FPRINT Outfile,"#endif" + LastLevel-- + WEND + END IF + END IF + FPRINT Outfile,"" + ' begin for initialized global arrays + DIM RAW P$, i + DIM RAW VarName$ + DIM RAW VarDim$ + DIM RAW Storage$ + DIM RAW VAR$ + IF GlobalVarCnt > 0 THEN + FPRINT Outfile,"" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// User Global Initialized Arrays" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"" + FOR i = 1 TO GlobalVarCnt + IF GlobalVars[i].VarEmitFlag THEN ITERATE + IF "" <> GlobalVars[i].VarDim$ AND GlobalVars[i].VarCondLevel = 0 THEN + IF INSTR(GlobalVars[i].VarDim,"{") THEN + P$ = "" + IF GlobalVars[i].VarPntr THEN P$ = STRING$(GlobalVars[i].VarPntr,42) + A = GlobalVars[i].VarType + IF GlobalVars[i].VarSF THEN + VarName$ = "(*" + GlobalVars[i].VarName$ + EXTRACT$(GlobalVars[i].VarDim,"(") + ")" + VarDim$ = MID$(GlobalVars[i].VarDim, INSTR(GlobalVars[i].VarDim,"(")) + ELSE + VarName$ = GlobalVars[i].VarName$ + VarDim$ = GlobalVars[i].VarDim + END IF + Storage$ = VarStorage$[GlobalVars[i].VarExtn] & VarConst$[GlobalVars[i].VarConstant] + SELECT CASE A + ' handle exceptions + CASE vt_STRVAR + FPRINT Outfile,Storage$;"char ";VarName$;VarDim$;";" + CASE vt_FILEPTR + REMOVE "@" FROM GlobalVars[i].VarName$ + FPRINT Outfile,Storage$;"FILE *";VarName$;VarDim$;";" + CASE vt_BOOL + FPRINT Outfile,Storage$;"bool ";VarName$;VarDim$;";" + ' handle normal + CASE vt_UDT, vt_STRUCT, vt_UNION + VAR$ = TypeDefs[GlobalVars[i].VarDef].VarName$ + VAR$ = RPAD$(VAR$, 7) + FPRINT Outfile,Storage$;VAR$;" ";P$;VarName$;VarDim$;";" + CASE vt_VarMin TO vt_VarMax + VAR$ = GetVarTypeName$(GlobalVars[i].VarType) + VAR$ = RPAD$(VAR$, 7) + FPRINT Outfile,Storage$;VAR$;" ";P$;VarName$;VarDim$;";" + END SELECT + END IF + END IF + NEXT + FPRINT Outfile,"" + END IF ' end of initialized global arrays + IF Use_Overloaded THEN + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// User's Overloaded Subs/Functions " + FPRINT Outfile,"// *************************************************" + OPEN ovrFile$ FOR INPUT AS FP8 + WHILE NOT EOF(FP8) + LINE INPUT FP8,ZZ$ + IF INSTR(ZZ$,"overloaded") THEN + FPRINT Outfile,"\n" + END IF + FPRINT Outfile,ZZ$ + WEND + CLOSE FP8 + FPRINT Outfile,"\n\n" + END IF + OPEN setFile$ FOR INPUT AS FP5 + IF LOF(setFile$) > 0 THEN + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// User GLOBAL SET Statements" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"" + WHILE NOT EOF(FP5) + LINE INPUT FP5,Z$ + FPRINT Outfile,Z$ + WEND + FPRINT Outfile,"" + END IF + CLOSE FP5 + IF Use_SingleFile = FALSE THEN + CLOSE fpHFile + END IF + IF NoMain = 0 THEN + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// " + $BCX_STR_MAIN_PROG + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"" + END IF + '********************************************************************** + IF NoMain = FALSE THEN + FPRINT Outfile,SaveMain$ ' add the >> void main() back to the stream + FPRINT Outfile,"{" ' AND OPEN the main FUNCTION + FPRINT Outfile," G_argc = argc;" + FPRINT Outfile," G_argv = argv;" + CALL BumpUp + END IF + '********************************************************************** + WHILE NOT EOF(FP1) + LINE INPUT FP1,ZZ$ + FPRINT Outfile,Scoot$,ZZ$ + WEND + IF Use_SingleFile = TRUE THEN + CALL RunTimeFunctions + END IF + FLUSH(Outfile) + CALL CloseAll + KILL FileOut$ + RENAME "$t$e$m$p", FileOut$ +END SUB ' AddProtos + +' ***** RUNTIME FUNCTIONS ***** +$INCLUDE "runtime.bas" +' ***************************** + +FUNCTION JoinLines(Arg$) + IF iMatchRgt(Arg$, " _") THEN + Arg[LEN(Arg)-1] = 0 + CurLine$ = CurLine$ & Arg$ + FUNCTION = 1 + END IF + IF *CurLine <> 0 THEN + Arg$ = CurLine$ & Arg$ + CurLine$ = "" + END IF + UmQt = FALSE + FUNCTION = 0 +END FUNCTION +SUB StripCode( Arg$ ) + RAW p AS PCHAR + RAW p2 = Arg AS PCHAR + RAW asmFlag = 0 + RAW eStr = 0 + RAW sub_$ + WHILE (*p2 >8 AND *p2 < 14) OR *p2 = 32 'Trim leading space + INCR p2 + WEND + IF *p2 = ASC("!") THEN asmFlag = NOT UmQt 'Handle "!" Asm lines + p = p2 + WHILE *p + IF *p = 9 THEN *p = 32 + IF *p = 34 THEN ' ignore anything in string literal + IF *(p-1) = 69 THEN ' we're in an extended string: E"\qABCD\n" + *(p-1) = 1 ' chr$(1) will be deleted + eStr = TRUE + END IF + WHILE *(++p) <> 34 + IF *p = 92 AND eStr THEN ' look for a \0, \t, \n, \r, \q, \\ + *p = 2 + SELECT CASE *(p+1) + CASE 48 + *(p+1) = 3 + CASE 116 + *(p+1) = 4 + CASE 110 + *(p+1) = 5 + CASE 114 + *(p+1) = 6 + CASE 113 + *(p+1) = 7 + CASE 92 + *(p+1) = 8 + END SELECT + p++ + END IF + IF *p = 0 THEN UmQt = NOT UmQt : EXIT WHILE + WEND + END IF + ' If we're in a quoted continuation line then ignore comments + IF NOT UmQt AND NOT asmFlag THEN + 'Remove REM's + IF (*p BOR 32) = ASC("r") THEN + IF _ + (*(p+1) BOR 32) = ASC("e") AND _ + (*(p+2) BOR 32) = ASC("m") AND _ + (*(p+3) = 32 OR *(p+3) = 0) THEN + IF p = p2 OR *(p-1) = ASC(":") OR *(p-1) = 32 THEN + *p = 0 : EXIT WHILE + END IF + END IF + END IF + ' check for single quote comment marker and //C++ style comments + IF *p = ASC("'") OR (*p = ASC("/") AND *(p+1) = ASC("/")) THEN + *p = 0 : EXIT WHILE + END IF + END IF + p++ + WEND + WHILE p2 < p + 'Trim trailing space + WHILE (*(p-1) >8 AND *(p-1) < 14) OR *(p-1) = 32 + *(--p) = 0 + WEND + IF UmQt OR asmFlag THEN EXIT WHILE + 'Strip dangling colons + IF *(p-1) = ASC(":") AND *(p-2) = 32 THEN + DECR p + ELSE + EXIT WHILE + END IF + WEND + IF eStr THEN + REPLACE CHR$(1) WITH "" IN p2$ ' E + REPLACE CHR$(2) WITH "" IN p2$ ' \ first backslash + '--- + sub_$ = DQ$+"+CHR$(0)+"+DQ$ + REPLACE CHR$(3) WITH sub_$ IN p2$ ' 0 + sub_$ = DQ$+"+CHR$(9)+"+DQ$ + REPLACE CHR$(4) WITH sub_$ IN p2$ ' t + sub_$ = DQ$+"+CHR$(10)+"+DQ$ + REPLACE CHR$(5) WITH sub_$ IN p2$ ' n + sub_$ = DQ$+"+CHR$(13)+"+DQ$ + REPLACE CHR$(6) WITH sub_$ IN p2$ ' r + sub_$ = DQ$+"+CHR$(34)+"+DQ$ + REPLACE CHR$(7) WITH sub_$ IN p2$ ' q + sub_$ = DQ$+"+CHR$(92)+"+DQ$ + REPLACE CHR$(8) WITH sub_$ IN p2$ ' \ + '--- + REPLACE (CHR$(34)+CHR$(34)+CHR$(43)) WITH "" IN p2$ + REPLACE (CHR$(43)+CHR$(34)+CHR$(34)) WITH "" IN p2$ + '--- + END IF + '/***** 2010/11/24 Changed to avoid overflow on 64bit Ubuntu -AIR *****/ + ' Arg$ = p2$ + memcpy(Arg$, p2$, LEN(p2$)+1) +END SUB + +SUB ProcSingleLineIf(BYREF ifFlag) + DIM RAW Tmp$, ifp, NdIfs + DIM STATIC EFlag + IF ifFlag = 0 THEN EFlag = 0 + REDO: + IF SplitCnt > 120 THEN Abort("Stack Overflow - Too many statements on one line") + Tmp$ = SplitStk$[SplitCnt] & SPC$ + IF iMatchLft(Tmp$, "if ") THEN + ifp = iMatchNQ(Tmp$, " then ") + IF ifp THEN + SplitStk$[SplitCnt++] = LEFT$(Tmp$,ifp+4) + SplitStk$[SplitCnt] = LTRIM$(Tmp+ifp+4) + EFlag = MAX(0,EFlag-1) : INCR (ifFlag) + GOTO REDO + END IF + ELSEIF (ifFlag) THEN + IF iMatchLft(Tmp$, "else ") THEN '"else xxx" + LftLse: + IF ++EFlag > 1 THEN + NdIfs = MAX(1,(ifFlag)-1) : (ifFlag) = 1 : EFlag = 0 + IF iMatchWrd(SplitStk$[SplitCnt-1],"else") THEN DECR SplitCnt + REPEAT NdIfs : SplitStk$[SplitCnt++] = "END IF" : END REPEAT + END IF + SplitStk$[SplitCnt++] = "ELSE" + SplitStk$[SplitCnt] = TRIM$(Tmp+4) + GOTO REDO + ELSE + ifp = iMatchNQ(Tmp$, " else ") + IF ifp THEN '"xxx else xxx" + SplitStk$[SplitCnt++] = RTRIM$(LEFT$(Tmp$, ifp-1)) + Tmp$ = MID$(Tmp$, ifp+1) + GOTO LftLse + END IF + END IF + END IF 'process "if/then/else" +END SUB + +'Split statements separated by a colon or a single line IF...THEN +FUNCTION SplitLines(Arg$) + DIM RAW p = Arg AS PCHAR + DIM RAW st = Arg AS PCHAR + DIM RAW i = 0, IfFlag = 0, SpcolonFlag = 0 + DIM RAW ParaCnt = 0 + IF *p = ASC("!") OR *p = ASC("$") THEN EXIT FUNCTION + WHILE *p + IF *p = 32 THEN SpcolonFlag = 1 + IF *p = 34 THEN ' ignore anything in string literal + WHILE *(++p) <> 34 + IF *p = 0 THEN FUNCTION = SplitCnt + WEND + END IF + IF *p = 40 THEN ParaCnt++ + IF *p = 41 THEN ParaCnt-- + IF *p = ASC(":") AND *(p+1) <> ASC("=") THEN + '--------- BEGIN INSERT ---------------- + IF *(p+1) = ASC(":") THEN + *p = -15 + *(p+1) = -15 + '--------- END INSERT ---------------- + ELSE + IF *(p+1) <> 0 OR SpcolonFlag THEN + WHILE *st = 32 + st++ + WEND 'Forward past leading spaces + SplitCnt++ + WHILE st < p 'Copy new string + SplitStk[SplitCnt][i++] = *(st++) + WEND + WHILE SplitStk[SplitCnt][i-1] = 32 'Trim trailing spaces + i-- + WEND + SplitStk[SplitCnt][i] = 0 'Add a string terminator + IF ParaCnt = 0 THEN + i=0 + st++ 'advance to next start position + ProcSingleLineIf(&IfFlag) + ELSE + SplitCnt-- + END IF + END IF 'if NOT End of line + END IF + END IF 'if : + p++ + WEND + 'Add the last string + IF SplitCnt > 0 THEN + WHILE *st = 32 + st++ + WEND 'Forward past leading spaces + SplitCnt++ + WHILE *st + SplitStk[SplitCnt][i++] = *(st++) + WEND + SplitStk[SplitCnt][i] = 0 + ProcSingleLineIf(&IfFlag) + 'Process single line if/thens that don't contain colon separated statements + ELSEIF iMatchLft(Arg$,"if ") AND NOT iMatchRgt(Arg$," then") THEN + SplitStk$[++SplitCnt] = Arg$ + ProcSingleLineIf(&IfFlag) + END IF + 'If we processed single line "if/then" then close it up + IF IfFlag THEN + WHILE IfFlag + SplitStk$[++SplitCnt] = "END IF" + IfFlag-- + WEND + END IF + FUNCTION = SplitCnt +END FUNCTION +'---------------------------------------------- +'Case insensitive comparison - MatchStr$ to Arg$ +' mt = 0, 1 or 2 Match left, whole word, right +'---------------------------------------------- +CONST iMatchLft(A,B) = iMatch(A,B,0) +CONST iMatchWrd(A,B) = iMatch(A,B,1) +CONST iMatchRgt(A,B) = iMatch(A,B,2) +FUNCTION iMatch(Arg$, MatchStr$, mt) + IF mt = 2 THEN + DIM RAW L1, L2 + L1 = LEN(Arg$) : L2 = LEN(MatchStr$) + IF L1 < L2 THEN EXIT FUNCTION + Arg = (Arg + L1) - L2 + END IF + WHILE *MatchStr + 'If we run out string to match against then return no match + IF *Arg = 0 THEN EXIT FUNCTION + 'bit ORing a character with 0x20 produces the lower case of it + IF (*Arg BOR 32) <> (*MatchStr BOR 32) THEN EXIT FUNCTION + INCR Arg + INCR MatchStr + WEND + IF mt AND *Arg <> 0 THEN EXIT FUNCTION + FUNCTION = 1 +END FUNCTION +'---------------------------------------------- +'Returns the position of the first occurrence +'of MatchStr$ in Arg$ that isn't in quotes. +'---------------------------------------------- +FUNCTION iMatchNQ(Arg$, MatchStr$) + DIM RAW mi=0 + DIM RAW a = Arg AS PCHAR + WHILE MatchStr[mi] + IF *a = 34 THEN + mi=0 + WHILE *(++a) <> 34 + IF *a = 0 THEN EXIT FUNCTION + WEND + END IF + IF a[mi] = 0 THEN EXIT FUNCTION + 'If we run out string to match against then return no match + 'bit ORing a character with 0x20 produces the lower case of it + IF (a[mi] BOR 32) <> (MatchStr[mi] BOR 32) THEN + INCR a : mi= -1 + END IF + INCR mi + WEND + FUNCTION = (a-Arg) + 1 ' We have a match +END FUNCTION + +FUNCTION SpecialCaseHandler(Arg$) + DIM RAW i,j + DIM RAW lsz$ + IF iMatchNQ(Arg$," sub ") OR iMatchNQ(Arg$," function ") THEN EXIT FUNCTION + IF iMatchNQ(Arg$,"function main(") THEN + SrcStk$[++SrcCnt] = Arg$ + SrcStk$[++SrcCnt] = "G_argc = argc" + SrcStk$[++SrcCnt] = "G_argv = argv" + GOTO ProcessNew + END IF + '************************************************** + ' Handle Multiple Dim's, Locals, Globals, Shared's + ' Example: DIM a, b!, c$, d$*1000, q[100] AS DWORD + '************************************************** + lsz$ = SPC$ & EXTRACT$(Arg$," ") & SPC$ + IF iMatchNQ(" dim , local , global , raw , static , shared , dynamic , auto , register , extern ", lsz$) THEN + CALL FastLexer(Arg$," ",",(){}") + ' tolerate nonsense like DIM A% as double + FOR i = 1 TO Ndx + IF iMatchWrd(Stk$[i],"as") THEN + Stk$[i-1] = Clean$(Stk$[i-1]) + END IF + NEXT + Stk$[2] = SPC$ & Stk$[2] & SPC$ + IF iMatchNQ(" raw local dynamic register static shared auto ",Stk$[2]) THEN + Stk$[1] = Stk$[1] & Stk$[2] + Stk$[2] = "" + END IF + INCR SrcCnt + j=0 + FOR i = 1 TO Ndx + IF Stk[i][0] = ASC("(") THEN INCR j + IF Stk[i][0] = ASC("{") THEN INCR j + IF Stk[i][0] = ASC(")") THEN DECR j + IF Stk[i][0] = ASC("}") THEN DECR j + IF Stk[i][0] = ASC(",") AND NOT j THEN + Stk$[i] = Stk$[1] + INCR SrcCnt + END IF + SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + Stk$[i] + " " + NEXT + GOTO ProcessNew + END IF + + SELECT CASE TRUE + '****************************** + CASE iMatchLft(Arg$,"on ") + '****************************** + DIM RAW Target + j = 0 + CALL FastLexer(Arg$," ",",") + FOR i = 1 TO Ndx + IF iMatchLft(Stk$[i],"gosub") OR _ + iMatchLft(Stk$[i],"goto") OR _ + iMatchLft(Stk$[i],"call") THEN + Target = i+1 + EXIT FOR + END IF + NEXT + SrcStk$[++SrcCnt] = "select case " 'Assemble our expression + FOR i = 2 TO Target - 2 + SrcStk$[SrcCnt] = SrcStk$[SrcCnt]+" "+ Stk$[i] + NEXT + FOR i = Target TO Ndx + IF Stk$[i] = "," THEN ITERATE + INCR j + SrcStk$[++SrcCnt] = "case" + STR$(j) + SrcStk$[++SrcCnt] = Stk$[Target-1] + " " + Stk$[i] + NEXT + SrcStk$[++SrcCnt] = "end select" + GOTO ProcessNew + '****************************** + CASE iMatchLft(Arg$,"loop ") + '****************************** + CALL FastLexer(Arg$," ",",()") + IF iMatchLft(Stk$[2],"until") THEN + SrcStk$[++SrcCnt] = "if " + FOR i = 3 TO Ndx + SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + Stk$[i] + " " + NEXT + SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + " then" + SrcStk$[++SrcCnt] = "exit loop" + SrcStk$[++SrcCnt] = "end if" + SrcStk$[++SrcCnt] = "loop" + GOTO ProcessNew + ELSEIF iMatchLft(Stk$[2],"while") THEN + SrcStk$[++SrcCnt] = "if NOT (" + FOR i = 3 TO Ndx + SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + Stk$[i] + " " + NEXT + SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + ") then" + SrcStk$[++SrcCnt] = "exit loop" + SrcStk$[++SrcCnt] = "end if" + SrcStk$[++SrcCnt] = "loop" + GOTO ProcessNew + ELSE + IF Ndx > 1 THEN + Abort("UNKNOWN Word " + Stk$[2] + " After LOOP") + END IF + END IF + '****************************** + CASE iMatchLft(Arg$,"do ") + '****************************** + CALL FastLexer(Arg$," ",",()") + IF iMatchLft(Stk$[2],"until") THEN + SrcStk$[++SrcCnt] = "do" + SrcStk$[++SrcCnt] = "if " + FOR i = 3 TO Ndx + SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + Stk$[i] + " " + NEXT + SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + "then" + SrcStk$[++SrcCnt] = "exit loop" + SrcStk$[++SrcCnt] = "end if" + GOTO ProcessNew + ELSEIF iMatchLft(Stk$[2],"while") THEN + SrcStk$[++SrcCnt] = "while " + FOR i = 3 TO Ndx + SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + Stk$[i] + " " + NEXT + GOTO ProcessNew + ELSE + IF Ndx > 1 THEN + Abort("UNKNOWN Word " + Stk$[2] + " After DO") + END IF + END IF + END SELECT + EXIT FUNCTION + ProcessNew: + Ndx = i = 0 + WHILE SrcCnt + Arg$ = SrcStk$[++i] + SrcStk$[i] = "" + DECR SrcCnt + CALL Parse(Arg$) + IF Ndx THEN CALL Emit + WEND + FUNCTION = TRUE +END FUNCTION +'************************************************************* +'delim1$ = delimiters to be removed +'delim2$ = delimiters to keep +'Stk$ and Ndx are Global +'As long as Ndx is honored Stk does not need to be initialized +'************************************************************* +SUB FastLexer OPTIONAL(Arg$, delim1$, delim2$, TokQuote = 1) + DIM RAW cnt1=0, cnt2=0 + DIM RAW pd1 AS PCHAR, pd2 AS PCHAR + Ndx=1 + WHILE Arg[cnt1] + IF Arg[cnt1] = 34 THEN 'quotes - string literals + IF cnt2 AND TokQuote THEN Stk[Ndx++][cnt2]=0 : cnt2=0 + Stk[Ndx][cnt2] = 34 + WHILE Arg[++cnt1] <> 34 + Stk[Ndx][++cnt2] = Arg[cnt1] + IF Arg[cnt1] = 0 THEN EXIT SUB + WEND + Stk[Ndx][++cnt2] = Arg[cnt1] + IF TokQuote THEN + Stk[Ndx++][++cnt2]=0 + cnt2=0 + GOTO again + END IF + END IF + pd1 = delim1 + WHILE *pd1 + IF *(pd1++) = Arg[cnt1] THEN + IF cnt2 THEN Stk[Ndx++][cnt2]=0 : cnt2=0 + GOTO again + END IF + WEND + pd2 = delim2 + WHILE *pd2 + IF *(pd2++) = Arg[cnt1] THEN + IF cnt2 THEN Stk[Ndx++][cnt2]=0 + Stk[Ndx][0] = Arg[cnt1] + Stk[Ndx++][1]=0 : cnt2 = 0 + GOTO again + END IF + WEND + Stk[Ndx][cnt2++]=Arg[cnt1] + again: + INCR cnt1 + WEND + Stk[Ndx][cnt2]=0 + IF cnt2 = 0 THEN DECR Ndx +END SUB + +SUB InsertTokens(PosAfter, NumTokens, ...) + DIM RAW ap AS va_list, i + FOR i = Ndx TO PosAfter+1 STEP -1 + Stk$[i+NumTokens] = Stk$[i] + NEXT i + va_start(ap,NumTokens) + FOR i = PosAfter+1 TO PosAfter+NumTokens + Stk$[i] = va_arg(ap, char*) + NEXT i + va_end(ap) + INCR Ndx,NumTokens +END SUB + +SUB EmitExportDef(fs$) + STATIC beenhere + DIM RAW fname$, funcname$ + DIM RAW i, st=1, sz=0 + fname$ = EXTRACT$(FileIn$,".") + ".def" + IF NOT beenhere THEN + OPEN fname$ FOR OUTPUT AS fpdef + _splitpath_(FileIn$, NULL, NULL, fname$, NULL) + FPRINT fpdef,"LIBRARY ", ENC$(fname$) + FPRINT fpdef, "EXPORTS" + beenhere = TRUE + END IF + FastLexer(fs$, "", "(,)") + WHILE *Stk$[st] <> ASC("(") + INCR st + WEND + FOR i = st+1 TO Ndx + IF *Stk$[i] = ASC(")") THEN EXIT + IF *Stk$[i] <> ASC(",") THEN + IF INCHR(Stk$[i],"*") THEN INCR sz,4 : ITERATE + IF INSTR(Stk$[i],"longlong",1,1) OR _ + INSTR(Stk$[i],"double",1,1) OR _ + INSTR(Stk$[i],"long long") THEN + INCR sz,8 + ITERATE + END IF + IF NOT INCHR(Stk$[i],"void") THEN INCR sz,4 + END IF + NEXT + Stk$[1] = TRIM$(Stk$[1]) + funcname$ = MID$(Stk$[1],INSTRREV(Stk$[1]," ") + 1) + FPRINT fpdef,funcname$," = _",funcname$,"@",LTRIM$(STR$(sz)) + 'CloseAll is called at the end of AddProtos +END SUB + +FUNCTION GetArg$(ArgNum, fp AS functionParse PTR) + DIM RAW RetArg$ + DIM RAW ArgEnd = fp->CommaPos[ArgNum] - 1 + DIM RAW ArgStart = fp->CommaPos[ArgNum - 1] + 1 + RetArg$ = "" + IF ArgNum >= fp->NumArgs THEN ArgEnd = Ndx + FOR ArgStart = ArgStart TO ArgEnd + CONCAT(RetArg$, Stk$[ArgStart]) + NEXT ArgStart + FUNCTION = RetArg$ +END FUNCTION + +FUNCTION SepFuncArgs(Strt, fp AS functionParse PTR, functionflag AS INTEGER) + DIM RAW CountR = 0 '()[] counter + DIM RAW i = Strt 'loop counter + IF functionflag THEN + WHILE i <= Ndx + IF Stk[i][0] = ASC("(") THEN EXIT WHILE + INCR i + WEND + Strt = i + 1 + fp->NumArgs = 0 'comma counter + fp->CommaPos[0] = i 'Strt-1 + IF Strt > Ndx THEN + FUNCTION = 0 + END IF + ELSE + Strt = 2 + fp->CommaPos[0] = 1 + END IF + IF *Stk$[Strt] = ASC(")") THEN + fp->CommaPos[1] = Strt + FUNCTION = 0 + END IF + fp->NumArgs = 1 + FOR i = Strt TO Ndx + IF *Stk$[i] = ASC("(") OR *Stk$[i] = ASC("[") THEN + CountR++ + ELSEIF *Stk$[i] = ASC(")") OR *Stk$[i] = ASC("]") THEN + IF CountR = 0 THEN + fp->CommaPos[fp->NumArgs] = i + EXIT FOR + END IF + CountR-- + ELSEIF *Stk$[i] = ASC(",") AND CountR = 0 THEN + fp->CommaPos[fp->NumArgs] = i + INCR fp->NumArgs + END IF + NEXT + IF functionflag = 0 THEN fp->CommaPos[fp->NumArgs] = Ndx + FUNCTION = fp->NumArgs 'Number of commas + 1 = Number of arguments +END FUNCTION ' SepFuncArgs + +FUNCTION MakeDecProto(fp AS functionParse PTR) AS PCHAR + DIM RAW fpp AS functionParse + DIM RAW FunType$ + DIM RAW AsType$ + DIM RAW AsArrys$ + DIM RAW FoundAs + DIM RAW pointer = 0 + DIM RAW i,ii + DIM RAW OptValue$ + DIM RAW OptFlag = 0 + STATIC Proto$ + STATIC SubFunPtr + IF SubFunPtr THEN GOTO argparse + Proto$ = "" + FunType$ = "" + 'Determine function type + '----------------------------------------------------- + + '/***** 2010-11-15 Added check for constructor/destructor -AIR + IF iMatchWrd(Stk$[2], "sub") OR iMatchWrd(Stk$[2], "constructor") OR iMatchWrd(Stk$[2], "destructor") THEN + FunType$ = "void" + ELSEIF *Stk$[Ndx] = ASC(")") THEN + 'check for type identifier suffix + 'if unknown, then integer will default + FunType$ = VarTypeLookup$[ INCHR(VarTypes$, RIGHT$(Stk$[3],1)) ] + ELSE + FOR i = Ndx TO fp->CommaPos[fp->NumArgs]+1 STEP -1 + IF iMatchWrd(Stk$[i], "ptr") THEN + INCR pointer + ELSEIF iMatchWrd(Stk$[i], "as") THEN + EXIT FOR + ELSE + FunType$ = Stk$[i] + SPC$ + FunType$ + END IF + NEXT + END IF + 'INCR pointer, TALLY(FunType$, "*") + 'RemoveAll(FunType$, "*", 1) + IF InTypeDef THEN + '/***** 2010-11-15 Added code for constructor/destructor WITHIN CLASS DECLARATION *****/ + '/***** also changed Proto$ to get rid of (__atribute__cdecl)(*variable) -AIR *****/ + ' Proto$ = FunType$ + " " + STRING$(pointer, ASC("*")) + " (" + CallType$ + "*" + Clean$(Stk$[3]) + ")(" + IF iMatchWrd(Stk$[2], "constructor") THEN + Proto$ = Clean$(Stk$[3]) + "(" + ELSEIF iMatchWrd(Stk$[2], "destructor") THEN + Proto$ = "~" + Clean$(Stk$[3]) + "(" + ELSE + Proto$ = FunType$ + " " + Clean$(Stk$[3]) + "(" + END IF + + + DIM RAW Var$, w, id, vt + Var$ = FunType$ + STRING$(pointer, ASC("*")) + GetTypeInfo(Var$, &w, &id, &vt) + AddTypedefElement(BaseTypeDefsCnt[InTypeDef],vt, Clean$(Stk$[3]), FunType$, 0) + ELSEIF SFPOINTER THEN + Proto$ = "typedef " + FunType$ + " (" + CallType$ + "*" + Clean$(Stk$[3]) + "_TYPE)(" + ELSEIF NOT NoTypeDeclare THEN + Proto$ = "typedef " + FunType$ + " (" + CallType$ + "*BCXFPROT" + LTRIM$(STR$(DllCnt)) + ")(" + ELSE + IF UseCProto THEN + UseCProto = FALSE + Proto$ = FunType$ + " " + STRING$(pointer, ASC("*")) + SPC$ + CallType$ + Clean$(Stk$[3]) + "(" + ELSE + Proto$ = "C_IMPORT " + FunType$ + " " + STRING$(pointer, ASC("*")) + SPC$ + CallType$ + Clean$(Stk$[3]) + "(" + END IF + END IF + '----------------------------------------------------- + argparse: + '----------------------------------------------------- + 'Determine argument types + '----------------------------------------------------- + IF fp->NumArgs = 0 THEN + '/***** 2010-11-15 Added code for constructor/destructor to remove VOID in CLASS DECLARATION -AIR *****/ + '/***** 2010-12-01 Added Use_VirtualUse_Virtual to support Abstract Classes -AIR *****/ + IF iMatchWrd(Stk$[2], "destructor") OR iMatchWrd(Stk$[2], "constructor") OR Use_Virtual THEN + Proto$ = Proto$ + ")" + ELSE + Proto$ = Proto$ + "void)" + END IF + ELSE + FOR ii = 0 TO fp->NumArgs - 1 + OptValue$ = "" + AsType$ = "" + AsArrys$ = "" + pointer = 0 + FoundAs = 0 + DIM RAW FirstToken = fp->CommaPos[ii] + 1 + DIM RAW LastToken = fp->CommaPos[ii+1] - 1 + DIM RAW NumOfTokens = (LastToken - FirstToken) + 1 + i = INCHR(Stk$[FirstToken], "[") + IF i THEN + AsArrys$ = MID$(Stk$[FirstToken], i) + Stk[FirstToken][i-1] = 0 + END IF + IF NumOfTokens = 1 THEN + '-------------------------------------------------------- + ' The bracket handling should be handled better. + ' currently using the preprocessing of FunSubDecs1 + ' which converts A![] to *A! and A$[] to *A$[][2048] + ' and A[] as xxx to A as xxx* + '-------------------------------------------------------- + AsType$ = VarTypeLookup$[ INCHR(VarTypes$, RIGHT$(Stk$[FirstToken],1)) ] + IF *AsArrys$ THEN + REMOVE "*" FROM AsType$ + ELSE + pointer = TALLY(Stk$[FirstToken], "*") + END IF + '-------------------------------------------------------- + FoundAs = TRUE + ELSE + FOR i = LastToken TO FirstToken STEP -1 + IF iMatchWrd(Stk$[i], "ptr") OR *Stk$[i] = ASC("*") THEN + INCR pointer + ELSEIF iMatchWrd(Stk$[i], "sub") THEN + SepFuncArgs(fp->CommaPos[ii]+2, &fpp, TRUE) + Proto$ = Proto$ + "void (*)(" + SubFunPtr = FoundAs = TRUE + MakeDecProto(&fpp) + SubFunPtr = FALSE + EXIT FOR + ELSEIF iMatchWrd(Stk$[i], "function") THEN + SepFuncArgs(fp->CommaPos[ii]+2, &fpp, TRUE) + IF AsType$ = "" THEN + AsType$ = VarTypeLookup$[ INCHR( VarTypes$, RIGHT$(Stk$[FirstToken],1)) ] + END IF + Proto$ = Proto$ + RTRIM$(AsType$) + STRING$(pointer,ASC("*")) + " (*)(" + pointer = 0 + AsType$ = "" + SubFunPtr = FoundAs = TRUE + MakeDecProto(&fpp) + SubFunPtr = FALSE + EXIT FOR + ELSEIF iMatchWrd(Stk$[i], "as") THEN + IF AsType$ = "" THEN Abort("No type specified for argument" + STR$(ii+1)) + FoundAs = TRUE + EXIT FOR + ELSEIF *Stk$[i] = ASC("=") THEN + OptFlag = FoundAs = TRUE + OptValue$ = " =" + AsType$ + AsType$ = "" + IF i = FirstToken + 1 THEN + AsType$ = VarTypeLookup$[ INCHR( VarTypes$, RIGHT$(Stk$[FirstToken],1)) ] + IF *AsArrys$ THEN + REMOVE "*" FROM AsType$ + ELSE + pointer = TALLY(Stk$[FirstToken], "*") + END IF + EXIT FOR + END IF + ELSE + IF *Stk$[i] <> ASC(".") THEN + AsType$ = Stk$[i] + SPC$ + AsType$ + ELSE + IF *Stk$[i-1] = ASC(".") THEN + IF OptFlag THEN Abort("Default value not allowed when using variable arguments") + IF ii <> (fp->NumArgs-1) THEN Abort("Variable argument must be the last parameter") + IF fp->NumArgs = 1 THEN Abort("Variable argument must be preceded by at least one other parameter") + FoundAs = TRUE + END IF + AsType$ = Stk$[i] + AsType$ + END IF + END IF + NEXT i + END IF + IF NOT FoundAs THEN Abort("Malformed argument type in parameter" + STR$(ii + 1)) + IF ii <> fp->NumArgs AND OptFlag AND OptValue$ = "" THEN Warning("No default value specified for parameter" + STR$(ii + 1), 1) + Proto$ = Proto$ + RTRIM$(AsType$) + AsArrys$ + STRING$(pointer,ASC("*")) + OptValue$ + Stk$[fp->CommaPos[ii+1]] + NEXT ii + '----------------------------------------------------- + END IF + FUNCTION = Proto +END SUB + +SUB AsmUnknownStructs(CompArrays) + DIM RAW InBrace = 0 + DIM RAW InStruct = 0, i + DIM RAW sztemp$ + FOR i = 2 TO Ndx + ' -------------------------------- + ' Complete arrays + ' -------------------------------- + IF CompArrays THEN + IF Stk$[i] = "[" THEN + sztemp$ = Stk$[i-1] : Stk$[i-1] = "" + DO + sztemp$ = sztemp$ + Stk[i] + IF Stk$[i] = "]" THEN DECR InBrace + IF Stk$[i] = "[" THEN INCR InBrace + Stk$[i] = "" + INCR i + LOOP WHILE InBrace AND i <= Ndx + Stk$[--i] = sztemp$ + END IF + END IF + ' -------------------------------- + ' Complete unknown struct members + ' -------------------------------- + IF LEN(Stk$[i]) > 1 AND NOT IsNumber(Stk$[i]+1) THEN + IF *Stk$[i] = ASC(".") OR iMatchLft(Stk$[i], "->") THEN + IF InStruct = 0 THEN + Stk$[i] = Stk$[i-1] + Stk$[i] + Stk$[i-1] = "" + InStruct = i + ELSE + CONCAT(Stk$[InStruct], Stk$[i]) + Stk$[i] = "" + END IF + ITERATE + END IF + END IF + IF *Stk$[i] AND InStruct > 0 THEN + '? STR$(ModuleLineNos[ModuleNdx]), Stk$[InStruct] , STR$(CompArrays) + InStruct = 0 + END IF + NEXT i + CALL RemEmptyTokens +END SUB + +SUB EmitIfCond(CondType$) + '********************************************************************* + ' Speedup/Optimize for statements like ---> if a$ = "" THEN + ' AND ---> if a$[1] = "" THEN + '********************************************************************* + DIM RAW TestString, A, B, ParCnt, Tmp + DIM RAW IsWhile = FALSE + DIM RAW szTest$ + TestString = DataType(Stk$[2]) + IF TestString = vt_STRVAR THEN + IF Stk$[4] = DDQ$ THEN + Stk$[2] = Clean$(Stk$[2]) + "[0]" + Stk$[4] = "0" + ELSEIF Stk$[3] = "[" AND Stk$[7] = DDQ$ THEN + Stk$[2] = Clean$(Stk$[2]) + CONCAT (Stk$[5],"[0]") + Stk$[7] = "0" + END IF + END IF + IF CondType$ = "while" THEN IsWhile = TRUE + '******************** If, ElseIf, & While Handler ********************* + FPRINT Outfile, Scoot$, CondType$, "("; + Tmp = 2 + WHILE Stk$[Tmp] = "(" OR Stk$[Tmp] = "!" + FPRINT Outfile, Stk$[Tmp]; + Tmp++ + WEND + TestString = FALSE + A = DataType(Stk$[Tmp]) + IF A = vt_STRLIT OR A = vt_STRVAR THEN + IF Stk$[Tmp + 1] <> ")" AND NOT iMatchWrd(Stk$[Tmp+1], "then") THEN + TestString = TRUE + Use_Str_Cmp = TRUE + FPRINT Outfile, "str_cmp("; + END IF + END IF + szTest$ = "" + ParCnt = 0 + DO + IF TestString THEN + IF Stk$[Tmp] = "=" THEN + Stk$[Tmp] = "," + szTest$ = ")==0" + ParCnt = 0 + ELSEIF Stk$[Tmp] = "!=" THEN + Stk$[Tmp] = "," + szTest$ = ")!=0" + ParCnt = 0 + ELSEIF Stk$[Tmp] = ">" THEN + IF Stk$[Tmp + 1] = "=" THEN + Stk$[Tmp] = "," + szTest$ = ")>=0" + Stk$[Tmp + 1] = "" + ELSE + Stk$[Tmp] = "," + szTest$ = ")==1" + END IF + ParCnt = 0 + ELSEIF Stk$[Tmp] = "<" THEN + IF Stk$[Tmp + 1] = "=" THEN + Stk$[Tmp] = "," + szTest$ = ")<=0" + Stk$[Tmp + 1] = "" + ELSE + Stk$[Tmp] = "," + szTest$ = ")==-1" + END IF + ParCnt = 0 + ELSEIF Stk$[Tmp] = "(" THEN + ParCnt++ + ELSEIF Stk$[Tmp] = ")" THEN + ParCnt-- + END IF + IF Stk$[Tmp] = ")" AND szTest$ <> "" AND ParCnt < 0 THEN + FPRINT Outfile, szTest$, Stk$[Tmp]; + szTest$ = "" + ELSE + IF Stk$[Tmp] = "||" OR Stk$[Tmp] = "&&" THEN + Stk$[Tmp] = szTest$ + " " + Stk$[Tmp] + " " + szTest$ = "" + B = 1 + WHILE Stk$[Tmp + B] = "(" + CONCAT (Stk$[Tmp],"(") + Stk$[Tmp + B] = "" + B++ + WEND + A = DataType(Stk$[Tmp+B]) ' look ahead + IF (A = vt_STRLIT OR A = vt_STRVAR) AND Stk$[Tmp+B+1] <> ")" THEN + CONCAT (Stk$[Tmp]," str_cmp(") + Use_Str_Cmp = TRUE + ELSE + FPRINT Outfile,Clean$(Stk$[Tmp]); + TestString = FALSE + GOTO NxtToken + END IF + END IF + FPRINT Outfile, Clean$(Stk$[Tmp]); + END IF + ELSE 'Not TestString + IF Stk$[Tmp] = "||" OR Stk$[Tmp] = "&&" THEN + B = 1 + WHILE Stk$[Tmp + B] = "(" + CONCAT (Stk$[Tmp], "(") + Stk$[Tmp + B] = "" + B++ + WEND + A = DataType(Stk$[Tmp+B]) ' look ahead + IF (A = vt_STRLIT OR A = vt_STRVAR) AND Stk$[Tmp+B+1] <> ")" THEN + CONCAT (Stk$[Tmp],"str_cmp(" ) + TestString = TRUE + Use_Str_Cmp = TRUE + szTest$ = "" + ParCnt = 0 + FPRINT Outfile, Clean$(Stk$[Tmp]); + GOTO NxtToken + END IF + END IF + IF Stk$[Tmp]= "!" THEN + FPRINT Outfile,Stk$[Tmp]; + ELSE + FPRINT Outfile,Clean$(Stk$[Tmp]); + END IF + IF Stk$[Tmp] = "=" THEN + IF Stk$[Tmp-1] <> "<" AND Stk$[Tmp-1] <> ">" THEN + IF Stk$[Tmp+1] <> ">" AND Stk$[Tmp+1] <> "<" THEN + FPRINT Outfile,"="; + END IF + END IF + END IF + END IF + NxtToken: + INCR Tmp + IF NOT IsWhile THEN + IF iMatchWrd(Stk$[Tmp], "then") THEN + EXIT LOOP + ELSEIF Tmp > Ndx THEN + Abort("If Without THEN") + END IF + END IF + LOOP UNTIL Tmp > Ndx + FPRINT Outfile, szTest$, ")" + CALL BumpUp + FPRINT Outfile, Scoot$, "{" + CALL BumpUp +END SUB + +SUB PrintGlobal(A, idx, Storage$, P$, VarName$, VarDim$) + DIM RAW VAR$ + SELECT CASE A + ' handle exceptions + CASE vt_FILEPTR + REMOVE "@" FROM VarName$ + FPRINT Outfile,Storage$;"FILE *";P$;VarName$;VarDim$;";" + CASE vt_UDT, vt_STRUCT, vt_UNION + VAR$ = TypeDefs[GlobalVars[idx].VarDef].VarName$ + VAR$ = RPAD$(VAR$, 7) + FPRINT Outfile,Storage$;VAR$;" ";P$;VarName$;VarDim$;";" + CASE vt_BOOL + FPRINT Outfile,Storage$;"bool ";VarName$;VarDim$;";" + CASE vt_STRVAR + IF VarDim$ = "" THEN VarDim$ = "[65535]" + FPRINT Outfile,Storage$;"char ";P$;VarName$;VarDim$;";" + ' handle normal + CASE vt_VarMin TO vt_VarMax + VAR$ = GetVarTypeName$(GlobalVars[idx].VarType) + VAR$ = RPAD$(VAR$, 7) + FPRINT Outfile,Storage$;VAR$;" ";P$;VarName$;VarDim$;";" + END SELECT +END SUB + +SUB ReDirectFPrint(TgtFile@, pat$, ...) 'Used primarily to bump gLinesWritten + DIM RAW ap AS va_list + IF DoCountLines AND TgtFile = FP3 THEN + INCR gLinesWritten + END IF + va_start(ap, pat$) + vfprintf(TgtFile, pat$, ap) + va_end(ap) +END SUB + +SET ReservedWord[] AS CHAR PTR + "IF", + "ELSEIF", + "THEN", + "ELSE", + "AND", + "OR", + "NOT", + "BOR", + "BAND", + "XOR", + "" +END SET + +FUNCTION IsReservedWord(match$) + DIM RAW mat$ + mat$ = UCASE$(match$) + IF CONTAINEDIN(mat$,ReservedWord) = 0 THEN FUNCTION = 1 + FUNCTION = 0 +END FUNCTION + +FUNCTION GetAsPos() + RAW i + FOR i = Ndx TO 2 STEP -1 + IF iMatchWrd(Stk$[i],"as") THEN + FUNCTION = i + END IF + NEXT + FUNCTION = 0 +END FUNCTION ' GetAsPos diff --git a/mbc4.cc b/mbc4.cc new file mode 100644 index 0000000..c276940 --- /dev/null +++ b/mbc4.cc @@ -0,0 +1,20603 @@ +// ********************************************************************* +// Created with MBC (V) 4.0-Beta3 (2018/12/09)Ported to OSX by Armando Rivera +// Ported from BCX32 BASIC To C/C++ Translator (V) 5.12 +// BCX (c) 1999 - 2018 by Kevin Diggins +// LinuxBC (c) 2009 by Mike Henning +// MBC (c) 2009 - 2018 by Armando Rivera +// ********************************************************************* +// Translated for compiling with the g++ Compiler +// g++ -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$.cc -ldl -o $FILE$ +// ********************************************************************* +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// *************************************************** +// Compiler Defines +// *************************************************** + #define C_EXPORT extern "C" + #define C_IMPORT extern "C" + +#ifndef stat + #define lstat stat +#endif +#ifndef _fcloseall + #define _fcloseall _fcloseall +#endif +#ifndef HWND + #define HWND GHWND +#endif +#ifndef MAX_PATH + #define MAX_PATH 2048 +#endif +#ifndef CALLBACK + #define CALLBACK +#endif +typedef unsigned int HINSTANCE; +typedef void* LPVOID; +typedef char* PCHAR; +typedef unsigned char BYTE; +typedef unsigned int UINT; +typedef unsigned char UCHAR; +typedef unsigned char* PUCHAR; +typedef unsigned long ULONG; +typedef unsigned long* ULONG_PTR; +typedef unsigned long DWORD; + +#ifndef TRUE + #define TRUE 1 +#endif + +#ifndef FALSE + #define FALSE 0 +#endif +#define BOOL bool + +// *************************************************** + +typedef long (*CPP_FARPROC)(char *); + + +// ************************************************* +// User Defined Constants +// ************************************************* + +#define Version "4.0-Beta3 (2018/12/09)" +#define __BCX__ 1 +#define vt_VarMin 2 +#define vt_VarMax vt_VARIANT +#define fprintf ReDirectFPrint +#define MaxElements 128 +#define MaxTypes 512 +#define MaxLocalVars 512 +#define MaxGlobalVars 4096 +#define MaxLib 64 +#define c_SglQt 39 +#define c_DblQt 34 +#define c_LPar 40 +#define c_RPar 41 +#define c_Komma 44 +#define c_LtBkt 91 +#define c_RtBkt 93 +#define BCX_STR_RUNTIME "Runtime Functions" +#define BCX_STR_MAIN_PROG "Main Program" +#define BCX_STR_SYS_VARS "System Variables" +#define BCX_STR_STD_MACROS "Standard Macros" +#define BCX_STR_STD_PROTOS "Standard Prototypes" +#define BCX_STR_USR_PROCS "User Subs and Functions" +#define BCX_STR_USR_VARS "User Global Variables" +#define BCX_STR_USR_PROTOS "User Prototypes" +#define BCX_STR_USR_CONST "User Defined Constants" +#define BCX_STR_USR_TYPES "User Defined Types, Classes (CPP Mode), And Unions" +#define FUNCTIONPARSE_CLASS struct _FUNCTIONPARSE* +#define VarTypes "%$#!@¦" +#define ARGTYPE_CLASS struct _ARGTYPE* +#define PROTOSTORE_CLASS struct _PROTOSTORE* +#define ELEMENT_CLASS struct _ELEMENT* +#define USERTYPEDEFS_CLASS struct _USERTYPEDEFS* +#define VARINFO_CLASS struct _VARINFO* +#define VARCODE_CLASS struct _VARCODE* +#define iMatchLft(A,B) iMatch (A ,B ,0) +#define iMatchWrd(A,B) iMatch (A ,B ,1) +#define iMatchRgt(A,B) iMatch (A ,B ,2) +// ************************************************* +// User's GLOBAL ENUM blocks +// ************************************************* + +enum + { + vt_UNKNOWN, + vt_STRLIT, + vt_INTEGER, + vt_SINGLE, + vt_DOUBLE, + vt_LDOUBLE, + VT_LLONG, + vt_STRVAR, + vt_DECFUNC, + vt_NUMBER, + vt_FILEPTR, + vt_UDT, + vt_STRUCT, + vt_UNION, + vt_BOOL, + vt_CHAR, + vt_LPSTRPTR, + vt_PCHAR, + vt_CHARPTR, + vt_VOID, + vt_LONG, + vt_DWORD, + vt_FARPROC, + vt_LPBYTE, + vt_LRESULT, + vt_BYTE, + vt_SHORT, + vt_USHORT, + vt_UINT, + vt_ULONG, + vt_HWND, + vt_HDC, + vt_COLORREF, + vt_HANDLE, + vt_HINSTANCE, + vt_WNDCLASSEX, + vt_HFONT, + vt_VARIANT + }; + + +enum + { + mt_ProcessSetCommand, + mt_FuncSubDecC_Dec, + mt_FuncSubDecC_Dec2, + mt_Opts, + mt_Opts2, + mt_Opts3, + mt_OverLoad, + mt_OverLoad2, + mt_FuncSubx1, + mt_FuncSubx2 + }; + + + +// ************************************************* +// User Defined Types, Classes (CPP Mode), And Unions +// ************************************************* + +typedef struct _functionParse +{ + int NumArgs; + int CommaPos[128]; +}functionParse, *LPFUNCTIONPARSE; + + +typedef struct _ARGTYPE +{ + char Arg[2048]; + int ArgType; +}ARGTYPE, *LPARGTYPE; + + +typedef struct _ProtoStore +{ + char Prototype[2048]; + char Condition[512]; + int CondLevel; +}ProtoStore, *LPPROTOSTORE; + + +typedef struct _Element +{ + int ElementType; + int ElementID; + int ElementDynaPtr; + char ElementName[64]; +}Element, *LPELEMENT; + + +typedef struct _UserTypeDefs +{ + int TypeofDef; + int EleCnt; + struct _Element Elements[MaxElements]; + char VarName[64]; +}UserTypeDefs, *LPUSERTYPEDEFS; + + +typedef struct _VarInfo +{ + int VarLine; + int VarType; + int VarDef; + int VarPntr; + int VarSF; + int VarExtn; + int VarCondLevel; + int VarEmitFlag; + int VarConstant; + char VarName[64]; + char VarDim[128]; + char VarModule[300]; + char VarCondDef[128]; +}VarInfo, *LPVARINFO; + + +typedef struct _VARCODE +{ + int VarNo; + int Method; + int IsPtrFlag; + char Header[2048]; + char Proto[2048]; + char Functype[2048]; + char StaticOut[2048]; + char Token[2048]; + char AsToken[2048]; +}VARCODE, *LPVARCODE; + + +// ************************************************* +// System Variables +// ************************************************* + +char TAB [2]={9,0}; // Horz Tab +char LF [2]={10,0}; // Line Feed +char ESC [2]={27,0}; // Escape +char SPC [2]={32,0}; // Space +char DQ [2]={34,0}; // Double-Quote +char DDQ [3]={34,34,0}; // Double-Double-Quote +char CRLF[3]={13,10,0}; // Carr Rtn & Line Feed +char *AR_fgets_retval; + +// ************************************************* +// User Global Variables +// ************************************************* + +static PCHAR *G_argv; +static int G_argc; +static int NoRT; +static int ByrefCnt; +static char CurLine[65535]; +static int gLinesWritten; +static int LoopLocalCnt; +static int GlobalVarCnt; +static int TypeDefsCnt; +static int LocalVarCnt; +static int LocalDynArrCount; +static int LocalDynaCnt; +static int GlobalDynaCnt; +static int ModuleNdx; +static int FPtrNdx; +static int SplitCnt; +static int SplitCur; +static char SrcTmp[65535]; +static int StartNdx; +static int ExitNdx; +static VARCODE VarCode; +static int UmQt; +static char LD_FLAGS[65535]; +static char Accelerator[65535]; +static char CallType[65535]; +static int CaseFlag; +static char CaseVar[65535]; +static char Cmd[65535]; +static char Compiler[65535]; +static char CmdLineConst[65535]; +static char CmdLineFileOut[65535]; +static int CurrentFuncType; +static char DimType[65535]; +static int DllCnt; +static int LoadLibsCnt; +static float Elapsed; +static int EndOfProgram; +static int EntryCnt; +static int ErrFile; +static char szFile[65535]; +static char Filnam[65535]; +static int ForceMainToFunc; +static char Funcname[65535]; +static char Handl[65535]; +static int HFileCnt; +static char HFile[65535]; +static int InConditional; +static char InIfDef[65535]; +static int Indent; +static int InFunc; +static int InMain; +static int IsCallBack; +static int TurboSize; +static int UseCProto; +static int InTypeDef; +static int IsAuto; +static int NoTypeDeclare; +static int IsDim; +static int IsExported; +static int IsRegister; +static int IsStatic; +static int IsStdFunc; +static int IsLocal; +static int IsRaw; +static int IsApple; +static int KillCFile; +static char Keyword1[65535]; +static int LastCmd; +static int LinesRead; +static char Linker[65535]; +static char Lookup[65535]; +static int MakeDLL; +static int Ndx; +static int NoMain; +static int NoDllMain; +static int OkayToSend; +static char Op[65535]; +static int OptionBase; +static char OutfileClone[65535]; +static int PassOne; +static int ProtoCnt; +static int Pusher; +static int Quiet; +static int ReDirect; +static FILE *SaveOutfileNum; +static char Scoot[65535]; +static int ShowStatus; +static int SrcCnt; +static int SrcFlag; +static int TrcFlag; +static int TestForBcxIni; +static char FileIn[65535]; +static char FileOut[65535]; +static char FileErr[65535]; +static char T[65535]; +static int Test; +static int Statements; +static int TestState; +static char Tipe[65535]; +static int TranslateSlash; +static int UseCpp; +static int UseFlag; +static int InNameSpace; +static int Use_Virtual; +static char vproc[65535]; +static int UseStdCall; +static int UseLCaseTbl; +static char Var[65535]; +static int XitCount; +static char Z[65535]; +static char ConstLastDef[65535]; +static int Use_AnsiToWide; +static int Use_Asc; +static int Use_AppExeName; +static int Use_AppExePath; +static int Use_Boolstr; +static int Use_Bor; +static int Use_Band; +static int Use_Bnot; +static int Use_BcxSplitPath; +static int Use_Bin; +static int Use_Bin2dec; +static int Use_Osx; +static int Use_Cvd; +static int Use_Cvld; +static int Use_Cvi; +static int Use_Cvl; +static int Use_Cvs; +static int Use_Chr; +static int Use_Cdbl; +static int Use_Cldbl; +static int Use_Csng; +static int Use_Clear; +static int Use_Cbool; +static int Use_Cint; +static int Use_Clng; +static int Use_Cls; +static int Use_Color; +static int Use_Command; +static int Use_ContainedIn; +static int Use_Console; +static int Use_CopyFile; +static int Use_Static; +static int Use_Crlf; +static int Use_Curdir; +static int Use_Del; +static int Use_Download; +static int Use_Dynacall; +static int Use_DynamicA; +static int Use_Embed; +static int Use_Enclose; +static int Use_Environ; +static int Use_EnumFile; +static int Use_Eof; +static int Use_Exist; +static int Use_ExitCode; +static int Use_Extract; +static int Use_LoadFile; +static int Use_FillArray; +static int Use_Findfirst; +static int Use_Findnext; +static int Use_FindInType; +static int Use_Fint; +static int Use_Fix; +static int Use_FileLocked; +static int Use_Frac; +static int Use_Fracl; +static int Use_Freefile; +static int Use_Get; +static int Use_GetCh; +static int Use_GenFree; +static int Use_Gosub; +static int Use_Gtk; +static int Use_Glib; +static int Use_Hex; +static int Use_Hex2Dec; +static int Use_Iif; +static int Use_Imod; +static int Use_Inkey; +static int Use_InkeyD; +static int Use_Ins; +static int Use_Instr; +static int Use_Inchr; +static int Use_Isptr; +static int Use_iReplace; +static int Use_IRemove; +static int Use_Instrrev; +static int Use_Join; +static int Use_Keypress; +static int Use_Lcase; +static int Use_Ldouble; +static int Use_Left; +static int Use_Like; +static int Use_Lineinput; +static int Use_Loc; +static int Use_Locate; +static int Use_Lof; +static int Use_Lpad; +static int Use_Ltrim; +static int Use_Mcase; +static int Use_Mid; +static int Use_Midstr; +static int Use_Mkd; +static int Use_Mkld; +static int Use_Mki; +static int Use_Mkl; +static int Use_Mks; +static int Use_Min; +static int Use_Max; +static int Use_Now; +static int Use_Numqsortdint; +static int Use_Numqsortaint; +static int Use_Numqsortdfloat; +static int Use_Numqsortafloat; +static int Use_Numqsortddouble; +static int Use_Numqsortadouble; +static int Use_Idxqsort; +static int Use_IdxqsortSt; +static int Use_PtrqsortSt; +static int Use_Oct; +static int Use_Overloaded; +static int Use_OSVersion; +static int Use_Pause; +static int Use_PeekStr; +static int Use_Put; +static int Use_QBColor; +static int Use_Randomize; +static int Use_Rec; +static int Use_RecCount; +static int Use_Remain; +static int Use_Remove; +static int Use_Repeat; +static int Use_Replace; +static int Use_Reverse; +static int Use_Right; +static int Use_Rpad; +static int Use_Rnd; +static int Use_Exp; +static int Use_Retain; +static int Use_Round; +static int Use_Rtrim; +static int Use_Run; +static int Use_Scan; +static int Use_Inputbuffer; +static int Use_SearchPath; +static int Use_StrUpLow; +static int Use_Shell; +static int Use_Sgn; +static int Use_SingleFile; +static int Use_Space; +static int Use_Split; +static int Use_DSplit; +static int Use_StartupCode; +static int Use_Stristr; +static int Use_StrStr; +static int Use_Str; +static int Use_Strl; +static int Use_Str_Cmp; +static int Use_Strim; +static int Use_String; +static int Use_Strptr; +static int Use_Strqsorta; +static int Use_Strqsortd; +static int Use_Strtoken; +static int Use_DynStrqsorta; +static int Use_DynStrqsortd; +static int Use_Swap; +static int Use_Sysdir; +static int Use_SysStr; +static int Use_sziif; +static int Use_Tally; +static int Use_Tempdir; +static int Use_TempFileName; +static int Use_Threads; +static int Use_Time; +static int Use_Timer; +static int Use_Trim; +static int Use_Turbo; +static int Use_Ubound; +static int Use_Ucase; +static int Use_Using; +static int Use_VChr; +static int Use_Verify; +static int Use_Val; +static int Use_Vall; +static int Use_WideToAnsi; +static int Use_Wx; +static int Use_WxC; +static int Use_Ctor; +static int Use_Instat; +static int Use_Socket; +static int Use_IOS; +static int Use_RegEx; +static int Use_BEL; +static int Use_BS; +static int Use_CR; +static int Use_DDQ; +static int Use_DQ; +static int Use_EOF; +static int Use_ESC; +static int Use_FF; +static int Use_LF; +static int Use_NUL; +static int Use_SPC; +static int Use_TAB; +static int Use_VT; +static char prcFile[65535]; +static char udtFile[65535]; +static char datFile[65535]; +static char cstFile[65535]; +static char ovrFile[65535]; +static char hdrFile[65535]; +static char setFile[65535]; +static char enuFile[65535]; +static char *szTmp; +static char *Src; +static char *AbortSrc; +static char *WarnMsg; +static char *RmLibs; +static FILE *SourceFile; +static FILE *FP2; +static FILE *FP3; +static FILE *FP4; +static FILE *FP5; +static FILE *FP6; +static FILE *FP7; +static FILE *FP8; +static FILE *FP9; +static FILE *FP11; +static FILE *Outfile; +static FILE *FP1; +static int DoCountLines; +static FILE *FP10; +static FILE *ResIn; +static FILE *ResOut; +static FILE *UserResIn; +static FILE *fpErr; +static FILE *fpHFile; +static FILE *FP68; +static FILE *fpdef; +static int SFPOINTER; +static int WithCnt; +static char ByrefVars[1024][65535]; +static int LoopLocalVar[256]; +static int BaseTypeDefsCnt[16]; +static char Modules[256][65535]; +static int ModuleLineNos[256]; +static FILE *FPtr[256]; +static char Stk[4096][65535]; +static ProtoStore ProtoType[1024]; +static char SrcStk[128][65535]; +static char SplitStk[128][65535]; +static char CaseStk[256][65535]; +static int CaseElseFlag[256]; +static char Entry[256][65535]; +static char Xit[256][65535]; +static char LocalDynArrName[256][65535]; +static char GlobalDynaStr[256][65535]; +static char DynaStr[256][65535]; +static char StartSub[32][65535]; +static char ExitSub[32][65535]; +static char Library[MaxLib][65535]; +static int GlobalVarHash[MaxGlobalVars]; +static VarInfo GlobalVars[MaxGlobalVars]; +static VarInfo LocalVars[MaxLocalVars]; +static UserTypeDefs TypeDefs[MaxTypes]; +static char DllDecl[800][512]; +static char Loadlibs[128][512]; +static char HFiles[128][65535]; +static char TypeName[16][65535]; +static char WithVar[8][65535]; + + + +// ************************************************* +// Standard Macros +// ************************************************* + +#define FDRV 2 +#define FPATH 4 +#define FNAME 8 +#define FEXT 16 +#define BAND & +#define BOR | +#define imod(a,b)((a)%(b)) +#define VAL(a)(double)atof(a) + + +// ************************************************* +// Standard Prototypes +// ************************************************* + +int str_cmp(char*, char*); +int EoF (FILE*); +void cls(void); +void locate (int,int,int=1,int=12); +void midstr (char*, int, int, char *); +char* BCX_TmpStr(size_t); +char* sziif (bool,char*,char*); +char* TempFileName (char*,char*); +char* AppExePath (void); +char* AppExeName (void); +char* lcase (char*); +char* ucase (char*); +char* mid (char*, int, int=-1); +char* ltrim (char*,char=32); +char* rtrim (char*,char=32); +char* trim (char*); +char* strim (char*); +char* left (char*,int); +char* right (char*,int); +char* rpad (char*,int,int=32); +char* lpad (char*,int,int=32); +char* stringx (int,int); +char* extract (char*,char*); +char* remain (char*,char*); +char* command (int=-1); +char* replace (char*,char*,char*); +char* iReplace (char*,char*,char*); +void Shell (char *); +char* space (int a); +char* str (double); +char* curdir (void); +char* tempdir (void); +char* Environ (char*); +char* _strupr_(char *); +char* _strlwr_(char *); +char* BcxSplitPath (char *, int); +void _splitpath_(const char* path, char* drv, char* dir, char* name, char* ext); +char* StrToken (char*,char*,int); +char* RemoveStr (char*,char*); +char* IRemoveStr (char*,char*); +char* join (int, ... ); +char* enc (char*, int=0, int=0); +char* chr(int,int=0,int=0,int=0,int=0,int=0,int=0,int=0,int=0,int=0); +char* vchr (int,...); +int InstrRev (char*,char*,int=0,int=0); +int instr_b(char*,char*,int=0,int=0); +char *MakeLCaseTbl(void); +char *_stristr_(char*,char*); +char *_strstr_(char*,char*); +int inchr (char*,char*); +int tally (char*,char*,int=0); +BOOL Exist (char*); +char* ins (char *S, int i, char *a); +char* del (char*,int,int); +DWORD lof (char*); +double Round (double,int); +float rnd (void); +double _MIN_ (double,double); +double _MAX_ (double,double); +int containedin(char * ,char **,int=0); + +// ************************************************* +// User Prototypes +// ************************************************* + +int main (int, PCHAR* ); +void EmitCmdLineConst (void); +void EmitCompilerDefines (void); +void MakeFreeGlobals (void); +void ProcessSetCommand (int); +int Directives (void); +int SubVarType (int); +char * PrintWriteFormat (int); +void EmitInputCode (void); +void EmitFileInputCode (void); +void AddFuncs (void); +int CheckLocal (char *, int* ); +int CheckGlobal (char *, int* ); +int CheckType (char *); +void ExportInternalConst (void); +int RestrictedWords (char *); +int DataType (char *); +void CloseAll (void); +char * Clean (char *); +void RemoveAll (char* ,char* ,int=0); +void Warning (char* ,int=0); +PCHAR GetVarTypeName (int); +int HashNumber (char *); +void AddLibrary (char *); +void RemoveLibrary (char *); +void EmitLibs (void); +void AddGlobal (char* ,int,int,char* ,int,int,int,int,int=0); +void AddLocal (char* ,int,int,char* ,int,int,int,int=0); +int IsNumber (char *); +int IsNumberEx (char *); +void StripTabs (void); +void PushFileIO (void); +void PopFileIO (void); +int Inset (char *, char *); +void CheckParQuotes (void); +void ClearIfThenStacks (void); +int IsQuoted (char *); +void PostProcess (void); +void XParse (char *); +void TokenSubstitutions (void); +void JoinStrings (int, int); +void Transforms (void); +void Parse (char *); +void FuncSubDecs1 (char *); +void RemEmptyTokens (void); +void FuncSubDecs2 (char *, int); +void FuncSubDecs3 (VARCODE* ); +void AddTypeDefs (char *, int); +int DefsID (char *); +void GetTypeInfo (char *, int* , int* , int* ); +void AddTypedefElement (int, int, char *, char *, int); +char * GetElement (int, int* , int* , int); +int GetElementInfo (int* , int* , char *); +void HandleNonsense (void); +void ValidVar (char *); +void PointerFix (void); +void DimDynaString (char *, int, int); +int SubFuncTest (void); +int DimSubFunc (int); +void Emit (void); +void Abort (char *); +void BumpDown (void); +void BumpUp (void); +int BraceCount (char *); +char* BracketHandler (char *, int); +void Push (char *); +void Pop (char *); +void EmitEpilog (void); +void EmitProlog (void); +void DeclareVariables (void); +int GetNumArgs (int,int* =NULL); +void GetVarCode (VARCODE* ); +void AddProtos (void); +void RunTimeFunctions (void); +int JoinLines (char *); +void StripCode (char *); +void ProcSingleLineIf (int* ); +int SplitLines (char *); +int iMatch (char *, char *, int); +int iMatchNQ (char *, char *); +int SpecialCaseHandler (char *); +void FastLexer (char* ,char* ,char* ,int=1); +void InsertTokens (int, int, ...); +void EmitExportDef (char *); +char * GetArg (int, functionParse* ); +int SepFuncArgs (int, functionParse* , int); +PCHAR MakeDecProto (functionParse* ); +void AsmUnknownStructs (int); +void EmitIfCond (char *); +void PrintGlobal (int, int, char *, char *, char *, char *); +void ReDirectFPrint (FILE*, char *, ...); +int IsReservedWord (char *); +int GetAsPos (void); +void FreeGlobals (void); + + +// ************************************************* +// User Global Initialized Arrays +// ************************************************* + + +// ************************************************* +// User GLOBAL SET Statements +// ************************************************* + +static char* VarTypeLookup[]= +{ + "int","int","char *","double","float","FILE *","long double" +}; + +static char VarConst[2][8]= +{ + "", + "const " +}; + +static char VarStorage[6][18]= +{ + "static ", + "extern ", + "", + "static volatile ", + "extern volatile ", + "volatile " +}; + +static char* ReservedWord[]= +{ + "IF", + "ELSEIF", + "THEN", + "ELSE", + "AND", + "OR", + "NOT", + "BOR", + "BAND", + "XOR", + "" +}; + + +// ******************************************************************************* +// Developer Guidelines +// ******************************************************************************* +// Code should be written in BCX Basic. If it can not be written in BCX Basic for +// some reason or results in code that seems too inefficient then this may be a +// cue that a new Basic function is needed. +// * All KEYWORDS should be capitalized +// * Use two space indentation +// * Use spaces not tabs +// * Record all notes in reverse chronological order +// * And most importantly....Have fun! +// ****************************************************************************************** +// This section is used to communicate to-do 's, changes, ideas, suggestions, etc. +// ****************************************************************************************** +// ------------------------------------------- +// 2018-12-12 Armando Rivera +// * Changed BcxRegEx function to REGMATCH +// * Changed BcxRegEx keyword to REGMATCH +// * Added $MODULE as alias to $INCLUDE to support external modules. ** MUST BE AT TOP OF MAIN SOURCE FILE ** +// * Added $LDFLAGS directive to support external modules +// ------------------------------------------- +// ------------------------------------------- +// 2016-02-15 Armando Rivera +// ------------------------------------------- +// * Changed default string size to 65K from +// 2k, which was limiting. +// * Updated output of PRINT command, eliminating +// leading spaces from numbers. +// ------------------------------------------- +// 2015-07-03 Armando Rivera +// ------------------------------------------- +// * Changed $OSX flag to use Cocoa instead of Carbon in MacOS +// This is in preparation of the new custom libcocoa library +// that I'm currently creating that will allow mbc +// to create 64bit GUI applications in OSX +// ------------------------------------------- +// 2013-06-26 Armando Rivera +// ------------------------------------------- +// * Added BcxRegex keyword, based on Posix Regex in Libc +// * Broke up main source file into files containing Runtime, Declarations, etc. +// * Added BYTE type +// +// ------------------------------------------- +// 2013-06-17 Armando Rivera +// ------------------------------------------- +// * Tweaked HEX$ so that it will emit 2-digit hex numbers +// * Added PUCHAR (unsigned char*) typedef +// ------------------------------------------- +// 2011-03-11 Armando Rivera +// ------------------------------------------- +// * Added Wayne's suggestion to support Reference Variables as return types. +// +// ------------------------------------------- +// 2011-03-10 Armando Rivera +// ------------------------------------------- +// * Ported $PROJECT directive from ConsoleBC. This doesn't emit the RTL yet, but it's a start. +// It's the first step towards re-writing the RT code to leverage CPP/WX. +// +// * Fixed bug where BCX_TmpStr sometimes wasn't emitted when returning a string from a function +// +// * Added Named Enum support. Syntax: +// myenum AS ENUM +// … +// END ENUM +// +// This required moving the Enum emit code to before the User Prototype emit code +// to allow passing the named enum to user defined functions. +// +// ------------------------------------------- +// 2011-01-23 Armando Rivera +// ------------------------------------------- +// * Initial Beta1 Release +// +// * Fixed bug in INPUT statement to remove trailing newlines (James Fuller) +// +// * Removed COLOR statements to avoid terminal output issues with redirected +// translator output (James Fuller) +// +// * Added CONST keyword when declaring variables (Global, Local, and as Function/Sub parameters) +// At the moment, this is experimental (meaning I haven't fully tested it) but it seems to work +// +// * Added PRIVATE keyword for CPP classes +// ------------------------------------------- +// 2010/12/21 Armando Rivera +// ------------------------------------------- +// * Cleaned up code emission so that unneeded defines/global vars are not emitted +// +// * Added new $IOS directive, which is MAC ONLY, to compile source for iDevices (iPhone/iTouch/AppleTV2) +// At this point in time, running binaries built this way requires a jailbroken iDevice. +// This is experimental, and for console apps only for now. +// A simple console example is in the Examples/IOS folder +// ------------------------------------------- +// 2010/12/11 Armando Rivera +// ------------------------------------------- +// * Add new Socket keywords: BcxSocket, BcxSocketSend, BcxSocketRead, and BcxSocketClose +// See the BcxSocket.bas demo in the Examples/Socket folder for info. +// +// * Added kbhit() , which doesn't exist outside of Windows +// This is a custom sub which emulates what kbhit() does +// +// * Changed the conditional emission of term.h to only be emitted when +// Use_Keypress is TRUE (InKey) +// +// ------------------------------------------- +// 2010/12/01 Armando Rivera +// ------------------------------------------- +// * Changed wxApp emission to use BCXPLITHPATH$, per James Fuller's suggestion. +// +// * Added support for Abstract Classes (gcc doesn't have the INTERFACE keyword) +// +// Example: +// Class MyAbstractClass +// public +// +// virtual sub Proc1() = 0 +// Virtual sub Proc2()=0 +// virtual function Proc3(a$,b$) as integer = 0 +// +// End Class +// ------------------------------------------- +// 2010/11/30 Armando Rivera +// ------------------------------------------- +// * Removed $CLASS/$ENDCLASS $NAMESPACE/$ENDNAMESPACE +// Using either will emit a message stating that they have been replaced. +// +// * Addded NAMESPACE / END NAMESPACE +// This allows creating methods within the NAMESPACE like so: +// +// $CPP +// $NOMAIN +// $EXECON +// '============================================================================== +// NAMESPACE Dlg_01 +// Sub DoIt() +// Print "Dlg_01" +// End Sub +// +// Function GetString$(A$) as string +// function = "The String you Passed Was: " + enc$(A$) +// end function +// END NAMESPACE +// '============================================================================== +// Function main(argc as INTEGER, argv as PCHAR ptr) as INTEGER +// Print "James" +// Dlg_01::DoIt() +// print Dlg_01::GetString$("Hello, World!") +// End Function +// +// * If using $WX, the #define for Clear() will not be emitted due to conflict +// with Classes that have that method defined +// +// * Made the inclusion of "term.h" conditional based on whether $WX/$WXC +// is used. "term.h" is required for the implementation of +// the PAUSE keyword in CONSOLE apps. +// +// ------------------------------------------- +// 2010/11/25 Armando Rivera +// ------------------------------------------- +// * Changed code so that in $CPP mode, the case of the emitted +// .cpp filename is preserved (James Fuller bug report) +// +// ------------------------------------------- +// 2010/11/24 Armando Rivera +// ------------------------------------------- +// * Minor change in StripCode() to correct +// possible overflow issue under 64bit Linux (James Fuller bug report) +// +// * Added $WXC Directive to support WX Console-Based Apps +// Using this switch, neither a wxApp or the IMPLEMENT_APP() macro are +// auto added to the translated source (James Fuller request) +// ------------------------------------------- +// 2010/11/20 Armando Rivera +// ------------------------------------------- +// * Changed $DLL directive so that it would generate *nix Shared Libraries. +// * Added $DLL support to $EXECON +// * Added required flags to LD_FLAGS$ for creating *nix Shared Libraries +// Example: +// $dll +// $execon +// +// function printdemo() export +// print "This was called from a Dynamic Library" +// end function +// +// Note that this is currently only useful for creating shared libraries +// for **OTHER** languages; it won't work with MBC created apps because of +// duplicate naming conflicts. +// +// ------------------------------------------- +// 2010/11/18 Armando Rivera +// ------------------------------------------- +// * Removed "-Os" compiler optimization flag from $EXECON for fastest tranlator compliation +// during Alpha testing stage. +// +// This will be re-added when translator is not longer in Alpha status +// +// * Added USE_CTOR global as flag for supporting Constructor/Destructor syntax +// +// * Added "USING" keyword for CONSTRUCTOR/DESTRUCTOR methods. It is used like this: +// +// CONSTRUCTOR MainWin::MainWin(title as wxString, winStyle as long) USING wxFrame( 0, -1, title, wxPoint(50,50), wxSize(490,296), winStyle ) +// +// Which will emit: +// +// MainWin::MainWin (wxString title, long winStyle) +// : wxFrame( 0, -1, title, wxPoint(50,50), wxSize(490,296), winStyle ) +// { +// +// * Added code to extract and emit derived class methods +// +// ------------------------------------------- +// 2010/11/17 Armando Rivera +// ------------------------------------------- +// * Added new CLASS / END CLASS / PUBLIC / PROTECTED / CONSTRUCTOR / DESTRUCTOR keywords. +// These additions flesh out Basic-Like C++ CLASS support, superceding $CLASS/$ENDCLASS, +// and now allows syntax like the following: +// +// $CPP +// $NOMAIN +// $execon +// +// class MyClass +// +// protected +// first as string +// secnd$ +// third% +// +// public +// type ATest +// a as PCHAR +// b as long +// c as single +// d as float +// end type +// +// Constructor MyClass(a$, b) +// Destructor MyClass() +// end class +// +// FUNCTION main(argc as INTEGER, argv as PCHAR ptr) as INTEGER +// RAW theClass as MyClass PTR +// +// theClass = new MyClass("Hello", 12) +// +// print (char*)theClass->ATest.a +// print theClass->ATest.b +// END FUNCTION +// +// Constructor MyClass::MyClass(a$,b) +// ATest.a = a$ +// ATest.b = b +// END Constructor +// ' +// Destructor MyClass::~MyClass() +// +// END Destructor +// +// ------------------------------------------- +// 2010/11/12 Armando Rivera +// ------------------------------------------- +// * Added code that (mostly) eliminates the need for a trailing ";" in $class/$endclass +// +// * Added code to allow the use of "SUB" in $class/$endclass. It just substitutes "void" for "sub" +// at this point. +// +// * Fixed "THIS" keyword code so that it emits a lowercase "this". Linux/OSX aren't affected +// by this breaking COM statements. :-P Thanks to JCFULLER for the tip! +// +// * For $CPP mode, added typedefs for std::string (CSTRING) and std::fstream (CFILE) +// These are direct replacements for STRING and FILE, and allows the full use of each +// C++ object/class. +// +// So instead of "dim mystring as string", for example, you would do "dim mystring as CSTRING". +// You would then have access to all of std::string's methods like .replace, .substr, .compare, etc. +// +// I'm considering doing the same with the other toolkit directives ($OSX, $GTK, etc) but we'll see... +// +// * Added "inherits" in $CPP mode so that subclassing can be done like so: +// +// $class MyClass inherits AnotherClass +// +// * For $WX mode, added code to automatically emit the required derived wxApp class. +// Note that it will be named the same as your sourcefile (minus the extension), and you MUST provide +// a "FUNCTION ::OnInit() as bool" for it: +// +// FUNCTION TestApp::OnInit() as bool +// +// END FUNCTION +// +// * For $WX mode, made "$NOMAIN" the default, so no need to pass that directive +// +// * Colorized some of the compiler output text. Just because I can. +// +// * Back-ported Wayne's changes to "WITH" to allow the use of "->" syntax +// +// * TODO: +// Finish off the $class/$endclass code to allow full basic syntax for method and variable +// declarations. +// +// Remove ALL remaining WIN32 related code and ifdefs. +// No need for that stuff under Linux/OSX, the Windows version of BCX can handle all +// of the Windows stuff one might need. +// +// Other stuff I can't remember right now….. +// ------------------------------------------- +// 2010/03/31 Armando Rivera +// Beginning with this version of the console compiler, +// the goal is to have a 100% unified code-base, because +// I'm fracking tired of trying to maintain separate builds +// for different Operating Systems. +// ------------------------------------------- +// +// * Added $OSX, $GTK¸$GLIB and $WX Directives +// (Use_Osx, Use_Wx, Use_Gtk, Use_Glib and LD_FLAGS$ Globals added) +// +// $OSX will automatically enable Carbon GUI support, and if $EXECON is invoked +// will also build a Universal Binary with 32bit and 64bit support +// +// $GTK will automatically enable GTK/GLIB support, and if $EXECON is invoked +// will build the executable linking in libgtk and it's support libraries. +// +// $GLIB will automatically enable >GLIB ONLY< support, and if $EXECON is invoked +// will build the executable linking in libglib and it's support libraries. +// +// $WX will automatically enable wxWidgets with $CPP set to "TRUE", and if $EXECON +// is invoked will build the executable linking in libwx and it's support libraries +// +// This is, in part, in preparation for moving the GTK support from the core of the +// LinuxBC translator to an external library which will be linked in as required. This +// will GREATLY simplify maintenence of the translator core once the lib is ready. +// +// * Changed alls instances of byte* to UCHAR* in SWAP() Function +// +// * Added internal return values for PUT/GET to get rid of ALL compiler warnings. +// +// * Updated runtime functions calling PUT()/GET()/fread()/fwrite so that they +// will not trigger compiler warnings +// +// * Reworked the way functions declared using C_DECLARE with the LIB and ALIAS keywords +// are emitted. This is so that you can dynamically load functions from a shared +// library at runtime via dlopen/dlsym. +// +// The syntax is: +// C_DECLARE FUNCTION LIB ALIAS ) AS +// +// For example: +// C_DECLARE FUNCTION b64encode LIB "libglib-2.0.so" ALIAS "g_base64_encode" (txt AS char*, length AS integer) AS string +// C_DECLARE FUNCTION g_base64_decode LIB "libglib-2.0.so" ALIAS "g_base64_decode" (txt AS char*, length AS INTEGER PTR) AS string +// +// NOTE that the ALIAS is the actual name of the function you want to call from the shared library. +// This is so you avoid redeclaration errors if you attempt to link to a library (libm is a good example) +// that is already compile-time linked with g++. +// +// NOTE 2: There is currently no checking whether the function was loaded without error. It is on the TODO list. +// +// * Changed compiler invocation to include -Wformat and -D_FORTIFY_SOURCE=2 (Ubuntu Standard) +// +// * Fixed User Include File handling in order to support mixed case filenames +// +// * Updated the CURDIR$, TEMPDIR$, AND SHELL code to eliminate warnings emitted when compiling on +// a system that has "_FORTIFY_SOURCE=2" enabled by default in GCC/G++ (Ubuntu) +// +// * Fixed a potential overflow problem with LINE INPUT that would also cause G++ to emit +// warnings as above. +// +// *Re-coded the $RESOURCE directive and the GETRESOURCE$ function to allow +// linking of Resources under Linux/Unix. Using $RESOURCE generates a #define +// allowing you to reference the embedded resource using an arbitrary IDENTIFIER. +// +// For example: +// +// DIRECTIVE FILE IDENTIFIER +// ------------------------------- +// $RESOURCE "file.txt" "myres" +// +// +// Note that you reference the resource using the identifier you passed as the +// SECOND parameter to the $RESOURCE directive, minus the quotes. +// +// "file.txt" above can be any arbitrary file on one's system +// +// At the moment, the resource is returned as a string with the GETRESOURCE$ function. +// ***************************************************************************************************** +// ** YOU WILL HAVE TO ENSURE THAT A BUFFER WITH ENOUGH SPACE TO HOLD THE RESOURCE HAS BEEN ALLOCATED ** +// ***************************************************************************************************** +// To aid in this, a constant is automatically created with the size of the resource. It will have the +// name you specified as the second parameter to $RESOURCE, with _SIZE appended. +// Using the example above, the constant would be defined as: myres_SIZE +// +// +// You should be able to manually cast the reference *itself* to what you require, since it is +// merely a pointer to the location of the resource itself. +// +// The resource will be converted to an object file, named using the filename provided with ".o" apppended. +// "file.txt" will be converted to "file.txt.o" in the above example, which can then be linked +// to the final executable via $EXECON "file.txt.o" or $EXEGUI "file.txt.o" +// +// * Tweaked $GUI directive and GUI keyword so that one can use the directive without +// having all of the support for BCX_* form objects automatically added to one's app. +// +// This is usefull when using GtkBuilder or Glade to build the user interface. +// +// ------------------------------------------- +// 2010-01-17 Armando Rivera +// ------------------------------------------- +// modified the $CLASS/$ENDCLASS directives to allow creation and inheritance of C++ Classes +// +// modified the Function/Sub prototype emitter so that it would not emit prototypes +// for C++ Class Methods, which are supposed to be prototyped within the Class itself +// +// made the inclusion of conditional based on whether UseCPP is true/false +// it will not be included if UseCpp is "true" because some C++ toolkits (wxWidgets) +// throw a "redefined" error when it's included +// +// ------------------------------------------- +// 2010-01-15 Armando Rivera +// ------------------------------------------- +// per wmhalsdorf's recommendation, modified SplitLines and Emit procs to support +// C++ Method syntax (CLASSNAME::METHOD) [see Yahoo group Message #40282] +// +// ------------------------------------------- +// 2010-01-10 Armando Rivera +// ------------------------------------------- +// changed $CPP directive to output lowercase filenames +// +// ------------------------------------------- +// 2009-10-18 Armando Rivera +// ------------------------------------------- +// added Carbon.h as a default include, to support Carbon/CoreFoundation calls +// added Carbon framework to $execon section +// removed TRUE and FALSE defines, which are now provided by Carbon.h +// changed Handle$ to Handl$ to resolve conflict with Carbon.h +// +// ------------------------------------------- +// 2009-10-13 Armando Rivera +// ------------------------------------------- +// added typedef for "byte" type (typedef unsigned char byte;) +// + +// ************************************************* +// Runtime Functions +// ************************************************* + +char *BCX_TmpStr (size_t Bites) +{ + static int StrCnt; + static char *StrFunc[512]; + StrCnt=((StrCnt+1) &511); + #if defined BCX_MAX_VAR_SIZE + if(Bites*sizeof(char)>BCX_MAX_VAR_SIZE) + { + printf("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\n",(int)(Bites*sizeof(char)),BCX_MAX_VAR_SIZE); + abort(); + } + #endif + StrFunc[StrCnt]=(char*)realloc(StrFunc[StrCnt],Bites + 128); + return (char*)memset(StrFunc[StrCnt],0,Bites+128); +} + + +int str_cmp (char *a, char *b) +{ + int counter=0; + for(;;) + { + if((a[counter]^b[counter])) + { + if((UINT) a[counter]>= (UINT) b[counter]) + return 1; + return -1; + } + if(!a[counter]) return 0; + counter++; + } +} + + +int EoF (FILE* stream) +{ + register int c, status = ((c = fgetc(stream)) == EOF); + ungetc(c,stream); + return status; +} + + +char *left (char *S, int length) +{ + int tmplen = strlen(S); + if(length<1) return BCX_TmpStr(1); + if(lengthtmplen||start<1) return BCX_TmpStr(1); + if (length<0 || length>(tmplen-start)+1) + length = (tmplen-start)+1; + strtmp = BCX_TmpStr(length); + return (char*)memcpy(strtmp,&S[start-1],length); +} + + +char *trim (char *S) +{ + while(*S==32 || *S==9 || *S==10 || *S==11 || *S==13) + S++; + int i = strlen(S); + while( i>0 && (S[i-1]==32 || S[i-1]==9 || S[i-1]==10 + || S[i-1]==11 || S[i-1]==13)) + i--; + char *strtmp=BCX_TmpStr(i); + return (char*)memcpy(strtmp,S,i); +} + + +char *ltrim (char *S, char c) +{ + if(S[0]==0) return S; + while((*S==32 || *S==c) && *S !=0) S++; + char *strtmp = BCX_TmpStr(strlen(S)); + return strcpy(strtmp,S); +} + + +char *rtrim (char *S,char c) +{ + if(S[0]==0) return S; + int i = strlen(S); + while(i>0 && (S[i-1]==c || S[i-1]==32)) + i--; + char *strtmp = BCX_TmpStr(i); + return (char*)memcpy(strtmp,S,i); +} + + +char *strim (char *src) +{ + char *strtmp = BCX_TmpStr(strlen(src)); + char *dst = strtmp; + while (isspace((unsigned char)*src)) src++; + do + { + while (*src && !isspace((unsigned char)*src)) *dst++ = *src++; + if (*src) + { + *dst++ = *src++; + while (isspace((unsigned char)*src)) src++; + } + } while (*src); + if (isspace((unsigned char)*(--dst))) *dst = 0; + return strtmp; +} + + +char *command (int nArg) + { + int i = 0; + char *retstr=BCX_TmpStr(1); + if(nArg < i) // return entire commandline + { + retstr = BCX_TmpStr(G_argc * 2048); + for(i=1; i < G_argc; i++) + { + strcat(retstr, G_argv[i]); + strcat(retstr, SPC); + } + } + else if(nArg < G_argc) + { + retstr = BCX_TmpStr(strlen(G_argv[nArg]) + 1); + strcpy(retstr, G_argv[nArg]); + } + return retstr; +} + + +char *extract (char *mane, char *match) +{ + char *a; + char *strtmp = BCX_TmpStr(strlen(mane)); + if(*match!=0) + { + a=_strstr_(mane,match); + if(a) return (char*)memcpy(strtmp,mane,a-mane); + } + return strcpy(strtmp,mane); +} + + +char *remain (char *mane, char *mat) +{ + char *p = strstr(mane,mat); + if(p) + { + p+=(strlen(mat)); + return p; + } + return mane; +} + + +char *replace (char *src, char *pat, char *rep) +{ + size_t patsz, repsz, tmpsz, delta; + char *strtmp, *p, *q, *r; + if (!pat || !*pat) + { + strtmp = BCX_TmpStr(strlen(src)); + if (!strtmp) return NULL; + return strcpy(strtmp, src); + } + repsz = strlen(rep); + patsz = strlen(pat); + for (tmpsz=0, p=src; (q=_strstr_(p,pat))!=0; p=q+patsz) + tmpsz += (size_t) (q - p) + repsz; + tmpsz += strlen(p); + strtmp = BCX_TmpStr(tmpsz); + if (!strtmp) return NULL; + for (r=strtmp,p=src; (q=_strstr_(p,pat))!=0;p=q+patsz) + { + delta = (size_t) (q-p); + memcpy(r,p,delta); r += delta; + strcpy(r,rep); r += repsz; + } + strcpy(r,p); + return strtmp; +} + + +char *ucase (char *S) +{ + char *strtmp = BCX_TmpStr(strlen(S)); + return _strupr_(strcpy(strtmp,S)); +} + + +char *lcase (char *S) +{ + char *strtmp = BCX_TmpStr(strlen(S)); + return _strlwr_(strcpy(strtmp,S)); +} + + +char *RemoveStr (char *a, char *b) +{ + char *strtmp, *p, *d; + int tmplen; + strtmp = d = BCX_TmpStr(strlen(a)); + if(!b || !*b) return strcpy(strtmp,a); + p=_strstr_(a,b); tmplen = strlen(b); + while(p) + { + memcpy(d,a,p-a); + d+= (p-a); + a=p+tmplen; + p=_strstr_(a,b); + } + strcpy(d,a); + return strtmp; +} + + +char *IRemoveStr (char *a, char *b) +{ + char *strtmp, *p, *d; + int tmplen; + strtmp = d = BCX_TmpStr(strlen(a)); + if(!b || !*b) return strcpy(strtmp,a); + p=_stristr_(a,b); tmplen = strlen(b); + while(p) + { + memcpy(d,a,p-a); + d+= (p-a); + a=p+tmplen; + p=_stristr_(a,b); + } + strcpy(d,a); + return strtmp; +} + + +char *ins (char *S, int i, char *a) +{ + int j = strlen(S); + if(i<1 || i>j+1) return S; + char *strtmp = BCX_TmpStr(j + strlen(a)); + memcpy(strtmp,S,--i); + strcpy(&strtmp[i],a); + return strcat(strtmp,&S[i]); +} + + +char *del (char *S, int i, int j) +{ + int ln = strlen(S); + if(i<1 || i>ln) return S; + char *strtmp = BCX_TmpStr(ln); + memcpy(strtmp,S,--i); + return strcat(strtmp,&S[i+j]); +} + + +char *str (double d) +{ + char *strtmp = BCX_TmpStr(16); + sprintf(strtmp,"% .15G",d); + return strtmp; +} + + +char *curdir (void) +{ + char *strtmp = BCX_TmpStr(2048); + char *res=getcwd(strtmp, 1024); + return strtmp; +} + + +char *tempdir (void) +{ + char *strtmp = BCX_TmpStr(2048); + if(!Exist("/tmp/mbc.compiler")) { + mkdir ("/tmp/mbc.compiler",0755); + } + strcpy(strtmp,"/tmp/mbc.compiler"); + return strtmp; +} + + +char *stringx (int count, int a) +{ + if(count<1) return BCX_TmpStr(1); + char *strtmp = BCX_TmpStr(count); + return (char*)memset(strtmp,a,count); +} + + +void Shell (char *cmd) +{ + int res=system(cmd); +} + + +char *space (int count) +{ + if(count<1) return BCX_TmpStr(1); + char *strtmp = BCX_TmpStr(count); + return (char*)memset(strtmp,32,count); +} + + +char *enc (char *A, int L, int R) +{ + char *BCX_RetStr = BCX_TmpStr(strlen(A)+3); + if(L==0) L=34; + if(R==0) R=L; + sprintf(BCX_RetStr,"%c%s%c%s",L,A,R,""); + return BCX_RetStr; +} + + +char *chr (int a,int b,int c,int d,int e,int f,int g,int h,int i,int j) +{ + char *strtmp = BCX_TmpStr(11); + strtmp[0] = a; + strtmp[1] = b; + strtmp[2] = c; + strtmp[3] = d; + strtmp[4] = e; + strtmp[5] = f; + strtmp[6] = g; + strtmp[7] = h; + strtmp[8] = i; + strtmp[9] = j; + strtmp[10] = 0; + return strtmp; +} + + +char *vchr(int charcount, ...) +{ + int c = 0, i = charcount; + char *s_ = BCX_TmpStr(charcount + 1); + va_list marker; + s_[i] = 0; + va_start(marker, charcount); + while(i-- > 0) s_[c++] = va_arg(marker,int); + va_end(marker); + return s_; +} + + +char * join(int n, ...) +{ + int i = n, tmplen = 0; + char *strtmp, *s_; + + va_list marker; + va_start(marker, n); // Initialize variable arguments + while(i-- > 0) + { + s_ = va_arg(marker, char *); + if(s_) tmplen += strlen(s_); + } + strtmp = BCX_TmpStr(tmplen); + va_end(marker); // Reset variable arguments + i = n; + va_start(marker, n); // Initialize variable arguments + while(i-- > 0) + { + s_ = va_arg(marker, char *); + if(s_) strcat(strtmp, s_); + } + va_end(marker); // Reset variable arguments + return strtmp; +} + + +char* Environ(char *S) +{ + char *strtmp, *tmp; + + tmp = getenv(S); + if(tmp != NULL) { + strtmp = BCX_TmpStr(strlen(tmp)+1); + return strcpy(strtmp, tmp); + } + return BCX_TmpStr(1); +} + + +char *AppExePath (void) +{ + char fullpath[MAX_PATH]; + int length; + length = readlink("/proc/self/exe", fullpath, MAX_PATH); + if(length < 1) return BCX_TmpStr(1); + + fullpath[length] = 0; + return BcxSplitPath(fullpath, FDRV|FPATH); +} + + +char *AppExeName (void) +{ + return BcxSplitPath(G_argv[0], FNAME|FEXT); +} + + +char * TempFileName (char *dr, char *prefix) +{ + static unsigned int count; + char *f, *tmpstr = BCX_TmpStr(MAX_PATH); + int i, length; + + if(!count) srand(time(0)); + + if(dr) strcpy(tmpstr, dr); + length = strlen(tmpstr); + if(length && (tmpstr[length-1] != '\\' && tmpstr[length-1] != '/')) + tmpstr[length++] = '/'; + if(prefix) strcpy(&tmpstr[length], prefix); + f = &tmpstr[strlen(tmpstr)]; + + do { + count++; + for(i=0; i<5; i+=1) + { + do { + f[i]=(char)(rnd()*122); + }while((f[i]<65)||(f[i]>90&&f[i]<97)); + } + snprintf(&f[5],3,"%x", count); + } while (Exist(tmpstr)); + + return tmpstr; +} + + +int InstrRev (char *s, char *p, int os, int sens) +{ + int sl, pl, ox; + int (*cmp)(const char *, const char *, size_t ); + + if (!s || !p) return 0; + sl = strlen(s); pl = strlen(p); + if (os > sl || sl == 0 || pl == 0 || (ox = sl - pl) < 0) + return 0; + + if (os <= 0) + os = ox ; + else if(os >= pl) + os = os - pl ; + else + return 0; + + cmp = (sens ? strncasecmp : strncmp); + do { if (cmp(s + os , p, pl) == 0) + return os+1; + } while (os--); + return 0; +} + + +int instr_b(char* mane,char* match,int offset,int sensflag) +{ + char *s; + if (!mane || !match || ! *match || offset>(int)strlen(mane)) return 0; + if (sensflag) + s = _stristr_(offset>0 ? mane+offset-1 : mane,match); + else + s = _strstr_(offset>0 ? mane+offset-1 : mane,match); + return s ? (int)(s-mane)+1 : 0; +} + + +char *MakeLCaseTbl (void) +{ + static char tbl[256]; + if(!tbl['a']) + { + int i; for (i=0; i < 256; i++) + tbl[i] = (char)(int)tolower(i); + } + return tbl; +} + + +char *_stristr_(char *String, char *Pattern) +{ + int mi=-1; + char *LowCase = MakeLCaseTbl(); + while(Pattern[++mi]) + { + if(String[mi]==0) return 0; + if(LowCase[(unsigned char)String[mi]]!=LowCase[(unsigned char)Pattern[mi]]) + { String++; mi=-1; } + } + return String; +} + + +char *_strstr_(char *String, char *Pattern) +{ + int mi=-1; + while(Pattern[++mi]) + { + if(String[mi]==0) return 0; + if(String[mi]!=Pattern[mi]) + { String++; mi=-1; } + } + return String; +} + + +int inchr (char *A, char *B) +{ + char* C=A; + while(*C) + { + if(*C==*B) return C-A+1; + C++; + } + return 0; +} + + +double Round (double n, int d) +{ + return (floor((n)*pow(10.0,(d))+0.5)/pow(10.0,(d))); +} + + +bool Exist (char *szFilePath) +{ + int retstat; + struct stat sb; + retstat = stat(szFilePath, &sb); + if(retstat != -1) + return TRUE; + return FALSE; +} + + +int tally (char *szLine, char *szChar, int sensflag) +{ + if(!*szChar) return 0; + int mlen = strlen(szChar); + int iCount = 0; + char *p = (sensflag == 0 ? _strstr_(szLine, szChar) : _stristr_(szLine, szChar)); + while (p) + { + iCount++; + p+=mlen; + p = (sensflag == 0 ? _strstr_(p, szChar) : _stristr_(p, szChar)); + } + return iCount; +} + + +float rnd (void) +{ + return (float)rand()/RAND_MAX; +} + + +double _MAX_ (double a, double b) +{ + if(a>b) + return a; + return b; +} + + +double _MIN_ (double a, double b) +{ + if(asrclen++ || st<1) return; + int replen = strlen(rep); + if(replen < length || length==-1) length=replen; + if((st+length) > srclen) length=srclen-st; + memcpy(&src[st-1],rep,length); +} + + +DWORD lof (char *FileName) +{ + + int retstat; + struct stat sb; + retstat = stat(FileName, &sb); + if(retstat != -1) + return sb.st_size; + return 0; +} + + +char * sziif (bool i, char *a, char *b) +{ + if(i) return a; + return b; +} + + +char *BcxSplitPath (char *FPath, int mask) +{ + if(!FPath) return BCX_TmpStr(1); + char *BCX_RetStr=BCX_TmpStr(strlen(FPath)); + char tmp[MAX_PATH*4]; + _splitpath_(FPath,tmp,&tmp[MAX_PATH],&tmp[MAX_PATH*2],&tmp[MAX_PATH*3]); + if(mask & FDRV) strcat(BCX_RetStr,tmp); + if(mask & FPATH)strcat(BCX_RetStr,&tmp[MAX_PATH]); + if(mask & FNAME)strcat(BCX_RetStr,&tmp[MAX_PATH*2]); + if(mask & FEXT) strcat(BCX_RetStr,&tmp[MAX_PATH*3]); + return BCX_RetStr; +} + + + void _splitpath_(const char* path, char* drv, char* dir, char* name, char* ext) + { + const char* pend; /* end of processed string */ + const char* p; /* search pointer */ + const char* s; /* copy pointer */ + + /* extract drive name */ + if (path[0] && path[1]==':') { + if (drv) { + *drv++ = *path++; + *drv++ = *path++; + *drv = 0; + } + } else if (drv) + *drv = 0; + + /* search for end of string or stream separator */ + for(pend=path; *pend && *pend!=':'; ) + pend++; + + /* search for begin of file extension */ + for(p=pend; p > path && *--p != '\\' && *p!='/'; ) + if (*p == '.') { + pend = p; + break; + } + + if (ext) + { + s=pend; + do{ *ext++ = *s; } while(*s++); + } + /* search for end of directory name */ + for(p=pend; p > path; ) + if (*--p == '\\' || *p == '/') { + p++; + break; + } + + if (name) { + for(s=p; stally(Source,TokenChar)+1) + { + BCX_RetStr=BCX_TmpStr(1); + if(RetVal)free(RetVal); + return BCX_RetStr; + } + while(*Copy) + { + if(*Copy==TokenChar[0]) Find++; + if(Find==n) break; + Copy++; + Posn++; + } + if(n==tally(Source,TokenChar)+1) + { + Posn=LenSrc; + Copy=Source+Posn; + while(*Copy&&Source[Posn]!=TokenChar[0]) + { + Posn--; + Copy--; + } + } + strcpy(RetVal,(char*)mid(Source,1,Posn)); + strcpy(RetVal,(char*)mid(RetVal,InstrRev(RetVal,TokenChar))); + BCX_RetStr=BCX_TmpStr(LenSrc); + strcpy(BCX_RetStr,(char*)RemoveStr(RetVal,TokenChar)); + if(RetVal)free(RetVal); + return BCX_RetStr; +} + + +char *iReplace (char *src, char *pat, char *rep) +{ + size_t patsz, repsz, tmpsz, delta; + char *strtmp, *p, *q, *r; + if (!pat || !*pat) + { + strtmp = BCX_TmpStr(strlen(src)); + if (!strtmp) return NULL; + return strcpy(strtmp, src); + } + repsz = strlen(rep); + patsz = strlen(pat); + for (tmpsz=0, p=src;(q=_stristr_(p,pat))!=0; p=q+patsz) + tmpsz += (size_t) (q - p) + repsz; + tmpsz += strlen(p); + strtmp = BCX_TmpStr(tmpsz); + if (!strtmp) return NULL; + for (r=strtmp,p=src;(q=_stristr_(p,pat))!=0;p=q+patsz) + { + delta = (size_t) (q-p); + memcpy(r,p,delta); r += delta; + strcpy(r,rep); r += repsz; + } + strcpy(r,p); + return strtmp; +} + + +int containedin(char * Token,char **Contain ,int c) + { + int i=0; + while(Contain[i][0]) + { + if(0 == ((c == 0 || c == 2) ? strcmp(Contain[i],Token) : strcasecmp(Contain[i],Token))) + { + return ((c < 2) ? 0 : i); + } + i++; + } + return -1; + } + + + +// ************************************ +// User Subs and Functions +// ************************************ + + +int main (int argc, PCHAR* argv) +{ + G_argc=argc; + G_argv=argv; + szTmp=(char*)calloc(256+1048576,1); + Src=(char*)calloc(256+1048576,1); + AbortSrc=(char*)calloc(256+1048576,1); + WarnMsg=(char*)calloc(256+32767,1); + RmLibs=(char*)calloc(256+32767,1); + static int bitz; + memset(&bitz,0,sizeof(bitz)); + ProtoCnt=0; + TranslateSlash=TRUE; + OkayToSend=TRUE; + Use_SingleFile=TRUE; + Use_StartupCode=FALSE; + StartNdx=0; + Use_ExitCode=FALSE; + ExitNdx=0; + *HFile=0; + *CmdLineFileOut=0; + *RmLibs=0; + InMain=TRUE; + TestState=FALSE; + *CmdLineConst=0; + bitz=sizeof(long)*8; + if(command(-1)[0]==0) + { + #if defined (__APPLE__) + printf("%s\n","MBC4: Ported to Mac OSX by Armando Rivera (c) 2009-2018"); + #else + printf("%s\n","MBC4: Based on Linux BCX by Mike Henning (c) 2009"); + printf("%s%s\n","(c) 2009-2018 Armando Rivera with additional code (c) 2009 John Jacques",LF); + #endif + printf("%s%s%s","Version ",Version," Compiled with "); +// FP3 +#if defined __BCPLUSPLUS__// OUTFILE + printf("%s\n","Borland C++"); +#elif defined __BORLANDC__ + printf("%s\n","Borland C"); +#elif defined __POCC__ + printf("%s\n","Pelles C"); +#elif defined __GNUG__ + printf("%s\n","GNU G++"); +#else + printf("%s\n","Unknown"); +#endif // Main + if(bitz==64) + { + printf("\n"); + printf("%s\n","********************"); + printf("%s\n","** 64 BIT VERSION **"); + printf("%s%s\n","********************",LF); + } + printf("%s%s%s\n"," Usage: ",AppExeName()," infile [.bas] [options]"); + printf("%s\n"," [-c] Generate C++ Compatible code"); + printf("%s%s%s\n"," [-d] DEFINE a constant ... ex. ",AppExeName()," MyFile -D:MyConst[=SomeValue]"); + printf("%s\n"," [-e] Write ERRORS to BCX.ERR file"); + printf("%s%s%s\n"," [-f] Output FILENAME... ex. ",AppExeName()," MyFile -f:/MyFiles/MyFile.c"); + printf("%s\n"," [-k] KILL the generated BCX generated 'C' file"); + printf("%s\n"," [-o] OUTPUT a copy of the generated C file to STDOUT"); + printf("%s\n"," [-q] QUIET - No output to screen during translation"); + printf("%s\n"," [-s] Show STATUS of translation by line number"); + printf("%s\n"," [-w] Enable WARNINGS during translation"); + printf("%s%s%s\n"," [-t] TURBO Mode ON w/optional size ... ex. ",AppExeName()," MyFile -t[:1024]"); + printf("%s\n"," [-u] Turn UNICODE Support ON"); + FreeGlobals(); + fflush(stdout); + exit(0); + } + Quiet=FALSE; + {register int i; + for(i=2; i<=argc-1; i+=1) + { + if(instr_b(lcase(argv[i]),"-f")) + { + strcpy(CmdLineFileOut,mid(argv[i],4)); + } + if(instr_b(lcase(argv[i]),"-d")) + { + strcpy(CmdLineConst, join(3,CmdLineConst,mid(argv[i],4),chr(1))); + } + if(str_cmp(lcase(argv[i]),"-c")==0) + { + UseCpp=TRUE; + } + if(str_cmp(lcase(argv[i]),"-e")==0) + { + ErrFile=TRUE; + } + if(str_cmp(lcase(argv[i]),"-q")==0) + { + Quiet=TRUE; + } + if(str_cmp(lcase(argv[i]),"-k")==0) + { + KillCFile=TRUE; + } + if(str_cmp(lcase(argv[i]),"-o")==0) + { + ReDirect=TRUE; + } + if(str_cmp(lcase(argv[i]),"-s")==0) + { + ShowStatus=TRUE; + } + if(str_cmp(lcase(argv[i]),"-w")==0) + { + TestState=TRUE; + } + if(instr_b(lcase(argv[i]),"-t")) + { + Use_Turbo=TRUE; + TurboSize=VAL(mid(argv[i],4)); + if(TurboSize!=0) + { + if((TurboSize&(TurboSize-1))!=0) + { + TurboSize=512; + Warning("Invalid $Turbo size - defaulting to 512"); + } + } + else + { + TurboSize=512; + } + } + } + } + if(ShowStatus) + { + cls(); + } + if(!Quiet) + { + cls(); + printf("%s%s\n","MBC Version ",Version); + #if defined (__APPLE__) + IsApple=TRUE; + printf("%s%s\n","MBC4: Ported to Mac OSX by Armando Rivera (c) 2009-2018",LF); + #else + printf("%s\n","MBC4: Based on Linux BCX by Mike Henning (c) 2009"); + printf("%s%s\n","(c) 2009-2018 Armando Rivera with additional code (c) 2009 John Jacques",LF); + #endif + if(bitz==64) + { + printf("\n"); + printf("%s\n","********************"); + printf("%s\n","** 64 BIT VERSION **"); + printf("%s%s\n","********************",LF); + } + } + if(inchr(command(1),".")) + { + strcpy(Cmd,command(1)); + } + else + { + if(Exist(join(2,command(1),".bas"))) + { + strcpy(Cmd, join(2,command(1),".bas")); + } + else if(Exist(join(2,command(1),".BAS"))) + { + strcpy(Cmd, join(2,command(1),".BAS")); + } + } + if(!Exist(Cmd)) + { + printf("\n"); + printf("%s%s\n","FILE NOT FOUND: ",command(1)); + FreeGlobals(); + fflush(stdout); + exit(0); + } + strcpy(FileIn,Cmd); + if(CmdLineFileOut[0]==0) + { + strcpy(FileOut, join(2,left(Cmd,InstrRev(Cmd,".",0)-1),".cc")); + } + else + { + strcpy(FileOut,CmdLineFileOut); + } + strcpy(FileErr, join(2,left(Cmd,InstrRev(Cmd,".",0)-1),".ERR")); + if(Exist(FileErr)) + { + remove (FileErr); + } + strcpy(prcFile,TempFileName(tempdir(),"prc")); + strcpy(udtFile,TempFileName(tempdir(),"udt")); + strcpy(datFile,TempFileName(tempdir(),"dat")); + strcpy(cstFile,TempFileName(tempdir(),"cst")); + strcpy(ovrFile,TempFileName(tempdir(),"ovr")); + strcpy(hdrFile,TempFileName(tempdir(),"hdr")); + strcpy(setFile,TempFileName(tempdir(),"set")); + strcpy(enuFile,TempFileName(tempdir(),"enu")); + if((SourceFile=fopen(FileIn,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",FileIn); + exit(1); + } + if((FP2=fopen(FileOut,"w"))==0) + { + fprintf(stderr,"Can't open file %s\n",FileOut); + exit(1); + } + Outfile=FP2; + if((FP3=fopen(prcFile,"w"))==0) + { + fprintf(stderr,"Can't open file %s\n",prcFile); + exit(1); + } + if((FP4=fopen(udtFile,"w"))==0) + { + fprintf(stderr,"Can't open file %s\n",udtFile); + exit(1); + } + if((FP5=fopen(datFile,"w"))==0) + { + fprintf(stderr,"Can't open file %s\n",datFile); + exit(1); + } + if((FP6=fopen(cstFile,"w"))==0) + { + fprintf(stderr,"Can't open file %s\n",cstFile); + exit(1); + } + if((FP7=fopen(hdrFile,"w"))==0) + { + fprintf(stderr,"Can't open file %s\n",hdrFile); + exit(1); + } + if((FP8=fopen(ovrFile,"w"))==0) + { + fprintf(stderr,"Can't open file %s\n",ovrFile); + exit(1); + } + if((FP9=fopen(setFile,"w"))==0) + { + fprintf(stderr,"Can't open file %s\n",setFile); + exit(1); + } + if((FP11=fopen(enuFile,"w"))==0) + { + fprintf(stderr,"Can't open file %s\n",enuFile); + exit(1); + } + ModuleNdx=1; + strcpy(Modules[ModuleNdx],FileIn); + ModuleLineNos[ModuleNdx]=0; + EmitProlog(); + ClearIfThenStacks(); + EmitCmdLineConst(); + AddGlobal("G_argv",vt_PCHAR,0,"",1,0,0,0); + AddGlobal("G_argc",vt_INTEGER,0,"",0,0,0,0); + +READSRCLINE:; + while(!EoF(SourceFile)||SplitCnt) + { + if(SplitCnt==0) + { + Src[0]=0; + AR_fgets_retval=fgets(Src,1048576,SourceFile); + if(Src[strlen(Src)-1]==10)Src[strlen(Src)-1]=0; + ModuleLineNos[ModuleNdx]++; + StripCode(Src); + if(*Src==0) + { + continue; + } + if(JoinLines(Src)==1) + { + continue; + } + if(inchr(Src,"[")) + { + BracketHandler(Src,0); + } + if(SplitLines(Src)) + { + strcpy(Src,SplitStk[++SplitCur]); + } + } + else + { + strcpy(Src,SplitStk[++SplitCur]); + } + if(SplitCur==SplitCnt) + { + SplitCur=SplitCnt=0; + } + if(*Src==0) + { + continue; + } + strcpy(AbortSrc,Src); + if(TrcFlag&&InFunc) + { + if(!iMatchLft(Src,"$trace")) + { + if(!iMatchLft(Src,"end ")&&instr_b(Src,"FUNCTION",0,1)==0) + { + fprintf(Outfile,"%s%s%s%s%s%s\n","// [",trim(Modules[ModuleNdx])," - ",trim(str(ModuleLineNos[ModuleNdx])),"] ",Src); + strcpy(Z,trim(Modules[ModuleNdx])); + strcpy(Z,replace(Z,"\\","\\\\")); + strcpy(Z, join(5," ",Z," - ",str(ModuleLineNos[ModuleNdx])," \\n")); + strcpy(Z, join(3,"printf(",enc(Z),");")); + fprintf(Outfile,"%s\n",Z); + } + } + } + if(SrcFlag) + { + if(!iMatchLft(Src,"$sourc")&&*Src!=33) + { + fprintf(Outfile,"%s%s%s%s%s%s\n","// [",trim(Modules[ModuleNdx])," - ",trim(str(ModuleLineNos[ModuleNdx])),"] ",Src); + } + } + if(ShowStatus) + { + locate (2,1,0); + printf("%s%s%s%d\n","Processing Module: ",trim(Modules[ModuleNdx])," - Line:",(int)ModuleLineNos[ModuleNdx]); + } + if(Src[0]==33) + { + Src[0]=32; + fprintf(Outfile,"%s\n",Src); + *Src=0; + } + if(*Src==0) + { + continue; + } + int di; + di=Directives(); + if(di==0) + { + goto READNEXTLINE; + } + if(di==1) + { + goto READSRCLINE; + } + if(iMatchLft(Src,"set ")) + { + ProcessSetCommand(0); + } + if(iMatchLft(Src,"sharedset ")) + { + ProcessSetCommand(1); + } + PassOne=TRUE; + CheckParQuotes(); + if(SpecialCaseHandler(Src)) + { + continue; + } + Parse(Src); + PassOne=FALSE; + if(Ndx) + { + Emit(); + } + +READNEXTLINE:; + } + if(CmdLineConst[0]>0) + { + strcpy(Src, join(2,"CONST ",CmdLineConst)); + Parse(Src); + Emit(); + *CmdLineConst=0; + } + if(TestForBcxIni==FALSE) + { + TestForBcxIni=TRUE; + strcpy(szFile, join(2,curdir(),"\\bcx.ini")); + if(!Exist(szFile)) + { + strcpy(szFile, join(2,AppExePath(),"bcx.ini")); + } + if(Exist(szFile)) + { + PushFileIO(); + if((SourceFile=fopen(szFile,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",szFile); + exit(1); + } + strcpy(Modules[++ModuleNdx],szFile); + ModuleLineNos[ModuleNdx]=0; + goto READSRCLINE; + } + } + fflush(Outfile); + if(FPtrNdx) + { + PopFileIO(); + goto READSRCLINE; + } + if(Use_GenFree&&GlobalDynaCnt) + { + MakeFreeGlobals(); + } + ExportInternalConst(); + EmitEpilog(); + CloseAll(); + AddProtos(); + DeclareVariables(); + AddFuncs(); + CloseAll(); + if(UseCpp&&str_cmp(CmdLineFileOut,"")==0) + { + strcpy(szTmp, join(2,extract(FileOut,"."),".cpp")); + remove (szTmp); + rename (FileOut,szTmp); + strcpy(FileOut,szTmp); + } + if(Use_Osx&&str_cmp(CmdLineFileOut,"")==0) + { + strcpy(szTmp, join(2,extract(FileOut,"."),".mm")); + remove (szTmp); + rename (FileOut,szTmp); + strcpy(FileOut,szTmp); + } + if((FP1=fopen(FileOut,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",FileOut); + exit(1); + } + if((FP2=fopen(hdrFile,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",hdrFile); + exit(1); + } + if((FP3=fopen("$temp$","w"))==0) + { + fprintf(stderr,"Can't open file %s\n","$temp$"); + exit(1); + } + DoCountLines=TRUE; + fprintf(FP3,"%s\n","// *********************************************************************"); + fprintf(FP3,"%s%s%s\n","// Created with MBC (V) ",Version,"Ported to OSX by Armando Rivera"); + fprintf(FP3,"%s\n","// Ported from BCX32 BASIC To C/C++ Translator (V) 5.12"); + fprintf(FP3,"%s\n","// BCX (c) 1999 - 2018 by Kevin Diggins"); + fprintf(FP3,"%s\n","// LinuxBC (c) 2009 by Mike Henning "); + fprintf(FP3,"%s\n","// MBC (c) 2009 - 2018 by Armando Rivera"); + fprintf(FP3,"%s\n","// *********************************************************************"); + fprintf(FP3,"%s\n","// Translated for compiling with the g++ Compiler"); + if(UseCpp) + { + fprintf(FP3,"%s\n","// g++ -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$.cpp -ldl -o $FILE$"); + } + else + { + fprintf(FP3,"%s\n","// g++ -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$.cc -ldl -o $FILE$"); + } + fprintf(FP3,"%s\n","// *********************************************************************"); + if(NoRT==FALSE) + { + if(Use_Osx) + { + fprintf(FP3,"%s\n","#import "); + } + /*****2010-11-24AddedWxCFORWXCONSOLEApps-AIR*****/; + if(Use_Wx||Use_WxC) + { + fprintf(FP3,"%s\n","// WXWIDGETS HEADER FILES //"); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","// ******************* //"); + fprintf(FP3,"%s\n",""); + } + if(Use_Gtk) + { + fprintf(FP3,"%s\n","#include "); + } + if(Use_Glib) + { + fprintf(FP3,"%s\n","#include "); + } + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + #if defined (__APPLE__) + fprintf(FP3,"%s\n","#include "); + #endif + if(UseCpp) + { + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + } + if(Use_Instat) + { + Use_Keypress=TRUE; + fprintf(FP3,"%s\n","#include "); + } + if(Use_Keypress) + { + fprintf(FP3,"%s\n","#include "); + } + if(Use_Socket) + { + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + fprintf(FP3,"%s\n","#include "); + } + if(Use_RegEx) + { + fprintf(FP3,"%s\n","#include "); + } + fprintf(FP3,"%s\n",""); + EmitCompilerDefines(); + } + while(!EoF(FP2)) + { + Z[0]=0; + AR_fgets_retval=fgets(Z,1048576,FP2); + if(Z[strlen(Z)-1]==10)Z[strlen(Z)-1]=0; + fprintf(FP3,"%s\n",Z); + } + char Lastlyne[2048]; + *Lastlyne=0; + while(!EoF(FP1)) + { + static int bMainOut=0; + Z[0]=0; + AR_fgets_retval=fgets(Z,1048576,FP1); + if(Z[strlen(Z)-1]==10)Z[strlen(Z)-1]=0; + if(iMatchLft(Lastlyne,"#if")) + { + if(iMatchLft(Z,"#endif")) + { + *Lastlyne=0; + continue; + } + else + { + fprintf(FP3,"%s\n",Lastlyne); + } + } + strcpy(Lastlyne,Z); + if(iMatchLft(Lastlyne,"#if")) + { + continue; + } + fprintf(FP3,"%s\n",Z); + if(bMainOut) + { + continue; + } + if(str_cmp(left(ltrim(Z),8),"int main")==0) + { + while(str_cmp(trim(Z),"{")!=0) + { + Z[0]=0; + AR_fgets_retval=fgets(Z,1048576,FP1); + if(Z[strlen(Z)-1]==10)Z[strlen(Z)-1]=0; + fprintf(FP3,"%s\n",Z); + } + if(Use_StartupCode) + { + fprintf(FP3,"%s%s\n",Scoot,"int BCX_SUCode = BCX_StartupCode_(); // execute user's startup code"); + } + if(Use_ExitCode) + { + fprintf(FP3,"%s%s\n",Scoot,"int BCX_EXCode = BCX_ExitCode_(); // Prepare for user's exit code"); + } + bMainOut++; + } + } + DoCountLines=FALSE; + CloseAll(); + remove (hdrFile); + remove (FileOut); + rename ("$temp$",FileOut); + if(ShowStatus) + { + locate (2,1,1); + } + if(!Quiet) + { + LinesRead+=(ModuleLineNos[1]); + Elapsed=Round((float)clock()/(float)CLOCKS_PER_SEC,2); + printf("%s%d%s%d%s","[Lines In:",(int)LinesRead,"] [Lines Out:",(int)gLinesWritten,"] "); + printf("%s%d%s%.7G%s\n","[Statements:",(int)Statements,"] [Time:",(float)Elapsed," sec's]"); + strcpy(Z, join(4,"BCX translated ",RemoveStr(FileIn," ")," to ",RemoveStr(FileOut," "))); + printf("%s\n",Z); + } + PostProcess(); + if(WarnMsg[0]>0) + { + printf("%s%s%s\n","Warnings! :",CRLF,WarnMsg); + } + if(KillCFile) + { + remove (FileOut); + } + FreeGlobals(); + return 0; +} + + +void EmitCmdLineConst (void) +{ + if(CmdLineConst[0]>0) + { + static FILE* Ftmp; + fprintf(FP7,"%s\n",""); + fprintf(FP7,"%s\n","// ***************************************************"); + fprintf(FP7,"%s\n","// Commandline Defines"); + fprintf(FP7,"%s\n","// ***************************************************"); + fprintf(FP7,"%s\n",""); + Ftmp=FP6; + FP6=FP7; + {register int i; + for(i=1; i<=tally(CmdLineConst,chr(1)); i+=1) + { + strcpy(Src,StrToken(CmdLineConst,chr(1),i)); + if(Src[0]==0) + { + break; + } + strcpy(Src, join(2,"CONST ",Src)); + Parse(Src); + Emit(); + } + } + *CmdLineConst=0; + FP6=Ftmp; + fprintf(FP7,"%s\n",""); + } +} + + +void EmitCompilerDefines (void) +{ + fprintf(FP3,"%s\n",""); + fprintf(FP3,"%s\n","// ***************************************************"); + fprintf(FP3,"%s\n","// Compiler Defines"); + fprintf(FP3,"%s\n","// ***************************************************"); + fprintf(FP3,"%s%s\n"," #define C_EXPORT extern ",enc("C")); + fprintf(FP3,"%s%s\n"," #define C_IMPORT extern ",enc("C")); + fprintf(FP3,"%s\n",""); + fprintf(FP3,"%s\n","#ifndef stat"); + fprintf(FP3,"%s\n"," #define lstat stat"); + fprintf(FP3,"%s\n","#endif"); + fprintf(FP3,"%s\n","#ifndef _fcloseall"); + fprintf(FP3,"%s\n"," #define _fcloseall _fcloseall"); + fprintf(FP3,"%s\n","#endif"); + fprintf(FP3,"%s\n","#ifndef HWND"); + fprintf(FP3,"%s\n"," #define HWND GHWND"); + fprintf(FP3,"%s\n","#endif"); + fprintf(FP3,"%s\n","#ifndef MAX_PATH"); + fprintf(FP3,"%s\n"," #define MAX_PATH 2048"); + fprintf(FP3,"%s\n","#endif"); + fprintf(FP3,"%s\n","#ifndef CALLBACK"); + fprintf(FP3,"%s\n"," #define CALLBACK"); + fprintf(FP3,"%s\n","#endif"); + fprintf(FP3,"%s\n","typedef unsigned int HINSTANCE;"); + fprintf(FP3,"%s\n","typedef void* LPVOID;"); + fprintf(FP3,"%s\n","typedef char* PCHAR;"); + fprintf(FP3,"%s\n","typedef unsigned char BYTE;"); + fprintf(FP3,"%s\n","typedef unsigned int UINT;"); + fprintf(FP3,"%s\n","typedef unsigned char UCHAR;"); + fprintf(FP3,"%s\n","typedef unsigned char* PUCHAR;"); + fprintf(FP3,"%s\n","typedef unsigned long ULONG;"); + fprintf(FP3,"%s\n","typedef unsigned long* ULONG_PTR;"); + fprintf(FP3,"%s\n","typedef unsigned long DWORD;"); + fprintf(FP3,"%s\n",""); + fprintf(FP3,"%s\n","#ifndef TRUE"); + fprintf(FP3,"%s\n"," #define TRUE 1"); + fprintf(FP3,"%s\n","#endif"); + fprintf(FP3,"%s\n",""); + fprintf(FP3,"%s\n","#ifndef FALSE"); + fprintf(FP3,"%s\n"," #define FALSE 0"); + fprintf(FP3,"%s\n","#endif"); + if(!Use_Osx) + { + fprintf(FP3,"%s\n","#define BOOL bool"); + } + fprintf(FP3,"%s\n",""); + if(UseCpp) + { + fprintf(FP3,"%s\n","#define println(a) (std::cout << a << std::endl)"); + fprintf(FP3,"%s\n"," typedef std::string CSTRING;"); + fprintf(FP3,"%s\n"," typedef std::fstream CFILE;"); + } +} + + +void MakeFreeGlobals (void) +{ + strcpy(Src,"SUB FreeGlobals"); + PassOne=1; + Parse(Src); + Emit(); + while(GlobalDynaCnt) + { + fprintf(Outfile,"%s%s\n"," ",GlobalDynaStr[GlobalDynaCnt]); + GlobalDynaCnt--; + } + strcpy(Src,"END SUB"); + PassOne=1; + Parse(Src); + Emit(); +} + + +void ProcessSetCommand (int GS) +{ + int i; + int ii; + int j; + int SetString=0; + char CVar[2048]; + int vt; + static FILE *SaveFP; + memset(&SaveFP,0,sizeof(SaveFP)); + SaveFP=Outfile; + if(!InFunc) + { + Outfile=FP9; + } + if(inchr(Src,"$")&&tally(Src,"[")>1) + { + strcpy(Src,strim(Src)); + strcpy(Src,IRemoveStr(Src,"as string")); + strcpy(Src,IRemoveStr(Src,"as char")); + strcat(Src," AS char"); + } + strcat(Src,"="); + PassOne=1; + Parse(Src); + *Tipe=0; + for(i=1; i<=Ndx; i+=1) + { + if(iMatchWrd(Stk[i],"as")) + { + strcpy(Tipe,Stk[i+1]); + *Stk[i]=0; + *Stk[i+1]=0; + break; + } + } + if(Tipe[0]==0) + { + strcpy(szTmp,Stk[2]); + SetString=DataType(Stk[2]); + j=SetString; + VarCode.Method=mt_ProcessSetCommand; + strcpy(VarCode.Token,szTmp); + VarCode.VarNo=j; + GetVarCode( &VarCode); + if(GS) + { + fprintf(Outfile,"%s%s",Scoot,RemoveStr(VarCode.StaticOut,"static ")); + } + else + { + fprintf(Outfile,"%s%s",Scoot,VarCode.StaticOut); + } + char lszTmp[65535]; + *lszTmp=0; + strcpy(CVar,Clean(Stk[2])); + ValidVar(CVar); + vt=DataType(Stk[2]); + for(i=3; i<=Ndx; i+=1) + { + strcat(lszTmp,Stk[i]); + } + if(vt==vt_STRVAR&&str_cmp(lszTmp,"")!=0) + { + strcat(lszTmp,"[65535]"); + } + if(!InFunc) + { + AddGlobal(CVar,vt,0,lszTmp,0,0,0,1); + } + else + { + AddLocal(CVar,vt,0,lszTmp,0,0,1); + } + } + else + { + strcpy(CVar,Clean(Stk[2])); + if(GS) + { + fprintf(Outfile,"%s%s%s%s",Scoot,Tipe," ",CVar); + } + else + { + fprintf(Outfile,"%s%s%s%s%s",Scoot,"static ",Tipe," ",CVar); + } + char DimType[2048]; + int IsPointer; + int id; + strcpy(DimType,RemoveStr(Tipe,"*")); + GetTypeInfo(Tipe, &IsPointer, &id, &vt); + if(vt==vt_STRVAR) + { + strcat(DimType,"[65535]"); + } + if(!InFunc) + { + AddGlobal(CVar,vt,id,DimType,IsPointer,0,0,1); + } + else + { + AddLocal(CVar,vt,id,DimType,IsPointer,0,1); + } + } + i=2; + j=0; + for(;;) + { + i++; + if(str_cmp(Stk[i],"=")==0) + { + j=1; + } + if(SetString==vt_STRVAR&&j==1) + { + fprintf(Outfile,"%s","[65535]="); + } + else + { + fprintf(Outfile,"%s",Stk[i]); + } + if(str_cmp(Stk[i],"=")==0) + { + break; + } + if(i==Ndx) + { + break; + } + } + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","{"); + while(!EoF(SourceFile)) + { + Src[0]=0; + AR_fgets_retval=fgets(Src,1048576,SourceFile); + if(Src[strlen(Src)-1]==10)Src[strlen(Src)-1]=0; + ModuleLineNos[ModuleNdx]++; + StripCode(Src); + if(JoinLines(Src)==1) + { + continue; + } + PassOne=TRUE; + XParse(Src); + PassOne=FALSE; + TokenSubstitutions(); + if(iMatchLft(Src,"end ")) + { + break; + } + if(strlen(Src)) + { + fprintf(Outfile,"%s"," "); + for(ii=1; ii<=Ndx; ii+=1) + { + fprintf(Outfile,"%s",Clean(Stk[ii])); + } + fprintf(Outfile,"%s\n",""); + } + } + fprintf(Outfile,"%s\n","};\n"); + *Src=0; + Outfile=SaveFP; +} + + +int Directives (void) +{ + char lszTmp[2048]; + int i; + char COutputFile[2048]; + if(*Src==35||*Src==36) + { + strcpy(Z,rtrim(lcase(left(Src,6)))); + for(;;) + { + if(str_cmp(Z,"$proje")==0) + { + NoRT=TRUE; + *Src=0; + return 0; + } + if(str_cmp(Z,"$accel")==0) + { + XParse(Src); + strcpy(Accelerator,RemoveStr(Stk[2],DQ)); + *Src=0; + return 0; + } + if(str_cmp(Z,"$bcxve")==0) + { + strcpy(Src,trim(mid(Src,12))); + strcpy(Src,RemoveStr(Src,DQ)); + if(str_cmp(lcase(Version),lcase(Src))==-1) + { + Abort(join(10,CRLF,"Your Translator needs updating.",CRLF,"This program ",enc(Modules[ModuleNdx])," requires BCX Version: ",Src," or later.",CRLF,CRLF)); + } + else + { + printf("%s\n",""); + printf("%s%s\n","Program written for BCX Version ",Src); + printf("%s\n",""); + } + return 0; + } + if(str_cmp(Z,"$compi")==0) + { + PassOne=1; + XParse(Src); + PassOne=0; + strcpy(Compiler,Stk[2]); + *Src=0; + return 0; + } + if(str_cmp(Z,"$execo")==0) + { + static char SrcExt[2048]; + memset(&SrcExt,0,sizeof(SrcExt)); + PassOne=1; + XParse(Src); + PassOne=0; + XitCount++; + if(UseCpp) + { + strcpy(SrcExt,".cpp"); + } + else if(Use_Osx) + { + strcpy(SrcExt,".mm"); + } + else + { + strcpy(SrcExt,".cc"); + } + if(MakeDLL) + { + strcpy(Xit[XitCount], join(7,"g++ -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$",SrcExt," -ldl ",LD_FLAGS,SPC,Stk[2]," -o lib$FILE$.so")); + *SrcExt=0; + *Src=0; + return 0; + } + if(Use_IOS) + { + static char IOS_COMPILER[2048]; + memset(&IOS_COMPILER,0,sizeof(IOS_COMPILER)); + strcpy(IOS_COMPILER,"/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++"); + if(strlen(Stk[2])>0) + { + strcpy(Xit[XitCount], join(8,IOS_COMPILER," -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$",SrcExt," -ldl ",LD_FLAGS,SPC,Stk[2]," -o $FILE$")); + } + else + { + strcpy(Xit[XitCount], join(6,IOS_COMPILER," -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$",SrcExt," -ldl ",LD_FLAGS," -o $FILE$")); + } + *SrcExt=0; + *Src=0; + return 0; + } + if(strlen(Stk[2])>0) + { + strcpy(Xit[XitCount], join(7,"g++ -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$",SrcExt," -ldl ",LD_FLAGS,SPC,Stk[2]," -o $FILE$")); + } + else + { + strcpy(Xit[XitCount], join(5,"g++ -Wformat -D_FORTIFY_SOURCE=2 -Wno-write-strings $FILE$",SrcExt," -ldl ",LD_FLAGS," -o $FILE$")); + } + *SrcExt=0; + *Src=0; + return 0; + } + if(str_cmp(Z,"$exest")==0) + { + PassOne=1; + XParse(Src); + PassOne=0; + XitCount++; + if(IsApple) + { + strcpy(Xit[XitCount],"strip $FILE$"); + } + else + { + strcpy(Xit[XitCount],"strip -s -R .comment -R .note -R .note.ABI-tag $FILE$"); + } + *Src=0; + return 0; + } + if(str_cmp(Z,"$genfr")==0) + { + Use_GenFree=TRUE; + *Src=0; + return 0; + } + if(str_cmp(Z,"$osx")==0) + { + Use_Osx=TRUE; + strcpy(LD_FLAGS,join(2,LD_FLAGS," -fobjc-arc -framework Cocoa")); + return 0; + } + if(str_cmp(Z,"$ios")==0) + { + #if !defined __APPLE__ + Abort(join(3,CRLF,"The $IOS Directive REQUIRES an Apple OSX Operating System",CRLF)); + #endif + Use_IOS=TRUE; + PassOne=1; + XParse(Src); + PassOne=0; + strcpy(LD_FLAGS,join(2,LD_FLAGS," -arch armv6 -arch armv7 -mthumb -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -framework Foundation -framework CoreFoundation")); + return 0; + } + if(str_cmp(Z,"$gtk")==0) + { + Use_Gtk=TRUE; + strcpy(LD_FLAGS,join(2,LD_FLAGS," $(pkg-config --libs --cflags gtk+-2.0)")); + return 0; + } + if(str_cmp(Z,"$ldfla")==0) + { + strcpy(LD_FLAGS,join(2,LD_FLAGS,remain(Src," "))); + return 0; + /*****2010-11-24AddedWxCFORWXCONSOLEApps-AIR*****/; + break; + } + if(str_cmp(Z,"$wxc")==0) + { + Use_WxC=UseCpp=NoMain=TRUE; + strcpy(LD_FLAGS,join(2,LD_FLAGS," $(wx-config --libs --cppflags)")); + return 0; + } + if(str_cmp(Z,"$wx")==0) + { + Use_Wx=UseCpp=NoMain=TRUE; + strcpy(LD_FLAGS,join(2,LD_FLAGS," $(wx-config --libs --cppflags)")); + return 0; + } + if(str_cmp(Z,"$glib")==0) + { + Use_Glib=TRUE; + strcpy(LD_FLAGS,join(2,LD_FLAGS," $(pkg-config --libs --cflags glib-2.0)")); + return 0; + } + if(str_cmp(Z,"$noini")==0) + { + *Src=0; + TestForBcxIni=TRUE; + return 0; + } + if(str_cmp(Z,"$linke")==0) + { + PassOne=1; + XParse(Src); + PassOne=0; + strcpy(Linker,Stk[2]); + *Src=0; + return 0; + } + if(str_cmp(Z,"$onexi")==0) + { + PassOne=1; + XParse(Src); + PassOne=0; + XitCount++; + strcpy(Xit[XitCount],Stk[2]); + *Src=0; + return 0; + } + if(str_cmp(Z,"$onent")==0) + { + PassOne=1; + XParse(Src); + PassOne=0; + EntryCnt++; + strcpy(Entry[EntryCnt],Stk[2]); + *Src=0; + return 0; + } + if(str_cmp(Z,"$pack")==0 || str_cmp(Z,"$pack(")==0) + { + strcpy(Src,mid(Src,6)); + fprintf(FP4,"%s%s\n","#pragma pack ",ltrim(Src)); + *Src=0; + return 0; + } + if(str_cmp(Z,"$nodll")==0) + { + NoDllMain=TRUE; + *Src=0; + return 0; + } + if(str_cmp(Z,"$pelle")==0) + { + *Src=0; + return 0; + } + if(str_cmp(Z,"$stdca")==0) + { + UseStdCall=TRUE; + *Src=0; + return 0; + } + if(str_cmp(Z,"$iprin")==0) + { + if(instr_b(lcase(Src),"_on")) + { + TranslateSlash=TRUE; + } + else + { + TranslateSlash=FALSE; + } + *Src=0; + return 0; + } + if(str_cmp(Z,"$nomai")==0) + { + NoMain=TRUE; + *Src=0; + return 0; + } + if(str_cmp(Z,"$test")==0) + { + TestState=!TestState; + *Src=0; + return 0; + } + if(str_cmp(Z,"$typed")==0) + { + fprintf(FP7,"%s%s%s\n","typedef ",remain(Src," "),";"); + *Src=0; + return 0; + } + if(str_cmp(Z,"$resou")==0) + { + static char resAlias[2048]; + memset(&resAlias,0,sizeof(resAlias)); + static char resFile[2048]; + memset(&resFile,0,sizeof(resFile)); + Use_Embed=TRUE; + PassOne=1; + XParse(Src); + PassOne=0; + EntryCnt++; + strcpy(Entry[EntryCnt], join(5,"ld -r -b binary ",Stk[2]," -o ",Stk[2],".o")); + strcpy(Stk[2],replace(Stk[2],".","_")); + strcpy(resFile,RemoveStr(Stk[2],DQ)); + strcpy(resAlias,RemoveStr(Stk[3],DQ)); + AddGlobal(join(3,"_binary_",resFile,"_start"),vt_INTEGER,0,"",0,0,1,0); + AddGlobal(join(3,"_binary_",resFile,"_size"),vt_INTEGER,0,"",0,0,1,0); + strcpy(Src, join(5,"CONST ",resAlias,"= &_binary_",resFile,"_start")); + Parse(Src); + Emit(); + strcpy(Src, join(5,"CONST ",resAlias,"_SIZE = (int)&_binary_",resFile,"_size")); + Parse(Src); + Emit(); + *Src=0; + return 0; + } + if(str_cmp(Z,"$turbo")==0) + { + strcpy(Src,ltrim(mid(Src,7))); + if(*Src!=0) + { + TurboSize=VAL(Src); + if((TurboSize&(TurboSize-1))!=0) + { + TurboSize=512; + Warning("Invalid $Turbo size - defaulting to 512"); + } + } + else + { + TurboSize=512; + } + Use_Turbo=TRUE; + *Src=0; + return 0; + } + if(str_cmp(Z,"$sourc")==0) + { + SrcFlag=!SrcFlag; + *Src=0; + return 0; + } + if(str_cmp(Z,"$fssta")==0) + { + Use_Static=!Use_Static; + *Src=0; + return 0; + } + if(str_cmp(Z,"$trace")==0) + { + TrcFlag=!TrcFlag; + *Src=0; + return 0; + } + if(str_cmp(Z,"$inclu")==0 || str_cmp(Z,"$modul")==0) + { + char orgfileName[2048]; + strcpy(szFile,trim(RemoveStr(mid(Src,9),DQ))); + strcpy(orgfileName,szFile); + if(str_cmp(left(szFile,1),"<")==0) + { + strcpy(szFile,mid(szFile,2,strlen(szFile)-2)); + strcpy(szFile, join(2,Environ("BCXLIB"),szFile)); + } + if(!Exist(szFile)) + { + strcpy(szFile,BcxSplitPath(szFile,FNAME|FEXT)); + strcpy(szFile, join(2,BcxSplitPath(FileIn,FDRV|FPATH),szFile)); + } + if(!Exist(szFile)) + { + Abort(join(2,"Unable to locate ",orgfileName)); + } + PushFileIO(); + if((SourceFile=fopen(szFile,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",szFile); + exit(1); + } + strcpy(Modules[++ModuleNdx],szFile); + ModuleLineNos[ModuleNdx]=0; + return 1; + } + if(str_cmp(Z,"$try")==0) + { + fprintf(Outfile,"%s\n","try {"); + *Src=0; + return 0; + } + if(str_cmp(Z,"$throw")==0) + { + strcpy(szTmp,mid(Src,8)); + if(szTmp[0]==0) + { + strcpy(szTmp,enc("An Exception has occured!")); + } + fprintf(Outfile,"%s%s%s%s\n",Scoot,"throw ",szTmp,";"); + *Src=0; + return 0; + } + if(str_cmp(Z,"$catch")==0) + { + strcpy(szTmp,mid(Src,8)); + if(szTmp[0]==0) + { + strcpy(szTmp,"char *str"); + } + fprintf(Outfile,"%s\n","}"); + fprintf(Outfile,"%s%s%s\n","catch (",szTmp,")"); + fprintf(Outfile,"%s\n","{"); + *Src=0; + return 0; + } + if(str_cmp(Z,"$endtr")==0) + { + fprintf(Outfile,"%s\n","}"); + *Src=0; + return 0; + } + if(str_cmp(Z,"$endna")==0) + { + InNameSpace--; + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + *Src=0; + return 0; + } + if(str_cmp(Z,"$names")==0) + { + Abort("$NAMESPACE/$ENDNAMESPACE have been removed from this version. Use NAMESPACE / END NAMESPACE instead."); + break; + } + if(str_cmp(Z,"$usena")==0) + { + UseCpp=TRUE; + strcpy(szTmp,mid(Src,inchr(Src," ")+1)); + if(str_cmp(right(trim(szTmp),1),";")!=0) + { + fprintf(Outfile,"%s%s%s\n","using namespace ",szTmp,";"); + } + else + { + fprintf(Outfile,"%s%s\n","using namespace ",szTmp); + } + *Src=0; + return 0; + } + if(str_cmp(Z,"$class")==0) + { + Abort("$CLASS has been removed from this version. Use CLASS instead."); + return 0; + } + if(str_cmp(Z,"$inter")==0) + { + static int BeenHere; + UseCpp=TRUE; + strcpy(szTmp,remain(Src,SPC)); + if(!BeenHere) + { + BeenHere++; + fprintf(FP4,"%s\n","#ifndef __cplusplus"); + fprintf(FP4,"%s\n"," #error A C++ compiler is required"); + fprintf(FP4,"%s\n","#endif"); + } + fprintf(FP4,"%s%s%s\n","interface ",szTmp," {"); + for(;;) + { + if(EoF(SourceFile)) + { + Abort("$Interface Without $EndInterface"); + } + Src[0]=0; + AR_fgets_retval=fgets(Src,1048576,SourceFile); + if(Src[strlen(Src)-1]==10)Src[strlen(Src)-1]=0; + ModuleLineNos[ModuleNdx]++; + if(iMatchLft(ltrim(Src),"$endinterface")) + { + break; + } + fprintf(FP4,"%s\n",Src); + } + fprintf(FP4,"%s%s%s\n","}",trim(join(2,Src,13)),";"); + return 0; + } + if(str_cmp(Z,"$comme")==0) + { + *Src=0; + for(;;) + { + if(EoF(SourceFile)) + { + Abort("Unbalanced $Comment"); + } + Src[0]=0; + AR_fgets_retval=fgets(Src,1048576,SourceFile); + if(Src[strlen(Src)-1]==10)Src[strlen(Src)-1]=0; + ModuleLineNos[ModuleNdx]++; + StripTabs(); + if(iMatchLft(ltrim(Src),"$comment")) + { + break; + } + fprintf(Outfile,"%s%s\n","// ",Src); + } + *Src=0; + return 0; + } + if(str_cmp(Z,"$ccode")==0) + { + *Src=0; + for(;;) + { + if(EoF(SourceFile)) + { + Abort("Unbalanced $Ccode"); + } + Src[0]=0; + AR_fgets_retval=fgets(Src,1048576,SourceFile); + if(Src[strlen(Src)-1]==10)Src[strlen(Src)-1]=0; + ModuleLineNos[ModuleNdx]++; + StripTabs(); + if(iMatchLft(ltrim(Src),"$ccode")) + { + if(SrcFlag) + { + fprintf(Outfile,"%s%s%s%s%s\n","// [",trim(Modules[ModuleNdx])," - ",trim(str(ModuleLineNos[ModuleNdx])),"] End of $CCODE Block"); + } + break; + } + fprintf(Outfile,"%s\n",rtrim(Src)); + } + *Src=0; + return 0; + } + if(str_cmp(Z,"$cprot")==0) + { + FastLexer(Src,SPC,"!"); + if(iMatchWrd(Stk[2],"!")) + { + ProtoCnt++; + strcpy(ProtoType[ProtoCnt].Prototype,remain(Src,"!")); + *ProtoType[ProtoCnt].Condition=0; + ProtoType[ProtoCnt].CondLevel=0; + } + else + { + i=iMatchNQ(Src,"function"); + if(i==0) + { + i=iMatchNQ(Src,"sub"); + } + if(i) + { + strcpy(Src, join(2,"c_declare ",mid(Src,i))); + } + else + { + i=iMatchNQ(Src,"$cproto"); + strcpy(Src, join(2,"c_declare function ",mid(Src,i+7))); + } + UseCProto=TRUE; + return 2; + } + *Src=0; + return 0; + } + if(str_cmp(Z,"$heade")==0) + { + *Src=0; + fprintf(FP7,"%s\n","// ***************************************************"); + fprintf(FP7,"%s\n",""); + for(;;) + { + if(EoF(SourceFile)) + { + Abort("Unbalanced $Header"); + } + Src[0]=0; + AR_fgets_retval=fgets(Src,1048576,SourceFile); + if(Src[strlen(Src)-1]==10)Src[strlen(Src)-1]=0; + ModuleLineNos[ModuleNdx]++; + StripTabs(); + strcpy(Src,trim(Src)); + if(iMatchLft(Src,"$heade")) + { + break; + } + fprintf(FP7,"%s\n",Src); + } + *Src=0; + fprintf(FP7,"%s\n",""); + return 0; + } + if(str_cmp(Z,"$asm")==0) + { + if(!iMatchLft(Src,"$asm")) + { + Abort(join(2,"Unknown metastatement: ",Src)); + } + *Src=0; + for(;;) + { + if(EoF(SourceFile)) + { + Abort("Unbalanced $Asm"); + } + Src[0]=0; + AR_fgets_retval=fgets(Src,1048576,SourceFile); + if(Src[strlen(Src)-1]==10)Src[strlen(Src)-1]=0; + ModuleLineNos[ModuleNdx]++; + if(SrcFlag) + { + fprintf(Outfile,"%s%s\n","// ",Src); + } + StripTabs(); + strcpy(Src,trim(Src)); + static int meta_asm_loop; + memset(&meta_asm_loop,0,sizeof(meta_asm_loop)); + static bool meta_asm_comment_present; + memset(&meta_asm_comment_present,0,sizeof(meta_asm_comment_present)); + static int Src_Len; + memset(&Src_Len,0,sizeof(Src_Len)); + Src_Len=strlen(Src); + meta_asm_comment_present=FALSE; + for(meta_asm_loop=0; meta_asm_loop<=Src_Len; meta_asm_loop+=1) + { + if(Src[meta_asm_loop]==39||Src[meta_asm_loop]==59) + { + strcpy(lszTmp,right(Src,Src_Len-meta_asm_loop-1)); + Src[meta_asm_loop]=0; + meta_asm_comment_present=TRUE; + break; + } + } + strcpy(Src,trim(Src)); + if(iMatchLft(Src,"$asm")) + { + break; + } + strcpy(Src,replace(Src,"$","0x")); + strcpy(Src,iReplace(Src,"&h","0x")); + if(Src[0]!=0) + { + strcpy(Src, join(3,"_asm(",enc(Src),chr(1))); + if(meta_asm_comment_present) + { + strcpy(Src, join(4,Src,TAB,"//",lszTmp)); + } + strcpy(SrcTmp,Src); + fprintf(Outfile,"%s\n","#if !defined( __POCC__ ) && !defined (__cplusplus )"); + strcpy(Src,replace(Src,chr(1),")")); + fprintf(Outfile,"%s\n",Src); + fprintf(Outfile,"%s\n","#else"); + strcpy(SrcTmp,replace(SrcTmp,"_asm(","__asm{")); + strcpy(SrcTmp,replace(SrcTmp,chr(1),"}")); + fprintf(Outfile,"%s\n",RemoveStr(SrcTmp,DQ)); + fprintf(Outfile,"%s\n","#endif"); + } + } + *Src=0; + return 0; + } + if(str_cmp(Z,"#inclu")==0) + { + strcpy(Src,RemoveStr(lcase(Src),"#include")); + strcpy(Src,trim(Src)); + fprintf(FP7,"%s%s\n","#include ",Src); + *Src=0; + return 0; + } + if(str_cmp(Z,"$libra")==0) + { + strcpy(Src,replace(Src,"\\","\\\\")); + strcpy(Src,RemoveStr(lcase(Src),"$library")); + strcpy(Src,trim(Src)); + AddLibrary(Src); + *Src=0; + return 0; + } + if(str_cmp(Z,"$nolib")==0) + { + strcpy(Src,replace(Src,"\\","\\\\")); + strcpy(Src,RemoveStr(lcase(Src),"$nolibrary")); + RemoveLibrary(Src); + *Src=0; + return 0; + } + break; + } + } + return 2; +} + + +int SubVarType (int TokenNum) +{ + int k; + int j=0; + k=CheckLocal(Stk[TokenNum], &j); + if(k==vt_CHAR) + { + if(*LocalVars[j].VarDim!=91&&LocalVars[j].VarPntr==0) + { + k=vt_INTEGER; + } + } + else if(k==vt_UNKNOWN) + { + k=CheckGlobal(Stk[TokenNum], &j); + if(k==vt_CHAR) + { + if(*GlobalVars[j].VarDim!=91&&GlobalVars[j].VarPntr==0) + { + k=vt_INTEGER; + } + } + } + j=(UCHAR)*(right(Stk[TokenNum],1)); + for(;;) + { + if(k==vt_STRVAR||k==vt_CHAR) + { + if(j!=36) + { + strcat(Stk[TokenNum],"$"); + } + break; + } + if(k==vt_INTEGER) + { + if(j!=37) + { + strcat(Stk[TokenNum],"%"); + } + break; + } + if(k==vt_SINGLE) + { + if(j!=33) + { + strcat(Stk[TokenNum],"!"); + } + break; + } + if(k==vt_DOUBLE) + { + if(j!=35) + { + strcat(Stk[TokenNum],"#"); + } + break; + } + if(k==vt_LDOUBLE) + { + if(j!=166) + { + strcat(Stk[TokenNum],"¦"); + } + } + break; + } + return k; +} + + +char * PrintWriteFormat (int DoWrite) +{ + char *BCX_RetStr={0}; + ARGTYPE Stak[128]; + char Frmat[2048]; + char Arg[2048]; + char ZZ[2048]; + char Cast[2048]; + int NewLineFlag=0; + int Argcount=0; + int i=0; + int j=0; + int k=0; + *Frmat=0; + *Arg=0; + *ZZ=0; + if(str_cmp(Stk[Ndx],";")==0) + { + NewLineFlag=TRUE; + Ndx--; + } + if(Ndx==1) + { + goto PRINTWRITELABEL; + } + Stak[1].ArgType=-1; + j=2; + while(j<=Ndx) + { + if(str_cmp(Clean(Stk[j]),"BCX_DynaCall")!=0) + { + i=SubVarType(j); + if(Stak[Argcount+1].ArgType==-1) + { + if(i==vt_CHAR||i==vt_STRVAR||i==vt_INTEGER||i==vt_SINGLE||i==vt_DOUBLE||i==vt_LDOUBLE) + { + Stak[Argcount+1].ArgType=i; + } + } + if(str_cmp(Stk[j],"(")==0) + { + i=0; + for(;;) + { + if(str_cmp(Stk[j],"(")==0) + { + i++; + } + if(str_cmp(Stk[j],")")==0) + { + i--; + } + strcat(Arg,Stk[j]); + j++; + if(i<=0||j>=Ndx) + { + break; + } + } + } + if(str_cmp(Stk[j],"[")==0) + { + i=0; + for(;;) + { + if(str_cmp(Stk[j],"[")==0) + { + i++; + } + if(str_cmp(Stk[j],"]")==0) + { + i--; + } + strcat(Arg,Stk[j]); + j++; + if(str_cmp(Stk[j],"[")==0 && i==0) + { + continue; + } + if(i<=0||j>=Ndx) + { + break; + } + } + } + if(str_cmp(Stk[j],";")==0 || str_cmp(Stk[j],",")==0 || str_cmp(Stk[j],"&")==0) + { + Argcount++; + strcpy(Stak[Argcount].Arg,Arg); + Stak[Argcount+1].ArgType=-1; + *Arg=0; + j++; + } + else + { + strcat(Arg,Stk[j]); + j++; + } + } + else + { + strcat(Arg,Stk[j]); + j++; + } + } + Argcount++; + strcpy(Stak[Argcount].Arg,Arg); + *Arg=0; + for(i=1; i<=Argcount; i+=1) + { + j=Stak[i].ArgType; + if(j==-1) + { + strcpy(ZZ,extract(Stak[i].Arg,"(")); + j=DataType(ZZ); + } + for(;;) + { + if(j==vt_STRLIT||j==vt_STRVAR||j==vt_CHAR) + { + if(DoWrite) + { + strcpy(Frmat, join(7,Frmat,"\\",DQ,"%s","\\",DQ,",")); + } + else + { + strcat(Frmat,"%s"); + } + if(str_cmp(left(ZZ,12),"BCX_DynaCall")==0) + { + strcpy(Arg, join(3,Arg,",(char*)",Stak[i].Arg)); + } + else + { + strcpy(Arg, join(3,Arg,",",Stak[i].Arg)); + } + break; + } + if(j==vt_INTEGER||j==vt_DECFUNC) + { + if(DoWrite) + { + strcpy(Frmat, join(3,Frmat,"%d",",")); + } + else + { + strcat(Frmat,"%d"); + } + strcpy(Arg, join(3,Arg,",(int)",Stak[i].Arg)); + break; + } + if(j==vt_SINGLE) + { + if(DoWrite) + { + strcpy(Frmat, join(3,Frmat,"%.7G",",")); + } + else + { + strcat(Frmat,"%.7G"); + } + strcpy(Arg, join(3,Arg,",(float)",Stak[i].Arg)); + break; + } + if(j==vt_DOUBLE||j==vt_NUMBER) + { + if(DoWrite) + { + strcpy(Frmat, join(3,Frmat,"%.15G",",")); + } + else + { + strcat(Frmat,"%.15G"); + } + strcpy(Arg, join(3,Arg,",(double)",Stak[i].Arg)); + break; + } + if(j==vt_LDOUBLE) + { + if(DoWrite) + { + strcpy(Frmat, join(3,Frmat,"%.19LG",",")); + } + else + { + strcat(Frmat,"%.19LG"); + } + strcpy(Arg, join(3,Arg,",(LDOUBLE)",Stak[i].Arg)); + break; + } + // case else + { + if((UCHAR)*(Stak[i].Arg)==40) + { + *ZZ=0; + strcat(Arg,","); + for(;;) + { + k=instr_b(Stak[i].Arg,")"); + strcpy(Cast,mid(Stak[i].Arg,1,k)); + strcpy(Stak[i].Arg,trim(mid(Stak[i].Arg,k+1))); + strcpy(Cast,iReplace(Cast,"char*","char *")); + strcpy(Cast,iReplace(Cast,"integer","int")); + strcpy(Cast,iReplace(Cast,"single","float")); + strcpy(Cast,iReplace(Cast,"ldouble","LDOUBLE")); + if(ZZ[0]==0) + { + if(str_cmp(Cast,"(char *)")==0 || str_cmp(Cast,"(int)")==0 || str_cmp(Cast,"(float)")==0 || str_cmp(Cast,"(double)")==0 || str_cmp(Cast,"(LDOUBLE)")==0) + { + strcpy(ZZ,Cast); + } + else + { + strcpy(ZZ,"(double)"); + strcpy(Cast, join(2,ZZ,Cast)); + } + RemoveAll(ZZ,"()"); + strcpy(ZZ,iReplace(ZZ,"char *","%s")); + strcpy(ZZ,iReplace(ZZ,"int","%d")); + strcpy(ZZ,iReplace(ZZ,"float","%.7G")); + strcpy(ZZ,iReplace(ZZ,"ldouble","%.19LG")); + strcpy(ZZ,iReplace(ZZ,"double","%.15G")); + } + strcat(Arg,Cast); + if(!((UCHAR)*(Stak[i].Arg)==40)) + { + break; + } + } + strcat(Arg,Stak[i].Arg); + strcat(Frmat,ZZ); + if(DoWrite) + { + strcat(Frmat,","); + } + } + else + { + if(DoWrite) + { + strcpy(Frmat, join(3,Frmat,"%G",",")); + } + else + { + strcat(Frmat,"%G"); + strcpy(Arg, join(3,Arg,",(float)",Stak[i].Arg)); + } + } + } + break; + } + } + if(DoWrite) + { + strcpy(Frmat,left(Frmat,strlen(Frmat)-1)); + } + +PRINTWRITELABEL:; + if(NewLineFlag==0) + { + strcat(Frmat,"\\n"); + } + BCX_RetStr=join(4,"printf(",enc(Frmat),Clean(Arg),");"); + return BCX_RetStr; +} + + +void EmitInputCode (void) +{ + int Argcount=0; + int VarCnt=0; + int i=0; + int j=0; + int l=0; + char Arg[2048]; + char Tmp[2048]; + char Frmat[2048]; + static char Stak[128][2048]; + memset(&Stak,0,sizeof(Stak)); + char Y[2048]; + char ZZ[2048]; + Use_Inputbuffer=TRUE; + Use_Scan=TRUE; + Use_Split=TRUE; + Use_Remove=TRUE; + Use_StrStr=TRUE; + Use_Mid=TRUE; + Use_Left=TRUE; + Use_Instr=TRUE; + Use_Stristr=TRUE; + UseLCaseTbl=TRUE; + UseFlag=TRUE; + Use_Lineinput=TRUE; + *Arg=0; + *ZZ=0; + *Frmat=0; + strcpy(Tmp, join(7,DQ,",",DQ,",",DQ," ",DQ)); + if(DataType(Stk[2])==vt_STRLIT) + { + fprintf(Outfile,"%s%s%s%s\n",Scoot,"printf(",Clean(Stk[2]),");"); + } + if(DataType(Stk[2])==vt_STRLIT) + { + j=4; + } + else + { + j=2; + } + l=j; + while(j<=Ndx) + { + if(j==l) + { + i=SubVarType(j); + } + if(str_cmp(Stk[j],",")==0) + { + l=j+1; + } + strcat(ZZ,Stk[j]); + j++; + } + FastLexer(ZZ,"",","); + j=1; + while(j<=Ndx) + { + if(str_cmp(Stk[j],",")==0) + { + Argcount++; + strcpy(Stak[Argcount],Arg); + *Arg=0; + j++; + } + else + { + strcat(Arg,Stk[j]); + j++; + if(j=Ndx) + { + break; + } + } + } + } + } + } + Argcount++; + strcpy(Stak[Argcount],Arg); + *Arg=0; + for(i=1; i<=Argcount; i+=1) + { + strcpy(Y,Stak[i]); + j=DataType(Y); + for(;;) + { + if(j==vt_STRVAR) + { + strcat(Frmat,"%s"); + strcpy(Arg, join(3,Arg,",",Clean(Stak[i]))); + fprintf(Outfile,"%s%s%s%s\n",Scoot,"*",trim(Clean(Stak[i])),"=0;"); + VarCnt++; + break; + } + if(j==vt_INTEGER) + { + strcat(Frmat,"%d"); + strcpy(Arg, join(3,Arg,",&",Clean(Stak[i]))); + fprintf(Outfile,"%s%s%s\n",Scoot,Clean(Stak[i]),"=0;"); + VarCnt++; + break; + } + if(j==vt_SINGLE) + { + strcat(Frmat,"%g"); + strcpy(Arg, join(3,Arg,",&",Clean(Stak[i]))); + fprintf(Outfile,"%s%s%s\n",Scoot,Clean(Stak[i]),"=0;"); + VarCnt++; + break; + } + if(j==vt_DOUBLE) + { + strcat(Frmat,"%lG"); + strcpy(Arg, join(3,Arg,",&",Clean(Stak[i]))); + fprintf(Outfile,"%s%s%s\n",Scoot,Clean(Stak[i]),"=0;"); + VarCnt++; + break; + } + if(j==vt_LDOUBLE) + { + strcat(Frmat,"%lG"); + strcpy(Arg, join(3,Arg,",&",Clean(Stak[i]))); + fprintf(Outfile,"%s%s%s\n",Scoot,Clean(Stak[i]),"=0;"); + VarCnt++; + break; + } + // case else + { + strcat(Frmat,"%d"); + strcpy(Arg, join(3,Arg,",&",Clean(Stak[i]))); + fprintf(Outfile,"%s%s%s\n",Scoot,Clean(Stak[i]),"=0;"); + VarCnt++; + } + break; + } + } + fprintf(Outfile,"%s%s\n",Scoot,"AR_fgets_retval=fgets(InputBuffer,sizeof(InputBuffer),stdin);"); + fprintf(Outfile,"%s%s\n",Scoot,"InputBuffer[strlen(InputBuffer)-1]=0;"); + fprintf(Outfile,"%s%s%s%s%s\n",Scoot,"ScanError = scan(InputBuffer,",enc(Frmat),Arg,");\n"); + fprintf(Outfile,"%s%s\n",Scoot,"*InputBuffer=0;"); +} + + +void EmitFileInputCode (void) +{ + int Argcount=0; + int VarCnt=0; + int i; + int j; + char Arg[2048]; + char Frmat[2048]; + char FHandle[2048]; + char Y[2048]; + char ZZ[2048]; + static char Stak[128][2048]; + memset(&Stak,0,sizeof(Stak)); + *Arg=0; + *Frmat=0; + *ZZ=0; + *FHandle=0; + Use_Inputbuffer=TRUE; + Use_Scan=TRUE; + Use_Split=TRUE; + Use_Remove=TRUE; + Use_StrStr=TRUE; + Use_Mid=TRUE; + Use_Left=TRUE; + Use_Instr=TRUE; + Use_Stristr=TRUE; + UseLCaseTbl=TRUE; + i=4; + for(j=2; j<=Ndx; j+=1) + { + if(*Stk[j]==44) + { + i=j+1; + break; + } + strcat(FHandle,Stk[j]); + } + for(j=i; j<=Ndx; j+=1) + { + if(j==i) + { + SubVarType(j); + } + if(str_cmp(Stk[j],",")==0) + { + SubVarType(j+1); + } + strcat(ZZ,Stk[j]); + } + FastLexer(ZZ,"",","); + j=1; + while(j<=Ndx) + { + if(str_cmp(Stk[j],",")==0) + { + Argcount++; + strcpy(Stak[Argcount],Arg); + *Arg=0; + j++; + } + else + { + strcat(Arg,Stk[j]); + j++; + if(j=Ndx) + { + break; + } + } + } + } + } + } + Argcount++; + strcpy(Stak[Argcount],Arg); + *Arg=0; + for(i=1; i<=Argcount; i+=1) + { + strcpy(Y,Stak[i]); + j=DataType(Y); + for(;;) + { + if(j==vt_STRVAR) + { + strcat(Frmat,"%s"); + strcpy(Arg, join(3,Arg,",",Clean(Stak[i]))); + fprintf(Outfile,"%s%s%s%s\n",Scoot,"*",trim(Clean(Stak[i])),"=0;"); + VarCnt++; + break; + } + if(j==vt_INTEGER) + { + strcat(Frmat,"%d"); + strcpy(Arg, join(3,Arg,",&",Clean(Stak[i]))); + fprintf(Outfile,"%s%s%s\n",Scoot,Clean(Stak[i]),"=0;"); + VarCnt++; + break; + } + if(j==vt_SINGLE) + { + strcat(Frmat,"%g"); + strcpy(Arg, join(3,Arg,",&",Clean(Stak[i]))); + fprintf(Outfile,"%s%s%s\n",Scoot,Clean(Stak[i]),"=0;"); + VarCnt++; + break; + } + if(j==vt_DOUBLE) + { + strcat(Frmat,"%lG"); + strcpy(Arg, join(3,Arg,",&",Clean(Stak[i]))); + fprintf(Outfile,"%s%s%s\n",Scoot,Clean(Stak[i]),"=0;"); + VarCnt++; + break; + } + if(j==vt_LDOUBLE) + { + strcat(Frmat,"%lG"); + strcpy(Arg, join(3,Arg,",&",Clean(Stak[i]))); + fprintf(Outfile,"%s%s%s\n",Scoot,Clean(Stak[i]),"=0;"); + VarCnt++; + break; + } + // case else + { + strcat(Frmat,"%d"); + strcpy(Arg, join(3,Arg,",&",Clean(Stak[i]))); + fprintf(Outfile,"%s%s%s\n",Scoot,Clean(Stak[i]),"=0;"); + VarCnt++; + } + break; + } + } + fprintf(Outfile,"%s%s%s%s\n",Scoot,"AR_fgets_retval=fgets(InputBuffer,1048576,",FHandle,");"); + fprintf(Outfile,"%s%s\n",Scoot,"if(InputBuffer[strlen(InputBuffer)-1]== 10)"); + fprintf(Outfile,"%s%s\n",Scoot," InputBuffer[strlen(InputBuffer)-1]=0;"); + fprintf(Outfile,"%s%s%s%s%s\n",Scoot,"ScanError = scan(InputBuffer,",enc(Frmat),Arg,");\n"); + fprintf(Outfile,"%s%s\n",Scoot,"*InputBuffer=0;"); +} + + +void AddFuncs (void) +{ + char ZZ[2048]; + char Last[2048]; + *Last=0; + CloseAll(); + if((FP1=fopen(prcFile,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",prcFile); + exit(1); + } + if((Outfile=fopen(FileOut,"a"))==0) + { + fprintf(stderr,"Can't open file %s\n",FileOut); + exit(1); + } + if(ProtoType[1].Prototype[0]>0) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// ************************************"); + fprintf(Outfile,"%s%s\n","// ",BCX_STR_USR_PROCS); + fprintf(Outfile,"%s\n","// ************************************"); + fprintf(Outfile,"%s\n","\n"); + } + while(!EoF(FP1)) + { + ZZ[0]=0; + AR_fgets_retval=fgets(ZZ,1048576,FP1); + if(ZZ[strlen(ZZ)-1]==10)ZZ[strlen(ZZ)-1]=0; + if(instr_b(ZZ,"DefWindowProc")) + { + if(instr_b(Last,"return ")||instr_b(Last,"CallWindowProc")||instr_b(Last,"DefWindowProc")||instr_b(Last,"DefMDIChildProc")||instr_b(Last,"DefFrameProc")) + { + *Last=0; + continue; + } + } + fprintf(Outfile,"%s\n",ZZ); + if(str_cmp(left(ZZ,2),"//")!=0) + { + strcpy(Last,ZZ); + } + } + CloseAll(); + remove (prcFile); + remove (udtFile); + remove (datFile); + remove (cstFile); + remove (ovrFile); + remove (setFile); + remove (enuFile); +} + + +int CheckLocal (char *ZZ, int* varidx) +{ + char TT[2048]; + if(LocalVarCnt) + { + strcpy(TT,Clean(ZZ)); + RemoveAll(TT," &*()",1); + if(instr_b(TT,"[")) + { + strcpy(TT,left(TT,instr_b(TT,"[")-1)); + } + {register int i; + for(i=1; i<=LocalVarCnt; i+=1) + { + if(str_cmp(TT,LocalVars[i].VarName)==0) + { + (*varidx)=i; + return LocalVars[i].VarType; + } + } + } + } + return vt_UNKNOWN; +} + + +int CheckGlobal (char *ZZ, int* varidx) +{ + int hn; + int s; + char TT[2048]; + strcpy(TT,Clean(ZZ)); + RemoveAll(TT," &*()",1); + if(instr_b(TT,"[")) + { + strcpy(TT,left(TT,instr_b(TT,"[")-1)); + } + hn=HashNumber(TT); + while(GlobalVarHash[hn]) + { + s=GlobalVarHash[hn]; + if(str_cmp(TT,GlobalVars[s].VarName)==0) + { + (*varidx)=s; + return GlobalVars[s].VarType; + } + hn=imod(hn+1,MaxGlobalVars); + } + return vt_UNKNOWN; +} + + +int CheckType (char *ZZ) +{ + char Keyword[2048]; + int varid=0; + int i; + strcpy(Keyword,lcase(ZZ)); + for(;;) + { + if(str_cmp(Keyword,"int")==0) + { + return vt_INTEGER; + } + if(str_cmp(Keyword,"string")==0) + { + return vt_STRVAR; + } + if(str_cmp(Keyword,"char")==0) + { + return vt_CHAR; + } + if(str_cmp(Keyword,"pchar")==0) + { + return vt_PCHAR; + } + if(str_cmp(Keyword,"byte")==0) + { + return vt_BYTE; + } + if(str_cmp(Keyword,"double")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"ldouble")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"file")==0) + { + return vt_FILEPTR; + } + if(str_cmp(Keyword,"float")==0) + { + return vt_SINGLE; + } + if(str_cmp(Keyword,"bool")==0 || str_cmp(Keyword,"boolean")==0) + { + return vt_BOOL; + } + if(str_cmp(Keyword,"long")==0) + { + return vt_LONG; + } + if(str_cmp(Keyword,"dword")==0) + { + return vt_DWORD; + } + if(str_cmp(Keyword,"farproc")==0) + { + return vt_FARPROC; + } + if(str_cmp(Keyword,"void")==0) + { + return vt_VOID; + } + if(str_cmp(Keyword,"lpbyte")==0) + { + return vt_LPBYTE; + } + if(str_cmp(Keyword,"lresult")==0) + { + return vt_LRESULT; + } + if(str_cmp(Keyword,"short")==0) + { + return vt_SHORT; + } + if(str_cmp(Keyword,"ushort")==0) + { + return vt_USHORT; + } + if(str_cmp(Keyword,"uint")==0) + { + return vt_UINT; + } + if(str_cmp(Keyword,"ulong")==0) + { + return vt_ULONG; + } + if(str_cmp(Keyword,"colorref")==0) + { + return vt_COLORREF; + } + if(str_cmp(Keyword,"handle")==0) + { + return vt_HANDLE; + } + if(str_cmp(Keyword,"hdc")==0) + { + return vt_HDC; + } + if(str_cmp(Keyword,"variant")==0) + { + return vt_VARIANT; + } + break; + } + i=CheckLocal(ZZ, &varid); + if(i==vt_UNKNOWN) + { + i=DefsID(ZZ); + if(i) + { + return TypeDefs[i].TypeofDef; + } + } + else + { + return i; + } + return CheckGlobal(ZZ, &varid); +} + + +void ExportInternalConst (void) +{ + if(Use_FillArray) + { + strcpy(Src,"CONST vt_INTEGER = 2"); + PassOne=1; + Parse(Src); + Emit(); + strcpy(Src,"CONST vt_SINGLE = 3"); + PassOne=1; + Parse(Src); + Emit(); + strcpy(Src,"CONST vt_DOUBLE = 4"); + PassOne=1; + Parse(Src); + Emit(); + strcpy(Src,"CONST vt_LDOUBLE = 5"); + PassOne=1; + Parse(Src); + Emit(); + } +} + + +int RestrictedWords (char *ZZ) +{ + if(str_cmp(ZZ,"CmdLine")==0) + { + return 1; + } + if(str_cmp(ZZ,"CmdShow")==0) + { + return 1; + } + if(str_cmp(ZZ,"hInst")==0) + { + return 1; + } + if(str_cmp(ZZ,"hPrev")==0) + { + return 1; + } + if(str_cmp(ZZ,"hWnd")==0) + { + return 1; + } + if(str_cmp(ZZ,"lParam")==0) + { + return 1; + } + if(str_cmp(ZZ,"Msg")==0) + { + return 1; + } + if(str_cmp(ZZ,"wParam")==0) + { + return 1; + } + if(str_cmp(ZZ,"vt_INTEGER")==0) + { + return 1; + } + if(str_cmp(ZZ,"vt_SINGLE")==0) + { + return 1; + } + if(str_cmp(ZZ,"vt_DOUBLE")==0) + { + return 1; + } + if(str_cmp(ZZ,"vt_LDOUBLE")==0) + { + return 1; + } + return 0; +} + + +int DataType (char *ZZ) +{ + char Keyword[2048]; + int i; + if(ZZ[0]==34) + { + return vt_STRLIT; + } + if(inchr(ZZ,"$")) + { + return vt_STRVAR; + } + if(IsNumber(ZZ)) + { + return vt_NUMBER; + } + i=DefsID(ZZ); + if(i) + { + return TypeDefs[i].TypeofDef; + } + strcpy(Keyword,lcase(ZZ)); + if(str_cmp(Keyword,"strlen")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"instr")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"inchr")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"sizeof")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"tally")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"band")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"bor")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"lof")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"pos")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"qbcolor")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"split")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"dsplit")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"sgn")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"timer")==0) + { + return vt_SINGLE; + } + if(str_cmp(Keyword,"keypress()")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"getattr")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"fix")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"instrrev")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"kbhit")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"exp")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"expl")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"sinh")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"cosh")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"tanh")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"asinh")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"acosh")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"atanh")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"round")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"val")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"vall")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"iif")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"bin2dec")==0) + { + return vt_INTEGER; + } + if(str_cmp(Keyword,"hex2dec")==0) + { + return vt_INTEGER; + } + if(str_cmp(Keyword,"rnd")==0) + { + return vt_SINGLE; + } + if(str_cmp(Keyword,"frac")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"fracl")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"asin")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"asinl")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"hypot")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"hypotl")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"log")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"logl")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"log10")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"log10l")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"acos")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"acosl")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"atan")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"atanl")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"sin")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"sinl")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"cos")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"cosl")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"tan")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"tanl")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"pow")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"powl")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"sqrt")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"sqrtl")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"min")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"max")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"exist")==0) + { + return vt_DECFUNC; + } + if(str_cmp(Keyword,"abs")==0) + { + return vt_DOUBLE; + } + if(str_cmp(Keyword,"absl")==0) + { + return vt_LDOUBLE; + } + if(str_cmp(Keyword,"freefile")==0) + { + return vt_FILEPTR; + } + if(str_cmp(Keyword,"fint")==0) + { + return vt_INTEGER; + } + if(inchr(ZZ,"%")) + { + return vt_INTEGER; + } + if(inchr(ZZ,"!")) + { + return vt_SINGLE; + } + if(inchr(ZZ,"#")) + { + return vt_DOUBLE; + } + if(inchr(ZZ,"^")) + { + return vt_DOUBLE; + } + if(inchr(ZZ,"¦")) + { + return vt_LDOUBLE; + } + if(iMatchRgt(ZZ,"@")) + { + return vt_FILEPTR; + } + if(inchr(ZZ," ")) + { + return vt_UDT; + } + if(isalpha(*ZZ)) + { + return vt_INTEGER; + } + return vt_UNKNOWN; +} + + +void CloseAll (void) +{ + #if defined (__APPLE__) + if(SourceFile) + { + fclose(SourceFile); + SourceFile=NULL; + } + if(FP2) + { + fclose(FP2); + FP2=NULL; + } + if(FP3) + { + fclose(FP3); + FP3=NULL; + } + if(FP4) + { + fclose(FP4); + FP4=NULL; + } + if(FP5) + { + fclose(FP5); + FP5=NULL; + } + if(FP6) + { + fclose(FP6); + FP6=NULL; + } + if(FP7) + { + fclose(FP7); + FP7=NULL; + } + if(FP8) + { + fclose(FP8); + FP8=NULL; + } + if(FP9) + { + fclose(FP9); + FP9=NULL; + } + if(FP10) + { + fclose(FP10); + FP10=NULL; + } + if(FP11) + { + fclose(FP11); + FP11=NULL; + } + if(Outfile) + { + fclose(Outfile); + Outfile=NULL; + } + if(FP1) + { + fclose(FP1); + FP1=NULL; + } + if(ResIn) + { + fclose(ResIn); + ResIn=NULL; + } + if(ResOut) + { + fclose(ResOut); + ResOut=NULL; + } + if(UserResIn) + { + fclose(UserResIn); + UserResIn=NULL; + } + if(fpErr) + { + fclose(fpErr); + fpErr=NULL; + } + if(fpHFile) + { + fclose(fpHFile); + fpHFile=NULL; + } + if(FP68) + { + fclose(FP68); + FP68=NULL; + } + if(fpdef) + { + fclose(fpdef); + fpdef=NULL; + } + if(SaveOutfileNum) + { + fclose(SaveOutfileNum); + SaveOutfileNum=NULL; + } + #else + fcloseall(); + #endif +} + + +char * Clean (char *ZZ) +{ + char *BCX_RetStr={0}; + char Tmp[2048]; + if(inchr(ZZ,"%")) + { + if(str_cmp(trim(ZZ),"%")==0) + { + BCX_RetStr=BCX_TmpStr(strlen(" % ")); + strcpy(BCX_RetStr," % "); + return BCX_RetStr; + } + } + if(iMatchNQ(ZZ,"!=")) + { + BCX_RetStr=BCX_TmpStr(strlen(ZZ)); + strcpy(BCX_RetStr,ZZ); + return BCX_RetStr; + } + strcpy(Tmp,ZZ); + RemoveAll(Tmp,"%$#!@¦",1); + BCX_RetStr=BCX_TmpStr(strlen(Tmp)); + strcpy(BCX_RetStr,Tmp); + return BCX_RetStr; +} + + +void RemoveAll (char * Arg,char * MatchChars,int qtflag) +{ + PCHAR C=Arg; + PCHAR pmc; + while(*Arg) + { + if(qtflag) + { + if(*Arg==34) + { + *(C++)=*Arg; + while(*(++Arg)!=34) + { + *(C++)=*Arg; + if(*Arg==0) + { + return; + } + } + *(C++)=*(Arg++); + continue; + } + } + pmc=MatchChars; + while(*pmc) + { + if(*(pmc++)==*Arg) + { + goto SKIP; + } + } + *(C++)=*Arg; + +SKIP:; + Arg++; + } + *C=0; +} + + +void Warning (char * ZZ,int WarnLvl) +{ + static FILE *fErr; + memset(&fErr,0,sizeof(fErr)); + if(WarnLvl) + { + strcpy(WarnMsg, join(7,WarnMsg," Line",str(ModuleLineNos[ModuleNdx])," in Module: ",trim(Modules[ModuleNdx])," - ",ZZ)); + } + else + { + strcat(WarnMsg,ZZ); + } + strcat(WarnMsg,CRLF); + if(ErrFile) + { + if((fErr=fopen(FileErr,"a"))==0) + { + fprintf(stderr,"Can't open file %s\n",FileErr); + exit(1); + } + fprintf(fErr,"%s%s\n","WARNING ",ZZ); + if(fErr) + { + fclose(fErr); + fErr=NULL; + } + } +} + + +PCHAR GetVarTypeName (int i) +{ + static char A[2048]; + for(;;) + { + if(i==vt_INTEGER) + { + strcpy(A,"int"); + break; + } + if(i==vt_STRVAR) + { + strcpy(A,"char *"); + break; + } + if(i==vt_STRLIT) + { + strcpy(A,"STRLIT"); + break; + } + if(i==vt_UNKNOWN) + { + strcpy(A,"UNKNOWN"); + break; + } + if(i==vt_SINGLE) + { + strcpy(A,"float"); + break; + } + if(i==vt_DOUBLE) + { + strcpy(A,"double"); + break; + } + if(i==vt_LDOUBLE) + { + strcpy(A,"LDOUBLE"); + break; + } + if(i==vt_DECFUNC) + { + strcpy(A,"DECFUNC"); + break; + } + if(i==vt_NUMBER) + { + strcpy(A,"NUMBER"); + break; + } + if(i==vt_FILEPTR) + { + strcpy(A,"FILE*"); + break; + } + if(i==vt_UDT) + { + strcpy(A,"struct"); + break; + } + if(i==vt_STRUCT) + { + strcpy(A,"struct"); + break; + } + if(i==vt_UNION) + { + strcpy(A,"union"); + break; + } + if(i==vt_BOOL) + { + strcpy(A,"bool"); + break; + } + if(i==vt_CHAR) + { + strcpy(A,"char"); + break; + } + if(i==vt_CHARPTR) + { + strcpy(A,"char"); + break; + } + if(i==vt_PCHAR) + { + strcpy(A,"PCHAR"); + break; + } + if(i==vt_VOID) + { + strcpy(A,"void"); + break; + } + if(i==vt_LONG) + { + strcpy(A,"long"); + break; + } + if(i==vt_DWORD) + { + strcpy(A,"DWORD"); + break; + } + if(i==vt_FARPROC) + { + strcpy(A,"FARPROC"); + break; + } + if(i==vt_LPBYTE) + { + strcpy(A,"LPBYTE"); + break; + } + if(i==vt_LRESULT) + { + strcpy(A,"LRESULT"); + break; + } + if(i==vt_BYTE) + { + strcpy(A,"BYTE"); + break; + } + if(i==vt_SHORT) + { + strcpy(A,"short"); + break; + } + if(i==vt_USHORT) + { + strcpy(A,"USHORT"); + break; + } + if(i==vt_COLORREF) + { + strcpy(A,"COLORREF"); + break; + } + if(i==vt_UINT) + { + strcpy(A,"UINT"); + break; + } + if(i==vt_ULONG) + { + strcpy(A,"ULONG"); + break; + } + if(i==vt_HANDLE) + { + strcpy(A,"HANDLE"); + break; + } + if(i==vt_HINSTANCE) + { + strcpy(A,"HINSTANCE"); + break; + } + if(i==vt_HDC) + { + strcpy(A,"HDC"); + break; + } + if(i==vt_VARIANT) + { + strcpy(A,"VARIANT"); + break; + } + // case else + { + *A=0; + } + break; + } + return A; +} + + +int HashNumber (char *HT) +{ + char* TT; + ULONG i=0; + TT=HT; + while(*TT) + { + i<<=1; + i ^= *TT; + TT++; + } + return imod(i,MaxGlobalVars); +} + + +void AddLibrary (char *LibName) +{ + static int nTimes; + static int nLibNdx; + memset(&nLibNdx,0,sizeof(nLibNdx)); + char TempLibName[2048]; + strcpy(TempLibName,lcase(LibName)); + if(!inchr(TempLibName,DQ)&&!inchr(TempLibName,"<")) + { + strcpy(TempLibName,enc(TempLibName,60,62)); + } + if(nTimes==0) + { + {register int i; + for(i=0; i<=MaxLib-1; i+=1) + { + *Library[i]=0; + } + } + nTimes++; + strcpy(Library[0],TempLibName); + return; + } + nLibNdx=0; + while(Library[nLibNdx][0]!=0) + { + if(str_cmp(Library[nLibNdx],TempLibName)==0) + { + return; + } + nLibNdx++; + } + if(nLibNdx0) + { + return; + } + nTimes++; + if(Library[0][0]==0) + { + return; + } + fprintf(FP7,"%s\n",""); + fprintf(FP7,"%s\n","#ifndef LINUXBCX"); + fprintf(FP7,"%s\n","#if !defined( __LCC__ )"); + {register int i; + for(i=0; i<=MaxLib-1; i+=1) + { + if(Library[i][0]==0&&nCount>0) + { + goto NEXTLIB; + } + else if(Library[i][0]==0) + { + goto NEXTLIB; + } + strcpy(ltmp,Library[i]); + RemoveAll(ltmp,join(2,"<>",DQ)); + if(instr_b(RmLibs,ltmp)) + { + continue; + } + if(nCount==0) + { + nCount++; + fprintf(FP7,"%s\n","// *************************************************"); + fprintf(FP7,"%s\n","// Instruct Linker to Search Object/Import Libraries"); + fprintf(FP7,"%s\n","// *************************************************"); + } + fprintf(FP7,"%s%s%s\n","#pragma comment(lib,",enc(ltmp),")"); + } + } + +NEXTLIB:; + fprintf(FP7,"%s\n","#else"); + strcat(RmLibs,",,,,,,,,"); + {register int i; + for(i=0; i<=MaxLib-1; i+=1) + { + if(Library[i][0]==0&&nCount>0) + { + fprintf(FP7,"%s\n","// *************************************************"); + fprintf(FP7,"%s\n","// End of Object/Import Libraries To Search"); + fprintf(FP7,"%s\n","// *************************************************"); + goto LIBEND; + } + else if(Library[i][0]==0) + { + goto LIBEND; + } + if(instr_b(RmLibs,Library[i])) + { + continue; + } + if(nCount==0) + { + nCount++; + fprintf(FP7,"%s\n",""); + fprintf(FP7,"%s\n","// *************************************************"); + fprintf(FP7,"%s\n","// Instruct Linker to Search Object/Import Libraries"); + fprintf(FP7,"%s\n","// *************************************************"); + } + fprintf(FP7,"%s%s\n","#pragma lib ",Library[i]); + } + } + +LIBEND:; + fprintf(FP7,"%s\n","#endif"); + fprintf(FP7,"%s\n","#endif // LINUXBCX not defined"); +} + + +void AddGlobal (char * GlobalName,int GlobalType,int GlobalDef,char * GlobalDim,int GlobalPtr,int GlobalFS,int GlobalExtn,int iEmitted,int iConst) +{ + char FirstVar[2048]; + char SecondVar[2048]; + char Warn[2048]; + int ss; + int s; + if(RestrictedWords(GlobalName)&&TestState) + { + strcpy(Warn, join(3,"Restricted Word ",GlobalName," on Line")); + strcpy(Warn, join(4,Warn,str(ModuleLineNos[ModuleNdx])," in Module: ",trim(Modules[ModuleNdx]))); + Warning(Warn); + } + ss=HashNumber(GlobalName); + while(GlobalVarHash[ss]) + { + s=GlobalVarHash[ss]; + if(str_cmp(GlobalName,GlobalVars[s].VarName)==0) + { + if(InConditional==0||(InConditional>0&&str_cmp(InIfDef,GlobalVars[s].VarCondDef)==0)) + { + if(GlobalVars[s].VarType!=GlobalType||str_cmp(GlobalDim,GlobalVars[s].VarDim)!=0 || GlobalVars[s].VarDef!=GlobalDef) + { + strcpy(FirstVar, join(11,"Line",str(ModuleLineNos[ModuleNdx])," in Module: ",trim(Modules[ModuleNdx])," : ",GlobalName,GlobalDim," as ",GetVarTypeName(GlobalType)," ",TypeDefs[GlobalDef].VarName)); + strcpy(SecondVar, join(11,"Line",str(GlobalVars[s].VarLine)," in Module: ",GlobalVars[s].VarModule," : ",GlobalName,GlobalVars[s].VarDim," as ",GetVarTypeName(GlobalVars[s].VarType)," ",TypeDefs[GlobalVars[s].VarDef].VarName)); + strcpy(Warn, join(4,"Two Variables ",FirstVar," previously defined at ",SecondVar)); + Warning(Warn); + } + return; + } + } + ss=imod(ss+1,MaxGlobalVars); + } + GlobalVarCnt++; + if(GlobalVarCnt==MaxGlobalVars) + { + Abort("Maximum Global Variables reached."); + } + strcpy(GlobalVars[GlobalVarCnt].VarName,GlobalName); + GlobalVars[GlobalVarCnt].VarType=GlobalType; + GlobalVars[GlobalVarCnt].VarDef=GlobalDef; + strcpy(GlobalVars[GlobalVarCnt].VarDim,GlobalDim); + GlobalVars[GlobalVarCnt].VarLine=ModuleLineNos[ModuleNdx]; + GlobalVars[GlobalVarCnt].VarPntr=GlobalPtr; + GlobalVars[GlobalVarCnt].VarSF=GlobalFS; + GlobalVars[GlobalVarCnt].VarEmitFlag=iEmitted; + strcpy(GlobalVars[GlobalVarCnt].VarModule,trim(Modules[ModuleNdx])); + GlobalVars[GlobalVarCnt].VarExtn=GlobalExtn; + GlobalVars[GlobalVarCnt].VarCondLevel=InConditional; + GlobalVars[GlobalVarCnt].VarConstant=iConst; + strcpy(GlobalVars[GlobalVarCnt].VarCondDef,InIfDef); + GlobalVarHash[ss]=GlobalVarCnt; +} + + +void AddLocal (char * LocalName,int LocalType,int LocalDef,char * LocalDim,int LocalPtr,int LocalFS,int iEmitted,int iConst) +{ + int varid=0; + char FirstVar[2048]; + char SecondVar[2048]; + char Warn[2048]; + int s; + if(LocalVarCnt&&TestState) + { + if(CheckGlobal(LocalName, &varid)!=vt_UNKNOWN) + { + if(LocalDef) + { + strcpy(FirstVar, join(9,"Line",str(ModuleLineNos[ModuleNdx])," in Module: ",trim(Modules[ModuleNdx])," : ",LocalName,LocalDim," as ",TypeDefs[LocalDef].VarName)); + } + else + { + strcpy(FirstVar, join(9,"Line",str(ModuleLineNos[ModuleNdx])," in Module: ",trim(Modules[ModuleNdx])," : ",LocalName,LocalDim," as ",GetVarTypeName(LocalType))); + } + if(GlobalVars[varid].VarDef) + { + strcpy(SecondVar, join(9,"Line",str(GlobalVars[varid].VarLine)," in Module: ",GlobalVars[varid].VarModule," : ",LocalName,GlobalVars[varid].VarDim," as ",TypeDefs[GlobalVars[varid].VarDef].VarName)); + } + else + { + strcpy(SecondVar, join(9,"Line",str(GlobalVars[varid].VarLine)," in Module: ",GlobalVars[varid].VarModule," : ",LocalName,GlobalVars[varid].VarDim," as ",GetVarTypeName(GlobalVars[varid].VarType))); + } + strcpy(Warn, join(5,"Local Variable ",FirstVar,CRLF,"Has Same Name as Global ",SecondVar)); + Warning(Warn); + } + for(s=1; s<=LocalVarCnt; s+=1) + { + if(str_cmp(LocalName,LocalVars[s].VarName)==0) + { + if(LocalVars[s].VarType!=LocalType||str_cmp(LocalDim,LocalVars[s].VarDim)!=0 || LocalVars[s].VarDef!=LocalDef) + { + strcpy(FirstVar, join(11,"Line",str(ModuleLineNos[ModuleNdx])," in Module: ",trim(Modules[ModuleNdx])," : ",LocalName,LocalDim," as ",GetVarTypeName(LocalType)," ",TypeDefs[LocalDef].VarName)); + strcpy(SecondVar, join(11,"Line",str(LocalVars[s].VarLine)," in Module: ",LocalVars[s].VarModule," : ",LocalName,LocalVars[s].VarDim," as ",GetVarTypeName(LocalVars[s].VarType)," ",TypeDefs[LocalVars[s].VarDef].VarName)); + strcpy(Warn, join(4,"Two Variables ",FirstVar," previously defined at ",SecondVar)); + Warning(Warn); + } + return; + } + } + } + LocalVarCnt++; + if(LocalVarCnt==MaxLocalVars) + { + strcpy(Warn,"Maximum Local Variables reached."); + Abort(Warn); + } + strcpy(LocalVars[LocalVarCnt].VarName,LocalName); + LocalVars[LocalVarCnt].VarType=LocalType; + LocalVars[LocalVarCnt].VarDef=LocalDef; + strcpy(LocalVars[LocalVarCnt].VarDim,LocalDim); + LocalVars[LocalVarCnt].VarLine=ModuleLineNos[ModuleNdx]; + LocalVars[LocalVarCnt].VarPntr=LocalPtr; + LocalVars[LocalVarCnt].VarSF=LocalFS; + LocalVars[LocalVarCnt].VarEmitFlag=iEmitted; + LocalVars[LocalVarCnt].VarConstant=iConst; + strcpy(LocalVars[LocalVarCnt].VarModule,trim(Modules[ModuleNdx])); +} + + +int IsNumber (char *a) +{ + int i=0; + if(!*a) + { + return FALSE; + } + while(a[i]) + { + if(a[i]>47&&a[i]<58) + { + i++; + } + else + { + return FALSE; + } + } + return TRUE; +} + + +int IsNumberEx (char *a) +{ + int i=0; + if(!*a) + { + return FALSE; + } + while(a[i]) + { + if(a[i]>44&&a[i]<58) + { + i++; + } + else + { + return FALSE; + } + } + return TRUE; +} + + +void StripTabs (void) +{ + int i=0; + while(Src[i]) + { + if(Src[i]==9) + { + Src[i]=32; + } + i++; + } +} + + +void PushFileIO (void) +{ + FPtr[++FPtrNdx]=SourceFile; +} + + +void PopFileIO (void) +{ + if(FPtrNdx==0) + { + return; + } + if(SourceFile) + { + fclose(SourceFile); + SourceFile=NULL; + } + LinesRead+=(ModuleLineNos[ModuleNdx--]); + SourceFile=FPtr[FPtrNdx--]; +} + + +int Inset (char *Mane, char *Match) +{ + int i=-1; + int j=-1; + while(Match[++i]) + { + while(Mane[++j]) + { + if(Match[i]==Mane[j]) + { + return TRUE; + } + } + j=-1; + } + return FALSE; +} + + +void CheckParQuotes (void) +{ + int CountR=0; + int CountS=0; + int i=0; + bool DoCount=TRUE; + while(Src[i]) + { + if(Src[i]==34) + { + DoCount=!DoCount; + } + if(DoCount) + { + if(Src[i]==40) + { + CountR++; + } + else if(Src[i]==41) + { + CountR--; + } + else if(Src[i]==91) + { + CountS++; + } + else if(Src[i]==93) + { + CountS--; + } + } + i++; + } + if(!DoCount) + { + Abort("Unmatched Quotes"); + } + else if(CountS) + { + Abort("Unmatched []"); + } + else if(CountR) + { + Abort("Unmatched ()"); + } +} + + +void ClearIfThenStacks (void) +{ + {register int i; + for(i=0; i<=127; i+=1) + { + *SrcStk[i]=0; + } + } + SrcCnt=0; +} + + +int IsQuoted (char *ZZ) +{ + if(!iMatchLft(ltrim(ZZ),DQ)) + { + return 0; + } + if(!iMatchRgt(rtrim(ZZ),DQ)) + { + return 0; + } + return TRUE; +} + + +void PostProcess (void) +{ + int A; + if(ReDirect==TRUE) + { + if((FP1=fopen(FileOut,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",FileOut); + exit(1); + } + while(!EoF(FP1)) + { + Z[0]=0; + AR_fgets_retval=fgets(Z,1048576,FP1); + if(Z[strlen(Z)-1]==10)Z[strlen(Z)-1]=0; + printf("%s\n",Z); + } + CloseAll(); + } + strcpy(OutfileClone,FileOut); + for(A=1; A<=EntryCnt; A+=1) + { + strcpy(OutfileClone,extract(OutfileClone,".")); + strcpy(Cmd,RemoveStr(Entry[A],DQ)); + strcpy(Cmd,replace(Cmd,"\\\\","\\")); + strcpy(Cmd,iReplace(Cmd,"$file$",extract(OutfileClone,"."))); + printf("%s%s\n","Shelling Out To: ",Cmd); + Shell(Cmd); + } + if(Compiler[0]>0) + { + strcpy(Compiler,trim(RemoveStr(Compiler,DQ))); + if(inchr(Compiler," ")) + { + strcpy(Compiler, join(3,enc(extract(Compiler," "))," ",remain(Compiler," "))); + } + else + { + strcpy(Compiler,enc(Compiler)); + } + strcpy(FileOut, join(2,extract(FileOut,"."),".cc")); + strcpy(Compiler, join(3,Compiler," ",FileOut)); + strcpy(Compiler,iReplace(Compiler,"$FILE$",extract(OutfileClone,"."))); + strcpy(Compiler,replace(Compiler,"\\\\","\\")); + strcpy(Compiler,replace(Compiler,DDQ,DQ)); + printf("%s%s\n","Shelling Out To: ",Compiler); + Shell(Compiler); + } + if(Linker[0]>0) + { + strcpy(Linker,trim(RemoveStr(Linker,DQ))); + if(inchr(Linker," ")) + { + strcpy(Linker, join(5,DQ,extract(Linker," "),DQ," ",remain(Linker," "))); + } + else + { + strcpy(Linker,enc(Linker)); + } + strcpy(FileOut, join(2,extract(FileOut,"."),".obj")); + strcpy(Linker, join(3,Linker," ",FileOut)); + strcpy(Linker,iReplace(Linker,"$FILE$",extract(OutfileClone,"."))); + strcpy(Linker,replace(Linker,"\\\\","\\")); + strcpy(Linker,replace(Linker,DDQ,DQ)); + printf("%s%s\n","Shelling Out To:",Linker); + Shell(Linker); + } + for(A=1; A<=XitCount; A+=1) + { + strcpy(FileOut,extract(FileOut,".")); + strcpy(Cmd,RemoveStr(Xit[A],DQ)); + strcpy(Cmd,iReplace(Cmd,"$FILE$",extract(OutfileClone,"."))); + strcpy(Cmd,replace(Cmd,"\\\\","\\")); + strcpy(Cmd,replace(Cmd,DDQ,DQ)); + printf("%s%s\n","Shelling Out To: ",Cmd); + Shell(Cmd); + } +} + + +void XParse (char *Arg) +{ + char lszTmp[2048]; + int j; + int i=0; + int Gapflag=0; + int InIF=0; + if(str_cmp(trim(Arg),"")==0) + { + Ndx=0; + return; + } + i=iMatchNQ(Arg,"&&"); + while(i) + { + strcpy(Arg,del(Arg,i,2)); + strcpy(Arg,ins(Arg,i," and ")); + i=iMatchNQ(Arg,"&&"); + } + FastLexer(Arg,SPC,"=&()[]{}',+-*/<>?;.|:^"); + while(++i<17) + { + *Stk[i+Ndx]=0; + } + for(i=1; i<=Ndx; i+=1) + { + strcpy(Keyword1,lcase(Stk[i])); + if(Keyword1[1]!=0) + { + for(;;) + { + if(str_cmp(Keyword1,"and")==0) + { + strcpy(Stk[i],"&&"); + break; + } + if(str_cmp(Keyword1,"or")==0) + { + strcpy(Stk[i],"||"); + break; + } + if(str_cmp(Keyword1,"not")==0) + { + strcpy(Stk[i],"!"); + break; + } + if(str_cmp(Keyword1,"is")==0) + { + strcpy(Stk[i],"="); + break; + } + if(str_cmp(Keyword1,"xor")==0) + { + strcpy(Stk[i],"xor"); + break; + } + if(str_cmp(Keyword1,"if")==0 || str_cmp(Keyword1,"iif")==0 || str_cmp(Keyword1,"iif$")==0 || str_cmp(Keyword1,"case")==0 || str_cmp(Keyword1,"elseif")==0 || str_cmp(Keyword1,"while")==0) + { + InIF=1; + break; + } + if(str_cmp(Keyword1,"then")==0) + { + InIF=0; + break; + } + if(str_cmp(Keyword1,"byval")==0) + { + *Stk[i]=0; + Gapflag=TRUE; + break; + } + if(str_cmp(Keyword1,"byref")==0) + { + if(!iMatchWrd(Stk[1],"declare")&&!iMatchWrd(Stk[1],"c_declare")) + { + strcpy(ByrefVars[++ByrefCnt],Stk[i+1]); + } + for(j=i; j<=Ndx; j+=1) + { + if(str_cmp(Stk[j+1],",")==0 || str_cmp(Stk[j+1],")")==0) + { + strcpy(Stk[j],"PTR"); + break; + } + strcpy(Stk[j],Stk[j+1]); + } + break; + } + // case else + { + if(PassOne) + { + if(str_cmp(Keyword1,enc(chr(92)))==0) + { + strcpy(Stk[i],"chr$"); + InsertTokens(i,3,"(","92",")"); + i+=(3); + } + else if(TranslateSlash) + { + strcpy(Stk[i],replace(Stk[i],"\\","\\\\")); + } + } + } + break; + } + if(!InIF) + { + if(str_cmp(Stk[i],"&&")==0) + { + strcpy(Stk[i],"BAND"); + } + else if(str_cmp(Stk[i],"||")==0) + { + strcpy(Stk[i],"BOR"); + } + } + } + else + { + for(;;) + { + if((UCHAR)*(Keyword1)==38) + { + if(i<3||inchr("+&,(=",Stk[i-1])) + { + strcpy(Stk[i+1], join(2," &",Stk[i+1])); + *Stk[i]=0; + Gapflag=TRUE; + } + break; + } + if((UCHAR)*(Keyword1)==63) + { + strcpy(Stk[i],"print"); + break; + } + if((UCHAR)*(Keyword1)==45) + { + if((UCHAR)*(Stk[i+1])==62) + { + strcpy(Stk[i], join(2,"->",Stk[i+2])); + *Stk[++i]=0; + *Stk[++i]=0; + Gapflag=TRUE; + } + break; + } + if((UCHAR)*(Keyword1)==46) + { + if(IsNumber(Stk[i-1])) + { + strcpy(Stk[i], join(2,Stk[i-1],".")); + *Stk[i-1]=0; + Gapflag=TRUE; + } + if(!inchr(",)=<>*/+-^",Stk[i+1])) + { + strcpy(Stk[i], join(2,Stk[i],Stk[i+1])); + *Stk[++i]=0; + Gapflag=TRUE; + } + } + break; + } + } + } + if(Gapflag) + { + for(i=1; i<=Ndx; i+=1) + { + if(!*Stk[i]) + { + j=i+1; + while(!*Stk[j]&&(j2) + { + if(inchr("+-^%*/|&<=>,",Stk[i-2])&&str_cmp(Stk[i-1],"*")==0) + { + *Stk[i-1]=0; + } + if(iMatchLft(Stk[i]," &")) + { + strcpy(Stk[i],Stk[i]+2); + break; + } + } + else if(i==2) + { + if(str_cmp(Stk[i-1],"*")==0) + { + *Stk[i-1]=0; + } + } + strcpy(Stk[i], join(2,"*",Stk[i])); + if(str_cmp(Stk[i-1],"(")!=0 || str_cmp(Stk[i+1],")")!=0) + { + strcpy(Stk[i],enc(Stk[i],40,41)); + } + break; + } + } + } + } + } + if(iMatchWrd(Stk[1],"dim")) + { + if(iMatchWrd(Stk[Ndx-1],"static")) + { + strcpy(Stk[1],"static"); + strcpy(Stk[Ndx-1],Stk[Ndx]); + Ndx--; + } + } + strcpy(Keyword1,lcase(Stk[1])); + if(InTypeDef) + { + if(str_cmp(Keyword1,"end")!=0 && str_cmp(Keyword1,"dim")!=0 && str_cmp(Keyword1,"declare")!=0 && str_cmp(Keyword1,"type")!=0 && str_cmp(Keyword1,"union")!=0) + { + InsertTokens(0,1,"dim"); + } + } + if(!InTypeDef) + { + char lsz[2048]; + int Res=1; + strcpy(lsz, join(3,SPC,Keyword1,SPC)); + if(iMatchNQ(" dim , local , global , raw , static , shared , dynamic , auto , register , extern ",lsz)) + { + Res=1; + } + strcpy(lsz, join(3,SPC,lcase(Stk[2]),SPC)); + if(iMatchNQ(" dim , local , global , raw , static , shared , dynamic , auto , register , extern ",lsz)) + { + Res=2; + } + if(Res>0) + { + i=Ndx; + while(i>1&&str_cmp(Stk[i],")")!=0) + { + if(iMatchWrd(Stk[i],"as")) + { + if(iMatchWrd(Stk[i+1],"function")) + { + if(i+1==Ndx) + { + *Stk[i]=0; + } + *Stk[i+1]=0; + InsertTokens(Res,1,"function"); + } + else if(iMatchWrd(Stk[i+1],"sub")) + { + if(i+1==Ndx) + { + *Stk[i]=0; + } + *Stk[i+1]=0; + InsertTokens(Res,1,"sub"); + } + RemEmptyTokens(); + break; + } + i--; + } + } + } + if(InTypeDef||iMatchWrd(Stk[1],"declare")||iMatchWrd(Stk[1],"c_declare")) + { + if(iMatchWrd(Stk[2],"sub")||iMatchWrd(Stk[2],"function")) + { + {register int i; + for(i=2; i<=Ndx; i+=1) + { + if(iMatchLft(Stk[i],"as")&&iMatchWrd(Stk[i+1],"string")) + { + if(*Stk[i+2]!=42) + { + strcpy(Stk[i+1],"char *"); + } + } + } + } + } + } +} + + +void TokenSubstitutions (void) +{ + int A; + int CompPtr; + int CompToken; + char Keyword[2048]; + int a; + int i; + int j; + int Tmp; + for(i=1; i<=Ndx; i+=1) + { + if(iMatchWrd(Stk[i],"as")) + { + if(iMatchWrd(Stk[i+1],"string")) + { + if(str_cmp(Stk[i+2],"*")==0) + { + strcpy(Stk[i],"["); + strcpy(Stk[i+1],Stk[i+3]); + strcpy(Stk[i+2],"]"); + strcpy(Stk[i+3],"as"); + Ndx++; + strcpy(Stk[Ndx],"char"); + break; + } + } + } + } + for(i=1; i<=Ndx; i+=1) + { + if(!InFunc) + { + if(iMatchWrd(Stk[i],"global")) + { + strcpy(Stk[i],"dim"); + } + } + } + A=FALSE; + for(Tmp=1; Tmp<=Ndx; Tmp+=1) + { + if(*Stk[Tmp]==48&&Stk[Tmp][1]!=120&&Stk[Tmp][1]!=108) + { + strcpy(Stk[Tmp],ltrim(Stk[Tmp],48)); + if(Stk[Tmp][0]==0) + { + strcpy(Stk[Tmp],"0"); + } + } + if(iMatchWrd(Stk[Tmp],"xor")) + { + strcpy(Stk[Tmp],"^"); + } + else if(str_cmp(Stk[Tmp],"=")==0 && str_cmp(Stk[Tmp+1],">")==0) + { + strcpy(Stk[Tmp],">"); + strcpy(Stk[Tmp+1],"="); + } + else if(str_cmp(Stk[Tmp],"=")==0 && str_cmp(Stk[Tmp+1],"<")==0) + { + strcpy(Stk[Tmp],"<"); + strcpy(Stk[Tmp+1],"="); + } + else if(str_cmp(Stk[Tmp],"<")==0 && str_cmp(Stk[Tmp+1],">")==0) + { + strcpy(Stk[Tmp],"!="); + *Stk[Tmp+1]=0; + A=TRUE; + } + else if(str_cmp(Stk[Tmp],">")==0 && str_cmp(Stk[Tmp+1],"<")==0) + { + strcpy(Stk[Tmp],"!="); + *Stk[Tmp+1]=0; + A=TRUE; + } + else if(str_cmp(Stk[Tmp],"!")==0 && str_cmp(Stk[Tmp+1],"=")==0) + { + strcpy(Stk[Tmp],"!="); + *Stk[Tmp+1]=0; + A=TRUE; + } + } + if(A==TRUE) + { + RemEmptyTokens(); + } + CompToken=0; + for(Tmp=1; Tmp<=Ndx; Tmp+=1) + { + A=CheckLocal(Stk[Tmp], &i); + if(A==vt_UNKNOWN) + { + A=CheckGlobal(Stk[Tmp], &i); + } + if(A==vt_STRUCT||A==vt_UDT||A==vt_UNION) + { + CompToken=1; + } + if(iMatchWrd(Stk[Tmp],"int")&&str_cmp(Stk[Tmp+1],"(")==0) + { + strcpy(Stk[Tmp],"fint"); + } + else if(iMatchWrd(Stk[Tmp],"integer")) + { + strcpy(Stk[Tmp],"int"); + } + else if(iMatchWrd(Stk[Tmp],"fint")&&str_cmp(Stk[Tmp+1],")")==0) + { + strcpy(Stk[Tmp],"int"); + } + } + CompPtr=0; + for(Tmp=1; Tmp<=Ndx; Tmp+=1) + { + strcpy(Keyword,lcase(Stk[Tmp])); + a=inchr("abcdefghijklmnopqrstuvwxyz",Keyword); + for(;;) + { + if(a==1) + { + for(;;) + { + if(str_cmp(Keyword,"abs")==0) + { + strcpy(Stk[Tmp],"abs"); + break; + } + if(str_cmp(Keyword,"acos")==0) + { + strcpy(Stk[Tmp],"acos"); + break; + } + if(str_cmp(Keyword,"acosl")==0) + { + strcpy(Stk[Tmp],"acosl"); + break; + } + if(str_cmp(Keyword,"acosh")==0) + { + strcpy(Stk[Tmp],"acosh"); + break; + } + if(str_cmp(Keyword,"appexename$")==0) + { + strcpy(Stk[Tmp],"AppExeName$()"); + Use_AppExeName=Use_BcxSplitPath=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"appexepath$")==0) + { + strcpy(Stk[Tmp],"AppExePath$()"); + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + } + Use_AppExePath=Use_BcxSplitPath=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"ansitowide")==0) + { + strcpy(Stk[Tmp],"AnsiToWide"); + Use_AnsiToWide=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"argc")==0) + { + strcpy(Stk[Tmp],"argc"); + break; + } + if(str_cmp(Keyword,"argv")==0) + { + strcpy(Stk[Tmp],"argv"); + break; + } + if(str_cmp(Keyword,"argv$")==0) + { + strcpy(Stk[Tmp],"argv$"); + break; + } + if(str_cmp(Keyword,"asc")==0) + { + i=0; + j=GetNumArgs(Tmp+2, &i); + if(*Stk[Tmp+2]==*DQ) + { + if(j>0||*Stk[Tmp+3]!=41) + { + strcpy(Stk[Tmp],"asc"); + Use_Asc=TRUE; + } + else + { + if(str_cmp(Stk[Tmp+2],DDQ)==0) + { + strcpy(Stk[Tmp],"0"); + } + else + { + strcpy(Stk[Tmp],ltrim(str((UCHAR)*(Stk[Tmp+2]+1)))); + } + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + *Stk[Tmp+3]=0; + } + } + else + { + if(j>0) + { + strcpy(Stk[i],"+"); + } + strcpy(Stk[Tmp],"(UCHAR)*"); + } + break; + } + if(str_cmp(Keyword,"asin")==0) + { + strcpy(Stk[Tmp],"asin"); + break; + } + if(str_cmp(Keyword,"asinl")==0) + { + strcpy(Stk[Tmp],"asinl"); + break; + } + if(str_cmp(Keyword,"asinh")==0) + { + strcpy(Stk[Tmp],"asinh"); + break; + } + if(str_cmp(Keyword,"atanh")==0) + { + strcpy(Stk[Tmp],"atanh"); + break; + } + if(str_cmp(Keyword,"atn")==0 || str_cmp(Keyword,"atan")==0) + { + strcpy(Stk[Tmp],"atan"); + break; + } + if(str_cmp(Keyword,"atnl")==0 || str_cmp(Keyword,"atanl")==0) + { + strcpy(Stk[Tmp],"atanl"); + break; + } + if(str_cmp(Keyword,"auto")==0) + { + if(iMatchWrd(Stk[Tmp+1],"local")) + { + strcpy(Stk[Tmp],"dim"); + strcpy(Stk[Tmp+1],"raw"); + } + else + { + strcpy(Stk[Tmp],"auto"); + } + } + break; + } + break; + } + if(a==2) + { + for(;;) + { + if(str_cmp(Keyword,"bcopy")==0) + { + *Stk[1]=0; + for(i=Tmp+1; i<=Ndx; i+=1) + { + if(iMatchWrd(Stk[i],"to")) + { + break; + } + strcat(Stk[1],Stk[i]); + } + *Stk[2]=0; + for(i=i+1; i<=Ndx; i+=1) + { + strcat(Stk[2],Stk[i]); + } + strcpy(Src, join(7,"memmove(&",Stk[2],",&",Stk[1],",sizeof(",Stk[2],"))")); + strcpy(Src,RemoveStr(Src,"&*")); + Ndx=0; + XParse(Src); + break; + } + if(str_cmp(Keyword,"bel$")==0) + { + strcpy(Stk[Tmp],"BEL$"); + Use_BEL=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"bs$")==0) + { + strcpy(Stk[Tmp],"BS$"); + Use_BS=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"bool")==0 || str_cmp(Keyword,"boolean")==0) + { + strcpy(Stk[Tmp],"bool"); + break; + } + if(str_cmp(Keyword,"band")==0) + { + strcpy(Stk[Tmp]," BAND "); + Use_Band=TRUE; + break; + } + if(str_cmp(Keyword,"bnot")==0) + { + strcpy(Stk[Tmp]," BNOT "); + Use_Bnot=TRUE; + break; + } + if(str_cmp(Keyword,"bcx_font")==0) + { + strcpy(Stk[Tmp],ucase(Stk[Tmp])); + char tmp[2048]; + strcpy(tmp,Clean(ucase(Stk[Tmp+1]))); + for(;;) + { + if(str_cmp(tmp,".NAME")==0) + { + strcpy(Stk[Tmp+1],".lf.lfFaceName$"); + break; + } + if(str_cmp(tmp,".BOLD")==0) + { + strcpy(Stk[Tmp+1],".lf.lfWeight"); + break; + } + if(str_cmp(tmp,".UNDERLINE")==0) + { + strcpy(Stk[Tmp+1],".lf.lfUnderline"); + break; + } + if(str_cmp(tmp,".STRIKEOUT")==0) + { + strcpy(Stk[Tmp+1],".lf.lfStrikeOut"); + break; + } + if(str_cmp(tmp,".ITALIC")==0) + { + strcpy(Stk[Tmp+1],".lf.lfItalic"); + break; + } + if(str_cmp(tmp,".CHARSET")==0) + { + strcpy(Stk[Tmp+1],".lf.lfCharSet"); + break; + } + if(str_cmp(tmp,".SIZE")==0 || str_cmp(tmp,".RGB")==0) + { + strcpy(Stk[Tmp+1],tmp); + break; + } + // case else + { + strcpy(Stk[Tmp+1],Clean(Stk[Tmp+1])); + } + break; + } + break; + } + if(str_cmp(Keyword,"bcxsplitpath$")==0) + { + strcpy(Stk[Tmp],"$$BcxSplitPath$"); + Use_BcxSplitPath=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"bcxpath$")==0) + { + UseFlag=TRUE; + strcpy(Stk[Tmp],"BcxPath$()"); + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + } + break; + } + if(str_cmp(Keyword,"bcxfont")==0) + { + strcpy(Stk[Tmp],"BcxFont"); + break; + } + if(str_cmp(Keyword,"bcxsocket")==0) + { + strcpy(Stk[Tmp],"BcxSocket"); + Use_Socket=TRUE; + break; + } + if(str_cmp(Keyword,"bcxsocketsend")==0) + { + strcpy(Stk[Tmp],"BcxSocketSend"); + break; + } + if(str_cmp(Keyword,"bcxsocketread")==0) + { + strcpy(Stk[Tmp],"BcxSocketRead"); + break; + } + if(str_cmp(Keyword,"bcxsocketclose")==0) + { + strcpy(Stk[Tmp],"BcxSocketClose"); + break; + } + if(str_cmp(Keyword,"bcx_thread")==0 || str_cmp(Keyword,"bcx_threadwait")==0 || str_cmp(Keyword,"bcx_threadsuspend")==0 || str_cmp(Keyword,"bcx_threadresume")==0 || str_cmp(Keyword,"bcx_threadkill")==0 || str_cmp(Keyword,"bcx_threadend")==0) + { + strcpy(Stk[Tmp],ucase(Stk[Tmp])); + Use_Threads=TRUE; + break; + } + if(str_cmp(Keyword,"bin$")==0) + { + strcpy(Stk[Tmp],"$$Bin$"); + Use_Bin=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"bool$")==0) + { + strcpy(Stk[Tmp],"$$BoolStr$"); + Use_Boolstr=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"bin2dec")==0) + { + strcpy(Stk[Tmp],"Bin2Dec"); + Use_Bin2dec=TRUE; + break; + } + if(str_cmp(Keyword,"boolean")==0) + { + strcpy(Stk[Tmp],"BOOLEAN"); + break; + } + if(str_cmp(Keyword,"bor")==0) + { + strcpy(Stk[Tmp]," BOR "); + Use_Bor=TRUE; + break; + } + if(str_cmp(Keyword,"byte")==0) + { + strcpy(Stk[Tmp],"BYTE"); + } + break; + } + break; + } + if(a==3) + { + for(;;) + { + if(str_cmp(Keyword,"containedin")==0) + { + strcpy(Stk[Tmp],"containedin"); + Use_ContainedIn=TRUE; + break; + } + if(str_cmp(Keyword,"copyfile")==0) + { + Use_CopyFile=TRUE; + Use_Exist=Use_Lof=TRUE; + break; + } + if(str_cmp(Keyword,"cr$")==0) + { + strcpy(Stk[Tmp],"CR$"); + Use_CR=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"close#")==0) + { + strcpy(Stk[Tmp],"close"); + break; + } + if(str_cmp(Keyword,"close")==0) + { + if(str_cmp(left(Stk[Tmp+1],1),"#")==0) + { + strcpy(Stk[Tmp+1],mid(Stk[Tmp+1],2)); + } + break; + } + if(str_cmp(Keyword,"cvd")==0) + { + strcpy(Stk[Tmp],"CVD"); + Use_Cvd=TRUE; + break; + } + if(str_cmp(Keyword,"cvi")==0) + { + strcpy(Stk[Tmp],"CVI"); + Use_Cvi=TRUE; + break; + } + if(str_cmp(Keyword,"cvl")==0) + { + strcpy(Stk[Tmp],"CVL"); + Use_Cvl=TRUE; + break; + } + if(str_cmp(Keyword,"cvld")==0) + { + strcpy(Stk[Tmp],"CVLD"); + Use_Cvld=TRUE; + break; + } + if(str_cmp(Keyword,"cvs")==0) + { + strcpy(Stk[Tmp],"CVS"); + Use_Cvs=TRUE; + break; + } + if(str_cmp(Keyword,"concat")==0) + { + strcpy(Stk[Tmp],"strcat"); + break; + } + if(str_cmp(Keyword,"chr$")==0) + { + strcpy(Stk[Tmp],"$$chr$"); + Use_Chr=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"char")==0) + { + strcpy(Stk[Tmp],"char"); + break; + } + if(str_cmp(Keyword,"crlf$")==0) + { + strcpy(Stk[Tmp],"CRLF$"); + Use_Crlf=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"cbctl")==0) + { + strcpy(Stk[Tmp],"LOWORD(wParam)"); + break; + } + if(str_cmp(Keyword,"cbctlmsg")==0) + { + strcpy(Stk[Tmp],"HIWORD(wParam)"); + break; + } + if(str_cmp(Keyword,"cblparam")==0) + { + strcpy(Stk[Tmp],"lParam"); + break; + } + if(str_cmp(Keyword,"cbmsg")==0) + { + strcpy(Stk[Tmp],"Msg"); + break; + } + if(str_cmp(Keyword,"cbwparam")==0) + { + strcpy(Stk[Tmp],"wParam"); + break; + } + if(str_cmp(Keyword,"cdbl")==0) + { + strcpy(Stk[Tmp],"CDBL"); + Use_Cdbl=TRUE; + break; + } + if(str_cmp(Keyword,"chdrive")==0 || str_cmp(Keyword,"chdir")==0) + { + strcpy(Stk[Tmp],"chdir"); + break; + } + if(str_cmp(Keyword,"cint")==0) + { + strcpy(Stk[Tmp],"Cint"); + Use_Cint=TRUE; + break; + } + if(str_cmp(Keyword,"cldbl")==0) + { + strcpy(Stk[Tmp],"CLDBL"); + Use_Cldbl=TRUE; + break; + } + if(str_cmp(Keyword,"clng")==0) + { + strcpy(Stk[Tmp],"CLNG"); + Use_Clng=TRUE; + break; + } + if(str_cmp(Keyword,"cls")==0) + { + strcpy(Stk[Tmp],"cls"); + Use_Cls=Use_ESC=TRUE; + break; + } + if(str_cmp(Keyword,"color")==0 || str_cmp(Keyword,"color_fg")==0 || str_cmp(Keyword,"color_bg")==0) + { + strcpy(Stk[Tmp],lcase(Stk[Tmp])); + Use_Color=Use_Console=TRUE; + break; + } + if(str_cmp(Keyword,"command$")==0) + { + Use_Command=Use_SPC=UseFlag=TRUE; + strcpy(Stk[Tmp],"command$(-1)"); + if(str_cmp(Stk[Tmp+1],"(")==0) + { + strcpy(Stk[Tmp],"command$"); + } + break; + } + if(str_cmp(Keyword,"colorref")==0) + { + strcpy(Stk[Tmp],"COLORREF"); + break; + } + if(str_cmp(Keyword,"cos")==0) + { + strcpy(Stk[Tmp],"cos"); + break; + } + if(str_cmp(Keyword,"cosl")==0) + { + strcpy(Stk[Tmp],"cosl"); + break; + } + if(str_cmp(Keyword,"cosh")==0) + { + strcpy(Stk[Tmp],"cosh"); + break; + } + if(str_cmp(Keyword,"cbool")==0) + { + strcpy(Stk[Tmp],"CBOOL"); + static struct _functionParse fp; + memset(&fp,0,sizeof(fp)); + static int i; + memset(&i,0,sizeof(i)); + static int t; + memset(&t,0,sizeof(t)); + static int expos=0; + memset(&expos,0,sizeof(expos)); + if(SepFuncArgs(Tmp+1, &fp,TRUE)==0) + { + Abort("No argument specified in CBOOL"); + } + for(i=fp.CommaPos[0]; i<=fp.CommaPos[1]; i+=1) + { + t=inchr("!<>=",Stk[i]); + if(t) + { + if(t<4) + { + if(str_cmp(Stk[i+1],"=")==0) + { + strcpy(Stk[i], join(2,Stk[i],Stk[i+1])); + *Stk[i+1]=0; + } + else if(t==1&&str_cmp(Stk[i],"!=")!=0) + { + continue; + } + } + else + { + if(str_cmp(Stk[i+1],"=")!=0) + { + strcpy(Stk[i],"=="); + } + } + expos=i; + break; + } + } + t=DataType(Stk[expos-1]); + if(t==vt_STRLIT||t==vt_STRVAR) + { + if(expos) + { + strcpy(Stk[Tmp+1], join(2,Stk[Tmp+1],"strcmp(")); + strcpy(Stk[fp.CommaPos[1]], join(3,")",Stk[expos],"0)")); + strcpy(Stk[expos],","); + *Src=0; + for(i=1; i<=Ndx; i+=1) + { + strcpy(Src, join(3,Src,Stk[i],SPC)); + } + FastLexer(Src," ","(),"); + } + } + break; + } + if(str_cmp(Keyword,"csng")==0) + { + strcpy(Stk[Tmp],"CSNG"); + Use_Csng=TRUE; + break; + } + if(str_cmp(Keyword,"curdir$")==0) + { + strcpy(Stk[Tmp],"curdir$()"); + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + } + Use_Curdir=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"currency")==0) + { + strcpy(Stk[Tmp],"CURRENCY"); + break; + } + if(str_cmp(Keyword,"c_declare")==0) + { + strcpy(CallType,"__attribute__((cdecl)) "); + strcpy(Stk[Tmp],"declare"); + if(iMatchWrd(Stk[4],"lib")) + { + NoTypeDeclare=FALSE; + } + else + { + NoTypeDeclare=TRUE; + } + } + break; + } + break; + } + if(a==4) + { + for(;;) + { + if(str_cmp(Keyword,"declare")==0) + { + strcpy(CallType,"__attribute__((stdcall)) "); + strcpy(Stk[Tmp],"declare"); + if(!iMatchWrd(Stk[4],"lib")) + { + NoTypeDeclare=TRUE; + } + else + { + NoTypeDeclare=FALSE; + } + break; + } + if(str_cmp(Keyword,"dq$")==0) + { + strcpy(Stk[Tmp],"DQ$"); + Use_DQ=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"ddq$")==0) + { + strcpy(Stk[Tmp],"DDQ$"); + Use_DDQ=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"data$")==0) + { + strcpy(Stk[Tmp],"DATA$"); + break; + } + if(str_cmp(Keyword,"date$")==0) + { + strcpy(Stk[Tmp],"$$timef$(12)"); + Use_Time=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"delete")==0) + { + if(UseCpp==FALSE) + { + Abort("'DELETE' can only be used with C++"); + } + strcpy(Stk[Tmp],"delete "); + break; + } + if(str_cmp(Keyword,"del$")==0) + { + strcpy(Stk[Tmp],"del$"); + Use_Del=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"double")==0) + { + strcpy(Stk[Tmp],"double"); + break; + } + if(str_cmp(Keyword,"download")==0) + { + strcpy(Stk[Tmp],"Download"); + Use_Download=Use_Dynacall=TRUE; + break; + } + if(str_cmp(Keyword,"dsplit")==0) + { + strcpy(Stk[Tmp],"DSplit"); + Use_DSplit=TRUE; + Use_Remove=TRUE; + Use_StrStr=TRUE; + Use_Mid=TRUE; + Use_Left=TRUE; + Use_Instr=TRUE; + Use_Stristr=TRUE; + UseLCaseTbl=TRUE; + UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"dword")==0) + { + strcpy(Stk[Tmp],"DWORD"); + } + break; + } + break; + } + if(a==5) + { + for(;;) + { + if(str_cmp(Keyword,"extern")==0) + { + strcpy(Stk[Tmp],"extern"); + break; + } + if(str_cmp(Keyword,"enc$")==0) + { + strcpy(Stk[Tmp],"$$enc$"); + Use_Enclose=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"extract$")==0) + { + strcpy(Stk[Tmp],"$$extract$"); + Use_Extract=Use_StrStr=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"eof$")==0) + { + strcpy(Stk[Tmp],"EF$"); + Use_EOF=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"eof")==0) + { + strcpy(Stk[Tmp],"EoF"); + Use_Eof=UseFlag=TRUE; + if(DataType(Stk[Tmp+2])==vt_NUMBER) + { + strcpy(Stk[Tmp+2], join(2,"FP",Stk[Tmp+2])); + } + break; + } + if(str_cmp(Keyword,"esc$")==0) + { + strcpy(Stk[Tmp],"ESC$"); + Use_ESC=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"enum")==0) + { + if(Ndx==1||iMatchWrd(Stk[3],"enum")) + { + Use_EnumFile=TRUE; + int EnumFlag=FALSE; + fprintf(FP11,"%s\n",""); + if(Ndx==1) + { + fprintf(FP11,"%s\n","enum"); + } + else + { + fprintf(FP11,"%s%s\n","enum ",Stk[1]); + } + fprintf(FP11,"%s\n"," {"); + *Src=0; + while(!iMatchLft(Src,"end ")) + { + if(EoF(SourceFile)) + { + Abort("Unbalanced ENUM"); + } + Src[0]=0; + AR_fgets_retval=fgets(Src,1048576,SourceFile); + if(Src[strlen(Src)-1]==10)Src[strlen(Src)-1]=0; + ModuleLineNos[ModuleNdx]++; + StripCode(Src); + if(iMatchLft(Src,"$comme")) + { + Directives(); + continue; + } + strcpy(Src,trim(Src)); + if(Src[0]==0) + { + continue; + } + if(str_cmp(lcase(left(join(2,Src," "),4)),"end ")==0) + { + break; + } + else + { + if(EnumFlag==FALSE) + { + EnumFlag=TRUE; + } + else + { + fprintf(FP11,"%s\n",","); + } + } + fprintf(FP11,"%s%s"," ",rtrim(Src)); + } + *Src=0; + Ndx=0; + fprintf(FP11,"%s\n",""); + fprintf(FP11,"%s\n"," };\n"); + return; + } + strcpy(Stk[1],"enum {"); + for(j=2; j<=Ndx; j+=1) + { + strcat(Stk[1],Stk[j]); + } + strcat(Stk[1],"}"); + Ndx=1; + break; + } + if(str_cmp(Keyword,"environ$")==0) + { + strcpy(Stk[Tmp],"Environ$"); + Use_Environ=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"exist")==0) + { + strcpy(Stk[Tmp],"Exist"); + Use_Exist=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"exp")==0) + { + strcpy(Stk[Tmp],"Exp"); + Use_Exp=TRUE; + } + break; + } + break; + } + if(a==6) + { + for(;;) + { + if(str_cmp(Keyword,"freeglobals")==0) + { + strcpy(Stk[Tmp],"FreeGlobals"); + break; + } + if(str_cmp(Keyword,"ff$")==0) + { + strcpy(Stk[Tmp],"FF$"); + Use_FF=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"function")==0) + { + if(str_cmp(Stk[Tmp+1],"=")==0) + { + if(str_cmp(Stk[Tmp+2],DDQ)==0) + { + strcpy(Stk[Tmp+2],"NUL$"); + } + strcpy(Stk[Tmp],"functionreturn"); + } + break; + } + if(str_cmp(Keyword,"false")==0) + { + strcpy(Stk[Tmp],"FALSE"); + break; + } + if(str_cmp(Keyword,"file")==0) + { + strcpy(Stk[Tmp],"FILE"); + break; + } + if(str_cmp(Keyword,"findintype")==0) + { + strcpy(Stk[Tmp],"FindInType"); + Use_FindInType=TRUE; + char StMem[2048]; + char StName[2048]; + char VarName[2048]; + static struct _functionParse fp; + memset(&fp,0,sizeof(fp)); + SepFuncArgs(Tmp, &fp,TRUE); + strcpy(StMem,remain(Clean(GetArg(2, &fp)),".")); + strcpy(VarName,extract(Clean(GetArg(2, &fp)),".")); + for(j=fp.CommaPos[1]+1; j<=fp.CommaPos[2]-1; j+=1) + { + *Stk[j]=0; + } + if(CheckLocal(VarName, &i)!=vt_UNKNOWN) + { + strcpy(StName,TypeDefs[LocalVars[i].VarDef].VarName); + } + else if(CheckGlobal(VarName, &i)!=vt_UNKNOWN) + { + strcpy(StName,TypeDefs[GlobalVars[i].VarDef].VarName); + } + j=fp.CommaPos[1]+1; + strcpy(Stk[j], join(9,"(char*)",VarName," + offsetof(",StName,",",StMem,"), sizeof(",StName,")")); + break; + } + if(str_cmp(Keyword,"farproc")==0) + { + strcpy(Stk[Tmp],"FARPROC"); + break; + } + if(str_cmp(Keyword,"fillarray")==0) + { + strcpy(Stk[Tmp],"fillarray"); + Use_FillArray=TRUE; + break; + } + if(str_cmp(Keyword,"findfirst$")==0) + { + strcpy(Stk[Tmp],"findfirst$"); + j=GetNumArgs(Tmp+2); + if(j==0) + { + strcpy(Stk[Ndx],", &FindData)"); + } + Use_Findfirst=Use_Like=TRUE; + Use_BcxSplitPath=TRUE; + Use_Join=TRUE; + UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"findnext$")==0) + { + strcpy(Stk[Tmp],"findnext$"); + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + strcpy(Stk[Tmp+1],"(&FindData"); + } + else if(Tmp==Ndx) + { + Ndx++; + strcpy(Stk[Ndx],"(&FindData)"); + } + Use_Findnext=Use_Like=UseFlag=TRUE; + Use_Join=TRUE; + break; + } + if(str_cmp(Keyword,"fint")==0) + { + strcpy(Stk[Tmp],"FINT"); + Use_Fint=TRUE; + break; + } + if(str_cmp(Keyword,"fix")==0) + { + strcpy(Stk[Tmp],"FIX"); + Use_Fix=TRUE; + break; + } + if(str_cmp(Keyword,"filelocked")==0) + { + strcpy(Stk[Tmp],"FileLocked"); + Use_FileLocked=TRUE; + break; + } + if(str_cmp(Keyword,"flush")==0) + { + strcpy(Stk[Tmp],"fflush"); + break; + } + if(str_cmp(Keyword,"frac")==0) + { + strcpy(Stk[Tmp],"FRAC"); + Use_Frac=TRUE; + break; + } + if(str_cmp(Keyword,"fracl")==0) + { + strcpy(Stk[Tmp],"FRACL"); + Use_Fracl=TRUE; + break; + } + if(str_cmp(Keyword,"freefile")==0) + { + strcpy(Stk[Tmp],"FreeFile()"); + Use_Freefile=TRUE; + } + break; + } + break; + } + if(a==7) + { + for(;;) + { + if(str_cmp(Keyword,"getprocaddress")==0) + { + static char GlobalName[2048]; + memset(&GlobalName,0,sizeof(GlobalName)); + static int s; + memset(&s,0,sizeof(s)); + static int ss; + memset(&ss,0,sizeof(ss)); + static char tempA[2048]; + memset(&tempA,0,sizeof(tempA)); + strcpy(GlobalName,Stk[Tmp-2]); + ss=HashNumber(GlobalName); + while(GlobalVarHash[ss]) + { + s=GlobalVarHash[ss]; + if(str_cmp(GlobalName,GlobalVars[s].VarName)==0) + { + strcpy(tempA,TypeDefs[GlobalVars[s].VarDef].VarName); + if(GlobalVars[s].VarPntr) + { + strcat(tempA," *"); + } + } + ss=imod(ss+1,MaxGlobalVars); + } + if(tempA[0]==0) + { + static char LocalName[2048]; + memset(&LocalName,0,sizeof(LocalName)); + strcpy(LocalName,Stk[Tmp-2]); + if(LocalVarCnt) + { + {register int i; + for(i=1; i<=LocalVarCnt; i+=1) + { + if(str_cmp(LocalName,LocalVars[i].VarName)==0) + { + strcpy(tempA,TypeDefs[LocalVars[i].VarDef].VarName); + if(LocalVars[i].VarPntr) + { + strcat(tempA," *"); + } + break; + } + } + } + } + } + if(tempA[0]!=0) + { + strcpy(Stk[Tmp], join(3,"(",tempA,")dlsym")); + } + else + { + strcpy(Stk[Tmp],"dlsym"); + } + break; + } + if(str_cmp(Keyword,"getattr")==0) + { + strcpy(Stk[Tmp],"GETATTR"); + break; + } + if(str_cmp(Keyword,"getbvalue")==0) + { + strcpy(Stk[Tmp],"GetBValue"); + break; + } + if(str_cmp(Keyword,"getc")==0) + { + strcpy(Stk[Tmp],"getc"); + break; + } + if(str_cmp(Keyword,"getgvalue")==0) + { + strcpy(Stk[Tmp],"GetGValue"); + break; + } + if(str_cmp(Keyword,"getrvalue")==0) + { + strcpy(Stk[Tmp],"GetRValue"); + break; + } + if(str_cmp(Keyword,"getresource")==0) + { + strcpy(Stk[Tmp],"GetResource"); + Use_Embed=TRUE; + } + break; + } + break; + } + if(a==8) + { + for(;;) + { + if(str_cmp(Keyword,"hiword")==0) + { + strcpy(Stk[Tmp],"HIWORD"); + break; + } + if(str_cmp(Keyword,"hex$")==0) + { + strcpy(Stk[Tmp],"hex$"); + Use_Hex=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"hex2dec")==0) + { + strcpy(Stk[Tmp],"Hex2Dec"); + Use_Hex2Dec=UseLCaseTbl=TRUE; + break; + } + if(str_cmp(Keyword,"hibyte")==0) + { + strcpy(Stk[Tmp],"HIBYTE"); + break; + } + if(str_cmp(Keyword,"hide")==0) + { + strcpy(Stk[Tmp],"Hide"); + break; + } + if(str_cmp(Keyword,"hypot")==0) + { + strcpy(Stk[Tmp],"hypot"); + } + break; + } + break; + } + if(a==9) + { + for(;;) + { + if(str_cmp(Keyword,"inherits")==0) + { + strcpy(Stk[Tmp],"inherits"); + break; + } + if(str_cmp(Keyword,"instr")==0) + { + strcpy(Stk[Tmp],"instr_b"); + Use_Instr=Use_StrStr=TRUE; + Use_Stristr=UseLCaseTbl=TRUE; + break; + } + if(str_cmp(Keyword,"inchr")==0) + { + strcpy(Stk[Tmp],"inchr"); + Use_Inchr=TRUE; + break; + } + if(str_cmp(Keyword,"imod")==0) + { + strcpy(Stk[Tmp],"imod"); + Use_Imod=TRUE; + break; + } + if(str_cmp(Keyword,"iif")==0) + { + strcpy(Stk[Tmp],"iif"); + Use_Iif=TRUE; + for(i=Tmp+1; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],"=")==0) + { + if(str_cmp(Stk[i-1],"<")!=0 && str_cmp(Stk[i-1],">")!=0) + { + strcpy(Stk[i],"=="); + } + } + } + break; + } + if(str_cmp(Keyword,"iif$")==0) + { + strcpy(Stk[Tmp],"sziif$"); + Use_sziif=TRUE; + for(i=Tmp+1; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],"=")==0) + { + if(str_cmp(Stk[i-1],"<")!=0 && str_cmp(Stk[i-1],">")!=0) + { + strcpy(Stk[i],"=="); + } + } + } + break; + } + if(str_cmp(Keyword,"inkey")==0) + { + Use_InkeyD=TRUE; + Use_GetCh=TRUE; + UseFlag=TRUE; + strcpy(Stk[Tmp],"inkeyd()"); + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + } + break; + } + if(str_cmp(Keyword,"inkey$")==0) + { + Use_Inkey=TRUE; + Use_GetCh=TRUE; + UseFlag=TRUE; + strcpy(Stk[Tmp],"inkey$()"); + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + } + break; + } + if(str_cmp(Keyword,"ins$")==0) + { + strcpy(Stk[Tmp],"ins$"); + Use_Ins=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"instat")==0) + { + Use_Instat=TRUE; + strcpy(Stk[Tmp],"kbhit()"); + break; + } + if(str_cmp(Keyword,"instrrev")==0) + { + strcpy(Stk[Tmp],"InstrRev"); + Use_Instrrev=TRUE; + break; + } + if(str_cmp(Keyword,"isptr")==0) + { + strcpy(Stk[Tmp],"IsPtr"); + Use_Isptr=TRUE; + break; + } + if(str_cmp(Keyword,"ireplace$")==0) + { + strcpy(Stk[Tmp],"iReplace$"); + Use_iReplace=Use_Stristr=UseFlag=TRUE; + UseLCaseTbl=TRUE; + break; + } + if(str_cmp(Keyword,"iremove$")==0) + { + strcpy(Stk[Tmp],"IRemoveStr$"); + Use_IRemove=UseFlag=TRUE; + Use_Stristr=UseLCaseTbl=TRUE; + break; + } + if(str_cmp(Keyword,"iterate")==0) + { + strcpy(Stk[Tmp],"continue"); + } + break; + } + break; + } + if(a==10) + { + for(;;) + { + if(str_cmp(Keyword,"join$")==0) + { + strcpy(Stk[Tmp],"$$join$"); + Use_Join=UseFlag=TRUE; + } + break; + } + break; + } + if(a==11) + { + for(;;) + { + if(str_cmp(Keyword,"keypress")==0) + { + strcpy(Stk[Tmp],"keypress()"); + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + } + Use_Keypress=TRUE; + Use_GetCh=TRUE; + } + break; + } + break; + } + if(a==12) + { + for(;;) + { + if(str_cmp(Keyword,"loadfile$")==0) + { + strcpy(Stk[Tmp],"$$LoadFile$"); + Use_LoadFile=Use_Get=UseFlag=TRUE; + Use_Exist=Use_Lof=TRUE; + break; + } + if(str_cmp(Keyword,"lf$")==0) + { + strcpy(Stk[Tmp],"LF$"); + Use_LF=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"line")==0) + { + if(iMatchWrd(Stk[Tmp+1],"input")) + { + Use_Lineinput=TRUE; + strcpy(Stk[Tmp],"lineinput"); + j=Tmp+4; + *Stk[Tmp+1]=0; + for(i=Tmp+2; i<=Ndx; i+=1) + { + if(*Stk[i]==44) + { + j=i+1; + break; + } + strcpy(Stk[Tmp+1], join(2,Stk[Tmp+1],Stk[i])); + *Stk[i]=0; + } + for(i=j; i<=Ndx; i+=1) + { + strcpy(Stk[Tmp+2], join(2,Stk[Tmp+2],Stk[i])); + } + } + break; + } + if(str_cmp(Keyword,"lcase$")==0) + { + strcpy(Stk[Tmp],"$$lcase$"); + Use_Lcase=TRUE; + Use_StrUpLow=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"ldouble")==0) + { + strcpy(Stk[Tmp],"LDOUBLE"); + Use_Ldouble=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"left$")==0) + { + strcpy(Stk[Tmp],"$$left$"); + Use_Left=TRUE; + UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"long")==0) + { + strcpy(Stk[Tmp],"long"); + break; + } + if(str_cmp(Keyword,"longlong")==0) + { + strcpy(Stk[Tmp],"LONGLONG"); + break; + } + if(str_cmp(Keyword,"lpbyte")==0) + { + strcpy(Stk[Tmp],"LPBYTE"); + break; + } + if(str_cmp(Keyword,"len")==0) + { + strcpy(Stk[Tmp],"strlen"); + break; + } + if(str_cmp(Keyword,"lprint")==0) + { + strcpy(Stk[Tmp],"lprint"); + if(Tmp==Ndx) + { + Ndx++; + strcpy(Stk[Ndx],enc("")); + } + break; + } + if(str_cmp(Keyword,"lpad$")==0) + { + strcpy(Stk[Tmp],"$$lpad$"); + Use_Lpad=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"ltrim$")==0) + { + strcpy(Stk[Tmp],"$$ltrim$"); + Use_Ltrim=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"lof")==0) + { + strcpy(Stk[Tmp],"lof"); + if(DataType(Stk[Tmp+2])==vt_NUMBER) + { + strcpy(Stk[Tmp+2], join(2,"FP",Stk[Tmp+2])); + } + Use_Lof=TRUE; + break; + } + if(str_cmp(Keyword,"loadlibrary")==0 || str_cmp(Keyword,"load_dll")==0) + { + strcpy(Stk[Tmp],"LoadLibrary"); + break; + } + if(str_cmp(Keyword,"like")==0) + { + strcpy(Stk[Tmp],"like"); + Use_Like=TRUE; + break; + } + if(str_cmp(Keyword,"lobyte")==0) + { + strcpy(Stk[Tmp],"LOBYTE"); + break; + } + if(str_cmp(Keyword,"loc")==0) + { + if(DataType(Stk[Tmp+2])==vt_NUMBER) + { + strcpy(Stk[Tmp+2], join(2,"FP",Stk[Tmp+2])); + } + strcpy(Stk[Tmp], join(5,"loc(",Stk[Tmp+2],",",Stk[Tmp+2],"len)")); + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + *Stk[Tmp+3]=0; + Use_Loc=TRUE; + break; + } + if(str_cmp(Keyword,"locate")==0) + { + Use_Locate=TRUE; + break; + } + if(str_cmp(Keyword,"log")==0) + { + strcpy(Stk[Tmp],"log"); + break; + } + if(str_cmp(Keyword,"logl")==0) + { + strcpy(Stk[Tmp],"logl"); + break; + } + if(str_cmp(Keyword,"log10")==0) + { + strcpy(Stk[Tmp],"log10"); + break; + } + if(str_cmp(Keyword,"log10l")==0) + { + strcpy(Stk[Tmp],"log10l"); + break; + } + if(str_cmp(Keyword,"loword")==0) + { + strcpy(Stk[Tmp],"LOWORD"); + break; + } + if(str_cmp(Keyword,"lpstr")==0) + { + strcpy(Stk[Tmp],"PCHAR"); + } + break; + } + break; + } + if(a==13) + { + for(;;) + { + if(str_cmp(Keyword,"mkd$")==0) + { + if(Tmp>2) + { + if(inchr(Stk[Tmp-2],"$")&&*Stk[Tmp-1]==61) + { + strcpy(Stk[1], join(2,"memcpy(",Stk[1])); + strcpy(Stk[Tmp-1],","); + strcpy(Stk[++Ndx],",9)"); + } + } + strcpy(Stk[Tmp],"MKD"); + Use_Mkd=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"mki$")==0) + { + if(Tmp>2) + { + if(inchr(Stk[Tmp-2],"$")&&*Stk[Tmp-1]==61) + { + strcpy(Stk[1], join(2,"memcpy(",Stk[1])); + strcpy(Stk[Tmp-1],","); + strcpy(Stk[++Ndx],",3)"); + } + } + strcpy(Stk[Tmp],"MKI"); + Use_Mki=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"mkl$")==0) + { + if(Tmp>2) + { + if(inchr(Stk[Tmp-2],"$")&&*Stk[Tmp-1]==61) + { + strcpy(Stk[1], join(2,"memcpy(",Stk[1])); + strcpy(Stk[Tmp-1],","); + strcpy(Stk[++Ndx],",5)"); + } + } + strcpy(Stk[Tmp],"MKL"); + Use_Mkl=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"mkld$")==0) + { + if(Tmp>2) + { + if(inchr(Stk[Tmp-2],"$")&&*Stk[Tmp-1]==61) + { + strcpy(Stk[1], join(2,"memcpy(",Stk[1])); + strcpy(Stk[Tmp-1],","); + strcpy(Stk[++Ndx],",11)"); + } + } + strcpy(Stk[Tmp],"MKLD"); + Use_Mkld=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"mks$")==0) + { + if(Tmp>2) + { + if(inchr(Stk[Tmp-2],"$")&&*Stk[Tmp-1]==61) + { + strcpy(Stk[1], join(2,"memcpy(",Stk[1])); + strcpy(Stk[Tmp-1],","); + strcpy(Stk[++Ndx],",5)"); + } + } + strcpy(Stk[Tmp],"MKS"); + Use_Mks=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"mid$")==0) + { + if(Tmp>1) + { + strcpy(Stk[Tmp],"$$mid$"); + Use_Mid=UseFlag=TRUE; + } + else + { + strcpy(Stk[Tmp],"midstr"); + Use_Midstr=UseFlag=TRUE; + } + break; + } + if(str_cmp(Keyword,"min")==0) + { + strcpy(Stk[Tmp],"_MIN_"); + Use_Min=TRUE; + break; + } + if(str_cmp(Keyword,"main")==0) + { + strcpy(Stk[Tmp],"main"); + break; + } + if(str_cmp(Keyword,"makeintresource")==0) + { + strcpy(Stk[Tmp],"MAKEINTRESOURCE"); + break; + } + if(str_cmp(Keyword,"makelong")==0) + { + strcpy(Stk[Tmp],"MAKELONG"); + break; + } + if(str_cmp(Keyword,"makeword")==0) + { + strcpy(Stk[Tmp],"MAKEWORD"); + break; + } + if(str_cmp(Keyword,"max")==0) + { + strcpy(Stk[Tmp],"_MAX_"); + Use_Max=TRUE; + break; + } + if(str_cmp(Keyword,"mcase$")==0) + { + strcpy(Stk[Tmp],"$$mcase$"); + Use_Mcase=UseFlag=TRUE; + Use_StrUpLow=TRUE; + break; + } + if(str_cmp(Keyword,"mkdir")==0) + { + strcpy(Stk[Tmp],"mkdir"); + break; + } + if(str_cmp(Keyword,"mod")==0) + { + strcpy(Stk[Tmp],"fmod"); + } + break; + } + break; + } + if(a==14) + { + for(;;) + { + if(str_cmp(Keyword,"new")==0) + { + if(iMatchWrd(Stk[Tmp-1],"binary")) + { + break; + } + if(UseCpp==FALSE) + { + Abort("'NEW' can only be used with C++"); + } + strcpy(Stk[Tmp],"new "); + break; + } + if(str_cmp(Keyword,"nul$")==0) + { + strcpy(Stk[Tmp],"NUL$"); + Use_NUL=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"null")==0) + { + strcpy(Stk[Tmp],"NULL"); + break; + } + if(str_cmp(Keyword,"now$")==0) + { + strcpy(Stk[Tmp],"now$()"); + Use_Now=UseFlag=TRUE; + } + break; + } + break; + } + if(a==15) + { + for(;;) + { + if(str_cmp(Keyword,"open")==0) + { + for(A=Tmp+1; A<=Ndx; A+=1) + { + if(str_cmp(left(Stk[A],1),"#")==0) + { + strcpy(Stk[A],mid(Stk[A],2)); + break; + } + } + break; + } + if(str_cmp(Keyword,"oct$")==0) + { + strcpy(Stk[Tmp],"oct$"); + Use_Oct=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"osversion")==0) + { + strcpy(Stk[Tmp],"OSVersion()"); + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + } + Use_OSVersion=TRUE; + } + break; + } + break; + } + if(a==16) + { + for(;;) + { + if(str_cmp(Keyword,"pause")==0) + { + strcpy(Stk[Tmp],"Pause()"); + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + } + Use_Pause=Use_Keypress=TRUE; + Use_GetCh=TRUE; + break; + } + if(str_cmp(Keyword,"preserve")==0) + { + strcpy(Stk[Tmp],"PRESERVE"); + break; + } + if(str_cmp(Keyword,"print#")==0) + { + strcpy(Stk[Tmp],"fprint"); + break; + } + if(str_cmp(Keyword,"print")==0) + { + if(str_cmp(left(Stk[Tmp+1],1),"#")==0) + { + strcpy(Stk[Tmp],"fprint"); + strcpy(Stk[Tmp+1],mid(Stk[Tmp+1],2)); + } + break; + } + if(str_cmp(Keyword,"ptr")==0) + { + CompPtr=1; + strcpy(Stk[Tmp-1], join(2,Stk[Tmp-1],"*")); + *Stk[Tmp]=0; + if(Tmp==Ndx) + { + Ndx--; + while(tally(Stk[Ndx],"*")==strlen(Stk[Ndx])) + { + strcpy(Stk[Ndx-1], join(2,Stk[Ndx-1],Stk[Ndx])); + *Stk[Ndx]=0; + Ndx--; + } + } + else + { + i=Tmp-1; + while(tally(Stk[i],"*")==strlen(Stk[i])) + { + strcpy(Stk[i-1], join(2,Stk[i-1],Stk[i])); + *Stk[i]=0; + i--; + } + } + break; + } + if(str_cmp(Keyword,"peek$")==0) + { + strcpy(Stk[Tmp],"$$peekstr$"); + Use_PeekStr=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"poke")==0) + { + strcpy(Stk[Tmp],"memmove"); + break; + } + if(str_cmp(Keyword,"pow")==0) + { + strcpy(Stk[Tmp],"pow"); + break; + } + if(str_cmp(Keyword,"powl")==0) + { + strcpy(Stk[Tmp],"powl"); + break; + } + if(str_cmp(Keyword,"private")==0) + { + if(UseCpp) + { + strcpy(Stk[Tmp],"private"); + } + if(iMatchWrd(Stk[Tmp+1],"const")) + { + strcpy(Stk[Tmp],"enum "); + strcpy(Stk[Tmp+1], join(2,Stk[Tmp+2],"{")); + Ndx++; + strcpy(Stk[Ndx],"}"); + } + break; + } + if(str_cmp(Keyword,"public")==0) + { + if(UseCpp) + { + strcpy(Stk[Tmp],"public"); + } + } + break; + } + break; + } + if(a==17) + { + for(;;) + { + if(str_cmp(Keyword,"qbcolor")==0) + { + strcpy(Stk[Tmp],"qbcolor"); + Use_QBColor=TRUE; + } + break; + } + break; + } + if(a==18) + { + for(;;) + { + if(str_cmp(Keyword,"regmatch")==0) + { + strcpy(Stk[Tmp],"regmatch"); + Use_PeekStr=Use_RegEx=TRUE; + break; + } + if(str_cmp(Keyword,"rewind")==0) + { + strcpy(Stk[Tmp],"rewind"); + if(DataType(Stk[Tmp+2])==vt_NUMBER) + { + strcpy(Stk[Tmp+2], join(2,"FP",Stk[Tmp+2])); + } + break; + } + if(str_cmp(Keyword,"remove$")==0) + { + strcpy(Stk[Tmp],"$$RemoveStr$"); + Use_Remove=Use_StrStr=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"replace$")==0) + { + strcpy(Stk[Tmp],"$$replace$"); + Use_Replace=Use_StrStr=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"right$")==0) + { + strcpy(Stk[Tmp],"$$right$"); + Use_Right=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"rename")==0) + { + strcpy(Stk[Tmp],"rename"); + break; + } + if(str_cmp(Keyword,"register")==0) + { + strcpy(Stk[Tmp],"register"); + break; + } + if(str_cmp(Keyword,"randomize")==0) + { + strcpy(Stk[Tmp],"randomize"); + Use_Randomize=TRUE; + Use_Rnd=TRUE; + if(Ndx==1) + { + Use_Timer=TRUE; + strcpy(Stk[1],"randomize(timer())"); + } + break; + } + if(str_cmp(Keyword,"rec")==0) + { + if(DataType(Stk[Tmp+2])==vt_NUMBER) + { + strcpy(Stk[Tmp+2], join(2,"FP",Stk[Tmp+2])); + } + strcpy(Stk[Tmp], join(5,"rec(",Stk[Tmp+2],",",Stk[Tmp+2],"len)")); + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + *Stk[Tmp+3]=0; + Use_Rec=TRUE; + break; + } + if(str_cmp(Keyword,"reccount")==0) + { + char length[2048]; + if(DataType(Stk[Tmp+2])==vt_NUMBER) + { + strcpy(Stk[Tmp+2], join(2,"FP",Stk[Tmp+2])); + } + strcpy(Stk[Tmp],"reccount"); + strcpy(length, join(2,Stk[Tmp+2],"len)")); + for(i=Tmp+1; i<=Ndx; i+=1) + { + if(*Stk[i]==41) + { + *Stk[i]=0; + break; + } + strcpy(Stk[Tmp], join(2,Stk[Tmp],Stk[i])); + *Stk[i]=0; + } + strcpy(Stk[Tmp], join(3,Stk[Tmp],",",length)); + Use_RecCount=TRUE; + break; + } + if(str_cmp(Keyword,"reclen")==0) + { + strcpy(Stk[Tmp],"reclen"); + break; + } + if(str_cmp(Keyword,"record")==0) + { + strcpy(Stk[Tmp],"record"); + break; + } + if(str_cmp(Keyword,"remain$")==0) + { + strcpy(Stk[Tmp],"$$remain$"); + Use_Remain=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"retain$")==0) + { + strcpy(Stk[Tmp],"$$Retain$"); + Use_Retain=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"repeat$")==0) + { + strcpy(Stk[Tmp],"$$repeat$"); + Use_Repeat=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"reverse$")==0) + { + strcpy(Stk[Tmp],"$$reverse$"); + Use_Reverse=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"rgb")==0) + { + strcpy(Stk[Tmp],"RGB"); + break; + } + if(str_cmp(Keyword,"rmdir")==0) + { + strcpy(Stk[Tmp],"rmdir"); + break; + } + if(str_cmp(Keyword,"rnd")==0) + { + strcpy(Stk[Tmp],"rnd()"); + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + } + Use_Rnd=TRUE; + break; + } + if(str_cmp(Keyword,"round")==0) + { + strcpy(Stk[Tmp],"Round"); + Use_Round=TRUE; + break; + } + if(str_cmp(Keyword,"rpad$")==0) + { + strcpy(Stk[Tmp],"$$rpad$"); + Use_Rpad=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"rtrim$")==0) + { + strcpy(Stk[Tmp],"$$rtrim$"); + Use_Rtrim=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"run")==0) + { + strcpy(Stk[Tmp],"Run"); + Use_Run=TRUE; + } + break; + } + break; + } + if(a==19) + { + for(;;) + { + if(str_cmp(Keyword,"scanerror")==0) + { + strcpy(Stk[Tmp],"ScanError"); + break; + } + if(str_cmp(Keyword,"sprint")==0) + { + strcpy(Stk[Tmp],"sprint"); + break; + } + if(str_cmp(Keyword,"spc$")==0) + { + strcpy(Stk[Tmp],"SPC$"); + Use_SPC=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"str$")==0) + { + strcpy(Stk[Tmp],"$$str$"); + Use_Str=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"strl$")==0) + { + strcpy(Stk[Tmp],"$$strl$"); + Use_Strl=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"searchpath$")==0) + { + strcpy(Stk[Tmp],"$$SEARCHPATH$"); + Use_SearchPath=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"sizeof")==0) + { + strcpy(Stk[Tmp],"sizeof"); + break; + } + if(str_cmp(Keyword,"setattr")==0) + { + strcpy(Stk[Tmp],"SETATTR"); + break; + } + if(str_cmp(Keyword,"setwindowrtftext")==0) + { + strcpy(Stk[Tmp],"SetWindowRTFText"); + break; + } + if(str_cmp(Keyword,"sgn")==0) + { + strcpy(Stk[Tmp],"sgn"); + Use_Sgn=TRUE; + break; + } + if(str_cmp(Keyword,"short")==0) + { + strcpy(Stk[Tmp],"short"); + break; + } + if(str_cmp(Keyword,"shell")==0) + { + Use_Shell=TRUE; + break; + } + if(str_cmp(Keyword,"show")==0) + { + strcpy(Stk[Tmp],"Show"); + break; + } + if(str_cmp(Keyword,"sin")==0) + { + strcpy(Stk[Tmp],"sin"); + break; + } + if(str_cmp(Keyword,"sinl")==0) + { + strcpy(Stk[Tmp],"sinl"); + break; + } + if(str_cmp(Keyword,"single")==0) + { + strcpy(Stk[Tmp],"float"); + break; + } + if(str_cmp(Keyword,"sinh")==0) + { + strcpy(Stk[Tmp],"sinh"); + break; + } + if(str_cmp(Keyword,"sleep")==0) + { + strcpy(Stk[Tmp],"sleep"); + break; + } + if(str_cmp(Keyword,"space$")==0) + { + strcpy(Stk[Tmp],"$$space$"); + Use_Space=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"split")==0) + { + strcpy(Stk[Tmp],"Split"); + Use_Split=UseFlag=TRUE; + Use_Remove=TRUE; + Use_StrStr=TRUE; + Use_Mid=TRUE; + Use_Left=TRUE; + Use_Instr=TRUE; + Use_Stristr=TRUE; + UseLCaseTbl=TRUE; + break; + } + if(str_cmp(Keyword,"splitbarfg")==0) + { + strcpy(Stk[Tmp],"SplitBarFG"); + break; + } + if(str_cmp(Keyword,"splitbarbg")==0) + { + strcpy(Stk[Tmp],"SplitBarBG"); + break; + } + if(str_cmp(Keyword,"sqr")==0 || str_cmp(Keyword,"sqrt")==0) + { + strcpy(Stk[Tmp],"sqrt"); + break; + } + if(str_cmp(Keyword,"sqrl")==0 || str_cmp(Keyword,"sqrtl")==0) + { + strcpy(Stk[Tmp],"sqrtl"); + break; + } + if(str_cmp(Keyword,"strarray")==0) + { + strcpy(Stk[Tmp],"PCHAR*"); + break; + } + if(str_cmp(Keyword,"strim$")==0) + { + strcpy(Stk[Tmp],"$$strim$"); + Use_Strim=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"string")==0) + { + strcpy(Stk[Tmp],"string"); + break; + } + if(str_cmp(Keyword,"string$")==0) + { + strcpy(Stk[Tmp],"$$stringx$"); + Use_String=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"strptr")==0) + { + strcpy(Stk[Tmp],"STRPTR"); + Use_Strptr=TRUE; + break; + } + if(str_cmp(Keyword,"strtoken$")==0) + { + strcpy(Stk[Tmp],"StrToken$"); + Use_Strtoken=Use_Mid=Use_Left=Use_Extract=TRUE; + Use_Instr=Use_Instrrev=Use_Stristr=Use_Tally=Use_Remove=TRUE; + Use_StrStr=UseLCaseTbl=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"swap")==0) + { + strcpy(Stk[Tmp],"swap"); + Use_Swap=TRUE; + break; + } + if(str_cmp(Keyword,"sysdir$")==0) + { + strcpy(Stk[Tmp],"$$sysdir$()"); + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + } + Use_Sysdir=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"sysstr")==0) + { + strcpy(Stk[Tmp],"SysStr"); + Use_SysStr=TRUE; + } + break; + } + break; + } + if(a==20) + { + for(;;) + { + if(str_cmp(Keyword,"tab$")==0) + { + strcpy(Stk[Tmp],"TAB$"); + Use_TAB=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"true")==0) + { + strcpy(Stk[Tmp],"TRUE"); + break; + } + if(str_cmp(Keyword,"trim$")==0) + { + strcpy(Stk[Tmp],"$$trim$"); + Use_Trim=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"tally")==0) + { + strcpy(Stk[Tmp],"tally"); + Use_Tally=UseLCaseTbl=Use_Stristr=Use_StrStr=TRUE; + break; + } + if(str_cmp(Keyword,"tan")==0) + { + strcpy(Stk[Tmp],"tan"); + break; + } + if(str_cmp(Keyword,"tanh")==0) + { + strcpy(Stk[Tmp],"tanh"); + break; + } + if(str_cmp(Keyword,"tanl")==0) + { + strcpy(Stk[Tmp],"tanl"); + break; + } + if(str_cmp(Keyword,"tempdir$")==0) + { + strcpy(Stk[Tmp],"$$tempdir$()"); + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + } + Use_Tempdir=UseFlag=Use_Exist=TRUE; + break; + } + if(str_cmp(Keyword,"tempfilename$")==0) + { + strcpy(Stk[Tmp],"$$TempFileName$"); + Use_TempFileName=UseFlag=TRUE; + Use_Exist=Use_Rnd=TRUE; + break; + } + if(str_cmp(Keyword,"this")==0) + { + strcpy(Stk[Tmp],"this"); + if(*Stk[Tmp+1]==46) + { + strcpy(Stk[Tmp+1], join(2,"->",mid(Stk[Tmp+1],2))); + } + break; + } + if(str_cmp(Keyword,"time$")==0) + { + if(str_cmp(Stk[Tmp+1],"(")!=0) + { + strcpy(Stk[Tmp],"$$timef$()"); + } + else + { + strcpy(Stk[Tmp],"$$timef$"); + } + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + } + Use_Time=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"timer")==0) + { + strcpy(Stk[Tmp],"timer()"); + if(str_cmp(Stk[Tmp+1],"(")==0 && str_cmp(Stk[Tmp+2],")")==0) + { + *Stk[Tmp+1]=0; + *Stk[Tmp+2]=0; + } + Use_Timer=TRUE; + } + break; + } + break; + } + if(a==21) + { + for(;;) + { + if(str_cmp(Keyword,"uint")==0) + { + strcpy(Stk[Tmp],"UINT"); + break; + } + if(str_cmp(Keyword,"ushort")==0) + { + strcpy(Stk[Tmp],"USHORT"); + break; + } + if(str_cmp(Keyword,"ulong")==0) + { + strcpy(Stk[Tmp],"ULONG"); + break; + } + if(str_cmp(Keyword,"ulonglong")==0) + { + strcpy(Stk[Tmp],"ULONGLONG"); + break; + } + if(str_cmp(Keyword,"ucase$")==0) + { + strcpy(Stk[Tmp],"$$ucase$"); + Use_Ucase=UseFlag=TRUE; + Use_StrUpLow=TRUE; + break; + } + if(str_cmp(Keyword,"ubound")==0) + { + strcpy(Stk[Tmp],"ubound"); + Use_Ubound=TRUE; + break; + } + if(str_cmp(Keyword,"using$")==0) + { + strcpy(Stk[Tmp],"$$Using$"); + Use_Using=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"using")==0) + { + strcpy(Stk[Tmp],"using"); + } + break; + } + break; + } + if(a==22) + { + for(;;) + { + if(str_cmp(Keyword,"val")==0) + { + strcpy(Stk[Tmp],"VAL"); + Use_Val=TRUE; + break; + } + if(str_cmp(Keyword,"vall")==0) + { + strcpy(Stk[Tmp],"VALL"); + Use_Vall=TRUE; + break; + } + if(str_cmp(Keyword,"variant")==0) + { + strcpy(Stk[Tmp],"VARIANT"); + break; + } + if(str_cmp(Keyword,"varptr")==0) + { + *Stk[Tmp]=0; + break; + } + if(str_cmp(Keyword,"vchr$")==0) + { + strcpy(Stk[Tmp],"$$vchr$"); + Use_VChr=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"virtual")==0) + { + strcpy(Stk[Tmp],"virtual"); + Use_Virtual=TRUE; + break; + } + if(str_cmp(Keyword,"vt$")==0) + { + strcpy(Stk[Tmp],"VT$"); + Use_VT=UseFlag=TRUE; + break; + } + if(str_cmp(Keyword,"verify")==0) + { + strcpy(Stk[Tmp],"Verify"); + Use_Verify=Use_Mid=UseFlag=TRUE; + } + break; + } + break; + } + if(a==23) + { + for(;;) + { + if(str_cmp(Keyword,"widetoansi$")==0) + { + strcpy(Stk[Tmp],"$$WideToAnsi$"); + Use_WideToAnsi=UseFlag=TRUE; + } + break; + } + } + break; + } + } + if(CompPtr==1) + { + RemEmptyTokens(); + } + if(WithCnt) + { + for(i=1; i<=Ndx; i+=1) + { + if(str_cmp(left(Stk[i],2),"->")==0 || ( str_cmp(left(Stk[i],1),".")==0 && !IsNumber(mid(Stk[i],2,1)))) + { + if(str_cmp(WithVar[WithCnt],"this")==0) + { + strcpy(Stk[i], join(2,"->",mid(Stk[i],2))); + } + if(i==1) + { + strcpy(Stk[i], join(2,WithVar[WithCnt],Stk[i])); + } + else + { + if(!IsReservedWord(Stk[i-1])) + { + if(!(isalpha(Stk[i-1][strlen(Stk[i-1]-1)])||IsNumber(right(Stk[i-1],strlen(Stk[i-1]-1))))) + { + strcpy(Stk[i], join(2,WithVar[WithCnt],Stk[i])); + } + } + else + { + strcpy(Stk[i], join(2,WithVar[WithCnt],Stk[i])); + } + } + while((isalpha(*Stk[i+1])||*Stk[i+1]==46)&&(i")==0) + { + InBrace--; + } + } + break; + } + if((DoJoin||inchr(",+-*/^;:<>~|&",t))&&!OnlyPara&&!InBrace) + { + DoJoin=0; + if(j) + { + strcpy(Stk[sj], join(4,"join$(",str(j+1),",",Stk[sj])); + j=sj; + j++; + while(j=",Stk[CntMarker])); + } + } + if(j==1) + { + *Src=0; + for(i=1; i<=Ndx; i+=1) + { + strcpy(Src, join(3,Src,Stk[i]," ")); + } + XParse(Src); + } + return; + } + break; + } + if(a==4) + { + if(str_cmp(Keyword,"declare")==0 && iMatchWrd(Stk[4],"lib")) + { + char alias[2048]; + int i; + int idx=-1; + char AR_DllName[2048]; + strcpy(Stk[5],RemoveStr(Stk[5],DQ)); + for(i=0; i<=LoadLibsCnt-1; i+=1) + { + if(str_cmp(Stk[5],Loadlibs[i])==0) + { + idx=i; + break; + } + } + if(idx<0) + { + strcpy(Loadlibs[LoadLibsCnt],Stk[5]); + LoadLibsCnt++; + } + if(iMatchWrd(Stk[6],"alias")) + { + strcpy(alias,Stk[7]); + *Stk[6]=0; + *Stk[7]=0; + } + else + { + strcpy(alias,enc(Stk[3])); + } + DllCnt++; + if(DllCnt>799) + { + Abort("Maximum number of declarations exceded."); + } + if(inchr(Stk[5],"-")) + { + strcpy(AR_DllName,extract(Stk[5],"-")); + } + else if(inchr(Stk[5],".")) + { + strcpy(AR_DllName,extract(Stk[5],".")); + } + strcpy(DllDecl[DllCnt], join(11,"static BCXFPROT",ltrim(str(DllCnt)),SPC,Clean(Stk[3]),"=(BCXFPROT",ltrim(str(DllCnt)),")dlsym(H_",ucase(AR_DllName),", ",alias,");")); + *Stk[4]=0; + *Stk[5]=0; + return; + } + break; + } + if(a==7) + { + if(str_cmp(Keyword,"get$")==0) + { + strcpy(Stk[1],"~get"); + return; + } + if(str_cmp(Keyword,"global")==0 && iMatchWrd(Stk[2],"dynamic")) + { + strcpy(Stk[1],"global"); + return; + } + break; + } + if(a==9) + { + if(str_cmp(Keyword,"iremove")==0) + { + char Mat[2048]; + char Fat[2048]; + *Mat=0; + *Fat=0; + for(i=2; i<=Ndx; i+=1) + { + if(iMatchWrd(Stk[i],"from")) + { + *Stk[i]=0; + break; + } + } + for(j=2; j<=i; j+=1) + { + strcat(Mat,Stk[j]); + } + for(j=i; j<=Ndx; j+=1) + { + strcat(Fat,Stk[j]); + } + strcpy(lszTmp, join(5,"=iremove$(",Fat,",",Mat,")")); + FastLexer(Fat," ()",""); + strcpy(lszTmp, join(2,Stk[Ndx],lszTmp)); + XParse(lszTmp); + TokenSubstitutions(); + Emit(); + Ndx=0; + return; + } + if(str_cmp(Keyword,"ireplace")==0) + { + if(Ndx<6) + { + Abort("Problem with IREPLACE statement"); + } + int W; + int I; + char VV[2048]; + char RR[2048]; + char WW[2048]; + *VV=0; + *RR=0; + *WW=0; + for(W=2; W<=Ndx; W+=1) + { + if(iMatchWrd(Stk[W],"with")) + { + *Stk[W]=0; + break; + } + } + for(I=2; I<=Ndx; I+=1) + { + if(iMatchWrd(Stk[I],"in")) + { + *Stk[I]=0; + break; + } + } + i=I+1; + for(j=i; j<=Ndx; j+=1) + { + strcat(VV,Stk[j]); + } + for(j=2; j<=W; j+=1) + { + strcat(RR,Stk[j]); + } + i=W+1; + for(j=i; j<=I; j+=1) + { + strcat(WW,Stk[j]); + } + strcpy(lszTmp, join(7,"=ireplace$(",VV,",",RR,",",WW,")")); + FastLexer(VV," ()",""); + strcpy(lszTmp, join(2,Stk[Ndx],lszTmp)); + XParse(lszTmp); + TokenSubstitutions(); + Emit(); + Ndx=0; + return; + } + break; + } + if(a==12) + { + if(str_cmp(Keyword,"local")==0 && iMatchWrd(Stk[2],"dynamic")) + { + strcpy(Stk[1],"dim"); + return; + } + break; + } + if(a==16) + { + if(str_cmp(Keyword,"put$")==0) + { + strcpy(Stk[1],"~put"); + return; + } + break; + } + if(a==18) + { + if(str_cmp(Keyword,"remove")==0) + { + char Mat[2048]; + char Fat[2048]; + *Mat=0; + *Fat=0; + for(i=2; i<=Ndx; i+=1) + { + if(iMatchWrd(Stk[i],"from")) + { + *Stk[i]=0; + break; + } + } + for(j=2; j<=i; j+=1) + { + strcat(Mat,Stk[j]); + } + for(j=i; j<=Ndx; j+=1) + { + strcat(Fat,Stk[j]); + } + strcpy(lszTmp, join(5,"=remove$(",Fat,",",Mat,")")); + FastLexer(Fat," ()",""); + strcpy(lszTmp, join(2,Stk[Ndx],lszTmp)); + XParse(lszTmp); + TokenSubstitutions(); + Emit(); + Ndx=0; + return; + } + if(str_cmp(Keyword,"replace")==0) + { + if(Ndx<6) + { + Abort("Problem with REPLACE statement"); + } + int W; + int I; + char VV[2048]; + char RR[2048]; + char WW[2048]; + *VV=0; + *RR=0; + *WW=0; + for(W=2; W<=Ndx; W+=1) + { + if(iMatchWrd(Stk[W],"with")) + { + *Stk[W]=0; + break; + } + } + for(I=2; I<=Ndx; I+=1) + { + if(iMatchWrd(Stk[I],"in")) + { + *Stk[I]=0; + break; + } + } + i=I+1; + for(j=i; j<=Ndx; j+=1) + { + strcat(VV,Stk[j]); + } + for(j=2; j<=W; j+=1) + { + strcat(RR,Stk[j]); + } + i=W+1; + for(j=i; j<=I; j+=1) + { + strcat(WW,Stk[j]); + } + strcpy(lszTmp, join(7,"=replace$(",VV,",",RR,",",WW,")")); + FastLexer(VV," ()",""); + strcpy(lszTmp, join(2,Stk[Ndx],lszTmp)); + XParse(lszTmp); + TokenSubstitutions(); + Emit(); + Ndx=0; + return; + } + break; + } + if(a==27) + { + for(;;) + { + if(str_cmp(Keyword,"$ifndef")==0) + { + strcpy(Stk[1],"~ifndef"); + InConditional++; + break; + } + if(str_cmp(Keyword,"$if")==0 || str_cmp(Keyword,"$ifdef")==0) + { + strcpy(Stk[1],"~if"); + InConditional++; + break; + } + if(str_cmp(Keyword,"$else")==0) + { + strcpy(Stk[1],"~else"); + break; + } + if(str_cmp(Keyword,"$elseif")==0) + { + strcpy(Stk[1],"~elseif"); + break; + } + if(str_cmp(Keyword,"$endif")==0) + { + strcpy(Stk[1],"~endif"); + InConditional--; + if(InConditional<0) + { + Abort("To many $ENDIFs"); + } + break; + } + if(str_cmp(Keyword,"$cpp")==0) + { + Ndx=0; + UseCpp=TRUE; + break; + } + if(str_cmp(Keyword,"$CPP")==0) + { + Ndx=0; + UseCpp=TRUE; + } + break; + } + return; + } + break; + } + IFCond=0; + for(i=1; i<=Ndx; i+=1) + { + if(iMatchWrd(Stk[i],"if")) + { + IFCond=i+1; + } + if(iMatchWrd(Stk[i],"then")&&iMatchWrd(Stk[i+1],"if")) + { + for(j=i+2; j<=Ndx; j+=1) + { + if(iMatchWrd(Stk[j],"else")) + { + break; + } + } + if(j>Ndx) + { + for(j=i; j>=IFCond+1; j+=-1) + { + strcpy(Stk[j],Stk[j-1]); + } + strcpy(Stk[IFCond],"("); + i++; + strcpy(Stk[i],")"); + i++; + for(j=Ndx; j>=i; j+=-1) + { + strcpy(Stk[j+2],Stk[j]); + } + Ndx++; + Ndx++; + strcpy(Stk[i],"&&"); + i++; + strcpy(Stk[i],"("); + i++; + for(i=i; i<=Ndx; i+=1) + { + if(iMatchWrd(Stk[i],"then")) + { + Ndx++; + for(j=Ndx; j>=i; j+=-1) + { + strcpy(Stk[j],Stk[j-1]); + } + strcpy(Stk[i],")"); + break; + } + } + i--; + } + else + { + break; + } + } + } +} + + +void Parse (char *Arg) +{ + int A; + int B; + int CommaCnt; + int Tmp; + int i; + int j; + int k; + char lszTmp[2048]; + char L_Stk_1[2048]; + char L_Stk_2[2048]; + char Var1[2048]; + int Plus2Amp=0; + int vt; + *L_Stk_1=0; + *L_Stk_2=0; + *lszTmp=0; + *Var1=0; + XParse(Arg); + PassOne=0; + if(!iMatchWrd(Stk[1],"function")) + { + Plus2Amp=iMatchNQ(Arg,"&"); + for(Tmp=2; Tmp<=Ndx-1; Tmp+=1) + { + if(str_cmp(Stk[Tmp],"+")==0) + { + vt=DataType(Stk[Tmp+1]); + if(vt==vt_STRVAR||vt==vt_STRLIT) + { + strcpy(Stk[Tmp],"&"); + Plus2Amp=TRUE; + } + else + { + vt=DataType(Stk[Tmp-1]); + if(vt==vt_STRVAR||vt==vt_STRLIT) + { + strcpy(Stk[Tmp],"&"); + Plus2Amp=TRUE; + } + } + } + } + if(Plus2Amp>0) + { + Use_Join=UseFlag=TRUE; + j=0; + k=0; + for(Tmp=1; Tmp<=Ndx-1; Tmp+=1) + { + A=CheckLocal(Stk[Tmp], &i); + if(A==vt_UNKNOWN) + { + A=CheckGlobal(Stk[Tmp], &i); + } + if(A==vt_STRUCT||A==vt_UDT||A==vt_UNION) + { + j=1; + } + if(str_cmp(Stk[Tmp],"&")==0) + { + A=DataType(Stk[Tmp+1]); + if(A==vt_STRVAR||A==vt_STRLIT) + { + k=1; + } + else + { + A=DataType(Stk[Tmp-1]); + if(A==vt_STRVAR||A==vt_STRLIT) + { + k=1; + } + } + } + } + if(k) + { + if(j) + { + AsmUnknownStructs(0); + } + JoinStrings(1,0); + *Src=0; + for(i=1; i<=Ndx; i+=1) + { + if(Stk[i][0]) + { + strcpy(Src, join(3,Src,Stk[i]," ")); + } + } + XParse(Src); + } + } + } + if(UseCpp) + { + if(iMatchNQ(Src,"->lpVtbl")) + { + {register int i; + for(i=1; i<=Ndx; i+=1) + { + if(iMatchRgt(Stk[i],"->lpVtbl")) + { + strcpy(Stk[i],extract(Stk[i],"->lpVtbl")); + if((str_cmp(Stk[i+3],Stk[i-1])==0 || str_cmp(Stk[i+3],Stk[i])==0) && str_cmp(Stk[i+3],")")!=0) + { + *Stk[i+3]=0; + if(str_cmp(Stk[i+4],",")==0) + { + *Stk[i+4]=0; + } + } + } + } + } + RemEmptyTokens(); + } + } + TokenSubstitutions(); + if(Ndx==0) + { + return; + } + Transforms(); + if(Ndx==0) + { + return; + } + if(iMatchWrd(Stk[1],"function")) + { + if(iMatchWrd(Stk[Ndx-2],"as")&&str_cmp(Stk[Ndx],")")!=0) + { + if(!iMatchWrd(Stk[Ndx],"export")&&!iMatchWrd(Stk[Ndx],"stdcall")) + { + strcpy(Stk[Ndx-1], join(3,Stk[Ndx-1]," ",Stk[Ndx])); + Ndx--; + } + } + } + if(iMatchWrd(Stk[1],"function")||iMatchWrd(Stk[1],"sub")) + { + int offset; + int LastBrk=Ndx-2; + for(i=Ndx; i>=3; i+=-1) + { + if(str_cmp(Stk[i],")")==0) + { + LastBrk=i; + break; + } + } + for(i=3; i<=LastBrk; i+=1) + { + offset=2; + if(iMatchWrd(Stk[i],"as")&&(i=i+3; B+=-1) + { + strcpy(Stk[B],Stk[B-3]); + } + strcpy(Stk[i+2],Stk[i+1]); + strcpy(Stk[i+1],","); + strcpy(Stk[i+3],","); + strcpy(Stk[i+4],ltrim(str(j))); + strcpy(Stk[i+5],sziif(j,",",")")); + Ndx+=(3); + Use_Dynacall=TRUE; + } + } + } + } + if(inchr(Arg,"^")) + { + int lp=0; + int rp=0; + Test=FALSE; + for(i=1; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],"^")==0) + { + Test=TRUE; + if(str_cmp(Stk[i+1],"-")==0) + { + Ndx++; + for(A=Ndx; A>=i+2; A+=-1) + { + strcpy(Stk[A],Stk[A-1]); + } + strcpy(Stk[i+1],"("); + B=i+3; + if(str_cmp(Stk[B],"(")==0) + { + lp=0; + rp=0; + for(;;) + { + if(str_cmp(Stk[B],"(")==0) + { + lp++; + } + if(str_cmp(Stk[B],")")==0) + { + rp++; + } + B++; + if(lp==rp) + { + break; + } + } + Ndx++; + j=B+1; + for(A=Ndx; A>=j; A+=-1) + { + strcpy(Stk[A],Stk[A-1]); + } + strcpy(Stk[B],")"); + } + else + { + B=i+4; + if(inchr("[",Stk[B])) + { + for(;;) + { + B++; + if(inchr("]",Stk[B])) + { + break; + } + } + Ndx++; + j=B+2; + for(A=Ndx; A>=j; A+=-1) + { + strcpy(Stk[A],Stk[A-1]); + } + strcpy(Stk[B+1],")"); + } + else + { + if(inchr("(",Stk[B])) + { + for(;;) + { + B++; + if(inchr(")",Stk[B])) + { + break; + } + } + Ndx++; + j=B+2; + for(A=Ndx; A>=j; A+=-1) + { + strcpy(Stk[A],Stk[A-1]); + } + strcpy(Stk[B+1],")"); + } + else + { + Ndx++; + j=B+1; + for(A=Ndx; A>=j; A+=-1) + { + strcpy(Stk[A],Stk[A-1]); + } + strcpy(Stk[B],")"); + } + } + } + } + } + } + if(Test) + { + for(i=1; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],"^")==0) + { + A=i-1; + B=0; + while(str_cmp(Stk[A],"=")!=0) + { + if(str_cmp(Stk[A],"]")==0) + { + B++; + } + if(str_cmp(Stk[A],")")==0) + { + B++; + } + if(str_cmp(Stk[A],"[")==0) + { + B--; + } + if(str_cmp(Stk[A],"(")==0) + { + B--; + } + if(B==0) + { + break; + } + A--; + } + if(str_cmp(Stk[A],"[")==0) + { + A--; + } + if(str_cmp(Stk[A],"=")==0) + { + A++; + } + if(str_cmp(Stk[A],"(")==0) + { + B=DataType(Stk[A-1]); + if(!iMatchWrd(Stk[A-1],"print")&&(B==vt_INTEGER||B==vt_SINGLE||B==vt_DOUBLE)) + { + A--; + } + } + strcpy(Arg,"pow("); + B=A-1; + while(B>0) + { + strcpy(Arg, join(4,Stk[B]," ",Arg," ")); + B--; + } + for(B=A; B<=i-1; B+=1) + { + strcpy(Arg, join(3,Arg," ",Stk[B])); + } + strcat(Arg,","); + A=i+1; + B=DataType(Stk[A]); + if((str_cmp(Stk[A+1],"(")==0 || str_cmp(Stk[A+1],"[")==0) && (B==vt_INTEGER||B==vt_SINGLE||B==vt_DOUBLE)) + { + A++; + } + B=0; + while(A<=Ndx) + { + if(str_cmp(Stk[A],"[")==0) + { + B++; + } + if(str_cmp(Stk[A],"(")==0) + { + B++; + } + if(str_cmp(Stk[A],"]")==0) + { + B--; + } + if(str_cmp(Stk[A],")")==0) + { + B--; + } + if(!B) + { + break; + } + A++; + } + for(B=i+1; B<=A; B+=1) + { + strcpy(Arg, join(3,Arg," ",Stk[B])); + } + strcat(Arg,")"); + A++; + while(A<=Ndx) + { + strcpy(Arg, join(3,Arg," ",Stk[A])); + A++; + } + break; + } + } + Parse(Arg); + } + } + strcpy(L_Stk_1,lcase(Stk[1])); + strcpy(L_Stk_2,lcase(Stk[2])); + if(str_cmp(L_Stk_1,"$dll")==0) + { + MakeDLL=NoMain=TRUE; + if(IsApple) + { + strcpy(LD_FLAGS,"-fPIC -shared $FILE$.so"); + } + else + { + strcpy(LD_FLAGS,"-fPIC -shared -Wl,-soname,$FILE$.so"); + } + Ndx=0; + return; + } + IsCallBack=0; + if(iMatchWrd(Stk[Ndx],"callback")) + { + IsCallBack=1; + Ndx--; + } + if(str_cmp(L_Stk_1,"open")==0) + { + for(A=1; A<=Ndx; A+=1) + { + if(iMatchWrd(Stk[A],"binary")) + { + break; + } + } + if(A"); + } + if(i>0) + { + if(WithCnt) + { + strcpy(Z,WithVar[WithCnt]); + } + else + { + strcpy(Z,left(Z,i-1)); + } + } + if(inchr(Z,"[")) + { + strcpy(Z,extract(Z,"[")); + } + if(CheckLocal(Z, &j)==vt_UNKNOWN) + { + if(CheckGlobal(Z, &j)==vt_UNKNOWN) + { + strcpy(Z,lcase(Z)); + if(str_cmp(Stk[2],"=")==0 && str_cmp(Z,"functionreturn")!=0 && str_cmp(Z,"bcx_retstr")!=0 && str_cmp(Z,"end")!=0) + { + Warning(join(6,"Assignment before Declaration in Line ",str(ModuleLineNos[ModuleNdx])," in Module: ",trim(Modules[ModuleNdx]),": ",Src)); + } + } + } + } + } +} + + +void FuncSubDecs1 (char *s) +{ + int i; + int j; + if(iMatchWrd(Stk[1],s)) + { + if(DataType(Stk[2])==vt_STRVAR) + { + Abort(join(3,"Invalid ",s,"name")); + } + } + for(i=1; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],"[")==0 && str_cmp(Stk[i+1],"]")==0) + { + if(iMatchWrd(Stk[i+2],"as")) + { + strcpy(Stk[i+3], join(2,Stk[i+3],"*")); + } + else if(str_cmp(Stk[i+2],"[")==0) + { + j=i-1; + while(i<=Ndx) + { + if(iMatchWrd(Stk[i],"as")) + { + break; + } + if(iMatchRgt(Stk[j],"]")&&inchr(",)=",Stk[i])) + { + break; + } + strcpy(Stk[j], join(2,Stk[j],Stk[i])); + *Stk[i++]=0; + } + continue; + } + else + { + if(DataType(Stk[i-1])==vt_STRVAR) + { + strcpy(Stk[i-1], join(2,Stk[i-1],"[][65535]")); + } + strcpy(Stk[i-1], join(2,"*",Stk[i-1])); + } + *Stk[i++]=0; + *Stk[i]=0; + } + } + RemEmptyTokens(); + IsExported=FALSE; + if(iMatchWrd(Stk[Ndx],"export")) + { + Ndx--; + IsExported=TRUE; + if(UseStdCall) + { + strcpy(CallType,"__attribute__((stdcall)) "); + } + else + { + strcpy(CallType,"__attribute__((cdecl)) "); + } + } +} + + +void RemEmptyTokens (void) +{ + int i; + int j; + for(i=1; i<=Ndx; i+=1) + { + if(!*Stk[i]) + { + j=i; + while(!*Stk[j]&&(jHeader,"..."); + } + strcpy(varcode->Header,rtrim(varcode->Header)); + if(iMatchRgt(varcode->Header,",")) + { + midstr(varcode->Header,strlen(varcode->Header),-1,")"); + } + else + { + strcat(varcode->Header,")"); + } + strcpy(varcode->Header,replace(varcode->Header,"()","(void)")); + strcpy(varcode->Header, join(3,varcode->Functype,varcode->Token,varcode->Header)); + if(varcode->Method==2) + { + if(*Stk[Ndx-1]==46) + { + strcat(varcode->Proto,"..."); + } + strcpy(varcode->Proto,rtrim(varcode->Proto)); + if(iMatchRgt(varcode->Proto,",")) + { + midstr(varcode->Proto,strlen(varcode->Proto),-1,")"); + } + else + { + strcat(varcode->Proto,")"); + } + strcpy(varcode->Proto,replace(varcode->Proto,"()","(void)")); + strcpy(varcode->Proto, join(4,varcode->Functype,varcode->Token,varcode->Proto,";")); + } + if(IsExported) + { + strcpy(varcode->Proto, join(2,"C_EXPORT ",varcode->Proto)); + strcpy(varcode->Header, join(2,"C_EXPORT ",varcode->Header)); + } +} + + +void AddTypeDefs (char *TypeName, int TDef) +{ + TypeDefsCnt++; + if(TypeDefsCnt==MaxTypes) + { + Abort("Exceeded TYPE Limits."); + } + strcpy(TypeDefs[TypeDefsCnt].VarName,TypeName); + TypeDefs[TypeDefsCnt].TypeofDef=TDef; + TypeDefs[TypeDefsCnt].EleCnt=0; +} + + +int DefsID (char *ZZ) +{ + int i; + if(TypeDefsCnt>0) + { + for(i=1; i<=TypeDefsCnt; i+=1) + { + if(str_cmp(ZZ,TypeDefs[i].VarName)==0) + { + return i; + } + } + } + return 0; +} + + +void GetTypeInfo (char *stk, int* IsPointer, int* UdtIdx, int* vtCode) +{ + char Var1[2048]; + (*IsPointer)=tally(stk,"*"); + strcpy(Var1,RemoveStr(stk,"*")); + if(str_cmp(right(Var1,6),"_CLASS")==0) + { + strcpy(Var1,left(Var1,strlen(Var1)-6)); + } + (*vtCode)=CheckType(Var1); + if((*vtCode)==vt_UNKNOWN) + { + AddTypeDefs(Var1,vt_UDT); + (*vtCode)=vt_UDT; + } + (*UdtIdx)=0; + if((*vtCode)==vt_STRUCT||(*vtCode)==vt_UNION||(*vtCode)==vt_UDT) + { + (*UdtIdx)=DefsID(Var1); + } +} + + +void AddTypedefElement (int WorkingTypeDefsCnt, int ElType, char *EName, char *EType, int EPtr) +{ + UserTypeDefs* TD; + TD= &(TypeDefs[WorkingTypeDefsCnt]); + if(TD->EleCnt==MaxElements) + { + Abort("Exceeded TYPE Element Limits."); + } + TD->Elements[TD->EleCnt].ElementType=ElType; + TD->Elements[TD->EleCnt].ElementDynaPtr=EPtr; + if(ElType==vt_STRUCT||ElType==vt_UNION||ElType==vt_UDT) + { + TD->Elements[TD->EleCnt].ElementID=DefsID(EType); + } + else + { + TD->Elements[TD->EleCnt].ElementID=0; + } + strcpy(TD->Elements[TD->EleCnt].ElementName,EName); + TD->EleCnt=1+TD->EleCnt; +} + + +char * GetElement (int StartStk, int* vt, int* dms, int id) +{ + char *BCX_RetStr={0}; + int BC=0; + int i; + char ZZ[2048]; + for(i=StartStk+1; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],"[")==0) + { + BC++; + } + else if(str_cmp(Stk[i],"]")==0) + { + BC--; + } + else if(BC==0) + { + if(iMatchLft(Stk[i],"->")||*Stk[i]==46) + { + strcpy(ZZ,Clean(Stk[i])); + RemoveAll(ZZ,".->(*)",1); + (*vt)=GetElementInfo( &id,dms,ZZ); + if((*vt)!=vt_STRUCT&&(*vt)!=vt_UNION) + { + break; + } + } + } + } + if((*vt)==vt_UDT||(*vt)==vt_UNION||(*vt)==vt_STRUCT) + { + strcpy(ZZ,TypeDefs[id].VarName); + } + else + { + strcpy(ZZ,GetVarTypeName(*vt)); + } + BCX_RetStr=BCX_TmpStr(strlen(ZZ)); + strcpy(BCX_RetStr,ZZ); + return BCX_RetStr; +} + + +int GetElementInfo (int* DefID, int* EPtr, char *Elename) +{ + int i; + int id; + id=(*DefID); + for(i=0; i<=TypeDefs[id].EleCnt-1; i+=1) + { + if(str_cmp(Elename,TypeDefs[id].Elements[i].ElementName)==0) + { + (*DefID)=TypeDefs[id].Elements[i].ElementID; + (*EPtr)=TypeDefs[id].Elements[i].ElementDynaPtr; + return TypeDefs[id].Elements[i].ElementType; + } + } + return 0; +} + + +void HandleNonsense (void) +{ + int i; + for(i=1; i<=Ndx; i+=1) + { + if(iMatchWrd(Stk[i],"as")) + { + strcpy(Stk[i-1],Clean(Stk[i-1])); + } + if(OptionBase) + { + if(str_cmp(Stk[i],"[")==0) + { + strcpy(Stk[i+1], join(3,ltrim(str(OptionBase)),"+",Stk[i+1])); + } + } + } +} + + +void ValidVar (char *v) +{ + char ZZ[2048]; + if(!isalpha(*v)&&*v!=95) + { + if(!iMatchLft(v,"(*")) + { + Abort("Invalid String Variable Name"); + } + } + if(RestrictedWords(v)&&TestState) + { + strcpy(ZZ, join(3,"Variable ",v," on line")); + strcpy(ZZ, join(5,ZZ,str(ModuleLineNos[ModuleNdx])," in Module: ",trim(Modules[ModuleNdx])," is a Restricted Word")); + Warning(ZZ); + } +} + + +void PointerFix (void) +{ + strcpy(Stk[Ndx-1], join(2,Stk[Ndx-1],Stk[Ndx])); + Stk[Ndx][0]=0; + Ndx--; + while(tally(Stk[Ndx],"*")==strlen(Stk[Ndx])) + { + strcpy(Stk[Ndx-1], join(2,Stk[Ndx-1],Stk[Ndx])); + Stk[Ndx][0]=0; + Ndx--; + } +} + + +void DimDynaString (char *SVar, int DG, int s) +{ + int A; + char DS[2048]; + strcpy(DS, join(5,"if(",SVar,")free(",SVar,");")); + if(InFunc&&(IsLocal||IsDim||IsRaw||IsAuto||IsRegister)&&DG==0) + { + LocalDynaCnt++; + strcpy(DynaStr[LocalDynaCnt],DS); + if(IsAuto) + { + fprintf(Outfile,"%s%s%s%s\n",Scoot,"char *",SVar,";"); + } + else if(IsRegister) + { + fprintf(Outfile,"%s%s%s%s\n",Scoot,"register char *",SVar,";"); + } + else + { + fprintf(Outfile,"%s%s%s%s\n",Scoot,"char *",SVar,";"); + } + AddLocal(SVar,vt_CHAR,0,"",1,0,0); + } + else + { + if(Use_GenFree) + { + GlobalDynaCnt++; + strcpy(GlobalDynaStr[GlobalDynaCnt],DS); + } + if(DG==2) + { + AddGlobal(SVar,vt_CHAR,0,"",1,0,1,0); + } + else + { + if(s) + { + AddGlobal(SVar,vt_CHAR,0,"",1,0,2,0); + } + else + { + AddGlobal(SVar,vt_CHAR,0,"",1,0,0,0); + } + } + } + if(DG!=2) + { + fprintf(Outfile,"%s%s%s",Scoot,SVar,"=(char*)calloc(256+"); + for(A=4; A<=Ndx; A+=1) + { + fprintf(Outfile,"%s",Clean(Stk[A])); + } + fprintf(Outfile,"%s\n",",1);"); + } +} + + +int SubFuncTest (void) +{ + if(iMatchWrd(Stk[2],"function")||iMatchWrd(Stk[2],"sub")) + { + return 1; + } + return 0; +} + + +int DimSubFunc (int IsDynamic) +{ + int i; + char lszTmp[2048]; + int StartPoint=3; + int Funptr=0; + *lszTmp=0; + if(iMatchWrd(Stk[Ndx],"stdcall")) + { + strcpy(CallType,"__attribute__((stdcall)) "); + Ndx--; + IsStdFunc=TRUE; + } + else + { + strcpy(CallType,"__attribute__((cdecl)) "); + IsStdFunc=FALSE; + } + static struct _functionParse FP; + memset(&FP,0,sizeof(FP)); + SepFuncArgs(3, &FP,TRUE); + StartPoint=_MAX_(FP.CommaPos[0],3); + if(!InTypeDef) + { + SFPOINTER=TRUE; + if(FP.NumArgs==0) + { + i=_MIN_(FP.CommaPos[1]+1,Ndx); + } + else + { + i=_MIN_(FP.CommaPos[FP.NumArgs]+1,Ndx); + } + if(str_cmp(Stk[i],"=")==0) + { + *Stk[i++]=0; + while(!iMatchWrd(Stk[i],"as")&&i<=Ndx) + { + strcat(lszTmp,Stk[i]); + *Stk[i++]=0; + } + RemoveAll(lszTmp,"{}",1); + if(lszTmp[0]!=0) + { + RemEmptyTokens(); + } + } + if(!InNameSpace) + { + fprintf(FP4,"%s%s\n",MakeDecProto( &FP),";"); + } + SFPOINTER=FALSE; + Ndx=StartPoint; + *Stk[2]=0; + if(lszTmp[0]!=0) + { + strcpy(Stk[Ndx++],"="); + strcpy(Stk[Ndx++],"{"); + strcpy(Stk[Ndx++],Clean(lszTmp)); + strcpy(Stk[Ndx++],"}"); + } + strcpy(Stk[Ndx++],"as"); + strcpy(Stk[Ndx], join(3,Clean(Stk[3]),"_TYPE",stringx(Funptr,42))); + RemEmptyTokens(); + return FALSE; + } + else + { + if(iMatchWrd(Stk[2],"constructor")||iMatchWrd(Stk[2],"destructor")) + { + fprintf(Outfile,"%s%s%s%s\n",LF,Scoot,MakeDecProto( &FP),";"); + } + else if(Use_Virtual) + { + fprintf(Outfile,"%s%s%s%s%s\n",Scoot,"virtual ",MakeDecProto( &FP),vproc,";"); + Use_Virtual=FALSE; + } + else + { + fprintf(Outfile,"%s%s%s\n",Scoot,MakeDecProto( &FP),";"); + } + } + return TRUE; +} + + +void Emit (void) +{ + int HasStorage=0; + int A; + int B; + int i; + int j; + int Tmp; + int FuncRetnFlag; + int IsPointer=0; + int VType; + int id=0; + int k=0; + int vt=0; + char Arg[2048]; + char CVar[2048]; + char Keyword[2048]; + char lszTmp[2048]; + char Var1[2048]; + char ZZ[2048]; + int IsSubOrFuncPtr; + int dms; + static int NoBreak; + static int NoBreak2; + FuncRetnFlag=0; + *lszTmp=0; + *ZZ=0; + strcpy(Keyword,lcase(Stk[1])); + if(NoBreak2&&!iMatchLft(Keyword,"case")&&!iMatchWrd(Keyword,"endselect")) + { + NoBreak2=0; + } + +EMITAGAIN:; + if(Ndx==0) + { + return; + } + Statements++; + if(iMatchRgt(Stk[1],":")) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s%s\n",ucase(Stk[1]),";"); + return; + } + for(i=1; i<=Ndx; i+=1) + { + strcpy(Stk[i],replace(Stk[i],chr(-15),":")); + } + if((CurrentFuncType==vt_STRVAR)&&InFunc&&OkayToSend) + { + fprintf(Outfile,"%s%s\n",Scoot,"char *BCX_RetStr={0};"); + OkayToSend=0; + } + strcpy(Lookup,lcase(Stk[1])); + for(;;) + { + if(str_cmp(Lookup,"fprint")==0 || str_cmp(Lookup,"sprint")==0) + { + int IsLprint=FALSE; + int IsSprint=FALSE; + if(iMatchWrd(Stk[1],"sprint")) + { + IsSprint=TRUE; + } + if(IsNumber(Stk[2])) + { + strcpy(Stk[2], join(2,"FP",Stk[2])); + } + if(IsSprint) + { + strcpy(Handl,Clean(Stk[2])); + } + else + { + if(str_cmp(lcase(Stk[2]),"stderr")==0) + { + strcpy(Handl,lcase(Stk[2])); + } + else + { + if(CheckLocal(Stk[2], &i)==vt_UNKNOWN) + { + if(CheckGlobal(Stk[2], &i)==vt_UNKNOWN) + { + AddGlobal(Stk[2],vt_FILEPTR,0,"",0,0,0,0); + } + } + *Handl=0; + for(i=2; i<=Ndx; i+=1) + { + if(*Stk[i]==44||*Stk[i]==59) + { + *Stk[i]=0; + break; + } + strcat(Handl,Stk[i]); + *Stk[i]=0; + } + strcat(Handl,"@"); + } + } + *Stk[2]=0; + *Stk[3]=0; + if(IsSprint) + { + strcpy(ZZ, join(2,"s",PrintWriteFormat(0))); + strcpy(ZZ,RemoveStr(ZZ,"\\n")); + } + else + { + strcpy(ZZ, join(2,"f",PrintWriteFormat(0))); + } + strcpy(ZZ, join(4,left(ZZ,8),RemoveStr(Handl,"@"),",",mid(ZZ,9))); + fprintf(Outfile,"%s%s\n",Scoot,ZZ); + break; + } + if(str_cmp(Lookup,"end")==0) + { + if(Ndx==1) + { + fprintf(Outfile,"%s%s\n",Scoot,"fflush(stdout);"); + fprintf(Outfile,"%s%s\n",Scoot,"exit(0);"); + break; + } + if(str_cmp(Stk[2],"=")==0) + { + fprintf(Outfile,"%s%s\n",Scoot,"fflush(stdout);"); + fprintf(Outfile,"%s%s",Scoot,"exit("); + for(Tmp=3; Tmp<=Ndx; Tmp+=1) + { + fprintf(Outfile,"%s",Clean(Stk[Tmp])); + } + fprintf(Outfile,"%s\n",");"); + break; + } + if(iMatchWrd(Stk[2],"if")) + { + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + BumpDown(); + break; + } + break; + } + if(str_cmp(Lookup,"endif")==0) + { + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + BumpDown(); + break; + } + if(str_cmp(Lookup,"if")==0) + { + EmitIfCond("if"); + break; + } + if(str_cmp(Lookup,"elseif")==0) + { + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + BumpDown(); + EmitIfCond("else if"); + break; + } + if(str_cmp(Lookup,"for")==0) + { + int FFlg=0; + int For1=0; + int For2=0; + int For3=0; + int For4=0; + char Reg[2048]; + char xxx[2048]; + char yyy[2048]; + char zzz[2048]; + char qqq[2048]; + *Reg=0; + *xxx=0; + *yyy=0; + *zzz=0; + *qqq=0; + for(i=Ndx; i>=1; i+=-1) + { + if(iMatchWrd(Stk[i],"step")) + { + FFlg=TRUE; + break; + } + } + if(!FFlg) + { + Ndx++; + strcpy(Stk[Ndx],"step"); + Ndx++; + strcpy(Stk[Ndx],"1"); + } + Test=FALSE; + for(i=1; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],"=")==0) + { + Test=TRUE; + } + } + if(Test==FALSE) + { + Abort("Missing ="); + } + Test=FALSE; + for(i=1; i<=Ndx; i+=1) + { + if(iMatchWrd(Stk[i],"to")) + { + Test=TRUE; + } + } + if(Test==FALSE) + { + Abort("Missing TO"); + } + strcpy(Reg,lcase(Stk[2])); + for(;;) + { + if(str_cmp(Reg,"int")==0 || str_cmp(Reg,"fint")==0) + { + strcpy(Reg,SPC); + LoopLocalVar[LoopLocalCnt++]=1; + fprintf(Outfile,"%s%s",Scoot," {register int "); + break; + } + if(str_cmp(Reg,"single")==0 || str_cmp(Reg,"float")==0) + { + strcpy(Reg,SPC); + LoopLocalVar[LoopLocalCnt++]=1; + fprintf(Outfile,"%s%s",Scoot," {float "); + break; + } + if(str_cmp(Reg,"double")==0) + { + strcpy(Reg,SPC); + LoopLocalVar[LoopLocalCnt++]=1; + fprintf(Outfile,"%s%s",Scoot," {double "); + break; + } + if(str_cmp(Reg,"ldouble")==0) + { + strcpy(Reg,SPC); + LoopLocalVar[LoopLocalCnt++]=1; + fprintf(Outfile,"%s%s",Scoot," {LDOUBLE "); + break; + } + // case else + { + *Reg=0; + LoopLocalVar[LoopLocalCnt++]=0; + } + break; + } + if(strlen(Reg)) + { + for(j=3; j<=Ndx; j+=1) + { + strcpy(Stk[j-1],Stk[j]); + } + Ndx--; + } + for(i=2; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],"=")==0) + { + For1=i-1; + break; + } + } + for(i=For1+2; i<=Ndx; i+=1) + { + if(iMatchWrd(Stk[i],"to")) + { + For2=i-1; + break; + } + } + for(i=For2+2; i<=Ndx; i+=1) + { + if(iMatchWrd(Stk[i],"step")) + { + For3=i-1; + break; + } + } + For4=For3+2; + for(i=2; i<=For1; i+=1) + { + strcat(xxx,Stk[i]); + } + for(i=For1+2; i<=For2; i+=1) + { + strcat(yyy,Stk[i]); + } + for(i=For2+2; i<=For3; i+=1) + { + strcat(zzz,Stk[i]); + } + for(i=For4; i<=Ndx; i+=1) + { + strcat(qqq,Stk[i]); + } + strcpy(xxx,Clean(xxx)); + strcpy(yyy,Clean(yyy)); + strcpy(zzz,Clean(zzz)); + strcpy(qqq,Clean(qqq)); + if(str_cmp(Reg,SPC)==0) + { + fprintf(Outfile,"%s%s\n",xxx,";"); + } + *Reg=0; + if(IsNumberEx(qqq)) + { + if(str_cmp(left(qqq,1),"-")==0) + { + fprintf(Outfile,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",Scoot,"for(",Reg,xxx,"=",yyy,"; ",xxx,">=",zzz,"; ",xxx,"+=",qqq,")"); + } + else + { + fprintf(Outfile,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",Scoot,"for(",Reg,xxx,"=",yyy,"; ",xxx,"<=",zzz,"; ",xxx,"+=",qqq,")"); + } + } + else + { + fprintf(Outfile,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",Scoot,"for(",Reg,xxx,"=",yyy,"; ",qqq,">=0 ? ",xxx,"<=",zzz," : ",xxx,">=",zzz,"; ",xxx,"+=",qqq,")"); + } + BumpUp(); + fprintf(Outfile,"%s%s\n",Scoot,"{"); + BumpUp(); + break; + } + if(str_cmp(Lookup,"next")==0) + { + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + if(LoopLocalVar[--LoopLocalCnt]) + { + fprintf(Outfile,"%s%s\n",Scoot,"}"); + } + if(LoopLocalCnt<0) + { + Abort("Next without For"); + } + BumpDown(); + break; + } + if(str_cmp(Lookup,"do")==0) + { + fprintf(Outfile,"%s%s\n",Scoot,"for(;;)"); + BumpUp(); + fprintf(Outfile,"%s%s\n",Scoot,"{"); + BumpUp(); + break; + } + if(str_cmp(Lookup,"loop")==0) + { + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + BumpDown(); + break; + } + if(str_cmp(Lookup,"caseelse")==0) + { + CaseElseFlag[Pusher]=TRUE; + if(CaseFlag) + { + if(NoBreak2==0) + { + fprintf(Outfile,"%s%s\n",Scoot,"break;"); + } + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + fprintf(Outfile,"%s%s\n",Scoot,"// case else"); + fprintf(Outfile,"%s%s\n",Scoot,"{"); + BumpUp(); + } + break; + } + if(str_cmp(Lookup,"endselect")==0) + { + if(CaseFlag) + { + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + } + BumpDown(); + if(CaseElseFlag[Pusher]==0||NoBreak2==0) + { + fprintf(Outfile,"%s%s\n",Scoot,"break;"); + } + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + NoBreak2=CaseElseFlag[Pusher]=0; + Pop(CaseVar); + break; + } + if(str_cmp(Lookup,"else")==0) + { + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"else"); + BumpUp(); + fprintf(Outfile,"%s%s\n",Scoot,"{"); + BumpUp(); + break; + } + if(str_cmp(Lookup,"case")==0) + { + for(i=2; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],"%")==0) + { + strcpy(Stk[i]," % "); + } + if(str_cmp(Stk[i],"!=")==0) + { + strcpy(Stk[i],"<>"); + } + if(str_cmp(Stk[i],"!")==0 && str_cmp(Stk[i+1],"=")==0) + { + strcpy(Stk[i],"<>"); + *Stk[i+1]=0; + } + if(isalpha(Stk[i][0])) + { + strcat(Stk[i]," "); + } + } + *szTmp=0; + Test=FALSE; + if(DataType(CaseVar)==vt_STRVAR) + { + Test=TRUE; + } + i=0; + for(A=2; A<=Ndx; A+=1) + { + if(inchr("([",Stk[A])) + { + i++; + } + if(inchr(")]",Stk[A])) + { + i--; + } + if(i) + { + strcat(szTmp,Stk[A]); + continue; + } + if(str_cmp(Stk[A],",")==0) + { + if(!inchr("<>=",Stk[A+1])) + { + strcpy(szTmp, join(4,szTmp," or ",CaseVar,"=")); + } + else + { + strcpy(szTmp, join(3,szTmp," or ",CaseVar)); + } + *Stk[A]=0; + continue; + } + if(str_cmp(Stk[A],"&&")==0) + { + strcpy(szTmp, join(3,szTmp," and ",CaseVar)); + *Stk[A]=0; + } + else if(str_cmp(Stk[A],"||")==0) + { + strcpy(szTmp, join(3,szTmp," or ",CaseVar)); + *Stk[A]=0; + } + else + { + strcat(szTmp,Stk[A]); + } + } + if(CaseFlag==0) + { + NoBreak=0; + } + if(CaseFlag) + { + if(NoBreak==0) + { + if(NoBreak2==0) + { + fprintf(Outfile,"%s%s\n",Scoot,"break;"); + } + } + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + BumpDown(); + } + CaseFlag=TRUE; + if(iMatchLft(CaseVar," BAND ")) + { + NoBreak=1; + strcpy(Src, join(4,"IF ",szTmp,CaseVar," Then ")); + } + else + { + if(inchr("<>=",szTmp)&&!IsQuoted(szTmp)) + { + strcpy(Src, join(4,"IF ",CaseVar,szTmp," Then ")); + } + else + { + strcpy(Src, join(5,"IF ",CaseVar," = ",szTmp," Then ")); + } + } + Parse(Src); + Emit(); + break; + } + if(str_cmp(Lookup,"delay")==0) + { + *lszTmp=0; + for(i=2; i<=Ndx; i+=1) + { + strcat(lszTmp,Clean(Stk[i])); + } + fprintf(Outfile,"%s%s%s%s\n",Scoot,"sleep(",lszTmp,");"); + break; + } + if(str_cmp(Lookup,"qsortidx")==0) + { + *lszTmp=0; + strcpy(Var,Clean(Stk[2])); + for(i=4; i<=Ndx-4; i+=1) + { + strcat(lszTmp,Stk[i]); + } + strcpy(lszTmp,Clean(lszTmp)); + fprintf(Outfile,"%s%s%s%s\n",Scoot,"Key = ",Stk[Ndx],";"); + if(str_cmp(Var,"0")!=0) + { + fprintf(Outfile,"%s%s\n",Scoot,"int iDx;"); + fprintf(Outfile,"%s%s%s%s",Scoot,"for(iDx=0; iDx<",lszTmp,"; iDx+=1) "); + fprintf(Outfile,"%s%s\n",Var,"[iDx]=iDx;"); + } + if(!inchr(Stk[Ndx-2],".")) + { + Use_Idxqsort=TRUE; + fprintf(Outfile,"%s%s%s%s\n",Scoot,"pppStr = ",Clean(Stk[Ndx-2]),";"); + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,"qsort(",Var,",",lszTmp,",sizeof(int),IdxCompare);"); + } + else + { + char Stptr[2048]; + char StMem[2048]; + char StName[2048]; + strcpy(StMem,remain(Clean(Stk[Ndx-2]),".")); + strcpy(Stptr,extract(Stk[Ndx-2],".")); + if(CheckLocal(Stptr, &i)!=vt_UNKNOWN) + { + strcpy(StName,TypeDefs[LocalVars[i].VarDef].VarName); + } + else if(CheckGlobal(Stptr, &i)!=vt_UNKNOWN) + { + strcpy(StName,TypeDefs[GlobalVars[i].VarDef].VarName); + } + if(str_cmp(Var,"0")!=0) + { + Use_IdxqsortSt=TRUE; + fprintf(Outfile,"%s%s%s%s%s%s%s%s\n",Scoot,"cmp1 =(char*)(",Stptr,") + offsetof(",StName,",",StMem,");"); + fprintf(Outfile,"%s%s%s%s\n",Scoot,"StructSize = sizeof(",StName,");"); + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,"qsort(",Var,",",lszTmp,",sizeof(int),IdxCompareSt);"); + } + else + { + Use_PtrqsortSt=TRUE; + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,"OffSet = offsetof(",StName,",",StMem,");"); + fprintf(Outfile,"%s%s%s%s%s%s%s%s\n",Scoot,"qsort(",Stptr,",",lszTmp,",sizeof(",StName,"),PtrCompareSt);"); + } + } + break; + } + if(str_cmp(Lookup,"qsort")==0) + { + int QST=0; + int order=0; + if(iMatchWrd(Stk[2],"dynamic")) + { + QST=TRUE; + for(j=3; j<=Ndx; j+=1) + { + strcpy(Stk[j-1],Stk[j]); + } + Ndx--; + } + if(str_cmp(lcase(Stk[Ndx]),"ascending")==0) + { + order=2; + Ndx--; + Ndx--; + } + if(str_cmp(lcase(Stk[Ndx]),"descending")==0) + { + order=1; + Ndx--; + Ndx--; + } + if(order==0) + { + order=2; + } + *lszTmp=0; + for(i=4; i<=Ndx; i+=1) + { + strcat(lszTmp,Stk[i]); + } + strcpy(Var,Clean(Stk[2])); + vt=DataType(Stk[2]); + if(vt!=vt_STRVAR&&vt!=vt_INTEGER&&vt!=vt_SINGLE&&vt!=vt_DOUBLE) + { + vt=CheckType(Stk[2]); + } + fprintf(Outfile,"%s%s%s%s%s",Scoot,"qsort(",Var,",",Clean(lszTmp)); + for(;;) + { + if(vt==vt_STRVAR) + { + if(!QST) + { + if(order==1) + { + fprintf(Outfile,"%s%s%s\n",",sizeof(",Var,"[0]),StrCompareD);"); + Use_Strqsortd=TRUE; + } + else + { + fprintf(Outfile,"%s%s%s\n",",sizeof(",Var,"[0]),StrCompareA);"); + Use_Strqsorta=TRUE; + } + } + else + { + if(order==1) + { + fprintf(Outfile,"%s%s%s\n",",sizeof(",Var,"[0]),DynStrCompareD);"); + Use_DynStrqsortd=TRUE; + } + else + { + fprintf(Outfile,"%s%s%s\n",",sizeof(",Var,"[0]),DynStrCompareA);"); + Use_DynStrqsorta=TRUE; + } + } + break; + } + if(vt==vt_INTEGER) + { + if(order==1) + { + fprintf(Outfile,"%s\n",",sizeof(int),NumCompareDint);"); + Use_Numqsortdint=TRUE; + } + else + { + fprintf(Outfile,"%s\n",",sizeof(int),NumCompareAint);"); + Use_Numqsortaint=TRUE; + } + break; + } + if(vt==vt_SINGLE) + { + if(order==1) + { + fprintf(Outfile,"%s\n",",sizeof(float),NumCompareDfloat);"); + Use_Numqsortdfloat=TRUE; + } + else + { + fprintf(Outfile,"%s\n",",sizeof(float),NumCompareAfloat);"); + Use_Numqsortafloat=TRUE; + } + break; + } + if(vt==vt_DOUBLE) + { + if(order==1) + { + fprintf(Outfile,"%s\n",",sizeof(double),NumCompareDdouble);"); + Use_Numqsortddouble=TRUE; + } + else + { + fprintf(Outfile,"%s\n",",sizeof(double),NumCompareAdouble);"); + Use_Numqsortadouble=TRUE; + } + break; + } + // case else + { + if(order==1) + { + fprintf(Outfile,"%s\n",",sizeof(int),NumCompareDint);"); + Use_Numqsortdint=TRUE; + } + else + { + fprintf(Outfile,"%s\n",",sizeof(int),NumCompareAint);"); + Use_Numqsortaint=TRUE; + } + } + break; + } + break; + } + if(str_cmp(Lookup,"endprogram")==0) + { + fprintf(Outfile,"%s\n"," return 0; // End of main program"); + fprintf(Outfile,"%s\n","}\n\n"); + EndOfProgram=1; + break; + } + if(str_cmp(Lookup,"~ifndef")==0) + { + strcpy(InIfDef,"#ifndef "); + for(i=2; i<=Ndx; i+=1) + { + strcpy(InIfDef, join(3,InIfDef,Stk[i]," ")); + } + strcpy(InIfDef,trim(InIfDef)); + if(InFunc||InMain) + { + fprintf(Outfile,"%s\n",InIfDef); + } + else + { + fprintf(FP6,"%s\n",InIfDef); + } + break; + } + if(str_cmp(Lookup,"~if")==0) + { + strcpy(InIfDef,"#if defined "); + for(i=2; i<=Ndx; i+=1) + { + strcpy(InIfDef, join(3,InIfDef,Stk[i]," ")); + } + strcpy(InIfDef,trim(InIfDef)); + strcpy(ConstLastDef,InIfDef); + if(InFunc) + { + if(Outfile==FP3) + { + fprintf(Outfile,"%s\n","// FP3"); + } + if(Outfile==FP2) + { + fprintf(Outfile,"%s\n","// FP2"); + } + fprintf(Outfile,"%s%s\n",InIfDef,"// OUTFILE"); + strcpy(InIfDef,"FP3"); + } + else if(InMain) + { + fprintf(Outfile,"%s%s\n",InIfDef,"// --FP2--"); + } + break; + } + if(str_cmp(Lookup,"~else")==0) + { + strcpy(InIfDef,"#else"); + strcpy(ConstLastDef,InIfDef); + if(InFunc||InMain) + { + fprintf(Outfile,"%s\n",InIfDef); + } + else + { + fprintf(FP6,"%s\n",InIfDef); + } + break; + } + if(str_cmp(Lookup,"~elseif")==0) + { + strcpy(InIfDef,"#elif defined "); + for(i=2; i<=Ndx; i+=1) + { + strcpy(InIfDef, join(3,InIfDef,Stk[i]," ")); + } + strcpy(InIfDef,trim(InIfDef)); + strcpy(ConstLastDef,InIfDef); + if(InFunc||InMain) + { + fprintf(Outfile,"%s\n",InIfDef); + } + else + { + fprintf(FP6,"%s\n",InIfDef); + } + break; + } + if(str_cmp(Lookup,"~endif")==0) + { + if(str_cmp(InIfDef,"FP3")==0) + { + fprintf(FP3,"%s\n","#endif // FP3"); + } + else + { + fprintf(Outfile,"%s\n","#endif // Main"); + } + if(str_cmp(ConstLastDef,"FP6")==0) + { + fprintf(FP6,"%s\n","#endif // FP6"); + } + strcpy(InIfDef,"#endif // other"); + if(InConditional==0) + { + *InIfDef=0; + *ConstLastDef=0; + } + break; + } + if(str_cmp(Lookup,"incr")==0) + { + j=FALSE; + fprintf(Outfile,"%s",Scoot); + for(i=2; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],",")==0) + { + fprintf(Outfile,"%s","+=("); + j=TRUE; + } + else + { + fprintf(Outfile,"%s",Clean(Stk[i])); + } + } + fprintf(Outfile,"%s\n",sziif(j,");","++;")); + break; + } + if(str_cmp(Lookup,"decr")==0) + { + j=FALSE; + fprintf(Outfile,"%s",Scoot); + for(i=2; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],",")==0) + { + fprintf(Outfile,"%s","-=("); + j=TRUE; + } + else + { + fprintf(Outfile,"%s",Clean(Stk[i])); + } + } + fprintf(Outfile,"%s\n",sziif(j,");","--;")); + break; + } + if(str_cmp(Lookup,"seek")==0) + { + if(DataType(Stk[2])==vt_NUMBER) + { + strcpy(Stk[2], join(2,"FP",Stk[2])); + } + if(CheckLocal(Stk[2], &i)==vt_UNKNOWN) + { + AddGlobal(Stk[2],vt_FILEPTR,0,"",0,0,0,0); + } + fprintf(Outfile,"%s%s",Scoot,"fseek("); + for(Tmp=2; Tmp<=Ndx; Tmp+=1) + { + fprintf(Outfile,"%s",Clean(Stk[Tmp])); + } + fprintf(Outfile,"%s\n",",0);"); + break; + } + if(str_cmp(Lookup,"select")==0) + { + *CaseVar=0; + CaseFlag=0; + for(A=3; A<=Ndx; A+=1) + { + strcat(CaseVar,Stk[A]); + } + Push(CaseVar); + fprintf(Outfile,"%s%s\n",Scoot,"for(;;)"); + fprintf(Outfile,"%s%s\n",Scoot,"{"); + BumpUp(); + break; + } + if(str_cmp(Lookup,"~get")==0) + { + Use_Get=TRUE; + if(DataType(Stk[2])==vt_NUMBER) + { + strcpy(Stk[2], join(2,"FP",Stk[2])); + } + if(CheckLocal(Stk[2], &i)==vt_UNKNOWN) + { + if(CheckGlobal(Stk[2], &i)==vt_UNKNOWN) + { + AddGlobal(Stk[2],vt_FILEPTR,0,"",0,0,0,0); + } + } + fprintf(Outfile,"%s%s",Scoot,"GET("); + for(Tmp=2; Tmp<=Ndx; Tmp+=1) + { + fprintf(Outfile,"%s",Clean(Stk[Tmp])); + } + fprintf(Outfile,"%s\n",");"); + break; + } + if(str_cmp(Lookup,"~put")==0) + { + Use_Put=TRUE; + if(DataType(Stk[2])==vt_NUMBER) + { + strcpy(Stk[2], join(2,"FP",Stk[2])); + } + if(CheckLocal(Stk[2], &i)==vt_UNKNOWN) + { + if(CheckGlobal(Stk[2], &i)==vt_UNKNOWN) + { + AddGlobal(Stk[2],vt_FILEPTR,0,"",0,0,0,0); + } + } + fprintf(Outfile,"%s%s",Scoot,"PUT("); + for(Tmp=2; Tmp<=Ndx; Tmp+=1) + { + fprintf(Outfile,"%s",Clean(Stk[Tmp])); + } + fprintf(Outfile,"%s\n",");"); + break; + } + if(str_cmp(Lookup,"gosub")==0) + { + Use_Gosub=TRUE; + fprintf(Outfile,"%s%s",Scoot,"if (setjmp(GosubStack[GosubNdx++])==0)"); + fprintf(Outfile,"%s%s%s\n"," goto ",ucase(Stk[2]),";"); + break; + } + if(str_cmp(Lookup,"return")==0) + { + Use_Gosub=TRUE; + fprintf(Outfile,"%s%s\n",Scoot,"longjmp (GosubStack [--GosubNdx],1 );"); + fprintf(Outfile,"%s\n",""); + break; + } + if(str_cmp(Lookup,"data")==0) + { + if(str_cmp(Stk[Ndx],",")!=0) + { + strcpy(Stk[Ndx+1],","); + Ndx++; + } + for(A=2; A<=Ndx; A+=1) + { + if(inchr(Stk[A],DQ)==0&&str_cmp(Stk[A],",")!=0) + { + strcpy(Stk[A],enc(Stk[A])); + } + fprintf(FP5,"%s",Stk[A]); + } + fprintf(FP5,"%s\n",""); + break; + } + if(str_cmp(Lookup,"namespace")==0) + { + UseCpp=TRUE; + strcpy(szTmp,mid(Src,inchr(Src," ")+1)); + fprintf(Outfile,"%s%s\n","namespace ",ltrim(szTmp)); + fprintf(Outfile,"%s\n","{"); + InNameSpace++; + BumpUp(); + break; + } + if(str_cmp(Lookup,"endnamespace")==0) + { + InNameSpace--; + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + break; + } + if(str_cmp(Lookup,"class")==0) + { + if(InTypeDef==0) + { + SaveOutfileNum=Outfile; + } + Outfile=FP4; + InTypeDef++; + strcpy(TypeName[InTypeDef],Stk[2]); + if(str_cmp(Stk[3],"inherits")==0) + { + strcpy(Stk[3], join(2,": public ",Stk[4])); + } + AddTypeDefs(TypeName[InTypeDef],vt_STRUCT); + BaseTypeDefsCnt[InTypeDef]=TypeDefsCnt; + if(InTypeDef==1) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s%s%s%s\n","class ",TypeName[InTypeDef],Stk[3]," {"); + BumpUp(); + } + break; + } + if(str_cmp(Lookup,"endclass")==0) + { + BumpDown(); + fprintf(Outfile,"%s%s\n","};",LF); + InTypeDef--; + break; + } + if(str_cmp(Lookup,"type")==0) + { + if(InTypeDef==0) + { + SaveOutfileNum=Outfile; + } + Outfile=FP4; + if(Ndx>2) + { + if(InTypeDef) + { + Abort("Single line TYPE within type/union not supported"); + } + for(i=Ndx; i>=1; i+=-1) + { + if(iMatchWrd(Stk[i],"as")) + { + break; + } + } + if(!iMatchWrd(Stk[i],"as")) + { + Abort("Missing AS TYPE"); + } + fprintf(Outfile,"%s","typedef "); + j=i-1; + i++; + while(i<=Ndx) + { + fprintf(Outfile,"%s%s",Stk[i]," "); + i++; + } + for(i=2; i<=j; i+=1) + { + fprintf(Outfile,"%s",Stk[i]); + } + fprintf(Outfile,"%s\n",";"); + Outfile=SaveOutfileNum; + } + else + { + InTypeDef++; + strcpy(TypeName[InTypeDef],Stk[2]); + AddTypeDefs(TypeName[InTypeDef],vt_STRUCT); + BaseTypeDefsCnt[InTypeDef]=TypeDefsCnt; + if(InTypeDef==1) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s%s\n","typedef struct _",TypeName[InTypeDef]); + fprintf(Outfile,"%s\n","{"); + BumpUp(); + } + else + { + fprintf(Outfile,"%s%s\n",Scoot,"struct"); + fprintf(Outfile,"%s%s\n",Scoot,"{"); + AddTypedefElement(BaseTypeDefsCnt[InTypeDef-1],vt_STRUCT,TypeName[InTypeDef],TypeName[InTypeDef],0); + BumpUp(); + } + } + break; + } + if(str_cmp(Lookup,"endtype")==0) + { + if(InTypeDef==1) + { + BumpDown(); + fprintf(Outfile,"%s%s%s%s%s%s\n","}",TypeName[InTypeDef],", *","LP",ucase(TypeName[InTypeDef]),";"); + fprintf(Outfile,"%s\n",""); + Outfile=SaveOutfileNum; + fprintf(FP6,"%s%s%s%s%s%s\n",Scoot,"#define ",ucase(TypeName[InTypeDef]),"_CLASS struct _",ucase(TypeName[InTypeDef]),"*"); + } + else + { + BumpDown(); + fprintf(Outfile,"%s%s%s%s\n",Scoot,"} ",TypeName[InTypeDef],";"); + fprintf(Outfile,"%s\n",""); + } + InTypeDef--; + break; + } + if(str_cmp(Lookup,"union")==0) + { + if(InTypeDef==0) + { + SaveOutfileNum=Outfile; + } + Outfile=FP4; + InTypeDef++; + strcpy(TypeName[InTypeDef],Stk[2]); + AddTypeDefs(TypeName[InTypeDef],vt_UNION); + BaseTypeDefsCnt[InTypeDef]=TypeDefsCnt; + if(InTypeDef==1) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","typedef union "); + fprintf(Outfile,"%s\n","{"); + BumpUp(); + } + else + { + fprintf(Outfile,"%s%s\n",Scoot,"union"); + fprintf(Outfile,"%s%s\n",Scoot,"{"); + AddTypedefElement(BaseTypeDefsCnt[InTypeDef-1],vt_UNION,TypeName[InTypeDef],TypeName[InTypeDef],0); + BumpUp(); + } + break; + } + if(str_cmp(Lookup,"endunion")==0) + { + if(InTypeDef==1) + { + BumpDown(); + fprintf(Outfile,"%s%s%s%s%s%s\n","} ",TypeName[InTypeDef],", *","LP",ucase(TypeName[InTypeDef]),";"); + fprintf(Outfile,"%s\n",""); + Outfile=SaveOutfileNum; + } + else + { + BumpDown(); + fprintf(Outfile,"%s%s%s%s\n",Scoot,"} ",TypeName[InTypeDef],";"); + fprintf(Outfile,"%s\n",""); + } + InTypeDef--; + break; + } + if(str_cmp(Lookup,"with")==0) + { + WithCnt++; + if(WithCnt==8) + { + Abort("[With] depth exceeded"); + } + *WithVar[WithCnt]=0; + for(i=2; i<=Ndx; i+=1) + { + strcat(WithVar[WithCnt],Stk[i]); + } + break; + } + if(str_cmp(Lookup,"endwith")==0) + { + WithCnt--; + break; + } + if(str_cmp(Lookup,"clear")==0) + { + Use_Clear=TRUE; + fprintf(Outfile,"%s%s",Scoot,"Clear "); + if(str_cmp(Stk[2],"(")!=0) + { + fprintf(Outfile,"%s","("); + } + for(i=2; i<=Ndx; i+=1) + { + fprintf(Outfile,"%s",Clean(Stk[i])); + } + if(str_cmp(Stk[2],"(")!=0) + { + fprintf(Outfile,"%s",")"); + } + fprintf(Outfile,"%s\n",";"); + break; + } + if(str_cmp(Lookup,"repeat")==0) + { + *lszTmp=0; + for(i=2; i<=Ndx; i+=1) + { + strcat(lszTmp,Stk[i]); + } + strcpy(lszTmp,Clean(lszTmp)); + BumpUp(); + if(inchr(Stk[2],"-")) + { + if(str_cmp(left(lszTmp,1),"-")==0) + { + strcpy(lszTmp,mid(lszTmp,2)); + } + fprintf(Outfile,"%s%s\n",Scoot,"{register int BCX_REPEAT;"); + fprintf(Outfile,"%s%s%s%s\n",Scoot,"for(BCX_REPEAT=",lszTmp,";BCX_REPEAT>=1;BCX_REPEAT--)"); + fprintf(Outfile,"%s%s\n",Scoot,"{"); + } + else + { + fprintf(Outfile,"%s%s\n",Scoot,"{register int BCX_REPEAT;"); + fprintf(Outfile,"%s%s%s%s\n",Scoot,"for(BCX_REPEAT=1;BCX_REPEAT<=",lszTmp,";BCX_REPEAT++)"); + fprintf(Outfile,"%s%s\n",Scoot,"{"); + } + BumpUp(); + break; + } + if(str_cmp(Lookup,"endrepeat")==0) + { + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + BumpDown(); + break; + } + if(str_cmp(Lookup,"const")==0) + { + char Buffer[2048]; + char Sep[2048]; + *Buffer=0; + *Sep=0; + *Stk[1]=0; + for(i=2; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],"=")==0) + { + i++; + break; + } + else + { + strcat(Stk[1],Stk[i]); + } + } + strcpy(Stk[1], join(3,"#define ",Clean(Stk[1]),SPC)); + for(i=i; i<=Ndx; i+=1) + { + if(isalpha(Stk[i][0])||(Stk[i][0]==95&&isalpha(Stk[i+1][0]))||Stk[i+1][0]==95) + { + strcpy(Sep," "); + } + else + { + *Sep=0; + } + if(!IsQuoted(Stk[i])) + { + strcpy(Stk[i],RemoveStr(Stk[i],"$")); + } + strcpy(Buffer, join(3,Buffer,Stk[i],Sep)); + } + strcpy(Buffer, join(2,Stk[1],Buffer)); + if(InConditional) + { + if(InFunc) + { + fprintf(Outfile,"%s\n",Buffer); + } + else + { + if(str_cmp(ConstLastDef,"FP6")!=0) + { + fprintf(FP6,"%s%s\n",InIfDef,"// FP6"); + strcpy(ConstLastDef,"FP6"); + } + fprintf(FP6,"%s\n",Buffer); + } + } + else + { + fprintf(FP6,"%s\n",Buffer); + } + break; + } + if(str_cmp(Lookup,"kill")==0) + { + fprintf(Outfile,"%s%s",Scoot,"remove ("); + for(A=2; A<=Ndx; A+=1) + { + fprintf(Outfile,"%s",Clean(trim(Stk[A]))); + } + fprintf(Outfile,"%s\n",");"); + break; + } + if(str_cmp(Lookup,"chdir")==0 || str_cmp(Lookup,"_chdir")==0 || str_cmp(Lookup,"rmdir")==0 || str_cmp(Lookup,"_rmdir")==0 || str_cmp(Lookup,"mkdir")==0 || str_cmp(Lookup,"_mkdir")==0) + { + fprintf(Outfile,"%s%s%s",Scoot,Lookup," ("); + for(A=2; A<=Ndx; A+=1) + { + fprintf(Outfile,"%s",Clean(trim(Stk[A]))); + } + fprintf(Outfile,"%s\n",");"); + break; + } + if(str_cmp(Lookup,"free")==0) + { + VarInfo* VI; + A=2; + if(iMatchWrd(Stk[2],"dynamic")) + { + A=3; + } + if(str_cmp(Stk[A],"(")==0) + { + A++; + Ndx--; + } + strcpy(CVar,Clean(Stk[A])); + vt=CheckLocal(CVar, &id); + if(vt==vt_UNKNOWN) + { + vt=CheckGlobal(CVar, &id); + if(vt==vt_UNKNOWN) + { + Abort(join(3,"Can not REDIM ",CVar," not previously dimensioned")); + } + VI= &GlobalVars[id]; + } + else + { + VI= &LocalVars[id]; + Warning("Local dynamic variables are automatically freed.",1); + } + *CVar=0; + for(i=A; i<=Ndx; i+=1) + { + strcat(CVar,Stk[i]); + } + strcpy(CVar,Clean(CVar)); + if(vt==vt_STRUCT||vt==vt_UNION) + { + GetElement(2, &vt, &dms,VI->VarDef); + if(vt!=vt_UNKNOWN&&dms>0) + { + Use_DynamicA=TRUE; + fprintf(Outfile,"%s%s%s",Scoot,"if (",CVar); + fprintf(Outfile,"%s%s%s%d%s",") { DestroyArr((void **)",CVar,",",(int)dms,", 1); "); + fprintf(Outfile,"%s%s\n",CVar,"=NULL; }"); + break; + } + } + if(VI->VarPntr>1) + { + Use_DynamicA=TRUE; + fprintf(Outfile,"%s%s%s",Scoot,"if (",CVar); + fprintf(Outfile,"%s%s%s%s%s",") { DestroyArr((void **)",CVar,",",str(VI->VarPntr),", 1); "); + fprintf(Outfile,"%s%s\n",CVar,"=NULL; }"); + } + else + { + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,"free(",CVar,"), ",CVar,"=NULL;"); + } + break; + } + if(str_cmp(Lookup,"midstr")==0) + { + *Src=0; + for(A=1; A<=Ndx; A+=1) + { + strcat(Src,Clean(Stk[A])); + } + fprintf(Outfile,"%s%s%s\n",Scoot,trim(Src),";"); + break; + } + if(str_cmp(Lookup,"swap")==0) + { + VarInfo* VI1; + VarInfo* VI2; + int indx; + fprintf(Outfile,"%s%s",Scoot,"swap ((BYTE*)&"); + for(i=2; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],",")==0) + { + break; + } + fprintf(Outfile,"%s",Clean(Stk[i])); + } + A=CheckLocal(Stk[2], &indx); + if(A==vt_UNKNOWN) + { + A=CheckGlobal(Stk[2], &indx); + if(A==vt_UNKNOWN) + { + Abort(join(3,"Variable '",Stk[2],"' in swap statement unknown")); + } + VI1= &GlobalVars[indx]; + } + else + { + VI1= &LocalVars[indx]; + } + if(str_cmp(right(Stk[i-1],1),"]")!=0) + { + if(VI1->VarType==vt_CHAR&&VI1->VarPntr==1) + { + fprintf(Outfile,"%s","[0]"); + } + } + fprintf(Outfile,"%s",",(BYTE*)&"); + i++; + for(j=i; j<=Ndx; j+=1) + { + fprintf(Outfile,"%s",Clean(Stk[j])); + } + A=CheckLocal(Stk[i], &indx); + if(A==vt_UNKNOWN) + { + A=CheckGlobal(Stk[i], &indx); + if(A==vt_UNKNOWN) + { + Abort(join(3,"Variable '",Stk[i],"' in swap statement unknown")); + } + VI2= &GlobalVars[indx]; + } + else + { + VI2= &LocalVars[indx]; + } + if(str_cmp(right(Stk[j-1],1),"]")!=0) + { + if(VI2->VarType==vt_CHAR&&VI2->VarPntr==1) + { + fprintf(Outfile,"%s","[0]"); + } + } + if(VI1->VarType!=VI2->VarType) + { + Warning("Possible size error in swap statement"); + } + if(VI2->VarType==vt_STRVAR||VI2->VarType==vt_CHAR) + { + fprintf(Outfile,"%s",",strlen("); + } + else + { + fprintf(Outfile,"%s",",sizeof("); + } + for(j=i; j<=Ndx; j+=1) + { + fprintf(Outfile,"%s",Clean(Stk[j])); + } + fprintf(Outfile,"%s\n","));"); + break; + } + if(str_cmp(Lookup,"rename")==0) + { + fprintf(Outfile,"%s%s",Scoot,"rename ("); + for(A=2; A<=Ndx; A+=1) + { + fprintf(Outfile,"%s",Clean(trim(Stk[A]))); + } + fprintf(Outfile,"%s\n",");"); + break; + } + if(str_cmp(Lookup,"copyfile")==0) + { + fprintf(Outfile,"%s%s",Scoot,"CopyFile "); + if(str_cmp(Stk[2],"(")!=0) + { + fprintf(Outfile,"%s","("); + } + for(A=2; A<=Ndx; A+=1) + { + fprintf(Outfile,"%s",Clean(trim(Stk[A]))); + } + if(str_cmp(Stk[Ndx],")")!=0) + { + fprintf(Outfile,"%s\n",");"); + } + else + { + fprintf(Outfile,"%s\n",";"); + } + break; + } + if(str_cmp(Lookup,"shell")==0) + { + if(Ndx>2) + { + for(A=3; A<=Ndx; A+=1) + { + strcpy(Stk[2], join(2,Stk[2],Stk[A])); + } + } + strcpy(ZZ,Stk[2]); + if(ZZ[0]==0) + { + strcpy(ZZ,DDQ); + } + fprintf(Outfile,"%s%s%s%s\n",Scoot,"Shell(",Clean(ZZ),");"); + break; + } + if(str_cmp(Lookup,"lineinput")==0) + { + i=DataType(Stk[2]); + if(i==vt_STRLIT||i==vt_STRVAR) + { + if(i!=vt_STRLIT) + { + strcpy(Stk[2],Clean(Stk[2])); + } + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,"printf(",enc("%s"),",",Stk[2],");"); + fprintf(Outfile,"%s%s%s%s\n",Scoot,"AR_fgets_retval=fgets(",Clean(Stk[3]),",2048-1,stdin);"); + fprintf(Outfile,"%s%s%s%s%s\n",Scoot,Clean(Stk[3]),"[strlen(",Clean(Stk[3]),")-1]=0;"); + break; + } + strcpy(Stk[2],RemoveStr(Stk[2],"#")); + if(DataType(Stk[2])==vt_NUMBER) + { + strcpy(Stk[2], join(2,"FP",Stk[2])); + } + strcpy(Handl,extract(Stk[2],"[")); + if(CheckLocal(Handl, &i)==vt_UNKNOWN) + { + if(CheckGlobal(Handl, &i)==vt_UNKNOWN) + { + AddGlobal(Handl,vt_FILEPTR,0,"",0,0,0,0); + } + } + strcpy(Var,Clean(Stk[3])); + *Var1=0; + strcpy(CVar,Var); + if(inchr(Var,"[")&&inchr(Var,"]")) + { + if(instr_b(Var,"[++")) + { + strcpy(CVar,replace(CVar,"++","")); + } + if(instr_b(Var,"[--")) + { + strcpy(CVar,replace(CVar,"--","")); + } + if(instr_b(Var,"++]")) + { + strcpy(CVar,replace(CVar,"++","")); + strcpy(Var1,mid(Var,inchr(Var,"[")+1)); + strcpy(Var1,extract(Var1,"]")); + strcpy(Var,CVar); + } + if(instr_b(Var,"--]")) + { + strcpy(CVar,replace(CVar,"--","")); + strcpy(Var1,mid(Var,inchr(Var,"[")+1)); + strcpy(Var1,extract(Var1,"]")); + strcpy(Var,CVar); + } + } + fprintf(Outfile,"%s%s%s\n",Scoot,Var,"[0]=0;"); + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,"AR_fgets_retval=fgets(",Var,",1048576,",Clean(Stk[2]),");"); + fprintf(Outfile,"%s%s%s%s%s%s",Scoot,"if(",CVar,"[strlen(",CVar,")-1]==10)"); + fprintf(Outfile,"%s%s%s%s\n",CVar,"[strlen(",CVar,")-1]=0;"); + if(Var1[0]!=0) + { + fprintf(Outfile,"%s%s\n",Var1,";"); + } + break; + } + if(str_cmp(Lookup,"open")==0) + { + for(A=1; A<=Ndx; A+=1) + { + strcpy(Keyword,lcase(Stk[A])); + for(;;) + { + if(str_cmp(Keyword,"open")==0) + { + *Stk[A]=0; + break; + } + if(str_cmp(Keyword,"for")==0) + { + *Stk[A]=0; + *Filnam=0; + for(j=2; j<=A-1; j+=1) + { + strcat(Filnam,Stk[j]); + } + strcpy(Filnam,Clean(Filnam)); + break; + } + if(str_cmp(Keyword,"as")==0) + { + *Stk[A]=0; + if(DataType(Stk[A+1])==vt_NUMBER) + { + strcpy(Stk[A+1], join(2,"FP",Stk[A+1])); + } + if(CheckLocal(Stk[A+1], &i)==vt_UNKNOWN) + { + if(CheckGlobal(Stk[A+1], &i)==vt_UNKNOWN) + { + AddGlobal(Stk[A+1],vt_FILEPTR,0,"",0,0,0,0); + } + } + *Var=0; + for(j=A+1; j<=Ndx; j+=1) + { + if(iMatchWrd(Stk[j],"reclen")) + { + break; + } + strcat(Var,Stk[j]); + *Stk[j]=0; + } + strcpy(Handl, join(2,Var,"@")); + break; + } + if(str_cmp(Keyword,"network")==0) + { + Use_Socket=TRUE; + break; + } + if(str_cmp(Keyword,"input")==0) + { + strcpy(Op,enc("r")); + *Stk[A]=0; + break; + } + if(str_cmp(Keyword,"output")==0) + { + strcpy(Op,enc("w")); + *Stk[A]=0; + break; + } + if(str_cmp(Keyword,"append")==0) + { + strcpy(Op,enc("a")); + *Stk[A]=0; + break; + } + if(str_cmp(Keyword,"binary")==0) + { + strcpy(Op,enc("rb+")); + *Stk[A]=0; + break; + } + if(str_cmp(Keyword,"binaryappend")==0) + { + strcpy(Op,enc("ab+")); + *Stk[A]=0; + break; + } + if(str_cmp(Keyword,"binarynew")==0) + { + strcpy(Op,enc("wb+")); + *Stk[A]=0; + break; + } + if(str_cmp(Keyword,"binaryinput")==0) + { + strcpy(Op,enc("rb")); + *Stk[A]=0; + break; + } + if(str_cmp(Keyword,"binaryoutput")==0) + { + strcpy(Op,enc("rb+")); + *Stk[A]=0; + break; + } + if(str_cmp(Keyword,"reclen")==0) + { + if(str_cmp(Stk[A+1],"=")==0) + { + for(j=A+2; j<=Ndx; j+=1) + { + strcpy(Stk[j-1],Stk[j]); + } + Ndx--; + } + strcpy(Var, join(2,extract(Clean(Handl),"["),"len")); + if(CheckLocal(Var, &i)==vt_UNKNOWN) + { + AddGlobal(Var,vt_INTEGER,0,"",0,0,0,0); + } + else + { + if(CheckLocal(Var, &i)==vt_UNKNOWN) + { + AddLocal(Var,vt_INTEGER,0,"",0,0,0); + strcpy(Var, join(2,"int ",Var)); + } + } + i=CheckType(Stk[A+1]); + strcpy(ZZ,lcase(Stk[A+1])); + if(i==vt_STRUCT||i==vt_UNION||str_cmp(ZZ,"int")==0 || str_cmp(ZZ,"double")==0 || str_cmp(ZZ,"float")==0) + { + fprintf(Outfile,"%s%s%s%s%s\n",Scoot,Var," = sizeof(",Stk[A+1],");"); + } + else + { + fprintf(Outfile,"%s%s%s%s%s\n",Scoot,Var," = ",Clean(Stk[A+1]),";"); + } + *Stk[A]=0; + *Stk[A+1]=0; + } + break; + } + } + fprintf(Outfile,"%s%s%s%s%s%s%s%s\n",Scoot,"if((",Clean(Handl),"=fopen(",Filnam,",",Op,"))==0)"); + fprintf(Outfile,"%s%s\n",Scoot," {"); + strcpy(lszTmp,enc("Can't open file %s\\n")); + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot," fprintf(stderr,",lszTmp,",",Filnam,");"); + fprintf(Outfile,"%s%s\n",Scoot," exit(1);"); + fprintf(Outfile,"%s%s\n",Scoot," }"); + break; + } + if(str_cmp(Lookup,"record")==0) + { + static struct _functionParse ffp; + memset(&ffp,0,sizeof(ffp)); + int numargs=0; + if(DataType(Stk[2])==vt_NUMBER) + { + strcpy(Stk[2], join(2,"FP",Stk[2])); + } + if(Ndx>1) + { + numargs=SepFuncArgs(1, &ffp,FALSE); + } + if(numargs<1) + { + Abort("Missing required arguments to RECORD"); + } + if(numargs>4) + { + Abort("Too many arguments to RECORD"); + } + if(numargs==3) + { + fprintf(Outfile,"%s%s%s%s%s%s%s%s%s%s\n",Scoot,"fseek(",GetArg(1, &ffp),", (",GetArg(2, &ffp)," - 1) * ",Stk[2],"len + ",GetArg(3, &ffp),", SEEK_SET);"); + } + else if(numargs==2) + { + fprintf(Outfile,"%s%s%s%s%s%s%s%s\n",Scoot,"fseek(",GetArg(1, &ffp),", (",GetArg(2, &ffp)," - 1) * ",Stk[2],"len, SEEK_SET);"); + } + else + { + fprintf(Outfile,"%s%s%s%s\n",Scoot,"fseek(",GetArg(1, &ffp),", 0, SEEK_SET);"); + } + break; + } + if(str_cmp(Lookup,"fwrite")==0) + { + if(DataType(Stk[2])==vt_NUMBER) + { + strcpy(Stk[2], join(2,"FP",Stk[Ndx])); + } + if(CheckLocal(Stk[2], &i)==vt_UNKNOWN) + { + AddGlobal(Stk[2],vt_FILEPTR,0,"",0,0,0,0); + } + *Handl=0; + for(j=2; j<=Ndx; j+=1) + { + if(iMatchWrd(Stk[j],",")||iMatchWrd(Stk[j],";")) + { + *Stk[j]=0; + break; + } + strcat(Handl,Stk[j]); + *Stk[j]=0; + } + strcat(Handl,"@"); + strcpy(ZZ, join(2,"f",PrintWriteFormat(1))); + strcpy(ZZ, join(4,left(ZZ,8),Clean(Handl),",",mid(ZZ,9))); + fprintf(Outfile,"%s%s\n",Scoot,ZZ); + break; + } + if(str_cmp(Lookup,"close")==0) + { + if(Ndx==1) + { + fprintf(Outfile,"%s%s\n",Scoot,"fcloseall();"); + break; + } + if(DataType(Stk[2])==vt_NUMBER) + { + strcpy(Stk[2], join(2,"FP",Stk[Ndx])); + } + if(CheckLocal(Stk[2], &i)==vt_UNKNOWN) + { + if(CheckGlobal(Stk[2], &i)==vt_UNKNOWN) + { + AddGlobal(Stk[2],vt_FILEPTR,0,"",0,0,0,0); + } + } + *Handl=0; + for(j=2; j<=Ndx; j+=1) + { + strcat(Handl,Stk[j]); + } + fprintf(Outfile,"%s%s%s%s\n",Scoot,"if(",Handl,")"); + fprintf(Outfile,"%s%s\n",Scoot," {"); + fprintf(Outfile,"%s%s%s%s\n",Scoot," fclose(",Handl,");"); + fprintf(Outfile,"%s%s%s%s\n",Scoot," ",Handl,"=NULL;"); + fprintf(Outfile,"%s%s\n",Scoot," }"); + break; + } + if(str_cmp(Lookup,"call")==0) + { + *lszTmp=0; + for(Tmp=2; Tmp<=Ndx; Tmp+=1) + { + strcat(lszTmp,Clean(Stk[Tmp])); + } + if(!iMatchRgt(lszTmp,")")) + { + strcat(lszTmp,"()"); + } + strcat(lszTmp,";"); + fprintf(Outfile,"%s%s\n",Scoot,lszTmp); + break; + } + if(str_cmp(Lookup,"declare")==0) + { + static struct _functionParse FP; + memset(&FP,0,sizeof(FP)); + char TempProto[2048]; + FuncSubDecs1("sub"); + SepFuncArgs(3, &FP,TRUE); + strcpy(TempProto,MakeDecProto( &FP)); + if(!NoTypeDeclare) + { + fprintf(FP4,"%s%s\n",TempProto,";"); + } + else + { + ProtoCnt++; + strcpy(ProtoType[ProtoCnt].Prototype, join(2,TempProto,";")); + } + break; + } + if(str_cmp(Lookup,"function")==0 || str_cmp(Lookup,"sub")==0 || str_cmp(Lookup,"constructor")==0 || str_cmp(Lookup,"destructor")==0) + { + static char CTOR_USE[2048]; + memset(&CTOR_USE,0,sizeof(CTOR_USE)); + static char CTOR_SRC[2048]; + memset(&CTOR_SRC,0,sizeof(CTOR_SRC)); + static int New_Ndx; + memset(&New_Ndx,0,sizeof(New_Ndx)); + if(str_cmp(Stk[2],"main")==0) + { + strcpy(Stk[1],"function"); + strcpy(Stk[2],"main%"); + ForceMainToFunc=TRUE; + } + if(iMatchWrd(Stk[1],"constructor")||iMatchWrd(Stk[1],"destructor")) + { + strcpy(Stk[1],"sub"); + {register int ct; + for(ct=1; ct<=Ndx; ct+=1) + { + if(str_cmp(Stk[ct],"using")==0) + { + New_Ndx=ct-1; + {register int ut; + for(ut=ct; ut<=Ndx; ut+=1) + { + strcat(CTOR_USE,Stk[ut]); + } + } + } + } + } + if(strlen(CTOR_USE)) + { + strcpy(CTOR_USE,iReplace(CTOR_USE,"using",":")); + Ndx=New_Ndx; + } + Use_Ctor=TRUE; + } + FuncSubDecs1("sub"); + IsStdFunc=FALSE; + if(iMatchWrd(Stk[Ndx],"stdcall")) + { + strcpy(CallType,"__attribute__((stdcall)) "); + Ndx--; + IsStdFunc=TRUE; + } + InFunc=TRUE; + InMain=FALSE; + LocalVarCnt=0; + if(InNameSpace) + { + Outfile=FP2; + } + else + { + Outfile=FP3; + } + FuncSubDecs2("sub",mt_FuncSubDecC_Dec); + strcpy(VarCode.Functype,ltrim(VarCode.Functype)); + strcpy(Funcname,Clean(Stk[2])); + if(IsExported||IsStdFunc) + { + strcpy(Funcname, join(2,CallType,Funcname)); + } + VarCode.Method=mt_FuncSubDecC_Dec2; + A=3; + while(A<=Ndx) + { + if(str_cmp(Stk[A+1],"(")==0) + { + for(k=A+2; k<=Ndx; k+=1) + { + if(str_cmp(Stk[k],")")==0) + { + break; + } + } + if(iMatchWrd(Stk[k+2],"sub")) + { + j=vt_VOID; + strcpy(VarCode.AsToken,"void"); + } + else if(iMatchWrd(Stk[k+2],"function")) + { + GetTypeInfo(Stk[k+3], &IsPointer, &i, &j); + strcpy(VarCode.AsToken,Stk[k+3]); + } + strcpy(VarCode.Token,Stk[A]); + VarCode.VarNo=j; + VarCode.IsPtrFlag=1; + VarCode.Method=mt_FuncSubx1; + GetVarCode( &VarCode); + strcpy(Var,Clean(Stk[A])); + *lszTmp=0; + A+=2; + while(A<=k) + { + if(iMatchWrd(Stk[A+1],"as")&&A1) + { + strcpy(ProtoType[ProtoCnt].Condition,ProtoType[ProtoCnt-1].Condition); + } + else + { + *ProtoType[ProtoCnt].Condition=0; + } + } + else + { + strcpy(ProtoType[ProtoCnt].Condition,InIfDef); + } + ProtoType[ProtoCnt].CondLevel=InConditional; + if(*InIfDef) + { + if(str_cmp(InIfDef,"FP3")!=0) + { + fprintf(Outfile,"%s\n",InIfDef); + printf("%s\n",InIfDef); + } + } + if(Use_Ctor) + { + strcpy(VarCode.Header,replace(VarCode.Header,"void ","")); + strcpy(VarCode.Header,replace(VarCode.Header,"void","")); + if(strlen(CTOR_USE)) + { + fprintf(Outfile,"%s\n",VarCode.Header); + fprintf(Outfile,"%s%s\n",Scoot,CTOR_USE); + } + else + { + fprintf(Outfile,"%s\n",VarCode.Header); + } + Use_Ctor=FALSE; + } + else if(InNameSpace) + { + char szCPP_SF1[2048]; + *szCPP_SF1=0; + if(iMatchLft(Lookup,"public")) + { + strcpy(szCPP_SF1,"public: virtual "); + } + fprintf(Outfile,"%s%s%s\n",Scoot,szCPP_SF1,VarCode.Header); + } + else + { + fprintf(Outfile,"%s\n",VarCode.Header); + } + fprintf(Outfile,"%s%s\n",Scoot,"{"); + BumpUp(); + break; + } + if(str_cmp(Lookup,"optfunction")==0 || str_cmp(Lookup,"optsub")==0) + { + FuncSubDecs1("optsub"); + InFunc=TRUE; + LocalVarCnt=0; + Outfile=FP3; + if(InNameSpace) + { + Outfile=FP2; + } + else + { + Outfile=FP3; + } + FuncSubDecs2("optsub",mt_Opts); + strcpy(Funcname,Clean(Stk[2])); + VarCode.Method=mt_Opts2; + A=4; + while(A1) + { + strcpy(ZZ,replace(ZZ,"][",",")); + } + strcpy(ZZ,Clean(ZZ)); + RemoveAll(ZZ,"[]"); + if(vt==vt_STRVAR) + { + vt=vt_CHAR; + strcpy(SOF,"char"); + if(InTypeDef) + { + if(str_cmp(Stk[3],"[")!=0) + { + dms--; + } + else + { + vt=vt_CHARPTR; + } + } + dms++; + strcat(ZZ,",65535"); + } + if(InTypeDef) + { + if(vt==vt_STRUCT) + { + fprintf(Outfile,"%s%s%s%s%s%s%s\n",Scoot,"struct _",SOF," ",stringx(dms,42),CVar,";"); + } + else + { + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,SOF," ",stringx(dms,42),CVar,";"); + } + AddTypedefElement(BaseTypeDefsCnt[InTypeDef],vt,CVar,SOF,dms); + } + else if(InFunc) + { + LocalDynArrCount++; + strcpy(LocalDynArrName[LocalDynArrCount], join(9,"if (",CVar,") { DestroyArr((void **)",CVar,",",str(dms),", 1); ",CVar,"=NULL; }")); + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,SOF," ",stringx(dms,42),CVar,"=0;"); + AddLocal(CVar,vt,id,"",dms,0,0); + } + else + { + if(Use_GenFree) + { + GlobalDynaCnt++; + strcpy(GlobalDynaStr[GlobalDynaCnt], join(9,"if (",CVar,") { DestroyArr((void **)",CVar,",",str(dms),", 1); ",CVar,"=NULL; }")); + } + AddGlobal(CVar,vt,id,"",dms,0,0,0); + } + if(!InTypeDef) + { + fprintf(Outfile,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",Scoot,CVar,"= (",SOF,stringx(dms,42),")CreateArr (",CVar,",sizeof(",SOF,"),0,",trim(str(dms)),",",ZZ,");"); + } + break; + } + if(str_cmp(Lookup,"redim")==0) + { + int IsPreserve; + char SOF[2048]; + VarInfo* VI; + int vt1=0; + int IsSplat=0; + int BC=0; + int StartPoint; + int AsPos=Ndx; + HandleNonsense(); + IsPreserve=iMatchWrd(Stk[2],"preserve"); + StartPoint=2+IsPreserve; + vt1=DataType(Stk[StartPoint]); + strcpy(CVar,Clean(Stk[StartPoint])); + IsSplat=iMatchWrd(Stk[StartPoint+1],"*"); + ValidVar(CVar); + for(i=Ndx; i>=1; i+=-1) + { + if(iMatchWrd(Stk[AsPos],"as")) + { + AsPos=i-1; + break; + } + } + int L=AsPos; + int SP=0; + while(L>StartPoint) + { + if(str_cmp(Stk[L],"[")==0) + { + BC--; + } + else if(str_cmp(Stk[L],"]")==0) + { + BC++; + if(BC==1) + { + L--; + continue; + } + } + if(BC==0) + { + SP++; + if(str_cmp(Stk[L-1],"]")!=0) + { + break; + } + strcpy(ZZ, join(2,",",ZZ)); + } + else + { + strcpy(ZZ, join(2,Stk[L],ZZ)); + } + L--; + } + vt=CheckLocal(CVar, &id); + if(vt==vt_UNKNOWN) + { + vt=CheckGlobal(CVar, &id); + if(vt==vt_UNKNOWN) + { + Abort(join(3,"Can not REDIM ",CVar," not previously dimensioned")); + } + VI= &GlobalVars[id]; + } + else + { + VI= &LocalVars[id]; + } + dms=VI->VarPntr; + if(vt==vt_STRUCT||vt==vt_UDT||vt==vt_UNION) + { + strcpy(SOF,GetElement(StartPoint, &vt, &dms,VI->VarDef)); + i=Ndx; + Ndx=L-1; + AsmUnknownStructs(1); + Ndx=i; + RemEmptyTokens(); + strcpy(CVar,Clean(Stk[StartPoint])); + IsSplat=iMatchWrd(Stk[StartPoint+1],"*"); + } + else + { + strcpy(SOF,GetVarTypeName(vt)); + } + if(iMatchWrd(Stk[Ndx-1],"as")) + { + if(str_cmp(SOF,Stk[Ndx])!=0 && !iMatchWrd(Stk[Ndx],"string")) + { + Abort(join(6,"Can not change types for variable ",CVar," previously defined as ",SOF," on line",str(VI->VarLine))); + } + if(iMatchWrd(Stk[Ndx],"string")) + { + Ndx--; + strcpy(Stk[Ndx],"["); + strcpy(Stk[++Ndx],"65535"); + strcpy(Stk[++Ndx],"]"); + } + else + { + Ndx-=2; + } + } + else + { + if((vt==vt_CHAR&&vt1==vt_STRVAR&&IsSplat==0)||vt==vt_CHARPTR) + { + Ndx++; + strcpy(Stk[Ndx],"["); + strcpy(Stk[++Ndx],"65535"); + strcpy(Stk[++Ndx],"]"); + } + } + if(str_cmp(Stk[3+IsPreserve],"[")==0) + { + if(IsPreserve) + { + StartPoint=4; + } + else + { + fprintf(Outfile,"%s%s%s%s%s%s%s%s%s%s\n",Scoot,"if (",CVar,") { DestroyArr((void **)",CVar,",",str(dms),", 1); ",CVar,"=NULL; }"); + StartPoint=3; + } + Use_DynamicA=TRUE; + A=0; + *ZZ=0; + for(i=StartPoint; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],"[")==0) + { + A++; + i++; + BC=1; + while(BC>0) + { + if(str_cmp(Stk[i],"[")==0) + { + BC++; + strcat(ZZ,Stk[i]); + } + else + { + if(str_cmp(Stk[i],"]")==0) + { + BC--; + if(BC==0&&i2+IsVolatile) + { + strcat(DimType,Stk[i]); + } + } + strcpy(Var,RemoveStr(Stk[Ndx],"*")); + GetTypeInfo(Var, &w, &id, &vt); + if(vt==vt_STRVAR) + { + strcpy(Stk[Ndx],"char"); + strcpy(Var,Stk[Ndx]); + strcat(DimType,"[65535]"); + strcat(lszTmp,"[65535]"); + } + if(InFunc||InTypeDef) + { + if(IsRegister||IsAuto) + { + if(IsRegister) + { + if(IsVolatile) + { + Abort("Register volatile not supported"); + } + if(vt==vt_FILEPTR) + { + fprintf(Outfile,"%s%s",Scoot,"register FILE* "); + } + else + { + fprintf(Outfile,"%s%s%s%s%s%s",Scoot,"register ",sConst," ",Stk[Ndx]," "); + } + } + else + { + if(vt==vt_FILEPTR) + { + fprintf(Outfile,"%s%s%s%s",Scoot,"auto ",IV," FILE* "); + } + else + { + fprintf(Outfile,"%s%s%s%s%s%s%s%s",Scoot,"auto ",IV," ",sConst," ",Stk[Ndx]," "); + } + } + } + else + { + if(IsRaw==TRUE) + { + if(vt==vt_FILEPTR) + { + fprintf(Outfile,"%s%s%s%s",Scoot,"static ",IV," FILE* "); + } + else + { + fprintf(Outfile,"%s%s%s%s%s%s",Scoot,IV,sConst," ",Stk[Ndx]," "); + } + } + else + { + if(InTypeDef) + { + *UseStatic=0; + } + else + { + strcpy(UseStatic,"static "); + } + if(vt==vt_STRUCT) + { + fprintf(Outfile,"%s%s%s%s%s%s%s%s",Scoot,UseStatic,IV,sConst," ","struct _",Stk[Ndx]," "); + } + else + { + if(vt==vt_FILEPTR) + { + fprintf(Outfile,"%s%s%s%s",Scoot,UseStatic,IV,"FILE *"); + } + else + { + fprintf(Outfile,"%s%s%s%s%s%s%s",Scoot,UseStatic,IV,sConst," ",Stk[Ndx]," "); + } + } + if(InTypeDef) + { + AddTypedefElement(BaseTypeDefsCnt[InTypeDef],vt,CVar,Var,0); + } + } + } + if(InFunc&&!InTypeDef) + { + AddLocal(Var1,vt,id,DimType,IsPointer,0,0,iIsConst); + } + fprintf(Outfile,"%s%s\n",Clean(lszTmp),";"); + if(!InTypeDef&&!IsStatic&&!IsRaw&&!IsRegister&&!IsVolatile) + { + strcpy(T,Clean(extract(lszTmp,"["))); + if(IsPointer) + { + fprintf(Outfile,"%s%s%s%s%s%s%s\n",Scoot,"memset(&",T,",0,sizeof(",Clean(Var)," *","));"); + } + else + { + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,"memset(&",T,",0,sizeof(",T,"));"); + } + } + } + else + { + if(IsVolatile) + { + AddGlobal(Var1,vt,id,DimType,IsPointer,0,3,0,iIsConst); + } + else + { + AddGlobal(Var1,vt,id,DimType,IsPointer,0,0,0,iIsConst); + } + } + break; + } + if(InFunc||InTypeDef) + { + *lszTmp=0; + if(iMatchWrd(Stk[3+IsVolatile],"as")) + { + VType=CheckType(Stk[4+IsVolatile]); + if(VType==vt_CHAR) + { + if(str_cmp(Stk[5],"*")==0) + { + strcpy(lszTmp, join(3,"[",Stk[6+IsVolatile],"]")); + } + } + } + else + { + for(i=3+IsVolatile; i<=Ndx; i+=1) + { + strcat(lszTmp,Stk[i]); + } + strcpy(lszTmp,ltrim(Clean(lszTmp))); + if(VType==vt_STRVAR) + { + if(str_cmp(lszTmp,"[65535]")!=0) + { + strcat(lszTmp,"[2048]"); + } + } + } + j=(!InTypeDef BAND !IsStatic BAND !IsRaw BAND !IsRegister); + if(j) + { + strcpy(T,Clean(extract(CVar,"["))); + } + for(;;) + { + if(VType==vt_STRVAR) + { + if(IsRaw) + { + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,IV,"char ",CVar,lszTmp,";"); + } + else if(IsAuto) + { + fprintf(Outfile,"%s%s%s%s%s%s%s\n",Scoot,"auto ",IV,"char ",CVar,lszTmp,";"); + } + else if(IsRegister) + { + if(IsVolatile) + { + Abort("register volatile not supported"); + } + fprintf(Outfile,"%s%s%s%s%s\n",Scoot,"register char ",CVar,lszTmp,";"); + } + else + { + if(InTypeDef) + { + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,IV,"char ",CVar,lszTmp,";"); + } + else + { + fprintf(Outfile,"%s%s%s%s%s%s%s\n",Scoot,"static ",IV,"char ",CVar,lszTmp,";"); + } + } + if(j&&!IsVolatile) + { + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,"memset(&",T,",0,sizeof(",T,"));"); + } + break; + } + if(VType>=vt_VarMin&&VType<=vt_VarMax) + { + strcpy(ZZ,GetVarTypeName(VType)); + strcpy(ZZ,rpad(ZZ,7)); + if(IsRaw) + { + fprintf(Outfile,"%s%s%s%s%s%s%s\n",Scoot,IV,ZZ," ",CVar,lszTmp,";"); + } + else if(IsAuto) + { + fprintf(Outfile,"%s%s%s%s%s%s%s%s\n",Scoot,"auto ",IV,ZZ," ",CVar,lszTmp,";"); + } + else if(IsRegister) + { + if(IsVolatile) + { + Abort("Regester volatile not supported"); + } + fprintf(Outfile,"%s%s%s%s%s%s%s\n",Scoot,"register ",ZZ," ",CVar,lszTmp,";"); + } + else + { + if(InTypeDef) + { + fprintf(Outfile,"%s%s%s%s%s%s%s\n",Scoot,IV,ZZ," ",CVar,lszTmp,";"); + } + else + { + fprintf(Outfile,"%s%s%s%s%s%s%s%s\n",Scoot,"static ",IV,ZZ," ",CVar,lszTmp,";"); + } + } + if(j&&!IsVolatile) + { + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,"memset(&",T,",0,sizeof(",T,"));"); + } + } + break; + } + if(InFunc&&!InTypeDef) + { + AddLocal(CVar,VType,0,lszTmp,0,0,0); + } + if(InTypeDef) + { + AddTypedefElement(BaseTypeDefsCnt[InTypeDef],VType,CVar,Var,0); + } + break; + } + *lszTmp=0; + for(i=3+IsVolatile; i<=Ndx; i+=1) + { + strcat(lszTmp,Stk[i]); + } + if(VType==vt_STRVAR&&str_cmp(lszTmp,"")!=0) + { + strcat(lszTmp,"[65535]"); + } + if(IsVolatile) + { + AddGlobal(CVar,VType,0,lszTmp,0,0,3,0); + } + else + { + AddGlobal(CVar,VType,0,lszTmp,0,0,0,0); + } + break; + } + if(str_cmp(Lookup,"extern")==0) + { + int IsVolatile; + IsSubOrFuncPtr=SubFuncTest(); + HandleNonsense(); + IsVolatile=iMatchWrd(Stk[2],"volatile"); + strcpy(CVar,Clean(Stk[2+IsVolatile])); + ValidVar(CVar); + if(str_cmp(Stk[Ndx],"*")==0) + { + PointerFix(); + } + if(str_cmp(Stk[Ndx],"&")==0) + { + *Stk[Ndx--]=0; + strcat(Stk[Ndx],"&"); + } + if(str_cmp(Stk[3+IsVolatile],"*")==0) + { + if(IsVolatile) + { + Abort("volatile dynamic strings not supported"); + } + DimDynaString(CVar,2,0); + break; + } + if(IsSubOrFuncPtr) + { + if(IsVolatile) + { + Abort("volatile SUB/FUNCTION pointers not supported"); + } + if(DimSubFunc(0)) + { + break; + } + } + strcpy(Var,Clean(Stk[2+IsVolatile])); + ValidVar(Var); + IsPointer=0; + *DimType=0; + if(iMatchWrd(Stk[Ndx-1],"as")) + { + GetTypeInfo(Stk[Ndx], &IsPointer, &id, &vt); + strcpy(Stk[Ndx],RemoveStr(Stk[Ndx],"*")); + for(i=3+IsVolatile; i<=Ndx-2; i+=1) + { + strcat(DimType,Stk[i]); + } + } + else + { + i=3+IsVolatile; + while(i<=Ndx) + { + strcat(DimType,Stk[i]); + i++; + } + vt=DataType(Stk[2+IsVolatile]); + id=0; + } + if(vt==vt_STRVAR) + { + strcat(DimType,"[65535]"); + } + if(IsVolatile) + { + AddGlobal(Var,vt,id,DimType,IsPointer,0,4,0); + } + else + { + AddGlobal(Var,vt,id,DimType,IsPointer,0,1,0); + } + break; + } + if(str_cmp(Lookup,"shared")==0 || str_cmp(Lookup,"global")==0) + { + int w=0; + char SOF[2048]; + int IsShared; + int IsVolatile; + IsSubOrFuncPtr=SubFuncTest(); + HandleNonsense(); + IsVolatile=iMatchWrd(Stk[2],"volatile"); + strcpy(CVar,Clean(Stk[2+IsVolatile])); + ValidVar(CVar); + IsShared=iMatchWrd(Stk[1],"shared"); + if(str_cmp(Stk[Ndx],"*")==0) + { + PointerFix(); + } + if(str_cmp(Stk[Ndx],"&")==0) + { + *Stk[Ndx--]=0; + strcat(Stk[Ndx],"&"); + } + if(str_cmp(Stk[3+IsVolatile],"*")==0) + { + if(IsVolatile) + { + Abort("volatile dynamic strings not supported"); + } + DimDynaString(CVar,1,IsShared); + break; + } + if(IsSubOrFuncPtr) + { + if(IsVolatile) + { + Abort("volatile SUB/FUNCTION pointers not supported"); + } + DimSubFunc(0); + break; + } + if(iMatchWrd(Stk[2],"dynamic")) + { + strcpy(CVar,Clean(Stk[3])); + ValidVar(CVar); + if(iMatchWrd(Stk[Ndx-1],"as")) + { + strcpy(SOF,Stk[Ndx]); + GetTypeInfo(SOF, &w, &id, &vt); + if(vt==vt_STRLIT||vt==vt_DECFUNC||vt==vt_NUMBER||(vt==vt_VOID&&inchr(Stk[Ndx],"*")==0)) + { + Abort(join(2,Stk[Ndx]," is not a valid type")); + } + Ndx-=2; + } + else + { + vt=DataType(Stk[3]); + id=0; + strcpy(SOF,GetVarTypeName(vt)); + } + Use_DynamicA=TRUE; + *ZZ=0; + for(i=4; i<=Ndx; i+=1) + { + strcat(ZZ,Stk[i]); + } + dms=tally(ZZ,"][")+1; + if(dms>1) + { + strcpy(ZZ,replace(ZZ,"][",",")); + } + strcpy(ZZ,Clean(ZZ)); + RemoveAll(ZZ,"[]"); + if(vt==vt_STRVAR) + { + vt=vt_CHAR; + strcpy(SOF,"char"); + dms++; + strcat(ZZ,",65535"); + } + if(Use_GenFree) + { + GlobalDynaCnt++; + strcpy(GlobalDynaStr[GlobalDynaCnt], join(9,"if (",CVar,") { DestroyArr((void **)",CVar,",",str(dms),", 1); ",CVar,"=NULL; }")); + } + AddGlobal(CVar,vt,id,"",dms,0,0,0); + fprintf(Outfile,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",Scoot,CVar,"= (",SOF,stringx(dms,42),")CreateArr (",CVar,",sizeof(",SOF,"),0,",trim(str(dms)),",",ZZ,");"); + break; + } + IsPointer=0; + strcpy(Var,Clean(Stk[2+IsVolatile])); + ValidVar(Var); + if(iMatchWrd(Stk[Ndx-1],"as")) + { + if(inchr(Stk[Ndx],"*")) + { + IsPointer=tally(Stk[Ndx],"*"); + strcpy(Stk[Ndx],RemoveStr(Stk[Ndx],"*")); + } + *DimType=0; + for(i=3+IsVolatile; i<=Ndx-2; i+=1) + { + strcat(DimType,Stk[i]); + } + GetTypeInfo(Stk[Ndx], &w, &id, &vt); + } + else + { + *DimType=0; + i=3+IsVolatile; + while(i<=Ndx) + { + strcat(DimType,Stk[i]); + i++; + } + vt=DataType(Stk[2+IsVolatile]); + id=0; + } + if(vt==vt_STRVAR) + { + strcat(DimType,"[65535]"); + } + if(IsShared) + { + if(IsVolatile) + { + AddGlobal(Var,vt,id,DimType,IsPointer,0,5,0); + } + else + { + AddGlobal(Var,vt,id,DimType,IsPointer,0,2,0); + } + } + else + { + if(IsVolatile) + { + AddGlobal(Var,vt,id,DimType,IsPointer,0,3,0); + } + else + { + AddGlobal(Var,vt,id,DimType,IsPointer,0,0,0); + } + } + break; + } + if(str_cmp(Lookup,"while")==0) + { + EmitIfCond("while"); + break; + } + if(str_cmp(Lookup,"wend")==0 || str_cmp(Lookup,"endwhile")==0) + { + BumpDown(); + fprintf(Outfile,"%s%s\n",Scoot,"}"); + BumpDown(); + break; + } + if(str_cmp(Lookup,"exit")==0) + { + if(CaseFlag) + { + NoBreak2=TRUE; + } + if(iMatchWrd(Stk[2],"sub")) + { + if(LocalDynaCnt!=0) + { + for(j=1; j<=LocalDynaCnt; j+=1) + { + fprintf(Outfile,"%s%s\n",Scoot,DynaStr[j]); + } + } + if(LocalDynArrCount!=0) + { + for(i=1; i<=LocalDynArrCount; i+=1) + { + fprintf(Outfile,"%s%s\n",Scoot,LocalDynArrName[i]); + } + } + fprintf(Outfile,"%s%s\n",Scoot,"return;"); + break; + } + if(iMatchWrd(Stk[2],"function")) + { + if(LocalDynaCnt!=0) + { + for(j=1; j<=LocalDynaCnt; j+=1) + { + fprintf(Outfile,"%s%s\n",Scoot,DynaStr[j]); + } + } + if(LocalDynArrCount!=0) + { + for(i=1; i<=LocalDynArrCount; i+=1) + { + fprintf(Outfile,"%s%s\n",Scoot,LocalDynArrName[i]); + } + } + fprintf(Outfile,"%s%s\n",Scoot,"return 0;"); + } + else + { + fprintf(Outfile,"%s%s\n",Scoot,"break;"); + } + break; + } + if(str_cmp(Lookup,"goto")==0) + { + if(CaseFlag) + { + NoBreak2=TRUE; + } + fprintf(Outfile,"%s%s%s%s\n",Scoot,"goto ",ucase(Stk[2]),";"); + break; + } + if(str_cmp(Lookup,"print")==0) + { + fprintf(Outfile,"%s%s\n",Scoot,PrintWriteFormat(0)); + break; + } + if(str_cmp(Lookup,"write")==0) + { + fprintf(Outfile,"%s%s\n",Scoot,PrintWriteFormat(1)); + break; + } + if(str_cmp(Lookup,"run")==0) + { + fprintf(Outfile,"%s%s",Scoot,"Run ("); + for(A=2; A<=Ndx; A+=1) + { + fprintf(Outfile,"%s",Clean(Stk[A])); + } + fprintf(Outfile,"%s%s\n",Scoot,");"); + break; + } + if(str_cmp(Lookup,"color")==0) + { + fprintf(Outfile,"%s%s",Scoot,"color ("); + for(A=2; A<=Ndx; A+=1) + { + fprintf(Outfile,"%s",Clean(Stk[A])); + } + fprintf(Outfile,"%s\n",");"); + break; + } + if(str_cmp(Lookup,"locate")==0) + { + fprintf(Outfile,"%s%s",Scoot,"locate ("); + for(A=2; A<=Ndx; A+=1) + { + fprintf(Outfile,"%s",Clean(Stk[A])); + } + fprintf(Outfile,"%s\n",");"); + break; + } + if(str_cmp(Lookup,"cls")==0) + { + fprintf(Outfile,"%s%s\n",Scoot,"cls();"); + break; + } + // case else + { + for(B=1; B<=Ndx; B+=1) + { + if(str_cmp(Stk[B],"=")==0) + { + break; + } + } + if(B-1==Ndx) + { + *lszTmp=0; + for(Tmp=1; Tmp<=Ndx; Tmp+=1) + { + strcat(lszTmp,Clean(Stk[Tmp])); + } + strcat(lszTmp,";"); + if(FuncRetnFlag==2) + { + fprintf(Outfile,"%s\n",lszTmp); + } + else + { + fprintf(Outfile,"%s%s\n",Scoot,lszTmp); + } + if(FuncRetnFlag==2) + { + FuncRetnFlag=0; + *Stk[1]=0; + return; + } + break; + } + for(i=2; i<=B-1; i+=1) + { + strcat(Stk[1],Stk[i]); + } + A=inchr(Stk[1],"*"); + if(A) + { + if(!(inchr(Stk[1],"$")&&A>1)) + { + RemoveAll(Stk[1],"$"); + goto PROCESSNUMERIC; + } + } + static int strtest; + memset(&strtest,0,sizeof(strtest)); + static int varid; + memset(&varid,0,sizeof(varid)); + static struct _VarInfo* vi; + memset(&vi,0,sizeof(VarInfo *)); + static char vr[2048]; + memset(&vr,0,sizeof(vr)); + static int brcnt; + memset(&brcnt,0,sizeof(brcnt)); + strtest=DataType(Stk[1]); + if(strtest==vt_INTEGER) + { + brcnt=tally(Stk[1],"["); + strcpy(vr,extract(Stk[1],"[")); + strtest=CheckLocal(vr, &varid); + if(strtest==vt_UNKNOWN) + { + strtest=CheckGlobal(vr, &varid); + vi= &(GlobalVars[varid]); + } + else + { + vi= &(LocalVars[varid]); + } + if(strtest==vt_CHAR) + { + strtest=vt_STRVAR; + } + if(strtest==vt_STRVAR) + { + if(vi->VarPntr!=0) + { + goto PROCESSNUMERIC; + } + if(tally(vi->VarDim,"[")==brcnt) + { + goto PROCESSNUMERIC; + } + if(tally(vi->VarDim,"[")!=brcnt+1) + { + goto PROCESSNUMERIC; + } + } + } + if(strtest==vt_STRVAR) + { + if(B+1==Ndx) + { + if(str_cmp(Stk[Ndx],DDQ)==0) + { + fprintf(Outfile,"%s%s%s%s\n",Scoot,"*",Clean(Stk[1]),"=0;"); + goto STRINGEXIT; + } + } + if(Ndx==3) + { + strcpy(Stk[1],Clean(Stk[1])); + strcpy(Stk[3],Clean(Stk[3])); + if(str_cmp(Stk[1],"BCX_RetStr")==0) + { + fprintf(Outfile,"%s%s%s%s\n",Scoot,"BCX_RetStr=BCX_TmpStr(strlen(",Stk[3],"));"); + } + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,"strcpy(",Stk[1],",",Stk[3],");"); + goto STRINGEXIT; + } + *Arg=0; + *lszTmp=0; + j=k=0; + if(iMatchLft(Stk[3],"$$")) + { + HasStorage=TRUE; + } + strcpy(Var,Clean(Stk[1])); + if(str_cmp(Clean(Stk[B+1]),Var)==0) + { + k=TRUE; + } + for(A=B+1; A<=Ndx; A+=1) + { + if(str_cmp(Stk[A],"&")==0 && str_cmp(Stk[A-1],",")!=0 && str_cmp(Stk[A-1],"(")!=0) + { + j++; + strcat(Arg,lszTmp); + strcpy(lszTmp,","); + } + else + { + strcat(lszTmp,Clean(Stk[A])); + } + } + if(*lszTmp!=0&&str_cmp(lszTmp,",")!=0) + { + strcat(Arg,lszTmp); + } + RemoveAll(Var,SPC); + if(j==0) + { + if(str_cmp(Var,"BCX_RetStr")==0) + { + if(HasStorage) + { + fprintf(Outfile,"%s%s%s%s\n",Scoot,"BCX_RetStr=",Arg,";"); + goto STRINGEXIT; + } + else + { + fprintf(Outfile,"%s%s%s%s\n",Scoot,"BCX_RetStr=BCX_TmpStr(strlen(",Arg,"));"); + } + } + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,"strcpy(",Var,",",Arg,");"); + goto STRINGEXIT; + } + if(k==TRUE&&j==1) + { + fprintf(Outfile,"%s%s%s%s\n",Scoot,"strcat(",Arg,");"); + goto STRINGEXIT; + } + strcpy(lszTmp,ltrim(str(++j))); + Use_Join=TRUE; + if(str_cmp(Var,"BCX_RetStr")==0) + { + fprintf(Outfile,"%s%s%s%s%s%s\n",Scoot,"BCX_RetStr=join(",lszTmp,",",Arg,");"); + } + else + { + fprintf(Outfile,"%s%s%s%s%s%s%s%s\n",Scoot,"strcpy(",Var,", join(",lszTmp,",",Arg,"));"); + } + +STRINGEXIT:; + break; + } + else + { + +PROCESSNUMERIC:; + for(i=2; i<=B; i+=1) + { + *Stk[i]=0; + } + strcpy(Stk[B],"="); + if(str_cmp(Stk[B+1],Stk[1])==0 && Ndx==5) + { + if(Inset(Stk[B+2],"+-*/")&&str_cmp(Stk[B+3],">")!=0) + { + strcpy(Stk[B], join(2,Stk[B+2],Stk[B])); + *Stk[B+1]=0; + *Stk[B+2]=0; + } + } + fprintf(Outfile,"%s%s",Scoot,Clean(Stk[1])); + for(A=2; A<=Ndx; A+=1) + { + if(str_cmp(Stk[A],"!")==0) + { + fprintf(Outfile,"%s","!"); + } + else + { + fprintf(Outfile,"%s",Clean(Stk[A])); + } + } + fprintf(Outfile,"%s\n",";"); + } + } + break; + } + if(FuncRetnFlag==1) + { + if(LocalDynaCnt!=0) + { + for(j=1; j<=LocalDynaCnt; j+=1) + { + fprintf(Outfile,"%s%s\n",Scoot,DynaStr[j]); + } + } + fprintf(Outfile,"%s%s\n",Scoot,"return BCX_RetStr;"); + } +} + + +void Abort (char *Z) +{ + int i=0; + int j=0; + int k=0; + int varnum=0; + char t[2048]; + char frmt[2048]; + *WarnMsg=0; + if(str_cmp(left(AbortSrc,11),"$BCXVERSION")==0) + { + strcat(WarnMsg,Z); + } + else + { + strcpy(WarnMsg, join(7,WarnMsg,Z," at line",str(ModuleLineNos[ModuleNdx])," in Module: ",trim(Modules[ModuleNdx]),CRLF)); + strcpy(WarnMsg, join(3,WarnMsg,"Original line",CRLF)); + strcpy(WarnMsg, join(3,WarnMsg,AbortSrc,CRLF)); + strcpy(WarnMsg, join(3,WarnMsg,"==============",CRLF)); + strcpy(WarnMsg, join(3,WarnMsg,"Current Tokens",CRLF)); + strcpy(WarnMsg, join(3,WarnMsg,"==============",CRLF)); + for(k=1; k<=Ndx; k+=1) + { + j=strlen(Stk[k]); + if(j<40) + { + j=40-j; + } + else + { + j=8-imod(j,8); + } + strcpy(frmt,lpad(str(k),3)); + strcpy(WarnMsg, join(6,WarnMsg,frmt," ",Stk[k],stringx(j,32),CRLF)); + strcpy(t,Clean(Stk[k])); + i=CheckLocal(t, &varnum); + if(i!=vt_UNKNOWN) + { + strcpy(WarnMsg, join(3,WarnMsg,"is a LOCAL defined at line",str(LocalVars[varnum].VarLine))); + strcpy(WarnMsg, join(4,WarnMsg," in Module: ",LocalVars[varnum].VarModule,CRLF)); + } + else + { + i=CheckGlobal(t, &varnum); + if(i!=vt_UNKNOWN) + { + strcpy(WarnMsg, join(3,WarnMsg,"is a GLOBAL defined at line",str(GlobalVars[varnum].VarLine))); + strcpy(WarnMsg, join(4,WarnMsg," in Module: ",GlobalVars[varnum].VarModule,CRLF)); + strcpy(WarnMsg, join(5,WarnMsg," ",Stk[k],GlobalVars[varnum].VarDim," as ")); + if(GlobalVars[varnum].VarDef) + { + strcpy(WarnMsg, join(3,WarnMsg,trim(TypeDefs[GlobalVars[varnum].VarDef].VarName),CRLF)); + } + else + { + strcpy(WarnMsg, join(3,WarnMsg,trim(GetVarTypeName(GlobalVars[varnum].VarType)),CRLF)); + } + } + else + { + if(Stk[k][0]==34) + { + strcpy(WarnMsg, join(3,WarnMsg,"is a STRING LITERAL",CRLF)); + } + } + } + } + strcpy(WarnMsg, join(3,WarnMsg,"===============",CRLF)); + strcpy(WarnMsg, join(3,WarnMsg,"Original Tokens",CRLF)); + strcpy(WarnMsg, join(3,WarnMsg,"===============",CRLF)); + XParse(AbortSrc); + for(k=1; k<=Ndx; k+=1) + { + j=strlen(Stk[k]); + if(j<40) + { + j=40-j; + } + else + { + j=8-imod(j,8); + } + strcpy(frmt,lpad(str(k),3)); + strcpy(WarnMsg, join(6,WarnMsg,frmt," ",Stk[k],stringx(j,32),CRLF)); + strcpy(t,Clean(Stk[k])); + i=CheckLocal(t, &varnum); + if(i!=vt_UNKNOWN) + { + strcpy(WarnMsg, join(3,WarnMsg,"is a LOCAL defined at line",str(LocalVars[varnum].VarLine))); + strcpy(WarnMsg, join(4,WarnMsg," in Module: ",LocalVars[varnum].VarModule,CRLF)); + } + else + { + i=CheckGlobal(t, &varnum); + if(i!=vt_UNKNOWN) + { + strcpy(WarnMsg, join(3,WarnMsg,"is a GLOBAL defined at line",str(GlobalVars[varnum].VarLine))); + strcpy(WarnMsg, join(4,WarnMsg," in Module: ",GlobalVars[varnum].VarModule,CRLF)); + strcpy(WarnMsg, join(5,WarnMsg," ",Stk[k],GlobalVars[varnum].VarDim," as ")); + if(GlobalVars[varnum].VarDef) + { + strcpy(WarnMsg, join(3,WarnMsg,TypeDefs[GlobalVars[varnum].VarDef].VarName,CRLF)); + } + else + { + strcpy(WarnMsg, join(3,WarnMsg,GetVarTypeName(GlobalVars[varnum].VarType),CRLF)); + } + } + else + { + if(Stk[k][0]==34) + { + strcpy(WarnMsg, join(3,WarnMsg,"is a string literal",CRLF)); + } + } + } + } + } + strcat(WarnMsg,CRLF); + CloseAll(); + remove (ovrFile); + remove (FileOut); + remove (prcFile); + remove (udtFile); + remove (hdrFile); + remove (cstFile); + remove (datFile); + remove (setFile); + remove (enuFile); + remove ("$t$e$m$p"); + if(ErrFile) + { + if((fpErr=fopen(FileErr,"a"))==0) + { + fprintf(stderr,"Can't open file %s\n",FileErr); + exit(1); + } + fprintf(fpErr,"%s%s%d%s%s\n",Z," at line",(int)ModuleLineNos[ModuleNdx]," in Module: ",trim(Modules[ModuleNdx])); + if(fpErr) + { + fclose(fpErr); + fpErr=NULL; + } + } + printf("%s%s%s%s%s\n","Error!",CRLF,FileIn,CRLF,WarnMsg); + FreeGlobals(); + fflush(stdout); + exit(1); +} + + +void BumpDown (void) +{ + Indent--; + Indent--; + if(Indent<0) + { + Indent=0; + } + strcpy(Scoot,space(Indent)); +} + + +void BumpUp (void) +{ + if(Indent<0) + { + Indent=0; + } + Indent++; + Indent++; + strcpy(Scoot,space(Indent)); +} + + +int BraceCount (char *Arg) +{ + char* p; + int braces; + p=Arg; + braces=0; + while(*p) + { + if(*p==c_DblQt) + { + p++; + while(*p!=c_DblQt) + { + if(*p==0) + { + return braces; + } + p++; + } + } + if(*p==125) + { + braces--; + } + if(*p==123) + { + braces++; + } + p++; + } + return braces; +} + + +char* BracketHandler (char *Src, int l) +{ + char* s; + s=Src; + for(;;) + { + if(l==0) + { + for(;;) + { + if(*s==0) + { + break; + } + if(*s==c_DblQt) + { + s++; + while(*s!=c_DblQt) + { + if(*s==0) + { + break; + } + s++; + } + } + if(*s==c_LtBkt) + { + s++; + s=BracketHandler(s,1); + } + if(*s==c_LPar) + { + s++; + s=BracketHandler(s,2); + } + s++; + } + break; + } + if(l==1) + { + while(*s!=c_RtBkt) + { + if(*s==c_DblQt) + { + s++; + while(*s!=c_DblQt) + { + if(*s==0) + { + break; + } + s++; + } + } + if(*s==c_LtBkt) + { + s++; + s=BracketHandler(s,1); + } + if(*s==c_LPar) + { + s++; + s=BracketHandler(s,2); + } + if(*s==c_Komma) + { + *s=1; + } + if(*s==0) + { + break; + } + s++; + } + break; + } + if(l==2) + { + while(*s!=c_RPar) + { + if(*s==c_DblQt) + { + s++; + while(*s!=c_DblQt) + { + if(*s==0) + { + break; + } + s++; + } + } + if(*s==c_LtBkt) + { + s++; + s=BracketHandler(s,1); + } + if(*s==c_LPar) + { + s++; + s=BracketHandler(s,2); + } + if(*s==0) + { + break; + } + s++; + } + } + break; + } + if(l==0) + { + strcpy(Src,replace(Src,chr(1),"][")); + return Src; + } + return s; +} + + +void Push (char *Z) +{ + strcpy(CaseStk[++Pusher],Z); +} + + +void Pop (char *Z) +{ + strcpy(Z,CaseStk[--Pusher]); +} + + +void EmitEpilog (void) +{ + if(NoMain+EndOfProgram==0) + { + fprintf(Outfile,"%s\n","return 0; // End of main program"); + BumpDown(); + fprintf(Outfile,"%s\n","}"); + fflush(Outfile); + } +} + + +void EmitProlog (void) +{ + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","int main(int argc, char *argv[])"); + fflush(Outfile); +} + + +void DeclareVariables (void) +{ + int i; + int A; + char P[2048]; + char VarName[2048]; + char VarDim[2048]; + char Storage[2048]; + if((FP1=fopen(FileOut,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",FileOut); + exit(1); + } + if((Outfile=fopen("$t$e$m$p","w"))==0) + { + fprintf(stderr,"Can't open file %s\n","$t$e$m$p"); + exit(1); + } + if((FP3=fopen(cstFile,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",cstFile); + exit(1); + } + if(lof(cstFile)>0) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s%s\n","// ",BCX_STR_USR_CONST); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n",""); + } + while(!EoF(FP3)) + { + Z[0]=0; + AR_fgets_retval=fgets(Z,1048576,FP3); + if(Z[strlen(Z)-1]==10)Z[strlen(Z)-1]=0; + fprintf(Outfile,"%s\n",ltrim(Z)); + } + if(FP3) + { + fclose(FP3); + FP3=NULL; + } + if(Use_EnumFile) + { + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n","// User's GLOBAL ENUM blocks"); + fprintf(Outfile,"%s\n","// *************************************************"); + if((FP8=fopen(enuFile,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",enuFile); + exit(1); + } + while(!EoF(FP8)) + { + Z[0]=0; + AR_fgets_retval=fgets(Z,1048576,FP8); + if(Z[strlen(Z)-1]==10)Z[strlen(Z)-1]=0; + fprintf(Outfile,"%s\n",Z); + } + if(FP8) + { + fclose(FP8); + FP8=NULL; + } + fprintf(Outfile,"%s\n",""); + } + if((FP3=fopen(udtFile,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",udtFile); + exit(1); + } + if(lof(udtFile)>0) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s%s\n","// ",BCX_STR_USR_TYPES); + fprintf(Outfile,"%s\n","// *************************************************"); + while(!EoF(FP3)) + { + Z[0]=0; + AR_fgets_retval=fgets(Z,1048576,FP3); + if(Z[strlen(Z)-1]==10)Z[strlen(Z)-1]=0; + fprintf(Outfile,"%s%s\n",Scoot,Z); + } + } + if(FP3) + { + fclose(FP3); + FP3=NULL; + } + if(HFileCnt>0) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n","// User Include Files"); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n",""); + A=0; + while(A"); + } + if(Use_SingleFile==TRUE) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s%s\n","// ",BCX_STR_SYS_VARS); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n",""); + if(Use_RegEx) + { + fprintf(Outfile,"%s\n","typedef struct _REGEX"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int count;"); + fprintf(Outfile,"%s\n"," regmatch_t matches[1024];"); + fprintf(Outfile,"%s\n"," PCHAR results[1024];"); + fprintf(Outfile,"%s\n","}REGEX, *LPREGEX;\n"); + } + if(Use_Time) + { + fprintf(Outfile,"%s\n","enum TIME_OPTIONS"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," TIME,"); + fprintf(Outfile,"%s\n"," HOUR,"); + fprintf(Outfile,"%s\n"," MINUTE,"); + fprintf(Outfile,"%s\n"," SECOND,"); + fprintf(Outfile,"%s\n"," APM,"); + fprintf(Outfile,"%s\n"," YEAR,"); + fprintf(Outfile,"%s\n"," MONTH,"); + fprintf(Outfile,"%s\n"," DAY,"); + fprintf(Outfile,"%s\n"," DAYNAME,"); + fprintf(Outfile,"%s\n"," WEEKDAY,"); + fprintf(Outfile,"%s\n"," YEARDAY,"); + fprintf(Outfile,"%s\n"," WEEKNUMBER,"); + fprintf(Outfile,"%s\n"," DATE,"); + fprintf(Outfile,"%s\n"," FULLDATE"); + fprintf(Outfile,"%s\n"," };\n"); + } + if(Use_Findfirst||Use_Findnext) + { + fprintf(Outfile,"%s\n","typedef struct _FILE_FIND_DATA"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," DWORD dwFileAttributes;"); + fprintf(Outfile,"%s\n"," DWORD ftCreationTime;"); + fprintf(Outfile,"%s\n"," DWORD ftLastAccessTime;"); + fprintf(Outfile,"%s\n"," DWORD ftLastWriteTime;"); + fprintf(Outfile,"%s\n"," DWORD nFileSizeHigh;"); + fprintf(Outfile,"%s\n"," DWORD nFileSizeLow;"); + fprintf(Outfile,"%s\n"," char cFileSpec[MAX_PATH];"); + fprintf(Outfile,"%s\n"," char cFileName[MAX_PATH];"); + fprintf(Outfile,"%s\n"," char path[MAX_PATH];"); + fprintf(Outfile,"%s\n"," DIR *FileHandle;"); + fprintf(Outfile,"%s\n","}FILE_FIND_DATA, *LPFILE_FIND_DATA;\n"); + } + if(Use_Ldouble) + { + fprintf(Outfile,"%s\n","#define LDOUBLE long double"); + } + if(Use_Idxqsort) + { + fprintf(Outfile,"%s\n","char*** pppStr;"); + } + if(Use_Idxqsort||Use_IdxqsortSt||Use_PtrqsortSt) + { + fprintf(Outfile,"%s\n","int Key;"); + } + if(Use_IdxqsortSt) + { + fprintf(Outfile,"%s\n","char* cmp1;"); + fprintf(Outfile,"%s\n","int StructSize;"); + } + if(Use_PtrqsortSt) + { + fprintf(Outfile,"%s\n","int OffSet;"); + } + if(Use_NUL) + { + fprintf(Outfile,"%s\n","char NUL [1]={0}; // Null"); + } + if(Use_BEL) + { + fprintf(Outfile,"%s\n","char BEL [2]={7,0}; // Bell"); + } + if(Use_BS) + { + fprintf(Outfile,"%s\n","char BS [2]={8,0}; // Back Space"); + } + if(Use_TAB) + { + fprintf(Outfile,"%s\n","char TAB [2]={9,0}; // Horz Tab"); + } + if(Use_LF) + { + fprintf(Outfile,"%s\n","char LF [2]={10,0}; // Line Feed"); + } + if(Use_VT) + { + fprintf(Outfile,"%s\n","char VT [2]={11,0}; // Vert Tab"); + } + if(Use_FF) + { + fprintf(Outfile,"%s\n","char FF [2]={12,0}; // Form Feed"); + } + if(Use_CR) + { + fprintf(Outfile,"%s\n","char CR [2]={13,0}; // Carr Rtn"); + } + if(Use_EOF) + { + fprintf(Outfile,"%s\n","char EF [2]={26,0}; // End-of-File"); + } + if(Use_ESC) + { + fprintf(Outfile,"%s\n","char ESC [2]={27,0}; // Escape"); + } + if(Use_SPC) + { + fprintf(Outfile,"%s\n","char SPC [2]={32,0}; // Space"); + } + if(Use_DQ) + { + fprintf(Outfile,"%s\n","char DQ [2]={34,0}; // Double-Quote"); + } + if(Use_DDQ) + { + fprintf(Outfile,"%s\n","char DDQ [3]={34,34,0}; // Double-Double-Quote"); + } + if(Use_Crlf) + { + fprintf(Outfile,"%s\n","char CRLF[3]={13,10,0}; // Carr Rtn & Line Feed"); + } + if(Use_Console) + { + fprintf(Outfile,"%s\n","int color_fg = 7;"); + fprintf(Outfile,"%s\n","int color_bg = 0;"); + } + if(Use_Lineinput) + { + fprintf(Outfile,"%s\n","char *AR_fgets_retval;"); + } + if(Use_Scan) + { + fprintf(Outfile,"%s\n","int ScanError;"); + } + if(Use_Inputbuffer==TRUE) + { + fprintf(Outfile,"%s\n","char InputBuffer[1048576];"); + } + if(Use_Findfirst||Use_Findnext) + { + fprintf(Outfile,"%s\n","FILE_FIND_DATA FindData;"); + } + if(Use_Gosub) + { + fprintf(Outfile,"%s\n","jmp_buf GosubStack[32];"); + fprintf(Outfile,"%s\n","int GosubNdx;"); + } + if(Use_Dynacall) + { + fprintf(Outfile,"%s\n","HINSTANCE BCX_DllStore[256];"); + } + } + if(GlobalVarCnt) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s%s\n","// ",BCX_STR_USR_VARS); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n",""); + } + for(i=1; i<=GlobalVarCnt; i+=1) + { + if(GlobalVars[i].VarEmitFlag) + { + continue; + } + if(str_cmp("",GlobalVars[i].VarDim)==0 && GlobalVars[i].VarCondLevel==0) + { + *P=0; + if(GlobalVars[i].VarPntr) + { + strcpy(P,stringx(GlobalVars[i].VarPntr,42)); + } + A=GlobalVars[i].VarType; + if(GlobalVars[i].VarSF) + { + strcpy(VarName, join(3,"(*",GlobalVars[i].VarName,")")); + } + else + { + strcpy(VarName,GlobalVars[i].VarName); + } + strcpy(Storage, join(2,VarStorage[GlobalVars[i].VarExtn],VarConst[GlobalVars[i].VarConstant])); + strcpy(VarDim,GlobalVars[i].VarDim); + PrintGlobal(A,i,Storage,P,VarName,VarDim); + } + } + for(i=1; i<=GlobalVarCnt; i+=1) + { + if(GlobalVars[i].VarEmitFlag) + { + continue; + } + if(str_cmp("",GlobalVars[i].VarDim)!=0 && GlobalVars[i].VarCondLevel==0) + { + if(instr_b(GlobalVars[i].VarDim,"{")==0) + { + *P=0; + if(GlobalVars[i].VarPntr) + { + strcpy(P,stringx(GlobalVars[i].VarPntr,42)); + } + A=GlobalVars[i].VarType; + if(GlobalVars[i].VarSF) + { + strcpy(VarName, join(4,"(*",GlobalVars[i].VarName,extract(GlobalVars[i].VarDim,"("),")")); + strcpy(VarDim,mid(GlobalVars[i].VarDim,instr_b(GlobalVars[i].VarDim,"("))); + } + else + { + strcpy(VarName,GlobalVars[i].VarName); + strcpy(VarDim,GlobalVars[i].VarDim); + } + strcpy(Storage, join(2,VarStorage[GlobalVars[i].VarExtn],VarConst[GlobalVars[i].VarConstant])); + PrintGlobal(A,i,Storage,P,VarName,VarDim); + } + } + } + char LastDef[2048]; + int LastLevel; + *LastDef=0; + LastLevel=1; + for(i=1; i<=GlobalVarCnt; i+=1) + { + if(GlobalVars[i].VarEmitFlag) + { + continue; + } + if(GlobalVars[i].VarCondLevel) + { + if(LastDef[0]==0) + { + strcpy(LastDef,GlobalVars[i].VarCondDef); + LastLevel=GlobalVars[i].VarCondLevel; + fprintf(Outfile,"%s\n",LastDef); + } + if(str_cmp(LastDef,GlobalVars[i].VarCondDef)!=0) + { + if(str_cmp(GlobalVars[i].VarCondDef,"#else")==0) + { + while(LastLevel>GlobalVars[i].VarCondLevel) + { + fprintf(Outfile,"%s\n","#endif"); + LastLevel--; + } + fprintf(Outfile,"%s\n","#else"); + strcpy(LastDef,GlobalVars[i].VarCondDef); + } + else + { + while(LastLevel>=GlobalVars[i].VarCondLevel) + { + fprintf(Outfile,"%s\n","#endif"); + LastLevel--; + } + strcpy(LastDef,GlobalVars[i].VarCondDef); + LastLevel=GlobalVars[i].VarCondLevel; + fprintf(Outfile,"%s\n",LastDef); + } + } + *P=0; + if(GlobalVars[i].VarPntr) + { + strcpy(P,stringx(GlobalVars[i].VarPntr,42)); + } + A=GlobalVars[i].VarType; + if(GlobalVars[i].VarSF) + { + strcpy(VarName, join(3,"(*",GlobalVars[i].VarName,")")); + } + else + { + strcpy(VarName,GlobalVars[i].VarName); + } + strcpy(VarDim,GlobalVars[i].VarDim); + strcpy(Storage, join(2,VarStorage[GlobalVars[i].VarExtn],VarConst[GlobalVars[i].VarConstant])); + PrintGlobal(A,i,Storage,P,VarName,VarDim); + } + } + if(*LastDef) + { + while(LastLevel) + { + fprintf(Outfile,"%s\n","#endif"); + LastLevel--; + } + } + fprintf(Outfile,"%s\n",""); + if(DllCnt) + { + int i; + char AR_DllName[2048]; + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// **********[ DLL Declarations ]**********"); + fprintf(Outfile,"%s\n",""); + for(i=0; i<=LoadLibsCnt-1; i+=1) + { + if(inchr(Loadlibs[i],"-")) + { + strcpy(AR_DllName,extract(Loadlibs[i],"-")); + } + else if(inchr(Loadlibs[i],".")) + { + strcpy(AR_DllName,extract(Loadlibs[i],".")); + } + fprintf(Outfile,"%s%s%s%s%s\n","void *H_",ucase(AR_DllName)," = dlopen(",enc(Loadlibs[i]),", RTLD_LAZY);"); + } + for(i=1; i<=DllCnt; i+=1) + { + fprintf(Outfile,"%s\n",DllDecl[i]); + } + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// ****************************************"); + fprintf(Outfile,"%s\n",""); + } + if((FP5=fopen(datFile,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",datFile); + exit(1); + } + if(lof(datFile)>0) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n","// User Data Statements"); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","char * DATA [] ="); + fprintf(Outfile,"%s\n","{"); + while(!EoF(FP5)) + { + Z[0]=0; + AR_fgets_retval=fgets(Z,1048576,FP5); + if(Z[strlen(Z)-1]==10)Z[strlen(Z)-1]=0; + fprintf(Outfile,"%s\n",Z); + } + fprintf(Outfile,"%s\n","};"); + } + if(FP5) + { + fclose(FP5); + FP5=NULL; + } + while(!EoF(FP1)) + { + Z[0]=0; + AR_fgets_retval=fgets(Z,1048576,FP1); + if(Z[strlen(Z)-1]==10)Z[strlen(Z)-1]=0; + fprintf(Outfile,"%s\n",Z); + } + CloseAll(); + remove (FileOut); + rename ("$t$e$m$p",FileOut); +} + + +int GetNumArgs (int Strt,int* NdxPos) +{ + int CountR=0; + int CountS=0; + int i; + int j=0; + int k=1; + for(i=Strt; i<=Ndx; i+=1) + { + if(str_cmp(Stk[i],"(")==0) + { + CountR++; + k++; + } + else if(str_cmp(Stk[i],")")==0) + { + CountR--; + k--; + if(k==0) + { + break; + } + } + else if(str_cmp(Stk[i],"[")==0) + { + CountS++; + } + else if(str_cmp(Stk[i],"]")==0) + { + CountS--; + } + else if(str_cmp(Stk[i],",")==0 && CountR==0&&CountS==0) + { + j++; + if(NdxPos) + { + *NdxPos=i; + } + } + } + return j; +} + + +void GetVarCode (VARCODE* varcode) +{ + char CB[2048]; + char PT[2048]; + char PTH[2048]; + char VAR[2048]; + int vn; + char RF[2048]; + if(varcode->Method==mt_Opts3) + { + strcat(varcode->Proto,varcode->Token); + if(str_cmp(varcode->Token,",")==0) + { + strcat(varcode->Header,varcode->Token); + } + return; + } + if(varcode->Method==mt_FuncSubx1) + { + strcpy(varcode->Proto, join(3,varcode->Proto,varcode->AsToken,"(*)(")); + strcpy(varcode->Header, join(5,varcode->Header,varcode->AsToken," (*",varcode->Token,")(")); + return; + } + if(varcode->Method==mt_FuncSubx2) + { + strcat(varcode->Proto,varcode->AsToken); + strcpy(varcode->Header, join(4,varcode->Header,varcode->AsToken," ",varcode->Token)); + return; + } + if(IsCallBack) + { + strcpy(CB,"CALLBACK "); + } + else + { + *CB=0; + } + if(inchr(varcode->Token,"*")||inchr(varcode->AsToken,"*")||varcode->IsPtrFlag) + { + RemoveAll(varcode->Token,"*"); + RemoveAll(varcode->AsToken,"*"); + strcpy(PT, join(2,stringx(varcode->IsPtrFlag,42)," ")); + strcpy(PTH,PT); + } + else + { + strcpy(PTH," "); + *PT=0; + } + if(inchr(varcode->Token,"&")) + { + strcpy(RF," &"); + } + else + { + *RF=0; + } + vn=varcode->VarNo; + strcpy(VAR,GetVarTypeName(vn)); + for(;;) + { + if(vn==vt_STRVAR) + { + for(;;) + { + if(varcode->Method==mt_ProcessSetCommand) + { + strcpy(varcode->StaticOut, join(2,"static char ",Clean(varcode->Token))); + break; + } + if(varcode->Method==mt_FuncSubDecC_Dec) + { + strcpy(varcode->Functype, join(2,"char * ",CB)); + break; + } + if(varcode->Method==mt_FuncSubDecC_Dec2) + { + if(!inchr(varcode->Token,"[")) + { + strcpy(varcode->Header, join(4,varcode->Header,"char *",Clean(varcode->Token),", ")); + strcat(varcode->Proto,"char *, "); + } + else + { + strcpy(varcode->Header, join(4,varcode->Header,"char ",RemoveStr(Clean(varcode->Token),"*"),", ")); + strcat(varcode->Proto,"char [][65535], "); + } + break; + } + if(varcode->Method==mt_Opts) + { + strcpy(varcode->Functype,"char *"); + break; + } + if(varcode->Method==mt_Opts2) + { + strcpy(varcode->Header, join(3,varcode->Header,"char * ",Clean(varcode->Token))); + strcat(varcode->Proto,"char* "); + break; + } + if(varcode->Method==mt_OverLoad) + { + strcpy(varcode->Functype,"char *"); + break; + } + if(varcode->Method==mt_OverLoad2) + { + strcpy(varcode->Header, join(4,varcode->Header,"char *",Clean(varcode->Token),", ")); + } + break; + } + break; + } + if(vn==vt_BOOL||vn==vt_BYTE||vn==vt_COLORREF||vn==vt_DOUBLE||vn==vt_DWORD||vn==vt_FARPROC||vn==vt_HDC||vn==vt_HANDLE||vn==vt_HINSTANCE||vn==vt_HWND||vn==vt_INTEGER||vn==vt_LONG||vn==vt_LPBYTE||vn==vt_LRESULT||vn==vt_SHORT||vn==vt_SINGLE||vn==vt_UINT||vn==vt_ULONG||vn==vt_USHORT||vn==vt_VARIANT||vn==vt_VOID||vn==vt_LDOUBLE) + { + for(;;) + { + if(varcode->Method==mt_ProcessSetCommand) + { + strcpy(varcode->StaticOut, join(4,"static ",VAR," ",Clean(varcode->Token))); + break; + } + if(varcode->Method==mt_FuncSubDecC_Dec) + { + strcpy(varcode->Functype, join(3,VAR,PTH,CB)); + break; + } + if(varcode->Method==mt_FuncSubDecC_Dec2) + { + strcpy(varcode->Header, join(5,varcode->Header,VAR,PTH,Clean(varcode->Token),", ")); + strcpy(varcode->Proto, join(5,varcode->Proto,VAR,RF,PT,", ")); + break; + } + if(varcode->Method==mt_Opts) + { + strcpy(varcode->Functype, join(2,VAR,PTH)); + break; + } + if(varcode->Method==mt_Opts2) + { + strcpy(varcode->Header, join(4,varcode->Header,VAR,PTH,Clean(varcode->Token))); + strcpy(varcode->Proto, join(4,varcode->Proto,VAR,RF,PT)); + break; + } + if(varcode->Method==mt_OverLoad) + { + strcpy(varcode->Functype, join(2,VAR," ")); + break; + } + if(varcode->Method==mt_OverLoad2) + { + strcpy(varcode->Header, join(5,varcode->Header,VAR,PTH,Clean(varcode->Token),", ")); + } + break; + } + break; + } + if(vn==vt_FILEPTR||vn==vt_CHAR) + { + for(;;) + { + if(varcode->Method==mt_FuncSubDecC_Dec) + { + strcpy(varcode->Functype, join(3,VAR,PTH,CB)); + break; + } + if(varcode->Method==mt_FuncSubDecC_Dec2) + { + strcpy(varcode->Header, join(5,varcode->Header,VAR,PTH,Clean(varcode->Token),", ")); + strcpy(varcode->Proto, join(4,varcode->Proto,VAR,PT,", ")); + break; + } + if(varcode->Method==mt_Opts) + { + strcpy(varcode->Functype, join(2,VAR,PTH)); + break; + } + if(varcode->Method==mt_Opts2) + { + strcpy(varcode->Header, join(4,varcode->Header,VAR,PTH,Clean(varcode->Token))); + strcpy(varcode->Proto, join(3,varcode->Proto,VAR,PT)); + break; + } + if(varcode->Method==mt_OverLoad) + { + strcpy(varcode->Functype, join(2,VAR," ")); + break; + } + if(varcode->Method==mt_OverLoad2) + { + strcpy(varcode->Header, join(5,varcode->Header,VAR,PTH,Clean(varcode->Token),", ")); + } + break; + } + break; + } + if(vn==vt_UDT||vn==vt_STRUCT||vn==vt_UNION) + { + for(;;) + { + if(varcode->Method==mt_ProcessSetCommand) + { + if(vn==vt_UNION) + { + strcpy(varcode->StaticOut, join(2,"static union ",Clean(varcode->Token))); + } + else + { + strcpy(varcode->StaticOut, join(3,"static struct _",Clean(varcode->Token)," ")); + } + break; + } + if(varcode->Method==mt_FuncSubDecC_Dec) + { + strcpy(varcode->Functype, join(3,varcode->AsToken,PTH,CB)); + break; + } + if(varcode->Method==mt_FuncSubDecC_Dec2) + { + strcpy(varcode->Header, join(5,varcode->Header,varcode->AsToken,PTH,Clean(varcode->Token),", ")); + strcpy(varcode->Proto, join(5,varcode->Proto,varcode->AsToken,RF,PT,", ")); + break; + } + if(varcode->Method==mt_Opts) + { + strcpy(varcode->Functype, join(2,varcode->AsToken,PTH)); + break; + } + if(varcode->Method==mt_Opts2) + { + strcpy(varcode->Header, join(5,varcode->Header,Clean(varcode->AsToken),PTH," ",Clean(varcode->Token))); + strcpy(varcode->Proto, join(4,varcode->Proto,Clean(varcode->AsToken),RF,PT)); + break; + } + if(varcode->Method==mt_OverLoad) + { + strcpy(varcode->Functype, join(2,VAR," ")); + break; + } + if(varcode->Method==mt_OverLoad2) + { + strcpy(varcode->Header, join(5,varcode->Header,varcode->AsToken,PTH,Clean(varcode->Token),", ")); + } + break; + } + break; + } + // case else + { + for(;;) + { + if(varcode->Method==mt_FuncSubDecC_Dec) + { + strcpy(varcode->Functype, join(3,varcode->AsToken,PTH,CB)); + break; + } + if(varcode->Method==mt_FuncSubDecC_Dec2) + { + strcpy(varcode->Header, join(5,varcode->Header,varcode->AsToken,PTH,Clean(varcode->Token),", ")); + strcpy(varcode->Proto, join(5,varcode->Proto,varcode->AsToken,RF,PT,", ")); + break; + } + if(varcode->Method==mt_Opts) + { + strcpy(varcode->Functype, join(2,varcode->AsToken,PTH)); + break; + } + if(varcode->Method==mt_Opts2) + { + strcpy(varcode->Header, join(4,varcode->Header,Clean(varcode->AsToken)," ",Clean(varcode->Token))); + strcat(varcode->Proto,Clean(varcode->AsToken)); + } + break; + } + } + break; + } +} + + +void AddProtos (void) +{ + char SaveMain[2048]; + char ZZ[2048]; + int A; + *SaveMain=0; + if((FP1=fopen(FileOut,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",FileOut); + exit(1); + } + if((Outfile=fopen("$t$e$m$p","w"))==0) + { + fprintf(stderr,"Can't open file %s\n","$t$e$m$p"); + exit(1); + } + while(!EoF(FP1)) + { + ZZ[0]=0; + AR_fgets_retval=fgets(ZZ,1048576,FP1); + if(ZZ[strlen(ZZ)-1]==10)ZZ[strlen(ZZ)-1]=0; + if(instr_b(ZZ,"int main")) + { + strcpy(SaveMain,ZZ); + break; + } + fprintf(Outfile,"%s\n",ZZ); + } + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s%s\n","// ",BCX_STR_STD_MACROS); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n",""); + if(Use_BcxSplitPath) + { + fprintf(Outfile,"%s\n","#define FDRV 2"); + fprintf(Outfile,"%s\n","#define FPATH 4"); + fprintf(Outfile,"%s\n","#define FNAME 8"); + fprintf(Outfile,"%s\n","#define FEXT 16"); + } + if(Use_Cbool) + { + fprintf(Outfile,"%s\n","#define CBOOL(A)(A!=0)?1:0"); + } + if(Use_Isptr) + { + fprintf(Outfile,"%s\n","#define IsPtr(a)((DWORD)a)"); + } + if(Use_Band) + { + fprintf(Outfile,"%s\n","#define BAND &"); + } + if(Use_Bor) + { + fprintf(Outfile,"%s\n","#define BOR |"); + } + if(Use_Bnot) + { + fprintf(Outfile,"%s\n","#define BNOT ~(int)"); + } + if(Use_Ubound) + { + fprintf(Outfile,"%s\n","#define ubound(T)(sizeof((T))/sizeof((T[0]))-1)"); + } + if(Use_Clear) + { + fprintf(Outfile,"%s\n","#define Clear(arg)memset(&arg,0,sizeof(arg))"); + } + if(Use_Imod) + { + fprintf(Outfile,"%s\n","#define imod(a,b)((a)%(b))"); + } + if(Use_Get) + { + fprintf(Outfile,"%s\n","#define GET(A,B,C) F_GetVal=fread(B,1,C,A)"); + AddGlobal("F_GetVal",vt_INTEGER,0,"",0,0,0,0); + } + if(Use_Put) + { + fprintf(Outfile,"%s\n","#define PUT(A,B,C) F_PutVal=fwrite(B,1,C,A)"); + AddGlobal("F_PutVal",vt_INTEGER,0,"",0,0,0,0); + } + if(Use_Strptr) + { + fprintf(Outfile,"%s\n","#define STRPTR(A)((char*)&(A))"); + } + if(Use_Val) + { + fprintf(Outfile,"%s\n","#define VAL(a)(double)atof(a)"); + } + if(Use_Vall) + { + fprintf(Outfile,"%s\n","#define VALL(a) (long double)strtold(a,(char**)NULL)"); + } + if(Use_Fint) + { + fprintf(Outfile,"%s\n","#define FINT(a)floor(a)"); + } + if(Use_Frac) + { + fprintf(Outfile,"%s\n","#define FRAC(a)(double)(a-FIX(a))"); + Use_Fix=TRUE; + } + if(Use_Fracl) + { + fprintf(Outfile,"%s\n","#define FRACL(a)(long double)(a-FIX(a))"); + Use_Fix=TRUE; + } + if(Use_Fix) + { + fprintf(Outfile,"%s\n","#define FIX(a)(int)((a))"); + } + if(Use_Csng) + { + fprintf(Outfile,"%s\n","#define CSNG(a)((float)(a))"); + } + if(Use_Cdbl) + { + fprintf(Outfile,"%s\n","#define CDBL(a)((double)(a))"); + } + if(Use_Cldbl) + { + fprintf(Outfile,"%s\n","#define CLDBL(a)((long double)(a))"); + } + if(Use_Threads) + { + fprintf(Outfile,"%s\n","#define BCX_THREAD(fn,arg) ({ pthread_t tid; pthread_create(&tid, NULL, (void*(*)(void*))fn, arg); tid;})"); + fprintf(Outfile,"%s\n","#define BCX_THREADWAIT(a) pthread_join(a, NULL)"); + fprintf(Outfile,"%s\n","#define BCX_INITLOCK(a) pthread_mutex_init(a, NULL)"); + fprintf(Outfile,"%s\n","#define BCX_THREADLOCK(a) pthread_mutex_lock (a)"); + fprintf(Outfile,"%s\n","#define BCX_THREADUNLOCK(a) pthread_mutex_unlock (a)"); + fprintf(Outfile,"%s\n","#define BCX_THREADKILL(t) pthread_cancel(t)"); + fprintf(Outfile,"%s\n","#define BCX_THREADEND pthread_exit(0)"); + } + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s%s\n","// ",BCX_STR_STD_PROTOS); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n",""); + if(NoRT==FALSE) + { + if(Use_Clng) + { + fprintf(Outfile,"%s\n","long CLNG(double);"); + } + if(Use_Cint) + { + fprintf(Outfile,"%s\n","int Cint(double);"); + } + if(Use_StartupCode) + { + fprintf(Outfile,"%s\n","int BCX_StartupCode_(void);"); + } + if(Use_ExitCode) + { + fprintf(Outfile,"%s\n","int BCX_ExitCode_(void);"); + } + if(Use_Str_Cmp) + { + fprintf(Outfile,"%s\n","int str_cmp(char*, char*);"); + } + if(Use_Eof) + { + fprintf(Outfile,"%s\n","int EoF (FILE*);"); + } + if(Use_CopyFile) + { + fprintf(Outfile,"%s\n","void CopyFile (char *,char *,int=FALSE);"); + } + if(Use_QBColor) + { + fprintf(Outfile,"%s\n","int qbcolor (int);"); + } + if(Use_Cls) + { + fprintf(Outfile,"%s\n","void cls(void);"); + } + if(Use_Color) + { + fprintf(Outfile,"%s\n","void color (int,int);"); + } + if(Use_Locate) + { + fprintf(Outfile,"%s\n","void locate (int,int,int=1,int=12);"); + } + if(Use_Run) + { + fprintf(Outfile,"%s\n","int Run (char*, int =1, int =0);"); + } + if(Use_Randomize) + { + fprintf(Outfile,"%s\n","void randomize (unsigned int);"); + } + if(Use_Midstr) + { + fprintf(Outfile,"%s\n","void midstr (char*, int, int, char *);"); + } + if(Use_Swap) + { + fprintf(Outfile,"%s\n","void swap (UCHAR*,UCHAR*,int);"); + } + if(UseFlag) + { + fprintf(Outfile,"%s\n","char* BCX_TmpStr(size_t);"); + } + if(Use_sziif) + { + fprintf(Outfile,"%s\n","char* sziif (bool,char*,char*);"); + } + if(Use_Using) + { + fprintf(Outfile,"%s\n","char* Using (char*,double);"); + } + if(Use_TempFileName) + { + fprintf(Outfile,"%s\n","char* TempFileName (char*,char*);"); + } + if(Use_AppExePath) + { + fprintf(Outfile,"%s\n","char* AppExePath (void);"); + } + if(Use_AppExeName) + { + fprintf(Outfile,"%s\n","char* AppExeName (void);"); + } + if(Use_Lcase) + { + fprintf(Outfile,"%s\n","char* lcase (char*);"); + } + if(Use_Ucase) + { + fprintf(Outfile,"%s\n","char* ucase (char*);"); + } + if(Use_Mid) + { + fprintf(Outfile,"%s\n","char* mid (char*, int, int=-1);"); + } + if(Use_Ltrim) + { + fprintf(Outfile,"%s\n","char* ltrim (char*,char=32);"); + } + if(Use_Rtrim) + { + fprintf(Outfile,"%s\n","char* rtrim (char*,char=32);"); + } + if(Use_Trim) + { + fprintf(Outfile,"%s\n","char* trim (char*);"); + } + if(Use_Strim) + { + fprintf(Outfile,"%s\n","char* strim (char*);"); + } + if(Use_Left) + { + fprintf(Outfile,"%s\n","char* left (char*,int);"); + } + if(Use_Right) + { + fprintf(Outfile,"%s\n","char* right (char*,int);"); + } + if(Use_Rpad) + { + fprintf(Outfile,"%s\n","char* rpad (char*,int,int=32);"); + } + if(Use_Lpad) + { + fprintf(Outfile,"%s\n","char* lpad (char*,int,int=32);"); + } + if(Use_String) + { + fprintf(Outfile,"%s\n","char* stringx (int,int);"); + } + if(Use_Repeat) + { + fprintf(Outfile,"%s\n","char* repeat (int,char*);"); + } + if(Use_Extract) + { + fprintf(Outfile,"%s\n","char* extract (char*,char*);"); + } + if(Use_Remain) + { + fprintf(Outfile,"%s\n","char* remain (char*,char*);"); + } + if(Use_Reverse) + { + fprintf(Outfile,"%s\n","char* reverse (char*);"); + } + if(Use_Command) + { + fprintf(Outfile,"%s\n","char* command (int=-1);"); + } + if(Use_Mcase) + { + fprintf(Outfile,"%s\n","char* mcase (char*);"); + } + if(Use_Replace) + { + fprintf(Outfile,"%s\n","char* replace (char*,char*,char*);"); + } + if(Use_iReplace) + { + fprintf(Outfile,"%s\n","char* iReplace (char*,char*,char*);"); + } + if(Use_Shell) + { + fprintf(Outfile,"%s\n","void Shell (char *);"); + } + if(Use_Space) + { + fprintf(Outfile,"%s\n","char* space (int a);"); + } + if(Use_Str) + { + fprintf(Outfile,"%s\n","char* str (double);"); + } + if(Use_Strl) + { + fprintf(Outfile,"%s\n","char* strl (long double);"); + } + if(Use_Findfirst) + { + fprintf(Outfile,"%s\n","char* findfirst (char*, FILE_FIND_DATA*);"); + } + if(Use_Findnext) + { + fprintf(Outfile,"%s\n","char* findnext (FILE_FIND_DATA*);"); + } + if(Use_Curdir) + { + fprintf(Outfile,"%s\n","char* curdir (void);"); + } + if(Use_Sysdir) + { + fprintf(Outfile,"%s\n","char* sysdir (void);"); + } + if(Use_Tempdir) + { + fprintf(Outfile,"%s\n","char* tempdir (void);"); + } + if(Use_Environ) + { + fprintf(Outfile,"%s\n","char* Environ (char*);"); + } + if(Use_Boolstr) + { + fprintf(Outfile,"%s\n","char* BoolStr (int);"); + } + if(Use_Hex) + { + fprintf(Outfile,"%s\n","char* hex (int);"); + } + if(Use_Bin) + { + fprintf(Outfile,"%s\n","char* Bin (int);"); + } + if(Use_Oct) + { + fprintf(Outfile,"%s\n","char* oct (int);"); + } + if(Use_Now) + { + fprintf(Outfile,"%s\n","char* now (void);"); + } + if(Use_SearchPath) + { + fprintf(Outfile,"%s\n","char* SEARCHPATH (char *);"); + } + if(Use_StrUpLow) + { + fprintf(Outfile,"%s\n","char* _strupr_(char *);"); + fprintf(Outfile,"%s\n","char* _strlwr_(char *);"); + } + if(Use_BcxSplitPath) + { + fprintf(Outfile,"%s\n","char* BcxSplitPath (char *, int);"); + fprintf(Outfile,"%s\n","void _splitpath_(const char* path, char* drv, char* dir, char* name, char* ext);"); + } + if(Use_Strtoken) + { + fprintf(Outfile,"%s\n","char* StrToken (char*,char*,int);"); + } + if(Use_FileLocked) + { + fprintf(Outfile,"%s\n","int FileLocked (char*);"); + } + if(Use_FillArray) + { + fprintf(Outfile,"%s\n","int fillarray (char *, int, int, void *);"); + } + if(Use_Remove) + { + fprintf(Outfile,"%s\n","char* RemoveStr (char*,char*);"); + } + if(Use_IRemove) + { + fprintf(Outfile,"%s\n","char* IRemoveStr (char*,char*);"); + } + if(Use_Time) + { + fprintf(Outfile,"%s\n","char* timef (int i=0);"); + } + if(Use_Join) + { + fprintf(Outfile,"%s\n","char* join (int, ... );"); + } + if(Use_Enclose) + { + fprintf(Outfile,"%s\n","char* enc (char*, int=0, int=0);"); + } + if(Use_Chr) + { + fprintf(Outfile,"%s","char* chr"); + fprintf(Outfile,"%s\n","(int,int=0,int=0,int=0,int=0,int=0,int=0,int=0,int=0,int=0);"); + } + if(Use_VChr) + { + fprintf(Outfile,"%s\n","char* vchr (int,...);"); + } + if(Use_Freefile) + { + fprintf(Outfile,"%s\n","FILE* FreeFile (void);"); + } + if(Use_PeekStr) + { + fprintf(Outfile,"%s\n","char* peekstr (LPVOID,int);"); + } + if(Use_Asc) + { + fprintf(Outfile,"%s\n","int asc (char*,int=0);"); + } + if(Use_Instrrev) + { + fprintf(Outfile,"%s\n","int InstrRev (char*,char*,int=0,int=0);"); + } + if(Use_Instr) + { + fprintf(Outfile,"%s\n","int instr_b(char*,char*,int=0,int=0);"); + } + if(UseLCaseTbl) + { + fprintf(Outfile,"%s\n","char *MakeLCaseTbl(void);"); + } + if(Use_Stristr) + { + fprintf(Outfile,"%s\n","char *_stristr_(char*,char*);"); + } + if(Use_StrStr) + { + fprintf(Outfile,"%s\n","char *_strstr_(char*,char*);"); + } + if(Use_Verify) + { + fprintf(Outfile,"%s\n","int Verify (char *, char *);"); + fprintf(Outfile,"%s\n","int VerifyInstr(char*,char*,int=0);"); + } + if(Use_Retain) + { + fprintf(Outfile,"%s\n","char* Retain (char*,char *);"); + } + if(Use_LoadFile) + { + fprintf(Outfile,"%s\n","char* LoadFile (char*);"); + } + if(Use_Inchr) + { + fprintf(Outfile,"%s\n","int inchr (char*,char*);"); + } + if(Use_Idxqsort) + { + fprintf(Outfile,"%s\n","int IdxCompare (const void *,const void *);"); + } + if(Use_IdxqsortSt) + { + fprintf(Outfile,"%s\n","int IdxCompareSt (const void *,const void *);"); + } + if(Use_PtrqsortSt) + { + fprintf(Outfile,"%s\n","int PtrCompareSt (const void *,const void *);"); + } + if(Use_Strqsorta) + { + fprintf(Outfile,"%s\n","int StrCompareA (const void *,const void *);"); + } + if(Use_Strqsortd) + { + fprintf(Outfile,"%s\n","int StrCompareD (const void *,const void *);"); + } + if(Use_DynStrqsorta) + { + fprintf(Outfile,"%s\n","int DynStrCompareA (const void *,const void *);"); + } + if(Use_DynStrqsortd) + { + fprintf(Outfile,"%s\n","int DynStrCompareD (const void *,const void *);"); + } + if(Use_Numqsortaint) + { + fprintf(Outfile,"%s\n","int NumCompareAint (const void *,const void *);"); + } + if(Use_Numqsortdint) + { + fprintf(Outfile,"%s\n","int NumCompareDint (const void *,const void *);"); + } + if(Use_Numqsortafloat) + { + fprintf(Outfile,"%s\n","int NumCompareAfloat (const void *,const void *);"); + } + if(Use_Numqsortdfloat) + { + fprintf(Outfile,"%s\n","int NumCompareDfloat (const void *,const void *);"); + } + if(Use_Numqsortadouble) + { + fprintf(Outfile,"%s\n","int NumCompareAdouble (const void *,const void *);"); + } + if(Use_Numqsortddouble) + { + fprintf(Outfile,"%s\n","int NumCompareDdouble (const void *,const void *);"); + } + if(Use_Like) + { + fprintf(Outfile,"%s\n","int like (char*,char*);"); + } + if(Use_Tally) + { + fprintf(Outfile,"%s\n","int tally (char*,char*,int=0);"); + } + if(Use_Inkey) + { + fprintf(Outfile,"%s\n","char* inkey (void);"); + } + if(Use_InkeyD) + { + fprintf(Outfile,"%s\n","int inkeyd (void);"); + } + if(Use_Instat) + { + fprintf(Outfile,"%s\n","int kbhit(void);"); + } + if(Use_GetCh) + { + fprintf(Outfile,"%s\n","int _getch_(int);"); + } + if(Use_Bin2dec) + { + fprintf(Outfile,"%s\n","int Bin2Dec (char*);"); + } + if(Use_Hex2Dec) + { + fprintf(Outfile,"%s\n","int Hex2Dec (char*);"); + } + if(Use_Download) + { + fprintf(Outfile,"%s\n","int Download (char*,char*);"); + } + if(Use_Embed) + { + fprintf(Outfile,"%s\n","char* GetResource (int* );"); + } + if(Use_Exist) + { + if(Use_Osx) + { + fprintf(Outfile,"%s\n","bool Exist (char*);"); + } + else + { + fprintf(Outfile,"%s\n","BOOL Exist (char*);"); + } + } + if(Use_Ins) + { + fprintf(Outfile,"%s\n","char* ins (char *S, int i, char *a);"); + } + if(Use_Del) + { + fprintf(Outfile,"%s\n","char* del (char*,int,int);"); + } + if(Use_Pause) + { + fprintf(Outfile,"%s\n","void Pause (void);"); + } + if(Use_Keypress) + { + fprintf(Outfile,"%s\n","int keypress (void);"); + } + if(Use_Lof) + { + fprintf(Outfile,"%s\n","DWORD lof (char*);"); + } + if(Use_Sgn) + { + fprintf(Outfile,"%s\n","double sgn (double);"); + } + if(Use_Round) + { + fprintf(Outfile,"%s\n","double Round (double,int);"); + } + if(Use_Rnd) + { + fprintf(Outfile,"%s\n","float rnd (void);"); + } + if(Use_Exp) + { + fprintf(Outfile,"%s\n","double Exp (double);"); + } + if(Use_Min) + { + fprintf(Outfile,"%s\n","double _MIN_ (double,double);"); + } + if(Use_Max) + { + fprintf(Outfile,"%s\n","double _MAX_ (double,double);"); + } + if(Use_Timer) + { + fprintf(Outfile,"%s\n","float timer (void);"); + } + if(Use_Iif) + { + fprintf(Outfile,"%s\n","double iif (bool,double,double);"); + } + if(Use_Loc) + { + fprintf(Outfile,"%s\n","int loc (FILE *fp, int fplen);"); + } + if(Use_Rec) + { + fprintf(Outfile,"%s\n","int rec (FILE *fp, int fplen);"); + } + if(Use_RecCount) + { + fprintf(Outfile,"%s\n","int reccount (FILE *fp, int fplen);"); + } + if(Use_Scan) + { + fprintf(Outfile,"%s\n","int scan (char *input, char *format, ... );"); + } + if(Use_Split) + { + fprintf(Outfile,"%s\n","int Split (char [][65535], char*, char*, int=0);"); + } + if(Use_DSplit) + { + fprintf(Outfile,"%s\n","int DSplit (PCHAR *, char*, char*, int=0);"); + } + if(Use_SysStr) + { + fprintf(Outfile,"%s\n","BSTR SysStr (char * szIn, int=0, int=0);"); + } + if(Use_WideToAnsi) + { + fprintf(Outfile,"%s\n","char* WideToAnsi (wchar_t *, UINT=0, DWORD=0);"); + } + if(Use_AnsiToWide) + { + fprintf(Outfile,"%s\n","wchar_t* AnsiToWide (char*,UINT=0,DWORD=0);"); + } + if(Use_Cvi) + { + fprintf(Outfile,"%s\n","short CVI (char*);"); + } + if(Use_Mki) + { + fprintf(Outfile,"%s\n","char* MKI (short);"); + } + if(Use_Cvl) + { + fprintf(Outfile,"%s\n","long CVL (char*);"); + } + if(Use_Mkl) + { + fprintf(Outfile,"%s\n","char* MKL (int);"); + } + if(Use_Cvs) + { + fprintf(Outfile,"%s\n","float CVS (char*);"); + } + if(Use_Mks) + { + fprintf(Outfile,"%s\n","char* MKS (float);"); + } + if(Use_Cvd) + { + fprintf(Outfile,"%s\n","double CVD (char*);"); + } + if(Use_Cvld) + { + fprintf(Outfile,"%s\n","long double CVLD (char*);"); + } + if(Use_Mkd) + { + fprintf(Outfile,"%s\n","char* MKD (double);"); + } + if(Use_Mkld) + { + fprintf(Outfile,"%s\n","char* MKLD (long double);"); + } + if(Use_OSVersion) + { + fprintf(Outfile,"%s\n","int OSVersion (void);"); + } + if(Use_Dynacall) + { + fprintf(Outfile,"%s\n","HINSTANCE BCX_LoadDll(char *);"); + fprintf(Outfile,"%s\n","void BCX_UnloadDll(void);"); + fprintf(Outfile,"%s\n","typedef int (CALLBACK *DYNACALL1)(void);"); + fprintf(Outfile,"%s\n","int BCX_DynaCall(char *, char *, int, ...);"); + } + if(Use_DynamicA) + { + fprintf(Outfile,"%s\n","void* CreateArr (void*,int,int,int,...);"); + fprintf(Outfile,"%s\n","void* CreateArr_internal(void*, int, int, int, va_list);"); + fprintf(Outfile,"%s\n","void DestroyArr (void**,int,int);"); + } + if(Use_ContainedIn) + { + fprintf(Outfile,"%s\n","int containedin(char * ,char **,int=0);"); + } + if(Use_FindInType) + { + fprintf(Outfile,"%s\n","int FindInType(char *,char *,int,int,int,int=0,int* =0);"); + } + if(Use_SingleFile==FALSE) + { + if((fpHFile=fopen(HFile,"w"))==0) + { + fprintf(stderr,"Can't open file %s\n",HFile); + exit(1); + } + } + /*****2010-11-24ChangeTOemitwxAppCLASSDefinitionFORWXCONSOLEApps-AIR*****/; + if(Use_Wx) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s%s%s\n","class ",BcxSplitPath(FileIn,FNAME),": public wxApp {"); + fprintf(Outfile,"%s\n"," public:"); + fprintf(Outfile,"%s\n"," virtual bool OnInit();"); + fprintf(Outfile,"%s\n","};"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s%s%s\n","IMPLEMENT_APP(",BcxSplitPath(FileIn,FNAME),")"); + fprintf(Outfile,"%s\n",""); + } + if(Use_Socket) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","sockaddr_in sock_addr (char* ,int=80);"); + fprintf(Outfile,"%s\n","int connect_socket (sockaddr_in);"); + fprintf(Outfile,"%s\n","int BcxSocket (char* ,int=80);"); + fprintf(Outfile,"%s\n","int BcxSocketSend (int, char *);"); + fprintf(Outfile,"%s\n","int BcxSocketRead (int, char *);"); + fprintf(Outfile,"%s\n","void BcxSocketClose(int);"); + fprintf(Outfile,"%s\n",""); + } + if(Use_RegEx) + { + fprintf(Outfile,"%s\n","bool regmatch (char *, char *, REGEX* );"); + } + } + if(ProtoCnt) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s%s\n","// ",BCX_STR_USR_PROTOS); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n",""); + char LastDef[2048]; + int LastLevel; + *LastDef=0; + LastLevel=1; + for(A=1; A<=ProtoCnt; A+=1) + { + if(LastDef[0]==0) + { + strcpy(LastDef,ProtoType[A].Condition); + LastLevel=ProtoType[A].CondLevel; + if(Use_SingleFile==FALSE) + { + if(LastDef[0]>0) + { + fprintf(fpHFile,"%s\n",LastDef); + } + } + if(LastDef[0]>0) + { + fprintf(Outfile,"%s\n",LastDef); + } + } + if(str_cmp(LastDef,ProtoType[A].Condition)!=0) + { + if(str_cmp(ProtoType[A].Condition,"#else")==0) + { + while(LastLevel>ProtoType[A].CondLevel) + { + if(Use_SingleFile==FALSE) + { + fprintf(fpHFile,"%s\n","#endif"); + } + fprintf(Outfile,"%s\n","#endif"); + LastLevel--; + } + if(Use_SingleFile==FALSE) + { + fprintf(fpHFile,"%s\n","#else"); + } + fprintf(Outfile,"%s\n","#else"); + strcpy(LastDef,ProtoType[A].Condition); + LastLevel=ProtoType[A].CondLevel; + } + else + { + while(LastLevel>ProtoType[A].CondLevel) + { + if(Use_SingleFile==FALSE) + { + fprintf(fpHFile,"%s\n","#endif"); + } + fprintf(Outfile,"%s\n","#endif"); + LastLevel--; + } + strcpy(LastDef,ProtoType[A].Condition); + LastLevel=ProtoType[A].CondLevel; + if(Use_SingleFile==FALSE) + { + if(LastDef[0]>0) + { + fprintf(fpHFile,"%s\n",LastDef); + } + } + if(LastDef[0]>0) + { + fprintf(Outfile,"%s\n",LastDef); + } + } + } + if(UseStdCall&&UseCpp) + { + if(str_cmp(left(ProtoType[A].Prototype,9),"C_EXPORT ")==0) + { + EmitExportDef(ProtoType[A].Prototype); + } + } + strcpy(T,extract(ProtoType[A].Prototype,SPC)); + strcpy(T, join(2,rpad(T,7),SPC)); + strcpy(ProtoType[A].Prototype, join(2,T,remain(ProtoType[A].Prototype,SPC))); + if(Use_SingleFile==FALSE) + { + fprintf(fpHFile,"%s\n",ProtoType[A].Prototype); + } + if(UseCpp==FALSE&&!instr_b(ProtoType[A].Prototype,"::")) + { + fprintf(Outfile,"%s\n",ProtoType[A].Prototype); + } + } + if(*LastDef) + { + while(LastLevel>0) + { + if(Use_SingleFile==FALSE) + { + fprintf(fpHFile,"%s\n","#endif"); + } + fprintf(Outfile,"%s\n","#endif"); + LastLevel--; + } + } + } + fprintf(Outfile,"%s\n",""); + char P[2048]; + int i; + char VarName[2048]; + char VarDim[2048]; + char Storage[2048]; + char VAR[2048]; + if(GlobalVarCnt>0) + { + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n","// User Global Initialized Arrays"); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n",""); + for(i=1; i<=GlobalVarCnt; i+=1) + { + if(GlobalVars[i].VarEmitFlag) + { + continue; + } + if(str_cmp("",GlobalVars[i].VarDim)!=0 && GlobalVars[i].VarCondLevel==0) + { + if(instr_b(GlobalVars[i].VarDim,"{")) + { + *P=0; + if(GlobalVars[i].VarPntr) + { + strcpy(P,stringx(GlobalVars[i].VarPntr,42)); + } + A=GlobalVars[i].VarType; + if(GlobalVars[i].VarSF) + { + strcpy(VarName, join(4,"(*",GlobalVars[i].VarName,extract(GlobalVars[i].VarDim,"("),")")); + strcpy(VarDim,mid(GlobalVars[i].VarDim,instr_b(GlobalVars[i].VarDim,"("))); + } + else + { + strcpy(VarName,GlobalVars[i].VarName); + strcpy(VarDim,GlobalVars[i].VarDim); + } + strcpy(Storage, join(2,VarStorage[GlobalVars[i].VarExtn],VarConst[GlobalVars[i].VarConstant])); + for(;;) + { + if(A==vt_STRVAR) + { + fprintf(Outfile,"%s%s%s%s%s\n",Storage,"char ",VarName,VarDim,";"); + break; + } + if(A==vt_FILEPTR) + { + strcpy(GlobalVars[i].VarName,RemoveStr(GlobalVars[i].VarName,"@")); + fprintf(Outfile,"%s%s%s%s%s\n",Storage,"FILE *",VarName,VarDim,";"); + break; + } + if(A==vt_BOOL) + { + fprintf(Outfile,"%s%s%s%s%s\n",Storage,"bool ",VarName,VarDim,";"); + break; + } + if(A==vt_UDT||A==vt_STRUCT||A==vt_UNION) + { + strcpy(VAR,TypeDefs[GlobalVars[i].VarDef].VarName); + strcpy(VAR,rpad(VAR,7)); + fprintf(Outfile,"%s%s%s%s%s%s%s\n",Storage,VAR," ",P,VarName,VarDim,";"); + break; + } + if(A>=vt_VarMin&&A<=vt_VarMax) + { + strcpy(VAR,GetVarTypeName(GlobalVars[i].VarType)); + strcpy(VAR,rpad(VAR,7)); + fprintf(Outfile,"%s%s%s%s%s%s%s\n",Storage,VAR," ",P,VarName,VarDim,";"); + } + break; + } + } + } + } + fprintf(Outfile,"%s\n",""); + } + if(Use_Overloaded) + { + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n","// User's Overloaded Subs/Functions "); + fprintf(Outfile,"%s\n","// *************************************************"); + if((FP8=fopen(ovrFile,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",ovrFile); + exit(1); + } + while(!EoF(FP8)) + { + ZZ[0]=0; + AR_fgets_retval=fgets(ZZ,1048576,FP8); + if(ZZ[strlen(ZZ)-1]==10)ZZ[strlen(ZZ)-1]=0; + if(instr_b(ZZ,"overloaded")) + { + fprintf(Outfile,"%s\n","\n"); + } + fprintf(Outfile,"%s\n",ZZ); + } + if(FP8) + { + fclose(FP8); + FP8=NULL; + } + fprintf(Outfile,"%s\n","\n\n"); + } + if((FP5=fopen(setFile,"r"))==0) + { + fprintf(stderr,"Can't open file %s\n",setFile); + exit(1); + } + if(lof(setFile)>0) + { + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n","// User GLOBAL SET Statements"); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n",""); + while(!EoF(FP5)) + { + Z[0]=0; + AR_fgets_retval=fgets(Z,1048576,FP5); + if(Z[strlen(Z)-1]==10)Z[strlen(Z)-1]=0; + fprintf(Outfile,"%s\n",Z); + } + fprintf(Outfile,"%s\n",""); + } + if(FP5) + { + fclose(FP5); + FP5=NULL; + } + if(Use_SingleFile==FALSE) + { + if(fpHFile) + { + fclose(fpHFile); + fpHFile=NULL; + } + } + if(NoMain==0) + { + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s%s\n","// ",BCX_STR_MAIN_PROG); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n",""); + } + if(NoMain==FALSE) + { + fprintf(Outfile,"%s\n",SaveMain); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," G_argc = argc;"); + fprintf(Outfile,"%s\n"," G_argv = argv;"); + BumpUp(); + } + while(!EoF(FP1)) + { + ZZ[0]=0; + AR_fgets_retval=fgets(ZZ,1048576,FP1); + if(ZZ[strlen(ZZ)-1]==10)ZZ[strlen(ZZ)-1]=0; + fprintf(Outfile,"%s%s\n",Scoot,ZZ); + } + if(Use_SingleFile==TRUE) + { + RunTimeFunctions(); + } + fflush(Outfile); + CloseAll(); + remove (FileOut); + rename ("$t$e$m$p",FileOut); +} + + +void RunTimeFunctions (void) +{ + static char X1[2048]; + memset(&X1,0,sizeof(X1)); + static char O1[2048]; + memset(&O1,0,sizeof(O1)); + static char D1[2048]; + memset(&D1,0,sizeof(D1)); + static char D2[2048]; + memset(&D2,0,sizeof(D2)); + static char T0[2048]; + memset(&T0,0,sizeof(T0)); + static char T1[2048]; + memset(&T1,0,sizeof(T1)); + static char T2[2048]; + memset(&T2,0,sizeof(T2)); + static char T3[2048]; + memset(&T3,0,sizeof(T3)); + static char T4[2048]; + memset(&T4,0,sizeof(T4)); + static char T5[2048]; + memset(&T5,0,sizeof(T5)); + static char T6[2048]; + memset(&T6,0,sizeof(T6)); + static char T7[2048]; + memset(&T7,0,sizeof(T7)); + static char T8[2048]; + memset(&T8,0,sizeof(T8)); + static char T9[2048]; + memset(&T9,0,sizeof(T9)); + static char T10[2048]; + memset(&T10,0,sizeof(T10)); + static char T11[2048]; + memset(&T11,0,sizeof(T11)); + static char T12[2048]; + memset(&T12,0,sizeof(T12)); + static char T13[2048]; + memset(&T13,0,sizeof(T13)); + static char TDIR[2048]; + memset(&TDIR,0,sizeof(TDIR)); + strcpy(D1,vchr(8,34,37,32,46,49,53,71,34)); + strcpy(D2,vchr(9,34,37,32,46,49,57,76,71,34)); + strcpy(O1,vchr(4,34,37,111,34)); + strcpy(T0,vchr(10,34,37,72,58,37,77,58,37,83,34)); + strcpy(T1,vchr(4,34,37,72,34)); + strcpy(T2,vchr(4,34,37,77,34)); + strcpy(T3,vchr(4,34,37,83,34)); + strcpy(T4,vchr(4,34,37,112,34)); + strcpy(T5,vchr(4,34,37,89,34)); + strcpy(T6,vchr(4,34,37,109,34)); + strcpy(T7,vchr(4,34,37,100,34)); + strcpy(T8,vchr(4,34,37,65,34)); + strcpy(T9,vchr(4,34,37,119,34)); + strcpy(T10,vchr(4,34,37,106,34)); + strcpy(T11,vchr(4,34,37,86,34)); + strcpy(T12,vchr(10,34,37,109,47,37,100,47,37,121,34)); + strcpy(T13,vchr(15,34,37,65,44,32,37,66,32,37,100,44,32,37,89,34)); + strcpy(X1,vchr(4,34,37,88,34)); + strcpy(TDIR,enc("/tmp/mbc.XXXXXXXX")); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s%s\n","// ",BCX_STR_RUNTIME); + fprintf(Outfile,"%s\n","// *************************************************"); + fprintf(Outfile,"%s\n",""); + if(NoRT==TRUE) + { + return; + } + if(UseFlag) + { + if(Use_Turbo) + { + fprintf(Outfile,"%s\n","char *BCX_TmpStr (size_t Bites)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," static int StrCnt;"); + fprintf(Outfile,"%s%d%s\n"," static char *StrFunc[",(int)TurboSize,"];"); + fprintf(Outfile,"%s%d%s\n"," StrCnt=((StrCnt+1) &",(int)TurboSize-1,");"); + fprintf(Outfile,"%s\n"," #if defined BCX_MAX_VAR_SIZE"); + fprintf(Outfile,"%s\n"," if(Bites*sizeof(char)>BCX_MAX_VAR_SIZE)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s%s%s\n"," printf(",enc("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\\n"),",(int)(Bites*sizeof(char)),BCX_MAX_VAR_SIZE);"); + fprintf(Outfile,"%s\n"," abort();"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," #endif"); + fprintf(Outfile,"%s\n"," StrFunc[StrCnt]=(char*)realloc(StrFunc[StrCnt],Bites + 128);"); + fprintf(Outfile,"%s\n"," return (char*)memset(StrFunc[StrCnt],0,Bites+128);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + else + { + fprintf(Outfile,"%s\n","char *BCX_TmpStr (size_t Bites)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," static int StrCnt;"); + fprintf(Outfile,"%s\n"," static char *StrFunc[65535];"); + fprintf(Outfile,"%s\n"," StrCnt=(StrCnt + 1) & 65535;"); + fprintf(Outfile,"%s\n"," if(StrFunc[StrCnt]) free (StrFunc[StrCnt]);"); + fprintf(Outfile,"%s\n"," #if defined BCX_MAX_VAR_SIZE"); + fprintf(Outfile,"%s\n"," if(Bites*sizeof(char)>BCX_MAX_VAR_SIZE)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s%s%s\n"," printf(",enc("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\\n"),",(int)(Bites*sizeof(char)),BCX_MAX_VAR_SIZE);"); + fprintf(Outfile,"%s\n"," abort();"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," #endif"); + fprintf(Outfile,"%s\n"," return StrFunc[StrCnt]=(char*)calloc(Bites+128,sizeof(char));"); + fprintf(Outfile,"%s\n","}\n\n"); + } + } + if(Use_CopyFile) + { + fprintf(Outfile,"%s\n","void CopyFile (char *InFile,char *TmpFile,int OverWrite)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," #define BLOCKCOPYSIZE (10 * 1000*1024)"); + fprintf(Outfile,"%s\n"," char* tmp=0;"); + fprintf(Outfile,"%s\n"," UINT blocks=1;"); + fprintf(Outfile,"%s\n"," UINT overage=0;"); + fprintf(Outfile,"%s\n"," UINT i;"); + fprintf(Outfile,"%s\n"," FILE *FP1,*FP2;"); + fprintf(Outfile,"%s\n"," if(!OverWrite)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(Exist(TmpFile)) return;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," if(Exist(InFile))"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," UINT length = lof(InFile);"); + fprintf(Outfile,"%s\n"," if(length > BLOCKCOPYSIZE)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," blocks = length/BLOCKCOPYSIZE;"); + fprintf(Outfile,"%s\n"," overage= length % BLOCKCOPYSIZE;"); + fprintf(Outfile,"%s\n"," length = BLOCKCOPYSIZE;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," tmp=(char*)calloc(16+length,1);"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s%s%s\n"," if((FP1=fopen(InFile,",enc("rb"),"))==0)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s%s%s\n"," fprintf(stderr,",enc("Can't open file %s\\n"),",InFile);"); + fprintf(Outfile,"%s\n"," exit(1);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s%s%s\n"," if((FP2=fopen(TmpFile,",enc("wb+"),"))==0)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s%s%s\n"," fprintf(stderr,",enc("Can't open file %s\\n"),",TmpFile);"); + fprintf(Outfile,"%s\n"," exit(1);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," for(i=0; i0)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," fread(tmp,1,overage,FP1);"); + fprintf(Outfile,"%s\n"," fwrite(tmp,1,overage,FP2);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," fclose(FP2); fclose(FP1);"); + fprintf(Outfile,"%s\n"," if(tmp) free(tmp);"); + fprintf(Outfile,"%s\n"," struct stat st;"); + fprintf(Outfile,"%s\n"," if(stat(InFile, &st) != -1)"); + fprintf(Outfile,"%s\n"," chmod(TmpFile,st.st_mode);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Str_Cmp) + { + fprintf(Outfile,"%s\n","int str_cmp (char *a, char *b)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int counter=0;"); + fprintf(Outfile,"%s\n"," for(;;)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if((a[counter]^b[counter]))"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if((UINT) a[counter]>= (UINT) b[counter])"); + fprintf(Outfile,"%s\n"," return 1;"); + fprintf(Outfile,"%s\n"," return -1;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," if(!a[counter]) return 0;"); + fprintf(Outfile,"%s\n"," counter++;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Eof) + { + fprintf(Outfile,"%s\n","int EoF (FILE* stream)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," register int c, status = ((c = fgetc(stream)) == EOF);"); + fprintf(Outfile,"%s\n"," ungetc(c,stream);"); + fprintf(Outfile,"%s\n"," return status;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Cint) + { + fprintf(Outfile,"%s\n","int Cint (double A)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return (A >=0 ? (int)(A+0.5) : (int)(A-0.5));"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Clng) + { + fprintf(Outfile,"%s\n","long CLNG (double A)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," float r=.5;"); + fprintf(Outfile,"%s\n"," double a=A-(long)A;"); + fprintf(Outfile,"%s\n"," if(A<0) { r=-.5; a=-a; }"); + fprintf(Outfile,"%s\n"," if(((long)A % 2)==0&&a<=.5)"); + fprintf(Outfile,"%s\n"," return (long)A;"); + fprintf(Outfile,"%s\n"," else"); + fprintf(Outfile,"%s\n"," return (long)(A+r);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Left) + { + fprintf(Outfile,"%s\n","char *left (char *S, int length)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int tmplen = strlen(S);"); + fprintf(Outfile,"%s\n"," if(length<1) return BCX_TmpStr(1);"); + fprintf(Outfile,"%s\n"," if(lengthtmplen||start<1) return BCX_TmpStr(1);"); + fprintf(Outfile,"%s\n"," if (length<0 || length>(tmplen-start)+1)"); + fprintf(Outfile,"%s\n"," length = (tmplen-start)+1;"); + fprintf(Outfile,"%s\n"," strtmp = BCX_TmpStr(length);"); + fprintf(Outfile,"%s\n"," return (char*)memcpy(strtmp,&S[start-1],length);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Trim) + { + fprintf(Outfile,"%s\n","char *trim (char *S)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," while(*S==32 || *S==9 || *S==10 || *S==11 || *S==13)"); + fprintf(Outfile,"%s\n"," S++;"); + fprintf(Outfile,"%s\n"," int i = strlen(S);"); + fprintf(Outfile,"%s\n"," while( i>0 && (S[i-1]==32 || S[i-1]==9 || S[i-1]==10"); + fprintf(Outfile,"%s\n"," || S[i-1]==11 || S[i-1]==13))"); + fprintf(Outfile,"%s\n"," i--;"); + fprintf(Outfile,"%s\n"," char *strtmp=BCX_TmpStr(i);"); + fprintf(Outfile,"%s\n"," return (char*)memcpy(strtmp,S,i);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Ltrim) + { + fprintf(Outfile,"%s\n","char *ltrim (char *S, char c)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," if(S[0]==0) return S;"); + fprintf(Outfile,"%s\n"," while((*S==32 || *S==c) && *S !=0) S++;"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(strlen(S));"); + fprintf(Outfile,"%s\n"," return strcpy(strtmp,S);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Rtrim) + { + fprintf(Outfile,"%s\n","char *rtrim (char *S,char c)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," if(S[0]==0) return S;"); + fprintf(Outfile,"%s\n"," int i = strlen(S);"); + fprintf(Outfile,"%s\n"," while(i>0 && (S[i-1]==c || S[i-1]==32))"); + fprintf(Outfile,"%s\n"," i--;"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(i);"); + fprintf(Outfile,"%s\n"," return (char*)memcpy(strtmp,S,i);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Strim) + { + fprintf(Outfile,"%s\n","char *strim (char *src)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(strlen(src));"); + fprintf(Outfile,"%s\n"," char *dst = strtmp;"); + fprintf(Outfile,"%s\n"," while (isspace((unsigned char)*src)) src++;"); + fprintf(Outfile,"%s\n"," do"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," while (*src && !isspace((unsigned char)*src)) *dst++ = *src++;"); + fprintf(Outfile,"%s\n"," if (*src)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," *dst++ = *src++;"); + fprintf(Outfile,"%s\n"," while (isspace((unsigned char)*src)) src++;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," } while (*src);"); + fprintf(Outfile,"%s\n"," if (isspace((unsigned char)*(--dst))) *dst = 0;"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Command) + { + fprintf(Outfile,"%s\n","char *command (int nArg)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," int i = 0;"); + fprintf(Outfile,"%s\n"," char *retstr=BCX_TmpStr(1);"); + fprintf(Outfile,"%s\n"," if(nArg < i) // return entire commandline"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," retstr = BCX_TmpStr(G_argc * 2048);"); + fprintf(Outfile,"%s\n"," for(i=1; i < G_argc; i++)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," strcat(retstr, G_argv[i]);"); + fprintf(Outfile,"%s\n"," strcat(retstr, SPC);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," else if(nArg < G_argc)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," retstr = BCX_TmpStr(strlen(G_argv[nArg]) + 1);"); + fprintf(Outfile,"%s\n"," strcpy(retstr, G_argv[nArg]);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return retstr;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Extract) + { + fprintf(Outfile,"%s\n","char *extract (char *mane, char *match)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *a;"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(strlen(mane));"); + fprintf(Outfile,"%s\n"," if(*match!=0)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," a=_strstr_(mane,match);"); + fprintf(Outfile,"%s\n"," if(a) return (char*)memcpy(strtmp,mane,a-mane);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return strcpy(strtmp,mane);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Remain) + { + fprintf(Outfile,"%s\n","char *remain (char *mane, char *mat)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *p = strstr(mane,mat);"); + fprintf(Outfile,"%s\n"," if(p)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," p+=(strlen(mat));"); + fprintf(Outfile,"%s\n"," return p;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return mane;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Replace) + { + fprintf(Outfile,"%s\n","char *replace (char *src, char *pat, char *rep)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," size_t patsz, repsz, tmpsz, delta;"); + fprintf(Outfile,"%s\n"," char *strtmp, *p, *q, *r;"); + fprintf(Outfile,"%s\n"," if (!pat || !*pat)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," strtmp = BCX_TmpStr(strlen(src));"); + fprintf(Outfile,"%s\n"," if (!strtmp) return NULL;"); + fprintf(Outfile,"%s\n"," return strcpy(strtmp, src);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," repsz = strlen(rep);"); + fprintf(Outfile,"%s\n"," patsz = strlen(pat);"); + fprintf(Outfile,"%s\n"," for (tmpsz=0, p=src; (q=_strstr_(p,pat))!=0; p=q+patsz)"); + fprintf(Outfile,"%s\n"," tmpsz += (size_t) (q - p) + repsz;"); + fprintf(Outfile,"%s\n"," tmpsz += strlen(p);"); + fprintf(Outfile,"%s\n"," strtmp = BCX_TmpStr(tmpsz);"); + fprintf(Outfile,"%s\n"," if (!strtmp) return NULL;"); + fprintf(Outfile,"%s\n"," for (r=strtmp,p=src; (q=_strstr_(p,pat))!=0;p=q+patsz)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," delta = (size_t) (q-p);"); + fprintf(Outfile,"%s\n"," memcpy(r,p,delta); r += delta;"); + fprintf(Outfile,"%s\n"," strcpy(r,rep); r += repsz;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," strcpy(r,p);"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Reverse) + { + fprintf(Outfile,"%s\n","char *reverse (char *s)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int j=strlen(s);"); + fprintf(Outfile,"%s\n"," char *rstr = BCX_TmpStr(j);"); + fprintf(Outfile,"%s\n"," while(j) rstr[--j] = *(s++);"); + fprintf(Outfile,"%s\n"," return rstr;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Findfirst) + { + fprintf(Outfile,"%s\n","char *findfirst (char *filespec, FILE_FIND_DATA *FindData)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," struct dirent *dp;"); + fprintf(Outfile,"%s\n"," struct stat st;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if(FindData->FileHandle)"); + fprintf(Outfile,"%s\n"," closedir(FindData->FileHandle);"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," strcpy(FindData->path, BcxSplitPath(filespec, FDRV|FPATH));"); + fprintf(Outfile,"%s\n"," strcpy(FindData->cFileSpec,BcxSplitPath(filespec, FNAME|FEXT));"); + fprintf(Outfile,"%s%s%s\n"," if(*FindData->path==0) strcpy(FindData->path, ",enc("."),");"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," FindData->FileHandle=opendir(FindData->path);"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," while(FindData->FileHandle)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," dp=readdir(FindData->FileHandle);"); + fprintf(Outfile,"%s\n"," if(dp==NULL) break;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if(like(dp->d_name,FindData->cFileSpec))"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," strcpy(FindData->cFileName,dp->d_name);"); + fprintf(Outfile,"%s\n"," lstat(join(2,FindData->path,dp->d_name), &st);"); + fprintf(Outfile,"%s\n"," FindData->dwFileAttributes = st.st_mode;"); + fprintf(Outfile,"%s\n"," return FindData->cFileName;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," *FindData->cFileName=0;"); + fprintf(Outfile,"%s\n"," return FindData->cFileName;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Findnext) + { + fprintf(Outfile,"%s\n","char *findnext (FILE_FIND_DATA *FindData)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," struct dirent *dp;"); + fprintf(Outfile,"%s\n"," struct stat st;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," while(FindData->FileHandle)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," dp=readdir(FindData->FileHandle);"); + fprintf(Outfile,"%s\n"," if(dp==NULL) break;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if(like(dp->d_name,FindData->cFileSpec))"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," strcpy(FindData->cFileName,dp->d_name);"); + fprintf(Outfile,"%s\n"," lstat(join(2,FindData->path,dp->d_name), &st);"); + fprintf(Outfile,"%s\n"," FindData->dwFileAttributes = st.st_mode;"); + fprintf(Outfile,"%s\n"," return FindData->cFileName;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," *FindData->cFileName=0;"); + fprintf(Outfile,"%s\n"," return FindData->cFileName;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Ucase) + { + fprintf(Outfile,"%s\n","char *ucase (char *S)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(strlen(S));"); + fprintf(Outfile,"%s\n"," return _strupr_(strcpy(strtmp,S));"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Lcase) + { + fprintf(Outfile,"%s\n","char *lcase (char *S)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(strlen(S));"); + fprintf(Outfile,"%s\n"," return _strlwr_(strcpy(strtmp,S));"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Mcase) + { + fprintf(Outfile,"%s\n","char *mcase (char *S)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(strlen(S)+1);"); + fprintf(Outfile,"%s\n"," char *s = strtmp;"); + fprintf(Outfile,"%s\n"," _strlwr_(strcpy(strtmp,S));"); + fprintf(Outfile,"%s\n"," while(*s)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(islower(*s))"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," *s-=32;"); + fprintf(Outfile,"%s\n"," while(isalpha(*++s));"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," s++;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Remove) + { + fprintf(Outfile,"%s\n","char *RemoveStr (char *a, char *b)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp, *p, *d;"); + fprintf(Outfile,"%s\n"," int tmplen;"); + fprintf(Outfile,"%s\n"," strtmp = d = BCX_TmpStr(strlen(a));"); + fprintf(Outfile,"%s\n"," if(!b || !*b) return strcpy(strtmp,a);"); + fprintf(Outfile,"%s\n"," p=_strstr_(a,b); tmplen = strlen(b);"); + fprintf(Outfile,"%s\n"," while(p)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," memcpy(d,a,p-a);"); + fprintf(Outfile,"%s\n"," d+= (p-a);"); + fprintf(Outfile,"%s\n"," a=p+tmplen;"); + fprintf(Outfile,"%s\n"," p=_strstr_(a,b);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," strcpy(d,a);"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_IRemove) + { + fprintf(Outfile,"%s\n","char *IRemoveStr (char *a, char *b)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp, *p, *d;"); + fprintf(Outfile,"%s\n"," int tmplen;"); + fprintf(Outfile,"%s\n"," strtmp = d = BCX_TmpStr(strlen(a));"); + fprintf(Outfile,"%s\n"," if(!b || !*b) return strcpy(strtmp,a);"); + fprintf(Outfile,"%s\n"," p=_stristr_(a,b); tmplen = strlen(b);"); + fprintf(Outfile,"%s\n"," while(p)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," memcpy(d,a,p-a);"); + fprintf(Outfile,"%s\n"," d+= (p-a);"); + fprintf(Outfile,"%s\n"," a=p+tmplen;"); + fprintf(Outfile,"%s\n"," p=_stristr_(a,b);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," strcpy(d,a);"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Ins) + { + fprintf(Outfile,"%s\n","char *ins (char *S, int i, char *a)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int j = strlen(S);"); + fprintf(Outfile,"%s\n"," if(i<1 || i>j+1) return S;"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(j + strlen(a));"); + fprintf(Outfile,"%s\n"," memcpy(strtmp,S,--i);"); + fprintf(Outfile,"%s\n"," strcpy(&strtmp[i],a);"); + fprintf(Outfile,"%s\n"," return strcat(strtmp,&S[i]);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Del) + { + fprintf(Outfile,"%s\n","char *del (char *S, int i, int j)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int ln = strlen(S);"); + fprintf(Outfile,"%s\n"," if(i<1 || i>ln) return S;"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(ln);"); + fprintf(Outfile,"%s\n"," memcpy(strtmp,S,--i);"); + fprintf(Outfile,"%s\n"," return strcat(strtmp,&S[i+j]);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Str) + { + fprintf(Outfile,"%s\n","char *str (double d)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(16);"); + fprintf(Outfile,"%s%s%s\n"," sprintf(strtmp,",D1,",d);"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Strl) + { + fprintf(Outfile,"%s\n","char *strl (long double d)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(27);"); + fprintf(Outfile,"%s%s%s\n"," sprintf(strtmp,",D2,",d);"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Curdir) + { + fprintf(Outfile,"%s\n","char *curdir (void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(2048);"); + fprintf(Outfile,"%s\n"," char *res=getcwd(strtmp, 1024);"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Hex) + { + fprintf(Outfile,"%s\n","char *hex (int a)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(16);"); + fprintf(Outfile,"%s%s%s\n"," sprintf(strtmp,",enc("%02X"),",a);"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Tempdir) + { + fprintf(Outfile,"%s\n","char *tempdir (void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(2048);"); + fprintf(Outfile,"%s%s%s\n"," if(!Exist(",enc("/tmp/mbc.compiler"),")) {"); + fprintf(Outfile,"%s%s%s\n"," mkdir (",enc("/tmp/mbc.compiler"),",0755);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s%s%s\n"," strcpy(strtmp,",enc("/tmp/mbc.compiler"),");"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Sysdir) + { + fprintf(Outfile,"%s\n","char *sysdir (void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(2048);"); + fprintf(Outfile,"%s\n"," GetSystemDirectory (strtmp,2048);"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Repeat) + { + fprintf(Outfile,"%s\n","char *repeat (int count, char *a)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr((1+count)*strlen(a));"); + fprintf(Outfile,"%s\n"," while(count-->0) strtmp = strcat(strtmp, a);"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_String) + { + fprintf(Outfile,"%s\n","char *stringx (int count, int a)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," if(count<1) return BCX_TmpStr(1);"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(count);"); + fprintf(Outfile,"%s\n"," return (char*)memset(strtmp,a,count);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Shell) + { + fprintf(Outfile,"%s\n","void Shell (char *cmd)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int res=system(cmd);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Space) + { + fprintf(Outfile,"%s\n","char *space (int count)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," if(count<1) return BCX_TmpStr(1);"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(count);"); + fprintf(Outfile,"%s\n"," return (char*)memset(strtmp,32,count);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Time) + { + fprintf(Outfile,"%s\n","char *timef (int t)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," time_t elapse_time;"); + fprintf(Outfile,"%s\n"," struct tm *tp;"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(256);"); + fprintf(Outfile,"%s\n"," time (&elapse_time);"); + fprintf(Outfile,"%s\n"," tp = localtime(&elapse_time);"); + fprintf(Outfile,"%s\n"," switch (t)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," case 0:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T0,",tp); break;"); + fprintf(Outfile,"%s\n"," case 1:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T1,",tp); break;"); + fprintf(Outfile,"%s\n"," case 2:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T2,",tp); break;"); + fprintf(Outfile,"%s\n"," case 3:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T3,",tp); break;"); + fprintf(Outfile,"%s\n"," case 4:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T4,",tp); break;"); + fprintf(Outfile,"%s\n"," case 5:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T5,",tp); break;"); + fprintf(Outfile,"%s\n"," case 6:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T6,",tp); break;"); + fprintf(Outfile,"%s\n"," case 7:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T7,",tp); break;"); + fprintf(Outfile,"%s\n"," case 8:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T8,",tp); break;"); + fprintf(Outfile,"%s\n"," case 9:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T9,",tp); break;"); + fprintf(Outfile,"%s\n"," case 10:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T10,",tp); break;"); + fprintf(Outfile,"%s\n"," case 11:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T11,",tp); break;"); + fprintf(Outfile,"%s\n"," case 12:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T12,",tp); break;"); + fprintf(Outfile,"%s\n"," case 13:"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",T13,",tp); break;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Enclose) + { + fprintf(Outfile,"%s\n","char *enc (char *A, int L, int R)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *BCX_RetStr = BCX_TmpStr(strlen(A)+3);"); + fprintf(Outfile,"%s\n"," if(L==0) L=34;"); + fprintf(Outfile,"%s\n"," if(R==0) R=L;"); + fprintf(Outfile,"%s%s%s%s%s\n"," sprintf(BCX_RetStr,",enc("%c%s%c%s"),",L,A,R,",enc("\0"),");"); + fprintf(Outfile,"%s\n"," return BCX_RetStr;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Chr) + { + fprintf(Outfile,"%s\n","char *chr (int a,int b,int c,int d,int e,int f,int g,int h,int i,int j)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(11);"); + fprintf(Outfile,"%s\n"," strtmp[0] = a;"); + fprintf(Outfile,"%s\n"," strtmp[1] = b;"); + fprintf(Outfile,"%s\n"," strtmp[2] = c;"); + fprintf(Outfile,"%s\n"," strtmp[3] = d;"); + fprintf(Outfile,"%s\n"," strtmp[4] = e;"); + fprintf(Outfile,"%s\n"," strtmp[5] = f;"); + fprintf(Outfile,"%s\n"," strtmp[6] = g;"); + fprintf(Outfile,"%s\n"," strtmp[7] = h;"); + fprintf(Outfile,"%s\n"," strtmp[8] = i;"); + fprintf(Outfile,"%s\n"," strtmp[9] = j;"); + fprintf(Outfile,"%s\n"," strtmp[10] = 0;"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_VChr) + { + fprintf(Outfile,"%s\n","char *vchr(int charcount, ...)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int c = 0, i = charcount;"); + fprintf(Outfile,"%s\n"," char *s_ = BCX_TmpStr(charcount + 1);"); + fprintf(Outfile,"%s\n"," va_list marker;"); + fprintf(Outfile,"%s\n"," s_[i] = 0;"); + fprintf(Outfile,"%s\n"," va_start(marker, charcount);"); + fprintf(Outfile,"%s\n"," while(i-- > 0) s_[c++] = va_arg(marker,int);"); + fprintf(Outfile,"%s\n"," va_end(marker);"); + fprintf(Outfile,"%s\n"," return s_;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Join) + { + fprintf(Outfile,"%s\n","char * join(int n, ...)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int i = n, tmplen = 0;"); + fprintf(Outfile,"%s\n"," char *strtmp, *s_;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," va_list marker;"); + fprintf(Outfile,"%s\n"," va_start(marker, n); // Initialize variable arguments"); + fprintf(Outfile,"%s\n"," while(i-- > 0)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," s_ = va_arg(marker, char *);"); + fprintf(Outfile,"%s\n"," if(s_) tmplen += strlen(s_);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," strtmp = BCX_TmpStr(tmplen);"); + fprintf(Outfile,"%s\n"," va_end(marker); // Reset variable arguments"); + fprintf(Outfile,"%s\n"," i = n;"); + fprintf(Outfile,"%s\n"," va_start(marker, n); // Initialize variable arguments"); + fprintf(Outfile,"%s\n"," while(i-- > 0)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," s_ = va_arg(marker, char *);"); + fprintf(Outfile,"%s\n"," if(s_) strcat(strtmp, s_);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," va_end(marker); // Reset variable arguments"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Environ) + { + fprintf(Outfile,"%s\n","char* Environ(char *S)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp, *tmp;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," tmp = getenv(S);"); + fprintf(Outfile,"%s\n"," if(tmp != NULL) {"); + fprintf(Outfile,"%s\n"," strtmp = BCX_TmpStr(strlen(tmp)+1);"); + fprintf(Outfile,"%s\n"," return strcpy(strtmp, tmp);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return BCX_TmpStr(1);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Oct) + { + fprintf(Outfile,"%s\n","char *oct (int a)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(2048);"); + fprintf(Outfile,"%s%s%s\n"," sprintf(strtmp,",O1,",a);"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Bin) + { + fprintf(Outfile,"%s\n","char* Bin(int number)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(2048);"); + fprintf(Outfile,"%s\n"," itoa(number,strtmp,2);"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Pause) + { + fprintf(Outfile,"%s\n","void Pause(void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s%s%s%s%s\n"," printf(",enc("\\n%s\\n"),",",enc("Press any key to continue . . ."),");"); + fprintf(Outfile,"%s\n"," _getch_(TRUE);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Keypress) + { + fprintf(Outfile,"%s\n","int keypress(void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return _getch_(TRUE);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Inkey) + { + fprintf(Outfile,"%s\n","char* inkey(void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(2);"); + fprintf(Outfile,"%s\n"," strtmp[0] = _getch_(FALSE);"); + fprintf(Outfile,"%s\n"," if(strtmp[0] == -1) strtmp[0] = 0;"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_InkeyD) + { + fprintf(Outfile,"%s\n","int inkeyd(void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return _getch_(TRUE);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Instat) + { + fprintf(Outfile,"%s\n","int kbhit(void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," struct termios oldt, newt;"); + fprintf(Outfile,"%s\n"," int ch;"); + fprintf(Outfile,"%s\n"," int oldf;"); + fprintf(Outfile,"%s\n"," tcgetattr(STDIN_FILENO, &oldt);"); + fprintf(Outfile,"%s\n"," newt = oldt;"); + fprintf(Outfile,"%s\n"," newt.c_lflag &= ~(ICANON | ECHO);"); + fprintf(Outfile,"%s\n"," tcsetattr(STDIN_FILENO, TCSANOW, &newt);"); + fprintf(Outfile,"%s\n"," oldf = fcntl(STDIN_FILENO, F_GETFL, 0);"); + fprintf(Outfile,"%s\n"," fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);"); + fprintf(Outfile,"%s\n"," ch = getchar();"); + fprintf(Outfile,"%s\n"," tcsetattr(STDIN_FILENO, TCSANOW, &oldt);"); + fprintf(Outfile,"%s\n"," fcntl(STDIN_FILENO, F_SETFL, oldf);"); + fprintf(Outfile,"%s\n"," if(ch != EOF)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," ungetc(ch, stdin);"); + fprintf(Outfile,"%s\n"," return 1;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_GetCh) + { + fprintf(Outfile,"%s\n","int _getch_(int waitkey)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," struct termios initial_settings, new_settings;"); + fprintf(Outfile,"%s\n"," unsigned char ch;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," tcgetattr(0,&initial_settings);"); + fprintf(Outfile,"%s\n"," new_settings = initial_settings;"); + fprintf(Outfile,"%s\n"," new_settings.c_lflag &= ~ICANON;"); + fprintf(Outfile,"%s\n"," new_settings.c_lflag &= ~ECHO;"); + fprintf(Outfile,"%s\n"," new_settings.c_lflag &= ~ISIG;"); + fprintf(Outfile,"%s\n"," new_settings.c_cc[VMIN] = waitkey;"); + fprintf(Outfile,"%s\n"," new_settings.c_cc[VTIME] = 0;"); + fprintf(Outfile,"%s\n"," tcsetattr(0, TCSANOW, &new_settings);"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," //read(0,&ch,1);"); + fprintf(Outfile,"%s\n"," ch = getchar();"); + fprintf(Outfile,"%s\n"," tcsetattr(0, TCSANOW, &initial_settings);"); + fprintf(Outfile,"%s\n"," return ch;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Now) + { + fprintf(Outfile,"%s\n","char *now (void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," time_t elapse_time;"); + fprintf(Outfile,"%s\n"," struct tm *tp;"); + fprintf(Outfile,"%s\n"," char *strtmp = BCX_TmpStr(2048);"); + fprintf(Outfile,"%s\n"," time(&elapse_time);"); + fprintf(Outfile,"%s\n"," tp=localtime(&elapse_time);"); + fprintf(Outfile,"%s%s%s\n"," strftime(strtmp,256,",enc("%m/%d/%y %I:%M:%S: %p"),",tp);"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}"); + } + if(Use_AppExePath) + { + fprintf(Outfile,"%s\n","char *AppExePath (void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char fullpath[MAX_PATH];"); + fprintf(Outfile,"%s\n"," int length;"); + #if defined (__APPLE__) + fprintf(Outfile,"%s\n"," pid_t pid = getpid();"); + fprintf(Outfile,"%s\n"," length = proc_pidpath (pid, fullpath, sizeof(fullpath));"); + #else + fprintf(Outfile,"%s%s%s\n"," length = readlink(",enc("/proc/self/exe"),", fullpath, MAX_PATH);"); + #endif + fprintf(Outfile,"%s\n"," if(length < 1) return BCX_TmpStr(1);"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," fullpath[length] = 0;"); + fprintf(Outfile,"%s\n"," return BcxSplitPath(fullpath, FDRV|FPATH);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_AppExeName) + { + fprintf(Outfile,"%s\n","char *AppExeName (void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return BcxSplitPath(G_argv[0], FNAME|FEXT);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_TempFileName) + { + fprintf(Outfile,"%s\n","char * TempFileName (char *dr, char *prefix)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," static unsigned int count;"); + fprintf(Outfile,"%s\n"," char *f, *tmpstr = BCX_TmpStr(MAX_PATH);"); + fprintf(Outfile,"%s\n"," int i, length;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if(!count) srand(time(0));"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if(dr) strcpy(tmpstr, dr);"); + fprintf(Outfile,"%s\n"," length = strlen(tmpstr);"); + fprintf(Outfile,"%s\n"," if(length && (tmpstr[length-1] != '\\\\' && tmpstr[length-1] != '/'))"); + fprintf(Outfile,"%s\n"," tmpstr[length++] = '/';"); + fprintf(Outfile,"%s\n"," if(prefix) strcpy(&tmpstr[length], prefix);"); + fprintf(Outfile,"%s\n"," f = &tmpstr[strlen(tmpstr)];"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," do {"); + fprintf(Outfile,"%s\n"," count++;"); + fprintf(Outfile,"%s\n"," for(i=0; i<5; i+=1)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," do {"); + fprintf(Outfile,"%s\n"," f[i]=(char)(rnd()*122);"); + fprintf(Outfile,"%s\n"," }while((f[i]<65)||(f[i]>90&&f[i]<97));"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s%s%s\n"," snprintf(&f[5],3,",enc("%x"),", count);"); + fprintf(Outfile,"%s\n"," } while (Exist(tmpstr));"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," return tmpstr;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Boolstr) + { + fprintf(Outfile,"%s\n","char * BoolStr (int a)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *BCX_RetStr=BCX_TmpStr(5);"); + fprintf(Outfile,"%s%s%s\n"," if(a) return strcpy(BCX_RetStr,",enc("True"),");"); + fprintf(Outfile,"%s%s%s\n"," return strcpy(BCX_RetStr,",enc("False"),");"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Using) + { + fprintf(Outfile,"%s\n","char *Using (char *Mask, double Num)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int Spaces = 0;"); + fprintf(Outfile,"%s\n"," int CntDec = 0;"); + fprintf(Outfile,"%s\n"," int Decimals = 0;"); + fprintf(Outfile,"%s\n"," int Dollar = 0;"); + fprintf(Outfile,"%s\n"," char* BCX_RetStr = BCX_TmpStr(512);"); + fprintf(Outfile,"%s\n"," char Buf_1[512]={0};"); + fprintf(Outfile,"%s\n"," char* p = Mask;"); + fprintf(Outfile,"%s\n"," char* r;"); + fprintf(Outfile,"%s\n"," int len;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," while (*p)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if (*p == 36) Dollar++;"); + fprintf(Outfile,"%s\n"," if (*p == 32) Spaces++;"); + fprintf(Outfile,"%s\n"," if ((*p == 32 || *p == 35)&& CntDec) Decimals++;"); + fprintf(Outfile,"%s\n"," if (*p == 46) CntDec = 1;"); + fprintf(Outfile,"%s\n"," p++;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s%s%s\n"," sprintf(Buf_1,",enc("%1.*f"),",Decimals,Num);"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," len = strlen(Buf_1)-Decimals-(Decimals>0?1:0);"); + fprintf(Outfile,"%s\n"," r = BCX_RetStr+Dollar+Spaces;"); + fprintf(Outfile,"%s\n"," p = Buf_1;"); + fprintf(Outfile,"%s\n"," while (*p)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," *r++ = *p++;"); + fprintf(Outfile,"%s\n"," if (--len>2 && *(p-1) != '-' && len % 3 == 0)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," *r++ = ',';"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," if(Dollar) BCX_RetStr[Spaces]=36;"); + fprintf(Outfile,"%s\n"," if(Spaces) memset(BCX_RetStr,32,Spaces);"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," return BCX_RetStr;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_SearchPath) + { + fprintf(Outfile,"%s\n","char *SEARCHPATH (char *szFile)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *BCX_RetStr=BCX_TmpStr(MAX_PATH+1);"); + fprintf(Outfile,"%s\n"," PCHAR lpbs=0;"); + fprintf(Outfile,"%s\n"," SearchPath(0,szFile,0,MAX_PATH,BCX_RetStr,&lpbs);"); + fprintf(Outfile,"%s\n"," if(lpbs) *lpbs=0;"); + fprintf(Outfile,"%s\n"," return BCX_RetStr;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Instrrev) + { + fprintf(Outfile,"%s\n","int InstrRev (char *s, char *p, int os, int sens)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int sl, pl, ox;"); + fprintf(Outfile,"%s\n"," int (*cmp)(const char *, const char *, size_t );"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if (!s || !p) return 0;"); + fprintf(Outfile,"%s\n"," sl = strlen(s); pl = strlen(p);"); + fprintf(Outfile,"%s\n"," if (os > sl || sl == 0 || pl == 0 || (ox = sl - pl) < 0)"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if (os <= 0) "); + fprintf(Outfile,"%s\n"," os = ox ;"); + fprintf(Outfile,"%s\n"," else if(os >= pl)"); + fprintf(Outfile,"%s\n"," os = os - pl ;"); + fprintf(Outfile,"%s\n"," else"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," cmp = (sens ? strncasecmp : strncmp);"); + fprintf(Outfile,"%s\n"," do { if (cmp(s + os , p, pl) == 0)"); + fprintf(Outfile,"%s\n"," return os+1;"); + fprintf(Outfile,"%s\n"," } while (os--);"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Instr) + { + fprintf(Outfile,"%s\n","int instr_b(char* mane,char* match,int offset,int sensflag)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *s;"); + fprintf(Outfile,"%s\n"," if (!mane || !match || ! *match || offset>(int)strlen(mane)) return 0;"); + fprintf(Outfile,"%s\n"," if (sensflag)"); + fprintf(Outfile,"%s\n"," s = _stristr_(offset>0 ? mane+offset-1 : mane,match);"); + fprintf(Outfile,"%s\n"," else"); + fprintf(Outfile,"%s\n"," s = _strstr_(offset>0 ? mane+offset-1 : mane,match);"); + fprintf(Outfile,"%s\n"," return s ? (int)(s-mane)+1 : 0;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(UseLCaseTbl) + { + fprintf(Outfile,"%s\n","char *MakeLCaseTbl (void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," static char tbl[256];"); + fprintf(Outfile,"%s\n"," if(!tbl['a'])"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," int i; for (i=0; i < 256; i++)"); + fprintf(Outfile,"%s\n"," tbl[i] = (char)(int)tolower(i);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return tbl;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Stristr) + { + fprintf(Outfile,"%s\n","char *_stristr_(char *String, char *Pattern)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int mi=-1;"); + fprintf(Outfile,"%s\n"," char *LowCase = MakeLCaseTbl();"); + fprintf(Outfile,"%s\n"," while(Pattern[++mi])"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(String[mi]==0) return 0;"); + fprintf(Outfile,"%s\n"," if(LowCase[(unsigned char)String[mi]]!=LowCase[(unsigned char)Pattern[mi]])"); + fprintf(Outfile,"%s\n"," { String++; mi=-1; }"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return String;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_StrStr) + { + fprintf(Outfile,"%s\n","char *_strstr_(char *String, char *Pattern)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int mi=-1;"); + fprintf(Outfile,"%s\n"," while(Pattern[++mi])"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(String[mi]==0) return 0;"); + fprintf(Outfile,"%s\n"," if(String[mi]!=Pattern[mi])"); + fprintf(Outfile,"%s\n"," { String++; mi=-1; }"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return String;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Inchr) + { + fprintf(Outfile,"%s\n","int inchr (char *A, char *B)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char* C=A;"); + fprintf(Outfile,"%s\n"," while(*C)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(*C==*B) return C-A+1;"); + fprintf(Outfile,"%s\n"," C++;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Asc) + { + fprintf(Outfile,"%s\n","extern int asc (char *z,int index)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return (unsigned char) z[index];"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Sgn) + { + fprintf(Outfile,"%s\n","double sgn (double a)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," if(a<0) return -1;"); + fprintf(Outfile,"%s\n"," if(a>0) return 1;"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Round) + { + fprintf(Outfile,"%s\n","double Round (double n, int d)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return (floor((n)*pow(10.0,(d))+0.5)/pow(10.0,(d)));"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Embed) + { + fprintf(Outfile,"%s\n","char* GetResource (int *resource)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *BCX_RetStr={0};"); + fprintf(Outfile,"%s\n"," static char* dat;"); + fprintf(Outfile,"%s\n"," memset(&dat,0,sizeof(char *));"); + fprintf(Outfile,"%s\n"," dat=(char*)resource;"); + fprintf(Outfile,"%s\n"," BCX_RetStr=BCX_TmpStr(strlen(dat));"); + fprintf(Outfile,"%s\n"," strcpy(BCX_RetStr,dat);"); + fprintf(Outfile,"%s\n"," return BCX_RetStr;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Exist) + { + fprintf(Outfile,"%s\n","bool Exist (char *szFilePath)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int retstat;"); + fprintf(Outfile,"%s\n"," struct stat sb;"); + fprintf(Outfile,"%s\n"," retstat = stat(szFilePath, &sb);"); + fprintf(Outfile,"%s\n"," if(retstat != -1)"); + fprintf(Outfile,"%s\n"," return TRUE;"); + fprintf(Outfile,"%s\n"," return FALSE;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Tally) + { + fprintf(Outfile,"%s\n","int tally (char *szLine, char *szChar, int sensflag)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," if(!*szChar) return 0;"); + fprintf(Outfile,"%s\n"," int mlen = strlen(szChar);"); + fprintf(Outfile,"%s\n"," int iCount = 0;"); + fprintf(Outfile,"%s\n"," char *p = (sensflag == 0 ? _strstr_(szLine, szChar) : _stristr_(szLine, szChar));"); + fprintf(Outfile,"%s\n"," while (p)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," iCount++;"); + fprintf(Outfile,"%s\n"," p+=mlen;"); + fprintf(Outfile,"%s\n"," p = (sensflag == 0 ? _strstr_(p, szChar) : _stristr_(p, szChar));"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return iCount;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Timer) + { + fprintf(Outfile,"%s\n","float timer (void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return ((double)clock()/CLOCKS_PER_SEC);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Rnd) + { + fprintf(Outfile,"%s\n","float rnd (void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return (float)rand()/RAND_MAX;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Exp) + { + fprintf(Outfile,"%s\n","double Exp (double arg)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return pow(2.718281828459045,arg);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Randomize) + { + fprintf(Outfile,"%s\n","void randomize (unsigned int seed)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," srand(seed);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Max) + { + fprintf(Outfile,"%s\n","double _MAX_ (double a, double b)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," if(a>b)"); + fprintf(Outfile,"%s\n"," return a;"); + fprintf(Outfile,"%s\n"," return b;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Min) + { + fprintf(Outfile,"%s\n","double _MIN_ (double a, double b)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," if(asrclen++ || st<1) return;"); + fprintf(Outfile,"%s\n"," int replen = strlen(rep);"); + fprintf(Outfile,"%s\n"," if(replen < length || length==-1) length=replen;"); + fprintf(Outfile,"%s\n"," if((st+length) > srclen) length=srclen-st;"); + fprintf(Outfile,"%s\n"," memcpy(&src[st-1],rep,length);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Swap) + { + fprintf(Outfile,"%s\n","void swap ( UCHAR* A, UCHAR* B, int length)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," UCHAR t;"); + fprintf(Outfile,"%s\n"," while(length--)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," t = *A;"); + fprintf(Outfile,"%s\n"," *(A++) = *B;"); + fprintf(Outfile,"%s\n"," *(B++) = t;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Like) + { + fprintf(Outfile,"%s\n","int like (char *raw, char *pat)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char a, b, d;"); + fprintf(Outfile,"%s\n"," char *r, *p;"); + fprintf(Outfile,"%s\n"," int star = 0;"); + fprintf(Outfile,"%s\n"," for(;;) {"); + fprintf(Outfile,"%s\n"," if ((d = *pat++)==0) return (star || !*raw);"); + fprintf(Outfile,"%s\n"," else if (d == '*') star = 1;"); + fprintf(Outfile,"%s\n"," else if (d == '?') { if (!*raw++) return 0; }"); + fprintf(Outfile,"%s\n"," else break;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," b = d;"); + fprintf(Outfile,"%s\n"," do if ((a = *raw++) == b) {"); + fprintf(Outfile,"%s\n"," r = raw;"); + fprintf(Outfile,"%s\n"," p = pat;"); + fprintf(Outfile,"%s\n"," do {"); + fprintf(Outfile,"%s\n"," if ((d = *p++) == '*')"); + fprintf(Outfile,"%s\n"," if (like(r, p - 1)) return 1;"); + fprintf(Outfile,"%s\n"," else break;"); + fprintf(Outfile,"%s\n"," else if (!d) {"); + fprintf(Outfile,"%s\n"," if (!*r) return 1;"); + fprintf(Outfile,"%s\n"," else break;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," } while (*r++ == d || d == '?');"); + fprintf(Outfile,"%s\n"," } while (star && a);"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Lof) + { + fprintf(Outfile,"%s\n","DWORD lof (char *FileName)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," int retstat;"); + fprintf(Outfile,"%s\n"," struct stat sb;"); + fprintf(Outfile,"%s\n"," retstat = stat(FileName, &sb);"); + fprintf(Outfile,"%s\n"," if(retstat != -1)"); + fprintf(Outfile,"%s\n"," return sb.st_size;"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Iif) + { + fprintf(Outfile,"%s\n","double iif (bool cond, double tp, double fp)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," if(cond) return tp;"); + fprintf(Outfile,"%s\n"," return fp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_sziif) + { + fprintf(Outfile,"%s\n","char * sziif (bool i, char *a, char *b)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," if(i) return a;"); + fprintf(Outfile,"%s\n"," return b;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_DynamicA) + { + fprintf(Outfile,"%s\n","void *CreateArr(void *a, int elem_size, int update, int num_dims, ... )"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," va_list ap;"); + fprintf(Outfile,"%s\n"," void *RetPtr;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," va_start(ap, num_dims);"); + fprintf(Outfile,"%s\n"," RetPtr = CreateArr_internal(a, elem_size, update, num_dims, ap);"); + fprintf(Outfile,"%s\n"," va_end(ap);"); + fprintf(Outfile,"%s\n"," return (RetPtr);"); + fprintf(Outfile,"%s\n","}\n\n"); + fprintf(Outfile,"%s\n","void *CreateArr_internal(void *a, int elem_size, int update, int num_dims, va_list ap)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," size_t s, s1, s2;"); + fprintf(Outfile,"%s\n"," void **vp;"); + fprintf(Outfile,"%s\n"," va_list marker;"); + fprintf(Outfile,"%s\n"," "); + fprintf(Outfile,"%s\n","#ifdef va_copy"); + fprintf(Outfile,"%s\n"," va_copy(marker, ap);"); + fprintf(Outfile,"%s\n","#else"); + fprintf(Outfile,"%s\n"," marker = ap;"); + fprintf(Outfile,"%s\n","#endif"); + fprintf(Outfile,"%s\n"," s = va_arg(marker, size_t);"); + fprintf(Outfile,"%s\n"," s2 = s + 2;"); + fprintf(Outfile,"%s\n"," if(num_dims == 1)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(update && a)"); + fprintf(Outfile,"%s\n"," a=realloc(a,s2*elem_size);"); + fprintf(Outfile,"%s\n"," else"); + fprintf(Outfile,"%s\n"," a=calloc(s2,elem_size);"); + fprintf(Outfile,"%s\n"," return a;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," else"); + fprintf(Outfile,"%s\n"," if(update && a)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," s1 = 0;"); + fprintf(Outfile,"%s\n"," vp = (void**)a;"); + fprintf(Outfile,"%s\n"," while(*vp && s1 <= s)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," vp++;"); + fprintf(Outfile,"%s\n"," s1++;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," if(s1 > s)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," vp--;"); + fprintf(Outfile,"%s\n"," DestroyArr(vp, num_dims, 0);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," a=realloc(a,s2*sizeof(int));"); + fprintf(Outfile,"%s\n"," s1 = 0;"); + fprintf(Outfile,"%s\n"," vp = (void**)a;"); + fprintf(Outfile,"%s\n"," while(*vp && s1 <= s)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," vp++;"); + fprintf(Outfile,"%s\n"," s1++;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," while(s1 < s2)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," *(((int *)vp)) = 0;"); + fprintf(Outfile,"%s\n"," vp++;"); + fprintf(Outfile,"%s\n"," s1++;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," else"); + fprintf(Outfile,"%s\n"," a=calloc(s2*sizeof(int),1);"); + fprintf(Outfile,"%s\n"," vp = (void**)a;"); + fprintf(Outfile,"%s\n"," if(--num_dims > 0)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," for(s1 = 0; s1 < s; s1++)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," vp[s1] = CreateArr_internal(vp[s1], elem_size, update, num_dims, marker);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return a;"); + fprintf(Outfile,"%s\n","}\n\n"); + fprintf(Outfile,"%s\n","void DestroyArr (void** a,int num_dims, int top_free)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int i = 0;"); + fprintf(Outfile,"%s\n"," static int s = 0;"); + fprintf(Outfile,"%s\n"," if(num_dims == 1)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," free(a);"); + fprintf(Outfile,"%s\n"," return;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," s++;"); + fprintf(Outfile,"%s\n"," num_dims--; "); + fprintf(Outfile,"%s\n"," while(a[i])"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," DestroyArr((void**)a[i], num_dims, top_free);"); + fprintf(Outfile,"%s\n"," if(num_dims > 1)"); + fprintf(Outfile,"%s\n"," free(a[i]);"); + fprintf(Outfile,"%s\n"," a[i++]=NULL;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," s--;"); + fprintf(Outfile,"%s\n"," if(s == 0 && top_free)"); + fprintf(Outfile,"%s\n"," free(a);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Idxqsort) + { + fprintf(Outfile,"%s\n","int IdxCompare (const void *one, const void *two)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int *ptr1 = (int *)(one);"); + fprintf(Outfile,"%s\n"," int *ptr2 = (int *)(two);"); + fprintf(Outfile,"%s\n"," return strcasecmp (pppStr[Key][*ptr1],pppStr[Key][*ptr2]);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_IdxqsortSt) + { + fprintf(Outfile,"%s\n","int IdxCompareSt (const void* one, const void* two)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n","#define compare1 cmp1+(StructSize * (*(UINT *)(one)))"); + fprintf(Outfile,"%s\n","#define compare2 cmp1+(StructSize * (*(UINT *)(two)))"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if (Key==0)"); + fprintf(Outfile,"%s\n"," return strcasecmp(compare1, compare2);"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if (Key==1)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if (*(int*)(compare1) < *(int*)(compare2)) return -1;"); + fprintf(Outfile,"%s\n"," if (*(int*)(compare1) > *(int*)(compare2)) return 1;"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if (Key==2)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if (*(double*)(compare1) < *(double*)(compare2)) return -1;"); + fprintf(Outfile,"%s\n"," if (*(double*)(compare1) > *(double*)(compare2)) return 1;"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if (Key==3)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if (*(UINT*)(compare1) < *(UINT*)(compare2)) return -1;"); + fprintf(Outfile,"%s\n"," if (*(UINT*)(compare1) > *(UINT*)(compare2)) return 1;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n","return 0;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_PtrqsortSt) + { + fprintf(Outfile,"%s\n","int PtrCompareSt (const void* one, const void* two)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n","#define pcompare1 ((char*)(one)+OffSet)"); + fprintf(Outfile,"%s\n","#define pcompare2 ((char*)(two)+OffSet)"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if (Key==0)"); + fprintf(Outfile,"%s\n"," return strcasecmp(pcompare1, pcompare2);"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if (Key==1)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if (*(int*)(pcompare1) < *(int*)(pcompare2)) return -1;"); + fprintf(Outfile,"%s\n"," if (*(int*)(pcompare1) > *(int*)(pcompare2)) return 1;"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if (Key==2)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if (*(double*)(pcompare1) < *(double*)(pcompare2)) return -1;"); + fprintf(Outfile,"%s\n"," if (*(double*)(pcompare1) > *(double*)(pcompare2)) return 1;"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if (Key==3)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if (*(UINT*)(pcompare1) < *(UINT*)(pcompare2)) return -1;"); + fprintf(Outfile,"%s\n"," if (*(UINT*)(pcompare1) > *(UINT*)(pcompare2)) return 1;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n","return 0;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Strqsorta) + { + fprintf(Outfile,"%s\n","int StrCompareA (const void *arg1, const void *arg2)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *v1 = (char*) arg1;"); + fprintf(Outfile,"%s\n"," char *v2 = (char*) arg2;"); + fprintf(Outfile,"%s\n"," return strcasecmp (v1,v2);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Strqsortd) + { + fprintf(Outfile,"%s\n","int StrCompareD (const void *arg1, const void *arg2)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *v1 = (char*) arg1;"); + fprintf(Outfile,"%s\n"," char *v2 = (char*) arg2;"); + fprintf(Outfile,"%s\n"," return strcasecmp (v2,v1);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_DynStrqsorta) + { + fprintf(Outfile,"%s\n","int DynStrCompareA (const void *arg1, const void *arg2)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *v1 = *(char **) arg1;"); + fprintf(Outfile,"%s\n"," char *v2 = *(char **) arg2;"); + fprintf(Outfile,"%s\n"," return strcasecmp(v1, v2);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_DynStrqsortd) + { + fprintf(Outfile,"%s\n","int DynStrCompareD (const void *arg1, const void *arg2)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *v1 = *(char **) arg1;"); + fprintf(Outfile,"%s\n"," char *v2 = *(char **) arg2;"); + fprintf(Outfile,"%s\n"," return strcasecmp(v2, v1);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Numqsortaint) + { + fprintf(Outfile,"%s\n","int NumCompareAint (const void *one, const void *two)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int *ptr1 = (int *)(one);"); + fprintf(Outfile,"%s\n"," int *ptr2 = (int *)(two);"); + fprintf(Outfile,"%s\n"," if (*ptr1 < *ptr2) return -1;"); + fprintf(Outfile,"%s\n"," else if (*ptr1 == *ptr2) return 0;"); + fprintf(Outfile,"%s\n"," else return 1;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Numqsortdint) + { + fprintf(Outfile,"%s\n","int NumCompareDint (const void *one, const void *two)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int *ptr1 = (int *)(one);"); + fprintf(Outfile,"%s\n"," int *ptr2 = (int *)(two);"); + fprintf(Outfile,"%s\n"," if (*ptr1 > *ptr2) return -1;"); + fprintf(Outfile,"%s\n"," else if (*ptr1 == *ptr2) return 0;"); + fprintf(Outfile,"%s\n"," else return 1;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Numqsortafloat) + { + fprintf(Outfile,"%s\n","int NumCompareAfloat (const void *one, const void *two)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," float *ptr1 = (float *)(one);"); + fprintf(Outfile,"%s\n"," float *ptr2 = (float *)(two);"); + fprintf(Outfile,"%s\n"," if (*ptr1 < *ptr2) return -1;"); + fprintf(Outfile,"%s\n"," else if (*ptr1 == *ptr2) return 0;"); + fprintf(Outfile,"%s\n"," else return 1;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Numqsortdfloat) + { + fprintf(Outfile,"%s\n","int NumCompareDfloat (const void *one, const void *two)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," float *ptr1 = (float *)(one);"); + fprintf(Outfile,"%s\n"," float *ptr2 = (float *)(two);"); + fprintf(Outfile,"%s\n"," if (*ptr1 > *ptr2) return -1;"); + fprintf(Outfile,"%s\n"," else if (*ptr1 == *ptr2) return 0;"); + fprintf(Outfile,"%s\n"," else return 1;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Numqsortadouble) + { + fprintf(Outfile,"%s\n","int NumCompareAdouble (const void *one, const void *two)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," double *ptr1 = (double *)(one);"); + fprintf(Outfile,"%s\n"," double *ptr2 = (double *)(two);"); + fprintf(Outfile,"%s\n"," if (*ptr1 < *ptr2) return -1;"); + fprintf(Outfile,"%s\n"," else if (*ptr1 == *ptr2) return 0;"); + fprintf(Outfile,"%s\n"," else return 1;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Numqsortddouble) + { + fprintf(Outfile,"%s\n","int NumCompareDdouble (const void *one, const void *two)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," double *ptr1 = (double *)(one);"); + fprintf(Outfile,"%s\n"," double *ptr2 = (double *)(two);"); + fprintf(Outfile,"%s\n"," if (*ptr1 > *ptr2) return -1;"); + fprintf(Outfile,"%s\n"," else if (*ptr1 == *ptr2) return 0;"); + fprintf(Outfile,"%s\n"," else return 1;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_FillArray) + { + fprintf(Outfile,"%s\n","int fillarray(char *input, int ArrayType, int MaxCnt, void *Array)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," if(MaxCnt < 1) return -1;"); + fprintf(Outfile,"%s\n"," int c = 0, cnt=-1, cnt2;"); + fprintf(Outfile,"%s\n"," char A[65535];"); + fprintf(Outfile,"%s\n"," int *intptr = (int *)Array;"); + fprintf(Outfile,"%s\n"," float *floatptr = (float *)Array;"); + fprintf(Outfile,"%s\n"," double *doubleptr = (double *)Array;"); + fprintf(Outfile,"%s\n"," long double *ldoubleptr = (long double *)Array;"); + fprintf(Outfile,"%s\n"," for(;;)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," cnt2=0;"); + fprintf(Outfile,"%s\n"," while(input[++cnt]!=',')"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(input[cnt]==0) break;"); + fprintf(Outfile,"%s\n"," A[cnt2++]=input[cnt];"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," A[cnt2]=0;"); + fprintf(Outfile,"%s\n"," if(cnt2==0||c==MaxCnt) break;"); + fprintf(Outfile,"%s\n"," "); + fprintf(Outfile,"%s\n"," if(ArrayType==2)"); + fprintf(Outfile,"%s\n"," intptr[c++] = atoi(A);"); + fprintf(Outfile,"%s\n"," else if(ArrayType==3)"); + fprintf(Outfile,"%s\n"," floatptr[c++] = atof(A);"); + fprintf(Outfile,"%s\n"," else if(ArrayType==4)"); + fprintf(Outfile,"%s\n"," doubleptr[c++] = atof(A);"); + fprintf(Outfile,"%s\n"," else if(ArrayType==5)"); + fprintf(Outfile,"%s\n"," ldoubleptr[c++] = atof(A);"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," if(input[cnt]==0) break;"); + fprintf(Outfile,"%s\n"," } "); + fprintf(Outfile,"%s\n"," return (c-1);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Loc) + { + fprintf(Outfile,"%s\n","int loc(FILE *fp, int fplen)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," fpos_t t;"); + fprintf(Outfile,"%s\n"," fgetpos(fp, &t);"); + fprintf(Outfile,"%s\n","#if defined( __POCC__ )"); + fprintf(Outfile,"%s\n"," t.off %= fplen;"); + fprintf(Outfile,"%s\n"," return (int)t.off;"); + fprintf(Outfile,"%s\n","#else"); + fprintf(Outfile,"%s\n"," t %= fplen;"); + fprintf(Outfile,"%s\n"," return (int)t;"); + fprintf(Outfile,"%s\n","#endif"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Rec) + { + fprintf(Outfile,"%s\n","int rec(FILE *fp, int fplen)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," fpos_t t;"); + fprintf(Outfile,"%s\n"," fgetpos(fp, &t);"); + fprintf(Outfile,"%s\n","#if defined( __POCC__ )"); + fprintf(Outfile,"%s\n"," t.off /= fplen;"); + fprintf(Outfile,"%s\n"," return (int)++t.off;"); + fprintf(Outfile,"%s\n","#else"); + fprintf(Outfile,"%s\n"," t /= fplen;"); + fprintf(Outfile,"%s\n"," return (int)++t;"); + fprintf(Outfile,"%s\n","#endif"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_RecCount) + { + fprintf(Outfile,"%s\n","int reccount(FILE *fp, int fplen)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," fpos_t t;"); + fprintf(Outfile,"%s\n"," fseek(fp,0,SEEK_END);"); + fprintf(Outfile,"%s\n"," fgetpos(fp, &t);"); + fprintf(Outfile,"%s\n","#if defined( __POCC__ )"); + fprintf(Outfile,"%s\n"," t.off /= fplen;"); + fprintf(Outfile,"%s\n"," return (int)t.off;"); + fprintf(Outfile,"%s\n","#else"); + fprintf(Outfile,"%s\n"," t /= fplen;"); + fprintf(Outfile,"%s\n"," return (int)t;"); + fprintf(Outfile,"%s\n","#endif"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Scan) + { + fprintf(Outfile,"%s\n","int scan(char *input, char *format, ... )"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int c,d ;"); + fprintf(Outfile,"%s\n"," char *s_;"); + fprintf(Outfile,"%s\n"," int *intptr;"); + fprintf(Outfile,"%s\n"," float *floatptr;"); + fprintf(Outfile,"%s\n"," double *doubleptr;"); + fprintf(Outfile,"%s\n"," char A[50][65535];"); + fprintf(Outfile,"%s\n"," va_list marker;"); + fprintf(Outfile,"%s\n"," c = 0;"); + fprintf(Outfile,"%s%s%s\n"," d = Split(A,input,",enc(","),");"); + fprintf(Outfile,"%s\n"," va_start(marker, format); //Initialize arguments"); + fprintf(Outfile,"%s\n"," while(d && *format)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(*format == '%') format++;"); + fprintf(Outfile,"%s\n"," if(*format == 's')"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," s_ = va_arg(marker, char *);"); + fprintf(Outfile,"%s\n"," strcpy(s_, A[c]);"); + fprintf(Outfile,"%s\n"," c++;"); + fprintf(Outfile,"%s\n"," d--;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," if(*format == 'd')"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," intptr = va_arg(marker, int *);"); + fprintf(Outfile,"%s\n"," *intptr = atoi(A[c]);"); + fprintf(Outfile,"%s\n"," c++;"); + fprintf(Outfile,"%s\n"," d--;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," if(*format == 'g')"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," floatptr = va_arg(marker, float *);"); + fprintf(Outfile,"%s\n"," *floatptr = atof(A[c]);"); + fprintf(Outfile,"%s\n"," c++;"); + fprintf(Outfile,"%s\n"," d--;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," if(*format == 'l')"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," format++;"); + fprintf(Outfile,"%s\n"," doubleptr = va_arg(marker, double *);"); + fprintf(Outfile,"%s\n"," *doubleptr = atof(A[c]);"); + fprintf(Outfile,"%s\n"," c++;"); + fprintf(Outfile,"%s\n"," d--;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," format++;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," va_end(marker); // Reset variable arguments"); + fprintf(Outfile,"%s\n"," if(d) return(1); // More data than variables"); + fprintf(Outfile,"%s\n"," if(*format == 0) return(0); // OK"); + fprintf(Outfile,"%s\n"," return(-1); // More variables than data"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Split) + { + fprintf(Outfile,"%s\n","int Split (char Buf[][65535], char *T, char *Delim, int Flg)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int Begin = 0;"); + fprintf(Outfile,"%s\n"," int Count = 0;"); + fprintf(Outfile,"%s\n"," int Quote = 0;"); + fprintf(Outfile,"%s\n"," int Index,i;"); + fprintf(Outfile,"%s\n"," int lenT = strlen(T);"); + fprintf(Outfile,"%s\n"," char Chr34[2]={34,0};"); + fprintf(Outfile,"%s\n"," for(Index=1;Index<=lenT;Index++)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(instr_b(Delim,mid(T,Index,1))&&!Quote)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," strcpy(Buf[Count],(char*)mid(T,Begin,Index-Begin));"); + fprintf(Outfile,"%s\n"," if ((Flg & 2) == 0) // 0 if old version"); + fprintf(Outfile,"%s\n"," Count++;"); + fprintf(Outfile,"%s\n"," else"); + fprintf(Outfile,"%s\n"," if (Buf[Count][0] != 0) Count++;"); + fprintf(Outfile,"%s\n"," Begin=0;"); + fprintf(Outfile,"%s\n"," if((Flg & 1) == 1) // 1 if true"); + fprintf(Outfile,"%s\n"," strcpy(Buf[Count++],(char*)mid(T,Index,1));"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," else"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(strcmp(mid(T,Index,1),Chr34)==0) Quote=!Quote;"); + fprintf(Outfile,"%s\n"," if(Begin==0) Begin=Index;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," if(Begin)"); + fprintf(Outfile,"%s\n"," strcpy(Buf[Count++],(char*)mid(T,Begin,Index-Begin));"); + fprintf(Outfile,"%s\n"," if((Flg & 1) == 0) // 0 if false"); + fprintf(Outfile,"%s\n"," for(i=0;i= 'a' && ch <= 'f') || (ch >= '0' && ch <= '9'))"); + fprintf(Outfile,"%s\n"," dwOut |=((int)ch - (ch>'9' ? 'a'-10 : '0')) << ((dwLen - szInput) << 2);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return dwOut;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Verify) + { + fprintf(Outfile,"%s\n","int Verify (char *Src, char *Allowed)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int i, j;"); + fprintf(Outfile,"%s\n"," for (i=1; i<=strlen(Src); i++)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," j=VerifyInstr(Allowed,mid(Src,i,1));"); + fprintf(Outfile,"%s\n"," if (!j) return 0;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return TRUE;"); + fprintf(Outfile,"%s\n","}\n\n"); + fprintf(Outfile,"%s\n","int VerifyInstr(char* mane,char* match,int offset)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *s;"); + fprintf(Outfile,"%s\n"," if (!mane || !match || !*match || offset>(int)strlen(mane)) return 0;"); + fprintf(Outfile,"%s\n"," s = strstr (offset>0 ? mane+offset-1 : mane,match);"); + fprintf(Outfile,"%s\n"," return s ? (int)(s-mane)+1 : 0;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Retain) + { + fprintf(Outfile,"%s\n","char *Retain (char *Text, char *ValidChars)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *BCX_RetStr=BCX_TmpStr(strlen(Text));"); + fprintf(Outfile,"%s\n"," char *temp=BCX_RetStr;"); + fprintf(Outfile,"%s\n"," while(*Text)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(strchr(ValidChars,*Text)) *(temp++) = *Text;"); + fprintf(Outfile,"%s\n"," Text++;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return BCX_RetStr;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_LoadFile) + { + fprintf(Outfile,"%s\n","char* LoadFile (char *N)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," FILE* FP1;"); + fprintf(Outfile,"%s\n"," char* BCX_RetStr;"); + fprintf(Outfile,"%s\n"," if(Exist(N))"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," BCX_RetStr=BCX_TmpStr(lof(N));"); + fprintf(Outfile,"%s%s%s\n"," if((FP1=fopen(N,",enc("rb"),"))!=0)"); + fprintf(Outfile,"%s\n"," GET(FP1,BCX_RetStr,lof(N));"); + fprintf(Outfile,"%s\n"," fclose(FP1);"); + fprintf(Outfile,"%s\n"," return BCX_RetStr;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," else"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," BCX_RetStr=BCX_TmpStr(64);"); + fprintf(Outfile,"%s%s%s\n"," return strcpy(BCX_RetStr,",enc("File Not Found"),");"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Freefile) + { + fprintf(Outfile,"%s\n","FILE* FreeFile (void)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," static FILE *pf;"); + fprintf(Outfile,"%s\n"," if(pf){free(pf);pf=NULL;}"); + fprintf(Outfile,"%s\n"," pf = (FILE*)calloc(sizeof(FILE*),sizeof(FILE*));"); + fprintf(Outfile,"%s\n"," return pf;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Run) + { + fprintf(Outfile,"%s\n","int Run (char* Cmdline, int ShowHide, int WaitState)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int processId;"); + fprintf(Outfile,"%s\n"," char *s, *p, *cmd_line;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," cmd_line=(char*)malloc(strlen(Cmdline)+1);"); + fprintf(Outfile,"%s\n"," if(cmd_line==NULL) return -2;"); + fprintf(Outfile,"%s\n",""); + fprintf(Outfile,"%s\n"," strcpy(cmd_line, Cmdline);"); + fprintf(Outfile,"%s\n"," p = s = cmd_line;"); + fprintf(Outfile,"%s\n"," processId=fork();"); + fprintf(Outfile,"%s\n"," if(processId==0)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," PCHAR argv[30];"); + fprintf(Outfile,"%s\n"," int i=0;"); + fprintf(Outfile,"%s\n"," while(*p)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(*p==34)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," while(*(++p)!=34) {}"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," if(*p==32)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," while(*(p+1)==32) p++;"); + fprintf(Outfile,"%s\n"," argv[i++]=s;"); + fprintf(Outfile,"%s\n"," *p=0; s=p+1;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," p++;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," argv[i] = s;"); + fprintf(Outfile,"%s\n"," argv[i+1]= 0;"); + fprintf(Outfile,"%s\n"," execvp(argv[0],argv);"); + fprintf(Outfile,"%s%s%s\n"," printf(",enc("Failed to run%s\\n"),",argv[0]);"); + fprintf(Outfile,"%s\n"," exit(-1);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," else if(processId!=-1)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(WaitState) waitpid(processId,NULL,0);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," waitpid(-1,NULL,WNOHANG);"); + fprintf(Outfile,"%s\n"," free(cmd_line), cmd_line=NULL;"); + fprintf(Outfile,"%s\n"," return processId;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Download) + { + fprintf(Outfile,"%s\n","int Download (char *URL,char *Localname)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int RetVal;"); + fprintf(Outfile,"%s\n"," return RetVal=!RetVal;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_PeekStr) + { + fprintf(Outfile,"%s\n","char *peekstr (LPVOID Src, int Count)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *Des=BCX_TmpStr(Count);"); + fprintf(Outfile,"%s\n"," memmove(Des,Src,Count);"); + fprintf(Outfile,"%s\n"," return Des;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_QBColor) + { + fprintf(Outfile,"%s\n","int qbcolor (int N)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," switch (N)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," case 0 : return RGB(0,0,0);"); + fprintf(Outfile,"%s\n"," case 1 : return RGB(0,0,128);"); + fprintf(Outfile,"%s\n"," case 2 : return RGB(0,128,0);"); + fprintf(Outfile,"%s\n"," case 3 : return RGB(0,128,128);"); + fprintf(Outfile,"%s\n"," case 4 : return RGB(196,0,0);"); + fprintf(Outfile,"%s\n"," case 5 : return RGB(128,0,128);"); + fprintf(Outfile,"%s\n"," case 6 : return RGB(128,64,0);"); + fprintf(Outfile,"%s\n"," case 7 : return RGB(196,196,196);"); + fprintf(Outfile,"%s\n"," case 8 : return RGB(128,128,128);"); + fprintf(Outfile,"%s\n"," case 9 : return RGB(0,0, 255);"); + fprintf(Outfile,"%s\n"," case 10 : return RGB(0,255,0);"); + fprintf(Outfile,"%s\n"," case 11 : return RGB(0,255,255);"); + fprintf(Outfile,"%s\n"," case 12 : return RGB(255,0,0);"); + fprintf(Outfile,"%s\n"," case 13 : return RGB(255,0,255);"); + fprintf(Outfile,"%s\n"," case 14 : return RGB(255,255,0);"); + fprintf(Outfile,"%s\n"," case 15 : return RGB(255,255,255);"); + fprintf(Outfile,"%s\n"," case 16 : return RGB(164,164,164);"); + fprintf(Outfile,"%s\n"," case 17 : return RGB(128,160,255);"); + fprintf(Outfile,"%s\n"," case 18 : return RGB(160,255,160);"); + fprintf(Outfile,"%s\n"," case 19 : return RGB(160,255,255);"); + fprintf(Outfile,"%s\n"," case 20 : return RGB(255,160,160);"); + fprintf(Outfile,"%s\n"," case 21 : return RGB(255,160,255);"); + fprintf(Outfile,"%s\n"," case 22 : return RGB(255,255,160);"); + fprintf(Outfile,"%s\n"," case 23 : return RGB(212,212,212);"); + fprintf(Outfile,"%s\n"," case 24 : return RGB(180,180,180);"); + fprintf(Outfile,"%s\n"," case 25 : return RGB(188,220,255);"); + fprintf(Outfile,"%s\n"," case 26 : return RGB(220,255,220);"); + fprintf(Outfile,"%s\n"," case 27 : return RGB(220,255,255);"); + fprintf(Outfile,"%s\n"," case 28 : return RGB(255,220,220);"); + fprintf(Outfile,"%s\n"," case 29 : return RGB(255,220,255);"); + fprintf(Outfile,"%s\n"," case 30 : return RGB(255,255,220);"); + fprintf(Outfile,"%s\n"," case 31 : return RGB(228,228,228);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n","return 0;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Cvi) + { + fprintf(Outfile,"%s\n","short CVI (char *s)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return ((short*)s)[0];"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Mki) + { + fprintf(Outfile,"%s\n","char *MKI (short cvt)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," static char temp[3];"); + fprintf(Outfile,"%s\n"," return (char *)memmove(temp,&cvt,2);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Cvl) + { + fprintf(Outfile,"%s\n","long CVL (char *s)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return ((long*)s)[0];"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Mkl) + { + fprintf(Outfile,"%s\n","char *MKL (int cvt)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," static char temp[5];"); + fprintf(Outfile,"%s\n"," return (char *) memmove(temp,&cvt,4);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Cvs) + { + fprintf(Outfile,"%s\n","float CVS (char *s)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return ((float*)s)[0];"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Mks) + { + fprintf(Outfile,"%s\n","char *MKS (float cvt)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," static char temp[5];"); + fprintf(Outfile,"%s\n"," return (char *) memmove(temp,&cvt,4);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Cvd) + { + fprintf(Outfile,"%s\n","double CVD (char *s)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return ((double*)s)[0];"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Cvld) + { + fprintf(Outfile,"%s\n","long double CVLD (char *s)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return ((long double*)s)[0];"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Mkd) + { + fprintf(Outfile,"%s\n","char *MKD (double cvt)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," static char temp[9];"); + fprintf(Outfile,"%s\n"," return (char *) memmove(temp,&cvt,8);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Mkld) + { + fprintf(Outfile,"%s\n","char *MKLD (long double cvt)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," static char temp[11];"); + fprintf(Outfile,"%s\n"," return (char *) memmove(temp,&cvt,10);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_BcxSplitPath) + { + fprintf(Outfile,"%s\n","char *BcxSplitPath (char *FPath, int mask)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," if(!FPath) return BCX_TmpStr(1);"); + fprintf(Outfile,"%s\n"," char *BCX_RetStr=BCX_TmpStr(strlen(FPath));"); + fprintf(Outfile,"%s\n"," char tmp[MAX_PATH*4];"); + fprintf(Outfile,"%s\n"," _splitpath_(FPath,tmp,&tmp[MAX_PATH],&tmp[MAX_PATH*2],&tmp[MAX_PATH*3]);"); + fprintf(Outfile,"%s\n"," if(mask & FDRV) strcat(BCX_RetStr,tmp);"); + fprintf(Outfile,"%s\n"," if(mask & FPATH)strcat(BCX_RetStr,&tmp[MAX_PATH]);"); + fprintf(Outfile,"%s\n"," if(mask & FNAME)strcat(BCX_RetStr,&tmp[MAX_PATH*2]);"); + fprintf(Outfile,"%s\n"," if(mask & FEXT) strcat(BCX_RetStr,&tmp[MAX_PATH*3]);"); + fprintf(Outfile,"%s\n"," return BCX_RetStr;"); + fprintf(Outfile,"%s\n","}\n\n"); + fprintf(Outfile,"%s\n"," void _splitpath_(const char* path, char* drv, char* dir, char* name, char* ext)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," const char* pend; /* end of processed string */"); + fprintf(Outfile,"%s\n"," const char* p; /* search pointer */"); + fprintf(Outfile,"%s\n"," const char* s; /* copy pointer */"); + fprintf(Outfile,"%s\n"," "); + fprintf(Outfile,"%s\n"," /* extract drive name */"); + fprintf(Outfile,"%s\n"," if (path[0] && path[1]==':') {"); + fprintf(Outfile,"%s\n"," if (drv) {"); + fprintf(Outfile,"%s\n"," *drv++ = *path++;"); + fprintf(Outfile,"%s\n"," *drv++ = *path++;"); + fprintf(Outfile,"%s\n"," *drv = 0;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," } else if (drv)"); + fprintf(Outfile,"%s\n"," *drv = 0;"); + fprintf(Outfile,"%s\n"," "); + fprintf(Outfile,"%s\n"," /* search for end of string or stream separator */"); + fprintf(Outfile,"%s\n"," for(pend=path; *pend && *pend!=':'; )"); + fprintf(Outfile,"%s\n"," pend++;"); + fprintf(Outfile,"%s\n"," "); + fprintf(Outfile,"%s\n"," /* search for begin of file extension */"); + fprintf(Outfile,"%s\n"," for(p=pend; p > path && *--p != '\\\\' && *p!='/'; )"); + fprintf(Outfile,"%s\n"," if (*p == '.') {"); + fprintf(Outfile,"%s\n"," pend = p;"); + fprintf(Outfile,"%s\n"," break;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," "); + fprintf(Outfile,"%s\n"," if (ext)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," s=pend;"); + fprintf(Outfile,"%s\n"," do{ *ext++ = *s; } while(*s++);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," /* search for end of directory name */"); + fprintf(Outfile,"%s\n"," for(p=pend; p > path; )"); + fprintf(Outfile,"%s\n"," if (*--p == '\\\\' || *p == '/') {"); + fprintf(Outfile,"%s\n"," p++;"); + fprintf(Outfile,"%s\n"," break;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," "); + fprintf(Outfile,"%s\n"," if (name) {"); + fprintf(Outfile,"%s\n"," for(s=p; stally(Source,TokenChar)+1)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," BCX_RetStr=BCX_TmpStr(1);"); + fprintf(Outfile,"%s\n"," if(RetVal)free(RetVal);"); + fprintf(Outfile,"%s\n"," return BCX_RetStr;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," while(*Copy)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(*Copy==TokenChar[0]) Find++;"); + fprintf(Outfile,"%s\n"," if(Find==n) break;"); + fprintf(Outfile,"%s\n"," Copy++;"); + fprintf(Outfile,"%s\n"," Posn++;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," if(n==tally(Source,TokenChar)+1)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," Posn=LenSrc;"); + fprintf(Outfile,"%s\n"," Copy=Source+Posn;"); + fprintf(Outfile,"%s\n"," while(*Copy&&Source[Posn]!=TokenChar[0])"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," Posn--;"); + fprintf(Outfile,"%s\n"," Copy--;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," strcpy(RetVal,(char*)mid(Source,1,Posn));"); + fprintf(Outfile,"%s\n"," strcpy(RetVal,(char*)mid(RetVal,InstrRev(RetVal,TokenChar)));"); + fprintf(Outfile,"%s\n"," BCX_RetStr=BCX_TmpStr(LenSrc);"); + fprintf(Outfile,"%s\n"," strcpy(BCX_RetStr,(char*)RemoveStr(RetVal,TokenChar));"); + fprintf(Outfile,"%s\n"," if(RetVal)free(RetVal);"); + fprintf(Outfile,"%s\n"," return BCX_RetStr;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_iReplace) + { + fprintf(Outfile,"%s\n","char *iReplace (char *src, char *pat, char *rep)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," size_t patsz, repsz, tmpsz, delta;"); + fprintf(Outfile,"%s\n"," char *strtmp, *p, *q, *r;"); + fprintf(Outfile,"%s\n"," if (!pat || !*pat)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," strtmp = BCX_TmpStr(strlen(src));"); + fprintf(Outfile,"%s\n"," if (!strtmp) return NULL;"); + fprintf(Outfile,"%s\n"," return strcpy(strtmp, src);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," repsz = strlen(rep);"); + fprintf(Outfile,"%s\n"," patsz = strlen(pat);"); + fprintf(Outfile,"%s\n"," for (tmpsz=0, p=src;(q=_stristr_(p,pat))!=0; p=q+patsz)"); + fprintf(Outfile,"%s\n"," tmpsz += (size_t) (q - p) + repsz;"); + fprintf(Outfile,"%s\n"," tmpsz += strlen(p);"); + fprintf(Outfile,"%s\n"," strtmp = BCX_TmpStr(tmpsz);"); + fprintf(Outfile,"%s\n"," if (!strtmp) return NULL;"); + fprintf(Outfile,"%s\n"," for (r=strtmp,p=src;(q=_stristr_(p,pat))!=0;p=q+patsz)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," delta = (size_t) (q-p);"); + fprintf(Outfile,"%s\n"," memcpy(r,p,delta); r += delta;"); + fprintf(Outfile,"%s\n"," strcpy(r,rep); r += repsz;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," strcpy(r,p);"); + fprintf(Outfile,"%s\n"," return strtmp;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_WideToAnsi) + { + fprintf(Outfile,"%s\n","char* WideToAnsi (wchar_t *WideStr, UINT CodePage,DWORD dwFlags)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," char *BCX_RetStr={0};"); + fprintf(Outfile,"%s\n"," UINT uLen;"); + fprintf(Outfile,"%s\n"," uLen=wcstombs(NULL, WideStr, 0); //WideCharToMultiByte(CodePage,dwFlags,WideStr,-1,0,0,0,0);"); + fprintf(Outfile,"%s\n"," BCX_RetStr=(char*)BCX_TmpStr(uLen);"); + fprintf(Outfile,"%s\n"," wcstombs(BCX_RetStr, WideStr, uLen); //WideCharToMultiByte(CodePage,dwFlags,WideStr,-1,BCX_RetStr,uLen,0,0);"); + fprintf(Outfile,"%s\n"," return BCX_RetStr;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_SysStr) + { + fprintf(Outfile,"%s\n","BSTR SysStr (char * szIn, int widstr, int bfree)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," static BSTR bStr[32];"); + fprintf(Outfile,"%s\n"," static int index;"); + fprintf(Outfile,"%s\n"," if(bfree)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," for(index=0; index<32; index+=1) "); + fprintf(Outfile,"%s\n"," SysFreeString(bStr[index]);"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," index=(++index & 31);"); + fprintf(Outfile,"%s\n"," SysFreeString(bStr[index]);"); + fprintf(Outfile,"%s\n"," int length=strlen(szIn);"); + fprintf(Outfile,"%s\n"," if(widstr)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," bStr[index]=SysAllocStringLen(NULL, (2*length));"); + fprintf(Outfile,"%s\n"," MultiByteToWideChar(CP_ACP,0,szIn,-1,bStr[index],(2*length+1));"); + fprintf(Outfile,"%s\n"," }else{"); + fprintf(Outfile,"%s\n"," bStr[index]=SysAllocStringByteLen(szIn, length);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return bStr[index];"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_AnsiToWide) + { + fprintf(Outfile,"%s\n","wchar_t *AnsiToWide (char *AnsiStr, UINT CodePage,DWORD dwFlags)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," UINT uLen;"); + fprintf(Outfile,"%s\n"," wchar_t *WideStr;"); + fprintf(Outfile,"%s\n"," uLen=mbstowcs(NULL, AnsiStr, 0); //MultiByteToWideChar(CodePage,dwFlags,AnsiStr,-1,0,0);"); + fprintf(Outfile,"%s\n"," if(uLen<=1) return (wchar_t*)BCX_TmpStr(2);"); + fprintf(Outfile,"%s\n"," WideStr = (wchar_t*)BCX_TmpStr(2*uLen);"); + fprintf(Outfile,"%s\n"," mbstowcs(WideStr, AnsiStr, uLen); //MultiByteToWideChar(CodePage,dwFlags,AnsiStr,uLen,WideStr,uLen);"); + fprintf(Outfile,"%s\n"," return WideStr;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_FileLocked) + { + fprintf(Outfile,"%s\n","int FileLocked (char *Filename)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s%s%s\n"," FILE *FP=fopen(Filename,",enc("rb+"),");"); + fprintf(Outfile,"%s\n"," if(FP==0) return 1;"); + fprintf(Outfile,"%s\n"," fclose(FP);"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_ContainedIn) + { + fprintf(Outfile,"%s\n","int containedin(char * Token,char **Contain ,int c)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," int i=0;"); + fprintf(Outfile,"%s\n"," while(Contain[i][0])"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if(0 == ((c == 0 || c == 2) ? strcmp(Contain[i],Token) : strcasecmp(Contain[i],Token)))"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," return ((c < 2) ? 0 : i);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," i++;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return -1;"); + fprintf(Outfile,"%s\n"," }\n\n"); + } + if(Use_FindInType) + { + fprintf(Outfile,"%s\n","int FindInType(char *Token,char *StOffset,int StSize,int start,int finish,int c,int *idx)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," int j;"); + fprintf(Outfile,"%s\n"," char *Srch;"); + fprintf(Outfile,"%s\n"," int (*cmp)(const char*,const char*);"); + fprintf(Outfile,"%s\n"," cmp = ((c == 0 || c == 2) ? strcmp : strcasecmp);"); + fprintf(Outfile,"%s\n"," for(j=start; j<=finish; j++)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," Srch = StOffset + ((idx==0) ? j*StSize : idx[j]*StSize);"); + fprintf(Outfile,"%s\n"," if(cmp(Srch,Token)==0)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," return ((c < 2) ? 0 : j);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return -1;"); + fprintf(Outfile,"%s\n"," }\n\n"); + } + if(Use_StartupCode) + { + fprintf(Outfile,"%s\n","int BCX_StartupCode_(void)"); + fprintf(Outfile,"%s\n","{"); + {register int i; + for(i=1; i<=StartNdx; i+=1) + { + fprintf(Outfile,"%s%s%s\n"," ",StartSub[i],"();"); + } + } + fprintf(Outfile,"%s\n"," return 1;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_ExitCode) + { + fprintf(Outfile,"%s\n","int BCX_ExitCode_(void)"); + fprintf(Outfile,"%s\n","{"); + {register int i; + for(i=1; i<=ExitNdx; i+=1) + { + fprintf(Outfile,"%s%s%s\n"," atexit(",ExitSub[i],");"); + } + } + fprintf(Outfile,"%s\n"," return 1;"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_Socket) + { + fprintf(Outfile,"%s\n","sockaddr_in sock_addr (char *ServerName,int port)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," in_addr iaHost;"); + fprintf(Outfile,"%s\n"," hostent* lpHostEntry;"); + fprintf(Outfile,"%s\n"," sockaddr_in saServer;"); + fprintf(Outfile,"%s\n"," iaHost.s_addr=inet_addr(ServerName);"); + fprintf(Outfile,"%s\n"," if(iaHost.s_addr==INADDR_NONE)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," lpHostEntry=gethostbyname(ServerName);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," else"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," lpHostEntry=gethostbyaddr((char*)&iaHost,sizeof(in_addr),AF_INET);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," if(lpHostEntry==NULL)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s%s%s\n"," printf(",enc("Error! HOST NOT FOUND: %s\\n"),", ServerName);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," else"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," saServer.sin_port=htons(port);"); + fprintf(Outfile,"%s\n"," saServer.sin_family=AF_INET;"); + fprintf(Outfile,"%s\n"," saServer.sin_addr=*(in_addr*)lpHostEntry->h_addr;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return saServer;"); + fprintf(Outfile,"%s\n","}\n\n"); + fprintf(Outfile,"%s\n","int connect_socket (sockaddr_in saServer)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," int Socket, nRet;"); + fprintf(Outfile,"%s\n"," Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);"); + fprintf(Outfile,"%s\n"," if(Socket==-1)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," return Socket;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," nRet=connect(Socket,(sockaddr*)&saServer,sizeof(sockaddr_in));"); + fprintf(Outfile,"%s\n"," if(nRet==-1)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," close(Socket);"); + fprintf(Outfile,"%s\n"," return nRet;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return Socket;"); + fprintf(Outfile,"%s\n","}\n\n"); + fprintf(Outfile,"%s\n","int BcxSocket (char *ServerName,int port)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," sockaddr_in saServer;"); + fprintf(Outfile,"%s\n"," saServer=sock_addr(ServerName,port);"); + fprintf(Outfile,"%s\n"," return connect_socket(saServer);"); + fprintf(Outfile,"%s\n","}\n\n"); + fprintf(Outfile,"%s\n","int BcxSocketSend (int Socket, char *szBuffer)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," static int nRet;"); + fprintf(Outfile,"%s\n"," nRet=send(Socket,szBuffer,strlen(szBuffer),0);"); + fprintf(Outfile,"%s\n"," if(nRet==-1)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," close(Socket);"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," return nRet;"); + fprintf(Outfile,"%s\n","}\n\n"); + fprintf(Outfile,"%s\n","int BcxSocketRead (int Socket, char *szBuffer)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," return read(Socket,szBuffer,strlen(szBuffer));"); + fprintf(Outfile,"%s\n","}\n\n"); + fprintf(Outfile,"%s\n","void BcxSocketClose(int Socket) {"); + fprintf(Outfile,"%s\n"," close(Socket);"); + fprintf(Outfile,"%s\n","}\n\n"); + } + if(Use_RegEx) + { + fprintf(Outfile,"%s\n","bool regmatch (char *buffer, char *pattern, REGEX* retval)"); + fprintf(Outfile,"%s\n","{"); + fprintf(Outfile,"%s\n"," static int t;"); + fprintf(Outfile,"%s\n"," static int i;"); + fprintf(Outfile,"%s\n"," static regex_t re;"); + fprintf(Outfile,"%s\n"," t=regcomp( &re,pattern,REG_ICASE|REG_EXTENDED);"); + fprintf(Outfile,"%s\n"," if(t)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," regerror(t, &re,buffer,sizeof(buffer));"); + fprintf(Outfile,"%s%s%s\n"," printf(",enc("regex error: %s %s"),",buffer,pattern);"); + fprintf(Outfile,"%s\n"," return 0;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," t=regexec( &re,buffer,1023,(*retval).matches,0);"); + fprintf(Outfile,"%s\n"," (*retval).count=re.re_nsub;"); + fprintf(Outfile,"%s\n"," if(!t)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," for(i=1; i<=(*retval).count; i+=1)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," if((*retval).matches[i].rm_so>=0)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," (*retval).results[i]=peekstr( &buffer[(*retval).matches[i].rm_so],((*retval).matches[i].rm_eo-(*retval).matches[i].rm_so));"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," regfree( &re);"); + fprintf(Outfile,"%s\n"," if(!t)"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," return TRUE;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n"," else"); + fprintf(Outfile,"%s\n"," {"); + fprintf(Outfile,"%s\n"," return FALSE;"); + fprintf(Outfile,"%s\n"," }"); + fprintf(Outfile,"%s\n","}\n\n"); + } +} + + +int JoinLines (char *Arg) +{ + if(iMatchRgt(Arg," _")) + { + Arg[strlen(Arg)-1]=0; + strcat(CurLine,Arg); + return 1; + } + if(*CurLine!=0) + { + strcpy(Arg, join(2,CurLine,Arg)); + *CurLine=0; + } + UmQt=FALSE; + return 0; +} + + +void StripCode (char *Arg) +{ + PCHAR p; + PCHAR p2=Arg; + int asmFlag=0; + int eStr=0; + char sub_[2048]; + while((*p2>8&&*p2<14)||*p2==32) + { + p2++; + } + if(*p2==33) + { + asmFlag=!UmQt; + } + p=p2; + while(*p) + { + if(*p==9) + { + *p=32; + } + if(*p==34) + { + if(*(p-1)==69) + { + *(p-1)=1; + eStr=TRUE; + } + while(*(++p)!=34) + { + if(*p==92&&eStr) + { + *p=2; + for(;;) + { + if(*(p+1)==48) + { + *(p+1)=3; + break; + } + if(*(p+1)==116) + { + *(p+1)=4; + break; + } + if(*(p+1)==110) + { + *(p+1)=5; + break; + } + if(*(p+1)==114) + { + *(p+1)=6; + break; + } + if(*(p+1)==113) + { + *(p+1)=7; + break; + } + if(*(p+1)==92) + { + *(p+1)=8; + } + break; + } + p++; + } + if(*p==0) + { + UmQt=!UmQt; + break; + } + } + } + if(!UmQt&&!asmFlag) + { + if((*p BOR 32)==114) + { + if((*(p+1) BOR 32)==101&&(*(p+2) BOR 32)==109&&(*(p+3)==32||*(p+3)==0)) + { + if(p==p2||*(p-1)==58||*(p-1)==32) + { + *p=0; + break; + } + } + } + if(*p==39||(*p==47&&*(p+1)==47)) + { + *p=0; + break; + } + } + p++; + } + while(p28&&*(p-1)<14)||*(p-1)==32) + { + *(--p)=0; + } + if(UmQt||asmFlag) + { + break; + } + if(*(p-1)==58&&*(p-2)==32) + { + p--; + } + else + { + break; + } + } + if(eStr) + { + strcpy(p2,replace(p2,chr(1),"")); + strcpy(p2,replace(p2,chr(2),"")); + strcpy(sub_, join(3,DQ,"+CHR$(0)+",DQ)); + strcpy(p2,replace(p2,chr(3),sub_)); + strcpy(sub_, join(3,DQ,"+CHR$(9)+",DQ)); + strcpy(p2,replace(p2,chr(4),sub_)); + strcpy(sub_, join(3,DQ,"+CHR$(10)+",DQ)); + strcpy(p2,replace(p2,chr(5),sub_)); + strcpy(sub_, join(3,DQ,"+CHR$(13)+",DQ)); + strcpy(p2,replace(p2,chr(6),sub_)); + strcpy(sub_, join(3,DQ,"+CHR$(34)+",DQ)); + strcpy(p2,replace(p2,chr(7),sub_)); + strcpy(sub_, join(3,DQ,"+CHR$(92)+",DQ)); + strcpy(p2,replace(p2,chr(8),sub_)); + strcpy(p2,replace(p2,(join(3,chr(34),chr(34),chr(43))),"")); + strcpy(p2,replace(p2,(join(3,chr(43),chr(34),chr(34))),"")); + } + memcpy(Arg,p2,strlen(p2)+1); +} + + +void ProcSingleLineIf (int* ifFlag) +{ + char Tmp[2048]; + int ifp; + int NdIfs; + static int EFlag; + if((*ifFlag)==0) + { + EFlag=0; + } + +REDO:; + if(SplitCnt>120) + { + Abort("Stack Overflow - Too many statements on one line"); + } + strcpy(Tmp, join(2,SplitStk[SplitCnt],SPC)); + if(iMatchLft(Tmp,"if ")) + { + ifp=iMatchNQ(Tmp," then "); + if(ifp) + { + strcpy(SplitStk[SplitCnt++],left(Tmp,ifp+4)); + strcpy(SplitStk[SplitCnt],ltrim(Tmp+ifp+4)); + EFlag=_MAX_(0,EFlag-1); + (*ifFlag)++; + goto REDO; + } + } + else if((*ifFlag)) + { + if(iMatchLft(Tmp,"else ")) + { + +LFTLSE:; + if(++EFlag>1) + { + NdIfs=_MAX_(1,(*ifFlag)-1); + (*ifFlag)=1; + EFlag=0; + if(iMatchWrd(SplitStk[SplitCnt-1],"else")) + { + SplitCnt--; + } + {register int BCX_REPEAT; + for(BCX_REPEAT=1;BCX_REPEAT<=NdIfs;BCX_REPEAT++) + { + strcpy(SplitStk[SplitCnt++],"END IF"); + } + } + } + strcpy(SplitStk[SplitCnt++],"ELSE"); + strcpy(SplitStk[SplitCnt],trim(Tmp+4)); + goto REDO; + } + else + { + ifp=iMatchNQ(Tmp," else "); + if(ifp) + { + strcpy(SplitStk[SplitCnt++],rtrim(left(Tmp,ifp-1))); + strcpy(Tmp,mid(Tmp,ifp+1)); + goto LFTLSE; + } + } + } +} + + +int SplitLines (char *Arg) +{ + PCHAR p=Arg; + PCHAR st=Arg; + int i=0; + int IfFlag=0; + int SpcolonFlag=0; + int ParaCnt=0; + if(*p==33||*p==36) + { + return 0; + } + while(*p) + { + if(*p==32) + { + SpcolonFlag=1; + } + if(*p==34) + { + while(*(++p)!=34) + { + if(*p==0) + { + return SplitCnt; + } + } + } + if(*p==40) + { + ParaCnt++; + } + if(*p==41) + { + ParaCnt--; + } + if(*p==58&&*(p+1)!=61) + { + if(*(p+1)==58) + { + *p=-15; + *(p+1)=-15; + } + else + { + if(*(p+1)!=0||SpcolonFlag) + { + while(*st==32) + { + st++; + } + SplitCnt++; + while(st0) + { + while(*st==32) + { + st++; + } + SplitCnt++; + while(*st) + { + SplitStk[SplitCnt][i++]=*(st++); + } + SplitStk[SplitCnt][i]=0; + ProcSingleLineIf( &IfFlag); + } + else if(iMatchLft(Arg,"if ")&&!iMatchRgt(Arg," then")) + { + strcpy(SplitStk[++SplitCnt],Arg); + ProcSingleLineIf( &IfFlag); + } + if(IfFlag) + { + while(IfFlag) + { + strcpy(SplitStk[++SplitCnt],"END IF"); + IfFlag--; + } + } + return SplitCnt; +} + + +int iMatch (char *Arg, char *MatchStr, int mt) +{ + if(mt==2) + { + int L1; + int L2; + L1=strlen(Arg); + L2=strlen(MatchStr); + if(L11) + { + Abort(join(3,"UNKNOWN Word ",Stk[2]," After LOOP")); + } + } + break; + } + if(TRUE==iMatchLft(Arg,"do ")) + { + FastLexer(Arg," ",",()"); + if(iMatchLft(Stk[2],"until")) + { + strcpy(SrcStk[++SrcCnt],"do"); + strcpy(SrcStk[++SrcCnt],"if "); + for(i=3; i<=Ndx; i+=1) + { + strcpy(SrcStk[SrcCnt], join(3,SrcStk[SrcCnt],Stk[i]," ")); + } + strcpy(SrcStk[SrcCnt], join(2,SrcStk[SrcCnt],"then")); + strcpy(SrcStk[++SrcCnt],"exit loop"); + strcpy(SrcStk[++SrcCnt],"end if"); + goto PROCESSNEW; + } + else if(iMatchLft(Stk[2],"while")) + { + strcpy(SrcStk[++SrcCnt],"while "); + for(i=3; i<=Ndx; i+=1) + { + strcpy(SrcStk[SrcCnt], join(3,SrcStk[SrcCnt],Stk[i]," ")); + } + goto PROCESSNEW; + } + else + { + if(Ndx>1) + { + Abort(join(3,"UNKNOWN Word ",Stk[2]," After DO")); + } + } + } + break; + } + return 0; + +PROCESSNEW:; + Ndx=i=0; + while(SrcCnt) + { + strcpy(Arg,SrcStk[++i]); + *SrcStk[i]=0; + SrcCnt--; + Parse(Arg); + if(Ndx) + { + Emit(); + } + } + return TRUE; +} + + +void FastLexer (char * Arg,char * delim1,char * delim2,int TokQuote) +{ + int cnt1=0; + int cnt2=0; + PCHAR pd1; + PCHAR pd2; + Ndx=1; + while(Arg[cnt1]) + { + if(Arg[cnt1]==34) + { + if(cnt2&&TokQuote) + { + Stk[Ndx++][cnt2]=0; + cnt2=0; + } + Stk[Ndx][cnt2]=34; + while(Arg[++cnt1]!=34) + { + Stk[Ndx][++cnt2]=Arg[cnt1]; + if(Arg[cnt1]==0) + { + return; + } + } + Stk[Ndx][++cnt2]=Arg[cnt1]; + if(TokQuote) + { + Stk[Ndx++][++cnt2]=0; + cnt2=0; + goto AGAIN; + } + } + pd1=delim1; + while(*pd1) + { + if(*(pd1++)==Arg[cnt1]) + { + if(cnt2) + { + Stk[Ndx++][cnt2]=0; + cnt2=0; + } + goto AGAIN; + } + } + pd2=delim2; + while(*pd2) + { + if(*(pd2++)==Arg[cnt1]) + { + if(cnt2) + { + Stk[Ndx++][cnt2]=0; + } + Stk[Ndx][0]=Arg[cnt1]; + Stk[Ndx++][1]=0; + cnt2=0; + goto AGAIN; + } + } + Stk[Ndx][cnt2++]=Arg[cnt1]; + +AGAIN:; + cnt1++; + } + Stk[Ndx][cnt2]=0; + if(cnt2==0) + { + Ndx--; + } +} + + +void InsertTokens (int PosAfter, int NumTokens, ...) +{ + va_list ap; + int i; + for(i=Ndx; i>=PosAfter+1; i+=-1) + { + strcpy(Stk[i+NumTokens],Stk[i]); + } + va_start(ap,NumTokens); + for(i=PosAfter+1; i<=PosAfter+NumTokens; i+=1) + { + strcpy(Stk[i],va_arg(ap,char*)); + } + va_end(ap); + Ndx+=(NumTokens); +} + + +void EmitExportDef (char *fs) +{ + static int beenhere; + char fname[2048]; + char funcname[2048]; + int i; + int st=1; + int sz=0; + strcpy(fname, join(2,extract(FileIn,"."),".def")); + if(!beenhere) + { + if((fpdef=fopen(fname,"w"))==0) + { + fprintf(stderr,"Can't open file %s\n",fname); + exit(1); + } + _splitpath_(FileIn,NULL,NULL,fname,NULL); + fprintf(fpdef,"%s%s\n","LIBRARY ",enc(fname)); + fprintf(fpdef,"%s\n","EXPORTS"); + beenhere=TRUE; + } + FastLexer(fs,"","(,)"); + while(*Stk[st]!=40) + { + st++; + } + for(i=st+1; i<=Ndx; i+=1) + { + if(*Stk[i]==41) + { + break; + } + if(*Stk[i]!=44) + { + if(inchr(Stk[i],"*")) + { + sz+=(4); + continue; + } + if(instr_b(Stk[i],"longlong",1,1)||instr_b(Stk[i],"double",1,1)||instr_b(Stk[i],"long long")) + { + sz+=(8); + continue; + } + if(!inchr(Stk[i],"void")) + { + sz+=(4); + } + } + } + strcpy(Stk[1],trim(Stk[1])); + strcpy(funcname,mid(Stk[1],InstrRev(Stk[1]," ")+1)); + fprintf(fpdef,"%s%s%s%s%s\n",funcname," = _",funcname,"@",ltrim(str(sz))); +} + + +char * GetArg (int ArgNum, functionParse* fp) +{ + char *BCX_RetStr={0}; + char RetArg[2048]; + int ArgEnd=fp->CommaPos[ArgNum]-1; + int ArgStart=fp->CommaPos[ArgNum-1]+1; + *RetArg=0; + if(ArgNum>=fp->NumArgs) + { + ArgEnd=Ndx; + } + for(ArgStart=ArgStart; ArgStart<=ArgEnd; ArgStart+=1) + { + strcat(RetArg,Stk[ArgStart]); + } + BCX_RetStr=BCX_TmpStr(strlen(RetArg)); + strcpy(BCX_RetStr,RetArg); + return BCX_RetStr; +} + + +int SepFuncArgs (int Strt, functionParse* fp, int functionflag) +{ + int CountR=0; + int i=Strt; + if(functionflag) + { + while(i<=Ndx) + { + if(Stk[i][0]==40) + { + break; + } + i++; + } + Strt=i+1; + fp->NumArgs=0; + fp->CommaPos[0]=i; + if(Strt>Ndx) + { + return 0; + } + } + else + { + Strt=2; + fp->CommaPos[0]=1; + } + if(*Stk[Strt]==41) + { + fp->CommaPos[1]=Strt; + return 0; + } + fp->NumArgs=1; + for(i=Strt; i<=Ndx; i+=1) + { + if(*Stk[i]==40||*Stk[i]==91) + { + CountR++; + } + else if(*Stk[i]==41||*Stk[i]==93) + { + if(CountR==0) + { + fp->CommaPos[fp->NumArgs]=i; + break; + } + CountR--; + } + else if(*Stk[i]==44&&CountR==0) + { + fp->CommaPos[fp->NumArgs]=i; + fp->NumArgs++; + } + } + if(functionflag==0) + { + fp->CommaPos[fp->NumArgs]=Ndx; + } + return fp->NumArgs; +} + + +PCHAR MakeDecProto (functionParse* fp) +{ + functionParse fpp; + char FunType[2048]; + char AsType[2048]; + char AsArrys[2048]; + int FoundAs; + int pointer=0; + int i; + int ii; + char OptValue[2048]; + int OptFlag=0; + static char Proto[2048]; + static int SubFunPtr; + if(SubFunPtr) + { + goto ARGPARSE; + } + *Proto=0; + *FunType=0; + if(iMatchWrd(Stk[2],"sub")||iMatchWrd(Stk[2],"constructor")||iMatchWrd(Stk[2],"destructor")) + { + strcpy(FunType,"void"); + } + else if(*Stk[Ndx]==41) + { + strcpy(FunType,VarTypeLookup[inchr(VarTypes,right(Stk[3],1))]); + } + else + { + for(i=Ndx; i>=fp->CommaPos[fp->NumArgs]+1; i+=-1) + { + if(iMatchWrd(Stk[i],"ptr")) + { + pointer++; + } + else if(iMatchWrd(Stk[i],"as")) + { + break; + } + else + { + strcpy(FunType, join(3,Stk[i],SPC,FunType)); + } + } + } + if(InTypeDef) + { + if(iMatchWrd(Stk[2],"constructor")) + { + strcpy(Proto, join(2,Clean(Stk[3]),"(")); + } + else if(iMatchWrd(Stk[2],"destructor")) + { + strcpy(Proto, join(3,"~",Clean(Stk[3]),"(")); + } + else + { + strcpy(Proto, join(4,FunType," ",Clean(Stk[3]),"(")); + } + char Var[2048]; + int w; + int id; + int vt; + strcpy(Var, join(2,FunType,stringx(pointer,42))); + GetTypeInfo(Var, &w, &id, &vt); + AddTypedefElement(BaseTypeDefsCnt[InTypeDef],vt,Clean(Stk[3]),FunType,0); + } + else if(SFPOINTER) + { + strcpy(Proto, join(7,"typedef ",FunType," (",CallType,"*",Clean(Stk[3]),"_TYPE)(")); + } + else if(!NoTypeDeclare) + { + strcpy(Proto, join(7,"typedef ",FunType," (",CallType,"*BCXFPROT",ltrim(str(DllCnt)),")(")); + } + else + { + if(UseCProto) + { + UseCProto=FALSE; + strcpy(Proto, join(7,FunType," ",stringx(pointer,42),SPC,CallType,Clean(Stk[3]),"(")); + } + else + { + strcpy(Proto, join(8,"C_IMPORT ",FunType," ",stringx(pointer,42),SPC,CallType,Clean(Stk[3]),"(")); + } + } + +ARGPARSE:; + if(fp->NumArgs==0) + { + if(iMatchWrd(Stk[2],"destructor")||iMatchWrd(Stk[2],"constructor")||Use_Virtual) + { + strcat(Proto,")"); + } + else + { + strcat(Proto,"void)"); + } + } + else + { + for(ii=0; ii<=fp->NumArgs-1; ii+=1) + { + *OptValue=0; + *AsType=0; + *AsArrys=0; + pointer=0; + FoundAs=0; + int FirstToken=fp->CommaPos[ii]+1; + int LastToken=fp->CommaPos[ii+1]-1; + int NumOfTokens=(LastToken-FirstToken)+1; + i=inchr(Stk[FirstToken],"["); + if(i) + { + strcpy(AsArrys,mid(Stk[FirstToken],i)); + Stk[FirstToken][i-1]=0; + } + if(NumOfTokens==1) + { + strcpy(AsType,VarTypeLookup[inchr(VarTypes,right(Stk[FirstToken],1))]); + if(*AsArrys) + { + strcpy(AsType,RemoveStr(AsType,"*")); + } + else + { + pointer=tally(Stk[FirstToken],"*"); + } + FoundAs=TRUE; + } + else + { + for(i=LastToken; i>=FirstToken; i+=-1) + { + if(iMatchWrd(Stk[i],"ptr")||*Stk[i]==42) + { + pointer++; + } + else if(iMatchWrd(Stk[i],"sub")) + { + SepFuncArgs(fp->CommaPos[ii]+2, &fpp,TRUE); + strcat(Proto,"void (*)("); + SubFunPtr=FoundAs=TRUE; + MakeDecProto( &fpp); + SubFunPtr=FALSE; + break; + } + else if(iMatchWrd(Stk[i],"function")) + { + SepFuncArgs(fp->CommaPos[ii]+2, &fpp,TRUE); + if(AsType[0]==0) + { + strcpy(AsType,VarTypeLookup[inchr(VarTypes,right(Stk[FirstToken],1))]); + } + strcpy(Proto, join(4,Proto,rtrim(AsType),stringx(pointer,42)," (*)(")); + pointer=0; + *AsType=0; + SubFunPtr=FoundAs=TRUE; + MakeDecProto( &fpp); + SubFunPtr=FALSE; + break; + } + else if(iMatchWrd(Stk[i],"as")) + { + if(AsType[0]==0) + { + Abort(join(2,"No type specified for argument",str(ii+1))); + } + FoundAs=TRUE; + break; + } + else if(*Stk[i]==61) + { + OptFlag=FoundAs=TRUE; + strcpy(OptValue, join(2," =",AsType)); + *AsType=0; + if(i==FirstToken+1) + { + strcpy(AsType,VarTypeLookup[inchr(VarTypes,right(Stk[FirstToken],1))]); + if(*AsArrys) + { + strcpy(AsType,RemoveStr(AsType,"*")); + } + else + { + pointer=tally(Stk[FirstToken],"*"); + } + break; + } + } + else + { + if(*Stk[i]!=46) + { + strcpy(AsType, join(3,Stk[i],SPC,AsType)); + } + else + { + if(*Stk[i-1]==46) + { + if(OptFlag) + { + Abort("Default value not allowed when using variable arguments"); + } + if(ii!=(fp->NumArgs-1)) + { + Abort("Variable argument must be the last parameter"); + } + if(fp->NumArgs==1) + { + Abort("Variable argument must be preceded by at least one other parameter"); + } + FoundAs=TRUE; + } + strcpy(AsType, join(2,Stk[i],AsType)); + } + } + } + } + if(!FoundAs) + { + Abort(join(2,"Malformed argument type in parameter",str(ii+1))); + } + if(ii!=fp->NumArgs&&OptFlag&&str_cmp(OptValue,"")==0) + { + Warning(join(2,"No default value specified for parameter",str(ii+1)),1); + } + strcpy(Proto, join(6,Proto,rtrim(AsType),AsArrys,stringx(pointer,42),OptValue,Stk[fp->CommaPos[ii+1]])); + } + } + return Proto; +} + + +void AsmUnknownStructs (int CompArrays) +{ + int InBrace=0; + int InStruct=0; + int i; + char sztemp[2048]; + for(i=2; i<=Ndx; i+=1) + { + if(CompArrays) + { + if(str_cmp(Stk[i],"[")==0) + { + strcpy(sztemp,Stk[i-1]); + *Stk[i-1]=0; + for(;;) + { + strcat(sztemp,Stk[i]); + if(str_cmp(Stk[i],"]")==0) + { + InBrace--; + } + if(str_cmp(Stk[i],"[")==0) + { + InBrace++; + } + *Stk[i]=0; + i++; + if(!(InBrace&&i<=Ndx)) + { + break; + } + } + strcpy(Stk[--i],sztemp); + } + } + if(strlen(Stk[i])>1&&!IsNumber(Stk[i]+1)) + { + if(*Stk[i]==46||iMatchLft(Stk[i],"->")) + { + if(InStruct==0) + { + strcpy(Stk[i], join(2,Stk[i-1],Stk[i])); + *Stk[i-1]=0; + InStruct=i; + } + else + { + strcat(Stk[InStruct],Stk[i]); + *Stk[i]=0; + } + continue; + } + } + if(*Stk[i]&&InStruct>0) + { + InStruct=0; + } + } + RemEmptyTokens(); +} + + +void EmitIfCond (char *CondType) +{ + int TestString; + int A; + int B; + int ParCnt; + int Tmp; + int IsWhile=FALSE; + char szTest[2048]; + TestString=DataType(Stk[2]); + if(TestString==vt_STRVAR) + { + if(str_cmp(Stk[4],DDQ)==0) + { + strcpy(Stk[2], join(2,Clean(Stk[2]),"[0]")); + strcpy(Stk[4],"0"); + } + else if(str_cmp(Stk[3],"[")==0 && str_cmp(Stk[7],DDQ)==0) + { + strcpy(Stk[2],Clean(Stk[2])); + strcat(Stk[5],"[0]"); + strcpy(Stk[7],"0"); + } + } + if(str_cmp(CondType,"while")==0) + { + IsWhile=TRUE; + } + fprintf(Outfile,"%s%s%s",Scoot,CondType,"("); + Tmp=2; + while(str_cmp(Stk[Tmp],"(")==0 || str_cmp(Stk[Tmp],"!")==0) + { + fprintf(Outfile,"%s",Stk[Tmp]); + Tmp++; + } + TestString=FALSE; + A=DataType(Stk[Tmp]); + if(A==vt_STRLIT||A==vt_STRVAR) + { + if(str_cmp(Stk[Tmp+1],")")!=0 && !iMatchWrd(Stk[Tmp+1],"then")) + { + TestString=TRUE; + Use_Str_Cmp=TRUE; + fprintf(Outfile,"%s","str_cmp("); + } + } + *szTest=0; + ParCnt=0; + for(;;) + { + if(TestString) + { + if(str_cmp(Stk[Tmp],"=")==0) + { + strcpy(Stk[Tmp],","); + strcpy(szTest,")==0"); + ParCnt=0; + } + else if(str_cmp(Stk[Tmp],"!=")==0) + { + strcpy(Stk[Tmp],","); + strcpy(szTest,")!=0"); + ParCnt=0; + } + else if(str_cmp(Stk[Tmp],">")==0) + { + if(str_cmp(Stk[Tmp+1],"=")==0) + { + strcpy(Stk[Tmp],","); + strcpy(szTest,")>=0"); + *Stk[Tmp+1]=0; + } + else + { + strcpy(Stk[Tmp],","); + strcpy(szTest,")==1"); + } + ParCnt=0; + } + else if(str_cmp(Stk[Tmp],"<")==0) + { + if(str_cmp(Stk[Tmp+1],"=")==0) + { + strcpy(Stk[Tmp],","); + strcpy(szTest,")<=0"); + *Stk[Tmp+1]=0; + } + else + { + strcpy(Stk[Tmp],","); + strcpy(szTest,")==-1"); + } + ParCnt=0; + } + else if(str_cmp(Stk[Tmp],"(")==0) + { + ParCnt++; + } + else if(str_cmp(Stk[Tmp],")")==0) + { + ParCnt--; + } + if(str_cmp(Stk[Tmp],")")==0 && str_cmp(szTest,"")!=0 && ParCnt<0) + { + fprintf(Outfile,"%s%s",szTest,Stk[Tmp]); + *szTest=0; + } + else + { + if(str_cmp(Stk[Tmp],"||")==0 || str_cmp(Stk[Tmp],"&&")==0) + { + strcpy(Stk[Tmp], join(4,szTest," ",Stk[Tmp]," ")); + *szTest=0; + B=1; + while(str_cmp(Stk[Tmp+B],"(")==0) + { + strcat(Stk[Tmp],"("); + *Stk[Tmp+B]=0; + B++; + } + A=DataType(Stk[Tmp+B]); + if((A==vt_STRLIT||A==vt_STRVAR)&&str_cmp(Stk[Tmp+B+1],")")!=0) + { + strcat(Stk[Tmp]," str_cmp("); + Use_Str_Cmp=TRUE; + } + else + { + fprintf(Outfile,"%s",Clean(Stk[Tmp])); + TestString=FALSE; + goto NXTTOKEN; + } + } + fprintf(Outfile,"%s",Clean(Stk[Tmp])); + } + } + else + { + if(str_cmp(Stk[Tmp],"||")==0 || str_cmp(Stk[Tmp],"&&")==0) + { + B=1; + while(str_cmp(Stk[Tmp+B],"(")==0) + { + strcat(Stk[Tmp],"("); + *Stk[Tmp+B]=0; + B++; + } + A=DataType(Stk[Tmp+B]); + if((A==vt_STRLIT||A==vt_STRVAR)&&str_cmp(Stk[Tmp+B+1],")")!=0) + { + strcat(Stk[Tmp],"str_cmp("); + TestString=TRUE; + Use_Str_Cmp=TRUE; + *szTest=0; + ParCnt=0; + fprintf(Outfile,"%s",Clean(Stk[Tmp])); + goto NXTTOKEN; + } + } + if(str_cmp(Stk[Tmp],"!")==0) + { + fprintf(Outfile,"%s",Stk[Tmp]); + } + else + { + fprintf(Outfile,"%s",Clean(Stk[Tmp])); + } + if(str_cmp(Stk[Tmp],"=")==0) + { + if(str_cmp(Stk[Tmp-1],"<")!=0 && str_cmp(Stk[Tmp-1],">")!=0) + { + if(str_cmp(Stk[Tmp+1],">")!=0 && str_cmp(Stk[Tmp+1],"<")!=0) + { + fprintf(Outfile,"%s","="); + } + } + } + } + +NXTTOKEN:; + Tmp++; + if(!IsWhile) + { + if(iMatchWrd(Stk[Tmp],"then")) + { + break; + } + else if(Tmp>Ndx) + { + Abort("If Without THEN"); + } + } + if(Tmp>Ndx) + { + break; + } + } + fprintf(Outfile,"%s%s\n",szTest,")"); + BumpUp(); + fprintf(Outfile,"%s%s\n",Scoot,"{"); + BumpUp(); +} + + +void PrintGlobal (int A, int idx, char *Storage, char *P, char *VarName, char *VarDim) +{ + char VAR[2048]; + for(;;) + { + if(A==vt_FILEPTR) + { + strcpy(VarName,RemoveStr(VarName,"@")); + fprintf(Outfile,"%s%s%s%s%s%s\n",Storage,"FILE *",P,VarName,VarDim,";"); + break; + } + if(A==vt_UDT||A==vt_STRUCT||A==vt_UNION) + { + strcpy(VAR,TypeDefs[GlobalVars[idx].VarDef].VarName); + strcpy(VAR,rpad(VAR,7)); + fprintf(Outfile,"%s%s%s%s%s%s%s\n",Storage,VAR," ",P,VarName,VarDim,";"); + break; + } + if(A==vt_BOOL) + { + fprintf(Outfile,"%s%s%s%s%s\n",Storage,"bool ",VarName,VarDim,";"); + break; + } + if(A==vt_STRVAR) + { + if(VarDim[0]==0) + { + strcpy(VarDim,"[65535]"); + } + fprintf(Outfile,"%s%s%s%s%s%s\n",Storage,"char ",P,VarName,VarDim,";"); + break; + } + if(A>=vt_VarMin&&A<=vt_VarMax) + { + strcpy(VAR,GetVarTypeName(GlobalVars[idx].VarType)); + strcpy(VAR,rpad(VAR,7)); + fprintf(Outfile,"%s%s%s%s%s%s%s\n",Storage,VAR," ",P,VarName,VarDim,";"); + } + break; + } +} + + +void ReDirectFPrint (FILE* TgtFile, char *pat, ...) +{ + va_list ap; + if(DoCountLines&&TgtFile==FP3) + { + gLinesWritten++; + } + va_start(ap,pat); + vfprintf(TgtFile,pat,ap); + va_end(ap); +} + + +int IsReservedWord (char *match) +{ + char mat[2048]; + strcpy(mat,ucase(match)); + if(containedin(mat,ReservedWord)==0) + { + return 1; + } + return 0; +} + + +int GetAsPos (void) +{ + int i; + for(i=Ndx; i>=2; i+=-1) + { + if(iMatchWrd(Stk[i],"as")) + { + return i; + } + } + return 0; +} + + +void FreeGlobals (void) +{ + if(RmLibs)free(RmLibs); + if(WarnMsg)free(WarnMsg); + if(AbortSrc)free(AbortSrc); + if(Src)free(Src); + if(szTmp)free(szTmp); +} + + diff --git a/runtime.bas b/runtime.bas new file mode 100644 index 0000000..751c130 --- /dev/null +++ b/runtime.bas @@ -0,0 +1,2357 @@ +SUB RunTimeFunctions + LOCAL X1$ + LOCAL O1$ ' "%o" + LOCAL D1$ ' "%.15G" + LOCAL D2$ ' "%.19LG" + LOCAL T0$ ' "%H:%M:%S" + LOCAL T1$ ' "%H" + LOCAL T2$ ' "%M" + LOCAL T3$ ' "%S" + LOCAL T4$ ' "%p" + LOCAL T5$ ' "%Y" + LOCAL T6$ ' "%m" + LOCAL T7$ ' "%d" + LOCAL T8$ ' "%A" + LOCAL T9$ ' "%w" + LOCAL T10$ ' "%j" + LOCAL T11$ ' "%V" [ISO week date standard (ISO-8601)] + LOCAL T12$ ' "%m/%d/%y" + LOCAL T13$ ' %A, %B %d, %Y [DAY OF WEEK, MONTH NAME, DAY, FULL YEAR] + LOCAL TDIR$ + D1$ = VCHR$(8,34,37,32,46,49,53,71,34) + D2$ = VCHR$(9,34,37,32,46,49,57,76,71,34) + O1$ = VCHR$(4,34,37,111,34) + T0$ = VCHR$(10,34,37,72,58,37,77,58,37,83,34) + T1$ = VCHR$(4,34,37, 72,34) + T2$ = VCHR$(4,34,37, 77,34) + T3$ = VCHR$(4,34,37, 83,34) + T4$ = VCHR$(4,34,37,112,34) + T5$ = VCHR$(4,34,37, 89,34) + T6$ = VCHR$(4,34,37,109,34) + T7$ = VCHR$(4,34,37,100,34) + T8$ = VCHR$(4,34,37, 65,34) + T9$ = VCHR$(4,34,37,119,34) + T10$ = VCHR$(4,34,37,106,34) + T11$ = VCHR$(4,34,37, 86,34) + T12$ = VCHR$(10,34,37,109,47,37,100,47,37,121,34) + T13$ = VCHR$(15,34,37,65,44,32,37,66,32,37,100,44,32,37,89,34) + X1$ = VCHR$(4,34,37,88,34) + TDIR$= ENC$("/tmp/mbc.XXXXXXXX") + 'U1$ = VCHR$(7,37,39,42,46,42,32,102) + + + FPRINT Outfile,"" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// " + $BCX_STR_RUNTIME + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"" + +IF NoRT=TRUE THEN EXIT SUB + + IF UseFlag THEN + IF Use_Turbo THEN + FPRINT Outfile,"char *BCX_TmpStr (size_t Bites)" + FPRINT Outfile,"{" + FPRINT Outfile," static int StrCnt;" + FPRINT Outfile," static char *StrFunc[",TurboSize,"];" + FPRINT Outfile," StrCnt=((StrCnt+1) &",TurboSize-1,");" + + FPRINT Outfile," #if defined BCX_MAX_VAR_SIZE" + FPRINT Outfile," if(Bites*sizeof(char)>BCX_MAX_VAR_SIZE)" + FPRINT Outfile," {" + FPRINT Outfile," printf(";ENC$("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\\n");",(int)(Bites*sizeof(char)),BCX_MAX_VAR_SIZE);" + FPRINT Outfile," abort();" + FPRINT Outfile," }" + FPRINT Outfile," #endif" + + FPRINT Outfile," StrFunc[StrCnt]=(char*)realloc(StrFunc[StrCnt],Bites + 128);" + FPRINT Outfile," return (char*)memset(StrFunc[StrCnt],0,Bites+128);" + FPRINT Outfile,"}\n\n" + ELSE + FPRINT Outfile,"char *BCX_TmpStr (size_t Bites)" + FPRINT Outfile,"{" + FPRINT Outfile," static int StrCnt;" + FPRINT Outfile," static char *StrFunc[65535];" + FPRINT Outfile," StrCnt=(StrCnt + 1) & 65535;" + FPRINT Outfile," if(StrFunc[StrCnt]) free (StrFunc[StrCnt]);" + FPRINT Outfile," #if defined BCX_MAX_VAR_SIZE" + FPRINT Outfile," if(Bites*sizeof(char)>BCX_MAX_VAR_SIZE)" + FPRINT Outfile," {" + FPRINT Outfile," printf(",ENC$("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\\n"),",(int)(Bites*sizeof(char)),BCX_MAX_VAR_SIZE);" + FPRINT Outfile," abort();" + FPRINT Outfile," }" + FPRINT Outfile," #endif" + + FPRINT Outfile," return StrFunc[StrCnt]=(char*)calloc(Bites+128,sizeof(char));" + FPRINT Outfile,"}\n\n" + END IF + END IF + + IF Use_CopyFile THEN + FPRINT Outfile,"void CopyFile (char *InFile,char *TmpFile,int OverWrite)" + FPRINT Outfile,"{" + FPRINT Outfile," #define BLOCKCOPYSIZE (10 * 1000*1024)" + FPRINT Outfile," char* tmp=0;" + FPRINT Outfile," UINT blocks=1;" + FPRINT Outfile," UINT overage=0;" + FPRINT Outfile," UINT i;" + FPRINT Outfile," FILE *FP1,*FP2;" + FPRINT Outfile," if(!OverWrite)" + FPRINT Outfile," {" + FPRINT Outfile," if(Exist(TmpFile)) return;" + FPRINT Outfile," }" + FPRINT Outfile," if(Exist(InFile))" + FPRINT Outfile," {" + FPRINT Outfile," UINT length = lof(InFile);" + FPRINT Outfile," if(length > BLOCKCOPYSIZE)" + FPRINT Outfile," {" + FPRINT Outfile," blocks = length/BLOCKCOPYSIZE;" + FPRINT Outfile," overage= length % BLOCKCOPYSIZE;" + FPRINT Outfile," length = BLOCKCOPYSIZE;" + FPRINT Outfile," }" + FPRINT Outfile,"" + FPRINT Outfile," tmp=(char*)calloc(16+length,1);" + FPRINT Outfile,"" + FPRINT Outfile," if((FP1=fopen(InFile,",ENC$("rb"),"))==0)" + FPRINT Outfile," {" + FPRINT Outfile," fprintf(stderr,",ENC$("Can't open file %s\\n"),",InFile);" + FPRINT Outfile," exit(1);" + FPRINT Outfile," }" + FPRINT Outfile," if((FP2=fopen(TmpFile,",ENC$("wb+"),"))==0)" + FPRINT Outfile," {" + FPRINT Outfile," fprintf(stderr,",ENC$("Can't open file %s\\n"),",TmpFile);" + FPRINT Outfile," exit(1);" + FPRINT Outfile," }" + FPRINT Outfile," for(i=0; i0)" + FPRINT Outfile," {" + FPRINT Outfile," fread(tmp,1,overage,FP1);" + FPRINT Outfile," fwrite(tmp,1,overage,FP2);" + FPRINT Outfile," }" + FPRINT Outfile," fclose(FP2); fclose(FP1);" + FPRINT Outfile," if(tmp) free(tmp);" + FPRINT Outfile," struct stat st;" + FPRINT Outfile," if(stat(InFile, &st) != -1)" + FPRINT Outfile," chmod(TmpFile,st.st_mode);" + FPRINT Outfile," }" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Str_Cmp THEN + FPRINT Outfile,"int str_cmp (char *a, char *b)" + FPRINT Outfile,"{" + FPRINT Outfile," int counter=0;" + FPRINT Outfile," for(;;)" + FPRINT Outfile," {" + FPRINT Outfile," if((a[counter]^b[counter]))" + FPRINT Outfile," {" + FPRINT Outfile," if((UINT) a[counter]>= (UINT) b[counter])" + FPRINT Outfile," return 1;" + FPRINT Outfile," return -1;" + FPRINT Outfile," }" + FPRINT Outfile," if(!a[counter]) return 0;" + FPRINT Outfile," counter++;" + FPRINT Outfile," }" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Eof THEN + FPRINT Outfile,"int EoF (FILE* stream)" + FPRINT Outfile,"{" + FPRINT Outfile," register int c, status = ((c = fgetc(stream)) == EOF);" + FPRINT Outfile," ungetc(c,stream);" + FPRINT Outfile," return status;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Cint THEN + FPRINT Outfile,"int Cint (double A)" + FPRINT Outfile,"{" + FPRINT Outfile," return (A >=0 ? (int)(A+0.5) : (int)(A-0.5));" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Clng THEN + FPRINT Outfile,"long CLNG (double A)" + FPRINT Outfile,"{" + FPRINT Outfile," float r=.5;" + FPRINT Outfile," double a=A-(long)A;" + FPRINT Outfile," if(A<0) { r=-.5; a=-a; }" + FPRINT Outfile," if(((long)A % 2)==0&&a<=.5)" + FPRINT Outfile," return (long)A;" + FPRINT Outfile," else" + FPRINT Outfile," return (long)(A+r);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Left THEN + FPRINT Outfile,"char *left (char *S, int length)" + FPRINT Outfile,"{" + FPRINT Outfile," int tmplen = strlen(S);" + FPRINT Outfile," if(length<1) return BCX_TmpStr(1);" + FPRINT Outfile," if(lengthtmplen||start<1) return BCX_TmpStr(1);" + FPRINT Outfile," if (length<0 || length>(tmplen-start)+1)" + FPRINT Outfile," length = (tmplen-start)+1;" + FPRINT Outfile," strtmp = BCX_TmpStr(length);" + FPRINT Outfile," return (char*)memcpy(strtmp,&S[start-1],length);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Trim THEN + FPRINT Outfile,"char *trim (char *S)" + FPRINT Outfile,"{" + FPRINT Outfile," while(*S==32 || *S==9 || *S==10 || *S==11 || *S==13)" + ' tab ,carriage return, vertical tab, newline, space + FPRINT Outfile," S++;" + FPRINT Outfile," int i = strlen(S);" + FPRINT Outfile," while( i>0 && (S[i-1]==32 || S[i-1]==9 || S[i-1]==10" + FPRINT Outfile," || S[i-1]==11 || S[i-1]==13))" + FPRINT Outfile," i--;" + FPRINT Outfile," char *strtmp=BCX_TmpStr(i);" + FPRINT Outfile," return (char*)memcpy(strtmp,S,i);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Ltrim THEN + FPRINT Outfile,"char *ltrim (char *S, char c)" + FPRINT Outfile,"{" + FPRINT Outfile," if(S[0]==0) return S;" + FPRINT Outfile," while((*S==32 || *S==c) && *S !=0) S++;" + FPRINT Outfile," char *strtmp = BCX_TmpStr(strlen(S));" + FPRINT Outfile," return strcpy(strtmp,S);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Rtrim THEN + FPRINT Outfile,"char *rtrim (char *S,char c)" + FPRINT Outfile,"{" + FPRINT Outfile," if(S[0]==0) return S;" + FPRINT Outfile," int i = strlen(S);" + FPRINT Outfile," while(i>0 && (S[i-1]==c || S[i-1]==32))" + FPRINT Outfile," i--;" + FPRINT Outfile," char *strtmp = BCX_TmpStr(i);" + FPRINT Outfile," return (char*)memcpy(strtmp,S,i);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Strim THEN + FPRINT Outfile,"char *strim (char *src)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(strlen(src));" + FPRINT Outfile," char *dst = strtmp;" + FPRINT Outfile," while (isspace((unsigned char)*src)) src++;" + FPRINT Outfile," do" + FPRINT Outfile," {" + FPRINT Outfile," while (*src && !isspace((unsigned char)*src)) *dst++ = *src++;" + FPRINT Outfile," if (*src)" + FPRINT Outfile," {" + FPRINT Outfile," *dst++ = *src++;" + FPRINT Outfile," while (isspace((unsigned char)*src)) src++;" + FPRINT Outfile," }" + FPRINT Outfile," } while (*src);" + FPRINT Outfile," if (isspace((unsigned char)*(--dst))) *dst = 0;" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Command THEN + FPRINT Outfile,"char *command (int nArg)" + FPRINT Outfile," {" + FPRINT Outfile," int i = 0;" + FPRINT Outfile," char *retstr=BCX_TmpStr(1);" + FPRINT Outfile," if(nArg < i) // return entire commandline" + FPRINT Outfile," {" + FPRINT Outfile," retstr = BCX_TmpStr(G_argc * 2048);" + FPRINT Outfile," for(i=1; i < G_argc; i++)" + FPRINT Outfile," {" + FPRINT Outfile," strcat(retstr, G_argv[i]);" + FPRINT Outfile," strcat(retstr, SPC);" + FPRINT Outfile," }" + FPRINT Outfile," }" + FPRINT Outfile," else if(nArg < G_argc)" + FPRINT Outfile," {" + FPRINT Outfile," retstr = BCX_TmpStr(strlen(G_argv[nArg]) + 1);" + FPRINT Outfile," strcpy(retstr, G_argv[nArg]);" + FPRINT Outfile," }" + FPRINT Outfile," return retstr;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Extract THEN + FPRINT Outfile,"char *extract (char *mane, char *match)" + FPRINT Outfile,"{" + FPRINT Outfile," char *a;" + FPRINT Outfile," char *strtmp = BCX_TmpStr(strlen(mane));" + FPRINT Outfile," if(*match!=0)" + FPRINT Outfile," {" + FPRINT Outfile," a=_strstr_(mane,match);" + FPRINT Outfile," if(a) return (char*)memcpy(strtmp,mane,a-mane);" + FPRINT Outfile," }" + FPRINT Outfile," return strcpy(strtmp,mane);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Remain THEN + FPRINT Outfile,"char *remain (char *mane, char *mat)" + FPRINT Outfile,"{" + FPRINT Outfile," char *p = strstr(mane,mat);" + FPRINT Outfile," if(p)" + FPRINT Outfile," {" + FPRINT Outfile," p+=(strlen(mat));" + FPRINT Outfile," return p;" + FPRINT Outfile," }" + FPRINT Outfile," return mane;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Replace THEN + FPRINT Outfile,"char *replace (char *src, char *pat, char *rep)" + FPRINT Outfile,"{" + FPRINT Outfile," size_t patsz, repsz, tmpsz, delta;" + FPRINT Outfile," char *strtmp, *p, *q, *r;" + FPRINT Outfile," if (!pat || !*pat)" + FPRINT Outfile," {" + FPRINT Outfile," strtmp = BCX_TmpStr(strlen(src));" + FPRINT Outfile," if (!strtmp) return NULL;" + FPRINT Outfile," return strcpy(strtmp, src);" + FPRINT Outfile," }" + FPRINT Outfile," repsz = strlen(rep);" + FPRINT Outfile," patsz = strlen(pat);" + FPRINT Outfile," for (tmpsz=0, p=src; (q=_strstr_(p,pat))!=0; p=q+patsz)" + FPRINT Outfile," tmpsz += (size_t) (q - p) + repsz;" + FPRINT Outfile," tmpsz += strlen(p);" + FPRINT Outfile," strtmp = BCX_TmpStr(tmpsz);" + FPRINT Outfile," if (!strtmp) return NULL;" + FPRINT Outfile," for (r=strtmp,p=src; (q=_strstr_(p,pat))!=0;p=q+patsz)" + FPRINT Outfile," {" + FPRINT Outfile," delta = (size_t) (q-p);" + FPRINT Outfile," memcpy(r,p,delta); r += delta;" + FPRINT Outfile," strcpy(r,rep); r += repsz;" + FPRINT Outfile," }" + FPRINT Outfile," strcpy(r,p);" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Reverse THEN + FPRINT Outfile,"char *reverse (char *s)" + FPRINT Outfile,"{" + FPRINT Outfile," int j=strlen(s);" + FPRINT Outfile," char *rstr = BCX_TmpStr(j);" + FPRINT Outfile," while(j) rstr[--j] = *(s++);" + FPRINT Outfile," return rstr;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Findfirst THEN + FPRINT Outfile,"char *findfirst (char *filespec, FILE_FIND_DATA *FindData)" + FPRINT Outfile,"{" + FPRINT Outfile," struct dirent *dp;" + FPRINT Outfile," struct stat st;" + FPRINT Outfile,"" + FPRINT Outfile," if(FindData->FileHandle)" + FPRINT Outfile," closedir(FindData->FileHandle);" + FPRINT Outfile,"" + FPRINT Outfile," strcpy(FindData->path, BcxSplitPath(filespec, FDRV|FPATH));" + FPRINT Outfile," strcpy(FindData->cFileSpec,BcxSplitPath(filespec, FNAME|FEXT));" + FPRINT Outfile," if(*FindData->path==0) strcpy(FindData->path, ",ENC$("."),");" + FPRINT Outfile,"" + FPRINT Outfile," FindData->FileHandle=opendir(FindData->path);" + FPRINT Outfile,"" + FPRINT Outfile," while(FindData->FileHandle)" + FPRINT Outfile," {" + FPRINT Outfile," dp=readdir(FindData->FileHandle);" + FPRINT Outfile," if(dp==NULL) break;" + FPRINT Outfile,"" + FPRINT Outfile," if(like(dp->d_name,FindData->cFileSpec))" + FPRINT Outfile," {" + FPRINT Outfile," strcpy(FindData->cFileName,dp->d_name);" + FPRINT Outfile," lstat(join(2,FindData->path,dp->d_name), &st);" + FPRINT Outfile," FindData->dwFileAttributes = st.st_mode;" + FPRINT Outfile," return FindData->cFileName;" + FPRINT Outfile," }" + FPRINT Outfile," }" + FPRINT Outfile,"" + FPRINT Outfile," *FindData->cFileName=0;" + FPRINT Outfile," return FindData->cFileName;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Findnext THEN + FPRINT Outfile,"char *findnext (FILE_FIND_DATA *FindData)" + FPRINT Outfile,"{" + FPRINT Outfile," struct dirent *dp;" + FPRINT Outfile," struct stat st;" + FPRINT Outfile,"" + FPRINT Outfile," while(FindData->FileHandle)" + FPRINT Outfile," {" + FPRINT Outfile," dp=readdir(FindData->FileHandle);" + FPRINT Outfile," if(dp==NULL) break;" + FPRINT Outfile,"" + FPRINT Outfile," if(like(dp->d_name,FindData->cFileSpec))" + FPRINT Outfile," {" + FPRINT Outfile," strcpy(FindData->cFileName,dp->d_name);" + FPRINT Outfile," lstat(join(2,FindData->path,dp->d_name), &st);" + FPRINT Outfile," FindData->dwFileAttributes = st.st_mode;" + FPRINT Outfile," return FindData->cFileName;" + FPRINT Outfile," }" + FPRINT Outfile," }" + FPRINT Outfile,"" + FPRINT Outfile," *FindData->cFileName=0;" + FPRINT Outfile," return FindData->cFileName;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Ucase THEN + FPRINT Outfile,"char *ucase (char *S)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(strlen(S));" + FPRINT Outfile," return _strupr_(strcpy(strtmp,S));" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Lcase THEN + FPRINT Outfile,"char *lcase (char *S)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(strlen(S));" + FPRINT Outfile," return _strlwr_(strcpy(strtmp,S));" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Mcase THEN + FPRINT Outfile,"char *mcase (char *S)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(strlen(S)+1);" + FPRINT Outfile," char *s = strtmp;" + FPRINT Outfile," _strlwr_(strcpy(strtmp,S));" + FPRINT Outfile," while(*s)" + FPRINT Outfile," {" + FPRINT Outfile," if(islower(*s))" + FPRINT Outfile," {" + FPRINT Outfile," *s-=32;" + FPRINT Outfile," while(isalpha(*++s));" + FPRINT Outfile," }" + FPRINT Outfile," s++;" + FPRINT Outfile," }" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Remove THEN + FPRINT Outfile,"char *RemoveStr (char *a, char *b)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp, *p, *d;" + FPRINT Outfile," int tmplen;" + FPRINT Outfile," strtmp = d = BCX_TmpStr(strlen(a));" + FPRINT Outfile," if(!b || !*b) return strcpy(strtmp,a);" + FPRINT Outfile," p=_strstr_(a,b); tmplen = strlen(b);" + FPRINT Outfile," while(p)" + FPRINT Outfile," {" + FPRINT Outfile," memcpy(d,a,p-a);" + FPRINT Outfile," d+= (p-a);" + FPRINT Outfile," a=p+tmplen;" + FPRINT Outfile," p=_strstr_(a,b);" + FPRINT Outfile," }" + FPRINT Outfile," strcpy(d,a);" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_IRemove THEN + FPRINT Outfile,"char *IRemoveStr (char *a, char *b)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp, *p, *d;" + FPRINT Outfile," int tmplen;" + FPRINT Outfile," strtmp = d = BCX_TmpStr(strlen(a));" + FPRINT Outfile," if(!b || !*b) return strcpy(strtmp,a);" + FPRINT Outfile," p=_stristr_(a,b); tmplen = strlen(b);" + FPRINT Outfile," while(p)" + FPRINT Outfile," {" + FPRINT Outfile," memcpy(d,a,p-a);" + FPRINT Outfile," d+= (p-a);" + FPRINT Outfile," a=p+tmplen;" + FPRINT Outfile," p=_stristr_(a,b);" + FPRINT Outfile," }" + FPRINT Outfile," strcpy(d,a);" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Ins THEN + FPRINT Outfile,"char *ins (char *S, int i, char *a)" + FPRINT Outfile,"{" + FPRINT Outfile," int j = strlen(S);" + FPRINT Outfile," if(i<1 || i>j+1) return S;" + FPRINT Outfile," char *strtmp = BCX_TmpStr(j + strlen(a));" + FPRINT Outfile," memcpy(strtmp,S,--i);" + FPRINT Outfile," strcpy(&strtmp[i],a);" + FPRINT Outfile," return strcat(strtmp,&S[i]);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Del THEN + FPRINT Outfile,"char *del (char *S, int i, int j)" + FPRINT Outfile,"{" + FPRINT Outfile," int ln = strlen(S);" + FPRINT Outfile," if(i<1 || i>ln) return S;" + FPRINT Outfile," char *strtmp = BCX_TmpStr(ln);" + FPRINT Outfile," memcpy(strtmp,S,--i);" + FPRINT Outfile," return strcat(strtmp,&S[i+j]);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Str THEN + FPRINT Outfile,"char *str (double d)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(16);" + FPRINT Outfile," sprintf(strtmp,";D1$;",d);" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Strl THEN + FPRINT Outfile,"char *strl (long double d)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(27);" + FPRINT Outfile," sprintf(strtmp,";D2$;",d);" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + + IF Use_Curdir THEN + FPRINT Outfile,"char *curdir (void)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(2048);" + FPRINT Outfile," char *res=getcwd(strtmp, 1024);" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + + IF Use_Hex THEN + FPRINT Outfile,"char *hex (int a)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(16);" + FPRINT Outfile," sprintf(strtmp,";enc$("%02X");",a);" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Tempdir THEN + FPRINT Outfile,"char *tempdir (void)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(2048);" + FPRINT Outfile," if(!Exist(";enc$("/tmp/mbc.compiler");")) {" + FPRINT Outfile," mkdir (";enc$("/tmp/mbc.compiler");",0755);" + FPRINT Outfile," }" + FPRINT Outfile," strcpy(strtmp,";enc$("/tmp/mbc.compiler");");" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Sysdir THEN + FPRINT Outfile,"char *sysdir (void)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(2048);" + FPRINT Outfile," GetSystemDirectory (strtmp,2048);" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Repeat THEN + FPRINT Outfile,"char *repeat (int count, char *a)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr((1+count)*strlen(a));" + FPRINT Outfile," while(count-->0) strtmp = strcat(strtmp, a);" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_String THEN + FPRINT Outfile,"char *stringx (int count, int a)" + FPRINT Outfile,"{" + FPRINT Outfile," if(count<1) return BCX_TmpStr(1);" + FPRINT Outfile," char *strtmp = BCX_TmpStr(count);" + FPRINT Outfile," return (char*)memset(strtmp,a,count);" + FPRINT Outfile,"}\n\n" + END IF + + IF Use_Shell THEN + FPRINT Outfile,"void Shell (char *cmd)" + FPRINT Outfile,"{" + FPRINT Outfile," int res=system(cmd);" + FPRINT Outfile,"}\n\n" + END IF + + IF Use_Space THEN + FPRINT Outfile,"char *space (int count)" + FPRINT Outfile,"{" + FPRINT Outfile," if(count<1) return BCX_TmpStr(1);" + FPRINT Outfile," char *strtmp = BCX_TmpStr(count);" + FPRINT Outfile," return (char*)memset(strtmp,32,count);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Time THEN + FPRINT Outfile,"char *timef (int t)" + FPRINT Outfile,"{" + FPRINT Outfile," time_t elapse_time;" + FPRINT Outfile," struct tm *tp;" + FPRINT Outfile," char *strtmp = BCX_TmpStr(256);" + FPRINT Outfile," time (&elapse_time);" + FPRINT Outfile," tp = localtime(&elapse_time);" + FPRINT Outfile," switch (t)" + FPRINT Outfile," {" + FPRINT Outfile," case 0:" + FPRINT Outfile," strftime(strtmp,256,",T0$, ",tp); break;" + FPRINT Outfile," case 1:" + FPRINT Outfile," strftime(strtmp,256,",T1$, ",tp); break;" + FPRINT Outfile," case 2:" + FPRINT Outfile," strftime(strtmp,256,",T2$, ",tp); break;" + FPRINT Outfile," case 3:" + FPRINT Outfile," strftime(strtmp,256,",T3$, ",tp); break;" + FPRINT Outfile," case 4:" + FPRINT Outfile," strftime(strtmp,256,",T4$, ",tp); break;" + FPRINT Outfile," case 5:" + FPRINT Outfile," strftime(strtmp,256,",T5$, ",tp); break;" + FPRINT Outfile," case 6:" + FPRINT Outfile," strftime(strtmp,256,",T6$, ",tp); break;" + FPRINT Outfile," case 7:" + FPRINT Outfile," strftime(strtmp,256,",T7$, ",tp); break;" + FPRINT Outfile," case 8:" + FPRINT Outfile," strftime(strtmp,256,",T8$, ",tp); break;" + FPRINT Outfile," case 9:" + FPRINT Outfile," strftime(strtmp,256,",T9$, ",tp); break;" + FPRINT Outfile," case 10:" + FPRINT Outfile," strftime(strtmp,256,",T10$, ",tp); break;" + FPRINT Outfile," case 11:" + FPRINT Outfile," strftime(strtmp,256,",T11$, ",tp); break;" + FPRINT Outfile," case 12:" + FPRINT Outfile," strftime(strtmp,256,",T12$, ",tp); break;" + FPRINT Outfile," case 13:" + FPRINT Outfile," strftime(strtmp,256,",T13$, ",tp); break;" + FPRINT Outfile," }" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Enclose THEN + FPRINT Outfile,"char *enc (char *A, int L, int R)" + FPRINT Outfile,"{" + FPRINT Outfile," char *BCX_RetStr = BCX_TmpStr(strlen(A)+3);" + FPRINT Outfile," if(L==0) L=34;" + FPRINT Outfile," if(R==0) R=L;" + FPRINT Outfile," sprintf(BCX_RetStr,",ENC$("%c%s%c%s"),",L,A,R,",ENC$("\0"),");" + FPRINT Outfile," return BCX_RetStr;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Chr THEN + FPRINT Outfile,"char *chr (int a,int b,int c,int d,int e,int f,int g,int h,int i,int j)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(11);" + FPRINT Outfile," strtmp[0] = a;" + FPRINT Outfile," strtmp[1] = b;" + FPRINT Outfile," strtmp[2] = c;" + FPRINT Outfile," strtmp[3] = d;" + FPRINT Outfile," strtmp[4] = e;" + FPRINT Outfile," strtmp[5] = f;" + FPRINT Outfile," strtmp[6] = g;" + FPRINT Outfile," strtmp[7] = h;" + FPRINT Outfile," strtmp[8] = i;" + FPRINT Outfile," strtmp[9] = j;" + FPRINT Outfile," strtmp[10] = 0;" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_VChr THEN + FPRINT Outfile,"char *vchr(int charcount, ...)" + FPRINT Outfile,"{" + FPRINT Outfile," int c = 0, i = charcount;" + FPRINT Outfile," char *s_ = BCX_TmpStr(charcount + 1);" + FPRINT Outfile," va_list marker;" + FPRINT Outfile," s_[i] = 0;" + FPRINT Outfile," va_start(marker, charcount);" + FPRINT Outfile," while(i-- > 0) s_[c++] = va_arg(marker,int);" + FPRINT Outfile," va_end(marker);" + FPRINT Outfile," return s_;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Join THEN + FPRINT Outfile,"char * join(int n, ...)" + FPRINT Outfile,"{" + FPRINT Outfile," int i = n, tmplen = 0;" + FPRINT Outfile," char *strtmp, *s_;" + FPRINT Outfile,"" + FPRINT Outfile," va_list marker;" + FPRINT Outfile," va_start(marker, n); // Initialize variable arguments" + FPRINT Outfile," while(i-- > 0)" + FPRINT Outfile," {" + FPRINT Outfile," s_ = va_arg(marker, char *);" + FPRINT Outfile," if(s_) tmplen += strlen(s_);" + FPRINT Outfile," }" + FPRINT Outfile," strtmp = BCX_TmpStr(tmplen);" + FPRINT Outfile," va_end(marker); // Reset variable arguments" + FPRINT Outfile," i = n;" + FPRINT Outfile," va_start(marker, n); // Initialize variable arguments" + FPRINT Outfile," while(i-- > 0)" + FPRINT Outfile," {" + FPRINT Outfile," s_ = va_arg(marker, char *);" + FPRINT Outfile," if(s_) strcat(strtmp, s_);" + FPRINT Outfile," }" + FPRINT Outfile," va_end(marker); // Reset variable arguments" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Environ THEN + FPRINT Outfile,"char* Environ(char *S)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp, *tmp;" + FPRINT Outfile,"" + FPRINT Outfile," tmp = getenv(S);" + FPRINT Outfile," if(tmp != NULL) {" + FPRINT Outfile," strtmp = BCX_TmpStr(strlen(tmp)+1);" + FPRINT Outfile," return strcpy(strtmp, tmp);" + FPRINT Outfile," }" + FPRINT Outfile," return BCX_TmpStr(1);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Oct THEN + FPRINT Outfile,"char *oct (int a)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(2048);" + FPRINT Outfile," sprintf(strtmp,";O1$;",a);" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Bin THEN + FPRINT Outfile,"char* Bin(int number)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(2048);" + FPRINT Outfile," itoa(number,strtmp,2);" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Pause THEN + FPRINT Outfile,"void Pause(void)" + FPRINT Outfile,"{" + FPRINT Outfile," printf(", ENC$("\\n%s\\n"), ",", ENC$("Press any key to continue . . ."), ");" + FPRINT Outfile," _getch_(TRUE);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Keypress THEN + FPRINT Outfile,"int keypress(void)" + FPRINT Outfile,"{" + FPRINT Outfile," return _getch_(TRUE);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Inkey THEN + FPRINT Outfile,"char* inkey(void)" + FPRINT Outfile,"{" + FPRINT Outfile," char *strtmp = BCX_TmpStr(2);" + FPRINT Outfile," strtmp[0] = _getch_(FALSE);" + FPRINT Outfile," if(strtmp[0] == -1) strtmp[0] = 0;" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_InkeyD THEN + FPRINT Outfile,"int inkeyd(void)" + FPRINT Outfile,"{" + FPRINT Outfile," return _getch_(TRUE);" + FPRINT Outfile,"}\n\n" + END IF + '/***** 2010-12-08 Added to support INSTAT -AIR *****/ + IF Use_Instat THEN + FPRINT Outfile,"int kbhit(void)" + FPRINT Outfile,"{" + FPRINT Outfile," struct termios oldt, newt;" + FPRINT Outfile," int ch;" + FPRINT Outfile," int oldf;" + + FPRINT Outfile," tcgetattr(STDIN_FILENO, &oldt);" + FPRINT Outfile," newt = oldt;" + FPRINT Outfile," newt.c_lflag &= ~(ICANON | ECHO);" + FPRINT Outfile," tcsetattr(STDIN_FILENO, TCSANOW, &newt);" + FPRINT Outfile," oldf = fcntl(STDIN_FILENO, F_GETFL, 0);" + FPRINT Outfile," fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);" + + FPRINT Outfile," ch = getchar();" + + FPRINT Outfile," tcsetattr(STDIN_FILENO, TCSANOW, &oldt);" + FPRINT Outfile," fcntl(STDIN_FILENO, F_SETFL, oldf);" + + FPRINT Outfile," if(ch != EOF)" + FPRINT Outfile," {" + FPRINT Outfile," ungetc(ch, stdin);" + FPRINT Outfile," return 1;" + FPRINT Outfile," }" + + FPRINT Outfile," return 0;" + FPRINT Outfile,"}\n\n" + END IF + + IF Use_GetCh THEN + FPRINT Outfile,"int _getch_(int waitkey)" + FPRINT Outfile,"{" + + FPRINT Outfile," struct termios initial_settings, new_settings;" + FPRINT Outfile," unsigned char ch;" + FPRINT Outfile,"" + FPRINT Outfile," tcgetattr(0,&initial_settings);" + FPRINT Outfile," new_settings = initial_settings;" + FPRINT Outfile," new_settings.c_lflag &= ~ICANON;" + FPRINT Outfile," new_settings.c_lflag &= ~ECHO;" + FPRINT Outfile," new_settings.c_lflag &= ~ISIG;" + FPRINT Outfile," new_settings.c_cc[VMIN] = waitkey;" + FPRINT Outfile," new_settings.c_cc[VTIME] = 0;" + FPRINT Outfile," tcsetattr(0, TCSANOW, &new_settings);" + FPRINT Outfile,"" + FPRINT Outfile," //read(0,&ch,1);" + FPRINT Outfile," ch = getchar();" + FPRINT Outfile," tcsetattr(0, TCSANOW, &initial_settings);" + FPRINT Outfile," return ch;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Now THEN + FPRINT Outfile,"char *now (void)" + FPRINT Outfile,"{" + FPRINT Outfile," time_t elapse_time;" + FPRINT Outfile," struct tm *tp;" + FPRINT Outfile," char *strtmp = BCX_TmpStr(2048);" + FPRINT Outfile," time(&elapse_time);" + FPRINT Outfile," tp=localtime(&elapse_time);" + FPRINT Outfile," strftime(strtmp,256,", ENC$("%m/%d/%y %I:%M:%S: %p"), ",tp);" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}" + END IF + IF Use_AppExePath THEN + FPRINT Outfile,"char *AppExePath (void)" + FPRINT Outfile,"{" + FPRINT Outfile," char fullpath[MAX_PATH];" + FPRINT Outfile," int length;" + !#if defined (__APPLE__) + FPRINT Outfile," pid_t pid = getpid();" + FPRINT Outfile," length = proc_pidpath (pid, fullpath, sizeof(fullpath));" + !#else + FPRINT Outfile," length = readlink(", ENC$("/proc/self/exe"),", fullpath, MAX_PATH);" + !#endif + FPRINT Outfile," if(length < 1) return BCX_TmpStr(1);" + FPRINT Outfile,"" + FPRINT Outfile," fullpath[length] = 0;" + FPRINT Outfile," return BcxSplitPath(fullpath, FDRV|FPATH);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_AppExeName THEN + FPRINT Outfile,"char *AppExeName (void)" + FPRINT Outfile,"{" + FPRINT Outfile," return BcxSplitPath(G_argv[0], FNAME|FEXT);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_TempFileName THEN + FPRINT Outfile,"char * TempFileName (char *dr, char *prefix)" + FPRINT Outfile,"{" + FPRINT Outfile," static unsigned int count;" + FPRINT Outfile," char *f, *tmpstr = BCX_TmpStr(MAX_PATH);" + FPRINT Outfile," int i, length;" + FPRINT Outfile,"" + FPRINT Outfile," if(!count) srand(time(0));" + FPRINT Outfile,"" + FPRINT Outfile," if(dr) strcpy(tmpstr, dr);" + FPRINT Outfile," length = strlen(tmpstr);" + FPRINT Outfile," if(length && (tmpstr[length-1] != '\\\\' && tmpstr[length-1] != '/'))" + FPRINT Outfile," tmpstr[length++] = '/';" + FPRINT Outfile," if(prefix) strcpy(&tmpstr[length], prefix);" + FPRINT Outfile," f = &tmpstr[strlen(tmpstr)];" + FPRINT Outfile,"" + FPRINT Outfile," do {" + FPRINT Outfile," count++;" + FPRINT Outfile," for(i=0; i<5; i+=1)" + FPRINT Outfile," {" + FPRINT Outfile," do {" + FPRINT Outfile," f[i]=(char)(rnd()*122);" + FPRINT Outfile," }while((f[i]<65)||(f[i]>90&&f[i]<97));" + FPRINT Outfile," }" + FPRINT Outfile," snprintf(&f[5],3,",ENC$("%x"),", count);" + FPRINT Outfile," } while (Exist(tmpstr));" + FPRINT Outfile,"" + FPRINT Outfile," return tmpstr;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Boolstr THEN + FPRINT Outfile,"char * BoolStr (int a)" + FPRINT Outfile,"{" + FPRINT Outfile," char *BCX_RetStr=BCX_TmpStr(5);" + FPRINT Outfile," if(a) return strcpy(BCX_RetStr,",ENC$("True"),");" + FPRINT Outfile," return strcpy(BCX_RetStr,",ENC$("False"),");" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Using THEN + FPRINT Outfile,"char *Using (char *Mask, double Num)" + FPRINT Outfile,"{" + FPRINT Outfile," int Spaces = 0;" + FPRINT Outfile," int CntDec = 0;" + FPRINT Outfile," int Decimals = 0;" + FPRINT Outfile," int Dollar = 0;" + FPRINT Outfile," char* BCX_RetStr = BCX_TmpStr(512);" + FPRINT Outfile," char Buf_1[512]={0};" + FPRINT Outfile," char* p = Mask;" + FPRINT Outfile," char* r;" + FPRINT Outfile," int len;" + FPRINT Outfile,"" + FPRINT Outfile," while (*p)" + FPRINT Outfile," {" + FPRINT Outfile," if (*p == 36) Dollar++;" + FPRINT Outfile," if (*p == 32) Spaces++;" + FPRINT Outfile," if ((*p == 32 || *p == 35)&& CntDec) Decimals++;" + FPRINT Outfile," if (*p == 46) CntDec = 1;" + FPRINT Outfile," p++;" + FPRINT Outfile," }" + FPRINT Outfile," sprintf(Buf_1,", ENC$("%1.*f"), ",Decimals,Num);" + FPRINT Outfile,"" + FPRINT Outfile," len = strlen(Buf_1)-Decimals-(Decimals>0?1:0);" + FPRINT Outfile," r = BCX_RetStr+Dollar+Spaces;" + FPRINT Outfile," p = Buf_1;" + FPRINT Outfile," while (*p)" + FPRINT Outfile," {" + FPRINT Outfile," *r++ = *p++;" + FPRINT Outfile," if (--len>2 && *(p-1) != '-' && len % 3 == 0)" + FPRINT Outfile," {" + FPRINT Outfile," *r++ = ',';" + FPRINT Outfile," }" + FPRINT Outfile," }" + FPRINT Outfile," if(Dollar) BCX_RetStr[Spaces]=36;" + FPRINT Outfile," if(Spaces) memset(BCX_RetStr,32,Spaces);" + FPRINT Outfile,"" + FPRINT Outfile," return BCX_RetStr;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_SearchPath THEN + FPRINT Outfile,"char *SEARCHPATH (char *szFile)" + FPRINT Outfile,"{" + FPRINT Outfile," char *BCX_RetStr=BCX_TmpStr(MAX_PATH+1);" + FPRINT Outfile," PCHAR lpbs=0;" + FPRINT Outfile," SearchPath(0,szFile,0,MAX_PATH,BCX_RetStr,&lpbs);" + FPRINT Outfile," if(lpbs) *lpbs=0;" + FPRINT Outfile," return BCX_RetStr;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Instrrev THEN + FPRINT Outfile,"int InstrRev (char *s, char *p, int os, int sens)" + FPRINT Outfile,"{" + FPRINT Outfile," int sl, pl, ox;" + FPRINT Outfile," int (*cmp)(const char *, const char *, size_t );" + FPRINT Outfile,"" + FPRINT Outfile," if (!s || !p) return 0;" + FPRINT Outfile," sl = strlen(s); pl = strlen(p);" + FPRINT Outfile," if (os > sl || sl == 0 || pl == 0 || (ox = sl - pl) < 0)" + FPRINT Outfile," return 0;" + FPRINT Outfile,"" + FPRINT Outfile," if (os <= 0) " + FPRINT Outfile," os = ox ;" + FPRINT Outfile," else if(os >= pl)" + FPRINT Outfile," os = os - pl ;" + FPRINT Outfile," else" + FPRINT Outfile," return 0;" + FPRINT Outfile,"" + FPRINT Outfile," cmp = (sens ? strncasecmp : strncmp);" + FPRINT Outfile," do { if (cmp(s + os , p, pl) == 0)" + FPRINT Outfile," return os+1;" + FPRINT Outfile," } while (os--);" + FPRINT Outfile," return 0;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Instr THEN + FPRINT Outfile,"int instr_b(char* mane,char* match,int offset,int sensflag)" + FPRINT Outfile,"{" + FPRINT Outfile," char *s;" + FPRINT Outfile," if (!mane || !match || ! *match || offset>(int)strlen(mane)) return 0;" + FPRINT Outfile," if (sensflag)" + FPRINT Outfile," s = _stristr_(offset>0 ? mane+offset-1 : mane,match);" + FPRINT Outfile," else" + FPRINT Outfile," s = _strstr_(offset>0 ? mane+offset-1 : mane,match);" + FPRINT Outfile," return s ? (int)(s-mane)+1 : 0;" + FPRINT Outfile,"}\n\n" + END IF + IF UseLCaseTbl THEN + FPRINT Outfile,"char *MakeLCaseTbl (void)" + FPRINT Outfile,"{" + FPRINT Outfile," static char tbl[256];" + FPRINT Outfile," if(!tbl['a'])" + FPRINT Outfile," {" + FPRINT Outfile," int i; for (i=0; i < 256; i++)" + FPRINT Outfile," tbl[i] = (char)(int)tolower(i);" + FPRINT Outfile," }" + FPRINT Outfile," return tbl;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Stristr THEN + FPRINT Outfile,"char *_stristr_(char *String, char *Pattern)" + FPRINT Outfile,"{" + FPRINT Outfile," int mi=-1;" + FPRINT Outfile," char *LowCase = MakeLCaseTbl();" + FPRINT Outfile," while(Pattern[++mi])" + FPRINT Outfile," {" + FPRINT Outfile," if(String[mi]==0) return 0;" + FPRINT Outfile," if(LowCase[(unsigned char)String[mi]]!=LowCase[(unsigned char)Pattern[mi]])" + FPRINT Outfile," { String++; mi=-1; }" + FPRINT Outfile," }" + FPRINT Outfile," return String;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_StrStr THEN + FPRINT Outfile,"char *_strstr_(char *String, char *Pattern)" + FPRINT Outfile,"{" + FPRINT Outfile," int mi=-1;" + FPRINT Outfile," while(Pattern[++mi])" + FPRINT Outfile," {" + FPRINT Outfile," if(String[mi]==0) return 0;" + FPRINT Outfile," if(String[mi]!=Pattern[mi])" + FPRINT Outfile," { String++; mi=-1; }" + FPRINT Outfile," }" + FPRINT Outfile," return String;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Inchr THEN + FPRINT Outfile,"int inchr (char *A, char *B)" + FPRINT Outfile,"{" + FPRINT Outfile," char* C=A;" + FPRINT Outfile," while(*C)" + FPRINT Outfile," {" + FPRINT Outfile," if(*C==*B) return C-A+1;" + FPRINT Outfile," C++;" + FPRINT Outfile," }" + FPRINT Outfile," return 0;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Asc THEN + FPRINT Outfile,"extern int asc (char *z,int index)" + FPRINT Outfile,"{" + FPRINT Outfile," return (unsigned char) z[index];" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Sgn THEN + FPRINT Outfile,"double sgn (double a)" + FPRINT Outfile,"{" + FPRINT Outfile," if(a<0) return -1;" + FPRINT Outfile," if(a>0) return 1;" + FPRINT Outfile," return 0;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Round THEN + FPRINT Outfile,"double Round (double n, int d)" + FPRINT Outfile,"{" + FPRINT Outfile," return (floor((n)*pow(10.0,(d))+0.5)/pow(10.0,(d)));" + FPRINT Outfile,"}\n\n" + END IF + + IF Use_Embed THEN + FPRINT Outfile,"char* GetResource (int *resource)" + FPRINT Outfile,"{" + FPRINT Outfile," char *BCX_RetStr={0};" + FPRINT Outfile," static char* dat;" + FPRINT Outfile," memset(&dat,0,sizeof(char *));" + FPRINT Outfile," dat=(char*)resource;" + FPRINT Outfile," BCX_RetStr=BCX_TmpStr(strlen(dat));" + FPRINT Outfile," strcpy(BCX_RetStr,dat);" + FPRINT Outfile," return BCX_RetStr;" + FPRINT Outfile,"}\n\n" + END IF + + IF Use_Exist THEN + FPRINT Outfile,"bool Exist (char *szFilePath)" + FPRINT Outfile,"{" + FPRINT Outfile," int retstat;" + FPRINT Outfile," struct stat sb;" + FPRINT Outfile," retstat = stat(szFilePath, &sb);" + FPRINT Outfile," if(retstat != -1)" + FPRINT Outfile," return TRUE;" + FPRINT Outfile," return FALSE;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Tally THEN + FPRINT Outfile,"int tally (char *szLine, char *szChar, int sensflag)" + FPRINT Outfile,"{" + FPRINT Outfile," if(!*szChar) return 0;" + FPRINT Outfile," int mlen = strlen(szChar);" + FPRINT Outfile," int iCount = 0;" + FPRINT Outfile," char *p = (sensflag == 0 ? _strstr_(szLine, szChar) : _stristr_(szLine, szChar));" + FPRINT Outfile," while (p)" + FPRINT Outfile," {" + FPRINT Outfile," iCount++;" + FPRINT Outfile," p+=mlen;" + FPRINT Outfile," p = (sensflag == 0 ? _strstr_(p, szChar) : _stristr_(p, szChar));" + FPRINT Outfile," }" + FPRINT Outfile," return iCount;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Timer THEN + FPRINT Outfile,"float timer (void)" + FPRINT Outfile,"{" + FPRINT Outfile," return ((double)clock()/CLOCKS_PER_SEC);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Rnd THEN + FPRINT Outfile,"float rnd (void)" + FPRINT Outfile,"{" + FPRINT Outfile," return (float)rand()/RAND_MAX;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Exp THEN + FPRINT Outfile,"double Exp (double arg)" + FPRINT Outfile,"{" + FPRINT Outfile," return pow(2.718281828459045,arg);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Randomize THEN + FPRINT Outfile,"void randomize (unsigned int seed)" + FPRINT Outfile,"{" + FPRINT Outfile," srand(seed);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Max THEN + FPRINT Outfile,"double _MAX_ (double a, double b)" + FPRINT Outfile,"{" + FPRINT Outfile," if(a>b)" + FPRINT Outfile," return a;" + FPRINT Outfile," return b;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Min THEN + FPRINT Outfile,"double _MIN_ (double a, double b)" + FPRINT Outfile,"{" + FPRINT Outfile," if(asrclen++ || st<1) return;" + FPRINT Outfile," int replen = strlen(rep);" + FPRINT Outfile," if(replen < length || length==-1) length=replen;" + FPRINT Outfile," if((st+length) > srclen) length=srclen-st;" + FPRINT Outfile," memcpy(&src[st-1],rep,length);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Swap THEN + FPRINT Outfile,"void swap ( UCHAR* A, UCHAR* B, int length)" + FPRINT Outfile,"{" + FPRINT Outfile," UCHAR t;" + FPRINT Outfile," while(length--)" + FPRINT Outfile," {" + FPRINT Outfile," t = *A;" + FPRINT Outfile," *(A++) = *B;" + FPRINT Outfile," *(B++) = t;" + FPRINT Outfile," }" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Like THEN + FPRINT Outfile,"int like (char *raw, char *pat)" + FPRINT Outfile,"{" + FPRINT Outfile," char a, b, d;" + FPRINT Outfile," char *r, *p;" + FPRINT Outfile," int star = 0;" + FPRINT Outfile," for(;;) {" + FPRINT Outfile," if ((d = *pat++)==0) return (star || !*raw);" + FPRINT Outfile," else if (d == '*') star = 1;" + FPRINT Outfile," else if (d == '?') { if (!*raw++) return 0; }" + FPRINT Outfile," else break;" + FPRINT Outfile," }" + FPRINT Outfile," b = d;" + FPRINT Outfile," do if ((a = *raw++) == b) {" + FPRINT Outfile," r = raw;" + FPRINT Outfile," p = pat;" + FPRINT Outfile," do {" + FPRINT Outfile," if ((d = *p++) == '*')" + FPRINT Outfile," if (like(r, p - 1)) return 1;" + FPRINT Outfile," else break;" + FPRINT Outfile," else if (!d) {" + FPRINT Outfile," if (!*r) return 1;" + FPRINT Outfile," else break;" + FPRINT Outfile," }" + FPRINT Outfile," } while (*r++ == d || d == '?');" + FPRINT Outfile," } while (star && a);" + FPRINT Outfile," return 0;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Lof THEN + FPRINT Outfile,"DWORD lof (char *FileName)" + FPRINT Outfile,"{" + FPRINT Outfile,"" + FPRINT Outfile," int retstat;" + FPRINT Outfile," struct stat sb;" + FPRINT Outfile," retstat = stat(FileName, &sb);" + FPRINT Outfile," if(retstat != -1)" + FPRINT Outfile," return sb.st_size;" + FPRINT Outfile," return 0;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Iif THEN + FPRINT Outfile,"double iif (bool cond, double tp, double fp)" + FPRINT Outfile,"{" + FPRINT Outfile," if(cond) return tp;" + FPRINT Outfile," return fp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_sziif THEN + FPRINT Outfile,"char * sziif (bool i, char *a, char *b)" + FPRINT Outfile,"{" + FPRINT Outfile," if(i) return a;" + FPRINT Outfile," return b;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_DynamicA THEN + FPRINT Outfile,"void *CreateArr(void *a, int elem_size, int update, int num_dims, ... )" + FPRINT Outfile,"{" + FPRINT Outfile," va_list ap;" + FPRINT Outfile," void *RetPtr;" + FPRINT Outfile,"" + FPRINT Outfile," va_start(ap, num_dims);" + FPRINT Outfile," RetPtr = CreateArr_internal(a, elem_size, update, num_dims, ap);" + FPRINT Outfile," va_end(ap);" + FPRINT Outfile," return (RetPtr);" + FPRINT Outfile,"}\n\n" + FPRINT Outfile,"void *CreateArr_internal(void *a, int elem_size, int update, int num_dims, va_list ap)" + FPRINT Outfile,"{" + FPRINT Outfile," size_t s, s1, s2;" + FPRINT Outfile," void **vp;" + FPRINT Outfile," va_list marker;" + FPRINT Outfile," " + FPRINT Outfile,"#ifdef va_copy" + FPRINT Outfile," va_copy(marker, ap);" + FPRINT Outfile,"#else" + FPRINT Outfile," marker = ap;" + FPRINT Outfile,"#endif" + FPRINT Outfile," s = va_arg(marker, size_t);" + FPRINT Outfile," s2 = s + 2;" + FPRINT Outfile," if(num_dims == 1)" + FPRINT Outfile," {" + FPRINT Outfile," if(update && a)" + FPRINT Outfile," a=realloc(a,s2*elem_size);" + FPRINT Outfile," else" + FPRINT Outfile," a=calloc(s2,elem_size);" + FPRINT Outfile," return a;" + FPRINT Outfile," }" + FPRINT Outfile," else" + FPRINT Outfile," if(update && a)" + FPRINT Outfile," {" + FPRINT Outfile," s1 = 0;" + FPRINT Outfile," vp = (void**)a;" + FPRINT Outfile," while(*vp && s1 <= s)" + FPRINT Outfile," {" + FPRINT Outfile," vp++;" + FPRINT Outfile," s1++;" + FPRINT Outfile," }" + FPRINT Outfile," if(s1 > s)" + FPRINT Outfile," {" + FPRINT Outfile," vp--;" + FPRINT Outfile," DestroyArr(vp, num_dims, 0);" + FPRINT Outfile," }" + FPRINT Outfile," a=realloc(a,s2*sizeof(int));" + FPRINT Outfile," s1 = 0;" + FPRINT Outfile," vp = (void**)a;" + FPRINT Outfile," while(*vp && s1 <= s)" + FPRINT Outfile," {" + FPRINT Outfile," vp++;" + FPRINT Outfile," s1++;" + FPRINT Outfile," }" + FPRINT Outfile," while(s1 < s2)" + FPRINT Outfile," {" + FPRINT Outfile," *(((int *)vp)) = 0;" + FPRINT Outfile," vp++;" + FPRINT Outfile," s1++;" + FPRINT Outfile," }" + FPRINT Outfile," }" + FPRINT Outfile," else" + FPRINT Outfile," a=calloc(s2*sizeof(int),1);" + FPRINT Outfile," vp = (void**)a;" + FPRINT Outfile," if(--num_dims > 0)" + FPRINT Outfile," {" + FPRINT Outfile," for(s1 = 0; s1 < s; s1++)" + FPRINT Outfile," {" + FPRINT Outfile," vp[s1] = CreateArr_internal(vp[s1], elem_size, update, num_dims, marker);" + FPRINT Outfile," }" + FPRINT Outfile," }" + FPRINT Outfile," return a;" + FPRINT Outfile,"}\n\n" + FPRINT Outfile,"void DestroyArr (void** a,int num_dims, int top_free)" + FPRINT Outfile,"{" + FPRINT Outfile," int i = 0;" + FPRINT Outfile," static int s = 0;" + FPRINT Outfile," if(num_dims == 1)" + FPRINT Outfile," {" + FPRINT Outfile," free(a);" + FPRINT Outfile," return;" + FPRINT Outfile," }" + FPRINT Outfile," s++;" + FPRINT Outfile," num_dims--; " + FPRINT Outfile," while(a[i])" + FPRINT Outfile," {" + FPRINT Outfile," DestroyArr((void**)a[i], num_dims, top_free);" + FPRINT Outfile," if(num_dims > 1)" + FPRINT Outfile," free(a[i]);" + FPRINT Outfile," a[i++]=NULL;" + FPRINT Outfile," }" + FPRINT Outfile," s--;" + FPRINT Outfile," if(s == 0 && top_free)" + FPRINT Outfile," free(a);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Idxqsort THEN + FPRINT Outfile,"int IdxCompare (const void *one, const void *two)" + FPRINT Outfile,"{" + FPRINT Outfile," int *ptr1 = (int *)(one);" + FPRINT Outfile," int *ptr2 = (int *)(two);" + FPRINT Outfile," return strcasecmp (pppStr[Key][*ptr1],pppStr[Key][*ptr2]);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_IdxqsortSt THEN + FPRINT Outfile,"int IdxCompareSt (const void* one, const void* two)" + FPRINT Outfile,"{" + FPRINT Outfile,"#define compare1 cmp1+(StructSize * (*(UINT *)(one)))" + FPRINT Outfile,"#define compare2 cmp1+(StructSize * (*(UINT *)(two)))" + FPRINT Outfile,"" + FPRINT Outfile," if (Key==0)" 'String + FPRINT Outfile," return strcasecmp(compare1, compare2);" + FPRINT Outfile,"" + FPRINT Outfile," if (Key==1)" 'Integer + FPRINT Outfile," {" + FPRINT Outfile," if (*(int*)(compare1) < *(int*)(compare2)) return -1;" + FPRINT Outfile," if (*(int*)(compare1) > *(int*)(compare2)) return 1;" + FPRINT Outfile," return 0;" + FPRINT Outfile," }" + FPRINT Outfile,"" + FPRINT Outfile," if (Key==2)" 'Double + FPRINT Outfile," {" + FPRINT Outfile," if (*(double*)(compare1) < *(double*)(compare2)) return -1;" + FPRINT Outfile," if (*(double*)(compare1) > *(double*)(compare2)) return 1;" + FPRINT Outfile," return 0;" + FPRINT Outfile," }" + FPRINT Outfile,"" + FPRINT Outfile," if (Key==3)" 'Unsigned integer + FPRINT Outfile," {" + FPRINT Outfile," if (*(UINT*)(compare1) < *(UINT*)(compare2)) return -1;" + FPRINT Outfile," if (*(UINT*)(compare1) > *(UINT*)(compare2)) return 1;" + FPRINT Outfile," }" + FPRINT Outfile,"return 0;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_PtrqsortSt THEN + FPRINT Outfile,"int PtrCompareSt (const void* one, const void* two)" + FPRINT Outfile,"{" + FPRINT Outfile,"#define pcompare1 ((char*)(one)+OffSet)" + FPRINT Outfile,"#define pcompare2 ((char*)(two)+OffSet)" + FPRINT Outfile,"" + FPRINT Outfile," if (Key==0)" + FPRINT Outfile," return strcasecmp(pcompare1, pcompare2);" + FPRINT Outfile,"" + FPRINT Outfile," if (Key==1)" + FPRINT Outfile," {" + FPRINT Outfile," if (*(int*)(pcompare1) < *(int*)(pcompare2)) return -1;" + FPRINT Outfile," if (*(int*)(pcompare1) > *(int*)(pcompare2)) return 1;" + FPRINT Outfile," return 0;" + FPRINT Outfile," }" + FPRINT Outfile,"" + FPRINT Outfile," if (Key==2)" + FPRINT Outfile," {" + FPRINT Outfile," if (*(double*)(pcompare1) < *(double*)(pcompare2)) return -1;" + FPRINT Outfile," if (*(double*)(pcompare1) > *(double*)(pcompare2)) return 1;" + FPRINT Outfile," return 0;" + FPRINT Outfile," }" + FPRINT Outfile,"" + FPRINT Outfile," if (Key==3)" + FPRINT Outfile," {" + FPRINT Outfile," if (*(UINT*)(pcompare1) < *(UINT*)(pcompare2)) return -1;" + FPRINT Outfile," if (*(UINT*)(pcompare1) > *(UINT*)(pcompare2)) return 1;" + FPRINT Outfile," }" + FPRINT Outfile,"return 0;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Strqsorta THEN + FPRINT Outfile,"int StrCompareA (const void *arg1, const void *arg2)" + FPRINT Outfile,"{" + FPRINT Outfile," char *v1 = (char*) arg1;" + FPRINT Outfile," char *v2 = (char*) arg2;" + FPRINT Outfile," return strcasecmp (v1,v2);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Strqsortd THEN + FPRINT Outfile,"int StrCompareD (const void *arg1, const void *arg2)" + FPRINT Outfile,"{" + FPRINT Outfile," char *v1 = (char*) arg1;" + FPRINT Outfile," char *v2 = (char*) arg2;" + FPRINT Outfile," return strcasecmp (v2,v1);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_DynStrqsorta THEN + FPRINT Outfile,"int DynStrCompareA (const void *arg1, const void *arg2)" + FPRINT Outfile,"{" + FPRINT Outfile," char *v1 = *(char **) arg1;" + FPRINT Outfile," char *v2 = *(char **) arg2;" + FPRINT Outfile," return strcasecmp(v1, v2);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_DynStrqsortd THEN + FPRINT Outfile,"int DynStrCompareD (const void *arg1, const void *arg2)" + FPRINT Outfile,"{" + FPRINT Outfile," char *v1 = *(char **) arg1;" + FPRINT Outfile," char *v2 = *(char **) arg2;" + FPRINT Outfile," return strcasecmp(v2, v1);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Numqsortaint THEN + FPRINT Outfile,"int NumCompareAint (const void *one, const void *two)" + FPRINT Outfile,"{" + FPRINT Outfile," int *ptr1 = (int *)(one);" + FPRINT Outfile," int *ptr2 = (int *)(two);" + FPRINT Outfile," if (*ptr1 < *ptr2) return -1;" + FPRINT Outfile," else if (*ptr1 == *ptr2) return 0;" + FPRINT Outfile," else return 1;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Numqsortdint THEN + FPRINT Outfile,"int NumCompareDint (const void *one, const void *two)" + FPRINT Outfile,"{" + FPRINT Outfile," int *ptr1 = (int *)(one);" + FPRINT Outfile," int *ptr2 = (int *)(two);" + FPRINT Outfile," if (*ptr1 > *ptr2) return -1;" + FPRINT Outfile," else if (*ptr1 == *ptr2) return 0;" + FPRINT Outfile," else return 1;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Numqsortafloat THEN + FPRINT Outfile,"int NumCompareAfloat (const void *one, const void *two)" + FPRINT Outfile,"{" + FPRINT Outfile," float *ptr1 = (float *)(one);" + FPRINT Outfile," float *ptr2 = (float *)(two);" + FPRINT Outfile," if (*ptr1 < *ptr2) return -1;" + FPRINT Outfile," else if (*ptr1 == *ptr2) return 0;" + FPRINT Outfile," else return 1;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Numqsortdfloat THEN + FPRINT Outfile,"int NumCompareDfloat (const void *one, const void *two)" + FPRINT Outfile,"{" + FPRINT Outfile," float *ptr1 = (float *)(one);" + FPRINT Outfile," float *ptr2 = (float *)(two);" + FPRINT Outfile," if (*ptr1 > *ptr2) return -1;" + FPRINT Outfile," else if (*ptr1 == *ptr2) return 0;" + FPRINT Outfile," else return 1;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Numqsortadouble THEN + FPRINT Outfile,"int NumCompareAdouble (const void *one, const void *two)" + FPRINT Outfile,"{" + FPRINT Outfile," double *ptr1 = (double *)(one);" + FPRINT Outfile," double *ptr2 = (double *)(two);" + FPRINT Outfile," if (*ptr1 < *ptr2) return -1;" + FPRINT Outfile," else if (*ptr1 == *ptr2) return 0;" + FPRINT Outfile," else return 1;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Numqsortddouble THEN + FPRINT Outfile,"int NumCompareDdouble (const void *one, const void *two)" + FPRINT Outfile,"{" + FPRINT Outfile," double *ptr1 = (double *)(one);" + FPRINT Outfile," double *ptr2 = (double *)(two);" + FPRINT Outfile," if (*ptr1 > *ptr2) return -1;" + FPRINT Outfile," else if (*ptr1 == *ptr2) return 0;" + FPRINT Outfile," else return 1;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_FillArray THEN + FPRINT Outfile,"int fillarray(char *input, int ArrayType, int MaxCnt, void *Array)" + FPRINT Outfile,"{" + FPRINT Outfile," if(MaxCnt < 1) return -1;" + FPRINT Outfile," int c = 0, cnt=-1, cnt2;" + FPRINT Outfile," char A[65535];" + FPRINT Outfile," int *intptr = (int *)Array;" + FPRINT Outfile," float *floatptr = (float *)Array;" + FPRINT Outfile," double *doubleptr = (double *)Array;" + FPRINT Outfile," long double *ldoubleptr = (long double *)Array;" + FPRINT Outfile," for(;;)" + FPRINT Outfile," {" + FPRINT Outfile," cnt2=0;" + FPRINT Outfile," while(input[++cnt]!=',')" + FPRINT Outfile," {" + FPRINT Outfile," if(input[cnt]==0) break;" + FPRINT Outfile," A[cnt2++]=input[cnt];" + FPRINT Outfile," }" + FPRINT Outfile," A[cnt2]=0;" + FPRINT Outfile," if(cnt2==0||c==MaxCnt) break;" + FPRINT Outfile," " + FPRINT Outfile," if(ArrayType==2)" + FPRINT Outfile," intptr[c++] = atoi(A);" + FPRINT Outfile," else if(ArrayType==3)" + FPRINT Outfile," floatptr[c++] = atof(A);" + FPRINT Outfile," else if(ArrayType==4)" + FPRINT Outfile," doubleptr[c++] = atof(A);" + FPRINT Outfile," else if(ArrayType==5)" + FPRINT Outfile," ldoubleptr[c++] = atof(A);" + FPRINT Outfile,"" + FPRINT Outfile," if(input[cnt]==0) break;" + FPRINT Outfile," } " + FPRINT Outfile," return (c-1);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Loc THEN + FPRINT Outfile,"int loc(FILE *fp, int fplen)" + FPRINT Outfile,"{" + FPRINT Outfile," fpos_t t;" + FPRINT Outfile," fgetpos(fp, &t);" + FPRINT Outfile,"#if defined( __POCC__ )" + FPRINT Outfile," t.off %= fplen;" + FPRINT Outfile," return (int)t.off;" + FPRINT Outfile,"#else" + FPRINT Outfile," t %= fplen;" + FPRINT Outfile," return (int)t;" + FPRINT Outfile,"#endif" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Rec THEN + FPRINT Outfile,"int rec(FILE *fp, int fplen)" + FPRINT Outfile,"{" + FPRINT Outfile," fpos_t t;" + FPRINT Outfile," fgetpos(fp, &t);" + FPRINT Outfile,"#if defined( __POCC__ )" + FPRINT Outfile," t.off /= fplen;" + FPRINT Outfile," return (int)++t.off;" + FPRINT Outfile,"#else" + FPRINT Outfile," t /= fplen;" + FPRINT Outfile," return (int)++t;" + FPRINT Outfile,"#endif" + FPRINT Outfile,"}\n\n" + END IF + IF Use_RecCount THEN + FPRINT Outfile,"int reccount(FILE *fp, int fplen)" + FPRINT Outfile,"{" + FPRINT Outfile," fpos_t t;" + FPRINT Outfile," fseek(fp,0,SEEK_END);" + FPRINT Outfile," fgetpos(fp, &t);" + FPRINT Outfile,"#if defined( __POCC__ )" + FPRINT Outfile," t.off /= fplen;" + FPRINT Outfile," return (int)t.off;" + FPRINT Outfile,"#else" + FPRINT Outfile," t /= fplen;" + FPRINT Outfile," return (int)t;" + FPRINT Outfile,"#endif" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Scan THEN + FPRINT Outfile,"int scan(char *input, char *format, ... )" + FPRINT Outfile,"{" + FPRINT Outfile," int c,d ;" + FPRINT Outfile," char *s_;" + FPRINT Outfile," int *intptr;" + FPRINT Outfile," float *floatptr;" + FPRINT Outfile," double *doubleptr;" + FPRINT Outfile," char A[50][65535];" + FPRINT Outfile," va_list marker;" + FPRINT Outfile," c = 0;" + FPRINT Outfile," d = Split(A,input,"; ENC$(",") ; ");" + FPRINT Outfile," va_start(marker, format); //Initialize arguments" + FPRINT Outfile," while(d && *format)" + FPRINT Outfile," {" + FPRINT Outfile," if(*format == '%') format++;" + FPRINT Outfile," if(*format == 's')" + FPRINT Outfile," {" + FPRINT Outfile," s_ = va_arg(marker, char *);" + FPRINT Outfile," strcpy(s_, A[c]);" + FPRINT Outfile," c++;" + FPRINT Outfile," d--;" + FPRINT Outfile," }" + FPRINT Outfile," if(*format == 'd')" + FPRINT Outfile," {" + FPRINT Outfile," intptr = va_arg(marker, int *);" + FPRINT Outfile," *intptr = atoi(A[c]);" + FPRINT Outfile," c++;" + FPRINT Outfile," d--;" + FPRINT Outfile," }" + FPRINT Outfile," if(*format == 'g')" + FPRINT Outfile," {" + FPRINT Outfile," floatptr = va_arg(marker, float *);" + FPRINT Outfile," *floatptr = atof(A[c]);" + FPRINT Outfile," c++;" + FPRINT Outfile," d--;" + FPRINT Outfile," }" + FPRINT Outfile," if(*format == 'l')" + FPRINT Outfile," {" + FPRINT Outfile," format++;" + FPRINT Outfile," doubleptr = va_arg(marker, double *);" + FPRINT Outfile," *doubleptr = atof(A[c]);" + FPRINT Outfile," c++;" + FPRINT Outfile," d--;" + FPRINT Outfile," }" + FPRINT Outfile," format++;" + FPRINT Outfile," }" + FPRINT Outfile," va_end(marker); // Reset variable arguments" + FPRINT Outfile," if(d) return(1); // More data than variables" + FPRINT Outfile," if(*format == 0) return(0); // OK" + FPRINT Outfile," return(-1); // More variables than data" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Split THEN + FPRINT Outfile,"int Split (char Buf[][65535], char *T, char *Delim, int Flg)" + FPRINT Outfile,"{" + FPRINT Outfile," int Begin = 0;" + FPRINT Outfile," int Count = 0;" + FPRINT Outfile," int Quote = 0;" + FPRINT Outfile," int Index,i;" + FPRINT Outfile," int lenT = strlen(T);" + FPRINT Outfile," char Chr34[2]={34,0};" + FPRINT Outfile," for(Index=1;Index<=lenT;Index++)" + FPRINT Outfile," {" + FPRINT Outfile," if(instr_b(Delim,mid(T,Index,1))&&!Quote)" + FPRINT Outfile," {" + FPRINT Outfile," strcpy(Buf[Count],(char*)mid(T,Begin,Index-Begin));" + FPRINT Outfile," if ((Flg & 2) == 0) // 0 if old version" + FPRINT Outfile," Count++;" + FPRINT Outfile," else" + FPRINT Outfile," if (Buf[Count][0] != 0) Count++;" + FPRINT Outfile," Begin=0;" + FPRINT Outfile," if((Flg & 1) == 1) // 1 if true" + FPRINT Outfile," strcpy(Buf[Count++],(char*)mid(T,Index,1));" + FPRINT Outfile," }" + FPRINT Outfile," else" + FPRINT Outfile," {" + FPRINT Outfile," if(strcmp(mid(T,Index,1),Chr34)==0) Quote=!Quote;" + FPRINT Outfile," if(Begin==0) Begin=Index;" + FPRINT Outfile," }" + FPRINT Outfile," }" + FPRINT Outfile," if(Begin)" + FPRINT Outfile," strcpy(Buf[Count++],(char*)mid(T,Begin,Index-Begin));" + FPRINT Outfile," if((Flg & 1) == 0) // 0 if false" + FPRINT Outfile," for(i=0;i= 'a' && ch <= 'f') || (ch >= '0' && ch <= '9'))" + FPRINT Outfile," dwOut |=((int)ch - (ch>'9' ? 'a'-10 : '0')) << ((dwLen - szInput) << 2);" + FPRINT Outfile," }" + FPRINT Outfile," return dwOut;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Verify THEN + FPRINT Outfile,"int Verify (char *Src, char *Allowed)" + FPRINT Outfile,"{" + FPRINT Outfile," int i, j;" + FPRINT Outfile," for (i=1; i<=strlen(Src); i++)" + FPRINT Outfile," {" + FPRINT Outfile," j=VerifyInstr(Allowed,mid(Src,i,1));" + FPRINT Outfile," if (!j) return 0;" + FPRINT Outfile," }" + FPRINT Outfile," return TRUE;" + FPRINT Outfile,"}\n\n" + FPRINT Outfile,"int VerifyInstr(char* mane,char* match,int offset)" + FPRINT Outfile,"{" + FPRINT Outfile," char *s;" + FPRINT Outfile," if (!mane || !match || !*match || offset>(int)strlen(mane)) return 0;" + FPRINT Outfile," s = strstr (offset>0 ? mane+offset-1 : mane,match);" + FPRINT Outfile," return s ? (int)(s-mane)+1 : 0;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Retain THEN + FPRINT Outfile,"char *Retain (char *Text, char *ValidChars)" + FPRINT Outfile,"{" + FPRINT Outfile," char *BCX_RetStr=BCX_TmpStr(strlen(Text));" + FPRINT Outfile," char *temp=BCX_RetStr;" + FPRINT Outfile," while(*Text)" + FPRINT Outfile," {" + FPRINT Outfile," if(strchr(ValidChars,*Text)) *(temp++) = *Text;" + FPRINT Outfile," Text++;" + FPRINT Outfile," }" + FPRINT Outfile," return BCX_RetStr;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_LoadFile THEN + FPRINT Outfile,"char* LoadFile (char *N)" + FPRINT Outfile,"{" + FPRINT Outfile," FILE* FP1;" + FPRINT Outfile," char* BCX_RetStr;" + FPRINT Outfile," if(Exist(N))" + FPRINT Outfile," {" + FPRINT Outfile," BCX_RetStr=BCX_TmpStr(lof(N));" + FPRINT Outfile," if((FP1=fopen(N,", ENC$("rb"), "))!=0)" + FPRINT Outfile," GET(FP1,BCX_RetStr,lof(N));" + FPRINT Outfile," fclose(FP1);" + FPRINT Outfile," return BCX_RetStr;" + FPRINT Outfile," }" + FPRINT Outfile," else" + FPRINT Outfile," {" + FPRINT Outfile," BCX_RetStr=BCX_TmpStr(64);" + FPRINT Outfile," return strcpy(BCX_RetStr,", ENC$("File Not Found"), ");" + FPRINT Outfile," }" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Freefile THEN + FPRINT Outfile,"FILE* FreeFile (void)" + FPRINT Outfile,"{" + FPRINT Outfile," static FILE *pf;" + FPRINT Outfile," if(pf){free(pf);pf=NULL;}" + FPRINT Outfile," pf = (FILE*)calloc(sizeof(FILE*),sizeof(FILE*));" + FPRINT Outfile," return pf;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Run THEN + FPRINT Outfile,"int Run (char* Cmdline, int ShowHide, int WaitState)" + FPRINT Outfile,"{" + FPRINT Outfile," int processId;" + FPRINT Outfile," char *s, *p, *cmd_line;" + FPRINT Outfile,"" + FPRINT Outfile," cmd_line=(char*)malloc(strlen(Cmdline)+1);" + FPRINT Outfile," if(cmd_line==NULL) return -2;" + FPRINT Outfile,"" + FPRINT Outfile," strcpy(cmd_line, Cmdline);" + FPRINT Outfile," p = s = cmd_line;" + FPRINT Outfile," processId=fork();" + FPRINT Outfile," if(processId==0)" + FPRINT Outfile," {" + FPRINT Outfile," PCHAR argv[30];" + FPRINT Outfile," int i=0;" + FPRINT Outfile," while(*p)" + FPRINT Outfile," {" + FPRINT Outfile," if(*p==34)" + FPRINT Outfile," {" + FPRINT Outfile," while(*(++p)!=34) {}" + FPRINT Outfile," }" + FPRINT Outfile," if(*p==32)" + FPRINT Outfile," {" + FPRINT Outfile," while(*(p+1)==32) p++;" + FPRINT Outfile," argv[i++]=s;" + FPRINT Outfile," *p=0; s=p+1;" + FPRINT Outfile," }" + FPRINT Outfile," p++;" + FPRINT Outfile," }" + FPRINT Outfile," argv[i] = s;" + FPRINT Outfile," argv[i+1]= 0;" + FPRINT Outfile," execvp(argv[0],argv);" + FPRINT Outfile," printf(",ENC$("Failed to run%s\\n"),",argv[0]);" + FPRINT Outfile," exit(-1);" + FPRINT Outfile," }" + FPRINT Outfile," else if(processId!=-1)" + FPRINT Outfile," {" + FPRINT Outfile," if(WaitState) waitpid(processId,NULL,0);" + FPRINT Outfile," }" + FPRINT Outfile," waitpid(-1,NULL,WNOHANG);" + FPRINT Outfile," free(cmd_line), cmd_line=NULL;" + FPRINT Outfile," return processId;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Download THEN + FPRINT Outfile,"int Download (char *URL,char *Localname)" + FPRINT Outfile,"{" + FPRINT Outfile," int RetVal;" + '~ FPRINT Outfile," RetVal=BCX_DynaCall (", ENC$("URLDownloadToFile"), "," ; + '~ FPRINT Outfile, ENC$("urlmon.dll"), ",5,NULL,URL,Localname,0,NULL);" + FPRINT Outfile," return RetVal=!RetVal;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_PeekStr THEN + FPRINT Outfile,"char *peekstr (LPVOID Src, int Count)" + FPRINT Outfile,"{" + FPRINT Outfile," char *Des=BCX_TmpStr(Count);" + FPRINT Outfile," memmove(Des,Src,Count);" + FPRINT Outfile," return Des;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_QBColor THEN + FPRINT Outfile,"int qbcolor (int N)" + FPRINT Outfile,"{" + FPRINT Outfile," switch (N)" + FPRINT Outfile," {" + FPRINT Outfile," case 0 : return RGB(0,0,0);" + FPRINT Outfile," case 1 : return RGB(0,0,128);" + FPRINT Outfile," case 2 : return RGB(0,128,0);" + FPRINT Outfile," case 3 : return RGB(0,128,128);" + FPRINT Outfile," case 4 : return RGB(196,0,0);" + FPRINT Outfile," case 5 : return RGB(128,0,128);" + FPRINT Outfile," case 6 : return RGB(128,64,0);" + FPRINT Outfile," case 7 : return RGB(196,196,196);" + FPRINT Outfile," case 8 : return RGB(128,128,128);" + FPRINT Outfile," case 9 : return RGB(0,0, 255);" + FPRINT Outfile," case 10 : return RGB(0,255,0);" + FPRINT Outfile," case 11 : return RGB(0,255,255);" + FPRINT Outfile," case 12 : return RGB(255,0,0);" + FPRINT Outfile," case 13 : return RGB(255,0,255);" + FPRINT Outfile," case 14 : return RGB(255,255,0);" + FPRINT Outfile," case 15 : return RGB(255,255,255);" + FPRINT Outfile," case 16 : return RGB(164,164,164);" + FPRINT Outfile," case 17 : return RGB(128,160,255);" + FPRINT Outfile," case 18 : return RGB(160,255,160);" + FPRINT Outfile," case 19 : return RGB(160,255,255);" + FPRINT Outfile," case 20 : return RGB(255,160,160);" + FPRINT Outfile," case 21 : return RGB(255,160,255);" + FPRINT Outfile," case 22 : return RGB(255,255,160);" + FPRINT Outfile," case 23 : return RGB(212,212,212);" + FPRINT Outfile," case 24 : return RGB(180,180,180);" + FPRINT Outfile," case 25 : return RGB(188,220,255);" + FPRINT Outfile," case 26 : return RGB(220,255,220);" + FPRINT Outfile," case 27 : return RGB(220,255,255);" + FPRINT Outfile," case 28 : return RGB(255,220,220);" + FPRINT Outfile," case 29 : return RGB(255,220,255);" + FPRINT Outfile," case 30 : return RGB(255,255,220);" + FPRINT Outfile," case 31 : return RGB(228,228,228);" + FPRINT Outfile," }" + FPRINT Outfile,"return 0;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Cvi THEN + FPRINT Outfile,"short CVI (char *s)" + FPRINT Outfile,"{" + FPRINT Outfile," return ((short*)s)[0];" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Mki THEN + FPRINT Outfile,"char *MKI (short cvt)" + FPRINT Outfile,"{" + FPRINT Outfile," static char temp[3];" + FPRINT Outfile," return (char *)memmove(temp,&cvt,2);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Cvl THEN + FPRINT Outfile,"long CVL (char *s)" + FPRINT Outfile,"{" + FPRINT Outfile," return ((long*)s)[0];" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Mkl THEN + FPRINT Outfile,"char *MKL (int cvt)" + FPRINT Outfile,"{" + FPRINT Outfile," static char temp[5];" + FPRINT Outfile," return (char *) memmove(temp,&cvt,4);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Cvs THEN + FPRINT Outfile,"float CVS (char *s)" + FPRINT Outfile,"{" + FPRINT Outfile," return ((float*)s)[0];" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Mks THEN + FPRINT Outfile,"char *MKS (float cvt)" + FPRINT Outfile,"{" + FPRINT Outfile," static char temp[5];" + FPRINT Outfile," return (char *) memmove(temp,&cvt,4);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Cvd THEN + FPRINT Outfile,"double CVD (char *s)" + FPRINT Outfile,"{" + FPRINT Outfile," return ((double*)s)[0];" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Cvld THEN + FPRINT Outfile,"long double CVLD (char *s)" + FPRINT Outfile,"{" + FPRINT Outfile," return ((long double*)s)[0];" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Mkd THEN + FPRINT Outfile,"char *MKD (double cvt)" + FPRINT Outfile,"{" + FPRINT Outfile," static char temp[9];" + FPRINT Outfile," return (char *) memmove(temp,&cvt,8);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_Mkld THEN + FPRINT Outfile,"char *MKLD (long double cvt)" + FPRINT Outfile,"{" + FPRINT Outfile," static char temp[11];" + FPRINT Outfile," return (char *) memmove(temp,&cvt,10);" + FPRINT Outfile,"}\n\n" + END IF + IF Use_BcxSplitPath THEN + FPRINT Outfile,"char *BcxSplitPath (char *FPath, int mask)" + FPRINT Outfile,"{" + FPRINT Outfile," if(!FPath) return BCX_TmpStr(1);" + FPRINT Outfile," char *BCX_RetStr=BCX_TmpStr(strlen(FPath));" + FPRINT Outfile," char tmp[MAX_PATH*4];" + FPRINT Outfile," _splitpath_(FPath,tmp,&tmp[MAX_PATH],&tmp[MAX_PATH*2],&tmp[MAX_PATH*3]);" + FPRINT Outfile," if(mask & FDRV) strcat(BCX_RetStr,tmp);" + FPRINT Outfile," if(mask & FPATH)strcat(BCX_RetStr,&tmp[MAX_PATH]);" + FPRINT Outfile," if(mask & FNAME)strcat(BCX_RetStr,&tmp[MAX_PATH*2]);" + FPRINT Outfile," if(mask & FEXT) strcat(BCX_RetStr,&tmp[MAX_PATH*3]);" + FPRINT Outfile," return BCX_RetStr;" + FPRINT Outfile,"}\n\n" + FPRINT Outfile," void _splitpath_(const char* path, char* drv, char* dir, char* name, char* ext)" + FPRINT Outfile," {" + FPRINT Outfile," const char* pend; /* end of processed string */" + FPRINT Outfile," const char* p; /* search pointer */" + FPRINT Outfile," const char* s; /* copy pointer */" + FPRINT Outfile," " + FPRINT Outfile," /* extract drive name */" + FPRINT Outfile," if (path[0] && path[1]==':') {" + FPRINT Outfile," if (drv) {" + FPRINT Outfile," *drv++ = *path++;" + FPRINT Outfile," *drv++ = *path++;" + FPRINT Outfile," *drv = 0;" + FPRINT Outfile," }" + FPRINT Outfile," } else if (drv)" + FPRINT Outfile," *drv = 0;" + FPRINT Outfile," " + FPRINT Outfile," /* search for end of string or stream separator */" + FPRINT Outfile," for(pend=path; *pend && *pend!=':'; )" + FPRINT Outfile," pend++;" + FPRINT Outfile," " + FPRINT Outfile," /* search for begin of file extension */" + FPRINT Outfile," for(p=pend; p > path && *--p != '\\\\' && *p!='/'; )" + FPRINT Outfile," if (*p == '.') {" + FPRINT Outfile," pend = p;" + FPRINT Outfile," break;" + FPRINT Outfile," }" + FPRINT Outfile," " + FPRINT Outfile," if (ext)" + FPRINT Outfile," {" + FPRINT Outfile," s=pend;" + FPRINT Outfile," do{ *ext++ = *s; } while(*s++);" + FPRINT Outfile," }" + FPRINT Outfile," /* search for end of directory name */" + FPRINT Outfile," for(p=pend; p > path; )" + FPRINT Outfile," if (*--p == '\\\\' || *p == '/') {" + FPRINT Outfile," p++;" + FPRINT Outfile," break;" + FPRINT Outfile," }" + FPRINT Outfile," " + FPRINT Outfile," if (name) {" + FPRINT Outfile," for(s=p; stally(Source,TokenChar)+1)" + FPRINT Outfile," {" + FPRINT Outfile," BCX_RetStr=BCX_TmpStr(1);" + FPRINT Outfile," if(RetVal)free(RetVal);" + FPRINT Outfile," return BCX_RetStr;" + FPRINT Outfile," }" + FPRINT Outfile," while(*Copy)" + FPRINT Outfile," {" + FPRINT Outfile," if(*Copy==TokenChar[0]) Find++;" + FPRINT Outfile," if(Find==n) break;" + FPRINT Outfile," Copy++;" + FPRINT Outfile," Posn++;" + FPRINT Outfile," }" + FPRINT Outfile," if(n==tally(Source,TokenChar)+1)" + FPRINT Outfile," {" + FPRINT Outfile," Posn=LenSrc;" + FPRINT Outfile," Copy=Source+Posn;" + FPRINT Outfile," while(*Copy&&Source[Posn]!=TokenChar[0])" + FPRINT Outfile," {" + FPRINT Outfile," Posn--;" + FPRINT Outfile," Copy--;" + FPRINT Outfile," }" + FPRINT Outfile," }" + FPRINT Outfile," strcpy(RetVal,(char*)mid(Source,1,Posn));" + FPRINT Outfile," strcpy(RetVal,(char*)mid(RetVal,InstrRev(RetVal,TokenChar)));" + FPRINT Outfile," BCX_RetStr=BCX_TmpStr(LenSrc);" + FPRINT Outfile," strcpy(BCX_RetStr,(char*)RemoveStr(RetVal,TokenChar));" + FPRINT Outfile," if(RetVal)free(RetVal);" + FPRINT Outfile," return BCX_RetStr;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_iReplace THEN + FPRINT Outfile,"char *iReplace (char *src, char *pat, char *rep)" + FPRINT Outfile,"{" + FPRINT Outfile," size_t patsz, repsz, tmpsz, delta;" + FPRINT Outfile," char *strtmp, *p, *q, *r;" + FPRINT Outfile," if (!pat || !*pat)" + FPRINT Outfile," {" + FPRINT Outfile," strtmp = BCX_TmpStr(strlen(src));" + FPRINT Outfile," if (!strtmp) return NULL;" + FPRINT Outfile," return strcpy(strtmp, src);" + FPRINT Outfile," }" + FPRINT Outfile," repsz = strlen(rep);" + FPRINT Outfile," patsz = strlen(pat);" + FPRINT Outfile," for (tmpsz=0, p=src;(q=_stristr_(p,pat))!=0; p=q+patsz)" + FPRINT Outfile," tmpsz += (size_t) (q - p) + repsz;" + FPRINT Outfile," tmpsz += strlen(p);" + FPRINT Outfile," strtmp = BCX_TmpStr(tmpsz);" + FPRINT Outfile," if (!strtmp) return NULL;" + FPRINT Outfile," for (r=strtmp,p=src;(q=_stristr_(p,pat))!=0;p=q+patsz)" + FPRINT Outfile," {" + FPRINT Outfile," delta = (size_t) (q-p);" + FPRINT Outfile," memcpy(r,p,delta); r += delta;" + FPRINT Outfile," strcpy(r,rep); r += repsz;" + FPRINT Outfile," }" + FPRINT Outfile," strcpy(r,p);" + FPRINT Outfile," return strtmp;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_WideToAnsi THEN + FPRINT Outfile,"char* WideToAnsi (wchar_t *WideStr, UINT CodePage,DWORD dwFlags)" + FPRINT Outfile,"{" + FPRINT Outfile," char *BCX_RetStr={0};" + FPRINT Outfile," UINT uLen;" + FPRINT Outfile," uLen=wcstombs(NULL, WideStr, 0); //WideCharToMultiByte(CodePage,dwFlags,WideStr,-1,0,0,0,0);" + FPRINT Outfile," BCX_RetStr=(char*)BCX_TmpStr(uLen);" + FPRINT Outfile," wcstombs(BCX_RetStr, WideStr, uLen); //WideCharToMultiByte(CodePage,dwFlags,WideStr,-1,BCX_RetStr,uLen,0,0);" + FPRINT Outfile," return BCX_RetStr;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_SysStr THEN + FPRINT Outfile,"BSTR SysStr (char * szIn, int widstr, int bfree)" + FPRINT Outfile,"{" + FPRINT Outfile," static BSTR bStr[32];" + FPRINT Outfile," static int index;" + FPRINT Outfile," if(bfree)" + FPRINT Outfile," {" + FPRINT Outfile," for(index=0; index<32; index+=1) " + FPRINT Outfile," SysFreeString(bStr[index]);" + FPRINT Outfile," return 0;" + FPRINT Outfile," }" + FPRINT Outfile," index=(++index & 31);" + FPRINT Outfile," SysFreeString(bStr[index]);" + FPRINT Outfile," int length=strlen(szIn);" + FPRINT Outfile," if(widstr)" + FPRINT Outfile," {" + FPRINT Outfile," bStr[index]=SysAllocStringLen(NULL, (2*length));" + FPRINT Outfile," MultiByteToWideChar(CP_ACP,0,szIn,-1,bStr[index],(2*length+1));" + FPRINT Outfile," }else{" + FPRINT Outfile," bStr[index]=SysAllocStringByteLen(szIn, length);" + FPRINT Outfile," }" + FPRINT Outfile," return bStr[index];" + FPRINT Outfile,"}\n\n" + END IF + IF Use_AnsiToWide THEN + FPRINT Outfile,"wchar_t *AnsiToWide (char *AnsiStr, UINT CodePage,DWORD dwFlags)" + FPRINT Outfile,"{" + FPRINT Outfile," UINT uLen;" + FPRINT Outfile," wchar_t *WideStr;" + FPRINT Outfile," uLen=mbstowcs(NULL, AnsiStr, 0); //MultiByteToWideChar(CodePage,dwFlags,AnsiStr,-1,0,0);" + FPRINT Outfile," if(uLen<=1) return (wchar_t*)BCX_TmpStr(2);" + FPRINT Outfile," WideStr = (wchar_t*)BCX_TmpStr(2*uLen);" + FPRINT Outfile," mbstowcs(WideStr, AnsiStr, uLen); //MultiByteToWideChar(CodePage,dwFlags,AnsiStr,uLen,WideStr,uLen);" + FPRINT Outfile," return WideStr;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_FileLocked THEN + FPRINT Outfile,"int FileLocked (char *Filename)" + FPRINT Outfile,"{" + FPRINT Outfile," FILE *FP=fopen(Filename,", ENC$("rb+"), ");" + FPRINT Outfile," if(FP==0) return 1;" + FPRINT Outfile," fclose(FP);" + FPRINT Outfile," return 0;" + FPRINT Outfile,"}\n\n" + END IF + + IF Use_ContainedIn THEN + FPRINT Outfile,"int containedin(char * Token,char **Contain ,int c)" + FPRINT Outfile," {" + FPRINT Outfile," int i=0;" + FPRINT Outfile," while(Contain[i][0])" + FPRINT Outfile," {" + FPRINT Outfile," if(0 == ((c == 0 || c == 2) ? strcmp(Contain[i],Token) : strcasecmp(Contain[i],Token)))" + FPRINT Outfile," {" + FPRINT Outfile," return ((c < 2) ? 0 : i);" + FPRINT Outfile," }" + FPRINT Outfile," i++;" + FPRINT Outfile," }" + FPRINT Outfile," return -1;" + FPRINT Outfile," }\n\n" + END IF + IF Use_FindInType THEN + FPRINT Outfile,"int FindInType(char *Token,char *StOffset,int StSize,int start,int finish,int c,int *idx)" + FPRINT Outfile," {" + FPRINT Outfile," int j;" + FPRINT Outfile," char *Srch;" + FPRINT Outfile," int (*cmp)(const char*,const char*);" + FPRINT Outfile," cmp = ((c == 0 || c == 2) ? strcmp : strcasecmp);" + FPRINT Outfile," for(j=start; j<=finish; j++)" + FPRINT Outfile," {" + FPRINT Outfile," Srch = StOffset + ((idx==0) ? j*StSize : idx[j]*StSize);" + FPRINT Outfile," if(cmp(Srch,Token)==0)" + FPRINT Outfile," {" + FPRINT Outfile," return ((c < 2) ? 0 : j);" + FPRINT Outfile," }" + FPRINT Outfile," }" + FPRINT Outfile," return -1;" + FPRINT Outfile," }\n\n" + END IF + IF Use_StartupCode THEN + FPRINT Outfile,"int BCX_StartupCode_(void)" + FPRINT Outfile,"{" + FOR INTEGER i = 1 TO StartNdx + FPRINT Outfile," " + StartSub$[i] + "();" + NEXT + FPRINT Outfile," return 1;" + FPRINT Outfile,"}\n\n" + END IF + IF Use_ExitCode THEN + FPRINT Outfile,"int BCX_ExitCode_(void)" + FPRINT Outfile,"{" + FOR INTEGER i = 1 TO ExitNdx + FPRINT Outfile," atexit(" + ExitSub$[i] + ");" + NEXT + FPRINT Outfile," return 1;" + FPRINT Outfile,"}\n\n" + END IF + + if Use_Socket then + FPRINT Outfile,"sockaddr_in sock_addr (char *ServerName,int port)" + FPRINT Outfile,"{" + FPRINT Outfile," in_addr iaHost;" + FPRINT Outfile," hostent* lpHostEntry;" + FPRINT Outfile," sockaddr_in saServer;" + FPRINT Outfile," iaHost.s_addr=inet_addr(ServerName);" + FPRINT Outfile," if(iaHost.s_addr==INADDR_NONE)" + FPRINT Outfile," {" + FPRINT Outfile," lpHostEntry=gethostbyname(ServerName);" + FPRINT Outfile," }" + FPRINT Outfile," else" + FPRINT Outfile," {" + FPRINT Outfile," lpHostEntry=gethostbyaddr((char*)&iaHost,sizeof(in_addr),AF_INET);" + FPRINT Outfile," }" + FPRINT Outfile," if(lpHostEntry==NULL)" + FPRINT Outfile," {" + FPRINT Outfile," printf("+enc$("Error! HOST NOT FOUND: %s\\n")+", ServerName);" + FPRINT Outfile," }" + FPRINT Outfile," else" + FPRINT Outfile," {" + FPRINT Outfile," saServer.sin_port=htons(port);" + FPRINT Outfile," saServer.sin_family=AF_INET;" + FPRINT Outfile," saServer.sin_addr=*(in_addr*)lpHostEntry->h_addr;" + FPRINT Outfile," }" + FPRINT Outfile," return saServer;" + FPRINT Outfile,"}\n\n" + + + FPRINT Outfile,"int connect_socket (sockaddr_in saServer)" + FPRINT Outfile,"{" + FPRINT Outfile," int Socket, nRet;" + FPRINT Outfile," Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);" + FPRINT Outfile," if(Socket==-1)" + FPRINT Outfile," {" + FPRINT Outfile," return Socket;" + FPRINT Outfile," }" + FPRINT Outfile," nRet=connect(Socket,(sockaddr*)&saServer,sizeof(sockaddr_in));" + FPRINT Outfile," if(nRet==-1)" + FPRINT Outfile," {" + FPRINT Outfile," close(Socket);" + FPRINT Outfile," return nRet;" + FPRINT Outfile," }" + FPRINT Outfile," return Socket;" + FPRINT Outfile,"}\n\n" + + + FPRINT Outfile,"int BcxSocket (char *ServerName,int port)" + FPRINT Outfile,"{" + FPRINT Outfile," sockaddr_in saServer;" + FPRINT Outfile," saServer=sock_addr(ServerName,port);" + FPRINT Outfile," return connect_socket(saServer);" + FPRINT Outfile,"}\n\n" + + + FPRINT Outfile,"int BcxSocketSend (int Socket, char *szBuffer)" + FPRINT Outfile,"{" + FPRINT Outfile," static int nRet;" + FPRINT Outfile," nRet=send(Socket,szBuffer,strlen(szBuffer),0);" + FPRINT Outfile," if(nRet==-1)" + FPRINT Outfile," {" + FPRINT Outfile," close(Socket);" + FPRINT Outfile," }" + FPRINT Outfile," return nRet;" + FPRINT Outfile,"}\n\n" + + + FPRINT Outfile,"int BcxSocketRead (int Socket, char *szBuffer)" + FPRINT Outfile,"{" + FPRINT Outfile," return read(Socket,szBuffer,strlen(szBuffer));" + FPRINT Outfile,"}\n\n" + FPRINT Outfile,"void BcxSocketClose(int Socket) {" + FPRINT Outfile," close(Socket);" + FPRINT Outfile,"}\n\n" + end if + + '/***** 2013-06-26 New REGEX Keywords -AIR *****/ + '/***** 2018-12-12 Changed to regmatch -AIR *****/ + IF Use_RegEx THEN + FPRINT Outfile,"bool regmatch (char *buffer, char *pattern, REGEX* retval)" + FPRINT Outfile,"{" + FPRINT Outfile," static int t;" +' FPRINT Outfile," memset(&t,0,sizeof(t));" + FPRINT Outfile," static int i;" +' FPRINT Outfile," memset(&i,0,sizeof(i));" + FPRINT Outfile," static regex_t re;" +' FPRINT Outfile," memset(&re,0,sizeof(re));" + FPRINT Outfile," t=regcomp( &re,pattern,REG_ICASE|REG_EXTENDED);" + FPRINT Outfile," if(t)" + FPRINT Outfile," {" + FPRINT Outfile," regerror(t, &re,buffer,sizeof(buffer));" + FPRINT Outfile," printf("+enc$("regex error: %s %s")+",buffer,pattern);" + FPRINT Outfile," return 0;" + FPRINT Outfile," }" + FPRINT Outfile," t=regexec( &re,buffer,1023,(*retval).matches,0);" + FPRINT Outfile," (*retval).count=re.re_nsub;" + FPRINT Outfile," if(!t)" + FPRINT Outfile," {" + FPRINT Outfile," for(i=1; i<=(*retval).count; i+=1)" + FPRINT Outfile," {" + FPRINT Outfile," if((*retval).matches[i].rm_so>=0)" + FPRINT Outfile," {" + FPRINT Outfile," (*retval).results[i]=peekstr( &buffer[(*retval).matches[i].rm_so],((*retval).matches[i].rm_eo-(*retval).matches[i].rm_so));" + FPRINT Outfile," }" + FPRINT Outfile," }" + FPRINT Outfile," }" + FPRINT Outfile," regfree( &re);" + FPRINT Outfile," if(!t)" + FPRINT Outfile," {" + FPRINT Outfile," return TRUE;" + FPRINT Outfile," }" + FPRINT Outfile," else" + FPRINT Outfile," {" + FPRINT Outfile," return FALSE;" + FPRINT Outfile," }" + FPRINT Outfile,"}\n\n" + + END IF +END SUB 'RunTimeFunctions \ No newline at end of file diff --git a/std_macros.bas b/std_macros.bas new file mode 100644 index 0000000..4878539 --- /dev/null +++ b/std_macros.bas @@ -0,0 +1,106 @@ + FPRINT Outfile,"" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// " + $BCX_STR_STD_MACROS + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"" + + IF Use_BcxSplitPath THEN + FPRINT Outfile,"#define FDRV 2" + FPRINT Outfile,"#define FPATH 4" + FPRINT Outfile,"#define FNAME 8" + FPRINT Outfile,"#define FEXT 16" + END IF + + IF Use_Cbool THEN + FPRINT Outfile,"#define CBOOL(A)(A!=0)?1:0" + END IF + + IF Use_Isptr THEN + FPRINT Outfile,"#define IsPtr(a)((DWORD)a)" + END IF + + IF Use_Band THEN + FPRINT Outfile,"#define BAND &" + END IF + + IF Use_Bor THEN + FPRINT Outfile,"#define BOR |" + END IF + + IF Use_Bnot THEN + FPRINT Outfile,"#define BNOT ~(int)" + END IF + + IF Use_Ubound THEN + FPRINT Outfile,"#define ubound(T)(sizeof((T))/sizeof((T[0]))-1)" + END IF + + IF Use_Clear THEN + FPRINT Outfile,"#define Clear(arg)memset(&arg,0,sizeof(arg))" + END IF + + IF Use_Imod THEN + FPRINT Outfile,"#define imod(a,b)((a)%(b))" + END IF + + IF Use_Get THEN + FPRINT Outfile,"#define GET(A,B,C) F_GetVal=fread(B,1,C,A)" + CALL AddGlobal("F_GetVal", vt_INTEGER , 0,"",0,0,0,0) + END IF + + IF Use_Put THEN + FPRINT Outfile,"#define PUT(A,B,C) F_PutVal=fwrite(B,1,C,A)" + CALL AddGlobal("F_PutVal", vt_INTEGER , 0,"",0,0,0,0) + END IF + + IF Use_Strptr THEN + FPRINT Outfile,"#define STRPTR(A)((char*)&(A))" + END IF + + IF Use_Val THEN + FPRINT Outfile,"#define VAL(a)(double)atof(a)" + END IF + + IF Use_Vall THEN + FPRINT Outfile,"#define VALL(a) (long double)strtold(a,(char**)NULL)" + END IF + + IF Use_Fint THEN + FPRINT Outfile,"#define FINT(a)floor(a)" + END IF + + IF Use_Frac THEN + FPRINT Outfile,"#define FRAC(a)(double)(a-FIX(a))" + Use_Fix = TRUE + END IF + + IF Use_Fracl THEN + FPRINT Outfile,"#define FRACL(a)(long double)(a-FIX(a))" + Use_Fix = TRUE + END IF + + IF Use_Fix THEN + FPRINT Outfile,"#define FIX(a)(int)((a))" + END IF + + IF Use_Csng THEN + FPRINT Outfile,"#define CSNG(a)((float)(a))" + END IF + + IF Use_Cdbl THEN + FPRINT Outfile,"#define CDBL(a)((double)(a))" + END IF + + IF Use_Cldbl THEN + FPRINT Outfile,"#define CLDBL(a)((long double)(a))" + END IF + + IF Use_Threads THEN + FPRINT Outfile,"#define BCX_THREAD(fn,arg) ({ pthread_t tid; pthread_create(&tid, NULL, (void*(*)(void*))fn, arg); tid;})" + FPRINT Outfile,"#define BCX_THREADWAIT(a) pthread_join(a, NULL)" + FPRINT Outfile,"#define BCX_INITLOCK(a) pthread_mutex_init(a, NULL)" + FPRINT Outfile,"#define BCX_THREADLOCK(a) pthread_mutex_lock (a)" + FPRINT Outfile,"#define BCX_THREADUNLOCK(a) pthread_mutex_unlock (a)" + FPRINT Outfile,"#define BCX_THREADKILL(t) pthread_cancel(t)" + FPRINT Outfile,"#define BCX_THREADEND pthread_exit(0)" + END IF diff --git a/std_prototypes.bas b/std_prototypes.bas new file mode 100644 index 0000000..a6df144 --- /dev/null +++ b/std_prototypes.bas @@ -0,0 +1,491 @@ + FPRINT Outfile,"" + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"// " + $BCX_STR_STD_PROTOS + FPRINT Outfile,"// *************************************************" + FPRINT Outfile,"" +IF NoRT=FALSE THEN + + IF Use_Clng THEN + FPRINT Outfile,"long CLNG(double);" + END IF + IF Use_Cint THEN + FPRINT Outfile,"int Cint(double);" + END IF + IF Use_StartupCode THEN + FPRINT Outfile,"int BCX_StartupCode_(void);" + END IF + IF Use_ExitCode THEN + FPRINT Outfile,"int BCX_ExitCode_(void);" + END IF + IF Use_Str_Cmp THEN + FPRINT Outfile,"int str_cmp(char*, char*);" + END IF + IF Use_Eof THEN + FPRINT Outfile,"int EoF (FILE*);" + END IF + IF Use_CopyFile THEN + FPRINT Outfile,"void CopyFile (char *,char *,int=FALSE);" + END IF + + IF Use_QBColor THEN + FPRINT Outfile,"int qbcolor (int);" + END IF + IF Use_Cls THEN + FPRINT Outfile,"void cls(void);" + END IF + IF Use_Color THEN + FPRINT Outfile,"void color (int,int);" + END IF + IF Use_Locate THEN + FPRINT Outfile,"void locate (int,int,int=1,int=12);" + END IF + IF Use_Run THEN + FPRINT Outfile,"int Run (char*, int =1, int =0);" + END IF + IF Use_Randomize THEN + FPRINT Outfile,"void randomize (unsigned int);" + END IF + IF Use_Midstr THEN + FPRINT Outfile,"void midstr (char*, int, int, char *);" + END IF + IF Use_Swap THEN + FPRINT Outfile,"void swap (UCHAR*,UCHAR*,int);" + END IF + + IF UseFlag THEN + FPRINT Outfile,"char* BCX_TmpStr(size_t);" + END IF + + IF Use_sziif THEN + FPRINT Outfile,"char* sziif (bool,char*,char*);" + END IF + IF Use_Using THEN + FPRINT Outfile,"char* Using (char*,double);" + END IF + IF Use_TempFileName THEN + FPRINT Outfile,"char* TempFileName (char*,char*);" + END IF + IF Use_AppExePath THEN + FPRINT Outfile,"char* AppExePath (void);" + END IF + IF Use_AppExeName THEN + FPRINT Outfile,"char* AppExeName (void);" + END IF + IF Use_Lcase THEN + FPRINT Outfile,"char* lcase (char*);" + END IF + IF Use_Ucase THEN + FPRINT Outfile,"char* ucase (char*);" + END IF + IF Use_Mid THEN + FPRINT Outfile,"char* mid (char*, int, int=-1);" + END IF + IF Use_Ltrim THEN + FPRINT Outfile,"char* ltrim (char*,char=32);" + END IF + IF Use_Rtrim THEN + FPRINT Outfile,"char* rtrim (char*,char=32);" + END IF + IF Use_Trim THEN + FPRINT Outfile,"char* trim (char*);" + END IF + IF Use_Strim THEN + FPRINT Outfile,"char* strim (char*);" + END IF + IF Use_Left THEN + FPRINT Outfile,"char* left (char*,int);" + END IF + IF Use_Right THEN + FPRINT Outfile,"char* right (char*,int);" + END IF + IF Use_Rpad THEN + FPRINT Outfile,"char* rpad (char*,int,int=32);" + END IF + IF Use_Lpad THEN + FPRINT Outfile,"char* lpad (char*,int,int=32);" + END IF + IF Use_String THEN + FPRINT Outfile,"char* stringx (int,int);" + END IF + IF Use_Repeat THEN + FPRINT Outfile,"char* repeat (int,char*);" + END IF + IF Use_Extract THEN + FPRINT Outfile,"char* extract (char*,char*);" + END IF + IF Use_Remain THEN + FPRINT Outfile,"char* remain (char*,char*);" + END IF + IF Use_Reverse THEN + FPRINT Outfile,"char* reverse (char*);" + END IF + IF Use_Command THEN + FPRINT Outfile,"char* command (int=-1);" + END IF + IF Use_Mcase THEN + FPRINT Outfile,"char* mcase (char*);" + END IF + IF Use_Replace THEN + FPRINT Outfile,"char* replace (char*,char*,char*);" + END IF + IF Use_iReplace THEN + FPRINT Outfile,"char* iReplace (char*,char*,char*);" + END IF + IF Use_Shell THEN + FPRINT Outfile,"void Shell (char *);" + END IF + IF Use_Space THEN + FPRINT Outfile,"char* space (int a);" + END IF + IF Use_Str THEN + FPRINT Outfile,"char* str (double);" + END IF + IF Use_Strl THEN + FPRINT Outfile,"char* strl (long double);" + END IF + IF Use_Findfirst THEN + FPRINT Outfile,"char* findfirst (char*, FILE_FIND_DATA*);" + END IF + IF Use_Findnext THEN + FPRINT Outfile,"char* findnext (FILE_FIND_DATA*);" + END IF + IF Use_Curdir THEN + FPRINT Outfile,"char* curdir (void);" + END IF + + IF Use_Sysdir THEN + FPRINT Outfile,"char* sysdir (void);" + END IF + IF Use_Tempdir THEN + FPRINT Outfile,"char* tempdir (void);" + END IF + IF Use_Environ THEN + FPRINT Outfile,"char* Environ (char*);" + END IF + IF Use_Boolstr THEN + FPRINT Outfile,"char* BoolStr (int);" + END IF + IF Use_Hex THEN + FPRINT Outfile,"char* hex (int);" + END IF + IF Use_Bin THEN + FPRINT Outfile,"char* Bin (int);" + END IF + IF Use_Oct THEN + FPRINT Outfile,"char* oct (int);" + END IF + IF Use_Now THEN + FPRINT Outfile,"char* now (void);" + END IF + IF Use_SearchPath THEN + FPRINT Outfile,"char* SEARCHPATH (char *);" + END IF + IF Use_StrUpLow THEN + FPRINT Outfile,"char* _strupr_(char *);" + FPRINT Outfile,"char* _strlwr_(char *);" + END IF + IF Use_BcxSplitPath THEN + FPRINT Outfile,"char* BcxSplitPath (char *, int);" + FPRINT Outfile,"void _splitpath_(const char* path, char* drv, char* dir, char* name, char* ext);" + END IF + + IF Use_Strtoken THEN + FPRINT Outfile,"char* StrToken (char*,char*,int);" + END IF + IF Use_FileLocked THEN + FPRINT Outfile,"int FileLocked (char*);" + END IF + IF Use_FillArray THEN + FPRINT Outfile,"int fillarray (char *, int, int, void *);" + END IF + IF Use_Remove THEN + FPRINT Outfile,"char* RemoveStr (char*,char*);" + END IF + IF Use_IRemove THEN + FPRINT Outfile,"char* IRemoveStr (char*,char*);" + END IF + IF Use_Time THEN + FPRINT Outfile,"char* timef (int i=0);" + END IF + IF Use_Join THEN + FPRINT Outfile,"char* join (int, ... );" + END IF + IF Use_Enclose THEN + FPRINT Outfile,"char* enc (char*, int=0, int=0);" + END IF + IF Use_Chr THEN + FPRINT Outfile,"char* chr"; + FPRINT Outfile,"(int,int=0,int=0,int=0,int=0,int=0,int=0,int=0,int=0,int=0);" + END IF + IF Use_VChr THEN + FPRINT Outfile,"char* vchr (int,...);" + END IF + IF Use_Freefile THEN + FPRINT Outfile,"FILE* FreeFile (void);" + END IF + IF Use_PeekStr THEN + FPRINT Outfile,"char* peekstr (LPVOID,int);" + END IF + IF Use_Asc THEN + FPRINT Outfile,"int asc (char*,int=0);" + END IF + IF Use_Instrrev THEN + FPRINT Outfile,"int InstrRev (char*,char*,int=0,int=0);" + END IF + IF Use_Instr THEN + FPRINT Outfile,"int instr_b(char*,char*,int=0,int=0);" + END IF + IF UseLCaseTbl THEN + FPRINT Outfile,"char *MakeLCaseTbl(void);" + END IF + IF Use_Stristr THEN + FPRINT Outfile,"char *_stristr_(char*,char*);" + END IF + IF Use_StrStr THEN + FPRINT Outfile,"char *_strstr_(char*,char*);" + END IF + IF Use_Verify THEN + FPRINT Outfile,"int Verify (char *, char *);" + FPRINT Outfile,"int VerifyInstr(char*,char*,int=0);" + END IF + IF Use_Retain THEN + FPRINT Outfile,"char* Retain (char*,char *);" + END IF + IF Use_LoadFile THEN + FPRINT Outfile,"char* LoadFile (char*);" + END IF + IF Use_Inchr THEN + FPRINT Outfile,"int inchr (char*,char*);" + END IF + IF Use_Idxqsort THEN + FPRINT Outfile,"int IdxCompare (const void *,const void *);" + END IF + IF Use_IdxqsortSt THEN + FPRINT Outfile,"int IdxCompareSt (const void *,const void *);" + END IF + IF Use_PtrqsortSt THEN + FPRINT Outfile,"int PtrCompareSt (const void *,const void *);" + END IF + IF Use_Strqsorta THEN + FPRINT Outfile,"int StrCompareA (const void *,const void *);" + END IF + IF Use_Strqsortd THEN + FPRINT Outfile,"int StrCompareD (const void *,const void *);" + END IF + IF Use_DynStrqsorta THEN + FPRINT Outfile,"int DynStrCompareA (const void *,const void *);" + END IF + IF Use_DynStrqsortd THEN + FPRINT Outfile,"int DynStrCompareD (const void *,const void *);" + END IF + IF Use_Numqsortaint THEN + FPRINT Outfile,"int NumCompareAint (const void *,const void *);" + END IF + IF Use_Numqsortdint THEN + FPRINT Outfile,"int NumCompareDint (const void *,const void *);" + END IF + IF Use_Numqsortafloat THEN + FPRINT Outfile,"int NumCompareAfloat (const void *,const void *);" + END IF + IF Use_Numqsortdfloat THEN + FPRINT Outfile,"int NumCompareDfloat (const void *,const void *);" + END IF + IF Use_Numqsortadouble THEN + FPRINT Outfile,"int NumCompareAdouble (const void *,const void *);" + END IF + IF Use_Numqsortddouble THEN + FPRINT Outfile,"int NumCompareDdouble (const void *,const void *);" + END IF + IF Use_Like THEN + FPRINT Outfile,"int like (char*,char*);" + END IF + IF Use_Tally THEN + FPRINT Outfile,"int tally (char*,char*,int=0);" + END IF + IF Use_Inkey THEN + FPRINT Outfile,"char* inkey (void);" + END IF + IF Use_InkeyD THEN + FPRINT Outfile,"int inkeyd (void);" + END IF + '/***** 2010-12-08 Added to support INSTAT-AIR *****/ + IF Use_Instat THEN + FPRINT Outfile,"int kbhit(void);" + END IF + IF Use_GetCh THEN + FPRINT Outfile,"int _getch_(int);" + END IF + IF Use_Bin2dec THEN + FPRINT Outfile,"int Bin2Dec (char*);" + END IF + IF Use_Hex2Dec THEN + FPRINT Outfile,"int Hex2Dec (char*);" + END IF + IF Use_Download THEN + FPRINT Outfile,"int Download (char*,char*);" + END IF + + IF Use_Embed THEN + FPRINT Outfile,"char* GetResource (int* );" + END IF + + IF Use_Exist THEN + IF Use_Osx THEN + FPRINT Outfile,"bool Exist (char*);" + ELSE + FPRINT Outfile,"BOOL Exist (char*);" + END IF + + END IF + IF Use_Ins THEN + FPRINT Outfile,"char* ins (char *S, int i, char *a);" + END IF + IF Use_Del THEN + FPRINT Outfile,"char* del (char*,int,int);" + END IF + IF Use_Pause THEN + FPRINT Outfile,"void Pause (void);" + END IF + IF Use_Keypress THEN + FPRINT Outfile,"int keypress (void);" + END IF + IF Use_Lof THEN + FPRINT Outfile,"DWORD lof (char*);" + END IF + IF Use_Sgn THEN + FPRINT Outfile,"double sgn (double);" + END IF + IF Use_Round THEN + FPRINT Outfile,"double Round (double,int);" + END IF + IF Use_Rnd THEN + FPRINT Outfile,"float rnd (void);" + END IF + IF Use_Exp THEN + FPRINT Outfile,"double Exp (double);" + END IF + IF Use_Min THEN + FPRINT Outfile,"double _MIN_ (double,double);" + END IF + IF Use_Max THEN + FPRINT Outfile,"double _MAX_ (double,double);" + END IF + IF Use_Timer THEN + FPRINT Outfile,"float timer (void);" + END IF + IF Use_Iif THEN + FPRINT Outfile,"double iif (bool,double,double);" + END IF + IF Use_Loc THEN + FPRINT Outfile,"int loc (FILE *fp, int fplen);" + END IF + IF Use_Rec THEN + FPRINT Outfile,"int rec (FILE *fp, int fplen);" + END IF + IF Use_RecCount THEN + FPRINT Outfile,"int reccount (FILE *fp, int fplen);" + END IF + IF Use_Scan THEN + FPRINT Outfile,"int scan (char *input, char *format, ... );" + END IF + IF Use_Split THEN + FPRINT Outfile,"int Split (char [][65535], char*, char*, int=0);" + END IF + IF Use_DSplit THEN + FPRINT Outfile,"int DSplit (PCHAR *, char*, char*, int=0);" + END IF + IF Use_SysStr THEN + FPRINT Outfile,"BSTR SysStr (char * szIn, int=0, int=0);" + END IF + IF Use_WideToAnsi THEN + FPRINT Outfile,"char* WideToAnsi (wchar_t *, UINT=0, DWORD=0);" + END IF + IF Use_AnsiToWide THEN + FPRINT Outfile,"wchar_t* AnsiToWide (char*,UINT=0,DWORD=0);" + END IF + IF Use_Cvi THEN + FPRINT Outfile,"short CVI (char*);" + END IF + IF Use_Mki THEN + FPRINT Outfile,"char* MKI (short);" + END IF + IF Use_Cvl THEN + FPRINT Outfile,"long CVL (char*);" + END IF + IF Use_Mkl THEN + FPRINT Outfile,"char* MKL (int);" + END IF + IF Use_Cvs THEN + FPRINT Outfile,"float CVS (char*);" + END IF + IF Use_Mks THEN + FPRINT Outfile,"char* MKS (float);" + END IF + IF Use_Cvd THEN + FPRINT Outfile,"double CVD (char*);" + END IF + IF Use_Cvld THEN + FPRINT Outfile,"long double CVLD (char*);" + END IF + IF Use_Mkd THEN + FPRINT Outfile,"char* MKD (double);" + END IF + IF Use_Mkld THEN + FPRINT Outfile,"char* MKLD (long double);" + END IF + IF Use_OSVersion THEN + FPRINT Outfile,"int OSVersion (void);" + END IF + IF Use_Dynacall THEN + FPRINT Outfile,"HINSTANCE BCX_LoadDll(char *);" + FPRINT Outfile,"void BCX_UnloadDll(void);" + FPRINT Outfile,"typedef int (CALLBACK *DYNACALL1)(void);" + FPRINT Outfile,"int BCX_DynaCall(char *, char *, int, ...);" + END IF + IF Use_DynamicA THEN + FPRINT Outfile,"void* CreateArr (void*,int,int,int,...);" + FPRINT Outfile,"void* CreateArr_internal(void*, int, int, int, va_list);" + FPRINT Outfile,"void DestroyArr (void**,int,int);" + END IF + IF Use_ContainedIn THEN + FPRINT Outfile,"int containedin(char * ,char **,int=0);" + END IF + IF Use_FindInType THEN + FPRINT Outfile,"int FindInType(char *,char *,int,int,int,int=0,int* =0);" + END IF + IF Use_SingleFile = FALSE THEN + OPEN HFile$ FOR OUTPUT AS fpHFile + END IF + + '/***** 2010-11-10 emit wxApp Class Definition - AIR *****/ + /***** 2010-11-24 Change TO NOT emit wxApp CLASS Definition FOR WX CONSOLE Apps -AIR *****/ + '/***** 2010-12-01 Switched to using BCXSPLITPATH$ per James Fuller's suggestion -AIR *****/ + IF Use_Wx THEN + FPRINT Outfile,"" + FPRINT Outfile,"class ";bcxsplitpath$(FileIn$, FNAME);": public wxApp {" + FPRINT Outfile," public:" + FPRINT Outfile," virtual bool OnInit();" + FPRINT Outfile,"};" + FPRINT Outfile,"" + FPRINT Outfile,"IMPLEMENT_APP(";bcxsplitpath$(FileIn$, FNAME);")" + FPRINT Outfile,"" + END IF + + '/***** 2010-12-10 Socket Support -AIR *****/ + if Use_Socket then + FPRINT Outfile,"" + FPRINT Outfile,"sockaddr_in sock_addr (char* ,int=80);" + FPRINT Outfile,"int connect_socket (sockaddr_in);" + FPRINT Outfile,"int BcxSocket (char* ,int=80);" + FPRINT Outfile,"int BcxSocketSend (int, char *);" + FPRINT Outfile,"int BcxSocketRead (int, char *);" + FPRINT Outfile,"void BcxSocketClose(int);" + FPRINT Outfile,"" + end if + + '/***** 2013-06-26 New REGEX Keywords -AIR *****/ + IF Use_RegEx then + FPRINT Outfile,"bool regmatch (char *, char *, REGEX* );" + END IF + +END IF 'IF NoRT=FALSE \ No newline at end of file