Esempio n. 1
0
void
print_path_elements (const_string path)
{
  string elt;
  printf ("Elements of `%s':", path ? path : "(null)");

  for (elt = kpathsea_path_element (kpse_def, path); elt != NULL;
       elt = kpathsea_path_element (kpse_def, NULL))
    {
      printf (" %s", *elt ? elt : "`'");
    }

  puts (".");
}
Esempio n. 2
0
void
kpathsea_init_fallback_resolutions (kpathsea kpse, string envvar)
{
  string size;
  const_string size_var = ENVVAR (envvar, "TEXSIZES");
  string size_str = getenv (size_var);
  unsigned *last_resort_sizes = NULL;
  unsigned size_count = 0;
  const_string default_sizes = kpse->fallback_resolutions_string
                         ? kpse->fallback_resolutions_string
                         : DEFAULT_FONT_SIZES;
  string size_list = kpathsea_expand_default (kpse, size_str, default_sizes);

  /* Initialize the list of last-resort sizes.  */
  for (size = kpathsea_path_element (kpse, size_list); size != NULL;
       size = kpathsea_path_element (kpse, NULL))
    {
      unsigned s;
      if (! *size) /* Skip empty elements.  */
        continue;

      s = atoi (size);
      if (size_count && s < last_resort_sizes[size_count - 1]) {
    WARNING1 ("kpathsea: last resort size %s not in ascending order; ignored",
          size);
      } else {
        size_count++;
        XRETALLOC (last_resort_sizes, size_count, unsigned);
        last_resort_sizes[size_count - 1] = atoi (size);
      }
    }

  /* Add a zero to mark the end of the list.  */
  size_count++;
  XRETALLOC (last_resort_sizes, size_count, unsigned);
  last_resort_sizes[size_count - 1] = 0;

  free (size_list);

  kpse->fallback_resolutions = last_resort_sizes;
}
Esempio n. 3
0
string
kpathsea_selfdir (kpathsea kpse, const_string argv0)
{
  string ret = NULL;
  string self = NULL;

  if (kpathsea_absolute_p (kpse, argv0, true)) {
    self = xstrdup (argv0);
  } else {
#ifdef AMIGA
#include <dos.h>
#include <proto/dos.h>
#include <proto/exec.h>
    BPTR lock;
    struct DosLibrary *DOSBase
      = (struct DosLibrary *) OpenLibrary ("dos.library", 0L);
    assert (DOSBase);

    self = xmalloc (BUFSIZ);
    lock = findpath (argv0);
    if (lock != ((BPTR) -1)) {
      if (getpath (lock, self) == -1) {
        *self = '\0';
      } else {
        strcat (self,DIR_SEP_STRING);
        strcat (self,argv0);
      }
      UnLock (lock);
    }
    CloseLibrary((struct Library *) DOSBase);
#else /* not AMIGA */
    const_string elt;
    struct stat s;

    /* Have to check PATH.  But don't call kpse_path_search since we don't
       want to search any ls-R's or do anything special with //'s.  */
    for (elt = kpathsea_path_element (kpse, getenv ("PATH")); !self && elt;
         elt = kpathsea_path_element (kpse, NULL)) {
      string name;

      /* UNIX tradition interprets the empty path element as "." */
      if (*elt == 0) elt = ".";

      name = concat3 (elt, DIR_SEP_STRING, argv0);

      /* In order to do this perfectly, we'd have to check the owner bits only
         if we are the file owner, and the group bits only if we belong
         to the file group.  That's a lot of work, though, and it's not
         likely that kpathsea will ever be used with a program that's
         only executable by some classes and not others.  See the
         `file_status' function in execute_cmd.c in bash for what's
         necessary if we were to do it right.  */
      if (stat (name, &s) == 0 && s.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) {
        /* Do not stop at directories. */
        if (!S_ISDIR(s.st_mode))
          self = name;
      }
    }
#endif /* not AMIGA */
  }

  /* If argv0 is somehow dir/exename, `self' will still be NULL.  */
  if (!self)
    self = concat3 (".", DIR_SEP_STRING, argv0);

  ret = xdirname (remove_dots (kpse, expand_symlinks (kpse, self)));

  free (self);

  return ret;
}