wclib.c revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2007 AT&T Knowledge Ventures *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Knowledge Ventures *
* *
* 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>
#if _hdr_wchar && _hdr_wctype
#include <wchar.h>
#include <wctype.h>
#else
#ifndef iswspace
#endif
#endif
{
register int n;
register int w;
return(0);
for(n=(1<<CHAR_BIT);--n >=0;)
return(wp);
}
/*
* compute the line, word, and character count for file <fd>
*/
{
register unsigned char *cp;
register ssize_t c;
register unsigned char *endbuff;
register int lasttype = 1;
unsigned int lastchar;
unsigned char *buff;
wchar_t x;
{
longest = 0;
eline = -1;
for (;;)
{
{
if (buff)
break;
}
nchars++;
if (x == -1)
{
{
error_info.file = 0;
error_info.line = 0;
}
}
else if (x == '\n')
{
nlines++;
lasttype = 1;
}
else if (iswspace(x))
lasttype = 1;
else if (lasttype)
{
lasttype = 0;
nwords++;
}
}
}
else
{
for (;;)
{
/* fill next buffer and check for end-of-file */
break;
nchars += c;
/* check to see whether first character terminates word */
if(c==1)
{
nlines++;
nwords++;
lasttype = c;
continue;
}
nwords++;
cp[c] = '\n';
c = lasttype;
/* process each buffer */
for (;;)
{
/* process spaces and new-lines */
do if (endline(c))
{
for (;;)
{
/* check for end of buffer */
goto eob;
nlines++;
if (*cp != '\n')
break;
cp++;
}
/* skip over word characters */
nwords++;
}
eob:
else
c = lasttype;
/* see if was in word */
if(!c && !lasttype)
nwords--;
}
nlines++;
else if(!lasttype)
nwords++;
}
return(0);
}