Print this page
Add catman, makewhatis functionality.  Print an error if the whatis database
is missing.

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/man/man.c
          +++ new/usr/src/cmd/man/man.c
↓ open down ↓ 151 lines elided ↑ open up ↑
 152  152  static int      all = 0;
 153  153  static int      apropos = 0;
 154  154  static int      debug = 0;
 155  155  static int      found = 0;
 156  156  static int      list = 0;
 157  157  static int      makewhatis = 0;
 158  158  static int      printmp = 0;
 159  159  static int      sargs = 0;
 160  160  static int      psoutput = 0;
 161  161  static int      whatis = 0;
      162 +static int      makewhatishere = 0;
 162  163  
 163  164  static char     *mansec;
 164  165  static char     *pager;
 165  166  
 166  167  static char     *addlocale(char *);
 167  168  static struct man_node *build_manpath(char **, int);
 168  169  static void     do_makewhatis(struct man_node *);
 169  170  static char     *check_config(char *);
 170  171  static int      cmp(const void *, const void *);
 171  172  static int      dupcheck(struct man_node *, struct dupnode **);
↓ open down ↓ 12 lines elided ↑ open up ↑
 184  185  static int      manual(struct man_node *, char *);
 185  186  static char     *map_section(char *, char *);
 186  187  static char     *path_to_manpath(char *);
 187  188  static void     print_manpath(struct man_node *);
 188  189  static void     search_whatis(char *, char *);
 189  190  static int      searchdir(char *, char *, char *);
 190  191  static void     sortdir(DIR *, char ***);
 191  192  static char     **split(char *, char);
 192  193  static void     usage_man(void);
 193  194  static void     usage_whatapro(void);
      195 +static void     usage_catman(void);
      196 +static void     usage_makewhatis(void);
 194  197  static void     whatapro(struct man_node *, char *);
 195  198  
 196  199  static char     language[MAXPATHLEN];   /* LC_MESSAGES */
 197  200  static char     localedir[MAXPATHLEN];  /* locale specific path component */
 198  201  
 199  202  static char     *newsection = NULL;
 200  203  
 201  204  static int      manwidth = 0;
 202  205  
 203  206  extern const char       *__progname;
↓ open down ↓ 2 lines elided ↑ open up ↑
 206  209  main(int argc, char **argv)
 207  210  {
 208  211          int             c, i;
 209  212          char            **pathv;
 210  213          char            *manpath = NULL;
 211  214          static struct man_node *mandirs = NULL;
 212  215          int             bmp_flags = 0;
 213  216          int             ret = 0;
 214  217          char            *opts;
 215  218          char            *mwstr;
      219 +        int             catman = 0;
 216  220  
 217  221          (void) setlocale(LC_ALL, "");
 218  222          (void) strcpy(language, setlocale(LC_MESSAGES, (char *)NULL));
 219  223          if (strcmp("C", language) != 0)
 220  224                  (void) strlcpy(localedir, language, MAXPATHLEN);
 221  225  
 222  226  #if !defined(TEXT_DOMAIN)
 223  227  #define TEXT_DOMAIN "SYS_TEST"
 224  228  #endif
 225  229          (void) textdomain(TEXT_DOMAIN);
 226  230  
 227  231          if (strcmp(__progname, "apropos") == 0) {
 228  232                  apropos++;
 229  233                  opts = "M:ds:";
 230  234          } else if (strcmp(__progname, "whatis") == 0) {
 231  235                  apropos++;
 232  236                  whatis++;
 233  237                  opts = "M:ds:";
      238 +        } else if (strcmp(__progname, "catman") == 0) {
      239 +                catman++;
      240 +                makewhatis++;
      241 +                opts = "M:w";
      242 +        } else if (strcmp(__progname, "makewhatis") == 0) {
      243 +                makewhatis++;
      244 +                makewhatishere++;
      245 +                manpath = ".";
      246 +                opts = "";
 234  247          } else {
 235  248                  opts = "M:adfklps:tw";
 236  249          }
 237  250  
 238  251          opterr = 0;
 239  252          while ((c = getopt(argc, argv, opts)) != -1) {
 240  253                  switch (c) {
 241  254                  case 'M':       /* Respecify path for man pages */
 242  255                          manpath = optarg;
 243  256                          break;
↓ open down ↓ 22 lines elided ↑ open up ↑
 266  279                  case 't':
 267  280                          psoutput++;
 268  281                          break;
 269  282                  case 'w':
 270  283                          makewhatis++;
 271  284                          break;
 272  285                  case '?':
 273  286                  default:
 274  287                          if (apropos)
 275  288                                  usage_whatapro();
      289 +                        else if (catman)
      290 +                                usage_catman();
      291 +                        else if (makewhatishere)
      292 +                                usage_makewhatis();
 276  293                          else
 277  294                                  usage_man();
 278  295                  }
 279  296          }
 280  297          argc -= optind;
 281  298          argv += optind;
 282  299  
 283  300          if (argc == 0) {
 284  301                  if (apropos) {
 285  302                          (void) fprintf(stderr, gettext("%s what?\n"),
↓ open down ↓ 397 lines elided ↑ open up ↑
 683  700  {
 684  701          FILE            *fp;
 685  702          char            *line = NULL;
 686  703          size_t          linecap = 0;
 687  704          char            *pkwd;
 688  705          regex_t         preg;
 689  706          char            **ss = NULL;
 690  707          char            s[MAXNAMELEN];
 691  708          int             i;
 692  709  
 693      -        if ((fp = fopen(whatpath, "r")) == NULL)
      710 +        if ((fp = fopen(whatpath, "r")) == NULL) {
      711 +                perror(whatpath);
 694  712                  return;
      713 +        }
 695  714  
 696  715          DPRINTF("-- Found %s: %s\n", WHATIS, whatpath);
 697  716  
 698  717          /* Build keyword regex */
 699  718          if (asprintf(&pkwd, "%s%s%s", (whatis) ? "\\<" : "",
 700  719              word, (whatis) ? "\\>" : "") == -1)
 701  720                  err(1, "asprintf");
 702  721  
 703  722          if (regcomp(&preg, pkwd, REG_BASIC | REG_ICASE | REG_NOSUB) != 0)
 704  723                  err(1, "regcomp");
↓ open down ↓ 852 lines elided ↑ open up ↑
1557 1576  
1558 1577  static void
1559 1578  usage_whatapro(void)
1560 1579  {
1561 1580  
1562 1581          (void) fprintf(stderr, gettext(
1563 1582  "usage: %s [-M path] [-s section] keyword ...\n"),
1564 1583              whatis ? "whatis" : "apropos");
1565 1584  
1566 1585          exit(1);
     1586 +}
     1587 +
     1588 +static void
     1589 +usage_catman(void)
     1590 +{
     1591 +        (void) fprintf(stderr, gettext(
     1592 +"usage: catman [-M path] [-w]\n"));
     1593 +
     1594 +        exit(1);
     1595 +}
     1596 +
     1597 +static void
     1598 +usage_makewhatis(void)
     1599 +{
     1600 +        (void) fprintf(stderr, gettext("usage: makewhatis\n"));
     1601 +
     1602 +        exit(1);
1567 1603  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX