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

Diff for /texi2mdoc/main.c between version 1.60 and 1.65

version 1.60, 2015/03/05 08:18:56 version 1.65, 2015/03/09 18:54:38
Line 42  static void doaccent(struct texi *, enum texicmd, size
Line 42  static void doaccent(struct texi *, enum texicmd, size
 static  void doblock(struct texi *, enum texicmd, size_t *);  static  void doblock(struct texi *, enum texicmd, size_t *);
 static  void dobracket(struct texi *, enum texicmd, size_t *);  static  void dobracket(struct texi *, enum texicmd, size_t *);
 static  void dobye(struct texi *, enum texicmd, size_t *);  static  void dobye(struct texi *, enum texicmd, size_t *);
   static  void docopying(struct texi *, enum texicmd, size_t *);
 static  void dodefindex(struct texi *, enum texicmd, size_t *);  static  void dodefindex(struct texi *, enum texicmd, size_t *);
 static  void dodefn(struct texi *, enum texicmd, size_t *);  static  void dodefn(struct texi *, enum texicmd, size_t *);
 static  void dodisplay(struct texi *, enum texicmd, size_t *);  static  void dodisplay(struct texi *, enum texicmd, size_t *);
Line 54  static void doignbracket(struct texi *, enum texicmd, 
Line 55  static void doignbracket(struct texi *, enum texicmd, 
 static  void doignline(struct texi *, enum texicmd, size_t *);  static  void doignline(struct texi *, enum texicmd, size_t *);
 static  void doinline(struct texi *, enum texicmd, size_t *);  static  void doinline(struct texi *, enum texicmd, size_t *);
 static  void doinclude(struct texi *, enum texicmd, size_t *);  static  void doinclude(struct texi *, enum texicmd, size_t *);
   static  void doinsertcopying(struct texi *, enum texicmd, size_t *);
 static  void doitem(struct texi *, enum texicmd, size_t *);  static  void doitem(struct texi *, enum texicmd, size_t *);
 static  void doitemize(struct texi *, enum texicmd, size_t *);  static  void doitemize(struct texi *, enum texicmd, size_t *);
 static  void dolink(struct texi *, enum texicmd, size_t *);  static  void dolink(struct texi *, enum texicmd, size_t *);
 static  void domacro(struct texi *, enum texicmd, size_t *);  static  void domacro(struct texi *, enum texicmd, size_t *);
 static  void domath(struct texi *, enum texicmd, size_t *);  static  void domath(struct texi *, enum texicmd, size_t *);
   #if 0
   static  void domenu(struct texi *, enum texicmd, size_t *);
   #endif
 static  void domultitable(struct texi *, enum texicmd, size_t *);  static  void domultitable(struct texi *, enum texicmd, size_t *);
   #if 0
   static  void donode(struct texi *, enum texicmd, size_t *);
   #endif
 static  void doquotation(struct texi *, enum texicmd, size_t *);  static  void doquotation(struct texi *, enum texicmd, size_t *);
 static  void dotable(struct texi *, enum texicmd, size_t *);  static  void dotable(struct texi *, enum texicmd, size_t *);
 static  void dotop(struct texi *, enum texicmd, size_t *);  static  void dotop(struct texi *, enum texicmd, size_t *);
Line 115  static const struct texitok __texitoks[TEXICMD__MAX] =
Line 123  static const struct texitok __texitoks[TEXICMD__MAX] =
         { doignline, "c", 1 }, /* TEXICMD_COMMENT */          { doignline, "c", 1 }, /* TEXICMD_COMMENT */
         { doignline, "comment", 7 }, /* TEXICMD_COMMENT_LONG */          { doignline, "comment", 7 }, /* TEXICMD_COMMENT_LONG */
         { doignline, "contents", 8 }, /* TEXICMD_CONTENTS */          { doignline, "contents", 8 }, /* TEXICMD_CONTENTS */
         { doignblock, "copying", 7 }, /* TEXICMD_COPYING */          { docopying, "copying", 7 }, /* TEXICMD_COPYING */
         { dosymbol, "copyright", 9 }, /* TEXICMD_COPYRIGHT */          { dosymbol, "copyright", 9 }, /* TEXICMD_COPYRIGHT */
         { dodefindex, "defcodeindex", 12 }, /* TEXICMD_DEFCODEINDEX */          { dodefindex, "defcodeindex", 12 }, /* TEXICMD_DEFCODEINDEX */
         { dodefn, "deffn", 5 }, /* TEXICMD_DEFFN */          { dodefn, "deffn", 5 }, /* TEXICMD_DEFFN */
Line 214  static const struct texitok __texitoks[TEXICMD__MAX] =
Line 222  static const struct texitok __texitoks[TEXICMD__MAX] =
         { dodisplay, "indentblock", 11 }, /* TEXICMD_INDENTBLOCK */          { dodisplay, "indentblock", 11 }, /* TEXICMD_INDENTBLOCK */
         { dolink, "indicateurl", 11 }, /* TEXICMD_INDICATEURL */          { dolink, "indicateurl", 11 }, /* TEXICMD_INDICATEURL */
         { dolink, "inforef", 7 }, /* TEXICMD_INFOREF */          { dolink, "inforef", 7 }, /* TEXICMD_INFOREF */
         { doignline, "insertcopying", 13 }, /* TEXICMD_INSERTCOPYING */          { doinsertcopying, "insertcopying", 13 }, /* TEXICMD_INSERTCOPYING */
         { doitem, "item", 4 }, /* TEXICMD_ITEM */          { doitem, "item", 4 }, /* TEXICMD_ITEM */
         { doitemize, "itemize", 7 }, /* TEXICMD_ITEMIZE */          { doitemize, "itemize", 7 }, /* TEXICMD_ITEMIZE */
         { doitem, "itemx", 5 }, /* TEXICMD_ITEMX */          { doitem, "itemx", 5 }, /* TEXICMD_ITEMX */
Line 229  static const struct texitok __texitoks[TEXICMD__MAX] =
Line 237  static const struct texitok __texitoks[TEXICMD__MAX] =
         { domacro, "macro", 5 }, /* TEXICMD_MACRO */          { domacro, "macro", 5 }, /* TEXICMD_MACRO */
         { doaccent, "=", 1 }, /* TEXICMD_MACRON */          { doaccent, "=", 1 }, /* TEXICMD_MACRON */
         { domath, "math", 4 }, /* TEXICMD_MATH */          { domath, "math", 4 }, /* TEXICMD_MATH */
   #if 0
           { domenu, "menu", 4 }, /* TEXICMD_MENU */
   #else
         { doignblock, "menu", 4 }, /* TEXICMD_MENU */          { doignblock, "menu", 4 }, /* TEXICMD_MENU */
   #endif
         { dosymbol, "minus", 5 }, /* TEXICMD_MINUS */          { dosymbol, "minus", 5 }, /* TEXICMD_MINUS */
         { domultitable, "multitable", 10 }, /* TEXICMD_MULTITABLE */          { domultitable, "multitable", 10 }, /* TEXICMD_MULTITABLE */
         { doignline, "need", 4 }, /* TEXICMD_NEED */          { doignline, "need", 4 }, /* TEXICMD_NEED */
         { dosymbol, "\n", 1 }, /* TEXICMD_NEWLINE */          { dosymbol, "\n", 1 }, /* TEXICMD_NEWLINE */
   #if 0
           { donode, "node", 4 }, /* TEXICMD_NODE */
   #else
         { doignline, "node", 4 }, /* TEXICMD_NODE */          { doignline, "node", 4 }, /* TEXICMD_NODE */
   #endif
         { doignline, "noindent", 8 }, /* TEXICMD_NOINDENT */          { doignline, "noindent", 8 }, /* TEXICMD_NOINDENT */
         { dosymbol, "O", 1 }, /* TEXICMD_O */          { dosymbol, "O", 1 }, /* TEXICMD_O */
         { dosymbol, "OE", 2 }, /* TEXICMD_OE */          { dosymbol, "OE", 2 }, /* TEXICMD_OE */
Line 541  dodefn(struct texi *p, enum texicmd cmd, size_t *pos)
Line 557  dodefn(struct texi *p, enum texicmd cmd, size_t *pos)
                 }                  }
                 break;                  break;
         }          }
   
           if (TEXICMD_END == peekcmd(p, *pos)) {
                   parseto(p, pos, blk);
                   return;
           }
   
         teximacro(p, "Bd -filled -offset indent");          teximacro(p, "Bd -filled -offset indent");
         p->seenvs = 1;  
         parseto(p, pos, blk);          parseto(p, pos, blk);
         teximacro(p, "Ed");          teximacro(p, "Ed");
           p->seenvs = 1;
 }  }
   
 static void  static void
