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

Diff for /mandoc/tbl.c between version 1.1 and 1.46

version 1.1, 2010/12/28 10:51:03 version 1.46, 2018/12/14 06:33:14
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 <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <time.h>  #include <time.h>
   
   #include "mandoc_aux.h"
 #include "mandoc.h"  #include "mandoc.h"
 #include "roff.h"  #include "tbl.h"
 #include "libmandoc.h"  #include "libmandoc.h"
 #include "libroff.h"  #include "tbl_parse.h"
   #include "tbl_int.h"
   
 enum    tbl_part {  
         TBL_PART_OPTS, /* in options (first line) */  
         TBL_PART_LAYOUT, /* describing layout */  
         TBL_PART_DATA  /* creating data rows */  
 };  
   
   void
   tbl_read(struct tbl_node *tbl, int ln, const char *p, int pos)
   {
           const char      *cp;
           int              active;
   
 struct  tbl {          /*
         enum tbl_part    part;           * 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             tbl_init(struct tbl *);          if (tbl->part == TBL_PART_OPTS) {
 static  void             tbl_clear(struct 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;
                   }
           }
   
 static void          /* Process the other section types.  */
 tbl_clear(struct tbl *tbl)  
 {  
   
           switch (tbl->part) {
           case TBL_PART_LAYOUT:
                   tbl_layout(tbl, ln, p, pos);
                   break;
           case TBL_PART_CDATA:
                   tbl_cdata(tbl, ln, p, pos);
                   break;
           default:
                   tbl_data(tbl, ln, p, pos);
                   break;
           }
 }  }
   
 static void  struct tbl_node *
 tbl_init(struct tbl *tbl)  tbl_alloc(int pos, int line, struct tbl_node *last_tbl)
 {  {
           struct tbl_node *tbl;
   
           tbl = mandoc_calloc(1, sizeof(*tbl));
           if (last_tbl != NULL)
                   last_tbl->next = tbl;
           tbl->line = line;
           tbl->pos = pos;
         tbl->part = TBL_PART_OPTS;          tbl->part = TBL_PART_OPTS;
           tbl->opts.tab = '\t';
           tbl->opts.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_node *old_tbl;
         const char      *cp;          struct tbl_row  *rp;
           struct tbl_cell *cp;
           struct tbl_span *sp;
           struct tbl_dat  *dp;
   
         cp = &p[offs];          while (tbl != NULL) {
         len = (int)strlen(cp);                  while ((rp = tbl->first_row) != NULL) {
                           tbl->first_row = rp->next;
         if (len && TBL_PART_OPTS == tbl->part)                          while (rp->first != NULL) {
                 if (';' != cp[len - 1])                                  cp = rp->first;
                         tbl->part = TBL_PART_LAYOUT;                                  rp->first = cp->next;
                                   free(cp->wstr);
         return(1);                                  free(cp);
                           }
                           free(rp);
                   }
                   while ((sp = tbl->first_span) != NULL) {
                           tbl->first_span = sp->next;
                           while (sp->first != NULL) {
                                   dp = sp->first;
                                   sp->first = dp->next;
                                   free(dp->string);
                                   free(dp);
                           }
                           free(sp);
                   }
                   old_tbl = tbl;
                   tbl = tbl->next;
                   free(old_tbl);
           }
 }  }
   
 struct tbl *  void
 tbl_alloc(void)  tbl_restart(int line, int pos, struct tbl_node *tbl)
 {  {
         struct tbl      *p;          if (tbl->part == TBL_PART_CDATA)
                   mandoc_msg(MANDOCERR_TBLDATA_BLK, line, pos, "T&");
   
         p = mandoc_malloc(sizeof(struct tbl));          tbl->part = TBL_PART_LAYOUT;
         tbl_init(p);          tbl->line = line;
         return(p);          tbl->pos = pos;
 }  }
   
 void  struct tbl_span *
 tbl_free(struct tbl *p)  tbl_span(struct tbl_node *tbl)
 {  {
           struct tbl_span  *span;
   
         tbl_clear(p);          span = tbl->current_span ? tbl->current_span->next
         free(p);                                   : tbl->first_span;
           if (span != NULL)
                   tbl->current_span = span;
           return span;
 }  }
   
 void  int
 tbl_reset(struct tbl *tbl)  tbl_end(struct tbl_node *tbl, int still_open)
 {  {
           struct tbl_span *sp;
   
         tbl_clear(tbl);          if (still_open)
         tbl_init(tbl);                  mandoc_msg(MANDOCERR_BLK_NOEND, tbl->line, tbl->pos, "TS");
           else if (tbl->part == TBL_PART_CDATA)
                   mandoc_msg(MANDOCERR_TBLDATA_BLK, 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->line, tbl->pos, NULL);
                   return 0;
           }
           return 1;
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.46

CVSweb