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

Diff for /mandoc/mdoc_macro.c between version 1.227 and 1.231

version 1.227, 2018/12/14 05:18:02 version 1.231, 2019/01/01 07:42:04
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2010, 2012-2019 Ingo Schwarze <schwarze@openbsd.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 49  static void  dword(struct roff_man *, int, int, const 
Line 49  static void  dword(struct roff_man *, int, int, const 
 static  int             find_pending(struct roff_man *, enum roff_tok,  static  int             find_pending(struct roff_man *, enum roff_tok,
                                 int, int, struct roff_node *);                                  int, int, struct roff_node *);
 static  int             lookup(struct roff_man *, int, int, int, const char *);  static  int             lookup(struct roff_man *, int, int, int, const char *);
 static  int             macro_or_word(MACRO_PROT_ARGS, int);  static  int             macro_or_word(MACRO_PROT_ARGS, char *, int);
 static  void            break_intermediate(struct roff_node *,  static  void            break_intermediate(struct roff_node *,
                                 struct roff_node *);                                  struct roff_node *);
 static  int             parse_rest(struct roff_man *, enum roff_tok,  static  int             parse_rest(struct roff_man *, enum roff_tok,
Line 233  mdoc_endparse(struct roff_man *mdoc)
Line 233  mdoc_endparse(struct roff_man *mdoc)
   
         /* Rewind to the first. */          /* Rewind to the first. */
   
         rew_last(mdoc, mdoc->first);          rew_last(mdoc, mdoc->meta.first);
         mdoc_state_reset(mdoc);  
 }  }
   
 /*  /*
Line 474  append_delims(struct roff_man *mdoc, int line, int *po
Line 473  append_delims(struct roff_man *mdoc, int line, int *po
 {  {
         char            *p;          char            *p;
         int              la;          int              la;
           enum margserr    ac;
   
         if (buf[*pos] == '\0')          if (buf[*pos] == '\0')
                 return;                  return;
   
         for (;;) {          for (;;) {
                 la = *pos;                  la = *pos;
                 if (mdoc_args(mdoc, line, pos, buf, TOKEN_NONE, &p) ==                  ac = mdoc_args(mdoc, line, pos, buf, TOKEN_NONE, &p);
                     ARGS_EOLN)                  if (ac == ARGS_EOLN)
                         break;                          break;
                 dword(mdoc, line, la, p, DELIM_MAX, 1);                  dword(mdoc, line, la, p, DELIM_MAX, 1);
   
Line 499  append_delims(struct roff_man *mdoc, int line, int *po
Line 499  append_delims(struct roff_man *mdoc, int line, int *po
   
                 if (mandoc_eos(p, strlen(p)))                  if (mandoc_eos(p, strlen(p)))
                         mdoc->last->flags |= NODE_EOS;                          mdoc->last->flags |= NODE_EOS;
                   if (ac == ARGS_ALLOC)
                           free(p);
         }          }
 }  }
   
Line 508  append_delims(struct roff_man *mdoc, int line, int *po
Line 510  append_delims(struct roff_man *mdoc, int line, int *po
  * Otherwise, allocate it and return 0.   * Otherwise, allocate it and return 0.
  */   */
 static int  static int
 macro_or_word(MACRO_PROT_ARGS, int parsed)  macro_or_word(MACRO_PROT_ARGS, char *p, int parsed)
 {  {
         char            *p;  
         int              ntok;          int              ntok;
   
         p = buf + ppos;          ntok = buf[ppos] == '"' || parsed == 0 ||
         ntok = TOKEN_NONE;              mdoc->flags & MDOC_PHRASELIT ? TOKEN_NONE :
         if (*p == '"')              lookup(mdoc, tok, line, ppos, p);
                 p++;  
         else if (parsed && ! (mdoc->flags & MDOC_PHRASELIT))  
                 ntok = lookup(mdoc, tok, line, ppos, p);  
   
         if (ntok == TOKEN_NONE) {          if (ntok == TOKEN_NONE) {
                 dword(mdoc, line, ppos, p, DELIM_MAX, tok == TOKEN_NONE ||                  dword(mdoc, line, ppos, p, DELIM_MAX, tok == TOKEN_NONE ||
Line 698  blk_exp_close(MACRO_PROT_ARGS)
Line 696  blk_exp_close(MACRO_PROT_ARGS)
                             "%s %s", roff_name[tok], buf + *pos);                              "%s %s", roff_name[tok], buf + *pos);
                 if (endbody == NULL && n != NULL)                  if (endbody == NULL && n != NULL)
                         rew_pending(mdoc, n);                          rew_pending(mdoc, n);
   
                   /*
                    * Restore the fill mode that was set before the display.
                    * This needs to be done here rather than during validation
                    * such that subsequent nodes get the right flags.
                    */
   
                   if (tok == MDOC_Ed && body != NULL) {
                           if (body->flags & NODE_NOFILL)
                                   mdoc->flags |= ROFF_NOFILL;
                           else
                                   mdoc->flags &= ~ROFF_NOFILL;
                   }
                 return;                  return;
         }          }
   
Line 720  blk_exp_close(MACRO_PROT_ARGS)
Line 731  blk_exp_close(MACRO_PROT_ARGS)
                 if (ntok == TOKEN_NONE) {                  if (ntok == TOKEN_NONE) {
                         dword(mdoc, line, lastarg, p, DELIM_MAX,                          dword(mdoc, line, lastarg, p, DELIM_MAX,
                             mdoc_macro(tok)->flags & MDOC_JOIN);                              mdoc_macro(tok)->flags & MDOC_JOIN);
                           if (ac == ARGS_ALLOC)
                                   free(p);
                         continue;                          continue;
                 }                  }
                   if (ac == ARGS_ALLOC)
                           free(p);
   
                 if (n != NULL)                  if (n != NULL)
                         rew_last(mdoc, n);                          rew_last(mdoc, n);
Line 836  in_line(MACRO_PROT_ARGS)
Line 851  in_line(MACRO_PROT_ARGS)
                             line, la, pos, buf);                              line, la, pos, buf);
                         if (nl)                          if (nl)
                                 append_delims(mdoc, line, pos, buf);                                  append_delims(mdoc, line, pos, buf);
                           if (ac == ARGS_ALLOC)
                                   free(p);
                         return;                          return;
                 }                  }
   
