home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 1
/
FFMCD01.bin
/
bbs
/
cliutil
/
dirs.lha
/
Dirs
/
Deutsch
/
dirs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-23
|
16KB
|
659 lines
// dirs geschrieben von Harald Pehl
// Letze Änderung am 23.August.1993, 18:30:24
// Version 1.00
// compiliert mit MaxonC++
// Includes
#include <pragma/exec_lib.h>
#include <pragma/dos_lib.h>
#include <dos/dosextens.h>
#include <dos/datetime.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <stream.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
// Funktionen
void close_all (const char *, const int);
char *itoa (int);
void strrfil (char *, char *, const char, int);
void strlfil (char *, char *, const char, int);
BOOL readdir (char *);
void usage ();
// Optionen für ReadArgs
char *template = "ARGS/M,C=CLI/S,S=SINCE/K,U=UPTO/K,AS=ALPHASORT/S,"\
"-AS=-ALPHASORT/S,SS=SIZESORT/S,-SS=-SIZESORT/S,"\
"DS=DATESORT/S,-DS=-DATESORT/S,Q=QUICK/S,DO=DIRSONLY/S,"\
"FO=FILESONLY/S,FF=FILESFIRST/S,SH=SHOWHIDDEN/S,NH=NOHEAD/S,"\
"NI=NOINFO/S,NS=NOSIZE/S,NP=NOPROTECT/S,ND=NODATE/S,"\
"NC=NOCOMMENT/S,V=VAR/K,HEADFORM/K,?=HELP/S";
struct Def
{
char **argv;
long cli;
char *since;
char *upto;
long alphasort;
long alphasortdown;
long sizesort;
long sizesortdown;
long datesort;
long datesortdown;
long quick;
long dirsonly;
long filesonly;
long filesfirst;
long showhidden;
long nohead;
long noinfo;
long nosize;
long noprotect;
long nodate;
long nocomment;
char *var;
char *headform;
long help;
} args = {NULL, FALSE, FALSE, FALSE, NULL, NULL, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, NULL, " <»--«> ", FALSE};
struct RDArgs *rda = NULL;
struct FileInfoBlock *fib = NULL;
BOOL sincedate = TRUE, uptodate = TRUE;
struct DateTime *dat = NULL, *since = NULL, *upto = NULL;
char strdate[LEN_DATSTRING], strtime[LEN_DATSTRING], *pat = NULL;
// Klasse, in der ein File bzw. Directory festgehalten wird
class Entry
{
Entry *prev, *next;
BOOL dir;
long size, days, mins;
char name[108], outstr[116];
Entry ();
int compare (const Entry *) const;
friend class Lst;
};
Entry::Entry ()
{
char *s = outstr;
prev = next = NULL;
dir = fib->fib_DirEntryType > 0 ? TRUE : FALSE;
size = fib->fib_Size;
days = fib->fib_Date.ds_Days;
mins = fib->fib_Date.ds_Minute;
strcpy (name, fib->fib_FileName);
memset (s, 0, 116);
if (args.quick) // Jetzt outstr je nach Parameter mit Daten auffüllen
{
strcpy (outstr, name);
return;
}
strlfil (s, name, ' ', 25);
s += 24;
if (!args.nosize)
{
if (dir)
{
strncpy (s, " (dir) ", 11);
s += 10;
}
else
{
strrfil (s, itoa (size), ' ', 7);
strcat (s, " ");
s += 10;
}
}
if (!args.noprotect)
{
int i, j;
char p[] = "hsparwed";
for (i = 128, j = 0 ; i >= 16 ; i >>= 1, j++, s++)
if (fib->fib_Protection & i)
*s = p[j];
else
*s = '-';
for (i = 8, j = 4 ; i >= 1 ; i >>= 1, j++, s++)
if (fib->fib_Protection & i)
*s = '-';
else
*s = p[j];
strcat (s, " ");
s += 3;
}
if (!args.nodate)
{
dat->dat_Stamp = fib->fib_Date;
if (DateToStr (dat))
{
strlfil (s, dat->dat_StrDate, ' ', 11);
s += 10;
strlfil (s, dat->dat_StrTime, ' ', 12);
s += 11;
}
}
if (!args.nocomment)
{
if (*fib->fib_Comment != '\0')
{
strcat (s, "\n ");
s += 4;
strncat (s, fib->fib_Comment, 40);
}
}
}
int Entry::compare (const Entry *that) const
{
if (args.alphasort || args.alphasortdown)
return stricmp (name, that->name);
else if (args.sizesort || args.sizesortdown)
return size - that->size;
else if (args.datesort || args.datesortdown)
return (days - that->days) ? (days - that->days) : (mins - that->mins);
// Wenn die Differenz der zwei Daten 0 ist, dann wird die Differenz
// der zwei Zeitangaben zurückgegeben
else return -1;
}
// Klasse, die die Einträge enthält
class Lst
{
Entry *first, *last;
public:
int count, bytes;
Lst ();
~Lst ();
void insert ();
void ausgabe () const;
BOOL empty () const;
};
Lst::Lst ()
{
count = bytes = 0;
first = last = NULL;
}
Lst::~Lst ()
{
Entry *e = first;
while (e)
{
Entry *hilf = e;
e = e->next;
delete hilf;
}
}
void Lst::insert ()
{
BOOL sort = FALSE;
Entry *pos = first, *neu = NULL;
if (pat) // Ist ein Pattern definiert?
if (MatchPatternNoCase (pat, fib->fib_FileName) == NULL)
return;
if (args.since) // Gibt es eine since-Vorgabe
{
if (sincedate)
{
if (fib->fib_Date.ds_Days < since->dat_Stamp.ds_Days)
return;
}
else
{
if (fib->fib_Date.ds_Minute < since->dat_Stamp.ds_Minute)
return;
}
}
if (args.upto) // Gibt es eine upto-Vorgabe
{
if (uptodate)
{
if (fib->fib_Date.ds_Days > upto->dat_Stamp.ds_Days)
return;
}
else
{
if (fib->fib_Date.ds_Minute > upto->dat_Stamp.ds_Minute)
return;
}
}
if (fib->fib_DirEntryType < 0) // Ist der Eintrag ein File
{ // und sind nur Dirs
if (args.dirsonly) // zugelassen...
return;
if (args.noinfo && strstr (fib->fib_FileName, ".info"))
return;
}
else
{
if (args.filesonly) // ...oder umgekehrt?
return;
}
if (!args.showhidden) // Ist das 'h'-Bit gesetzt
if (fib->fib_Protection & FIBF_HIDDEN)
return;
neu = new Entry ();
if (neu == NULL)
{
cout << "\nKein Speicherplatz mehr!!\n\n";
return;
}
// Sortieren falls nötig
if (args.alphasort || args.sizesort || args.datesort)
{
while (pos && neu->compare (pos) > 0)
pos = pos->next;
sort = TRUE;
}
else if (args.alphasortdown || args.sizesortdown || args.datesortdown)
{
while (pos && neu->compare (pos) < 0)
pos = pos->next;
sort = TRUE;
}
if (sort)
{
// und endlich einfügen
if (pos == NULL)
{
Entry *alt = last;
if (alt != NULL)
{
alt->next = neu;
neu->prev = alt;
last = neu;
}
else
{
first = neu;
last = neu;
}
}
else
{
if (pos->prev == NULL)
{
pos->prev = neu;
neu->next = pos;
first = neu;
}
else
{
Entry *vor = pos->prev;
vor->next = neu;
neu->prev = vor;
neu->next = pos;
pos->prev = neu;
}
}
}
else
{
Entry *alt = last;
if (alt)
{
alt->next = neu;
neu->prev = alt;
last = neu;
}
else
{
first = neu;
last = neu;
}
}
count++;
if (!neu->dir)
bytes += neu->size;
return;
}
void Lst::ausgabe () const
{
for (Entry *e = first ; e ; e = e->next)
cout << " " << e->outstr << "\n";
}
BOOL Lst::empty () const
{
return first || last ? FALSE : TRUE;
}
void close_all (const char *why, const int how)
{
if (why) cout << why << "\n\n";
if (pat) delete [] pat;
if (fib) FreeDosObject (DOS_FIB, (APTR)fib);
if (upto) FreeVec ((APTR)upto);
if (since) FreeVec ((APTR)since);
if (dat) FreeVec ((APTR)dat);
if (rda) FreeArgs (rda);
exit (how);
}
char *itoa (int zahl)
{
static char res[10];
char c, *dest = res;
int maxpot = 1000000, flag = 0;
while (maxpot >= 1)
{
c = zahl / maxpot + '0';
if ((c != '0') || (maxpot == 1) || flag)
{
flag = 1;
*dest++ = c;
}
zahl %= maxpo