/[man-db]/man-db/src/convert_name.c
ViewVC logotype

Diff of /man-db/src/convert_name.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by cjwatson, Thu May 1 18:14:11 2003 UTC revision 1.9 by cjwatson, Sun Nov 16 21:30:22 2003 UTC
# Line 57  static __inline__ void gripe_converting_ Line 57  static __inline__ void gripe_converting_
57          error (FATAL, 0, _("Can't convert %s to cat name"), name);          error (FATAL, 0, _("Can't convert %s to cat name"), name);
58  }  }
59    
60  /* derive the catpage path for manpage 'name'. If alternate is not NULL, use  /* Convert the trailing part of 'name' to be a cat page path by altering its
61     its value as the catpath dir. */   * extension appropriately. If fsstnd is set, also try converting the
62  char *convert_name (const char *name, const char *alternate)   * containing directory name from "man1" to "cat1" etc., returning NULL if
63     * that doesn't work.
64     *
65     * fsstnd should only be set if name is the original path of a man page
66     * found in a man hierarchy, not something like a symlink target or a file
67     * named with 'man -l'. Otherwise, a symlink to "/home/manuel/foo.1.gz"
68     * would be converted to "/home/catuel/foo.1.gz", which would be bad.
69     */
70    char *convert_name (const char *name, int fsstnd)
71  {  {
72          char *to_name, *t1 = NULL;          char *to_name, *t1 = NULL;
73          char *t2 = NULL;          char *t2 = NULL;
74  #ifdef COMP_SRC  #ifdef COMP_SRC
75          struct compression *comp;          struct compression *comp;
76  #endif /* COMP_SRC */  #endif /* COMP_SRC */
77            char *namestem;
         /* we already checked that there is an alternate catdir */  
         if (alternate)  
                 name = alternate;  
78    
79  #ifdef COMP_SRC  #ifdef COMP_SRC
80          comp = comp_info (name);          comp = comp_info (name);
81          if (comp)          if (comp)
82                  *comp->file = '\0';                  namestem = xstrndup (name, comp->file - name);
83            else
84  #endif /* COMP_SRC */  #endif /* COMP_SRC */
85                    namestem = xstrdup (name);
86    
87  #ifdef COMP_CAT  #ifdef COMP_CAT
88          /* TODO: BSD layout requires .0. */          /* TODO: BSD layout requires .0. */
89          to_name = strappend (NULL, name, "." COMPRESS_EXT, NULL);          to_name = strappend (NULL, namestem, "." COMPRESS_EXT, NULL);
90  #else /* !COMP_CAT */  #else /* !COMP_CAT */
91          to_name = xstrdup (name);          to_name = xstrdup (namestem);
92  #endif /* COMP_CAT */  #endif /* COMP_CAT */
93            free (namestem);
94    
95          t1 = strrchr (to_name, '/');          if (fsstnd) {
96          if (t1) {                  t1 = strrchr (to_name, '/');
97                    if (!t1)
98                            gripe_converting_name (name);
99                  *t1 = '\0';                  *t1 = '\0';
100    
101                  t2 = strrchr (to_name, '/');                  t2 = strrchr (to_name, '/');
102                  if (t2 == NULL)                  if (!t2)
103                          gripe_converting_name (name);                          gripe_converting_name (name);
104                    ++t2;
105                  *t1 = '/';                  *t1 = '/';
106                  /* TODO: This is broken beyond repair. Rewrite this whole  
107                   * function, after understanding what on earth it's trying                  if (STRNEQ (t2, "man", 3)) {
108                   * to achieve!                          /* If the second-last component starts with "man",
109                   */                           * replace "man" with "cat".
110                  *(t2 + 1) = 'c';                           */
111                  *(t2 + 3) = 't';                          *t2 = 'c';
112          } else                          *(t2 + 2) = 't';
113                  gripe_converting_name (name);                  } else {
114                            free (to_name);
115                            if (debug)
116                                    fprintf (stderr, "couldn't convert %s to "
117                                                     "FSSTND cat file\n", name);
118                            return NULL;
119                    }
120            }
121    
122          if (debug)          if (debug)
123                  fprintf (stderr, "to_name in convert_name () is %s\n", to_name);                  fprintf (stderr, "converted %s to %s\n", name, to_name);
124    
 #ifdef COMP_SRC  
         if (comp)  
                 *comp->file = '.';  
 #endif /* COMP_SRC */  
125          return to_name;          return to_name;
126  }  }
127    

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

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26