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