Back to index

tetex-bin  3.0
Defines | Functions | Variables
t1io.c File Reference
#include "c-auto.h"
#include "t1stdio.h"
#include "t1hdigit.h"

Go to the source code of this file.

Defines

#define STATIC   static
#define c1   ((unsigned short)52845)
#define c2   ((unsigned short)22719)

Functions

F_FILET1Open ()
F_FILET1Eexec ()
int T1Close ()
int T1Read ()
int T1Getc ()
int T1Ungetc ()
STATIC int T1Decrypt ()
STATIC int T1Fill ()
F_FILET1Open (char *fn, char *mode)
int T1Getc (F_FILE *f)
int T1Ungetc (int c, F_FILE *f)
int T1Read (char *buffP, int size, int n, F_FILE *f)
int T1Close (F_FILE *f)
F_FILET1eexec (F_FILE *f)
STATIC int T1Decrypt (unsigned char *p, int len)
STATIC int T1Fill (F_FILE *f)

Variables

static unsigned short r
static int asc
static int Decrypt
static int extrach
static int haveextrach
STATIC F_FILE TheFile
STATIC unsigned char TheBuffer [F_BUFSIZ]

Define Documentation

#define c1   ((unsigned short)52845)

Definition at line 50 of file t1io.c.

#define c2   ((unsigned short)22719)

Definition at line 51 of file t1io.c.

#define STATIC   static

Definition at line 37 of file t1io.c.


Function Documentation

int T1Close ( )
int T1Close ( F_FILE f)

Definition at line 167 of file t1io.c.

{
  if (f->b_base == NULL) return 0;  /* already closed */
  f->b_base = NULL;  /* no valid stream */
  return close(f->fd);
} /* end Close */
STATIC int T1Decrypt ( unsigned char *  p,
int  len 
)

Definition at line 224 of file t1io.c.

{
  int n;
  int H, L;
  unsigned char *inp = p;
  unsigned char *tblP;
 
  if (asc) {
    if (haveextrach) {
      H = extrach;
      tblP = LowHexP;
    }
    else tblP = HighHexP;
    for (n=0; len>0; len--) {
      L = tblP[*inp++];
      if (L == HWHITE_SPACE) continue;
      if (L > LAST_HDIGIT) break;
      if (tblP == HighHexP) { /* Got first hexit value */
        H = L;
        tblP = LowHexP;
      } else { /* Got second hexit value; compute value and store it */
        n++;
        tblP = HighHexP;
        H |= L;
        /* H is an int, 0 <= H <= 255, so all of this will work */
        *p++ = H ^ (r >> 8);
        r = (H + r) * c1 + c2;
      }
    }
    if (tblP != HighHexP) {  /* We had an odd number of hexits */
      extrach = H;
      haveextrach = 1;
    } else haveextrach = 0;
    return n;
  } else {
    for (n = len; n>0; n--) {
      H = *inp++;
      *p++ = H ^ (r >> 8);
      r = (H + r) * c1 + c2;
    }
    return len;
  }
} /* end Decrypt */

Here is the call graph for this function:

F_FILE * T1Eexec ( )
F_FILE* T1eexec ( F_FILE f) [read]

Definition at line 176 of file t1io.c.

{
  int i, c;
  int H;
  unsigned char *p;
  unsigned char randomP[8];
 
  r = 55665;  /* initial key */
  asc = 1;    /* indicate ASCII form */
 
  /* Consume the 4 random bytes, determining if we are also to
     ASCIIDecodeHex as we process our input.  (See pages 63-64
     of the Adobe Type 1 Font Format book.)  */
 
  /* Skip over any initial white space chars */
  while (HighHexP[c=getc(f)] == HWHITE_SPACE) ;
 
  /* If ASCII, the next 7 chars are guaranteed consecutive */
  randomP[0] = c;  /* store first non white space char */
  fread(randomP+1, 1, 3, f);  /* read 3 more, for a total of 4 */
  /* store first four chars */
  for (i=0,p=randomP; i<4; i++) {  /* Check 4 valid ASCIIEncode chars */
    if (HighHexP[*p++] > LAST_HDIGIT) {  /* non-ASCII byte */
      asc = 0;
      break;
    }
  }
  if (asc) {  /* ASCII form, convert first eight bytes to binary */
    fread(randomP+4, 1, 4, f);  /* Need four more */
    for (i=0,p=randomP; i<4; i++) {  /* Convert */
      H = HighHexP[*p++];
      randomP[i] = H | LowHexP[*p++];
    }
  }
 
  /* Adjust our key */
  for (i=0,p=randomP; i<4; i++) {
    r = (*p++ + r) * c1 + c2;
  }
 
  /* Decrypt the remaining buffered bytes */
  f->b_cnt = T1Decrypt(f->b_ptr, f->b_cnt);
  Decrypt = 1;
  return (feof(f))?NULL:f;
} /* end eexec */

