more robust source encoding detection

Fixed detection of source from magic comment. Also, it can be argued than encoding defined by author in magic comment should have priority over other default encoding parameters and guesses. Therefore use default encoding parameter as last resort, then fallback to iso-8859-1.