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

Diff for /texi2mdoc/main.c between version 1.9 and 1.10

version 1.9, 2015/02/18 14:52:45 version 1.10, 2015/02/18 15:30:31
Line 27 
Line 27 
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   #include <time.h>
 #include <unistd.h>  #include <unistd.h>
   
 /*  /*
Line 191  struct texi {
Line 192  struct texi {
         int               seenws; /* ws has been seen (and ignored) */          int               seenws; /* ws has been seen (and ignored) */
         int               ign; /* if >0, don't print anything */          int               ign; /* if >0, don't print anything */
         int               literal; /* if >0, literal context */          int               literal; /* if >0, literal context */
           char             *title; /* title of document */
           char             *subtitle; /* subtitle of document */
 };  };
   
 /* FIXME: FIND A BETTER WAY. */  /* FIXME: FIND A BETTER WAY. */
Line 202  struct texi {
Line 205  struct texi {
 #define isws(_x) \  #define isws(_x) \
         (' ' == (_x) || '\t' == (_x))          (' ' == (_x) || '\t' == (_x))
 #define ismspace(_x) \  #define ismspace(_x) \
         (isws((_x) || '\n' == (_x)))          (isws((_x)) || '\n' == (_x))
   
 static  void doblock(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void doblock(struct texi *, enum texicmd, const char *, size_t, size_t *);
 static  void dobracket(struct texi *, enum texicmd, const char *, size_t, size_t *);  static  void dobracket(struct texi *, enum texicmd, const char *, size_t, size_t *);
Line 235  static void dosection(struct texi *, enum texicmd, con
Line 238  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 dotitle(struct texi *, enum texicmd, const char *, size_t, size_t *);
   
 static  const struct texitok texitoks[TEXICMD__MAX] = {  static  const struct texitok texitoks[TEXICMD__MAX] = {
         { doignargn, "acronym", 7 }, /* TEXICMD_ACRONYM */          { doignargn, "acronym", 7 }, /* TEXICMD_ACRONYM */
Line 315  static const struct texitok texitoks[TEXICMD__MAX] = {
Line 319  static const struct texitok texitoks[TEXICMD__MAX] = {
         { doignline, "set", 3 }, /* TEXICMD_SET */          { doignline, "set", 3 }, /* TEXICMD_SET */
         { doignline, "setchapternewpage", 17 }, /* TEXICMD_SETCHAPNEWPAGE */          { doignline, "setchapternewpage", 17 }, /* TEXICMD_SETCHAPNEWPAGE */
         { doignline, "setfilename", 11 }, /* TEXICMD_SETFILENAME */          { doignline, "setfilename", 11 }, /* TEXICMD_SETFILENAME */
         { doignline, "settitle", 8 }, /* TEXICMD_SETTITLE */          { dotitle, "settitle", 8 }, /* TEXICMD_SETTITLE */
         { dosp, "sp", 2 }, /* TEXICMD_SP */          { dosp, "sp", 2 }, /* TEXICMD_SP */
         { dosymbol, " ", 1 }, /* TEXICMD_SPACE */          { dosymbol, " ", 1 }, /* TEXICMD_SPACE */
         { doexample, "smallexample", 12 }, /* TEXICMD_SMALLEXAMPLE */          { doexample, "smallexample", 12 }, /* TEXICMD_SMALLEXAMPLE */
Line 373  texiexit(struct texi *p)
Line 377  texiexit(struct texi *p)
   
         for (i = 0; i < p->dirsz; i++)          for (i = 0; i < p->dirsz; i++)
                 free(p->dirs[i]);                  free(p->dirs[i]);
   
         free(p->dirs);          free(p->dirs);
           free(p->subtitle);
           free(p->title);
 }  }
   
 /*  /*
Line 1235  dobye(struct texi *p, enum texicmd cmd, 
Line 1242  dobye(struct texi *p, enum texicmd cmd, 
 }  }
   
 static void  static void
   dotitle(struct texi *p, enum texicmd cmd,
           const char *buf, size_t sz, size_t *pos)
   {
           size_t   start, end;
   
           while (*pos < sz && isws(buf[*pos]))
                   advance(p, buf, pos);
           start = end = *pos;
           while (end < sz && '\n' != buf[end])
                   end++;
           free(p->subtitle);
           p->subtitle = malloc(end - start + 1);
           memcpy(p->subtitle, &buf[start], end - start);
           p->subtitle[end - start] = '\0';
   }
   
   static void
 dosymbol(struct texi *p, enum texicmd cmd,  dosymbol(struct texi *p, enum texicmd cmd,
         const char *buf, size_t sz, size_t *pos)          const char *buf, size_t sz, size_t *pos)
 {  {
Line 1449  static void
Line 1473  static void
 dotop(struct texi *p, enum texicmd cmd,  dotop(struct texi *p, enum texicmd cmd,
         const char *buf, size_t sz, size_t *pos)          const char *buf, size_t sz, size_t *pos)
 {  {
           const char      *cp;
           time_t           t;
           char             date[32];
   
           t = time(NULL);
           strftime(date, sizeof(date), "%F", localtime(&t));
   
         p->ign--;          p->ign--;
         advanceeoln(p, buf, sz, pos, 1);          advanceeoln(p, buf, sz, pos, 1);
         teximacro(p, "Dd $Mdocdate$");          teximacroopen(p, "Dd");
         teximacro(p, "Dt SOMETHING 7");          texiputchars(p, date);
           teximacroclose(p);
           teximacroopen(p, "Dt");
           for (cp = p->title; '\0' != *cp; cp++)
                   texiputchar(p, toupper(*cp));
           teximacroclose(p);
         teximacro(p, "Os");          teximacro(p, "Os");
         teximacro(p, "Sh NAME");          teximacro(p, "Sh NAME");
         teximacro(p, "Nm Something");          teximacroopen(p, "Nm");
         teximacro(p, "Nd Something");          texiputchars(p, p->title);
           teximacroclose(p);
           teximacroopen(p, "Nd");
           texiputchars(p, NULL != p->subtitle ?
                   p->subtitle : "Unknown description");
           teximacroclose(p);
 }  }
   
 static void  static void
Line 1599  main(int argc, char *argv[])
Line 1639  main(int argc, char *argv[])
         struct texi      texi;          struct texi      texi;
         int              c;          int              c;
         char            *path, *dir;          char            *path, *dir;
         const char      *progname, *Idir;          const char      *progname, *Idir, *cp;
   
         progname = strrchr(argv[0], '/');          progname = strrchr(argv[0], '/');
         if (progname == NULL)          if (progname == NULL)
Line 1607  main(int argc, char *argv[])
Line 1647  main(int argc, char *argv[])
         else          else
                 ++progname;                  ++progname;
   
           memset(&texi, 0, sizeof(struct texi));
         Idir = NULL;          Idir = NULL;
   
         while (-1 != (c = getopt(argc, argv, "I:")))          while (-1 != (c = getopt(argc, argv, "I:")))
                 switch (c) {                  switch (c) {
                 case ('I'):                  case ('I'):
Line 1631  main(int argc, char *argv[])
Line 1673  main(int argc, char *argv[])
         }          }
         free(path);          free(path);
   
         memset(&texi, 0, sizeof(struct texi));          if (NULL != (cp = strrchr(argv[0], '/')))
                   texi.title = strdup(cp + 1);
           else
                   texi.title = strdup(argv[0]);
   
           if (NULL == texi.title) {
                   perror(NULL);
                   exit(EXIT_FAILURE);
           } else if (NULL != (path = strchr(texi.title, '.')))
                   *path = '\0';
   
         texi.ign = 1;          texi.ign = 1;
         texi.dirs = parsedirs(dir, Idir, &texi.dirsz);          texi.dirs = parsedirs(dir, Idir, &texi.dirsz);
         parsefile(&texi, argv[0]);          parsefile(&texi, argv[0]);

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

CVSweb