/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2011 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
/*
*/
#pragma prototyped
/*
* David Korn
* AT&T Bell Laboratories
*
* library interface for word count
*/
#include <cmd.h>
#include <wc.h>
#include <ctype.h>
#include <wchar.h>
#include <wctype.h>
#include <lc.h>
#else
#ifndef iswspace
#endif
#endif
{
register int n;
register int w;
return 0;
if (!mbwide())
#endif
else
for (n = (1<<CHAR_BIT); --n >= 0;)
{
for (n = 0; n < 64; n++)
{
if (n<32)
else if (n<48)
else if (n<56)
else if (n<60)
else if (n<62)
}
}
return wp;
}
{
error_info.file = 0;
error_info.line = 0;
return nlines;
}
/*
* handle utf space characters
*/
{
switch(state)
{
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
state = 0;
if(c==0xa0 || c==0xa1)
return(10);
else if((c&0xf0)== 0x80)
{
if((c&=0xf)==7)
if(c<=0xb)
return(10);
}
return(10);
break;
case 7:
break;
case 8:
return (iswspace(c)?10:0);
}
return state;
}
/*
* compute the line, word, and character count for file <fd>
*/
{
register unsigned char* cp;
register ssize_t c;
register unsigned char* endbuff;
unsigned int lastchar;
ssize_t n;
ssize_t o;
unsigned char* buff;
wchar_t x;
{
for (;;)
{
{
{
if (buff)
{
if (o)
mbinit();
}
else
o = 0;
{
break;
}
nbytes += n;
if ((c = sizeof(side) - o) > n)
c = n;
if (c)
{
}
else
}
else
{
cp++;
x = -1;
}
}
else
cp += n ? n : 1;
if (x == '\n')
{
nlines++;
lasttype = 1;
}
else if (iswspace(x))
lasttype = 1;
else if (lasttype)
{
lasttype = 0;
nwords++;
}
nchars++;
}
}
else if (!wp->mb && !(wp->mode & WC_LONGEST) || wp->mb > 0 && !(wp->mode & (WC_MBYTE|WC_WORDS|WC_LONGEST)))
{
{
{
nchars += c;
if (*--endbuff == '\n')
nlines++;
else
*endbuff = '\n';
for (;;)
if (*cp++ == '\n')
{
break;
nlines++;
}
}
}
else
{
{
nchars += c;
/* check to see whether first character terminates word */
if (c==1)
{
nlines++;
nwords++;
lasttype = c;
continue;
}
nwords++;
c = lasttype;
/* process each buffer */
for (;;)
{
/* process spaces and new-lines */
do
{
if (eol(c))
for (;;)
{
/* check for end of buffer */
goto beob;
nlines++;
if (*cp != '\n')
break;
cp++;
}
/* skip over word characters */
nwords++;
}
beob:
else
c = lasttype;
/* see if was in word */
if (!c && !lasttype)
nwords--;
}
nlines++;
else if (!lasttype)
nwords++;
}
}
else
{
int lineoff=0;
int skip=0;
int adjust=0;
int state=0;
int oldc;
int xspace;
unsigned char* start;
int flagm = 0;
lastchar = 0;
{
nbytes += c;
nchars += c;
/* check to see whether first character terminates word */
if(c==1)
{
nlines++;
nwords++;
lasttype = c;
continue;
}
cp[c] = '\n';
{
c = lasttype;
flagm = 1;
goto mbyte;
}
nwords++;
c = lasttype;
/* process each buffer */
for (;;)
{
/* process spaces and new-lines */
do
{
if (eol(c))
{
/* check for end of buffer */
goto eob;
{
}
nlines++;
adjust = 0;
}
wasspace=1;
if(mbc(c))
{
do
{
if(c&WC_ERR)
goto err;
if(skip && (c&7))
break;
if(!skip)
{
if(!(c&7))
{
skip=1;
break;
}
skip = (c&7);
state = 0;
if (flagm == 1) {
flagm = 0;
if (xspace && (
(*cp)
== 1)) {
= 8;
}
continue;
}
{
state = 8;
}
}
else
{
skip--;
{
if(state==10)
{
if(!wasspace)
nwords++;
wasspace = 1;
state=0;
goto spaces;
}
}
}
wasspace = 0;
if(skip)
{
goto eob;
err:
skip = 0;
state = 0;
{
goto eob;
}
if(mbc(c))
goto mbyte;
else if(c&WC_SP)
goto spaces;
}
if(spc(c))
{
nwords++;
continue;
}
}
/* skip over word characters */
if(mbc(c))
goto mbyte;
nwords++;
}
eob:
else
c = lasttype;
/* see if was in word */
if(!c && !lasttype)
nwords--;
}
nlines++;
else if (!lasttype)
nwords++;
else
}
return 0;
}