require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_LIB_PTHREAD_QUEUE_H)) {
    eval 'sub _LIB_PTHREAD_QUEUE_H () {1;}' unless defined(&_LIB_PTHREAD_QUEUE_H);
    eval 'sub PTQ_HEAD {
        my($name, $type) = @_;
	    eval q(\'struct name\' { \'struct type\' * &ptqh_first; \'struct type\' ** &ptqh_last; });
    }' unless defined(&PTQ_HEAD);
    eval 'sub PTQ_HEAD_INITIALIZER () {{  &NULL,  &NULL };}' unless defined(&PTQ_HEAD_INITIALIZER);
    eval 'sub PTQ_ENTRY {
        my($type) = @_;
	    eval q(\'struct struct\' { \'struct type\' * &ptqe_next; \'struct type\' ** &ptqe_prev; });
    }' unless defined(&PTQ_ENTRY);
    eval 'sub PTQ_INIT {
        my($head) = @_;
	    eval q( &do { ($head)-> &ptqh_first =  &NULL; ($head)-> &ptqh_last = ($head)-> &ptqh_first; }  &while (0));
    }' unless defined(&PTQ_INIT);
    eval 'sub PTQ_INSERT_HEAD {
        my($head, $elm, $field) = @_;
	    eval q( &do {  &if ((($elm)-> ($field->{ptqe_next}) = ($head)-> &ptqh_first) !=  &NULL) ($head)-> ($ptqh_first->{field}->{ptqe_prev}) = ($elm)-> ($field->{ptqe_next});  &else ($head)-> &ptqh_last = ($elm)-> ($field->{ptqe_next}); ($head)-> &ptqh_first = ($elm); ($elm)-> ($field->{ptqe_prev}) = ($head)-> &ptqh_first; }  &while (0));
    }' unless defined(&PTQ_INSERT_HEAD);
    eval 'sub PTQ_INSERT_TAIL {
        my($head, $elm, $field) = @_;
	    eval q( &do { ($elm)-> ($field->{ptqe_next}) =  &NULL;  &if (($head)-> &ptqh_last ==  &NULL) ($head)-> &ptqh_last = ($head)-> &ptqh_first; ($elm)-> ($field->{ptqe_prev}) = ($head)-> &ptqh_last; *($head)-> &ptqh_last = ($elm); ($head)-> &ptqh_last = ($elm)-> ($field->{ptqe_next}); }  &while (0));
    }' unless defined(&PTQ_INSERT_TAIL);
    eval 'sub PTQ_INSERT_AFTER {
        my($head, $listelm, $elm, $field) = @_;
	    eval q( &do {  &if ((($elm)-> ($field->{ptqe_next}) = ($listelm)-> ($field->{ptqe_next})) !=  &NULL) ($elm)-> ($field->{ptqe_next}->{field}->{ptqe_prev}) = ($elm)-> ($field->{ptqe_next});  &else ($head)-> &ptqh_last = ($elm)-> ($field->{ptqe_next}); ($listelm)-> ($field->{ptqe_next}) = ($elm); ($elm)-> ($field->{ptqe_prev}) = ($listelm)-> ($field->{ptqe_next}); }  &while (0));
    }' unless defined(&PTQ_INSERT_AFTER);
    eval 'sub PTQ_INSERT_BEFORE {
        my($listelm, $elm, $field) = @_;
	    eval q( &do { ($elm)-> ($field->{ptqe_prev}) = ($listelm)-> ($field->{ptqe_prev}); ($elm)-> ($field->{ptqe_next}) = ($listelm); *($listelm)-> ($field->{ptqe_prev}) = ($elm); ($listelm)-> ($field->{ptqe_prev}) = ($elm)-> ($field->{ptqe_next}); }  &while (0));
    }' unless defined(&PTQ_INSERT_BEFORE);
    eval 'sub PTQ_REMOVE {
        my($head, $elm, $field) = @_;
	    eval q( &do {  &if ((($elm)-> ($field->{ptqe_next})) !=  &NULL) ($elm)-> ($field->{ptqe_next}->{field}->{ptqe_prev}) = ($elm)-> ($field->{ptqe_prev});  &else ($head)-> &ptqh_last = ($elm)-> ($field->{ptqe_prev}); *($elm)-> ($field->{ptqe_prev}) = ($elm)-> ($field->{ptqe_next}); }  &while (0));
    }' unless defined(&PTQ_REMOVE);
    eval 'sub PTQ_EMPTY {
        my($head) = @_;
	    eval q((($head)-> &ptqh_first ==  &NULL));
    }' unless defined(&PTQ_EMPTY);
    eval 'sub PTQ_FIRST {
        my($head) = @_;
	    eval q((($head)-> &ptqh_first));
    }' unless defined(&PTQ_FIRST);
    eval 'sub PTQ_NEXT {
        my($elm, $field) = @_;
	    eval q((($elm)-> ($field->{ptqe_next})));
    }' unless defined(&PTQ_NEXT);
    eval 'sub PTQ_LAST {
        my($head, $headname) = @_;
	    eval q((*((( &void *)(($head)-> &ptqh_last))-> &ptqh_last)));
    }' unless defined(&PTQ_LAST);
    eval 'sub PTQ_PREV {
        my($elm, $headname, $field) = @_;
	    eval q((*((( &void *)(($elm)-> ($field->{ptqe_prev})))-> &ptqh_last)));
    }' unless defined(&PTQ_PREV);
    eval 'sub PTQ_FOREACH {
        my($var, $head, $field) = @_;
	    eval q( &for (($var) = (($head)-> &ptqh_first); ($var); ($var) = (($var)-> ($field->{ptqe_next}))));
    }' unless defined(&PTQ_FOREACH);
    eval 'sub PTQ_FOREACH_REVERSE {
        my($var, $head, $headname, $field) = @_;
	    eval q( &for (($var) = (*((( &void *)(($head)-> &ptqh_last))-> &ptqh_last)); ($var); ($var) = (*((( &void *)(($var)-> ($field->{ptqe_prev})))-> &ptqh_last))));
    }' unless defined(&PTQ_FOREACH_REVERSE);
}
1;
