annotate src/doprnt.c @ 16591:afb15f49a0c9

Use new file name dos-w32.el
author Geoff Voelker <voelker@cs.washington.edu>
date Tue, 19 Nov 1996 07:02:50 +0000
parents aa25c2ac018b
children e7814b054e91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
1 /* Output like sprintf to a buffer of specified size.
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
2 Also takes args differently: pass one pointer to an array of strings
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
3 in addition to the format string which is separate.
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
4 Copyright (C) 1985 Free Software Foundation, Inc.
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
5
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
6 This file is part of GNU Emacs.
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
7
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8 GNU Emacs is free software; you can redistribute it and/or modify
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
12244
ac7375e60931 Update GPL to version 2.
Karl Heuer <kwzh@gnu.org>
parents: 11700
diff changeset
10 the Free Software Foundation; either version 2, or (at your option)
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
11 any later version.
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
12
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13 GNU Emacs is distributed in the hope that it will be useful,
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 GNU General Public License for more details.
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19 along with GNU Emacs; see the file COPYING. If not, write to
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13554
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13554
diff changeset
21 Boston, MA 02111-1307, USA. */
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
22
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
23
5036
ef34c5a4d264 Include config.h.
Richard M. Stallman <rms@gnu.org>
parents: 4774
diff changeset
24 #include <config.h>
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
25 #include <stdio.h>
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
26 #include <ctype.h>
13449
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
27 #include "lisp.h"
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
28
11320
aaf81f284f83 (xmalloc, xrealloc): Declare them here.
Richard M. Stallman <rms@gnu.org>
parents: 8141
diff changeset
29 extern long *xmalloc (), *xrealloc ();
aaf81f284f83 (xmalloc, xrealloc): Declare them here.
Richard M. Stallman <rms@gnu.org>
parents: 8141
diff changeset
30
13449
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
31 static int doprnt1 ();
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
32
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
33 /* Generate output from a format-spec FORMAT,
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
34 terminated at position FORMAT_END.
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
35 Output goes in BUFFER, which has room for BUFSIZE chars.
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
36 If the output does not fit, truncate it to fit.
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
37 Returns the number of characters stored into BUFFER.
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
38 ARGS points to the vector of arguments, and NARGS says how many.
13449
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
39 A double counts as two arguments.
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
40 String arguments are passed as C strings.
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
41 Integers are passed as C integers. */
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
42
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
43 doprnt (buffer, bufsize, format, format_end, nargs, args)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
44 char *buffer;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
45 register int bufsize;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
46 char *format;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
47 char *format_end;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
48 int nargs;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
49 char **args;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
50 {
13449
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
51 return doprnt1 (0, buffer, bufsize, format, format_end, nargs, args);
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
52 }
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
53
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
54 /* Like doprnt except that strings in ARGS are passed
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
55 as Lisp_Object. */
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
56
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
57 doprnt_lisp (buffer, bufsize, format, format_end, nargs, args)
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
58 char *buffer;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
59 register int bufsize;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
60 char *format;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
61 char *format_end;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
62 int nargs;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
63 char **args;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
64 {
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
65 return doprnt1 (1, buffer, bufsize, format, format_end, nargs, args);
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
66 }
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
67
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
68 static int
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
69 doprnt1 (lispstrings, buffer, bufsize, format, format_end, nargs, args)
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
70 int lispstrings;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
71 char *buffer;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
72 register int bufsize;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
73 char *format;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
74 char *format_end;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
75 int nargs;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
76 char **args;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
77 {
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
78 int cnt = 0; /* Number of arg to gobble next */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
79 register char *fmt = format; /* Pointer into format string */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
80 register char *bufptr = buffer; /* Pointer into output buffer.. */
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
81
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
82 /* Use this for sprintf unless we need something really big. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
83 char tembuf[100];
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
84
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
85 /* Size of sprintf_buffer. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
86 int size_allocated = 100;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
87
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
88 /* Buffer to use for sprintf. Either tembuf or same as BIG_BUFFER. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
89 char *sprintf_buffer = tembuf;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
90
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
91 /* Buffer we have got with malloc. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
92 char *big_buffer = 0;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
93
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94 register int tem;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
95 char *string;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
96 char fixed_buffer[20]; /* Default buffer for small formatting. */
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
97 char *fmtcpy;
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
98 int minlen;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
99 int size; /* Field width factor; e.g., %90d */
8141
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
100 char charbuf[2]; /* Used for %c. */
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
101
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
102 if (format_end == 0)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
103 format_end = format + strlen (format);
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
104
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
105 if ((format_end - format + 1) < sizeof (fixed_buffer))
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
106 fmtcpy = fixed_buffer;
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
107 else
5053
b98e742f0b05 (doprnt): Cast the value alloca returns.
Richard M. Stallman <rms@gnu.org>
parents: 5036
diff changeset
108 fmtcpy = (char *) alloca (format_end - format + 1);
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
109
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
110 bufsize--;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
111
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
112 /* Loop until end of format string or buffer full. */
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
113 while (fmt != format_end && bufsize > 0)
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
114 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
115 if (*fmt == '%') /* Check for a '%' character */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
116 {
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
117 int size_bound;
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
118
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
119 fmt++;
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 147
diff changeset
120 /* Copy this one %-spec into fmtcpy. */
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
121 string = fmtcpy;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
122 *string++ = '%';
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
123 while (1)
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
124 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
125 *string++ = *fmt;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
126 if (! (*fmt >= '0' && *fmt <= '9')
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
127 && *fmt != '-' && *fmt != ' '&& *fmt != '.')
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
128 break;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
129 fmt++;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
130 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
131 *string = 0;
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
132 /* Get an idea of how much space we might need. */
6236
d9f096200099 (doprnt): Do the right thing for negative size spec.
Karl Heuer <kwzh@gnu.org>
parents: 5053
diff changeset
133 size_bound = atoi (&fmtcpy[1]);
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
134
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
135 /* Avoid pitfall of negative "size" parameter ("%-200d"). */
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
136 if (size_bound < 0)
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
137 size_bound = -size_bound;
6236
d9f096200099 (doprnt): Do the right thing for negative size spec.
Karl Heuer <kwzh@gnu.org>
parents: 5053
diff changeset
138 size_bound += 50;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
139
14690
cd283f1eb0cf (doprnt1): Move cast to unsigned inside a shift.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
140 if (size_bound > (((unsigned) 1) << (BITS_PER_INT - 1)))
12959
f83031b644ac (doprnt): Fix typo in error message.
Richard M. Stallman <rms@gnu.org>
parents: 12830
diff changeset
141 error ("Format padding too large");
12797
f0724d9d625e (doprnt): Don't let size_bound be gigantic. Fix error message.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
142
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
143 /* Make sure we have that much. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
144 if (size_bound > size_allocated)
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
145 {
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
146 if (big_buffer)
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
147 big_buffer = (char *) xrealloc (big_buffer, size_bound);
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
148 else
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
149 big_buffer = (char *) xmalloc (size_bound);
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
150 sprintf_buffer = big_buffer;
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
151 size_allocated = size_bound;
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
152 }
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
153 minlen = 0;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
154 switch (*fmt++)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
155 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
156 default:
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
157 error ("Invalid format operation %%%c", fmt[-1]);
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
158
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
159 /* case 'b': */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
160 case 'd':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
161 case 'o':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
162 case 'x':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
163 if (cnt == nargs)
12797
f0724d9d625e (doprnt): Don't let size_bound be gigantic. Fix error message.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
164 error ("Not enough arguments for format string");
11700
79358a3240fe (doprnt): Handle long EMACS_INT in sprintf.
Richard M. Stallman <rms@gnu.org>
parents: 11320
diff changeset
165 if (sizeof (int) == sizeof (EMACS_INT))
79358a3240fe (doprnt): Handle long EMACS_INT in sprintf.
Richard M. Stallman <rms@gnu.org>
parents: 11320
diff changeset
166 ;
79358a3240fe (doprnt): Handle long EMACS_INT in sprintf.
Richard M. Stallman <rms@gnu.org>
parents: 11320
diff changeset
167 else if (sizeof (long) == sizeof (EMACS_INT))
79358a3240fe (doprnt): Handle long EMACS_INT in sprintf.
Richard M. Stallman <rms@gnu.org>
parents: 11320
diff changeset
168 /* Insert an `l' the right place. */
79358a3240fe (doprnt): Handle long EMACS_INT in sprintf.
Richard M. Stallman <rms@gnu.org>
parents: 11320
diff changeset
169 string[1] = string[0],
79358a3240fe (doprnt): Handle long EMACS_INT in sprintf.
Richard M. Stallman <rms@gnu.org>
parents: 11320
diff changeset
170 string[0] = string[-1],
79358a3240fe (doprnt): Handle long EMACS_INT in sprintf.
Richard M. Stallman <rms@gnu.org>
parents: 11320
diff changeset
171 string[-1] = 'l',
79358a3240fe (doprnt): Handle long EMACS_INT in sprintf.
Richard M. Stallman <rms@gnu.org>
parents: 11320
diff changeset
172 string++;
79358a3240fe (doprnt): Handle long EMACS_INT in sprintf.
Richard M. Stallman <rms@gnu.org>
parents: 11320
diff changeset
173 else
79358a3240fe (doprnt): Handle long EMACS_INT in sprintf.
Richard M. Stallman <rms@gnu.org>
parents: 11320
diff changeset
174 abort ();
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
175 sprintf (sprintf_buffer, fmtcpy, args[cnt++]);
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
176 /* Now copy into final output, truncating as nec. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
177 string = sprintf_buffer;
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
178 goto doit;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
179
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
180 case 'f':
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
181 case 'e':
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
182 case 'g':
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
183 {
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
184 union { double d; char *half[2]; } u;
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
185 if (cnt + 1 == nargs)
6715
3864d274a56c (doprnt): Reword confusing error message.
Karl Heuer <kwzh@gnu.org>
parents: 6236
diff changeset
186 error ("not enough arguments for format string");
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
187 u.half[0] = args[cnt++];
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
188 u.half[1] = args[cnt++];
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
189 sprintf (sprintf_buffer, fmtcpy, u.d);
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
190 /* Now copy into final output, truncating as nec. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
191 string = sprintf_buffer;
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
192 goto doit;
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
193 }
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
194
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
195 case 'S':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
196 string[-1] = 's';
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
197 case 's':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
198 if (cnt == nargs)
6715
3864d274a56c (doprnt): Reword confusing error message.
Karl Heuer <kwzh@gnu.org>
parents: 6236
diff changeset
199 error ("not enough arguments for format string");
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
200 if (fmtcpy[1] != 's')
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
201 minlen = atoi (&fmtcpy[1]);
13449
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
202 if (lispstrings)
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
203 {
16096
aa25c2ac018b (doprnt1): If lispstrings, accept a string
Richard M. Stallman <rms@gnu.org>
parents: 14690
diff changeset
204 string = (char *) ((struct Lisp_String *)args[cnt])->data;
aa25c2ac018b (doprnt1): If lispstrings, accept a string
Richard M. Stallman <rms@gnu.org>
parents: 14690
diff changeset
205 tem = ((struct Lisp_String *)args[cnt])->size;
13449
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
206 cnt++;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
207 }
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
208 else
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
209 {
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
210 string = args[cnt++];
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
211 tem = strlen (string);
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
212 }
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
213 goto doit1;
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
214
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
215 /* Copy string into final output, truncating if no room. */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
216 doit:
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
217 tem = strlen (string);
8141
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
218 doit1:
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
219 if (minlen > 0)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
220 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
221 while (minlen > tem && bufsize > 0)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
222 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
223 *bufptr++ = ' ';
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
224 bufsize--;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
225 minlen--;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
226 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
227 minlen = 0;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
228 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
229 if (tem > bufsize)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
230 tem = bufsize;
13449
2e9306561b80 Include lisp.h.
Richard M. Stallman <rms@gnu.org>
parents: 13363
diff changeset
231 bcopy (string, bufptr, tem);
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
232 bufptr += tem;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
233 bufsize -= tem;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
234 if (minlen < 0)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
235 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
236 while (minlen < - tem && bufsize > 0)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
237 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
238 *bufptr++ = ' ';
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
239 bufsize--;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
240 minlen++;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
241 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
242 minlen = 0;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
243 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
244 continue;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
245
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
246 case 'c':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
247 if (cnt == nargs)
6715
3864d274a56c (doprnt): Reword confusing error message.
Karl Heuer <kwzh@gnu.org>
parents: 6236
diff changeset
248 error ("not enough arguments for format string");
11320
aaf81f284f83 (xmalloc, xrealloc): Declare them here.
Richard M. Stallman <rms@gnu.org>
parents: 8141
diff changeset
249 *charbuf = (EMACS_INT) args[cnt++];
8141
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
250 string = charbuf;
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
251 tem = 1;
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
252 if (fmtcpy[1] != 'c')
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
253 minlen = atoi (&fmtcpy[1]);
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
254 goto doit1;
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
255
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
256 case '%':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
257 fmt--; /* Drop thru and this % will be treated as normal */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
258 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
259 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
260 *bufptr++ = *fmt++; /* Just some characters; Copy 'em */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
261 bufsize--;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
262 };
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
263
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
264 /* If we had to malloc something, free it. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
265 if (big_buffer)
2439
b6c62e4abf59 Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents: 484
diff changeset
266 xfree (big_buffer);
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
267
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
268 *bufptr = 0; /* Make sure our string end with a '\0' */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
269 return bufptr - buffer;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
270 }