head	1.27;
access;
symbols
	netbsd-11-0-RC4:1.27
	netbsd-11-0-RC3:1.27
	netbsd-11-0-RC2:1.27
	netbsd-11-0-RC1:1.27
	perseant-exfatfs-base-20250801:1.27
	netbsd-11:1.27.0.6
	netbsd-11-base:1.27
	netbsd-10-1-RELEASE:1.27
	perseant-exfatfs-base-20240630:1.27
	perseant-exfatfs:1.27.0.4
	perseant-exfatfs-base:1.27
	netbsd-8-3-RELEASE:1.24
	netbsd-9-4-RELEASE:1.24
	netbsd-10-0-RELEASE:1.27
	netbsd-10-0-RC6:1.27
	netbsd-10-0-RC5:1.27
	netbsd-10-0-RC4:1.27
	netbsd-10-0-RC3:1.27
	netbsd-10-0-RC2:1.27
	netbsd-10-0-RC1:1.27
	netbsd-10:1.27.0.2
	netbsd-10-base:1.27
	netbsd-9-3-RELEASE:1.24
	cjep_sun2x-base1:1.24
	cjep_sun2x:1.24.0.40
	cjep_sun2x-base:1.24
	cjep_staticlib_x-base1:1.24
	netbsd-9-2-RELEASE:1.24
	cjep_staticlib_x:1.24.0.38
	cjep_staticlib_x-base:1.24
	netbsd-9-1-RELEASE:1.24
	phil-wifi-20200421:1.24
	phil-wifi-20200411:1.24
	is-mlppp:1.24.0.36
	is-mlppp-base:1.24
	phil-wifi-20200406:1.24
	netbsd-8-2-RELEASE:1.24
	netbsd-9-0-RELEASE:1.24
	netbsd-9-0-RC2:1.24
	netbsd-9-0-RC1:1.24
	phil-wifi-20191119:1.24
	netbsd-9:1.24.0.34
	netbsd-9-base:1.24
	phil-wifi-20190609:1.24
	netbsd-8-1-RELEASE:1.24
	netbsd-8-1-RC1:1.24
	pgoyette-compat-merge-20190127:1.24
	pgoyette-compat-20190127:1.24
	pgoyette-compat-20190118:1.24
	pgoyette-compat-1226:1.24
	pgoyette-compat-1126:1.24
	pgoyette-compat-1020:1.24
	pgoyette-compat-0930:1.24
	pgoyette-compat-0906:1.24
	netbsd-7-2-RELEASE:1.24
	pgoyette-compat-0728:1.24
	netbsd-8-0-RELEASE:1.24
	phil-wifi:1.24.0.32
	phil-wifi-base:1.24
	pgoyette-compat-0625:1.24
	netbsd-8-0-RC2:1.24
	pgoyette-compat-0521:1.24
	pgoyette-compat-0502:1.24
	pgoyette-compat-0422:1.24
	netbsd-8-0-RC1:1.24
	pgoyette-compat-0415:1.24
	pgoyette-compat-0407:1.24
	pgoyette-compat-0330:1.24
	pgoyette-compat-0322:1.24
	pgoyette-compat-0315:1.24
	netbsd-7-1-2-RELEASE:1.24
	pgoyette-compat:1.24.0.30
	pgoyette-compat-base:1.24
	netbsd-7-1-1-RELEASE:1.24
	matt-nb8-mediatek:1.24.0.28
	matt-nb8-mediatek-base:1.24
	perseant-stdc-iso10646:1.24.0.26
	perseant-stdc-iso10646-base:1.24
	netbsd-8:1.24.0.24
	netbsd-8-base:1.24
	prg-localcount2-base3:1.24
	prg-localcount2-base2:1.24
	prg-localcount2-base1:1.24
	prg-localcount2:1.24.0.22
	prg-localcount2-base:1.24
	pgoyette-localcount-20170426:1.24
	bouyer-socketcan-base1:1.24
	pgoyette-localcount-20170320:1.24
	netbsd-7-1:1.24.0.20
	netbsd-7-1-RELEASE:1.24
	netbsd-7-1-RC2:1.24
	netbsd-7-nhusb-base-20170116:1.24
	bouyer-socketcan:1.24.0.18
	bouyer-socketcan-base:1.24
	pgoyette-localcount-20170107:1.24
	netbsd-7-1-RC1:1.24
	pgoyette-localcount-20161104:1.24
	netbsd-7-0-2-RELEASE:1.24
	localcount-20160914:1.24
	netbsd-7-nhusb:1.24.0.16
	netbsd-7-nhusb-base:1.24
	pgoyette-localcount-20160806:1.24
	pgoyette-localcount-20160726:1.24
	pgoyette-localcount:1.24.0.14
	pgoyette-localcount-base:1.24
	netbsd-7-0-1-RELEASE:1.24
	netbsd-7-0:1.24.0.12
	netbsd-7-0-RELEASE:1.24
	netbsd-7-0-RC3:1.24
	netbsd-7-0-RC2:1.24
	netbsd-7-0-RC1:1.24
	netbsd-5-2-3-RELEASE:1.19
	netbsd-5-1-5-RELEASE:1.19
	netbsd-6-0-6-RELEASE:1.21
	netbsd-6-1-5-RELEASE:1.21
	netbsd-7:1.24.0.10
	netbsd-7-base:1.24
	yamt-pagecache-base9:1.24
	yamt-pagecache-tag8:1.21.2.2
	netbsd-6-1-4-RELEASE:1.21
	netbsd-6-0-5-RELEASE:1.21
	tls-earlyentropy:1.24.0.8
	tls-earlyentropy-base:1.24
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.24
	riastradh-drm2-base3:1.24
	netbsd-6-1-3-RELEASE:1.21
	netbsd-6-0-4-RELEASE:1.21
	netbsd-5-2-2-RELEASE:1.19
	netbsd-5-1-4-RELEASE:1.19
	netbsd-6-1-2-RELEASE:1.21
	netbsd-6-0-3-RELEASE:1.21
	netbsd-5-2-1-RELEASE:1.19
	netbsd-5-1-3-RELEASE:1.19
	netbsd-6-1-1-RELEASE:1.21
	riastradh-drm2-base2:1.24
	riastradh-drm2-base1:1.24
	riastradh-drm2:1.24.0.4
	riastradh-drm2-base:1.24
	netbsd-6-1:1.21.0.10
	netbsd-6-0-2-RELEASE:1.21
	netbsd-6-1-RELEASE:1.21
	netbsd-6-1-RC4:1.21
	netbsd-6-1-RC3:1.21
	agc-symver:1.24.0.6
	agc-symver-base:1.24
	netbsd-6-1-RC2:1.21
	netbsd-6-1-RC1:1.21
	yamt-pagecache-base8:1.24
	netbsd-5-2:1.19.0.2
	netbsd-6-0-1-RELEASE:1.21
	yamt-pagecache-base7:1.24
	netbsd-5-2-RELEASE:1.19
	netbsd-5-2-RC1:1.19
	matt-nb6-plus-nbase:1.21
	yamt-pagecache-base6:1.24
	netbsd-6-0:1.21.0.8
	netbsd-6-0-RELEASE:1.21
	netbsd-6-0-RC2:1.21
	tls-maxphys:1.24.0.2
	tls-maxphys-base:1.24
	matt-nb6-plus:1.21.0.6
	matt-nb6-plus-base:1.21
	netbsd-6-0-RC1:1.21
	yamt-pagecache-base5:1.22
	yamt-pagecache-base4:1.22
	netbsd-6:1.21.0.4
	netbsd-6-base:1.21
	netbsd-5-1-2-RELEASE:1.19
	netbsd-5-1-1-RELEASE:1.19
	yamt-pagecache-base3:1.21
	yamt-pagecache-base2:1.21
	yamt-pagecache:1.21.0.2
	yamt-pagecache-base:1.21
	cherry-xenmp:1.20.0.4
	cherry-xenmp-base:1.20
	bouyer-quota2-nbase:1.20
	bouyer-quota2:1.20.0.2
	bouyer-quota2-base:1.20
	matt-mips64-premerge-20101231:1.20
	matt-nb5-mips64-premerge-20101231:1.19
	matt-nb5-pq3:1.19.0.14
	matt-nb5-pq3-base:1.19
	netbsd-5-1:1.19.0.12
	netbsd-5-1-RELEASE:1.19
	netbsd-5-1-RC4:1.19
	matt-nb5-mips64-k15:1.19
	netbsd-5-1-RC3:1.19
	netbsd-5-1-RC2:1.19
	netbsd-5-1-RC1:1.19
	netbsd-5-0-2-RELEASE:1.19
	matt-nb5-mips64-premerge-20091211:1.19
	matt-premerge-20091211:1.20
	matt-nb5-mips64-u2-k2-k4-k7-k8-k9:1.19
	matt-nb4-mips64-k7-u2a-k9b:1.19
	matt-nb5-mips64-u1-k1-k5:1.19
	matt-nb5-mips64:1.19.0.10
	netbsd-5-0-1-RELEASE:1.19
	jym-xensuspend-nbase:1.20
	netbsd-5-0:1.19.0.8
	netbsd-5-0-RELEASE:1.19
	netbsd-5-0-RC4:1.19
	netbsd-5-0-RC3:1.19
	netbsd-5-0-RC2:1.19
	jym-xensuspend:1.19.0.6
	jym-xensuspend-base:1.20
	netbsd-5-0-RC1:1.19
	netbsd-5:1.19.0.4
	netbsd-5-base:1.19
	matt-mips64-base2:1.19
	matt-mips64:1.17.0.6
	netbsd-4-0-1-RELEASE:1.16
	wrstuden-revivesa-base-3:1.19
	wrstuden-revivesa-base-2:1.19
	wrstuden-fixsa-newbase:1.16
	wrstuden-revivesa-base-1:1.18
	yamt-pf42-base4:1.18
	yamt-pf42-base3:1.18
	hpcarm-cleanup-nbase:1.18
	yamt-pf42-baseX:1.18
	yamt-pf42-base2:1.18
	wrstuden-revivesa:1.18.0.8
	wrstuden-revivesa-base:1.18
	yamt-pf42:1.18.0.6
	yamt-pf42-base:1.18
	keiichi-mipv6-nbase:1.18
	keiichi-mipv6:1.18.0.4
	keiichi-mipv6-base:1.18
	matt-armv6-nbase:1.18
	matt-armv6-prevmlocking:1.17.4.1
	wrstuden-fixsa-base-1:1.16
	netbsd-4-0:1.16.0.8
	netbsd-4-0-RELEASE:1.16
	cube-autoconf:1.18.0.2
	cube-autoconf-base:1.18
	netbsd-4-0-RC5:1.16
	netbsd-4-0-RC4:1.16
	netbsd-4-0-RC3:1.16
	netbsd-4-0-RC2:1.16
	netbsd-4-0-RC1:1.16
	matt-armv6:1.17.0.4
	matt-armv6-base:1.18
	matt-mips64-base:1.17
	hpcarm-cleanup:1.17.0.2
	hpcarm-cleanup-base:1.18
	netbsd-3-1-1-RELEASE:1.12
	netbsd-3-0-3-RELEASE:1.12
	wrstuden-fixsa:1.16.0.6
	wrstuden-fixsa-base:1.16
	abandoned-netbsd-4-base:1.16
	abandoned-netbsd-4:1.16.0.2
	netbsd-3-1:1.12.0.12
	netbsd-3-1-RELEASE:1.12
	netbsd-3-0-2-RELEASE:1.12
	netbsd-3-1-RC4:1.12
	netbsd-3-1-RC3:1.12
	netbsd-3-1-RC2:1.12
	netbsd-3-1-RC1:1.12
	netbsd-4:1.16.0.4
	netbsd-4-base:1.16
	chap-midi-nbase:1.16
	netbsd-3-0-1-RELEASE:1.12
	chap-midi:1.15.0.2
	chap-midi-base:1.16
	netbsd-3-0:1.12.0.10
	netbsd-3-0-RELEASE:1.12
	netbsd-3-0-RC6:1.12
	netbsd-3-0-RC5:1.12
	netbsd-3-0-RC4:1.12
	netbsd-3-0-RC3:1.12
	netbsd-3-0-RC2:1.12
	netbsd-3-0-RC1:1.12
	netbsd-2-0-3-RELEASE:1.12
	netbsd-2-1:1.12.0.8
	netbsd-2-1-RELEASE:1.12
	netbsd-2-1-RC6:1.12
	netbsd-2-1-RC5:1.12
	netbsd-2-1-RC4:1.12
	netbsd-2-1-RC3:1.12
	netbsd-2-1-RC2:1.12
	netbsd-2-1-RC1:1.12
	netbsd-2-0-2-RELEASE:1.12
	netbsd-3:1.12.0.6
	netbsd-3-base:1.12
	netbsd-2-0-1-RELEASE:1.12
	netbsd-2:1.12.0.4
	netbsd-2-base:1.12
	netbsd-2-0-RELEASE:1.12
	netbsd-2-0-RC5:1.12
	netbsd-2-0-RC4:1.12
	netbsd-2-0-RC3:1.12
	netbsd-2-0-RC2:1.12
	netbsd-2-0-RC1:1.12
	netbsd-2-0:1.12.0.2
	netbsd-2-0-base:1.12
	netbsd-1-6-PATCH002-RELEASE:1.10
	netbsd-1-6-PATCH002:1.10
	netbsd-1-6-PATCH002-RC4:1.10
	netbsd-1-6-PATCH002-RC3:1.10
	netbsd-1-6-PATCH002-RC2:1.10
	netbsd-1-6-PATCH002-RC1:1.10
	netbsd-1-6-PATCH001:1.10
	netbsd-1-6-PATCH001-RELEASE:1.10
	netbsd-1-6-PATCH001-RC3:1.10
	netbsd-1-6-PATCH001-RC2:1.10
	netbsd-1-6-PATCH001-RC1:1.10
	fvdl_fs64_base:1.10
	netbsd-1-6-RELEASE:1.10
	netbsd-1-6-RC3:1.10
	netbsd-1-6-RC2:1.10
	netbsd-1-6-RC1:1.10
	netbsd-1-6:1.10.0.2
	netbsd-1-6-base:1.10
	netbsd-1-5-PATCH003:1.7.10.2
	netbsd-1-5-PATCH002:1.7.10.2
	netbsd-1-5-PATCH001:1.7.10.2
	netbsd-1-5-RELEASE:1.7.10.2
	netbsd-1-5-BETA2:1.7.10.2
	netbsd-1-5-BETA:1.7.10.1
	netbsd-1-4-PATCH003:1.7
	netbsd-1-5-ALPHA2:1.7.10.1
	netbsd-1-5:1.7.0.10
	netbsd-1-5-base:1.7
	minoura-xpg4dl-base:1.7
	minoura-xpg4dl:1.7.0.8
	netbsd-1-4-PATCH002:1.7
	wrstuden-devbsize-19991221:1.7
	wrstuden-devbsize:1.7.0.6
	wrstuden-devbsize-base:1.7
	comdex-fall-1999:1.7.0.4
	comdex-fall-1999-base:1.7
	netbsd-1-4-PATCH001:1.7
	netbsd-1-4-RELEASE:1.7
	netbsd-1-4:1.7.0.2
	netbsd-1-4-base:1.7
	netbsd-1-3-PATCH003:1.5
	netbsd-1-3-PATCH003-CANDIDATE2:1.5
	netbsd-1-3-PATCH003-CANDIDATE1:1.5
	netbsd-1-3-PATCH003-CANDIDATE0:1.5
	netbsd-1-3-PATCH002:1.5
	netbsd-1-3-PATCH001:1.5
	netbsd-1-3-RELEASE:1.5
	netbsd-1-3-BETA:1.5
	netbsd-1-3:1.5.0.2
	netbsd-1-3-base:1.5
	netbsd-1-2-PATCH001:1.3
	lite-2:1.1.1.1
	CSRG:1.1.1
	netbsd-1-2-RELEASE:1.3
	netbsd-1-2-BETA:1.3
	netbsd-1-2:1.3.0.6
	netbsd-1-2-base:1.3
	netbsd-1-1-PATCH001:1.3
	netbsd-1-1-RELEASE:1.3
	netbsd-1-1:1.3.0.2
	netbsd-1-1-base:1.3
	netbsd-1-0-PATCH06:1.2
	netbsd-1-0-PATCH05:1.2
	netbsd-1-0-PATCH04:1.2
	netbsd-1-0-PATCH03:1.2
	netbsd-1-0-PATCH02:1.2
	netbsd-1-0-PATCH1:1.2
	netbsd-1-0-PATCH0:1.2
	netbsd-1-0-RELEASE:1.2
	netbsd-1-0:1.2.0.2
	netbsd-1-0-base:1.2;
