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

Diff for /mandoc/Attic/mdoc_action.c between version 1.38 and 1.45

version 1.38, 2009/09/24 13:03:32 version 1.45, 2009/10/26 10:36:46
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.
  */   */
   #ifndef OSNAME
 #include <sys/utsname.h>  #include <sys/utsname.h>
   #endif
   
 #include <assert.h>  #include <assert.h>
 #include <errno.h>  #include <errno.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   #include <time.h>
   
 #include "libmdoc.h"  #include "libmdoc.h"
   
Line 32  struct actions {
Line 35  struct actions {
         int     (*post)(POST_ARGS);          int     (*post)(POST_ARGS);
 };  };
   
   static  int       concat(struct mdoc *,
                           const struct mdoc_node *,
                           char *, size_t);
   static  inline int order_rs(int);
   
   #ifdef __linux__
   extern  size_t    strlcat(char *, const char *, size_t);
   #endif
   
 static  int       post_ar(POST_ARGS);  static  int       post_ar(POST_ARGS);
 static  int       post_at(POST_ARGS);  static  int       post_at(POST_ARGS);
 static  int       post_bl(POST_ARGS);  static  int       post_bl(POST_ARGS);
Line 45  static int   post_lb(POST_ARGS);
Line 57  static int   post_lb(POST_ARGS);
 static  int       post_nm(POST_ARGS);  static  int       post_nm(POST_ARGS);
 static  int       post_os(POST_ARGS);  static  int       post_os(POST_ARGS);
 static  int       post_prol(POST_ARGS);  static  int       post_prol(POST_ARGS);
   static  int       post_rs(POST_ARGS);
 static  int       post_sh(POST_ARGS);  static  int       post_sh(POST_ARGS);
 static  int       post_st(POST_ARGS);  static  int       post_st(POST_ARGS);
 static  int       post_std(POST_ARGS);  static  int       post_std(POST_ARGS);
