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

Diff for /mandoc/tbl.c between version 1.8 and 1.40

version 1.8, 2010/12/29 16:44:23 version 1.40, 2015/10/06 18:32:20
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>   * 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  void             tbl_init(struct tbl *);  
 static  void             tbl_clear(struct tbl *);  
   
 static void  enum rofferr
 tbl_clear(struct tbl *tbl)  tbl_read(struct tbl_node *tbl, int ln, const char *p, int pos)
 {  {
         struct tbl_row  *rp;          const char      *cp;
         struct tbl_cell *cp;          int              active;
   
         while (tbl->first) {          /*
                 rp = tbl->first;           * In the options section, proceed to the layout section
                 tbl->first = rp->next;           * after a semicolon, or right away if there is no semicolon.
                 while (rp->first) {           * Ignore semicolons in arguments.
                         cp = rp->first;           */
                         rp->first = cp->next;  
                         free(cp);          if (tbl->part == TBL_PART_OPTS) {
                   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;
                 }                  }
                 free(rp);                  if (*cp == ';') {
                           tbl_option(tbl, ln, p, &pos);
                           if (p[pos] == '\0')
                                   return ROFF_IGN;
                   }
         }          }
   
         tbl->last = NULL;          /* Process the other section types.  */
   
           switch (tbl->part) {
           case TBL_PART_LAYOUT:
                   tbl_layout(tbl, ln, p, pos);
                   return ROFF_IGN;
           case TBL_PART_CDATA:
                   return tbl_cdata(tbl, ln, p, pos) ? ROFF_TBL : ROFF_IGN;
           default:
                   break;
           }
   
           tbl_data(tbl, ln, p, pos);
           return ROFF_TBL;
 }  }
   
 static void  struct tbl_node *
 tbl_init(struct tbl *tbl)  tbl_alloc(int pos, int line, struct mparse *parse)
 {  {
           struct tbl_node *tbl;
   
           tbl = mandoc_calloc(1, sizeof(*tbl));
           tbl->line = line;
           tbl->pos = pos;
           tbl->parse = parse;
         tbl->part = TBL_PART_OPTS;          tbl->part = TBL_PART_OPTS;
         tbl->tab = '\t';          tbl->opts.tab = '\t';
         tbl->linesize = 12;          tbl->opts.decimal = '.';
         tbl->decimal = '.';          return tbl;
 }  }
   
 enum rofferr  void
 tbl_read(struct tbl *tbl, int ln, const char *p, int offs)  tbl_free(struct tbl_node *tbl)
 {  {
         int              len;          struct tbl_row  *rp;
         const char      *cp;          struct tbl_cell *cp;
         struct tbl_dat  *dp;  
         struct tbl_span *sp;          struct tbl_span *sp;
           struct tbl_dat  *dp;
   
         cp = &p[offs];          while ((rp = tbl->first_row) != NULL) {
         len = (int)strlen(cp);                  tbl->first_row = rp->next;
                   while (rp->first != NULL) {
         /*                          cp = rp->first;
          * If we're in the options section and we don't have a                          rp->first = cp->next;
          * terminating semicolon, assume we've moved directly into the                          free(cp);
          * layout section.  No need to report a warning: this is,                  }
          * apparently, standard behaviour.                  free(rp);
          */  
   
         if (TBL_PART_OPTS == tbl->part && len)  
                 if (';' != cp[len - 1])  
                         tbl->part = TBL_PART_LAYOUT;  
   
         /* Now process each logical section of the table.  */  
   
         switch (tbl->part) {  
         case (TBL_PART_OPTS):  
                 return(tbl_option(tbl, ln, p) ? ROFF_IGN : ROFF_ERR);  
         case (TBL_PART_LAYOUT):  
                 return(tbl_layout(tbl, ln, p) ? ROFF_IGN : ROFF_ERR);  
         case (TBL_PART_DATA):  
                 break;  
         }          }
   
         /* XXX: throw away data for now. */          while ((sp = tbl->first_span) != NULL) {
         if (NULL != (sp = tbl_data(tbl, ln, p))) {                  tbl->first_span = sp->next;
                 while (NULL != (dp = sp->first)) {                  while (sp->first != NULL) {
                         sp->first = sp->first->next;                          dp = sp->first;
                         if (dp->string)                          sp->first = dp->next;
                                 free(dp->string);                          free(dp->string);
                         free(dp);                          free(dp);
                 }                  }
                 free(sp);                  free(sp);
         }          }
   
         return(ROFF_CONT);  
 }  
   
 struct tbl *          free(tbl);
 tbl_alloc(void *data, const mandocmsg msg)  
 {  
         struct tbl      *p;  
   
         p = mandoc_calloc(1, sizeof(struct tbl));  
         p->data = data;  
         p->msg = msg;  
         tbl_init(p);  
         return(p);  
 }  }
   
 void  void
 tbl_free(struct tbl *p)  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(p);          tbl->part = TBL_PART_LAYOUT;
         free(p);          tbl->line = line;
           tbl->pos = pos;
 }  }
   
 void  const struct tbl_span *
 tbl_reset(struct tbl *tbl)  tbl_span(struct tbl_node *tbl)
 {  {
           struct tbl_span  *span;
   
         tbl_clear(tbl);          assert(tbl);
         tbl_init(tbl);          span = tbl->current_span ? tbl->current_span->next
                                    : tbl->first_span;
           if (span)
                   tbl->current_span = span;
           return span;
 }  }
   
 void  int
 tbl_restart(struct tbl *tbl)  tbl_end(struct tbl_node **tblp)
 {  {
           struct tbl_node *tbl;
           struct tbl_span *sp;
   
         tbl_clear(tbl);          tbl = *tblp;
         tbl->part = TBL_PART_LAYOUT;          *tblp = NULL;
 }  
   
           if (tbl->part == TBL_PART_CDATA)
                   mandoc_msg(MANDOCERR_TBLDATA_BLK, tbl->parse,
                       tbl->line, tbl->pos, "TE");
   
           sp = tbl->first_span;
           while (sp != NULL && sp->first == NULL)
                   sp = sp->next;
           if (sp == NULL) {
                   mandoc_msg(MANDOCERR_TBLDATA_NONE, tbl->parse,
                       tbl->line, tbl->pos, NULL);
                   return 0;
           }
           return 1;
   }

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

CVSweb