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

Diff for /texi2mdoc/main.c between version 1.43 and 1.45

version 1.43, 2015/02/24 20:34:43 version 1.45, 2015/02/25 10:01:54
Line 45  static void dobye(struct texi *, enum texicmd, const c
Line 45  static void dobye(struct texi *, enum texicmd, const c
 static  void dodefindex(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void dodefindex(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void dodefn(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void dodefn(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void dodisplay(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void dodisplay(struct texi *, enum texicmd, const char *, size_t, size_t *);
   static  void doend(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void doenumerate(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void doenumerate(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void doexample(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void doexample(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void doignargn(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void doignargn(struct texi *, enum texicmd, const char *, size_t, size_t *);
Line 149  static const struct texitok __texitoks[TEXICMD__MAX] =
Line 150  static const struct texitok __texitoks[TEXICMD__MAX] =
         { doignbracket, "dmn", 3 }, /* TEXICMD_DMN */          { doignbracket, "dmn", 3 }, /* TEXICMD_DMN */
         { doignblock, "documentdescription", 19 }, /* TEXICMD_DOCUMENTDESCRIPTION */          { doignblock, "documentdescription", 19 }, /* TEXICMD_DOCUMENTDESCRIPTION */
         { doignline, "documentencoding", 16 }, /* TEXICMD_DOCUMENTENCODING */          { doignline, "documentencoding", 16 }, /* TEXICMD_DOCUMENTENCODING */
           { doignline, "documentlanguage", 16 }, /* TEXICMD_DOCUMENTLANGUAGE */
         { doaccent, "dotaccent", 9 }, /* TEXICMD_DOTACCENT */          { doaccent, "dotaccent", 9 }, /* TEXICMD_DOTACCENT */
         { doaccent, "dotless", 7 }, /* TEXICMD_DOTLESS */          { doaccent, "dotless", 7 }, /* TEXICMD_DOTLESS */
         { dosymbol, "dots", 4 }, /* TEXICMD_DOTS */          { dosymbol, "dots", 4 }, /* TEXICMD_DOTS */
         { dolink, "email", 5 }, /* TEXICMD_EMAIL */          { dolink, "email", 5 }, /* TEXICMD_EMAIL */
         { doinline, "emph", 4 }, /* TEXICMD_EMPH */          { doinline, "emph", 4 }, /* TEXICMD_EMPH */
         { NULL, "end", 3 }, /* TEXICMD_END */          { doend, "end", 3 }, /* TEXICMD_END */
         { dosymbol, "enddots", 7 }, /* TEXICMD_ENDDOTS */          { dosymbol, "enddots", 7 }, /* TEXICMD_ENDDOTS */
         { doenumerate, "enumerate", 9 }, /* TEXICMD_ENUMERATE */          { doenumerate, "enumerate", 9 }, /* TEXICMD_ENUMERATE */
         { doinline, "env", 3 }, /* TEXICMD_ENV */          { doinline, "env", 3 }, /* TEXICMD_ENV */
Line 168  static const struct texitok __texitoks[TEXICMD__MAX] =
Line 170  static const struct texitok __texitoks[TEXICMD__MAX] =
         { doinline, "file", 4 }, /* TEXICMD_FILE */          { doinline, "file", 4 }, /* TEXICMD_FILE */
         { doignline, "finalout", 8 }, /* TEXICMD_FINALOUT */          { doignline, "finalout", 8 }, /* TEXICMD_FINALOUT */
         { doignline, "findex", 6 }, /* TEXICMD_FINDEX */          { doignline, "findex", 6 }, /* TEXICMD_FINDEX */
           { doblock, "flushleft", 9 }, /* TEXICMD_FLUSHLEFT */
           { doblock, "flushright", 10 }, /* TEXICMD_FLUSHRIGHT */
           { doignline, "firstparagraphindent", 20 }, /* TEXICMD_FIRSTPARAGRAPHINDENT */
         { doignbracket, "footnote", 8 }, /* TEXICMD_FOOTNOTE */          { doignbracket, "footnote", 8 }, /* TEXICMD_FOOTNOTE */
           { doignline, "footnotestyle", 13 }, /* TEXICMD_FOOTNOTESTYLE */
         { dotable, "ftable", 6 }, /* TEXICMD_FTABLE */          { dotable, "ftable", 6 }, /* TEXICMD_FTABLE */
         { dodisplay, "format", 6 }, /* TEXICMD_FORMAT */          { dodisplay, "format", 6 }, /* TEXICMD_FORMAT */
         { dosymbol, "geq", 3 }, /* TEXICMD_GEQ */          { dosymbol, "geq", 3 }, /* TEXICMD_GEQ */
Line 205  static const struct texitok __texitoks[TEXICMD__MAX] =
Line 211  static const struct texitok __texitoks[TEXICMD__MAX] =
         { doignbracket, "image", 5 }, /* TEXICMD_IMAGE */          { doignbracket, "image", 5 }, /* TEXICMD_IMAGE */
         { doinclude, "include", 7 }, /* TEXICMD_INCLUDE */          { doinclude, "include", 7 }, /* TEXICMD_INCLUDE */
         { dodisplay, "indentblock", 11 }, /* TEXICMD_INDENTBLOCK */          { dodisplay, "indentblock", 11 }, /* TEXICMD_INDENTBLOCK */
         { dolink, "inforef", 7 }, /* TEXICMD_INDENTBLOCK */          { dolink, "indicateurl", 11 }, /* TEXICMD_INDICATEURL */
           { dolink, "inforef", 7 }, /* TEXICMD_INFOREF */
         { doignline, "insertcopying", 13 }, /* TEXICMD_INSERTCOPYING */          { doignline, "insertcopying", 13 }, /* TEXICMD_INSERTCOPYING */
         { doitem, "item", 4 }, /* TEXICMD_ITEM */          { doitem, "item", 4 }, /* TEXICMD_ITEM */
         { doitemize, "itemize", 7 }, /* TEXICMD_ITEMIZE */          { doitemize, "itemize", 7 }, /* TEXICMD_ITEMIZE */
Line 530  domacro(struct texi *p, enum texicmd cmd, 
Line 537  domacro(struct texi *p, enum texicmd cmd, 
         start = *pos;          start = *pos;
         endtok = "\n@end macro\n";          endtok = "\n@end macro\n";
         endtoksz = strlen(endtok);          endtoksz = strlen(endtok);
         blk = memmem(&buf[start], sz, endtok, endtoksz);          blk = memmem(&buf[start], sz - start, endtok, endtoksz);
         if (NULL == blk)          if (NULL == blk)
                 texierr(p, "unterminated macro body");                  texierr(p, "unterminated macro body");
         while (&buf[*pos] != blk)          while (&buf[*pos] != blk)
Line 559  static void
Line 566  static void
 doignblock(struct texi *p, enum texicmd cmd,  doignblock(struct texi *p, enum texicmd cmd,
         const char *buf, size_t sz, size_t *pos)          const char *buf, size_t sz, size_t *pos)
 {  {
         char             end[32];          char             end[32], start[32];
         const char      *term;          const char      *endt, *startt;
         size_t           endsz, endpos;          size_t           esz, ssz, newpos, stack;
   
         /*          /*
          * We want to completely ignore everything in these blocks, so           * FIXME: this is cheating.
          * simply jump to the @end block.           * These tokens are supposed to begin on a newline.
            * However, if we do that, then we would need to check within
            * the loop for trailer (or leading, as the case may be)
            * newline, and that's just a bit too complicated right now.
            * This is becasue
            *      @ifset BAR
            *      @ifset FOO
            *      @end ifset
            *      @end ifset
            * won't work right now: we'd read after the first "@end ifset"
            * to the next line, then look for the next line after that.
          */           */
         endsz = snprintf(end, sizeof(end),          ssz = snprintf(start, sizeof(start),
                 "\n@end %s\n", texitoks[cmd].tok);                  "@%s", texitoks[cmd].tok);
         assert(endsz < sizeof(end));          assert(ssz < sizeof(start));
           esz = snprintf(end, sizeof(end),
                   "@end %s\n", texitoks[cmd].tok);
           assert(esz < sizeof(end));
           stack = 1;
   
         /*          /*
          * Look up where our end token occurs.           * Here we look for the end token "end" somewhere in the file in
          * Set our end position based on the relative offset of that           * front of us.
          * from our current position, or the EOF if we don't have a           * It's not that easy, of course: if we have a nested block,
          * proper ending point.           * then there'll be an "end" token of the same kind between us.
            * Thus, we keep track of scopes for matching "end" blocks.
          */           */
         term = memmem(&buf[*pos], sz, end, endsz);          while (stack > 0 && *pos < sz) {
         endpos = NULL == term ? sz :                  if (stack > 10)
                 *pos + (size_t)(term - &buf[*pos]);                          abort();
         assert(endpos <= sz);                  endt = memmem(&buf[*pos], sz - *pos, end, esz);
         while (*pos < endpos)                  startt = memmem(&buf[*pos], sz - *pos, start, ssz);
                 advance(p, buf, pos);                  if (NULL == endt) {
                           texiwarn(p, "unterminated \"%s\" "
                                   "block", texitoks[cmd].tok);
                           *pos = sz;
                           break;
                   }
   
         /* Only do this if we're not already at the end. */                  newpos = *pos;
         if (endpos < sz)                  if (NULL == startt || startt > endt) {
                 advanceto(p, buf, pos, endpos + endsz);                          newpos += esz + (size_t)(endt - &buf[*pos]);
                           stack--;
                   } else {
                           newpos += ssz + (size_t)(startt - &buf[*pos]);
                           stack++;
                   }
   
                   assert(newpos <= sz);
                   while (*pos < newpos)
                           advance(p, buf, pos);
           }
 }  }
   
 static void  static void
Line 698  doverbatim(struct texi *p, enum texicmd cmd, 
Line 735  doverbatim(struct texi *p, enum texicmd cmd, 
         const char      *end, *term;          const char      *end, *term;
         size_t           endsz, endpos;          size_t           endsz, endpos;
   
         advanceeoln(p, buf, sz, pos, 1);          /* We read from the @verbatim\n newline inclusive! */
   
         /* We end at exactly this token. */  
         end = "\n@end verbatim\n";          end = "\n@end verbatim\n";
         endsz = strlen(end);          endsz = strlen(end);
           advanceeoln(p, buf, sz, pos, 0);
           if (*pos == sz) {
                   texiwarn(p, "unexpected end of file");
                   return;
           }
   
         /*          term = memmem(&buf[*pos], sz - *pos, end, endsz);
          * Look up where our end token occurs.          if (NULL == term) {
          * Set our end position based on the relative offset of that                  texiwarn(p, "unterminated verbatim block");
          * from our current position.                  endpos = sz;
          */          } else
         term = memmem(&buf[*pos], sz, end, endsz);                  endpos = *pos + (size_t)(term - &buf[*pos]);
         endpos = NULL == term ? sz :  
                 *pos + (size_t)(term - &buf[*pos]);  
   
         teximacro(p, "Bd -literal -offset indent");  
         assert(endpos <= sz);          assert(endpos <= sz);
           assert('\n' == buf[*pos]);
           advance(p, buf, pos);
           teximacro(p, "Bd -literal -offset indent");
         while (*pos < endpos) {          while (*pos < endpos) {
                 texiputchar(p, buf[*pos]);                  texiputchar(p, buf[*pos]);
                 advance(p, buf, pos);                  advance(p, buf, pos);
         }          }
         teximacro(p, "Ed");          teximacro(p, "Ed");
         advanceto(p, buf, pos, endpos + endsz);          if (*pos < sz)
                   advanceto(p, buf, pos, endpos + endsz);
 }  }
   
 static void  static void
Line 1401  dolink(struct texi *p, enum texicmd cmd, 
Line 1442  dolink(struct texi *p, enum texicmd cmd, 
                 break;                  break;
         case (TEXICMD_UREF):          case (TEXICMD_UREF):
         case (TEXICMD_URL):          case (TEXICMD_URL):
           case (TEXICMD_INDICATEURL):
                 teximacroopen(p, "Lk");                  teximacroopen(p, "Lk");
                 break;                  break;
         case (TEXICMD_XREF):          case (TEXICMD_XREF):
Line 1738  dotable(struct texi *p, enum texicmd cmd, 
Line 1780  dotable(struct texi *p, enum texicmd cmd, 
         parseto(p, buf, sz, pos, texitoks[cmd].tok);          parseto(p, buf, sz, pos, texitoks[cmd].tok);
         teximacro(p, "El");          teximacro(p, "El");
         p->list = sv;          p->list = sv;
   }
   
   static void
   doend(struct texi *p, enum texicmd cmd,
           const char *buf, size_t sz, size_t *pos)
   {
           size_t   start;
   
           while (*pos < sz && isws(buf[*pos]))
                   advance(p, buf, pos);
           start = *pos;
           while (*pos < sz && '\n' != buf[*pos])
                   advance(p, buf, pos);
   
           texiwarn(p, "unexpected \"end\": %.*s", (int)(*pos - start), &buf[start]);
           advanceeoln(p, buf, sz, pos, 1);
 }  }
   
 static void  static void

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

CVSweb