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

Diff for /texi2mdoc/main.c between version 1.57 and 1.62

version 1.57, 2015/03/01 16:57:39 version 1.62, 2015/03/05 09:36:41
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 *);
Line 94  static const struct texitok __texitoks[TEXICMD__MAX] =
Line 96  static const struct texitok __texitoks[TEXICMD__MAX] =
         { dosymbol, "*", 1 }, /* TEXICMD_ASTERISK */          { dosymbol, "*", 1 }, /* TEXICMD_ASTERISK */
         { dosymbol, "@", 1 }, /* TEXICMD_AT */          { dosymbol, "@", 1 }, /* TEXICMD_AT */
         { doignline, "author", 6 }, /* TEXICMD_AUTHOR */          { doignline, "author", 6 }, /* TEXICMD_AUTHOR */
         { doinline, "b", 1 }, /* TEXICMD_BOLD */          { doinline, "b", 1 }, /* TEXICMD_B */
           { dosymbol, "\\", 1 }, /* TEXICMD_BACKSLASH */
         { dosymbol, "!", 1 }, /* TEXICMD_BANG */          { dosymbol, "!", 1 }, /* TEXICMD_BANG */
         { dosymbol, "bullet", 6 }, /* TEXICMD_BULLET */          { dosymbol, "bullet", 6 }, /* TEXICMD_BULLET */
         { dobye, "bye", 3 }, /* TEXICMD_BYE */          { dobye, "bye", 3 }, /* TEXICMD_BYE */
Line 114  static const struct texitok __texitoks[TEXICMD__MAX] =
Line 117  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 213  static const struct texitok __texitoks[TEXICMD__MAX] =
Line 216  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 268  static const struct texitok __texitoks[TEXICMD__MAX] =
Line 271  static const struct texitok __texitoks[TEXICMD__MAX] =
         { doaccent, "ringaccent", 10 }, /* TEXICMD_RINGACCENT */          { doaccent, "ringaccent", 10 }, /* TEXICMD_RINGACCENT */
         { doinline, "samp", 4 }, /* TEXICMD_SAMP */          { doinline, "samp", 4 }, /* TEXICMD_SAMP */
         { doinline, "sansserif", 9 }, /* TEXICMD_SANSSERIF */          { doinline, "sansserif", 9 }, /* TEXICMD_SANSSERIF */
         { dobracket, "sc", 2 }, /* TEXICMD_SC */          { doinline, "sc", 2 }, /* TEXICMD_SC */
         { dosection, "section", 7 }, /* TEXICMD_SECTION */          { dosection, "section", 7 }, /* TEXICMD_SECTION */
         { dovalue, "set", 3 }, /* TEXICMD_SET */          { dovalue, "set", 3 }, /* TEXICMD_SET */
         { doignline, "setchapternewpage", 17 }, /* TEXICMD_SETCHAPNEWPAGE */          { doignline, "setchapternewpage", 17 }, /* TEXICMD_SETCHAPNEWPAGE */
