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
|
/*
* DEVICE dependent I/O
*/
#include "defs.h"
#include "emit.h"
#include "global.h"
#include "ps.h"
static void copyfile();
static void createpipe();
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;
{
int i;
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)
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);
}
}
cpfile(spfp, remcom, fn)
FILE *spfp;
BOOLEAN remcom;
char *fn;
{
int t, pt;
if ((t = getc(spfp)) == 0x80) {
copy_type1_pfb(spfp, fn);
} else if (remcom) {
for (pt = '\n'; 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 ******************************/
/*********************************************************************/
static void
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 ******************************/
/*********************************************************************/
static void
createpipe(fn, remcom)
char *fn;
BOOLEAN remcom;
{
FILE *spfp;
int t, pt;
#ifdef MSDOS
Warning("MSDOS does not have pipes");
return;
#else
if ((spfp = BINARYPOPEN(fn)) != 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
}
|