Print this page
10120 smatch indenting fixes for usr/src/cmd
Reviewed by: Gergő Doma <domag02@gmail.com>
Portions contributed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/infocmp/infocmp.c
+++ new/usr/src/cmd/infocmp/infocmp.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]
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /* Copyright (c) 1988 AT&T */
23 23 /* All Rights Reserved */
24 24
25 25
26 26 /*
27 27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 28 * Use is subject to license terms.
29 + *
30 + * Copyright (c) 2019, Joyent, Inc.
29 31 */
30 32
31 -#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.13 */
32 -
33 33 /*
34 34 NAME
35 35 infocmp - compare terminfo descriptions, or dump a terminfo
36 36 description
37 37
38 38 AUTHOR
39 39 Tony Hansen, February 23, 1984.
40 40 */
41 41
42 42 #include "curses.h"
43 43 #include "term.h"
44 44 #include "print.h"
45 45 #include <fcntl.h>
46 46 #include <stdlib.h>
47 47
48 48 /* externs from libcurses */
49 49 extern char *boolnames[];
50 50 extern char *boolcodes[];
51 51 extern char *boolfnames[];
52 52 extern char *numnames[];
53 53 extern char *numcodes[];
54 54 extern char *numfnames[];
55 55 extern char *strnames[];
56 56 extern char *strcodes[];
57 57 extern char *strfnames[];
58 58 extern char ttytype[];
59 59 extern int tgetflag();
60 60 extern int tgetnum();
61 61 extern char *tgetstr();
62 62
63 63 /* externs from libc */
64 64 extern void exit();
65 65 extern void qsort();
66 66 extern char *getenv();
67 67 extern int getopt();
68 68 extern int optind;
69 69 extern char *optarg;
70 70 extern char *strncpy(), *strcpy();
71 71 extern int strcmp(), strlen();
72 72
73 73 /* data structures for this program */
74 74
75 75 struct boolstruct {
76 76 char *infoname; /* the terminfo capability name */
77 77 char *capname; /* the termcap capability name */
78 78 char *fullname; /* the long C variable name */
79 79 char *secondname; /* the use= terminal w/ this value */
80 80 char val; /* the value */
81 81 char secondval; /* the value in the use= terminal */
82 82 char changed; /* a use= terminal changed the value */
83 83 char seenagain; /* a use= terminal had this entry */
84 84 };
85 85
86 86 struct numstruct {
87 87 char *infoname; /* ditto from above */
88 88 char *capname;
89 89 char *fullname;
90 90 char *secondname;
91 91 short val;
92 92 short secondval;
93 93 char changed;
94 94 char seenagain;
95 95 };
96 96
97 97 struct strstruct {
98 98 char *infoname; /* ditto from above */
99 99 char *capname;
100 100 char *fullname;
101 101 char *secondname;
102 102 char *val;
103 103 char *secondval;
104 104 char changed;
105 105 char seenagain;
106 106 };
107 107
108 108 /* globals for this file */
109 109 char *progname; /* argv[0], the name of the program */
110 110 static struct boolstruct *ibool; /* array of char information */
111 111 static struct numstruct *num; /* array of number information */
112 112 static struct strstruct *str; /* array of string information */
113 113 static char *used; /* usage statistics */
114 114 static int numbools; /* how many booleans there are */
115 115 static int numnums; /* how many numbers there are */
116 116 static int numstrs; /* how many strings there are */
117 117 #define TTYLEN 255
118 118 static char *firstterm; /* the name of the first terminal */
119 119 static char *savettytype; /* the synonyms of the first terminal */
120 120 static char _savettytype[TTYLEN+1]; /* the place to save those names */
121 121 static int devnull; /* open("/dev/null") for setupterm */
122 122 #define trace stderr /* send trace messages to stderr */
123 123
124 124 /* options */
125 125 static int verbose = 0; /* debugging printing level */
126 126 static int diff = 0; /* produce diff listing, the default */
127 127 static int common = 0; /* produce common listing */
128 128 static int neither = 0; /* list caps in neither entry */
129 129 static int use = 0; /* produce use= comparison listing */
130 130 static enum printtypes printing /* doing any of above printing at all */
131 131 = pr_none;
132 132 enum { none, by_database, by_terminfo, by_longnames, by_cap }
133 133 sortorder = none; /* sort the fields for printing */
134 134 static char *term1info, *term2info; /* $TERMINFO settings */
135 135 static int Aflag = 0, Bflag = 0; /* $TERMINFO was set with -A/-B */
136 136
137 137 #define EQUAL(s1, s2) (((s1 == NULL) && (s2 == NULL)) || \
138 138 ((s1 != NULL) && (s2 != NULL) && \
139 139 (strcmp(s1, s2) == 0)))
140 140
141 141 static void sortnames();
142 142 int numcompare(const void *, const void *);
143 143 int boolcompare(const void *, const void *);
144 144 int strcompare(const void *, const void *);
145 145 static void check_nth_terminal(char *, int);
146 146
147 147 void
148 148 badmalloc()
149 149 {
150 150 (void) fprintf(stderr, "%s: malloc is out of space!\n", progname);
151 151 exit(-1);
152 152 }
153 153
154 154 /*
155 155 Allocate and initialize the global data structures and variables.
156 156 */
157 157 void
158 158 allocvariables(int argc, int firstoptind)
159 159 {
160 160 register int i, nullseen;
161 161
162 162 /* find out how many names we are dealing with */
163 163 for (numbools = 0; boolnames[numbools]; numbools++)
164 164 ;
165 165 for (numnums = 0; numnames[numnums]; numnums++)
166 166 ;
167 167 for (numstrs = 0; strnames[numstrs]; numstrs++)
168 168 ;
169 169
170 170 if (verbose) {
171 171 (void) fprintf(trace, "There are %d boolean capabilities.\n",
172 172 numbools);
173 173 (void) fprintf(trace, "There are %d numeric capabilities.\n",
174 174 numnums);
175 175 (void) fprintf(trace, "There are %d string capabilities.\n",
176 176 numstrs);
177 177 }
↓ open down ↓ |
135 lines elided |
↑ open up ↑ |
178 178
179 179 /* Allocate storage for the names and their values */
180 180 ibool = (struct boolstruct *) malloc((unsigned) numbools *
181 181 sizeof (struct boolstruct));
182 182 num = (struct numstruct *) malloc((unsigned) numnums *
183 183 sizeof (struct numstruct));
184 184 str = (struct strstruct *) malloc((unsigned) numstrs *
185 185 sizeof (struct strstruct));
186 186
187 187 /* Allocate array to keep track of which names have been used. */
188 - if (use)
188 + if (use) {
189 189 used = (char *) malloc((unsigned) (argc - firstoptind) *
190 190 sizeof (char));
191 + }
191 192
192 193 if ((ibool == NULL) || (num == NULL) || (str == NULL) ||
193 194 (use && (used == NULL)))
194 195 badmalloc();
195 196
196 197 /* Fill in the names and initialize the structures. */
197 198 nullseen = FALSE;
198 199 for (i = 0; i < numbools; i++) {
199 200 ibool[i].infoname = boolnames[i];
200 201 ibool[i].capname = boolcodes[i];
201 202 /* This is necessary until fnames.c is */
202 203 /* incorporated into standard curses. */
203 204 if (nullseen || (boolfnames[i] == NULL)) {
204 205 ibool[i].fullname = "unknown_boolean";
205 206 nullseen = TRUE;
206 - } else
207 + } else {
207 208 ibool[i].fullname = boolfnames[i];
209 + }
208 210 ibool[i].changed = FALSE;
209 211 ibool[i].seenagain = FALSE;
210 212 }
211 213 nullseen = 0;
212 214 for (i = 0; i < numnums; i++) {
213 215 num[i].infoname = numnames[i];
214 216 num[i].capname = numcodes[i];
215 217 if (nullseen || (numfnames[i] == NULL)) {
216 218 ibool[i].fullname = "unknown_number";
217 219 nullseen = TRUE;
218 - } else
220 + } else {
219 221 num[i].fullname = numfnames[i];
222 + }
220 223 num[i].changed = FALSE;
221 224 num[i].seenagain = FALSE;
222 225 }
223 226 nullseen = 0;
224 227 for (i = 0; i < numstrs; i++) {
225 228 str[i].infoname = strnames[i];
226 229 str[i].capname = strcodes[i];
227 230 if (nullseen || (strfnames[i] == NULL)) {
228 231 str[i].fullname = "unknown_string";
229 232 nullseen = TRUE;
230 - } else
233 + } else {
231 234 str[i].fullname = strfnames[i];
235 + }
232 236 str[i].changed = FALSE;
233 237 str[i].seenagain = FALSE;
234 238 }
235 239 }
236 240
237 241 /*
238 242 Routines to be passed to qsort(3) for comparison of the structures.
239 243 */
240 244 int
241 245 boolcompare(const void *x, const void *y)
242 246 {
243 247 struct boolstruct *a;
244 248 struct boolstruct *b;
245 249
246 250 a = (struct boolstruct *)x;
247 251 b = (struct boolstruct *)y;
248 252
249 253 switch ((int) sortorder) {
250 254 case (int) by_terminfo:
251 255 return (strcmp(a->infoname, b->infoname));
252 256 case (int) by_cap:
253 257 return (strcmp(a->capname, b->capname));
254 258 case (int) by_longnames:
255 259 return (strcmp(a->fullname, b->fullname));
256 260 default:
257 261 return (0);
258 262 }
259 263 }
260 264
261 265 int
262 266 numcompare(const void *x, const void *y)
263 267 {
264 268 struct numstruct *a;
265 269 struct numstruct *b;
266 270
267 271 a = (struct numstruct *)x;
268 272 b = (struct numstruct *)y;
269 273 switch ((int) sortorder) {
270 274 case (int) by_terminfo:
271 275 return (strcmp(a->infoname, b->infoname));
272 276 case (int) by_cap:
273 277 return (strcmp(a->capname, b->capname));
274 278 case (int) by_longnames:
275 279 return (strcmp(a->fullname, b->fullname));
276 280 default:
277 281 return (0);
278 282 }
279 283 }
280 284
281 285 int
282 286 strcompare(const void *x, const void *y)
283 287 {
284 288 struct strstruct *a;
285 289 struct strstruct *b;
286 290
287 291 a = (struct strstruct *)x;
288 292 b = (struct strstruct *)y;
289 293
290 294 switch ((int) sortorder) {
291 295 case (int) by_terminfo:
292 296 return (strcmp(a->infoname, b->infoname));
293 297 case (int) by_cap:
294 298 return (strcmp(a->capname, b->capname));
295 299 case (int) by_longnames:
296 300 return (strcmp(a->fullname, b->fullname));
297 301 default:
298 302 return (0);
299 303 }
300 304 }
301 305
302 306 /*
303 307 Sort the entries by their terminfo name.
304 308 */
305 309 static void
306 310 sortnames()
307 311 {
308 312 if (sortorder != by_database) {
309 313 qsort((char *) ibool, (unsigned) numbools,
310 314 sizeof (struct boolstruct), boolcompare);
311 315 qsort((char *) num, (unsigned) numnums,
312 316 sizeof (struct numstruct), numcompare);
313 317 qsort((char *) str, (unsigned) numstrs,
314 318 sizeof (struct strstruct), strcompare);
315 319 }
316 320 return;
317 321 }
318 322
319 323 /*
320 324 Print out a string, or "NULL" if it's not defined.
321 325 */
322 326 void
323 327 PR(FILE *stream, char *string)
324 328 {
325 329 if (string == NULL)
326 330 (void) fprintf(stream, "NULL");
327 331 else
328 332 tpr(stream, string);
329 333 }
330 334
331 335 /*
332 336 Output the 'ko' termcap string. This is a list of all of the input
333 337 keys that input the same thing as the corresponding output strings.
334 338 */
335 339 int kncounter;
336 340 char kobuffer[512];
337 341
338 342 char
339 343 *addko(char *output, char *input, char *koptr)
340 344 {
341 345 char *inptr, *outptr, padbuffer[512];
342 346 inptr = tgetstr(input, (char **)0);
343 347 if (inptr == NULL)
344 348 return (koptr);
345 349 outptr = tgetstr(output, (char **)0);
346 350 if (outptr == NULL)
347 351 return (koptr);
348 352 outptr = rmpadding(outptr, padbuffer, (int *) 0);
349 353 if (strcmp(inptr, outptr) == 0) {
350 354 *koptr++ = *output++;
351 355 *koptr++ = *output++;
352 356 *koptr++ = ',';
353 357 kncounter++;
354 358 }
355 359 return (koptr);
356 360 }
357 361
358 362 void
359 363 setupknko()
360 364 {
361 365 char *koptr;
362 366
363 367 kncounter = 0;
364 368 koptr = kobuffer;
365 369
366 370 koptr = addko("bs", "kb", koptr); /* key_backspace */
367 371 koptr = addko("bt", "kB", koptr); /* key_btab */
368 372 koptr = addko("cl", "kC", koptr); /* key_clear */
369 373 koptr = addko("le", "kl", koptr); /* key_left */
370 374 koptr = addko("do", "kd", koptr); /* key_down */
371 375 koptr = addko("nd", "kr", koptr); /* key_right */
372 376 koptr = addko("up", "ku", koptr); /* key_up */
373 377 koptr = addko("dc", "kD", koptr); /* key_dc */
374 378 koptr = addko("dl", "kL", koptr); /* key_dl */
375 379 koptr = addko("cd", "kS", koptr); /* key_eos */
376 380 koptr = addko("ce", "kE", koptr); /* key_eol */
377 381 koptr = addko("ho", "kh", koptr); /* key_home */
378 382 koptr = addko("st", "kT", koptr); /* key_stab */
379 383 koptr = addko("ic", "kI", koptr); /* key_ic */
380 384 koptr = addko("im", "kI", koptr); /* key_ic */
381 385 koptr = addko("al", "kA", koptr); /* key_il */
382 386 koptr = addko("sf", "kF", koptr); /* key_sf */
383 387 koptr = addko("ll", "kH", koptr); /* key_ll */
384 388 koptr = addko("sr", "kR", koptr); /* key_sr */
385 389 koptr = addko("ei", "kM", koptr); /* key_eic */
386 390 koptr = addko("ct", "ka", koptr); /* key_catab */
387 391
388 392 /* get rid of comma */
389 393 if (koptr != kobuffer)
390 394 *(--koptr) = '\0';
391 395 }
392 396
393 397 void
394 398 pr_kn()
395 399 {
396 400 if (kncounter > 0)
397 401 pr_number((char *)0, "kn", (char *)0, kncounter);
398 402 }
399 403
400 404 void
401 405 pr_ko()
402 406 {
403 407 if (kncounter > 0)
404 408 pr_string((char *)0, "ko", (char *)0, kobuffer);
405 409 }
406 410
407 411 void
408 412 pr_bcaps()
409 413 {
410 414 char *retptr;
411 415 char padbuffer[512];
412 416
413 417 if (verbose)
414 418 (void) fprintf(trace, "looking at 'bs'\n");
415 419 retptr = cconvert(rmpadding(cursor_left, padbuffer, (int *) 0));
416 420 if (strcmp("\\b", retptr) == 0)
417 421 pr_boolean((char *)0, "bs", (char *)0, 1);
418 422
419 423 if (verbose)
420 424 (void) fprintf(trace, "looking at 'pt'\n");
421 425 retptr = cconvert(rmpadding(tab, padbuffer, (int *) 0));
422 426 if (strcmp("\\t", retptr) == 0)
423 427 pr_boolean((char *)0, "pt", (char *)0, 1);
424 428
425 429 if (verbose)
426 430 (void) fprintf(trace, "looking at 'nc'\n");
427 431 retptr = cconvert(rmpadding(carriage_return, padbuffer, (int *) 0));
428 432 if (strcmp("\\r", retptr) != 0)
429 433 pr_boolean((char *)0, "nc", (char *)0, 1);
430 434
431 435 if (verbose)
432 436 (void) fprintf(trace, "looking at 'ns'\n");
433 437 if (scroll_forward == NULL)
434 438 pr_boolean((char *)0, "ns", (char *)0, 1);
435 439
436 440 /* Ignore "xr": Return acts like ce \r \n (Delta Data) */
437 441 }
438 442
439 443 void
440 444 pr_ncaps()
441 445 {
442 446 char padbuffer[512];
443 447 int padding;
444 448
445 449 if (verbose)
446 450 (void) fprintf(trace, "looking at 'ug'\n");
447 451 /* Duplicate sg for ug: Number of blank chars left by us or ue */
448 452 if (magic_cookie_glitch > -1)
449 453 pr_number((char *)0, "ug", (char *)0, magic_cookie_glitch);
450 454
451 455 if (verbose)
452 456 (void) fprintf(trace, "looking at 'dB'\n");
453 457 /* Number of millisec of bs delay needed */
454 458 (void) rmpadding(cursor_left, padbuffer, &padding);
455 459 if (padding > 0)
456 460 pr_number((char *)0, "dB", (char *)0, padding);
457 461
458 462 if (verbose)
459 463 (void) fprintf(trace, "looking at 'dC'\n");
460 464 /* Number of millisec of cr delay needed */
461 465 (void) rmpadding(carriage_return, padbuffer, &padding);
462 466 if (padding > 0)
463 467 pr_number((char *)0, "dC", (char *)0, padding);
464 468
465 469 if (verbose)
466 470 (void) fprintf(trace, "looking at 'dF'\n");
467 471 /* Number of millisec of ff delay needed */
468 472 (void) rmpadding(form_feed, padbuffer, &padding);
469 473 if (padding > 0)
470 474 pr_number((char *)0, "dF", (char *)0, padding);
471 475
472 476 if (verbose)
473 477 (void) fprintf(trace, "looking at 'dN'\n");
474 478 /* Number of millisec of nl delay needed */
475 479 (void) rmpadding(cursor_down, padbuffer, &padding);
476 480 if (padding > 0)
477 481 pr_number((char *)0, "dN", (char *)0, padding);
478 482
479 483 if (verbose)
480 484 (void) fprintf(trace, "looking at 'dT'\n");
481 485 /* Number of millisec of tab delay needed */
482 486 (void) rmpadding(tab, padbuffer, &padding);
483 487 if (padding > 0)
484 488 pr_number((char *)0, "dT", (char *)0, padding);
485 489
486 490 /* Handle "kn": Number of "other" keys */
487 491 setupknko();
488 492 pr_kn();
489 493 }
490 494
491 495 void
492 496 pr_scaps()
493 497 {
494 498 char *retptr;
495 499 char padbuffer[512];
496 500
497 501 /* Backspace if not "^H" */
498 502 if (verbose)
499 503 (void) fprintf(trace, "looking at 'bc'\n");
500 504 retptr = cconvert(rmpadding(cursor_left, padbuffer, (int *) 0));
501 505 if (strcmp("\\b", retptr) != 0)
502 506 pr_string((char *)0, "bc", (char *)0, cursor_left);
503 507
504 508 /* Newline character (default "\n") */
505 509 if (verbose)
506 510 (void) fprintf(trace, "looking at 'nl'\n");
507 511 retptr = cconvert(rmpadding(cursor_down, padbuffer, (int *) 0));
508 512 if (strcmp("\\n", retptr) != 0)
509 513 pr_string((char *)0, "nl", (char *)0, cursor_down);
510 514
511 515 /* Handle "ko" here: Termcap entries for other non-function keys */
512 516 pr_ko();
513 517
514 518 /* Ignore "ma": Arrow key map, used by vi version 2 only */
↓ open down ↓ |
273 lines elided |
↑ open up ↑ |
515 519 }
516 520
517 521 /*
518 522 Set up the first terminal and save the values from it.
519 523 */
520 524 void
521 525 initfirstterm(char *term)
522 526 {
523 527 register int i;
524 528
525 - if (verbose)
529 + if (verbose) {
526 530 (void) fprintf(trace, "setting up terminal type '%s'.\n",
527 531 term);
532 + }
528 533
529 534 (void) setupterm(term, devnull, (int *) 0);
530 535
531 536 /* Save the name for later use. */
532 537 if (use) {
533 538 register unsigned int length;
534 539 savettytype = _savettytype;
535 540 if ((length = strlen(ttytype)) >= TTYLEN) {
536 541 savettytype = malloc(length);
537 542 if (savettytype == NULL) {
538 543 (void) fprintf(stderr, "%s: malloc is out "
539 544 "of space\n", progname);
540 545 (void) strncpy(_savettytype, ttytype,
541 546 TTYLEN-1);
542 547 _savettytype[TTYLEN] = '\0';
543 548 savettytype = _savettytype;
544 549 }
545 - } else
550 + } else {
546 551 (void) strcpy(_savettytype, ttytype);
552 + }
547 553 }
548 554
549 555 if (printing != pr_none) {
550 556 pr_heading(term, ttytype);
551 557 pr_bheading();
552 558 }
553 559
554 560 /* Save the values for the first terminal. */
555 561 for (i = 0; i < numbools; i++) {
556 562 if ((ibool[i].val = tgetflag(ibool[i].capname)) &&
557 - printing != pr_none)
563 + printing != pr_none) {
558 564 pr_boolean(ibool[i].infoname, ibool[i].capname,
559 565 ibool[i].fullname, 1);
560 - if (verbose)
566 + }
567 +
568 + if (verbose) {
561 569 (void) fprintf(trace, "%s=%d.\n", ibool[i].infoname,
562 570 ibool[i].val);
571 + }
563 572 }
564 573
565 574 if (printing != pr_none) {
566 575 if (printing == pr_cap)
567 576 pr_bcaps();
568 577 pr_bfooting();
569 578 pr_nheading();
570 579 }
571 580
572 581 for (i = 0; i < numnums; i++) {
573 582 if (((num[i].val = tgetnum(num[i].capname)) > -1) &&
574 - printing != pr_none)
583 + printing != pr_none) {
575 584 pr_number(num[i].infoname, num[i].capname,
576 585 num[i].fullname, num[i].val);
577 - if (verbose)
586 + }
587 +
588 + if (verbose) {
578 589 (void) fprintf(trace, "%s=%d.\n", num[i].infoname,
579 590 num[i].val);
591 + }
580 592 }
581 593
582 594 if (printing != pr_none) {
583 595 if (printing == pr_cap)
584 596 pr_ncaps();
585 597 pr_nfooting();
586 598 pr_sheading();
587 599 }
588 600
589 601 for (i = 0; i < numstrs; i++) {
590 602 str[i].val = tgetstr(str[i].capname, (char **)0);
591 - if ((str[i].val != NULL) && printing != pr_none)
603 + if ((str[i].val != NULL) && printing != pr_none) {
592 604 pr_string(str[i].infoname, str[i].capname,
593 605 str[i].fullname, str[i].val);
606 + }
607 +
594 608 if (verbose) {
595 609 (void) fprintf(trace, "%s='", str[i].infoname);
596 610 PR(trace, str[i].val);
597 611 (void) fprintf(trace, "'.\n");
598 612 }
599 613 }
600 614
601 615 if (printing == pr_cap)
602 616 pr_scaps();
603 617
604 618 if (printing != pr_none)
605 619 pr_sfooting();
606 620 }
607 621
608 622 /*
609 623 Set up the n'th terminal.
610 624 */
611 625 static void
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
612 626 check_nth_terminal(char *nterm, int n)
613 627 {
614 628 register char boolval;
615 629 register short numval;
616 630 register char *strval;
617 631 register int i;
618 632
619 633 if (use)
620 634 used[n] = FALSE;
621 635
622 - if (verbose)
636 + if (verbose) {
623 637 (void) fprintf(trace, "adding in terminal type '%s'.\n",
624 638 nterm);
639 + }
625 640
626 641 (void) setupterm(nterm, devnull, (int *) 0);
627 642
628 643 if (printing != pr_none) {
629 644 pr_heading(nterm, ttytype);
630 645 pr_bheading();
631 646 }
632 647
633 648 if (diff || common || neither) {
634 649 if (Aflag && Bflag)
635 650 (void) printf("comparing %s (TERMINFO=%s) to %s "
636 651 "(TERMINFO=%s).\n",
637 652 firstterm, term1info, nterm, term2info);
638 653 else if (Aflag)
639 654 (void) printf("comparing %s (TERMINFO=%s) to %s.\n",
640 655 firstterm, term1info, nterm);
641 656 else if (Bflag)
642 657 (void) printf("comparing %s to %s (TERMINFO=%s).\n",
643 658 firstterm, nterm, term2info);
644 659 else
645 660 (void) printf("comparing %s to %s.\n",
646 661 firstterm, nterm);
647 662 (void) printf(" comparing booleans.\n");
648 663 }
649 664
650 665 /* save away the values for the nth terminal */
651 666 for (i = 0; i < numbools; i++) {
652 667 boolval = tgetflag(ibool[i].capname);
653 668 if (use) {
654 669 if (ibool[i].seenagain) {
655 670 /*
656 671 ** We do not have to worry about this impossible case
657 672 ** since booleans can have only two values: true and
658 673 ** false.
659 674 ** if (boolval && (boolval != ibool[i].secondval))
660 675 ** {
661 676 ** (void) fprintf(trace, "use= order dependency"
662 677 ** "found:\n");
663 678 ** (void) fprintf(trace, " %s: %s has %d, %s has"
664 679 ** " %d.\n",
665 680 ** ibool[i].capname, ibool[i].secondname,
666 681 ** ibool[i].secondval, nterm, boolval);
667 682 ** }
668 683 */
669 684 } else {
670 685 if (boolval == TRUE) {
671 686 ibool[i].seenagain = TRUE;
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
672 687 ibool[i].secondval = boolval;
673 688 ibool[i].secondname = nterm;
674 689 if (ibool[i].val != boolval)
675 690 ibool[i].changed = TRUE;
676 691 else
677 692 used[n] = TRUE;
678 693 }
679 694 }
680 695 }
681 696 if (boolval) {
682 - if (printing != pr_none)
697 + if (printing != pr_none) {
683 698 pr_boolean(ibool[i].infoname, ibool[i].capname,
684 699 ibool[i].fullname, 1);
700 + }
701 +
685 702 if (common && (ibool[i].val == boolval))
686 703 (void) printf("\t%s= T.\n", ibool[i].infoname);
687 - } else if (neither && !ibool[i].val)
704 + } else if (neither && !ibool[i].val) {
688 705 (void) printf("\t!%s.\n", ibool[i].infoname);
706 + }
689 707 if (diff && (ibool[i].val != boolval))
690 708 (void) printf("\t%s: %c:%c.\n", ibool[i].infoname,
691 709 ibool[i].val?'T':'F', boolval?'T':'F');
692 - if (verbose)
710 + if (verbose) {
693 711 (void) fprintf(trace, "%s: %d:%d, changed=%d, "
694 712 "seen=%d.\n", ibool[i].infoname, ibool[i].val,
695 713 boolval, ibool[i].changed, ibool[i].seenagain);
714 + }
696 715 }
697 716
698 717 if (printing != pr_none) {
699 718 if (printing == pr_cap)
700 719 pr_bcaps();
701 720 pr_bfooting();
702 721 pr_nheading();
703 722 }
704 723
705 724 if (diff || common || neither)
706 725 (void) printf(" comparing numbers.\n");
707 726
708 727 for (i = 0; i < numnums; i++) {
709 728 numval = tgetnum(num[i].capname);
710 729 if (use) {
711 730 if (num[i].seenagain) {
712 731 if ((numval > -1) &&
713 732 (numval != num[i].secondval)) {
714 733 (void) fprintf(stderr,
715 734 "%s: use = order dependency "
716 735 "found:\n", progname);
717 736 (void) fprintf(stderr, " %s: %s "
718 737 "has %d, %s has %d.\n",
719 738 num[i].capname, num[i].secondname,
720 739 num[i].secondval, nterm, numval);
721 740 }
722 741 } else {
723 742 if (numval > -1) {
724 743 num[i].seenagain = TRUE;
725 744 num[i].secondval = numval;
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
726 745 num[i].secondname = nterm;
727 746 if ((numval > -1) &&
728 747 (num[i].val != numval))
729 748 num[i].changed = TRUE;
730 749 else
731 750 used[n] = TRUE;
732 751 }
733 752 }
734 753 }
735 754 if (numval > -1) {
736 - if (printing != pr_none)
755 + if (printing != pr_none) {
737 756 pr_number(num[i].infoname, num[i].capname,
738 757 num[i].fullname, numval);
739 - if (common && (num[i].val == numval))
758 + }
759 +
760 + if (common && (num[i].val == numval)) {
740 761 (void) printf("\t%s= %d.\n", num[i].infoname,
741 762 numval);
742 - } else if (neither && (num[i].val == -1))
743 - (void) printf("\t!%s.\n", num[i].infoname);
744 - if (diff && (num[i].val != numval))
745 - (void) printf("\t%s: %d:%d.\n",
746 - num[i].infoname, num[i].val, numval);
747 - if (verbose)
748 - (void) fprintf(trace, "%s: %d:%d, "
749 - "changed = %d, seen = %d.\n",
750 - num[i].infoname, num[i].val, numval,
751 - num[i].changed, num[i].seenagain);
763 + }
764 +
765 + } else if (neither && (num[i].val == -1)) {
766 + (void) printf("\t!%s.\n", num[i].infoname);
767 + }
768 +
769 + if (diff && (num[i].val != numval)) {
770 + (void) printf("\t%s: %d:%d.\n",
771 + num[i].infoname, num[i].val, numval);
772 + }
773 +
774 + if (verbose) {
775 + (void) fprintf(trace, "%s: %d:%d, "
776 + "changed = %d, seen = %d.\n",
777 + num[i].infoname, num[i].val, numval,
778 + num[i].changed, num[i].seenagain);
779 + }
752 780 }
753 781
754 782 if (printing != pr_none) {
755 783 if (printing == pr_cap)
756 784 pr_ncaps();
757 785 pr_nfooting();
758 786 pr_sheading();
759 787 }
760 788
761 789 if (diff || common || neither)
762 790 (void) printf(" comparing strings.\n");
763 791
764 792 for (i = 0; i < numstrs; i++) {
765 793 strval = tgetstr(str[i].capname, (char **)0);
766 794 if (use) {
767 795 if (str[i].seenagain && (strval != NULL)) {
768 796 if (!EQUAL(strval, str[i].secondval)) {
769 797 (void) fprintf(stderr,
770 798 "use= order dependency"
771 799 " found:\n");
772 800 (void) fprintf(stderr,
773 801 " %s: %s has '",
774 802 str[i].capname, str[i].secondname);
775 803 PR(stderr, str[i].secondval);
776 804 (void) fprintf(stderr,
777 805 "', %s has '", nterm);
778 806 PR(stderr, strval);
779 807 (void) fprintf(stderr, "'.\n");
780 808 }
781 809 } else {
782 810 if (strval != NULL) {
783 811 str[i].seenagain = TRUE;
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
784 812 str[i].secondval = strval;
785 813 str[i].secondname = nterm;
786 814 if (!EQUAL(str[i].val, strval))
787 815 str[i].changed = TRUE;
788 816 else
789 817 used[n] = TRUE;
790 818 }
791 819 }
792 820 }
793 821 if (strval != NULL) {
794 - if (printing != pr_none)
822 + if (printing != pr_none) {
795 823 pr_string(str[i].infoname, str[i].capname,
796 824 str[i].fullname, strval);
825 + }
826 +
797 827 if (common && EQUAL(str[i].val, strval)) {
798 828 (void) printf("\t%s= '", str[i].infoname);
799 829 PR(stdout, strval);
800 830 (void) printf("'.\n");
801 831 }
802 832 } else if (neither && (str[i].val == NULL))
803 833 (void) printf("\t!%s.\n", str[i].infoname);
804 834 if (diff && !EQUAL(str[i].val, strval)) {
805 835 (void) printf("\t%s: '", str[i].infoname);
806 836 PR(stdout, str[i].val);
807 837 (void) printf("','");
808 838 PR(stdout, strval);
809 839 (void) printf("'.\n");
810 840 }
811 841 if (verbose) {
812 842 (void) fprintf(trace, "%s: '", str[i].infoname);
813 843 PR(trace, str[i].val);
814 844 (void) fprintf(trace, "':'");
815 845 PR(trace, strval);
816 846 (void) fprintf(trace, "',changed=%d,seen=%d.\n",
817 847 str[i].changed, str[i].seenagain);
818 848 }
819 849 }
820 850
821 851 if (printing == pr_cap)
822 852 pr_scaps();
823 853
824 854 if (printing != pr_none)
825 855 pr_sfooting();
826 856
827 857 return;
828 858 }
829 859
830 860 /*
831 861 A capability gets an at-sign if it no longer exists, but
832 862 one of the relative entries contains a value for it.
833 863 It gets printed if the original value is not seen in ANY
834 864 of the relative entries, or if the FIRST relative entry that has
835 865 the capability gives a DIFFERENT value for the capability.
836 866 */
837 867 void
838 868 dorelative(int firstoptind, int argc, char **argv)
839 869 {
840 870 register int i;
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
841 871
842 872 /* turn off printing of termcap and long names */
843 873 pr_init(pr_terminfo);
844 874
845 875 /* print out the entry name */
846 876 pr_heading((char *)0, savettytype);
847 877
848 878 pr_bheading();
849 879
850 880 /* Print out all bools that are different. */
851 - for (i = 0; i < numbools; i++)
852 - if (!ibool[i].val && ibool[i].changed)
881 + for (i = 0; i < numbools; i++) {
882 + if (!ibool[i].val && ibool[i].changed) {
853 883 pr_boolean(ibool[i].infoname, (char *)0,
854 884 (char *)0, -1);
855 - else if (ibool[i].val && (ibool[i].changed ||
856 - !ibool[i].seenagain))
885 + } else if (ibool[i].val && (ibool[i].changed ||
886 + !ibool[i].seenagain)) {
857 887 pr_boolean(ibool[i].infoname, (char *)0, (char *)0, 1);
888 + }
889 + }
858 890
859 891 pr_bfooting();
860 892 pr_nheading();
861 893
862 894 /* Print out all nums that are different. */
863 - for (i = 0; i < numnums; i++)
864 - if (num[i].val < 0 && num[i].changed)
895 + for (i = 0; i < numnums; i++) {
896 + if (num[i].val < 0 && num[i].changed) {
865 897 pr_number(num[i].infoname, (char *)0, (char *)0, -1);
866 - else if (num[i].val >= 0 && (num[i].changed ||
867 - !num[i].seenagain))
898 + } else if (num[i].val >= 0 && (num[i].changed ||
899 + !num[i].seenagain)) {
868 900 pr_number(num[i].infoname, (char *)0,
869 901 (char *)0, num[i].val);
902 + }
903 + }
870 904
871 905 pr_nfooting();
872 906 pr_sheading();
873 907
874 908 /* Print out all strs that are different. */
875 - for (i = 0; i < numstrs; i++)
876 - if (str[i].val == NULL && str[i].changed)
909 + for (i = 0; i < numstrs; i++) {
910 + if (str[i].val == NULL && str[i].changed) {
877 911 pr_string(str[i].infoname, (char *)0, (char *)0,
878 912 (char *)0);
879 - else if ((str[i].val != NULL) &&
880 - (str[i].changed || !str[i].seenagain))
881 - pr_string(str[i].infoname, (char *)0, (char *)0, str[i].val);
913 + } else if ((str[i].val != NULL) &&
914 + (str[i].changed || !str[i].seenagain)) {
915 + pr_string(str[i].infoname,
916 + (char *)0, (char *)0, str[i].val);
917 + }
918 + }
882 919
883 920 pr_sfooting();
884 921
885 922 /* Finish it up. */
886 - for (i = firstoptind; i < argc; i++)
887 - if (used[i - firstoptind])
923 + for (i = firstoptind; i < argc; i++) {
924 + if (used[i - firstoptind]) {
888 925 (void) printf("\tuse=%s,\n", argv[i]);
889 - else
926 + } else {
890 927 (void) fprintf(stderr,
891 928 "%s: 'use=%s' did not add anything to the "
892 929 "description.\n", progname, argv[i]);
930 + }
931 + }
893 932 }
894 933
895 934 void
896 935 local_setenv(char *termNinfo)
897 936 {
898 937 extern char **environ;
899 938 static char *newenviron[2] = { 0, 0 };
900 939 static unsigned int termsize = BUFSIZ;
901 940 static char _terminfo[BUFSIZ];
902 941 static char *terminfo = &_terminfo[0];
903 942 register int termlen;
904 943
905 944 if (termNinfo && *termNinfo) {
906 - if (verbose)
945 + if (verbose) {
907 946 (void) fprintf(trace, "setting TERMINFO=%s.\n",
908 947 termNinfo);
948 + }
949 +
909 950 termlen = strlen(termNinfo);
910 951 if (termlen + 10 > termsize) {
911 952 termsize = termlen + 20;
912 953 terminfo = (char *) malloc(termsize * sizeof (char));
913 954 }
914 955 if (terminfo == (char *) NULL)
915 956 badmalloc();
916 957 (void) sprintf(terminfo, "TERMINFO=%s", termNinfo);
917 958 newenviron[0] = terminfo;
918 959 } else
919 960 newenviron[0] = (char *) 0;
920 961 environ = newenviron;
921 962 }
922 963
923 964 int
924 965 main(int argc, char **argv)
925 966 {
926 967 int i, c, firstoptind;
927 968 char *tempargv[2];
928 969 char *term = getenv("TERM");
929 970
930 971 term1info = term2info = getenv("TERMINFO");
931 972 progname = argv[0];
932 973
933 974 /* parse options */
934 975 while ((c = getopt(argc, argv, "ducnILCvV1rw:s:A:B:")) != EOF)
935 976 switch (c) {
936 977 case 'v': verbose++;
937 978 break;
938 979 case '1': pr_onecolumn(1);
939 980 break;
940 981 case 'w': pr_width(atoi(optarg));
941 982 break;
942 983 case 'd': diff++;
943 984 break;
944 985 case 'c': common++;
945 986 break;
946 987 case 'n': neither++;
947 988 break;
948 989 case 'u': use++;
949 990 break;
950 991 case 'L': pr_init(printing = pr_longnames);
951 992 break;
952 993 case 'I': pr_init(printing = pr_terminfo);
953 994 break;
954 995 case 'C': pr_init(printing = pr_cap);
955 996 break;
956 997 case 'A': term1info = optarg; Aflag++;
957 998 break;
958 999 case 'B': term2info = optarg; Bflag++;
959 1000 break;
960 1001 case 'r': pr_caprestrict(0);
961 1002 break;
962 1003 case 's':
963 1004 if (strcmp(optarg, "d") == 0)
964 1005 sortorder = by_database;
965 1006 else if (strcmp(optarg, "i") == 0)
966 1007 sortorder = by_terminfo;
967 1008 else if (strcmp(optarg, "l") == 0)
968 1009 sortorder = by_longnames;
969 1010 else if (strcmp(optarg, "c") == 0)
970 1011 sortorder = by_cap;
971 1012 else
972 1013 goto usage;
973 1014 break;
974 1015 case 'V':
975 1016 (void) printf("%s: version %s\n", progname,
976 1017 "@(#)curses:screen/infocmp.c 1.13");
977 1018 exit(0);
978 1019 case '?':
979 1020 usage:
980 1021 (void) fprintf(stderr,
981 1022 "usage: %s [-ducn] [-ILC] [-1Vv] "
982 1023 "[-s d|i|l|c] [-A directory] "
983 1024 "[-B directory] term-names ...\n",
984 1025 progname);
985 1026 (void) fprintf(stderr, "\t-d\tprint "
986 1027 "differences (the default for >1 "
987 1028 "term-name)\n");
988 1029 (void) fprintf(stderr, "\t-u\tproduce "
989 1030 "relative description\n");
990 1031 (void) fprintf(stderr, "\t-c\tprint common "
991 1032 "entries\n");
992 1033 (void) fprintf(stderr, "\t-n\tprint entries "
993 1034 "in neither\n");
994 1035 (void) fprintf(stderr, "\t-I\tprint terminfo "
995 1036 "entries (the default for 1 term-name)\n");
996 1037 (void) fprintf(stderr, "\t-C\tprint termcap "
997 1038 "entries\n");
998 1039 (void) fprintf(stderr, "\t-L\tprint long C "
999 1040 "variable names\n");
1000 1041 (void) fprintf(stderr, "\t-1\tsingle column "
1001 1042 "output\n");
1002 1043 (void) fprintf(stderr, "\t-V\tprint program "
1003 1044 "version\n");
1004 1045 (void) fprintf(stderr, "\t-v\tverbose "
1005 1046 "debugging output\n");
1006 1047 (void) fprintf(stderr, "\t-s\tchange sort "
1007 1048 "order\n");
1008 1049 (void) fprintf(stderr, "\t-A\tset $TERMINFO "
1009 1050 "for first term-name\n");
1010 1051 (void) fprintf(stderr, "\t-B\tset $TERMINFO "
1011 1052 "for other term-names\n");
1012 1053 exit(-1);
1013 1054 }
1014 1055
1015 1056 argc -= optind;
1016 1057 argv += optind;
1017 1058 optind = 0;
1018 1059
1019 1060 /* Default to $TERM for -n, -I, -C and -L options. */
1020 1061 /* This is done by faking argv[][], argc and optind. */
1021 1062 if (neither && (argc == 0 || argc == 1)) {
1022 1063 if (argc == 0)
1023 1064 tempargv[0] = term;
1024 1065 else
1025 1066 tempargv[0] = argv[optind];
1026 1067 tempargv[1] = term;
1027 1068 argc = 2;
1028 1069 argv = tempargv;
1029 1070 optind = 0;
1030 1071 } else if ((printing != pr_none) && (argc == 0)) {
1031 1072 tempargv[0] = term;
1032 1073 argc = 1;
1033 1074 argv = tempargv;
1034 1075 optind = 0;
1035 1076 }
1036 1077
1037 1078 /* Check for enough names. */
1038 1079 if ((use || diff || common) && (argc <= 1)) {
1039 1080 (void) fprintf(stderr,
1040 1081 "%s: must have at least two terminal names for a "
1041 1082 "comparison to be done.\n", progname);
1042 1083 goto usage;
1043 1084 }
1044 1085
↓ open down ↓ |
126 lines elided |
↑ open up ↑ |
1045 1086 /* Set the default of diff -d or print -I */
1046 1087 if (!use && (printing == pr_none) && !common && !neither) {
1047 1088 if (argc == 0 || argc == 1) {
1048 1089 if (argc == 0) {
1049 1090 tempargv[0] = term;
1050 1091 argc = 1;
1051 1092 argv = tempargv;
1052 1093 optind = 0;
1053 1094 }
1054 1095 pr_init(printing = pr_terminfo);
1055 - } else
1096 + } else {
1056 1097 diff++;
1098 + }
1057 1099 }
1058 1100
1059 1101 /* Set the default sorting order. */
1060 - if (sortorder == none)
1102 + if (sortorder == none) {
1061 1103 switch ((int) printing) {
1062 1104 case (int) pr_cap:
1063 1105 sortorder = by_cap; break;
1064 1106 case (int) pr_longnames:
1065 1107 sortorder = by_longnames; break;
1066 1108 case (int) pr_terminfo:
1067 1109 case (int) pr_none:
1068 1110 sortorder = by_terminfo; break;
1069 1111 }
1112 + }
1070 1113
1071 1114 firstterm = argv[optind++];
1072 1115 firstoptind = optind;
1073 1116
1074 1117 allocvariables(argc, firstoptind);
1075 1118 sortnames();
1076 1119
1077 1120 devnull = open("/dev/null", O_RDWR);
1078 1121 local_setenv(term1info);
1079 1122 initfirstterm(firstterm);
1080 1123 local_setenv(term2info);
1081 1124 for (i = 0; optind < argc; optind++, i++)
1082 1125 check_nth_terminal(argv[optind], i);
1083 1126
1084 1127 if (use)
1085 1128 dorelative(firstoptind, argc, argv);
1086 1129
1087 1130 return (0);
1088 1131 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX