mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.
This commit is contained in:
parent
ff662b5c98
commit
a7d5f7eb3b
44925 changed files with 0 additions and 17229487 deletions
126
COPYRIGHT
126
COPYRIGHT
|
|
@ -1,126 +0,0 @@
|
|||
# $FreeBSD$
|
||||
# @(#)COPYRIGHT 8.2 (Berkeley) 3/21/94
|
||||
|
||||
The compilation of software known as FreeBSD is distributed under the
|
||||
following terms:
|
||||
|
||||
Copyright (c) 1992-2010 The FreeBSD Project. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
The 4.4BSD and 4.4BSD-Lite software is distributed under the following
|
||||
terms:
|
||||
|
||||
All of the documentation and software included in the 4.4BSD and 4.4BSD-Lite
|
||||
Releases is copyrighted by The Regents of the University of California.
|
||||
|
||||
Copyright 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
|
||||
The Regents of the University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. All advertising materials mentioning features or use of this software
|
||||
must display the following acknowledgement:
|
||||
This product includes software developed by the University of
|
||||
California, Berkeley and its contributors.
|
||||
4. Neither the name of the University nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
The Institute of Electrical and Electronics Engineers and the American
|
||||
National Standards Committee X3, on Information Processing Systems have
|
||||
given us permission to reprint portions of their documentation.
|
||||
|
||||
In the following statement, the phrase ``this text'' refers to portions
|
||||
of the system documentation.
|
||||
|
||||
Portions of this text are reprinted and reproduced in electronic form in
|
||||
the second BSD Networking Software Release, from IEEE Std 1003.1-1988, IEEE
|
||||
Standard Portable Operating System Interface for Computer Environments
|
||||
(POSIX), copyright C 1988 by the Institute of Electrical and Electronics
|
||||
Engineers, Inc. In the event of any discrepancy between these versions
|
||||
and the original IEEE Standard, the original IEEE Standard is the referee
|
||||
document.
|
||||
|
||||
In the following statement, the phrase ``This material'' refers to portions
|
||||
of the system documentation.
|
||||
|
||||
This material is reproduced with permission from American National
|
||||
Standards Committee X3, on Information Processing Systems. Computer and
|
||||
Business Equipment Manufacturers Association (CBEMA), 311 First St., NW,
|
||||
Suite 500, Washington, DC 20001-2178. The developmental work of
|
||||
Programming Language C was completed by the X3J11 Technical Committee.
|
||||
|
||||
The views and conclusions contained in the software and documentation are
|
||||
those of the authors and should not be interpreted as representing official
|
||||
policies, either expressed or implied, of the Regents of the University
|
||||
of California.
|
||||
|
||||
|
||||
NOTE: The copyright of UC Berkeley's Berkeley Software Distribution ("BSD")
|
||||
source has been updated. The copyright addendum may be found at
|
||||
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change and is
|
||||
included below.
|
||||
|
||||
July 22, 1999
|
||||
|
||||
To All Licensees, Distributors of Any Version of BSD:
|
||||
|
||||
As you know, certain of the Berkeley Software Distribution ("BSD") source
|
||||
code files require that further distributions of products containing all or
|
||||
portions of the software, acknowledge within their advertising materials
|
||||
that such products contain software developed by UC Berkeley and its
|
||||
contributors.
|
||||
|
||||
Specifically, the provision reads:
|
||||
|
||||
" * 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors."
|
||||
|
||||
Effective immediately, licensees and distributors are no longer required to
|
||||
include the acknowledgement within advertising materials. Accordingly, the
|
||||
foregoing paragraph of those BSD Unix files containing it is hereby deleted
|
||||
in its entirety.
|
||||
|
||||
William Hoskins
|
||||
Director, Office of Technology Licensing
|
||||
University of California, Berkeley
|
||||
13
LOCKS
13
LOCKS
|
|
@ -1,13 +0,0 @@
|
|||
$FreeBSD$
|
||||
|
||||
This file documents formal review/approval requirements that have been
|
||||
approved by core.
|
||||
|
||||
subsystem login expires notes
|
||||
--------------------------------------
|
||||
|
||||
Special cases:
|
||||
releng/4.* Requires Security Officer approval.
|
||||
releng/5.* Requires Security Officer approval.
|
||||
releng/6.* Requires Security Officer approval.
|
||||
releng/7.* Requires Security Officer approval.
|
||||
141
MAINTAINERS
141
MAINTAINERS
|
|
@ -1,141 +0,0 @@
|
|||
$FreeBSD$
|
||||
|
||||
Please note that the content of this file is strictly advisory.
|
||||
No locks listed here are valid. The only strict review requirements
|
||||
are granted by core. These are documented in head/LOCKS and enforced
|
||||
by CVSROOT/approvers.
|
||||
|
||||
The source tree is a community effort. However, some folks go to the
|
||||
trouble of looking after particular areas of the tree. In return for
|
||||
their active caretaking of the code it is polite to coordinate changes
|
||||
with them. This is a list of people who have expressed an interest in
|
||||
part of the code or listed their active caretaking role so that other
|
||||
committers can easily find somebody who is familiar with it. The notes
|
||||
should specify if there is a 3rd party source tree involved or other
|
||||
things that should be kept in mind.
|
||||
|
||||
However, this is not a 'big stick', it is an offer to help and a source
|
||||
of guidance. It does not override the communal nature of the tree.
|
||||
It is not a registry of 'turf' or private property.
|
||||
|
||||
subsystem login notes
|
||||
-----------------------------
|
||||
kqueue jmg Pre-commit review requested.
|
||||
mergemaster dougb Prefers to pre-approve commits
|
||||
libc/posix1e rwatson Pre-commit review requested.
|
||||
POSIX.1e ACLs rwatson Pre-commit review requested.
|
||||
UFS EAs rwatson Pre-commit review requested.
|
||||
MAC Framework rwatson Pre-commit review requested.
|
||||
MAC Modules rwatson Pre-commit review requested.
|
||||
contrib/openbsm rwatson Pre-commit review requested.
|
||||
sys/security/audit rwatson Pre-commit review requested.
|
||||
ahc(4) gibbs Pre-commit review requested.
|
||||
ahd(4) gibbs Pre-commit review requested.
|
||||
NEWCARD imp Pre-commit review requested.
|
||||
pci bus imp,jhb Pre-commit review requested.
|
||||
cdboot jhb Pre-commit review requested.
|
||||
pxeboot jhb Pre-commit review requested.
|
||||
witness jhb Pre-commit review requested.
|
||||
CAM gibbs,
|
||||
ken Pre-commit review requested. send to scsi@freebsd.org
|
||||
devstat(9) ken Pre-commit review requested.
|
||||
camcontrol(8) ken Pre-commit review requested.
|
||||
libcam ken Pre-commit review requested.
|
||||
libdevstat ken Pre-commit review requested.
|
||||
iostat(8) ken Pre-commit review requested.
|
||||
cd(4) ken Pre-commit review requested.
|
||||
pass(4) ken Pre-commit review requested.
|
||||
ch(4) ken Pre-commit review requested.
|
||||
em(4) jfv Pre-commit review requested.
|
||||
tdfx(4) cokane Just keep me informed of changes, try not to break it.
|
||||
sendmail gshapiro Pre-commit review requested.
|
||||
etc/mail gshapiro Pre-commit review requested.
|
||||
Keep in sync with -STABLE.
|
||||
etc/sendmail gshapiro Pre-commit review requested.
|
||||
Keep in sync with -STABLE.
|
||||
libfetch des Advance notification requested.
|
||||
fetch des Advance notification requested.
|
||||
libpam des Pre-commit review requested.
|
||||
openssh des Pre-commit review requested.
|
||||
pseudofs des Pre-commit review requested.
|
||||
procfs des Pre-commit review requested.
|
||||
linprocfs des Pre-commit review requested.
|
||||
lpr gad Pre-commit review requested, particularly for
|
||||
lpd/recvjob.c and lpd/printjob.c.
|
||||
newsyslog(8) gad Heads-up appreciated. I'm going thru the PR's for it.
|
||||
cvs peter Heads-up appreciated, try not to break it.
|
||||
nvi peter Try not to break it.
|
||||
libz peter Try not to break it.
|
||||
groff ru Recommends pre-commit review.
|
||||
share/mk ru This is a vital component of the build system, so I
|
||||
offer a pre-commit review for anything non-trivial.
|
||||
ipfw ipfw Pre-commit review preferred. send to ipfw@freebsd.org
|
||||
drm rnoland Just keep me informed of changes, try not to break it.
|
||||
unifdef(1) fanf Pre-commit review requested.
|
||||
ntp roberto Pre-commit review requested.
|
||||
inetd dwmalone Recommends pre-commit review.
|
||||
nwfs bp In case of functional changes pre-commit review
|
||||
requested.
|
||||
contrib/smbfs bp Open for in-tree committs. In case of functional
|
||||
changes pre-commit review requested.
|
||||
contrib/pf mlaier Pre-commit review requested.
|
||||
binutils obrien Insists on BU blocked from unapproved commits
|
||||
file obrien Insists to keep file blocked from other's unapproved
|
||||
commits
|
||||
contrib/bzip2 obrien Pre-commit review required.
|
||||
lukemftpd obrien Pre-commit review required.
|
||||
geom_concat pjd Pre-commit review preferred.
|
||||
geom_eli pjd Pre-commit review preferred.
|
||||
geom_gate pjd Pre-commit review preferred.
|
||||
geom_label pjd Pre-commit review preferred.
|
||||
geom_mirror pjd Pre-commit review preferred.
|
||||
geom_nop pjd Pre-commit review preferred.
|
||||
geom_raid3 pjd Pre-commit review preferred.
|
||||
geom_shsec pjd Pre-commit review preferred.
|
||||
geom_stripe pjd Pre-commit review preferred.
|
||||
geom_zero pjd Pre-commit review preferred.
|
||||
sbin/geom pjd Pre-commit review preferred.
|
||||
zfs pjd Pre-commit review preferred.
|
||||
nfs alfred Will be happy to review code, but not mandatory.
|
||||
rpc.lockd alfred Will be happy to review code, but not mandatory.
|
||||
truss alfred Will be happy to review code, but not mandatory.
|
||||
rpc alfred Pre-commit review requested.
|
||||
xfs kan@FreeBSD.org,rodrigc@FreeBSD.org,cattelan@xfs.org
|
||||
Pre-commit review preferred.
|
||||
pkg_install portmgr Pre-commit review or approval from portmgr@ requested.
|
||||
linux emul emulation Please discuss changes here.
|
||||
bs{diff,patch} cperciva Pre-commit review requested.
|
||||
portsnap cperciva Pre-commit review requested.
|
||||
freebsd-update cperciva Pre-commit review requested.
|
||||
openssl simon Pre-commit review requested.
|
||||
sys/netgraph/bluetooth emax Pre-commit review preferred.
|
||||
lib/libbluetooth emax Pre-commit review preferred.
|
||||
lib/libsdp emax Pre-commit review preferred.
|
||||
usr.bin/bluetooth emax Pre-commit review preferred.
|
||||
usr.sbin/bluetooth emax Pre-commit review preferred.
|
||||
gnu/usr.bin/send-pr bugmaster Pre-commit review requested.
|
||||
ncurses rafan Heads-up appreciated, try not to break it.
|
||||
*env(3) secteam Due to the problematic security history of this
|
||||
code, please have patches reviewed by secteam.
|
||||
share/zoneinfo edwin Heads-up appreciated, since our data is coming
|
||||
from a third party source.
|
||||
usr.sbin/zic edwin Heads-up appreciated, since this code is
|
||||
maintained by a third party source.
|
||||
lib/libc/stdtime edwin Heads-up appreciated, since parts of this code
|
||||
is maintained by a third party source.
|
||||
sysinstall randi Please contact about any major changes so that
|
||||
they can be co-ordinated.
|
||||
sbin/routed bms Pre-commit review; notify vendor at rhyolite.com
|
||||
|
||||
Following are the entries from the Makefiles, and a few other sources.
|
||||
Please remove stale entries from both their origin, and this file.
|
||||
|
||||
Please also consider removing the lines from the files listed below and
|
||||
stating your preferences here instead.
|
||||
|
||||
List below generated with:
|
||||
$ cd /usr/src; find */* -type f|xargs egrep 'MAINTAINER[ <tab>]*='
|
||||
|
||||
sys/modules/3dfx/Makefile:MAINTAINER= cokane@FreeBSD.org
|
||||
sys/modules/urio/Makefile:MAINTAINER= Iwasa Kazmi <kzmi@ca2.so-net.ne.jp>
|
||||
tools/tools/sysdoc/Makefile:MAINTAINER= trhodes@FreeBSD.org
|
||||
357
Makefile
357
Makefile
|
|
@ -1,357 +0,0 @@
|
|||
#
|
||||
# $FreeBSD$
|
||||
#
|
||||
# The user-driven targets are:
|
||||
#
|
||||
# universe - *Really* build *everything* (buildworld and
|
||||
# all kernels on all architectures).
|
||||
# buildworld - Rebuild *everything*, including glue to help do
|
||||
# upgrades.
|
||||
# installworld - Install everything built by "buildworld".
|
||||
# world - buildworld + installworld, no kernel.
|
||||
# buildkernel - Rebuild the kernel and the kernel-modules.
|
||||
# installkernel - Install the kernel and the kernel-modules.
|
||||
# installkernel.debug
|
||||
# reinstallkernel - Reinstall the kernel and the kernel-modules.
|
||||
# reinstallkernel.debug
|
||||
# kernel - buildkernel + installkernel.
|
||||
# kernel-toolchain - Builds the subset of world necessary to build a kernel
|
||||
# doxygen - Build API documentation of the kernel, needs doxygen.
|
||||
# update - Convenient way to update your source tree (cvs).
|
||||
# check-old - List obsolete directories/files/libraries.
|
||||
# check-old-dirs - List obsolete directories.
|
||||
# check-old-files - List obsolete files.
|
||||
# check-old-libs - List obsolete libraries.
|
||||
# delete-old - Delete obsolete directories/files/libraries.
|
||||
# delete-old-dirs - Delete obsolete directories.
|
||||
# delete-old-files - Delete obsolete files.
|
||||
# delete-old-libs - Delete obsolete libraries.
|
||||
#
|
||||
# This makefile is simple by design. The FreeBSD make automatically reads
|
||||
# the /usr/share/mk/sys.mk unless the -m argument is specified on the
|
||||
# command line. By keeping this makefile simple, it doesn't matter too
|
||||
# much how different the installed mk files are from those in the source
|
||||
# tree. This makefile executes a child make process, forcing it to use
|
||||
# the mk files from the source tree which are supposed to DTRT.
|
||||
#
|
||||
# The user-driven targets (as listed above) are implemented in Makefile.inc1.
|
||||
#
|
||||
# If you want to build your system from source be sure that /usr/obj has
|
||||
# at least 800MB of diskspace available.
|
||||
#
|
||||
# For individuals wanting to build from the sources currently on their
|
||||
# system, the simple instructions are:
|
||||
#
|
||||
# 1. `cd /usr/src' (or to the directory containing your source tree).
|
||||
# 2. Define `HISTORICAL_MAKE_WORLD' variable (see README).
|
||||
# 3. `make world'
|
||||
#
|
||||
# For individuals wanting to upgrade their sources (even if only a
|
||||
# delta of a few days):
|
||||
#
|
||||
# 1. `cd /usr/src' (or to the directory containing your source tree).
|
||||
# 2. `make buildworld'
|
||||
# 3. `make buildkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).
|
||||
# 4. `make installkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).
|
||||
# [steps 3. & 4. can be combined by using the "kernel" target]
|
||||
# 5. `reboot' (in single user mode: boot -s from the loader prompt).
|
||||
# 6. `mergemaster -p'
|
||||
# 7. `make installworld'
|
||||
# 8. `make delete-old'
|
||||
# 9. `mergemaster' (you may wish to use -U or -ai).
|
||||
# 10. `reboot'
|
||||
# 11. `make delete-old-libs' (in case no 3rd party program uses them anymore)
|
||||
#
|
||||
# See src/UPDATING `COMMON ITEMS' for more complete information.
|
||||
#
|
||||
# If TARGET=machine (e.g. ia64, sparc64, ...) is specified you can
|
||||
# cross build world for other machine types using the buildworld target,
|
||||
# and once the world is built you can cross build a kernel using the
|
||||
# buildkernel target.
|
||||
#
|
||||
# Define the user-driven targets. These are listed here in alphabetical
|
||||
# order, but that's not important.
|
||||
#
|
||||
# Targets that begin with underscore are internal targets intended for
|
||||
# developer convenience only. They are intentionally not documented and
|
||||
# completely subject to change without notice.
|
||||
#
|
||||
# For more information, see the build(7) manual page.
|
||||
#
|
||||
TGTS= all all-man buildenv buildenvvars buildkernel buildworld \
|
||||
check-old check-old-dirs check-old-files check-old-libs \
|
||||
checkdpadd clean cleandepend cleandir \
|
||||
delete-old delete-old-dirs delete-old-files delete-old-libs \
|
||||
depend distribute distributeworld distrib-dirs distribution doxygen \
|
||||
everything hierarchy install installcheck installkernel \
|
||||
installkernel.debug reinstallkernel reinstallkernel.debug \
|
||||
installworld kernel-toolchain libraries lint maninstall \
|
||||
obj objlink regress rerelease showconfig tags toolchain update \
|
||||
_worldtmp _legacy _bootstrap-tools _cleanobj _obj \
|
||||
_build-tools _cross-tools _includes _libraries _depend \
|
||||
build32 builddtb distribute32 install32 xdev xdev-build xdev-install \
|
||||
|
||||
TGTS+= ${SUBDIR_TARGETS}
|
||||
|
||||
BITGTS= files includes
|
||||
BITGTS:=${BITGTS} ${BITGTS:S/^/build/} ${BITGTS:S/^/install/}
|
||||
TGTS+= ${BITGTS}
|
||||
|
||||
.ORDER: buildworld installworld
|
||||
.ORDER: buildworld distributeworld
|
||||
.ORDER: buildworld buildkernel
|
||||
.ORDER: buildkernel installkernel
|
||||
.ORDER: buildkernel installkernel.debug
|
||||
.ORDER: buildkernel reinstallkernel
|
||||
.ORDER: buildkernel reinstallkernel.debug
|
||||
|
||||
PATH= /sbin:/bin:/usr/sbin:/usr/bin
|
||||
MAKEOBJDIRPREFIX?= /usr/obj
|
||||
_MAKEOBJDIRPREFIX!= /usr/bin/env -i PATH=${PATH} ${MAKE} \
|
||||
${.MAKEFLAGS:MMAKEOBJDIRPREFIX=*} __MAKE_CONF=${__MAKE_CONF} \
|
||||
-f /dev/null -V MAKEOBJDIRPREFIX dummy
|
||||
.if !empty(_MAKEOBJDIRPREFIX)
|
||||
.error MAKEOBJDIRPREFIX can only be set in environment, not as a global\
|
||||
(in make.conf(5)) or command-line variable.
|
||||
.endif
|
||||
MAKEPATH= ${MAKEOBJDIRPREFIX}${.CURDIR}/make.${MACHINE}
|
||||
BINMAKE= \
|
||||
`if [ -x ${MAKEPATH}/make ]; then echo ${MAKEPATH}/make; else echo ${MAKE}; fi` \
|
||||
-m ${.CURDIR}/share/mk
|
||||
_MAKE= PATH=${PATH} ${BINMAKE} -f Makefile.inc1
|
||||
|
||||
#
|
||||
# Make sure we have an up-to-date make(1). Only world and buildworld
|
||||
# should do this as those are the initial targets used for upgrades.
|
||||
# The user can define ALWAYS_CHECK_MAKE to have this check performed
|
||||
# for all targets.
|
||||
#
|
||||
.if defined(ALWAYS_CHECK_MAKE)
|
||||
${TGTS}: upgrade_checks
|
||||
.else
|
||||
buildworld: upgrade_checks
|
||||
.endif
|
||||
|
||||
#
|
||||
# This 'cleanworld' target is not included in TGTS, because it is not a
|
||||
# recursive target. All of the work for it is done right here. It is
|
||||
# expected that BW_CANONICALOBJDIR == the CANONICALOBJDIR as would be
|
||||
# created by bsd.obj.mk, except that we don't want to .include that file
|
||||
# in this makefile.
|
||||
#
|
||||
# In the following, the first 'rm' in a series will usually remove all
|
||||
# files and directories. If it does not, then there are probably some
|
||||
# files with chflags set, so this unsets them and tries the 'rm' a
|
||||
# second time. There are situations where this target will be cleaning
|
||||
# some directories via more than one method, but that duplication is
|
||||
# needed to correctly handle all the possible situations.
|
||||
#
|
||||
BW_CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR}
|
||||
cleanworld:
|
||||
.if ${.CURDIR} == ${.OBJDIR} || ${.CURDIR}/obj == ${.OBJDIR}
|
||||
.if exists(${BW_CANONICALOBJDIR}/)
|
||||
-rm -rf ${BW_CANONICALOBJDIR}/*
|
||||
-chflags -R 0 ${BW_CANONICALOBJDIR}
|
||||
rm -rf ${BW_CANONICALOBJDIR}/*
|
||||
.endif
|
||||
# To be safe in this case, fall back to a 'make cleandir'
|
||||
${_+_}@cd ${.CURDIR}; ${_MAKE} cleandir
|
||||
.else
|
||||
-rm -rf ${.OBJDIR}/*
|
||||
-chflags -R 0 ${.OBJDIR}
|
||||
rm -rf ${.OBJDIR}/*
|
||||
.endif
|
||||
|
||||
#
|
||||
# Handle the user-driven targets, using the source relative mk files.
|
||||
#
|
||||
|
||||
${TGTS}:
|
||||
${_+_}@cd ${.CURDIR}; \
|
||||
${_MAKE} ${.TARGET}
|
||||
|
||||
# Set a reasonable default
|
||||
.MAIN: all
|
||||
|
||||
STARTTIME!= LC_ALL=C date
|
||||
CHECK_TIME!= find ${.CURDIR}/sys/sys/param.h -mtime -0
|
||||
.if !empty(CHECK_TIME)
|
||||
.error check your date/time: ${STARTTIME}
|
||||
.endif
|
||||
|
||||
.if defined(HISTORICAL_MAKE_WORLD) || defined(DESTDIR)
|
||||
#
|
||||
# world
|
||||
#
|
||||
# Attempt to rebuild and reinstall everything. This target is not to be
|
||||
# used for upgrading an existing FreeBSD system, because the kernel is
|
||||
# not included. One can argue that this target doesn't build everything
|
||||
# then.
|
||||
#
|
||||
world: upgrade_checks
|
||||
@echo "--------------------------------------------------------------"
|
||||
@echo ">>> make world started on ${STARTTIME}"
|
||||
@echo "--------------------------------------------------------------"
|
||||
.if target(pre-world)
|
||||
@echo
|
||||
@echo "--------------------------------------------------------------"
|
||||
@echo ">>> Making 'pre-world' target"
|
||||
@echo "--------------------------------------------------------------"
|
||||
${_+_}@cd ${.CURDIR}; ${_MAKE} pre-world
|
||||
.endif
|
||||
${_+_}@cd ${.CURDIR}; ${_MAKE} buildworld
|
||||
${_+_}@cd ${.CURDIR}; ${_MAKE} -B installworld
|
||||
.if target(post-world)
|
||||
@echo
|
||||
@echo "--------------------------------------------------------------"
|
||||
@echo ">>> Making 'post-world' target"
|
||||
@echo "--------------------------------------------------------------"
|
||||
${_+_}@cd ${.CURDIR}; ${_MAKE} post-world
|
||||
.endif
|
||||
@echo
|
||||
@echo "--------------------------------------------------------------"
|
||||
@echo ">>> make world completed on `LC_ALL=C date`"
|
||||
@echo " (started ${STARTTIME})"
|
||||
@echo "--------------------------------------------------------------"
|
||||
.else
|
||||
world:
|
||||
@echo "WARNING: make world will overwrite your existing FreeBSD"
|
||||
@echo "installation without also building and installing a new"
|
||||
@echo "kernel. This can be dangerous. Please read the handbook,"
|
||||
@echo "'Rebuilding world', for how to upgrade your system."
|
||||
@echo "Define DESTDIR to where you want to install FreeBSD,"
|
||||
@echo "including /, to override this warning and proceed as usual."
|
||||
@echo ""
|
||||
@echo "Bailing out now..."
|
||||
@false
|
||||
.endif
|
||||
|
||||
#
|
||||
# kernel
|
||||
#
|
||||
# Short hand for `make buildkernel installkernel'
|
||||
#
|
||||
kernel: buildkernel installkernel
|
||||
|
||||
#
|
||||
# Perform a few tests to determine if the installed tools are adequate
|
||||
# for building the world.
|
||||
#
|
||||
upgrade_checks:
|
||||
@if ! (cd ${.CURDIR}/tools/build/make_check && \
|
||||
PATH=${PATH} ${BINMAKE} obj >/dev/null 2>&1 && \
|
||||
PATH=${PATH} ${BINMAKE} >/dev/null 2>&1); \
|
||||
then \
|
||||
(cd ${.CURDIR} && ${MAKE} make); \
|
||||
fi
|
||||
|
||||
#
|
||||
# Upgrade make(1) to the current version using the installed
|
||||
# headers, libraries and tools. Also, allow the location of
|
||||
# the system bsdmake-like utility to be overridden.
|
||||
#
|
||||
MMAKEENV= MAKEOBJDIRPREFIX=${MAKEPATH} \
|
||||
DESTDIR= \
|
||||
INSTALL="sh ${.CURDIR}/tools/install.sh"
|
||||
MMAKE= ${MMAKEENV} ${MAKE} \
|
||||
-D_UPGRADING \
|
||||
-DNOMAN -DNO_MAN -DNOSHARED -DNO_SHARED \
|
||||
-DNO_CPU_CFLAGS -DNO_WERROR
|
||||
|
||||
make: .PHONY
|
||||
@echo
|
||||
@echo "--------------------------------------------------------------"
|
||||
@echo ">>> Building an up-to-date make(1)"
|
||||
@echo "--------------------------------------------------------------"
|
||||
${_+_}@cd ${.CURDIR}/usr.bin/make; \
|
||||
${MMAKE} obj && \
|
||||
${MMAKE} depend && \
|
||||
${MMAKE} all && \
|
||||
${MMAKE} install DESTDIR=${MAKEPATH} BINDIR=
|
||||
|
||||
tinderbox:
|
||||
cd ${.CURDIR} && \
|
||||
DOING_TINDERBOX=YES ${MAKE} ${JFLAG} universe
|
||||
|
||||
#
|
||||
# universe
|
||||
#
|
||||
# Attempt to rebuild *everything* for all supported architectures,
|
||||
# with a reasonable chance of success, regardless of how old your
|
||||
# existing system is.
|
||||
#
|
||||
.if make(universe) || make(universe_kernels) || make(tinderbox)
|
||||
TARGETS?=amd64 arm i386 ia64 mips pc98 powerpc sparc64 sun4v
|
||||
|
||||
.if defined(DOING_TINDERBOX)
|
||||
FAILFILE=tinderbox.failed
|
||||
MAKEFAIL=tee -a ${FAILFILE}
|
||||
.else
|
||||
MAKEFAIL=cat
|
||||
.endif
|
||||
|
||||
universe: universe_prologue
|
||||
universe_prologue:
|
||||
@echo "--------------------------------------------------------------"
|
||||
@echo ">>> make universe started on ${STARTTIME}"
|
||||
@echo "--------------------------------------------------------------"
|
||||
.if defined(DOING_TINDERBOX)
|
||||
rm -f ${FAILFILE}
|
||||
.endif
|
||||
.for target in ${TARGETS}
|
||||
universe: universe_${target}
|
||||
.ORDER: universe_prologue universe_${target} universe_epilogue
|
||||
universe_${target}:
|
||||
.if !defined(MAKE_JUST_KERNELS)
|
||||
@echo ">> ${target} started on `LC_ALL=C date`"
|
||||
@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
|
||||
${MAKE} ${JFLAG} buildworld \
|
||||
TARGET=${target} \
|
||||
> _.${target}.buildworld 2>&1 || \
|
||||
(echo "${target} world failed," \
|
||||
"check _.${target}.buildworld for details" | ${MAKEFAIL}))
|
||||
@echo ">> ${target} buildworld completed on `LC_ALL=C date`"
|
||||
.endif
|
||||
.if !defined(MAKE_JUST_WORLDS)
|
||||
.if exists(${.CURDIR}/sys/${target}/conf/NOTES)
|
||||
@(cd ${.CURDIR}/sys/${target}/conf && env __MAKE_CONF=/dev/null \
|
||||
${MAKE} LINT > ${.CURDIR}/_.${target}.makeLINT 2>&1 || \
|
||||
(echo "${target} 'make LINT' failed," \
|
||||
"check _.${target}.makeLINT for details"| ${MAKEFAIL}))
|
||||
.endif
|
||||
@cd ${.CURDIR} && ${MAKE} ${.MAKEFLAGS} TARGET=${target} \
|
||||
universe_kernels
|
||||
.endif
|
||||
@echo ">> ${target} completed on `LC_ALL=C date`"
|
||||
.endfor
|
||||
universe_kernels: universe_kernconfs
|
||||
.if !defined(TARGET)
|
||||
TARGET!= uname -m
|
||||
.endif
|
||||
KERNCONFS!= cd ${.CURDIR}/sys/${TARGET}/conf && \
|
||||
find [A-Z0-9]*[A-Z0-9] -type f -maxdepth 0 \
|
||||
! -name DEFAULTS ! -name NOTES
|
||||
universe_kernconfs:
|
||||
.for kernel in ${KERNCONFS}
|
||||
@(cd ${.CURDIR} && env __MAKE_CONF=/dev/null \
|
||||
${MAKE} ${JFLAG} buildkernel \
|
||||
TARGET=${TARGET} \
|
||||
KERNCONF=${kernel} \
|
||||
> _.${TARGET}.${kernel} 2>&1 || \
|
||||
(echo "${TARGET} ${kernel} kernel failed," \
|
||||
"check _.${TARGET}.${kernel} for details"| ${MAKEFAIL}))
|
||||
.endfor
|
||||
universe: universe_epilogue
|
||||
universe_epilogue:
|
||||
@echo "--------------------------------------------------------------"
|
||||
@echo ">>> make universe completed on `LC_ALL=C date`"
|
||||
@echo " (started ${STARTTIME})"
|
||||
@echo "--------------------------------------------------------------"
|
||||
.if defined(DOING_TINDERBOX)
|
||||
@if [ -e ${FAILFILE} ] ; then \
|
||||
echo "Tinderbox failed:" ;\
|
||||
cat ${FAILFILE} ;\
|
||||
exit 1 ;\
|
||||
fi
|
||||
.endif
|
||||
.endif
|
||||
1516
Makefile.inc1
1516
Makefile.inc1
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +0,0 @@
|
|||
# $FreeBSD$
|
||||
|
||||
.if defined(TARGET_ABI) && ${TARGET_ABI} == "n64"
|
||||
MK_RESCUE=no
|
||||
.endif
|
||||
5326
ObsoleteFiles.inc
5326
ObsoleteFiles.inc
File diff suppressed because it is too large
Load diff
87
README
87
README
|
|
@ -1,87 +0,0 @@
|
|||
This is the top level of the FreeBSD source directory. This file
|
||||
was last revised on:
|
||||
$FreeBSD$
|
||||
|
||||
For copyright information, please see the file COPYRIGHT in this
|
||||
directory (additional copyright information also exists for some
|
||||
sources in this tree - please see the specific source directories for
|
||||
more information).
|
||||
|
||||
The Makefile in this directory supports a number of targets for
|
||||
building components (or all) of the FreeBSD source tree, the most
|
||||
commonly used one being ``world'', which rebuilds and installs
|
||||
everything in the FreeBSD system from the source tree except the
|
||||
kernel, the kernel-modules and the contents of /etc. The ``world''
|
||||
target should only be used in cases where the source tree has not
|
||||
changed from the currently running version. See:
|
||||
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/makeworld.html
|
||||
for more information, including setting make(1) variables.
|
||||
|
||||
The ``buildkernel'' and ``installkernel'' targets build and install
|
||||
the kernel and the modules (see below). Please see the top of
|
||||
the Makefile in this directory for more information on the
|
||||
standard build targets and compile-time flags.
|
||||
|
||||
Building a kernel is a somewhat more involved process, documentation
|
||||
for which can be found at:
|
||||
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig.html
|
||||
And in the config(8) man page.
|
||||
Note: If you want to build and install the kernel with the
|
||||
``buildkernel'' and ``installkernel'' targets, you might need to build
|
||||
world before. More information is available in the handbook.
|
||||
|
||||
The sample kernel configuration files reside in the sys/<arch>/conf
|
||||
sub-directory (assuming that you've installed the kernel sources), the
|
||||
file named GENERIC being the one used to build your initial installation
|
||||
kernel. The file NOTES contains entries and documentation for all possible
|
||||
devices, not just those commonly used. It is the successor of the ancient
|
||||
LINT file, but in contrast to LINT, it is not buildable as a kernel but a
|
||||
pure reference and documentation file.
|
||||
|
||||
|
||||
Source Roadmap:
|
||||
---------------
|
||||
bin System/user commands.
|
||||
|
||||
contrib Packages contributed by 3rd parties.
|
||||
|
||||
crypto Cryptography stuff (see crypto/README).
|
||||
|
||||
etc Template files for /etc.
|
||||
|
||||
games Amusements.
|
||||
|
||||
gnu Various commands and libraries under the GNU Public License.
|
||||
Please see gnu/COPYING* for more information.
|
||||
|
||||
include System include files.
|
||||
|
||||
kerberos5 Kerberos5 (Heimdal) package.
|
||||
|
||||
lib System libraries.
|
||||
|
||||
libexec System daemons.
|
||||
|
||||
release Release building Makefile & associated tools.
|
||||
|
||||
rescue Build system for statically linked /rescue utilities.
|
||||
|
||||
sbin System commands.
|
||||
|
||||
secure Cryptographic libraries and commands.
|
||||
|
||||
share Shared resources.
|
||||
|
||||
sys Kernel sources.
|
||||
|
||||
tools Utilities for regression testing and miscellaneous tasks.
|
||||
|
||||
usr.bin User commands.
|
||||
|
||||
usr.sbin System administration commands.
|
||||
|
||||
|
||||
For information on synchronizing your source tree with one or more of
|
||||
the FreeBSD Project's development branches, please see:
|
||||
|
||||
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/synching.html
|
||||
58
bin/Makefile
58
bin/Makefile
|
|
@ -1,58 +0,0 @@
|
|||
# From: @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
# $FreeBSD$
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
SUBDIR= cat \
|
||||
chflags \
|
||||
chio \
|
||||
chmod \
|
||||
cp \
|
||||
date \
|
||||
dd \
|
||||
df \
|
||||
domainname \
|
||||
echo \
|
||||
ed \
|
||||
expr \
|
||||
getfacl \
|
||||
hostname \
|
||||
kenv \
|
||||
kill \
|
||||
ln \
|
||||
ls \
|
||||
mkdir \
|
||||
mv \
|
||||
pax \
|
||||
pkill \
|
||||
ps \
|
||||
pwait \
|
||||
pwd \
|
||||
realpath \
|
||||
rm \
|
||||
rmdir \
|
||||
setfacl \
|
||||
sh \
|
||||
sleep \
|
||||
stty \
|
||||
sync \
|
||||
test \
|
||||
uuidgen
|
||||
|
||||
.if ${MK_RCMDS} != "no"
|
||||
SUBDIR+= rcp
|
||||
.endif
|
||||
|
||||
.if ${MK_SENDMAIL} != "no"
|
||||
SUBDIR+= rmail
|
||||
.endif
|
||||
|
||||
.if ${MK_TCSH} != "no"
|
||||
SUBDIR+= csh
|
||||
.endif
|
||||
|
||||
.include <bsd.arch.inc.mk>
|
||||
|
||||
SUBDIR:= ${SUBDIR:O}
|
||||
|
||||
.include <bsd.subdir.mk>
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
# @(#)Makefile.inc 8.1 (Berkeley) 5/31/93
|
||||
# $FreeBSD$
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
BINDIR?= /bin
|
||||
WARNS?= 6
|
||||
|
||||
.if ${MK_DYNAMICROOT} == "no"
|
||||
NO_SHARED?= YES
|
||||
.endif
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= cat
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
203
bin/cat/cat.1
203
bin/cat/cat.1
|
|
@ -1,203 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 1989, 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" the Institute of Electrical and Electronics Engineers, Inc.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)cat.1 8.3 (Berkeley) 5/2/95
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd March 21, 2004
|
||||
.Dt CAT 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm cat
|
||||
.Nd concatenate and print files
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl benstuv
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility reads files sequentially, writing them to the standard output.
|
||||
The
|
||||
.Ar file
|
||||
operands are processed in command-line order.
|
||||
If
|
||||
.Ar file
|
||||
is a single dash
|
||||
.Pq Sq Fl
|
||||
or absent,
|
||||
.Nm
|
||||
reads from the standard input.
|
||||
If
|
||||
.Ar file
|
||||
is a
|
||||
.Ux
|
||||
domain socket,
|
||||
.Nm
|
||||
connects to it and then reads it until
|
||||
.Dv EOF .
|
||||
This complements the
|
||||
.Ux
|
||||
domain binding capability available in
|
||||
.Xr inetd 8 .
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width indent
|
||||
.It Fl b
|
||||
Number the non-blank output lines, starting at 1.
|
||||
.It Fl e
|
||||
Display non-printing characters (see the
|
||||
.Fl v
|
||||
option), and display a dollar sign
|
||||
.Pq Ql \&$
|
||||
at the end of each line.
|
||||
.It Fl n
|
||||
Number the output lines, starting at 1.
|
||||
.It Fl s
|
||||
Squeeze multiple adjacent empty lines, causing the output to be
|
||||
single spaced.
|
||||
.It Fl t
|
||||
Display non-printing characters (see the
|
||||
.Fl v
|
||||
option), and display tab characters as
|
||||
.Ql ^I .
|
||||
.It Fl u
|
||||
Disable output buffering.
|
||||
.It Fl v
|
||||
Display non-printing characters so they are visible.
|
||||
Control characters print as
|
||||
.Ql ^X
|
||||
for control-X; the delete
|
||||
character (octal 0177) prints as
|
||||
.Ql ^? .
|
||||
.Pf Non- Tn ASCII
|
||||
characters (with the high bit set) are printed as
|
||||
.Ql M-
|
||||
(for meta) followed by the character for the low 7 bits.
|
||||
.El
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std
|
||||
.Sh EXAMPLES
|
||||
The command:
|
||||
.Pp
|
||||
.Dl "cat file1"
|
||||
.Pp
|
||||
will print the contents of
|
||||
.Pa file1
|
||||
to the standard output.
|
||||
.Pp
|
||||
The command:
|
||||
.Pp
|
||||
.Dl "cat file1 file2 > file3"
|
||||
.Pp
|
||||
will sequentially print the contents of
|
||||
.Pa file1
|
||||
and
|
||||
.Pa file2
|
||||
to the file
|
||||
.Pa file3 ,
|
||||
truncating
|
||||
.Pa file3
|
||||
if it already exists.
|
||||
See the manual page for your shell (i.e.,
|
||||
.Xr sh 1 )
|
||||
for more information on redirection.
|
||||
.Pp
|
||||
The command:
|
||||
.Pp
|
||||
.Dl "cat file1 - file2 - file3"
|
||||
.Pp
|
||||
will print the contents of
|
||||
.Pa file1 ,
|
||||
print data it receives from the standard input until it receives an
|
||||
.Dv EOF
|
||||
.Pq Sq ^D
|
||||
character, print the contents of
|
||||
.Pa file2 ,
|
||||
read and output contents of the standard input again, then finally output
|
||||
the contents of
|
||||
.Pa file3 .
|
||||
Note that if the standard input referred to a file, the second dash
|
||||
on the command-line would have no effect, since the entire contents of the file
|
||||
would have already been read and printed by
|
||||
.Nm
|
||||
when it encountered the first
|
||||
.Sq Fl
|
||||
operand.
|
||||
.Sh SEE ALSO
|
||||
.Xr head 1 ,
|
||||
.Xr more 1 ,
|
||||
.Xr pr 1 ,
|
||||
.Xr sh 1 ,
|
||||
.Xr tail 1 ,
|
||||
.Xr vis 1 ,
|
||||
.Xr zcat 1 ,
|
||||
.Xr setbuf 3
|
||||
.Rs
|
||||
.%A Rob Pike
|
||||
.%T "UNIX Style, or cat -v Considered Harmful"
|
||||
.%J "USENIX Summer Conference Proceedings"
|
||||
.%D 1983
|
||||
.Re
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility is compliant with the
|
||||
.St -p1003.2-92
|
||||
specification.
|
||||
.Pp
|
||||
The flags
|
||||
.Op Fl benstv
|
||||
are extensions to the specification.
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm
|
||||
utility appeared in
|
||||
.At v1 .
|
||||
.An Dennis Ritchie
|
||||
designed and wrote the first man page.
|
||||
It appears to have been
|
||||
.Xr cat 1 .
|
||||
.Sh BUGS
|
||||
Because of the shell language mechanism used to perform output
|
||||
redirection, the command
|
||||
.Dq Li cat file1 file2 > file1
|
||||
will cause the original data in
|
||||
.Pa file1
|
||||
to be destroyed!
|
||||
.Pp
|
||||
The
|
||||
.Nm
|
||||
utility does not recognize multibyte characters when the
|
||||
.Fl t
|
||||
or
|
||||
.Fl v
|
||||
option is in effect.
|
||||
333
bin/cat/cat.c
333
bin/cat/cat.c
|
|
@ -1,333 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Kevin Fall.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char const copyright[] =
|
||||
"@(#) Copyright (c) 1989, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)cat.c 8.2 (Berkeley) 4/27/95";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#ifndef NO_UDOM_SUPPORT
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stddef.h>
|
||||
|
||||
int bflag, eflag, nflag, sflag, tflag, vflag;
|
||||
int rval;
|
||||
const char *filename;
|
||||
|
||||
static void usage(void);
|
||||
static void scanfiles(char *argv[], int cooked);
|
||||
static void cook_cat(FILE *);
|
||||
static void raw_cat(int);
|
||||
|
||||
#ifndef NO_UDOM_SUPPORT
|
||||
static int udom_open(const char *path, int flags);
|
||||
#endif
|
||||
|
||||
/* Memory strategy threshold, in pages: if physmem is larger then this, use a
|
||||
* large buffer */
|
||||
#define PHYSPAGES_THRESHOLD (32*1024)
|
||||
|
||||
/* Maximum buffer size in bytes - do not allow it to grow larger than this */
|
||||
#define BUFSIZE_MAX (2*1024*1024)
|
||||
|
||||
/* Small (default) buffer size in bytes. It's inefficient for this to be
|
||||
* smaller than MAXPHYS */
|
||||
#define BUFSIZE_SMALL (MAXPHYS)
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
|
||||
setlocale(LC_CTYPE, "");
|
||||
|
||||
while ((ch = getopt(argc, argv, "benstuv")) != -1)
|
||||
switch (ch) {
|
||||
case 'b':
|
||||
bflag = nflag = 1; /* -b implies -n */
|
||||
break;
|
||||
case 'e':
|
||||
eflag = vflag = 1; /* -e implies -v */
|
||||
break;
|
||||
case 'n':
|
||||
nflag = 1;
|
||||
break;
|
||||
case 's':
|
||||
sflag = 1;
|
||||
break;
|
||||
case 't':
|
||||
tflag = vflag = 1; /* -t implies -v */
|
||||
break;
|
||||
case 'u':
|
||||
setbuf(stdout, NULL);
|
||||
break;
|
||||
case 'v':
|
||||
vflag = 1;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argv += optind;
|
||||
|
||||
if (bflag || eflag || nflag || sflag || tflag || vflag)
|
||||
scanfiles(argv, 1);
|
||||
else
|
||||
scanfiles(argv, 0);
|
||||
if (fclose(stdout))
|
||||
err(1, "stdout");
|
||||
exit(rval);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: cat [-benstuv] [file ...]\n");
|
||||
exit(1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static void
|
||||
scanfiles(char *argv[], int cooked)
|
||||
{
|
||||
int i = 0;
|
||||
char *path;
|
||||
FILE *fp;
|
||||
|
||||
while ((path = argv[i]) != NULL || i == 0) {
|
||||
int fd;
|
||||
|
||||
if (path == NULL || strcmp(path, "-") == 0) {
|
||||
filename = "stdin";
|
||||
fd = STDIN_FILENO;
|
||||
} else {
|
||||
filename = path;
|
||||
fd = open(path, O_RDONLY);
|
||||
#ifndef NO_UDOM_SUPPORT
|
||||
if (fd < 0 && errno == EOPNOTSUPP)
|
||||
fd = udom_open(path, O_RDONLY);
|
||||
#endif
|
||||
}
|
||||
if (fd < 0) {
|
||||
warn("%s", path);
|
||||
rval = 1;
|
||||
} else if (cooked) {
|
||||
if (fd == STDIN_FILENO)
|
||||
cook_cat(stdin);
|
||||
else {
|
||||
fp = fdopen(fd, "r");
|
||||
cook_cat(fp);
|
||||
fclose(fp);
|
||||
}
|
||||
} else {
|
||||
raw_cat(fd);
|
||||
if (fd != STDIN_FILENO)
|
||||
close(fd);
|
||||
}
|
||||
if (path == NULL)
|
||||
break;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
cook_cat(FILE *fp)
|
||||
{
|
||||
int ch, gobble, line, prev;
|
||||
|
||||
/* Reset EOF condition on stdin. */
|
||||
if (fp == stdin && feof(stdin))
|
||||
clearerr(stdin);
|
||||
|
||||
line = gobble = 0;
|
||||
for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) {
|
||||
if (prev == '\n') {
|
||||
if (sflag) {
|
||||
if (ch == '\n') {
|
||||
if (gobble)
|
||||
continue;
|
||||
gobble = 1;
|
||||
} else
|
||||
gobble = 0;
|
||||
}
|
||||
if (nflag && (!bflag || ch != '\n')) {
|
||||
(void)fprintf(stdout, "%6d\t", ++line);
|
||||
if (ferror(stdout))
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ch == '\n') {
|
||||
if (eflag && putchar('$') == EOF)
|
||||
break;
|
||||
} else if (ch == '\t') {
|
||||
if (tflag) {
|
||||
if (putchar('^') == EOF || putchar('I') == EOF)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
} else if (vflag) {
|
||||
if (!isascii(ch) && !isprint(ch)) {
|
||||
if (putchar('M') == EOF || putchar('-') == EOF)
|
||||
break;
|
||||
ch = toascii(ch);
|
||||
}
|
||||
if (iscntrl(ch)) {
|
||||
if (putchar('^') == EOF ||
|
||||
putchar(ch == '\177' ? '?' :
|
||||
ch | 0100) == EOF)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (putchar(ch) == EOF)
|
||||
break;
|
||||
}
|
||||
if (ferror(fp)) {
|
||||
warn("%s", filename);
|
||||
rval = 1;
|
||||
clearerr(fp);
|
||||
}
|
||||
if (ferror(stdout))
|
||||
err(1, "stdout");
|
||||
}
|
||||
|
||||
static void
|
||||
raw_cat(int rfd)
|
||||
{
|
||||
int off, wfd;
|
||||
ssize_t nr, nw;
|
||||
static size_t bsize;
|
||||
static char *buf = NULL;
|
||||
struct stat sbuf;
|
||||
|
||||
wfd = fileno(stdout);
|
||||
if (buf == NULL) {
|
||||
if (fstat(wfd, &sbuf))
|
||||
err(1, "%s", filename);
|
||||
if (S_ISREG(sbuf.st_mode)) {
|
||||
/* If there's plenty of RAM, use a large copy buffer */
|
||||
if (sysconf(_SC_PHYS_PAGES) > PHYSPAGES_THRESHOLD)
|
||||
bsize = MIN(BUFSIZE_MAX, MAXPHYS*8);
|
||||
else
|
||||
bsize = BUFSIZE_SMALL;
|
||||
} else
|
||||
bsize = MAX(sbuf.st_blksize,
|
||||
(blksize_t)sysconf(_SC_PAGESIZE));
|
||||
if ((buf = malloc(bsize)) == NULL)
|
||||
err(1, "malloc() failure of IO buffer");
|
||||
}
|
||||
while ((nr = read(rfd, buf, bsize)) > 0)
|
||||
for (off = 0; nr; nr -= nw, off += nw)
|
||||
if ((nw = write(wfd, buf + off, (size_t)nr)) < 0)
|
||||
err(1, "stdout");
|
||||
if (nr < 0) {
|
||||
warn("%s", filename);
|
||||
rval = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NO_UDOM_SUPPORT
|
||||
|
||||
static int
|
||||
udom_open(const char *path, int flags)
|
||||
{
|
||||
struct sockaddr_un sou;
|
||||
int fd;
|
||||
unsigned int len;
|
||||
|
||||
bzero(&sou, sizeof(sou));
|
||||
|
||||
/*
|
||||
* Construct the unix domain socket address and attempt to connect
|
||||
*/
|
||||
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fd >= 0) {
|
||||
sou.sun_family = AF_UNIX;
|
||||
if ((len = strlcpy(sou.sun_path, path,
|
||||
sizeof(sou.sun_path))) >= sizeof(sou.sun_path)) {
|
||||
errno = ENAMETOOLONG;
|
||||
return (-1);
|
||||
}
|
||||
len = offsetof(struct sockaddr_un, sun_path[len+1]);
|
||||
|
||||
if (connect(fd, (void *)&sou, len) < 0) {
|
||||
close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* handle the open flags by shutting down appropriate directions
|
||||
*/
|
||||
if (fd >= 0) {
|
||||
switch(flags & O_ACCMODE) {
|
||||
case O_RDONLY:
|
||||
if (shutdown(fd, SHUT_WR) == -1)
|
||||
warn(NULL);
|
||||
break;
|
||||
case O_WRONLY:
|
||||
if (shutdown(fd, SHUT_RD) == -1)
|
||||
warn(NULL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return(fd);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= chflags
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,227 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 1989, 1990, 1993, 1994
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" the Institute of Electrical and Electronics Engineers, Inc.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)chflags.1 8.4 (Berkeley) 5/2/95
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd March 3, 2006
|
||||
.Dt CHFLAGS 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm chflags
|
||||
.Nd change file flags
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl fhv
|
||||
.Oo
|
||||
.Fl R
|
||||
.Op Fl H | Fl L | Fl P
|
||||
.Oc
|
||||
.Ar flags
|
||||
.Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility modifies the file flags of the listed files
|
||||
as specified by the
|
||||
.Ar flags
|
||||
operand.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width indent
|
||||
.It Fl f
|
||||
Do not display a diagnostic message if
|
||||
.Nm
|
||||
could not modify the flags for
|
||||
.Va file ,
|
||||
nor modify the exit status to reflect such failures.
|
||||
.It Fl H
|
||||
If the
|
||||
.Fl R
|
||||
option is specified, symbolic links on the command line are followed.
|
||||
(Symbolic links encountered in the tree traversal are not followed.)
|
||||
.It Fl h
|
||||
If the
|
||||
.Ar file
|
||||
is a symbolic link,
|
||||
change the file flags of the link itself rather than the file to which it points.
|
||||
.It Fl L
|
||||
If the
|
||||
.Fl R
|
||||
option is specified, all symbolic links are followed.
|
||||
.It Fl P
|
||||
If the
|
||||
.Fl R
|
||||
option is specified, no symbolic links are followed.
|
||||
This is the default.
|
||||
.It Fl R
|
||||
Change the file flags for the file hierarchies rooted
|
||||
in the files instead of just the files themselves.
|
||||
.It Fl v
|
||||
Cause
|
||||
.Nm
|
||||
to be verbose, showing filenames as the flags are modified.
|
||||
If the
|
||||
.Fl v
|
||||
option is specified more than once, the old and new flags of the file
|
||||
will also be printed, in octal notation.
|
||||
.El
|
||||
.Pp
|
||||
The flags are specified as an octal number or a comma separated list
|
||||
of keywords.
|
||||
The following keywords are currently defined:
|
||||
.Bl -tag -offset indent -width ".Cm opaque"
|
||||
.It Cm arch , archived
|
||||
set the archived flag (super-user only)
|
||||
.It Cm opaque
|
||||
set the opaque flag (owner or super-user only)
|
||||
.It Cm nodump
|
||||
set the nodump flag (owner or super-user only)
|
||||
.It Cm sappnd , sappend
|
||||
set the system append-only flag (super-user only)
|
||||
.It Cm schg , schange , simmutable
|
||||
set the system immutable flag (super-user only)
|
||||
.It Cm sunlnk , sunlink
|
||||
set the system undeletable flag (super-user only)
|
||||
.It Cm uappnd , uappend
|
||||
set the user append-only flag (owner or super-user only)
|
||||
.It Cm uchg , uchange , uimmutable
|
||||
set the user immutable flag (owner or super-user only)
|
||||
.It Cm uunlnk , uunlink
|
||||
set the user undeletable flag (owner or super-user only)
|
||||
.El
|
||||
.Pp
|
||||
Putting the letters
|
||||
.Dq Ar no
|
||||
before or removing the letters
|
||||
.Dq Ar no
|
||||
from a keyword causes the flag to be cleared.
|
||||
For example:
|
||||
.Pp
|
||||
.Bl -tag -offset indent -width "nouchg" -compact
|
||||
.It Cm nouchg
|
||||
clear the user immutable flag (owner or super-user only)
|
||||
.It Cm dump
|
||||
clear the nodump flag (owner or super-user only)
|
||||
.El
|
||||
.Pp
|
||||
A few of the octal values include:
|
||||
.Bl -tag -offset indent -width ".Li 10"
|
||||
.It Li 0
|
||||
Clear all file flags.
|
||||
.It Li 1
|
||||
Translates to the
|
||||
.Cm nodump
|
||||
keyword.
|
||||
.It Li 2
|
||||
Translates to the
|
||||
.Cm uchg
|
||||
keyword.
|
||||
.It Li 3
|
||||
Translates to the
|
||||
.Cm uchg , nodump
|
||||
keywords.
|
||||
.It Li 4
|
||||
Translates to the
|
||||
.Cm uappnd
|
||||
keyword.
|
||||
.It Li 10
|
||||
Translates to the
|
||||
.Cm opaque
|
||||
keyword.
|
||||
.It Li 20
|
||||
translates to the
|
||||
.Cm uunlnk
|
||||
keyword.
|
||||
.El
|
||||
.Pp
|
||||
Other combinations of keywords may be placed by using
|
||||
the octets assigned; however, these are the most notable.
|
||||
.Pp
|
||||
Unless the
|
||||
.Fl H ,
|
||||
.Fl L ,
|
||||
or
|
||||
.Fl h
|
||||
options are given,
|
||||
.Nm
|
||||
on a symbolic link always succeeds and has no effect.
|
||||
The
|
||||
.Fl H ,
|
||||
.Fl L
|
||||
and
|
||||
.Fl P
|
||||
options are ignored unless the
|
||||
.Fl R
|
||||
option is specified.
|
||||
In addition, these options override each other and the
|
||||
command's actions are determined by the last one specified.
|
||||
.Pp
|
||||
You can use "ls -lo" to see the flags of existing files.
|
||||
.Pp
|
||||
Note that the ability to change certain flags is dependent
|
||||
on the current kernel
|
||||
.Va securelevel
|
||||
setting.
|
||||
See
|
||||
.Xr security 7
|
||||
for more information on this setting.
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std
|
||||
.Sh SEE ALSO
|
||||
.Xr ls 1 ,
|
||||
.Xr chflags 2 ,
|
||||
.Xr stat 2 ,
|
||||
.Xr fts 3 ,
|
||||
.Xr security 7 ,
|
||||
.Xr symlink 7
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command first appeared in
|
||||
.Bx 4.4 .
|
||||
.Sh BUGS
|
||||
Only a limited number of utilities are
|
||||
.Nm
|
||||
aware.
|
||||
Some of these tools include
|
||||
.Xr ls 1 ,
|
||||
.Xr cp 1 ,
|
||||
.Xr find 1 ,
|
||||
.Xr install 1 ,
|
||||
.Xr dump 8 ,
|
||||
and
|
||||
.Xr restore 8 .
|
||||
In particular a tool which is not currently
|
||||
.Nm
|
||||
aware is the
|
||||
.Xr pax 1
|
||||
utility.
|
||||
|
|
@ -1,205 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1992, 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)chflags.c 8.5 (Berkeley) 4/1/94";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fts.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void usage(void);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
FTS *ftsp;
|
||||
FTSENT *p;
|
||||
u_long clear, newflags, set;
|
||||
long val;
|
||||
int Hflag, Lflag, Rflag, fflag, hflag, vflag;
|
||||
int ch, fts_options, oct, rval;
|
||||
char *flags, *ep;
|
||||
int (*change_flags)(const char *, unsigned long);
|
||||
|
||||
Hflag = Lflag = Rflag = fflag = hflag = vflag = 0;
|
||||
while ((ch = getopt(argc, argv, "HLPRfhv")) != -1)
|
||||
switch (ch) {
|
||||
case 'H':
|
||||
Hflag = 1;
|
||||
Lflag = 0;
|
||||
break;
|
||||
case 'L':
|
||||
Lflag = 1;
|
||||
Hflag = 0;
|
||||
break;
|
||||
case 'P':
|
||||
Hflag = Lflag = 0;
|
||||
break;
|
||||
case 'R':
|
||||
Rflag = 1;
|
||||
break;
|
||||
case 'f':
|
||||
fflag = 1;
|
||||
break;
|
||||
case 'h':
|
||||
hflag = 1;
|
||||
break;
|
||||
case 'v':
|
||||
vflag++;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
if (Rflag) {
|
||||
fts_options = FTS_PHYSICAL;
|
||||
if (hflag)
|
||||
errx(1, "the -R and -h options "
|
||||
"may not be specified together");
|
||||
if (Hflag)
|
||||
fts_options |= FTS_COMFOLLOW;
|
||||
if (Lflag) {
|
||||
fts_options &= ~FTS_PHYSICAL;
|
||||
fts_options |= FTS_LOGICAL;
|
||||
}
|
||||
} else
|
||||
fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
|
||||
|
||||
/* XXX: Why don't chflags and lchflags have compatible prototypes? */
|
||||
if (hflag)
|
||||
change_flags = (int (*)(const char *, unsigned long))lchflags;
|
||||
else
|
||||
change_flags = chflags;
|
||||
|
||||
flags = *argv;
|
||||
if (*flags >= '0' && *flags <= '7') {
|
||||
errno = 0;
|
||||
val = strtol(flags, &ep, 8);
|
||||
if (val < 0)
|
||||
errno = ERANGE;
|
||||
if (errno)
|
||||
err(1, "invalid flags: %s", flags);
|
||||
if (*ep)
|
||||
errx(1, "invalid flags: %s", flags);
|
||||
set = val;
|
||||
oct = 1;
|
||||
} else {
|
||||
if (strtofflags(&flags, &set, &clear))
|
||||
errx(1, "invalid flag: %s", flags);
|
||||
clear = ~clear;
|
||||
oct = 0;
|
||||
}
|
||||
|
||||
if ((ftsp = fts_open(++argv, fts_options , 0)) == NULL)
|
||||
err(1, NULL);
|
||||
|
||||
for (rval = 0; (p = fts_read(ftsp)) != NULL;) {
|
||||
switch (p->fts_info) {
|
||||
case FTS_D: /* Change it at FTS_DP if we're recursive. */
|
||||
if (!Rflag)
|
||||
fts_set(ftsp, p, FTS_SKIP);
|
||||
continue;
|
||||
case FTS_DNR: /* Warn, chflag, continue. */
|
||||
warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
|
||||
rval = 1;
|
||||
break;
|
||||
case FTS_ERR: /* Warn, continue. */
|
||||
case FTS_NS:
|
||||
warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
|
||||
rval = 1;
|
||||
continue;
|
||||
case FTS_SL: /* Ignore. */
|
||||
case FTS_SLNONE:
|
||||
/*
|
||||
* The only symlinks that end up here are ones that
|
||||
* don't point to anything and ones that we found
|
||||
* doing a physical walk.
|
||||
*/
|
||||
if (!hflag)
|
||||
continue;
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (oct)
|
||||
newflags = set;
|
||||
else
|
||||
newflags = (p->fts_statp->st_flags | set) & clear;
|
||||
if (newflags == p->fts_statp->st_flags)
|
||||
continue;
|
||||
if ((*change_flags)(p->fts_accpath, newflags) && !fflag) {
|
||||
warn("%s", p->fts_path);
|
||||
rval = 1;
|
||||
} else if (vflag) {
|
||||
(void)printf("%s", p->fts_path);
|
||||
if (vflag > 1)
|
||||
(void)printf(": 0%lo -> 0%lo",
|
||||
(u_long)p->fts_statp->st_flags,
|
||||
newflags);
|
||||
(void)printf("\n");
|
||||
}
|
||||
}
|
||||
if (errno)
|
||||
err(1, "fts_read");
|
||||
exit(rval);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: chflags [-fhv] [-R [-H | -L | -P]] flags file ...\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
# $FreeBSD$
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
|
||||
PROG= chio
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
304
bin/chio/chio.1
304
bin/chio/chio.1
|
|
@ -1,304 +0,0 @@
|
|||
.\" $NetBSD: chio.1,v 1.4 1997/10/02 00:41:25 hubertf Exp $
|
||||
.\"-
|
||||
.\" Copyright (c) 1996 Jason R. Thorpe <thorpej@and.com>
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgements:
|
||||
.\" This product includes software developed by Jason R. Thorpe
|
||||
.\" for And Communications, http://www.and.com/
|
||||
.\" 4. The name of the author may not be used to endorse or promote products
|
||||
.\" derived from this software without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd May 14, 1998
|
||||
.Dt CHIO 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm chio
|
||||
.Nd medium changer control utility
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl f Ar changer
|
||||
.Ar command
|
||||
.Op Fl <flags>
|
||||
.Ar arg1
|
||||
.Ar arg2
|
||||
.Op Ar arg3 Op ...
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility is used to control the operation of medium changers, such as those
|
||||
found in tape and optical disk jukeboxes.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width indent
|
||||
.It Fl f Ar changer
|
||||
Use the device
|
||||
.Ar changer
|
||||
rather than the default device
|
||||
.Pa /dev/ch0 .
|
||||
.El
|
||||
.Pp
|
||||
The default changer may be overridden by setting the environment variable
|
||||
.Ev CHANGER
|
||||
to the desired changer device.
|
||||
.Pp
|
||||
A medium changer apparatus is made up of
|
||||
.Em elements .
|
||||
There are five element types:
|
||||
.Em picker
|
||||
(medium transport),
|
||||
.Em slot
|
||||
(storage),
|
||||
.Em portal
|
||||
(import/export),
|
||||
.Em drive
|
||||
(data transfer), and
|
||||
.Em voltag
|
||||
(select by volume identifier).
|
||||
The
|
||||
.Em voltag
|
||||
pseudo-element type allows the selection of tapes by their volume tag
|
||||
(typically a barcode on the tape).
|
||||
.Pp
|
||||
In this command description, the shorthand
|
||||
.Em ET
|
||||
will be used to represent an element type, and
|
||||
.Em EU
|
||||
will be used to represent an element unit.
|
||||
For example, to represent the first robotic arm in the changer, the
|
||||
.Em ET
|
||||
would be
|
||||
.Dq picker
|
||||
and the
|
||||
.Em EU
|
||||
would be
|
||||
.Dq 0 .
|
||||
.Sh SUPPORTED COMMANDS
|
||||
.Bl -tag -width indent
|
||||
.It Ic move Xo
|
||||
.Ar <from ET> <from EU> <to ET> <to EU>
|
||||
.Op Cm inv
|
||||
.Xc
|
||||
Move the media unit from
|
||||
.Ar <from ET/EU>
|
||||
to
|
||||
.Ar <to ET/EU> .
|
||||
If the optional modifier
|
||||
.Cm inv
|
||||
is specified, the media unit will be inverted before insertion.
|
||||
.It Ic exchange Xo
|
||||
.Ar <src ET> <src EU> <dst1 ET> <dst1 EU>
|
||||
.Op Ar <dst2 ET> <dst2 ET>
|
||||
.Op Cm inv1
|
||||
.Op Cm inv2
|
||||
.Xc
|
||||
Perform a media unit exchange operation.
|
||||
The media unit in
|
||||
.Ar <src ET/EU>
|
||||
is moved to
|
||||
.Ar <dst1 ET/EU>
|
||||
and the media unit previously in
|
||||
.Ar <dst1 ET/EU>
|
||||
is moved to
|
||||
.Ar <dst2 ET/EU> .
|
||||
In the case of a simple exchange,
|
||||
.Ar <dst2 ET/EU>
|
||||
is omitted and the values
|
||||
.Ar <src ET/EU>
|
||||
are used in their place.
|
||||
The optional modifiers
|
||||
.Cm inv1
|
||||
and
|
||||
.Cm inv2
|
||||
specify whether the media units are to be inverted before insertion into
|
||||
.Ar <dst1 ET/EU>
|
||||
and
|
||||
.Ar <dst2 ET/EU>
|
||||
respectively.
|
||||
.Pp
|
||||
Note that not all medium changers support the
|
||||
.Ic exchange
|
||||
operation; the changer must have multiple free pickers or emulate
|
||||
multiple free pickers with transient storage.
|
||||
.It Ic return Xo
|
||||
.Ar <from ET> <from EU>
|
||||
.Xc
|
||||
Return the media unit to its source element.
|
||||
This command will query the status of the specified media unit, and
|
||||
will move it to the element specified in its source attribute.
|
||||
This is a convenient way to return media from a drive or portal
|
||||
to its previous element in the changer.
|
||||
.Pp
|
||||
.It Ic position Xo
|
||||
.Ar <to ET> <to EU>
|
||||
.Op Cm inv
|
||||
.Xc
|
||||
Position the picker in front of the element described by
|
||||
.Ar <to ET/EU> .
|
||||
If the optional modifier
|
||||
.Cm inv
|
||||
is specified, the media unit will be inverted before insertion.
|
||||
.Pp
|
||||
Note that not all changers behave as expected when issued this command.
|
||||
.It Ic params
|
||||
Report the number of slots, drives, pickers, and portals in the changer,
|
||||
and which picker unit the changer is currently configured to use.
|
||||
.It Ic getpicker
|
||||
Report which picker unit the changer is currently configured to use.
|
||||
.It Ic setpicker Xo
|
||||
.Ar <unit>
|
||||
.Xc
|
||||
Configure the changer to use picker
|
||||
.Ar <unit> .
|
||||
.Pp
|
||||
.It Ic ielem Xo
|
||||
.Op Ar <timeout>
|
||||
.Xc
|
||||
Perform an
|
||||
.Em INITIALIZE ELEMENT STATUS
|
||||
operation on the changer.
|
||||
The optional
|
||||
.Ar <timeout>
|
||||
parameter may be given to specify a timeout in seconds for the
|
||||
operations.
|
||||
This may be used if the operation takes unusually long
|
||||
because of buggy firmware or the like.
|
||||
.It Ic voltag Xo
|
||||
.Op Fl fca
|
||||
.Ar <ET>
|
||||
.Ar <EU>
|
||||
.Op Ar <label>
|
||||
.Op Ar <serial>
|
||||
.Xc
|
||||
Change volume tag for an element in the media changer.
|
||||
This command
|
||||
is only supported by few media changers.
|
||||
If it is not supported by a
|
||||
device, using this command will usually result in an "Invalid Field in
|
||||
CDB" error message on the console.
|
||||
.Pp
|
||||
If the
|
||||
.Fl c
|
||||
flag is specified, the volume tag of the specified element is
|
||||
cleared.
|
||||
If the
|
||||
.Fl f
|
||||
flag is specified, the volume tag is superseded with the specified
|
||||
volume tag even if a volume tag is already defined for the element.
|
||||
It is an error to not specify the
|
||||
.Fl f
|
||||
flag when trying to set a label for an element which already has
|
||||
volume tag information defined.
|
||||
.Pp
|
||||
The command works with the primary volume tag or, if the
|
||||
.Fl a
|
||||
flag is given, with the alternate volume tag.
|
||||
.It Ic status Xo
|
||||
.Op Fl vVsSbIa
|
||||
.Op Ar <type>
|
||||
.Xc
|
||||
Report the status of all elements in the changer.
|
||||
If
|
||||
.Ar <type>
|
||||
is specified, report the status of all elements of type
|
||||
.Ar <type> .
|
||||
.It Fl v
|
||||
Print the primary volume tag for each loaded medium, if any.
|
||||
The volume
|
||||
tag is printed as
|
||||
.Dq <LABEL:SERIAL> .
|
||||
.It Fl V
|
||||
Print the alternate volume tag for each loaded medium, if any.
|
||||
.It Fl s
|
||||
Print the additional sense code and additional sense code qualifier for
|
||||
each element.
|
||||
.It Fl S
|
||||
Print the element source address for each element.
|
||||
.It Fl b
|
||||
Print SCSI bus information for each element.
|
||||
Note that this information
|
||||
is valid only for drives.
|
||||
.It Fl I
|
||||
Print the internal element addresses for each element.
|
||||
The internal
|
||||
element address is not normally used with this driver.
|
||||
It is reported
|
||||
for diagnostic purposes only.
|
||||
.It Fl a
|
||||
Print all additional information (as in
|
||||
.Fl vVsSba ) .
|
||||
.El
|
||||
.Pp
|
||||
The status bits are defined as follows:
|
||||
.Bl -tag -width indent
|
||||
.It FULL
|
||||
Element contains a media unit.
|
||||
.It IMPEXP
|
||||
Media was deposited into element by an outside human operator.
|
||||
.It EXCEPT
|
||||
Element is in an abnormal state.
|
||||
.It ACCESS
|
||||
Media in this element is accessible by a picker.
|
||||
.It EXENAB
|
||||
Element supports passing media (exporting) to an outside human operator.
|
||||
.It INENAB
|
||||
Element supports receiving media (importing) from an outside human operator.
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width /dev/ch0 -compact
|
||||
.It Pa /dev/ch0
|
||||
default changer device
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
.Bl -tag -width indent
|
||||
.It Li chio move slot 3 drive 0
|
||||
Move the media in slot 3 (fourth slot) to drive 0 (first drive).
|
||||
.It Li chio move voltag VOLUME01 drive 0
|
||||
Move the media with the barcode VOLUME01 to drive 0 (first drive).
|
||||
.It Li chio return drive 0
|
||||
Remove the tape from drive 0 (first drive) and return it to its original
|
||||
location in the rack.
|
||||
.It Li chio setpicker 2
|
||||
Configure the changer to use picker 2 (third picker) for operations.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr mt 1 ,
|
||||
.Xr mount 8
|
||||
.Sh AUTHORS
|
||||
.An -nosplit
|
||||
The
|
||||
.Nm
|
||||
program and SCSI changer driver were written by
|
||||
.An Jason R. Thorpe Aq thorpej@and.com
|
||||
for And Communications,
|
||||
.Pa http://www.and.com/ .
|
||||
.Pp
|
||||
Additional work by
|
||||
.An Hans Huebner
|
||||
.Aq hans@artcom.de
|
||||
and
|
||||
.An Steve Gunn
|
||||
.Aq csg@waterspout.com .
|
||||
1179
bin/chio/chio.c
1179
bin/chio/chio.c
File diff suppressed because it is too large
Load diff
|
|
@ -1,57 +0,0 @@
|
|||
/* $FreeBSD$ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996 Jason R. Thorpe <thorpej@and.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgements:
|
||||
* This product includes software developed by Jason R. Thorpe
|
||||
* for And Communications, http://www.and.com/
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
struct element_type {
|
||||
const char *et_name; /* name; i.e. "picker, "slot", etc. */
|
||||
int et_type; /* type number */
|
||||
};
|
||||
|
||||
struct changer_command {
|
||||
const char *cc_name; /* command name */
|
||||
/* command handler */
|
||||
int (*cc_handler)(const char *, int, char **);
|
||||
};
|
||||
|
||||
struct special_word {
|
||||
const char *sw_name; /* special word */
|
||||
int sw_value; /* token value */
|
||||
};
|
||||
|
||||
/* sw_value */
|
||||
#define SW_INVERT 1 /* set "invert media" flag */
|
||||
#define SW_INVERT1 2 /* set "invert media 1" flag */
|
||||
#define SW_INVERT2 3 /* set "invert media 2" flag */
|
||||
|
||||
/* Environment variable to check for default changer. */
|
||||
#define CHANGER_ENV_VAR "CHANGER"
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/* $FreeBSD$ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1996 Jason R. Thorpe <thorpej@and.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgements:
|
||||
* This product includes software developed by Jason R. Thorpe
|
||||
* for And Communications, http://www.and.com/
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define _PATH_CH "/dev/ch0"
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= chmod
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,350 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 1989, 1990, 1993, 1994
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" the Institute of Electrical and Electronics Engineers, Inc.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)chmod.1 8.4 (Berkeley) 3/31/94
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd January 26, 2009
|
||||
.Dt CHMOD 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm chmod
|
||||
.Nd change file modes
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl fhv
|
||||
.Op Fl R Op Fl H | L | P
|
||||
.Ar mode
|
||||
.Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility modifies the file mode bits of the listed files
|
||||
as specified by the
|
||||
.Ar mode
|
||||
operand.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width indent
|
||||
.It Fl f
|
||||
Do not display a diagnostic message if
|
||||
.Nm
|
||||
could not modify the mode for
|
||||
.Va file ,
|
||||
nor modify the exit status to reflect such failures.
|
||||
.It Fl H
|
||||
If the
|
||||
.Fl R
|
||||
option is specified, symbolic links on the command line are followed.
|
||||
(Symbolic links encountered in the tree traversal are not followed by
|
||||
default.)
|
||||
.It Fl h
|
||||
If the file is a symbolic link, change the mode of the link itself
|
||||
rather than the file that the link points to.
|
||||
.It Fl L
|
||||
If the
|
||||
.Fl R
|
||||
option is specified, all symbolic links are followed.
|
||||
.It Fl P
|
||||
If the
|
||||
.Fl R
|
||||
option is specified, no symbolic links are followed.
|
||||
This is the default.
|
||||
.It Fl R
|
||||
Change the modes of the file hierarchies rooted in the files
|
||||
instead of just the files themselves.
|
||||
.It Fl v
|
||||
Cause
|
||||
.Nm
|
||||
to be verbose, showing filenames as the mode is modified.
|
||||
If the
|
||||
.Fl v
|
||||
flag is specified more than once, the old and new modes of the file
|
||||
will also be printed, in both octal and symbolic notation.
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
.Fl H ,
|
||||
.Fl L
|
||||
and
|
||||
.Fl P
|
||||
options are ignored unless the
|
||||
.Fl R
|
||||
option is specified.
|
||||
In addition, these options override each other and the
|
||||
command's actions are determined by the last one specified.
|
||||
.Pp
|
||||
Only the owner of a file or the super-user is permitted to change
|
||||
the mode of a file.
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std
|
||||
.Sh MODES
|
||||
Modes may be absolute or symbolic.
|
||||
An absolute mode is an octal number constructed from the sum of
|
||||
one or more of the following values:
|
||||
.Pp
|
||||
.Bl -tag -width 6n -compact -offset indent
|
||||
.It Li 4000
|
||||
(the setuid bit).
|
||||
Executable files with this bit set
|
||||
will run with effective uid set to the uid of the file owner.
|
||||
Directories with this bit set will force all files and
|
||||
sub-directories created in them to be owned by the directory owner
|
||||
and not by the uid of the creating process, if the underlying file
|
||||
system supports this feature: see
|
||||
.Xr chmod 2
|
||||
and the
|
||||
.Cm suiddir
|
||||
option to
|
||||
.Xr mount 8 .
|
||||
.It Li 2000
|
||||
(the setgid bit).
|
||||
Executable files with this bit set
|
||||
will run with effective gid set to the gid of the file owner.
|
||||
.It Li 1000
|
||||
(the sticky bit).
|
||||
See
|
||||
.Xr chmod 2
|
||||
and
|
||||
.Xr sticky 8 .
|
||||
.It Li 0400
|
||||
Allow read by owner.
|
||||
.It Li 0200
|
||||
Allow write by owner.
|
||||
.It Li 0100
|
||||
For files, allow execution by owner.
|
||||
For directories, allow the owner to
|
||||
search in the directory.
|
||||
.It Li 0040
|
||||
Allow read by group members.
|
||||
.It Li 0020
|
||||
Allow write by group members.
|
||||
.It Li 0010
|
||||
For files, allow execution by group members.
|
||||
For directories, allow
|
||||
group members to search in the directory.
|
||||
.It Li 0004
|
||||
Allow read by others.
|
||||
.It Li 0002
|
||||
Allow write by others.
|
||||
.It Li 0001
|
||||
For files, allow execution by others.
|
||||
For directories allow others to
|
||||
search in the directory.
|
||||
.El
|
||||
.Pp
|
||||
For example, the absolute mode that permits read, write and execute by
|
||||
the owner, read and execute by group members, read and execute by
|
||||
others, and no set-uid or set-gid behaviour is 755
|
||||
(400+200+100+040+010+004+001).
|
||||
.Pp
|
||||
The symbolic mode is described by the following grammar:
|
||||
.Bd -literal -offset indent
|
||||
mode ::= clause [, clause ...]
|
||||
clause ::= [who ...] [action ...] action
|
||||
action ::= op [perm ...]
|
||||
who ::= a | u | g | o
|
||||
op ::= + | \- | =
|
||||
perm ::= r | s | t | w | x | X | u | g | o
|
||||
.Ed
|
||||
.Pp
|
||||
The
|
||||
.Ar who
|
||||
symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
|
||||
of the mode bits, respectively.
|
||||
The
|
||||
.Ar who
|
||||
symbol ``a'' is equivalent to ``ugo''.
|
||||
.Pp
|
||||
The
|
||||
.Ar perm
|
||||
symbols represent the portions of the mode bits as follows:
|
||||
.Pp
|
||||
.Bl -tag -width Ds -compact -offset indent
|
||||
.It r
|
||||
The read bits.
|
||||
.It s
|
||||
The set-user-ID-on-execution and set-group-ID-on-execution bits.
|
||||
.It t
|
||||
The sticky bit.
|
||||
.It w
|
||||
The write bits.
|
||||
.It x
|
||||
The execute/search bits.
|
||||
.It X
|
||||
The execute/search bits if the file is a directory or any of the
|
||||
execute/search bits are set in the original (unmodified) mode.
|
||||
Operations with the
|
||||
.Ar perm
|
||||
symbol ``X'' are only meaningful in conjunction with the
|
||||
.Ar op
|
||||
symbol ``+'', and are ignored in all other cases.
|
||||
.It u
|
||||
The user permission bits in the original mode of the file.
|
||||
.It g
|
||||
The group permission bits in the original mode of the file.
|
||||
.It o
|
||||
The other permission bits in the original mode of the file.
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
.Ar op
|
||||
symbols represent the operation performed, as follows:
|
||||
.Bl -tag -width 4n
|
||||
.It +
|
||||
If no value is supplied for
|
||||
.Ar perm ,
|
||||
the ``+'' operation has no effect.
|
||||
If no value is supplied for
|
||||
.Ar who ,
|
||||
each permission bit specified in
|
||||
.Ar perm ,
|
||||
for which the corresponding bit in the file mode creation mask
|
||||
(see
|
||||
.Xr umask 2 )
|
||||
is clear, is set.
|
||||
Otherwise, the mode bits represented by the specified
|
||||
.Ar who
|
||||
and
|
||||
.Ar perm
|
||||
values are set.
|
||||
.It \&\-
|
||||
If no value is supplied for
|
||||
.Ar perm ,
|
||||
the ``\-'' operation has no effect.
|
||||
If no value is supplied for
|
||||
.Ar who ,
|
||||
each permission bit specified in
|
||||
.Ar perm ,
|
||||
for which the corresponding bit in the file mode creation mask
|
||||
is clear, is cleared.
|
||||
Otherwise, the mode bits represented by the specified
|
||||
.Ar who
|
||||
and
|
||||
.Ar perm
|
||||
values are cleared.
|
||||
.It =
|
||||
The mode bits specified by the
|
||||
.Ar who
|
||||
value are cleared, or, if no
|
||||
.Ar who
|
||||
value is specified, the owner, group
|
||||
and other mode bits are cleared.
|
||||
Then, if no value is supplied for
|
||||
.Ar who ,
|
||||
each permission bit specified in
|
||||
.Ar perm ,
|
||||
for which the corresponding bit in the file mode creation mask
|
||||
is clear, is set.
|
||||
Otherwise, the mode bits represented by the specified
|
||||
.Ar who
|
||||
and
|
||||
.Ar perm
|
||||
values are set.
|
||||
.El
|
||||
.Pp
|
||||
Each
|
||||
.Ar clause
|
||||
specifies one or more operations to be performed on the mode
|
||||
bits, and each operation is applied to the mode bits in the
|
||||
order specified.
|
||||
.Pp
|
||||
Operations upon the other permissions only (specified by the symbol
|
||||
``o'' by itself), in combination with the
|
||||
.Ar perm
|
||||
symbols ``s'' or ``t'', are ignored.
|
||||
.Pp
|
||||
The ``w'' permission on directories will permit file creation, relocation,
|
||||
and copy into that directory.
|
||||
Files created within the directory itself will inherit its group ID.
|
||||
.Sh EXAMPLES
|
||||
.Bl -tag -width "u=rwx,go=u-w" -compact
|
||||
.It Li 644
|
||||
make a file readable by anyone and writable by the owner only.
|
||||
.Pp
|
||||
.It Li go-w
|
||||
deny write permission to group and others.
|
||||
.Pp
|
||||
.It Li =rw,+X
|
||||
set the read and write permissions to the usual defaults, but
|
||||
retain any execute permissions that are currently set.
|
||||
.Pp
|
||||
.It Li +X
|
||||
make a directory or file searchable/executable by everyone if it is
|
||||
already searchable/executable by anyone.
|
||||
.Pp
|
||||
.It Li 755
|
||||
.It Li u=rwx,go=rx
|
||||
.It Li u=rwx,go=u-w
|
||||
make a file readable/executable by everyone and writable by the owner only.
|
||||
.Pp
|
||||
.It Li go=
|
||||
clear all mode bits for group and others.
|
||||
.Pp
|
||||
.It Li g=u-w
|
||||
set the group bits equal to the user bits, but clear the group write bit.
|
||||
.El
|
||||
.Sh COMPATIBILITY
|
||||
The
|
||||
.Fl v
|
||||
option is non-standard and its use in scripts is not recommended.
|
||||
.Sh SEE ALSO
|
||||
.Xr chflags 1 ,
|
||||
.Xr install 1 ,
|
||||
.Xr setfacl 1 ,
|
||||
.Xr chmod 2 ,
|
||||
.Xr stat 2 ,
|
||||
.Xr umask 2 ,
|
||||
.Xr fts 3 ,
|
||||
.Xr setmode 3 ,
|
||||
.Xr symlink 7 ,
|
||||
.Xr chown 8 ,
|
||||
.Xr mount 8 ,
|
||||
.Xr sticky 8
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility is expected to be
|
||||
.St -p1003.2
|
||||
compatible with the exception of the
|
||||
.Ar perm
|
||||
symbol
|
||||
.Dq t
|
||||
which is not included in that standard.
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm
|
||||
command appeared in
|
||||
.At v1 .
|
||||
.Sh BUGS
|
||||
There is no
|
||||
.Ar perm
|
||||
option for the naughty bits of a horse.
|
||||
|
|
@ -1,248 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1989, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char const copyright[] =
|
||||
"@(#) Copyright (c) 1989, 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)chmod.c 8.8 (Berkeley) 4/1/94";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fts.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void usage(void);
|
||||
static int may_have_nfs4acl(const FTSENT *ent, int hflag);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
FTS *ftsp;
|
||||
FTSENT *p;
|
||||
mode_t *set;
|
||||
int Hflag, Lflag, Rflag, ch, error, fflag, fts_options, hflag, rval;
|
||||
int vflag;
|
||||
char *mode;
|
||||
mode_t newmode;
|
||||
|
||||
set = NULL;
|
||||
Hflag = Lflag = Rflag = fflag = hflag = vflag = 0;
|
||||
while ((ch = getopt(argc, argv, "HLPRXfghorstuvwx")) != -1)
|
||||
switch (ch) {
|
||||
case 'H':
|
||||
Hflag = 1;
|
||||
Lflag = 0;
|
||||
break;
|
||||
case 'L':
|
||||
Lflag = 1;
|
||||
Hflag = 0;
|
||||
break;
|
||||
case 'P':
|
||||
Hflag = Lflag = 0;
|
||||
break;
|
||||
case 'R':
|
||||
Rflag = 1;
|
||||
break;
|
||||
case 'f':
|
||||
fflag = 1;
|
||||
break;
|
||||
case 'h':
|
||||
/*
|
||||
* In System V (and probably POSIX.2) the -h option
|
||||
* causes chmod to change the mode of the symbolic
|
||||
* link. 4.4BSD's symbolic links didn't have modes,
|
||||
* so it was an undocumented noop. In FreeBSD 3.0,
|
||||
* lchmod(2) is introduced and this option does real
|
||||
* work.
|
||||
*/
|
||||
hflag = 1;
|
||||
break;
|
||||
/*
|
||||
* XXX
|
||||
* "-[rwx]" are valid mode commands. If they are the entire
|
||||
* argument, getopt has moved past them, so decrement optind.
|
||||
* Regardless, we're done argument processing.
|
||||
*/
|
||||
case 'g': case 'o': case 'r': case 's':
|
||||
case 't': case 'u': case 'w': case 'X': case 'x':
|
||||
if (argv[optind - 1][0] == '-' &&
|
||||
argv[optind - 1][1] == ch &&
|
||||
argv[optind - 1][2] == '\0')
|
||||
--optind;
|
||||
goto done;
|
||||
case 'v':
|
||||
vflag++;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
done: argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
if (Rflag) {
|
||||
fts_options = FTS_PHYSICAL;
|
||||
if (hflag)
|
||||
errx(1,
|
||||
"the -R and -h options may not be specified together.");
|
||||
if (Hflag)
|
||||
fts_options |= FTS_COMFOLLOW;
|
||||
if (Lflag) {
|
||||
fts_options &= ~FTS_PHYSICAL;
|
||||
fts_options |= FTS_LOGICAL;
|
||||
}
|
||||
} else
|
||||
fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
|
||||
|
||||
mode = *argv;
|
||||
if ((set = setmode(mode)) == NULL)
|
||||
errx(1, "invalid file mode: %s", mode);
|
||||
|
||||
if ((ftsp = fts_open(++argv, fts_options, 0)) == NULL)
|
||||
err(1, "fts_open");
|
||||
for (rval = 0; (p = fts_read(ftsp)) != NULL;) {
|
||||
switch (p->fts_info) {
|
||||
case FTS_D: /* Change it at FTS_DP. */
|
||||
if (!Rflag)
|
||||
fts_set(ftsp, p, FTS_SKIP);
|
||||
continue;
|
||||
case FTS_DNR: /* Warn, chmod, continue. */
|
||||
warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
|
||||
rval = 1;
|
||||
break;
|
||||
case FTS_ERR: /* Warn, continue. */
|
||||
case FTS_NS:
|
||||
warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
|
||||
rval = 1;
|
||||
continue;
|
||||
case FTS_SL: /* Ignore. */
|
||||
case FTS_SLNONE:
|
||||
/*
|
||||
* The only symlinks that end up here are ones that
|
||||
* don't point to anything and ones that we found
|
||||
* doing a physical walk.
|
||||
*/
|
||||
if (!hflag)
|
||||
continue;
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
newmode = getmode(set, p->fts_statp->st_mode);
|
||||
/*
|
||||
* With NFSv4 ACLs, it is possible that applying a mode
|
||||
* identical to the one computed from an ACL will change
|
||||
* that ACL.
|
||||
*/
|
||||
if (may_have_nfs4acl(p, hflag) == 0 &&
|
||||
(newmode & ALLPERMS) == (p->fts_statp->st_mode & ALLPERMS))
|
||||
continue;
|
||||
if (hflag)
|
||||
error = lchmod(p->fts_accpath, newmode);
|
||||
else
|
||||
error = chmod(p->fts_accpath, newmode);
|
||||
if (error) {
|
||||
if (!fflag) {
|
||||
warn("%s", p->fts_path);
|
||||
rval = 1;
|
||||
}
|
||||
} else {
|
||||
if (vflag) {
|
||||
(void)printf("%s", p->fts_path);
|
||||
|
||||
if (vflag > 1) {
|
||||
char m1[12], m2[12];
|
||||
|
||||
strmode(p->fts_statp->st_mode, m1);
|
||||
strmode((p->fts_statp->st_mode &
|
||||
S_IFMT) | newmode, m2);
|
||||
(void)printf(": 0%o [%s] -> 0%o [%s]",
|
||||
p->fts_statp->st_mode, m1,
|
||||
(p->fts_statp->st_mode & S_IFMT) |
|
||||
newmode, m2);
|
||||
}
|
||||
(void)printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (errno)
|
||||
err(1, "fts_read");
|
||||
exit(rval);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: chmod [-fhv] [-R [-H | -L | -P]] mode file ...\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static int
|
||||
may_have_nfs4acl(const FTSENT *ent, int hflag)
|
||||
{
|
||||
int ret;
|
||||
static dev_t previous_dev = NODEV;
|
||||
static int supports_acls = -1;
|
||||
|
||||
if (previous_dev != ent->fts_statp->st_dev) {
|
||||
previous_dev = ent->fts_statp->st_dev;
|
||||
supports_acls = 0;
|
||||
|
||||
if (hflag)
|
||||
ret = lpathconf(ent->fts_accpath, _PC_ACL_NFS4);
|
||||
else
|
||||
ret = pathconf(ent->fts_accpath, _PC_ACL_NFS4);
|
||||
if (ret > 0)
|
||||
supports_acls = 1;
|
||||
else if (ret < 0 && errno != EINVAL)
|
||||
warn("%s", ent->fts_path);
|
||||
}
|
||||
|
||||
return (supports_acls);
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= cp
|
||||
SRCS= cp.c utils.c
|
||||
CFLAGS+= -DVM_AND_BUFFER_CACHE_SYNCHRONIZED -D_ACL_PRIVATE
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
300
bin/cp/cp.1
300
bin/cp/cp.1
|
|
@ -1,300 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 1989, 1990, 1993, 1994
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" the Institute of Electrical and Electronics Engineers, Inc.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)cp.1 8.3 (Berkeley) 4/18/94
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd January 17, 2010
|
||||
.Dt CP 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm cp
|
||||
.Nd copy files
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Oo
|
||||
.Fl R
|
||||
.Op Fl H | Fl L | Fl P
|
||||
.Oc
|
||||
.Op Fl f | i | n
|
||||
.Op Fl alpvx
|
||||
.Ar source_file target_file
|
||||
.Nm
|
||||
.Oo
|
||||
.Fl R
|
||||
.Op Fl H | Fl L | Fl P
|
||||
.Oc
|
||||
.Op Fl f | i | n
|
||||
.Op Fl alpvx
|
||||
.Ar source_file ... target_directory
|
||||
.Sh DESCRIPTION
|
||||
In the first synopsis form, the
|
||||
.Nm
|
||||
utility copies the contents of the
|
||||
.Ar source_file
|
||||
to the
|
||||
.Ar target_file .
|
||||
In the second synopsis form,
|
||||
the contents of each named
|
||||
.Ar source_file
|
||||
is copied to the destination
|
||||
.Ar target_directory .
|
||||
The names of the files themselves are not changed.
|
||||
If
|
||||
.Nm
|
||||
detects an attempt to copy a file to itself, the copy will fail.
|
||||
.Pp
|
||||
The following options are available:
|
||||
.Bl -tag -width flag
|
||||
.It Fl H
|
||||
If the
|
||||
.Fl R
|
||||
option is specified, symbolic links on the command line are followed.
|
||||
(Symbolic links encountered in the tree traversal are not followed.)
|
||||
.It Fl L
|
||||
If the
|
||||
.Fl R
|
||||
option is specified, all symbolic links are followed.
|
||||
.It Fl P
|
||||
If the
|
||||
.Fl R
|
||||
option is specified, no symbolic links are followed.
|
||||
This is the default.
|
||||
.It Fl R
|
||||
If
|
||||
.Ar source_file
|
||||
designates a directory,
|
||||
.Nm
|
||||
copies the directory and the entire subtree connected at that point.
|
||||
If the
|
||||
.Ar source_file
|
||||
ends in a
|
||||
.Pa / ,
|
||||
the contents of the directory are copied rather than the
|
||||
directory itself.
|
||||
This option also causes symbolic links to be copied, rather than
|
||||
indirected through, and for
|
||||
.Nm
|
||||
to create special files rather than copying them as normal files.
|
||||
Created directories have the same mode as the corresponding source
|
||||
directory, unmodified by the process' umask.
|
||||
.Pp
|
||||
Note that
|
||||
.Nm
|
||||
copies hard linked files as separate files.
|
||||
If you need to preserve hard links, consider using
|
||||
.Xr tar 1 ,
|
||||
.Xr cpio 1 ,
|
||||
or
|
||||
.Xr pax 1
|
||||
instead.
|
||||
.It Fl a
|
||||
Archive mode.
|
||||
Same as
|
||||
.Fl RpP .
|
||||
.It Fl f
|
||||
For each existing destination pathname, remove it and
|
||||
create a new file, without prompting for confirmation
|
||||
regardless of its permissions.
|
||||
(The
|
||||
.Fl f
|
||||
option overrides any previous
|
||||
.Fl i
|
||||
or
|
||||
.Fl n
|
||||
options.)
|
||||
.It Fl i
|
||||
Cause
|
||||
.Nm
|
||||
to write a prompt to the standard error output before copying a file
|
||||
that would overwrite an existing file.
|
||||
If the response from the standard input begins with the character
|
||||
.Sq Li y
|
||||
or
|
||||
.Sq Li Y ,
|
||||
the file copy is attempted.
|
||||
(The
|
||||
.Fl i
|
||||
option overrides any previous
|
||||
.Fl f
|
||||
or
|
||||
.Fl n
|
||||
options.)
|
||||
.It Fl l
|
||||
Create hard links to regular files in a hierarchy instead of copying.
|
||||
.It Fl n
|
||||
Do not overwrite an existing file.
|
||||
(The
|
||||
.Fl n
|
||||
option overrides any previous
|
||||
.Fl f
|
||||
or
|
||||
.Fl i
|
||||
options.)
|
||||
.It Fl p
|
||||
Cause
|
||||
.Nm
|
||||
to preserve the following attributes of each source
|
||||
file in the copy: modification time, access time,
|
||||
file flags, file mode, user ID, and group ID, as allowed by permissions.
|
||||
.Pp
|
||||
If the user ID and group ID cannot be preserved, no error message
|
||||
is displayed and the exit value is not altered.
|
||||
.Pp
|
||||
If the source file has its set-user-ID bit on and the user ID cannot
|
||||
be preserved, the set-user-ID bit is not preserved
|
||||
in the copy's permissions.
|
||||
If the source file has its set-group-ID bit on and the group ID cannot
|
||||
be preserved, the set-group-ID bit is not preserved
|
||||
in the copy's permissions.
|
||||
If the source file has both its set-user-ID and set-group-ID bits on,
|
||||
and either the user ID or group ID cannot be preserved, neither
|
||||
the set-user-ID nor set-group-ID bits are preserved in the copy's
|
||||
permissions.
|
||||
.It Fl v
|
||||
Cause
|
||||
.Nm
|
||||
to be verbose, showing files as they are copied.
|
||||
.It Fl x
|
||||
File system mount points are not traversed.
|
||||
.El
|
||||
.Pp
|
||||
For each destination file that already exists, its contents are
|
||||
overwritten if permissions allow.
|
||||
Its mode, user ID, and group
|
||||
ID are unchanged unless the
|
||||
.Fl p
|
||||
option was specified.
|
||||
.Pp
|
||||
In the second synopsis form,
|
||||
.Ar target_directory
|
||||
must exist unless there is only one named
|
||||
.Ar source_file
|
||||
which is a directory and the
|
||||
.Fl R
|
||||
flag is specified.
|
||||
.Pp
|
||||
If the destination file does not exist, the mode of the source file is
|
||||
used as modified by the file mode creation mask
|
||||
.Pf ( Ic umask ,
|
||||
see
|
||||
.Xr csh 1 ) .
|
||||
If the source file has its set-user-ID bit on, that bit is removed
|
||||
unless both the source file and the destination file are owned by the
|
||||
same user.
|
||||
If the source file has its set-group-ID bit on, that bit is removed
|
||||
unless both the source file and the destination file are in the same
|
||||
group and the user is a member of that group.
|
||||
If both the set-user-ID and set-group-ID bits are set, all of the above
|
||||
conditions must be fulfilled or both bits are removed.
|
||||
.Pp
|
||||
Appropriate permissions are required for file creation or overwriting.
|
||||
.Pp
|
||||
Symbolic links are always followed unless the
|
||||
.Fl R
|
||||
flag is set, in which case symbolic links are not followed, by default.
|
||||
The
|
||||
.Fl H
|
||||
or
|
||||
.Fl L
|
||||
flags (in conjunction with the
|
||||
.Fl R
|
||||
flag) cause symbolic links to be followed as described above.
|
||||
The
|
||||
.Fl H ,
|
||||
.Fl L
|
||||
and
|
||||
.Fl P
|
||||
options are ignored unless the
|
||||
.Fl R
|
||||
option is specified.
|
||||
In addition, these options override each other and the
|
||||
command's actions are determined by the last one specified.
|
||||
.Pp
|
||||
If
|
||||
.Nm
|
||||
receives a
|
||||
.Dv SIGINFO
|
||||
(see the
|
||||
.Cm status
|
||||
argument for
|
||||
.Xr stty 1 )
|
||||
signal, the current input and output file and the percentage complete
|
||||
will be written to the standard output.
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std
|
||||
.Sh COMPATIBILITY
|
||||
Historic versions of the
|
||||
.Nm
|
||||
utility had a
|
||||
.Fl r
|
||||
option.
|
||||
This implementation supports that option, however, its behavior
|
||||
is different from historical
|
||||
.Fx
|
||||
behavior.
|
||||
Use of this option
|
||||
is strongly discouraged as the behavior is
|
||||
implementation-dependent.
|
||||
In
|
||||
.Fx ,
|
||||
.Fl r
|
||||
is a synonym for
|
||||
.Fl RL
|
||||
and works the same unless modified by other flags.
|
||||
Historical implementations
|
||||
of
|
||||
.Fl r
|
||||
differ as they copy special files as normal
|
||||
files while recreating a hierarchy.
|
||||
.Pp
|
||||
The
|
||||
.Fl v
|
||||
and
|
||||
.Fl n
|
||||
options are non-standard and their use in scripts is not recommended.
|
||||
.Sh SEE ALSO
|
||||
.Xr mv 1 ,
|
||||
.Xr rcp 1 ,
|
||||
.Xr umask 2 ,
|
||||
.Xr fts 3 ,
|
||||
.Xr symlink 7
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
command is expected to be
|
||||
.St -p1003.2
|
||||
compatible.
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm
|
||||
command appeared in
|
||||
.At v1 .
|
||||
524
bin/cp/cp.c
524
bin/cp/cp.c
|
|
@ -1,524 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1988, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* David Hitz of Auspex Systems Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char const copyright[] =
|
||||
"@(#) Copyright (c) 1988, 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)cp.c 8.2 (Berkeley) 4/1/94";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* Cp copies source files to target files.
|
||||
*
|
||||
* The global PATH_T structure "to" always contains the path to the
|
||||
* current target file. Since fts(3) does not change directories,
|
||||
* this path can be either absolute or dot-relative.
|
||||
*
|
||||
* The basic algorithm is to initialize "to" and use fts(3) to traverse
|
||||
* the file hierarchy rooted in the argument list. A trivial case is the
|
||||
* case of 'cp file1 file2'. The more interesting case is the case of
|
||||
* 'cp file1 file2 ... fileN dir' where the hierarchy is traversed and the
|
||||
* path (relative to the root of the traversal) is appended to dir (stored
|
||||
* in "to") to form the final target path.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fts.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
#define STRIP_TRAILING_SLASH(p) { \
|
||||
while ((p).p_end > (p).p_path + 1 && (p).p_end[-1] == '/') \
|
||||
*--(p).p_end = 0; \
|
||||
}
|
||||
|
||||
static char emptystring[] = "";
|
||||
|
||||
PATH_T to = { to.p_path, emptystring, "" };
|
||||
|
||||
int fflag, iflag, lflag, nflag, pflag, vflag;
|
||||
static int Rflag, rflag;
|
||||
volatile sig_atomic_t info;
|
||||
|
||||
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
|
||||
|
||||
static int copy(char *[], enum op, int);
|
||||
static int mastercmp(const FTSENT * const *, const FTSENT * const *);
|
||||
static void siginfo(int __unused);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct stat to_stat, tmp_stat;
|
||||
enum op type;
|
||||
int Hflag, Lflag, Pflag, ch, fts_options, r, have_trailing_slash;
|
||||
char *target;
|
||||
|
||||
fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
|
||||
Hflag = Lflag = Pflag = 0;
|
||||
while ((ch = getopt(argc, argv, "HLPRafilnprvx")) != -1)
|
||||
switch (ch) {
|
||||
case 'H':
|
||||
Hflag = 1;
|
||||
Lflag = Pflag = 0;
|
||||
break;
|
||||
case 'L':
|
||||
Lflag = 1;
|
||||
Hflag = Pflag = 0;
|
||||
break;
|
||||
case 'P':
|
||||
Pflag = 1;
|
||||
Hflag = Lflag = 0;
|
||||
break;
|
||||
case 'R':
|
||||
Rflag = 1;
|
||||
break;
|
||||
case 'a':
|
||||
Pflag = 1;
|
||||
pflag = 1;
|
||||
Rflag = 1;
|
||||
Hflag = Lflag = 0;
|
||||
break;
|
||||
case 'f':
|
||||
fflag = 1;
|
||||
iflag = nflag = 0;
|
||||
break;
|
||||
case 'i':
|
||||
iflag = 1;
|
||||
fflag = nflag = 0;
|
||||
break;
|
||||
case 'l':
|
||||
lflag = 1;
|
||||
break;
|
||||
case 'n':
|
||||
nflag = 1;
|
||||
fflag = iflag = 0;
|
||||
break;
|
||||
case 'p':
|
||||
pflag = 1;
|
||||
break;
|
||||
case 'r':
|
||||
rflag = Lflag = 1;
|
||||
Hflag = Pflag = 0;
|
||||
break;
|
||||
case 'v':
|
||||
vflag = 1;
|
||||
break;
|
||||
case 'x':
|
||||
fts_options |= FTS_XDEV;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
if (Rflag && rflag)
|
||||
errx(1, "the -R and -r options may not be specified together");
|
||||
if (rflag)
|
||||
Rflag = 1;
|
||||
if (Rflag) {
|
||||
if (Hflag)
|
||||
fts_options |= FTS_COMFOLLOW;
|
||||
if (Lflag) {
|
||||
fts_options &= ~FTS_PHYSICAL;
|
||||
fts_options |= FTS_LOGICAL;
|
||||
}
|
||||
} else {
|
||||
fts_options &= ~FTS_PHYSICAL;
|
||||
fts_options |= FTS_LOGICAL | FTS_COMFOLLOW;
|
||||
}
|
||||
(void)signal(SIGINFO, siginfo);
|
||||
|
||||
/* Save the target base in "to". */
|
||||
target = argv[--argc];
|
||||
if (strlcpy(to.p_path, target, sizeof(to.p_path)) >= sizeof(to.p_path))
|
||||
errx(1, "%s: name too long", target);
|
||||
to.p_end = to.p_path + strlen(to.p_path);
|
||||
if (to.p_path == to.p_end) {
|
||||
*to.p_end++ = '.';
|
||||
*to.p_end = 0;
|
||||
}
|
||||
have_trailing_slash = (to.p_end[-1] == '/');
|
||||
if (have_trailing_slash)
|
||||
STRIP_TRAILING_SLASH(to);
|
||||
to.target_end = to.p_end;
|
||||
|
||||
/* Set end of argument list for fts(3). */
|
||||
argv[argc] = NULL;
|
||||
|
||||
/*
|
||||
* Cp has two distinct cases:
|
||||
*
|
||||
* cp [-R] source target
|
||||
* cp [-R] source1 ... sourceN directory
|
||||
*
|
||||
* In both cases, source can be either a file or a directory.
|
||||
*
|
||||
* In (1), the target becomes a copy of the source. That is, if the
|
||||
* source is a file, the target will be a file, and likewise for
|
||||
* directories.
|
||||
*
|
||||
* In (2), the real target is not directory, but "directory/source".
|
||||
*/
|
||||
r = stat(to.p_path, &to_stat);
|
||||
if (r == -1 && errno != ENOENT)
|
||||
err(1, "%s", to.p_path);
|
||||
if (r == -1 || !S_ISDIR(to_stat.st_mode)) {
|
||||
/*
|
||||
* Case (1). Target is not a directory.
|
||||
*/
|
||||
if (argc > 1)
|
||||
errx(1, "%s is not a directory", to.p_path);
|
||||
|
||||
/*
|
||||
* Need to detect the case:
|
||||
* cp -R dir foo
|
||||
* Where dir is a directory and foo does not exist, where
|
||||
* we want pathname concatenations turned on but not for
|
||||
* the initial mkdir().
|
||||
*/
|
||||
if (r == -1) {
|
||||
if (Rflag && (Lflag || Hflag))
|
||||
stat(*argv, &tmp_stat);
|
||||
else
|
||||
lstat(*argv, &tmp_stat);
|
||||
|
||||
if (S_ISDIR(tmp_stat.st_mode) && Rflag)
|
||||
type = DIR_TO_DNE;
|
||||
else
|
||||
type = FILE_TO_FILE;
|
||||
} else
|
||||
type = FILE_TO_FILE;
|
||||
|
||||
if (have_trailing_slash && type == FILE_TO_FILE) {
|
||||
if (r == -1)
|
||||
errx(1, "directory %s does not exist",
|
||||
to.p_path);
|
||||
else
|
||||
errx(1, "%s is not a directory", to.p_path);
|
||||
}
|
||||
} else
|
||||
/*
|
||||
* Case (2). Target is a directory.
|
||||
*/
|
||||
type = FILE_TO_DIR;
|
||||
|
||||
exit (copy(argv, type, fts_options));
|
||||
}
|
||||
|
||||
static int
|
||||
copy(char *argv[], enum op type, int fts_options)
|
||||
{
|
||||
struct stat to_stat;
|
||||
FTS *ftsp;
|
||||
FTSENT *curr;
|
||||
int base = 0, dne, badcp, rval;
|
||||
size_t nlen;
|
||||
char *p, *target_mid;
|
||||
mode_t mask, mode;
|
||||
|
||||
/*
|
||||
* Keep an inverted copy of the umask, for use in correcting
|
||||
* permissions on created directories when not using -p.
|
||||
*/
|
||||
mask = ~umask(0777);
|
||||
umask(~mask);
|
||||
|
||||
if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL)
|
||||
err(1, "fts_open");
|
||||
for (badcp = rval = 0; (curr = fts_read(ftsp)) != NULL; badcp = 0) {
|
||||
switch (curr->fts_info) {
|
||||
case FTS_NS:
|
||||
case FTS_DNR:
|
||||
case FTS_ERR:
|
||||
warnx("%s: %s",
|
||||
curr->fts_path, strerror(curr->fts_errno));
|
||||
badcp = rval = 1;
|
||||
continue;
|
||||
case FTS_DC: /* Warn, continue. */
|
||||
warnx("%s: directory causes a cycle", curr->fts_path);
|
||||
badcp = rval = 1;
|
||||
continue;
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we are in case (2) or (3) above, we need to append the
|
||||
* source name to the target name.
|
||||
*/
|
||||
if (type != FILE_TO_FILE) {
|
||||
/*
|
||||
* Need to remember the roots of traversals to create
|
||||
* correct pathnames. If there's a directory being
|
||||
* copied to a non-existent directory, e.g.
|
||||
* cp -R a/dir noexist
|
||||
* the resulting path name should be noexist/foo, not
|
||||
* noexist/dir/foo (where foo is a file in dir), which
|
||||
* is the case where the target exists.
|
||||
*
|
||||
* Also, check for "..". This is for correct path
|
||||
* concatenation for paths ending in "..", e.g.
|
||||
* cp -R .. /tmp
|
||||
* Paths ending in ".." are changed to ".". This is
|
||||
* tricky, but seems the easiest way to fix the problem.
|
||||
*
|
||||
* XXX
|
||||
* Since the first level MUST be FTS_ROOTLEVEL, base
|
||||
* is always initialized.
|
||||
*/
|
||||
if (curr->fts_level == FTS_ROOTLEVEL) {
|
||||
if (type != DIR_TO_DNE) {
|
||||
p = strrchr(curr->fts_path, '/');
|
||||
base = (p == NULL) ? 0 :
|
||||
(int)(p - curr->fts_path + 1);
|
||||
|
||||
if (!strcmp(&curr->fts_path[base],
|
||||
".."))
|
||||
base += 1;
|
||||
} else
|
||||
base = curr->fts_pathlen;
|
||||
}
|
||||
|
||||
p = &curr->fts_path[base];
|
||||
nlen = curr->fts_pathlen - base;
|
||||
target_mid = to.target_end;
|
||||
if (*p != '/' && target_mid[-1] != '/')
|
||||
*target_mid++ = '/';
|
||||
*target_mid = 0;
|
||||
if (target_mid - to.p_path + nlen >= PATH_MAX) {
|
||||
warnx("%s%s: name too long (not copied)",
|
||||
to.p_path, p);
|
||||
badcp = rval = 1;
|
||||
continue;
|
||||
}
|
||||
(void)strncat(target_mid, p, nlen);
|
||||
to.p_end = target_mid + nlen;
|
||||
*to.p_end = 0;
|
||||
STRIP_TRAILING_SLASH(to);
|
||||
}
|
||||
|
||||
if (curr->fts_info == FTS_DP) {
|
||||
/*
|
||||
* We are nearly finished with this directory. If we
|
||||
* didn't actually copy it, or otherwise don't need to
|
||||
* change its attributes, then we are done.
|
||||
*/
|
||||
if (!curr->fts_number)
|
||||
continue;
|
||||
/*
|
||||
* If -p is in effect, set all the attributes.
|
||||
* Otherwise, set the correct permissions, limited
|
||||
* by the umask. Optimise by avoiding a chmod()
|
||||
* if possible (which is usually the case if we
|
||||
* made the directory). Note that mkdir() does not
|
||||
* honour setuid, setgid and sticky bits, but we
|
||||
* normally want to preserve them on directories.
|
||||
*/
|
||||
if (pflag) {
|
||||
if (setfile(curr->fts_statp, -1))
|
||||
rval = 1;
|
||||
if (preserve_dir_acls(curr->fts_statp,
|
||||
curr->fts_accpath, to.p_path) != 0)
|
||||
rval = 1;
|
||||
} else {
|
||||
mode = curr->fts_statp->st_mode;
|
||||
if ((mode & (S_ISUID | S_ISGID | S_ISTXT)) ||
|
||||
((mode | S_IRWXU) & mask) != (mode & mask))
|
||||
if (chmod(to.p_path, mode & mask) != 0){
|
||||
warn("chmod: %s", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Not an error but need to remember it happened */
|
||||
if (stat(to.p_path, &to_stat) == -1)
|
||||
dne = 1;
|
||||
else {
|
||||
if (to_stat.st_dev == curr->fts_statp->st_dev &&
|
||||
to_stat.st_ino == curr->fts_statp->st_ino) {
|
||||
warnx("%s and %s are identical (not copied).",
|
||||
to.p_path, curr->fts_path);
|
||||
badcp = rval = 1;
|
||||
if (S_ISDIR(curr->fts_statp->st_mode))
|
||||
(void)fts_set(ftsp, curr, FTS_SKIP);
|
||||
continue;
|
||||
}
|
||||
if (!S_ISDIR(curr->fts_statp->st_mode) &&
|
||||
S_ISDIR(to_stat.st_mode)) {
|
||||
warnx("cannot overwrite directory %s with "
|
||||
"non-directory %s",
|
||||
to.p_path, curr->fts_path);
|
||||
badcp = rval = 1;
|
||||
continue;
|
||||
}
|
||||
dne = 0;
|
||||
}
|
||||
|
||||
switch (curr->fts_statp->st_mode & S_IFMT) {
|
||||
case S_IFLNK:
|
||||
/* Catch special case of a non-dangling symlink */
|
||||
if ((fts_options & FTS_LOGICAL) ||
|
||||
((fts_options & FTS_COMFOLLOW) &&
|
||||
curr->fts_level == 0)) {
|
||||
if (copy_file(curr, dne))
|
||||
badcp = rval = 1;
|
||||
} else {
|
||||
if (copy_link(curr, !dne))
|
||||
badcp = rval = 1;
|
||||
}
|
||||
break;
|
||||
case S_IFDIR:
|
||||
if (!Rflag) {
|
||||
warnx("%s is a directory (not copied).",
|
||||
curr->fts_path);
|
||||
(void)fts_set(ftsp, curr, FTS_SKIP);
|
||||
badcp = rval = 1;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* If the directory doesn't exist, create the new
|
||||
* one with the from file mode plus owner RWX bits,
|
||||
* modified by the umask. Trade-off between being
|
||||
* able to write the directory (if from directory is
|
||||
* 555) and not causing a permissions race. If the
|
||||
* umask blocks owner writes, we fail..
|
||||
*/
|
||||
if (dne) {
|
||||
if (mkdir(to.p_path,
|
||||
curr->fts_statp->st_mode | S_IRWXU) < 0)
|
||||
err(1, "%s", to.p_path);
|
||||
} else if (!S_ISDIR(to_stat.st_mode)) {
|
||||
errno = ENOTDIR;
|
||||
err(1, "%s", to.p_path);
|
||||
}
|
||||
/*
|
||||
* Arrange to correct directory attributes later
|
||||
* (in the post-order phase) if this is a new
|
||||
* directory, or if the -p flag is in effect.
|
||||
*/
|
||||
curr->fts_number = pflag || dne;
|
||||
break;
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
if (Rflag) {
|
||||
if (copy_special(curr->fts_statp, !dne))
|
||||
badcp = rval = 1;
|
||||
} else {
|
||||
if (copy_file(curr, dne))
|
||||
badcp = rval = 1;
|
||||
}
|
||||
break;
|
||||
case S_IFSOCK:
|
||||
warnx("%s is a socket (not copied).",
|
||||
curr->fts_path);
|
||||
break;
|
||||
case S_IFIFO:
|
||||
if (Rflag) {
|
||||
if (copy_fifo(curr->fts_statp, !dne))
|
||||
badcp = rval = 1;
|
||||
} else {
|
||||
if (copy_file(curr, dne))
|
||||
badcp = rval = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (copy_file(curr, dne))
|
||||
badcp = rval = 1;
|
||||
break;
|
||||
}
|
||||
if (vflag && !badcp)
|
||||
(void)printf("%s -> %s\n", curr->fts_path, to.p_path);
|
||||
}
|
||||
if (errno)
|
||||
err(1, "fts_read");
|
||||
fts_close(ftsp);
|
||||
return (rval);
|
||||
}
|
||||
|
||||
/*
|
||||
* mastercmp --
|
||||
* The comparison function for the copy order. The order is to copy
|
||||
* non-directory files before directory files. The reason for this
|
||||
* is because files tend to be in the same cylinder group as their
|
||||
* parent directory, whereas directories tend not to be. Copying the
|
||||
* files first reduces seeking.
|
||||
*/
|
||||
static int
|
||||
mastercmp(const FTSENT * const *a, const FTSENT * const *b)
|
||||
{
|
||||
int a_info, b_info;
|
||||
|
||||
a_info = (*a)->fts_info;
|
||||
if (a_info == FTS_ERR || a_info == FTS_NS || a_info == FTS_DNR)
|
||||
return (0);
|
||||
b_info = (*b)->fts_info;
|
||||
if (b_info == FTS_ERR || b_info == FTS_NS || b_info == FTS_DNR)
|
||||
return (0);
|
||||
if (a_info == FTS_D)
|
||||
return (-1);
|
||||
if (b_info == FTS_D)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
siginfo(int sig __unused)
|
||||
{
|
||||
|
||||
info = 1;
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)extern.h 8.2 (Berkeley) 4/1/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
char *p_end; /* pointer to NULL at end of path */
|
||||
char *target_end; /* pointer to end of target base */
|
||||
char p_path[PATH_MAX]; /* pointer to the start of a path */
|
||||
} PATH_T;
|
||||
|
||||
extern PATH_T to;
|
||||
extern int fflag, iflag, lflag, nflag, pflag, vflag;
|
||||
extern volatile sig_atomic_t info;
|
||||
|
||||
__BEGIN_DECLS
|
||||
int copy_fifo(struct stat *, int);
|
||||
int copy_file(const FTSENT *, int);
|
||||
int copy_link(const FTSENT *, int);
|
||||
int copy_special(struct stat *, int);
|
||||
int setfile(struct stat *, int);
|
||||
int preserve_dir_acls(struct stat *, char *, char *);
|
||||
int preserve_fd_acls(int, int);
|
||||
void usage(void);
|
||||
__END_DECLS
|
||||
525
bin/cp/utils.c
525
bin/cp/utils.c
|
|
@ -1,525 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/acl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <fts.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sysexits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
#define cp_pct(x, y) ((y == 0) ? 0 : (int)(100.0 * (x) / (y)))
|
||||
|
||||
/* Memory strategy threshold, in pages: if physmem is larger then this, use a
|
||||
* large buffer */
|
||||
#define PHYSPAGES_THRESHOLD (32*1024)
|
||||
|
||||
/* Maximum buffer size in bytes - do not allow it to grow larger than this */
|
||||
#define BUFSIZE_MAX (2*1024*1024)
|
||||
|
||||
/* Small (default) buffer size in bytes. It's inefficient for this to be
|
||||
* smaller than MAXPHYS */
|
||||
#define BUFSIZE_SMALL (MAXPHYS)
|
||||
|
||||
int
|
||||
copy_file(const FTSENT *entp, int dne)
|
||||
{
|
||||
static char *buf = NULL;
|
||||
static size_t bufsize;
|
||||
struct stat *fs;
|
||||
ssize_t wcount;
|
||||
size_t wresid;
|
||||
off_t wtotal;
|
||||
int ch, checkch, from_fd = 0, rcount, rval, to_fd = 0;
|
||||
char *bufp;
|
||||
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
|
||||
char *p;
|
||||
#endif
|
||||
|
||||
if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
|
||||
warn("%s", entp->fts_path);
|
||||
return (1);
|
||||
}
|
||||
|
||||
fs = entp->fts_statp;
|
||||
|
||||
/*
|
||||
* If the file exists and we're interactive, verify with the user.
|
||||
* If the file DNE, set the mode to be the from file, minus setuid
|
||||
* bits, modified by the umask; arguably wrong, but it makes copying
|
||||
* executables work right and it's been that way forever. (The
|
||||
* other choice is 666 or'ed with the execute bits on the from file
|
||||
* modified by the umask.)
|
||||
*/
|
||||
if (!dne) {
|
||||
#define YESNO "(y/n [n]) "
|
||||
if (nflag) {
|
||||
if (vflag)
|
||||
printf("%s not overwritten\n", to.p_path);
|
||||
(void)close(from_fd);
|
||||
return (0);
|
||||
} else if (iflag) {
|
||||
(void)fprintf(stderr, "overwrite %s? %s",
|
||||
to.p_path, YESNO);
|
||||
checkch = ch = getchar();
|
||||
while (ch != '\n' && ch != EOF)
|
||||
ch = getchar();
|
||||
if (checkch != 'y' && checkch != 'Y') {
|
||||
(void)close(from_fd);
|
||||
(void)fprintf(stderr, "not overwritten\n");
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
if (fflag) {
|
||||
/* remove existing destination file name,
|
||||
* create a new file */
|
||||
(void)unlink(to.p_path);
|
||||
if (!lflag)
|
||||
to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
|
||||
fs->st_mode & ~(S_ISUID | S_ISGID));
|
||||
} else {
|
||||
if (!lflag)
|
||||
/* overwrite existing destination file name */
|
||||
to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
|
||||
}
|
||||
} else {
|
||||
if (!lflag)
|
||||
to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
|
||||
fs->st_mode & ~(S_ISUID | S_ISGID));
|
||||
}
|
||||
|
||||
if (to_fd == -1) {
|
||||
warn("%s", to.p_path);
|
||||
(void)close(from_fd);
|
||||
return (1);
|
||||
}
|
||||
|
||||
rval = 0;
|
||||
|
||||
if (!lflag) {
|
||||
/*
|
||||
* Mmap and write if less than 8M (the limit is so we don't totally
|
||||
* trash memory on big files. This is really a minor hack, but it
|
||||
* wins some CPU back.
|
||||
* Some filesystems, such as smbnetfs, don't support mmap,
|
||||
* so this is a best-effort attempt.
|
||||
*/
|
||||
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
|
||||
if (S_ISREG(fs->st_mode) && fs->st_size > 0 &&
|
||||
fs->st_size <= 8 * 1024 * 1024 &&
|
||||
(p = mmap(NULL, (size_t)fs->st_size, PROT_READ,
|
||||
MAP_SHARED, from_fd, (off_t)0)) != MAP_FAILED) {
|
||||
wtotal = 0;
|
||||
for (bufp = p, wresid = fs->st_size; ;
|
||||
bufp += wcount, wresid -= (size_t)wcount) {
|
||||
wcount = write(to_fd, bufp, wresid);
|
||||
if (wcount <= 0)
|
||||
break;
|
||||
wtotal += wcount;
|
||||
if (info) {
|
||||
info = 0;
|
||||
(void)fprintf(stderr,
|
||||
"%s -> %s %3d%%\n",
|
||||
entp->fts_path, to.p_path,
|
||||
cp_pct(wtotal, fs->st_size));
|
||||
}
|
||||
if (wcount >= (ssize_t)wresid)
|
||||
break;
|
||||
}
|
||||
if (wcount != (ssize_t)wresid) {
|
||||
warn("%s", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
/* Some systems don't unmap on close(2). */
|
||||
if (munmap(p, fs->st_size) < 0) {
|
||||
warn("%s", entp->fts_path);
|
||||
rval = 1;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (buf == NULL) {
|
||||
/*
|
||||
* Note that buf and bufsize are static. If
|
||||
* malloc() fails, it will fail at the start
|
||||
* and not copy only some files.
|
||||
*/
|
||||
if (sysconf(_SC_PHYS_PAGES) >
|
||||
PHYSPAGES_THRESHOLD)
|
||||
bufsize = MIN(BUFSIZE_MAX, MAXPHYS * 8);
|
||||
else
|
||||
bufsize = BUFSIZE_SMALL;
|
||||
buf = malloc(bufsize);
|
||||
if (buf == NULL)
|
||||
err(1, "Not enough memory");
|
||||
}
|
||||
wtotal = 0;
|
||||
while ((rcount = read(from_fd, buf, bufsize)) > 0) {
|
||||
for (bufp = buf, wresid = rcount; ;
|
||||
bufp += wcount, wresid -= wcount) {
|
||||
wcount = write(to_fd, bufp, wresid);
|
||||
if (wcount <= 0)
|
||||
break;
|
||||
wtotal += wcount;
|
||||
if (info) {
|
||||
info = 0;
|
||||
(void)fprintf(stderr,
|
||||
"%s -> %s %3d%%\n",
|
||||
entp->fts_path, to.p_path,
|
||||
cp_pct(wtotal, fs->st_size));
|
||||
}
|
||||
if (wcount >= (ssize_t)wresid)
|
||||
break;
|
||||
}
|
||||
if (wcount != (ssize_t)wresid) {
|
||||
warn("%s", to.p_path);
|
||||
rval = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rcount < 0) {
|
||||
warn("%s", entp->fts_path);
|
||||
rval = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (link(entp->fts_path, to.p_path)) {
|
||||
warn("%s", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't remove the target even after an error. The target might
|
||||
* not be a regular file, or its attributes might be important,
|
||||
* or its contents might be irreplaceable. It would only be safe
|
||||
* to remove it if we created it and its length is 0.
|
||||
*/
|
||||
|
||||
if (!lflag) {
|
||||
if (pflag && setfile(fs, to_fd))
|
||||
rval = 1;
|
||||
if (pflag && preserve_fd_acls(from_fd, to_fd) != 0)
|
||||
rval = 1;
|
||||
if (close(to_fd)) {
|
||||
warn("%s", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
}
|
||||
|
||||
(void)close(from_fd);
|
||||
|
||||
return (rval);
|
||||
}
|
||||
|
||||
int
|
||||
copy_link(const FTSENT *p, int exists)
|
||||
{
|
||||
int len;
|
||||
char llink[PATH_MAX];
|
||||
|
||||
if ((len = readlink(p->fts_path, llink, sizeof(llink) - 1)) == -1) {
|
||||
warn("readlink: %s", p->fts_path);
|
||||
return (1);
|
||||
}
|
||||
llink[len] = '\0';
|
||||
if (exists && unlink(to.p_path)) {
|
||||
warn("unlink: %s", to.p_path);
|
||||
return (1);
|
||||
}
|
||||
if (symlink(llink, to.p_path)) {
|
||||
warn("symlink: %s", llink);
|
||||
return (1);
|
||||
}
|
||||
return (pflag ? setfile(p->fts_statp, -1) : 0);
|
||||
}
|
||||
|
||||
int
|
||||
copy_fifo(struct stat *from_stat, int exists)
|
||||
{
|
||||
if (exists && unlink(to.p_path)) {
|
||||
warn("unlink: %s", to.p_path);
|
||||
return (1);
|
||||
}
|
||||
if (mkfifo(to.p_path, from_stat->st_mode)) {
|
||||
warn("mkfifo: %s", to.p_path);
|
||||
return (1);
|
||||
}
|
||||
return (pflag ? setfile(from_stat, -1) : 0);
|
||||
}
|
||||
|
||||
int
|
||||
copy_special(struct stat *from_stat, int exists)
|
||||
{
|
||||
if (exists && unlink(to.p_path)) {
|
||||
warn("unlink: %s", to.p_path);
|
||||
return (1);
|
||||
}
|
||||
if (mknod(to.p_path, from_stat->st_mode, from_stat->st_rdev)) {
|
||||
warn("mknod: %s", to.p_path);
|
||||
return (1);
|
||||
}
|
||||
return (pflag ? setfile(from_stat, -1) : 0);
|
||||
}
|
||||
|
||||
int
|
||||
setfile(struct stat *fs, int fd)
|
||||
{
|
||||
static struct timeval tv[2];
|
||||
struct stat ts;
|
||||
int rval, gotstat, islink, fdval;
|
||||
|
||||
rval = 0;
|
||||
fdval = fd != -1;
|
||||
islink = !fdval && S_ISLNK(fs->st_mode);
|
||||
fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX |
|
||||
S_IRWXU | S_IRWXG | S_IRWXO;
|
||||
|
||||
TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atim);
|
||||
TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtim);
|
||||
if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) {
|
||||
warn("%sutimes: %s", islink ? "l" : "", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
if (fdval ? fstat(fd, &ts) :
|
||||
(islink ? lstat(to.p_path, &ts) : stat(to.p_path, &ts)))
|
||||
gotstat = 0;
|
||||
else {
|
||||
gotstat = 1;
|
||||
ts.st_mode &= S_ISUID | S_ISGID | S_ISVTX |
|
||||
S_IRWXU | S_IRWXG | S_IRWXO;
|
||||
}
|
||||
/*
|
||||
* Changing the ownership probably won't succeed, unless we're root
|
||||
* or POSIX_CHOWN_RESTRICTED is not set. Set uid/gid before setting
|
||||
* the mode; current BSD behavior is to remove all setuid bits on
|
||||
* chown. If chown fails, lose setuid/setgid bits.
|
||||
*/
|
||||
if (!gotstat || fs->st_uid != ts.st_uid || fs->st_gid != ts.st_gid)
|
||||
if (fdval ? fchown(fd, fs->st_uid, fs->st_gid) :
|
||||
(islink ? lchown(to.p_path, fs->st_uid, fs->st_gid) :
|
||||
chown(to.p_path, fs->st_uid, fs->st_gid))) {
|
||||
if (errno != EPERM) {
|
||||
warn("chown: %s", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
fs->st_mode &= ~(S_ISUID | S_ISGID);
|
||||
}
|
||||
|
||||
if (!gotstat || fs->st_mode != ts.st_mode)
|
||||
if (fdval ? fchmod(fd, fs->st_mode) :
|
||||
(islink ? lchmod(to.p_path, fs->st_mode) :
|
||||
chmod(to.p_path, fs->st_mode))) {
|
||||
warn("chmod: %s", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
|
||||
if (!gotstat || fs->st_flags != ts.st_flags)
|
||||
if (fdval ?
|
||||
fchflags(fd, fs->st_flags) :
|
||||
(islink ? lchflags(to.p_path, fs->st_flags) :
|
||||
chflags(to.p_path, fs->st_flags))) {
|
||||
warn("chflags: %s", to.p_path);
|
||||
rval = 1;
|
||||
}
|
||||
|
||||
return (rval);
|
||||
}
|
||||
|
||||
int
|
||||
preserve_fd_acls(int source_fd, int dest_fd)
|
||||
{
|
||||
acl_t acl;
|
||||
acl_type_t acl_type;
|
||||
int acl_supported = 0, ret, trivial;
|
||||
|
||||
ret = fpathconf(source_fd, _PC_ACL_NFS4);
|
||||
if (ret > 0 ) {
|
||||
acl_supported = 1;
|
||||
acl_type = ACL_TYPE_NFS4;
|
||||
} else if (ret < 0 && errno != EINVAL) {
|
||||
warn("fpathconf(..., _PC_ACL_NFS4) failed for %s", to.p_path);
|
||||
return (1);
|
||||
}
|
||||
if (acl_supported == 0) {
|
||||
ret = fpathconf(source_fd, _PC_ACL_EXTENDED);
|
||||
if (ret > 0 ) {
|
||||
acl_supported = 1;
|
||||
acl_type = ACL_TYPE_ACCESS;
|
||||
} else if (ret < 0 && errno != EINVAL) {
|
||||
warn("fpathconf(..., _PC_ACL_EXTENDED) failed for %s",
|
||||
to.p_path);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
if (acl_supported == 0)
|
||||
return (0);
|
||||
|
||||
acl = acl_get_fd_np(source_fd, acl_type);
|
||||
if (acl == NULL) {
|
||||
warn("failed to get acl entries while setting %s", to.p_path);
|
||||
return (1);
|
||||
}
|
||||
if (acl_is_trivial_np(acl, &trivial)) {
|
||||
warn("acl_is_trivial() failed for %s", to.p_path);
|
||||
acl_free(acl);
|
||||
return (1);
|
||||
}
|
||||
if (trivial) {
|
||||
acl_free(acl);
|
||||
return (0);
|
||||
}
|
||||
if (acl_set_fd_np(dest_fd, acl, acl_type) < 0) {
|
||||
warn("failed to set acl entries for %s", to.p_path);
|
||||
acl_free(acl);
|
||||
return (1);
|
||||
}
|
||||
acl_free(acl);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
preserve_dir_acls(struct stat *fs, char *source_dir, char *dest_dir)
|
||||
{
|
||||
acl_t (*aclgetf)(const char *, acl_type_t);
|
||||
int (*aclsetf)(const char *, acl_type_t, acl_t);
|
||||
struct acl *aclp;
|
||||
acl_t acl;
|
||||
acl_type_t acl_type;
|
||||
int acl_supported = 0, ret, trivial;
|
||||
|
||||
ret = pathconf(source_dir, _PC_ACL_NFS4);
|
||||
if (ret > 0) {
|
||||
acl_supported = 1;
|
||||
acl_type = ACL_TYPE_NFS4;
|
||||
} else if (ret < 0 && errno != EINVAL) {
|
||||
warn("fpathconf(..., _PC_ACL_NFS4) failed for %s", source_dir);
|
||||
return (1);
|
||||
}
|
||||
if (acl_supported == 0) {
|
||||
ret = pathconf(source_dir, _PC_ACL_EXTENDED);
|
||||
if (ret > 0) {
|
||||
acl_supported = 1;
|
||||
acl_type = ACL_TYPE_ACCESS;
|
||||
} else if (ret < 0 && errno != EINVAL) {
|
||||
warn("fpathconf(..., _PC_ACL_EXTENDED) failed for %s",
|
||||
source_dir);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
if (acl_supported == 0)
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* If the file is a link we will not follow it
|
||||
*/
|
||||
if (S_ISLNK(fs->st_mode)) {
|
||||
aclgetf = acl_get_link_np;
|
||||
aclsetf = acl_set_link_np;
|
||||
} else {
|
||||
aclgetf = acl_get_file;
|
||||
aclsetf = acl_set_file;
|
||||
}
|
||||
if (acl_type == ACL_TYPE_ACCESS) {
|
||||
/*
|
||||
* Even if there is no ACL_TYPE_DEFAULT entry here, a zero
|
||||
* size ACL will be returned. So it is not safe to simply
|
||||
* check the pointer to see if the default ACL is present.
|
||||
*/
|
||||
acl = aclgetf(source_dir, ACL_TYPE_DEFAULT);
|
||||
if (acl == NULL) {
|
||||
warn("failed to get default acl entries on %s",
|
||||
source_dir);
|
||||
return (1);
|
||||
}
|
||||
aclp = &acl->ats_acl;
|
||||
if (aclp->acl_cnt != 0 && aclsetf(dest_dir,
|
||||
ACL_TYPE_DEFAULT, acl) < 0) {
|
||||
warn("failed to set default acl entries on %s",
|
||||
dest_dir);
|
||||
acl_free(acl);
|
||||
return (1);
|
||||
}
|
||||
acl_free(acl);
|
||||
}
|
||||
acl = aclgetf(source_dir, acl_type);
|
||||
if (acl == NULL) {
|
||||
warn("failed to get acl entries on %s", source_dir);
|
||||
return (1);
|
||||
}
|
||||
if (acl_is_trivial_np(acl, &trivial)) {
|
||||
warn("acl_is_trivial() failed on %s", source_dir);
|
||||
acl_free(acl);
|
||||
return (1);
|
||||
}
|
||||
if (trivial) {
|
||||
acl_free(acl);
|
||||
return (0);
|
||||
}
|
||||
if (aclsetf(dest_dir, acl_type, acl) < 0) {
|
||||
warn("failed to set acl entries on %s", dest_dir);
|
||||
acl_free(acl);
|
||||
return (1);
|
||||
}
|
||||
acl_free(acl);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr, "%s\n%s\n",
|
||||
"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file target_file",
|
||||
" cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file ... "
|
||||
"target_directory");
|
||||
exit(EX_USAGE);
|
||||
}
|
||||
141
bin/csh/Makefile
141
bin/csh/Makefile
|
|
@ -1,141 +0,0 @@
|
|||
# $FreeBSD$
|
||||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
#
|
||||
# C Shell with process control; VM/UNIX VAX Makefile
|
||||
# Bill Joy UC Berkeley; Jim Kulp IIASA, Austria
|
||||
#
|
||||
# To profile, put -DPROF in DEFS and -pg in CFLAGS, and recompile.
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
TCSHDIR= ${.CURDIR}/../../contrib/tcsh
|
||||
.PATH: ${TCSHDIR}
|
||||
|
||||
PROG= csh
|
||||
.if defined(RESCUE)
|
||||
DFLAGS= -D_PATH_TCSHELL='"/rescue/${PROG}"'
|
||||
.else
|
||||
DFLAGS= -D_PATH_TCSHELL='"/bin/${PROG}"'
|
||||
.endif
|
||||
CFLAGS+= -I. -I${.CURDIR} -I${TCSHDIR} ${DFLAGS}
|
||||
WARNS?= 0
|
||||
SRCS= sh.c sh.dir.c sh.dol.c sh.err.c sh.exec.c sh.char.c \
|
||||
sh.exp.c sh.file.c sh.func.c sh.glob.c sh.hist.c sh.init.c \
|
||||
sh.lex.c sh.misc.c sh.parse.c sh.print.c sh.proc.c sh.sem.c \
|
||||
sh.set.c sh.time.c sh.char.h sh.dir.h sh.proc.h sh.h
|
||||
SRCS+= sh.decls.h glob.c glob.h mi.termios.c mi.wait.h mi.varargs.h
|
||||
SRCS+= tw.decls.h tw.h tw.help.c tw.init.c tw.parse.c tw.spell.c \
|
||||
tw.comp.c tw.color.c
|
||||
SRCS+= ed.chared.c ed.decls.h ed.defns.c ed.h ed.init.c ed.inputl.c \
|
||||
ed.refresh.c ed.screen.c ed.xmap.c ed.term.c ed.term.h
|
||||
SRCS+= tc.alloc.c tc.bind.c tc.const.c tc.decls.h tc.disc.c \
|
||||
tc.func.c tc.nls.c tc.os.c tc.os.h tc.printf.c tc.prompt.c \
|
||||
tc.sched.c tc.sig.c tc.sig.h tc.str.c sh.types.h tc.vers.c tc.wait.h \
|
||||
tc.who.c tc.h
|
||||
GENHDRS= ed.defns.h sh.err.h tc.const.h tc.defs.c
|
||||
SRCS+= ${GENHDRS}
|
||||
|
||||
MLINKS= csh.1 tcsh.1
|
||||
# MLINKS for Shell built in commands for which there are no userland
|
||||
# utilities of the same name are handled with the associated manpage,
|
||||
# builtin.1 in share/man/man1/.
|
||||
|
||||
DPADD= ${LIBTERMCAP} ${LIBCRYPT}
|
||||
LDADD= -ltermcap -lcrypt
|
||||
|
||||
LINKS= ${BINDIR}/csh ${BINDIR}/tcsh
|
||||
|
||||
CLEANFILES= ${GENHDRS} gethost csh.1
|
||||
|
||||
.if ${MK_EXAMPLES} != "no"
|
||||
FILESDIR= ${SHAREDIR}/examples/tcsh
|
||||
FILES= complete.tcsh csh-mode.el
|
||||
.endif
|
||||
|
||||
CATALOGS= et:et_EE.ISO8859-15 \
|
||||
finnish:fi_FI.ISO8859-1 \
|
||||
french:fr_FR.ISO8859-1 \
|
||||
german:de_DE.ISO8859-1 \
|
||||
greek:el_GR.ISO8859-7 \
|
||||
italian:it_IT.ISO8859-1 \
|
||||
ja:ja_JP.eucJP \
|
||||
russian:ru_RU.KOI8-R \
|
||||
spanish:es_ES.ISO8859-1 \
|
||||
ukrainian:uk_UA.KOI8-U
|
||||
|
||||
NLSLINKS_fi_FI.ISO8859-1= fi_FI.ISO8859-15
|
||||
NLSLINKS_fr_FR.ISO8859-1= fr_BE.ISO8859-1 fr_BE.ISO8859-15 \
|
||||
fr_CA.ISO8859-1 fr_CA.ISO8859-15 fr_CH.ISO8859-1 \
|
||||
fr_CH.ISO8859-15 fr_FR.ISO8859-15
|
||||
NLSLINKS_de_DE.ISO8859-1= de_AT.ISO8859-1 de_AT.ISO8859-15 de_CH.ISO8859-1 \
|
||||
de_CH.ISO8859-15 de_DE.ISO8859-15
|
||||
NLSLINKS_it_IT.ISO8859-1= it_CH.ISO8859-1 it_CH.ISO8859-15 it_IT.ISO8859-15
|
||||
NLSLINKS_es_ES.ISO8859-1= es_ES.ISO8859-15
|
||||
|
||||
.if ${MK_NLS_CATALOGS} == "no" || defined(RESCUE)
|
||||
CFLAGS+= -DNO_NLS_CATALOGS
|
||||
.else
|
||||
CFLAGS+= -DHAVE_ICONV
|
||||
SRCS+= iconv_stub.c
|
||||
# Following links can be installed from ports/shells/tcsh_nls:
|
||||
# NLSLINKS_de_DE.ISO8859-1 += de_AT.UTF-8 de_CH.UTF-8 de_DE.UTF-8
|
||||
# NLSLINKS_el_GR.ISO8859-7 = el_GR.UTF-8
|
||||
# NLSLINKS_es_ES.ISO8859-1 += es_ES.UTF-8
|
||||
# NLSLINKS_et_EE.ISO8859-15 = et_EE.UTF-8
|
||||
# NLSLINKS_fi_FI.ISO8859-1 += fi_FI.UTF-8
|
||||
# NLSLINKS_fr_FR.ISO8859-1 += fr_BE.UTF-8 fr_CA.UTF-8 fr_CH.UTF-8 fr_FR.UTF-8
|
||||
# NLSLINKS_it_IT.ISO8859-1 += it_CH.UTF-8 it_IT.UTF-8
|
||||
# NLSLINKS_ja_JP.eucJP = ja_JP.SJIS ja_JP.UTF-8
|
||||
# NLSLINKS_ru_RU.KOI8-R = ru_RU.CP1251 ru_RU.CP866 ru_RU.ISO8859-5 ru_RU.UTF-8
|
||||
# NLSLINKS_uk_UA.KOI8-U = uk_UA.ISO8859-5 uk_UA.UTF-8
|
||||
.endif
|
||||
|
||||
NLSNAME= tcsh
|
||||
|
||||
.for catalog in ${CATALOGS}
|
||||
NLS+= ${catalog:C/.*://}
|
||||
NLSSRCDIR_${catalog:C/.*://}= ${TCSHDIR}/nls/${catalog:C/:.*//}
|
||||
NLSSRCFILES_${catalog:C/.*://}!= cd ${NLSSRCDIR_${catalog:C/.*://}}; echo charset set[0-9]*
|
||||
.endfor
|
||||
|
||||
csh.1: tcsh.man
|
||||
cat ${.ALLSRC} > ${.TARGET}
|
||||
|
||||
build-tools: gethost
|
||||
|
||||
gethost: gethost.c sh.err.h tc.const.h sh.h
|
||||
@rm -f ${.TARGET}
|
||||
${CC} -o gethost ${LDFLAGS} ${CFLAGS} ${TCSHDIR}/gethost.c
|
||||
|
||||
tc.defs.c: gethost ${.CURDIR}/host.defs
|
||||
@rm -f ${.TARGET}
|
||||
@echo "/* Do not edit this file, make creates it */" > ${.TARGET}
|
||||
./gethost ${.CURDIR}/host.defs >> ${.TARGET}
|
||||
|
||||
ed.defns.h: ed.defns.c
|
||||
@rm -f ${.TARGET}
|
||||
@echo '/* Do not edit this file, make creates it. */' > ${.TARGET}
|
||||
@echo '#ifndef _h_ed_defns' >> ${.TARGET}
|
||||
@echo '#define _h_ed_defns' >> ${.TARGET}
|
||||
grep '[FV]_' ${TCSHDIR}/ed.defns.c | grep '^#define' >> ${.TARGET}
|
||||
@echo '#endif /* _h_ed_defns */' >> ${.TARGET}
|
||||
|
||||
sh.err.h: sh.err.c
|
||||
@rm -f ${.TARGET}
|
||||
@echo '/* Do not edit this file, make creates it. */' > ${.TARGET}
|
||||
@echo '#ifndef _h_sh_err' >> ${.TARGET}
|
||||
@echo '#define _h_sh_err' >> ${.TARGET}
|
||||
grep 'ERR_' ${.ALLSRC} | grep '^#define' >> ${.TARGET}
|
||||
@echo '#endif /* _h_sh_err */' >> ${.TARGET}
|
||||
|
||||
tc.const.h: tc.const.c sh.char.h config.h config_f.h sh.types.h sh.err.h
|
||||
@rm -f ${.TARGET}
|
||||
@echo '/* Do not edit this file, make creates it. */' > ${.TARGET}
|
||||
@echo '#ifndef _h_tc_const' >> ${.TARGET}
|
||||
@echo '#define _h_tc_const' >> ${.TARGET}
|
||||
${CC} -E ${CFLAGS} ${.ALLSRC} -D_h_tc_const | grep 'Char STR' | \
|
||||
sed -e 's/Char \([a-zA-Z0-9_]*\)\(.*\)/extern Char \1[];/' | \
|
||||
sort >> ${.TARGET}
|
||||
@echo '#endif /* _h_tc_const */' >> ${.TARGET}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,649 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)csh.3 8.1 (Berkeley) 6/8/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.nr H1 2
|
||||
.NH
|
||||
Shell control structures and command scripts
|
||||
.NH 2
|
||||
Introduction
|
||||
.PP
|
||||
It is possible to place commands in files and to cause shells to be
|
||||
invoked to read and execute commands from these files,
|
||||
which are called
|
||||
.I "shell scripts."
|
||||
We here detail those features of the shell useful to the writers of such
|
||||
scripts.
|
||||
.NH 2
|
||||
Make
|
||||
.PP
|
||||
It is important to first note what shell scripts are
|
||||
.I not
|
||||
useful for.
|
||||
There is a program called
|
||||
.I make
|
||||
which is very useful for maintaining a group of related files
|
||||
or performing sets of operations on related files.
|
||||
For instance a large program consisting of one or more files
|
||||
can have its dependencies described in a
|
||||
.I makefile
|
||||
which contains definitions of the commands used to create these
|
||||
different files when changes occur.
|
||||
Definitions of the means for printing listings, cleaning up the directory
|
||||
in which the files reside, and installing the resultant programs
|
||||
are easily, and most appropriately placed in this
|
||||
.I makefile.
|
||||
This format is superior and preferable to maintaining a group of shell
|
||||
procedures to maintain these files.
|
||||
.PP
|
||||
Similarly when working on a document a
|
||||
.I makefile
|
||||
may be created which defines how different versions of the document
|
||||
are to be created and which options of
|
||||
.I nroff
|
||||
or
|
||||
.I troff
|
||||
are appropriate.
|
||||
.NH 2
|
||||
Invocation and the argv variable
|
||||
.PP
|
||||
A
|
||||
.I csh
|
||||
command script may be interpreted by saying
|
||||
.DS
|
||||
% csh script ...
|
||||
.DE
|
||||
where
|
||||
.I script
|
||||
is the name of the file containing a group of
|
||||
.I csh
|
||||
commands and
|
||||
`\&...' is replaced by a sequence of arguments.
|
||||
The shell places these arguments in the variable
|
||||
.I argv
|
||||
and then begins to read commands from the script.
|
||||
These parameters are then available through the same mechanisms
|
||||
which are used to reference any other shell variables.
|
||||
.PP
|
||||
If you make the file
|
||||
`script'
|
||||
executable by doing
|
||||
.DS
|
||||
chmod 755 script
|
||||
.DE
|
||||
and place a shell comment at the beginning of the shell script
|
||||
(i.e. begin the file with a `#' character)
|
||||
then a `/bin/csh' will automatically be invoked to execute `script' when
|
||||
you type
|
||||
.DS
|
||||
script
|
||||
.DE
|
||||
If the file does not begin with a `#' then the standard shell
|
||||
`/bin/sh' will be used to execute it.
|
||||
This allows you to convert your older shell scripts to use
|
||||
.I csh
|
||||
at your convenience.
|
||||
.NH 2
|
||||
Variable substitution
|
||||
.PP
|
||||
After each input line is broken into words and history substitutions
|
||||
are done on it, the input line is parsed into distinct commands.
|
||||
Before each command is executed a mechanism know as
|
||||
.I "variable substitution"
|
||||
is done on these words.
|
||||
Keyed by the character `$' this substitution replaces the names
|
||||
of variables by their values.
|
||||
Thus
|
||||
.DS
|
||||
echo $argv
|
||||
.DE
|
||||
when placed in a command script would cause the current value of the
|
||||
variable
|
||||
.I argv
|
||||
to be echoed to the output of the shell script.
|
||||
It is an error for
|
||||
.I argv
|
||||
to be unset at this point.
|
||||
.PP
|
||||
A number of notations are provided for accessing components and attributes
|
||||
of variables.
|
||||
The notation
|
||||
.DS
|
||||
$?name
|
||||
.DE
|
||||
expands to `1' if name is
|
||||
.I set
|
||||
or to `0'
|
||||
if name is not
|
||||
.I set.
|
||||
It is the fundamental mechanism used for checking whether particular
|
||||
variables have been assigned values.
|
||||
All other forms of reference to undefined variables cause errors.
|
||||
.PP
|
||||
The notation
|
||||
.DS
|
||||
$#name
|
||||
.DE
|
||||
expands to the number of elements in the variable
|
||||
.I name.
|
||||
Thus
|
||||
.DS
|
||||
% set argv=(a b c)
|
||||
% echo $?argv
|
||||
1
|
||||
% echo $#argv
|
||||
3
|
||||
% unset argv
|
||||
% echo $?argv
|
||||
0
|
||||
% echo $argv
|
||||
Undefined variable: argv.
|
||||
%
|
||||
.DE
|
||||
.PP
|
||||
It is also possible to access the components of a variable
|
||||
which has several values.
|
||||
Thus
|
||||
.DS
|
||||
$argv[1]
|
||||
.DE
|
||||
gives the first component of
|
||||
.I argv
|
||||
or in the example above `a'.
|
||||
Similarly
|
||||
.DS
|
||||
$argv[$#argv]
|
||||
.DE
|
||||
would give `c',
|
||||
and
|
||||
.DS
|
||||
$argv[1\-2]
|
||||
.DE
|
||||
would give `a b'. Other notations useful in shell scripts are
|
||||
.DS
|
||||
$\fIn\fR
|
||||
.DE
|
||||
where
|
||||
.I n
|
||||
is an integer as a shorthand for
|
||||
.DS
|
||||
$argv[\fIn\fR\|]
|
||||
.DE
|
||||
the
|
||||
.I n\|th
|
||||
parameter and
|
||||
.DS
|
||||
$*
|
||||
.DE
|
||||
which is a shorthand for
|
||||
.DS
|
||||
$argv
|
||||
.DE
|
||||
The form
|
||||
.DS
|
||||
$$
|
||||
.DE
|
||||
expands to the process number of the current shell.
|
||||
Since this process number is unique in the system it can
|
||||
be used in generation of unique temporary file names.
|
||||
The form
|
||||
.DS
|
||||
$<
|
||||
.DE
|
||||
is quite special and is replaced by the next line of input read from
|
||||
the shell's standard input (not the script it is reading). This is
|
||||
useful for writing shell scripts that are interactive, reading
|
||||
commands from the terminal, or even writing a shell script that
|
||||
acts as a filter, reading lines from its input file.
|
||||
Thus the sequence
|
||||
.DS
|
||||
echo 'yes or no?\ec'
|
||||
set a=($<)
|
||||
.DE
|
||||
would write out the prompt `yes or no?' without a newline and then
|
||||
read the answer into the variable `a'. In this case `$#a' would be
|
||||
`0' if either a blank line or end-of-file (^D) was typed.
|
||||
.PP
|
||||
One minor difference between `$\fIn\fR\|' and `$argv[\fIn\fR\|]'
|
||||
should be noted here.
|
||||
The form
|
||||
`$argv[\fIn\fR\|]'
|
||||
will yield an error if
|
||||
.I n
|
||||
is not in the range
|
||||
`1\-$#argv'
|
||||
while `$n'
|
||||
will never yield an out of range subscript error.
|
||||
This is for compatibility with the way older shells handled parameters.
|
||||
.PP
|
||||
Another important point is that it is never an error to give a subrange
|
||||
of the form `n\-'; if there are less than
|
||||
.I n
|
||||
components of the given variable then no words are substituted.
|
||||
A range of the form `m\-n' likewise returns an empty vector without giving
|
||||
an error when \fIm\fR exceeds the number of elements of the given variable,
|
||||
provided the subscript \fIn\fR is in range.
|
||||
.NH 2
|
||||
Expressions
|
||||
.PP
|
||||
In order for interesting shell scripts to be constructed it
|
||||
must be possible to evaluate expressions in the shell based on the
|
||||
values of variables.
|
||||
In fact, all the arithmetic operations of the language C are available
|
||||
in the shell
|
||||
with the same precedence that they have in C.
|
||||
In particular, the operations `==' and `!=' compare strings
|
||||
and the operators `&&' and `|\|\||' implement the boolean and/or operations.
|
||||
The special operators `=~' and `!~' are similar to `==' and `!=' except
|
||||
that the string on the right side can have pattern matching characters
|
||||
(like *, ? or []) and the test is whether the string on the left matches
|
||||
the pattern on the right.
|
||||
.PP
|
||||
The shell also allows file enquiries of the form
|
||||
.DS
|
||||
\-? filename
|
||||
.DE
|
||||
where `?' is replace by a number of single characters.
|
||||
For instance the expression primitive
|
||||
.DS
|
||||
\-e filename
|
||||
.DE
|
||||
tell whether the file
|
||||
`filename'
|
||||
exists.
|
||||
Other primitives test for read, write and execute access to the file,
|
||||
whether it is a directory, or has non-zero length.
|
||||
.PP
|
||||
It is possible to test whether a command terminates normally,
|
||||
by a primitive of the
|
||||
form `{ command }' which returns true, i.e. `1' if the command
|
||||
succeeds exiting normally with exit status 0, or `0' if the command
|
||||
terminates abnormally or with exit status non-zero.
|
||||
If more detailed information about the execution status of a command
|
||||
is required, it can be executed and the variable `$status' examined
|
||||
in the next command.
|
||||
Since `$status' is set by every command, it is very transient.
|
||||
It can be saved if it is inconvenient to use it only in the single
|
||||
immediately following command.
|
||||
.PP
|
||||
For a full list of expression components available see the manual
|
||||
section for the shell.
|
||||
.NH 2
|
||||
Sample shell script
|
||||
.PP
|
||||
A sample shell script which makes use of the expression mechanism
|
||||
of the shell and some of its control structure follows:
|
||||
.DS
|
||||
% cat copyc
|
||||
#
|
||||
# Copyc copies those C programs in the specified list
|
||||
# to the directory ~/backup if they differ from the files
|
||||
# already in ~/backup
|
||||
#
|
||||
set noglob
|
||||
foreach i ($argv)
|
||||
|
||||
if ($i !~ *.c) continue # not a .c file so do nothing
|
||||
|
||||
if (! \-r ~/backup/$i:t) then
|
||||
echo $i:t not in backup... not cp\e\'ed
|
||||
continue
|
||||
endif
|
||||
|
||||
cmp \-s $i ~/backup/$i:t # to set $status
|
||||
|
||||
if ($status != 0) then
|
||||
echo new backup of $i
|
||||
cp $i ~/backup/$i:t
|
||||
endif
|
||||
end
|
||||
.DE
|
||||
.PP
|
||||
This script makes use of the
|
||||
.I foreach
|
||||
command, which causes the shell to execute the commands between the
|
||||
.I foreach
|
||||
and the matching
|
||||
.I end
|
||||
for each of the values given between `(' and `)' with the named
|
||||
variable, in this case `i' set to successive values in the list.
|
||||
Within this loop we may use the command
|
||||
.I break
|
||||
to stop executing the loop
|
||||
and
|
||||
.I continue
|
||||
to prematurely terminate one iteration
|
||||
and begin the next.
|
||||
After the
|
||||
.I foreach
|
||||
loop the iteration variable
|
||||
(\fIi\fR in this case)
|
||||
has the value at the last iteration.
|
||||
.PP
|
||||
We set the variable
|
||||
.I noglob
|
||||
here to prevent filename expansion of the members of
|
||||
.I argv.
|
||||
This is a good idea, in general, if the arguments to a shell script
|
||||
are filenames which have already been expanded or if the arguments
|
||||
may contain filename expansion metacharacters.
|
||||
It is also possible to quote each use of a `$' variable expansion,
|
||||
but this is harder and less reliable.
|
||||
.PP
|
||||
The other control construct used here is a statement of the form
|
||||
.DS
|
||||
\fBif\fR ( expression ) \fBthen\fR
|
||||
command
|
||||
...
|
||||
\fBendif\fR
|
||||
.DE
|
||||
The placement of the keywords here is
|
||||
.B not
|
||||
flexible due to the current implementation of the shell.\(dg
|
||||
.FS
|
||||
\(dgThe following two formats are not currently acceptable to the shell:
|
||||
.sp
|
||||
.in +5
|
||||
.nf
|
||||
\fBif\fR ( expression ) # \fBWon't work!\fR
|
||||
\fBthen\fR
|
||||
command
|
||||
...
|
||||
\fBendif\fR
|
||||
.fi
|
||||
.in -5
|
||||
.sp
|
||||
and
|
||||
.sp
|
||||
.in +5
|
||||
.nf
|
||||
\fBif\fR ( expression ) \fBthen\fR command \fBendif\fR # \fBWon't work\fR
|
||||
.in -5
|
||||
.fi
|
||||
.FE
|
||||
.PP
|
||||
The shell does have another form of the if statement of the form
|
||||
.DS
|
||||
\fBif\fR ( expression ) \fBcommand\fR
|
||||
.DE
|
||||
which can be written
|
||||
.DS
|
||||
\fBif\fR ( expression ) \e
|
||||
command
|
||||
.DE
|
||||
Here we have escaped the newline for the sake of appearance.
|
||||
The command must not involve `\||\|', `&' or `;'
|
||||
and must not be another control command.
|
||||
The second form requires the final `\e' to
|
||||
.B immediately
|
||||
precede the end-of-line.
|
||||
.PP
|
||||
The more general
|
||||
.I if
|
||||
statements above also admit a sequence of
|
||||
.I else\-if
|
||||
pairs followed by a single
|
||||
.I else
|
||||
and an
|
||||
.I endif,
|
||||
e.g.:
|
||||
.DS
|
||||
\fBif\fR ( expression ) \fBthen\fR
|
||||
commands
|
||||
\fBelse\fR \fBif\fR (expression ) \fBthen\fR
|
||||
commands
|
||||
\&...
|
||||
|
||||
\fBelse\fR
|
||||
commands
|
||||
\fBendif\fR
|
||||
.DE
|
||||
.PP
|
||||
Another important mechanism used in shell scripts is the `:' modifier.
|
||||
We can use the modifier `:r' here to extract a root of a filename or
|
||||
`:e' to extract the
|
||||
.I extension.
|
||||
Thus if the variable
|
||||
.I i
|
||||
has the value
|
||||
`/mnt/foo.bar'
|
||||
then
|
||||
.sp
|
||||
.in +5
|
||||
.nf
|
||||
% echo $i $i:r $i:e
|
||||
/mnt/foo.bar /mnt/foo bar
|
||||
%
|
||||
.sp
|
||||
.in -5
|
||||
.fi
|
||||
shows how the `:r' modifier strips off the trailing `.bar' and the
|
||||
the `:e' modifier leaves only the `bar'.
|
||||
Other modifiers will take off the last component of a pathname leaving
|
||||
the head `:h' or all but the last component of a pathname leaving the
|
||||
tail `:t'.
|
||||
These modifiers are fully described in the
|
||||
.I csh
|
||||
manual pages in the User's Reference Manual.
|
||||
It is also possible to use the
|
||||
.I "command substitution"
|
||||
mechanism described in the next major section to perform modifications
|
||||
on strings to then reenter the shell's environment.
|
||||
Since each usage of this mechanism involves the creation of a new process,
|
||||
it is much more expensive to use than the `:' modification mechanism.\(dd
|
||||
.FS
|
||||
\(dd It is also important to note that
|
||||
the current implementation of the shell limits the number of `:' modifiers
|
||||
on a `$' substitution to 1.
|
||||
Thus
|
||||
.sp
|
||||
.nf
|
||||
.in +5
|
||||
% echo $i $i:h:t
|
||||
/a/b/c /a/b:t
|
||||
%
|
||||
.in -5
|
||||
.fi
|
||||
.sp
|
||||
does not do what one would expect.
|
||||
.FE
|
||||
Finally, we note that the character `#' lexically introduces a shell
|
||||
comment in shell scripts (but not from the terminal).
|
||||
All subsequent characters on the input line after a `#' are discarded
|
||||
by the shell.
|
||||
This character can be quoted using `\'' or `\e' to place it in
|
||||
an argument word.
|
||||
.NH 2
|
||||
Other control structures
|
||||
.PP
|
||||
The shell also has control structures
|
||||
.I while
|
||||
and
|
||||
.I switch
|
||||
similar to those of C.
|
||||
These take the forms
|
||||
.DS
|
||||
\fBwhile\fR ( expression )
|
||||
commands
|
||||
\fBend\fR
|
||||
.DE
|
||||
and
|
||||
.DS
|
||||
\fBswitch\fR ( word )
|
||||
|
||||
\fBcase\fR str1:
|
||||
commands
|
||||
\fBbreaksw\fR
|
||||
|
||||
\& ...
|
||||
|
||||
\fBcase\fR strn:
|
||||
commands
|
||||
\fBbreaksw\fR
|
||||
|
||||
\fBdefault:\fR
|
||||
commands
|
||||
\fBbreaksw\fR
|
||||
|
||||
\fBendsw\fR
|
||||
.DE
|
||||
For details see the manual section for
|
||||
.I csh.
|
||||
C programmers should note that we use
|
||||
.I breaksw
|
||||
to exit from a
|
||||
.I switch
|
||||
while
|
||||
.I break
|
||||
exits a
|
||||
.I while
|
||||
or
|
||||
.I foreach
|
||||
loop.
|
||||
A common mistake to make in
|
||||
.I csh
|
||||
scripts is to use
|
||||
.I break
|
||||
rather than
|
||||
.I breaksw
|
||||
in switches.
|
||||
.PP
|
||||
Finally,
|
||||
.I csh
|
||||
allows a
|
||||
.I goto
|
||||
statement, with labels looking like they do in C, i.e.:
|
||||
.DS
|
||||
loop:
|
||||
commands
|
||||
\fBgoto\fR loop
|
||||
.DE
|
||||
.NH 2
|
||||
Supplying input to commands
|
||||
.PP
|
||||
Commands run from shell scripts receive by default the standard
|
||||
input of the shell which is running the script.
|
||||
This is different from previous shells running
|
||||
under \s-2UNIX\s0. It allows shell scripts to fully participate
|
||||
in pipelines, but mandates extra notation for commands which are to take
|
||||
inline data.
|
||||
.PP
|
||||
Thus we need a metanotation for supplying inline data to commands in
|
||||
shell scripts.
|
||||
As an example, consider this script which runs the editor to
|
||||
delete leading blanks from the lines in each argument file:
|
||||
.DS
|
||||
% cat deblank
|
||||
# deblank \-\- remove leading blanks
|
||||
foreach i ($argv)
|
||||
ed \- $i << \'EOF\'
|
||||
1,$s/^[ ]*//
|
||||
w
|
||||
q
|
||||
\&\'EOF\'
|
||||
end
|
||||
%
|
||||
.DE
|
||||
The notation `<< \'EOF\''
|
||||
means that the standard input for the
|
||||
.I ed
|
||||
command is to come from the text in the shell script file
|
||||
up to the next line consisting of exactly `\'EOF\''.
|
||||
The fact that the `EOF' is enclosed in `\'' characters, i.e. quoted,
|
||||
causes the shell to not perform variable substitution on the
|
||||
intervening lines.
|
||||
In general, if any part of the word following the `<<' which the
|
||||
shell uses to terminate the text to be given to the command is quoted
|
||||
then these substitutions will not be performed.
|
||||
In this case since we used the form `1,$' in our editor script
|
||||
we needed to insure that this `$' was not variable substituted.
|
||||
We could also have insured this by preceding the `$' here with a `\e',
|
||||
i.e.:
|
||||
.DS
|
||||
1,\e$s/^[ ]*//
|
||||
.DE
|
||||
but quoting the `EOF' terminator is a more reliable way of achieving the
|
||||
same thing.
|
||||
.NH 2
|
||||
Catching interrupts
|
||||
.PP
|
||||
If our shell script creates temporary files, we may wish to catch
|
||||
interruptions of the shell script so that we can clean up
|
||||
these files.
|
||||
We can then do
|
||||
.DS
|
||||
onintr label
|
||||
.DE
|
||||
where
|
||||
.I label
|
||||
is a label in our program.
|
||||
If an interrupt is received the shell will do a
|
||||
`goto label'
|
||||
and we can remove the temporary files and then do an
|
||||
.I exit
|
||||
command (which is built in to the shell)
|
||||
to exit from the shell script.
|
||||
If we wish to exit with a non-zero status we can do
|
||||
.DS
|
||||
exit(1)
|
||||
.DE
|
||||
e.g. to exit with status `1'.
|
||||
.NH 2
|
||||
What else?
|
||||
.PP
|
||||
There are other features of the shell useful to writers of shell
|
||||
procedures.
|
||||
The
|
||||
.I verbose
|
||||
and
|
||||
.I echo
|
||||
options and the related
|
||||
.I \-v
|
||||
and
|
||||
.I \-x
|
||||
command line options can be used to help trace the actions of the shell.
|
||||
The
|
||||
.I \-n
|
||||
option causes the shell only to read commands and not to execute
|
||||
them and may sometimes be of use.
|
||||
.PP
|
||||
One other thing to note is that
|
||||
.I csh
|
||||
will not execute shell scripts which do not begin with the
|
||||
character `#', that is shell scripts that do not begin with a comment.
|
||||
Similarly, the `/bin/sh' on your system may well defer to `csh'
|
||||
to interpret shell scripts which begin with `#'.
|
||||
This allows shell scripts for both shells to live in harmony.
|
||||
.PP
|
||||
There is also another quotation mechanism using `"' which allows
|
||||
only some of the expansion mechanisms we have so far discussed to occur
|
||||
on the quoted string and serves to make this string into a single word
|
||||
as `\'' does.
|
||||
.bp
|
||||
|
|
@ -1,176 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)csh.4 8.1 (Berkeley) 6/8/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.nr H1 3
|
||||
.NH
|
||||
Other, less commonly used, shell features
|
||||
.NH 2
|
||||
Loops at the terminal; variables as vectors
|
||||
.PP
|
||||
It is occasionally useful to use the
|
||||
.I foreach
|
||||
control structure at the terminal to aid in performing a number
|
||||
of similar commands.
|
||||
For instance, there were at one point three shells in use on the Cory \s-2UNIX\s0
|
||||
system at Cory Hall,
|
||||
`/bin/sh',
|
||||
`/bin/nsh',
|
||||
and
|
||||
`/bin/csh'.
|
||||
To count the number of persons using each shell one could have issued
|
||||
the commands
|
||||
.DS
|
||||
% grep \-c csh$ /etc/passwd
|
||||
27
|
||||
% grep \-c nsh$ /etc/passwd
|
||||
128
|
||||
% grep \-c \-v sh$ /etc/passwd
|
||||
430
|
||||
%
|
||||
.DE
|
||||
Since these commands are very similar we can use
|
||||
.I foreach
|
||||
to do this more easily.
|
||||
.DS
|
||||
% foreach i (\'sh$\' \'csh$\' \'\-v sh$\')
|
||||
? grep \-c $i /etc/passwd
|
||||
? end
|
||||
27
|
||||
128
|
||||
430
|
||||
%
|
||||
.DE
|
||||
Note here that the shell prompts for
|
||||
input with `? ' when reading the body of the loop.
|
||||
.PP
|
||||
Very useful with loops are variables which contain lists of filenames
|
||||
or other words.
|
||||
You can, for example, do
|
||||
.DS
|
||||
% set a=(\`ls\`)
|
||||
% echo $a
|
||||
csh.n csh.rm
|
||||
% ls
|
||||
csh.n
|
||||
csh.rm
|
||||
% echo $#a
|
||||
2
|
||||
%
|
||||
.DE
|
||||
The
|
||||
.I set
|
||||
command here gave the variable
|
||||
.I a
|
||||
a list of all the filenames in the current directory as value.
|
||||
We can then iterate over these names to perform any chosen function.
|
||||
.PP
|
||||
The output of a command within `\`' characters is converted by
|
||||
the shell to a list of words.
|
||||
You can also place the `\`' quoted string within `"' characters
|
||||
to take each (non-empty) line as a component of the variable;
|
||||
preventing the lines from being split into words at blanks and tabs.
|
||||
A modifier `:x' exists which can be used later to expand each component
|
||||
of the variable into another variable splitting it into separate words
|
||||
at embedded blanks and tabs.
|
||||
.NH 2
|
||||
Braces { ... } in argument expansion
|
||||
.PP
|
||||
Another form of filename expansion, alluded
|
||||
to before involves the characters `{' and `}'.
|
||||
These characters specify that the contained strings, separated by `,'
|
||||
are to be consecutively substituted into the containing characters
|
||||
and the results expanded left to right.
|
||||
Thus
|
||||
.DS
|
||||
A{str1,str2,...strn}B
|
||||
.DE
|
||||
expands to
|
||||
.DS
|
||||
Astr1B Astr2B ... AstrnB
|
||||
.DE
|
||||
This expansion occurs before the other filename expansions, and may
|
||||
be applied recursively (i.e. nested).
|
||||
The results of each expanded string are sorted separately, left
|
||||
to right order being preserved.
|
||||
The resulting filenames are not required to exist if no other expansion
|
||||
mechanisms are used.
|
||||
This means that this mechanism can be used to generate arguments which are
|
||||
not filenames, but which have common parts.
|
||||
.PP
|
||||
A typical use of this would be
|
||||
.DS
|
||||
mkdir ~/{hdrs,retrofit,csh}
|
||||
.DE
|
||||
to make subdirectories `hdrs', `retrofit' and `csh'
|
||||
in your home directory.
|
||||
This mechanism is most useful when the common prefix is longer
|
||||
than in this example, i.e.
|
||||
.DS
|
||||
chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
|
||||
.DE
|
||||
.NH 2
|
||||
Command substitution
|
||||
.PP
|
||||
A command enclosed in `\`' characters is replaced, just before
|
||||
filenames are expanded, by the output from that command.
|
||||
Thus it is possible to do
|
||||
.DS
|
||||
set pwd=\`pwd\`
|
||||
.DE
|
||||
to save the current directory in the variable
|
||||
.I pwd
|
||||
or to do
|
||||
.DS
|
||||
ex \`grep \-l TRACE *.c\`
|
||||
.DE
|
||||
to run the editor
|
||||
.I ex
|
||||
supplying as arguments those files whose names end in `.c'
|
||||
which have the string `TRACE' in them.*
|
||||
.FS
|
||||
*Command expansion also occurs in input redirected with `<<'
|
||||
and within `"' quotations.
|
||||
Refer to the shell manual section for full details.
|
||||
.FE
|
||||
.NH 2
|
||||
Other details not covered here
|
||||
.PP
|
||||
In particular circumstances it may be necessary to know the exact
|
||||
nature and order of different substitutions performed by the shell.
|
||||
The exact meaning of certain combinations of quotations is also
|
||||
occasionally important.
|
||||
These are detailed fully in its manual section.
|
||||
.PP
|
||||
The shell has a number of command line option flags mostly of use
|
||||
in writing \s-2UNIX\s0 programs,
|
||||
and debugging shell scripts.
|
||||
See the csh(1) manual section for a list of these options.
|
||||
.bp
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)csh.a 8.1 (Berkeley) 6/8/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.SH
|
||||
Appendix \- Special characters
|
||||
.LP
|
||||
The following table lists the special characters of
|
||||
.I csh
|
||||
and the \s-2UNIX\s0 system, giving for each the section(s) in which it
|
||||
is discussed.
|
||||
A number of these characters also have special meaning in expressions.
|
||||
See the
|
||||
.I csh
|
||||
manual section
|
||||
for a complete list.
|
||||
.ta .75i 1.5i 2.25i
|
||||
.LP
|
||||
Syntactic metacharacters
|
||||
.DS
|
||||
; 2.4 separates commands to be executed sequentially
|
||||
| 1.5 separates commands in a pipeline
|
||||
( ) 2.2,3.6 brackets expressions and variable values
|
||||
& 2.5 follows commands to be executed without waiting for completion
|
||||
.DE
|
||||
.LP
|
||||
Filename metacharacters
|
||||
.DS
|
||||
/ 1.6 separates components of a file's pathname
|
||||
\&. 1.6 separates root parts of a file name from extensions
|
||||
? 1.6 expansion character matching any single character
|
||||
* 1.6 expansion character matching any sequence of characters
|
||||
[ ] 1.6 expansion sequence matching any single character from a set
|
||||
~ 1.6 used at the beginning of a filename to indicate home directories
|
||||
{ } 4.2 used to specify groups of arguments with common parts
|
||||
.DE
|
||||
.LP
|
||||
Quotation metacharacters
|
||||
.DS
|
||||
\e 1.7 prevents meta-meaning of following single character
|
||||
\' 1.7 prevents meta-meaning of a group of characters
|
||||
" 4.3 like \', but allows variable and command expansion
|
||||
.DE
|
||||
.LP
|
||||
Input/output metacharacters
|
||||
.DS
|
||||
< 1.5 indicates redirected input
|
||||
> 1.3 indicates redirected output
|
||||
.DE
|
||||
.LP
|
||||
Expansion/substitution metacharacters
|
||||
.DS
|
||||
$ 3.4 indicates variable substitution
|
||||
! 2.3 indicates history substitution
|
||||
: 3.6 precedes substitution modifiers
|
||||
^ 2.3 used in special forms of history substitution
|
||||
\` 4.3 indicates command substitution
|
||||
.DE
|
||||
.LP
|
||||
Other metacharacters
|
||||
.DS
|
||||
# 1.3,3.6 begins scratch file names; indicates shell comments
|
||||
\- 1.2 prefixes option (flag) arguments to commands
|
||||
% 2.6 prefixes job name specifications
|
||||
.DE
|
||||
.bp
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,32 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)tabs 8.1 (Berkeley) 6/8/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.ta 5n 10n 15n 20n 25n 30n 35n 40n 45n 50n 55n 60n 65n 70n 75n 80n
|
||||
242
bin/csh/config.h
242
bin/csh/config.h
|
|
@ -1,242 +0,0 @@
|
|||
/* $FreeBSD$ */
|
||||
/* config.h. Generated by configure. */
|
||||
/* config.h.in. Generated from configure.in by autoheader. */
|
||||
|
||||
/* Define to the type of elements in the array set by `getgroups'. Usually
|
||||
this is either `int' or `gid_t'. */
|
||||
#define GETGROUPS_T gid_t
|
||||
|
||||
/* Define to 1 if the `getpgrp' function requires zero arguments. */
|
||||
#define GETPGRP_VOID 1
|
||||
|
||||
/* Define to 1 if you have the <auth.h> header file. */
|
||||
/* #undef HAVE_AUTH_H */
|
||||
|
||||
/* Define to 1 if you have the `catgets' function. */
|
||||
#define HAVE_CATGETS 1
|
||||
|
||||
/* Define to 1 if you have the <crypt.h> header file. */
|
||||
/* #undef HAVE_CRYPT_H */
|
||||
|
||||
/* Define to 1 if you have the declaration of `crypt', and to 0 if you don't.
|
||||
*/
|
||||
#define HAVE_DECL_CRYPT 1
|
||||
|
||||
/* Define to 1 if you have the declaration of `environ', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_ENVIRON 0
|
||||
|
||||
/* Define to 1 if you have the declaration of `gethostname', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_GETHOSTNAME 1
|
||||
|
||||
/* Define to 1 if you have the declaration of `getpgrp', and to 0 if you
|
||||
don't. */
|
||||
#define HAVE_DECL_GETPGRP 1
|
||||
|
||||
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#define HAVE_DIRENT_H 1
|
||||
|
||||
/* Define to 1 if you have the `dup2' function. */
|
||||
#define HAVE_DUP2 1
|
||||
|
||||
/* Define to 1 if you have the `getauthid' function. */
|
||||
/* #undef HAVE_GETAUTHID */
|
||||
|
||||
/* Define to 1 if you have the `getcwd' function. */
|
||||
#define HAVE_GETCWD 1
|
||||
|
||||
/* Define to 1 if you have the `gethostname' function. */
|
||||
#define HAVE_GETHOSTNAME 1
|
||||
|
||||
/* Define to 1 if you have the `getpwent' function. */
|
||||
#define HAVE_GETPWENT 1
|
||||
|
||||
/* Define to 1 if you have the `getutent' function. */
|
||||
#define HAVE_GETUTENT 1
|
||||
|
||||
/* Define if you have the iconv() function. */
|
||||
/* #undef HAVE_ICONV */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if the system has the type `long long'. */
|
||||
#define HAVE_LONG_LONG 1
|
||||
|
||||
/* Define to 1 if mbrtowc and mbstate_t are properly declared. */
|
||||
#define HAVE_MBRTOWC 1
|
||||
|
||||
/* Define to 1 if you have the `memmove' function. */
|
||||
#define HAVE_MEMMOVE 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#define HAVE_MEMSET 1
|
||||
|
||||
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
|
||||
/* #undef HAVE_NDIR_H */
|
||||
|
||||
/* Define to 1 if you have the `nice' function. */
|
||||
#define HAVE_NICE 1
|
||||
|
||||
/* Define to 1 if you have the `nl_langinfo' function. */
|
||||
#define HAVE_NL_LANGINFO 1
|
||||
|
||||
/* Define to 1 if you have the `sbrk' function. */
|
||||
#define HAVE_SBRK 1
|
||||
|
||||
/* Define to 1 if you have the `setpgid' function. */
|
||||
#define HAVE_SETPGID 1
|
||||
|
||||
/* Define to 1 if you have the `setpriority' function. */
|
||||
#define HAVE_SETPRIORITY 1
|
||||
|
||||
/* Define to 1 if you have the <shadow.h> header file. */
|
||||
/* #undef HAVE_SHADOW_H */
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the `strcoll' function and it is properly defined.
|
||||
*/
|
||||
#define HAVE_STRCOLL 1
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#define HAVE_STRERROR 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strstr' function. */
|
||||
#define HAVE_STRSTR 1
|
||||
|
||||
/* Define to 1 if `d_ino' is member of `struct dirent'. */
|
||||
#define HAVE_STRUCT_DIRENT_D_INO 1
|
||||
|
||||
/* Define to 1 if `ss_family' is member of `struct sockaddr_storage'. */
|
||||
#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1
|
||||
|
||||
/* Define to 1 if `ut_host' is member of `struct utmp'. */
|
||||
#define HAVE_STRUCT_UTMP_UT_HOST 1
|
||||
|
||||
/* Define to 1 if `ut_tv' is member of `struct utmp'. */
|
||||
#define HAVE_STRUCT_UTMP_UT_TV 1
|
||||
|
||||
/* Define to 1 if `ut_user' is member of `struct utmp'. */
|
||||
#define HAVE_STRUCT_UTMP_UT_USER 1
|
||||
|
||||
/* Define to 1 if `ut_xtime' is member of `struct utmp'. */
|
||||
/* #undef HAVE_STRUCT_UTMP_UT_XTIME */
|
||||
|
||||
/* Define to 1 if you have the `sysconf' function. */
|
||||
#define HAVE_SYSCONF 1
|
||||
|
||||
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
/* #undef HAVE_SYS_DIR_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
/* #undef HAVE_SYS_NDIR_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to 1 if you have the <utmpx.h> header file. */
|
||||
#define HAVE_UTMPX_H 1
|
||||
|
||||
/* Define to 1 if you have the <utmp.h> header file. */
|
||||
/* #undef HAVE_UTMP_H */
|
||||
|
||||
/* Define to 1 if you have the <wchar.h> header file. */
|
||||
#define HAVE_WCHAR_H 1
|
||||
|
||||
/* Define to 1 if you have the <wctype.h> header file. */
|
||||
#define HAVE_WCTYPE_H 1
|
||||
|
||||
/* Define to 1 if you have the `wcwidth' function. */
|
||||
#define HAVE_WCWIDTH 1
|
||||
|
||||
/* Define as const if the declaration of iconv() needs const. */
|
||||
#define ICONV_CONST const
|
||||
|
||||
/* Support NLS. */
|
||||
#define NLS 1
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME ""
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING ""
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME ""
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION ""
|
||||
|
||||
/* Define to 1 if the `setpgrp' function takes no argument. */
|
||||
/* #undef SETPGRP_VOID */
|
||||
|
||||
/* The size of a `wchar_t', as computed by sizeof. */
|
||||
#define SIZEOF_WCHAR_T 4
|
||||
|
||||
/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
|
||||
/* #undef STAT_MACROS_BROKEN */
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
/* #undef gid_t */
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
/* #undef mode_t */
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
||||
|
||||
/* Define to `int' if neither <sys/types.h> nor <sys/socket.h> define. */
|
||||
/* #undef socklen_t */
|
||||
|
||||
/* Define to `int' not defined in <sys/types.h>. */
|
||||
/* #undef ssize_t */
|
||||
|
||||
/* Define to `int' if <sys/types.h> doesn't define. */
|
||||
/* #undef uid_t */
|
||||
|
||||
/* Define to empty if the keyword `volatile' does not work. Warning: valid
|
||||
code using `volatile' can become incorrect without. Disable with care. */
|
||||
/* #undef volatile */
|
||||
|
||||
#include "config_p.h"
|
||||
#include "config_f.h"
|
||||
|
||||
#ifndef NO_NLS_CATALOGS
|
||||
#define NLS_CATALOGS
|
||||
#endif
|
||||
|
||||
/* Work around a vendor issue where config_f.h is #undef'ing this setting */
|
||||
#define SYSMALLOC
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
/* $FreeBSD$ */
|
||||
/*
|
||||
* config.h -- configure various defines for tcsh
|
||||
*
|
||||
* All source files should #include this FIRST.
|
||||
*
|
||||
* Edit this to match your system type.
|
||||
*/
|
||||
|
||||
#ifndef _h_config
|
||||
#define _h_config
|
||||
/****************** System dependant compilation flags ****************/
|
||||
/*
|
||||
* POSIX This system supports IEEE Std 1003.1-1988 (POSIX).
|
||||
*/
|
||||
#define POSIX
|
||||
|
||||
/*
|
||||
* POSIXJOBS This system supports the optional IEEE Std 1003.1-1988 (POSIX)
|
||||
* job control facilities.
|
||||
*/
|
||||
#define POSIXJOBS
|
||||
|
||||
/*
|
||||
* VFORK This machine has a vfork().
|
||||
* It used to be that for job control to work, this define
|
||||
* was mandatory. This is not the case any more.
|
||||
* If you think you still need it, but you don't have vfork,
|
||||
* define this anyway and then do #define vfork fork.
|
||||
* I do this anyway on a Sun because of yellow pages brain damage,
|
||||
* [should not be needed under 4.1]
|
||||
* and on the iris4d cause SGI's fork is sufficiently "virtual"
|
||||
* that vfork isn't necessary. (Besides, SGI's vfork is weird).
|
||||
* Note that some machines eg. rs6000 have a vfork, but not
|
||||
* with the berkeley semantics, so we cannot use it there either.
|
||||
*/
|
||||
#define VFORK
|
||||
|
||||
/*
|
||||
* BSDJOBS You have BSD-style job control (both process groups and
|
||||
* a tty that deals correctly
|
||||
*/
|
||||
#define BSDJOBS
|
||||
|
||||
/*
|
||||
* BSDTIMES You have BSD-style process time stuff (like rusage)
|
||||
* This may or may not be true. For example, Apple Unix
|
||||
* (OREO) has BSDJOBS but not BSDTIMES.
|
||||
*/
|
||||
#define BSDTIMES
|
||||
|
||||
/*
|
||||
* BSDLIMIT You have BSD-style resource limit stuff (getrlimit/setrlimit)
|
||||
*/
|
||||
#define BSDLIMIT
|
||||
|
||||
/*
|
||||
* TERMIO You have struct termio instead of struct sgttyb.
|
||||
* This is usually the case for SYSV systems, where
|
||||
* BSD uses sgttyb. POSIX systems should define this
|
||||
* anyway, even though they use struct termios.
|
||||
*/
|
||||
#define TERMIO
|
||||
|
||||
/*
|
||||
* SYSVREL Your machine is SYSV based (HPUX, A/UX)
|
||||
* NOTE: don't do this if you are on a Pyramid -- tcsh is
|
||||
* built in a BSD universe.
|
||||
* Set SYSVREL to 1, 2, 3, or 4, depending the version of System V
|
||||
* you are running. Or set it to 0 if you are not SYSV based
|
||||
*/
|
||||
#define SYSVREL 0
|
||||
|
||||
/*
|
||||
* YPBUGS Work around Sun YP bugs that cause expansion of ~username
|
||||
* to send command output to /dev/null
|
||||
*/
|
||||
#undef YPBUGS
|
||||
|
||||
/****************** local defines *********************/
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#define NLS_BUGS
|
||||
#define BSD_STYLE_COLORLS
|
||||
/* Use LC_MESSAGES locale category to open the message catalog */
|
||||
#define MCLoadBySet NL_CAT_LOCALE
|
||||
#define BUFSIZE 8192
|
||||
#define UTMPX_FILE "/var/run/utx.active"
|
||||
#endif
|
||||
|
||||
#if defined(__bsdi__)
|
||||
/*
|
||||
* _PATH_TCSHELL if you've change the installation location (vix)
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
# ifdef _BSDI_VERSION >= 199701
|
||||
# define _PATH_TCSHELL "/bin/tcsh"
|
||||
# undef SYSMALLOC
|
||||
# define SYSMALLOC
|
||||
# else
|
||||
# define _PATH_TCSHELL "/usr/contrib/bin/tcsh"
|
||||
# endif
|
||||
|
||||
# undef NLS
|
||||
# undef NLS_CATALOGS
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
# define SYSMALLOC
|
||||
|
||||
#else
|
||||
# define NLS_CATALOGS
|
||||
#endif
|
||||
|
||||
#endif /* _h_config */
|
||||
1140
bin/csh/host.defs
1140
bin/csh/host.defs
File diff suppressed because it is too large
Load diff
|
|
@ -1,44 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 2006 Hajimu UMEMOTO <ume@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _ICONV_H_
|
||||
#define _ICONV_H_
|
||||
|
||||
typedef void *iconv_t;
|
||||
typedef size_t dl_iconv_t(iconv_t, const char **, size_t *, char **, size_t *);
|
||||
typedef int dl_iconv_close_t(iconv_t);
|
||||
|
||||
extern iconv_t dl_iconv_open(const char *, const char *);
|
||||
extern dl_iconv_t *dl_iconv;
|
||||
extern dl_iconv_close_t *dl_iconv_close;
|
||||
|
||||
#define iconv_open dl_iconv_open
|
||||
#define iconv dl_iconv
|
||||
#define iconv_close dl_iconv_close
|
||||
|
||||
#endif /* !_ICONV_H_ */
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 2006 Hajimu UMEMOTO <ume@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "iconv.h"
|
||||
|
||||
#undef iconv_open
|
||||
#undef iconv
|
||||
#undef iconv_close
|
||||
|
||||
#define ICONVLIB "libiconv.so"
|
||||
#define ICONV_ENGINE "iconv"
|
||||
#define ICONV_OPEN "iconv_open"
|
||||
#define ICONV_CLOSE "iconv_close"
|
||||
|
||||
typedef iconv_t iconv_open_t(const char *, const char *);
|
||||
|
||||
dl_iconv_t *dl_iconv;
|
||||
dl_iconv_close_t *dl_iconv_close;
|
||||
|
||||
static int initialized;
|
||||
static void *iconvlib;
|
||||
static iconv_open_t *iconv_open;
|
||||
|
||||
iconv_t
|
||||
dl_iconv_open(const char *tocode, const char *fromcode)
|
||||
{
|
||||
if (initialized) {
|
||||
if (iconvlib == NULL)
|
||||
return (iconv_t)-1;
|
||||
} else {
|
||||
initialized = 1;
|
||||
iconvlib = dlopen(ICONVLIB, RTLD_LAZY | RTLD_GLOBAL);
|
||||
if (iconvlib == NULL)
|
||||
return (iconv_t)-1;
|
||||
iconv_open = (iconv_open_t *)dlfunc(iconvlib, ICONV_OPEN);
|
||||
if (iconv_open == NULL)
|
||||
goto dlfunc_err;
|
||||
dl_iconv = (dl_iconv_t *)dlfunc(iconvlib, ICONV_ENGINE);
|
||||
if (dl_iconv == NULL)
|
||||
goto dlfunc_err;
|
||||
dl_iconv_close = (dl_iconv_close_t *)dlfunc(iconvlib,
|
||||
ICONV_CLOSE);
|
||||
if (dl_iconv_close == NULL)
|
||||
goto dlfunc_err;
|
||||
}
|
||||
return iconv_open(tocode, fromcode);
|
||||
|
||||
dlfunc_err:
|
||||
dlclose(iconvlib);
|
||||
iconvlib = NULL;
|
||||
return (iconv_t)-1;
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= date
|
||||
SRCS= date.c netdate.c vary.c
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
440
bin/date/date.1
440
bin/date/date.1
|
|
@ -1,440 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 1980, 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" the Institute of Electrical and Electronics Engineers, Inc.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)date.1 8.3 (Berkeley) 4/28/95
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 3, 2010
|
||||
.Dt DATE 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm date
|
||||
.Nd display or set date and time
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl ju
|
||||
.Op Fl r Ar seconds
|
||||
.Oo
|
||||
.Fl v
|
||||
.Sm off
|
||||
.Op Cm + | -
|
||||
.Ar val Op Ar ymwdHMS
|
||||
.Sm on
|
||||
.Oc
|
||||
.Ar ...
|
||||
.Op Cm + Ns Ar output_fmt
|
||||
.Nm
|
||||
.Op Fl jnu
|
||||
.Sm off
|
||||
.Op Oo Oo Oo Oo Ar cc Oc Ar yy Oc Ar mm Oc Ar dd Oc Ar HH
|
||||
.Ar MM Op Ar .ss
|
||||
.Sm on
|
||||
.Nm
|
||||
.Op Fl jnu
|
||||
.Fl f Ar input_fmt new_date
|
||||
.Op Cm + Ns Ar output_fmt
|
||||
.Nm
|
||||
.Op Fl d Ar dst
|
||||
.Op Fl t Ar minutes_west
|
||||
.Sh DESCRIPTION
|
||||
When invoked without arguments, the
|
||||
.Nm
|
||||
utility displays the current date and time.
|
||||
Otherwise, depending on the options specified,
|
||||
.Nm
|
||||
will set the date and time or print it in a user-defined way.
|
||||
.Pp
|
||||
The
|
||||
.Nm
|
||||
utility displays the date and time read from the kernel clock.
|
||||
When used to set the date and time,
|
||||
both the kernel clock and the hardware clock are updated.
|
||||
.Pp
|
||||
Only the superuser may set the date,
|
||||
and if the system securelevel (see
|
||||
.Xr securelevel 7 )
|
||||
is greater than 1,
|
||||
the time may not be changed by more than 1 second.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl d Ar dst
|
||||
Set the kernel's value for daylight saving time.
|
||||
If
|
||||
.Ar dst
|
||||
is non-zero, future calls
|
||||
to
|
||||
.Xr gettimeofday 2
|
||||
will return a non-zero for
|
||||
.Fa tz_dsttime .
|
||||
.It Fl f
|
||||
Use
|
||||
.Ar input_fmt
|
||||
as the format string to parse the
|
||||
.Ar new_date
|
||||
provided rather than using the default
|
||||
.Sm off
|
||||
.Oo Oo Oo Oo Oo
|
||||
.Ar cc Oc
|
||||
.Ar yy Oc
|
||||
.Ar mm Oc
|
||||
.Ar dd Oc
|
||||
.Ar HH
|
||||
.Oc Ar MM Op Ar .ss
|
||||
.Sm on
|
||||
format.
|
||||
Parsing is done using
|
||||
.Xr strptime 3 .
|
||||
.It Fl j
|
||||
Do not try to set the date.
|
||||
This allows you to use the
|
||||
.Fl f
|
||||
flag in addition to the
|
||||
.Cm +
|
||||
option to convert one date format to another.
|
||||
.It Fl n
|
||||
By default, if the
|
||||
.Xr timed 8
|
||||
daemon is running,
|
||||
.Nm
|
||||
sets the time on all of the machines in the local group.
|
||||
The
|
||||
.Fl n
|
||||
option suppresses this behavior and causes the time to be set only on the
|
||||
current machine.
|
||||
.It Fl r Ar seconds
|
||||
Print the date and time represented by
|
||||
.Ar seconds ,
|
||||
where
|
||||
.Ar seconds
|
||||
is the number of seconds since the Epoch
|
||||
(00:00:00 UTC, January 1, 1970;
|
||||
see
|
||||
.Xr time 3 ) ,
|
||||
and can be specified in decimal, octal, or hex.
|
||||
.It Fl t Ar minutes_west
|
||||
Set the system's value for minutes west of
|
||||
.Tn GMT .
|
||||
.Ar minutes_west
|
||||
specifies the number of minutes returned in
|
||||
.Fa tz_minuteswest
|
||||
by future calls to
|
||||
.Xr gettimeofday 2 .
|
||||
.It Fl u
|
||||
Display or set the date in
|
||||
.Tn UTC
|
||||
(Coordinated Universal) time.
|
||||
.It Fl v
|
||||
Adjust (i.e., take the current date and display the result of the
|
||||
adjustment; not actually set the date) the second, minute, hour, month
|
||||
day, week day, month or year according to
|
||||
.Ar val .
|
||||
If
|
||||
.Ar val
|
||||
is preceded with a plus or minus sign,
|
||||
the date is adjusted forwards or backwards according to the remaining string,
|
||||
otherwise the relevant part of the date is set.
|
||||
The date can be adjusted as many times as required using these flags.
|
||||
Flags are processed in the order given.
|
||||
.Pp
|
||||
When setting values
|
||||
(rather than adjusting them),
|
||||
seconds are in the range 0-59, minutes are in the range 0-59, hours are
|
||||
in the range 0-23, month days are in the range 1-31, week days are in the
|
||||
range 0-6 (Sun-Sat),
|
||||
months are in the range 1-12 (Jan-Dec)
|
||||
and years are in the range 80-38 or 1980-2038.
|
||||
.Pp
|
||||
If
|
||||
.Ar val
|
||||
is numeric, one of either
|
||||
.Ar y ,
|
||||
.Ar m ,
|
||||
.Ar w ,
|
||||
.Ar d ,
|
||||
.Ar H ,
|
||||
.Ar M
|
||||
or
|
||||
.Ar S
|
||||
must be used to specify which part of the date is to be adjusted.
|
||||
.Pp
|
||||
The week day or month may be specified using a name rather than a
|
||||
number.
|
||||
If a name is used with the plus
|
||||
(or minus)
|
||||
sign, the date will be put forwards
|
||||
(or backwards)
|
||||
to the next
|
||||
(previous)
|
||||
date that matches the given week day or month.
|
||||
This will not adjust the date,
|
||||
if the given week day or month is the same as the current one.
|
||||
.Pp
|
||||
When a date is adjusted to a specific value or in units greater than hours,
|
||||
daylight savings time considerations are ignored.
|
||||
Adjustments in units of hours or less honor daylight saving time.
|
||||
So, assuming the current date is March 26, 0:30 and that the DST adjustment
|
||||
means that the clock goes forward at 01:00 to 02:00, using
|
||||
.Fl v No +1H
|
||||
will adjust the date to March 26, 2:30.
|
||||
Likewise, if the date is October 29, 0:30 and the DST adjustment means that
|
||||
the clock goes back at 02:00 to 01:00, using
|
||||
.Fl v No +3H
|
||||
will be necessary to reach October 29, 2:30.
|
||||
.Pp
|
||||
When the date is adjusted to a specific value that does not actually exist
|
||||
(for example March 26, 1:30 BST 2000 in the Europe/London timezone),
|
||||
the date will be silently adjusted forwards in units of one hour until it
|
||||
reaches a valid time.
|
||||
When the date is adjusted to a specific value that occurs twice
|
||||
(for example October 29, 1:30 2000),
|
||||
the resulting timezone will be set so that the date matches the earlier of
|
||||
the two times.
|
||||
.Pp
|
||||
It is not possible to adjust a date to an invalid absolute day, so using
|
||||
the switches
|
||||
.Fl v No 31d Fl v No 12m
|
||||
will simply fail five months of the year.
|
||||
It is therefore usual to set the month before setting the day; using
|
||||
.Fl v No 12m Fl v No 31d
|
||||
always works.
|
||||
.Pp
|
||||
Adjusting the date by months is inherently ambiguous because
|
||||
a month is a unit of variable length depending on the current date.
|
||||
This kind of date adjustment is applied in the most intuitive way.
|
||||
First of all,
|
||||
.Nm
|
||||
tries to preserve the day of the month.
|
||||
If it is impossible because the target month is shorter than the present one,
|
||||
the last day of the target month will be the result.
|
||||
For example, using
|
||||
.Fl v No +1m
|
||||
on May 31 will adjust the date to June 30, while using the same option
|
||||
on January 30 will result in the date adjusted to the last day of February.
|
||||
This approach is also believed to make the most sense for shell scripting.
|
||||
Nevertheless, be aware that going forth and back by the same number of
|
||||
months may take you to a different date.
|
||||
.Pp
|
||||
Refer to the examples below for further details.
|
||||
.El
|
||||
.Pp
|
||||
An operand with a leading plus
|
||||
.Pq Sq +
|
||||
sign signals a user-defined format string
|
||||
which specifies the format in which to display the date and time.
|
||||
The format string may contain any of the conversion specifications
|
||||
described in the
|
||||
.Xr strftime 3
|
||||
manual page, as well as any arbitrary text.
|
||||
A newline
|
||||
.Pq Ql \en
|
||||
character is always output after the characters specified by
|
||||
the format string.
|
||||
The format string for the default display is
|
||||
.Dq +%+ .
|
||||
.Pp
|
||||
If an operand does not have a leading plus sign, it is interpreted as
|
||||
a value for setting the system's notion of the current date and time.
|
||||
The canonical representation for setting the date and time is:
|
||||
.Pp
|
||||
.Bl -tag -width Ds -compact -offset indent
|
||||
.It Ar cc
|
||||
Century
|
||||
(either 19 or 20)
|
||||
prepended to the abbreviated year.
|
||||
.It Ar yy
|
||||
Year in abbreviated form
|
||||
(e.g., 89 for 1989, 06 for 2006).
|
||||
.It Ar mm
|
||||
Numeric month, a number from 1 to 12.
|
||||
.It Ar dd
|
||||
Day, a number from 1 to 31.
|
||||
.It Ar HH
|
||||
Hour, a number from 0 to 23.
|
||||
.It Ar MM
|
||||
Minutes, a number from 0 to 59.
|
||||
.It Ar ss
|
||||
Seconds, a number from 0 to 61
|
||||
(59 plus a maximum of two leap seconds).
|
||||
.El
|
||||
.Pp
|
||||
Everything but the minutes is optional.
|
||||
.Pp
|
||||
Time changes for Daylight Saving Time, standard time, leap seconds,
|
||||
and leap years are handled automatically.
|
||||
.Sh ENVIRONMENT
|
||||
The following environment variables affect the execution of
|
||||
.Nm :
|
||||
.Bl -tag -width Ds
|
||||
.It Ev TZ
|
||||
The timezone to use when displaying dates.
|
||||
The normal format is a pathname relative to
|
||||
.Pa /usr/share/zoneinfo .
|
||||
For example, the command
|
||||
.Dq TZ=America/Los_Angeles date
|
||||
displays the current time in California.
|
||||
See
|
||||
.Xr environ 7
|
||||
for more information.
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width /var/log/messages -compact
|
||||
.It Pa /var/log/utx.log
|
||||
record of date resets and time changes
|
||||
.It Pa /var/log/messages
|
||||
record of the user setting the time
|
||||
.El
|
||||
.Sh EXIT STATUS
|
||||
The
|
||||
.Nm
|
||||
utility exits 0 on success, 1 if unable to set the date, and 2
|
||||
if able to set the local date, but unable to set it globally.
|
||||
.Sh EXAMPLES
|
||||
The command:
|
||||
.Pp
|
||||
.Dl "date ""+DATE: %Y-%m-%d%nTIME: %H:%M:%S"""
|
||||
.Pp
|
||||
will display:
|
||||
.Bd -literal -offset indent
|
||||
DATE: 1987-11-21
|
||||
TIME: 13:36:16
|
||||
.Ed
|
||||
.Pp
|
||||
In the Europe/London timezone, the command:
|
||||
.Pp
|
||||
.Dl "date -v1m -v+1y"
|
||||
.Pp
|
||||
will display:
|
||||
.Pp
|
||||
.Dl "Sun Jan 4 04:15:24 GMT 1998"
|
||||
.Pp
|
||||
where it is currently
|
||||
.Li "Mon Aug 4 04:15:24 BST 1997" .
|
||||
.Pp
|
||||
The command:
|
||||
.Pp
|
||||
.Dl "date -v1d -v3m -v0y -v-1d"
|
||||
.Pp
|
||||
will display the last day of February in the year 2000:
|
||||
.Pp
|
||||
.Dl "Tue Feb 29 03:18:00 GMT 2000"
|
||||
.Pp
|
||||
So will the command:
|
||||
.Pp
|
||||
.Dl "date -v3m -v30d -v0y -v-1m"
|
||||
.Pp
|
||||
because there is no such date as the 30th of February.
|
||||
.Pp
|
||||
The command:
|
||||
.Pp
|
||||
.Dl "date -v1d -v+1m -v-1d -v-fri"
|
||||
.Pp
|
||||
will display the last Friday of the month:
|
||||
.Pp
|
||||
.Dl "Fri Aug 29 04:31:11 BST 1997"
|
||||
.Pp
|
||||
where it is currently
|
||||
.Li "Mon Aug 4 04:31:11 BST 1997" .
|
||||
.Pp
|
||||
The command:
|
||||
.Pp
|
||||
.Dl "date 8506131627"
|
||||
.Pp
|
||||
sets the date to
|
||||
.Dq Li "June 13, 1985, 4:27 PM" .
|
||||
.Pp
|
||||
.Dl "date ""+%Y%m%d%H%M.%S"""
|
||||
.Pp
|
||||
may be used on one machine to print out the date
|
||||
suitable for setting on another.
|
||||
.Qq ( Li "+%m%d%H%M%Y.%S"
|
||||
for use on
|
||||
.Tn Linux . )
|
||||
.Pp
|
||||
The command:
|
||||
.Pp
|
||||
.Dl "date 1432"
|
||||
.Pp
|
||||
sets the time to
|
||||
.Li "2:32 PM" ,
|
||||
without modifying the date.
|
||||
.Pp
|
||||
Finally the command:
|
||||
.Pp
|
||||
.Dl "date -j -f ""%a %b %d %T %Z %Y"" ""`date`"" ""+%s"""
|
||||
.Pp
|
||||
can be used to parse the output from
|
||||
.Nm
|
||||
and express it in Epoch time.
|
||||
.Sh DIAGNOSTICS
|
||||
Occasionally, when
|
||||
.Xr timed 8
|
||||
synchronizes the time on many hosts, the setting of a new time value may
|
||||
require more than a few seconds.
|
||||
On these occasions,
|
||||
.Nm
|
||||
prints:
|
||||
.Ql Network time being set .
|
||||
The message
|
||||
.Ql Communication error with timed
|
||||
occurs when the communication
|
||||
between
|
||||
.Nm
|
||||
and
|
||||
.Xr timed 8
|
||||
fails.
|
||||
.Sh SEE ALSO
|
||||
.Xr locale 1 ,
|
||||
.Xr gettimeofday 2 ,
|
||||
.Xr getutxent 3 ,
|
||||
.Xr strftime 3 ,
|
||||
.Xr strptime 3 ,
|
||||
.Xr timed 8
|
||||
.Rs
|
||||
.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD"
|
||||
.%A R. Gusella
|
||||
.%A S. Zatti
|
||||
.Re
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility is expected to be compatible with
|
||||
.St -p1003.2 .
|
||||
The
|
||||
.Fl d , f , j , n , r , t ,
|
||||
and
|
||||
.Fl v
|
||||
options are all extensions to the standard.
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm
|
||||
command appeared in
|
||||
.At v1 .
|
||||
309
bin/date/date.c
309
bin/date/date.c
|
|
@ -1,309 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1985, 1987, 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char const copyright[] =
|
||||
"@(#) Copyright (c) 1985, 1987, 1988, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <utmpx.h>
|
||||
|
||||
#include "extern.h"
|
||||
#include "vary.h"
|
||||
|
||||
#ifndef TM_YEAR_BASE
|
||||
#define TM_YEAR_BASE 1900
|
||||
#endif
|
||||
|
||||
static time_t tval;
|
||||
int retval;
|
||||
|
||||
static void setthetime(const char *, const char *, int, int);
|
||||
static void badformat(void);
|
||||
static void usage(void);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct timezone tz;
|
||||
int ch, rflag;
|
||||
int jflag, nflag;
|
||||
const char *format;
|
||||
char buf[1024];
|
||||
char *endptr, *fmt;
|
||||
char *tmp;
|
||||
int set_timezone;
|
||||
struct vary *v;
|
||||
const struct vary *badv;
|
||||
struct tm lt;
|
||||
|
||||
v = NULL;
|
||||
fmt = NULL;
|
||||
(void) setlocale(LC_TIME, "");
|
||||
tz.tz_dsttime = tz.tz_minuteswest = 0;
|
||||
rflag = 0;
|
||||
jflag = nflag = 0;
|
||||
set_timezone = 0;
|
||||
while ((ch = getopt(argc, argv, "d:f:jnr:t:uv:")) != -1)
|
||||
switch((char)ch) {
|
||||
case 'd': /* daylight savings time */
|
||||
tz.tz_dsttime = strtol(optarg, &endptr, 10) ? 1 : 0;
|
||||
if (endptr == optarg || *endptr != '\0')
|
||||
usage();
|
||||
set_timezone = 1;
|
||||
break;
|
||||
case 'f':
|
||||
fmt = optarg;
|
||||
break;
|
||||
case 'j':
|
||||
jflag = 1; /* don't set time */
|
||||
break;
|
||||
case 'n': /* don't set network */
|
||||
nflag = 1;
|
||||
break;
|
||||
case 'r': /* user specified seconds */
|
||||
rflag = 1;
|
||||
tval = strtoq(optarg, &tmp, 0);
|
||||
if (*tmp != 0)
|
||||
usage();
|
||||
break;
|
||||
case 't': /* minutes west of UTC */
|
||||
/* error check; don't allow "PST" */
|
||||
tz.tz_minuteswest = strtol(optarg, &endptr, 10);
|
||||
if (endptr == optarg || *endptr != '\0')
|
||||
usage();
|
||||
set_timezone = 1;
|
||||
break;
|
||||
case 'u': /* do everything in UTC */
|
||||
(void)setenv("TZ", "UTC0", 1);
|
||||
break;
|
||||
case 'v':
|
||||
v = vary_append(v, optarg);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
/*
|
||||
* If -d or -t, set the timezone or daylight savings time; this
|
||||
* doesn't belong here; the kernel should not know about either.
|
||||
*/
|
||||
if (set_timezone && settimeofday((struct timeval *)NULL, &tz))
|
||||
err(1, "settimeofday (timezone)");
|
||||
|
||||
if (!rflag && time(&tval) == -1)
|
||||
err(1, "time");
|
||||
|
||||
format = "%+";
|
||||
|
||||
/* allow the operands in any order */
|
||||
if (*argv && **argv == '+') {
|
||||
format = *argv + 1;
|
||||
++argv;
|
||||
}
|
||||
|
||||
if (*argv) {
|
||||
setthetime(fmt, *argv, jflag, nflag);
|
||||
++argv;
|
||||
} else if (fmt != NULL)
|
||||
usage();
|
||||
|
||||
if (*argv && **argv == '+')
|
||||
format = *argv + 1;
|
||||
|
||||
lt = *localtime(&tval);
|
||||
badv = vary_apply(v, <);
|
||||
if (badv) {
|
||||
fprintf(stderr, "%s: Cannot apply date adjustment\n",
|
||||
badv->arg);
|
||||
vary_destroy(v);
|
||||
usage();
|
||||
}
|
||||
vary_destroy(v);
|
||||
(void)strftime(buf, sizeof(buf), format, <);
|
||||
(void)printf("%s\n", buf);
|
||||
if (fflush(stdout))
|
||||
err(1, "stdout");
|
||||
exit(retval);
|
||||
}
|
||||
|
||||
#define ATOI2(s) ((s) += 2, ((s)[-2] - '0') * 10 + ((s)[-1] - '0'))
|
||||
|
||||
static void
|
||||
setthetime(const char *fmt, const char *p, int jflag, int nflag)
|
||||
{
|
||||
struct utmpx utx;
|
||||
struct tm *lt;
|
||||
struct timeval tv;
|
||||
const char *dot, *t;
|
||||
int century;
|
||||
|
||||
lt = localtime(&tval);
|
||||
lt->tm_isdst = -1; /* divine correct DST */
|
||||
|
||||
if (fmt != NULL) {
|
||||
t = strptime(p, fmt, lt);
|
||||
if (t == NULL) {
|
||||
fprintf(stderr, "Failed conversion of ``%s''"
|
||||
" using format ``%s''\n", p, fmt);
|
||||
badformat();
|
||||
} else if (*t != '\0')
|
||||
fprintf(stderr, "Warning: Ignoring %ld extraneous"
|
||||
" characters in date string (%s)\n",
|
||||
(long) strlen(t), t);
|
||||
} else {
|
||||
for (t = p, dot = NULL; *t; ++t) {
|
||||
if (isdigit(*t))
|
||||
continue;
|
||||
if (*t == '.' && dot == NULL) {
|
||||
dot = t;
|
||||
continue;
|
||||
}
|
||||
badformat();
|
||||
}
|
||||
|
||||
if (dot != NULL) { /* .ss */
|
||||
dot++; /* *dot++ = '\0'; */
|
||||
if (strlen(dot) != 2)
|
||||
badformat();
|
||||
lt->tm_sec = ATOI2(dot);
|
||||
if (lt->tm_sec > 61)
|
||||
badformat();
|
||||
} else
|
||||
lt->tm_sec = 0;
|
||||
|
||||
century = 0;
|
||||
/* if p has a ".ss" field then let's pretend it's not there */
|
||||
switch (strlen(p) - ((dot != NULL) ? 3 : 0)) {
|
||||
case 12: /* cc */
|
||||
lt->tm_year = ATOI2(p) * 100 - TM_YEAR_BASE;
|
||||
century = 1;
|
||||
/* FALLTHROUGH */
|
||||
case 10: /* yy */
|
||||
if (century)
|
||||
lt->tm_year += ATOI2(p);
|
||||
else {
|
||||
lt->tm_year = ATOI2(p);
|
||||
if (lt->tm_year < 69) /* hack for 2000 ;-} */
|
||||
lt->tm_year += 2000 - TM_YEAR_BASE;
|
||||
else
|
||||
lt->tm_year += 1900 - TM_YEAR_BASE;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
case 8: /* mm */
|
||||
lt->tm_mon = ATOI2(p);
|
||||
if (lt->tm_mon > 12)
|
||||
badformat();
|
||||
--lt->tm_mon; /* time struct is 0 - 11 */
|
||||
/* FALLTHROUGH */
|
||||
case 6: /* dd */
|
||||
lt->tm_mday = ATOI2(p);
|
||||
if (lt->tm_mday > 31)
|
||||
badformat();
|
||||
/* FALLTHROUGH */
|
||||
case 4: /* HH */
|
||||
lt->tm_hour = ATOI2(p);
|
||||
if (lt->tm_hour > 23)
|
||||
badformat();
|
||||
/* FALLTHROUGH */
|
||||
case 2: /* MM */
|
||||
lt->tm_min = ATOI2(p);
|
||||
if (lt->tm_min > 59)
|
||||
badformat();
|
||||
break;
|
||||
default:
|
||||
badformat();
|
||||
}
|
||||
}
|
||||
|
||||
/* convert broken-down time to GMT clock time */
|
||||
if ((tval = mktime(lt)) == -1)
|
||||
errx(1, "nonexistent time");
|
||||
|
||||
if (!jflag) {
|
||||
/* set the time */
|
||||
if (nflag || netsettime(tval)) {
|
||||
utx.ut_type = OLD_TIME;
|
||||
gettimeofday(&utx.ut_tv, NULL);
|
||||
pututxline(&utx);
|
||||
tv.tv_sec = tval;
|
||||
tv.tv_usec = 0;
|
||||
if (settimeofday(&tv, (struct timezone *)NULL))
|
||||
err(1, "settimeofday (timeval)");
|
||||
utx.ut_type = NEW_TIME;
|
||||
gettimeofday(&utx.ut_tv, NULL);
|
||||
pututxline(&utx);
|
||||
}
|
||||
|
||||
if ((p = getlogin()) == NULL)
|
||||
p = "???";
|
||||
syslog(LOG_AUTH | LOG_NOTICE, "date set by %s", p);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
badformat(void)
|
||||
{
|
||||
warnx("illegal time format");
|
||||
usage();
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr, "%s\n%s\n",
|
||||
"usage: date [-jnu] [-d dst] [-r seconds] [-t west] "
|
||||
"[-v[+|-]val[ymwdHMS]] ... ",
|
||||
" "
|
||||
"[-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]");
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)extern.h 8.1 (Berkeley) 5/31/93
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
int netsettime(time_t);
|
||||
|
|
@ -1,183 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)netdate.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#define TSPTYPES
|
||||
#include <protocols/timed.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
#define WAITACK 2 /* seconds */
|
||||
#define WAITDATEACK 5 /* seconds */
|
||||
|
||||
extern int retval;
|
||||
|
||||
/*
|
||||
* Set the date in the machines controlled by timedaemons by communicating the
|
||||
* new date to the local timedaemon. If the timedaemon is in the master state,
|
||||
* it performs the correction on all slaves. If it is in the slave state, it
|
||||
* notifies the master that a correction is needed.
|
||||
* Returns 0 on success. Returns > 0 on failure, setting retval to 2;
|
||||
*/
|
||||
int
|
||||
netsettime(time_t tval)
|
||||
{
|
||||
struct timeval tout;
|
||||
struct servent *sp;
|
||||
struct tsp msg;
|
||||
struct sockaddr_in lsin, dest, from;
|
||||
fd_set ready;
|
||||
long waittime;
|
||||
int s, port, timed_ack, found, lerr;
|
||||
socklen_t length;
|
||||
char hostname[MAXHOSTNAMELEN];
|
||||
|
||||
if ((sp = getservbyname("timed", "udp")) == NULL) {
|
||||
warnx("timed/udp: unknown service");
|
||||
return (retval = 2);
|
||||
}
|
||||
|
||||
dest.sin_port = sp->s_port;
|
||||
dest.sin_family = AF_INET;
|
||||
dest.sin_addr.s_addr = htonl((u_long)INADDR_ANY);
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
if (errno != EPROTONOSUPPORT)
|
||||
warn("timed");
|
||||
return (retval = 2);
|
||||
}
|
||||
|
||||
memset(&lsin, 0, sizeof(lsin));
|
||||
lsin.sin_family = AF_INET;
|
||||
for (port = IPPORT_RESERVED - 1; port > IPPORT_RESERVED / 2; port--) {
|
||||
lsin.sin_port = htons((u_short)port);
|
||||
if (bind(s, (struct sockaddr *)&lsin, sizeof(lsin)) >= 0)
|
||||
break;
|
||||
if (errno == EADDRINUSE)
|
||||
continue;
|
||||
if (errno != EADDRNOTAVAIL)
|
||||
warn("bind");
|
||||
goto bad;
|
||||
}
|
||||
if (port == IPPORT_RESERVED / 2) {
|
||||
warnx("all ports in use");
|
||||
goto bad;
|
||||
}
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
msg.tsp_type = TSP_SETDATE;
|
||||
msg.tsp_vers = TSPVERSION;
|
||||
if (gethostname(hostname, sizeof(hostname))) {
|
||||
warn("gethostname");
|
||||
goto bad;
|
||||
}
|
||||
(void)strlcpy(msg.tsp_name, hostname, sizeof(msg.tsp_name));
|
||||
msg.tsp_seq = htons((u_short)0);
|
||||
msg.tsp_time.tv_sec = htonl((u_long)tval);
|
||||
msg.tsp_time.tv_usec = htonl((u_long)0);
|
||||
length = sizeof(struct sockaddr_in);
|
||||
if (connect(s, (struct sockaddr *)&dest, length) < 0) {
|
||||
warn("connect");
|
||||
goto bad;
|
||||
}
|
||||
if (send(s, (char *)&msg, sizeof(struct tsp), 0) < 0) {
|
||||
if (errno != ECONNREFUSED)
|
||||
warn("send");
|
||||
goto bad;
|
||||
}
|
||||
|
||||
timed_ack = -1;
|
||||
waittime = WAITACK;
|
||||
loop:
|
||||
tout.tv_sec = waittime;
|
||||
tout.tv_usec = 0;
|
||||
|
||||
FD_ZERO(&ready);
|
||||
FD_SET(s, &ready);
|
||||
found = select(FD_SETSIZE, &ready, (fd_set *)0, (fd_set *)0, &tout);
|
||||
|
||||
length = sizeof(lerr);
|
||||
if (!getsockopt(s,
|
||||
SOL_SOCKET, SO_ERROR, (char *)&lerr, &length) && lerr) {
|
||||
if (lerr != ECONNREFUSED)
|
||||
warnc(lerr, "send (delayed error)");
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (found > 0 && FD_ISSET(s, &ready)) {
|
||||
length = sizeof(struct sockaddr_in);
|
||||
if (recvfrom(s, &msg, sizeof(struct tsp), 0,
|
||||
(struct sockaddr *)&from, &length) < 0) {
|
||||
if (errno != ECONNREFUSED)
|
||||
warn("recvfrom");
|
||||
goto bad;
|
||||
}
|
||||
msg.tsp_seq = ntohs(msg.tsp_seq);
|
||||
msg.tsp_time.tv_sec = ntohl(msg.tsp_time.tv_sec);
|
||||
msg.tsp_time.tv_usec = ntohl(msg.tsp_time.tv_usec);
|
||||
switch (msg.tsp_type) {
|
||||
case TSP_ACK:
|
||||
timed_ack = TSP_ACK;
|
||||
waittime = WAITDATEACK;
|
||||
goto loop;
|
||||
case TSP_DATEACK:
|
||||
(void)close(s);
|
||||
return (0);
|
||||
default:
|
||||
warnx("wrong ack received from timed: %s",
|
||||
tsptype[msg.tsp_type]);
|
||||
timed_ack = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (timed_ack == -1)
|
||||
warnx("can't reach time daemon, time set locally");
|
||||
|
||||
bad:
|
||||
(void)close(s);
|
||||
return (retval = 2);
|
||||
}
|
||||
506
bin/date/vary.c
506
bin/date/vary.c
|
|
@ -1,506 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1997 Brian Somers <brian@Awfulhak.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <err.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "vary.h"
|
||||
|
||||
struct trans {
|
||||
int val;
|
||||
const char *str;
|
||||
};
|
||||
|
||||
static struct trans trans_mon[] = {
|
||||
{ 1, "january" }, { 2, "february" }, { 3, "march" }, { 4, "april" },
|
||||
{ 5, "may"}, { 6, "june" }, { 7, "july" }, { 8, "august" },
|
||||
{ 9, "september" }, { 10, "october" }, { 11, "november" }, { 12, "december" },
|
||||
{ -1, NULL }
|
||||
};
|
||||
|
||||
static struct trans trans_wday[] = {
|
||||
{ 0, "sunday" }, { 1, "monday" }, { 2, "tuesday" }, { 3, "wednesday" },
|
||||
{ 4, "thursday" }, { 5, "friday" }, { 6, "saturday" },
|
||||
{ -1, NULL }
|
||||
};
|
||||
|
||||
static char digits[] = "0123456789";
|
||||
static int adjhour(struct tm *, char, int, int);
|
||||
|
||||
static int
|
||||
domktime(struct tm *t, char type)
|
||||
{
|
||||
time_t ret;
|
||||
|
||||
while ((ret = mktime(t)) == -1 && t->tm_year > 68 && t->tm_year < 138)
|
||||
/* While mktime() fails, adjust by an hour */
|
||||
adjhour(t, type == '-' ? type : '+', 1, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
trans(const struct trans t[], const char *arg)
|
||||
{
|
||||
int f;
|
||||
|
||||
for (f = 0; t[f].val != -1; f++)
|
||||
if (!strncasecmp(t[f].str, arg, 3) ||
|
||||
!strncasecmp(t[f].str, arg, strlen(t[f].str)))
|
||||
return t[f].val;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct vary *
|
||||
vary_append(struct vary *v, char *arg)
|
||||
{
|
||||
struct vary *result, **nextp;
|
||||
|
||||
if (v) {
|
||||
result = v;
|
||||
while (v->next)
|
||||
v = v->next;
|
||||
nextp = &v->next;
|
||||
} else
|
||||
nextp = &result;
|
||||
|
||||
if ((*nextp = (struct vary *)malloc(sizeof(struct vary))) == NULL)
|
||||
err(1, "malloc");
|
||||
(*nextp)->arg = arg;
|
||||
(*nextp)->next = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
static int mdays[12] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
|
||||
static int
|
||||
daysinmonth(const struct tm *t)
|
||||
{
|
||||
int year;
|
||||
|
||||
year = t->tm_year + 1900;
|
||||
|
||||
if (t->tm_mon == 1)
|
||||
if (!(year % 400))
|
||||
return 29;
|
||||
else if (!(year % 100))
|
||||
return 28;
|
||||
else if (!(year % 4))
|
||||
return 29;
|
||||
else
|
||||
return 28;
|
||||
else if (t->tm_mon >= 0 && t->tm_mon < 12)
|
||||
return mdays[t->tm_mon];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
adjyear(struct tm *t, char type, int val, int mk)
|
||||
{
|
||||
switch (type) {
|
||||
case '+':
|
||||
t->tm_year += val;
|
||||
break;
|
||||
case '-':
|
||||
t->tm_year -= val;
|
||||
break;
|
||||
default:
|
||||
t->tm_year = val;
|
||||
if (t->tm_year < 69)
|
||||
t->tm_year += 100; /* as per date.c */
|
||||
else if (t->tm_year > 1900)
|
||||
t->tm_year -= 1900; /* struct tm holds years since 1900 */
|
||||
break;
|
||||
}
|
||||
return !mk || domktime(t, type) != -1;
|
||||
}
|
||||
|
||||
static int
|
||||
adjmon(struct tm *t, char type, int val, int istext, int mk)
|
||||
{
|
||||
int lmdays;
|
||||
|
||||
if (val < 0)
|
||||
return 0;
|
||||
|
||||
switch (type) {
|
||||
case '+':
|
||||
if (istext) {
|
||||
if (val <= t->tm_mon)
|
||||
val += 11 - t->tm_mon; /* early next year */
|
||||
else
|
||||
val -= t->tm_mon + 1; /* later this year */
|
||||
}
|
||||
if (val) {
|
||||
if (!adjyear(t, '+', (t->tm_mon + val) / 12, 0))
|
||||
return 0;
|
||||
val %= 12;
|
||||
t->tm_mon += val;
|
||||
if (t->tm_mon > 11)
|
||||
t->tm_mon -= 12;
|
||||
}
|
||||
break;
|
||||
|
||||
case '-':
|
||||
if (istext) {
|
||||
if (val-1 > t->tm_mon)
|
||||
val = 13 - val + t->tm_mon; /* later last year */
|
||||
else
|
||||
val = t->tm_mon - val + 1; /* early this year */
|
||||
}
|
||||
if (val) {
|
||||
if (!adjyear(t, '-', val / 12, 0))
|
||||
return 0;
|
||||
val %= 12;
|
||||
if (val > t->tm_mon) {
|
||||
if (!adjyear(t, '-', 1, 0))
|
||||
return 0;
|
||||
val -= 12;
|
||||
}
|
||||
t->tm_mon -= val;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (val > 12 || val < 1)
|
||||
return 0;
|
||||
t->tm_mon = --val;
|
||||
}
|
||||
|
||||
/* e.g., -v-1m on March, 31 is the last day of February in common sense */
|
||||
lmdays = daysinmonth(t);
|
||||
if (t->tm_mday > lmdays)
|
||||
t->tm_mday = lmdays;
|
||||
|
||||
return !mk || domktime(t, type) != -1;
|
||||
}
|
||||
|
||||
static int
|
||||
adjday(struct tm *t, char type, int val, int mk)
|
||||
{
|
||||
int lmdays;
|
||||
|
||||
switch (type) {
|
||||
case '+':
|
||||
while (val) {
|
||||
lmdays = daysinmonth(t);
|
||||
if (val > lmdays - t->tm_mday) {
|
||||
val -= lmdays - t->tm_mday + 1;
|
||||
t->tm_mday = 1;
|
||||
if (!adjmon(t, '+', 1, 0, 0))
|
||||
return 0;
|
||||
} else {
|
||||
t->tm_mday += val;
|
||||
val = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
while (val)
|
||||
if (val >= t->tm_mday) {
|
||||
val -= t->tm_mday;
|
||||
t->tm_mday = 1;
|
||||
if (!adjmon(t, '-', 1, 0, 0))
|
||||
return 0;
|
||||
t->tm_mday = daysinmonth(t);
|
||||
} else {
|
||||
t->tm_mday -= val;
|
||||
val = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (val > 0 && val <= daysinmonth(t))
|
||||
t->tm_mday = val;
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return !mk || domktime(t, type) != -1;
|
||||
}
|
||||
|
||||
static int
|
||||
adjwday(struct tm *t, char type, int val, int istext, int mk)
|
||||
{
|
||||
if (val < 0)
|
||||
return 0;
|
||||
|
||||
switch (type) {
|
||||
case '+':
|
||||
if (istext)
|
||||
if (val < t->tm_wday)
|
||||
val = 7 - t->tm_wday + val; /* early next week */
|
||||
else
|
||||
val -= t->tm_wday; /* later this week */
|
||||
else
|
||||
val *= 7; /* "-v+5w" == "5 weeks in the future" */
|
||||
return !val || adjday(t, '+', val, mk);
|
||||
case '-':
|
||||
if (istext) {
|
||||
if (val > t->tm_wday)
|
||||
val = 7 - val + t->tm_wday; /* later last week */
|
||||
else
|
||||
val = t->tm_wday - val; /* early this week */
|
||||
} else
|
||||
val *= 7; /* "-v-5w" == "5 weeks ago" */
|
||||
return !val || adjday(t, '-', val, mk);
|
||||
default:
|
||||
if (val < t->tm_wday)
|
||||
return adjday(t, '-', t->tm_wday - val, mk);
|
||||
else if (val > 6)
|
||||
return 0;
|
||||
else if (val > t->tm_wday)
|
||||
return adjday(t, '+', val - t->tm_wday, mk);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
adjhour(struct tm *t, char type, int val, int mk)
|
||||
{
|
||||
if (val < 0)
|
||||
return 0;
|
||||
|
||||
switch (type) {
|
||||
case '+':
|
||||
if (val) {
|
||||
int days;
|
||||
|
||||
days = (t->tm_hour + val) / 24;
|
||||
val %= 24;
|
||||
t->tm_hour += val;
|
||||
t->tm_hour %= 24;
|
||||
if (!adjday(t, '+', days, 0))
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case '-':
|
||||
if (val) {
|
||||
int days;
|
||||
|
||||
days = val / 24;
|
||||
val %= 24;
|
||||
if (val > t->tm_hour) {
|
||||
days++;
|
||||
val -= 24;
|
||||
}
|
||||
t->tm_hour -= val;
|
||||
if (!adjday(t, '-', days, 0))
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (val > 23)
|
||||
return 0;
|
||||
t->tm_hour = val;
|
||||
}
|
||||
|
||||
return !mk || domktime(t, type) != -1;
|
||||
}
|
||||
|
||||
static int
|
||||
adjmin(struct tm *t, char type, int val, int mk)
|
||||
{
|
||||
if (val < 0)
|
||||
return 0;
|
||||
|
||||
switch (type) {
|
||||
case '+':
|
||||
if (val) {
|
||||
if (!adjhour(t, '+', (t->tm_min + val) / 60, 0))
|
||||
return 0;
|
||||
val %= 60;
|
||||
t->tm_min += val;
|
||||
if (t->tm_min > 59)
|
||||
t->tm_min -= 60;
|
||||
}
|
||||
break;
|
||||
|
||||
case '-':
|
||||
if (val) {
|
||||
if (!adjhour(t, '-', val / 60, 0))
|
||||
return 0;
|
||||
val %= 60;
|
||||
if (val > t->tm_min) {
|
||||
if (!adjhour(t, '-', 1, 0))
|
||||
return 0;
|
||||
val -= 60;
|
||||
}
|
||||
t->tm_min -= val;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (val > 59)
|
||||
return 0;
|
||||
t->tm_min = val;
|
||||
}
|
||||
|
||||
return !mk || domktime(t, type) != -1;
|
||||
}
|
||||
|
||||
static int
|
||||
adjsec(struct tm *t, char type, int val, int mk)
|
||||
{
|
||||
if (val < 0)
|
||||
return 0;
|
||||
|
||||
switch (type) {
|
||||
case '+':
|
||||
if (val) {
|
||||
if (!adjmin(t, '+', (t->tm_sec + val) / 60, 0))
|
||||
return 0;
|
||||
val %= 60;
|
||||
t->tm_sec += val;
|
||||
if (t->tm_sec > 59)
|
||||
t->tm_sec -= 60;
|
||||
}
|
||||
break;
|
||||
|
||||
case '-':
|
||||
if (val) {
|
||||
if (!adjmin(t, '-', val / 60, 0))
|
||||
return 0;
|
||||
val %= 60;
|
||||
if (val > t->tm_sec) {
|
||||
if (!adjmin(t, '-', 1, 0))
|
||||
return 0;
|
||||
val -= 60;
|
||||
}
|
||||
t->tm_sec -= val;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (val > 59)
|
||||
return 0;
|
||||
t->tm_sec = val;
|
||||
}
|
||||
|
||||
return !mk || domktime(t, type) != -1;
|
||||
}
|
||||
|
||||
const struct vary *
|
||||
vary_apply(const struct vary *v, struct tm *t)
|
||||
{
|
||||
char type;
|
||||
char which;
|
||||
char *arg;
|
||||
size_t len;
|
||||
int val;
|
||||
|
||||
for (; v; v = v->next) {
|
||||
type = *v->arg;
|
||||
arg = v->arg;
|
||||
if (type == '+' || type == '-')
|
||||
arg++;
|
||||
else
|
||||
type = '\0';
|
||||
len = strlen(arg);
|
||||
if (len < 2)
|
||||
return v;
|
||||
|
||||
if (type == '\0')
|
||||
t->tm_isdst = -1;
|
||||
|
||||
if (strspn(arg, digits) != len-1) {
|
||||
val = trans(trans_wday, arg);
|
||||
if (val != -1) {
|
||||
if (!adjwday(t, type, val, 1, 1))
|
||||
return v;
|
||||
} else {
|
||||
val = trans(trans_mon, arg);
|
||||
if (val != -1) {
|
||||
if (!adjmon(t, type, val, 1, 1))
|
||||
return v;
|
||||
} else
|
||||
return v;
|
||||
}
|
||||
} else {
|
||||
val = atoi(arg);
|
||||
which = arg[len-1];
|
||||
|
||||
switch (which) {
|
||||
case 'S':
|
||||
if (!adjsec(t, type, val, 1))
|
||||
return v;
|
||||
break;
|
||||
case 'M':
|
||||
if (!adjmin(t, type, val, 1))
|
||||
return v;
|
||||
break;
|
||||
case 'H':
|
||||
if (!adjhour(t, type, val, 1))
|
||||
return v;
|
||||
break;
|
||||
case 'd':
|
||||
t->tm_isdst = -1;
|
||||
if (!adjday(t, type, val, 1))
|
||||
return v;
|
||||
break;
|
||||
case 'w':
|
||||
t->tm_isdst = -1;
|
||||
if (!adjwday(t, type, val, 0, 1))
|
||||
return v;
|
||||
break;
|
||||
case 'm':
|
||||
t->tm_isdst = -1;
|
||||
if (!adjmon(t, type, val, 0, 1))
|
||||
return v;
|
||||
break;
|
||||
case 'y':
|
||||
t->tm_isdst = -1;
|
||||
if (!adjyear(t, type, val, 1))
|
||||
return v;
|
||||
break;
|
||||
default:
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
vary_destroy(struct vary *v)
|
||||
{
|
||||
struct vary *n;
|
||||
|
||||
while (v) {
|
||||
n = v->next;
|
||||
free(v);
|
||||
v = n;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1997 Brian Somers <brian@Awfulhak.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
struct vary {
|
||||
char *arg;
|
||||
struct vary *next;
|
||||
};
|
||||
|
||||
extern struct vary *vary_append(struct vary *v, char *arg);
|
||||
extern const struct vary *vary_apply(const struct vary *v, struct tm *t);
|
||||
extern void vary_destroy(struct vary *v);
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= dd
|
||||
SRCS= args.c conv.c conv_tab.c dd.c misc.c position.c
|
||||
|
||||
#
|
||||
# Test the character conversion functions. We have to be explicit about
|
||||
# which LC_LANG we use because the definition of upper and lower case
|
||||
# depends on it.
|
||||
#
|
||||
|
||||
CLEANFILES= gen
|
||||
|
||||
test: ${PROG} gen
|
||||
.for conv in ascii ebcdic ibm oldascii oldebcdic oldibm \
|
||||
pareven parnone parodd parset \
|
||||
swab lcase ucase
|
||||
@${ECHO} testing conv=${conv}
|
||||
@./gen | \
|
||||
LC_ALL=en_US.US-ASCII ./dd conv=${conv} 2>/dev/null | \
|
||||
LC_ALL=en_US.US-ASCII hexdump -C | \
|
||||
diff -I FreeBSD - ${.CURDIR}/ref.${conv}
|
||||
.endfor
|
||||
@rm -f gen
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
498
bin/dd/args.c
498
bin/dd/args.c
|
|
@ -1,498 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Keith Muller of the University of California, San Diego and Lance
|
||||
* Visser of Convex Computer Corporation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)args.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "dd.h"
|
||||
#include "extern.h"
|
||||
|
||||
static int c_arg(const void *, const void *);
|
||||
static int c_conv(const void *, const void *);
|
||||
static void f_bs(char *);
|
||||
static void f_cbs(char *);
|
||||
static void f_conv(char *);
|
||||
static void f_count(char *);
|
||||
static void f_files(char *);
|
||||
static void f_fillchar(char *);
|
||||
static void f_ibs(char *);
|
||||
static void f_if(char *);
|
||||
static void f_obs(char *);
|
||||
static void f_of(char *);
|
||||
static void f_seek(char *);
|
||||
static void f_skip(char *);
|
||||
static uintmax_t get_num(const char *);
|
||||
static off_t get_off_t(const char *);
|
||||
|
||||
static const struct arg {
|
||||
const char *name;
|
||||
void (*f)(char *);
|
||||
u_int set, noset;
|
||||
} args[] = {
|
||||
{ "bs", f_bs, C_BS, C_BS|C_IBS|C_OBS|C_OSYNC },
|
||||
{ "cbs", f_cbs, C_CBS, C_CBS },
|
||||
{ "conv", f_conv, 0, 0 },
|
||||
{ "count", f_count, C_COUNT, C_COUNT },
|
||||
{ "files", f_files, C_FILES, C_FILES },
|
||||
{ "fillchar", f_fillchar, C_FILL, C_FILL },
|
||||
{ "ibs", f_ibs, C_IBS, C_BS|C_IBS },
|
||||
{ "if", f_if, C_IF, C_IF },
|
||||
{ "iseek", f_skip, C_SKIP, C_SKIP },
|
||||
{ "obs", f_obs, C_OBS, C_BS|C_OBS },
|
||||
{ "of", f_of, C_OF, C_OF },
|
||||
{ "oseek", f_seek, C_SEEK, C_SEEK },
|
||||
{ "seek", f_seek, C_SEEK, C_SEEK },
|
||||
{ "skip", f_skip, C_SKIP, C_SKIP },
|
||||
};
|
||||
|
||||
static char *oper;
|
||||
|
||||
/*
|
||||
* args -- parse JCL syntax of dd.
|
||||
*/
|
||||
void
|
||||
jcl(char **argv)
|
||||
{
|
||||
struct arg *ap, tmp;
|
||||
char *arg;
|
||||
|
||||
in.dbsz = out.dbsz = 512;
|
||||
|
||||
while ((oper = *++argv) != NULL) {
|
||||
if ((oper = strdup(oper)) == NULL)
|
||||
errx(1, "unable to allocate space for the argument \"%s\"", *argv);
|
||||
if ((arg = strchr(oper, '=')) == NULL)
|
||||
errx(1, "unknown operand %s", oper);
|
||||
*arg++ = '\0';
|
||||
if (!*arg)
|
||||
errx(1, "no value specified for %s", oper);
|
||||
tmp.name = oper;
|
||||
if (!(ap = (struct arg *)bsearch(&tmp, args,
|
||||
sizeof(args)/sizeof(struct arg), sizeof(struct arg),
|
||||
c_arg)))
|
||||
errx(1, "unknown operand %s", tmp.name);
|
||||
if (ddflags & ap->noset)
|
||||
errx(1, "%s: illegal argument combination or already set",
|
||||
tmp.name);
|
||||
ddflags |= ap->set;
|
||||
ap->f(arg);
|
||||
}
|
||||
|
||||
/* Final sanity checks. */
|
||||
|
||||
if (ddflags & C_BS) {
|
||||
/*
|
||||
* Bs is turned off by any conversion -- we assume the user
|
||||
* just wanted to set both the input and output block sizes
|
||||
* and didn't want the bs semantics, so we don't warn.
|
||||
*/
|
||||
if (ddflags & (C_BLOCK | C_LCASE | C_SWAB | C_UCASE |
|
||||
C_UNBLOCK))
|
||||
ddflags &= ~C_BS;
|
||||
|
||||
/* Bs supersedes ibs and obs. */
|
||||
if (ddflags & C_BS && ddflags & (C_IBS | C_OBS))
|
||||
warnx("bs supersedes ibs and obs");
|
||||
}
|
||||
|
||||
/*
|
||||
* Ascii/ebcdic and cbs implies block/unblock.
|
||||
* Block/unblock requires cbs and vice-versa.
|
||||
*/
|
||||
if (ddflags & (C_BLOCK | C_UNBLOCK)) {
|
||||
if (!(ddflags & C_CBS))
|
||||
errx(1, "record operations require cbs");
|
||||
if (cbsz == 0)
|
||||
errx(1, "cbs cannot be zero");
|
||||
cfunc = ddflags & C_BLOCK ? block : unblock;
|
||||
} else if (ddflags & C_CBS) {
|
||||
if (ddflags & (C_ASCII | C_EBCDIC)) {
|
||||
if (ddflags & C_ASCII) {
|
||||
ddflags |= C_UNBLOCK;
|
||||
cfunc = unblock;
|
||||
} else {
|
||||
ddflags |= C_BLOCK;
|
||||
cfunc = block;
|
||||
}
|
||||
} else
|
||||
errx(1, "cbs meaningless if not doing record operations");
|
||||
} else
|
||||
cfunc = def;
|
||||
|
||||
/*
|
||||
* Bail out if the calculation of a file offset would overflow.
|
||||
*/
|
||||
if (in.offset > OFF_MAX / (ssize_t)in.dbsz ||
|
||||
out.offset > OFF_MAX / (ssize_t)out.dbsz)
|
||||
errx(1, "seek offsets cannot be larger than %jd",
|
||||
(intmax_t)OFF_MAX);
|
||||
}
|
||||
|
||||
static int
|
||||
c_arg(const void *a, const void *b)
|
||||
{
|
||||
|
||||
return (strcmp(((const struct arg *)a)->name,
|
||||
((const struct arg *)b)->name));
|
||||
}
|
||||
|
||||
static void
|
||||
f_bs(char *arg)
|
||||
{
|
||||
uintmax_t res;
|
||||
|
||||
res = get_num(arg);
|
||||
if (res < 1 || res > SSIZE_MAX)
|
||||
errx(1, "bs must be between 1 and %jd", (intmax_t)SSIZE_MAX);
|
||||
in.dbsz = out.dbsz = (size_t)res;
|
||||
}
|
||||
|
||||
static void
|
||||
f_cbs(char *arg)
|
||||
{
|
||||
uintmax_t res;
|
||||
|
||||
res = get_num(arg);
|
||||
if (res < 1 || res > SSIZE_MAX)
|
||||
errx(1, "cbs must be between 1 and %jd", (intmax_t)SSIZE_MAX);
|
||||
cbsz = (size_t)res;
|
||||
}
|
||||
|
||||
static void
|
||||
f_count(char *arg)
|
||||
{
|
||||
intmax_t res;
|
||||
|
||||
res = (intmax_t)get_num(arg);
|
||||
if (res < 0)
|
||||
errx(1, "count cannot be negative");
|
||||
if (res == 0)
|
||||
cpy_cnt = (uintmax_t)-1;
|
||||
else
|
||||
cpy_cnt = (uintmax_t)res;
|
||||
}
|
||||
|
||||
static void
|
||||
f_files(char *arg)
|
||||
{
|
||||
|
||||
files_cnt = get_num(arg);
|
||||
if (files_cnt < 1)
|
||||
errx(1, "files must be between 1 and %jd", (uintmax_t)-1);
|
||||
}
|
||||
|
||||
static void
|
||||
f_fillchar(char *arg)
|
||||
{
|
||||
|
||||
if (strlen(arg) != 1)
|
||||
errx(1, "need exactly one fill char");
|
||||
|
||||
fill_char = arg[0];
|
||||
}
|
||||
|
||||
static void
|
||||
f_ibs(char *arg)
|
||||
{
|
||||
uintmax_t res;
|
||||
|
||||
if (!(ddflags & C_BS)) {
|
||||
res = get_num(arg);
|
||||
if (res < 1 || res > SSIZE_MAX)
|
||||
errx(1, "ibs must be between 1 and %jd",
|
||||
(intmax_t)SSIZE_MAX);
|
||||
in.dbsz = (size_t)res;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
f_if(char *arg)
|
||||
{
|
||||
|
||||
in.name = arg;
|
||||
}
|
||||
|
||||
static void
|
||||
f_obs(char *arg)
|
||||
{
|
||||
uintmax_t res;
|
||||
|
||||
if (!(ddflags & C_BS)) {
|
||||
res = get_num(arg);
|
||||
if (res < 1 || res > SSIZE_MAX)
|
||||
errx(1, "obs must be between 1 and %jd",
|
||||
(intmax_t)SSIZE_MAX);
|
||||
out.dbsz = (size_t)res;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
f_of(char *arg)
|
||||
{
|
||||
|
||||
out.name = arg;
|
||||
}
|
||||
|
||||
static void
|
||||
f_seek(char *arg)
|
||||
{
|
||||
|
||||
out.offset = get_off_t(arg);
|
||||
}
|
||||
|
||||
static void
|
||||
f_skip(char *arg)
|
||||
{
|
||||
|
||||
in.offset = get_off_t(arg);
|
||||
}
|
||||
|
||||
static const struct conv {
|
||||
const char *name;
|
||||
u_int set, noset;
|
||||
const u_char *ctab;
|
||||
} clist[] = {
|
||||
{ "ascii", C_ASCII, C_EBCDIC, e2a_POSIX },
|
||||
{ "block", C_BLOCK, C_UNBLOCK, NULL },
|
||||
{ "ebcdic", C_EBCDIC, C_ASCII, a2e_POSIX },
|
||||
{ "ibm", C_EBCDIC, C_ASCII, a2ibm_POSIX },
|
||||
{ "lcase", C_LCASE, C_UCASE, NULL },
|
||||
{ "noerror", C_NOERROR, 0, NULL },
|
||||
{ "notrunc", C_NOTRUNC, 0, NULL },
|
||||
{ "oldascii", C_ASCII, C_EBCDIC, e2a_32V },
|
||||
{ "oldebcdic", C_EBCDIC, C_ASCII, a2e_32V },
|
||||
{ "oldibm", C_EBCDIC, C_ASCII, a2ibm_32V },
|
||||
{ "osync", C_OSYNC, C_BS, NULL },
|
||||
{ "pareven", C_PAREVEN, C_PARODD|C_PARSET|C_PARNONE, NULL},
|
||||
{ "parnone", C_PARNONE, C_PARODD|C_PARSET|C_PAREVEN, NULL},
|
||||
{ "parodd", C_PARODD, C_PAREVEN|C_PARSET|C_PARNONE, NULL},
|
||||
{ "parset", C_PARSET, C_PARODD|C_PAREVEN|C_PARNONE, NULL},
|
||||
{ "sparse", C_SPARSE, 0, NULL },
|
||||
{ "swab", C_SWAB, 0, NULL },
|
||||
{ "sync", C_SYNC, 0, NULL },
|
||||
{ "ucase", C_UCASE, C_LCASE, NULL },
|
||||
{ "unblock", C_UNBLOCK, C_BLOCK, NULL },
|
||||
};
|
||||
|
||||
static void
|
||||
f_conv(char *arg)
|
||||
{
|
||||
struct conv *cp, tmp;
|
||||
|
||||
while (arg != NULL) {
|
||||
tmp.name = strsep(&arg, ",");
|
||||
cp = bsearch(&tmp, clist, sizeof(clist) / sizeof(struct conv),
|
||||
sizeof(struct conv), c_conv);
|
||||
if (cp == NULL)
|
||||
errx(1, "unknown conversion %s", tmp.name);
|
||||
if (ddflags & cp->noset)
|
||||
errx(1, "%s: illegal conversion combination", tmp.name);
|
||||
ddflags |= cp->set;
|
||||
if (cp->ctab)
|
||||
ctab = cp->ctab;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
c_conv(const void *a, const void *b)
|
||||
{
|
||||
|
||||
return (strcmp(((const struct conv *)a)->name,
|
||||
((const struct conv *)b)->name));
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an expression of the following forms to a uintmax_t.
|
||||
* 1) A positive decimal number.
|
||||
* 2) A positive decimal number followed by a 'b' or 'B' (mult by 512).
|
||||
* 3) A positive decimal number followed by a 'k' or 'K' (mult by 1 << 10).
|
||||
* 4) A positive decimal number followed by a 'm' or 'M' (mult by 1 << 20).
|
||||
* 5) A positive decimal number followed by a 'g' or 'G' (mult by 1 << 30).
|
||||
* 5) A positive decimal number followed by a 'w' or 'W' (mult by sizeof int).
|
||||
* 6) Two or more positive decimal numbers (with/without [BbKkMmGgWw])
|
||||
* separated by 'x' or 'X' (also '*' for backwards compatibility),
|
||||
* specifying the product of the indicated values.
|
||||
*/
|
||||
static uintmax_t
|
||||
get_num(const char *val)
|
||||
{
|
||||
uintmax_t num, mult, prevnum;
|
||||
char *expr;
|
||||
|
||||
errno = 0;
|
||||
num = strtouq(val, &expr, 0);
|
||||
if (errno != 0) /* Overflow or underflow. */
|
||||
err(1, "%s", oper);
|
||||
|
||||
if (expr == val) /* No valid digits. */
|
||||
errx(1, "%s: illegal numeric value", oper);
|
||||
|
||||
mult = 0;
|
||||
switch (*expr) {
|
||||
case 'B':
|
||||
case 'b':
|
||||
mult = 512;
|
||||
break;
|
||||
case 'K':
|
||||
case 'k':
|
||||
mult = 1 << 10;
|
||||
break;
|
||||
case 'M':
|
||||
case 'm':
|
||||
mult = 1 << 20;
|
||||
break;
|
||||
case 'G':
|
||||
case 'g':
|
||||
mult = 1 << 30;
|
||||
break;
|
||||
case 'W':
|
||||
case 'w':
|
||||
mult = sizeof(int);
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
||||
if (mult != 0) {
|
||||
prevnum = num;
|
||||
num *= mult;
|
||||
/* Check for overflow. */
|
||||
if (num / mult != prevnum)
|
||||
goto erange;
|
||||
expr++;
|
||||
}
|
||||
|
||||
switch (*expr) {
|
||||
case '\0':
|
||||
break;
|
||||
case '*': /* Backward compatible. */
|
||||
case 'X':
|
||||
case 'x':
|
||||
mult = get_num(expr + 1);
|
||||
prevnum = num;
|
||||
num *= mult;
|
||||
if (num / mult == prevnum)
|
||||
break;
|
||||
erange:
|
||||
errx(1, "%s: %s", oper, strerror(ERANGE));
|
||||
default:
|
||||
errx(1, "%s: illegal numeric value", oper);
|
||||
}
|
||||
return (num);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an expression of the following forms to an off_t. This is the
|
||||
* same as get_num(), but it uses signed numbers.
|
||||
*
|
||||
* The major problem here is that an off_t may not necessarily be a intmax_t.
|
||||
*/
|
||||
static off_t
|
||||
get_off_t(const char *val)
|
||||
{
|
||||
intmax_t num, mult, prevnum;
|
||||
char *expr;
|
||||
|
||||
errno = 0;
|
||||
num = strtoq(val, &expr, 0);
|
||||
if (errno != 0) /* Overflow or underflow. */
|
||||
err(1, "%s", oper);
|
||||
|
||||
if (expr == val) /* No valid digits. */
|
||||
errx(1, "%s: illegal numeric value", oper);
|
||||
|
||||
mult = 0;
|
||||
switch (*expr) {
|
||||
case 'B':
|
||||
case 'b':
|
||||
mult = 512;
|
||||
break;
|
||||
case 'K':
|
||||
case 'k':
|
||||
mult = 1 << 10;
|
||||
break;
|
||||
case 'M':
|
||||
case 'm':
|
||||
mult = 1 << 20;
|
||||
break;
|
||||
case 'G':
|
||||
case 'g':
|
||||
mult = 1 << 30;
|
||||
break;
|
||||
case 'W':
|
||||
case 'w':
|
||||
mult = sizeof(int);
|
||||
break;
|
||||
}
|
||||
|
||||
if (mult != 0) {
|
||||
prevnum = num;
|
||||
num *= mult;
|
||||
/* Check for overflow. */
|
||||
if ((prevnum > 0) != (num > 0) || num / mult != prevnum)
|
||||
goto erange;
|
||||
expr++;
|
||||
}
|
||||
|
||||
switch (*expr) {
|
||||
case '\0':
|
||||
break;
|
||||
case '*': /* Backward compatible. */
|
||||
case 'X':
|
||||
case 'x':
|
||||
mult = (intmax_t)get_off_t(expr + 1);
|
||||
prevnum = num;
|
||||
num *= mult;
|
||||
if ((prevnum > 0) == (num > 0) && num / mult == prevnum)
|
||||
break;
|
||||
erange:
|
||||
errx(1, "%s: %s", oper, strerror(ERANGE));
|
||||
default:
|
||||
errx(1, "%s: illegal numeric value", oper);
|
||||
}
|
||||
return (num);
|
||||
}
|
||||
268
bin/dd/conv.c
268
bin/dd/conv.c
|
|
@ -1,268 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Keith Muller of the University of California, San Diego and Lance
|
||||
* Visser of Convex Computer Corporation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)conv.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "dd.h"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* def --
|
||||
* Copy input to output. Input is buffered until reaches obs, and then
|
||||
* output until less than obs remains. Only a single buffer is used.
|
||||
* Worst case buffer calculation is (ibs + obs - 1).
|
||||
*/
|
||||
void
|
||||
def(void)
|
||||
{
|
||||
u_char *inp;
|
||||
const u_char *t;
|
||||
size_t cnt;
|
||||
|
||||
if ((t = ctab) != NULL)
|
||||
for (inp = in.dbp - (cnt = in.dbrcnt); cnt--; ++inp)
|
||||
*inp = t[*inp];
|
||||
|
||||
/* Make the output buffer look right. */
|
||||
out.dbp = in.dbp;
|
||||
out.dbcnt = in.dbcnt;
|
||||
|
||||
if (in.dbcnt >= out.dbsz) {
|
||||
/* If the output buffer is full, write it. */
|
||||
dd_out(0);
|
||||
|
||||
/*
|
||||
* Ddout copies the leftover output to the beginning of
|
||||
* the buffer and resets the output buffer. Reset the
|
||||
* input buffer to match it.
|
||||
*/
|
||||
in.dbp = out.dbp;
|
||||
in.dbcnt = out.dbcnt;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
def_close(void)
|
||||
{
|
||||
/* Just update the count, everything is already in the buffer. */
|
||||
if (in.dbcnt)
|
||||
out.dbcnt = in.dbcnt;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy variable length newline terminated records with a max size cbsz
|
||||
* bytes to output. Records less than cbs are padded with spaces.
|
||||
*
|
||||
* max in buffer: MAX(ibs, cbsz)
|
||||
* max out buffer: obs + cbsz
|
||||
*/
|
||||
void
|
||||
block(void)
|
||||
{
|
||||
u_char *inp, *outp;
|
||||
const u_char *t;
|
||||
size_t cnt, maxlen;
|
||||
static int intrunc;
|
||||
int ch;
|
||||
|
||||
/*
|
||||
* Record truncation can cross block boundaries. If currently in a
|
||||
* truncation state, keep tossing characters until reach a newline.
|
||||
* Start at the beginning of the buffer, as the input buffer is always
|
||||
* left empty.
|
||||
*/
|
||||
if (intrunc) {
|
||||
for (inp = in.db, cnt = in.dbrcnt; cnt && *inp++ != '\n'; --cnt)
|
||||
;
|
||||
if (!cnt) {
|
||||
in.dbcnt = 0;
|
||||
in.dbp = in.db;
|
||||
return;
|
||||
}
|
||||
intrunc = 0;
|
||||
/* Adjust the input buffer numbers. */
|
||||
in.dbcnt = cnt - 1;
|
||||
in.dbp = inp + cnt - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy records (max cbsz size chunks) into the output buffer. The
|
||||
* translation is done as we copy into the output buffer.
|
||||
*/
|
||||
ch = 0;
|
||||
for (inp = in.dbp - in.dbcnt, outp = out.dbp; in.dbcnt;) {
|
||||
maxlen = MIN(cbsz, in.dbcnt);
|
||||
if ((t = ctab) != NULL)
|
||||
for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n';
|
||||
++cnt)
|
||||
*outp++ = t[ch];
|
||||
else
|
||||
for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n';
|
||||
++cnt)
|
||||
*outp++ = ch;
|
||||
/*
|
||||
* Check for short record without a newline. Reassemble the
|
||||
* input block.
|
||||
*/
|
||||
if (ch != '\n' && in.dbcnt < cbsz) {
|
||||
(void)memmove(in.db, in.dbp - in.dbcnt, in.dbcnt);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Adjust the input buffer numbers. */
|
||||
in.dbcnt -= cnt;
|
||||
if (ch == '\n')
|
||||
--in.dbcnt;
|
||||
|
||||
/* Pad short records with spaces. */
|
||||
if (cnt < cbsz)
|
||||
(void)memset(outp, ctab ? ctab[' '] : ' ', cbsz - cnt);
|
||||
else {
|
||||
/*
|
||||
* If the next character wouldn't have ended the
|
||||
* block, it's a truncation.
|
||||
*/
|
||||
if (!in.dbcnt || *inp != '\n')
|
||||
++st.trunc;
|
||||
|
||||
/* Toss characters to a newline. */
|
||||
for (; in.dbcnt && *inp++ != '\n'; --in.dbcnt)
|
||||
;
|
||||
if (!in.dbcnt)
|
||||
intrunc = 1;
|
||||
else
|
||||
--in.dbcnt;
|
||||
}
|
||||
|
||||
/* Adjust output buffer numbers. */
|
||||
out.dbp += cbsz;
|
||||
if ((out.dbcnt += cbsz) >= out.dbsz)
|
||||
dd_out(0);
|
||||
outp = out.dbp;
|
||||
}
|
||||
in.dbp = in.db + in.dbcnt;
|
||||
}
|
||||
|
||||
void
|
||||
block_close(void)
|
||||
{
|
||||
/*
|
||||
* Copy any remaining data into the output buffer and pad to a record.
|
||||
* Don't worry about truncation or translation, the input buffer is
|
||||
* always empty when truncating, and no characters have been added for
|
||||
* translation. The bottom line is that anything left in the input
|
||||
* buffer is a truncated record. Anything left in the output buffer
|
||||
* just wasn't big enough.
|
||||
*/
|
||||
if (in.dbcnt) {
|
||||
++st.trunc;
|
||||
(void)memmove(out.dbp, in.dbp - in.dbcnt, in.dbcnt);
|
||||
(void)memset(out.dbp + in.dbcnt, ctab ? ctab[' '] : ' ',
|
||||
cbsz - in.dbcnt);
|
||||
out.dbcnt += cbsz;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert fixed length (cbsz) records to variable length. Deletes any
|
||||
* trailing blanks and appends a newline.
|
||||
*
|
||||
* max in buffer: MAX(ibs, cbsz) + cbsz
|
||||
* max out buffer: obs + cbsz
|
||||
*/
|
||||
void
|
||||
unblock(void)
|
||||
{
|
||||
u_char *inp;
|
||||
const u_char *t;
|
||||
size_t cnt;
|
||||
|
||||
/* Translation and case conversion. */
|
||||
if ((t = ctab) != NULL)
|
||||
for (inp = in.dbp - (cnt = in.dbrcnt); cnt--; ++inp)
|
||||
*inp = t[*inp];
|
||||
/*
|
||||
* Copy records (max cbsz size chunks) into the output buffer. The
|
||||
* translation has to already be done or we might not recognize the
|
||||
* spaces.
|
||||
*/
|
||||
for (inp = in.db; in.dbcnt >= cbsz; inp += cbsz, in.dbcnt -= cbsz) {
|
||||
for (t = inp + cbsz - 1; t >= inp && *t == ' '; --t)
|
||||
;
|
||||
if (t >= inp) {
|
||||
cnt = t - inp + 1;
|
||||
(void)memmove(out.dbp, inp, cnt);
|
||||
out.dbp += cnt;
|
||||
out.dbcnt += cnt;
|
||||
}
|
||||
*out.dbp++ = '\n';
|
||||
if (++out.dbcnt >= out.dbsz)
|
||||
dd_out(0);
|
||||
}
|
||||
if (in.dbcnt)
|
||||
(void)memmove(in.db, in.dbp - in.dbcnt, in.dbcnt);
|
||||
in.dbp = in.db + in.dbcnt;
|
||||
}
|
||||
|
||||
void
|
||||
unblock_close(void)
|
||||
{
|
||||
u_char *t;
|
||||
size_t cnt;
|
||||
|
||||
if (in.dbcnt) {
|
||||
warnx("%s: short input record", in.name);
|
||||
for (t = in.db + in.dbcnt - 1; t >= in.db && *t == ' '; --t)
|
||||
;
|
||||
if (t >= in.db) {
|
||||
cnt = t - in.db + 1;
|
||||
(void)memmove(out.dbp, in.db, cnt);
|
||||
out.dbp += cnt;
|
||||
out.dbcnt += cnt;
|
||||
}
|
||||
++out.dbcnt;
|
||||
*out.dbp++ = '\n';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,284 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Keith Muller of the University of California, San Diego and Lance
|
||||
* Visser of Convex Computer Corporation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)conv_tab.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/*
|
||||
* There are currently six tables:
|
||||
*
|
||||
* ebcdic -> ascii 32V conv=oldascii
|
||||
* ascii -> ebcdic 32V conv=oldebcdic
|
||||
* ascii -> ibm ebcdic 32V conv=oldibm
|
||||
*
|
||||
* ebcdic -> ascii POSIX/S5 conv=ascii
|
||||
* ascii -> ebcdic POSIX/S5 conv=ebcdic
|
||||
* ascii -> ibm ebcdic POSIX/S5 conv=ibm
|
||||
*
|
||||
* Other tables are built from these if multiple conversions are being
|
||||
* done.
|
||||
*
|
||||
* Tables used for conversions to/from IBM and EBCDIC to support an extension
|
||||
* to POSIX P1003.2/D11. The tables referencing POSIX contain data extracted
|
||||
* from tables 4-3 and 4-4 in P1003.2/Draft 11. The historic tables were
|
||||
* constructed by running against a file with all possible byte values.
|
||||
*
|
||||
* More information can be obtained in "Correspondences of 8-Bit and Hollerith
|
||||
* Codes for Computer Environments-A USASI Tutorial", Communications of the
|
||||
* ACM, Volume 11, Number 11, November 1968, pp. 783-789.
|
||||
*/
|
||||
|
||||
u_char casetab[256];
|
||||
|
||||
/* EBCDIC to ASCII -- 32V compatible. */
|
||||
const u_char e2a_32V[] = {
|
||||
0000, 0001, 0002, 0003, 0234, 0011, 0206, 0177, /* 0000 */
|
||||
0227, 0215, 0216, 0013, 0014, 0015, 0016, 0017, /* 0010 */
|
||||
0020, 0021, 0022, 0023, 0235, 0205, 0010, 0207, /* 0020 */
|
||||
0030, 0031, 0222, 0217, 0034, 0035, 0036, 0037, /* 0030 */
|
||||
0200, 0201, 0202, 0203, 0204, 0012, 0027, 0033, /* 0040 */
|
||||
0210, 0211, 0212, 0213, 0214, 0005, 0006, 0007, /* 0050 */
|
||||
0220, 0221, 0026, 0223, 0224, 0225, 0226, 0004, /* 0060 */
|
||||
0230, 0231, 0232, 0233, 0024, 0025, 0236, 0032, /* 0070 */
|
||||
0040, 0240, 0241, 0242, 0243, 0244, 0245, 0246, /* 0100 */
|
||||
0247, 0250, 0133, 0056, 0074, 0050, 0053, 0041, /* 0110 */
|
||||
0046, 0251, 0252, 0253, 0254, 0255, 0256, 0257, /* 0120 */
|
||||
0260, 0261, 0135, 0044, 0052, 0051, 0073, 0136, /* 0130 */
|
||||
0055, 0057, 0262, 0263, 0264, 0265, 0266, 0267, /* 0140 */
|
||||
0270, 0271, 0174, 0054, 0045, 0137, 0076, 0077, /* 0150 */
|
||||
0272, 0273, 0274, 0275, 0276, 0277, 0300, 0301, /* 0160 */
|
||||
0302, 0140, 0072, 0043, 0100, 0047, 0075, 0042, /* 0170 */
|
||||
0303, 0141, 0142, 0143, 0144, 0145, 0146, 0147, /* 0200 */
|
||||
0150, 0151, 0304, 0305, 0306, 0307, 0310, 0311, /* 0210 */
|
||||
0312, 0152, 0153, 0154, 0155, 0156, 0157, 0160, /* 0220 */
|
||||
0161, 0162, 0313, 0314, 0315, 0316, 0317, 0320, /* 0230 */
|
||||
0321, 0176, 0163, 0164, 0165, 0166, 0167, 0170, /* 0240 */
|
||||
0171, 0172, 0322, 0323, 0324, 0325, 0326, 0327, /* 0250 */
|
||||
0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337, /* 0260 */
|
||||
0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347, /* 0270 */
|
||||
0173, 0101, 0102, 0103, 0104, 0105, 0106, 0107, /* 0300 */
|
||||
0110, 0111, 0350, 0351, 0352, 0353, 0354, 0355, /* 0310 */
|
||||
0175, 0112, 0113, 0114, 0115, 0116, 0117, 0120, /* 0320 */
|
||||
0121, 0122, 0356, 0357, 0360, 0361, 0362, 0363, /* 0330 */
|
||||
0134, 0237, 0123, 0124, 0125, 0126, 0127, 0130, /* 0340 */
|
||||
0131, 0132, 0364, 0365, 0366, 0367, 0370, 0371, /* 0350 */
|
||||
0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067, /* 0360 */
|
||||
0070, 0071, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
|
||||
};
|
||||
|
||||
/* ASCII to EBCDIC -- 32V compatible. */
|
||||
const u_char a2e_32V[] = {
|
||||
0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, /* 0000 */
|
||||
0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017, /* 0010 */
|
||||
0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, /* 0020 */
|
||||
0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037, /* 0030 */
|
||||
0100, 0117, 0177, 0173, 0133, 0154, 0120, 0175, /* 0040 */
|
||||
0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141, /* 0050 */
|
||||
0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, /* 0060 */
|
||||
0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157, /* 0070 */
|
||||
0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, /* 0100 */
|
||||
0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326, /* 0110 */
|
||||
0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, /* 0120 */
|
||||
0347, 0350, 0351, 0112, 0340, 0132, 0137, 0155, /* 0130 */
|
||||
0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, /* 0140 */
|
||||
0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226, /* 0150 */
|
||||
0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, /* 0160 */
|
||||
0247, 0250, 0251, 0300, 0152, 0320, 0241, 0007, /* 0170 */
|
||||
0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, /* 0200 */
|
||||
0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033, /* 0210 */
|
||||
0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, /* 0220 */
|
||||
0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341, /* 0230 */
|
||||
0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, /* 0240 */
|
||||
0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127, /* 0250 */
|
||||
0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, /* 0260 */
|
||||
0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165, /* 0270 */
|
||||
0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, /* 0300 */
|
||||
0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236, /* 0310 */
|
||||
0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257, /* 0320 */
|
||||
0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, /* 0330 */
|
||||
0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, /* 0340 */
|
||||
0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333, /* 0350 */
|
||||
0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, /* 0360 */
|
||||
0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
|
||||
};
|
||||
|
||||
/* ASCII to IBM EBCDIC -- 32V compatible. */
|
||||
const u_char a2ibm_32V[] = {
|
||||
0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, /* 0000 */
|
||||
0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017, /* 0010 */
|
||||
0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, /* 0020 */
|
||||
0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037, /* 0030 */
|
||||
0100, 0132, 0177, 0173, 0133, 0154, 0120, 0175, /* 0040 */
|
||||
0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141, /* 0050 */
|
||||
0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, /* 0060 */
|
||||
0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157, /* 0070 */
|
||||
0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, /* 0100 */
|
||||
0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326, /* 0110 */
|
||||
0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, /* 0120 */
|
||||
0347, 0350, 0351, 0255, 0340, 0275, 0137, 0155, /* 0130 */
|
||||
0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, /* 0140 */
|
||||
0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226, /* 0150 */
|
||||
0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, /* 0160 */
|
||||
0247, 0250, 0251, 0300, 0117, 0320, 0241, 0007, /* 0170 */
|
||||
0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, /* 0200 */
|
||||
0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033, /* 0210 */
|
||||
0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, /* 0220 */
|
||||
0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341, /* 0230 */
|
||||
0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, /* 0240 */
|
||||
0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127, /* 0250 */
|
||||
0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, /* 0260 */
|
||||
0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165, /* 0270 */
|
||||
0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, /* 0300 */
|
||||
0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236, /* 0310 */
|
||||
0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257, /* 0320 */
|
||||
0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, /* 0330 */
|
||||
0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, /* 0340 */
|
||||
0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333, /* 0350 */
|
||||
0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, /* 0360 */
|
||||
0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
|
||||
};
|
||||
|
||||
/* EBCDIC to ASCII -- POSIX and System V compatible. */
|
||||
const u_char e2a_POSIX[] = {
|
||||
0000, 0001, 0002, 0003, 0234, 0011, 0206, 0177, /* 0000 */
|
||||
0227, 0215, 0216, 0013, 0014, 0015, 0016, 0017, /* 0010 */
|
||||
0020, 0021, 0022, 0023, 0235, 0205, 0010, 0207, /* 0020 */
|
||||
0030, 0031, 0222, 0217, 0034, 0035, 0036, 0037, /* 0030 */
|
||||
0200, 0201, 0202, 0203, 0204, 0012, 0027, 0033, /* 0040 */
|
||||
0210, 0211, 0212, 0213, 0214, 0005, 0006, 0007, /* 0050 */
|
||||
0220, 0221, 0026, 0223, 0224, 0225, 0226, 0004, /* 0060 */
|
||||
0230, 0231, 0232, 0233, 0024, 0025, 0236, 0032, /* 0070 */
|
||||
0040, 0240, 0241, 0242, 0243, 0244, 0245, 0246, /* 0100 */
|
||||
0247, 0250, 0325, 0056, 0074, 0050, 0053, 0174, /* 0110 */
|
||||
0046, 0251, 0252, 0253, 0254, 0255, 0256, 0257, /* 0120 */
|
||||
0260, 0261, 0041, 0044, 0052, 0051, 0073, 0176, /* 0130 */
|
||||
0055, 0057, 0262, 0263, 0264, 0265, 0266, 0267, /* 0140 */
|
||||
0270, 0271, 0313, 0054, 0045, 0137, 0076, 0077, /* 0150 */
|
||||
0272, 0273, 0274, 0275, 0276, 0277, 0300, 0301, /* 0160 */
|
||||
0302, 0140, 0072, 0043, 0100, 0047, 0075, 0042, /* 0170 */
|
||||
0303, 0141, 0142, 0143, 0144, 0145, 0146, 0147, /* 0200 */
|
||||
0150, 0151, 0304, 0305, 0306, 0307, 0310, 0311, /* 0210 */
|
||||
0312, 0152, 0153, 0154, 0155, 0156, 0157, 0160, /* 0220 */
|
||||
0161, 0162, 0136, 0314, 0315, 0316, 0317, 0320, /* 0230 */
|
||||
0321, 0345, 0163, 0164, 0165, 0166, 0167, 0170, /* 0240 */
|
||||
0171, 0172, 0322, 0323, 0324, 0133, 0326, 0327, /* 0250 */
|
||||
0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337, /* 0260 */
|
||||
0340, 0341, 0342, 0343, 0344, 0135, 0346, 0347, /* 0270 */
|
||||
0173, 0101, 0102, 0103, 0104, 0105, 0106, 0107, /* 0300 */
|
||||
0110, 0111, 0350, 0351, 0352, 0353, 0354, 0355, /* 0310 */
|
||||
0175, 0112, 0113, 0114, 0115, 0116, 0117, 0120, /* 0320 */
|
||||
0121, 0122, 0356, 0357, 0360, 0361, 0362, 0363, /* 0330 */
|
||||
0134, 0237, 0123, 0124, 0125, 0126, 0127, 0130, /* 0340 */
|
||||
0131, 0132, 0364, 0365, 0366, 0367, 0370, 0371, /* 0350 */
|
||||
0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067, /* 0360 */
|
||||
0070, 0071, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
|
||||
};
|
||||
|
||||
/* ASCII to EBCDIC -- POSIX and System V compatible. */
|
||||
const u_char a2e_POSIX[] = {
|
||||
0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, /* 0000 */
|
||||
0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017, /* 0010 */
|
||||
0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, /* 0020 */
|
||||
0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037, /* 0030 */
|
||||
0100, 0132, 0177, 0173, 0133, 0154, 0120, 0175, /* 0040 */
|
||||
0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141, /* 0050 */
|
||||
0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, /* 0060 */
|
||||
0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157, /* 0070 */
|
||||
0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, /* 0100 */
|
||||
0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326, /* 0110 */
|
||||
0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, /* 0120 */
|
||||
0347, 0350, 0351, 0255, 0340, 0275, 0232, 0155, /* 0130 */
|
||||
0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, /* 0140 */
|
||||
0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226, /* 0150 */
|
||||
0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, /* 0160 */
|
||||
0247, 0250, 0251, 0300, 0117, 0320, 0137, 0007, /* 0170 */
|
||||
0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, /* 0200 */
|
||||
0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033, /* 0210 */
|
||||
0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, /* 0220 */
|
||||
0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341, /* 0230 */
|
||||
0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, /* 0240 */
|
||||
0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127, /* 0250 */
|
||||
0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, /* 0260 */
|
||||
0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165, /* 0270 */
|
||||
0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, /* 0300 */
|
||||
0216, 0217, 0220, 0152, 0233, 0234, 0235, 0236, /* 0310 */
|
||||
0237, 0240, 0252, 0253, 0254, 0112, 0256, 0257, /* 0320 */
|
||||
0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, /* 0330 */
|
||||
0270, 0271, 0272, 0273, 0274, 0241, 0276, 0277, /* 0340 */
|
||||
0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333, /* 0350 */
|
||||
0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, /* 0360 */
|
||||
0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
|
||||
};
|
||||
|
||||
/* ASCII to IBM EBCDIC -- POSIX and System V compatible. */
|
||||
const u_char a2ibm_POSIX[] = {
|
||||
0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057, /* 0000 */
|
||||
0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017, /* 0010 */
|
||||
0020, 0021, 0022, 0023, 0074, 0075, 0062, 0046, /* 0020 */
|
||||
0030, 0031, 0077, 0047, 0034, 0035, 0036, 0037, /* 0030 */
|
||||
0100, 0132, 0177, 0173, 0133, 0154, 0120, 0175, /* 0040 */
|
||||
0115, 0135, 0134, 0116, 0153, 0140, 0113, 0141, /* 0050 */
|
||||
0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, /* 0060 */
|
||||
0370, 0371, 0172, 0136, 0114, 0176, 0156, 0157, /* 0070 */
|
||||
0174, 0301, 0302, 0303, 0304, 0305, 0306, 0307, /* 0100 */
|
||||
0310, 0311, 0321, 0322, 0323, 0324, 0325, 0326, /* 0110 */
|
||||
0327, 0330, 0331, 0342, 0343, 0344, 0345, 0346, /* 0120 */
|
||||
0347, 0350, 0351, 0255, 0340, 0275, 0137, 0155, /* 0130 */
|
||||
0171, 0201, 0202, 0203, 0204, 0205, 0206, 0207, /* 0140 */
|
||||
0210, 0211, 0221, 0222, 0223, 0224, 0225, 0226, /* 0150 */
|
||||
0227, 0230, 0231, 0242, 0243, 0244, 0245, 0246, /* 0160 */
|
||||
0247, 0250, 0251, 0300, 0117, 0320, 0241, 0007, /* 0170 */
|
||||
0040, 0041, 0042, 0043, 0044, 0025, 0006, 0027, /* 0200 */
|
||||
0050, 0051, 0052, 0053, 0054, 0011, 0012, 0033, /* 0210 */
|
||||
0060, 0061, 0032, 0063, 0064, 0065, 0066, 0010, /* 0220 */
|
||||
0070, 0071, 0072, 0073, 0004, 0024, 0076, 0341, /* 0230 */
|
||||
0101, 0102, 0103, 0104, 0105, 0106, 0107, 0110, /* 0240 */
|
||||
0111, 0121, 0122, 0123, 0124, 0125, 0126, 0127, /* 0250 */
|
||||
0130, 0131, 0142, 0143, 0144, 0145, 0146, 0147, /* 0260 */
|
||||
0150, 0151, 0160, 0161, 0162, 0163, 0164, 0165, /* 0270 */
|
||||
0166, 0167, 0170, 0200, 0212, 0213, 0214, 0215, /* 0300 */
|
||||
0216, 0217, 0220, 0232, 0233, 0234, 0235, 0236, /* 0310 */
|
||||
0237, 0240, 0252, 0253, 0254, 0255, 0256, 0257, /* 0320 */
|
||||
0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, /* 0330 */
|
||||
0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, /* 0340 */
|
||||
0312, 0313, 0314, 0315, 0316, 0317, 0332, 0333, /* 0350 */
|
||||
0334, 0335, 0336, 0337, 0352, 0353, 0354, 0355, /* 0360 */
|
||||
0356, 0357, 0372, 0373, 0374, 0375, 0376, 0377, /* 0370 */
|
||||
};
|
||||
431
bin/dd/dd.1
431
bin/dd/dd.1
|
|
@ -1,431 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Keith Muller of the University of California, San Diego.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)dd.1 8.2 (Berkeley) 1/13/94
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd January 23, 2009
|
||||
.Dt DD 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm dd
|
||||
.Nd convert and copy a file
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Ar operands ...
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility copies the standard input to the standard output.
|
||||
Input data is read and written in 512-byte blocks.
|
||||
If input reads are short, input from multiple reads are aggregated
|
||||
to form the output block.
|
||||
When finished,
|
||||
.Nm
|
||||
displays the number of complete and partial input and output blocks
|
||||
and truncated input records to the standard error output.
|
||||
.Pp
|
||||
The following operands are available:
|
||||
.Bl -tag -width ".Cm of Ns = Ns Ar file"
|
||||
.It Cm bs Ns = Ns Ar n
|
||||
Set both input and output block size to
|
||||
.Ar n
|
||||
bytes, superseding the
|
||||
.Cm ibs
|
||||
and
|
||||
.Cm obs
|
||||
operands.
|
||||
If no conversion values other than
|
||||
.Cm noerror ,
|
||||
.Cm notrunc
|
||||
or
|
||||
.Cm sync
|
||||
are specified, then each input block is copied to the output as a
|
||||
single block without any aggregation of short blocks.
|
||||
.It Cm cbs Ns = Ns Ar n
|
||||
Set the conversion record size to
|
||||
.Ar n
|
||||
bytes.
|
||||
The conversion record size is required by the record oriented conversion
|
||||
values.
|
||||
.It Cm count Ns = Ns Ar n
|
||||
Copy only
|
||||
.Ar n
|
||||
input blocks.
|
||||
.It Cm files Ns = Ns Ar n
|
||||
Copy
|
||||
.Ar n
|
||||
input files before terminating.
|
||||
This operand is only applicable when the input device is a tape.
|
||||
.It Cm fillchar Ns = Ns Ar c
|
||||
When padding a block in conversion mode or due to use of
|
||||
.Cm noerror
|
||||
and
|
||||
.Cm sync
|
||||
modes, fill with the specified
|
||||
.Tn ASCII
|
||||
character, rather than using a space or
|
||||
.Dv NUL .
|
||||
.It Cm ibs Ns = Ns Ar n
|
||||
Set the input block size to
|
||||
.Ar n
|
||||
bytes instead of the default 512.
|
||||
.It Cm if Ns = Ns Ar file
|
||||
Read input from
|
||||
.Ar file
|
||||
instead of the standard input.
|
||||
.It Cm iseek Ns = Ns Ar n
|
||||
Seek on the input file
|
||||
.Ar n
|
||||
blocks.
|
||||
This is synonymous with
|
||||
.Cm skip Ns = Ns Ar n .
|
||||
.It Cm obs Ns = Ns Ar n
|
||||
Set the output block size to
|
||||
.Ar n
|
||||
bytes instead of the default 512.
|
||||
.It Cm of Ns = Ns Ar file
|
||||
Write output to
|
||||
.Ar file
|
||||
instead of the standard output.
|
||||
Any regular output file is truncated unless the
|
||||
.Cm notrunc
|
||||
conversion value is specified.
|
||||
If an initial portion of the output file is seeked past (see the
|
||||
.Cm oseek
|
||||
operand),
|
||||
the output file is truncated at that point.
|
||||
.It Cm oseek Ns = Ns Ar n
|
||||
Seek on the output file
|
||||
.Ar n
|
||||
blocks.
|
||||
This is synonymous with
|
||||
.Cm seek Ns = Ns Ar n .
|
||||
.It Cm seek Ns = Ns Ar n
|
||||
Seek
|
||||
.Ar n
|
||||
blocks from the beginning of the output before copying.
|
||||
On non-tape devices, an
|
||||
.Xr lseek 2
|
||||
operation is used.
|
||||
Otherwise, existing blocks are read and the data discarded.
|
||||
If the user does not have read permission for the tape, it is positioned
|
||||
using the tape
|
||||
.Xr ioctl 2
|
||||
function calls.
|
||||
If the seek operation is past the end of file, space from the current
|
||||
end of file to the specified offset is filled with blocks of
|
||||
.Dv NUL
|
||||
bytes.
|
||||
.It Cm skip Ns = Ns Ar n
|
||||
Skip
|
||||
.Ar n
|
||||
blocks from the beginning of the input before copying.
|
||||
On input which supports seeks, an
|
||||
.Xr lseek 2
|
||||
operation is used.
|
||||
Otherwise, input data is read and discarded.
|
||||
For pipes, the correct number of bytes is read.
|
||||
For all other devices, the correct number of blocks is read without
|
||||
distinguishing between a partial or complete block being read.
|
||||
.It Cm conv Ns = Ns Ar value Ns Op , Ns Ar value ...
|
||||
Where
|
||||
.Cm value
|
||||
is one of the symbols from the following list.
|
||||
.Bl -tag -width ".Cm unblock"
|
||||
.It Cm ascii , oldascii
|
||||
The same as the
|
||||
.Cm unblock
|
||||
value except that characters are translated from
|
||||
.Tn EBCDIC
|
||||
to
|
||||
.Tn ASCII
|
||||
before the
|
||||
records are converted.
|
||||
(These values imply
|
||||
.Cm unblock
|
||||
if the operand
|
||||
.Cm cbs
|
||||
is also specified.)
|
||||
There are two conversion maps for
|
||||
.Tn ASCII .
|
||||
The value
|
||||
.Cm ascii
|
||||
specifies the recommended one which is compatible with
|
||||
.At V .
|
||||
The value
|
||||
.Cm oldascii
|
||||
specifies the one used in historic
|
||||
.At
|
||||
and
|
||||
.No pre- Ns Bx 4.3 reno
|
||||
systems.
|
||||
.It Cm block
|
||||
Treats the input as a sequence of newline or end-of-file terminated variable
|
||||
length records independent of input and output block boundaries.
|
||||
Any trailing newline character is discarded.
|
||||
Each input record is converted to a fixed length output record where the
|
||||
length is specified by the
|
||||
.Cm cbs
|
||||
operand.
|
||||
Input records shorter than the conversion record size are padded with spaces.
|
||||
Input records longer than the conversion record size are truncated.
|
||||
The number of truncated input records, if any, are reported to the standard
|
||||
error output at the completion of the copy.
|
||||
.It Cm ebcdic , ibm , oldebcdic , oldibm
|
||||
The same as the
|
||||
.Cm block
|
||||
value except that characters are translated from
|
||||
.Tn ASCII
|
||||
to
|
||||
.Tn EBCDIC
|
||||
after the
|
||||
records are converted.
|
||||
(These values imply
|
||||
.Cm block
|
||||
if the operand
|
||||
.Cm cbs
|
||||
is also specified.)
|
||||
There are four conversion maps for
|
||||
.Tn EBCDIC .
|
||||
The value
|
||||
.Cm ebcdic
|
||||
specifies the recommended one which is compatible with
|
||||
.At V .
|
||||
The value
|
||||
.Cm ibm
|
||||
is a slightly different mapping, which is compatible with the
|
||||
.At V
|
||||
.Cm ibm
|
||||
value.
|
||||
The values
|
||||
.Cm oldebcdic
|
||||
and
|
||||
.Cm oldibm
|
||||
are maps used in historic
|
||||
.At
|
||||
and
|
||||
.No pre- Ns Bx 4.3 reno
|
||||
systems.
|
||||
.It Cm lcase
|
||||
Transform uppercase characters into lowercase characters.
|
||||
.It Cm pareven , parnone , parodd , parset
|
||||
Output data with the specified parity.
|
||||
The parity bit on input is stripped unless
|
||||
.Tn EBCDIC
|
||||
to
|
||||
.Tn ASCII
|
||||
conversions is also specified.
|
||||
.It Cm noerror
|
||||
Do not stop processing on an input error.
|
||||
When an input error occurs, a diagnostic message followed by the current
|
||||
input and output block counts will be written to the standard error output
|
||||
in the same format as the standard completion message.
|
||||
If the
|
||||
.Cm sync
|
||||
conversion is also specified, any missing input data will be replaced
|
||||
with
|
||||
.Dv NUL
|
||||
bytes (or with spaces if a block oriented conversion value was
|
||||
specified) and processed as a normal input buffer.
|
||||
If the
|
||||
.Cm fillchar
|
||||
option is specified, the fill character provided on the command line
|
||||
will override
|
||||
the automatic selection of the fill character.
|
||||
If the
|
||||
.Cm sync
|
||||
conversion is not specified, the input block is omitted from the output.
|
||||
On input files which are not tapes or pipes, the file offset
|
||||
will be positioned past the block in which the error occurred using
|
||||
.Xr lseek 2 .
|
||||
.It Cm notrunc
|
||||
Do not truncate the output file.
|
||||
This will preserve any blocks in the output file not explicitly written
|
||||
by
|
||||
.Nm .
|
||||
The
|
||||
.Cm notrunc
|
||||
value is not supported for tapes.
|
||||
.It Cm osync
|
||||
Pad the final output block to the full output block size.
|
||||
If the input file is not a multiple of the output block size
|
||||
after conversion, this conversion forces the final output block
|
||||
to be the same size as preceding blocks for use on devices that require
|
||||
regularly sized blocks to be written.
|
||||
This option is incompatible with use of the
|
||||
.Cm bs Ns = Ns Ar n
|
||||
block size specification.
|
||||
.It Cm sparse
|
||||
If one or more output blocks would consist solely of
|
||||
.Dv NUL
|
||||
bytes, try to seek the output file by the required space instead of
|
||||
filling them with
|
||||
.Dv NUL Ns s ,
|
||||
resulting in a sparse file.
|
||||
.It Cm swab
|
||||
Swap every pair of input bytes.
|
||||
If an input buffer has an odd number of bytes, the last byte will be
|
||||
ignored during swapping.
|
||||
.It Cm sync
|
||||
Pad every input block to the input buffer size.
|
||||
Spaces are used for pad bytes if a block oriented conversion value is
|
||||
specified, otherwise
|
||||
.Dv NUL
|
||||
bytes are used.
|
||||
.It Cm ucase
|
||||
Transform lowercase characters into uppercase characters.
|
||||
.It Cm unblock
|
||||
Treats the input as a sequence of fixed length records independent of input
|
||||
and output block boundaries.
|
||||
The length of the input records is specified by the
|
||||
.Cm cbs
|
||||
operand.
|
||||
Any trailing space characters are discarded and a newline character is
|
||||
appended.
|
||||
.El
|
||||
.El
|
||||
.Pp
|
||||
Where sizes are specified, a decimal, octal, or hexadecimal number of
|
||||
bytes is expected.
|
||||
If the number ends with a
|
||||
.Dq Li b ,
|
||||
.Dq Li k ,
|
||||
.Dq Li m ,
|
||||
.Dq Li g ,
|
||||
or
|
||||
.Dq Li w ,
|
||||
the
|
||||
number is multiplied by 512, 1024 (1K), 1048576 (1M), 1073741824 (1G)
|
||||
or the number of bytes in an integer, respectively.
|
||||
Two or more numbers may be separated by an
|
||||
.Dq Li x
|
||||
to indicate a product.
|
||||
.Pp
|
||||
When finished,
|
||||
.Nm
|
||||
displays the number of complete and partial input and output blocks,
|
||||
truncated input records and odd-length byte-swapping blocks to the
|
||||
standard error output.
|
||||
A partial input block is one where less than the input block size
|
||||
was read.
|
||||
A partial output block is one where less than the output block size
|
||||
was written.
|
||||
Partial output blocks to tape devices are considered fatal errors.
|
||||
Otherwise, the rest of the block will be written.
|
||||
Partial output blocks to character devices will produce a warning message.
|
||||
A truncated input block is one where a variable length record oriented
|
||||
conversion value was specified and the input line was too long to
|
||||
fit in the conversion record or was not newline terminated.
|
||||
.Pp
|
||||
Normally, data resulting from input or conversion or both are aggregated
|
||||
into output blocks of the specified size.
|
||||
After the end of input is reached, any remaining output is written as
|
||||
a block.
|
||||
This means that the final output block may be shorter than the output
|
||||
block size.
|
||||
.Pp
|
||||
If
|
||||
.Nm
|
||||
receives a
|
||||
.Dv SIGINFO
|
||||
(see the
|
||||
.Cm status
|
||||
argument for
|
||||
.Xr stty 1 )
|
||||
signal, the current input and output block counts will
|
||||
be written to the standard error output
|
||||
in the same format as the standard completion message.
|
||||
If
|
||||
.Nm
|
||||
receives a
|
||||
.Dv SIGINT
|
||||
signal, the current input and output block counts will
|
||||
be written to the standard error output
|
||||
in the same format as the standard completion message and
|
||||
.Nm
|
||||
will exit.
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std
|
||||
.Sh EXAMPLES
|
||||
Check that a disk drive contains no bad blocks:
|
||||
.Pp
|
||||
.Dl "dd if=/dev/ad0 of=/dev/null bs=1m"
|
||||
.Pp
|
||||
Do a refresh of a disk drive, in order to prevent presently
|
||||
recoverable read errors from progressing into unrecoverable read errors:
|
||||
.Pp
|
||||
.Dl "dd if=/dev/ad0 of=/dev/ad0 bs=1m"
|
||||
.Pp
|
||||
Remove parity bit from a file:
|
||||
.Pp
|
||||
.Dl "dd if=file conv=parnone of=file.txt"
|
||||
.Pp
|
||||
Check for (even) parity errors on a file:
|
||||
.Pp
|
||||
.Dl "dd if=file conv=pareven | cmp -x - file"
|
||||
.Pp
|
||||
To create an image of a Mode-1 CD-ROM, which is a commonly used format
|
||||
for data CD-ROM disks, use a block size of 2048 bytes:
|
||||
.Pp
|
||||
.Dl "dd if=/dev/acd0 of=filename.iso bs=2048"
|
||||
.Sh SEE ALSO
|
||||
.Xr cp 1 ,
|
||||
.Xr mt 1 ,
|
||||
.Xr tr 1 ,
|
||||
.Xr geom 4
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility is expected to be a superset of the
|
||||
.St -p1003.2
|
||||
standard.
|
||||
The
|
||||
.Cm files
|
||||
operand and the
|
||||
.Cm ascii ,
|
||||
.Cm ebcdic ,
|
||||
.Cm ibm ,
|
||||
.Cm oldascii ,
|
||||
.Cm oldebcdic
|
||||
and
|
||||
.Cm oldibm
|
||||
values are extensions to the
|
||||
.Tn POSIX
|
||||
standard.
|
||||
.Sh BUGS
|
||||
Protection mechanisms in the
|
||||
.Xr geom 4
|
||||
subsystem might prevent the super-user from writing blocks to a disk.
|
||||
Instructions for temporarily disabling these protection mechanisms can be
|
||||
found in the
|
||||
.Xr geom 4
|
||||
manpage.
|
||||
494
bin/dd/dd.c
494
bin/dd/dd.c
|
|
@ -1,494 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Keith Muller of the University of California, San Diego and Lance
|
||||
* Visser of Convex Computer Corporation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char const copyright[] =
|
||||
"@(#) Copyright (c) 1991, 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)dd.c 8.5 (Berkeley) 4/2/94";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/filio.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "dd.h"
|
||||
#include "extern.h"
|
||||
|
||||
static void dd_close(void);
|
||||
static void dd_in(void);
|
||||
static void getfdtype(IO *);
|
||||
static void setup(void);
|
||||
|
||||
IO in, out; /* input/output state */
|
||||
STAT st; /* statistics */
|
||||
void (*cfunc)(void); /* conversion function */
|
||||
uintmax_t cpy_cnt; /* # of blocks to copy */
|
||||
static off_t pending = 0; /* pending seek if sparse */
|
||||
u_int ddflags = 0; /* conversion options */
|
||||
size_t cbsz; /* conversion block size */
|
||||
uintmax_t files_cnt = 1; /* # of files to copy */
|
||||
const u_char *ctab; /* conversion table */
|
||||
char fill_char; /* Character to fill with if defined */
|
||||
|
||||
int
|
||||
main(int argc __unused, char *argv[])
|
||||
{
|
||||
(void)setlocale(LC_CTYPE, "");
|
||||
jcl(argv);
|
||||
setup();
|
||||
|
||||
(void)signal(SIGINFO, summaryx);
|
||||
(void)signal(SIGINT, terminate);
|
||||
|
||||
atexit(summary);
|
||||
|
||||
while (files_cnt--)
|
||||
dd_in();
|
||||
|
||||
dd_close();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int
|
||||
parity(u_char c)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = c ^ (c >> 1) ^ (c >> 2) ^ (c >> 3) ^
|
||||
(c >> 4) ^ (c >> 5) ^ (c >> 6) ^ (c >> 7);
|
||||
return (i & 1);
|
||||
}
|
||||
|
||||
static void
|
||||
setup(void)
|
||||
{
|
||||
u_int cnt;
|
||||
struct timeval tv;
|
||||
|
||||
if (in.name == NULL) {
|
||||
in.name = "stdin";
|
||||
in.fd = STDIN_FILENO;
|
||||
} else {
|
||||
in.fd = open(in.name, O_RDONLY, 0);
|
||||
if (in.fd == -1)
|
||||
err(1, "%s", in.name);
|
||||
}
|
||||
|
||||
getfdtype(&in);
|
||||
|
||||
if (files_cnt > 1 && !(in.flags & ISTAPE))
|
||||
errx(1, "files is not supported for non-tape devices");
|
||||
|
||||
if (out.name == NULL) {
|
||||
/* No way to check for read access here. */
|
||||
out.fd = STDOUT_FILENO;
|
||||
out.name = "stdout";
|
||||
} else {
|
||||
#define OFLAGS \
|
||||
(O_CREAT | (ddflags & (C_SEEK | C_NOTRUNC) ? 0 : O_TRUNC))
|
||||
out.fd = open(out.name, O_RDWR | OFLAGS, DEFFILEMODE);
|
||||
/*
|
||||
* May not have read access, so try again with write only.
|
||||
* Without read we may have a problem if output also does
|
||||
* not support seeks.
|
||||
*/
|
||||
if (out.fd == -1) {
|
||||
out.fd = open(out.name, O_WRONLY | OFLAGS, DEFFILEMODE);
|
||||
out.flags |= NOREAD;
|
||||
}
|
||||
if (out.fd == -1)
|
||||
err(1, "%s", out.name);
|
||||
}
|
||||
|
||||
getfdtype(&out);
|
||||
|
||||
/*
|
||||
* Allocate space for the input and output buffers. If not doing
|
||||
* record oriented I/O, only need a single buffer.
|
||||
*/
|
||||
if (!(ddflags & (C_BLOCK | C_UNBLOCK))) {
|
||||
if ((in.db = malloc(out.dbsz + in.dbsz - 1)) == NULL)
|
||||
err(1, "input buffer");
|
||||
out.db = in.db;
|
||||
} else if ((in.db = malloc(MAX(in.dbsz, cbsz) + cbsz)) == NULL ||
|
||||
(out.db = malloc(out.dbsz + cbsz)) == NULL)
|
||||
err(1, "output buffer");
|
||||
in.dbp = in.db;
|
||||
out.dbp = out.db;
|
||||
|
||||
/* Position the input/output streams. */
|
||||
if (in.offset)
|
||||
pos_in();
|
||||
if (out.offset)
|
||||
pos_out();
|
||||
|
||||
/*
|
||||
* Truncate the output file. If it fails on a type of output file
|
||||
* that it should _not_ fail on, error out.
|
||||
*/
|
||||
if ((ddflags & (C_OF | C_SEEK | C_NOTRUNC)) == (C_OF | C_SEEK) &&
|
||||
out.flags & ISTRUNC)
|
||||
if (ftruncate(out.fd, out.offset * out.dbsz) == -1)
|
||||
err(1, "truncating %s", out.name);
|
||||
|
||||
if (ddflags & (C_LCASE | C_UCASE | C_ASCII | C_EBCDIC | C_PARITY)) {
|
||||
if (ctab != NULL) {
|
||||
for (cnt = 0; cnt <= 0377; ++cnt)
|
||||
casetab[cnt] = ctab[cnt];
|
||||
} else {
|
||||
for (cnt = 0; cnt <= 0377; ++cnt)
|
||||
casetab[cnt] = cnt;
|
||||
}
|
||||
if ((ddflags & C_PARITY) && !(ddflags & C_ASCII)) {
|
||||
/*
|
||||
* If the input is not EBCDIC, and we do parity
|
||||
* processing, strip input parity.
|
||||
*/
|
||||
for (cnt = 200; cnt <= 0377; ++cnt)
|
||||
casetab[cnt] = casetab[cnt & 0x7f];
|
||||
}
|
||||
if (ddflags & C_LCASE) {
|
||||
for (cnt = 0; cnt <= 0377; ++cnt)
|
||||
casetab[cnt] = tolower(casetab[cnt]);
|
||||
} else if (ddflags & C_UCASE) {
|
||||
for (cnt = 0; cnt <= 0377; ++cnt)
|
||||
casetab[cnt] = toupper(casetab[cnt]);
|
||||
}
|
||||
if ((ddflags & C_PARITY)) {
|
||||
/*
|
||||
* This should strictly speaking be a no-op, but I
|
||||
* wonder what funny LANG settings could get us.
|
||||
*/
|
||||
for (cnt = 0; cnt <= 0377; ++cnt)
|
||||
casetab[cnt] = casetab[cnt] & 0x7f;
|
||||
}
|
||||
if ((ddflags & C_PARSET)) {
|
||||
for (cnt = 0; cnt <= 0377; ++cnt)
|
||||
casetab[cnt] = casetab[cnt] | 0x80;
|
||||
}
|
||||
if ((ddflags & C_PAREVEN)) {
|
||||
for (cnt = 0; cnt <= 0377; ++cnt)
|
||||
if (parity(casetab[cnt]))
|
||||
casetab[cnt] = casetab[cnt] | 0x80;
|
||||
}
|
||||
if ((ddflags & C_PARODD)) {
|
||||
for (cnt = 0; cnt <= 0377; ++cnt)
|
||||
if (!parity(casetab[cnt]))
|
||||
casetab[cnt] = casetab[cnt] | 0x80;
|
||||
}
|
||||
|
||||
ctab = casetab;
|
||||
}
|
||||
|
||||
(void)gettimeofday(&tv, (struct timezone *)NULL);
|
||||
st.start = tv.tv_sec + tv.tv_usec * 1e-6;
|
||||
}
|
||||
|
||||
static void
|
||||
getfdtype(IO *io)
|
||||
{
|
||||
struct stat sb;
|
||||
int type;
|
||||
|
||||
if (fstat(io->fd, &sb) == -1)
|
||||
err(1, "%s", io->name);
|
||||
if (S_ISREG(sb.st_mode))
|
||||
io->flags |= ISTRUNC;
|
||||
if (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) {
|
||||
if (ioctl(io->fd, FIODTYPE, &type) == -1) {
|
||||
err(1, "%s", io->name);
|
||||
} else {
|
||||
if (type & D_TAPE)
|
||||
io->flags |= ISTAPE;
|
||||
else if (type & (D_DISK | D_MEM))
|
||||
io->flags |= ISSEEK;
|
||||
if (S_ISCHR(sb.st_mode) && (type & D_TAPE) == 0)
|
||||
io->flags |= ISCHR;
|
||||
}
|
||||
return;
|
||||
}
|
||||
errno = 0;
|
||||
if (lseek(io->fd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE)
|
||||
io->flags |= ISPIPE;
|
||||
else
|
||||
io->flags |= ISSEEK;
|
||||
}
|
||||
|
||||
static void
|
||||
dd_in(void)
|
||||
{
|
||||
ssize_t n;
|
||||
|
||||
for (;;) {
|
||||
switch (cpy_cnt) {
|
||||
case -1: /* count=0 was specified */
|
||||
return;
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
if (st.in_full + st.in_part >= (uintmax_t)cpy_cnt)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Zero the buffer first if sync; if doing block operations,
|
||||
* use spaces.
|
||||
*/
|
||||
if (ddflags & C_SYNC) {
|
||||
if (ddflags & C_FILL)
|
||||
memset(in.dbp, fill_char, in.dbsz);
|
||||
else if (ddflags & (C_BLOCK | C_UNBLOCK))
|
||||
memset(in.dbp, ' ', in.dbsz);
|
||||
else
|
||||
memset(in.dbp, 0, in.dbsz);
|
||||
}
|
||||
|
||||
n = read(in.fd, in.dbp, in.dbsz);
|
||||
if (n == 0) {
|
||||
in.dbrcnt = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Read error. */
|
||||
if (n == -1) {
|
||||
/*
|
||||
* If noerror not specified, die. POSIX requires that
|
||||
* the warning message be followed by an I/O display.
|
||||
*/
|
||||
if (!(ddflags & C_NOERROR))
|
||||
err(1, "%s", in.name);
|
||||
warn("%s", in.name);
|
||||
summary();
|
||||
|
||||
/*
|
||||
* If it's a seekable file descriptor, seek past the
|
||||
* error. If your OS doesn't do the right thing for
|
||||
* raw disks this section should be modified to re-read
|
||||
* in sector size chunks.
|
||||
*/
|
||||
if (in.flags & ISSEEK &&
|
||||
lseek(in.fd, (off_t)in.dbsz, SEEK_CUR))
|
||||
warn("%s", in.name);
|
||||
|
||||
/* If sync not specified, omit block and continue. */
|
||||
if (!(ddflags & C_SYNC))
|
||||
continue;
|
||||
|
||||
/* Read errors count as full blocks. */
|
||||
in.dbcnt += in.dbrcnt = in.dbsz;
|
||||
++st.in_full;
|
||||
|
||||
/* Handle full input blocks. */
|
||||
} else if ((size_t)n == in.dbsz) {
|
||||
in.dbcnt += in.dbrcnt = n;
|
||||
++st.in_full;
|
||||
|
||||
/* Handle partial input blocks. */
|
||||
} else {
|
||||
/* If sync, use the entire block. */
|
||||
if (ddflags & C_SYNC)
|
||||
in.dbcnt += in.dbrcnt = in.dbsz;
|
||||
else
|
||||
in.dbcnt += in.dbrcnt = n;
|
||||
++st.in_part;
|
||||
}
|
||||
|
||||
/*
|
||||
* POSIX states that if bs is set and no other conversions
|
||||
* than noerror, notrunc or sync are specified, the block
|
||||
* is output without buffering as it is read.
|
||||
*/
|
||||
if (ddflags & C_BS) {
|
||||
out.dbcnt = in.dbcnt;
|
||||
dd_out(1);
|
||||
in.dbcnt = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ddflags & C_SWAB) {
|
||||
if ((n = in.dbrcnt) & 1) {
|
||||
++st.swab;
|
||||
--n;
|
||||
}
|
||||
swab(in.dbp, in.dbp, (size_t)n);
|
||||
}
|
||||
|
||||
in.dbp += in.dbrcnt;
|
||||
(*cfunc)();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Clean up any remaining I/O and flush output. If necessary, the output file
|
||||
* is truncated.
|
||||
*/
|
||||
static void
|
||||
dd_close(void)
|
||||
{
|
||||
if (cfunc == def)
|
||||
def_close();
|
||||
else if (cfunc == block)
|
||||
block_close();
|
||||
else if (cfunc == unblock)
|
||||
unblock_close();
|
||||
if (ddflags & C_OSYNC && out.dbcnt && out.dbcnt < out.dbsz) {
|
||||
if (ddflags & C_FILL)
|
||||
memset(out.dbp, fill_char, out.dbsz - out.dbcnt);
|
||||
else if (ddflags & (C_BLOCK | C_UNBLOCK))
|
||||
memset(out.dbp, ' ', out.dbsz - out.dbcnt);
|
||||
else
|
||||
memset(out.dbp, 0, out.dbsz - out.dbcnt);
|
||||
out.dbcnt = out.dbsz;
|
||||
}
|
||||
if (out.dbcnt || pending)
|
||||
dd_out(1);
|
||||
}
|
||||
|
||||
void
|
||||
dd_out(int force)
|
||||
{
|
||||
u_char *outp;
|
||||
size_t cnt, i, n;
|
||||
ssize_t nw;
|
||||
static int warned;
|
||||
int sparse;
|
||||
|
||||
/*
|
||||
* Write one or more blocks out. The common case is writing a full
|
||||
* output block in a single write; increment the full block stats.
|
||||
* Otherwise, we're into partial block writes. If a partial write,
|
||||
* and it's a character device, just warn. If a tape device, quit.
|
||||
*
|
||||
* The partial writes represent two cases. 1: Where the input block
|
||||
* was less than expected so the output block was less than expected.
|
||||
* 2: Where the input block was the right size but we were forced to
|
||||
* write the block in multiple chunks. The original versions of dd(1)
|
||||
* never wrote a block in more than a single write, so the latter case
|
||||
* never happened.
|
||||
*
|
||||
* One special case is if we're forced to do the write -- in that case
|
||||
* we play games with the buffer size, and it's usually a partial write.
|
||||
*/
|
||||
outp = out.db;
|
||||
for (n = force ? out.dbcnt : out.dbsz;; n = out.dbsz) {
|
||||
for (cnt = n;; cnt -= nw) {
|
||||
sparse = 0;
|
||||
if (ddflags & C_SPARSE) {
|
||||
sparse = 1; /* Is buffer sparse? */
|
||||
for (i = 0; i < cnt; i++)
|
||||
if (outp[i] != 0) {
|
||||
sparse = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (sparse && !force) {
|
||||
pending += cnt;
|
||||
nw = cnt;
|
||||
} else {
|
||||
if (pending != 0) {
|
||||
if (force)
|
||||
pending--;
|
||||
if (lseek(out.fd, pending, SEEK_CUR) ==
|
||||
-1)
|
||||
err(2, "%s: seek error creating sparse file",
|
||||
out.name);
|
||||
if (force)
|
||||
write(out.fd, outp, 1);
|
||||
pending = 0;
|
||||
}
|
||||
if (cnt)
|
||||
nw = write(out.fd, outp, cnt);
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
if (nw <= 0) {
|
||||
if (nw == 0)
|
||||
errx(1, "%s: end of device", out.name);
|
||||
if (errno != EINTR)
|
||||
err(1, "%s", out.name);
|
||||
nw = 0;
|
||||
}
|
||||
outp += nw;
|
||||
st.bytes += nw;
|
||||
if ((size_t)nw == n) {
|
||||
if (n != out.dbsz)
|
||||
++st.out_part;
|
||||
else
|
||||
++st.out_full;
|
||||
break;
|
||||
}
|
||||
++st.out_part;
|
||||
if ((size_t)nw == cnt)
|
||||
break;
|
||||
if (out.flags & ISTAPE)
|
||||
errx(1, "%s: short write on tape device",
|
||||
out.name);
|
||||
if (out.flags & ISCHR && !warned) {
|
||||
warned = 1;
|
||||
warnx("%s: short write on character device",
|
||||
out.name);
|
||||
}
|
||||
}
|
||||
if ((out.dbcnt -= n) < out.dbsz)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Reassemble the output block. */
|
||||
if (out.dbcnt)
|
||||
(void)memmove(out.db, out.dbp - out.dbcnt, out.dbcnt);
|
||||
out.dbp = out.db + out.dbcnt;
|
||||
}
|
||||
99
bin/dd/dd.h
99
bin/dd/dd.h
|
|
@ -1,99 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Keith Muller of the University of California, San Diego and Lance
|
||||
* Visser of Convex Computer Corporation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)dd.h 8.3 (Berkeley) 4/2/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/* Input/output stream state. */
|
||||
typedef struct {
|
||||
u_char *db; /* buffer address */
|
||||
u_char *dbp; /* current buffer I/O address */
|
||||
/* XXX ssize_t? */
|
||||
size_t dbcnt; /* current buffer byte count */
|
||||
size_t dbrcnt; /* last read byte count */
|
||||
size_t dbsz; /* buffer size */
|
||||
|
||||
#define ISCHR 0x01 /* character device (warn on short) */
|
||||
#define ISPIPE 0x02 /* pipe-like (see position.c) */
|
||||
#define ISTAPE 0x04 /* tape */
|
||||
#define ISSEEK 0x08 /* valid to seek on */
|
||||
#define NOREAD 0x10 /* not readable */
|
||||
#define ISTRUNC 0x20 /* valid to ftruncate() */
|
||||
u_int flags;
|
||||
|
||||
const char *name; /* name */
|
||||
int fd; /* file descriptor */
|
||||
off_t offset; /* # of blocks to skip */
|
||||
} IO;
|
||||
|
||||
typedef struct {
|
||||
uintmax_t in_full; /* # of full input blocks */
|
||||
uintmax_t in_part; /* # of partial input blocks */
|
||||
uintmax_t out_full; /* # of full output blocks */
|
||||
uintmax_t out_part; /* # of partial output blocks */
|
||||
uintmax_t trunc; /* # of truncated records */
|
||||
uintmax_t swab; /* # of odd-length swab blocks */
|
||||
uintmax_t bytes; /* # of bytes written */
|
||||
double start; /* start time of dd */
|
||||
} STAT;
|
||||
|
||||
/* Flags (in ddflags). */
|
||||
#define C_ASCII 0x00001
|
||||
#define C_BLOCK 0x00002
|
||||
#define C_BS 0x00004
|
||||
#define C_CBS 0x00008
|
||||
#define C_COUNT 0x00010
|
||||
#define C_EBCDIC 0x00020
|
||||
#define C_FILES 0x00040
|
||||
#define C_IBS 0x00080
|
||||
#define C_IF 0x00100
|
||||
#define C_LCASE 0x00200
|
||||
#define C_NOERROR 0x00400
|
||||
#define C_NOTRUNC 0x00800
|
||||
#define C_OBS 0x01000
|
||||
#define C_OF 0x02000
|
||||
#define C_OSYNC 0x04000
|
||||
#define C_PAREVEN 0x08000
|
||||
#define C_PARNONE 0x100000
|
||||
#define C_PARODD 0x200000
|
||||
#define C_PARSET 0x400000
|
||||
#define C_SEEK 0x800000
|
||||
#define C_SKIP 0x1000000
|
||||
#define C_SPARSE 0x2000000
|
||||
#define C_SWAB 0x4000000
|
||||
#define C_SYNC 0x8000000
|
||||
#define C_UCASE 0x10000000
|
||||
#define C_UNBLOCK 0x20000000
|
||||
#define C_FILL 0x40000000
|
||||
|
||||
#define C_PARITY (C_PAREVEN | C_PARODD | C_PARNONE | C_PARSET)
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Keith Muller of the University of California, San Diego and Lance
|
||||
* Visser of Convex Computer Corporation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)extern.h 8.3 (Berkeley) 4/2/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
void block(void);
|
||||
void block_close(void);
|
||||
void dd_out(int);
|
||||
void def(void);
|
||||
void def_close(void);
|
||||
void jcl(char **);
|
||||
void pos_in(void);
|
||||
void pos_out(void);
|
||||
void summary(void);
|
||||
void summaryx(int);
|
||||
void terminate(int);
|
||||
void unblock(void);
|
||||
void unblock_close(void);
|
||||
|
||||
extern IO in, out;
|
||||
extern STAT st;
|
||||
extern void (*cfunc)(void);
|
||||
extern uintmax_t cpy_cnt;
|
||||
extern size_t cbsz;
|
||||
extern u_int ddflags;
|
||||
extern uintmax_t files_cnt;
|
||||
extern const u_char *ctab;
|
||||
extern const u_char a2e_32V[], a2e_POSIX[];
|
||||
extern const u_char e2a_32V[], e2a_POSIX[];
|
||||
extern const u_char a2ibm_32V[], a2ibm_POSIX[];
|
||||
extern u_char casetab[];
|
||||
extern char fill_char;
|
||||
17
bin/dd/gen.c
17
bin/dd/gen.c
|
|
@ -1,17 +0,0 @@
|
|||
/*-
|
||||
* This program is in the public domain
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(int argc __unused, char **argv __unused)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
putchar(i);
|
||||
return (0);
|
||||
}
|
||||
104
bin/dd/misc.c
104
bin/dd/misc.c
|
|
@ -1,104 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Keith Muller of the University of California, San Diego and Lance
|
||||
* Visser of Convex Computer Corporation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "dd.h"
|
||||
#include "extern.h"
|
||||
|
||||
void
|
||||
summary(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
double secs;
|
||||
char buf[100];
|
||||
|
||||
(void)gettimeofday(&tv, (struct timezone *)NULL);
|
||||
secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start;
|
||||
if (secs < 1e-6)
|
||||
secs = 1e-6;
|
||||
/* Use snprintf(3) so that we don't reenter stdio(3). */
|
||||
(void)snprintf(buf, sizeof(buf),
|
||||
"%ju+%ju records in\n%ju+%ju records out\n",
|
||||
st.in_full, st.in_part, st.out_full, st.out_part);
|
||||
(void)write(STDERR_FILENO, buf, strlen(buf));
|
||||
if (st.swab) {
|
||||
(void)snprintf(buf, sizeof(buf), "%ju odd length swab %s\n",
|
||||
st.swab, (st.swab == 1) ? "block" : "blocks");
|
||||
(void)write(STDERR_FILENO, buf, strlen(buf));
|
||||
}
|
||||
if (st.trunc) {
|
||||
(void)snprintf(buf, sizeof(buf), "%ju truncated %s\n",
|
||||
st.trunc, (st.trunc == 1) ? "block" : "blocks");
|
||||
(void)write(STDERR_FILENO, buf, strlen(buf));
|
||||
}
|
||||
(void)snprintf(buf, sizeof(buf),
|
||||
"%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n",
|
||||
st.bytes, secs, st.bytes / secs);
|
||||
(void)write(STDERR_FILENO, buf, strlen(buf));
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
summaryx(int notused __unused)
|
||||
{
|
||||
int save_errno = errno;
|
||||
|
||||
summary();
|
||||
errno = save_errno;
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void
|
||||
terminate(int sig)
|
||||
{
|
||||
|
||||
summary();
|
||||
_exit(sig == 0 ? 0 : 1);
|
||||
}
|
||||
|
|
@ -1,183 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Keith Muller of the University of California, San Diego and Lance
|
||||
* Visser of Convex Computer Corporation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)position.c 8.3 (Berkeley) 4/2/94";
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/mtio.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "dd.h"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* Position input/output data streams before starting the copy. Device type
|
||||
* dependent. Seekable devices use lseek, and the rest position by reading.
|
||||
* Seeking past the end of file can cause null blocks to be written to the
|
||||
* output.
|
||||
*/
|
||||
void
|
||||
pos_in(void)
|
||||
{
|
||||
off_t cnt;
|
||||
int warned;
|
||||
ssize_t nr;
|
||||
size_t bcnt;
|
||||
|
||||
/* If known to be seekable, try to seek on it. */
|
||||
if (in.flags & ISSEEK) {
|
||||
errno = 0;
|
||||
if (lseek(in.fd, in.offset * in.dbsz, SEEK_CUR) == -1 &&
|
||||
errno != 0)
|
||||
err(1, "%s", in.name);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Don't try to read a really weird amount (like negative). */
|
||||
if (in.offset < 0)
|
||||
errx(1, "%s: illegal offset", "iseek/skip");
|
||||
|
||||
/*
|
||||
* Read the data. If a pipe, read until satisfy the number of bytes
|
||||
* being skipped. No differentiation for reading complete and partial
|
||||
* blocks for other devices.
|
||||
*/
|
||||
for (bcnt = in.dbsz, cnt = in.offset, warned = 0; cnt;) {
|
||||
if ((nr = read(in.fd, in.db, bcnt)) > 0) {
|
||||
if (in.flags & ISPIPE) {
|
||||
if (!(bcnt -= nr)) {
|
||||
bcnt = in.dbsz;
|
||||
--cnt;
|
||||
}
|
||||
} else
|
||||
--cnt;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nr == 0) {
|
||||
if (files_cnt > 1) {
|
||||
--files_cnt;
|
||||
continue;
|
||||
}
|
||||
errx(1, "skip reached end of input");
|
||||
}
|
||||
|
||||
/*
|
||||
* Input error -- either EOF with no more files, or I/O error.
|
||||
* If noerror not set die. POSIX requires that the warning
|
||||
* message be followed by an I/O display.
|
||||
*/
|
||||
if (ddflags & C_NOERROR) {
|
||||
if (!warned) {
|
||||
warn("%s", in.name);
|
||||
warned = 1;
|
||||
summary();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
err(1, "%s", in.name);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pos_out(void)
|
||||
{
|
||||
struct mtop t_op;
|
||||
off_t cnt;
|
||||
ssize_t n;
|
||||
|
||||
/*
|
||||
* If not a tape, try seeking on the file. Seeking on a pipe is
|
||||
* going to fail, but don't protect the user -- they shouldn't
|
||||
* have specified the seek operand.
|
||||
*/
|
||||
if (out.flags & (ISSEEK | ISPIPE)) {
|
||||
errno = 0;
|
||||
if (lseek(out.fd, out.offset * out.dbsz, SEEK_CUR) == -1 &&
|
||||
errno != 0)
|
||||
err(1, "%s", out.name);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Don't try to read a really weird amount (like negative). */
|
||||
if (out.offset < 0)
|
||||
errx(1, "%s: illegal offset", "oseek/seek");
|
||||
|
||||
/* If no read access, try using mtio. */
|
||||
if (out.flags & NOREAD) {
|
||||
t_op.mt_op = MTFSR;
|
||||
t_op.mt_count = out.offset;
|
||||
|
||||
if (ioctl(out.fd, MTIOCTOP, &t_op) == -1)
|
||||
err(1, "%s", out.name);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Read it. */
|
||||
for (cnt = 0; cnt < out.offset; ++cnt) {
|
||||
if ((n = read(out.fd, out.db, out.dbsz)) > 0)
|
||||
continue;
|
||||
|
||||
if (n == -1)
|
||||
err(1, "%s", out.name);
|
||||
|
||||
/*
|
||||
* If reach EOF, fill with NUL characters; first, back up over
|
||||
* the EOF mark. Note, cnt has not yet been incremented, so
|
||||
* the EOF read does not count as a seek'd block.
|
||||
*/
|
||||
t_op.mt_op = MTBSR;
|
||||
t_op.mt_count = 1;
|
||||
if (ioctl(out.fd, MTIOCTOP, &t_op) == -1)
|
||||
err(1, "%s", out.name);
|
||||
|
||||
while (cnt++ < out.offset) {
|
||||
n = write(out.fd, out.db, out.dbsz);
|
||||
if (n == -1)
|
||||
err(1, "%s", out.name);
|
||||
if ((size_t)n != out.dbsz)
|
||||
errx(1, "%s: write failure", out.name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$FreeBSD$
|
||||
00000000 00 01 02 03 9c 09 86 7f 97 8d 8e 0b 0c 0d 0e 0f |................|
|
||||
00000010 10 11 12 13 9d 85 08 87 18 19 92 8f 1c 1d 1e 1f |................|
|
||||
00000020 80 81 82 83 84 0a 17 1b 88 89 8a 8b 8c 05 06 07 |................|
|
||||
00000030 90 91 16 93 94 95 96 04 98 99 9a 9b 14 15 9e 1a |................|
|
||||
00000040 20 a0 a1 a2 a3 a4 a5 a6 a7 a8 d5 2e 3c 28 2b 7c | ...........<(+||
|
||||
00000050 26 a9 aa ab ac ad ae af b0 b1 21 24 2a 29 3b 7e |&.........!$*);~|
|
||||
00000060 2d 2f b2 b3 b4 b5 b6 b7 b8 b9 cb 2c 25 5f 3e 3f |-/.........,%_>?|
|
||||
00000070 ba bb bc bd be bf c0 c1 c2 60 3a 23 40 27 3d 22 |.........`:#@'="|
|
||||
00000080 c3 61 62 63 64 65 66 67 68 69 c4 c5 c6 c7 c8 c9 |.abcdefghi......|
|
||||
00000090 ca 6a 6b 6c 6d 6e 6f 70 71 72 5e cc cd ce cf d0 |.jklmnopqr^.....|
|
||||
000000a0 d1 e5 73 74 75 76 77 78 79 7a d2 d3 d4 5b d6 d7 |..stuvwxyz...[..|
|
||||
000000b0 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 5d e6 e7 |.............]..|
|
||||
000000c0 7b 41 42 43 44 45 46 47 48 49 e8 e9 ea eb ec ed |{ABCDEFGHI......|
|
||||
000000d0 7d 4a 4b 4c 4d 4e 4f 50 51 52 ee ef f0 f1 f2 f3 |}JKLMNOPQR......|
|
||||
000000e0 5c 9f 53 54 55 56 57 58 59 5a f4 f5 f6 f7 f8 f9 |\.STUVWXYZ......|
|
||||
000000f0 30 31 32 33 34 35 36 37 38 39 fa fb fc fd fe ff |0123456789......|
|
||||
00000100
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$FreeBSD$
|
||||
00000000 00 01 02 03 37 2d 2e 2f 16 05 25 0b 0c 0d 0e 0f |....7-./..%.....|
|
||||
00000010 10 11 12 13 3c 3d 32 26 18 19 3f 27 1c 1d 1e 1f |....<=2&..?'....|
|
||||
00000020 40 5a 7f 7b 5b 6c 50 7d 4d 5d 5c 4e 6b 60 4b 61 |@Z.{[lP}M]\Nk`Ka|
|
||||
00000030 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 7a 5e 4c 7e 6e 6f |..........z^L~no|
|
||||
00000040 7c c1 c2 c3 c4 c5 c6 c7 c8 c9 d1 d2 d3 d4 d5 d6 ||...............|
|
||||
00000050 d7 d8 d9 e2 e3 e4 e5 e6 e7 e8 e9 ad e0 bd 9a 6d |...............m|
|
||||
00000060 79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96 |y...............|
|
||||
00000070 97 98 99 a2 a3 a4 a5 a6 a7 a8 a9 c0 4f d0 5f 07 |............O._.|
|
||||
00000080 20 21 22 23 24 15 06 17 28 29 2a 2b 2c 09 0a 1b | !"#$...()*+,...|
|
||||
00000090 30 31 1a 33 34 35 36 08 38 39 3a 3b 04 14 3e e1 |01.3456.89:;..>.|
|
||||
000000a0 41 42 43 44 45 46 47 48 49 51 52 53 54 55 56 57 |ABCDEFGHIQRSTUVW|
|
||||
000000b0 58 59 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |XYbcdefghipqrstu|
|
||||
000000c0 76 77 78 80 8a 8b 8c 8d 8e 8f 90 6a 9b 9c 9d 9e |vwx........j....|
|
||||
000000d0 9f a0 aa ab ac 4a ae af b0 b1 b2 b3 b4 b5 b6 b7 |.....J..........|
|
||||
000000e0 b8 b9 ba bb bc a1 be bf ca cb cc cd ce cf da db |................|
|
||||
000000f0 dc dd de df ea eb ec ed ee ef fa fb fc fd fe ff |................|
|
||||
00000100
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$FreeBSD$
|
||||
00000000 00 01 02 03 37 2d 2e 2f 16 05 25 0b 0c 0d 0e 0f |....7-./..%.....|
|
||||
00000010 10 11 12 13 3c 3d 32 26 18 19 3f 27 1c 1d 1e 1f |....<=2&..?'....|
|
||||
00000020 40 5a 7f 7b 5b 6c 50 7d 4d 5d 5c 4e 6b 60 4b 61 |@Z.{[lP}M]\Nk`Ka|
|
||||
00000030 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 7a 5e 4c 7e 6e 6f |..........z^L~no|
|
||||
00000040 7c c1 c2 c3 c4 c5 c6 c7 c8 c9 d1 d2 d3 d4 d5 d6 ||...............|
|
||||
00000050 d7 d8 d9 e2 e3 e4 e5 e6 e7 e8 e9 ad e0 bd 5f 6d |.............._m|
|
||||
00000060 79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96 |y...............|
|
||||
00000070 97 98 99 a2 a3 a4 a5 a6 a7 a8 a9 c0 4f d0 a1 07 |............O...|
|
||||
00000080 20 21 22 23 24 15 06 17 28 29 2a 2b 2c 09 0a 1b | !"#$...()*+,...|
|
||||
00000090 30 31 1a 33 34 35 36 08 38 39 3a 3b 04 14 3e e1 |01.3456.89:;..>.|
|
||||
000000a0 41 42 43 44 45 46 47 48 49 51 52 53 54 55 56 57 |ABCDEFGHIQRSTUVW|
|
||||
000000b0 58 59 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |XYbcdefghipqrstu|
|
||||
000000c0 76 77 78 80 8a 8b 8c 8d 8e 8f 90 9a 9b 9c 9d 9e |vwx.............|
|
||||
000000d0 9f a0 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 |................|
|
||||
000000e0 b8 b9 ba bb bc bd be bf ca cb cc cd ce cf da db |................|
|
||||
000000f0 dc dd de df ea eb ec ed ee ef fa fb fc fd fe ff |................|
|
||||
00000100
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$FreeBSD$
|
||||
00000000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f |................|
|
||||
00000010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f |................|
|
||||
00000020 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f | !"#$%&'()*+,-./|
|
||||
00000030 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f |0123456789:;<=>?|
|
||||
00000040 40 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f |@abcdefghijklmno|
|
||||
00000050 70 71 72 73 74 75 76 77 78 79 7a 5b 5c 5d 5e 5f |pqrstuvwxyz[\]^_|
|
||||
00000060 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f |`abcdefghijklmno|
|
||||
00000070 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f |pqrstuvwxyz{|}~.|
|
||||
00000080 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f |................|
|
||||
00000090 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f |................|
|
||||
000000a0 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af |................|
|
||||
000000b0 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf |................|
|
||||
000000c0 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf |................|
|
||||
000000d0 d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df |................|
|
||||
000000e0 e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef |................|
|
||||
000000f0 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff |................|
|
||||
00000100
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$FreeBSD$
|
||||
00000000 00 01 02 03 9c 09 86 7f 97 8d 8e 0b 0c 0d 0e 0f |................|
|
||||
00000010 10 11 12 13 9d 85 08 87 18 19 92 8f 1c 1d 1e 1f |................|
|
||||
00000020 80 81 82 83 84 0a 17 1b 88 89 8a 8b 8c 05 06 07 |................|
|
||||
00000030 90 91 16 93 94 95 96 04 98 99 9a 9b 14 15 9e 1a |................|
|
||||
00000040 20 a0 a1 a2 a3 a4 a5 a6 a7 a8 5b 2e 3c 28 2b 21 | .........[.<(+!|
|
||||
00000050 26 a9 aa ab ac ad ae af b0 b1 5d 24 2a 29 3b 5e |&.........]$*);^|
|
||||
00000060 2d 2f b2 b3 b4 b5 b6 b7 b8 b9 7c 2c 25 5f 3e 3f |-/........|,%_>?|
|
||||
00000070 ba bb bc bd be bf c0 c1 c2 60 3a 23 40 27 3d 22 |.........`:#@'="|
|
||||
00000080 c3 61 62 63 64 65 66 67 68 69 c4 c5 c6 c7 c8 c9 |.abcdefghi......|
|
||||
00000090 ca 6a 6b 6c 6d 6e 6f 70 71 72 cb cc cd ce cf d0 |.jklmnopqr......|
|
||||
000000a0 d1 7e 73 74 75 76 77 78 79 7a d2 d3 d4 d5 d6 d7 |.~stuvwxyz......|
|
||||
000000b0 d8 d9 da db dc dd de df e0 e1 e2 e3 e4 e5 e6 e7 |................|
|
||||
000000c0 7b 41 42 43 44 45 46 47 48 49 e8 e9 ea eb ec ed |{ABCDEFGHI......|
|
||||
000000d0 7d 4a 4b 4c 4d 4e 4f 50 51 52 ee ef f0 f1 f2 f3 |}JKLMNOPQR......|
|
||||
000000e0 5c 9f 53 54 55 56 57 58 59 5a f4 f5 f6 f7 f8 f9 |\.STUVWXYZ......|
|
||||
000000f0 30 31 32 33 34 35 36 37 38 39 fa fb fc fd fe ff |0123456789......|
|
||||
00000100
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$FreeBSD$
|
||||
00000000 00 01 02 03 37 2d 2e 2f 16 05 25 0b 0c 0d 0e 0f |....7-./..%.....|
|
||||
00000010 10 11 12 13 3c 3d 32 26 18 19 3f 27 1c 1d 1e 1f |....<=2&..?'....|
|
||||
00000020 40 4f 7f 7b 5b 6c 50 7d 4d 5d 5c 4e 6b 60 4b 61 |@O.{[lP}M]\Nk`Ka|
|
||||
00000030 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 7a 5e 4c 7e 6e 6f |..........z^L~no|
|
||||
00000040 7c c1 c2 c3 c4 c5 c6 c7 c8 c9 d1 d2 d3 d4 d5 d6 ||...............|
|
||||
00000050 d7 d8 d9 e2 e3 e4 e5 e6 e7 e8 e9 4a e0 5a 5f 6d |...........J.Z_m|
|
||||
00000060 79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96 |y...............|
|
||||
00000070 97 98 99 a2 a3 a4 a5 a6 a7 a8 a9 c0 6a d0 a1 07 |............j...|
|
||||
00000080 20 21 22 23 24 15 06 17 28 29 2a 2b 2c 09 0a 1b | !"#$...()*+,...|
|
||||
00000090 30 31 1a 33 34 35 36 08 38 39 3a 3b 04 14 3e e1 |01.3456.89:;..>.|
|
||||
000000a0 41 42 43 44 45 46 47 48 49 51 52 53 54 55 56 57 |ABCDEFGHIQRSTUVW|
|
||||
000000b0 58 59 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |XYbcdefghipqrstu|
|
||||
000000c0 76 77 78 80 8a 8b 8c 8d 8e 8f 90 9a 9b 9c 9d 9e |vwx.............|
|
||||
000000d0 9f a0 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 |................|
|
||||
000000e0 b8 b9 ba bb bc bd be bf ca cb cc cd ce cf da db |................|
|
||||
000000f0 dc dd de df ea eb ec ed ee ef fa fb fc fd fe ff |................|
|
||||
00000100
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$FreeBSD$
|
||||
00000000 00 01 02 03 37 2d 2e 2f 16 05 25 0b 0c 0d 0e 0f |....7-./..%.....|
|
||||
00000010 10 11 12 13 3c 3d 32 26 18 19 3f 27 1c 1d 1e 1f |....<=2&..?'....|
|
||||
00000020 40 5a 7f 7b 5b 6c 50 7d 4d 5d 5c 4e 6b 60 4b 61 |@Z.{[lP}M]\Nk`Ka|
|
||||
00000030 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 7a 5e 4c 7e 6e 6f |..........z^L~no|
|
||||
00000040 7c c1 c2 c3 c4 c5 c6 c7 c8 c9 d1 d2 d3 d4 d5 d6 ||...............|
|
||||
00000050 d7 d8 d9 e2 e3 e4 e5 e6 e7 e8 e9 ad e0 bd 5f 6d |.............._m|
|
||||
00000060 79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96 |y...............|
|
||||
00000070 97 98 99 a2 a3 a4 a5 a6 a7 a8 a9 c0 4f d0 a1 07 |............O...|
|
||||
00000080 20 21 22 23 24 15 06 17 28 29 2a 2b 2c 09 0a 1b | !"#$...()*+,...|
|
||||
00000090 30 31 1a 33 34 35 36 08 38 39 3a 3b 04 14 3e e1 |01.3456.89:;..>.|
|
||||
000000a0 41 42 43 44 45 46 47 48 49 51 52 53 54 55 56 57 |ABCDEFGHIQRSTUVW|
|
||||
000000b0 58 59 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |XYbcdefghipqrstu|
|
||||
000000c0 76 77 78 80 8a 8b 8c 8d 8e 8f 90 9a 9b 9c 9d 9e |vwx.............|
|
||||
000000d0 9f a0 aa ab ac ad ae af b0 b1 b2 b3 b4 b5 b6 b7 |................|
|
||||
000000e0 b8 b9 ba bb bc bd be bf ca cb cc cd ce cf da db |................|
|
||||
000000f0 dc dd de df ea eb ec ed ee ef fa fb fc fd fe ff |................|
|
||||
00000100
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$FreeBSD$
|
||||
00000000 00 81 82 03 84 05 06 87 88 09 0a 8b 0c 8d 8e 0f |................|
|
||||
00000010 90 11 12 93 14 95 96 17 18 99 9a 1b 9c 1d 1e 9f |................|
|
||||
00000020 a0 21 22 a3 24 a5 a6 27 28 a9 aa 2b ac 2d 2e af |.!".$..'(..+.-..|
|
||||
00000030 30 b1 b2 33 b4 35 36 b7 b8 39 3a bb 3c bd be 3f |0..3.56..9:.<..?|
|
||||
00000040 c0 41 42 c3 44 c5 c6 47 48 c9 ca 4b cc 4d 4e cf |.AB.D..GH..K.MN.|
|
||||
00000050 50 d1 d2 53 d4 55 56 d7 d8 59 5a db 5c dd de 5f |P..S.UV..YZ.\.._|
|
||||
00000060 60 e1 e2 63 e4 65 66 e7 e8 69 6a eb 6c ed ee 6f |`..c.ef..ij.l..o|
|
||||
00000070 f0 71 72 f3 74 f5 f6 77 78 f9 fa 7b fc 7d 7e ff |.qr.t..wx..{.}~.|
|
||||
00000080 00 81 82 03 84 05 06 87 88 09 0a 8b 0c 8d 8e 0f |................|
|
||||
00000090 90 11 12 93 14 95 96 17 18 99 9a 1b 9c 1d 1e 9f |................|
|
||||
000000a0 a0 21 22 a3 24 a5 a6 27 28 a9 aa 2b ac 2d 2e af |.!".$..'(..+.-..|
|
||||
000000b0 30 b1 b2 33 b4 35 36 b7 b8 39 3a bb 3c bd be 3f |0..3.56..9:.<..?|
|
||||
000000c0 c0 41 42 c3 44 c5 c6 47 48 c9 ca 4b cc 4d 4e cf |.AB.D..GH..K.MN.|
|
||||
000000d0 50 d1 d2 53 d4 55 56 d7 d8 59 5a db 5c dd de 5f |P..S.UV..YZ.\.._|
|
||||
000000e0 60 e1 e2 63 e4 65 66 e7 e8 69 6a eb 6c ed ee 6f |`..c.ef..ij.l..o|
|
||||
000000f0 f0 71 72 f3 74 f5 f6 77 78 f9 fa 7b fc 7d 7e ff |.qr.t..wx..{.}~.|
|
||||
00000100
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$FreeBSD$
|
||||
00000000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f |................|
|
||||
00000010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f |................|
|
||||
00000020 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f | !"#$%&'()*+,-./|
|
||||
00000030 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f |0123456789:;<=>?|
|
||||
00000040 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f |@ABCDEFGHIJKLMNO|
|
||||
00000050 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f |PQRSTUVWXYZ[\]^_|
|
||||
00000060 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f |`abcdefghijklmno|
|
||||
00000070 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f |pqrstuvwxyz{|}~.|
|
||||
00000080 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f |................|
|
||||
00000090 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f |................|
|
||||
000000a0 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f | !"#$%&'()*+,-./|
|
||||
000000b0 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f |0123456789:;<=>?|
|
||||
000000c0 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f |@ABCDEFGHIJKLMNO|
|
||||
000000d0 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f |PQRSTUVWXYZ[\]^_|
|
||||
000000e0 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f |`abcdefghijklmno|
|
||||
000000f0 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f |pqrstuvwxyz{|}~.|
|
||||
00000100
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$FreeBSD$
|
||||
00000000 80 01 02 83 04 85 86 07 08 89 8a 0b 8c 0d 0e 8f |................|
|
||||
00000010 10 91 92 13 94 15 16 97 98 19 1a 9b 1c 9d 9e 1f |................|
|
||||
00000020 20 a1 a2 23 a4 25 26 a7 a8 29 2a ab 2c ad ae 2f | ..#.%&..)*.,../|
|
||||
00000030 b0 31 32 b3 34 b5 b6 37 38 b9 ba 3b bc 3d 3e bf |.12.4..78..;.=>.|
|
||||
00000040 40 c1 c2 43 c4 45 46 c7 c8 49 4a cb 4c cd ce 4f |@..C.EF..IJ.L..O|
|
||||
00000050 d0 51 52 d3 54 d5 d6 57 58 d9 da 5b dc 5d 5e df |.QR.T..WX..[.]^.|
|
||||
00000060 e0 61 62 e3 64 e5 e6 67 68 e9 ea 6b ec 6d 6e ef |.ab.d..gh..k.mn.|
|
||||
00000070 70 f1 f2 73 f4 75 76 f7 f8 79 7a fb 7c fd fe 7f |p..s.uv..yz.|...|
|
||||
00000080 80 01 02 83 04 85 86 07 08 89 8a 0b 8c 0d 0e 8f |................|
|
||||
00000090 10 91 92 13 94 15 16 97 98 19 1a 9b 1c 9d 9e 1f |................|
|
||||
000000a0 20 a1 a2 23 a4 25 26 a7 a8 29 2a ab 2c ad ae 2f | ..#.%&..)*.,../|
|
||||
000000b0 b0 31 32 b3 34 b5 b6 37 38 b9 ba 3b bc 3d 3e bf |.12.4..78..;.=>.|
|
||||
000000c0 40 c1 c2 43 c4 45 46 c7 c8 49 4a cb 4c cd ce 4f |@..C.EF..IJ.L..O|
|
||||
000000d0 d0 51 52 d3 54 d5 d6 57 58 d9 da 5b dc 5d 5e df |.QR.T..WX..[.]^.|
|
||||
000000e0 e0 61 62 e3 64 e5 e6 67 68 e9 ea 6b ec 6d 6e ef |.ab.d..gh..k.mn.|
|
||||
000000f0 70 f1 f2 73 f4 75 76 f7 f8 79 7a fb 7c fd fe 7f |p..s.uv..yz.|...|
|
||||
00000100
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$FreeBSD$
|
||||
00000000 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f |................|
|
||||
00000010 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f |................|
|
||||
00000020 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af |................|
|
||||
00000030 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf |................|
|
||||
00000040 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf |................|
|
||||
00000050 d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df |................|
|
||||
00000060 e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef |................|
|
||||
00000070 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff |................|
|
||||
00000080 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f |................|
|
||||
00000090 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f |................|
|
||||
000000a0 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af |................|
|
||||
000000b0 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf |................|
|
||||
000000c0 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf |................|
|
||||
000000d0 d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df |................|
|
||||
000000e0 e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef |................|
|
||||
000000f0 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff |................|
|
||||
00000100
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$FreeBSD$
|
||||
00000000 01 00 03 02 05 04 07 06 09 08 0b 0a 0d 0c 0f 0e |................|
|
||||
00000010 11 10 13 12 15 14 17 16 19 18 1b 1a 1d 1c 1f 1e |................|
|
||||
00000020 21 20 23 22 25 24 27 26 29 28 2b 2a 2d 2c 2f 2e |! #"%$'&)(+*-,/.|
|
||||
00000030 31 30 33 32 35 34 37 36 39 38 3b 3a 3d 3c 3f 3e |1032547698;:=<?>|
|
||||
00000040 41 40 43 42 45 44 47 46 49 48 4b 4a 4d 4c 4f 4e |A@CBEDGFIHKJMLON|
|
||||
00000050 51 50 53 52 55 54 57 56 59 58 5b 5a 5d 5c 5f 5e |QPSRUTWVYX[Z]\_^|
|
||||
00000060 61 60 63 62 65 64 67 66 69 68 6b 6a 6d 6c 6f 6e |a`cbedgfihkjmlon|
|
||||
00000070 71 70 73 72 75 74 77 76 79 78 7b 7a 7d 7c 7f 7e |qpsrutwvyx{z}|.~|
|
||||
00000080 81 80 83 82 85 84 87 86 89 88 8b 8a 8d 8c 8f 8e |................|
|
||||
00000090 91 90 93 92 95 94 97 96 99 98 9b 9a 9d 9c 9f 9e |................|
|
||||
000000a0 a1 a0 a3 a2 a5 a4 a7 a6 a9 a8 ab aa ad ac af ae |................|
|
||||
000000b0 b1 b0 b3 b2 b5 b4 b7 b6 b9 b8 bb ba bd bc bf be |................|
|
||||
000000c0 c1 c0 c3 c2 c5 c4 c7 c6 c9 c8 cb ca cd cc cf ce |................|
|
||||
000000d0 d1 d0 d3 d2 d5 d4 d7 d6 d9 d8 db da dd dc df de |................|
|
||||
000000e0 e1 e0 e3 e2 e5 e4 e7 e6 e9 e8 eb ea ed ec ef ee |................|
|
||||
000000f0 f1 f0 f3 f2 f5 f4 f7 f6 f9 f8 fb fa fd fc ff fe |................|
|
||||
00000100
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$FreeBSD$
|
||||
00000000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f |................|
|
||||
00000010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f |................|
|
||||
00000020 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f | !"#$%&'()*+,-./|
|
||||
00000030 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f |0123456789:;<=>?|
|
||||
00000040 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f |@ABCDEFGHIJKLMNO|
|
||||
00000050 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f |PQRSTUVWXYZ[\]^_|
|
||||
00000060 60 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f |`ABCDEFGHIJKLMNO|
|
||||
00000070 50 51 52 53 54 55 56 57 58 59 5a 7b 7c 7d 7e 7f |PQRSTUVWXYZ{|}~.|
|
||||
00000080 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f |................|
|
||||
00000090 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f |................|
|
||||
000000a0 a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af |................|
|
||||
000000b0 b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf |................|
|
||||
000000c0 c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf |................|
|
||||
000000d0 d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df |................|
|
||||
000000e0 e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef |................|
|
||||
000000f0 f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff |................|
|
||||
00000100
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
# @(#)Makefile 8.3 (Berkeley) 5/8/95
|
||||
# $FreeBSD$
|
||||
|
||||
MOUNT= ${.CURDIR}/../../sbin/mount
|
||||
.PATH: ${MOUNT}
|
||||
|
||||
PROG= df
|
||||
SRCS= df.c vfslist.c
|
||||
|
||||
CFLAGS+= -I${MOUNT}
|
||||
|
||||
DPADD= ${LIBUTIL}
|
||||
LDADD= -lutil
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
179
bin/df/df.1
179
bin/df/df.1
|
|
@ -1,179 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 1989, 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)df.1 8.3 (Berkeley) 5/8/95
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd November 23, 2008
|
||||
.Dt DF 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm df
|
||||
.Nd display free disk space
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl b | g | H | h | k | m | P
|
||||
.Op Fl acilnT
|
||||
.Op Fl t Ar type
|
||||
.Op Ar file | filesystem ...
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility
|
||||
displays statistics about the amount of free disk space on the specified
|
||||
.Ar file system
|
||||
or on the file system of which
|
||||
.Ar file
|
||||
is a part.
|
||||
Values are displayed in 512-byte per block counts.
|
||||
If neither a file or a file system operand is specified,
|
||||
statistics for all mounted file systems are displayed
|
||||
(subject to the
|
||||
.Fl t
|
||||
option below).
|
||||
.Pp
|
||||
The following options are available:
|
||||
.Bl -tag -width indent
|
||||
.It Fl a
|
||||
Show all mount points, including those that were mounted with the
|
||||
.Dv MNT_IGNORE
|
||||
flag.
|
||||
.It Fl b
|
||||
Use 512-byte blocks rather than the default.
|
||||
Note that
|
||||
this overrides the
|
||||
.Ev BLOCKSIZE
|
||||
specification from the environment.
|
||||
.It Fl c
|
||||
Display a grand total.
|
||||
.It Fl g
|
||||
Use 1073741824-byte (1-Gbyte) blocks rather than the default.
|
||||
Note that
|
||||
this overrides the
|
||||
.Ev BLOCKSIZE
|
||||
specification from the environment.
|
||||
.It Fl H
|
||||
.Dq Human-readable
|
||||
output.
|
||||
Use unit suffixes: Byte, Kilobyte, Megabyte,
|
||||
Gigabyte, Terabyte and Petabyte in order to reduce the number of
|
||||
digits to four or fewer using base 10 for sizes.
|
||||
.It Fl h
|
||||
.Dq Human-readable
|
||||
output.
|
||||
Use unit suffixes: Byte, Kilobyte, Megabyte,
|
||||
Gigabyte, Terabyte and Petabyte in order to reduce the number of
|
||||
digits to four or fewer using base 2 for sizes.
|
||||
Inodes statistics, if enabled with
|
||||
.Fl i ,
|
||||
are always printed in base 10.
|
||||
.It Fl i
|
||||
Include statistics on the number of free inodes.
|
||||
.It Fl k
|
||||
Use 1024-byte (1-Kbyte) blocks rather than the default.
|
||||
Note that
|
||||
this overrides the
|
||||
.Ev BLOCKSIZE
|
||||
specification from the environment.
|
||||
.It Fl l
|
||||
Only display information about locally-mounted file systems.
|
||||
.It Fl m
|
||||
Use 1048576-byte (1-Mbyte) blocks rather than the default.
|
||||
Note that
|
||||
this overrides the
|
||||
.Ev BLOCKSIZE
|
||||
specification from the environment.
|
||||
.It Fl n
|
||||
Print out the previously obtained statistics from the file systems.
|
||||
This option should be used if it is possible that one or more
|
||||
file systems are in a state such that they will not be able to provide
|
||||
statistics without a long delay.
|
||||
When this option is specified,
|
||||
.Nm
|
||||
will not request new statistics from the file systems, but will respond
|
||||
with the possibly stale statistics that were previously obtained.
|
||||
.It Fl P
|
||||
Use POSIX compliant output of 512-byte blocks rather than the default.
|
||||
Note that this overrides the
|
||||
.Ev BLOCKSIZE
|
||||
specification from the environment.
|
||||
.It Fl t
|
||||
Only print out statistics for file systems of the specified types.
|
||||
More than one type may be specified in a comma separated list.
|
||||
The list of file system types can be prefixed with
|
||||
.Dq no
|
||||
to specify the file system types for which action should
|
||||
.Em not
|
||||
be taken.
|
||||
For example, the
|
||||
.Nm
|
||||
command:
|
||||
.Bd -literal -offset indent
|
||||
df -t nonfs,nullfs
|
||||
.Ed
|
||||
.Pp
|
||||
lists all file systems except those of type
|
||||
.Tn NFS
|
||||
and
|
||||
.Tn NULLFS .
|
||||
The
|
||||
.Xr lsvfs 1
|
||||
command can be used to find out the types of file systems
|
||||
that are available on the system.
|
||||
.It Fl T
|
||||
Include file system type.
|
||||
.El
|
||||
.Sh ENVIRONMENT
|
||||
.Bl -tag -width BLOCKSIZE
|
||||
.It Ev BLOCKSIZE
|
||||
If the environment variable
|
||||
.Ev BLOCKSIZE
|
||||
is set, the block counts will be displayed in units of that size block.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr lsvfs 1 ,
|
||||
.Xr quota 1 ,
|
||||
.Xr fstatfs 2 ,
|
||||
.Xr getfsstat 2 ,
|
||||
.Xr statfs 2 ,
|
||||
.Xr getmntinfo 3 ,
|
||||
.Xr fstab 5 ,
|
||||
.Xr mount 8 ,
|
||||
.Xr quot 8
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Nm
|
||||
command appeared in
|
||||
.At v1 .
|
||||
.Sh BUGS
|
||||
The
|
||||
.Fl n
|
||||
flag is ignored if a file or file system is specified.
|
||||
Also, if a mount
|
||||
point is not accessible by the user, it is possible that the file system
|
||||
information could be stale.
|
||||
613
bin/df/df.c
613
bin/df/df.c
|
|
@ -1,613 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1980, 1990, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
* (c) UNIX System Laboratories, Inc.
|
||||
* All or some portions of this file are derived from material licensed
|
||||
* to the University of California by American Telephone and Telegraph
|
||||
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
||||
* the permission of UNIX System Laboratories, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static const char copyright[] =
|
||||
"@(#) Copyright (c) 1980, 1990, 1993, 1994\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)df.c 8.9 (Berkeley) 5/8/95";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <ufs/ufs/ufsmount.h>
|
||||
#include <err.h>
|
||||
#include <libutil.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sysexits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "extern.h"
|
||||
|
||||
#define UNITS_SI 1
|
||||
#define UNITS_2 2
|
||||
|
||||
/* Maximum widths of various fields. */
|
||||
struct maxwidths {
|
||||
int mntfrom;
|
||||
int fstype;
|
||||
int total;
|
||||
int used;
|
||||
int avail;
|
||||
int iused;
|
||||
int ifree;
|
||||
};
|
||||
|
||||
static void addstat(struct statfs *, struct statfs *);
|
||||
static char *getmntpt(const char *);
|
||||
static int int64width(int64_t);
|
||||
static char *makenetvfslist(void);
|
||||
static void prthuman(const struct statfs *, int64_t);
|
||||
static void prthumanval(int64_t);
|
||||
static intmax_t fsbtoblk(int64_t, uint64_t, u_long);
|
||||
static void prtstat(struct statfs *, struct maxwidths *);
|
||||
static size_t regetmntinfo(struct statfs **, long, const char **);
|
||||
static void update_maxwidths(struct maxwidths *, const struct statfs *);
|
||||
static void usage(void);
|
||||
|
||||
static __inline int
|
||||
imax(int a, int b)
|
||||
{
|
||||
return (a > b ? a : b);
|
||||
}
|
||||
|
||||
static int aflag = 0, cflag, hflag, iflag, kflag, lflag = 0, nflag, Tflag;
|
||||
static struct ufs_args mdev;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct stat stbuf;
|
||||
struct statfs statfsbuf, totalbuf;
|
||||
struct maxwidths maxwidths;
|
||||
struct statfs *mntbuf;
|
||||
const char *fstype;
|
||||
char *mntpath, *mntpt;
|
||||
const char **vfslist;
|
||||
size_t i, mntsize;
|
||||
int ch, rv;
|
||||
|
||||
fstype = "ufs";
|
||||
|
||||
memset(&totalbuf, 0, sizeof(totalbuf));
|
||||
totalbuf.f_bsize = DEV_BSIZE;
|
||||
strlcpy(totalbuf.f_mntfromname, "total", MNAMELEN);
|
||||
vfslist = NULL;
|
||||
while ((ch = getopt(argc, argv, "abcgHhiklmnPt:T")) != -1)
|
||||
switch (ch) {
|
||||
case 'a':
|
||||
aflag = 1;
|
||||
break;
|
||||
case 'b':
|
||||
/* FALLTHROUGH */
|
||||
case 'P':
|
||||
/*
|
||||
* POSIX specifically discusses the the behavior of
|
||||
* both -k and -P. It states that the blocksize should
|
||||
* be set to 1024. Thus, if this occurs, simply break
|
||||
* rather than clobbering the old blocksize.
|
||||
*/
|
||||
if (kflag)
|
||||
break;
|
||||
setenv("BLOCKSIZE", "512", 1);
|
||||
hflag = 0;
|
||||
break;
|
||||
case 'c':
|
||||
cflag = 1;
|
||||
break;
|
||||
case 'g':
|
||||
setenv("BLOCKSIZE", "1g", 1);
|
||||
hflag = 0;
|
||||
break;
|
||||
case 'H':
|
||||
hflag = UNITS_SI;
|
||||
break;
|
||||
case 'h':
|
||||
hflag = UNITS_2;
|
||||
break;
|
||||
case 'i':
|
||||
iflag = 1;
|
||||
break;
|
||||
case 'k':
|
||||
kflag++;
|
||||
setenv("BLOCKSIZE", "1024", 1);
|
||||
hflag = 0;
|
||||
break;
|
||||
case 'l':
|
||||
if (vfslist != NULL)
|
||||
errx(1, "-l and -t are mutually exclusive.");
|
||||
vfslist = makevfslist(makenetvfslist());
|
||||
lflag = 1;
|
||||
break;
|
||||
case 'm':
|
||||
setenv("BLOCKSIZE", "1m", 1);
|
||||
hflag = 0;
|
||||
break;
|
||||
case 'n':
|
||||
nflag = 1;
|
||||
break;
|
||||
case 't':
|
||||
if (lflag)
|
||||
errx(1, "-l and -t are mutually exclusive.");
|
||||
if (vfslist != NULL)
|
||||
errx(1, "only one -t option may be specified");
|
||||
fstype = optarg;
|
||||
vfslist = makevfslist(optarg);
|
||||
break;
|
||||
case 'T':
|
||||
Tflag = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
|
||||
bzero(&maxwidths, sizeof(maxwidths));
|
||||
for (i = 0; i < mntsize; i++)
|
||||
update_maxwidths(&maxwidths, &mntbuf[i]);
|
||||
|
||||
rv = 0;
|
||||
if (!*argv) {
|
||||
mntsize = regetmntinfo(&mntbuf, mntsize, vfslist);
|
||||
bzero(&maxwidths, sizeof(maxwidths));
|
||||
for (i = 0; i < mntsize; i++) {
|
||||
if (cflag)
|
||||
addstat(&totalbuf, &mntbuf[i]);
|
||||
update_maxwidths(&maxwidths, &mntbuf[i]);
|
||||
}
|
||||
if (cflag)
|
||||
update_maxwidths(&maxwidths, &totalbuf);
|
||||
for (i = 0; i < mntsize; i++)
|
||||
if (aflag || (mntbuf[i].f_flags & MNT_IGNORE) == 0)
|
||||
prtstat(&mntbuf[i], &maxwidths);
|
||||
if (cflag)
|
||||
prtstat(&totalbuf, &maxwidths);
|
||||
exit(rv);
|
||||
}
|
||||
|
||||
for (; *argv; argv++) {
|
||||
if (stat(*argv, &stbuf) < 0) {
|
||||
if ((mntpt = getmntpt(*argv)) == 0) {
|
||||
warn("%s", *argv);
|
||||
rv = 1;
|
||||
continue;
|
||||
}
|
||||
} else if (S_ISCHR(stbuf.st_mode)) {
|
||||
if ((mntpt = getmntpt(*argv)) == 0) {
|
||||
mdev.fspec = *argv;
|
||||
mntpath = strdup("/tmp/df.XXXXXX");
|
||||
if (mntpath == NULL) {
|
||||
warn("strdup failed");
|
||||
rv = 1;
|
||||
continue;
|
||||
}
|
||||
mntpt = mkdtemp(mntpath);
|
||||
if (mntpt == NULL) {
|
||||
warn("mkdtemp(\"%s\") failed", mntpath);
|
||||
rv = 1;
|
||||
free(mntpath);
|
||||
continue;
|
||||
}
|
||||
if (mount(fstype, mntpt, MNT_RDONLY,
|
||||
&mdev) != 0) {
|
||||
warn("%s", *argv);
|
||||
rv = 1;
|
||||
(void)rmdir(mntpt);
|
||||
free(mntpath);
|
||||
continue;
|
||||
} else if (statfs(mntpt, &statfsbuf) == 0) {
|
||||
statfsbuf.f_mntonname[0] = '\0';
|
||||
prtstat(&statfsbuf, &maxwidths);
|
||||
if (cflag)
|
||||
addstat(&totalbuf, &statfsbuf);
|
||||
} else {
|
||||
warn("%s", *argv);
|
||||
rv = 1;
|
||||
}
|
||||
(void)unmount(mntpt, 0);
|
||||
(void)rmdir(mntpt);
|
||||
free(mntpath);
|
||||
continue;
|
||||
}
|
||||
} else
|
||||
mntpt = *argv;
|
||||
|
||||
/*
|
||||
* Statfs does not take a `wait' flag, so we cannot
|
||||
* implement nflag here.
|
||||
*/
|
||||
if (statfs(mntpt, &statfsbuf) < 0) {
|
||||
warn("%s", mntpt);
|
||||
rv = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to make sure the arguments we've been given are
|
||||
* satisfied. Return an error if we have been asked to
|
||||
* list a mount point that does not match the other args
|
||||
* we've been given (-l, -t, etc.).
|
||||
*/
|
||||
if (checkvfsname(statfsbuf.f_fstypename, vfslist)) {
|
||||
rv = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
bzero(&maxwidths, sizeof(maxwidths));
|
||||
update_maxwidths(&maxwidths, &statfsbuf);
|
||||
}
|
||||
prtstat(&statfsbuf, &maxwidths);
|
||||
if (cflag)
|
||||
addstat(&totalbuf, &statfsbuf);
|
||||
}
|
||||
if (cflag)
|
||||
prtstat(&totalbuf, &maxwidths);
|
||||
return (rv);
|
||||
}
|
||||
|
||||
static char *
|
||||
getmntpt(const char *name)
|
||||
{
|
||||
size_t mntsize, i;
|
||||
struct statfs *mntbuf;
|
||||
|
||||
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
|
||||
for (i = 0; i < mntsize; i++) {
|
||||
if (!strcmp(mntbuf[i].f_mntfromname, name))
|
||||
return (mntbuf[i].f_mntonname);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make a pass over the file system info in ``mntbuf'' filtering out
|
||||
* file system types not in vfslist and possibly re-stating to get
|
||||
* current (not cached) info. Returns the new count of valid statfs bufs.
|
||||
*/
|
||||
static size_t
|
||||
regetmntinfo(struct statfs **mntbufp, long mntsize, const char **vfslist)
|
||||
{
|
||||
int error, i, j;
|
||||
struct statfs *mntbuf;
|
||||
|
||||
if (vfslist == NULL)
|
||||
return (nflag ? mntsize : getmntinfo(mntbufp, MNT_WAIT));
|
||||
|
||||
mntbuf = *mntbufp;
|
||||
for (j = 0, i = 0; i < mntsize; i++) {
|
||||
if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
|
||||
continue;
|
||||
/*
|
||||
* XXX statfs(2) can fail for various reasons. It may be
|
||||
* possible that the user does not have access to the
|
||||
* pathname, if this happens, we will fall back on
|
||||
* "stale" filesystem statistics.
|
||||
*/
|
||||
error = statfs(mntbuf[i].f_mntonname, &mntbuf[j]);
|
||||
if (nflag || error < 0)
|
||||
if (i != j) {
|
||||
if (error < 0)
|
||||
warnx("%s stats possibly stale",
|
||||
mntbuf[i].f_mntonname);
|
||||
mntbuf[j] = mntbuf[i];
|
||||
}
|
||||
j++;
|
||||
}
|
||||
return (j);
|
||||
}
|
||||
|
||||
static void
|
||||
prthuman(const struct statfs *sfsp, int64_t used)
|
||||
{
|
||||
|
||||
prthumanval(sfsp->f_blocks * sfsp->f_bsize);
|
||||
prthumanval(used * sfsp->f_bsize);
|
||||
prthumanval(sfsp->f_bavail * sfsp->f_bsize);
|
||||
}
|
||||
|
||||
static void
|
||||
prthumanval(int64_t bytes)
|
||||
{
|
||||
char buf[6];
|
||||
int flags;
|
||||
|
||||
flags = HN_B | HN_NOSPACE | HN_DECIMAL;
|
||||
if (hflag == UNITS_SI)
|
||||
flags |= HN_DIVISOR_1000;
|
||||
|
||||
humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1),
|
||||
bytes, "", HN_AUTOSCALE, flags);
|
||||
|
||||
(void)printf(" %6s", buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print an inode count in "human-readable" format.
|
||||
*/
|
||||
static void
|
||||
prthumanvalinode(int64_t bytes)
|
||||
{
|
||||
char buf[6];
|
||||
int flags;
|
||||
|
||||
flags = HN_NOSPACE | HN_DECIMAL | HN_DIVISOR_1000;
|
||||
|
||||
humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1),
|
||||
bytes, "", HN_AUTOSCALE, flags);
|
||||
|
||||
(void)printf(" %5s", buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert statfs returned file system size into BLOCKSIZE units.
|
||||
* Attempts to avoid overflow for large file systems.
|
||||
*/
|
||||
static intmax_t
|
||||
fsbtoblk(int64_t num, uint64_t fsbs, u_long bs)
|
||||
{
|
||||
|
||||
if (fsbs != 0 && fsbs < bs)
|
||||
return (num / (intmax_t)(bs / fsbs));
|
||||
else
|
||||
return (num * (intmax_t)(fsbs / bs));
|
||||
}
|
||||
|
||||
/*
|
||||
* Print out status about a file system.
|
||||
*/
|
||||
static void
|
||||
prtstat(struct statfs *sfsp, struct maxwidths *mwp)
|
||||
{
|
||||
static long blocksize;
|
||||
static int headerlen, timesthrough = 0;
|
||||
static const char *header;
|
||||
int64_t used, availblks, inodes;
|
||||
|
||||
if (++timesthrough == 1) {
|
||||
mwp->mntfrom = imax(mwp->mntfrom, (int)strlen("Filesystem"));
|
||||
mwp->fstype = imax(mwp->fstype, (int)strlen("Type"));
|
||||
if (hflag) {
|
||||
header = " Size";
|
||||
mwp->total = mwp->used = mwp->avail =
|
||||
(int)strlen(header);
|
||||
} else {
|
||||
header = getbsize(&headerlen, &blocksize);
|
||||
mwp->total = imax(mwp->total, headerlen);
|
||||
}
|
||||
mwp->used = imax(mwp->used, (int)strlen("Used"));
|
||||
mwp->avail = imax(mwp->avail, (int)strlen("Avail"));
|
||||
|
||||
(void)printf("%-*s", mwp->mntfrom, "Filesystem");
|
||||
if (Tflag)
|
||||
(void)printf(" %-*s", mwp->fstype, "Type");
|
||||
(void)printf(" %-*s %*s %*s Capacity", mwp->total, header,
|
||||
mwp->used, "Used", mwp->avail, "Avail");
|
||||
if (iflag) {
|
||||
mwp->iused = imax(hflag ? 0 : mwp->iused,
|
||||
(int)strlen(" iused"));
|
||||
mwp->ifree = imax(hflag ? 0 : mwp->ifree,
|
||||
(int)strlen("ifree"));
|
||||
(void)printf(" %*s %*s %%iused",
|
||||
mwp->iused - 2, "iused", mwp->ifree, "ifree");
|
||||
}
|
||||
(void)printf(" Mounted on\n");
|
||||
}
|
||||
(void)printf("%-*s", mwp->mntfrom, sfsp->f_mntfromname);
|
||||
if (Tflag)
|
||||
(void)printf(" %-*s", mwp->fstype, sfsp->f_fstypename);
|
||||
used = sfsp->f_blocks - sfsp->f_bfree;
|
||||
availblks = sfsp->f_bavail + used;
|
||||
if (hflag) {
|
||||
prthuman(sfsp, used);
|
||||
} else {
|
||||
(void)printf(" %*jd %*jd %*jd",
|
||||
mwp->total, fsbtoblk(sfsp->f_blocks,
|
||||
sfsp->f_bsize, blocksize),
|
||||
mwp->used, fsbtoblk(used, sfsp->f_bsize, blocksize),
|
||||
mwp->avail, fsbtoblk(sfsp->f_bavail,
|
||||
sfsp->f_bsize, blocksize));
|
||||
}
|
||||
(void)printf(" %5.0f%%",
|
||||
availblks == 0 ? 100.0 : (double)used / (double)availblks * 100.0);
|
||||
if (iflag) {
|
||||
inodes = sfsp->f_files;
|
||||
used = inodes - sfsp->f_ffree;
|
||||
if (hflag) {
|
||||
(void)printf(" ");
|
||||
prthumanvalinode(used);
|
||||
prthumanvalinode(sfsp->f_ffree);
|
||||
} else {
|
||||
(void)printf(" %*jd %*jd", mwp->iused, (intmax_t)used,
|
||||
mwp->ifree, (intmax_t)sfsp->f_ffree);
|
||||
}
|
||||
(void)printf(" %4.0f%% ", inodes == 0 ? 100.0 :
|
||||
(double)used / (double)inodes * 100.0);
|
||||
} else
|
||||
(void)printf(" ");
|
||||
if (strncmp(sfsp->f_mntfromname, "total", MNAMELEN) != 0)
|
||||
(void)printf(" %s", sfsp->f_mntonname);
|
||||
(void)printf("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
addstat(struct statfs *totalfsp, struct statfs *statfsp)
|
||||
{
|
||||
uint64_t bsize;
|
||||
|
||||
bsize = statfsp->f_bsize / totalfsp->f_bsize;
|
||||
totalfsp->f_blocks += statfsp->f_blocks * bsize;
|
||||
totalfsp->f_bfree += statfsp->f_bfree * bsize;
|
||||
totalfsp->f_bavail += statfsp->f_bavail * bsize;
|
||||
totalfsp->f_files += statfsp->f_files;
|
||||
totalfsp->f_ffree += statfsp->f_ffree;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the maximum field-width information in `mwp' based on
|
||||
* the file system specified by `sfsp'.
|
||||
*/
|
||||
static void
|
||||
update_maxwidths(struct maxwidths *mwp, const struct statfs *sfsp)
|
||||
{
|
||||
static long blocksize = 0;
|
||||
int dummy;
|
||||
|
||||
if (blocksize == 0)
|
||||
getbsize(&dummy, &blocksize);
|
||||
|
||||
mwp->mntfrom = imax(mwp->mntfrom, (int)strlen(sfsp->f_mntfromname));
|
||||
mwp->fstype = imax(mwp->fstype, (int)strlen(sfsp->f_fstypename));
|
||||
mwp->total = imax(mwp->total, int64width(
|
||||
fsbtoblk((int64_t)sfsp->f_blocks, sfsp->f_bsize, blocksize)));
|
||||
mwp->used = imax(mwp->used,
|
||||
int64width(fsbtoblk((int64_t)sfsp->f_blocks -
|
||||
(int64_t)sfsp->f_bfree, sfsp->f_bsize, blocksize)));
|
||||
mwp->avail = imax(mwp->avail, int64width(fsbtoblk(sfsp->f_bavail,
|
||||
sfsp->f_bsize, blocksize)));
|
||||
mwp->iused = imax(mwp->iused, int64width((int64_t)sfsp->f_files -
|
||||
sfsp->f_ffree));
|
||||
mwp->ifree = imax(mwp->ifree, int64width(sfsp->f_ffree));
|
||||
}
|
||||
|
||||
/* Return the width in characters of the specified value. */
|
||||
static int
|
||||
int64width(int64_t val)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
/* Negative or zero values require one extra digit. */
|
||||
if (val <= 0) {
|
||||
val = -val;
|
||||
len++;
|
||||
}
|
||||
while (val > 0) {
|
||||
len++;
|
||||
val /= 10;
|
||||
}
|
||||
|
||||
return (len);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
|
||||
(void)fprintf(stderr,
|
||||
"usage: df [-b | -g | -H | -h | -k | -m | -P] [-acilnT] [-t type] [file | filesystem ...]\n");
|
||||
exit(EX_USAGE);
|
||||
}
|
||||
|
||||
static char *
|
||||
makenetvfslist(void)
|
||||
{
|
||||
char *str, *strptr, **listptr;
|
||||
struct xvfsconf *xvfsp, *keep_xvfsp;
|
||||
size_t buflen;
|
||||
int cnt, i, maxvfsconf;
|
||||
|
||||
if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0) {
|
||||
warn("sysctl(vfs.conflist)");
|
||||
return (NULL);
|
||||
}
|
||||
xvfsp = malloc(buflen);
|
||||
if (xvfsp == NULL) {
|
||||
warnx("malloc failed");
|
||||
return (NULL);
|
||||
}
|
||||
keep_xvfsp = xvfsp;
|
||||
if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0) {
|
||||
warn("sysctl(vfs.conflist)");
|
||||
free(keep_xvfsp);
|
||||
return (NULL);
|
||||
}
|
||||
maxvfsconf = buflen / sizeof(struct xvfsconf);
|
||||
|
||||
if ((listptr = malloc(sizeof(char*) * maxvfsconf)) == NULL) {
|
||||
warnx("malloc failed");
|
||||
free(keep_xvfsp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
for (cnt = 0, i = 0; i < maxvfsconf; i++) {
|
||||
if (xvfsp->vfc_flags & VFCF_NETWORK) {
|
||||
listptr[cnt++] = strdup(xvfsp->vfc_name);
|
||||
if (listptr[cnt-1] == NULL) {
|
||||
warnx("malloc failed");
|
||||
free(listptr);
|
||||
free(keep_xvfsp);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
xvfsp++;
|
||||
}
|
||||
|
||||
if (cnt == 0 ||
|
||||
(str = malloc(sizeof(char) * (32 * cnt + cnt + 2))) == NULL) {
|
||||
if (cnt > 0)
|
||||
warnx("malloc failed");
|
||||
free(listptr);
|
||||
free(keep_xvfsp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
*str = 'n'; *(str + 1) = 'o';
|
||||
for (i = 0, strptr = str + 2; i < cnt; i++, strptr++) {
|
||||
strlcpy(strptr, listptr[i], 32);
|
||||
strptr += strlen(listptr[i]);
|
||||
*strptr = ',';
|
||||
free(listptr[i]);
|
||||
}
|
||||
*(--strptr) = '\0';
|
||||
|
||||
free(keep_xvfsp);
|
||||
free(listptr);
|
||||
return (str);
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
# $FreeBSD$
|
||||
|
||||
PROG= domainname
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 1983, 1988, 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" From: @(#)hostname.1 8.1 (Berkeley) 5/31/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd September 18, 1994
|
||||
.Dt DOMAINNAME 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm domainname
|
||||
.Nd set or print name of current YP/NIS domain
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Ar ypdomain
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility prints the name of the current YP/NIS domain.
|
||||
The super-user can
|
||||
set the domain name by supplying an argument; this is usually done in the
|
||||
network initialization script
|
||||
.Pa /etc/rc.network ,
|
||||
normally run at boot
|
||||
time.
|
||||
.Sh NOTES
|
||||
The YP/NIS (formerly ``Yellow Pages'' but renamed for legal reasons)
|
||||
domain name does not necessarily have anything to do with the Domain
|
||||
Name System domain name, although they are often set equal for administrative
|
||||
convenience.
|
||||
.Sh SEE ALSO
|
||||
.Xr getdomainname 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
command appeared in
|
||||
.Fx 1.1 ,
|
||||
based on a similar command in
|
||||
.Tn SunOS .
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char const copyright[] =
|
||||
"@(#) Copyright (c) 1988, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char const sccsid[] = "From: @(#)hostname.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void usage(void);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
char domainname[MAXHOSTNAMELEN];
|
||||
|
||||
while ((ch = getopt(argc, argv, "")) != -1)
|
||||
switch (ch) {
|
||||
case '?':
|
||||
/* fall through */
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc > 1)
|
||||
usage();
|
||||
|
||||
if (*argv) {
|
||||
if (setdomainname(*argv, (int)strlen(*argv)))
|
||||
err(1, "setdomainname");
|
||||
} else {
|
||||
if (getdomainname(domainname, (int)sizeof(domainname)))
|
||||
err(1, "getdomainname");
|
||||
(void)printf("%s\n", domainname);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr, "usage: domainname [ypdomain]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= echo
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
.\"-
|
||||
.\" Copyright (c) 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" the Institute of Electrical and Electronics Engineers, Inc.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)echo.1 8.1 (Berkeley) 7/22/93
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd April 12, 2003
|
||||
.Dt ECHO 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm echo
|
||||
.Nd write arguments to the standard output
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl n
|
||||
.Op Ar string ...
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility writes any specified operands, separated by single blank
|
||||
.Pq Ql "\ "
|
||||
characters and followed by a newline
|
||||
.Pq Ql \en
|
||||
character, to the standard
|
||||
output.
|
||||
.Pp
|
||||
The following option is available:
|
||||
.Bl -tag -width flag
|
||||
.It Fl n
|
||||
Do not print the trailing newline character.
|
||||
This may also be achieved by appending
|
||||
.Ql \ec
|
||||
to the end of the string, as is done
|
||||
by iBCS2 compatible systems.
|
||||
Note that this option as well as the effect of
|
||||
.Ql \ec
|
||||
are implementation-defined in
|
||||
.St -p1003.1-2001
|
||||
as amended by Cor.\& 1-2002.
|
||||
Applications aiming for maximum
|
||||
portability are strongly encouraged to use
|
||||
.Xr printf 1
|
||||
to suppress the newline character.
|
||||
.El
|
||||
.Pp
|
||||
Some shells may provide a builtin
|
||||
.Nm
|
||||
command which is similar or identical to this utility.
|
||||
Consult the
|
||||
.Xr builtin 1
|
||||
manual page.
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std
|
||||
.Sh SEE ALSO
|
||||
.Xr builtin 1 ,
|
||||
.Xr csh 1 ,
|
||||
.Xr printf 1 ,
|
||||
.Xr sh 1
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility conforms to
|
||||
.St -p1003.1-2001
|
||||
as amended by Cor.\& 1-2002.
|
||||
137
bin/echo/echo.c
137
bin/echo/echo.c
|
|
@ -1,137 +0,0 @@
|
|||
/*-
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static char const copyright[] =
|
||||
"@(#) Copyright (c) 1989, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)echo.c 8.1 (Berkeley) 5/31/93";
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
* Report an error and exit.
|
||||
* Use it instead of err(3) to avoid linking-in stdio.
|
||||
*/
|
||||
static __dead2 void
|
||||
errexit(const char *prog, const char *reason)
|
||||
{
|
||||
char *errstr = strerror(errno);
|
||||
write(STDERR_FILENO, prog, strlen(prog));
|
||||
write(STDERR_FILENO, ": ", 2);
|
||||
write(STDERR_FILENO, reason, strlen(reason));
|
||||
write(STDERR_FILENO, ": ", 2);
|
||||
write(STDERR_FILENO, errstr, strlen(errstr));
|
||||
write(STDERR_FILENO, "\n", 1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int nflag; /* if not set, output a trailing newline. */
|
||||
int veclen; /* number of writev arguments. */
|
||||
struct iovec *iov, *vp; /* Elements to write, current element. */
|
||||
char space[] = " ";
|
||||
char newline[] = "\n";
|
||||
char *progname = argv[0];
|
||||
|
||||
/* This utility may NOT do getopt(3) option parsing. */
|
||||
if (*++argv && !strcmp(*argv, "-n")) {
|
||||
++argv;
|
||||
--argc;
|
||||
nflag = 1;
|
||||
} else
|
||||
nflag = 0;
|
||||
|
||||
veclen = (argc >= 2) ? (argc - 2) * 2 + 1 : 0;
|
||||
|
||||
if ((vp = iov = malloc((veclen + 1) * sizeof(struct iovec))) == NULL)
|
||||
errexit(progname, "malloc");
|
||||
|
||||
while (argv[0] != NULL) {
|
||||
size_t len;
|
||||
|
||||
len = strlen(argv[0]);
|
||||
|
||||
/*
|
||||
* If the next argument is NULL then this is this
|
||||
* the last argument, therefore we need to check
|
||||
* for a trailing \c.
|
||||
*/
|
||||
if (argv[1] == NULL) {
|
||||
/* is there room for a '\c' and is there one? */
|
||||
if (len >= 2 &&
|
||||
argv[0][len - 2] == '\\' &&
|
||||
argv[0][len - 1] == 'c') {
|
||||
/* chop it and set the no-newline flag. */
|
||||
len -= 2;
|
||||
nflag = 1;
|
||||
}
|
||||
}
|
||||
vp->iov_base = *argv;
|
||||
vp++->iov_len = len;
|
||||
if (*++argv) {
|
||||
vp->iov_base = space;
|
||||
vp++->iov_len = 1;
|
||||
}
|
||||
}
|
||||
if (!nflag) {
|
||||
veclen++;
|
||||
vp->iov_base = newline;
|
||||
vp++->iov_len = 1;
|
||||
}
|
||||
/* assert(veclen == (vp - iov)); */
|
||||
while (veclen) {
|
||||
int nwrite;
|
||||
|
||||
nwrite = (veclen > IOV_MAX) ? IOV_MAX : veclen;
|
||||
if (writev(STDOUT_FILENO, iov, nwrite) == -1)
|
||||
errexit(progname, "write");
|
||||
iov += nwrite;
|
||||
veclen -= nwrite;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
# $FreeBSD$
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
PROG= ed
|
||||
SRCS= buf.c cbc.c glbl.c io.c main.c re.c sub.c undo.c
|
||||
LINKS= ${BINDIR}/ed ${BINDIR}/red
|
||||
MLINKS= ed.1 red.1
|
||||
|
||||
.if !defined(RELEASE_CRUNCH)
|
||||
.if ${MK_OPENSSL} != "no"
|
||||
CFLAGS+=-DDES
|
||||
DPADD= ${LIBCRYPTO}
|
||||
LDADD= -lcrypto
|
||||
.endif
|
||||
.endif
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
101
bin/ed/POSIX
101
bin/ed/POSIX
|
|
@ -1,101 +0,0 @@
|
|||
$FreeBSD$
|
||||
|
||||
This version of ed(1) is not strictly POSIX compliant, as described in
|
||||
the POSIX 1003.2 document. The following is a summary of the omissions,
|
||||
extensions and possible deviations from POSIX 1003.2.
|
||||
|
||||
OMISSIONS
|
||||
---------
|
||||
1) For backwards compatibility, the POSIX rule that says a range of
|
||||
addresses cannot be used where only a single address is expected has
|
||||
been relaxed.
|
||||
|
||||
2) To support the BSD `s' command (see extension [1] below),
|
||||
substitution patterns cannot be delimited by numbers or the characters
|
||||
`r', `g' and `p'. In contrast, POSIX specifies any character expect
|
||||
space or newline can used as a delimiter.
|
||||
|
||||
EXTENSIONS
|
||||
----------
|
||||
1) BSD commands have been implemented wherever they do not conflict with
|
||||
the POSIX standard. The BSD-ism's included are:
|
||||
i) `s' (i.e., s[n][rgp]*) to repeat a previous substitution,
|
||||
ii) `W' for appending text to an existing file,
|
||||
iii) `wq' for exiting after a write,
|
||||
iv) `z' for scrolling through the buffer, and
|
||||
v) BSD line addressing syntax (i.e., `^' and `%') is recognized.
|
||||
|
||||
2) If crypt(3) is available, files can be read and written using DES
|
||||
encryption. The `x' command prompts the user to enter a key used for
|
||||
encrypting/ decrypting subsequent reads and writes. If only a newline
|
||||
is entered as the key, then encryption is disabled. Otherwise, a key
|
||||
is read in the same manner as a password entry. The key remains in
|
||||
effect until encryption is disabled. For more information on the
|
||||
encryption algorithm, see the bdes(1) man page. Encryption/decryption
|
||||
should be fully compatible with SunOS des(1).
|
||||
|
||||
3) The POSIX interactive global commands `G' and `V' are extended to
|
||||
support multiple commands, including `a', `i' and `c'. The command
|
||||
format is the same as for the global commands `g' and `v', i.e., one
|
||||
command per line with each line, except for the last, ending in a
|
||||
backslash (\).
|
||||
|
||||
4) An extension to the POSIX file commands `E', `e', `r', `W' and `w' is
|
||||
that <file> arguments are processed for backslash escapes, i.e., any
|
||||
character preceded by a backslash is interpreted literally. If the
|
||||
first unescaped character of a <file> argument is a bang (!), then the
|
||||
rest of the line is interpreted as a shell command, and no escape
|
||||
processing is performed by ed.
|
||||
|
||||
5) For SunOS ed(1) compatibility, ed runs in restricted mode if invoked
|
||||
as red. This limits editing of files in the local directory only and
|
||||
prohibits shell commands.
|
||||
|
||||
DEVIATIONS
|
||||
----------
|
||||
1) Though ed is not a stream editor, it can be used to edit binary files.
|
||||
To assist in binary editing, when a file containing at least one ASCII
|
||||
NUL character is written, a newline is not appended if it did not
|
||||
already contain one upon reading. In particular, reading /dev/null
|
||||
prior to writing prevents appending a newline to a binary file.
|
||||
|
||||
For example, to create a file with ed containing a single NUL character:
|
||||
$ ed file
|
||||
a
|
||||
^@
|
||||
.
|
||||
r /dev/null
|
||||
wq
|
||||
|
||||
Similarly, to remove a newline from the end of binary `file':
|
||||
$ ed file
|
||||
r /dev/null
|
||||
wq
|
||||
|
||||
2) Since the behavior of `u' (undo) within a `g' (global) command list is
|
||||
not specified by POSIX, it follows the behavior of the SunOS ed:
|
||||
undo forces a global command list to be executed only once, rather than
|
||||
for each line matching a global pattern. In addtion, each instance of
|
||||
`u' within a global command undoes all previous commands (including
|
||||
undo's) in the command list. This seems the best way, since the
|
||||
alternatives are either too complicated to implement or too confusing
|
||||
to use.
|
||||
|
||||
The global/undo combination is useful for masking errors that
|
||||
would otherwise cause a script to fail. For instance, an ed script
|
||||
to remove any occurences of either `censor1' or `censor2' might be
|
||||
written as:
|
||||
ed - file <<EOF
|
||||
1g/.*/u\
|
||||
,s/censor1//g\
|
||||
,s/censor2//g
|
||||
...
|
||||
|
||||
3) The `m' (move) command within a `g' command list also follows the SunOS
|
||||
ed implementation: any moved lines are removed from the global command's
|
||||
`active' list.
|
||||
|
||||
4) If ed is invoked with a name argument prefixed by a bang (!), then the
|
||||
remainder of the argument is interpreted as a shell command. To invoke
|
||||
ed on a file whose name starts with bang, prefix the name with a
|
||||
backslash.
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
$FreeBSD$
|
||||
|
||||
ed is an 8-bit-clean, POSIX-compliant line editor. It should work with
|
||||
any regular expression package that conforms to the POSIX interface
|
||||
standard, such as GNU regex(3).
|
||||
|
||||
If reliable signals are supported (e.g., POSIX sigaction(2)), it should
|
||||
compile with little trouble. Otherwise, the macros SPL1() and SPL0()
|
||||
should be redefined to disable interrupts.
|
||||
|
||||
The following compiler directives are recognized:
|
||||
DES - to add encryption support (requires crypt(3))
|
||||
NO_REALLOC_NULL - if realloc(3) does not accept a NULL pointer
|
||||
BACKWARDS - for backwards compatibility
|
||||
NEED_INSQUE - if insque(3) is missing
|
||||
|
||||
The file `POSIX' describes extensions to and deviations from the POSIX
|
||||
standard.
|
||||
|
||||
The ./test directory contains regression tests for ed. The README
|
||||
file in that directory explains how to run these.
|
||||
|
||||
For a description of the ed algorithm, see Kernighan and Plauger's book
|
||||
"Software Tools in Pascal," Addison-Wesley, 1981.
|
||||
284
bin/ed/buf.c
284
bin/ed/buf.c
|
|
@ -1,284 +0,0 @@
|
|||
/* buf.c: This file contains the scratch-file buffer routines for the
|
||||
ed line editor. */
|
||||
/*-
|
||||
* Copyright (c) 1993 Andrew Moore, Talke Studio.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/file.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "ed.h"
|
||||
|
||||
|
||||
FILE *sfp; /* scratch file pointer */
|
||||
off_t sfseek; /* scratch file position */
|
||||
int seek_write; /* seek before writing */
|
||||
line_t buffer_head; /* incore buffer */
|
||||
|
||||
/* get_sbuf_line: get a line of text from the scratch file; return pointer
|
||||
to the text */
|
||||
char *
|
||||
get_sbuf_line(line_t *lp)
|
||||
{
|
||||
static char *sfbuf = NULL; /* buffer */
|
||||
static int sfbufsz = 0; /* buffer size */
|
||||
|
||||
int len, ct;
|
||||
|
||||
if (lp == &buffer_head)
|
||||
return NULL;
|
||||
seek_write = 1; /* force seek on write */
|
||||
/* out of position */
|
||||
if (sfseek != lp->seek) {
|
||||
sfseek = lp->seek;
|
||||
if (fseeko(sfp, sfseek, SEEK_SET) < 0) {
|
||||
fprintf(stderr, "%s\n", strerror(errno));
|
||||
errmsg = "cannot seek temp file";
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
len = lp->len;
|
||||
REALLOC(sfbuf, sfbufsz, len + 1, NULL);
|
||||
if ((ct = fread(sfbuf, sizeof(char), len, sfp)) < 0 || ct != len) {
|
||||
fprintf(stderr, "%s\n", strerror(errno));
|
||||
errmsg = "cannot read temp file";
|
||||
return NULL;
|
||||
}
|
||||
sfseek += len; /* update file position */
|
||||
sfbuf[len] = '\0';
|
||||
return sfbuf;
|
||||
}
|
||||
|
||||
|
||||
/* put_sbuf_line: write a line of text to the scratch file and add a line node
|
||||
to the editor buffer; return a pointer to the end of the text */
|
||||
const char *
|
||||
put_sbuf_line(const char *cs)
|
||||
{
|
||||
line_t *lp;
|
||||
int len, ct;
|
||||
const char *s;
|
||||
|
||||
if ((lp = (line_t *) malloc(sizeof(line_t))) == NULL) {
|
||||
fprintf(stderr, "%s\n", strerror(errno));
|
||||
errmsg = "out of memory";
|
||||
return NULL;
|
||||
}
|
||||
/* assert: cs is '\n' terminated */
|
||||
for (s = cs; *s != '\n'; s++)
|
||||
;
|
||||
if (s - cs >= LINECHARS) {
|
||||
errmsg = "line too long";
|
||||
return NULL;
|
||||
}
|
||||
len = s - cs;
|
||||
/* out of position */
|
||||
if (seek_write) {
|
||||
if (fseeko(sfp, (off_t)0, SEEK_END) < 0) {
|
||||
fprintf(stderr, "%s\n", strerror(errno));
|
||||
errmsg = "cannot seek temp file";
|
||||
return NULL;
|
||||
}
|
||||
sfseek = ftello(sfp);
|
||||
seek_write = 0;
|
||||
}
|
||||
/* assert: SPL1() */
|
||||
if ((ct = fwrite(cs, sizeof(char), len, sfp)) < 0 || ct != len) {
|
||||
sfseek = -1;
|
||||
fprintf(stderr, "%s\n", strerror(errno));
|
||||
errmsg = "cannot write temp file";
|
||||
return NULL;
|
||||
}
|
||||
lp->len = len;
|
||||
lp->seek = sfseek;
|
||||
add_line_node(lp);
|
||||
sfseek += len; /* update file position */
|
||||
return ++s;
|
||||
}
|
||||
|
||||
|
||||
/* add_line_node: add a line node in the editor buffer after the current line */
|
||||
void
|
||||
add_line_node(line_t *lp)
|
||||
{
|
||||
line_t *cp;
|
||||
|
||||
cp = get_addressed_line_node(current_addr); /* this get_addressed_line_node last! */
|
||||
INSQUE(lp, cp);
|
||||
addr_last++;
|
||||
current_addr++;
|
||||
}
|
||||
|
||||
|
||||
/* get_line_node_addr: return line number of pointer */
|
||||
long
|
||||
get_line_node_addr(line_t *lp)
|
||||
{
|
||||
line_t *cp = &buffer_head;
|
||||
long n = 0;
|
||||
|
||||
while (cp != lp && (cp = cp->q_forw) != &buffer_head)
|
||||
n++;
|
||||
if (n && cp == &buffer_head) {
|
||||
errmsg = "invalid address";
|
||||
return ERR;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/* get_addressed_line_node: return pointer to a line node in the editor buffer */
|
||||
line_t *
|
||||
get_addressed_line_node(long n)
|
||||
{
|
||||
static line_t *lp = &buffer_head;
|
||||
static long on = 0;
|
||||
|
||||
SPL1();
|
||||
if (n > on)
|
||||
if (n <= (on + addr_last) >> 1)
|
||||
for (; on < n; on++)
|
||||
lp = lp->q_forw;
|
||||
else {
|
||||
lp = buffer_head.q_back;
|
||||
for (on = addr_last; on > n; on--)
|
||||
lp = lp->q_back;
|
||||
}
|
||||
else
|
||||
if (n >= on >> 1)
|
||||
for (; on > n; on--)
|
||||
lp = lp->q_back;
|
||||
else {
|
||||
lp = &buffer_head;
|
||||
for (on = 0; on < n; on++)
|
||||
lp = lp->q_forw;
|
||||
}
|
||||
SPL0();
|
||||
return lp;
|
||||
}
|
||||
|
||||
|
||||
extern int newline_added;
|
||||
|
||||
char sfn[15] = ""; /* scratch file name */
|
||||
|
||||
/* open_sbuf: open scratch file */
|
||||
int
|
||||
open_sbuf(void)
|
||||
{
|
||||
int fd;
|
||||
int u;
|
||||
|
||||
isbinary = newline_added = 0;
|
||||
u = umask(077);
|
||||
strcpy(sfn, "/tmp/ed.XXXXXX");
|
||||
if ((fd = mkstemp(sfn)) == -1 ||
|
||||
(sfp = fdopen(fd, "w+")) == NULL) {
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
perror(sfn);
|
||||
errmsg = "cannot open temp file";
|
||||
umask(u);
|
||||
return ERR;
|
||||
}
|
||||
umask(u);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* close_sbuf: close scratch file */
|
||||
int
|
||||
close_sbuf(void)
|
||||
{
|
||||
if (sfp) {
|
||||
if (fclose(sfp) < 0) {
|
||||
fprintf(stderr, "%s: %s\n", sfn, strerror(errno));
|
||||
errmsg = "cannot close temp file";
|
||||
return ERR;
|
||||
}
|
||||
sfp = NULL;
|
||||
unlink(sfn);
|
||||
}
|
||||
sfseek = seek_write = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* quit: remove_lines scratch file and exit */
|
||||
void
|
||||
quit(int n)
|
||||
{
|
||||
if (sfp) {
|
||||
fclose(sfp);
|
||||
unlink(sfn);
|
||||
}
|
||||
exit(n);
|
||||
}
|
||||
|
||||
|
||||
unsigned char ctab[256]; /* character translation table */
|
||||
|
||||
/* init_buffers: open scratch buffer; initialize line queue */
|
||||
void
|
||||
init_buffers(void)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
/* Read stdin one character at a time to avoid i/o contention
|
||||
with shell escapes invoked by nonterminal input, e.g.,
|
||||
ed - <<EOF
|
||||
!cat
|
||||
hello, world
|
||||
EOF */
|
||||
setbuffer(stdin, stdinbuf, 1);
|
||||
|
||||
/* Ensure stdout is line buffered. This avoids bogus delays
|
||||
of output if stdout is piped through utilities to a terminal. */
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
if (open_sbuf() < 0)
|
||||
quit(2);
|
||||
REQUE(&buffer_head, &buffer_head);
|
||||
for (i = 0; i < 256; i++)
|
||||
ctab[i] = i;
|
||||
}
|
||||
|
||||
|
||||
/* translit_text: translate characters in a string */
|
||||
char *
|
||||
translit_text(char *s, int len, int from, int to)
|
||||
{
|
||||
static int i = 0;
|
||||
|
||||
unsigned char *us;
|
||||
|
||||
ctab[i] = i; /* restore table to initial state */
|
||||
ctab[i = from] = to;
|
||||
for (us = (unsigned char *) s; len-- > 0; us++)
|
||||
*us = ctab[*us];
|
||||
return s;
|
||||
}
|
||||
402
bin/ed/cbc.c
402
bin/ed/cbc.c
|
|
@ -1,402 +0,0 @@
|
|||
/* cbc.c: This file contains the encryption routines for the ed line editor */
|
||||
/*-
|
||||
* Copyright (c) 1993 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Copyright (c) 1993 Andrew Moore, Talke Studio.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <pwd.h>
|
||||
#ifdef DES
|
||||
#include <time.h>
|
||||
#include <openssl/des.h>
|
||||
#define ED_DES_INCLUDES
|
||||
#endif
|
||||
|
||||
#include "ed.h"
|
||||
|
||||
|
||||
/*
|
||||
* BSD and System V systems offer special library calls that do
|
||||
* block move_liness and fills, so if possible we take advantage of them
|
||||
*/
|
||||
#define MEMCPY(dest,src,len) memcpy((dest),(src),(len))
|
||||
#define MEMZERO(dest,len) memset((dest), 0, (len))
|
||||
|
||||
/* Hide the calls to the primitive encryption routines. */
|
||||
#define DES_XFORM(buf) \
|
||||
DES_ecb_encrypt(buf, buf, &schedule, \
|
||||
inverse ? DES_DECRYPT : DES_ENCRYPT);
|
||||
|
||||
/*
|
||||
* read/write - no error checking
|
||||
*/
|
||||
#define READ(buf, n, fp) fread(buf, sizeof(char), n, fp)
|
||||
#define WRITE(buf, n, fp) fwrite(buf, sizeof(char), n, fp)
|
||||
|
||||
/*
|
||||
* global variables and related macros
|
||||
*/
|
||||
|
||||
enum { /* encrypt, decrypt, authenticate */
|
||||
MODE_ENCRYPT, MODE_DECRYPT, MODE_AUTHENTICATE
|
||||
} mode = MODE_ENCRYPT;
|
||||
|
||||
#ifdef DES
|
||||
DES_cblock ivec; /* initialization vector */
|
||||
DES_cblock pvec; /* padding vector */
|
||||
#endif
|
||||
|
||||
char bits[] = { /* used to extract bits from a char */
|
||||
'\200', '\100', '\040', '\020', '\010', '\004', '\002', '\001'
|
||||
};
|
||||
|
||||
int pflag; /* 1 to preserve parity bits */
|
||||
|
||||
#ifdef DES
|
||||
DES_key_schedule schedule; /* expanded DES key */
|
||||
#endif
|
||||
|
||||
unsigned char des_buf[8]; /* shared buffer for get_des_char/put_des_char */
|
||||
int des_ct = 0; /* count for get_des_char/put_des_char */
|
||||
int des_n = 0; /* index for put_des_char/get_des_char */
|
||||
|
||||
/* init_des_cipher: initialize DES */
|
||||
void
|
||||
init_des_cipher(void)
|
||||
{
|
||||
#ifdef DES
|
||||
int i;
|
||||
|
||||
des_ct = des_n = 0;
|
||||
|
||||
/* initialize the initialization vector */
|
||||
MEMZERO(ivec, 8);
|
||||
|
||||
/* initialize the padding vector */
|
||||
for (i = 0; i < 8; i++)
|
||||
pvec[i] = (char) (arc4random() % 256);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* get_des_char: return next char in an encrypted file */
|
||||
int
|
||||
get_des_char(FILE *fp)
|
||||
{
|
||||
#ifdef DES
|
||||
if (des_n >= des_ct) {
|
||||
des_n = 0;
|
||||
des_ct = cbc_decode(des_buf, fp);
|
||||
}
|
||||
return (des_ct > 0) ? des_buf[des_n++] : EOF;
|
||||
#else
|
||||
return (getc(fp));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* put_des_char: write a char to an encrypted file; return char written */
|
||||
int
|
||||
put_des_char(int c, FILE *fp)
|
||||
{
|
||||
#ifdef DES
|
||||
if (des_n == sizeof des_buf) {
|
||||
des_ct = cbc_encode(des_buf, des_n, fp);
|
||||
des_n = 0;
|
||||
}
|
||||
return (des_ct >= 0) ? (des_buf[des_n++] = c) : EOF;
|
||||
#else
|
||||
return (fputc(c, fp));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* flush_des_file: flush an encrypted file's output; return status */
|
||||
int
|
||||
flush_des_file(FILE *fp)
|
||||
{
|
||||
#ifdef DES
|
||||
if (des_n == sizeof des_buf) {
|
||||
des_ct = cbc_encode(des_buf, des_n, fp);
|
||||
des_n = 0;
|
||||
}
|
||||
return (des_ct >= 0 && cbc_encode(des_buf, des_n, fp) >= 0) ? 0 : EOF;
|
||||
#else
|
||||
return (fflush(fp));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DES
|
||||
/*
|
||||
* get keyword from tty or stdin
|
||||
*/
|
||||
int
|
||||
get_keyword(void)
|
||||
{
|
||||
char *p; /* used to obtain the key */
|
||||
DES_cblock msgbuf; /* I/O buffer */
|
||||
|
||||
/*
|
||||
* get the key
|
||||
*/
|
||||
if (*(p = getpass("Enter key: "))) {
|
||||
|
||||
/*
|
||||
* copy it, nul-padded, into the key area
|
||||
*/
|
||||
expand_des_key(msgbuf, p);
|
||||
MEMZERO(p, _PASSWORD_LEN);
|
||||
set_des_key(&msgbuf);
|
||||
MEMZERO(msgbuf, sizeof msgbuf);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* print a warning message and, possibly, terminate
|
||||
*/
|
||||
void
|
||||
des_error(const char *s)
|
||||
{
|
||||
errmsg = s ? s : strerror(errno);
|
||||
}
|
||||
|
||||
/*
|
||||
* map a hex character to an integer
|
||||
*/
|
||||
int
|
||||
hex_to_binary(int c, int radix)
|
||||
{
|
||||
switch(c) {
|
||||
case '0': return(0x0);
|
||||
case '1': return(0x1);
|
||||
case '2': return(radix > 2 ? 0x2 : -1);
|
||||
case '3': return(radix > 3 ? 0x3 : -1);
|
||||
case '4': return(radix > 4 ? 0x4 : -1);
|
||||
case '5': return(radix > 5 ? 0x5 : -1);
|
||||
case '6': return(radix > 6 ? 0x6 : -1);
|
||||
case '7': return(radix > 7 ? 0x7 : -1);
|
||||
case '8': return(radix > 8 ? 0x8 : -1);
|
||||
case '9': return(radix > 9 ? 0x9 : -1);
|
||||
case 'A': case 'a': return(radix > 10 ? 0xa : -1);
|
||||
case 'B': case 'b': return(radix > 11 ? 0xb : -1);
|
||||
case 'C': case 'c': return(radix > 12 ? 0xc : -1);
|
||||
case 'D': case 'd': return(radix > 13 ? 0xd : -1);
|
||||
case 'E': case 'e': return(radix > 14 ? 0xe : -1);
|
||||
case 'F': case 'f': return(radix > 15 ? 0xf : -1);
|
||||
}
|
||||
/*
|
||||
* invalid character
|
||||
*/
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* convert the key to a bit pattern
|
||||
* obuf bit pattern
|
||||
* kbuf the key itself
|
||||
*/
|
||||
void
|
||||
expand_des_key(char *obuf, char *kbuf)
|
||||
{
|
||||
int i, j; /* counter in a for loop */
|
||||
int nbuf[64]; /* used for hex/key translation */
|
||||
|
||||
/*
|
||||
* leading '0x' or '0X' == hex key
|
||||
*/
|
||||
if (kbuf[0] == '0' && (kbuf[1] == 'x' || kbuf[1] == 'X')) {
|
||||
kbuf = &kbuf[2];
|
||||
/*
|
||||
* now translate it, bombing on any illegal hex digit
|
||||
*/
|
||||
for (i = 0; kbuf[i] && i < 16; i++)
|
||||
if ((nbuf[i] = hex_to_binary((int) kbuf[i], 16)) == -1)
|
||||
des_error("bad hex digit in key");
|
||||
while (i < 16)
|
||||
nbuf[i++] = 0;
|
||||
for (i = 0; i < 8; i++)
|
||||
obuf[i] =
|
||||
((nbuf[2*i]&0xf)<<4) | (nbuf[2*i+1]&0xf);
|
||||
/* preserve parity bits */
|
||||
pflag = 1;
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* leading '0b' or '0B' == binary key
|
||||
*/
|
||||
if (kbuf[0] == '0' && (kbuf[1] == 'b' || kbuf[1] == 'B')) {
|
||||
kbuf = &kbuf[2];
|
||||
/*
|
||||
* now translate it, bombing on any illegal binary digit
|
||||
*/
|
||||
for (i = 0; kbuf[i] && i < 16; i++)
|
||||
if ((nbuf[i] = hex_to_binary((int) kbuf[i], 2)) == -1)
|
||||
des_error("bad binary digit in key");
|
||||
while (i < 64)
|
||||
nbuf[i++] = 0;
|
||||
for (i = 0; i < 8; i++)
|
||||
for (j = 0; j < 8; j++)
|
||||
obuf[i] = (obuf[i]<<1)|nbuf[8*i+j];
|
||||
/* preserve parity bits */
|
||||
pflag = 1;
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* no special leader -- ASCII
|
||||
*/
|
||||
(void)strncpy(obuf, kbuf, 8);
|
||||
}
|
||||
|
||||
/*****************
|
||||
* DES FUNCTIONS *
|
||||
*****************/
|
||||
/*
|
||||
* This sets the DES key and (if you're using the deszip version)
|
||||
* the direction of the transformation. This uses the Sun
|
||||
* to map the 64-bit key onto the 56 bits that the key schedule
|
||||
* generation routines use: the old way, which just uses the user-
|
||||
* supplied 64 bits as is, and the new way, which resets the parity
|
||||
* bit to be the same as the low-order bit in each character. The
|
||||
* new way generates a greater variety of key schedules, since many
|
||||
* systems set the parity (high) bit of each character to 0, and the
|
||||
* DES ignores the low order bit of each character.
|
||||
*/
|
||||
void
|
||||
set_des_key(DES_cblock *buf) /* key block */
|
||||
{
|
||||
int i, j; /* counter in a for loop */
|
||||
int par; /* parity counter */
|
||||
|
||||
/*
|
||||
* if the parity is not preserved, flip it
|
||||
*/
|
||||
if (!pflag) {
|
||||
for (i = 0; i < 8; i++) {
|
||||
par = 0;
|
||||
for (j = 1; j < 8; j++)
|
||||
if ((bits[j] & (*buf)[i]) != 0)
|
||||
par++;
|
||||
if ((par & 0x01) == 0x01)
|
||||
(*buf)[i] &= 0x7f;
|
||||
else
|
||||
(*buf)[i] = ((*buf)[i] & 0x7f) | 0x80;
|
||||
}
|
||||
}
|
||||
|
||||
DES_set_odd_parity(buf);
|
||||
DES_set_key(buf, &schedule);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This encrypts using the Cipher Block Chaining mode of DES
|
||||
*/
|
||||
int
|
||||
cbc_encode(unsigned char *msgbuf, int n, FILE *fp)
|
||||
{
|
||||
int inverse = 0; /* 0 to encrypt, 1 to decrypt */
|
||||
|
||||
/*
|
||||
* do the transformation
|
||||
*/
|
||||
if (n == 8) {
|
||||
for (n = 0; n < 8; n++)
|
||||
msgbuf[n] ^= ivec[n];
|
||||
DES_XFORM((DES_cblock *)msgbuf);
|
||||
MEMCPY(ivec, msgbuf, 8);
|
||||
return WRITE(msgbuf, 8, fp);
|
||||
}
|
||||
/*
|
||||
* at EOF or last block -- in either case, the last byte contains
|
||||
* the character representation of the number of bytes in it
|
||||
*/
|
||||
/*
|
||||
MEMZERO(msgbuf + n, 8 - n);
|
||||
*/
|
||||
/*
|
||||
* Pad the last block randomly
|
||||
*/
|
||||
(void)MEMCPY(msgbuf + n, pvec, 8 - n);
|
||||
msgbuf[7] = n;
|
||||
for (n = 0; n < 8; n++)
|
||||
msgbuf[n] ^= ivec[n];
|
||||
DES_XFORM((DES_cblock *)msgbuf);
|
||||
return WRITE(msgbuf, 8, fp);
|
||||
}
|
||||
|
||||
/*
|
||||
* This decrypts using the Cipher Block Chaining mode of DES
|
||||
* msgbuf I/O buffer
|
||||
* fp input file descriptor
|
||||
*/
|
||||
int
|
||||
cbc_decode(unsigned char *msgbuf, FILE *fp)
|
||||
{
|
||||
DES_cblock tbuf; /* temp buffer for initialization vector */
|
||||
int n; /* number of bytes actually read */
|
||||
int c; /* used to test for EOF */
|
||||
int inverse = 1; /* 0 to encrypt, 1 to decrypt */
|
||||
|
||||
if ((n = READ(msgbuf, 8, fp)) == 8) {
|
||||
/*
|
||||
* do the transformation
|
||||
*/
|
||||
MEMCPY(tbuf, msgbuf, 8);
|
||||
DES_XFORM((DES_cblock *)msgbuf);
|
||||
for (c = 0; c < 8; c++)
|
||||
msgbuf[c] ^= ivec[c];
|
||||
MEMCPY(ivec, tbuf, 8);
|
||||
/*
|
||||
* if the last one, handle it specially
|
||||
*/
|
||||
if ((c = fgetc(fp)) == EOF) {
|
||||
n = msgbuf[7];
|
||||
if (n < 0 || n > 7) {
|
||||
des_error("decryption failed (block corrupted)");
|
||||
return EOF;
|
||||
}
|
||||
} else
|
||||
(void)ungetc(c, fp);
|
||||
return n;
|
||||
}
|
||||
if (n > 0)
|
||||
des_error("decryption failed (incomplete block)");
|
||||
else if (n < 0)
|
||||
des_error("cannot read file");
|
||||
return EOF;
|
||||
}
|
||||
#endif /* DES */
|
||||
1005
bin/ed/ed.1
1005
bin/ed/ed.1
File diff suppressed because it is too large
Load diff
279
bin/ed/ed.h
279
bin/ed/ed.h
|
|
@ -1,279 +0,0 @@
|
|||
/* ed.h: type and constant definitions for the ed editor. */
|
||||
/*-
|
||||
* Copyright (c) 1993 Andrew Moore
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)ed.h,v 1.5 1994/02/01 00:34:39 alm Exp
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <regex.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define ERR (-2)
|
||||
#define EMOD (-3)
|
||||
#define FATAL (-4)
|
||||
|
||||
#define MINBUFSZ 512 /* minimum buffer size - must be > 0 */
|
||||
#define SE_MAX 30 /* max subexpressions in a regular expression */
|
||||
#ifdef INT_MAX
|
||||
# define LINECHARS INT_MAX /* max chars per line */
|
||||
#else
|
||||
# define LINECHARS MAXINT /* max chars per line */
|
||||
#endif
|
||||
|
||||
/* gflags */
|
||||
#define GLB 001 /* global command */
|
||||
#define GPR 002 /* print after command */
|
||||
#define GLS 004 /* list after command */
|
||||
#define GNP 010 /* enumerate after command */
|
||||
#define GSG 020 /* global substitute */
|
||||
|
||||
typedef regex_t pattern_t;
|
||||
|
||||
/* Line node */
|
||||
typedef struct line {
|
||||
struct line *q_forw;
|
||||
struct line *q_back;
|
||||
off_t seek; /* address of line in scratch buffer */
|
||||
int len; /* length of line */
|
||||
} line_t;
|
||||
|
||||
|
||||
typedef struct undo {
|
||||
|
||||
/* type of undo nodes */
|
||||
#define UADD 0
|
||||
#define UDEL 1
|
||||
#define UMOV 2
|
||||
#define VMOV 3
|
||||
|
||||
int type; /* command type */
|
||||
line_t *h; /* head of list */
|
||||
line_t *t; /* tail of list */
|
||||
} undo_t;
|
||||
|
||||
#ifndef max
|
||||
# define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
#ifndef min
|
||||
# define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#define INC_MOD(l, k) ((l) + 1 > (k) ? 0 : (l) + 1)
|
||||
#define DEC_MOD(l, k) ((l) - 1 < 0 ? (k) : (l) - 1)
|
||||
|
||||
/* SPL1: disable some interrupts (requires reliable signals) */
|
||||
#define SPL1() mutex++
|
||||
|
||||
/* SPL0: enable all interrupts; check sigflags (requires reliable signals) */
|
||||
#define SPL0() \
|
||||
if (--mutex == 0) { \
|
||||
if (sigflags & (1 << (SIGHUP - 1))) handle_hup(SIGHUP); \
|
||||
if (sigflags & (1 << (SIGINT - 1))) handle_int(SIGINT); \
|
||||
}
|
||||
|
||||
/* STRTOL: convert a string to long */
|
||||
#define STRTOL(i, p) { \
|
||||
if (((i = strtol(p, &p, 10)) == LONG_MIN || i == LONG_MAX) && \
|
||||
errno == ERANGE) { \
|
||||
errmsg = "number out of range"; \
|
||||
i = 0; \
|
||||
return ERR; \
|
||||
} \
|
||||
}
|
||||
|
||||
#if defined(sun) || defined(NO_REALLOC_NULL)
|
||||
/* REALLOC: assure at least a minimum size for buffer b */
|
||||
#define REALLOC(b,n,i,err) \
|
||||
if ((i) > (n)) { \
|
||||
int ti = (n); \
|
||||
char *ts; \
|
||||
SPL1(); \
|
||||
if ((b) != NULL) { \
|
||||
if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \
|
||||
fprintf(stderr, "%s\n", strerror(errno)); \
|
||||
errmsg = "out of memory"; \
|
||||
SPL0(); \
|
||||
return err; \
|
||||
} \
|
||||
} else { \
|
||||
if ((ts = (char *) malloc(ti += max((i), MINBUFSZ))) == NULL) { \
|
||||
fprintf(stderr, "%s\n", strerror(errno)); \
|
||||
errmsg = "out of memory"; \
|
||||
SPL0(); \
|
||||
return err; \
|
||||
} \
|
||||
} \
|
||||
(n) = ti; \
|
||||
(b) = ts; \
|
||||
SPL0(); \
|
||||
}
|
||||
#else /* NO_REALLOC_NULL */
|
||||
/* REALLOC: assure at least a minimum size for buffer b */
|
||||
#define REALLOC(b,n,i,err) \
|
||||
if ((i) > (n)) { \
|
||||
int ti = (n); \
|
||||
char *ts; \
|
||||
SPL1(); \
|
||||
if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \
|
||||
fprintf(stderr, "%s\n", strerror(errno)); \
|
||||
errmsg = "out of memory"; \
|
||||
SPL0(); \
|
||||
return err; \
|
||||
} \
|
||||
(n) = ti; \
|
||||
(b) = ts; \
|
||||
SPL0(); \
|
||||
}
|
||||
#endif /* NO_REALLOC_NULL */
|
||||
|
||||
/* REQUE: link pred before succ */
|
||||
#define REQUE(pred, succ) (pred)->q_forw = (succ), (succ)->q_back = (pred)
|
||||
|
||||
/* INSQUE: insert elem in circular queue after pred */
|
||||
#define INSQUE(elem, pred) \
|
||||
{ \
|
||||
REQUE((elem), (pred)->q_forw); \
|
||||
REQUE((pred), elem); \
|
||||
}
|
||||
|
||||
/* REMQUE: remove_lines elem from circular queue */
|
||||
#define REMQUE(elem) REQUE((elem)->q_back, (elem)->q_forw);
|
||||
|
||||
/* NUL_TO_NEWLINE: overwrite ASCII NULs with newlines */
|
||||
#define NUL_TO_NEWLINE(s, l) translit_text(s, l, '\0', '\n')
|
||||
|
||||
/* NEWLINE_TO_NUL: overwrite newlines with ASCII NULs */
|
||||
#define NEWLINE_TO_NUL(s, l) translit_text(s, l, '\n', '\0')
|
||||
|
||||
#ifdef ED_DES_INCLUDES
|
||||
void des_error(const char *);
|
||||
void expand_des_key(char *, char *);
|
||||
void set_des_key(DES_cblock *);
|
||||
#endif
|
||||
|
||||
/* Other DES support stuff */
|
||||
void init_des_cipher(void);
|
||||
int flush_des_file(FILE *);
|
||||
int get_des_char(FILE *);
|
||||
int put_des_char(int, FILE *);
|
||||
|
||||
/* Local Function Declarations */
|
||||
void add_line_node(line_t *);
|
||||
int append_lines(long);
|
||||
int apply_subst_template(const char *, regmatch_t *, int, int);
|
||||
int build_active_list(int);
|
||||
int cbc_decode(unsigned char *, FILE *);
|
||||
int cbc_encode(unsigned char *, int, FILE *);
|
||||
int check_addr_range(long, long);
|
||||
void clear_active_list(void);
|
||||
void clear_undo_stack(void);
|
||||
int close_sbuf(void);
|
||||
int copy_lines(long);
|
||||
int delete_lines(long, long);
|
||||
int display_lines(long, long, int);
|
||||
line_t *dup_line_node(line_t *);
|
||||
int exec_command(void);
|
||||
long exec_global(int, int);
|
||||
int extract_addr_range(void);
|
||||
char *extract_pattern(int);
|
||||
int extract_subst_tail(int *, long *);
|
||||
char *extract_subst_template(void);
|
||||
int filter_lines(long, long, char *);
|
||||
line_t *get_addressed_line_node(long);
|
||||
pattern_t *get_compiled_pattern(void);
|
||||
char *get_extended_line(int *, int);
|
||||
char *get_filename(void);
|
||||
int get_keyword(void);
|
||||
long get_line_node_addr(line_t *);
|
||||
long get_matching_node_addr(pattern_t *, int);
|
||||
long get_marked_node_addr(int);
|
||||
char *get_sbuf_line(line_t *);
|
||||
int get_shell_command(void);
|
||||
int get_stream_line(FILE *);
|
||||
int get_tty_line(void);
|
||||
void handle_hup(int);
|
||||
void handle_int(int);
|
||||
void handle_winch(int);
|
||||
int has_trailing_escape(char *, char *);
|
||||
int hex_to_binary(int, int);
|
||||
void init_buffers(void);
|
||||
int is_legal_filename(char *);
|
||||
int join_lines(long, long);
|
||||
int mark_line_node(line_t *, int);
|
||||
int move_lines(long);
|
||||
line_t *next_active_node(void);
|
||||
long next_addr(void);
|
||||
int open_sbuf(void);
|
||||
char *parse_char_class(char *);
|
||||
int pop_undo_stack(void);
|
||||
undo_t *push_undo_stack(int, long, long);
|
||||
const char *put_sbuf_line(const char *);
|
||||
int put_stream_line(FILE *, const char *, int);
|
||||
int put_tty_line(const char *, int, long, int);
|
||||
void quit(int);
|
||||
long read_file(char *, long);
|
||||
long read_stream(FILE *, long);
|
||||
int search_and_replace(pattern_t *, int, int);
|
||||
int set_active_node(line_t *);
|
||||
void signal_hup(int);
|
||||
void signal_int(int);
|
||||
char *strip_escapes(char *);
|
||||
int substitute_matching_text(pattern_t *, line_t *, int, int);
|
||||
char *translit_text(char *, int, int, int);
|
||||
void unmark_line_node(line_t *);
|
||||
void unset_active_nodes(line_t *, line_t *);
|
||||
long write_file(char *, const char *, long, long);
|
||||
long write_stream(FILE *, long, long);
|
||||
|
||||
/* global buffers */
|
||||
extern char stdinbuf[];
|
||||
extern char *ibuf;
|
||||
extern char *ibufp;
|
||||
extern int ibufsz;
|
||||
|
||||
/* global flags */
|
||||
extern int isbinary;
|
||||
extern int isglobal;
|
||||
extern int modified;
|
||||
extern int mutex;
|
||||
extern int sigflags;
|
||||
|
||||
/* global vars */
|
||||
extern long addr_last;
|
||||
extern long current_addr;
|
||||
extern const char *errmsg;
|
||||
extern long first_addr;
|
||||
extern int lineno;
|
||||
extern long second_addr;
|
||||
extern long u_addr_last;
|
||||
extern long u_current_addr;
|
||||
218
bin/ed/glbl.c
218
bin/ed/glbl.c
|
|
@ -1,218 +0,0 @@
|
|||
/* glob.c: This file contains the global command routines for the ed line
|
||||
editor */
|
||||
/*-
|
||||
* Copyright (c) 1993 Andrew Moore, Talke Studio.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "ed.h"
|
||||
|
||||
|
||||
/* build_active_list: add line matching a pattern to the global-active list */
|
||||
int
|
||||
build_active_list(int isgcmd)
|
||||
{
|
||||
pattern_t *pat;
|
||||
line_t *lp;
|
||||
long n;
|
||||
char *s;
|
||||
char delimiter;
|
||||
|
||||
if ((delimiter = *ibufp) == ' ' || delimiter == '\n') {
|
||||
errmsg = "invalid pattern delimiter";
|
||||
return ERR;
|
||||
} else if ((pat = get_compiled_pattern()) == NULL)
|
||||
return ERR;
|
||||
else if (*ibufp == delimiter)
|
||||
ibufp++;
|
||||
clear_active_list();
|
||||
lp = get_addressed_line_node(first_addr);
|
||||
for (n = first_addr; n <= second_addr; n++, lp = lp->q_forw) {
|
||||
if ((s = get_sbuf_line(lp)) == NULL)
|
||||
return ERR;
|
||||
if (isbinary)
|
||||
NUL_TO_NEWLINE(s, lp->len);
|
||||
if (!regexec(pat, s, 0, NULL, 0) == isgcmd &&
|
||||
set_active_node(lp) < 0)
|
||||
return ERR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* exec_global: apply command list in the command buffer to the active
|
||||
lines in a range; return command status */
|
||||
long
|
||||
exec_global(int interact, int gflag)
|
||||
{
|
||||
static char *ocmd = NULL;
|
||||
static int ocmdsz = 0;
|
||||
|
||||
line_t *lp = NULL;
|
||||
int status;
|
||||
int n;
|
||||
char *cmd = NULL;
|
||||
|
||||
#ifdef BACKWARDS
|
||||
if (!interact)
|
||||
if (!strcmp(ibufp, "\n"))
|
||||
cmd = "p\n"; /* null cmd-list == `p' */
|
||||
else if ((cmd = get_extended_line(&n, 0)) == NULL)
|
||||
return ERR;
|
||||
#else
|
||||
if (!interact && (cmd = get_extended_line(&n, 0)) == NULL)
|
||||
return ERR;
|
||||
#endif
|
||||
clear_undo_stack();
|
||||
while ((lp = next_active_node()) != NULL) {
|
||||
if ((current_addr = get_line_node_addr(lp)) < 0)
|
||||
return ERR;
|
||||
if (interact) {
|
||||
/* print current_addr; get a command in global syntax */
|
||||
if (display_lines(current_addr, current_addr, gflag) < 0)
|
||||
return ERR;
|
||||
while ((n = get_tty_line()) > 0 &&
|
||||
ibuf[n - 1] != '\n')
|
||||
clearerr(stdin);
|
||||
if (n < 0)
|
||||
return ERR;
|
||||
else if (n == 0) {
|
||||
errmsg = "unexpected end-of-file";
|
||||
return ERR;
|
||||
} else if (n == 1 && !strcmp(ibuf, "\n"))
|
||||
continue;
|
||||
else if (n == 2 && !strcmp(ibuf, "&\n")) {
|
||||
if (cmd == NULL) {
|
||||
errmsg = "no previous command";
|
||||
return ERR;
|
||||
} else cmd = ocmd;
|
||||
} else if ((cmd = get_extended_line(&n, 0)) == NULL)
|
||||
return ERR;
|
||||
else {
|
||||
REALLOC(ocmd, ocmdsz, n + 1, ERR);
|
||||
memcpy(ocmd, cmd, n + 1);
|
||||
cmd = ocmd;
|
||||
}
|
||||
|
||||
}
|
||||
ibufp = cmd;
|
||||
for (; *ibufp;)
|
||||
if ((status = extract_addr_range()) < 0 ||
|
||||
(status = exec_command()) < 0 ||
|
||||
(status > 0 && (status = display_lines(
|
||||
current_addr, current_addr, status)) < 0))
|
||||
return status;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
line_t **active_list; /* list of lines active in a global command */
|
||||
long active_last; /* index of last active line in active_list */
|
||||
long active_size; /* size of active_list */
|
||||
long active_ptr; /* active_list index (non-decreasing) */
|
||||
long active_ndx; /* active_list index (modulo active_last) */
|
||||
|
||||
/* set_active_node: add a line node to the global-active list */
|
||||
int
|
||||
set_active_node(line_t *lp)
|
||||
{
|
||||
if (active_last + 1 > active_size) {
|
||||
int ti = active_size;
|
||||
line_t **ts;
|
||||
SPL1();
|
||||
#if defined(sun) || defined(NO_REALLOC_NULL)
|
||||
if (active_list != NULL) {
|
||||
#endif
|
||||
if ((ts = (line_t **) realloc(active_list,
|
||||
(ti += MINBUFSZ) * sizeof(line_t **))) == NULL) {
|
||||
fprintf(stderr, "%s\n", strerror(errno));
|
||||
errmsg = "out of memory";
|
||||
SPL0();
|
||||
return ERR;
|
||||
}
|
||||
#if defined(sun) || defined(NO_REALLOC_NULL)
|
||||
} else {
|
||||
if ((ts = (line_t **) malloc((ti += MINBUFSZ) *
|
||||
sizeof(line_t **))) == NULL) {
|
||||
fprintf(stderr, "%s\n", strerror(errno));
|
||||
errmsg = "out of memory";
|
||||
SPL0();
|
||||
return ERR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
active_size = ti;
|
||||
active_list = ts;
|
||||
SPL0();
|
||||
}
|
||||
active_list[active_last++] = lp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* unset_active_nodes: remove a range of lines from the global-active list */
|
||||
void
|
||||
unset_active_nodes(line_t *np, line_t *mp)
|
||||
{
|
||||
line_t *lp;
|
||||
long i;
|
||||
|
||||
for (lp = np; lp != mp; lp = lp->q_forw)
|
||||
for (i = 0; i < active_last; i++)
|
||||
if (active_list[active_ndx] == lp) {
|
||||
active_list[active_ndx] = NULL;
|
||||
active_ndx = INC_MOD(active_ndx, active_last - 1);
|
||||
break;
|
||||
} else active_ndx = INC_MOD(active_ndx, active_last - 1);
|
||||
}
|
||||
|
||||
|
||||
/* next_active_node: return the next global-active line node */
|
||||
line_t *
|
||||
next_active_node(void)
|
||||
{
|
||||
while (active_ptr < active_last && active_list[active_ptr] == NULL)
|
||||
active_ptr++;
|
||||
return (active_ptr < active_last) ? active_list[active_ptr++] : NULL;
|
||||
}
|
||||
|
||||
|
||||
/* clear_active_list: clear the global-active list */
|
||||
void
|
||||
clear_active_list(void)
|
||||
{
|
||||
SPL1();
|
||||
active_size = active_last = active_ptr = active_ndx = 0;
|
||||
free(active_list);
|
||||
active_list = NULL;
|
||||
SPL0();
|
||||
}
|
||||
353
bin/ed/io.c
353
bin/ed/io.c
|
|
@ -1,353 +0,0 @@
|
|||
/* io.c: This file contains the i/o routines for the ed line editor */
|
||||
/*-
|
||||
* Copyright (c) 1993 Andrew Moore, Talke Studio.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "ed.h"
|
||||
|
||||
|
||||
extern int scripted;
|
||||
|
||||
/* read_file: read a named file/pipe into the buffer; return line count */
|
||||
long
|
||||
read_file(char *fn, long n)
|
||||
{
|
||||
FILE *fp;
|
||||
long size;
|
||||
|
||||
|
||||
fp = (*fn == '!') ? popen(fn + 1, "r") : fopen(strip_escapes(fn), "r");
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
|
||||
errmsg = "cannot open input file";
|
||||
return ERR;
|
||||
} else if ((size = read_stream(fp, n)) < 0)
|
||||
return ERR;
|
||||
else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) {
|
||||
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
|
||||
errmsg = "cannot close input file";
|
||||
return ERR;
|
||||
}
|
||||
fprintf(stdout, !scripted ? "%lu\n" : "", size);
|
||||
return current_addr - n;
|
||||
}
|
||||
|
||||
|
||||
extern int des;
|
||||
|
||||
char *sbuf; /* file i/o buffer */
|
||||
int sbufsz; /* file i/o buffer size */
|
||||
int newline_added; /* if set, newline appended to input file */
|
||||
|
||||
/* read_stream: read a stream into the editor buffer; return status */
|
||||
long
|
||||
read_stream(FILE *fp, long n)
|
||||
{
|
||||
line_t *lp = get_addressed_line_node(n);
|
||||
undo_t *up = NULL;
|
||||
unsigned long size = 0;
|
||||
int o_newline_added = newline_added;
|
||||
int o_isbinary = isbinary;
|
||||
int appended = (n == addr_last);
|
||||
int len;
|
||||
|
||||
isbinary = newline_added = 0;
|
||||
if (des)
|
||||
init_des_cipher();
|
||||
for (current_addr = n; (len = get_stream_line(fp)) > 0; size += len) {
|
||||
SPL1();
|
||||
if (put_sbuf_line(sbuf) == NULL) {
|
||||
SPL0();
|
||||
return ERR;
|
||||
}
|
||||
lp = lp->q_forw;
|
||||
if (up)
|
||||
up->t = lp;
|
||||
else if ((up = push_undo_stack(UADD, current_addr,
|
||||
current_addr)) == NULL) {
|
||||
SPL0();
|
||||
return ERR;
|
||||
}
|
||||
SPL0();
|
||||
}
|
||||
if (len < 0)
|
||||
return ERR;
|
||||
if (appended && size && o_isbinary && o_newline_added)
|
||||
fputs("newline inserted\n", stderr);
|
||||
else if (newline_added && (!appended || (!isbinary && !o_isbinary)))
|
||||
fputs("newline appended\n", stderr);
|
||||
if (isbinary && newline_added && !appended)
|
||||
size += 1;
|
||||
if (!size)
|
||||
newline_added = 1;
|
||||
newline_added = appended ? newline_added : o_newline_added;
|
||||
isbinary = isbinary | o_isbinary;
|
||||
if (des)
|
||||
size += 8 - size % 8; /* adjust DES size */
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
/* get_stream_line: read a line of text from a stream; return line length */
|
||||
int
|
||||
get_stream_line(FILE *fp)
|
||||
{
|
||||
int c;
|
||||
int i = 0;
|
||||
|
||||
while (((c = des ? get_des_char(fp) : getc(fp)) != EOF || (!feof(fp) &&
|
||||
!ferror(fp))) && c != '\n') {
|
||||
REALLOC(sbuf, sbufsz, i + 1, ERR);
|
||||
if (!(sbuf[i++] = c))
|
||||
isbinary = 1;
|
||||
}
|
||||
REALLOC(sbuf, sbufsz, i + 2, ERR);
|
||||
if (c == '\n')
|
||||
sbuf[i++] = c;
|
||||
else if (ferror(fp)) {
|
||||
fprintf(stderr, "%s\n", strerror(errno));
|
||||
errmsg = "cannot read input file";
|
||||
return ERR;
|
||||
} else if (i) {
|
||||
sbuf[i++] = '\n';
|
||||
newline_added = 1;
|
||||
}
|
||||
sbuf[i] = '\0';
|
||||
return (isbinary && newline_added && i) ? --i : i;
|
||||
}
|
||||
|
||||
|
||||
/* write_file: write a range of lines to a named file/pipe; return line count */
|
||||
long
|
||||
write_file(char *fn, const char *mode, long n, long m)
|
||||
{
|
||||
FILE *fp;
|
||||
long size;
|
||||
|
||||
fp = (*fn == '!') ? popen(fn+1, "w") : fopen(strip_escapes(fn), mode);
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
|
||||
errmsg = "cannot open output file";
|
||||
return ERR;
|
||||
} else if ((size = write_stream(fp, n, m)) < 0)
|
||||
return ERR;
|
||||
else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) {
|
||||
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
|
||||
errmsg = "cannot close output file";
|
||||
return ERR;
|
||||
}
|
||||
fprintf(stdout, !scripted ? "%lu\n" : "", size);
|
||||
return n ? m - n + 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
/* write_stream: write a range of lines to a stream; return status */
|
||||
long
|
||||
write_stream(FILE *fp, long n, long m)
|
||||
{
|
||||
line_t *lp = get_addressed_line_node(n);
|
||||
unsigned long size = 0;
|
||||
char *s;
|
||||
int len;
|
||||
|
||||
if (des)
|
||||
init_des_cipher();
|
||||
for (; n && n <= m; n++, lp = lp->q_forw) {
|
||||
if ((s = get_sbuf_line(lp)) == NULL)
|
||||
return ERR;
|
||||
len = lp->len;
|
||||
if (n != addr_last || !isbinary || !newline_added)
|
||||
s[len++] = '\n';
|
||||
if (put_stream_line(fp, s, len) < 0)
|
||||
return ERR;
|
||||
size += len;
|
||||
}
|
||||
if (des) {
|
||||
flush_des_file(fp); /* flush buffer */
|
||||
size += 8 - size % 8; /* adjust DES size */
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
/* put_stream_line: write a line of text to a stream; return status */
|
||||
int
|
||||
put_stream_line(FILE *fp, const char *s, int len)
|
||||
{
|
||||
while (len--)
|
||||
if ((des ? put_des_char(*s++, fp) : fputc(*s++, fp)) < 0) {
|
||||
fprintf(stderr, "%s\n", strerror(errno));
|
||||
errmsg = "cannot write file";
|
||||
return ERR;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get_extended_line: get an extended line from stdin */
|
||||
char *
|
||||
get_extended_line(int *sizep, int nonl)
|
||||
{
|
||||
static char *cvbuf = NULL; /* buffer */
|
||||
static int cvbufsz = 0; /* buffer size */
|
||||
|
||||
int l, n;
|
||||
char *t = ibufp;
|
||||
|
||||
while (*t++ != '\n')
|
||||
;
|
||||
if ((l = t - ibufp) < 2 || !has_trailing_escape(ibufp, ibufp + l - 1)) {
|
||||
*sizep = l;
|
||||
return ibufp;
|
||||
}
|
||||
*sizep = -1;
|
||||
REALLOC(cvbuf, cvbufsz, l, NULL);
|
||||
memcpy(cvbuf, ibufp, l);
|
||||
*(cvbuf + --l - 1) = '\n'; /* strip trailing esc */
|
||||
if (nonl) l--; /* strip newline */
|
||||
for (;;) {
|
||||
if ((n = get_tty_line()) < 0)
|
||||
return NULL;
|
||||
else if (n == 0 || ibuf[n - 1] != '\n') {
|
||||
errmsg = "unexpected end-of-file";
|
||||
return NULL;
|
||||
}
|
||||
REALLOC(cvbuf, cvbufsz, l + n, NULL);
|
||||
memcpy(cvbuf + l, ibuf, n);
|
||||
l += n;
|
||||
if (n < 2 || !has_trailing_escape(cvbuf, cvbuf + l - 1))
|
||||
break;
|
||||
*(cvbuf + --l - 1) = '\n'; /* strip trailing esc */
|
||||
if (nonl) l--; /* strip newline */
|
||||
}
|
||||
REALLOC(cvbuf, cvbufsz, l + 1, NULL);
|
||||
cvbuf[l] = '\0';
|
||||
*sizep = l;
|
||||
return cvbuf;
|
||||
}
|
||||
|
||||
|
||||
/* get_tty_line: read a line of text from stdin; return line length */
|
||||
int
|
||||
get_tty_line(void)
|
||||
{
|
||||
int oi = 0;
|
||||
int i = 0;
|
||||
int c;
|
||||
|
||||
for (;;)
|
||||
switch (c = getchar()) {
|
||||
default:
|
||||
oi = 0;
|
||||
REALLOC(ibuf, ibufsz, i + 2, ERR);
|
||||
if (!(ibuf[i++] = c)) isbinary = 1;
|
||||
if (c != '\n')
|
||||
continue;
|
||||
lineno++;
|
||||
ibuf[i] = '\0';
|
||||
ibufp = ibuf;
|
||||
return i;
|
||||
case EOF:
|
||||
if (ferror(stdin)) {
|
||||
fprintf(stderr, "stdin: %s\n", strerror(errno));
|
||||
errmsg = "cannot read stdin";
|
||||
clearerr(stdin);
|
||||
ibufp = NULL;
|
||||
return ERR;
|
||||
} else {
|
||||
clearerr(stdin);
|
||||
if (i != oi) {
|
||||
oi = i;
|
||||
continue;
|
||||
} else if (i)
|
||||
ibuf[i] = '\0';
|
||||
ibufp = ibuf;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define ESCAPES "\a\b\f\n\r\t\v\\"
|
||||
#define ESCCHARS "abfnrtv\\"
|
||||
|
||||
extern int rows;
|
||||
extern int cols;
|
||||
|
||||
/* put_tty_line: print text to stdout */
|
||||
int
|
||||
put_tty_line(const char *s, int l, long n, int gflag)
|
||||
{
|
||||
int col = 0;
|
||||
int lc = 0;
|
||||
char *cp;
|
||||
|
||||
if (gflag & GNP) {
|
||||
printf("%ld\t", n);
|
||||
col = 8;
|
||||
}
|
||||
for (; l--; s++) {
|
||||
if ((gflag & GLS) && ++col > cols) {
|
||||
fputs("\\\n", stdout);
|
||||
col = 1;
|
||||
#ifndef BACKWARDS
|
||||
if (!scripted && !isglobal && ++lc > rows) {
|
||||
lc = 0;
|
||||
fputs("Press <RETURN> to continue... ", stdout);
|
||||
fflush(stdout);
|
||||
if (get_tty_line() < 0)
|
||||
return ERR;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (gflag & GLS) {
|
||||
if (31 < *s && *s < 127 && *s != '\\')
|
||||
putchar(*s);
|
||||
else {
|
||||
putchar('\\');
|
||||
col++;
|
||||
if (*s && (cp = strchr(ESCAPES, *s)) != NULL)
|
||||
putchar(ESCCHARS[cp - ESCAPES]);
|
||||
else {
|
||||
putchar((((unsigned char) *s & 0300) >> 6) + '0');
|
||||
putchar((((unsigned char) *s & 070) >> 3) + '0');
|
||||
putchar(((unsigned char) *s & 07) + '0');
|
||||
col += 2;
|
||||
}
|
||||
}
|
||||
|
||||
} else
|
||||
putchar(*s);
|
||||
}
|
||||
#ifndef BACKWARDS
|
||||
if (gflag & GLS)
|
||||
putchar('$');
|
||||
#endif
|
||||
putchar('\n');
|
||||
return 0;
|
||||
}
|
||||
1416
bin/ed/main.c
1416
bin/ed/main.c
File diff suppressed because it is too large
Load diff
132
bin/ed/re.c
132
bin/ed/re.c
|
|
@ -1,132 +0,0 @@
|
|||
/* re.c: This file contains the regular expression interface routines for
|
||||
the ed line editor. */
|
||||
/*-
|
||||
* Copyright (c) 1993 Andrew Moore, Talke Studio.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "ed.h"
|
||||
|
||||
|
||||
extern int patlock;
|
||||
|
||||
const char *errmsg = "";
|
||||
|
||||
/* get_compiled_pattern: return pointer to compiled pattern from command
|
||||
buffer */
|
||||
pattern_t *
|
||||
get_compiled_pattern(void)
|
||||
{
|
||||
static pattern_t *expr = NULL;
|
||||
static char error[1024];
|
||||
|
||||
char *exprs;
|
||||
char delimiter;
|
||||
int n;
|
||||
|
||||
if ((delimiter = *ibufp) == ' ') {
|
||||
errmsg = "invalid pattern delimiter";
|
||||
return NULL;
|
||||
} else if (delimiter == '\n' || *++ibufp == '\n' || *ibufp == delimiter) {
|
||||
if (!expr)
|
||||
errmsg = "no previous pattern";
|
||||
return expr;
|
||||
} else if ((exprs = extract_pattern(delimiter)) == NULL)
|
||||
return NULL;
|
||||
/* buffer alloc'd && not reserved */
|
||||
if (expr && !patlock)
|
||||
regfree(expr);
|
||||
else if ((expr = (pattern_t *) malloc(sizeof(pattern_t))) == NULL) {
|
||||
fprintf(stderr, "%s\n", strerror(errno));
|
||||
errmsg = "out of memory";
|
||||
return NULL;
|
||||
}
|
||||
patlock = 0;
|
||||
if ((n = regcomp(expr, exprs, 0))) {
|
||||
regerror(n, expr, error, sizeof error);
|
||||
errmsg = error;
|
||||
free(expr);
|
||||
return expr = NULL;
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
|
||||
/* extract_pattern: copy a pattern string from the command buffer; return
|
||||
pointer to the copy */
|
||||
char *
|
||||
extract_pattern(int delimiter)
|
||||
{
|
||||
static char *lhbuf = NULL; /* buffer */
|
||||
static int lhbufsz = 0; /* buffer size */
|
||||
|
||||
char *nd;
|
||||
int len;
|
||||
|
||||
for (nd = ibufp; *nd != delimiter && *nd != '\n'; nd++)
|
||||
switch (*nd) {
|
||||
default:
|
||||
break;
|
||||
case '[':
|
||||
if ((nd = parse_char_class(++nd)) == NULL) {
|
||||
errmsg = "unbalanced brackets ([])";
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
case '\\':
|
||||
if (*++nd == '\n') {
|
||||
errmsg = "trailing backslash (\\)";
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
len = nd - ibufp;
|
||||
REALLOC(lhbuf, lhbufsz, len + 1, NULL);
|
||||
memcpy(lhbuf, ibufp, len);
|
||||
lhbuf[len] = '\0';
|
||||
ibufp = nd;
|
||||
return (isbinary) ? NUL_TO_NEWLINE(lhbuf, len) : lhbuf;
|
||||
}
|
||||
|
||||
|
||||
/* parse_char_class: expand a POSIX character class */
|
||||
char *
|
||||
parse_char_class(char *s)
|
||||
{
|
||||
int c, d;
|
||||
|
||||
if (*s == '^')
|
||||
s++;
|
||||
if (*s == ']')
|
||||
s++;
|
||||
for (; *s != ']' && *s != '\n'; s++)
|
||||
if (*s == '[' && ((d = *(s+1)) == '.' || d == ':' || d == '='))
|
||||
for (s++, c = *++s; *s != ']' || c != d; s++)
|
||||
if ((c = *s) == '\n')
|
||||
return NULL;
|
||||
return (*s == ']') ? s : NULL;
|
||||
}
|
||||
254
bin/ed/sub.c
254
bin/ed/sub.c
|
|
@ -1,254 +0,0 @@
|
|||
/* sub.c: This file contains the substitution routines for the ed
|
||||
line editor */
|
||||
/*-
|
||||
* Copyright (c) 1993 Andrew Moore, Talke Studio.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "ed.h"
|
||||
|
||||
|
||||
char *rhbuf; /* rhs substitution buffer */
|
||||
int rhbufsz; /* rhs substitution buffer size */
|
||||
int rhbufi; /* rhs substitution buffer index */
|
||||
|
||||
/* extract_subst_tail: extract substitution tail from the command buffer */
|
||||
int
|
||||
extract_subst_tail(int *flagp, long *np)
|
||||
{
|
||||
char delimiter;
|
||||
|
||||
*flagp = *np = 0;
|
||||
if ((delimiter = *ibufp) == '\n') {
|
||||
rhbufi = 0;
|
||||
*flagp = GPR;
|
||||
return 0;
|
||||
} else if (extract_subst_template() == NULL)
|
||||
return ERR;
|
||||
else if (*ibufp == '\n') {
|
||||
*flagp = GPR;
|
||||
return 0;
|
||||
} else if (*ibufp == delimiter)
|
||||
ibufp++;
|
||||
if ('1' <= *ibufp && *ibufp <= '9') {
|
||||
STRTOL(*np, ibufp);
|
||||
return 0;
|
||||
} else if (*ibufp == 'g') {
|
||||
ibufp++;
|
||||
*flagp = GSG;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* extract_subst_template: return pointer to copy of substitution template
|
||||
in the command buffer */
|
||||
char *
|
||||
extract_subst_template(void)
|
||||
{
|
||||
int n = 0;
|
||||
int i = 0;
|
||||
char c;
|
||||
char delimiter = *ibufp++;
|
||||
|
||||
if (*ibufp == '%' && *(ibufp + 1) == delimiter) {
|
||||
ibufp++;
|
||||
if (!rhbuf)
|
||||
errmsg = "no previous substitution";
|
||||
return rhbuf;
|
||||
}
|
||||
while (*ibufp != delimiter) {
|
||||
REALLOC(rhbuf, rhbufsz, i + 2, NULL);
|
||||
if ((c = rhbuf[i++] = *ibufp++) == '\n' && *ibufp == '\0') {
|
||||
i--, ibufp--;
|
||||
break;
|
||||
} else if (c != '\\')
|
||||
;
|
||||
else if ((rhbuf[i++] = *ibufp++) != '\n')
|
||||
;
|
||||
else if (!isglobal) {
|
||||
while ((n = get_tty_line()) == 0 ||
|
||||
(n > 0 && ibuf[n - 1] != '\n'))
|
||||
clearerr(stdin);
|
||||
if (n < 0)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
REALLOC(rhbuf, rhbufsz, i + 1, NULL);
|
||||
rhbuf[rhbufi = i] = '\0';
|
||||
return rhbuf;
|
||||
}
|
||||
|
||||
|
||||
char *rbuf; /* substitute_matching_text buffer */
|
||||
int rbufsz; /* substitute_matching_text buffer size */
|
||||
|
||||
/* search_and_replace: for each line in a range, change text matching a pattern
|
||||
according to a substitution template; return status */
|
||||
int
|
||||
search_and_replace(pattern_t *pat, int gflag, int kth)
|
||||
{
|
||||
undo_t *up;
|
||||
const char *txt;
|
||||
const char *eot;
|
||||
long lc;
|
||||
long xa = current_addr;
|
||||
int nsubs = 0;
|
||||
line_t *lp;
|
||||
int len;
|
||||
|
||||
current_addr = first_addr - 1;
|
||||
for (lc = 0; lc <= second_addr - first_addr; lc++) {
|
||||
lp = get_addressed_line_node(++current_addr);
|
||||
if ((len = substitute_matching_text(pat, lp, gflag, kth)) < 0)
|
||||
return ERR;
|
||||
else if (len) {
|
||||
up = NULL;
|
||||
if (delete_lines(current_addr, current_addr) < 0)
|
||||
return ERR;
|
||||
txt = rbuf;
|
||||
eot = rbuf + len;
|
||||
SPL1();
|
||||
do {
|
||||
if ((txt = put_sbuf_line(txt)) == NULL) {
|
||||
SPL0();
|
||||
return ERR;
|
||||
} else if (up)
|
||||
up->t = get_addressed_line_node(current_addr);
|
||||
else if ((up = push_undo_stack(UADD,
|
||||
current_addr, current_addr)) == NULL) {
|
||||
SPL0();
|
||||
return ERR;
|
||||
}
|
||||
} while (txt != eot);
|
||||
SPL0();
|
||||
nsubs++;
|
||||
xa = current_addr;
|
||||
}
|
||||
}
|
||||
current_addr = xa;
|
||||
if (nsubs == 0 && !(gflag & GLB)) {
|
||||
errmsg = "no match";
|
||||
return ERR;
|
||||
} else if ((gflag & (GPR | GLS | GNP)) &&
|
||||
display_lines(current_addr, current_addr, gflag) < 0)
|
||||
return ERR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* substitute_matching_text: replace text matched by a pattern according to
|
||||
a substitution template; return pointer to the modified text */
|
||||
int
|
||||
substitute_matching_text(pattern_t *pat, line_t *lp, int gflag, int kth)
|
||||
{
|
||||
int off = 0;
|
||||
int changed = 0;
|
||||
int matchno = 0;
|
||||
int i = 0;
|
||||
regmatch_t rm[SE_MAX];
|
||||
char *txt;
|
||||
char *eot;
|
||||
|
||||
if ((txt = get_sbuf_line(lp)) == NULL)
|
||||
return ERR;
|
||||
if (isbinary)
|
||||
NUL_TO_NEWLINE(txt, lp->len);
|
||||
eot = txt + lp->len;
|
||||
if (!regexec(pat, txt, SE_MAX, rm, 0)) {
|
||||
do {
|
||||
if (!kth || kth == ++matchno) {
|
||||
changed++;
|
||||
i = rm[0].rm_so;
|
||||
REALLOC(rbuf, rbufsz, off + i, ERR);
|
||||
if (isbinary)
|
||||
NEWLINE_TO_NUL(txt, rm[0].rm_eo);
|
||||
memcpy(rbuf + off, txt, i);
|
||||
off += i;
|
||||
if ((off = apply_subst_template(txt, rm, off,
|
||||
pat->re_nsub)) < 0)
|
||||
return ERR;
|
||||
} else {
|
||||
i = rm[0].rm_eo;
|
||||
REALLOC(rbuf, rbufsz, off + i, ERR);
|
||||
if (isbinary)
|
||||
NEWLINE_TO_NUL(txt, i);
|
||||
memcpy(rbuf + off, txt, i);
|
||||
off += i;
|
||||
}
|
||||
txt += rm[0].rm_eo;
|
||||
} while (*txt &&
|
||||
(!changed || ((gflag & GSG) && rm[0].rm_eo)) &&
|
||||
!regexec(pat, txt, SE_MAX, rm, REG_NOTBOL));
|
||||
i = eot - txt;
|
||||
REALLOC(rbuf, rbufsz, off + i + 2, ERR);
|
||||
if (i > 0 && !rm[0].rm_eo && (gflag & GSG)) {
|
||||
errmsg = "infinite substitution loop";
|
||||
return ERR;
|
||||
}
|
||||
if (isbinary)
|
||||
NEWLINE_TO_NUL(txt, i);
|
||||
memcpy(rbuf + off, txt, i);
|
||||
memcpy(rbuf + off + i, "\n", 2);
|
||||
}
|
||||
return changed ? off + i + 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
/* apply_subst_template: modify text according to a substitution template;
|
||||
return offset to end of modified text */
|
||||
int
|
||||
apply_subst_template(const char *boln, regmatch_t *rm, int off, int re_nsub)
|
||||
{
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
int n;
|
||||
char *sub = rhbuf;
|
||||
|
||||
for (; sub - rhbuf < rhbufi; sub++)
|
||||
if (*sub == '&') {
|
||||
j = rm[0].rm_so;
|
||||
k = rm[0].rm_eo;
|
||||
REALLOC(rbuf, rbufsz, off + k - j, ERR);
|
||||
while (j < k)
|
||||
rbuf[off++] = boln[j++];
|
||||
} else if (*sub == '\\' && '1' <= *++sub && *sub <= '9' &&
|
||||
(n = *sub - '0') <= re_nsub) {
|
||||
j = rm[n].rm_so;
|
||||
k = rm[n].rm_eo;
|
||||
REALLOC(rbuf, rbufsz, off + k - j, ERR);
|
||||
while (j < k)
|
||||
rbuf[off++] = boln[j++];
|
||||
} else {
|
||||
REALLOC(rbuf, rbufsz, off + 1, ERR);
|
||||
rbuf[off++] = *sub;
|
||||
}
|
||||
REALLOC(rbuf, rbufsz, off + 1, ERR);
|
||||
rbuf[off] = '\0';
|
||||
return off;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
1,$=
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
# $FreeBSD$
|
||||
|
||||
SHELL= /bin/sh
|
||||
ED= ${.OBJDIR}/ed
|
||||
|
||||
all: check
|
||||
@:
|
||||
|
||||
check: build test
|
||||
@if grep -h '\*\*\*' errs.o scripts.o; then :; else \
|
||||
echo "tests completed successfully."; \
|
||||
fi
|
||||
|
||||
build: mkscripts.sh
|
||||
@if [ -f errs.o ]; then :; else \
|
||||
uudecode < ascii.d.uu ; \
|
||||
uudecode < ascii.r.uu ; \
|
||||
echo "building test scripts for $(ED) ..."; \
|
||||
$(SHELL) mkscripts.sh $(ED); \
|
||||
fi
|
||||
|
||||
test: build ckscripts.sh
|
||||
@echo testing $(ED) ...
|
||||
@$(SHELL) ckscripts.sh $(ED)
|
||||
|
||||
clean:
|
||||
rm -f *.ed *.red *.[oz] *~ ascii.d ascii.r
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
# $FreeBSD$
|
||||
|
||||
The files in this directory with suffixes `.t', `.d', `.r' and `.err' are
|
||||
used for testing ed. To run the tests, set the ED variable in the Makefile
|
||||
for the path name of the program to be tested (e.g., /bin/ed), and type
|
||||
`make'. The tests do not exhaustively verify POSIX compliance nor do
|
||||
they verify correct 8-bit or long line support.
|
||||
|
||||
The test file suffixes have the following meanings:
|
||||
.t Template - a list of ed commands from which an ed script is
|
||||
constructed
|
||||
.d Data - read by an ed script
|
||||
.r Result - the expected output after processing data via an ed
|
||||
script.
|
||||
.err Error - invalid ed commands that should generate an error
|
||||
|
||||
The output of the tests is written to the two files err.o and scripts.o.
|
||||
At the end of the tests, these files are grep'ed for error messages,
|
||||
which look like:
|
||||
*** The script u.ed exited abnormally ***
|
||||
or:
|
||||
*** Output u.o of script u.ed is incorrect ***
|
||||
|
||||
The POSIX requirement that an address range not be used where at most
|
||||
a single address is expected has been relaxed in this version of ed.
|
||||
Therefore, the following scripts which test for compliance with this
|
||||
POSIX rule exit abnormally:
|
||||
=-err.ed
|
||||
a1-err.ed
|
||||
i1-err.ed
|
||||
k1-err.ed
|
||||
r1-err.ed
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
Some missing tests:
|
||||
0) g/./s^@^@ - okay: NULs in commands
|
||||
1) g/./s/^@/ - okay: NULs in patterns
|
||||
2) a
|
||||
hello^V^Jworld
|
||||
. - okay: embedded newlines in insert mode
|
||||
3) ed "" - error: invalid filename
|
||||
4) red .. - error: restricted
|
||||
5) red / - error: restricted
|
||||
5) red !xx - error: restricted
|
||||
6) ed -x - verify: 8-bit clean
|
||||
7) ed - verify: long-line support
|
||||
8) ed - verify: interactive/help mode
|
||||
9) G/pat/ - verify: global interactive command
|
||||
10) V/pat/ - verify: global interactive command
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
line 1
|
||||
line 2
|
||||
line 3
|
||||
line 4
|
||||
line5
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue