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

Diff for /mandoc/mdoc.c between version 1.49 and 1.52

version 1.49, 2009/03/01 23:14:15 version 1.52, 2009/03/06 14:13:47
Line 74  const char *const __mdoc_macronames[MDOC_MAX] = {   
Line 74  const char *const __mdoc_macronames[MDOC_MAX] = {   
         "Tn",           "Ux",           "Xc",           "Xo",          "Tn",           "Ux",           "Xc",           "Xo",
         "Fo",           "Fc",           "Oo",           "Oc",          "Fo",           "Fc",           "Oo",           "Oc",
         "Bk",           "Ek",           "Bt",           "Hf",          "Bk",           "Ek",           "Bt",           "Hf",
         "Fr",           "Ud",          "Fr",           "Ud",           "Lb",
         };          };
   
 const   char *const __mdoc_argnames[MDOC_ARG_MAX] = {  const   char *const __mdoc_argnames[MDOC_ARG_MAX] = {
Line 85  const char *const __mdoc_argnames[MDOC_ARG_MAX] = {   
Line 85  const char *const __mdoc_argnames[MDOC_ARG_MAX] = {   
         "tag",                  "diag",                 "hang",          "tag",                  "diag",                 "hang",
         "ohang",                "inset",                "column",          "ohang",                "inset",                "column",
         "width",                "compact",              "std",          "width",                "compact",              "std",
         "p1003.1-88",           "p1003.1-90",           "p1003.1-96",          "filled",               "words",                "emphasis",
         "p1003.1-2001",         "p1003.1-2004",         "p1003.1",          "symbolic"
         "p1003.1b",             "p1003.1b-93",          "p1003.1c-95",  
         "p1003.1g-2000",        "p1003.2-92",           "p1387.2-95",  
         "p1003.2",              "p1387.2",              "isoC-90",  
         "isoC-amd1",            "isoC-tcor1",           "isoC-tcor2",  
         "isoC-99",              "ansiC",                "ansiC-89",  
         "ansiC-99",             "ieee754",              "iso8802-3",  
         "xpg3",                 "xpg4",                 "xpg4.2",  
         "xpg4.3",               "xbd5",                 "xcu5",  
         "xsh5",                 "xns5",                 "xns5.2d2.0",  
         "xcurses4.2",           "susv2",                "susv3",  
         "svid4",                "filled",               "words",  
         "emphasis",             "symbolic",  
         };          };
   
 const   char * const *mdoc_macronames = __mdoc_macronames;  const   char * const *mdoc_macronames = __mdoc_macronames;
Line 135  mdoc_free(struct mdoc *mdoc)
Line 123  mdoc_free(struct mdoc *mdoc)
                 free(mdoc->meta.os);                  free(mdoc->meta.os);
         if (mdoc->meta.name)          if (mdoc->meta.name)
                 free(mdoc->meta.name);                  free(mdoc->meta.name);
           if (mdoc->meta.arch)
                   free(mdoc->meta.arch);
           if (mdoc->meta.vol)
                   free(mdoc->meta.vol);
   
         free(mdoc);          free(mdoc);
 }  }
Line 180  mdoc_endparse(struct mdoc *mdoc)
Line 172  mdoc_endparse(struct mdoc *mdoc)
 }  }
   
   
   /*
    * Main line-parsing routine.  If the line is a macro-line (started with
    * a '.' control character), then pass along to the parser, which parses
    * subsequent macros until the end of line.  If normal text, simply
    * append the entire line to the chain.
    */
 int  int
 mdoc_parseln(struct mdoc *mdoc, int line, char *buf)  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
 {  {
Line 191  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
Line 189  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
   
         mdoc->linetok = 0;          mdoc->linetok = 0;
   
         /*  
          * FIXME: should puke on whitespace in non-literal displays.  
          */  
   
         if ('.' != *buf) {          if ('.' != *buf) {
                   /*
                    * Free-form text.  Not allowed in the prologue.
                    */
                 if (SEC_PROLOGUE == mdoc->lastnamed)                  if (SEC_PROLOGUE == mdoc->lastnamed)
                         return(mdoc_perr(mdoc, line, 0,                          return(mdoc_perr(mdoc, line, 0,
                                 "no text in document prologue"));                                          "no text in prologue"));
   
                 if ( ! mdoc_word_alloc(mdoc, line, 0, buf))                  if ( ! mdoc_word_alloc(mdoc, line, 0, buf))
                         return(0);                          return(0);
                 mdoc->next = MDOC_NEXT_SIBLING;                  mdoc->next = MDOC_NEXT_SIBLING;
                 return(1);                  return(1);
         }          }
   
           /*
            * Control-character detected.  Begin the parsing sequence.
            */
   
         if (buf[1] && '\\' == buf[1])          if (buf[1] && '\\' == buf[1])
                 if (buf[2] && '\"' == buf[2])                  if (buf[2] && '\"' == buf[2])
                         return(1);                          return(1);
   
         i = 1;          i = 1;
         while (buf[i] && ! isspace((int)buf[i]) && i < (int)sizeof(tmp))          while (buf[i] && ! isspace((u_char)buf[i]) &&
                           i < (int)sizeof(tmp))
                 i++;                  i++;
   
         if (i == (int)sizeof(tmp)) {          if (i == (int)sizeof(tmp)) {
Line 231  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
Line 234  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
                 return(mdoc_perr(mdoc, line, 1, "unknown macro"));                  return(mdoc_perr(mdoc, line, 1, "unknown macro"));
         }          }
   
         while (buf[i] && isspace((int)buf[i]))          while (buf[i] && isspace((u_char)buf[i]))
                 i++;                  i++;
   
         if ( ! mdoc_macro(mdoc, c, line, 1, &i, buf)) {          if ( ! mdoc_macro(mdoc, c, line, 1, &i, buf)) {
                 mdoc->flags |= MDOC_HALT;                  mdoc->flags |= MDOC_HALT;
                 return(0);                  return(0);
         }          }
   
         return(1);          return(1);
 }  }
   