Line 753  doinline(struct texi *p, enum texicmd cmd, size_t *pos
Line 775  doinline(struct texi *p, enum texicmd cmd, size_t *pos
   
         teximacroopen(p, macro);          teximacroopen(p, macro);
         p->seenws = 0;          p->seenws = 0;
           if (TEXICMD_CODE == cmd)
                   p->literal++;
         if (TEXICMD_SC == cmd)          if (TEXICMD_SC == cmd)
                 p->uppercase++;                  p->uppercase++;
         parsebracket(p, pos, 0);          parsebracket(p, pos, 0);
         if (TEXICMD_SC == cmd)          if (TEXICMD_SC == cmd)
                 p->uppercase--;                  p->uppercase--;
           if (TEXICMD_CODE == cmd)
                   p->literal--;
         texipunctuate(p, pos);          texipunctuate(p, pos);
         teximacroclose(p);          teximacroclose(p);
 }  }
Line 801  doverb(struct texi *p, enum texicmd cmd, size_t *pos)
Line 827  doverb(struct texi *p, enum texicmd cmd, size_t *pos)
 }  }
   
 static void  static void
   doinsertcopying(struct texi *p, enum texicmd cmd, size_t *pos)
   {
   
           advanceeoln(p, pos, 0);
           if (NULL == p->copying)
                   return;
           texisplice(p, p->copying, p->copyingsz, *pos);
   }
   
   static void
   docopying(struct texi *p, enum texicmd cmd, size_t *pos)
   {
           const char      *end, *term;
           size_t           endsz, endpos;
   
           /* We retain our starting (but not ending) newlines. */
           end = "\n@end copying\n";
           endsz = strlen(end);
           advanceeoln(p, pos, 0);
           if (*pos == BUFSZ(p)) {
                   texiwarn(p, "unterminated \"%s\"", texitoks[cmd].tok);
                   return;
           }
   
           term = memmem(&BUF(p)[*pos], BUFSZ(p) - *pos, end, endsz);
           if (NULL == term) {
                   texiwarn(p, "unterminated \"%s\"", texitoks[cmd].tok);
                   endpos = BUFSZ(p);
           } else
                   endpos = *pos + (size_t)(term - &BUF(p)[*pos]);
   
           assert(endpos <= BUFSZ(p));
           assert('\n' == BUF(p)[*pos]);
           advance(p, pos);
   
           p->copying = malloc(endpos - *pos + 1);
           p->copyingsz = endpos - *pos;
           memcpy(p->copying, &BUF(p)[*pos], p->copyingsz);
           p->copying[endpos - *pos] = '\0';
   
           while (*pos < endpos)
                   advance(p, pos);
           if (*pos < BUFSZ(p))
                   advanceto(p, pos, endpos + endsz);
   }
   
   static void
 doverbatim(struct texi *p, enum texicmd cmd, size_t *pos)  doverbatim(struct texi *p, enum texicmd cmd, size_t *pos)
 {  {
         const char      *end, *term;          const char      *end, *term;
Line 811  doverbatim(struct texi *p, enum texicmd cmd, size_t *p
Line 884  doverbatim(struct texi *p, enum texicmd cmd, size_t *p
         endsz = strlen(end);          endsz = strlen(end);
         advanceeoln(p, pos, 0);          advanceeoln(p, pos, 0);
         if (*pos == BUFSZ(p)) {          if (*pos == BUFSZ(p)) {
                 texiwarn(p, "unexpected end of file");                  texiwarn(p, "unterminated \"%s\"", texitoks[cmd].tok);
                 return;                  return;
         }          }
   
         term = memmem(&BUF(p)[*pos], BUFSZ(p) - *pos, end, endsz);          term = memmem(&BUF(p)[*pos], BUFSZ(p) - *pos, end, endsz);
         if (NULL == term) {          if (NULL == term) {
                 texiwarn(p, "unterminated verbatim block");                  texiwarn(p, "unterminated \"%s\"", texitoks[cmd].tok);
                 endpos = BUFSZ(p);                  endpos = BUFSZ(p);
         } else          } else
                 endpos = *pos + (size_t)(term - &BUF(p)[*pos]);                  endpos = *pos + (size_t)(term - &BUF(p)[*pos]);
Line 831  doverbatim(struct texi *p, enum texicmd cmd, size_t *p
Line 904  doverbatim(struct texi *p, enum texicmd cmd, size_t *p
                 advance(p, pos);                  advance(p, pos);
         }          }
         teximacro(p, "Ed");          teximacro(p, "Ed");
           p->seenvs = 1;
         if (*pos < BUFSZ(p))          if (*pos < BUFSZ(p))
                 advanceto(p, pos, endpos + endsz);                  advanceto(p, pos, endpos + endsz);
 }  }
Line 980  dodisplay(struct texi *p, enum texicmd cmd, size_t *po
Line 1054  dodisplay(struct texi *p, enum texicmd cmd, size_t *po
                 break;                  break;
         }          }
   
         p->seenvs = 1;  
         parseto(p, pos, texitoks[cmd].tok);          parseto(p, pos, texitoks[cmd].tok);
         teximacro(p, "Ed");          teximacro(p, "Ed");
           p->seenvs = 1;
 }  }
   
 static void  static void
