Back to index

tetex-bin  3.0
Defines | Functions | Variables
t1env.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include "../type1/types.h"
#include "parseAFM.h"
#include "../type1/objects.h"
#include "../type1/spaces.h"
#include "../type1/util.h"
#include "../type1/fontfcn.h"
#include "../type1/fontmisc.h"
#include "sysconf.h"
#include "t1types.h"
#include "t1extern.h"
#include "t1env.h"
#include "t1misc.h"
#include "t1base.h"

Go to the source code of this file.

Defines

#define T1ENV_C

Functions

static void qstrncpy (char *destP, const char *srcP, long nochars)
void intT1_SetupDefaultSearchPaths (void)
void intT1_FreeSearchPaths (void)
int intT1_ScanConfigFile (void)
char * intT1_Env_GetCompletePath (char *FileName, char **env_ptr)
int T1_SetFileSearchPath (int type, char *pathname)
char * T1_GetFileSearchPath (int type)
int T1_AddToFileSearchPath (int pathtype, int mode, char *pathname)
int T1_SetFontDataBase (char *filename)
int T1_AddFontDataBase (int mode, char *filename)

Variables

static int pfab_no = -1
static int afm_no = -1
static int enc_no = -1
static int fdb_no = -1
static char path_sep_char = '\0'
static char path_sep_string [2]
static char pathbuf [2048]
static char T1_pfab [] = "."
static char T1_afm [] = "."
static char T1_enc [] = "."
char T1_fdb [] = "FontDataBase"
static const char enc_key [] = "ENCODING"
static const char pfab_key [] = "TYPE1"
static const char afm_key [] = "AFM"
static const char fdb_key [] = "FONTDATABASE"

Define Documentation

#define T1ENV_C

Definition at line 30 of file t1env.c.


Function Documentation

char* intT1_Env_GetCompletePath ( char *  FileName,
char **  env_ptr 
)

Definition at line 471 of file t1env.c.

