home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
JSAGE
/
ZSUS
/
PROGPACK
/
CFORZ02.LBR
/
CDIR.CZ
/
CDIR.C
Wrap
Text File
|
2000-06-30
|
3KB
|
132 lines
/* CDIR
Example of low level dos access with BDS C. Prints a sorted directory
with file sizes to the nearest K. This version is for ZCPR systems
and will accept DIR: specifications. You must have BDSZ to use this!
You need to link this with the command:
clink cdir -f z3func05 z3func03 z3func01 sfn zsutil cvlib itoa -n
*/
#include <STDIO.H>
#define DIRSTO 14 /* Size of storage for each dir entry */
#define NDIR 1024 /* Maximum number of directory entries */
char *fnbuf, *bufptr;
int numfn;
main(argc,argv)
int argc;
char *argv[];
{
char *alloc(), *fn2as(), *dir2a();
int fcomp();
void storefn();
char *fnptr, *fcb, *p, tempd[13], tempn[13];
int i, user, crow, ccol, nrow, ncol;
/* initialize variables */
fcb = 0x5c; /* use default fcb */
fnbuf = bufptr = alloc(DIRSTO*NDIR); /* create buffer for files */
numfn = 0;
iobreak(0);
printf("CDIR Version 0.2\n");
if(!fnbuf) {
printf("*** Not enough memory!\n");
exit(-1);
}
/* Parse file spec into fcb */
if(zsetfcb(fcb, (argc <= 1 ? "*.*": argv[1]), &user) == ERROR)
printf("*** Illegal filename!\n");
else {
/* Test for du: only and wildcard if needed */
if(fcb[1] == ' ' && fcb[9] == ' ')
for(i=1;i<12;fcb[i++]='?');
/* print header */
printf("Directory for %s:%s\n",dir2a(getfdu(fcb),tempd),fn2as(fcb,tempn));
fcb[12] = fcb[14] = '?'; /* get all extents */
/* read dir, sort into alpha order by name */
i = getdir(fcb, storefn);
qsort(fnbuf,numfn,DIRSTO,fcomp);
/* eliminate all but the last extent of a file */
for(p=fnbuf,i=1;i<numfn;) {
if(ncomp(p,p+DIRSTO,12) == 0) {
movmem(p+DIRSTO,p,(numfn-i)*DIRSTO);
--numfn;
} else {
p+=DIRSTO;
++i;
}
}
/* Display names and sizes, 4 per row */
nrow = ckrow(255); /* get number of rows from env */
ncol = ckcol(255); /* get number of cols from env */
ncol /= 20; /* number of names per line */
crow = ccol = 1;
for(p=fnbuf,i=0;i<numfn;++i,p+=DIRSTO) {
if(--ccol == 0) {
if(++crow == nrow-1) {
getchar(); /* page break */
crow = 1; /* reset counter */
}
printf("\n ");
ccol = ncol;
} else {
printf(" | ");
}
printf("%s%4dk",fn2as(p,tempn),(p[12] << 8)+p[13]);
}
printf("\n%d files matched\n",numfn);
}
}
/* Dir manipulation routine passed to getdir. Copies the user and filename
to the buffer, then computes the file size as if this entry represents
the last extent of the file. The size in k is stored in REVERSE order
so that when the entries are sorted, the extent with the largest size
is LAST. After sorting, all but the last entry will be removed from
the buffer. Note this is the virtual size of the file.
*/
void storefn(dir)
char *dir;
{
int i;
if(*dir < 0x20) {
for(i=0 ; i < 12; ++i)
bufptr[i] = dir[i];
i = fsize(dir);
bufptr[12] = i >> 8; /* msb */
bufptr[13] = i & 0xff; /* lsb */
if(numfn < NDIR) {
++numfn;
bufptr += DIRSTO;
}
}
}
/* file name compare routine for qsort */
int fcomp(x,y)
char *x,*y;
{
return(ncomp(x,y,DIRSTO));
}