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

Diff for /mandoc/Attic/mlg.c between version 1.8 and 1.11

version 1.8, 2008/12/04 23:10:51 version 1.11, 2008/12/05 19:45:15
Line 51  struct md_mlg {
Line 51  struct md_mlg {
         size_t            pos;          size_t            pos;
         enum md_tok       last;          enum md_tok       last;
         void             *arg;          void             *arg;
         ml_begintag       begintag;          struct ml_cbs     cbs;
         ml_endtag         endtag;  
         ml_begin          begin;  
         ml_end            end;  
         int               flags;          int               flags;
 #define ML_OVERRIDE_ONE  (1 << 0)  #define ML_OVERRIDE_ONE  (1 << 0)
 #define ML_OVERRIDE_ALL  (1 << 1)  #define ML_OVERRIDE_ALL  (1 << 1)
           void             *data;
 };  };
   
   
Line 82  static int   mlg_roffblkbodyin(void *, int, 
Line 80  static int   mlg_roffblkbodyin(void *, int, 
                                 int *, char **);                                  int *, char **);
 static  int              mlg_roffblkbodyout(void *, int);  static  int              mlg_roffblkbodyout(void *, int);
   
 static  int              mlg_endblk(struct md_mlg *, enum md_ns, int);  
 static  int              mlg_begintag(struct md_mlg *, enum md_ns,  static  int              mlg_begintag(struct md_mlg *, enum md_ns,
                                 int, int *, char **);                                  int, int *, char **);
 static  int              mlg_endtag(struct md_mlg *, enum md_ns, int);  static  int              mlg_endtag(struct md_mlg *, enum md_ns, int);
