[BACK]Return to entries.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cvs

Diff for /src/usr.bin/cvs/entries.c between version 1.3 and 1.4

version 1.3, 2004/07/14 05:16:04 version 1.4, 2004/07/14 19:03:00
Line 64 
Line 64 
         CVSENTRIES *ep;          CVSENTRIES *ep;
   
         memset(mode, 0, sizeof(mode));          memset(mode, 0, sizeof(mode));
         if (flags & O_RDONLY)          switch (flags & O_ACCMODE) {
           case O_RDWR:
                   mode[1] = '+';
                   /* fallthrough */
           case O_RDONLY:
                 mode[0] = 'r';                  mode[0] = 'r';
         else if (flags & O_WRONLY)                  break;
           case O_WRONLY:
                 mode[0] = 'w';                  mode[0] = 'w';
         else if (flags & O_RDWR) {                  break;
                 mode[0] = 'r';  
                 mode[1] = '+';  
         }          }
   
         snprintf(entpath, sizeof(entpath), "%s/" CVS_PATH_ENTRIES, dir);          snprintf(entpath, sizeof(entpath), "%s/" CVS_PATH_ENTRIES, dir);
Line 95 
Line 98 
                 return (NULL);                  return (NULL);
         }          }
   
         ep->cef_nid = 0;          ep->cef_cur = NULL;
         ep->cef_entries = NULL;          TAILQ_INIT(&(ep->cef_ent));
         ep->cef_nbent = 0;  
   
         /* only keep a pointer to the open file if we're in writing mode */  
         if ((flags & O_WRONLY) || (flags & O_RDWR))  
                 ep->cef_file = fp;  
   
         while (fgets(ebuf, sizeof(ebuf), fp) != NULL) {          while (fgets(ebuf, sizeof(ebuf), fp) != NULL) {
                 len = strlen(ebuf);                  len = strlen(ebuf);
                 if ((len > 0) && (ebuf[len - 1] == '\n'))                  if ((len > 0) && (ebuf[len - 1] == '\n'))
Line 111 
Line 109 
                 if (ent == NULL)                  if (ent == NULL)
                         continue;                          continue;
   
                 if (cvs_ent_add(ep, ent) < 0) {                  TAILQ_INSERT_TAIL(&(ep->cef_ent), ent, ce_list);
                         cvs_ent_close(ep);  
                         ep = NULL;  
                         break;  
                 }  
         }          }
   
         (void)fclose(fp);          /* only keep a pointer to the open file if we're in writing mode */
           if ((flags & O_WRONLY) || (flags & O_RDWR))
                   ep->cef_file = fp;
           else
                   (void)fclose(fp);
   
         return (ep);          return (ep);
 }  }
   
Line 161 
Line 160 
         }          }
         fprintf(ef->cef_file, "%s\n", ent->ce_line);          fprintf(ef->cef_file, "%s\n", ent->ce_line);
   
         tmp = realloc(ef->cef_entries, (ef->cef_nbent + 1) * sizeof(ent));          TAILQ_INSERT_TAIL(&(ef->cef_ent), ent, ce_list);
         if (tmp == NULL) {  
                 cvs_log(LP_ERRNO, "failed to resize entries buffer");  
                 return (-1);  
         }  
   
         ef->cef_entries = (struct cvs_ent **)tmp;  
         ef->cef_entries[ef->cef_nbent++] = ent;  
   
         return (0);          return (0);
 }  }
   
Line 198 
Line 189 
         if (cvs_ent_get(ef, ent->ce_name) != NULL)          if (cvs_ent_get(ef, ent->ce_name) != NULL)
                 return (-1);                  return (-1);
   
         tmp = realloc(ef->cef_entries, (ef->cef_nbent + 1) * sizeof(ent));          TAILQ_INSERT_TAIL(&(ef->cef_ent), ent, ce_list);
         if (tmp == NULL) {  
                 cvs_log(LP_ERRNO, "failed to resize entries buffer");  
                 return (-1);  
         }  
   
         ef->cef_entries = (struct cvs_ent **)tmp;  
         ef->cef_entries[ef->cef_nbent++] = ent;  
   
         return (0);          return (0);
 }  }
   
Line 223 
Line 206 
 cvs_ent_get(CVSENTRIES *ef, const char *file)  cvs_ent_get(CVSENTRIES *ef, const char *file)
 {  {
         u_int i;          u_int i;
           struct cvs_ent *ep;
   
         for (i = 0; i < ef->cef_nbent; i++) {          TAILQ_FOREACH(ep, &(ef->cef_ent), ce_list)
                 if (strcmp(ef->cef_entries[i]->ce_name, file) == 0)                  if (strcmp(ep->ce_name, file) == 0)
                         return ef->cef_entries[i];                          return (ep);
         }  
   
         return (NULL);          return (NULL);
 }  }
Line 236 
Line 219 
 /*  /*
  * cvs_ent_next()   * cvs_ent_next()
  *   *
    * This function is used to iterate over the entries in an Entries file.  The
    * first call will return the first entry of the file and each subsequent call
    * will return the entry following the last one returned.
  * Returns a pointer to the cvs entry structure on success, or NULL on failure.   * Returns a pointer to the cvs entry structure on success, or NULL on failure.
  */   */
   
 struct cvs_ent*  struct cvs_ent*
 cvs_ent_next(CVSENTRIES *ef)  cvs_ent_next(CVSENTRIES *ef)
 {  {
         if (ef->cef_nid >= ef->cef_nbent)          if (ef->cef_cur == NULL) {
                 return (NULL);                  ef->cef_cur = TAILQ_FIRST(&(ef->cef_ent));
                   return (ef->cef_cur);
           }
   
         return (ef->cef_entries[ef->cef_nid++]);          return TAILQ_NEXT(ef->cef_cur, ce_list);
 }  }
   
   

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4