Mercurial > emacs
annotate src/tparam.c @ 112377:5855bdef20c9
Minor Makefile.in tweaks to build from gnulib better.
<http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00673.html>
* Makefile.in (sync-from-gnulib): Also run autoreconf -I m4.
(top_maintainer_clean): Don't remove aclocal.m4.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Wed, 19 Jan 2011 15:56:53 -0800 |
parents | ef719132ddfa |
children |
rev | line source |
---|---|
4687 | 1 /* Merge parameters into a termcap entry string. |
75227
e90d04cd455a
Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents:
68651
diff
changeset
|
2 Copyright (C) 1985, 1987, 1993, 1995, 2000, 2001, 2002, 2003, 2004, |
100960
69177b934405
Revert copyright year changes for files that are not part of Emacs.
Glenn Morris <rgm@gnu.org>
parents:
100951
diff
changeset
|
3 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
4687 | 4 |
5 This program is free software; you can redistribute it and/or modify | |
6 it under the terms of the GNU General Public License as published by | |
7 the Free Software Foundation; either version 2, or (at your option) | |
8 any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with this program; see the file COPYING. If not, write to | |
64084 | 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 Boston, MA 02110-1301, USA. */ | |
4687 | 19 |
20 /* Emacs config.h may rename various library functions such as malloc. */ | |
21 #include <config.h> | |
105669
68dd71358159
* alloc.c: Do not define struct catchtag.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100960
diff
changeset
|
22 #include <setjmp.h> |
29805 | 23 #include "lisp.h" /* for xmalloc */ |
4687 | 24 |
25 #ifndef NULL | |
26 #define NULL (char *) 0 | |
27 #endif | |
28 | |
29 /* Assuming STRING is the value of a termcap string entry | |
30 containing `%' constructs to expand parameters, | |
31 merge in parameter values and store result in block OUTSTRING points to. | |
32 LEN is the length of OUTSTRING. If more space is needed, | |
33 a block is allocated with `malloc'. | |
34 | |
35 The value returned is the address of the resulting string. | |
36 This may be OUTSTRING or may be the address of a block got with `malloc'. | |
37 In the latter case, the caller must free the block. | |
38 | |
39 The fourth and following args to tparam serve as the parameter values. */ | |
40 | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
41 static char *tparam1 (char *string, char *outstring, int len, char *up, char *left, register int *argp); |
4687 | 42 |
43 /* VARARGS 2 */ | |
44 char * | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
45 tparam (char *string, char *outstring, int len, int arg0, int arg1, int arg2, int arg3) |
4687 | 46 { |
47 int arg[4]; | |
12678
8fc56d171ada
(tparam): Remove arg array and the #ifdef.
David J. MacKenzie <djm@gnu.org>
parents:
4687
diff
changeset
|
48 |
4687 | 49 arg[0] = arg0; |
50 arg[1] = arg1; | |
51 arg[2] = arg2; | |
52 arg[3] = arg3; | |
53 return tparam1 (string, outstring, len, NULL, NULL, arg); | |
54 } | |
55 | |
56 char *BC; | |
57 char *UP; | |
58 | |
59 static char tgoto_buf[50]; | |
60 | |
61 char * | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
62 tgoto (char *cm, int hpos, int vpos) |
4687 | 63 { |
64 int args[2]; | |
65 if (!cm) | |
66 return NULL; | |
67 args[0] = vpos; | |
68 args[1] = hpos; | |
69 return tparam1 (cm, tgoto_buf, 50, UP, BC, args); | |
70 } | |
71 | |
72 static char * | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105669
diff
changeset
|
73 tparam1 (char *string, char *outstring, int len, char *up, char *left, register int *argp) |
4687 | 74 { |
75 register int c; | |
76 register char *p = string; | |
77 register char *op = outstring; | |
78 char *outend; | |
79 int outlen = 0; | |
80 | |
81 register int tem; | |
53270
971b19b300e6
(tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
82 int *old_argp = argp; /* can move */ |
971b19b300e6
(tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
83 int *fixed_argp = argp; /* never moves */ |
971b19b300e6
(tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
84 int explicit_param_p = 0; /* set by %p */ |
4687 | 85 int doleft = 0; |
86 int doup = 0; | |
87 | |
88 outend = outstring + len; | |
89 | |
90 while (1) | |
91 { | |
92 /* If the buffer might be too short, make it bigger. */ | |
93 if (op + 5 >= outend) | |
94 { | |
95 register char *new; | |
34360
c6d74397e65f
(tparam1): Change the way buffers are reallocated to be
Gerd Moellmann <gerd@gnu.org>
parents:
29805
diff
changeset
|
96 int offset = op - outstring; |
c6d74397e65f
(tparam1): Change the way buffers are reallocated to be
Gerd Moellmann <gerd@gnu.org>
parents:
29805
diff
changeset
|
97 |
4687 | 98 if (outlen == 0) |
99 { | |
100 outlen = len + 40; | |
101 new = (char *) xmalloc (outlen); | |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
102 memcpy (new, outstring, offset); |
4687 | 103 } |
104 else | |
105 { | |
106 outlen *= 2; | |
107 new = (char *) xrealloc (outstring, outlen); | |
108 } | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44890
diff
changeset
|
109 |
34360
c6d74397e65f
(tparam1): Change the way buffers are reallocated to be
Gerd Moellmann <gerd@gnu.org>
parents:
29805
diff
changeset
|
110 op = new + offset; |
c6d74397e65f
(tparam1): Change the way buffers are reallocated to be
Gerd Moellmann <gerd@gnu.org>
parents:
29805
diff
changeset
|
111 outend = new + outlen; |
4687 | 112 outstring = new; |
113 } | |
114 c = *p++; | |
115 if (!c) | |
116 break; | |
117 if (c == '%') | |
118 { | |
119 c = *p++; | |
53270
971b19b300e6
(tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
120 if (explicit_param_p) |
971b19b300e6
(tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
121 explicit_param_p = 0; |
971b19b300e6
(tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
122 else |
971b19b300e6
(tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
123 tem = *argp; |
4687 | 124 switch (c) |
125 { | |
126 case 'd': /* %d means output in decimal. */ | |
127 if (tem < 10) | |
128 goto onedigit; | |
129 if (tem < 100) | |
130 goto twodigit; | |
131 case '3': /* %3 means output in decimal, 3 digits. */ | |
132 if (tem > 999) | |
133 { | |
134 *op++ = tem / 1000 + '0'; | |
135 tem %= 1000; | |
136 } | |
137 *op++ = tem / 100 + '0'; | |
138 case '2': /* %2 means output in decimal, 2 digits. */ | |
139 twodigit: | |
140 tem %= 100; | |
141 *op++ = tem / 10 + '0'; | |
142 onedigit: | |
143 *op++ = tem % 10 + '0'; | |
144 argp++; | |
145 break; | |
53270
971b19b300e6
(tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
146 case 'p': /* %pN means use param N for next subst. */ |
971b19b300e6
(tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
147 tem = fixed_argp[(*p++) - '1']; |
971b19b300e6
(tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
148 explicit_param_p = 1; |
971b19b300e6
(tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
52401
diff
changeset
|
149 break; |
4687 | 150 case 'C': |
151 /* For c-100: print quotient of value by 96, if nonzero, | |
152 then do like %+. */ | |
153 if (tem >= 96) | |
154 { | |
155 *op++ = tem / 96; | |
156 tem %= 96; | |
157 } | |
158 case '+': /* %+x means add character code of char x. */ | |
159 tem += *p++; | |
160 case '.': /* %. means output as character. */ | |
161 if (left) | |
162 { | |
163 /* If want to forbid output of 0 and \n and \t, | |
164 and this is one of them, increment it. */ | |
165 while (tem == 0 || tem == '\n' || tem == '\t') | |
166 { | |
167 tem++; | |
168 if (argp == old_argp) | |
169 doup++, outend -= strlen (up); | |
170 else | |
171 doleft++, outend -= strlen (left); | |
172 } | |
173 } | |
174 *op++ = tem ? tem : 0200; | |
175 case 'f': /* %f means discard next arg. */ | |
176 argp++; | |
177 break; | |
178 | |
179 case 'b': /* %b means back up one arg (and re-use it). */ | |
180 argp--; | |
181 break; | |
182 | |
183 case 'r': /* %r means interchange following two args. */ | |
184 argp[0] = argp[1]; | |
185 argp[1] = tem; | |
186 old_argp++; | |
187 break; | |
188 | |
189 case '>': /* %>xy means if arg is > char code of x, */ | |
190 if (argp[0] > *p++) /* then add char code of y to the arg, */ | |
191 argp[0] += *p; /* and in any case don't output. */ | |
192 p++; /* Leave the arg to be output later. */ | |
193 break; | |
194 | |
195 case 'a': /* %a means arithmetic. */ | |
196 /* Next character says what operation. | |
197 Add or subtract either a constant or some other arg. */ | |
198 /* First following character is + to add or - to subtract | |
199 or = to assign. */ | |
200 /* Next following char is 'p' and an arg spec | |
201 (0100 plus position of that arg relative to this one) | |
202 or 'c' and a constant stored in a character. */ | |
203 tem = p[2] & 0177; | |
204 if (p[1] == 'p') | |
205 tem = argp[tem - 0100]; | |
206 if (p[0] == '-') | |
207 argp[0] -= tem; | |
208 else if (p[0] == '+') | |
209 argp[0] += tem; | |
210 else if (p[0] == '*') | |
211 argp[0] *= tem; | |
212 else if (p[0] == '/') | |
213 argp[0] /= tem; | |
214 else | |
215 argp[0] = tem; | |
216 | |
217 p += 3; | |
218 break; | |
219 | |
220 case 'i': /* %i means add one to arg, */ | |
221 argp[0] ++; /* and leave it to be output later. */ | |
222 argp[1] ++; /* Increment the following arg, too! */ | |
223 break; | |
224 | |
225 case '%': /* %% means output %; no arg. */ | |
226 goto ordinary; | |
227 | |
228 case 'n': /* %n means xor each of next two args with 140. */ | |
229 argp[0] ^= 0140; | |
230 argp[1] ^= 0140; | |
231 break; | |
232 | |
233 case 'm': /* %m means xor each of next two args with 177. */ | |
234 argp[0] ^= 0177; | |
235 argp[1] ^= 0177; | |
236 break; | |
237 | |
238 case 'B': /* %B means express arg as BCD char code. */ | |
239 argp[0] += 6 * (tem / 10); | |
240 break; | |
241 | |
242 case 'D': /* %D means weird Delta Data transformation. */ | |
243 argp[0] -= 2 * (tem % 16); | |
244 break; | |
28573
cdc89dbad540
(tparam1): Abort when encountering an unknown
Gerd Moellmann <gerd@gnu.org>
parents:
14414
diff
changeset
|
245 |
cdc89dbad540
(tparam1): Abort when encountering an unknown
Gerd Moellmann <gerd@gnu.org>
parents:
14414
diff
changeset
|
246 default: |
cdc89dbad540
(tparam1): Abort when encountering an unknown
Gerd Moellmann <gerd@gnu.org>
parents:
14414
diff
changeset
|
247 abort (); |
4687 | 248 } |
249 } | |
250 else | |
251 /* Ordinary character in the argument string. */ | |
252 ordinary: | |
253 *op++ = c; | |
254 } | |
255 *op = 0; | |
256 while (doup-- > 0) | |
257 strcat (op, up); | |
258 while (doleft-- > 0) | |
259 strcat (op, left); | |
260 return outstring; | |
261 } | |
262 | |
263 #ifdef DEBUG | |
264 | |
265 main (argc, argv) | |
266 int argc; | |
267 char **argv; | |
268 { | |
269 char buf[50]; | |
270 int args[3]; | |
271 args[0] = atoi (argv[2]); | |
272 args[1] = atoi (argv[3]); | |
273 args[2] = atoi (argv[4]); | |
274 tparam1 (argv[1], buf, "LEFT", "UP", args); | |
275 printf ("%s\n", buf); | |
276 return 0; | |
277 } | |
278 | |
279 #endif /* DEBUG */ | |
52401 | 280 |