1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
/*
* DEVICE dependent I/O
*/
#include "defs.h"
#include "emit.h"
#include "global.h"
#include "ps.h"
void
dev_copyfile(str)
char *str;
{
EMIT(outfp, "%%%%BeginFile: %s\n", str);
copyfile(str, FALSE);
EMIT(outfp, "%%%%EndFile\n");
}
void
ps_add_setup(str)
char *str;
{
int found;
char newf[PATHLEN];
if (found = ps_searchfile(str, newf)) {
add_setup_spec(found == SEARCH_ORIG ? str : newf, dev_copyfile);
} else
Warning("File %s not found", str);
}
void
ps_copyfigfile(str)
char *str;
{
int found;
char newf[PATHLEN];
if (found = ps_searchfile(str, newf)) {
EMIT(outfp, "%%%%BeginDocument: %s\n", str);
copyfile(found == SEARCH_ORIG ? str : newf, G_removecomments);
EMIT(outfp, "%%%%EndDocument\n");
} else
Warning("File %s not found", str);
}
ps_searchfile(f, newf)
char *f, *newf;
{
if (f[0] == '/') {
if (access(f, R_OK) == 0)
return SEARCH_ORIG;
} else {
if (dvidirpath[0] != '\0') {
(void)strcpy(newf, dvidirpath);
(void)strcat(newf, f);
if (access(newf, R_OK) == 0)
return SEARCH_NEW;
}
if (access(f, R_OK) == 0)
return SEARCH_ORIG;
(void)strcpy(newf, dvi2lib);
(void)strcat(newf, "/");
(void)strcat(newf, f);
if (access(newf, R_OK) == 0)
return SEARCH_NEW;
}
return SEARCH_FAIL;
}
void
ps_createpipe(str)
char *str;
{
EMIT(outfp, "%%%%BeginDocument: %s\n", str);
createpipe(str, G_removecomments);
EMIT(outfp, "%%%%EndDocument\n");
}
void
dev_copystring(str)
char *str;
{
EMIT(outfp, "%s\n", str);
}
void
ps_string(str)
char *str;
{
register int i;
register int instring = 0;
int lastc = 0;
i = 0 ;
while (*str) {
if (i > 65 && *str == ' ' && instring == 0) {
EMITC('\n');
i = 0;
} else {
EMITC(*str);
i++;
}
if (*str == '(' && lastc != '\\')
instring = 1;
else if (*str == ')' && lastc != '\\')
instring = 0;
lastc = *str;
str++;
}
}
pschar(c)
register int c;
{
if (c < ' ' || c >= 0177)
EMITO(c);
else if (c == '(' || c == ')' || c == '\\') {
EMITC('\\');
EMITC(c);
} else
EMITC(c);
}
codetopsstr(code, n)
int code, n;
{
EMITC('(');
c2pstr(code, n);
EMITS(") ");
}
c2pstr(code, n)
int code, n;
{
if (n > 0) {
c2pstr(code>>8, n-1);
pschar(code&0xff);
}
}
#define BINLEN 32
static char *hexdig = "0123456789ABCDEF";
cpfile(spfp, remcom, fn)
FILE *spfp;
BOOLEAN remcom;
char *fn;
{
int t, pt;
long len, b;
int i;
if ((t = getc(spfp)) == 0x80) {
for (;;) {
switch (t = getc(spfp)) {
case 1:
for (len = 0, b = 1, i = 1; i <= 4; b = b*256, i++)
len += b*getc(spfp);
for (; len > 0; --len) {
if ((t = getc(spfp)) == EOF)
Fatal("premature EOF in type1 font file %s", fn);
if (t == '\r')
EMITC('\n');
else
EMITC(t);
}
break;
case 2:
for (len = 0, b = 1, i = 1; i <= 4; b = b*256, i++)
len += b*getc(spfp);
for (i = 0; len > 0; --len) {
if ((t = getc(spfp)) == EOF)
Fatal("premature EOF in type1 font file %s", fn);
EMITC(hexdig[t>>4]);
EMITC(hexdig[t&0xf]);
i++;
if (i == BINLEN) {
EMITC('\n');
i = 0;
}
}
if (i > 0)
EMITC('\n');
break;
case 3:
return;
}
}
} else if (remcom) {
pt = '\n';
for (; t != EOF; t = getc(spfp)) {
if (t == '%' && pt == '\n') {
while ((t = getc(spfp)) != EOF) /* remove comments */
if (t == '\n')
break;
} else {
EMITC(t);
pt = t;
}
}
} else
for (; t != EOF; t = getc(spfp))
EMITC(t);
}
/*-->copyfile*/ /* copy a file straight through to output */
/*********************************************************************/
/***************************** copyfile ******************************/
/*********************************************************************/
copyfile(fn, remcom)
char *fn;
BOOLEAN remcom;
{
FILE *spfp;
if ((spfp = fopen(fn,"r")) == NULL) {
Warning("Unable to open file %s", fn);
return;
}
if (!G_quiet)
(void)fprintf(stderr, "[%s", fn);
cpfile(spfp, remcom, fn);
(void)fclose(spfp);
if (!G_quiet) {
(void)fprintf(stderr, "] ");
(void)fflush(stderr);
}
}
/*-->createpipe*/ /* create pipe */
/*********************************************************************/
/***************************** createpipe ******************************/
/*********************************************************************/
createpipe(fn, remcom)
char *fn;
BOOLEAN remcom;
{
FILE *spfp;
int t, pt;
#ifdef MSDOS
Warning("MSDOS does not have pipes");
return;
#else
if ((spfp = popen(fn,"r")) == NULL) {
Warning("Unable to create pipe %s", fn);
return;
}
if (!G_quiet)
(void)fprintf(stderr, "[%s", fn);
cpfile(spfp, remcom, fn);
(void)pclose(spfp);
if (!G_quiet) {
(void)fprintf(stderr, "] ");
(void)fflush(stderr);
}
#endif
}
|