Line 341  static const struct texitok __texitoks[TEXICMD__MAX] =
Line 344  static const struct texitok __texitoks[TEXICMD__MAX] =
   
 const   struct texitok *const texitoks = __texitoks;  const   struct texitok *const texitoks = __texitoks;
   
   /*
    * Texinfo has lots of indexes.
    * You can add new ones in a variety of ways.
    * We maintain an array of all of these index names (usually a few
    * letters) and pass unknown commands through the array list.
    */
 static void  static void
 dodefindex(struct texi *p, enum texicmd cmd, size_t *pos)  dodefindex(struct texi *p, enum texicmd cmd, size_t *pos)
 {  {
Line 349  dodefindex(struct texi *p, enum texicmd cmd, size_t *p
Line 358  dodefindex(struct texi *p, enum texicmd cmd, size_t *p
   
         while (*pos < BUFSZ(p) && isws(BUF(p)[*pos]))          while (*pos < BUFSZ(p) && isws(BUF(p)[*pos]))
                 advance(p, pos);                  advance(p, pos);
   
         start = end = *pos;          start = end = *pos;
         while (end < BUFSZ(p) && ! ismspace(BUF(p)[end]))          while (end < BUFSZ(p) && ! ismspace(BUF(p)[end]))
                 end++;                  end++;
Line 357  dodefindex(struct texi *p, enum texicmd cmd, size_t *p
Line 365  dodefindex(struct texi *p, enum texicmd cmd, size_t *p
         if (start == end) {          if (start == end) {
                 advanceeoln(p, pos, 1);                  advanceeoln(p, pos, 1);
                 return;                  return;
         } else if (NULL == (cp = malloc(end - start + 1)))          }
   
           if (NULL == (cp = malloc(end - start + 1)))
                 texiabort(p, NULL);                  texiabort(p, NULL);
   
         memcpy(cp, &BUF(p)[start], end - start);          memcpy(cp, &BUF(p)[start], end - start);
         cp[end - start] = '\0';          cp[end - start] = '\0';
   
           /* FIXME: use reallocarray(). */
         p->indexs = realloc(p->indexs,          p->indexs = realloc(p->indexs,
                 sizeof(char *) * (p->indexsz + 1));                  sizeof(char *) * (p->indexsz + 1));
   
         if (NULL == p->indexs)          if (NULL == p->indexs)
                 texiabort(p, NULL);                  texiabort(p, NULL);
         p->indexs[p->indexsz++] = cp;          p->indexs[p->indexsz++] = cp;
   
           advanceeoln(p, pos, 1);
 }  }
   
 static void  static void
Line 533  dodefn(struct texi *p, enum texicmd cmd, size_t *pos)
Line 544  dodefn(struct texi *p, enum texicmd cmd, size_t *pos)
                 break;                  break;
         }          }
         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 725  doinline(struct texi *p, enum texicmd cmd, size_t *pos
Line 736  doinline(struct texi *p, enum texicmd cmd, size_t *pos
         }          }
   
         if (NULL == macro || p->literal || TEXILIST_TABLE == p->list) {          if (NULL == macro || p->literal || TEXILIST_TABLE == p->list) {
                   if (TEXICMD_SC == cmd)
                           p->uppercase++;
                 parsebracket(p, pos, 0);                  parsebracket(p, pos, 0);
                   if (TEXICMD_SC == cmd)
                           p->uppercase--;
                 return;                  return;
         }          }
   
           /*
            * If we haven't seen any whitespace, then we don't want the
            * subsequent macro to insert any whitespace.
            */
           if (p->outmacro && 0 == p->seenws) {
                   teximacroopen(p, "Ns");
                   teximacroclose(p);
           }
   
         teximacroopen(p, macro);          teximacroopen(p, macro);
         p->seenws = 0;          p->seenws = 0;
           if (TEXICMD_SC == cmd)
                   p->uppercase++;
         parsebracket(p, pos, 0);          parsebracket(p, pos, 0);
           if (TEXICMD_SC == cmd)
                   p->uppercase--;
         texipunctuate(p, pos);          texipunctuate(p, pos);
         teximacroclose(p);          teximacroclose(p);
 }  }
Line 775  doverb(struct texi *p, enum texicmd cmd, size_t *pos)
Line 803  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 785  doverbatim(struct texi *p, enum texicmd cmd, size_t *p
Line 860  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 805  doverbatim(struct texi *p, enum texicmd cmd, size_t *p
Line 880  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 954  dodisplay(struct texi *p, enum texicmd cmd, size_t *po
Line 1030  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 970  doexample(struct texi *p, enum texicmd cmd, size_t *po
Line 1046  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 1196  dosymbol(struct texi *p, enum texicmd cmd, size_t *pos
Line 1273  dosymbol(struct texi *p, enum texicmd cmd, size_t *pos
         case (TEXICMD_AT):          case (TEXICMD_AT):
                 texiputchar(p, '@');                  texiputchar(p, '@');
                 break;                  break;
           case (TEXICMD_BACKSLASH):
                   texiputchar(p, '\\');
                   break;
         case (TEXICMD_BANG):          case (TEXICMD_BANG):
                 texiputchar(p, '!');                  texiputchar(p, '!');
                 break;                  break;
Line 1590  dosection(struct texi *p, enum texicmd cmd, size_t *po
Line 1670  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 1644  doitem(struct texi *p, enum texicmd cmd, size_t *pos)
Line 1723  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 1741  dotable(struct texi *p, enum texicmd cmd, size_t *pos)
Line 1819  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 1772  doenumerate(struct texi *p, enum texicmd cmd, size_t *
Line 1850  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 1787  doitemize(struct texi *p, enum texicmd cmd, size_t *po
Line 1865  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.57  
changed lines
  Added in v.1.62

CVSweb