home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / stex2-18.zip / SeeTeX / libtex / tfm.c < prev    next >
C/C++ Source or Header  |  1990-07-10  |  2KB  |  123 lines

  1. /*
  2.  * Copyright (c) 1987, 1989 University of Maryland
  3.  * Department of Computer Science.  All rights reserved.
  4.  * Permission to copy for any purpose is hereby granted
  5.  * so long as this copyright notice remains intact.
  6.  */
  7.  
  8. #ifndef lint
  9. static char rcsid[] = "$Header: /usr/src/local/tex/local/mctex/lib/RCS/tfm.c,v 3.1 89/08/22 22:00:12 chris Exp $";
  10. #endif
  11.  
  12. /*
  13.  * TFM file reading routines.
  14.  *
  15.  * TODO:
  16.  *    finish
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include "types.h"
  21. #include "fio.h"
  22. #include "tfm.h"
  23.  
  24. static int trd_header(), trd_ci(), trd_fix();
  25.  
  26. char    *malloc();
  27.  
  28. #define    ALLOC(n, type)    ((type *)malloc((unsigned)((n) * sizeof(type))))
  29.  
  30. int
  31. readtfmfile(f, t, stopafterwidth)
  32.     register FILE *f;
  33.     register struct tfmdata *t;
  34.     int stopafterwidth;    /* ??? */
  35. {
  36.     i32 nc;
  37.  
  38.     if (trd_header(f, &t->t_hdr))
  39.         return (-1);
  40.     nc = t->t_hdr.th_ec - t->t_hdr.th_bc + 1;
  41.  
  42.     t->t_ci = NULL;
  43.     t->t_width = NULL;
  44.     t->t_height = NULL;
  45.     t->t_depth = NULL;
  46.  
  47.     (void) fseek(f, t->t_hdr.th_lh * 4L, 1);    /* XXX */
  48.  
  49.     if ((t->t_ci = ALLOC(nc, struct char_info_word)) == NULL ||
  50.         trd_ci(f, nc, t->t_ci) ||
  51.         (t->t_width = ALLOC(t->t_hdr.th_nw, i32)) == NULL ||
  52.         trd_fix(f, t->t_hdr.th_nw, t->t_width))
  53.         goto bad;
  54.     if (stopafterwidth)
  55.         return (0);
  56.     if ((t->t_height = ALLOC(t->t_hdr.th_nh, i32)) == NULL ||
  57.         trd_fix(f, t->t_hdr.th_nh, t->t_height) ||
  58.         (t->t_depth = ALLOC(t->t_hdr.th_nd, i32)) == NULL ||
  59.         trd_fix(f, t->t_hdr.th_nd, t->t_depth))
  60.         goto bad;
  61.     return (0);
  62.  
  63. bad:
  64.     if (t->t_ci != NULL)
  65.         free((char *) t->t_ci);
  66.     if (t->t_width != NULL)
  67.         free((char *) t->t_width);
  68.     if (t->t_height != NULL)
  69.         free((char *) t->t_height);
  70.     if (t->t_depth != NULL)
  71.         free((char *) t->t_depth);
  72.     return (-1);
  73. }
  74.  
  75. static int
  76. trd_header(f, th)
  77.     register FILE *f;
  78.     register struct tfmheader *th;
  79. {
  80.     register i32 *p;
  81.  
  82.     for (p = &th->th_lf; p <= &th->th_np; p++)
  83.         fGetWord(f, *p);
  84.     if (feof(f))
  85.         return (-1);
  86.     return (0);
  87. }
  88.  
  89. static int
  90. trd_ci(f, nc, ci)
  91.     register FILE *f;
  92.     register int nc;
  93.     register struct char_info_word *ci;
  94. {
  95.  
  96.     while (--nc >= 0) {
  97.         ci->ci_width = fgetbyte(f);
  98.         ci->ci_h_d = fgetbyte(f);
  99.         ci->ci_i_t = fgetbyte(f);
  100.         ci->ci_remainder = fgetbyte(f);
  101.         ci++;
  102.     }
  103.     if (feof(f))
  104.         return (-1);
  105.     return (0);
  106. }
  107.  
  108. static int
  109. trd_fix(f, nf, p)
  110.     register FILE *f;
  111.     register int nf;
  112.     register i32 *p;
  113. {
  114.  
  115.     while (--nf >= 0) {
  116.         fGetLong(f, *p);
  117.         p++;
  118.     }
  119.     if (feof(f))
  120.         return (-1);
  121.     return (0);
  122. }
  123.