initial commit / ported and extended from BBmisc
allow rules to be a vector in c