locks; strict;
comment	@ * @;


1.27
date	2022.05.23.19.52.35;	author andvar;	state Exp;
branches;
next	1.26;
commitid	1KaHqLtSL772wdFD;

1.26
date	2022.04.08.10.17.55;	author andvar;	state Exp;
branches;
next	1.25;
commitid	J1NucfCns0zRLnzD;

1.25
date	2021.12.05.08.03.07;	author msaitoh;	state Exp;
branches;
next	1.24;
commitid	GU5fY1QSkOdl2rjD;

1.24
date	2012.08.01.02.27.48;	author ginsbach;	state Exp;
branches;
next	1.23;

1.23
date	2012.07.24.02.13.04;	author ginsbach;	state Exp;
branches;
next	1.22;

1.22
date	2012.03.12.18.06.24;	author christos;	state Exp;
branches;
next	1.21;

1.21
date	2011.09.06.18.26.06;	author joerg;	state Exp;
branches
	1.21.2.1;
next	1.20;

1.20
date	2009.04.13.00.37.05;	author lukem;	state Exp;
branches;
next	1.19;

1.19
date	2008.07.21.14.19.24;	author lukem;	state Exp;
branches
	1.19.6.1;
next	1.18;

1.18
date	2007.10.14.11.21.32;	author lukem;	state Exp;
branches
	1.18.8.1;
next	1.17;

1.17
date	2007.04.29.20.23.37;	author msaitoh;	state Exp;
branches
	1.17.4.1;
next	1.16;

1.16
date	2006.05.24.15.59.06;	author christos;	state Exp;
branches;
next	1.15;

1.15
date	2006.05.01.23.31.10;	author christos;	state Exp;
branches
	1.15.2.1;
next	1.14;

1.14
date	2006.04.02.04.17.08;	author christos;	state Exp;
branches;
next	1.13;

1.13
date	2005.12.28.21.29.16;	author christos;	state Exp;
branches;
next	1.12;

1.12
date	2003.10.13.07.41.22;	author agc;	state Exp;
branches;
next	1.11;

1.11
date	2003.08.07.11.15.30;	author agc;	state Exp;
branches;
next	1.10;

1.10
date	2001.07.22.13.34.13;	author wiz;	state Exp;
branches;
next	1.9;

1.9
date	2000.10.22.15.06.52;	author kleink;	state Exp;
branches;
next	1.8;

1.8
date	2000.07.13.02.07.53;	author simonb;	state Exp;
branches;
next	1.7;

1.7
date	98.12.19.20.16.50;	author christos;	state Exp;
branches
	1.7.10.1;
next	1.6;

1.6
date	98.04.02.10.42.51;	author kleink;	state Exp;
branches;
next	1.5;

1.5
date	97.10.19.12.42.10;	author lukem;	state Exp;
branches;
next	1.4;

1.4
date	97.01.09.15.01.36;	author tls;	state Exp;
branches;
next	1.3;

1.3
date	95.06.07.16.10.11;	author cgd;	state Exp;
branches;
next	1.2;

1.2
date	94.03.07.05.42.17;	author cgd;	state Exp;
branches;
next	1.1;

1.1
date	94.01.06.15.57.25;	author cgd;	state Exp;
branches
	1.1.1.1;
next	;

1.21.2.1
date	2012.04.17.00.09.38;	author yamt;	state Exp;
branches;
next	1.21.2.2;

1.21.2.2
date	2012.10.30.19.00.26;	author yamt;	state Exp;
branches;
next	;

1.19.6.1
date	2009.05.13.19.20.01;	author jym;	state Exp;
branches;
next	;

1.18.8.1
date	2008.09.18.04.29.18;	author wrstuden;	state Exp;
branches;
next	;

1.17.4.1
date	2007.11.06.23.36.14;	author matt;	state Exp;
branches;
next	;

1.15.2.1
date	2006.06.19.04.17.07;	author chap;	state Exp;
branches;
next	;

1.7.10.1
date	2000.07.13.03.23.33;	author simonb;	state Exp;
branches;
next	1.7.10.2;

1.7.10.2
date	2000.10.25.16.29.11;	author tv;	state Exp;
branches;
next	;

1.1.1.1
date	97.01.09.14.49.44;	author tls;	state Exp;
branches;
next	;


desc
@@


1.27
log
@s/boundries/boundaries/, s/itterate/iterate/ and few more typos.
@
text
@/*	$NetBSD: pr.c,v 1.26 2022/04/08 10:17:55 andvar Exp $	*/

/*-
 * Copyright (c) 1991 Keith Muller.
 * Copyright (c) 1993
 *	The Regents of the University of California.  All rights reserved.
 * Copyright (c) 2012
 *	The NetBSD Foundation, Inc.
 *
 * 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.
 * 3. 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>
#ifndef lint
__COPYRIGHT("@@(#) Copyright (c) 1993\
 The Regents of the University of California.  All rights reserved.");
#endif /* not lint */

#ifndef lint
#if 0
from: static char sccsid[] = "@@(#)pr.c	8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: pr.c,v 1.26 2022/04/08 10:17:55 andvar Exp $");
#endif
#endif /* not lint */

#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>

#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <util.h>

#include "pr.h"
#include "extern.h"

/*
 * pr:	a printing and pagination filter. If multiple input files
 *	are specified, each is read, formatted, and written to standard
 *	output. By default, input is separated into 66-line pages, each
 *	with a header that includes the page number, date, time and the
 *	files pathname.
 *
 *	Complies with posix P1003.2/D11
 */

/*
 * parameter variables
 */
static int	pgnm;			/* starting page number */
static int	clcnt;			/* number of columns */
static int	colwd;			/* column data width - multiple columns */
static int	across;			/* mult col flag; write across page */
static int	dspace;			/* double space flag */
static char	inchar;			/* expand input char */
static int	ingap;			/* expand input gap */
static int	formfeed;		/* use formfeed as trailer */
static char	*header;		/* header name instead of file name */
static char	ochar;			/* contract output char */
static int	ogap;			/* contract output gap */
static int	lines;			/* number of lines per page */
static int	merge;			/* merge multiple files in output */
static char	nmchar;			/* line numbering append char */
static int	nmwd;			/* width of line number field */
static int	offst;			/* number of page offset spaces */
static int	nodiag;			/* do not report file open errors */
static char	schar;			/* text column separation character */
static int	sflag;			/* -s option for multiple columns */
static int	ttyout;			/* output is a tty */
static int	nohead;			/* do not write head and trailer */
static int	pgpause;		/* pause before each page */
static int	pgwd;			/* page width with multiple col output */
static const char *timefrmt = TIMEFMT;	/* time conversion string */
static FILE	*ttyinf;		/* input terminal for page pauses */

/*
 * misc globals
 */
static FILE	*errf;			/* error message file pointer */
static int	addone;			/* page length is odd with double space */
static int	errcnt;			/* error count on file processing */
static const char	digs[] = "0123456789";	/* page number translation map */

static void	 addnum(char *, int, int);
static void	 flsh_errs(void);
static int	 horzcol(int, char **);
static int	 inln(FILE *, char *, int, int *, int, int *);
static int	 inskip(FILE *, int, int);
static void	 mfail(void);
static int	 mulfile(int, char **);
static FILE	*nxtfile(int, char **, const char **, char *, int);
static int	 onecol(int, char **);
static int	 otln(char *, int, int *, int *, int);
static void	 pfail(void);
static int	 prhead(char *, const char *, int);
static void	 prpause(int);
static int	 prtail(int, int);
static int	 setup(int, char **);
__dead static void	 terminate(int);
static void	 usage(void);
static int	 vertcol(int, char **);

