ctpp2-2.8.3/ 0000755 0000000 0000000 00000000000 12056726603 011261 5 ustar root root ctpp2-2.8.3/LICENSE 0000644 0000000 0000000 00000002735 12006425304 012262 0 ustar root root
Copyright (c) 2006 - 2010 CTPP Team
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
4. Neither the name of the CTPP Team nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
ctpp2-2.8.3/TODO 0000644 0000000 0000000 00000000437 12006425304 011742 0 ustar root root Version 2
---------
TODO LIST
---------
!! - high priority
! - medium priority
. - low priority
----------------------------------------------------------------------------------
!!. Create compiler for new template tt2-like dialect
+. Examples and documentation
ctpp2-2.8.3/CHANGES 0000644 0000000 0000000 00000033113 12047435253 012253 0 ustar root root CTPP version 2.8.3 change log
-----------------------------
Legend
------
+ = New feature
* = Improved feature
- = Removed feature
! = Bug fixed
= = Unresolved
# = Other stuff
Version 2.8.3 (10.11.2012)
--------------------------
01. + Returned curly brakets as an alias for square
02. ! Fixed error reporting
Version 2.8.2 (13.06.2012)
--------------------------
01. - Removed the operator ...
02. - Removed __FIRST__, __LAST__, __INNER__, __ODD__, __COUNTER__, __EVEN__, __SIZE__, __CONTENT__
03. - Removed string compat old version in
04. - Removed the attribute 'map' in
05. - Removed functions: NUMERAL, ARRAY_ELEMENT, HASH_ELEMENT
06. ! Full support of variables in
07. + Support of hashes in
08. + New operator
09. + New attributes for iterator of : __first__, __last__, __index__, __key__, __inner__, __odd__, __even__, __size__
10. + New functions: CONTEXT, LIST
11. + Documentation of the CT++ template language (English version)
12. # Renamed JSESCAPE to JSONESCAPE. Refactored the code
13. # Performance boost for stream-like DumpJsonString fucntion
14. # Refactored code
Version 2.8.0 (28.12.2011)
--------------------------
01. * Improved access to arrays and hashes
Version 2.7.6 (28.12.2011)
--------------------------
01. ! Bug fixes
02. + Tests
Version 2.7.5 (23.12.2011)
--------------------------
01. ! Fixes in CDT::operator=
02. ! Fixes in block parameters
Version 2.7.4 (19.12.2011)
--------------------------
01. ! Fixes in CDT::operator=
02. + New constant operator[INT_32] and constant operator[STLW::string]
Version 2.7.3 (14.11.2011)
--------------------------
01. ! Fixes in block arguments
02. ! New access operator [] for constant objects
Version 2.7.2 (05.10.2011)
--------------------------
01. ! Fixes in URI/URL Escape functions
02. ! Fixes codegenerator for call/block operators
Version 2.7.1 (04.07.2011)
--------------------------
01. + New operator ...
02. + New modifications of *ALL* operators allows cut leading and trailing spaces
03. + New implementation of GETTEXT function
04. ! Bug fixes
Version 2.7.0 (23.05.2011)
--------------------------
01. + Access to arrays ahd hashes contents in variables
Version 2.6.15 (16.05.2011)
---------------------------
01. ! Fixes in TMPL_foreach translate map
Version 2.6.14 (28.04.2011)
---------------------------
01. ! Gettext patches
Version 2.6.13 (05.04.2011)
---------------------------
01. ! Fixes in SPRINTF function (thanks for patch to Varinov Nicolay )
02. New methods in CDT class: JoinArrayElements, JoinHashKeys, JoinHashKeys, GetHashKeys, GetHashValues, MergeCDT
Version 2.6.12 (15.03.2011)
---------------------------
01. ! Fixes in Unicode unescape algorithm, thanks to
Version 2.6.11 (28.02.2011)
---------------------------
01. * Fixes in CTPP2DTOA.cpp, thanks to Vincent
Version 2.6.10 (11.02.2011)
---------------------------
01. * Fixes in SPRINTF function (thanks for patch to Varinov Nicolay )
Version 2.6.9 (09.02.2011)
--------------------------
01. * New function: HOSTNAME
Version 2.6.8 (27.01.2011)
--------------------------
01. * New function: GET_TYPE, thanks to Tim Tavlintsev
Version 2.6.7 (01.11.2010)
--------------------------
01. * Dump/RecursiveDump improvements
02. * NUM_FORMAT improvements, thanks to Lunkov Alexander
03. ! SPRINTF %f/%e/%g format fixes, thanks to Vlad 'twilight' Maximov
Version 2.6.6 (05.10.2010)
--------------------------
01. ! Linux bug fixes
Version 2.6.5 (22.09.2010)
--------------------------
01. ! Fixes in CTPP2 dialect compiler, thanks to Vlad 'twilight' Maximov
Version 2.6.4 (20.09.2010)
--------------------------
01. * Fixes in SortArray method
Version 2.6.3 (27.07.2010)
--------------------------
01. ! Fixes in TMPL_foreach iterators (thanks to Kirichenko Sergey )
Version 2.6.2 (20.07.2010)
--------------------------
01. + CDT Swap method
02. + CDT SortArray method & helpers
Version 2.6.1 (15.06.2010)
--------------------------
01. ! Various bug fixes
02. # First stable version if branch 2.6
Version 2.6.0 (08.06.2010) (Technology Preview)
-----------------------------------------------
01. + New CDT implementation
02. + New contextual variables: __RCOUNTER__ & __OUTER__
03. + New function: HASH_ELEMENT
04. # System identificator changed from `Sanahin` to `Dzoraget`
05. # HUGE API changes
Version 2.5.19 (24.05.2010)
---------------------------
01. ! Math ops in Foreach cycle
Version 2.5.18 (09.04.2010)
---------------------------
01. ! Darwin OS fixes only (types)
Version 2.5.17 (02.04.2010)
---------------------------
01. + New function: SPRINTF
02. * StreamOutputCollector.hpp fixes
03. ! Fixes in template compiler(IsFloat mechanism)
Version 2.5.16 (11.02.2010)
---------------------------
01. # Bump Copyright year
02. + Documentation for functions NUMERAL, LIST_ELEMENT and ARRAY_ELEMENT
03. + English version of documentation (thanks to Alexey Kerdivare
04. * Function EscapeJSONString is now ECMA-262 compatible
Version 2.5.15 (30.12.2009)
---------------------------
01. ! Fixes in function NUM_FORMAT, thanks to http://ilnarb.livejournal.com/
Version 2.5.14 (02.12.2009)
---------------------------
01. + New method for class CDT: Erase. Erase element from hash by specified key name.
Version 2.5.13 (24.11.2009)
---------------------------
01. ! Fixes in Base64Encode function
Version 2.5.12 (18.10.2009)
---------------------------
01. + New data collector: C++ ostream collector (thanks to Chris Trees )
02. + Port to CygWin (thanks to NetImperia )
03. + New overloaded method for class CDT: Exist. Check existence of element.
04. ! Fixes in CDT class: pointer POINTER_VAL
Version 2.5.11 (27.08.2009)
---------------------------
01. ! Fixes in virtual machine (CMP instruction)
Version 2.5.10 (18.08.2009)
--------------------------_
01. + New functions: LIST_ELEMENT & ARRAY_ELEMENT
02. ! Fixes in JSON parser
Version 2.5.9 (13.08.2009)
--------------------------
01. ! Fixes in
Version 2.5.8 (05.08.2009)
--------------------------
01. * Completely rewrite code of JSON parser
Version 2.5.7 (24.06.2009)
--------------------------
01. + New function: NUMERAL
02. ! Fixes in TRUNCATE & MB_TRUNCATE functions
Version 2.5.6 (09.06.2009)
--------------------------
01. ! Fixes in JSESCAPE function
Version 2.5.5 (02.06.2009)
--------------------------
01. ! Fixes in math. expressions inside functions:
Version 2.5.4 (20.05.2009)
--------------------------
01. ! Fixes for MSVC 2008
02. ! Fixes in Win32/CryptoAPI
03. * Avoid a lot of warnings on gcc 4.3+
04. # #include <...> changed to #include "..." for all files of project
Version 2.5.3 (12.05.2009)
--------------------------
01. * Removed inline methods of exception classes
Version 2.5.2 (20.04.2009)
--------------------------
01. ! Bug fixes in branches inside foreach operator
Version 2.5.1 (17.04.2009)
--------------------------
01. ! Bug fixes in foreach operator
02. + Documentation for foreach operator
Version 2.5.0 (16.04.2009)
--------------------------
01. + New operator: )
03. ! EscapeJSONString empty string bug
04. # Port to MacOS X
05. - Removed CDT::operator+(std::string)
Version 2.4.3 (08.02.2009)
--------------------------
01. + Port to Microsoft (R) Windows (TM)
(thanks to vsheveliov )
Version 2.4.2 (25.01.2009)
--------------------------
01. * Fixed warnings in HashTable class
02. * Fixed incorrect default message in VMException
Version 2.4.1 (18.01.2009)
--------------------------
01. + New functions: JSON, JSESCAPE
02. * Documentation for new features
03. # Code cleanup
Version 2.4.0 (14.01.2009)
--------------------------
01. + New operators: )
Version 2.3.9 (12.09.2008)
--------------------------
01. * Improvements in parsing Non-HTML templates
Version 2.3.8 (05.09.2008)
--------------------------
01. + Port on SunOS 5.10 i386 and amd64
02. * CDT datatype improvements
Version 2.3.7 (02.09.2008)
--------------------------
01. + Nested loops from various data sources
02. ! Fixes in error handling
Version 2.3.6 (11.08.2008)
--------------------------
01. +
03. + Crossplatform format of executable bytecode file
04. + Check of CRC32 checksum for bytecode file
05. + New function: DEFINED. Check that value has not an UNDEF type.
06. ! Fixed error in multiple logical && and || comparison
Version 2.1.2 (28.03.2008)
--------------------------
01. + Renaming values in
Inverse to map (value : value_in_include) order of variables
Version 2.1.1 (19.03.2008)
--------------------------
01. + Renaming values in
Version 2.1.0 (14.03.2008)
--------------------------
01. + Arithmetic & string operations in operators
02. + New function: CAST. Cast to specified type.
03. # Up to 10% performance
Version 2.0.5 (02.03.2008)
--------------------------
01. + Namespaces in variable names ()
02. ! Bug fixes
Version 2.0.4 (18.02.2008)
--------------------------
01. + New contextual variable: __CONTENT__
02. + Small API changes, see file VMDumper.hpp
03. ! Linux RPATH bug fixes
Version 2.0.3 (15.02.2008)
--------------------------
01. ! Fixed "stack underflow" error in
02. + New functions: iconv and obj_dump
03. + Russian documentation (in HTML)
04. + New data collector class: StringOutputCollector
Version 2.0.2 (08.02.2008)
--------------------------
01. ! Bug fixes
02. + New functions: base64_encode, base64_decode and md5
Version 2.0.1 (04.02.2008)
--------------------------
01. ! Fixed "stack underflow" error in
02. + New method CDT::RecursiveDump
03. + FreeBSD port, Debian package, RPM spec file
Version 2.0.0 (15.01.2008)
--------------------------
01. # Initial revision
ctpp2-2.8.3/tests/ 0000755 0000000 0000000 00000000000 12056726603 012423 5 ustar root root ctpp2-2.8.3/tests/CTPP2JSONParser.cpp 0000644 0000000 0000000 00000006227 12006425304 015622 0 ustar root root /*-
* Copyright (c) 2006, 2007 CTPP Team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the CTPP Team nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* CTPP2JSONParser.cpp
*
* $CTPP$
*/
#include
#include
#include
#include
#include
#ifdef HAVE_SYSEXITS_H
#include
#endif
using namespace CTPP;
int main(int argc, char ** argv)
{
fprintf(stdout, "CTPP2 JSON parser v" CTPP_VERSION " (" CTPP_IDENT "). Copyright (c) 2004-2011 CTPP Dev. Team.\n\n");
if (argc != 2) { fprintf(stderr, "usage: %s file.json\n", argv[0]); return EX_USAGE; }
// Get file size
struct stat oStat;
if (stat(argv[1], &oStat) == -1 || oStat.st_size == 0) { fprintf(stderr, "ERROR: Cannot get size of file `%s`\n", argv[1]); return EX_SOFTWARE; }
// Load file
FILE * F = fopen(argv[1], "r");
if (F == NULL) { fprintf(stderr, "ERROR: Cannot open file `%s` for writing\n", argv[1]); return EX_SOFTWARE; }
// Allocate memory
CHAR_8 * szJSONBuffer = (CHAR_8 *)malloc(oStat.st_size + 1);
// Read from file
if (fread(szJSONBuffer, oStat.st_size, 1, F) != 1)
{
fprintf(stderr, "ERROR: Cannot read from file `%s`\n", argv[1]);
fclose(F);
free(szJSONBuffer);
return EX_SOFTWARE;
}
szJSONBuffer[oStat.st_size] = '\0';
CDT oCDT;
CTPP2JSONParser oJSONParser(oCDT);
CCHAR_P szEnd = szJSONBuffer + oStat.st_size;
try
{
oJSONParser.Parse(szJSONBuffer, szEnd);
}
catch(CTPPParserSyntaxError & e) { fprintf(stderr, "ERROR: At line %d, char %d: %s\n", e.GetLine(), e.GetLinePos(), e.what()); return EX_SOFTWARE; }
fprintf(stderr, "%s\n", oCDT.Dump().c_str());
// All Done
fclose(F);
// All done with loading
free(szJSONBuffer);
// make valgrind happy
fclose(stdin);
fclose(stdout);
fclose(stderr);
return EX_OK;
}
// End.
ctpp2-2.8.3/tests/VMEmulator.cpp 0000644 0000000 0000000 00000015071 12006425304 015153 0 ustar root root /*-
* Copyright (c) 2006, 2007 CTPP Team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the CTPP Team nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* VMEmulator.cpp
*
* $CTPP$
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef HAVE_SYS_TIME_H
#include
#endif
#ifdef WIN32
#include
#endif
#include
#include
using namespace CTPP;
int main(int argc, char ** argv)
{
INT_32 iRetCode = EX_SOFTWARE;
if (argc != 2 && argc != 3 && argc != 4)
{
fprintf(stdout, "CTPP2 virtual machine v" CTPP_VERSION " (" CTPP_IDENT "). Copyright (c) 2004-2011 CTPP Dev. Team.\n\n");
fprintf(stderr, "usage: %s file.name [data.json] [limit of steps]\n", argv[0]);
return EX_USAGE;
}
// Output
FileOutputCollector oOutputCollector(stdout);
// Initialize Standard CTPP library
SyscallFactory oSyscallFactory(100);
// Load standard library
STDLibInitializer::InitLibrary(oSyscallFactory);
UINT_32 iStepsLimit = 10240;
if(argc == 4) { iStepsLimit = atoi(argv[3]); }
else
{
fprintf(stderr, "WARNING: [limit of steps] not set, use default value of %d\n", iStepsLimit);
}
try
{
// Load program from file
VMFileLoader oLoader(argv[1]);
// Get program core
const VMMemoryCore * pVMMemoryCore = oLoader.GetCore();
CDT oHash(CDT::HASH_VAL);
// Load JSON data
if(argc >= 3)
{
struct stat oStat;
// Get file size
if (stat(argv[2], &oStat) == -1 || oStat.st_size == 0) { fprintf(stderr, "ERROR: Cannot get size of file `%s`\n", argv[2]); return EX_SOFTWARE; }
// Allocate memory
CHAR_8 * szJSONBuffer = (CHAR_8 *)malloc(oStat.st_size + 1);
// Read from file
FILE * F = fopen(argv[2], "rb");
if (F == NULL) { fprintf(stderr, "ERROR: Cannot open file `%s` for reading\n", argv[2]); return EX_SOFTWARE; }
fread(szJSONBuffer, oStat.st_size, 1, F);
szJSONBuffer[oStat.st_size] = '\0';
CTPP2JSONParser oJSONParser(oHash);
CCHAR_P szEnd = szJSONBuffer + oStat.st_size;
oJSONParser.Parse(szJSONBuffer, szEnd);
// All Done
fclose(F);
// All done with loading
free(szJSONBuffer);
}
else
{
fprintf(stderr, "WARNING: [data.json] not given\n");
}
// Logger
FileLogger oLogger(stderr);
// Run program
VM oVM(&oSyscallFactory, 10240, 10240, iStepsLimit);
UINT_32 iIP = 0;
struct timeval sTimeValLocBegin;
gettimeofday(&sTimeValLocBegin, NULL);
oVM.Init(pVMMemoryCore, &oOutputCollector, &oLogger);
oVM.Run(pVMMemoryCore, &oOutputCollector, iIP, oHash, &oLogger);
struct timeval sTimeValLocEnd;
gettimeofday(&sTimeValLocEnd, NULL);
fprintf(stderr, "Completed in %f seconds.\n", (1.0 * (sTimeValLocEnd.tv_sec - sTimeValLocBegin.tv_sec) + 1.0 * (sTimeValLocEnd.tv_usec - sTimeValLocBegin.tv_usec) / 1000000));
iRetCode = EX_OK;
}
// CDT
catch(CDTTypeCastException & e) { fprintf(stderr, "ERROR: Type Cast %s\n", e.what()); }
catch(CDTAccessException & e) { fprintf(stderr, "ERROR: Array index out of bounds: %s\n", e.what()); }
// Virtual machine
catch(IllegalOpcode & e) { fprintf(stderr, "ERROR: Illegal opcode 0x%08X at 0x%08X\n", e.GetOpcode(), e.GetIP()); }
catch(InvalidSyscall & e)
{
if (e.GetIP() != 0)
{
VMDebugInfo oVMDebugInfo(e.GetDebugInfo());
fprintf(stderr, "ERROR: %s at 0x%08X (Template file \"%s\", Line %d, Pos %d)\n", e.what(), e.GetIP(), e.GetSourceName(), oVMDebugInfo.GetLine(), oVMDebugInfo.GetLinePos());
}
else
{
fprintf(stderr, "Unsupported syscall: \"%s\"\n", e.what());
}
}
catch(InvalidCall & e)
{
VMDebugInfo oVMDebugInfo(e.GetDebugInfo());
fprintf(stderr, "ERROR: at 0x%08X: Invalid block name \"%s\" in file \"%s\", Line %d, Pos %d\n", e.GetIP(), e.what(), e.GetSourceName(), oVMDebugInfo.GetLine(), oVMDebugInfo.GetLinePos());
}
catch(CodeSegmentOverrun & e) { fprintf(stderr, "ERROR: %s at 0x%08X\n", e.what(), e.GetIP()); }
catch(StackOverflow & e) { fprintf(stderr, "ERROR: Stack overflow at 0x%08X\n", e.GetIP()); }
catch(StackUnderflow & e) { fprintf(stderr, "ERROR: Stack underflow at 0x%08X\n", e.GetIP()); }
catch(ExecutionLimitReached & e) { fprintf(stderr, "ERROR: Execution limit of %d step(s) reached at 0x%08X\n", iStepsLimit, e.GetIP()); }
catch(VMException & e) { fprintf(stderr, "ERROR: VM generic exception: %s at 0x%08X\n", e.what(), e.GetIP()); }
// CTPP
catch(CTPPLogicError & e) { fprintf(stderr, "ERROR: %s\n", e.what()); }
catch(CTPPUnixException & e) { fprintf(stderr, "ERROR: I/O in %s: %s\n", e.what(), strerror(e.ErrNo())); }
catch(CTPPException & e) { fprintf(stderr, "ERROR: CTPP Generic exception: %s\n", e.what()); }
// Destroy standard library
STDLibInitializer::DestroyLibrary(oSyscallFactory);
// make valgrind happy
fclose(stdin);
fclose(stdout);
fclose(stderr);
return iRetCode;
}
// End.
ctpp2-2.8.3/tests/CTPP2Compiler.cpp 0000644 0000000 0000000 00000007720 12006425304 015445 0 ustar root root /*-
* Copyright (c) 2006, 2007 CTPP Team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the CTPP Team nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* CTPP2Compiler.cpp
*
* $CTPP$
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace CTPP;
int main(int argc, char ** argv)
{
if (argc != 3)
{
fprintf(stdout, "CTPP2 template compiler v" CTPP_VERSION " (" CTPP_IDENT "). Copyright (c) 2004-2011 CTPP Dev. Team.\n\n");
fprintf(stderr, "usage: %s source.ctpp2 destination.ct2\n", argv[0]);
return EX_USAGE;
}
VMOpcodeCollector oVMOpcodeCollector;
StaticText oSyscalls;
StaticData oStaticData;
StaticText oStaticText;
HashTable oHashTable;
CTPP2Compiler oCompiler(oVMOpcodeCollector, oSyscalls, oStaticData, oStaticText, oHashTable);
try
{
// Load template
CTPP2FileSourceLoader oSourceLoader;
oSourceLoader.LoadTemplate(argv[1]);
// Create template parser
CTPP2Parser oCTPP2Parser(&oSourceLoader, &oCompiler, argv[1]);
// Compile template
oCTPP2Parser.Compile();
}
catch(CTPPLogicError & e)
{
fprintf(stderr, "ERROR: %s\n", e.what());
return EX_SOFTWARE;
}
catch(CTPPUnixException & e)
{
fprintf(stderr, "ERROR: I/O in %s: %s\n", e.what(), strerror(e.ErrNo()));
return EX_SOFTWARE;
}
catch(CTPPParserSyntaxError & e)
{
fprintf(stderr, "ERROR: At line %d, pos. %d: %s\n", e.GetLine(), e.GetLinePos(), e.what());
return EX_SOFTWARE;
}
catch (CTPPParserOperatorsMismatch &e)
{
fprintf(stderr, "ERROR: At line %d, pos. %d: expected %s, but found %s>\n", e.GetLine(), e.GetLinePos(), e.Expected(), e.Found());
return EX_SOFTWARE;
}
catch(...)
{
fprintf(stderr, "ERROR: Bad thing happened.\n");
return EX_SOFTWARE;
}
// Get program core
UINT_32 iCodeSize = 0;
const VMInstruction * oVMInstruction = oVMOpcodeCollector.GetCode(iCodeSize);
// Dump program
VMDumper oDumper(iCodeSize, oVMInstruction, oSyscalls, oStaticData, oStaticText, oHashTable);
UINT_32 iSize = 0;
const VMExecutable * aProgramCore = oDumper.GetExecutable(iSize);
// Open file only if compilation is done
FILE * FW = fopen(argv[2], "wb");
if (FW == NULL) { fprintf(stderr, "ERROR: Cannot open destination file `%s` for writing\n", argv[2]); return EX_SOFTWARE; }
// Write to the disc
fwrite(aProgramCore, iSize, 1, FW);
// All done
fclose(FW);
// Make valgrind happy
fclose(stdin);
fclose(stdout);
fclose(stderr);
return EX_OK;
}
// End.
ctpp2-2.8.3/tests/HashTest.cpp 0000644 0000000 0000000 00000004455 12006425304 014647 0 ustar root root /*-
* Copyright (c) 2006, 2007 CTPP Team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the CTPP Team nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* HashTest.hpp
*
* $CTPP$
*/
#include
#include
#ifdef HAVE_SYSEXITS_H
#include
#endif
using namespace CTPP;
int main(void)
{
HashTable oHashTable;
oHashTable.Put("1", 1, 12345);
oHashTable.Put("12", 2, 23456);
oHashTable.Put("123", 3, 34567);
oHashTable.Put("1234", 4, 45678);
oHashTable.Put("12345", 5, 56789);
fprintf(stdout, "1 => %d\n", INT_32(oHashTable.Get("1", 1)));
fprintf(stdout, "12 => %d\n", INT_32(oHashTable.Get("12", 2)));
fprintf(stdout, "123 => %d\n", INT_32(oHashTable.Get("123", 3)));
fprintf(stdout, "1234 => %d\n", INT_32(oHashTable.Get("1234", 4)));
fprintf(stdout, "12345 => %d\n", INT_32(oHashTable.Get("12345", 5)));
// make valgrind happy
fclose(stdin);
fclose(stdout);
fclose(stderr);
return EX_OK;
}
// End.
ctpp2-2.8.3/tests/VMDumperTest.cpp 0000644 0000000 0000000 00000005723 12006425304 015462 0 ustar root root /*-
* Copyright (c) 2006, 2007 CTPP Team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the CTPP Team nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* VMDumperTest.cpp
*
* $CTPP$
*/
#include
#include
#include
#include
#ifdef HAVE_SYS_TIME_H
#include
#endif
#include
#include
using namespace CTPP;
int main(int argc, char ** argv)
{
if (argc != 3)
{
fprintf(stderr, "usage: %s file_in.ct2 filename_out.ct2\n", argv[0]);
return EX_USAGE;
}
try
{
// Load program from file
VMFileLoader oLoader(argv[1]);
// Get program core
const VMMemoryCore * pVMMemoryCore = oLoader.GetCore();
// Dump program
VMDumper oDumper(*pVMMemoryCore);
UINT_32 iSize = 0;
const VMExecutable * aProgramCore = oDumper.GetExecutable(iSize);
// Open file only if compilation is done
FILE * FW = fopen(argv[2], "wb");
if (FW == NULL) { fprintf(stderr, "ERROR: Cannot open destination file `%s` for writing\n", argv[2]); return EX_SOFTWARE; }
// Write to the disc
fwrite(aProgramCore, iSize, 1, FW);
// All done
fclose(FW);
}
catch(CTPPLogicError & e) { fprintf(stderr, "ERROR: %s\n", e.what()); }
catch(CTPPUnixException & e) { fprintf(stderr, "ERROR: I/O in %s: %s\n", e.what(), strerror(e.ErrNo())); }
catch(std::exception & e) { fprintf(stderr, "ERROR: %s\n", e.what()); }
// make valgrind happy
fclose(stdin);
fclose(stdout);
fclose(stderr);
return EX_OK;
}
// End.
ctpp2-2.8.3/tests/BitIndexText.cpp 0000644 0000000 0000000 00000005743 12006425304 015500 0 ustar root root /*-
* Copyright (c) 2004 - 2011 CTPP Team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the CTPP Team nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* CTPP2BitIndex.cpp
*
* $CTPP$
*/
#include
#include
#ifdef HAVE_SYSEXITS_H
#include
#endif
using namespace CTPP;
#define C_BITS_NUM 13
int main(void)
{
BitIndex oBitIndex(C_BITS_NUM);
for (UINT_32 iI = 0; iI < C_BITS_NUM; ++iI)
{
oBitIndex.SetBit(iI, iI % 2);
fprintf(stderr, "%c", (iI % 2) ? '1' : '0');
}
fprintf(stderr, "\n");
for (UINT_32 iI = 0; iI < C_BITS_NUM; ++iI)
{
fprintf(stderr, "%c", oBitIndex.GetBit(iI) ? '1' : '0');
}
fprintf(stderr, "\n");
oBitIndex.SetBit(0, 1);
oBitIndex.SetBit(1, 1);
oBitIndex.SetBit(2, 1);
oBitIndex.SetBit(3, 0);
oBitIndex.SetBit(4, 0);
oBitIndex.SetBit(5, 0);
oBitIndex.SetBit(6, 1);
oBitIndex.SetBit(7, 1);
oBitIndex.SetBit(8, 1);
for (UINT_32 iI = 0; iI < C_BITS_NUM; ++iI)
{
fprintf(stderr, "%c", oBitIndex.GetBit(iI) ? '1' : '0');
}
fprintf(stderr, "\nExpand index:\n");
for (UINT_32 iI = C_BITS_NUM; iI < C_BITS_NUM * 2; ++iI)
{
oBitIndex.SetBit(iI, 0);
fprintf(stderr, "Bit %d, used bytes: %d\n", iI, oBitIndex.GetUsedSize());
}
fprintf(stderr, "\n");
for (UINT_32 iI = C_BITS_NUM; iI < C_BITS_NUM * 2; ++iI)
{
oBitIndex.SetBit(iI, iI % 2);
fprintf(stderr, "%c", (iI % 2) ? '1' : '0');
}
fprintf(stderr, "\n");
for (UINT_32 iI = 0; iI < C_BITS_NUM * 2; ++iI)
{
fprintf(stderr, "%c", oBitIndex.GetBit(iI) ? '1' : '0');
}
fprintf(stderr, "\n");
// make valgrind happy
fclose(stdin);
fclose(stdout);
fclose(stderr);
return EX_OK;
}
// End.
ctpp2-2.8.3/tests/SimpleVMTest.cpp 0000644 0000000 0000000 00000004466 12006425304 015462 0 ustar root root /*-
* Copyright (c) 2004 - 2010 CTPP Team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the CTPP Team nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* SimpleVMTest.hpp
*
* $CTPP$
*/
#include
#include
#include
#include
using namespace CTPP;
// test case
int main(int argc, char ** argv)
{
if (argc != 2) { fprintf(stderr, "usage: %s file.ct2\n", argv[0]); return EX_USAGE; }
SimpleVM oSimpleVM;
// Create data
CDT oHello;
oHello["hello"] = "Hello, World!";
// Load template file
VMFileLoader oLoader(argv[1]);
// Create logger object
FileLogger oLogger(stderr);
// Execute template and write data to standard output
oSimpleVM.Run(oHello, oLoader, stdout, oLogger);
// Execute template and write data to string
std::string sResult;
oSimpleVM.Run(oHello, oLoader, sResult, oLogger);
// Make Valgrind happy
fclose(stdin);
fclose(stdout);
fclose(stderr);
}
// End.
ctpp2-2.8.3/tests/CDTTest.cpp 0000644 0000000 0000000 00000101306 12006425304 014367 0 ustar root root /*-
* Copyright (c) 2004 - 2011 CTPP Team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the CTPP Team nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* CDTTest.cpp
*
* $CTPP$
*/
#include
#include
#include
#ifdef HAVE_SYSEXITS_H
#include
#endif
using namespace CTPP;
int main(void)
{
CDT oCDT = 10;
fprintf(stderr, "== INT ===================================\n");
fprintf(stderr, "Initial value: %d\n", INT_32(oCDT.GetInt()));
{
fprintf(stderr, "Post-increnent\n");
CDT oTMP = oCDT++;
fprintf(stderr, "TMP = CDT++: ");
fprintf(stderr, "%d -> %d\n\n", INT_32(oTMP.GetInt()), INT_32(oCDT.GetInt()));
}
{
fprintf(stderr, "Pre-increnent\n");
CDT oTMP = ++oCDT;
fprintf(stderr, "TMP = ++CDT: ");
fprintf(stderr, "%d -> %d\n\n", INT_32(oTMP.GetInt()), INT_32(oCDT.GetInt()));
}
{
fprintf(stderr, "Post-decrement\n");
CDT oTMP = oCDT--;
fprintf(stderr, "TMP = CDT--: ");
fprintf(stderr, "%d -> %d\n\n", INT_32(oTMP.GetInt()), INT_32(oCDT.GetInt()));
}
{
fprintf(stderr, "Pre-decrement\n");
CDT oTMP = --oCDT;
fprintf(stderr, "TMP = --CDT: ");
fprintf(stderr, "%d -> %d\n\n", INT_32(oTMP.GetInt()), INT_32(oCDT.GetInt()));
}
fprintf(stderr, "operator+=(INT_32)\n");
oCDT += 10;
fprintf(stderr, "CDT += 10 -> %d\n\n", INT_32(oCDT.GetInt()));
fprintf(stderr, "operator-=(INT_32)\n");
oCDT -= 10;
fprintf(stderr, "CDT -= 10 -> %d\n\n", INT_32(oCDT.GetInt()));
fprintf(stderr, "operator*=(INT_32)\n");
oCDT *= 10;
fprintf(stderr, "CDT *= 10 -> %d\n\n", INT_32(oCDT.GetInt()));
fprintf(stderr, "operator/=(INT_32)\n");
oCDT /= 10;
fprintf(stderr, "CDT /= 10 -> %d\n\n", INT_32(oCDT.GetInt()));
fprintf(stderr, "operator+(INT_32)\n");
oCDT = oCDT + 10;
fprintf(stderr, "CDT = CDT + 10 -> %d\n\n", INT_32(oCDT.GetInt()));
fprintf(stderr, "standalone operator+(int, CDT)\n");
oCDT = 10 + oCDT;
fprintf(stderr, "CDT = 10 + CDT -> %d\n\n", INT_32(oCDT.GetInt()));
fprintf(stderr, "operator-(INT_32)\n");
oCDT = oCDT - 10;
fprintf(stderr, "CDT = CDT - 10 -> %d\n\n", INT_32(oCDT.GetInt()));
fprintf(stderr, "standalone operator-(int, CDT)\n");
oCDT = 10 - oCDT;
fprintf(stderr, "CDT = 10 - CDT -> %d\n\n", INT_32(oCDT.GetInt()));
fprintf(stderr, "operator*(INT_32)\n");
oCDT = oCDT * 10;
fprintf(stderr, "CDT = CDT * 10 -> %d\n\n", INT_32(oCDT.GetInt()));
fprintf(stderr, "standalone operator*(int, CDT)\n");
oCDT = 10 * oCDT;
fprintf(stderr, "CDT = 10 * CDT -> %d\n\n", INT_32(oCDT.GetInt()));
fprintf(stderr, "operator/(INT_32)\n");
oCDT = oCDT / 10;
fprintf(stderr, "CDT = CDT * 10 -> %d\n\n", INT_32(oCDT.GetInt()));
fprintf(stderr, "standalone operator*(int, CDT)\n");
oCDT = 10 / oCDT;
fprintf(stderr, "CDT = 10 * CDT -> %d\n\n", INT_32(oCDT.GetInt()));
fprintf(stderr, "Auto-cast to float\n");
oCDT = -1.0 * oCDT;
fprintf(stderr, "CDT -> %f: %s\n\n", W_FLOAT(oCDT.GetFloat()), oCDT.PrintableType());
fprintf(stderr, "== REAL ===================================\n");
fprintf(stderr, "Initial value: %f\n", W_FLOAT(oCDT.GetFloat()));
{
fprintf(stderr, "Post-increnent\n");
CDT oTMP = oCDT++;
fprintf(stderr, "TMP = CDT++: ");
fprintf(stderr, "%f -> %f\n\n", W_FLOAT(oTMP.GetFloat()), W_FLOAT(oCDT.GetFloat()));
}
{
fprintf(stderr, "Pre-increnent\n");
CDT oTMP = ++oCDT;
fprintf(stderr, "TMP = ++CDT: ");
fprintf(stderr, "%f -> %f\n\n", W_FLOAT(oTMP.GetFloat()), W_FLOAT(oCDT.GetFloat()));
}
{
fprintf(stderr, "Post-decrement\n");
CDT oTMP = oCDT--;
fprintf(stderr, "TMP = CDT--: ");
fprintf(stderr, "%f -> %f\n\n", W_FLOAT(oTMP.GetFloat()), W_FLOAT(oCDT.GetFloat()));
}
{
fprintf(stderr, "Pre-decrement\n");
CDT oTMP = --oCDT;
fprintf(stderr, "TMP = --CDT: ");
fprintf(stderr, "%f -> %f\n\n", W_FLOAT(oTMP.GetFloat()), W_FLOAT(oCDT.GetFloat()));
}
fprintf(stderr, "operator+=(INT_32)\n");
oCDT += 10;
fprintf(stderr, "CDT += 10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator-=(INT_32)\n");
oCDT -= 10;
fprintf(stderr, "CDT -= 10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator*=(INT_32)\n");
oCDT *= 10;
fprintf(stderr, "CDT *= 10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator/=(INT_32)\n");
oCDT /= 10;
fprintf(stderr, "CDT /= 10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator+(INT_32)\n");
oCDT = oCDT + 10;
fprintf(stderr, "CDT = CDT + 10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "standalone operator+(int, CDT)\n");
oCDT = 10 + oCDT;
fprintf(stderr, "CDT = 10 + CDT -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator-(INT_32)\n");
oCDT = oCDT - 10;
fprintf(stderr, "CDT = CDT - 10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "standalone operator-(int, CDT)\n");
oCDT = 10 - oCDT;
fprintf(stderr, "CDT = 10 - CDT -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator*(INT_32)\n");
oCDT = oCDT * 10;
fprintf(stderr, "CDT = CDT * 10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "standalone operator*(int, CDT)\n");
oCDT = 10 * oCDT;
fprintf(stderr, "CDT = 10 * CDT -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator/(INT_32)\n");
oCDT = oCDT / 10;
fprintf(stderr, "CDT = CDT * 10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "standalone operator*(int, CDT)\n");
oCDT = 10 / oCDT;
fprintf(stderr, "CDT = 10 * CDT -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
// //
fprintf(stderr, "operator+=(W_FLOAT)\n");
oCDT += 10.10;
fprintf(stderr, "CDT += 10.10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator-=(W_FLOAT)\n");
oCDT -= 10.10;
fprintf(stderr, "CDT -= 10.10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator*=(W_FLOAT)\n");
oCDT *= 10.10;
fprintf(stderr, "CDT *= 10.10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator/=(W_FLOAT)\n");
oCDT /= 10.10;
fprintf(stderr, "CDT /= 10.10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator+(W_FLOAT)\n");
oCDT = oCDT + 10.10;
fprintf(stderr, "CDT = CDT + 10.10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "standalone operator+(W_FLOAT, CDT)\n");
oCDT = 10.10 + oCDT;
fprintf(stderr, "CDT = 10.10 + CDT -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator-(INT_32)\n");
oCDT = oCDT - 10.10;
fprintf(stderr, "CDT = CDT - 10.10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "standalone operator-(W_FLOAT, CDT)\n");
oCDT = 10.10 - oCDT;
fprintf(stderr, "CDT = 10.10 - CDT -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator*(W_FLOAT)\n");
oCDT = oCDT * 10.10;
fprintf(stderr, "CDT = CDT * 10.10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "standalone operator*(W_FLOAT, CDT)\n");
oCDT = 10.10 * oCDT;
fprintf(stderr, "CDT = 10.10 * CDT -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "operator/(W_FLOAT)\n");
oCDT = oCDT / 10.10;
fprintf(stderr, "CDT = CDT * 10.10 -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "standalone operator*(W_FLOAT, CDT)\n");
oCDT = 10.10 / oCDT;
fprintf(stderr, "CDT = 10.10 * CDT -> %f\n\n", W_FLOAT(oCDT.GetFloat()));
fprintf(stderr, "Auto-cast to complex type\n");
oCDT = "2";
fprintf(stderr, "CDT -> %d: %s\n", INT_32(oCDT.GetInt()), oCDT.PrintableType());
fprintf(stderr, "CDT -> %s: %s\n\n", oCDT.GetString().c_str(), oCDT.PrintableType());
oCDT *= 3.141;
fprintf(stderr, "CDT -> %f: %s\n", W_FLOAT(oCDT.GetFloat()), oCDT.PrintableType());
fprintf(stderr, "CDT -> %s: %s\n\n", oCDT.GetString().c_str(), oCDT.PrintableType());
oCDT = "3.141";
fprintf(stderr, "CDT -> %d: %s\n", INT_32(oCDT.GetInt()), oCDT.PrintableType());
fprintf(stderr, "CDT -> %s: %s\n\n", oCDT.GetString().c_str(), oCDT.PrintableType());
oCDT *= 2;
fprintf(stderr, "CDT -> %f: %s\n", W_FLOAT(oCDT.GetFloat()), oCDT.PrintableType());
fprintf(stderr, "CDT -> %s: %s\n\n", oCDT.GetString().c_str(), oCDT.PrintableType());
// Shared date types
fprintf(stderr, "Shared data types\n");
{
oCDT = "3.141";
fprintf(stderr, "CDT -> %s: %s\n\n", oCDT.GetString().c_str(), oCDT.PrintableType());
CDT oCDT1 = oCDT;
fprintf(stderr, "CDT1 -> %d: %s\n", INT_32(oCDT1.GetInt()), oCDT1.PrintableType());
fprintf(stderr, "CDT1 -> %f: %s\n", W_FLOAT(oCDT1.GetFloat()), oCDT1.PrintableType());
fprintf(stderr, "CDT1 -> %s: %s\n\n", oCDT1.GetString().c_str(), oCDT1.PrintableType());
fprintf(stderr, "CDT -> %d: %s\n", INT_32(oCDT.GetInt()), oCDT.PrintableType());
fprintf(stderr, "CDT -> %f: %s\n", W_FLOAT(oCDT.GetFloat()), oCDT.PrintableType());
fprintf(stderr, "CDT -> %s: %s\n\n", oCDT.GetString().c_str(), oCDT.PrintableType());
}
fprintf(stderr, "Comparisons/NUMERIC/equal\n");
{
CDT oCDT1 = 10;
CDT oCDT2 = 10.0;
fprintf(stderr, "%f EQ %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.Equal(oCDT2)) ? 't':'f');
fprintf(stderr, "%f GE %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.GreaterOrEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%f LE %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.LessOrEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%f NE %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.NotEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%f GT %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.Greater(oCDT2)) ? 't':'f');
fprintf(stderr, "%f LT %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.Less(oCDT2)) ? 't':'f');
fprintf(stderr, "%f == %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1 == oCDT2) ? 't':'f');
fprintf(stderr, "%f >= %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1 >= oCDT2) ? 't':'f');
fprintf(stderr, "%f <= %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1 <= oCDT2) ? 't':'f');
fprintf(stderr, "%f != %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1 != oCDT2) ? 't':'f');
fprintf(stderr, "%f > %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1 > oCDT2) ? 't':'f');
fprintf(stderr, "%f < %f === '%c'\n\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1 < oCDT2) ? 't':'f');
}
fprintf(stderr, "Comparisons/NUMERIC/not equal\n");
{
CDT oCDT1 = 10;
CDT oCDT2 = 10.1;
fprintf(stderr, "%f EQ %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.Equal(oCDT2)) ? 't':'f');
fprintf(stderr, "%f GE %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.GreaterOrEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%f LE %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.LessOrEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%f NE %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.NotEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%f GT %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.Greater(oCDT2)) ? 't':'f');
fprintf(stderr, "%f LT %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.Less(oCDT2)) ? 't':'f');
fprintf(stderr, "%f == %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1 == oCDT2) ? 't':'f');
fprintf(stderr, "%f >= %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1 >= oCDT2) ? 't':'f');
fprintf(stderr, "%f <= %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1 <= oCDT2) ? 't':'f');
fprintf(stderr, "%f != %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1 != oCDT2) ? 't':'f');
fprintf(stderr, "%f > %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1 > oCDT2) ? 't':'f');
fprintf(stderr, "%f < %f === '%c'\n\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1 < oCDT2) ? 't':'f');
}
fprintf(stderr, "Comparisons/STRING/equal\n");
{
CDT oCDT1 = "abac";
CDT oCDT2 = "abac";
fprintf(stderr, "%s EQ %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1.Equal(oCDT2)) ? 't':'f');
fprintf(stderr, "%s GE %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1.GreaterOrEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%s LE %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1.LessOrEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%s NE %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1.NotEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%s GT %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1.Greater(oCDT2)) ? 't':'f');
fprintf(stderr, "%s LT %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1.Less(oCDT2)) ? 't':'f');
fprintf(stderr, "%s == %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 == oCDT2) ? 't':'f');
fprintf(stderr, "%s >= %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 >= oCDT2) ? 't':'f');
fprintf(stderr, "%s <= %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 <= oCDT2) ? 't':'f');
fprintf(stderr, "%s != %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 != oCDT2) ? 't':'f');
fprintf(stderr, "%s > %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 > oCDT2) ? 't':'f');
fprintf(stderr, "%s < %s === '%c'\n\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 < oCDT2) ? 't':'f');
}
fprintf(stderr, "Comparisons/STRING/not equal\n");
{
CDT oCDT1 = "abac";
CDT oCDT2 = "abaca";
fprintf(stderr, "%s EQ %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1.Equal(oCDT2)) ? 't':'f');
fprintf(stderr, "%s GE %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1.GreaterOrEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%s LE %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1.LessOrEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%s NE %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1.NotEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%s GT %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1.Greater(oCDT2)) ? 't':'f');
fprintf(stderr, "%s LT %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1.Less(oCDT2)) ? 't':'f');
fprintf(stderr, "%s == %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 == oCDT2) ? 't':'f');
fprintf(stderr, "%s >= %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 >= oCDT2) ? 't':'f');
fprintf(stderr, "%s <= %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 <= oCDT2) ? 't':'f');
fprintf(stderr, "%s != %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 != oCDT2) ? 't':'f');
fprintf(stderr, "%s > %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 > oCDT2) ? 't':'f');
fprintf(stderr, "%s < %s === '%c'\n\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 < oCDT2) ? 't':'f');
}
fprintf(stderr, "Comparisons/INT-STRING/equal\n");
{
CDT oCDT1 = 100;
CDT oCDT2 = "100";
fprintf(stderr, "%f EQ %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.Equal(oCDT2)) ? 't':'f');
fprintf(stderr, "%f GE %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.GreaterOrEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%f LE %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.LessOrEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%f NE %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.NotEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%f GT %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.Greater(oCDT2)) ? 't':'f');
fprintf(stderr, "%f LT %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.Less(oCDT2)) ? 't':'f');
fprintf(stderr, "%s == %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 == oCDT2) ? 't':'f');
fprintf(stderr, "%s >= %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 >= oCDT2) ? 't':'f');
fprintf(stderr, "%s <= %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 <= oCDT2) ? 't':'f');
fprintf(stderr, "%s != %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 != oCDT2) ? 't':'f');
fprintf(stderr, "%s > %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 > oCDT2) ? 't':'f');
fprintf(stderr, "%s < %s === '%c'\n\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 < oCDT2) ? 't':'f');
}
fprintf(stderr, "Comparisons/INT-STRING/not equal\n");
{
CDT oCDT1 = 100.1;
CDT oCDT2 = "100";
fprintf(stderr, "%f EQ %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.Equal(oCDT2)) ? 't':'f');
fprintf(stderr, "%f GE %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.GreaterOrEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%f LE %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.LessOrEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%f NE %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.NotEqual(oCDT2)) ? 't':'f');
fprintf(stderr, "%f GT %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.Greater(oCDT2)) ? 't':'f');
fprintf(stderr, "%f LT %f === '%c'\n", oCDT1.GetFloat(), oCDT2.GetFloat(), (oCDT1.Less(oCDT2)) ? 't':'f');
fprintf(stderr, "%s == %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 == oCDT2) ? 't':'f');
fprintf(stderr, "%s >= %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 >= oCDT2) ? 't':'f');
fprintf(stderr, "%s <= %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 <= oCDT2) ? 't':'f');
fprintf(stderr, "%s != %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 != oCDT2) ? 't':'f');
fprintf(stderr, "%s > %s === '%c'\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 > oCDT2) ? 't':'f');
fprintf(stderr, "%s < %s === '%c'\n\n", oCDT1.GetString().c_str(), oCDT2.GetString().c_str(), (oCDT1 < oCDT2) ? 't':'f');
}
oCDT = 0xdeadbeef;
fprintf(stderr, "As String 1: `%s` %s\n", oCDT.GetString().c_str(), oCDT.PrintableType());
fprintf(stderr, "As String 2: `%s` %s\n\n", oCDT.GetString("0x%08X").c_str(), oCDT.PrintableType());
fprintf(stderr, "== POINTER ==================================\n");
void * vTMP = (void *)0xDeadBeef;
oCDT = vTMP;
fprintf(stderr, "As String 1: `%s`\n", oCDT.GetString("").c_str());
fprintf(stderr, "As String 2: `%s`\n\n", oCDT.GetString("Pointer: %p").c_str());
fprintf(stderr, "As Pointer 1: %p\n", oCDT.GetPointer());
fprintf(stderr, "As Pointer 2: %p\n\n", (void *)(oCDT.GetObject()));
fprintf(stderr, "== STRING ===================================\n");
oCDT = ", ";
oCDT.Prepend("Hello");
oCDT.Append("World!");
fprintf(stderr, "CDT: `%s` %s\n", oCDT.GetString("").c_str(), oCDT.PrintableType());
oCDT.Prepend(111);
oCDT.Append(222);
fprintf(stderr, "CDT: `%s` %s\n\n", oCDT.GetString("").c_str(), oCDT.PrintableType());
fprintf(stderr, "== Comparators ==============================\n");
{
W_FLOAT dValue = 123.456;
oCDT = 123.456;
fprintf(stderr, "%f EQ %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT.Equal(dValue)) ? 't':'f');
fprintf(stderr, "%f GE %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT.GreaterOrEqual(dValue)) ? 't':'f');
fprintf(stderr, "%f LE %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT.LessOrEqual(dValue)) ? 't':'f');
fprintf(stderr, "%f NE %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT.NotEqual(dValue)) ? 't':'f');
fprintf(stderr, "%f GT %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT.Greater(dValue)) ? 't':'f');
fprintf(stderr, "%f LT %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT.Less(dValue)) ? 't':'f');
fprintf(stderr, "%f == %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT == dValue) ? 't':'f');
fprintf(stderr, "%f >= %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT >= dValue) ? 't':'f');
fprintf(stderr, "%f <= %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT <= dValue) ? 't':'f');
fprintf(stderr, "%f != %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT != dValue) ? 't':'f');
fprintf(stderr, "%f > %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT > dValue) ? 't':'f');
fprintf(stderr, "%f < %f === '%c'\n\n", oCDT.GetFloat(), dValue, (oCDT < dValue) ? 't':'f');
}
{
W_FLOAT dValue = 456.321;
oCDT = 123.456;
fprintf(stderr, "%f EQ %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT.Equal(dValue)) ? 't':'f');
fprintf(stderr, "%f GE %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT.GreaterOrEqual(dValue)) ? 't':'f');
fprintf(stderr, "%f LE %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT.LessOrEqual(dValue)) ? 't':'f');
fprintf(stderr, "%f NE %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT.NotEqual(dValue)) ? 't':'f');
fprintf(stderr, "%f GT %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT.Greater(dValue)) ? 't':'f');
fprintf(stderr, "%f LT %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT.Less(dValue)) ? 't':'f');
fprintf(stderr, "%f == %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT == dValue) ? 't':'f');
fprintf(stderr, "%f >= %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT >= dValue) ? 't':'f');
fprintf(stderr, "%f <= %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT <= dValue) ? 't':'f');
fprintf(stderr, "%f != %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT != dValue) ? 't':'f');
fprintf(stderr, "%f > %f === '%c'\n", oCDT.GetFloat(), dValue, (oCDT > dValue) ? 't':'f');
fprintf(stderr, "%f < %f === '%c'\n\n", oCDT.GetFloat(), dValue, (oCDT < dValue) ? 't':'f');
}
{
STLW::string sValue = "Foobar";
oCDT = "Foobar";
fprintf(stderr, "%s EQ %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT.Equal(sValue)) ? 't':'f');
fprintf(stderr, "%s GE %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT.GreaterOrEqual(sValue)) ? 't':'f');
fprintf(stderr, "%s LE %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT.LessOrEqual(sValue)) ? 't':'f');
fprintf(stderr, "%s NE %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT.NotEqual(sValue)) ? 't':'f');
fprintf(stderr, "%s GT %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT.Greater(sValue)) ? 't':'f');
fprintf(stderr, "%s LT %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT.Less(sValue)) ? 't':'f');
fprintf(stderr, "%s == %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT == sValue) ? 't':'f');
fprintf(stderr, "%s >= %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT >= sValue) ? 't':'f');
fprintf(stderr, "%s <= %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT <= sValue) ? 't':'f');
fprintf(stderr, "%s != %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT != sValue) ? 't':'f');
fprintf(stderr, "%s > %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT > sValue) ? 't':'f');
fprintf(stderr, "%s < %s === '%c'\n\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT < sValue) ? 't':'f');
}
{
STLW::string sValue = "Flurbamatic";
oCDT = "Foobar";
fprintf(stderr, "%s EQ %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT.Equal(sValue)) ? 't':'f');
fprintf(stderr, "%s GE %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT.GreaterOrEqual(sValue)) ? 't':'f');
fprintf(stderr, "%s LE %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT.LessOrEqual(sValue)) ? 't':'f');
fprintf(stderr, "%s NE %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT.NotEqual(sValue)) ? 't':'f');
fprintf(stderr, "%s GT %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT.Greater(sValue)) ? 't':'f');
fprintf(stderr, "%s LT %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT.Less(sValue)) ? 't':'f');
fprintf(stderr, "%s == %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT == sValue) ? 't':'f');
fprintf(stderr, "%s >= %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT >= sValue) ? 't':'f');
fprintf(stderr, "%s <= %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT <= sValue) ? 't':'f');
fprintf(stderr, "%s != %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT != sValue) ? 't':'f');
fprintf(stderr, "%s > %s === '%c'\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT > sValue) ? 't':'f');
fprintf(stderr, "%s < %s === '%c'\n\n", oCDT.GetString().c_str(), sValue.c_str(), (oCDT < sValue) ? 't':'f');
}
/*
try
{
CDT oCDT_array(CDT::ARRAY_VAL);
oCDT_array[0] = 10;
oCDT_array[1] = 10.5;
oCDT_array[2] = "test";
oCDT_array[3] = "passed";
oCDT_array[10] = 11;
oCDT_array[11][3] = 5;
fprintf(stderr, "ARRAY size: %d\n", oCDT_array.Size());
for (UINT_32 iI = 0; iI < oCDT_array.Size(); ++iI)
{
fprintf(stderr, "oCDT_array[%d] (%s) = `%s`\n", iI, oCDT_array[iI].PrintableType(), oCDT_array[iI].GetString().c_str());
}
fprintf(stderr, "ARRAY size: %d\n\n", oCDT_array.Size());
}
catch(CDTTypeCastException &e)
{
fprintf(stderr, "ERROR: Type cast %s\n", e.what());
}
catch(std::exception &e)
{
fprintf(stderr, "ERROR: std %s\n", e.what());
}
catch(...)
{
fprintf(stderr, "Ouch!\n");
}
/ *
my %H;
$H{'q'} -> [1] -> {"test"} = "passed";
* /
*/
fprintf(stderr, "== ARRAYS & HASHES ==========================\n");
CDT oCDT_array;
oCDT_array["abc"] = 10;
oCDT_array["xyz"][0] = 2;
oCDT_array["1"]["2"][3] = 4;
fprintf(stderr, "oCDT_array[\"abc\"] (%s) = `%s`\n", oCDT_array["abc"].PrintableType(), oCDT_array["abc"].GetString().c_str());
fprintf(stderr, "oCDT_array[\"1\"] (%s) = `%s`\n", oCDT_array["1"].PrintableType(), oCDT_array["1"].GetString().c_str());
fprintf(stderr, "oCDT_array[\"1\"][\"2\"] (%s) = `%s`\n", oCDT_array["1"]["2"].PrintableType(), oCDT_array["1"]["2"].GetString().c_str());
fprintf(stderr, "oCDT_array[\"abc\"][\"2\"][3] (%s) = `%s`\n", oCDT_array["1"]["2"][3].PrintableType(), oCDT_array["1"]["2"][3].GetString().c_str());
CDT oCDT_empty;
fprintf(stderr, "oCDT_empty = `%s`\n\n", oCDT_empty["test"].GetString().c_str());
fprintf(stderr, "DUMP: %s\n", oCDT_array.RecursiveDump().c_str());
fprintf(stderr, "Join HASH keys: %s\n", oCDT_array.JoinHashKeys(":").c_str());
fprintf(stderr, "Join HASH values: %s\n", oCDT_array.JoinHashValues(":").c_str());
fprintf(stderr, "Get HASH keys: %s\n", oCDT_array.GetHashKeys().Dump().c_str());
fprintf(stderr, "Get HASH values: %s\n", oCDT_array.GetHashValues().Dump().c_str());
CDT::Iterator itCDTArray = oCDT_array.Begin();
while (itCDTArray != oCDT_array.End())
{
fprintf(stderr, "oCDT_array[\"%s\"] => %s\n", itCDTArray -> first.c_str(), itCDTArray -> second.GetString().c_str());
itCDTArray -> second = "Empty";
++itCDTArray;
}
CDT::ConstIterator itCDTCArray = oCDT_array.Begin();
while (itCDTCArray != oCDT_array.End())
{
fprintf(stderr, "oCDT_array[\"%s\"] => %s\n", itCDTCArray -> first.c_str(), itCDTCArray -> second.GetString().c_str());
++itCDTCArray;
}
fprintf(stderr, "DUMP: %s", oCDT_array.RecursiveDump().c_str());
CDT oCDT_array1(CDT::ARRAY_VAL);
oCDT_array1.PushBack(1);
oCDT_array1.PushBack(1.23);
oCDT_array1.PushBack("some string");
oCDT_array1.PushBack(oCDT_array);
fprintf(stderr, "DUMP: %s", oCDT_array1.RecursiveDump().c_str());
fprintf(stderr, "DUMP: %s\n", oCDT_array1.RecursiveDump().c_str());
fprintf(stderr, "Join ARRAY: %s\n", oCDT_array1.JoinArrayElements(":").c_str());
// Swap two values
{
oCDT = "Foo";
CDT oCDTSwap = "Bar";
fprintf(stderr, "Swap: `%s` to `%s`\n", oCDT.GetString().c_str(), oCDTSwap.GetString().c_str());
oCDT.Swap(oCDTSwap);
fprintf(stderr, "Result: `%s` <> `%s`\n\n", oCDT.GetString().c_str(), oCDTSwap.GetString().c_str());
}
// Sort array
{
CDT oCDT1;
oCDT1[0] = "12";
oCDT1[1] = "34";
oCDT1[2] = "56";
oCDT1[3] = 78;
oCDT1[4] = 910;
fprintf(stderr, "Source: `%s`\n", oCDT1.RecursiveDump().c_str());
oCDT1.SortArray(SortCompareNum());
fprintf(stderr, "SortCompareNum: `%s`\n", oCDT1.RecursiveDump().c_str());
oCDT1.SortArray(SortCompareStr());
fprintf(stderr, "SortCompareStr: `%s`\n", oCDT1.RecursiveDump().c_str());
oCDT1 = CDT();
oCDT1[0][1] = "apple";
oCDT1[1][1] = "pera";
oCDT1[2][1] = "orange";
oCDT1[3][1] = "raspberry";
oCDT1[4][1] = "banana";
oCDT1.SortArray(SortCompareNumArrayElement(1));
fprintf(stderr, "SortCompareNumArryElement(ASC): `%s`\n", oCDT1.RecursiveDump().c_str());
oCDT1.SortArray(SortCompareStrArrayElement(1));
fprintf(stderr, "SortCompareStrArryElement(ASC): `%s`\n", oCDT1.RecursiveDump().c_str());
oCDT1.SortArray(SortCompareNumArrayElement(1, CDT::SortingComparator::DESC));
fprintf(stderr, "SortCompareNumArryElement(DESC): `%s`\n", oCDT1.RecursiveDump().c_str());
oCDT1.SortArray(SortCompareStrArrayElement(1, CDT::SortingComparator::DESC));
fprintf(stderr, "SortCompareStrArryElement(DESC): `%s`\n", oCDT1.RecursiveDump().c_str());
oCDT1 = CDT();
oCDT1[0]["foo"] = "apple";
oCDT1[1]["foo"] = "pera";
oCDT1[2]["foo"] = "orange";
oCDT1[3]["foo"] = "raspberry";
oCDT1[4]["foo"] = "banana";
oCDT1.SortArray(SortCompareNumHashElement("foo"));
fprintf(stderr, "SortCompareNumHashElement(ASC): `%s`\n", oCDT1.RecursiveDump().c_str());
oCDT1.SortArray(SortCompareStrHashElement("foo"));
fprintf(stderr, "SortCompareNumHashElement(ASC): `%s`\n", oCDT1.RecursiveDump().c_str());
oCDT1.SortArray(SortCompareNumHashElement("foo", CDT::SortingComparator::DESC));
fprintf(stderr, "SortCompareNumHashElement(DESC): `%s`\n", oCDT1.RecursiveDump().c_str());
oCDT1.SortArray(SortCompareStrHashElement("foo", CDT::SortingComparator::DESC));
fprintf(stderr, "SortCompareNumHashElement(DESC): `%s`\n", oCDT1.RecursiveDump().c_str());
}
// Merge hashes, arrays, etc
fprintf(stderr, "== Merge ARRAYS & HASHES ====================\n");
{
CDT oSource;
CDT oDestination;
oDestination.MergeCDT(oSource);
// Array-to-array
oDestination[0] = "one";
oDestination[1] = "two";
oDestination[2] = "three";
oDestination.MergeCDT(oSource);
oSource[0] = "four";
oSource[1] = "five";
oSource[2] = "six";
oDestination.MergeCDT(oSource);
fprintf(stderr, "Merge: `%s`\n", oDestination.RecursiveDump().c_str());
// Array-to-hash
oDestination = CDT(CDT::HASH_VAL);
oDestination["one"] = 1;
oDestination["two"] = 2;
oDestination["three"] = 3;
oDestination.MergeCDT(oSource);
fprintf(stderr, "Merge: `%s`\n", oDestination.RecursiveDump().c_str());
// Hash-to-array
oDestination = CDT(CDT::ARRAY_VAL);
oDestination[0] = "one";
oDestination[1] = "two";
oDestination[2] = "three";
oSource = CDT(CDT::HASH_VAL);
oSource["four"] = 4;
oSource["five"] = 5;
oSource["six"] = 6;
oDestination.MergeCDT(oSource);
fprintf(stderr, "Merge: `%s`\n", oDestination.RecursiveDump().c_str());
// Hash-to-hash
oDestination = CDT(CDT::HASH_VAL);
oDestination["one"] = 1;
oDestination["two"] = 2;
oDestination["three"] = 3;
oDestination.MergeCDT(oSource);
fprintf(stderr, "Merge: `%s`\n", oDestination.RecursiveDump().c_str());
}
fprintf(stderr, "== Merge DEEP ARRAYS & HASHES ===============\n");
{
CDT oSource;
CDT oDestination;
oSource["foo"][0] = "apple";
oSource["bar"][0] = "cat";
oSource["foo"][1] = "pera";
oSource["bar"][1] = "dog";
oSource["foo"][2] = "orange";
oSource["bar"][2] = "fox";
oSource["foo"][3] = "raspberry";
oSource["bar"][3] = "bear";
oSource["foo"][4] = "banana";
oSource["bar"][4] = "rat";
oDestination["foo"][0] = "melon";
oDestination["baz"][0] = "whale";
oDestination["baz"][1] = "dolphin";
oDestination["boo"][1] = "raven";
CDT oDestination1 = oDestination;
oDestination.MergeCDT(oSource);
fprintf(stderr, "Merge: `%s`\n", oDestination.RecursiveDump().c_str());
oDestination1.MergeCDT(oSource, CDT::DEEP_MERGE);
fprintf(stderr, "Merge: `%s`\n", oDestination1.RecursiveDump().c_str());
}
fprintf(stderr, "== END ======================================\n");
// make valgrind happy
fclose(stdin);
fclose(stdout);
fclose(stderr);
return EX_OK;
}
// End.
ctpp2-2.8.3/tests/PHPPerfTest.php 0000755 0000000 0000000 00000001051 12006425304 015225 0 ustar root root
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
$NI = 0;
#$AArray = new Array();
for ($NI = 0; $NI < 10000; ++$NI)
{
if ($NI % 2 == 0) { $AArray[$NI] = $NI; }
else
{
$NJ = 0;
for ($NJ = 0; $NJ < 100; ++$NJ)
{
$SKey = sprintf("_%d_%d_", $NI, $NJ);
$AArray[$NI][$SKey][10] = $NI;
}
}
}
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$elapsed = ($endtime - $starttime);
print("Time: " . $elapsed . "\n")
?>
ctpp2-2.8.3/tests/SimpleCompilerTest.cpp 0000644 0000000 0000000 00000003656 12006425304 016712 0 ustar root root /*-
* Copyright (c) 2004 - 2010 CTPP Team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the CTPP Team nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* SimpleCompilerTest.cpp
*
* $CTPP$
*/
#include
#include
using namespace CTPP;
// test case
int main(int argc, char ** argv)
{
if (argc != 3) { fprintf(stderr, "usage: %s file.tmpl file.ct2\n", argv[0]); return EX_USAGE; }
SimpleCompiler oSimpleCompiler(argv[1]);
oSimpleCompiler.Save(argv[2]);
// Make Valgrind happy
fclose(stdin);
fclose(stdout);
fclose(stderr);
}
// End.
ctpp2-2.8.3/tests/PERLPerfTest.pl 0000755 0000000 0000000 00000000660 12006425304 015171 0 ustar root root #!/usr/bin/perl -w
use strict;
use Time::HiRes qw(gettimeofday tv_interval);
my $t0 = [gettimeofday];
my $NI = 0;
my @AArray;
for ($NI = 0; $NI < 10000; ++$NI)
{
if ($NI % 2 == 0) { $AArray[$NI] = $NI; }
else
{
my $NJ = 0;
for ($NJ = 0; $NJ < 100; ++$NJ)
{
my $SKey = sprintf("_%d_%d_", $NI, $NJ);
$AArray[$NI] -> {$SKey} -> [10] = $NI;
}
}
}
my $elapsed = tv_interval($t0);
print("Time: " . $elapsed . "\n")
ctpp2-2.8.3/tests/CTPP2Interpreter.cpp 0000644 0000000 0000000 00000015770 12006425304 016202 0 ustar root root /*-
* Copyright (c) 2006, 2007 CTPP Team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the CTPP Team nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* CTPP2Interpreter.cpp
*
* $CTPP$
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace CTPP;
int main(int argc, char ** argv)
{
INT_32 iRetCode = EX_SOFTWARE;
if (argc != 2 && argc != 3 && argc != 4 && argc != 5)
{
fprintf(stdout, "CTPP2 interpreter v" CTPP_VERSION " (" CTPP_IDENT "). Copyright (c) 2004-2011 CTPP Dev. Team.\n\n");
fprintf(stderr, "usage: %s file.name [data.json] [translation.mo | 0] [limit of steps]\n", argv[0]);
return EX_USAGE;
}
// Output
FileOutputCollector oOutputCollector(stdout);
// Initialize Standard CTPP library
SyscallFactory oSyscallFactory(100);
// Load standard library
STDLibInitializer::InitLibrary(oSyscallFactory);
CTPP2GetText oGetText;
if (argc >= 4 && strncmp(argv[3], "0", sizeof(argv[3])) != 0) { oGetText.AddTranslation(argv[3], "test", "unknown"); }
oGetText.InitSTDLibFunction(oSyscallFactory);
oGetText.SetLanguage(oSyscallFactory, "unknown");
oGetText.SetDefaultDomain("test");
UINT_32 iStepsLimit = 10240;
if(argc == 5) { iStepsLimit = atoi(argv[4]); }
else
{
fprintf(stderr, "WARNING: [limit of steps] not set, use default value of %d\n", iStepsLimit);
}
try
{
VMOpcodeCollector oVMOpcodeCollector;
StaticText oSyscalls;
StaticData oStaticData;
StaticText oStaticText;
HashTable oHashTable;
CTPP2Compiler oCompiler(oVMOpcodeCollector, oSyscalls, oStaticData, oStaticText, oHashTable);
// Load template
CTPP2FileSourceLoader oSourceLoader;
oSourceLoader.LoadTemplate(argv[1]);
// Create template parser
CTPP2Parser oCTPP2Parser(&oSourceLoader, &oCompiler, argv[1]);
// Compile template
oCTPP2Parser.Compile();
// Get program core
UINT_32 iCodeSize = 0;
const VMInstruction * oVMInstruction = oVMOpcodeCollector.GetCode(iCodeSize);
// Dump program
VMDumper oDumper(iCodeSize, oVMInstruction, oSyscalls, oStaticData, oStaticText, oHashTable);
UINT_32 iSize = 0;
const VMExecutable * aProgramCore = oDumper.GetExecutable(iSize);
// Get program core
const VMMemoryCore oVMMemoryCore(aProgramCore);
CDT oHash(CDT::HASH_VAL);
// Load JSON data
if(argc >= 3)
{
// Our data
CTPP2JSONFileParser oJSONFileParser(oHash);
oJSONFileParser.Parse(argv[2]);
}
else
{
fprintf(stderr, "WARNING: [data.json] not given\n");
}
// Logger
FileLogger oLogger(stderr);
// Run program
VM oVM(&oSyscallFactory, 10240, 10240, iStepsLimit);
UINT_32 iIP = 0;
oVM.Init(&oVMMemoryCore, &oOutputCollector, &oLogger);
oVM.Run(&oVMMemoryCore, &oOutputCollector, iIP, oHash, &oLogger);
iRetCode = EX_OK;
}
catch(CTPPParserSyntaxError & e) { fprintf(stderr, "ERROR: At line %d, pos. %d: %s\n", e.GetLine(), e.GetLinePos(), e.what()); }
catch(CTPPParserOperatorsMismatch & e) { fprintf(stderr, "ERROR: At line %d, pos. %d: expected %s, but found %s>\n", e.GetLine(), e.GetLinePos(), e.Expected(), e.Found()); }
// CDT
catch(CDTTypeCastException & e) { fprintf(stderr, "ERROR: Type Cast %s\n", e.what()); }
catch(CDTAccessException & e) { fprintf(stderr, "ERROR: Array index out of bounds: %s\n", e.what()); }
// Virtual machine
catch(IllegalOpcode & e) { fprintf(stderr, "ERROR: Illegal opcode 0x%08X at 0x%08X\n", e.GetOpcode(), e.GetIP()); }
catch(InvalidSyscall & e)
{
if (e.GetIP() != 0)
{
VMDebugInfo oVMDebugInfo(e.GetDebugInfo());
fprintf(stderr, "ERROR: %s at 0x%08X (Template file \"%s\", Line %d, Pos: %d)\n", e.what(), e.GetIP(), e.GetSourceName(), oVMDebugInfo.GetLine(), oVMDebugInfo.GetLinePos());
}
else
{
fprintf(stderr, "Unsupported syscall: \"%s\"\n", e.what());
}
}
catch(CodeSegmentOverrun & e) { fprintf(stderr, "ERROR: %s at 0x%08X\n", e.what(), e.GetIP()); }
catch(StackOverflow & e) { fprintf(stderr, "ERROR: Stack overflow at 0x%08X\n", e.GetIP()); }
catch(StackUnderflow & e) { fprintf(stderr, "ERROR: Stack underflow at 0x%08X\n", e.GetIP()); }
catch(ExecutionLimitReached & e) { fprintf(stderr, "ERROR: Execution limit of %d step(s) reached at 0x%08X\n", iStepsLimit, e.GetIP()); }
catch(VMException & e) { fprintf(stderr, "ERROR: VM generic exception: %s at 0x%08X\n", e.what(), e.GetIP()); }
// CTPP
catch(CTPPLogicError & e) { fprintf(stderr, "ERROR: %s\n", e.what()); }
catch(CTPPUnixException & e) { fprintf(stderr, "ERROR: I/O in %s: %s\n", e.what(), strerror(e.ErrNo())); }
catch(CTPPException & e) { fprintf(stderr, "ERROR: CTPP Generic exception: %s\n", e.what()); }
catch(...) { fprintf(stderr, "ERROR: Bad thing happened.\n"); }
// Destroy standard library
STDLibInitializer::DestroyLibrary(oSyscallFactory);
// make valgrind happy
fclose(stdin);
fclose(stdout);
fclose(stderr);
return iRetCode;
}
// End.
ctpp2-2.8.3/tests/StaticTextTest.cpp 0000644 0000000 0000000 00000004744 12006425304 016061 0 ustar root root /*-
* Copyright (c) 2006, 2007 CTPP Team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the CTPP Team nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* VMTest.cpp
*
* $CTPP$
*/
#include
#include
#ifdef HAVE_SYSEXITS_H
#include
#endif
using namespace CTPP;
int main(void)
{
StaticText oStaticText;
oStaticText.StoreData("Test", 4);
oStaticText.StoreData("really", 6);
oStaticText.StoreData(" passed?", 8);
oStaticText.StoreData("1234", 4);
fprintf(stderr, "Stored text: ");
UINT_32 iDataSize = 0;
CCHAR_P sData = oStaticText.GetData(0, iDataSize);
fwrite(sData, iDataSize, 1, stderr);
sData = oStaticText.GetData(2, iDataSize);
fwrite(sData, iDataSize, 1, stderr);
sData = oStaticText.GetData(6, iDataSize);
if (sData == NULL) { fprintf(stderr, "\nNon-existent text segment: OK\nYet another stored text: "); }
else { return EX_SOFTWARE; }
sData = oStaticText.GetData(1, iDataSize);
fwrite(sData, iDataSize, 1, stderr);
fprintf(stderr, "\n");
// make valgrind happy
fclose(stdin);
fclose(stdout);
fclose(stderr);
return EX_OK;
}
// End.
ctpp2-2.8.3/tests/VMArgStackTest.cpp 0000644 0000000 0000000 00000005002 12006425304 015713 0 ustar root root /*-
* Copyright (c) 2006, 2007 CTPP Team
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the CTPP Team nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* VMArgStackTest.cpp
*
* $CTPP$
*/
#include
#include
#include
#ifdef HAVE_SYSEXITS_H
#include
#endif
using namespace CTPP;
int main(void)
{
UINT_32 iFlag = 2;
VMArgStack oVMArgStack(5);
oVMArgStack.PushElement(1);
oVMArgStack.PushElement(1.1);
oVMArgStack.PushElement("1.2");
oVMArgStack.PushElement(CDT(1));
CDT oCDT;
oCDT[1][10][10] = 1;
oVMArgStack.PushElement(oCDT);
try
{
oVMArgStack.PushElement(0);
}
catch(StackOverflow & e)
{
--iFlag;
}
oVMArgStack.PopElement();
oVMArgStack.PopElement();
oVMArgStack.PopElement();
oVMArgStack.PopElement();
oVMArgStack.PopElement();
try
{
oVMArgStack.PopElement();
}
catch(StackUnderflow & e)
{
--iFlag;
}
INT_32 iExitCode = EX_SOFTWARE;
if (iFlag == 0) { fprintf(stdout, "OK\n"); iExitCode = EX_OK; }
else { fprintf(stdout, "FAILED\n"); }
// make valgrind happy
fclose(stdin);
fclose(stdout);
fclose(stderr);
return iExitCode;
}
// End.
ctpp2-2.8.3/tests/testdata/ 0000755 0000000 0000000 00000000000 12056726603 014234 5 ustar root root ctpp2-2.8.3/tests/testdata/function_obj_dump.tmpl 0000644 0000000 0000000 00000000064 12006425304 020623 0 ustar root root OBJ_DUMP:
ctpp2-2.8.3/tests/testdata/lebowski-bench.json 0000644 0000000 0000000 00000013275 12006425304 020020 0 ustar root root {
"adverts" : [
{
"title" : "Walter",
"text" : "You see what happens, Larry?",
"url" : "http://www.imdb.com/title/tt0118715/quotes"
},
{
"title" : "Walter",
"text" : "I don't roll on Shabbos!",
"url" : "http://www.imdb.com/title/tt0118715/quotes"
},
{
"title" : "Blond Thug",
"text" : "Where's the money, Lebowski?",
"url" : "http://www.imdb.com/title/tt0118715/quotes"
},
{
"title" : "Nihilist",
"text" : "We believe in nothing, Lebowski.",
"url" : "http://www.imdb.com/title/tt0118715/quotes"
},
{
"title" : "Walter",
"text" : "Is this your homework, Larry?",
"url" : "http://www.imdb.com/title/tt0118715/quotes"
},
{
"title" : "Nihilist",
"text" : "Ve vant ze money, Lebowski",
"url" : "http://www.imdb.com/title/tt0118715/quotes"
}
],
"sections" : [
{
"id" : 1234,
"title" : "The Dude",
"rip" : 0
},
{
"id" : 2345,
"title" : "Walter Sobchak",
"rip" : 0
},
{
"id" : 3456,
"title" : "Donny",
"rip" : 1
},
{
"id" : 4567,
"title" : "Maude Lebowski",
"rip" : 0
},
{
"id" : 5678,
"title" : "The Big Lebowski",
"rip" : 0
},
{
"id" : 6789,
"title" : "Brandt",
"rip" : 0
},
{
"id" : 7890,
"title" : "Jesus Quintana",
"rip" : 0
}
],
"total" : 654329,
"online" : [
{ "name" : "true" },
{ "name" : "false" },
{ "name" : "short" },
{ "name" : "long" },
{ "name" : "apha" },
{ "name" : "omega" },
{ "name" : "drag" },
{ "name" : "drop" },
{ "name" : "make" },
{ "name" : "clean" },
{ "name" : "east" },
{ "name" : "west" },
{ "name" : "up" },
{ "name" : "down" },
{ "name" : "sun" },
{ "name" : "rain" },
{ "name" : "secondary" },
{ "name" : "main" }
],
"news" : [
{
"time" : "03:45",
"id" : 987,
"title" : "The Stranger",
"text" : "See, they call Los Angeles the \"City Of Angels\"; but I didn't find it to be that, exactly. But I'll allow it as there are s ome nice folks there. 'Course I ain't never been to London, and I ain't never seen France. And I ain't never seen no queen in her damned undies, so the feller says. But I'll tell you what - after seeing Los Angeles, and this here story I'm about to unfold, well, I guess I seen somethin' every bit as stupefyin' as you'd seen in any of them other places. And in English , too. So I can die with a smile on my face, without feelin' like the good Lord gypped me. Now this here story I'm about to unfold took place in the early '90s - just about the time of our conflict with Sad'm and the I-raqis. I only mention it be cause sometimes there's a man..."
},
{
"time" : "03:48",
"id" : 876,
"title" : "The Stranger",
"text" : "...I won't say a hero, 'cause, what's a hero? Sometimes, there's a man. And I'm talkin' about the Dude here - the Dude from Los Angeles. Sometimes, there's a man, well, he's the man for his time and place. He fits right in there. And that's the Dude. The Dude, from Los Angeles. And even if he's a lazy man - and the Dude was most certainly that. Quite possibly the laziest in all of Los Angeles County, which would place him high in the runnin' for laziest worldwide. Sometimes there's a man , sometimes, there's a man. Well, I lost my train of thought here. But... aw, hell. I've done introduced it enough."
},
{
"time" : "03:50",
"id" : 765,
"title" : "Walter Sobchak",
"text" : "Donny was a good bowler, and a good man. He was one of us. He was a man who loved the outdoors... and bowling, and as a surfer he explored the beaches of Southern California, from La Jolla to Leo Carrillo and... up to... Pismo. He died, like so many young men of his generation, he died before his time. In your wisdom, Lord, you took him, as you took so many bright flowering young men at Khe Sanh, at Langdok, at Hill 364. These young men gave their lives. And so would Donny. Donny, who loved bowling. And so, Theodore Donald Karabotsos, in accordance with what we think your dying wishes might well have been, we commit your final mortal remains to the bosom of the Pacific Ocean, which you loved so well. Good night, sweet prince."
},
{
"time" : "03:52",
"id" : 654,
"title" : "The Dude",
"text" : "God damn you Walter! You fuckin' asshole! Everything's a fuckin' travesty with you, man! And what was all that shit about Vietnam? What the FUCK, has anything got to do with Vietnam? What the fuck are you talking about?"
},
{
"time" : "03:57",
"id" : 543,
"title" : "Jesus Quintana",
"text" : "What's this day of rest shit? What's this bullshit? I don't fuckin' care! It don't matter to Jesus. But you're not foolin'me, man. You might fool the fucks in the league office, but you don't fool Jesus. This bush league psyche-out stuff. Laughable, man - ha ha! I would have fucked you in the ass Saturday. I fuck you in the ass next Wednesday instead. Wooo! You gotadate Wednesday, baby!"
},
{
"time" : "03:59",
"id" : 432,
"title" : "Jesus Quintana",
"text" : "Let me tell you something, pendejo. You pull any of your crazy shit with us, you flash a piece out on the lanes, I'll take it away from you, stick it up your ass and pull the fucking trigger 'til it goes \"click.\""
},
{
"time" : "04:01",
"id" : 321,
"title" : "The Dude",
"text" : "Let me explain something to you. Um, I am not \"Mr. Lebowski\". You're Mr. Lebowski. I'm the Dude. So that's what you call me. You know, that or, uh, His Dudeness, or uh, Duder, or El Duderino if you're not into the whole brevity thing."
}
]
}
ctpp2-2.8.3/tests/testdata/calls.out 0000644 0000000 0000000 00000000677 12006425304 016062 0 ustar root root
vara|varb|varc
vara|varb|varc
BINGOBINGOBINGO
1|2|3|4|
123
test|
10#
test|
15#
Argument 1:
[
"fields"
]
Argument 1:
{
'fields' : {
'field1' : "name"
}
}
Argument 1:
{
'field1' : "name"
}
Argument 1:
{
'fields' : {
'field1' : "name"
}
}
ctpp2-2.8.3/tests/testdata/function_gettext.tmpl 0000644 0000000 0000000 00000001465 12006425304 020516 0 ustar root root // Start
_:
GETTEXT:
_:
GETTEXT:
_ n1:
_ n2:
_ n5:
GETTEXT n1:
GETTEXT n2:
GETTEXT n5:
_ n1:
_ n2:
GETTEXT n1:
GETTEXT n2:
// End.
ctpp2-2.8.3/tests/testdata/array_and_hash_access.tmpl 0000644 0000000 0000000 00000002421 12047433466 021417 0 ustar root root 1.
2.
3.
3a.
4.
5.
6.
7.
8.
9.
A.
B. |
C. |
D. |
E. |
F. |
G.
H.
I.
J. =
K.
L.
ctpp2-2.8.3/tests/testdata/functions.out 0000644 0000000 0000000 00000005313 12050202304 016754 0 ustar root root // Start
AVG(a): 2
AVG(g): 1.81712059283
AVG(h): 1.63636363636
AVG(q): 2.16024689947
BASE64_DECODE/BASE64_ENCODE: Hello, World
CAST(int): 1
CAST(int): 8
CAST(dec): 10
CAST(oct): 8
CAST(hex): 16
CAST(float): 1.234
CONCAT: HelloWorld!
DATE_FORMAT: 2008-01-16 16:32:03
DEFAULT: Default value
DEFINED(nonexistent): 0
DEFINED : 1
FORM_PARAM:
GET_TYPE: INTEGER
GET_TYPE: REAL
GET_TYPE: STRING
GET_TYPE: ARRAY
HASH_KEYS: one three two | one three two
HREF_PARAM: hello=%3Cb%3Etest%3C/b%3E+%22test%22+%24test%24&
IN_ARRAY: 1
IN_SET: 1
LIST: cat dog bat rat
LIST_ELEMENT: 3
LOG: 2.00432137378
LOG: 2.00432137378
LOG: 10
LOG: 1
MB_SIZE: 26
MB_SUBSTR: Привет, мир!
MB_SUBSTR: World! Привет
MB_SUBSTR: Hello, :) мир!
MB_TRUNCATE: Hello, World
MB_TRUNCATE: Hello, World...
MIN: 1
MAX: 3
NUM_FORMAT: 1 234 567 890
SIZE: 4
SIZE: 3
SPRINTF: -123 0
SUBSTR: World
TRUNCATE: Hello
TRUNCATE: Hello...
VERSION : CTPP2 engine v2.8.2 (Dzoraget), copyright (c) 2004 - 2012 CTPP Dev. Team
VERSION(full): Engine: CTPP2 engine v2.8.2 (Dzoraget), copyright (c) 2004 - 2012 CTPP Dev. Team;
RuntimeLibrary: CTPP Standard Library v2.8.2 (Dzoraget), copyright (c) 2007 - 2012 CTPP Dev. Team;
License: BSD-like, see http://ctpp.havoc.ru/;
// Escape
HTMLESCAPE: <b>test</b> "test" $test$
JSON: "\u003cb\u003etest\u003c\/b\u003e \"test\" $test$"
JSONESCAPE: test<\/b> \"test\" $test$
URLESCAPE: %3Cb%3Etest%3C/b%3E+%22test%22+%24test%24
URIESCAPE: %3Cb%3Etest%3C/b%3E%20%22test%22%20%24test%24
XMLESCAPE: <b>test</b> "test" $test$
WMLESCAPE: <b>test</b> "test" $$test$$
// End.
ctpp2-2.8.3/tests/testdata/array_and_hash_access_incl.tmpl 0000644 0000000 0000000 00000000016 12006425304 022405 0 ustar root root