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

Diff for /mandoc/manpath.c between version 1.18 and 1.22

version 1.18, 2014/11/18 19:41:47 version 1.22, 2015/03/26 22:42:32
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$    */
 /*  /*
  * Copyright (c) 2011, 2014 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2011, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
  * copyright notice and this permission notice appear in all copies.   * copyright notice and this permission notice appear in all copies.
  *   *
  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF   * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR   * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN   * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
Line 20 
Line 20 
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/stat.h>  #include <sys/stat.h>
   
 #include <assert.h>  
 #include <ctype.h>  #include <ctype.h>
 #include <limits.h>  #include <limits.h>
 #include <stdio.h>  #include <stdio.h>
Line 31 
Line 30 
 #include "manpath.h"  #include "manpath.h"
   
 #define MAN_CONF_FILE   "/etc/man.conf"  #define MAN_CONF_FILE   "/etc/man.conf"
 #define MAN_CONF_KEY    "_whatdb"  
   
 static  void     manpath_add(struct manpaths *, const char *, int);  static  void     manpath_add(struct manpaths *, const char *, int);
 static  void     manpath_parseline(struct manpaths *, char *, int);  static  void     manpath_parseline(struct manpaths *, char *, int);
Line 80  manpath_parse(struct manpaths *dirs, const char *file,
Line 78  manpath_parse(struct manpaths *dirs, const char *file,
         if ( ! ferror(stream) && feof(stream) &&          if ( ! ferror(stream) && feof(stream) &&
                         bsz && '\n' == buf[bsz - 1]) {                          bsz && '\n' == buf[bsz - 1]) {
                 buf[bsz - 1] = '\0';                  buf[bsz - 1] = '\0';
                 manpath_parseline(dirs, buf);                  manpath_parseline(dirs, buf, 1);
         }          }
   
         free(buf);          free(buf);
         pclose(stream);          pclose(stream);
 #else  #else
           char             manpath_default[] = MANPATH_DEFAULT;
         char            *insert;          char            *insert;
   
         /* Always prepend -m. */          /* Always prepend -m. */
Line 105  manpath_parse(struct manpaths *dirs, const char *file,
Line 104  manpath_parse(struct manpaths *dirs, const char *file,
         /* No MANPATH; use man.conf(5) only. */          /* No MANPATH; use man.conf(5) only. */
         if (NULL == defp || '\0' == defp[0]) {          if (NULL == defp || '\0' == defp[0]) {
                 manpath_manconf(dirs, file);                  manpath_manconf(dirs, file);
                   if (dirs->sz == 0)
                           manpath_parseline(dirs, manpath_default, 0);
                 return;                  return;
         }          }
   
Line 204  manpath_free(struct manpaths *p)
Line 205  manpath_free(struct manpaths *p)
 void  void
 manpath_manconf(struct manpaths *dirs, const char *file)  manpath_manconf(struct manpaths *dirs, const char *file)
 {  {
           const char *const toks[] = { "manpath", "_whatdb" };
   
         FILE            *stream;          FILE            *stream;
         char            *p, *q;          char            *cp, *ep;
         size_t           len, keysz;          size_t           len, tok;
   
         keysz = strlen(MAN_CONF_KEY);          if ((stream = fopen(file, "r")) == NULL)
         assert(keysz > 0);  
   
         if (NULL == (stream = fopen(file, "r")))  
                 return;                  return;
   
         while (NULL != (p = fgetln(stream, &len))) {          while ((cp = fgetln(stream, &len)) != NULL) {
                 if (0 == len || '\n' != p[--len])                  ep = cp + len;
                   if (ep[-1] != '\n')
                         break;                          break;
                 p[len] = '\0';                  *--ep = '\0';
                 while (isspace((unsigned char)*p))                  while (isspace((unsigned char)*cp))
                         p++;                          cp++;
                 if (strncmp(MAN_CONF_KEY, p, keysz))                  if (*cp == '#')
                         continue;                          continue;
                 p += keysz;  
                 while (isspace((unsigned char)*p))                  for (tok = 0; tok < sizeof(toks)/sizeof(toks[0]); tok++) {
                         p++;                          len = strlen(toks[tok]);
                 if ('\0' == *p)                          if (cp + len < ep &&
                         continue;                              isspace((unsigned char)cp[len]) &&
                 if (NULL == (q = strrchr(p, '/')))                              !strncmp(cp, toks[tok], len)) {
                         continue;                                  cp += len;
                 *q = '\0';                                  while (isspace((unsigned char)*cp))
                 manpath_add(dirs, p, 0);                                          cp++;
                                   break;
                           }
                   }
   
                   switch (tok) {
                   case 1:  /* _whatdb */
                           while (ep > cp && ep[-1] != '/')
                                   ep--;
                           if (ep == cp)
                                   continue;
                           *ep = '\0';
                           /* FALLTHROUGH */
                   case 0:  /* manpath */
                           manpath_add(dirs, cp, 0);
                           break;
                   default:
                           break;
                   }
         }          }
   
         fclose(stream);          fclose(stream);

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

CVSweb