Category : Recently Uploaded Files
Archive   : DOSUIT07.ZIP
Filename : FLIST.CPP

 
Output of file : FLIST.CPP contained in archive : DOSUIT07.ZIP
#ifdef ALL
#define FLISTA
#define FLISTB
#define FLISTC
#define FLISTD
#define FLISTE
#define FLISTF
#define FLISTG
#define FLISTH
#define FLISTI
#define FLISTJ
#define FLISTK
#define FLISTL
#define FLISTM
#define FLISTN
#define FLISTO
#define FLISTP
#define FLISTQ
#endif
#ifndef FLISTA
#define LIBRARY_MODULE
#endif

/*
* Lists of files and/or directories
*/
#include
#include
#include
#ifdef disable /* TURBO C #defines enable & disable in dos.h ! */
#undef disable
#endif
#ifdef enable
#undef enable
#endif
#include
#include "flist.hpp"
#include "window.hpp"
#include "event.hpp"


#ifdef FLISTA
#ifdef __ZTC__
FoundFile::FoundFile(struct FIND *f)
: ListElement(strcpy(filename,f->name)), tim(f->date,f->time),
siz(f->size), att(FAreadable)
{
if(!(f->attribute & FA_RDONLY))
att = FileAttribute(att | FAwriteable);
if(f->attribute & FA_DIREC)
att = FileAttribute(att | FAdirectory);
else
att = FileAttribute(att | FAfile);
transfname(f->name);
}
#endif
#ifdef __TURBOC__
FoundFile::FoundFile(struct FIND *f)
: ListElement(strcpy(filename,f->ff_name)), tim(f->ff_fdate,f->ff_ftime),
siz(f->ff_fsize), att(FAreadable)
{
if(!(f->ff_attrib & FA_RDONLY))
att = FileAttribute(att | FAwriteable);
if(f->ff_attrib & FA_DIREC)
att = FileAttribute(att | FAdirectory);
else
att = FileAttribute(att | FAfile);
transfname(f->ff_name);
}
#endif
#endif

#ifdef FLISTB
FoundFile::FoundFile(char disk,int fixed)
: ListElement(strcpy(filename,"[A:")), tim(0l), siz(0),
att(fixed ? FAfixeddisk : FAremovedisk)
{
filename[1] = toupper(disk);
}
#endif

#ifdef FLISTC
FoundFile::FoundFile(const char *name,FileAttribute a,
const Time &time,unsigned long size)
: ListElement(strcpy(filename,name)), tim(time), siz(size),
att(FileAttribute(a | FAdummy))
{
transfname(name);
}
#endif

#ifdef FLISTD
FoundFile::~FoundFile()
{
}

coord FoundFile::minwidth() const
{
coord w = ListElement::minwidth();
if(attribute(FAdirectory) && name()[0] == '\\' && name()[1] == '.')
{
if(!name()[2])
w = 14;
else if(name()[2] == '.' && !name()[3])
w = 12;
}
else if(attribute(FAdisk) && name()[0] == '[' && name()[2] == ':'
&& name()[3] == 0)
w = 4;
return w;
}

void FoundFile::paint(const Rectangle &at, Window *w, const Rectangle &clip,
color col)
{
ListElement::paint(at, w, clip, col);
if(attribute(FAdirectory) && name()[0] == '\\' && name()[1] == '.')
{
Point p = { at.left() + 4, at.top() };

if(!name()[2])
w->printstring(p,clip,col,"(this dir)");
else if(name()[2] == '.' && !name()[3])
w->printstring(p,clip,col,"(parent)");
}
else if(attribute(FAdisk) && name()[0] == '[' && name()[2] == ':'
&& name()[3] == 0)
{
Point p = { at.left() + 3, at.top() };
w->printstring(p,clip,col,"]");
}
}

