diff options
author | Niall O'Higgins <niallo@cvs.openbsd.org> | 2005-11-12 21:34:49 +0000 |
---|---|---|
committer | Niall O'Higgins <niallo@cvs.openbsd.org> | 2005-11-12 21:34:49 +0000 |
commit | 13b0631dc99e0e78b876bf22b11c3bc7b14a2fc9 (patch) | |
tree | b9a65448b950a4c4b35c104a7aec4b3b5b4c1f7a /usr.bin/cvs | |
parent | b8d774983f09c3432bb10b1647c44644d9f8e9b9 (diff) |
- remove strtab stuff. serves no useful purpose.
diff is from joris@, committing on his behalf because his net connection
is very dodgy right now.
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r-- | usr.bin/cvs/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/cvs/cvs.c | 7 | ||||
-rw-r--r-- | usr.bin/cvs/file.c | 19 | ||||
-rw-r--r-- | usr.bin/cvs/file.h | 6 | ||||
-rw-r--r-- | usr.bin/cvs/rcs.c | 103 | ||||
-rw-r--r-- | usr.bin/cvs/strtab.c | 233 | ||||
-rw-r--r-- | usr.bin/cvs/strtab.h | 40 |
7 files changed, 66 insertions, 346 deletions
diff --git a/usr.bin/cvs/Makefile b/usr.bin/cvs/Makefile index de71a507b8b..a64c7f3349a 100644 --- a/usr.bin/cvs/Makefile +++ b/usr.bin/cvs/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.15 2005/10/22 17:34:47 joris Exp $ +# $OpenBSD: Makefile,v 1.16 2005/11/12 21:34:48 niallo Exp $ PROG= cvs MAN= cvs.1 cvsignore.5 cvsrc.5 cvswrappers.5 cvsintro.7 @@ -7,7 +7,7 @@ CPPFLAGS+=-I${.CURDIR} SRCS= cvs.c add.c admin.c annotate.c buf.c checkout.c cmd.c commit.c date.y \ diff.c diff3.c edit.c entries.c file.c getlog.c history.c hist.c \ import.c init.c log.c logmsg.c proto.c rcs.c rcsnum.c release.c \ - remove.c req.c resp.c root.c server.c status.c strtab.c tag.c \ + remove.c req.c resp.c root.c server.c status.c tag.c \ update.c util.c version.c watch.c CFLAGS= -g -ggdb diff --git a/usr.bin/cvs/cvs.c b/usr.bin/cvs/cvs.c index 351db3962e5..7bf9cf7887b 100644 --- a/usr.bin/cvs/cvs.c +++ b/usr.bin/cvs/cvs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.c,v 1.85 2005/10/07 21:47:32 reyk Exp $ */ +/* $OpenBSD: cvs.c,v 1.86 2005/11/12 21:34:48 niallo Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -41,7 +41,6 @@ #include "cvs.h" #include "log.h" #include "file.h" -#include "strtab.h" extern char *__progname; @@ -115,8 +114,6 @@ main(int argc, char **argv) (void)cvs_log_filter(LP_FILTER_UNSET, LP_DEBUG); #endif - cvs_strtab_init(); - /* check environment so command-line options override it */ if ((envstr = getenv("CVS_RSH")) != NULL) cvs_rsh = envstr; @@ -259,8 +256,6 @@ main(int argc, char **argv) if (cvs_msg != NULL) free(cvs_msg); - cvs_strtab_cleanup(); - return (ret); } diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c index 66230cdd39f..709a399b172 100644 --- a/usr.bin/cvs/file.c +++ b/usr.bin/cvs/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.126 2005/10/27 00:24:24 joris Exp $ */ +/* $OpenBSD: file.c,v 1.127 2005/11/12 21:34:48 niallo Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -42,7 +42,6 @@ #include "cvs.h" #include "file.h" #include "log.h" -#include "strtab.h" #define CVS_IGN_STATIC 0x01 /* pattern is static, no need to glob */ @@ -1031,10 +1030,10 @@ cvs_file_free(CVSFILE *cf) CVSFILE *child; if (cf->cf_name != NULL) - cvs_strfree(cf->cf_name); + free(cf->cf_name); if (cf->cf_dir != NULL) - cvs_strfree(cf->cf_dir); + free(cf->cf_dir); if (cf->cf_type == DT_DIR) { if (cf->cf_root != NULL) @@ -1048,9 +1047,9 @@ cvs_file_free(CVSFILE *cf) } } else { if (cf->cf_tag != NULL) - cvs_strfree(cf->cf_tag); + free(cf->cf_tag); if (cf->cf_opts != NULL) - cvs_strfree(cf->cf_opts); + free(cf->cf_opts); } free(cf); @@ -1162,7 +1161,7 @@ cvs_file_alloc(const char *path, u_int type) SIMPLEQ_INIT(&(cfp->cf_files)); } - cfp->cf_name = cvs_strdup(basename(path)); + cfp->cf_name = strdup(basename(path)); if (cfp->cf_name == NULL) { cvs_log(LP_ERR, "failed to copy file name"); cvs_file_free(cfp); @@ -1172,7 +1171,7 @@ cvs_file_alloc(const char *path, u_int type) if ((p = strrchr(path, '/')) != NULL) { *p = '\0'; if (strcmp(path, ".")) { - cfp->cf_dir = cvs_strdup(path); + cfp->cf_dir = strdup(path); if (cfp->cf_dir == NULL) { cvs_log(LP_ERR, "failed to copy directory"); @@ -1277,7 +1276,7 @@ cvs_file_lget(const char *path, int flags, CVSFILE *parent, CVSENTRIES *pent, if (ent->ce_type == CVS_ENT_FILE) { if (ent->ce_tag[0] != '\0') { - cfp->cf_tag = cvs_strdup(ent->ce_tag); + cfp->cf_tag = strdup(ent->ce_tag); if (cfp->cf_tag == NULL) { cvs_file_free(cfp); return (NULL); @@ -1285,7 +1284,7 @@ cvs_file_lget(const char *path, int flags, CVSFILE *parent, CVSENTRIES *pent, } if (ent->ce_opts[0] != '\0') { - cfp->cf_opts = cvs_strdup(ent->ce_opts); + cfp->cf_opts = strdup(ent->ce_opts); if (cfp->cf_opts == NULL) { cvs_file_free(cfp); return (NULL); diff --git a/usr.bin/cvs/file.h b/usr.bin/cvs/file.h index 5926514dc46..ee2fa5a73b6 100644 --- a/usr.bin/cvs/file.h +++ b/usr.bin/cvs/file.h @@ -1,4 +1,4 @@ -/* $OpenBSD: file.h,v 1.28 2005/08/17 16:23:19 joris Exp $ */ +/* $OpenBSD: file.h,v 1.29 2005/11/12 21:34:48 niallo Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -81,8 +81,8 @@ typedef struct cvs_file { * cf_dir contains the parent directory the file or dir is in. * if cf_dir is NULL the file is in the parent directory. */ - const char *cf_name; - const char *cf_dir; + char *cf_name; + char *cf_dir; /* pointer to the parent directory's entry file */ void *cf_entry; diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c index f506a7723c5..d0c7a0d80d4 100644 --- a/usr.bin/cvs/rcs.c +++ b/usr.bin/cvs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.98 2005/11/09 15:42:58 xsa Exp $ */ +/* $OpenBSD: rcs.c,v 1.99 2005/11/12 21:34:48 niallo Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -42,7 +42,6 @@ #include "log.h" #include "rcs.h" #include "diff.h" -#include "strtab.h" #define RCS_BUFSIZE 16384 #define RCS_BUFEXTSIZE 8192 @@ -391,7 +390,7 @@ rcs_close(RCSFILE *rfp) while (!TAILQ_EMPTY(&(rfp->rf_access))) { rap = TAILQ_FIRST(&(rfp->rf_access)); TAILQ_REMOVE(&(rfp->rf_access), rap, ra_list); - cvs_strfree(rap->ra_name); + free(rap->ra_name); free(rap); } @@ -399,7 +398,7 @@ rcs_close(RCSFILE *rfp) rsp = TAILQ_FIRST(&(rfp->rf_symbols)); TAILQ_REMOVE(&(rfp->rf_symbols), rsp, rs_list); rcsnum_free(rsp->rs_num); - cvs_strfree(rsp->rs_name); + free(rsp->rs_name); free(rsp); } @@ -407,7 +406,7 @@ rcs_close(RCSFILE *rfp) rlp = TAILQ_FIRST(&(rfp->rf_locks)); TAILQ_REMOVE(&(rfp->rf_locks), rlp, rl_list); rcsnum_free(rlp->rl_num); - cvs_strfree(rlp->rl_name); + free(rlp->rl_name); free(rlp); } @@ -419,11 +418,11 @@ rcs_close(RCSFILE *rfp) if (rfp->rf_path != NULL) free(rfp->rf_path); if (rfp->rf_comment != NULL) - cvs_strfree(rfp->rf_comment); + free(rfp->rf_comment); if (rfp->rf_expand != NULL) - cvs_strfree(rfp->rf_expand); + free(rfp->rf_expand); if (rfp->rf_desc != NULL) - cvs_strfree(rfp->rf_desc); + free(rfp->rf_desc); free(rfp); } @@ -734,7 +733,7 @@ rcs_access_add(RCSFILE *file, const char *login) return (-1); } - ap->ra_name = cvs_strdup(login); + ap->ra_name = strdup(login); if (ap->ra_name == NULL) { cvs_log(LP_ERRNO, "failed to duplicate user name"); free(ap); @@ -770,7 +769,7 @@ rcs_access_remove(RCSFILE *file, const char *login) } TAILQ_REMOVE(&(file->rf_access), ap, ra_list); - cvs_strfree(ap->ra_name); + free(ap->ra_name); free(ap); /* not synced anymore */ @@ -809,7 +808,7 @@ rcs_sym_add(RCSFILE *rfp, const char *sym, RCSNUM *snum) return (-1); } - if ((symp->rs_name = cvs_strdup(sym)) == NULL) { + if ((symp->rs_name = strdup(sym)) == NULL) { rcs_errno = RCS_ERR_ERRNO; cvs_log(LP_ERRNO, "failed to duplicate symbol"); free(symp); @@ -817,7 +816,7 @@ rcs_sym_add(RCSFILE *rfp, const char *sym, RCSNUM *snum) } if ((symp->rs_num = rcsnum_alloc()) == NULL) { - cvs_strfree(symp->rs_name); + free(symp->rs_name); free(symp); return (-1); } @@ -858,7 +857,7 @@ rcs_sym_remove(RCSFILE *file, const char *sym) } TAILQ_REMOVE(&(file->rf_symbols), symp, rs_list); - cvs_strfree(symp->rs_name); + free(symp->rs_name); rcsnum_free(symp->rs_num); free(symp); @@ -990,7 +989,7 @@ rcs_lock_add(RCSFILE *file, const char *user, RCSNUM *rev) return (-1); } - lkp->rl_name = cvs_strdup(user); + lkp->rl_name = strdup(user); if (lkp->rl_name == NULL) { cvs_log(LP_ERRNO, "failed to duplicate user name"); free(lkp); @@ -998,7 +997,7 @@ rcs_lock_add(RCSFILE *file, const char *user, RCSNUM *rev) } if ((lkp->rl_num = rcsnum_alloc()) == NULL) { - cvs_strfree(lkp->rl_name); + free(lkp->rl_name); free(lkp); return (-1); } @@ -1036,7 +1035,7 @@ rcs_lock_remove(RCSFILE *file, const RCSNUM *rev) TAILQ_REMOVE(&(file->rf_locks), lkp, rl_list); rcsnum_free(lkp->rl_num); - cvs_strfree(lkp->rl_name); + free(lkp->rl_name); free(lkp); /* not synced anymore */ @@ -1066,11 +1065,11 @@ rcs_desc_set(RCSFILE *file, const char *desc) { char *tmp; - if ((tmp = cvs_strdup(desc)) == NULL) + if ((tmp = strdup(desc)) == NULL) return (-1); if (file->rf_desc != NULL) - cvs_strfree(file->rf_desc); + free(file->rf_desc); file->rf_desc = tmp; file->rf_flags &= ~RCS_SYNCED; @@ -1123,11 +1122,11 @@ rcs_comment_set(RCSFILE *file, const char *comment) { char *tmp; - if ((tmp = cvs_strdup(comment)) == NULL) + if ((tmp = strdup(comment)) == NULL) return (-1); if (file->rf_comment != NULL) - cvs_strfree(file->rf_comment); + free(file->rf_comment); file->rf_comment = tmp; file->rf_flags &= ~RCS_SYNCED; @@ -1433,19 +1432,19 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date, if (username == NULL) username = pw->pw_name; - if ((rdp->rd_author = cvs_strdup(username)) == NULL) { + if ((rdp->rd_author = strdup(username)) == NULL) { rcs_freedelta(rdp); rcsnum_free(old); return (-1); } - if ((rdp->rd_state = cvs_strdup(RCS_STATE_EXP)) == NULL) { + if ((rdp->rd_state = strdup(RCS_STATE_EXP)) == NULL) { rcs_freedelta(rdp); rcsnum_free(old); return (-1); } - if ((rdp->rd_log = cvs_strdup(msg)) == NULL) { + if ((rdp->rd_log = strdup(msg)) == NULL) { rcs_errno = RCS_ERR_ERRNO; rcs_freedelta(rdp); rcsnum_free(old); @@ -1562,14 +1561,14 @@ rcs_kwexp_set(RCSFILE *file, int mode) buf[i++] = 'l'; } - if ((tmp = cvs_strdup(buf)) == NULL) { + if ((tmp = strdup(buf)) == NULL) { cvs_log(LP_ERRNO, "%s: failed to copy expansion mode", file->rf_path); return (-1); } if (file->rf_expand != NULL) - cvs_strfree(file->rf_expand); + free(file->rf_expand); file->rf_expand = tmp; /* not synced anymore */ file->rf_flags &= ~RCS_SYNCED; @@ -1738,7 +1737,7 @@ rcs_parse(RCSFILE *rfp) return (-1); } - rfp->rf_desc = cvs_strdup(RCS_TOKSTR(rfp)); + rfp->rf_desc = strdup(RCS_TOKSTR(rfp)); if (rfp->rf_desc == NULL) { cvs_log(LP_ERRNO, "failed to duplicate rcs token"); rcs_freepdata(pdp); @@ -1840,14 +1839,14 @@ rcs_parse_admin(RCSFILE *rfp) rfp->rf_branch) < 0) return (-1); } else if (tok == RCS_TOK_COMMENT) { - rfp->rf_comment = cvs_strdup(RCS_TOKSTR(rfp)); + rfp->rf_comment = strdup(RCS_TOKSTR(rfp)); if (rfp->rf_comment == NULL) { cvs_log(LP_ERRNO, "failed to duplicate rcs token"); return (-1); } } else if (tok == RCS_TOK_EXPAND) { - rfp->rf_expand = cvs_strdup(RCS_TOKSTR(rfp)); + rfp->rf_expand = strdup(RCS_TOKSTR(rfp)); if (rfp->rf_expand == NULL) { cvs_log(LP_ERRNO, "failed to duplicate rcs token"); @@ -1998,8 +1997,8 @@ rcs_parse_delta(RCSFILE *rfp) } if (tokstr != NULL) - cvs_strfree(tokstr); - tokstr = cvs_strdup(RCS_TOKSTR(rfp)); + free(tokstr); + tokstr = strdup(RCS_TOKSTR(rfp)); if (tokstr == NULL) { cvs_log(LP_ERRNO, "failed to duplicate rcs token"); @@ -2014,14 +2013,14 @@ rcs_parse_delta(RCSFILE *rfp) cvs_log(LP_ERR, "missing semi-colon after RCS `%s' key", rk->rk_str); - cvs_strfree(tokstr); + free(tokstr); rcs_freedelta(rdp); return (-1); } if (tok == RCS_TOK_DATE) { if ((datenum = rcsnum_parse(tokstr)) == NULL) { - cvs_strfree(tokstr); + free(tokstr); rcs_freedelta(rdp); return (-1); } @@ -2032,7 +2031,7 @@ rcs_parse_delta(RCSFILE *rfp) "fields", (datenum->rn_len > 6) ? "too many" : "missing"); - cvs_strfree(tokstr); + free(tokstr); rcs_freedelta(rdp); rcsnum_free(datenum); return (-1); @@ -2073,7 +2072,7 @@ rcs_parse_delta(RCSFILE *rfp) } if (tokstr != NULL) - cvs_strfree(tokstr); + free(tokstr); TAILQ_INSERT_TAIL(&(rfp->rf_delta), rdp, rd_list); rfp->rf_ndelta++; @@ -2140,7 +2139,7 @@ rcs_parse_deltatext(RCSFILE *rfp) RCS_TOKSTR(rfp)); return (-1); } - rdp->rd_log = cvs_strdup(RCS_TOKSTR(rfp)); + rdp->rd_log = strdup(RCS_TOKSTR(rfp)); if (rdp->rd_log == NULL) { cvs_log(LP_ERRNO, "failed to copy RCS deltatext log"); return (-1); @@ -2229,7 +2228,7 @@ rcs_parse_symbols(RCSFILE *rfp) cvs_log(LP_ERRNO, "failed to allocate RCS symbol"); return (-1); } - symp->rs_name = cvs_strdup(RCS_TOKSTR(rfp)); + symp->rs_name = strdup(RCS_TOKSTR(rfp)); if (symp->rs_name == NULL) { cvs_log(LP_ERRNO, "failed to duplicate rcs token"); free(symp); @@ -2239,7 +2238,7 @@ rcs_parse_symbols(RCSFILE *rfp) symp->rs_num = rcsnum_alloc(); if (symp->rs_num == NULL) { cvs_log(LP_ERRNO, "failed to allocate rcsnum info"); - cvs_strfree(symp->rs_name); + free(symp->rs_name); free(symp); return (-1); } @@ -2250,7 +2249,7 @@ rcs_parse_symbols(RCSFILE *rfp) cvs_log(LP_ERR, "unexpected token `%s' in symbol list", RCS_TOKSTR(rfp)); rcsnum_free(symp->rs_num); - cvs_strfree(symp->rs_name); + free(symp->rs_name); free(symp); return (-1); } @@ -2261,7 +2260,7 @@ rcs_parse_symbols(RCSFILE *rfp) cvs_log(LP_ERR, "unexpected token `%s' in symbol list", RCS_TOKSTR(rfp)); rcsnum_free(symp->rs_num); - cvs_strfree(symp->rs_name); + free(symp->rs_name); free(symp); return (-1); } @@ -2270,7 +2269,7 @@ rcs_parse_symbols(RCSFILE *rfp) cvs_log(LP_ERR, "failed to parse RCS NUM `%s'", RCS_TOKSTR(rfp)); rcsnum_free(symp->rs_num); - cvs_strfree(symp->rs_name); + free(symp->rs_name); free(symp); return (-1); } @@ -2311,7 +2310,7 @@ rcs_parse_locks(RCSFILE *rfp) return (-1); } - if ((lkp->rl_name = cvs_strdup(RCS_TOKSTR(rfp))) == NULL) { + if ((lkp->rl_name = strdup(RCS_TOKSTR(rfp))) == NULL) { cvs_log(LP_ERR, "failed to save locking user"); free(lkp); return (-1); @@ -2319,7 +2318,7 @@ rcs_parse_locks(RCSFILE *rfp) lkp->rl_num = rcsnum_alloc(); if (lkp->rl_num == NULL) { - cvs_strfree(lkp->rl_name); + free(lkp->rl_name); free(lkp); return (-1); } @@ -2330,7 +2329,7 @@ rcs_parse_locks(RCSFILE *rfp) cvs_log(LP_ERR, "unexpected token `%s' in symbol list", RCS_TOKSTR(rfp)); rcsnum_free(lkp->rl_num); - cvs_strfree(lkp->rl_name); + free(lkp->rl_name); free(lkp); return (-1); } @@ -2341,7 +2340,7 @@ rcs_parse_locks(RCSFILE *rfp) cvs_log(LP_ERR, "unexpected token `%s' in symbol list", RCS_TOKSTR(rfp)); rcsnum_free(lkp->rl_num); - cvs_strfree(lkp->rl_name); + free(lkp->rl_name); free(lkp); return (-1); } @@ -2350,7 +2349,7 @@ rcs_parse_locks(RCSFILE *rfp) cvs_log(LP_ERR, "failed to parse RCS NUM `%s'", RCS_TOKSTR(rfp)); rcsnum_free(lkp->rl_num); - cvs_strfree(lkp->rl_name); + free(lkp->rl_name); free(lkp); return (-1); } @@ -2437,11 +2436,11 @@ rcs_freedelta(struct rcs_delta *rdp) rcsnum_free(rdp->rd_next); if (rdp->rd_author != NULL) - cvs_strfree(rdp->rd_author); + free(rdp->rd_author); if (rdp->rd_state != NULL) - cvs_strfree(rdp->rd_state); + free(rdp->rd_state); if (rdp->rd_log != NULL) - cvs_strfree(rdp->rd_log); + free(rdp->rd_log); if (rdp->rd_text != NULL) free(rdp->rd_text); @@ -2883,9 +2882,9 @@ rcs_rev_setlog(RCSFILE *rfp, RCSNUM *rev, const char *logtext) return (-1); if (rdp->rd_log != NULL) - cvs_strfree(rdp->rd_log); + free(rdp->rd_log); - if ((rdp->rd_log = cvs_strdup(logtext)) == NULL) + if ((rdp->rd_log = strdup(logtext)) == NULL) return (-1); rfp->rf_flags &= ~RCS_SYNCED; @@ -2925,9 +2924,9 @@ rcs_state_set(RCSFILE *rfp, RCSNUM *rev, const char *state) return (-1); if (rdp->rd_state != NULL) - cvs_strfree(rdp->rd_state); + free(rdp->rd_state); - if ((rdp->rd_state = cvs_strdup(state)) == NULL) + if ((rdp->rd_state = strdup(state)) == NULL) return (-1); rfp->rf_flags &= ~RCS_SYNCED; diff --git a/usr.bin/cvs/strtab.c b/usr.bin/cvs/strtab.c deleted file mode 100644 index e20730a0ee0..00000000000 --- a/usr.bin/cvs/strtab.c +++ /dev/null @@ -1,233 +0,0 @@ -/* $OpenBSD: strtab.c,v 1.7 2005/07/29 17:04:42 xsa Exp $ */ -/* - * Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/* - * The hash table code uses the 32-bit Fowler/Noll/Vo (FNV-1) hash algorithm - * for indexing. - * http://www.isthe.com/chongo/tech/comp/fnv/ - */ - -#include <sys/types.h> -#include <sys/queue.h> - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "cvs.h" -#include "log.h" -#include "strtab.h" - -#define CVS_STRTAB_HASHBITS 8 -#define CVS_STRTAB_NBUCKETS (1 << CVS_STRTAB_HASHBITS) -#define CVS_STRTAB_FNVPRIME 0x01000193 -#define CVS_STRTAB_FNVINIT 0x811c9dc5 - -struct cvs_str { - char *cs_str; - int cs_ref; - SLIST_ENTRY(cvs_str) cs_link; -}; - -SLIST_HEAD(cvs_slist, cvs_str); - -static struct cvs_slist cvs_strtab[CVS_STRTAB_NBUCKETS]; - - -static struct cvs_str *cvs_strtab_insert(const char *); -static struct cvs_str *cvs_strtab_lookup(const char *); -static u_int32_t cvs_strtab_hash(const char *); -static void cvs_strtab_free(const char *); - - - -/* - * cvs_strdup() - * - * Simple interface to the string table. - */ -char * -cvs_strdup(const char *s) -{ - struct cvs_str *csp; - - if ((csp = cvs_strtab_lookup(s)) == NULL) { - if ((csp = cvs_strtab_insert(s)) == NULL) - return (NULL); - } else { - csp->cs_ref++; - } - - return (csp->cs_str); -} - -/* - * cvs_strfree() - */ -void -cvs_strfree(const char *s) -{ - cvs_strtab_free(s); -} - -/* - * - */ -void -cvs_strtab_init(void) -{ - int i; - - for (i = 0; i < CVS_STRTAB_NBUCKETS; i++) - SLIST_INIT(&cvs_strtab[i]); -} - -/* - * cvs_strtab_cleanup() - * - */ -void -cvs_strtab_cleanup(void) -{ - int i, unfreed; - struct cvs_str *sp; - - unfreed = 0; - for (i = 0; i < CVS_STRTAB_NBUCKETS; i++) { - SLIST_FOREACH(sp, &cvs_strtab[i], cs_link) { - cvs_log(LP_DEBUG, "string '%s' not freed", sp->cs_str); - unfreed++; - } - } - - if (unfreed > 0) - cvs_log(LP_WARN, "%d unfreed string references in string table", - unfreed); -} - -/* - * cvs_strtab_insert() - * - * Insert the string <str> in the string table. - */ -static struct cvs_str * -cvs_strtab_insert(const char *str) -{ - u_int32_t h; - struct cvs_str *sp; - - if ((sp = (struct cvs_str *)malloc(sizeof(*sp))) == NULL) { - cvs_log(LP_ERRNO, "failed to insert string `%s'", str); - return (NULL); - } - - if ((sp->cs_str = strdup(str)) == NULL) { - free(sp); - return (NULL); - } - - h = cvs_strtab_hash(str); - - SLIST_INSERT_HEAD(&cvs_strtab[h], sp, cs_link); - - sp->cs_ref = 1; - return (sp); -} - -/* - * cvs_strtab_hash() - * - * Generate a hash value from the string <str>. - * The resulting hash value is bitwise AND'ed with the appropriate mask so - * the returned index does not go out of the boundaries of the hash table. - */ -static u_int32_t -cvs_strtab_hash(const char *str) -{ - const char *np; - u_int32_t h; - - h = CVS_STRTAB_FNVINIT; - for (np = str; *np != '\0'; np++) { - h *= CVS_STRTAB_FNVPRIME; - h ^= (u_int32_t)*np; - } - - return (h & (CVS_STRTAB_NBUCKETS - 1)); -} - -/* - * cvs_strtab_lookup() - * - * Lookup the string <str> in the string table. If the corresponding entry - * is found, a pointer to the string is returned and the entry's reference - * count is increased. - */ -static struct cvs_str * -cvs_strtab_lookup(const char *str) -{ - u_int32_t h; - struct cvs_str *sp; - - h = cvs_strtab_hash(str); - - SLIST_FOREACH(sp, &(cvs_strtab[h]), cs_link) - if (strcmp(str, sp->cs_str) == 0) { - break; - } - - return (sp); -} - -/* - * cvs_strtab_free() - * - * Release a reference to the string <str>. If the reference count reaches 0, - * the string is removed from the table and freed. - */ -static void -cvs_strtab_free(const char *str) -{ - u_int32_t h; - struct cvs_str *sp; - - if ((sp = cvs_strtab_lookup(str)) == NULL) { - cvs_log(LP_WARN, "attempt to free unregistered string `%s'", - str); - return; - } - - sp->cs_ref--; - if (sp->cs_ref == 0) { - /* no more references, free the file */ - h = cvs_strtab_hash(sp->cs_str); - - SLIST_REMOVE(&(cvs_strtab[h]), sp, cvs_str, cs_link); - free(sp->cs_str); - free(sp); - } -} diff --git a/usr.bin/cvs/strtab.h b/usr.bin/cvs/strtab.h deleted file mode 100644 index c726c3bcabf..00000000000 --- a/usr.bin/cvs/strtab.h +++ /dev/null @@ -1,40 +0,0 @@ -/* $OpenBSD: strtab.h,v 1.3 2005/07/25 11:32:20 xsa Exp $ */ -/* - * Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef STRTAB_H -#define STRTAB_H - -#define CVS_STRTAB_HASHBITS 8 -#define CVS_STRTAB_NBUCKETS (1 << CVS_STRTAB_HASHBITS) -#define CVS_STRTAB_FNVPRIME 0x01000193 -#define CVS_STRTAB_FNVINIT 0x811c9dc5 - -void cvs_strtab_init(void); -void cvs_strtab_cleanup(void); -char *cvs_strdup(const char *); -void cvs_strfree(const char *); - -#endif /* STRTAB_H */ |