[BACK]Return to main.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/main.c between version 1.160 and 1.171

version 1.160, 2011/03/28 21:49:42 version 1.171, 2014/03/19 22:20:43
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze <schwarze@openbsd.org>
    * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
Line 43  typedef void  (*out_free)(void *);
Line 44  typedef void  (*out_free)(void *);
   
 enum    outt {  enum    outt {
         OUTT_ASCII = 0, /* -Tascii */          OUTT_ASCII = 0, /* -Tascii */
           OUTT_LOCALE,    /* -Tlocale */
           OUTT_UTF8,      /* -Tutf8 */
         OUTT_TREE,      /* -Ttree */          OUTT_TREE,      /* -Ttree */
           OUTT_MAN,       /* -Tman */
         OUTT_HTML,      /* -Thtml */          OUTT_HTML,      /* -Thtml */
         OUTT_XHTML,     /* -Txhtml */          OUTT_XHTML,     /* -Txhtml */
         OUTT_LINT,      /* -Tlint */          OUTT_LINT,      /* -Tlint */
Line 63  struct curparse {
Line 67  struct curparse {
         char              outopts[BUFSIZ]; /* buf of output opts */          char              outopts[BUFSIZ]; /* buf of output opts */
 };  };
   
 static  int               moptions(enum mparset *, char *);  static  int               moptions(int *, char *);
 static  void              mmsg(enum mandocerr, enum mandoclevel,  static  void              mmsg(enum mandocerr, enum mandoclevel,
                                 const char *, int, int, const char *);                                  const char *, int, int, const char *);
 static  void              parse(struct curparse *, int,  static  void              parse(struct curparse *, int,
Line 80  main(int argc, char *argv[])
Line 84  main(int argc, char *argv[])
 {  {
         int              c;          int              c;
         struct curparse  curp;          struct curparse  curp;
         enum mparset     type;          int              options;
         enum mandoclevel rc;          enum mandoclevel rc;
           char            *defos;
   
         progname = strrchr(argv[0], '/');          progname = strrchr(argv[0], '/');
         if (progname == NULL)          if (progname == NULL)
Line 91  main(int argc, char *argv[])
Line 96  main(int argc, char *argv[])
   
         memset(&curp, 0, sizeof(struct curparse));          memset(&curp, 0, sizeof(struct curparse));
   
         type = MPARSE_AUTO;          options = MPARSE_SO;
         curp.outtype = OUTT_ASCII;          curp.outtype = OUTT_ASCII;
         curp.wlevel  = MANDOCLEVEL_FATAL;          curp.wlevel  = MANDOCLEVEL_FATAL;
           defos = NULL;
   
         /* LINTED */          /* LINTED */
         while (-1 != (c = getopt(argc, argv, "m:O:T:VW:")))          while (-1 != (c = getopt(argc, argv, "I:m:O:T:VW:")))
                 switch (c) {                  switch (c) {
                   case ('I'):
                           if (strncmp(optarg, "os=", 3)) {
                                   fprintf(stderr, "-I%s: Bad argument\n",
                                                   optarg);
                                   return((int)MANDOCLEVEL_BADARG);
                           }
                           if (defos) {
                                   fprintf(stderr, "-I%s: Duplicate argument\n",
                                                   optarg);
                                   return((int)MANDOCLEVEL_BADARG);
                           }
                           defos = mandoc_strdup(optarg + 3);
                           break;
                 case ('m'):                  case ('m'):
                         if ( ! moptions(&type, optarg))                          if ( ! moptions(&options, optarg))
                                 return((int)MANDOCLEVEL_BADARG);                                  return((int)MANDOCLEVEL_BADARG);
                         break;                          break;
                 case ('O'):                  case ('O'):
Line 122  main(int argc, char *argv[])
Line 141  main(int argc, char *argv[])
                         /* NOTREACHED */                          /* NOTREACHED */
                 }                  }
   
         curp.mp = mparse_alloc(type, curp.wlevel, mmsg, &curp);          curp.mp = mparse_alloc(options, curp.wlevel, mmsg, defos);
   
           /*
            * Conditionally start up the lookaside buffer before parsing.
            */
           if (OUTT_MAN == curp.outtype)
                   mparse_keep(curp.mp);
   
         argc -= optind;          argc -= optind;
         argv += optind;          argv += optind;
   
Line 143  main(int argc, char *argv[])
Line 168  main(int argc, char *argv[])
                 (*curp.outfree)(curp.outdata);                  (*curp.outfree)(curp.outdata);
         if (curp.mp)          if (curp.mp)
                 mparse_free(curp.mp);                  mparse_free(curp.mp);
           free(defos);
   
         return((int)rc);          return((int)rc);
 }  }
Line 161  usage(void)
Line 187  usage(void)
   
         fprintf(stderr, "usage: %s "          fprintf(stderr, "usage: %s "
                         "[-V] "                          "[-V] "
                         "[-foption] "                          "[-Ios=name] "
                         "[-mformat] "                          "[-mformat] "
                         "[-Ooption] "                          "[-Ooption] "
                         "[-Toutput] "                          "[-Toutput] "
                         "[-Werr] "                          "[-Wlevel]\n"
                         "[file...]\n",                          "\t      [file ...]\n",
                         progname);                          progname);
   
         exit((int)MANDOCLEVEL_BADARG);          exit((int)MANDOCLEVEL_BADARG);
Line 206  parse(struct curparse *curp, int fd, 
Line 232  parse(struct curparse *curp, int fd, 
                 switch (curp->outtype) {                  switch (curp->outtype) {
                 case (OUTT_XHTML):                  case (OUTT_XHTML):
                         curp->outdata = xhtml_alloc(curp->outopts);                          curp->outdata = xhtml_alloc(curp->outopts);
                           curp->outfree = html_free;
                         break;                          break;
                 case (OUTT_HTML):                  case (OUTT_HTML):
                         curp->outdata = html_alloc(curp->outopts);                          curp->outdata = html_alloc(curp->outopts);
                           curp->outfree = html_free;
                         break;                          break;
                   case (OUTT_UTF8):
                           curp->outdata = utf8_alloc(curp->outopts);
                           curp->outfree = ascii_free;
                           break;
                   case (OUTT_LOCALE):
                           curp->outdata = locale_alloc(curp->outopts);
                           curp->outfree = ascii_free;
                           break;
                 case (OUTT_ASCII):                  case (OUTT_ASCII):
                         curp->outdata = ascii_alloc(curp->outopts);                          curp->outdata = ascii_alloc(curp->outopts);
                         curp->outfree = ascii_free;                          curp->outfree = ascii_free;
Line 232  parse(struct curparse *curp, int fd, 
Line 268  parse(struct curparse *curp, int fd, 
                 case (OUTT_XHTML):                  case (OUTT_XHTML):
                         curp->outman = html_man;                          curp->outman = html_man;
                         curp->outmdoc = html_mdoc;                          curp->outmdoc = html_mdoc;
                         curp->outfree = html_free;  
                         break;                          break;
                 case (OUTT_TREE):                  case (OUTT_TREE):
                         curp->outman = tree_man;                          curp->outman = tree_man;
                         curp->outmdoc = tree_mdoc;                          curp->outmdoc = tree_mdoc;
                         break;                          break;
                   case (OUTT_MAN):
                           curp->outmdoc = man_mdoc;
                           curp->outman = man_man;
                           break;
                 case (OUTT_PDF):                  case (OUTT_PDF):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (OUTT_ASCII):                  case (OUTT_ASCII):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                   case (OUTT_UTF8):
                           /* FALLTHROUGH */
                   case (OUTT_LOCALE):
                           /* FALLTHROUGH */
                 case (OUTT_PS):                  case (OUTT_PS):
                         curp->outman = terminal_man;                          curp->outman = terminal_man;
                         curp->outmdoc = terminal_mdoc;                          curp->outmdoc = terminal_mdoc;
Line 251  parse(struct curparse *curp, int fd, 
Line 294  parse(struct curparse *curp, int fd, 
                 }                  }
         }          }
   
         mparse_result(curp->mp, &mdoc, &man);          mparse_result(curp->mp, &mdoc, &man, NULL);
   
         /* Execute the out device, if it exists. */          /* Execute the out device, if it exists. */
   
Line 269  parse(struct curparse *curp, int fd, 
Line 312  parse(struct curparse *curp, int fd, 
 }  }
   
 static int  static int
 moptions(enum mparset *tflags, char *arg)  moptions(int *options, char *arg)
 {  {
   
         if (0 == strcmp(arg, "doc"))          if (0 == strcmp(arg, "doc"))
                 *tflags = MPARSE_MDOC;                  *options |= MPARSE_MDOC;
         else if (0 == strcmp(arg, "andoc"))          else if (0 == strcmp(arg, "andoc"))
                 *tflags = MPARSE_AUTO;                  /* nothing to do */;
         else if (0 == strcmp(arg, "an"))          else if (0 == strcmp(arg, "an"))
                 *tflags = MPARSE_MAN;                  *options |= MPARSE_MAN;
         else {          else {
                 fprintf(stderr, "%s: Bad argument\n", arg);                  fprintf(stderr, "%s: Bad argument\n", arg);
                 return(0);                  return(0);
Line 297  toptions(struct curparse *curp, char *arg)
Line 340  toptions(struct curparse *curp, char *arg)
                 curp->wlevel  = MANDOCLEVEL_WARNING;                  curp->wlevel  = MANDOCLEVEL_WARNING;
         } else if (0 == strcmp(arg, "tree"))          } else if (0 == strcmp(arg, "tree"))
                 curp->outtype = OUTT_TREE;                  curp->outtype = OUTT_TREE;
           else if (0 == strcmp(arg, "man"))
                   curp->outtype = OUTT_MAN;
         else if (0 == strcmp(arg, "html"))          else if (0 == strcmp(arg, "html"))
                 curp->outtype = OUTT_HTML;                  curp->outtype = OUTT_HTML;
           else if (0 == strcmp(arg, "utf8"))
                   curp->outtype = OUTT_UTF8;
           else if (0 == strcmp(arg, "locale"))
                   curp->outtype = OUTT_LOCALE;
         else if (0 == strcmp(arg, "xhtml"))          else if (0 == strcmp(arg, "xhtml"))
                 curp->outtype = OUTT_XHTML;                  curp->outtype = OUTT_XHTML;
         else if (0 == strcmp(arg, "ps"))          else if (0 == strcmp(arg, "ps"))

Legend:
Removed from v.1.160  
changed lines
  Added in v.1.171

CVSweb