require '_h2ph_pre.ph';

unless(defined(&_SYS_QUEUE_H)) {
    eval 'sub _SYS_QUEUE_H () {1;}' unless defined(&_SYS_QUEUE_H);
    eval 'sub LIST_HEAD {
        local($name, $type) = @_;
	    eval q(\'struct name\' { \'struct type\' * &lh_first; });
    }' unless defined(&LIST_HEAD);
    eval 'sub LIST_ENTRY {
        local($type) = @_;
	    eval q(\'struct struct\' { \'struct type\' * &le_next; \'struct type\' ** &le_prev; });
    }' unless defined(&LIST_ENTRY);
    eval 'sub LIST_INIT {
        local($head) = @_;
	    eval q({ ($head)-> &lh_first =  &NULL; });
    }' unless defined(&LIST_INIT);
    eval 'sub LIST_INSERT_AFTER {
        local($listelm, $elm, $field) = @_;
	    eval q({  &if ((($elm)-> ($field->{le_next}) = ($listelm)-> ($field->{le_next})) !=  &NULL) ($listelm)-> ($field->{le_next}->{field}->{le_prev}) = ($elm)-> ($field->{le_next}); ($listelm)-> ($field->{le_next}) = ($elm); ($elm)-> ($field->{le_prev}) = ($listelm)-> ($field->{le_next}); });
    }' unless defined(&LIST_INSERT_AFTER);
    eval 'sub LIST_INSERT_HEAD {
        local($head, $elm, $field) = @_;
	    eval q({  &if ((($elm)-> ($field->{le_next}) = ($head)-> &lh_first) !=  &NULL) ($head)-> ($lh_first->{field}->{le_prev}) = ($elm)-> ($field->{le_next}); ($head)-> &lh_first = ($elm); ($elm)-> ($field->{le_prev}) = ($head)-> &lh_first; });
    }' unless defined(&LIST_INSERT_HEAD);
    eval 'sub LIST_REMOVE {
        local($elm, $field) = @_;
	    eval q({  &if (($elm)-> ($field->{le_next}) !=  &NULL) ($elm)-> ($field->{le_next}->{field}->{le_prev}) = ($elm)-> ($field->{le_prev}); *($elm)-> ($field->{le_prev}) = ($elm)-> ($field->{le_next}); });
    }' unless defined(&LIST_REMOVE);
    eval 'sub TAILQ_HEAD {
        local($name, $type) = @_;
	    eval q(\'struct name\' { \'struct type\' * &tqh_first; \'struct type\' ** &tqh_last; });
    }' unless defined(&TAILQ_HEAD);
    eval 'sub TAILQ_ENTRY {
        local($type) = @_;
	    eval q(\'struct struct\' { \'struct type\' * &tqe_next; \'struct type\' ** &tqe_prev; });
    }' unless defined(&TAILQ_ENTRY);
    eval 'sub TAILQ_INIT {
        local($head) = @_;
	    eval q({ ($head)-> &tqh_first =  &NULL; ($head)-> &tqh_last = ($head)-> &tqh_first; });
    }' unless defined(&TAILQ_INIT);
    eval 'sub TAILQ_INSERT_HEAD {
        local($head, $elm, $field) = @_;
	    eval q({  &if ((($elm)-> ($field->{tqe_next}) = ($head)-> &tqh_first) !=  &NULL) ($elm)-> ($field->{tqe_next}->{field}->{tqe_prev}) = ($elm)-> ($field->{tqe_next});  &else ($head)-> &tqh_last = ($elm)-> ($field->{tqe_next}); ($head)-> &tqh_first = ($elm); ($elm)-> ($field->{tqe_prev}) = ($head)-> &tqh_first; });
    }' unless defined(&TAILQ_INSERT_HEAD);
    eval 'sub TAILQ_INSERT_TAIL {
        local($head, $elm, $field) = @_;
	    eval q({ ($elm)-> ($field->{tqe_next}) =  &NULL; ($elm)-> ($field->{tqe_prev}) = ($head)-> &tqh_last; *($head)-> &tqh_last = ($elm); ($head)-> &tqh_last = ($elm)-> ($field->{tqe_next}); });
    }' unless defined(&TAILQ_INSERT_TAIL);
    eval 'sub TAILQ_INSERT_AFTER {
        local($head, $listelm, $elm, $field) = @_;
	    eval q({  &if ((($elm)-> ($field->{tqe_next}) = ($listelm)-> ($field->{tqe_next})) !=  &NULL) ($elm)-> ($field->{tqe_next}->{field}->{tqe_prev}) = ($elm)-> ($field->{tqe_next});  &else ($head)-> &tqh_last = ($elm)-> ($field->{tqe_next}); ($listelm)-> ($field->{tqe_next}) = ($elm); ($elm)-> ($field->{tqe_prev}) = ($listelm)-> ($field->{tqe_next}); });
    }' unless defined(&TAILQ_INSERT_AFTER);
    eval 'sub TAILQ_REMOVE {
        local($head, $elm, $field) = @_;
	    eval q({  &if ((($elm)-> ($field->{tqe_next})) !=  &NULL) ($elm)-> ($field->{tqe_next}->{field}->{tqe_prev}) = ($elm)-> ($field->{tqe_prev});  &else ($head)-> &tqh_last = ($elm)-> ($field->{tqe_prev}); *($elm)-> ($field->{tqe_prev}) = ($elm)-> ($field->{tqe_next}); });
    }' unless defined(&TAILQ_REMOVE);
    eval 'sub CIRCLEQ_HEAD {
        local($name, $type) = @_;
	    eval q(\'struct name\' { \'struct type\' * &cqh_first; \'struct type\' * &cqh_last; });
    }' unless defined(&CIRCLEQ_HEAD);
    eval 'sub CIRCLEQ_ENTRY {
        local($type) = @_;
	    eval q(\'struct struct\' { \'struct type\' * &cqe_next; \'struct type\' * &cqe_prev; });
    }' unless defined(&CIRCLEQ_ENTRY);
    eval 'sub CIRCLEQ_INIT {
        local($head) = @_;
	    eval q({ -> &cqh_first = ; -> &cqh_last = ($head); });
    }' unless defined(&CIRCLEQ_INIT);
    eval 'sub CIRCLEQ_INSERT_AFTER {
        local($head, $listelm, $elm, $field) = @_;
	    eval q({ -> ($field->{cqe_next}) = -> ($field->{cqe_next}); -> ($field->{cqe_prev}) = ;  &if (-> ($field->{cqe_next}) == ($head)) ($head)-> &cqh_last = ($elm);  &else ($listelm)-> ($field->{cqe_next}->{field}->{cqe_prev}) = ($elm); ($listelm)-> ($field->{cqe_next}) = ($elm); });
    }' unless defined(&CIRCLEQ_INSERT_AFTER);
    eval 'sub CIRCLEQ_INSERT_BEFORE {
        local($head, $listelm, $elm, $field) = @_;
	    eval q({ -> ($field->{cqe_next}) = ; -> ($field->{cqe_prev}) = -> ($field->{cqe_prev});  &if (-> ($field->{cqe_prev}) == ($head)) ($head)-> &cqh_first = ($elm);  &else ($listelm)-> ($field->{cqe_prev}->{field}->{cqe_next}) = ($elm); ($listelm)-> ($field->{cqe_prev}) = ($elm); });
    }' unless defined(&CIRCLEQ_INSERT_BEFORE);
    eval 'sub CIRCLEQ_INSERT_HEAD {
        local($head, $elm, $field) = @_;
	    eval q({ -> ($field->{cqe_next}) = -> &cqh_first; -> ($field->{cqe_prev}) = ;  &if (-> &cqh_last == ($head)) ($head)-> &cqh_last = ($elm);  &else ($head)-> ($cqh_first->{field}->{cqe_prev}) = ($elm); ($head)-> &cqh_first = ($elm); });
    }' unless defined(&CIRCLEQ_INSERT_HEAD);
    eval 'sub CIRCLEQ_INSERT_TAIL {
        local($head, $elm, $field) = @_;
	    eval q({ -> ($field->{cqe_next}) = ; -> ($field->{cqe_prev}) = -> &cqh_last;  &if (-> &cqh_first == ($head)) ($head)-> &cqh_first = ($elm);  &else ($head)-> ($cqh_last->{field}->{cqe_next}) = ($elm); ($head)-> &cqh_last = ($elm); });
    }' unless defined(&CIRCLEQ_INSERT_TAIL);
    eval 'sub CIRCLEQ_REMOVE {
        local($head, $elm, $field) = @_;
	    eval q({  &if (-> ($field->{cqe_next}) == ) -> &cqh_last = -> ($field->{cqe_prev});  &else -> ($field->{cqe_next}->{field}->{cqe_prev}) = -> ($field->{cqe_prev});  &if (-> ($field->{cqe_prev}) == ($head)) ($head)-> &cqh_first = ($elm)-> ($field->{cqe_next});  &else ($elm)-> ($field->{cqe_prev}->{field}->{cqe_next}) = ($elm)-> ($field->{cqe_next}); });
    }' unless defined(&CIRCLEQ_REMOVE);
}
1;
