Back to index

tetex-bin  3.0
Defines | Functions | Variables
kpsewhich.c File Reference
#include <kpathsea/config.h>
#include <kpathsea/c-ctype.h>
#include <kpathsea/c-pathch.h>
#include <kpathsea/expand.h>
#include <kpathsea/getopt.h>
#include <kpathsea/line.h>
#include <kpathsea/pathsearch.h>
#include <kpathsea/proginit.h>
#include <kpathsea/tex-file.h>
#include <kpathsea/tex-glyph.h>
#include <kpathsea/variable.h>
#include <kpathsea/progname.h>

Go to the source code of this file.

Defines

#define TRY_SUFFIX(ftry)
#define USAGE   "\ Standalone path lookup and expansion for Kpathsea.\n\\n\-debug=NUM set debugging flags.\n\-D, -dpi=NUM use a base resolution of NUM; default 600.\n\-engine=STRING set engine name to STRING.\n\-expand-braces=STRING output variable and brace expansion of STRING.\n\-expand-path=STRING output complete path expansion of STRING.\n\-expand-var=STRING output variable expansion of STRING.\n\-format=NAME use file type NAME (see list below).\n\-help print this message and exit.\n\-interactive ask for additional filenames to look up.\n\[-no]-mktex=FMT disable/enable mktexFMT generation (FMT=pk/mf/tex/tfm).\n\-mode=STRING set device name for $MAKETEX_MODE to STRING;\n\ no default.\n\-must-exist search the disk as well as ls-R if necessary\n\-path=STRING search in the path STRING.\n\-progname=STRING set program name to STRING.\n\-show-path=NAME output search path for file type NAME (see list below).\n\-var-value=STRING output the value of variable $STRING.\n\-version print version number and exit.\n \"
#define ARGUMENT_IS(a)   STREQ (long_options[option_index].name, a)

Functions

static unsigned find_dpi P1C (string, s)
static kpse_file_format_type
find_format 
P2C (string, name, boolean, is_filename)
static unsigned lookup P1C (string, name)
static void read_command_line P2C (int, argc, string *, argv)

Variables

unsigned dpi = 600
string var_to_expand = NULL
string braces_to_expand = NULL
string path_to_expand = NULL
string path_to_show = NULL
string var_to_value = NULL
kpse_file_format_type user_format = kpse_last_format
string user_format_string
string user_path
boolean interactive = false
boolean must_exist = false
boolean show_all = false
string mode = NULL
string progname = NULL
string engine = NULL
static struct option []

Define Documentation

#define ARGUMENT_IS (   a)    STREQ (long_options[option_index].name, a)

Definition at line 244 of file kpsewhich.c.

#define TRY_SUFFIX (   ftry)
Value:
(\
  try_len = (ftry) ? strlen (ftry) : 0, \
  (ftry) && try_len <= name_len \
     && FILESTRCASEEQ (ftry, name + name_len - try_len))
#define USAGE   "\ Standalone path lookup and expansion for Kpathsea.\n\\n\-debug=NUM set debugging flags.\n\-D, -dpi=NUM use a base resolution of NUM; default 600.\n\-engine=STRING set engine name to STRING.\n\-expand-braces=STRING output variable and brace expansion of STRING.\n\-expand-path=STRING output complete path expansion of STRING.\n\-expand-var=STRING output variable expansion of STRING.\n\-format=NAME use file type NAME (see list below).\n\-help print this message and exit.\n\-interactive ask for additional filenames to look up.\n\[-no]-mktex=FMT disable/enable mktexFMT generation (FMT=pk/mf/tex/tfm).\n\-mode=STRING set device name for $MAKETEX_MODE to STRING;\n\ no default.\n\-must-exist search the disk as well as ls-R if necessary\n\-path=STRING search in the path STRING.\n\-progname=STRING set program name to STRING.\n\-show-path=NAME output search path for file type NAME (see list below).\n\-var-value=STRING output the value of variable $STRING.\n\-version print version number and exit.\n \"

Definition at line 218 of file kpsewhich.c.


Function Documentation

static unsigned find_dpi P1C ( string  ,
s   
) [static]

Definition at line 72 of file kpsewhich.c.

{
  unsigned dpi_number = 0;
  string extension = find_suffix (s);
  
  if (extension != NULL)
    sscanf (extension, "%u", &dpi_number);

  return dpi_number;
}

Here is the call graph for this function:

static unsigned lookup P1C ( string  ,
name   
) [static]

Definition at line 163 of file kpsewhich.c.

