Back to index

tetex-bin  3.0
Defines | Functions | Variables
vaxvms.c File Reference
#include <stdio.h>
#include <types.h>
#include <ctype.h>
#include <stat.h>
#include <descrip.h>
#include <iodef.h>
#include <ssdef.h>

Go to the source code of this file.

Defines

#define EXIT   vms_exit
#define FTELL   vms_ftell
#define FSEEK   vms_fseek
#define GETENV   vms_getenv
#define GETCHAR   vms_getchar
#define READ   vms_read
#define UNGETC   vms_ungetc
#define FAILED(status)   (~(status) & 1) /* failure if LSB is 0 */

Functions

void EXIT (int code)
long FTELL (FILE *fp)
long FSEEK (FILE *fp, long n, long dir)
long UNGETC (char c, FILE *fp)
int GETCHAR (void)
int READ (int file_desc, char *buffer, int nbytes)
char * GETENV (char *name)
char * getlogin (void)
long tell (int handle)
int unlink (char *filename)
void vms_exit (int code)
int READ (register int file_desc, register char *buffer, register int nbytes)

Variables

static int tt_channel = -1

Define Documentation

#define EXIT   vms_exit

Definition at line 110 of file vaxvms.c.

#define FAILED (   status)    (~(status) & 1) /* failure if LSB is 0 */

Definition at line 256 of file vaxvms.c.

#define FSEEK   vms_fseek

Definition at line 112 of file vaxvms.c.

#define FTELL   vms_ftell

Definition at line 111 of file vaxvms.c.

int GETCHAR   vms_getchar

Definition at line 114 of file vaxvms.c.

#define GETENV   vms_getenv

Definition at line 113 of file vaxvms.c.

#define READ   vms_read

Definition at line 115 of file vaxvms.c.

#define UNGETC   vms_ungetc

Definition at line 116 of file vaxvms.c.


Function Documentation

void EXIT ( int  code)

Here is the caller graph for this function:

long FSEEK ( FILE fp,
long  n,
long  dir 
)

Definition at line 170 of file vaxvms.c.

{
    long k,m,pos,val,oldpos;
    struct stat buffer;

    for (;;)                /* loops only once or twice */
    {
      switch (dir)
      {
      case 0:               /* from BOF */
         oldpos = FTELL(fp);       /* get current byte offset in file */
         k = n & 511;              /* offset in 512-byte block */
         m = n >> 9;        /* relative block number in file */
         if (((*fp)->_cnt) && ((oldpos >> 9) == m)) /* still in same block */
         {
           val = 0;         /* success */
           (*fp)->_ptr = ((*fp)->_base) + k; /* reset pointers to requested byte */
           (*fp)->_cnt = 512 - k;
         }
         else
         {
           val = fseek(fp,m << 9,0); /* move to start of requested 512-byte block */
           if (val == 0)    /* success */
           {
             (*fp)->_cnt = 0;      /* indicate empty buffer */
             (void)fgetc(fp);      /* force refill of buffer */
             (*fp)->_ptr = ((*fp)->_base) + k;   /* reset pointers to requested byte */
             (*fp)->_cnt = 512 - k;
           }
         }
         return(val);

      case 1:               /* from current pos */
         pos = FTELL(fp);
         if (pos == EOF)    /* then error */
           return (EOF);
         n += pos;
         dir = 0;
         break;             /* go do case 0 */

      case 2:               /* from EOF */
         val = fstat(fileno(fp),&buffer);
         if (val == EOF)    /* then error */
           return (EOF);
         n += buffer.st_size - 1; /* convert filesize to offset and */
                               /* add to requested offset */
         dir = 0;
         break;             /* go do case 0 */

      default:                     /* illegal direction parameter */
         return (EOF);
      }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

long FTELL ( FILE fp)

Definition at line 233 of file vaxvms.c.

{
    char c;
    long pos;
    long val;
    if ((*fp)->_cnt == 0)   /* buffer empty--force refill */
    {
       c = fgetc(fp);
       val = UNGETC(c,fp);
       if (val != c)
           return (EOF);    /* should never happen */
    }
    pos = ftell(fp);        /* this returns multiple of 512 (start of block) */
    if (pos >= 0)           /* then success--patch in offset in block */
      pos += ((*fp)->_ptr) - ((*fp)->_base);
    return (pos);
}

Here is the caller graph for this function:

int GETCHAR ( void  )
char * GETENV ( char *  name)

Definition at line 321 of file vaxvms.c.

{
    char* p;
    char* result;
    char ucname[256];

    p = ucname;
    while (*name)    /* VMS logical names must be upper-case */
    {
      *p++ = islower(*name) ? toupper(*name) : *name;
      ++name;
    }
    *p = '\0';

    p = strchr(ucname,':');        /* colon in name? */
    if (p == (char *)NULL)         /* no colon in name */
        result = getenv(ucname);
    else                           /* try with and without colon */
    {
       result = getenv(ucname);
       if (result == (char *)NULL)
       {
           *p = '\0';
           result = getenv(ucname);
           *p = ':';
       }
    }
    return (result);
}
char * getlogin ( void  )

Definition at line 354 of file vaxvms.c.

{
    return ((char *)getenv("USER")); /* use equivalent VMS routine */
}
int READ ( int  file_desc,
char *  buffer,
int  nbytes 
)
int READ ( register int  file_desc,
register char *  buffer,
register int  nbytes 
)

Definition at line 283 of file vaxvms.c.

{
    register int ngot;
    register int left;
    
    for ((left = nbytes, ngot = 0); left > 0; /* NOOP */)
    {
       ngot = read(file_desc,buffer,left);
       if (ngot < 0)
           return (-1);     /* error occurred */
       buffer += ngot;
       left -= ngot;
    }
    return(nbytes-left);
}
long tell ( int  handle)

Definition at line 459 of file vaxvms.c.

{
    return (lseek(handle,0L,1));
}

Here is the call graph for this function:

long UNGETC ( char  c,
FILE fp 
)

Definition at line 302 of file vaxvms.c.

{                           /* (which is half the time!)        */

    if ((c == EOF) && feof(fp))
       return (EOF);        /* do nothing at true end-of-file */
    else if ((*fp)->_cnt >= 512)/* buffer full--no fgetc() done in this block!*/
       return (EOF);        /* must be user error if this happens */
    else                    /* put the character back in the buffer */
    {
      (*fp)->_cnt++;        /* increase count of characters left */
      (*fp)->_ptr--;        /* backup pointer to next available char */
      *((*fp)->_ptr) = c;   /* save the character */
      return (c);           /* and return it */
    }
}
int unlink ( char *  filename)

Definition at line 467 of file vaxvms.c.

{
       return (delete(filename)); /* use equivalent VMS routine */
}

Here is the caller graph for this function:

void vms_exit ( int  code)

Definition at line 145 of file vaxvms.c.

{
    switch (code)
    {
    case 0:
       exit(1);                    /* success */
       break;

    default:
       exit(2);                    /* error */
       break;
    }
}

Here is the call graph for this function:


Variable Documentation

int tt_channel = -1 [static]

Definition at line 254 of file vaxvms.c.