require '_h2ph_pre.ph';

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)) {
	    require 'string.ph';
	} else {
	    require 'strings.ph';
	}
    } else {
	require 'string.ph';
    }
    unless(defined(&whitespace)) {
	eval 'sub whitespace {
	    local($c) = @_;
    	    eval q(((($c) == ord(\' \') || ((c) == \'\\\\t\'))));
	}' unless defined(&whitespace);
    }
    if(defined(&CTRL)) {
	undef(&CTRL) if defined(&CTRL);
    }
    eval 'sub control_character_threshold () {0x020;}' unless defined(&control_character_threshold);
    eval 'sub control_character_mask () {0x1f;}' unless defined(&control_character_mask);
    eval 'sub meta_character_threshold () {0x07f;}' unless defined(&meta_character_threshold);
    eval 'sub control_character_bit () {0x40;}' unless defined(&control_character_bit);
    eval 'sub meta_character_bit () {0x080;}' unless defined(&meta_character_bit);
    eval 'sub largest_char () {255;}' unless defined(&largest_char);
    eval 'sub CTRL_CHAR {
        local($c) = @_;
	    eval q((($c) <  &control_character_threshold  && ($c) >= 0));
    }' unless defined(&CTRL_CHAR);
    eval 'sub META_CHAR {
        local($c) = @_;
	    eval q((($c) >  &meta_character_threshold  && ($c) <=  &largest_char));
    }' unless defined(&META_CHAR);
    eval 'sub CTRL {
        local($c) = @_;
	    eval q((($c) &  &control_character_mask));
    }' unless defined(&CTRL);
    eval 'sub META {
        local($c) = @_;
	    eval q((($c) |  &meta_character_bit));
    }' unless defined(&META);
    eval 'sub UNMETA {
        local($c) = @_;
	    eval q((($c) & (~ &meta_character_bit)));
    }' unless defined(&UNMETA);
    eval 'sub UNCTRL {
        local($c) = @_;
	    eval q( &_rl_to_upper((($c)| &control_character_bit)));
    }' unless defined(&UNCTRL);
    eval 'sub _rl_lowercase_p {
        local($c) = @_;
	    eval q(( &islower($c)));
    }' unless defined(&_rl_lowercase_p);
    eval 'sub _rl_uppercase_p {
        local($c) = @_;
	    eval q(( &isupper($c)));
    }' unless defined(&_rl_uppercase_p);
    eval 'sub _rl_digit_p {
        local($x) = @_;
	    eval q(( &isdigit ($x)));
    }' unless defined(&_rl_digit_p);
    eval 'sub _rl_pure_alphabetic {
        local($c) = @_;
	    eval q(( &_rl_lowercase_p($c) ||  &_rl_uppercase_p($c)));
    }' unless defined(&_rl_pure_alphabetic);
    eval 'sub ALPHABETIC {
        local($c) = @_;
	    eval q(( &_rl_lowercase_p($c) ||  &_rl_uppercase_p($c) ||  &_rl_digit_p($c)));
    }' unless defined(&ALPHABETIC);
    unless(defined(&_rl_to_upper)) {
	eval 'sub _rl_to_upper {
	    local($c) = @_;
    	    eval q(( &islower($c) ?  &toupper($c) : ($c)));
	}' unless defined(&_rl_to_upper);
	eval 'sub _rl_to_lower {
	    local($c) = @_;
    	    eval q(( &isupper($c) ?  &tolower($c) : ($c)));
	}' unless defined(&_rl_to_lower);
    }
    unless(defined(&_rl_digit_value)) {
	eval 'sub _rl_digit_value {
	    local($x) = @_;
    	    eval q((($x) - ord(\'0\')));
	}' unless defined(&_rl_digit_value);
    }
    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);
    unless(defined(&ISOCTAL)) {
	eval 'sub ISOCTAL {
	    local($c) = @_;
    	    eval q((($c) >= ord(\'0\' && (c) <= \'7\')));
	}' unless defined(&ISOCTAL);
    }
    eval 'sub OCTVALUE {
        local($c) = @_;
	    eval q((($c) - ord(\'0\')));
    }' unless defined(&OCTVALUE);
    unless(defined(&isxdigit)) {
	eval 'sub isxdigit {
	    local($c) = @_;
    	    eval q(( &isdigit(($c)) || (($c) >= ord(\'a\' && (c) <= \'f\') || ((c) >= \'A\' && (c) <= \'F\'))));
	}' unless defined(&isxdigit);
    }
    eval 'sub HEXVALUE {
        local($c) = @_;
	    eval q(((($c) >= ord(\'a\' && (c) <= \'f\')   	? (c)-\'a\'+10   	: (c) >= \'A\' && (c) <= \'F\' ? (c)-\'A\'+10 : (c)-\'0\')));
    }' unless defined(&HEXVALUE);
}
1;
