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
↓ 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"
↓ 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)
↓ 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  
↓ 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)
↓ 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)
↓ 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)
↓ 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);
↓ 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
↓ 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