home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / unixtex-6.1b-src.tgz / tar.out / contrib / unixtex / web2c / lib / ourpaths.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  4KB  |  120 lines

  1. /* ourpaths.c: path searching.  */
  2.  
  3. #include "config.h"
  4.  
  5. #include <kpathsea/cnf.h>
  6. #include <kpathsea/default.h>
  7. #include <kpathsea/expand.h>
  8. #include <kpathsea/fontmap.h>
  9. #include <kpathsea/paths.h>
  10. #include <kpathsea/pathsearch.h>
  11. #include <kpathsea/tex-file.h>
  12.  
  13. /* `path_dirs' is initialized in `setpaths', to a null-terminated array
  14.    of directories to search for.  */
  15. static const_string path_dirs[LAST_PATH];
  16.  
  17.  
  18. /* This sets up the paths, by either copying from an environment variable
  19.    or using the default path, which is defined as a preprocessor symbol
  20.    (with the same name as the environment variable) in `site.h'.  The
  21.    parameter PATH_BITS is a logical or of the paths we need to set.  */
  22.  
  23. extern void
  24. setpaths (path_bits)
  25.     int path_bits;
  26. {
  27.   if (path_bits & BIBINPUTPATHBIT)
  28.     path_dirs[BIBINPUTPATH] = kpse_init_format (kpse_bib_format);
  29.  
  30.   if (path_bits & BSTINPUTPATHBIT)
  31.     path_dirs[BSTINPUTPATH] = kpse_init_format (kpse_bst_format);
  32.  
  33.   if (path_bits & GFFILEPATHBIT)
  34.     path_dirs[GFFILEPATH] = kpse_init_format (kpse_gf_format);
  35.  
  36.   if (path_bits & MFBASEPATHBIT)
  37.     path_dirs[MFBASEPATH] = kpse_init_format (kpse_base_format);
  38.  
  39.   if (path_bits & MFINPUTPATHBIT)
  40.     path_dirs[MFINPUTPATH] = kpse_init_format (kpse_mf_format);
  41.  
  42.   if (path_bits & MFPOOLPATHBIT)
  43.     path_dirs[MFPOOLPATH] = kpse_init_format (kpse_mfpool_format);
  44.  
  45.   if (path_bits & PKFILEPATHBIT)
  46.     path_dirs[PKFILEPATH] = kpse_init_format (kpse_pk_format);
  47.  
  48.   if (path_bits & TEXFORMATPATHBIT)
  49.     path_dirs[TEXFORMATPATH] = kpse_init_format (kpse_fmt_format);
  50.  
  51.   if (path_bits & TEXINPUTPATHBIT)
  52.     path_dirs[TEXINPUTPATH] = kpse_init_format (kpse_tex_format);
  53.  
  54.   if (path_bits & TEXPOOLPATHBIT)
  55.     path_dirs[TEXPOOLPATH] = kpse_init_format (kpse_texpool_format);
  56.  
  57.   if (path_bits & TFMFILEPATHBIT)
  58.     path_dirs[TFMFILEPATH] = kpse_init_format (kpse_tfm_format);
  59.  
  60.   if (path_bits & VFFILEPATHBIT)
  61.     path_dirs[VFFILEPATH] = kpse_init_format (kpse_vf_format);
  62. }
  63.  
  64. /* Look for NAME, a Pascal string, in the colon-separated list of
  65.    directories given by `path_dirs[PATH_INDEX]'.  If the search is
  66.    successful, leave the full pathname in NAME (which therefore must
  67.    have enough room for such a pathname), padded with blanks.
  68.    Otherwise, or if NAME is an absolute or relative pathname, just leave
  69.    it alone.  */
  70.  
  71. boolean
  72. testreadaccess (name, path_index)
  73.     string name;
  74.     int path_index;
  75. {
  76.   string found;  
  77.   const_string path = path_dirs[path_index];
  78.   
  79.   make_c_string (&name);
  80.  
  81.   /* Look for it.  Don't use the kpse_find_glyph stuff, since we don't
  82.      have the dpi available separately, and anyway we don't care about
  83.      having pktogf run MakeTeXPK, etc.  */
  84.   found = kpse_path_search (path, name, true);
  85.  
  86.   /* If we didn't find it, and we're looking for a font, maybe it's
  87.      an alias defined in a mapping file.  This duplicates most of
  88.      `try_fontmap' in `kpathsea/tex-glyph.c', but the differences are
  89.      substantial enough that it doesn't seem worth combining.  */
  90.   if (!found && (path_index == TFMFILEPATH || path_index == GFFILEPATH
  91.                  || path_index == PKFILEPATH))
  92.     {
  93.       string *mapped_names;
  94.       static hash_table_type fontmap = { NULL, 0 };
  95.       
  96.       /* Fault in the mapping if necessary.  */
  97.       if (fontmap.size == 0)
  98.         fontmap = map_create (path);
  99.       
  100.       /* Now look for our filename in the mapping.  */
  101.       mapped_names = map_lookup (fontmap, name);
  102.       if (mapped_names)
  103.         {
  104.           string mapped_name;
  105.           while ((mapped_name = *mapped_names++) && !found)
  106.             {
  107.               found = kpse_path_search (path, mapped_name, true);
  108.             }
  109.         }
  110.     }
  111.  
  112.   /* If we found it somewhere, save it.  */
  113.   if (found)
  114.     strcpy (name, found);
  115.   
  116.   make_pascal_string (&name);
  117.   
  118.   return found != NULL;
  119. }
  120.