Line 141  static const struct actions mdoc_actions[MDOC_MAX] = {
Line 154  static const struct actions mdoc_actions[MDOC_MAX] = {
         { NULL, NULL }, /* Qo */          { NULL, NULL }, /* Qo */
         { NULL, NULL }, /* Qq */          { NULL, NULL }, /* Qq */
         { NULL, NULL }, /* Re */          { NULL, NULL }, /* Re */
         { NULL, NULL }, /* Rs */          { NULL, post_rs }, /* Rs */
         { NULL, NULL }, /* Sc */          { NULL, NULL }, /* Sc */
         { NULL, NULL }, /* So */          { NULL, NULL }, /* So */
         { NULL, NULL }, /* Sq */          { NULL, NULL }, /* Sq */
Line 164  static const struct actions mdoc_actions[MDOC_MAX] = {
Line 177  static const struct actions mdoc_actions[MDOC_MAX] = {
         { NULL, NULL }, /* Ud */          { NULL, NULL }, /* Ud */
         { NULL, post_lb }, /* Lb */          { NULL, post_lb }, /* Lb */
         { NULL, NULL }, /* Lp */          { NULL, NULL }, /* Lp */
         { NULL, post_tilde }, /* Lk */          { NULL, NULL }, /* Lk */
         { NULL, NULL }, /* Mt */          { NULL, NULL }, /* Mt */
         { NULL, NULL }, /* Brq */          { NULL, NULL }, /* Brq */
         { NULL, NULL }, /* Bro */          { NULL, NULL }, /* Bro */
Line 176  static const struct actions mdoc_actions[MDOC_MAX] = {
Line 189  static const struct actions mdoc_actions[MDOC_MAX] = {
         { NULL, NULL }, /* %Q */          { NULL, NULL }, /* %Q */
         { NULL, NULL }, /* br */          { NULL, NULL }, /* br */
         { NULL, NULL }, /* sp */          { NULL, NULL }, /* sp */
           { NULL, NULL }, /* %U */
 };  };
   
 static  int       concat(struct mdoc *, const struct mdoc_node *,  #define RSORD_MAX 14
                         char *, size_t);  
   
 #ifdef __linux__  static  const int rsord[RSORD_MAX] = {
 extern  size_t    strlcat(char *, const char *, size_t);          MDOC__A,
 #endif          MDOC__T,
           MDOC__B,
           MDOC__I,
           MDOC__J,
           MDOC__R,
           MDOC__N,
           MDOC__V,
           MDOC__P,
           MDOC__Q,
           MDOC__D,
           MDOC__O,
           MDOC__C,
           MDOC__U
   };
   
   
 int  int
Line 499  static int
Line 525  static int
 post_os(POST_ARGS)  post_os(POST_ARGS)
 {  {
         char              buf[64];          char              buf[64];
   #ifndef OSNAME
         struct utsname    utsname;          struct utsname    utsname;
   #endif
   
           /*
            * Setting OSNAME to be the name of the target operating system,
            * e.g., "OpenBSD 4.4", will result in the compile-time constant
            * by supplied instead of the value in uname().
            */
   
         if (m->meta.os)          if (m->meta.os)
                 free(m->meta.os);                  free(m->meta.os);
   
Line 509  post_os(POST_ARGS)
Line 543  post_os(POST_ARGS)
                 return(0);                  return(0);
   
         if (0 == buf[0]) {          if (0 == buf[0]) {
   #ifdef  OSNAME
                   if (strlcat(buf, OSNAME, 64) >= 64)
                           return(mdoc_nerr(m, n, EUTSNAME));
   #else
                 if (-1 == uname(&utsname))                  if (-1 == uname(&utsname))
                         return(mdoc_nerr(m, n, EUTSNAME));                          return(mdoc_nerr(m, n, EUTSNAME));
                 if (strlcat(buf, utsname.sysname, 64) >= 64)                  if (strlcat(buf, utsname.sysname, 64) >= 64)
Line 517  post_os(POST_ARGS)
Line 555  post_os(POST_ARGS)
                         return(mdoc_nerr(m, n, ETOOLONG));                          return(mdoc_nerr(m, n, ETOOLONG));
                 if (strlcat(buf, utsname.release, 64) >= 64)                  if (strlcat(buf, utsname.release, 64) >= 64)
                         return(mdoc_nerr(m, n, ETOOLONG));                          return(mdoc_nerr(m, n, ETOOLONG));
   #endif
         }          }
   
         if (NULL == (m->meta.os = strdup(buf)))          if (NULL == (m->meta.os = strdup(buf)))
Line 736  post_tilde(POST_ARGS)
Line 775  post_tilde(POST_ARGS)
         np = n;          np = n;
         m->next = MDOC_NEXT_CHILD;          m->next = MDOC_NEXT_CHILD;
   
         /* XXX: not documented for `Lk'. */  
         if ( ! mdoc_word_alloc(m, n->line, n->pos, "~"))          if ( ! mdoc_word_alloc(m, n->line, n->pos, "~"))
                 return(0);                  return(0);
         m->last = np;          m->last = np;
Line 899  post_display(POST_ARGS)
Line 937  post_display(POST_ARGS)
 }  }
   
   
   static inline int
   order_rs(int t)
   {
           int             i;
   
           for (i = 0; i < RSORD_MAX; i++)
                   if (rsord[i] == t)
                           return(i);
   
           abort();
           /* NOTREACHED */
   }
   
   
   /* ARGSUSED */
   static int
   post_rs(POST_ARGS)
   {
           struct mdoc_node        *nn, *next, *prev;
           int                      o;
   
           if (MDOC_BLOCK != n->type)
                   return(1);
   
           assert(n->body->child);
           for (next = NULL, nn = n->body->child->next; nn; nn = next) {
                   o = order_rs(nn->tok);
   
                   /* Remove `nn' from the chain. */
                   next = nn->next;
                   if (next)
                           next->prev = nn->prev;
   
                   prev = nn->prev;
                   if (prev)
                           prev->next = nn->next;
   
                   nn->prev = nn->next = NULL;
   
                   /*
                    * Scan back until we reach a node that's ordered before
                    * us, then set ourselves as being the next.
                    */
                   for ( ; prev; prev = prev->prev)
                           if (order_rs(prev->tok) <= o)
                                   break;
   
                   nn->prev = prev;
                   if (prev) {
                           if (prev->next)
                                   prev->next->prev = nn;
                           nn->next = prev->next;
                           prev->next = nn;
                           continue;
                   }
   
                   n->body->child->prev = nn;
                   nn->next = n->body->child;
                   n->body->child = nn;
           }
           return(1);
   }

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.45

CVSweb