Print this page
-T on the wrong command!
Latest round of fixes per RM and AL.  Fix bugs found in man.c.

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/man/man.c
          +++ new/usr/src/cmd/man/man.c
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   * Copyright 2012, Josef 'Jeff' Sipek <jeffpc@31bits.net>. All rights reserved.
  25   25   * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
       26 + * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  26   27   */
  27   28  
  28   29  /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989  AT&T.   */
  29   30  /*              All rights reserved.                                    */
  30   31  
  31   32  /*
  32   33   * University Copyright- Copyright (c) 1982, 1986, 1988
  33   34   * The Regents of the University of California
  34   35   * All Rights Reserved
  35   36   *
↓ open down ↓ 39 lines elided ↑ open up ↑
  75   76          { "3b",         "3ucb"          },
  76   77          { "3e",         "3elf"          },
  77   78          { "3g",         "3gen"          },
  78   79          { "3k",         "3kstat"        },
  79   80          { "3n",         "3socket"       },
  80   81          { "3r",         "3rt"           },
  81   82          { "3s",         "3c"            },
  82   83          { "3t",         "3thr"          },
  83   84          { "3x",         "3curses"       },
  84   85          { "3xc",        "3xcurses"      },
  85      -        { "3xn",        "3xnet"         }
       86 +        { "3xn",        "3xnet"         },
       87 +        { NULL,         NULL            }
  86   88  };
  87   89  
  88   90  struct suffix {
  89   91          char *ds;
  90   92          char *fs;
  91   93  };
  92   94  
  93   95  /*
  94   96   * Flags that control behavior of build_manpath()
  95   97   *
↓ open down ↓ 55 lines elided ↑ open up ↑
 151  153  
 152  154  static int      all = 0;
 153  155  static int      apropos = 0;
 154  156  static int      debug = 0;
 155  157  static int      found = 0;
 156  158  static int      list = 0;
 157  159  static int      makewhatis = 0;
 158  160  static int      printmp = 0;
 159  161  static int      sargs = 0;
 160  162  static int      psoutput = 0;
      163 +static int      lintout = 0;
 161  164  static int      whatis = 0;
 162  165  static int      makewhatishere = 0;
 163  166  
 164  167  static char     *mansec;
 165      -static char     *pager;
      168 +static char     *pager = NULL;
 166  169  
 167  170  static char     *addlocale(char *);
 168  171  static struct man_node *build_manpath(char **, int);
 169  172  static void     do_makewhatis(struct man_node *);
 170  173  static char     *check_config(char *);
 171  174  static int      cmp(const void *, const void *);
 172  175  static int      dupcheck(struct man_node *, struct dupnode **);
 173  176  static int      format(char *, char *, char *, char *);
 174  177  static void     free_dupnode(struct dupnode *);
 175  178  static void     free_manp(struct man_node *manp);
↓ open down ↓ 55 lines elided ↑ open up ↑
 231  234          if (strcmp(__progname, "apropos") == 0) {
 232  235                  apropos++;
 233  236                  opts = "M:ds:";
 234  237          } else if (strcmp(__progname, "whatis") == 0) {
 235  238                  apropos++;
 236  239                  whatis++;
 237  240                  opts = "M:ds:";
 238  241          } else if (strcmp(__progname, "catman") == 0) {
 239  242                  catman++;
 240  243                  makewhatis++;
 241      -                opts = "M:w";
      244 +                opts = "P:M:w";
 242  245          } else if (strcmp(__progname, "makewhatis") == 0) {
 243  246                  makewhatis++;
 244  247                  makewhatishere++;
 245  248                  manpath = ".";
 246  249                  opts = "";
 247  250          } else {
 248      -                opts = "M:adfklps:tw";
      251 +                opts = "FM:P:T:adfklprs:tw";
      252 +                if (argc > 1 && strcmp(argv[1], "-") == 0) {
      253 +                        pager = "cat";
      254 +                        optind++;
      255 +                }
 249  256          }
 250  257  
 251  258          opterr = 0;
 252  259          while ((c = getopt(argc, argv, opts)) != -1) {
 253  260                  switch (c) {
 254  261                  case 'M':       /* Respecify path for man pages */
 255  262                          manpath = optarg;
 256  263                          break;
 257  264                  case 'a':
 258  265                          all++;
