home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fonts 1
/
freshfonts1.bin
/
bbs
/
programs
/
amiga
/
pastex13.lha
/
DVIPS
/
dvips5519.lha
/
dvips
/
resident.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-26
|
25KB
|
936 lines
/* For use with emTeX set FONTPATH to "TEXTFM"
*/
#ifndef FONTPATH
#define FONTPATH "TEXFONTS"
#endif
/*
* This code reads in and handles the defaults for the program from the
* file config.sw. This entire file is a bit kludgy, sorry.
*/
#include "dvips.h" /* The copyright notice in that file is included too! */
#include "paths.h"
/*
* This is the structure definition for resident fonts. We use
* a small and simple hash table to handle these. We don't need
* a big hash table.
*/
struct resfont *reshash[RESHASHPRIME] ;
/*
* These are the external routines we use.
*/
extern void error() ;
extern integer scalewidth() ;
extern int tfmload() ;
extern FILE *search() ;
extern shalfword pkbyte() ;
extern integer pkquad() ;
extern integer pktrio() ;
extern Boolean pkopen() ;
extern char *getenv() ;
extern char *newstring() ;
extern int add_header() ;
extern int add_name() ;
extern char *get_name() ;
extern int system() ;
extern void handlepapersize() ;
extern void checkstrings() ;
void getpsinfo() ;
extern void *revlist() ;
/*
* These are the external variables we use.
*/
#ifdef DEBUG
extern integer debug_flag;
#endif /* DEBUG */
extern integer pagecopies ;
extern int overridemag ;
extern long bytesleft ;
extern quarterword *raster ;
extern FILE *pkfile ;
extern char *oname ;
extern integer swmem, fontmem ;
extern char *tfmpath, *pictpath ;
extern char *pkpath ;
extern char *vfpath ;
extern char *figpath ;
extern char *configpath ;
extern Boolean noenv ;
#ifdef SEARCH_SUBDIRECTORIES
extern char *fontsubdirpath ;
#endif
#ifdef FONTLIB
extern char *flipath, *fliname ;
#endif
extern char *headerpath ;
extern char *paperfmt ;
extern char *nextstring ;
extern char *maxstring ;
extern char *warningmsg ;
extern Boolean disablecomments ;
extern Boolean compressed ;
extern int quiet ;
extern int filter ;
extern Boolean reverse ;
extern Boolean usesPSfonts ;
extern Boolean nosmallchars ;
extern Boolean removecomments ;
extern Boolean safetyenclose ;
extern Boolean dopprescan ;
extern integer maxsecsize ;
extern integer mag ;
extern Boolean sepfiles ;
extern int actualdpi ;
extern int vactualdpi ;
extern int maxdrift ;
extern int vmaxdrift ;
extern char *printer ;
extern char *mfmode ;
extern Boolean sendcontrolD ;
extern int lastresortsizes[] ;
extern integer hoff, voff ;
extern struct papsiz *papsizes ;
/*
* To maintain a list of document fonts, we use the following
* pointer.
*/
struct header_list *ps_fonts_used ;
/*
* Our hash routine.
*/
int
hash(s)
char *s ;
{
int h = 12 ;
while (*s != 0)
h = (h + h + *s++) % RESHASHPRIME ;
return(h) ;
}
/*
* Reverse the hash chains.
*/
void
revpslists() {
register int i ;
for (i=0; i<RESHASHPRIME; i++)
reshash[i] = (struct resfont *)revlist(reshash[i]) ;
}
/*
* cleanres() marks all resident fonts as not being yet sent.
*/
void
cleanres() {
register int i ;
register struct resfont *p ;
for (i=0; i<RESHASHPRIME; i++)
for (p=reshash[i]; p; p=p->next)
p->sent = 0 ;
}
/*
* The routine that looks up a font name.
*/
struct resfont *
lookup(name)
char *name ;
{
struct resfont *p ;
for (p=reshash[hash(name)]; p!=NULL; p=p->next)
if (strcmp(p->Keyname, name)==0)
return(p) ;
return(NULL) ;
}
/*
* This routine adds an entry.
*/
void
add_entry(TeXname, PSname, specinfo, downloadinfo)
char *TeXname, *PSname, *specinfo, *downloadinfo ;
{
struct resfont *p ;
int h ;
if (PSname == NULL)
PSname = TeXname ;
p = (struct resfont *)mymalloc((integer)sizeof(struct resfont)) ;
p->Keyname = TeXname ;
p->PSname = PSname ;
p->TeXname = TeXname ;
p->specialinstructions = specinfo ;
if (downloadinfo && *downloadinfo)
p->downloadheader = downloadinfo ;
else
p->downloadheader = 0 ;
h = hash(TeXname) ;
p->next = reshash[h] ;
p->sent = 0 ;
reshash[h] = p ;
}
/*
* Now our residentfont routine. Returns the number of characters in
* this font, based on the TFM file.
*/
extern char *infont ;
int
residentfont(curfnt)
register fontdesctype *curfnt ;
{
register shalfword i ;
struct resfont *p ;
/*
* First we determine if we can find this font in the resident list.
*/
if (*curfnt->area)
return 0 ; /* resident fonts never have a nonstandard font area */
if ((p=lookup(curfnt->name))==NULL)
return 0 ;
/*
* We clear out some pointers:
*/
#ifdef DEBUG
if (dd(D_FONTS))
(void)fprintf(stderr,"Font %s <%s> is resident.\n",
curfnt->name, p->PSname) ;
#endif /* DEBUG */
curfnt->resfont = p ;
curfnt->name = p->TeXname ;
for (i=0; i<256; i++) {
curfnt->chardesc[i].TFMwidth = 0 ;
curfnt->chardesc[i].packptr = NULL ;
curfnt->chardesc[i].pixelwidth = 0 ;
curfnt->chardesc[i].flags = 0 ;
}
add_name(p->PSname, &ps_fonts_used) ;
/*
* We include the font here. But we only should need to include the
* font if we have a stupid spooler; smart spoolers should be able
* to supply it automatically.
*/
if (p->downloadheader) {
char *cp = p->downloadheader ;
char *q ;
infont = p->PSname ;
while (1) {
q = cp ;
while (*cp && *cp != ' ')
cp++ ;
if (*cp) {
*cp = 0 ;
add_header(q) ;
*cp++ = ' ' ;
} else {
add_header(q) ;
break ;
}
infont = 0 ;
}
infont = 0 ;
}
i = tfmload(curfnt) ;
if (i < 0)
i = 1 ;
usesPSfonts = 1 ;
return(i) ;
}
#define INLINE_SIZE (500)
static char was_inline[INLINE_SIZE] ;
void
bad_config() {
extern void exit() ;
error("Error in config file:") ;
(void)fprintf(stderr, "%s\n", was_inline) ;
exit(1) ;
}
/*
* Get environment variables! These override entries in ./config.h.
* We substitute everything of the form ::, ^: or :$ with default,
* so a user can easily build on to the existing paths.
*/
static char *getpath(who, what)
char *who, *what ;
{
if (who) {
register char *pp, *qq ;
int lastsep = 1 ;
for (pp=nextstring, qq=who; *qq;) {
if (*qq == PATHSEP) {
if (lastsep) {
strcpy(pp, what) ;
pp = pp + strlen(pp) ;
}
lastsep = 1 ;
} else
lastsep = 0 ;
*pp++ = *qq++ ;
}
if (lastsep) {
strcpy(pp, what) ;
pp = pp + strlen(pp) ;
}
*pp = 0 ;
qq = nextstring ;
nextstring = pp + 1 ;
return qq ;
} else
return what ;
}
/*
* We use this function so we can support strings delimited by
* double quotes with spaces in them. We also accept strings
* with spaces in them, but kill off any spaces at the end.
*/
char *configstring(s, nullok)
char *s ;
int nullok ;
{
char tstr[300] ;
char *p = tstr ;
while (*s && *s <= ' ')
s++ ;
if (*s == '"') {
s++ ;
while (*s != 10 && *s != 0 && *s != '"' && p < tstr+290)
*p++ = *s++ ;
} else {
while (*s && p < tstr+290)
*p++ = *s++ ;
while (*(p-1) <= ' ' && p > tstr)
p-- ;
}
*p = 0 ;
if (p == tstr && ! nullok)
bad_config() ;
return newstring(tstr) ;
}
/*
* Now we have the getdefaults routine.
*/
static char *psmapfile = PSMAPFILE ;
void
getdefaults(s)
char *s ;
{
FILE *deffile ;
char PSname[300] ;
register char *p ;
int i, j ;
integer hsiz, vsiz ;
char *d = configpath ;
int canaddtopaper = 0 ;
if (printer == NULL) {
if (s) {
strcpy(PSname, s) ;
} else {
#ifndef VMCMS /* IBM: VM/CMS - don't have home directory on VMCMS */
#ifndef MVSXA
d = "~" ;
#endif
#endif /* IBM: VM/CMS */
strcpy(PSname, DVIPSRC) ;
}
} else {
#ifdef OS2
strcpy(PSname, printer) ;
strcat(PSname, ".cfg") ;
#else
strcpy(PSname, "config.") ;
strcat(PSname, printer) ;
#endif
}
if ((deffile=search(d,PSname,READ))!=NULL) {
while (fgets(was_inline, INLINE_SIZE, deffile)!=NULL) {
/*
* We need to get rid of the newline.
*/
for