Theory of dislocations in diamond and silicon and their interaction with hydrogen