/* SFN - Directory access routines for CP/M. */ #include /* Getdir Directory scanning engine. Given an initialized fcb, getdir scans the directory and calls copyname() once for each match found. Getdir resets the default dma address to 0x80 and logs into the drive/user specified in the fcb. The number of matches is returned to the caller. The copyname() routine is called with a pointer to the first byte of the directory entry. */ int getdir(fcb, copyname) char *fcb; void (*copyname)(); { char *dirbuf, *fcb1; int matchct,i; matchct = 0; dirbuf = 0x80; bdos(26,dirbuf); /* point bdos dma to tbuff */ logud(fcb); /* log the drive/user area specified */ if((i = bdos(17,fcb)) != 0xff) { i <<= 5; /* multiply dirbuf index by 32 */ ++matchct; (*copyname)(dirbuf+i); /* copy entry to buffer */ while((i = bdos(18,0)) != 0xff) { i <<= 5; ++matchct; (*copyname)(dirbuf+i); } } return(matchct); } /* Display file name, masking attributes. Space padding shown. Period shown between name and type. */ void dispfn(fcb) char fcb[]; { int i; for(i=1; i < 9; i++) putchar(fcb[i] & 0x7f); putchar('.'); for(; i < 12; i++) putchar(fcb[i] & 0x7f); } /* compare at most n characters in a dir or fcb */ int ncomp(x,y,n) char *x,*y; int n; { int i,r; for(i = r = 0;i < n && r == 0; ++i) { if(i<12 && i) r = (*x++ & 0x7f) - (*y++ & 0x7f); /* mask attributes */ else r = (*x++) - (*y++); } if(r == 0) return(r); return(r > 0 ? 1 : -1); } /* Given last extent, compute file size in k from record, extent, and data module fields. */ int fsize(dir) char *dir; { int i; i = (dir[15] & 7) > 0; /* i=0 if rec mod 8 = 0, else 1 */ i += dir[15] >> 3; /* record -> k */ i += (dir[12] & 0x1f)<<4; /* extent -> k */ i += (dir[14] & 0x3f)<<9; /* data module -> k */ return(i); }