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

Diff for /texi2mdoc/main.c between version 1.17 and 1.18

version 1.17, 2015/02/19 10:29:17 version 1.18, 2015/02/19 15:34:20
Line 56  enum texicmd {
Line 56  enum texicmd {
         TEXICMD_CITE,          TEXICMD_CITE,
         TEXICMD_CODE,          TEXICMD_CODE,
         TEXICMD_COLON,          TEXICMD_COLON,
           TEXICMD_COLUMNFRACTIONS,
         TEXICMD_COMMAND,          TEXICMD_COMMAND,
         TEXICMD_COMMENT,          TEXICMD_COMMENT,
         TEXICMD_COMMENT_LONG,          TEXICMD_COMMENT_LONG,
Line 102  enum texicmd {
Line 103  enum texicmd {
         TEXICMD_GROUP,          TEXICMD_GROUP,
         TEXICMD_HEADING,          TEXICMD_HEADING,
         TEXICMD_HEADINGS,          TEXICMD_HEADINGS,
           TEXICMD_HEADITEM,
         TEXICMD_HYPHEN,          TEXICMD_HYPHEN,
         TEXICMD_I,          TEXICMD_I,
         TEXICMD_IFCLEAR,          TEXICMD_IFCLEAR,
Line 125  enum texicmd {
Line 127  enum texicmd {
         TEXICMD_INSERTCOPYING,          TEXICMD_INSERTCOPYING,
         TEXICMD_ITEM,          TEXICMD_ITEM,
         TEXICMD_ITEMIZE,          TEXICMD_ITEMIZE,
           TEXICMD_KEY,
         TEXICMD_KBD,          TEXICMD_KBD,
         TEXICMD_LATEX,          TEXICMD_LATEX,
         TEXICMD_MATH,          TEXICMD_MATH,
         TEXICMD_MENU,          TEXICMD_MENU,
           TEXICMD_MULTITABLE,
         TEXICMD_NEED,          TEXICMD_NEED,
         TEXICMD_NEWLINE,          TEXICMD_NEWLINE,
         TEXICMD_NODE,          TEXICMD_NODE,
Line 165  enum texicmd {
Line 169  enum texicmd {
         TEXICMD_SUBTITLE,          TEXICMD_SUBTITLE,
         TEXICMD_T,          TEXICMD_T,
         TEXICMD_TAB,          TEXICMD_TAB,
           TEXICMD_TABSYM,
         TEXICMD_TABLE,          TEXICMD_TABLE,
         TEXICMD_TEX,          TEXICMD_TEX,
         TEXICMD_TEXSYM,          TEXICMD_TEXSYM,
Line 180  enum texicmd {
Line 185  enum texicmd {
         TEXICMD_URL,          TEXICMD_URL,
         TEXICMD_VAR,          TEXICMD_VAR,
         TEXICMD_VERBATIMINCLUDE,          TEXICMD_VERBATIMINCLUDE,
           TEXICMD_VINDEX,
         TEXICMD_VSKIP,          TEXICMD_VSKIP,
         TEXICMD_W,          TEXICMD_W,
         TEXICMD_XREF,          TEXICMD_XREF,
Line 219  enum texilist {
Line 225  enum texilist {
         TEXILIST_NONE = 0,          TEXILIST_NONE = 0,
         TEXILIST_ITEM,          TEXILIST_ITEM,
         TEXILIST_NOITEM,          TEXILIST_NOITEM,
           TEXILIST_TABLE
 };  };
   
 /*  /*
Line 270  static void doitem(struct texi *, enum texicmd, const 
Line 277  static void doitem(struct texi *, enum texicmd, const 
 static  void doitemize(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void doitemize(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void dolink(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void dolink(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void domath(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void domath(struct texi *, enum texicmd, const char *, size_t, size_t *);
   static  void domultitable(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void doquotation(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void doquotation(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void dotable(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void dotable(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void dotop(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void dotop(struct texi *, enum texicmd, const char *, size_t, size_t *);
Line 277  static void dosection(struct texi *, enum texicmd, con
Line 285  static void dosection(struct texi *, enum texicmd, con
 static  void dosp(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void dosp(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void dosubsection(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void dosubsection(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void dosymbol(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void dosymbol(struct texi *, enum texicmd, const char *, size_t, size_t *);
   static  void dotab(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void dotitle(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void dotitle(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void doverbinclude(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void doverbinclude(struct texi *, enum texicmd, const char *, size_t, size_t *);
   
Line 301  static const struct texitok texitoks[TEXICMD__MAX] = {
Line 310  static const struct texitok texitoks[TEXICMD__MAX] = {
         { dofont, "code", 4 }, /* TEXICMD_CODE */          { dofont, "code", 4 }, /* TEXICMD_CODE */
         { dofont, "cite", 4 }, /* TEXICMD_CITE */          { dofont, "cite", 4 }, /* TEXICMD_CITE */
         { dosymbol, ":", 1 }, /* TEXICMD_COLON */          { dosymbol, ":", 1 }, /* TEXICMD_COLON */
           { NULL, "columnfractions", 15 }, /* TEXICMD_COLUMNFRACTIONS */
         { doinline, "command", 7 }, /* TEXICMD_COMMAND */          { doinline, "command", 7 }, /* TEXICMD_COMMAND */
         { doignline, "c", 1 }, /* TEXICMD_COMMENT */          { doignline, "c", 1 }, /* TEXICMD_COMMENT */
         { doignline, "comment", 7 }, /* TEXICMD_COMMENT_LONG */          { doignline, "comment", 7 }, /* TEXICMD_COMMENT_LONG */
Line 347  static const struct texitok texitoks[TEXICMD__MAX] = {
Line 357  static const struct texitok texitoks[TEXICMD__MAX] = {
         { doblock, "group", 5 }, /* TEXICMD_GROUP */          { doblock, "group", 5 }, /* TEXICMD_GROUP */
         { dosection, "heading", 7 }, /* TEXICMD_HEADING */          { dosection, "heading", 7 }, /* TEXICMD_HEADING */
         { doignline, "headings", 8 }, /* TEXICMD_HEADINGS */          { doignline, "headings", 8 }, /* TEXICMD_HEADINGS */
           { doitem, "headitem", 8 }, /* TEXICMD_HEADITEM */
         { dosymbol, "-", 1 }, /* TEXICMD_HYPHEN */          { dosymbol, "-", 1 }, /* TEXICMD_HYPHEN */
         { dofont, "i", 1 }, /* TEXICMD_I */          { dofont, "i", 1 }, /* TEXICMD_I */
         { doignblock, "ifclear", 7 }, /* TEXICMD_IFCLEAR */          { doignblock, "ifclear", 7 }, /* TEXICMD_IFCLEAR */
Line 370  static const struct texitok texitoks[TEXICMD__MAX] = {
Line 381  static const struct texitok texitoks[TEXICMD__MAX] = {
         { 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 */
           { dobracket, "key", 3 }, /* TEXICMD_KEY */
         { dofont, "kbd", 3 }, /* TEXICMD_KBD */          { dofont, "kbd", 3 }, /* TEXICMD_KBD */
         { dosymbol, "LaTeX", 5 }, /* TEXICMD_LATEX */          { dosymbol, "LaTeX", 5 }, /* TEXICMD_LATEX */
         { domath, "math", 4 }, /* TEXICMD_MATH */          { domath, "math", 4 }, /* TEXICMD_MATH */
         { doignblock, "menu", 4 }, /* TEXICMD_MENU */          { doignblock, "menu", 4 }, /* TEXICMD_MENU */
           { 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 */
         { doignline, "node", 4 }, /* TEXICMD_NODE */          { doignline, "node", 4 }, /* TEXICMD_NODE */
Line 409  static const struct texitok texitoks[TEXICMD__MAX] = {
Line 422  static const struct texitok texitoks[TEXICMD__MAX] = {
         { dosubsection, "subsection", 10 }, /* TEXICMD_SUBSECTION */          { dosubsection, "subsection", 10 }, /* TEXICMD_SUBSECTION */
         { doignline, "subtitle", 8 }, /* TEXICMD_SUBTITLE */          { doignline, "subtitle", 8 }, /* TEXICMD_SUBTITLE */
         { dofont, "t", 1 }, /* TEXICMD_T */          { dofont, "t", 1 }, /* TEXICMD_T */
         { dosymbol, "\t", 1 }, /* TEXICMD_TAB */          { dotab, "tab", 3 }, /* TEXICMD_TAB */
           { dosymbol, "\t", 1 }, /* TEXICMD_TABSYM */
         { dotable, "table", 5 }, /* TEXICMD_TABLE */          { dotable, "table", 5 }, /* TEXICMD_TABLE */
         { doignblock, "tex", 3 }, /* TEXICMD_TEX */          { doignblock, "tex", 3 }, /* TEXICMD_TEX */
         { dosymbol, "TeX", 3 }, /* TEXICMD_TEXSYM */          { dosymbol, "TeX", 3 }, /* TEXICMD_TEXSYM */
Line 425  static const struct texitok texitoks[TEXICMD__MAX] = {
Line 439  static const struct texitok texitoks[TEXICMD__MAX] = {
         { dolink, "url", 3 }, /* TEXICMD_URL */          { dolink, "url", 3 }, /* TEXICMD_URL */
         { doinline, "var", 3 }, /* TEXICMD_VAR */          { doinline, "var", 3 }, /* TEXICMD_VAR */
         { doverbinclude, "verbatiminclude", 15 }, /* TEXICMD_VERBATIMINCLUDE */          { doverbinclude, "verbatiminclude", 15 }, /* TEXICMD_VERBATIMINCLUDE */
           { doignline, "vindex", 6 }, /* TEXICMD_VINDEX */
         { dosp, "vskip", 5 }, /* TEXICMD_VSKIP */          { dosp, "vskip", 5 }, /* TEXICMD_VSKIP */
         { dobracket, "w", 1 }, /* TEXICMD_W */          { dobracket, "w", 1 }, /* TEXICMD_W */
         { dolink, "xref", 4 }, /* TEXICMD_XREF */          { dolink, "xref", 4 }, /* TEXICMD_XREF */
Line 523  texierr(struct texi *p, const char *fmt, ...)
Line 538  texierr(struct texi *p, const char *fmt, ...)
 /*  /*
  * Put a single data character to the output if we're not ignoring.   * Put a single data character to the output if we're not ignoring.
  * Adjusts our output status.   * Adjusts our output status.
    * This shouldn't be called for macros: just for ordinary text.
  */   */
 static void  static void
 texiputchar(struct texi *p, char c)  texiputchar(struct texi *p, char c)
Line 530  texiputchar(struct texi *p, char c)
Line 546  texiputchar(struct texi *p, char c)
   
         if (p->ign)          if (p->ign)
                 return;                  return;
   
           if ('.' == c && 0 == p->outcol)
                   fputs("\\&", stdout);
   
         putchar(c);          putchar(c);
         p->seenvs = 0;          p->seenvs = 0;
         if ('\n' == c) {          if ('\n' == c) {
Line 541  texiputchar(struct texi *p, char c)
Line 561  texiputchar(struct texi *p, char c)
   
 /*  /*
  * Put multiple characters (see texiputchar()).   * Put multiple characters (see texiputchar()).
    * This shouldn't be called for macros: just for ordinary text.
  */   */
 static void  static void
 texiputchars(struct texi *p, const char *s)  texiputchars(struct texi *p, const char *s)
Line 558  static void
Line 579  static void
 teximacroclose(struct texi *p)  teximacroclose(struct texi *p)
 {  {
   
         /* FIXME: punctuation. */          if (p->ign)
         if (0 == --p->outmacro)                  return;
                 texiputchar(p, '\n');  
           if (0 == --p->outmacro) {
                   putchar('\n');
                   p->outcol = p->seenws = 0;
           }
 }  }
   
 /*  /*
Line 571  teximacroclose(struct texi *p)
Line 596  teximacroclose(struct texi *p)
 static void  static void
 teximacroopen(struct texi *p, const char *s)  teximacroopen(struct texi *p, const char *s)
 {  {
           int      rc;
   
         if (p->outcol && 0 == p->outmacro)          if (p->ign)
                 texiputchar(p, '\n');                  return;
   
           if (p->outcol && 0 == p->outmacro) {
                   putchar('\n');
                   p->outcol = 0;
           }
   
         if (0 == p->outmacro)          if (0 == p->outmacro)
                 texiputchar(p, '.');                  putchar('.');
         else          else
                 texiputchar(p, ' ');                  putchar(' ');
         texiputchars(p, s);  
         texiputchar(p, ' ');          if (EOF != (rc = fputs(s, stdout)))
                   p->outcol += rc;
   
           putchar(' ');
           p->outcol++;
         p->outmacro++;          p->outmacro++;
         p->seenws = 0;          p->seenws = 0;
 }  }
Line 591  static void
Line 627  static void
 teximacro(struct texi *p, const char *s)  teximacro(struct texi *p, const char *s)
 {  {
   
           if (p->ign)
                   return;
   
         if (p->outmacro)          if (p->outmacro)
                 texierr(p, "\"%s\" in open line scope!?", s);                  texierr(p, "\"%s\" in open line scope!?", s);
         else if (p->literal)          if (p->literal)
                 texierr(p, "\"%s\" in a literal scope!?", s);                  texierr(p, "\"%s\" in a literal scope!?", s);
   
         if (p->outcol)          if (p->outcol)
                 texiputchar(p, '\n');                  putchar('\n');
   
         texiputchar(p, '.');          putchar('.');
         texiputchars(p, s);          puts(s);
         texiputchar(p, '\n');          p->outcol = p->seenws = 0;
 }  }
   
 static void  static void
Line 737  texiword(struct texi *p, const char *buf, 
Line 776  texiword(struct texi *p, const char *buf, 
         size_t sz, size_t *pos, char extra)          size_t sz, size_t *pos, char extra)
 {  {
   
         if (0 == p->outmacro && p->outcol > 72 && 0 == p->literal)          if (p->seenws && 0 == p->outmacro && p->outcol > 72 && 0 == p->literal)
                 texiputchar(p, '\n');                  texiputchar(p, '\n');
         /* FIXME: abstract this: we use it elsewhere. */          /* FIXME: abstract this: we use it elsewhere. */
         if (p->seenws && p->outcol && 0 == p->literal)          if (p->seenws && p->outcol && 0 == p->literal)
Line 1437  dofont(struct texi *p, enum texicmd cmd, 
Line 1476  dofont(struct texi *p, enum texicmd cmd, 
                 abort();                  abort();
         }          }
   
           if (p->seenws) {
                   texiputchar(p, ' ');
                   p->seenws = 0;
           }
         texiputchars(p, font);          texiputchars(p, font);
         parsebracket(p, buf, sz, pos);          parsebracket(p, buf, sz, pos);
         texiputchars(p, "\\fP");          texiputchars(p, "\\fP");
Line 1600  dosymbol(struct texi *p, enum texicmd cmd, 
Line 1643  dosymbol(struct texi *p, enum texicmd cmd, 
         case (TEXICMD_ASTERISK):          case (TEXICMD_ASTERISK):
         case (TEXICMD_NEWLINE):          case (TEXICMD_NEWLINE):
         case (TEXICMD_SPACE):          case (TEXICMD_SPACE):
         case (TEXICMD_TAB):          case (TEXICMD_TABSYM):
                 texiputchar(p, ' ');                  texiputchar(p, ' ');
                 break;                  break;
         case (TEXICMD_AT):          case (TEXICMD_AT):
Line 1817  dotop(struct texi *p, enum texicmd cmd, 
Line 1860  dotop(struct texi *p, enum texicmd cmd, 
         time_t           t;          time_t           t;
         char             date[32];          char             date[32];
   
           /*
            * Here we print our standard mdoc(7) prologue.
            * We use the title set with @settitle for the `Nd' description
            * and the source document filename (the first one as invoked on
            * the command line) for the title.
            * The date is set to the current date.
            */
         t = time(NULL);          t = time(NULL);
         strftime(date, sizeof(date), "%F", localtime(&t));          strftime(date, sizeof(date), "%F", localtime(&t));
   
Line 1847  doitem(struct texi *p, enum texicmd cmd, 
Line 1897  doitem(struct texi *p, enum texicmd cmd, 
         const char *buf, size_t sz, size_t *pos)          const char *buf, size_t sz, size_t *pos)
 {  {
   
           /* Multitable is using raw tbl(7). */
           if (TEXILIST_TABLE == p->list) {
                   texiputchar(p, '\n');
                   return;
           }
   
         if (p->outmacro)          if (p->outmacro)
                 texierr(p, "item in open line scope!?");                  texierr(p, "item in open line scope!?");
         else if (p->literal)          else if (p->literal)
Line 1863  doitem(struct texi *p, enum texicmd cmd, 
Line 1919  doitem(struct texi *p, enum texicmd cmd, 
                 texivspace(p);                  texivspace(p);
                 break;                  break;
         }          }
         p->seenvs = 1;  
   
           /* Trick so we don't start with Pp. */
           p->seenvs = 1;
         parseeoln(p, buf, sz, pos);          parseeoln(p, buf, sz, pos);
   
         if (TEXILIST_ITEM == p->list)          if (TEXILIST_ITEM == p->list)
                 teximacroclose(p);                  teximacroclose(p);
         else if (p->outcol > 0)          else if (p->outcol > 0)
                 texiputchar(p, '\n');                  texiputchar(p, '\n');
   }
   
   static void
   dotab(struct texi *p, enum texicmd cmd,
           const char *buf, size_t sz, size_t *pos)
   {
   
           /* This command is only useful in @multitable. */
           if (TEXILIST_TABLE == p->list)
                   texiputchar(p, '\t');
   }
   
   static void
   domultitable(struct texi *p, enum texicmd cmd,
           const char *buf, size_t sz, size_t *pos)
   {
           enum texilist   sv = p->list;
           enum texicmd    type;
           size_t          i, end, columns;
   
           p->list = TEXILIST_TABLE;
           teximacro(p, "TS");
           columns = 0;
   
           /* Advance to the first argument... */
           while (*pos < sz && isws(buf[*pos]))
                   advance(p, buf, pos);
   
           /* Make sure we don't print anything when scanning. */
           p->ign++;
           if ('@' == buf[*pos]) {
                   /*
                    * Look for @columnfractions.
                    * We ignore these, but we do use the number of
                    * arguments to set the number of columns that we'll
                    * have.
                    */
                   type = texicmd(p, buf, *pos, sz, &end);
                   advanceto(p, buf, pos, end);
                   if (TEXICMD_COLUMNFRACTIONS != type)
                           texierr(p, "unknown multitable type");
                   while (*pos < sz && '\n' != buf[*pos]) {
                           while (*pos < sz && isws(buf[*pos]))
                                   advance(p, buf, pos);
                           while (*pos < sz && ! isws(buf[*pos])) {
                                   if ('\n' == buf[*pos])
                                           break;
                                   advance(p, buf, pos);
                           }
                           columns++;
                   }
           } else
                   /*
                    * We have arguments.
                    * We could parse these, but it's easier to just let
                    * tbl(7) figure it out.
                    * So use this only to count arguments.
                    */
                   while (parselinearg(p, buf, sz, pos) > 0)
                           columns++;
           p->ign--;
   
           /* Left-justify each table entry. */
           for (i = 0; i < columns; i++) {
                   if (i > 0)
                           texiputchar(p, ' ');
                   texiputchar(p, 'l');
           }
           texiputchars(p, ".\n");
           p->outmacro++;
           parseto(p, buf, sz, pos, texitoks[cmd].tok);
           p->outmacro--;
           teximacro(p, "TE");
           p->list = sv;
 }  }
   
 static void  static void

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

CVSweb