/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1998-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* determine fixed record size by sampling data
*/
#include "pzlib.h"
typedef struct
{
} Fixed_t;
/*
* determine fixed record size by sampling data
* if buf!=0 then <buf,z> is used
* otherwise data is peeked from io
* return:
* >0 best guess from sample
* 0 could not determine
* <0 error
*/
{
register unsigned char* s;
register unsigned int* cp;
register unsigned int i;
unsigned char* t;
unsigned int j;
unsigned int k;
unsigned int n;
unsigned int m;
unsigned int max;
unsigned long f;
unsigned long g;
if (buf)
s = (unsigned char*)buf;
return -1;
else
if (trace)
/*
* first check for newline terminated
*/
{
n = 0;
else
for (i = n - 1; i < z; i += n)
if (s[i] != '\n')
{
n = 0;
break;
}
if (n && trace)
}
else
n = 0;
{
if (trace)
max = 0;
for (i = 0; i < z; i++)
{
m = i - *cp;
*cp = i;
{
if (m > max)
max = m;
}
}
n = 0;
m = 0;
f = ~0;
for (i = max; i > 1; i--)
{
{
m++;
g = 0;
for (j = i; j < z - i; j += i)
for (k = 0; k < i; k++)
if (s[j + k] != s[j + k - i])
g++;
if (trace)
(*trace)(pz, pz->disc, -2, "pzfixed: %5d %8d %8ld %8ld%s", i, xp->rep[i], f, g, (g <= f) ? " *" : "");
if (g <= f)
{
f = g;
n = i;
}
}
}
n = siz;
}
/*
* release the peek data
*/
if (!buf)
return n;
}