Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.bin / tn3270 / general / genbsubs.c
blob4ce48d983d79c86f1a811b83f45e7964f1dc7b7f
1 /* $NetBSD: genbsubs.c,v 1.5 1998/03/11 16:49:19 thorpej Exp $ */
3 /*-
4 * Copyright (c) 1988 The Regents of the University of California.
5 * All rights reserved.
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 #ifndef lint
34 #if 0
35 static char sccsid[] = "@(#)genbsubs.c 4.2 (Berkeley) 4/26/91";
36 #else
37 __RCSID("$NetBSD: genbsubs.c,v 1.5 1998/03/11 16:49:19 thorpej Exp $");
38 #endif
39 #endif /* not lint */
41 #include "general.h"
43 /* The output of bunequal is the offset of the byte which didn't match;
44 * if all the bytes match, then we return n.
45 * bunequal(s1, s2, n) */
47 int
48 bunequal(s1, s2, n)
49 char *s1, *s2;
50 int n;
52 int i = 0;
54 while (i++ < n) {
55 if (*s1++ != *s2++) {
56 break;
59 return(i-1);
62 /* bskip(s1, n, b) : finds the first occurrence of any byte != 'b' in the 'n'
63 * bytes beginning at 's1'.
66 int
67 bskip(s1, n, b)
68 char *s1;
69 int n;
70 int b;
72 int i = 0;
74 while (i++ < n) {
75 if (*s1++ != b) {
76 break;
79 return(i-1);
83 * memNSchr(const void *s, int c, size_t n, int and)
85 * Like memchr, but the comparison is '((*s)&and) == c',
86 * and we increment our way through s by "stride" ('s += stride').
88 * We optimize for the most used strides of +1 and -1.
91 unsigned char *
92 memNSchr(s, c, n, and, stride)
93 char *s;
94 int c;
95 unsigned int n;
96 int and;
97 ssize_t stride;
99 unsigned char _c, *_s, _and;
101 _and = and;
102 _c = (c&_and);
103 _s = (unsigned char *)s;
104 switch (stride) {
105 case 1:
106 while (n--) {
107 if (((*_s)&_and) == _c) {
108 return _s;
110 _s++;
112 break;
113 case -1:
114 while (n--) {
115 if (((*_s)&_and) == _c) {
116 return _s;
118 _s--;
120 break;
121 default:
122 while (n--) {
123 if (((*_s)&_and) == _c) {
124 return _s;
126 _s += stride;
129 return 0;