commit 3d8ed4020ff4ba97bc7b187d9f669b1c6559f8a4 Author: jdg Date: Sun Sep 12 22:07:21 2021 +0200 First commit 27/02/2001 diff --git a/README.md b/README.md new file mode 100644 index 0000000..a315946 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +#ExpansorHTML + + +*27/02/2001* + +ToDo: wwtcf? + + +![screenshot](/ExpansorHTML.png "Screenshot") diff --git a/Tb_Ref.DB b/Tb_Ref.DB new file mode 100644 index 0000000..4405d63 Binary files /dev/null and b/Tb_Ref.DB differ diff --git a/expansor.bpr b/expansor.bpr new file mode 100644 index 0000000..9448c3f --- /dev/null +++ b/expansor.bpr @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +[Version Info] +IncludeVerInfo=0 +AutoIncBuild=0 +MajorVer=1 +MinorVer=0 +Release=0 +Build=0 +Debug=0 +PreRelease=0 +Special=0 +Private=0 +DLL=0 +Locale=3082 +CodePage=1252 + +[Version Info Keys] +CompanyName= +FileDescription=Executable (Console) +FileVersion=1.0.0.0 +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion=1.0.0.0 +Comments= + +[HistoryLists\hlRunParameters] +Count=2 +Item0=t tb_ref.db +Item1=t t + +[Debugging] +DebugSourceDirs=$(BCB)\source\vcl + +[Parameters] +RunParams= +HostApplication= +RemoteHost= +RemotePath= +RemoteDebug=0 + +[Compiler] +ShowInfoMsgs=0 +LinkDebugVcl=1 +LinkCGLIB=0 + +[CORBA] +AddServerUnit=1 +AddClientUnit=1 +PrecompiledHeaders=1 + +[Language] +ActiveLang= +ProjectLang= +RootDir= + + \ No newline at end of file diff --git a/expansor.cpp b/expansor.cpp new file mode 100644 index 0000000..33f39c8 --- /dev/null +++ b/expansor.cpp @@ -0,0 +1,232 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +#pragma hdrstop + +int file_exists(char *filename); +void Expande( char *Texto, char *Origen ); +int findTAG( FILE *handle, char *TAG ); +char * scanUntil( char *text, char Terminador ); +char * scanUntil( FILE *handle, char Terminador, char *buffer ); + +bool SinDecimales; + +//--------------------------------------------------------------------------- +#pragma argsused +int main(int argc, char **argv) +{ + if ( argc < 3 ) + { + cout << "Expansor de Datos\n"; + cout << "-----------------\n\n"; + cout << "Parámetros insuficientes: [documento_a_expandir] [origen_de_datos] \n\n"; + cout << "\n\n"; + } else { + + if ( argc == 4 ) SinDecimales = false; else SinDecimales = true; + + if ( !file_exists( argv[1] ) ) + { + cout << "El documento a expandir no existe: " << argv[1]; + } else { + if ( !file_exists( argv[2] ) ) + { + cout << "El origen de datos no existe: " << argv[2]; + } else + Expande( argv[1], argv[2] ); + } + } + + return 0; +} + + +int file_exists(char *filename) +{ + return (access(filename, 0) == 0); +} + +/* + + + opcionalmente: F="1.16" (factor de multiplicación) +*/ +void Expande( char *Texto, char *Origen ) +{ + FILE *handle; char digit, buffer[80], *buff; + AnsiString IDnombre, IDvalor, Campo_n, FactorM, dev; + float Factor; + + buffer[79] = '\0'; + + TTable *TbOrigen; + + TbOrigen = new TTable(0); + + TbOrigen->TableName = AnsiString( Origen ); + try { + TbOrigen->Active = true; + } catch(...) { + puts( "\nERROR GRABE ABRIENDO ORIGEN\n" ); + return; + } + + if ( (handle = fopen( Texto, "r") ) == NULL) + { + return; + } + + while ( !feof( handle ) ) + { + if ( findTAG( handle, "', buffer ); // Buscamos en buffer si hay parámetros opcionales + FactorM = AnsiString( buffer ); + digit = FactorM.Pos( "F=\"" ); + + + if ( TbOrigen->FindField( Campo_n ) == NULL ) + { + dev = "ERROR ACCEDIENDO AL DESTINO: " + Campo_n + " "; + } else { + + // Buscamos en la base de datos y... + try { + if ( !TbOrigen->Locate( IDnombre, IDvalor, TLocateOptions() << loCaseInsensitive ) ) + dev = "Valor: " + IDvalor + " no encontrado en: " + IDnombre + " "; + } catch(...) { + dev = "ERROR ACCEDIENDO AL CAMPO: " + IDnombre + " "; + } + + } + + if ( digit ) + { + StrLCopy( buffer, (FactorM.SubString( digit+3, FactorM.Length() - digit+1 ) ).c_str(), 79 ); + scanUntil( buffer, '\"' ); + try { + Factor = atof( buffer ); + }catch(...){ + dev = "El campo FACTOR debe ser numérico"; + } + + //Aplicamos el Valor del campo deseado X el factor de escala + try { + if ( TbOrigen->FindField( Campo_n ) != NULL ) + { + dev = TbOrigen->FieldByName( Campo_n )->AsString; + if ( SinDecimales ) + dev = FormatCurr( "###,###,##0;0; ", dev.ToDouble() * Factor ); + //AnsiString( Ceil( dev.ToDouble() * Factor) ); + else + dev = FormatCurr( "###,###,###.#0;0; ", dev.ToDouble() * Factor ); + } + } catch( ... ) { + dev = "El campo: "+Campo_n+" no es NUMERICO "; + } + + } else { + //Soltamos el Valor del campo deseado + if ( TbOrigen->FindField( Campo_n ) != NULL ) + dev = TbOrigen->FieldByName( Campo_n )->AsString; + } + + printf( "%s", dev.c_str() ); + + findTAG( handle, "" ); + } + } + + fclose(handle); + + TbOrigen->Active = false; + delete TbOrigen; + +} + +char * scanUntil( FILE *handle, char Terminador, char *buffer ) +{ + char digit; + char *buff; + int count; + + count = 0; + buff = buffer; + digit = fgetc( handle ); + while ( !feof( handle ) && digit != Terminador && count<32 ) + { + *buff = digit; + buff ++; + count ++; + digit = fgetc( handle ); + } + *buff = '\0'; + + return buffer; +} + +char * scanUntil( char *text, char Terminador ) +{ + char *buff; + + buff = text; + + while ( *buff != '\0' && *buff != Terminador ) + buff++; + + *buff = '\0'; + + return buff; +} + +int findTAG( FILE *handle, char *TAG ) +{ + char digit; char *TAG2, *TAG3; + + do { + TAG2 = TAG; + digit = fgetc( handle ); + while( digit != *TAG2 && !feof(handle) ) + { + fputchar( digit ); + digit = fgetc( handle ); + } + + while( digit == *TAG2 && !feof( handle ) ) + { + TAG2++; + if ( *TAG2 != '\0' ) + digit = fgetc( handle ); + } + + if ( *TAG2 != '\0' ) + { + TAG3 = TAG; + while ( TAG3 != TAG2 ) + { + fputchar( *TAG3 ); + TAG3++; + } + fputchar( digit ); + if ( feof( handle ) ) + return 0; + } else { + return 1; + } + } while( 1 ); + + return 0; +} diff --git a/expansor.exe b/expansor.exe new file mode 100644 index 0000000..58fd263 Binary files /dev/null and b/expansor.exe differ diff --git a/t b/t new file mode 100644 index 0000000..c8a86a1 --- /dev/null +++ b/t @@ -0,0 +1,17 @@ +o +esto solo es una prueba buscar en la base de datosksldf +ewrew +rewrew +rewrew +rewr + +ew + +sd + == \ No newline at end of file