Line 105  extern size_t   strlcpy(char *, const char *, size_t);
Line 102  extern size_t   strlcpy(char *, const char *, size_t);
   
   
 static int  static int
 mlg_endblk(struct md_mlg *p, enum md_ns ns, int tok)  
 {  
   
         p->indent--;  
   
         if (0 != p->pos) {  
                 if ( ! mlg_newline(p))  
                         return(0);  
                 if ( ! mlg_indent(p))  
                         return(0);  
         } else if ( ! mlg_indent(p))  
                 return(0);  
   
         mlg_mode(p, MD_BLK_OUT);  
         if ( ! mlg_endtag(p, ns, tok))  
                 return(0);  
         return(mlg_newline(p));  
 }  
   
   
 static int  
 mlg_begintag(struct md_mlg *p, enum md_ns ns, int tok,  mlg_begintag(struct md_mlg *p, enum md_ns ns, int tok,
                 int *argc, char **argv)                  int *argc, char **argv)
 {  {
Line 137  mlg_begintag(struct md_mlg *p, enum md_ns ns, int tok,
Line 113  mlg_begintag(struct md_mlg *p, enum md_ns ns, int tok,
         case (MD_NS_INLINE):          case (MD_NS_INLINE):
                 if ( ! (ML_OVERRIDE_ONE & p->flags) &&                  if ( ! (ML_OVERRIDE_ONE & p->flags) &&
                                 ! (ML_OVERRIDE_ALL & p->flags) &&                                  ! (ML_OVERRIDE_ALL & p->flags) &&
                                 p->pos + 11 > COLUMNS)                                  p->pos + 11 >= COLUMNS)
                         if ( ! mlg_newline(p))                          if ( ! mlg_newline(p))
                                 return(0);                                  return(0);
                 if (0 != p->pos && (MD_TEXT == p->last ||                  if (0 != p->pos && (MD_TEXT == p->last ||
Line 166  mlg_begintag(struct md_mlg *p, enum md_ns ns, int tok,
Line 142  mlg_begintag(struct md_mlg *p, enum md_ns ns, int tok,
         if ( ! ml_nputs(p->mbuf, "<", 1, &p->pos))          if ( ! ml_nputs(p->mbuf, "<", 1, &p->pos))
                 return(0);                  return(0);
   
         res = (*p->begintag)(p->mbuf, p->args, ns, tok,          res = (*p->cbs.ml_begintag)(p->mbuf, p->data, p->args, ns, tok,
                         argc, (const char **)argv);                          argc, (const char **)argv);
         if (-1 == res)          if (-1 == res)
                 return(0);                  return(0);
Line 195  mlg_endtag(struct md_mlg *p, enum md_ns ns, int tok)
Line 171  mlg_endtag(struct md_mlg *p, enum md_ns ns, int tok)
 {  {
         ssize_t          res;          ssize_t          res;
   
         /* TODO: extra rules for block/inline. */          assert(MD_NS_DEFAULT != ns);
   
           switch (ns) {
           case (MD_NS_INLINE):
                   break;
           default:
                   p->indent--;
                   if (0 != p->pos) {
                           if ( ! mlg_newline(p))
                                   return(0);
                           if ( ! mlg_indent(p))
                                   return(0);
                   } else if ( ! mlg_indent(p))
                           return(0);
                   break;
           }
   
         if ( ! ml_nputs(p->mbuf, "</", 2, &p->pos))          if ( ! ml_nputs(p->mbuf, "</", 2, &p->pos))
                 return(0);                  return(0);
   
         res = (*p->endtag)(p->mbuf, p->args, ns, tok);          res = (*p->cbs.ml_endtag)(p->mbuf, p->data, p->args, ns, tok);
         if (-1 == res)          if (-1 == res)
                 return(0);                  return(0);
   
         assert(res >= 0);          assert(res >= 0);
         p->pos += (size_t)res;          p->pos += (size_t)res;
   
         /* TODO: extra rules for block/inline. */          if ( ! ml_nputs(p->mbuf, ">", 1, &p->pos))
                   return(0);
   
           switch (ns) {
           case (MD_NS_INLINE):
                   mlg_mode(p, MD_INLINE_OUT);
                   break;
           default:
                   mlg_mode(p, MD_BLK_OUT);
                   break;
           }
   
         return(ml_nputs(p->mbuf, ">", 1, &p->pos));          return(1);
 }  }
   
   
Line 218  mlg_indent(struct md_mlg *p)
Line 219  mlg_indent(struct md_mlg *p)
 {  {
         size_t           count;          size_t           count;
   
         count = p->indent > MAXINDENT ? (size_t)MAXINDENT : p->indent;          count = p->indent > MAXINDENT ?
                   (size_t)MAXINDENT : p->indent;
         count *= INDENT;          count *= INDENT;
   
         assert(0 == p->pos);          assert(0 == p->pos);
Line 229  mlg_indent(struct md_mlg *p)
Line 231  mlg_indent(struct md_mlg *p)
 static int  static int
 mlg_newline(struct md_mlg *p)  mlg_newline(struct md_mlg *p)
 {  {
         size_t           dummy;  
   
         if ( ! ml_nputs(p->mbuf, "\n", 1, &dummy))  
                 return(0);  
         p->pos = 0;          p->pos = 0;
         return(1);          return(ml_nputs(p->mbuf, "\n", 1, NULL));
 }  }
   
   
Line 324  mlg_exit(struct md_mlg *p, int flush)
Line 323  mlg_exit(struct md_mlg *p, int flush)
   
         c = roff_free(p->tree, flush);          c = roff_free(p->tree, flush);
         free(p);          free(p);
   
           (*p->cbs.ml_free)(p->data);
   
         return(c);          return(c);
 }  }
   
Line 332  struct md_mlg *
Line 334  struct md_mlg *
 mlg_alloc(const struct md_args *args,  mlg_alloc(const struct md_args *args,
                 const struct md_rbuf *rbuf,                  const struct md_rbuf *rbuf,
                 struct md_mbuf *mbuf,                  struct md_mbuf *mbuf,
                 ml_begintag begintag, ml_endtag endtag,                  const struct ml_cbs *cbs)
                 ml_begin begin, ml_end end)  
 {  {
         struct roffcb    cb;          struct roffcb    cb;
         struct md_mlg   *p;          struct md_mlg   *p;
Line 358  mlg_alloc(const struct md_args *args, 
Line 359  mlg_alloc(const struct md_args *args, 
         p->args = args;          p->args = args;
         p->mbuf = mbuf;          p->mbuf = mbuf;
         p->rbuf = rbuf;          p->rbuf = rbuf;
         p->begintag = begintag;  
         p->endtag = endtag;  
         p->begin = begin;  
         p->end = end;  
   
         if (NULL == (p->tree = roff_alloc(&cb, p))) {          (void)memcpy(&p->cbs, cbs, sizeof(struct ml_cbs));
   
           if (NULL == (p->tree = roff_alloc(&cb, p)))
                 free(p);                  free(p);
                 return(NULL);          else if ( ! (*p->cbs.ml_alloc)(&p->data))
         }                  free(p);
           else
                   return(p);
   
         return(p);          return(NULL);
 }  }
   
   
Line 382  mlg_roffhead(void *arg, const struct tm *tm, const cha
Line 383  mlg_roffhead(void *arg, const struct tm *tm, const cha
         p = (struct md_mlg *)arg;          p = (struct md_mlg *)arg;
   
         mlg_mode(p, MD_BLK_IN);          mlg_mode(p, MD_BLK_IN);
         if ( ! (*p->begin)(p->mbuf, p->args, tm, os, title, sec, vol))  
           if ( ! (*p->cbs.ml_begin)(p->mbuf, p->args, tm, os, title, sec, vol))
                 return(0);                  return(0);
   
         p->indent++;          p->indent++;
Line 398  mlg_rofftail(void *arg)
Line 400  mlg_rofftail(void *arg)
         assert(arg);          assert(arg);
         p = (struct md_mlg *)arg;          p = (struct md_mlg *)arg;
   
         if (0 != p->pos && ! mlg_newline(p))          if (0 != p->pos)
                   if ( ! mlg_newline(p))
                           return(0);
   
           if ( ! (*p->cbs.ml_end)(p->mbuf, p->args))
                 return(0);                  return(0);
   
         mlg_mode(p, MD_BLK_OUT);          mlg_mode(p, MD_BLK_OUT);
         if ( ! (*p->end)(p->mbuf, p->args))  
                 return(0);  
   
         return(mlg_newline(p));          return(mlg_newline(p));
 }  }
   
   
 /* ARGSUSED */  
 static int  static int
 mlg_roffspecial(void *arg, int tok, const char *start, char **more)  mlg_roffspecial(void *arg, int tok, const char *start, char **more)
 {  {
Line 421  mlg_roffspecial(void *arg, int tok, const char *start,
Line 424  mlg_roffspecial(void *arg, int tok, const char *start,
         switch (tok) {          switch (tok) {
         case (ROFF_Xr):          case (ROFF_Xr):
                 if ( ! *more) {                  if ( ! *more) {
                         mlg_err(p, start, start,                          mlg_err(p, start, start, "missing argument");
                                         "missing required argument");  
                         return(0);                          return(0);
                 }                  }
                 if ( ! mlg_begintag(p, MD_NS_INLINE, tok, NULL, NULL))                  if ( ! mlg_begintag(p, MD_NS_INLINE, tok, NULL, NULL))
Line 432  mlg_roffspecial(void *arg, int tok, const char *start,
Line 434  mlg_roffspecial(void *arg, int tok, const char *start,
                 if (*more) {                  if (*more) {
                         if ( ! ml_nputs(p->mbuf, "(", 1, &p->pos))                          if ( ! ml_nputs(p->mbuf, "(", 1, &p->pos))
                                 return(0);                                  return(0);
                         if ( ! mlg_data(p, 0, start, *more++))                          if ( ! ml_puts(p->mbuf, *more++, &p->pos))
                                 return(0);                                  return(0);
                         if ( ! ml_nputs(p->mbuf, ")", 1, &p->pos))                          if ( ! ml_nputs(p->mbuf, ")", 1, &p->pos))
                                 return(0);                                  return(0);
Line 443  mlg_roffspecial(void *arg, int tok, const char *start,
Line 445  mlg_roffspecial(void *arg, int tok, const char *start,
                 }                  }
                 if ( ! mlg_endtag(p, MD_NS_INLINE, tok))                  if ( ! mlg_endtag(p, MD_NS_INLINE, tok))
                         return(0);                          return(0);
                 mlg_mode(p, MD_INLINE_OUT);  
                 break;                  break;
         case (ROFF_Fn):          case (ROFF_Fn):
                 break;                  break;
Line 478  static int
Line 479  static int
 mlg_roffblkout(void *arg, int tok)  mlg_roffblkout(void *arg, int tok)
 {  {
   
         return(mlg_endblk((struct md_mlg *)arg, MD_NS_BLOCK, tok));          return(mlg_endtag((struct md_mlg *)arg, MD_NS_BLOCK, tok));
 }  }
   
   
Line 495  static int
Line 496  static int
 mlg_roffblkbodyout(void *arg, int tok)  mlg_roffblkbodyout(void *arg, int tok)
 {  {
   
         return(mlg_endblk((struct md_mlg *)arg, MD_NS_BODY, tok));          return(mlg_endtag((struct md_mlg *)arg, MD_NS_BODY, tok));
 }  }
   
   
Line 512  static int
Line 513  static int
 mlg_roffblkheadout(void *arg, int tok)  mlg_roffblkheadout(void *arg, int tok)
 {  {
   
         return(mlg_endblk((struct md_mlg *)arg, MD_NS_HEAD, tok));          return(mlg_endtag((struct md_mlg *)arg, MD_NS_HEAD, tok));
 }  }
   
   
Line 528  mlg_roffin(void *arg, int tok, int *argc, char **argv)
Line 529  mlg_roffin(void *arg, int tok, int *argc, char **argv)
 static int  static int
 mlg_roffout(void *arg, int tok)  mlg_roffout(void *arg, int tok)
 {  {
         struct md_mlg   *p;  
   
         assert(arg);          return(mlg_endtag((struct md_mlg *)arg, MD_NS_INLINE, tok));
         p = (struct md_mlg *)arg;  
   
         if (0 == p->pos && ! mlg_indent(p))  
                 return(0);  
   
         mlg_mode(p, MD_INLINE_OUT);  
         return(mlg_endtag(p, MD_NS_INLINE, tok));  
 }  }
   
   
Line 562  mlg_roffdata(void *arg, int space, const char *start, 
Line 555  mlg_roffdata(void *arg, int space, const char *start, 
                 return(0);                  return(0);
   
         mlg_mode(p, MD_TEXT);          mlg_mode(p, MD_TEXT);
   
         return(1);          return(1);
 }  }
   

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.11

CVSweb