↓ open down ↓ 2 lines elided ↑ open up ↑
 261  268                          debug++;
 262  269                          break;
 263  270                  case 'f':
 264  271                          whatis++;
 265  272                          /*FALLTHROUGH*/
 266  273                  case 'k':
 267  274                          apropos++;
 268  275                          break;
 269  276                  case 'l':
 270  277                          list++;
 271      -                        /*FALLTHROUGH*/
      278 +                        all++;
      279 +                        break;
 272  280                  case 'p':
 273  281                          printmp++;
 274  282                          break;
 275  283                  case 's':
 276  284                          mansec = optarg;
 277  285                          sargs++;
 278  286                          break;
      287 +                case 'r':
      288 +                        lintout++;
      289 +                        break;
 279  290                  case 't':
 280  291                          psoutput++;
 281  292                          break;
      293 +                case 'T':
      294 +                case 'P':
      295 +                case 'F':
      296 +                        /* legacy options, compatibility only and ignored */
      297 +                        break;
 282  298                  case 'w':
 283  299                          makewhatis++;
 284  300                          break;
 285  301                  case '?':
 286  302                  default:
 287  303                          if (apropos)
 288  304                                  usage_whatapro();
 289  305                          else if (catman)
 290  306                                  usage_catman();
 291  307                          else if (makewhatishere)
