This source file includes following definitions.
- tparam
- tgoto
- tparam1
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include "lisp.h"
22 #include "tparam.h"
23
24
25
26
27
28
29
30
31
32
33
34
35
36 static char *tparam1 (char const *string, char *outstring, int len,
37 char *up, char *left, int *argp);
38
39 char *
40 tparam (const char *string, char *outstring, int len,
41 int arg0, int arg1, int arg2, int arg3)
42 {
43 int arg[4];
44
45 arg[0] = arg0;
46 arg[1] = arg1;
47 arg[2] = arg2;
48 arg[3] = arg3;
49 return tparam1 (string, outstring, len, NULL, NULL, arg);
50 }
51
52 char *BC;
53 char *UP;
54
55 static char tgoto_buf[50];
56
57 char *
58 tgoto (const char *cm, int hpos, int vpos)
59 {
60 int args[2];
61 if (!cm)
62 return NULL;
63 args[0] = vpos;
64 args[1] = hpos;
65 return tparam1 (cm, tgoto_buf, 50, UP, BC, args);
66 }
67
68 static char *
69 tparam1 (const char *string, char *outstring, int len,
70 char *up, char *left, register int *argp)
71 {
72 register int c;
73 register const char *p = string;
74 register char *op = outstring;
75 char *outend;
76 char *new = 0;
77 ptrdiff_t outlen = 0;
78
79 register int tem;
80 int *old_argp = argp;
81 int *fixed_argp = argp;
82 bool explicit_param_p = false;
83 ptrdiff_t doleft = 0;
84 ptrdiff_t doup = 0;
85 ptrdiff_t append_len = 0;
86
87 outend = outstring + len;
88
89 while (true)
90 {
91
92 while (outend - op - append_len <= 5)
93 {
94 ptrdiff_t offset = op - outstring;
95
96 if (outlen == 0)
97 {
98 outlen = len + 40;
99 new = xmalloc (outlen);
100 memcpy (new, outstring, offset);
101 }
102 else
103 {
104 new = xpalloc (outstring, &outlen, 1, -1, 1);
105 }
106
107 op = new + offset;
108 outend = new + outlen;
109 outstring = new;
110 }
111 c = *p++;
112 if (!c)
113 break;
114 if (c == '%')
115 {
116 c = *p++;
117 if (explicit_param_p)
118 explicit_param_p = false;
119 else
120 tem = *argp;
121 switch (c)
122 {
123 case 'd':
124 if (tem < 10)
125 goto onedigit;
126 if (tem < 100)
127 goto twodigit;
128 FALLTHROUGH;
129 case '3':
130 if (tem > 999)
131 {
132 *op++ = tem / 1000 + '0';
133 tem %= 1000;
134 }
135 *op++ = tem / 100 + '0';
136 FALLTHROUGH;
137 case '2':
138 twodigit:
139 tem %= 100;
140 *op++ = tem / 10 + '0';
141 onedigit:
142 *op++ = tem % 10 + '0';
143 argp++;
144 break;
145
146 case 'p':
147 tem = fixed_argp[(*p++) - '1'];
148 explicit_param_p = true;
149 break;
150
151 case 'C':
152
153
154 if (tem >= 96)
155 {
156 *op++ = tem / 96;
157 tem %= 96;
158 }
159 FALLTHROUGH;
160 case '+':
161 tem += *p++;
162 FALLTHROUGH;
163 case '.':
164 if (left)
165 {
166
167
168 while (tem == 0 || tem == '\n' || tem == '\t')
169 {
170 ptrdiff_t append_len_incr;
171 tem++;
172 if (argp == old_argp)
173 doup++, append_len_incr = strlen (up);
174 else
175 doleft++, append_len_incr = strlen (left);
176 if (INT_ADD_WRAPV (append_len_incr,
177 append_len, &append_len))
178 memory_full (SIZE_MAX);
179 }
180 }
181 *op++ = tem ? tem : 0200;
182 FALLTHROUGH;
183 case 'f':
184 argp++;
185 break;
186
187 case 'b':
188 argp--;
189 break;
190
191 case 'r':
192 argp[0] = argp[1];
193 argp[1] = tem;
194 old_argp++;
195 break;
196
197 case '>':
198 if (argp[0] > *p++)
199 argp[0] += *p;
200 p++;
201 break;
202
203 case 'a':
204
205
206
207
208
209
210
211 tem = p[2] & 0177;
212 if (p[1] == 'p')
213 tem = argp[tem - 0100];
214 if (p[0] == '-')
215 argp[0] -= tem;
216 else if (p[0] == '+')
217 argp[0] += tem;
218 else if (p[0] == '*')
219 argp[0] *= tem;
220 else if (p[0] == '/')
221 argp[0] /= tem;
222 else
223 argp[0] = tem;
224
225 p += 3;
226 break;
227
228 case 'i':
229 argp[0] ++;
230 argp[1] ++;
231 break;
232
233 case '%':
234 goto ordinary;
235
236 case 'n':
237 argp[0] ^= 0140;
238 argp[1] ^= 0140;
239 break;
240
241 case 'm':
242 argp[0] ^= 0177;
243 argp[1] ^= 0177;
244 break;
245
246 case 'B':
247 argp[0] += 6 * (tem / 10);
248 break;
249
250 case 'D':
251 argp[0] -= 2 * (tem % 16);
252 break;
253
254 default:
255 emacs_abort ();
256 }
257 }
258 else
259
260 ordinary:
261 *op++ = c;
262 }
263 *op = 0;
264 while (doup-- > 0)
265 op = stpcpy (op, up);
266 while (doleft-- > 0)
267 op = stpcpy (op, left);
268 return outstring;
269 }
270
271 #ifdef DEBUG
272
273 int
274 main (int argc, char **argv)
275 {
276 char buf[50];
277 int args[3];
278 args[0] = atoi (argv[2]);
279 args[1] = atoi (argv[3]);
280 args[2] = atoi (argv[4]);
281 tparam1 (argv[1], buf, 50, "LEFT", "UP", args);
282 printf ("%s\n", buf);
283 return 0;
284 }
285
286 #endif