summaryrefslogtreecommitdiff
path: root/usr/src/cmd/wc/wc.c
diff options
context:
space:
mode:
authorRoland Mainz <roland.mainz@nrubsig.org>2009-10-28 10:36:39 -0700
committerRoland Mainz <roland.mainz@nrubsig.org>2009-10-28 10:36:39 -0700
commit34f9b3eef6fdadbda0a846aa4d68691ac40eace5 (patch)
tree0b0fdfb35f8eb9324728de5a99e50e939aca650f /usr/src/cmd/wc/wc.c
parent14969419acb89bb74e6c95fa472119b710224440 (diff)
downloadillumos-joyent-34f9b3eef6fdadbda0a846aa4d68691ac40eace5.tar.gz
Portions contributed by Olga Kryzhanovska <olga.kryzhanovska@gmail.com>
PSARC/2009/063 ksh93 update 2 PSARC/2009/248 ksh93 update to 2009-03-10 PSARC/2009/249 more ksh93 command conversions 6888396 libast sources should not include localedef.h 6605478 ksh93 profile shell option does not work 6631006 ksh93 hangs in situations that ksh handles okay 6661487 logname reports nothing after running the script command 6705126 first call to read doesn't honor new setting of HISTFILE 6764665 *libpp* Array overrun in libpp 6765756 *libast* Array overruns in libast 6769332 Recursive function+command substitutions terminate shell after 257 iterations 6777491 *ksh93* lacks arithmetric function iszero() 6778077 *ksh93* does not understand "THAW" as a signal for use with trap 6789247 [ku1] libast/ksh93 1-digit hexfloat base conversion rounds incorrectly 6791838 *ksh93* unset of a variable which is not set should return 0 6793714 RFE: Update /usr/bin/comm to AT&T AST "comm" 6793719 RFE: Update /usr/bin/cut to AT&T AST "cut" 6793721 RFE: Update /usr/bin/paste to AT&T AST "paste" 6793722 RFE: Update /usr/bin/cmp to AT&T AST "cmp" 6793726 RFE: Update /usr/bin/uniq to AT&T AST "uniq" 6793735 RFE: Update /usr/bin/wc to AT&T AST "wc" 6793744 RFE: Add /usr/share/doc/ksh/ for ksh93 documentation 6793747 RFE: Provide "print" builtin as /usr/bin/print for external applications 6793763 RFE: Update /usr/bin/ksh93 to ast-ksh.2009-05-05 6794952 RFE: Enable "globstar" mode in /etc/ksh.kshrc (= interactive ksh93 shells) 6805792 [ku1] Moving local compound var into array does not work 6805794 [ku1] printf returns "invalid character constant" for $ printf "%d\n" "'<euro>" 6805795 [ku1] ksh93 does not differ between -0 and +0 6805797 [ku1]Can't append to nodes of an array of compound vars if addressing them via nameref 6805799 Indexed compound variable arrays do not work... 6805800 [ku1] Declaring associative compound array does not work 6805813 RFE: Update /usr/bin/join to AT&T AST "join". 6805819 RFE: Update /usr/bin/tee to AT&T AST "tee". 6809663 shlint missing ending newline on errors 6811916 ksh93 repeatedly segfaults when "tee" builtin is interrupted via <ctrl-c> in interactive mode 6821113 SUNWosdem package issues 6828644 RFE: Update /usr/bin/logname to AT&T AST "logname". 6828692 RFE: Update /usr/bin/cksum to AT&T AST "cksum". 6834184 ksh93 gets SIGSEGV if HISTFILE is changed in place. 6834207 ksh93 gets SIGSEGV on interactive function definition with HISTSIZE unset 6835835 ksh93 "cat" builtin does not handle "-n" correctly 6841442 Need exception list for OS/Net trees managed via Subversion 6848486 "echo ${test}" with test undefined crashes the shell 6850672 ksh93 (VISUAL=vi) crashes with memory fault while scrolling through history 6855875 typeset -X x ; print $x # does not print sufficient digits to restore value 6857344 /usr/bin/hash core dump with invalid arguments 6866676 Need test suite module to test the kernel support for compiled shell scripts 6881017 Subshell doesn't exit, holds pipe open preventing callers from exiting 6884409 fts functions in libast library can result in segv with deep dir trees (similar to CERT VU#590371)
Diffstat (limited to 'usr/src/cmd/wc/wc.c')
-rw-r--r--usr/src/cmd/wc/wc.c266
1 files changed, 0 insertions, 266 deletions
diff --git a/usr/src/cmd/wc/wc.c b/usr/src/cmd/wc/wc.c
deleted file mode 100644
index 7eaa884619..0000000000
--- a/usr/src/cmd/wc/wc.c
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
-/* All Rights Reserved */
-
-
-/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-/*
- * wc -- word and line count
- */
-
-#include <stdio.h>
-#include <limits.h>
-#include <locale.h>
-#include <wctype.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <euc.h>
-
-#undef BUFSIZ
-#define BUFSIZ 4096
-unsigned char b[BUFSIZ];
-
-FILE *fptr = stdin;
-unsigned long long wordct;
-unsigned long long twordct;
-unsigned long long linect;
-unsigned long long tlinect;
-unsigned long long charct;
-unsigned long long tcharct;
-unsigned long long real_charct;
-unsigned long long real_tcharct;
-
-int cflag = 0, mflag = 0, lflag = 0, wflag = 0;
-
-static void wcp(unsigned long long, unsigned long long,
- unsigned long long, unsigned long long);
-static void usage(void);
-
-int
-main(int argc, char **argv)
-{
- unsigned char *p1, *p2;
- unsigned int c;
- int flag;
- int i, token;
- int status = 0;
- wchar_t wc;
- int len, n, errflag;
-
-
- (void) setlocale(LC_ALL, "");
-#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
-#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
-#endif
- (void) textdomain(TEXT_DOMAIN);
-
-
- while ((flag = getopt(argc, argv, "cCmlw")) != EOF) {
- switch (flag) {
- case 'c':
- if (mflag)
- usage();
-
- cflag++;
- break;
-
- case 'C':
- case 'm': /* POSIX.2 */
- if (cflag)
- usage();
- mflag++;
- break;
-
- case 'l':
- lflag++;
- break;
-
- case 'w':
- wflag++;
- break;
-
- default:
- usage();
- break;
- }
- }
-
- argc -= optind;
- argv = &argv[optind];
-
- /*
- * If no flags set, use defaults
- */
- if (cflag == 0 && mflag == 0 && lflag == 0 && wflag == 0) {
- cflag = 1;
- lflag = 1;
- wflag = 1;
- }
-
- i = 0;
- do {
- if (argc > 0 && (fptr = fopen(argv[i], "r")) == NULL) {
- (void) fprintf(stderr, "wc: %s: %s\n",
- argv[i], strerror(errno));
- status = 2;
- continue;
- }
-
- p1 = p2 = b;
- linect = 0;
- wordct = 0;
- charct = 0;
- real_charct = 0;
- token = 0;
- errflag = 0;
- for (;;) {
- if (p1 >= p2) {
- p1 = b;
- c = fread(p1, 1, BUFSIZ, fptr);
- if (c == 0) {
- if (feof(fptr))
- break;
- /*
- * skip the file and generate error
- * message when failed to read the
- * file.
- */
- if (ferror(fptr)) {
- (void) fprintf(stderr, gettext(
- "wc: cannot read %s: %s\n"),
- argv[i], strerror(errno));
- status = 2;
- errflag = 1;
- break;
- }
- }
- charct += c;
- p2 = p1+c;
- }
- c = *p1++;
- real_charct++;
- if (ISASCII(c)) {
- if (isspace(c)) {
- if (c == '\n')
- linect++;
- token = 0;
- continue;
- }
-
- if (!token) {
- wordct++;
- token++;
- }
- } else {
- p1--;
- if ((len = (p2 - p1)) <
- (unsigned int)MB_CUR_MAX) {
- for (n = 0; n < len; n++)
- b[n] = *p1++;
- p1 = b;
- p2 = p1 + n;
- c = fread(p2, 1, BUFSIZ - n, fptr);
- if ((int)c > 0) {
- charct += c;
- p2 += c;
- }
- }
-
- if ((len = (p2 - p1)) >
- (unsigned int)MB_CUR_MAX)
- len = (unsigned int)MB_CUR_MAX;
- if ((len = mbtowc(&wc, (char *)p1, len)) > 0) {
- p1 += len;
- if (iswspace(wc)) {
- token = 0;
- continue;
- }
- } else
- p1++;
- if (!token) {
- wordct++;
- token++;
- }
- }
- }
- /* print lines, words, chars */
-printwc:
- (void) fclose(fptr);
- if (errflag)
- continue;
-
- wcp(charct, wordct, linect, real_charct);
- if (argc > 0) {
- (void) printf(" %s\n", argv[i]);
- }
- else
- (void) printf("\n");
- tlinect += linect;
- twordct += wordct;
- tcharct += charct;
- real_tcharct += real_charct;
- } while (++i < argc);
-
- if (argc > 1) {
- wcp(tcharct, twordct, tlinect, real_tcharct);
- (void) printf(" total\n");
- }
- return (status);
-}
-
-static void
-wcp(
- unsigned long long charct,
- unsigned long long wordct,
- unsigned long long linect,
- unsigned long long real_charct)
-{
- if (lflag)
- (void) printf((linect < 10000000) ? " %7llu" :
- " %llu", linect);
-
- if (wflag)
- (void) printf((wordct < 10000000) ? " %7llu" :
- " %llu", wordct);
-
- if (cflag)
- (void) printf((charct < 10000000) ? " %7llu" :
- " %llu", charct);
- else if (mflag)
- (void) printf((real_charct < 10000000) ? " %7llu" :
- " %llu", real_charct);
-}
-
-static void
-usage()
-{
- (void) fprintf(stderr, gettext(
- "usage: wc [-c | -m | -C] [-lw] [file ...]\n"));
- exit(2);
-}