home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / zoo_src / z201src1 / addfname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-25  |  3.5 KB  |  128 lines

  1. #ifndef LINT
  2. static char sccsid[]="@(#) addfname.c 2.11 88/02/06 20:17:17";
  3. #endif /* LINT */
  4.  
  5. /*
  6. Copyright (C) 1986, 1987 Rahul Dhesi -- All rights reserved
  7. (C) Copyright 1988 Rahul Dhesi -- All rights reserved
  8. */
  9. #include "options.h"
  10.  
  11. /* Adds a filename to global list.  (This global list will eventually
  12. be searched by the inlist() function.)  The second and subsequent
  13. parameters suppplied are stored with the name of the file and 
  14. returned by inlist. */
  15.  
  16. #include "zooio.h"
  17. #include "various.h"
  18. #include "zoo.h"
  19. #include "zoofns.h"
  20. #include "zoomem.h" /* to get LIST_SIZE */
  21.  
  22. static struct item *fentry[LIST_SIZE];
  23. static int lastname = 0;                  /* index of last name */
  24.  
  25. struct item {              /* global filename list entry */
  26.    char *fname;
  27.    long position;
  28.    unsigned int date;
  29.    unsigned int time;
  30.     unsigned vflag;
  31.     unsigned version_no;
  32. };
  33.  
  34. void addfname(fname, position, date, time, vflag, version_no)
  35. char *fname;
  36. long position;
  37. unsigned int date, time;
  38. unsigned vflag;
  39. unsigned version_no;
  40. {
  41.    if (lastname == 0)
  42.       fentry[lastname] = (struct item *) emalloc (sizeof(struct item));
  43.  
  44.    /* keep a few empty spaces at end to avoid off by one errors */
  45.    if (lastname >= LIST_SIZE - 3)
  46.       memerr();
  47.  
  48.    fentry[lastname]->fname = strdup(fname);
  49.    fentry[lastname]->position = position;
  50.    fentry[lastname]->date = date;
  51.    fentry[lastname]->time = time;
  52.     fentry[lastname]->vflag = vflag;
  53.     fentry[lastname]->version_no = version_no;
  54.    lastname++;
  55.    /* allocate memory for empty entry at end */
  56.    fentry[lastname] = (struct item *) emalloc (sizeof(struct item)); 
  57. } /* addfname */
  58.  
  59. /* inlist() */
  60. /* Examines global list built by addfname() to see if supplied filename
  61. is in the list.  
  62.  
  63. If found, returns the file's position within the archive as the function 
  64. value and the date, time, version flag, and version number as parameters.
  65. If not found, returns -1.  Also returns the highest version no. seen
  66. for this filename and the vflag associated with that version.
  67.  
  68. A simple sequential search is done.
  69.  
  70. If justname is nonzero, then the search is for the filename only
  71. without the directory prefix;  else it is for the full
  72. pathname.
  73. */
  74.  
  75. long inlist (fname, date, time, this_version_no, high_vflag, 
  76.                     high_version_no, high_pos, justname)
  77. char *fname;
  78. unsigned int *date, *time;
  79. unsigned *high_vflag;
  80. unsigned *this_version_no;
  81. unsigned *high_version_no;
  82. long *high_pos;
  83. int justname;
  84. {
  85.    register int i = 0;
  86.  
  87.     *high_version_no = 0;
  88.     if (justname)
  89.         fname = nameptr (fname);                    /* if directory wanted */
  90.    fentry[lastname]->fname = fname;          /* sentinel */
  91.     fentry[lastname]->version_no = 0;
  92.  
  93. #ifdef IGNORECASE
  94. #define    COMPARE    strcmpi
  95. #else
  96. #define    COMPARE    strcmp
  97. #endif
  98.  
  99.    while (COMPARE(fname,
  100.             (justname ? nameptr (fentry[i]->fname) : fentry[i]->fname)) != 0) {
  101.       i++;
  102.    }
  103.  
  104.    if (i == lastname)
  105.       return (-1L);
  106.    else {
  107.         int j;
  108.         *date = fentry[i]->date;
  109.         *time = fentry[i]->time;
  110.         *high_pos = fentry[i]->position;
  111.         *high_vflag = fentry[i]->vflag;
  112.         for (j = i; j < lastname; j++) {    /* find highest version no. for file */
  113.             if (COMPARE(fname,
  114.                 (justname ? nameptr (fentry[j]->fname) : fentry[j]->fname)) == 0) {
  115.                 if (*high_version_no < fentry[j]->version_no) {
  116.                     *high_version_no = fentry[j]->version_no;
  117.                     *high_vflag = fentry[j]->vflag;
  118.                     *high_pos = fentry[j]->position;
  119.                     *date = fentry[j]->date;
  120.                     *time = fentry[j]->time;
  121.                 }
  122.             }
  123.         }
  124.         *this_version_no = fentry[i]->version_no;
  125.       return (fentry[i]->position);
  126.    }
  127. } /* inlist() */
  128.