void FoundFile::transfname(const char *fname)
{
if(attribute(FAdirectory))
{
filename[0] = '\\';
strncpy(filename+1,fname,OSFileNameLen-1);
}
else
strncpy(filename,fname,OSFileNameLen);
}
#endif

#ifdef FLISTE
int sortname(const FoundFile *f1,const FoundFile *f2)
{
int retval = f1->attribute(FileAttribute(FAdirectory|FAdisk)) -
f2->attribute(FileAttribute(FAdirectory|FAdisk));

if(!retval)
retval = strcmp(f1->name(),f2->name());
return retval;
}
#endif

#ifdef FLISTF
int sortext(const FoundFile *f1,const FoundFile *f2)
{
int retval = f1->attribute(FileAttribute(FAdirectory|FAdisk)) -
f2->attribute(FileAttribute(FAdirectory|FAdisk));

if(!retval)
{
const char *s1 = f1->name(), *s2 = f2->name();

while(*s1 && *s1++ != '.')
;
while(*s2 && *s2++ != '.')
;
retval = strcmp(s1,s2);
}
if(!retval)
retval = strcmp(f1->name(),f2->name());
return retval;
}
#endif

#ifdef FLISTG
int sorttime(const FoundFile *f1,const FoundFile *f2)
{
int retval = f1->attribute(FileAttribute(FAdirectory|FAdisk)) -
f2->attribute(FileAttribute(FAdirectory|FAdisk));

if(!retval)
{
if(f1->time() > f2->time())
retval = 1;
else if(f1->time() < f2->time())
retval = -1;
else
retval = strcmp(f1->name(),f2->name());
}
return retval;
}
#endif

#ifdef FLISTH
int sortsize(const FoundFile *f1,const FoundFile *f2)
{
int retval = f1->attribute(FileAttribute(FAdirectory|FAdisk)) -
f2->attribute(FileAttribute(FAdirectory|FAdisk));

if(!retval)
{
if(f1->size() > f2->size())
retval = 1;
else if(f1->size() < f2->size())
retval = -1;
else
retval = strcmp(f1->name(),f2->name());
}
return retval;
}
#endif

#ifdef FLISTI
const char *dir(const char *p)
{
static char path[OSPathLen];

strcpy(path,p);

char *n = (char *)file(path);

if(n > path) // there is a path part
{
n--; // point to dir/disk delimiter
if(*n == ':') // current dir of disk
strcpy(n + 1,".");
else if(n == path || n[-1] == ':')
n[1] = 0; // root dir
else
*n = 0; // other dir
}
else
strcpy(path,".");
return path;
}
#endif

#ifdef FLISTJ
const char *file(const char *p)
{
const char *n = p;

while(*p)
switch(*p++)
{
case ':':
case '\\':
case '/':
n = p;
}
return n;
}
#endif

#ifdef FLISTK
const char *fullfilename(const char *directory,const char *file)
{
static char newname[OSPathLen+1];
int l = strlen(directory);

strcpy(newname,directory);
if(l > 0 && newname[l - 1] != '\\')
strcat(newname,"\\");
strcat(newname,file);
return newname;
}
#endif

#ifdef FLISTL
void fixdirname(char *s)
{
static char newname[OSPathLen+1];
static union REGS r;
static struct SREGS sg;

segread(&sg);
sg.es = sg.ds;
r.h.ah = 0x60; // qualify path name
sg.ds = FP_SEG(s);
r.x.si = FP_OFF(s);
sg.es = FP_SEG(newname);
r.x.di = FP_OFF(newname);
intdosx(&r,&r,&sg);
if(!r.x.cflag)
strcpy(s,newname);
}
#endif

#ifdef FLISTM
FileList::FileList(const char *fname,FileAttribute a,
const char *n,const BorderFlag b)
: List(files,OSFileNameLen,1,n,b)
{
addfiles(fname,a);
resize();
}
#endif

#ifdef FLISTN
FileList::FileList(coord height,const char *fname,FileAttribute a,
const char *n,const BorderFlag b)
: List(files,OSFileNameLen,height,n,b)
{
addfiles(fname,a);
resize();
}
#endif

#ifdef FLISTO
implement(LCollection,FoundFile)

FileList::~FileList()
{
deleteall();
}

int FileList::addfiles(const char *fname,FileAttribute a)
{
if(!(a & (FAfile | FAdirectory | FAdisk)))
return 0; // doesn't want anything we can find

struct FIND *f;
#ifdef __TURBOC__
struct FIND fbuf;
f = &fbuf;
#endif
int added = 0;

if(a & FAfile)
{
int attribute = FileAttribute(FA_RDONLY);

if(a & FAwriteable)
attribute &= ~FA_RDONLY;
#ifdef __ZTC__
for(f = findfirst((char *)fname,attribute); f; f = findnext())
{
attribute = f->attribute;
#endif
#ifdef __TURBOC__
for(int r = findfirst((char *)fname,f,attribute); r == 0; r = findnext(f))
{
attribute = f->ff_attrib;
#endif
if((attribute & FA_RDONLY) && (a & FAwriteable))
continue; // exclude read-only files
if(attribute & FA_DIREC)
continue; // exclude directories for now
files.add(new FoundFile(f));
added++;
}
}
if(a & FAdirectory)
{
int dotfound = (a & FAexcludedot);

fname = fullfilename(dir(fname),"*.*");
#ifdef __ZTC__
for(f = findfirst((char *)fname,FA_DIREC); f; f = findnext())
{
if(!(f->attribute & FA_DIREC))
continue; // only directories wanted now
if(f->name[0] == '.' && !f->name[1])
#endif
#ifdef __TURBOC__
for(int r = findfirst((char *)fname,f,FA_DIREC); r == 0; r = findnext(f))
{
if(!(f->ff_attrib & FA_DIREC))
continue; // only directories wanted now
if(f->ff_name[0] == '.' && !f->ff_name[1])
#endif
{
if(dotfound)
continue;
dotfound = 1;
}
files.add(new FoundFile(f));
added++;
}
if(!dotfound)
files.add(new FoundFile(".",FileAttribute(FAreadable|FAwriteable|FAdirectory)));
}
if(a & FAdisk)
{
union REGS regs;
regs.h.ah = 0x19; // get default disk
intdos(®s,®s);
regs.h.ah = 0x0e; // set default disk
regs.h.dl = regs.h.al; // to the same one
intdos(®s,®s); // returns no of drives in AL

char lastdrive = regs.h.al + 'A';

for(char i = 'A'; i < lastdrive; i++)
{
regs.x.ax = 0x4408; // check if drive changeable
regs.h.bl = i - 'A' + 1;// drive no (1 = A, 2 = B, ...)
intdos(®s,®s);
if((regs.h.al & 0x0f) == 0x0f)
continue; // invalid drive
// BIT(0) set if fixed disk
files.add(new FoundFile(i,(regs.h.al & BIT(0))));
}
}
dirty();
changeCollection();
return added;
}
#endif

#ifdef FLISTP
int FileList::addFile(FoundFile *f)
{
int o = line();
deselect();
int l = files.add(f);

if(l < 0)
{
if(o >= 0)
select(o);
return l; // could not add
}
if(l >= topitem() && l - topitem() < height() - 1)
dirty(); // add is visible on screen
if(o >= 0)
select(l); // select recently added item
changeCollection();
return l;
}
#endif

#ifdef FLISTQ
void FileList::sort(int (*compare)(const FoundFile *,const FoundFile *))
{
FoundFile *f = files[line()]; // remember which one selected

deselect();
files.sort(compare);
dirty();
changeCollection();
if(f)
select(files.elementNo(f)); // select the same one
}
#endif


  3 Responses to “Category : Recently Uploaded Files
Archive   : DOSUIT07.ZIP
Filename : FLIST.CPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/