1f08c3bdfSopenharmony_ci/*
2f08c3bdfSopenharmony_ci * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3f08c3bdfSopenharmony_ci *
4f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify it
5f08c3bdfSopenharmony_ci * under the terms of version 2 of the GNU General Public License as
6f08c3bdfSopenharmony_ci * published by the Free Software Foundation.
7f08c3bdfSopenharmony_ci *
8f08c3bdfSopenharmony_ci * This program is distributed in the hope that it would be useful, but
9f08c3bdfSopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
10f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11f08c3bdfSopenharmony_ci *
12f08c3bdfSopenharmony_ci * Further, this software is distributed without any warranty that it is
13f08c3bdfSopenharmony_ci * free of the rightful claim of any third person regarding infringement
14f08c3bdfSopenharmony_ci * or the like.  Any license provided herein, whether implied or
15f08c3bdfSopenharmony_ci * otherwise, applies only to this software file.  Patent licenses, if
16f08c3bdfSopenharmony_ci * any, provided herein do not apply to combinations of this program with
17f08c3bdfSopenharmony_ci * other software, or any other product whatsoever.
18f08c3bdfSopenharmony_ci *
19f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License along
20f08c3bdfSopenharmony_ci * with this program; if not, write the Free Software Foundation, Inc.,
21f08c3bdfSopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22f08c3bdfSopenharmony_ci *
23f08c3bdfSopenharmony_ci * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24f08c3bdfSopenharmony_ci * Mountain View, CA  94043, or:
25f08c3bdfSopenharmony_ci *
26f08c3bdfSopenharmony_ci * http://www.sgi.com
27f08c3bdfSopenharmony_ci *
28f08c3bdfSopenharmony_ci * For further information regarding this notice, see:
29f08c3bdfSopenharmony_ci *
30f08c3bdfSopenharmony_ci * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31f08c3bdfSopenharmony_ci */
32f08c3bdfSopenharmony_ci#ifndef _PATTERN_H_
33f08c3bdfSopenharmony_ci#define _PATTERN_H_
34f08c3bdfSopenharmony_ci
35f08c3bdfSopenharmony_ci/*
36f08c3bdfSopenharmony_ci * pattern_check(buf, buflen, pat, patlen, patshift)
37f08c3bdfSopenharmony_ci *
38f08c3bdfSopenharmony_ci * Check a buffer of length buflen against repeated occurrances of
39f08c3bdfSopenharmony_ci * a pattern whose length is patlen.  Patshift can be used to rotate
40f08c3bdfSopenharmony_ci * the pattern by patshift bytes to the left.
41f08c3bdfSopenharmony_ci *
42f08c3bdfSopenharmony_ci * Patshift may be greater than patlen, the pattern will be rotated by
43f08c3bdfSopenharmony_ci * (patshift % patshift) bytes.
44f08c3bdfSopenharmony_ci *
45f08c3bdfSopenharmony_ci * pattern_check returns -1 if the buffer does not contain repeated
46f08c3bdfSopenharmony_ci * occurrances of the indicated pattern (shifted by patshift).
47f08c3bdfSopenharmony_ci *
48f08c3bdfSopenharmony_ci * The algorithm used to check the buffer relies on the fact that buf is
49f08c3bdfSopenharmony_ci * supposed to be repeated copies of pattern.  The basic algorithm is
50f08c3bdfSopenharmony_ci * to validate the first patlen bytes of buf against the pat argument
51f08c3bdfSopenharmony_ci * passed in - then validate the next patlen bytes against the 1st patlen
52f08c3bdfSopenharmony_ci * bytes - the next (2*patlen) bytes against the 1st (2*pathen) bytes, and
53f08c3bdfSopenharmony_ci * so on.  This algorithm only works when the assumption of a buffer full
54f08c3bdfSopenharmony_ci * of repeated copies of a pattern holds, and gives MUCH better results
55f08c3bdfSopenharmony_ci * then walking the buffer byte by byte.
56f08c3bdfSopenharmony_ci *
57f08c3bdfSopenharmony_ci * Performance wise, It appears to be about 5% slower than doing a straight
58f08c3bdfSopenharmony_ci * memcmp of 2 buffers, but the big win is that it does not require a
59f08c3bdfSopenharmony_ci * 2nd comparison buffer, only the pattern.
60f08c3bdfSopenharmony_ci */
61f08c3bdfSopenharmony_ciint pattern_check( char * , int , char * , int , int );
62f08c3bdfSopenharmony_ci
63f08c3bdfSopenharmony_ci/*
64f08c3bdfSopenharmony_ci * pattern_fill(buf, buflen, pat, patlen, patshift)
65f08c3bdfSopenharmony_ci *
66f08c3bdfSopenharmony_ci * Fill a buffer of length buflen with repeated occurrances of
67f08c3bdfSopenharmony_ci * a pattern whose length is patlen.  Patshift can be used to rotate
68f08c3bdfSopenharmony_ci * the pattern by patshift bytes to the left.
69f08c3bdfSopenharmony_ci *
70f08c3bdfSopenharmony_ci * Patshift may be greater than patlen, the pattern will be rotated by
71f08c3bdfSopenharmony_ci * (patshift % patlen) bytes.
72f08c3bdfSopenharmony_ci *
73f08c3bdfSopenharmony_ci * If buflen is not a multiple of patlen, a partial pattern will be written
74f08c3bdfSopenharmony_ci * in the last part of the buffer.  This implies that a buffer which is
75f08c3bdfSopenharmony_ci * shorter than the pattern length will receive only a partial pattern ...
76f08c3bdfSopenharmony_ci *
77f08c3bdfSopenharmony_ci * pattern_fill always returns 0 - no validation of arguments is done.
78f08c3bdfSopenharmony_ci *
79f08c3bdfSopenharmony_ci * The algorithm used to fill the buffer relies on the fact that buf is
80f08c3bdfSopenharmony_ci * supposed to be repeated copies of pattern.  The basic algorithm is
81f08c3bdfSopenharmony_ci * to fill the first patlen bytes of buf with the pat argument
82f08c3bdfSopenharmony_ci * passed in - then copy the next patlen bytes with the 1st patlen
83f08c3bdfSopenharmony_ci * bytes - the next (2*patlen) bytes with the 1st (2*pathen) bytes, and
84f08c3bdfSopenharmony_ci * so on.  This algorithm only works when the assumption of a buffer full
85f08c3bdfSopenharmony_ci * of repeated copies of a pattern holds, and gives MUCH better results
86f08c3bdfSopenharmony_ci * then filling the buffer 1 byte at a time.
87f08c3bdfSopenharmony_ci */
88f08c3bdfSopenharmony_ciint pattern_fill( char * , int , char * , int , int );
89f08c3bdfSopenharmony_ci
90f08c3bdfSopenharmony_ci#endif
91