If you have a polynomial with real coefficients, the roots are real or occur in complex conjugate pairs.
So one way to do this would be to call the roots function, and first remove all the results which are real (these will be the linear factors). Then, take all the factors which have non-zero imaginary part, and throw out the ones which have strictly negative imaginary part. You'll be left with roots $r_1,r_2,...$. Then, the quadratic factors will be given by $(x-r_i)(x-\bar{r_i}) = x - 2 Re(r_i) x + |r_i|^2$.