int
main(int argc, char *argv[])
{
	int ret_val;

	if (signal(SIGINT, SIG_IGN) != SIG_IGN)
		(void)signal(SIGINT, terminate);
	ret_val = setup(argc, argv);
	if (!ret_val) {
		/*
		 * select the output format based on options
		 */
		if (merge)
			ret_val = mulfile(argc, argv);
		else if (clcnt == 1)
			ret_val = onecol(argc, argv);
		else if (across)
			ret_val = horzcol(argc, argv);
		else
			ret_val = vertcol(argc, argv);
	} else
		usage();
	flsh_errs();
	if (errcnt || ret_val)
		exit(1);
	return(0);
}

/*
 * onecol:	print files with only one column of output.
 *		Line length is unlimited.
 */
static int
onecol(int argc, char *argv[])
{
	int cnt = -1;
	int off;
	int lrgln;
	int linecnt;
	int num;
	int lncnt;
	int pagecnt;
	int ips;
	int ops;
	int cps;
	char *obuf = NULL;
	char *lbuf;
	char *nbuf;
	char *hbuf = NULL;
	char *ohbuf;
	FILE *inf = NULL;
	const char *fname;
	int mor;
	int error = 1;

	if (nmwd)
		num = nmwd + 1;
	else
		num = 0;
	off = num + offst;

	/*
	 * allocate line buffer
	 */
	if ((obuf = malloc((unsigned)(LBUF + off)*sizeof(char))) == NULL)
		goto oomem;
	/*
	 * allocate header buffer
	 */
	if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL)
		goto oomem;

	ohbuf = hbuf + offst;
	nbuf = obuf + offst;
	lbuf = nbuf + num;
	if (num)
		nbuf[--num] = nmchar;
	if (offst) {
		(void)memset(obuf, (int)' ', offst);
		(void)memset(hbuf, (int)' ', offst);
	}

	/*
	 * loop by file
	 */
	while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) {
		if (pgnm) {
			/*
			 * skip to specified page
			 */
			if (inskip(inf, pgnm, lines))
				continue;
			pagecnt = pgnm;
		} else
			pagecnt = 1;
		lncnt = 0;

		/*
		 * loop by page
		 */
		for(;;) {
			linecnt = 0;
			lrgln = 0;
			ops = 0;
			ips = 0;
			cps = 0;

			/*
			 * loop by line
			 */
			while (linecnt < lines) {
				/*
				 * input next line
				 */
				if ((cnt = inln(inf,lbuf,LBUF,&cps,0,&mor)) < 0)
					break;
				if (!linecnt) {
					if (pgpause)
						prpause(pagecnt);

				        if (!nohead &&
					    prhead(hbuf, fname, pagecnt))
						goto out;
				}

				/*
				 * start of new line.
				 */
				if (!lrgln) {
					if (num)
						addnum(nbuf, num, ++lncnt);
					if (otln(obuf,cnt+off, &ips, &ops, mor))
						goto out;
				} else if (otln(lbuf, cnt, &ips, &ops, mor))
					goto out;

				/*
				 * if line bigger than buffer, get more
				 */
				if (mor) {
					lrgln = 1;
					continue;
				}

				/*
				 * whole line rcvd. reset tab proc. state
				 */
				++linecnt;
				lrgln = 0;
				ops = 0;
				ips = 0;
			}

			/*
			 * fill to end of page
			 */
			if (linecnt && prtail(lines-linecnt-lrgln, lrgln))
				goto out;

			/*
			 * On EOF go to next file
			 */
			if (cnt < 0)
				break;
			++pagecnt;
		}
		if (inf != stdin)
			(void)fclose(inf);
	}
	if (eoptind < argc)
		goto out;
	error = 0;
	goto out;
oomem:
	mfail();
out:
	free(obuf);
	free(hbuf);
	if (inf != NULL && inf != stdin)
		(void)fclose(inf);
	return error;
}

/*
 * vertcol:	print files with more than one column of output down a page
 */
static int
vertcol(int argc, char *argv[])
{
	char *ptbf;
	char **lstdat = NULL;
	int i;
	int j;
	int cnt = -1;
	int pln;
	int *indy = NULL;
	int cvc;
	int *lindy = NULL;
	int lncnt;
	int stp;
	int pagecnt;
	int col = colwd + 1;
	int mxlen = pgwd + offst + 1;
	int mclcnt = clcnt - 1;
	struct vcol *vc = NULL;
	int mvc;
	int tvc;
	int cw = nmwd + 1;
	int fullcol;
	char *buf = NULL;
	char *hbuf = NULL;
	char *ohbuf;
	const char *fname;
	FILE *inf = NULL;
	int ips = 0;
	int cps = 0;
	int ops = 0;
	int mor = 0;
	int error = 1;

	/*
	 * allocate page buffer
	 */
	if ((buf = malloc((unsigned)lines*mxlen*sizeof(char))) == NULL)
		goto oomem;

	/*
	 * allocate page header
	 */
	if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL)
		goto oomem;
	ohbuf = hbuf + offst;
	if (offst)
		(void)memset(hbuf, (int)' ', offst);

	/*
	 * col pointers when no headers
	 */
	mvc = lines * clcnt;
	if ((vc = malloc((unsigned)mvc*sizeof(struct vcol))) == NULL)
		goto oomem;

	/*
	 * pointer into page where last data per line is located
	 */
	if ((lstdat = malloc((unsigned)lines*sizeof(char *))) == NULL)
		goto oomem;

	/*
	 * fast index lookups to locate start of lines
	 */
	if ((indy = malloc((unsigned)lines*sizeof(int))) == NULL)
		goto oomem;
	if ((lindy = malloc((unsigned)lines*sizeof(int))) == NULL)
		goto oomem;

	if (nmwd)
		fullcol = col + cw;
	else
		fullcol = col;

	/*
	 * initialize buffer lookup indexes and offset area
	 */
	for (j = 0; j < lines; ++j) {
		lindy[j] = j * mxlen;
		indy[j] = lindy[j] + offst;
		if (offst) {
			ptbf = buf + lindy[j];
			(void)memset(ptbf, (int)' ', offst);
			ptbf += offst;
		} else
			ptbf = buf + indy[j];
		lstdat[j] = ptbf;
	}

	/*
	 * loop by file
	 */
	while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) {
		if (pgnm) {
			/*
			 * skip to requested page
			 */
			if (inskip(inf, pgnm, lines))
				continue;
			pagecnt = pgnm;
		} else
			pagecnt = 1;
		lncnt = 0;

		/*
		 * loop by page
		 */
		for(;;) {
			/*
			 * loop by column
			 */
			cvc = 0;
			for (i = 0; i < clcnt; ++i) {
				j = 0;
				/*
				 * if last column, do not pad
				 */
				if (i == mclcnt)
					stp = 1;
				else
					stp = 0;
				/*
				 * loop by line
				 */
				for(;;) {
					/*
					 * is this first column
					 */
					if (!i) {
						ptbf = buf + indy[j];
						lstdat[j] = ptbf;
					} else 
						ptbf = lstdat[j];
					vc[cvc].pt = ptbf;

					/*
					 * add number
					 */
					if (nmwd) {
						addnum(ptbf, nmwd, ++lncnt);
						ptbf += nmwd;
						*ptbf++ = nmchar;
					}

					/*
					 * input next line
					 */
					cnt = inln(inf,ptbf,colwd,&cps,1,&mor);
					vc[cvc++].cnt = cnt;
					if (cnt < 0)
						break;
					ptbf += cnt;

					/*
					 * pad all but last column on page
					 */
					if (!stp) {
						/*
						 * pad to end of column
						 */
						if (sflag)
							*ptbf++ = schar;
						else if ((pln = col-cnt) > 0) {
							(void)memset(ptbf,
								(int)' ',pln);
							ptbf += pln;
						}
					}
					/*
					 * remember last char in line
					 */
					lstdat[j] = ptbf;
					if (++j >= lines)
						break;
				}
				if (cnt < 0)
					break;
			}

			/*
			 * when -t (no header) is specified the spec requires
			 * the min number of lines. The last page may not have
			 * balanced length columns. To fix this we must reorder
			 * the columns. This is a very slow technique so it is
			 * only used under limited conditions. Without -t, the
			 * balancing of text columns is unspecified. To NOT
			 * balance the last page, add the global variable
			 * nohead to the if statement below e.g.
			 *
			 * if ((cnt < 0) && nohead && cvc ......
			 */
			--cvc;

			/*
			 * check to see if last page needs to be reordered
			 */
			if ((cnt < 0) && cvc && ((mvc-cvc) >= clcnt)){
				pln = cvc/clcnt;
				if (cvc % clcnt)
					++pln;

				if (pgpause)
					prpause(pagecnt);

				/*
				 * print header
				 */
				if (!nohead && prhead(hbuf, fname, pagecnt))
					goto out;
				for (i = 0; i < pln; ++i) {
					ips = 0;
					ops = 0;
					if (offst&& otln(buf,offst,&ips,&ops,1)) {
						error = 1;
						goto out;
					}
					tvc = i;

					for (j = 0; j < clcnt; ++j) {
						/*
						 * determine column length
						 */
						if (j == mclcnt) {
							/*
							 * last column
							 */
							cnt = vc[tvc].cnt;
							if (nmwd)
								cnt += cw;
						} else if (sflag) {
							/*
							 * single ch between
							 */
							cnt = vc[tvc].cnt + 1;
							if (nmwd)
								cnt += cw;
						} else
							cnt = fullcol;
						if (otln(vc[tvc].pt, cnt, &ips,
								&ops, 1))
							goto out;
						tvc += pln;
						if (tvc >= cvc)
							break;
					}
					/*
					 * terminate line
					 */
					if (otln(buf, 0, &ips, &ops, 0))
						goto out;
				}
				/*
				 * pad to end of page
				 */
				if (prtail((lines - pln), 0))
					goto out;
				/*
				 * done with output, go to next file
				 */
				break;
			}

			/*
			 * determine how many lines to output
			 */
			if (i > 0)
				pln = lines;
			else
				pln = j;

			/*
			 * print header
			 */
			if (pln) {
				if (pgpause)
					prpause(pagecnt);

			        if (!nohead && prhead(hbuf, fname, pagecnt))
					goto out;
			}

			/*
			 * output each line
			 */
			for (i = 0; i < pln; ++i) {
				ptbf = buf + lindy[i];
				if ((j = lstdat[i] - ptbf) <= offst)
					break;
				if (otln(ptbf, j, &ips, &ops, 0))
					goto out;
			}

			/*
			 * pad to end of page
			 */
			if (pln && prtail((lines - pln), 0))
				goto out;

			/*
			 * if EOF go to next file
			 */
			if (cnt < 0)
				break;
			++pagecnt;
		}
		if (inf != stdin)
			(void)fclose(inf);
	}
	if (eoptind < argc)
		goto out;
	error = 0;
	goto out;
oomem:
	mfail();
out:
	free(buf);
	free(hbuf);
	free(vc);
	free(lstdat);
	free(lindy);
	if (inf != NULL && inf != stdin)
		(void)fclose(inf);
	return error;
}

/*
 * horzcol:	print files with more than one column of output across a page
 */
