da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner* Copyright (c) 1992-2010 AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* by AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Glenn Fowler <gsf@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * David Korn
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * AT&T Bell Laboratories
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * count the number of bytes, words, and lines in a file
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner"[-?\n@(#)$Id: wc (AT&T Research) 2009-11-28 $\n]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+NAME?wc - print the number of bytes, words, and lines in files]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+DESCRIPTION?\bwc\b reads one or more input files and, by default, "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "for each file writes a line containing the number of newlines, "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "\aword\as, and bytes contained in each file followed by the "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "file name to standard output in that order. A \aword\a is "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "defined to be a non-zero length string delimited by \bisspace\b(3) "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "characters.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+?If more than one file is specified, \bwc\b writes a total count "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "for all of the named files with \btotal\b written instead "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "of the file name.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+?By default, \bwc\b writes all three counts. Options can specified "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "so that only certain counts are written. The options \b-c\b "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "and \b-m\b are mutually exclusive.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+?If no \afile\a is given, or if the \afile\a is \b-\b, \bwc\b "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "reads from standard input and no filename is written to standard "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "output. The start of the file is defined as the current offset.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[l:lines?List the line counts.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[w:words?List the word counts.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[c:bytes|chars:chars?List the byte counts.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[m|C:multibyte-chars?List the character counts.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[q:quiet?Suppress invalid multibyte character warnings.]"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz"[L:longest-line|max-line-length?List the longest line length; the newline,"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz "if any, is not counted in the length.]"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz"[N!:utf8?For \bUTF-8\b locales \b--noutf8\b disables \bUTF-8\b "
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz "optimzations and relies on the native \bmbtowc\b(3).]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"\n[file ...]\n"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+EXIT STATUS?]{"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+0?All files processed successfully.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+>0?One or more files failed to open or could not be read.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+SEE ALSO?\bcat\b(1), \bisspace\b(3)]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void printout(register Wc_t *wp, register char *name,register int mode)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sfstdout," %7I*d",sizeof(wp->lines),wp->lines);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sfstdout," %7I*d",sizeof(wp->words),wp->words);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sfstdout," %7I*d",sizeof(wp->chars),wp->chars);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sfprintf(sfstdout," %7I*d",sizeof(wp->chars),wp->longest);
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if (!(mode&(WC_WORDS|WC_CHARS|WC_LINES|WC_MBYTE|WC_LONGEST)))
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz if (!(mode&(WC_WORDS|WC_LINES|WC_MBYTE|WC_LONGEST)) && fstat(sffileno(fp),&statb)>=0