{
  string ret = NULL;
  string *ret_list = NULL;
  int i;
  unsigned local_dpi;
  kpse_glyph_file_type glyph_ret;
  
  if (user_path) {
    if (show_all) {
      ret_list = kpse_all_path_search (user_path, name);
    } else {
       ret = kpse_path_search (user_path, name, must_exist);
    }
    
  } else {
    /* No user-specified search path, check user format or guess from NAME.  */
    kpse_file_format_type fmt = find_format (name, true);

    switch (fmt) {
      case kpse_pk_format:
      case kpse_gf_format:
      case kpse_any_glyph_format:
        /* Try to extract the resolution from the name.  */
        local_dpi = find_dpi (name);
        if (!local_dpi)
          local_dpi = dpi;
        ret = kpse_find_glyph (remove_suffix (name), local_dpi, fmt, &glyph_ret);
        break;

      case kpse_last_format:
        /* If the suffix isn't recognized, assume it's a tex file. */
        fmt = kpse_tex_format;
        /* fall through */

      default:
        ret = kpse_find_file (name, fmt, must_exist);
    }
  }
  
  if (ret)
    puts (ret);
  if (ret_list) {
    for (i = 0; ret_list[i]; i++)
      puts (ret_list[i]);
    /* Save whether we found anything */
    ret = ret_list[0];
    free (ret_list);
  }
  
  return ret == NULL;
}

Here is the call graph for this function:

static kpse_file_format_type find_format P2C ( string  ,
name  ,
boolean  ,
is_filename   
) [static]

Definition at line 92 of file kpsewhich.c.

{
  kpse_file_format_type ret;
  
  if (is_filename && user_format != kpse_last_format) {
    ret = user_format;
  } else if (FILESTRCASEEQ (name, "pdftex.cfg")) {
    ret = kpse_pdftex_config_format;
  } else {
    int f;  /* kpse_file_format_type */
    unsigned name_len = strlen (name);

/* Have to rely on `try_len' being declared here, since we can't assume
   GNU C and statement expressions.  */
#define TRY_SUFFIX(ftry) (\
  try_len = (ftry) ? strlen (ftry) : 0, \
  (ftry) && try_len <= name_len \
     && FILESTRCASEEQ (ftry, name + name_len - try_len))

    f = 0;
    while (f != kpse_last_format) {
      unsigned try_len;
      const_string *ext;
      const_string ftry;
      boolean found = false;
      
      if (!kpse_format_info[f].type)
        kpse_init_format ((kpse_file_format_type)f);

      if (!is_filename) {
        /* Allow the long name, but only in the -format option.  We don't
           want a filename confused with a format name.  */
        ftry = kpse_format_info[f].type;
        found = TRY_SUFFIX (ftry);
      }
      for (ext = kpse_format_info[f].suffix; !found && ext && *ext; ext++){
        found = TRY_SUFFIX (*ext);
      }      
      for (ext = kpse_format_info[f].alt_suffix; !found && ext && *ext; ext++){
        found = TRY_SUFFIX (*ext);
      }

      if (found)
        break;

      /* Some trickery here: the extensions for kpse_fmt_format can
       * clash with other extensions in use, and we prefer for those
       * others to be preferred.  And we don't want to change the
       * integer value of kpse_fmt_format.  So skip it when first
       * enountered, then use it when we've done everything else,
       * and use it as the end-guard.
       */
      if (f == kpse_fmt_format) {
        f = kpse_last_format;
      } else if (++f == kpse_fmt_format) {
        f++;
      } else if (f == kpse_last_format) {
        f = kpse_fmt_format;
      }
    }

    /* If there was a match, f will be one past the correct value.  */
    ret = f;
  }
  
  return ret;
}

Here is the call graph for this function:

static void read_command_line P2C ( int  ,
argc  ,
string ,
argv   
) [static]

Definition at line 272 of file kpsewhich.c.

