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 / SFN.CZ / SFN.C
Text File  |  2000-06-30  |  2KB  |  89 lines

  1. /* SFN - Directory access routines for CP/M. */
  2.  
  3. #include    <STDIO.H>
  4.  
  5. /* Getdir
  6.    Directory scanning engine.  Given an initialized fcb, getdir scans
  7.    the directory and calls copyname() once for each match found.  Getdir
  8.    resets the default dma address to 0x80 and logs into the drive/user
  9.    specified in the fcb.  The number of matches is returned to the caller.
  10.  
  11.    The copyname() routine is called with a pointer to the first byte of
  12.    the directory entry.
  13. */  
  14.  
  15. int getdir(fcb, copyname)
  16.     char *fcb;
  17.     void (*copyname)();
  18. {
  19.     char *dirbuf, *fcb1;
  20.     int matchct,i;
  21.  
  22.     matchct = 0;
  23.     dirbuf = 0x80;
  24.  
  25.     bdos(26,dirbuf);        /* point bdos dma to tbuff */
  26.     logud(fcb);        /* log the drive/user area specified */
  27.     if((i = bdos(17,fcb)) != 0xff) {
  28.         i <<= 5;        /* multiply dirbuf index by 32 */
  29.         ++matchct;
  30.         (*copyname)(dirbuf+i);    /* copy entry to buffer */    
  31.         while((i = bdos(18,0)) != 0xff) {
  32.             i <<= 5;
  33.             ++matchct;
  34.             (*copyname)(dirbuf+i);
  35.         }
  36.     }
  37.     return(matchct);
  38. }
  39.  
  40. /* Display file name, masking attributes.  Space padding shown. 
  41.    Period shown between name and type.
  42. */
  43.  
  44. void dispfn(fcb)
  45.     char fcb[];
  46. {
  47.     int i;
  48.  
  49.     for(i=1; i < 9; i++)
  50.         putchar(fcb[i] & 0x7f);
  51.     putchar('.');
  52.     for(; i < 12; i++)
  53.         putchar(fcb[i] & 0x7f);
  54. }
  55.  
  56. /* compare at most n characters in a dir or fcb */
  57.  
  58. int ncomp(x,y,n)
  59.     char *x,*y;
  60.     int n;
  61. {
  62.     int i,r;
  63.  
  64.     for(i = r = 0;i < n && r == 0; ++i) {
  65.         if(i<12 && i)
  66.             r = (*x++ & 0x7f) - (*y++ & 0x7f);    /* mask attributes */
  67.         else
  68.             r = (*x++) - (*y++);
  69.     }
  70.     if(r == 0)
  71.         return(r);
  72.     return(r > 0 ? 1 : -1);
  73. }
  74.  
  75. /* Given last extent, compute file size in k from record, extent, and 
  76.    data module fields.
  77. */
  78.  
  79. int fsize(dir)
  80.     char *dir;
  81. {
  82.     int i;
  83.     i = (dir[15] & 7) > 0;    /* i=0 if rec mod 8 = 0, else 1 */
  84.     i += dir[15] >> 3;    /* record -> k */
  85.     i += (dir[12] & 0x1f)<<4;    /* extent -> k */
  86.     i += (dir[14] & 0x3f)<<9;    /* data module -> k */
  87.     return(i);
  88. }
  89.