Line 314  mdoc_macro(struct mdoc *mdoc, int tok, 
Line 318  mdoc_macro(struct mdoc *mdoc, int tok, 
 static int  static int
 mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *p)  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *p)
 {  {
         const char       *nn, *nt, *on, *ot, *act;  
   
         assert(mdoc->last);          assert(mdoc->last);
         assert(mdoc->first);          assert(mdoc->first);
Line 341  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
Line 344  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
                                         MDOC_LINEARG_SOFTMAX, mdoc->linetok))                                          MDOC_LINEARG_SOFTMAX, mdoc->linetok))
                         return(0);                          return(0);
   
         if (MDOC_TEXT == mdoc->last->type)  
                 on = "<text>";  
         else if (MDOC_ROOT == mdoc->last->type)  
                 on = "<root>";  
         else  
                 on = mdoc_macronames[mdoc->last->tok];  
   
         if (MDOC_TEXT == p->type)  
                 nn = "<text>";  
         else if (MDOC_ROOT == p->type)  
                 nn = "<root>";  
         else  
                 nn = mdoc_macronames[p->tok];  
   
         ot = mdoc_type2a(mdoc->last->type);  
         nt = mdoc_type2a(p->type);  
   
         switch (mdoc->next) {          switch (mdoc->next) {
         case (MDOC_NEXT_SIBLING):          case (MDOC_NEXT_SIBLING):
                 mdoc->last->next = p;                  mdoc->last->next = p;
                 p->prev = mdoc->last;                  p->prev = mdoc->last;
                 p->parent = mdoc->last->parent;                  p->parent = mdoc->last->parent;
                 act = "sibling";  
                 break;                  break;
         case (MDOC_NEXT_CHILD):          case (MDOC_NEXT_CHILD):
                 mdoc->last->child = p;                  mdoc->last->child = p;
                 p->parent = mdoc->last;                  p->parent = mdoc->last;
                 act = "child";  
                 break;                  break;
         default:          default:
                 abort();                  abort();
Line 396  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
Line 380  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
         }          }
   
         mdoc->last = p;          mdoc->last = p;
         mdoc_msg(mdoc, "parse: %s `%s' %s of %s `%s'",  
                         nt, nn, act, ot, on);  
         return(1);          return(1);
 }  }
   
Line 660  argdup(size_t argsz, const struct mdoc_arg *args)
Line 642  argdup(size_t argsz, const struct mdoc_arg *args)
   
         return(pp);          return(pp);
 }  }
   
   
 /* FIXME: deprecate. */  
 char *  
 mdoc_node2a(struct mdoc_node *node)  
 {  
         static char      buf[64];  
   
         assert(node);  
   
         buf[0] = 0;  
         (void)xstrlcat(buf, mdoc_type2a(node->type), 64);  
         if (MDOC_ROOT == node->type)  
                 return(buf);  
         (void)xstrlcat(buf, " `", 64);  
         if (MDOC_TEXT == node->type)  
                 (void)xstrlcat(buf, node->data.text.string, 64);  
         else  
                 (void)xstrlcat(buf, mdoc_macronames[node->tok], 64);  
         (void)xstrlcat(buf, "'", 64);  
   
         return(buf);  
 }  
   
   

Legend:
Removed from v.1.49  
changed lines
  Added in v.1.52

CVSweb