$displayed = 0;

sub ZPut {
    my(@a) = @_;
    &Zion::put(@a);
}

sub ZFields {
    if(!$have_gotten_fields){
	@zephyr_fields = &Zion::fields();
	$have_gotten_fields = 1;
    }
    @zephyr_fields;
}

sub SetZFields {
    if($Feature::zfC >= 70){
	@zephyr_fields = @_;
    }
}

#
# Features are registered in the following way:
# &FeatureRegister(@features);
#   which will register the feature with the flow control array
#   There is an array @zfc, which has as elements references to
#   lists of function calls
#
# Features set $main::displayed if they think they have handled the primary
# 'display' of any given message

# Features have standard 'insertion points'
#
# 10      ALL zephyrs will get to this point.  No modifications or official
#         display of zephyrs should occur yet.  Look, don't touch.
# 20      This is the first opportunity to preemptively exit.
#         No modifications to the zephyr may be made.  You may exit.
# 30      Modification of zephyrs is allowed here
# 40      Special cased opcodes are handled here
# 50      Special cased class/instance/recipient/sender stuff is here
# 60      All "normal" zephyrs are guaranteed to get here.  Look, don't touch.
# 70      Normal zephyr modifications made here.
# 80      Special display mechanisms here.
# 90      Standard display mechanisms here
# 100     Fall through

package Feature;

sub HandleZephyr {
    $main::displayed = 0;
    $main::have_gotten_fields = 0;
    for $zfC (0..100){
	foreach $func (@{$zfc[$zfC]}){
	    &$func();
	}
    }
    $zfC = 0;
    if(!$main::displayed){
	&main::ZPut("Warning:\nYou do not have a default display mechanism!");
    }
}

sub Register {
    my(@f) = @_;
	return if $registered;
    foreach $f (@f){
	$featurefile = $f.".zf";
	require $featurefile;
	$pload = \&{$f."::Load"};
	if(defined &$pload){
		&$pload;
	}
	else {
		print("zion: Warning, no load function for feature $f\n");
	}
    }
	$registered = 1;
}

sub FuncReg {
    my($functionref, $when) = @_;
    push(@{$zfc[$when]}, $functionref);
}

sub LocalizeZephyr {
    ($package, $f, $l) = caller();
    @vars = qw(number_of_fields version zephyr_version class
	       instance opcode default recipient fullsender port
	       kind auth sender message error fromhost realm user
	       time date);

    foreach $v (@vars){
	*{"${package}::$v"} = \${"main::$v"};
    }
}

1;



