]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_hash.c
1 /* $Id: mdoc_hash.c,v 1.27 2016/07/15 18:03:45 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>
32 #include "libmandoc.h"
35 static unsigned char table
[27 * 12];
47 memset(table
, UCHAR_MAX
, sizeof(table
));
49 for (i
= 0; i
< (int)MDOC_MAX
; i
++) {
50 p
= mdoc_macronames
[i
];
52 if (isalpha((unsigned char)p
[1]))
53 major
= 12 * (tolower((unsigned char)p
[1]) - 97);
57 for (j
= 0; j
< 12; j
++)
58 if (UCHAR_MAX
== table
[major
+ j
]) {
59 table
[major
+ j
] = (unsigned char)i
;
68 mdoc_hash_find(const char *p
)
74 if ( ! isalpha((unsigned char)p
[0]) && '%' != p
[0])
77 if (isalpha((unsigned char)p
[1]))
78 major
= 12 * (tolower((unsigned char)p
[1]) - 97);
87 for (j
= 0; j
< 12; j
++) {
88 if (UCHAR_MAX
== (i
= table
[major
+ j
]))
90 if (0 == strcmp(p
, mdoc_macronames
[i
]))