Line 879  in_line(MACRO_PROT_ARGS)
Line 896  in_line(MACRO_PROT_ARGS)
                 dword(mdoc, line, la, p, d,                  dword(mdoc, line, la, p, d,
                     mdoc_macro(tok)->flags & MDOC_JOIN);                      mdoc_macro(tok)->flags & MDOC_JOIN);
   
                   if (ac == ARGS_ALLOC)
                           free(p);
   
                 /*                  /*
                  * If the first argument is a closing delimiter,                   * If the first argument is a closing delimiter,
                  * do not suppress spacing before it.                   * do not suppress spacing before it.
Line 929  in_line(MACRO_PROT_ARGS)
Line 949  in_line(MACRO_PROT_ARGS)
 static void  static void
 blk_full(MACRO_PROT_ARGS)  blk_full(MACRO_PROT_ARGS)
 {  {
         int               la, nl, parsed;  
         struct mdoc_arg  *arg;          struct mdoc_arg  *arg;
         struct roff_node *blk; /* Our own or a broken block. */          struct roff_node *blk; /* Our own or a broken block. */
         struct roff_node *head; /* Our own head. */          struct roff_node *head; /* Our own head. */
         struct roff_node *body; /* Our own body. */          struct roff_node *body; /* Our own body. */
         struct roff_node *n;          struct roff_node *n;
         enum margserr     ac, lac;  
         char             *p;          char             *p;
           size_t            iarg;
           int               done, la, nl, parsed;
           enum margserr     ac, lac;
   
         nl = MDOC_NEWLINE & mdoc->flags;          nl = MDOC_NEWLINE & mdoc->flags;
   
Line 1032  blk_full(MACRO_PROT_ARGS)
Line 1053  blk_full(MACRO_PROT_ARGS)
          * regular child nodes.           * regular child nodes.
          */           */
   
           if (tok == MDOC_Sh)
                   mdoc->flags &= ~ROFF_NOFILL;
   
         mdoc_argv(mdoc, line, tok, &arg, pos, buf);          mdoc_argv(mdoc, line, tok, &arg, pos, buf);
         blk = mdoc_block_alloc(mdoc, line, ppos, tok, arg);          blk = mdoc_block_alloc(mdoc, line, ppos, tok, arg);
         head = body = NULL;          head = body = NULL;
Line 1095  blk_full(MACRO_PROT_ARGS)
Line 1119  blk_full(MACRO_PROT_ARGS)
                 if (tok == MDOC_Bd || tok == MDOC_Bk) {                  if (tok == MDOC_Bd || tok == MDOC_Bk) {
                         mandoc_msg(MANDOCERR_ARG_EXCESS, line, la,                          mandoc_msg(MANDOCERR_ARG_EXCESS, line, la,
                             "%s ... %s", roff_name[tok], buf + la);                              "%s ... %s", roff_name[tok], buf + la);
                           if (ac == ARGS_ALLOC)
                                   free(p);
                         break;                          break;
                 }                  }
                 if (tok == MDOC_Rs) {                  if (tok == MDOC_Rs) {
                         mandoc_msg(MANDOCERR_ARG_SKIP,                          mandoc_msg(MANDOCERR_ARG_SKIP,
                             line, la, "Rs %s", buf + la);                              line, la, "Rs %s", buf + la);
                           if (ac == ARGS_ALLOC)
                                   free(p);
                         break;                          break;
                 }                  }
                 if (ac == ARGS_PUNCT)                  if (ac == ARGS_PUNCT)
