Spectrographic phase-retrieval algorithm for femtosecond and attosecond pulses with frequency gaps