Back to index

tetex-bin  3.0
Defines | Functions | Variables
filesys.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define INFOPATH_PREPEND   0
#define INFOPATH_APPEND   1
#define DEFAULT_INFOPATH   "/usr/local/info:/usr/info:/usr/local/lib/info:/usr/lib/info:/usr/local/gnu/info:/usr/local/gnu/lib/info:/usr/gnu/info:/usr/gnu/lib/info:/opt/gnu/info:/usr/share/info:/usr/share/lib/info:/usr/local/share/info:/usr/local/share/lib/info:/usr/gnu/lib/emacs/info:/usr/local/gnu/lib/emacs/info:/usr/local/lib/emacs/info:/usr/local/emacs/info:."

Functions

void zap_infopath (void)
void info_add_path (char *path, int where)
char * info_find_fullpath (char *partial)
long convert_eols (char *text, long textlen)
char * filesys_read_info_file (char *pathname, long int *filesize, struct stat *finfo, int *is_compressed)
char * filesys_read_compressed (char *pathname, long int *filesize)
char * filesys_decompressor_for_file (char *filename)
int compressed_filename_p (char *filename)
char * filesys_error_string (char *filename, int error_num)
char * extract_colon_unit (char *string, int *idx)
int is_dir_name (char *filename)

Variables

char * infopath
int filesys_error_number

Define Documentation

#define DEFAULT_INFOPATH   "/usr/local/info:/usr/info:/usr/local/lib/info:/usr/lib/info:/usr/local/gnu/info:/usr/local/gnu/lib/info:/usr/gnu/info:/usr/gnu/lib/info:/opt/gnu/info:/usr/share/info:/usr/share/lib/info:/usr/local/share/info:/usr/local/share/lib/info:/usr/gnu/lib/emacs/info:/usr/local/gnu/lib/emacs/info:/usr/local/lib/emacs/info:/usr/local/emacs/info:."

Definition at line 81 of file filesys.h.

#define INFOPATH_APPEND   1

Definition at line 39 of file filesys.h.

#define INFOPATH_PREPEND   0

Definition at line 38 of file filesys.h.


Function Documentation

int compressed_filename_p ( char *  filename)

Definition at line 604 of file filesys.c.