static int
horzcol(int argc, char *argv[])
{
	char *ptbf;
	int pln;
	int cnt = -1;
	char *lstdat;
	int col = colwd + 1;
	int j;
	int i;
	int lncnt;
	int pagecnt;
	char *buf = NULL;
	char *hbuf = NULL;
	char *ohbuf;
	const char *fname;
	FILE *inf = NULL;
	int ips = 0;
	int cps = 0;
	int ops = 0;
	int mor = 0;
	int error = 1;

	if ((buf = malloc((unsigned)(pgwd+offst+1)*sizeof(char))) == NULL)
		goto oomem;

	/*
	 * page header
	 */
	if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL)
		goto oomem;
	ohbuf = hbuf + offst;
	if (offst) {
		(void)memset(buf, (int)' ', offst);
		(void)memset(hbuf, (int)' ', offst);
	}

	/*
	 * loop by file
	 */
	while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) {
		if (pgnm) {
			if (inskip(inf, pgnm, lines))
				continue;
			pagecnt = pgnm;
		} else
			pagecnt = 1;
		lncnt = 0;

		/*
		 * loop by page
		 */
		for(;;) {
			/*
			 * loop by line
			 */
			for (i = 0; i < lines; ++i) {
				ptbf = buf + offst;
				lstdat = ptbf;
				j = 0;
				/*
				 * loop by col
				 */
				for(;;) {
					if (nmwd) {
						/*
						 * add number to column
						 */
						addnum(ptbf, nmwd, ++lncnt);
						ptbf += nmwd;
						*ptbf++ = nmchar;
					}
					/*
					 * input line
					 */
					if ((cnt = inln(inf,ptbf,colwd,&cps,1,
							&mor)) < 0)
						break;
					ptbf += cnt;
					lstdat = ptbf;

					/*
					 * if last line skip padding
					 */
					if (++j >= clcnt)
						break;

					/*
					 * pad to end of column
					 */
					if (sflag)
						*ptbf++ = schar;
					else if ((pln = col - cnt) > 0) {
						(void)memset(ptbf,(int)' ',pln);
						ptbf += pln;
					}
				}

				/*
				 * determine line length
				 */
				if ((j = lstdat - buf) <= offst)
					break;
				if (!i) {
					if (pgpause)
						prpause(pagecnt);

				        if (!nohead &&
					    prhead(hbuf, fname, pagecnt))
						goto out;
				}
				/*
				 * output line
				 */
				if (otln(buf, j, &ips, &ops, 0))
					goto out;
			}

			/*
			 * pad to end of page
			 */
			if (i && prtail(lines-i, 0))
				goto out;

			/*
			 * if EOF go to next file
			 */
			if (cnt < 0)
				break;
			++pagecnt;
		}
		if (inf != stdin)
			(void)fclose(inf);
	}
	if (eoptind < argc)
		goto out;
	error = 0;
	goto out;
oomem:
	mfail();
out:
	free(buf);
	free(hbuf);
	if (inf != NULL && inf != stdin)
		(void)fclose(inf);
	return error;
}

/*
 * mulfile:	print files with more than one column of output and
 *		more than one file concurrently
 */
static int
mulfile(int argc, char *argv[])
{
	char *ptbf;
	int j;
	int pln;
	int cnt;
	char *lstdat;
	int i;
	FILE **fbuf = NULL;
	int actf;
	int lncnt;
	int col;
	int pagecnt;
	int fproc;
	char *buf = NULL;
	char *hbuf = NULL;
	char *ohbuf;
	const char *fname;
	int ips = 0;
	int cps = 0;
	int ops = 0;
	int mor = 0;
	int error = 1;

	/*
	 * array of FILE *, one for each operand
	 */
	if ((fbuf = calloc(clcnt, sizeof(FILE *))) == NULL)
		goto oomem;

	/*
	 * page header
	 */
	if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL)
		goto oomem;
	ohbuf = hbuf + offst;

	/*
	 * do not know how many columns yet. The number of operands provide an
	 * upper bound on the number of columns. We use the number of files
	 * we can open successfully to set the number of columns. The operation
	 * of the merge operation (-m) in relation to unsuccessful file opens
	 * is unspecified by posix.
	 */
	j = 0;
	while (j < clcnt) {
		if ((fbuf[j] = nxtfile(argc, argv, &fname, ohbuf, 1)) == NULL)
			break;
		if (pgnm && (inskip(fbuf[j], pgnm, lines)))
			fbuf[j] = NULL;
		++j;
	}

	/*
	 * if no files, exit
	 */
	if (!j)
		goto out;

	/*
	 * calculate page boundaries based on open file count
	 */
	clcnt = j;
	if (nmwd) {
		colwd = (pgwd - clcnt - nmwd)/clcnt;
		pgwd = ((colwd + 1) * clcnt) - nmwd - 2;
	} else {
		colwd = (pgwd + 1 - clcnt)/clcnt;
		pgwd = ((colwd + 1) * clcnt) - 1;
	}
	if (colwd < 1) {
		(void)fprintf(errf,
		  "pr: page width too small for %d columns\n", clcnt);
		goto out;
	}
	actf = clcnt;
	col = colwd + 1;

	/*
	 * line buffer
	 */
	if ((buf = malloc((unsigned)(pgwd+offst+1)*sizeof(char))) == NULL)
		goto out;
	if (offst) {
		(void)memset(buf, (int)' ', offst);
		(void)memset(hbuf, (int)' ', offst);
	}
	if (pgnm)
		pagecnt = pgnm;
	else
		pagecnt = 1;
	lncnt = 0;

	/*
	 * continue to loop while any file still has data
	 */
	while (actf > 0) {
		/*
		 * loop by line
		 */
		for (i = 0; i < lines; ++i) {
			ptbf = buf + offst;
			lstdat = ptbf;
			if (nmwd) {
				/*
				 * add line number to line
				 */
				addnum(ptbf, nmwd, ++lncnt);
				ptbf += nmwd;
				*ptbf++ = nmchar;
			}
			j = 0;
			fproc = 0;

			/*
			 * loop by column
			 */
			for (j = 0; j < clcnt; ++j) {
				if (fbuf[j] == NULL) {
					/*
					 * empty column; EOF
					 */
					cnt = 0;
				} else if ((cnt = inln(fbuf[j], ptbf, colwd,
							&cps, 1, &mor)) < 0) {
					/*
					 * EOF hit; no data
					 */
					if (fbuf[j] != stdin)
						(void)fclose(fbuf[j]);
					fbuf[j] = NULL;
					--actf;
					cnt = 0;
				} else {
					/*
					 * process file data
					 */
					ptbf += cnt;
					lstdat = ptbf;
					fproc++;
				}

				/*
				 * if last ACTIVE column, done with line
				 */
				if (fproc >= actf)
					break;

				/*
				 * pad to end of column
				 */
				if (sflag) {
					*ptbf++ = schar;
				} else if ((pln = col - cnt) > 0) {
					(void)memset(ptbf, (int)' ', pln);
					ptbf += pln;
				}
			}

			/*
			 * calculate data in line
			 */
			if ((j = lstdat - buf) <= offst)
				break;

			if (!i) {
				if (pgpause)
					prpause(pagecnt);

			        if (!nohead && prhead(hbuf, fname, pagecnt))
					goto out;
			}

			/*
			 * output line
			 */
			if (otln(buf, j, &ips, &ops, 0))
				goto out;

			/*
			 * if no more active files, done
			 */
			if (actf <= 0) {
				++i;
				break;
			}
		}

		/*
		 * pad to end of page
		 */
		if (i && prtail(lines-i, 0))
			goto out;
		++pagecnt;
	}
	if (eoptind < argc)
		goto out;
	error = 0;
	goto out;
oomem:
	mfail();
out:
	if (fbuf) {
		for (j = 0; j < clcnt; j++)
			if (fbuf[j] && fbuf[j] != stdin)
				(void)fclose(fbuf[j]);
		free(fbuf);
	}
	free(hbuf);
	free(buf);
	return error;
}

/*
 * inln():	input a line of data (unlimited length lines supported)
 *		Input is optionally expanded to spaces
 *
 *	inf:	file
 *	buf:	buffer
 *	lim:	buffer length
 *	cps:	column position 1st char in buffer (large line support)
 *	trnc:	throw away data more than lim up to \n 
 *	mor:	set if more data in line (not truncated)
 */
static int
inln(FILE *inf, char *buf, int lim, int *cps, int trnc, int *mor)
{
	int col;
	int gap = ingap;
	int ch = EOF;
	char *ptbuf;
	int chk = (int)inchar;

	ptbuf = buf;

	if (gap) {
		/*
		 * expanding input option
		 */
		while ((--lim >= 0) && ((ch = getc(inf)) != EOF)) {
			/*
			 * is this the input "tab" char
			 */
			if (ch == chk) {
				/*
				 * expand to number of spaces
				 */
				col = (ptbuf - buf) + *cps;
				col = gap - (col % gap);

				/*
				 * if more than this line, push back
				 */
				if ((col > lim) && (ungetc(ch, inf) == EOF))
					return(1);

				/*
				 * expand to spaces
				 */
				while ((--col >= 0) && (--lim >= 0))
					*ptbuf++ = ' ';
				continue;
			}
			if (ch == '\n')
				break;
			*ptbuf++ = ch;
		}
	} else {
		/*
		 * no expansion
		 */
		while ((--lim >= 0) && ((ch = getc(inf)) != EOF)) {
			if (ch == '\n')
				break;
			*ptbuf++ = ch;
		}
	}
	col = ptbuf - buf;
	if (ch == EOF) {
		*mor = 0;
		*cps = 0;
		if (!col)
			return(-1);
		return(col);
	}
	if (ch == '\n') {
		/*
		 * entire line processed
		 */
		*mor = 0;
		*cps = 0;
		return(col);
	}

	/*
	 * line was larger than limit
	 */
	if (trnc) {
		/*
		 * throw away rest of line
		 */
		while ((ch = getc(inf)) != EOF) {
			if (ch == '\n')
				break;
		}
		*cps = 0;
		*mor = 0;
	} else {
		/*
		 * save column offset if not truncated
		 */
		*cps += col;
		*mor = 1;
	}

	return(col);
}

/*
 * otln():	output a line of data. (Supports unlimited length lines)
 *		output is optionally contracted to tabs
 *
 *	buf:	output buffer with data
 *	cnt:	number of chars of valid data in buf
 *	svips:	buffer input column position (for large lines)
 *	svops:	buffer output column position (for large lines)
 *	mor:	output line not complete in this buf; more data to come.	
 *		1 is more, 0 is complete, -1 is no \n's
 */
static int
otln(char *buf, int cnt, int *svips, int *svops, int mor)
{
	int ops;		/* last col output */
	int ips;		/* last col in buf examined */
	int gap = ogap;
	int tbps;
	char *endbuf;

	if (ogap) {
		/*
		 * contracting on output
		 */
		endbuf = buf + cnt;
		ops = *svops;
		ips = *svips;
		while (buf < endbuf) {
			/*
			 * count number of spaces and ochar in buffer
			 */
			if (*buf == ' ') {
				++ips;
				++buf;
				continue;
			}

			/*
			 * simulate ochar processing
			 */
			if (*buf == ochar) {
				ips += gap - (ips % gap);
				++buf;
				continue;
			}

			/*
			 * got a non space char; contract out spaces
			 */
			while (ips - ops > 1) {
				/*
				 * use as many ochar as will fit
				 */
				if ((tbps = ops + gap - (ops % gap)) > ips)
					break;
				if (putchar(ochar) == EOF) {
					pfail();
					return(1);
				}
				ops = tbps;
			}

			while (ops < ips) {
				/*
				 * finish off with spaces
				 */
				if (putchar(' ') == EOF) {
					pfail();
					return(1);
				}
				++ops;
			}

			/*
			 * output non space char
			 */
			if (putchar(*buf++) == EOF) {
				pfail();
				return(1);
			}
			++ips;
			++ops;
		}

		if (mor > 0) {
			/*
			 * if incomplete line, save position counts
			 */
			*svops = ops;
			*svips = ips;
			return(0);
		}

		if (mor < 0) {
			while (ips - ops > 1) {
				/*
				 * use as many ochar as will fit
				 */
				if ((tbps = ops + gap - (ops % gap)) > ips)
					break;
				if (putchar(ochar) == EOF) {
					pfail();
					return(1);
				}
				ops = tbps;
			}
			while (ops < ips) {
				/*
				 * finish off with spaces
				 */
				if (putchar(' ') == EOF) {
					pfail();
					return(1);
				}
				++ops;
			}
			return(0);
		}
	} else {
		/*
		 * output is not contracted
		 */
		if (cnt && (fwrite(buf, sizeof(char), cnt, stdout) <= 0)) {
			pfail();
			return(1);
		}
		if (mor != 0)
			return(0);
	}

	/*
	 * process line end and double space as required
	 */
	if ((putchar('\n') == EOF) || (dspace && (putchar('\n') == EOF))) {
		pfail();
		return(1);
	}
	return(0);
}

