1 /* Merge parameters into a termcap entry string.
2 Copyright (C) 1985, 1987, 1993, 1995, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA. */
20 /* Emacs config.h may rename various library functions such as malloc. */
23 #include "lisp.h" /* for xmalloc */
26 #define NULL (char *) 0
29 /* Assuming STRING is the value of a termcap string entry
30 containing `%' constructs to expand parameters,
31 merge in parameter values and store result in block OUTSTRING points to.
32 LEN is the length of OUTSTRING. If more space is needed,
33 a block is allocated with `malloc'.
35 The value returned is the address of the resulting string.
36 This may be OUTSTRING or may be the address of a block got with `malloc'.
37 In the latter case, the caller must free the block.
39 The fourth and following args to tparam serve as the parameter values. */
41 static char *tparam1 (char *string
, char *outstring
, int len
, char *up
, char *left
, register int *argp
);
45 tparam (char *string
, char *outstring
, int len
, int arg0
, int arg1
, int arg2
, int arg3
)
53 return tparam1 (string
, outstring
, len
, NULL
, NULL
, arg
);
59 static char tgoto_buf
[50];
62 tgoto (char *cm
, int hpos
, int vpos
)
69 return tparam1 (cm
, tgoto_buf
, 50, UP
, BC
, args
);
73 tparam1 (char *string
, char *outstring
, int len
, char *up
, char *left
, register int *argp
)
76 register char *p
= string
;
77 register char *op
= outstring
;
82 int *old_argp
= argp
; /* can move */
83 int *fixed_argp
= argp
; /* never moves */
84 int explicit_param_p
= 0; /* set by %p */
88 outend
= outstring
+ len
;
92 /* If the buffer might be too short, make it bigger. */
96 int offset
= op
- outstring
;
101 new = (char *) xmalloc (outlen
);
102 memcpy (new, outstring
, offset
);
107 new = (char *) xrealloc (outstring
, outlen
);
111 outend
= new + outlen
;
120 if (explicit_param_p
)
121 explicit_param_p
= 0;
126 case 'd': /* %d means output in decimal. */
131 case '3': /* %3 means output in decimal, 3 digits. */
134 *op
++ = tem
/ 1000 + '0';
137 *op
++ = tem
/ 100 + '0';
138 case '2': /* %2 means output in decimal, 2 digits. */
141 *op
++ = tem
/ 10 + '0';
143 *op
++ = tem
% 10 + '0';
146 case 'p': /* %pN means use param N for next subst. */
147 tem
= fixed_argp
[(*p
++) - '1'];
148 explicit_param_p
= 1;
151 /* For c-100: print quotient of value by 96, if nonzero,
158 case '+': /* %+x means add character code of char x. */
160 case '.': /* %. means output as character. */
163 /* If want to forbid output of 0 and \n and \t,
164 and this is one of them, increment it. */
165 while (tem
== 0 || tem
== '\n' || tem
== '\t')
168 if (argp
== old_argp
)
169 doup
++, outend
-= strlen (up
);
171 doleft
++, outend
-= strlen (left
);
174 *op
++ = tem
? tem
: 0200;
175 case 'f': /* %f means discard next arg. */
179 case 'b': /* %b means back up one arg (and re-use it). */
183 case 'r': /* %r means interchange following two args. */
189 case '>': /* %>xy means if arg is > char code of x, */
190 if (argp
[0] > *p
++) /* then add char code of y to the arg, */
191 argp
[0] += *p
; /* and in any case don't output. */
192 p
++; /* Leave the arg to be output later. */
195 case 'a': /* %a means arithmetic. */
196 /* Next character says what operation.
197 Add or subtract either a constant or some other arg. */
198 /* First following character is + to add or - to subtract
200 /* Next following char is 'p' and an arg spec
201 (0100 plus position of that arg relative to this one)
202 or 'c' and a constant stored in a character. */
205 tem
= argp
[tem
- 0100];
208 else if (p
[0] == '+')
210 else if (p
[0] == '*')
212 else if (p
[0] == '/')
220 case 'i': /* %i means add one to arg, */
221 argp
[0] ++; /* and leave it to be output later. */
222 argp
[1] ++; /* Increment the following arg, too! */
225 case '%': /* %% means output %; no arg. */
228 case 'n': /* %n means xor each of next two args with 140. */
233 case 'm': /* %m means xor each of next two args with 177. */
238 case 'B': /* %B means express arg as BCD char code. */
239 argp
[0] += 6 * (tem
/ 10);
242 case 'D': /* %D means weird Delta Data transformation. */
243 argp
[0] -= 2 * (tem
% 16);
251 /* Ordinary character in the argument string. */
271 args
[0] = atoi (argv
[2]);
272 args
[1] = atoi (argv
[3]);
273 args
[2] = atoi (argv
[4]);
274 tparam1 (argv
[1], buf
, "LEFT", "UP", args
);
275 printf ("%s\n", buf
);
281 /* arch-tag: 83f7b5ac-a808-4f75-b87a-123de009b402
282 (do not change this comment) */