{
  struct stat filestats;    /* A structure where fileinfo is stored */
  int fnamelen, i, j;
  char *FullPathName;
  char *StrippedName;
  

  if (FileName==NULL)
    return(NULL);
  fnamelen=strlen(FileName);

  /* We check whether absolute or relative pathname is given. If so,
     stat() it and if appropriate, return that string immediately. */
  if ( (FileName[0]==DIRECTORY_SEP_CHAR)
       ||
       ((fnamelen>1) && (FileName[0]=='.') &&
       (FileName[1]==DIRECTORY_SEP_CHAR))
       ||
       ((fnamelen>2) && (FileName[0]=='.') &&
       (FileName[1]=='.') && (FileName[2]==DIRECTORY_SEP_CHAR))
#if defined(MSDOS) | defined(_WIN32) | defined (__EMX__)
       ||
       ((isalpha(FileName[0])) && (FileName[1]==':'))
#endif
#ifdef VMS
       || (strchr(FileName,':') != NULL)
#endif
       )
    {
    /* Check for existence of the path: */
    if (!stat( FileName, &filestats)) {
      if (t1lib_log_file!=NULL) {
       sprintf( err_warn_msg_buf, "stat()'ing complete path %s successful",
               FileName);
       T1_PrintLog( "intT1_Env_GetCompletePath()", err_warn_msg_buf,
                   T1LOG_DEBUG);
      }
      /* Return a copy of the string */
      if ((FullPathName=(char *)malloc( fnamelen + 1))==NULL) {
       T1_errno=T1ERR_ALLOC_MEM;
       return(NULL);
      }
      strcpy( FullPathName, FileName);
      return(FullPathName);
    }
    if (t1lib_log_file!=NULL){
      sprintf( err_warn_msg_buf, "stat()'ing complete path %s failed",
              FileName);
      T1_PrintLog( "intT1_Env_GetCompletePath()", err_warn_msg_buf,
                 T1LOG_DEBUG);
    }
    /* Trying to locate absolute path spec. failed. We try to recover
       by removing the path component and searching in the remaining search
       path entries. This depends on the OS. */
    i=fnamelen-1;
    StrippedName=&(FileName[i]);
    while ( FileName[i]!=DIRECTORY_SEP_CHAR
#if defined(VMS)
           /* What exactly to do for VMS? */
#elif defined(MSDOS) | defined(_WIN32) | defined (__EMX__) | defined(_MSC_VER)
           /* We take a drive specification into account. This means we
              step back until the directory separator or a drive specifier
              appears! */
           && FileName[i]!=':'
#endif
           ) {
      i--;
    }
    i++;
    StrippedName=&FileName[i];
    if (t1lib_log_file!=NULL){
      sprintf( err_warn_msg_buf, "path %s stripped to %s",
              FileName, StrippedName);
      T1_PrintLog( "intT1_Env_GetCompletePath()", err_warn_msg_buf,
                 T1LOG_DEBUG);
    }
  }
  else{ /* We have a relative path name */
    StrippedName=&FileName[0];
  }

  i=0;
  while (env_ptr[i]!=NULL) {
    /* Copy current path element: */
    strcpy( pathbuf, env_ptr[i]);
    /* cut a trailing directory separator */
    j=strlen(pathbuf);
    if (pathbuf[j-1]==DIRECTORY_SEP_CHAR)
      pathbuf[j--]='\0';
    /* Add the directory separator: */
#ifdef VMS
    { char *p= strrchr(pathbuf, DIRECTORY_SEP_CHAR);
      if (p && *(p+1) ==  '\0')
       *p = '\0';
    } 
#endif 
    strcat( pathbuf, DIRECTORY_SEP);
    /* And finally the filename: */
    strcat( pathbuf, StrippedName);
    
    /* Check for existence of the path: */
    if (!stat( pathbuf, &filestats)) {
      if ((FullPathName=(char*)malloc( (j+fnamelen+2)*sizeof(char)))==NULL) {
       T1_errno=T1ERR_ALLOC_MEM;
       return(NULL);
      }
      strcpy( FullPathName, pathbuf);
      if (t1lib_log_file!=NULL){
       sprintf( err_warn_msg_buf, "stat()'ing %s successful",
               FullPathName);
       T1_PrintLog( "intT1_Env_GetCompletePath()", err_warn_msg_buf,
                   T1LOG_DEBUG);
      }
      return(FullPathName);
    }
    if (t1lib_log_file!=NULL){
      sprintf( err_warn_msg_buf, "stat()'ing %s failed",
              pathbuf);
      T1_PrintLog( "intT1_Env_GetCompletePath()", err_warn_msg_buf,
                 T1LOG_DEBUG);
    }
    /* We didn't find the file --> try next path entry */
    i++;
  }
  /* If we get here, no file was found at all, so return a NULL-pointer */
  return(NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 172 of file t1env.c.

{
  int i;
  
  i=0;
  if (T1_PFAB_ptr!=NULL) {
    while (T1_PFAB_ptr[i]!=NULL) {
      free(T1_PFAB_ptr[i]);
      T1_PFAB_ptr[i]=NULL;
    }
    free( T1_PFAB_ptr);
  }
  i=0;
  if (T1_AFM_ptr!=NULL) {
    while (T1_AFM_ptr[i]!=NULL) {
      free(T1_AFM_ptr[i]);
      T1_AFM_ptr[i]=NULL;
    }
    free( T1_AFM_ptr);
  }
  i=0;
  if (T1_ENC_ptr!=NULL) {
    while (T1_ENC_ptr[i]!=NULL) {
      free(T1_ENC_ptr[i]);
      T1_ENC_ptr[i]=NULL;
    }
    free( T1_ENC_ptr);
  }
  i=0;
  if (T1_FDB_ptr!=NULL) {
    while (T1_FDB_ptr[i]!=NULL) {
      free(T1_FDB_ptr[i]);
      T1_FDB_ptr[i]=NULL;
    }
    free( T1_FDB_ptr);
  }
  /* indicate t1lib non-initialized */
  pfab_no=-1;
  afm_no=-1;
  enc_no=-1;
  fdb_no=-1;
  
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 221 of file t1env.c.

{
  
  char *env_str;
  char *linebuf;
  char *usershome;
  char *cnffilepath;
  char *globalcnffilepath;
  static int linecnt;
  char local_path_sep_char;
  int quoted=0;
  int quotecnt=0;
  FILE *cfg_fp;
  int filesize, i, j, k;
  int ignoreline=0;

  char*** destP=NULL;
  int *idestP=NULL;
  char* curr_key=NULL;
  
  /* First, get the string stored in the environment variable: */
  env_str=getenv(ENV_CONF_STRING);
  linecnt=1;

  if (env_str==NULL) {
    /* environment variable not set, try to open default file
       in user's home directory and afterwards global config file */
    if ((usershome=getenv("HOME"))!=NULL) {
      cnffilepath=(char *)malloc((strlen(usershome) +
                              strlen(T1_CONFIGFILENAME) + 2
                              ) * sizeof(char));
      if (cnffilepath==NULL){
       T1_errno=T1ERR_ALLOC_MEM;
       return(-1);
      }
      strcpy( cnffilepath, usershome);
    }
    else {
      cnffilepath=(char *)malloc((strlen(T1_CONFIGFILENAME) + 2
                              ) * sizeof(char));
    }
    strcat( cnffilepath, DIRECTORY_SEP);
    strcat( cnffilepath, T1_CONFIGFILENAME);

    globalcnffilepath=(char*)malloc((strlen(GLOBAL_CONFIG_DIR) +
                                 strlen(GLOBAL_CONFIG_FILE) + 2
                                 ) * sizeof(char));
    if (globalcnffilepath==NULL){
      T1_errno=T1ERR_ALLOC_MEM;
      return(-1);
    }
    strcpy( globalcnffilepath, GLOBAL_CONFIG_DIR);
    strcat( globalcnffilepath, DIRECTORY_SEP);
    strcat( globalcnffilepath, GLOBAL_CONFIG_FILE);
    
    if ((cfg_fp=fopen( cnffilepath, "rb"))==NULL){
      sprintf( err_warn_msg_buf, "Could not open configfile %s",
              cnffilepath);
      T1_PrintLog( "ScanConfigFile()", err_warn_msg_buf, T1LOG_STATISTIC);
      /* Try global config file */
      if ((cfg_fp=fopen( globalcnffilepath, "rb"))==NULL){
       sprintf( err_warn_msg_buf, "Could not open global configfile %s",
               globalcnffilepath);
       T1_PrintLog( "ScanConfigFile()", err_warn_msg_buf, T1LOG_WARNING);
      }
      else{
       sprintf( err_warn_msg_buf, "Using %s as Configfile (global)",
               cnffilepath);
       T1_PrintLog( "ScanConfigFile()", err_warn_msg_buf, T1LOG_STATISTIC);
      }
    }
    else{
      sprintf( err_warn_msg_buf, "Using %s as Configfile (user's)",
              cnffilepath);
      T1_PrintLog( "ScanConfigFile()", err_warn_msg_buf, T1LOG_STATISTIC);
    }
    free( cnffilepath);
    free( globalcnffilepath);
    if (cfg_fp==NULL){
      T1_PrintLog( "ScanConfigFile()",
                 "Neither user's nor global Configfile has been found",
                 T1LOG_WARNING);
      return(0);
    }
  }
  else {
    /* open specified file for reading the configuration */
    if ((cfg_fp=fopen(env_str,"rb"))==NULL){
      T1_PrintLog( "ScanConfigFile()",
                 "Configfile as specified by Environment has not been found",
                 T1LOG_WARNING);
      return(0);  /* specified file could not be openend
                   => no config paths read */
    }
    else {
      sprintf( err_warn_msg_buf, "Using %s as Configfile (environment)",
              env_str);
      T1_PrintLog( "ScanConfigFile()", err_warn_msg_buf, T1LOG_STATISTIC);
    }
  }
  

  /* cfg_fp points now to a valid config file */
  /* Get the file size */
  fseek( cfg_fp, 0, SEEK_END);
  filesize=ftell(cfg_fp);
  /* Reset fileposition to start */
  fseek( cfg_fp, 0, SEEK_SET);
  
  if ((linebuf=(char *)calloc( filesize+1,
                            sizeof(char)))==NULL){
    T1_errno=T1ERR_ALLOC_MEM;
    return(-1);
  }
  
  fread((char *)linebuf, sizeof(char), filesize, cfg_fp);
  fclose(cfg_fp);
  
  i=0;

  /* this might be overwritten on a per file basis */
  local_path_sep_char=path_sep_char;

  while(i<filesize) {
    ignoreline=0;
    j=i;     /* Save index of beginning of line */
    while ((linebuf[i]!='=') && (linebuf[i]!='\n') && (i<filesize)) {
      i++;
    } 
    if (i==filesize) {
      free( linebuf);
      return(i);
    }
    
    if (strncmp( enc_key, &linebuf[j], 8)==0) {
      /* setup target */
      destP=&T1_ENC_ptr;
      idestP=&enc_no;
      curr_key=(char*)enc_key;
    }
    else if (strncmp( "TYPE1", &linebuf[j], 5)==0) {
      /* setup target */
      destP=&T1_PFAB_ptr;
      idestP=&pfab_no;
      curr_key=(char*)pfab_key;
    }
    else if (strncmp( afm_key, &linebuf[j], 3)==0) {
      /* setup target */
      destP=&T1_AFM_ptr;
      idestP=&afm_no;
      curr_key=(char*)afm_key;
    }
    else if (strncmp( fdb_key, &linebuf[j], 12)==0) {
      /* setup target */
      destP=&T1_FDB_ptr;
      idestP=&fdb_no;
      curr_key=(char*)fdb_key;
    }
    else {
      ignoreline=1;
      T1_PrintLog( "ScanConfigFile()", "Ignoring line %d",
                 T1LOG_DEBUG, linecnt);
    }

    /* If appropriate, scan this line. */
    if (ignoreline==0) { 
      /* Check for an explicitly assigned value */
      if (*idestP==0) { /* default paths are currently setup, get rid of them */
       free((*destP)[0]);
      }
      else { /* append to existing paths */
       T1_PrintLog( "ScanConfigFile()",
                   "Appending to existing %s search path",
                   T1LOG_DEBUG, curr_key);
      }
      while ( (!isspace((int)linebuf[i])) && (i<filesize) ) {
       k=++i;      /* index to current path element */
       (*idestP)++;
       quotecnt=0;
       if (linebuf[i]=='"') { /* We have a quoted string */
         quoted=1;
         k=++i;
         while ( 1) {
           if ( linebuf[i]=='"' ) {    /* we find a quote-char */ 
             if ( linebuf[i-1]!='\\' ) 
              break;                     /* not escaped --> end of path specification */
             else
              quotecnt++;
           }                           /* some other char */
           if (linebuf[i]=='\n') { /* a newline in a quoted string? Perhabs, quotes do not match! */
             T1_PrintLog( "ScanConfigFile()",
                        "Newline in quoted %s-string in line %d, column %d, of config file! Closing quote missing?", 
                        T1LOG_WARNING, curr_key, linecnt, i-j+1);
             j=i+1;                /* resynchronize linecount */
             linecnt++;           
           }
           if (i<filesize) {            /* filesize not exceeded? */
             i++;
           }
           else {                       /* issue error msg because end of quotation is missing */
             T1_PrintLog( "ScanConfigFile()", "Unterminated quoted string in config file",
                        T1LOG_ERROR);
             return -1;
           }
         }
       }
       else {
         quoted=0;
         while ( (linebuf[i]!=local_path_sep_char) && (!isspace((int)linebuf[i])) && (i<filesize) )
           i++;
       }
       if (((*destP)=(char**)realloc( (*destP), ((*idestP)+1)*sizeof(char*)))==NULL) {
         T1_errno=T1ERR_ALLOC_MEM;
         return(-1);
       }
       if (((*destP)[(*idestP)-1]=(char*)malloc((i-k-quotecnt+1)*sizeof(char)))==NULL) {
         T1_errno=T1ERR_ALLOC_MEM;
         return(-1);
       }
       if (quoted==0) {
         strncpy( (*destP)[*idestP-1], &(linebuf[k]), i-k);
         (*destP)[(*idestP)-1][i-k]='\0';
       }
       else {
         qstrncpy( (*destP)[(*idestP)-1], &(linebuf[k]), i-k);
         (*destP)[(*idestP)-1][i-k-quotecnt]='\0';
         i++;         /* step over closing quote */
       }
       (*destP)[(*idestP)]=NULL;     /* indicate end of string list */
      }
    }

    /* skip remaining of line or file */
    while ((linebuf[i]!='\n')&&(i<filesize))
      i++;
    i++;
    linecnt++;
  }
  /* file should now be read in */
  free( linebuf);
  
  return(i);
  
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 132 of file t1env.c.

{

  path_sep_char=PATH_SEP_CHAR;
  sprintf( path_sep_string, "%c", path_sep_char);
  
  /* We set the number of stored path elements 0 so that we can distiguish
     between explicitly setup paths and default paths in intT1_ScanConfigFile(). */
  if (pfab_no==-1) {
    T1_PFAB_ptr=(char**) calloc( 2, sizeof(char*));
    T1_PFAB_ptr[0]=(char*)malloc(strlen(T1_pfab)+1);
    strcpy(T1_PFAB_ptr[0],T1_pfab);
    pfab_no=0;
  }
  
  if (afm_no==-1) {
    T1_AFM_ptr=(char**) calloc( 2, sizeof(char*));
    T1_AFM_ptr[0]=(char*)malloc(strlen(T1_afm)+1);
    strcpy(T1_AFM_ptr[0],T1_afm);
    afm_no=0;
  }
  
  if (enc_no==-1) {
    T1_ENC_ptr=(char**) calloc( 2, sizeof(char*));
    T1_ENC_ptr[0]=(char*)malloc(strlen(T1_enc)+1);
    strcpy(T1_ENC_ptr[0],T1_enc);
    enc_no=0;
  }

  if (fdb_no==-1) {
    T1_FDB_ptr=(char**) calloc( 2, sizeof(char*));
    T1_FDB_ptr[0]=(char*)malloc(strlen(T1_fdb)+1);
    strcpy(T1_FDB_ptr[0],T1_fdb);
    fdb_no=0;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void qstrncpy ( char *  destP,
const char *  srcP,
long  nochars 
) [static]

Definition at line 107 of file t1env.c.

{
  long i;
  long j;
  
  i=0;  /* dest-index */
  j=0;  /* src-index */
  
  while (j<nochars) {
    if (srcP[j]=='\\') {
      if (srcP[j+1]=='"') { 
       j++;                /* escaped quotation character --> omit escape char. */
      }
    }
    else {                  /* normal character */
      destP[i++]=srcP[j++];
    }
  }
}

Here is the caller graph for this function:

int T1_AddFontDataBase ( int  mode,
char *  filename 
)

Definition at line 982 of file t1env.c.

{
  int i;
  int pathlen;
  int result=0;
  char* newpath;
  
  
  if (filename==NULL) {
    T1_errno=T1ERR_INVALID_PARAMETER;
    return(-1);
  }
  
  pathlen=strlen(filename);
  
  /* Allocate memory for string */
  if ((newpath=(char*)malloc( (pathlen+1)*sizeof(char)))==NULL)  {
    T1_errno=T1ERR_ALLOC_MEM;
    return(-1);
  }
  strcpy( newpath, filename);
  /* Check for and handle the existing path configuration */
  if (fdb_no==0) {   /* defauls setup, free the path */
    free( T1_FDB_ptr[0]);
  }
  if (fdb_no==-1) {  /* not initialized! */
    fdb_no=0;
    T1_FDB_ptr=NULL; /* realloc() will do the malloc()! */
  }
  
  if ((T1_FDB_ptr=(char**)realloc( T1_FDB_ptr, (++fdb_no+1)*sizeof(char*)))==NULL) {
    T1_errno=T1ERR_ALLOC_MEM;
    return(-1);
  }
  /* Insert the new database. If t1lib is already initialzed, the database can only
     be appended. Otherwise. prepending is also possible.*/
  if ((mode & T1_PREPEND_PATH) && (T1_CheckForInit()!=0) ) { /* prepend */
    i=fdb_no-2;
    while (i>=0) {
      T1_FDB_ptr[i+1]=T1_FDB_ptr[i];
      i--;
    }
    T1_FDB_ptr[0]=newpath;
    result=0;
  }
  else { /* append */
    T1_FDB_ptr[fdb_no-1]=newpath;
    if (T1_CheckForInit()==0) {
      if ((result=intT1_scanFontDBase(T1_FDB_ptr[fdb_no-1]))==-1) {
       T1_PrintLog( "T1_AddFontDataBase()", "Fatal error scanning Font Database File %s (T1_errno=%d)",
                   T1LOG_WARNING, T1_FDB_ptr[fdb_no-1], T1_errno);
      }
      if (result>-1)
       pFontBase->no_fonts+=result;
      result=pFontBase->no_fonts;
    }
  }
  T1_FDB_ptr[fdb_no]=NULL;
  return result;
  
}

Here is the call graph for this function:

int T1_AddToFileSearchPath ( int  pathtype,
int  mode,
char *  pathname 
)

Definition at line 768 of file t1env.c.

{
  int i;
  int pathlen;
  char* newpath = NULL;
  int nofonts;
  
  
  if (pathname==NULL)
    return(-1);

  nofonts=T1_GetNoFonts();
  
  pathlen=strlen(pathname);
  
  if (pathtype & T1_PFAB_PATH){
    /* Allocate meory for string */
    if ((newpath=(char*)malloc( (pathlen+1)*sizeof(char)))==NULL)  {
      T1_errno=T1ERR_ALLOC_MEM;
      return(-1);
    }
    /* Check for and handle the existing path configuration */
    if (pfab_no==0) {   /* do not free the default path but establish it
                        as a regularly setup path, if database not empty! */
      if (nofonts>0) {
       pfab_no++;
      }
      else {
       free( T1_AFM_ptr[0]);
      }
    }
    if (pfab_no==-1) {  /* not initialized! */
      pfab_no=0;
      T1_PFAB_ptr=NULL; /* realloc() will do the malloc()! */
    }
    if ((T1_PFAB_ptr=(char**)realloc( T1_PFAB_ptr, (++pfab_no+1)*sizeof(char*)))==NULL) {
      T1_errno=T1ERR_ALLOC_MEM;
      return(-1);
    }
    /* Insert the new path element: */
    if (mode & T1_PREPEND_PATH){ /* prepend */
      i=pfab_no-2;
      while (i>=0) {
       T1_PFAB_ptr[i+1]=T1_PFAB_ptr[i];
       i--;
      }
      T1_PFAB_ptr[0]=newpath;
    }
    else{ /* append */
      T1_PFAB_ptr[pfab_no-1]=newpath;
    }
    T1_PFAB_ptr[pfab_no]=NULL;
  }
  if (pathtype & T1_AFM_PATH){
    /* Allocate meory for string */
    if ((newpath=(char*)malloc( (pathlen+1)*sizeof(char)))==NULL)  {
      T1_errno=T1ERR_ALLOC_MEM;
      return(-1);
    }
    /* Check for and handle the existing path configuration */
    if (afm_no==0) {   /* do not free the default path but establish it
                       as a regularly setup path, if database not empty! */
      if (nofonts>0) {
       afm_no++;
      }
      else {
       free( T1_AFM_ptr[0]);
      }
    }
    if (afm_no==-1) {  /* not initialized! */
      afm_no=0;
      T1_AFM_ptr=NULL; /* realloc() will do the malloc()! */
    }
    if ((T1_AFM_ptr=(char**)realloc( T1_AFM_ptr, (++afm_no+1)*sizeof(char*)))==NULL) {
      T1_errno=T1ERR_ALLOC_MEM;
      return(-1);
    }
    /* Insert the new path element */
    if (mode & T1_PREPEND_PATH){ /* prepend */
      i=afm_no-2;
      while (i>=0) {
       T1_AFM_ptr[i+1]=T1_AFM_ptr[i];
       i--;
      }
      T1_AFM_ptr[0]=newpath;
    }
    else{ /* append */
      T1_AFM_ptr[afm_no-1]=newpath;
    }
    T1_AFM_ptr[afm_no]=NULL;
  }
  if (pathtype & T1_ENC_PATH){
    /* Allocate meory for string */
    if ((newpath=(char*)malloc( (pathlen+1)*sizeof(char)))==NULL)  {
      T1_errno=T1ERR_ALLOC_MEM;
      return(-1);
    }
    /* Check for and handle the existing path configuration */
    if (enc_no==0) {    /* do not free the default path but establish it
                        as a regularly setup path, if database not empty! */
      if (nofonts>0) {
       enc_no++;
      }
      else {
       free( T1_ENC_ptr[0]);
      }
    }
    if (enc_no==-1) {  /* not initialized! */
      enc_no=0;
      T1_ENC_ptr=NULL; /* realloc() will do the malloc()! */
    }
    if ((T1_ENC_ptr=(char**)realloc( T1_ENC_ptr, (++enc_no+1)*sizeof(char*)))==NULL) {
      T1_errno=T1ERR_ALLOC_MEM;
      return(-1);
    }
    /* Insert the new path element: */
    if (mode & T1_PREPEND_PATH){ /* prepend */
      i=enc_no-2;
      while (i>=0) {
       T1_ENC_ptr[i+1]=T1_ENC_ptr[i];
       i--;
      }
      T1_ENC_ptr[0]=newpath;
    }
    else{ /* append */
      T1_ENC_ptr[enc_no-1]=newpath;
    }
    T1_ENC_ptr[enc_no]=NULL;
  }
  
  /* Copy new path to where it belongs ... */
  if (newpath)
    strcpy(newpath, pathname);
  
  return(0);
  
}

Here is the call graph for this function:

char* T1_GetFileSearchPath ( int  type)

Definition at line 714 of file t1env.c.

{
  static char *out_ptr;
  int i;
  int pathlen;
  char **src_ptr=NULL;
  

  if (out_ptr!=NULL)
    free( out_ptr);
  out_ptr=NULL;
  
  if (type & T1_PFAB_PATH) {
    src_ptr=T1_PFAB_ptr;
  }
  else  if (type & T1_AFM_PATH) {
    src_ptr=T1_AFM_ptr;
  }
  else if (type & T1_ENC_PATH) {
    src_ptr=T1_ENC_ptr;
  }
  else if (type & T1_FDB_PATH) {
    src_ptr=T1_FDB_ptr;
  }
  
  
  i=0;
  pathlen=0;
  while (src_ptr[i]!=NULL) {
    pathlen +=strlen( src_ptr[i++]);
    pathlen+=1; /* path separator */
  }
  if ((out_ptr=(char *)malloc(pathlen+1))==NULL) {
    T1_errno=T1ERR_ALLOC_MEM;
    return( NULL);
  }
  strcpy( out_ptr, src_ptr[0]);
  i=1;
  while (src_ptr[i]!=NULL) {
    strcat( out_ptr, path_sep_string);
    strcat( out_ptr, src_ptr[i++]);
  }
  
  return( out_ptr);

}

Here is the call graph for this function:

Here is the caller graph for this function:

int T1_SetFileSearchPath ( int  type,
char *  pathname 
)

Definition at line 609 of file t1env.c.

{

  int i;
  int pathlen;
  
  
  if (pathname==NULL){
    T1_errno=T1ERR_INVALID_PARAMETER;
    return(-1);
  }

  /* We do not allow to change the searchpath if the database already
     contains one or more entries. */
  if (T1_GetNoFonts()>0){
    sprintf( err_warn_msg_buf, "Path %s not set, database is not empty",
            pathname);
    T1_PrintLog( "T1_SetFileSearchPath()", err_warn_msg_buf,
               T1LOG_STATISTIC);
    T1_errno=T1ERR_OP_NOT_PERMITTED;
    return(-1);
  }

  pathlen=strlen(pathname)+1;
  /* Throw away a possibly existing path */
  if (type & T1_PFAB_PATH){
    if (pfab_no==-1) {
      T1_PFAB_ptr=NULL; /* realloc() will do a malloc() */
    }
    else {
      /* throw away current paths */
      i=0;
      while (T1_PFAB_ptr[i]!=NULL) {
       free (T1_PFAB_ptr[i++]);
      }
    }
    if ((T1_PFAB_ptr=(char**)realloc( T1_PFAB_ptr, 2*sizeof(char*)))==NULL) {
      T1_errno=T1ERR_ALLOC_MEM;
      return(-1);
    }
    if ((T1_PFAB_ptr[0]=(char*)malloc(pathlen*sizeof(char)))==NULL) {
      T1_errno=T1ERR_ALLOC_MEM;
      return(-1);
    }
    strcpy( T1_PFAB_ptr[0], pathname);
    T1_PFAB_ptr[1]=NULL;
    pfab_no=1;
  }
  if (type & T1_AFM_PATH){
    if (afm_no==-1) {
      T1_AFM_ptr=NULL; /* realloc() will do a malloc() */
    }
    else {
      /* throw away current paths */
      i=0;
      while (T1_AFM_ptr[i]!=NULL) {
       free (T1_AFM_ptr[i++]);
      }
    }
    if ((T1_AFM_ptr=(char**)realloc( T1_AFM_ptr, 2*sizeof(char*)))==NULL) {
      T1_errno=T1ERR_ALLOC_MEM;
      return(-1);
    }
    if ((T1_AFM_ptr[0]=(char*)malloc(pathlen*sizeof(char)))==NULL) {
      T1_errno=T1ERR_ALLOC_MEM;
      return(-1);
    }
    strcpy( T1_AFM_ptr[0], pathname);
    T1_AFM_ptr[1]=NULL;
    afm_no=1;
  }
  if (type & T1_ENC_PATH){
    if (enc_no==-1) {
      T1_ENC_ptr=NULL; /* realloc() will do a malloc() */
    }
    else {
      /* throw away current paths */
      i=0;
      while (T1_ENC_ptr[i]!=NULL) {
       free (T1_ENC_ptr[i++]);
      }
    }
    if ((T1_ENC_ptr=(char**)realloc( T1_ENC_ptr, 2*sizeof(char*)))==NULL) {
      T1_errno=T1ERR_ALLOC_MEM;
      return(-1);
    }
    if ((T1_ENC_ptr[0]=(char*)malloc(pathlen*sizeof(char)))==NULL) {
      T1_errno=T1ERR_ALLOC_MEM;
      return(-1);
    }
    strcpy( T1_ENC_ptr[0], pathname);
    T1_ENC_ptr[1]=NULL;
    enc_no=1;
  }
  
  return(0);
  
}

Here is the call graph for this function:

int T1_SetFontDataBase ( char *  filename)

Definition at line 912 of file t1env.c.

{
  int pathlen;
  int i;
  int result=0;
  
  
  /* chekc filename */
  if (filename==NULL) {
    T1_errno=T1ERR_INVALID_PARAMETER;
    return -1;
  }

  /* this function must be called before any font is in the database, that is, usually,
     before initialization! */
  if ( pFontBase!=NULL && pFontBase->no_fonts>0) {
    T1_errno=T1ERR_OP_NOT_PERMITTED;
    return -1;
  }

  
  pathlen=strlen(filename)+1;
  /* Throw away a possibly existing font database-statement */
  if (fdb_no==-1) {  
    T1_FDB_ptr=NULL; /* realloc() will do a malloc() */
  }
  else { 
    /* throw away current paths */
    i=0;
    while (T1_FDB_ptr[i]!=NULL) {
      free (T1_FDB_ptr[i++]);
    }
  }

  if ((T1_FDB_ptr=(char**)realloc( T1_FDB_ptr, 2*sizeof(char*)))==NULL) {
    T1_errno=T1ERR_ALLOC_MEM;
    return -1;
  }
  
  if ((T1_FDB_ptr[0]=(char*)malloc(pathlen*sizeof(char)))==NULL) {
    T1_errno=T1ERR_ALLOC_MEM;
    return -1;
  }
  strcpy( T1_FDB_ptr[0], filename);
  T1_FDB_ptr[1]=NULL;
  fdb_no=1;

  /* Load database immediately if t1lib already is initailzed */
  if (T1_CheckForInit()==0) {
    if ((result=intT1_scanFontDBase(T1_FDB_ptr[0]))==-1) {
      T1_PrintLog( "T1_AddFontDataBase()", "Fatal error scanning Font Database File %s (T1_errno=%d)",
                 T1LOG_WARNING, T1_FDB_ptr[0], T1_errno);
    }
    if (result>-1)
      pFontBase->no_fonts+=result;
    result=pFontBase->no_fonts;
  }
  return result;
  
}

Here is the call graph for this function:


Variable Documentation

const char afm_key[] = "AFM" [static]

Definition at line 99 of file t1env.c.

int afm_no = -1 [static]

Definition at line 74 of file t1env.c.

const char enc_key[] = "ENCODING" [static]

Definition at line 97 of file t1env.c.

int enc_no = -1 [static]

Definition at line 75 of file t1env.c.

const char fdb_key[] = "FONTDATABASE" [static]

Definition at line 100 of file t1env.c.

int fdb_no = -1 [static]

Definition at line 76 of file t1env.c.

char path_sep_char = '\0' [static]

Definition at line 78 of file t1env.c.

char path_sep_string[2] [static]

Definition at line 79 of file t1env.c.

char pathbuf[2048] [static]

Definition at line 81 of file t1env.c.

const char pfab_key[] = "TYPE1" [static]

Definition at line 98 of file t1env.c.

int pfab_no = -1 [static]

Definition at line 73 of file t1env.c.

char T1_afm[] = "." [static]

Definition at line 86 of file t1env.c.

char T1_enc[] = "." [static]

Definition at line 87 of file t1env.c.

char T1_fdb[] = "FontDataBase"

Definition at line 93 of file t1env.c.

char T1_pfab[] = "." [static]

Definition at line 85 of file t1env.c.