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

Diff for /texi2mdoc/util.c between version 1.10 and 1.12

version 1.10, 2015/02/23 15:09:09 version 1.12, 2015/02/23 22:50:11
Line 43  texifilepop(struct texi *p)
Line 43  texifilepop(struct texi *p)
   
         assert(p->filepos > 0);          assert(p->filepos > 0);
         f = &p->files[--p->filepos];          f = &p->files[--p->filepos];
         munmap(f->map, f->mapsz);          if (TEXISRC_FILE == f->type)
                   munmap(f->map, f->mapsz);
           else
                   free(f->map);
 }  }
   
 static void  static void
Line 421  static void
Line 424  static void
 texiexecmacro(struct texi *p, struct teximacro *m,  texiexecmacro(struct texi *p, struct teximacro *m,
         const char *buf, size_t sz, size_t *pos)          const char *buf, size_t sz, size_t *pos)
 {  {
         size_t    valsz, realsz, aasz, asz,          size_t            valsz, realsz, aasz, asz,
                   ssz, i, j, k, start, end;                             ssz, i, j, k, start, end;
         char     *val;          char             *val;
         char    **args;          char            **args;
           const char       *cp;
   
         args = argparse(p, buf, sz, pos, &asz, m->argsz);          args = argparse(p, buf, sz, pos, &asz, m->argsz);
         if (asz != m->argsz)          if (asz != m->argsz)
Line 494  texiexecmacro(struct texi *p, struct teximacro *m,
Line 498  texiexecmacro(struct texi *p, struct teximacro *m,
                                 texiabort(p, NULL);                                  texiabort(p, NULL);
                 }                  }
   
                 j = strlcat(val, args[k], valsz + 1);                  for (cp = args[k]; '\0' != *cp; cp++)
                           val[j++] = *cp;
   
                   val[j] = '\0';
                 i = end;                  i = end;
         }          }
   
Line 951  parseto(struct texi *p, const char *buf, 
Line 958  parseto(struct texi *p, const char *buf, 
 }  }
   
 /*  /*
    * Like parsefile() but used for reading from stdandard input.
    * This can only be called for the first file!
    */
   void
   parsestdin(struct texi *p)
   {
           struct texifile *f;
           size_t           off;
           ssize_t          ssz;
   
           assert(0 == p->filepos);
           f = &p->files[p->filepos];
           memset(f, 0, sizeof(struct texifile));
   
           f->type = TEXISRC_STDIN;
           f->name = "<stdin>";
   
           for (off = 0; ; off += (size_t)ssz) {
                   if (off == f->mapsz) {
                           if (f->mapsz == (1U << 31))
                                   texierr(p, "stdin buffer too long");
                           f->mapsz = f->mapsz > 65536 / 2 ?
                                   2 * f->mapsz : 65536;
                           f->map = realloc(f->map, f->mapsz);
                           if (NULL == f->map)
                                   texiabort(p, NULL);
                   }
                   ssz = read(STDIN_FILENO,
                           f->map + (int)off, f->mapsz - off);
                   if (0 == ssz)
                           break;
                   else if (-1 == ssz)
                           texiabort(p, NULL);
           }
   
           p->filepos++;
           parseeof(p, f->map, off);
           texifilepop(p);
   }
   
   /*
  * Memory-map the file "fname" and begin parsing it unless "parse" is   * Memory-map the file "fname" and begin parsing it unless "parse" is
  * zero, in which case we just dump the file to stdout (making sure it   * zero, in which case we just dump the file to stdout (making sure it
  * doesn't trip up mdoc(7) along the way).   * doesn't trip up mdoc(7) along the way).
Line 969  parsefile(struct texi *p, const char *fname, int parse
Line 1017  parsefile(struct texi *p, const char *fname, int parse
         f = &p->files[p->filepos];          f = &p->files[p->filepos];
         memset(f, 0, sizeof(struct texifile));          memset(f, 0, sizeof(struct texifile));
   
           f->type = TEXISRC_FILE;
         f->name = fname;          f->name = fname;
         if (-1 == (fd = open(fname, O_RDONLY, 0))) {          if (-1 == (fd = open(fname, O_RDONLY, 0))) {
                 texiabort(p, fname);                  texiabort(p, fname);
Line 1221  argparse(struct texi *p, const char *buf, 
Line 1270  argparse(struct texi *p, const char *buf, 
                 /* Test for zero-length '{  }'. */                  /* Test for zero-length '{  }'. */
                 if (start == end && '}' == buf[*pos] && 0 == *argsz)                  if (start == end && '}' == buf[*pos] && 0 == *argsz)
                         break;                          break;
                 if (start == end)  
                         texierr(p, "zero-length argument");  
                 /* FIXME: use reallocarray. */                  /* FIXME: use reallocarray. */
                 args = realloc                  args = realloc
                         (args, sizeof(char *) *                          (args, sizeof(char *) *

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

CVSweb