Print this page
Update to 1.12.3.

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/mandoc/main.c
          +++ new/usr/src/cmd/mandoc/main.c
   1      -/*      $Id: main.c,v 1.165 2011/10/06 22:29:12 kristaps Exp $ */
        1 +/*      $Id: main.c,v 1.167 2012/11/19 17:22:26 schwarze Exp $ */
   2    2  /*
   3    3   * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
   4      - * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
        4 + * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
   5    5   *
   6    6   * Permission to use, copy, modify, and distribute this software for any
   7    7   * purpose with or without fee is hereby granted, provided that the above
   8    8   * copyright notice and this permission notice appear in all copies.
   9    9   *
  10   10   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11   11   * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12   12   * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13   13   * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14   14   * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
↓ open down ↓ 63 lines elided ↑ open up ↑
  78   78  
  79   79  static  const char       *progname;
  80   80  
  81   81  int
  82   82  main(int argc, char *argv[])
  83   83  {
  84   84          int              c;
  85   85          struct curparse  curp;
  86   86          enum mparset     type;
  87   87          enum mandoclevel rc;
       88 +        char            *defos;
  88   89  
  89   90          progname = strrchr(argv[0], '/');
  90   91          if (progname == NULL)
  91   92                  progname = argv[0];
  92   93          else
  93   94                  ++progname;
  94   95  
  95   96          memset(&curp, 0, sizeof(struct curparse));
  96   97  
  97   98          type = MPARSE_AUTO;
  98   99          curp.outtype = OUTT_ASCII;
  99  100          curp.wlevel  = MANDOCLEVEL_FATAL;
      101 +        defos = NULL;
 100  102  
 101  103          /* LINTED */
 102      -        while (-1 != (c = getopt(argc, argv, "m:O:T:VW:")))
      104 +        while (-1 != (c = getopt(argc, argv, "I:m:O:T:VW:")))
 103  105                  switch (c) {
      106 +                case ('I'):
      107 +                        if (strncmp(optarg, "os=", 3)) {
      108 +                                fprintf(stderr, "-I%s: Bad argument\n",
      109 +                                                optarg);
      110 +                                return((int)MANDOCLEVEL_BADARG);
      111 +                        }
      112 +                        if (defos) {
      113 +                                fprintf(stderr, "-I%s: Duplicate argument\n",
      114 +                                                optarg);
      115 +                                return((int)MANDOCLEVEL_BADARG);
      116 +                        }
      117 +                        defos = mandoc_strdup(optarg + 3);
      118 +                        break;
 104  119                  case ('m'):
 105  120                          if ( ! moptions(&type, optarg))
 106  121                                  return((int)MANDOCLEVEL_BADARG);
 107  122                          break;
 108  123                  case ('O'):
 109  124                          (void)strlcat(curp.outopts, optarg, BUFSIZ);
 110  125                          (void)strlcat(curp.outopts, ",", BUFSIZ);
 111  126                          break;
 112  127                  case ('T'):
 113  128                          if ( ! toptions(&curp, optarg))
↓ open down ↓ 4 lines elided ↑ open up ↑
 118  133                                  return((int)MANDOCLEVEL_BADARG);
 119  134                          break;
 120  135                  case ('V'):
 121  136                          version();
 122  137                          /* NOTREACHED */
 123  138                  default:
 124  139                          usage();
 125  140                          /* NOTREACHED */
 126  141                  }
 127  142  
 128      -        curp.mp = mparse_alloc(type, curp.wlevel, mmsg, &curp);
      143 +        curp.mp = mparse_alloc(type, curp.wlevel, mmsg, &curp, defos);
 129  144  
 130  145          /*
 131  146           * Conditionally start up the lookaside buffer before parsing.
 132  147           */
 133  148          if (OUTT_MAN == curp.outtype)
 134  149                  mparse_keep(curp.mp);
 135  150  
 136  151          argc -= optind;
 137  152          argv += optind;
 138  153  
↓ open down ↓ 6 lines elided ↑ open up ↑
 145  160                  parse(&curp, -1, *argv, &rc);
 146  161                  if (MANDOCLEVEL_OK != rc && curp.wstop)
 147  162                          break;
 148  163                  ++argv;
 149  164          }
 150  165  
 151  166          if (curp.outfree)
 152  167                  (*curp.outfree)(curp.outdata);
 153  168          if (curp.mp)
 154  169                  mparse_free(curp.mp);
      170 +        free(defos);
 155  171  
 156  172          return((int)rc);
 157  173  }
 158  174  
 159  175  static void
 160  176  version(void)
 161  177  {
 162  178  
 163  179          printf("%s %s\n", progname, VERSION);
 164  180          exit((int)MANDOCLEVEL_OK);
 165  181  }
 166  182  
 167  183  static void
 168  184  usage(void)
 169  185  {
 170  186  
 171  187          fprintf(stderr, "usage: %s "
 172  188                          "[-V] "
 173      -                        "[-foption] "
      189 +                        "[-Ios=name] "
 174  190                          "[-mformat] "
 175  191                          "[-Ooption] "
 176  192                          "[-Toutput] "
 177      -                        "[-Wlevel] "
 178      -                        "[file...]\n", 
      193 +                        "[-Wlevel]\n"
      194 +                        "\t      [file ...]\n", 
 179  195                          progname);
 180  196  
 181  197          exit((int)MANDOCLEVEL_BADARG);
 182  198  }
 183  199  
 184  200  static void
 185  201  parse(struct curparse *curp, int fd, 
 186  202                  const char *file, enum mandoclevel *level)
 187  203  {
 188  204          enum mandoclevel  rc;
↓ open down ↓ 213 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX