
# include <stdio.h>
typedef int Truth;
class File { // Implementation layered on FILE
public:
    File( char *name = "", char *mode = "r")
    {
        if( *name )
            fp = fopen( name, mode);
        else if( *mode == 'r' )
            fp = stdin;
        else
            fp = stdout;
        state = (int)fp;
    }

    ~File()           { if( fp) fclose( fp); }

    Truth isok()      { return state; }

    Truth iseof()     { return feof( fp); }

    int get()         { return getc( fp); }
    // unget and peek useful for lexical scanners
    void unget(int c) { (void)ungetc( c, fp); }

    int peek()  { int c = get(); unget(c); return c; }

    void put( int c)  { putc( c, fp); }
private:
    FILE *fp;
    int state;
};

