require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&_OCURSES_H_)) {
    eval 'sub _OCURSES_H_ () {1;}' unless defined(&_OCURSES_H_);
    require 'sys/types.ph';
    require 'sys/cdefs.ph';
    require 'stdio.ph';
    eval 'sub bool () {\'char\';}' unless defined(&bool);
    unless(defined(&TRUE)) {
	eval 'sub TRUE () {(1);}' unless defined(&TRUE);
    }
    unless(defined(&FALSE)) {
	eval 'sub FALSE () {(0);}' unless defined(&FALSE);
    }
    unless(defined(&_CURSES_PRIVATE)) {
	eval 'sub _puts {
	    my($s) = @_;
    	    eval q( &tputs($s, 0,  &__cputchar));
	}' unless defined(&_puts);
	eval 'sub _putchar {
	    my($c) = @_;
    	    eval q( &__cputchar($c));
	}' unless defined(&_putchar);
	eval 'sub baudrate () {
	    eval q(( &cfgetospeed(& &__baset)));
	}' unless defined(&baudrate);
	eval 'sub crmode () {
	    eval q( &cbreak());
	}' unless defined(&crmode);
	eval 'sub erasechar () {
	    eval q(( ($__baset->{c_cc[&VERASE]})));
	}' unless defined(&erasechar);
	eval 'sub killchar () {
	    eval q(( ($__baset->{c_cc[&VKILL]})));
	}' unless defined(&killchar);
	eval 'sub nocrmode () {
	    eval q( &nocbreak());
	}' unless defined(&nocrmode);
	eval 'sub ospeed () {( &cfgetospeed(& &__baset));}' unless defined(&ospeed);
    }
    eval 'sub unctrl {
        my($c) = @_;
	    eval q( $__unctrl[($c) & 0xff]);
    }' unless defined(&unctrl);
    eval 'sub unctrllen {
        my($ch) = @_;
	    eval q( $__unctrllen[($ch) & 0xff]);
    }' unless defined(&unctrllen);
    eval 'sub __STANDOUT () {0x1;}' unless defined(&__STANDOUT);
    eval 'sub __LDATASIZE () {($sizeof{ &__LDATA});}' unless defined(&__LDATASIZE);
    eval 'sub __ISDIRTY () {0x1;}' unless defined(&__ISDIRTY);
    eval 'sub __ISPASTEOL () {0x2;}' unless defined(&__ISPASTEOL);
    eval 'sub __FORCEPAINT () {0x4;}' unless defined(&__FORCEPAINT);
    eval 'sub __ENDLINE () {0x1;}' unless defined(&__ENDLINE);
    eval 'sub __FLUSH () {0x2;}' unless defined(&__FLUSH);
    eval 'sub __FULLWIN () {0x4;}' unless defined(&__FULLWIN);
    eval 'sub __IDLINE () {0x8;}' unless defined(&__IDLINE);
    eval 'sub __SCROLLWIN () {0x10;}' unless defined(&__SCROLLWIN);
    eval 'sub __SCROLLOK () {0x20;}' unless defined(&__SCROLLOK);
    eval 'sub __CLEAROK () {0x40;}' unless defined(&__CLEAROK);
    eval 'sub __WSTANDOUT () {0x80;}' unless defined(&__WSTANDOUT);
    eval 'sub __LEAVEOK () {0x100;}' unless defined(&__LEAVEOK);
    eval 'sub ERR () {(0);}' unless defined(&ERR);
    eval 'sub OK () {(1);}' unless defined(&OK);
    eval 'sub addbytes {
        my($s, $n) = @_;
	    eval q( &__waddbytes( &stdscr, $s, $n, 0));
    }' unless defined(&addbytes);
    eval 'sub addch {
        my($ch) = @_;
	    eval q( &waddch( &stdscr, $ch));
    }' unless defined(&addch);
    eval 'sub addnstr {
        my($s, $n) = @_;
	    eval q( &waddnstr( &stdscr, $s, $n));
    }' unless defined(&addnstr);
    eval 'sub addstr {
        my($s) = @_;
	    eval q( &__waddbytes( &stdscr, $s,  &strlen($s), 0));
    }' unless defined(&addstr);
    eval 'sub clear () {
        eval q( &wclear( &stdscr));
    }' unless defined(&clear);
    eval 'sub clrtobot () {
        eval q( &wclrtobot( &stdscr));
    }' unless defined(&clrtobot);
    eval 'sub clrtoeol () {
        eval q( &wclrtoeol( &stdscr));
    }' unless defined(&clrtoeol);
    eval 'sub delch () {
        eval q( &wdelch( &stdscr));
    }' unless defined(&delch);
    eval 'sub deleteln () {
        eval q( &wdeleteln( &stdscr));
    }' unless defined(&deleteln);
    eval 'sub erase () {
        eval q( &werase( &stdscr));
    }' unless defined(&erase);
    eval 'sub getch () {
        eval q( &wgetch( &stdscr));
    }' unless defined(&getch);
    eval 'sub getstr {
        my($s) = @_;
	    eval q( &wgetstr( &stdscr, $s));
    }' unless defined(&getstr);
    eval 'sub inch () {
        eval q( &winch( &stdscr));
    }' unless defined(&inch);
    eval 'sub insch {
        my($ch) = @_;
	    eval q( &winsch( &stdscr, $ch));
    }' unless defined(&insch);
    eval 'sub insertln () {
        eval q( &winsertln( &stdscr));
    }' unless defined(&insertln);
    eval 'sub move {
        my($y, $x) = @_;
	    eval q( &wmove( &stdscr, $y, $x));
    }' unless defined(&move);
    eval 'sub refresh () {
        eval q( &wrefresh( &stdscr));
    }' unless defined(&refresh);
    eval 'sub standend () {
        eval q( &wstandend( &stdscr));
    }' unless defined(&standend);
    eval 'sub standout () {
        eval q( &wstandout( &stdscr));
    }' unless defined(&standout);
    eval 'sub waddbytes {
        my($w, $s, $n) = @_;
	    eval q( &__waddbytes($w, $s, $n, 0));
    }' unless defined(&waddbytes);
    eval 'sub waddstr {
        my($w, $s) = @_;
	    eval q( &__waddbytes($w, $s,  &strlen($s), 0));
    }' unless defined(&waddstr);
    eval 'sub mvaddbytes {
        my($y, $x, $s, $n) = @_;
	    eval q( &mvwaddbytes( &stdscr, $y, $x, $s, $n));
    }' unless defined(&mvaddbytes);
    eval 'sub mvaddch {
        my($y, $x, $ch) = @_;
	    eval q( &mvwaddch( &stdscr, $y, $x, $ch));
    }' unless defined(&mvaddch);
    eval 'sub mvaddnstr {
        my($y, $x, $s, $n) = @_;
	    eval q( &mvwaddnstr( &stdscr, $y, $x, $s, $n));
    }' unless defined(&mvaddnstr);
    eval 'sub mvaddstr {
        my($y, $x, $s) = @_;
	    eval q( &mvwaddstr( &stdscr, $y, $x, $s));
    }' unless defined(&mvaddstr);
    eval 'sub mvdelch {
        my($y, $x) = @_;
	    eval q( &mvwdelch( &stdscr, $y, $x));
    }' unless defined(&mvdelch);
    eval 'sub mvgetch {
        my($y, $x) = @_;
	    eval q( &mvwgetch( &stdscr, $y, $x));
    }' unless defined(&mvgetch);
    eval 'sub mvgetstr {
        my($y, $x, $s) = @_;
	    eval q( &mvwgetstr( &stdscr, $y, $x, $s));
    }' unless defined(&mvgetstr);
    eval 'sub mvinch {
        my($y, $x) = @_;
	    eval q( &mvwinch( &stdscr, $y, $x));
    }' unless defined(&mvinch);
    eval 'sub mvinsch {
        my($y, $x, $c) = @_;
	    eval q( &mvwinsch( &stdscr, $y, $x, $c));
    }' unless defined(&mvinsch);
    eval 'sub mvwaddbytes {
        my($w, $y, $x, $s, $n) = @_;
	    eval q(( &wmove($w, $y, $x) ==  &ERR ?  &ERR :  &__waddbytes($w, $s, $n, 0)));
    }' unless defined(&mvwaddbytes);
    eval 'sub mvwaddch {
        my($w, $y, $x, $ch) = @_;
	    eval q(( &wmove($w, $y, $x) ==  &ERR ?  &ERR :  &waddch($w, $ch)));
    }' unless defined(&mvwaddch);
    eval 'sub mvwaddnstr {
        my($w, $y, $x, $s, $n) = @_;
	    eval q(( &wmove($w, $y, $x) ==  &ERR ?  &ERR :  &waddnstr($w, $s, $n)));
    }' unless defined(&mvwaddnstr);
    eval 'sub mvwaddstr {
        my($w, $y, $x, $s) = @_;
	    eval q(( &wmove($w, $y, $x) ==  &ERR ?  &ERR :  &__waddbytes($w, $s,  &strlen($s), 0)));
    }' unless defined(&mvwaddstr);
    eval 'sub mvwdelch {
        my($w, $y, $x) = @_;
	    eval q(( &wmove($w, $y, $x) ==  &ERR ?  &ERR :  &wdelch($w)));
    }' unless defined(&mvwdelch);
    eval 'sub mvwgetch {
        my($w, $y, $x) = @_;
	    eval q(( &wmove($w, $y, $x) ==  &ERR ?  &ERR :  &wgetch($w)));
    }' unless defined(&mvwgetch);
    eval 'sub mvwgetstr {
        my($w, $y, $x, $s) = @_;
	    eval q(( &wmove($w, $y, $x) ==  &ERR ?  &ERR :  &wgetstr($w, $s)));
    }' unless defined(&mvwgetstr);
    eval 'sub mvwinch {
        my($w, $y, $x) = @_;
	    eval q(( &wmove($w, $y, $x) ==  &ERR ?  &ERR :  &winch($w)));
    }' unless defined(&mvwinch);
    eval 'sub mvwinsch {
        my($w, $y, $x, $c) = @_;
	    eval q(( &wmove($w, $y, $x) ==  &ERR ?  &ERR :  &winsch($w, $c)));
    }' unless defined(&mvwinsch);
    eval 'sub clearok {
        my($w, $bf) = @_;
	    eval q((($bf) ? (($w)-> &flags |=  &__CLEAROK) : (($w)-> &flags &= ~ &__CLEAROK)));
    }' unless defined(&clearok);
    eval 'sub flushok {
        my($w, $bf) = @_;
	    eval q((($bf) ? (($w)-> &flags |=  &__FLUSH) : (($w)-> &flags &= ~ &__FLUSH)));
    }' unless defined(&flushok);
    eval 'sub getyx {
        my($w, $y, $x) = @_;
	    eval q(($y) = ($w)-> &cury, ($x) = ($w)-> &curx);
    }' unless defined(&getyx);
    eval 'sub leaveok {
        my($w, $bf) = @_;
	    eval q((($bf) ? (($w)-> &flags |=  &__LEAVEOK) : (($w)-> &flags &= ~ &__LEAVEOK)));
    }' unless defined(&leaveok);
    eval 'sub scrollok {
        my($w, $bf) = @_;
	    eval q((($bf) ? (($w)-> &flags |=  &__SCROLLOK) : (($w)-> &flags &= ~ &__SCROLLOK)));
    }' unless defined(&scrollok);
    eval 'sub winch {
        my($w) = @_;
	    eval q((($w)-> ($lines[&(w)->{cury]}->{line[&(w)}->{curx]}->{ch}) & 0177));
    }' unless defined(&winch);
    if(defined(&_CURSES_PRIVATE)) {
	eval 'sub min {
	    my($a,$b) = @_;
    	    eval q(($a < $b ? $a : $b));
	}' unless defined(&min);
	eval 'sub max {
	    my($a,$b) = @_;
    	    eval q(($a > $b ? $a : $b));
	}' unless defined(&max);
    }
}
1;
