
$include "defs.icn"
$include "global_vars.icn"
# Number the subtree headed by p 
procedure number(p)
    local q,v,temp,e    # q pointer to next field of p to be recursively     
    # examined.                                        
    #  register int v;      bit vector specifying primary link fields of *p  
    # shifted so that the most significant bit         
    # corresponds to q.                                
    if (/ p ) then return
    next_pre +:= 1
    if numeric(p) then return p
    p. pre_num := next_pre
    # recursively examine subtrees 
    if (is_list(p)) then {
	temp := p.lh_first
	while \temp do {
	    e := temp.cn_hd_field
	    number(e)
	    temp := temp.cn_tl_field
	}
    }
    else 
	{
	cnt := 1
	every fld := fieldnames(p) do 
	    {
		if should_examine(fld) then
		    {
			number(p[cnt])
		    }
		cnt +:= 1
	    }
    }
    
    next_post +:= 1
    p . post_num := next_post
end

