home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / COMPRESS / ARC520S.ZIP / ARCDIR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-10-23  |  2.2 KB  |  61 lines

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