home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / tex / texsrc1 / Src / lib / c / ourpaths < prev    next >
Text File  |  1993-05-02  |  4KB  |  127 lines

  1. /* ourpaths.c: path searching.  */
  2.  
  3. #include "config.h"
  4.  
  5. #include "fontmap.h"
  6. #include "paths.h"
  7. #include "pathsrch.h"
  8.  
  9.  
  10. /* `path_dirs' is initialized in `setpaths', to a null-terminated array
  11.    of directories to search for.  */
  12. static string *path_dirs[LAST_PATH];
  13.  
  14.  
  15. /* This sets up the paths, by either copying from an environment variable
  16.    or using the default path, which is defined as a preprocessor symbol
  17.    (with the same name as the environment variable) in `site.h'.  The
  18.    parameter PATH_BITS is a logical or of the paths we need to set.  */
  19.  
  20. extern void
  21. setpaths (path_bits)
  22.   int path_bits;
  23. {
  24.   if (path_bits & BIBINPUTPATHBIT)
  25.     path_dirs[BIBINPUTPATH] = initialize_path_list ("BIBINPUTS", BIBINPUTS);
  26.  
  27.   if (path_bits & BSTINPUTPATHBIT)
  28.     {
  29.       string bst_var = getenv ("BSTINPUTS") ? "BSTINPUTS" : "TEXINPUTS";
  30.       path_dirs[BSTINPUTPATH] = initialize_path_list (bst_var, BSTINPUTS);
  31.     }
  32.  
  33.   if (path_bits & GFFILEPATHBIT)
  34.     {
  35.       string gf_var = getenv ("GFFONTS") ? "GFFONTS" : "TEXFONTS";
  36.       path_dirs[GFFILEPATH] = initialize_path_list (gf_var, GFFONTS);
  37.     }
  38.  
  39.   if (path_bits & MFBASEPATHBIT)
  40.     path_dirs[MFBASEPATH] = initialize_path_list ("MFBASES", MFBASES);
  41.  
  42.   if (path_bits & MFINPUTPATHBIT)
  43.     path_dirs[MFINPUTPATH] = initialize_path_list ("MFINPUTS", MFINPUTS);
  44.  
  45.   if (path_bits & MFPOOLPATHBIT)
  46.     path_dirs[MFPOOLPATH] = initialize_path_list ("MFPOOL", MFPOOL);
  47.  
  48.   if (path_bits & PKFILEPATHBIT)
  49.     {
  50.       string pk_var = getenv ("PKFONTS") ? "PKFONTS"
  51.                       : getenv ("TEXPKS") ? "TEXPKS" : "TEXFONTS";
  52.       path_dirs[PKFILEPATH] = initialize_path_list (pk_var, PKFONTS);
  53.     }
  54.  
  55.   if (path_bits & TEXFORMATPATHBIT)
  56.     path_dirs[TEXFORMATPATH]
  57.       = initialize_path_list ("TEXFORMATS", TEXFORMATS);
  58.  
  59.   if (path_bits & TEXINPUTPATHBIT)
  60.     path_dirs[TEXINPUTPATH]
  61.       = initialize_path_list ("TEXINPUTS", TEXINPUTS);
  62.  
  63.   if (path_bits & TEXPOOLPATHBIT)
  64.     path_dirs[TEXPOOLPATH] = initialize_path_list ("TEXPOOL", TEXPOOL);
  65.  
  66.   if (path_bits & TFMFILEPATHBIT)
  67.       path_dirs[TFMFILEPATH] = initialize_path_list ("TEXFONTS", TEXFONTS);
  68.  
  69.   if (path_bits & VFFILEPATHBIT)
  70.     {
  71.       string vf_var = getenv ("VFFONTS") ? "VFFONTS" : "TEXFONTS";
  72.       path_dirs[VFFILEPATH] = initialize_path_list (vf_var, VFFONTS);
  73.     }
  74. }
  75.  
  76. /* Look for NAME, a Pascal string, in the colon-separated list of
  77.    directories given by `path_dirs[PATH_INDEX]'.  If the search is
  78.    successful, leave the full pathname in NAME (which therefore must
  79.    have enough room for such a pathname), padded with blanks.
  80.    Otherwise, or if NAME is an absolute or relative pathname, just leave
  81.    it alone.  */
  82.  
  83. boolean
  84. testreadaccess (name, path_index)
  85.     char *name;
  86.     int path_index;
  87. {
  88.   string found;  
  89.   
  90.   make_c_string (&name);
  91.  
  92. #ifdef RISCOS_DEBUG
  93.   fprintf(stderr, "testreadaccess('%s', %d)\n", name, path_index);
  94. #endif
  95.  
  96.   /* Look for it.  */
  97.   found = find_path_filename (name, path_dirs[path_index]);
  98.  
  99.   /* If we didn't find it, and we're looking for a font, maybe it's
  100.      an alias defined in a mapping file.  */
  101.   if (!found && path_index == TFMFILEPATH)
  102.     {
  103.       char *mapped_name;
  104.       static map_type fontmap = NULL;
  105.       
  106.       /* Fault in the mapping if necessary.  */
  107.       if (fontmap == NULL)
  108.         fontmap = map_create (path_dirs[path_index]);
  109.       
  110.       /* Now look for our filename in the mapping.  */
  111.       mapped_name = map_lookup (fontmap, name);
  112.       if (mapped_name)
  113.         {
  114.           /* Found a possibility.  Look for the new name.  */
  115.           found = find_path_filename (mapped_name, path_dirs[path_index]);
  116.         }
  117.     }
  118.  
  119.   /* If we found it somewhere, save it.  */
  120.   if (found)
  121.     strcpy (name, found);
  122.   
  123.   make_pascal_string (&name);
  124.   
  125.   return found != NULL;
  126. }
  127.