diff options
author | Roland Mainz <roland.mainz@nrubsig.org> | 2009-10-28 10:36:39 -0700 |
---|---|---|
committer | Roland Mainz <roland.mainz@nrubsig.org> | 2009-10-28 10:36:39 -0700 |
commit | 34f9b3eef6fdadbda0a846aa4d68691ac40eace5 (patch) | |
tree | 0b0fdfb35f8eb9324728de5a99e50e939aca650f /usr/src/cmd | |
parent | 14969419acb89bb74e6c95fa472119b710224440 (diff) | |
download | illumos-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')
37 files changed, 208 insertions, 4032 deletions
diff --git a/usr/src/cmd/Makefile b/usr/src/cmd/Makefile index c6fa8fe4f0..e9423852de 100644 --- a/usr/src/cmd/Makefile +++ b/usr/src/cmd/Makefile @@ -88,14 +88,11 @@ COMMON_SUBDIRS= \ chmod \ chown \ chroot \ - cksum \ clear \ clinfo \ cmd-crypto \ cmd-inet \ - cmp \ col \ - comm \ compress \ consadm \ coreadm \ @@ -108,7 +105,6 @@ COMMON_SUBDIRS= \ ctrun \ ctstat \ ctwatch \ - cut \ datadm \ date \ dc \ @@ -218,7 +214,6 @@ COMMON_SUBDIRS= \ isns \ itadm \ java \ - join \ kbd \ keyserv \ killall \ @@ -244,7 +239,6 @@ COMMON_SUBDIRS= \ logger \ login \ logins \ - logname \ look \ ls \ luxadm \ @@ -294,7 +288,6 @@ COMMON_SUBDIRS= \ pagesize \ passmgmt \ passwd \ - paste \ pathchk \ pbind \ pcidr \ @@ -403,7 +396,6 @@ COMMON_SUBDIRS= \ tbl \ tcopy \ tcpd \ - tee \ terminfo \ th_tools \ tic \ @@ -423,7 +415,6 @@ COMMON_SUBDIRS= \ uadmin \ ul \ uname \ - uniq \ units \ unlink \ unpack \ @@ -440,7 +431,6 @@ COMMON_SUBDIRS= \ w \ wall \ wbem \ - wc \ which \ who \ whodo \ @@ -547,12 +537,9 @@ MSGSUBDIRS= \ chgrp \ chmod \ chown \ - cksum \ cmd-crypto \ cmd-inet \ - cmp \ col \ - comm \ compress \ consadm \ coreadm \ @@ -564,7 +551,6 @@ MSGSUBDIRS= \ ctrun \ ctstat \ ctwatch \ - cut \ datadm \ date \ dc \ @@ -615,7 +601,6 @@ MSGSUBDIRS= \ iscsid \ isns \ itadm \ - join \ kbd \ krb5 \ ksh \ @@ -629,7 +614,6 @@ MSGSUBDIRS= \ logadm \ logger \ logins \ - logname \ ls \ luxadm \ lvm \ @@ -653,7 +637,6 @@ MSGSUBDIRS= \ pack \ passwd \ passmgmt \ - paste \ pathchk \ pfexec \ pg \ @@ -714,7 +697,6 @@ MSGSUBDIRS= \ tabs \ tar \ tbl \ - tee \ time \ tnf \ touch \ @@ -725,7 +707,6 @@ MSGSUBDIRS= \ ttymon \ ul \ uname \ - uniq \ units \ unlink \ unpack \ @@ -736,7 +717,6 @@ MSGSUBDIRS= \ volrmmount \ w \ wbem \ - wc \ who \ whodo \ wracct \ diff --git a/usr/src/cmd/ast/msgcc/Makefile b/usr/src/cmd/ast/msgcc/Makefile index 88713d23dd..a5f1f24df5 100644 --- a/usr/src/cmd/ast/msgcc/Makefile +++ b/usr/src/cmd/ast/msgcc/Makefile @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # @@ -36,10 +36,11 @@ include ../../../Makefile.ast CPPFLAGS = \ $(DTEXTDOM) $(DTS_ERRNO) \ -I$(ROOT)/usr/include/ast \ + -I$(ROOT)/usr/include \ -D_PACKAGE_ast \ '-DUSAGE_LICENSE=\ "[-author?Glenn Fowler <gsf@research.att.com>]"\ - "[-copyright?Copyright (c) 1986-2008 AT&T Intellectual Property]"\ + "[-copyright?Copyright (c) 1986-2009 AT&T Intellectual Property]"\ "[-license?http://www.opensource.org/licenses/cpl1.0.txt]"\ "[--catalog?msgcc]"' diff --git a/usr/src/cmd/ast/msgcc/msgcc.sh b/usr/src/cmd/ast/msgcc/msgcc.sh index 3ea55b8dd8..209cbda167 100644 --- a/usr/src/cmd/ast/msgcc/msgcc.sh +++ b/usr/src/cmd/ast/msgcc/msgcc.sh @@ -1,7 +1,7 @@ ######################################################################## # # # This software is part of the ast package # -# Copyright (c) 2000-2008 AT&T Intellectual Property # +# Copyright (c) 2000-2009 AT&T Intellectual Property # # and is licensed under the # # Common Public License, Version 1.0 # # by AT&T Intellectual Property # diff --git a/usr/src/cmd/ast/msgcc/msgcpp.c b/usr/src/cmd/ast/msgcc/msgcpp.c index a9bc934313..a9ac00b52f 100644 --- a/usr/src/cmd/ast/msgcc/msgcpp.c +++ b/usr/src/cmd/ast/msgcc/msgcpp.c @@ -1,7 +1,7 @@ /*********************************************************************** * * * This software is part of the ast package * -* Copyright (c) 2000-2008 AT&T Intellectual Property * +* Copyright (c) 2000-2009 AT&T Intellectual Property * * and is licensed under the * * Common Public License, Version 1.0 * * by AT&T Intellectual Property * diff --git a/usr/src/cmd/ast/msgcc/msgcvt.c b/usr/src/cmd/ast/msgcc/msgcvt.c index d7afe93c82..329fce0d83 100644 --- a/usr/src/cmd/ast/msgcc/msgcvt.c +++ b/usr/src/cmd/ast/msgcc/msgcvt.c @@ -1,7 +1,7 @@ /*********************************************************************** * * * This software is part of the ast package * -* Copyright (c) 2000-2008 AT&T Intellectual Property * +* Copyright (c) 2000-2009 AT&T Intellectual Property * * and is licensed under the * * Common Public License, Version 1.0 * * by AT&T Intellectual Property * diff --git a/usr/src/cmd/ast/msgcc/msggen.c b/usr/src/cmd/ast/msgcc/msggen.c index 7961530dc7..d6999c8b2c 100644 --- a/usr/src/cmd/ast/msgcc/msggen.c +++ b/usr/src/cmd/ast/msgcc/msggen.c @@ -1,7 +1,7 @@ /*********************************************************************** * * * This software is part of the ast package * -* Copyright (c) 2000-2008 AT&T Intellectual Property * +* Copyright (c) 2000-2009 AT&T Intellectual Property * * and is licensed under the * * Common Public License, Version 1.0 * * by AT&T Intellectual Property * diff --git a/usr/src/cmd/ast/msgcc/msgget.c b/usr/src/cmd/ast/msgcc/msgget.c index 10a389bfeb..d4c8798fa2 100644 --- a/usr/src/cmd/ast/msgcc/msgget.c +++ b/usr/src/cmd/ast/msgcc/msgget.c @@ -1,7 +1,7 @@ /*********************************************************************** * * * This software is part of the ast package * -* Copyright (c) 2000-2008 AT&T Intellectual Property * +* Copyright (c) 2000-2009 AT&T Intellectual Property * * and is licensed under the * * Common Public License, Version 1.0 * * by AT&T Intellectual Property * diff --git a/usr/src/cmd/cksum/Makefile b/usr/src/cmd/cksum/Makefile deleted file mode 100644 index 7b1e59e17c..0000000000 --- a/usr/src/cmd/cksum/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# cmd/cksum/Makefile - -PROG= cksum - -include ../Makefile.cmd - -CFLAGS += $(CCVERBOSE) -CPPFLAGS += -D_FILE_OFFSET_BITS=64 - -.KEEP_STATE: - -all: $(PROG) - -install: all $(ROOTPROG) - -clean: - -lint: lint_PROG - -include ../Makefile.targ diff --git a/usr/src/cmd/cksum/cksum.c b/usr/src/cmd/cksum/cksum.c deleted file mode 100644 index 000a1649d7..0000000000 --- a/usr/src/cmd/cksum/cksum.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (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 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <locale.h> -#include <libgen.h> - -#define NBUF 4096 /* Read this much at a time */ -#define BSIZE 512 /* Bytes per block */ - -typedef unsigned long CRC; /* 32 bit (at least) crc size */ - -static uchar_t buf[NBUF]; /* Input buffer */ -static uchar_t tflag; /* More than one input file */ -static uchar_t many; -static CRC filecrc; /* CRC for this file */ -static CRC totcrc; /* Total of all files */ -static long long totbytes; /* Total bytes read */ -static ulong_t bsize = 1; /* block size */ - -static int sum(const char *fn); -static int usage(void); -static CRC docrcposix(CRC crcval, uchar_t *bp, ulong_t n); -static CRC postprocess(CRC S, long long n); - -static CRC (*crcfunc)(CRC crcval, uchar_t *bp, ulong_t n) = docrcposix; -static void m_crcposix(ulong_t *, const uchar_t *, size_t); - -/* - * Mainline for cksum. - */ -int -main(int argc, char *argv[]) -{ - int c; - int exstat = 0; - - (void) setlocale(LC_ALL, ""); - -#if !defined(TEXT_DOMAIN) -#define TEXT_DOMAIN "SYS_TEST" -#endif - (void) textdomain(TEXT_DOMAIN); - - tflag = many = 0; - totbytes = totcrc = 0; - while ((c = getopt(argc, argv, "")) != -1) { - switch (c) { - case 't': /* this is non-functional for now */ - tflag++; - break; - default: - return (usage()); - } - } - - /* Sum from standard input? */ - if ((many = optind < argc) == 0) - return (sum(NULL)); - - /* Sum each file argument. */ - for (; optind < argc; ++optind) - exstat |= sum(argv[optind]); - - if (tflag) { - (void) printf("%lu", postprocess(totcrc, totbytes)); - (void) printf(gettext("\t%lld\t Total\n"), - (long long)((totbytes + bsize - 1) / bsize)); - } - return (exstat); -} - -/* - * Compute checksum for one file. - */ -static int -sum(const char *fn) -{ - int n; - int fd; - long long bytes = 0; - - if (fn == NULL || (fn[0] == '-' && fn[1] == '\0')) - fd = 0; - else if ((fd = open(fn, O_RDONLY)) < 0) { - (void) fprintf(stderr, gettext("cksum: input file \"%s\": "), - fn); - perror(""); - return (1); - } - filecrc = 0; - while ((n = read(fd, (char *)buf, sizeof (buf))) > 0) { - bytes += n; - filecrc = (*crcfunc) (filecrc, buf, n); - if (tflag) - totcrc = (*crcfunc) (totcrc, buf, n); - } - (void) close(fd); - totbytes += bytes; - (void) printf("%lu", postprocess(filecrc, bytes)); - (void) printf("\t%lld", (long long)((bytes + bsize - 1) / bsize)); - if (many) { - (void) printf("\t%s", (fn[0] == '-' && fn[1] == '\0') ? - gettext("[standard input]") : fn); - } - if (n < 0) - (void) fputs(gettext(" [read error]"), stdout); - (void) putchar('\n'); - return (n == 0 ? 0 : 1); -} - - -/* - * Do CRC-POSIX function by calling a library entry point that has a - * slightly different calling sequence. - */ -static CRC -docrcposix(CRC crcval, uchar_t *bp, ulong_t n) -{ - m_crcposix(&crcval, bp, n); - return (crcval); -} - -/* - * Sum algorithms require various kinds of post-processing. - * The 'S' and 'R' variables are from the POSIX.2 (Draft 8?) description - * of the "sum" utility. - * This code makes no assumption about word size except that a - * "CRC" type holds at least 32 bits. - */ -static CRC -postprocess(CRC S, long long n) -{ - /* - * POSIX tacks on significant bytes of the length so that - * different length sequences of '\0' have different sums; - * then it complements sum. - */ - uchar_t char_n[sizeof (n)]; - ulong_t i; - - for (i = 0; n != 0; n >>= 8, ++i) - char_n[i] = n & 0xFF; - return (~docrcposix(S, char_n, i)); -} - -/* - * usage message for cksum - */ -static int -usage() -{ - (void) fprintf(stderr, gettext("Usage: cksum [file ...]\n")); - return (2); -} - -/* - * crcposix -- compute posix.2 compatable 32 bit CRC - * - * The POSIX.2 (draft 10) CRC algorithm. - * This is a 32 bit CRC with polynomial - * x**32 + x**26 + x**23 + x**22 + x**16 + x**12 + x**11 + x**10 + - * x**8 + x**7 + x**5 + x**4 + x**2 + x**1 + x**0 - */ - -/* layout is from the POSIX.2 Rationale */ -static ulong_t crctab_posix[256] = { - 0x00000000, - 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B, - 0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, - 0x2B4BCB61, 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, - 0x4C11DB70, 0x48D0C6C7, 0x4593E01E, 0x4152FDA9, 0x5F15ADAC, - 0x5BD4B01B, 0x569796C2, 0x52568B75, 0x6A1936C8, 0x6ED82B7F, - 0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3, 0x709F7B7A, - 0x745E66CD, 0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039, - 0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5, 0xBE2B5B58, - 0xBAEA46EF, 0xB7A96036, 0xB3687D81, 0xAD2F2D84, 0xA9EE3033, - 0xA4AD16EA, 0xA06C0B5D, 0xD4326D90, 0xD0F37027, 0xDDB056FE, - 0xD9714B49, 0xC7361B4C, 0xC3F706FB, 0xCEB42022, 0xCA753D95, - 0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1, 0xE13EF6F4, - 0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D, 0x34867077, 0x30476DC0, - 0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, 0x2E003DC5, - 0x2AC12072, 0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16, - 0x018AEB13, 0x054BF6A4, 0x0808D07D, 0x0CC9CDCA, 0x7897AB07, - 0x7C56B6B0, 0x71159069, 0x75D48DDE, 0x6B93DDDB, 0x6F52C06C, - 0x6211E6B5, 0x66D0FB02, 0x5E9F46BF, 0x5A5E5B08, 0x571D7DD1, - 0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA, - 0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, 0xBFA1B04B, - 0xBB60ADFC, 0xB6238B25, 0xB2E29692, 0x8AAD2B2F, 0x8E6C3698, - 0x832F1041, 0x87EE0DF6, 0x99A95DF3, 0x9D684044, 0x902B669D, - 0x94EA7B2A, 0xE0B41DE7, 0xE4750050, 0xE9362689, 0xEDF73B3E, - 0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2, 0xC6BCF05F, - 0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, 0xD1799B34, - 0xDC3ABDED, 0xD8FBA05A, 0x690CE0EE, 0x6DCDFD59, 0x608EDB80, - 0x644FC637, 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB, - 0x4F040D56, 0x4BC510E1, 0x46863638, 0x42472B8F, 0x5C007B8A, - 0x58C1663D, 0x558240E4, 0x51435D53, 0x251D3B9E, 0x21DC2629, - 0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5, 0x3F9B762C, - 0x3B5A6B9B, 0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF, - 0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623, 0xF12F560E, - 0xF5EE4BB9, 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, 0xE6EA3D65, - 0xEBA91BBC, 0xEF68060B, 0xD727BBB6, 0xD3E6A601, 0xDEA580D8, - 0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD, 0xCDA1F604, 0xC960EBB3, - 0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7, 0xAE3AFBA2, - 0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B, 0x9B3660C6, 0x9FF77D71, - 0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, 0x81B02D74, - 0x857130C3, 0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640, - 0x4E8EE645, 0x4A4FFBF2, 0x470CDD2B, 0x43CDC09C, 0x7B827D21, - 0x7F436096, 0x7200464F, 0x76C15BF8, 0x68860BFD, 0x6C47164A, - 0x61043093, 0x65C52D24, 0x119B4BE9, 0x155A565E, 0x18197087, - 0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC, - 0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, 0x2497D08D, - 0x2056CD3A, 0x2D15EBE3, 0x29D4F654, 0xC5A92679, 0xC1683BCE, - 0xCC2B1D17, 0xC8EA00A0, 0xD6AD50A5, 0xD26C4D12, 0xDF2F6BCB, - 0xDBEE767C, 0xE3A1CBC1, 0xE760D676, 0xEA23F0AF, 0xEEE2ED18, - 0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4, 0x89B8FD09, - 0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, 0x9E7D9662, - 0x933EB0BB, 0x97FFAD0C, 0xAFB010B1, 0xAB710D06, 0xA6322BDF, - 0xA2F33668, 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4 -}; - -/* - * crcposix -- compute posix.2 compatible 32 bit CRC - */ -void -m_crcposix(crcp, bp, n) -ulong_t *crcp; -const uchar_t *bp; -size_t n; -{ - while (n-- > 0) - *crcp = (*crcp<<8) ^ crctab_posix[(uchar_t)((*crcp>>24)^*bp++)]; -} diff --git a/usr/src/cmd/cmp/Makefile b/usr/src/cmd/cmp/Makefile deleted file mode 100644 index 5a74c59d76..0000000000 --- a/usr/src/cmd/cmp/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright (c) 1989, 1996 by Sun Microsystems, Inc. -# All rights reserved. -# - -PROG= cmp - -include ../Makefile.cmd - -CPPFLAGS += -D_FILE_OFFSET_BITS=64 - -.KEEP_STATE: - -all: $(PROG) - -install: all $(ROOTPROG) - -clean: - -lint: lint_PROG - -include ../Makefile.targ diff --git a/usr/src/cmd/cmp/cmp.c b/usr/src/cmd/cmp/cmp.c deleted file mode 100644 index 37ede810eb..0000000000 --- a/usr/src/cmd/cmp/cmp.c +++ /dev/null @@ -1,194 +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 - */ -/* Portions Copyright 2006 Stephen P. Potter */ - -/* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * compare two files - */ - -#include <stdio.h> -#include <stdlib.h> -#include <ctype.h> -#include <locale.h> -#include <sys/types.h> - -FILE *file1, *file2; - -char *arg; - -int eflg; -int lflg = 1; - -offset_t line = 1; -offset_t chr = 0; -offset_t skip1; -offset_t skip2; - -offset_t otoi(char *); - -static void narg(void); -static void barg(void); -static void earg(void); - -int -main(int argc, char **argv) -{ - int c; - int c1, c2; - - (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 ((c = getopt(argc, argv, "ls")) != EOF) - switch (c) { - case 'l': - lflg = 2; - break; - case 's': - lflg = 0; - break; - case '?': - default: - narg(); - } - argv += optind; - argc -= optind; - if (argc < 2 || argc > 4) - narg(); - - arg = argv[0]; - if (arg[0] == '-' && arg[1] == 0) - file1 = stdin; - else if ((file1 = fopen(arg, "r")) == NULL) - barg(); - - arg = argv[1]; - if (arg[0] == '-' && arg[1] == 0) - file2 = stdin; - else if ((file2 = fopen(arg, "r")) == NULL) - barg(); - - if (file1 == stdin && file2 == stdin) - narg(); - - if (argc > 2) - skip1 = otoi(argv[2]); - if (argc > 3) - skip2 = otoi(argv[3]); - while (skip1) { - if ((c1 = getc(file1)) == EOF) { - arg = argv[0]; - earg(); - } - skip1--; - } - while (skip2) { - if ((c2 = getc(file2)) == EOF) { - arg = argv[1]; - earg(); - } - skip2--; - } - - for (;;) { - chr++; - c1 = getc(file1); - c2 = getc(file2); - if (c1 == c2) { - if (c1 == '\n') - line++; - if (c1 == EOF) { - if (eflg) - return (1); - return (0); - } - continue; - } - if (lflg == 0) - return (1); - if (c1 == EOF) { - arg = argv[0]; - earg(); - } - if (c2 == EOF) - earg(); - if (lflg == 1) { - (void) printf( - gettext("%s %s differ: char %lld, line %lld\n"), - argv[0], arg, chr, line); - return (1); - } - eflg = 1; - (void) printf("%6lld %3o %3o\n", chr, c1, c2); - } -} - -offset_t -otoi(s) -char *s; -{ - offset_t v; - int base; - - v = 0; - base = 10; - if (*s == '0') - base = 8; - while (isdigit(*s)) - v = v*base + *s++ - '0'; - return (v); -} - -static void -narg() -{ - (void) fprintf(stderr, - gettext("usage: cmp [-l | -s] file1 file2 [skip1] [skip2]\n")); - exit(2); -} - -static void -barg() -{ - if (lflg) - (void) fprintf(stderr, gettext("cmp: cannot open %s\n"), arg); - exit(2); -} - -static void -earg() -{ - (void) fprintf(stderr, gettext("cmp: EOF on %s\n"), arg); - exit(1); -} diff --git a/usr/src/cmd/comm/Makefile b/usr/src/cmd/comm/Makefile deleted file mode 100644 index a07e14d6a7..0000000000 --- a/usr/src/cmd/comm/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -PROG= comm - -include ../Makefile.cmd - -CFLAGS += $(CCVERBOSE) - -.KEEP_STATE: - -all: $(PROG) - -install: all $(ROOTPROG) - -clean: - -lint: lint_PROG - -include ../Makefile.targ diff --git a/usr/src/cmd/comm/comm.c b/usr/src/cmd/comm/comm.c deleted file mode 100644 index 00f8caa932..0000000000 --- a/usr/src/cmd/comm/comm.c +++ /dev/null @@ -1,256 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (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 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * process common lines of two files - */ - -#include <locale.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -static int compare(char *, char *); -static int rd(FILE *, char *); -static FILE *openfil(char *); -static void copy(FILE *, char *, int); -static void usage(void); -static void wr(char *, int); - -#define LB 2050 /* P1003.2 minimum (2048) + 2 */ - -#define RDTWO(ib1, lb1, ib2, lb2) \ - { \ - if (rd(ib1, lb1) < 0) { \ - if (rd(ib2, lb2) < 0) \ - exit(0); \ - copy(ib2, lb2, 2); \ - } \ - if (rd(ib2, lb2) < 0) \ - copy(ib1, lb1, 1); \ - } - -static int one; -static int two; -static int three; - -static char ldr[3][3] = {"", "\t", "\t\t"}; - -static FILE *ib1; -static FILE *ib2; -static int is_c_locale; - -int -main(int argc, char **argv) -{ - int l = 1; - int c; /* used for getopt() */ - char lb1[LB], lb2[LB], *collate; - - (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); - - if ((collate = setlocale(LC_COLLATE, NULL)) == NULL) { - (void) fprintf(stderr, - gettext("Query of LC_COLLATE category failed\n")); - exit(4); - } - - is_c_locale = (strcmp("C", collate) == 0) ? 1 : 0; - while ((c = getopt(argc, argv, "123")) != EOF) - switch (c) { - case '1': - if (!one) { - one = 1; - ldr[1][0] = ldr[2][l--] = '\0'; - } - break; - case '2': - if (!two) { - two = 1; - ldr[2][l--] = '\0'; - } - break; - case '3': - three = 1; - break; - - default: - usage(); - } - - argc -= optind; - argv = &argv[optind]; - - if (argc != 2) - usage(); - ib1 = openfil(argv[0]); - ib2 = openfil(argv[1]); - RDTWO(ib1, lb1, ib2, lb2); - for (;;) { - switch (compare(lb1, lb2)) { - case 0: - wr(lb1, 3); - RDTWO(ib1, lb1, ib2, lb2); - continue; - - case 1: - wr(lb1, 1); - if (rd(ib1, lb1) < 0) - copy(ib2, lb2, 2); - continue; - - case 2: - wr(lb2, 2); - if (rd(ib2, lb2) < 0) - copy(ib1, lb1, 1); - continue; - /* - * case "3" means lines are equal in collation, - * but not identical (not very likely) - */ - case 3: - wr(lb1, 1); - wr(lb2, 2); - RDTWO(ib1, lb1, ib2, lb2); - continue; - } - } - /* NOTREACHED */ - return (0); -} - -static int -rd(file, buf) -FILE *file; -char *buf; -{ - register int i, j; - i = j = 0; - while ((j = getc(file)) != EOF) { - *buf = (char)j; - if (*buf == '\n' || i > LB-2) { - *buf = '\0'; - return (0); - } - i++; - buf++; - } - return (-1); -} - -static void -wr(str, n) -char *str; -int n; -{ - switch (n) { - case 1: - if (one) - return; - break; - - case 2: - if (two) - return; - break; - - case 3: - if (three) - return; - } - (void) printf("%s%s\n", ldr[n-1], str); -} - -static void -copy(ibuf, lbuf, n) -FILE *ibuf; -char *lbuf; -int n; -{ - do { - wr(lbuf, n); - } while (rd(ibuf, lbuf) >= 0); - - exit(0); -} - -static int -compare(a, b) -char *a, *b; -{ - register char *ra, *rb; - int ret; - - ra = a - 1; - rb = b - 1; - while (*++ra == *++rb) - if (*ra == '\0') - return (0); - - /* For "C" locale, just compare bytes */ - if (is_c_locale) { - if (*ra < *rb) - return (1); - return (2); - } - /* For other locales, call locale-sensitive compare routine */ - else { - ret = strcoll(a, b); - return (ret == 0 ? 3 : (ret < 0 ? 1 : 2)); - } -} - -static FILE * -openfil(s) -char *s; -{ - FILE *b; - if (s[0] == '-' && s[1] == 0) - b = stdin; - else if ((b = fopen(s, "r")) == NULL) { - (void) fprintf(stderr, "comm: "); - perror(s); - exit(2); - } - return (b); -} - -static void -usage() -{ - (void) fprintf(stderr, gettext("usage: comm [-123] file1 file2\n")); - exit(2); -} diff --git a/usr/src/cmd/cut/Makefile b/usr/src/cmd/cut/Makefile deleted file mode 100644 index 55b3e17fc9..0000000000 --- a/usr/src/cmd/cut/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright (c) 1989, 1996 by Sun Microsystems, Inc. -# All rights reserved. -# - -PROG= cut - -include ../Makefile.cmd - -CPPFLAGS += -D_FILE_OFFSET_BITS=64 - -XGETFLAGS += -a -x $(PROG).xcl - -.KEEP_STATE: - -all: $(PROG) - -install: all $(ROOTPROG) - -clean: - -lint: lint_PROG - -include ../Makefile.targ diff --git a/usr/src/cmd/cut/cut.c b/usr/src/cmd/cut/cut.c deleted file mode 100644 index 49d89db3c2..0000000000 --- a/usr/src/cmd/cut/cut.c +++ /dev/null @@ -1,627 +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 2008 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - -# -/* cut : cut and paste columns of a table (projection of a relation) */ -/* Release 1.5; handles single backspaces as produced by nroff */ - -#include <stdio.h> /* make: cc cut.c */ -#include <ctype.h> -#include <limits.h> -#include <locale.h> -#include <wchar.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <errno.h> - -#define MAX_RANGES MAX_INPUT /* maximum number of ranges */ - /* as input args */ - -static void bfunc(void); -static void bnfunc(void); -static void cfunc(void); -static void ffunc(void); -static wchar_t *read_line(FILE *); -static void process_list(char *); -static void diag(const char *); -static void usage(void); - -static wchar_t wdel = '\t'; -static int dellen; -static int supflag = 0; -static int rstart[MAX_RANGES]; -static int rend[MAX_RANGES]; -static int nranges = 0; -static FILE *inptr; -static char dummy[MB_LEN_MAX]; - -static wchar_t *linebuf = NULL; -static int bufsiz; - -int -main(int argc, char **argv) -{ - int c; - char *list; - int status = 0; - int bflag, nflag, cflag, fflag, dflag, filenr; - void (*funcp)(); - - bflag = nflag = cflag = fflag = dflag = 0; - - (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 ((c = getopt(argc, argv, "b:c:d:f:ns")) != EOF) - switch (c) { - case 'b': - if (fflag || cflag) - usage(); - bflag++; - list = optarg; - break; - - case 'c': - if (fflag || bflag) - usage(); - cflag++; - list = optarg; - break; - - case 'd': - dellen = mbtowc(&wdel, optarg, MB_CUR_MAX); - if (dellen == -1) { - diag("no delimiter specified"); - } else if (dellen != strlen(optarg)) - diag("invalid delimiter"); - dflag++; - break; - - case 'f': - if (bflag || cflag) - usage(); - fflag++; - list = optarg; - break; - - case 'n': - nflag++; - break; - - case 's': - supflag++; - break; - - case '?': - usage(); - } - - argv = &argv[optind]; - argc -= optind; - - /* you must use one and only one option -b, -c, or -f */ - if (!(cflag || fflag || bflag)) - usage(); - - /* - * Make sure combination of options is correct - */ - if (nflag) { - if (cflag || fflag) { - (void) fprintf(stderr, gettext( - "cut: -n may only be used with -b\n")); - usage(); - } - } - - if (dflag || supflag) { - if (bflag || cflag) { - if (dflag) - (void) fprintf(stderr, gettext( - "cut: -d may only be used with -f\n")); - if (supflag) - (void) fprintf(stderr, gettext( - "cut: -s may only be used with -f\n")); - usage(); - } - } - - process_list(list); - - if (cflag) { - funcp = cfunc; - } else if (bflag) { - if (nflag) - funcp = bnfunc; - else - funcp = bfunc; - } else { /* fflag */ - funcp = ffunc; - } - - if (nranges == 0) - diag("no list specified"); - - filenr = 0; - do { /* for all input files */ - if (argc == 0 || strcmp(argv[filenr], "-") == 0) - inptr = stdin; - else { - if ((inptr = fopen(argv[filenr], "r")) == NULL) { - (void) fprintf(stderr, "cut: %s: %s\n", - argv[filenr], strerror(errno)); - status = 1; - continue; - } - /* - * ftell() is used to check whether the file is an - * open file descriptor and if the file is associate - * with the a pipe, a FIFO,or a socket if file cannot - * be opened ftell() can be used to check the status - * of the file - */ - if (ftell(inptr) == -1) { - (void) fprintf(stderr, "cut: %s: %s\n", - argv[filenr], strerror(errno)); - status = 1; - continue; - } - } - (*funcp)(); - (void) fclose(inptr); - } while (++filenr < argc); - return (status); -} - -/* parse range list argument and set-up rstart/rend array */ -void -process_list(char *list) -{ - int inrange = 0; - int start = 0; - int num = 0; - char *rlist = list; - char *p; - int i, j; - int tmp; - - /* first, parse list of ranges */ - do { - p = rlist; - switch (*p) { - case '-': - if (inrange) - diag("invalid range specifier"); - - inrange = 1; - if (num == 0) - start = 1; - else { - start = num; - num = 0; - } - break; - - case '\0': - case ',': - case ' ': - case '\t': - /* - * this is temporary - it will change - * when the isblank() routine becomes - * available. - */ - if (nranges == MAX_RANGES) - diag("too many ranges specified"); - - if (inrange) { - if (num == 0) - num = INT_MAX; - if (num < start) - diag("ranges must be " - "increasing"); - rstart[nranges] = start; - rend[nranges] = num; - nranges++; - } else { - rstart[nranges] = num; - rend[nranges] = num; - nranges++; - } - - num = 0; - start = 0; - inrange = 0; - - if (*p == '\0') - continue; - break; - - default: - if (!isdigit(*p)) - diag("invalid character in range"); - num = atoi(p); - while (isdigit(*rlist)) - rlist++; - continue; - } - rlist++; - } while (*p != '\0'); - - /* then, consolidate ranges where possible */ - for (i = 0; i < (nranges - 1); i++) { - for (j = i + 1; j < nranges; j++) { - if (rstart[i] != 0 && rend[i] != 0 && - (!(rend[i] < rstart[j] || rstart[i] > rend[j]))) { - if (rstart[i] < rstart[j]) - rstart[j] = rstart[i]; - if (rend[i] > rend[j]) - rend[j] = rend[i]; - rstart[i] = 0; - rend[i] = 0; - break; - } - } - } - - /* then, weed out the zero'ed/consolidated entries */ - for (i = 0; i < nranges; ) { - if (rstart[i] == 0 && rend[i] == 0) { - for (j = i; j < (nranges - 1); j++) { - rstart[j] = rstart[j+1]; - rend[j] = rend[j+1]; - } - nranges--; - } else if (rstart[i] == 0 || rend[i] == 0) { - diag("Internal error processing input"); - } else { - i++; - } - } - - /* finally, sort the remaining entries */ - for (i = 0; i < (nranges - 1); i++) { - for (j = i+1; j < nranges; j++) { - if (rstart[i] > rend[j]) { - tmp = rstart[i]; - rstart[i] = rstart[j]; - rstart[j] = tmp; - - tmp = rend[i]; - rend[i] = rend[j]; - rend[j] = tmp; - } - } - } - -#ifdef DEBUG - /* dump ranges */ - for (i = 0; i < nranges; i++) { - (void) printf("Range %d - start: %d end: %d\n", i, rstart[i], - rend[i]); - } -#endif -} - -/* called when -c is used */ -/* print out those characters selected */ - -void -cfunc(void) -{ - wint_t c; /* current character */ - int pos = 0; /* current position within line */ - int inrange = 0; /* is 'pos' within a range */ - int rndx = 0; /* current index into range table */ - - while ((c = fgetwc(inptr)) != EOF) { - if (c == '\n') { - (void) putchar('\n'); - - /* reset per-line variables */ - pos = 0; - inrange = 0; - rndx = 0; - } else { - pos++; - - /* - * check if current character is within range and, - * if so, print it. - */ - if (!inrange) - if (pos == rstart[rndx]) - inrange = 1; - - if (inrange) { - (void) putwchar(c); - if (pos == rend[rndx]) { - inrange = 0; - rndx++; - /* - * optimization - - * check for last range index - * and eat chars until newline - * if so. - */ - } - } - } - } -} - -void -bfunc(void) /* called when -b is used but -n is not */ -{ - int c; /* current character */ - int pos = 0; /* current position within line */ - int inrange = 0; /* is 'pos' within a range */ - int rndx = 0; /* current index into range table */ - - while ((c = getc(inptr)) != EOF) { - if (c == L'\n') { - (void) putchar('\n'); - - /* reset per-line variables */ - pos = 0; - inrange = 0; - rndx = 0; - } else { - pos++; - - /* - * check if current character is within range and, - * if so, print it. - */ - if (!inrange) - if (pos == rstart[rndx]) - inrange = 1; - - if (inrange) { - (void) putchar(c); - if (pos == rend[rndx]) { - inrange = 0; - rndx++; - /* - * optimization - - * check for last range index - * and eat chars until newline - * if so. - */ - } - } - } - } -} - - -void -bnfunc(void) /* called when -b -n is used */ -{ - wint_t c; /* current character */ - int pos = 0; /* current position within line */ - int inrange = 0; /* is 'pos' within a range */ - int rndx = 0; /* current index into range table */ - int wlen; /* byte length of current wide char */ - - while ((c = fgetwc(inptr)) != EOF) { - if (c == '\n') { - (void) putchar('\n'); - - /* reset per-line variables */ - pos = 0; - inrange = 0; - rndx = 0; - } else { - if (rndx >= nranges) - continue; - - if ((wlen = wctomb(dummy, c)) < 0) - diag("invalid multibyte character"); - pos += wlen; - - /* - * when trying to figure this out, remember that - * pos is actually pointing to the start byte of - * the next char. - */ - - /* - * if char starts after beginning of range, - * for the moment, consider it in range. - */ - if (!inrange && pos < rstart[rndx]) - continue; - - /* - * If tail of the multibyte is out of the range. - * do not print the character. - * (See XCU4) - */ - if (pos <= rend[rndx]) { - inrange = 1; - (void) putwchar(c); - continue; - } - inrange = 0; - while (++rndx < nranges && pos >= rstart[rndx]) { - if (pos <= rend[rndx]) { - inrange = 1; - (void) putwchar(c); - break; - } - } - } - } -} - -wchar_t * -read_line(FILE *fp) -{ - wint_t c; - wchar_t *cp; - int charcnt; - - /* alloc the line buffer if it isn't already there */ - if (linebuf == NULL) { - bufsiz = BUFSIZ - 1; - if ((linebuf = (wchar_t *)malloc((bufsiz + 1) * - sizeof (wchar_t))) == NULL) - diag("unable to allocate enough memory"); - } - - cp = linebuf; - charcnt = 0; - while ((c = fgetwc(fp)) != EOF) { - if (c == '\n') { - *cp = NULL; - return (linebuf); - } else { - charcnt++; - if (charcnt == bufsiz) { - /* - * there is no line length limitation so we - * have to be ready to expand the line buffer. - */ - bufsiz += BUFSIZ; - if ((linebuf = (wchar_t *)realloc(linebuf, - (bufsiz + 1) * sizeof (wchar_t))) == NULL) - diag("unable to allocate " - "enough memory"); - - cp = linebuf + charcnt - 1; - } - *cp++ = c; - } - } - - if (cp != linebuf) { - *cp = NULL; - return (linebuf); - } else - return (NULL); -} - -void -ffunc(void) /* called when -f is used */ -{ - int fpos; /* current field position within line */ - int inrange; /* is 'pos' within a range */ - int rndx; /* current index into range table */ - int need_del; /* need to put a delimiter char in output */ - wchar_t *linep; /* pointer to line buffer */ - wchar_t *cp, *ncp; /* working pointers into linebuf */ - - while ((linep = read_line(inptr)) != NULL) { - - /* first, prune out line with no delimiters */ - if (wcschr(linep, wdel) == NULL) { -#if !defined(__lint) /* lint doesn't grok "%ws" */ - if (!supflag) - (void) printf("%ws\n", linep); -#endif - continue; - } - - /* init per-line variable */ - fpos = 1; - inrange = 0; - rndx = 0; - need_del = 0; - - for (ncp = cp = linep; ncp != NULL; fpos++) { - /* why continue processing if no more ranges? */ - if (rndx >= nranges) - break; - - /* find the next field delimiter */ - ncp = wcschr(cp, wdel); - - if (!inrange) - if (fpos == rstart[rndx]) - inrange = 1; - - if (inrange) { - if (need_del) - (void) putwchar(wdel); - - if (ncp == NULL) { - /* - * if there are no more delimiters - * and we are in the range, print - * out the rest of the line. - */ -#if !defined(__lint) /* lint doesn't grok "%ws" */ - (void) printf("%ws", cp); -#endif - break; - } - else - while (cp != ncp) - (void) putwchar(*cp++); - need_del = 1; - - if (fpos == rend[rndx]) { - inrange = 0; - rndx++; - } - } - - if (ncp != NULL) - cp = ncp + 1; - } - (void) putchar('\n'); - } -} - - -void -diag(const char *s) -{ - (void) fprintf(stderr, "cut: "); - (void) fprintf(stderr, gettext(s)); - (void) fprintf(stderr, "\n"); - exit(2); -} - - -void -usage(void) -{ - (void) fprintf(stderr, gettext( - "usage: cut -b list [-n] [filename ...]\n" - " cut -c list [filename ...]\n" - " cut -f list [-d delim] [-s] [filename]\n")); - exit(2); -} diff --git a/usr/src/cmd/cut/cut.xcl b/usr/src/cmd/cut/cut.xcl deleted file mode 100644 index a020d688d0..0000000000 --- a/usr/src/cmd/cut/cut.xcl +++ /dev/null @@ -1,29 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -msgid "" -msgid "b:c:d:f:ns" -msgid "-" -msgid "r" -msgid "%ws\n" -msgid "%ws" -msgid "cut: " -msgid "\n" diff --git a/usr/src/cmd/join/Makefile b/usr/src/cmd/join/Makefile deleted file mode 100644 index a3dee14f6d..0000000000 --- a/usr/src/cmd/join/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -PROG= join - -include ../Makefile.cmd - -CFLAGS += $(CCVERBOSE) -XGETFLAGS += -a -x join.xcl -CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 - -.KEEP_STATE: - -all: $(PROG) - -install: all $(ROOTPROG) - -clean: - -lint: lint_PROG - -include ../Makefile.targ diff --git a/usr/src/cmd/join/join.c b/usr/src/cmd/join/join.c deleted file mode 100644 index bd631aaecb..0000000000 --- a/usr/src/cmd/join/join.c +++ /dev/null @@ -1,693 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (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 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* join F1 F2 on stuff */ - -#include <stdio.h> -#include <locale.h> -#include <stdlib.h> -#include <widec.h> -#include <string.h> -#include <limits.h> -#include <malloc.h> -#include <errno.h> -#include <unistd.h> - - -static void output(int, int); -static int cmp(wchar_t *, wchar_t *); -static int input(int); -static void Usage(); -static void init_buf(); -static void get_buf(int, int); -static void get_ppi(int); -static void get_olist(int); -wchar_t *wcsrchr(const wchar_t *, wchar_t); -size_t wcslen(const wchar_t *); - - -#define JOINFIELD 9999 -#define F1 0 -#define F2 1 -#define NFLD LINE_MAX/2 /* max field per line */ -#define NOFLD (2*NFLD) /* number arguments to -o */ -#define comp() cmp(ppi[F1][j1], ppi[F2][j2]) -#define get1() n1 = input(F1) -#define get2() n2 = input(F2) -#define putfield(string) \ - if (string == (wchar_t *)NULL) \ - (void) fputs(null, stdout); \ - else if (*string == (wchar_t)NULL) \ - (void) fputs(null, stdout); \ - else \ - (void) fputws(string, stdout) - -#define max(a, b) (a >= b ? a : b) -int CNFLD; /* current number of fields per line */ -int CNOFLD; /* current number of output fields */ -int CBUFSIZE[2]; /* current size of input buffers */ - -static FILE *f[2]; -static wchar_t *buf[2]; /* input lines */ -static wchar_t **ppi[2]; /* pointers to fields in lines */ -static int j1 = 1; /* join of this field of file 1 */ -static int j2 = 1; /* join of this field of file 2 */ -static int *olist; /* output these fields */ -static int *olistf; /* from these files */ -static int no = 0; /* number of entries in olist */ -static wchar_t sep1 = L' '; /* default field separator */ -static wchar_t sep2 = L'\t'; -static char *null = ""; -static int aflg = 0; -static int vflg = 0; -static int tflg = 0; - -int -main(int argc, char *argv[]) -{ - int i, j; - int n1, n2; - off_t top2, bot2; - int cmpresult; - int opt, filenumber; - int nextargopt; - size_t t; - char buffer1[BUFSIZ]; - char tmpfile[20]; - int fd; - - (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); - - (void) init_buf(); /* allocate buffers */ - - /* check for non-standard "-j#" option, last 2 arguments are files */ - for (i = 1; i < (argc - 2); i++) { - if (strcmp(argv[i], "--") == 0) - break; - - if (strcmp(argv[i], "-j1") == 0) { - if (i == argc - 3) - Usage(); - - j1 = (int)strtol(argv[i+1], (char **)NULL, 10); - for (j = i; j < argc - 1; j++) { - argv[j] = argv[j+2]; - } - argc -= 2; - i--; - } else if (strcmp(argv[i], "-j2") == 0) { - if (i >= argc - 3) - Usage(); - - j2 = (int)strtol(argv[i+1], (char **)NULL, 10); - for (j = i; j < argc - 1; j++) { - argv[j] = argv[j+2]; - } - argc -= 2; - i--; - } - - } - - /* check for non-standard "-o" option, last 2 arguments are files */ - for (i = 1; i < argc - 2; i++) { - - /* stop looking for -o if "--" */ - if (strcmp(argv[i], "--") == 0) - break; - - if (strncmp(argv[i], "-o", 2) == 0) { - if (argv[i][2] == '\0') { - for (j = i; j < argc; j++) { - argv[j] = argv[j+1]; - } - argc--; - } else { - argv[i] += 2 + (int)strspn(&argv[i][2], " "); - } - - if (i == argc - 2) - Usage(); - - for (no = 0; (no < 2*CNFLD) && (i < argc - 2); no++) { - if (no > CNOFLD - 1) { - /* Get larger table for outlists */ - /* (CNOFLD is updated.) */ - get_olist(CNOFLD + NOFLD); - } - - if (strncmp(argv[i], "1.", 2) == 0) { - olistf[no] = F1; - olist[no] = (int)strtol(&argv[i][2], - (char **)NULL, 10); - nextargopt = 2 + (int) - strspn(&argv[i][2], "0123456789"); - } else if (strncmp(argv[i], "2.", 2) == 0) { - olistf[no] = F2; - olist[no] = (int)strtol(&argv[i][2], - (char **)NULL, 10); - nextargopt = 2 + (int) - strspn(&argv[i][2], "0123456789"); - } else if (argv[i][0] == '0') { - olistf[no] = JOINFIELD; - nextargopt = 1; - } else - break; - - if (olist[no] > CNFLD) - get_ppi(olist[no]); - - if (argv[i][nextargopt] == '\0') { - for (j = i; j < argc; j++) { - argv[j] = argv[j+1]; - } - argc--; - } else if ((argv[i][nextargopt] == ' ') || - (argv[i][nextargopt] == ',')) { - argv[i] += nextargopt + 1; - } else - Usage(); - } - } - } - - /* get other options */ - while ((opt = getopt(argc, argv, "1:2:a:e:j:t:v:")) != EOF) { - switch (opt) { - case '1': - j1 = (int)strtol(optarg, (char **)NULL, 10); - break; - - case '2': - j2 = (int)strtol(optarg, (char **)NULL, 10); - break; - - case 'a': - case 'v': - filenumber = (int)strtol(optarg, (char **)NULL, 10); - if ((filenumber != 1) && (filenumber != 2)) - Usage(); - - aflg |= filenumber; - if (opt == 'v') - vflg |= filenumber; - break; - - case 'e': - null = optarg; - break; - - case 'j': - j1 = j2 = (int)strtol(optarg, (char **)NULL, 10); - break; - - case 't': - tflg = 1; - (void) mbtowc(&sep1, optarg, MB_CUR_MAX); - sep2 = sep1; - break; - } - } - if (j1 > CNFLD || j2 > CNFLD) - get_ppi(max(j1, j2)); - - /* check options */ - if ((j1 > CNFLD) || (j2 > CNFLD) || (j1 <= 0) || (j2 <= 0)) { - (void) fprintf(stderr, gettext( - "join: bad join field number\n")); - Usage(); - } - - /* 0 origin */ - for (i = 0; i < no; i++) - olist[i]--; - j1--; - j2--; - - if (argc - optind != 2) - Usage(); - - if (strcmp(argv[optind], "-") == 0) - f[F1] = stdin; - else if ((f[F1] = fopen(argv[optind], "r")) == NULL) { - perror(argv[optind]); - exit(1); - } - - if (strcmp(argv[optind+1], "-") == 0) { - (void) strncpy(tmpfile, "/tmp/joinXXXXXX", 20); - if ((fd = mkstemp(tmpfile)) < 0) { - perror(gettext("join: cannot create tmpfile")); - exit(1); - } - if ((f[F2] = fdopen(fd, "w+")) == NULL) { - perror(gettext("join: cannot open tmpfile")); - exit(1); - } - /* tmpfile is automatically removed on exit */ - (void) unlink(tmpfile); - - while ((t = fread(buffer1, 1, BUFSIZ, stdin)) != 0) { - if ((fwrite(buffer1, 1, t, f[F2])) != t) { - (void) fprintf(stderr, gettext( - "join: cannot write to tmpfile\n")); - exit(1); - } - } - (void) fflush(f[F2]); - rewind(f[F2]); - } else if ((f[F2] = fopen(argv[optind+1], "r")) == NULL) { - perror(argv[optind+1]); - exit(1); - } - - /* set bottom mark on file2 */ - bot2 = ftello(f[F2]); - - /* input a line from each file */ - get1(); - get2(); - - /* while lines in both files or -a|v and lines in ether file */ - while (((n1 > 0) && (n2 > 0)) || ((aflg != 0) && ((n1 + n2) > 0))) { - - /* compare join fields */ - cmpresult = comp(); - - /* joinfiled1 > joinfield2 or file1 exasted */ - if (((n1 > 0) && (n2 > 0) && (cmpresult > 0)) || (n1 == 0)) { - - /* outputing unpaired ? */ - if (aflg & 2) - output(0, n2); - - /* mark bottom of file2 */ - bot2 = ftello(f[F2]); - - /* input line from file2 */ - get2(); - - /* joinfiled1 < joinfield2 or file2 exasted */ - } else if (((n1 > 0) && (n2 > 0) && (cmpresult < 0)) || - (n2 == 0)) { - - /* outputing unpaired ? */ - if (aflg & 1) - output(n1, 0); - - /* input line from file1 */ - get1(); - - /* line1 and line2 not empty and joinfield1 == joinfield2 */ - } else { - /* for lines in file2 that match join field */ - while (n2 > 0 && comp() == 0) { - - /* if not -v output line */ - if (!vflg) - output(n1, n2); - - /* mark top of file2 */ - top2 = ftello(f[F2]); - - /* input line from file2 */ - get2(); - } - - /* back to bottom line in file2 */ - (void) fseeko(f[F2], (off_t)bot2, SEEK_SET); - - /* input line form file1 and file2 */ - get2(); - get1(); - - for (;;) { - /* compare join fields */ - cmpresult = comp(); - - /* - * line1 and line2 not empty and - * joinfield1 == joinfield2 - */ - if (n1 > 0 && n2 > 0 && cmpresult == 0) { - - /* if not -v output line */ - if (!vflg) - output(n1, n2); - - /* input line from file2 */ - get2(); - - /* joinfiled1 < joinfield2 or file2 exasted */ - } else if (n1 > 0 && n2 > 0 && cmpresult < 0 || - n2 == 0) { - - /* seek to bottom of file2 */ - (void) fseeko(f[F2], (off_t)bot2, SEEK_SET); - - /* input line form file1 and file2 */ - get2(); - get1(); - - /* file1 exasted or joinfile1 > joinfield2 */ - } else { - /* seek to top of file2 */ - (void) fseeko(f[F2], (off_t)top2, SEEK_SET); - - /* set bottom at top */ - bot2 = top2; - - /* input line form file2 */ - get2(); - - break; - } - } - } - } - return (0); -} - - -static int -input(int n) /* get input line and split into fields */ -{ - int i, c; - wchar_t *bp; - wchar_t *tbp; - wchar_t **pp; - int nread; - - bp = buf[n]; - pp = ppi[n]; - - errno = 0; - if (fgetws(bp, CBUFSIZE[n], f[n]) == (wchar_t *)NULL) { - if (errno) { - perror("join"); - exit(1); - } - return (0); - } else { - if (errno == EILSEQ) { - (void) fprintf(stderr, gettext( - "join: invalid char following \"")); - (void) fputws(bp, stderr); - (void) fprintf(stderr, "\": "); - perror(""); - exit(1); - } else if (errno) { - perror("join"); - exit(1); - } - - /* Check for long lines */ - if (((wchar_t *)wcsrchr((wchar_t *)bp, L'\n') - == (wchar_t *)NULL) && (size_t)wcslen((wchar_t *)bp) - == (size_t)(CBUFSIZE[n] - 1)) { - tbp = bp; - nread = CBUFSIZE[n] - 1; - while ((wchar_t *)wcsrchr((wchar_t *)tbp, L'\n') - == (wchar_t *)NULL) { - /* Increase buffer by LINE_MAX */ - /* (CBUFSIZE[n] is updated.) */ - get_buf(n, CBUFSIZE[n] + LINE_MAX); - bp = buf[n]; - tbp = buf[n] + nread; - - /* Read rest of line */ - errno = 0; - if (fgetws(tbp, LINE_MAX + 1, f[n]) - == (wchar_t *)NULL) { - if (errno) { - perror("join"); - exit(1); - } - break; - } else if (errno == EILSEQ) { - (void) fprintf(stderr, gettext( - "join: invalid char following \"")); - (void) fputws(bp, stderr); - (void) fprintf(stderr, "\": "); - perror(""); - exit(1); - } else if (errno) { - perror("join"); - exit(1); - } - nread += (size_t)wcslen((wchar_t *)tbp); - } - } - } - - bp = buf[n]; - i = 0; - do { - i++; - /* Check for overflow of ppi[n] */ - if (i > CNFLD - 1) { /* account for 0 termination */ - /* Reallocate larger buffers (CNFLD is updated.) */ - get_ppi(CNFLD + NFLD); - /* Restore local pointer */ - pp = &ppi[n][i-1]; - } - if (!tflg) /* strip multiples */ - while ((c = *bp) == sep1 || c == sep2) { - bp++; /* skip blanks */ - } - *pp++ = bp; /* record beginning */ - while ((c = *bp) != sep1 && c != L'\n' && - c != sep2 && c != L'\0') { - bp++; - } - *bp++ = L'\0'; /* mark end by overwriting blank */ - } while ((c != L'\n') && (c != L'\0') && (pp != &ppi[n][CNFLD])); - - *pp = (wchar_t *)NULL; - - - return (i); -} - - -static void -output(on1, on2) /* print items from olist */ -int on1, on2; -{ - int i; - - if (no <= 0) { /* default case */ - if (on1) - putfield(ppi[F1][j1]); - else - putfield(ppi[F2][j2]); - for (i = 0; i < on1; i++) - if (i != j1) { - (void) putwchar(sep1); - putfield(ppi[F1][i]); - } - for (i = 0; i < on2; i++) - if (i != j2) { - (void) putwchar(sep1); - putfield(ppi[F2][i]); - } - (void) putwchar(L'\n'); - } else { - for (i = 0; i < no; i++) { - if (olistf[i] == F1 && on1 <= olist[i] || - olistf[i] == F2 && on2 <= olist[i]) { - (void) fputs(null, stdout); - } else if (olistf[i] == JOINFIELD) { - if (on1) - putfield(ppi[F1][j1]); - else - putfield(ppi[F2][j2]); - } else - putfield(ppi[olistf[i]][olist[i]]); - - if (i < no - 1) -#if defined(__lint) /* lint doesn't grok "%wc" */ - /* EMPTY */; -#else - (void) printf("%wc", sep1); -#endif - else - (void) putwchar(L'\n'); - } - } -} - - -static int -cmp(s1, s2) -wchar_t *s1, *s2; -{ - int rc; - - if (s1 == (wchar_t *)NULL) { - if (s2 == (wchar_t *)NULL) - rc = 0; - else - rc = -1; - } else if (s2 == (wchar_t *)NULL) - rc = 1; - else - rc = wscoll(s1, s2); - - return (rc); -} - - -static void -Usage() -{ - (void) fprintf(stderr, gettext( - "usage: join [-a file_number | -v file_number] [-o list [-e string]]\n" - " [-t char] [-1 field] [-2 field] file1 file2\n\n" - " join [-a file_number] [-j field] [-j1 field] [-j2 field]\n" - " [-o list [-e string]] [-t char] file1 file2\n")); - exit(1); -} - -/* - * Allocate memory for buffers. - */ -static void -init_buf() -{ - (void) get_buf(F1, LINE_MAX); - (void) get_buf(F2, LINE_MAX); - (void) get_ppi(NFLD); - (void) get_olist(NOFLD); -} - - -static void -get_ppi(nfld) -int nfld; -{ - int i; - - for (i = 0; i < 2; i++) { - if (ppi[i]) { - if ((ppi[i] = (wchar_t **)realloc((char *)ppi[i], - (unsigned)(nfld * sizeof (wchar_t *)))) - == NULL) { - (void) fprintf(stderr, - gettext("realloc pointer table failed\n")); - exit(1); - } - } else { - if ((ppi[i] = (wchar_t **)calloc((unsigned)nfld, - (unsigned)sizeof (wchar_t *))) == NULL) { - (void) fprintf(stderr, - gettext("calloc pointer table failed\n")); - exit(1); - } - } - } - - CNFLD = nfld; -} - - -static void -get_buf(i, size) -int i; -int size; -{ - if (buf[i]) { - if ((buf[i] = (wchar_t *) - realloc(buf[i], (unsigned)(size * sizeof (wchar_t)))) - == NULL) { - (void) fprintf(stderr, - gettext("realloc input buffer failed\n")); - exit(1); - } - } else { - if ((buf[i] = (wchar_t *) - calloc((unsigned)size, (unsigned)sizeof (wchar_t))) - == NULL) { - (void) fprintf(stderr, - gettext("calloc input buffer failed\n")); - exit(1); - } - } - - CBUFSIZE[i] = size; -} - - -static void -get_olist(onfld) -int onfld; -{ - if (olist) { - if ((olist = (int *)realloc((wchar_t *)olist, - (unsigned)(onfld * sizeof (int)))) == NULL) { - (void) fprintf(stderr, - gettext("realloc olist failed\n")); - exit(1); - } - } else { - if ((olist = (int *) - calloc((unsigned)onfld, (unsigned)sizeof (int))) - == NULL) { - (void) fprintf(stderr, - gettext("calloc olist failed\n")); - exit(1); - } - } - - if (olistf) { - if ((olistf = (int *)realloc((wchar_t *)olistf, - (unsigned)(onfld * sizeof (int)))) == NULL) { - (void) fprintf(stderr, - gettext("realloc olistf failed\n")); - exit(1); - } - } else { - if ((olistf = (int *) - calloc((unsigned)onfld, (unsigned)sizeof (int))) - == NULL) { - (void) fprintf(stderr, gettext("calloc olistf failed\n")); - exit(1); - } - } - - CNOFLD = onfld; -} diff --git a/usr/src/cmd/join/join.xcl b/usr/src/cmd/join/join.xcl deleted file mode 100644 index 88053f2ce7..0000000000 --- a/usr/src/cmd/join/join.xcl +++ /dev/null @@ -1,26 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -msgid "" -msgid "%wc" -msgid "\n" -msgid "join: " -msgid "r" diff --git a/usr/src/cmd/ksh/Makefile.testshell b/usr/src/cmd/ksh/Makefile.testshell index fdad066a57..ef520d4d04 100644 --- a/usr/src/cmd/ksh/Makefile.testshell +++ b/usr/src/cmd/ksh/Makefile.testshell @@ -20,7 +20,7 @@ # # -# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # @@ -101,7 +101,7 @@ testshell: $(PROG) printf "# which ksh='%s', ksh93='%s'\n" \ "$$(which ksh)" "$$(which ksh93)" ; \ ) ; \ - if [[ "$$(isalist)" != ~(E)$(LIBSHELLMACH) ]] ; then \ + if [[ "$$(isalist)" != ~(F)$(LIBSHELLMACH) ]] ; then \ printf \ "# ISA='%s' not available on this system, skipping tests...\n" \ "$(LIBSHELLMACH)" ; \ @@ -135,6 +135,7 @@ testshell: $(PROG) "$$(basename "$${test_item}")" \ "$${mode%:*}"; \ ( \ + ulimit -s 65536 ; \ test_output="$$( ( \ export \ SHELL="$(SRC)/cmd/ksh/$(LIBSHELLMACH)/ksh" \ diff --git a/usr/src/cmd/ksh/builtins/Makefile b/usr/src/cmd/ksh/builtins/Makefile index fcc92f323e..52808250c7 100644 --- a/usr/src/cmd/ksh/builtins/Makefile +++ b/usr/src/cmd/ksh/builtins/Makefile @@ -30,29 +30,43 @@ PROG= alias ALIASPROG= \ bg \ cd \ + cksum \ + cmp \ + comm \ command \ + cut \ fc \ fg \ getopts \ hash \ jobs \ + join \ kill \ + logname \ + paste \ + print \ read \ rev \ sleep \ sum \ + tee \ test \ type \ ulimit \ umask \ unalias \ - wait + uniq \ + wait \ + wc include ../../Makefile.cmd +$(SPARC_BLD)include ../../Makefile.cmd.64 ROOTALIASPROG= $(ALIASPROG:%=$(ROOTBIN)/%) FILEMODE= 555 +OWNER= root +GROUP= bin .KEEP_STATE: @@ -61,8 +75,6 @@ all: $(PROG) $(ROOTBIN)/%: $(ROOTBIN)/alias $(INS.link) -include ../../Makefile.cmd - .KEEP_STATE: # Set common AST build flags (e.g., needed to support the math stuff). @@ -73,11 +85,19 @@ OBJECTS= \ SRCS= $(OBJECTS:%.o=%.c) -LDLIBS += -lshell -last +GROUP= bin +LDLIBS += -lshell -lcmd -last CPPFLAGS = \ $(DTEXTDOM) $(DTS_ERRNO) \ - -I$(ROOT)/usr/include/ast + -I$(ROOT)/usr/include/ast \ + -I$(ROOT)/usr/include + +# Enable workaround for a crash in /usr/bin/alias when invalid +# options are passed (e.g. $ /usr/bin/alias -c #). The shell +# code will call an error handler which does a |longjmp()| but +# somehow the code failed to do the |setjmp()| before this point. +CPPFLAGS += -DWORKAROUND_FOR_ALIAS_CRASH CFLAGS += \ $(ASTCFLAGS) diff --git a/usr/src/cmd/ksh/builtins/alias.c b/usr/src/cmd/ksh/builtins/alias.c index b477d7353c..dd789ef844 100644 --- a/usr/src/cmd/ksh/builtins/alias.c +++ b/usr/src/cmd/ksh/builtins/alias.c @@ -33,8 +33,122 @@ #include <shell.h> #include <nval.h> +#include <cmdext.h> #include <stdio.h> +typedef struct { + const char *name; + int (* func)(int, char **, void *); +} bfastpathrec; + +/* + * We've disabled the "fastpath" codepath for some commands below + * because it causes a paradoxon for large input files (as used by + * ON PerfPIT for testing). For /usr/bin/rev (where the issue was + * first discovered) it looks like this: + * - for small files like /etc/profile the fastpath is faster in a loop + * with 1000 iterations (8 seconds with fastpath, 14 seconds without + * fastpath) + * - for large files (/usr/pub/UTF-8 replicated until the test file + * reaches 24884706 bytes) the benchmark reverses: The fastpath now + * needs 40 seconds and without fastpath it needs 30 seconds (for 100 + * iterations). + */ +#if 0 +#define ENABLE_PERFORMANCE_PARADOXON 1 +#endif + +/* + * List of libcmd builtins which do not require a |Shell_t| context. + * This list was automatically generated from <ast/cmdext.h> + */ +static const +bfastpathrec fastpath_builtins[] = +{ + /* This list must be alphabetically sorted for |strcmp()| usage */ + { "basename", b_basename }, + { "cat", b_cat }, + { "chgrp", b_chgrp }, + { "chmod", b_chmod }, + { "chown", b_chown }, +#ifdef ENABLE_PERFORMANCE_PARADOXON + { "cksum", b_cksum }, +#endif /* ENABLE_PERFORMANCE_PARADOXON */ + { "cmp", b_cmp }, + { "comm", b_comm }, + { "cp", b_cp }, + { "cut", b_cut }, + { "date", b_date }, + { "dirname", b_dirname }, + { "egrep", b_egrep }, + { "expr", b_expr }, + { "fds", b_fds }, + { "fgrep", b_fgrep }, + { "fmt", b_fmt }, + { "fold", b_fold }, + { "getconf", b_getconf }, + { "grep", b_grep }, + { "head", b_head }, + { "id", b_id }, + { "join", b_join }, + { "ln", b_ln }, + { "logname", b_logname }, + { "md5sum", b_md5sum }, + { "mkdir", b_mkdir }, + { "mkfifo", b_mkfifo }, + { "mktemp", b_mktemp }, + { "mv", b_mv }, + { "paste", b_paste }, + { "pathchk", b_pathchk }, + { "pids", b_pids }, + { "readlink", b_readlink }, +#ifdef ENABLE_PERFORMANCE_PARADOXON + { "rev", b_rev }, +#endif /* ENABLE_PERFORMANCE_PARADOXON */ + { "rm", b_rm }, + { "rmdir", b_rmdir }, + { "stty", b_stty }, +#ifdef ENABLE_PERFORMANCE_PARADOXON + { "sum", b_sum }, +#endif /* ENABLE_PERFORMANCE_PARADOXON */ + { "sync", b_sync }, + { "tail", b_tail }, + { "tee", b_tee }, + { "tty", b_tty }, + { "uname", b_uname }, + { "uniq", b_uniq }, + { "wc", b_wc }, + { "xgrep", b_xgrep }, + { NULL, (int (*)(int, char **, void *))NULL } +}; + +static inline +const bfastpathrec * +find_bfastpathrec(const char *name) +{ + unsigned int i; + signed int cmpres; + for (i = 0; fastpath_builtins[i].name != NULL; i++) { + cmpres = strcmp(fastpath_builtins[i].name, name); + if (cmpres == 0) + return (&fastpath_builtins[i]); + else if (cmpres > 0) + return (NULL); + + } + return (NULL); +} + +static inline +int +fastpath_builtin_main(const bfastpathrec *brec, int argc, char *argv[]) +{ + setlocale(LC_ALL, ""); /* calls |_ast_setlocale()| */ + + return ((*brec->func)(argc, argv, NULL)); +} + + /* Builtin script, original derived from alias.sh */ static const char *script = "\n" /* Get name of builtin */ @@ -58,12 +172,27 @@ static const char *script = "\n" "if [[ \"${cmd}\" == \"command\" ]] ; then\n" "command \"$@\"\n" "else\n" +#ifdef WORKAROUND_FOR_ALIAS_CRASH +/* + * Work around a crash in /usr/bin/alias when invalid options are + * passed (e.g. $ /usr/bin/alias -c #). The shell code will call + * an error handler which does a |longjmp()| but somehow the code + * failed to do the |setjmp()| before this point. + * Putting the "alias" command in a subshell avoids the crash. + * Real cause of the issue is under investigation and a fix be + * delivered with the next ast-ksh update. + */ + "( \"${cmd}\" \"$@\" )\n" +#else "\"${cmd}\" \"$@\"\n" +#endif /* WORKAROUND_FOR_ALIAS_CRASH */ "fi\n" "exitval=$?"; + +static inline int -main(int argc, char *argv[]) +script_builtin_main(int argc, char *argv[]) { int i; Shell_t *shp; @@ -98,3 +227,35 @@ main(int argc, char *argv[]) return (exitval); } + +int +main(int argc, char *argv[]) +{ + const char *progname; + const bfastpathrec *brec; + char execnamebuff[PATH_MAX+1]; + + /* Get program name */ + if (pathprog(argv[0], execnamebuff, sizeof (execnamebuff)) <= 0) + error(ERROR_exit(1), "could not determinate exec name."); + + progname = (const char *)strrchr(execnamebuff, '/'); + if (progname != NULL) { + progname++; + } + else + { + progname = execnamebuff; + } + + /* Execute command... */ + if (brec = find_bfastpathrec(progname)) { + /* ... either via a fast path (calling the code directly) ... */ + return (fastpath_builtin_main(brec, argc, argv)); + } + else + { + /* ... or from within a full shell. */ + return (script_builtin_main(argc, argv)); + } +} diff --git a/usr/src/cmd/logname/Makefile b/usr/src/cmd/logname/Makefile deleted file mode 100644 index 74bdddb5f8..0000000000 --- a/usr/src/cmd/logname/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -PROG= logname - -include ../Makefile.cmd - -CFLAGS += $(CCVERBOSE) - -.KEEP_STATE: - -all: $(PROG) - -install: all $(ROOTPROG) - -clean: - -lint: lint_PROG - -include ../Makefile.targ diff --git a/usr/src/cmd/logname/logname.c b/usr/src/cmd/logname/logname.c deleted file mode 100644 index 62c895ea94..0000000000 --- a/usr/src/cmd/logname/logname.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (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 2005 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <unistd.h> -#include <libintl.h> -#include <locale.h> -#include <stdio.h> - -int -main(void) -{ - char *name; - - (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); - - if ((name = getlogin()) == NULL) - return (1); - (void) puts(name); - return (0); -} diff --git a/usr/src/cmd/nsadmin/ksh.kshrc b/usr/src/cmd/nsadmin/ksh.kshrc index 10da11dbfe..ea3826223d 100644 --- a/usr/src/cmd/nsadmin/ksh.kshrc +++ b/usr/src/cmd/nsadmin/ksh.kshrc @@ -20,7 +20,7 @@ # # -# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # @@ -35,6 +35,8 @@ if [[ "$(set +o)" != ~(Er)--(gmacs|emacs|vi)( .*|) ]] ; then set -o gmacs # enable multiline input mode set -o multiline + # enable globstar mode (match subdirs with **/) + set -o globstar fi # Set a default prompt (<username>@<hostname>:<path><"($|#) ">) if @@ -66,10 +68,12 @@ fi # - Make sure to use absolute paths (e.g. /usr/bin/hostname) to make # sure PS1 works in cases where PATH does not contain /usr/bin/ if [[ "$(set)" != ~(E)PS1= && "${PS1}" == '' ]] ; then - PS1='$(printf "%*s\r%s" COLUMNS "")${LOGNAME}@$(/usr/bin/hostname):$( - ellip="$( + PS1='$(set +o xtrace +o errexit + printf "%*s\r%s" COLUMNS "" + printf "%s@%s:" "${LOGNAME}" "$(/usr/bin/hostname)" + ellip="${ [[ "${LC_ALL}/${LANG}" == ~(Elr)(.*UTF-8/.*|/.*UTF-8) ]] && - printf "\u[2026]\n" || print "..." )" + printf "\u[2026]\n" || print "..." ; }" p="${PWD/~(El)${HOME}/\~}" (( ${#p} > 30 )) && print -r -n -- "${ellip}${p:${#p}-30:30}" || diff --git a/usr/src/cmd/paste/Makefile b/usr/src/cmd/paste/Makefile deleted file mode 100644 index 13e884af1d..0000000000 --- a/usr/src/cmd/paste/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright (c) 1989,1996 by Sun Microsystems, Inc. -# All rights reserved. -# - -PROG= paste - -include ../Makefile.cmd - -XGETFLAGS += -a -x $(PROG).xcl -CPPFLAGS += -D_FILE_OFFSET_BITS=64 - -.KEEP_STATE: - -all: $(PROG) - -install: all $(ROOTPROG) - -clean: - -lint: lint_PROG - -include ../Makefile.targ diff --git a/usr/src/cmd/paste/paste.c b/usr/src/cmd/paste/paste.c deleted file mode 100644 index 14fc096b0e..0000000000 --- a/usr/src/cmd/paste/paste.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (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 1994 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* - * Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T - * All Rights Reserved - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -#include <stdio.h> -#include <locale.h> -#include <widec.h> -#include <stdlib.h> -#include <limits.h> - - -#define MAXOPNF 12 /* maximal no. of open files (not with -s option) */ -#define MAXOPNF_STR "12" -#define RUB '\177' - - -/* - * Function prototypes - */ -static void diag(char *, char *); -static int move(char *, wchar_t *); -static void usage(); - -int -main(int argc, char **argv) -{ - int i, j, k, eofcount, nfiles, maxline, glue; - int delcount = 1; - int onefile = 0; - register int c; - wchar_t del[LINE_MAX]; - wchar_t outbuf[LINE_MAX], l, t; - register wchar_t *p; - FILE *inptr[MAXOPNF]; - int arg_ind; - int file_ind; - int error = 0; - - - /* Get locale variables from environment */ - (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); - - del[0] = '\t'; - maxline = LINE_MAX -2; - - /* Get command arguments */ - while ((c = getopt(argc, argv, "d:s")) != EOF) { - switch (c) { - case 'd' : - delcount = move(optarg, del); - if (delcount < 1) - diag("paste: no delimiters\n", NULL); - break; - - case 's' : - onefile++; - break; - - case '?': - usage(); - - /* NOTREACHED */ - break; - } - } - - if (!onefile) { /* not -s option: parallel line merging */ - - /* Find explicit stdin and file names */ - for (file_ind = 0, arg_ind = optind; arg_ind < argc && - file_ind < MAXOPNF; arg_ind++) { - if (argv[arg_ind][0] == '-' && - argv[arg_ind][1] == '\0') { - inptr[file_ind++] = stdin; - } else if (arg_ind >= optind) { - inptr[file_ind++] = fopen(argv[arg_ind], "r"); - if (inptr[file_ind -1] == NULL) { - diag("paste: cannot open %s\n", - argv[arg_ind]); - } - } - } - if (arg_ind < argc) { - char maxopnf_buf[LINE_MAX]; - (void) sprintf(maxopnf_buf, "%d", MAXOPNF); - diag("paste: too many files- limit %s\n", maxopnf_buf); - } - nfiles = file_ind; - - do { - p = &outbuf[0]; - eofcount = 0; - j = k = 0; - for (i = 0; i < nfiles; i++) { - while ((c = fgetwc(inptr[i])) != '\n' && - c != EOF) { - if (++j <= maxline) - *p++ = c; - else { - diag( - "paste: line too long\n", - NULL); - } - } - if ((l = del[k]) != RUB) - *p++ = l; - - k = (k + 1) % delcount; - - if (c == EOF) - eofcount++; - } - if (l != RUB) - *--p = '\n'; - else - *p = '\n'; - *++p = 0; - if (eofcount < nfiles) - (void) printf("%ws", outbuf); - } while (eofcount < nfiles); - - } else { /* -s option: serial file pasting (old 127 paste command) */ - - for (i = optind; i < argc; i++) { - p = &outbuf[0]; - glue = 0; - j = 0; - k = 0; - t = 0; - if (argv[i][0] == '-' && - argv[i][1] == '\0') { - inptr[0] = stdin; - } else if (i >= optind) { - inptr[0] = fopen(argv[i], "r"); - if (inptr[0] == NULL) { - (void) fprintf(stderr, gettext( - "paste: cannot open %s\n"), argv[i]); - error = 1; - } - } - - /* Argument not a file name */ - if (inptr[0] == NULL) { - continue; - } - - while ((c = fgetwc(inptr[0])) != EOF) { - if (j >= maxline) { - t = *--p; - *++p = 0; - (void) printf("%ws", outbuf); - p = &outbuf[0]; - j = 0; - } - if (glue) { - glue = 0; - l = del[k]; - if (l != RUB) { - *p++ = l; - t = l; - j++; - } - k = (k + 1) % delcount; - } - if (c != '\n') { - *p++ = c; - t = c; - j++; - } else glue++; - } - if (t != '\n') { - *p++ = '\n'; - j++; - } - if (j > 0) { - *p = 0; - (void) printf("%ws", outbuf); - } - } - } - return (error); -} - - -static void -diag(char *s, char *arg) -{ - (void) fprintf(stderr, gettext(s), arg); - exit(1); -} - - -static int -move(char *from, wchar_t *to) -{ - int i, n; - wchar_t wc; - - i = 0; - while (*from) { - n = mbtowc(&wc, from, MB_CUR_MAX); - if (n <= 0) - return (0); /* invalid character as a delimiter */ - from += n; - if (wc != L'\\') *to++ = wc; - else { - n = mbtowc(&wc, from, MB_CUR_MAX); - if (n <= 0) - return (0); - from += n; - switch (wc) { - case L'0' : *to++ = RUB; - break; - case L't' : *to++ = L'\t'; - break; - case L'n' : *to++ = L'\n'; - break; - default : *to++ = wc; - break; - } - } - i++; - } - return (i); -} - - -static void -usage() -{ - (void) fprintf(stderr, gettext( - "usage: paste [-s] [-d list] file \n\n")); - exit(1); -} diff --git a/usr/src/cmd/paste/paste.xcl b/usr/src/cmd/paste/paste.xcl deleted file mode 100644 index b2c15d5201..0000000000 --- a/usr/src/cmd/paste/paste.xcl +++ /dev/null @@ -1,24 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -msgid "" -msgid "%ws" -msgid "r" diff --git a/usr/src/cmd/shcomp/Makefile b/usr/src/cmd/shcomp/Makefile index a75aa1669e..1e2e774413 100644 --- a/usr/src/cmd/shcomp/Makefile +++ b/usr/src/cmd/shcomp/Makefile @@ -27,6 +27,7 @@ SHELL=/usr/bin/ksh93 include ../Makefile.cmd +$(SPARC_BLD)include ../Makefile.cmd.64 .KEEP_STATE: @@ -42,6 +43,7 @@ LIBSHELLSRC=$(LIBSHELLBASE)/common/sh SRCS= $(OBJECTS:%.o=$(LIBSHELLSRC)/%.c) +GROUP= bin LDLIBS += -lshell -last # 1. Make sure that the -D/-U defines in CFLAGS below are in sync diff --git a/usr/src/cmd/tee/Makefile b/usr/src/cmd/tee/Makefile deleted file mode 100644 index a123f8fdc6..0000000000 --- a/usr/src/cmd/tee/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -PROG= tee - -include ../Makefile.cmd - -CFLAGS += $(CCVERBOSE) -CPPFLAGS += -D_FILE_OFFSET_BITS=64 - -# -# For messaging catalogue file -XGETFLAGS += -a -x tee.xcl - -.KEEP_STATE: - -all: $(PROG) - -install: all $(ROOTPROG) - -clean: - -lint: lint_PROG - -include ../Makefile.targ diff --git a/usr/src/cmd/tee/tee.c b/usr/src/cmd/tee/tee.c deleted file mode 100644 index 954a4fd2ce..0000000000 --- a/usr/src/cmd/tee/tee.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (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 2005 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * tee - pipe fitting - */ - -#include <stdlib.h> -#include <limits.h> -#include <signal.h> -#include <unistd.h> -#include <stdio.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <locale.h> - -#define min(a, b) ((a) > (b) ? (b) : (a)) -#define MAXFILES 20 - -static void stash(int); - -static int ofiles = 0; -static int ispipe = 0; /* output goes to pipe or special file */ -static int openf[MAXFILES] = { 1 }; -static char in[PIPE_BUF]; -static const char *usage = "usage: tee [-ai] [file...]\n"; - -int -main(int argc, char **argv) -{ - int w; - int c; - int aflag = 0; - int errorcode = 0; - struct stat buf; - - - (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 ((c = getopt(argc, argv, "ai")) != EOF) { - switch (c) { - case 'a': - aflag++; - break; - case 'i': - (void) signal(SIGINT, SIG_IGN); - break; - case '?': - (void) fprintf(stderr, gettext(usage)); - exit(1); - } - } - argc -= optind; - argv = &argv[optind]; - - (void) fstat(1, &buf); - if (S_ISFIFO(buf.st_mode) || S_ISCHR(buf.st_mode)) - ispipe++; - - openf[ofiles++] = 1; - while (argc-- > 0 && ofiles < MAXFILES) { - openf[ofiles] = open(argv[0], - O_WRONLY|O_CREAT|(aflag ? O_APPEND:O_TRUNC), 0666); - if (openf[ofiles] < 0) { - (void) fprintf(stderr, "tee: "); - perror(argv[0]); - errorcode++; - } else { - if (fstat(openf[ofiles], &buf) >= 0) { - if (S_ISCHR(buf.st_mode)) - ispipe++; - ofiles++; - } else { - (void) fprintf(stderr, "tee: "); - perror(argv[0]); - errorcode++; - } - } - argv++; - } - if (argc >= 0 && ofiles >= MAXFILES) { - argv--; - (void) fprintf(stderr, gettext("tee: too many input files; " - "ignoring file(s) listed after %s\n"), argv[0]); - errorcode++; - } - - while ((w = read(0, in, PIPE_BUF)) > 0) - stash(w); - if (w < 0) { - (void) fprintf(stderr, gettext("tee: read error on input\n")); - exit(1); - } - return (errorcode); -} - -static void -stash(int nbytes) -{ - register int k, i, chunk, nb; - - chunk = ispipe ? PIPE_BUF : nbytes; - for (i = 0; i < nbytes; i += chunk) { - nb = min(chunk, nbytes - i); - for (k = 0; k < ofiles; k++) - (void) write(openf[k], in+i, nb); - } -} diff --git a/usr/src/cmd/tee/tee.xcl b/usr/src/cmd/tee/tee.xcl deleted file mode 100644 index 5d8634ce8b..0000000000 --- a/usr/src/cmd/tee/tee.xcl +++ /dev/null @@ -1,23 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -msgid "" -msgid "ai" diff --git a/usr/src/cmd/uniq/Makefile b/usr/src/cmd/uniq/Makefile deleted file mode 100644 index ad0e2aed3a..0000000000 --- a/usr/src/cmd/uniq/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright 2004 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -PROG= uniq - -include ../Makefile.cmd - -CFLAGS += $(CCVERBOSE) - -XGETFLAGS += -a -x uniq.xcl -.KEEP_STATE: - -all: $(PROG) - -install: all $(ROOTPROG) - -clean: - -lint: lint_PROG - -include ../Makefile.targ diff --git a/usr/src/cmd/uniq/uniq.c b/usr/src/cmd/uniq/uniq.c deleted file mode 100644 index 0f9ae1ca32..0000000000 --- a/usr/src/cmd/uniq/uniq.c +++ /dev/null @@ -1,642 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (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 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ - -/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * uniq: delete repeated lines within a file. - * - * uniq [-c|-d|-u][-f fields][-s char] [input_file [output_file]] - * OR: - * uniq [-c|-d|-u][-n][+m] [input_file [output_file]] - */ - -#include <stdio.h> -#include <ctype.h> -#include <locale.h> -#include <stdlib.h> -#include <libintl.h> -#include <string.h> -#include <wchar.h> -#include <wctype.h> - -#define isWblank(c) \ - ((c == 0x09 || c == 0x20) ? 1 : (iswctype((c), _ISBLANK|_ISSPACE))) - - -#define BLOCKSIZE 1000 /* How much line buffer to allocate at a time */ - -static int mcount = 0; /* # of mutually exclusive flags used */ -static int fields = 0; /* # of fields to be ignored */ -static int letters = 0; /* # of letters to be ignored */ -static int linec; -static char mode; /* = [c, d, u] */ -static int uniq; -static int mac; /* our modified argc, after parseargs() */ -static char **mav; /* our modified argv, after parseargs() */ -static char *skip(); - -/* - * according to spec 1170 (draft April 8, 1994), there are two - * ways to use uniq; and both ways are mutually exclusive. we use modeflag - * to insure that the user doesn't mix these mutually exclusive flags. - * if the [-f -s] flags are used, modeflag should be 1. if [-n +m] are - * used, then modeflag should be 2. so the possible values for modeflag are: - * 0: [-f,-s] && [-n, +m] weren't specified. default to XBD. - * 1: either -f or -s was specified. XBD specification. - * 2: either -n or +m was specified. obsolescent usage. - */ -#define MODEFLAG_FS 1 /* modeflag bits: -f or -s was specified */ -#define MODEFLAG_NM 2 /* modeflag bits: -n or _m was specified */ - -static int modeflag = 0; /* 0,1 = XBD spec. 2 = Obsolescent usage */ - - -static char usage0[] = "uniq [-c|-d|-u][-f fields][-s char]"; -static char usage1[] = "uniq [-c|-d|-u][-n][+m]"; - -static void printe(); -static int gline(char **buf, int *size); -static void pline(char *buf); -static int equal(char *b1, char *b2); -static void parseargs(int ac, char **av); -static void usage(); - - -int -main(int argc, char *argv[]) -{ - int c; /* for getopt(3C) parsing */ - char *b1 = NULL, *b2 = NULL; - int b1size = BLOCKSIZE, b2size = BLOCKSIZE; - FILE *temp; - - (void) setlocale(LC_ALL, ""); -#if !defined(TEXT_DOMAIN) -#define TEXT_DOMAIN "SYS_TEST" -#endif - (void) textdomain(TEXT_DOMAIN); - - if ((b1 = ((char *) malloc((unsigned) BLOCKSIZE))) == NULL || (b2 = - ((char *) malloc((unsigned) BLOCKSIZE))) == NULL) - printe(gettext("out of memory\n"), ""); - - parseargs(argc, argv); /* reformat all arguments for getopt */ - - /* handle all of uniq's arguments via getopt(3C): */ - while ((c = getopt(mac, mav, "n:m:cduf:s:")) != EOF) { - switch (c) { - case 'n': /* parseargs() psuedo argument for -# */ - modeflag |= MODEFLAG_NM; - fields = atoi(optarg); - break; - - case 'm': /* parseargs() psuedo argument for +# */ - modeflag |= MODEFLAG_NM; - letters = atoi(optarg); - break; - - case 'c': /* -c: precede output lines */ - /* FALLTHROUGH! */ - case 'd': /* -d: suppress non-repeated lines */ - /* FALLTHROUGH! */ - case 'u': /* -u: suppress repeated lines */ - mcount++; - mode = c; - break; - - case 'f': /* -f: ignore 1st fields on input lines */ - modeflag |= MODEFLAG_FS; - if (isdigit((unsigned char)*optarg) != 0) { - fields = atoi(optarg); - } else { - (void) fprintf(stderr, "uniq -f: %s: %s\n", - gettext("bad fields value"), optarg); - usage(); - exit(1); - } - break; - - case 's': /* -s: ignore 1st chars on comparisons */ - modeflag |= MODEFLAG_FS; - if (isdigit((unsigned char)*optarg) != 0) { - letters = atoi(optarg); - } else { - (void) fprintf(stderr, "uniq -s: %s: %s\n", - gettext("bad fields value"), optarg); - usage(); - exit(1); - } - break; - - default: - usage(); - exit(2); - break; - } - } - - /* see if we have any mutually exclusive options: */ - if (mcount > 1) { - (void) fprintf(stderr, - gettext("Mutually exclusive options were given!\n")); - usage(); - exit(3); - } - - /* see if the user mixed the old style usage with the new: */ - if (modeflag > MODEFLAG_NM) { - (void) fprintf(stderr, gettext( - "Mutually exclusive command lines arguments!\n")); - usage(); - exit(4); - } - - /* if there are more arguments than getopt(3C) handled: */ - if (mav[optind] != (char *) NULL) { - /* if the user specified an input filename: */ - if (*mav[optind] != (char) NULL) { - /* if the user didn't specify stdin: */ - if (strcmp(mav[optind], "-") != 0) { - if ((temp = fopen(mav[optind], "r")) == NULL) { - printe(gettext("cannot open %s\n"), - mav[optind]); - } - - (void) fclose(temp); - (void) freopen(mav[optind], "r", stdin); - } - } - - /* if the user specified an output filename: */ - if ((mav[optind + 1] != (char *) NULL) && - (*mav[optind + 1] != (char) NULL)) { - if (freopen(mav[optind + 1], "w", stdout) == NULL) { - printe(gettext("cannot create %s\n"), - mav[optind + 1]); - } - } - } - - if (gline(&b1, &b1size)) - exit(0); - for (; ; ) { - linec++; - if (gline(&b2, &b2size)) { - pline(b1); - exit(0); - } - if (!equal(b1, b2)) { - pline(b1); - linec = 0; - do { - linec++; - if (gline(&b1, &b1size)) { - pline(b2); - exit(0); - } - } while (equal(b1, b2)); - pline(b2); - linec = 0; - } - } -} - -/* - * Get an input line, dynamically growing the buffer as necessary. - */ -static int -gline(buf, size) -char **buf; -int *size; -{ - register int c, left = *size; - register char *input = *buf; - - while ((c = getchar()) != '\n') - { - if (c == EOF) - return (1); - - *input++ = c; - if (--left == 0) - { - *buf = (char *) realloc(*buf, *size + BLOCKSIZE); - if (*buf == NULL) - printe(gettext("out of memory\n"), ""); - - input = (*buf) + *size; - left = BLOCKSIZE; - *size += BLOCKSIZE; - } - } - - *input = '\0'; - return (0); -} - -static void -pline(buf) -register char buf[]; -{ - - switch (mode) { - - case 'u': - if (uniq) { - uniq = 0; - return; - } - break; - - case 'd': - if (uniq) break; - return; - - case 'c': - (void) printf("%4d ", linec); - } - uniq = 0; - (void) fputs(buf, stdout); - (void) putchar('\n'); -} - -/* - * equal: see if two strings are the same, accounting for any skipping. - * similar to strcmp(), except that we call skip() first. - * output: 1 if the strings are the same. 0 otherwise. - */ -static int -equal(b1, b2) -register char b1[], b2[]; -{ - b1 = skip(b1); - b2 = skip(b2); - - if (strcmp(b1, b2) == 0) { /* if they're the same, */ - uniq++; - return (1); - } - - return (0); -} - -char * -skip(char *s) -{ - int nf, nl; - int clen; /* # bytes which comprise a mb char */ - wchar_t wc; /* the xlated version of each mb char */ - - nf = nl = 0; - - /* - * we want to skip all user-specified fields first, and then - * any specified characters. so while there're fields to be - * skipped, examine each (possible m.b.) char. for each field, - * we first skip all blanks. then we skip any non-blank chars. - */ - - while (nf++ < fields) { - /* skip blank characters (s.b. or m.b) */ - clen = mbtowc(&wc, s, MB_CUR_MAX); - while ((clen > 0) && isWblank(wc)) { - s += clen; - clen = mbtowc(&wc, s, MB_CUR_MAX); - } - - if (clen == -1) { - /* - * illegal char found - * treat it as a non-blank single byte char - */ - s++; - clen = mbtowc(&wc, s, MB_CUR_MAX); - } else if (clen == 0) { - /* EOL found */ - break; - } - - /* skip non-blank and illegal characters */ - while (((clen > 0) && !isWblank(wc)) || - (clen == -1)) { - s += clen > 0 ? clen : 1; - clen = mbtowc(&wc, s, MB_CUR_MAX); - } - - /* if we've encountered EOL */ - if (clen == 0) { - break; - } - } - - /* - * skip all user-specified letters, s.b. or m.b. - */ - - while (nl++ < letters) { - clen = mbtowc(&wc, s, MB_CUR_MAX); - - /* if we've encountered EOL */ - if (clen == 0) { - break; - } - s += clen > 0 ? clen : 1; - - } - return (s); -} - -static void -printe(p, s) -char *p, *s; -{ - (void) fprintf(stderr, p, s); - exit(1); -} - - - -/* - * parseargs(): modify the args - * this routine is used to transform all arguments into a format - * which is acceptable to getopt(3C), and which retains backwards - * Solaris 2.[0-4] compatibility. - * - * This routine allows us to make full use of getopts, without any - * funny argument processing in main(). - * - * The other alternative would be to hand-craft the processed arguments - * during and after getopt(3C) - which usually leads to uglier code - * in main(). I've opted to keep the ugliness isolated down here, - * instead of in main(). - * - * We leave the following arguments unchanged: - * [-c | -d | -u], [-f fields] [-s char]. - * - * We modify the following arguments: - * -# (a.k.a. -n) to "-n #" - * +# (a.k.a. +n) to "-m #" - * - * E.g. -3 gets changed to the psuedo argument "-n 3". - * - * N.B.: we *DON'T* map -# to -f, nor +# to -s, as -/+ usage is - * mutually exclusive with -f & -s according to the - * spec 1170 man page. - * - * Anything after the valid options is assumed to be input or - * output filenames. - * - */ -static void -parseargs(ac, av) -int ac; -char **av; -{ - int i; /* current argument */ - int fflag; /* 0 = haven't found input/output file */ - int minusflag; /* !0 = have hit a "--": end of flags */ - size_t sz; /* size of the argument */ - size_t mav_sz; /* size of our psuedo argument space */ - - i = mac = fflag = minusflag = 0; /* proper initializations */ - - mav_sz = (size_t) ((ac + 1) * sizeof (char *)); - if ((mav = malloc(mav_sz)) == (char **) NULL) { - perror("malloc failed"); - exit(1); - } - - /* for each argument, see if we need to change things: */ - while ((av[i] != (char *) NULL) && (av[i][0] != (char) NULL)) { - /* - * if we're doing argument processing, and we have - * a "+" sign, then it should be of the form: +#. - * map it to "-m #". - */ - if ((fflag == 0) && (minusflag == 0) && (av[i][0] == '+')) { - if ((av[i][1] == (char) NULL) || - (atoi(&av[i][1]) <= 0)) { - /* - * The user did not follow the + with a - * positive decimal integer. - * Exit here because we don't want getopt() to - * print an error message about the -m option, - * since it doesn't exist in the man page! - */ - usage(); - exit(1); - } - /* since we're adding an arg, need to inc mav space */ - mav_sz += sizeof (char *); - if ((mav = realloc(mav, mav_sz)) == (char **) NULL) { - perror("realloc failed"); - exit(1); - } - - if ((mav[mac] = malloc(sizeof ("-m") + 1)) == - (char *) NULL) { - perror("malloc failed"); - exit(1); - } - - (void) strcpy(mav[mac], "-m"); - ++mac; /* prepare for 2nd argument */ - - - /* add the arg to our modified space */ - if ((mav[mac] = malloc(strlen(&av[i][1]) + 1)) == - (char *) NULL) { - perror("malloc failed"); - exit(1); - } - - (void) strcpy(mav[mac++], &av[i++][1]); - continue; - } - - /* - * Here we need to see if the user typed -#, where # is - * a positive integer. - * Allow for input file named "-" (standard input). - */ - if ((fflag == 0) && (minusflag == 0) && (av[i][0] == '-') && - (av[i][1] != (char) NULL) && (atoi(&av[i][1]) > 0)) { - /* this user did, so convert it to "-n #". */ - - /* since we're adding an arg, need to inc mav space */ - mav_sz += sizeof (char *); - if ((mav = realloc(mav, mav_sz)) == (char **) NULL) { - perror("realloc failed"); - exit(1); - } - - if ((mav[mac] = malloc(sizeof ("-n") + 1)) == - (char *) NULL) { - perror("malloc failed"); - exit(1); - } - - (void) strcpy(mav[mac++], "-n"); - - if ((mav[mac] = malloc(strlen(&av[i][1] + 1))) == - (char *) NULL) { - perror("malloc failed"); - exit(1); - } - - (void) strcpy(mav[mac++], &av[i++][1]); - continue; - } - - /* the rest should be normal argument processing: */ - - /* first copy the argument: */ - sz = strlen(&av[i][0]); - if ((mav[mac] = malloc(sz + 1)) == (char *) NULL) { - perror("malloc failed"); - exit(1); - } - - (void) strcpy(mav[mac], av[i]); - - /* see if we need to do any further processing: */ - if ((av[i][0] == '-') && (av[i][1] != (char) NULL) && - (minusflag == 0)) { - - switch (av[i][1]) { - /* - * start of all the other expected arguments. - * here we keep continuing - eventually we'll - * either run out of arguments, or we'll run - * into the input & output files (after which - * we terminate this loop). - */ - - /* flags without subarguments: */ - case 'c': /* FALLTHROUGH */ - case 'd': /* FALLTHROUGH */ - case 'u': - break; /* no more processing required */ - - - /* flags with required subarguments: */ - case 'f': /* FALLTHROUGH */ - case 's': - if (av[i][2] == (char) NULL) { - /* - * The user has put white space - * between the option and its argument; - * alloc some space, & add the next - * arg. - */ - ++mac; /* inc our arg count */ - ++i; /* mv to next (sub)arg */ - - /* - * If there's no next argument, then - * simply return; getopt(3C) will - * print a message about the missing - * option argument. - */ - if ((av[i] == (char *) NULL) || - av[i][0] == (char) NULL) - return; - else { - /* add the subargument */ - mav[mac] = malloc( - strlen(&av[i][0])); - if (mav[mac] == (char *) NULL) { - perror("malloc failed"); - exit(1); - } - (void) strcpy(mav[mac], - &av[i][0]); - } - } - - break; - - case '-': /* --: end of arguments */ - minusflag = 1; - break; - - default: - /* - * no flags == input/output file. inc - * fflag, so that: - * - we do no further argument processing. - * - we know apriori that there will - * be no more than 2 files. - * we leave if we hit the second file. - */ - if (++fflag >= 2) { - /* - * we've copied the file argument - * already, so leave. - */ - mav[++mac] = (char *) NULL; - return; - } - - break; - } - } else if (i > 0) { /* if we're not the 1st arg */ - /* - * here it's not a flag, so it *must* be either - * the input or the output file, including stdin. - * - * set fflag, so we don't mishandle the -[cdu] flags. - */ - if (++fflag >= 2) { - /* - * we've copied the file argument - * already, so leave. - */ - mav[++mac] = (char *) NULL; - return; - } - } - - mac++; - i++; - } - - mav[mac] = (char *) NULL; -} - -static void -usage() -{ - (void) fprintf(stderr, "Usage:\t%s [input_file [output_file]]\n", - usage0); - (void) fprintf(stderr, "Or:\t%s [input_file [output_file]]\n", - usage1); -} diff --git a/usr/src/cmd/uniq/uniq.xcl b/usr/src/cmd/uniq/uniq.xcl deleted file mode 100644 index d6460a6212..0000000000 --- a/usr/src/cmd/uniq/uniq.xcl +++ /dev/null @@ -1,25 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -msgid "" -msgid "%4d " -msgid "r" -msgid "w" diff --git a/usr/src/cmd/wc/Makefile b/usr/src/cmd/wc/Makefile deleted file mode 100644 index 8ca1afc41c..0000000000 --- a/usr/src/cmd/wc/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License, Version 1.0 only -# (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 -# -# -#ident "%Z%%M% %I% %E% SMI" -# -# Copyright (c) 1989,1996 by Sun Microsystems, Inc. -# All rights reserved. -# - -PROG= wc - -include ../Makefile.cmd - -CPPFLAGS += -D_FILE_OFFSET_BITS=64 - -.KEEP_STATE: - -all: $(PROG) - -install: all $(ROOTPROG) - -clean: - -lint: lint_PROG - -include ../Makefile.targ 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); -} |