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

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

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

revision 1.107 by cjwatson, Sun Nov 16 18:46:47 2003 UTC revision 1.108 by cjwatson, Sun Nov 16 21:30:23 2003 UTC
# Line 2493  static int display (const char *dir, con Line 2493  static int display (const char *dir, con
2493                          checked_system (format_cmd);                          checked_system (format_cmd);
2494                  }                  }
2495          } else {          } else {
2496                  int format;                  int format = 1;
2497                  int status;                  int status;
                 char *catpath;  
2498    
2499                  /* cat_file is the alternate cat_file.. */                  /* The caller should already have checked for any
2500                  /* If !man_file, we have a straycat                   * FSSTND-style (same hierarchy) cat page that may be
2501                     If !cat_file, we can't produce a cat_file, but we                   * present, and we don't expect to have to update the cat
2502                     may still have one tucked away under /usr...                   * page in that case. If by some chance we do have to update
2503                     Check there first ala the FSSTND, and display if newer                   * it, then there's no harm trying; open_cat_stream() will
2504                     than man_file, if older, ignore it altogether */                   * refuse gracefully if the file isn't writeable.
2505                     */
2506    
2507                  if (different_encoding                  if (different_encoding
2508  #ifdef TROFF_IS_GROFF  #ifdef TROFF_IS_GROFF
2509                      || htmlout                      || htmlout
2510  #endif  #endif
2511                              ) {                      || local_man_file)
                         format = 1;  
2512                          save_cat = 0;                          save_cat = 0;
                 } else if (!local_man_file) {  
                         catpath = get_catpath  
                                 (dir, global_manpath ? SYSTEM_CAT : USER_CAT);  
   
                         assert (dir);  
   
                         if (man_file && catpath) {  
                                 /* we may have a FSSTND cat != cat_file */  
                                 char *std_cat_file =  
                                         convert_name (man_file, NULL);  
                                 status = is_changed (man_file, std_cat_file);  
           
                                 if (status != -2 && !(status & 1) == 1) {  
                                         cat_file = std_cat_file;  
                                         save_cat = format = 0;  
                                 } else  
                                         format = 1;  
                                 /* @@@ memory leak of std_cat_file */  
                         } else  
                                 format = 1;  
   
                         if (catpath)  
                                 free (catpath);  
                 } else  
                         format = 1;  
2513    
2514                  if (!man_file) {                  if (!man_file) {
2515                            /* Stray cat. */
2516                          assert (cat_file);                          assert (cat_file);
2517                          format = 0;                          format = 0;
2518                  } else if (!cat_file) {                  } else if (!cat_file) {
# Line 2703  static int display (const char *dir, con Line 2678  static int display (const char *dir, con
2678  }  }
2679    
2680    
2681  static char *find_cat_file (const char *path, const char *man_file)  static char *find_cat_file (const char *path, const char *original,
2682                                const char *man_file)
2683  {  {
2684            size_t path_len = strlen (path);
2685          char *cat_file, *cat_path;          char *cat_file, *cat_path;
2686            int status;
2687    
2688            /* Try the FSSTND way first, namely a cat page in the same hierarchy
2689             * as the original path to the man page. We don't create these
2690             * unless no alternate cat hierarchy is available, but will use them
2691             * if they happen to exist already and have the same timestamp as
2692             * the corresponding man page. (In practice I'm betting that this
2693             * means we'll hardly ever use them at all except for user
2694             * hierarchies; but compatibility, eh?)
2695             */
2696            cat_file = convert_name (original, 1);
2697            if (cat_file) {
2698                    status = is_changed (original, cat_file);
2699                    if (status != -2 && !(status & 1) == 1) {
2700                            if (debug)
2701                                    fprintf (stderr,
2702                                             "found valid FSSTND cat file %s\n",
2703                                             cat_file);
2704                            return cat_file;
2705                    }
2706                    free (cat_file);
2707            }
2708    
2709          /* could do this with `global' */          /* Otherwise, find the cat page we actually want to use or create,
2710             * taking any alternate cat hierarchy into account. If the original
2711             * path and man_file differ (i.e. original was a symlink or .so
2712             * link), try the link target and then the source.
2713             */
2714            if (!STREQ (man_file, original)) {
2715                    global_manpath = is_global_mandir (man_file);
2716                    cat_path = get_catpath
2717                            (man_file, global_manpath ? SYSTEM_CAT : USER_CAT);
2718    
2719                    if (cat_path) {
2720                            cat_file = convert_name (cat_path, 0);
2721                            free (cat_path);
2722                    } else if (STRNEQ (man_file, path, path_len) &&
2723                               man_file[path_len] == '/')
2724                            cat_file = convert_name (man_file, 1);
2725                    else
2726                            cat_file = NULL;
2727    
2728                    if (cat_file) {
2729                            char *cat_dir = xstrdup (cat_file);
2730                            char *tmp = strrchr (cat_dir, '/');
2731                            if (tmp)
2732                                    *tmp = 0;
2733                            if (is_directory (cat_dir)) {
2734                                    if (debug)
2735                                            fprintf (stderr,
2736                                                     "will try cat file %s\n",
2737                                                     cat_file);
2738                                    return cat_file;
2739                            } else if (debug)
2740                                    fprintf (stderr, "cat dir %s does not exist\n",
2741                                             cat_dir);
2742                            free (cat_dir);
2743                    } else if (debug)
2744                            fprintf (stderr, "no cat path for %s\n", man_file);
2745            }
2746    
2747          global_manpath = is_global_mandir (path);          global_manpath = is_global_mandir (original);
2748          cat_path = get_catpath          cat_path = get_catpath
2749                  (man_file, global_manpath ? SYSTEM_CAT : USER_CAT);                  (original, global_manpath ? SYSTEM_CAT : USER_CAT);
         cat_file = convert_name (man_file, cat_path);  
2750    
2751          if (cat_path)          if (cat_path) {
2752                    cat_file = convert_name (cat_path, 0);
2753                  free (cat_path);                  free (cat_path);
2754            } else
2755                    cat_file = convert_name (original, 1);
2756    
2757            if (debug) {
2758                    if (cat_file)
2759                            fprintf (stderr, "will try cat file %s\n", cat_file);
2760                    else
2761                            fprintf (stderr, "no cat path for %s\n", original);
2762            }
2763    
2764          return cat_file;          return cat_file;
2765  }  }
# Line 2938  static int display_filesystem (struct ca Line 2982  static int display_filesystem (struct ca
2982                                   man_file);                                   man_file);
2983                  lang = lang_dir (man_file);                  lang = lang_dir (man_file);
2984    
2985                  cat_file = find_cat_file (candp->path, man_file);                  cat_file = find_cat_file (candp->path, filename, man_file);
                 if (debug)  
                         fprintf (stderr, "will try cat file %s\n", cat_file);  
