![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/share/emscripten/tools/ |
Upload File : |
import sys # This function checks and prints out the detected line endings in the given file. # If the file only contains either Windows \r\n line endings or Unix \n line endings, it returns 0. # Otherwise, in the presence of old OSX or mixed/malformed line endings, a non-zero error code is returned. def check_line_endings(filename, print_errors=True): try: data = open(filename, 'rb').read() except Exception, e: if print_errors: print >> sys.stderr, "Unable to read file '" + filename + "'! " + str(e) return 1 if len(data) == 0: if print_errors: print >> sys.stderr, "Unable to read file '" + filename + "', or file was empty!" return 1 if "\r\r\n" in data: if print_errors: print >> sys.stderr, "File '" + filename + "' contains BAD line endings of form \\r\\r\\n!" return 1 # Bad line endings in file, return a non-zero process exit code. has_dos_line_endings = False has_unix_line_endings = False if '\r\n' in data: has_dos_line_endings = True data = data.replace('\r\n', 'A') # Replace all DOS line endings with some other character, and continue testing what's left. if '\n' in data: has_unix_line_endings = True if '\r' in data: if print_errors: print >> sys.stderr, 'File \'' + filename + '\' contains OLD OSX line endings "\\r"' return 1 # Return a non-zero process exit code since we don't want to use the old OSX (9.x) line endings anywhere. if has_dos_line_endings and has_unix_line_endings: if print_errors: print >> sys.stderr, 'File \'' + filename + '\' contains both DOS "\\r\\n" and UNIX "\\n" line endings!' return 1 # Mixed line endings else: return 0 if __name__ == '__main__': if len(sys.argv) != 2: print >> sys.stderr, 'Unknown command line ' + str(sys.argv) + '!' print >> sys.stderr, 'Usage: ' + sys.argv[0] + ' <filename>' sys.exit(1) sys.exit(check_line_endings(sys.argv[1]))