Print this page
5083 avoid undefined order of operations in assignments
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/troff/nroff.d/n6.c
+++ new/usr/src/cmd/troff/nroff.d/n6.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 28 /* All Rights Reserved */
29 29
↓ open down ↓ |
29 lines elided |
↑ open up ↑ |
30 30 /*
31 31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 32 * The Regents of the University of California
33 33 * All Rights Reserved
34 34 *
35 35 * University Acknowledgment- Portions of this document are derived from
36 36 * software developed by the University of California, Berkeley, and its
37 37 * contributors.
38 38 */
39 39
40 -#pragma ident "%Z%%M% %I% %E% SMI"
41 -
42 40 #include "tdef.h"
43 41 #include "tw.h"
44 42 #include "ext.h"
45 43 #include <ctype.h>
46 44
47 45 /*
48 46 * n6.c -- width functions, sizes and fonts
49 47 */
50 48
51 49 int bdtab[NFONT+1] ={ 0, 0, 0, 3, 3, 0, };
52 50 int sbold = 0;
53 51 int fontlab[NFONT+1] = { 0, 'R', 'I', 'B', PAIR('B','I'), 'S', 0 };
54 52
55 53 extern int nchtab;
56 54
57 55 int
58 56 width(j)
59 57 tchar j;
60 58 {
61 59 int i, k;
62 60
63 61 if (j & (ZBIT|MOT)) {
64 62 if (iszbit(j))
65 63 return(0);
66 64 if (isvmot(j))
67 65 return(0);
68 66 k = absmot(j);
69 67 if (isnmot(j))
70 68 k = -k;
71 69 return(k);
72 70 }
73 71 i = cbits(j);
74 72 if (i < ' ') {
75 73 if (i == '\b')
76 74 return(-widthp);
77 75 if (i == PRESC)
78 76 i = eschar;
79 77 else if (iscontrol(i))
80 78 return(0);
81 79 }
82 80 if (i==ohc)
83 81 return(0);
84 82 #ifdef EUC
85 83 #ifdef NROFF
86 84 if (multi_locale) {
87 85 if ((j & MBMASK) || (j & CSMASK)) {
88 86 switch(j & MBMASK) {
89 87 case BYTE_CHR:
90 88 case LASTOFMB:
91 89 k = t.Char * csi_width[cs(j)];
92 90 break;
93 91 default:
94 92 k = 0;
95 93 break;
96 94 }
97 95 widthp = k;
98 96 return(k);
99 97 }
100 98 }
101 99 i &= 0x1ff;
102 100 #endif /* NROFF */
103 101 #endif /* EUC */
104 102 i = trtab[i];
105 103 if (i < 32)
106 104 return(0);
107 105 k = t.width[i] * t.Char;
108 106 widthp = k;
109 107 return(k);
110 108 }
111 109
112 110
113 111 tchar setch()
114 112 {
115 113 int j;
116 114 char temp[10];
117 115 char *s;
118 116
119 117 s = temp;
120 118 if ((*s++ = getach()) == 0 || (*s++ = getach()) == 0)
121 119 return(0);
122 120 *s = '\0';
123 121 if ((j = findch(temp)) > 0)
124 122 return j | chbits;
125 123 else
126 124 return 0;
127 125 }
128 126
129 127 tchar setabs() /* set absolute char from \C'...' */
130 128 { /* for now, a no-op */
131 129 int i, n, nf;
132 130
133 131 getch();
134 132 n = 0;
135 133 n = inumb(&n);
136 134 getch();
137 135 if (nonumb)
138 136 return 0;
139 137 return n + nchtab + _SPECCHAR_ST;
140 138 }
141 139
142 140 int
143 141 findft(i)
144 142 int i;
145 143 {
146 144 int k;
147 145
148 146 if ((k = i - '0') >= 0 && k <= nfonts && k < smnt)
149 147 return(k);
150 148 for (k = 0; fontlab[k] != i; k++)
151 149 if (k > nfonts)
152 150 return(-1);
153 151 return(k);
154 152 }
155 153
156 154 int
157 155 caseps()
158 156 {
159 157 return (0);
160 158 }
161 159
162 160 int
163 161 mchbits()
164 162 {
165 163 chbits = 0;
166 164 setfbits(chbits, font);
167 165 sps = width(' ' | chbits);
168 166
169 167 return (0);
170 168 }
171 169
172 170
173 171 int
174 172 setps()
175 173 {
176 174 int i, j;
177 175
178 176 i = cbits(getch());
179 177 if (ischar(i) && isdigit(i)) { /* \sd or \sdd */
180 178 i -= '0';
181 179 if (i == 0) /* \s0 */
182 180 ;
183 181 else if (i <= 3 && ischar(j = cbits(ch = getch())) &&
184 182 isdigit(j)) { /* \sdd */
185 183 ch = 0;
186 184 }
187 185 } else if (i == '(') { /* \s(dd */
188 186 getch();
189 187 getch();
190 188 } else if (i == '+' || i == '-') { /* \s+, \s- */
191 189 j = cbits(getch());
192 190 if (ischar(j) && isdigit(j)) { /* \s+d, \s-d */
193 191 ;
194 192 } else if (j == '(') { /* \s+(dd, \s-(dd */
195 193 getch();
196 194 getch();
197 195 }
198 196 }
199 197
200 198 return (0);
201 199 }
202 200
203 201
204 202 tchar setht() /* set character height from \H'...' */
205 203 {
206 204 int n;
207 205 tchar c;
208 206
209 207 getch();
210 208 n = inumb(&apts);
211 209 getch();
212 210 return(0);
213 211 }
214 212
215 213
216 214 tchar setslant() /* set slant from \S'...' */
217 215 {
218 216 int n;
219 217 tchar c;
220 218
221 219 getch();
222 220 n = 0;
223 221 n = inumb(&n);
224 222 getch();
225 223 return(0);
226 224 }
227 225
228 226
229 227 int
230 228 caseft()
231 229 {
232 230 skip();
233 231 setfont(1);
234 232
235 233 return (0);
236 234 }
↓ open down ↓ |
185 lines elided |
↑ open up ↑ |
237 235
238 236
239 237 int
240 238 setfont(a)
241 239 int a;
242 240 {
243 241 int i, j;
244 242
245 243 if (a)
246 244 i = getrq();
247 - else
245 + else
248 246 i = getsn();
249 247 if (!i || i == 'P') {
250 248 j = font1;
251 249 goto s0;
252 250 }
253 251 if (i == 'S' || i == '0')
254 252 return (0);
255 253 if ((j = findft(i, fontlab)) == -1)
256 254 return (0);
257 255 s0:
258 256 font1 = font;
259 257 font = j;
260 258 mchbits();
261 259
262 260 return (0);
263 261 }
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
264 262
265 263
266 264 int
267 265 setwd()
268 266 {
269 267 int base, wid;
270 268 tchar i;
271 269 int delim, emsz, k;
272 270 int savhp, savapts, savapts1, savfont, savfont1, savpts, savpts1;
273 271
274 - base = numtab[ST].val = numtab[ST].val = wid = numtab[CT].val = 0;
272 + base = numtab[ST].val = wid = numtab[CT].val = 0;
275 273 if (ismot(i = getch()))
276 274 return (0);
277 275 delim = cbits(i);
278 276 savhp = numtab[HP].val;
279 277 numtab[HP].val = 0;
280 278 savapts = apts;
281 279 savapts1 = apts1;
282 280 savfont = font;
283 281 savfont1 = font1;
284 282 savpts = pts;
285 283 savpts1 = pts1;
286 284 setwdf++;
287 285 while (cbits(i = getch()) != delim && !nlflg) {
288 286 k = width(i);
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
289 287 wid += k;
290 288 numtab[HP].val += k;
291 289 if (!ismot(i)) {
292 290 emsz = (INCH * pts + 36) / 72;
293 291 } else if (isvmot(i)) {
294 292 k = absmot(i);
295 293 if (isnmot(i))
296 294 k = -k;
297 295 base -= k;
298 296 emsz = 0;
299 - } else
297 + } else
300 298 continue;
301 299 if (base < numtab[SB].val)
302 300 numtab[SB].val = base;
303 301 if ((k = base + emsz) > numtab[ST].val)
304 302 numtab[ST].val = k;
305 303 }
306 304 setn1(wid, 0, (tchar) 0);
307 305 numtab[HP].val = savhp;
308 306 apts = savapts;
309 307 apts1 = savapts1;
310 308 font = savfont;
311 309 font1 = savfont1;
312 310 pts = savpts;
313 311 pts1 = savpts1;
314 312 mchbits();
315 313 setwdf = 0;
316 314
317 315 return (0);
318 316 }
319 317
320 318
321 319 tchar vmot()
322 320 {
323 321 dfact = lss;
324 322 vflag++;
325 323 return(mot());
326 324 }
327 325
328 326
329 327 tchar hmot()
330 328 {
331 329 dfact = EM;
332 330 return(mot());
333 331 }
334 332
335 333
336 334 tchar mot()
337 335 {
338 336 int j, n;
339 337 tchar i;
340 338
341 339 j = HOR;
342 340 getch(); /*eat delim*/
343 341 if (n = atoi()) {
344 342 if (vflag)
345 343 j = VERT;
346 344 i = makem(quant(n, j));
347 345 } else
348 346 i = 0;
349 347 getch();
350 348 vflag = 0;
351 349 dfact = 1;
352 350 return(i);
353 351 }
354 352
355 353
356 354 tchar sethl(k)
357 355 int k;
358 356 {
359 357 int j;
360 358 tchar i;
361 359
362 360 j = t.Halfline;
363 361 if (k == 'u')
364 362 j = -j;
365 363 else if (k == 'r')
366 364 j = -2 * j;
367 365 vflag++;
368 366 i = makem(j);
369 367 vflag = 0;
370 368 return(i);
371 369 }
372 370
373 371
374 372 tchar makem(i)
375 373 int i;
376 374 {
377 375 tchar j;
378 376
379 377 if ((j = i) < 0)
380 378 j = -j;
381 379 j |= MOT;
382 380 if (i < 0)
383 381 j |= NMOT;
384 382 if (vflag)
385 383 j |= VMOT;
386 384 return(j);
387 385 }
388 386
389 387
390 388 tchar getlg(i)
391 389 tchar i;
392 390 {
393 391 return(i);
394 392 }
395 393
396 394
397 395 int
398 396 caselg()
399 397 {
400 398 return (0);
401 399 }
402 400
403 401
404 402 int
405 403 casefp()
406 404 {
407 405 int i, j;
408 406
409 407 skip();
410 408 if ((i = cbits(getch()) - '0') < 0 || i > nfonts)
411 409 return (0);
412 410 if (skip() || !(j = getrq()))
413 411 return (0);
414 412 fontlab[i] = j;
415 413
416 414 return (0);
417 415 }
418 416
419 417
420 418 int
421 419 casecs()
422 420 {
423 421 return (0);
424 422 }
425 423
426 424
↓ open down ↓ |
117 lines elided |
↑ open up ↑ |
427 425 int
428 426 casebd()
429 427 {
430 428 int i, j, k;
431 429
432 430 k = 0;
433 431 bd0:
434 432 if (skip() || !(i = getrq()) || (j = findft(i)) == -1) {
435 433 if (k)
436 434 goto bd1;
437 - else
435 + else
438 436 return (0);
439 437 }
440 438 if (j == smnt) {
441 439 k = smnt;
442 440 goto bd0;
443 441 }
444 442 if (k) {
445 443 sbold = j;
446 444 j = k;
447 445 }
448 446 bd1:
449 447 skip();
450 448 noscale++;
451 449 bdtab[j] = atoi();
452 450 noscale = 0;
453 451
454 452 return (0);
455 453 }
456 454
457 455
458 456 int
459 457 casevs()
460 458 {
461 459 int i;
462 460
463 461 skip();
464 462 vflag++;
465 463 dfact = INCH; /*default scaling is points!*/
466 464 dfactd = 72;
467 465 res = VERT;
468 466 i = inumb(&lss);
469 467 if (nonumb)
470 468 i = lss1;
471 469 if (i < VERT)
472 470 i = VERT; /* was VERT */
473 471 lss1 = lss;
474 472 lss = i;
475 473
476 474 return (0);
477 475 }
478 476
479 477
480 478
481 479 int
482 480 casess()
483 481 {
484 482 return (0);
485 483 }
486 484
487 485
488 486 tchar xlss()
489 487 {
490 488 /* stores \x'...' into
491 489 * two successive tchars.
492 490 * the first contains HX, the second the value,
493 491 * encoded as a vertical motion.
494 492 * decoding is done in n2.c by pchar().
495 493 */
496 494 int i;
497 495
498 496 getch();
499 497 dfact = lss;
500 498 i = quant(atoi(), VERT);
501 499 dfact = 1;
502 500 getch();
503 501 if (i >= 0)
504 502 *pbp++ = MOT | VMOT | i;
505 503 else
506 504 *pbp++ = MOT | VMOT | NMOT | -i;
507 505 return(HX);
508 506 }
↓ open down ↓ |
61 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX