]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_hash.c
1 /* $Id: mdoc_hash.c,v 1.26 2015/10/06 18:32:19 schwarze Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
33 static unsigned char table
[27 * 12];
45 memset(table
, UCHAR_MAX
, sizeof(table
));
47 for (i
= 0; i
< (int)MDOC_MAX
; i
++) {
48 p
= mdoc_macronames
[i
];
50 if (isalpha((unsigned char)p
[1]))
51 major
= 12 * (tolower((unsigned char)p
[1]) - 97);
55 for (j
= 0; j
< 12; j
++)
56 if (UCHAR_MAX
== table
[major
+ j
]) {
57 table
[major
+ j
] = (unsigned char)i
;
66 mdoc_hash_find(const char *p
)
72 if ( ! isalpha((unsigned char)p
[0]) && '%' != p
[0])
75 if (isalpha((unsigned char)p
[1]))
76 major
= 12 * (tolower((unsigned char)p
[1]) - 97);
85 for (j
= 0; j
< 12; j
++) {
86 if (UCHAR_MAX
== (i
= table
[major
+ j
]))
88 if (0 == strcmp(p
, mdoc_macronames
[i
]))