1NAMEALLOC(3)                 MBK UTILITY FUNCTIONS                NAMEALLOC(3)
2
3
4

NAME

6       namealloc - hash table for strings
7

SYNOPSIS

9       #include "mut.h"
10       char ∗namealloc(inputname)
11       char ∗inputname;
12

PARAMETER

14       inputname           Pointer to a string of characters
15

DESCRIPTION

17       The  namealloc  function creates a dictionary of names in mbk.  It war‐
18       ranties equality on characters string if the pointers to these  strings
19       are equal, at strcmp(3) meaning. This means also that there is a single
20       memory address for a given string.
21       The case of the letters do not matter. All names are changed  to  lower
22       case  before  being  introduced  in  the  symbol  table. This is needed
23       because most of the file format do not check case.
24       namealloc is used by all mbk utility function using names, so  its  use
25       should be needed only when directly filling or modifying the structure,
26       or when having to compare an external string to mbk internal ones. This
27       should speed up string comparisons.
28       One  shall never modify the contains of a string pointed to by a result
29       of namealloc, since all the field that points to this name  would  have
30       there  values  modified,  and that there is no chance that the new hash
31       code will be the same as the old one, so pointer  comparison  would  be
32       meaningless.  All  string  used  by namealloc are constants string, and
33       therefore must be left alone.
34

RETURN VALUE

36       namealloc returns a string pointer.  If the inputname is already in the
37       hash  table, then its internal pointer is returned, else a new entry is
38       created, and then the new pointer returned.
39

EXAMPLE

41       #include "mut.h"
42       #include "mlo.h"
43       lofig_list ∗find_fig(name)
44       char ∗name;
45       {
46       lofig_list ∗p;
47          name = namealloc(name);
48          for (p = HEAD_LOFIG; p; p = p->NEXT)
49             if (p->NAME == name) /∗ pointer equality ∗/
50                return p;
51          return NULL;
52       }
53

DIAGNOSTICS

55       namealloc can be used only after a call to mbkenv(3).
56

SEE ALSO

58       mbk(1).
59
60
61
62
63
64
65ASIM/LIP6                       October 1, 1997                   NAMEALLOC(3)
Impressum