| 1 |
/* |
| 2 |
* This routine handles special commands; |
| 3 |
* predospecial() is for the prescan, dospecial() for the real thing. |
| 4 |
*/ |
| 5 |
#ifndef XDVIPSK |
| 6 |
#include "dvips.h" /* The copyright notice in that file is included too! */ |
| 7 |
#else |
| 8 |
#include "xdvips.h" /* The copyright notice in that file is included too! */ |
| 9 |
#include "lua.h" |
| 10 |
#include "lauxlib.h" |
| 11 |
#include "lualib.h" |
| 12 |
#include "glyphmap.h" |
| 13 |
#endif /* XDVIPSK */ |
| 14 |
|
| 15 |
#ifdef KPATHSEA |
| 16 |
#include <kpathsea/c-ctype.h> |
| 17 |
#include <kpathsea/tex-hush.h> |
| 18 |
#else /* ! KPATHSEA */ |
| 19 |
#include <ctype.h> |
| 20 |
#include <stdlib.h> |
| 21 |
#ifndef WIN32 |
| 22 |
extern int atoi(); |
| 23 |
extern int system(); |
| 24 |
#endif /* WIN32*/ |
| 25 |
#endif |
| 26 |
/* |
| 27 |
* The external declarations: |
| 28 |
*/ |
| 29 |
#include "protos.h" |
| 30 |
|
| 31 |
static int specialerrors = 20; |
| 32 |
|
| 33 |
struct bangspecial { |
| 34 |
struct bangspecial *next; |
| 35 |
char *actualstuff; |
| 36 |
} *bangspecials = NULL; |
| 37 |
|
| 38 |
#ifdef XDVIPSK |
| 39 |
#ifndef WIN32 |
| 40 |
char *strlwr(char *str) |
| 41 |
{ |
| 42 |
char *ptr = str; |
| 43 |
while(*ptr) |
| 44 |
{ |
| 45 |
*ptr = tolower(*ptr); |
| 46 |
ptr++; |
| 47 |
} |
| 48 |
return(str); |
| 49 |
} |
| 50 |
#endif |
| 51 |
#endif /* XDVIPSK */ |
| 52 |
void |
| 53 |
specerror(const char *s) |
| 54 |
{ |
| 55 |
if (specialerrors > 0 |
| 56 |
#ifdef KPATHSEA |
| 57 |
&& !kpse_tex_hush ("special") |
| 58 |
#endif |
| 59 |
) { |
| 60 |
error(s); |
| 61 |
specialerrors--; |
| 62 |
} else if (specialerrors == 0 |
| 63 |
#ifdef KPATHSEA |
| 64 |
&& !kpse_tex_hush ("special") |
| 65 |
#endif |
| 66 |
) { |
| 67 |
#ifndef XDVIPSK |
| 68 |
error("more errors in special, being ignored . . ."); |
| 69 |
error("(perhaps dvips doesn't support your macro package?)"); |
| 70 |
#else |
| 71 |
writelogrecord(s); |
| 72 |
fprintf(stderr, "%s\n", "more errors in special, being ignored . . ."); |
| 73 |
fprintf(stderr, "%s\n", "(perhaps dvips doesn't support your macro package?)"); |
| 74 |
#endif /* XDVIPSK */ |
| 75 |
specialerrors--; |
| 76 |
} |
| 77 |
#ifdef XDVIPSK |
| 78 |
else if (specialerrors < 0 |
| 79 |
#ifdef KPATHSEA |
| 80 |
&& !kpse_tex_hush("special") |
| 81 |
#endif |
| 82 |
) { |
| 83 |
writelogrecord(s); |
| 84 |
} |
| 85 |
#endif /* XDVIPSK */ |
| 86 |
} |
| 87 |
|
| 88 |
static void |
| 89 |
outputstring(register char *p) |
| 90 |
{ |
| 91 |
putc('\n', bitfile); |
| 92 |
while(*p) { |
| 93 |
putc(*p, bitfile); |
| 94 |
p++; |
| 95 |
} |
| 96 |
putc('\n', bitfile); |
| 97 |
} |
| 98 |
|
| 99 |
static void |
| 100 |
trytobreakout(register char *p) |
| 101 |
{ |
| 102 |
register int i; |
| 103 |
register int instring = 0; |
| 104 |
int lastc = 0; |
| 105 |
|
| 106 |
i = 0; |
| 107 |
putc('\n', bitfile); |
| 108 |
|
| 109 |
if(*p == '%') { |
| 110 |
while(*p) { |
| 111 |
putc(*p, bitfile); |
| 112 |
p++; |
| 113 |
} |
| 114 |
putc('\n', bitfile); |
| 115 |
return; |
| 116 |
} |
| 117 |
|
| 118 |
while (*p) { |
| 119 |
if (i > 65 && *p == ' ' && instring == 0) { |
| 120 |
putc('\n', bitfile); |
| 121 |
i = 0; |
| 122 |
} else { |
| 123 |
putc(*p, bitfile); |
| 124 |
i++; |
| 125 |
} |
| 126 |
if (*p == '(' && lastc != '\\') |
| 127 |
instring = 1; |
| 128 |
else if (*p == ')' && lastc != '\\') |
| 129 |
instring = 0; |
| 130 |
lastc = *p; |
| 131 |
p++; |
| 132 |
} |
| 133 |
putc('\n', bitfile); |
| 134 |
} |
| 135 |
|
| 136 |
static void |
| 137 |
dobs(register struct bangspecial *q) |
| 138 |
{ |
| 139 |
if (q) { |
| 140 |
dobs(q->next); |
| 141 |
trytobreakout(q->actualstuff); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
/* added for dvi2ps & jdvi2kps format */ |
| 146 |
static char *mfgets(char *buf, unsigned int bytes, FILE *fp); |
| 147 |
|
| 148 |
static void |
| 149 |
fgetboundingbox(char *f, float *llx_p, float *lly_p, float *urx_p, float *ury_p) |
| 150 |
{ |
| 151 |
FILE *fp; |
| 152 |
char buf[BUFSIZ+1]; |
| 153 |
|
| 154 |
fp = search(figpath, f, READ); |
| 155 |
if (fp == 0) |
| 156 |
fp = search(headerpath, f, READ); |
| 157 |
if (fp) { |
| 158 |
while (mfgets(buf, BUFSIZ, fp) != 0) { |
| 159 |
if (buf[0] == '%' && buf[1] == '%' |
| 160 |
&& strncmp(buf+2, "BoundingBox:", 12) == 0) { |
| 161 |
if (sscanf(buf+14, "%f %f %f %f", llx_p, lly_p, urx_p, ury_p) == 4) { |
| 162 |
fclose(fp); |
| 163 |
return; |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
fclose(fp); |
| 168 |
} |
| 169 |
sprintf(errbuf, "Couldn't get BoundingBox of %.500s: assuming full A4 size", f); |
| 170 |
specerror(errbuf); |
| 171 |
*llx_p = 0.0; |
| 172 |
*lly_p = 0.0; |
| 173 |
*urx_p = 595.0; |
| 174 |
*ury_p = 842.0; |
| 175 |
} |
| 176 |
|
| 177 |
static char * |
| 178 |
mfgets(char *buf, unsigned int bytes, FILE *fp) |
| 179 |
{ |
| 180 |
int i, cc; |
| 181 |
|
| 182 |
for (i = 0; i < bytes; i++) { |
| 183 |
cc = fgetc(fp); |
| 184 |
if (cc == 0x0a || cc == 0x0d) { |
| 185 |
if (cc == 0x0d) { |
| 186 |
cc = fgetc(fp); |
| 187 |
if (cc != 0x0a) { |
| 188 |
ungetc(cc, fp); |
| 189 |
} |
| 190 |
} |
| 191 |
cc = 0x0a; |
| 192 |
buf[i] = cc; |
| 193 |
buf[i+1] = '\0'; |
| 194 |
return buf; |
| 195 |
} else if (cc == EOF) { |
| 196 |
buf[i] = '\0'; |
| 197 |
if (i == 0) return NULL; |
| 198 |
else return buf; |
| 199 |
} else { |
| 200 |
buf[i] = cc; |
| 201 |
} |
| 202 |
} |
| 203 |
buf[i] = '\0'; |
| 204 |
return buf; |
| 205 |
} |
| 206 |
|
| 207 |
static void |
| 208 |
floatroundout(float f) |
| 209 |
{ |
| 210 |
integer i; |
| 211 |
i = (integer)(f<0 ? f-0.5 : f+0.5); |
| 212 |
if (i-f < 0.001 && i-f > -0.001) { |
| 213 |
numout((integer)i); |
| 214 |
} else { |
| 215 |
floatout(f); |
| 216 |
} |
| 217 |
} |
| 218 |
/* end of addition */ |
| 219 |
|
| 220 |
void |
| 221 |
outbangspecials(void) { |
| 222 |
if (bangspecials) { |
| 223 |
cmdout("TeXDict"); |
| 224 |
cmdout("begin"); |
| 225 |
cmdout("@defspecial\n"); |
| 226 |
dobs(bangspecials); |
| 227 |
cmdout("\n@fedspecial"); |
| 228 |
cmdout("end"); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
/* We recommend that new specials be handled by the following general |
| 233 |
* (and extensible) scheme, in which the user specifies one or more |
| 234 |
* `key=value' pairs separated by spaces. |
| 235 |
* The known keys are given in KeyTab; they take values |
| 236 |
* of one of the following types: |
| 237 |
* |
| 238 |
* None: no value, just a keyword (in which case the = sign is omitted) |
| 239 |
* String: the value should be "<string without double-quotes" |
| 240 |
* or '<string without single-quotes' |
| 241 |
* Integer: the value should be a decimal integer (%d format) |
| 242 |
* Number: the value should be a decimal integer or real (%f format) |
| 243 |
* Dimension: like Number, but will be multiplied by the scaledsize |
| 244 |
* of the current font and converted to default PostScript units |
| 245 |
* (Actually, strings are allowed in all cases; the delimiting quotes |
| 246 |
* are simply stripped off if present.) |
| 247 |
* |
| 248 |
*/ |
| 249 |
|
| 250 |
typedef enum {None, String, Integer, Number, Dimension} ValTyp; |
| 251 |
typedef struct { |
| 252 |
const char *Entry; |
| 253 |
ValTyp Type; |
| 254 |
} KeyDesc; |
| 255 |
|
| 256 |
#define NKEYS (sizeof(KeyTab)/sizeof(KeyTab[0])) |
| 257 |
|
| 258 |
#ifdef XDVIPSK |
| 259 |
enum |
| 260 |
{ |
| 261 |
psfile_key, /* 0 */ |
| 262 |
ifffile_key, /* 1 */ |
| 263 |
tekfile_key, /* 2 */ |
| 264 |
hsize_key, /* 3 */ |
| 265 |
vsize_key, /* 4 */ |
| 266 |
hoffset_key, /* 5 */ |
| 267 |
voffset_key, /* 6 */ |
| 268 |
hscale_key, /* 7 */ |
| 269 |
vscale_key, /* 8 */ |
| 270 |
angle_key, /* 9 */ |
| 271 |
llx_key, /* 10 */ |
| 272 |
lly_key, /* 11 */ |
| 273 |
urx_key, /* 12 */ |
| 274 |
ury_key, /* 13 */ |
| 275 |
rwi_key, /* 14 */ |
| 276 |
rhi_key, /* 15 */ |
| 277 |
clip_key, /* 16 */ |
| 278 |
mapline_key, /* 17 */ |
| 279 |
mapfile_key, /* 18 */ |
| 280 |
g2umapline_key, /* 19 */ |
| 281 |
g2umapfile_key, /* 20 */ |
| 282 |
opentype_key, /* 21 */ |
| 283 |
enc_key, /* 22 */ |
| 284 |
nkeys /* 23 */ |
| 285 |
}; |
| 286 |
#endif /* XDVIPSK */ |
| 287 |
|
| 288 |
KeyDesc KeyTab[] = {{"psfile", String}, /* j==0 in the routine below */ |
| 289 |
{"ifffile", String}, /* j==1 */ |
| 290 |
{"tekfile", String}, /* j==2 */ |
| 291 |
{"hsize", Number}, |
| 292 |
{"vsize", Number}, |
| 293 |
{"hoffset", Number}, |
| 294 |
{"voffset", Number}, |
| 295 |
{"hscale", Number}, |
| 296 |
{"vscale", Number}, |
| 297 |
{"angle", Number}, |
| 298 |
{"llx", Number}, |
| 299 |
{"lly", Number}, |
| 300 |
{"urx", Number}, |
| 301 |
{"ury", Number}, |
| 302 |
{"rwi", Number}, |
| 303 |
{"rhi", Number}, |
| 304 |
#ifndef XDVIPSK |
| 305 |
{"clip", None}}; |
| 306 |
#else /* XDVIPSK */ |
| 307 |
{"clip", None}, |
| 308 |
{"mapline", String}, |
| 309 |
{"mapfile", String}, |
| 310 |
{"g2umapline", String}, |
| 311 |
{"g2umapfile", String}, |
| 312 |
{"opentype", String}, |
| 313 |
{"enc", String}, |
| 314 |
}; |
| 315 |
#endif /* XDVIPSK */ |
| 316 |
|
| 317 |
#ifndef KPATHSEA |
| 318 |
#define TOLOWER Tolower |
| 319 |
#ifdef VMS |
| 320 |
#ifndef __GNUC__ /* GNUC tolower is too simple */ |
| 321 |
#define Tolower tolower |
| 322 |
#endif |
| 323 |
#else |
| 324 |
#ifdef VMCMS /* IBM: VM/CMS */ |
| 325 |
#define Tolower __tolower |
| 326 |
#else |
| 327 |
#ifdef MVSXA /* IBM: MVS/XA */ |
| 328 |
#define Tolower __tolower |
| 329 |
#else |
| 330 |
/* |
| 331 |
* compare strings, ignore case |
| 332 |
*/ |
| 333 |
char |
| 334 |
Tolower(register char c) |
| 335 |
{ |
| 336 |
if ('A' <= c && c <= 'Z') |
| 337 |
return(c+32); |
| 338 |
else |
| 339 |
return(c); |
| 340 |
} |
| 341 |
#endif |
| 342 |
#endif /* IBM: VM/CMS */ |
| 343 |
#endif |
| 344 |
#endif /* !KPATHSEA */ |
| 345 |
static int |
| 346 |
IsSame(const char *a, const char *b) |
| 347 |
{ |
| 348 |
for(; *a != '\0'; ) { |
| 349 |
if( TOLOWER(*a) != TOLOWER(*b) ) |
| 350 |
return( 0 ); |
| 351 |
a++; |
| 352 |
b++; |
| 353 |
} |
| 354 |
return( *b == '\0' ); |
| 355 |
} |
| 356 |
|
| 357 |
char *KeyStr; /* Key and ... */ |
| 358 |
const char *ValStr; /* ... String values found */ |
| 359 |
long ValInt; /* Integer value found */ |
| 360 |
float ValNum; /* Number or Dimension value found */ |
| 361 |
|
| 362 |
static char * |
| 363 |
GetKeyVal(char *str, int *tno) /* returns NULL if none found, else next scan point */ |
| 364 |
/* str : starting point for scan */ |
| 365 |
/* tno : table entry number of keyword, or -1 if keyword not found */ |
| 366 |
{ |
| 367 |
unsigned char *s; |
| 368 |
register int i; |
| 369 |
register char t; |
| 370 |
|
| 371 |
#ifdef XDVIPSK |
| 372 |
assert(NKEYS == nkeys); |
| 373 |
|
| 374 |
for (s = str; ((*s <= ' ') || (*s == ',') || (*s == ';')) && *s; s++); /* skip over blanks and key-value delimiters*/ |
| 375 |
#else |
| 376 |
for (s=str; *s <= ' ' && *s; s++); /* skip over blanks */ |
| 377 |
#endif /* XDVIPSK */ |
| 378 |
if (*s == '\0') |
| 379 |
return (NULL); |
| 380 |
KeyStr = s; |
| 381 |
while (*s>' ' && *s!='=') s++; |
| 382 |
if (0 != (t = *s)) |
| 383 |
*s++ = 0; |
| 384 |
|
| 385 |
for(i=0; i<NKEYS; i++) |
| 386 |
if( IsSame(KeyStr, KeyTab[i].Entry) ) |
| 387 |
goto found; |
| 388 |
*tno = -1; |
| 389 |
return (s); |
| 390 |
|
| 391 |
found: *tno = i; |
| 392 |
if (KeyTab[i].Type == None) |
| 393 |
return (s); |
| 394 |
|
| 395 |
if (t && t <= ' ') { |
| 396 |
for (; *s <= ' ' && *s; s++); /* now look for the value part */ |
| 397 |
if ((t = *s)=='=') |
| 398 |
s++; |
| 399 |
} |
| 400 |
ValStr = ""; |
| 401 |
if ( t == '=' ) { |
| 402 |
while (*s <= ' ' && *s) |
| 403 |
s++; |
| 404 |
if (*s=='\'' || *s=='\"') |
| 405 |
t = *s++; /* get string delimiter */ |
| 406 |
#ifdef XDVIPSK |
| 407 |
else if (*s == '{') |
| 408 |
{ |
| 409 |
t = '}'; |
| 410 |
while (*(++s) <= ' '); |
| 411 |
} |
| 412 |
#endif /* XDVIPSK */ |
| 413 |
else t = ' '; |
| 414 |
ValStr = s; |
| 415 |
#ifdef XDVIPSK |
| 416 |
while (*s != t && ((t != ' ') || ((*s != ',') && (*s != ';'))) && *s) |
| 417 |
#else |
| 418 |
while (*s!=t && *s) |
| 419 |
#endif /* XDVIPSK */ |
| 420 |
s++; |
| 421 |
if (*s) |
| 422 |
*s++ = 0; |
| 423 |
} |
| 424 |
switch (KeyTab[i].Type) { |
| 425 |
case Integer: |
| 426 |
if(sscanf(ValStr,"%ld",&ValInt)!=1) { |
| 427 |
sprintf(errbuf,"Non-integer value (%.500s) given for keyword %.500s", |
| 428 |
ValStr, KeyStr); |
| 429 |
specerror(errbuf); |
| 430 |
ValInt = 0; |
| 431 |
} |
| 432 |
break; |
| 433 |
case Number: |
| 434 |
case Dimension: |
| 435 |
if(sscanf(ValStr,"%f",&ValNum)!=1) { |
| 436 |
sprintf(errbuf,"Non-numeric value (%.500s) given for keyword %.500s", |
| 437 |
ValStr, KeyStr); |
| 438 |
specerror(errbuf); |
| 439 |
ValNum = 0.0; |
| 440 |
} |
| 441 |
if (KeyTab[i].Type==Dimension) { |
| 442 |
if (curfnt==NULL) |
| 443 |
error("! No font selected"); |
| 444 |
ValNum = ValNum * ((double)curfnt->scaledsize) * conv * 72 / DPI; |
| 445 |
} |
| 446 |
break; |
| 447 |
default: break; |
| 448 |
} |
| 449 |
return (s); |
| 450 |
} |
| 451 |
|
| 452 |
/* |
| 453 |
* Now our routines. We get the number of bytes specified and place them |
| 454 |
* into the string buffer, and then parse it. Numerous conventions are |
| 455 |
* supported here for historical reasons. |
| 456 |
* |
| 457 |
* To support GNUplot's horribly long specials, we go ahead and malloc a |
| 458 |
* new string buffer if necessary. |
| 459 |
*/ |
| 460 |
|
| 461 |
void |
| 462 |
#ifdef XDVIPSK |
| 463 |
predospecial(integer numbytes, Boolean scanning, boolean parse_maps) |
| 464 |
#else |
| 465 |
predospecial(integer numbytes, Boolean scanning) |
| 466 |
#endif /* XDVIPSK */ |
| 467 |
{ |
| 468 |
register char *p = nextstring; |
| 469 |
register int i = 0; |
| 470 |
int j; |
| 471 |
static int omega_specials = 0; |
| 472 |
#ifdef XDVIPSK |
| 473 |
size_t ll; |
| 474 |
char *spec_buf, *spec_buf_end, *spec_ptr, *key_buf, *key_ptr, *pp; |
| 475 |
const char *spec_name; |
| 476 |
int ii, jj; |
| 477 |
#endif /* XDVIPSK */ |
| 478 |
|
| 479 |
if (numbytes < 0 || numbytes > maxstring - nextstring) { |
| 480 |
if (numbytes < 0 || numbytes > (INT_MAX - 1000) / 2 ) { |
| 481 |
error("! Integer overflow in predospecial"); |
| 482 |
#ifndef XDVIPSK |
| 483 |
exit(1); |
| 484 |
#else |
| 485 |
dvips_exit(1); |
| 486 |
#endif /* XDVIPSK */ |
| 487 |
} |
| 488 |
p = nextstring = mymalloc(1000 + 2 * numbytes); |
| 489 |
maxstring = nextstring + 2 * numbytes + 700; |
| 490 |
} |
| 491 |
for (i=numbytes; i>0; i--) |
| 492 |
#ifdef VMCMS /* IBM: VM/CMS */ |
| 493 |
*p++ = ascii2ebcdic[(char)dvibyte()]; |
| 494 |
#else |
| 495 |
#ifdef MVSXA /* IBM: MVS/XA */ |
| 496 |
*p++ = ascii2ebcdic[(char)dvibyte()]; |
| 497 |
#else |
| 498 |
*p++ = (char)dvibyte(); |
| 499 |
#endif /* IBM: VM/CMS */ |
| 500 |
#endif |
| 501 |
#ifdef XDVIPSK |
| 502 |
if ((!parse_maps) && pprescan) |
| 503 |
#else |
| 504 |
if (pprescan) |
| 505 |
#endif /* XDVIPSK */ |
| 506 |
return; |
| 507 |
while (p[-1] <= ' ' && p > nextstring) |
| 508 |
p--; /* trim trailing blanks */ |
| 509 |
if (p==nextstring) return; /* all blank is no-op */ |
| 510 |
*p = 0; |
| 511 |
p = nextstring; |
| 512 |
while (*p <= ' ') |
| 513 |
p++; |
| 514 |
#ifdef DEBUG |
| 515 |
if (dd(D_SPECIAL)) |
| 516 |
fprintf_str(stderr, "Preprocessing special: %s\n", p); |
| 517 |
#endif |
| 518 |
|
| 519 |
#ifdef XDVIPSK |
| 520 |
if (!parse_maps) |
| 521 |
{ |
| 522 |
ll = run_lua_specials(L, "prescan_specials_callback", p, lua_prescan_specials); |
| 523 |
if (ll == 0) return; |
| 524 |
} |
| 525 |
#endif /* XDVIPSK */ |
| 526 |
|
| 527 |
/* |
| 528 |
* We use strncmp() here to also pass things like landscape() |
| 529 |
* or landscape: or such. |
| 530 |
*/ |
| 531 |
|
| 532 |
#ifdef XDVIPSK |
| 533 |
if (!parse_maps) |
| 534 |
{ |
| 535 |
#endif /* XDVIPSK */ |
| 536 |
switch (*p) { |
| 537 |
case 'o': |
| 538 |
if (strncmp(p, "om:", 3)==0) { /* Omega specials ignored */ |
| 539 |
if (omega_specials==0) { |
| 540 |
fprintf(stderr, "Omega specials are currently ignored\n"); |
| 541 |
omega_specials++; |
| 542 |
} |
| 543 |
return; |
| 544 |
} |
| 545 |
break; |
| 546 |
case 'l': |
| 547 |
if (strncmp(p, "landscape", 9)==0) { |
| 548 |
if (hpapersize || vpapersize) |
| 549 |
error( |
| 550 |
"both landscape and papersize specified: ignoring landscape"); |
| 551 |
else |
| 552 |
landscape = 1; |
| 553 |
return; |
| 554 |
} |
| 555 |
break; |
| 556 |
case 'p': |
| 557 |
if (strncmp(p, "pos:", 4)==0) return; /* positional specials */ |
| 558 |
if (strncmp(p, "papersize", 9)==0) { |
| 559 |
p += 9; |
| 560 |
while (*p == '=' || *p == ' ') |
| 561 |
p++; |
| 562 |
if (lastpsizwins || hpapersize == 0 || vpapersize == 0) { |
| 563 |
if (landscape) { |
| 564 |
error( |
| 565 |
"both landscape and papersize specified: ignoring landscape"); |
| 566 |
landscape = 0; |
| 567 |
} |
| 568 |
handlepapersize(p, &hpapersize, &vpapersize); |
| 569 |
} |
| 570 |
return; |
| 571 |
} |
| 572 |
break; |
| 573 |
case 'x': |
| 574 |
if (strncmp(p, "xtex:", 5)==0) return; |
| 575 |
break; |
| 576 |
case 's': |
| 577 |
if (strncmp(p, "src:", 4)==0) return; /* source specials */ |
| 578 |
break; |
| 579 |
|
| 580 |
case 'h': |
| 581 |
if (strncmp(p, "header", 6)==0) { |
| 582 |
char *q, *r, *pre = NULL, *post = NULL; |
| 583 |
p += 6; |
| 584 |
while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0) |
| 585 |
p++; |
| 586 |
if(*p == '{') { |
| 587 |
p++; |
| 588 |
while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0) |
| 589 |
p++; |
| 590 |
q = p; |
| 591 |
while (*p != '}' && *p != 0) |
| 592 |
p++; |
| 593 |
r = p-1; |
| 594 |
while ((*r <= ' ' || *r == ')') && r >= q) |
| 595 |
r--; |
| 596 |
if (*p != 0) p++; |
| 597 |
r[1] = 0; /* q is the file name */ |
| 598 |
while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0) |
| 599 |
p++; |
| 600 |
if(strncmp(p, "pre", 3) == 0) { |
| 601 |
int bracecount = 1, num_bytes = 0; |
| 602 |
while(*p != '{' && *p != 0) |
| 603 |
p++; |
| 604 |
if (*p != 0) p++; |
| 605 |
for(r = p; *r != 0; r++) { |
| 606 |
if (*r == '{') bracecount++; |
| 607 |
else if (*r == '}') bracecount--; |
| 608 |
if (bracecount == 0) break; |
| 609 |
num_bytes++; |
| 610 |
} |
| 611 |
pre = (char *)malloc(num_bytes+1); |
| 612 |
r = pre; |
| 613 |
for (j=0; j < num_bytes; j++) |
| 614 |
*r++ = *p++; |
| 615 |
*r = 0; |
| 616 |
if (*p != 0) p++; |
| 617 |
} |
| 618 |
while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0) |
| 619 |
p++; |
| 620 |
if(strncmp(p, "post", 4) == 0) { |
| 621 |
int bracecount = 1, num_bytes = 0; |
| 622 |
while(*p != '{' && *p != 0) |
| 623 |
p++; |
| 624 |
if (*p != 0) p++; |
| 625 |
for(r = p; *r != 0; r++) { |
| 626 |
if (*r == '{') bracecount++; |
| 627 |
else if (*r == '}') bracecount--; |
| 628 |
if (bracecount == 0) break; |
| 629 |
num_bytes++; |
| 630 |
} |
| 631 |
post = (char *)malloc(num_bytes+1); |
| 632 |
r = post; |
| 633 |
for (j=0; j < num_bytes; j++) |
| 634 |
*r++ = *p++; |
| 635 |
*r = 0; |
| 636 |
} |
| 637 |
if (strlen(q) > 0) |
| 638 |
add_header_general(q, pre, post); |
| 639 |
} else { |
| 640 |
q = p; /* we will remove enclosing parentheses */ |
| 641 |
p = p + strlen(p) - 1; |
| 642 |
while ((*p <= ' ' || *p == ')') && p >= q) |
| 643 |
p--; |
| 644 |
p[1] = 0; |
| 645 |
if (p >= q) |
| 646 |
add_header(q); |
| 647 |
} |
| 648 |
} |
| 649 |
break; |
| 650 |
/* IBM: color - added section here for color header and color history */ |
| 651 |
/* using strncmp in this fashion isn't perfect; if later someone wants |
| 652 |
to introduce a verb like colorspace, well, just checking |
| 653 |
strcmp(p, "color", 5) will not do. But we leave it alone for the moment. |
| 654 |
--tgr */ |
| 655 |
case 'b': |
| 656 |
if (strncmp(p, "background", 10) == 0) { |
| 657 |
usescolor = 1; |
| 658 |
p += 10; |
| 659 |
while ( *p && *p <= ' ' ) p++; |
| 660 |
background(p); |
| 661 |
return; |
| 662 |
} |
| 663 |
break; |
| 664 |
case 'c': |
| 665 |
if (strncmp(p, "color", 5) == 0) { |
| 666 |
usescolor = 1; |
| 667 |
p += 5; |
| 668 |
while ( *p && *p <= ' ' ) p++; |
| 669 |
if (strncmp(p, "push", 4) == 0 ) { |
| 670 |
p += 4; |
| 671 |
while ( *p && *p <= ' ' ) p++; |
| 672 |
pushcolor(p, 0); |
| 673 |
} else if (strncmp(p, "pop", 3) == 0 ) { |
| 674 |
popcolor(0); |
| 675 |
} else { |
| 676 |
resetcolorstack(p,0); |
| 677 |
} |
| 678 |
} /* IBM: color - end changes */ |
| 679 |
break; |
| 680 |
case '!': |
| 681 |
{ |
| 682 |
register struct bangspecial *q; |
| 683 |
p++; |
| 684 |
q = (struct bangspecial *)mymalloc((integer)(sizeof(struct bangspecial))); |
| 685 |
q->actualstuff = mymalloc(strlen(p) + 1); |
| 686 |
strcpy(q->actualstuff, p); |
| 687 |
q->next = bangspecials; |
| 688 |
bangspecials = q; |
| 689 |
usesspecial = 1; |
| 690 |
return; |
| 691 |
} |
| 692 |
break; |
| 693 |
default: |
| 694 |
break; |
| 695 |
} |
| 696 |
#ifdef XDVIPSK |
| 697 |
} |
| 698 |
else /* if (!parse_maps) */ |
| 699 |
{ |
| 700 |
switch (*p) { |
| 701 |
case 'm': |
| 702 |
/* "mapline=MTMI MinionPro-It \" scottm-mn-oml ReEncodeFont \" <[scottm-mn-oml.enc <MinionPro-It.pfb " */ |
| 703 |
/* "mapline: [lmroman10-regular]:+tlig; LMRoman10-Regular \"LMRoman10-Regular\" >$SELFAUTOPARENT/texmf-dist/fonts/opentype/public/lm/lmroman10-regular.otf" */ |
| 704 |
/* "mapline: [De-Gruyter-Sans-Regular-v105.otf]:mode=node;script=latn;language=dflt;+tlig; De-Gruyter-Sans-Regular-v105 \"De Gruyter Sans Regular v105\" >$SELFAUTOGRANDPARENT/vtex-dist/fonts/opentype/google/noto-dg-v105/De-Gruyter-Sans-Regular-v105.otf" */ |
| 705 |
spec_name = KeyTab[mapline_key].Entry; |
| 706 |
ll = strlen(spec_name); |
| 707 |
if (strncmp(p, spec_name, ll) == 0) |
| 708 |
{ |
| 709 |
char *specinfo, *downloadinfo; |
| 710 |
char downbuf[500]; |
| 711 |
char specbuf[500]; |
| 712 |
char *specval, *spec_ptr; |
| 713 |
int slen; |
| 714 |
char *TeXname = NULL; |
| 715 |
char *PSname = NULL; |
| 716 |
char *Fontfile = NULL; |
| 717 |
char *Vectfile = NULL; |
| 718 |
char *hdr_name = NULL; |
| 719 |
boolean nopartial_p = false; |
| 720 |
boolean encoding_p = false; |
| 721 |
boolean repl = 1; |
| 722 |
boolean inside_quotes = FALSE; |
| 723 |
|
| 724 |
p += ll; |
| 725 |
if ((*p == ':') || (*p == '=')) |
| 726 |
p++; |
| 727 |
if ((*p == ' ') || (*p == '\t')) |
| 728 |
p++; |
| 729 |
if (*p == '+') { |
| 730 |
repl = 0; |
| 731 |
p++; |
| 732 |
} |
| 733 |
specval = strdup(p); |
| 734 |
assert(specval); |
| 735 |
strlwr(specval); |
| 736 |
if (strstr(specval, ".ttf") || |
| 737 |
strstr(specval, ".ttc") || |
| 738 |
strstr(specval, ".otf") || |
| 739 |
strstr(specval, ".dfont")) |
| 740 |
{ |
| 741 |
spec_ptr = specval; |
| 742 |
inside_quotes = FALSE; |
| 743 |
while (*p) |
| 744 |
{ |
| 745 |
if (*p == '\"') |
| 746 |
inside_quotes = !inside_quotes; |
| 747 |
else |
| 748 |
{ |
| 749 |
if ((!inside_quotes) && (*p == ' ')) |
| 750 |
*spec_ptr++ = '\t'; |
| 751 |
else |
| 752 |
*spec_ptr++ = *p; |
| 753 |
} |
| 754 |
p++; |
| 755 |
} |
| 756 |
*spec_ptr = '\0'; |
| 757 |
parse_otf_map_line(specval); |
| 758 |
} |
| 759 |
else |
| 760 |
{ |
| 761 |
specinfo = NULL; |
| 762 |
downloadinfo = NULL; |
| 763 |
downbuf[0] = 0; |
| 764 |
specbuf[0] = 0; |
| 765 |
while (*p) { |
| 766 |
encoding_p = false; |
| 767 |
while (*p && *p <= ' ') |
| 768 |
p++; |
| 769 |
if (*p) { |
| 770 |
if (*p == '"') { /* PostScript instructions? */ |
| 771 |
if (specinfo) { |
| 772 |
strcat(specbuf, specinfo); |
| 773 |
strcat(specbuf, " "); |
| 774 |
} |
| 775 |
specinfo = p + 1; |
| 776 |
|
| 777 |
} else if (*p == '<') { /* Header to download? */ |
| 778 |
/* If had previous downloadinfo, save it. */ |
| 779 |
if (downloadinfo) { |
| 780 |
strcat(downbuf, downloadinfo); |
| 781 |
strcat(downbuf, " "); |
| 782 |
downloadinfo = NULL; |
| 783 |
} |
| 784 |
if (p[1] == '<') { /* << means always full download */ |
| 785 |
p++; |
| 786 |
nopartial_p = true; |
| 787 |
} else if (p[1] == '[') { /* <[ means an encoding */ |
| 788 |
p++; |
| 789 |
encoding_p = true; |
| 790 |
} |
| 791 |
p++; |
| 792 |
/* skip whitespace after < */ |
| 793 |
while (*p && *p <= ' ') |
| 794 |
p++; |
| 795 |
/* save start of header name */ |
| 796 |
hdr_name = p; |
| 797 |
} else if (TeXname) /* second regular word on line? */ |
| 798 |
PSname = p; |
| 799 |
|
| 800 |
else /* first regular word? */ |
| 801 |
TeXname = p; |
| 802 |
|
| 803 |
if (*p == '"') { |
| 804 |
p++; /* find end of "..." word */ |
| 805 |
while (*p != '"' && *p) |
| 806 |
p++; |
| 807 |
} else |
| 808 |
while (*p > ' ') /* find end of anything else */ |
| 809 |
p++; |
| 810 |
if (*p) |
| 811 |
*p++ = 0; |
| 812 |
|
| 813 |
/* If we had a header we were downloading, figure |
| 814 |
out what to do; couldn't do this above since we |
| 815 |
want to check the suffix. */ |
| 816 |
if (hdr_name) { |
| 817 |
const char *suffix = find_suffix (hdr_name); |
| 818 |
if (encoding_p || STREQ (suffix, "enc")) { |
| 819 |
/* (SPQR) if it is a reencoding, pass on to |
| 820 |
FontPart, and download as usual */ |
| 821 |
Vectfile = downloadinfo = hdr_name; |
| 822 |
} else if (nopartial_p) { |
| 823 |
downloadinfo = hdr_name; |
| 824 |
} else if (FILESTRCASEEQ (suffix, "pfa") |
| 825 |
|| FILESTRCASEEQ (suffix, "pfb") |
| 826 |
|| STREQ (suffix, "PFA") |
| 827 |
|| STREQ (suffix, "PFB")) { |
| 828 |
Fontfile = hdr_name; |
| 829 |
} else { |
| 830 |
downloadinfo = hdr_name; |
| 831 |
} |
| 832 |
hdr_name = NULL; |
| 833 |
} |
| 834 |
} |
| 835 |
} |
| 836 |
if (specinfo) |
| 837 |
strcat(specbuf, specinfo); |
| 838 |
if (downloadinfo) |
| 839 |
strcat(downbuf, downloadinfo); |
| 840 |
slen = strlen(downbuf) - 1; |
| 841 |
if (slen > 0 && downbuf[slen] == ' ') { |
| 842 |
downbuf[slen] = 0; |
| 843 |
} |
| 844 |
nextstring = p + 1; |
| 845 |
if (TeXname) { |
| 846 |
TeXname = newstring(TeXname); |
| 847 |
PSname = newstring(PSname); |
| 848 |
Vectfile = newstring(Vectfile); |
| 849 |
Fontfile = newstring(Fontfile); |
| 850 |
specinfo = newstring(specbuf); |
| 851 |
downloadinfo = newstring(downbuf); |
| 852 |
add_entry_spec(TeXname, PSname, Fontfile, Vectfile, |
| 853 |
specinfo, downloadinfo, !nopartial_p, 0, 0, repl); |
| 854 |
} |
| 855 |
} |
| 856 |
free(specval); |
| 857 |
} |
| 858 |
else |
| 859 |
{ |
| 860 |
spec_name = KeyTab[mapfile_key].Entry; |
| 861 |
ll = strlen(spec_name); |
| 862 |
if (strncmp(p, spec_name, ll) == 0) |
| 863 |
{ |
| 864 |
boolean repl = 1; |
| 865 |
p += ll; |
| 866 |
if ((*p == ':') || (*p == '=')) |
| 867 |
p++; |
| 868 |
if ((*p == ' ') || (*p == '\t')) |
| 869 |
p++; |
| 870 |
if (*p == '+') { |
| 871 |
repl = 0; |
| 872 |
p++; |
| 873 |
} |
| 874 |
getpsinfo_spec(p, repl); |
| 875 |
} |
| 876 |
} |
| 877 |
break; |
| 878 |
case 'g': |
| 879 |
/* "g2umapline=Acircle,24B6" */ |
| 880 |
/* "g2umapline=FFIsmall,0066 0066 0069" */ |
| 881 |
spec_name = KeyTab[g2umapline_key].Entry; |
| 882 |
ll = strlen(spec_name); |
| 883 |
if (strncmp(p, spec_name, ll) == 0) |
| 884 |
{ |
| 885 |
static char map_line[ENC_BUF_SIZE + 1]; |
| 886 |
|
| 887 |
p += ll; |
| 888 |
if ((*p == ':') || (*p == '=')) |
| 889 |
p++; |
| 890 |
if ((*p == ' ') || (*p == '\t')) |
| 891 |
p++; |
| 892 |
|
| 893 |
strcpy(map_line, "load_touni({['"); |
| 894 |
|
| 895 |
spec_ptr = spec_buf = strdup(p); |
| 896 |
assert(spec_buf); |
| 897 |
spec_buf_end = spec_buf + strlen(spec_buf); |
| 898 |
spec_ptr = strtok(spec_ptr, ","); |
| 899 |
if (spec_ptr) |
| 900 |
{ |
| 901 |
strncat(map_line, spec_ptr, ENC_BUF_SIZE - strlen(map_line) - 20); |
| 902 |
map_line[ENC_BUF_SIZE] = '\0'; |
| 903 |
pp = map_line + strlen(map_line); |
| 904 |
while (*(--pp) == ' ') |
| 905 |
*pp = '\0'; /* strip trailing spaces */ |
| 906 |
strcat(map_line, "'] = {"); |
| 907 |
|
| 908 |
spec_ptr += strlen(spec_ptr) + 1; |
| 909 |
while (spec_ptr && (spec_ptr <= spec_buf_end)) |
| 910 |
{ |
| 911 |
spec_ptr = strtok(spec_ptr, " "); |
| 912 |
if (spec_ptr) |
| 913 |
{ |
| 914 |
strcat(map_line, "0x"); |
| 915 |
strncat(map_line, spec_ptr, ENC_BUF_SIZE - strlen(map_line) - 20); |
| 916 |
map_line[ENC_BUF_SIZE] = '\0'; |
| 917 |
strcat(map_line, ", "); |
| 918 |
spec_ptr += strlen(spec_ptr) + 1; |
| 919 |
if (spec_ptr >= spec_buf_end) |
| 920 |
break; |
| 921 |
} |
| 922 |
} |
| 923 |
strcat(map_line, "}}, true, \'\')"); |
| 924 |
if (luaL_dostring(L, map_line)) |
| 925 |
{ |
| 926 |
PRINTF_PR("Error: Lua script %.500s execution error: %.500s.\n", map_line, lua_tostring(L, -1)); |
| 927 |
lua_pop(L, 1); |
| 928 |
} |
| 929 |
} |
| 930 |
else |
| 931 |
{ |
| 932 |
PRINTF_PR("Error: special %s format not recognized: %.500s\n", spec_name, p); |
| 933 |
} |
| 934 |
free(spec_buf); |
| 935 |
} |
| 936 |
else |
| 937 |
{ |
| 938 |
/* "g2umapfile=texglyphlist.lua" */ |
| 939 |
/* "g2umapfile=pfb:lmmi8/lmmi8.lua" */ |
| 940 |
spec_name = KeyTab[g2umapfile_key].Entry; |
| 941 |
ll = strlen(spec_name); |
| 942 |
if (strncmp(p, spec_name, ll) == 0) |
| 943 |
{ |
| 944 |
char* pfb_name; |
| 945 |
p += ll; |
| 946 |
if ((*p == ':') || (*p == '=')) |
| 947 |
p++; |
| 948 |
if ((*p == ' ') || (*p == '\t')) |
| 949 |
p++; |
| 950 |
pfb_name = strchr(p, ':'); |
| 951 |
if (pfb_name) |
| 952 |
{ |
| 953 |
if (strncmp(p, "pfb:", 4)) |
| 954 |
{ |
| 955 |
PRINTF_PR("Error: special %s prefix format not recognized: %.500s\n", spec_name, p); |
| 956 |
} |
| 957 |
pfb_name++; |
| 958 |
p = pfb_name; |
| 959 |
while (*p && (*p != '/')) |
| 960 |
p++; |
| 961 |
if (*p) |
| 962 |
*p++ = '\0'; |
| 963 |
} |
| 964 |
load_touni_file(p, TRUE, pfb_name, 2); |
| 965 |
} |
| 966 |
} |
| 967 |
break; |
| 968 |
case 'v': |
| 969 |
spec_ptr = spec_buf = strdup(p); |
| 970 |
assert(spec_buf); |
| 971 |
spec_ptr = strtok(spec_ptr, ":"); |
| 972 |
if (spec_ptr && (strcmp(spec_ptr, "vtex") == 0)) |
| 973 |
{ |
| 974 |
spec_ptr += strlen(spec_ptr) + 1; |
| 975 |
spec_ptr = strtok(spec_ptr, "."); |
| 976 |
if (spec_ptr && (strcmp(spec_ptr, "settings") == 0)) |
| 977 |
{ |
| 978 |
spec_ptr += strlen(spec_ptr) + 1; |
| 979 |
spec_ptr = strtok(spec_ptr, "."); |
| 980 |
if (spec_ptr && (strcmp(spec_ptr, "xdvipsk") == 0)) |
| 981 |
{ |
| 982 |
spec_ptr += strlen(spec_ptr) + 1; |
| 983 |
|
| 984 |
key_ptr = GetKeyVal(spec_ptr, &ii); |
| 985 |
if (key_ptr) |
| 986 |
{ |
| 987 |
key_ptr = key_buf = strdup((ii >= 0) ? ValStr : ""); |
| 988 |
assert(key_buf); |
| 989 |
switch (ii) |
| 990 |
{ |
| 991 |
/* "vtex:settings.xdvipsk.opentype={enc=gid,...}" */ |
| 992 |
case opentype_key: |
| 993 |
spec_name = KeyTab[ii].Entry; |
| 994 |
while ((key_ptr = GetKeyVal(key_ptr, &jj)) != NULL) |
| 995 |
switch (jj) |
| 996 |
{ |
| 997 |
case enc_key: |
| 998 |
if (strcmp(ValStr, "gid") == 0) |
| 999 |
{ |
| 1000 |
Otf_Enc_Type = enc_gid; |
| 1001 |
noToUnicode = TRUE; |
| 1002 |
} |
| 1003 |
else |
| 1004 |
{ |
| 1005 |
PRINTF_PR("Unknown keyword `%s' value `%.500s' in \\special{vtex:settings.xdvipsk.%s={...}} will be ignored\n", KeyStr, ValStr, spec_name); |
| 1006 |
} |
| 1007 |
break; |
| 1008 |
default: |
| 1009 |
PRINTF_PR("Unknown keyword `%.500s' in \\special{vtex:settings.xdvipsk.%s={...}} will be ignored\n", KeyStr, spec_name); |
| 1010 |
break; |
| 1011 |
} |
| 1012 |
break; |
| 1013 |
default: |
| 1014 |
PRINTF_PR("Unknown keyword `%.500s' in \\special{vtex:settings.xdvipsk...} will be ignored\n", KeyStr); |
| 1015 |
break; |
| 1016 |
} |
| 1017 |
free(key_buf); |
| 1018 |
} |
| 1019 |
else |
| 1020 |
{ |
| 1021 |
PRINTF_PR("%s", "No keyword in \\special{vtex:settings.xdvipsk...}\n"); |
| 1022 |
} |
| 1023 |
} |
| 1024 |
else |
| 1025 |
spec_ptr = NULL; |
| 1026 |
} |
| 1027 |
else |
| 1028 |
spec_ptr = NULL; |
| 1029 |
} |
| 1030 |
else |
| 1031 |
spec_ptr = NULL; |
| 1032 |
free(spec_buf); |
| 1033 |
break; |
| 1034 |
default: |
| 1035 |
break; |
| 1036 |
} |
| 1037 |
} |
| 1038 |
|
| 1039 |
p = spec_buf = strdup(p); /* GetKey() alters the string */ |
| 1040 |
assert(spec_buf); |
| 1041 |
#endif /* XDVIPSK */ |
| 1042 |
usesspecial = 1; /* now the special prolog will be sent */ |
| 1043 |
#ifndef XDVIPSK |
| 1044 |
if (scanning && *p != '"' && (p=GetKeyVal(p, &j)) != NULL && j==0 |
| 1045 |
#else /* XDVIPSK */ |
| 1046 |
if (scanning && *p != '"' && (p=GetKeyVal(p, &j)) != NULL && j == psfile_key |
| 1047 |
#endif /* XDVIPSK */ |
| 1048 |
&& *ValStr != '`') /* Don't bother to scan compressed files. */ |
| 1049 |
scanfontcomments(ValStr); |
| 1050 |
#ifdef XDVIPSK |
| 1051 |
free(spec_buf); |
| 1052 |
#endif /* XDVIPSK */ |
| 1053 |
} |
| 1054 |
|
| 1055 |
/* Return 1 if S is readable along figpath, 0 if not. */ |
| 1056 |
static int |
| 1057 |
maccess(char *s) |
| 1058 |
{ |
| 1059 |
FILE *f = search(figpath, s, "r"); |
| 1060 |
int found = (f != 0); |
| 1061 |
if (found) |
| 1062 |
(*close_file) (f); |
| 1063 |
return found; |
| 1064 |
} |
| 1065 |
|
| 1066 |
const char *tasks[] = { 0, "iff2ps", "tek2ps" }; |
| 1067 |
|
| 1068 |
#define PSFILESIZ 511 |
| 1069 |
static char psfile[PSFILESIZ]; |
| 1070 |
|
| 1071 |
void |
| 1072 |
dospecial(integer numbytes) |
| 1073 |
{ |
| 1074 |
register char *p = nextstring; |
| 1075 |
register int i = 0; |
| 1076 |
int j, systemtype = 0; |
| 1077 |
register const char *q; |
| 1078 |
Boolean psfilewanted = 1; |
| 1079 |
const char *task = 0; |
| 1080 |
char cmdbuf[111]; |
| 1081 |
#ifdef XDVIPSK |
| 1082 |
size_t l; |
| 1083 |
#endif /* XDVIPSK */ |
| 1084 |
#ifdef HPS |
| 1085 |
if (HPS_FLAG && PAGEUS_INTERUPPTUS) { |
| 1086 |
HREF_COUNT--; |
| 1087 |
start_new_box(); |
| 1088 |
PAGEUS_INTERUPPTUS = 0; |
| 1089 |
} |
| 1090 |
if (HPS_FLAG && NEED_NEW_BOX) { |
| 1091 |
vertical_in_hps(); |
| 1092 |
NEED_NEW_BOX = 0; |
| 1093 |
} |
| 1094 |
#endif |
| 1095 |
if (nextstring + numbytes > maxstring) |
| 1096 |
error("! out of string space in dospecial"); |
| 1097 |
for (i=numbytes; i>0; i--) |
| 1098 |
#ifdef VMCMS /* IBM: VM/CMS */ |
| 1099 |
*p++ = ascii2ebcdic[(char)dvibyte()]; |
| 1100 |
#else |
| 1101 |
#ifdef MVSXA /* IBM: MVS/XA */ |
| 1102 |
*p++ = ascii2ebcdic[(char)dvibyte()]; |
| 1103 |
#else |
| 1104 |
*p++ = (char)dvibyte(); |
| 1105 |
#endif /* IBM: VM/CMS */ |
| 1106 |
#endif |
| 1107 |
while (p[-1] <= ' ' && p > nextstring) |
| 1108 |
p--; /* trim trailing blanks */ |
| 1109 |
if (p==nextstring) return; /* all blank is no-op */ |
| 1110 |
*p = 0; |
| 1111 |
p = nextstring; |
| 1112 |
while (*p <= ' ') |
| 1113 |
p++; |
| 1114 |
#ifdef DEBUG |
| 1115 |
if (dd(D_SPECIAL)) |
| 1116 |
fprintf_str(stderr, "Processing special: %s\n", p); |
| 1117 |
#endif |
| 1118 |
#ifdef XDVIPSK |
| 1119 |
l = run_lua_specials(L, "scan_specials_callback", p, lua_scan_specials); |
| 1120 |
if (l == 0) return; |
| 1121 |
|
| 1122 |
if (VTEX_SPEC_MODE) { |
| 1123 |
if ((strncmp(p, "mt:", 3) == 0) || (strncmp(p, "vtex:", 5) == 0) || |
| 1124 |
(strncmp(p, "MC:", 3) == 0) || (strncmp(p, "BMC:", 4) == 0) || |
| 1125 |
(strncmp(p, "EMC:", 4) == 0)) { /* VTeX private specials ignored */ |
| 1126 |
return; |
| 1127 |
} |
| 1128 |
} |
| 1129 |
#endif /* XDVIPSK */ |
| 1130 |
switch (*p) { |
| 1131 |
case 'o': |
| 1132 |
if (strncmp(p, "om:", 3)==0) { /* Omega specials ignored */ |
| 1133 |
return; |
| 1134 |
} |
| 1135 |
break; |
| 1136 |
case 'e': |
| 1137 |
if (strncmp(p, "em:", 3)==0) { /* emTeX specials in emspecial.c */ |
| 1138 |
emspecial(p); |
| 1139 |
return; |
| 1140 |
} |
| 1141 |
|
| 1142 |
/* added for dvi2ps special */ |
| 1143 |
if (strncmp(p, "epsfile=", 8)==0) { /* epsf.sty for dvi2ps-j */ |
| 1144 |
float llx, lly, urx, ury; |
| 1145 |
unsigned psfilelen = 0; |
| 1146 |
|
| 1147 |
p += 8; |
| 1148 |
while (*p && !isspace((unsigned char)*p)) { |
| 1149 |
if (psfilelen < PSFILESIZ - 1) { |
| 1150 |
psfile[psfilelen] = *p; |
| 1151 |
psfilelen++; |
| 1152 |
p++; |
| 1153 |
} else { |
| 1154 |
psfile[psfilelen] = 0; /* should not strictly be necessary */ |
| 1155 |
sprintf(errbuf, |
| 1156 |
"! epsfile=%.20s... argument longer than %d characters", |
| 1157 |
psfile, PSFILESIZ); |
| 1158 |
error(errbuf); |
| 1159 |
} |
| 1160 |
} |
| 1161 |
if (psfilelen == 0) { |
| 1162 |
error ("! epsfile= argument empty"); |
| 1163 |
} |
| 1164 |
psfile[psfilelen] = 0; |
| 1165 |
p += strlen(psfile); |
| 1166 |
fgetboundingbox(psfile, &llx, &lly, &urx, &ury); |
| 1167 |
hvpos(); |
| 1168 |
cmdout("@beginspecial"); |
| 1169 |
floatroundout(llx); |
| 1170 |
cmdout("@llx"); |
| 1171 |
floatroundout(lly); |
| 1172 |
cmdout("@lly"); |
| 1173 |
floatroundout(urx); |
| 1174 |
cmdout("@urx"); |
| 1175 |
floatroundout(ury); |
| 1176 |
cmdout("@ury"); |
| 1177 |
|
| 1178 |
while ((p = GetKeyVal(p, &j))) { |
| 1179 |
switch (j) { |
| 1180 |
#ifndef XDVIPSK |
| 1181 |
case 3: /* hsize */ |
| 1182 |
#else /* XDVIPSK */ |
| 1183 |
case hsize_key: |
| 1184 |
#endif /* XDVIPSK */ |
| 1185 |
floatroundout(ValNum*10); |
| 1186 |
cmdout("@rwi"); |
| 1187 |
break; |
| 1188 |
#ifndef XDVIPSK |
| 1189 |
case 4: /* vsize */ |
| 1190 |
#else /* XDVIPSK */ |
| 1191 |
case vsize_key: |
| 1192 |
#endif /* XDVIPSK */ |
| 1193 |
floatroundout(ValNum*10); |
| 1194 |
cmdout("@rhi"); |
| 1195 |
break; |
| 1196 |
#ifndef XDVIPSK |
| 1197 |
case 7: /* hscale */ |
| 1198 |
#else /* XDVIPSK */ |
| 1199 |
case hscale_key: |
| 1200 |
#endif /* XDVIPSK */ |
| 1201 |
floatroundout((urx-llx)*ValNum*10); |
| 1202 |
cmdout("@rwi"); |
| 1203 |
break; |
| 1204 |
#ifndef XDVIPSK |
| 1205 |
case 8: /* vscale */ |
| 1206 |
#else /* XDVIPSK */ |
| 1207 |
case vscale_key: |
| 1208 |
#endif /* XDVIPSK */ |
| 1209 |
floatroundout((ury-lly)*ValNum*10); |
| 1210 |
cmdout("@rhi"); |
| 1211 |
break; |
| 1212 |
default: |
| 1213 |
sprintf(errbuf, "Unknown keyword `%.500s' in \\special{epsfile=%.500s...} will be ignored\n", |
| 1214 |
KeyStr, psfile); |
| 1215 |
specerror(errbuf); |
| 1216 |
break; |
| 1217 |
} |
| 1218 |
} |
| 1219 |
cmdout("@setspecial"); |
| 1220 |
numout((integer)0); |
| 1221 |
cmdout("lly"); |
| 1222 |
cmdout("ury"); |
| 1223 |
cmdout("sub"); |
| 1224 |
cmdout("TR"); |
| 1225 |
figcopyfile(psfile, 0); |
| 1226 |
cmdout("\n@endspecial"); |
| 1227 |
return; |
| 1228 |
} |
| 1229 |
/* end addition */ |
| 1230 |
break; |
| 1231 |
case 'p': |
| 1232 |
if (strncmp(p, "pos:", 4)==0) return; /* positional specials */ |
| 1233 |
if (strncmp(p, "ps:", 3)==0) { |
| 1234 |
psflush(); /* now anything can happen. */ |
| 1235 |
if (p[3]==':') { |
| 1236 |
if (strncmp(p+4, "[nobreak]", 9) == 0) { |
| 1237 |
hvpos(); |
| 1238 |
outputstring(&p[13]); |
| 1239 |
} else if (strncmp(p+4, "[begin]", 7) == 0) { |
| 1240 |
hvpos(); |
| 1241 |
trytobreakout(&p[11]); |
| 1242 |
} else if (strncmp(p+4, "[end]", 5) == 0) |
| 1243 |
trytobreakout(&p[9]); |
| 1244 |
else trytobreakout(&p[4]); |
| 1245 |
} else if (strncmp(p+3, " plotfile ", 10) == 0) { |
| 1246 |
char *sfp; |
| 1247 |
hvpos(); |
| 1248 |
p += 13; |
| 1249 |
/* |
| 1250 |
* Fixed to allow popen input for plotfile |
| 1251 |
* TJD 10/20/91 |
| 1252 |
*/ |
| 1253 |
while (*p == ' ') p++; |
| 1254 |
if (*p == '"') { |
| 1255 |
p++; |
| 1256 |
for (sfp = p; *sfp && *sfp != '"'; sfp++); |
| 1257 |
} else { |
| 1258 |
for (sfp = p; *sfp && *sfp != ' '; sfp++); |
| 1259 |
} |
| 1260 |
*sfp = '\0'; |
| 1261 |
if (*p == '`') |
| 1262 |
figcopyfile(p+1, 1); |
| 1263 |
else |
| 1264 |
figcopyfile (p, 0); |
| 1265 |
/* End TJD changes */ |
| 1266 |
} else { |
| 1267 |
hvpos(); |
| 1268 |
trytobreakout(&p[3]); |
| 1269 |
psflush(); |
| 1270 |
hvpos(); |
| 1271 |
} |
| 1272 |
return; |
| 1273 |
} |
| 1274 |
if (strncmp(p, "papersize", 9) == 0) |
| 1275 |
return; |
| 1276 |
#ifdef TPIC |
| 1277 |
if (strncmp(p, "pn ", 3) == 0) {setPenSize(p+2); return;} |
| 1278 |
if (strncmp(p, "pa ", 3) == 0) {addPath(p+2); return;} |
| 1279 |
#endif |
| 1280 |
|
| 1281 |
/* added for jdvi2kps special */ |
| 1282 |
if (strncmp(p, "postscriptbox", 13)==0) { /* epsbox.sty for jdvi2kps */ |
| 1283 |
float w, h; |
| 1284 |
float llx, lly, urx, ury; |
| 1285 |
if (strlen(p)-13-6 >= PSFILESIZ) { /* -6 for the braces */ |
| 1286 |
/* We're not allowing as long a name as we could, since however |
| 1287 |
many characters the two {%fpt} arguments consume is not |
| 1288 |
taken into account. But parsing it all so we know the |
| 1289 |
character length is too much work for this obscure special. */ |
| 1290 |
sprintf(errbuf, |
| 1291 |
"! postscriptbox{} arguments longer than %d characters", |
| 1292 |
PSFILESIZ); |
| 1293 |
error(errbuf); |
| 1294 |
} |
| 1295 |
if (sscanf(p+13, "{%fpt}{%fpt}{%[^}]}", &w, &h, psfile) != 3) |
| 1296 |
break; |
| 1297 |
fgetboundingbox(psfile, &llx, &lly, &urx, &ury); |
| 1298 |
hvpos(); |
| 1299 |
cmdout("@beginspecial"); |
| 1300 |
floatroundout(llx); |
| 1301 |
cmdout("@llx"); |
| 1302 |
floatroundout(lly); |
| 1303 |
cmdout("@lly"); |
| 1304 |
floatroundout(urx); |
| 1305 |
cmdout("@urx"); |
| 1306 |
floatroundout(ury); |
| 1307 |
cmdout("@ury"); |
| 1308 |
floatroundout(w*10*72/72.27); |
| 1309 |
cmdout("@rwi"); |
| 1310 |
floatroundout(h*10*72/72.27); |
| 1311 |
cmdout("@rhi"); |
| 1312 |
cmdout("@setspecial"); |
| 1313 |
figcopyfile(psfile, 0); |
| 1314 |
cmdout("\n@endspecial"); |
| 1315 |
return; |
| 1316 |
} |
| 1317 |
/* end addition */ |
| 1318 |
break; |
| 1319 |
case 'l': |
| 1320 |
if (strncmp(p, "landscape", 9)==0) return; |
| 1321 |
break; |
| 1322 |
case '!': |
| 1323 |
return; |
| 1324 |
case 'h': |
| 1325 |
if (strncmp(p, "header", 6)==0) return; |
| 1326 |
#ifdef HPS |
| 1327 |
if (strncmp(p, "html:", 5)==0) { |
| 1328 |
if (! HPS_FLAG) return; |
| 1329 |
p += 5; |
| 1330 |
while (isspace((unsigned char)*p)) |
| 1331 |
p++; |
| 1332 |
if (*p == '<') { |
| 1333 |
char *sp = p; |
| 1334 |
char *str; |
| 1335 |
int ii=0, len, lower_len; |
| 1336 |
|
| 1337 |
while ((*p) && (*p != '>')) { |
| 1338 |
ii++; |
| 1339 |
p++; |
| 1340 |
} |
| 1341 |
str = (char *)mymalloc(ii+2); |
| 1342 |
strncpy(str,sp+1,ii-1); |
| 1343 |
str[ii-1] = 0;len=strlen(str); |
| 1344 |
if(len>6) lower_len=6; else lower_len=len; |
| 1345 |
for(ii=0;ii<lower_len;ii++) str[ii]=tolower((unsigned char)str[ii]); |
| 1346 |
do_html(str); |
| 1347 |
free(str); |
| 1348 |
} else |
| 1349 |
#ifdef KPATHSEA |
| 1350 |
if (!kpse_tex_hush ("special")) |
| 1351 |
#endif |
| 1352 |
{ |
| 1353 |
|
| 1354 |
sprintf(errbuf,"Error in html special\n"); |
| 1355 |
error(errbuf); |
| 1356 |
return; |
| 1357 |
} |
| 1358 |
return; |
| 1359 |
} |
| 1360 |
#else |
| 1361 |
if (strncmp(p, "html:", 5)==0) return; |
| 1362 |
#endif |
| 1363 |
case 'w': |
| 1364 |
case 'W': |
| 1365 |
if (strncmp(p+1, "arning", 6) == 0) { |
| 1366 |
static int maxwarns = 50; |
| 1367 |
if (maxwarns > 0) { |
| 1368 |
error(p); |
| 1369 |
maxwarns--; |
| 1370 |
} else if (maxwarns == 0) { |
| 1371 |
error(". . . rest of warnings suppressed"); |
| 1372 |
maxwarns--; |
| 1373 |
} |
| 1374 |
return; |
| 1375 |
} |
| 1376 |
#ifdef TPIC |
| 1377 |
if (strcmp(p, "wh") == 0) {whitenLast(); return;} |
| 1378 |
#endif |
| 1379 |
break; |
| 1380 |
case 'b': |
| 1381 |
if ( strncmp(p, "background", 10) == 0 ) |
| 1382 |
return; /* already handled in prescan */ |
| 1383 |
#ifdef TPIC |
| 1384 |
if (strcmp(p, "bk") == 0) {blackenLast(); return;} |
| 1385 |
#endif |
| 1386 |
break; |
| 1387 |
case 'c': |
| 1388 |
if (strncmp(p, "color", 5) == 0) { |
| 1389 |
p += 5; |
| 1390 |
while ( *p && *p <= ' ' ) p++; |
| 1391 |
if (strncmp(p, "push", 4) == 0 ) { |
| 1392 |
p += 4; |
| 1393 |
while ( *p && *p <= ' ' ) p++; |
| 1394 |
pushcolor(p,1); |
| 1395 |
} else if (strncmp(p, "pop", 3) == 0 ) { |
| 1396 |
popcolor(1); |
| 1397 |
} else { |
| 1398 |
resetcolorstack(p,1); |
| 1399 |
} |
| 1400 |
return; |
| 1401 |
} /* IBM: color - end changes*/ |
| 1402 |
break; |
| 1403 |
case 'f': |
| 1404 |
#ifdef TPIC |
| 1405 |
if (strcmp(p, "fp") == 0) {flushPath(0); return;} |
| 1406 |
#endif |
| 1407 |
break; |
| 1408 |
case 'i': |
| 1409 |
#ifdef TPIC |
| 1410 |
if (strcmp(p, "ip") == 0) {flushPath(1); return;} /* tpic 2.0 */ |
| 1411 |
if (strncmp(p, "ia ", 3) == 0) {arc(p+2, 1); return;} /* tpic 2.0 */ |
| 1412 |
#endif |
| 1413 |
break; |
| 1414 |
case 'd': |
| 1415 |
#ifdef TPIC |
| 1416 |
if (strncmp(p, "da ", 3) == 0) {flushDashed(p+2, 0); return;} |
| 1417 |
if (strncmp(p, "dt ", 3) == 0) {flushDashed(p+2, 1); return;} |
| 1418 |
#endif |
| 1419 |
break; |
| 1420 |
case 's': |
| 1421 |
if (strncmp(p, "src:", 4) == 0) return; /* source specials */ |
| 1422 |
#ifdef TPIC |
| 1423 |
if (strcmp(p, "sp") == 0) {flushSpline(p+2); return;} /* tpic 2.0 */ |
| 1424 |
if (strncmp(p, "sp ", 3) == 0) {flushSpline(p+3); return;} /* tpic 2.0 */ |
| 1425 |
if (strcmp(p, "sh") == 0) {shadeLast(p+2); return;} /* tpic 2.0 */ |
| 1426 |
if (strncmp(p, "sh ", 3) == 0) {shadeLast(p+3); return;} /* tpic 2.0 */ |
| 1427 |
#endif |
| 1428 |
break; |
| 1429 |
case 'a': |
| 1430 |
#ifdef TPIC |
| 1431 |
if (strncmp(p, "ar ", 3) == 0) {arc(p+2, 0); return;} /* tpic 2.0 */ |
| 1432 |
#endif |
| 1433 |
break; |
| 1434 |
case 't': |
| 1435 |
#ifdef TPIC |
| 1436 |
if (strncmp(p, "tx ", 3) == 0) {SetShade(p+3); return;} |
| 1437 |
#endif |
| 1438 |
break; |
| 1439 |
case '"': |
| 1440 |
hvpos(); |
| 1441 |
cmdout("@beginspecial"); |
| 1442 |
cmdout("@setspecial"); |
| 1443 |
trytobreakout(p+1); |
| 1444 |
cmdout("\n@endspecial"); |
| 1445 |
return; |
| 1446 |
break; |
| 1447 |
#ifdef XDVIPSK |
| 1448 |
case 'm': |
| 1449 |
if (strncmp(p, "mapline", 7)==0) return; |
| 1450 |
else if (strncmp(p, "mapfile", 7)==0) return; |
| 1451 |
break; |
| 1452 |
#endif /* XDVIPSK */ |
| 1453 |
default: |
| 1454 |
break; |
| 1455 |
} |
| 1456 |
/* At last we get to the key/value conventions */ |
| 1457 |
psfile[0] = '\0'; |
| 1458 |
hvpos(); |
| 1459 |
cmdout("@beginspecial"); |
| 1460 |
|
| 1461 |
while( (p=GetKeyVal(p,&j)) != NULL ) |
| 1462 |
switch (j) { |
| 1463 |
case -1: /* for compatibility with old conventions, we allow a file name |
| 1464 |
* to be given without the 'psfile=' keyword */ |
| 1465 |
if (!psfile[0] && maccess(KeyStr)==1) { /* yes we can read it */ |
| 1466 |
if (strlen(KeyStr) >= PSFILESIZ) { |
| 1467 |
sprintf(errbuf, |
| 1468 |
"! Bare filename (%.20s...) in \\special longer than %d characters", |
| 1469 |
KeyStr, PSFILESIZ); |
| 1470 |
} |
| 1471 |
strcpy(psfile,KeyStr); |
| 1472 |
} else { |
| 1473 |
if (strlen(KeyStr) < 40) { |
| 1474 |
sprintf(errbuf, |
| 1475 |
"Unknown keyword (%s) in \\special will be ignored", |
| 1476 |
KeyStr); |
| 1477 |
} else { |
| 1478 |
sprintf(errbuf, |
| 1479 |
"Unknown keyword (%.40s...) in \\special will be ignored", |
| 1480 |
KeyStr); |
| 1481 |
} |
| 1482 |
specerror(errbuf); |
| 1483 |
#ifdef XDVIPSK |
| 1484 |
cmdout("@endspecial"); |
| 1485 |
return; |
| 1486 |
#endif /* XDVIPSK */ |
| 1487 |
} |
| 1488 |
break; |
| 1489 |
#ifndef XDVIPSK |
| 1490 |
case 0: case 1: case 2: /* psfile */ |
| 1491 |
#else /* XDVIPSK */ |
| 1492 |
case psfile_key: case ifffile_key: case tekfile_key: |
| 1493 |
#endif /* XDVIPSK */ |
| 1494 |
if (psfile[0]) { |
| 1495 |
sprintf(errbuf, "More than one \\special %s given; %.40s ignored", |
| 1496 |
"psfile", ValStr); |
| 1497 |
specerror(errbuf); |
| 1498 |
#ifdef XDVIPSK |
| 1499 |
cmdout("@endspecial"); |
| 1500 |
return; |
| 1501 |
#endif /* XDVIPSK */ |
| 1502 |
} else { |
| 1503 |
if (strlen(ValStr) >= PSFILESIZ) { |
| 1504 |
sprintf(errbuf, |
| 1505 |
"! PS filename (%.20s...) in \\special longer than %d characters", |
| 1506 |
ValStr, PSFILESIZ); |
| 1507 |
error(errbuf); |
| 1508 |
} |
| 1509 |
strcpy(psfile, ValStr); |
| 1510 |
} |
| 1511 |
task = tasks[j]; |
| 1512 |
break; |
| 1513 |
#ifdef XDVIPSK |
| 1514 |
case mapline_key: |
| 1515 |
case mapfile_key: |
| 1516 |
case g2umapline_key: |
| 1517 |
case g2umapfile_key: |
| 1518 |
case opentype_key: |
| 1519 |
case enc_key: |
| 1520 |
cmdout("@endspecial"); |
| 1521 |
return; |
| 1522 |
break; |
| 1523 |
#endif /* XDVIPSK */ |
| 1524 |
default: /* most keywords are output as PostScript procedure calls */ |
| 1525 |
if (KeyTab[j].Type == Integer) |
| 1526 |
numout((integer)ValInt); |
| 1527 |
else if (KeyTab[j].Type == String) |
| 1528 |
for (q=ValStr; *q; q++) |
| 1529 |
scout(*q); |
| 1530 |
else if (KeyTab[j].Type == None); |
| 1531 |
else { /* Number or Dimension */ |
| 1532 |
ValInt = (integer)(ValNum<0? ValNum-0.5 : ValNum+0.5); |
| 1533 |
if (ValInt-ValNum < 0.001 && ValInt-ValNum > -0.001) |
| 1534 |
numout((integer)ValInt); |
| 1535 |
else { |
| 1536 |
snprintf(cmdbuf, sizeof(cmdbuf), "%f", ValNum); |
| 1537 |
cmdout(cmdbuf); |
| 1538 |
} |
| 1539 |
} |
| 1540 |
snprintf(cmdbuf, sizeof(cmdbuf), "@%s", KeyStr); |
| 1541 |
cmdout(cmdbuf); |
| 1542 |
} |
| 1543 |
|
| 1544 |
cmdout("@setspecial"); |
| 1545 |
|
| 1546 |
if(psfile[0]) { |
| 1547 |
if (task == 0) { |
| 1548 |
systemtype = (psfile[0]=='`'); |
| 1549 |
figcopyfile(psfile+systemtype, systemtype); |
| 1550 |
} else { |
| 1551 |
#ifndef XDVIPSK |
| 1552 |
fprintf (stderr, "dvips: iff2ps and tek2ps are not supported.\n"); |
| 1553 |
#else |
| 1554 |
error("dvips: iff2ps and tek2ps are not supported."); |
| 1555 |
#endif /* XDVIPSK */ |
| 1556 |
} |
| 1557 |
} else if (psfilewanted |
| 1558 |
#ifdef KPATHSEA |
| 1559 |
&& !kpse_tex_hush ("special") |
| 1560 |
#endif |
| 1561 |
) |
| 1562 |
specerror("No \\special psfile was given; figure will be blank"); |
| 1563 |
|
| 1564 |
cmdout("@endspecial"); |
| 1565 |
} |
| 1566 |
|
| 1567 |
/* |
| 1568 |
* Handles specials encountered during bounding box calculations. |
| 1569 |
* Currently we only deal with psfile's or PSfiles and only those |
| 1570 |
* that do not use rotations. |
| 1571 |
*/ |
| 1572 |
static float rbbox[4]; |
| 1573 |
float * |
| 1574 |
bbdospecial(int nbytes) |
| 1575 |
{ |
| 1576 |
char *p = nextstring; |
| 1577 |
int i, j; |
| 1578 |
char seen[NKEYS]; |
| 1579 |
float valseen[NKEYS]; |
| 1580 |
|
| 1581 |
if (nbytes < 0 || nbytes > maxstring - nextstring) { |
| 1582 |
if (nbytes < 0 || nbytes > (INT_MAX - 1000) / 2 ) { |
| 1583 |
error("! Integer overflow in bbdospecial"); |
| 1584 |
#ifndef XDVIPSK |
| 1585 |
exit(1); |
| 1586 |
#else |
| 1587 |
dvips_exit(1); |
| 1588 |
#endif /* XDVIPSK */ |
| 1589 |
} |
| 1590 |
p = nextstring = mymalloc(1000 + 2 * nbytes); |
| 1591 |
maxstring = nextstring + 2 * nbytes + 700; |
| 1592 |
} |
| 1593 |
if (nextstring + nbytes > maxstring) |
| 1594 |
error("! out of string space in bbdospecial"); |
| 1595 |
for (i=nbytes; i>0; i--) |
| 1596 |
#ifdef VMCMS /* IBM: VM/CMS */ |
| 1597 |
*p++ = ascii2ebcdic[(char)dvibyte()]; |
| 1598 |
#else |
| 1599 |
#ifdef MVSXA /* IBM: MVS/XA */ |
| 1600 |
*p++ = ascii2ebcdic[(char)dvibyte()]; |
| 1601 |
#else |
| 1602 |
*p++ = (char)dvibyte(); |
| 1603 |
#endif /* IBM: VM/CMS */ |
| 1604 |
#endif |
| 1605 |
while (p[-1] <= ' ' && p > nextstring) |
| 1606 |
p--; /* trim trailing blanks */ |
| 1607 |
if (p==nextstring) return NULL; /* all blank is no-op */ |
| 1608 |
*p = 0; |
| 1609 |
p = nextstring; |
| 1610 |
while (*p && *p <= ' ') |
| 1611 |
p++; |
| 1612 |
if (strncmp(p, "psfile", 6)==0 || strncmp(p, "PSfile", 6)==0) { |
| 1613 |
float originx = 0, originy = 0, hscale = 1, vscale = 1, |
| 1614 |
hsize = 0, vsize = 0; |
| 1615 |
for (j=0; j<NKEYS; j++) |
| 1616 |
seen[j] = 0; |
| 1617 |
j = 0; |
| 1618 |
while ((p=GetKeyVal(p, &j))) { |
| 1619 |
if (j >= 0 && j < NKEYS && KeyTab[j].Type == Number) { |
| 1620 |
seen[j]++; |
| 1621 |
valseen[j] = ValNum; |
| 1622 |
} |
| 1623 |
} |
| 1624 |
/* |
| 1625 |
* This code mimics what happens in @setspecial. |
| 1626 |
*/ |
| 1627 |
#ifndef XDVIPSK |
| 1628 |
if (seen[3]) |
| 1629 |
hsize = valseen[3]; |
| 1630 |
if (seen[4]) |
| 1631 |
vsize = valseen[4]; |
| 1632 |
if (seen[5]) |
| 1633 |
originx = valseen[5]; |
| 1634 |
if (seen[6]) |
| 1635 |
originy = valseen[6]; |
| 1636 |
if (seen[7]) |
| 1637 |
hscale = valseen[7] / 100.0; |
| 1638 |
if (seen[8]) |
| 1639 |
vscale = valseen[8] / 100.0; |
| 1640 |
if (seen[10] && seen[12]) |
| 1641 |
hsize = valseen[12] - valseen[10]; |
| 1642 |
if (seen[11] && seen[13]) |
| 1643 |
vsize = valseen[13] - valseen[11]; |
| 1644 |
if (seen[14] || seen[15]) { |
| 1645 |
if (seen[14] && seen[15] == 0) { |
| 1646 |
hscale = vscale = valseen[14] / (10.0 * hsize); |
| 1647 |
} else if (seen[15] && seen[14] == 0) { |
| 1648 |
hscale = vscale = valseen[15] / (10.0 * vsize); |
| 1649 |
} else { |
| 1650 |
hscale = valseen[14] / (10.0 * hsize); |
| 1651 |
vscale = valseen[15] / (10.0 * vsize); |
| 1652 |
} |
| 1653 |
#else /* XDVIPSK */ |
| 1654 |
if (seen[hsize_key]) |
| 1655 |
hsize = valseen[hsize_key]; |
| 1656 |
if (seen[vsize_key]) |
| 1657 |
vsize = valseen[vsize_key]; |
| 1658 |
if (seen[hoffset_key]) |
| 1659 |
originx = valseen[hoffset_key]; |
| 1660 |
if (seen[voffset_key]) |
| 1661 |
originy = valseen[voffset_key]; |
| 1662 |
if (seen[hscale_key]) |
| 1663 |
hscale = valseen[hscale_key] / 100.0; |
| 1664 |
if (seen[vscale_key]) |
| 1665 |
vscale = valseen[vscale_key] / 100.0; |
| 1666 |
if (seen[llx_key] && seen[urx_key]) |
| 1667 |
hsize = valseen[urx_key] - valseen[llx_key]; |
| 1668 |
if (seen[lly_key] && seen[ury_key]) |
| 1669 |
vsize = valseen[ury_key] - valseen[lly_key]; |
| 1670 |
if (seen[rwi_key] || seen[rhi_key]) { |
| 1671 |
if (seen[rwi_key] && seen[rhi_key] == 0) { |
| 1672 |
hscale = vscale = valseen[rwi_key] / (10.0 * hsize); |
| 1673 |
} else if (seen[rhi_key] && seen[rwi_key] == 0) { |
| 1674 |
hscale = vscale = valseen[rhi_key] / (10.0 * vsize); |
| 1675 |
} else { |
| 1676 |
hscale = valseen[rwi_key] / (10.0 * hsize); |
| 1677 |
vscale = valseen[rhi_key] / (10.0 * vsize); |
| 1678 |
} |
| 1679 |
#endif /* XDVIPSK */ |
| 1680 |
} |
| 1681 |
/* at this point, the bounding box in PostScript units relative to |
| 1682 |
the current dvi point is |
| 1683 |
originx originy originx+hsize*hscale originy+vsize*vscale |
| 1684 |
We'll let the bbox routine handle the remaining math. |
| 1685 |
*/ |
| 1686 |
rbbox[0] = originx; |
| 1687 |
rbbox[1] = originy; |
| 1688 |
rbbox[2] = originx+hsize*hscale; |
| 1689 |
rbbox[3] = originy+vsize*vscale; |
| 1690 |
return rbbox; |
| 1691 |
} |
| 1692 |
return 0; |
| 1693 |
} |