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

Diff for /mandoc/Attic/xml.c between version 1.10 and 1.19

version 1.10, 2008/12/03 14:39:59 version 1.19, 2008/12/07 23:44:19
Line 16 
Line 16 
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR   * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  * PERFORMANCE OF THIS SOFTWARE.   * PERFORMANCE OF THIS SOFTWARE.
  */   */
   #include <assert.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   
Line 24 
Line 25 
 #include "ml.h"  #include "ml.h"
   
   
 static  ssize_t         xml_endtag(struct md_mbuf *,  static  int             xml_alloc(void **);
   static  void            xml_free(void *);
   static  ssize_t         xml_endtag(struct md_mbuf *, void *,
                                 const struct md_args *,                                  const struct md_args *,
                                 enum md_ns, int);                                  enum md_ns, int);
 static  ssize_t         xml_begintag(struct md_mbuf *,  static  ssize_t         xml_begintag(struct md_mbuf *, void *,
                                 const struct md_args *,                                  const struct md_args *,
                                 enum md_ns, int,                                  enum md_ns, int,
                                 const int *, const char **);                                  const int *, const char **);
   static  ssize_t         xml_beginstring(struct md_mbuf *,
                                   const struct md_args *,
                                   const char *, size_t);
   static  ssize_t         xml_endstring(struct md_mbuf *,
                                   const struct md_args *,
                                   const char *, size_t);
   static  int             xml_begin(struct md_mbuf *,
                                   const struct md_args *,
                                   const struct tm *,
                                   const char *, const char *,
                                   const char *, const char *);
   static  int             xml_end(struct md_mbuf *,
                                   const struct md_args *);
   static  ssize_t         xml_printtagname(struct md_mbuf *,
                                   enum md_ns, int);
   static  ssize_t         xml_printtagargs(struct md_mbuf *,
                                   const int *, const char **);
   
   
 static ssize_t  static ssize_t
 xml_begintag(struct md_mbuf *mbuf, const struct md_args *args,  xml_printtagargs(struct md_mbuf *mbuf, const int *argc,
                 enum md_ns ns, int tok,                  const char **argv)
                 const int *argc, const char **argv)  
 {  {
           int              i, c;
         size_t           res;          size_t           res;
   
         res = 0;          if (NULL == argc || NULL == argv)
                   return(0);
           assert(argc && argv);
   
         switch (ns) {          /* LINTED */
         case (MD_NS_BLOCK):          for (res = 0, i = 0; ROFF_ARGMAX != (c = argc[i]); i++) {
                 if ( ! ml_nputs(mbuf, "block:", 6, &res))                  if ( ! ml_nputs(mbuf, " ", 1, &res))
                         return(-1);                          return(-1);
                 break;  
         case (MD_NS_INLINE):                  if ( ! ml_puts(mbuf, tokargnames[c], &res))
                 if ( ! ml_nputs(mbuf, "inline:", 7, &res))  
                         return(-1);                          return(-1);
                 break;                  if ( ! ml_nputs(mbuf, "=\"", 2, &res))
         default:  
                 if ( ! ml_nputs(mbuf, "mbuf", 4, &res))  
                         return(-1);                          return(-1);
                 return((ssize_t)res);                  if (argv[i]) {
                           if ( ! ml_putstring(mbuf, argv[i], &res))
                                   return(-1);
                   } else if ( ! ml_nputs(mbuf, "true", 4, &res))
                           return(-1);
                   if ( ! ml_nputs(mbuf, "\"", 1, &res))
                           return(-1);
         }          }
   
         if ( ! ml_nputs(mbuf, toknames[tok],  
                                 strlen(toknames[tok]), &res))  
                 return(-1);  
   
         return((ssize_t)res);          return((ssize_t)res);
 }  }
   
   
 static ssize_t  static ssize_t
 xml_endtag(struct md_mbuf *mbuf, const struct md_args *args,  xml_printtagname(struct md_mbuf *mbuf, enum md_ns ns, int tok)
                 enum md_ns ns, int tok)  
 {  {
         size_t           res;          size_t           res;
   
         res = 0;          res = 0;
   
         switch (ns) {          switch (ns) {
         case (MD_NS_BLOCK):          case (MD_NS_BLOCK):
                 if ( ! ml_nputs(mbuf, "block:", 6, &res))                  if ( ! ml_nputs(mbuf, "block:", 6, &res))
Line 81  xml_endtag(struct md_mbuf *mbuf, const struct md_args 
Line 101  xml_endtag(struct md_mbuf *mbuf, const struct md_args 
                 if ( ! ml_nputs(mbuf, "inline:", 7, &res))                  if ( ! ml_nputs(mbuf, "inline:", 7, &res))
                         return(-1);                          return(-1);
                 break;                  break;
         default:          case (MD_NS_BODY):
                 if ( ! ml_nputs(mbuf, "mbuf", 4, &res))                  if ( ! ml_nputs(mbuf, "body:", 5, &res))
                         return(-1);                          return(-1);
                 return((ssize_t)res);                  break;
           case (MD_NS_HEAD):
                   if ( ! ml_nputs(mbuf, "head:", 5, &res))
                           return(-1);
                   break;
           default:
                   break;
         }          }
   
         if ( ! ml_nputs(mbuf, toknames[tok],          if ( ! ml_puts(mbuf, toknames[tok], &res))
                                 strlen(toknames[tok]), &res))  
                 return(-1);                  return(-1);
   
         return((ssize_t)res);          return((ssize_t)res);
 }  }
   
   
   /* ARGSUSED */
   static int
   xml_begin(struct md_mbuf *mbuf, const struct md_args *args,
                   const struct tm *tm, const char *os,
                   const char *title, const char *section,
                   const char *vol)
   {
   
           if ( ! ml_puts(mbuf, "<?xml version=\"1.0\" "
                                   "encoding=\"UTF-8\"?>\n", NULL))
                   return(0);
           return(ml_puts(mbuf, "<mdoc xmlns:block=\"block\" "
                                   "xmlns:body=\"body\" "
                                   "xmlns:head=\"head\" "
                                   "xmlns:inline=\"inline\">", NULL));
   }
   
   
   /* ARGSUSED */
   static int
   xml_end(struct md_mbuf *mbuf, const struct md_args *args)
   {
   
           return(ml_puts(mbuf, "</mdoc>", NULL));
   }
   
   
   /* ARGSUSED */
   static ssize_t
   xml_beginstring(struct md_mbuf *mbuf,
                   const struct md_args *args,
                   const char *buf, size_t sz)
   {
   
           return(0);
   }
   
   
   /* ARGSUSED */
   static ssize_t
   xml_endstring(struct md_mbuf *mbuf,
                   const struct md_args *args,
                   const char *buf, size_t sz)
   {
   
           return(0);
   }
   
   
   /* ARGSUSED */
   static ssize_t
   xml_begintag(struct md_mbuf *mbuf, void *data,
                   const struct md_args *args, enum md_ns ns,
                   int tok, const int *argc, const char **argv)
   {
           ssize_t          res, sz;
   
           if (-1 == (res = xml_printtagname(mbuf, ns, tok)))
                   return(-1);
           if (-1 == (sz = xml_printtagargs(mbuf, argc, argv)))
                   return(-1);
           return(res + sz);
   }
   
   
   /* ARGSUSED */
   static ssize_t
   xml_endtag(struct md_mbuf *mbuf, void *data,
                   const struct md_args *args, enum md_ns ns, int tok)
   {
   
           return(xml_printtagname(mbuf, ns, tok));
   }
   
   
   /* ARGSUSED */
 int  int
   xml_alloc(void **p)
   {
   
           return(1);
   }
   
   
   /* ARGSUSED */
   void
   xml_free(void *p)
   {
   
           /* Do nothing. */
   }
   
   
   int
 md_line_xml(void *data, char *buf)  md_line_xml(void *data, char *buf)
 {  {
   
Line 115  void *
Line 232  void *
 md_init_xml(const struct md_args *args,  md_init_xml(const struct md_args *args,
                 struct md_mbuf *mbuf, const struct md_rbuf *rbuf)                  struct md_mbuf *mbuf, const struct md_rbuf *rbuf)
 {  {
           struct ml_cbs    cbs;
   
         return(mlg_alloc(args, rbuf, mbuf, xml_begintag, xml_endtag));          cbs.ml_alloc = xml_alloc;
           cbs.ml_free = xml_free;
           cbs.ml_begintag = xml_begintag;
           cbs.ml_endtag = xml_endtag;
           cbs.ml_begin = xml_begin;
           cbs.ml_end = xml_end;
           cbs.ml_beginstring = xml_beginstring;
           cbs.ml_endstring = xml_endstring;
   
           return(mlg_alloc(args, rbuf, mbuf, &cbs));
 }  }
   

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.19

CVSweb