home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / arcsrc.lzh / ARCDIR.MAC < prev    next >
Text File  |  1986-02-04  |  3KB  |  67 lines

  1. /*  ARC - Archive utility - ARCDIR
  2.  
  3. $define(tag,$$segment(@1,$$index(@1,=)+1))#
  4. $define(version,Version $tag(
  5. TED_VERSION DB =1.02), created on $tag(
  6. TED_DATE DB =02/04/86) at $tag(
  7. TED_TIME DB =01:36:09))#
  8. $undefine(tag)#
  9.     $version
  10.  
  11. (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  12.  
  13.     By:  Thom Henderson
  14.  
  15.     Description:
  16.          This file contains the dir() routine used when adding files to an
  17.          archive.  It is an adaptation of the CI-C86 library function
  18.          filedir().  It differes in that it returns the file names one by
  19.          one, instead of all at once.
  20.  
  21.     Language:
  22.          Computer Innovations Optimizing C86
  23. */
  24. #include <stdio.h>
  25.  
  26. static struct
  27. {   char dummy[21];                    /* reserved for dos */
  28.     unsigned char attribute;           /* returned attribute */
  29.     unsigned time;
  30.     unsigned date;
  31.     long size;                         /* size of file */
  32.     unsigned char fn[13];              /* string containing the filename */
  33. }   ff_area;
  34.  
  35. char *dir(filename,mode)               /* get files, one by one */
  36. char *filename;                        /* template, or NULL */
  37. int mode;                              /* search mode bits */
  38. {
  39.     struct { int ax,bx,cx,dx,si,di,ds,es; } reg;
  40.     char *result, *alloc();
  41.     static int first = 1;              /* true only on first call */
  42.  
  43. #ifdef _C86_BIG
  44.     reg.ds = ((unsigned long)filename) >> 16;
  45. #else
  46.     segread(®.si);                  /* get ds value */
  47. #endif
  48.     if(filename)                       /* if filename is given */
  49.     {    reg.dx = filename;            /* then use it */
  50.          reg.ax = 0x4e00;              /* and search for first */
  51.     }
  52.     else if(first)                     /* if no name and first call */
  53.          return NULL;                  /* then not much we can do */
  54.     else reg.ax = 0x4f00;              /* else search for next */
  55.     first = 0;                         /* no longer first time */
  56.  
  57.     reg.cx = mode;                     /* set search modes */
  58.     bdos(0x1a,&ff_area);               /* set the transfer address */
  59.  
  60.     if(sysint21(®,®)&1)
  61.          return NULL;                  /* no more files */
  62.  
  63.     result = alloc(strlen(ff_area.fn)+1);
  64.     strcpy(result,ff_area.fn);         /* save name of file */
  65.     return result;
  66. }
  67.