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

Diff for /mandoc/tbl.c between version 1.3 and 1.36

version 1.3, 2010/12/28 13:46:07 version 1.36, 2015/01/28 17:32:07
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@kth.se>   * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
    * Copyright (c) 2011, 2015 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 14 
Line 15 
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
   #include "config.h"
   
   #include <sys/types.h>
   
 #include <assert.h>  #include <assert.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
Line 21 
Line 26 
 #include <time.h>  #include <time.h>
   
 #include "mandoc.h"  #include "mandoc.h"
 #include "roff.h"  #include "mandoc_aux.h"
 #include "libmandoc.h"  #include "libmandoc.h"
 #include "libroff.h"  #include "libroff.h"
   
 static  const char       tbl_toks[TBL_TOK__MAX] = {  
         '(',    ')',    ',',    ';',    '.',  
         ' ',    '\t',   '\0'  
 };  
   
 static  void             tbl_init(struct tbl *);  enum rofferr
 static  void             tbl_clear(struct tbl *);  tbl_read(struct tbl_node *tbl, int ln, const char *p, int pos)
 static  enum tbl_tok     tbl_next_char(char);  
   
 static void  
 tbl_clear(struct tbl *tbl)  
 {  {
           const char      *cp;
           int              active;
   
 }          /*
            * In the options section, proceed to the layout section
            * after a semicolon, or right away if there is no semicolon.
            * Ignore semicolons in arguments.
            */
   
 static void          if (tbl->part == TBL_PART_OPTS) {
 tbl_init(struct tbl *tbl)                  tbl->part = TBL_PART_LAYOUT;
 {                  active = 1;
                   for (cp = p + pos; *cp != '\0'; cp++) {
                           switch (*cp) {
                           case '(':
                                   active = 0;
                                   continue;
                           case ')':
                                   active = 1;
                                   continue;
                           case ';':
                                   if (active)
                                           break;
                                   continue;
                           default:
                                   continue;
                           }
                           break;
                   }
                   if (*cp == ';') {
                           tbl_option(tbl, ln, p, &pos);
                           if (p[pos] == '\0')
                                   return(ROFF_IGN);
                   }
           }
   
         tbl->part = TBL_PART_OPTS;          /* Process the other section types.  */
 }  
   
 enum rofferr          switch (tbl->part) {
 tbl_read(struct tbl *tbl, int ln, const char *p, int offs)          case TBL_PART_LAYOUT:
 {                  tbl_layout(tbl, ln, p, pos);
         int              len;                  return(ROFF_IGN);
         const char      *cp;          case TBL_PART_CDATA:
                   return(tbl_cdata(tbl, ln, p, pos) ? ROFF_TBL : ROFF_IGN);
           default:
                   break;
           }
   
         cp = &p[offs];          tbl_data(tbl, ln, p, pos);
         len = (int)strlen(cp);          return(ROFF_TBL);
   
         if (len && TBL_PART_OPTS == tbl->part)  
                 if (';' != cp[len - 1])  
                         tbl->part = TBL_PART_LAYOUT;  
   
         return(ROFF_CONT);  
 }  }
   
 struct tbl *  struct tbl_node *
 tbl_alloc(void)  tbl_alloc(int pos, int line, struct mparse *parse)
 {  {
         struct tbl      *p;          struct tbl_node *tbl;
   
         p = mandoc_malloc(sizeof(struct tbl));          tbl = mandoc_calloc(1, sizeof(struct tbl_node));
         tbl_init(p);          tbl->line = line;
         return(p);          tbl->pos = pos;
           tbl->parse = parse;
           tbl->part = TBL_PART_OPTS;
           tbl->opts.tab = '\t';
           tbl->opts.decimal = '.';
           return(tbl);
 }  }
   
 void  void
 tbl_free(struct tbl *p)  tbl_free(struct tbl_node *tbl)
 {  {
           struct tbl_row  *rp;
           struct tbl_cell *cp;
           struct tbl_span *sp;
           struct tbl_dat  *dp;
           struct tbl_head *hp;
   
         tbl_clear(p);          while (NULL != (rp = tbl->first_row)) {
         free(p);                  tbl->first_row = rp->next;
                   while (rp->first) {
                           cp = rp->first;
                           rp->first = cp->next;
                           free(cp);
                   }
                   free(rp);
           }
   
           while (NULL != (sp = tbl->first_span)) {
                   tbl->first_span = sp->next;
                   while (sp->first) {
                           dp = sp->first;
                           sp->first = dp->next;
                           if (dp->string)
                                   free(dp->string);
                           free(dp);
                   }
                   free(sp);
           }
   
           while (NULL != (hp = tbl->first_head)) {
                   tbl->first_head = hp->next;
                   free(hp);
           }
   
           free(tbl);
 }  }
   
 void  void
 tbl_reset(struct tbl *tbl)  tbl_restart(int line, int pos, struct tbl_node *tbl)
 {  {
           if (tbl->part == TBL_PART_CDATA)
                   mandoc_msg(MANDOCERR_TBLDATA_BLK, tbl->parse,
                       line, pos, "T&");
   
         tbl_clear(tbl);          tbl->part = TBL_PART_LAYOUT;
         tbl_init(tbl);          tbl->line = line;
           tbl->pos = pos;
 }  }
   
 static enum tbl_tok  const struct tbl_span *
 tbl_next_char(char c)  tbl_span(struct tbl_node *tbl)
 {  {
         int              i;          struct tbl_span  *span;
   
         /*          assert(tbl);
          * These are delimiting tokens.  They separate out words in the          span = tbl->current_span ? tbl->current_span->next
          * token stream.                                   : tbl->first_span;
          *          if (span)
          * FIXME: make this into a hashtable for faster lookup.                  tbl->current_span = span;
          */          return(span);
         for (i = 0; i < TBL_TOK__MAX; i++)  
                 if (c == tbl_toks[i])  
                         return((enum tbl_tok)i);  
   
         return(TBL_TOK__MAX);  
 }  }
   
 enum tbl_tok  int
 tbl_next(struct tbl *tbl, const char *p, int *pos)  tbl_end(struct tbl_node **tblp)
 {  {
         int              i;          struct tbl_node *tbl;
         enum tbl_tok     c;          struct tbl_span *sp;
   
         tbl->buf[0] = '\0';          tbl = *tblp;
           *tblp = NULL;
   
         if (TBL_TOK__MAX != (c = tbl_next_char(p[*pos]))) {          if (tbl->part == TBL_PART_CDATA)
                 if (TBL_TOK_NIL != c) {                  mandoc_msg(MANDOCERR_TBLDATA_BLK, tbl->parse,
                         tbl->buf[0] = p[*pos];                      tbl->line, tbl->pos, "TE");
                         tbl->buf[1] = '\0';  
                         (*pos)++;          sp = tbl->first_span;
                 }          while (sp != NULL && sp->first == NULL)
                 return(c);                  sp = sp->next;
           if (sp == NULL) {
                   mandoc_msg(MANDOCERR_TBLDATA_NONE, tbl->parse,
                       tbl->line, tbl->pos, NULL);
                   return(0);
         }          }
   
         /*          if (tbl->last_span != NULL)
          * Copy words into a nil-terminated buffer.  For now, we use a                  tbl->last_span->flags |= TBL_SPAN_LAST;
          * static buffer.  FIXME: eventually this should be made into a  
          * dynamic one living in struct tbl.  
          */  
   
         for (i = 0; i < BUFSIZ; i++, (*pos)++)          return(1);
                 if (TBL_TOK__MAX == tbl_next_char(p[*pos]))  
                         tbl->buf[i] = p[*pos];  
                 else  
                         break;  
   
         assert(i < BUFSIZ);  
         tbl->buf[i] = '\0';  
   
         return(TBL_TOK__MAX);  
 }  }
   
   

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.36

CVSweb