{
  int g;   /* `getopt' return code.  */
  int option_index;

  for (;;) {
    g = getopt_long_only (argc, argv, "", long_options, &option_index);

    if (g == -1)
      break;

    if (g == '?')
      exit (1);  /* Unknown option.  */

    assert (g == 0); /* We have no short option names.  */

    if (ARGUMENT_IS ("debug")) {
      kpathsea_debug |= atoi (optarg);

    } else if (ARGUMENT_IS ("dpi") || ARGUMENT_IS ("D")) {
      dpi = atoi (optarg);

    } else if (ARGUMENT_IS ("engine")) {
      engine = optarg;
      
    } else if (ARGUMENT_IS ("expand-braces")) {
      braces_to_expand = optarg;
      
    } else if (ARGUMENT_IS ("expand-path")) {
      path_to_expand = optarg;

    } else if (ARGUMENT_IS ("expand-var")) {
      var_to_expand = optarg;

    } else if (ARGUMENT_IS ("format")) {
      user_format_string = optarg;

    } else if (ARGUMENT_IS ("help")) {
      int f; /* kpse_file_format_type */
      extern KPSEDLL char *kpse_bug_address; /* from version.c */
      
      printf ("Usage: %s [OPTION]... [FILENAME]...\n", argv[0]);
      fputs (USAGE, stdout);
      putchar ('\n');
      fputs (kpse_bug_address, stdout);

      /* Have to set this for init_format to work.  */
      kpse_set_program_name (argv[0], progname);

      puts ("\nRecognized format names and their suffixes:");
      for (f = 0; f < kpse_last_format; f++) {
        const_string *ext;
        kpse_init_format ((kpse_file_format_type)f);
        printf ("%s:", kpse_format_info[f].type);
        for (ext = kpse_format_info[f].suffix; ext && *ext; ext++) {
          putchar (' ');
          fputs (*ext, stdout);
        }
        for (ext = kpse_format_info[f].alt_suffix; ext && *ext; ext++) {
          putchar (' ');
          fputs (*ext, stdout);
        }
        putchar ('\n');
      }

      exit (0);

    } else if (ARGUMENT_IS ("mktex")) {
      kpse_maketex_option (optarg, true);

    } else if (ARGUMENT_IS ("mode")) {
      mode = optarg;

    } else if (ARGUMENT_IS ("no-mktex")) {
      kpse_maketex_option (optarg, false);

    } else if (ARGUMENT_IS ("path")) {
      user_path = optarg;

    } else if (ARGUMENT_IS ("progname")) {
      progname = optarg;

    } else if (ARGUMENT_IS ("show-path")) {
      path_to_show = optarg;
      user_format_string = optarg;

    } else if (ARGUMENT_IS ("var-value")) {
      var_to_value = optarg;

    } else if (ARGUMENT_IS ("version")) {
      extern KPSEDLL char *kpathsea_version_string; /* from version.c */
      puts (kpathsea_version_string);
      puts ("Copyright (C) 1997 - 2004 K. Berry & O. Weber.\n\
There is NO warranty.  You may redistribute this software\n\
under the terms of the GNU General Public License.\n\
For more information about these matters, see the files named COPYING.");
      exit (0);
    }

    /* Else it was just a flag; getopt has already done the assignment.  */
  }
  
  if (user_path && user_format_string) {
    fprintf (stderr, "-path (%s) and -format (%s) are mutually exclusive.\n",
             user_path, user_format_string);
    fputs ("Try `kpsewhich --help' for more information.\n", stderr);
    exit (1);
  }

  if (optind == argc && !var_to_expand && !braces_to_expand && !path_to_expand
                     && !path_to_show && !var_to_value) {
    fputs ("Missing argument. Try `kpsewhich --help' for more information.\n",
           stderr);
    exit (1);
  }
}

Here is the call graph for this function:


Variable Documentation

Definition at line 40 of file kpsewhich.c.

unsigned dpi = 600

Definition at line 35 of file kpsewhich.c.

Definition at line 66 of file kpsewhich.c.

Definition at line 51 of file kpsewhich.c.

Definition at line 60 of file kpsewhich.c.

Definition at line 54 of file kpsewhich.c.

struct option[] [static]
Initial value:
 { { "D",                   1, 0, 0 },
      { "all",                     0, (int *) &show_all, 1 },
      { "debug",            1, 0, 0 },
      { "dpi",                     1, 0, 0 },
      { "engine",           1, 0, 0 },
      { "expand-braces",    1, 0, 0 },
      { "expand-path",             1, 0, 0 },
      { "expand-var",              1, 0, 0 },
      { "format",           1, 0, 0 },
      { "help",                 0, 0, 0 },
      { "interactive",             0, (int *) &interactive, 1 },
      { "mktex",            1, 0, 0 },
      { "mode",                    1, 0, 0 },
      { "must-exist",              0, (int *) &must_exist, 1 },
      { "path",                    1, 0, 0 },
      { "no-mktex",         1, 0, 0 },
      { "progname",         1, 0, 0 },
      { "separator",        1, 0, 0 },
      { "show-path",        1, 0, 0 },
      { "var-value",        1, 0, 0 },
      { "version",              0, 0, 0 },
      { 0, 0, 0, 0 } }

Definition at line 248 of file kpsewhich.c.

Definition at line 41 of file kpsewhich.c.

Definition at line 42 of file kpsewhich.c.

Definition at line 63 of file kpsewhich.c.

Definition at line 57 of file kpsewhich.c.

Definition at line 46 of file kpsewhich.c.

Definition at line 47 of file kpsewhich.c.

Definition at line 48 of file kpsewhich.c.

Definition at line 39 of file kpsewhich.c.

Definition at line 43 of file kpsewhich.c.