/*
 * stdio.h
 * PDC I/O Library Copyright (C) 1987 by J.A. Lydiatt.
 * Freely Distributable for non-commercial use.
 */
/*
 * I'll try to begin PD System variables with an '_'.
 */

#ifndef _STDIO_H
#  define _STDIO_H
#  ifndef  NULL
#    define NULL 0
#  endif
#  define EOF -1

#  define BUFSIZ 1024
#  define MAXSTREAM 20

#  define _FILEACTIVE	0x01
#  define _FILEISDYNA	0x02
#  define _FILEISDIRTY 	0x04
#  define _FILEATEOF	0x08
#  define _FILEBAD		0x10
#  define _FILEISTTY	0x80

	typedef struct _fdevice {
	struct _fdevice *next; /* pointer to the next table entry */
	char *_filecpos;	/* Current position in the buffer */
	char *_fileend;		/* one past last char in buffer */
	char *_filebufp;	/* pointer to the buffer */
	short _fileflag;	/* mode flags */
	short _fileunit;	/* value returned by open */
	char  _filebyte;	/* one byte used by unbuffered streams. */
	short _filelen;		/* length of the buffer. */
	}
		FILE;

	extern FILE _fdevtab[];

#	define stdin		(&_fdevtab[0])
#	define stdout		(&_fdevtab[1])
#	define stderr		(&_fdevtab[2])
#	define getchar()	getc(stdin)
#	define fgetc(fp)	getc(fp)
#	define putchar(c)	putc(c,stdout)
#	define fputc(c,fp)	putc(c,fp)
#	define feof(fp)		(((fp)->_fileflag & _FILEATEOF) != 0)
#	define ferror(fp)	((fp)->_fileflag & _FILEBAD) != 0)
#	define clearerr(fp)	((fp)->_fileflag &= ~(_FILEBAD|_FILEATEOF))
#	define fileno(fp)	((int)(fp)->_fileunit) 
#	define fflush(fp)	_doflush(fp, -1)
#	define rewind		fseek(fp, 0L, 0)

#endif