/*
 * inskip():	skip over pgcnt pages with lncnt lines per page
 *		file is closed at EOF (if not stdin).
 *
 *	inf	FILE * to read from
 *	pgcnt	number of pages to skip
 *	lncnt	number of lines per page
 */
static int
inskip(FILE *inf, int pgcnt, int lncnt)
{
	int c;
	int cnt;

	while(--pgcnt > 0) {
		cnt = lncnt;
		while ((c = getc(inf)) != EOF) {
			if ((c == '\n') && (--cnt == 0))
				break;
		}
		if (c == EOF) {
			if (inf != stdin)
				(void)fclose(inf);
			return(1);
		}
	}
	return(0);
}

/*
 * nxtfile:	returns a FILE * to next file in arg list and sets the
 *		time field for this file (or current date).
 *
 *	buf	array to store proper date for the header.
 *	dt	if set skips the date processing (used with -m)
 */
static FILE *
nxtfile(int argc, char **argv, const char **fname, char *buf, int dt)
{
	FILE *inf = NULL;
	struct timeval tv;
	struct timezone tz;
	struct tm *timeptr = NULL;
	struct stat statbuf;
	time_t curtime;
	static int twice = -1;

	++twice;
	if (eoptind >= argc) {
		/*
		 * no file listed; default, use standard input
		 */
		if (twice)
			return(NULL);
		clearerr(stdin);
		inf = stdin;
		if (header != NULL)
			*fname = header;
		else
			*fname = FNAME;
		if (nohead)
			return(inf);
		if (gettimeofday(&tv, &tz) < 0) {
			++errcnt;
			(void)fprintf(errf, "pr: cannot get time of day, %s\n",
				strerror(errno));
			eoptind = argc - 1;
			return(NULL);
		}
		curtime = tv.tv_sec;
		timeptr = localtime(&curtime);
	}
	for (; eoptind < argc; ++eoptind) {
		if (strcmp(argv[eoptind], "-") == 0) {
			/*
			 * process a "-" for filename
			 */
			clearerr(stdin);
			inf = stdin;
			if (header != NULL)
				*fname = header;
			else
				*fname = FNAME;
			++eoptind;
			if (nohead || (dt && twice))
				return(inf);
			if (gettimeofday(&tv, &tz) < 0) {
				++errcnt;
				(void)fprintf(errf,
					"pr: cannot get time of day, %s\n",
					strerror(errno));
				return(NULL);
			}
			curtime = tv.tv_sec;
			timeptr = localtime(&curtime);
		} else {
			/*
			 * normal file processing
			 */
			if ((inf = fopen(argv[eoptind], "r")) == NULL) {
				++errcnt;
				if (nodiag)
					continue;
				(void)fprintf(errf, "pr: Cannot open %s, %s\n",
					argv[eoptind], strerror(errno));
				continue;
			}
			if (header != NULL)
				*fname = header;
			else if (dt)
				*fname = FNAME;
			else
				*fname = argv[eoptind];
			++eoptind;
			if (nohead || (dt && twice))
				return(inf);

			if (dt) {
				if (gettimeofday(&tv, &tz) < 0) {
					++errcnt;
					(void)fprintf(errf,
					     "pr: cannot get time of day, %s\n",
					     strerror(errno));
					return(NULL);
				}
				curtime = tv.tv_sec;
				timeptr = localtime(&curtime);
			} else {
				if (fstat(fileno(inf), &statbuf) < 0) {
					++errcnt;
					(void)fclose(inf);
					(void)fprintf(errf, 
						"pr: Cannot stat %s, %s\n",
						argv[eoptind], strerror(errno));
					return(NULL);
				}
				timeptr = localtime(&(statbuf.st_mtime));
			}
		}
		break;
	}
	if (inf == NULL)
		return(NULL);

	/*
	 * set up time field used in header
	 */
	if (strftime(buf, HDBUF, timefrmt, timeptr) <= 0) {
		++errcnt;
		if (inf != stdin)
			(void)fclose(inf);
		(void)fputs("pr: time conversion failed\n", errf);
		return(NULL);
	}
	return(inf);
}

/*
 * addnum():	adds the line number to the column
 *		Truncates from the front or pads with spaces as required.
 *		Numbers are right justified.
 *
 *	buf	buffer to store the number
 *	wdth	width of buffer to fill
 *	line	line number
 *
 *		NOTE: numbers occupy part of the column. The posix
 *		spec does not specify if -i processing should or should not
 *		occur on number padding. The spec does say it occupies
 *		part of the column. The usage of addnum	currently treats
 *		numbers as part of the column so spaces may be replaced.
 */
void
addnum(char *buf, int wdth, int line)
{
	char *pt = buf + wdth;

	do {
		*--pt = digs[line % 10];
		line /= 10;
	} while (line && (pt > buf));

	/*
	 * pad with space as required
	 */
	while (pt > buf)
		*--pt = ' ';
}

/*
 * prpause():	pause before printing each page
 *
 *	pagcnt	page number
 */
static void
prpause(int pagcnt)
{

	if (ttyout) {
		int c;

		(void)putc('\a', stderr);
		(void)fflush(stderr);

		while ((c = getc(ttyinf)) != '\n' && c != EOF)
			;

		/*
		 * pause ONLY before first page of first file
		 */
		if (pgpause == FIRSTPAGE && pagcnt == 1)
			pgpause = NO_PAUSE;
	}
}

/*
 * prhead():	prints the top of page header
 *
 *	buf	buffer with time field (and offset)
 *	cnt	number of chars in buf
 *	fname	fname field for header
 *	pagcnt	page number
 */
static int
prhead(char *buf, const char *fname, int pagcnt)
{
	int ips = 0;
	int ops = 0;

	if ((putchar('\n') == EOF) || (putchar('\n') == EOF)) {
		pfail();
		return(1);
	}
	/*
	 * posix is not clear if the header is subject to line length
	 * restrictions. The specification for header line format
	 * in the spec clearly does not limit length. No pr currently
	 * restricts header length. However if we need to truncate in
	 * a reasonable way, adjust the length of the printf by
	 * changing HDFMT to allow a length max as an argument printf.
	 * buf (which contains the offset spaces and time field could
	 * also be trimmed
	 *
	 * note only the offset (if any) is processed for tab expansion
	 */
	if (offst && otln(buf, offst, &ips, &ops, -1))
		return(1);
	(void)printf(HDFMT,buf+offst, fname, pagcnt);
	return(0);
}

/*
 * prtail():	pad page with empty lines (if required) and print page trailer
 *		if requested
 *
 *	cnt	number of lines of padding needed
 *	incomp	was a '\n' missing from last line output
 */
static int
prtail(int cnt, int incomp)
{
	if (nohead) {
		/*
		 * only pad with no headers when incomplete last line
		 */
		if (!incomp)
			return(0);
		if ((dspace && (putchar('\n') == EOF)) ||
		    (putchar('\n') == EOF)) {
			pfail();
			return(1);
		}
		return(0);
	}

	/*
	 * if double space output two \n
	 */
	if (dspace)
		cnt *= 2;

	/*
	 * if an odd number of lines per page, add an extra \n
	 */
	if (addone)
		++cnt;

	/*
	 * pad page
	 */
	if (formfeed) {
		if ((incomp && (putchar('\n') == EOF)) || 
		    (putchar('\f') == EOF)) {
			pfail();
			return(1);
		}
		return(0);
	} 
	cnt += TAILLEN;
	while (--cnt >= 0) {
		if (putchar('\n') == EOF) {
			pfail();
			return(1);
		}
	}
	return(0);
}

/*
 * terminate():	when a SIGINT is recvd
 */
static void
terminate(int which_sig)
{
	flsh_errs();
	(void)raise_default_signal(which_sig);
	exit(1);
}


/*
 * flsh_errs():	output saved up diagnostic messages after all normal
 *		processing has completed
 */
static void
flsh_errs(void)
{
	char buf[BUFSIZ];

	(void)fflush(stdout);
	(void)fflush(errf);
	if (errf == stderr)
		return;
	rewind(errf);
	while (fgets(buf, BUFSIZ, errf) != NULL)
		(void)fputs(buf, stderr);
}

static void
mfail(void)
{
	(void)fputs("pr: memory allocation failed\n", errf);
}

static void
pfail(void)
{
	(void)fprintf(errf, "pr: write failure, %s\n", strerror(errno));
}

static void
usage(void)
{
	(void)fputs(
	 "usage: pr [+page] [-col] [-adFfmprt] [-e[ch][gap]] [-h header]\n",
		    errf);
	(void)fputs(
	 "          [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",
		    errf);
	(void)fputs(
	 "          [-s[ch]] [-T timefmt] [-w width] [-] [file ...]\n",
		    errf);
}

/*
 * setup:	Validate command args, initialize and perform sanity 
 *		checks on options
 */
