home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / unixtex-6.1b-src.tgz / tar.out / contrib / unixtex / dvipsk / afm2tfm.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  52KB  |  1,849 lines

  1. /*
  2.  *   This program converts AFM files to TeX TFM files, and optionally
  3.  *   to TeX VPL files that retain all kerning and ligature information.
  4.  *   Both files make the characters not normally encoded by TeX available
  5.  *   by character codes greater than 127.
  6.  */
  7.  
  8. /*   (Modified by Don Knuth from Tom Rokicki's pre-VPL version.) */
  9. /*   VM/CMS port by J. Hafner (hafner@almaden.ibm.com), based on
  10.  *   the port by Alessio Guglielmi (guglielmi@ipisnsib.bitnet)
  11.  *   and Marco Prevedelli (prevedelli@ipisnsva.bitnet).
  12.  *   This port is still in test state.  No guarantees.
  13.  *   11/3/92: more corrections to VM/CMS port. Now it looks correct
  14.  *   and will be supported by J. Hafner.
  15.  *
  16. */
  17.  
  18. #include "config.h"
  19. #include <kpathsea/c-ctype.h>
  20.   
  21. /* JLH: added these to make the code easier to read and remove some
  22.    ascii<->ebcdic dependencies */
  23. #define ASCII_A 65
  24. #define ASCII_Z 90
  25. #define ASCII_a 97
  26. #define ASCII_z 122
  27. #define ASCII_0 48
  28. #define ASCII_9 57
  29.  
  30. #ifdef VMCMS
  31. #define interesting lookstr  /* for 8 character truncation conflicts */
  32. #include "dvipscms.h"
  33. extern FILE *cmsfopen() ;
  34. extern char ebcdic2ascii[] ;
  35. extern char ascii2ebcdic[] ;
  36. #ifdef fopen
  37. #undef fopen
  38. #endif
  39. #define fopen cmsfopen
  40. #endif
  41.  
  42. #if (defined(MSDOS) && defined(__TURBOC__)) || (defined(OS2) && defined(_MSC_VER))
  43. #define SMALLMALLOC
  44. #endif
  45.  
  46. struct encoding {
  47.    char *name ;
  48.    char *vec[256] ;
  49. } ;
  50. struct encoding staticencoding = {
  51.   "TeX text",
  52.   {"Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma",
  53.    "Upsilon", "Phi", "Psi", "Omega", "arrowup", "arrowdown", "quotesingle",
  54.    "exclamdown", "questiondown", "dotlessi", "dotlessj", "grave", "acute",
  55.    "caron", "breve", "macron", "ring", "cedilla", "germandbls", "ae", "oe",
  56.    "oslash", "AE", "OE", "Oslash", "space", "exclam", "quotedbl", "numbersign",
  57.    "dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright",
  58.    "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one",
  59.    "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon",
  60.    "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C",
  61.    "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
  62.    "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash",
  63.    "bracketright", "circumflex", "underscore", "quoteleft", "a", "b", "c", "d",
  64.    "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
  65.    "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright",
  66.    "tilde", "dieresis", "", "", "", "", "", "", "", "", "", "", "", "", "",
  67.     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  68.     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  69.     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  70.     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  71.     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  72.     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
  73.     "", "", "", "", "", "", "" } } ;
  74. /*
  75.  *   It's easier to put this in static storage and parse it as we go
  76.  *   than to build the structures ourselves.
  77.  */
  78. char *staticligkern[] = {
  79.    "% LIGKERN space l =: lslash ; space L =: Lslash ;",
  80.    "% LIGKERN question quoteleft =: questiondown ;",
  81.    "% LIGKERN exclam quoteleft =: exclamdown ;",
  82.    "% LIGKERN hyphen hyphen =: endash ; endash hyphen =: emdash ;",
  83.    "% LIGKERN quoteleft quoteleft =: quotedblleft ;",
  84.    "% LIGKERN quoteright quoteright =: quotedblright ;",
  85.    "% LIGKERN space {} * ; * {} space ; zero {} * ; * {} zero ;",
  86.    "% LIGKERN one {} * ; * {} one ; two {} * ; * {} two ;",
  87.    "% LIGKERN three {} * ; * {} three ; four {} * ; * {} four ;",
  88.    "% LIGKERN five {} * ; * {} five ; six {} * ; * {} six ;",
  89.    "% LIGKERN seven {} * ; * {} seven ; eight {} * ; * {} eight ;",
  90.    "% LIGKERN nine {} * ; * {} nine ;",
  91. /*
  92.  *   These next are only included for deficient afm files that
  93.  *   have the lig characters but not the lig commands.
  94.  */
  95.    "% LIGKERN f i =: fi ; f l =: fl ; f f =: ff ; ff i =: ffi ;",
  96.    "% LIGKERN ff l =: ffl ;",
  97.    0 } ;
  98. /*
  99.  *   The above layout corresponds to TeX Typewriter Type and is compatible
  100.  *   with TeX Text because the position of ligatures is immaterial.
  101.  */
  102. struct encoding *outencoding = 0 ;
  103. struct encoding *inencoding = 0 ;
  104. char *outenname, *inenname ;/* the file names for input and output encodings */
  105. int boundarychar = -1 ;     /* the boundary character */
  106. int ignoreligkern ;         /* do we look at ligkern info in the encoding? */
  107. /*
  108.  *   This is what we store Adobe data in.
  109.  */
  110. struct adobeinfo {
  111.    struct adobeinfo *next ;
  112.    int adobenum, texnum, width ;
  113.    char *adobename ;
  114.    int llx, lly, urx, ury ;
  115.    struct lig *ligs ;
  116.    struct kern *kerns ;
  117.    struct pcc *pccs ;
  118.    int wptr, hptr, dptr, iptr ;
  119. } *adobechars, *adobeptrs[256], *texptrs[256],
  120.   *uppercase[256], *lowercase[256] ;
  121. int nexttex[256] ; /* for characters encoded multiple times in output */
  122. /*
  123.  *   These are the eight ligature ops, in VPL terms and in METAFONT terms.
  124.  */
  125. char *vplligops[] = {
  126.    "LIG", "/LIG", "/LIG>", "LIG/", "LIG/>", "/LIG/", "/LIG/>", "/LIG/>>", 0
  127. } ;
  128. char *encligops[] = {
  129.    "=:", "|=:", "|=:>", "=:|", "=:|>", "|=:|", "|=:|>", "|=:|>>", 0
  130. } ;
  131. struct lig {
  132.    struct lig *next ;
  133.    char *succ, *sub ;
  134.    short op, boundleft ;
  135. } ;
  136. struct kern {
  137.    struct kern *next ;
  138.    char *succ ;
  139.    int delta ;
  140. } ;
  141. struct pcc {
  142.    struct pcc *next ;
  143.    char * partname ;
  144.    int xoffset, yoffset ;
  145. } ;
  146.  
  147. FILE *afmin, *vplout, *tfmout ;
  148. char inname[200], outname[200] ; /* names of input and output files */
  149. char buffer[255]; /* input buffer (modified while parsing) */
  150. char obuffer[255] ; /* unmodified copy of input buffer */
  151. char *param ; /* current position in input buffer */
  152. char *fontname = "Unknown" ;
  153. char *codingscheme = "Unspecified" ;
  154. #ifdef VMCMS
  155. char *ebfontname ;
  156. char *ebcodingscheme ;
  157. #endif
  158. float italicangle = 0.0 ;
  159. char fixedpitch ;
  160. char makevpl ;
  161. char pedantic ;
  162. int xheight = 400 ;
  163. int fontspace ;
  164. int bc, ec ;
  165. long cksum ;
  166. float efactor = 1.0, slant = 0.0 ;
  167. float capheight = 0.8 ;
  168. char *efactorparam, *slantparam ;
  169. double newslant ;
  170. char titlebuf[500] ;
  171.  
  172. void
  173. error(s)
  174. register char *s ;
  175. {
  176.    (void)fprintf(stderr, "%s\n", s) ;
  177.    if (obuffer[0]) {
  178.       (void)fprintf(stderr, "%s\n", obuffer) ;
  179.       while (param > buffer) {
  180.          (void)fprintf(stderr, " ") ;
  181.          param-- ;
  182.       }
  183.       (void)fprintf(stderr, "^\n") ;
  184.    }
  185.    if (*s == '!')
  186.       exit(1) ;
  187. }
  188.  
  189. int
  190. transform(x,y)
  191.    register int x,y ;
  192. {
  193.    register double acc ;
  194.    acc = efactor * x + slant *y ;
  195.    return (int)(acc>=0? floor(acc+0.5) : ceil(acc-0.5) ) ;
  196. }
  197.  
  198. int
  199. getline() {
  200.    register char *p ;
  201.    register int c ;
  202.  
  203.    param = buffer ;
  204.    for (p=buffer; (c=getc(afmin)) != EOF && c != '\n';)/* changed 10 to '\n' */
  205.       *p++ = c ;
  206.    *p = 0 ;
  207.    (void)strcpy(obuffer, buffer) ;
  208.    if (p == buffer && c == EOF)
  209.       return(0) ;
  210.    else
  211.       return(1) ;
  212. }
  213.  
  214. char *interesting[] = { "FontName", "ItalicAngle", "IsFixedPitch",
  215.    "XHeight", "C", "KPX", "CC", "EncodingScheme", NULL} ;
  216. #define FontName (0)
  217. #define ItalicAngle (1)
  218. #define IsFixedPitch (2)
  219. #define XHeight (3)
  220. #define C (4)
  221. #define KPX (5)
  222. #define CC (6)
  223. #define EncodingScheme (7)
  224. #define NONE (-1)
  225. int
  226. interest(s)
  227. char *s ;
  228. {
  229.    register char **p ;
  230.    register int n ;
  231.  
  232.    for (p=interesting, n=0; *p; p++, n++)
  233.       if (strcmp(s, *p)==0)
  234.          return(n) ;
  235.    return(NONE) ;
  236. }
  237.  
  238. char *
  239. mymalloc(len)
  240. unsigned long len ;
  241. {
  242.    register char *p ;
  243.    int i ;
  244.  
  245. #ifdef SMALLMALLOC
  246.    if (len > 65500L)
  247.       error("! can't allocate more than 64K!") ;
  248. #endif
  249.    p = malloc((unsigned)len) ;
  250.    if (p==NULL)
  251.       error("! out of memory") ;
  252.    for (i=0; i<len; i++)
  253.       p[i] = 0 ;
  254.    return(p) ;
  255. }
  256.  
  257. char *
  258. newstring(s)
  259. char *s ;
  260. {
  261.    char *q = mymalloc((unsigned long)(strlen(s) + 1)) ;
  262.    (void)strcpy(q, s) ;
  263.    return q ;
  264. }
  265.  
  266. char *
  267. paramnewstring() {
  268.    register char *p, *q ;
  269.  
  270.    p = param ;
  271.    while (*p > ' ')
  272.       p++ ;
  273.    if (*p != 0)
  274.       *p++ = 0 ;
  275.    q = newstring(param) ;
  276.    while (*p && *p <= ' ')
  277.       p++ ;
  278.    param = p ;
  279.    return(q) ;
  280. }
  281.  
  282. char *
  283. paramstring() {
  284.    register char *p, *q ;
  285.  
  286.    p = param ;
  287.    while (*p > ' ')
  288.       p++ ;
  289.    q = param ;
  290.    if (*p != 0)
  291.       *p++ = 0 ;
  292.    while (*p && *p <= ' ')
  293.       p++ ;
  294.    param = p ;
  295.    return(q) ;
  296. }
  297.  
  298. int
  299. paramnum() {
  300.    register char *p ;
  301.    int i ;
  302.  
  303.    p = paramstring() ;
  304.    if (sscanf(p, "%d", &i) != 1)
  305.       error("! integer expected") ;
  306.    return(i) ;
  307. }
  308.  
  309. float
  310. paramfloat() {
  311.    register char *p ;
  312.    float i ;
  313.  
  314.    p = paramstring() ;
  315.    if (sscanf(p, "%f", &i) != 1)
  316.       error("! number expected") ;
  317.    return(i) ;
  318. }
  319.  
  320. struct adobeinfo *
  321. newchar() {
  322.    register struct adobeinfo *ai ;
  323.  
  324.    ai = (struct adobeinfo *)mymalloc((unsigned long)sizeof(struct adobeinfo)) ;
  325.    ai->adobenum = -1 ;
  326.    ai->texnum = -1 ;
  327.    ai->width = -1 ;
  328.    ai->adobename = NULL ;
  329.    ai->llx = -1 ;
  330.    ai->lly = -1 ;
  331.    ai->urx = -1 ;
  332.    ai->ury = -1 ;
  333.    ai->ligs = NULL ;
  334.    ai->kerns = NULL ;
  335.    ai->pccs = NULL ;
  336.    ai->next = adobechars ;
  337.    adobechars = ai ;
  338.    return(ai) ;
  339. }
  340.  
  341. struct kern *
  342. newkern() {
  343.    register struct kern *nk ;
  344.  
  345.    nk = (struct kern *)mymalloc((unsigned long)sizeof(struct kern)) ;
  346.    nk->next = NULL ;
  347.    nk->succ = NULL ;
  348.    nk->delta = 0 ;
  349.    return(nk) ;
  350. }
  351.  
  352. struct pcc *
  353. newpcc() {
  354.    register struct pcc *np ;
  355.  
  356.    np = (struct pcc *)mymalloc((unsigned long)sizeof(struct pcc)) ;
  357.    np->next = NULL ;
  358.    np->partname = NULL ;
  359.    np->xoffset = 0 ;
  360.    np->yoffset = 0 ;
  361.    return(np) ;
  362. }
  363.  
  364. struct lig *
  365. newlig() {
  366.    register struct lig *nl ;
  367.  
  368.    nl = (struct lig *)mymalloc((unsigned long)sizeof(struct lig)) ;
  369.    nl->next = NULL ;
  370.    nl->succ = NULL ;
  371.    nl->sub = NULL ;
  372.    nl->op = 0 ; /* the default =: op */
  373.    nl->boundleft = 0 ;
  374.    return(nl) ;
  375. }
  376.  
  377. void
  378. expect(s)
  379. char *s ;
  380. {
  381.    if (strcmp(paramstring(), s) != 0) {
  382.       (void)fprintf(stderr, "%s expected: ", s) ;
  383.       error("! syntax error") ;
  384.    }
  385. }
  386.  
  387. void
  388. handlechar() { /* an input line beginning with C */
  389.    register struct adobeinfo *ai ;
  390.    register struct lig *nl ;
  391.  
  392.    ai = newchar() ;
  393.    ai->adobenum = paramnum() ;
  394.    expect(";") ;
  395.    expect("WX") ;
  396.    ai->width = transform(paramnum(),0) ;
  397.    if (ai->adobenum >= 0 && ai->adobenum < 256) {
  398.       adobeptrs[ai->adobenum] = ai ;
  399.    }
  400.    expect(";") ;
  401.    expect("N") ;
  402.    ai->adobename = paramnewstring() ;
  403.    expect(";") ;
  404.    expect("B") ;
  405.    ai->llx = paramnum() ;
  406.    ai->lly = paramnum() ;
  407.    ai->llx = transform(ai->llx, ai->lly) ;
  408.    ai->urx = paramnum() ;
  409.    ai->ury = paramnum() ;
  410.    ai->urx = transform(ai->urx, ai->ury) ;
  411. /* We need to avoid negative heights or depths. They break accents in
  412.    math mode, among other things.  */
  413.    if (ai->lly > 0)
  414.       ai->lly = 0 ;
  415.    if (ai->ury < 0)
  416.       ai->ury = 0 ;
  417.    expect(";") ;
  418. /* Now look for ligatures (which aren't present in fixedpitch fonts) */
  419.    while (*param == 'L' && !fixedpitch) {
  420.       expect("L") ;
  421.       nl = newlig() ;
  422.       nl->succ = paramnewstring() ;
  423.       nl->sub = paramnewstring() ;
  424.       nl->next = ai->ligs ;
  425.       ai->ligs = nl ;
  426.       expect(";") ;
  427.    }
  428. }
  429.  
  430. struct adobeinfo *
  431. findadobe(p)
  432. char *p ;
  433. {
  434.    register struct adobeinfo *ai ;
  435.  
  436.    for (ai=adobechars; ai; ai = ai->next)
  437.       if (strcmp(p, ai->adobename)==0)
  438.          return(ai) ;
  439.    return(NULL) ;
  440. }
  441.  
  442.  
  443. /*
  444.  *   The following comment no longer applies; we rely on the LIGKERN
  445.  *   entries to kill space kerns.  Also, the same applies to numbers.
  446.  *
  447.  * We ignore kerns before and after space characters, because (1) TeX
  448.  * is using the space only for Polish ligatures, and (2) TeX's
  449.  * boundarychar mechanisms are not oriented to kerns (they apply
  450.  * to both spaces and punctuation) so we don't want to use them.
  451.  */
  452. void
  453. handlekern() { /* an input line beginning with KPX */
  454.    register struct adobeinfo *ai ;
  455.    register char *p ;
  456.    register struct kern *nk ;
  457.  
  458.    p = paramstring() ;
  459.    ai = findadobe(p) ;
  460.    if (ai == NULL)
  461.       error("kern char not found") ;
  462.    else {
  463.       nk = newkern() ;
  464.       nk->succ = paramnewstring() ;
  465.       nk->delta = transform(paramnum(),0) ;
  466.       nk->next = ai->kerns ;
  467.       ai->kerns = nk ;
  468.     }
  469. }
  470.  
  471. void
  472. handleconstruct() { /* an input line beginning with CC */
  473.    register struct adobeinfo *ai ;
  474.    register char *p ;
  475.    register struct pcc *np ;
  476.    register int n ;
  477.    struct pcc *npp = NULL;
  478.  
  479.    p = paramstring() ;
  480.    ai = findadobe(p) ;
  481.    if (ai == NULL)
  482.       error("! composite character name not found") ;
  483.    n = paramnum() ;
  484.    expect(";") ;
  485.    while (n--) {
  486.       if (strcmp(paramstring(),"PCC") != 0) return ;
  487.         /* maybe I should expect("PCC") instead, but I'm playing it safe */
  488.       np = newpcc() ;
  489.       np->partname = paramnewstring() ;
  490.       if (findadobe(np->partname)==NULL) return ;
  491.       np->xoffset = paramnum() ;
  492.       np->yoffset = paramnum() ;
  493.       np->xoffset = transform(np->xoffset, np->yoffset) ;
  494.       if (npp) npp->next = np ;
  495.       else ai->pccs = np ;
  496.       npp = np ;
  497.       expect(";") ;
  498.    }
  499. }
  500.  
  501. struct encoding *readencoding() ;
  502.  
  503. void
  504. makeaccentligs() {
  505.    register struct adobeinfo *ai, *aci ;
  506.    register char *p ;
  507.    register struct lig *nl ;
  508.    for (ai=adobechars; ai; ai=ai->next) {
  509.       p = ai->adobename ;
  510.       if (strlen(p)>2)
  511.          if ((aci=findadobe(p+1)) && (aci->adobenum > 127)) {
  512.             nl = newlig() ;
  513.             nl->succ = mymalloc((unsigned long)2) ;
  514.             *(nl->succ + 1) = 0 ;
  515.             *(nl->succ) = *p ;
  516.             nl->sub = ai->adobename ;
  517.             nl->next = aci->ligs ;
  518.             aci->ligs = nl ;
  519.          }
  520.    }
  521. }
  522.  
  523. void
  524. readadobe() {
  525.    struct adobeinfo *ai ;
  526. #ifdef VMCMS
  527.     int i;
  528. #endif
  529.  
  530. /*
  531.  *   We allocate a placeholder boundary char.
  532.  */
  533.    ai = newchar() ;
  534.    ai->adobenum = -1 ;
  535.    ai->adobename = "||" ; /* boundary character name */
  536.    while (getline()) {
  537.       switch(interest(paramstring())) {
  538. case FontName:
  539.          fontname = paramnewstring() ;
  540. #ifdef VMCMS
  541. /* fontname comes in as ebcdic but we need it asciified for tfm file
  542.    so we save it in ebfontname and change it in fontname */
  543.    ebfontname = newstring(fontname) ;
  544.    i=0;
  545.    while(fontname[i] != '\0') {
  546.       fontname[i]=ebcdic2ascii[fontname[i]];
  547.       i++;
  548.    };
  549. #endif
  550.          break ;
  551. case EncodingScheme:
  552.          codingscheme = paramnewstring() ;
  553. #ifdef VMCMS
  554. /* for codingscheme, we do the same as we did for fontname */
  555.    ebcodingscheme = newstring(codingscheme) ;
  556.    i=0;
  557.    while(codingscheme[i] != '\0') {
  558.       codingscheme[i]=ebcdic2ascii[codingscheme[i]];
  559.       i++;
  560.    }
  561. #endif
  562.          break ;
  563. case ItalicAngle:
  564.          italicangle = paramfloat() ;
  565.          break ;
  566. case IsFixedPitch:
  567.          if (*param == 't' || *param == 'T')
  568.             fixedpitch = 1 ;
  569.          else
  570.             fixedpitch = 0 ;
  571.          break ;
  572. case XHeight:
  573.          xheight = paramnum() ;
  574.          break ;
  575. case C:
  576.          handlechar() ;
  577.          break ;
  578. case KPX:
  579.          handlekern() ;
  580.          break ;
  581. case CC:
  582.          handleconstruct() ;
  583.          break ;
  584. default:
  585.          break ;
  586.       }
  587.    }
  588.    fclose(afmin) ;
  589.    afmin = 0 ;
  590. }
  591. /*
  592.  *   Re-encode the adobe font.  Assumes that the header file will
  593.  *   also contain the appropriate instructions!
  594.  */
  595. void
  596. handlereencoding() {
  597.    if (inenname) {
  598.       int i ;
  599.       struct adobeinfo *ai ;
  600.       char *p ;
  601.  
  602.       ignoreligkern = 1 ;
  603.       inencoding = readencoding(inenname) ;
  604.       for (i=0; i<256; i++)
  605.          if (0 != (ai=adobeptrs[i])) {
  606.             ai->adobenum = -1 ;
  607.             adobeptrs[i] = NULL ;
  608.          }
  609.       for (i=0; i<256; i++) {
  610.          p = inencoding->vec[i] ;
  611.          if (p && *p && 0 != (ai = findadobe(p))) {
  612.             ai->adobenum = i ;
  613.             adobeptrs[i] = ai ;
  614.          }
  615.       }
  616.       codingscheme = inencoding->name ;
  617.    }
  618.    ignoreligkern = 0 ;
  619.    if (outenname) {
  620.       outencoding = readencoding(outenname) ;
  621.    } else {
  622.       outencoding = readencoding((char *)0) ;
  623.    }
  624. }
  625.  
  626. /*
  627.  *   This routine reverses a list.  We use it because we accumulate the
  628.  *   adobeinfo list in reverse order, but when we go to map the
  629.  *   characters, we would prefer to use the original ordering.  It just
  630.  *   makes more sense.
  631.  */
  632. struct adobeinfo *revlist(p)
  633. struct adobeinfo *p ;
  634. {
  635.    struct adobeinfo *q = 0, *t ;
  636.  
  637.    while (p) {
  638.       t = p->next ;
  639.       p->next = q ;
  640.       q = p ;
  641.       p = t ;
  642.    }
  643.    return (void *)q ;
  644. }
  645.  
  646. void
  647. assignchars() {
  648.    register char **p ;
  649.    register int i, j ;
  650.    register struct adobeinfo *ai, *pai ;
  651.    int nextfree = 128 ;
  652.    struct pcc *pcp ;
  653.  
  654. /*
  655.  *   First, we assign all those that match perfectly.
  656.  */
  657.    for (i=0, p=outencoding->vec; i<256; i++, p++)
  658.       if ((ai=findadobe(*p)) && (ai->adobenum >= 0 || ai->pccs != NULL)) {
  659.          if (ai->texnum >= 0)
  660.             nexttex[i] = ai->texnum ; /* linked list */
  661.          ai->texnum = i ;
  662.          texptrs[i] = ai ;
  663.       }
  664.    if (pedantic)
  665.       return ;
  666. /*
  667.  *   Next, we assign all the others, retaining the adobe positions, possibly
  668.  *   multiply assigning characters. Unless the output encoding was
  669.  *   precisely specified.
  670.  */
  671.    for (ai=adobechars; ai; ai=ai->next)
  672.       if (ai->adobenum >= 0 && ai->texnum < 0 && texptrs[ai->adobenum]==0) {
  673.          ai->texnum = ai->adobenum ;
  674.          texptrs[ai->adobenum] = ai ;
  675.       }
  676. /*
  677.  *   Finally, we map all remaining characters into free locations beginning
  678.  *   with 128, if we know how to construct those characters.  We need to
  679.  *   make sure the component pieces are mapped.
  680.  */
  681.    adobechars = revlist(adobechars) ;
  682.    for (ai=adobechars; ai; ai=ai->next)
  683.       if (ai->texnum<0 && (ai->adobenum>=0 || ai->pccs != NULL)) {
  684.          while (texptrs[nextfree]) {
  685.             nextfree=(nextfree+1)&255 ;
  686.             if (nextfree==128) goto finishup ; /* all slots full */
  687.          }
  688.          ai->texnum = nextfree ;
  689.          texptrs[nextfree] = ai ;
  690.       }
  691. finishup:
  692. /*
  693.  *   We now check all of the composite characters.  If any of the
  694.  *   components are not mapped, we unmap the composite character.
  695.  */
  696.    for (i=0; i<256; i++) {
  697.       ai = texptrs[i] ;
  698.       if (ai && ai->pccs != NULL && ai->texnum >= 0) {
  699.          for (pcp = ai->pccs; pcp; pcp = pcp->next) {
  700.             pai = findadobe(pcp->partname) ;
  701.             if (pai == NULL || pai->texnum < 0) {
  702.                texptrs[ai->texnum] = 0 ;
  703.                ai->texnum = -1 ;
  704.                break ;
  705.             }
  706.          }
  707.       }
  708.    }
  709. /*
  710.  *   Now, if any of the characters are encoded multiple times, we want
  711.  *   ai->texnum to be the first one assigned, since that is most likely
  712.  *   to be the most important one.  So we reverse the above lists.
  713.  */
  714.    for (ai=adobechars; ai; ai=ai->next)
  715.       if (ai->texnum >= 0) {
  716.          j = -1 ;
  717.          while (nexttex[ai->texnum] >= 0) {
  718.             i = nexttex[ai->texnum] ;
  719.             nexttex[ai->texnum] = j ;
  720.             j = ai->texnum ;
  721.             ai->texnum = i ;
  722.          }
  723.          nexttex[ai->texnum] = j ;
  724.       }
  725. }
  726.  
  727. void
  728. upmap() { /* Compute uppercase mapping, when making a small caps font */
  729.    register struct adobeinfo *ai, *Ai ;
  730.    register char *p, *q ;
  731.    register struct pcc *np, *nq ;
  732.    int i ;
  733.    char lwr[50] ;
  734.  
  735. /* JLH: changed some lines below to be ascii<->ebcdic independent
  736.    any reason we don't use 'isupper'?.
  737.    Looks like we should use isupper to me --karl.  */
  738.    for (Ai=adobechars; Ai; Ai=Ai->next) {
  739.       p = Ai->adobename ;
  740.       if (isupper (*p)) {
  741.          q = lwr ;
  742.          for (; *p; p++)
  743.             *q++ = TOLOWER (*p);
  744.          *q = '\0';   /* changed this too! */
  745.  
  746.          if (0 != (ai=findadobe(lwr))) {
  747.             for (i = ai->texnum; i >= 0; i = nexttex[i])
  748.                uppercase[i] = Ai ;
  749.             for (i = Ai->texnum; i >= 0; i = nexttex[i])
  750.                lowercase[i] = ai ;
  751.          }
  752.       }
  753.    }
  754. /* Note that, contrary to the normal true/false conventions,
  755.  * uppercase[i] is NULL and lowercase[i] is non-NULL when i is the
  756.  * ASCII code of an uppercase letter; and vice versa for lowercase letters */
  757.  
  758.    if (0 != (ai=findadobe("germandbls")))
  759.       if (0 != (Ai=findadobe("S"))) { /* we also construct SS */
  760.          for (i=ai->texnum; i >= 0; i = nexttex[i])
  761.             uppercase[i] = ai ;
  762.          ai->adobenum = -1 ;
  763.          ai->width = Ai->width << 1 ;
  764.          ai->llx = Ai->llx ;
  765.          ai->lly = Ai->lly ;
  766.          ai->urx = Ai->width + Ai->urx ;
  767.          ai->ury = Ai->ury ;
  768.          ai->kerns = Ai->kerns ;
  769.          np = newpcc() ;
  770.          np->partname = "S" ;
  771.          nq = newpcc() ;
  772.          nq->partname = "S" ;
  773.          nq->xoffset = Ai->width ;
  774.          np->next = nq ;
  775.          ai->pccs = np ;
  776.       }
  777.    if ((ai=findadobe("dotlessi")))
  778.       for (i=ai->texnum; i >= 0; i = nexttex[i])
  779.          uppercase[i] = findadobe("I") ;
  780.    if ((ai=findadobe("dotlessj")))
  781.       for (i=ai->texnum; i >= 0; i = nexttex[i])
  782.          uppercase[i] = findadobe("J") ;
  783. }
  784. /* The logic above seems to work well enough, but it leaves useless characters
  785.  * like `fi' and `fl' in the font if they were present initially,
  786.  * and it omits characters like `dotlessj' if they are absent initially */
  787.  
  788. /* Now we turn to computing the TFM file */
  789.  
  790. int lf, lh, nw, nh, nd, ni, nl, nk, ne, np ;
  791.  
  792. void
  793. write16(what)
  794. register short what ;
  795. {
  796.    (void)fputc(what >> 8, tfmout) ;
  797.    (void)fputc(what & 255, tfmout) ;
  798. }
  799.  
  800. void
  801. writearr(p, n)
  802. register long *p ;
  803. register int n ;
  804. {
  805.    while (n) {
  806.       write16((short)(*p >> 16)) ;
  807.       write16((short)(*p & 65535)) ;
  808.       p++ ;
  809.       n-- ;
  810.    }
  811. }
  812.  
  813. void
  814. makebcpl(p, s, n)
  815. register long *p ;
  816. register char *s ;
  817. register int n ;
  818. {
  819.    register long t ;
  820.    register long sc ;
  821.  
  822.    if (strlen(s) < n)
  823.       n = strlen(s) ;
  824.    t = ((long)n) << 24 ;
  825.    sc = 16 ;
  826.    while (n > 0) {
  827.       t |= ((long)(*(unsigned char *)s++)) << sc ;
  828.       sc -= 8 ;
  829.       if (sc < 0) {
  830.          *p++ = t ;
  831.          t = 0 ;
  832.          sc = 24 ;
  833.       }
  834.       n-- ;
  835.    }
  836.    *p++ = t ;
  837. }
  838.  
  839. int source[257] ;
  840. int unsort[257] ;
  841.  
  842. /*
  843.  *   Next we need a routine to reduce the number of distinct dimensions
  844.  *   in a TFM file. Given an array what[0]...what[oldn-1], we want to
  845.  *   group its elements into newn clusters, in such a way that the maximum
  846.  *   difference between elements of a cluster is as small as possible.
  847.  *   Furthermore, what[0]=0, and this value must remain in a cluster by
  848.  *   itself. Data such as `0 4 6 7 9' with newn=3 shows that an iterative
  849.  *   scheme in which 6 is first clustered with 7 will not work. So we
  850.  *   borrow a neat algorithm from METAFONT to find the true optimum.
  851.  *   Memory location what[oldn] is set to 0x7fffffffL for convenience.
  852.  */
  853. long nextd ; /* smallest value that will give a different mincover */
  854. int
  855. mincover(what,d) /* tells how many clusters result, given max difference d */
  856. register long d ;
  857. long *what ;
  858. {
  859.    register int m ;
  860.    register long l ;
  861.    register long *p ;
  862.  
  863.    nextd = 0x7fffffffL ;
  864.    p = what+1 ;
  865.    m = 1 ;
  866.    while (*p<0x7fffffffL) {
  867.       m++ ;
  868.       l = *p ;
  869.       while (*++p <= l+d) ;
  870.       if (*p-l < nextd) nextd = *p-l ;
  871.    }
  872.    return (m) ;
  873. }
  874.  
  875. void
  876. remap(what, oldn, newn)
  877. long *what ;
  878. int oldn, newn ;
  879. {
  880.    register int i, j ;
  881.    register long d, l ;
  882.  
  883.    what[oldn] = 0x7fffffffL ;
  884.    for (i=oldn-1; i>0; i--) {
  885.       d = what[i] ;
  886.       for (j=i; what[j+1]<d; j++) {
  887.          what[j] = what[j+1] ;
  888.          source[j] = source[j+1] ;
  889.       }
  890.       what[j] = d ;
  891.       source[j] = i ;
  892.    } /* Tom, don't let me ever catch you using bubblesort again! -- Don */
  893.  
  894.    i = mincover(what, 0L) ;
  895.    d = nextd ;
  896.    while (mincover(what,d+d)>newn) d += d ;
  897.    while (mincover(what,d)>newn) d = nextd ;
  898.  
  899.    i = 1 ;
  900.    j = 0 ;
  901.    while (i<oldn) {
  902.       j++ ;
  903.       l = what[i] ;
  904.       unsort[source[i]] = j ;
  905.       while (what[++i] <= l+d) {
  906.          unsort[source[i]] = j ;
  907.          if (i-j == oldn-newn) d = 0 ;
  908.       }
  909.       what[j] = (l+what[i-1])/2 ;
  910.    }
  911. }
  912.  
  913. long checksum() {
  914.    int i ;
  915.    long s1 = 0, s2 = 0 ;
  916.    char *p ;
  917.    struct adobeinfo *ai ;
  918.  
  919.    for (i=0; i<256; i++)
  920.       if (0 != (ai=adobeptrs[i])) {
  921.          s1 = (s1 << 1) ^ ai->width ;
  922.          for (p=ai->adobename; *p; p++)
  923. #ifndef VMCMS
  924.             s2 = (s2 * 3) + *p ;
  925. #else
  926.             s2 = (s2 * 3) + ebcdic2ascii[*p] ;
  927. #endif
  928.       }
  929.    s1 = (s1 << 1) ^ s2 ;
  930.    return s1 ;
  931. }
  932.  
  933. /*
  934.  *   The next routine simply scales something.
  935.  *   Input is in 1000ths of an em.  Output is in FIXFACTORths of 1000.
  936.  */
  937. #define FIXFACTOR (0x100000L) /* 2^{20}, the unit fixnum */
  938. long
  939. scale(what)
  940. long what ;
  941. {
  942.    return(((what / 1000) << 20) +
  943.           (((what % 1000) << 20) + 500) / 1000) ;
  944. }
  945.  
  946. long *header, *charinfo, *width, *height, *depth, *ligkern, *kern, *tparam,
  947.      *italic ;
  948. long *tfmdata ;
  949.  
  950. void
  951. buildtfm() {
  952.    register int i, j ;
  953.    register struct adobeinfo *ai ;
  954.  
  955.    header = tfmdata ;
  956.    cksum = checksum() ;
  957.    header[0] = cksum ;
  958.    header[1] = 0xa00000 ; /* 10pt design size */
  959.    makebcpl(header+2, codingscheme, 39) ;
  960.    makebcpl(header+12, fontname, 19) ;
  961.    lh = 17 ;
  962.    charinfo = header + lh ;
  963.  
  964.    for (i=0; i<256 && adobeptrs[i]==NULL; i++) ;
  965.    bc = i ;
  966.    for (i=255; i>=0 && adobeptrs[i]==NULL; i--) ;
  967.    ec = i;
  968.    if (ec < bc)
  969.       error("! no Adobe characters") ;
  970.  
  971.    width = charinfo + (ec - bc + 1) ;
  972.    width[0] = 0 ;
  973.    nw++ ;
  974.    for (i=bc; i<=ec; i++)
  975.       if (0 != (ai=adobeptrs[i])) {
  976.          width[nw]=ai->width ;
  977.          for (j=1; width[j]!=ai->width; j++) ;
  978.          ai->wptr = j ;
  979.          if (j==nw)
  980.             nw++ ;
  981.       }
  982.    if (nw>256)
  983.       error("! 256 chars with different widths") ;
  984.    depth = width + nw ;
  985.    depth[0] = 0 ;
  986.    nd = 1 ;
  987.    for (i=bc; i<=ec; i++)
  988.       if (0 != (ai=adobeptrs[i])) {
  989.          depth[nd] = -ai->lly ;
  990.          for (j=0; depth[j]!=-ai->lly; j++) ;
  991.          ai->dptr = j ;
  992.          if (j==nd)
  993.             nd++ ;
  994.       }
  995.    if (nd > 16) {
  996.       remap(depth, nd, 16) ;
  997.       nd = 16 ;
  998.       for (i=bc; i<=ec; i++)
  999.          if (0 != (ai=adobeptrs[i]))
  1000.             ai->dptr = unsort[ai->dptr] ;
  1001.    }
  1002.    height = depth + nd ;
  1003.    height[0] = 0 ;
  1004.    nh = 1 ;
  1005.    for (i=bc; i<=ec; i++)
  1006.       if (0 != (ai=adobeptrs[i])) {
  1007.          height[nh]=ai->ury ;
  1008.          for (j=0; height[j]!=ai->ury; j++) ;
  1009.          ai->hptr = j ;
  1010.          if (j==nh)
  1011.             nh++ ;
  1012.       }
  1013.    if (nh > 16) {
  1014.       remap(height, nh, 16) ;
  1015.       nh = 16 ;
  1016.       for (i=bc; i<=ec; i++)
  1017.          if (0 != (ai=adobeptrs[i]))
  1018.             ai->hptr = unsort[ai->hptr] ;
  1019.    }
  1020.    italic  = height + nh ;
  1021.    italic[0] = 0 ;
  1022.    ni = 1 ;
  1023.    for (i=bc; i<=ec; i++)
  1024.       if (0 != (ai=adobeptrs[i])) {
  1025.          italic[ni] = ai->urx - ai->width ;
  1026.          if (italic[ni]<0)
  1027.             italic[ni] = 0 ;
  1028.          for (j=0; italic[j]!=italic[ni]; j++) ;
  1029.          ai->iptr = j ;
  1030.          if (j==ni)
  1031.             ni++ ;
  1032.       }
  1033.    if (ni > 64) {
  1034.       remap(italic, ni, 64) ;
  1035.       ni = 64 ;
  1036.       for (i=bc; i<=ec; i++)
  1037.          if (0 != (ai=adobeptrs[i]))
  1038.             ai->iptr = unsort[ai->iptr] ;
  1039.    }
  1040.  
  1041.    for (i=bc; i<=ec; i++)
  1042.       if (0 != (ai=adobeptrs[i]))
  1043.          charinfo[i-bc] = ((long)(ai->wptr)<<24) +
  1044.                            ((long)(ai->hptr)<<20) +
  1045.                             ((long)(ai->dptr)<<16) +
  1046.                              ((long)(ai->iptr)<<10) ;
  1047.  
  1048.    ligkern = italic + ni ;
  1049.    nl = 0 ; /* ligatures and kerns omitted from raw Adobe font */
  1050.    kern = ligkern + nl ;
  1051.    nk = 0 ;
  1052.  
  1053.    newslant = (double)slant - efactor * tan(italicangle*(3.1415926535/180.0)) ;
  1054.    tparam = kern + nk ;
  1055.    tparam[0] = (long)(FIXFACTOR * newslant + 0.5) ;
  1056.    tparam[1] = scale((long)fontspace) ;
  1057.    tparam[2] = (fixedpitch ? 0 : scale((long)(300*efactor+0.5))) ;
  1058.    tparam[3] = (fixedpitch ? 0 : scale((long)(100*efactor+0.5))) ;
  1059.    tparam[4] = scale((long)xheight) ;
  1060.    tparam[5] = scale((long)(1000*efactor+0.5)) ;
  1061.    np = 6 ;
  1062. }
  1063.  
  1064. void
  1065. writesarr(what, len)
  1066. long *what ;
  1067. int len ;
  1068. {
  1069.    register long *p ;
  1070.    int i ;
  1071.  
  1072.    p = what ;
  1073.    i = len ;
  1074.    while (i) {
  1075.       *p = scale(*p) ;
  1076.       (void)scale(*p) ; /* need this kludge for some compilers */
  1077.       p++ ;
  1078.       i-- ;
  1079.    }
  1080.    writearr(what, len) ;
  1081. }
  1082.  
  1083. void
  1084. writetfm() {
  1085.    lf = 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np ;
  1086.    write16(lf) ;
  1087.    write16(lh) ;
  1088.    write16(bc) ;
  1089.    write16(ec) ;
  1090.    write16(nw) ;
  1091.    write16(nh) ;
  1092.    write16(nd) ;
  1093.    write16(ni) ;
  1094.    write16(nl) ;
  1095.    write16(nk) ;
  1096.    write16(ne) ;
  1097.    write16(np) ;
  1098.    writearr(header, lh) ;
  1099.    writearr(charinfo, ec-bc+1) ;
  1100.    writesarr(width, nw) ;
  1101.    writesarr(height, nh) ;
  1102.    writesarr(depth, nd) ;
  1103.    writesarr(italic, ni) ;
  1104.    writearr(ligkern, nl) ;
  1105.    writesarr(kern, nk) ;
  1106.    writearr(tparam, np) ;
  1107. }
  1108.  
  1109. /* OK, the TFM file is done! Now for our next trick, the VPL file. */
  1110.  
  1111. /* For TeX we want to compute a character height that works properly
  1112.  * with accents. The following list of accents doesn't need to be complete. */
  1113. /*
  1114.  *   We only do this if the xheight has a reasonable value.
  1115.  *   (>50)
  1116.  */
  1117. char *accents[] = { "acute", "tilde", "caron", "dieresis", NULL} ;
  1118. int
  1119. texheight(ai)
  1120. register struct adobeinfo *ai ;
  1121. {
  1122.    register char **p;
  1123.    register struct adobeinfo *aci, *acci ;
  1124.    if (xheight <= 50 || *(ai->adobename + 1)) return (ai->ury) ;
  1125.                                            /* that was the simple case */
  1126.    for (p=accents; *p; p++)  /* otherwise we look for accented letters */
  1127.       if (0 != (aci=findadobe(*p))) {
  1128.          strcpy(buffer,ai->adobename) ;
  1129.          strcat(buffer,*p) ;
  1130.          if (0 != (acci=findadobe(buffer)))
  1131.             return (acci->ury - aci->ury + xheight) ;
  1132.       }
  1133.    return (ai->ury) ;
  1134. }
  1135.  
  1136. /* modified tgr to eliminate varargs problems */
  1137.  
  1138. #define vout(s)  fprintf(vplout, s)
  1139. int level ; /* the depth of parenthesis nesting in VPL file being written */
  1140. void vlevout() {
  1141.    register int l = level ;
  1142.    while (l--) vout("   ") ;
  1143. }
  1144. void vlevnlout() {
  1145.    vout("\n") ;
  1146.    vlevout() ;
  1147. }
  1148. #define voutln(str) {fprintf(vplout,"%s\n",str);vlevout();}
  1149. #define voutln2(f,s) {fprintf(vplout,f,s);vlevnlout();}
  1150. #define voutln3(f,a,b) {fprintf(vplout,f,a,b);vlevnlout();}
  1151. #define voutln4(f,a,b,c) {fprintf(vplout,f,a,b,c);vlevnlout();}
  1152. void
  1153. vleft()
  1154. {
  1155.    level++ ;
  1156.    vout("(") ;
  1157. }
  1158.  
  1159. void
  1160. vright()
  1161. {
  1162.    level-- ;
  1163.    voutln(")") ;
  1164. }
  1165.  
  1166. int forceoctal = 0 ;
  1167.  
  1168. char vcharbuf[6] ;
  1169. char *vchar(c)
  1170. int c ;
  1171. {
  1172.    if (forceoctal == 0 && ISALNUM (c))
  1173.       (void) sprintf(vcharbuf,"C %c",
  1174. #ifndef VMCMS
  1175.       c) ;
  1176. #else
  1177.       ascii2ebcdic[c]) ;
  1178. #endif
  1179.    else (void) sprintf(vcharbuf,"O %o", (unsigned)c) ;
  1180.    return (vcharbuf) ;
  1181. }
  1182.  
  1183. void
  1184. writevpl()
  1185. {
  1186.    register int i, j, k ;
  1187.    register struct adobeinfo *ai ;
  1188.    register struct lig *nlig ;
  1189.    register struct kern *nkern ;
  1190.    register struct pcc *npcc ;
  1191.    struct adobeinfo *asucc, *asub, *api ;
  1192.    int xoff, yoff, ht ;
  1193.    char unlabeled ;
  1194.  
  1195.    voutln2("(VTITLE Created by %s)", titlebuf) ;
  1196.    voutln("(COMMENT Please edit that VTITLE if you edit this file)") ;
  1197.    (void)sprintf(obuffer, "TeX-%s%s%s%s", outname,
  1198.       (efactor==1.0? "" : "-E"), (slant==0.0? "" : "-S"),
  1199.                  (makevpl==1? "" : "-CSC")) ;
  1200.    if (strlen(obuffer)>19) { /* too long, will retain first 9 and last 10 */
  1201.       register char *p, *q ;
  1202.       for (p = &obuffer[9], q = &obuffer[strlen(obuffer)-10] ; p<&obuffer[19];
  1203.               p++, q++) *p = *q ;
  1204.       obuffer[19] = '\0' ;
  1205.    }
  1206.    voutln2("(FAMILY %s)" , obuffer) ;
  1207.    {
  1208.       char tbuf[300] ;
  1209.  
  1210.       sprintf(tbuf, "%s + %s", outencoding->name,
  1211. #ifndef VMCMS
  1212.          codingscheme) ;
  1213. #else
  1214.          ebcodingscheme) ;
  1215. #endif
  1216.       if (strlen(tbuf) > 39) {
  1217.          error("Coding scheme too long; shortening to 39 characters.") ;
  1218.          tbuf[39] = 0 ;
  1219.       }
  1220.       voutln2("(CODINGSCHEME %s)", tbuf) ;
  1221.    }
  1222.    voutln("(DESIGNSIZE R 10.0)") ;
  1223.    voutln("(DESIGNUNITS R 1000)") ;
  1224.    voutln("(COMMENT DESIGNSIZE (1 em) IS IN POINTS)") ;
  1225.    voutln("(COMMENT OTHER DIMENSIONS ARE MULTIPLES OF DESIGNSIZE/1000)") ;
  1226.    voutln2("(CHECKSUM O %lo)",cksum ^ 0xffffffff) ;
  1227.    if (boundarychar >= 0)
  1228.       voutln2("(BOUNDARYCHAR O %lo)", (unsigned long)boundarychar) ;
  1229.    vleft() ; voutln("FONTDIMEN") ;
  1230.    if (newslant)
  1231.       voutln2("(SLANT R %f)", newslant) ;
  1232.    voutln2("(SPACE D %d)", fontspace) ;
  1233.    if (! fixedpitch) {
  1234.       voutln2("(STRETCH D %d)", transform(200,0)) ;
  1235.       voutln2("(SHRINK D %d)", transform(100,0)) ;
  1236.    }
  1237.    voutln2("(XHEIGHT D %d)", xheight) ;
  1238.    voutln2("(QUAD D %d)", transform(1000,0)) ;
  1239.    voutln2("(EXTRASPACE D %d)", fixedpitch ? fontspace : transform(111, 0)) ;
  1240.    vright() ;
  1241.    vleft() ; voutln("MAPFONT D 0");
  1242.    voutln2("(FONTNAME %s)", outname) ;
  1243.    voutln2("(FONTCHECKSUM O %lo)", (unsigned long)cksum) ;
  1244.    vright() ;
  1245.    if (makevpl>1) {
  1246.       vleft() ; voutln("MAPFONT D 1");
  1247.       voutln2("(FONTNAME %s)", outname) ;
  1248.       voutln2("(FONTAT D %d)", (int)(1000.0*capheight+0.5)) ;
  1249.       voutln2("(FONTCHECKSUM O %lo)", (unsigned long)cksum) ;
  1250.       vright() ;
  1251.    }
  1252.  
  1253.    for (i=0; i<256 && texptrs[i]==NULL; i++) ;
  1254.    bc = i ;
  1255.    for (i=255; i>=0 && texptrs[i]==NULL; i--) ;
  1256.    ec = i;
  1257.  
  1258.    vleft() ; voutln("LIGTABLE") ;
  1259.    ai = findadobe("||") ;
  1260.    unlabeled = 1 ;
  1261.    for (nlig=ai->ligs; nlig; nlig=nlig->next)
  1262.       if (0 != (asucc=findadobe(nlig->succ))) {
  1263.          if (0 != (asub=findadobe(nlig->sub)))
  1264.             if (asucc->texnum>=0)
  1265.                if (asub->texnum>=0) {
  1266.                   if (unlabeled) {
  1267.                      voutln("(LABEL BOUNDARYCHAR)") ;
  1268.                      unlabeled = 0 ;
  1269.                   }
  1270.                   for (j = asucc->texnum; j >= 0; j = nexttex[j]) {
  1271.                      voutln4("(%s %s O %o)", vplligops[nlig->op],
  1272.                          vchar(j), (unsigned)asub->texnum) ;
  1273.                   }
  1274.                }
  1275.        }
  1276.    if (! unlabeled) voutln("(STOP)") ;
  1277.    for (i=bc; i<=ec; i++)
  1278.       if ((ai=texptrs[i]) && ai->texnum == i) {
  1279.          unlabeled = 1 ;
  1280.          if (uppercase[i]==NULL) /* omit ligatures from smallcap lowercase */
  1281.             for (nlig=ai->ligs; nlig; nlig=nlig->next)
  1282.                if (0 != (asucc=findadobe(nlig->succ)))
  1283.                   if (0 != (asub=findadobe(nlig->sub)))
  1284.                      if (asucc->texnum>=0)
  1285.                         if (asub->texnum>=0) {
  1286.                            if (unlabeled) {
  1287.                               for (j = ai->texnum; j >= 0; j = nexttex[j])
  1288.                                  voutln2("(LABEL %s)", vchar(j)) ;
  1289.                               unlabeled = 0 ;
  1290.                            }
  1291.                            for (j = asucc->texnum; j >= 0; j = nexttex[j]) {
  1292.                               voutln4("(%s %s O %o)", vplligops[nlig->op],
  1293.                                    vchar(j), (unsigned)asub->texnum) ;
  1294.                               if (nlig->boundleft)
  1295.                                  break ;
  1296.                            }
  1297.                         }
  1298.          for (nkern = (uppercase[i] ? uppercase[i]->kerns : ai->kerns);
  1299.                     nkern; nkern=nkern->next)
  1300.             if (0 != (asucc=findadobe(nkern->succ)))
  1301.                for (j = asucc->texnum; j >= 0; j = nexttex[j]) {
  1302.                   if (uppercase[j]==NULL) {
  1303.                      if (unlabeled) {
  1304.                         for (k = ai->texnum; k >= 0; k = nexttex[k])
  1305.                            voutln2("(LABEL %s)", vchar(k)) ;
  1306.                         unlabeled = 0 ;
  1307.                      }
  1308.                      if (uppercase[i]) {
  1309.                         if (lowercase[j]) {
  1310.                            for (k=lowercase[j]->texnum; k >= 0; k = nexttex[k])
  1311.                               voutln3("(KRN %s R %.1f)", vchar(k),
  1312.                                     capheight*nkern->delta) ;
  1313.                         } else voutln3("(KRN %s R %.1f)",
  1314.                                  vchar(j), capheight*nkern->delta) ;
  1315.                      } else {
  1316.                         voutln3("(KRN %s R %d)", vchar(j),
  1317.                                 nkern->delta) ;
  1318.                         if (lowercase[j])
  1319.                            for (k=lowercase[j]->texnum; k >= 0; k = nexttex[k])
  1320.                               voutln3("(KRN %s R %.1f)", vchar(k),
  1321.                                 capheight*nkern->delta) ;
  1322.                      }
  1323.                   }
  1324.                }
  1325.          if (! unlabeled) voutln("(STOP)") ;
  1326.       }
  1327.    vright() ;
  1328.  
  1329.    for (i=bc; i<=ec; i++)
  1330.       if (0 != (ai=texptrs[i])) {
  1331.          vleft() ; fprintf(vplout, "CHARACTER %s", vchar(i)) ;
  1332.          if (*vcharbuf=='C') {
  1333.             voutln("") ;
  1334.          } else
  1335.             voutln2(" (comment %s)", ai->adobename) ;
  1336.          if (uppercase[i]) {
  1337.             ai=uppercase[i] ;
  1338.             voutln2("(CHARWD R %.1f)", capheight * (ai->width)) ;
  1339.             if (0 != (ht=texheight(ai)))
  1340.                voutln2("(CHARHT R %.1f)", capheight * ht) ;
  1341.             if (ai->lly)
  1342.                voutln2("(CHARDP R %.1f)", -capheight * ai->lly) ;
  1343.             if (ai->urx > ai->width)
  1344.                voutln2("(CHARIC R %.1f)", capheight * (ai->urx - ai->width)) ;
  1345.          } else {
  1346.             voutln2("(CHARWD R %d)", ai->width) ;
  1347.             if (0 != (ht=texheight(ai)))
  1348.                voutln2("(CHARHT R %d)", ht) ;
  1349.             if (ai->lly)
  1350.                voutln2("(CHARDP R %d)", -ai->lly) ;
  1351.             if (ai->urx > ai->width)
  1352.                voutln2("(CHARIC R %d)", ai->urx - ai->width) ;
  1353.          }
  1354.          if (ai->adobenum != i || uppercase[i]) {
  1355.             vleft() ; voutln("MAP") ;
  1356.             if (uppercase[i]) voutln("(SELECTFONT D 1)") ;
  1357.             if (ai->pccs && ai->adobenum < 0) {
  1358.                xoff = 0 ; yoff = 0 ;
  1359.                for (npcc = ai->pccs; npcc; npcc=npcc->next)
  1360.                   if (0 != (api=findadobe(npcc->partname)))
  1361.                      if (api->texnum>=0) {
  1362.                         if (npcc->xoffset != xoff) {
  1363.                            if (uppercase[i]) {
  1364.                               voutln2("(MOVERIGHT R %.1f)",
  1365.                                       capheight * (npcc->xoffset - xoff)) ;
  1366.                            } else voutln2("(MOVERIGHT R %d)",
  1367.                                       npcc->xoffset - xoff) ;
  1368.                            xoff = npcc->xoffset ;
  1369.                         }
  1370.                         if (npcc->yoffset != yoff) {
  1371.                            if (uppercase[i]) {
  1372.                               voutln2("(MOVEUP R %.1f)",
  1373.                                       capheight * (npcc->yoffset - yoff)) ;
  1374.                            } else voutln2("(MOVEUP R %d)",
  1375.                                       npcc->yoffset - yoff) ;
  1376.                            yoff = npcc->yoffset ;
  1377.                         }
  1378.                         voutln2("(SETCHAR O %o)", (unsigned)api->adobenum) ;
  1379.                         xoff += texptrs[api->texnum]->width ;
  1380.                      }
  1381.             } else voutln2("(SETCHAR O %o)", (unsigned)ai->adobenum) ;
  1382.             vright() ;
  1383.          }
  1384.          vright() ;
  1385.       }
  1386.    if (level) error("! I forgot to match the parentheses") ;
  1387. }
  1388.  
  1389. void usage(f)
  1390. FILE *f ;
  1391. {
  1392.    (void)fprintf(f,
  1393.  "afm2tfm 7.8, Copyright 1990-93 by Radical Eye Software\n") ;
  1394.    (void)fprintf(f,
  1395.  "Usage: afm2tfm foo[.afm] [-O] [-u] [-v|-V bar[.vpl]]\n") ;
  1396.    (void)fprintf(f,
  1397.  "                 [-e expansion] [-s slant] [-c capheight]\n") ;
  1398.    (void)fprintf(f,
  1399.  "                 [-p|-t|-T encodingfile] [foo[.tfm]]\n") ;
  1400. }
  1401.  
  1402. void
  1403. openfiles(argc, argv)
  1404. int argc ;
  1405. char *argv[] ;
  1406. {
  1407.    register int lastext ;
  1408.    register int i ;
  1409.    int arginc ;
  1410.    tfmout = (FILE *)NULL ;
  1411.    if (argc == 1) {
  1412.       usage(stdout) ;
  1413.       exit(1) ;
  1414.    }
  1415.  
  1416. #if defined(MSDOS) || defined(OS2) || defined(ATARIST)
  1417.    /* Make VPL file identical to that created under Unix */
  1418.    (void)sprintf(titlebuf, "afm2tfm %s", argv[1]) ;
  1419. #else
  1420. #ifdef VMCMS
  1421.    /* Make VPL file identical to that created under Unix */
  1422.    (void)sprintf(titlebuf, "afm2tfm %s", argv[1]) ;
  1423. #else
  1424.    (void)sprintf(titlebuf, "%s %s", argv[0], argv[1]) ;
  1425. #endif
  1426. #endif
  1427.    (void)strcpy(inname, argv[1]) ;
  1428.    lastext = -1 ;
  1429.    for (i=0; inname[i]; i++)
  1430.       if (inname[i] == '.')
  1431.          lastext = i ;
  1432.       else if (inname[i] == '/' || inname[i] == ':')
  1433.          lastext = -1 ;
  1434.    if (lastext == -1) (void)strcat(inname, ".afm") ;
  1435.  
  1436.    while (argc>2 && *argv[2]=='-') {
  1437.       arginc = 2 ;
  1438.       i = argv[2][1] ;
  1439.       if (i == '/')
  1440.          i = argv[2][2] - 32 ; /* /a ==> A for VMS */
  1441.       switch (i) {
  1442. case 'V': makevpl++ ;
  1443. case 'v': makevpl++ ;
  1444.          (void)strcpy(outname, argv[3]) ;
  1445.          lastext = -1 ;
  1446.          for (i=0; outname[i]; i++)
  1447.             if (outname[i] == '.')
  1448.                lastext = i ;
  1449.             else if (outname[i] == '/' || outname[i] == ':')
  1450.                lastext = -1 ;
  1451.          if (lastext == -1) (void)strcat(outname, ".vpl") ;
  1452. #ifndef VMCMS
  1453. #ifndef ATARIST
  1454.          if ((vplout=fopen(outname, WRITEBIN))==NULL)
  1455. #else
  1456.          if ((vplout=fopen(outname, "w"))==NULL)
  1457. #endif
  1458. #else
  1459.          if ((vplout=fopen(outname, "w"))==NULL)
  1460. #endif
  1461.             error("! can't open vpl output file") ;
  1462.          break ;
  1463. case 'e': if (sscanf(argv[3], "%f", &efactor)==0 || efactor<0.01)
  1464.             error("! Bad extension factor") ;
  1465.          efactorparam = argv[3] ;
  1466.          break ;
  1467. case 'c':
  1468.          if (sscanf(argv[3], "%f", &capheight)==0 || capheight<0.01)
  1469.             error("! Bad small caps height") ;
  1470.          break ;
  1471. case 's': if (sscanf(argv[3], "%f", &slant)==0)
  1472.             error("! Bad slant parameter") ;
  1473.          slantparam = argv[3] ;
  1474.          break ;
  1475. case 'P':
  1476. case 'p':
  1477.          inenname = argv[3] ;
  1478.          break ;
  1479. case 'T':
  1480.          inenname = outenname = argv[3] ;
  1481.          break ;
  1482. case 't':
  1483.          outenname = argv[3] ;
  1484.          break ;
  1485. case 'O':
  1486.          forceoctal = 1 ;
  1487.          arginc = 1 ;
  1488.          break ;
  1489. case 'u':
  1490.          pedantic = 1 ;
  1491.          arginc = 1 ;
  1492.          break ;
  1493. default: (void)fprintf(stderr, "Unknown option %s %s will be ignored.\n",
  1494.                          argv[2], argv[3]) ;
  1495.       }
  1496.       for (i=0; i<arginc; i++) {
  1497.          (void)sprintf(titlebuf + strlen(titlebuf), " %s", argv[2]) ;
  1498.          argv++ ;
  1499.          argc-- ;
  1500.       }
  1501.    }
  1502.  
  1503.    if ((afmin=fopen(inname, "r"))==NULL)
  1504.       error("! can't open afm input file") ;
  1505.  
  1506.    if (argc>3 || (argc==3 && *argv[2]=='-')) {
  1507.       usage(stderr) ;
  1508.       error("! incorrect usage") ;
  1509.    }
  1510.  
  1511.    if (argc == 2) (void)strcpy(outname, inname) ;
  1512.    else (void)strcpy(outname, argv[2]) ;
  1513.  
  1514.    lastext = -1 ;
  1515.    for (i=0; outname[i]; i++)
  1516.       if (outname[i] == '.')
  1517.          lastext = i ;
  1518.       else if (outname[i] == '/' || outname[i] == ':' || outname[i] == '\\')
  1519.          lastext = -1 ;
  1520.    if (argc == 2) {
  1521.       outname[lastext] = 0 ;
  1522.       lastext = -1 ;
  1523.    }
  1524.    if (lastext == -1) {
  1525.       lastext = strlen(outname) ;
  1526.       (void)strcat(outname, ".tfm") ;
  1527.    }
  1528.    if (tfmout == NULL && (tfmout=fopen(outname, WRITEBIN))==NULL)
  1529.       error("! can't open tfm output file") ;
  1530.    outname[lastext] = 0 ;
  1531. /*
  1532.  *   Now we strip off any directory information, so we only use the
  1533.  *   base name in the vf file.  We accept any of /, :, or \ as directory
  1534.  *   delimiters, so none of these are available for use inside the
  1535.  *   base name; this shouldn't be a problem.
  1536.  */
  1537.    for (i=0, lastext=0; outname[i]; i++)
  1538.       if (outname[i] == '/' || outname[i] == ':' || outname[i] == '\\')
  1539.          lastext = i + 1 ;
  1540.    if (lastext)
  1541.       strcpy(outname, outname + lastext) ;
  1542. }
  1543. /*
  1544.  *   Some routines to remove kerns that match certain patterns.
  1545.  */
  1546. struct kern *rmkernmatch(k, s)
  1547. struct kern *k ;
  1548. char *s ;
  1549. {
  1550.    struct kern *nk ;
  1551.  
  1552.    while (k && strcmp(k->succ, s)==0)
  1553.       k = k->next ;
  1554.    if (k) {
  1555.       for (nk = k; nk; nk = nk->next)
  1556.          while (nk->next && strcmp(nk->next->succ, s)==0)
  1557.             nk->next = nk->next->next ;
  1558.    }
  1559.    return k ;
  1560. }
  1561. /*
  1562.  *   Recursive to one level.
  1563.  */
  1564. void rmkern(s1, s2, ai)
  1565. char *s1, *s2 ;
  1566. struct adobeinfo *ai ;
  1567. {
  1568.    if (ai == 0) {
  1569.       if (strcmp(s1, "*") == 0) {
  1570.          for (ai=adobechars; ai; ai = ai->next)
  1571.             rmkern(s1, s2, ai) ;
  1572.          return ;
  1573.       } else {
  1574.          ai = findadobe(s1) ;
  1575.          if (ai == 0)
  1576.             return ;
  1577.       }
  1578.    }
  1579.    if (strcmp(s2, "*")==0)
  1580.       ai->kerns = 0 ; /* drop them on the floor */
  1581.    else
  1582.       ai->kerns = rmkernmatch(ai->kerns, s2) ;
  1583. }
  1584. int sawligkern ;
  1585. /*
  1586.  *   Reads a ligkern line, if this is one.  Assumes the first character
  1587.  *   passed is `%'.
  1588.  */
  1589. void checkligkern(s)
  1590. char *s ;
  1591. {
  1592.    char *oparam = param ;
  1593.    char *mlist[5] ;
  1594.    int n ;
  1595.  
  1596.    s++ ;
  1597.    while (*s && *s <= ' ')
  1598.       s++ ;
  1599.    if (strncmp(s, "LIGKERN", 7)==0) {
  1600.       sawligkern = 1 ;
  1601.       s += 7 ;
  1602.       while (*s && *s <= ' ')
  1603.          s++ ;
  1604.       param = s ;
  1605.       while (*param) {
  1606.          for (n=0; n<5;) {
  1607.             if (*param == 0)
  1608.                break ;
  1609.             mlist[n] = paramstring() ;
  1610.             if (strcmp(mlist[n], ";") == 0)
  1611.                break ;
  1612.             n++ ;
  1613.          }
  1614.          if (n > 4)
  1615.             error("! too many parameters in lig kern data") ;
  1616.          if (n < 3)
  1617.             error("! too few parameters in lig kern data") ;
  1618.          if (n == 3 && strcmp(mlist[1], "{}") == 0) { /* rmkern command */
  1619.             rmkern(mlist[0], mlist[2], (struct adobeinfo *)0) ;
  1620.          } else if (n == 3 && strcmp(mlist[0], "||") == 0 &&
  1621.                               strcmp(mlist[1], "=") == 0) { /* bc command */
  1622.             struct adobeinfo *ai = findadobe("||") ;
  1623.  
  1624.             if (boundarychar != -1)
  1625.                error("! multiple boundary character commands?") ;
  1626.             if (sscanf(mlist[2], "%d", &n) != 1)
  1627.                error("! expected number assignment for boundary char") ;
  1628.             if (n < 0 || n > 255)
  1629.                error("! boundary character number must be 0..255") ;
  1630.             boundarychar = n ;
  1631.             if (ai == 0)
  1632.                error("! internal error: boundary char") ;
  1633.             ai->texnum = n ; /* prime the pump, so to speak, for lig/kerns */
  1634.          } else if (n == 4) {
  1635.             int op = -1 ;
  1636.             struct adobeinfo *ai ;
  1637.  
  1638.             for (n=0; encligops[n]; n++)
  1639.                if (strcmp(mlist[2], encligops[n])==0) {
  1640.                   op = n ;
  1641.                   break ;
  1642.                }
  1643.             if (op < 0)
  1644.                error("! bad ligature op specified") ;
  1645.             if (0 != (ai = findadobe(mlist[0]))) {
  1646.                struct lig *lig ;
  1647.  
  1648.                if (findadobe(mlist[2]))     /* remove coincident kerns */
  1649.                   rmkern(mlist[0], mlist[1], ai) ;
  1650.                if (strcmp(mlist[3], "||") == 0)
  1651.                   error("! you can't lig to the boundary character!") ;
  1652.                if (! fixedpitch) { /* fixed pitch fonts get *0* ligs */
  1653.                   for (lig=ai->ligs; lig; lig = lig->next)
  1654.                      if (strcmp(lig->succ, mlist[1]) == 0)
  1655.                         break ; /* we'll re-use this structure */
  1656.                   if (lig == 0) {
  1657.                      lig = newlig() ;
  1658.                      lig->succ = newstring(mlist[1]) ;
  1659.                      lig->next = ai->ligs ;
  1660.                      ai->ligs = lig ;
  1661.                   }
  1662.                   lig->sub = newstring(mlist[3]) ;
  1663.                   lig->op = op ;
  1664.                   if (strcmp(mlist[1], "||")==0) {
  1665.                      lig->boundleft = 1 ;
  1666.                      if (strcmp(mlist[0], "||")==0)
  1667.                         error("! you can't lig boundarychar boundarychar!") ;
  1668.                   } else
  1669.                      lig->boundleft = 0 ;
  1670.                }
  1671.             }
  1672.          } else
  1673.             error("! bad form in LIGKERN command") ;
  1674.       }
  1675.    }
  1676.    param = oparam ;
  1677. }
  1678. /*
  1679.  *   Here we get a token from the AFM file.  We parse just as much PostScript
  1680.  *   as we expect to find in an encoding file.  We allow commented lines and
  1681.  *   names like 0, .notdef, _foo_.  We do not allow //abc.
  1682.  */
  1683. char smbuffer[100] ;    /* for tokens */
  1684. char *gettoken() {
  1685.    char *p, *q ;
  1686.  
  1687.    while (1) {
  1688.       while (param == 0 || *param == 0) {
  1689.          if (getline() == 0)
  1690.             error("! premature end in encoding file") ;
  1691.          for (p=buffer; *p; p++)
  1692.             if (*p == '%') {
  1693.                if (ignoreligkern == 0)
  1694.                   checkligkern(p) ;
  1695.                *p = 0 ;
  1696.                break ;
  1697.             }
  1698.       }
  1699.       while (*param && *param <= ' ')
  1700.          param++ ;
  1701.       if (*param) {
  1702.          if (*param == '[' || *param == ']' ||
  1703.              *param == '{' || *param == '}') {
  1704.             smbuffer[0] = *param++ ;
  1705.             smbuffer[1] = 0 ;
  1706.             return smbuffer ;
  1707.          } else if (*param == '/' || *param == '-' || *param == '_' ||
  1708.                     *param == '.' ||
  1709.                     ('0' <= *param && *param <= '9') ||
  1710.                     ('a' <= *param && *param <= 'z') ||
  1711.                     ('A' <= *param && *param <= 'Z')) {
  1712.             smbuffer[0] = *param ;
  1713.             for (p=param+1, q=smbuffer+1;
  1714.                         *p == '-' || *p == '_' || *p == '.' ||
  1715.                         ('0' <= *p && *p <= '9') ||
  1716.                         ('a' <= *p && *p <= 'z') ||
  1717.                         ('A' <= *p && *p <= 'Z'); p++, q++)
  1718.                *q = *p ;
  1719.             *q = 0 ;
  1720.             param = p ;
  1721.             return smbuffer ;
  1722.          }
  1723.       }
  1724.    }
  1725. }
  1726. void getligkerndefaults() {
  1727.    int i ;
  1728.  
  1729.    for (i=0; staticligkern[i]; i++) {
  1730.       strcpy(buffer, staticligkern[i]) ;
  1731.       strcpy(obuffer, staticligkern[i]) ;
  1732.       param = buffer ;
  1733.       checkligkern(buffer) ;
  1734.    }
  1735. }
  1736. /*
  1737.  *   This routine reads in an encoding file, given the name.  It returns
  1738.  *   the final total structure.  It performs a number of consistency checks.
  1739.  */
  1740. struct encoding *readencoding(enc)
  1741. char *enc ;
  1742. {
  1743.    char *p ;
  1744.    int i ;
  1745.    struct encoding *e =
  1746.       (struct encoding *)mymalloc((unsigned long)sizeof(struct encoding)) ;
  1747.  
  1748.    sawligkern = 0 ;
  1749.    if (afmin)
  1750.       error("! oops; internal afmin error") ;
  1751.    if (enc) {
  1752.       afmin = fopen(enc, "r") ;
  1753.       param = 0 ;
  1754.       if (afmin == 0)
  1755.          error("! couldn't open that encoding file") ;
  1756.       p = gettoken() ;
  1757.       if (*p != '/' || p[1] == 0)
  1758.          error("! first token in encoding must be literal encoding name") ;
  1759.       e->name = newstring(p+1) ;
  1760.       p = gettoken() ;
  1761.       if (strcmp(p, "["))
  1762.          error("! second token in encoding must be mark ([) token") ;
  1763.       for (i=0; i<256; i++) {
  1764.          p = gettoken() ;
  1765.          if (*p != '/' || p[1] == 0)
  1766.             error("! tokens 3 to 257 in encoding must be literal names") ;
  1767.          e->vec[i] = newstring(p+1) ;
  1768.       }
  1769.       p = gettoken() ;
  1770.       if (strcmp(p, "]"))
  1771.          error("! token 258 in encoding must be make-array (])") ;
  1772.       while (getline()) {
  1773.          for (p=buffer; *p; p++)
  1774.             if (*p == '%') {
  1775.                if (ignoreligkern == 0)
  1776.                   checkligkern(p) ;
  1777.                *p = 0 ;
  1778.                break ;
  1779.             }
  1780.       }
  1781.       fclose(afmin) ;
  1782.       afmin = 0 ;
  1783.       if (ignoreligkern == 0 && sawligkern == 0)
  1784.          getligkerndefaults() ;
  1785.    } else {
  1786.       e = &staticencoding ;
  1787.       getligkerndefaults() ;
  1788.    }
  1789.    param = 0 ;
  1790.    return e ;
  1791. }
  1792. /*
  1793.  *   This routine prints out the line that needs to be added to psfonts.map.
  1794.  */
  1795. void conspsfonts() {
  1796.    (void)printf("%s %s", outname,
  1797. #ifndef VMCMS
  1798.    fontname) ;
  1799. #else /* VM/CMS: fontname is ascii, so we use ebfontname */
  1800.    ebfontname) ;
  1801. #endif
  1802.    if (slantparam || efactorparam || inenname) {
  1803.       (void)printf(" \"") ;
  1804.       if (slantparam)
  1805.          (void)printf(" %s SlantFont", slantparam) ;
  1806.       if (efactorparam)
  1807.          (void)printf(" %s ExtendFont", efactorparam) ;
  1808.       if (inenname)
  1809.          (void)printf(" %s ReEncodeFont", inencoding->name) ;
  1810.       (void)printf(" \"") ;
  1811.       if (inenname)
  1812.          (void)printf(" <%s", inenname) ;
  1813.    }
  1814.    (void)printf("\n") ;
  1815. }
  1816. int
  1817. main(argc, argv)
  1818. int argc ;
  1819. char *argv[] ;
  1820. {
  1821.    int i ;
  1822.    for (i=0; i<256; i++)
  1823.       nexttex[i] = -1 ; /* encoding chains have length 0 */
  1824.    tfmdata = (long *)mymalloc((unsigned long)40000L) ;
  1825.    openfiles(argc, argv) ;
  1826.    readadobe() ;
  1827.    if (fontspace == 0) {
  1828.       struct adobeinfo *ai ;
  1829.  
  1830.       if (0 != (ai = findadobe("space")))
  1831.          fontspace = ai->width ;
  1832.       else if (adobeptrs[32])
  1833.          fontspace = adobeptrs[32]->width ;
  1834.       else
  1835.          fontspace = transform(500, 0) ;
  1836.    }
  1837.    handlereencoding() ;
  1838.    buildtfm() ;
  1839.    writetfm() ;
  1840.    conspsfonts() ;
  1841.    if (makevpl) {
  1842.       assignchars() ;
  1843.       if (makevpl>1) upmap() ;
  1844.       writevpl() ;
  1845.    }
  1846.    return 0 ;
  1847.    /*NOTREACHED*/
  1848. }
  1849.