diff options
Diffstat (limited to 'src/lib/libc/string/bm.3')
| -rw-r--r-- | src/lib/libc/string/bm.3 | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/lib/libc/string/bm.3 b/src/lib/libc/string/bm.3 new file mode 100644 index 0000000000..7138ee4271 --- /dev/null +++ b/src/lib/libc/string/bm.3 | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | .\" Copyright (c) 1994 | ||
| 2 | .\" The Regents of the University of California. All rights reserved. | ||
| 3 | .\" | ||
| 4 | .\" This code is derived from software contributed to Berkeley by | ||
| 5 | .\" Andrew Hume of AT&T Bell Laboratories. | ||
| 6 | .\" | ||
| 7 | .\" Redistribution and use in source and binary forms, with or without | ||
| 8 | .\" modification, are permitted provided that the following conditions | ||
| 9 | .\" are met: | ||
| 10 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 11 | .\" notice, this list of conditions and the following disclaimer. | ||
| 12 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 14 | .\" documentation and/or other materials provided with the distribution. | ||
| 15 | .\" 3. All advertising materials mentioning features or use of this software | ||
| 16 | .\" must display the following acknowledgement: | ||
| 17 | .\" This product includes software developed by the University of | ||
| 18 | .\" California, Berkeley and its contributors. | ||
| 19 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 20 | .\" may be used to endorse or promote products derived from this software | ||
| 21 | .\" without specific prior written permission. | ||
| 22 | .\" | ||
| 23 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 24 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 25 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 26 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 27 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 28 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 29 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 30 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 31 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 33 | .\" SUCH DAMAGE. | ||
| 34 | .\" | ||
| 35 | .\" $OpenBSD: bm.3,v 1.6 2001/06/23 14:42:12 deraadt Exp $ | ||
| 36 | .\" | ||
| 37 | .Dd June 29, 1999 | ||
| 38 | .Dt BM 3 | ||
| 39 | .Os | ||
| 40 | .Sh NAME | ||
| 41 | .Nm bm_comp , | ||
| 42 | .Nm bm_exec , | ||
| 43 | .Nm bm_free | ||
| 44 | .Nd Boyer-Moore string search | ||
| 45 | .Sh SYNOPSIS | ||
| 46 | .Fd #include <sys/types.h> | ||
| 47 | .Fd #include <bm.h> | ||
| 48 | .Ft bm_pat * | ||
| 49 | .Fn bm_comp "u_char *pattern" "size_t patlen" "u_char freq[256]" | ||
| 50 | .Ft u_char * | ||
| 51 | .Fn bm_exec "bm_pat *pdesc" "u_char *text" "size_t len" | ||
| 52 | .Ft void | ||
| 53 | .Fn bm_free "bm_pat *pdesc" | ||
| 54 | .Sh DESCRIPTION | ||
| 55 | These routines implement an efficient mechanism to find an | ||
| 56 | occurrence of a byte string within another byte string. | ||
| 57 | .Pp | ||
| 58 | .Fn bm_comp | ||
| 59 | evaluates | ||
| 60 | .Fa patlen | ||
| 61 | bytes starting at | ||
| 62 | .Fa pattern | ||
| 63 | and returns a pointer to a structure describing them. | ||
| 64 | The bytes referenced by | ||
| 65 | .Fa pattern | ||
| 66 | may be of any value. | ||
| 67 | .Pp | ||
| 68 | The search takes advantage of the frequency distribution of the | ||
| 69 | bytes in the text to be searched. | ||
| 70 | If specified, | ||
| 71 | .Ar freq | ||
| 72 | should be an array of 256 values, | ||
| 73 | with higher values indicating that the corresponding character occurs | ||
| 74 | more frequently. | ||
| 75 | (A less than optimal frequency distribution can only result in less | ||
| 76 | than optimal performance, not incorrect results.) | ||
| 77 | If | ||
| 78 | .Ar freq | ||
| 79 | is | ||
| 80 | .Dv NULL , | ||
| 81 | a system default table is used. | ||
| 82 | .Pp | ||
| 83 | .Fn bm_exec | ||
| 84 | returns a pointer to the leftmost occurrence of the string given to | ||
| 85 | .Fn bm_comp | ||
| 86 | within | ||
| 87 | .Ar text , | ||
| 88 | or | ||
| 89 | .Dv NULL | ||
| 90 | if none occurs. | ||
| 91 | The number of bytes in | ||
| 92 | .Ar text | ||
| 93 | must be specified by | ||
| 94 | .Ar len . | ||
| 95 | .Pp | ||
| 96 | Space allocated for the returned description is discarded | ||
| 97 | by calling | ||
| 98 | .Fn bm_free | ||
| 99 | with the returned description as an argument. | ||
| 100 | .Pp | ||
| 101 | The asymptotic speed of | ||
| 102 | .Fn bm_exec | ||
| 103 | is | ||
| 104 | .Pf O Ns Pq len / patlen . | ||
| 105 | .Sh SEE ALSO | ||
| 106 | .Xr regexp 3 , | ||
| 107 | .Xr strstr 3 | ||
| 108 | .Rs | ||
| 109 | .%R "Fast String Searching" | ||
| 110 | .%A Andrew Hume | ||
| 111 | .%A Daniel Sunday | ||
| 112 | .%J "Software Practice and Experience" | ||
| 113 | .%V Volume 21, 11 (November 1991) | ||
| 114 | .%P 1221-48 | ||
| 115 | .Re | ||
