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

Diff for /mandoc/Attic/mdocml.c between version 1.26 and 1.40

version 1.26, 2008/12/28 21:25:09 version 1.40, 2009/01/12 12:52:21
Line 57  static int   buf_leave(struct md_parse *, int);
Line 57  static int   buf_leave(struct md_parse *, int);
   
 static  int              msg_err(void *, int, int, enum mdoc_err);  static  int              msg_err(void *, int, int, enum mdoc_err);
 static  int              msg_warn(void *, int, int, enum mdoc_warn);  static  int              msg_warn(void *, int, int, enum mdoc_warn);
 static  void             msg_msg(void *, int, const char *);  static  void             msg_msg(void *, int, int, const char *);
   
 #ifdef __linux__  #ifdef __linux__
 extern  int              getsubopt(char **, char *const *, char **);  extern  int              getsubopt(char **, char *const *, char **);
Line 192  print_node(const struct mdoc_node *n, int indent)
Line 192  print_node(const struct mdoc_node *n, int indent)
         params = NULL;          params = NULL;
         sz = 0;          sz = 0;
   
           /* FIXME: put parts of this in util.c. */
         switch (n->type) {          switch (n->type) {
         case (MDOC_TEXT):          case (MDOC_TEXT):
                 assert(NULL == n->child);                  assert(NULL == n->child);
Line 199  print_node(const struct mdoc_node *n, int indent)
Line 200  print_node(const struct mdoc_node *n, int indent)
                 t = "text";                  t = "text";
                 break;                  break;
         case (MDOC_BODY):          case (MDOC_BODY):
                 p = mdoc_macronames[n->data.body.tok];                  p = mdoc_macronames[n->tok];
                 t = "block-body";                  t = "block-body";
                 break;                  break;
         case (MDOC_HEAD):          case (MDOC_HEAD):
                 p = mdoc_macronames[n->data.head.tok];                  p = mdoc_macronames[n->tok];
                 t = "block-head";                  t = "block-head";
                 params = n->data.head.args;  
                 sz = n->data.head.sz;  
                 break;                  break;
           case (MDOC_TAIL):
                   p = mdoc_macronames[n->tok];
                   t = "block-tail";
                   break;
         case (MDOC_ELEM):          case (MDOC_ELEM):
                 assert(NULL == n->child);                  p = mdoc_macronames[n->tok];
                 p = mdoc_macronames[n->data.elem.tok];  
                 t = "element";                  t = "element";
                 argv = n->data.elem.argv;                  argv = n->data.elem.argv;
                 argc = n->data.elem.argc;                  argc = n->data.elem.argc;
                 params = n->data.elem.args;  
                 sz = n->data.elem.sz;  
                 break;                  break;
         case (MDOC_BLOCK):          case (MDOC_BLOCK):
                 p = mdoc_macronames[n->data.block.tok];                  p = mdoc_macronames[n->tok];
                 t = "block";                  t = "block";
                 argv = n->data.block.argv;                  argv = n->data.block.argv;
                 argc = n->data.block.argc;                  argc = n->data.block.argc;
                 break;                  break;
           case (MDOC_ROOT):
                   p = "root";
                   t = "root";
                   break;
         default:          default:
                 abort();                  abort();
                 /* NOTREACHED */                  /* NOTREACHED */
Line 241  print_node(const struct mdoc_node *n, int indent)
Line 245  print_node(const struct mdoc_node *n, int indent)
         for (i = 0; i < (int)sz; i++)          for (i = 0; i < (int)sz; i++)
                 (void)printf(" \"%s\"", params[i]);                  (void)printf(" \"%s\"", params[i]);
   
         (void)printf("\n");          (void)printf(" %d:%d\n", n->line, n->pos);
   
         if (n->child)          if (n->child)
                 print_node(n->child, indent + 1);                  print_node(n->child, indent + 1);
Line 255  parse_leave(struct md_parse *p, int code)
Line 259  parse_leave(struct md_parse *p, int code)
 {  {
         const struct mdoc_node *n;          const struct mdoc_node *n;
   
         if (p->mdoc) {          if (NULL == p->mdoc)
                 if ((n = mdoc_result(p->mdoc)))                  return(code);
                         print_node(n, 0);  
                 mdoc_free(p->mdoc);          if ( ! mdoc_endparse(p->mdoc))
         }                  code = 0;
           if ((n = mdoc_result(p->mdoc)))
                   print_node(n, 0);
   
           mdoc_free(p->mdoc);
   
         return(code);          return(code);
 }  }
   
Line 303  parse_begin(struct md_parse *p)
Line 312  parse_begin(struct md_parse *p)
                         }                          }
   
                         line[(int)pos] = sv[(int)pos] = 0;                          line[(int)pos] = sv[(int)pos] = 0;
                         if ( ! mdoc_parseln(p->mdoc, line))                          if ( ! mdoc_parseln(p->mdoc, p->lnn, line))
                                 return(parse_leave(p, 0));                                  return(parse_leave(p, 0));
   
                         p->lnn++;                          p->lnn++;
