Back to index

tetex-bin  3.0
Defines | Functions | Variables
fontmap.c File Reference
#include <kpathsea/config.h>
#include <kpathsea/c-ctype.h>
#include <kpathsea/c-fopen.h>
#include <kpathsea/fontmap.h>
#include <kpathsea/hash.h>
#include <kpathsea/line.h>
#include <kpathsea/pathsearch.h>
#include <kpathsea/str-list.h>
#include <kpathsea/tex-file.h>

Go to the source code of this file.

Defines

#define MAP_NAME   "texfonts.map"
#define MAP_HASH_SIZE   4001

Functions

static string token P1C (const_string, str)
static void map_file_parse P1C (const_string, map_filename)
static void read_all_maps P1H (void)
string *kpse_fontmap_lookup P1C (const_string, key)

Variables

static hash_table_type map
static const_string map_path

Define Documentation

#define MAP_HASH_SIZE   4001

Definition at line 37 of file fontmap.c.

#define MAP_NAME   "texfonts.map"

Definition at line 34 of file fontmap.c.


Function Documentation

static string token P1C ( const_string  ,
str   
) [static]

Definition at line 45 of file fontmap.c.

{
  unsigned len;
  const_string start;
  string ret;
  
  while (*str && ISSPACE (*str))
    str++;
  
  start = str;
  while (*str && !ISSPACE (*str))
    str++;
  
  len = str - start;
  ret = (string)xmalloc (len + 1);
  strncpy (ret, start, len);
  ret[len] = 0;
  
  return ret;
}

Here is the call graph for this function:

static void map_file_parse P1C ( const_string  ,
map_filename   
) [static]

Definition at line 76 of file fontmap.c.

{
  char *orig_l;
  unsigned map_lineno = 0;
  FILE *f = xfopen (map_filename, FOPEN_R_MODE);
  
  while ((orig_l = read_line (f)) != NULL) {
    string filename;
    string l = orig_l;
    string comment_loc = strrchr (l, '%');
    if (!comment_loc) {
      comment_loc = strstr (l, "@c");
    }
    
    /* Ignore anything after a % or @c.  */
    if (comment_loc)
      *comment_loc = 0;

    map_lineno++;

    /* Skip leading whitespace so we can use strlen below.  Can't use
       strtok since this routine is recursive.  */
    while (*l && ISSPACE (*l))
      l++;
      
    /* If we don't have any filename, that's ok, the line is blank.  */
    filename = token (l);
    if (filename) {
      string alias = token (l + strlen (filename));

      if (STREQ (filename, "include")) {
        if (alias == NULL) {
          WARNING2 ("%s:%u: Filename argument for include directive missing",
                    map_filename, map_lineno);
        } else {
          string include_fname = kpse_path_search (map_path, alias, false);
          if (include_fname) {
            map_file_parse (include_fname);
            if (include_fname != alias)
              free (include_fname);
          } else {
            WARNING3 ("%s:%u: Can't find fontname include file `%s'",
                      map_filename, map_lineno, alias);
          }
          free (alias);
          free (filename);
        }

      /* But if we have a filename and no alias, something's wrong.  */
      } else if (alias == NULL) {
        WARNING3 ("%s:%u: Fontname alias missing for filename `%s'",
                  map_filename, map_lineno, filename);
        free (filename);

      } else {
        /* We've got everything.  Insert the new entry.  They were
           already dynamically allocated, so don't bother with xstrdup.  */
        hash_insert_normalized (&map, alias, filename);
      }
    }

    free (l);
  }
  
  xfclose (f, map_filename);
}

Here is the call graph for this function:

string* kpse_fontmap_lookup P1C ( const_string  ,
key   
)

Definition at line 167 of file fontmap.c.

{
  string *ret;
  string suffix = find_suffix (key);
  
  if (map.size == 0) {
    read_all_maps ();
  }

  ret = hash_lookup (map, key);
  if (!ret) {
    /* OK, the original KEY didn't work.  Let's check for the KEY without
       an extension -- perhaps they gave foobar.tfm, but the mapping only
       defines `foobar'.  */
    if (suffix) {
      string base_key = remove_suffix (key);
      ret = hash_lookup (map, base_key);
      free (base_key);
    }
  }

  /* Append any original suffix.  */
  if (ret && suffix) {
    string *elt;
    for (elt = ret; *elt; elt++) {
      *elt = extend_filename (*elt, suffix);
    }
  }

  return ret;
}

Here is the call graph for this function:

static void read_all_maps P1H ( void  ) [static]

Definition at line 148 of file fontmap.c.

{
  string *filenames;
  
  map_path = kpse_init_format (kpse_fontmap_format);
  filenames = kpse_all_path_search (map_path, MAP_NAME);
  
  map = hash_create (MAP_HASH_SIZE);

  while (*filenames) {
    map_file_parse (*filenames);
    filenames++;
  }
}

Variable Documentation

hash_table_type map [static]

Definition at line 32 of file fontmap.c.

Definition at line 40 of file fontmap.c.