home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fonts 1
/
freshfonts1.bin
/
bbs
/
programs
/
amiga
/
pastex13.lha
/
DVIPS
/
dvips5519.lha
/
dvips
/
output.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-04
|
32KB
|
1,221 lines
/*
* These routines do most of the communicating with the printer.
*
* LINELENGTH tells the maximum line length to send out. It's been
* reduced to 72 because sometimes PostScript files are included in
* mail messages and many mailers mutilate longer lines.
*/
#define LINELENGTH (72)
#include "dvips.h" /* The copyright notice in that file is included too! */
#include <ctype.h>
/*
* The external routines called here:
*/
extern void error() ;
extern void send_headers() ;
extern int add_header() ;
extern FILE *search() ;
extern char *getenv() ;
extern void makepsname() ;
extern void handlepapersize() ;
extern void findbb() ;
/*
* These are the external variables used by these routines.
*/
extern integer hh, vv ;
extern fontdesctype *curfnt ;
extern FILE *bitfile ;
extern char *oname ;
extern Boolean secure ;
extern Boolean reverse ;
extern Boolean removecomments ;
extern Boolean sendcontrolD, disablecomments, multiplesects ;
extern Boolean usesPSfonts, headers_off ;
extern Boolean safetyenclose ;
extern Boolean cropmarks ;
extern Boolean tryepsf ;
extern int numcopies ;
extern int collatedcopies ;
extern integer pagecopies ;
extern int totalpages ;
extern integer pagenum ;
extern Boolean manualfeed ;
extern int landscape ;
extern int quiet ;
extern int prettycolumn ;
extern int actualdpi, vactualdpi ;
extern char *iname, *nextstring ;
extern char *paperfmt ;
extern char *headerpath ;
extern char errbuf[] ;
extern shalfword linepos ;
extern char *figpath ;
extern struct header_list *ps_fonts_used ;
extern char banner[] ;
extern int gargc ;
extern char **gargv ;
extern struct papsiz *papsizes ;
extern integer hpapersize, vpapersize ;
char preamblecomment[256] ; /* usually "TeX output ..." */
/*
* We need a few statics to take care of things.
*/
static integer rhh, rvv ;
static int instring ;
static Boolean lastspecial = 1 ;
static shalfword d ;
static Boolean popened = 0 ;
int lastfont ; /* exported to dospecial to fix rotate.tex problem */
static void chrcmd(); /* just a forward declaration */
static char strbuffer[LINELENGTH + 20], *strbp = strbuffer ;
static struct papsiz *finpapsiz ;
static struct papsiz defpapsiz = {
0, 40258437L, 52099154L, "letter", ""
} ;
#ifdef CREATIONDATE
#if !defined(VMS) && !defined(MSDOS) && !defined(AMIGA) /* VAXC/MSDOS don't like/need this !! */
#include <sys/types.h>
#include <sys/time.h> /* time(), at least on BSD Unix */
#endif
#include <time.h> /* asctime() and localtime(), at least on BSD Unix */
static time_t jobtime;
#endif
/*
* This routine copies a file down the pipe. Search path uses the
* header path.
*
* We add code to handle the case of MS-DOS font files.
*
* Format: 80 {01,02} four byte length in littleendian order data
* repeated possibly multiple times.
*/
static char *hxdata = "0123456789ABCDEF" ;
static int infigure ;
extern char *infont ;
static char *begbinary = "\n%%BeginBinary:" ;
void
copyfile(s)
char *s ;
{
FILE *f = NULL ;
int c, prevc = '\n' ;
long len ;
char *bbmatch = begbinary ;
#ifdef VMCMS
register char *lastdirsep ;
register char *trunc_s ;
trunc_s = s ;
#endif
#ifdef MVSXA
register char *lastdirsep ;
register char *trunc_s ;
trunc_s = s ;
#endif
switch (infigure) {
case 1:
/*
* Look in headerpath too, just in case. This allows common header
* or figure files to be installed in the .../ps directory.
*/
f = search(figpath, s, READ) ;
if (f == 0)
f = search(headerpath, s, READ) ;
#ifdef VMCMS
lastdirsep = strrchr(s, '/') ;
if ( NULL != lastdirsep ) trunc_s = lastdirsep + 1 ;
(void)sprintf(errbuf,
"Couldn't find figure file %s with CMS name %s; continuing", s, trunc_s) ;
#else
#ifdef MVSXA
lastdirsep = strrchr(s, '/') ;
if ( NULL != lastdirsep ) trunc_s = lastdirsep + 1 ;
(void)sprintf(errbuf,
"Couldn't find figure file %s with MVS name %s; continuing", s, trunc_s) ;
#else
(void)sprintf(errbuf, "Couldn't find figure file %s; continuing", s) ;
#endif
#endif
break ;
default:
f = search(headerpath, s, READ) ;
(void)sprintf(errbuf, "! Couldn't find header file %s", s) ;
break ;
#ifndef VMCMS
#ifndef MVSXA
#ifndef VMS
#ifndef MSDOS
#ifndef __THINK__
#ifndef AMIGA
case 2:
#ifdef SECURE
(void)sprintf(errbuf, "<%s>: Tick filename execution disabled", s) ;
#else
if (secure == 0)
f = popen(s, "r") ;
(void)sprintf(errbuf, "Failure to execute %s; continuing", s) ;
#endif
break;
#endif
#endif
#endif
#endif
#endif
#endif
}
if (f==NULL)
error(errbuf) ;
else {
if (! quiet) {
if (strlen(s) + prettycolumn > STDOUTSIZE) {
fprintf(stderr, "\n") ;
prettycolumn = 0 ;
}
#ifdef VMCMS
(void)fprintf(stderr, "<%s>", trunc_s) ;
#else
#ifdef MVSXA
(void)fprintf(stderr, "<%s>", trunc_s) ;
#else
(void)fprintf(stderr, "<%s>", s) ;
#endif
#endif
(void)fflush(stderr) ;
prettycolumn += 2 + strlen(s) ;
}
if (linepos != 0)
(void)putc('\n', bitfile) ;
if (! disablecomments)
if (infigure)
(void)fprintf(bitfile, "%%%%BeginDocument: %s\n", s) ;
else if (infont)
(void)fprintf(bitfile, "%%%%BeginFont: %s\n", infont) ;
else
(void)fprintf(bitfile, "%%%%BeginProcSet: %s\n", s) ;
c = getc(f) ;
if (c == 0x80) {
#if defined MSDOS || defined OS2
(void)fclose(f) ; /* close MSDOS font file */
f = search(headerpath, s, READBIN) ; /* reopen in BINARY mode */
(void)sprintf(errbuf, "! Couldn't find header file %s", s) ;
if (f==NULL)
error(errbuf) ;
c = getc(f);
#endif
while (1) {
c = getc(f) ;
switch(c) {
case 1:
case 2:
len = getc(f) ;
len += getc(f) * 256L ;
len += getc(f) * 65536L ;
len += getc(f) * 256L * 65536 ;
if (c == 1) {
while (len > 0) {
c = getc(f) ;
if (c == EOF) {
error("premature EOF in MS-DOS font file") ;
len = 0 ;
} else {
if (c == 13)
(void)putc('\n', bitfile) ;
else
(void)putc(c, bitfile) ;
len-- ;
}
}
} else {
putc('\n', bitfile) ;
prevc = 0 ;
while (len > 0) {
c = getc(f) ;
if (c == EOF) {
error("premature EOF in MS-DOS font file") ;
len = 0 ;
} else {
(void)putc(hxdata[c >> 4], bitfile) ;
(void)putc(hxdata[c & 15], bitfile) ;
len-- ;
prevc += 2 ;
if (prevc >= 76) {
putc('\n', bitfile) ;
prevc = 0 ;
}
}
}
}
break ;
case 3:
goto msdosdone ;
default:
error("saw type other than 1, 2, or 3 in MS-DOS font file") ;
break ;
}
c = getc(f) ;
if (c == EOF)
break ;
if (c != 0x80) {
error("saw non-MSDOS header in MSDOS font file") ;
break ;
}
}
msdosdone:
prevc = 0 ;
} else {
if (c != EOF) {
while (1) {
if (c == *bbmatch) {
bbmatch++ ;
if (*bbmatch == '\0') {
integer size = 0 ;
if (removecomments)
(void)fputs(begbinary, bitfile) ;
(void)putc(c, bitfile) ;
while (1) {
c = getc(f) ;
if (c