diff --git a/EGnDllMain.cpp b/EGnDllMain.cpp new file mode 100644 index 0000000..43310d3 --- /dev/null +++ b/EGnDllMain.cpp @@ -0,0 +1,41 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : EGnDllMain.cpp Data : 20.11.13 Versione : 1.3a1 +// Contenuto : Inizializzazione della DLL. +// +// +// +// Modifiche : 20.11.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include +#include <\EgtDev\Include\EgtTrace.h> + +//--------------------------- Macro ------------------------------------------- +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + + +//----------------------------------------------------------------------------- +BOOL APIENTRY +DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved) +{ + + if ( dwReason == DLL_PROCESS_ATTACH) { + EGT_TRACE( "EgtGeneral.dll Initializing!\n") ; + } + else if ( dwReason == DLL_PROCESS_DETACH) { + EGT_TRACE( "EgtGeneral.dll Terminating!\n") ; + } + + return 1 ; +} + diff --git a/EgtGeneral.sln b/EgtGeneral.sln new file mode 100644 index 0000000..95591d7 --- /dev/null +++ b/EgtGeneral.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EgtGeneral", "EgtGeneral.vcxproj", "{D216A77C-ACE6-4012-B4E1-61E5C9102E9A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D216A77C-ACE6-4012-B4E1-61E5C9102E9A}.Debug|Win32.ActiveCfg = Debug|Win32 + {D216A77C-ACE6-4012-B4E1-61E5C9102E9A}.Debug|Win32.Build.0 = Debug|Win32 + {D216A77C-ACE6-4012-B4E1-61E5C9102E9A}.Release|Win32.ActiveCfg = Release|Win32 + {D216A77C-ACE6-4012-B4E1-61E5C9102E9A}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/EgtGeneral.vcxproj b/EgtGeneral.vcxproj new file mode 100644 index 0000000..16f7fe1 --- /dev/null +++ b/EgtGeneral.vcxproj @@ -0,0 +1,115 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {D216A77C-ACE6-4012-B4E1-61E5C9102E9A} + Win32Proj + EgtGeneral + + + + DynamicLibrary + true + Unicode + + + DynamicLibrary + false + true + Unicode + + + + + + + + + + + + + true + $(SolutionDir)$(Configuration)$(PlatformArchitecture)\ + $(Configuration)$(PlatformArchitecture)\ + $(ProjectName)D$(PlatformArchitecture) + + + false + $(SolutionDir)$(Configuration)$(PlatformArchitecture)\ + $(Configuration)$(PlatformArchitecture)\ + $(ProjectName)R$(PlatformArchitecture) + + + + Use + Level3 + Disabled + WIN32;I_AM_EGN;_DEBUG;_WINDOWS;_USRDLL;EGTGENERAL_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + + + copy $(TargetDir)$(TargetName).pdb \EgtDev\Lib\ +copy $(TargetDir)$(TargetName).lib \EgtDev\Lib\ +copy $(TargetPath) \EgtProg\Dll + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;I_AM_EGN;NDEBUG;_WINDOWS;_USRDLL;EGTGENERAL_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + true + true + + + copy $(TargetDir)$(TargetName).pdb \EgtDev\Lib\ +copy $(TargetDir)$(TargetName).lib \EgtDev\Lib\ +copy $(TargetPath) \EgtProg\Dll + + + + + + + + + + + false + + + false + + + + + + Create + Create + + + + + + + \ No newline at end of file diff --git a/EgtGeneral.vcxproj.filters b/EgtGeneral.vcxproj.filters new file mode 100644 index 0000000..3dde2d9 --- /dev/null +++ b/EgtGeneral.vcxproj.filters @@ -0,0 +1,45 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + + + File di origine + + + File di origine + + + File di origine + + + File di origine + + + \ No newline at end of file diff --git a/Scan.cpp b/Scan.cpp new file mode 100644 index 0000000..455a9f4 --- /dev/null +++ b/Scan.cpp @@ -0,0 +1,70 @@ +//---------------------------------------------------------------------------- +// EgalS +//---------------------------------------------------------------------------- +// File : Scan.cpp Data : 30.09.13 Versione : 1.2a1 +// Contenuto : Implementazione della classe CCmdScan. +// Scansione di file di testo con codifica UTF-8 (anche con BOM) +// e quindi anche ASCII. +// +// +// Modifiche : 30.09.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "/EgtDEv/Include/EGnScan.h" +#include "/EgtDEv/Include/EGnStringUtils.h" +#include "/EgtDEv/Include/EGnStringConverter.h" + +using namespace std ; + + +//---------------------------------------------------------------------------- +CScan::CScan( void) +{ + m_nLineNbr = 0 ; + m_pInFile = NULL ; +} + +//---------------------------------------------------------------------------- +CScan::~CScan( void) +{ +} + +//---------------------------------------------------------------------------- +bool +CScan::Initialize( ifstream& InFile) +{ + // verifico che il file passato sia regolarmente aperto per lettura + if ( ! InFile.is_open()) + return false ; + + // assegno il file + m_pInFile = &InFile ; + + // reset numero linea corrente + m_nLineNbr = 0 ; + + return ( ! m_pInFile->fail()) ; +} + +//---------------------------------------------------------------------------- +bool +CScan::GetLine( string& sLine) +{ + if ( m_pInFile == nullptr || ! m_pInFile->is_open()) + return false ; + + do { + if ( ! getline( *m_pInFile, sLine)) + return false ; + if ( m_nLineNbr == 0) + TrimUtf8Bom( sLine) ; + Trim( sLine) ; + m_nLineNbr ++ ; + } while ( sLine.empty() || sLine.find( "//") == 0) ; + + return true ; +} diff --git a/StringUtils.cpp b/StringUtils.cpp new file mode 100644 index 0000000..af782ad --- /dev/null +++ b/StringUtils.cpp @@ -0,0 +1,273 @@ +//---------------------------------------------------------------------------- +// EgalS +//---------------------------------------------------------------------------- +// File : StringUtils.cpp Data : 20.01.13 Versione : 1.1a1 +// Contenuto : Implementazione delle funzioni di utilità per le stringhe. +// +// +// +// Modifiche : 20.01.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "/EgtDEv/Include/EgnStringUtils.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +const string +ToString( int nVal, int nPrec) +{ + int nErr ; + int nLen ; + char szBuff[24] ; + + + // eseguo conversione + nErr = _itoa_s( nVal, szBuff, 10) ; + + // se errore, ritorno stringa opportuna + if ( nErr != 0) { + _ASSERT( 0) ; + return "#Error" ; + } + + // verifico lunghezza minima + if ( ( nLen = (int) strlen( szBuff)) >= nPrec) + return szBuff ; + + // porto la stringa alla minima lunghezza + string sBuff( szBuff) ; + sBuff.insert( 0, ( nPrec - nLen), '0') ; + return sBuff ; +} + +//---------------------------------------------------------------------------- +const string +ToString( double dVal, int nPrec) +{ + const double BIG_NUMBER = 1e10 ; + const int BIG_DIGITNBR = 10 ; + const int MAX_PREC = 12 ; + char szBuff[24] ; + char szDest[32] ; + char* pBuff ; + char* pDest ; + int nErr ; + int nDecimal ; + int nSign ; + int nExp ; + int nTmp ; + + + // verifico la precisione + nPrec = min( nPrec, MAX_PREC) ; + + // converto la mantissa + if ( fabs( dVal) < BIG_NUMBER) + nErr = _fcvt_s( szBuff, dVal, nPrec, &nDecimal, &nSign) ; + else + nErr = _ecvt_s( szBuff, dVal, BIG_DIGITNBR + nPrec, &nDecimal, &nSign) ; + + // se errore, ritorno stringa opportuna + if ( nErr != 0) { + _ASSERT( 0) ; + return "#Error" ; + } + + // se buffer vuoto, risultato è numero 0 + if ( szBuff[0] == '\0') + return "0" ; + + // verifica per forma esponenziale + if ( nDecimal > BIG_DIGITNBR) { + nExp = nDecimal - 1 ; + nDecimal = 1 ; + } + else + nExp = 0 ; + + // puntatori a inizio stringhe + pBuff = szBuff ; + pDest = szDest ; + // eventuale inserimento segno '-' + if ( nSign != 0) { + *pDest = '-' ; + pDest ++ ; + } ; + // gestione decimali dopo 0 + if ( nDecimal <= 0) { + *pDest = '0' ; + pDest ++ ; + *pDest = '.' ; + pDest ++ ; + for ( ; nDecimal < 0 ; nDecimal ++) { + *pDest = '0' ; + pDest ++ ; + } + nDecimal -- ; + } + // gestione cifre e . + while ( *pBuff != '\0') { + if ( *pBuff == '#') // NAN, INFINITY, INDEFINITE + _ASSERT( 0) ; + if ( nDecimal == 0) { + *pDest = '.' ; + pDest ++ ; + } + nDecimal -- ; + *pDest = *pBuff ; + pDest ++ ; + pBuff ++ ; + } + *pDest = '\0' ; + // se inserito un punto decimale tolgo i trailing zero + if ( nDecimal < 0) { + pDest -- ; + while ( *pDest == '0') { + *pDest = '\0' ; + pDest -- ; + } + if ( *pDest == '.') + *pDest = '\0' ; + else + pDest ++ ; + } + // aggiungo eventuale esponente (sempre compreso tra 9 e 308) + if ( nExp > 0) { + *pDest = 'e' ; + pDest ++ ; + nTmp = nExp ; + if ( nTmp >= 100) { + *pDest = '0' + ( nTmp / 100) ; + pDest ++ ; + nTmp = nTmp % 100 ; + } + if ( nTmp >= 10 || nExp >= 100) { + *pDest = '0' + ( nTmp / 10) ; + pDest ++ ; + nTmp = nTmp % 10 ; + } + *pDest = '0' + nTmp ; + pDest ++ ; + *pDest = '\0' ; + } + + if ( szDest[0] == '-' && szDest[1] == '0' && szDest[2] == '\0') + return "0" ; + else + return szDest ; +} + +//---------------------------------------------------------------------------- +void +Split( const string& sString, const string& sSeparator, bool bFirstVsLast, + string& sFirst, string& sLast) +{ + string::size_type iPos ; + + + // cerco il separatore + iPos = ( bFirstVsLast ? sString.find( sSeparator) : sString.rfind( sSeparator)) ; + // se trovato + if ( iPos != string::npos) { + if ( iPos > 0) + sFirst = sString.substr( 0, iPos) ; + else + sFirst.clear() ; + if ( ( iPos + 1) < sString.length()) + sLast = sString.substr( iPos + 1) ; + else + sLast.clear() ; + } + // altrimenti + else { + sFirst = sString ; + sLast.clear() ; + } +} + +//---------------------------------------------------------------------------- +bool +Tokenize( const string& sString, const string& sSeparators, STRVECTOR& vsTokens) +{ + string::size_type iPosStart ; + string::size_type iPosEnd ; + + + // pulisco il risultato + vsTokens.clear() ; + // parto dall'inizio + iPosStart = ( sString.empty() ? string::npos : 0) ; + // mentre esiste un nuovo inizio di token + while ( iPosStart != string::npos) { + // cerco il primo separatore + iPosEnd = sString.find_first_of( sSeparators, iPosStart) ; + // aggiungo il token al vettore + vsTokens.push_back( sString.substr( iPosStart, iPosEnd - iPosStart)) ; + // cerco l'inizio di un nuovo token + iPosStart = sString.find_first_not_of( sSeparators, iPosEnd) ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Tokenize( const string& sString, const string& sSeparators, + const string& sAtomStarts, const string& sAtomEnds, STRVECTOR& vsTokens) +{ + string::size_type iPosStart ; + string::size_type iPosEnd ; + string::size_type iAtomStart ; + string::size_type iAtomEnd ; + + + // i separatori devono essere diversi da inizio e fine di atomi + if ( sAtomStarts.find_first_of( sSeparators) != string::npos || + sAtomEnds.find_first_of( sSeparators) != string::npos) + return false ; + + // parto dall'inizio + iPosStart = ( sString.empty() ? string::npos : 0) ; + // mentre esiste un nuovo inizio di token + while ( iPosStart != string::npos) { + // eventuale inizio e fine di parte atomica + iAtomStart = sString.find_first_of( sAtomStarts, iPosStart) ; + iAtomEnd = sString.find_first_of( sAtomEnds, iAtomStart) ; + // cerco il primo separatore + iPosEnd = sString.find_first_of( sSeparators, iPosStart) ; + // se separatore è nella parte atomica, lo ricerco dopo la sua fine + if ( iAtomStart != string::npos && iPosEnd != string::npos && + iPosEnd > iAtomStart && iPosEnd < iAtomEnd) + iPosEnd = sString.find_first_of( sSeparators, iAtomEnd) ; + // aggiungo il token al vettore + vsTokens.push_back( sString.substr( iPosStart, iPosEnd - iPosStart)) ; + // cerco l'inizio di un nuovo token + iPosStart = sString.find_first_not_of( sSeparators, iPosEnd) ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +int +ReplaceString( std::string& sString, const std::string& sOld, const std::string& sNew) +{ + int nSubs ; + size_t pos ; + + + nSubs = 0 ; + pos = 0 ; + while ( ( pos = sString.find( sOld, pos)) != std::string::npos) { + sString.replace( pos, sOld.length(), sNew) ; + pos += sNew.length() ; + nSubs ++ ; + } + + return nSubs ; +} diff --git a/stdafx.cpp b/stdafx.cpp new file mode 100644 index 0000000..6b86b92 --- /dev/null +++ b/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : file di origine che include solo le inclusioni standard +// EgtGeneral.pch sarà l'intestazione precompilata +// stdafx.obj conterrà le informazioni sui tipi precompilati + +#include "stdafx.h" + +// TODO: fare riferimento alle intestazioni aggiuntive necessarie in STDAFX.H +// e non in questo file diff --git a/stdafx.h b/stdafx.h new file mode 100644 index 0000000..72d7fb4 --- /dev/null +++ b/stdafx.h @@ -0,0 +1,27 @@ +// stdafx.h : file di inclusione per file di inclusione di sistema standard +// o file di inclusione specifici del progetto utilizzati di frequente, ma +// modificati raramente +// + +#pragma once + +#include "/EgtDev/Include/EgtTargetVer.h" + +#include +#include +#include +#include + +// in Debug riconoscimento memory leakage +#ifdef _DEBUG + #define _CRTDBG_MAP_ALLOC + #include + #include +#endif + +// in Debug controllo iteratori +#ifdef _DEBUG + #define _SECURE_SCL 1 +#else + #define _SECURE_SCL 0 +#endif