blob: 25f71e47cf9ffbda1422815756ff714093bbed98 [file] [log] [blame]
Jack Jansen024a3871996-07-18 16:07:05 +00001"""checktext - Check that a text file has macintosh-style newlines"""
2
Jack Jansen024a3871996-07-18 16:07:05 +00003import sys
4import EasyDialogs
5import string
6
7def main():
Tim Peters182b5ac2004-07-18 06:16:08 +00008 pathname = EasyDialogs.AskFileForOpen(message='File to check end-of-lines in:')
9 if not pathname:
10 sys.exit(0)
11 fp = open(pathname, 'rb')
12 try:
13 data = fp.read()
14 except MemoryError:
15 EasyDialogs.Message('Sorry, file is too big.')
16 sys.exit(0)
17 if len(data) == 0:
18 EasyDialogs.Message('File is empty.')
19 sys.exit(0)
20 number_cr = string.count(data, '\r')
21 number_lf = string.count(data, '\n')
22 if number_cr == number_lf == 0:
23 EasyDialogs.Message('File contains no lines.')
24 if number_cr == 0:
25 EasyDialogs.Message('File has unix-style line endings')
26 elif number_lf == 0:
27 EasyDialogs.Message('File has mac-style line endings')
28 elif number_cr == number_lf:
29 EasyDialogs.Message('File probably has MSDOS-style line endings')
30 else:
31 EasyDialogs.Message('File has no recognizable line endings (binary file?)')
32 sys.exit(0)
33
Jack Jansen024a3871996-07-18 16:07:05 +000034if __name__ == '__main__':
Tim Peters182b5ac2004-07-18 06:16:08 +000035 main()