X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/0ae5e7b3fd62e0251d21f3abbc187f4c7585f85f..ff1e93acf2626d2531a97de3b54bce9b5a37bcb5:/atom.c diff --git a/atom.c b/atom.c index 661c342..b11fb39 100644 --- a/atom.c +++ b/atom.c @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: atom.c,v 1.2 2001/01/21 19:04:51 mdw Exp $ + * $Id$ * * Atom management * * (c) 2000 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the mLib utilities library. * @@ -15,29 +15,18 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * mLib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with mLib; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: atom.c,v $ - * Revision 1.2 2001/01/21 19:04:51 mdw - * Include `crc32.h' for @CRC32@ macro. - * - * Revision 1.1 2001/01/20 11:50:16 mdw - * Implementation of atom tables (for example, as found in X11). - * - */ - /*----- Header files ------------------------------------------------------*/ #include @@ -45,9 +34,9 @@ #include "alloc.h" #include "atom.h" -#include "crc32.h" #include "hash.h" #include "sym.h" +#include "unihash.h" /*----- Static variables --------------------------------------------------*/ @@ -105,10 +94,11 @@ void atom_destroytable(atom_table *t) sym_destroy(&t->t); } -/* --- @atom_intern@ --- * +/* --- @atom_intern@, @atom_nintern@ --- * * * Arguments: @atom_table *t@ = pointer to an atom table * @const char *p@ = pointer to the string to intern + * @size_t n@ = size of the string (for @atom_nintern) * * Returns: A pointer to the atom block for the given symbol string. * @@ -128,6 +118,18 @@ atom *atom_intern(atom_table *t, const char *p) return (a); } +atom *atom_nintern(atom_table *t, const char *p, size_t n) +{ + atom *a; + unsigned f; + + ATOM_RESOLVE(t); + a = sym_find(&t->t, p, n, sizeof(atom), &f); + if (!f) + a->f = 0; + return (a); +} + /* --- @atom_gensym@ --- * * * Arguments: @atom_table *t@ = pointer to a symbol table @@ -151,8 +153,8 @@ atom *atom_gensym(atom_table *t) a = x_alloc(t->t.t.a, sizeof(atom) + sz); a->b.name = (char *)(a + 1); memcpy(a->b.name, buf, sz); - a->b.len = sz; - CRC32(a->b.b.hash, 0, buf, sz); + a->b.len = sz - 1; + a->b.b.hash = UNIHASH(&unihash_global, buf, sz); a->f = ATOMF_GENSYM; a->b.b.next = t->g; t->g = &a->b.b;