.Dd September 5, 1996 .Dt LIBSEARCHSTR 3 .Os NetBSD 1.2BETA .Sh NAME .Nm searchstr_maketbl , .Nm searchstr , .Nd fast block searching .Sh SYNOPSIS .Fd #include .br .Nm cc .Op Ar arguments .Fl lsearchstr .br .Ft void .Fn searchstr_maketbl "unsigned char (*table)[256]" "const unsigned char *string" "unsigned int len" "const unsigned char equiv[256]" .Ft int .Fn searchstr "const unsigned char *string" "unsigned int stringlen" "unsigned char (*table)[256]" "unsigned int tablelen" .Sh DESCRIPTION These functions are an implementation of a very fast algorithm for searching a large block of memory for small block. It can also do mapping of characters to equivalent characters, such as case folding or stripping accents. .Pp .Fn searchstr_maketbl constructs a searching table. The .Fa string and .Fa len arguments describe the small block of memory, the block that is being searched for. (The name .Dq string is perhaps a misnomer, since there is no restriction on content; NUL bytes are not special.) .Fa table points to an array of .Fa len blocks of 256 bytes; .Fn searchstr_maketbl constructs an internal table in this space. .Fa equiv is an "equivalence" vector; all bytes, both in the block of memory being searched and in the supplied block to search for, are effectively passed through this table before being compared. (That is, rather than comparing, say, .Dl mem[i] == str[j] then the comparison is effectively .Dl equiv[mem[i]] == equiv[str[j]] instead.) .Pp .Fn searchstr actually performs the search. .Fa string and .Fa stringlen describe the block of memory to be searched; .Fa table is the table constructed by .Fn searchstr_maketbl , and .Fa tablelen must match the .Fa len argument to the .Fn searchstr_maketbl call that constructed the table. The returned value is an index into .Fa string which matches the first byte of the searched-for string, or \-1 if the search failed. .Sh BUGS Code blindly assumes 8-bit .Do char .Dc Ns s. .Pp Maximum length of the string to be searched for is 255, or maybe 256. .Sh AUTHOR der Mouse, .Aq mouse@rodents.montreal.qc.ca .