1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* Phong Vo <kpv@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A
1N/A/*
1N/A * return the length of the current record at b, size n, according to f
1N/A * -1 returned on error
1N/A * 0 returned if more data is required
1N/A */
1N/A
1N/A#include <recfmt.h>
1N/A#include <ctype.h>
1N/A
1N/Assize_t
1N/Areclen(Recfmt_t f, const void* b, size_t n)
1N/A{
1N/A register unsigned char* s = (unsigned char*)b;
1N/A register unsigned char* e;
1N/A size_t h;
1N/A size_t z;
1N/A
1N/A switch (RECTYPE(f))
1N/A {
1N/A case REC_delimited:
1N/A if (e = (unsigned char*)memchr(s, REC_D_DELIMITER(f), n))
1N/A return e - s + 1;
1N/A return 0;
1N/A case REC_fixed:
1N/A return REC_F_SIZE(f);
1N/A case REC_variable:
1N/A h = REC_V_HEADER(f);
1N/A if (n < h)
1N/A return 0;
1N/A z = 0;
1N/A s += REC_V_OFFSET(f);
1N/A e = s + REC_V_LENGTH(f);
1N/A if (REC_V_LITTLE(f))
1N/A while (e > s)
1N/A z = (z<<8)|*--e;
1N/A else
1N/A while (s < e)
1N/A z = (z<<8)|*s++;
1N/A if (!REC_V_INCLUSIVE(f))
1N/A z += h;
1N/A else if (z < h)
1N/A z = h;
1N/A return z;
1N/A case REC_method:
1N/A return -1;
1N/A }
1N/A return -1;
1N/A}