Here is the call graph for this function:

STATIC int T1Fill ( F_FILE f)

Definition at line 271 of file t1io.c.

{
  int rc;
 
  rc = read(f->fd, f->b_base, F_BUFSIZ);
  /* propagate any error or eof to current file */
  if (rc <= 0) {
    if (rc == 0)    /* means EOF */
      f->flags |= FIOEOF;
    else {
      f->error = (short)-rc;
      f->flags |= FIOERROR;
      rc = 0;
    }
  }
  f->b_ptr = f->b_base;
  if (Decrypt) rc = T1Decrypt(f->b_base, rc);
  return rc;
} /* end Fill */

Here is the call graph for this function:

int T1Getc ( )
int T1Getc ( F_FILE f)

Definition at line 96 of file t1io.c.

{
  if (f->b_base == NULL) return EOF;  /* already closed */
 
  if (f->flags & UNGOTTENC) { /* there is an ungotten c */
    f->flags &= ~UNGOTTENC;
    return (int) f->ungotc;
  }
 
  if (f->b_cnt == 0)  /* Buffer needs to be (re)filled */
    f->b_cnt = T1Fill(f);
  if (f->b_cnt > 0) return (f->b_cnt--, (int) *(f->b_ptr++));
  else {
    f->flags |= FIOEOF;
    return EOF;
  }
} /* end Getc */

Here is the call graph for this function:

Here is the caller graph for this function:

F_FILE* T1Open ( )
F_FILE* T1Open ( char *  fn,
char *  mode 
) [read]

Definition at line 69 of file t1io.c.

{
  F_FILE *of = &TheFile;
 
  Decrypt = 0;
 
  /* We know we are only reading */
#if defined(MSDOS) || defined(VMS) || defined(WIN32)
  if ((of->fd=open(fn, O_RDONLY | O_BINARY)) < 0) return NULL;
#else
  if ((of->fd=open(fn, O_RDONLY)) < 0) return NULL;
#endif
 
  /* Initialize the buffer information of our file descriptor */
  of->b_base = TheBuffer;
  of->b_size = F_BUFSIZ;
  of->b_ptr = NULL;
  of->b_cnt = 0;
  of->flags = 0;
  of->error = 0;
  haveextrach = 0;
  return &TheFile;
} /* end Open */

Here is the call graph for this function:

int T1Read ( )
int T1Read ( char *  buffP,
int  size,
int  n,
F_FILE f 
)

Definition at line 129 of file t1io.c.

{
  int bytelen, cnt, i;
  F_char *p = (F_char *)buffP;
  int  icnt;         /* Number of characters to read */
 
  if (f->b_base == NULL) return 0;  /* closed */
  icnt = (size!=1)?n*size:n;  /* Number of bytes we want */
 
  if (f->flags & UNGOTTENC) { /* there is an ungotten c */
    f->flags &= ~UNGOTTENC;
    *(p++) = f->ungotc;
    icnt--; bytelen = 1;
  }
  else bytelen = 0;
 
  while (icnt > 0) {
    /* First use any bytes we have buffered in the stream buffer */
    if ((cnt=f->b_cnt) > 0) {
      if (cnt > icnt) cnt = icnt;
      for (i=0; i<cnt; i++) *(p++) = *(f->b_ptr++);
      f->b_cnt -= cnt;
      icnt -= cnt;
      bytelen += cnt;
    }
 
    if ((icnt == 0) || (f->flags & FIOEOF)) break;
 
    f->b_cnt = T1Fill(f);
  }
  return ((size!=1)?bytelen/size:bytelen);
} /* end Read */

Here is the call graph for this function:

int T1Ungetc ( int  c,
F_FILE f 
)

Definition at line 116 of file t1io.c.

{
  if (c != EOF) {
    f->ungotc = c;
    f->flags |= UNGOTTENC;  /* set flag */
    f->flags &= ~FIOEOF;    /* reset EOF */
  }
  return c;
} /* end Ungetc */

Here is the caller graph for this function:


Variable Documentation

int asc [static]

Definition at line 53 of file t1io.c.

int Decrypt [static]

Definition at line 53 of file t1io.c.

int extrach [static]

Definition at line 54 of file t1io.c.

int haveextrach [static]

Definition at line 55 of file t1io.c.

unsigned short r [static]

Definition at line 52 of file t1io.c.

STATIC unsigned char TheBuffer[F_BUFSIZ]

Definition at line 59 of file t1io.c.

Definition at line 58 of file t1io.c.