home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PRINTING / DVIPS54.ZIP / DVIPS / AFM2TFM.C < prev    next >
C/C++ Source or Header  |  1990-11-25  |  36KB  |  1,286 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.  
  10. #include <stdio.h>
  11. #ifdef SYSV
  12. #include <string.h>
  13. #else
  14. #ifdef VMS
  15. #include <string.h>
  16. #else
  17. #include <strings.h>
  18. #endif
  19. #endif
  20. #include <math.h>
  21.  
  22. #ifdef MSDOS
  23. #define WRITEBIN "wb"
  24. #else
  25. #define WRITEBIN "w"
  26. #endif
  27.  
  28. char *texencoding[] = {
  29.    "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi", "Sigma",
  30.    "Upsilon", "Phi", "Psi", "Omega", "arrowup", "arrowdown", "quotesingle",
  31.    "exclamdown", "questiondown", "dotlessi", "dotlessj", "grave", "acute",
  32.    "caron", "breve", "macron", "ring", "cedilla", "germandbls", "ae", "oe",
  33.    "oslash", "AE", "OE", "Oslash", "space", "exclam", "quotedbl", "numbersign",
  34.    "dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright",
  35.    "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one",
  36.    "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon",
  37.    "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C",
  38.    "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
  39.    "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash",
  40.    "bracketright", "circumflex", "underscore", "quoteleft", "a", "b", "c", "d",
  41.    "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
  42.    "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright",
  43.    "tilde", "dieresis" } ;
  44. /*
  45.  *   The above layout corresponds to TeX Typewriter Type and is compatible
  46.  *   with TeX Text because the position of ligatures is immaterial.
  47.  */
  48.  
  49. /*
  50.  *   This is what we store Adobe data in.
  51.  */
  52. struct adobeinfo {
  53.    struct adobeinfo *next ;
  54.    int adobenum, texnum, width ;
  55.    char *adobename ;
  56.    int llx, lly, urx, ury ;
  57.    struct lig *ligs ;
  58.    struct kern *kerns ;
  59.    struct pcc *pccs ;
  60.    int wptr, hptr, dptr, iptr ;
  61. } *adobechars, *adobeptrs[256], *texptrs[256],
  62.   *uppercase[256], *lowercase[256] ;
  63. struct lig {
  64.    struct lig *next ;
  65.    char *succ, *sub ;
  66. } ;
  67. struct kern {
  68.    struct kern *next ;
  69.    char *succ ;
  70.    int delta ;
  71. } ;
  72. struct pcc {
  73.    struct pcc *next ;
  74.    char * partname ;
  75.    int xoffset, yoffset ;
  76. } ;
  77.  
  78. FILE *afmin, *vplout, *tfmout ;
  79. char inname[200], outname[200] ; /* names of input and output files */
  80. char buffer[255]; /* input buffer (modified while parsing) */
  81. char obuffer[255] ; /* unmodified copy of input buffer */
  82. char *param ; /* current position in input buffer */
  83. char *fontname = "Unknown" ;
  84. char *codingscheme = "Unspecified" ;
  85. float italicangle = 0.0 ;
  86. char fixedpitch ;
  87. char makevpl ;
  88. int xheight = 400 ;
  89. int fontspace ;
  90. int bc, ec ;
  91. long cksum ;
  92. float efactor = 1.0, slant = 0.0 ;
  93. double newslant ;
  94. char titlebuf[100] ;
  95.  
  96. void
  97. error(s)
  98. register char *s ;
  99. {
  100.    extern void exit() ;
  101.  
  102.    (void)fprintf(stderr, "%s\n", s) ;
  103.    if (obuffer[0]) {
  104.       (void)fprintf(stderr, "%s\n", obuffer) ;
  105.       while (param > buffer) {
  106.          (void)fprintf(stderr, " ") ;
  107.          param-- ;
  108.       }
  109.       (void)fprintf(stderr, "^\n") ;
  110.    }
  111.    if (*s == '!')
  112.       exit(1) ;
  113. }
  114.  
  115. int
  116. transform(x,y)
  117.    register int x,y ;
  118. {
  119.    register double acc ;
  120.    acc = efactor * x + slant *y ;
  121.    return (int)(acc>=0? acc+0.5 : acc-0.5 ) ;
  122. }
  123.  
  124. int
  125. getline() {
  126.    register char *p ;
  127.    register int c ;
  128.  
  129.    param = buffer ;
  130.    for (p=buffer; (c=getc(afmin)) != EOF && c != 10;)
  131.       *p++ = c ;
  132.    *p = 0 ;
  133.    (void)strcpy(obuffer, buffer) ;
  134.    if (p == buffer && c == EOF)
  135.       return(0) ;
  136.    else
  137.       return(1) ;
  138. }
  139.  
  140. char *interesting[] = { "FontName", "ItalicAngle", "IsFixedPitch",
  141.    "XHeight", "C", "KPX", "CC", "EncodingScheme", NULL} ; 
  142. #define FontName (0)
  143. #define ItalicAngle (1)
  144. #define IsFixedPitch (2)
  145. #define XHeight (3)
  146. #define C (4)
  147. #define KPX (5)
  148. #define CC (6)
  149. #define EncodingScheme (7)
  150. #define NONE (-1)
  151. int
  152. interest(s)
  153. char *s ;
  154. {
  155.    register char **p ;
  156.    register int n ;
  157.  
  158.    for (p=interesting, n=0; *p; p++, n++)
  159.       if (strcmp(s, *p)==0)
  160.          return(n) ;
  161.    return(NONE) ;
  162. }
  163.  
  164. char *
  165. mymalloc(len)
  166. int len ;
  167. {
  168.    register char *p ;
  169.    extern char *malloc() ;
  170.  
  171.    p = malloc((unsigned)len) ;
  172.    if (p==NULL)
  173.       error("! out of memory") ;
  174.    return(p) ;
  175. }
  176.  
  177. char *
  178. paramnewstring() {
  179.    register char *p, *q ;
  180.  
  181.    p = param ;
  182.    while (*p > ' ')
  183.       p++ ;
  184.    q = mymalloc((int)(p-param+1)) ;
  185.    if (*p != 0)
  186.       *p++ = 0 ;
  187.    (void)strcpy(q, param) ;
  188.    while (*p && *p <= ' ')
  189.       p++ ;
  190.    param = p ;
  191.    return(q) ;
  192. }
  193.  
  194. char *
  195. paramstring() {
  196.    register char *p, *q ;
  197.  
  198.    p = param ;
  199.    while (*p > ' ')
  200.       p++ ;
  201.    q = param ;
  202.    if (*p != 0)
  203.       *p++ = 0 ;
  204.    while (*p && *p <= ' ')
  205.       p++ ;
  206.    param = p ;
  207.    return(q) ;
  208. }
  209.  
  210. int
  211. paramnum() {
  212.    register char *p ;
  213.    int i ;
  214.  
  215.    p = paramstring() ;
  216.    if (sscanf(p, "%d", &i) != 1)
  217.       error("! integer expected") ;
  218.    return(i) ;
  219. }
  220.  
  221. float
  222. paramfloat() {
  223.    register char *p ;
  224.    float i ;
  225.  
  226.    p = paramstring() ;
  227.    if (sscanf(p, "%f", &i) != 1)
  228.       error("! number expected") ;
  229.    return(i) ;
  230. }
  231.  
  232. struct adobeinfo *
  233. newchar() {
  234.    register struct adobeinfo *ai ;
  235.  
  236.    ai = (struct adobeinfo *)mymalloc(sizeof(struct adobeinfo)) ;
  237.    ai->adobenum = -1 ;
  238.    ai->texnum = -1 ;
  239.    ai->width = -1 ;
  240.    ai->adobename = NULL ;
  241.    ai->llx = -1 ;
  242.    ai->lly = -1 ;
  243.    ai->urx = -1 ;
  244.    ai->ury = -1 ;
  245.    ai->ligs = NULL ;
  246.    ai->kerns = NULL ;
  247.    ai->pccs = NULL ;
  248.    ai->next = adobechars ;
  249.    adobechars = ai ;
  250.    return(ai) ;
  251. }
  252.  
  253. struct kern *
  254. newkern() {
  255.    register struct kern *nk ;
  256.  
  257.    nk = (struct kern *)mymalloc(sizeof(struct kern)) ;
  258.    nk->next = NULL ;
  259.    nk->succ = NULL ;
  260.    nk->delta = 0 ;
  261.    return(nk) ;
  262. }
  263.  
  264. struct pcc *
  265. newpcc() {
  266.    register struct pcc *np ;
  267.  
  268.    np = (struct pcc *)mymalloc(sizeof(struct pcc)) ;
  269.    np->next = NULL ;
  270.    np->partname = NULL ;
  271.    np->xoffset = 0 ;
  272.    np->yoffset = 0 ;
  273.    return(np) ;
  274. }
  275.  
  276. struct lig *
  277. newlig() {
  278.    register struct lig *nl ;
  279.  
  280.    nl = (struct lig *)mymalloc(sizeof(struct lig)) ;
  281.    nl->next = NULL ;
  282.    nl->succ = NULL ;
  283.    nl->sub = NULL ;
  284.    return(nl) ;
  285. }
  286.  
  287. void
  288. expect(s)
  289. char *s ;
  290. {
  291.    if (strcmp(paramstring(), s) != 0) {
  292.       (void)fprintf(stderr, "%s expected: ", s) ;
  293.       error("! syntax error") ;
  294.    }
  295. }
  296.  
  297. void
  298. handlechar() { /* an input line beginning with C */
  299.    register struct adobeinfo *ai ;
  300.    register struct lig *nl ;
  301.  
  302.    ai = newchar() ;
  303.    ai->adobenum = paramnum() ;
  304.    expect(";") ;
  305.    expect("WX") ;
  306.    ai->width = transform(paramnum(),0) ;
  307.    if (ai->adobenum >= 0) {
  308.       adobeptrs[ai->adobenum] = ai ;
  309.       cksum = (cksum<<1) ^ ai->width ;
  310.    }
  311.    expect(";") ;
  312.    expect("N") ;
  313.    ai->adobename = paramnewstring() ;
  314.    expect(";") ;
  315.    expect("B") ;
  316.    ai->llx = paramnum() ;
  317.    ai->lly = paramnum() ;
  318.    ai->llx = transform(ai->llx, ai->lly) ;
  319.    ai->urx = paramnum() ;
  320.    ai->ury = paramnum() ;
  321.    ai->urx = transform(ai->urx, ai->ury) ;
  322.    expect(";") ;
  323. /* Now look for ligatures (which aren't present in fixedpitch fonts) */
  324.    while (*param == 'L') {
  325.       expect("L") ;
  326.       nl = newlig() ;
  327.       nl->succ = paramnewstring() ;
  328.       nl->sub = paramnewstring() ;
  329.       nl->next = ai->ligs ;
  330.       ai->ligs = nl ;
  331.       expect(";") ;
  332.    }
  333.    if (strcmp(ai->adobename, "space")==0) {
  334.       fontspace = ai->width ;
  335.       nl = newlig() ;        /* space will act as zero-width Polish crossbar */
  336.       nl->succ = "l" ;       /* when used by plain TeX's \l or \L macros */
  337.       nl->sub = "lslash" ;
  338.       nl->next = ai->ligs ;
  339.       ai->ligs = nl ;
  340.       nl = newlig() ;
  341.       nl->succ = "L" ;
  342.       nl->sub = "Lslash" ;
  343.       nl->next = ai->ligs ;
  344.       ai->ligs = nl ;
  345.    } else if (strcmp(ai->adobename, "question")==0) {
  346.       nl = newlig() ;
  347.       nl->succ = "quoteleft" ;
  348.       nl->sub = "questiondown" ;
  349.       nl->next = ai->ligs ;
  350.       ai->ligs = nl ;
  351.    } else if (strcmp(ai->adobename, "exclam")==0) {
  352.       nl = newlig() ;
  353.       nl->succ = "quoteleft" ;
  354.       nl->sub = "exclamdown" ;
  355.       nl->next = ai->ligs ;
  356.       ai->ligs = nl ;
  357.    } else if (! fixedpitch) {
  358.       if (strcmp(ai->adobename, "hyphen")==0) {
  359.          nl = newlig() ;
  360.          nl->succ = "hyphen" ;
  361.          nl->sub = "endash" ;
  362.          nl->next = ai->ligs ;
  363.          ai->ligs = nl ;
  364.       } else if (strcmp(ai->adobename, "endash")==0) {
  365.          nl = newlig() ;
  366.          nl->succ = "hyphen" ;
  367.          nl->sub = "emdash" ;
  368.          nl->next = ai->ligs ;
  369.          ai->ligs = nl ;
  370.       } else if (strcmp(ai->adobename, "quoteleft")==0) {
  371.          nl = newlig() ;
  372.          nl->succ = "quoteleft" ;
  373.          nl->sub = "quotedblleft" ;
  374.          nl->next = ai->ligs ;
  375.          ai->ligs = nl ;
  376.       } else if (strcmp(ai->adobename, "quoteright")==0) {
  377.          nl = newlig() ;
  378.          nl->succ = "quoteright" ;
  379.          nl->sub = "quotedblright" ;
  380.          nl->next = ai->ligs ;
  381.          ai->ligs = nl ;
  382.       }
  383.    }
  384. }
  385.  
  386. struct adobeinfo *
  387. findadobe(p)
  388. char *p ;
  389. {
  390.    register struct adobeinfo *ai ;
  391.  
  392.    for (ai=adobechars; ai; ai = ai->next)
  393.       if (strcmp(p, ai->adobename)==0)
  394.          return(ai) ;
  395.    return(NULL) ;
  396. }
  397.  
  398. /* We ignore kerns before and after space characters, because (1) TeX
  399.  * is using the space only for Polish ligatures, and (2) TeX's
  400.  * boundarychar mechanisms are not oriented to kerns (they apply
  401.  * to both spaces and punctuation) so we don't want to use them. */
  402. void
  403. handlekern() { /* an input line beginning with KPX */
  404.    register struct adobeinfo *ai ;
  405.    register char *p ;
  406.    register struct kern *nk ;
  407.  
  408.    p = paramstring() ;
  409.    if (strcmp(p,"space")==0) return ;
  410.    ai = findadobe(p) ;
  411.    if (ai == NULL)
  412.       error("! kern char not found") ;
  413.    if (ai->adobenum<'0' || ai->adobenum>'9') {
  414. /* Ignore kerns after digits because they would mess up our nice tables */
  415.       nk = newkern() ;
  416.       nk->succ = paramnewstring() ;
  417.       if (strcmp(nk->succ,"space")==0) return ;
  418.       nk->delta = transform(paramnum(),0) ;
  419.       nk->next = ai->kerns ;
  420.       ai->kerns = nk ;
  421.     }
  422. }
  423.  
  424. void
  425. handleconstruct() { /* an input line beginning with CC */
  426.    register struct adobeinfo *ai ;
  427.    register char *p ;
  428.    register struct pcc *np ;
  429.    register int n ;
  430.    struct pcc *npp = NULL;
  431.  
  432.    p = paramstring() ;
  433.    ai = findadobe(p) ;
  434.    if (ai == NULL)
  435.       error("! composite character name not found") ;
  436.    n = paramnum() ;
  437.    expect(";") ;
  438.    while (n--) {
  439.       if (strcmp(paramstring(),"PCC") != 0) return ;
  440.         /* maybe I should expect("PCC") instead, but I'm playing it safe */
  441.       np = newpcc() ;
  442.       np->partname = paramnewstring() ;
  443.       if (findadobe(np->partname)==NULL) return ;
  444.       np->xoffset = paramnum() ;
  445.       np->yoffset = paramnum() ;
  446.       np->xoffset = transform(np->xoffset, np->yoffset) ;
  447.       if (npp) npp->next = np ;
  448.       else ai->pccs = np ;
  449.       npp = np ;
  450.       expect(";") ;
  451.    }
  452. }
  453.  
  454. void
  455. makeaccentligs() {
  456.    register struct adobeinfo *ai, *aci ;
  457.    register char *p ;
  458.    register struct lig *nl ;
  459.    for (ai=adobechars; ai; ai=ai->next) {
  460.       p = ai->adobename ;
  461.       if (strlen(p)>2)
  462.          if ((aci=findadobe(p+1)) && (aci->adobenum > 127)) {
  463.             nl = newlig() ;
  464.             nl->succ = mymalloc(2) ;
  465.             *(nl->succ + 1) = 0 ;
  466.             *(nl->succ) = *p ;
  467.             nl->sub = ai->adobename ;
  468.             nl->next = aci->ligs ;
  469.             aci->ligs = nl ;
  470.          }
  471.    }
  472. }
  473.  
  474. void
  475. readadobe() {
  476.    while (getline()) {
  477.       switch(interest(paramstring())) {
  478. case FontName:
  479.          fontname = paramnewstring() ;
  480.          break ;
  481. case EncodingScheme:
  482.          codingscheme = paramnewstring() ;
  483.          break ;
  484. case ItalicAngle:
  485.          italicangle = paramfloat() ;
  486.          break ;
  487. case IsFixedPitch:
  488.          if (*param == 't' || *param == 'T')
  489.             fixedpitch = 1 ;
  490.          else
  491.             fixedpitch = 0 ;
  492.          break ;
  493. case XHeight:
  494.          xheight = paramnum() ;
  495.          break ;
  496. case C:
  497.          handlechar() ;
  498.          break ;
  499. case KPX:
  500.          handlekern() ;
  501.          break ;
  502. case CC:
  503.          handleconstruct() ;
  504.          break ;
  505. default:
  506.          break ;
  507.       }
  508.    }
  509.    makeaccentligs() ;
  510. }
  511.  
  512. void
  513. assignchars() {
  514.    register char **p ;
  515.    register int i ;
  516.    register struct adobeinfo *ai ;
  517.    int nextfree = 128 ;
  518.  
  519. /*
  520.  *   First, we assign all those that match perfectly.
  521.  */
  522.    for (i=0, p=texencoding; i<128; i++, p++)
  523.       if ((ai=findadobe(*p)) && ai->adobenum >= 0) {
  524.          ai->texnum = i ;
  525.          texptrs[i] = ai ;
  526.       }
  527. /*
  528.  *   Next, we assign all the others whose codes are above 127, retaining
  529.  *   the adobe positions. */
  530.    for (ai=adobechars; ai; ai=ai->next)
  531.       if (ai->adobenum > 127 && ai->texnum<0) {
  532.          ai->texnum = ai->adobenum ;
  533.          texptrs[ai->adobenum] = ai ;
  534.       }
  535. /*   Finally, we map all remaining characters into free locations beginning
  536.  *   with 128, if we know how to construct those characters. */
  537.    for (ai=adobechars; ai; ai=ai->next)
  538.       if (ai->texnum<0 && (ai->adobenum>=0 || ai->pccs !=NULL)) {
  539.          while (texptrs[nextfree]) {
  540.             nextfree=(nextfree+1)&255 ;
  541.             if (nextfree==128) return ; /* all slots full */
  542.          }
  543.          ai->texnum = nextfree ;
  544.          texptrs[nextfree] = ai ;
  545.       }
  546. }
  547.  
  548. void
  549. upmap() { /* Compute uppercase mapping, when making a small caps font */
  550.    register struct adobeinfo *ai, *Ai ;
  551.    register char *p, *q ;
  552.    register struct pcc *np, *nq ;
  553.    char lwr[50] ;
  554.  
  555.    for (Ai=adobechars; Ai; Ai=Ai->next) {
  556.       p = Ai->adobename ;
  557.       if (*p>='A' && *p<='Z') {
  558.          q = lwr ;
  559.          for (; *p; p++)
  560.             *q++ = ((*p>='A' && *p<='Z') ? *p+32 : *p) ;
  561.          *q = 0;
  562.          if (ai=findadobe(lwr)) {
  563.             if (ai->texnum>=0) uppercase[ai->texnum] = Ai ;
  564.             if (Ai->texnum>=0) lowercase[Ai->texnum] = ai ;
  565.          }
  566.       }
  567.    }
  568. /* Note that, contrary to the normal true/false conventions,
  569.  * uppercase[i] is NULL and lowercase[i] is non-NULL when i is the
  570.  * ASCII code of an uppercase letter; and vice versa for lowercase letters */
  571.  
  572.    if (ai=findadobe("germandbls"))
  573.       if (Ai=findadobe("S")) { /* we also construct SS */
  574.          uppercase[ai->texnum] = ai ;
  575.          ai->width = Ai->width << 1 ;
  576.          ai->llx = Ai->llx ;
  577.          ai->lly = Ai->lly ;
  578.          ai->urx = Ai->width + Ai->urx ;
  579.          ai->ury = Ai->ury ;
  580.          ai->kerns = Ai->kerns ;
  581.          np = newpcc() ;
  582.          np->partname = "S" ;
  583.          nq = newpcc() ;
  584.          nq->partname = "S" ;
  585.          nq->xoffset = Ai->width ;
  586.          np->next = nq ;   
  587.          ai->pccs = np ;
  588.       }
  589.    if (ai=findadobe("dotlessi"))
  590.       uppercase[ai->texnum] = findadobe("I") ;
  591.    if (ai=findadobe("dotlessj"))
  592.       uppercase[ai->texnum] = findadobe("J") ;
  593. }
  594. /* The logic above seems to work well enough, but it leaves useless characters
  595.  * like `fi' and `fl' in the font if they were present initially,
  596.  * and it omits characters like `dotlessj' if they are absent initially */
  597.  
  598. /* Now we turn to computing the TFM file */
  599.  
  600. int lf, lh, nw, nh, nd, ni, nl, nk, ne, np ;
  601.  
  602. void
  603. write16(what)
  604. register short what ;
  605. {
  606.    (void)fputc(what >> 8, tfmout) ;
  607.    (void)fputc(what & 255, tfmout) ;
  608. }
  609.  
  610. void
  611. writearr(p, n)
  612. register long *p ;
  613. register int n ;
  614. {
  615.    while (n) {
  616.       write16((short)(*p >> 16)) ;
  617.       write16((short)(*p & 65535)) ;
  618.       p++ ;
  619.       n-- ;
  620.    }
  621. }
  622.  
  623. void
  624. makebcpl(p, s, n)
  625. register long *p ;
  626. register char *s ;
  627. register int n ;
  628. {
  629.    register long t ;
  630.    register long sc ;
  631.  
  632.    if (strlen(s) < n)
  633.       n = strlen(s) ;
  634.    t = ((long)n) << 24 ;
  635.    sc = 16 ;
  636.    while (n > 0) {
  637.       t |= ((long)(*(unsigned char *)s++)) << sc ;
  638.       sc -= 8 ;
  639.       if (sc < 0) {
  640.          *p++ = t ;
  641.          t = 0 ;
  642.          sc = 24 ;
  643.       }
  644.       n-- ;
  645.    }
  646.    *p++ = t ;
  647. }
  648.  
  649. int source[257] ;
  650. int unsort[257] ;
  651.  
  652. /*
  653.  *   Next we need a routine to reduce the number of distinct dimensions
  654.  *   in a TFM file. Given an array what[0]...what[oldn-1], we want to
  655.  *   group its elements into newn clusters, in such a way that the maximum
  656.  *   difference between elements of a cluster is as small as possible.
  657.  *   Furthermore, what[0]=0, and this value must remain in a cluster by
  658.  *   itself. Data such as `0 4 6 7 9' with newn=3 shows that an iterative
  659.  *   scheme in which 6 is first clustered with 7 will not work. So we
  660.  *   borrow a neat algorithm from METAFONT to find the true optimum.
  661.  *   Memory location what[oldn] is set to 0x7fffffffL for convenience.
  662.  */
  663. long nextd ; /* smallest value that will give a different mincover */
  664. int
  665. mincover(what,d) /* tells how many clusters result, given max difference d */
  666. register long d ;
  667. long *what ;
  668. {
  669.    register int m ;
  670.    register long l ;
  671.    register long *p ;
  672.  
  673.    nextd = 0x7fffffffL ;
  674.    p = what+1 ;
  675.    m = 1 ;
  676.    while (*p<0x7fffffffL) {
  677.       m++ ;
  678.       l = *p ;
  679.       while (*++p <= l+d) ;
  680.       if (*p-l < nextd) nextd = *p-l ;
  681.    }
  682.    return (m) ;
  683. }
  684.  
  685. void
  686. remap(what, oldn, newn)
  687. long *what ;
  688. int oldn, newn ;
  689. {
  690.    register int i, j ;
  691.    register long d, l ;
  692.  
  693.    what[oldn] = 0x7fffffffL ;
  694.    for (i=oldn-1; i>0; i--) {
  695.       d = what[i] ;
  696.       for (j=i; what[j+1]<d; j++) {
  697.          what[j] = what[j+1] ;
  698.          source[j] = source[j+1] ;
  699.       }
  700.       what[j] = d ;
  701.       source[j] = i ;
  702.    } /* Tom, don't let me ever catch you using bubblesort again! -- Don */
  703.  
  704.    i = mincover(what, 0L) ;
  705.    d = nextd ;
  706.    while (mincover(what,d+d)>newn) d += d ;
  707.    while (mincover(what,d)>newn) d = nextd ;
  708.  
  709.    i = 1 ;
  710.    j = 0 ;
  711.    while (i<oldn) {
  712.       j++ ;
  713.       l = what[i] ;
  714.       unsort[source[i]] = j ;
  715.       while (what[++i] <= l+d) {
  716.          unsort[source[i]] = j ;
  717.          if (i-j == oldn-newn) d = 0 ;
  718.       }
  719.       what[j] = (l+what[i-1])/2 ;
  720.    }
  721. }
  722.  
  723. /*
  724.  *   The next routine simply scales something.
  725.  *   Input is in 1000ths of an em.  Output is in FIXFACTORths of 1000.
  726.  */
  727. #define FIXFACTOR (0x100000L) /* 2^{20}, the unit fixnum */
  728. long
  729. scale(what)
  730. long what ;
  731. {
  732.    return(((what / 1000) << 20) +
  733.           (((what % 1000) << 20) + 500) / 1000) ;
  734. }
  735.  
  736. long *header, *charinfo, *width, *height, *depth, *ligkern, *kern, *tparam,
  737.      *italic ;
  738. long tfmdata[10000] ;
  739.  
  740. void
  741. buildtfm() {
  742.    register int i, j ;
  743.    register struct adobeinfo *ai ;
  744.    double tan() ;
  745.  
  746.    header = tfmdata ;
  747.    header[0] = cksum ;
  748.    header[1] = 0xa00000 ; /* 10pt design size */
  749.    makebcpl(header+2, codingscheme, 39) ;
  750.    makebcpl(header+12, fontname, 19) ;
  751.    lh = 17 ;
  752.    charinfo = header + lh ;
  753.  
  754.    for (i=0; i<256 && adobeptrs[i]==NULL; i++) ;
  755.    bc = i ;
  756.    for (i=255; i>=0 && adobeptrs[i]==NULL; i--) ;
  757.    ec = i;
  758.    if (ec < bc)
  759.       error("! no Adobe characters") ;
  760.  
  761.    width = charinfo + (ec - bc + 1) ;
  762.    width[0] = 0 ;
  763.    nw++ ;
  764.    for (i=bc; i<=ec; i++)
  765.       if (ai=adobeptrs[i]) {
  766.          width[nw]=ai->width ;
  767.          for (j=1; width[j]!=ai->width; j++) ;
  768.          ai->wptr = j ;
  769.          if (j==nw)
  770.             nw++ ;
  771.       }
  772.    if (nw>256)
  773.       error("! 256 chars with different widths") ;
  774.    depth = width + nw ;
  775.    depth[0] = 0 ;
  776.    nd = 1 ;
  777.    for (i=bc; i<=ec; i++)
  778.       if (ai=adobeptrs[i]) {
  779.          depth[nd] = -ai->lly ;
  780.          for (j=0; depth[j]!=-ai->lly; j++) ;
  781.          ai->dptr = j ;
  782.          if (j==nd)
  783.             nd++ ;
  784.       }
  785.    if (nd > 16) {
  786.       remap(depth, nd, 16) ;
  787.       nd = 16 ;
  788.       for (i=bc; i<=ec; i++)
  789.          if (ai=adobeptrs[i])
  790.             ai->dptr = unsort[ai->dptr] ;
  791.    }
  792.    height = depth + nd ;
  793.    height[0] = 0 ;
  794.    nh = 1 ;
  795.    for (i=bc; i<=ec; i++)
  796.       if (ai=adobeptrs[i]) {
  797.          height[nh]=ai->ury ;
  798.          for (j=0; height[j]!=ai->ury; j++) ;
  799.          ai->hptr = j ;
  800.          if (j==nh)
  801.             nh++ ;
  802.       }
  803.    if (nh > 16) {
  804.       remap(height, nh, 16) ;
  805.       nh = 16 ;
  806.       for (i=bc; i<=ec; i++)
  807.          if (ai=adobeptrs[i])
  808.             ai->hptr = unsort[ai->hptr] ;
  809.    }
  810.    italic  = height + nh ;
  811.    italic[0] = 0 ;
  812.    ni = 1 ;
  813.    for (i=bc; i<=ec; i++)
  814.       if (ai=adobeptrs[i]) {
  815.          italic[ni] = ai->urx - ai->width ;
  816.          if (italic[ni]<0)
  817.             italic[ni] = 0 ;
  818.          for (j=0; italic[j]!=italic[ni]; j++) ;
  819.          ai->iptr = j ;
  820.          if (j==ni)
  821.             ni++ ;
  822.       }
  823.    if (ni > 64) {
  824.       remap(italic, ni, 64) ;
  825.       ni = 64 ;
  826.       for (i=bc; i<=ec; i++)
  827.          if (ai=adobeptrs[i])
  828.             ai->iptr = unsort[ai->iptr] ;
  829.    }
  830.  
  831.    for (i=bc; i<=ec; i++)
  832.       if (ai=adobeptrs[i])
  833.          charinfo[i-bc] = ((long)(ai->wptr)<<24) +
  834.                            ((long)(ai->hptr)<<20) +
  835.                             ((long)(ai->dptr)<<16) +
  836.                              ((long)(ai->iptr)<<10) ;
  837.  
  838.    ligkern = italic + ni ;
  839.    nl = 0 ; /* ligatures and kerns omitted from raw Adobe font */
  840.    kern = ligkern + nl ;
  841.    nk = 0 ;
  842.  
  843.    newslant = (double)slant - efactor * tan(italicangle*(3.1415926535/180.0)) ;
  844.    tparam = kern + nk ;
  845.    tparam[0] = (long)(FIXFACTOR * newslant + 0.5) ;
  846.    tparam[1] = scale((long)(fontspace*efactor+0.5)) ;
  847.    tparam[2] = (fixedpitch ? 0 : scale((long)(300*efactor+0.5))) ;
  848.    tparam[3] = (fixedpitch ? 0 : scale((long)(100*efactor+0.5))) ;
  849.    tparam[4] = scale((long)xheight) ;
  850.    tparam[5] = scale((long)(1000*efactor+0.5)) ;
  851.    np = 6 ;
  852. }
  853.  
  854. void
  855. writesarr(what, len)
  856. long *what ;
  857. int len ;
  858. {
  859.    register long *p ;
  860.    int i ;
  861.  
  862.    p = what ;
  863.    i = len ;
  864.    while (i) {
  865.       *p = scale(*p) ;
  866.       p++ ;
  867.       i-- ;
  868.    }
  869.    writearr(what, len) ;
  870. }
  871.  
  872. void
  873. writetfm() {
  874.    lf = 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np ;
  875.    write16(lf) ;
  876.    write16(lh) ;
  877.    write16(bc) ;
  878.    write16(ec) ;
  879.    write16(nw) ;
  880.    write16(nh) ;
  881.    write16(nd) ;
  882.    write16(ni) ;
  883.    write16(nl) ;
  884.    write16(nk) ;
  885.    write16(ne) ;
  886.    write16(np) ;
  887.    writearr(header, lh) ;
  888.    writearr(charinfo, ec-bc+1) ;
  889.    writesarr(width, nw) ;
  890.    writesarr(height, nh) ;
  891.    writesarr(depth, nd) ;
  892.    writesarr(italic, ni) ;
  893.    writearr(ligkern, nl) ;
  894.    writesarr(kern, nk) ;
  895.    writearr(tparam, np) ;
  896. }
  897.  
  898. /* OK, the TFM file is done! Now for our next trick, the VPL file. */
  899.  
  900. /* For TeX we want to compute a character height that works properly
  901.  * with accents. The following list of accents doesn't need to be complete. */
  902. char *accents[] = { "acute", "tilde", "caron", "dieresis", NULL} ;
  903. int
  904. texheight(ai)
  905. register struct adobeinfo *ai ;
  906. {
  907.    register char **p;
  908.    register struct adobeinfo *aci, *acci ;
  909.    if (*(ai->adobename + 1)) return (ai->ury) ; /* that was the simple case */
  910.    for (p=accents; *p; p++)  /* otherwise we look for accented letters */
  911.       if (aci=findadobe(*p)) {
  912.          strcpy(buffer,ai->adobename) ;
  913.          strcat(buffer,*p) ;
  914.          if (acci=findadobe(buffer)) return (acci->ury - aci->ury + xheight) ;
  915.       }
  916.    return (ai->ury) ;
  917. }
  918.  
  919. /* modified tgr to eliminate varargs problems */
  920.  
  921. #define vout(s)  fprintf(vplout, s)
  922. int level ; /* the depth of parenthesis nesting in VPL file being written */
  923.  
  924. void vlevout() {
  925.    register int l = level ;
  926.    while (l--) vout("   ") ;
  927. }
  928.  
  929. void vlevnlout() {
  930.    vout("\n") ;
  931.    vlevout() ;
  932. }
  933.  
  934. #define voutln(str) {fprintf(vplout,"%s\n",str);vlevout();}
  935. /*
  936. void
  937. voutln(s)
  938. char *s ;
  939. {
  940.    register char l ;
  941.    fprintf(vplout,"%s\n", s) ;
  942.    for (l=level; l; l--) vout("   ") ;
  943. }
  944. */
  945. #define voutln2(f,s) {fprintf(vplout,f,s);vlevnlout();}
  946. /*
  947. void
  948. voutln2(f,s)
  949. char *f, *s ;
  950. {
  951.    register char l ;
  952.    (void) sprintf(buffer, f, s) ;
  953.    fprintf(vplout,"%s\n", buffer) ;
  954.    for (l=level; l; l--) vout("   ") ;
  955. }
  956. */
  957. #define voutln3(f,a,b) {fprintf(vplout,f,a,b);vlevnlout();}
  958. /*
  959. void
  960. voutln3(f,s1,s2)
  961. char *f, *s1, *s2 ;
  962. {
  963.    register char l ;
  964.    (void) sprintf(buffer, f, s1, s2) ;
  965.    fprintf(vplout,"%s\n", buffer) ;
  966.    for (l=level; l; l--) vout("   ") ;
  967. }
  968. */
  969. void
  970. vleft()
  971. {
  972.    level++ ;
  973.    vout("(") ;
  974. }
  975.  
  976. void
  977. vright()
  978. {
  979.    level-- ;
  980.    voutln(")") ;
  981. }
  982.  
  983. char vcharbuf[6] ;
  984. char *vchar(c)
  985. int c ;
  986. {
  987.    if ((c>='0' && c<='9')||(c>='A' && c<='Z')||(c>='a' && c<='z'))
  988.       (void) sprintf(vcharbuf,"C %c", c) ;
  989.    else (void) sprintf(vcharbuf,"O %o", c) ;
  990.    return (vcharbuf) ;
  991. }
  992.  
  993. void
  994. writevpl()
  995. {
  996.    register int i ;
  997.    register struct adobeinfo *ai ;
  998.    register struct lig *nlig ;
  999.    register struct kern *nkern ;
  1000.    register struct pcc *npcc ;
  1001.    struct adobeinfo *asucc, *asub, *api ;
  1002.    int xoff, yoff, ht ;
  1003.    char unlabeled ;
  1004.    double tan() ;
  1005.  
  1006.    voutln2("(VTITLE Created by %s)", titlebuf) ;
  1007.    voutln("(COMMENT Please edit that VTITLE if you edit this file)") ;
  1008.    (void)sprintf(obuffer, "TeX-%s%s%s%s", outname,
  1009.       (efactor==1.0? "" : "-E"), (slant==0.0? "" : "-S"),
  1010.                  (makevpl==1? "" : "-CSC")) ;
  1011.    if (strlen(obuffer)>19) { /* too long, will retain first 9 and last 10 */
  1012.       register char *p, *q ;
  1013.       for (p = &obuffer[9], q = &obuffer[strlen(obuffer)-10] ; p<&obuffer[19];
  1014.               p++, q++) *p = *q ;
  1015.       obuffer[19] = '\0' ;
  1016.    }
  1017.    voutln2("(FAMILY %s)" , obuffer) ;
  1018.    voutln2("(CODINGSCHEME TeX text + %s)", codingscheme) ;
  1019.    voutln("(DESIGNSIZE R 10.0)") ;
  1020.    voutln("(DESIGNUNITS R 1000)") ;
  1021.    voutln("(COMMENT DESIGNSIZE (1 em) IS IN POINTS)") ;
  1022.    voutln("(COMMENT OTHER DIMENSIONS ARE MULTIPLES OF DESIGNSIZE/1000)") ;
  1023.    voutln2("(CHECKSUM O %lo)",cksum ^ 0xffffffff) ;
  1024.    vleft() ; voutln("FONTDIMEN") ;
  1025.    if (newslant)
  1026.       voutln2("(SLANT R %f)", newslant) ;
  1027.    voutln2("(SPACE D %d)", transform(fontspace,0)) ;
  1028.    if (! fixedpitch) {
  1029.       voutln2("(STRETCH D %d)", transform(200,0)) ;
  1030.       voutln2("(SHRINK D %d)", transform(100,0)) ;
  1031.    }
  1032.    voutln2("(XHEIGHT D %d)", xheight) ;
  1033.    voutln2("(QUAD D %d)", transform(1000,0)) ;
  1034.    voutln2("(EXTRASPACE D %d)", transform(fixedpitch ? fontspace : 111, 0)) ;
  1035.    vright() ;
  1036.    vleft() ; voutln("MAPFONT D 0");
  1037.    voutln2("(FONTNAME %s)", outname) ;
  1038.    voutln2("(FONTCHECKSUM O %lo)", cksum) ;
  1039.    vright() ;
  1040.    if (makevpl>1) {
  1041.       vleft() ; voutln("MAPFONT D 1");
  1042.       voutln2("(FONTNAME %s)", outname) ;
  1043.       voutln("(FONTAT D 800)") ;
  1044.       voutln2("(FONTCHECKSUM O %lo)", cksum) ;
  1045.       vright() ;
  1046.    }
  1047.  
  1048.    for (i=0; i<256 && texptrs[i]==NULL; i++) ;
  1049.    bc = i ;
  1050.    for (i=255; i>=0 && texptrs[i]==NULL; i--) ;
  1051.    ec = i;
  1052.  
  1053.    vleft() ; voutln("LIGTABLE") ;
  1054.    for (i=bc; i<=ec; i++)
  1055.       if (ai=texptrs[i]) {
  1056.          unlabeled = 1 ;
  1057.          if (uppercase[i]==NULL) /* omit ligatures from smallcap lowercase */
  1058.             for (nlig=ai->ligs; nlig; nlig=nlig->next)
  1059.                if (asucc=findadobe(nlig->succ))
  1060.                   if (asucc->texnum>=0)
  1061.                      if (asub=findadobe(nlig->sub))
  1062.                         if (asub->texnum>=0) {
  1063.                            if (unlabeled) {
  1064.                               voutln2("(LABEL %s)", vchar(i)) ;
  1065.                               unlabeled = 0 ;
  1066.                            }
  1067.                            voutln3("(LIG %s O %o)", vchar(asucc->texnum),
  1068.                                 asub->texnum) ;
  1069.                         }
  1070.          for (nkern = (uppercase[i] ? uppercase[i]->kerns : ai->kerns);
  1071.                     nkern; nkern=nkern->next)
  1072.             if (asucc=findadobe(nkern->succ))
  1073.                if (asucc->texnum>=0)
  1074.                   if (uppercase[asucc->texnum]==NULL) {
  1075.                      if (unlabeled) {
  1076.                         voutln2("(LABEL %s)", vchar(i)) ;
  1077.                         unlabeled = 0 ;
  1078.                      }
  1079.                      if (uppercase[i]) {
  1080.                         if (lowercase[asucc->texnum]) {
  1081.                            voutln3("(KRN %s R %.1f)",
  1082.                                  vchar(lowercase[asucc->texnum]->texnum),
  1083.                                  0.8*nkern->delta) ;
  1084.                         } else voutln3("(KRN %s R %.1f)",
  1085.                                  vchar(asucc->texnum), 0.8*nkern->delta) ;
  1086.                      } else {
  1087.                         voutln3("(KRN %s R %d)", vchar(asucc->texnum),
  1088.                                 nkern->delta) ;
  1089.                         if (lowercase[asucc->texnum])
  1090.                            if (lowercase[asucc->texnum]->texnum>=0)
  1091.                               voutln3("(KRN %s R %.1f)",
  1092.                                 vchar(lowercase[asucc->texnum]->texnum),
  1093.                                 0.8*nkern->delta) ;
  1094.                      }
  1095.                   }
  1096.          if (! unlabeled) voutln("(STOP)") ;
  1097.       }
  1098.    vright() ;
  1099.  
  1100.    for (i=bc; i<=ec; i++)
  1101.       if (ai=texptrs[i]) {
  1102.          vleft() ; fprintf(vplout, "CHARACTER %s", vchar(i)) ;
  1103.          if (*vcharbuf=='C') {
  1104.             voutln("") ;
  1105.          } else
  1106.             voutln2(" (comment %s)", ai->adobename) ;
  1107.          if (uppercase[i]) {
  1108.             ai=uppercase[i] ;
  1109.             voutln2("(CHARWD R %.1f)", 0.8 * (ai->width)) ;
  1110.             if (ht=texheight(ai)) voutln2("(CHARHT R %.1f)", 0.8 * ht) ;
  1111.             if (ai->lly) voutln2("(CHARDP R %.1f)", -0.8 * ai->lly) ;
  1112.             if (ai->urx > ai->width)
  1113.                voutln2("(CHARIC R %.1f)", 0.8 * (ai->urx - ai->width)) ;
  1114.          } else {
  1115.             voutln2("(CHARWD R %d)", ai->width) ;
  1116.             if (ht=texheight(ai)) voutln2("(CHARHT R %d)", ht) ;
  1117.             if (ai->lly) voutln2("(CHARDP R %d)", -ai->lly) ;
  1118.             if (ai->urx > ai->width)
  1119.                voutln2("(CHARIC R %d)", ai->urx - ai->width) ;
  1120.          }
  1121.          if (ai->adobenum != i || uppercase[i]) {
  1122.             vleft() ; voutln("MAP") ;
  1123.             if (uppercase[i]) voutln("(SELECTFONT D 1)") ;
  1124.             if (ai->pccs) {
  1125.                xoff = 0 ; yoff = 0 ;
  1126.                for (npcc = ai->pccs; npcc; npcc=npcc->next)
  1127.                   if (api=findadobe(npcc->partname))
  1128.                      if (api->texnum>=0) {
  1129.                         if (npcc->xoffset != xoff) {
  1130.                            if (uppercase[i]) {
  1131.                               voutln2("(MOVERIGHT R %.1f)",
  1132.                                       0.8 * (npcc->xoffset - xoff)) ;
  1133.                            } else voutln2("(MOVERIGHT R %d)",
  1134.                                       npcc->xoffset - xoff) ;
  1135.                            xoff = npcc->xoffset ;
  1136.                         }
  1137.                         if (npcc->yoffset != yoff) {
  1138.                            if (uppercase[i]) {
  1139.                               voutln2("(MOVEUP R %.1f)",
  1140.                                       0.8 * (npcc->yoffset - yoff)) ;
  1141.                            } else voutln2("(MOVEUP R %d)",
  1142.                                       npcc->yoffset - yoff) ;
  1143.                            yoff = npcc->yoffset ;
  1144.                         }
  1145.                         voutln2("(SETCHAR O %o)", api->adobenum) ;
  1146.                         xoff += texptrs[api->texnum]->width ;
  1147.                      }
  1148.             } else voutln2("(SETCHAR O %o)", ai->adobenum) ;
  1149.             vright() ;
  1150.          }
  1151.          vright() ;
  1152.       }
  1153.    if (level) error("! I forgot to match the parentheses") ;
  1154. }
  1155.  
  1156. void
  1157. openfiles(argc, argv)
  1158. int argc ;
  1159. char *argv[] ;
  1160. {
  1161.    register int lastext ;
  1162.    register int i ;
  1163.    extern void exit() ;
  1164.    tfmout = (FILE *)NULL ;
  1165.  
  1166.    if (argc == 1) {
  1167.       (void)printf("afm2tfm 5.36, Copyright 1990 by Radical Eye Software\n") ;
  1168.       (void)
  1169.         printf("Usage: afm2tfm foo[.afm] [-v|-V bar[.vpl]] [foo[.tfm]]\n") ;
  1170.      exit(0) ;
  1171.    }
  1172.  
  1173.    (void)sprintf(titlebuf, "%s %s", argv[0], argv[1]) ;
  1174.    (void)strcpy(inname, argv[1]) ;
  1175.    lastext = -1 ;
  1176.    for (i=0; inname[i]; i++)
  1177.       if (inname[i] == '.')
  1178.          lastext = i ;
  1179.       else if (inname[i] == '/' || inname[i] == ':')
  1180.          lastext = -1 ;
  1181.    if (lastext == -1) (void)strcat(inname, ".afm") ;
  1182.    if ((afmin=fopen(inname, "r"))==NULL)
  1183.       error("! can't open afm input file") ;
  1184.  
  1185.    while (argc>3 && *argv[2]=='-') {
  1186.       switch (argv[2][1]) {
  1187. case 'V': makevpl++ ;
  1188. case 'v': makevpl++ ;
  1189.          (void)strcpy(outname, argv[3]) ;
  1190.          lastext = -1 ;
  1191.          for (i=0; outname[i]; i++)
  1192.             if (outname[i] == '.')
  1193.                lastext = i ;
  1194.             else if (outname[i] == '/' || outname[i] == ':')
  1195.                lastext = -1 ;
  1196.          if (lastext == -1) (void)strcat(outname, ".vpl") ;
  1197.          if ((vplout=fopen(outname, WRITEBIN))==NULL)
  1198.             error("! can't open vpl output file") ;
  1199.          break ;
  1200. case 'e': if (sscanf(argv[3], "%f", &efactor)==0 || efactor<0.01)
  1201.             error("! Bad extension factor") ;
  1202.          break ;
  1203. case 's': if (sscanf(argv[3], "%f", &slant)==0)
  1204.             error("! Bad slant parameter") ;
  1205.          break ;
  1206. case 't':  /* get tfm name if present */
  1207.          (void)strcpy(outname, argv[3]) ;
  1208.          lastext = -1 ;
  1209.          for (i=0; outname[i]; i++)
  1210.             if (outname[i] == '.')
  1211.                lastext = i ;
  1212.             else if (outname[i] == '/' || outname[i] == ':')
  1213.                     lastext = -1 ;
  1214.         if (lastext == -1) {
  1215.            lastext = strlen(outname) ;
  1216.            (void)strcat(outname, ".tfm") ;
  1217.         }
  1218.         if ((tfmout=fopen(outname, WRITEBIN))==NULL)
  1219.            error("! can't open tfm output file") ;
  1220.         break ;
  1221. default: (void)fprintf(stderr, "Unknown option %s %s will be ignored.\n",
  1222.                          argv[2], argv[3]) ;
  1223.       }
  1224.       (void)sprintf(titlebuf, "%s %s %s", titlebuf, argv[2], argv[3]) ;
  1225.       argv += 2 ;
  1226.       argc -= 2 ;
  1227.    }
  1228.  
  1229.    if (argc>3 || (argc==3 && *argv[2]=='-'))
  1230.       error("! Usage: afm2tfm foo[.afm] [-v|-V bar[.vpl]] [foo[.tfm]]") ;
  1231.          
  1232.    if (argc == 2) (void)strcpy(outname, inname) ;
  1233.    else (void)strcpy(outname, argv[2]) ;
  1234.  
  1235.    lastext = -1 ;
  1236.    for (i=0; outname[i]; i++)
  1237.       if (outname[i] == '.')
  1238.          lastext = i ;
  1239.       else if (outname[i] == '/' || outname[i] == ':' || outname[i] == '\\')
  1240.          lastext = -1 ;
  1241.    if (argc == 2) {
  1242.       outname[lastext] = 0 ;
  1243.       lastext = -1 ;
  1244.    }
  1245.    if (lastext == -1) {
  1246.       lastext = strlen(outname) ;
  1247.       (void)strcat(outname, ".tfm") ;
  1248.    }
  1249.    if (tfmout == NULL && (tfmout=fopen(outname, WRITEBIN))==NULL)
  1250.       error("! can't open tfm output file") ;
  1251.    outname[lastext] = 0 ;
  1252. /*
  1253.  *   Now we strip off any directory information, so we only use the
  1254.  *   base name in the vf file.  We accept any of /, :, or \ as directory
  1255.  *   delimiters, so none of these are available for use inside the
  1256.  *   base name; this shouldn't be a problem.
  1257.  */
  1258.    for (i=0, lastext=0; outname[i]; i++)
  1259.       if (outname[i] == '/' || outname[i] == ':' || outname[i] == '\\')
  1260.          lastext = i + 1 ;
  1261.    if (lastext)
  1262.       strcpy(outname, outname + lastext) ;
  1263. }
  1264.  
  1265. #ifndef VMS
  1266. void
  1267. #endif
  1268. main(argc, argv)
  1269. int argc ;
  1270. char *argv[] ;
  1271. {
  1272.    extern void exit() ;
  1273.  
  1274.    openfiles(argc, argv) ;
  1275.    readadobe() ;
  1276.    buildtfm() ;
  1277.    writetfm() ;
  1278.    if (makevpl) {
  1279.       assignchars() ;
  1280.       if (makevpl>1) upmap() ;
  1281.       writevpl() ;
  1282.    }
  1283.    exit(0) ;
  1284.    /*NOTREACHED*/
  1285. }
  1286.