1 /* Merge parameters into a termcap entry string.
2 Copyright (C) 1985, 1987, 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of XEmacs.
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Synched up with: Not synched with FSF. */
23 /* config.h may rename various library functions such as malloc. */
30 #define realloc xrealloc
31 #define malloc xmalloc
33 extern void *xmalloc (size_t size);
34 extern void *xrealloc (void *, size_t size);
42 extern char *malloc ();
43 extern char *realloc ();
48 /* Assuming STRING is the value of a termcap string entry
49 containing `%' constructs to expand parameters,
50 merge in parameter values and store result in block OUTSTRING points to.
51 LEN is the length of OUTSTRING. If more space is needed,
52 a block is allocated with `malloc'.
54 The value returned is the address of the resulting string.
55 This may be OUTSTRING or may be the address of a block got with `malloc'.
56 In the latter case, the caller must free the block.
58 The fourth and following args to tparam serve as the parameter values. */
60 static char *tparam1 (const char *string, char *outstring, int len,
61 const char *up, const char *left,
64 /* XEmacs: renamed this function because just tparam() conflicts with
66 char *emacs_tparam (const char *string, char *outstring, int len, int arg0,
67 int arg1, int arg2, int arg3);
69 emacs_tparam (const char *string, char *outstring, int len, int arg0,
70 int arg1, int arg2, int arg3)
77 return tparam1 (string, outstring, len, 0, 0, arg);
83 static char tgoto_buf[50];
85 char *tgoto (const char *cm, int hpos, int vpos);
87 tgoto (const char *cm, int hpos, int vpos)
94 return tparam1 (cm, tgoto_buf, 50, UP, BC, args);
98 tparam1 (const char *string, char *outstring, int len, const char *up,
99 const char *left, int *argp)
102 const char *p = string;
103 char *op = outstring;
108 int *old_argp = argp;
112 outend = outstring + len;
116 /* If the buffer might be too short, make it bigger. */
117 if (op + 5 >= outend)
123 new = (char *) malloc (outlen);
125 memcpy (new, outstring, op - outstring);
131 new = (char *) realloc (outstring, outlen);
133 op += new - outstring;
134 outend += new - outstring;
146 case 'd': /* %d means output in decimal. */
151 case '3': /* %3 means output in decimal, 3 digits. */
154 *op++ = tem / 1000 + '0';
157 *op++ = tem / 100 + '0';
158 case '2': /* %2 means output in decimal, 2 digits. */
161 *op++ = tem / 10 + '0';
163 *op++ = tem % 10 + '0';
168 /* For c-100: print quotient of value by 96, if nonzero,
175 case '+': /* %+x means add character code of char x. */
177 case '.': /* %. means output as character. */
180 /* If want to forbid output of 0 and \n and \t,
181 and this is one of them, increment it. */
182 while (tem == 0 || tem == '\n' || tem == '\t')
185 if (argp == old_argp)
186 doup++, outend -= strlen (up);
188 doleft++, outend -= strlen (left);
192 case 'f': /* %f means discard next arg. */
196 case 'b': /* %b means back up one arg (and re-use it). */
200 case 'r': /* %r means interchange following two args. */
206 case '>': /* %>xy means if arg is > char code of x, */
207 if (argp[0] > *p++) /* then add char code of y to the arg, */
208 argp[0] += *p; /* and in any case don't output. */
209 p++; /* Leave the arg to be output later. */
212 case 'a': /* %a means arithmetic. */
213 /* Next character says what operation.
214 Add or subtract either a constant or some other arg. */
215 /* First following character is + to add or - to subtract
217 /* Next following char is 'p' and an arg spec
218 (0100 plus position of that arg relative to this one)
219 or 'c' and a constant stored in a character. */
222 tem = argp[tem - 0100];
225 else if (p[0] == '+')
227 else if (p[0] == '*')
229 else if (p[0] == '/')
237 case 'i': /* %i means add one to arg, */
238 argp[0] ++; /* and leave it to be output later. */
239 argp[1] ++; /* Increment the following arg, too! */
242 case '%': /* %% means output %; no arg. */
245 case 'n': /* %n means xor each of next two args with 140. */
250 case 'm': /* %m means xor each of next two args with 177. */
255 case 'B': /* %B means express arg as BCD char code. */
256 argp[0] += 6 * (tem / 10);
259 case 'D': /* %D means weird Delta Data transformation. */
260 argp[0] -= 2 * (tem % 16);
265 /* Ordinary character in the argument string. */
285 args[0] = atoi (argv[2]);
286 args[1] = atoi (argv[3]);
287 args[2] = atoi (argv[4]);
288 tparam1 (argv[1], buf, "LEFT", "UP", args);
289 printf ("%s\n", buf);