Back to index

tetex-bin  3.0
read-mapfile.c
Go to the documentation of this file.
00001 /*
00002   This code was stolen from dvips (getpsinfo() in resident.c) for xdvi
00003   use.  The file itself does not carry any licensing info, except for
00004   reference to dvips.h, which doesn't have a standart-type license
00005   either.  The code seems to be either in the public domain, or, in
00006   the worst case, GPL.
00007   
00008   - Nicolai Langfeldt, 21/2/1999
00009 
00010 */
00011 
00012 #include "xdvi-config.h"
00013 #include "xdvi.h"
00014 #include "util.h"
00015 #include "read-mapfile.h"
00016 #include "dvi-draw.h" /* for add_T1_mapentry */
00017 #include <stdio.h>
00018 
00019 #ifdef T1LIB
00020 
00021 #include "kpathsea/tex-file.h"
00022 
00023 #define INLINE_SIZE 2048
00024 
00025 /*
00026  * Read a dvips psfont map file.  Return True if it was read ok,
00027  * False otherwise.
00028  */
00029 Boolean
00030 read_map_file(char *name)
00031 {
00032     FILE *fp;
00033     char *p;
00034     char *specinfo;
00035     char specbuf[500];
00036     char *fullname;
00037     int lineno = 0;
00038     static char inline_buf[INLINE_SIZE];
00039 
00040     /* Try first for xdvi specific file */
00041     fullname = kpse_find_file(name, kpse_program_text_format, 0);
00042     /* Then any fontmap file */
00043     if (fullname == NULL) {
00044        fullname = kpse_find_file(name, kpse_fontmap_format, 0);
00045     }
00046 
00047     if (fullname == NULL) {
00048        XDVI_WARNING((stderr, "Could not find map file \"%s\".", name));
00049        return False;
00050     }
00051 
00052     fp = XFOPEN(fullname, "r");
00053     if (fp == NULL) {
00054        XDVI_WARNING((stderr, "Could not open map file \"%s\": %s.\n", name, strerror(errno)));
00055        return False;
00056     }
00057 
00058     while (fgets(inline_buf, INLINE_SIZE, fp) != NULL) {
00059        char *TeXname = NULL;
00060        char *PSname = NULL;
00061        char *Fontfile = NULL;
00062        char *Vectfile = NULL;
00063        char *hdr_name = NULL;
00064        specinfo = NULL;
00065        specbuf[0] = 0;
00066        lineno++;
00067 
00068        /* One line at a time */
00069        p = inline_buf;
00070 
00071        if (*p < ' ' || *p == '*' || *p == '#' || *p == ';' || *p == '%')
00072            continue;
00073 
00074        while (*p) {
00075            while (*p && *p <= ' ')
00076               p++;
00077            if (*p) {
00078               /* Note: In dvips, this flag is set outside the loop
00079                  so that font files may be scanned/included as encoding files
00080                  (I guess it doesn't matter for dvips, but it does for xdvi ...)
00081               */
00082               boolean encoding_p = False;
00083               if (*p == '"') {     /* PostScript instructions? */
00084                   if (specinfo) {
00085                      strcat(specbuf, specinfo);
00086                      strcat(specbuf, " ");
00087                   }
00088                   specinfo = p + 1;
00089 
00090               }
00091               else if (*p == '<') {       /* Header to download? */
00092                   if (p[1] == '<') {      /* << means always full download, ignore */
00093                      p++;
00094                   }
00095                   else if (p[1] == '[') { /* <[ means an encoding */
00096                      p++;
00097                      encoding_p = True;
00098                   }
00099                   p++;
00100                   /* skip whitespace after < */
00101                   while (*p && *p <= ' ')
00102                      p++;
00103 
00104                   /* save start of header name */
00105                   hdr_name = p;
00106 
00107               }
00108               else if (TeXname)    /* second regular word on line? */
00109                   PSname = p;
00110 
00111               else   /* first regular word? */
00112                   TeXname = p;
00113 
00114               if (*p == '"') {
00115                   p++;      /* find end of "..." word */
00116                   while (*p != '"' && *p)
00117                      p++;
00118               }
00119               else
00120                   while (*p > ' ') /* find end of anything else */
00121                      p++;
00122 
00123               /* Terminate the substring we just identified */
00124               if (*p)
00125                   *p++ = 0;
00126 
00127               /* If we had a header we were downloading, figure out what to do;
00128                  couldn't do this above since we want to check the suffix.  */
00129               if (hdr_name) {
00130                   char *suffix = find_suffix(hdr_name);
00131                   if (encoding_p
00132                      || (suffix != NULL && strcmp(suffix, "enc") == 0)) {
00133                      Vectfile = hdr_name;
00134                   }
00135                   else {
00136                      Fontfile = hdr_name;
00137                   }
00138               }
00139            }
00140        }      /* while (*p) */
00141 
00142        /* Line finished.  Lookit what we got */
00143        if (specinfo) {
00144            strcat(specbuf, specinfo);
00145        }
00146 
00147        if (TeXname) {
00148            add_T1_mapentry(lineno, fullname, TeXname, Fontfile, Vectfile, specinfo);
00149        }
00150 
00151     }
00152     fclose(fp);
00153     return True;
00154 }
00155 
00156 #endif /* T1LIB */