  In the 1980's Stallings showed that every finitely generated subgroup of a
free group is canonically represented by a finite minimal immersion of a
bouquet of circles. In terms of the theory of automata, this is a minimal
finite inverse automaton. This allows for the deep algorithmic theory of finite
automata and finite inverse monoids to be used to answer questions about
finitely generated subgroups of free groups.
  In this paper we attempt to apply the same methods to other classes of
groups. A fundamental new problem is that the Stallings folding algorithm must
be modified to allow for ``sewing'' on relations of non-free groups. We look at
the class of groups that are amalgams of finite groups. It is known that these
groups are locally quasiconvex and thus all finitely generated subgroups are
represented by finite automata. We present an algorithm to compute such a
finite automaton and use it to solve various algorithmic problems.
