annotate src/doprnt.c @ 9096:51a06d484c05

REMOVE CONFIG_BROKETS
author David J. MacKenzie <djm@gnu.org>
date Mon, 26 Sep 1994 21:56:21 +0000
parents e3859c43c6f4
children aaf81f284f83
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
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10 the Free Software Foundation; either version 1, or (at your option)
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
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
21
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
22
5036
ef34c5a4d264 Include config.h.
Richard M. Stallman <rms@gnu.org>
parents: 4774
diff changeset
23 #include <config.h>
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
24 #include <stdio.h>
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
25 #include <ctype.h>
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
26
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
27 /* Generate output from a format-spec FORMAT,
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
28 terminated at position FORMAT_END.
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
29 Output goes in BUFFER, which has room for BUFSIZE chars.
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
30 If the output does not fit, truncate it to fit.
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
31 Returns the number of characters stored into BUFFER.
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
32 ARGS points to the vector of arguments, and NARGS says how many.
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
33 A double counts as two arguments. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
34
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
35 doprnt (buffer, bufsize, format, format_end, nargs, args)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
36 char *buffer;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
37 register int bufsize;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
38 char *format;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
39 char *format_end;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
40 int nargs;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
41 char **args;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
42 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
43 int cnt = 0; /* Number of arg to gobble next */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
44 register char *fmt = format; /* Pointer into format string */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
45 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
46
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
47 /* Use this for sprintf unless we need something really big. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
48 char tembuf[100];
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
49
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
50 /* Size of sprintf_buffer. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
51 int size_allocated = 100;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
52
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
53 /* 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
54 char *sprintf_buffer = tembuf;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
55
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
56 /* Buffer we have got with malloc. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
57 char *big_buffer = 0;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
58
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
59 register int tem;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
60 char *string;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
61 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
62 char *fmtcpy;
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
63 int minlen;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
64 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
65 char charbuf[2]; /* Used for %c. */
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
66
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
67 if (format_end == 0)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
68 format_end = format + strlen (format);
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
69
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
70 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
71 fmtcpy = fixed_buffer;
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
72 else
5053
b98e742f0b05 (doprnt): Cast the value alloca returns.
Richard M. Stallman <rms@gnu.org>
parents: 5036
diff changeset
73 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
74
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
75 bufsize--;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
76
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
77 /* 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
78 while (fmt != format_end && bufsize > 0)
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
79 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
80 if (*fmt == '%') /* Check for a '%' character */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
81 {
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
82 int size_bound;
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
83
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
84 fmt++;
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 147
diff changeset
85 /* Copy this one %-spec into fmtcpy. */
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
86 string = fmtcpy;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
87 *string++ = '%';
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
88 while (1)
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
89 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
90 *string++ = *fmt;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
91 if (! (*fmt >= '0' && *fmt <= '9')
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
92 && *fmt != '-' && *fmt != ' '&& *fmt != '.')
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
93 break;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94 fmt++;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
95 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
96 *string = 0;
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
97 /* 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
98 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
99
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
100 /* 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
101 if (size_bound < 0)
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
102 size_bound = -size_bound;
6236
d9f096200099 (doprnt): Do the right thing for negative size spec.
Karl Heuer <kwzh@gnu.org>
parents: 5053
diff changeset
103 size_bound += 50;
4774
8e36034f65e2 (doprnt): Use a fixed buffer to store the format
Brian Fox <bfox@gnu.org>
parents: 2439
diff changeset
104
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
105 /* Make sure we have that much. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
106 if (size_bound > size_allocated)
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
107 {
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
108 if (big_buffer)
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
109 big_buffer = (char *) xrealloc (big_buffer, size_bound);
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
110 else
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
111 big_buffer = (char *) xmalloc (size_bound);
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
112 sprintf_buffer = big_buffer;
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
113 size_allocated = size_bound;
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
114 }
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
115 minlen = 0;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
116 switch (*fmt++)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
117 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
118 default:
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
119 error ("Invalid format operation %%%c", fmt[-1]);
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
120
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
121 /* case 'b': */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
122 case 'd':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
123 case 'o':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
124 case 'x':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
125 if (cnt == nargs)
6715
3864d274a56c (doprnt): Reword confusing error message.
Karl Heuer <kwzh@gnu.org>
parents: 6236
diff changeset
126 error ("not enough arguments for format string");
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
127 sprintf (sprintf_buffer, fmtcpy, args[cnt++]);
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
128 /* Now copy into final output, truncating as nec. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
129 string = sprintf_buffer;
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
130 goto doit;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
131
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
132 case 'f':
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
133 case 'e':
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
134 case 'g':
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
135 {
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
136 union { double d; char *half[2]; } u;
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
137 if (cnt + 1 == nargs)
6715
3864d274a56c (doprnt): Reword confusing error message.
Karl Heuer <kwzh@gnu.org>
parents: 6236
diff changeset
138 error ("not enough arguments for format string");
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
139 u.half[0] = args[cnt++];
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
140 u.half[1] = args[cnt++];
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
141 sprintf (sprintf_buffer, fmtcpy, u.d);
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
142 /* Now copy into final output, truncating as nec. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
143 string = sprintf_buffer;
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
144 goto doit;
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
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
147 case 'S':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
148 string[-1] = 's';
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
149 case 's':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
150 if (cnt == nargs)
6715
3864d274a56c (doprnt): Reword confusing error message.
Karl Heuer <kwzh@gnu.org>
parents: 6236
diff changeset
151 error ("not enough arguments for format string");
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
152 string = args[cnt++];
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
153 if (fmtcpy[1] != 's')
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
154 minlen = atoi (&fmtcpy[1]);
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
155 /* Copy string into final output, truncating if no room. */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
156 doit:
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
157 tem = strlen (string);
8141
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
158 doit1:
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
159 if (minlen > 0)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
160 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
161 while (minlen > tem && bufsize > 0)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
162 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
163 *bufptr++ = ' ';
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
164 bufsize--;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
165 minlen--;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
166 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
167 minlen = 0;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
168 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
169 if (tem > bufsize)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
170 tem = bufsize;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
171 strncpy (bufptr, string, tem);
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
172 bufptr += tem;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
173 bufsize -= tem;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
174 if (minlen < 0)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
175 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
176 while (minlen < - tem && bufsize > 0)
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
177 {
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
178 *bufptr++ = ' ';
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
179 bufsize--;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
180 minlen++;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
181 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
182 minlen = 0;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
183 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
184 continue;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
185
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
186 case 'c':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
187 if (cnt == nargs)
6715
3864d274a56c (doprnt): Reword confusing error message.
Karl Heuer <kwzh@gnu.org>
parents: 6236
diff changeset
188 error ("not enough arguments for format string");
8141
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
189 *charbuf = (int) args[cnt++];
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
190 string = charbuf;
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
191 tem = 1;
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
192 if (fmtcpy[1] != 'c')
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
193 minlen = atoi (&fmtcpy[1]);
e3859c43c6f4 (doprnt): Handle padding on %c.
Richard M. Stallman <rms@gnu.org>
parents: 6715
diff changeset
194 goto doit1;
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
195
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
196 case '%':
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
197 fmt--; /* Drop thru and this % will be treated as normal */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
198 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
199 }
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
200 *bufptr++ = *fmt++; /* Just some characters; Copy 'em */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
201 bufsize--;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
202 };
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
203
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
204 /* If we had to malloc something, free it. */
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
205 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
206 xfree (big_buffer);
147
0f50f1badd75 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 116
diff changeset
207
49
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
208 *bufptr = 0; /* Make sure our string end with a '\0' */
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
209 return bufptr - buffer;
94e408cdb3ce Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
210 }