diff options
author | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2004-08-04 15:39:11 +0000 |
---|---|---|
committer | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2004-08-04 15:39:11 +0000 |
commit | 114e8fb25b365f63650c1b837d8732ec01230431 (patch) | |
tree | 957069ebc5927c4e4020e529b4cad56a9fe9a0a8 /usr.bin | |
parent | ebc56c5a53382df8aac4df260e6108627566fa03 (diff) |
Simplify entry parsing
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/entries.c | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/usr.bin/cvs/entries.c b/usr.bin/cvs/entries.c index 698f7409bda..da6d39cf2f8 100644 --- a/usr.bin/cvs/entries.c +++ b/usr.bin/cvs/entries.c @@ -1,4 +1,4 @@ -/* $OpenBSD: entries.c,v 1.9 2004/08/03 14:48:02 jfb Exp $ */ +/* $OpenBSD: entries.c,v 1.10 2004/08/04 15:39:10 jfb Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -37,7 +37,7 @@ #include "cvs.h" -#define CVS_ENTRIES_NFIELDS 5 +#define CVS_ENTRIES_NFIELDS 6 #define CVS_ENTRIES_DELIM '/' @@ -308,19 +308,41 @@ struct cvs_ent* cvs_ent_parse(const char *entry) { int i; - char *fields[CVS_ENTRIES_NFIELDS], *sp, *dp; + char *fields[CVS_ENTRIES_NFIELDS], *buf, *sp, *dp; struct cvs_ent *entp; + buf = strdup(entry); + if (buf == NULL) { + cvs_log(LP_ERRNO, "failed to allocate entry copy"); + return (NULL); + } + + sp = buf; + i = 0; + do { + dp = strchr(sp, CVS_ENTRIES_DELIM); + if (dp != NULL) + *(dp++) = '\0'; + fields[i++] = sp; + sp = dp; + } while ((dp != NULL) && (i < CVS_ENTRIES_NFIELDS)); + + if (i < CVS_ENTRIES_NFIELDS) { + cvs_log(LP_ERR, "missing fields in entry line `%s'", entry); + return (NULL); + } + entp = (struct cvs_ent *)malloc(sizeof(*entp)); if (entp == NULL) { cvs_log(LP_ERRNO, "failed to allocate CVS entry"); return (NULL); } memset(entp, 0, sizeof(*entp)); + entp->ce_buf = buf; entp->ce_rev = rcsnum_alloc(); if (entp->ce_rev == NULL) { - free(entp); + cvs_ent_free(entp); return (NULL); } @@ -330,42 +352,20 @@ cvs_ent_parse(const char *entry) return (NULL); } - entp->ce_buf = strdup(entry); - if (entp->ce_buf == NULL) { - cvs_ent_free(entp); - return (NULL); - } - sp = entp->ce_buf; - - if (*sp == CVS_ENTRIES_DELIM) + if (*fields[0] == '\0') entp->ce_type = CVS_ENT_FILE; - else if (*sp == 'D') { + else if (*fields[0] == 'D') entp->ce_type = CVS_ENT_DIR; - sp++; - } - else { - /* unknown entry, ignore for future expansion */ + else entp->ce_type = CVS_ENT_NONE; - sp++; - } - - sp++; - i = 0; - do { - dp = strchr(sp, CVS_ENTRIES_DELIM); - if (dp != NULL) - *(dp++) = '\0'; - fields[i++] = sp; - sp = dp; - } while ((dp != NULL) && (i < CVS_ENTRIES_NFIELDS)); - entp->ce_name = fields[0]; + entp->ce_name = fields[1]; if (entp->ce_type == CVS_ENT_FILE) { - rcsnum_aton(fields[1], NULL, entp->ce_rev); - entp->ce_timestamp = fields[2]; - entp->ce_opts = fields[3]; - entp->ce_tag = fields[4]; + rcsnum_aton(fields[2], NULL, entp->ce_rev); + entp->ce_timestamp = fields[3]; + entp->ce_opts = fields[4]; + entp->ce_tag = fields[5]; } return (entp); |