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

Diff for /mandoc/Attic/action.c between version 1.3 and 1.4

version 1.3, 2009/01/07 15:53:00 version 1.4, 2009/01/08 15:05:50
Line 21 
Line 21 
   
 #include "private.h"  #include "private.h"
   
 typedef int     (*a_act)(struct mdoc *, int, int);  typedef int     (*a_pre)(struct mdoc *, struct mdoc_node *);
   typedef int     (*a_post)(struct mdoc *);
   
   
 struct  actions {  struct  actions {
         a_act    action;          a_pre    pre;
           a_post   post;
 };  };
   
   
 static int       action_sh(struct mdoc *, int, int);  static int       post_sh(struct mdoc *);
   static int       post_os(struct mdoc *);
   static int       post_dt(struct mdoc *);
   static int       post_dd(struct mdoc *);
   
   
 const   struct actions mdoc_actions[MDOC_MAX] = {  const   struct actions mdoc_actions[MDOC_MAX] = {
         { NULL }, /* \" */          { NULL, NULL }, /* \" */
         { NULL }, /* Dd */          { NULL, post_dd }, /* Dd */
         { NULL }, /* Dt */          { NULL, post_dt }, /* Dt */
         { NULL }, /* Os */          { NULL, post_os }, /* Os */
         { action_sh }, /* Sh */          { NULL, post_sh }, /* Sh */
         { NULL }, /* Ss */          { NULL, NULL }, /* Ss */
         { NULL }, /* Pp */          { NULL, NULL }, /* Pp */
         { NULL }, /* D1 */          { NULL, NULL }, /* D1 */
         { NULL }, /* Dl */          { NULL, NULL }, /* Dl */
         { NULL }, /* Bd */          { NULL, NULL }, /* Bd */
         { NULL }, /* Ed */          { NULL, NULL }, /* Ed */
         { NULL }, /* Bl */          { NULL, NULL }, /* Bl */
         { NULL }, /* El */          { NULL, NULL }, /* El */
         { NULL }, /* It */          { NULL, NULL }, /* It */
         { NULL }, /* Ad */          { NULL, NULL }, /* Ad */
         { NULL }, /* An */          { NULL, NULL }, /* An */
         { NULL }, /* Ar */          { NULL, NULL }, /* Ar */
         { NULL }, /* Cd */          { NULL, NULL }, /* Cd */
         { NULL }, /* Cm */          { NULL, NULL }, /* Cm */
         { NULL }, /* Dv */          { NULL, NULL }, /* Dv */
         { NULL }, /* Er */          { NULL, NULL }, /* Er */
         { NULL }, /* Ev */          { NULL, NULL }, /* Ev */
         { NULL }, /* Ex */          { NULL, NULL }, /* Ex */
         { NULL }, /* Fa */          { NULL, NULL }, /* Fa */
         { NULL }, /* Fd */          { NULL, NULL }, /* Fd */
         { NULL }, /* Fl */          { NULL, NULL }, /* Fl */
         { NULL }, /* Fn */          { NULL, NULL }, /* Fn */
         { NULL }, /* Ft */          { NULL, NULL }, /* Ft */
         { NULL }, /* Ic */          { NULL, NULL }, /* Ic */
         { NULL }, /* In */          { NULL, NULL }, /* In */
         { NULL }, /* Li */          { NULL, NULL }, /* Li */
         { NULL }, /* Nd */          { NULL, NULL }, /* Nd */
         { NULL }, /* Nm */          { NULL, NULL }, /* Nm */
         { NULL }, /* Op */          { NULL, NULL }, /* Op */
         { NULL }, /* Ot */          { NULL, NULL }, /* Ot */
         { NULL }, /* Pa */          { NULL, NULL }, /* Pa */
         { NULL }, /* Rv */          { NULL, NULL }, /* Rv */
         { NULL }, /* St */          { NULL, NULL }, /* St */
         { NULL }, /* Va */          { NULL, NULL }, /* Va */
         { NULL }, /* Vt */          { NULL, NULL }, /* Vt */
         { NULL }, /* Xr */          { NULL, NULL }, /* Xr */
         { NULL }, /* %A */          { NULL, NULL }, /* %A */
         { NULL }, /* %B */          { NULL, NULL }, /* %B */
         { NULL }, /* %D */          { NULL, NULL }, /* %D */
         { NULL }, /* %I */          { NULL, NULL }, /* %I */
         { NULL }, /* %J */          { NULL, NULL }, /* %J */
         { NULL }, /* %N */          { NULL, NULL }, /* %N */
         { NULL }, /* %O */          { NULL, NULL }, /* %O */
         { NULL }, /* %P */          { NULL, NULL }, /* %P */
         { NULL }, /* %R */          { NULL, NULL }, /* %R */
         { NULL }, /* %T */          { NULL, NULL }, /* %T */
         { NULL }, /* %V */          { NULL, NULL }, /* %V */
         { NULL }, /* Ac */          { NULL, NULL }, /* Ac */
         { NULL }, /* Ao */          { NULL, NULL }, /* Ao */
         { NULL }, /* Aq */          { NULL, NULL }, /* Aq */
         { NULL }, /* At */          { NULL, NULL }, /* At */
         { NULL }, /* Bc */          { NULL, NULL }, /* Bc */
         { NULL }, /* Bf */          { NULL, NULL }, /* Bf */
         { NULL }, /* Bo */          { NULL, NULL }, /* Bo */
         { NULL }, /* Bq */          { NULL, NULL }, /* Bq */
         { NULL }, /* Bsx */          { NULL, NULL }, /* Bsx */
         { NULL }, /* Bx */          { NULL, NULL }, /* Bx */
         { NULL }, /* Db */          { NULL, NULL }, /* Db */
         { NULL }, /* Dc */          { NULL, NULL }, /* Dc */
         { NULL }, /* Do */          { NULL, NULL }, /* Do */
         { NULL }, /* Dq */          { NULL, NULL }, /* Dq */
         { NULL }, /* Ec */          { NULL, NULL }, /* Ec */
         { NULL }, /* Ef */          { NULL, NULL }, /* Ef */
         { NULL }, /* Em */          { NULL, NULL }, /* Em */
         { NULL }, /* Eo */          { NULL, NULL }, /* Eo */
         { NULL }, /* Fx */          { NULL, NULL }, /* Fx */
         { NULL }, /* Ms */          { NULL, NULL }, /* Ms */
         { NULL }, /* No */          { NULL, NULL }, /* No */
         { NULL }, /* Ns */          { NULL, NULL }, /* Ns */
         { NULL }, /* Nx */          { NULL, NULL }, /* Nx */
         { NULL }, /* Ox */          { NULL, NULL }, /* Ox */
         { NULL }, /* Pc */          { NULL, NULL }, /* Pc */
         { NULL }, /* Pf */          { NULL, NULL }, /* Pf */
         { NULL }, /* Po */          { NULL, NULL }, /* Po */
         { NULL }, /* Pq */          { NULL, NULL }, /* Pq */
         { NULL }, /* Qc */          { NULL, NULL }, /* Qc */
         { NULL }, /* Ql */          { NULL, NULL }, /* Ql */
         { NULL }, /* Qo */          { NULL, NULL }, /* Qo */
         { NULL }, /* Qq */          { NULL, NULL }, /* Qq */
         { NULL }, /* Re */          { NULL, NULL }, /* Re */
         { NULL }, /* Rs */          { NULL, NULL }, /* Rs */
         { NULL }, /* Sc */          { NULL, NULL }, /* Sc */
         { NULL }, /* So */          { NULL, NULL }, /* So */
         { NULL }, /* Sq */          { NULL, NULL }, /* Sq */
         { NULL }, /* Sm */          { NULL, NULL }, /* Sm */
         { NULL }, /* Sx */          { NULL, NULL }, /* Sx */
         { NULL }, /* Sy */          { NULL, NULL }, /* Sy */
         { NULL }, /* Tn */          { NULL, NULL }, /* Tn */
         { NULL }, /* Ux */          { NULL, NULL }, /* Ux */
         { NULL }, /* Xc */          { NULL, NULL }, /* Xc */
         { NULL }, /* Xo */          { NULL, NULL }, /* Xo */
         { NULL }, /* Fo */          { NULL, NULL }, /* Fo */
         { NULL }, /* Fc */          { NULL, NULL }, /* Fc */
         { NULL }, /* Oo */          { NULL, NULL }, /* Oo */
         { NULL }, /* Oc */          { NULL, NULL }, /* Oc */
         { NULL }, /* Bk */          { NULL, NULL }, /* Bk */
         { NULL }, /* Ek */          { NULL, NULL }, /* Ek */
         { NULL }, /* Bt */          { NULL, NULL }, /* Bt */
         { NULL }, /* Hf */          { NULL, NULL }, /* Hf */
         { NULL }, /* Fr */          { NULL, NULL }, /* Fr */
         { NULL }, /* Ud */          { NULL, NULL }, /* Ud */
 };  };
   
   
 static int  static int
 action_sh(struct mdoc *mdoc, int tok, int pos)  post_sh(struct mdoc *mdoc)
 {  {
         enum mdoc_sec     sec;          enum mdoc_sec     sec;
         int               i;          int               i;
Line 152  action_sh(struct mdoc *mdoc, int tok, int pos)
Line 157  action_sh(struct mdoc *mdoc, int tok, int pos)
   
         if (MDOC_HEAD != mdoc->last->type)          if (MDOC_HEAD != mdoc->last->type)
                 return(1);                  return(1);
   
           assert(MDOC_Sh == mdoc->last->data.head.tok);
   
         n = mdoc->last->child;          n = mdoc->last->child;
         assert(n);          assert(n);
Line 172  action_sh(struct mdoc *mdoc, int tok, int pos)
Line 179  action_sh(struct mdoc *mdoc, int tok, int pos)
 }  }
   
   
   static int
   post_dt(struct mdoc *mdoc)
   {
   #if 0
           int               lastarg, j;
           char             *args[MDOC_LINEARG_MAX];
   
           if (SEC_PROLOGUE != mdoc->sec_lastn)
                   return(mdoc_err(mdoc, tok, ppos, ERR_SEC_NPROLOGUE));
           if (0 == mdoc->meta.date)
                   return(mdoc_err(mdoc, tok, ppos, ERR_SEC_PROLOGUE_OO));
           if (mdoc->meta.title[0])
                   return(mdoc_err(mdoc, tok, ppos, ERR_SEC_PROLOGUE_REP));
   
           j = -1;
           lastarg = ppos;
   
   again:
           if (j == MDOC_LINEARG_MAX)
                   return(mdoc_err(mdoc, tok, lastarg, ERR_ARGS_MANY));
   
           lastarg = *pos;
   
           switch (mdoc_args(mdoc, tok, pos, buf, 0, &args[++j])) {
           case (ARGS_EOLN):
                   if (mdoc->meta.title)
                           return(1);
                   if ( ! mdoc_warn(mdoc, tok, ppos, WARN_ARGS_GE1))
                           return(0);
                   (void)xstrlcpy(mdoc->meta.title,
                                   "UNTITLED", META_TITLE_SZ);
                   return(1);
           case (ARGS_ERROR):
                   return(0);
           default:
                   break;
           }
   
           if (0 == j) {
                   if (xstrlcpy(mdoc->meta.title, args[0], META_TITLE_SZ))
                           goto again;
                   return(mdoc_err(mdoc, tok, lastarg, ERR_SYNTAX_ARGFORM));
   
           } else if (1 == j) {
                   mdoc->meta.msec = mdoc_atomsec(args[1]);
                   if (MSEC_DEFAULT != mdoc->meta.msec)
                           goto again;
                   return(mdoc_err(mdoc, tok, -1, ERR_SYNTAX_ARGFORM));
   
           } else if (2 == j) {
                   mdoc->meta.vol = mdoc_atovol(args[2]);
                   if (VOL_DEFAULT != mdoc->meta.vol)
                           goto again;
                   mdoc->meta.arch = mdoc_atoarch(args[2]);
                   if (ARCH_DEFAULT != mdoc->meta.arch)
                           goto again;
                   return(mdoc_err(mdoc, tok, lastarg, ERR_SYNTAX_ARGFORM));
           }
   
           return(mdoc_err(mdoc, tok, lastarg, ERR_ARGS_MANY));
   #endif
           return(1);
   }
   
   
   static int
   post_os(struct mdoc *mdoc)
   {
   #if 0
           int               lastarg, j;
           char             *args[MDOC_LINEARG_MAX];
   
           /* FIXME: if we use `Os' again... ? */
   
           if (SEC_PROLOGUE != mdoc->sec_lastn)
                   return(mdoc_err(mdoc, tok, ppos, ERR_SEC_NPROLOGUE));
           if (0 == mdoc->meta.title[0])
                   return(mdoc_err(mdoc, tok, ppos, ERR_SEC_PROLOGUE_OO));
           if (mdoc->meta.os[0])
                   return(mdoc_err(mdoc, tok, ppos, ERR_SEC_PROLOGUE_REP));
   
           j = -1;
           lastarg = ppos;
   
   again:
           if (j == MDOC_LINEARG_MAX)
                   return(mdoc_err(mdoc, tok, lastarg, ERR_ARGS_MANY));
   
           lastarg = *pos;
   
           switch (mdoc_args(mdoc, tok, pos, buf,
                                   ARGS_QUOTED, &args[++j])) {
           case (ARGS_EOLN):
                   mdoc->sec_lastn = mdoc->sec_last = SEC_BODY;
                   return(1);
           case (ARGS_ERROR):
                   return(0);
           default:
                   break;
           }
   
           if ( ! xstrlcat(mdoc->meta.os, args[j], sizeof(mdoc->meta.os)))
                   return(mdoc_err(mdoc, tok, lastarg, ERR_SYNTAX_ARGFORM));
           if ( ! xstrlcat(mdoc->meta.os, " ", sizeof(mdoc->meta.os)))
                   return(mdoc_err(mdoc, tok, lastarg, ERR_SYNTAX_ARGFORM));
   
           goto again;
           /* NOTREACHED */
   #endif
           return(1);
   }
   
   
   static int
   post_dd(struct mdoc *mdoc)
   {
   #if 0
           int               lastarg, j;
           char             *args[MDOC_LINEARG_MAX], date[64];
   
           if (SEC_PROLOGUE != mdoc->sec_lastn)
                   return(mdoc_err(mdoc, tok, ppos, ERR_SEC_NPROLOGUE));
           if (mdoc->meta.title[0])
                   return(mdoc_err(mdoc, tok, ppos, ERR_SEC_PROLOGUE_OO));
           if (mdoc->meta.date)
                   return(mdoc_err(mdoc, tok, ppos, ERR_SEC_PROLOGUE_REP));
   
           j = -1;
           date[0] = 0;
           lastarg = ppos;
   
   again:
           if (j == MDOC_LINEARG_MAX)
                   return(mdoc_err(mdoc, tok, lastarg, ERR_ARGS_MANY));
   
           lastarg = *pos;
           switch (mdoc_args(mdoc, tok, pos, buf, 0, &args[++j])) {
           case (ARGS_EOLN):
                   if (mdoc->meta.date)
                           return(1);
                   mdoc->meta.date = mdoc_atotime(date);
                   if (mdoc->meta.date)
                           return(1);
                   return(mdoc_err(mdoc, tok, ppos, ERR_SYNTAX_ARGFORM));
           case (ARGS_ERROR):
                   return(0);
           default:
                   break;
           }
   
           if (MDOC_MAX != mdoc_find(mdoc, args[j]) && ! mdoc_warn
                           (mdoc, tok, lastarg, WARN_SYNTAX_MACLIKE))
                   return(0);
   
           if (0 == j) {
                   if (xstrcmp("$Mdocdate$", args[j])) {
                           mdoc->meta.date = time(NULL);
                           goto again;
                   } else if (xstrcmp("$Mdocdate:", args[j]))
                           goto again;
           } else if (4 == j)
                   if ( ! xstrcmp("$", args[j]))
                           goto again;
   
           if ( ! xstrlcat(date, args[j], sizeof(date)))
                   return(mdoc_err(mdoc, tok, lastarg, ERR_SYNTAX_ARGFORM));
           if ( ! xstrlcat(date, " ", sizeof(date)))
                   return(mdoc_err(mdoc, tok, lastarg, ERR_SYNTAX_ARGFORM));
   
           goto again;
           /* NOTREACHED */
   #endif
           return(1);
   }
   
   
 int  int
 mdoc_action(struct mdoc *mdoc, int pos)  mdoc_action_pre(struct mdoc *mdoc, struct mdoc_node *node)
 {  {
   
           return(1);
   }
   
   
   int
   mdoc_action_post(struct mdoc *mdoc)
   {
         int              t;          int              t;
   
         switch (mdoc->last->type) {          switch (mdoc->last->type) {
Line 194  mdoc_action(struct mdoc *mdoc, int pos)
Line 385  mdoc_action(struct mdoc *mdoc, int pos)
                 return(1);                  return(1);
         }          }
   
         if (NULL == mdoc_actions[t].action)          if (NULL == mdoc_actions[t].post)
                 return(1);                  return(1);
         /* TODO: MDOC_Nm... ? */          /* TODO: MDOC_Nm... ? */
         return((*mdoc_actions[t].action)(mdoc, t, pos));          return((*mdoc_actions[t].post)(mdoc));
 }  }
   

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

CVSweb