#!/usr/bin/env cobra """ le.cobra "line endings" - Report the line endings of text files as 'dos', 'unix', 'oldmac', 'both' or '?'. Skips binary files and reports files with unknown extensions. Also, can convert to dos or unix line endings. This is a console/command-line utility. Run with -h for usage help. Notes * The program looks at the extension of a file to determine if it is text or binary. While this is less technically accurate than examining file contents and also requires the extension lists to be occasionally augmented, it is very efficient--many files do not have to be opened. """ use System.Text.RegularExpressions enum Action None ToUnix ToDos class LineEndings var _excludeNamesSpec = '.svn _svn' var _binExtensionsSpec = 'dll doc exe pdb mdb gif png pyc pyo jpg jpeg snk tif tiff xls' var _textExtensionsSpec = 'bat c cobra config cpp cs css dif diff h htm html kv m patch py sh sql svg text txt xhtml xml' var _excludeNamesCache = List() var _binExtensionsCache = List() var _textExtensionsCache = List() var _action as Action var _crLfRegEx = Regex(r'\r\n') # dos / windows var _notCrLfRegEx = Regex(r'[^\r]\n') # unix / mac / linux / etc var _crRegEx = Regex(r'\r') # old mac var _exts = Set() get excludeNames as IList if not _excludeNamesCache.count _excludeNamesCache = List(_excludeNamesSpec.split) return _excludeNamesCache get binExtensions as IList if not _binExtensionsCache.count _binExtensionsCache = List(_binExtensionsSpec.split) return _binExtensionsCache get textExtensions as IList if not _textExtensionsCache.count _textExtensionsCache = List(_textExtensionsSpec.split) return _textExtensionsCache def main is shared LineEndings().run(CobraCore.commandLineArgs) def printHelp print 'le