1 /* Merge parameters into a termcap entry string.
2 Copyright (C) 1985, 87, 93, 95 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to the
16 Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
18 /* Emacs config.h may rename various library functions such as malloc. */
25 extern char *getenv ();
26 extern char *malloc ();
27 extern char *realloc ();
30 #else /* not HAVE_CONFIG_H */
32 #if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
33 #define bcopy(s, d, n) memcpy ((d), (s), (n))
44 #endif /* not HAVE_CONFIG_H */
49 #define NULL (char *) 0
56 write (2, "virtual memory exhausted\n", 25);
64 register char *tem = malloc (size);
76 register char *tem = realloc (ptr, size);
82 #endif /* not emacs */
84 /* Assuming STRING is the value of a termcap string entry
85 containing `%' constructs to expand parameters,
86 merge in parameter values and store result in block OUTSTRING points to.
87 LEN is the length of OUTSTRING. If more space is needed,
88 a block is allocated with `malloc'.
90 The value returned is the address of the resulting string.
91 This may be OUTSTRING or may be the address of a block got with `malloc'.
92 In the latter case, the caller must free the block.
94 The fourth and following args to tparam serve as the parameter values. */
96 static char *tparam1 ();
100 tparam (string, outstring, len, arg0, arg1, arg2, arg3)
104 int arg0, arg1, arg2, arg3;
112 return tparam1 (string, outstring, len, NULL, NULL, arg);
115 __private_extern__ char *BC;
116 __private_extern__ char *UP;
118 static char tgoto_buf[50];
122 tgoto (cm, hpos, vpos)
131 return tparam1 (cm, tgoto_buf, 50, UP, BC, args);
135 tparam1 (string, outstring, len, up, left, argp)
143 register char *p = string;
144 register char *op = outstring;
149 int *old_argp = argp;
153 outend = outstring + len;
157 /* If the buffer might be too short, make it bigger. */
158 if (op + 5 >= outend)
164 new = (char *) xmalloc (outlen);
166 bcopy (outstring, new, op - outstring);
172 new = (char *) xrealloc (outstring, outlen);
174 op += new - outstring;
175 outend += new - outstring;
187 case 'd': /* %d means output in decimal. */
192 case '3': /* %3 means output in decimal, 3 digits. */
195 *op++ = tem / 1000 + '0';
198 *op++ = tem / 100 + '0';
199 case '2': /* %2 means output in decimal, 2 digits. */
202 *op++ = tem / 10 + '0';
204 *op++ = tem % 10 + '0';
209 /* For c-100: print quotient of value by 96, if nonzero,
216 case '+': /* %+x means add character code of char x. */
218 case '.': /* %. means output as character. */
221 /* If want to forbid output of 0 and \n and \t,
222 and this is one of them, increment it. */
223 while (tem == 0 || tem == '\n' || tem == '\t')
226 if (argp == old_argp)
227 doup++, outend -= strlen (up);
229 doleft++, outend -= strlen (left);
232 *op++ = tem ? tem : 0200;
233 case 'f': /* %f means discard next arg. */
237 case 'b': /* %b means back up one arg (and re-use it). */
241 case 'r': /* %r means interchange following two args. */
247 case '>': /* %>xy means if arg is > char code of x, */
248 if (argp[0] > *p++) /* then add char code of y to the arg, */
249 argp[0] += *p; /* and in any case don't output. */
250 p++; /* Leave the arg to be output later. */
253 case 'a': /* %a means arithmetic. */
254 /* Next character says what operation.
255 Add or subtract either a constant or some other arg. */
256 /* First following character is + to add or - to subtract
258 /* Next following char is 'p' and an arg spec
259 (0100 plus position of that arg relative to this one)
260 or 'c' and a constant stored in a character. */
263 tem = argp[tem - 0100];
266 else if (p[0] == '+')
268 else if (p[0] == '*')
270 else if (p[0] == '/')
278 case 'i': /* %i means add one to arg, */
279 argp[0] ++; /* and leave it to be output later. */
280 argp[1] ++; /* Increment the following arg, too! */
283 case '%': /* %% means output %; no arg. */
286 case 'n': /* %n means xor each of next two args with 140. */
291 case 'm': /* %m means xor each of next two args with 177. */
296 case 'B': /* %B means express arg as BCD char code. */
297 argp[0] += 6 * (tem / 10);
300 case 'D': /* %D means weird Delta Data transformation. */
301 argp[0] -= 2 * (tem % 16);
306 /* Ordinary character in the argument string. */
326 args[0] = atoi (argv[2]);
327 args[1] = atoi (argv[3]);
328 args[2] = atoi (argv[4]);
329 tparam1 (argv[1], buf, "LEFT", "UP", args);
330 printf ("%s\n", buf);