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 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
|
/* 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"
#ifdef KPATHSEA
#include <kpathsea/c-ctype.h>
#include <kpathsea/c-pathch.h>
#include <kpathsea/c-stat.h>
#include <kpathsea/pathsearch.h>
#include <kpathsea/tex-file.h>
#include <kpathsea/variable.h>
#endif
/*
* 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.
*/
#include "protos.h"
/*
* These are the external variables we use.
*/
extern char *realnameoffile ;
#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 ;
#ifndef KPATHSEA
extern char *tfmpath, *pictpath ;
extern char *pkpath ;
extern char *vfpath ;
extern char *figpath ;
extern char *configpath ;
extern char *headerpath ;
#ifdef SEARCH_SUBDIRECTORIES
extern char *fontsubdirpath ;
#endif
#endif
extern Boolean noenv ;
extern Boolean downloadpspk ;
#ifdef FONTLIB
extern char *flipath, *fliname ;
#endif
extern char *paperfmt ;
extern char *nextstring ;
extern char *maxstring ;
extern char *warningmsg ;
extern Boolean disablecomments ;
extern Boolean compressed ;
extern Boolean partialdownload ;
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 double mag ;
extern Boolean sepfiles ;
extern int actualdpi ;
extern int vactualdpi ;
extern int maxdrift ;
extern int vmaxdrift ;
extern char *printer ;
extern char *mfmode, *mflandmode ;
extern int mfmode_option;
extern int oname_option;
extern Boolean sendcontrolD ;
#ifdef SHIFTLOWCHARS
extern Boolean shiftlowchars ;
#endif
extern unsigned lastresortsizes[] ;
extern integer hoff, voff ;
extern struct papsiz *papsizes ;
extern Boolean secure ;
extern integer hpapersize, vpapersize ;
extern int landscape ;
/*
* To maintain a list of document fonts, we use the following
* pointer.
*/
struct header_list *ps_fonts_used ;
/*
* Our hash routine.
*/
int
hash P1C(char *, s)
{
int h = 12 ;
while (*s != 0)
h = (h + h + *s++) % RESHASHPRIME ;
return(h) ;
}
/*
* Reverse the hash chains.
*/
void
revpslists P1H(void) {
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 P1H(void) {
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 P1C(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) ;
}
struct resfont *
findPSname P1C(char *, name)
{
register int i ;
register struct resfont *p ;
for (i=0; i<RESHASHPRIME; i++)
for (p=reshash[i]; p; p=p->next) {
if (strcmp(p->PSname, name)==0)
return p;
}
return NULL;
}
/*
* This routine adds an entry.
*/
void
add_entry P6C(char *, TeXname, char *, PSname, char *, Fontfile,
char *, Vectfile, char *, specinfo, char *, 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->Fontfile = Fontfile;
p->Vectfile = Vectfile;
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 P1C(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 ;
/*
* This is not yet the correct way to do things, but it is useful as it
* is so we leave it in. The problem: if resident Times-Roman is
* re-encoded, then it will be downloaded as bitmaps; this is not
* right. The solution will be to introduce two types of `<'
* directives, one that downloads fonts and one that downloads
* short headers that are innocuous.
*/
if (p->Fontfile && downloadpspk) {
#ifdef DEBUG
if (dd(D_FONTS))
(void)fprintf(stderr,"Using PK font %s for <%s>.\n",
curfnt->name, p->PSname) ;
#endif /* DEBUG */
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 ;
curfnt->chardesc[i].flags2 = 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 {
/* if (strstr(q,".pfa")||strstr(q,".pfb")||
strstr(q,".PFA")||strstr(q,".PFB"))
break ;
else */ {
add_header(q) ;
break;
}
}
infont = 0 ;
}
infont = 0 ;
}
i = tfmload(curfnt) ;
if (i < 0)
i = 1 ;
usesPSfonts = 1 ;
return(i) ;
}
#define INLINE_SIZE (2000)
static char was_inline[INLINE_SIZE] ;
static unsigned c_lineno;
void
bad_config P1C(char *, err)
{
fprintf (stderr, "%s:%d:", realnameoffile, c_lineno);
error (err);
fprintf(stderr, " (%s)\n", was_inline) ;
}
#ifndef KPATHSEA
/*
* 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 P2C(char *, who, char *, 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 ;
}
#endif
/*
* 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 P2C(char *, s, int, nullok)
{
char tstr[INLINE_SIZE] ;
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("bad string") ;
return newstring(tstr) ;
}
#ifdef KPATHSEA
/* We use this in `getdefaults' to modify the kpathsea structure for the
paths we read. See kpathsea/tex-file.[ch]. */
#define SET_CLIENT_PATH(filefmt, val) \
kpse_format_info[filefmt].client_path = xstrdup (val)
#endif
/*
* Now we have the getdefaults routine.
*/
char *psmapfile = PSMAPFILE ;
Boolean
getdefaults P1C(char *, s)
{
FILE *deffile ;
char PSname[INLINE_SIZE] ;
register char *p ;
int i, j ;
integer hsiz, vsiz ;
#ifndef KPATHSEA
char *d = configpath ;
#endif
int canaddtopaper = 0 ;
if (printer == NULL) {
if (s) {
strcpy(PSname, s) ;
} else {
#ifdef KPATHSEA
char *dvipsrc = kpse_var_value ("DVIPSRC");
#ifdef WIN32
if (dvipsrc && *dvipsrc) {
/* $DVIPSRC was set by user */
strcpy(PSname, dvipsrc);
}
else
/* No env var, looking into some kind of standard path. */
if (SearchPath(".;%HOME%;c:\\", ".dvipsrc", NULL,
INLINE_SIZE, PSname,
&dvipsrc) == 0) {
/* search failed, we must put something into PSname. */
dvipsrc = kpse_var_expand(DVIPSRC);
if (dvipsrc) {
strcpy(PSname, dvipsrc);
free(dvipsrc);
}
/* Else SearchPath has filled PSname with something */
}
/* remove any redundant path separators. Many configurations
can show up: c:\/.dvipsrc and so on ... */
{
char *p, *q;
for (p = q = PSname; *p && (p - PSname < INLINE_SIZE) ;
p++, q++) {
if (IS_DIR_SEP(*p)) {
*q = DIR_SEP; p++; q++;
while (*p && IS_DIR_SEP(*p)) p++;
}
*q = *p;
}
*q = '\0';
}
#else
if(!dvipsrc) dvipsrc = kpse_var_expand(DVIPSRC) ;
strcpy(PSname, dvipsrc ? dvipsrc : "~/.dvipsrc") ;
if(dvipsrc) free(dvipsrc) ;
#endif /* WIN32 */
#else /* ! KPATHSEA */
#ifndef VMCMS /* IBM: VM/CMS - don't have home directory on VMCMS */
#ifndef MVSXA
d = "~" ;
#endif
#endif /* IBM: VM/CMS */
strcpy(PSname, DVIPSRC) ;
#endif /* KPATHSEA */
}
} else {
#if defined(MSDOS) || defined(OS2)
strcpy(PSname, printer) ;
strcat(PSname, ".cfg") ;
#else
strcpy(PSname, "config.") ;
strcat(PSname, printer) ;
#endif
}
#ifdef KPATHSEA
if ((deffile=search(configpath,PSname,READ))!=NULL) {
#else
if ((deffile=search(d,PSname,READ))!=NULL) {
#endif
#ifdef DEBUG
if (dd (D_CONFIG)) {
fprintf (stderr, "Reading dvips config file `%s':\n", realnameoffile);
}
#endif
c_lineno = 0;
while (fgets(was_inline, INLINE_SIZE, deffile)!=NULL) {
c_lineno++;
#ifdef DEBUG
if (dd (D_CONFIG)) {
fprintf (stderr, "%s:%d:%s", realnameoffile, c_lineno, was_inline);
}
#endif
/*
* We need to get rid of the newline.
*/
for (p=was_inline; *p; p++) ;
if (p > was_inline) *(p-1) = 0 ;
if (was_inline[0] != '@')
canaddtopaper = 0 ;
switch (was_inline[0]) {
/*
* Handling paper size information:
*
* If line is empty, then we clear out the paper size information
* we have so far.
*
* If it is `@+', then we add to the current paper size info.
*
* If it is `name hsize vsize', then we start a new definition.
*/
case '@' :
p = was_inline + 1 ;
while (*p && *p <= ' ') p++ ;
if (*p == 0) {
papsizes = 0 ; /* throw away memory */
} else if (*p == '+') {
if (canaddtopaper == 0)
error(
" @+ in config files must immediately following a @ lines") ;
else {
*(nextstring-1) = '\n' ;/* IBM: VM/CMS - changed 10 to "\n" */
p++ ;
while (*p && *p == ' ') p++ ;
strcpy(nextstring, p) ;
nextstring += strlen(p) + 1 ;
}
} else {
struct papsiz *ps ;
ps = (struct papsiz *)mymalloc((integer)sizeof(struct papsiz)) ;
ps->next = papsizes ;
papsizes = ps ;
ps->name = p ;
while (*p && *p > ' ')
p++ ;
*p++ = 0 ;
ps->name = newstring(ps->name) ;
while (*p && *p <= ' ') p++ ;
handlepapersize(p, &hsiz, &vsiz) ;
ps->xsize = hsiz ;
ps->ysize = vsiz ;
ps->specdat = nextstring++ ;
canaddtopaper = 1 ;
}
break ;
case 'a' :
dopprescan = (was_inline[1] != '0') ;
break ;
case 'b':
#ifdef SHORTINT
if (sscanf(was_inline+1, "%ld", &pagecopies) != 1)
bad_config("missing pagecopies to b") ;
#else
if (sscanf(was_inline+1, "%d", &pagecopies) != 1)
bad_config("missing pagecopies to b") ;
#endif
if (pagecopies < 1 || pagecopies > 1000)
bad_config("pagecopies not between 1 and 1000") ;
break ;
case 'm' :
#ifdef SHORTINT
if (sscanf(was_inline+1, "%ld", &swmem) != 1)
bad_config("missing swmem to m") ;
#else /* ~SHORTINT */
if (sscanf(was_inline+1, "%d", &swmem) != 1)
bad_config("missing swmem to m") ;
#endif /* ~SHORTINT */
swmem += fontmem ; /* grab headers we've seen already */
break ;
case 'M' :
/* If the user specified a -mode, don't replace it. */
if (!mfmode_option)
mfmode = configstring(was_inline+1, 0) ;
mflandmode = 0 ;
{
char *pp ;
for (pp=mfmode; pp && *pp>' '; pp++) ;
if (pp && *pp == ' ') {
*pp++ = 0 ;
while (*pp && *pp <= ' ')
pp++ ;
if (*pp)
mflandmode = pp ;
}
}
break ;
case 'o' :
if (!oname_option) {
struct stat st_buf;
oname = configstring(was_inline+1, 1) ;
if (*oname && oname[strlen(oname)-1] == ':'
|| (stat(oname, &st_buf) == 0 && S_ISCHR(st_buf.st_mode))) {
sendcontrolD = 1 ; /* if we send to a device, *we* are spooler */
#if defined(MSDOS) || defined(OS2)
oname[strlen(oname)-1] = 0 ;
#endif
}
}
break ;
case 'F' :
sendcontrolD = (was_inline[1] != '0') ;
break ;
case 'O' :
p = was_inline + 1 ;
handlepapersize(p, &hoff, &voff) ;
break ;
#ifdef FONTLIB
case 'L' :
{
char tempname[INLINE_SIZE] ;
extern char *fliparse() ;
if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config("missing arg to L") ;
else {
flipath = getpath(fliparse(PSname,tempname), flipath);
fliname = newstring(tempname) ;
}
}
break ;
#endif
case 'T' :
if (sscanf(was_inline+1, "%s", PSname) != 1)
bad_config("missing arg to T") ;
else
#ifdef KPATHSEA
SET_CLIENT_PATH (kpse_tfm_format, PSname);
#else
tfmpath = getpath(PSname, tfmpath) ;
#endif
break ;
case 'P' :
if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config("missing arg to P") ;
else
#ifdef KPATHSEA
SET_CLIENT_PATH (kpse_pk_format, PSname);
#else
pkpath = getpath(PSname, pkpath) ;
#endif
break ;
case 'p' :
p = was_inline + 1 ;
while (*p && *p <= ' ')
p++ ;
if (*p == '+') {
if (sscanf(p+1, "%s", PSname) != 1)
bad_config("missing arg to p") ;
getpsinfo(PSname) ;
} else {
psmapfile = configstring(was_inline+1, 0) ;
}
break ;
case 'v' : case 'V' :
if (sscanf(was_inline+1, "%s", PSname) != 1)
bad_config("missing arg to V") ;
else
#ifdef KPATHSEA
SET_CLIENT_PATH (kpse_vf_format, PSname);
#else
vfpath = getpath(PSname, vfpath) ;
#endif
break ;
case 'S' :
if (sscanf(was_inline+1, "%s", PSname) != 1)
bad_config("missing arg to S") ;
else
#ifdef KPATHSEA
SET_CLIENT_PATH (kpse_pict_format, PSname);
#else
figpath = getpath(PSname, figpath) ;
#endif
break ;
case 's':
safetyenclose = 1 ;
break ;
case 'H' :
if (sscanf(was_inline+1, "%s", PSname) != 1)
bad_config("missing arg to H") ;
else
#ifdef KPATHSEA
SET_CLIENT_PATH (headerpath, PSname);
#else
headerpath = getpath(PSname, headerpath) ;
#endif
break ;
case '%': case ' ' : case '*' : case '#' : case ';' :
case '=' : case 0 : case '\n' :
break ;
case 'r' :
reverse = (was_inline[1] != '0') ;
break ;
/*
* This case is for last resort font scaling; I hate this, but enough
* people have in no uncertain terms demanded it that I'll go ahead and
* add it.
*
* This line must have numbers on it, resolutions, to search for the
* font as a last resort, and then the font will be scaled. These
* resolutions should be in increasing order.
*
* For most machines, just `300' is sufficient here; on the NeXT,
* `300 400' may be more appropriate.
*/
case 'R':
#ifndef KPATHSEA
i = 0 ;
p = was_inline + 1 ;
while (*p) {
while (*p && *p <= ' ')
p++ ;
if ('0' <= *p && *p <= '9') {
j = 0 ;
while ('0' <= *p && *p <= '9')
j = 10 * j + (*p++ - '0') ;
if (i > 0)
if (lastresortsizes[i-1] > j) {
bad_config("last resort sizes (R) must be sorted") ;
}
lastresortsizes[i++] = j ;
} else {
if (*p == 0)
break ;
bad_config("only numbers expected on `R' line") ;
}
}
lastresortsizes[i] = 32000 ;
#else /* KPATHSEA */
for (p = was_inline + 1; *p; p++) {
if (isblank (*p)) {
*p = ':';
}
}
kpse_fallback_resolutions_string = xstrdup (was_inline + 1);
#endif
break ;
case 'D' :
if (sscanf(was_inline+1, "%d", &actualdpi) != 1)
bad_config("missing arg to D") ;
if (actualdpi < 10 || actualdpi > 10000)
bad_config("dpi must be between 10 and 10000") ;
vactualdpi = actualdpi;
break ;
/*
* Execute a command. This can be dangerous, but can also be very useful.
*/
case 'E' :
#ifdef SECURE
error("dvips was compiled with SECURE, which disables E in config") ;
#else
if (secure) {
error("dvips -R option used, which disables E in config") ;
break ;
}
(void)system(was_inline+1) ;
#endif
break ;
case 'K':
removecomments = (was_inline[1] != '0') ;
break ;
case 'U':
nosmallchars = (was_inline[1] != '0') ;
break ;
case 'W':
for (p=was_inline+1; *p && *p <= ' '; p++) ;
if (*p)
warningmsg = newstring(p) ;
else
warningmsg = 0 ;
break ;
case 'X' :
if (sscanf(was_inline+1, "%d", &actualdpi) != 1)
bad_config("missing numeric arg to X") ;
if (actualdpi < 10 || actualdpi > 10000)
bad_config("X arg must be between 10 and 10000") ;
break ;
case 'Y' :
if (sscanf(was_inline+1, "%d", &vactualdpi) != 1)
bad_config("missing numeric arg to Y") ;
if (vactualdpi < 10 || vactualdpi > 10000)
bad_config("Y arg must be between 10 and 10000") ;
break ;
case 'x': case 'y':
if (sscanf(was_inline+1, "%lg", &mag) != 1)
bad_config("missing arg to x or y") ;
overridemag = (was_inline[0] == 'x') ? 1 : -1 ;
break ;
case 'e' :
if (sscanf(was_inline+1, "%d", &maxdrift) != 1)
bad_config("missing arg to e") ;
if (maxdrift < 0) bad_config("bad argument to e") ;
vmaxdrift = maxdrift;
break ;
case 'z' :
secure = (was_inline[1] != '0') ;
break ;
case 'q' : case 'Q' :
quiet = (was_inline[1] != '0') ;
break ;
case 'f' :
filter = (was_inline[1] != '0') ;
if (filter)
oname = "";
/* noenv has already been tested, so no point in setting. */
sendcontrolD = 0;
break ;
#ifdef SHIFTLOWCHARS
case 'G':
shiftlowchars = (was_inline[1] != '0') ;
break ;
#endif
case 'h' :
if (sscanf(was_inline+1, "%s", PSname) != 1)
bad_config("missing arg to h") ;
else (void)add_header(PSname) ;
break ;
case 'i' :
if (sscanf(was_inline+1, "%d", &maxsecsize) != 1)
maxsecsize = 0 ;
sepfiles = 1 ;
break ;
case 'I':
noenv = (was_inline[1] != '0') ;
break ;
case 'N' :
disablecomments = (was_inline[1] != '0') ;
break ;
case 'Z' :
compressed = (was_inline[1] != '0') ;
break ;
case 'j':
partialdownload = (was_inline[1] != '0') ;
break ;
case 't' :
if (sscanf(was_inline+1, "%s", PSname) != 1)
bad_config("missing arg to t") ;
else {
if (strcmp(PSname, "landscape") == 0) {
if (hpapersize || vpapersize)
error(
"both landscape and papersize specified; ignoring landscape") ;
else
landscape = 1 ;
} else
paperfmt = newstring(PSname) ;
}
break ;
default:
bad_config("strange line") ;
}
}
(void)fclose(deffile) ;
} else {
if (printer)
{
char msg[1000];
sprintf (msg, "warning: no config file for `%s'", printer);
error(msg);
return 0;
}
}
return 1;
}
/*
* If a character pointer is passed in, use that name; else, use the
* default (possibly set) name, psfonts.map.
*/
void getpsinfo P1C(char *, name)
{
FILE *deffile ;
register char *p ;
char *specinfo, *downloadinfo ;
char downbuf[500] ;
char specbuf[500] ;
int slen ;
if (name == 0)
name = psmapfile ;
if ((deffile=search(configpath, name, READ))!=NULL) {
while (fgets(was_inline, INLINE_SIZE, deffile)!=NULL) {
p = was_inline ;
if (*p > ' ' && *p != '*' && *p != '#' && *p != ';' && *p != '%') {
char *TeXname = NULL ;
char *PSname = NULL ;
char *Fontfile = NULL;
char *Vectfile = NULL;
char *hdr_name = NULL;
boolean nopartial_p = false;
boolean encoding_p = false;
specinfo = NULL ;
downloadinfo = NULL ;
downbuf[0] = 0 ;
specbuf[0] = 0 ;
while (*p) {
while (*p && *p <= ' ')
p++ ;
if (*p) {
if (*p == '"') { /* PostScript instructions? */
if (specinfo) {
strcat(specbuf, specinfo) ;
strcat(specbuf, " ") ;
}
specinfo = p + 1 ;
} else if (*p == '<') { /* Header to download? */
/* If had previous downloadinfo, save it. */
if (downloadinfo) {
strcat(downbuf, downloadinfo) ;
strcat(downbuf, " ") ;
downloadinfo = NULL;
}
if (p[1] == '<') { /* << means always full download */
p++;
nopartial_p = true;
} else if (p[1] == '[') { /* <[ means an encoding */
p++;
encoding_p = true;
}
p++ ;
/* skip whitespace after < */
while (*p && *p <= ' ')
p++;
/* save start of header name */
hdr_name = p ;
} else if (TeXname) /* second regular word on line? */
PSname = p ;
else /* first regular word? */
TeXname = p ;
if (*p == '"') {
p++ ; /* find end of "..." word */
while (*p != '"' && *p)
p++ ;
} else
while (*p > ' ') /* find end of anything else */
p++ ;
if (*p)
*p++ = 0 ;
/* If we had a header we were downloading, figure
out what to do; couldn't do this above since we
want to check the suffix. */
if (hdr_name) {
char *suffix = find_suffix (hdr_name);
if (encoding_p || STREQ (suffix, "enc")) {
/* (SPQR) if it is a reencoding, pass on to
FontPart, and download as usual */
Vectfile = downloadinfo = hdr_name;
} else if (nopartial_p) {
downloadinfo = hdr_name ;
} else if (FILESTRCASEEQ (suffix, "pfa")
|| FILESTRCASEEQ (suffix, "pfb")
|| STREQ (suffix, "PFA")
|| STREQ (suffix, "PFB")) {
Fontfile = hdr_name;
} else {
downloadinfo = hdr_name;
}
}
}
}
if (specinfo)
strcat(specbuf, specinfo) ;
if (downloadinfo)
strcat(downbuf, downloadinfo) ;
slen = strlen(downbuf) - 1;
if (downbuf[slen] == ' ') {
downbuf[slen] = 0;
}
if (TeXname) {
TeXname = newstring(TeXname) ;
PSname = newstring(PSname) ;
Fontfile = newstring(Fontfile);
Vectfile = newstring(Vectfile);
specinfo = newstring(specbuf) ;
downloadinfo = newstring(downbuf) ;
add_entry(TeXname, PSname, Fontfile, Vectfile,
specinfo, downloadinfo) ;
}
}
}
(void)fclose(deffile) ;
}
checkstrings() ;
}
#ifndef KPATHSEA
/*
* 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 *getenvup P2C(char *, who, char *, what)
{
return getpath(getenv(who), what) ;
}
#endif
#if !defined(KPATHSEA) && defined(SEARCH_SUBDIRECTORIES)
static char *concat3();
#endif
void checkenv P1C(int, which)
{
#ifndef KPATHSEA
if (which) {
tfmpath = getenvup(FONTPATH, tfmpath) ;
vfpath = getenvup("VFFONTS", vfpath) ;
pictpath = getenvup("TEXPICTS", pictpath) ;
figpath = getenvup("TEXINPUTS", figpath) ;
headerpath = getenvup("DVIPSHEADERS", headerpath) ;
if (getenv("TEXPKS"))
pkpath = getenvup("TEXPKS", pkpath) ;
else if (getenv("TEXPACKED"))
pkpath = getenvup("TEXPACKED", pkpath) ;
else if (getenv("PKFONTS"))
pkpath = getenvup("PKFONTS", pkpath) ;
#ifdef SEARCH_SUBDIRECTORIES
else if (getenv(FONTPATH))
pkpath = getenvup(FONTPATH, pkpath) ;
if (getenv ("TEXFONTS_SUBDIR"))
fontsubdirpath = getenvup ("TEXFONTS_SUBDIR", fontsubdirpath);
{
char pathsep[2] ;
char *do_subdir_path();
char *dirs = do_subdir_path (fontsubdirpath);
/* If the paths were in dynamic storage before, that memory is
wasted now. */
pathsep[0] = PATHSEP ;
pathsep[1] = '\0' ;
tfmpath = concat3 (tfmpath, pathsep, dirs);
pkpath = concat3 (pkpath, pathsep, dirs);
}
#endif
} else
configpath = getenvup("TEXCONFIG", configpath) ;
#endif
}
#if !defined(KPATHSEA) && defined(SEARCH_SUBDIRECTORIES)
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#ifdef SYSV
#include <dirent.h>
typedef struct dirent *directory_entry_type;
#else
#include <sys/dir.h>
typedef struct direct *directory_entry_type;
#endif
/* Declare the routine to get the current working directory. */
#ifndef HAVE_GETCWD
extern char *getwd ();
#define getcwd(b, len) ((b) ? getwd (b) : getwd (xmalloc (len)))
#else
#ifdef ANSI
extern char *getcwd (char *, int);
#else
extern char *getcwd ();
#endif /* not ANSI */
#endif /* not HAVE_GETWD */
#if defined(SYSV) || defined(VMS) || defined(MSDOS) || defined(OS2) || defined(ATARIST)
#define MAXPATHLEN (256)
#else /* ~SYSV */
#include <sys/param.h> /* for MAXPATHLEN */
#endif
extern void exit() ;
extern int chdir() ;
/* Memory operations: variants of malloc(3) and realloc(3) that just
give up the ghost when they fail. */
char *
xmalloc P1C(unsigned, size)
{
char *mem = malloc (size);
if (mem == NULL)
{
fprintf (stderr, "! Cannot allocate %u bytes.\n", size);
exit (10);
}
return mem;
}
char *
xrealloc P2C(char *, ptr, unsigned, size)
{
char *mem = realloc (ptr, size);
if (mem == NULL)
{
fprintf (stderr, "! Cannot reallocate %u bytes at %x.\n", size, (int)ptr);
exit (10);
}
return mem;
}
/* Return, in NAME, the next component of PATH, i.e., the characters up
to the next PATHSEP. */
static void
next_component P2C(char *, name, char **, path)
{
unsigned count = 0;
while (**path != 0 && **path != PATHSEP)
{
name[count++] = **path;
(*path)++; /* Move further along, even between calls. */
}
name[count] = 0;
if (**path == PATHSEP)
(*path)++; /* Move past the delimiter. */
}
#ifndef _POSIX_SOURCE
#ifndef S_ISDIR
#define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
#endif
#endif
/* Return true if FN is a directory or a symlink to a directory,
false if not. */
int
is_dir P1C(char *, fn)
{
struct stat stats;
return stat (fn, &stats) == 0 && S_ISDIR (stats.st_mode);
}
static char *
concat3 P3C(char *, s1, char *, s2, char *, s3)
{
char *r = xmalloc (strlen (s1) + strlen (s2) + strlen (s3) + 1);
strcpy (r, s1);
strcat (r, s2);
strcat (r, s3);
return r;
}
/* DIR_LIST is the default list of directories (colon-separated) to
search. We want to add all the subdirectories directly below each of
the directories in the path.
We return the list of directories found. */
char *
do_subdir_path P1C(char *, dir_list)
{
char *cwd;
unsigned len;
char *result = xmalloc ((unsigned)1);
char *temp = dir_list;
char dirsep[2] ;
dirsep[0] = DIRSEP ;
dirsep[1] = '\0' ;
/* Make a copy in writable memory. */
dir_list = xmalloc (strlen (temp) + 1);
strcpy (dir_list, temp);
*result = 0;
/* Unfortunately, we can't look in the environment for the current
directory, because if we are running under a program (let's say
Emacs), the PWD variable might have been set by Emacs' parent
to the current directory at the time Emacs was invoked. This
is not necessarily the same directory the user expects to be
in. So, we must always call getcwd(3) or getwd(3), even though
they are slow and prone to hang in networked installations. */
cwd = getcwd (NULL, MAXPATHLEN + 2);
if (cwd == NULL)
{
perror ("getcwd");
exit (errno);
}
do
{
DIR *dir;
directory_entry_type e;
char dirname[MAXPATHLEN];
next_component (dirname, &dir_list);
/* All the `::'s should be gone by now, but we may as well make
sure `chdir' doesn't crash. */
if (*dirname == 0) continue;
/* By changing directories, we save a bunch of string
concatenations (and make the pathnames the kernel looks up
shorter). */
if (chdir (dirname) != 0) continue;
dir = opendir (".");
if (dir == NULL) continue;
while ((e = readdir (dir)) != NULL)
{
if (is_dir (e->d_name) && strcmp (e->d_name, ".") != 0
&& strcmp (e->d_name, "..") != 0)
{
char *found = concat3 (dirname, dirsep, e->d_name);
result = xrealloc (result, strlen (result) + strlen (found) + 2);
len = strlen (result);
if (len > 0)
{
result[len] = PATHSEP;
result[len + 1] = 0;
}
strcat (result, found);
free (found);
}
}
closedir (dir);
/* Change back to the current directory, in case the path
contains relative directory names. */
if (chdir (cwd) != 0)
{
perror (cwd);
exit (errno);
}
}
while (*dir_list != 0);
return result;
}
#endif /* SEARCH_SUBDIRECTORIES */
|