2986                  found = display (candp->path, man_file, cat_file, title, NULL);                  found = display (candp->path, man_file, cat_file, title, NULL);
2987                  free (cat_file);                  if (cat_file)
2988                            free (cat_file);
2989                  free (title);                  free (title);
2990    
2991  #ifdef COMP_SRC  #ifdef COMP_SRC
# Line 3032  static int display_database (struct cand Line 3075  static int display_database (struct cand
3075                                           man_file);                                           man_file);
3076                          lang = lang_dir (man_file);                          lang = lang_dir (man_file);
3077    
3078                          cat_file = find_cat_file (candp->path, man_file);                          cat_file = find_cat_file (candp->path, file, man_file);
3079                          found += display (candp->path, man_file, cat_file,                          found += display (candp->path, man_file, cat_file,
3080                                            title, in->filter);                                            title, in->filter);
3081                          free (cat_file);                          if (cat_file)
3082                                    free (cat_file);
3083  #ifdef COMP_SRC  #ifdef COMP_SRC
3084                          /* if ult_src() produced a ztemp file, we need to                          /* if ult_src() produced a ztemp file, we need to
3085                             remove it (and unexist it) before proceeding */                             remove it (and unexist it) before proceeding */

Legend:
Removed from v.1.107  
changed lines
  Added in v.1.108

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