campo-sirio/cb/source/t4info.cpp
alex af15e0698b Codebase
git-svn-id: svn://10.65.10.50/trunk@4679 c028cbd2-c16b-5b4b-a496-9718f37d4682
1997-06-16 13:01:08 +00:00

230 lines
5.0 KiB
C++
Executable File

/* t4info.cpp/cxx (c)Copyright Sequiter Software Inc., 1988-1996. All rights reserved. */
#include "d4all.hpp"
#ifdef __TURBOC__
#pragma hdrstop
#endif /* __TUROBC__ */
Tag4info::Tag4info( Code4 &code )
{
size = 0 ;
codeBase = &code ;
length = 0 ;
tag = NULL ;
expr=filt=0;
}
Tag4info::Tag4info( Index4 i )
{
size = 0 ;
codeBase = (Code4 *) i.index->data->codeBase ;
length = 0 ;
tag = NULL ;
expr=filt=0;
add_index_tags( i.index ) ;
}
Tag4info::Tag4info( Data4 d )
{
INDEX4 *index = (INDEX4*) l4next( &(d.data->indexes), NULL ) ;
size = 0 ;
codeBase = (Code4 *) d.data->codeBase ;
length = 0 ;
tag = NULL ;
expr=filt=0;
for(; index != NULL ; index = (INDEX4*) l4next( &(d.data->indexes), index ) )
add_index_tags( index ) ;
}
int Tag4info::add_index_tags( INDEX4 *index )
{
TAG4INFO *tagInfo ;
int i = 0 ;
tagInfo = i4tagInfo( index ) ;
while( tagInfo[i].name != 0 )
{
add( getName( tagInfo, i ), getExpr( tagInfo, i ), getFilter( tagInfo, i ),
getUniqueKey( tagInfo, i ), getDescendKey( tagInfo, i ) ) ;
i++ ;
}
return 0 ;
}
int Tag4info::add( Tag4 tagIn )
{
TAG4INFO *tagInfo ;
int i = 0 ;
char *name ;
tagInfo = i4tagInfo( tagIn.tag->index ) ;
name = t4alias( tagIn.tag ) ;
while( strcmp( tagInfo[i].name, name ) != 0 ) i++ ;
add( getName( tagInfo, i ), getExpr( tagInfo, i ), getFilter( tagInfo, i ),
getUniqueKey( tagInfo, i ), getDescendKey( tagInfo, i ) ) ;
return 0 ;
}
int Tag4info::add( const char *name, const char *expre, const char *filter,
int uniq, int desc )
{
Str4ten st_name( name ) ;
st_name.upper() ;
st_name.trim() ;
#ifdef E4DEBUG
if( name == 0 || expre == 0 )
return codeBase->error( e4parm, E60991 ) ;
#endif
if( u4allocAgain( codeBase, (char **)&tag, &length,
(size+2) * sizeof( TAG4INFO ))!=0 )
return -1 ;
tag[size].name = (char *)u4allocEr( codeBase, 11 ) ;
if( tag[size].name )
u4ncpy( tag[size].name, st_name.ptr(), 11 ) ;
unsigned len = strlen(expre) + 1 ;
//tag[size].expression = (char *)u4allocEr( codeBase, len ) ;
expr= (char *)u4allocEr( codeBase, len ) ;
if( expr != NULL )
u4ncpy( expr, expre, len ) ;
tag[size].expression=expr;
//if( tag[size].expression != NULL )
// u4ncpy( tag[size].expression, expre, len ) ;
if( filter )
{
filt = (char *)u4allocEr( codeBase, len = strlen( filter )+1 ) ;
//tag[size].filter = (char *)u4allocEr( codeBase, len = strlen( filter )+1 ) ;
if( filt != NULL )
//if( tag[size].filter != NULL )
u4ncpy( filt, filter, len ) ;
//u4ncpy( tag[size].filter, filter, len ) ;
tag[size].filter=filt;
}
if( codeBase->errorCode < 0 )
{
u4free( tag[size].name ) ;
u4free( expr ) ;
//u4free( tag[size].expression ) ;
u4free( filt ) ;
//u4free( tag[size].filter ) ;
memset( tag+size, 0, sizeof(TAG4INFO) ) ;
return -1 ;
}
tag[size].unique = uniq ;
tag[size].descending = desc ;
size++ ;
return 0 ;
}
char * Tag4info::getName( TAG4INFO *tagInfo, int tagPos )
{
if( tagInfo[tagPos].name != 0 )
return tagInfo[tagPos].name ;
else
return 0 ;
}
const char * Tag4info::getExpr( TAG4INFO *tagInfo, int tagPos )
{
if( tagInfo[tagPos].name != 0 )
return tagInfo[tagPos].expression ;
else
return 0 ;
}
const char * Tag4info::getFilter( TAG4INFO *tagInfo, int tagPos )
{
if( tagInfo[tagPos].name != 0 )
return tagInfo[tagPos].filter ;
else
return 0 ;
}
int Tag4info::getUniqueKey( TAG4INFO *tagInfo, int tagPos )
{
if( tagInfo[tagPos].name != 0 )
return tagInfo[tagPos].unique ;
else
return 0 ;
}
int Tag4info::getDescendKey( TAG4INFO *tagInfo, int tagPos )
{
if( tagInfo[tagPos].name != 0 )
return tagInfo[tagPos].descending ;
else
return 0 ;
}
void Tag4info::free( )
{
for( ; size > 0 ; )
{
size -- ;
u4free( tag[size].name ) ;
tag[size].expression=0;
u4free( expr ) ;
//u4free( tag[size].expression ) ;
tag[size].filter=0;
u4free( filt ) ;
//u4free( tag[size].filter ) ;
}
u4free( tag ) ;
tag = 0 ;
size = 0 ;
length = 0 ;
}
Tag4info::~Tag4info()
{
free( ) ;
}
int Tag4info::del( int index )
{
if( index >= size || index < 0 )
return codeBase->error( e4parm, E60982 ) ;
u4free( tag[index].name ) ;
tag[index].expression=0;
tag[index].filter=0;
u4free( expr ) ;
u4free( filt ) ;
memcpy( tag+index, tag+index+1, sizeof(TAG4INFO) * (size-index) ) ;
size-- ;
return 0 ;
}
int Tag4info::del( const char *name )
{
Str4ten st_tag( name ) ;
st_tag.upper( ) ;
st_tag.trim( ) ;
for( int i = 0 ; i < size ; i++ )
{
if( memcmp( tag[i].name, st_tag.ptr( ), st_tag.len() ) == 0 )
{
del( i ) ;
return 0 ;
}
}
codeBase->error( e4parm, E60982, name ) ;
return -1 ;
}