home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fonts 1
/
freshfonts1.bin
/
bbs
/
programs
/
amiga
/
pastex13.lha
/
DVIPS
/
dvips5519.lha
/
dvips
/
search.c.bak
< prev
next >
Wrap
Text File
|
1993-09-04
|
11KB
|
383 lines
/*
* The search routine takes a directory list, separated by PATHSEP, and
* tries to open a file. Null directory components indicate current
* directory. if the file SUBDIR exists and the file is a font file,
* it checks for the file in a subdirectory named the same as the font name.
* Returns the open file descriptor if ok, else NULL.
*/
#include "dvips.h" /* The copyright notice in that file is included too! */
#include <ctype.h>
#if defined(SYSV) || defined(VMS) || defined(__THINK__) || defined(MSDOS) || defined(AMIGA)
#define MAXPATHLEN (256)
#else
#include <sys/param.h> /* for MAXPATHLEN */
#endif
#ifndef MSDOS
#ifndef VMS
#ifndef MVSXA
#ifndef VMCMS /* IBM: VM/CMS */
#ifndef __THINK__
#ifndef AMIGA
#include <pwd.h>
#endif
#endif
#endif
#endif /* IBM: VM/CMS */
#endif
#endif
/*
*
* We hope MAXPATHLEN is enough -- only rudimentary checking is done!
*/
#ifdef DEBUG
extern integer debug_flag;
#endif /* DEBUG */
extern char *mfmode ;
extern int actualdpi ;
char realnameoffile[MAXPATHLEN] ;
FILE *
search(path, file, mode)
char *path, *file, *mode ;
{
extern char *getenv(), *newstring() ;
register char *nam ; /* index into fname */
register FILE *fd ; /* file desc of file */
char fname[MAXPATHLEN] ; /* to store file name */
static char *home = 0 ; /* home is where the heart is */
#ifdef MVSXA
char fname_safe[256];
register int i, firstext, lastext, lastchar;
#endif
#ifdef VMCMS /* IBM: VM/CMS - we don't have paths or dirsep's but we strip off
filename if there is a Unix path dirsep */
register char *lastdirsep ;
lastdirsep = strrchr(file, '/') ;
if ( NULL != lastdirsep ) file = lastdirsep + 1 ;
if ((fd=fopen(file,mode)) != NULL) {
return(fd) ;
} else {
return(NULL) ;
}
#else
if (*file == DIRSEP) { /* if full path name */
if ((fd=fopen(file,mode)) != NULL) {
strcpy(realnameoffile, file) ;
return(fd) ;
} else
return(NULL) ;
}
#endif /* IBM: VM/CMS */
#if defined MSDOS || defined OS2
if ( isalpha(file[0]) && file[1]==':' ) { /* if full path name */
if ((fd=fopen(file,mode)) != NULL)
return(fd) ;
else
return(NULL) ;
}
#endif
#if defined AMIGA
if (strchr(file, ':')) { /* if full path name */
if ((fd=fopen(file,mode)) != NULL)
return(fd) ;
else
return(NULL) ;
}
#endif
do {
/* copy the current directory into fname */
nam = fname;
/* copy till PATHSEP */
if (*path == '~') {
char *p = nam ;
path++ ;
while (*path && *path != PATHSEP && *path != DIRSEP)
*p++ = *path++ ;
*p = 0 ;
if (*nam == 0) {
if (home == 0) {
if (0 != (home = getenv("HOME")))
home = newstring(home) ;
else
home = "." ;
}
strcpy(fname, home) ;
} else {
#if defined MSDOS || defined OS2
error("! ~username in path???") ;
#else
#ifdef VMS
error("! ~username in path???") ;
#else
#ifdef VMCMS /* IBM: VM/CMS */
error("! ~username in path???") ;
#else
#ifdef MVSXA /* IBM: MVS/XA */
error("! ~username in path???") ;
#else
#ifdef __THINK__
error("! ~username in path???") ;
#else
#ifdef AMIGA
error("! ~username in path???") ;
#else
struct passwd *pw = getpwnam(fname) ;
if (pw)
strcpy(fname, pw->pw_dir) ;
else
error("no such user") ;
#endif
#endif
#endif /* IBM: VM/CMS */
#endif
#endif
#endif
}
nam = fname + strlen(fname) ;
}
while (*path != PATHSEP && *path) *nam++ = *path++;
*nam = 0 ;
#ifndef VMS
#ifndef __THINK__
if (nam == fname) *nam++ = '.'; /* null component is current dir */
if (*file != '\0') {
if ((nam != fname) && *(nam-1) != DIRSEP) /* GNW 1992.07.09 */
*nam++ = DIRSEP; /* add separator */
(void)strcpy(nam,file); /* tack the file on */
}
else
*nam = '\0' ;
#else
(void)strcpy(nam,file); /* tack the file on */
#endif
#else
(void)strcpy(nam,file); /* tack the file on */
#endif
#ifdef MVSXA
nam = fname;
if (strchr(nam,'=') != NULL) {
(void) strcpy(fname_safe,fname); /* save fname */
firstext = strchr(nam, '=') - nam + 2;
lastext = strrchr(nam, '.') - nam + 1;
lastchar = strlen(nam) - 1;
(void) strcpy(fname,"dd:"); /* initialize fname */
nam=&fname[3];
for (i=lastext; i<=lastchar; i++) *nam++ = fname_safe[i] ;
*nam++ = '(' ;
for (i=firstext; i<lastext-1; i++) *nam++ = fname_safe[i] ;
*nam++ = ')' ;
*nam++ = 0 ;
}
else {
if (fname[0] == '/') {
fname[0] = '\'';
strcat(&fname[strlen(fname)],"\'");
}
if (fname[0] == '.') fname[0] = ' ';
if (fname[1] == '.') fname[1] = ' ';
}
#endif
#ifdef AMIGA
if (fname[0] == '.' && fname[1] == DIRSEP) { /* special case "./" */
int i;
for (i=2; i<strlen(fname)+1; i++) {
fname[i-2] = fname[i]; /* copy with the '\0' */
}
}
#endif
/* belated check -- bah! */
if ((nam - fname) + strlen(file) + 1 > MAXPATHLEN)
error("! overran allocated storage in search()");
#ifdef DEBUG
if (dd(D_PATHS))
(void)fprintf(stderr,"Trying to open %s\n", fname) ;
#endif
if ((fd=fopen(fname,mode)) != NULL) {
strcpy(realnameoffile, fname) ;
return(fd);
}
/* skip over PATHSEP and try again */
} while (*(path++));
return(NULL);
} /* end search */
FILE *
pksearch(path, file, mode, n, dpi, vdpi)
char *path, *file, *mode ;
char *n ;
halfword dpi, vdpi ;
{
extern char *getenv(), *newstring() ;
register char *nam ; /* index into fname */
register FILE *fd ; /* file desc of file */
char fname[MAXPATHLEN] ; /* to store file name */
static char *home = 0 ; /* home is where the heart is */
int sub ;
if (*file == DIRSEP) { /* if full path name */
if ((fd=fopen(file,mode)) != NULL)
return(fd) ;
else
return(NULL) ;
}
#if defined MSDOS || defined OS2
if ( isalpha(file[0]) && file[1]==':' ) { /* if full path name */
if ((fd=fopen(file,mode)) != NULL)
return(fd) ;
else
return(NULL) ;
}
#endif
do {
/* copy the current directory into fname */
nam = fname;
sub = 0 ;
/* copy till PATHSEP */
if (*path == '~') {
char *p = nam ;
path++ ;
while (*path && *path != PATHSEP && *path != DIRSEP)
*p++ = *path++ ;
*p = 0 ;
if (*nam == 0) {
if (home == 0) {
if (0 != (home = getenv("HOME")))
home = newstring(home) ;
else
home = "." ;
}
strcpy(fname, home) ;
} else {
#if defined MSDOS || defined OS2
error("! ~username in path???") ;
#else
#ifdef VMS
error("! ~username in path???") ;
#else
#ifdef VMCMS /* IBM: VM/CMS */
error("! ~username in path???") ;
#else
#ifdef MVSXA /* IBM: MVS/XA */
error("! ~username in path???") ;
#else
#ifdef __THINK__
error("! ~username in path???") ;
#else
struct passwd *pw = getpwnam(fname) ;
if (pw)
strcpy(fname, pw->pw_dir) ;
else
error("no such user") ;
#endif
#endif /* IBM: VM/CMS */
#endif
#endif
#endif
}
nam = fname + strlen(fname) ;
}
/* copy till PATHSEP */
while (*path != PATHSEP && *path) {
if (*path == '%') {
sub = 1 ;
path++ ;
switch(*path) {
case 'b': sprintf(nam, "%d", actualdpi) ; break ;
case 'd