home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / OS2ARC_S.ZIP / ARCDIR.C < prev    next >
C/C++ Source or Header  |  1987-10-16  |  3KB  |  75 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. extern far pascal DOSFINDFIRST(char far *, int far *, int, char far *,
  27.                 int, int far *, unsigned long);
  28. extern far pascal DOSFINDNEXT(int, char far *, int, int far *);
  29.  
  30. static struct
  31. {   
  32.     unsigned int cdate,ctime;        /* creation date/time */
  33.     unsigned int adate,atime;        /* accessed date/time */
  34.     unsigned int wdate,wtime;        /* write date/time */
  35.     unsigned long filesize;        /* size */
  36.     unsigned long filealloc;        /* allocation */
  37.     unsigned int attribute;        /* attribute */
  38.     unsigned char namelength;        /* length of name */
  39.     unsigned char fn[15];        /* file name storage */
  40. }   ff_area;
  41.  
  42. static int dirhandle = 1;        /* directory search handle */
  43.  
  44. char *dir(filename,mode)               /* get files, one by one */
  45. char *filename;                        /* template, or NULL */
  46. int mode;                              /* search mode bits */
  47. {
  48.     char *result, *alloc();/*mpl*/
  49.     static int first = 1;              /* true only on first call */
  50.     int sf_mode = 1;            /* search first mode */
  51.     int num2find = 1;            /* how many to find */
  52.     int res;
  53.  
  54.     if(filename)                       /* if filename is given */
  55.     {
  56.     res = DOSFINDFIRST((char far *) filename,(int far *) &dirhandle,
  57.                 mode, (char far *) &ff_area, sizeof(ff_area),
  58.                 (int far *) &num2find,0L);
  59.         if (res) return NULL;
  60.     }
  61.     else if(first)                     /* if no name and first call */
  62.          return NULL;                  /* then not much we can do */
  63.     else {
  64.     res = DOSFINDNEXT(dirhandle,(char far *) &ff_area, sizeof(ff_area),
  65.               &num2find);
  66.     if (res) return NULL;
  67.     }
  68.  
  69.     first = 0;                         /* no longer first time */
  70.  
  71.     result = alloc(strlen(ff_area.fn)+1);/*mpl*/
  72.     strcpy(result,ff_area.fn);         /* save name of file */
  73.     return result;
  74. }
  75.