Back to index

tetex-bin  3.0
Defines | Functions | Variables
psearch.h File Reference
#include <sys/types.h>
#include <sys/stat.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define NONFATAL   0
#define FATAL   1

Functions

char * path (char *deFault, char *env)
void substitute (char *str, char *patterns,...)
char * search_file (char *path, char *file, int terminate)
void init_pksearch (int bdpi, char *mode, int margin, char *tolerance)
char * search_pkfile (char *path, char *font, int dpi)
int evaluate (char *expr, int dpi)
int nearesthalf (int dpi)
void subtilde (char **fn, char **path)
int absname (char *name)
char * search_flipath (char *flipath, int(*font)(char *, int))

Variables

int tilde

Define Documentation

#define FATAL   1

Definition at line 38 of file psearch.h.

#define NONFATAL   0

Definition at line 36 of file psearch.h.


Function Documentation

int absname ( char *  name)

Definition at line 211 of file psearch.c.

                        {

   if (*name == DIRSEP) return 1;
#ifdef MSDOS
   if (*(name+1) == ':' && *(name+2) == DIRSEP && isalpha(*name)) return 1;
#endif
   return 0;
}

Here is the caller graph for this function:

int evaluate ( char *  expr,
int  dpi 
)

Definition at line 356 of file psearch.c.

                                  {
   char expression[128];
   int result;

   if (expr == NULL || *expr == '\0') return 0;
   strcpy(expression, expr);
   substitute(expression, "%d", dpi);
   if (strexpr(&result, expression))
      fatal("%s: expression error\n", expression);
   return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void init_pksearch ( int  bdpi,
char *  mode,
int  margin,
char *  tolerance 
)

Definition at line 346 of file psearch.c.

                                                                      {
   _bdpi = bdpi;
   _mode = mode;
   _margin = margin;
   _tolerance = tolerance;
}
int nearesthalf ( int  dpi)

Definition at line 374 of file psearch.c.

                         {
   double near = _bdpi, half = 1.095445115; int tolerance;

   tolerance = evaluate(_tolerance, dpi);
   if (tolerance == 0 || dpi == _bdpi) return dpi;
   if (dpi > INT(near)+tolerance)
      while (dpi > INT(near)+tolerance) near*=half;
   else if (dpi < INT(near)-tolerance)
      while (dpi < INT(near)-tolerance) near/=half;
   if (dpi >= INT(near)-tolerance && dpi <= INT(near)+tolerance)
      return INT(near);
   return dpi;
}

Here is the call graph for this function:

char* path ( char *  deFault,
char *  env 
)

Definition at line 76 of file psearch.c.

                                     {
   char *e, *p, *q; int len, left = MAXPATHLEN;

   if (env == NULL) return deFault;

   p = (char *) malloc(MAXPATHLEN);
   if (p == NULL) fatal("Out of memory\n");

   q = p; e = env;
   while (*e) {
      if (*e == PATHSEP) {
         if (left == MAXPATHLEN) {
           len = strlen(deFault);
            if (len > left-1) fatal("'%s' path too long!\n", env);
           strcpy(q, deFault);
           q += len; left -= len;
           *q++ = *e++; left--;
        }
        else if (*(e+1) == PATHSEP || *(e+1) == '\0') {
           *q++ = *e++; left--;
            len = strlen(deFault);
           if (len > left) fatal("'%s' path too long!\n", env);     
            strcpy(q, deFault);
           q += len; left -= len;
        }
        else {
          *q++ = *e++; left--;
        }
      }
      else {
         *q++ = *e++; left--;
      }
      if (left == 0) fatal("'%s' path too long!\n", env);
   }
   *q = '\0';
   return p;
}

Here is the call graph for this function:

char* search_file ( char *  path,
char *  file,
int  terminate 
)

Definition at line 225 of file psearch.c.

                                                         {
   char *fn, pe[MAXPATHLEN], *ppe, *ppath;
   struct stat status;

   if (path == NULL || *path == '\0' || absname(file)) {
      if (stat(file, &status) == 0) return file;
      if (terminate) fatal("File <%s> not found\n", file);
      return NULL;
   }
   ppath = path;
   while (*ppath) {
      /* copy next pathelement into pe */
      ppe = pe;
      while (*ppath != PATHSEP && *ppath != '\0') {
         if (tilde && *ppath == '~')
            subtilde(&ppe, &ppath);
         else
            *ppe++ = *ppath++;
      }
      *ppe = '\0';
      if (*ppath == PATHSEP) ppath++;
      if (fn = rsearch(pe, file)) return fn;
   }
   if (terminate) fatal("File <%s> not found in path \"%s\"\n", file, path);
   return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* search_flipath ( char *  flipath,
int(*)(char *, int font 
)

Definition at line 529 of file psearch.c.

                                                              {
   char fn[MAXPATHLEN], *pfn, *pfli, *fliname;
   int len;

   if (flipath == NULL) fatal("Invalid fli path\n");

   /* treat first element of flipath as a directory */
   pfn = fn;
   while (*flipath != PATHSEP && *flipath != '\0') {
      *pfn++ = *flipath++;
   }
   *pfn = '\0'; len = strlen(fn);
   if (len >= 1 && fn[len-1] != DIRSEP) *pfn++ = DIRSEP;

   /* and next elements as fli files */
   while (*flipath != '\0') {
      /* copy next pathelement into fn */
      pfli = pfn; flipath++;
      while (*flipath != PATHSEP && *flipath != '\0') {
         *pfli++ = *flipath++;
      }
      *pfli = '\0'; len = strlen(pfn);
      if (len > 4 && strcmp(pfli-4, ".fli") != 0)
         strcat(pfli, ".fli");
      if ((fliname = search_flifile(fn, font)) != NULL)
        return fliname;
   }
   return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* search_pkfile ( char *  path,
char *  font,
int  dpi 
)

Definition at line 415 of file psearch.c.

                                                        {
   char *ppe, *pkpath, pe[MAXPATHLEN];
   int del;
   char *pkname;
   struct stat status;

   for (del=0; del <= _margin ; del=del>0?-del:-del+1) {
      pkpath = path;
      while (*pkpath) {
         /* copy next pathelement into pe */
         ppe = pe;
         while (*pkpath != PATHSEP && *pkpath != '\0') {
            if (tilde && *pkpath == '~')
               subtilde(&ppe, &pkpath);
            else
               *ppe++ = *pkpath++;
         }
         *ppe = '\0';
         if (strchr(pe, '%')) {
            if (strstr(pe, "%d") && strstr(pe, "%f")) {
               /* try filename after replacing placeholders */
               substitute(pe, "%b%m%f%d%p",
                _bdpi, _mode, texfont, dpi+del, "pk");
              if (stat(pe, &status) == 0) {
                  pkname = malloc(strlen(pe)+1);
                  if (pkname == NULL) fatal("Out of memory\n");
                  strcpy(pkname, pe);
                  return pkname;
               }
            }
            else /* %f and %d are required! */
               fatal("%s: incomplete path element!\n", pe);
         }
         else {
           sprintf(ppe, "%c%s.%dpk", DIRSEP, texfont, dpi+del);
            if (stat(pe, &status) == 0) {
               pkname = malloc(strlen(pe)+1);
               if (pkname == NULL) fatal("Out of memory\n");
               strcpy(pkname, pe);
               return pkname;
            }
         }
         if (*pkpath == PATHSEP) pkpath++;
      }
   }
   return NULL;
}

Here is the call graph for this function:

void substitute ( char *  str,
char *  patterns,
  ... 
)

Definition at line 298 of file psearch.c.

                                                {
   va_list ap;
   char *p;
   char *svalue; int ivalue;

   /* get arguments ... */
   va_start(ap, patterns);
   for (p = patterns; *p; p++) {
      if (*p != '%') {
        fatal("%s: invalid format\n");
      }
      switch (*++p) {
      case 'b':
         ivalue = va_arg(ap, int);
        replace(str, "%b", &ivalue);
        break;
      case 'd':
         ivalue = va_arg(ap, int);
        replace(str, "%d", &ivalue);
        break;
      case 'F':
         svalue = va_arg(ap, char *);
        replace(str, "%F", svalue);
        break;
      case 'f':
         svalue = va_arg(ap, char *);
        replace(str, "%f", svalue);
        break;
      case 'm':
         svalue = va_arg(ap, char *);
        replace(str, "%m", svalue);
        break;
      case 'p':
         svalue = va_arg(ap, char *);
        replace(str, "%p", svalue);
        break;
      default:
        fatal("%s: invalid letter (%c) in format\n", patterns, *p);
      }
   }
   va_end(ap);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void subtilde ( char **  fn,
char **  path 
)

Variable Documentation