Pion-pion interactions in S- and P-waves and their applications to certain three-pion and four-pion systems