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
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 /* Emacs config.h may rename various library functions such as malloc. */
25 #include "lisp.h" /* for xmalloc */
27 #if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
28 #define bcopy(s, d, n) memcpy ((d), (s), (n))
39 #endif /* not emacs */
42 #define NULL (char *) 0
49 write (2, "virtual memory exhausted\n", 25);
57 register char *tem
= malloc (size
);
69 register char *tem
= realloc (ptr
, size
);
75 #endif /* not emacs */
77 /* Assuming STRING is the value of a termcap string entry
78 containing `%' constructs to expand parameters,
79 merge in parameter values and store result in block OUTSTRING points to.
80 LEN is the length of OUTSTRING. If more space is needed,
81 a block is allocated with `malloc'.
83 The value returned is the address of the resulting string.
84 This may be OUTSTRING or may be the address of a block got with `malloc'.
85 In the latter case, the caller must free the block.
87 The fourth and following args to tparam serve as the parameter values. */
89 static char *tparam1 ();
93 tparam (string
, outstring
, len
, arg0
, arg1
, arg2
, arg3
)
97 int arg0
, arg1
, arg2
, arg3
;
105 return tparam1 (string
, outstring
, len
, NULL
, NULL
, arg
);
111 static char tgoto_buf
[50];
114 tgoto (cm
, hpos
, vpos
)
123 return tparam1 (cm
, tgoto_buf
, 50, UP
, BC
, args
);
127 tparam1 (string
, outstring
, len
, up
, left
, argp
)
135 register char *p
= string
;
136 register char *op
= outstring
;
141 int *old_argp
= argp
;
145 outend
= outstring
+ len
;
149 /* If the buffer might be too short, make it bigger. */
150 if (op
+ 5 >= outend
)
156 new = (char *) xmalloc (outlen
);
158 bcopy (outstring
, new, op
- outstring
);
164 new = (char *) xrealloc (outstring
, outlen
);
166 op
+= new - outstring
;
167 outend
+= new - outstring
;
179 case 'd': /* %d means output in decimal. */
184 case '3': /* %3 means output in decimal, 3 digits. */
187 *op
++ = tem
/ 1000 + '0';
190 *op
++ = tem
/ 100 + '0';
191 case '2': /* %2 means output in decimal, 2 digits. */
194 *op
++ = tem
/ 10 + '0';
196 *op
++ = tem
% 10 + '0';
201 /* For c-100: print quotient of value by 96, if nonzero,
208 case '+': /* %+x means add character code of char x. */
210 case '.': /* %. means output as character. */
213 /* If want to forbid output of 0 and \n and \t,
214 and this is one of them, increment it. */
215 while (tem
== 0 || tem
== '\n' || tem
== '\t')
218 if (argp
== old_argp
)
219 doup
++, outend
-= strlen (up
);
221 doleft
++, outend
-= strlen (left
);
224 *op
++ = tem
? tem
: 0200;
225 case 'f': /* %f means discard next arg. */
229 case 'b': /* %b means back up one arg (and re-use it). */
233 case 'r': /* %r means interchange following two args. */
239 case '>': /* %>xy means if arg is > char code of x, */
240 if (argp
[0] > *p
++) /* then add char code of y to the arg, */
241 argp
[0] += *p
; /* and in any case don't output. */
242 p
++; /* Leave the arg to be output later. */
245 case 'a': /* %a means arithmetic. */
246 /* Next character says what operation.
247 Add or subtract either a constant or some other arg. */
248 /* First following character is + to add or - to subtract
250 /* Next following char is 'p' and an arg spec
251 (0100 plus position of that arg relative to this one)
252 or 'c' and a constant stored in a character. */
255 tem
= argp
[tem
- 0100];
258 else if (p
[0] == '+')
260 else if (p
[0] == '*')
262 else if (p
[0] == '/')
270 case 'i': /* %i means add one to arg, */
271 argp
[0] ++; /* and leave it to be output later. */
272 argp
[1] ++; /* Increment the following arg, too! */
275 case '%': /* %% means output %; no arg. */
278 case 'n': /* %n means xor each of next two args with 140. */
283 case 'm': /* %m means xor each of next two args with 177. */
288 case 'B': /* %B means express arg as BCD char code. */
289 argp
[0] += 6 * (tem
/ 10);
292 case 'D': /* %D means weird Delta Data transformation. */
293 argp
[0] -= 2 * (tem
% 16);
301 /* Ordinary character in the argument string. */
321 args
[0] = atoi (argv
[2]);
322 args
[1] = atoi (argv
[3]);
323 args
[2] = atoi (argv
[4]);
324 tparam1 (argv
[1], buf
, "LEFT", "UP", args
);
325 printf ("%s\n", buf
);