Debian Codegraph @

texk/xdvipsk/resident.c

raw
1 /* For use with emTeX set FONTPATH to "TEXTFM"
2 */
3 #ifndef FONTPATH
4 #define FONTPATH "TEXFONTS"
5 #endif
6
7 /*
8 * This code reads in and handles the defaults for the program from the
9 * file config.sw. This entire file is a bit kludgy, sorry.
10 */
11 #ifndef XDVIPSK
12 #include "dvips.h" /* The copyright notice in that file is included too! */
13 #else
14 #include "xdvips.h" /* The copyright notice in that file is included too! */
15 #include "glyphmap.h"
16 #ifndef WIN32
17 #define strnicmp strncasecmp
18 #endif
19 #endif /* XDVIPSK */
20 #include "paths.h"
21 #ifdef KPATHSEA
22 #include <kpathsea/c-ctype.h>
23 #include <kpathsea/c-pathch.h>
24 #include <kpathsea/c-stat.h>
25 #include <kpathsea/pathsearch.h>
26 #include <kpathsea/tex-file.h>
27 #include <kpathsea/variable.h>
28 #endif
29 /*
30 * This is the structure definition for resident fonts. We use
31 * a small and simple hash table to handle these. We don't need
32 * a big hash table.
33 */
34 struct resfont *reshash[RESHASHPRIME];
35
36 #ifdef XDVIPSK
37 resfont_ref *reshash_ps[RESHASHPRIME];
38 resfont_ref *reshash_v[RESHASHPRIME];
39 #endif /* XDVIPSK */
40
41 /*
42 * The external declarations:
43 */
44 #include "protos.h"
45
46 /*
47 * To maintain a list of document fonts, we use the following
48 * pointer.
49 */
50 struct header_list *ps_fonts_used;
51 /*
52 * Our hash routine.
53 */
54 unsigned int
55 #ifndef XDVIPSK
56 hash(char *s)
57 #else /* XDVIPSK */
58 hash(const char *s)
59 #endif
60 {
61 unsigned int h = 12;
62
63 while (*s != 0)
64 h = (h + h + (unsigned char)(*s++)) % RESHASHPRIME;
65 return(h);
66 }
67 /*
68 * Reverse the hash chains.
69 */
70 void
71 revpslists(void) {
72 register int i;
73 for (i=0; i<RESHASHPRIME; i++)
74 reshash[i] = (struct resfont *)revlist(reshash[i]);
75 }
76 /*
77 * cleanres() marks all resident fonts as not being yet sent, except
78 * those marked with 2 meaning they were downloaded as part of the
79 * main prolog (not section prolog).
80 */
81 void
82 cleanres(void) {
83 register int i;
84 register struct resfont *p;
85 for (i=0; i<RESHASHPRIME; i++)
86 for (p=reshash[i]; p; p=p->next)
87 if (p->sent == 1)
88 p->sent = 0;
89 }
90 /*
91 * The routine that looks up a font name.
92 */
93 struct resfont *
94 lookup(char *name)
95 {
96 struct resfont *p;
97
98 for (p=reshash[hash(name)]; p!=NULL; p=p->next)
99 if (strcmp(p->Keyname, name)==0)
100 return(p);
101 return(NULL);
102 }
103
104 #ifdef XDVIPSK
105 boolean otftype_conforms(quarterword /* otftype_enum */ font_otftype, quarterword /* otftype_enum */ otftype)
106 {
107 boolean retv = false;
108
109 switch (otftype)
110 {
111 case Any_type1_font:
112 if ((font_otftype == None_font) /* ||
113 (font_otftype == PostScript_font) */)
114 retv = true;
115 break;
116 case Any_otf_font:
117 if ((font_otftype != None_font) /* &&
118 (font_otftype != PostScript_font) */)
119 retv = true;
120 break;
121 default:
122 if (font_otftype == otftype)
123 retv = true;
124 break;
125 }
126
127 return retv;
128 }
129
130 resfont_ref *lookup_ps(const char *ps_name, quarterword /* otftype_enum */ otftype)
131 {
132 resfont_ref *ptr;
133
134 assert(ps_name);
135
136 for (ptr = reshash_ps[hash(ps_name)]; ptr != NULL; ptr = ptr->next)
137 if ((strcmp(ptr->resfont_ptr->PSname, ps_name) == 0) && otftype_conforms(ptr->resfont_ptr->otftype, otftype))
138 break;
139
140 return(ptr);
141 }
142
143 resfont_ref *lookup_v(const char *vect_name)
144 {
145 resfont_ref *ptr;
146
147 assert(vect_name);
148
149 for (ptr = reshash_v[hash(vect_name)]; ptr != NULL; ptr = ptr->next)
150 if (strcmp(ptr->resfont_ptr->Vectfile, vect_name) == 0)
151 break;
152
153 return(ptr);
154 }
155 #endif /* XDVIPSK */
156
157 struct resfont *
158 #ifdef XDVIPSK
159 findPSname(char *name, quarterword /* otftype_enum */ otftype)
160 #else
161 findPSname(char *name)
162 #endif /* XDVIPSK */
163 {
164 register int i;
165 register struct resfont *p;
166 for (i=0; i<RESHASHPRIME; i++)
167 for (p=reshash[i]; p; p=p->next) {
168 if (strcmp(p->PSname, name)==0)
169 #ifdef XDVIPSK
170 if (otftype_conforms(p->otftype, otftype))
171 #endif /* XDVIPSK */
172 return p;
173 }
174 return NULL;
175 }
176
177 /*
178 * This routine adds an entry.
179 */
180 static void
181 #ifndef XDVIPSK
182 add_entry(char *TeXname, char *PSname, char *Fontfile,
183 char *Vectfile, char *specinfo, char *downloadinfo)
184 #else
185 add_entry(char *TeXname, char *PSname, char *Fontfile,
186 char *Vectfile, char *specinfo, char *downloadinfo, boolean partial, boolean isOTF, quarterword embolden)
187 #endif /* XDVIPSK */
188 {
189 struct resfont *p;
190 #ifdef XDVIPSK
191 resfont_ref *p_ref;
192 #endif /* XDVIPSK */
193 int h;
194 if (PSname == NULL)
195 PSname = TeXname;
196 p = (struct resfont *)mymalloc((integer)sizeof(struct resfont));
197 p->Keyname = TeXname;
198 p->PSname = PSname;
199 p->Fontfile = Fontfile;
200 p->Vectfile = Vectfile;
201 p->TeXname = TeXname;
202 p->specialinstructions = specinfo;
203 if (downloadinfo && *downloadinfo)
204 p->downloadheader = downloadinfo;
205 else
206 p->downloadheader = 0;
207 h = hash(TeXname);
208 p->next = reshash[h];
209 p->sent = 0;
210 #ifdef XDVIPSK
211 p->partialdownload = partial;
212 if (isOTF)
213 p->otftype = OTF_font;
214 else
215 p->otftype = None_font;
216 p->index = 0;
217 p->embolden = embolden;
218 p->cmap_fmt = 0;
219 p->luamap_idx = -1;
220 p->enc = NULL;
221 #endif /* XDVIPSK */
222 reshash[h] = p;
223 #ifdef XDVIPSK
224 p_ref = lookup_ps(PSname, p->otftype);
225 if (p_ref == NULL)
226 {
227 p_ref = (resfont_ref*)mymalloc((integer)sizeof(resfont_ref));
228 assert(p_ref);
229
230 h = hash(PSname);
231 p_ref->next = reshash_ps[h];
232 reshash_ps[h] = p_ref;
233 }
234 p_ref->resfont_ptr = p;
235
236 if (Vectfile)
237 {
238 p_ref = lookup_v(Vectfile);
239 if (p_ref == NULL)
240 {
241 p_ref = (resfont_ref*)mymalloc((integer)sizeof(resfont_ref));
242 assert(p_ref);
243
244 h = hash(Vectfile);
245 p_ref->next = reshash_v[h];
246 reshash_v[h] = p_ref;
247 }
248 p_ref->resfont_ptr = p;
249 }
250 #endif /* XDVIPSK */
251 }
252
253 #ifdef XDVIPSK
254 /*
255 * This routine adds(replaces) an entry from SPECIAL.
256 */
257 void
258 add_entry_spec(char *TeXname, char *PSname, char *Fontfile,
259 char *Vectfile, char *specinfo, char *downloadinfo, boolean partial, boolean isOTF, quarterword embolden, boolean replace)
260 {
261 struct resfont *p;
262 resfont_ref *p_ref;
263 int h, found = 0;
264
265 if (PSname == NULL)
266 PSname = TeXname;
267 if ((p = lookup(TeXname))) {
268 if (!replace) {
269 char s[256];
270 sprintf(s,"Resident font %s allready found in map",TeXname);
271 error(s);
272 return;
273 }
274 found = 1;
275 }
276 else {
277 p = (struct resfont *)mymalloc((integer)sizeof(struct resfont));
278 p->Keyname = TeXname;
279 }
280 p->PSname = PSname;
281 p->Fontfile = Fontfile;
282 p->Vectfile = Vectfile;
283 p->TeXname = TeXname;
284 p->specialinstructions = specinfo;
285 if (downloadinfo && *downloadinfo)
286 p->downloadheader = downloadinfo;
287 else
288 p->downloadheader = 0;
289 p->sent = 0;
290 p->partialdownload = partial;
291 if (isOTF)
292 p->otftype = OTF_font;
293 else
294 p->otftype = None_font;
295 p->index = 0;
296 p->embolden = 0;
297 p->cmap_fmt = 0;
298 p->luamap_idx = -1;
299 p->enc = NULL;
300 if (!found) {
301 h = hash(TeXname);
302 p->next = reshash[h];
303 reshash[h] = p;
304 }
305
306 p_ref = lookup_ps(PSname, p->otftype);
307 if (p_ref == NULL)
308 {
309 p_ref = (resfont_ref*)mymalloc((integer)sizeof(resfont_ref));
310 assert(p_ref);
311
312 h = hash(PSname);
313 p_ref->next = reshash_ps[h];
314 reshash_ps[h] = p_ref;
315 }
316 p_ref->resfont_ptr = p;
317
318 if (Vectfile)
319 {
320 p_ref = lookup_v(Vectfile);
321 if (p_ref == NULL)
322 {
323 p_ref = (resfont_ref*)mymalloc((integer)sizeof(resfont_ref));
324 assert(p_ref);
325
326 h = hash(Vectfile);
327 p_ref->next = reshash_v[h];
328 reshash_v[h] = p_ref;
329 }
330 p_ref->resfont_ptr = p;
331 }
332 }
333 #endif /* XDVIPSK */
334
335 /*
336 * Now our residentfont routine. Returns the number of characters in
337 * this font, based on the TFM file.
338 */
339 int
340 residentfont(register fontdesctype *curfnt)
341 {
342 int i;
343 struct resfont *p;
344 #ifdef XDVIPSK
345 chardesctype *cd;
346 #endif /* XDVIPSK */
347
348 /*
349 * First we determine if we can find this font in the resident list.
350 */
351 if (*curfnt->area)
352 return 0; /* resident fonts never have a nonstandard font area */
353 if ((p=lookup(curfnt->name))==NULL)
354 return 0;
355 /*
356 * This is not yet the correct way to do things, but it is useful as it
357 * is so we leave it in. The problem: if resident Times-Roman is
358 * re-encoded, then it will be downloaded as bitmaps; this is not
359 * right. The solution will be to introduce two types of `<'
360 * directives, one that downloads fonts and one that downloads
361 * short headers that are innocuous.
362 */
363 #ifndef XDVIPSK
364 if (p->Fontfile && downloadpspk) {
365 #else
366 if (p->Fontfile && (!p->otftype) && downloadpspk) {
367 #endif /* XDVIPSK */
368 #ifdef DEBUG
369 if (dd(D_FONTS))
370 fprintf_str(stderr,"Using PK font %s for <%s>.\n",
371 curfnt->name, p->PSname);
372 #endif /* DEBUG */
373 return 0;
374 }
375 /*
376 * We clear out some pointers:
377 */
378 #ifdef DEBUG
379 if (dd(D_FONTS))
380 fprintf_str(stderr,"Font %s <%s> is resident.\n",
381 curfnt->name, p->PSname);
382 #endif /* DEBUG */
383 curfnt->resfont = p;
384 curfnt->name = p->TeXname;
385 #ifdef XDVIPSK
386 if (p->otftype) {
387 curfnt->maxchars = MAX_CODE;
388 curfnt->iswide = 1;
389 curfnt->codewidth = 2;
390 if (curfnt->chardesc_hh) {
391 delete_all_chardesc(curfnt);
392 curfnt->chardesc_hh = NULL;
393 }
394 i = sfntload(curfnt);
395 add_name(p->PSname, &ps_fonts_used);
396 usesOTFfonts = 1;
397 return(i);
398 }
399 #endif /* XDVIPSK */
400 for (i=0; i<256; i++) {
401 #ifndef XDVIPSK
402 curfnt->chardesc[i].TFMwidth = 0;
403 curfnt->chardesc[i].packptr = NULL;
404 curfnt->chardesc[i].pixelwidth = 0;
405 curfnt->chardesc[i].flags = 0;
406 curfnt->chardesc[i].flags2 = 0;
407 #else
408 cd = add_chardesc(curfnt, i);
409 #endif /* XDVIPSK */
410 }
411 add_name(p->PSname, &ps_fonts_used);
412 /*
413 * We include the font here. But we only should need to include the
414 * font if we have a stupid spooler; smart spoolers should be able
415 * to supply it automatically.
416 */
417 if (p->downloadheader) {
418 char *cp = p->downloadheader;
419 char *q;
420
421 infont = p->PSname;
422 #ifdef XDVIPSK
423 inotftype = p->otftype;
424 #endif /* XDVIPSK */
425 while (1) {
426 q = cp;
427 while (*cp && *cp != ' ')
428 cp++;
429 if (*cp) {
430 *cp = 0;
431 add_header(q);
432 *cp++ = ' ';
433 } else {
434 /* if (strstr(q,".pfa")||strstr(q,".pfb")||
435 strstr(q,".PFA")||strstr(q,".PFB"))
436 break;
437 else */ {
438 add_header(q);
439 break;
440 }
441 }
442 infont = 0;
443 }
444 infont = 0;
445 }
446 i = tfmload(curfnt);
447 if (i < 0)
448 i = 1;
449 usesPSfonts = 1;
450 return(i);
451 }
452 #define INLINE_SIZE (2000)
453 static char was_inline[INLINE_SIZE];
454 static unsigned c_lineno;
455 static void
456 bad_config(const char *err)
457 {
458 fprintf_str(stderr, "%s:%d:", realnameoffile, c_lineno);
459 error (err);
460 fprintf_str(stderr, " (%s)\n", was_inline);
461 }
462
463 #ifndef KPATHSEA
464 /*
465 * Get environment variables! These override entries in ./config.h.
466 * We substitute everything of the form ::, ^: or :$ with default,
467 * so a user can easily build on to the existing paths.
468 */
469 static char *
470 getpath(char *who, char *what)
471 {
472 if (who) {
473 register char *pp, *qq;
474 int lastsep = 1;
475
476 for (pp=nextstring, qq=who; *qq;) {
477 if (*qq == PATHSEP) {
478 if (lastsep) {
479 strcpy(pp, what);
480 pp = pp + strlen(pp);
481 }
482 lastsep = 1;
483 } else
484 lastsep = 0;
485 *pp++ = *qq++;
486 }
487 if (lastsep) {
488 strcpy(pp, what);
489 pp = pp + strlen(pp);
490 }
491 *pp = 0;
492 qq = nextstring;
493 nextstring = pp + 1;
494 return qq;
495 } else
496 return what;
497 }
498 #endif
499 /*
500 * We use this function so we can support strings delimited by
501 * double quotes with spaces in them. We also accept strings
502 * with spaces in them, but kill off any spaces at the end.
503 */
504 static char *
505 configstring(char *s, int nullok)
506 {
507 char tstr[INLINE_SIZE];
508 char *p = tstr;
509
510 while (*s && *s <= ' ')
511 s++;
512 if (*s == '"') {
513 s++;
514 while (*s != 10 && *s != 0 && *s != '"' && p < tstr+290)
515 *p++ = *s++;
516 } else {
517 while (*s && p < tstr+290)
518 *p++ = *s++;
519 while (*(p-1) <= ' ' && p > tstr)
520 p--;
521 }
522 *p = 0;
523 if (p == tstr && ! nullok)
524 bad_config("bad string");
525 return newstring(tstr);
526 }
527 #ifdef KPATHSEA
528 /* We use this in `getdefaults' to modify the kpathsea structure for the
529 paths we read. See kpathsea/tex-file.[ch]. */
530 #define SET_CLIENT_PATH(filefmt, val) \
531 kpse_format_info[filefmt].client_path = xstrdup (val)
532 #endif
533 /*
534 * Now we have the getdefaults routine.
535 */
536 #ifdef XDVIPSK
537 const char *luascript = LUASCRIPTFILE;
538 #endif
539 const char *psmapfile = PSMAPFILE;
540 Boolean
541 getdefaults(const char *s)
542 {
543 FILE *deffile;
544 char PSname[INLINE_SIZE];
545 #ifdef XDVIPSK
546 char buf[INLINE_SIZE];
547 #endif /* XDVIPSK */
548 register char *p;
549 integer hsiz, vsiz;
550 #ifndef KPATHSEA
551 char *d = configpath;
552 int i, j;
553 #endif
554 int canaddtopaper = 0;
555
556 if (printer == NULL) {
557 if (s) {
558 strcpy(PSname, s);
559 } else {
560 #ifdef KPATHSEA
561 char *dvipsrc = kpse_var_value ("DVIPSRC");
562 #ifdef WIN32
563 if (dvipsrc && *dvipsrc) {
564 /* $DVIPSRC was set by user */
565 strcpy(PSname, dvipsrc);
566 }
567 else
568 /* No env var, looking into some kind of standard path. */
569 if (SearchPath(".;%HOME%;c:\\", ".dvipsrc", NULL,
570 INLINE_SIZE, PSname,
571 &dvipsrc) == 0) {
572 /* search failed, we must put something into PSname. */
573 dvipsrc = kpse_var_expand(DVIPSRC);
574 if (dvipsrc) {
575 strcpy(PSname, dvipsrc);
576 free(dvipsrc);
577 }
578 /* Else SearchPath has filled PSname with something */
579 }
580 /* remove any redundant path separators. Many configurations
581 can show up: c:\/.dvipsrc and so on ... */
582 {
583 char *p, *q;
584 for (p = q = PSname; *p && (p - PSname < INLINE_SIZE);
585 p++, q++) {
586 if (IS_DIR_SEP(*p)) {
587 *q = DIR_SEP; p++; q++;
588 while (*p && IS_DIR_SEP(*p)) p++;
589 }
590 else if (IS_KANJI(p)) {
591 *q++ = *p++;
592 }
593 *q = *p;
594 }
595 *q = '\0';
596 }
597 #else
598 if(!dvipsrc) dvipsrc = kpse_var_expand(DVIPSRC);
599 strcpy(PSname, dvipsrc ? dvipsrc : "~/.dvipsrc");
600 if(dvipsrc) free(dvipsrc);
601 #endif /* WIN32 */
602
603 #else /* ! KPATHSEA */
604 #ifndef VMCMS /* IBM: VM/CMS - don't have home directory on VMCMS */
605 #ifndef MVSXA
606 d = "~";
607 #endif
608 #endif /* IBM: VM/CMS */
609 strcpy(PSname, DVIPSRC);
610 #endif /* KPATHSEA */
611 }
612 } else {
613 #if defined(MSDOS) || defined(OS2)
614 strcpy(PSname, printer);
615 strcat(PSname, ".cfg");
616 #else
617 strcpy(PSname, "config.");
618 strcat(PSname, printer);
619 #endif
620 }
621 #ifdef KPATHSEA
622 if ((deffile=search(configpath,PSname,READ))!=NULL) {
623 #else
624 if ((deffile=search(d,PSname,READ))!=NULL) {
625 #endif
626 if (dvips_debug_flag && !quiet) {
627 if (strlen(realnameoffile) + prettycolumn > STDOUTSIZE) {
628 fprintf(stderr, "\n");
629 prettycolumn = 0;
630 }
631 fprintf(stderr, "{%s}", realnameoffile);
632 prettycolumn += strlen(realnameoffile) + 2;
633 }
634 #ifdef DEBUG
635 if (dd (D_CONFIG)) {
636 fprintf_str(stderr, "Reading dvips config file `%s':\n", realnameoffile);
637 }
638 #endif
639 c_lineno = 0;
640 while (fgets(was_inline, INLINE_SIZE, deffile)!=NULL) {
641 c_lineno++;
642 #ifdef DEBUG
643 if (dd (D_CONFIG)) {
644 fprintf_str(stderr, "%s:%d:%s", realnameoffile, c_lineno, was_inline);
645 }
646 #endif
647 /*
648 * We need to get rid of the newline.
649 */
650 for (p=was_inline; *p; p++);
651 while (p > was_inline && (*(p-1) == '\n' || *(p-1) == '\r')) {
652 *--p = '\0';
653 }
654 if (was_inline[0] != '@')
655 canaddtopaper = 0;
656 switch (was_inline[0]) {
657 /*
658 * Handling paper size information:
659 *
660 * If line is empty, then we clear out the paper size information
661 * we have so far.
662 *
663 * If it is `@+', then we add to the current paper size info.
664 *
665 * If it is `name hsize vsize', then we start a new definition.
666 */
667 case '@' :
668 p = was_inline + 1;
669 while (*p && *p <= ' ') p++;
670 if (*p == 0) {
671 papsizes = 0; /* throw away memory */
672 } else if (*p == '+') {
673 if (canaddtopaper == 0)
674 error(
675 " @+ in config files must immediately following a @ lines");
676 else {
677 *(nextstring-1) = '\n';/* IBM: VM/CMS - changed 10 to "\n" */
678 p++;
679 while (*p && *p == ' ') p++;
680 strcpy(nextstring, p);
681 nextstring += strlen(p) + 1;
682 }
683 } else {
684 struct papsiz *ps;
685 char *q;
686
687 ps = (struct papsiz *)mymalloc((integer)sizeof(struct papsiz));
688 ps->next = papsizes;
689 papsizes = ps;
690 q = p;
691 while (*p && *p > ' ')
692 p++;
693 *p++ = 0;
694 ps->name = newstring(q);
695 while (*p && *p <= ' ') p++;
696 handlepapersize(p, &hsiz, &vsiz);
697 ps->xsize = hsiz;
698 ps->ysize = vsiz;
699 ps->specdat = newstring("");
700 canaddtopaper = 1;
701 }
702 break;
703 case 'a' :
704 dopprescan = (was_inline[1] != '0');
705 break;
706 case 'b':
707 if (strncmp(was_inline, "bitmapfontenc", 13) == 0) {
708 char *p = was_inline + 13 ;
709 while (*p && *p <= ' ')
710 p++ ;
711 if (strncmp(p, "off", 3) == 0) {
712 bitmapencopt(0) ; // disable bitmap font enc feature
713 } else if (strncmp(p, "on", 2) == 0) {
714 bitmapencopt(1) ; // try to include bitmap font encs
715 } else if (strncmp(p, "strict", 6) == 0) {
716 bitmapencopt(2) ; // issue warnings for missing encs
717 } else {
718 error(
719 "! bitmapfontenc config file option only supports on, off, and strict") ;
720 }
721 break ;
722 }
723 #ifdef SHORTINT
724 if (sscanf(was_inline+1, "%ld", &pagecopies) != 1)
725 bad_config("missing pagecopies to b");
726 #else
727 if (sscanf(was_inline+1, "%d", &pagecopies) != 1)
728 bad_config("missing pagecopies to b");
729 #endif
730 if (pagecopies < 1 || pagecopies > 1000)
731 bad_config("pagecopies not between 1 and 1000");
732 break;
733 case 'm' :
734 #ifdef SHORTINT
735 if (sscanf(was_inline+1, "%ld", &swmem) != 1)
736 bad_config("missing swmem to m");
737 #else /* ~SHORTINT */
738 if (sscanf(was_inline+1, "%d", &swmem) != 1)
739 bad_config("missing swmem to m");
740 #endif /* ~SHORTINT */
741 if (swmem > 0) {
742 swmem += fontmem; /* grab headers we've seen already */
743 } else {
744 swmem = INT_MAX; /* if value <=0, max it out */
745 }
746 break;
747 case 'M' :
748 /* If the user specified a -mode, don't replace it. */
749 if (!mfmode_option)
750 mfmode = configstring(was_inline+1, 0);
751 mflandmode = 0;
752 {
753 char *pp;
754 for (pp=mfmode; pp && *pp>' '; pp++);
755 if (pp && *pp == ' ') {
756 *pp++ = 0;
757 while (*pp && *pp <= ' ')
758 pp++;
759 if (*pp)
760 mflandmode = pp;
761 }
762 }
763 break;
764 case 'o' :
765 if (!oname_option) {
766 struct stat st_buf;
767 char *tmp_oname;
768 tmp_oname = configstring(was_inline+1, 1);
769 if ((*tmp_oname && tmp_oname[strlen(tmp_oname)-1] == ':')
770 || (stat(tmp_oname, &st_buf) == 0 && S_ISCHR(st_buf.st_mode))) {
771 sendcontrolD = 1; /* if we send to a device, *we* are spooler */
772 #if defined(MSDOS) || defined(OS2)
773 tmp_oname[strlen(tmp_oname)-1] = 0;
774 #endif
775 }
776 oname = tmp_oname;
777 }
778 break;
779 case 'F' :
780 sendcontrolD = (was_inline[1] != '0');
781 break;
782 case 'O' :
783 p = was_inline + 1;
784 handlepapersize(p, &hoff, &voff);
785 break;
786 case 'l':
787 p = was_inline + 1 ;
788 #ifndef XDVIPSK
789 if (strncmp(p, "andscaperotate", 14) != 0)
790 error("! in config file line starting with l was not landscaperotate") ;
791 p += 14 ;
792 landscaperotate = (*p != '0') ;
793 #else /* XDVIPSK */
794 if (strncmp(p, "andscaperotate", 14) != 0) {
795 if (strncmp(p, "uascript ", 9) != 0) {
796 error("! in config file line starting with l was not landscaperotate or luascript") ;
797 } else {
798 luascript = configstring(was_inline+9, 0);
799 }
800 } else {
801 p += 14 ;
802 landscaperotate = (*p != '0') ;
803 }
804 #endif /* XDVIPSK */
805 break ;
806 #ifdef FONTLIB
807 case 'L' :
808 {
809 char tempname[INLINE_SIZE];
810 if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config("missing arg to L");
811 else {
812 #ifndef XDVIPSK
813 flipath = getpath(fliparse(PSname,tempname), flipath);
814 #else /* XDVIPSK */
815 #ifdef KPATHSEA
816 SET_CLIENT_PATH (kpse_miscfonts_format, fliparse(PSname,tempname));
817 #else
818 flipath = getpath(fliparse(PSname,tempname), flipath);
819 #endif
820 #endif
821 fliname = newstring(tempname);
822 }
823 }
824 break;
825 #endif
826 case 'T' :
827 if (sscanf(was_inline+1, "%s", PSname) != 1)
828 bad_config("missing arg to T");
829 else
830 #ifdef KPATHSEA
831 SET_CLIENT_PATH (kpse_tfm_format, PSname);
832 #else
833 tfmpath = getpath(PSname, tfmpath);
834 #endif
835 break;
836 case 'P' :
837 if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config("missing arg to P");
838 else
839 #ifdef KPATHSEA
840 SET_CLIENT_PATH (kpse_pk_format, PSname);
841 #else
842 pkpath = getpath(PSname, pkpath);
843 #endif
844 break;
845 case 'p' :
846 p = was_inline + 1;
847 while (*p && *p <= ' ')
848 p++;
849 if (*p == '+') {
850 if (sscanf(p+1, "%s", PSname) != 1)
851 bad_config("missing arg to p");
852 getpsinfo(PSname);
853 } else {
854 psmapfile = configstring(was_inline+1, 0);
855 }
856 break;
857 case 'v' : case 'V' :
858 if (sscanf(was_inline+1, "%s", PSname) != 1)
859 bad_config("missing arg to V");
860 else
861 #ifdef KPATHSEA
862 SET_CLIENT_PATH (kpse_vf_format, PSname);
863 #else
864 vfpath = getpath(PSname, vfpath);
865 #endif
866 break;
867 case 'S' :
868 if (sscanf(was_inline+1, "%s", PSname) != 1)
869 bad_config("missing arg to S");
870 else
871 #ifdef KPATHSEA
872 SET_CLIENT_PATH (kpse_pict_format, PSname);
873 #else
874 figpath = getpath(PSname, figpath);
875 #endif
876 break;
877 case 's':
878 safetyenclose = 1;
879 break;
880 case 'H' :
881 if (sscanf(was_inline+1, "%s", PSname) != 1)
882 bad_config("missing arg to H");
883 else
884 #ifdef KPATHSEA
885 SET_CLIENT_PATH (headerpath, PSname);
886 #else
887 headerpath = getpath(PSname, headerpath);
888 #endif
889 break;
890 case '%': case ' ' : case '*' : case '#' : case ';' :
891 case '=' : case 0 : case '\n' :
892 break;
893 case 'r' :
894 reverse = (was_inline[1] != '0');
895 break;
896 /*
897 * This case is for last resort font scaling; I hate this, but enough
898 * people have in no uncertain terms demanded it that I'll go ahead and
899 * add it.
900 *
901 * This line must have numbers on it, resolutions, to search for the
902 * font as a last resort, and then the font will be scaled. These
903 * resolutions should be in increasing order.
904 *
905 * For most machines, just `300' is sufficient here; on the NeXT,
906 * `300 400' may be more appropriate.
907 */
908 case 'R':
909 #ifndef KPATHSEA
910 i = 0;
911 p = was_inline + 1;
912 while (*p) {
913 while (*p && *p <= ' ')
914 p++;
915 if ('0' <= *p && *p <= '9') {
916 j = 0;
917 while ('0' <= *p && *p <= '9')
918 j = 10 * j + (*p++ - '0');
919 if (i > 0)
920 if (lastresortsizes[i-1] > j) {
921 bad_config("last resort sizes (R) must be sorted");
922 }
923 lastresortsizes[i++] = j;
924 } else {
925 if (*p == 0)
926 break;
927 bad_config("only numbers expected on `R' line");
928 }
929 }
930 lastresortsizes[i] = 32000;
931 #else /* KPATHSEA */
932 for (p = was_inline + 1; *p; p++) {
933 if (isblank ((unsigned char)*p)) {
934 *p = ':';
935 }
936 }
937 kpse_fallback_resolutions_string = xstrdup (was_inline + 1);
938 #endif
939 break;
940 case 'D' :
941 if (sscanf(was_inline+1, "%d", &actualdpi) != 1)
942 bad_config("missing arg to D");
943 if (actualdpi < 10 || actualdpi > 10000)
944 bad_config("dpi must be between 10 and 10000");
945 vactualdpi = actualdpi;
946 break;
947 /*
948 * Execute a command. This can be dangerous, but can also be very useful.
949 */
950 case 'E' :
951 #ifdef SECURE
952 error("dvips was compiled with SECURE, which disables E in config");
953 #else
954 if (secure) {
955 error("E in config is disabled. To enable E, set z0 before E");
956 break;
957 }
958 system(was_inline+1);
959 #endif
960 break;
961 case 'K':
962 removecomments = (was_inline[1] != '0');
963 break;
964 case 'L':
965 lastpsizwins = (was_inline[1] != '0');
966 break;
967 case 'U':
968 nosmallchars = (was_inline[1] != '0');
969 break;
970 case 'W':
971 for (p=was_inline+1; *p && *p <= ' '; p++);
972 if (*p)
973 warningmsg = newstring(p);
974 else
975 warningmsg = 0;
976 break;
977 case 'X' :
978 if (sscanf(was_inline+1, "%d", &actualdpi) != 1)
979 bad_config("missing numeric arg to X");
980 if (actualdpi < 10 || actualdpi > 10000)
981 bad_config("X arg must be between 10 and 10000");
982 break;
983 case 'Y' :
984 if (sscanf(was_inline+1, "%d", &vactualdpi) != 1)
985 bad_config("missing numeric arg to Y");
986 if (vactualdpi < 10 || vactualdpi > 10000)
987 bad_config("Y arg must be between 10 and 10000");
988 break;
989 case 'x': case 'y':
990 if (sscanf(was_inline+1, "%lg", &mag) != 1)
991 bad_config("missing arg to x or y");
992 overridemag = (was_inline[0] == 'x') ? 1 : -1;
993 break;
994 case 'e' :
995 if (sscanf(was_inline+1, "%d", &maxdrift) != 1)
996 bad_config("missing arg to e");
997 if (maxdrift < 0) bad_config("bad argument to e");
998 vmaxdrift = maxdrift;
999 break;
1000 case 'z' :
1001 if (secure_option && secure && was_inline[1] == '0') {
1002 #ifndef XDVIPSK
1003 fprintf_str(stderr,
1004 "warning: %s: z0 directive ignored since -R1 given\n",
1005 realnameoffile); /* Never happen */
1006 #else
1007 sprintf(buf,
1008 "warning: %s: z0 directive ignored since -R1 given\n",
1009 realnameoffile); /* Never happen */
1010 error(buf);
1011 #endif /* XDVIPSK */
1012 } else {
1013 if (was_inline[1] == '0') {
1014 secure = 0;
1015 } else if (was_inline[1] == '2') {
1016 secure = 2;
1017 } else {
1018 secure = 1;
1019 }
1020 }
1021 break;
1022 case 'q' : case 'Q' :
1023 quiet = (was_inline[1] != '0');
1024 break;
1025 case 'f' :
1026 filter = (was_inline[1] != '0');
1027 if (filter)
1028 oname = "";
1029 /* noenv has already been tested, so no point in setting. */
1030 sendcontrolD = 0;
1031 break;
1032 #ifdef SHIFTLOWCHARS
1033 case 'G':
1034 shiftlowchars = (was_inline[1] != '0');
1035 break;
1036 #endif
1037 case 'h' :
1038 if (sscanf(was_inline+1, "%s", PSname) != 1)
1039 bad_config("missing arg to h");
1040 else add_header(PSname);
1041 break;
1042 case 'i' :
1043 if (sscanf(was_inline+1, "%d", &maxsecsize) != 1)
1044 maxsecsize = 0;
1045 sepfiles = 1;
1046 break;
1047 case 'I':
1048 noenv = (was_inline[1] != '0');
1049 break;
1050 case 'N' :
1051 disablecomments = (was_inline[1] != '0');
1052 break;
1053 case 'Z' :
1054 compressed = (was_inline[1] != '0');
1055 break;
1056 case 'j':
1057 #ifndef XDVIPSK
1058 partialdownload = (was_inline[1] != '0');
1059 #else
1060 t1_partialdownload = (was_inline[1] != '0');
1061 break;
1062 case 'J':
1063 cid_partialdownload = (was_inline[1] != '0');
1064 break;
1065 #endif /* XDVIPSK */
1066 case 't' :
1067 if (sscanf(was_inline+1, "%s", PSname) != 1)
1068 bad_config("missing arg to t");
1069 else {
1070 if (strcmp(PSname, "landscape") == 0) {
1071 if (hpapersize || vpapersize)
1072 error(
1073 "both landscape and papersize specified; ignoring landscape");
1074 else
1075 landscape = 1;
1076 } else
1077 paperfmt = newstring(PSname);
1078 }
1079 break;
1080 case 'c' :
1081 if (sscanf(was_inline+1, "%s", PSname) != 1)
1082 bad_config("missing arg to c");
1083 else
1084 getdefaults(PSname);
1085 break;
1086 default:
1087 bad_config("strange line");
1088 }
1089 }
1090 fclose(deffile);
1091 } else {
1092 if (printer)
1093 {
1094 char msg[1000];
1095 snprintf (msg, sizeof(msg), "warning: no config file for `%s'",
1096 printer);
1097 error(msg);
1098 return 0;
1099 }
1100 }
1101
1102 return 1;
1103 }
1104
1105 #ifdef XDVIPSK
1106 /* pfb_name -- pfb font name without an extension
1107 enc -- full encoding file name
1108 returns an alias id, if the encoding should be aliased, zero otherwise */
1109 static int get_enc_alias(const char *pfb_name, const char *enc)
1110 {
1111 int enc_alias_id = 0;
1112 int error;
1113 char *pfb_name_lwr;
1114 char *enc_lwr;
1115
1116 if (pfb_name && enc)
1117 {
1118 pfb_name_lwr = strdup(pfb_name);
1119 assert(pfb_name_lwr);
1120 strlwr(pfb_name_lwr);
1121
1122 enc_lwr = strdup(enc);
1123 assert(enc_lwr);
1124 strlwr(enc_lwr);
1125
1126 lua_getglobal(L, "get_enc_alias");
1127 lua_pushstring(L, pfb_name_lwr);
1128 lua_pushstring(L, enc_lwr);
1129 error = lua_pcall(L, 2, 1, 0);
1130 if (error)
1131 {
1132 PRINTF_PR("Lua function get_enc_alias() execution error: %d - %s\n", error, lua_tostring(L, -1));
1133 }
1134 else
1135 enc_alias_id = lua_tointeger(L, -1);
1136 lua_pop(L, 1);
1137
1138 free(pfb_name_lwr);
1139 free(enc_lwr);
1140 }
1141
1142 return(enc_alias_id);
1143 }
1144 #endif /* XDVIPSK */
1145 /*
1146 * If a character pointer is passed in, use that name; else, use the
1147 * default (possibly set) name, psfonts.map.
1148 */
1149 void
1150 getpsinfo(const char *name)
1151 {
1152 FILE *deffile;
1153 register char *p;
1154 char *specinfo, *downloadinfo;
1155 char downbuf[500];
1156 char specbuf[500];
1157 int slen;
1158 #ifdef XDVIPSK
1159 static char vect_alias[ENC_BUF_SIZE + 1];
1160 int enc_alias_id = 0;
1161 #endif /* XDVIPSK */
1162
1163 if (name == 0)
1164 name = psmapfile;
1165 if ((deffile=search(mappath, name, READ))!=NULL) {
1166 if (dvips_debug_flag && !quiet) {
1167 if (strlen(realnameoffile) + prettycolumn > STDOUTSIZE) {
1168 fprintf(stderr, "\n");
1169 prettycolumn = 0;
1170 }
1171 fprintf_str(stderr, "{%s}", realnameoffile);
1172 prettycolumn += strlen(realnameoffile) + 2;
1173 }
1174 while (fgets(was_inline, INLINE_SIZE, deffile)!=NULL) {
1175 p = was_inline;
1176 if (*p > ' ' && *p != '*' && *p != '#' && *p != ';' && *p != '%') {
1177 char *TeXname = NULL;
1178 char *PSname = NULL;
1179 char *Fontfile = NULL;
1180 char *Vectfile = NULL;
1181 char *hdr_name = NULL;
1182 boolean nopartial_p = false;
1183 boolean encoding_p = false;
1184 specinfo = NULL;
1185 downloadinfo = NULL;
1186 downbuf[0] = 0;
1187 specbuf[0] = 0;
1188 while (*p) {
1189 encoding_p = false;
1190 while (*p && *p <= ' ')
1191 p++;
1192 if (*p) {
1193 if (*p == '"') { /* PostScript instructions? */
1194 if (specinfo) {
1195 strcat(specbuf, specinfo);
1196 strcat(specbuf, " ");
1197 }
1198 specinfo = p + 1;
1199
1200 } else if (*p == '<') { /* Header to download? */
1201 /* If had previous downloadinfo, save it. */
1202 if (downloadinfo) {
1203 strcat(downbuf, downloadinfo);
1204 strcat(downbuf, " ");
1205 downloadinfo = NULL;
1206 }
1207 if (p[1] == '<') { /* << means always full download */
1208 p++;
1209 nopartial_p = true;
1210 } else if (p[1] == '[') { /* <[ means an encoding */
1211 p++;
1212 encoding_p = true;
1213 }
1214 p++;
1215 /* skip whitespace after < */
1216 while (*p && *p <= ' ')
1217 p++;
1218
1219 /* save start of header name */
1220 hdr_name = p;
1221
1222 } else if (TeXname) /* second regular word on line? */
1223 PSname = p;
1224
1225 else /* first regular word? */
1226 TeXname = p;
1227
1228 if (*p == '"') {
1229 p++; /* find end of "..." word */
1230 while (*p != '"' && *p)
1231 p++;
1232 } else
1233 while (*p > ' ') /* find end of anything else */
1234 p++;
1235 if (*p)
1236 *p++ = 0;
1237
1238 /* If we had a header we were downloading, figure
1239 out what to do; couldn't do this above since we
1240 want to check the suffix. */
1241 if (hdr_name) {
1242 const char *suffix = find_suffix (hdr_name);
1243 if (encoding_p || STREQ (suffix, "enc")) {
1244 /* (SPQR) if it is a reencoding, pass on to
1245 FontPart, and download as usual */
1246 Vectfile = downloadinfo = hdr_name;
1247 } else if (nopartial_p) {
1248 downloadinfo = hdr_name;
1249 } else if (FILESTRCASEEQ (suffix, "pfa")
1250 || FILESTRCASEEQ (suffix, "pfb")
1251 || STREQ (suffix, "PFA")
1252 || STREQ (suffix, "PFB")) {
1253 Fontfile = hdr_name;
1254 } else {
1255 downloadinfo = hdr_name;
1256 }
1257 }
1258 }
1259 }
1260 if (specinfo)
1261 strcat(specbuf, specinfo);
1262 if (downloadinfo)
1263 strcat(downbuf, downloadinfo);
1264 slen = strlen(downbuf) - 1;
1265 if (slen > 0 && downbuf[slen] == ' ') {
1266 downbuf[slen] = 0;
1267 }
1268 if (TeXname) {
1269 TeXname = newstring(TeXname);
1270 PSname = newstring(PSname);
1271 Fontfile = newstring(Fontfile);
1272 #ifdef XDVIPSK
1273 enc_alias_id = 0;
1274 if (Fontfile)
1275 {
1276 strncpy(vect_alias, Fontfile, ENC_BUF_SIZE);
1277 vect_alias[ENC_BUF_SIZE] = '\0';
1278 p = strstr(vect_alias, PFB_EXT);
1279 if (p)
1280 {
1281 *p = '\0';
1282 enc_alias_id = get_enc_alias(vect_alias, Vectfile);
1283 }
1284 }
1285
1286 if (enc_alias_id && Vectfile)
1287 {
1288 snprintf(vect_alias, ENC_BUF_SIZE, "%s%c%d", Vectfile, ALIAS_ID_DELIM, enc_alias_id);
1289 vect_alias[ENC_BUF_SIZE] = '\0';
1290 Vectfile = vect_alias;
1291 }
1292 #endif /* XDVIPSK */
1293 Vectfile = newstring(Vectfile);
1294 #ifdef XDVIPSK
1295 if (enc_alias_id)
1296 {
1297 strncpy(vect_alias, specbuf, ENC_BUF_SIZE);
1298 vect_alias[ENC_BUF_SIZE] = '\0';
1299 p = strstr(vect_alias, ENC_REF_SIGNATURE);
1300 if (p)
1301 {
1302 while ((p > vect_alias) && (*(p - 1) == ' ')) --p;
1303 snprintf(p, ENC_BUF_SIZE - (p - vect_alias), "%d", enc_alias_id);
1304 vect_alias[ENC_BUF_SIZE] = '\0';
1305 strncat(vect_alias, specbuf + (p - vect_alias), ENC_BUF_SIZE - strlen(vect_alias));
1306 vect_alias[ENC_BUF_SIZE] = '\0';
1307 specinfo = newstring(vect_alias);
1308 }
1309 else
1310 specinfo = newstring(specbuf);
1311 }
1312 else
1313 #endif /* XDVIPSK */
1314 specinfo = newstring(specbuf);
1315 #ifdef XDVIPSK
1316 if (enc_alias_id && downbuf[0])
1317 {
1318 snprintf(vect_alias, ENC_BUF_SIZE, "%s%c%d", downbuf, ALIAS_ID_DELIM, enc_alias_id);
1319 vect_alias[ENC_BUF_SIZE] = '\0';
1320 downloadinfo = newstring(vect_alias);
1321 }
1322 else
1323 #endif /* XDVIPSK */
1324 downloadinfo = newstring(downbuf);
1325 add_entry(TeXname, PSname, Fontfile, Vectfile,
1326 #ifndef XDVIPSK
1327 specinfo, downloadinfo);
1328 #else
1329 specinfo, downloadinfo, !nopartial_p, 0, 0);
1330 #endif /* XDVIPSK */
1331 }
1332 }
1333 }
1334 fclose(deffile);
1335 }
1336 checkstrings();
1337 }
1338 #ifdef XDVIPSK
1339 /*
1340 * Read fonts map file suplied via /special{mapfile: xxxx.map}
1341 * Replaces or not duplicating entries
1342 */
1343 void
1344 getpsinfo_spec(const char *name, boolean replace)
1345 {
1346 FILE *deffile;
1347 register char *p;
1348 char *specinfo, *downloadinfo;
1349 char downbuf[500];
1350 char specbuf[500];
1351 int slen;
1352
1353 if (name == 0)
1354 return;
1355 if ((deffile=search(mappath, name, READ))!=NULL) {
1356 if (dvips_debug_flag && !quiet) {
1357 if (strlen(realnameoffile) + prettycolumn > STDOUTSIZE) {
1358 fprintf(stderr, "\n");
1359 prettycolumn = 0;
1360 }
1361 fprintf(stderr, "{%s}", realnameoffile);
1362 prettycolumn += strlen(realnameoffile) + 2;
1363 }
1364 while (fgets(was_inline, INLINE_SIZE, deffile)!=NULL) {
1365 p = was_inline;
1366 if (*p > ' ' && *p != '*' && *p != '#' && *p != ';' && *p != '%') {
1367 char *TeXname = NULL;
1368 char *PSname = NULL;
1369 char *Fontfile = NULL;
1370 char *Vectfile = NULL;
1371 char *hdr_name = NULL;
1372 boolean nopartial_p = false;
1373 boolean encoding_p = false;
1374 specinfo = NULL;
1375 downloadinfo = NULL;
1376 downbuf[0] = 0;
1377 specbuf[0] = 0;
1378 while (*p) {
1379 encoding_p = false;
1380 while (*p && *p <= ' ')
1381 p++;
1382 if (*p) {
1383 if (*p == '"') { /* PostScript instructions? */
1384 if (specinfo) {
1385 strcat(specbuf, specinfo);
1386 strcat(specbuf, " ");
1387 }
1388 specinfo = p + 1;
1389
1390 } else if (*p == '<') { /* Header to download? */
1391 /* If had previous downloadinfo, save it. */
1392 if (downloadinfo) {
1393 strcat(downbuf, downloadinfo);
1394 strcat(downbuf, " ");
1395 downloadinfo = NULL;
1396 }
1397 if (p[1] == '<') { /* << means always full download */
1398 p++;
1399 nopartial_p = true;
1400 } else if (p[1] == '[') { /* <[ means an encoding */
1401 p++;
1402 encoding_p = true;
1403 }
1404 p++;
1405 /* skip whitespace after < */
1406 while (*p && *p <= ' ')
1407 p++;
1408
1409 /* save start of header name */
1410 hdr_name = p;
1411
1412 } else if (TeXname) /* second regular word on line? */
1413 PSname = p;
1414
1415 else /* first regular word? */
1416 TeXname = p;
1417
1418 if (*p == '"') {
1419 p++; /* find end of "..." word */
1420 while (*p != '"' && *p)
1421 p++;
1422 } else
1423 while (*p > ' ') /* find end of anything else */
1424 p++;
1425 if (*p)
1426 *p++ = 0;
1427
1428 /* If we had a header we were downloading, figure
1429 out what to do; couldn't do this above since we
1430 want to check the suffix. */
1431 if (hdr_name) {
1432 const char *suffix = find_suffix (hdr_name);
1433 if (encoding_p || STREQ (suffix, "enc")) {
1434 /* (SPQR) if it is a reencoding, pass on to
1435 FontPart, and download as usual */
1436 Vectfile = downloadinfo = hdr_name;
1437 } else if (nopartial_p) {
1438 downloadinfo = hdr_name;
1439 } else if (FILESTRCASEEQ (suffix, "pfa")
1440 || FILESTRCASEEQ (suffix, "pfb")
1441 || STREQ (suffix, "PFA")
1442 || STREQ (suffix, "PFB")) {
1443 Fontfile = hdr_name;
1444 } else {
1445 downloadinfo = hdr_name;
1446 }
1447 }
1448 }
1449 }
1450 if (specinfo)
1451 strcat(specbuf, specinfo);
1452 if (downloadinfo)
1453 strcat(downbuf, downloadinfo);
1454 slen = strlen(downbuf) - 1;
1455 if (slen > 0 && downbuf[slen] == ' ') {
1456 downbuf[slen] = 0;
1457 }
1458 if (TeXname) {
1459 TeXname = newstring(TeXname);
1460 PSname = newstring(PSname);
1461 Fontfile = newstring(Fontfile);
1462 Vectfile = newstring(Vectfile);
1463 specinfo = newstring(specbuf);
1464 downloadinfo = newstring(downbuf);
1465 add_entry_spec(TeXname, PSname, Fontfile, Vectfile,
1466 specinfo, downloadinfo, !nopartial_p, 0, 0, replace);
1467 }
1468 }
1469 }
1470 fclose(deffile);
1471 }
1472 checkstrings();
1473 }
1474
1475 void parse_otf_map_line(const char *map_line)
1476 {
1477 char *map_line_copy = NULL;
1478 register char *p, *pt;
1479 char* specinfo;
1480 char specbuf[500];
1481 char map_name[260];
1482
1483 p = map_line_copy = strdup(map_line);
1484 assert(map_line_copy);
1485
1486 if (*p > '\t' && *p != '*' && *p != '#' && *p != ';' && *p != '%') {
1487 char *TeXname = NULL;
1488 char *PSname = NULL;
1489 char *Vectfile = NULL;
1490 char *Fontfile = NULL;
1491 char *hdr_name = NULL;
1492 int embolden = 0;
1493
1494 specinfo = NULL;
1495 specbuf[0] = 0;
1496 while (*p) {
1497 while (*p && *p <= '\t')
1498 p++;
1499 if (*p) {
1500 if (*p == '{') { /* PostScript instructions? */
1501 if (specinfo) {
1502 strcat(specbuf, specinfo);
1503 strcat(specbuf, " ");
1504 }
1505 specinfo = p + 1;
1506
1507 }
1508 else if (*p == '>') { /* Header to download? */
1509 p++;
1510 /* skip whitespace after < */
1511 while (*p && *p <= ' ')
1512 p++;
1513
1514 /* save start of header name */
1515 hdr_name = p;
1516
1517 }
1518 else if (TeXname && PSname) /* third regular word on line? */
1519 Vectfile = p;
1520
1521 else if (TeXname) /* second regular word on line? */
1522 PSname = p;
1523
1524 else /* first regular word? */
1525 TeXname = p;
1526
1527 if (*p == '{') {
1528 p++; /* find end of "..." word */
1529 while (*p != '}' && *p)
1530 p++;
1531 }
1532 else
1533 while (*p > '\t') /* find end of anything else */
1534 p++;
1535 if (*p)
1536 *p++ = 0;
1537
1538 /* If we had a header we were downloading, figure
1539 out what to do; couldn't do this above since we
1540 want to check the suffix. */
1541 if (hdr_name) {
1542 const char *suffix;
1543 if ((specinfo = strchr(hdr_name, '('))) {
1544 *specinfo = 0;
1545 specinfo++;
1546 strcat(specbuf, "index=");
1547 while (*specinfo != ')') {
1548 int x = strlen(specbuf);
1549 specbuf[x] = *specinfo;
1550 specbuf[x + 1] = 0;
1551 specinfo++;
1552 }
1553 specinfo = NULL;
1554 }
1555 suffix = find_suffix(hdr_name);
1556 pt = hdr_name + strlen(hdr_name) - 1;
1557 while ((pt >= hdr_name) && ((*pt == '\n') || (*pt == '\r')))
1558 *pt-- = '\0';
1559 if (FILESTRCASEEQ(suffix, "ttf")
1560 || FILESTRCASEEQ(suffix, "ttc")
1561 || FILESTRCASEEQ(suffix, "otf")
1562 || FILESTRCASEEQ(suffix, "dfont")
1563 || STREQ(suffix, "TTF")
1564 || STREQ(suffix, "TTC")
1565 || STREQ(suffix, "OTF")
1566 || STREQ(suffix, "DFONT")) {
1567 Fontfile = hdr_name;
1568 }
1569 }
1570 if (TeXname) {
1571 if ((specinfo = strchr(TeXname, '('))) {
1572 specinfo++;
1573 strcat(specbuf, "index=");
1574 while (*specinfo != ')') {
1575 int x = strlen(specbuf);
1576 specbuf[x] = *specinfo;
1577 specbuf[x + 1] = 0;
1578 specinfo++;
1579 }
1580 specinfo = NULL;
1581 }
1582 }
1583 }
1584 }
1585 if (specinfo)
1586 strcat(specbuf, specinfo);
1587 if (TeXname) {
1588 char seps[] = ";";
1589 char *token;
1590 float val;
1591 pt = mymalloc(strlen(TeXname) + 1);
1592 strcpy(pt, TeXname);
1593 strcat(specbuf, "{");
1594 token = strtok(pt, seps);
1595 while( token != NULL ) {
1596 if (strnicmp(token, "slant=", 6) == 0) {
1597 if (specbuf[strlen(specbuf) - 1] != '{')
1598 strcat(specbuf, " ");
1599 sscanf(token + 6,"%f",&val);
1600 sprintf(map_name,"%g ct_SlantFont",val);
1601 strcat(specbuf, map_name);
1602 }
1603 else if (strnicmp(token, "extend=", 7) == 0) {
1604 if (specbuf[strlen(specbuf) - 1] != '{')
1605 strcat(specbuf, " ");
1606 sscanf(token + 7,"%f",&val);
1607 sprintf(map_name,"%g ct_ExtendFont",val);
1608 strcat(specbuf, map_name);
1609 }
1610 else if (strnicmp(token, "embolden=", 9) == 0) {
1611 sscanf(token + 9,"%d",&embolden);
1612 }
1613 token = strtok( NULL, seps );
1614 }
1615 strcat(specbuf, "}");
1616 free(pt);
1617 TeXname = newstring(TeXname);
1618 PSname = newstring(PSname);
1619 Vectfile = newstring(Vectfile);
1620 Fontfile = newstring(Fontfile);
1621 specinfo = newstring(specbuf);
1622 add_entry(TeXname, PSname, Fontfile, Vectfile,
1623 specinfo, NULL, 1, 1, embolden);
1624 }
1625 }
1626 free(map_line_copy);
1627 }
1628
1629 /*
1630 Map file (dvi_name.opentype.map) record structure:
1631 - LuaTex font name ("xxxx")
1632 - Postscript font name
1633 - Encoding name
1634 - font file name(index for TTC)
1635 */
1636 void
1637 getotfinfo(const char *dviname)
1638 {
1639 FILE *deffile;
1640 register char *p, *p1;
1641 char strbuf[500], map_name[260];
1642
1643 if ((dviname == 0) || (strlen(dviname) == 0))
1644 return;
1645 strcpy(strbuf, dviname);
1646 p = strrchr(strbuf, '.');
1647 if (p)
1648 *p = 0;
1649 p1 = p - 1;
1650 while (p1 > strbuf) {
1651 if ((*p1 == '\\') || (*p1 == '/')) {
1652 strcpy(map_name, p1 + 1);
1653 *(p1 + 1) = 0;
1654 break;
1655 }
1656 p1--;
1657 }
1658 if (p1 == strbuf) {
1659 strcpy(map_name, p1);
1660 *p1 = 0;
1661 }
1662 strcat(strbuf, OTFMAPFILEDIR);
1663 strcat(strbuf, map_name);
1664 strcat(strbuf, OTFMAPFILEEXT);
1665 if ((deffile = search(mappath, strbuf, READ)) != NULL) {
1666 if (dvips_debug_flag && !quiet) {
1667 if (strlen(realnameoffile) + prettycolumn > STDOUTSIZE) {
1668 fprintf(stderr, "\n");
1669 prettycolumn = 0;
1670 }
1671 fprintf(stderr, "{%s}", realnameoffile);
1672 prettycolumn += strlen(realnameoffile) + 2;
1673 }
1674 while (fgets(was_inline, INLINE_SIZE, deffile) != NULL)
1675 parse_otf_map_line(was_inline);
1676 fclose(deffile);
1677 }
1678 checkstrings();
1679 }
1680 #endif /* XDVIPSK */
1681 #ifndef KPATHSEA
1682 /*
1683 * Get environment variables! These override entries in ./config.h.
1684 * We substitute everything of the form ::, ^: or :$ with default,
1685 * so a user can easily build on to the existing paths.
1686 */
1687 static char *
1688 getenvup(char *who, char *what)
1689 {
1690 return getpath(getenv(who), what);
1691 }
1692 #endif
1693 #if !defined(KPATHSEA) && defined(SEARCH_SUBDIRECTORIES)
1694 static char *concat3();
1695 #endif
1696 void
1697 checkenv(int which)
1698 {
1699 #ifndef KPATHSEA
1700 if (which) {
1701 tfmpath = getenvup(FONTPATH, tfmpath);
1702 vfpath = getenvup("VFFONTS", vfpath);
1703 pictpath = getenvup("TEXPICTS", pictpath);
1704 figpath = getenvup("TEXINPUTS", figpath);
1705 headerpath = getenvup("DVIPSHEADERS", headerpath);
1706 if (getenv("TEXPKS"))
1707 pkpath = getenvup("TEXPKS", pkpath);
1708 else if (getenv("TEXPACKED"))
1709 pkpath = getenvup("TEXPACKED", pkpath);
1710 else if (getenv("PKFONTS"))
1711 pkpath = getenvup("PKFONTS", pkpath);
1712 #ifdef SEARCH_SUBDIRECTORIES
1713 else if (getenv(FONTPATH))
1714 pkpath = getenvup(FONTPATH, pkpath);
1715 if (getenv ("TEXFONTS_SUBDIR"))
1716 fontsubdirpath = getenvup ("TEXFONTS_SUBDIR", fontsubdirpath);
1717 {
1718 char pathsep[2];
1719 char *do_subdir_path();
1720 char *dirs = do_subdir_path (fontsubdirpath);
1721 /* If the paths were in dynamic storage before, that memory is
1722 wasted now. */
1723 pathsep[0] = PATHSEP;
1724 pathsep[1] = '\0';
1725 tfmpath = concat3 (tfmpath, pathsep, dirs);
1726 pkpath = concat3 (pkpath, pathsep, dirs);
1727 }
1728 #endif
1729 } else
1730 configpath = getenvup("TEXCONFIG", configpath);
1731 #endif
1732 }
1733
1734 #if !defined(KPATHSEA) && defined(SEARCH_SUBDIRECTORIES)
1735
1736 #include <sys/types.h>
1737 #include <sys/stat.h>
1738 #include <errno.h>
1739
1740 #ifdef SYSV
1741 #include <dirent.h>
1742 typedef struct dirent *directory_entry_type;
1743 #else
1744 #include <sys/dir.h>
1745 typedef struct direct *directory_entry_type;
1746 #endif
1747
1748 /* Declare the routine to get the current working directory. */
1749
1750 #ifndef HAVE_GETCWD
1751 extern char *getwd ();
1752 #define getcwd(b, len) ((b) ? getwd (b) : getwd (xmalloc (len)))
1753 #else
1754 #ifdef ANSI
1755 extern char *getcwd (char *, int);
1756 #else
1757 extern char *getcwd ();
1758 #endif /* not ANSI */
1759 #endif /* not HAVE_GETWD */
1760
1761 #if defined(SYSV) || defined(VMS) || defined(MSDOS) || defined(OS2) || defined(ATARIST)
1762 #define MAXPATHLEN (256)
1763 #else /* ~SYSV */
1764 #include <sys/param.h> /* for MAXPATHLEN */
1765 #endif
1766
1767 extern void exit();
1768 extern int chdir();
1769
1770 /* Memory operations: variants of malloc(3) and realloc(3) that just
1771 give up the ghost when they fail. */
1772
1773 char *
1774 xmalloc(unsigned size)
1775 {
1776 char *mem = malloc (size);
1777
1778 if (mem == NULL)
1779 {
1780 fprintf (stderr, "! Cannot allocate %u bytes.\n", size);
1781 exit (10);
1782 }
1783
1784 return mem;
1785 }
1786
1787
1788 char *
1789 xrealloc(char *ptr, unsigned size)
1790 {
1791 char *mem = realloc (ptr, size);
1792
1793 if (mem == NULL)
1794 {
1795 fprintf (stderr, "! Cannot reallocate %u bytes at %x.\n", size, (int)ptr);
1796 exit (10);
1797 }
1798
1799 return mem;
1800 }
1801
1802
1803 /* Return, in NAME, the next component of PATH, i.e., the characters up
1804 to the next PATHSEP. */
1805
1806 static void
1807 next_component(char *name, char **path)
1808 {
1809 unsigned count = 0;
1810
1811 while (**path != 0 && **path != PATHSEP)
1812 {
1813 name[count++] = **path;
1814 (*path)++; /* Move further along, even between calls. */
1815 }
1816
1817 name[count] = 0;
1818 if (**path == PATHSEP)
1819 (*path)++; /* Move past the delimiter. */
1820 }
1821
1822
1823 #ifndef _POSIX_SOURCE
1824 #ifndef S_ISDIR
1825 #define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
1826 #endif
1827 #endif
1828
1829 /* Return true if FN is a directory or a symlink to a directory,
1830 false if not. */
1831
1832 int
1833 is_dir(char *fn)
1834 {
1835 struct stat stats;
1836
1837 return stat (fn, &stats) == 0 && S_ISDIR (stats.st_mode);
1838 }
1839
1840
1841 static char *
1842 concat3(char *s1, char *s2, char *s3)
1843 {
1844 char *r = xmalloc (strlen (s1) + strlen (s2) + strlen (s3) + 1);
1845 strcpy (r, s1);
1846 strcat (r, s2);
1847 strcat (r, s3);
1848 return r;
1849 }
1850
1851
1852 /* DIR_LIST is the default list of directories (colon-separated) to
1853 search. We want to add all the subdirectories directly below each of
1854 the directories in the path.
1855
1856 We return the list of directories found. */
1857
1858 char *
1859 do_subdir_path(char *dir_list)
1860 {
1861 char *cwd;
1862 unsigned len;
1863 char *result = xmalloc ((unsigned)1);
1864 char *temp = dir_list;
1865 char dirsep[2];
1866
1867 dirsep[0] = DIRSEP;
1868 dirsep[1] = '\0';
1869
1870 /* Make a copy in writable memory. */
1871 dir_list = xmalloc (strlen (temp) + 1);
1872 strcpy (dir_list, temp);
1873
1874 *result = 0;
1875
1876 /* Unfortunately, we can't look in the environment for the current
1877 directory, because if we are running under a program (let's say
1878 Emacs), the PWD variable might have been set by Emacs' parent
1879 to the current directory at the time Emacs was invoked. This
1880 is not necessarily the same directory the user expects to be
1881 in. So, we must always call getcwd(3) or getwd(3), even though
1882 they are slow and prone to hang in networked installations. */
1883 cwd = getcwd (NULL, MAXPATHLEN + 2);
1884 if (cwd == NULL)
1885 {
1886 perror ("getcwd");
1887 exit (errno);
1888 }
1889
1890 do
1891 {
1892 DIR *dir;
1893 directory_entry_type e;
1894 char dirname[MAXPATHLEN];
1895
1896 next_component (dirname, &dir_list);
1897
1898 /* All the `::'s should be gone by now, but we may as well make
1899 sure `chdir' doesn't crash. */
1900 if (*dirname == 0) continue;
1901
1902 /* By changing directories, we save a bunch of string
1903 concatenations (and make the pathnames the kernel looks up
1904 shorter). */
1905 if (chdir (dirname) != 0) continue;
1906
1907 dir = opendir (".");
1908 if (dir == NULL) continue;
1909
1910 while ((e = readdir (dir)) != NULL)
1911 {
1912 if (is_dir (e->d_name) && strcmp (e->d_name, ".") != 0
1913 && strcmp (e->d_name, "..") != 0)
1914 {
1915 char *found = concat3 (dirname, dirsep, e->d_name);
1916
1917 result = xrealloc (result, strlen (result) + strlen (found) + 2);
1918
1919 len = strlen (result);
1920 if (len > 0)
1921 {
1922 result[len] = PATHSEP;
1923 result[len + 1] = 0;
1924 }
1925 strcat (result, found);
1926 free (found);
1927 }
1928 }
1929 closedir (dir);
1930
1931 /* Change back to the current directory, in case the path
1932 contains relative directory names. */
1933 if (chdir (cwd) != 0)
1934 {
1935 perror (cwd);
1936 exit (errno);
1937 }
1938 }
1939 while (*dir_list != 0);
1940
1941 return result;
1942 }
1943 #endif /* SEARCH_SUBDIRECTORIES */