Muonic and pionic L- and M-series in carbon and oxygen and the pionic 2p level shift and width of oxygen