Line 996  doexample(struct texi *p, enum texicmd cmd, size_t *po
Line 1070  doexample(struct texi *p, enum texicmd cmd, size_t *po
         parseto(p, pos, texitoks[cmd].tok);          parseto(p, pos, texitoks[cmd].tok);
         p->literal--;          p->literal--;
         teximacro(p, "Ed");          teximacro(p, "Ed");
           p->seenvs = 1;
 }  }
   
 static void  static void
Line 1396  doquotation(struct texi *p, enum texicmd cmd, size_t *
Line 1471  doquotation(struct texi *p, enum texicmd cmd, size_t *
         teximacro(p, "Qc");          teximacro(p, "Qc");
 }  }
   
   #if 0
 static void  static void
   donode(struct texi *p, enum texicmd cmd, size_t *pos)
   {
   
           teximacroopen(p, "Ix");
           texiputchars(p, "Node");
           while (*pos < BUFSZ(p) && isspace(BUF(p)[*pos]))
                   advance(p, pos);
           while (*pos < BUFSZ(p)) {
                   if (BUF(p)[*pos] == ',')
                           break;
                   else if (BUF(p)[*pos] == '\n')
                           break;
                   texiputchar(p, BUF(p)[*pos]);
                   advance(p, pos);
           }
   
           teximacroclose(p);
           advanceeoln(p, pos, 1);
   }
   
   static void
   domenu(struct texi *p, enum texicmd cmd, size_t *pos)
   {
           size_t   start, sv;
   
           if (NULL != p->chapters) {
                   doignblock(p, cmd, pos);
                   return;
           }
   
           advanceeoln(p, pos, 1);
   
           texivspace(p);
           teximacro(p, "Bl -tag -width Ds -compact");
           while (*pos < BUFSZ(p)) {
                   /* Read to next menu item. */
                   while (*pos < BUFSZ(p) && ismspace(BUF(p)[*pos]))
                           advance(p, pos);
                   if ('*' != BUF(p)[*pos])
                           break;
   
                   assert('*' == BUF(p)[*pos]);
                   advance(p, pos);
                   while (*pos < BUFSZ(p) && ismspace(BUF(p)[*pos]))
                           advance(p, pos);
                   sv = start = *pos;
                   while (*pos < BUFSZ(p) && ':' != BUF(p)[*pos])
                           advance(p, pos);
                   if (*pos == BUFSZ(p) || *pos == start) {
                           texiwarn(p, "empty menu name");
                           break;
                   }
                   teximacroopen(p, "It");
                   teximacroopen(p, "Lkx");
                   texiputchar(p, '"');
                   texiputchars(p, "Node");
                   for (start = sv; start < *pos; start++)
                           texiputchar(p, BUF(p)[start]);
                   texiputchars(p, "\" \"");
                   for (start = sv; start < *pos; start++)
                           texiputchar(p, BUF(p)[start]);
                   texiputchar(p, '"');
                   teximacroclose(p);
                   teximacroclose(p);
   
                   advance(p, pos);
                   if (*pos == BUFSZ(p)) {
                           texiwarn(p, "bad menu syntax");
                           break;
                   } else if (':' != BUF(p)[*pos]) {
                           while (*pos < BUFSZ(p) && isws(BUF(p)[*pos]))
                                   advance(p, pos);
                           start = *pos;
                           while (*pos < BUFSZ(p)) {
                                   switch (BUF(p)[*pos]) {
                                   case ('\t'):
                                   case ('\n'):
                                   case (','):
                                           break;
                                   case ('.'):
                                           if (*pos + 1 == BUFSZ(p)) {
                                                   advance(p, pos);
                                                   continue;
                                           }
                                           if (' ' == BUF(p)[*pos + 1]) {
                                                   advance(p, pos);
                                                   break;
                                           }
                                           /* FALLTHROUGH */
                                   default:
                                           advance(p, pos);
                                           continue;
                                   }
                                   advance(p, pos);
                                   break;
                           }
                   } else
                           advance(p, pos);
   
                   while (*pos < BUFSZ(p) && isws(BUF(p)[*pos]))
                           advance(p, pos);
   
                   if (*pos == BUFSZ(p)) {
                           texiwarn(p, "bad menu syntax");
                           break;
                   }
   
                   while (*pos < BUFSZ(p)) {
                           if ('*' == BUF(p)[*pos])
                                   break;
                           if ('\n' != BUF(p)[*pos]) {
                                   texiputchar(p, BUF(p)[*pos]);
                                   advance(p, pos);
                                   continue;
                           }
                           advance(p, pos);
                           while (*pos == BUFSZ(p)) {
                                   texiwarn(p, "bad menu syntax");
                                   break;
                           }
                           if ('\n' == BUF(p)[*pos]) {
                                   advance(p, pos);
                                   break;
                           } else if ('*' == BUF(p)[*pos]) {
                                   continue;
                           } else if ('@' == BUF(p)[*pos])
                                   break;
                           texiputchar(p, ' ');
                   }
           }
   
           teximacro(p, "El");
   
           doignblock(p, cmd, pos);
   }
   #endif
   
   static void
 domath(struct texi *p, enum texicmd cmd, size_t *pos)  domath(struct texi *p, enum texicmd cmd, size_t *pos)
 {  {
   
Line 1619  dosection(struct texi *p, enum texicmd cmd, size_t *po
Line 1833  dosection(struct texi *p, enum texicmd cmd, size_t *po
         teximacroopen(p, sects[sec]);          teximacroopen(p, sects[sec]);
         parseeoln(p, pos);          parseeoln(p, pos);
         teximacroclose(p);          teximacroclose(p);
         p->seenvs = 1;  
 }  }
   
 static void  static void
Line 1651  doitem(struct texi *p, enum texicmd cmd, size_t *pos)
Line 1864  doitem(struct texi *p, enum texicmd cmd, size_t *pos)
   
         /* Multitable is using raw tbl(7). */          /* Multitable is using raw tbl(7). */
         if (TEXILIST_TABLE == p->list) {          if (TEXILIST_TABLE == p->list) {
                 texiputchar(p, '\n');                  if (p->outcol > 0)
                           texiputchar(p, '\n');
                 return;                  return;
         }          }
   
Line 1673  doitem(struct texi *p, enum texicmd cmd, size_t *pos)
Line 1887  doitem(struct texi *p, enum texicmd cmd, size_t *pos)
         }          }
   
         /* Trick so we don't start with Pp. */          /* Trick so we don't start with Pp. */
         p->seenvs = 1;  
         parseeoln(p, pos);          parseeoln(p, pos);
   
         if (TEXILIST_ITEM == p->list)          if (TEXILIST_ITEM == p->list)
