Release 6
[unix-history] / usr / src / usr.bin / ex / printf.c
index 4e0a76f..f0bbd52 100644 (file)
@@ -1,8 +1,25 @@
+/*-
+ * Copyright (c) 1980 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.proprietary.c%
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)printf.c   7.6 (Berkeley) %G%";
+#endif /* not lint */
+
+#ifndef lint
 /* The pwb version this is based on */
 static char *printf_id = "@(#) printf.c:2.2 6/5/79";
 /* The pwb version this is based on */
 static char *printf_id = "@(#) printf.c:2.2 6/5/79";
-/* The local sccs version within ex */
-static char *sccsid = "@(#)printf.c    5.1 %G%";
-#include "varargs.h"
+#endif /* not lint */
+
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
 /*
  * This version of printf is compatible with the Version 7 C
  * printf. The differences are only minor except that this
 /*
  * This version of printf is compatible with the Version 7 C
  * printf. The differences are only minor except that this
@@ -10,7 +27,6 @@ static char *sccsid = "@(#)printf.c   5.1 %G%";
  * printf is more general (and is much larger) and includes
  * provisions for floating point.
  */
  * printf is more general (and is much larger) and includes
  * provisions for floating point.
  */
 
 #define MAXOCT 11      /* Maximum octal digits in a long */
 #define MAXINT 32767   /* largest normal length positive integer */
 
 #define MAXOCT 11      /* Maximum octal digits in a long */
 #define MAXINT 32767   /* largest normal length positive integer */
@@ -21,11 +37,17 @@ static int width, sign, fill;
 
 char *_p_dconv();
 
 
 char *_p_dconv();
 
-printf(va_alist)
+/* VARARGS */
+#if __STDC__
+ex_printf(const char *fmt0, ...)
+#else
+ex_printf(fmt0, va_alist)
+       char *fmt0;
        va_dcl
        va_dcl
+#endif
 {
 {
-       va_list ap;
        register char *fmt;
        register char *fmt;
+       va_list ap;
        char fcode;
        int prec;
        int length,mask1,nbits,n;
        char fcode;
        int prec;
        int length,mask1,nbits,n;
@@ -34,15 +56,19 @@ printf(va_alist)
        char *ptr;
        char buf[134];
 
        char *ptr;
        char buf[134];
 
+#if __STDC__
+       va_start(ap, fmt0);
+#else
        va_start(ap);
        va_start(ap);
-       fmt = va_arg(ap,char *);
+#endif
+       fmt = (char *)fmt0;
        for (;;) {
                /* process format string first */
                while ((fcode = *fmt++)!='%') {
                        /* ordinary (non-%) character */
                        if (fcode=='\0')
                                return;
        for (;;) {
                /* process format string first */
                while ((fcode = *fmt++)!='%') {
                        /* ordinary (non-%) character */
                        if (fcode=='\0')
                                return;
-                       putchar(fcode);
+                       ex_putchar(fcode);
                }
                /* length modifier: -1 for h, 1 for l, 0 for none */
                length = 0;
                }
                /* length modifier: -1 for h, 1 for l, 0 for none */
                length = 0;
@@ -172,8 +198,8 @@ printf(va_alist)
                                }
                                else
                                        if (!sign && fill <= 0) {
                                }
                                else
                                        if (!sign && fill <= 0) {
-                                               putchar('0');
-                                               putchar(fcode);
+                                               ex_putchar('0');
+                                               ex_putchar(fcode);
                                                width -= 2;
                                        }
                                        else {
                                                width -= 2;
                                        }
                                        else {
@@ -321,7 +347,7 @@ _p_emit(s, send)
        
        /* we may want to print a leading '-' before anything */
        if (*s == '-' && fill < 0) {
        
        /* we may want to print a leading '-' before anything */
        if (*s == '-' && fill < 0) {
-               putchar(*s++);
+               ex_putchar(*s++);
                alen--;
                width--;
        }
                alen--;
                width--;
        }
@@ -330,14 +356,14 @@ _p_emit(s, send)
        /* emit any leading pad characters */
        if (!sign)
                while (--npad >= 0)
        /* emit any leading pad characters */
        if (!sign)
                while (--npad >= 0)
-                       putchar(cfill);
+                       ex_putchar(cfill);
                        
        /* emit the string itself */
        while (--alen >= 0)
                        
        /* emit the string itself */
        while (--alen >= 0)
-               putchar(*s++);
+               ex_putchar(*s++);
                
        /* emit trailing pad characters */
        if (sign)
                while (--npad >= 0)
                
        /* emit trailing pad characters */
        if (sign)
                while (--npad >= 0)
-                       putchar(cfill);
+                       ex_putchar(cfill);
 }
 }