BSD 4_4_Lite2 release
[unix-history] / usr / src / usr.bin / printf / printf.c
index 6375c10..82ffbda 100644 (file)
@@ -1,20 +1,46 @@
 /*
 /*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * 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.
  */
 
 #if !defined(BUILTIN) && !defined(SHELL)
 #ifndef lint
  */
 
 #if !defined(BUILTIN) && !defined(SHELL)
 #ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1989, 1993\n\
      The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 #endif
 
 #ifndef lint
 #endif /* not lint */
 #endif
 
 #ifndef lint
-static char sccsid[] = "@(#)printf.c   5.14 (Berkeley) %G%";
+static char sccsid[] = "@(#)printf.c   8.2 (Berkeley) 3/22/95";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -36,9 +62,9 @@ static char sccsid[] = "@(#)printf.c  5.14 (Berkeley) %G%";
  */
 #ifdef SHELL
 #define main printfcmd
  */
 #ifdef SHELL
 #define main printfcmd
-#define warnx(a, b) {                                                  \
+#define warnx(a, b, c) {                                               \
        char buf[64];                                                   \
        char buf[64];                                                   \
-       (void)sprintf(buf, sizeof(buf), a, b);                          \
+       (void)sprintf(buf, sizeof(buf), a, b, c);                       \
        error(buf);                                                     \
 }
 #include "../../bin/sh/bltin/bltin.h"
        error(buf);                                                     \
 }
 #include "../../bin/sh/bltin/bltin.h"
@@ -117,7 +143,8 @@ next:               for (start = fmt;; ++fmt) {
                        if (!*fmt) {
                                /* avoid infinite loop */
                                if (end == 1) {
                        if (!*fmt) {
                                /* avoid infinite loop */
                                if (end == 1) {
-                                       warnx("missing format character", NULL);
+                                       warnx("missing format character",
+                                           NULL, NULL);
                                        return (1);
                                }
                                end = 1;
                                        return (1);
                                }
                                end = 1;
@@ -159,7 +186,7 @@ next:               for (start = fmt;; ++fmt) {
                /* skip to conversion char */
                for (; strchr(skip2, *fmt); ++fmt);
                if (!*fmt) {
                /* skip to conversion char */
                for (; strchr(skip2, *fmt); ++fmt);
                if (!*fmt) {
-                       warnx("missing format character", NULL);
+                       warnx("missing format character", NULL, NULL);
                        return (1);
                }
 
                        return (1);
                }
 
@@ -200,7 +227,7 @@ next:               for (start = fmt;; ++fmt) {
                        break;
                }
                default:
                        break;
                }
                default:
-                       warnx("illegal format character", NULL);
+                       warnx("illegal format character", NULL, NULL);
                        return (1);
                }
                *fmt = nextch;
                        return (1);
                }
                *fmt = nextch;
@@ -231,7 +258,7 @@ escape(fmt)
        register char *store;
        register int value, c;
 
        register char *store;
        register int value, c;
 
-       for (store = fmt; c = *fmt; ++fmt, ++store) {
+       for (store = fmt; (c = *fmt) != '\0'; ++fmt, ++store) {
                if (c != '\\') {
                        *store = c;
                        continue;
                if (c != '\\') {
                        *store = c;
                        continue;
@@ -311,8 +338,7 @@ getint(ip)
        if (getlong(&val))
                return (1);
        if (val > INT_MAX) {
        if (getlong(&val))
                return (1);
        if (val > INT_MAX) {
-               errno = ERANGE;
-               warn("%s", *gargv);
+               warnx("%s: %s", *gargv, strerror(ERANGE));
                return (1);
        }
        *ip = val;
                return (1);
        }
        *ip = val;
@@ -334,16 +360,16 @@ getlong(lp)
                errno = 0;
                val = strtol(*gargv, &ep, 0);
                if (*ep != '\0') {
                errno = 0;
                val = strtol(*gargv, &ep, 0);
                if (*ep != '\0') {
-                       warnx("%s: illegal number", *gargv);
+                       warnx("%s: illegal number", *gargv, NULL);
                        return (1);
                }
                if (errno == ERANGE)
                        if (val == LONG_MAX) {
                        return (1);
                }
                if (errno == ERANGE)
                        if (val == LONG_MAX) {
-                               warn("%s", *gargv);
+                               warnx("%s: %s", *gargv, strerror(ERANGE));
                                return (1);
                        }
                        if (val == LONG_MIN) {
                                return (1);
                        }
                        if (val == LONG_MIN) {
-                               warn("%s", *gargv);
+                               warnx("%s: %s", *gargv, strerror(ERANGE));
                                return (1);
                        }
                        
                                return (1);
                        }