↓ open down ↓ 52 lines elided ↑ open up ↑
 344  360                  } else {
 345  361                          manwidth = (int)strtol(mwstr, (char **)NULL, 10);
 346  362                          if (manwidth < 0)
 347  363                                  manwidth = 0;
 348  364                  }
 349  365          }
 350  366          if (manwidth != 0) {
 351  367                  DPRINTF("-- Using non-standard page width: %d\n", manwidth);
 352  368          }
 353  369  
 354      -        if ((pager = getenv("PAGER")) == NULL || *pager == '\0')
 355      -                pager = PAGER;
      370 +        if (pager == NULL) {
      371 +                if ((pager = getenv("PAGER")) == NULL || *pager == '\0')
      372 +                        pager = PAGER;
      373 +        }
 356  374          DPRINTF("-- Using pager: %s\n", pager);
 357  375  
 358  376          for (i = 0; i < argc; i++) {
 359  377                  char            *cmd;
 360  378                  static struct man_node *mp;
 361  379                  char            *pv[2];
 362  380  
 363  381                  /*
 364  382                   * If full path to command specified, customize
 365  383                   * the manpath accordingly.
↓ open down ↓ 773 lines elided ↑ open up ↑
1139 1157  }
1140 1158  
1141 1159  /*
1142 1160   * Check the hash table of old directory names to see if there is a
1143 1161   * new directory name.
1144 1162   */
1145 1163  static char *
1146 1164  map_section(char *section, char *path)
1147 1165  {
1148 1166          int     i;
1149      -        int     len;
1150 1167          char    fullpath[MAXPATHLEN];
1151 1168  
1152 1169          if (list)  /* -l option fall through */
1153 1170                  return (NULL);
1154 1171  
1155      -        for (i = 0; i <= ((sizeof (map)/sizeof (map[0]) - 1)); i++) {
1156      -                if (strlen(section) > strlen(map[i].new_name)) {
1157      -                        len = strlen(section);
1158      -                } else {
1159      -                        len = strlen(map[i].new_name);
1160      -                }
1161      -                if (strncmp(section, map[i].old_name, len) == 0) {
     1172 +        for (i = 0; map[i].new_name != NULL; i++) {
     1173 +                if (strcmp(section, map[i].old_name) == 0) {
1162 1174                          (void) snprintf(fullpath, sizeof (fullpath),
1163      -                            "%s/sman%s", path, map[i].new_name);
     1175 +                            "%s/man%s", path, map[i].new_name);
1164 1176                          if (!access(fullpath, R_OK | X_OK)) {
1165 1177                                  return (map[i].new_name);
1166 1178                          } else {
1167 1179                                  return (NULL);
1168 1180                          }
1169 1181                  }
1170 1182          }
1171 1183  
1172 1184          return (NULL);
1173 1185  }
↓ open down ↓ 16 lines elided ↑ open up ↑
1190 1202                  (void) printf(gettext("%s(%s)\t-M %s\n"), name, dir + 3, path);
1191 1203                  return (-1);
1192 1204          }
1193 1205  
1194 1206          (void) snprintf(manpname, sizeof (manpname), "%s/man%s/%s", path,
1195 1207              dir + 3, pg);
1196 1208          (void) snprintf(catpname, sizeof (catpname), "%s/cat%s/%s", path,
1197 1209              dir + 3, pg);
1198 1210  
1199 1211          /* Can't do PS output if manpage doesn't exist */
1200      -        if (stat(manpname, &sbman) != 0 && psoutput)
     1212 +        if (stat(manpname, &sbman) != 0 && (psoutput|lintout))
1201 1213                  return (-1);
1202 1214  
1203 1215          /*
1204 1216           * If both manpage and catpage do not exist, manpname is
1205 1217           * broken symlink, most likely.
1206 1218           */
1207 1219          if (stat(catpname, &sbcat) != 0 && stat(manpname, &sbman) != 0)
1208 1220                  err(1, "%s", manpname);
1209 1221  
1210 1222          /* Setup cattool */
1211 1223          if (fnmatch("*.gz", manpname, 0) == 0)
1212 1224                  cattool = "gzcat";
1213 1225          else if (fnmatch("*.bz2", manpname, 0) == 0)
1214 1226                  cattool = "bzcat";
1215 1227          else
1216      -                cattool = "gzcat -f";
     1228 +                cattool = "cat";
1217 1229  
1218 1230          /* Preprocess UTF-8 input with preconv (could be smarter) */
1219 1231          if (strstr(path, "UTF-8") != NULL)
1220 1232                  utf8 = 1;
1221 1233  
1222 1234          if (psoutput) {
1223 1235                  (void) snprintf(cmdbuf, BUFSIZ,
1224 1236                      "cd %s; %s %s%s | mandoc -Tps | lp -Tpostscript",
1225 1237                      path, cattool, manpname,
1226 1238                      utf8 ? " | " PRECONV " -e UTF-8" : "");
1227 1239                  DPRINTF("-- Using manpage: %s\n", manpname);
1228 1240                  goto cmd;
     1241 +        } else if (lintout) {
     1242 +                (void) snprintf(cmdbuf, BUFSIZ,
     1243 +                    "cd %s; %s %s%s | mandoc -Tlint",
     1244 +                    path, cattool, manpname,
     1245 +                    utf8 ? " | " PRECONV " -e UTF-8" : "");
     1246 +                DPRINTF("-- Linting manpage: %s\n", manpname);
     1247 +                goto cmd;
1229 1248          }
1230 1249  
1231 1250          /*
1232 1251           * Output catpage if:
1233 1252           * - manpage doesn't exist
1234 1253           * - output width is standard and catpage is recent enough
1235 1254           */
1236 1255          if (stat(manpname, &sbman) != 0 || (manwidth == 0 &&
1237 1256              stat(catpname, &sbcat) == 0 && sbcat.st_mtime >= sbman.st_mtime)) {
1238 1257                  DPRINTF("-- Using catpage: %s\n", catpname);
↓ open down ↓ 322 lines elided ↑ open up ↑
1561 1580          }
1562 1581          (void) printf("\n");
1563 1582  }
1564 1583  
1565 1584  static void
1566 1585  usage_man(void)
1567 1586  {
1568 1587  
1569 1588          (void) fprintf(stderr, gettext(
1570 1589  "usage: man [-alptw] [-M path] [-s section] name ...\n"
1571      -"       man [-M path] [-s section] -k keyword -- emulate apropos\n"
1572      -"       man [-M path] [-s section] -f keyword -- emulate whatis\n"));
     1590 +"       man [-M path] [-s section] -k keyword ...\n"
     1591 +"       man [-M path] [-s section] -f keyword ...\n"));
1573 1592  
1574 1593          exit(1);
1575 1594  }
1576 1595  
1577 1596  static void
1578 1597  usage_whatapro(void)
1579 1598  {
1580 1599  
1581 1600          (void) fprintf(stderr, gettext(
1582 1601  "usage: %s [-M path] [-s section] keyword ...\n"),
↓ open down ↓ 21 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX