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

 
Output of file : FILEEDIT.CPP contained in archive : DOSUIT07.ZIP
#ifdef ALL
#define FILEEDA
#define FILEEDB
#endif
#ifndef FILEEDA
#define LIBRARY_MODULE
#endif

#include
#include
#include
#include
#include
#ifdef disable /* TURBO C #defines enable & disable in dos.h ! */
#undef disable
#endif
#ifdef enable
#undef enable
#endif
#include "fileedit.hpp"
#include "popwin.hpp"
#include "event.hpp"


class FileBrowser : public FileList {
public:
FileBrowser(FileEdit *e,const char *dir,const char *file,FileAttribute a);

virtual int pick();
virtual int escape();

private:
FileAttribute attrib;
FileEdit *editor;
char chosen[OSPathLen];
char mask[OSFileNameLen+1];
};

#ifdef FILEEDA
FileBrowser::FileBrowser(FileEdit *e,const char *dir,const char *file,
FileAttribute a)
: FileList(fullfilename(dir,file),(a & FAdirectory) ?
FileAttribute(a|FAdisk) : FileAttribute(a|FAdisk|FAdirectory|FAexcludedot)), attrib(a),
editor(e)
{
strcpy(chosen,dir);
fixdirname(chosen);
strncpy(mask,file,OSFileNameLen);
sort(sortname);
}

int FileBrowser::pick()
{
const FoundFile *f = selected();

if(!f)
return 0;
if(f->attribute(FAdisk))
{
strcpy(chosen,f->fname());
strcat(chosen,".");
}
else
strcpy(chosen,fullfilename(chosen,f->fname()));
fixdirname(chosen);
if(f->attribute(FAfile) // file chosen
|| (f->fname()[0] == '.' && !f->fname()[1]))// current dir chosen
editor->endBrowse(chosen);
else // another dir chosen
{
editor->setString(chosen);// show new chosen value
deleteall();
addfiles(fullfilename(chosen,mask),(attrib & FAdirectory) ?
FileAttribute(attrib|FAdisk) : FileAttribute(attrib|FAdisk|FAdirectory|FAexcludedot));

PopWindow *pop = (PopWindow *)window;
Point p = pop->topleft();

pop->popout();
pop->popin(p);
}
return 1;
}

int FileBrowser::escape()
{
if(editor)
editor->endBrowse();
return 1;
}

FileEdit::FileEdit(char *string,const char *prompt,
int allowCreate,FileAttribute a,int length)
: UpperEdit(string,length,prompt,"-0-9A-Z/\\:!$%^_#~.?*"),
createOK(allowCreate), attrib(a)
{
setBrowsable();
}

const char *FileEdit::directory() const
{
return dir(string());
}

const char *FileEdit::filename() const
{
const char *n = string();

for(const char *s = n; *s; s++)
switch(*s)
{
case ':':
case '\\':
case '/':
n = s + 1;
}
return n;
}

int FileEdit::validate()
{
char *p = strchr(edittext,':');
if(p)
{
p++;
if((p - edittext > 2 || strchr(p,':')))
return 0;
}
return 1;
}

#ifdef __TURBOC__
TextEdit::
#endif
Complete FileEdit::complete()
{
struct stat s;

fixdirname(edittext); // standardise name
if(!stat((char *)edittext,&s))
{
if(!(s.st_mode & S_IWRITE)) // read-only
{
if(attrib & FAwriteable) // but we want only writeable files
return Cinvalid;
}
if(s.st_mode & S_IFDIR) // is a directory
{
if(!(attrib & FAdirectory)) // but we don't want directories
return Cinvalid;
}
else // is a file
{
if(!(attrib & FAfile)) // but we don't want files
return Cinvalid;
}
return Cchanged;
}
// item does not exist
if(createOK && !stat((char *)dir(edittext),&s)) // does directory exist ?
{
if(s.st_mode & S_IFDIR) // is it really a directory
return Cchanged;
}
return Cinvalid;
}

VObject *FileEdit::browse()
{
struct stat s;
const char *f, *d = directory();

if(stat((char *)d,&s) || !(s.st_mode & S_IFDIR))
return 0; // directory not found
if(stat((char *)string(),&s) || !(s.st_mode & S_IFDIR))
{ // this is a file specifier, or doesn't exist
f = filename();
if(!strpbrk(f,"*?"))
f = "*.*"; // not ambiguous, so show all files in same directory
}
else // this is a directory specifier
{
d = string();
f = "*.*";
}
return new FileBrowser(this,d,f,attrib);
}
#endif

#ifdef FILEEDB
DirectoryEdit::DirectoryEdit(char *string,const char *prompt,int length)
: FileEdit(string,prompt,0,FAdirectory,length)
{
}
#endif


  3 Responses to “Category : Recently Uploaded Files
Archive   : DOSUIT07.ZIP
Filename : FILEEDIT.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/