First-principles study of edge states of H-terminated graphitic ribbons