*BSD News Article 43840


Return to BSD News archive

Newsgroups: comp.bugs.2bsd
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!yarrina.connect.com.au!classic.iinet.com.au!news.uoknor.edu!news.ecn.uoknor.edu!paladin.american.edu!europa.chnt.gtegsc.com!wlbr!sms
From: sms@wlv.iipo.gtegsc.com (Steven M. Schultz)
Subject: printf(1) [new] and update(8) [replacement] (#239)
Sender: news@wlbr.iipo.gtegsc.com (System Administrator)
Organization: GTE Government Systems, Westlake Village
Message-ID: <D8ALoJ.Fq8@wlbr.iipo.gtegsc.com>
X-Nntp-Posting-Host: wlv.iipo.gtegsc.com
Date: Tue, 9 May 1995 03:57:55 GMT
Lines: 1074

Subject: printf(1) [new] and update(8) [replacement] (#239)
Index:	usr.bin/printf,etc/update.c 2.11BSD

Description:
	The printf program was ported from 4.4BSD-Lite.  This program is
	useful for doing formatted I/O in shell scripts and Makefiles.

	A new update(8) was ported from 4.4BSD-Lite.  This version uses
	several less file and inode kernel resources by not opening 5 or
	6 directories.  Also the new version will disassociate from the 
	terminal and place itself in the background (unlike the older
	version).

Repeat-By:
	Observation.

Fix:
	The printf(1) program will be used soon (it is being tested now)
	to generate the system call entries in libc.a (the directory
	/usr/src/lib/libc/pdp/sys has been reduced from 118 files to 15 files
	on the system here, saving 100kb of disc space in the process).

	In a previous patch (#233) a backslash was accidentally omitted
	from a Makefile.  The /usr/src/bin Makefile is fixed is this 
	patch.  If you have already added the \ then ignore the warning
	produced when applying the patch below.

	To install the new programs you will have to move the existing
	update.c program aside (because shar will not overwrite an 
	existing file):

		mv /usr/src/etc/update.c /usr/src/etc/update.c.old

	Cut where indicated below and save to a /tmp file (/tmp/foo).  Then:

		sh /tmp/foo
		patch -p0 < /tmp/patch.239
		sh /tmp/printf.shar
		sh /tmp/update.shar

	To install the new programs:

		cd /usr/src/usr.bin/printf
		make
		make install
		make clean

		cd /usr/src/etc
		make update
		install -m 700 -s update /etc/update

	You may wish to kill the currently running update program and
	restart /etc/update.  To see the savings in file and inodes used
	do a "pstat -T" before killing the old one and after starting the
	new update program.

	As always the updates to 2.11BSD are available via anonymous
	FTP to the system FTP.IIPO.GTEGSC.COM in the directory /pub/2.11BSD.

==============================cut here=====================
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	/tmp/patch.239
#	/tmp/printf.shar
#	/tmp/update.shar
# This archive created: Mon May  8 20:33:14 1995
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f '/tmp/patch.239'
then
	echo shar: "will not over-write existing file '/tmp/patch.239'"
else
sed 's/^Y//' << \SHAR_EOF > '/tmp/patch.239'
Y*** /usr/include/paths.h.old	Sat Apr  1 22:38:07 1995
Y--- /usr/include/paths.h	Mon Apr 10 22:10:57 1995
Y***************
Y*** 14,20 ****
Y   * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
Y   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Y   *
Y!  *	@(#)pathnames.h	5.3.3 (2.11BSD) 1995/04/01
Y   */
Y  
Y  #define	_PATH_BSHELL	"/bin/sh"
Y--- 14,20 ----
Y   * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
Y   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Y   *
Y!  *	@(#)pathnames.h	5.3.4 (2.11BSD) 1995/04/10
Y   */
Y  
Y  #define	_PATH_BSHELL	"/bin/sh"
Y***************
Y*** 21,26 ****
Y--- 21,27 ----
Y  #define	_PATH_CSHELL	"/bin/csh"
Y  #define	_PATH_CP	"/bin/cp"
Y  #define	_PATH_RSH	"/usr/ucb/rsh"
Y+ #define	_PATH_VI	"/usr/ucb/vi"
Y  #define	_PATH_CONSOLE	"/dev/console"
Y  #define	_PATH_DEVNULL	"/dev/null"
Y  #define	_PATH_TTY	"/dev/tty"
Y*** /usr/src/usr.bin/Makefile.old	Sat Feb  4 23:34:23 1995
Y--- /usr/src/usr.bin/Makefile	Tue May  2 23:50:19 1995
Y***************
Y*** 1,4 ****
Y! #	Makefile	4.39.1.2	95/02/4
Y  #
Y  DESTDIR=
Y  CFLAGS=	-O
Y--- 1,4 ----
Y! #	Makefile	1.1 (2.11BSD GTE) 1995/05/02
Y  #
Y  DESTDIR=
Y  CFLAGS=	-O
Y***************
Y*** 7,14 ****
Y  # Programs that live in subdirectories, and have makefiles of their own.
Y  #
Y  SUBDIR=	at calendar dc diction diff3 eqn f77 find graph learn lex lint \
Y! 	m4 neqn plot prof ranlib ratfor refer roff spell struct tbl tip uucp \
Y! 	uname yacc
Y  
Y  # Shell scripts that need only be installed and are never removed.
Y  #
Y--- 7,14 ----
Y  # Programs that live in subdirectories, and have makefiles of their own.
Y  #
Y  SUBDIR=	at calendar dc diction diff3 eqn f77 find graph learn lex lint \
Y! 	m4 neqn plot printf prof ranlib ratfor refer roff spell struct tbl \
Y! 	tip uucp uname yacc
Y  
Y  # Shell scripts that need only be installed and are never removed.
Y  #
Y*** /usr/src/bin/Makefile.old	Mon Mar 13 20:42:49 1995
Y--- /usr/src/bin/Makefile	Tue May  2 23:39:43 1995
Y***************
Y*** 3,9 ****
Y  # All rights reserved.  The Berkeley software License Agreement
Y  # specifies the terms and conditions for redistribution.
Y  #
Y! #	@(#)Makefile	5.19.5 (2.11BSD GTE) 1995/03/13
Y  #
Y  DESTDIR=
Y  CFLAGS=	-O
Y--- 3,9 ----
Y  # All rights reserved.  The Berkeley software License Agreement
Y  # specifies the terms and conditions for redistribution.
Y  #
Y! #	@(#)Makefile	5.19.6 (2.11BSD GTE) 1995/05/02
Y  #
Y  DESTDIR=
Y  CFLAGS=	-O
Y***************
Y*** 11,17 ****
Y  
Y  # Programs that live in subdirectories, and have makefiles of their own.
Y  #
Y! SUBDIR=	adb ar as awk chflags chpass csh diff hostname ld login ls make nm 
Y  	passwd sed sh sysctl test tp
Y  
Y  # Shell scripts that need only be installed and are never removed.
Y--- 11,17 ----
Y  
Y  # Programs that live in subdirectories, and have makefiles of their own.
Y  #
Y! SUBDIR=	adb ar as awk chflags chpass csh diff hostname ld login ls make nm \
Y  	passwd sed sh sysctl test tp
Y  
Y  # Shell scripts that need only be installed and are never removed.
Y*** /VERSION.old	Tue Apr 25 19:36:58 1995
Y--- /VERSION	Sat May  6 21:59:31 1995
Y***************
Y*** 1,4 ****
Y! Current Patch Level: 237
Y  
Y  2.11 BSD
Y  ============
Y--- 1,4 ----
Y! Current Patch Level: 239
Y  
Y  2.11 BSD
Y  ============
SHAR_EOF
fi
if test -f '/tmp/printf.shar'
then
	echo shar: "will not over-write existing file '/tmp/printf.shar'"
else
sed 's/^Y//' << \SHAR_EOF > '/tmp/printf.shar'
Y#! /bin/sh
Y# This is a shell archive, meaning:
Y# 1. Remove everything above the #! /bin/sh line.
Y# 2. Save the resulting text in a file.
Y# 3. Execute the file with /bin/sh (not csh) to create:
Y#	/usr/src/usr.bin/printf
Y# This archive created: Mon May  8 20:09:53 1995
Yexport PATH; PATH=/bin:/usr/bin:$PATH
Yif test ! -d '/usr/src/usr.bin/printf'
Ythen
Y	mkdir '/usr/src/usr.bin/printf'
Yfi
Ycd '/usr/src/usr.bin/printf'
Yif test -f 'printf.c'
Ythen
Y	echo shar: "will not over-write existing file 'printf.c'"
Yelse
Ysed 's/^X//' << \SHAR_EOF > 'printf.c'
YX/*
YX * Copyright (c) 1989, 1993
YX *	The Regents of the University of California.  All rights reserved.
YX *
YX * Redistribution and use in source and binary forms, with or without
YX * modification, are permitted provided that the following conditions
YX * are met:
YX * 1. Redistributions of source code must retain the above copyright
YX *    notice, this list of conditions and the following disclaimer.
YX * 2. Redistributions in binary form must reproduce the above copyright
YX *    notice, this list of conditions and the following disclaimer in the
YX *    documentation and/or other materials provided with the distribution.
YX * 3. All advertising materials mentioning features or use of this software
YX *    must display the following acknowledgement:
YX *	This product includes software developed by the University of
YX *	California, Berkeley and its contributors.
YX * 4. Neither the name of the University nor the names of its contributors
YX *    may be used to endorse or promote products derived from this software
YX *    without specific prior written permission.
YX *
YX * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
YX * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
YX * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
YX * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
YX * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
YX * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
YX * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
YX * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
YX * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
YX * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
YX * SUCH DAMAGE.
YX */
YX
YX#if !defined(BUILTIN) && !defined(SHELL) && !defined(lint) && defined(DOSCCS)
YXstatic char copyright[] =
YX"@(#) Copyright (c) 1989, 1993\n\
YX	The Regents of the University of California.  All rights reserved.\n";
YX
YXstatic char sccsid[] = "@(#)printf.c	8.1 (Berkeley) 7/20/93";
YX#endif /* not lint */
YX
YX#include <sys/types.h>
YX
YX#include <errno.h>
YX#ifdef SHELL
YX#define	EOF	-1
YX#else
YX#include <stdio.h>
YX#endif
YX#include <string.h>
YX
YXextern	double	atof();
YXextern	long	strtol();
YXextern	int	errno;
YX
YX/*
YX * XXX
YX * This *has* to go away.  TK.
YX */
YX#ifdef SHELL
YX#define main printfcmd
YX#define warnx(a, b, c) {						\
YX	char buf[64];							\
YX	(void)sprintf(buf, sizeof(buf), a, b, c);			\
YX	error(buf);							\
YX}
YX#include "../../bin/sh/bltin/bltin.h"
YX#endif
YX
YX#define PF(f, func) { \
YX	if (fieldwidth) \
YX		if (precision) \
YX			(void)printf(f, fieldwidth, precision, func); \
YX		else \
YX			(void)printf(f, fieldwidth, func); \
YX	else if (precision) \
YX		(void)printf(f, precision, func); \
YX	else \
YX		(void)printf(f, func); \
YX}
YX
YXstatic int	 asciicode();
YXstatic void	 escape();
YXstatic int	 getchr();
YXstatic double	 getdouble();
YXstatic int	 getint();
YXstatic int	 getlong();
YXstatic char	*getstr();
YXstatic char	*mklong();
YXstatic void	 usage();
YX
YXstatic char **gargv;
YX
YXint
YX#ifdef BUILTIN
YXprogprintf(argc, argv)
YX#else
YXmain(argc, argv)
YX#endif
YX	int argc;
YX	char *argv[];
YX{
YX	extern int optind;
YX	static char *skip1, *skip2;
YX	int ch, end, fieldwidth, precision;
YX	char convch, nextch, *format, *start;
YX	register char *fmt;
YX
YX	while ((ch = getopt(argc, argv, "")) != EOF)
YX		switch (ch) {
YX		case '?':
YX		default:
YX			usage();
YX			return (1);
YX		}
YX	argc -= optind;
YX	argv += optind;
YX
YX	if (argc < 1) {
YX		usage();
YX		return (1);
YX	}
YX
YX	/*
YX	 * Basic algorithm is to scan the format string for conversion
YX	 * specifications -- once one is found, find out if the field
YX	 * width or precision is a '*'; if it is, gather up value.  Note,
YX	 * format strings are reused as necessary to use up the provided
YX	 * arguments, arguments of zero/null string are provided to use
YX	 * up the format string.
YX	 */
YX	skip1 = "#-+ 0";
YX	skip2 = "*0123456789";
YX
YX	escape(fmt = format = *argv);		/* backslash interpretation */
YX	gargv = ++argv;
YX	for (;;) {
YX		end = 0;
YX		/* find next format specification */
YXnext:		for (start = fmt;; ++fmt) {
YX			if (!*fmt) {
YX				/* avoid infinite loop */
YX				if (end == 1) {
YX					warnx("missing format character",
YX					    NULL, NULL);
YX					return (1);
YX				}
YX				end = 1;
YX				if (fmt > start)
YX					(void)printf("%s", start);
YX				if (!*gargv)
YX					return (0);
YX				fmt = format;
YX				goto next;
YX			}
YX			/* %% prints a % */
YX			if (*fmt == '%') {
YX				if (*++fmt != '%')
YX					break;
YX				*fmt++ = '\0';
YX				(void)printf("%s", start);
YX				goto next;
YX			}
YX		}
YX
YX		/* skip to field width */
YX		for (; strchr(skip1, *fmt); ++fmt);
YX		if (*fmt == '*') {
YX			if (getint(&fieldwidth))
YX				return (1);
YX		} else
YX			fieldwidth = 0;
YX
YX		/* skip to possible '.', get following precision */
YX		for (; strchr(skip2, *fmt); ++fmt);
YX		if (*fmt == '.')
YX			++fmt;
YX		if (*fmt == '*') {
YX			if (getint(&precision))
YX				return (1);
YX		} else
YX			precision = 0;
YX
YX		/* skip to conversion char */
YX		for (; strchr(skip2, *fmt); ++fmt);
YX		if (!*fmt) {
YX			warnx("missing format character", NULL, NULL);
YX			return (1);
YX		}
YX
YX		convch = *fmt;
YX		nextch = *++fmt;
YX		*fmt = '\0';
YX		switch(convch) {
YX		case 'c': {
YX			char p;
YX
YX			p = getchr();
YX			PF(start, p);
YX			break;
YX		}
YX		case 's': {
YX			char *p;
YX
YX			p = getstr();
YX			PF(start, p);
YX			break;
YX		}
YX		case 'd': case 'i': case 'o': case 'u': case 'x': case 'X': {
YX			long p;
YX			char *f;
YX			
YX			if ((f = mklong(start, convch)) == NULL)
YX				return (1);
YX			if (getlong(&p))
YX				return (1);
YX			PF(f, p);
YX			break;
YX		}
YX		case 'e': case 'E': case 'f': case 'g': case 'G': {
YX			double p;
YX
YX			p = getdouble();
YX			PF(start, p);
YX			break;
YX		}
YX		default:
YX			warnx("illegal format character", NULL, NULL);
YX			return (1);
YX		}
YX		*fmt = nextch;
YX	}
YX	/* NOTREACHED */
YX}
YX
YXstatic char *
YXmklong(str, ch)
YX	register char *str;
YX	int ch;
YX{
YX	static char copy[64];
YX	register int len;
YX
YX	if (ch == 'X')		/* XXX */
YX		ch = 'x';
YX	len = strlen(str) + 2;
YX	bcopy(str, copy, len - 3);
YX	copy[len - 3] = 'l';
YX	copy[len - 2] = ch;
YX	copy[len - 1] = '\0';
YX	return (copy);
YX}
YX
YXstatic void
YXescape(fmt)
YX	register char *fmt;
YX{
YX	register char *store;
YX	register int value;
YX	int c;
YX
YX	for (store = fmt; c = *fmt; ++fmt, ++store) {
YX		if (c != '\\') {
YX			*store = c;
YX			continue;
YX		}
YX		switch (*++fmt) {
YX		case '\0':		/* EOS, user error */
YX			*store = '\\';
YX			*++store = '\0';
YX			return;
YX		case '\\':		/* backslash */
YX		case '\'':		/* single quote */
YX			*store = *fmt;
YX			break;
YX		case 'a':		/* bell/alert */
YX			*store = '\7';
YX			break;
YX		case 'b':		/* backspace */
YX			*store = '\b';
YX			break;
YX		case 'f':		/* form-feed */
YX			*store = '\f';
YX			break;
YX		case 'n':		/* newline */
YX			*store = '\n';
YX			break;
YX		case 'r':		/* carriage-return */
YX			*store = '\r';
YX			break;
YX		case 't':		/* horizontal tab */
YX			*store = '\t';
YX			break;
YX		case 'v':		/* vertical tab */
YX			*store = '\13';
YX			break;
YX					/* octal constant */
YX		case '0': case '1': case '2': case '3':
YX		case '4': case '5': case '6': case '7':
YX			for (c = 3, value = 0;
YX			    c-- && *fmt >= '0' && *fmt <= '7'; ++fmt) {
YX				value <<= 3;
YX				value += *fmt - '0';
YX			}
YX			--fmt;
YX			*store = value;
YX			break;
YX		default:
YX			*store = *fmt;
YX			break;
YX		}
YX	}
YX	*store = '\0';
YX}
YX
YXstatic int
YXgetchr()
YX{
YX	if (!*gargv)
YX		return ('\0');
YX	return ((int)**gargv++);
YX}
YX
YXstatic char *
YXgetstr()
YX{
YX	if (!*gargv)
YX		return ("");
YX	return (*gargv++);
YX}
YX
YXstatic char *Number = "+-.0123456789";
YXstatic int
YXgetint(ip)
YX	int *ip;
YX{
YX	long val;
YX
YX	if (getlong(&val))
YX		return (1);
YX	if (val > 65535) {
YX		warnx("%s: %s", *gargv, strerror(ERANGE));
YX		return (1);
YX	}
YX	*ip = val;
YX	return (0);
YX}
YX
YXstatic int
YXgetlong(lp)
YX	register long *lp;
YX{
YX	long val;
YX	char *ep;
YX
YX	if (!*gargv) {
YX		*lp = 0;
YX		return (0);
YX	}
YX	if (strchr(Number, **gargv)) {
YX		errno = 0;
YX		val = strtol(*gargv, &ep, 0);
YX		if (*ep != '\0') {
YX			warnx("%s: illegal number", *gargv, NULL);
YX			return (1);
YX		}
YX		if (errno == ERANGE)
YX			if (val == 2147483647L) {
YX				warnx("%s: %s", *gargv, strerror(ERANGE));
YX				return (1);
YX			}
YX			if (val == (-2147483647L-1)) {
YX				warnx("%s: %s", *gargv, strerror(ERANGE));
YX				return (1);
YX			}
YX			
YX		*lp = val;
YX		++gargv;
YX		return (0);
YX	}
YX	*lp =  (long)asciicode();
YX	return (0);
YX}
YX
YXstatic double
YXgetdouble()
YX{
YX	if (!*gargv)
YX		return ((double)0);
YX	if (strchr(Number, **gargv))
YX		return (atof(*gargv++));
YX	return ((double)asciicode());
YX}
YX
YXstatic int
YXasciicode()
YX{
YX	register int ch;
YX
YX	ch = **gargv;
YX	if (ch == '\'' || ch == '"')
YX		ch = (*gargv)[1];
YX	++gargv;
YX	return (ch);
YX}
YX
YXstatic void
YXusage()
YX{
YX	(void)fprintf(stderr, "usage: printf format [arg ...]\n");
YX}
YSHAR_EOF
Ychmod 644 'printf.c'
Yfi
Yif test -f 'Makefile'
Ythen
Y	echo shar: "will not over-write existing file 'Makefile'"
Yelse
Ysed 's/^X//' << \SHAR_EOF > 'Makefile'
YX#
YX# Public Domain.  1995/05/02 - Steven Schultz
YX#
YX#	@(#)Makefile	1.0 (2.11BSD GTE) 1995/05/02
YX#
YXCFLAGS=	 -O
YXSEPFLAG= -i
YXSRCS=	printf.c
YXOBJS=	printf.o
YXMAN=	printf.0
YXMANSRC=	printf.1
YX
YXall: printf printf.0
YX
YXprintf: ${OBJS}
YX	${CC} ${CFLAGS} ${SEPFLAG} -o $@ ${OBJS}
YX
YXprintf.0: ${MANSRC}
YX	/usr/man/manroff ${MANSRC} > ${MAN}
YX
YXclean:
YX	rm -f ${OBJS} ${MAN} printf tags 
YX
YXdepend: ${SRCS}
YX	mkdep ${CFLAGS} ${SRCS}
YX
YXinstall: all
YX	install -c -o bin -g bin -m 444 ${MAN} ${DESTDIR}/usr/man/cat1
YX	install -s -o root -g bin -m 755 printf ${DESTDIR}/usr/bin/printf
YX
YXlint: ${SRCS}
YX	lint -hax ${SRCS}
YX
YXtags: ${SRCS}
YX	ctags ${SRCS}
YX# DO NOT DELETE THIS LINE -- mkdep uses it.
YX# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
YSHAR_EOF
Ychmod 644 'Makefile'
Yfi
Yif test -f 'printf.1'
Ythen
Y	echo shar: "will not over-write existing file 'printf.1'"
Yelse
Ysed 's/^X//' << \SHAR_EOF > 'printf.1'
YX.\" Copyright (c) 1989, 1990, 1993
YX.\"	The Regents of the University of California.  All rights reserved.
YX.\"
YX.\" This code is derived from software contributed to Berkeley by
YX.\" the Institute of Electrical and Electronics Engineers, Inc.
YX.\"
YX.\" Redistribution and use in source and binary forms, with or without
YX.\" modification, are permitted provided that the following conditions
YX.\" are met:
YX.\" 1. Redistributions of source code must retain the above copyright
YX.\"    notice, this list of conditions and the following disclaimer.
YX.\" 2. Redistributions in binary form must reproduce the above copyright
YX.\"    notice, this list of conditions and the following disclaimer in the
YX.\"    documentation and/or other materials provided with the distribution.
YX.\" 3. All advertising materials mentioning features or use of this software
YX.\"    must display the following acknowledgement:
YX.\"	This product includes software developed by the University of
YX.\"	California, Berkeley and its contributors.
YX.\" 4. Neither the name of the University nor the names of its contributors
YX.\"    may be used to endorse or promote products derived from this software
YX.\"    without specific prior written permission.
YX.\"
YX.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
YX.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
YX.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
YX.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
YX.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
YX.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
YX.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
YX.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
YX.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
YX.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
YX.\" SUCH DAMAGE.
YX.\"
YX.\"	@(#)printf.1	8.1.1 (2.11BSD) 1995/05/02
YX.\"
YX.TH PRINTF 1 "May 2, 1995"
YX.UC 4
YX.SH NAME
YXprintf \- formatted output
YX.SH SYNOPSIS
YX.B printf format [ arguments  ... ]
YX.SH DESCRIPTION
YX.B Printf
YXformats and prints its arguments, after the first, under control
YXof the
YX.IR format  .
YXThe
YX.I format
YXis a character string which contains three types of objects: plain characters,
YXwhich are simply copied to standard output, character escape sequences which
YXare converted and copied to the standard output, and format specifications,
YXeach of which causes printing of the next successive
YX.IR argument  .
YX.PP
YXThe
YX.I arguments
YXafter the first are treated as strings if the corresponding format is
YXeither
YX.B c
YXor
YX.BR s ;
YXotherwise it is evaluated as a C constant, with the following extensions:
YX.TP
YX.B \(bu
YXA leading plus or minus sign is allowed.
YX.TP
YX.B \(bu
YXIf the leading character is a single or double quote, or not a digit,
YXplus, or minus sign, the value is the ASCII code of the next character.
YX.PP
YXThe format string is reused as often as necessary to satisfy the
YX.IR arguments  .
YXAny extra format specifications are evaluated with zero or the null
YXstring.
YX.PP
YXCharacter escape sequences are in backslash notation as defined in the
YXdraft proposed
YXANSI C
YXStandard
YXX3J11.
YXThe characters and their meanings
YXare as follows:
YX.br
YX.po +0.5i
YX.TP 10
YX.B \ea
YXWrite a <bell> character.
YX.TP 10
YX.B \eb
YXWrite a <backspace> character.
YX.TP 10
YX.B \ef
YXWrite a <form-feed> character.
YX.TP 10
YX.B \en
YXWrite a <new-line> character.
YX.TP 10
YX.B \er
YXWrite a <carriage return> character.
YX.TP 10
YX.B \et
YXWrite a <tab> character.
YX.TP 10
YX.B \ev
YXWrite a <vertical tab> character.
YX.TP 10
YX.B \e\'
YXWrite a <single quote> character.
YX.TP 10
YX.B \e\e
YXWrite a backslash character.
YX.TP 10
YX.B \e\fInum\fP
YXWrite an 8-bit character whose
YXASCII
YXvalue is the 1-, 2-, or 3-digit
YXoctal number
YX.IR num .
YX.br
YX.po -0.5i
YX.PP
YXEach format specification is introduced by the percent character
YX(``%'').
YXThe remainder of the format specification includes,
YXin the following order:
YX.sp
YX"Zero or more of the following flags:"
YX.sp
YX.po +0.5i
YX.TP 10
YX.B #
YXA `#' character
YXspecifying that the value should be printed in an ``alternate form''.
YXFor
YX.BR c  ,
YX.BR d ,
YXand
YX.BR s  ,
YXformats, this option has no effect.  For the
YX.B o
YXformats the precision of the number is increased to force the first
YXcharacter of the output string to a zero.  For the
YX.B x
YX(\fBX\fP)
YXformat, a non-zero result has the string
YX0x
YX(0X)
YXprepended to it.  For
YX.BR e  ,
YX.BR E ,
YX.BR f  ,
YX.BR g ,
YXand
YX.BR G  ,
YXformats, the result will always contain a decimal point, even if no
YXdigits follow the point (normally, a decimal point only appears in the
YXresults of those formats if a digit follows the decimal point).  For
YX.B g
YXand
YX.B G
YXformats, trailing zeros are not removed from the result as they
YXwould otherwise be;
YX.TP 10
YX.B \-
YXA minus sign `\-' which specifies
YX.I left adjustment
YXof the output in the indicated field;
YX.TP 10
YX.B +
YXA `+' character specifying that there should always be
YXa sign placed before the number when using signed formats.
YX.TP 10
YX.B \` \'
YXA space specifying that a blank should be left before a positive number
YXfor a signed format.  A `+' overrides a space if both are used;
YX.TP 10
YX.B 0
YXA zero `0' character indicating that zero-padding should be used
YXrather than blank-padding.  A `\-' overrides a `0' if both are used;
YX.po -0.5i
YX.TP
YXField Width:
YXAn optional digit string specifying a
YX.IR "field width" ;
YXif the output string has fewer characters than the field width it will
YXbe blank-padded on the left (or right, if the left-adjustment indicator
YXhas been given) to make up the field width (note that a leading zero
YXis a flag, but an embedded zero is part of a field width);
YX.TP
YXPrecision:
YXAn optional period,
YX\fB\.\fP,
YXfollowed by an optional digit string giving a
YX.I precision
YXwhich specifies the number of digits to appear after the decimal point,
YXfor
YX.B e
YXand 
YX.B f
YXformats, or the maximum number of characters to be printed
YXfrom a string; if the digit string is missing, the precision is treated
YXas zero;
YX.TP
YXFormat:
YX.br
YXA character which indicates the type of format to use (one of
YX.BR diouxXfwEgGcs ).
YX.PP
YXA field width or precision may be
YX.B *
YXinstead of a digit string.
YXIn this case an
YX.I argument
YXsupplies the field width or precision.
YX.PP
YXThe format characters and their meanings are:
YX.TP 10
YX.B diouXx
YXThe
YX.I argument
YXis printed as a signed decimal (d or i), unsigned decimal, unsigned octal,
YXor unsigned hexadecimal (X or x), respectively.
YX.TP 10
YX.B f
YXThe
YX.I argument
YXis printed in the style `[\-]ddd.ddd' where the number of d's
YXafter the decimal point is equal to the precision specification for
YXthe argument.
YXIf the precision is missing, 6 digits are given; if the precision
YXis explicitly 0, no digits and no decimal point are printed.
YX.TP 10
YX.B eE
YXThe
YX.I argument
YXis printed in the style
YX.B e
YX\.`[-]d.ddd Ns \(+-dd\' 
YXwhere there
YXis one digit before the decimal point and the number after is equal to
YXthe precision specification for the argument; when the precision is
YXmissing, 6 digits are produced.
YXAn upper-case E is used for an `E' format.
YX.TP 10
YX.B gG
YXThe
YX.I argument
YXis printed in style
YX.B f
YXor in style
YX.B e
YX(\fBE\fP)
YXwhichever gives full precision in minimum space.
YX.TP 10
YX.B c
YXThe first character of
YX.I argument
YXis printed.
YX.TP 10
YX.B s
YXCharacters from the string
YX.I argument
YXare printed until the end is reached or until the number of characters
YXindicated by the precision specification is reached; however if the
YXprecision is 0 or missing, all characters in the string are printed.
YX.TP 10
YX.B %
YXPrint a \`%\'; no argument is used.
YX.PP
YXIn no case does a non-existent or small field width cause truncation of
YXa field; padding takes place only if the specified field width exceeds
YXthe actual width.
YX.SH RETURN VALUES
YX.B Printf
YXexits 0 on success, 1 on failure.
YX.SH SEE ALSO
YX.IR printf (3)
YX.SH HISTORY
YXThe
YX.B printf
YXcommand appeared in
YX.BR 4.3\-Reno .
YXIt is modeled
YXafter the standard library function,
YX.BR printf (3).
YX.SH BUGS
YXSince the floating point numbers are translated from
YXASCII
YXto floating-point and
YXthen back again, floating-point precision may be lost.
YX.PP
YXANSI
YXhexadecimal character constants were deliberately not provided.
YSHAR_EOF
Ychmod 644 'printf.1'
Yfi
Ychmod 755 .
Ycd ..
Yexit 0
Y#	End of shell archive
SHAR_EOF
fi
if test -f '/tmp/update.shar'
then
	echo shar: "will not over-write existing file '/tmp/update.shar'"
else
sed 's/^Y//' << \SHAR_EOF > '/tmp/update.shar'
Y#! /bin/sh
Y# This is a shell archive, meaning:
Y# 1. Remove everything above the #! /bin/sh line.
Y# 2. Save the resulting text in a file.
Y# 3. Execute the file with /bin/sh (not csh) to create:
Y#	/usr/src/etc/update.c
Y# This archive created: Mon May  8 20:11:10 1995
Yexport PATH; PATH=/bin:/usr/bin:$PATH
Yif test -f '/usr/src/etc/update.c'
Ythen
Y	echo shar: "will not over-write existing file '/usr/src/etc/update.c'"
Yelse
Ysed 's/^X//' << \SHAR_EOF > '/usr/src/etc/update.c'
YX/*-
YX * Copyright (c) 1987, 1990, 1993
YX *	The Regents of the University of California.  All rights reserved.
YX *
YX * Redistribution and use in source and binary forms, with or without
YX * modification, are permitted provided that the following conditions
YX * are met:
YX * 1. Redistributions of source code must retain the above copyright
YX *    notice, this list of conditions and the following disclaimer.
YX * 2. Redistributions in binary form must reproduce the above copyright
YX *    notice, this list of conditions and the following disclaimer in the
YX *    documentation and/or other materials provided with the distribution.
YX * 3. All advertising materials mentioning features or use of this software
YX *    must display the following acknowledgement:
YX *	This product includes software developed by the University of
YX *	California, Berkeley and its contributors.
YX * 4. Neither the name of the University nor the names of its contributors
YX *    may be used to endorse or promote products derived from this software
YX *    without specific prior written permission.
YX *
YX * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
YX * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
YX * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
YX * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
YX * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
YX * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
YX * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
YX * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
YX * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
YX * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
YX * SUCH DAMAGE.
YX */
YX
YX#if	!defined(lint) && defined(DOSCCS)
YXstatic char copyright[] =
YX"@(#) Copyright (c) 1987, 1990, 1993\n\
YX	The Regents of the University of California.  All rights reserved.\n";
YX
YXstatic char sccsid[] = "@(#)update.c	8.1 (Berkeley) 6/6/93";
YX#endif
YX
YX#include <sys/time.h>
YX#include <signal.h>
YX#include <stdio.h>
YX
YXmain()
YX{
YX	struct itimerval value;
YX	void mysync();
YX
YX	daemon(0, 0);
YX
YX	(void)signal(SIGALRM, mysync);
YX
YX	value.it_interval.tv_sec = 30;
YX	value.it_interval.tv_usec = 0;
YX	value.it_value = value.it_interval;
YX	if (setitimer(ITIMER_REAL, &value, NULL)) {
YX		perror("update: setitimer");
YX		exit(1);
YX	}
YX	for (;;)
YX		sigpause(sigblock(0L));
YX	/* NOTREACHED */
YX}
YX
YXvoid
YXmysync()
YX{
YX	(void)sync();
YX}
YSHAR_EOF
Yfi
Yexit 0
Y#	End of shell archive
SHAR_EOF
fi
exit 0
#	End of shell archive