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

Diff for /mandoc/demandoc.c between version 1.1 and 1.4

version 1.1, 2011/09/01 10:46:28 version 1.4, 2011/09/01 20:55:50
Line 19 
Line 19 
 #endif  #endif
   
 #include <assert.h>  #include <assert.h>
   #include <ctype.h>
 #include <getopt.h>  #include <getopt.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   #include <unistd.h>
   
 #include "man.h"  #include "man.h"
 #include "mdoc.h"  #include "mdoc.h"
 #include "mandoc.h"  #include "mandoc.h"
   
 static  void     pline(int, int *, int *);  static  void     pline(int, int *, int *, int);
 static  void     pman(const struct man_node *, int *, int *);  static  void     pman(const struct man_node *, int *, int *, int);
 static  void     pmandoc(struct mparse *, int, const char *);  static  void     pmandoc(struct mparse *, int, const char *, int);
 static  void     pmdoc(const struct mdoc_node *, int *, int *);  static  void     pmdoc(const struct mdoc_node *, int *, int *, int);
 static  void     pstring(const char *, int, int *);  static  void     pstring(const char *, int, int *, int);
 static  void     usage(void);  static  void     usage(void);
   
 static  const char       *progname;  static  const char       *progname;
Line 41  int
Line 43  int
 main(int argc, char *argv[])  main(int argc, char *argv[])
 {  {
         struct mparse   *mp;          struct mparse   *mp;
         int              ch, i;          int              ch, i, list;
         extern int       optind;          extern int       optind;
         extern char     *optarg;  
   
         progname = strrchr(argv[0], '/');          progname = strrchr(argv[0], '/');
         if (progname == NULL)          if (progname == NULL)
Line 52  main(int argc, char *argv[])
Line 53  main(int argc, char *argv[])
                 ++progname;                  ++progname;
   
         mp = NULL;          mp = NULL;
           list = 0;
   
         while (-1 != (ch = getopt(argc, argv, "")))          while (-1 != (ch = getopt(argc, argv, "ikm:pw")))
                 switch (ch) {                  switch (ch) {
                   case ('i'):
                           /* FALLTHROUGH */
                   case ('k'):
                           /* FALLTHROUGH */
                   case ('m'):
                           /* FALLTHROUGH */
                   case ('p'):
                           break;
                   case ('w'):
                           list = 1;
                           break;
                 default:                  default:
                         usage();                          usage();
                         return((int)MANDOCLEVEL_BADARG);                          return((int)MANDOCLEVEL_BADARG);
Line 67  main(int argc, char *argv[])
Line 80  main(int argc, char *argv[])
         assert(mp);          assert(mp);
   
         if (0 == argc)          if (0 == argc)
                 pmandoc(mp, STDIN_FILENO, "<stdin>");                  pmandoc(mp, STDIN_FILENO, "<stdin>", list);
   
         for (i = 0; i < argc; i++) {          for (i = 0; i < argc; i++) {
                 mparse_reset(mp);                  mparse_reset(mp);
                 pmandoc(mp, -1, argv[i]);                  pmandoc(mp, -1, argv[i], list);
         }          }
   
         mparse_free(mp);          mparse_free(mp);
         return(MANDOCLEVEL_OK);          return((int)MANDOCLEVEL_OK);
 }  }
   
 static void  static void
 usage(void)  usage(void)
 {  {
   
         fprintf(stderr, "usage: %s [files...]\n", progname);          fprintf(stderr, "usage: %s [-w] [files...]\n", progname);
 }  }
   
 static void  static void
 pmandoc(struct mparse *mp, int fd, const char *fn)  pmandoc(struct mparse *mp, int fd, const char *fn, int list)
 {  {
         struct mdoc     *mdoc;          struct mdoc     *mdoc;
         struct man      *man;          struct man      *man;
Line 102  pmandoc(struct mparse *mp, int fd, const char *fn)
Line 115  pmandoc(struct mparse *mp, int fd, const char *fn)
         col = 0;          col = 0;
   
         if (mdoc)          if (mdoc)
                 pmdoc(mdoc_node(mdoc), &line, &col);                  pmdoc(mdoc_node(mdoc), &line, &col, list);
         else if (man)          else if (man)
                 pman(man_node(man), &line, &col);                  pman(man_node(man), &line, &col, list);
         else          else
                 return;                  return;
   
Line 115  pmandoc(struct mparse *mp, int fd, const char *fn)
Line 128  pmandoc(struct mparse *mp, int fd, const char *fn)
  * Strip the escapes out of a string, emitting the results.   * Strip the escapes out of a string, emitting the results.
  */   */
 static void  static void
 pstring(const char *p, int col, int *colp)  pstring(const char *p, int col, int *colp, int list)
 {  {
         enum mandoc_esc  esc;          enum mandoc_esc  esc;
   
Line 124  pstring(const char *p, int col, int *colp)
Line 137  pstring(const char *p, int col, int *colp)
                 (*colp)++;                  (*colp)++;
         }          }
   
         while ('\0' != *p) {          while ('\0' != *p)
                 if ('\\' == *p) {                  if ('\\' == *p) {
                         p++;                          p++;
                         esc = mandoc_escape(&p, NULL, NULL);                          esc = mandoc_escape(&p, NULL, NULL);
                         if (ESCAPE_ERROR == esc)                          if (ESCAPE_ERROR == esc)
                                 return;                                  break;
                 } else {                  } else {
                         putchar(*p++);                          putchar((unsigned char )*p++);
                         (*colp)++;                          (*colp)++;
                 }                  }
         }  
 }  }
   
 /*  
  * Emit lines until we're in sync with our input.  
  */  
 static void  static void
 pline(int line, int *linep, int *col)  pline(int line, int *linep, int *col, int list)
 {  {
   
         while (*linep < line) {          while (*linep < line) {
                 putchar('\n');                  putchar('\n');
                 (*linep)++;                  (*linep)++;
         }          }
   
         *col = 0;          *col = 0;
 }  }
   
 static void  static void
 pmdoc(const struct mdoc_node *p, int *line, int *col)  pmdoc(const struct mdoc_node *p, int *line, int *col, int list)
 {  {
   
         for ( ; p; p = p->next) {          for ( ; p; p = p->next) {
                 if (MDOC_LINE & p->flags)                  if (MDOC_LINE & p->flags)
                         pline(p->line, line, col);                          pline(p->line, line, col, list);
                 if (MDOC_TEXT == p->type)                  if (MDOC_TEXT == p->type)
                         pstring(p->string, p->pos, col);                          pstring(p->string, p->pos, col, list);
                 if (p->child)                  if (p->child)
                         pmdoc(p->child, line, col);                          pmdoc(p->child, line, col, list);
         }          }
 }  }
   
 static void  static void
 pman(const struct man_node *p, int *line, int *col)  pman(const struct man_node *p, int *line, int *col, int list)
 {  {
   
         for ( ; p; p = p->next) {          for ( ; p; p = p->next) {
                 if (MAN_LINE & p->flags)                  if (MAN_LINE & p->flags)
                         pline(p->line, line, col);                          pline(p->line, line, col, list);
                 if (MAN_TEXT == p->type)                  if (MAN_TEXT == p->type)
                         pstring(p->string, p->pos, col);                          pstring(p->string, p->pos, col, list);
                 if (p->child)                  if (p->child)
                         pman(p->child, line, col);                          pman(p->child, line, col, list);
         }          }
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.4

CVSweb