]>
git.cameronkatri.com Git - mandoc.git/blob - hash.c
1 /* $Id: hash.c,v 1.2 2008/12/15 02:23:12 kristaps Exp $ */
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
30 mdoc_hash_free(void *htab
)
40 int i
, major
, minor
, ind
;
43 htab
= calloc(27 * 26, sizeof(struct mdoc_macro
*));
47 for (i
= 1; i
< MDOC_MAX
; i
++) {
48 major
= mdoc_macronames
[i
][0];
49 assert((major
>= 65 && major
<= 90) ||
57 minor
= mdoc_macronames
[i
][1];
58 assert((minor
>= 65 && minor
<= 90) ||
60 (minor
>= 97 && minor
<= 122));
69 assert(major
>= 0 && major
< 27);
70 assert(minor
>= 0 && minor
< 26);
72 ind
= (major
* 27) + minor
;
74 assert(NULL
== htab
[ind
]);
75 htab
[ind
] = &mdoc_macros
[i
];
83 mdoc_hash_find(const void *arg
, const char *tmp
)
85 int major
, minor
, ind
, slot
;
91 if (0 == tmp
[0] || 0 == tmp
[1])
94 if ( ! (tmp
[0] == 37 || (tmp
[0] >= 65 && tmp
[0] <= 90)))
97 if ( ! ((tmp
[1] >= 65 && tmp
[1] <= 90) ||
99 (tmp
[1] >= 97 && tmp
[1] <= 122)))
109 else if (tmp
[1] <= 90)
114 ind
= (major
* 27) + minor
;
116 if (NULL
== htab
[ind
])
119 slot
= htab
[ind
] - /* LINTED */
121 assert(0 == (size_t)slot
% sizeof(struct mdoc_macro
));
122 slot
/= sizeof(struct mdoc_macro
);
124 if (0 != strcmp(mdoc_macronames
[slot
], tmp
))