Chemical and optical properties of carbon-doped TiO2: A density-functional study