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

Diff for /mandoc/Attic/ascii.c between version 1.1 and 1.4

version 1.1, 2009/03/16 22:19:19 version 1.4, 2009/03/20 21:58:38
Line 33 
Line 33 
  */   */
   
 struct  line {  struct  line {
         const char      *code;          const char       *code;
         const char      *out;          const char       *out;
         /* 32- and 64-bit alignment safe. */          /* 32- and 64-bit alignment safe. */
         size_t           codesz;          size_t            codesz;
         size_t           outsz;          size_t            outsz;
 };  };
   
 struct  linep {  struct  linep {
         const struct line *line;          const struct line *line;
         struct linep    *next;          struct linep     *next;
 };  };
   
 #define LINE(w, x, y, z) \  #define LINE(w, x, y, z) \
Line 51  static const struct line lines[] = {
Line 51  static const struct line lines[] = {
 #include "ascii.in"  #include "ascii.in"
 };  };
   
   struct  asciitab {
           struct linep     *lines;
           void            **htab;
   };
   
 static  inline int       match(const struct line *,  
   static  inline int        match(const struct line *,
                                 const char *, size_t);                                  const char *, size_t);
   
   
   void
   term_asciifree(void *arg)
   {
           struct asciitab *tab;
   
           tab = (struct asciitab *)arg;
   
           free(tab->lines);
           free(tab->htab);
           free(tab);
   }
   
   
 void *  void *
 ascii2htab(void)  term_ascii2htab(void)
 {  {
           struct asciitab  *tab;
         void            **htab;          void            **htab;
         struct linep     *pp, *p;          struct linep     *pp, *p;
         int               i, len, hash;          int               i, len, hash;
Line 70  ascii2htab(void)
Line 89  ascii2htab(void)
          * (they're in-line re-ordered during lookup).           * (they're in-line re-ordered during lookup).
          */           */
   
         assert(0 == sizeof(lines) % sizeof(struct line));          if (NULL == (tab = malloc(sizeof(struct asciitab))))
                   err(1, "malloc");
   
         len = sizeof(lines) / sizeof(struct line);          len = sizeof(lines) / sizeof(struct line);
   
         if (NULL == (p = calloc((size_t)len, sizeof(struct linep))))          if (NULL == (p = calloc((size_t)len, sizeof(struct linep))))
Line 102  ascii2htab(void)
Line 123  ascii2htab(void)
                 pp->next = &p[i];                  pp->next = &p[i];
         }          }
   
         return((void *)htab);          tab->htab = htab;
           tab->lines = p;
   
           return(tab);
 }  }
   
   
 const char *  const char *
 a2ascii(void *htabp, const char *p, size_t sz, size_t *rsz)  term_a2ascii(void *arg, const char *p, size_t sz, size_t *rsz)
 {  {
           struct asciitab  *tab;
         struct linep     *pp, *prev;          struct linep     *pp, *prev;
         void            **htab;          void            **htab;
         int               hash;          int               hash;
   
         htab = (void **)htabp;          tab = (struct asciitab *)arg;
           htab = tab->htab;
   
         assert(p);          assert(p);
         assert(sz > 0);          assert(sz > 0);

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

CVSweb