home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
tv20os2.zip
/
src
/
TFileCollection.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1998-01-19
|
1KB
|
66 lines
/*
* TFileCollection.cc
*
* Turbo Vision - Version 2.0
*
* Copyright (c) 1994 by Borland International
* All Rights Reserved.
*
* Modified by Sergio Sigala <ssigala@globalnet.it>
*/
#define Uses_TFileCollection
#define Uses_TSearchRec
#include <tvision/tv.h>
#include <string.h>
inline const char *getName( void *k )
{
return ((TSearchRec *)k)->name;
}
inline int attr( void *k )
{
return ((TSearchRec *)k)->attr;
}
int TFileCollection::compare(void *key1, void *key2)
{
if( strcmp( getName( key1 ), getName( key2 ) ) == 0 )
return 0;
if( strcmp( getName( key1 ), ".." ) == 0 )
return 1;
if( strcmp( getName( key2 ), ".." ) == 0 )
return -1;
if( (attr( key1 ) & FA_DIREC) != 0 && (attr( key2 ) & FA_DIREC) == 0 )
return 1;
if( (attr( key2 ) & FA_DIREC) != 0 && (attr( key1 ) & FA_DIREC) == 0 )
return -1;
return strcmp( getName( key1 ), getName( key2 ) );
}
TStreamable *TFileCollection::build()
{
return new TFileCollection( streamableInit );
}
void TFileCollection::writeItem( void *obj, opstream& os )
{
TSearchRec *item = (TSearchRec *)obj;
os << item->attr << item->time << item->size;
os.writeString( item->name );
}
void *TFileCollection::readItem( ipstream& is )
{
TSearchRec *item = new TSearchRec;
is >> item->attr >> item->time >> item->size;
is.readString( item->name, sizeof(item->name) );
return item;
}