version 1.3, 2004/07/14 05:16:04 |
version 1.4, 2004/07/14 19:03:00 |
|
|
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); |
|
|
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')) |
|
|
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); |
} |
} |
|
|
|
|
} |
} |
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); |
} |
} |
|
|
|
|
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); |
} |
} |
|
|
|
|
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); |
} |
} |
|
|
/* |
/* |
* 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); |
} |
} |
|
|
|
|