static int
setup(int argc, char **argv)
{
	int c;
	int eflag = 0;
	int iflag = 0;
	int wflag = 0;
	int cflag = 0;

	ttyinf = stdin;

	if (isatty(fileno(stdout))) {
		/*
		 * defer diagnostics until processing is done
		 */
		if ((errf = tmpfile()) == NULL) {
		       (void)fputs("Cannot defer diagnostic messages\n",stderr);
		       return(1);
		}
		ttyout = 1;
	} else
		errf = stderr;
	while ((c = egetopt(argc, argv, "#adFfmrte?h:i?l:n?o:ps?T:w:")) != -1) {
		switch (c) {
		case '+':
			if ((pgnm = atoi(eoptarg)) < 1) {
			    (void)fputs("pr: +page number must be 1 or more\n",
				errf);
			    return(1);
			}
			break;
		case '-':
			if ((clcnt = atoi(eoptarg)) < 1) {
			    (void)fputs("pr: -columns must be 1 or more\n",errf);
			    return(1);
			}
			if (clcnt > 1)
				++cflag;
			break;
		case 'a':
			++across;
			break;
		case 'd':
			++dspace;
			break;
		case 'e':
			++eflag;
			if ((eoptarg != NULL) &&
			    !isdigit((unsigned char)*eoptarg))
				inchar = *eoptarg++;
			else
				inchar = INCHAR;
			if ((eoptarg != NULL) &&
			    isdigit((unsigned char)*eoptarg)) {
				if ((ingap = atoi(eoptarg)) < 0) {
					(void)fputs(
					"pr: -e gap must be 0 or more\n", errf);
					return(1);
				}
				if (ingap == 0)
					ingap = INGAP;
			} else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
				(void)fprintf(errf,
				      "pr: invalid value for -e %s\n", eoptarg);
				return(1);
			} else
				ingap = INGAP;
			break;
		case 'f':
			pgpause |= FIRSTPAGE;
			/*FALLTHROUGH*/
		case 'F':
			++formfeed;
			break;
		case 'h':
			header = eoptarg;
			break;
		case 'i':
			++iflag;
			if ((eoptarg != NULL) &&
			    !isdigit((unsigned char)*eoptarg))
				ochar = *eoptarg++;
			else
				ochar = OCHAR;
			if ((eoptarg != NULL) &&
			    isdigit((unsigned char)*eoptarg)) {
				if ((ogap = atoi(eoptarg)) < 0) {
					(void)fputs(
					"pr: -i gap must be 0 or more\n", errf);
					return(1);
				}
				if (ogap == 0)
					ogap = OGAP;
			} else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
				(void)fprintf(errf,
				      "pr: invalid value for -i %s\n", eoptarg);
				return(1);
			} else
				ogap = OGAP;
			break;
		case 'l':
			if (!isdigit((unsigned char)*eoptarg) ||
			    ((lines=atoi(eoptarg)) < 1)) {
				(void)fputs(
				 "pr: Number of lines must be 1 or more\n",errf);
				return(1);
			}
			break;
		case 'm':
			++merge;
			break;
		case 'n':
			if ((eoptarg != NULL) &&
			    !isdigit((unsigned char)*eoptarg))
				nmchar = *eoptarg++;
			else
				nmchar = NMCHAR;
			if ((eoptarg != NULL) &&
			    isdigit((unsigned char)*eoptarg)) {
				if ((nmwd = atoi(eoptarg)) < 1) {
					(void)fputs(
					"pr: -n width must be 1 or more\n",errf);
					return(1);
				}
			} else if ((eoptarg != NULL) && (*eoptarg != '\0')) {
				(void)fprintf(errf,
				      "pr: invalid value for -n %s\n", eoptarg);
				return(1);
			} else
				nmwd = NMWD;
			break;
		case 'o':
			if (!isdigit((unsigned char)*eoptarg) ||
			    ((offst = atoi(eoptarg))< 1)){
				(void)fputs("pr: -o offset must be 1 or more\n",
					errf);
				return(1);
			}
			break;
		case 'p':
			pgpause |= EACHPAGE;
			break;
		case 'r':
			++nodiag;
			break;
		case 's':
			++sflag;
			if (eoptarg == NULL)
				schar = SCHAR;
			else
				schar = *eoptarg++;
			if (eoptarg && *eoptarg != '\0') {
				(void)fprintf(errf,
				      "pr: invalid value for -s %s\n", eoptarg);
				return(1);
			}
			break;
		case 'T':
			timefrmt = eoptarg;
			break;
		case 't':
			++nohead;
			break;
		case 'w':
			++wflag;
			if (!isdigit((unsigned char)*eoptarg) ||
			    ((pgwd = atoi(eoptarg)) < 1)){
				(void)fputs(
				   "pr: -w width must be 1 or more \n",errf);
				return(1);
			}
			break;
		case '?':
		default:
			return(1);
		}
	}

	/*
	 * default and sanity checks
	 */
	if (!clcnt) {
		if (merge) {
			if ((clcnt = argc - eoptind) <= 1) {
				clcnt = CLCNT;
				merge = 0;
			}
		} else
			clcnt = CLCNT;
	}
	if (across) {
		if (clcnt == 1) {
			(void)fputs("pr: -a flag requires multiple columns\n",
				errf);
			return(1);
		}
		if (merge) {
			(void)fputs("pr: -m cannot be used with -a\n", errf);
			return(1);
		}
	}
	if (!wflag) {
		if (sflag)
			pgwd = SPGWD;
		else
			pgwd = PGWD;
	}
	if (cflag || merge) {
		if (!eflag) {
			inchar = INCHAR;
			ingap = INGAP;
		}
		if (!iflag) {
			ochar = OCHAR;
			ogap = OGAP;
		}
	}
	if (cflag) {
		if (merge) {
			(void)fputs(
			  "pr: -m cannot be used with multiple columns\n", errf);
			return(1);
		}
		if (nmwd) {
			colwd = (pgwd + 1 - (clcnt * (nmwd + 2)))/clcnt;
			pgwd = ((colwd + nmwd + 2) * clcnt) - 1;
		} else {
			colwd = (pgwd + 1 - clcnt)/clcnt;
			pgwd = ((colwd + 1) * clcnt) - 1;
		}
		if (colwd < 1) {
			(void)fprintf(errf,
			  "pr: page width is too small for %d columns\n",clcnt);
			return(1);
		}
	}
	if (!lines)
		lines = LINES;

	/*
	 * make sure long enough for headers. if not disable
	 */
	if (lines <= HEADLEN + TAILLEN)
		++nohead;	
	else if (!nohead)
		lines -= HEADLEN + TAILLEN;

	/*
	 * adjust for double space on odd length pages
	 */
	if (dspace) {
		if (lines == 1)
			dspace = 0;
		else {
			if (lines & 1)
				++addone;
			lines /= 2;
		}
	}

	/*
	 * open /dev/tty if we are to pause before each page
	 * but only if stdout is a terminal and stdin is not a terminal
	 */
	if (ttyout && pgpause && !isatty(fileno(stdin))) {
		if ((ttyinf = fopen("/dev/tty", "r")) == NULL) {
			(void)fprintf(errf, "pr: cannot open terminal\n");
			return(1);
		}
	}

	return(0);
}
@


1.26
log
@fix various typos, mainly in comments, but also log messages, docs, game text.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.25 2021/12/05 08:03:07 msaitoh Exp $	*/
d48 1
a48 1
__RCSID("$NetBSD: pr.c,v 1.25 2021/12/05 08:03:07 msaitoh Exp $");
d863 1
a863 1
	 * calculate page boundries based on open file count
d1499 1
a1499 1
	 * an reasonable way, adjust the length of the printf by
@


1.25
log
@s/succesful/successful/ in comment.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.24 2012/08/01 02:27:48 ginsbach Exp $	*/
d48 1
a48 1
__RCSID("$NetBSD: pr.c,v 1.24 2012/08/01 02:27:48 ginsbach Exp $");
d1023 1
a1023 1
 *	cps:	column positon 1st char in buffer (large line support)
@


1.24
log
@Minor tweaks to usage:
- Sort options to match pr(1) SYNOPSIS (suggested by wiz)
- Add missing -T timefmt option
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.23 2012/07/24 02:13:04 ginsbach Exp $	*/
d48 1
a48 1
__RCSID("$NetBSD: pr.c,v 1.23 2012/07/24 02:13:04 ginsbach Exp $");
d844 1
a844 1
	 * of the merge operation (-m) in relation to unsuccesful file opens
@


1.23
log
@- Fix PR 19468 by adding -f and -p options to pr(1).
  Changes adapted from patch by Ryan Younce and FreeBSD.  The provided
  patch was not used directly as the changes didn't mimic the System V
  origins of these options.  System V pr(1) does not pause for empty files.
  These changes follow that precedent.

- Improve man page description of the -i option.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.22 2012/03/12 18:06:24 christos Exp $	*/
d48 1
a48 1
__RCSID("$NetBSD: pr.c,v 1.22 2012/03/12 18:06:24 christos Exp $");
d1615 2
a1616 1
	 "usage: pr [+page] [-col] [-adFmrt] [-e[ch][gap]] [-h header]\n",errf);
d1618 2
a1619 1
	 "          [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",errf);
d1621 2
a1622 1
	 "          [-s[ch]] [-w width] [-fp] [-] [file ...]\n", errf);
@


1.22
log
@PR/41880: Ralph G. Previous fix for PR/5797 broke since space separator.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.21 2011/09/06 18:26:06 joerg Exp $	*/
d7 2
d48 1
a48 1
__RCSID("$NetBSD: pr.c,v 1.21 2011/09/06 18:26:06 joerg Exp $");
d101 1
d103 1
d106 1
d128 1
d251 8
a258 3
				if (!linecnt && !nohead &&
					prhead(hbuf, fname, pagecnt))
					goto out;
d523 3
d595 7
a601 2
			if (pln && !nohead && prhead(hbuf, fname, pagecnt))
				goto out;
d753 8
a760 3
				if (!i && !nohead &&
					prhead(hbuf, fname, pagecnt))
					goto out;
d968 7
a974 2
			if (!i && !nohead && prhead(hbuf, fname, pagecnt))
				goto out;
d1451 26
d1619 1
a1619 1
	 "          [-s[ch]] [-w width] [-] [file ...]\n", errf);