Line 316  parse_begin(struct md_parse *p)
Line 325  parse_begin(struct md_parse *p)
   
   
 static int  static int
 msg_err(void *arg, int tok, int col, enum mdoc_err type)  msg_err(void *arg, int line, int col, enum mdoc_err type)
 {  {
         char             *fmt, *lit;          char             *lit;
         struct md_parse  *p;          struct md_parse  *p;
         int               i;  
   
         p = (struct md_parse *)arg;          p = (struct md_parse *)arg;
   
         fmt = lit = NULL;          lit = NULL;
   
         switch (type) {          switch (type) {
           case (ERR_SYNTAX_NOTEXT):
                   lit = "syntax: context-free text disallowed";
                   break;
         case (ERR_SYNTAX_QUOTE):          case (ERR_SYNTAX_QUOTE):
                 lit = "syntax: disallowed argument quotation";                  lit = "syntax: disallowed argument quotation";
                 break;                  break;
Line 337  msg_err(void *arg, int tok, int col, enum mdoc_err typ
Line 348  msg_err(void *arg, int tok, int col, enum mdoc_err typ
                 lit = "syntax: whitespace in argument";                  lit = "syntax: whitespace in argument";
                 break;                  break;
         case (ERR_SYNTAX_ARGFORM):          case (ERR_SYNTAX_ARGFORM):
                 fmt = "syntax: macro `%s' arguments malformed";                  lit = "syntax: macro arguments malformed";
                 break;                  break;
           case (ERR_SYNTAX_NOPUNCT):
                   lit = "syntax: macro doesn't understand punctuation";
                   break;
         case (ERR_SYNTAX_ARG):          case (ERR_SYNTAX_ARG):
                 fmt = "syntax: unknown argument for macro `%s'";                  lit = "syntax: unknown argument for macro";
                 break;                  break;
         case (ERR_SCOPE_BREAK):          case (ERR_SCOPE_BREAK):
                 /* Which scope is broken? */                  /* Which scope is broken? */
                 fmt = "scope: macro `%s' breaks prior explicit scope";                  lit = "scope: macro breaks prior explicit scope";
                 break;                  break;
         case (ERR_SCOPE_NOCTX):          case (ERR_SCOPE_NOCTX):
                 fmt = "scope: closure macro `%s' has no context";                  lit = "scope: closure macro has no context";
                 break;                  break;
         case (ERR_SCOPE_NONEST):          case (ERR_SCOPE_NONEST):
                 fmt = "scope: macro `%s' may not be nested in the current context";                  lit = "scope: macro may not be nested in the current context";
                 break;                  break;
         case (ERR_MACRO_NOTSUP):          case (ERR_MACRO_NOTSUP):
                 fmt = "macro `%s' not supported";                  lit = "macro not supported";
                 break;                  break;
         case (ERR_MACRO_NOTCALL):          case (ERR_MACRO_NOTCALL):
                 fmt = "macro `%s' not callable";                  lit = "macro not callable";
                 break;                  break;
         case (ERR_SEC_PROLOGUE):          case (ERR_SEC_PROLOGUE):
                 fmt = "macro `%s' cannot be called in the prologue";                  lit = "macro cannot be called in the prologue";
                 break;                  break;
         case (ERR_SEC_NPROLOGUE):          case (ERR_SEC_NPROLOGUE):
                 fmt = "macro `%s' called outside of prologue";                  lit = "macro called outside of prologue";
                 break;                  break;
           case (ERR_ARGS_EQ0):
                   lit = "macro expects zero arguments";
                   break;
           case (ERR_ARGS_EQ1):
                   lit = "macro expects one argument";
                   break;
         case (ERR_ARGS_GE1):          case (ERR_ARGS_GE1):
                 fmt = "macro `%s' expects one or more arguments";                  lit = "macro expects one or more arguments";
                 break;                  break;
           case (ERR_ARGS_LE2):
                   lit = "macro expects two or fewer arguments";
                   break;
           case (ERR_ARGS_LE8):
                   lit = "macro expects eight or fewer arguments";
                   break;
         case (ERR_ARGS_MANY):          case (ERR_ARGS_MANY):
                 fmt = "macro `%s' has too many arguments";                  lit = "macro has too many arguments";
                 break;                  break;
         case (ERR_SEC_PROLOGUE_OO):          case (ERR_SEC_PROLOGUE_OO):
                 fmt = "prologue macro `%s' is out-of-order";                  lit = "prologue macro is out-of-order";
                 break;                  break;
         case (ERR_SEC_PROLOGUE_REP):          case (ERR_SEC_PROLOGUE_REP):
                 fmt = "prologue macro `%s' repeated";                  lit = "prologue macro repeated";
                 break;                  break;
         case (ERR_SEC_NAME):          case (ERR_SEC_NAME):
                 lit = "`NAME' section must be first";                  lit = "`NAME' section must be first";
Line 383  msg_err(void *arg, int tok, int col, enum mdoc_err typ
Line 409  msg_err(void *arg, int tok, int col, enum mdoc_err typ
                 lit = "syntax: expected value for macro argument";                  lit = "syntax: expected value for macro argument";
                 break;                  break;
         case (ERR_SYNTAX_ARGBAD):          case (ERR_SYNTAX_ARGBAD):
                 lit = "syntax: invalid value for macro argument";                  lit = "syntax: invalid value(s) for macro argument";
                 break;                  break;
           case (ERR_SYNTAX_ARGMISS):
                   lit = "syntax: missing required argument(s) for macro";
                   break;
         case (ERR_SYNTAX_ARGMANY):          case (ERR_SYNTAX_ARGMANY):
                 lit = "syntax: too many values for macro argument";                  lit = "syntax: too many values for macro argument";
                 break;                  break;
           case (ERR_SYNTAX_CHILDBAD):
                   lit = "syntax: invalid child for parent macro";
                   break;
           case (ERR_SYNTAX_PARENTBAD):
                   lit = "syntax: invalid parent for macro";
                   break;
           case (ERR_SYNTAX_CHILDHEAD):
                   lit = "syntax: expected only block-header section";
                   break;
           case (ERR_SYNTAX_CHILDBODY):
                   lit = "syntax: expected only a block-body section";
                   break;
           case (ERR_SYNTAX_EMPTYHEAD):
                   lit = "syntax: block-header section may not be empty";
                   break;
           case (ERR_SYNTAX_EMPTYBODY):
                   lit = "syntax: block-body section may not be empty";
                   break;
         default:          default:
                 abort();                  abort();
                 /* NOTREACHED */                  /* NOTREACHED */
         }          }
   
         if (fmt) {          (void)fprintf(stderr, "%s:%d: error: %s (column %d)\n",
                 (void)fprintf(stderr, "%s:%d: error: ",                          p->name, line, lit, col);
                                 p->name, p->lnn);  
                 (void)fprintf(stderr, fmt, mdoc_macronames[tok]);  
         } else  
                 (void)fprintf(stderr, "%s:%d: error: %s",  
                                 p->name, p->lnn, lit);  
   
         if (p->dbg < 1) {  
                 if (-1 != col)  
                         (void)fprintf(stderr, " (column %d)\n", col);  
                 return(0);  
         } else if (-1 == col) {  
                 (void)fprintf(stderr, "\nFrom: %s", p->line);  
                 return(0);  
         }  
   
         (void)fprintf(stderr, "\nFrom: %s\n      ", p->line);  
         for (i = 0; i < col; i++)  
                 (void)fprintf(stderr, " ");  
         (void)fprintf(stderr, "^\n");  
   
         return(0);          return(0);
 }  }
   
   
 static void  static void
 msg_msg(void *arg, int col, const char *msg)  msg_msg(void *arg, int line, int col, const char *msg)
 {  {
         struct md_parse  *p;          struct md_parse  *p;
         int               i;  
   
         p = (struct md_parse *)arg;          p = (struct md_parse *)arg;
   
         if (p->dbg < 2)          if (p->dbg < 2)
                 return;                  return;
   
         (void)printf("%s:%d: %s", p->name, p->lnn, msg);          (void)printf("%s:%d: %s (column %d)\n",
                           p->name, line, msg, col);
         if (p->dbg < 3) {  
                 if (-1 != col)  
                         (void)printf(" (column %d)\n", col);  
                 return;  
         } else if (-1 == col) {  
                 (void)printf("\nFrom %s\n", p->line);  
                 return;  
         }  
   
         (void)printf("\nFrom: %s\n      ", p->line);  
         for (i = 0; i < col; i++)  
                 (void)printf(" ");  
         (void)printf("^\n");  
 }  }
   
   
 static int  static int
 msg_warn(void *arg, int tok, int col, enum mdoc_warn type)  msg_warn(void *arg, int line, int col, enum mdoc_warn type)
 {  {
         char             *fmt, *lit;          char             *lit;
         struct md_parse  *p;          struct md_parse  *p;
         int               i;  
         extern char      *__progname;          extern char      *__progname;
   
         p = (struct md_parse *)arg;          p = (struct md_parse *)arg;
Line 461  msg_warn(void *arg, int tok, int col, enum mdoc_warn t
Line 473  msg_warn(void *arg, int tok, int col, enum mdoc_warn t
         if ( ! (p->warn & MD_WARN_ALL))          if ( ! (p->warn & MD_WARN_ALL))
                 return(1);                  return(1);
   
         fmt = lit = NULL;          lit = NULL;
   
         switch (type) {          switch (type) {
         case (WARN_SYNTAX_WS_EOLN):          case (WARN_SYNTAX_WS_EOLN):
Line 476  msg_warn(void *arg, int tok, int col, enum mdoc_warn t
Line 488  msg_warn(void *arg, int tok, int col, enum mdoc_warn t
         case (WARN_SYNTAX_ARGLIKE):          case (WARN_SYNTAX_ARGLIKE):
                 lit = "syntax: argument-like value";                  lit = "syntax: argument-like value";
                 break;                  break;
           case (WARN_SYNTAX_EMPTYBODY):
                   lit = "syntax: macro suggests non-empty block-body section";
                   break;
           case (WARN_SYNTAX_EMPTYHEAD):
                   lit = "syntax: macro suggests non-empty block-head section";
                   break;
           case (WARN_SYNTAX_NOBODY):
                   lit = "syntax: macro suggests empty block-body section";
                   break;
         case (WARN_SEC_OO):          case (WARN_SEC_OO):
                 lit = "section is out of conventional order";                  lit = "section is out of conventional order";
                 break;                  break;
           case (WARN_SEC_REP):
                   lit = "section repeated";
                   break;
         case (WARN_ARGS_GE1):          case (WARN_ARGS_GE1):
                 fmt = "macro `%s' suggests one or more arguments";                  lit = "macro suggests one or more arguments";
                 break;                  break;
         case (WARN_ARGS_EQ0):          case (WARN_ARGS_EQ0):
                 fmt = "macro `%s' suggests zero arguments";                  lit = "macro suggests zero arguments";
                 break;                  break;
         case (WARN_IGN_AFTER_BLK):          case (WARN_IGN_AFTER_BLK):
                 fmt = "ignore: macro `%s' ignored after block macro";                  lit = "ignore: macro ignored after block macro";
                 break;                  break;
           case (WARN_IGN_OBSOLETE):
                   lit = "ignore: macro is obsolete";
                   break;
         case (WARN_IGN_BEFORE_BLK):          case (WARN_IGN_BEFORE_BLK):
                 fmt = "ignore: macro before block macro `%s' ignored";                  lit = "ignore: macro before block macro ignored";
                 break;                  break;
           case (WARN_COMPAT_TROFF):
                   lit = "compat: macro behaves differently in troff and nroff";
                   break;
         default:          default:
                 abort();                  abort();
                 /* NOTREACHED */                  /* NOTREACHED */
         }          }
   
         if (fmt) {  
                 (void)fprintf(stderr, "%s:%d: warning: ",  
                                 p->name, p->lnn);  
                 (void)fprintf(stderr, fmt, mdoc_macronames[tok]);  
         } else  
                 (void)fprintf(stderr, "%s:%d: warning: %s",  
                                 p->name, p->lnn, lit);  
   
         if (p->dbg >= 1) {          (void)fprintf(stderr, "%s:%d: warning: %s (column %d)\n",
                 (void)fprintf(stderr, "\nFrom: %s\n      ", p->line);                          p->name, line, lit, col);
                 for (i = 0; i < col; i++)  
                         (void)fprintf(stderr, " ");  
                 (void)fprintf(stderr, "^\n");  
         } else  
                 (void)fprintf(stderr, " (column %d)\n", col);  
   
         if (p->warn & MD_WARN_ERR) {          if (p->warn & MD_WARN_ERR) {
                 (void)fprintf(stderr, "%s: considering warnings as "                  (void)fprintf(stderr, "%s: considering warnings as "

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.40

CVSweb