Line 1114  blk_full(MACRO_PROT_ARGS)
Line 1142  blk_full(MACRO_PROT_ARGS)
                     ac != ARGS_PHRASE &&                      ac != ARGS_PHRASE &&
                     mdoc_isdelim(p) == DELIM_OPEN) {                      mdoc_isdelim(p) == DELIM_OPEN) {
                         dword(mdoc, line, la, p, DELIM_OPEN, 0);                          dword(mdoc, line, la, p, DELIM_OPEN, 0);
                           if (ac == ARGS_ALLOC)
                                   free(p);
                         continue;                          continue;
                 }                  }
   
Line 1145  blk_full(MACRO_PROT_ARGS)
Line 1175  blk_full(MACRO_PROT_ARGS)
                         continue;                          continue;
                 }                  }
   
                 if (macro_or_word(mdoc, tok, line, la, pos, buf, parsed))                  done = macro_or_word(mdoc, tok, line, la, pos, buf, p, parsed);
                   if (ac == ARGS_ALLOC)
                           free(p);
                   if (done)
                         break;                          break;
         }          }
   
Line 1164  blk_full(MACRO_PROT_ARGS)
Line 1197  blk_full(MACRO_PROT_ARGS)
   
         rew_last(mdoc, head);          rew_last(mdoc, head);
         body = roff_body_alloc(mdoc, line, ppos, tok);          body = roff_body_alloc(mdoc, line, ppos, tok);
   
           /*
            * Set up fill mode for display blocks.
            * This needs to be done here up front rather than during
            * validation such that child nodes get the right flags.
            */
   
           if (tok == MDOC_Bd && arg != NULL) {
                   for (iarg = 0; iarg < arg->argc; iarg++) {
                           switch (arg->argv[iarg].arg) {
                           case MDOC_Unfilled:
                           case MDOC_Literal:
                                   mdoc->flags |= ROFF_NOFILL;
                                   break;
                           case MDOC_Filled:
                           case MDOC_Ragged:
                           case MDOC_Centred:
                                   mdoc->flags &= ~ROFF_NOFILL;
                                   break;
                           default:
                                   continue;
                           }
                           break;
                   }
           }
 out:  out:
         if (mdoc->flags & MDOC_FREECOL) {          if (mdoc->flags & MDOC_FREECOL) {
                 rew_last(mdoc, body);                  rew_last(mdoc, body);
Line 1175  out:
Line 1233  out:
 static void  static void
 blk_part_imp(MACRO_PROT_ARGS)  blk_part_imp(MACRO_PROT_ARGS)
 {  {
         int               la, nl;          int               done, la, nl;
         enum margserr     ac;          enum margserr     ac;
         char             *p;          char             *p;
         struct roff_node *blk; /* saved block context */          struct roff_node *blk; /* saved block context */
Line 1210  blk_part_imp(MACRO_PROT_ARGS)
Line 1268  blk_part_imp(MACRO_PROT_ARGS)
   
                 if (body == NULL && mdoc_isdelim(p) == DELIM_OPEN) {                  if (body == NULL && mdoc_isdelim(p) == DELIM_OPEN) {
                         dword(mdoc, line, la, p, DELIM_OPEN, 0);                          dword(mdoc, line, la, p, DELIM_OPEN, 0);
                           if (ac == ARGS_ALLOC)
                                   free(p);
                         continue;                          continue;
                 }                  }
   
                 if (body == NULL)                  if (body == NULL)
                         body = roff_body_alloc(mdoc, line, ppos, tok);                          body = roff_body_alloc(mdoc, line, ppos, tok);
   
                 if (macro_or_word(mdoc, tok, line, la, pos, buf, 1))                  done = macro_or_word(mdoc, tok, line, la, pos, buf, p, 1);
                   if (ac == ARGS_ALLOC)
                           free(p);
                   if (done)
                         break;                          break;
         }          }
         if (body == NULL)          if (body == NULL)
Line 1241  blk_part_imp(MACRO_PROT_ARGS)
Line 1304  blk_part_imp(MACRO_PROT_ARGS)
 static void  static void
 blk_part_exp(MACRO_PROT_ARGS)  blk_part_exp(MACRO_PROT_ARGS)
 {  {
         int               la, nl;          int               done, la, nl;
         enum margserr     ac;          enum margserr     ac;
         struct roff_node *head; /* keep track of head */          struct roff_node *head; /* keep track of head */
         char             *p;          char             *p;
Line 1266  blk_part_exp(MACRO_PROT_ARGS)
Line 1329  blk_part_exp(MACRO_PROT_ARGS)
   
                 if (head == NULL && mdoc_isdelim(p) == DELIM_OPEN) {                  if (head == NULL && mdoc_isdelim(p) == DELIM_OPEN) {
                         dword(mdoc, line, la, p, DELIM_OPEN, 0);                          dword(mdoc, line, la, p, DELIM_OPEN, 0);
                           if (ac == ARGS_ALLOC)
                                   free(p);
                         continue;                          continue;
                 }                  }
   
Line 1275  blk_part_exp(MACRO_PROT_ARGS)
Line 1340  blk_part_exp(MACRO_PROT_ARGS)
                                 dword(mdoc, line, la, p, DELIM_MAX, 0);                                  dword(mdoc, line, la, p, DELIM_MAX, 0);
                         rew_last(mdoc, head);                          rew_last(mdoc, head);
                         roff_body_alloc(mdoc, line, ppos, tok);                          roff_body_alloc(mdoc, line, ppos, tok);
                         if (tok == MDOC_Eo)                          if (tok == MDOC_Eo) {
                                   if (ac == ARGS_ALLOC)
                                           free(p);
                                 continue;                                  continue;
                           }
                 }                  }
   
                 if (macro_or_word(mdoc, tok, line, la, pos, buf, 1))                  done = macro_or_word(mdoc, tok, line, la, pos, buf, p, 1);
                   if (ac == ARGS_ALLOC)
                           free(p);
                   if (done)
                         break;                          break;
         }          }
   
