annotate src/tparam.c @ 112328:ba9f26694b92

Merge from mainline.
author Paul Eggert <eggert@cs.ucla.edu>
date Fri, 14 Jan 2011 13:12:57 -0800
parents 76e072dbe342
children ef719132ddfa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
1 /* Merge parameters into a termcap entry string.
75227
e90d04cd455a Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents: 68651
diff changeset
2 Copyright (C) 1985, 1987, 1993, 1995, 2000, 2001, 2002, 2003, 2004,
100960
69177b934405 Revert copyright year changes for files that are not part of Emacs.
Glenn Morris <rgm@gnu.org>
parents: 100951
diff changeset
3 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
4
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
7 the Free Software Foundation; either version 2, or (at your option)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
8 any later version.
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
9
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
13 GNU General Public License for more details.
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
14
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
16 along with this program; see the file COPYING. If not, write to
64084
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 53270
diff changeset
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 53270
diff changeset
18 Boston, MA 02110-1301, USA. */
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
19
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
20 /* Emacs config.h may rename various library functions such as malloc. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
21 #include <config.h>
105669
68dd71358159 * alloc.c: Do not define struct catchtag.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 100960
diff changeset
22 #include <setjmp.h>
29805
0df8151400b9 [emacs]: Include lisp.h.
Dave Love <fx@gnu.org>
parents: 28573
diff changeset
23 #include "lisp.h" /* for xmalloc */
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
24
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
25 #ifndef NULL
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
26 #define NULL (char *) 0
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
27 #endif
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
28
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
29 /* Assuming STRING is the value of a termcap string entry
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
30 containing `%' constructs to expand parameters,
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
31 merge in parameter values and store result in block OUTSTRING points to.
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
32 LEN is the length of OUTSTRING. If more space is needed,
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
33 a block is allocated with `malloc'.
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
34
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
35 The value returned is the address of the resulting string.
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
36 This may be OUTSTRING or may be the address of a block got with `malloc'.
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
37 In the latter case, the caller must free the block.
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
38
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
39 The fourth and following args to tparam serve as the parameter values. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
40
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 105669
diff changeset
41 static char *tparam1 (char *string, char *outstring, int len, char *up, char *left, register int *argp);
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
42
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
43 /* VARARGS 2 */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
44 char *
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 105669
diff changeset
45 tparam (char *string, char *outstring, int len, int arg0, int arg1, int arg2, int arg3)
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
46 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
47 int arg[4];
12678
8fc56d171ada (tparam): Remove arg array and the #ifdef.
David J. MacKenzie <djm@gnu.org>
parents: 4687
diff changeset
48
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
49 arg[0] = arg0;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
50 arg[1] = arg1;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
51 arg[2] = arg2;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
52 arg[3] = arg3;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
53 return tparam1 (string, outstring, len, NULL, NULL, arg);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
54 }
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
55
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
56 char *BC;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
57 char *UP;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
58
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
59 static char tgoto_buf[50];
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
60
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
61 char *
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 105669
diff changeset
62 tgoto (char *cm, int hpos, int vpos)
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
63 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
64 int args[2];
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
65 if (!cm)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
66 return NULL;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
67 args[0] = vpos;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
68 args[1] = hpos;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
69 return tparam1 (cm, tgoto_buf, 50, UP, BC, args);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
70 }
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
71
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
72 static char *
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 105669
diff changeset
73 tparam1 (char *string, char *outstring, int len, char *up, char *left, register int *argp)
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
74 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
75 register int c;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
76 register char *p = string;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
77 register char *op = outstring;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
78 char *outend;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
79 int outlen = 0;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
80
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
81 register int tem;
53270
971b19b300e6 (tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
82 int *old_argp = argp; /* can move */
971b19b300e6 (tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
83 int *fixed_argp = argp; /* never moves */
971b19b300e6 (tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
84 int explicit_param_p = 0; /* set by %p */
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
85 int doleft = 0;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
86 int doup = 0;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
87
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
88 outend = outstring + len;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
89
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
90 while (1)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
91 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
92 /* If the buffer might be too short, make it bigger. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
93 if (op + 5 >= outend)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
94 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
95 register char *new;
34360
c6d74397e65f (tparam1): Change the way buffers are reallocated to be
Gerd Moellmann <gerd@gnu.org>
parents: 29805
diff changeset
96 int offset = op - outstring;
c6d74397e65f (tparam1): Change the way buffers are reallocated to be
Gerd Moellmann <gerd@gnu.org>
parents: 29805
diff changeset
97
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
98 if (outlen == 0)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
99 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
100 outlen = len + 40;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
101 new = (char *) xmalloc (outlen);
109165
750db9f3e6d8 Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents: 109126
diff changeset
102 memcpy (new, outstring, offset);
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
103 }
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
104 else
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
105 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
106 outlen *= 2;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
107 new = (char *) xrealloc (outstring, outlen);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
108 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 44890
diff changeset
109
34360
c6d74397e65f (tparam1): Change the way buffers are reallocated to be
Gerd Moellmann <gerd@gnu.org>
parents: 29805
diff changeset
110 op = new + offset;
c6d74397e65f (tparam1): Change the way buffers are reallocated to be
Gerd Moellmann <gerd@gnu.org>
parents: 29805
diff changeset
111 outend = new + outlen;
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
112 outstring = new;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
113 }
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
114 c = *p++;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
115 if (!c)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
116 break;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
117 if (c == '%')
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
118 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
119 c = *p++;
53270
971b19b300e6 (tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
120 if (explicit_param_p)
971b19b300e6 (tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
121 explicit_param_p = 0;
971b19b300e6 (tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
122 else
971b19b300e6 (tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
123 tem = *argp;
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
124 switch (c)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
125 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
126 case 'd': /* %d means output in decimal. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
127 if (tem < 10)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
128 goto onedigit;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
129 if (tem < 100)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
130 goto twodigit;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
131 case '3': /* %3 means output in decimal, 3 digits. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
132 if (tem > 999)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
133 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
134 *op++ = tem / 1000 + '0';
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
135 tem %= 1000;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
136 }
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
137 *op++ = tem / 100 + '0';
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
138 case '2': /* %2 means output in decimal, 2 digits. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
139 twodigit:
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
140 tem %= 100;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
141 *op++ = tem / 10 + '0';
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
142 onedigit:
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
143 *op++ = tem % 10 + '0';
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
144 argp++;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
145 break;
53270
971b19b300e6 (tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
146 case 'p': /* %pN means use param N for next subst. */
971b19b300e6 (tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
147 tem = fixed_argp[(*p++) - '1'];
971b19b300e6 (tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
148 explicit_param_p = 1;
971b19b300e6 (tparam1): Add handling for `%pN', which
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
149 break;
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
150 case 'C':
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
151 /* For c-100: print quotient of value by 96, if nonzero,
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
152 then do like %+. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
153 if (tem >= 96)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
154 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
155 *op++ = tem / 96;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
156 tem %= 96;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
157 }
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
158 case '+': /* %+x means add character code of char x. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
159 tem += *p++;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
160 case '.': /* %. means output as character. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
161 if (left)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
162 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
163 /* If want to forbid output of 0 and \n and \t,
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
164 and this is one of them, increment it. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
165 while (tem == 0 || tem == '\n' || tem == '\t')
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
166 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
167 tem++;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
168 if (argp == old_argp)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
169 doup++, outend -= strlen (up);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
170 else
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
171 doleft++, outend -= strlen (left);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
172 }
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
173 }
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
174 *op++ = tem ? tem : 0200;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
175 case 'f': /* %f means discard next arg. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
176 argp++;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
177 break;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
178
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
179 case 'b': /* %b means back up one arg (and re-use it). */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
180 argp--;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
181 break;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
182
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
183 case 'r': /* %r means interchange following two args. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
184 argp[0] = argp[1];
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
185 argp[1] = tem;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
186 old_argp++;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
187 break;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
188
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
189 case '>': /* %>xy means if arg is > char code of x, */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
190 if (argp[0] > *p++) /* then add char code of y to the arg, */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
191 argp[0] += *p; /* and in any case don't output. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
192 p++; /* Leave the arg to be output later. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
193 break;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
194
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
195 case 'a': /* %a means arithmetic. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
196 /* Next character says what operation.
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
197 Add or subtract either a constant or some other arg. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
198 /* First following character is + to add or - to subtract
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
199 or = to assign. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
200 /* Next following char is 'p' and an arg spec
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
201 (0100 plus position of that arg relative to this one)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
202 or 'c' and a constant stored in a character. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
203 tem = p[2] & 0177;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
204 if (p[1] == 'p')
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
205 tem = argp[tem - 0100];
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
206 if (p[0] == '-')
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
207 argp[0] -= tem;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
208 else if (p[0] == '+')
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
209 argp[0] += tem;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
210 else if (p[0] == '*')
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
211 argp[0] *= tem;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
212 else if (p[0] == '/')
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
213 argp[0] /= tem;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
214 else
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
215 argp[0] = tem;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
216
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
217 p += 3;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
218 break;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
219
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
220 case 'i': /* %i means add one to arg, */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
221 argp[0] ++; /* and leave it to be output later. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
222 argp[1] ++; /* Increment the following arg, too! */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
223 break;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
224
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
225 case '%': /* %% means output %; no arg. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
226 goto ordinary;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
227
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
228 case 'n': /* %n means xor each of next two args with 140. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
229 argp[0] ^= 0140;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
230 argp[1] ^= 0140;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
231 break;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
232
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
233 case 'm': /* %m means xor each of next two args with 177. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
234 argp[0] ^= 0177;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
235 argp[1] ^= 0177;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
236 break;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
237
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
238 case 'B': /* %B means express arg as BCD char code. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
239 argp[0] += 6 * (tem / 10);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
240 break;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
241
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
242 case 'D': /* %D means weird Delta Data transformation. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
243 argp[0] -= 2 * (tem % 16);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
244 break;
28573
cdc89dbad540 (tparam1): Abort when encountering an unknown
Gerd Moellmann <gerd@gnu.org>
parents: 14414
diff changeset
245
cdc89dbad540 (tparam1): Abort when encountering an unknown
Gerd Moellmann <gerd@gnu.org>
parents: 14414
diff changeset
246 default:
cdc89dbad540 (tparam1): Abort when encountering an unknown
Gerd Moellmann <gerd@gnu.org>
parents: 14414
diff changeset
247 abort ();
4687
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
248 }
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
249 }
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
250 else
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
251 /* Ordinary character in the argument string. */
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
252 ordinary:
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
253 *op++ = c;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
254 }
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
255 *op = 0;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
256 while (doup-- > 0)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
257 strcat (op, up);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
258 while (doleft-- > 0)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
259 strcat (op, left);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
260 return outstring;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
261 }
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
262
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
263 #ifdef DEBUG
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
264
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
265 main (argc, argv)
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
266 int argc;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
267 char **argv;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
268 {
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
269 char buf[50];
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
270 int args[3];
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
271 args[0] = atoi (argv[2]);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
272 args[1] = atoi (argv[3]);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
273 args[2] = atoi (argv[4]);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
274 tparam1 (argv[1], buf, "LEFT", "UP", args);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
275 printf ("%s\n", buf);
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
276 return 0;
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
277 }
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
278
f0abfb1b59fd entered into RCS
Roland McGrath <roland@gnu.org>
parents:
diff changeset
279 #endif /* DEBUG */
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
280
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
281 /* arch-tag: 83f7b5ac-a808-4f75-b87a-123de009b402
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
282 (do not change this comment) */