Back to index

tetex-bin  3.0
t1stdio.h
Go to the documentation of this file.
00001 /* $XConsortium: t1stdio.h,v 1.4 91/10/10 11:19:49 rws Exp $ */
00002 /* Copyright International Business Machines,Corp. 1991
00003  * All Rights Reserved
00004  *
00005  * License to use, copy, modify, and distribute this software
00006  * and its documentation for any purpose and without fee is
00007  * hereby granted, provided that the above copyright notice
00008  * appear in all copies and that both that copyright notice and
00009  * this permission notice appear in supporting documentation,
00010  * and that the name of IBM not be used in advertising or
00011  * publicity pertaining to distribution of the software without
00012  * specific, written prior permission.
00013  *
00014  * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
00015  * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
00016  * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
00018  * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
00019  * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
00020  * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
00021  * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
00022  * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
00023  * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
00024  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
00025  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
00026  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
00027  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00028  * SOFTWARE.
00029  */
00030 /* T1IO FILE structure and related stuff */
00031 
00032 #include "types.h"
00033 
00034 #undef  getc
00035 #undef  fclose
00036 #undef  ungetc
00037 #undef  fgetc
00038 #undef  fread
00039 #undef  feof
00040 #undef  ferror
00041 #undef  FILE
00042 
00043 #define FILE F_FILE
00044 typedef unsigned char F_char;
00045  
00046 typedef struct F_FILE {
00047   F_char  *b_base;    /* Pointer to beginning of buffer */
00048   LONG    b_size;     /* Size of the buffer */
00049   F_char  *b_ptr;     /* Pointer to next char in buffer */
00050   LONG    b_cnt;      /* Number of chars remaining in buffer */
00051   F_char  flags;      /* other flags; != 0 means getc must call fgetc */
00052   F_char  ungotc;     /* Place for ungotten char; flag set if present */
00053   short   error;      /* error status */
00054   int     fd;         /* underlying file descriptor */
00055 } F_FILE;
00056  
00057  
00058 /* defines for flags */
00059 #define UNGOTTENC (0x01)
00060 #define FIOEOF    (0x80)
00061 #define FIOERROR  (0x40)
00062  
00063 #ifndef NULL
00064 #define NULL 0       /* null pointer */
00065 #endif
00066 #ifndef EOF
00067 #define EOF (-1)     /* end of file */
00068 #endif
00069 #define F_BUFSIZ (512)
00070  
00071 #define getc(f) \
00072   ( \
00073    ( ((f)->b_cnt > 0) && ((f)->flags == 0) ) ? \
00074    ( (f)->b_cnt--, (unsigned int)*( (f)->b_ptr++ ) ) : \
00075    T1Getc(f) \
00076   )
00077  
00078 extern FILE *T1Open(), *T1eexec();
00079 extern int T1Close(), T1Ungetc(), T1Read();
00080 
00081 #define  fclose(f)          T1Close(f)
00082 #define  fopen(name,mode)   T1Open(name,mode)
00083 #define  ungetc(c,f)        T1Ungetc(c,f)
00084 #define  fgetc(f)           T1Getc(f)
00085 #define  fread(bufP,size,n,f) T1Read(bufP,size,n,f)
00086 #define  feof(f)            (((f)->flags & FIOEOF) && ((f)->b_cnt==0))
00087 #define  ferror(f)          (((f)->flags & FIOERROR)?(f)->error:0)