1 /* Merge parameters into a termcap entry string.
2 Copyright (C) 1985, 1987, 1993 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
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
18 /* Emacs config.h may rename various library functions such as malloc. */
21 #else /* not HAVE_CONFIG_H */
23 #if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
24 #define bcopy(s, d, n) memcpy ((d), (s), (n))
35 #endif /* not HAVE_CONFIG_H */
38 #define NULL (char *) 0
45 write (2, "virtual memory exhausted\n", 25);
53 register char *tem
= malloc (size
);
65 register char *tem
= realloc (ptr
, size
);
71 #endif /* not emacs */
73 /* Assuming STRING is the value of a termcap string entry
74 containing `%' constructs to expand parameters,
75 merge in parameter values and store result in block OUTSTRING points to.
76 LEN is the length of OUTSTRING. If more space is needed,
77 a block is allocated with `malloc'.
79 The value returned is the address of the resulting string.
80 This may be OUTSTRING or may be the address of a block got with `malloc'.
81 In the latter case, the caller must free the block.
83 The fourth and following args to tparam serve as the parameter values. */
85 static char *tparam1 ();
89 tparam (string
, outstring
, len
, arg0
, arg1
, arg2
, arg3
)
93 int arg0
, arg1
, arg2
, arg3
;
101 return tparam1 (string
, outstring
, len
, NULL
, NULL
, arg
);
103 return tparam1 (string
, outstring
, len
, NULL
, NULL
, &arg0
);
110 static char tgoto_buf
[50];
113 tgoto (cm
, hpos
, vpos
)
122 return tparam1 (cm
, tgoto_buf
, 50, UP
, BC
, args
);
126 tparam1 (string
, outstring
, len
, up
, left
, argp
)
134 register char *p
= string
;
135 register char *op
= outstring
;
140 int *old_argp
= argp
;
144 outend
= outstring
+ len
;
148 /* If the buffer might be too short, make it bigger. */
149 if (op
+ 5 >= outend
)
155 new = (char *) xmalloc (outlen
);
157 bcopy (outstring
, new, op
- outstring
);
163 new = (char *) xrealloc (outstring
, outlen
);
165 op
+= new - outstring
;
166 outend
+= new - outstring
;
178 case 'd': /* %d means output in decimal. */
183 case '3': /* %3 means output in decimal, 3 digits. */
186 *op
++ = tem
/ 1000 + '0';
189 *op
++ = tem
/ 100 + '0';
190 case '2': /* %2 means output in decimal, 2 digits. */
193 *op
++ = tem
/ 10 + '0';
195 *op
++ = tem
% 10 + '0';
200 /* For c-100: print quotient of value by 96, if nonzero,
207 case '+': /* %+x means add character code of char x. */
209 case '.': /* %. means output as character. */
212 /* If want to forbid output of 0 and \n and \t,
213 and this is one of them, increment it. */
214 while (tem
== 0 || tem
== '\n' || tem
== '\t')
217 if (argp
== old_argp
)
218 doup
++, outend
-= strlen (up
);
220 doleft
++, outend
-= strlen (left
);
223 *op
++ = tem
? tem
: 0200;
224 case 'f': /* %f means discard next arg. */
228 case 'b': /* %b means back up one arg (and re-use it). */
232 case 'r': /* %r means interchange following two args. */
238 case '>': /* %>xy means if arg is > char code of x, */
239 if (argp
[0] > *p
++) /* then add char code of y to the arg, */
240 argp
[0] += *p
; /* and in any case don't output. */
241 p
++; /* Leave the arg to be output later. */
244 case 'a': /* %a means arithmetic. */
245 /* Next character says what operation.
246 Add or subtract either a constant or some other arg. */
247 /* First following character is + to add or - to subtract
249 /* Next following char is 'p' and an arg spec
250 (0100 plus position of that arg relative to this one)
251 or 'c' and a constant stored in a character. */
254 tem
= argp
[tem
- 0100];
257 else if (p
[0] == '+')
259 else if (p
[0] == '*')
261 else if (p
[0] == '/')
269 case 'i': /* %i means add one to arg, */
270 argp
[0] ++; /* and leave it to be output later. */
271 argp
[1] ++; /* Increment the following arg, too! */
274 case '%': /* %% means output %; no arg. */
277 case 'n': /* %n means xor each of next two args with 140. */
282 case 'm': /* %m means xor each of next two args with 177. */
287 case 'B': /* %B means express arg as BCD char code. */
288 argp
[0] += 6 * (tem
/ 10);
291 case 'D': /* %D means weird Delta Data transformation. */
292 argp
[0] -= 2 * (tem
% 16);
297 /* Ordinary character in the argument string. */
317 args
[0] = atoi (argv
[2]);
318 args
[1] = atoi (argv
[3]);
319 args
[2] = atoi (argv
[4]);
320 tparam1 (argv
[1], buf
, "LEFT", "UP", args
);
321 printf ("%s\n", buf
);