{
  char *decompressor;

  /* Find the final extension of this filename, and see if it matches one
     of our known ones. */
  decompressor = filesys_decompressor_for_file (filename);

  if (decompressor)
    return (1);
  else
    return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

long convert_eols ( char *  text,
long  textlen 
)
char* extract_colon_unit ( char *  string,
int idx 
)

Definition at line 276 of file filesys.c.

{
  unsigned int i = (unsigned int) *idx;
  unsigned int start = i;

  if (!string || i >= strlen (string))
    return NULL;

  if (!string[i]) /* end of string */
    return NULL;

  /* Advance to next PATH_SEP.  */
  while (string[i] && string[i] != PATH_SEP[0])
    i++;

  {
    char *value = xmalloc ((i - start) + 1);
    strncpy (value, &string[start], (i - start));
    value[i - start] = 0;

    i++; /* move past PATH_SEP */
    *idx = i;
    return value;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* filesys_decompressor_for_file ( char *  filename)

Definition at line 620 of file filesys.c.

{
  register int i;
  char *extension = (char *)NULL;

  /* Find the final extension of FILENAME, and see if it appears in our
     list of known compression extensions. */
  for (i = strlen (filename) - 1; i > 0; i--)
    if (filename[i] == '.')
      {
        extension = filename + i;
        break;
      }

  if (!extension)
    return ((char *)NULL);

  for (i = 0; compress_suffixes[i].suffix; i++)
    if (FILENAME_CMP (extension, compress_suffixes[i].suffix) == 0)
      return (compress_suffixes[i].decompressor);

#if defined (__MSDOS__)
  /* If no other suffix matched, allow any extension which ends
     with `z' to be decompressed by gunzip.  Due to limited 8+3 DOS
     file namespace, we can expect many such cases, and supporting
     every weird suffix thus produced would be a pain.  */
  if (extension[strlen (extension) - 1] == 'z' ||
      extension[strlen (extension) - 1] == 'Z')
    return "gunzip";
#endif

  return ((char *)NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* filesys_error_string ( char *  filename,
int  error_num 
)

Definition at line 663 of file filesys.c.

{
  int len;
  char *result;

  if (error_num == 0)
    return ((char *)NULL);

  result = strerror (error_num);

  len = 4 + strlen (filename) + strlen (result);
  if (len >= errmsg_buf_size)
    errmsg_buf = (char *)xrealloc (errmsg_buf, (errmsg_buf_size = 2 + len));

  sprintf (errmsg_buf, "%s: %s", filename, result);
  return (errmsg_buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* filesys_read_compressed ( char *  pathname,
long int filesize 
)

Definition at line 516 of file filesys.c.

{
  FILE *stream;
  char *command, *decompressor;
  char *contents = (char *)NULL;

  *filesize = filesys_error_number = 0;

  decompressor = filesys_decompressor_for_file (pathname);

  if (!decompressor)
    return ((char *)NULL);

  command = (char *)xmalloc (15 + strlen (pathname) + strlen (decompressor));
  /* Explicit .exe suffix makes the diagnostics of `popen'
     better on systems where COMMAND.COM is the stock shell.  */
  sprintf (command, "%s%s < %s",
          decompressor, STRIP_DOT_EXE ? ".exe" : "", pathname);

#if !defined (BUILDING_LIBRARY)
  if (info_windows_initialized_p)
    {
      char *temp;

      temp = (char *)xmalloc (5 + strlen (command));
      sprintf (temp, "%s...", command);
      message_in_echo_area ("%s", temp, NULL);
      free (temp);
    }
#endif /* !BUILDING_LIBRARY */

  stream = popen (command, FOPEN_RBIN);
  free (command);

  /* Read chunks from this file until there are none left to read. */
  if (stream)
    {
      long offset, size;
      char *chunk;
    
      offset = size = 0;
      chunk = (char *)xmalloc (FILESYS_PIPE_BUFFER_SIZE);

      while (1)
        {
          int bytes_read;

          bytes_read = fread (chunk, 1, FILESYS_PIPE_BUFFER_SIZE, stream);

          if (bytes_read + offset >= size)
            contents = (char *)xrealloc
              (contents, size += (2 * FILESYS_PIPE_BUFFER_SIZE));

          memcpy (contents + offset, chunk, bytes_read);
          offset += bytes_read;
          if (bytes_read != FILESYS_PIPE_BUFFER_SIZE)
            break;
        }

      free (chunk);
      if (pclose (stream) == -1)
       {
         if (contents)
           free (contents);
         contents = (char *)NULL;
         filesys_error_number = errno;
       }
      else
       {
         *filesize = convert_eols (contents, offset);
         contents = (char *)xrealloc (contents, 1 + *filesize);
         contents[*filesize] = '\0';
       }
    }
  else
    {
      filesys_error_number = errno;
    }

#if !defined (BUILDING_LIBARARY)
  if (info_windows_initialized_p)
    unmessage_in_echo_area ();
#endif /* !BUILDING_LIBRARY */
  return (contents);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* filesys_read_info_file ( char *  pathname,
long int filesize,
struct stat finfo,
int is_compressed 
)

Definition at line 454 of file filesys.c.

{
  long st_size;

  *filesize = filesys_error_number = 0;

  if (compressed_filename_p (pathname))
    {
      *is_compressed = 1;
      return (filesys_read_compressed (pathname, filesize));
    }
  else
    {
      int descriptor;
      char *contents;

      *is_compressed = 0;
      descriptor = open (pathname, O_RDONLY | O_BINARY, 0666);

      /* If the file couldn't be opened, give up. */
      if (descriptor < 0)
        {
          filesys_error_number = errno;
          return ((char *)NULL);
        }

      /* Try to read the contents of this file. */
      st_size = (long) finfo->st_size;
      contents = (char *)xmalloc (1 + st_size);
      if ((read (descriptor, contents, st_size)) != st_size)
        {
         filesys_error_number = errno;
         close (descriptor);
         free (contents);
         return ((char *)NULL);
        }

      close (descriptor);

      /* Convert any DOS-style CRLF EOLs into Unix-style NL.
        Seems like a good idea to have even on Unix, in case the Info
        files are coming from some Windows system across a network.  */
      *filesize = convert_eols (contents, st_size);

      /* EOL conversion can shrink the text quite a bit.  We don't
        want to waste storage.  */
      if (*filesize < st_size)
       contents = (char *)xrealloc (contents, 1 + *filesize);
      contents[*filesize] = '\0';

      return (contents);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void info_add_path ( char *  path,
int  where 
)

Definition at line 371 of file filesys.c.

{
  int len;

  if (!infopath)
    {
      infopath = (char *)xmalloc (infopath_size = 200 + strlen (path));
      infopath[0] = '\0';
    }

  len = strlen (path) + strlen (infopath);

  if (len + 2 >= infopath_size)
    infopath = (char *)xrealloc (infopath, (infopath_size += (2 * len) + 2));

  if (!*infopath)
    strcpy (infopath, path);
  else if (where == INFOPATH_APPEND)
    {
      strcat (infopath, PATH_SEP);
      strcat (infopath, path);
    }
  else if (where == INFOPATH_PREPEND)
    {
      char *temp = xstrdup (infopath);
      strcpy (infopath, path);
      strcat (infopath, PATH_SEP);
      strcat (infopath, temp);
      free (temp);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* info_find_fullpath ( char *  partial)

Definition at line 83 of file filesys.c.

{
  int initial_character;
  char *temp;

  filesys_error_number = 0;

  maybe_initialize_infopath ();

  if (partial && (initial_character = *partial))
    {
      char *expansion;

      expansion = lookup_info_filename (partial);

      if (expansion)
        return (expansion);

      /* If we have the full path to this file, we still may have to add
         various extensions to it.  I guess we have to stat this file
         after all. */
      if (IS_ABSOLUTE (partial))
       temp = info_absolute_file (partial);
      else if (initial_character == '~')
        {
          expansion = tilde_expand_word (partial);
          if (IS_ABSOLUTE (expansion))
            {
              temp = info_absolute_file (expansion);
              free (expansion);
            }
          else
            temp = expansion;
        }
      else if (initial_character == '.' &&
               (IS_SLASH (partial[1]) ||
              (partial[1] == '.' && IS_SLASH (partial[2]))))
        {
          if (local_temp_filename_size < 1024)
            local_temp_filename = (char *)xrealloc
              (local_temp_filename, (local_temp_filename_size = 1024));
#if defined (HAVE_GETCWD)
          if (!getcwd (local_temp_filename, local_temp_filename_size))
#else /*  !HAVE_GETCWD */
          if (!getwd (local_temp_filename))
#endif /* !HAVE_GETCWD */
            {
              filesys_error_number = errno;
              return (partial);
            }

          strcat (local_temp_filename, "/");
          strcat (local_temp_filename, partial);
         temp = info_absolute_file (local_temp_filename); /* try extensions */
         if (!temp)
           partial = local_temp_filename;
        }
      else
        temp = info_file_in_path (partial, infopath);

      if (temp)
        {
          remember_info_filename (partial, temp);
          if (strlen (temp) > (unsigned int) local_temp_filename_size)
            local_temp_filename = (char *) xrealloc
              (local_temp_filename,
               (local_temp_filename_size = (50 + strlen (temp))));
          strcpy (local_temp_filename, temp);
          free (temp);
          return (local_temp_filename);
        }
    }
  return (partial);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int is_dir_name ( char *  filename)

Definition at line 686 of file filesys.c.

{
  unsigned i;

  for (i = 0; info_suffixes[i]; i++)
    {
      unsigned c;
      char trydir[50];
      strcpy (trydir, "dir");
      strcat (trydir, info_suffixes[i]);
      
      if (strcasecmp (filename, trydir) == 0)
        return 1;

      for (c = 0; compress_suffixes[c].suffix; c++)
        {
          char dir_compressed[50]; /* can be short */
          strcpy (dir_compressed, trydir); 
          strcat (dir_compressed, compress_suffixes[c].suffix);
          if (strcasecmp (filename, dir_compressed) == 0)
            return 1;
        }
    }  

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 405 of file filesys.c.

{
  if (infopath)
    free (infopath);

  infopath = (char *)NULL;
  infopath_size = 0;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 655 of file filesys.c.

char* infopath

Definition at line 73 of file filesys.c.