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

Diff for /mandoc/tbl_opts.c between version 1.7 and 1.15

version 1.7, 2011/01/07 13:20:58 version 1.15, 2014/11/26 17:51:55
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>
  *   *
  * 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 14 
  * 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 <ctype.h>  #include <ctype.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   
 #include "mandoc.h"  #include "mandoc.h"
   #include "libmandoc.h"
 #include "libroff.h"  #include "libroff.h"
   
 enum    tbl_ident {  enum    tbl_ident {
Line 57  struct tbl_phrase {
Line 62  struct tbl_phrase {
 static  const struct tbl_phrase keys[KEY_MAXKEYS] = {  static  const struct tbl_phrase keys[KEY_MAXKEYS] = {
         { "center",      TBL_OPT_CENTRE,        KEY_CENTRE},          { "center",      TBL_OPT_CENTRE,        KEY_CENTRE},
         { "centre",      TBL_OPT_CENTRE,        KEY_CENTRE},          { "centre",      TBL_OPT_CENTRE,        KEY_CENTRE},
         { "delim",       0,                     KEY_DELIM},          { "delim",       0,                     KEY_DELIM},
         { "expand",      TBL_OPT_EXPAND,        KEY_EXPAND},          { "expand",      TBL_OPT_EXPAND,        KEY_EXPAND},
         { "box",         TBL_OPT_BOX,           KEY_BOX},          { "box",         TBL_OPT_BOX,           KEY_BOX},
         { "doublebox",   TBL_OPT_DBOX,          KEY_DBOX},          { "doublebox",   TBL_OPT_DBOX,          KEY_DBOX},
         { "allbox",      TBL_OPT_ALLBOX,        KEY_ALLBOX},          { "allbox",      TBL_OPT_ALLBOX,        KEY_ALLBOX},
         { "frame",       TBL_OPT_BOX,           KEY_FRAME},          { "frame",       TBL_OPT_BOX,           KEY_FRAME},
         { "doubleframe", TBL_OPT_DBOX,          KEY_DFRAME},          { "doubleframe", TBL_OPT_DBOX,          KEY_DFRAME},
Line 71  static const struct tbl_phrase keys[KEY_MAXKEYS] = {
Line 76  static const struct tbl_phrase keys[KEY_MAXKEYS] = {
         { "nospaces",    TBL_OPT_NOSPACE,       KEY_NOSPACE},          { "nospaces",    TBL_OPT_NOSPACE,       KEY_NOSPACE},
 };  };
   
 static  int              arg(struct tbl_node *, int,  static  int              arg(struct tbl_node *, int,
                                 const char *, int *, enum tbl_ident);                                  const char *, int *, enum tbl_ident);
 static  void             opt(struct tbl_node *, int,  static  void             opt(struct tbl_node *, int,
                                 const char *, int *);                                  const char *, int *);
   
   
 static int  static int
 arg(struct tbl_node *tbl, int ln, const char *p, int *pos, enum tbl_ident key)  arg(struct tbl_node *tbl, int ln, const char *p, int *pos, enum tbl_ident key)
 {  {
Line 88  arg(struct tbl_node *tbl, int ln, const char *p, int *
Line 94  arg(struct tbl_node *tbl, int ln, const char *p, int *
         /* Arguments always begin with a parenthesis. */          /* Arguments always begin with a parenthesis. */
   
         if ('(' != p[*pos]) {          if ('(' != p[*pos]) {
                 TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos);                  mandoc_msg(MANDOCERR_TBL, tbl->parse,
                       ln, *pos, NULL);
                 return(0);                  return(0);
         }          }
   
Line 101  arg(struct tbl_node *tbl, int ln, const char *p, int *
Line 108  arg(struct tbl_node *tbl, int ln, const char *p, int *
          */           */
   
         switch (key) {          switch (key) {
         case (KEY_DELIM):          case KEY_DELIM:
                 if ('\0' == p[(*pos)++]) {                  if ('\0' == p[(*pos)++]) {
                         TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1);                          mandoc_msg(MANDOCERR_TBL, tbl->parse,
                               ln, *pos - 1, NULL);
                         return(0);                          return(0);
                 }                  }
   
                 if ('\0' == p[(*pos)++]) {                  if ('\0' == p[(*pos)++]) {
                         TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1);                          mandoc_msg(MANDOCERR_TBL, tbl->parse,
                               ln, *pos - 1, NULL);
                         return(0);                          return(0);
                 }                  }
                 break;                  break;
         case (KEY_TAB):          case KEY_TAB:
                 if ('\0' != (tbl->opts.tab = p[(*pos)++]))                  if ('\0' != (tbl->opts.tab = p[(*pos)++]))
                         break;                          break;
   
                 TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1);                  mandoc_msg(MANDOCERR_TBL, tbl->parse,
                       ln, *pos - 1, NULL);
                 return(0);                  return(0);
         case (KEY_LINESIZE):          case KEY_LINESIZE:
                 for (i = 0; i < KEY_MAXNUMSZ && p[*pos]; i++, (*pos)++) {                  for (i = 0; i < KEY_MAXNUMSZ && p[*pos]; i++, (*pos)++) {
                         buf[i] = p[*pos];                          buf[i] = p[*pos];
                         if ( ! isdigit((unsigned char)buf[i]))                          if ( ! isdigit((unsigned char)buf[i]))
Line 131  arg(struct tbl_node *tbl, int ln, const char *p, int *
Line 141  arg(struct tbl_node *tbl, int ln, const char *p, int *
                         break;                          break;
                 }                  }
   
                 (*tbl->msg)(MANDOCERR_TBL, tbl->data, ln, *pos, NULL);                  mandoc_msg(MANDOCERR_TBL, tbl->parse, ln, *pos, NULL);
                 return(0);                  return(0);
         case (KEY_DPOINT):          case KEY_DPOINT:
                 if ('\0' != (tbl->opts.decimal = p[(*pos)++]))                  if ('\0' != (tbl->opts.decimal = p[(*pos)++]))
                         break;                          break;
   
                 TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1);                  mandoc_msg(MANDOCERR_TBL, tbl->parse,
                       ln, *pos - 1, NULL);
                 return(0);                  return(0);
         default:          default:
                 abort();                  abort();
Line 149  arg(struct tbl_node *tbl, int ln, const char *p, int *
Line 160  arg(struct tbl_node *tbl, int ln, const char *p, int *
         if (')' == p[(*pos)++])          if (')' == p[(*pos)++])
                 return(1);                  return(1);
   
         TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos - 1);          mandoc_msg(MANDOCERR_TBL, tbl->parse, ln, *pos - 1, NULL);
         return(0);          return(0);
 }  }
   
Line 171  again: /*
Line 182  again: /*
          *           *
          * options      ::= option_list [:space:]* [;][\n]           * options      ::= option_list [:space:]* [;][\n]
          * option_list  ::= option option_tail           * option_list  ::= option option_tail
          * option_tail  ::= [:space:]+ option_list |           * option_tail  ::= [,:space:]+ option_list |
          *              ::= epsilon           *              ::= epsilon
          * option       ::= [:alpha:]+ args           * option       ::= [:alpha:]+ args
          * args         ::= [:space:]* [(] [:alpha:]+ [)]           * args         ::= [:space:]* [(] [:alpha:]+ [)]
          */           */
Line 188  again: /*
Line 199  again: /*
         /* Copy up to first non-alpha character. */          /* Copy up to first non-alpha character. */
   
         for (sv = *pos, i = 0; i < KEY_MAXNAME; i++, (*pos)++) {          for (sv = *pos, i = 0; i < KEY_MAXNAME; i++, (*pos)++) {
                 buf[i] = tolower(p[*pos]);                  buf[i] = (char)tolower((unsigned char)p[*pos]);
                 if ( ! isalpha((unsigned char)buf[i]))                  if ( ! isalpha((unsigned char)buf[i]))
                         break;                          break;
         }          }
Line 196  again: /*
Line 207  again: /*
         /* Exit if buffer is empty (or overrun). */          /* Exit if buffer is empty (or overrun). */
   
         if (KEY_MAXNAME == i || 0 == i) {          if (KEY_MAXNAME == i || 0 == i) {
                 TBL_MSG(tbl, MANDOCERR_TBL, ln, *pos);                  mandoc_msg(MANDOCERR_TBL, tbl->parse, ln, *pos, NULL);
                 return;                  return;
         }          }
   
         buf[i] = '\0';          buf[i] = '\0';
   
         while (isspace((unsigned char)p[*pos]))          while (isspace((unsigned char)p[*pos]) || p[*pos] == ',')
                 (*pos)++;                  (*pos)++;
   
         /*          /*
          * Look through all of the available keys to find one that           * Look through all of the available keys to find one that
          * matches the input.  FIXME: hashtable this.           * matches the input.  FIXME: hashtable this.
          */           */
Line 221  again: /*
Line 232  again: /*
                  * of the sequence altogether.                   * of the sequence altogether.
                  */                   */
   
                 if (keys[i].key)                  if (keys[i].key)
                         tbl->opts.opts |= keys[i].key;                          tbl->opts.opts |= keys[i].key;
                 else if ( ! arg(tbl, ln, p, pos, keys[i].ident))                  else if ( ! arg(tbl, ln, p, pos, keys[i].ident))
                         return;                          return;
Line 229  again: /*
Line 240  again: /*
                 break;                  break;
         }          }
   
         /*          /*
          * Allow us to recover from bad options by continuing to another           * Allow us to recover from bad options by continuing to another
          * parse sequence.           * parse sequence.
          */           */
   
         if (KEY_MAXKEYS == i)          if (KEY_MAXKEYS == i)
                 TBL_MSG(tbl, MANDOCERR_TBLOPT, ln, sv);                  mandoc_msg(MANDOCERR_TBLOPT, tbl->parse, ln, sv, NULL);
   
         goto again;          goto again;
         /* NOTREACHED */          /* NOTREACHED */

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.15

CVSweb