X-Git-Url: http://git.hcoop.net/bpt/emacs.git/blobdiff_plain/dd559368b0db67654f643320b1d84afdabe60e97..72af86bd8cf1812d1fcc8924c4093d692040a664:/src/doprnt.c diff --git a/src/doprnt.c b/src/doprnt.c index 6351657e70..3ff2f70dd3 100644 --- a/src/doprnt.c +++ b/src/doprnt.c @@ -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, 2008 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 3, 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 . */ #include #include #include +#include #ifdef STDC_HEADERS #include @@ -49,8 +48,6 @@ Boston, MA 02110-1301, USA. */ another macro. */ #include "character.h" -static int doprnt1 (); - /* Generate output from a format-spec FORMAT, terminated at position FORMAT_END. Output goes in BUFFER, which has room for BUFSIZE chars. @@ -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;