pr.c (37262) | pr.c (53948) |
---|---|
1/*- 2 * Copyright (c) 1991 Keith Muller. 3 * Copyright (c) 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Keith Muller of the University of California, San Diego. 8 * --- 19 unchanged lines hidden (view full) --- 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. | 1/*- 2 * Copyright (c) 1991 Keith Muller. 3 * Copyright (c) 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Keith Muller of the University of California, San Diego. 8 * --- 19 unchanged lines hidden (view full) --- 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. |
36 * 37 * $FreeBSD: head/usr.bin/pr/pr.c 53948 1999-11-30 09:41:01Z ache $ |
|
36 */ 37 38#ifndef lint 39static char copyright[] = 40"@(#) Copyright (c) 1993\n\ 41 The Regents of the University of California. All rights reserved.\n"; 42#endif /* not lint */ 43 44#ifndef lint 45static char sccsid[] = "@(#)pr.c 8.2 (Berkeley) 4/16/94"; 46#endif /* not lint */ 47 48#include <sys/types.h> 49#include <sys/time.h> 50#include <sys/stat.h> 51 52#include <ctype.h> 53#include <errno.h> | 38 */ 39 40#ifndef lint 41static char copyright[] = 42"@(#) Copyright (c) 1993\n\ 43 The Regents of the University of California. All rights reserved.\n"; 44#endif /* not lint */ 45 46#ifndef lint 47static char sccsid[] = "@(#)pr.c 8.2 (Berkeley) 4/16/94"; 48#endif /* not lint */ 49 50#include <sys/types.h> 51#include <sys/time.h> 52#include <sys/stat.h> 53 54#include <ctype.h> 55#include <errno.h> |
56#include <locale.h> |
|
54#include <signal.h> 55#include <stdio.h> 56#include <stdlib.h> 57#include <string.h> 58#include <unistd.h> 59 60#include "pr.h" 61#include "extern.h" --- 1490 unchanged lines hidden (view full) --- 1552{ 1553 (void)fprintf(err, "pr: write failure, %s\n", strerror(errno)); 1554} 1555 1556void 1557usage() 1558{ 1559 (void)fputs( | 57#include <signal.h> 58#include <stdio.h> 59#include <stdlib.h> 60#include <string.h> 61#include <unistd.h> 62 63#include "pr.h" 64#include "extern.h" --- 1490 unchanged lines hidden (view full) --- 1555{ 1556 (void)fprintf(err, "pr: write failure, %s\n", strerror(errno)); 1557} 1558 1559void 1560usage() 1561{ 1562 (void)fputs( |
1560 "usage: pr [+page] [-col] [-adFmrt] [-e[ch][gap]] [-h header]\n",err); | 1563 "usage: pr [+page] [-col] [-adFLmrt] [-e[ch][gap]] [-h header]\n",err); |
1561 (void)fputs( 1562 " [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",err); 1563 (void)fputs( 1564 " [-s[ch]] [-w width] [-] [file ...]\n", err); 1565} 1566 1567/* 1568 * setup: Validate command args, initialize and perform sanity --- 4 unchanged lines hidden (view full) --- 1573 register int argc; 1574 register char **argv; 1575{ 1576 register int c; 1577 int eflag = 0; 1578 int iflag = 0; 1579 int wflag = 0; 1580 int cflag = 0; | 1564 (void)fputs( 1565 " [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]\n",err); 1566 (void)fputs( 1567 " [-s[ch]] [-w width] [-] [file ...]\n", err); 1568} 1569 1570/* 1571 * setup: Validate command args, initialize and perform sanity --- 4 unchanged lines hidden (view full) --- 1576 register int argc; 1577 register char **argv; 1578{ 1579 register int c; 1580 int eflag = 0; 1581 int iflag = 0; 1582 int wflag = 0; 1583 int cflag = 0; |
1584 int Lflag = 0; |
|
1581 1582 if (isatty(fileno(stdout))) { 1583 /* 1584 * defer diagnostics until processing is done 1585 */ 1586 if ((err = tmpfile()) == NULL) { 1587 (void)fputs("Cannot defer diagnostic messages\n",stderr); 1588 return(1); 1589 } 1590 } else 1591 err = stderr; | 1585 1586 if (isatty(fileno(stdout))) { 1587 /* 1588 * defer diagnostics until processing is done 1589 */ 1590 if ((err = tmpfile()) == NULL) { 1591 (void)fputs("Cannot defer diagnostic messages\n",stderr); 1592 return(1); 1593 } 1594 } else 1595 err = stderr; |
1592 while ((c = egetopt(argc, argv, "#adFmrte?h:i?l:n?o:s?w:")) != -1) { | 1596 while ((c = egetopt(argc, argv, "#adFmrte?h:i?Ll:n?o:s?w:")) != -1) { |
1593 switch (c) { 1594 case '+': 1595 if ((pgnm = atoi(eoptarg)) < 1) { 1596 (void)fputs("pr: +page number must be 1 or more\n", 1597 err); 1598 return(1); 1599 } 1600 break; --- 8 unchanged lines hidden (view full) --- 1609 case 'a': 1610 ++across; 1611 break; 1612 case 'd': 1613 ++dspace; 1614 break; 1615 case 'e': 1616 ++eflag; | 1597 switch (c) { 1598 case '+': 1599 if ((pgnm = atoi(eoptarg)) < 1) { 1600 (void)fputs("pr: +page number must be 1 or more\n", 1601 err); 1602 return(1); 1603 } 1604 break; --- 8 unchanged lines hidden (view full) --- 1613 case 'a': 1614 ++across; 1615 break; 1616 case 'd': 1617 ++dspace; 1618 break; 1619 case 'e': 1620 ++eflag; |
1617 if ((eoptarg != NULL) && !isdigit(*eoptarg)) | 1621 if ((eoptarg != NULL) && !isdigit((unsigned char)*eoptarg)) |
1618 inchar = *eoptarg++; 1619 else 1620 inchar = INCHAR; | 1622 inchar = *eoptarg++; 1623 else 1624 inchar = INCHAR; |
1621 if ((eoptarg != NULL) && isdigit(*eoptarg)) { | 1625 if ((eoptarg != NULL) && isdigit((unsigned char)*eoptarg)) { |
1622 if ((ingap = atoi(eoptarg)) < 0) { 1623 (void)fputs( 1624 "pr: -e gap must be 0 or more\n", err); 1625 return(1); 1626 } 1627 if (ingap == 0) 1628 ingap = INGAP; 1629 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) { --- 6 unchanged lines hidden (view full) --- 1636 case 'F': 1637 ++formfeed; 1638 break; 1639 case 'h': 1640 header = eoptarg; 1641 break; 1642 case 'i': 1643 ++iflag; | 1626 if ((ingap = atoi(eoptarg)) < 0) { 1627 (void)fputs( 1628 "pr: -e gap must be 0 or more\n", err); 1629 return(1); 1630 } 1631 if (ingap == 0) 1632 ingap = INGAP; 1633 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) { --- 6 unchanged lines hidden (view full) --- 1640 case 'F': 1641 ++formfeed; 1642 break; 1643 case 'h': 1644 header = eoptarg; 1645 break; 1646 case 'i': 1647 ++iflag; |
1644 if ((eoptarg != NULL) && !isdigit(*eoptarg)) | 1648 if ((eoptarg != NULL) && !isdigit((unsigned char)*eoptarg)) |
1645 ochar = *eoptarg++; 1646 else 1647 ochar = OCHAR; | 1649 ochar = *eoptarg++; 1650 else 1651 ochar = OCHAR; |
1648 if ((eoptarg != NULL) && isdigit(*eoptarg)) { | 1652 if ((eoptarg != NULL) && isdigit((unsigned char)*eoptarg)) { |
1649 if ((ogap = atoi(eoptarg)) < 0) { 1650 (void)fputs( 1651 "pr: -i gap must be 0 or more\n", err); 1652 return(1); 1653 } 1654 if (ogap == 0) 1655 ogap = OGAP; 1656 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) { 1657 (void)fprintf(err, 1658 "pr: invalid value for -i %s\n", eoptarg); 1659 return(1); 1660 } else 1661 ogap = OGAP; 1662 break; | 1653 if ((ogap = atoi(eoptarg)) < 0) { 1654 (void)fputs( 1655 "pr: -i gap must be 0 or more\n", err); 1656 return(1); 1657 } 1658 if (ogap == 0) 1659 ogap = OGAP; 1660 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) { 1661 (void)fprintf(err, 1662 "pr: invalid value for -i %s\n", eoptarg); 1663 return(1); 1664 } else 1665 ogap = OGAP; 1666 break; |
1667 case 'L': 1668 Lflag++; 1669 break; |
|
1663 case 'l': | 1670 case 'l': |
1664 if (!isdigit(*eoptarg) || ((lines=atoi(eoptarg)) < 1)) { | 1671 if (!isdigit((unsigned char)*eoptarg) || ((lines=atoi(eoptarg)) < 1)) { |
1665 (void)fputs( 1666 "pr: Number of lines must be 1 or more\n",err); 1667 return(1); 1668 } 1669 break; 1670 case 'm': 1671 ++merge; 1672 break; 1673 case 'n': | 1672 (void)fputs( 1673 "pr: Number of lines must be 1 or more\n",err); 1674 return(1); 1675 } 1676 break; 1677 case 'm': 1678 ++merge; 1679 break; 1680 case 'n': |
1674 if ((eoptarg != NULL) && !isdigit(*eoptarg)) | 1681 if ((eoptarg != NULL) && !isdigit((unsigned char)*eoptarg)) |
1675 nmchar = *eoptarg++; 1676 else 1677 nmchar = NMCHAR; | 1682 nmchar = *eoptarg++; 1683 else 1684 nmchar = NMCHAR; |
1678 if ((eoptarg != NULL) && isdigit(*eoptarg)) { | 1685 if ((eoptarg != NULL) && isdigit((unsigned char)*eoptarg)) { |
1679 if ((nmwd = atoi(eoptarg)) < 1) { 1680 (void)fputs( 1681 "pr: -n width must be 1 or more\n",err); 1682 return(1); 1683 } 1684 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) { 1685 (void)fprintf(err, 1686 "pr: invalid value for -n %s\n", eoptarg); 1687 return(1); 1688 } else 1689 nmwd = NMWD; 1690 break; 1691 case 'o': | 1686 if ((nmwd = atoi(eoptarg)) < 1) { 1687 (void)fputs( 1688 "pr: -n width must be 1 or more\n",err); 1689 return(1); 1690 } 1691 } else if ((eoptarg != NULL) && (*eoptarg != '\0')) { 1692 (void)fprintf(err, 1693 "pr: invalid value for -n %s\n", eoptarg); 1694 return(1); 1695 } else 1696 nmwd = NMWD; 1697 break; 1698 case 'o': |
1692 if (!isdigit(*eoptarg) || ((offst = atoi(eoptarg))< 1)){ | 1699 if (!isdigit((unsigned char)*eoptarg) || ((offst = atoi(eoptarg))< 1)){ |
1693 (void)fputs("pr: -o offset must be 1 or more\n", 1694 err); 1695 return(1); 1696 } 1697 break; 1698 case 'r': 1699 ++nodiag; 1700 break; --- 9 unchanged lines hidden (view full) --- 1710 return(1); 1711 } 1712 break; 1713 case 't': 1714 ++nohead; 1715 break; 1716 case 'w': 1717 ++wflag; | 1700 (void)fputs("pr: -o offset must be 1 or more\n", 1701 err); 1702 return(1); 1703 } 1704 break; 1705 case 'r': 1706 ++nodiag; 1707 break; --- 9 unchanged lines hidden (view full) --- 1717 return(1); 1718 } 1719 break; 1720 case 't': 1721 ++nohead; 1722 break; 1723 case 'w': 1724 ++wflag; |
1718 if (!isdigit(*eoptarg) || ((pgwd = atoi(eoptarg)) < 1)){ | 1725 if (!isdigit((unsigned char)*eoptarg) || ((pgwd = atoi(eoptarg)) < 1)){ |
1719 (void)fputs( 1720 "pr: -w width must be 1 or more \n",err); 1721 return(1); 1722 } 1723 break; 1724 case '?': 1725 default: 1726 return(1); --- 78 unchanged lines hidden (view full) --- 1805 else { 1806 if (lines & 1) 1807 ++addone; 1808 lines /= 2; 1809 } 1810 } 1811 1812 timefrmt = TIMEFMT; | 1726 (void)fputs( 1727 "pr: -w width must be 1 or more \n",err); 1728 return(1); 1729 } 1730 break; 1731 case '?': 1732 default: 1733 return(1); --- 78 unchanged lines hidden (view full) --- 1812 else { 1813 if (lines & 1) 1814 ++addone; 1815 lines /= 2; 1816 } 1817 } 1818 1819 timefrmt = TIMEFMT; |
1820 if (!Lflag) 1821 (void) setlocale(LC_TIME, ""); 1822 |
|
1813 return(0); 1814} | 1823 return(0); 1824} |