/* 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 #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> 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)); }