require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&_CHARDEFS_H_)) {
    eval 'sub _CHARDEFS_H_ () {1;}' unless defined(&_CHARDEFS_H_);
    require 'ctype.ph';
    if(defined ( &HAVE_CONFIG_H)) {
	if(defined ( &HAVE_STRING_H)) {
	    if(! defined ( &STDC_HEADERS)  && defined ( &HAVE_MEMORY_H)) {
		require 'memory.ph';
	    }
	    require 'string.ph';
	}
	if(defined ( &HAVE_STRINGS_H)) {
	    require 'strings.ph';
	}
    } else {
	require 'string.ph';
    }
    unless(defined(&whitespace)) {
	eval 'sub whitespace {
	    my($c) = @_;
    	    eval q(((($c) == ord(\' \') || ((c) == \'\\\\t\'))));
	}' unless defined(&whitespace);
    }
    if(defined(&CTRL)) {
	undef(&CTRL) if defined(&CTRL);
    }
    if(defined(&UNCTRL)) {
	undef(&UNCTRL) if defined(&UNCTRL);
    }
    eval 'sub control_character_threshold () {0x20;}' unless defined(&control_character_threshold);
    eval 'sub control_character_mask () {0x1f;}' unless defined(&control_character_mask);
    eval 'sub meta_character_threshold () {0x7f;}' unless defined(&meta_character_threshold);
    eval 'sub control_character_bit () {0x40;}' unless defined(&control_character_bit);
    eval 'sub meta_character_bit () {0x80;}' unless defined(&meta_character_bit);
    eval 'sub largest_char () {255;}' unless defined(&largest_char);
    eval 'sub CTRL_CHAR {
        my($c) = @_;
	    eval q((($c) <  &control_character_threshold  && ((($c) & 0x80) == 0)));
    }' unless defined(&CTRL_CHAR);
    eval 'sub META_CHAR {
        my($c) = @_;
	    eval q((($c) >  &meta_character_threshold  && ($c) <=  &largest_char));
    }' unless defined(&META_CHAR);
    eval 'sub CTRL {
        my($c) = @_;
	    eval q((($c) &  &control_character_mask));
    }' unless defined(&CTRL);
    eval 'sub META {
        my($c) = @_;
	    eval q((($c) |  &meta_character_bit));
    }' unless defined(&META);
    eval 'sub UNMETA {
        my($c) = @_;
	    eval q((($c) & (~ &meta_character_bit)));
    }' unless defined(&UNMETA);
    eval 'sub UNCTRL {
        my($c) = @_;
	    eval q( &_rl_to_upper((($c)| &control_character_bit)));
    }' unless defined(&UNCTRL);
    if(defined (defined(&STDC_HEADERS) ? &STDC_HEADERS : 0) || (!defined ( &isascii)  && !defined ( &HAVE_ISASCII))) {
	eval 'sub IN_CTYPE_DOMAIN {
	    my($c) = @_;
    	    eval q(1);
	}' unless defined(&IN_CTYPE_DOMAIN);
    } else {
	eval 'sub IN_CTYPE_DOMAIN {
	    my($c) = @_;
    	    eval q( &isascii($c));
	}' unless defined(&IN_CTYPE_DOMAIN);
    }
    if(!defined ( &isxdigit)  && !defined ( &HAVE_ISXDIGIT)) {
	eval 'sub isxdigit {
	    my($c) = @_;
    	    eval q(( &isdigit(($c)) || (($c) >= ord(\'a\' && (c) <= \'f\') || ((c) >= \'A\' && (c) <= \'F\'))));
	}' unless defined(&isxdigit);
    }
    eval 'sub NON_NEGATIVE {
        my($c) = @_;
	    eval q((($c) == ($c)));
    }' unless defined(&NON_NEGATIVE);
    undef(&ISPRINT) if defined(&ISPRINT);
    eval 'sub ISALNUM {
        my($c) = @_;
	    eval q(( &IN_CTYPE_DOMAIN ($c)  &&  &isalnum ($c)));
    }' unless defined(&ISALNUM);
    eval 'sub ISALPHA {
        my($c) = @_;
	    eval q(( &IN_CTYPE_DOMAIN ($c)  &&  &isalpha ($c)));
    }' unless defined(&ISALPHA);
    eval 'sub ISDIGIT {
        my($c) = @_;
	    eval q(( &IN_CTYPE_DOMAIN ($c)  &&  &isdigit ($c)));
    }' unless defined(&ISDIGIT);
    eval 'sub ISLOWER {
        my($c) = @_;
	    eval q(( &IN_CTYPE_DOMAIN ($c)  &&  &islower ($c)));
    }' unless defined(&ISLOWER);
    eval 'sub ISPRINT {
        my($c) = @_;
	    eval q(( &IN_CTYPE_DOMAIN ($c)  &&  &isprint ($c)));
    }' unless defined(&ISPRINT);
    eval 'sub ISUPPER {
        my($c) = @_;
	    eval q(( &IN_CTYPE_DOMAIN ($c)  &&  &isupper ($c)));
    }' unless defined(&ISUPPER);
    eval 'sub ISXDIGIT {
        my($c) = @_;
	    eval q(( &IN_CTYPE_DOMAIN ($c)  &&  &isxdigit ($c)));
    }' unless defined(&ISXDIGIT);
    eval 'sub _rl_lowercase_p {
        my($c) = @_;
	    eval q(( &NON_NEGATIVE($c)  &&  &ISLOWER($c)));
    }' unless defined(&_rl_lowercase_p);
    eval 'sub _rl_uppercase_p {
        my($c) = @_;
	    eval q(( &NON_NEGATIVE($c)  &&  &ISUPPER($c)));
    }' unless defined(&_rl_uppercase_p);
    eval 'sub _rl_digit_p {
        my($c) = @_;
	    eval q((($c) >= ord(\'0\' && (c) <= \'9\')));
    }' unless defined(&_rl_digit_p);
    eval 'sub _rl_pure_alphabetic {
        my($c) = @_;
	    eval q(( &NON_NEGATIVE($c)  &&  &ISALPHA($c)));
    }' unless defined(&_rl_pure_alphabetic);
    eval 'sub ALPHABETIC {
        my($c) = @_;
	    eval q(( &NON_NEGATIVE($c)  &&  &ISALNUM($c)));
    }' unless defined(&ALPHABETIC);
    unless(defined(&_rl_to_upper)) {
	eval 'sub _rl_to_upper {
	    my($c) = @_;
    	    eval q(( &_rl_lowercase_p ?  &toupper($c) : ($c)));
	}' unless defined(&_rl_to_upper);
	eval 'sub _rl_to_lower {
	    my($c) = @_;
    	    eval q(( &_rl_uppercase_p ?  &tolower($c) : ($c)));
	}' unless defined(&_rl_to_lower);
    }
    unless(defined(&_rl_digit_value)) {
	eval 'sub _rl_digit_value {
	    my($x) = @_;
    	    eval q((($x) - ord(\'0\')));
	}' unless defined(&_rl_digit_value);
    }
    unless(defined(&_rl_isident)) {
	eval 'sub _rl_isident {
	    my($c) = @_;
    	    eval q(( &ISALNUM($c) || ($c) == ord(\'_\')));
	}' unless defined(&_rl_isident);
    }
    unless(defined(&ISOCTAL)) {
	eval 'sub ISOCTAL {
	    my($c) = @_;
    	    eval q((($c) >= ord(\'0\' && (c) <= \'7\')));
	}' unless defined(&ISOCTAL);
    }
    eval 'sub OCTVALUE {
        my($c) = @_;
	    eval q((($c) - ord(\'0\')));
    }' unless defined(&OCTVALUE);
    eval 'sub HEXVALUE {
        my($c) = @_;
	    eval q(((($c) >= ord(\'a\' && (c) <= \'f\')   	? (c)-\'a\'+10   	: (c) >= \'A\' && (c) <= \'F\' ? (c)-\'A\'+10 : (c)-\'0\')));
    }' unless defined(&HEXVALUE);
    unless(defined(&NEWLINE)) {
	eval 'sub NEWLINE () {ord(\'\\n\');}' unless defined(&NEWLINE);
    }
    unless(defined(&RETURN)) {
	eval 'sub RETURN () { &CTRL(ord(\'M\'));}' unless defined(&RETURN);
    }
    unless(defined(&RUBOUT)) {
	eval 'sub RUBOUT () {0x7f;}' unless defined(&RUBOUT);
    }
    unless(defined(&TAB)) {
	eval 'sub TAB () {ord(\'\\t\');}' unless defined(&TAB);
    }
    if(defined(&ABORT_CHAR)) {
	undef(&ABORT_CHAR) if defined(&ABORT_CHAR);
    }
    eval 'sub ABORT_CHAR () { &CTRL(ord(\'G\'));}' unless defined(&ABORT_CHAR);
    if(defined(&PAGE)) {
	undef(&PAGE) if defined(&PAGE);
    }
    eval 'sub PAGE () { &CTRL(ord(\'L\'));}' unless defined(&PAGE);
    if(defined(&SPACE)) {
	undef(&SPACE) if defined(&SPACE);
    }
    eval 'sub SPACE () {ord(\' \');}' unless defined(&SPACE);
    if(defined(&ESC)) {
	undef(&ESC) if defined(&ESC);
    }
    eval 'sub ESC () { &CTRL(ord(\'[\'));}' unless defined(&ESC);
}
1;