Line 1337  in_line_argn(MACRO_PROT_ARGS)
Line 1408  in_line_argn(MACRO_PROT_ARGS)
                 la = *pos;                  la = *pos;
                 ac = mdoc_args(mdoc, line, pos, buf, tok, &p);                  ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
   
                 if (ac == ARGS_WORD && state == -1 &&                  if ((ac == ARGS_WORD || ac == ARGS_ALLOC) && state == -1 &&
                     (mdoc_macro(tok)->flags & MDOC_IGNDELIM) == 0 &&                      (mdoc_macro(tok)->flags & MDOC_IGNDELIM) == 0 &&
                     mdoc_isdelim(p) == DELIM_OPEN) {                      mdoc_isdelim(p) == DELIM_OPEN) {
                         dword(mdoc, line, la, p, DELIM_OPEN, 0);                          dword(mdoc, line, la, p, DELIM_OPEN, 0);
                           if (ac == ARGS_ALLOC)
                                   free(p);
                         continue;                          continue;
                 }                  }
   
Line 1373  in_line_argn(MACRO_PROT_ARGS)
Line 1446  in_line_argn(MACRO_PROT_ARGS)
                         }                          }
                         (*mdoc_macro(ntok)->fp)(mdoc, ntok,                          (*mdoc_macro(ntok)->fp)(mdoc, ntok,
                             line, la, pos, buf);                              line, la, pos, buf);
                           if (ac == ARGS_ALLOC)
                                   free(p);
                         break;                          break;
                 }                  }
   
Line 1390  in_line_argn(MACRO_PROT_ARGS)
Line 1465  in_line_argn(MACRO_PROT_ARGS)
   
                 dword(mdoc, line, la, p, DELIM_MAX,                  dword(mdoc, line, la, p, DELIM_MAX,
                     mdoc_macro(tok)->flags & MDOC_JOIN);                      mdoc_macro(tok)->flags & MDOC_JOIN);
                   if (ac == ARGS_ALLOC)
                           free(p);
                   p = mdoc->last->string;
         }          }
   
         if (state == -1) {          if (state == -1) {
Line 1444  static int
Line 1522  static int
 parse_rest(struct roff_man *mdoc, enum roff_tok tok,  parse_rest(struct roff_man *mdoc, enum roff_tok tok,
     int line, int *pos, char *buf)      int line, int *pos, char *buf)
 {  {
         int              la;          char            *p;
           int              done, la;
           enum margserr    ac;
   
         for (;;) {          for (;;) {
                 la = *pos;                  la = *pos;
                 if (mdoc_args(mdoc, line, pos, buf, tok, NULL) == ARGS_EOLN)                  ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
                   if (ac == ARGS_EOLN)
                         return 0;                          return 0;
                 if (macro_or_word(mdoc, tok, line, la, pos, buf, 1))                  done = macro_or_word(mdoc, tok, line, la, pos, buf, p, 1);
                   if (ac == ARGS_ALLOC)
                           free(p);
                   if (done)
                         return 1;                          return 1;
         }          }
 }  }

Legend:
Removed from v.1.227  
changed lines
  Added in v.1.231

CVSweb