Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
[bpt/emacs.git] / src / doprnt.c
index 799f38d..3ff2f70 100644 (file)
@@ -2,14 +2,14 @@
    Also takes args differently: pass one pointer to an array of strings
    in addition to the format string which is separate.
    Copyright (C) 1985, 2001, 2002, 2003, 2004, 2005,
-                 2006, 2007  Free Software Foundation, Inc.
+                 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,14 +17,13 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 #include <config.h>
 #include <stdio.h>
 #include <ctype.h>
+#include <setjmp.h>
 
 #ifdef STDC_HEADERS
 #include <float.h>
@@ -47,9 +46,7 @@ Boston, MA 02110-1301, USA.  */
 /* Since we use the macro CHAR_HEAD_P, we have to include this, but
    don't have to include others because CHAR_HEAD_P does not contains
    another macro.  */
-#include "charset.h"
-
-static int doprnt1 ();
+#include "character.h"
 
 /* Generate output from a format-spec FORMAT,
    terminated at position FORMAT_END.
@@ -62,41 +59,7 @@ static int doprnt1 ();
    Integers are passed as C integers.  */
 
 int
-doprnt (buffer, bufsize, format, format_end, nargs, args)
-     char *buffer;
-     register int bufsize;
-     char *format;
-     char *format_end;
-     int nargs;
-     char **args;
-{
-  return doprnt1 (0, buffer, bufsize, format, format_end, nargs, args);
-}
-
-/* Like doprnt except that strings in ARGS are passed
-   as Lisp_Object.  */
-
-int
-doprnt_lisp (buffer, bufsize, format, format_end, nargs, args)
-     char *buffer;
-     register int bufsize;
-     char *format;
-     char *format_end;
-     int nargs;
-     char **args;
-{
-  return doprnt1 (1, buffer, bufsize, format, format_end, nargs, args);
-}
-
-static int
-doprnt1 (lispstrings, buffer, bufsize, format, format_end, nargs, args)
-     int lispstrings;
-     char *buffer;
-     register int bufsize;
-     char *format;
-     char *format_end;
-     int nargs;
-     char **args;
+doprnt (char *buffer, register int bufsize, char *format, char *format_end, int nargs, char **args)
 {
   int cnt = 0;                 /* Number of arg to gobble next */
   register char *fmt = format; /* Pointer into format string */
@@ -119,7 +82,7 @@ doprnt1 (lispstrings, buffer, bufsize, format, format_end, nargs, args)
   char fixed_buffer[20];       /* Default buffer for small formatting. */
   char *fmtcpy;
   int minlen;
-  unsigned char charbuf[5];    /* Used for %c.  */
+  unsigned char charbuf[MAX_MULTIBYTE_LENGTH + 1];     /* Used for %c.  */
 
   if (format_end == 0)
     format_end = format + strlen (format);
@@ -155,9 +118,9 @@ doprnt1 (lispstrings, buffer, bufsize, format, format_end, nargs, args)
                  unsigned n = *fmt - '0';
                  while ('0' <= fmt[1] && fmt[1] <= '9')
                    {
-                     if (n * 10 / 10 != n
-                         || (n = n * 10 + (fmt[1] - '0')) < n)
+                     if (n * 10 + fmt[1] - '0' < n)
                        error ("Format width or precision too large");
+                     n = n * 10 + fmt[1] - '0';
                      *string++ = *++fmt;
                    }
 
@@ -237,17 +200,8 @@ doprnt1 (lispstrings, buffer, bufsize, format, format_end, nargs, args)
                error ("Not enough arguments for format string");
              if (fmtcpy[1] != 's')
                minlen = atoi (&fmtcpy[1]);
-             if (lispstrings)
-               {
-                 string = ((struct Lisp_String *) args[cnt])->data;
-                 tem = STRING_BYTES ((struct Lisp_String *) args[cnt]);
-                 cnt++;
-               }
-             else
-               {
-                 string = (unsigned char *) args[cnt++];
-                 tem = strlen (string);
-               }
+             string = (unsigned char *) args[cnt++];
+             tem = strlen (string);
              width = strwidth (string, tem);
              goto doit1;
 
@@ -275,12 +229,12 @@ doprnt1 (lispstrings, buffer, bufsize, format, format_end, nargs, args)
                  /* Truncate the string at character boundary.  */
                  tem = bufsize;
                  while (!CHAR_HEAD_P (string[tem - 1])) tem--;
-                 bcopy (string, bufptr, tem);
+                 memcpy (bufptr, string, tem);
                  /* We must calculate WIDTH again.  */
                  width = strwidth (bufptr, tem);
                }
              else
-               bcopy (string, bufptr, tem);
+               memcpy (bufptr, string, tem);
              bufptr += tem;
              bufsize -= tem;
              if (minlen < 0)
@@ -328,8 +282,7 @@ doprnt1 (lispstrings, buffer, bufsize, format, format_end, nargs, args)
     };
 
   /* If we had to malloc something, free it.  */
-  if (big_buffer)
-    xfree (big_buffer);
+  xfree (big_buffer);
 
   *bufptr = 0;         /* Make sure our string end with a '\0' */
   return bufptr - buffer;