d1635 2
d1645 1
d1648 1
a1648 1
	while ((c = egetopt(argc, argv, "#adFmrte?h:i?l:n?o:s?T:w:")) != -1) {
d1694 3
d1765 3
d1886 11
@


1.21
log
@ANSIfy, static + __dead
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.20 2009/04/13 00:37:05 lukem Exp $	*/
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.20 2009/04/13 00:37:05 lukem Exp $");
d1141 1
a1141 8
			while (ops < ips) {
				/*
				 * use one space if necessary
				 */
				if (ips - ops == 1) {
					putchar(' ');
					break;
				}
d1186 1
a1186 8
			while (ops < ips) {
				/*
				 * use one space if necessary
				 */
				if (ips - ops == 1) {
					putchar(' ');
					break;
				}
@


1.21.2.1
log
@sync with head
@
text
@d1 1
a1 1
/*	$NetBSD$	*/
d46 1
a46 1
__RCSID("$NetBSD$");
d1141 8
a1148 1
			while (ips - ops > 1) {
d1193 8
a1200 1
			while (ips - ops > 1) {
@


1.21.2.2
log
@sync with head
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.21.2.1 2012/04/17 00:09:38 yamt Exp $	*/
a6 2
 * Copyright (c) 2012
 *	The NetBSD Foundation, Inc.
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.21.2.1 2012/04/17 00:09:38 yamt Exp $");
a98 1
static int	ttyout;			/* output is a tty */
a99 1
static int	pgpause;		/* pause before each page */
a101 1
static FILE	*ttyinf;		/* input terminal for page pauses */
a122 1
static void	 prpause(int);
d245 3
a247 8
				if (!linecnt) {
					if (pgpause)
						prpause(pagecnt);

				        if (!nohead &&
					    prhead(hbuf, fname, pagecnt))
						goto out;
				}
a511 3
				if (pgpause)
					prpause(pagecnt);

d581 2
a582 7
			if (pln) {
				if (pgpause)
					prpause(pagecnt);

			        if (!nohead && prhead(hbuf, fname, pagecnt))
					goto out;
			}
d734 3
a736 8
				if (!i) {
					if (pgpause)
						prpause(pagecnt);

				        if (!nohead &&
					    prhead(hbuf, fname, pagecnt))
						goto out;
				}
d944 2
a945 7
			if (!i) {
				if (pgpause)
					prpause(pagecnt);

			        if (!nohead && prhead(hbuf, fname, pagecnt))
					goto out;
			}
a1421 26
 * prpause():	pause before printing each page
 *
 *	pagcnt	page number
 */
static void
prpause(int pagcnt)
{

	if (ttyout) {
		int c;

		(void)putc('\a', stderr);
		(void)fflush(stderr);

		while ((c = getc(ttyinf)) != '\n' && c != EOF)
			;

		/*
		 * pause ONLY before first page of first file
		 */
		if (pgpause == FIRSTPAGE && pagcnt == 1)
			pgpause = NO_PAUSE;
	}
}

/*
d1560 1
a1560 2
	 "usage: pr [+page] [-col] [-adFfmprt] [-e[ch][gap]] [-h header]\n",
		    errf);
d1562 1
a1562 2
	 "          [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",
		    errf);
d1564 1
a1564 2
	 "          [-s[ch]] [-T timefmt] [-w width] [-] [file ...]\n",
		    errf);
a1579 2
	ttyinf = stdin;

a1587 1
		ttyout = 1;
d1590 1
a1590 1
	while ((c = egetopt(argc, argv, "#adFfmrte?h:i?l:n?o:ps?T:w:")) != -1) {
a1635 3
		case 'f':
			pgpause |= FIRSTPAGE;
			/*FALLTHROUGH*/
a1703 3
		case 'p':
			pgpause |= EACHPAGE;
			break;
a1821 11
	/*
	 * open /dev/tty if we are to pause before each page
	 * but only if stdout is a terminal and stdin is not a terminal
	 */
	if (ttyout && pgpause && !isatty(fileno(stdin))) {
		if ((ttyinf = fopen("/dev/tty", "r")) == NULL) {
			(void)fprintf(errf, "pr: cannot open terminal\n");
			return(1);
		}
	}

@


1.20
log
@Fix -Wcast-qual issues
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.19 2008/07/21 14:19:24 lukem Exp $	*/
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.19 2008/07/21 14:19:24 lukem Exp $");
d80 22
a101 22
int	pgnm;			/* starting page number */
int	clcnt;			/* number of columns */
int	colwd;			/* column data width - multiple columns */
int	across;			/* mult col flag; write across page */
int	dspace;			/* double space flag */
char	inchar;			/* expand input char */
int	ingap;			/* expand input gap */
int	formfeed;		/* use formfeed as trailer */
char	*header;		/* header name instead of file name */
char	ochar;			/* contract output char */
int	ogap;			/* contract output gap */
int	lines;			/* number of lines per page */
int	merge;			/* merge multiple files in output */
char	nmchar;			/* line numbering append char */
int	nmwd;			/* width of line number field */
int	offst;			/* number of page offset spaces */
int	nodiag;			/* do not report file open errors */
char	schar;			/* text column separation character */
int	sflag;			/* -s option for multiple columns */
int	nohead;			/* do not write head and trailer */
int	pgwd;			/* page width with multiple col output */
const char *timefrmt = TIMEFMT;	/* time conversion string */
d106 22
a127 6
FILE	*err;			/* error message file pointer */
int	addone;			/* page length is odd with double space */
int	errcnt;			/* error count on file processing */
char	digs[] = "0123456789";	/* page number translation map */

int	main __P((int, char **));
d130 1
a130 3
main(argc, argv)
        int argc;
        char *argv[];
d161 2
a162 4
int
onecol(argc, argv)
        int argc;
        char *argv[];
d300 2
a301 4
	if (obuf)
		free(obuf);
	if (hbuf)
		free(hbuf);
d310 2
a311 4
int
vertcol(argc, argv)
        int argc;
        char *argv[];
d618 5
a622 10
	if (buf)
		free(buf);
	if (hbuf)
		free(hbuf);
	if (vc)
		free(vc);
	if (lstdat)
		free(lstdat);
	if (indy)
		free(lindy);
d631 2
a632 4
int
horzcol(argc, argv)
        int argc;
        char *argv[];
d767 2
a768 4
	if (buf)
		free(buf);
	if (hbuf)
		free(hbuf);
d778 2
a779 4
int
mulfile(argc, argv)
        int argc;
        char *argv[];
d850 1
a850 1
		(void)fprintf(err,
d982 2
a983 4
	if (hbuf)
		free(hbuf);
	if (buf)
		free(buf);
d998 2
a999 8
int
inln(inf, buf, lim, cps, trnc, mor)
	FILE *inf;
	char *buf;
	int lim;
	int *cps;
	int trnc;
	int *mor;
d1103 2
a1104 7
int
otln(buf, cnt, svips, svops, mor)
	char *buf;
	int cnt;
	int *svops;
	int *svips;
	int mor;
d1254 2
a1255 5
int
inskip(inf, pgcnt, lncnt)
	FILE *inf;
	int pgcnt;
	int lncnt;
d1282 2
a1283 7
FILE *
nxtfile(argc, argv, fname, buf, dt)
	int argc;
	char **argv;
	const char **fname;
	char *buf;
	int dt;
d1310 1
a1310 1
			(void)fprintf(err, "pr: cannot get time of day, %s\n",
d1334 1
a1334 1
				(void)fprintf(err,
d1349 1
a1349 1
				(void)fprintf(err, "pr: Cannot open %s, %s\n",
d1366 1
a1366 1
					(void)fprintf(err,
d1377 1
a1377 1
					(void)fprintf(err, 
d1397 1
a1397 1
		(void)fputs("pr: time conversion failed\n", err);
d1419 1
a1419 4
addnum(buf, wdth, line)
	char *buf;
	int wdth;
	int line;
d1443 2
a1444 5
int
prhead(buf, fname, pagcnt)
	char *buf;
	const char *fname;
	int pagcnt;
d1478 2
a1479 4
int
prtail(cnt, incomp)
	int cnt;
	int incomp;
d1531 2
a1532 3
void
terminate(which_sig)
	int which_sig;
d1544 2
a1545 2
void
flsh_errs()
d1550 2
a1551 2
	(void)fflush(err);
	if (err == stderr)
d1553 2
a1554 2
	rewind(err);
	while (fgets(buf, BUFSIZ, err) != NULL)
d1558 2
a1559 2
void
mfail()
d1561 1
a1561 1
	(void)fputs("pr: memory allocation failed\n", err);
d1564 2
a1565 2
void
pfail()
d1567 1
a1567 1
	(void)fprintf(err, "pr: write failure, %s\n", strerror(errno));
d1570 2
a1571 2
void
usage()
d1574 1
a1574 1
	 "usage: pr [+page] [-col] [-adFmrt] [-e[ch][gap]] [-h header]\n",err);
d1576 1
a1576 1
	 "          [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",err);
d1578 1
a1578 1
	 "          [-s[ch]] [-w width] [-] [file ...]\n", err);
d1585 2
a1586 4
int
setup(argc, argv)
	int argc;
	char **argv;
d1598 1
a1598 1
		if ((err = tmpfile()) == NULL) {
d1603 1
a1603 1
		err = stderr;
d1609 1
a1609 1
				err);
d1615 1
a1615 1
			    (void)fputs("pr: -columns must be 1 or more\n",err);
d1638 1
a1638 1
					"pr: -e gap must be 0 or more\n", err);
d1644 1
a1644 1
				(void)fprintf(err,
d1667 1
a1667 1
					"pr: -i gap must be 0 or more\n", err);
d1673 1
a1673 1
				(void)fprintf(err,
d1683 1
a1683 1
				 "pr: Number of lines must be 1 or more\n",err);
d1700 1
a1700 1
					"pr: -n width must be 1 or more\n",err);
d1704 1
a1704 1
				(void)fprintf(err,
d1714 1
a1714 1
					err);
d1728 1
a1728 1
				(void)fprintf(err,
d1744 1
a1744 1
				   "pr: -w width must be 1 or more \n",err);
d1769 1
a1769 1
				err);
d1773 1
a1773 1
			(void)fputs("pr: -m cannot be used with -a\n", err);
d1796 1
a1796 1
			  "pr: -m cannot be used with multiple columns\n", err);
d1807 1
a1807 1
			(void)fprintf(err,
@


1.19
log
@Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.18 2007/10/14 11:21:32 lukem Exp $	*/
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.18 2007/10/14 11:21:32 lukem Exp $");
d101 1
a101 1
char	*timefrmt = TIMEFMT;	/* time conversion string */
d168 1
a168 1
	char *fname;
d328 1
a328 1
	char *fname;
d645 1
a645 1
	char *fname;
d799 1
a799 1
	char *fname;
d1305 1
a1305 1
	char **fname;
d1473 1
a1473 1
	char *fname;
@


1.19.6.1
log
@Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.20 2009/04/13 00:37:05 lukem Exp $	*/
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.20 2009/04/13 00:37:05 lukem Exp $");
d101 1
a101 1
const char *timefrmt = TIMEFMT;	/* time conversion string */
d168 1
a168 1
	const char *fname;
d328 1
a328 1
	const char *fname;
d645 1
a645 1
	const char *fname;
d799 1
a799 1
	const char *fname;
d1305 1
a1305 1
	const char **fname;
d1473 1
a1473 1
	const char *fname;
@


1.18
log
@Convert to using raise_default_signal(3).
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.17 2007/04/29 20:23:37 msaitoh Exp $	*/
d38 2
a39 2
__COPYRIGHT("@@(#) Copyright (c) 1993\n\
	The Regents of the University of California.  All rights reserved.\n");
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.17 2007/04/29 20:23:37 msaitoh Exp $");
@


1.18.8.1
log
@Sync with wrstuden-revivesa-base-2.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.18 2007/10/14 11:21:32 lukem Exp $	*/
d38 2
a39 2
__COPYRIGHT("@@(#) Copyright (c) 1993\
 The Regents of the University of California.  All rights reserved.");
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.18 2007/10/14 11:21:32 lukem Exp $");
@


1.17
log
@fix typos
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.16 2006/05/24 15:59:06 christos Exp $	*/
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.16 2006/05/24 15:59:06 christos Exp $");
d62 1
d1568 1
@


1.17.4.1
log
@sync with HEAD
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.18 2007/10/14 11:21:32 lukem Exp $	*/
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.18 2007/10/14 11:21:32 lukem Exp $");
a61 1
#include <util.h>
a1566 1
	(void)raise_default_signal(which_sig);
@


1.16
log
@Coverity CID 3212: Don't return, goto out in all cases so that cleanup
happens.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.15 2006/05/01 23:31:10 christos Exp $	*/
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.15 2006/05/01 23:31:10 christos Exp $");
d1488 1
a1488 1
	 * changing HDFMT to allow a length max as an arguement printf.
@


1.15
log
@Coverity CID 2989: Use the error path to return.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.14 2006/04/02 04:17:08 christos Exp $	*/
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.14 2006/04/02 04:17:08 christos Exp $");
d539 1
a539 1
							return(1);
@


1.15.2.1
log
@Sync with head.
@
text
@d1 1
a1 1
/*	$NetBSD$	*/
d46 1
a46 1
__RCSID("$NetBSD$");
d539 1
a539 1
							goto out;
@


1.14
log
@Coverity CID 1660: Plug memory leaks.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.13 2005/12/28 21:29:16 christos Exp $	*/
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.13 2005/12/28 21:29:16 christos Exp $");
d511 4
a514 2
					if (offst&& otln(buf,offst,&ips,&ops,1))
						return(1);
@


1.13
log
@PR/32402: Jeffrey Bedard: pr filter dumps core with -s option specified,
when -s is specified with no argument. Option arguments in pr (as documented)
need to immediately follow the option. For example to set the separator char
to `.' you need to use "pr -s." instread of "pr -s .". The second form sets
the separator character to tab, and reads from file `.'. Coredumping is wrong
anyway, so fix that. Grr to POSIX for not forcing pr and a few other utilities
to use getopt(3).
cvs: ----------------------------------------------------------------------
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.12 2003/10/13 07:41:22 agc Exp $	*/
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.12 2003/10/13 07:41:22 agc Exp $");
d161 1
a161 1
	char *obuf;
d164 1
a164 1
	char *hbuf;
d166 1
a166 1
	FILE *inf;
d169 1
d180 2
a181 4
	if ((obuf = malloc((unsigned)(LBUF + off)*sizeof(char))) == NULL) {
		mfail();
		return(1);
	}
d185 2
a186 4
	if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
		mfail();
		return(1);
	}
d234 1
a234 1
					return(1);
d243 1
a243 1
						return(1);
d245 1
a245 1
					return(1);
d268 1
a268 1
				return(1);
d281 13
a293 2
		return(1);
	return(0);
d305 1
a305 1
	char **lstdat;
d310 1
a310 1
	int *indy;
d312 1
a312 1
	int *lindy;
d319 1
a319 1
	struct vcol *vc;
d324 2
a325 2
	char *buf;
	char *hbuf;
d328 1
a328 1
	FILE *inf;
d333 1
d338 2
a339 4
	if ((buf = malloc((unsigned)lines*mxlen*sizeof(char))) == NULL) {
		mfail();
		return(1);
	}
d344 2
a345 4
	if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
		mfail();
		return(1);
	}
d354 2
a355 5
	if ((vc =
	    (struct vcol *)malloc((unsigned)mvc*sizeof(struct vcol))) == NULL) {
		mfail();
		return(1);
	}
d360 2
a361 4
	if ((lstdat = (char **)malloc((unsigned)lines*sizeof(char *))) == NULL){
		mfail();
		return(1);
	}
d366 4
a369 8
	if ((indy = (int *)malloc((unsigned)lines*sizeof(int))) == NULL) {
		mfail();
		return(1);
	}
	if ((lindy = (int *)malloc((unsigned)lines*sizeof(int))) == NULL) {
		mfail();
		return(1);
	}
d507 1
a507 1
					return(1);
d546 1
a546 1
						return(1);
d552 1
a552 1
					return(1);
d571 1
a571 1
				return(1);
d581 1
a581 1
					return(1);
d588 1
a588 1
				return(1);
d601 19
a619 2
		return(1);
	return(0);
d639 2
a640 2
	char *buf;
	char *hbuf;
d643 1
a643 1
	FILE *inf;
d648 1
d650 2
a651 4
	if ((buf = malloc((unsigned)(pgwd+offst+1)*sizeof(char))) == NULL) {
		mfail();
		return(1);
	}
d656 2
a657 4
	if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
		mfail();
		return(1);
	}
d732 1
a732 1
					return(1);
d737 1
a737 1
					return(1);
d744 1
a744 1
				return(1);
d757 13
a769 2
		return(1);
	return(0);
d787 1
a787 1
	FILE **fbuf;
d793 2
a794 2
	char *buf;
	char *hbuf;
d801 1
d806 2
a807 4
	if ((fbuf = (FILE **)malloc((unsigned)clcnt*sizeof(FILE *))) == NULL) {
		mfail();
		return(1);
	}
d812 2
a813 4
	if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) {
		mfail();
		return(1);
	}
d836 1
a836 1
		return(1);
d852 1
a852 1
		return(1);
d860 2
a861 4
	if ((buf = malloc((unsigned)(pgwd+offst+1)*sizeof(char))) == NULL) {
		mfail();
		return(1);
	}
d945 1
a945 1
				return(1);
d951 1
a951 1
				return(1);
d966 1
a966 1
			return(1);
d970 17
a986 2
		return(1);
	return(0);
@


1.12
log
@Move Keith Muller's code from a 4-clause to a 3-clause licence by removing
the advertising clause. Diffs provided in PR 22397 by Joel Baker, confirmed
to the board by Keith Muller.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.11 2003/08/07 11:15:30 agc Exp $	*/
d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.11 2003/08/07 11:15:30 agc Exp $");
d1727 1
a1727 1
			if (*eoptarg != '\0') {
@


1.11
log
@Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22365, verified by myself.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.10 2001/07/22 13:34:13 wiz Exp $	*/
d4 1
a35 35
/*-
 * Copyright (c) 1991 Keith Muller.
 *
 * 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.
 * 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.
 */

d46 1
a46 1
__RCSID("$NetBSD: pr.c,v 1.10 2001/07/22 13:34:13 wiz Exp $");
@


1.10
log
@seperate -> separate
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.9 2000/10/22 15:06:52 kleink Exp $	*/
a3 1
 * Copyright (c) 1991 Keith Muller.
d18 31
d80 1
a80 1
__RCSID("$NetBSD: pr.c,v 1.9 2000/10/22 15:06:52 kleink Exp $");
@


1.9
log
@Don't be silly and try to read an strftime() format string from the LC_TIME
environment variable; since there isn't a standard format provided by the
C library that corresponds to pr's default header format, add a new option
'-T' to take a strftime() format string if desired.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.8 2000/07/13 02:07:53 simonb Exp $	*/
d50 1
a50 1
__RCSID("$NetBSD: pr.c,v 1.8 2000/07/13 02:07:53 simonb Exp $");
d73 1
a73 1
 *	output. By default, input is seperated into 66-line pages, each
@


1.8
log
@For the -i option, don't convert a single space before a tab stop to a
tab.  Fixes PR bin/5797 from Todd Vierling.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.7 1998/12/19 20:16:50 christos Exp $	*/
d50 1
a50 1
__RCSID("$NetBSD: pr.c,v 1.7 1998/12/19 20:16:50 christos Exp $");
d104 1
a104 1
char	*timefrmt;		/* time conversion string */
d1608 1
a1608 1
	while ((c = egetopt(argc, argv, "#adFmrte?h:i?l:n?o:s?w:")) != -1) {
d1737 3
a1839 2
	if ((timefrmt = getenv("LC_TIME")) == NULL)
		timefrmt = TIMEFMT;
@


1.7
log
@char -> unsigned char
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.6 1998/04/02 10:42:51 kleink Exp $	*/
d50 1
a50 1
__RCSID("$NetBSD: pr.c,v 1.6 1998/04/02 10:42:51 kleink Exp $");
d1129 7
d1180 7
@


1.7.10.1
log
@Pull up rev 1.8 from trunk:
 For the -i option, don't convert a single space before a tab stop to a
 tab.  Fixes PR bin/5797 from Todd Vierling.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.7 1998/12/19 20:16:50 christos Exp $	*/
d50 1
a50 1
__RCSID("$NetBSD: pr.c,v 1.7 1998/12/19 20:16:50 christos Exp $");
a1128 7
				 * use one space if necessary
				 */
				if (ips - ops == 1) {
					putchar(' ');
					break;
				}
				/*
a1172 7
				/*
				 * use one space if necessary
				 */
				if (ips - ops == 1) {
					putchar(' ');
					break;
				}
@


1.7.10.2
log
@Pullup 1.9 [kleink]:
Don't abuse LC_TIME for strftime(3) format strings.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.7.10.1 2000/07/13 03:23:33 simonb Exp $	*/
d50 1
a50 1
__RCSID("$NetBSD: pr.c,v 1.7.10.1 2000/07/13 03:23:33 simonb Exp $");
d104 1
a104 1
char	*timefrmt = TIMEFMT;	/* time conversion string */
d1608 1
a1608 1
	while ((c = egetopt(argc, argv, "#adFmrte?h:i?l:n?o:s?T:w:")) != -1) {
a1736 3
		case 'T':
			timefrmt = eoptarg;
			break;
d1837 2
@


1.6
log
@Need <time.h> for localtime() and strftime() prototypes.
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.5 1997/10/19 12:42:10 lukem Exp $	*/
d50 1
a50 1
__RCSID("$NetBSD: pr.c,v 1.5 1997/10/19 12:42:10 lukem Exp $");
d1619 2
a1620 1
			if ((eoptarg != NULL) && !isdigit(*eoptarg))
d1624 2
a1625 1
			if ((eoptarg != NULL) && isdigit(*eoptarg)) {
d1648 2
a1649 1
			if ((eoptarg != NULL) && !isdigit(*eoptarg))
d1653 2
a1654 1
			if ((eoptarg != NULL) && isdigit(*eoptarg)) {
d1670 2
a1671 1
			if (!isdigit(*eoptarg) || ((lines=atoi(eoptarg)) < 1)) {
d1681 2
a1682 1
			if ((eoptarg != NULL) && !isdigit(*eoptarg))
d1686 2
a1687 1
			if ((eoptarg != NULL) && isdigit(*eoptarg)) {
d1701 2
a1702 1
			if (!isdigit(*eoptarg) || ((offst = atoi(eoptarg))< 1)){
d1728 2
a1729 1
			if (!isdigit(*eoptarg) || ((pgwd = atoi(eoptarg)) < 1)){
@


1.5
log
@WARNSify, fix .Nm usage, deprecate register
@
text
@d1 1
a1 1
/*	$NetBSD: pr.c,v 1.4 1997/01/09 15:01:36 tls Exp $	*/
d50 1
a50 1
__RCSID("$NetBSD$");
d64 1
@


1.4
log
@RCS ID police
@
text
@d1 1
a1 1
/*	$NetBSD$	*/
d40 1
d42 2
a43 3
static char copyright[] =
"@@(#) Copyright (c) 1993\n\
	The Regents of the University of California.  All rights reserved.\n";
d47 5
a51 2
/* from: static char sccsid[] = "@@(#)pr.c	8.1 (Berkeley) 6/6/93"; */
static char *rcsid = "$NetBSD: pr.c,v 1.3 1995/06/07 16:10:11 cgd Exp $";
d113 2
d154 5
a158 5
	register int cnt = -1;
	register int off;
	register int lrgln;
	register int linecnt;
	register int num;
d299 7
a305 7
	register char *ptbf;
	register char **lstdat;
	register int i;
	register int j;
	register int cnt = -1;
	register int pln;
	register int *indy;
d620 7
a626 7
	register char *ptbf;
	register int pln;
	register int cnt = -1;
	register char *lstdat;
	register int col = colwd + 1;
	register int j;
	register int i;
d763 6
a768 6
	register char *ptbf;
	register int j;
	register int pln;
	register int cnt;
	register char *lstdat;
	register int i;
d976 1
a976 1
	register int lim;
d981 5
a985 5
	register int col;
	register int gap = ingap;
	register int ch = EOF;
	register char *ptbuf;
	register int chk = (int)inchar;
d1085 1
a1085 1
	register char *buf;
d1091 5
a1095 5
	register int ops;		/* last col output */
	register int ips;		/* last col in buf examined */
	register int gap = ogap;
	register int tbps;
	register char *endbuf;
d1228 2
a1229 2
	register int pgcnt;
	register int lncnt;
d1231 2
a1232 2
	register int c;
	register int cnt;
d1399 3
a1401 3
	register char *buf;
	register int wdth;
	register int line;
d1403 1
a1403 1
	register char *pt = buf + wdth;
d1465 1
a1465 1
	register int cnt;
d1574 2
a1575 2
	register int argc;
	register char **argv;
d1577 1
a1577 1
	register int c;
d1593 1
a1593 1
	while ((c = egetopt(argc, argv, "#adFmrte?h:i?l:n?o:s?w:")) != EOF) {
@


1.3
log
@can't assume that timeval.ts_sec is same type as time_t.  grr.
@
text
@d1 2
d48 1
a48 1
static char *rcsid = "$Id: pr.c,v 1.2 1994/03/07 05:42:17 cgd Exp $";
@


1.2
log
@from John F. Woods <jfw@@ksr.com>:
don't crap out if -w specified and not in multi-column mode.
my reading of my draft of P.2 indicates that this is allowed, just
ignored...
@
text
@d46 1
a46 1
static char *rcsid = "$Id: pr.c,v 1.1 1994/01/06 15:57:25 cgd Exp $";
d1262 1
d1287 2
a1288 1
		timeptr = localtime(&(tv.tv_sec));
d1311 2
a1312 1
			timeptr = localtime(&(tv.tv_sec));
d1343 2
a1344 1
				timeptr = localtime(&(tv.tv_sec));
@


1.1
log
@add berkeley pr
@
text
@d46 1
a46 1
static char *rcsid = "$Id$";
a1747 3
	} else if (clcnt == 1) {
		(void)fputs("pr: -w requires multiple columns\n", err);
		return(1);
@


1.1.1.1
log
@Import from 4.4BSD-Lite2
@
text
@d45 2
a46 1
static char sccsid[] = "@@(#)pr.c	8.3 (Berkeley) 10/9/94";
d103 1
a103 1
FILE	*errf;			/* error message file pointer */
d828 1
a828 1
		(void)fprintf(errf,
d1281 1
a1281 1
			(void)fprintf(errf, "pr: cannot get time of day, %s\n",
d1304 1
a1304 1
				(void)fprintf(errf,
d1318 1
a1318 1
				(void)fprintf(errf, "pr: Cannot open %s, %s\n",
d1335 1
a1335 1
					(void)fprintf(errf,
d1345 1
a1345 1
					(void)fprintf(errf, 
d1365 1
a1365 1
		(void)fputs("pr: time conversion failed\n", errf);
d1526 2
a1527 2
	(void)fflush(errf);
	if (errf == stderr)
d1529 2
a1530 2
	rewind(errf);
	while (fgets(buf, BUFSIZ, errf) != NULL)
d1537 1
a1537 1
	(void)fputs("pr: memory allocation failed\n", errf);
d1543 1
a1543 1
	(void)fprintf(errf, "pr: write failure, %s\n", strerror(errno));
d1550 1
a1550 2
	 "usage: pr [+page] [-col] [-adFmrt] [-e[ch][gap]] [-h header]\n",
	 errf);
d1552 1
a1552 2
	 "          [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",
	 errf);
d1554 1
a1554 1
	 "          [-s[ch]] [-w width] [-] [file ...]\n", errf);
d1576 1
a1576 1
		if ((errf = tmpfile()) == NULL) {
d1581 1
a1581 1
		errf = stderr;
d1587 1
a1587 1
				errf);
d1593 1
a1593 2
			    (void)fputs("pr: -columns must be 1 or more\n",
			    	errf);
d1614 1
a1614 1
					"pr: -e gap must be 0 or more\n", errf);
d1620 1
a1620 1
				(void)fprintf(errf,
d1641 1
a1641 1
					"pr: -i gap must be 0 or more\n", errf);
d1647 1
a1647 1
				(void)fprintf(errf,
d1656 1
a1656 1
				 "pr: Number of lines must be 1 or more\n",errf);
d1671 1
a1671 1
					"pr: -n width must be 1 or more\n",errf);
d1675 1
a1675 1
				(void)fprintf(errf,
d1684 1
a1684 1
					errf);
d1698 1
a1698 1
				(void)fprintf(errf,
d1710 1
a1710 1
				   "pr: -w width must be 1 or more \n",errf);
d1735 1
a1735 1
				errf);
d1739 1
a1739 1
			(void)fputs("pr: -m cannot be used with -a\n", errf);
d1748 3
d1765 1
a1765 1
			  "pr: -m cannot be used with multiple columns\n", errf);
d1776 1
a1776 1
			(void)fprintf(errf,
@