Line 1687  dotab(struct texi *p, enum texicmd cmd, size_t *pos)
Line 1900  dotab(struct texi *p, enum texicmd cmd, size_t *pos)
 {  {
   
         /* This command is only useful in @multitable. */          /* This command is only useful in @multitable. */
         if (TEXILIST_TABLE == p->list)          if (TEXILIST_TABLE == p->list && p->outcol)
                 texiputchar(p, '\t');                  texiputchar(p, '\t');
 }  }
   
Line 1699  domultitable(struct texi *p, enum texicmd cmd, size_t 
Line 1912  domultitable(struct texi *p, enum texicmd cmd, size_t 
         enum texicmd    type;          enum texicmd    type;
         size_t          i, end, columns;          size_t          i, end, columns;
   
           texivspace(p);
         p->list = TEXILIST_TABLE;          p->list = TEXILIST_TABLE;
         /*          /*
          * TS/TE blocks aren't "in mdoc(7)", so we can disregard the           * TS/TE blocks aren't "in mdoc(7)", so we can disregard the
Line 1752  domultitable(struct texi *p, enum texicmd cmd, size_t 
Line 1966  domultitable(struct texi *p, enum texicmd cmd, size_t 
                         texiputchar(p, ' ');                          texiputchar(p, ' ');
                 texiputchar(p, 'l');                  texiputchar(p, 'l');
         }          }
         texiputchars(p, ".\n");  
           texiputchar(p, '.');
           texiputchar(p, '\n');
         p->outmacro++;          p->outmacro++;
         parseto(p, pos, texitoks[cmd].tok);          parseto(p, pos, texitoks[cmd].tok);
         p->outmacro--;          p->outmacro--;
Line 1770  dotable(struct texi *p, enum texicmd cmd, size_t *pos)
Line 1986  dotable(struct texi *p, enum texicmd cmd, size_t *pos)
   
         p->list = TEXILIST_ITEM;          p->list = TEXILIST_ITEM;
         teximacro(p, "Bl -tag -width Ds");          teximacro(p, "Bl -tag -width Ds");
         p->seenvs = 1;  
         parseto(p, pos, texitoks[cmd].tok);          parseto(p, pos, texitoks[cmd].tok);
         teximacro(p, "El");          teximacro(p, "El");
           p->seenvs = 1;
         p->list = sv;          p->list = sv;
 }  }
   
Line 1801  doenumerate(struct texi *p, enum texicmd cmd, size_t *
Line 2017  doenumerate(struct texi *p, enum texicmd cmd, size_t *
   
         p->list = TEXILIST_NOITEM;          p->list = TEXILIST_NOITEM;
         teximacro(p, "Bl -enum");          teximacro(p, "Bl -enum");
         p->seenvs = 1;  
         parseto(p, pos, texitoks[cmd].tok);          parseto(p, pos, texitoks[cmd].tok);
         teximacro(p, "El");          teximacro(p, "El");
           p->seenvs = 1;
         p->list = sv;          p->list = sv;
 }  }
   
Line 1816  doitemize(struct texi *p, enum texicmd cmd, size_t *po
Line 2032  doitemize(struct texi *p, enum texicmd cmd, size_t *po
   
         p->list = TEXILIST_NOITEM;          p->list = TEXILIST_NOITEM;
         teximacro(p, "Bl -bullet");          teximacro(p, "Bl -bullet");
         p->seenvs = 1;  
         parseto(p, pos, texitoks[cmd].tok);          parseto(p, pos, texitoks[cmd].tok);
         teximacro(p, "El");          teximacro(p, "El");
           p->seenvs = 1;
         p->list = sv;          p->list = sv;
 }  }
   

Legend:
Removed from v.1.60  
changed lines
  Added in v.1.65

CVSweb